]> git.ipfire.org Git - people/ms/u-boot.git/blame - include/usb.h
Fix EHCI usb submit timeout and unify with OHCI
[people/ms/u-boot.git] / include / usb.h
CommitLineData
012771d8
WD
1/*
2 * (C) Copyright 2001
3 * Denis Peter, MPL AG Switzerland
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5cf91d6b 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012771d8
WD
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 * Note: Part of this code has been derived from linux
24 *
25 */
26#ifndef _USB_H_
27#define _USB_H_
28
29#include <usb_defs.h>
8f8bd565 30#include <usbdescriptors.h>
012771d8
WD
31
32/* Everything is aribtrary */
5cf91d6b
WD
33#define USB_ALTSETTINGALLOC 4
34#define USB_MAXALTSETTING 128 /* Hard limit */
012771d8 35
5cf91d6b
WD
36#define USB_MAX_DEVICE 32
37#define USB_MAXCONFIG 8
38#define USB_MAXINTERFACES 8
39#define USB_MAXENDPOINTS 16
40#define USB_MAXCHILDREN 8 /* This is arbitrary */
41#define USB_MAX_HUB 16
012771d8
WD
42
43#define USB_CNTL_TIMEOUT 100 /* 100ms timeout */
44
96820a35
SG
45/*
46 * This is the timeout to allow for submitting an urb in ms. We allow more
47 * time for a BULK device to react - some are slow.
48 */
49#define USB_TIMEOUT_MS(pipe) (usb_pipebulk(pipe) ? 5000 : 100)
50
012771d8
WD
51/* device request (setup) */
52struct devrequest {
de39f8c1
MT
53 unsigned char requesttype;
54 unsigned char request;
55 unsigned short value;
56 unsigned short index;
57 unsigned short length;
012771d8
WD
58} __attribute__ ((packed));
59
012771d8
WD
60/* All standard descriptors have these 2 fields in common */
61struct usb_descriptor_header {
de39f8c1
MT
62 unsigned char bLength;
63 unsigned char bDescriptorType;
012771d8
WD
64} __attribute__ ((packed));
65
8f8bd565
TR
66/* Interface */
67struct usb_interface {
68 struct usb_interface_descriptor desc;
de39f8c1
MT
69
70 unsigned char no_of_ep;
71 unsigned char num_altsetting;
72 unsigned char act_altsetting;
73
012771d8
WD
74 struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS];
75} __attribute__ ((packed));
76
8f8bd565
TR
77/* Configuration information.. */
78struct usb_config {
79 struct usb_configuration_descriptor desc;
de39f8c1
MT
80
81 unsigned char no_of_if; /* number of interfaces */
8f8bd565 82 struct usb_interface if_desc[USB_MAXINTERFACES];
012771d8
WD
83} __attribute__ ((packed));
84
48867208
RB
85enum {
86 /* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */
87 PACKET_SIZE_8 = 0,
88 PACKET_SIZE_16 = 1,
89 PACKET_SIZE_32 = 2,
90 PACKET_SIZE_64 = 3,
91};
012771d8
WD
92
93struct usb_device {
de39f8c1 94 int devnum; /* Device number on USB bus */
3e126484 95 int speed; /* full/low/high */
de39f8c1
MT
96 char mf[32]; /* manufacturer */
97 char prod[32]; /* product */
98 char serial[32]; /* serial number */
012771d8 99
48867208
RB
100 /* Maximum packet size; one of: PACKET_SIZE_* */
101 int maxpacketsize;
102 /* one bit for each endpoint ([0] = IN, [1] = OUT) */
103 unsigned int toggle[2];
de39f8c1
MT
104 /* endpoint halts; one bit per endpoint # & direction;
105 * [0] = IN, [1] = OUT
106 */
48867208 107 unsigned int halted[2];
012771d8
WD
108 int epmaxpacketin[16]; /* INput endpoint specific maximums */
109 int epmaxpacketout[16]; /* OUTput endpoint specific maximums */
110
111 int configno; /* selected config number */
112 struct usb_device_descriptor descriptor; /* Device Descriptor */
8f8bd565 113 struct usb_config config; /* config descriptor */
012771d8
WD
114
115 int have_langid; /* whether string_langid is valid yet */
116 int string_langid; /* language ID for strings */
117 int (*irq_handle)(struct usb_device *dev);
118 unsigned long irq_status;
5cf91d6b 119 int irq_act_len; /* transfered bytes */
012771d8
WD
120 void *privptr;
121 /*
122 * Child devices - if this is a hub device
123 * Each instance needs its own set of data structures.
124 */
125 unsigned long status;
126 int act_len; /* transfered bytes */
127 int maxchild; /* Number of ports if hub */
3e126484 128 int portnr;
012771d8
WD
129 struct usb_device *parent;
130 struct usb_device *children[USB_MAXCHILDREN];
131};
132
133/**********************************************************************
134 * this is how the lowlevel part communicate with the outer world
135 */
136
822af351 137#if defined(CONFIG_USB_UHCI) || defined(CONFIG_USB_OHCI) || \
51ab142b 138 defined(CONFIG_USB_EHCI) || defined(CONFIG_USB_OHCI_NEW) || \
3e126484 139 defined(CONFIG_USB_SL811HS) || defined(CONFIG_USB_ISP116X_HCD) || \
f298e4b6 140 defined(CONFIG_USB_R8A66597_HCD) || defined(CONFIG_USB_DAVINCI) || \
e608f221 141 defined(CONFIG_USB_OMAP3) || defined(CONFIG_USB_DA8XX) || \
dbea3242 142 defined(CONFIG_USB_BLACKFIN) || defined(CONFIG_USB_AM35X)
822af351 143
012771d8
WD
144int usb_lowlevel_init(void);
145int usb_lowlevel_stop(void);
de39f8c1
MT
146int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
147 void *buffer, int transfer_len);
012771d8 148int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
de39f8c1 149 int transfer_len, struct devrequest *setup);
012771d8
WD
150int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
151 int transfer_len, int interval);
fdcfaa1b 152void usb_event_poll(void);
012771d8
WD
153
154/* Defines */
de39f8c1
MT
155#define USB_UHCI_VEND_ID 0x8086
156#define USB_UHCI_DEV_ID 0x7112
012771d8
WD
157
158#else
159#error USB Lowlevel not defined
160#endif
161
162#ifdef CONFIG_USB_STORAGE
163
164#define USB_MAX_STOR_DEV 5
165block_dev_desc_t *usb_stor_get_dev(int index);
166int usb_stor_scan(int mode);
e813eae3 167int usb_stor_info(void);
012771d8
WD
168
169#endif
170
171#ifdef CONFIG_USB_KEYBOARD
172
173int drv_usb_kbd_init(void);
174int usb_kbd_deregister(void);
175
176#endif
177/* routines */
178int usb_init(void); /* initialize the USB Controller */
179int usb_stop(void); /* stop the USB Controller */
180
181
182int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol);
de39f8c1
MT
183int usb_set_idle(struct usb_device *dev, int ifnum, int duration,
184 int report_id);
185struct usb_device *usb_get_dev_index(int index);
012771d8
WD
186int usb_control_msg(struct usb_device *dev, unsigned int pipe,
187 unsigned char request, unsigned char requesttype,
188 unsigned short value, unsigned short index,
189 void *data, unsigned short size, int timeout);
190int usb_bulk_msg(struct usb_device *dev, unsigned int pipe,
191 void *data, int len, int *actual_length, int timeout);
192int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe,
de39f8c1 193 void *buffer, int transfer_len, int interval);
012771d8 194void usb_disable_asynch(int disable);
de39f8c1
MT
195int usb_maxpacket(struct usb_device *dev, unsigned long pipe);
196inline void wait_ms(unsigned long ms);
197int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer,
198 int cfgno);
199int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
200 unsigned char id, void *buf, int size);
012771d8 201int usb_get_class_descriptor(struct usb_device *dev, int ifnum,
de39f8c1
MT
202 unsigned char type, unsigned char id, void *buf,
203 int size);
012771d8
WD
204int usb_clear_halt(struct usb_device *dev, int pipe);
205int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
206int usb_set_interface(struct usb_device *dev, int interface, int alternate);
207
208/* big endian -> little endian conversion */
149dded2 209/* some CPUs are already little endian e.g. the ARM920T */
ae3b770e 210#define __swap_16(x) \
3f85ce27
WD
211 ({ unsigned short x_ = (unsigned short)x; \
212 (unsigned short)( \
de39f8c1 213 ((x_ & 0x00FFU) << 8) | ((x_ & 0xFF00U) >> 8)); \
3f85ce27 214 })
ae3b770e 215#define __swap_32(x) \
3f85ce27
WD
216 ({ unsigned long x_ = (unsigned long)x; \
217 (unsigned long)( \
218 ((x_ & 0x000000FFUL) << 24) | \
5cf91d6b
WD
219 ((x_ & 0x0000FF00UL) << 8) | \
220 ((x_ & 0x00FF0000UL) >> 8) | \
de39f8c1 221 ((x_ & 0xFF000000UL) >> 24)); \
3f85ce27 222 })
ae3b770e 223
c7d703f3 224#ifdef __LITTLE_ENDIAN
ae3b770e
MK
225# define swap_16(x) (x)
226# define swap_32(x) (x)
227#else
228# define swap_16(x) __swap_16(x)
229# define swap_32(x) __swap_32(x)
c7d703f3 230#endif
012771d8
WD
231
232/*
233 * Calling this entity a "pipe" is glorifying it. A USB pipe
234 * is something embarrassingly simple: it basically consists
235 * of the following information:
236 * - device number (7 bits)
237 * - endpoint number (4 bits)
238 * - current Data0/1 state (1 bit)
239 * - direction (1 bit)
3e126484 240 * - speed (2 bits)
012771d8
WD
241 * - max packet size (2 bits: 8, 16, 32 or 64)
242 * - pipe type (2 bits: control, interrupt, bulk, isochronous)
243 *
244 * That's 18 bits. Really. Nothing more. And the USB people have
245 * documented these eighteen bits as some kind of glorious
246 * virtual data structure.
247 *
248 * Let's not fall in that trap. We'll just encode it as a simple
249 * unsigned int. The encoding is:
250 *
251 * - max size: bits 0-1 (00 = 8, 01 = 16, 10 = 32, 11 = 64)
de39f8c1
MT
252 * - direction: bit 7 (0 = Host-to-Device [Out],
253 * (1 = Device-to-Host [In])
012771d8
WD
254 * - device: bits 8-14
255 * - endpoint: bits 15-18
256 * - Data0/1: bit 19
3e126484 257 * - speed: bit 26 (0 = Full, 1 = Low Speed, 2 = High)
de39f8c1
MT
258 * - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt,
259 * 10 = control, 11 = bulk)
012771d8
WD
260 *
261 * Why? Because it's arbitrary, and whatever encoding we select is really
262 * up to us. This one happens to share a lot of bit positions with the UHCI
263 * specification, so that much of the uhci driver can just mask the bits
264 * appropriately.
265 */
266/* Create various pipes... */
267#define create_pipe(dev,endpoint) \
d0fe1128 268 (((dev)->devnum << 8) | ((endpoint) << 15) | \
3e126484
MT
269 ((dev)->speed << 26) | (dev)->maxpacketsize)
270#define default_pipe(dev) ((dev)->speed << 26)
de39f8c1
MT
271
272#define usb_sndctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \
273 create_pipe(dev, endpoint))
274#define usb_rcvctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \
275 create_pipe(dev, endpoint) | \
276 USB_DIR_IN)
277#define usb_sndisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \
278 create_pipe(dev, endpoint))
279#define usb_rcvisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \
280 create_pipe(dev, endpoint) | \
281 USB_DIR_IN)
282#define usb_sndbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \
283 create_pipe(dev, endpoint))
284#define usb_rcvbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \
285 create_pipe(dev, endpoint) | \
286 USB_DIR_IN)
287#define usb_sndintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \
288 create_pipe(dev, endpoint))
289#define usb_rcvintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \
290 create_pipe(dev, endpoint) | \
291 USB_DIR_IN)
292#define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | \
293 default_pipe(dev))
294#define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | \
295 default_pipe(dev) | \
296 USB_DIR_IN)
012771d8
WD
297
298/* The D0/D1 toggle bits */
299#define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
5cf91d6b 300#define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep))
de39f8c1
MT
301#define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = \
302 ((dev)->toggle[out] & \
303 ~(1 << ep)) | ((bit) << ep))
012771d8
WD
304
305/* Endpoint halt control/status */
306#define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1)
307#define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
308#define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
309#define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
310
de39f8c1
MT
311#define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : \
312 USB_PID_OUT)
012771d8
WD
313
314#define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1)
315#define usb_pipein(pipe) (((pipe) >> 7) & 1)
316#define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
317#define usb_pipe_endpdev(pipe) (((pipe) >> 8) & 0x7ff)
318#define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
319#define usb_pipedata(pipe) (((pipe) >> 19) & 1)
3e126484
MT
320#define usb_pipespeed(pipe) (((pipe) >> 26) & 3)
321#define usb_pipeslow(pipe) (usb_pipespeed(pipe) == USB_SPEED_LOW)
012771d8
WD
322#define usb_pipetype(pipe) (((pipe) >> 30) & 3)
323#define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
324#define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
325#define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
326#define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
327
328
329/*************************************************************************
330 * Hub Stuff
331 */
332struct usb_port_status {
333 unsigned short wPortStatus;
334 unsigned short wPortChange;
335} __attribute__ ((packed));
336
337struct usb_hub_status {
338 unsigned short wHubStatus;
339 unsigned short wHubChange;
340} __attribute__ ((packed));
341
342
343/* Hub descriptor */
344struct usb_hub_descriptor {
345 unsigned char bLength;
346 unsigned char bDescriptorType;
347 unsigned char bNbrPorts;
348 unsigned short wHubCharacteristics;
349 unsigned char bPwrOn2PwrGood;
350 unsigned char bHubContrCurrent;
351 unsigned char DeviceRemovable[(USB_MAXCHILDREN+1+7)/8];
352 unsigned char PortPowerCtrlMask[(USB_MAXCHILDREN+1+7)/8];
de39f8c1 353 /* DeviceRemovable and PortPwrCtrlMask want to be variable-length
012771d8
WD
354 bitmaps that hold max 255 entries. (bit0 is ignored) */
355} __attribute__ ((packed));
356
357
358struct usb_hub_device {
359 struct usb_device *pusb_dev;
360 struct usb_hub_descriptor desc;
361};
362
363#endif /*_USB_H_ */