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.c,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> 51 /* for ED and TD structures */ 53 typedefvoid* __OHCI_BAG
; 54 typedefint(*f_handler
)(void* ohci
,struct usb_ohci_ed
*ed
,void*data
,int data_len
,int status
, __OHCI_BAG lw0
, __OHCI_BAG lw1
); 61 #define ED_UNLINK 0x01 65 #define ED_TD_DEL 0x05 66 #define ED_RH 0x07/* marker for RH ED */ 68 #define ED_STATE(ed) (((ed)->hwINFO >> 29) & 0x7) 69 #define ED_setSTATE(ed,state) (ed)->hwINFO = ((ed)->hwINFO & ~(0x7 << 29)) | (((state)& 0x7) << 29) 70 #define ED_TYPE(ed) (((ed)->hwINFO >> 27) & 0x3) 80 struct usb_ohci_ed
*ed_prev
; 86 }__attribute((aligned(32))); 105 #define TD_CC 0xf0000000 106 #define TD_CC_GET(td_p) ((td_p >>28) & 0x0f) 107 #define TD_CC_SET(td_p, cc) (td_p) = ((td_p) & 0x0fffffff) | (((cc) & 0x0f) << 28) 108 #define TD_EC 0x0C000000 109 #define TD_T 0x03000000 110 #define TD_T_DATA0 0x02000000 111 #define TD_T_DATA1 0x03000000 112 #define TD_T_TOGGLE 0x00000000 113 #define TD_R 0x00040000 114 #define TD_DI 0x00E00000 115 #define TD_DI_SET(X) (((X) & 0x07)<< 21) 116 #define TD_DP 0x00180000 117 #define TD_DP_SETUP 0x00000000 118 #define TD_DP_IN 0x00100000 119 #define TD_DP_OUT 0x00080000 121 #define TD_ISO 0x00010000 122 #define TD_DEL 0x00020000 125 #define TD_CC_NOERROR 0x00 126 #define TD_CC_CRC 0x01 127 #define TD_CC_BITSTUFFING 0x02 128 #define TD_CC_DATATOGGLEM 0x03 129 #define TD_CC_STALL 0x04 130 #define TD_DEVNOTRESP 0x05 131 #define TD_PIDCHECKFAIL 0x06 132 #define TD_UNEXPECTEDPID 0x07 133 #define TD_DATAOVERRUN 0x08 134 #define TD_DATAUNDERRUN 0x09 135 #define TD_BUFFEROVERRUN 0x0C 136 #define TD_BUFFERUNDERRUN 0x0D 137 #define TD_NOTACCESSED 0x0F 144 __u32 hwCBP
;/* Current Buffer Pointer */ 145 __u32 hwNextTD
;/* Next TD Pointer */ 146 __u32 hwBE
;/* Memory Buffer End Pointer */ 152 struct usb_ohci_ed
*ed
; 153 struct usb_ohci_td
*next_dl_td
; 156 }__attribute((aligned(32))); 164 /* TD types with direction */ 166 #define BULK_OUT 0x03 170 #define CTRL_OUT 0x02 174 #define CTRL_SETUP 0x102 175 #define CTRL_DATA_IN 0x206 176 #define CTRL_DATA_OUT 0x202 177 #define CTRL_STATUS_IN 0x306 178 #define CTRL_STATUS_OUT 0x302 181 #define SEND 0x00001000 182 #define ST_ADDR 0x00002000 183 #define ADD_LEN 0x00004000 184 #define DEL 0x00008000 185 #define DEL_ED 0x00040000 186 #define TD_RM 0x00080000 188 #define OHCI_ED_SKIP (1 << 14) 193 * The HCCA (Host Controller Communications Area) is a 256 byte 194 * structure defined in the OHCI spec. that the host controller is 195 * told the base address of. It must be 256-byte aligned. 197 #define NUM_INTS 32/* part of the OHCI standard */ 199 __u32 int_table
[NUM_INTS
];/* Interrupt ED table */ 200 __u16 frame_no
;/* current frame number */ 201 __u16 pad1
;/* set to 0 on each frame_no change */ 202 __u32 done_head
;/* info returned for an interrupt */ 203 u8 reserved_for_hc
[116]; 204 }__attribute((aligned(256))); 208 * This is the maximum number of root hub ports. I don't think we'll 209 * ever see more than two as that's the space available on an ATX 210 * motherboard's case, but it could happen. The OHCI spec allows for 211 * up to 15... (which is insane!) 213 * Although I suppose several "ports" could be connected directly to 214 * internal laptop devices such as a keyboard, mouse, camera and 215 * serial/parallel ports. hmm... That'd be neat. 217 #define MAX_ROOT_PORTS 15/* maximum OHCI root hub ports */ 220 * This is the structure of the OHCI controller's memory mapped I/O 221 * region. This is Memory Mapped I/O. You must use the readl() and 222 * writel() macros defined in asm/io.h to access these!! 225 /* control and status registers */ 232 /* memory pointers */ 234 __u32 ed_periodcurrent
; 235 __u32 ed_controlhead
; 236 __u32 ed_controlcurrent
; 238 __u32 ed_bulkcurrent
; 247 struct ohci_roothub_regs
{ 251 __u32 portstatus
[MAX_ROOT_PORTS
]; 253 }__attribute((aligned(32))); 257 * Read a MMIO register and re-write it after ANDing with (m) 259 #define writel_mask(m, a) writel( (readl((__u32)(a))) & (__u32)(m), (__u32)(a) ) 262 * Read a MMIO register and re-write it after ORing with (b) 264 #define writel_set(b, a) writel( (readl((__u32)(a))) | (__u32)(b), (__u32)(a) ) 267 * cmdstatus register */ 268 #define OHCI_CLF 0x02 269 #define OHCI_BLF 0x04 272 * Interrupt register masks 274 #define OHCI_INTR_SO (1) 275 #define OHCI_INTR_WDH (1 << 1) 276 #define OHCI_INTR_SF (1 << 2) 277 #define OHCI_INTR_RD (1 << 3) 278 #define OHCI_INTR_UE (1 << 4) 279 #define OHCI_INTR_FNO (1 << 5) 280 #define OHCI_INTR_RHSC (1 << 6) 281 #define OHCI_INTR_OC (1 << 30) 282 #define OHCI_INTR_MIE (1 << 31) 285 * Control register masks 287 #define OHCI_USB_RESET 0 288 #define OHCI_USB_OPER (2 << 6) 289 #define OHCI_USB_SUSPEND (3 << 6) 291 struct virt_root_hub
{ 292 int devnum
;/* Address of Root Hub endpoint */ 293 usb_device_irq handler
; 298 struct timer_list rh_int_timer
; 301 * This is the full ohci controller description 303 * Note how the "proper" USB information is just 304 * a subset of what the full implementation needs. (Linus) 310 struct ohci_regs
*regs
;/* OHCI controller's memory */ 311 struct ohci_hc_area
*hc_area
;/* hcca, int ed-tree, ohci itself .. */ 313 int ohci_int_load
[32];/* load of the 32 Interrupt Chains (for load ballancing)*/ 314 struct usb_ohci_ed
* ed_rm_list
;/* list of all endpoints to be removed */ 315 struct usb_ohci_ed
* ed_bulktail
;/* last endpoint of bulk list */ 316 struct usb_ohci_ed
* ed_controltail
;/* last endpoint of control list */ 317 struct usb_ohci_ed
* ed_isotail
;/* last endpoint of iso list */ 319 struct ohci_rep_td
*repl_queue
;/* for internal requests */ 323 struct virt_root_hub rh
; 327 #define NUM_TDS 0/* num of preallocated transfer descriptors */ 328 #define NUM_EDS 32/* num of preallocated endpoint descriptors */ 330 struct ohci_hc_area
{ 331 struct ohci_hcca hcca
;/* OHCI mem. mapped IO area 256 Bytes*/ 336 struct usb_device
*usb
; 339 struct usb_ohci_ed ed
[NUM_EDS
]; 340 unsigned long data
[16]; 343 #define ohci_to_usb(ohci) ((ohci)->usb) 344 #define usb_to_ohci(usb) ((struct ohci_device *)(usb)->hcpriv) 347 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
); 348 struct usb_ohci_ed
*usb_ohci_add_ep(struct usb_device
* usb_dev
,struct usb_hcd_ed
* hcd_ed
,int interval
,int load
); 349 intusb_ohci_rm_function(struct usb_device
* usb_dev
, f_handler handler
, __OHCI_BAG lw0
, __OHCI_BAG lw1
); 350 intusb_ohci_rm_ep(struct usb_device
* usb_dev
,struct usb_ohci_ed
*ed
, f_handler handler
, __OHCI_BAG lw0
, __OHCI_BAG lw1
,int send
); 351 struct usb_ohci_ed
*ohci_find_ep(struct usb_device
* usb_dev
,struct usb_hcd_ed
*hcd_ed
); 355 introot_hub_control_msg(struct usb_device
*usb_dev
,unsigned int pipe
, devrequest
*cmd
,void*data
,int len
); 356 introot_hub_release_irq(struct usb_device
*usb_dev
,void* ed
); 357 void*root_hub_request_irq(struct usb_device
*usb_dev
,unsigned int pipe
, usb_device_irq handler
,int period
,void*dev_id
); 359 /* Root-Hub Register info */ 361 #define RH_PS_CCS 0x00000001 362 #define RH_PS_PES 0x00000002 363 #define RH_PS_PSS 0x00000004 364 #define RH_PS_POCI 0x00000008 365 #define RH_PS_PRS 0x00000010 366 #define RH_PS_PPS 0x00000100 367 #define RH_PS_LSDA 0x00000200 368 #define RH_PS_CSC 0x00010000 369 #define RH_PS_PESC 0x00020000 370 #define RH_PS_PSSC 0x00040000 371 #define RH_PS_OCIC 0x00080000 372 #define RH_PS_PRSC 0x00100000 376 #define OHCI_FREE(x) kfree(x); printk("OHCI FREE: %d: %4x\n", -- __ohci_free_cnt, (unsigned int) x) 377 #define OHCI_ALLOC(x,size) (x) = kmalloc(size, GFP_KERNEL); printk("OHCI ALLO: %d: %4x\n", ++ __ohci_free_cnt,(unsigned int) x) 378 #define USB_FREE(x) kfree(x); printk("USB FREE: %d: %4x\n", -- __ohci_free1_cnt, (unsigned int) x) 379 #define USB_ALLOC(x,size) (x) = kmalloc(size, GFP_KERNEL); printk("USB ALLO: %d: %4x\n", ++ __ohci_free1_cnt, (unsigned int) x) 380 static int __ohci_free_cnt
=0; 381 static int __ohci_free1_cnt
=0; 383 #define OHCI_FREE(x) kfree(x) 384 #define OHCI_ALLOC(x,size) (x) = kmalloc(size, GFP_KERNEL) 385 #define USB_FREE(x) kfree(x) 386 #define USB_ALLOC(x,size) (x) = kmalloc(size, GFP_KERNEL)