Import 2.3.25pre1
[davej-history.git] / drivers / usb / ohci-hcd.h
blob722bbeaeaef5094779039b19601bd121a740f508
1 /*
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 ]
18 * v4.0 1999/08/18
19 * v2.1 1999/05/09 ep_addr correction, code clean up
20 * v2.0 1999/05/04
21 * v1.0 1999/04/27
22 * ohci-hcd.h
25 #define OHCI_DBG /* printk some debug information */
28 #include <linux/config.h>
30 // #ifdef CONFIG_USB_OHCI_VROOTHUB
31 #define VROOTHUB
32 // #endif
33 /* enables virtual root hub
34 * (root hub will be managed by the hub controller
35 * hub.c of the alternate usb driver)
36 * must be on now
41 #ifdef OHCI_DBG
42 #define OHCI_DEBUG(X) X
43 #else
44 #define OHCI_DEBUG(X)
45 #endif
47 /* for readl writel functions */
48 #include <linux/list.h>
49 #include <asm/io.h>
50 struct usb_ohci_ed;
51 struct usb_ohci_td;
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);
59 /* ED States */
61 #define ED_NEW 0x00
62 #define ED_UNLINK 0x01
63 #define ED_OPER 0x02
64 #define ED_STOP 0x03
65 #define ED_DEL 0x04
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)
73 struct usb_ohci_ed {
74 __u32 hwINFO;
75 __u32 hwTailP;
76 __u32 hwHeadP;
77 __u32 hwNextED;
79 void * buffer_start;
80 unsigned int len;
81 struct usb_ohci_ed *ed_prev;
82 __u8 int_period;
83 __u8 int_branch;
84 __u8 int_load;
85 __u8 int_interval;
87 } __attribute((aligned(32)));
89 struct usb_hcd_ed {
90 int endpoint;
91 int function;
92 int out;
93 int type;
94 int slow;
95 int maxpack;
98 struct ohci_state {
99 int len;
100 int status;
105 /* TD info field */
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
125 /* CC Codes */
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
141 #define MAXPSW 2
143 struct usb_ohci_td {
144 __u32 hwINFO;
145 __u32 hwCBP; /* Current Buffer Pointer */
146 __u32 hwNextTD; /* Next TD Pointer */
147 __u32 hwBE; /* Memory Buffer End Pointer */
148 __u16 hwPSW[MAXPSW];
150 __u32 type;
151 void * buffer_start;
152 f_handler handler;
153 struct usb_ohci_ed *ed;
154 struct usb_ohci_td *next_dl_td;
155 __OHCI_BAG lw0;
156 __OHCI_BAG lw1;
157 } __attribute((aligned(32)));
160 /* TD types */
161 #define BULK 0x03
162 #define INT 0x01
163 #define CTRL 0x02
164 #define ISO 0x00
165 /* TD types with direction */
166 #define BULK_IN 0x07
167 #define BULK_OUT 0x03
168 #define INT_IN 0x05
169 #define INT_OUT 0x01
170 #define CTRL_IN 0x06
171 #define CTRL_OUT 0x02
172 #define ISO_IN 0x04
173 #define ISO_OUT 0x00
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 */
199 struct ohci_hcca {
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!!
225 struct ohci_regs {
226 /* control and status registers */
227 __u32 revision;
228 __u32 control;
229 __u32 cmdstatus;
230 __u32 intrstatus;
231 __u32 intrenable;
232 __u32 intrdisable;
233 /* memory pointers */
234 __u32 hcca;
235 __u32 ed_periodcurrent;
236 __u32 ed_controlhead;
237 __u32 ed_controlcurrent;
238 __u32 ed_bulkhead;
239 __u32 ed_bulkcurrent;
240 __u32 donehead;
241 /* frame counters */
242 __u32 fminterval;
243 __u32 fmremaining;
244 __u32 fmnumber;
245 __u32 periodicstart;
246 __u32 lsthresh;
247 /* Root hub ports */
248 struct ohci_roothub_regs {
249 __u32 a;
250 __u32 b;
251 __u32 status;
252 __u32 portstatus[MAX_ROOT_PORTS];
253 } roothub;
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;
295 void * dev_id;
296 void * int_addr;
297 int send;
298 int interval;
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)
309 struct ohci {
310 int irq;
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 */
321 int intrstatus;
322 struct ohci_rep_td *repl_queue; /* for internal requests */
323 int rh_int_interval;
324 int rh_int_timer;
325 struct usb_bus *bus;
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*/
335 struct ohci ohci;
338 struct ohci_device {
339 struct usb_device *usb;
340 atomic_t refcnt;
341 struct ohci *ohci;
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)
349 /* hcd */
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);
356 /* roothub */
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
378 #ifdef OHCI_DBG
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;
385 #else
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)
390 #endif