From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Vasut Date: Fri, 23 Jun 2017 19:59:05 +0200 Subject: [U-Boot] [PATCH 07/16] usb: hub: Translate USB 3.0 hub port status into old version In-Reply-To: <1498211673-18715-8-git-send-email-bmeng.cn@gmail.com> References: <1498211673-18715-1-git-send-email-bmeng.cn@gmail.com> <1498211673-18715-8-git-send-email-bmeng.cn@gmail.com> Message-ID: <8183c3df-f969-89a4-800d-5ebfafb4b5d0@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 06/23/2017 11:54 AM, Bin Meng wrote: > USB 3.0 hub port status field has different bit positions from 2.0 > hubs. Since U-Boot only understands the old version, translate the > new one into the old one. This is quite hairy. I'd rather see some protocol version agnostic flag field rather than patching the wPortStatus and co. > Since we are going to add USB 3.0 hub support, this feature is only > available with driver model USB. > > Signed-off-by: Bin Meng > --- > > common/usb_hub.c | 33 ++++++++++++++++++++++++++++++++- > 1 file changed, 32 insertions(+), 1 deletion(-) > > diff --git a/common/usb_hub.c b/common/usb_hub.c > index d780251..835fac9 100644 > --- a/common/usb_hub.c > +++ b/common/usb_hub.c > @@ -119,9 +119,40 @@ static int usb_get_hub_status(struct usb_device *dev, void *data) > > int usb_get_port_status(struct usb_device *dev, int port, void *data) > { > - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), > + int ret; > + > + ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), > USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port, > data, sizeof(struct usb_port_status), USB_CNTL_TIMEOUT); > + > +#ifdef CONFIG_DM_USB > + if (ret < 0) > + return ret; > + > + /* > + * Translate the USB 3.0 hub port status field into the old version > + * that U-Boot understands. Do this only when the hub is not root hub. > + * For root hub, the port status field has already been translated > + * in the host controller driver (see xhci_submit_root() in xhci.c). > + * > + * Note: this only supports driver model. > + */ > + > + if (!usb_hub_is_root_hub(dev->dev) && usb_hub_is_superspeed(dev)) { > + struct usb_port_status *status = (struct usb_port_status *)data; > + u16 tmp = (status->wPortStatus) & USB_SS_PORT_STAT_MASK; > + > + if (status->wPortStatus & USB_SS_PORT_STAT_POWER) > + tmp |= USB_PORT_STAT_POWER; > + if ((status->wPortStatus & USB_SS_PORT_STAT_SPEED) == > + USB_SS_PORT_STAT_SPEED_5GBPS) > + tmp |= USB_PORT_STAT_SUPER_SPEED; > + > + status->wPortStatus = tmp; > + } > +#endif > + > + return ret; > } > > > -- Best regards, Marek Vasut