2002-03-09 05:31:05 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2001
|
|
|
|
* Denis Peter, MPL AG Switzerland
|
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2002-03-09 05:31:05 +08:00
|
|
|
* Note: Part of this code has been derived from linux
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef _USB_H_
|
|
|
|
#define _USB_H_
|
|
|
|
|
|
|
|
#include <usb_defs.h>
|
2012-11-06 21:48:20 +08:00
|
|
|
#include <linux/usb/ch9.h>
|
2014-11-07 17:34:55 +08:00
|
|
|
#include <asm/cache.h>
|
|
|
|
#include <part.h>
|
2002-03-09 05:31:05 +08:00
|
|
|
|
2012-07-16 06:14:24 +08:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2002-03-09 05:31:05 +08:00
|
|
|
/* Everything is aribtrary */
|
2004-04-24 04:32:05 +08:00
|
|
|
#define USB_ALTSETTINGALLOC 4
|
|
|
|
#define USB_MAXALTSETTING 128 /* Hard limit */
|
2002-03-09 05:31:05 +08:00
|
|
|
|
2004-04-24 04:32:05 +08:00
|
|
|
#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
|
2002-03-09 05:31:05 +08:00
|
|
|
|
|
|
|
#define USB_CNTL_TIMEOUT 100 /* 100ms timeout */
|
|
|
|
|
2011-02-08 06:42:16 +08:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-08-01 04:09:58 +08:00
|
|
|
#define USB_TIMEOUT_MS(pipe) (usb_pipebulk(pipe) ? 5000 : 1000)
|
2011-02-08 06:42:16 +08:00
|
|
|
|
2002-03-09 05:31:05 +08:00
|
|
|
/* device request (setup) */
|
|
|
|
struct devrequest {
|
2008-11-27 00:41:34 +08:00
|
|
|
unsigned char requesttype;
|
|
|
|
unsigned char request;
|
|
|
|
unsigned short value;
|
|
|
|
unsigned short index;
|
|
|
|
unsigned short length;
|
2002-03-09 05:31:05 +08:00
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
2009-11-01 01:37:38 +08:00
|
|
|
/* Interface */
|
|
|
|
struct usb_interface {
|
|
|
|
struct usb_interface_descriptor desc;
|
2008-11-27 00:41:34 +08:00
|
|
|
|
|
|
|
unsigned char no_of_ep;
|
|
|
|
unsigned char num_altsetting;
|
|
|
|
unsigned char act_altsetting;
|
|
|
|
|
2002-03-09 05:31:05 +08:00
|
|
|
struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS];
|
2013-04-12 19:04:38 +08:00
|
|
|
/*
|
|
|
|
* 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];
|
2002-03-09 05:31:05 +08:00
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
2009-11-01 01:37:38 +08:00
|
|
|
/* Configuration information.. */
|
|
|
|
struct usb_config {
|
2012-11-06 21:48:20 +08:00
|
|
|
struct usb_config_descriptor desc;
|
2008-11-27 00:41:34 +08:00
|
|
|
|
|
|
|
unsigned char no_of_if; /* number of interfaces */
|
2009-11-01 01:37:38 +08:00
|
|
|
struct usb_interface if_desc[USB_MAXINTERFACES];
|
2002-03-09 05:31:05 +08:00
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
fix USB initialisation procedure
The max packet size is encoded as 0,1,2,3 for 8,16,32,64 bytes.
At some places directly 8,16,32,64 was used instead of the encoded
value. Made a enum for the options to make this more clear and to help
preventing similar errors in the future.
After fixing this bug it became clear that another bug existed where
the 'pipe' is and-ed with PIPE_* flags, where it should have been
'usb_pipetype(pipe)', or even better usb_pipeint(pipe).
Also removed the triple 'get_device_descriptor' sequence, it has no use,
and Windows nor Linux behaves that way.
There is also a poll going on with a timeout when usb_control_msg() fails.
However, the poll is useless, because the flag will never be set on a error,
because there is no code that runs in a parallel that can set this flag.
Changed this to something more logical.
Tested on AT91SAM9261ek and compared the flow on the USB bus to what
Linux is doing. There is no difference anymore in the early initialisation
sequence.
Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Markus Klotzbuecher <mk@denx.de>
2008-10-10 16:23:21 +08:00
|
|
|
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,
|
|
|
|
};
|
2002-03-09 05:31:05 +08:00
|
|
|
|
|
|
|
struct usb_device {
|
2008-11-27 00:41:34 +08:00
|
|
|
int devnum; /* Device number on USB bus */
|
2008-11-28 20:19:19 +08:00
|
|
|
int speed; /* full/low/high */
|
2008-11-27 00:41:34 +08:00
|
|
|
char mf[32]; /* manufacturer */
|
|
|
|
char prod[32]; /* product */
|
|
|
|
char serial[32]; /* serial number */
|
2002-03-09 05:31:05 +08:00
|
|
|
|
fix USB initialisation procedure
The max packet size is encoded as 0,1,2,3 for 8,16,32,64 bytes.
At some places directly 8,16,32,64 was used instead of the encoded
value. Made a enum for the options to make this more clear and to help
preventing similar errors in the future.
After fixing this bug it became clear that another bug existed where
the 'pipe' is and-ed with PIPE_* flags, where it should have been
'usb_pipetype(pipe)', or even better usb_pipeint(pipe).
Also removed the triple 'get_device_descriptor' sequence, it has no use,
and Windows nor Linux behaves that way.
There is also a poll going on with a timeout when usb_control_msg() fails.
However, the poll is useless, because the flag will never be set on a error,
because there is no code that runs in a parallel that can set this flag.
Changed this to something more logical.
Tested on AT91SAM9261ek and compared the flow on the USB bus to what
Linux is doing. There is no difference anymore in the early initialisation
sequence.
Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Markus Klotzbuecher <mk@denx.de>
2008-10-10 16:23:21 +08:00
|
|
|
/* Maximum packet size; one of: PACKET_SIZE_* */
|
|
|
|
int maxpacketsize;
|
|
|
|
/* one bit for each endpoint ([0] = IN, [1] = OUT) */
|
|
|
|
unsigned int toggle[2];
|
2008-11-27 00:41:34 +08:00
|
|
|
/* endpoint halts; one bit per endpoint # & direction;
|
|
|
|
* [0] = IN, [1] = OUT
|
|
|
|
*/
|
fix USB initialisation procedure
The max packet size is encoded as 0,1,2,3 for 8,16,32,64 bytes.
At some places directly 8,16,32,64 was used instead of the encoded
value. Made a enum for the options to make this more clear and to help
preventing similar errors in the future.
After fixing this bug it became clear that another bug existed where
the 'pipe' is and-ed with PIPE_* flags, where it should have been
'usb_pipetype(pipe)', or even better usb_pipeint(pipe).
Also removed the triple 'get_device_descriptor' sequence, it has no use,
and Windows nor Linux behaves that way.
There is also a poll going on with a timeout when usb_control_msg() fails.
However, the poll is useless, because the flag will never be set on a error,
because there is no code that runs in a parallel that can set this flag.
Changed this to something more logical.
Tested on AT91SAM9261ek and compared the flow on the USB bus to what
Linux is doing. There is no difference anymore in the early initialisation
sequence.
Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Markus Klotzbuecher <mk@denx.de>
2008-10-10 16:23:21 +08:00
|
|
|
unsigned int halted[2];
|
2002-03-09 05:31:05 +08:00
|
|
|
int epmaxpacketin[16]; /* INput endpoint specific maximums */
|
|
|
|
int epmaxpacketout[16]; /* OUTput endpoint specific maximums */
|
|
|
|
|
|
|
|
int configno; /* selected config number */
|
2012-04-03 17:26:06 +08:00
|
|
|
/* Device Descriptor */
|
|
|
|
struct usb_device_descriptor descriptor
|
|
|
|
__attribute__((aligned(ARCH_DMA_MINALIGN)));
|
2009-11-01 01:37:38 +08:00
|
|
|
struct usb_config config; /* config descriptor */
|
2002-03-09 05:31:05 +08:00
|
|
|
|
|
|
|
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;
|
2004-04-24 04:32:05 +08:00
|
|
|
int irq_act_len; /* transfered bytes */
|
2002-03-09 05:31:05 +08:00
|
|
|
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 */
|
2008-11-28 20:19:19 +08:00
|
|
|
int portnr;
|
2002-03-09 05:31:05 +08:00
|
|
|
struct usb_device *parent;
|
|
|
|
struct usb_device *children[USB_MAXCHILDREN];
|
2012-09-26 06:14:34 +08:00
|
|
|
|
|
|
|
void *controller; /* hardware controller private data */
|
2013-09-14 16:32:45 +08:00
|
|
|
/* slot_id - for xHCI enabled devices */
|
|
|
|
unsigned int slot_id;
|
2002-03-09 05:31:05 +08:00
|
|
|
};
|
|
|
|
|
2014-09-24 20:06:06 +08:00
|
|
|
struct int_queue;
|
|
|
|
|
2013-10-11 06:27:55 +08:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
};
|
|
|
|
|
2002-03-09 05:31:05 +08:00
|
|
|
/**********************************************************************
|
|
|
|
* this is how the lowlevel part communicate with the outer world
|
|
|
|
*/
|
|
|
|
|
2007-04-03 20:27:18 +08:00
|
|
|
#if defined(CONFIG_USB_UHCI) || defined(CONFIG_USB_OHCI) || \
|
2008-12-11 20:43:55 +08:00
|
|
|
defined(CONFIG_USB_EHCI) || defined(CONFIG_USB_OHCI_NEW) || \
|
2008-11-28 20:19:19 +08:00
|
|
|
defined(CONFIG_USB_SL811HS) || defined(CONFIG_USB_ISP116X_HCD) || \
|
2009-11-01 01:37:41 +08:00
|
|
|
defined(CONFIG_USB_R8A66597_HCD) || defined(CONFIG_USB_DAVINCI) || \
|
2009-12-17 11:04:02 +08:00
|
|
|
defined(CONFIG_USB_OMAP3) || defined(CONFIG_USB_DA8XX) || \
|
2012-11-06 21:48:22 +08:00
|
|
|
defined(CONFIG_USB_BLACKFIN) || defined(CONFIG_USB_AM35X) || \
|
2012-11-06 21:48:29 +08:00
|
|
|
defined(CONFIG_USB_MUSB_DSPS) || defined(CONFIG_USB_MUSB_AM35X) || \
|
2015-01-12 03:34:48 +08:00
|
|
|
defined(CONFIG_USB_MUSB_OMAP2PLUS) || defined(CONFIG_USB_MUSB_SUNXI) || \
|
|
|
|
defined(CONFIG_USB_XHCI) || defined(CONFIG_USB_DWC2)
|
2007-04-03 20:27:18 +08:00
|
|
|
|
2013-10-11 06:27:56 +08:00
|
|
|
int usb_lowlevel_init(int index, enum usb_init_type init, void **controller);
|
2012-09-26 06:14:34 +08:00
|
|
|
int usb_lowlevel_stop(int index);
|
|
|
|
|
2008-11-27 00:41:34 +08:00
|
|
|
int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
|
|
|
|
void *buffer, int transfer_len);
|
2002-03-09 05:31:05 +08:00
|
|
|
int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
|
2008-11-27 00:41:34 +08:00
|
|
|
int transfer_len, struct devrequest *setup);
|
2002-03-09 05:31:05 +08:00
|
|
|
int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
|
|
|
|
int transfer_len, int interval);
|
|
|
|
|
2014-09-24 20:06:06 +08:00
|
|
|
#ifdef CONFIG_USB_EHCI /* Only the ehci code has pollable int support */
|
|
|
|
struct int_queue *create_int_queue(struct usb_device *dev, unsigned long pipe,
|
2015-01-12 03:38:28 +08:00
|
|
|
int queuesize, int elementsize, void *buffer, int interval);
|
2014-09-24 20:06:06 +08:00
|
|
|
int destroy_int_queue(struct usb_device *dev, struct int_queue *queue);
|
|
|
|
void *poll_int_queue(struct usb_device *dev, struct int_queue *queue);
|
|
|
|
#endif
|
|
|
|
|
2002-03-09 05:31:05 +08:00
|
|
|
/* Defines */
|
2008-11-27 00:41:34 +08:00
|
|
|
#define USB_UHCI_VEND_ID 0x8086
|
|
|
|
#define USB_UHCI_DEV_ID 0x7112
|
2002-03-09 05:31:05 +08:00
|
|
|
|
2012-10-02 23:04:33 +08:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
2002-03-09 05:31:05 +08:00
|
|
|
#endif
|
|
|
|
|
2013-10-05 01:22:26 +08:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2013-10-11 06:27:55 +08:00
|
|
|
int board_usb_init(int index, enum usb_init_type init);
|
2013-10-05 01:22:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* can be used to clean up after failed USB initialization attempt
|
|
|
|
* vide: board_usb_init()
|
|
|
|
*
|
|
|
|
* @param index USB controller number for selective cleanup
|
2013-10-11 06:27:55 +08:00
|
|
|
* @param init usb_init_type passed to board_usb_init()
|
2013-10-05 01:22:26 +08:00
|
|
|
*/
|
2013-10-11 06:27:55 +08:00
|
|
|
int board_usb_cleanup(int index, enum usb_init_type init);
|
2013-10-05 01:22:26 +08:00
|
|
|
|
2002-03-09 05:31:05 +08:00
|
|
|
#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);
|
2008-03-27 00:47:44 +08:00
|
|
|
int usb_stor_info(void);
|
2002-03-09 05:31:05 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-02-17 03:14:33 +08:00
|
|
|
#ifdef CONFIG_USB_HOST_ETHER
|
|
|
|
|
|
|
|
#define USB_MAX_ETH_DEV 5
|
|
|
|
int usb_host_eth_scan(int mode);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2002-03-09 05:31:05 +08:00
|
|
|
#ifdef CONFIG_USB_KEYBOARD
|
|
|
|
|
|
|
|
int drv_usb_kbd_init(void);
|
2014-09-20 22:54:38 +08:00
|
|
|
int usb_kbd_deregister(int force);
|
2002-03-09 05:31:05 +08:00
|
|
|
|
|
|
|
#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);
|
2008-11-27 00:41:34 +08:00
|
|
|
int usb_set_idle(struct usb_device *dev, int ifnum, int duration,
|
|
|
|
int report_id);
|
|
|
|
struct usb_device *usb_get_dev_index(int index);
|
2002-03-09 05:31:05 +08:00
|
|
|
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,
|
2008-11-27 00:41:34 +08:00
|
|
|
void *buffer, int transfer_len, int interval);
|
2011-02-17 03:14:33 +08:00
|
|
|
int usb_disable_asynch(int disable);
|
2008-11-27 00:41:34 +08:00
|
|
|
int usb_maxpacket(struct usb_device *dev, unsigned long pipe);
|
|
|
|
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);
|
2002-03-09 05:31:05 +08:00
|
|
|
int usb_get_class_descriptor(struct usb_device *dev, int ifnum,
|
2008-11-27 00:41:34 +08:00
|
|
|
unsigned char type, unsigned char id, void *buf,
|
|
|
|
int size);
|
2002-03-09 05:31:05 +08:00
|
|
|
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 */
|
2003-09-11 02:20:28 +08:00
|
|
|
/* some CPUs are already little endian e.g. the ARM920T */
|
2006-11-27 18:46:46 +08:00
|
|
|
#define __swap_16(x) \
|
2004-02-24 00:11:30 +08:00
|
|
|
({ unsigned short x_ = (unsigned short)x; \
|
|
|
|
(unsigned short)( \
|
2008-11-27 00:41:34 +08:00
|
|
|
((x_ & 0x00FFU) << 8) | ((x_ & 0xFF00U) >> 8)); \
|
2004-02-24 00:11:30 +08:00
|
|
|
})
|
2006-11-27 18:46:46 +08:00
|
|
|
#define __swap_32(x) \
|
2004-02-24 00:11:30 +08:00
|
|
|
({ unsigned long x_ = (unsigned long)x; \
|
|
|
|
(unsigned long)( \
|
|
|
|
((x_ & 0x000000FFUL) << 24) | \
|
2004-04-24 04:32:05 +08:00
|
|
|
((x_ & 0x0000FF00UL) << 8) | \
|
|
|
|
((x_ & 0x00FF0000UL) >> 8) | \
|
2008-11-27 00:41:34 +08:00
|
|
|
((x_ & 0xFF000000UL) >> 24)); \
|
2004-02-24 00:11:30 +08:00
|
|
|
})
|
2006-11-27 18:46:46 +08:00
|
|
|
|
2009-01-02 07:27:27 +08:00
|
|
|
#ifdef __LITTLE_ENDIAN
|
2006-11-27 18:46:46 +08:00
|
|
|
# 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)
|
2009-01-02 07:27:27 +08:00
|
|
|
#endif
|
2002-03-09 05:31:05 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
2008-11-28 20:19:19 +08:00
|
|
|
* - speed (2 bits)
|
2002-03-09 05:31:05 +08:00
|
|
|
* - 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)
|
2008-11-27 00:41:34 +08:00
|
|
|
* - direction: bit 7 (0 = Host-to-Device [Out],
|
|
|
|
* (1 = Device-to-Host [In])
|
2002-03-09 05:31:05 +08:00
|
|
|
* - device: bits 8-14
|
|
|
|
* - endpoint: bits 15-18
|
|
|
|
* - Data0/1: bit 19
|
2008-11-27 00:41:34 +08:00
|
|
|
* - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt,
|
|
|
|
* 10 = control, 11 = bulk)
|
2002-03-09 05:31:05 +08:00
|
|
|
*
|
|
|
|
* 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) \
|
2010-05-27 01:26:43 +08:00
|
|
|
(((dev)->devnum << 8) | ((endpoint) << 15) | \
|
2012-11-06 21:48:20 +08:00
|
|
|
(dev)->maxpacketsize)
|
2008-11-28 20:19:19 +08:00
|
|
|
#define default_pipe(dev) ((dev)->speed << 26)
|
2008-11-27 00:41:34 +08:00
|
|
|
|
|
|
|
#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)
|
2002-03-09 05:31:05 +08:00
|
|
|
|
|
|
|
/* The D0/D1 toggle bits */
|
|
|
|
#define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
|
2004-04-24 04:32:05 +08:00
|
|
|
#define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep))
|
2008-11-27 00:41:34 +08:00
|
|
|
#define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = \
|
|
|
|
((dev)->toggle[out] & \
|
|
|
|
~(1 << ep)) | ((bit) << ep))
|
2002-03-09 05:31:05 +08:00
|
|
|
|
|
|
|
/* 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)))
|
|
|
|
|
2008-11-27 00:41:34 +08:00
|
|
|
#define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : \
|
|
|
|
USB_PID_OUT)
|
2002-03-09 05:31:05 +08:00
|
|
|
|
|
|
|
#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)
|
|
|
|
#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)
|
|
|
|
|
2013-09-14 16:32:45 +08:00
|
|
|
#define usb_pipe_ep_index(pipe) \
|
|
|
|
usb_pipecontrol(pipe) ? (usb_pipeendpoint(pipe) * 2) : \
|
|
|
|
((usb_pipeendpoint(pipe) * 2) - \
|
|
|
|
(usb_pipein(pipe) ? 0 : 1))
|
2002-03-09 05:31:05 +08:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* 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];
|
2008-11-27 00:41:34 +08:00
|
|
|
/* DeviceRemovable and PortPwrCtrlMask want to be variable-length
|
2002-03-09 05:31:05 +08:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2012-02-14 02:58:17 +08:00
|
|
|
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);
|
|
|
|
|
2012-09-26 06:14:34 +08:00
|
|
|
struct usb_device *usb_alloc_new_device(void *controller);
|
|
|
|
|
2012-02-14 02:58:17 +08:00
|
|
|
int usb_new_device(struct usb_device *dev);
|
2012-12-13 09:55:28 +08:00
|
|
|
void usb_free_device(void);
|
2013-09-14 16:32:45 +08:00
|
|
|
int usb_alloc_device(struct usb_device *dev);
|
2012-02-14 02:58:17 +08:00
|
|
|
|
2002-03-09 05:31:05 +08:00
|
|
|
#endif /*_USB_H_ */
|