2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
6 * The OHCI HCD layer is a simple but nearly complete implementation of what the
7 * USB people would call a HCD for the OHCI.
8 * (ISO comming soon, Bulk, INT u. CTRL transfers enabled)
9 * The layer on top of it, is for interfacing to the alternate-usb device-drivers.
11 * [ This is based on Linus' UHCI code and gregs OHCI fragments (0.03c source tree). ]
12 * [ Open Host Controller Interface driver for USB. ]
13 * [ (C) Copyright 1999 Linus Torvalds (uhci.c) ]
14 * [ (C) Copyright 1999 Gregory P. Smith <greg@electricrain.com> ]
15 * [ _Log: ohci-hcd.h,v _
16 * [ Revision 1.1 1999/04/05 08:32:30 greg ]
19 * v2.1 1999/05/09 ep_addr correction, code clean up
25 #define OHCI_DBG /* printk some debug information */
28 #include <linux/config.h>
30 // #ifdef CONFIG_USB_OHCI_VROOTHUB
33 /* enables virtual root hub
34 * (root hub will be managed by the hub controller
35 * hub.c of the alternate usb driver)
42 #define OHCI_DEBUG(X) X
47 /* for readl writel functions */
48 #include <linux/list.h>
52 /* for ED and TD structures */
54 typedef void * __OHCI_BAG
;
55 typedef int (*f_handler
)(void * ohci
, struct usb_ohci_td
*td
, void *data
, int data_len
, int dlen
, int status
, __OHCI_BAG lw0
, __OHCI_BAG lw1
);
62 #define ED_UNLINK 0x01
66 #define ED_TD_DEL 0x05
67 #define ED_RH 0x07 /* marker for RH ED */
69 #define ED_STATE(ed) (((ed)->hwINFO >> 29) & 0x7)
70 #define ED_setSTATE(ed,state) (ed)->hwINFO = ((ed)->hwINFO & ~(0x7 << 29)) | (((state)& 0x7) << 29)
71 #define ED_TYPE(ed) (((ed)->hwINFO >> 27) & 0x3)
81 struct usb_ohci_ed
*ed_prev
;
87 } __attribute((aligned(32)));
106 #define TD_CC 0xf0000000
107 #define TD_CC_GET(td_p) ((td_p >>28) & 0x0f)
108 #define TD_CC_SET(td_p, cc) (td_p) = ((td_p) & 0x0fffffff) | (((cc) & 0x0f) << 28)
109 #define TD_EC 0x0C000000
110 #define TD_T 0x03000000
111 #define TD_T_DATA0 0x02000000
112 #define TD_T_DATA1 0x03000000
113 #define TD_T_TOGGLE 0x00000000
114 #define TD_R 0x00040000
115 #define TD_DI 0x00E00000
116 #define TD_DI_SET(X) (((X) & 0x07)<< 21)
117 #define TD_DP 0x00180000
118 #define TD_DP_SETUP 0x00000000
119 #define TD_DP_IN 0x00100000
120 #define TD_DP_OUT 0x00080000
122 #define TD_ISO 0x00010000
123 #define TD_DEL 0x00020000
126 #define TD_CC_NOERROR 0x00
127 #define TD_CC_CRC 0x01
128 #define TD_CC_BITSTUFFING 0x02
129 #define TD_CC_DATATOGGLEM 0x03
130 #define TD_CC_STALL 0x04
131 #define TD_DEVNOTRESP 0x05
132 #define TD_PIDCHECKFAIL 0x06
133 #define TD_UNEXPECTEDPID 0x07
134 #define TD_DATAOVERRUN 0x08
135 #define TD_DATAUNDERRUN 0x09
136 #define TD_BUFFEROVERRUN 0x0C
137 #define TD_BUFFERUNDERRUN 0x0D
138 #define TD_NOTACCESSED 0x0F
145 __u32 hwCBP
; /* Current Buffer Pointer */
146 __u32 hwNextTD
; /* Next TD Pointer */
147 __u32 hwBE
; /* Memory Buffer End Pointer */
153 struct usb_ohci_ed
*ed
;
154 struct usb_ohci_td
*next_dl_td
;
157 } __attribute((aligned(32)));
165 /* TD types with direction */
167 #define BULK_OUT 0x03
171 #define CTRL_OUT 0x02
175 #define CTRL_SETUP 0x102
176 #define CTRL_DATA_IN 0x206
177 #define CTRL_DATA_OUT 0x202
178 #define CTRL_STATUS_IN 0x306
179 #define CTRL_STATUS_OUT 0x302
182 #define SEND 0x00001000
183 #define ST_ADDR 0x00002000
184 #define ADD_LEN 0x00004000
185 #define DEL 0x00008000
186 #define DEL_ED 0x00040000
187 #define TD_RM 0x00080000
189 #define OHCI_ED_SKIP (1 << 14)
194 * The HCCA (Host Controller Communications Area) is a 256 byte
195 * structure defined in the OHCI spec. that the host controller is
196 * told the base address of. It must be 256-byte aligned.
198 #define NUM_INTS 32 /* part of the OHCI standard */
200 __u32 int_table
[NUM_INTS
]; /* Interrupt ED table */
201 __u16 frame_no
; /* current frame number */
202 __u16 pad1
; /* set to 0 on each frame_no change */
203 __u32 done_head
; /* info returned for an interrupt */
204 u8 reserved_for_hc
[116];
205 } __attribute((aligned(256)));
209 * This is the maximum number of root hub ports. I don't think we'll
210 * ever see more than two as that's the space available on an ATX
211 * motherboard's case, but it could happen. The OHCI spec allows for
212 * up to 15... (which is insane!)
214 * Although I suppose several "ports" could be connected directly to
215 * internal laptop devices such as a keyboard, mouse, camera and
216 * serial/parallel ports. hmm... That'd be neat.
218 #define MAX_ROOT_PORTS 15 /* maximum OHCI root hub ports */
221 * This is the structure of the OHCI controller's memory mapped I/O
222 * region. This is Memory Mapped I/O. You must use the readl() and
223 * writel() macros defined in asm/io.h to access these!!
226 /* control and status registers */
233 /* memory pointers */
235 __u32 ed_periodcurrent
;
236 __u32 ed_controlhead
;
237 __u32 ed_controlcurrent
;
239 __u32 ed_bulkcurrent
;
248 struct ohci_roothub_regs
{
252 __u32 portstatus
[MAX_ROOT_PORTS
];
254 } __attribute((aligned(32)));
258 * Read a MMIO register and re-write it after ANDing with (m)
260 #define writel_mask(m, a) writel( (readl((__u32)(a))) & (__u32)(m), (__u32)(a) )
263 * Read a MMIO register and re-write it after ORing with (b)
265 #define writel_set(b, a) writel( (readl((__u32)(a))) | (__u32)(b), (__u32)(a) )
268 * cmdstatus register */
269 #define OHCI_CLF 0x02
270 #define OHCI_BLF 0x04
273 * Interrupt register masks
275 #define OHCI_INTR_SO (1)
276 #define OHCI_INTR_WDH (1 << 1)
277 #define OHCI_INTR_SF (1 << 2)
278 #define OHCI_INTR_RD (1 << 3)
279 #define OHCI_INTR_UE (1 << 4)
280 #define OHCI_INTR_FNO (1 << 5)
281 #define OHCI_INTR_RHSC (1 << 6)
282 #define OHCI_INTR_OC (1 << 30)
283 #define OHCI_INTR_MIE (1 << 31)
286 * Control register masks
288 #define OHCI_USB_RESET 0
289 #define OHCI_USB_OPER (2 << 6)
290 #define OHCI_USB_SUSPEND (3 << 6)
292 struct virt_root_hub
{
293 int devnum
; /* Address of Root Hub endpoint */
294 usb_device_irq handler
;
299 struct timer_list rh_int_timer
;
302 * This is the full ohci controller description
304 * Note how the "proper" USB information is just
305 * a subset of what the full implementation needs. (Linus)
311 struct ohci_regs
*regs
; /* OHCI controller's memory */
312 struct ohci_hc_area
*hc_area
; /* hcca, int ed-tree, ohci itself .. */
314 struct list_head ohci_hcd_list
; /* list of all ohci_hcd */
316 int ohci_int_load
[32]; /* load of the 32 Interrupt Chains (for load ballancing)*/
317 struct usb_ohci_ed
* ed_rm_list
; /* list of all endpoints to be removed */
318 struct usb_ohci_ed
* ed_bulktail
; /* last endpoint of bulk list */
319 struct usb_ohci_ed
* ed_controltail
; /* last endpoint of control list */
320 struct usb_ohci_ed
* ed_isotail
; /* last endpoint of iso list */
322 struct ohci_rep_td
*repl_queue
; /* for internal requests */
326 struct virt_root_hub rh
;
330 #define NUM_TDS 0 /* num of preallocated transfer descriptors */
331 #define NUM_EDS 32 /* num of preallocated endpoint descriptors */
333 struct ohci_hc_area
{
334 struct ohci_hcca hcca
; /* OHCI mem. mapped IO area 256 Bytes*/
339 struct usb_device
*usb
;
342 struct usb_ohci_ed ed
[NUM_EDS
];
343 unsigned long data
[16];
346 #define ohci_to_usb(ohci) ((ohci)->usb)
347 #define usb_to_ohci(usb) ((struct ohci_device *)(usb)->hcpriv)
350 struct usb_ohci_td
* ohci_trans_req(struct ohci
* ohci
, struct usb_ohci_ed
* ed
, int cmd_len
, void *cmd
, void * data
, int data_len
, __OHCI_BAG lw0
, __OHCI_BAG lw1
, unsigned int type
, f_handler handler
);
351 struct usb_ohci_ed
*usb_ohci_add_ep(struct usb_device
* usb_dev
, struct usb_hcd_ed
* hcd_ed
, int interval
, int load
);
352 int usb_ohci_rm_function(struct usb_device
* usb_dev
, f_handler handler
, __OHCI_BAG lw0
, __OHCI_BAG lw1
);
353 int usb_ohci_rm_ep(struct usb_device
* usb_dev
, struct usb_ohci_ed
*ed
, f_handler handler
, __OHCI_BAG lw0
, __OHCI_BAG lw1
, int send
);
354 struct usb_ohci_ed
* ohci_find_ep(struct usb_device
* usb_dev
, struct usb_hcd_ed
*hcd_ed
);
358 int root_hub_control_msg(struct usb_device
*usb_dev
, unsigned int pipe
, devrequest
*cmd
, void *data
, int len
);
359 int root_hub_release_irq(struct usb_device
*usb_dev
, void * ed
);
360 int root_hub_request_irq(struct usb_device
*usb_dev
, unsigned int pipe
, usb_device_irq handler
, int period
, void *dev_id
, void **handle
);
362 /* Root-Hub Register info */
364 #define RH_PS_CCS 0x00000001
365 #define RH_PS_PES 0x00000002
366 #define RH_PS_PSS 0x00000004
367 #define RH_PS_POCI 0x00000008
368 #define RH_PS_PRS 0x00000010
369 #define RH_PS_PPS 0x00000100
370 #define RH_PS_LSDA 0x00000200
371 #define RH_PS_CSC 0x00010000
372 #define RH_PS_PESC 0x00020000
373 #define RH_PS_PSSC 0x00040000
374 #define RH_PS_OCIC 0x00080000
375 #define RH_PS_PRSC 0x00100000
379 #define OHCI_FREE(x) kfree(x); printk("OHCI FREE: %d: %4x\n", -- __ohci_free_cnt, (unsigned int) x)
380 #define OHCI_ALLOC(x,size) (x) = kmalloc(size, GFP_KERNEL); printk("OHCI ALLO: %d: %4x\n", ++ __ohci_free_cnt,(unsigned int) x)
381 #define USB_FREE(x) kfree(x); printk("USB FREE: %d: %4x\n", -- __ohci_free1_cnt, (unsigned int) x)
382 #define USB_ALLOC(x,size) (x) = kmalloc(size, GFP_KERNEL); printk("USB ALLO: %d: %4x\n", ++ __ohci_free1_cnt, (unsigned int) x)
383 static int __ohci_free_cnt
= 0;
384 static int __ohci_free1_cnt
= 0;
386 #define OHCI_FREE(x) kfree(x)
387 #define OHCI_ALLOC(x,size) (x) = kmalloc(size, GFP_KERNEL)
388 #define USB_FREE(x) kfree(x)
389 #define USB_ALLOC(x,size) (x) = kmalloc(size, GFP_KERNEL)