w.i.p sdcard device driver for raspi. detects cards but isnt able to send commands...
[AROS.git] / arch / arm-raspi / devs / sdcard / sdcard_ioops.c
blobd448cdbc3c7c4cb75d5b9b244f53cdb7b792d266
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 1
8 // use #define xxx(a) D(a) to enable particular sections.
9 #if DEBUG
10 #define DIRQ(a) D(a)
11 #define DIRQ_MORE(a)
12 #define DUMP(a) D(a)
13 #define DUMP_MORE(a)
14 #define DINIT(a) (a)
15 #else
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)
21 #endif
22 /* Errors that shouldn't happen */
23 #define DERROR(a) a
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>
30 #include <oop/oop.h>
32 #include <proto/exec.h>
33 #include <devices/timer.h>
35 #include <hardware/mmc.h>
37 #include "sdcard_intern.h"
38 #include "timer.h"
40 static BOOL sdcard_WaitBusyTO(struct sdcard_Unit *unit, UWORD tout, BOOL irq, UBYTE *stout);
42 #define DEVHEAD_VAL 0x40
44 #if DEBUG
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]);
56 if (i == 15)
57 break;
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 : '.' : '.');
65 if (i == 15)
66 break;
68 bug("\n");
71 #endif
73 static void sdcard_strcpy(const UBYTE *str1, UBYTE *str2, ULONG size)
75 register int i = size;
77 while (size--)
78 str2[size ^ 1] = str1[size];
80 while (i > 0 && str2[--i] <= ' ')
81 str2[i] = '\0';
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));
90 return CDERR_NOCMD;
93 static BYTE sdcard_STUB_IO32(struct sdcard_Unit *unit, ULONG blk, ULONG len,
94 APTR buf, ULONG* act)
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));
98 return CDERR_NOCMD;
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));
106 return CDERR_NOCMD;
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));
112 return CDERR_NOCMD;
115 static inline BOOL sdcard_SelectUnit(struct sdcard_Unit* unit)
117 return TRUE;
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)
155 BYTE err = 0;
156 return err;
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},
170 {SDCARD_TAG_RSP, 0},
171 {SDCARD_TAG_DATA, buffer},
172 {SDCARD_TAG_DATALEN, count * (1 << unit->sdcu_Bus->sdcb_SectorShift)},
173 {SDCARD_TAG_DATAFLAGS, MMC_DATA_READ},
174 {TAG_DONE, 0}
177 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
179 *act = 0;
181 if (count > 1)
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__));
194 else
196 D(bug("[SDCard%02ld] %s: Error ..\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
197 count = 0;
200 if (count > 1)
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));
215 return 0;
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__));
224 return 0;
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__));
232 return 0;
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__));
243 return 0;
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__));
251 return 0;
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__));
259 return 0;
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__));
270 return 0;
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__));
278 return 0;
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__));
286 return 0;
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__));
297 return 0;
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__));
305 return 0;
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__));
313 return 0;
317 * miscellaneous
319 BYTE FNAME_SDCIO(Eject)(struct sdcard_Unit *unit)
321 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
323 return 0;