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
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
#define DR_DESC gen_bmRequestType(device_to_host, standard_type, dev_recp)
|
|
|
|
|
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
|
|
|
{
|
2014-04-08 21:54:25 +02:00
|
|
|
hci_t *controller = xzalloc(sizeof (hci_t));
|
|
|
|
controller->next = usb_hcs;
|
|
|
|
usb_hcs = controller;
|
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;
|
2014-04-08 21:54:25 +02:00
|
|
|
|
|
|
|
usb_detach_device(controller, 0); /* tear down root hub tree */
|
|
|
|
|
2008-09-02 18:06:22 +02:00
|
|
|
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;
|
|
|
|
}
|
2012-06-20 01:57:18 +02:00
|
|
|
it = it->next;
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-04 12:06:06 +01:00
|
|
|
/**
|
|
|
|
* Shut down all controllers
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
usb_exit (void)
|
|
|
|
{
|
2013-03-24 19:40:02 +01:00
|
|
|
while (usb_hcs != NULL) {
|
|
|
|
usb_hcs->shutdown(usb_hcs);
|
2011-11-04 12:06:06 +01:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
usbdev_t *
|
2008-09-02 18:06:22 +02:00
|
|
|
init_device_entry (hci_t *controller, int i)
|
|
|
|
{
|
2013-09-18 07:16:04 +02:00
|
|
|
usbdev_t *dev = calloc(1, sizeof(usbdev_t));
|
|
|
|
if (!dev) {
|
|
|
|
usb_debug("no memory to allocate device structure\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-10-16 21:20:51 +02:00
|
|
|
if (controller->devices[i] != 0)
|
2012-11-01 23:44:10 +01:00
|
|
|
usb_debug("warning: device %d reassigned?\n", i);
|
2013-09-18 07:16:04 +02:00
|
|
|
controller->devices[i] = dev;
|
|
|
|
dev->controller = controller;
|
|
|
|
dev->address = -1;
|
|
|
|
dev->hub = -1;
|
|
|
|
dev->port = -1;
|
|
|
|
dev->init = usb_nop_init;
|
|
|
|
dev->init (controller->devices[i]);
|
|
|
|
return dev;
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
int
|
2008-09-02 18:06:22 +02:00
|
|
|
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;
|
2013-09-18 07:16:04 +02:00
|
|
|
|
|
|
|
return dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0);
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
int
|
2008-09-02 18:06:22 +02:00
|
|
|
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;
|
2013-09-18 07:16:04 +02:00
|
|
|
|
|
|
|
return dev->controller->control (dev, IN, sizeof (dr), &dr, len, data);
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
|
|
|
|
2015-09-24 23:45:10 +02:00
|
|
|
/*
|
|
|
|
* Certain Lexar / Micron USB 2.0 disks will fail the get_descriptor(DT_CFG)
|
|
|
|
* call due to timing issues. Work around this by making extra attempts on
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
#define GET_DESCRIPTOR_TRIES 3
|
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
int
|
2015-09-24 23:45:10 +02:00
|
|
|
get_descriptor(usbdev_t *dev, int rtype, int desc_type, int desc_idx,
|
2013-09-18 07:16:04 +02:00
|
|
|
void *data, size_t len)
|
2008-09-02 18:06:22 +02:00
|
|
|
{
|
|
|
|
dev_req_t dr;
|
2015-09-24 23:45:10 +02:00
|
|
|
int fail_tries = 0;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
while (fail_tries++ < GET_DESCRIPTOR_TRIES) {
|
|
|
|
dr.bmRequestType = rtype;
|
|
|
|
dr.bRequest = GET_DESCRIPTOR;
|
|
|
|
dr.wValue = desc_type << 8 | desc_idx;
|
|
|
|
dr.wIndex = 0;
|
|
|
|
dr.wLength = len;
|
|
|
|
|
|
|
|
ret = dev->controller->control(dev, IN,
|
|
|
|
sizeof(dr), &dr, len, data);
|
2018-02-10 11:57:28 +01:00
|
|
|
|
|
|
|
if (ret == len)
|
|
|
|
break;
|
|
|
|
udelay(10);
|
2015-09-24 23:45:10 +02:00
|
|
|
}
|
|
|
|
return ret;
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
int
|
2008-09-02 18:06:22 +02:00
|
|
|
set_configuration (usbdev_t *dev)
|
|
|
|
{
|
|
|
|
dev_req_t dr;
|
|
|
|
|
|
|
|
dr.bmRequestType = 0;
|
|
|
|
dr.bRequest = SET_CONFIGURATION;
|
2013-09-18 07:16:04 +02:00
|
|
|
dr.wValue = dev->configuration->bConfigurationValue;
|
2008-09-02 18:06:22 +02:00
|
|
|
dr.wIndex = 0;
|
|
|
|
dr.wLength = 0;
|
2013-09-18 07:16:04 +02:00
|
|
|
|
|
|
|
return dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0);
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-01 09:50:11 +02:00
|
|
|
int
|
2012-05-21 16:19:05 +02:00
|
|
|
clear_feature (usbdev_t *dev, int endp, int feature, int rtype)
|
2008-09-02 18:06:22 +02:00
|
|
|
{
|
|
|
|
dev_req_t dr;
|
|
|
|
|
2012-05-21 16:19:05 +02:00
|
|
|
dr.bmRequestType = rtype;
|
|
|
|
dr.data_dir = host_to_device;
|
2008-09-02 18:06:22 +02:00
|
|
|
dr.bRequest = CLEAR_FEATURE;
|
2012-05-21 16:19:05 +02:00
|
|
|
dr.wValue = feature;
|
2008-09-02 18:06:22 +02:00
|
|
|
dr.wIndex = endp;
|
|
|
|
dr.wLength = 0;
|
2013-09-18 07:16:04 +02:00
|
|
|
|
2013-02-21 22:41:40 +01:00
|
|
|
return dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0) < 0;
|
2012-05-21 16:19:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
clear_stall (endpoint_t *ep)
|
|
|
|
{
|
2013-09-18 07:16:04 +02:00
|
|
|
int ret = clear_feature (ep->dev, ep->endpoint, ENDPOINT_HALT,
|
|
|
|
gen_bmRequestType (host_to_device, standard_type, endp_recp));
|
2010-03-25 23:17:36 +01:00
|
|
|
ep->toggle = 0;
|
2012-06-01 09:50:11 +02:00
|
|
|
return ret;
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* returns free address or -1 */
|
|
|
|
static int
|
|
|
|
get_free_address (hci_t *controller)
|
|
|
|
{
|
libpayload: usb: Try to avoid reusing device addresses
We recently changed the USB stack to detach devices aggressively that we
don't intend to use. This alone is not really a problem, but it
exarcerbates the fact that our device detachment itself is not very
good. We destroy any local info about the device, but we don't properly
disable the offending port. The device keeps thinking that it's active,
and if we later try to reuse that device address for another device
things become confused.
The real fix would be to properly disable all ports that we don't intend
to use. Unfortunately, this isn't really possible in our current
device/hub polymorphism structure, and I don't want to hack a new
disable_port() callback into usbdev_t that really doesn't belong there.
We will only be able to fix this cleanly after we ported all root hubs
to the generic_hub interface.
Until then, an easy workaround is to just avoid reusing addresses as
long as possible. This is firmware, so the chance that we'll ever run
through 127 devices is really small in practice. Even if we ever fix the
underlying issue, it's probably a smart precaution to keep.
BRANCH=nyan,rambi
BUG=chrome-os-partner:28328
TEST=Boot from a hub that has an "unknown" device in an earlier port
than the stick you want to boot from, make sure you can still boot.
Original-Change-Id: I9b522dd8cbcd441e8c3b8781fcecd2effa0f23ee
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/197420
Original-Reviewed-by: Shawn Nematbakhsh <shawnn@chromium.org>
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
(cherry picked from commit 28b48aa69b55a983226edf2ea616f33cd4b959e2)
Signed-off-by: Marc Jones <marc.jones@se-eng.com>
Change-Id: Id4c5c92e75d6b5a7e8f0ee3e396c69c4efd13176
Reviewed-on: http://review.coreboot.org/7881
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-04-29 01:04:24 +02:00
|
|
|
int i = controller->latest_address + 1;
|
|
|
|
for (; i != controller->latest_address; i++) {
|
|
|
|
if (i >= ARRAY_SIZE(controller->devices) || i < 1) {
|
|
|
|
usb_debug("WARNING: Device addresses for controller %#x"
|
|
|
|
" wrapped around!\n", controller->reg_base);
|
|
|
|
i = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (controller->devices[i] == 0) {
|
|
|
|
controller->latest_address = i;
|
2008-09-02 18:06:22 +02:00
|
|
|
return i;
|
libpayload: usb: Try to avoid reusing device addresses
We recently changed the USB stack to detach devices aggressively that we
don't intend to use. This alone is not really a problem, but it
exarcerbates the fact that our device detachment itself is not very
good. We destroy any local info about the device, but we don't properly
disable the offending port. The device keeps thinking that it's active,
and if we later try to reuse that device address for another device
things become confused.
The real fix would be to properly disable all ports that we don't intend
to use. Unfortunately, this isn't really possible in our current
device/hub polymorphism structure, and I don't want to hack a new
disable_port() callback into usbdev_t that really doesn't belong there.
We will only be able to fix this cleanly after we ported all root hubs
to the generic_hub interface.
Until then, an easy workaround is to just avoid reusing addresses as
long as possible. This is firmware, so the chance that we'll ever run
through 127 devices is really small in practice. Even if we ever fix the
underlying issue, it's probably a smart precaution to keep.
BRANCH=nyan,rambi
BUG=chrome-os-partner:28328
TEST=Boot from a hub that has an "unknown" device in an earlier port
than the stick you want to boot from, make sure you can still boot.
Original-Change-Id: I9b522dd8cbcd441e8c3b8781fcecd2effa0f23ee
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/197420
Original-Reviewed-by: Shawn Nematbakhsh <shawnn@chromium.org>
Original-Reviewed-by: David Hendricks <dhendrix@chromium.org>
(cherry picked from commit 28b48aa69b55a983226edf2ea616f33cd4b959e2)
Signed-off-by: Marc Jones <marc.jones@se-eng.com>
Change-Id: Id4c5c92e75d6b5a7e8f0ee3e396c69c4efd13176
Reviewed-on: http://review.coreboot.org/7881
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2014-04-29 01:04:24 +02:00
|
|
|
}
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
2012-11-01 23:44:10 +01:00
|
|
|
usb_debug ("no free address found\n");
|
2008-09-02 18:06:22 +02:00
|
|
|
return -1; // no free address
|
|
|
|
}
|
|
|
|
|
2013-05-24 15:48:56 +02:00
|
|
|
int
|
2013-09-25 05:03:54 +02:00
|
|
|
usb_decode_mps0(usb_speed speed, u8 bMaxPacketSize0)
|
2008-09-02 18:06:22 +02:00
|
|
|
{
|
2013-09-25 05:03:54 +02:00
|
|
|
switch (speed) {
|
|
|
|
case LOW_SPEED:
|
|
|
|
if (bMaxPacketSize0 != 8) {
|
|
|
|
usb_debug("Invalid MPS0: 0x%02x\n", bMaxPacketSize0);
|
|
|
|
bMaxPacketSize0 = 8;
|
|
|
|
}
|
|
|
|
return bMaxPacketSize0;
|
|
|
|
case FULL_SPEED:
|
|
|
|
switch (bMaxPacketSize0) {
|
|
|
|
case 8: case 16: case 32: case 64:
|
|
|
|
return bMaxPacketSize0;
|
|
|
|
default:
|
|
|
|
usb_debug("Invalid MPS0: 0x%02x\n", bMaxPacketSize0);
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
case HIGH_SPEED:
|
|
|
|
if (bMaxPacketSize0 != 64) {
|
|
|
|
usb_debug("Invalid MPS0: 0x%02x\n", bMaxPacketSize0);
|
|
|
|
bMaxPacketSize0 = 64;
|
|
|
|
}
|
|
|
|
return bMaxPacketSize0;
|
|
|
|
case SUPER_SPEED:
|
|
|
|
if (bMaxPacketSize0 != 9) {
|
|
|
|
usb_debug("Invalid MPS0: 0x%02x\n", bMaxPacketSize0);
|
|
|
|
bMaxPacketSize0 = 9;
|
|
|
|
}
|
2015-05-07 09:28:19 +02:00
|
|
|
return 1 << bMaxPacketSize0;
|
2013-09-25 05:03:54 +02:00
|
|
|
default: /* GCC is stupid and cannot deal with enums correctly */
|
|
|
|
return 8;
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
2013-05-24 15:48:56 +02:00
|
|
|
}
|
|
|
|
|
2016-03-17 10:13:35 +01:00
|
|
|
int speed_to_default_mps(usb_speed speed)
|
|
|
|
{
|
|
|
|
switch (speed) {
|
|
|
|
case LOW_SPEED:
|
|
|
|
return 8;
|
|
|
|
case FULL_SPEED:
|
|
|
|
case HIGH_SPEED:
|
|
|
|
return 64;
|
|
|
|
case SUPER_SPEED:
|
|
|
|
default:
|
|
|
|
return 512;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-06 10:20:35 +02:00
|
|
|
/* Normalize bInterval to log2 of microframes */
|
|
|
|
static int
|
2013-09-25 05:03:54 +02:00
|
|
|
usb_decode_interval(usb_speed speed, const endpoint_type type, const unsigned char bInterval)
|
2013-06-06 10:20:35 +02:00
|
|
|
{
|
|
|
|
#define LOG2(a) ((sizeof(unsigned) << 3) - __builtin_clz(a) - 1)
|
|
|
|
switch (speed) {
|
|
|
|
case LOW_SPEED:
|
|
|
|
switch (type) {
|
|
|
|
case ISOCHRONOUS: case INTERRUPT:
|
|
|
|
return LOG2(bInterval) + 3;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case FULL_SPEED:
|
|
|
|
switch (type) {
|
|
|
|
case ISOCHRONOUS:
|
|
|
|
return (bInterval - 1) + 3;
|
|
|
|
case INTERRUPT:
|
|
|
|
return LOG2(bInterval) + 3;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case HIGH_SPEED:
|
|
|
|
switch (type) {
|
|
|
|
case ISOCHRONOUS: case INTERRUPT:
|
|
|
|
return bInterval - 1;
|
|
|
|
default:
|
|
|
|
return LOG2(bInterval);
|
|
|
|
}
|
|
|
|
case SUPER_SPEED:
|
|
|
|
switch (type) {
|
|
|
|
case ISOCHRONOUS: case INTERRUPT:
|
|
|
|
return bInterval - 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#undef LOG2
|
|
|
|
}
|
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
usbdev_t *
|
2013-09-25 05:03:54 +02:00
|
|
|
generic_set_address (hci_t *controller, usb_speed speed,
|
|
|
|
int hubport, int hubaddr)
|
|
|
|
{
|
|
|
|
int adr = get_free_address (controller); // address to set
|
2017-01-04 22:22:56 +01:00
|
|
|
if (adr < 0)
|
|
|
|
return NULL;
|
2013-09-25 05:03:54 +02:00
|
|
|
dev_req_t dr;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
usbdev_t *dev = init_device_entry(controller, adr);
|
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
|
2013-09-25 05:03:54 +02:00
|
|
|
// dummy values for registering the address
|
|
|
|
dev->address = 0;
|
|
|
|
dev->hub = hubaddr;
|
|
|
|
dev->port = hubport;
|
|
|
|
dev->speed = speed;
|
|
|
|
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;
|
2013-09-18 07:16:04 +02:00
|
|
|
dev->endpoints[0].type = CONTROL;
|
2013-09-25 05:03:54 +02:00
|
|
|
if (dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0) < 0) {
|
|
|
|
usb_debug ("set_address failed\n");
|
2013-09-18 07:16:04 +02:00
|
|
|
usb_detach_device (controller, adr);
|
|
|
|
return NULL;
|
2013-09-25 05:03:54 +02:00
|
|
|
}
|
|
|
|
mdelay (SET_ADDRESS_MDELAY);
|
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
u8 buf[8];
|
|
|
|
dev->address = adr;
|
|
|
|
if (get_descriptor (dev, DR_DESC, DT_DEV, 0, buf, sizeof(buf))
|
|
|
|
!= sizeof(buf)) {
|
|
|
|
usb_debug("first get_descriptor(DT_DEV) failed\n");
|
|
|
|
usb_detach_device (controller, adr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
dev->endpoints[0].maxpacketsize = usb_decode_mps0(speed, buf[7]);
|
|
|
|
|
|
|
|
return dev;
|
2013-09-25 05:03:54 +02:00
|
|
|
}
|
|
|
|
|
2013-05-24 15:48:56 +02:00
|
|
|
static int
|
2013-09-25 05:03:54 +02:00
|
|
|
set_address (hci_t *controller, usb_speed speed, int hubport, int hubaddr)
|
2013-05-24 15:48:56 +02:00
|
|
|
{
|
2013-09-18 07:16:04 +02:00
|
|
|
usbdev_t *dev = controller->set_address(controller, speed,
|
|
|
|
hubport, hubaddr);
|
|
|
|
if (!dev) {
|
2013-05-24 15:48:56 +02:00
|
|
|
usb_debug ("set_address failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
dev->descriptor = malloc(sizeof(*dev->descriptor));
|
|
|
|
if (!dev->descriptor || get_descriptor (dev, DR_DESC, DT_DEV, 0,
|
|
|
|
dev->descriptor, sizeof(*dev->descriptor))
|
|
|
|
!= sizeof(*dev->descriptor)) {
|
|
|
|
usb_debug ("get_descriptor(DT_DEV) failed\n");
|
|
|
|
usb_detach_device (controller, dev->address);
|
|
|
|
return -1;
|
|
|
|
}
|
2010-03-25 23:17:36 +01:00
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
usb_debug ("* found device (0x%04x:0x%04x, USB %x.%x, MPS0: %d)\n",
|
|
|
|
dev->descriptor->idVendor, dev->descriptor->idProduct,
|
|
|
|
dev->descriptor->bcdUSB >> 8, dev->descriptor->bcdUSB & 0xff,
|
|
|
|
dev->endpoints[0].maxpacketsize);
|
|
|
|
dev->quirks = usb_quirk_check(dev->descriptor->idVendor,
|
|
|
|
dev->descriptor->idProduct);
|
2010-03-25 23:17:36 +01:00
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
usb_debug ("device has %d configurations\n",
|
|
|
|
dev->descriptor->bNumConfigurations);
|
|
|
|
if (dev->descriptor->bNumConfigurations == 0) {
|
2008-09-02 18:06:22 +02:00
|
|
|
/* device isn't usable */
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug ("... no usable configuration!\n");
|
2013-09-18 07:16:04 +02:00
|
|
|
usb_detach_device (controller, dev->address);
|
2008-09-02 18:06:22 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2010-03-25 23:17:36 +01:00
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
u16 buf[2];
|
|
|
|
if (get_descriptor (dev, DR_DESC, DT_CFG, 0, buf, sizeof(buf))
|
|
|
|
!= sizeof(buf)) {
|
|
|
|
usb_debug ("first get_descriptor(DT_CFG) failed\n");
|
|
|
|
usb_detach_device (controller, dev->address);
|
|
|
|
return -1;
|
|
|
|
}
|
2014-11-10 16:50:21 +01:00
|
|
|
/* workaround for some USB devices: wait until they're ready, or
|
|
|
|
* they send a NAK when they're not allowed to do. 1ms is enough */
|
|
|
|
mdelay(1);
|
2013-09-18 07:16:04 +02:00
|
|
|
dev->configuration = malloc(buf[1]);
|
|
|
|
if (!dev->configuration) {
|
|
|
|
usb_debug ("could not allocate %d bytes for DT_CFG\n", buf[1]);
|
|
|
|
usb_detach_device (controller, dev->address);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (get_descriptor (dev, DR_DESC, DT_CFG, 0, dev->configuration,
|
|
|
|
buf[1]) != buf[1]) {
|
|
|
|
usb_debug ("get_descriptor(DT_CFG) failed\n");
|
|
|
|
usb_detach_device (controller, dev->address);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
configuration_descriptor_t *cd = dev->configuration;
|
|
|
|
if (cd->wTotalLength != buf[1]) {
|
|
|
|
usb_debug ("configuration descriptor size changed, aborting\n");
|
|
|
|
usb_detach_device (controller, dev->address);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the device is not well known (ifnum == -1), we use the first
|
|
|
|
* interface we encounter, 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 set it yourself.
|
|
|
|
*/
|
|
|
|
usb_debug ("device has %x interfaces\n", cd->bNumInterfaces);
|
|
|
|
int ifnum = usb_interface_check(dev->descriptor->idVendor,
|
|
|
|
dev->descriptor->idProduct);
|
|
|
|
if (cd->bNumInterfaces > 1 && ifnum < 0)
|
|
|
|
usb_debug ("NOTICE: Your device has multiple interfaces and\n"
|
|
|
|
"this driver will only use the first one. That may\n"
|
|
|
|
"be the wrong choice and cause the device to not\n"
|
|
|
|
"work correctly. Please report this case\n"
|
|
|
|
"(including the above debugging output) to\n"
|
|
|
|
"coreboot@coreboot.org to have the device added to\n"
|
|
|
|
"the list of well-known quirks.\n");
|
|
|
|
|
|
|
|
u8 *end = (void *)dev->configuration + cd->wTotalLength;
|
|
|
|
interface_descriptor_t *intf;
|
|
|
|
u8 *ptr;
|
|
|
|
|
|
|
|
/* Find our interface (or the first good one if we don't know) */
|
|
|
|
for (ptr = (void *)dev->configuration + sizeof(*cd); ; ptr += ptr[0]) {
|
|
|
|
if (ptr + 2 > end || !ptr[0] || ptr + ptr[0] > end) {
|
|
|
|
usb_debug ("Couldn't find usable DT_INTF\n");
|
|
|
|
usb_detach_device (controller, dev->address);
|
|
|
|
return -1;
|
2010-03-25 23:17:36 +01:00
|
|
|
}
|
2013-09-18 07:16:04 +02:00
|
|
|
if (ptr[1] != DT_INTF)
|
|
|
|
continue;
|
|
|
|
intf = (void *)ptr;
|
|
|
|
if (intf->bLength != sizeof(*intf)) {
|
|
|
|
usb_debug ("Skipping broken DT_INTF\n");
|
|
|
|
continue;
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
2013-09-18 07:16:04 +02:00
|
|
|
if (ifnum >= 0 && intf->bInterfaceNumber != ifnum)
|
|
|
|
continue;
|
|
|
|
usb_debug ("Interface %d: class 0x%x, sub 0x%x. proto 0x%x\n",
|
|
|
|
intf->bInterfaceNumber, intf->bInterfaceClass,
|
|
|
|
intf->bInterfaceSubClass, intf->bInterfaceProtocol);
|
|
|
|
ptr += sizeof(*intf);
|
|
|
|
break;
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
2010-03-25 23:17:36 +01:00
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
/* Gather up all endpoints belonging to this inteface */
|
|
|
|
dev->num_endp = 1;
|
|
|
|
for (; ptr + 2 <= end && ptr[0] && ptr + ptr[0] <= end; ptr += ptr[0]) {
|
|
|
|
if (ptr[1] == DT_INTF || ptr[1] == DT_CFG ||
|
|
|
|
dev->num_endp >= ARRAY_SIZE(dev->endpoints))
|
|
|
|
break;
|
|
|
|
if (ptr[1] != DT_ENDP)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
endpoint_descriptor_t *desc = (void *)ptr;
|
|
|
|
static const char *transfertypes[4] = {
|
|
|
|
"control", "isochronous", "bulk", "interrupt"
|
|
|
|
};
|
|
|
|
usb_debug (" #Endpoint %d (%s), max packet size %x, type %s\n",
|
|
|
|
desc->bEndpointAddress & 0x7f,
|
|
|
|
(desc->bEndpointAddress & 0x80) ? "in" : "out",
|
|
|
|
desc->wMaxPacketSize,
|
|
|
|
transfertypes[desc->bmAttributes & 0x3]);
|
|
|
|
|
|
|
|
endpoint_t *ep = &dev->endpoints[dev->num_endp++];
|
|
|
|
ep->dev = dev;
|
|
|
|
ep->endpoint = desc->bEndpointAddress;
|
|
|
|
ep->toggle = 0;
|
|
|
|
ep->maxpacketsize = desc->wMaxPacketSize;
|
|
|
|
ep->direction = (desc->bEndpointAddress & 0x80) ? IN : OUT;
|
|
|
|
ep->type = desc->bmAttributes & 0x3;
|
|
|
|
ep->interval = usb_decode_interval (dev->speed, ep->type,
|
|
|
|
desc->bInterval);
|
|
|
|
}
|
2013-05-24 15:48:56 +02:00
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
if ((controller->finish_device_config &&
|
|
|
|
controller->finish_device_config(dev)) ||
|
|
|
|
set_configuration(dev) < 0) {
|
|
|
|
usb_debug ("Could not finalize device configuration\n");
|
|
|
|
usb_detach_device (controller, dev->address);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-05-24 15:48:56 +02:00
|
|
|
|
2013-09-18 07:16:04 +02:00
|
|
|
int class = dev->descriptor->bDeviceClass;
|
2008-09-02 18:06:22 +02:00
|
|
|
if (class == 0)
|
2013-09-18 07:16:04 +02:00
|
|
|
class = intf->bInterfaceClass;
|
2008-09-02 18:06:22 +02:00
|
|
|
|
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,
|
|
|
|
};
|
2013-09-18 07:16:04 +02:00
|
|
|
usb_debug("Class: ");
|
2010-03-25 23:17:36 +01:00
|
|
|
switch (class) {
|
|
|
|
case audio_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("audio\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case comm_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("communication\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case hid_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug ("HID\n");
|
2019-03-06 01:55:15 +01:00
|
|
|
#if CONFIG(LP_USB_HID)
|
2013-09-18 07:16:04 +02:00
|
|
|
dev->init = usb_hid_init;
|
|
|
|
return dev->address;
|
2008-09-02 18:06:22 +02:00
|
|
|
#else
|
2012-11-01 23:44:10 +01:00
|
|
|
usb_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:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("physical\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case imaging_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("camera\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case printer_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("printer\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case msc_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug ("MSC\n");
|
2019-03-06 01:55:15 +01:00
|
|
|
#if CONFIG(LP_USB_MSC)
|
2013-09-18 07:16:04 +02:00
|
|
|
dev->init = usb_msc_init;
|
|
|
|
return dev->address;
|
2008-09-02 18:06:22 +02:00
|
|
|
#else
|
2012-11-01 23:44:10 +01:00
|
|
|
usb_debug ("NOTICE: USB MSC support not compiled in\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case hub_device:
|
2015-07-10 01:29:10 +02:00
|
|
|
usb_debug ("hub\n");
|
2019-03-06 01:55:15 +01:00
|
|
|
#if CONFIG(LP_USB_HUB)
|
2015-07-10 01:29:10 +02:00
|
|
|
dev->init = usb_hub_init;
|
|
|
|
return dev->address;
|
2010-03-25 23:17:36 +01:00
|
|
|
#else
|
2015-07-10 01:29:10 +02:00
|
|
|
usb_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:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("CDC\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case ccid_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("smartcard / CCID\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case security_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("content security\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case video_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("video\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case healthcare_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("healthcare\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case diagnostic_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("diagnostic\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
case wireless_device:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("wireless\n");
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
|
|
|
default:
|
2012-12-11 21:08:07 +01:00
|
|
|
usb_debug("unsupported class %x\n", class);
|
2010-03-25 23:17:36 +01:00
|
|
|
break;
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
2013-09-18 07:16:04 +02:00
|
|
|
dev->init = usb_generic_init;
|
|
|
|
return dev->address;
|
2008-09-02 18:06:22 +02:00
|
|
|
}
|
2008-10-16 21:20:51 +02:00
|
|
|
|
2012-06-01 09:50:11 +02:00
|
|
|
/*
|
|
|
|
* Should be called by the hub drivers whenever a physical detach occurs
|
|
|
|
* and can be called by usb class drivers if they are unsatisfied with a
|
|
|
|
* malfunctioning device.
|
|
|
|
*/
|
2008-10-16 21:20:51 +02:00
|
|
|
void
|
|
|
|
usb_detach_device(hci_t *controller, int devno)
|
|
|
|
{
|
2012-06-01 09:50:11 +02:00
|
|
|
/* check if device exists, as we may have
|
|
|
|
been called yet by the usb class driver */
|
|
|
|
if (controller->devices[devno]) {
|
|
|
|
controller->devices[devno]->destroy (controller->devices[devno]);
|
2018-02-10 12:03:58 +01:00
|
|
|
|
2013-09-25 05:03:54 +02:00
|
|
|
if (controller->destroy_device)
|
|
|
|
controller->destroy_device(controller, devno);
|
2018-02-10 12:03:58 +01:00
|
|
|
|
|
|
|
free(controller->devices[devno]->descriptor);
|
|
|
|
controller->devices[devno]->descriptor = NULL;
|
|
|
|
free(controller->devices[devno]->configuration);
|
|
|
|
controller->devices[devno]->configuration = NULL;
|
|
|
|
|
2015-08-01 00:08:00 +02:00
|
|
|
/* Tear down the device itself *after* destroy_device()
|
|
|
|
* has had a chance to interoogate it. */
|
|
|
|
free(controller->devices[devno]);
|
|
|
|
controller->devices[devno] = NULL;
|
2012-06-01 09:50:11 +02:00
|
|
|
}
|
2008-10-16 21:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-09-25 05:03:54 +02:00
|
|
|
usb_attach_device(hci_t *controller, int hubaddress, int port, usb_speed speed)
|
2008-10-16 21:20:51 +02:00
|
|
|
{
|
2013-09-25 05:03:54 +02:00
|
|
|
static const char* speeds[] = { "full", "low", "high", "super" };
|
|
|
|
usb_debug ("%sspeed device\n", (speed < sizeof(speeds) / sizeof(char*))
|
|
|
|
? speeds[speed] : "invalid value - no");
|
2012-05-23 09:21:54 +02:00
|
|
|
int newdev = set_address (controller, speed, port, hubaddress);
|
2008-10-16 21:20:51 +02:00
|
|
|
if (newdev == -1)
|
|
|
|
return -1;
|
|
|
|
usbdev_t *newdev_t = controller->devices[newdev];
|
|
|
|
// determine responsible driver - current done in set_address
|
|
|
|
newdev_t->init (newdev_t);
|
2012-06-21 11:21:23 +02:00
|
|
|
/* init() may have called usb_detach_device() yet, so check */
|
|
|
|
return controller->devices[newdev] ? newdev : -1;
|
2008-10-16 21:20:51 +02:00
|
|
|
}
|
2009-07-31 13:39:55 +02:00
|
|
|
|
libpayload: Add usb_generic_(create|remove) functions for unrecognized devices
It might be useful to provide a USB driver in the payload itself instead of in
libpayload. For example there are multiple payloads being built and linked
against the same libpayload, and they might not need or even want to have the
same set of drivers installed.
This change adds two new functions, usb_generic_create and usb_generic_remove,
which behave like the usbdisk_create and usbdisk_remove functions which are
defined for USB mass storage devices. If a USB device isn't recognized and
claimed by one of the built in USB class drivers (currently hub, hid, and msc)
and the create function is defined, then it will be called to give the payload
a chance to use the device. Once it's removed, if usb_generic_remove is
defined it will be called, effectively giving the payload notice.
Built and booted depthcharge on Link. Built depthcharge for Daisy. Built
a netbooting payload, called usb_poll() with those functions implemented, and
verified that they were called and that the devices they were told about were
reasonable and the same as what was reported by lsusb in the booted system.
Change-Id: Ief7c0a513b60849fbf2986ef4ae5c9e7825fef16
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: http://review.coreboot.org/2666
Tested-by: build bot (Jenkins)
Reviewed-by: Kimarie Hoot <kimarie.hoot@se-eng.com>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2013-02-02 05:19:27 +01:00
|
|
|
static void
|
|
|
|
usb_generic_destroy (usbdev_t *dev)
|
|
|
|
{
|
|
|
|
if (usb_generic_remove)
|
|
|
|
usb_generic_remove(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usb_generic_init (usbdev_t *dev)
|
|
|
|
{
|
|
|
|
dev->data = NULL;
|
|
|
|
dev->destroy = usb_generic_destroy;
|
|
|
|
|
|
|
|
if (usb_generic_create)
|
|
|
|
usb_generic_create(dev);
|
2014-04-16 06:34:30 +02:00
|
|
|
|
|
|
|
if (dev->data == NULL) {
|
|
|
|
usb_debug("Detaching device not used by payload\n");
|
|
|
|
usb_detach_device(dev->controller, dev->address);
|
|
|
|
}
|
libpayload: Add usb_generic_(create|remove) functions for unrecognized devices
It might be useful to provide a USB driver in the payload itself instead of in
libpayload. For example there are multiple payloads being built and linked
against the same libpayload, and they might not need or even want to have the
same set of drivers installed.
This change adds two new functions, usb_generic_create and usb_generic_remove,
which behave like the usbdisk_create and usbdisk_remove functions which are
defined for USB mass storage devices. If a USB device isn't recognized and
claimed by one of the built in USB class drivers (currently hub, hid, and msc)
and the create function is defined, then it will be called to give the payload
a chance to use the device. Once it's removed, if usb_generic_remove is
defined it will be called, effectively giving the payload notice.
Built and booted depthcharge on Link. Built depthcharge for Daisy. Built
a netbooting payload, called usb_poll() with those functions implemented, and
verified that they were called and that the devices they were told about were
reasonable and the same as what was reported by lsusb in the booted system.
Change-Id: Ief7c0a513b60849fbf2986ef4ae5c9e7825fef16
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: http://review.coreboot.org/2666
Tested-by: build bot (Jenkins)
Reviewed-by: Kimarie Hoot <kimarie.hoot@se-eng.com>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2013-02-02 05:19:27 +01:00
|
|
|
}
|
2015-07-02 09:28:11 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* returns the address of the closest USB2.0 hub, which is responsible for
|
|
|
|
* split transactions, along with the number of the used downstream port
|
|
|
|
*/
|
|
|
|
int closest_usb2_hub(const usbdev_t *dev, int *const addr, int *const port)
|
|
|
|
{
|
|
|
|
const usbdev_t *usb1dev;
|
|
|
|
|
|
|
|
do {
|
|
|
|
usb1dev = dev;
|
|
|
|
if ((dev->hub >= 0) && (dev->hub < 128))
|
|
|
|
dev = dev->controller->devices[dev->hub];
|
|
|
|
else
|
|
|
|
dev = NULL;
|
|
|
|
} while (dev && (dev->speed < 2));
|
|
|
|
|
|
|
|
if (dev) {
|
|
|
|
*addr = usb1dev->hub;
|
|
|
|
*port = usb1dev->port;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
usb_debug("Couldn't find closest USB2.0 hub.\n");
|
|
|
|
return 1;
|
|
|
|
}
|