From: Hans de Goede <hdegoede@redhat.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/8] dm: usb: Store usb_device parent pointer in usb_device
Date: Fri, 01 May 2015 10:26:25 +0200 [thread overview]
Message-ID: <554338B1.9010504@redhat.com> (raw)
In-Reply-To: <CAPnjgZ1nuws_C1+_kwMt=N=pTnucYnhXgT6=YaDF+VQQyrMSdw@mail.gmail.com>
Hi,
On 01-05-15 06:11, Simon Glass wrote:
> Hi Hans,
>
> On 30 April 2015 at 08:35, Hans de Goede <hdegoede@redhat.com> wrote:
>> When calling into the hcd code in usb_scan_device() we do not yet have
>> the actual udevice for the device we are scanning, so we temporarily set
>> usb_device.dev to the parent.
>>
>> This means that we cannot use usb_device.dev to accurately determine our
>> place in the usb topology when reading descriptors, and this is necessary
>> to correctly program the usb-2 hub tt settings when a usb-1 device is
>> connected to a usb-2 hub.
>>
>> This commit (re)adds a direct parent usb_device pointer to struct usb_device
>> so that the usb hcd code can get to the usb_device parent without needing to
>> go through the dm.
>>
>> This fixes usb-1 devices plugged into usb-2 hubs not working with the driver
>> model.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> drivers/usb/host/ehci-hcd.c | 24 +-----------------------
>> drivers/usb/host/usb-uclass.c | 5 ++---
>> include/usb.h | 2 +-
>> 3 files changed, 4 insertions(+), 27 deletions(-)
>>
>
> While I agree this is expedient, is there really no other way? How are
> we going to move to driver model if we add back in the
> non-driver-model pointers, etc.? We'll end up with a hybrid approach
> and a real mess.
>
> Is it possible to bug-fix the driver model code (presumably below) instead?
>
That is what I tried first, and failed todo. But after implementing the fix
as posted to the list I've been thinking about it some more and I think it should
be possible so I'll try again.
Regards,
Hans
>> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
>> index 19f1e29..00c038c 100644
>> --- a/drivers/usb/host/ehci-hcd.c
>> +++ b/drivers/usb/host/ehci-hcd.c
>> @@ -292,7 +292,6 @@ static void ehci_update_endpt2_dev_n_port(struct usb_device *udev,
>> struct QH *qh)
>> {
>> struct usb_device *ttdev;
>> - int parent_devnum;
>>
>> if (udev->speed != USB_SPEED_LOW && udev->speed != USB_SPEED_FULL)
>> return;
>> @@ -302,35 +301,14 @@ static void ehci_update_endpt2_dev_n_port(struct usb_device *udev,
>> * the tt, so of the first upstream usb-2 hub, there may be usb-1 hubs
>> * in the tree before that one!
>> */
>> -#ifdef CONFIG_DM_USB
>> - struct udevice *parent;
>> -
>> - for (ttdev = udev; ; ) {
>> - struct udevice *dev = ttdev->dev;
>> -
>> - if (dev->parent &&
>> - device_get_uclass_id(dev->parent) == UCLASS_USB_HUB)
>> - parent = dev->parent;
>> - else
>> - parent = NULL;
>> - if (!parent)
>> - return;
>> - ttdev = dev_get_parentdata(parent);
>> - if (!ttdev->speed != USB_SPEED_HIGH)
>> - break;
>> - }
>> - parent_devnum = ttdev->devnum;
>> -#else
>> ttdev = udev;
>> while (ttdev->parent && ttdev->parent->speed != USB_SPEED_HIGH)
>> ttdev = ttdev->parent;
>> if (!ttdev->parent)
>> return;
>> - parent_devnum = ttdev->parent->devnum;
>> -#endif
>>
>> qh->qh_endpt2 |= cpu_to_hc32(QH_ENDPT2_PORTNUM(ttdev->portnr) |
>> - QH_ENDPT2_HUBADDR(parent_devnum));
>> + QH_ENDPT2_HUBADDR(ttdev->parent->devnum));
>> }
>>
>> static int
>> diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
>> index 95e371d..0157bc6 100644
>> --- a/drivers/usb/host/usb-uclass.c
>> +++ b/drivers/usb/host/usb-uclass.c
>> @@ -470,7 +470,6 @@ int usb_scan_device(struct udevice *parent, int port,
>> bool created = false;
>> struct usb_dev_platdata *plat;
>> struct usb_bus_priv *priv;
>> - struct usb_device *parent_udev;
>> int ret;
>> ALLOC_CACHE_ALIGN_BUFFER(struct usb_device, udev, 1);
>> struct usb_interface_descriptor *iface = &udev->config.if_desc[0].desc;
>> @@ -515,9 +514,9 @@ int usb_scan_device(struct udevice *parent, int port,
>> udev->devnum = priv->next_addr + 1;
>> udev->portnr = port;
>> debug("Calling usb_setup_device(), portnr=%d\n", udev->portnr);
>> - parent_udev = device_get_uclass_id(parent) == UCLASS_USB_HUB ?
>> + udev->parent = device_get_uclass_id(parent) == UCLASS_USB_HUB ?
>> dev_get_parentdata(parent) : NULL;
>> - ret = usb_setup_device(udev, priv->desc_before_addr, parent_udev, port);
>> + ret = usb_setup_device(udev, priv->desc_before_addr, udev->parent, port);
>> debug("read_descriptor for '%s': ret=%d\n", parent->name, ret);
>> if (ret)
>> return ret;
>> diff --git a/include/usb.h b/include/usb.h
>> index 1b667ff..7876df4 100644
>> --- a/include/usb.h
>> +++ b/include/usb.h
>> @@ -141,9 +141,9 @@ struct usb_device {
>> int act_len; /* transfered bytes */
>> int maxchild; /* Number of ports if hub */
>> int portnr; /* Port number, 1=first */
>> -#ifndef CONFIG_DM_USB
>> /* parent hub, or NULL if this is the root hub */
>> struct usb_device *parent;
>> +#ifndef CONFIG_DM_USB
>> struct usb_device *children[USB_MAXCHILDREN];
>> void *controller; /* hardware controller private data */
>> #endif
>> --
>> 2.3.6
>>
next prev parent reply other threads:[~2015-05-01 8:26 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-30 14:35 [U-Boot] [PATCH 0/8] usb: driver-model fixes and dm support sunxi-ehci.c Hans de Goede
2015-04-30 14:35 ` [U-Boot] [PATCH 1/8] dm: usb: Copy over usb_device values from usb_scan_device() to final usb_device Hans de Goede
2015-05-01 4:11 ` Simon Glass
2015-05-01 7:21 ` Hans de Goede
2015-05-01 8:03 ` Hans de Goede
2015-04-30 14:35 ` [U-Boot] [PATCH 2/8] dm: usb: Use controller_dev in dm ehci code Hans de Goede
2015-05-01 4:11 ` Simon Glass
2015-05-01 8:03 ` Hans de Goede
2015-04-30 14:35 ` [U-Boot] [PATCH 3/8] dm: usb: Store usb_device parent pointer in usb_device Hans de Goede
2015-05-01 4:11 ` Simon Glass
2015-05-01 8:26 ` Hans de Goede [this message]
2015-04-30 14:35 ` [U-Boot] [PATCH 4/8] dm: usb: Set desc_before_addr from ehci dm code Hans de Goede
2015-05-01 4:12 ` Simon Glass
2015-04-30 14:35 ` [U-Boot] [PATCH 5/8] dm: usb: Add support for interrupt queues to the dm usb code Hans de Goede
2015-05-01 4:12 ` Simon Glass
2015-04-30 14:35 ` [U-Boot] [PATCH 6/8] dm: usb: Prefix ehci interrupt-queue functions with _ehci_ Hans de Goede
2015-05-01 4:12 ` Simon Glass
2015-04-30 14:35 ` [U-Boot] [PATCH 7/8] dm: usb: Add support for interrupt queues to the dm ehci code Hans de Goede
2015-05-01 4:12 ` Simon Glass
2015-04-30 14:35 ` [U-Boot] [PATCH 8/8] sunxi: ehci: Convert to the driver-model Hans de Goede
2015-05-01 4:12 ` Simon Glass
2015-05-01 8:37 ` Hans de Goede
2015-05-02 14:03 ` Ian Campbell
2015-05-02 14:04 ` Ian Campbell
2015-05-04 14:16 ` Hans de Goede
2015-04-30 14:39 ` [U-Boot] [PATCH 0/8] usb: driver-model fixes and dm support sunxi-ehci.c Hans de Goede
2015-04-30 14:48 ` Simon Glass
2015-04-30 19:38 ` Hans de Goede
2015-04-30 22:04 ` Simon Glass
2015-05-01 7:17 ` 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=554338B1.9010504@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.