Blame view
include/usb.h
13.4 KB
012771d88 Initial revision |
1 2 3 4 |
/* * (C) Copyright 2001 * Denis Peter, MPL AG Switzerland * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
012771d88 Initial revision |
6 7 8 9 10 11 12 |
* Note: Part of this code has been derived from linux * */ #ifndef _USB_H_ #define _USB_H_ #include <usb_defs.h> |
c60795f41 usb: use linux/us... |
13 |
#include <linux/usb/ch9.h> |
012771d88 Initial revision |
14 |
|
71c5de4f4 ehci-hcd.c, musb_... |
15 16 17 18 19 20 21 22 23 |
/* * The EHCI spec says that we must align to at least 32 bytes. However, * some platforms require larger alignment. */ #if ARCH_DMA_MINALIGN > 32 #define USB_DMA_MINALIGN ARCH_DMA_MINALIGN #else #define USB_DMA_MINALIGN 32 #endif |
012771d88 Initial revision |
24 |
/* Everything is aribtrary */ |
5cf91d6bd * Modify KUP4X bo... |
25 26 |
#define USB_ALTSETTINGALLOC 4 #define USB_MAXALTSETTING 128 /* Hard limit */ |
012771d88 Initial revision |
27 |
|
5cf91d6bd * Modify KUP4X bo... |
28 29 30 31 32 33 |
#define USB_MAX_DEVICE 32 #define USB_MAXCONFIG 8 #define USB_MAXINTERFACES 8 #define USB_MAXENDPOINTS 16 #define USB_MAXCHILDREN 8 /* This is arbitrary */ #define USB_MAX_HUB 16 |
012771d88 Initial revision |
34 35 |
#define USB_CNTL_TIMEOUT 100 /* 100ms timeout */ |
96820a358 Fix EHCI usb subm... |
36 37 38 39 |
/* * This is the timeout to allow for submitting an urb in ms. We allow more * time for a BULK device to react - some are slow. */ |
80b350a7a usb: increase non... |
40 |
#define USB_TIMEOUT_MS(pipe) (usb_pipebulk(pipe) ? 5000 : 1000) |
96820a358 Fix EHCI usb subm... |
41 |
|
012771d88 Initial revision |
42 43 |
/* device request (setup) */ struct devrequest { |
de39f8c19 USB style patch, ... |
44 45 46 47 48 |
unsigned char requesttype; unsigned char request; unsigned short value; unsigned short index; unsigned short length; |
012771d88 Initial revision |
49 |
} __attribute__ ((packed)); |
8f8bd565f USB Consolidate d... |
50 51 52 |
/* Interface */ struct usb_interface { struct usb_interface_descriptor desc; |
de39f8c19 USB style patch, ... |
53 54 55 56 |
unsigned char no_of_ep; unsigned char num_altsetting; unsigned char act_altsetting; |
012771d88 Initial revision |
57 |
struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS]; |
6497c6670 USB: SS: Add supp... |
58 59 60 61 62 63 |
/* * Super Speed Device will have Super Speed Endpoint * Companion Descriptor (section 9.6.7 of usb 3.0 spec) * Revision 1.0 June 6th 2011 */ struct usb_ss_ep_comp_descriptor ss_ep_comp_desc[USB_MAXENDPOINTS]; |
012771d88 Initial revision |
64 |
} __attribute__ ((packed)); |
8f8bd565f USB Consolidate d... |
65 66 |
/* Configuration information.. */ struct usb_config { |
c60795f41 usb: use linux/us... |
67 |
struct usb_config_descriptor desc; |
de39f8c19 USB style patch, ... |
68 69 |
unsigned char no_of_if; /* number of interfaces */ |
8f8bd565f USB Consolidate d... |
70 |
struct usb_interface if_desc[USB_MAXINTERFACES]; |
012771d88 Initial revision |
71 |
} __attribute__ ((packed)); |
488672084 fix USB initialis... |
72 73 74 75 76 77 78 |
enum { /* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */ PACKET_SIZE_8 = 0, PACKET_SIZE_16 = 1, PACKET_SIZE_32 = 2, PACKET_SIZE_64 = 3, }; |
012771d88 Initial revision |
79 80 |
struct usb_device { |
de39f8c19 USB style patch, ... |
81 |
int devnum; /* Device number on USB bus */ |
3e126484d Prepare USB layer... |
82 |
int speed; /* full/low/high */ |
de39f8c19 USB style patch, ... |
83 84 85 |
char mf[32]; /* manufacturer */ char prod[32]; /* product */ char serial[32]; /* serial number */ |
012771d88 Initial revision |
86 |
|
488672084 fix USB initialis... |
87 88 89 90 |
/* Maximum packet size; one of: PACKET_SIZE_* */ int maxpacketsize; /* one bit for each endpoint ([0] = IN, [1] = OUT) */ unsigned int toggle[2]; |
de39f8c19 USB style patch, ... |
91 92 93 |
/* endpoint halts; one bit per endpoint # & direction; * [0] = IN, [1] = OUT */ |
488672084 fix USB initialis... |
94 |
unsigned int halted[2]; |
012771d88 Initial revision |
95 96 97 98 |
int epmaxpacketin[16]; /* INput endpoint specific maximums */ int epmaxpacketout[16]; /* OUTput endpoint specific maximums */ int configno; /* selected config number */ |
f57661394 USB: Align buffer... |
99 100 101 |
/* Device Descriptor */ struct usb_device_descriptor descriptor __attribute__((aligned(ARCH_DMA_MINALIGN))); |
8f8bd565f USB Consolidate d... |
102 |
struct usb_config config; /* config descriptor */ |
012771d88 Initial revision |
103 104 105 106 107 |
int have_langid; /* whether string_langid is valid yet */ int string_langid; /* language ID for strings */ int (*irq_handle)(struct usb_device *dev); unsigned long irq_status; |
5cf91d6bd * Modify KUP4X bo... |
108 |
int irq_act_len; /* transfered bytes */ |
012771d88 Initial revision |
109 110 111 112 113 114 115 116 |
void *privptr; /* * Child devices - if this is a hub device * Each instance needs its own set of data structures. */ unsigned long status; int act_len; /* transfered bytes */ int maxchild; /* Number of ports if hub */ |
3e126484d Prepare USB layer... |
117 |
int portnr; |
012771d88 Initial revision |
118 119 |
struct usb_device *parent; struct usb_device *children[USB_MAXCHILDREN]; |
c7e3b2b58 usb: lowlevel int... |
120 121 |
void *controller; /* hardware controller private data */ |
5853e1335 USB: xHCI: Add st... |
122 123 |
/* slot_id - for xHCI enabled devices */ unsigned int slot_id; |
012771d88 Initial revision |
124 |
}; |
bba679144 usb: rename board... |
125 126 127 128 129 130 131 132 133 |
/* * You can initialize platform's USB host or device * ports by passing this enum as an argument to * board_usb_init(). */ enum usb_init_type { USB_INIT_HOST, USB_INIT_DEVICE }; |
012771d88 Initial revision |
134 135 136 |
/********************************************************************** * this is how the lowlevel part communicate with the outer world */ |
822af351a Support for the P... |
137 |
#if defined(CONFIG_USB_UHCI) || defined(CONFIG_USB_OHCI) || \ |
51ab142b8 [PATCH] This patc... |
138 |
defined(CONFIG_USB_EHCI) || defined(CONFIG_USB_OHCI_NEW) || \ |
3e126484d Prepare USB layer... |
139 |
defined(CONFIG_USB_SL811HS) || defined(CONFIG_USB_ISP116X_HCD) || \ |
f298e4b6d OMAP3 Add usb dev... |
140 |
defined(CONFIG_USB_R8A66597_HCD) || defined(CONFIG_USB_DAVINCI) || \ |
e608f221c usb: musb: add su... |
141 |
defined(CONFIG_USB_OMAP3) || defined(CONFIG_USB_DA8XX) || \ |
37931f02c musb-new: dsps ba... |
142 |
defined(CONFIG_USB_BLACKFIN) || defined(CONFIG_USB_AM35X) || \ |
673a524b6 musb-new: omap2pl... |
143 |
defined(CONFIG_USB_MUSB_DSPS) || defined(CONFIG_USB_MUSB_AM35X) || \ |
5853e1335 USB: xHCI: Add st... |
144 |
defined(CONFIG_USB_MUSB_OMAP2PLUS) || defined(CONFIG_USB_XHCI) |
822af351a Support for the P... |
145 |
|
06d513ecb usb: add enum usb... |
146 |
int usb_lowlevel_init(int index, enum usb_init_type init, void **controller); |
c7e3b2b58 usb: lowlevel int... |
147 |
int usb_lowlevel_stop(int index); |
de39f8c19 USB style patch, ... |
148 149 |
int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int transfer_len); |
012771d88 Initial revision |
150 |
int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, |
de39f8c19 USB style patch, ... |
151 |
int transfer_len, struct devrequest *setup); |
012771d88 Initial revision |
152 153 154 155 |
int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int transfer_len, int interval); /* Defines */ |
de39f8c19 USB style patch, ... |
156 157 |
#define USB_UHCI_VEND_ID 0x8086 #define USB_UHCI_DEV_ID 0x7112 |
012771d88 Initial revision |
158 |
|
e5f24753c usb.h: Add udc_di... |
159 160 161 162 163 164 165 166 167 168 |
/* * PXA25x can only act as USB device. There are drivers * which works with USB CDC gadgets implementations. * Some of them have common routines which can be used * in boards init functions e.g. udc_disconnect() used for * forced device disconnection from host. */ #elif defined(CONFIG_USB_GADGET_PXA2XX) extern void udc_disconnect(void); |
012771d88 Initial revision |
169 |
#endif |
16297cfb2 usb: new board-sp... |
170 |
/* |
16297cfb2 usb: new board-sp... |
171 172 173 174 175 176 |
* board-specific hardware initialization, called by * usb drivers and u-boot commands * * @param index USB controller number * @param init initializes controller as USB host or device */ |
bba679144 usb: rename board... |
177 |
int board_usb_init(int index, enum usb_init_type init); |
16297cfb2 usb: new board-sp... |
178 179 180 181 182 183 |
/* * can be used to clean up after failed USB initialization attempt * vide: board_usb_init() * * @param index USB controller number for selective cleanup |
bba679144 usb: rename board... |
184 |
* @param init usb_init_type passed to board_usb_init() |
16297cfb2 usb: new board-sp... |
185 |
*/ |
bba679144 usb: rename board... |
186 |
int board_usb_cleanup(int index, enum usb_init_type init); |
16297cfb2 usb: new board-sp... |
187 |
|
351e9b206 usb: ums: add ums... |
188 189 190 191 192 193 194 195 196 |
/* * If CONFIG_USB_CABLE_CHECK is set then this function * should be defined in board file. * * @return 1 if cable is connected and 0 otherwise. */ #ifdef CONFIG_USB_CABLE_CHECK int usb_cable_connected(void); #endif |
012771d88 Initial revision |
197 198 199 200 201 |
#ifdef CONFIG_USB_STORAGE #define USB_MAX_STOR_DEV 5 block_dev_desc_t *usb_stor_get_dev(int index); int usb_stor_scan(int mode); |
e813eae3b Fix compilation e... |
202 |
int usb_stor_info(void); |
012771d88 Initial revision |
203 204 |
#endif |
89d48367e Add USB host ethe... |
205 206 207 208 209 210 |
#ifdef CONFIG_USB_HOST_ETHER #define USB_MAX_ETH_DEV 5 int usb_host_eth_scan(int mode); #endif |
012771d88 Initial revision |
211 212 213 214 215 216 217 218 219 220 221 222 |
#ifdef CONFIG_USB_KEYBOARD int drv_usb_kbd_init(void); int usb_kbd_deregister(void); #endif /* routines */ int usb_init(void); /* initialize the USB Controller */ int usb_stop(void); /* stop the USB Controller */ int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol); |
de39f8c19 USB style patch, ... |
223 224 225 |
int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id); struct usb_device *usb_get_dev_index(int index); |
012771d88 Initial revision |
226 227 228 229 230 231 232 |
int usb_control_msg(struct usb_device *dev, unsigned int pipe, unsigned char request, unsigned char requesttype, unsigned short value, unsigned short index, void *data, unsigned short size, int timeout); int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout); int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe, |
de39f8c19 USB style patch, ... |
233 |
void *buffer, int transfer_len, int interval); |
89d48367e Add USB host ethe... |
234 |
int usb_disable_asynch(int disable); |
de39f8c19 USB style patch, ... |
235 |
int usb_maxpacket(struct usb_device *dev, unsigned long pipe); |
de39f8c19 USB style patch, ... |
236 237 238 239 |
int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer, int cfgno); int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type, unsigned char id, void *buf, int size); |
012771d88 Initial revision |
240 |
int usb_get_class_descriptor(struct usb_device *dev, int ifnum, |
de39f8c19 USB style patch, ... |
241 242 |
unsigned char type, unsigned char id, void *buf, int size); |
012771d88 Initial revision |
243 244 245 246 247 |
int usb_clear_halt(struct usb_device *dev, int pipe); int usb_string(struct usb_device *dev, int index, char *buf, size_t size); int usb_set_interface(struct usb_device *dev, int interface, int alternate); /* big endian -> little endian conversion */ |
149dded2b * Add support for... |
248 |
/* some CPUs are already little endian e.g. the ARM920T */ |
ae3b770e4 Fix some endianne... |
249 |
#define __swap_16(x) \ |
3f85ce278 * CVS add missing... |
250 251 |
({ unsigned short x_ = (unsigned short)x; \ (unsigned short)( \ |
de39f8c19 USB style patch, ... |
252 |
((x_ & 0x00FFU) << 8) | ((x_ & 0xFF00U) >> 8)); \ |
3f85ce278 * CVS add missing... |
253 |
}) |
ae3b770e4 Fix some endianne... |
254 |
#define __swap_32(x) \ |
3f85ce278 * CVS add missing... |
255 256 257 |
({ unsigned long x_ = (unsigned long)x; \ (unsigned long)( \ ((x_ & 0x000000FFUL) << 24) | \ |
5cf91d6bd * Modify KUP4X bo... |
258 259 |
((x_ & 0x0000FF00UL) << 8) | \ ((x_ & 0x00FF0000UL) >> 8) | \ |
de39f8c19 USB style patch, ... |
260 |
((x_ & 0xFF000000UL) >> 24)); \ |
3f85ce278 * CVS add missing... |
261 |
}) |
ae3b770e4 Fix some endianne... |
262 |
|
c7d703f3f usb.h: use standa... |
263 |
#ifdef __LITTLE_ENDIAN |
ae3b770e4 Fix some endianne... |
264 265 266 267 268 |
# define swap_16(x) (x) # define swap_32(x) (x) #else # define swap_16(x) __swap_16(x) # define swap_32(x) __swap_32(x) |
c7d703f3f usb.h: use standa... |
269 |
#endif |
012771d88 Initial revision |
270 271 272 273 274 275 276 277 278 |
/* * Calling this entity a "pipe" is glorifying it. A USB pipe * is something embarrassingly simple: it basically consists * of the following information: * - device number (7 bits) * - endpoint number (4 bits) * - current Data0/1 state (1 bit) * - direction (1 bit) |
3e126484d Prepare USB layer... |
279 |
* - speed (2 bits) |
012771d88 Initial revision |
280 281 282 283 284 285 286 287 288 289 290 |
* - max packet size (2 bits: 8, 16, 32 or 64) * - pipe type (2 bits: control, interrupt, bulk, isochronous) * * That's 18 bits. Really. Nothing more. And the USB people have * documented these eighteen bits as some kind of glorious * virtual data structure. * * Let's not fall in that trap. We'll just encode it as a simple * unsigned int. The encoding is: * * - max size: bits 0-1 (00 = 8, 01 = 16, 10 = 32, 11 = 64) |
de39f8c19 USB style patch, ... |
291 292 |
* - direction: bit 7 (0 = Host-to-Device [Out], * (1 = Device-to-Host [In]) |
012771d88 Initial revision |
293 294 295 |
* - device: bits 8-14 * - endpoint: bits 15-18 * - Data0/1: bit 19 |
de39f8c19 USB style patch, ... |
296 297 |
* - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt, * 10 = control, 11 = bulk) |
012771d88 Initial revision |
298 299 300 301 302 303 304 305 |
* * Why? Because it's arbitrary, and whatever encoding we select is really * up to us. This one happens to share a lot of bit positions with the UHCI * specification, so that much of the uhci driver can just mask the bits * appropriately. */ /* Create various pipes... */ #define create_pipe(dev,endpoint) \ |
d0fe1128c USB: fix create_p... |
306 |
(((dev)->devnum << 8) | ((endpoint) << 15) | \ |
c60795f41 usb: use linux/us... |
307 |
(dev)->maxpacketsize) |
3e126484d Prepare USB layer... |
308 |
#define default_pipe(dev) ((dev)->speed << 26) |
de39f8c19 USB style patch, ... |
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
#define usb_sndctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \ create_pipe(dev, endpoint)) #define usb_rcvctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \ create_pipe(dev, endpoint) | \ USB_DIR_IN) #define usb_sndisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \ create_pipe(dev, endpoint)) #define usb_rcvisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \ create_pipe(dev, endpoint) | \ USB_DIR_IN) #define usb_sndbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \ create_pipe(dev, endpoint)) #define usb_rcvbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \ create_pipe(dev, endpoint) | \ USB_DIR_IN) #define usb_sndintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \ create_pipe(dev, endpoint)) #define usb_rcvintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \ create_pipe(dev, endpoint) | \ USB_DIR_IN) #define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | \ default_pipe(dev)) #define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | \ default_pipe(dev) | \ USB_DIR_IN) |
012771d88 Initial revision |
335 336 337 |
/* The D0/D1 toggle bits */ #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1) |
5cf91d6bd * Modify KUP4X bo... |
338 |
#define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep)) |
de39f8c19 USB style patch, ... |
339 340 341 |
#define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = \ ((dev)->toggle[out] & \ ~(1 << ep)) | ((bit) << ep)) |
012771d88 Initial revision |
342 343 344 345 346 347 |
/* Endpoint halt control/status */ #define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1) #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep))) #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep))) #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep))) |
de39f8c19 USB style patch, ... |
348 349 |
#define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : \ USB_PID_OUT) |
012771d88 Initial revision |
350 351 352 353 354 355 356 |
#define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1) #define usb_pipein(pipe) (((pipe) >> 7) & 1) #define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f) #define usb_pipe_endpdev(pipe) (((pipe) >> 8) & 0x7ff) #define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf) #define usb_pipedata(pipe) (((pipe) >> 19) & 1) |
012771d88 Initial revision |
357 358 359 360 361 |
#define usb_pipetype(pipe) (((pipe) >> 30) & 3) #define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS) #define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT) #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL) #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK) |
5853e1335 USB: xHCI: Add st... |
362 363 364 365 |
#define usb_pipe_ep_index(pipe) \ usb_pipecontrol(pipe) ? (usb_pipeendpoint(pipe) * 2) : \ ((usb_pipeendpoint(pipe) * 2) - \ (usb_pipein(pipe) ? 0 : 1)) |
012771d88 Initial revision |
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
/************************************************************************* * Hub Stuff */ struct usb_port_status { unsigned short wPortStatus; unsigned short wPortChange; } __attribute__ ((packed)); struct usb_hub_status { unsigned short wHubStatus; unsigned short wHubChange; } __attribute__ ((packed)); /* Hub descriptor */ struct usb_hub_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bNbrPorts; unsigned short wHubCharacteristics; unsigned char bPwrOn2PwrGood; unsigned char bHubContrCurrent; unsigned char DeviceRemovable[(USB_MAXCHILDREN+1+7)/8]; unsigned char PortPowerCtrlMask[(USB_MAXCHILDREN+1+7)/8]; |
de39f8c19 USB style patch, ... |
391 |
/* DeviceRemovable and PortPwrCtrlMask want to be variable-length |
012771d88 Initial revision |
392 393 394 395 396 397 398 399 |
bitmaps that hold max 255 entries. (bit0 is ignored) */ } __attribute__ ((packed)); struct usb_hub_device { struct usb_device *pusb_dev; struct usb_hub_descriptor desc; }; |
23faf2bc9 USB: Separate out... |
400 401 402 403 |
int usb_hub_probe(struct usb_device *dev, int ifnum); void usb_hub_reset(void); int hub_port_reset(struct usb_device *dev, int port, unsigned short *portstat); |
c7e3b2b58 usb: lowlevel int... |
404 |
struct usb_device *usb_alloc_new_device(void *controller); |
23faf2bc9 USB: Separate out... |
405 |
int usb_new_device(struct usb_device *dev); |
359439d28 usb: Clean up new... |
406 |
void usb_free_device(void); |
5853e1335 USB: xHCI: Add st... |
407 |
int usb_alloc_device(struct usb_device *dev); |
23faf2bc9 USB: Separate out... |
408 |
|
012771d88 Initial revision |
409 |
#endif /*_USB_H_ */ |