dont set 4bit data mode, or enable acmd12/dma int's in init. set the highest support...
[AROS.git] / arch / arm-raspi / devs / sdcard / sdcard_intern.h
blob04142c60484cfd84e4f321c4a0bccab43088ddb7
1 #ifndef _SDCARD_INTERN_H
2 #define _SDCARD_INTERN_H
3 /*
4 Copyright © 2013, The AROS Development Team. All rights reserved.
5 $Id$
6 */
8 #include <exec/types.h>
9 #include <exec/devices.h>
10 #include <exec/semaphores.h>
11 #include <exec/execbase.h>
12 #include <exec/libraries.h>
13 #include <exec/ports.h>
14 #include <utility/utility.h>
15 #include <exec/io.h>
16 #include <exec/errors.h>
17 #include <devices/trackdisk.h>
18 #include <devices/scsidisk.h>
19 #include <devices/newstyle.h>
20 #include <devices/timer.h>
21 #include <devices/cd.h>
23 #define FNAME_SDC(x) SDCARD__Device__ ## x
24 #define FNAME_SDCIO(x) SDCARD__SDIO__ ## x
25 #define FNAME_SDCBUS(x) SDCARD__SDBus__ ## x
27 #define TASK_PRI 10
28 #define TIMEOUT 30
30 #define HOSTCLOCK_MIN 400000
31 #define V200_MAXCLKDIV 256
32 #define V300_MAXCLKDIV 2046
34 #define SDCARD_TAGBASE (TAG_USER | 0x00534400)
36 #define SDCARD_TAG_CMD (SDCARD_TAGBASE + 1)
37 #define SDCARD_TAG_ARG (SDCARD_TAGBASE + 2)
38 #define SDCARD_TAG_RSPTYPE (SDCARD_TAGBASE + 3)
39 #define SDCARD_TAG_RSP (SDCARD_TAGBASE + 4)
40 #define SDCARD_TAG_DATA (SDCARD_TAGBASE + 5)
41 #define SDCARD_TAG_DATALEN (SDCARD_TAGBASE + 6)
42 #define SDCARD_TAG_DATAFLAGS (SDCARD_TAGBASE + 7)
44 /* structure forward declarations */
45 struct sdcard_Unit;
46 struct sdcard_Bus;
48 /* sdhc.device base */
49 struct SDCardBase
51 /* standard device structure */
52 struct Device sdcard_Device;
54 /* Imports */
55 struct Device *sdcard_TimerBase;
56 APTR sdcard_VCMBoxBase;
58 /* Bus's (to be replaced with hidds...) */
59 struct sdcard_Bus *sdcard_Bus;
61 /* Memory Management */
62 APTR sdcard_MemPool;
65 struct sdcard_Bus
67 struct SDCardBase *sdcb_DeviceBase; /* Device self */
69 APTR sdcb_IOBase;
70 ULONG sdcb_BusNum;
72 UBYTE sdcb_BusFlags; /* Bus flags similar to unit flags */
73 UBYTE sdcb_TaskSig; /* Signal used to wake task */
74 UBYTE sdcb_SectorShift; /* Sector shift. 9 here is 512 bytes sector */
76 struct Task *sdcb_Task;
77 struct MsgPort *sdcb_MsgPort;
78 struct IORequest *sdcb_Timer; /* timer stuff */
80 /* Chipset .. */
81 ULONG sdcb_Capabilities;
82 ULONG sdcb_Version;
83 ULONG sdcb_ClockMax;
84 ULONG sdcb_Power;
86 ULONG sdcb_IntrMask;
88 ULONG sdcb_LastWrite;
90 ULONG sdcb_UnitCnt;
91 struct sdcard_Unit *sdcb_Units[1]; /* Units on the bus */
95 Unit structure describing given device on the bus. It contains all the
96 necessary information unit/device may need.
98 struct sdcard_Unit
100 struct Unit sdcu_Unit; /* exec's unit */
101 struct sdcard_Bus *sdcu_Bus; /* Bus on which this unit is */
102 ULONG sdcu_Flags; /* Unit flags, see below */
103 ULONG sdcu_UnitNum; /* Unit number as coded by device */
104 ULONG sdcu_CardRCA;
106 ULONG sdcu_CardPower; /* voltages supported by card/controller */
108 UQUAD sdcu_Capacity; /* Real capacity of device */
110 /* OLD DEFINES */
112 ULONG sdcu_DMAPort;
114 ULONG sdcu_Cylinders;
115 UBYTE sdcu_Heads;
116 UBYTE sdcu_Sectors;
117 UBYTE sdcu_Model[41];
118 UBYTE sdcu_FirmwareRev[9];
119 UBYTE sdcu_SerialNumber[21];
122 Here are stored pointers to functions responsible for handling this
123 device. They are set during device initialization and point to most
124 effective functions for this particular unit. Read/Write may be done
125 in PIO mode reading single sectors, using multisector PIO, or
126 multiword DMA.
128 BYTE (*sdcu_Read32)(struct sdcard_Unit *, ULONG, ULONG, APTR, ULONG *);
129 BYTE (*sdcu_Write32)(struct sdcard_Unit *, ULONG, ULONG, APTR, ULONG *);
130 BYTE (*sdcu_Read64)(struct sdcard_Unit *, UQUAD, ULONG, APTR, ULONG *);
131 BYTE (*sdcu_Write64)(struct sdcard_Unit *, UQUAD, ULONG, APTR, ULONG *);
132 BYTE (*sdcu_Eject)(struct sdcard_Unit *);
133 BYTE (*sdcu_DirectSCSI)(struct sdcard_Unit *, struct SCSICmd*);
135 ULONG sdcu_ChangeNum; /* Number of disc changes */
137 struct Interrupt *sdcu_RemoveInt; /* Raise this interrupt on a disc change */
138 struct List sdcu_SoftList; /* Raise even more interrupts from this list on disc change */
140 UBYTE sdcu_DevMask; /* device mask used to simplify device number coding */
141 UBYTE sdcu_SenseKey; /* Sense key from ATAPI devices */
142 UBYTE sdcu_DevType;
144 /******* PIO IO ********/
145 APTR sdcu_cmd_data;
146 ULONG sdcu_cmd_length;
147 ULONG sdcu_cmd_total;
148 ULONG sdcu_cmd_error;
151 /* Unit internal flags */
152 #define AB_MediaPresent 30 /* media available */
153 #define AB_MediaChanged 29 /* media changed */
154 #define AB_HighSpeed 28
155 #define AB_HighCapacity 27
156 #define AB_MMC 26
157 #define AB_4bitData 25
159 #define AF_MediaPresent (1 << AB_MediaPresent)
160 #define AF_MediaChanged (1 << AB_MediaChanged)
161 #define AF_HighSpeed (1 << AB_HighSpeed)
162 #define AF_HighCapacity (1 << AB_HighCapacity)
163 #define AF_MMC (1 << AB_MMC)
164 #define AF_4bitData (1 << AB_4bitData)
166 #define Unit(io) ((struct sdcard_Unit *)(io)->io_Unit)
167 #define IOStdReq(io) ((struct IOStdReq *)io)
169 UBYTE FNAME_SDCBUS(MMIOReadByte)(ULONG, struct sdcard_Bus *);
170 UWORD FNAME_SDCBUS(MMIOReadWord)(ULONG, struct sdcard_Bus *);
171 ULONG FNAME_SDCBUS(MMIOReadLong)(ULONG, struct sdcard_Bus *);
173 void FNAME_SDCBUS(MMIOWriteByte)(ULONG, UBYTE, struct sdcard_Bus *);
174 void FNAME_SDCBUS(MMIOWriteWord)(ULONG, UWORD, struct sdcard_Bus *);
175 void FNAME_SDCBUS(MMIOWriteLong)(ULONG, ULONG, struct sdcard_Bus *);
177 void FNAME_SDCBUS(SoftReset)(UBYTE, struct sdcard_Bus *);
178 ULONG FNAME_SDCBUS(SendCmd)(struct TagItem *, struct sdcard_Bus *);
179 ULONG FNAME_SDCBUS(Rsp136Unpack)(ULONG *, ULONG, const ULONG);
181 void FNAME_SDCBUS(BusTask)(struct sdcard_Bus *);
183 BOOL FNAME_SDC(RegisterVolume)(struct sdcard_Bus *);
185 int FNAME_SDCBUS(SDUnitChangeFrequency)(struct sdcard_Unit *);
187 BOOL FNAME_SDC(HandleIO)(struct IORequest *io);
189 /* IO Operations */
191 BYTE FNAME_SDCIO(ReadSector32)(struct sdcard_Unit *, ULONG, ULONG, APTR, ULONG *);
192 BYTE FNAME_SDCIO(ReadSector64)(struct sdcard_Unit *, UQUAD, ULONG, APTR, ULONG *);
193 BYTE FNAME_SDCIO(ReadMultiple32)(struct sdcard_Unit *, ULONG, ULONG, APTR, ULONG *);
194 BYTE FNAME_SDCIO(ReadMultiple64)(struct sdcard_Unit *, UQUAD, ULONG, APTR, ULONG *);
195 BYTE FNAME_SDCIO(ReadDMA32)(struct sdcard_Unit *, ULONG, ULONG, APTR, ULONG *);
196 BYTE FNAME_SDCIO(ReadDMA64)(struct sdcard_Unit *, UQUAD, ULONG, APTR, ULONG *);
197 BYTE FNAME_SDCIO(WriteSector32)(struct sdcard_Unit *, ULONG, ULONG, APTR, ULONG *);
198 BYTE FNAME_SDCIO(WriteSector64)(struct sdcard_Unit *, UQUAD, ULONG, APTR, ULONG *);
199 BYTE FNAME_SDCIO(WriteMultiple32)(struct sdcard_Unit *, ULONG, ULONG, APTR, ULONG *);
200 BYTE FNAME_SDCIO(WriteMultiple64)(struct sdcard_Unit *, UQUAD, ULONG, APTR, ULONG *);
201 BYTE FNAME_SDCIO(WriteDMA32)(struct sdcard_Unit *, ULONG, ULONG, APTR, ULONG *);
202 BYTE FNAME_SDCIO(WriteDMA64)(struct sdcard_Unit *, UQUAD, ULONG, APTR, ULONG *);
203 BYTE FNAME_SDCIO(Eject)(struct sdcard_Unit *);
205 #endif // _SDCARD_INTERN_H