[U-Boot] [PATCH 04/16] usb: hub: Use 'struct usb_hub_device' as hub device's uclass_priv

Marek Vasut marex at denx.de
Fri Jun 23 17:54:54 UTC 2017


On 06/23/2017 11:54 AM, Bin Meng wrote:
> 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 <bmeng.cn at gmail.com>

Can you trim down the ifdeffery somehow or keep it more contained ?
I don't like having the code polluted by ifdefs all over the place,
so maybe factor out the specialties into function and put ifdef around
that or somesuch.

> ---
> 
>  common/usb_hub.c              | 10 +++++++++-
>  drivers/usb/host/usb-uclass.c |  2 --
>  2 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/common/usb_hub.c b/common/usb_hub.c
> index 090966b..18bd827 100644
> --- a/common/usb_hub.c
> +++ b/common/usb_hub.c
> @@ -58,9 +58,10 @@ struct usb_device_scan {
>  	struct list_head list;
>  };
>  
> -/* TODO(sjg at chromium.org): Remove this when CONFIG_DM_USB is defined */
> +#ifndef CONFIG_DM_USB
>  static struct usb_hub_device hub_dev[USB_MAX_HUB];
>  static int usb_hub_index;
> +#endif
>  static LIST_HEAD(usb_scan_list);
>  
>  __weak void usb_hub_reset_devices(int port)
> @@ -167,6 +168,7 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
>  	      max(100, (int)pgood_delay) + 1000);
>  }
>  
> +#ifndef CONFIG_DM_USB
>  void usb_hub_reset(void)
>  {
>  	usb_hub_index = 0;
> @@ -183,6 +185,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
>  
> @@ -557,10 +560,14 @@ static int usb_hub_configure(struct usb_device *dev)
>  	__maybe_unused struct usb_hub_status *hubsts;
>  	int ret;
>  
> +#ifndef CONFIG_DM_USB
>  	/* "allocate" Hub device */
>  	hub = usb_hub_allocate();
>  	if (hub == NULL)
>  		return -ENOMEM;
> +#else
> +	hub = dev_get_uclass_priv(dev->dev);
> +#endif
>  	hub->pusb_dev = dev;
>  	/* Get the the hub descriptor */
>  	ret = usb_get_hub_descriptor(dev, buffer, 4);
> @@ -795,6 +802,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 110ddc9..9bb8477 100644
> --- a/drivers/usb/host/usb-uclass.c
> +++ b/drivers/usb/host/usb-uclass.c
> @@ -177,7 +177,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;
>  
> @@ -230,7 +229,6 @@ int usb_init(void)
>  	int ret;
>  
>  	asynch_allowed = 1;
> -	usb_hub_reset();
>  
>  	ret = uclass_get(UCLASS_USB, &uc);
>  	if (ret)
> 


-- 
Best regards,
Marek Vasut


More information about the U-Boot mailing list