From a4aff629f384f33eda62b84cf7cd66d7862c6ced Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Wed, 19 Jul 2017 21:51:09 +0800 Subject: [PATCH] usb: hub: Use 'struct usb_hub_device' as hub device's uclass_priv Use USB hub device's dev->uclass_priv to point to 'usb_hub_device' so that with driver model usb_hub_reset() and usb_hub_allocate() are no longer needed. Signed-off-by: Bin Meng Reviewed-by: Simon Glass (cherry picked from commit dfa96e06761e223288e59d7a3e1d574f014b5a0d) Signed-off-by: Santan Kumar Conflicts: common/usb_hub.c Change-Id: I7a46a12c62aa7429ef2241c9543dd877abe6ac0b --- common/usb_hub.c | 27 ++++++++++++++++++++++----- drivers/usb/host/usb-uclass.c | 2 -- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/common/usb_hub.c b/common/usb_hub.c index 0eb8f15631..fa9fb4dbe0 100644 --- a/common/usb_hub.c +++ b/common/usb_hub.c @@ -46,9 +46,6 @@ DECLARE_GLOBAL_DATA_PTR; #define USB_BUFSIZ 512 -/* TODO(sjg@chromium.org): Remove this when CONFIG_DM_USB is defined */ -static struct usb_hub_device hub_dev[USB_MAX_HUB]; -static int usb_hub_index; __weak void usb_hub_reset_devices(int port) { @@ -140,6 +137,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub) mdelay(pgood_delay + 1000); } +#ifndef CONFIG_DM_USB +static struct usb_hub_device hub_dev[USB_MAX_HUB]; +static int usb_hub_index; + void usb_hub_reset(void) { usb_hub_index = 0; @@ -153,6 +154,7 @@ static struct usb_hub_device *usb_hub_allocate(void) printf("ERROR: USB_MAX_HUB (%d) reached\n", USB_MAX_HUB); return NULL; } +#endif #define MAX_TRIES 5 @@ -351,6 +353,20 @@ int usb_hub_port_connect_change(struct usb_device *dev, int port) } +static struct usb_hub_device *usb_get_hub_device(struct usb_device *dev) +{ + struct usb_hub_device *hub; + +#ifndef CONFIG_DM_USB + /* "allocate" Hub device */ + hub = usb_hub_allocate(); +#else + hub = dev_get_uclass_priv(dev->dev); +#endif + + return hub; +} + static int usb_hub_configure(struct usb_device *dev) { int i, length; @@ -362,11 +378,11 @@ static int usb_hub_configure(struct usb_device *dev) __maybe_unused struct usb_hub_status *hubsts; int ret; - /* "allocate" Hub device */ - hub = usb_hub_allocate(); + hub = usb_get_hub_device(dev); if (hub == NULL) return -ENOMEM; hub->pusb_dev = dev; + /* Get the the hub descriptor */ ret = usb_get_hub_descriptor(dev, buffer, 4); if (ret < 0) { @@ -677,6 +693,7 @@ UCLASS_DRIVER(usb_hub) = { .child_pre_probe = usb_child_pre_probe, .per_child_auto_alloc_size = sizeof(struct usb_device), .per_child_platdata_auto_alloc_size = sizeof(struct usb_dev_platdata), + .per_device_auto_alloc_size = sizeof(struct usb_hub_device), }; static const struct usb_device_id hub_id_table[] = { diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index ec8b403215..0b268d1964 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -174,7 +174,6 @@ int usb_stop(void) #ifdef CONFIG_USB_STORAGE usb_stor_reset(); #endif - usb_hub_reset(); uc_priv->companion_device_count = 0; usb_started = 0; @@ -227,7 +226,6 @@ int usb_init(void) int ret; asynch_allowed = 1; - usb_hub_reset(); ret = uclass_get(UCLASS_USB, &uc); if (ret)