Warning, cross-references for /kernel/include/drivers/usb/usb.h need to be fixed.
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
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
0070
0071
0072
0073
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
0088
0089
0090
0091
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
0115
0116
0117
0118
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
0136
0137
0138
0139
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
0157
0158
0159
0160
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
0179
0180
0181
0182
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
0198
0199
0200
0201
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
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
0249
0250
0251
0252
0253
0254
0255
0256