dm: usb: Refactor port resets

Move the port reset code into its own function. Rename usb_hub_reset() to
indicate that is is now a legacy function.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
This commit is contained in:
Simon Glass 2015-03-25 12:22:04 -06:00
parent 53d8aa0f61
commit 862e75c0db
3 changed files with 45 additions and 17 deletions

View File

@ -877,6 +877,26 @@ __weak int usb_alloc_device(struct usb_device *udev)
{ {
return 0; return 0;
} }
int usb_legacy_port_reset(struct usb_device *hub, int portnr)
{
if (hub) {
unsigned short portstatus;
int err;
/* reset the port for the second time */
err = legacy_hub_port_reset(hub, portnr - 1, &portstatus);
if (err < 0) {
printf("\n Couldn't reset port %i\n", portnr);
return err;
}
} else {
usb_reset_root_port();
}
return 0;
}
/* /*
* By the time we get here, the device has gotten a new device ID * 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 * and is in the default state. We need to identify the thing and
@ -913,9 +933,6 @@ int usb_new_device(struct usb_device *dev)
* http://sourceforge.net/mailarchive/forum.php? * http://sourceforge.net/mailarchive/forum.php?
* thread_id=5729457&forum_id=5398 * thread_id=5729457&forum_id=5398
*/ */
__maybe_unused struct usb_device_descriptor *desc;
struct usb_device *parent = dev->parent;
unsigned short portstatus;
/* /*
* send 64-byte GET-DEVICE-DESCRIPTOR request. Since the descriptor is * send 64-byte GET-DEVICE-DESCRIPTOR request. Since the descriptor is
@ -923,7 +940,6 @@ int usb_new_device(struct usb_device *dev)
* the maxpacket size is 8 or 16 the device may be waiting to transmit * the maxpacket size is 8 or 16 the device may be waiting to transmit
* some more, or keeps on retransmitting the 8 byte header. */ * some more, or keeps on retransmitting the 8 byte header. */
desc = (struct usb_device_descriptor *)tmpbuf;
dev->descriptor.bMaxPacketSize0 = 64; /* Start off at 64 bytes */ dev->descriptor.bMaxPacketSize0 = 64; /* Start off at 64 bytes */
/* Default to 64 byte max packet size */ /* Default to 64 byte max packet size */
dev->maxpacketsize = PACKET_SIZE_64; dev->maxpacketsize = PACKET_SIZE_64;
@ -937,6 +953,9 @@ int usb_new_device(struct usb_device *dev)
* of that is done for XHCI unlike EHCI. * of that is done for XHCI unlike EHCI.
*/ */
#ifndef CONFIG_USB_XHCI #ifndef CONFIG_USB_XHCI
struct usb_device_descriptor *desc;
desc = (struct usb_device_descriptor *)tmpbuf;
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64); err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64);
/* /*
* Validate we've received only at least 8 bytes, not that we've * Validate we've received only at least 8 bytes, not that we've
@ -966,16 +985,9 @@ int usb_new_device(struct usb_device *dev)
dev->descriptor.bDeviceClass = desc->bDeviceClass; dev->descriptor.bDeviceClass = desc->bDeviceClass;
#endif #endif
if (parent) { err = usb_legacy_port_reset(dev->parent, dev->portnr);
/* reset the port for the second time */ if (err)
err = hub_port_reset(dev->parent, dev->portnr - 1, &portstatus); return err;
if (err < 0) {
printf("\n Couldn't reset port %i\n", dev->portnr);
return -EIO;
}
} else {
usb_reset_root_port();
}
dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0; dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0;
dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0; dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0;

View File

@ -149,7 +149,7 @@ static inline char *portspeed(int portstatus)
return speed_str; return speed_str;
} }
int hub_port_reset(struct usb_device *dev, int port, int legacy_hub_port_reset(struct usb_device *dev, int port,
unsigned short *portstat) unsigned short *portstat)
{ {
int tries; int tries;
@ -249,7 +249,7 @@ int usb_hub_port_connect_change(struct usb_device *dev, int port)
mdelay(200); mdelay(200);
/* Reset the port */ /* Reset the port */
ret = hub_port_reset(dev, port, &portstatus); ret = legacy_hub_port_reset(dev, port, &portstatus);
if (ret < 0) { if (ret < 0) {
printf("cannot reset port %i!?\n", port + 1); printf("cannot reset port %i!?\n", port + 1);
return ret; return ret;

View File

@ -700,9 +700,25 @@ bool usb_device_has_child_on_port(struct usb_device *parent, int port);
int usb_hub_probe(struct usb_device *dev, int ifnum); int usb_hub_probe(struct usb_device *dev, int ifnum);
void usb_hub_reset(void); void usb_hub_reset(void);
int hub_port_reset(struct usb_device *dev, int port,
/**
* legacy_hub_port_reset() - reset a port given its usb_device pointer
*
* Reset a hub port and see if a device is present on that port, providing
* sufficient time for it to show itself. The port status is returned.
*
* With driver model this moves to hub_port_reset() and is passed a struct
* udevice.
*
* @dev: USB device to reset
* @port: Port number to reset (note ports are numbered from 0 here)
* @portstat: Returns port status
*/
int legacy_hub_port_reset(struct usb_device *dev, int port,
unsigned short *portstat); unsigned short *portstat);
int hub_port_reset(struct udevice *dev, int port, unsigned short *portstat);
/** /**
* usb_alloc_new_device() - Allocate a new device * usb_alloc_new_device() - Allocate a new device
* *