Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/drivers/usb/usb.h need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #ifndef _USB_H_
0019 #define _USB_H_
0020 
0021 #include <types.h>
0022 
0023 #define pci_config_rd8(bus, slot, func, reg) \
0024   pci_read_byte (pci_addr (bus, slot, func, reg))
0025 #define pci_config_wr8(bus, slot, func, reg, val) \
0026   pci_write_byte (pci_addr (bus, slot, func, reg), val)
0027 
0028 #define pci_config_rd16(bus, slot, func, reg) \
0029   pci_read_word (pci_addr (bus, slot, func, reg))
0030 #define pci_config_wr16(bus, slot, func, reg, val) \
0031   pci_write_word (pci_addr (bus, slot, func, reg), val)
0032 
0033 #define pci_config_rd32(bus, slot, func, reg) \
0034   pci_read_dword (pci_addr (bus, slot, func, reg))
0035 #define pci_config_wr32(bus, slot, func, reg, val) \
0036   pci_write_dword (pci_addr (bus, slot, func, reg), val)
0037 
0038 #define delay(x) sched_usleep (x*1000)
0039 
0040 #define USB_MAX_LEN       0x3FE
0041 #define USB_NULL_PACKET   0x7FF
0042 
0043 #define USB_GET_STATUS           0x00
0044 #define USB_CLEAR_FEATURE        0x01
0045 #define USB_SET_FEATURE          0x03
0046 #define USB_SET_ADDRESS          0x05
0047 #define USB_GET_DESCRIPTOR       0x06
0048 #define USB_SET_DESCRIPTOR       0x07
0049 #define USB_GET_CONFIGURATION    0x08
0050 #define USB_SET_CONFIGURATION    0x09
0051 #define USB_GET_INTERFACE        0x0A
0052 #define USB_SET_INTERFACE        0x0B
0053 #define USB_SYNCH_FRAME          0x0C
0054 
0055 #define USB_TYPE_DEV_DESC      0x01
0056 #define USB_TYPE_CFG_DESC      0x02
0057 #define USB_TYPE_STR_DESC      0x03
0058 #define USB_TYPE_IF_DESC       0x04
0059 #define USB_TYPE_EPT_DESC      0x05
0060 #define USB_TYPE_QUA_DESC      0x06
0061 #define USB_TYPE_SPD_CFG_DESC  0x07
0062 #define USB_TYPE_IF_PWR_DESC   0x08
0063 
0064 #define USB_TYPE_HC_UHCI    0x00
0065 #define USB_TYPE_HC_EHCI    0x01
0066 #define USB_TYPE_HC_OHCI    0x02
0067 
0068 /*
0069  * USB_DEV_REQ : USB Device Request
0070  *
0071  * Reference :
0072  *     Universal Serial Bus Specification
0073  *     Revision 1.1, Page 183
0074  */
0075 struct usb_dev_req
0076 {
0077   uint8_t bmRequestType;
0078   uint8_t bRequest;
0079   uint16_t wValue;
0080   uint16_t wIndex;
0081   uint16_t wLength;
0082 } PACKED;
0083 
0084 typedef struct usb_dev_req USB_DEV_REQ;
0085 
0086 /*
0087  * USB_DEV_DESC : Standard Device Descriptor
0088  *
0089  * Reference :
0090  *     Universal Serial Bus Specification
0091  *     Revision 1.1, Page 197
0092  */
0093 struct usb_dev_desc
0094 {
0095   uint8_t bLength;
0096   uint8_t bDescriptorType;
0097   uint16_t bcdUSB;
0098   uint8_t bDeviceClass;
0099   uint8_t bDeviceSubClass;
0100   uint8_t bDeviceProtocol;
0101   uint8_t bMaxPacketSize0;
0102   uint16_t idVendor;
0103   uint16_t idProduct;
0104   uint16_t bcdDevice;
0105   uint8_t iManufacturer;
0106   uint8_t iProduct;
0107   uint8_t iSerialNumber;
0108   uint8_t bNumConfigurations;
0109 } PACKED;
0110 
0111 typedef struct usb_dev_desc USB_DEV_DESC;
0112 
0113 /*
0114  * USB_CFG_DESC : Standard Configuration Descriptor
0115  *
0116  * Reference :
0117  *     Universal Serial Bus Specification
0118  *     Revision 1.1, Page 199
0119  */
0120 struct usb_cfg_desc
0121 {
0122   uint8_t bLength;
0123   uint8_t bDescriptorType;
0124   uint16_t wTotalLength;
0125   uint8_t bNumInterfaces;
0126   uint8_t bConfigurationValue;
0127   uint8_t iConfiguration;
0128   uint8_t bmAttributes;
0129   uint8_t MaxPower;
0130 } PACKED;
0131 
0132 typedef struct usb_cfg_desc USB_CFG_DESC;
0133 
0134 /*
0135  * USB_SPD_CFG_DESC : Other Speed Configuration Descriptor
0136  *
0137  * Reference :
0138  *     Universal Serial Bus Specification
0139  *     Revision 2.0, Page 267
0140  */
0141 struct usb_spd_cfg_desc
0142 {
0143   uint8_t bLength;
0144   uint8_t bDescriptorType;
0145   uint16_t wTotalLength;
0146   uint8_t bNumInterfaces;
0147   uint8_t bConfigurationValue;
0148   uint8_t iConfiguration;
0149   uint8_t bmAttributes;
0150   uint8_t bMaxPower;
0151 } PACKED;
0152 
0153 typedef struct usb_spd_cfg_desc USB_SPD_CFG_DESC;
0154 
0155 /*
0156  * USB_IF_DESC : Standard Interface Descriptor
0157  *
0158  * Reference :
0159  *     Universal Serial Bus Specification
0160  *     Revision 1.1, Page 202
0161  */
0162 struct usb_if_desc
0163 {
0164   uint8_t bLength;
0165   uint8_t bDescriptorType;
0166   uint8_t bInterfaceNumber;
0167   uint8_t bAlternateSetting;
0168   uint8_t bNumEndpoints;
0169   uint8_t bInterfaceClass;
0170   uint8_t bInterfaceSubClass;
0171   uint8_t bInterfaceProtocol;
0172   uint8_t iInterface;
0173 } PACKED;
0174 
0175 typedef struct usb_if_desc USB_IF_DESC;
0176 
0177 /*
0178  * USB_EPT_DESC : Standard Endpoint Descriptor
0179  *
0180  * Reference :
0181  *     Universal Serial Bus Specification
0182  *     Revision 1.1, Page 203
0183  */
0184 struct usb_ept_desc
0185 {
0186   uint8_t bLength;
0187   uint8_t bDescriptorType;
0188   uint8_t bEndpointAddress;
0189   uint8_t bmAttributes;
0190   uint16_t wMaxPacketSize;
0191   uint8_t bInterval;
0192 } PACKED;
0193 
0194 typedef struct usb_ept_desc USB_EPT_DESC;
0195 
0196 /* 
0197  * USB_STR_DESC: Standard String Descriptor
0198  *
0199  * Reference :
0200  *     Universal Serial Bus Specification
0201  *     Revision 1.1, Page 205
0202  */
0203 
0204 struct usb_str_desc
0205 {
0206   uint8_t bLength;
0207   uint8_t bDescriptorType;
0208   uint8_t bString[];
0209 } PACKED;
0210 
0211 typedef struct usb_str_desc USB_STR_DESC;
0212 
0213 /* ************************************************** */
0214 
0215 typedef struct
0216 {
0217   uint8 address;
0218   USB_DEV_DESC devd;
0219   uint8 host_type;
0220   uint8 *raw;
0221 } USB_DEVICE_INFO;
0222 
0223 typedef struct
0224 {
0225   bool (*probe) (USB_DEVICE_INFO *, USB_CFG_DESC *, USB_IF_DESC *);
0226 } USB_DRIVER;
0227 
0228 bool usb_register_driver (USB_DRIVER *);
0229 
0230 
0231 /* Generic USB operations */
0232 extern int usb_control_transfer(USB_DEVICE_INFO *, addr_t, uint16_t,
0233     addr_t, uint16_t);
0234 extern int usb_bulk_transfer(USB_DEVICE_INFO *, uint8_t, addr_t,
0235                              uint16_t, uint8_t, uint8_t, uint32_t *);
0236 
0237 extern int usb_get_descriptor(USB_DEVICE_INFO *, uint16_t, uint16_t,
0238     uint16_t, uint16_t, addr_t);
0239 extern int usb_set_address(USB_DEVICE_INFO *, uint8_t);
0240 extern int usb_get_configuration(USB_DEVICE_INFO *);
0241 extern int usb_set_configuration(USB_DEVICE_INFO *, uint8_t);
0242 extern int usb_get_interface(USB_DEVICE_INFO *, uint16_t);
0243 extern int usb_set_interface(USB_DEVICE_INFO *, uint16_t, uint16_t);
0244 
0245 #endif
0246 
0247 /*
0248  * Local Variables:
0249  * indent-tabs-mode: nil
0250  * mode: C
0251  * c-file-style: "gnu"
0252  * c-basic-offset: 2
0253  * End:
0254  */
0255 
0256 /* vi: set et sw=2 sts=2: */