1 /*****************************************************************************
2 * Copyright (c) 2013 IBM Corporation
4 * This program and the accompanying materials
5 * are made available under the terms of the BSD License
6 * which accompanies this distribution, and is available at
7 * http://www.opensource.org/licenses/bsd-license.php
10 * IBM Corporation - initial implementation
11 *****************************************************************************/
34 struct usb_hcd_ops *ops;
35 void *priv; /* hcd owned structure */
36 long nextaddr; /* address for devices */
41 /*******************************************/
42 /* Standard Endpoint Descriptor */
43 /*******************************************/
45 #define USB_EP_TYPE_MASK 0x03
46 #define USB_EP_TYPE_CONTROL 0
47 #define USB_EP_TYPE_ISOC 1
48 #define USB_EP_TYPE_BULK 2
49 #define USB_EP_TYPE_INTR 3
52 uint8_t bLength; /* size of descriptor */
53 uint8_t bDescriptorType; /* Type = 5 */
54 uint8_t bEndpointAddress;
56 uint16_t wMaxPacketSize;
58 } __attribute__((packed));
60 #define DEV_HID_KEYB 0x030101 /* class=HIB, protocol=Keyboard */
61 #define DEV_HID_MOUSE 0x030102 /* class=HIB, protocol=Mouse */
62 #define DEV_HUB 0x090000 /* class=HUB, subclass, protocol */
63 #define DEV_MASS_RBC 0x080150 /* MassStorage, RBC, Bulk */
64 #define DEV_CDROM_ATAPI 0x080250 /* MassStorage, SFF-8020i , Bulk */
65 #define DEV_MASS_FLOPPY 0x080450 /* MassStorage, UFI, Bulk */
66 #define DEV_MASS_ATAPI 0x080550 /* MassStorage, SFF-8070i , Bulk */
67 #define DEV_MASS_SCSI 0x080650 /* MassStorage, SCSI, Bulk */
76 /* Max number of endpoints supported in a device */
77 #define USB_DEV_EP_MAX 4
78 #define USB_TIMEOUT 5000 /* 5 sec usb timeout */
82 struct usb_hcd_dev *hcidev;
83 struct usb_pipe *intr;
84 struct usb_pipe *control;
85 struct usb_pipe *bulk_in;
86 struct usb_pipe *bulk_out;
87 struct usb_ep_descr ep[USB_DEV_EP_MAX];
98 #define DEVICE_KEYBOARD 1
99 #define DEVICE_MOUSE 2
100 #define DEVICE_DISK 3
103 /* Structure in sync with FORTH code */
104 struct slof_usb_dev {
111 } __attribute__((packed));
120 struct usb_pipe *next;
126 } __attribute__((packed));
128 #define REQ_GET_STATUS 0 /* see Table 9-4 */
129 #define REQ_CLEAR_FEATURE 1
130 #define REQ_GET_STATE 2 /* HUB specific */
131 #define REQ_SET_FEATURE 3
132 #define REQ_SET_ADDRESS 5
133 #define REQ_GET_DESCRIPTOR 6
134 #define REQ_SET_DESCRIPTOR 7
135 #define REQ_GET_CONFIGURATION 8
136 #define REQ_SET_CONFIGURATION 9
137 #define REQ_GET_INTERFACE 10
138 #define REQ_SET_INTERFACE 11
139 #define REQ_SYNCH_FRAME 12
141 #define FEATURE_DEVICE_REMOTE_WAKEUP 1
142 #define FEATURE_ENDPOINT_HALT 0
144 #define REQT_REC_DEVICE 0
145 #define REQT_REC_INTERFACE 1
146 #define REQT_REC_EP 2
147 #define REQT_REC_OTHER 3
148 #define REQT_TYPE_STANDARD (0 << 5)
149 #define REQT_TYPE_CLASS (1 << 5)
150 #define REQT_TYPE_VENDOR (2 << 5)
151 #define REQT_TYPE_RSRVD (3 << 5)
152 #define REQT_DIR_OUT (0 << 7) /* host -> device */
153 #define REQT_DIR_IN (1 << 7) /* device -> host */
155 #define DESCR_TYPE_DEVICE 1 /* see Table 9-5 */
156 #define DESCR_TYPE_CONFIGURATION 2
157 #define DESCR_TYPE_STRING 3
158 #define DESCR_TYPE_INTERFACE 4
159 #define DESCR_TYPE_ENDPOINT 5
160 #define DESCR_TYPE_HUB 0x29 /* Class Descriptor HUB */
161 #define DESCR_TYPE_HID 0x21 /* Class Descriptor HID */
162 #define DESCR_TYPE_REPORT 0x22 /* Class Descriptor HID */
163 #define DESCR_TYPE_PHYSICAL 0x23 /* Class Descriptor HID */
166 uint8_t bmRequestType; /* direction, recipient */
167 uint8_t bRequest; /* see spec: Table 9-3 */
170 uint16_t wLength; /* number of bytes to transfer */
171 } __attribute__((packed));
173 /* Standard Device Descriptor (18 Bytes) */
174 /*******************************************/
175 struct usb_dev_descr {
177 uint8_t bDescriptorType;
179 uint8_t bDeviceClass;
180 uint8_t bDeviceSubClass;
181 uint8_t bDeviceProtocol;
182 uint8_t bMaxPacketSize0;
186 uint8_t iManufacturer;
188 uint8_t iSerialNumber;
189 uint8_t bNumConfigurations;
190 } __attribute__((packed));
192 /*******************************************/
193 /* Standard Configuration Descriptor */
194 /*******************************************/
195 struct usb_dev_config_descr {
196 uint8_t bLength; /* size of descriptor */
197 uint8_t bDescriptorType; /* Type = 2 */
198 uint16_t wTotalLength; /* total returned data */
199 uint8_t bNumInterfaces; /* interfaces supported by this config */
200 uint8_t bConfigurationValue; /* Configuration-ID for SetConfiguration */
201 uint8_t iConfiguration; /* index of string descriptor */
202 uint8_t bmAttributes; /* configuration characteristics */
203 uint8_t bMaxPower; /* in 2mA units */
204 } __attribute__((packed));
206 /*******************************************/
207 /* Standard Interface Descriptor */
208 /*******************************************/
209 struct usb_dev_intf_descr {
210 uint8_t bLength; /* size of descriptor */
211 uint8_t bDescriptorType; /* Type = 4 */
212 uint8_t bInterfaceNumber;
213 uint8_t bAlternateSetting;
214 uint8_t bNumEndpoints;
215 uint8_t bInterfaceClass;
216 uint8_t bInterfaceSubClass;
217 uint8_t bInterfaceProtocol; /* protocol code */
218 uint8_t iInterface; /* index to string descriptor */
219 } __attribute__((packed));
221 /*******************************************/
222 /* HUB-Class Descriptor */
223 /*******************************************/
224 struct usb_dev_hub_descr {
225 uint8_t bLength; /* size of complete descriptor */
226 uint8_t bDescriptorType; /* type = 0x29 for HUB */
227 uint8_t bNbrPorts; /* number of downstream ports */
228 uint8_t wHubCharacteristics; /* mode bits 7..0 */
229 uint8_t reserved; /* mode bits 15..8 */
230 uint8_t bPwrOn2PwrGood; /* in 2ms units */
231 uint8_t bHubContrCurrent; /* current requirement in mA */
232 uint8_t DeviceTable; /* length depends on number of ports */
233 } __attribute__((packed));
235 /*******************************************/
236 /* HID-Class Descriptor */
237 /*******************************************/
238 struct usb_dev_hid_descr {
239 uint8_t bLength; /* size of this descriptor */
240 uint8_t bDescriptorType; /* type = 0x21 for HID */
241 uint16_t bcdHID; /* Sample: 0x0102 for 2.01 */
242 uint8_t bCountryCode; /* Hardware target country */
243 uint8_t bNumDescriptors; /* Number of HID class descr. */
244 uint8_t bReportType; /* Report Descriptor Type */
245 uint16_t wReportLength; /* Total Length of Report Descr. */
246 } __attribute__((packed));
250 void (*init)(struct usb_hcd_dev *);
251 void (*exit)(struct usb_hcd_dev *);
252 void (*detect)(void);
253 void (*disconnect)(void);
254 int (*send_ctrl)(struct usb_pipe *pipe, struct usb_dev_req *req, void *data);
255 struct usb_pipe* (*get_pipe)(struct usb_dev *dev, struct usb_ep_descr *ep,
256 char *buf, size_t len);
257 int (*transfer_bulk)(struct usb_pipe *pipe, void *td, void *td_phys, void *data, int size);
258 void (*put_pipe)(struct usb_pipe *);
259 int (*poll_intr)(struct usb_pipe *, uint8_t *);
260 struct usb_hcd_ops *next;
261 unsigned int usb_type;
264 extern void usb_hcd_register(struct usb_hcd_ops *ops);
265 extern struct usb_pipe *usb_get_pipe(struct usb_dev *dev, struct usb_ep_descr *ep,
266 char *buf, size_t len);
267 extern void usb_put_pipe(struct usb_pipe *pipe);
268 extern int usb_poll_intr(struct usb_pipe *pipe, uint8_t *buf);
269 extern int usb_send_ctrl(struct usb_pipe *pipe, struct usb_dev_req *req, void *data);
270 extern struct usb_dev *usb_devpool_get(void);
271 extern void usb_devpool_put(struct usb_dev *);
272 extern int setup_new_device(struct usb_dev *dev, unsigned int port);
273 extern int slof_usb_handle(struct usb_dev *dev);
274 extern int usb_dev_populate_pipe(struct usb_dev *dev, struct usb_ep_descr *ep,
275 void *buf, size_t len);
276 extern int usb_hid_kbd_init(struct usb_dev *dev);
277 extern int usb_hid_kbd_exit(struct usb_dev *dev);
278 extern void usb_msc_resetrecovery(struct usb_dev *dev);