public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 12/22] musb: Update usb-compat to work with struct usb_device without a parent ptr
Date: Wed, 1 Jul 2015 16:57:57 +0200	[thread overview]
Message-ID: <5593FFF5.5020908@redhat.com> (raw)
In-Reply-To: <CAPnjgZ27aMiwiq-FYS2ZktZiusMF61As17bTrUWBXqP1m9t8Dw@mail.gmail.com>

Hi,

On 29-06-15 05:45, Simon Glass wrote:
> Hi Hans,
>
> On 17 June 2015 at 13:33, Hans de Goede <hdegoede@redhat.com> wrote:
>> When building with CONFIG_DM_USB=y struct usb_device does not have a parent
>> pointer. This commit adds support to the musb code to deal with this.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>   drivers/usb/musb-new/musb_host.c  |  4 +++
>>   drivers/usb/musb-new/musb_uboot.c |  2 +-
>>   drivers/usb/musb-new/usb-compat.h | 70 +++++++++++++++++++++++++++++++++++++++
>>   3 files changed, 75 insertions(+), 1 deletion(-)
>>
>
> Acked-by: Simon Glass <sjg@chromium.org>
>
> See note below.
>
>> diff --git a/drivers/usb/musb-new/musb_host.c b/drivers/usb/musb-new/musb_host.c
>> index 437309c..40b9c66 100644
>> --- a/drivers/usb/musb-new/musb_host.c
>> +++ b/drivers/usb/musb-new/musb_host.c
>> @@ -2067,7 +2067,11 @@ int musb_urb_enqueue(
>>
>>          /* precompute addressing for external hub/tt ports */
>>          if (musb->is_multipoint) {
>> +#ifndef __UBOOT__
>>                  struct usb_device       *parent = urb->dev->parent;
>> +#else
>> +               struct usb_device       *parent = usb_dev_get_parent(urb->dev);
>> +#endif
>>
>>   #ifndef __UBOOT__
>>                  if (parent != hcd->self.root_hub) {
>> diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb-new/musb_uboot.c
>> index 70e87c9..a96e8d2 100644
>> --- a/drivers/usb/musb-new/musb_uboot.c
>> +++ b/drivers/usb/musb-new/musb_uboot.c
>> @@ -97,7 +97,7 @@ int submit_control_msg(struct usb_device *dev, unsigned long pipe,
>>                        buffer, len, setup, 0);
>>
>>          /* Fix speed for non hub-attached devices */
>> -       if (!dev->parent)
>> +       if (!usb_dev_get_parent(dev))
>>                  dev->speed = host_speed;
>>
>>          return submit_urb(&hcd, &urb);
>> diff --git a/drivers/usb/musb-new/usb-compat.h b/drivers/usb/musb-new/usb-compat.h
>> index 50bad37..53fe4ff 100644
>> --- a/drivers/usb/musb-new/usb-compat.h
>> +++ b/drivers/usb/musb-new/usb-compat.h
>> @@ -1,6 +1,7 @@
>>   #ifndef __USB_COMPAT_H__
>>   #define __USB_COMPAT_H__
>>
>> +#include <dm.h>
>>   #include "usb.h"
>>
>>   struct usb_hcd {
>> @@ -66,6 +67,68 @@ static inline int usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd,
>>          return 0;
>>   }
>>
>> +#ifdef CONFIG_DM_USB
>> +static inline u16 find_tt(struct usb_device *udev)
>> +{
>> +       struct udevice *parent;
>> +       struct usb_device *uparent, *ttdev;
>> +
>> +       /*
>> +        * When called from usb-uclass.c: usb_scan_device() udev->dev points
>> +        * to the parent udevice, not the actual udevice belonging to the
>> +        * udev as the device is not instantiated yet. So when searching
>> +        * for the first usb-2 parent start with udev->dev not
>> +        * udev->dev->parent .
>> +        */
>> +       ttdev = udev;
>> +       parent = udev->dev;
>> +       uparent = dev_get_parentdata(parent);
>> +
>> +       while (uparent->speed != USB_SPEED_HIGH) {
>> +               struct udevice *dev = parent;
>> +
>> +               if (device_get_uclass_id(dev->parent) != UCLASS_USB_HUB) {
>> +                       printf("musb: Error cannot find high speed parent of usb-1 device\n");
>> +                       return 0;
>> +               }
>> +
>> +               ttdev = dev_get_parentdata(dev);
>> +               parent = dev->parent;
>> +               uparent = dev_get_parentdata(parent);
>> +       }
>> +
>> +       return (uparent->devnum << 8) | (ttdev->portnr - 1);
>> +}
>> +
>> +static inline struct usb_device *usb_dev_get_parent(struct usb_device *udev)
>> +{
>> +       struct udevice *parent = udev->dev->parent;
>> +
>> +       /*
>> +        * When called from usb-uclass.c: usb_scan_device() udev->dev points
>> +        * to the parent udevice, not the actual udevice belonging to the
>> +        * udev as the device is not instantiated yet.
>
> Another option here is to somehow allow devices to be added before we
> know what they are. In this case we could bind a 'generic' USB device
> (UCLASS_USB_DEV_GENERIC). Then when we work out what it is, we could
> unbind it (without throwing away the udevice and usb_device) and have
> it bind again as the correct device. Something like
> device_morph_child().

Right, I think that may end up being cleaner in the long term.

Regards,

Hans

  reply	other threads:[~2015-07-01 14:57 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-17 19:33 [U-Boot] [PATCH 00/22] Convert musb host mode code to the device-model Hans de Goede
2015-06-17 19:33 ` [U-Boot] [PATCH 01/22] usb: Always declare usb function prototypes Hans de Goede
2015-06-29  3:44   ` Simon Glass
2015-07-07 18:33     ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 02/22] usb: Drop device-model specific copy of usb_legacy_port_reset Hans de Goede
2015-06-29  3:44   ` Simon Glass
2015-07-07 18:33     ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 03/22] usb: usb_setup_device: Drop unneeded portnr function argument Hans de Goede
2015-06-29  3:44   ` Simon Glass
2015-06-30 12:29     ` Hans de Goede
2015-06-30 14:51       ` Simon Glass
2015-07-07 18:34         ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 04/22] usb: Pass device instead of portnr to usb_legacy_port_reset Hans de Goede
2015-06-29  3:44   ` Simon Glass
2015-06-30 12:31     ` Hans de Goede
2015-06-30 14:58       ` Simon Glass
2015-07-07 18:34         ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 05/22] usb: Add an usb_device parameter to usb_reset_root_port Hans de Goede
2015-06-29  3:45   ` Simon Glass
2015-07-07 18:34     ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 06/22] dm: Export device_chld_remove / device_chld_unbind Hans de Goede
2015-06-29  3:45   ` Simon Glass
2015-06-30 12:33     ` Hans de Goede
2015-06-17 19:33 ` [U-Boot] [PATCH 07/22] dm: usb: Fix "usb tree" output Hans de Goede
2015-06-29  3:45   ` Simon Glass
2015-07-07 18:34     ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 08/22] dm: usb: Use device_chld_remove and _unbind to clean up usb devs on stop Hans de Goede
2015-06-29  3:45   ` Simon Glass
2015-06-30 12:54     ` Hans de Goede
2015-06-30 14:58       ` Simon Glass
2015-06-30 15:54         ` Hans de Goede
2015-06-30 16:07           ` Simon Glass
2015-06-30 20:20             ` Hans de Goede
2015-06-30 21:20               ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 09/22] dm: usb: Allow usb host drivers to implement usb_reset_root_port Hans de Goede
2015-06-29  3:45   ` Simon Glass
2015-07-07 18:35     ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 10/22] dm: usb: Do not assume that first child is always a hub Hans de Goede
2015-06-29  3:45   ` Simon Glass
2015-07-07 18:35     ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 11/22] musb: Allow musb_platform_enable to return an error code Hans de Goede
2015-06-29  3:45   ` Simon Glass
2015-07-07 18:35     ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 12/22] musb: Update usb-compat to work with struct usb_device without a parent ptr Hans de Goede
2015-06-29  3:45   ` Simon Glass
2015-07-01 14:57     ` Hans de Goede [this message]
2015-07-07 18:35       ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 13/22] musb: Rename and wrap public functions Hans de Goede
2015-06-29  3:45   ` Simon Glass
2015-07-07 18:35     ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 14/22] musb: Add musb_host_data struct to hold global data Hans de Goede
2015-06-29  3:45   ` Simon Glass
2015-07-07 18:36     ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 15/22] musb: Add device-model support to the musb-host u-boot glue Hans de Goede
2015-06-29  3:45   ` Simon Glass
2015-07-07 18:36     ` Simon Glass
2015-06-17 19:33 ` [U-Boot] [PATCH 16/22] sunxi: usb-phy: Add support for reading otg id pin value Hans de Goede
2015-06-19  7:37   ` Ian Campbell
2015-06-17 19:34 ` [U-Boot] [PATCH 17/22] sunxi: musb: Move vbus check to sunxi_musb_enable Hans de Goede
2015-06-19  7:37   ` Ian Campbell
2015-06-17 19:34 ` [U-Boot] [PATCH 18/22] sunxi: musb: Add id pin support Hans de Goede
2015-06-19  7:40   ` Ian Campbell
2015-06-19  9:33     ` Hans de Goede
2015-06-17 19:34 ` [U-Boot] [PATCH 19/22] sunxi: musb: Move musb config and platdata to the sunxi-musb glue Hans de Goede
2015-06-19  7:43   ` Ian Campbell
2015-06-19  9:35     ` Hans de Goede
2015-06-19 13:31       ` Ian Campbell
2015-06-17 19:34 ` [U-Boot] [PATCH 20/22] sunxi: musb: Use device-model for musb host mode Hans de Goede
2015-06-19  7:45   ` Ian Campbell
2015-06-17 19:34 ` [U-Boot] [PATCH 21/22] sunxi: Kconfig: Enable CONFIG_USB and friends by default on sunxi Hans de Goede
2015-06-19  7:46   ` Ian Campbell
2015-06-19  9:37     ` Hans de Goede
2015-06-19 13:32       ` Ian Campbell
2015-06-17 19:34 ` [U-Boot] [PATCH 22/22] sunxi: ga10h: Enable both otg and regular usb host controllers Hans de Goede
2015-06-19  7:46   ` Ian Campbell
2015-06-19 13:10 ` [U-Boot] [PATCH 00/22] Convert musb host mode code to the device-model Simon Glass
2015-06-19 13:12   ` Hans de Goede
2015-06-19 13:14   ` Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5593FFF5.5020908@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox