Enforce libdir. On OpenSUSE the libs where stored in "lib64". They weren't
[AROS.git] / rom / devs / sdcard / sdcard_ioops.c
blob251ff867ea2b6cb46d294a03651eead43a4d6cdd
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
7 #include <aros/debug.h>
9 #include <exec/types.h>
10 #include <exec/exec.h>
11 #include <exec/resident.h>
12 #include <utility/utility.h>
13 #include <oop/oop.h>
15 #include <proto/exec.h>
16 #include <devices/cd.h>
17 #include <devices/timer.h>
19 #include <hardware/mmc.h>
20 #include <hardware/sdhc.h>
22 #include "sdcard_base.h"
23 #include "sdcard_unit.h"
25 static BOOL sdcard_WaitBusyTO(struct sdcard_Unit *unit, UWORD tout, BOOL irq, UBYTE *stout);
27 #define DEVHEAD_VAL 0x40
29 static void sdcard_strcpy(const UBYTE *str1, UBYTE *str2, ULONG size)
31 register int i = size;
33 while (size--)
34 str2[size ^ 1] = str1[size];
36 while (i > 0 && str2[--i] <= ' ')
37 str2[i] = '\0';
41 * a STUB function for commands not supported by this particular device
43 static BYTE sdcard_STUB(struct sdcard_Unit *unit)
45 DERROR(bug("[SDCard%02ld] CALLED STUB FUNCTION (GENERIC). OPERATION IS NOT SUPPORTED BY DEVICE\n", unit->sdcu_UnitNum));
46 return CDERR_NOCMD;
49 static BYTE sdcard_STUB_IO32(struct sdcard_Unit *unit, ULONG blk, ULONG len,
50 APTR buf, ULONG* act)
52 DERROR(bug("[SDCard%02ld] CALLED STUB FUNCTION (IO32). OPERATION IS NOT SUPPORTED BY DEVICE\n", unit->sdcu_UnitNum));
53 DERROR(bug("[SDCard%02ld] -- IO ACCESS TO BLOCK %08lx, LENGTH %08lx\n", unit->sdcu_UnitNum, blk, len));
54 return CDERR_NOCMD;
57 static BYTE sdcard_STUB_IO64(struct sdcard_Unit *unit, UQUAD blk, ULONG len,
58 APTR buf, ULONG* act)
60 DERROR(bug("[SDCard%02ld] CALLED STUB FUNCTION (IO64). OPERATION IS NOT SUPPORTED BY DEVICE\n", unit->sdcu_UnitNum));
61 DERROR(bug("[SDCard%02ld] -- IO ACCESS TO BLOCK %08lx:%08lx, LENGTH %08lx\n", unit->sdcu_UnitNum, (blk >> 32), (blk & 0xffffffff), len));
62 return CDERR_NOCMD;
65 static BYTE sdcard_STUB_SCSI(struct sdcard_Unit *unit, struct SCSICmd* cmd)
67 DERROR(bug("[SDCard%02ld] CALLED STUB FUNCTION (IOSCSI). OPERATION IS NOT SUPPORTED BY DEVICE\n", unit->sdcu_UnitNum));
68 return CDERR_NOCMD;
71 static inline BOOL sdcard_SelectUnit(struct sdcard_Unit* unit)
73 return TRUE;
76 void sdcard_IRQSetHandler(struct sdcard_Unit *unit, void (*handler)(struct sdcard_Unit*, UBYTE), APTR piomem, ULONG blklen, ULONG piolen)
81 void sdcard_IRQNoData(struct sdcard_Unit *unit, UBYTE status)
86 void sdcard_IRQPIORead(struct sdcard_Unit *unit, UBYTE status)
91 void sdcard_PIOWriteBlk(struct sdcard_Unit *unit)
96 void sdcard_IRQPIOWrite(struct sdcard_Unit *unit, UBYTE status)
101 void sdcard_IRQDMAReadWrite(struct sdcard_Unit *unit, UBYTE status)
107 * wait for timeout or drive ready
109 BOOL sdcard_WaitBusyTO(struct sdcard_Unit *unit, UWORD tout, BOOL irq, UBYTE *stout)
111 BYTE err = 0;
112 return err;
116 * 32bit Read operations
118 BYTE FNAME_SDCIO(ReadSector32)(struct sdcard_Unit *unit, ULONG block,
119 ULONG count, APTR buffer, ULONG *act)
121 struct TagItem sdcReadTags[] =
123 {SDCARD_TAG_CMD, MMC_CMD_READ_SINGLE_BLOCK},
124 {SDCARD_TAG_ARG, block},
125 {SDCARD_TAG_RSPTYPE, MMC_RSP_R1},
126 {SDCARD_TAG_RSP, 0},
127 {SDCARD_TAG_DATA, (IPTR)buffer},
128 {SDCARD_TAG_DATALEN, count * (1 << unit->sdcu_Bus->sdcb_SectorShift)},
129 {SDCARD_TAG_DATAFLAGS, MMC_DATA_READ},
130 {TAG_DONE, 0}
132 BYTE retVal = 0;
134 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
136 *act = 0;
138 if (count > 1)
139 sdcReadTags[0].ti_Data = MMC_CMD_READ_MULTIPLE_BLOCK;
141 if (!(unit->sdcu_Flags & AF_Card_HighCapacity))
142 sdcReadTags[1].ti_Data <<= unit->sdcu_Bus->sdcb_SectorShift;
144 D(bug("[SDCard%02ld] %s: Sending CMD %d, block %08x, len %d [buffer @ 0x%p]\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__,
145 sdcReadTags[0].ti_Data, sdcReadTags[1].ti_Data, sdcReadTags[5].ti_Data, sdcReadTags[4].ti_Data));
147 if (FNAME_SDCBUS(SendCmd)(sdcReadTags, unit->sdcu_Bus) != -1)
149 if (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 100000, unit->sdcu_Bus) != -1)
151 if (count > 1)
153 DTRANS(bug("[SDCard%02ld] %s: Finishing transaction ..\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
154 sdcReadTags[0].ti_Data = MMC_CMD_STOP_TRANSMISSION;
155 sdcReadTags[1].ti_Data = 0;
156 sdcReadTags[2].ti_Data = MMC_RSP_R1b;
157 sdcReadTags[4].ti_Tag = TAG_DONE;
158 if (FNAME_SDCBUS(SendCmd)(sdcReadTags, unit->sdcu_Bus) == -1)
160 bug("[SDCard%02ld] %s: Failed to terminate Read operation\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__);
163 *act = sdcReadTags[5].ti_Data;
165 else
167 bug("[SDCard%02ld] %s: Transfer error\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__);
168 retVal = IOERR_ABORTED;
171 else
173 bug("[SDCard%02ld] %s: Error ..\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__);
174 retVal = IOERR_ABORTED;
177 DTRANS(bug("[SDCard%02ld] %s: %d bytes Read\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__, *act));
179 return retVal;
182 BYTE FNAME_SDCIO(ReadMultiple32)(struct sdcard_Unit *unit, ULONG block,
183 ULONG count, APTR buffer, ULONG *act)
186 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
188 return IOERR_NOCMD;
191 BYTE FNAME_SDCIO(ReadDMA32)(struct sdcard_Unit *unit, ULONG block,
192 ULONG count, APTR buffer, ULONG *act)
194 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
196 return IOERR_NOCMD;
200 * 64bit Read operations
202 BYTE FNAME_SDCIO(ReadSector64)(struct sdcard_Unit *unit, UQUAD block,
203 ULONG count, APTR buffer, ULONG *act)
205 struct TagItem sdcReadTags[] =
207 {SDCARD_TAG_CMD, MMC_CMD_READ_SINGLE_BLOCK},
208 {SDCARD_TAG_ARG, block},
209 {SDCARD_TAG_RSPTYPE, MMC_RSP_R1},
210 {SDCARD_TAG_RSP, 0},
211 {SDCARD_TAG_DATA, (IPTR)buffer},
212 {SDCARD_TAG_DATALEN, count * (1 << unit->sdcu_Bus->sdcb_SectorShift)},
213 {SDCARD_TAG_DATAFLAGS, MMC_DATA_READ},
214 {TAG_DONE, 0}
216 BYTE retVal = 0;
218 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
220 *act = 0;
222 if (count > 1)
223 sdcReadTags[0].ti_Data = MMC_CMD_READ_MULTIPLE_BLOCK;
225 if (!(unit->sdcu_Flags & AF_Card_HighCapacity))
226 return IOERR_NOCMD;
228 D(bug("[SDCard%02ld] %s: Sending CMD %d, block %08x, len %d [buffer @ 0x%p]\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__,
229 sdcReadTags[0].ti_Data, sdcReadTags[1].ti_Data, sdcReadTags[5].ti_Data, sdcReadTags[4].ti_Data));
231 if (FNAME_SDCBUS(SendCmd)(sdcReadTags, unit->sdcu_Bus) != -1)
233 if (FNAME_SDCBUS(WaitCmd)(SDHCI_PS_CMD_INHIBIT|SDHCI_PS_DATA_INHIBIT, 100000, unit->sdcu_Bus) != -1)
235 if (count > 1)
237 DTRANS(bug("[SDCard%02ld] %s: Finishing transaction ..\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
238 sdcReadTags[0].ti_Data = MMC_CMD_STOP_TRANSMISSION;
239 sdcReadTags[1].ti_Data = 0;
240 sdcReadTags[2].ti_Data = MMC_RSP_R1b;
241 sdcReadTags[4].ti_Tag = TAG_DONE;
242 if (FNAME_SDCBUS(SendCmd)(sdcReadTags, unit->sdcu_Bus) == -1)
244 bug("[SDCard%02ld] %s: Failed to terminate Read operation\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__);
247 *act = sdcReadTags[5].ti_Data;
249 else
251 bug("[SDCard%02ld] %s: Transfer error\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__);
252 retVal = IOERR_ABORTED;
255 else
257 bug("[SDCard%02ld] %s: Error ..\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__);
258 retVal = IOERR_ABORTED;
261 DTRANS(bug("[SDCard%02ld] %s: %d bytes Read\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__, *act));
263 return retVal;
266 BYTE FNAME_SDCIO(ReadMultiple64)(struct sdcard_Unit *unit, UQUAD block,
267 ULONG count, APTR buffer, ULONG *act)
269 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
271 return IOERR_NOCMD;
274 BYTE FNAME_SDCIO(ReadDMA64)(struct sdcard_Unit *unit, UQUAD block,
275 ULONG count, APTR buffer, ULONG *act)
277 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
279 return IOERR_NOCMD;
283 * 32bit Write operations
285 BYTE FNAME_SDCIO(WriteSector32)(struct sdcard_Unit *unit, ULONG block,
286 ULONG count, APTR buffer, ULONG *act)
288 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
290 return IOERR_NOCMD;
293 BYTE FNAME_SDCIO(WriteMultiple32)(struct sdcard_Unit *unit, ULONG block,
294 ULONG count, APTR buffer, ULONG *act)
296 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
298 return IOERR_NOCMD;
301 BYTE FNAME_SDCIO(WriteDMA32)(struct sdcard_Unit *unit, ULONG block,
302 ULONG count, APTR buffer, ULONG *act)
304 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
306 return IOERR_NOCMD;
310 * 64bit Write operations
312 BYTE FNAME_SDCIO(WriteSector64)(struct sdcard_Unit *unit, UQUAD block,
313 ULONG count, APTR buffer, ULONG *act)
315 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
317 return IOERR_NOCMD;
320 BYTE FNAME_SDCIO(WriteMultiple64)(struct sdcard_Unit *unit, UQUAD block,
321 ULONG count, APTR buffer, ULONG *act)
323 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
325 return IOERR_NOCMD;
328 BYTE FNAME_SDCIO(WriteDMA64)(struct sdcard_Unit *unit, UQUAD block,
329 ULONG count, APTR buffer, ULONG *act)
331 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
333 return IOERR_NOCMD;
337 * miscellaneous
339 BYTE FNAME_SDCIO(Eject)(struct sdcard_Unit *unit)
341 D(bug("[SDCard%02ld] %s()\n", unit->sdcu_UnitNum, __PRETTY_FUNCTION__));
343 return IOERR_NOCMD;