2 Copyright © 2013, The AROS Development Team. All rights reserved.
8 // use #define xxx(a) D(a) to enable particular sections.
16 #define DIRQ(a) do { } while (0)
17 #define DIRQ_MORE(a) do { } while (0)
18 #define DUMP(a) do { } while (0)
19 #define DUMP_MORE(a) do { } while (0)
20 #define DINIT(a) do { } while (0)
22 /* Errors that shouldn't happen */
25 #include <aros/debug.h>
26 #include <exec/types.h>
27 #include <exec/exec.h>
28 #include <exec/resident.h>
29 #include <utility/utility.h>
32 #include <proto/exec.h>
33 #include <devices/timer.h>
35 #include <hardware/mmc.h>
37 #include "sdcard_intern.h"
40 static BOOL
sdcard_WaitBusyTO(struct sdcard_Unit
*unit
, UWORD tout
, BOOL irq
, UBYTE
*stout
);
42 #define DEVHEAD_VAL 0x40
45 static void dump(APTR mem
, ULONG len
)
47 register int i
, j
= 0;
49 DUMP_MORE(for (j
=0; j
<(len
+15)>>4; ++j
))
51 bug("[SDC ] %06lx: ", j
<<4);
53 for (i
=0; i
<len
-(j
<<4); i
++)
55 bug("%02lx ", ((unsigned char*)mem
)[(j
<<4)|i
]);
60 for (i
=0; i
<len
-(j
<<4); i
++)
62 unsigned char c
= ((unsigned char*)mem
)[(j
<<4)|i
];
64 bug("%c", c
>= 0x20 ? c
<=0x7f ? c
: '.' : '.');
73 static void sdcard_strcpy(const UBYTE
*str1
, UBYTE
*str2
, ULONG size
)
75 register int i
= size
;
78 str2
[size
^ 1] = str1
[size
];
80 while (i
> 0 && str2
[--i
] <= ' ')
85 * a STUB function for commands not supported by this particular device
87 static BYTE
sdcard_STUB(struct sdcard_Unit
*unit
)
89 DERROR(bug("[SDCard%02ld] CALLED STUB FUNCTION (GENERIC). OPERATION IS NOT SUPPORTED BY DEVICE\n", unit
->sdcu_UnitNum
));
93 static BYTE
sdcard_STUB_IO32(struct sdcard_Unit
*unit
, ULONG blk
, ULONG len
,
96 DERROR(bug("[SDCard%02ld] CALLED STUB FUNCTION (IO32). OPERATION IS NOT SUPPORTED BY DEVICE\n", unit
->sdcu_UnitNum
));
97 DERROR(bug("[SDCard%02ld] -- IO ACCESS TO BLOCK %08lx, LENGTH %08lx\n", unit
->sdcu_UnitNum
, blk
, len
));
101 static BYTE
sdcard_STUB_IO64(struct sdcard_Unit
*unit
, UQUAD blk
, ULONG len
,
102 APTR buf
, ULONG
* act
)
104 DERROR(bug("[SDCard%02ld] CALLED STUB FUNCTION (IO64). OPERATION IS NOT SUPPORTED BY DEVICE\n", unit
->sdcu_UnitNum
));
105 DERROR(bug("[SDCard%02ld] -- IO ACCESS TO BLOCK %08lx:%08lx, LENGTH %08lx\n", unit
->sdcu_UnitNum
, (blk
>> 32), (blk
& 0xffffffff), len
));
109 static BYTE
sdcard_STUB_SCSI(struct sdcard_Unit
*unit
, struct SCSICmd
* cmd
)
111 DERROR(bug("[SDCard%02ld] CALLED STUB FUNCTION (IOSCSI). OPERATION IS NOT SUPPORTED BY DEVICE\n", unit
->sdcu_UnitNum
));
115 static inline BOOL
sdcard_SelectUnit(struct sdcard_Unit
* unit
)
120 void sdcard_IRQSetHandler(struct sdcard_Unit
*unit
, void (*handler
)(struct sdcard_Unit
*, UBYTE
), APTR piomem
, ULONG blklen
, ULONG piolen
)
125 void sdcard_IRQNoData(struct sdcard_Unit
*unit
, UBYTE status
)
130 void sdcard_IRQPIORead(struct sdcard_Unit
*unit
, UBYTE status
)
135 void sdcard_PIOWriteBlk(struct sdcard_Unit
*unit
)
140 void sdcard_IRQPIOWrite(struct sdcard_Unit
*unit
, UBYTE status
)
145 void sdcard_IRQDMAReadWrite(struct sdcard_Unit
*unit
, UBYTE status
)
151 * wait for timeout or drive ready
153 BOOL
sdcard_WaitBusyTO(struct sdcard_Unit
*unit
, UWORD tout
, BOOL irq
, UBYTE
*stout
)
160 * 32bit Read operations
162 BYTE
FNAME_SDCIO(ReadSector32
)(struct sdcard_Unit
*unit
, ULONG block
,
163 ULONG count
, APTR buffer
, ULONG
*act
)
165 struct TagItem sdcReadTags
[] =
167 {SDCARD_TAG_CMD
, MMC_CMD_READ_SINGLE_BLOCK
},
168 {SDCARD_TAG_ARG
, block
},
169 {SDCARD_TAG_RSPTYPE
, MMC_RSP_R1
},
171 {SDCARD_TAG_DATA
, buffer
},
172 {SDCARD_TAG_DATALEN
, count
* (1 << unit
->sdcu_Bus
->sdcb_SectorShift
)},
173 {SDCARD_TAG_DATAFLAGS
, MMC_DATA_READ
},
177 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
182 sdcReadTags
[0].ti_Data
= MMC_CMD_READ_MULTIPLE_BLOCK
;
184 if (!(unit
->sdcu_Flags
& AF_HighCapacity
))
185 sdcReadTags
[1].ti_Data
<<= unit
->sdcu_Bus
->sdcb_SectorShift
;
187 D(bug("[SDCard%02ld] %s: Sending CMD %d, block 0x%p, len %d [buffer @ 0x%p]\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
,
188 sdcReadTags
[0].ti_Data
, sdcReadTags
[1].ti_Data
, sdcReadTags
[5].ti_Data
, sdcReadTags
[4].ti_Data
));
190 if (FNAME_SDCBUS(SendCmd
)(sdcReadTags
, unit
->sdcu_Bus
) != -1)
192 D(bug("[SDCard%02ld] %s: checking response ..\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
196 D(bug("[SDCard%02ld] %s: Error ..\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
202 sdcReadTags
[0].ti_Data
= MMC_CMD_STOP_TRANSMISSION
;
203 sdcReadTags
[1].ti_Data
= 0;
204 sdcReadTags
[1].ti_Data
= MMC_RSP_R1b
;
205 if (FNAME_SDCBUS(SendCmd
)(sdcReadTags
, unit
->sdcu_Bus
) == -1)
207 D(bug("[SDCard%02ld] %s: Failed to terminate Read operation\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
211 *act
= count
<< unit
->sdcu_Bus
->sdcb_SectorShift
;
213 D(bug("[SDCard%02ld] %s: %d bytes Read\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
, *act
));
218 BYTE
FNAME_SDCIO(ReadMultiple32
)(struct sdcard_Unit
*unit
, ULONG block
,
219 ULONG count
, APTR buffer
, ULONG
*act
)
222 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
227 BYTE
FNAME_SDCIO(ReadDMA32
)(struct sdcard_Unit
*unit
, ULONG block
,
228 ULONG count
, APTR buffer
, ULONG
*act
)
230 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
236 * 64bit Read operations
238 BYTE
FNAME_SDCIO(ReadSector64
)(struct sdcard_Unit
*unit
, UQUAD block
,
239 ULONG count
, APTR buffer
, ULONG
*act
)
241 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
246 BYTE
FNAME_SDCIO(ReadMultiple64
)(struct sdcard_Unit
*unit
, UQUAD block
,
247 ULONG count
, APTR buffer
, ULONG
*act
)
249 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
254 BYTE
FNAME_SDCIO(ReadDMA64
)(struct sdcard_Unit
*unit
, UQUAD block
,
255 ULONG count
, APTR buffer
, ULONG
*act
)
257 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
263 * 32bit Write operations
265 BYTE
FNAME_SDCIO(WriteSector32
)(struct sdcard_Unit
*unit
, ULONG block
,
266 ULONG count
, APTR buffer
, ULONG
*act
)
268 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
273 BYTE
FNAME_SDCIO(WriteMultiple32
)(struct sdcard_Unit
*unit
, ULONG block
,
274 ULONG count
, APTR buffer
, ULONG
*act
)
276 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
281 BYTE
FNAME_SDCIO(WriteDMA32
)(struct sdcard_Unit
*unit
, ULONG block
,
282 ULONG count
, APTR buffer
, ULONG
*act
)
284 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
290 * 64bit Write operations
292 BYTE
FNAME_SDCIO(WriteSector64
)(struct sdcard_Unit
*unit
, UQUAD block
,
293 ULONG count
, APTR buffer
, ULONG
*act
)
295 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
300 BYTE
FNAME_SDCIO(WriteMultiple64
)(struct sdcard_Unit
*unit
, UQUAD block
,
301 ULONG count
, APTR buffer
, ULONG
*act
)
303 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
308 BYTE
FNAME_SDCIO(WriteDMA64
)(struct sdcard_Unit
*unit
, UQUAD block
,
309 ULONG count
, APTR buffer
, ULONG
*act
)
311 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
319 BYTE
FNAME_SDCIO(Eject
)(struct sdcard_Unit
*unit
)
321 D(bug("[SDCard%02ld] %s()\n", unit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));