2008-09-02 18:06:22 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the libpayload project.
|
|
|
|
*
|
2010-03-25 23:17:36 +01:00
|
|
|
* Copyright (C) 2008-2010 coresystems GmbH
|
2008-09-02 18:06:22 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2010-03-25 23:17:36 +01:00
|
|
|
//#define USB_DEBUG
|
|
|
|
|
2008-11-24 18:54:46 +01:00
|
|
|
#include <libpayload-config.h>
|
2008-09-11 19:29:00 +02:00
|
|
|
#include <usb/usb.h>
|
2008-09-02 18:06:22 +02:00
|
|
|
|
|
|
|
hci_t *usb_hcs = 0;
|
|
|
|
|
|
|
|
hci_t *
|
2009-07-31 13:39:55 +02:00
|
|
|
new_controller (void)
|
2008-09-02 18:06:22 +02:00
|
|
|
{
|
|
|
|
hci_t *controller = malloc (sizeof (hci_t));
|
|
|
|
|
2009-07-31 13:39:55 +02:00
|
|
|
if (controller) {
|
|
|
|
/* atomic */
|
|
|
|
controller->next = usb_hcs;
|
|
|
|
usb_hcs = controller;
|
|
|
|
/* atomic end */
|
|
|
|
}
|
2008-09-02 18:06:22 +02:00
|
|
|
|
|
|
|
return controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
detach_controller (hci_t *controller)
|
|
|
|
{
|
2009-07-31 13:39:55 +02:00
|
|
|
if (controller == NULL)
|
2008-09-02 18:06:22 +02:00
|
|
|
return;
|
|
|
|
if (usb_hcs == controller) {
|
|
|
|
usb_hcs = controller->next;
|
|
|
|
} else {
|
|
|
|
hci_t *it = usb_hcs;
|
2009-07-31 13:39:55 +02:00
|
|
|
while (it != NULL) {
|
2008-09-02 18:06:22 +02:00
|
|
|
if (it->next == controller) {
|
|
|
|
it->next = controller->next;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-04 12:06:06 +01:00
|
|
|
/**
|
|
|
|
* Shut down all controllers
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
usb_exit (void)
|
|
|
|
{
|
|
|
|
if (usb_hcs == 0)
|
|
|
|
return 0;
|
|
|
|
hci_t *controller = usb_hcs;
|
2011-11-18 11:56:38 +01:00
|
|
|
while (controller != NULL) {
|
2011-11-04 12:06:06 +01:00
|
|
|
controller->shutdown(controller);
|
|
|
|
controller = controller->next;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-02 18:06:22 +02:00
|
|
|
/**
|
|
|
|
* Polls all hubs on all USB controllers, to find out about device changes
|
|
|
|
*/
|
|
|
|
void
|
2010-03-25 23:17:36 +01:00
|
|
|
usb_poll (void)
|
2008-09-02 18:06:22 +02:00
|
|
|
{
|
|
|
|
if (usb_hcs == 0)
|
|
|
|
return;
|
|
|
|
hci_t *controller = usb_hcs;
|
2011-11-18 11:56:38 +01:00
|
|
|
while (controller != NULL) {
|
2008-09-02 18:06:22 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < 128; i++) {
|
2008-10-16 21:20:51 +02:00
|
|
|
if (controller->devices[i] != 0) {
|
2010-03-25 23:17:36 +01:00
|
|
|
controller->devices[i]->poll (controller->devices[i]);
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
controller = controller->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
init_device_entry (hci_t *controller, int i)
|
|
|
|
{
|
2008-10-16 21:20:51 +02:00
|
|
|
if (controller->devices[i] != 0)
|
2011-06-08 15:36:55 +02:00
|
|
|
debug("warning: device %d reassigned?\n", i);
|
2008-10-16 21:20:51 +02:00
|
|
|
controller->devices[i] = malloc(sizeof(usbdev_t));
|
|
|
|
controller->devices[i]->controller = controller;
|
|
|
|
controller->devices[i]->address = -1;
|
|
|
|
controller->devices[i]->hub = -1;
|
|
|
|
controller->devices[i]->port = -1;
|
|
|
|
controller->devices[i]->init = usb_nop_init;
|
|
|
|
controller->devices[i]->init (controller->devices[i]);
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
set_feature (usbdev_t *dev, int endp, int feature, int rtype)
|
|
|
|
{
|
|
|
|
dev_req_t dr;
|
|
|
|
|
|
|
|
dr.bmRequestType = rtype;
|
|
|
|
dr.data_dir = host_to_device;
|
|
|
|
dr.bRequest = SET_FEATURE;
|
|
|
|
dr.wValue = feature;
|
|
|
|
dr.wIndex = endp;
|
|
|
|
dr.wLength = 0;
|
|
|
|
dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
get_status (usbdev_t *dev, int intf, int rtype, int len, void *data)
|
|
|
|
{
|
|
|
|
dev_req_t dr;
|
|
|
|
|
|
|
|
dr.bmRequestType = rtype;
|
|
|
|
dr.data_dir = device_to_host;
|
|
|
|
dr.bRequest = GET_STATUS;
|
|
|
|
dr.wValue = 0;
|
|
|
|
dr.wIndex = intf;
|
|
|
|
dr.wLength = len;
|
|
|
|
dev->controller->control (dev, IN, sizeof (dr), &dr, len, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 *
|
|
|
|
get_descriptor (usbdev_t *dev, unsigned char bmRequestType, int descType,
|
|
|
|
int descIdx, int langID)
|
|
|
|
{
|
|
|
|
u8 buf[8];
|
|
|
|
u8 *result;
|
|
|
|
dev_req_t dr;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
dr.bmRequestType = bmRequestType;
|
|
|
|
dr.data_dir = device_to_host; // always like this for descriptors
|
|
|
|
dr.bRequest = GET_DESCRIPTOR;
|
|
|
|
dr.wValue = (descType << 8) | descIdx;
|
|
|
|
dr.wIndex = langID;
|
|
|
|
dr.wLength = 8;
|
|
|
|
if (dev->controller->control (dev, IN, sizeof (dr), &dr, 8, buf)) {
|
2011-06-08 15:36:55 +02:00
|
|
|
debug ("getting descriptor size (type %x) failed\n",
|
2008-09-02 18:06:22 +02:00
|
|
|
descType);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (descType == 1) {
|
|
|
|
device_descriptor_t *dd = (device_descriptor_t *) buf;
|
2010-03-25 23:17:36 +01:00
|
|
|
debug ("maxPacketSize0: %x\n", dd->bMaxPacketSize0);
|
2008-09-02 18:06:22 +02:00
|
|
|
if (dd->bMaxPacketSize0 != 0)
|
|
|
|
dev->endpoints[0].maxpacketsize = dd->bMaxPacketSize0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* special case for configuration descriptors: they carry all their
|
|
|
|
subsequent descriptors with them, and keep the entire size at a
|
|
|
|
different location */
|
|
|
|
size = buf[0];
|
|
|
|
if (buf[1] == 2) {
|
|
|
|
int realsize = ((unsigned short *) (buf + 2))[0];
|
|
|
|
size = realsize;
|
|
|
|
}
|
|
|
|
result = malloc (size);
|
|
|
|
memset (result, 0, size);
|
|
|
|
dr.wLength = size;
|
|
|
|
if (dev->controller->
|
|
|
|
control (dev, IN, sizeof (dr), &dr, size, result)) {
|
2011-06-08 15:36:55 +02:00
|
|
|
debug ("getting descriptor (type %x, size %x) failed\n",
|
2008-09-02 18:06:22 +02:00
|
|
|
descType, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
set_configuration (usbdev_t *dev)
|
|
|
|
{
|
|
|
|
dev_req_t dr;
|
|
|
|
|
|
|
|
dr.bmRequestType = 0;
|
|
|
|
dr.bRequest = SET_CONFIGURATION;
|
|
|
|
dr.wValue = dev->configuration[5];
|
|
|
|
dr.wIndex = 0;
|
|
|
|
dr.wLength = 0;
|
|
|
|
dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
clear_stall (endpoint_t *ep)
|
|
|
|
{
|
|
|
|
usbdev_t *dev = ep->dev;
|
|
|
|
int endp = ep->endpoint;
|
|
|
|
dev_req_t dr;
|
|
|
|
|
|
|
|
dr.bmRequestType = 0;
|
|
|
|
if (endp != 0) {
|
|
|
|
dr.req_recp = endp_recp;
|
|
|
|
}
|
|
|
|
dr.bRequest = CLEAR_FEATURE;
|
|
|
|
dr.wValue = ENDPOINT_HALT;
|
|
|
|
dr.wIndex = endp;
|
|
|
|
dr.wLength = 0;
|
|
|
|
dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0);
|
2010-03-25 23:17:36 +01:00
|
|
|
ep->toggle = 0;
|
2008-09-02 18:06:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns free address or -1 */
|
|
|
|
static int
|
|
|
|
get_free_address (hci_t *controller)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < 128; i++) {
|
2008-10-16 21:20:51 +02:00
|
|
|
if (controller->devices[i] == 0)
|
2008-09-02 18:06:22 +02:00
|
|
|
return i;
|
|
|
|
}
|
2011-06-08 15:36:55 +02:00
|
|
|
debug ("no free address found\n");
|
2008-09-02 18:06:22 +02:00
|
|
|
return -1; // no free address
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-03-25 23:17:36 +01:00
|
|
|
set_address (hci_t *controller, int speed)
|
2008-09-02 18:06:22 +02:00
|
|
|
{
|
|
|
|
int adr = get_free_address (controller); // address to set
|
|
|
|
dev_req_t dr;
|
|
|
|
configuration_descriptor_t *cd;
|
|
|
|
device_descriptor_t *dd;
|
|
|
|
|
|
|
|
memset (&dr, 0, sizeof (dr));
|
|
|
|
dr.data_dir = host_to_device;
|
|
|
|
dr.req_type = standard_type;
|
|
|
|
dr.req_recp = dev_recp;
|
|
|
|
dr.bRequest = SET_ADDRESS;
|
|
|
|
dr.wValue = adr;
|
|
|
|
dr.wIndex = 0;
|
|
|
|
dr.wLength = 0;
|
|
|
|
|
2008-10-16 21:20:51 +02:00
|
|
|
init_device_entry(controller, adr);
|
|
|
|
usbdev_t *dev = controller->devices[adr];
|
2008-09-02 18:06:22 +02:00
|
|
|
// dummy values for registering the address
|
|
|
|
dev->address = 0;
|
2010-03-25 23:17:36 +01:00
|
|
|
dev->speed = speed;
|
2008-09-02 18:06:22 +02:00
|
|
|
dev->endpoints[0].dev = dev;
|
|
|
|
dev->endpoints[0].endpoint = 0;
|
|
|
|
dev->endpoints[0].maxpacketsize = 8;
|
|
|
|
dev->endpoints[0].toggle = 0;
|
|
|
|
dev->endpoints[0].direction = SETUP;
|
|
|
|
mdelay (50);
|
|
|
|
if (dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0)) {
|
2011-06-08 15:36:55 +02:00
|
|
|
debug ("set_address failed\n");
|
2008-09-02 18:06:22 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
mdelay (50);
|
|
|
|
dev->address = adr;
|
2010-04-27 08:56:47 +02:00
|
|
|
dev->descriptor = get_descriptor (dev, gen_bmRequestType
|
2010-03-25 23:17:36 +01:00
|
|
|
(device_to_host, standard_type, dev_recp), 1, 0, 0);
|
2008-09-02 18:06:22 +02:00
|
|
|
dd = (device_descriptor_t *) dev->descriptor;
|
2010-03-25 23:17:36 +01:00
|
|
|
|
2011-06-08 15:36:55 +02:00
|
|
|
printf ("* found device (0x%04x:0x%04x, USB %x.%x)",
|
2010-04-27 08:56:47 +02:00
|
|
|
dd->idVendor, dd->idProduct,
|
2010-03-25 23:17:36 +01:00
|
|
|
dd->bcdUSB >> 8, dd->bcdUSB & 0xff);
|
|
|
|
dev->quirks = usb_quirk_check(dd->idVendor, dd->idProduct);
|
|
|
|
|
|
|
|
debug ("\ndevice has %x configurations\n", dd->bNumConfigurations);
|
2008-09-02 18:06:22 +02:00
|
|
|
if (dd->bNumConfigurations == 0) {
|
|
|
|
/* device isn't usable */
|
2010-03-25 23:17:36 +01:00
|
|
|
printf ("... no usable configuration!\n");
|
2008-09-02 18:06:22 +02:00
|
|
|
dev->address = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
2010-03-25 23:17:36 +01:00
|
|
|
|
|
|
|
dev->configuration = get_descriptor (dev, gen_bmRequestType
|
|
|
|
(device_to_host, standard_type, dev_recp), 2, 0, 0);
|
2008-09-02 18:06:22 +02:00
|
|
|
cd = (configuration_descriptor_t *) dev->configuration;
|
|
|
|
set_configuration (dev);
|
|
|
|
interface_descriptor_t *interface =
|
|
|
|
(interface_descriptor_t *) (((char *) cd) + cd->bLength);
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int num = cd->bNumInterfaces;
|
|
|
|
interface_descriptor_t *current = interface;
|
2010-03-25 23:17:36 +01:00
|
|
|
debug ("device has %x interfaces\n", num);
|
|
|
|
if (num > 1) {
|
|
|
|
int interfaces = usb_interface_check(dd->idVendor, dd->idProduct);
|
|
|
|
if (interfaces) {
|
|
|
|
/* Well known device, don't warn */
|
|
|
|
num = interfaces;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
printf ("\nNOTICE: This driver defaults to using the first interface.\n"
|
|
|
|
"This might be the wrong choice and lead to limited functionality\n"
|
|
|
|
"of the device. Please report such a case to coreboot@coreboot.org\n"
|
|
|
|
"as you might be the first.\n");
|
|
|
|
/* we limit to the first interface, as there was no need to
|
|
|
|
* implement something else for the time being. If you need
|
|
|
|
* it, see the SetInterface and GetInterface functions in
|
|
|
|
* the USB specification, and adapt appropriately.
|
|
|
|
*/
|
|
|
|
num = (num > 1) ? 1 : num;
|
|
|
|
}
|
|
|
|
}
|
2008-09-02 18:06:22 +02:00
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
int j;
|
2010-03-25 23:17:36 +01:00
|
|
|
debug (" #%x has %x endpoints, interface %x:%x, protocol %x\n",
|
|
|
|
current->bInterfaceNumber, current->bNumEndpoints, current->bInterfaceClass, current->bInterfaceSubClass, current->bInterfaceProtocol);
|
2008-09-02 18:06:22 +02:00
|
|
|
endpoint_descriptor_t *endp =
|
|
|
|
(endpoint_descriptor_t *) (((char *) current)
|
2010-03-25 23:17:36 +01:00
|
|
|
+ current->bLength);
|
2008-09-02 18:06:22 +02:00
|
|
|
if (interface->bInterfaceClass == 0x3)
|
|
|
|
endp = (endpoint_descriptor_t *) (((char *) endp) + ((char *) endp)[0]); // ignore HID descriptor
|
|
|
|
memset (dev->endpoints, 0, sizeof (dev->endpoints));
|
|
|
|
dev->num_endp = 1; // 0 always exists
|
|
|
|
dev->endpoints[0].dev = dev;
|
|
|
|
dev->endpoints[0].maxpacketsize = dd->bMaxPacketSize0;
|
|
|
|
dev->endpoints[0].direction = SETUP;
|
|
|
|
dev->endpoints[0].type = CONTROL;
|
|
|
|
for (j = 1; j <= current->bNumEndpoints; j++) {
|
2010-03-25 23:17:36 +01:00
|
|
|
#ifdef USB_DEBUG
|
|
|
|
static const char *transfertypes[4] = {
|
|
|
|
"control", "isochronous", "bulk", "interrupt"
|
2008-09-02 18:06:22 +02:00
|
|
|
};
|
2010-03-25 23:17:36 +01:00
|
|
|
debug (" #%x: Endpoint %x (%s), max packet size %x, type %s\n", j, endp->bEndpointAddress & 0x7f, ((endp->bEndpointAddress & 0x80) != 0) ? "in" : "out", endp->wMaxPacketSize, transfertypes[endp->bmAttributes]);
|
|
|
|
#endif
|
2008-09-02 18:06:22 +02:00
|
|
|
endpoint_t *ep =
|
|
|
|
&dev->endpoints[dev->num_endp++];
|
|
|
|
ep->dev = dev;
|
|
|
|
ep->endpoint = endp->bEndpointAddress;
|
|
|
|
ep->toggle = 0;
|
|
|
|
ep->maxpacketsize = endp->wMaxPacketSize;
|
|
|
|
ep->direction =
|
|
|
|
((endp->bEndpointAddress & 0x80) ==
|
|
|
|
0) ? OUT : IN;
|
|
|
|
ep->type = endp->bmAttributes;
|
|
|
|
endp = (endpoint_descriptor_t
|
|
|
|
*) (((char *) endp) + endp->bLength);
|
|
|
|
}
|
|
|
|
current = (interface_descriptor_t *) endp;
|
|
|
|
}
|
|
|
|
}
|
2010-03-25 23:17:36 +01:00
|
|
|
|
2008-09-02 18:06:22 +02:00
|
|
|
int class = dd->bDeviceClass;
|
|
|
|
if (class == 0)
|
|
|
|
class = interface->bInterfaceClass;
|
|
|
|
|
2010-03-25 23:17:36 +01:00
|
|
|
enum {
|
|
|
|
audio_device = 0x01,
|
|
|
|
comm_device = 0x02,
|
|
|
|
hid_device = 0x03,
|
|
|
|
physical_device = 0x05,
|
|
|
|
imaging_device = 0x06,
|
|
|
|
printer_device = 0x07,
|
|
|
|
msc_device = 0x08,
|
|
|
|
hub_device = 0x09,
|
|
|
|
cdc_device = 0x0a,
|
|
|
|
ccid_device = 0x0b,
|
|
|
|
security_device = 0x0d,
|
|
|
|
video_device = 0x0e,
|
|
|
|
healthcare_device = 0x0f,
|
|
|
|
diagnostic_device = 0xdc,
|
|
|
|
wireless_device = 0xe0,
|
|
|
|
misc_device = 0xef,
|
|
|
|
};
|
2011-06-08 15:36:55 +02:00
|
|
|
printf(", class: ");
|
2010-03-25 23:17:36 +01:00
|
|
|
switch (class) {
|
|
|
|
case audio_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("audio\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case comm_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("communication\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case hid_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf ("HID\n");
|
2008-09-02 18:06:22 +02:00
|
|
|
#ifdef CONFIG_USB_HID
|
2008-10-16 21:20:51 +02:00
|
|
|
controller->devices[adr]->init = usb_hid_init;
|
2008-09-02 18:06:22 +02:00
|
|
|
#else
|
2011-06-08 15:36:55 +02:00
|
|
|
debug ("NOTICE: USB HID support not compiled in\n");
|
2008-09-02 18:06:22 +02:00
|
|
|
#endif
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case physical_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("physical\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case imaging_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("camera\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case printer_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("printer\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case msc_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf ("MSC\n");
|
2008-09-02 18:06:22 +02:00
|
|
|
#ifdef CONFIG_USB_MSC
|
2008-10-16 21:20:51 +02:00
|
|
|
controller->devices[adr]->init = usb_msc_init;
|
2008-09-02 18:06:22 +02:00
|
|
|
#else
|
2011-06-08 15:36:55 +02:00
|
|
|
debug ("NOTICE: USB MSC support not compiled in\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case hub_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf ("hub\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
#ifdef CONFIG_USB_HUB
|
|
|
|
controller->devices[adr]->init = usb_hub_init;
|
|
|
|
#else
|
2011-06-08 15:36:55 +02:00
|
|
|
debug ("NOTICE: USB hub support not compiled in.\n");
|
2008-09-02 18:06:22 +02:00
|
|
|
#endif
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case cdc_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("CDC\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case ccid_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("smartcard / CCID\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case security_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("content security\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case video_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("video\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case healthcare_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("healthcare\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case diagnostic_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("diagnostic\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case wireless_device:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("wireless\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
default:
|
2011-06-08 15:36:55 +02:00
|
|
|
printf("unsupported class %x\n", class);
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
|
|
|
return adr;
|
|
|
|
}
|
2008-10-16 21:20:51 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
usb_detach_device(hci_t *controller, int devno)
|
|
|
|
{
|
|
|
|
controller->devices[devno]->destroy (controller->devices[devno]);
|
|
|
|
free(controller->devices[devno]);
|
|
|
|
controller->devices[devno] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-03-25 23:17:36 +01:00
|
|
|
usb_attach_device(hci_t *controller, int hubaddress, int port, int speed)
|
2008-10-16 21:20:51 +02:00
|
|
|
{
|
2010-03-25 23:17:36 +01:00
|
|
|
static const char* speeds[] = { "full", "low", "high" };
|
2011-06-08 15:36:55 +02:00
|
|
|
debug ("%sspeed device\n", (speed <= 2) ? speeds[speed] : "invalid value - no");
|
2010-03-25 23:17:36 +01:00
|
|
|
int newdev = set_address (controller, speed);
|
2008-10-16 21:20:51 +02:00
|
|
|
if (newdev == -1)
|
|
|
|
return -1;
|
|
|
|
usbdev_t *newdev_t = controller->devices[newdev];
|
|
|
|
|
|
|
|
newdev_t->address = newdev;
|
|
|
|
newdev_t->hub = hubaddress;
|
|
|
|
newdev_t->port = port;
|
|
|
|
// determine responsible driver - current done in set_address
|
|
|
|
newdev_t->init (newdev_t);
|
|
|
|
return newdev;
|
|
|
|
}
|
2009-07-31 13:39:55 +02:00
|
|
|
|