Newer
Older
default:
printf("usb_new_device: invalid max packet size\n");
return -EIO;
return 0;
}
static int usb_prepare_device(struct usb_device *dev, int addr, bool do_read,
struct usb_device *parent, int portnr)
/*
* Allocate usb 3.0 device context.
* USB 3.0 (xHCI) protocol tries to allocate device slot
* and related data structures first. This call does that.
* Refer to sec 4.3.2 in xHCI spec rev1.0
*/
err = usb_alloc_device(dev);
if (err) {
printf("Cannot allocate device context to get SLOT_ID\n");
}
err = usb_setup_descriptor(dev, do_read);
if (err)
return err;
err = usb_legacy_port_reset(parent, portnr);
if (err)
return err;
dev->devnum = addr;
err = usb_set_address(dev); /* set address */
if (err < 0) {
printf("\n USB device not accepting new address " \
"(error=%lX)\n", dev->status);
mdelay(10); /* Let the SET_ADDRESS settle */
int usb_select_config(struct usb_device *dev)
{
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, tmpbuf, USB_BUFSIZ);
err = get_descriptor_len(dev, USB_DT_DEVICE_SIZE, USB_DT_DEVICE_SIZE);
if (err)
return err;
le16_to_cpus(&dev->descriptor.bcdUSB);
le16_to_cpus(&dev->descriptor.idVendor);
le16_to_cpus(&dev->descriptor.idProduct);
le16_to_cpus(&dev->descriptor.bcdDevice);
err = usb_get_configuration_no(dev, tmpbuf, 0);
if (err < 0) {
printf("usb_new_device: Cannot read configuration, " \
"skipping device %04x:%04x\n",
dev->descriptor.idVendor, dev->descriptor.idProduct);
/*
* we set the default configuration here
* This seems premature. If the driver wants a different configuration
* it will need to select itself.
*/
err = usb_set_configuration(dev, dev->config.desc.bConfigurationValue);
if (err < 0) {
printf("failed to set default configuration " \
"len %d, status %lX\n", dev->act_len, dev->status);
debug("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\n",
dev->descriptor.iManufacturer, dev->descriptor.iProduct,
dev->descriptor.iSerialNumber);
memset(dev->mf, 0, sizeof(dev->mf));
memset(dev->prod, 0, sizeof(dev->prod));
memset(dev->serial, 0, sizeof(dev->serial));
if (dev->descriptor.iManufacturer)
usb_string(dev, dev->descriptor.iManufacturer,
dev->mf, sizeof(dev->mf));
usb_string(dev, dev->descriptor.iProduct,
dev->prod, sizeof(dev->prod));
usb_string(dev, dev->descriptor.iSerialNumber,
dev->serial, sizeof(dev->serial));
debug("Manufacturer %s\n", dev->mf);
debug("Product %s\n", dev->prod);
debug("SerialNumber %s\n", dev->serial);
return 0;
}
int usb_setup_device(struct usb_device *dev, bool do_read,
struct usb_device *parent, int portnr)
{
int addr;
int ret;
/* We still haven't set the Address yet */
addr = dev->devnum;
dev->devnum = 0;
ret = usb_prepare_device(dev, addr, do_read, parent, portnr);
if (ret)
return ret;
ret = usb_select_config(dev);
return ret;
}
#ifndef CONFIG_DM_USB
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
/*
* By the time we get here, the device has gotten a new device ID
* and is in the default state. We need to identify the thing and
* get the ball rolling..
*
* Returns 0 for success, != 0 for error.
*/
int usb_new_device(struct usb_device *dev)
{
bool do_read = true;
int err;
/*
* XHCI needs to issue a Address device command to setup
* proper device context structures, before it can interact
* with the device. So a get_descriptor will fail before any
* of that is done for XHCI unlike EHCI.
*/
#ifdef CONFIG_USB_XHCI
do_read = false;
#endif
err = usb_setup_device(dev, do_read, dev->parent, dev->portnr);
if (err)
return err;
/* Now probe if the device is a hub */
err = usb_hub_probe(dev, 0);
if (err < 0)
return err;
int board_usb_init(int index, enum usb_init_type init)
__weak
int board_usb_cleanup(int index, enum usb_init_type init)
{
return 0;
}
bool usb_device_has_child_on_port(struct usb_device *parent, int port)
{
#ifdef CONFIG_DM_USB
return false;
#else
return parent->children[port] != NULL;
#endif
}