提交 dfa96e06 编写于 作者: B Bin Meng 提交者: Marek Vasut

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: NBin Meng <bmeng.cn@gmail.com>
Reviewed-by: NSimon Glass <sjg@chromium.org>
上级 5e941943
...@@ -55,9 +55,6 @@ struct usb_device_scan { ...@@ -55,9 +55,6 @@ struct usb_device_scan {
struct list_head list; struct list_head list;
}; };
/* 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;
static LIST_HEAD(usb_scan_list); static LIST_HEAD(usb_scan_list);
__weak void usb_hub_reset_devices(int port) __weak void usb_hub_reset_devices(int port)
...@@ -164,6 +161,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub) ...@@ -164,6 +161,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
max(100, (int)pgood_delay) + 1000); max(100, (int)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) void usb_hub_reset(void)
{ {
usb_hub_index = 0; usb_hub_index = 0;
...@@ -180,6 +181,7 @@ static struct usb_hub_device *usb_hub_allocate(void) ...@@ -180,6 +181,7 @@ static struct usb_hub_device *usb_hub_allocate(void)
printf("ERROR: USB_MAX_HUB (%d) reached\n", USB_MAX_HUB); printf("ERROR: USB_MAX_HUB (%d) reached\n", USB_MAX_HUB);
return NULL; return NULL;
} }
#endif
#define MAX_TRIES 5 #define MAX_TRIES 5
...@@ -543,6 +545,20 @@ out: ...@@ -543,6 +545,20 @@ out:
return ret; return ret;
} }
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) static int usb_hub_configure(struct usb_device *dev)
{ {
int i, length; int i, length;
...@@ -554,11 +570,11 @@ static int usb_hub_configure(struct usb_device *dev) ...@@ -554,11 +570,11 @@ static int usb_hub_configure(struct usb_device *dev)
__maybe_unused struct usb_hub_status *hubsts; __maybe_unused struct usb_hub_status *hubsts;
int ret; int ret;
/* "allocate" Hub device */ hub = usb_get_hub_device(dev);
hub = usb_hub_allocate();
if (hub == NULL) if (hub == NULL)
return -ENOMEM; return -ENOMEM;
hub->pusb_dev = dev; hub->pusb_dev = dev;
/* Get the the hub descriptor */ /* Get the the hub descriptor */
ret = usb_get_hub_descriptor(dev, buffer, 4); ret = usb_get_hub_descriptor(dev, buffer, 4);
if (ret < 0) { if (ret < 0) {
...@@ -792,6 +808,7 @@ UCLASS_DRIVER(usb_hub) = { ...@@ -792,6 +808,7 @@ UCLASS_DRIVER(usb_hub) = {
.child_pre_probe = usb_child_pre_probe, .child_pre_probe = usb_child_pre_probe,
.per_child_auto_alloc_size = sizeof(struct usb_device), .per_child_auto_alloc_size = sizeof(struct usb_device),
.per_child_platdata_auto_alloc_size = sizeof(struct usb_dev_platdata), .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[] = { static const struct usb_device_id hub_id_table[] = {
......
...@@ -177,7 +177,6 @@ int usb_stop(void) ...@@ -177,7 +177,6 @@ int usb_stop(void)
#ifdef CONFIG_USB_STORAGE #ifdef CONFIG_USB_STORAGE
usb_stor_reset(); usb_stor_reset();
#endif #endif
usb_hub_reset();
uc_priv->companion_device_count = 0; uc_priv->companion_device_count = 0;
usb_started = 0; usb_started = 0;
...@@ -230,7 +229,6 @@ int usb_init(void) ...@@ -230,7 +229,6 @@ int usb_init(void)
int ret; int ret;
asynch_allowed = 1; asynch_allowed = 1;
usb_hub_reset();
ret = uclass_get(UCLASS_USB, &uc); ret = uclass_get(UCLASS_USB, &uc);
if (ret) if (ret)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册