blob: c37b5f6005c2a8d0ec03571c6745e65cb90763a5 [file] [log] [blame]
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +02001/*
2 * URB OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2001 David Brownell <dbrownell@users.sourceforge.net>
6 *
7 * usb-ohci.h
8 */
9
10/* functions for doing board specific setup/cleanup */
Markus Klotzbuecher24e37642006-05-23 10:33:11 +020011#ifdef CFG_USB_BOARD_INIT
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020012extern int usb_board_init(void);
13extern int usb_board_stop(void);
Markus Klotzbuecher24e37642006-05-23 10:33:11 +020014#endif
15
16#ifdef CFG_USB_CPU_INIT
17extern int usb_cpu_init(void);
18extern int usb_cpu_stop(void);
19#endif
20
Markus Klotzbuecher3e326ec2006-05-22 16:33:54 +020021
22static int cc_to_error[16] = {
23
24/* mapping of the OHCI CC status to error codes */
25 /* No Error */ 0,
26 /* CRC Error */ USB_ST_CRC_ERR,
27 /* Bit Stuff */ USB_ST_BIT_ERR,
28 /* Data Togg */ USB_ST_CRC_ERR,
29 /* Stall */ USB_ST_STALLED,
30 /* DevNotResp */ -1,
31 /* PIDCheck */ USB_ST_BIT_ERR,
32 /* UnExpPID */ USB_ST_BIT_ERR,
33 /* DataOver */ USB_ST_BUF_ERR,
34 /* DataUnder */ USB_ST_BUF_ERR,
35 /* reservd */ -1,
36 /* reservd */ -1,
37 /* BufferOver */ USB_ST_BUF_ERR,
38 /* BuffUnder */ USB_ST_BUF_ERR,
39 /* Not Access */ -1,
40 /* Not Access */ -1
41};
42
43/* ED States */
44
45#define ED_NEW 0x00
46#define ED_UNLINK 0x01
47#define ED_OPER 0x02
48#define ED_DEL 0x04
49#define ED_URB_DEL 0x08
50
51/* usb_ohci_ed */
52struct ed {
53 __u32 hwINFO;
54 __u32 hwTailP;
55 __u32 hwHeadP;
56 __u32 hwNextED;
57
58 struct ed *ed_prev;
59 __u8 int_period;
60 __u8 int_branch;
61 __u8 int_load;
62 __u8 int_interval;
63 __u8 state;
64 __u8 type;
65 __u16 last_iso;
66 struct ed *ed_rm_list;
67
68 struct usb_device *usb_dev;
69 __u32 unused[3];
70} __attribute((aligned(16)));
71typedef struct ed ed_t;
72
73
74/* TD info field */
75#define TD_CC 0xf0000000
76#define TD_CC_GET(td_p) ((td_p >>28) & 0x0f)
77#define TD_CC_SET(td_p, cc) (td_p) = ((td_p) & 0x0fffffff) | (((cc) & 0x0f) << 28)
78#define TD_EC 0x0C000000
79#define TD_T 0x03000000
80#define TD_T_DATA0 0x02000000
81#define TD_T_DATA1 0x03000000
82#define TD_T_TOGGLE 0x00000000
83#define TD_R 0x00040000
84#define TD_DI 0x00E00000
85#define TD_DI_SET(X) (((X) & 0x07)<< 21)
86#define TD_DP 0x00180000
87#define TD_DP_SETUP 0x00000000
88#define TD_DP_IN 0x00100000
89#define TD_DP_OUT 0x00080000
90
91#define TD_ISO 0x00010000
92#define TD_DEL 0x00020000
93
94/* CC Codes */
95#define TD_CC_NOERROR 0x00
96#define TD_CC_CRC 0x01
97#define TD_CC_BITSTUFFING 0x02
98#define TD_CC_DATATOGGLEM 0x03
99#define TD_CC_STALL 0x04
100#define TD_DEVNOTRESP 0x05
101#define TD_PIDCHECKFAIL 0x06
102#define TD_UNEXPECTEDPID 0x07
103#define TD_DATAOVERRUN 0x08
104#define TD_DATAUNDERRUN 0x09
105#define TD_BUFFEROVERRUN 0x0C
106#define TD_BUFFERUNDERRUN 0x0D
107#define TD_NOTACCESSED 0x0F
108
109
110#define MAXPSW 1
111
112struct td {
113 __u32 hwINFO;
114 __u32 hwCBP; /* Current Buffer Pointer */
115 __u32 hwNextTD; /* Next TD Pointer */
116 __u32 hwBE; /* Memory Buffer End Pointer */
117
118 __u16 hwPSW[MAXPSW];
119 __u8 unused;
120 __u8 index;
121 struct ed *ed;
122 struct td *next_dl_td;
123 struct usb_device *usb_dev;
124 int transfer_len;
125 __u32 data;
126
127 __u32 unused2[2];
128} __attribute((aligned(32)));
129typedef struct td td_t;
130
131#define OHCI_ED_SKIP (1 << 14)
132
133/*
134 * The HCCA (Host Controller Communications Area) is a 256 byte
135 * structure defined in the OHCI spec. that the host controller is
136 * told the base address of. It must be 256-byte aligned.
137 */
138
139#define NUM_INTS 32 /* part of the OHCI standard */
140struct ohci_hcca {
141 __u32 int_table[NUM_INTS]; /* Interrupt ED table */
142 __u16 frame_no; /* current frame number */
143 __u16 pad1; /* set to 0 on each frame_no change */
144 __u32 done_head; /* info returned for an interrupt */
145 u8 reserved_for_hc[116];
146} __attribute((aligned(256)));
147
148
149/*
150 * Maximum number of root hub ports.
151 */
152#define MAX_ROOT_PORTS 3 /* maximum OHCI root hub ports */
153
154/*
155 * This is the structure of the OHCI controller's memory mapped I/O
156 * region. This is Memory Mapped I/O. You must use the readl() and
157 * writel() macros defined in asm/io.h to access these!!
158 */
159struct ohci_regs {
160 /* control and status registers */
161 __u32 revision;
162 __u32 control;
163 __u32 cmdstatus;
164 __u32 intrstatus;
165 __u32 intrenable;
166 __u32 intrdisable;
167 /* memory pointers */
168 __u32 hcca;
169 __u32 ed_periodcurrent;
170 __u32 ed_controlhead;
171 __u32 ed_controlcurrent;
172 __u32 ed_bulkhead;
173 __u32 ed_bulkcurrent;
174 __u32 donehead;
175 /* frame counters */
176 __u32 fminterval;
177 __u32 fmremaining;
178 __u32 fmnumber;
179 __u32 periodicstart;
180 __u32 lsthresh;
181 /* Root hub ports */
182 struct ohci_roothub_regs {
183 __u32 a;
184 __u32 b;
185 __u32 status;
186 __u32 portstatus[MAX_ROOT_PORTS];
187 } roothub;
188} __attribute((aligned(32)));
189
190
191/* OHCI CONTROL AND STATUS REGISTER MASKS */
192
193/*
194 * HcControl (control) register masks
195 */
196#define OHCI_CTRL_CBSR (3 << 0) /* control/bulk service ratio */
197#define OHCI_CTRL_PLE (1 << 2) /* periodic list enable */
198#define OHCI_CTRL_IE (1 << 3) /* isochronous enable */
199#define OHCI_CTRL_CLE (1 << 4) /* control list enable */
200#define OHCI_CTRL_BLE (1 << 5) /* bulk list enable */
201#define OHCI_CTRL_HCFS (3 << 6) /* host controller functional state */
202#define OHCI_CTRL_IR (1 << 8) /* interrupt routing */
203#define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
204#define OHCI_CTRL_RWE (1 << 10) /* remote wakeup enable */
205
206/* pre-shifted values for HCFS */
207# define OHCI_USB_RESET (0 << 6)
208# define OHCI_USB_RESUME (1 << 6)
209# define OHCI_USB_OPER (2 << 6)
210# define OHCI_USB_SUSPEND (3 << 6)
211
212/*
213 * HcCommandStatus (cmdstatus) register masks
214 */
215#define OHCI_HCR (1 << 0) /* host controller reset */
216#define OHCI_CLF (1 << 1) /* control list filled */
217#define OHCI_BLF (1 << 2) /* bulk list filled */
218#define OHCI_OCR (1 << 3) /* ownership change request */
219#define OHCI_SOC (3 << 16) /* scheduling overrun count */
220
221/*
222 * masks used with interrupt registers:
223 * HcInterruptStatus (intrstatus)
224 * HcInterruptEnable (intrenable)
225 * HcInterruptDisable (intrdisable)
226 */
227#define OHCI_INTR_SO (1 << 0) /* scheduling overrun */
228#define OHCI_INTR_WDH (1 << 1) /* writeback of done_head */
229#define OHCI_INTR_SF (1 << 2) /* start frame */
230#define OHCI_INTR_RD (1 << 3) /* resume detect */
231#define OHCI_INTR_UE (1 << 4) /* unrecoverable error */
232#define OHCI_INTR_FNO (1 << 5) /* frame number overflow */
233#define OHCI_INTR_RHSC (1 << 6) /* root hub status change */
234#define OHCI_INTR_OC (1 << 30) /* ownership change */
235#define OHCI_INTR_MIE (1 << 31) /* master interrupt enable */
236
237
238/* Virtual Root HUB */
239struct virt_root_hub {
240 int devnum; /* Address of Root Hub endpoint */
241 void *dev; /* was urb */
242 void *int_addr;
243 int send;
244 int interval;
245};
246
247/* USB HUB CONSTANTS (not OHCI-specific; see hub.h) */
248
249/* destination of request */
250#define RH_INTERFACE 0x01
251#define RH_ENDPOINT 0x02
252#define RH_OTHER 0x03
253
254#define RH_CLASS 0x20
255#define RH_VENDOR 0x40
256
257/* Requests: bRequest << 8 | bmRequestType */
258#define RH_GET_STATUS 0x0080
259#define RH_CLEAR_FEATURE 0x0100
260#define RH_SET_FEATURE 0x0300
261#define RH_SET_ADDRESS 0x0500
262#define RH_GET_DESCRIPTOR 0x0680
263#define RH_SET_DESCRIPTOR 0x0700
264#define RH_GET_CONFIGURATION 0x0880
265#define RH_SET_CONFIGURATION 0x0900
266#define RH_GET_STATE 0x0280
267#define RH_GET_INTERFACE 0x0A80
268#define RH_SET_INTERFACE 0x0B00
269#define RH_SYNC_FRAME 0x0C80
270/* Our Vendor Specific Request */
271#define RH_SET_EP 0x2000
272
273
274/* Hub port features */
275#define RH_PORT_CONNECTION 0x00
276#define RH_PORT_ENABLE 0x01
277#define RH_PORT_SUSPEND 0x02
278#define RH_PORT_OVER_CURRENT 0x03
279#define RH_PORT_RESET 0x04
280#define RH_PORT_POWER 0x08
281#define RH_PORT_LOW_SPEED 0x09
282
283#define RH_C_PORT_CONNECTION 0x10
284#define RH_C_PORT_ENABLE 0x11
285#define RH_C_PORT_SUSPEND 0x12
286#define RH_C_PORT_OVER_CURRENT 0x13
287#define RH_C_PORT_RESET 0x14
288
289/* Hub features */
290#define RH_C_HUB_LOCAL_POWER 0x00
291#define RH_C_HUB_OVER_CURRENT 0x01
292
293#define RH_DEVICE_REMOTE_WAKEUP 0x00
294#define RH_ENDPOINT_STALL 0x01
295
296#define RH_ACK 0x01
297#define RH_REQ_ERR -1
298#define RH_NACK 0x00
299
300
301/* OHCI ROOT HUB REGISTER MASKS */
302
303/* roothub.portstatus [i] bits */
304#define RH_PS_CCS 0x00000001 /* current connect status */
305#define RH_PS_PES 0x00000002 /* port enable status*/
306#define RH_PS_PSS 0x00000004 /* port suspend status */
307#define RH_PS_POCI 0x00000008 /* port over current indicator */
308#define RH_PS_PRS 0x00000010 /* port reset status */
309#define RH_PS_PPS 0x00000100 /* port power status */
310#define RH_PS_LSDA 0x00000200 /* low speed device attached */
311#define RH_PS_CSC 0x00010000 /* connect status change */
312#define RH_PS_PESC 0x00020000 /* port enable status change */
313#define RH_PS_PSSC 0x00040000 /* port suspend status change */
314#define RH_PS_OCIC 0x00080000 /* over current indicator change */
315#define RH_PS_PRSC 0x00100000 /* port reset status change */
316
317/* roothub.status bits */
318#define RH_HS_LPS 0x00000001 /* local power status */
319#define RH_HS_OCI 0x00000002 /* over current indicator */
320#define RH_HS_DRWE 0x00008000 /* device remote wakeup enable */
321#define RH_HS_LPSC 0x00010000 /* local power status change */
322#define RH_HS_OCIC 0x00020000 /* over current indicator change */
323#define RH_HS_CRWE 0x80000000 /* clear remote wakeup enable */
324
325/* roothub.b masks */
326#define RH_B_DR 0x0000ffff /* device removable flags */
327#define RH_B_PPCM 0xffff0000 /* port power control mask */
328
329/* roothub.a masks */
330#define RH_A_NDP (0xff << 0) /* number of downstream ports */
331#define RH_A_PSM (1 << 8) /* power switching mode */
332#define RH_A_NPS (1 << 9) /* no power switching */
333#define RH_A_DT (1 << 10) /* device type (mbz) */
334#define RH_A_OCPM (1 << 11) /* over current protection mode */
335#define RH_A_NOCP (1 << 12) /* no over current protection */
336#define RH_A_POTPGT (0xff << 24) /* power on to power good time */
337
338/* urb */
339#define N_URB_TD 48
340typedef struct
341{
342 ed_t *ed;
343 __u16 length; /* number of tds associated with this request */
344 __u16 td_cnt; /* number of tds already serviced */
345 int state;
346 unsigned long pipe;
347 int actual_length;
348 td_t *td[N_URB_TD]; /* list pointer to all corresponding TDs associated with this request */
349} urb_priv_t;
350#define URB_DEL 1
351
352/*
353 * This is the full ohci controller description
354 *
355 * Note how the "proper" USB information is just
356 * a subset of what the full implementation needs. (Linus)
357 */
358
359
360typedef struct ohci {
361 struct ohci_hcca *hcca; /* hcca */
362 /*dma_addr_t hcca_dma;*/
363
364 int irq;
365 int disabled; /* e.g. got a UE, we're hung */
366 int sleeping;
367 unsigned long flags; /* for HC bugs */
368
369 struct ohci_regs *regs; /* OHCI controller's memory */
370
371 ed_t *ed_rm_list[2]; /* lists of all endpoints to be removed */
372 ed_t *ed_bulktail; /* last endpoint of bulk list */
373 ed_t *ed_controltail; /* last endpoint of control list */
374 int intrstatus;
375 __u32 hc_control; /* copy of the hc control reg */
376 struct usb_device *dev[32];
377 struct virt_root_hub rh;
378
379 const char *slot_name;
380} ohci_t;
381
382#define NUM_EDS 8 /* num of preallocated endpoint descriptors */
383
384struct ohci_device {
385 ed_t ed[NUM_EDS];
386 int ed_cnt;
387};
388
389/* hcd */
390/* endpoint */
391static int ep_link(ohci_t * ohci, ed_t * ed);
392static int ep_unlink(ohci_t * ohci, ed_t * ed);
393static ed_t * ep_add_ed(struct usb_device * usb_dev, unsigned long pipe);
394
395/*-------------------------------------------------------------------------*/
396
397/* we need more TDs than EDs */
398#define NUM_TD 64
399
400/* +1 so we can align the storage */
401td_t gtd[NUM_TD+1];
402/* pointers to aligned storage */
403td_t *ptd;
404
405/* TDs ... */
406static inline struct td *
407td_alloc (struct usb_device *usb_dev)
408{
409 int i;
410 struct td *td;
411
412 td = NULL;
413 for (i = 0; i < NUM_TD; i++)
414 {
415 if (ptd[i].usb_dev == NULL)
416 {
417 td = &ptd[i];
418 td->usb_dev = usb_dev;
419 break;
420 }
421 }
422
423 return td;
424}
425
426static inline void
427ed_free (struct ed *ed)
428{
429 ed->usb_dev = NULL;
430}