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 1/2 v3] usb: Move determination of TT hub address/port into seperate function
Date: Mon, 21 Dec 2015 20:32:21 +0100	[thread overview]
Message-ID: <567853C5.3020605@redhat.com> (raw)
In-Reply-To: <5676FD87.9080000@redhat.com>

Hi,

On 20-12-15 20:12, Hans de Goede wrote:
> Hi,
>
> On 19-12-15 21:26, Stefan Br?ns wrote:
>> Start split and complete split tokens need the hub address and the
>> downstream port of the first HS hub (device view).
>>
>> The core of the function was duplicated in both host/ehci_hcd and
>> musb-new/usb-compat.h.
>>
>> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
>> ---
>> v2: - renamed function to usb_find_usb2_hub_address_port()
>>      - put musb port numbering change into seperate patch
>> v3: - do one assignement per line
>
> Thanks, I've tried to test this, but it seems that musb-new support in
> current master is broken in host mode when using hubs even when not
> adding your patch, so I need to debug that first...
>
> Note that your patch for musb-new does not even compile, you need this
> compile fix:
>
> @@ -2094,7 +2094,8 @@ int musb_urb_enqueue(
>               if (tt_needed(musb, urb->dev)) {
>                   uint8_t portnr = 0;
>                   uint8_t hubaddr = 0;
> -                usb_find_usb2_hub_address_port(udev, &hubaddr,
> +                usb_find_usb2_hub_address_port(urb->dev,
> +                                   &hubaddr,
>                                      &portnr);
>                   qh->h_addr_reg = hubaddr;
>                   qh->h_port_reg = portnr - 1;
>
> But with that still things do not work (as said current master seems broken atm).

Ok, so this is caused by the addition of drivermodel support to
the keyboard layer. I've just send a patch selecting DM_KEYBOARD for
sunxi and that fixes usb-kbds not working at all with current master.

With that fixed + the above compile fix, things work.

So with the above compile fix this patch is:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans

>
> Regards,
>
> Hans
>
>
>>
>>   common/usb.c                      | 56 +++++++++++++++++++++++++++++++++++++++
>>   drivers/usb/host/ehci-hcd.c       | 50 ++++------------------------------
>>   drivers/usb/musb-new/musb_host.c  |  9 ++++---
>>   drivers/usb/musb-new/usb-compat.h | 53 ------------------------------------
>>   include/usb.h                     | 12 +++++++++
>>   5 files changed, 79 insertions(+), 101 deletions(-)
>>
>> diff --git a/common/usb.c b/common/usb.c
>> index cc79695..41efe27 100644
>> --- a/common/usb.c
>> +++ b/common/usb.c
>> @@ -1213,4 +1213,60 @@ bool usb_device_has_child_on_port(struct usb_device *parent, int port)
>>   #endif
>>   }
>>
>> +#ifdef CONFIG_DM_USB
>> +void usb_find_usb2_hub_address_port(struct usb_device *udev,
>> +                   uint8_t *hub_address, uint8_t *hub_port)
>> +{
>> +    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_parent_priv(parent);
>> +
>> +    while (uparent->speed != USB_SPEED_HIGH) {
>> +        struct udevice *dev = parent;
>> +
>> +        if (device_get_uclass_id(dev->parent) != UCLASS_USB_HUB) {
>> +            printf("Error: Cannot find high speed parent of usb-1 device\n");
>> +            *hub_address = 0;
>> +            *hub_port = 0;
>> +            return;
>> +        }
>> +
>> +        ttdev = dev_get_parent_priv(dev);
>> +        parent = dev->parent;
>> +        uparent = dev_get_parent_priv(parent);
>> +    }
>> +    *hub_address = uparent->devnum;
>> +    *hub_port = ttdev->portnr;
>> +}
>> +#else
>> +void usb_find_usb2_hub_address_port(struct usb_device *udev,
>> +                   uint8_t *hub_address, uint8_t *hub_port)
>> +{
>> +    /* Find out the nearest parent which is high speed */
>> +    while (udev->parent->parent != NULL)
>> +        if (udev->parent->speed != USB_SPEED_HIGH) {
>> +            udev = udev->parent;
>> +        } else {
>> +            *hub_address = udev->parent->devnum;
>> +            *hub_port = udev->portnr;
>> +            return;
>> +        }
>> +
>> +    printf("Error: Cannot find high speed parent of usb-1 device\n");
>> +    *hub_address = 0;
>> +    *hub_port = 0;
>> +}
>> +#endif
>> +
>> +
>>   /* EOF */
>> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
>> index c85dbce..af025de 100644
>> --- a/drivers/usb/host/ehci-hcd.c
>> +++ b/drivers/usb/host/ehci-hcd.c
>> @@ -279,56 +279,16 @@ static inline u8 ehci_encode_speed(enum usb_device_speed speed)
>>   static void ehci_update_endpt2_dev_n_port(struct usb_device *udev,
>>                         struct QH *qh)
>>   {
>> -    struct usb_device *ttdev;
>> -    int parent_devnum;
>> +    uint8_t portnr = 0;
>> +    uint8_t hubaddr = 0;
>>
>>       if (udev->speed != USB_SPEED_LOW && udev->speed != USB_SPEED_FULL)
>>           return;
>>
>> -    /*
>> -     * For full / low speed devices we need to get the devnum and portnr of
>> -     * 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
>> -    /*
>> -     * 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 .
>> -     */
>> -    struct udevice *parent;
>> -    struct usb_device *uparent;
>> -
>> -    ttdev = udev;
>> -    parent = udev->dev;
>> -    uparent = dev_get_parent_priv(parent);
>> -
>> -    while (uparent->speed != USB_SPEED_HIGH) {
>> -        struct udevice *dev = parent;
>> -
>> -        if (device_get_uclass_id(dev->parent) != UCLASS_USB_HUB) {
>> -            printf("ehci: Error cannot find high-speed parent of usb-1 device\n");
>> -            return;
>> -        }
>> -
>> -        ttdev = dev_get_parent_priv(dev);
>> -        parent = dev->parent;
>> -        uparent = dev_get_parent_priv(parent);
>> -    }
>> -    parent_devnum = uparent->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
>> +    usb_find_usb2_hub_address_port(udev, &hubaddr, &portnr)
>>
>> -    qh->qh_endpt2 |= cpu_to_hc32(QH_ENDPT2_PORTNUM(ttdev->portnr) |
>> -                     QH_ENDPT2_HUBADDR(parent_devnum));
>> +    qh->qh_endpt2 |= cpu_to_hc32(QH_ENDPT2_PORTNUM(portnr) |
>> +                     QH_ENDPT2_HUBADDR(hubaddr));
>>   }
>>
>>   static int
>> diff --git a/drivers/usb/musb-new/musb_host.c b/drivers/usb/musb-new/musb_host.c
>> index 40b9c66..0125679 100644
>> --- a/drivers/usb/musb-new/musb_host.c
>> +++ b/drivers/usb/musb-new/musb_host.c
>> @@ -2092,9 +2092,12 @@ int musb_urb_enqueue(
>>               }
>>   #else
>>               if (tt_needed(musb, urb->dev)) {
>> -                u16 hub_port = find_tt(urb->dev);
>> -                qh->h_addr_reg = (u8) (hub_port >> 8);
>> -                qh->h_port_reg = (u8) (hub_port & 0xff);
>> +                uint8_t portnr = 0;
>> +                uint8_t hubaddr = 0;
>> +                usb_find_usb2_hub_address_port(udev, &hubaddr,
>> +                                   &portnr);
>> +                qh->h_addr_reg = hubaddr;
>> +                qh->h_port_reg = portnr - 1;
>>               }
>>   #endif
>>           }
>> diff --git a/drivers/usb/musb-new/usb-compat.h b/drivers/usb/musb-new/usb-compat.h
>> index 1c41e2a..760bd78 100644
>> --- a/drivers/usb/musb-new/usb-compat.h
>> +++ b/drivers/usb/musb-new/usb-compat.h
>> @@ -68,38 +68,6 @@ static inline int usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd,
>>   }
>>
>>   #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_parent_priv(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_parent_priv(dev);
>> -        parent = dev->parent;
>> -        uparent = dev_get_parent_priv(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;
>> @@ -129,27 +97,6 @@ static inline struct usb_device *usb_dev_get_parent(struct usb_device *udev)
>>       return NULL;
>>   }
>>   #else
>> -static inline u16 find_tt(struct usb_device *dev)
>> -{
>> -    u8 chid;
>> -    u8 hub;
>> -
>> -    /* Find out the nearest parent which is high speed */
>> -    while (dev->parent->parent != NULL)
>> -        if (dev->parent->speed != USB_SPEED_HIGH)
>> -            dev = dev->parent;
>> -        else
>> -            break;
>> -
>> -    /* determine the port address at that hub */
>> -    hub = dev->parent->devnum;
>> -    for (chid = 0; chid < USB_MAXCHILDREN; chid++)
>> -        if (dev->parent->children[chid] == dev)
>> -            break;
>> -
>> -    return (hub << 8) | chid;
>> -}
>> -
>>   static inline struct usb_device *usb_dev_get_parent(struct usb_device *dev)
>>   {
>>       return dev->parent;
>> diff --git a/include/usb.h b/include/usb.h
>> index 198ecbc..2539364 100644
>> --- a/include/usb.h
>> +++ b/include/usb.h
>> @@ -875,6 +875,18 @@ int legacy_hub_port_reset(struct usb_device *dev, int port,
>>
>>   int hub_port_reset(struct udevice *dev, int port, unsigned short *portstat);
>>
>> +/*
>> + * usb_find_usb2_hub_address_port() - Get hub address and port for TT setting
>> + *
>> + * Searches for the first HS hub above the given device. If a
>> + * HS hub is found, the hub address and the port the device is
>> + * connected to is return, as required for SPLIT transactions
>> + *
>> + * @param: udev full speed or low speed device
>> + */
>> +void usb_find_usb2_hub_address_port(struct usb_device *udev,
>> +                    uint8_t *hub_address, uint8_t *hub_port);
>> +
>>   /**
>>    * usb_alloc_new_device() - Allocate a new device
>>    *
>>

  reply	other threads:[~2015-12-21 19:32 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-13  4:17 [U-Boot] [PATCH 0/6] usb: dwc2: add SPLIT transaction support Stefan Brüns
2015-12-13  4:17 ` [U-Boot] [PATCH 1/6] usb: dwc2: avoid out of bounds access Stefan Brüns
2015-12-13  4:41   ` Marek Vasut
2015-12-16  2:58   ` Stephen Warren
2015-12-16 10:29     ` Marek Vasut
2015-12-17  1:44       ` Stefan Bruens
2015-12-13  4:17 ` [U-Boot] [PATCH 2/6] usb: dwc2: Handle NAK during CONTROL DATA and STATUS stage Stefan Brüns
2015-12-13  4:46   ` Marek Vasut
2015-12-16  3:07   ` Stephen Warren
2015-12-17  3:09     ` Stefan Bruens
2015-12-13  4:17 ` [U-Boot] [PATCH 3/6] usb: dwc2: determine TT hub address and port for split transactions Stefan Brüns
2015-12-13  4:43   ` Marek Vasut
2015-12-16  3:17   ` Stephen Warren
2015-12-17  3:16     ` Stefan Bruens
2015-12-18  1:11       ` [U-Boot] [PATCH] usb: Move determination of TT hub address/port into seperate function Stefan Brüns
2015-12-18  2:35         ` Marek Vasut
2015-12-18 10:00         ` Hans de Goede
2015-12-19 17:17           ` Stefan Bruens
2015-12-19 18:27             ` Hans de Goede
2015-12-19 20:16               ` [U-Boot] [PATCH 1/2 v2] " Stefan Brüns
2015-12-19 20:16                 ` [U-Boot] [PATCH 2/2 v2] usb: musb: Fix hub port number for SPLIT transactions Stefan Brüns
2015-12-21 19:33                   ` Hans de Goede
2015-12-21 20:27                     ` Marek Vasut
2015-12-21 23:02                       ` Stefan Bruens
2015-12-21 23:08                         ` Marek Vasut
2015-12-19 20:26               ` [U-Boot] [PATCH 1/2 v3] usb: Move determination of TT hub address/port into seperate function Stefan Brüns
2015-12-20 19:12                 ` Hans de Goede
2015-12-21 19:32                   ` Hans de Goede [this message]
2015-12-13  4:17 ` [U-Boot] [PATCH 4/6] usb: dwc2: add helper function for setting SPLIT HC registers Stefan Brüns
2015-12-13  4:44   ` Marek Vasut
2015-12-16  3:19   ` Stephen Warren
2015-12-13  4:17 ` [U-Boot] [PATCH 5/6] usb: dwc2: add support for SPLIT transactions Stefan Brüns
2015-12-13  4:48   ` Marek Vasut
2015-12-16  3:36   ` Stephen Warren
2015-12-20  0:17     ` Stefan Bruens
2015-12-20  0:41       ` Marek Vasut
2015-12-13  4:17 ` [U-Boot] [PATCH 6/6] usb: dwc2: remove no longer used wait_for_chhltd() Stefan Brüns
2015-12-13  4:48   ` Marek Vasut
2015-12-16  3:36   ` Stephen Warren
2015-12-13  4:41 ` [U-Boot] [PATCH 0/6] usb: dwc2: add SPLIT transaction support Marek Vasut
2015-12-16  2:53 ` Stephen Warren

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=567853C5.3020605@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