RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / cfe / cfe / usb / usbd.h
blob73fde869aa4f96a7da8f33404327e7b055a3f958
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * USB Device Layer definitions File: usbd.h
5 *
6 * Definitions for the USB device layer.
7 *
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
9 *
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
47 #ifndef _PHYSADDR_T_DEFINED_
48 #include "lib_physio.h"
49 #endif
51 #include "usbchap9.h"
54 /* *********************************************************************
55 * Forward declarations and opaque types
56 ********************************************************************* */
58 typedef struct usb_hc_s usb_hc_t;
59 typedef struct usb_ept_s usb_ept_t;
60 typedef struct usb_hcdrv_s usb_hcdrv_t;
61 typedef struct usbdev_s usbdev_t;
62 typedef struct usb_driver_s usb_driver_t;
64 /* *********************************************************************
65 * USB Bus structure - one of these per host controller
66 ********************************************************************* */
68 #define USB_MAX_DEVICES 128
70 typedef struct usbbus_s {
71 struct usbbus_s *ub_next; /* link to other buses */
72 usb_hc_t *ub_hwsoftc; /* bus driver softc */
73 usb_hcdrv_t *ub_hwdisp; /* bus driver dispatch */
74 usbdev_t *ub_roothub; /* root hub device */
75 usbdev_t *ub_devices[USB_MAX_DEVICES]; /* pointers to each device, idx by address */
76 unsigned int ub_flags; /* flag bits */
77 int ub_num; /* bus number */
78 } usbbus_t;
80 #define UB_FLG_NEEDSCAN 1 /* some device on bus needs scanning */
82 /* *********************************************************************
83 * USB Pipe structure - one of these per unidirectional channel
84 * to an endpoint on a USB device
85 ********************************************************************* */
87 #define UP_TYPE_CONTROL 1
88 #define UP_TYPE_BULK 2
89 #define UP_TYPE_INTR 4
90 #define UP_TYPE_ISOC 8
92 #define UP_TYPE_IN 128
93 #define UP_TYPE_OUT 256
95 #define UP_TYPE_LOWSPEED 16
97 typedef struct usbpipe_s {
98 usb_ept_t *up_hwendpoint; /* OHCI-specific endpoint pointer */
99 usbdev_t *up_dev; /* our device info */
100 int up_num; /* pipe number */
101 int up_mps; /* max packet size */
102 int up_flags;
103 } usbpipe_t;
105 /* *********************************************************************
106 * USB device structure - one per device attached to the USB
107 * This is the basic structure applications will use to
108 * refer to a device.
109 ********************************************************************* */
111 #define UD_FLAG_HUB 0x0001 /* this is a hub device */
112 #define UD_FLAG_ROOTHUB 0x0002 /* this is a root hub device */
113 #define UD_FLAG_LOWSPEED 0x0008 /* this is a lowspeed device */
115 #define UD_MAX_PIPES 32
116 #define USB_EPADDR_TO_IDX(addr) ((((addr)&0x80) >> 3) | ((addr) & 0x0F))
117 //#define USB_EPADDR_TO_IDX(addr) USB_ENDPOINT_ADDRESS(addr)
118 //#define UD_MAX_PIPES 16
120 struct usbdev_s {
121 usb_driver_t *ud_drv; /* Driver's methods */
122 usbbus_t *ud_bus; /* owning bus */
123 int ud_address; /* USB address */
124 usbpipe_t *ud_pipes[UD_MAX_PIPES]; /* pipes, 0 is the control pipe */
125 struct usbdev_s *ud_parent; /* used for hubs */
126 int ud_flags;
127 void *ud_private; /* private data for device driver */
128 usb_device_descr_t ud_devdescr; /* device descriptor */
129 usb_config_descr_t *ud_cfgdescr; /* config, interface, and ep descrs */
133 /* *********************************************************************
134 * USB Request - basic structure to describe an in-progress
135 * I/O request. It associates buses, pipes, and buffers
136 * together.
137 ********************************************************************* */
140 #define UR_FLAG_SYNC 0x8000
142 #define UR_FLAG_SETUP 0x0001
143 #define UR_FLAG_IN 0x0002
144 #define UR_FLAG_OUT 0x0004
145 #define UR_FLAG_STATUS_IN 0x0008 /* status phase of a control WRITE */
146 #define UR_FLAG_STATUS_OUT 0x0010 /* status phase of a control READ */
147 #define UR_FLAG_SHORTOK 0x0020 /* short transfers are ok */
150 typedef struct usbreq_s {
151 queue_t ur_qblock;
154 * pointers to our device and pipe
157 usbdev_t *ur_dev;
158 usbpipe_t *ur_pipe;
161 * stuff to keep track of the data we transfer
164 uint8_t *ur_buffer;
165 int ur_length;
166 int ur_xferred;
167 int ur_status;
168 int ur_flags;
171 * Stuff needed for the callback
173 void *ur_ref;
174 int ur_inprogress;
175 int (*ur_callback)(struct usbreq_s *req);
178 * For use inside the ohci driver
180 void *ur_tdqueue;
181 int ur_tdcount;
182 } usbreq_t;
185 /* *********************************************************************
186 * Prototypes
187 ********************************************************************* */
189 int usb_create_pipe(usbdev_t *dev,int pipenum,int mps,int flags);
190 void usb_destroy_pipe(usbdev_t *dev,int pipenum);
191 int usb_set_address(usbdev_t *dev,int addr);
192 usbdev_t *usb_create_device(usbbus_t *bus,int lowspeed);
193 void usb_destroy_device(usbdev_t *dev);
194 usbreq_t *usb_make_request(usbdev_t *dev,int pipenum,uint8_t *buf,int length,int flags);
195 void usb_poll(usbbus_t *bus);
196 void usb_daemon(usbbus_t *bus);
197 int usb_cancel_request(usbreq_t *ur);
198 void usb_free_request(usbreq_t *ur);
199 int usb_queue_request(usbreq_t *ur);
200 int usb_wait_request(usbreq_t *ur);
201 int usb_sync_request(usbreq_t *ur);
202 int usb_get_descriptor(usbdev_t *dev,uint8_t reqtype,int dsctype,int dscidx,uint8_t *buffer,int buflen);
203 int usb_get_config_descriptor(usbdev_t *dev,usb_config_descr_t *dscr,int idx,int maxlen);
204 int usb_get_device_status(usbdev_t *dev,usb_device_status_t *status);
205 int usb_set_configuration(usbdev_t *dev,int config);
206 int usb_open_pipe(usbdev_t *dev,usb_endpoint_descr_t *epdesc);
207 int usb_simple_request(usbdev_t *dev,uint8_t reqtype,int bRequest,int wValue,int wIndex);
208 void usb_complete_request(usbreq_t *ur,int status);
209 int usb_get_device_descriptor(usbdev_t *dev,usb_device_descr_t *dscr,int smallflg);
210 int usb_set_ep0mps(usbdev_t *dev,int mps);
211 int usb_new_address(usbbus_t *bus);
212 int usb_get_string(usbdev_t *dev,int id,char *buf,int maxlen);
213 int usb_std_request(usbdev_t *dev,uint8_t bmRequestType,
214 uint8_t bRequest,uint16_t wValue,
215 uint16_t wIndex,uint8_t *buffer,int length);
216 void *usb_find_cfg_descr(usbdev_t *dev,int dtype,int idx);
217 void usb_delay_ms(usbbus_t *bus,int ms);
218 int usb_clear_stall(usbdev_t *dev,int pipe);
220 void usb_scan(usbbus_t *bus);
221 void usbhub_map_tree(usbbus_t *bus,int (*func)(usbdev_t *dev,void *arg),void *arg);
222 void usbhub_dumpbus(usbbus_t *bus,uint32_t verbose);
224 void usb_initroot(usbbus_t *bus);
227 /* *********************************************************************
228 * Host Controller Driver
229 * Methods for abstracting the USB host controller from the
230 * rest of the goop.
231 ********************************************************************* */
233 struct usb_hcdrv_s {
234 usbbus_t * (*hcdrv_create)(physaddr_t regaddr);
235 void (*hcdrv_delete)(usbbus_t *);
236 int (*hcdrv_start)(usbbus_t *);
237 void (*hcdrv_stop)(usbbus_t *);
238 int (*hcdrv_intr)(usbbus_t *);
239 usb_ept_t * (*hcdrv_ept_create)(usbbus_t *,int usbaddr,int eptnum,int mps,int flags);
240 void (*hcdrv_ept_delete)(usbbus_t *,usb_ept_t *);
241 void (*hcdrv_ept_setmps)(usbbus_t *,usb_ept_t *,int mps);
242 void (*hcdrv_ept_setaddr)(usbbus_t *,usb_ept_t *,int addr);
243 void (*hcdrv_ept_cleartoggle)(usbbus_t *,usb_ept_t *);
244 int (*hcdrv_xfer)(usbbus_t *,usb_ept_t *uept,usbreq_t *ur);
247 #define UBCREATE(driver,addr) (*((driver)->hcdrv_create))(addr)
248 #define UBDELETE(bus) (*((bus)->ub_hwdisp->hcdrv_delete))(bus)
249 #define UBSTART(bus) (*((bus)->ub_hwdisp->hcdrv_start))(bus)
250 #define UBSTOP(bus) (*((bus)->ub_hwdisp->hcdrv_stop))(bus)
251 #define UBINTR(bus) (*((bus)->ub_hwdisp->hcdrv_intr))(bus)
252 #define UBEPTCREATE(bus,addr,num,mps,flags) (*((bus)->ub_hwdisp->hcdrv_ept_create))(bus,addr,num,mps,flags)
253 #define UBEPTDELETE(bus,ept) (*((bus)->ub_hwdisp->hcdrv_ept_delete))(bus,ept)
254 #define UBEPTSETMPS(bus,ept,mps) (*((bus)->ub_hwdisp->hcdrv_ept_setmps))(bus,ept,mps)
255 #define UBEPTSETADDR(bus,ept,addr) (*((bus)->ub_hwdisp->hcdrv_ept_setaddr))(bus,ept,addr)
256 #define UBEPTCLEARTOGGLE(bus,ept) (*((bus)->ub_hwdisp->hcdrv_ept_cleartoggle))(bus,ept)
257 #define UBXFER(bus,ept,xfer) (*((bus)->ub_hwdisp->hcdrv_xfer))(bus,ept,xfer)
259 /* *********************************************************************
260 * Devices - methods for abstracting things that _use_ USB
261 * (devices you can plug into the USB) - the entry points
262 * here are basically just for device discovery, since the top half
263 * of the actual driver will be device-specific.
264 ********************************************************************* */
266 struct usb_driver_s {
267 char *udrv_name;
268 int (*udrv_attach)(usbdev_t *,usb_driver_t *);
269 int (*udrv_detach)(usbdev_t *);
272 typedef struct usb_drvlist_s {
273 int udl_class;
274 int udl_vendor;
275 int udl_product;
276 usb_driver_t *udl_disp;
277 } usb_drvlist_t;
279 extern usb_driver_t *usb_find_driver(usbdev_t *dev);
281 #define CLASS_ANY -1
282 #define VENDOR_ANY -1
283 #define PRODUCT_ANY -1
285 void mydelay(int x);
287 #define IS_HUB(dev) ((dev)->ud_devdescr.bDeviceClass == USB_DEVICE_CLASS_HUB)
289 /* *********************************************************************
290 * Error codes
291 ********************************************************************* */
293 #define USBD_ERR_OK 0 /* Request ok */
294 #define USBD_ERR_STALLED -1 /* Endpoint is stalled */
295 #define USBD_ERR_IOERROR -2 /* I/O error */
296 #define USBD_ERR_HWERROR -3 /* Hardware failure */
297 #define USBD_ERR_CANCELED -4 /* Request canceled */
298 #define USBD_ERR_NOMEM -5 /* Out of memory */
299 #define USBD_ERR_TIMEOUT -6 /* Request timeout */
301 /* *********************************************************************
302 * Debug routines
303 ********************************************************************* */
305 void usb_dbg_dumpportstatus(int port,usb_port_status_t *portstatus,int level);
306 void usb_dbg_dumpdescriptors(usbdev_t *dev,uint8_t *ptr,int len);
307 void usb_dbg_dumpcfgdescr(usbdev_t *dev);
308 void usb_dbg_dumpeptdescr(usb_endpoint_descr_t * epdscr);