1
2
3
4
5
6
7
8
9
10
11extern int usb_board_init(void);
12extern int usb_board_stop(void);
13extern int usb_board_init_fail(void);
14
15extern int usb_cpu_init(void);
16extern int usb_cpu_stop(void);
17extern int usb_cpu_init_fail(void);
18
19
20static int cc_to_error[16] = {
21
22
23 0,
24 USB_ST_CRC_ERR,
25 USB_ST_BIT_ERR,
26 USB_ST_CRC_ERR,
27 USB_ST_STALLED,
28 -1,
29 USB_ST_BIT_ERR,
30 USB_ST_BIT_ERR,
31 USB_ST_BUF_ERR,
32 USB_ST_BUF_ERR,
33 -1,
34 -1,
35 USB_ST_BUF_ERR,
36 USB_ST_BUF_ERR,
37 -1,
38 -1
39};
40
41static const char *cc_to_string[16] = {
42 "No Error",
43 "CRC: Last data packet from endpoint contained a CRC error.",
44 "BITSTUFFING: Last data packet from endpoint contained a bit " \
45 "stuffing violation",
46 "DATATOGGLEMISMATCH: Last packet from endpoint had data toggle PID\n" \
47 "that did not match the expected value.",
48 "STALL: TD was moved to the Done Queue because the endpoint returned" \
49 " a STALL PID",
50 "DEVICENOTRESPONDING: Device did not respond to token (IN) or did\n" \
51 "not provide a handshake (OUT)",
52 "PIDCHECKFAILURE: Check bits on PID from endpoint failed on data PID\n"\
53 "(IN) or handshake (OUT)",
54 "UNEXPECTEDPID: Receive PID was not valid when encountered or PID\n" \
55 "value is not defined.",
56 "DATAOVERRUN: The amount of data returned by the endpoint exceeded\n" \
57 "either the size of the maximum data packet allowed\n" \
58 "from the endpoint (found in MaximumPacketSize field\n" \
59 "of ED) or the remaining buffer size.",
60 "DATAUNDERRUN: The endpoint returned less than MaximumPacketSize\n" \
61 "and that amount was not sufficient to fill the\n" \
62 "specified buffer",
63 "reserved1",
64 "reserved2",
65 "BUFFEROVERRUN: During an IN, HC received data from endpoint faster\n" \
66 "than it could be written to system memory",
67 "BUFFERUNDERRUN: During an OUT, HC could not retrieve data from\n" \
68 "system memory fast enough to keep up with data USB " \
69 "data rate.",
70 "NOT ACCESSED: This code is set by software before the TD is placed" \
71 "on a list to be processed by the HC.(1)",
72 "NOT ACCESSED: This code is set by software before the TD is placed" \
73 "on a list to be processed by the HC.(2)",
74};
75
76
77
78#define ED_NEW 0x00
79#define ED_UNLINK 0x01
80#define ED_OPER 0x02
81#define ED_DEL 0x04
82#define ED_URB_DEL 0x08
83
84
85struct ed {
86 __u32 hwINFO;
87 __u32 hwTailP;
88 __u32 hwHeadP;
89 __u32 hwNextED;
90
91 struct ed *ed_prev;
92 __u8 int_period;
93 __u8 int_branch;
94 __u8 int_load;
95 __u8 int_interval;
96 __u8 state;
97 __u8 type;
98 __u16 last_iso;
99 struct ed *ed_rm_list;
100
101 struct usb_device *usb_dev;
102 void *purb;
103 __u32 unused[2];
104} __attribute__((aligned(16)));
105typedef struct ed ed_t;
106
107
108
109#define TD_CC 0xf0000000
110#define TD_CC_GET(td_p) ((td_p >>28) & 0x0f)
111#define TD_CC_SET(td_p, cc) (td_p) = ((td_p) & 0x0fffffff) | (((cc) & 0x0f) << 28)
112#define TD_EC 0x0C000000
113#define TD_T 0x03000000
114#define TD_T_DATA0 0x02000000
115#define TD_T_DATA1 0x03000000
116#define TD_T_TOGGLE 0x00000000
117#define TD_R 0x00040000
118#define TD_DI 0x00E00000
119#define TD_DI_SET(X) (((X) & 0x07)<< 21)
120#define TD_DP 0x00180000
121#define TD_DP_SETUP 0x00000000
122#define TD_DP_IN 0x00100000
123#define TD_DP_OUT 0x00080000
124
125#define TD_ISO 0x00010000
126#define TD_DEL 0x00020000
127
128
129#define TD_CC_NOERROR 0x00
130#define TD_CC_CRC 0x01
131#define TD_CC_BITSTUFFING 0x02
132#define TD_CC_DATATOGGLEM 0x03
133#define TD_CC_STALL 0x04
134#define TD_DEVNOTRESP 0x05
135#define TD_PIDCHECKFAIL 0x06
136#define TD_UNEXPECTEDPID 0x07
137#define TD_DATAOVERRUN 0x08
138#define TD_DATAUNDERRUN 0x09
139#define TD_BUFFEROVERRUN 0x0C
140#define TD_BUFFERUNDERRUN 0x0D
141#define TD_NOTACCESSED 0x0F
142
143
144#define MAXPSW 1
145
146struct td {
147 __u32 hwINFO;
148 __u32 hwCBP;
149 __u32 hwNextTD;
150 __u32 hwBE;
151
152
153 __u16 hwPSW[MAXPSW];
154
155 __u8 unused;
156 __u8 index;
157 struct ed *ed;
158 struct td *next_dl_td;
159 struct usb_device *usb_dev;
160 int transfer_len;
161 __u32 data;
162
163 __u32 unused2[2];
164} __attribute__((aligned(32)));
165typedef struct td td_t;
166
167#define OHCI_ED_SKIP (1 << 14)
168
169
170
171
172
173
174
175#define NUM_INTS 32
176struct ohci_hcca {
177 __u32 int_table[NUM_INTS];
178#if defined(CONFIG_MPC5200)
179 __u16 pad1;
180 __u16 frame_no;
181#else
182 __u16 frame_no;
183 __u16 pad1;
184#endif
185 __u32 done_head;
186 u8 reserved_for_hc[116];
187} __attribute__((aligned(256)));
188
189
190
191
192
193#ifndef CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS
194# error "CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS undefined!"
195#endif
196
197
198
199
200
201
202struct ohci_regs {
203
204 __u32 revision;
205 __u32 control;
206 __u32 cmdstatus;
207 __u32 intrstatus;
208 __u32 intrenable;
209 __u32 intrdisable;
210
211 __u32 hcca;
212 __u32 ed_periodcurrent;
213 __u32 ed_controlhead;
214 __u32 ed_controlcurrent;
215 __u32 ed_bulkhead;
216 __u32 ed_bulkcurrent;
217 __u32 donehead;
218
219 __u32 fminterval;
220 __u32 fmremaining;
221 __u32 fmnumber;
222 __u32 periodicstart;
223 __u32 lsthresh;
224
225 struct ohci_roothub_regs {
226 __u32 a;
227 __u32 b;
228 __u32 status;
229 __u32 portstatus[CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS];
230 } roothub;
231} __attribute__((aligned(32)));
232
233
234#define EHCI_USBCMD_OFF 0x20
235#define EHCI_USBCMD_HCRESET (1 << 1)
236
237
238
239
240
241
242#define OHCI_CTRL_CBSR (3 << 0)
243#define OHCI_CTRL_PLE (1 << 2)
244#define OHCI_CTRL_IE (1 << 3)
245#define OHCI_CTRL_CLE (1 << 4)
246#define OHCI_CTRL_BLE (1 << 5)
247#define OHCI_CTRL_HCFS (3 << 6)
248#define OHCI_CTRL_IR (1 << 8)
249#define OHCI_CTRL_RWC (1 << 9)
250#define OHCI_CTRL_RWE (1 << 10)
251
252
253# define OHCI_USB_RESET (0 << 6)
254# define OHCI_USB_RESUME (1 << 6)
255# define OHCI_USB_OPER (2 << 6)
256# define OHCI_USB_SUSPEND (3 << 6)
257
258
259
260
261#define OHCI_HCR (1 << 0)
262#define OHCI_CLF (1 << 1)
263#define OHCI_BLF (1 << 2)
264#define OHCI_OCR (1 << 3)
265#define OHCI_SOC (3 << 16)
266
267
268
269
270
271
272
273#define OHCI_INTR_SO (1 << 0)
274#define OHCI_INTR_WDH (1 << 1)
275#define OHCI_INTR_SF (1 << 2)
276#define OHCI_INTR_RD (1 << 3)
277#define OHCI_INTR_UE (1 << 4)
278#define OHCI_INTR_FNO (1 << 5)
279#define OHCI_INTR_RHSC (1 << 6)
280#define OHCI_INTR_OC (1 << 30)
281#define OHCI_INTR_MIE (1 << 31)
282
283
284
285struct virt_root_hub {
286 int devnum;
287 void *dev;
288 void *int_addr;
289 int send;
290 int interval;
291};
292
293
294
295
296#define RH_INTERFACE 0x01
297#define RH_ENDPOINT 0x02
298#define RH_OTHER 0x03
299
300#define RH_CLASS 0x20
301#define RH_VENDOR 0x40
302
303
304#define RH_GET_STATUS 0x0080
305#define RH_CLEAR_FEATURE 0x0100
306#define RH_SET_FEATURE 0x0300
307#define RH_SET_ADDRESS 0x0500
308#define RH_GET_DESCRIPTOR 0x0680
309#define RH_SET_DESCRIPTOR 0x0700
310#define RH_GET_CONFIGURATION 0x0880
311#define RH_SET_CONFIGURATION 0x0900
312#define RH_GET_STATE 0x0280
313#define RH_GET_INTERFACE 0x0A80
314#define RH_SET_INTERFACE 0x0B00
315#define RH_SYNC_FRAME 0x0C80
316
317#define RH_SET_EP 0x2000
318
319
320
321#define RH_PORT_CONNECTION 0x00
322#define RH_PORT_ENABLE 0x01
323#define RH_PORT_SUSPEND 0x02
324#define RH_PORT_OVER_CURRENT 0x03
325#define RH_PORT_RESET 0x04
326#define RH_PORT_POWER 0x08
327#define RH_PORT_LOW_SPEED 0x09
328
329#define RH_C_PORT_CONNECTION 0x10
330#define RH_C_PORT_ENABLE 0x11
331#define RH_C_PORT_SUSPEND 0x12
332#define RH_C_PORT_OVER_CURRENT 0x13
333#define RH_C_PORT_RESET 0x14
334
335
336#define RH_C_HUB_LOCAL_POWER 0x00
337#define RH_C_HUB_OVER_CURRENT 0x01
338
339#define RH_DEVICE_REMOTE_WAKEUP 0x00
340#define RH_ENDPOINT_STALL 0x01
341
342#define RH_ACK 0x01
343#define RH_REQ_ERR -1
344#define RH_NACK 0x00
345
346
347
348
349
350#define RH_PS_CCS 0x00000001
351#define RH_PS_PES 0x00000002
352#define RH_PS_PSS 0x00000004
353#define RH_PS_POCI 0x00000008
354#define RH_PS_PRS 0x00000010
355#define RH_PS_PPS 0x00000100
356#define RH_PS_LSDA 0x00000200
357#define RH_PS_CSC 0x00010000
358#define RH_PS_PESC 0x00020000
359#define RH_PS_PSSC 0x00040000
360#define RH_PS_OCIC 0x00080000
361#define RH_PS_PRSC 0x00100000
362
363
364#define RH_HS_LPS 0x00000001
365#define RH_HS_OCI 0x00000002
366#define RH_HS_DRWE 0x00008000
367#define RH_HS_LPSC 0x00010000
368#define RH_HS_OCIC 0x00020000
369#define RH_HS_CRWE 0x80000000
370
371
372#define RH_B_DR 0x0000ffff
373#define RH_B_PPCM 0xffff0000
374
375
376#define RH_A_NDP (0xff << 0)
377#define RH_A_PSM (1 << 8)
378#define RH_A_NPS (1 << 9)
379#define RH_A_DT (1 << 10)
380#define RH_A_OCPM (1 << 11)
381#define RH_A_NOCP (1 << 12)
382#define RH_A_POTPGT (0xff << 24)
383
384
385#define N_URB_TD 48
386typedef struct
387{
388 ed_t *ed;
389 __u16 length;
390 __u16 td_cnt;
391 struct usb_device *dev;
392 int state;
393 unsigned long pipe;
394 void *transfer_buffer;
395 int transfer_buffer_length;
396 int interval;
397 int actual_length;
398 int finished;
399 td_t *td[N_URB_TD];
400} urb_priv_t;
401#define URB_DEL 1
402
403
404
405
406
407
408
409
410
411typedef struct ohci {
412 struct ohci_hcca *hcca;
413
414
415 int irq;
416 int disabled;
417 int sleeping;
418 unsigned long flags;
419
420 struct ohci_regs *regs;
421
422 int ohci_int_load[32];
423 ed_t *ed_rm_list[2];
424 ed_t *ed_bulktail;
425 ed_t *ed_controltail;
426 int intrstatus;
427 __u32 hc_control;
428 struct usb_device *dev[32];
429 struct virt_root_hub rh;
430
431 const char *slot_name;
432} ohci_t;
433
434#define NUM_EDS 8
435
436struct ohci_device {
437 ed_t ed[NUM_EDS];
438 int ed_cnt;
439};
440
441
442
443static int ep_link(ohci_t * ohci, ed_t * ed);
444static int ep_unlink(ohci_t * ohci, ed_t * ed);
445static ed_t * ep_add_ed(struct usb_device * usb_dev, unsigned long pipe,
446 int interval, int load);
447
448
449
450
451#define NUM_TD 64
452
453
454td_t gtd[NUM_TD+1];
455
456td_t *ptd;
457
458
459static inline struct td *
460td_alloc (struct usb_device *usb_dev)
461{
462 int i;
463 struct td *td;
464
465 td = NULL;
466 for (i = 0; i < NUM_TD; i++)
467 {
468 if (ptd[i].usb_dev == NULL)
469 {
470 td = &ptd[i];
471 td->usb_dev = usb_dev;
472 break;
473 }
474 }
475
476 return td;
477}
478
479static inline void
480ed_free (struct ed *ed)
481{
482 ed->usb_dev = NULL;
483}
484