From 89aea23abb971fa89b7a96c02024b63d0b918a78 Mon Sep 17 00:00:00 2001 From: Ismael Luceno Cortes Date: Tue, 19 Mar 2019 09:19:44 +0000 Subject: [PATCH 1/3] usb: host: Print device name when scanning Drop the counter, it has no meaning other than being the order in which the interface is found; the name assigned to the USB host controller interface is a better indicator. Example of the original output: > USB0: USB EHCI 1.10 > scanning bus 0 for devices... 2 USB Device(s) found > scanning usb for storage devices... 1 Storage Device(s) found Patched output: > Bus usb@ee080100: USB EHCI 1.10 > scanning bus usb@ee080100 for devices... 2 USB Device(s) found > scanning usb for storage devices... 1 Storage Device(s) found Signed-off-by: Ismael Luceno --- drivers/usb/host/usb-uclass.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index 611ea97a72..6e118b5a8f 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -210,7 +210,7 @@ static void usb_scan_bus(struct udevice *bus, bool recurse) assert(recurse); /* TODO: Support non-recusive */ - printf("scanning bus %d for devices... ", bus->seq); + printf("scanning bus %s for devices... ", bus->name); debug("\n"); ret = usb_scan_device(bus, 0, USB_SPEED_FULL, &dev); if (ret) @@ -242,7 +242,6 @@ int usb_init(void) struct usb_bus_priv *priv; struct udevice *bus; struct uclass *uc; - int count = 0; int ret; asynch_allowed = 1; @@ -255,8 +254,7 @@ int usb_init(void) uclass_foreach_dev(bus, uc) { /* init low_level USB */ - printf("USB%d: ", count); - count++; + printf("Bus %s: ", bus->name); #ifdef CONFIG_SANDBOX /* @@ -327,10 +325,8 @@ int usb_init(void) remove_inactive_children(uc, bus); /* if we were not able to find at least one working bus, bail out */ - if (!count) - printf("No controllers found\n"); - else if (controllers_initialized == 0) - printf("USB error: all controllers failed lowlevel init\n"); + if (controllers_initialized == 0) + printf("No working controllers found\n"); return usb_started ? 0 : -1; } From 51f60a89b75e5b71c747e15b8247abae798244ec Mon Sep 17 00:00:00 2001 From: Ismael Luceno Cortes Date: Mon, 1 Apr 2019 16:09:13 +0000 Subject: [PATCH 2/3] usb: Make portspeed return a read-only string Current code is plain wrong, and there's no need to have a mutable string, so fix function type and remove the intermediate variable. Signed-off-by: Ismael Luceno --- cmd/usb.c | 18 +++++------------- common/usb_hub.c | 18 +++++------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/cmd/usb.c b/cmd/usb.c index 0ccb1b5148..dd9ac0bc97 100644 --- a/cmd/usb.c +++ b/cmd/usb.c @@ -316,26 +316,18 @@ static struct usb_device *usb_find_device(int devnum) return NULL; } -static inline char *portspeed(int speed) +static inline const char *portspeed(int speed) { - char *speed_str; - switch (speed) { case USB_SPEED_SUPER: - speed_str = "5 Gb/s"; - break; + return "5 Gb/s"; case USB_SPEED_HIGH: - speed_str = "480 Mb/s"; - break; + return "480 Mb/s"; case USB_SPEED_LOW: - speed_str = "1.5 Mb/s"; - break; + return "1.5 Mb/s"; default: - speed_str = "12 Mb/s"; - break; + return "12 Mb/s"; } - - return speed_str; } /* shows the device tree recursively */ diff --git a/common/usb_hub.c b/common/usb_hub.c index 33aaeb8e44..9069f4b33a 100644 --- a/common/usb_hub.c +++ b/common/usb_hub.c @@ -233,26 +233,18 @@ static struct usb_hub_device *usb_hub_allocate(void) #define MAX_TRIES 5 -static inline char *portspeed(int portstatus) +static inline const char *portspeed(int portstatus) { - char *speed_str; - switch (portstatus & USB_PORT_STAT_SPEED_MASK) { case USB_PORT_STAT_SUPER_SPEED: - speed_str = "5 Gb/s"; - break; + return "5 Gb/s"; case USB_PORT_STAT_HIGH_SPEED: - speed_str = "480 Mb/s"; - break; + return "480 Mb/s"; case USB_PORT_STAT_LOW_SPEED: - speed_str = "1.5 Mb/s"; - break; + return "1.5 Mb/s"; default: - speed_str = "12 Mb/s"; - break; + return "12 Mb/s"; } - - return speed_str; } /** From 69535b33bc1fce43dcc10b646cf44db81cffa131 Mon Sep 17 00:00:00 2001 From: Adam Ford Date: Wed, 3 Apr 2019 08:41:56 -0500 Subject: [PATCH 3/3] usb: ehci-mx6: Use common code to extract dr_mode There exists code in drivers/common/common.c to read the dr_mode from the device tree. This patch converts this driver to use that function to initialize the driver. Signed-off-by: Adam Ford --- drivers/usb/host/ehci-mx6.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c index 948394709f..33abfeada0 100644 --- a/drivers/usb/host/ehci-mx6.c +++ b/drivers/usb/host/ehci-mx6.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "ehci.h" @@ -483,23 +484,23 @@ static int ehci_usb_phy_mode(struct udevice *dev) static int ehci_usb_ofdata_to_platdata(struct udevice *dev) { struct usb_platdata *plat = dev_get_platdata(dev); - const char *mode; + enum usb_dr_mode dr_mode; - mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "dr_mode", NULL); - if (mode) { - if (strcmp(mode, "peripheral") == 0) - plat->init_type = USB_INIT_DEVICE; - else if (strcmp(mode, "host") == 0) - plat->init_type = USB_INIT_HOST; - else if (strcmp(mode, "otg") == 0) - return ehci_usb_phy_mode(dev); - else - return -EINVAL; + dr_mode = usb_get_dr_mode(dev_of_offset(dev)); - return 0; - } + switch (dr_mode) { + case USB_DR_MODE_HOST: + plat->init_type = USB_INIT_HOST; + break; + case USB_DR_MODE_PERIPHERAL: + plat->init_type = USB_INIT_DEVICE; + break; + case USB_DR_MODE_OTG: + case USB_DR_MODE_UNKNOWN: + return ehci_usb_phy_mode(dev); + }; - return ehci_usb_phy_mode(dev); + return 0; } static int ehci_usb_probe(struct udevice *dev)