blob: 24f5e4e3e82057c5668fa1c26c4783c1063dea6b [file] [log] [blame]
Markus Klotzbuecherd8d023f2006-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
Becky Bruce4abaacb2010-06-30 13:05:44 -050010/*
11 * e.g. PCI controllers need this
12 */
13#ifdef CONFIG_SYS_OHCI_SWAP_REG_ACCESS
14# define ohci_readl(a) __swap_32(*((volatile u32 *)(a)))
15# define ohci_writel(a, b) (*((volatile u32 *)(b)) = __swap_32((volatile u32)a))
16#else
17# define ohci_readl(a) (*((volatile u32 *)(a)))
18# define ohci_writel(a, b) (*((volatile u32 *)(b)) = ((volatile u32)a))
19#endif /* CONFIG_SYS_OHCI_SWAP_REG_ACCESS */
20
Wolfgang Denk2c195722006-06-26 11:06:00 +020021/* functions for doing board or CPU specific setup/cleanup */
Mateusz Zalegad862f892013-10-04 19:22:26 +020022int usb_board_stop(void);
Markus Klotzbuecher98095512006-05-23 10:33:11 +020023
Mateusz Zalegad862f892013-10-04 19:22:26 +020024int usb_cpu_init(void);
25int usb_cpu_stop(void);
26int usb_cpu_init_fail(void);
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +020027
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +020028/* ED States */
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +020029#define ED_NEW 0x00
30#define ED_UNLINK 0x01
31#define ED_OPER 0x02
32#define ED_DEL 0x04
33#define ED_URB_DEL 0x08
34
35/* usb_ohci_ed */
36struct ed {
37 __u32 hwINFO;
38 __u32 hwTailP;
39 __u32 hwHeadP;
40 __u32 hwNextED;
41
42 struct ed *ed_prev;
43 __u8 int_period;
44 __u8 int_branch;
45 __u8 int_load;
46 __u8 int_interval;
47 __u8 state;
48 __u8 type;
49 __u16 last_iso;
50 struct ed *ed_rm_list;
51
52 struct usb_device *usb_dev;
Zhang Wei8d15efa2007-06-06 10:08:14 +020053 void *purb;
54 __u32 unused[2];
Peter Tyser21d2cd22009-04-20 11:08:46 -050055} __attribute__((aligned(16)));
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +020056typedef struct ed ed_t;
57
58
59/* TD info field */
60#define TD_CC 0xf0000000
61#define TD_CC_GET(td_p) ((td_p >>28) & 0x0f)
62#define TD_CC_SET(td_p, cc) (td_p) = ((td_p) & 0x0fffffff) | (((cc) & 0x0f) << 28)
63#define TD_EC 0x0C000000
64#define TD_T 0x03000000
65#define TD_T_DATA0 0x02000000
66#define TD_T_DATA1 0x03000000
67#define TD_T_TOGGLE 0x00000000
68#define TD_R 0x00040000
69#define TD_DI 0x00E00000
70#define TD_DI_SET(X) (((X) & 0x07)<< 21)
71#define TD_DP 0x00180000
72#define TD_DP_SETUP 0x00000000
73#define TD_DP_IN 0x00100000
74#define TD_DP_OUT 0x00080000
75
76#define TD_ISO 0x00010000
77#define TD_DEL 0x00020000
78
79/* CC Codes */
80#define TD_CC_NOERROR 0x00
81#define TD_CC_CRC 0x01
82#define TD_CC_BITSTUFFING 0x02
83#define TD_CC_DATATOGGLEM 0x03
84#define TD_CC_STALL 0x04
85#define TD_DEVNOTRESP 0x05
86#define TD_PIDCHECKFAIL 0x06
87#define TD_UNEXPECTEDPID 0x07
88#define TD_DATAOVERRUN 0x08
89#define TD_DATAUNDERRUN 0x09
90#define TD_BUFFEROVERRUN 0x0C
91#define TD_BUFFERUNDERRUN 0x0D
92#define TD_NOTACCESSED 0x0F
93
94
95#define MAXPSW 1
96
97struct td {
98 __u32 hwINFO;
99 __u32 hwCBP; /* Current Buffer Pointer */
100 __u32 hwNextTD; /* Next TD Pointer */
101 __u32 hwBE; /* Memory Buffer End Pointer */
102
Markus Klotzbuecher661ffe52006-11-27 11:43:09 +0100103/* #ifndef CONFIG_MPC5200 /\* this seems wrong *\/ */
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200104 __u16 hwPSW[MAXPSW];
Markus Klotzbuecher661ffe52006-11-27 11:43:09 +0100105/* #endif */
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200106 __u8 unused;
107 __u8 index;
108 struct ed *ed;
109 struct td *next_dl_td;
110 struct usb_device *usb_dev;
111 int transfer_len;
112 __u32 data;
113
114 __u32 unused2[2];
Peter Tyser21d2cd22009-04-20 11:08:46 -0500115} __attribute__((aligned(32)));
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200116typedef struct td td_t;
117
118#define OHCI_ED_SKIP (1 << 14)
119
120/*
121 * The HCCA (Host Controller Communications Area) is a 256 byte
122 * structure defined in the OHCI spec. that the host controller is
123 * told the base address of. It must be 256-byte aligned.
124 */
125
126#define NUM_INTS 32 /* part of the OHCI standard */
127struct ohci_hcca {
128 __u32 int_table[NUM_INTS]; /* Interrupt ED table */
Markus Klotzbuecher661ffe52006-11-27 11:43:09 +0100129#if defined(CONFIG_MPC5200)
130 __u16 pad1; /* set to 0 on each frame_no change */
131 __u16 frame_no; /* current frame number */
132#else
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200133 __u16 frame_no; /* current frame number */
134 __u16 pad1; /* set to 0 on each frame_no change */
Markus Klotzbuecher661ffe52006-11-27 11:43:09 +0100135#endif
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200136 __u32 done_head; /* info returned for an interrupt */
137 u8 reserved_for_hc[116];
Peter Tyser21d2cd22009-04-20 11:08:46 -0500138} __attribute__((aligned(256)));
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200139
140
141/*
142 * Maximum number of root hub ports.
143 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200144#ifndef CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS
145# error "CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS undefined!"
Markus Klotzbuecher661ffe52006-11-27 11:43:09 +0100146#endif
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200147
148/*
149 * This is the structure of the OHCI controller's memory mapped I/O
Becky Bruce4abaacb2010-06-30 13:05:44 -0500150 * region. This is Memory Mapped I/O. You must use the ohci_readl() and
151 * ohci_writel() macros defined in this file to access these!!
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200152 */
153struct ohci_regs {
154 /* control and status registers */
155 __u32 revision;
156 __u32 control;
157 __u32 cmdstatus;
158 __u32 intrstatus;
159 __u32 intrenable;
160 __u32 intrdisable;
161 /* memory pointers */
162 __u32 hcca;
163 __u32 ed_periodcurrent;
164 __u32 ed_controlhead;
165 __u32 ed_controlcurrent;
166 __u32 ed_bulkhead;
167 __u32 ed_bulkcurrent;
168 __u32 donehead;
169 /* frame counters */
170 __u32 fminterval;
171 __u32 fmremaining;
172 __u32 fmnumber;
173 __u32 periodicstart;
174 __u32 lsthresh;
175 /* Root hub ports */
176 struct ohci_roothub_regs {
177 __u32 a;
178 __u32 b;
179 __u32 status;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200180 __u32 portstatus[CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS];
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200181 } roothub;
Peter Tyser21d2cd22009-04-20 11:08:46 -0500182} __attribute__((aligned(32)));
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200183
Yuri Tikhonov11af42c2008-09-04 11:19:05 +0200184/* Some EHCI controls */
185#define EHCI_USBCMD_OFF 0x20
186#define EHCI_USBCMD_HCRESET (1 << 1)
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200187
188/* OHCI CONTROL AND STATUS REGISTER MASKS */
189
190/*
191 * HcControl (control) register masks
192 */
193#define OHCI_CTRL_CBSR (3 << 0) /* control/bulk service ratio */
194#define OHCI_CTRL_PLE (1 << 2) /* periodic list enable */
195#define OHCI_CTRL_IE (1 << 3) /* isochronous enable */
196#define OHCI_CTRL_CLE (1 << 4) /* control list enable */
197#define OHCI_CTRL_BLE (1 << 5) /* bulk list enable */
198#define OHCI_CTRL_HCFS (3 << 6) /* host controller functional state */
199#define OHCI_CTRL_IR (1 << 8) /* interrupt routing */
200#define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
201#define OHCI_CTRL_RWE (1 << 10) /* remote wakeup enable */
202
203/* pre-shifted values for HCFS */
204# define OHCI_USB_RESET (0 << 6)
205# define OHCI_USB_RESUME (1 << 6)
206# define OHCI_USB_OPER (2 << 6)
207# define OHCI_USB_SUSPEND (3 << 6)
208
209/*
210 * HcCommandStatus (cmdstatus) register masks
211 */
212#define OHCI_HCR (1 << 0) /* host controller reset */
213#define OHCI_CLF (1 << 1) /* control list filled */
214#define OHCI_BLF (1 << 2) /* bulk list filled */
215#define OHCI_OCR (1 << 3) /* ownership change request */
216#define OHCI_SOC (3 << 16) /* scheduling overrun count */
217
218/*
219 * masks used with interrupt registers:
220 * HcInterruptStatus (intrstatus)
221 * HcInterruptEnable (intrenable)
222 * HcInterruptDisable (intrdisable)
223 */
224#define OHCI_INTR_SO (1 << 0) /* scheduling overrun */
225#define OHCI_INTR_WDH (1 << 1) /* writeback of done_head */
226#define OHCI_INTR_SF (1 << 2) /* start frame */
227#define OHCI_INTR_RD (1 << 3) /* resume detect */
228#define OHCI_INTR_UE (1 << 4) /* unrecoverable error */
229#define OHCI_INTR_FNO (1 << 5) /* frame number overflow */
230#define OHCI_INTR_RHSC (1 << 6) /* root hub status change */
231#define OHCI_INTR_OC (1 << 30) /* ownership change */
232#define OHCI_INTR_MIE (1 << 31) /* master interrupt enable */
233
234
235/* Virtual Root HUB */
236struct virt_root_hub {
237 int devnum; /* Address of Root Hub endpoint */
238 void *dev; /* was urb */
239 void *int_addr;
240 int send;
241 int interval;
242};
243
244/* USB HUB CONSTANTS (not OHCI-specific; see hub.h) */
245
246/* destination of request */
247#define RH_INTERFACE 0x01
248#define RH_ENDPOINT 0x02
249#define RH_OTHER 0x03
250
251#define RH_CLASS 0x20
252#define RH_VENDOR 0x40
253
254/* Requests: bRequest << 8 | bmRequestType */
255#define RH_GET_STATUS 0x0080
256#define RH_CLEAR_FEATURE 0x0100
257#define RH_SET_FEATURE 0x0300
258#define RH_SET_ADDRESS 0x0500
259#define RH_GET_DESCRIPTOR 0x0680
260#define RH_SET_DESCRIPTOR 0x0700
261#define RH_GET_CONFIGURATION 0x0880
262#define RH_SET_CONFIGURATION 0x0900
263#define RH_GET_STATE 0x0280
264#define RH_GET_INTERFACE 0x0A80
265#define RH_SET_INTERFACE 0x0B00
266#define RH_SYNC_FRAME 0x0C80
267/* Our Vendor Specific Request */
268#define RH_SET_EP 0x2000
269
270
271/* Hub port features */
272#define RH_PORT_CONNECTION 0x00
273#define RH_PORT_ENABLE 0x01
274#define RH_PORT_SUSPEND 0x02
275#define RH_PORT_OVER_CURRENT 0x03
276#define RH_PORT_RESET 0x04
277#define RH_PORT_POWER 0x08
278#define RH_PORT_LOW_SPEED 0x09
279
280#define RH_C_PORT_CONNECTION 0x10
281#define RH_C_PORT_ENABLE 0x11
282#define RH_C_PORT_SUSPEND 0x12
283#define RH_C_PORT_OVER_CURRENT 0x13
284#define RH_C_PORT_RESET 0x14
285
286/* Hub features */
287#define RH_C_HUB_LOCAL_POWER 0x00
288#define RH_C_HUB_OVER_CURRENT 0x01
289
290#define RH_DEVICE_REMOTE_WAKEUP 0x00
291#define RH_ENDPOINT_STALL 0x01
292
293#define RH_ACK 0x01
294#define RH_REQ_ERR -1
295#define RH_NACK 0x00
296
297
298/* OHCI ROOT HUB REGISTER MASKS */
299
300/* roothub.portstatus [i] bits */
301#define RH_PS_CCS 0x00000001 /* current connect status */
302#define RH_PS_PES 0x00000002 /* port enable status*/
303#define RH_PS_PSS 0x00000004 /* port suspend status */
304#define RH_PS_POCI 0x00000008 /* port over current indicator */
305#define RH_PS_PRS 0x00000010 /* port reset status */
306#define RH_PS_PPS 0x00000100 /* port power status */
307#define RH_PS_LSDA 0x00000200 /* low speed device attached */
308#define RH_PS_CSC 0x00010000 /* connect status change */
309#define RH_PS_PESC 0x00020000 /* port enable status change */
310#define RH_PS_PSSC 0x00040000 /* port suspend status change */
311#define RH_PS_OCIC 0x00080000 /* over current indicator change */
312#define RH_PS_PRSC 0x00100000 /* port reset status change */
313
314/* roothub.status bits */
315#define RH_HS_LPS 0x00000001 /* local power status */
316#define RH_HS_OCI 0x00000002 /* over current indicator */
317#define RH_HS_DRWE 0x00008000 /* device remote wakeup enable */
318#define RH_HS_LPSC 0x00010000 /* local power status change */
319#define RH_HS_OCIC 0x00020000 /* over current indicator change */
320#define RH_HS_CRWE 0x80000000 /* clear remote wakeup enable */
321
322/* roothub.b masks */
323#define RH_B_DR 0x0000ffff /* device removable flags */
324#define RH_B_PPCM 0xffff0000 /* port power control mask */
325
326/* roothub.a masks */
327#define RH_A_NDP (0xff << 0) /* number of downstream ports */
328#define RH_A_PSM (1 << 8) /* power switching mode */
329#define RH_A_NPS (1 << 9) /* no power switching */
330#define RH_A_DT (1 << 10) /* device type (mbz) */
331#define RH_A_OCPM (1 << 11) /* over current protection mode */
332#define RH_A_NOCP (1 << 12) /* no over current protection */
333#define RH_A_POTPGT (0xff << 24) /* power on to power good time */
334
335/* urb */
336#define N_URB_TD 48
337typedef struct
338{
339 ed_t *ed;
340 __u16 length; /* number of tds associated with this request */
341 __u16 td_cnt; /* number of tds already serviced */
Zhang Wei8d15efa2007-06-06 10:08:14 +0200342 struct usb_device *dev;
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200343 int state;
344 unsigned long pipe;
Zhang Wei8d15efa2007-06-06 10:08:14 +0200345 void *transfer_buffer;
346 int transfer_buffer_length;
347 int interval;
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200348 int actual_length;
Zhang Wei8d15efa2007-06-06 10:08:14 +0200349 int finished;
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200350 td_t *td[N_URB_TD]; /* list pointer to all corresponding TDs associated with this request */
351} urb_priv_t;
352#define URB_DEL 1
353
Hans de Goede0c0e9602015-05-05 23:56:08 +0200354#define NUM_EDS 8 /* num of preallocated endpoint descriptors */
355
Hans de Goedee5ef4212015-05-05 23:56:09 +0200356#define NUM_TD 64 /* we need more TDs than EDs */
357
Hans de Goede0c0e9602015-05-05 23:56:08 +0200358typedef struct ohci_device {
359 ed_t ed[NUM_EDS] __aligned(16);
Hans de Goedee5ef4212015-05-05 23:56:09 +0200360 td_t tds[NUM_TD] __aligned(32);
Hans de Goede0c0e9602015-05-05 23:56:08 +0200361 int ed_cnt;
362} ohci_dev_t;
363
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200364/*
365 * This is the full ohci controller description
366 *
367 * Note how the "proper" USB information is just
368 * a subset of what the full implementation needs. (Linus)
369 */
370
371
372typedef struct ohci {
Hans de Goede0c0e9602015-05-05 23:56:08 +0200373 /* this allocates EDs for all possible endpoints */
Hans de Goedee5ef4212015-05-05 23:56:09 +0200374 struct ohci_device ohci_dev __aligned(32);
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200375 struct ohci_hcca *hcca; /* hcca */
376 /*dma_addr_t hcca_dma;*/
377
378 int irq;
379 int disabled; /* e.g. got a UE, we're hung */
380 int sleeping;
381 unsigned long flags; /* for HC bugs */
382
383 struct ohci_regs *regs; /* OHCI controller's memory */
384
Zhang Wei8d15efa2007-06-06 10:08:14 +0200385 int ohci_int_load[32]; /* load of the 32 Interrupt Chains (for load balancing)*/
Markus Klotzbuecherd8d023f2006-05-22 16:33:54 +0200386 ed_t *ed_rm_list[2]; /* lists of all endpoints to be removed */
387 ed_t *ed_bulktail; /* last endpoint of bulk list */
388 ed_t *ed_controltail; /* last endpoint of control list */
389 int intrstatus;
390 __u32 hc_control; /* copy of the hc control reg */
391 struct usb_device *dev[32];
392 struct virt_root_hub rh;
393
394 const char *slot_name;
395} ohci_t;