1 #ifndef USB2OTG_INTERN_H
2 #define USB2OTG_INTERN_H
4 Copyright © 2013-2019, The AROS Development Team. All rights reserved.
8 #include LC_LIBDEFS_FILE
10 #include <aros/libcall.h>
11 #include <aros/asmcall.h>
12 #include <aros/symbolsets.h>
14 #include <exec/types.h>
15 #include <exec/lists.h>
16 #include <exec/memory.h>
17 #include <exec/libraries.h>
18 #include <exec/interrupts.h>
19 #include <exec/semaphores.h>
20 #include <exec/execbase.h>
21 #include <exec/devices.h>
23 #include <exec/ports.h>
24 #include <exec/errors.h>
25 #include <exec/resident.h>
26 #include <exec/initializers.h>
29 #include <devices/timer.h>
30 #include <utility/utility.h>
32 #include <devices/usbhardware.h>
33 #include <devices/newstyle.h>
37 extern IPTR __arm_periiobase
;
38 #define ARM_PERIIOBASE __arm_periiobase
39 #include <hardware/bcm2708.h>
40 #include <hardware/usb2otg.h>
43 Force the USB chipset to run in Host mode
44 AFAIK Poseidon doesnt support device mode? - TODO
46 //#define OTG_FORCEHOSTMODE
47 //#define OTG_FORCEDEVICEMODE
51 /* Reply the iorequest with success */
54 /* Magic cookie, don't set error fields & don't reply the ioreq */
55 #define RC_DONTREPLY -1
57 #define MAX_ROOT_PORTS 16
59 #define VCMB_PROPCHAN 8
60 #define VCPOWER_USBHCD 3
61 #define VCPOWER_STATE_ON 1
62 #define VCPOWER_STATE_WAIT 2
64 static inline ULONG
rd32le(IPTR iobase
) {
67 val
= AROS_LE2LONG(*(volatile ULONG
*)(iobase
));
72 static inline UWORD
rd16le(IPTR iobase
) {
75 val
= AROS_LE2WORD(*(volatile UWORD
*)(iobase
));
80 static inline UBYTE
rd8(IPTR iobase
) {
83 val
= *(volatile UBYTE
*)(iobase
);
88 static inline void wr32le(IPTR iobase
, ULONG value
) {
90 *(volatile ULONG
*)(iobase
) = AROS_LONG2LE(value
);
94 static inline void wr16le(IPTR iobase
, UWORD value
) {
96 *(volatile UWORD
*)(iobase
) = AROS_WORD2LE(value
);
100 static inline void wr8be(IPTR iobase
, UBYTE value
) {
102 *(volatile UBYTE
*)(iobase
) = value
;
106 struct USBNSDeviceQueryResult
108 ULONG DevQueryFormat
;
112 const UWORD
*SupportedCommands
; /* 0 terminated list of cmd's */
119 struct List hu_IOPendingQueue
; /* Root Hub Pending IO Requests */
121 struct List hu_TDQueue
;
122 struct List hu_PeriodicTDQueue
;
123 struct List hu_CtrlXFerQueue
;
124 struct List hu_IntXFerQueue
;
125 struct List hu_IntXFerScheduled
;
126 struct List hu_IsoXFerQueue
;
127 struct List hu_BulkXFerQueue
;
128 struct List hu_FinishedXfers
;
131 struct USB2OTGChannel
{
132 struct IOUsbHWReq
* hc_Request
;
136 // struct IOUsbHWReq * hu_InProgressXFer[8];
137 // ULONG hu_InProgressXFerSize[8];
139 struct List hu_AbortQueue
;
141 APTR hu_GlobalIRQHandle
;
142 struct Interrupt hu_PendingInt
;
143 struct Interrupt hu_NakTimeoutInt
;
144 struct timerequest hu_NakTimeoutReq
;
145 struct MsgPort hu_NakTimeoutMsgPort
;
147 UBYTE hu_OperatingMode
; /* HOST/DEVICE mode */
153 BOOL hu_UnitAllocated
; /* unit opened */
154 BOOL hu_HubPortChanged
; /* Root port state change */
157 ULONG hu_XferSizeWidth
;
158 ULONG hu_PktSizeWidth
;
160 ULONG hu_PIDBits
[128]; /* PID 2-bit pairs, one ULONG per device, each ULONG contains 2-bits for every endpoint */
163 /* PRIVATE device node */
166 struct Library hd_Library
; /* standard */
167 UWORD hd_Flags
; /* various flags */
169 APTR hd_KernelBase
; /* kernel.resource base */
170 APTR hd_UtilityBase
; /* for tags etc */
172 APTR hd_MemPool
; /* memory pool */
174 struct USB2OTGUnit
*hd_Unit
; /* we only currently support a single unit.. */
176 struct MsgPort
*hd_MsgPort
;
177 struct timerequest
*hd_TimerReq
; /* Timer I/O Requests */
181 #define FNAME_DEV(x) USB2OTG__Dev__ ## x
182 #define FNAME_ROOTHUB(x) USB2OTG__RootHub__ ## x
192 #define UtilityBase USB2OTGBase->hd_UtilityBase
194 #define KernelBase USB2OTGBase->hd_KernelBase
196 struct Unit
*FNAME_DEV(OpenUnit
)(struct IOUsbHWReq
*, LONG
, struct USB2OTGDevice
*);
197 void FNAME_DEV(CloseUnit
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
199 void FNAME_DEV(TermIO
)(struct IOUsbHWReq
*, struct USB2OTGDevice
*);
201 WORD
FNAME_DEV(cmdNSDeviceQuery
)(struct IOStdReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
202 WORD
FNAME_DEV(cmdQueryDevice
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
204 WORD
FNAME_DEV(cmdReset
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
205 WORD
FNAME_DEV(cmdFlush
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
207 WORD
FNAME_DEV(cmdUsbReset
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
208 WORD
FNAME_DEV(cmdUsbResume
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
209 WORD
FNAME_DEV(cmdUsbSuspend
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
210 WORD
FNAME_DEV(cmdUsbOper
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
211 WORD
FNAME_DEV(cmdControlXFer
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
212 WORD
FNAME_DEV(cmdBulkXFer
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
213 WORD
FNAME_DEV(cmdIntXFer
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
214 WORD
FNAME_DEV(cmdIsoXFer
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
216 void FNAME_DEV(Cause
)(struct USB2OTGDevice
*, struct Interrupt
*);
218 WORD
FNAME_ROOTHUB(cmdControlXFer
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
219 WORD
FNAME_ROOTHUB(cmdIntXFer
)(struct IOUsbHWReq
*, struct USB2OTGUnit
*, struct USB2OTGDevice
*);
220 void FNAME_ROOTHUB(PendingIO
)(struct USB2OTGUnit
*);
222 void FNAME_DEV(GlobalIRQHandler
)(struct USB2OTGUnit
*USBUnit
, struct ExecBase
*SysBase
);
223 void FNAME_DEV(ScheduleCtrlTDs
)(struct USB2OTGUnit
*);
224 void FNAME_DEV(ScheduleBulkTDs
)(struct USB2OTGUnit
*);
225 void FNAME_DEV(ScheduleIntTDs
)(struct USB2OTGUnit
*);
226 void FNAME_DEV(SetupChannel
)(struct USB2OTGUnit
*, int chan
);
227 void FNAME_DEV(StartChannel
)(struct USB2OTGUnit
*, int chan
, int quick
);
228 int FNAME_DEV(AdvanceChannel
)(struct USB2OTGUnit
*, int chan
);
229 void FNAME_DEV(FinalizeChannel
)(struct USB2OTGUnit
*, int chan
);
240 #endif /* USB2OTG_INTERN_H */