From 3a38e874d70b1c80a3e3118be6fc010b558cc050 Mon Sep 17 00:00:00 2001 From: Shuah Khan Date: Thu, 2 May 2019 13:47:18 -0600 Subject: usbip: usbip_host: cleanup do_rebind() return path Cleanup do_rebind() return path and use common return path. Signed-off-by: Shuah Khan Signed-off-by: Greg Kroah-Hartman --- drivers/usb/usbip/stub_main.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c index bf8a5feb0ee9..2e4bfccd4bfc 100644 --- a/drivers/usb/usbip/stub_main.c +++ b/drivers/usb/usbip/stub_main.c @@ -201,7 +201,7 @@ static DRIVER_ATTR_RW(match_busid); static int do_rebind(char *busid, struct bus_id_priv *busid_priv) { - int ret; + int ret = 0; /* device_attach() callers should hold parent lock for USB */ if (busid_priv->udev->dev.parent) @@ -209,11 +209,9 @@ static int do_rebind(char *busid, struct bus_id_priv *busid_priv) ret = device_attach(&busid_priv->udev->dev); if (busid_priv->udev->dev.parent) device_unlock(busid_priv->udev->dev.parent); - if (ret < 0) { + if (ret < 0) dev_err(&busid_priv->udev->dev, "rebind failed\n"); - return ret; - } - return 0; + return ret; } static void stub_device_rebind(void) -- cgit v1.2.3 From 01d4071486fe18ec91f78725d81c7e46557c629a Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Mon, 20 May 2019 11:08:23 +0200 Subject: usb: exynos: add workaround for the USB device bindings conflict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 69bec7259853 ("USB: core: let USB device know device node") added support for attaching devicetree node for USB devices. Those nodes are children of their USB host controller. However Exynos EHCI and OHCI driver bindings already define child-nodes for each physical root hub port and assigns respective PHY controller and parameters to them. Those bindings predates support for USB device tree nodes. To mitigate the side-effects of the conflict between those bindings, lets reset Exynos host controller of_node pointer before registering it to USB subsystem. This fixes the issue raised by the commit 01fdf179f4b0 ("usb: core: skip interfaces disabled in devicetree"), which incorrectly disabled some devices on Exynos based boards. Reported-by: Markus Reichl Suggested-by: Måns Rullgård Signed-off-by: Marek Szyprowski Acked-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-exynos.c | 11 +++++++++++ drivers/usb/host/ohci-exynos.c | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c index 8e3bab1e0c1f..3a29a1a8519c 100644 --- a/drivers/usb/host/ehci-exynos.c +++ b/drivers/usb/host/ehci-exynos.c @@ -39,6 +39,7 @@ static struct hc_driver __read_mostly exynos_ehci_hc_driver; struct exynos_ehci_hcd { struct clk *clk; + struct device_node *of_node; struct phy *phy[PHY_NUMBER]; }; @@ -203,6 +204,13 @@ static int exynos_ehci_probe(struct platform_device *pdev) ehci = hcd_to_ehci(hcd); ehci->caps = hcd->regs; + /* + * Workaround: reset of_node pointer to avoid conflict between Exynos + * EHCI port subnodes and generic USB device bindings + */ + exynos_ehci->of_node = pdev->dev.of_node; + pdev->dev.of_node = NULL; + /* DMA burst Enable */ writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); @@ -219,6 +227,7 @@ static int exynos_ehci_probe(struct platform_device *pdev) fail_add_hcd: exynos_ehci_phy_disable(&pdev->dev); + pdev->dev.of_node = exynos_ehci->of_node; fail_io: clk_disable_unprepare(exynos_ehci->clk); fail_clk: @@ -231,6 +240,8 @@ static int exynos_ehci_remove(struct platform_device *pdev) struct usb_hcd *hcd = platform_get_drvdata(pdev); struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); + pdev->dev.of_node = exynos_ehci->of_node; + usb_remove_hcd(hcd); exynos_ehci_phy_disable(&pdev->dev); diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c index c0c4dcca6f3c..905c6317e0c3 100644 --- a/drivers/usb/host/ohci-exynos.c +++ b/drivers/usb/host/ohci-exynos.c @@ -30,6 +30,7 @@ static struct hc_driver __read_mostly exynos_ohci_hc_driver; struct exynos_ohci_hcd { struct clk *clk; + struct device_node *of_node; struct phy *phy[PHY_NUMBER]; }; @@ -170,6 +171,13 @@ static int exynos_ohci_probe(struct platform_device *pdev) goto fail_io; } + /* + * Workaround: reset of_node pointer to avoid conflict between Exynos + * OHCI port subnodes and generic USB device bindings + */ + exynos_ohci->of_node = pdev->dev.of_node; + pdev->dev.of_node = NULL; + err = usb_add_hcd(hcd, irq, IRQF_SHARED); if (err) { dev_err(&pdev->dev, "Failed to add USB HCD\n"); @@ -180,6 +188,7 @@ static int exynos_ohci_probe(struct platform_device *pdev) fail_add_hcd: exynos_ohci_phy_disable(&pdev->dev); + pdev->dev.of_node = exynos_ohci->of_node; fail_io: clk_disable_unprepare(exynos_ohci->clk); fail_clk: @@ -192,6 +201,8 @@ static int exynos_ohci_remove(struct platform_device *pdev) struct usb_hcd *hcd = platform_get_drvdata(pdev); struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); + pdev->dev.of_node = exynos_ohci->of_node; + usb_remove_hcd(hcd); exynos_ohci_phy_disable(&pdev->dev); -- cgit v1.2.3 From 4e4feeec4e6cf6d0e14a45470c7f232cb685336b Mon Sep 17 00:00:00 2001 From: Naveen Kumar Parna Date: Thu, 16 May 2019 20:49:23 +0530 Subject: USB: OHCI: remove space before open square bracket '[' This patch removes following checkpatch.pl error in usb/host/ohci-pci.c file. ERROR: space prohibited before open square bracket '[' Signed-off-by: Naveen Kumar Parna Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ohci-pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c index fbcd34911025..a033f7d855e0 100644 --- a/drivers/usb/host/ohci-pci.c +++ b/drivers/usb/host/ohci-pci.c @@ -274,7 +274,7 @@ static const struct ohci_driver_overrides pci_overrides __initconst = { .reset = ohci_pci_reset, }; -static const struct pci_device_id pci_ids [] = { { +static const struct pci_device_id pci_ids[] = { { /* handle any USB OHCI controller */ PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_OHCI, ~0), .driver_data = (unsigned long) &ohci_pci_hc_driver, -- cgit v1.2.3 From be21a02a5a5ec88b12ce535ead715d4bbb173a55 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Mon, 13 May 2019 11:40:29 +0900 Subject: usb: renesas_usbhs: Use specific struct instead of USBHS_TYPE_* enums This patch adds a specific struct "usbhs_of_data" to add a new SoC data easily instead of code basis in the future. Signed-off-by: Yoshihiro Shimoda Reviewed-by: Geert Uytterhoeven Reviewed-by: Simon Horman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 112 +++++++++++++++++++++---------------- drivers/usb/renesas_usbhs/common.h | 5 ++ 2 files changed, 70 insertions(+), 47 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 249fbee97f3f..0ca89de7f842 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -535,53 +535,92 @@ static int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev) return 0; } +static const struct usbhs_of_data rcar_gen2_data = { + .platform_callback = &usbhs_rcar2_ops, + .param = { + .type = USBHS_TYPE_RCAR_GEN2, + .has_usb_dmac = 1, + .pipe_configs = usbhsc_new_pipe, + .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), + } +}; + +static const struct usbhs_of_data rcar_gen3_data = { + .platform_callback = &usbhs_rcar3_ops, + .param = { + .type = USBHS_TYPE_RCAR_GEN3, + .has_usb_dmac = 1, + .pipe_configs = usbhsc_new_pipe, + .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), + } +}; + +static const struct usbhs_of_data rcar_gen3_with_pll_data = { + .platform_callback = &usbhs_rcar3_with_pll_ops, + .param = { + .type = USBHS_TYPE_RCAR_GEN3_WITH_PLL, + .has_usb_dmac = 1, + .pipe_configs = usbhsc_new_pipe, + .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), + } +}; + +static const struct usbhs_of_data rza1_data = { + .platform_callback = &usbhs_rza1_ops, + .param = { + .type = USBHS_TYPE_RZA1, + .pipe_configs = usbhsc_new_pipe, + .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), + } +}; + /* * platform functions */ static const struct of_device_id usbhs_of_match[] = { { .compatible = "renesas,usbhs-r8a774c0", - .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL, + .data = &rcar_gen3_with_pll_data, }, { .compatible = "renesas,usbhs-r8a7790", - .data = (void *)USBHS_TYPE_RCAR_GEN2, + .data = &rcar_gen2_data, }, { .compatible = "renesas,usbhs-r8a7791", - .data = (void *)USBHS_TYPE_RCAR_GEN2, + .data = &rcar_gen2_data, }, { .compatible = "renesas,usbhs-r8a7794", - .data = (void *)USBHS_TYPE_RCAR_GEN2, + .data = &rcar_gen2_data, }, { .compatible = "renesas,usbhs-r8a7795", - .data = (void *)USBHS_TYPE_RCAR_GEN3, + .data = &rcar_gen3_data, }, { .compatible = "renesas,usbhs-r8a7796", - .data = (void *)USBHS_TYPE_RCAR_GEN3, + .data = &rcar_gen3_data, }, { .compatible = "renesas,usbhs-r8a77990", - .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL, + .data = &rcar_gen3_with_pll_data, }, { .compatible = "renesas,usbhs-r8a77995", - .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL, + .data = &rcar_gen3_with_pll_data, }, { .compatible = "renesas,rcar-gen2-usbhs", - .data = (void *)USBHS_TYPE_RCAR_GEN2, + .data = &rcar_gen2_data, }, { .compatible = "renesas,rcar-gen3-usbhs", - .data = (void *)USBHS_TYPE_RCAR_GEN3, + .data = &rcar_gen3_data, }, { .compatible = "renesas,rza1-usbhs", - .data = (void *)USBHS_TYPE_RZA1, + .data = &rza1_data, }, { }, }; @@ -591,6 +630,7 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) { struct renesas_usbhs_platform_info *info; struct renesas_usbhs_driver_param *dparam; + const struct usbhs_of_data *data; u32 tmp; int gpio; @@ -598,8 +638,15 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) if (!info) return NULL; + data = of_device_get_match_data(dev); + if (!data) + return NULL; + dparam = &info->driver_param; - dparam->type = (uintptr_t)of_device_get_match_data(dev); + memcpy(dparam, &data->param, sizeof(data->param)); + memcpy(&info->platform_callback, data->platform_callback, + sizeof(*data->platform_callback)); + if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp)) dparam->buswait_bwait = tmp; gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0, @@ -607,19 +654,6 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) if (gpio > 0) dparam->enable_gpio = gpio; - if (dparam->type == USBHS_TYPE_RCAR_GEN2 || - dparam->type == USBHS_TYPE_RCAR_GEN3 || - dparam->type == USBHS_TYPE_RCAR_GEN3_WITH_PLL) { - dparam->has_usb_dmac = 1; - dparam->pipe_configs = usbhsc_new_pipe; - dparam->pipe_size = ARRAY_SIZE(usbhsc_new_pipe); - } - - if (dparam->type == USBHS_TYPE_RZA1) { - dparam->pipe_configs = usbhsc_new_pipe; - dparam->pipe_size = ARRAY_SIZE(usbhsc_new_pipe); - } - return info; } @@ -676,29 +710,13 @@ static int usbhs_probe(struct platform_device *pdev) &info->driver_param, sizeof(struct renesas_usbhs_driver_param)); - switch (priv->dparam.type) { - case USBHS_TYPE_RCAR_GEN2: - priv->pfunc = usbhs_rcar2_ops; - break; - case USBHS_TYPE_RCAR_GEN3: - priv->pfunc = usbhs_rcar3_ops; - break; - case USBHS_TYPE_RCAR_GEN3_WITH_PLL: - priv->pfunc = usbhs_rcar3_with_pll_ops; - break; - case USBHS_TYPE_RZA1: - priv->pfunc = usbhs_rza1_ops; - break; - default: - if (!info->platform_callback.get_id) { - dev_err(&pdev->dev, "no platform callbacks"); - return -EINVAL; - } - memcpy(&priv->pfunc, - &info->platform_callback, - sizeof(struct renesas_usbhs_platform_callback)); - break; + if (!info->platform_callback.get_id) { + dev_err(&pdev->dev, "no platform callbacks"); + return -EINVAL; } + memcpy(&priv->pfunc, + &info->platform_callback, + sizeof(struct renesas_usbhs_platform_callback)); /* set driver callback functions for platform */ dfunc = &info->driver_callback; diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h index 3777af848a35..de1a6638bf68 100644 --- a/drivers/usb/renesas_usbhs/common.h +++ b/drivers/usb/renesas_usbhs/common.h @@ -282,6 +282,11 @@ struct usbhs_priv { struct clk *clks[2]; }; +struct usbhs_of_data { + const struct renesas_usbhs_platform_callback *platform_callback; + const struct renesas_usbhs_driver_param param; +}; + /* * common */ -- cgit v1.2.3 From d991f855cb4f84c638e2016818259720ceed4191 Mon Sep 17 00:00:00 2001 From: Bartlomiej Zolnierkiewicz Date: Mon, 20 May 2019 16:14:33 +0200 Subject: usb: remove redundant 'default n' from Kconfig-s 'default n' is the default value for any bool or tristate Kconfig setting so there is no need to write it explicitly. Also since commit f467c5640c29 ("kconfig: only write '# CONFIG_FOO is not set' for visible symbols") the Kconfig behavior is the same regardless of 'default n' being present or not: ... One side effect of (and the main motivation for) this change is making the following two definitions behave exactly the same: config FOO bool config FOO bool default n With this change, neither of these will generate a '# CONFIG_FOO is not set' line (assuming FOO isn't selected/implied). That might make it clearer to people that a bare 'default n' is redundant. ... Signed-off-by: Bartlomiej Zolnierkiewicz Signed-off-by: Greg Kroah-Hartman --- drivers/usb/atm/Kconfig | 1 - drivers/usb/core/Kconfig | 1 - drivers/usb/dwc2/Kconfig | 1 - drivers/usb/gadget/legacy/Kconfig | 2 -- drivers/usb/host/Kconfig | 5 ----- drivers/usb/renesas_usbhs/Kconfig | 1 - 6 files changed, 11 deletions(-) diff --git a/drivers/usb/atm/Kconfig b/drivers/usb/atm/Kconfig index 989aaa3b080d..3d958a1a1a71 100644 --- a/drivers/usb/atm/Kconfig +++ b/drivers/usb/atm/Kconfig @@ -7,7 +7,6 @@ menuconfig USB_ATM tristate "USB DSL modem support" depends on ATM select CRC32 - default n help Say Y here if you want to connect a USB Digital Subscriber Line (DSL) modem to your computer's USB port. You will then need to choose your diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig index bdb6bd0b63a6..ecaacc8ed311 100644 --- a/drivers/usb/core/Kconfig +++ b/drivers/usb/core/Kconfig @@ -45,7 +45,6 @@ config USB_DYNAMIC_MINORS config USB_OTG bool "OTG support" depends on PM - default n help The most notable feature of USB OTG is support for a "Dual-Role" device, which can act as either a device diff --git a/drivers/usb/dwc2/Kconfig b/drivers/usb/dwc2/Kconfig index 68d095ae2865..16e1aa304edc 100644 --- a/drivers/usb/dwc2/Kconfig +++ b/drivers/usb/dwc2/Kconfig @@ -58,7 +58,6 @@ config USB_DWC2_PCI tristate "DWC2 PCI" depends on USB_PCI depends on USB_GADGET || !USB_GADGET - default n select NOP_USB_XCEIV help The Designware USB2.0 PCI interface module for controllers diff --git a/drivers/usb/gadget/legacy/Kconfig b/drivers/usb/gadget/legacy/Kconfig index d7c9e4fca895..94fc3c462930 100644 --- a/drivers/usb/gadget/legacy/Kconfig +++ b/drivers/usb/gadget/legacy/Kconfig @@ -153,7 +153,6 @@ config USB_ETH_EEM depends on USB_ETH select USB_LIBCOMPOSITE select USB_F_EEM - default n help CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM and therefore can be supported by more hardware. Technically ECM and @@ -419,7 +418,6 @@ config USB_G_MULTI_RNDIS config USB_G_MULTI_CDC bool "CDC Ethernet + CDC Serial + Storage configuration" depends on USB_G_MULTI - default n select USB_F_ECM help This option enables a configuration with CDC Ethernet (ECM), CDC diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index d809671c5fea..fb3406ea8592 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -161,7 +161,6 @@ config USB_EHCI_PCI config USB_EHCI_HCD_PMC_MSP tristate "EHCI support for on-chip PMC MSP71xx USB controller" depends on MSP_HAS_USB - default n select USB_EHCI_BIG_ENDIAN_DESC select USB_EHCI_BIG_ENDIAN_MMIO ---help--- @@ -308,7 +307,6 @@ config USB_CNS3XXX_EHCI config USB_EHCI_HCD_PLATFORM tristate "Generic EHCI driver for a platform device" - default n ---help--- Adds an EHCI host driver for a generic platform device, which provides a memory space and an irq. @@ -318,7 +316,6 @@ config USB_EHCI_HCD_PLATFORM config USB_OCTEON_EHCI bool "Octeon on-chip EHCI support (DEPRECATED)" depends on CAVIUM_OCTEON_SOC - default n select USB_EHCI_BIG_ENDIAN_MMIO if CPU_BIG_ENDIAN select USB_EHCI_HCD_PLATFORM help @@ -526,7 +523,6 @@ config USB_OHCI_HCD_SSB depends on (SSB = y || SSB = USB_OHCI_HCD) select USB_HCD_SSB select USB_OHCI_HCD_PLATFORM - default n ---help--- This option is deprecated now and the driver was removed, use USB_HCD_SSB and USB_OHCI_HCD_PLATFORM instead. @@ -569,7 +565,6 @@ config USB_CNS3XXX_OHCI config USB_OHCI_HCD_PLATFORM tristate "Generic OHCI driver for a platform device" - default n ---help--- Adds an OHCI host driver for a generic platform device, which provides a memory space and an irq. diff --git a/drivers/usb/renesas_usbhs/Kconfig b/drivers/usb/renesas_usbhs/Kconfig index 7fdbff23ae8b..d6b3fef3e55b 100644 --- a/drivers/usb/renesas_usbhs/Kconfig +++ b/drivers/usb/renesas_usbhs/Kconfig @@ -8,7 +8,6 @@ config USB_RENESAS_USBHS depends on USB_GADGET depends on ARCH_RENESAS || SUPERH || COMPILE_TEST depends on EXTCON || !EXTCON # if EXTCON=m, USBHS cannot be built-in - default n help Renesas USBHS is a discrete USB host and peripheral controller chip that supports both full and high speed USB 2.0 data transfers. -- cgit v1.2.3 From fea3af5e0358b014c653561109c11ebd3ecdbff2 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Tue, 14 May 2019 14:38:31 -0700 Subject: usb: core: hub: Enable/disable U1/U2 in configured state SET_FEATURE(U1/U2_ENABLE) and CLEAR_FEATURE(U1/U2) only apply while the device is in configured state. Add proper check in usb_disable_lpm() and usb_enable_lpm() for enabling/disabling device-initiated U1/U2. Signed-off-by: Thinh Nguyen Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hub.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 2f94568ba385..026b652d4f38 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -4139,7 +4139,7 @@ int usb_disable_lpm(struct usb_device *udev) if (!udev || !udev->parent || udev->speed < USB_SPEED_SUPER || !udev->lpm_capable || - udev->state < USB_STATE_DEFAULT) + udev->state < USB_STATE_CONFIGURED) return 0; hcd = bus_to_hcd(udev->bus); @@ -4198,7 +4198,7 @@ void usb_enable_lpm(struct usb_device *udev) if (!udev || !udev->parent || udev->speed < USB_SPEED_SUPER || !udev->lpm_capable || - udev->state < USB_STATE_DEFAULT) + udev->state < USB_STATE_CONFIGURED) return; udev->lpm_disable_count--; -- cgit v1.2.3 From 561759292774707b71ee61aecc07724905bb7ef1 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Tue, 14 May 2019 14:38:38 -0700 Subject: usb: core: hub: Disable hub-initiated U1/U2 If the device rejects the control transfer to enable device-initiated U1/U2 entry, then the device will not initiate U1/U2 transition. To improve the performance, the downstream port should not initate transition to U1/U2 to avoid the delay from the device link command response (no packet can be transmitted while waiting for a response from the device). If the device has some quirks and does not implement U1/U2, it may reject all the link state change requests, and the downstream port may resend and flood the bus with more requests. This will affect the device performance even further. This patch disables the hub-initated U1/U2 if the device-initiated U1/U2 entry fails. Reference: USB 3.2 spec 7.2.4.2.3 Signed-off-by: Thinh Nguyen Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hub.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 026b652d4f38..572e8c26a129 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -3999,6 +3999,9 @@ static int usb_set_lpm_timeout(struct usb_device *udev, * control transfers to set the hub timeout or enable device-initiated U1/U2 * will be successful. * + * If the control transfer to enable device-initiated U1/U2 entry fails, then + * hub-initiated U1/U2 will be disabled. + * * If we cannot set the parent hub U1/U2 timeout, we attempt to let the xHCI * driver know about it. If that call fails, it should be harmless, and just * take up more slightly more bus bandwidth for unnecessary U1/U2 exit latency. @@ -4053,23 +4056,24 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, * host know that this link state won't be enabled. */ hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); - } else { - /* Only a configured device will accept the Set Feature - * U1/U2_ENABLE - */ - if (udev->actconfig) - usb_set_device_initiated_lpm(udev, state, true); + return; + } - /* As soon as usb_set_lpm_timeout(timeout) returns 0, the - * hub-initiated LPM is enabled. Thus, LPM is enabled no - * matter the result of usb_set_device_initiated_lpm(). - * The only difference is whether device is able to initiate - * LPM. - */ + /* Only a configured device will accept the Set Feature + * U1/U2_ENABLE + */ + if (udev->actconfig && + usb_set_device_initiated_lpm(udev, state, true) == 0) { if (state == USB3_LPM_U1) udev->usb3_lpm_u1_enabled = 1; else if (state == USB3_LPM_U2) udev->usb3_lpm_u2_enabled = 1; + } else { + /* Don't request U1/U2 entry if the device + * cannot transition to U1/U2. + */ + usb_set_lpm_timeout(udev, state, 0); + hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); } } -- cgit v1.2.3 From 804898e8bc43080c9194ae7e1807bf0e995bad73 Mon Sep 17 00:00:00 2001 From: Chris Brandt Date: Wed, 15 May 2019 10:20:39 -0500 Subject: dt-bindings: rcar-gen3-phy-usb2: Document dr_mode Document the optional dr_mode property Signed-off-by: Chris Brandt Reviewed-by: Rob Herring Reviewed-by: Yoshihiro Shimoda Reviewed-by: Simon Horman Signed-off-by: Greg Kroah-Hartman --- Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt index d46188f450bf..64afd086e606 100644 --- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt @@ -46,6 +46,9 @@ channel as USB OTG: regulator will be managed during the PHY power on/off sequence. - renesas,no-otg-pins: boolean, specify when a board does not provide proper otg pins. +- dr_mode: string, indicates the working mode for the PHY. Can be "host", + "peripheral", or "otg". Should be set if otg controller is not used. + Example (R-Car H3): -- cgit v1.2.3 From b051c93746543385f398b6b8002a51e9d43143a6 Mon Sep 17 00:00:00 2001 From: Chris Brandt Date: Wed, 15 May 2019 10:20:40 -0500 Subject: dt-bindings: rcar-gen3-phy-usb2: Add r7s9210 support Document RZ/A2 (R7S9210) SoC bindings. Signed-off-by: Chris Brandt Reviewed-by: Rob Herring Reviewed-by: Yoshihiro Shimoda Reviewed-by: Simon Horman Signed-off-by: Greg Kroah-Hartman --- Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt index 64afd086e606..503a8cfb3184 100644 --- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt @@ -1,10 +1,12 @@ * Renesas R-Car generation 3 USB 2.0 PHY This file provides information on what the device node for the R-Car generation -3, RZ/G1C and RZ/G2 USB 2.0 PHY contain. +3, RZ/G1C, RZ/G2 and RZ/A2 USB 2.0 PHY contain. Required properties: -- compatible: "renesas,usb2-phy-r8a77470" if the device is a part of an R8A77470 +- compatible: "renesas,usb2-phy-r7s9210" if the device is a part of an R7S9210 + SoC. + "renesas,usb2-phy-r8a77470" if the device is a part of an R8A77470 SoC. "renesas,usb2-phy-r8a774a1" if the device is a part of an R8A774A1 SoC. @@ -20,8 +22,8 @@ Required properties: R8A77990 SoC. "renesas,usb2-phy-r8a77995" if the device is a part of an R8A77995 SoC. - "renesas,rcar-gen3-usb2-phy" for a generic R-Car Gen3 or RZ/G2 - compatible device. + "renesas,rcar-gen3-usb2-phy" for a generic R-Car Gen3, RZ/G2 or + RZ/A2 compatible device. When compatible with the generic version, nodes must list the SoC-specific version corresponding to the platform first -- cgit v1.2.3 From 97a7968448cb0ef5c15e3d395746b108b1a55556 Mon Sep 17 00:00:00 2001 From: Chris Brandt Date: Wed, 15 May 2019 10:20:41 -0500 Subject: usb: renesas_usbhs: move flags to param Move options from 'flags' field in private structure to param structure where other options are already being kept. Signed-off-by: Chris Brandt Reviewed-by: Yoshihiro Shimoda Reviewed-by: Simon Horman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 23 +++++++---------------- drivers/usb/renesas_usbhs/common.h | 2 -- include/linux/usb/renesas_usbhs.h | 1 + 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 0ca89de7f842..1de7a44f3415 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -43,15 +43,6 @@ * | .... | +-----------+ */ - -#define USBHSF_RUNTIME_PWCTRL (1 << 0) - -/* status */ -#define usbhsc_flags_init(p) do {(p)->flags = 0; } while (0) -#define usbhsc_flags_set(p, b) ((p)->flags |= (b)) -#define usbhsc_flags_clr(p, b) ((p)->flags &= ~(b)) -#define usbhsc_flags_has(p, b) ((p)->flags & (b)) - /* * platform call back * @@ -479,7 +470,7 @@ static void usbhsc_hotplug(struct usbhs_priv *priv) dev_dbg(&pdev->dev, "%s enable\n", __func__); /* power on */ - if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) + if (usbhs_get_dparam(priv, runtime_pwctrl)) usbhsc_power_ctrl(priv, enable); /* bus init */ @@ -499,7 +490,7 @@ static void usbhsc_hotplug(struct usbhs_priv *priv) usbhsc_bus_init(priv); /* power off */ - if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) + if (usbhs_get_dparam(priv, runtime_pwctrl)) usbhsc_power_ctrl(priv, enable); usbhs_mod_change(priv, -1); @@ -733,7 +724,7 @@ static int usbhs_probe(struct platform_device *pdev) /* FIXME */ /* runtime power control ? */ if (priv->pfunc.get_vbus) - usbhsc_flags_set(priv, USBHSF_RUNTIME_PWCTRL); + usbhs_get_dparam(priv, runtime_pwctrl) = 1; /* * priv settings @@ -807,7 +798,7 @@ static int usbhs_probe(struct platform_device *pdev) /* power control */ pm_runtime_enable(&pdev->dev); - if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) { + if (!usbhs_get_dparam(priv, runtime_pwctrl)) { usbhsc_power_ctrl(priv, 1); usbhs_mod_autonomy_mode(priv); } @@ -848,7 +839,7 @@ static int usbhs_remove(struct platform_device *pdev) dfunc->notify_hotplug = NULL; /* power off */ - if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) + if (!usbhs_get_dparam(priv, runtime_pwctrl)) usbhsc_power_ctrl(priv, 0); pm_runtime_disable(&pdev->dev); @@ -873,7 +864,7 @@ static __maybe_unused int usbhsc_suspend(struct device *dev) usbhs_mod_change(priv, -1); } - if (mod || !usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) + if (mod || !usbhs_get_dparam(priv, runtime_pwctrl)) usbhsc_power_ctrl(priv, 0); return 0; @@ -884,7 +875,7 @@ static __maybe_unused int usbhsc_resume(struct device *dev) struct usbhs_priv *priv = dev_get_drvdata(dev); struct platform_device *pdev = usbhs_priv_to_pdev(priv); - if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) { + if (!usbhs_get_dparam(priv, runtime_pwctrl)) { usbhsc_power_ctrl(priv, 1); usbhs_mod_autonomy_mode(priv); } diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h index de1a6638bf68..1fbffb7bbc8f 100644 --- a/drivers/usb/renesas_usbhs/common.h +++ b/drivers/usb/renesas_usbhs/common.h @@ -260,8 +260,6 @@ struct usbhs_priv { spinlock_t lock; - u32 flags; - /* * module control */ diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index 53924f8e840c..17fae6e504cc 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h @@ -189,6 +189,7 @@ struct renesas_usbhs_driver_param { u32 has_otg:1; /* for controlling PWEN/EXTLP */ u32 has_sudmac:1; /* for SUDMAC */ u32 has_usb_dmac:1; /* for USB-DMAC */ + u32 runtime_pwctrl:1; #define USBHS_USB_DMAC_XFER_SIZE 32 /* hardcode the xfer size */ }; -- cgit v1.2.3 From 2195e3af9079ea067079e98446ea6a457c81a98c Mon Sep 17 00:00:00 2001 From: Chris Brandt Date: Wed, 15 May 2019 10:20:42 -0500 Subject: usb: renesas_usbhs: add support for CNEN bit For some SoC, CNEN must be set for USB Device mode operation. Signed-off-by: Chris Brandt Reviewed-by: Yoshihiro Shimoda Reviewed-by: Simon Horman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 6 ++++++ drivers/usb/renesas_usbhs/common.h | 1 + include/linux/usb/renesas_usbhs.h | 1 + 3 files changed, 8 insertions(+) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 1de7a44f3415..734fb4e542c5 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -114,6 +114,12 @@ void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable) u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; u16 val = HSE | USBE; + /* CNEN bit is required for function operation */ + if (usbhs_get_dparam(priv, has_cnen)) { + mask |= CNEN; + val |= CNEN; + } + /* * if enable * diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h index 1fbffb7bbc8f..de74ebd1a347 100644 --- a/drivers/usb/renesas_usbhs/common.h +++ b/drivers/usb/renesas_usbhs/common.h @@ -104,6 +104,7 @@ struct usbhs_priv; /* SYSCFG */ #define SCKE (1 << 10) /* USB Module Clock Enable */ +#define CNEN (1 << 8) /* Single-ended receiver operation Enable */ #define HSE (1 << 7) /* High-Speed Operation Enable */ #define DCFM (1 << 6) /* Controller Function Select */ #define DRPD (1 << 5) /* D+ Line/D- Line Resistance Control */ diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index 17fae6e504cc..9097a38fcda8 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h @@ -190,6 +190,7 @@ struct renesas_usbhs_driver_param { u32 has_sudmac:1; /* for SUDMAC */ u32 has_usb_dmac:1; /* for USB-DMAC */ u32 runtime_pwctrl:1; + u32 has_cnen:1; #define USBHS_USB_DMAC_XFER_SIZE 32 /* hardcode the xfer size */ }; -- cgit v1.2.3 From f756066990607dbe8ea5579c925b48e646891f3e Mon Sep 17 00:00:00 2001 From: Chris Brandt Date: Wed, 15 May 2019 10:20:43 -0500 Subject: usb: renesas_usbhs: support byte addressable CFIFO Some SoC have a CFIFO register that is byte addressable. This means when the CFIFO access is set to 32-bit, you can write 8-bit values to addresses CFIFO+0, CFIFO+1, CFIFO+2, CFIFO+3. Signed-off-by: Chris Brandt Reviewed-by: Yoshihiro Shimoda Reviewed-by: Simon Horman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/fifo.c | 9 +++++++-- include/linux/usb/renesas_usbhs.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c index 39fa2fc1b8b7..452b456ac24e 100644 --- a/drivers/usb/renesas_usbhs/fifo.c +++ b/drivers/usb/renesas_usbhs/fifo.c @@ -543,8 +543,13 @@ static int usbhsf_pio_try_push(struct usbhs_pkt *pkt, int *is_done) } /* the rest operation */ - for (i = 0; i < len; i++) - iowrite8(buf[i], addr + (0x03 - (i & 0x03))); + if (usbhs_get_dparam(priv, cfifo_byte_addr)) { + for (i = 0; i < len; i++) + iowrite8(buf[i], addr + (i & 0x03)); + } else { + for (i = 0; i < len; i++) + iowrite8(buf[i], addr + (0x03 - (i & 0x03))); + } /* * variable update diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index 9097a38fcda8..87043fd21d54 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h @@ -191,6 +191,7 @@ struct renesas_usbhs_driver_param { u32 has_usb_dmac:1; /* for USB-DMAC */ u32 runtime_pwctrl:1; u32 has_cnen:1; + u32 cfifo_byte_addr:1; /* CFIFO is byte addressable */ #define USBHS_USB_DMAC_XFER_SIZE 32 /* hardcode the xfer size */ }; -- cgit v1.2.3 From b69dce6341053cd51f3692a2ab3825140fad6ab8 Mon Sep 17 00:00:00 2001 From: Chris Brandt Date: Wed, 15 May 2019 10:20:44 -0500 Subject: usb: renesas_usbhs: Add support for RZ/A2 The RZ/A2 is similar to the R-Car Gen3 with some small differences. Signed-off-by: Chris Brandt Reviewed-by: Simon Horman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/Makefile | 2 +- drivers/usb/renesas_usbhs/common.c | 15 ++++++++ drivers/usb/renesas_usbhs/rza.h | 1 + drivers/usb/renesas_usbhs/rza2.c | 72 ++++++++++++++++++++++++++++++++++++++ include/linux/usb/renesas_usbhs.h | 1 + 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/renesas_usbhs/rza2.c diff --git a/drivers/usb/renesas_usbhs/Makefile b/drivers/usb/renesas_usbhs/Makefile index 5c5b51bb48ef..a1fed56b0957 100644 --- a/drivers/usb/renesas_usbhs/Makefile +++ b/drivers/usb/renesas_usbhs/Makefile @@ -5,7 +5,7 @@ obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs.o -renesas_usbhs-y := common.o mod.o pipe.o fifo.o rcar2.o rcar3.o rza.o +renesas_usbhs-y := common.o mod.o pipe.o fifo.o rcar2.o rcar3.o rza.o rza2.o ifneq ($(CONFIG_USB_RENESAS_USBHS_HCD),) renesas_usbhs-y += mod_host.o diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 734fb4e542c5..c7c9c5d75a56 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -571,6 +571,17 @@ static const struct usbhs_of_data rza1_data = { } }; +static const struct usbhs_of_data rza2_data = { + .platform_callback = &usbhs_rza2_ops, + .param = { + .type = USBHS_TYPE_RZA2, + .has_cnen = 1, + .cfifo_byte_addr = 1, + .pipe_configs = usbhsc_new_pipe, + .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), + } +}; + /* * platform functions */ @@ -619,6 +630,10 @@ static const struct of_device_id usbhs_of_match[] = { .compatible = "renesas,rza1-usbhs", .data = &rza1_data, }, + { + .compatible = "renesas,rza2-usbhs", + .data = &rza2_data, + }, { }, }; MODULE_DEVICE_TABLE(of, usbhs_of_match); diff --git a/drivers/usb/renesas_usbhs/rza.h b/drivers/usb/renesas_usbhs/rza.h index ca917ca54f6d..073a53d1d442 100644 --- a/drivers/usb/renesas_usbhs/rza.h +++ b/drivers/usb/renesas_usbhs/rza.h @@ -2,3 +2,4 @@ #include "common.h" extern const struct renesas_usbhs_platform_callback usbhs_rza1_ops; +extern const struct renesas_usbhs_platform_callback usbhs_rza2_ops; diff --git a/drivers/usb/renesas_usbhs/rza2.c b/drivers/usb/renesas_usbhs/rza2.c new file mode 100644 index 000000000000..9d8551f93533 --- /dev/null +++ b/drivers/usb/renesas_usbhs/rza2.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Renesas USB driver RZ/A2 initialization and power control + * + * Copyright (C) 2019 Chris Brandt + * Copyright (C) 2019 Renesas Electronics Corporation + */ + +#include +#include +#include +#include +#include "common.h" +#include "rza.h" + +static int usbhs_rza2_hardware_init(struct platform_device *pdev) +{ + struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); + struct phy *phy = phy_get(&pdev->dev, "usb"); + + if (IS_ERR(phy)) + return PTR_ERR(phy); + + priv->phy = phy; + return 0; +} + +static int usbhs_rza2_hardware_exit(struct platform_device *pdev) +{ + struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); + + phy_put(priv->phy); + priv->phy = NULL; + + return 0; +} + +static int usbhs_rza2_power_ctrl(struct platform_device *pdev, + void __iomem *base, int enable) +{ + struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); + int retval = 0; + + if (!priv->phy) + return -ENODEV; + + if (enable) { + retval = phy_init(priv->phy); + usbhs_bset(priv, SUSPMODE, SUSPM, SUSPM); + udelay(100); /* Wait for PLL to become stable */ + if (!retval) + retval = phy_power_on(priv->phy); + } else { + usbhs_bset(priv, SUSPMODE, SUSPM, 0); + phy_power_off(priv->phy); + phy_exit(priv->phy); + } + + return retval; +} + +static int usbhs_rza2_get_id(struct platform_device *pdev) +{ + return USBHS_GADGET; +} + +const struct renesas_usbhs_platform_callback usbhs_rza2_ops = { + .hardware_init = usbhs_rza2_hardware_init, + .hardware_exit = usbhs_rza2_hardware_exit, + .power_ctrl = usbhs_rza2_power_ctrl, + .get_id = usbhs_rza2_get_id, +}; diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index 87043fd21d54..3f53043fb56b 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h @@ -199,6 +199,7 @@ struct renesas_usbhs_driver_param { #define USBHS_TYPE_RCAR_GEN3 2 #define USBHS_TYPE_RCAR_GEN3_WITH_PLL 3 #define USBHS_TYPE_RZA1 4 +#define USBHS_TYPE_RZA2 5 /* * option: -- cgit v1.2.3 From 6e9aed4ed4ca129510fcb1af495391d4717246d6 Mon Sep 17 00:00:00 2001 From: Chris Brandt Date: Wed, 15 May 2019 10:20:45 -0500 Subject: dt-bindings: usb: renesas_usbhs: Add support for r7s9210 Add support for r7s9210 (RZ/A2M) SoC Signed-off-by: Chris Brandt Reviewed-by: Rob Herring Reviewed-by: Yoshihiro Shimoda Reviewed-by: Simon Horman Signed-off-by: Greg Kroah-Hartman --- Documentation/devicetree/bindings/usb/renesas_usbhs.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt index b8acc2a994a8..e39255ea6e4f 100644 --- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt +++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt @@ -20,9 +20,11 @@ Required properties: - "renesas,usbhs-r8a77990" for r8a77990 (R-Car E3) compatible device - "renesas,usbhs-r8a77995" for r8a77995 (R-Car D3) compatible device - "renesas,usbhs-r7s72100" for r7s72100 (RZ/A1) compatible device + - "renesas,usbhs-r7s9210" for r7s9210 (RZ/A2) compatible device - "renesas,rcar-gen2-usbhs" for R-Car Gen2 or RZ/G1 compatible devices - "renesas,rcar-gen3-usbhs" for R-Car Gen3 or RZ/G2 compatible devices - "renesas,rza1-usbhs" for RZ/A1 compatible device + - "renesas,rza2-usbhs" for RZ/A2 compatible device When compatible with the generic version, nodes must list the SoC-specific version corresponding to the platform first followed -- cgit v1.2.3 From 086ebf92aa791b6cc8805decffca7b8898d99a4e Mon Sep 17 00:00:00 2001 From: Weitao Hou Date: Thu, 23 May 2019 19:52:08 +0800 Subject: usb: avoid redundant allocation and free of memory If usb is not attached, it's unnessary to allocate, copy and free memory Signed-off-by: Weitao Hou Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/devio.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index fa783531ee88..aa17dab6c4ea 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -2130,6 +2130,9 @@ static int proc_ioctl(struct usb_dev_state *ps, struct usbdevfs_ioctl *ctl) if (ps->privileges_dropped) return -EACCES; + if (!connected(ps)) + return -ENODEV; + /* alloc buffer */ size = _IOC_SIZE(ctl->ioctl_code); if (size > 0) { @@ -2146,11 +2149,6 @@ static int proc_ioctl(struct usb_dev_state *ps, struct usbdevfs_ioctl *ctl) } } - if (!connected(ps)) { - kfree(buf); - return -ENODEV; - } - if (ps->dev->state != USB_STATE_CONFIGURED) retval = -EHOSTUNREACH; else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno))) -- cgit v1.2.3 From 96ef07f79ae8644ab9c277e3f2f4fb04a54be43d Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Wed, 1 May 2019 17:14:05 -0700 Subject: dt-bindings: phy: Add binding for Qualcomm PCIe2 PHY The Qualcomm PCIe2 PHY is a Synopsys based PCIe PHY found in a number of Qualcomm platforms, add a binding to describe this. Signed-off-by: Bjorn Andersson Reviewed-by: Rob Herring Signed-off-by: Kishon Vijay Abraham I --- .../devicetree/bindings/phy/qcom-pcie2-phy.txt | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/qcom-pcie2-phy.txt diff --git a/Documentation/devicetree/bindings/phy/qcom-pcie2-phy.txt b/Documentation/devicetree/bindings/phy/qcom-pcie2-phy.txt new file mode 100644 index 000000000000..30064253f290 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/qcom-pcie2-phy.txt @@ -0,0 +1,42 @@ +Qualcomm PCIe2 PHY controller +============================= + +The Qualcomm PCIe2 PHY is a Synopsys based phy found in a number of Qualcomm +platforms. + +Required properties: + - compatible: compatible list, should be: + "qcom,qcs404-pcie2-phy", "qcom,pcie2-phy" + + - reg: offset and length of the PHY register set. + - #phy-cells: must be 0. + + - clocks: a clock-specifier pair for the "pipe" clock + + - vdda-vp-supply: phandle to low voltage regulator + - vdda-vph-supply: phandle to high voltage regulator + + - resets: reset-specifier pairs for the "phy" and "pipe" resets + - reset-names: list of resets, should contain: + "phy" and "pipe" + + - clock-output-names: name of the outgoing clock signal from the PHY PLL + - #clock-cells: must be 0 + +Example: + phy@7786000 { + compatible = "qcom,qcs404-pcie2-phy", "qcom,pcie2-phy"; + reg = <0x07786000 0xb8>; + + clocks = <&gcc GCC_PCIE_0_PIPE_CLK>; + resets = <&gcc GCC_PCIEPHY_0_PHY_BCR>, + <&gcc GCC_PCIE_0_PIPE_ARES>; + reset-names = "phy", "pipe"; + + vdda-vp-supply = <&vreg_l3_1p05>; + vdda-vph-supply = <&vreg_l5_1p8>; + + clock-output-names = "pcie_0_pipe_clk"; + #clock-cells = <0>; + #phy-cells = <0>; + }; -- cgit v1.2.3 From 6ef72bc036bcb4c8ad5ef9bd73a71ad2e6538026 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Wed, 1 May 2019 17:14:06 -0700 Subject: phy: qcom: Add Qualcomm PCIe2 PHY driver The Qualcomm PCIe2 PHY is based on design from Synopsys and found in several different platforms where the QMP PHY isn't used. Reviewed-by: Niklas Cassel Signed-off-by: Bjorn Andersson Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/qualcomm/Kconfig | 8 + drivers/phy/qualcomm/Makefile | 1 + drivers/phy/qualcomm/phy-qcom-pcie2.c | 331 ++++++++++++++++++++++++++++++++++ 3 files changed, 340 insertions(+) create mode 100644 drivers/phy/qualcomm/phy-qcom-pcie2.c diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig index 32f7d34eb784..8688ce27d0a6 100644 --- a/drivers/phy/qualcomm/Kconfig +++ b/drivers/phy/qualcomm/Kconfig @@ -24,6 +24,14 @@ config PHY_QCOM_IPQ806X_SATA depends on OF select GENERIC_PHY +config PHY_QCOM_PCIE2 + tristate "Qualcomm PCIe Gen2 PHY Driver" + depends on OF && COMMON_CLK && (ARCH_QCOM || COMPILE_TEST) + select GENERIC_PHY + help + Enable this to support the Qualcomm PCIe PHY, used with the Synopsys + based PCIe controller. + config PHY_QCOM_QMP tristate "Qualcomm QMP PHY Driver" depends on OF && COMMON_CLK && (ARCH_QCOM || COMPILE_TEST) diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile index c56efd3af205..283251d6a5d9 100644 --- a/drivers/phy/qualcomm/Makefile +++ b/drivers/phy/qualcomm/Makefile @@ -2,6 +2,7 @@ obj-$(CONFIG_PHY_ATH79_USB) += phy-ath79-usb.o obj-$(CONFIG_PHY_QCOM_APQ8064_SATA) += phy-qcom-apq8064-sata.o obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o +obj-$(CONFIG_PHY_QCOM_PCIE2) += phy-qcom-pcie2.o obj-$(CONFIG_PHY_QCOM_QMP) += phy-qcom-qmp.o obj-$(CONFIG_PHY_QCOM_QUSB2) += phy-qcom-qusb2.o obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs.o diff --git a/drivers/phy/qualcomm/phy-qcom-pcie2.c b/drivers/phy/qualcomm/phy-qcom-pcie2.c new file mode 100644 index 000000000000..9dba3594e6d9 --- /dev/null +++ b/drivers/phy/qualcomm/phy-qcom-pcie2.c @@ -0,0 +1,331 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. + * Copyright (c) 2019, Linaro Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define PCIE20_PARF_PHY_STTS 0x3c +#define PCIE2_PHY_RESET_CTRL 0x44 +#define PCIE20_PARF_PHY_REFCLK_CTRL2 0xa0 +#define PCIE20_PARF_PHY_REFCLK_CTRL3 0xa4 +#define PCIE20_PARF_PCS_SWING_CTRL1 0x88 +#define PCIE20_PARF_PCS_SWING_CTRL2 0x8c +#define PCIE20_PARF_PCS_DEEMPH1 0x74 +#define PCIE20_PARF_PCS_DEEMPH2 0x78 +#define PCIE20_PARF_PCS_DEEMPH3 0x7c +#define PCIE20_PARF_CONFIGBITS 0x84 +#define PCIE20_PARF_PHY_CTRL3 0x94 +#define PCIE20_PARF_PCS_CTRL 0x80 + +#define TX_AMP_VAL 120 +#define PHY_RX0_EQ_GEN1_VAL 0 +#define PHY_RX0_EQ_GEN2_VAL 4 +#define TX_DEEMPH_GEN1_VAL 24 +#define TX_DEEMPH_GEN2_3_5DB_VAL 26 +#define TX_DEEMPH_GEN2_6DB_VAL 36 +#define PHY_TX0_TERM_OFFST_VAL 0 + +struct qcom_phy { + struct device *dev; + void __iomem *base; + + struct regulator_bulk_data vregs[2]; + + struct reset_control *phy_reset; + struct reset_control *pipe_reset; + struct clk *pipe_clk; +}; + +static int qcom_pcie2_phy_init(struct phy *phy) +{ + struct qcom_phy *qphy = phy_get_drvdata(phy); + int ret; + + ret = reset_control_deassert(qphy->phy_reset); + if (ret) { + dev_err(qphy->dev, "cannot deassert pipe reset\n"); + return ret; + } + + ret = regulator_bulk_enable(ARRAY_SIZE(qphy->vregs), qphy->vregs); + if (ret) + reset_control_assert(qphy->phy_reset); + + return ret; +} + +static int qcom_pcie2_phy_power_on(struct phy *phy) +{ + struct qcom_phy *qphy = phy_get_drvdata(phy); + int ret; + u32 val; + + /* Program REF_CLK source */ + val = readl(qphy->base + PCIE20_PARF_PHY_REFCLK_CTRL2); + val &= ~BIT(1); + writel(val, qphy->base + PCIE20_PARF_PHY_REFCLK_CTRL2); + + usleep_range(1000, 2000); + + /* Don't use PAD for refclock */ + val = readl(qphy->base + PCIE20_PARF_PHY_REFCLK_CTRL2); + val &= ~BIT(0); + writel(val, qphy->base + PCIE20_PARF_PHY_REFCLK_CTRL2); + + /* Program SSP ENABLE */ + val = readl(qphy->base + PCIE20_PARF_PHY_REFCLK_CTRL3); + val |= BIT(0); + writel(val, qphy->base + PCIE20_PARF_PHY_REFCLK_CTRL3); + + usleep_range(1000, 2000); + + /* Assert Phy SW Reset */ + val = readl(qphy->base + PCIE2_PHY_RESET_CTRL); + val |= BIT(0); + writel(val, qphy->base + PCIE2_PHY_RESET_CTRL); + + /* Program Tx Amplitude */ + val = readl(qphy->base + PCIE20_PARF_PCS_SWING_CTRL1); + val &= ~0x7f; + val |= TX_AMP_VAL; + writel(val, qphy->base + PCIE20_PARF_PCS_SWING_CTRL1); + + val = readl(qphy->base + PCIE20_PARF_PCS_SWING_CTRL2); + val &= ~0x7f; + val |= TX_AMP_VAL; + writel(val, qphy->base + PCIE20_PARF_PCS_SWING_CTRL2); + + /* Program De-Emphasis */ + val = readl(qphy->base + PCIE20_PARF_PCS_DEEMPH1); + val &= ~0x3f; + val |= TX_DEEMPH_GEN2_6DB_VAL; + writel(val, qphy->base + PCIE20_PARF_PCS_DEEMPH1); + + val = readl(qphy->base + PCIE20_PARF_PCS_DEEMPH2); + val &= ~0x3f; + val |= TX_DEEMPH_GEN2_3_5DB_VAL; + writel(val, qphy->base + PCIE20_PARF_PCS_DEEMPH2); + + val = readl(qphy->base + PCIE20_PARF_PCS_DEEMPH3); + val &= ~0x3f; + val |= TX_DEEMPH_GEN1_VAL; + writel(val, qphy->base + PCIE20_PARF_PCS_DEEMPH3); + + /* Program Rx_Eq */ + val = readl(qphy->base + PCIE20_PARF_CONFIGBITS); + val &= ~0x7; + val |= PHY_RX0_EQ_GEN2_VAL; + writel(val, qphy->base + PCIE20_PARF_CONFIGBITS); + + /* Program Tx0_term_offset */ + val = readl(qphy->base + PCIE20_PARF_PHY_CTRL3); + val &= ~0x1f; + val |= PHY_TX0_TERM_OFFST_VAL; + writel(val, qphy->base + PCIE20_PARF_PHY_CTRL3); + + /* disable Tx2Rx Loopback */ + val = readl(qphy->base + PCIE20_PARF_PCS_CTRL); + val &= ~BIT(1); + writel(val, qphy->base + PCIE20_PARF_PCS_CTRL); + + /* De-assert Phy SW Reset */ + val = readl(qphy->base + PCIE2_PHY_RESET_CTRL); + val &= ~BIT(0); + writel(val, qphy->base + PCIE2_PHY_RESET_CTRL); + + usleep_range(1000, 2000); + + ret = reset_control_deassert(qphy->pipe_reset); + if (ret) { + dev_err(qphy->dev, "cannot deassert pipe reset\n"); + goto out; + } + + clk_set_rate(qphy->pipe_clk, 250000000); + + ret = clk_prepare_enable(qphy->pipe_clk); + if (ret) { + dev_err(qphy->dev, "failed to enable pipe clock\n"); + goto out; + } + + ret = readl_poll_timeout(qphy->base + PCIE20_PARF_PHY_STTS, val, + !(val & BIT(0)), 1000, 10); + if (ret) + dev_err(qphy->dev, "phy initialization failed\n"); + +out: + return ret; +} + +static int qcom_pcie2_phy_power_off(struct phy *phy) +{ + struct qcom_phy *qphy = phy_get_drvdata(phy); + u32 val; + + val = readl(qphy->base + PCIE2_PHY_RESET_CTRL); + val |= BIT(0); + writel(val, qphy->base + PCIE2_PHY_RESET_CTRL); + + clk_disable_unprepare(qphy->pipe_clk); + reset_control_assert(qphy->pipe_reset); + + return 0; +} + +static int qcom_pcie2_phy_exit(struct phy *phy) +{ + struct qcom_phy *qphy = phy_get_drvdata(phy); + + regulator_bulk_disable(ARRAY_SIZE(qphy->vregs), qphy->vregs); + reset_control_assert(qphy->phy_reset); + + return 0; +} + +static const struct phy_ops qcom_pcie2_ops = { + .init = qcom_pcie2_phy_init, + .power_on = qcom_pcie2_phy_power_on, + .power_off = qcom_pcie2_phy_power_off, + .exit = qcom_pcie2_phy_exit, + .owner = THIS_MODULE, +}; + +/* + * Register a fixed rate pipe clock. + * + * The _pipe_clksrc generated by PHY goes to the GCC that gate + * controls it. The _pipe_clk coming out of the GCC is requested + * by the PHY driver for its operations. + * We register the _pipe_clksrc here. The gcc driver takes care + * of assigning this _pipe_clksrc as parent to _pipe_clk. + * Below picture shows this relationship. + * + * +---------------+ + * | PHY block |<<---------------------------------------+ + * | | | + * | +-------+ | +-----+ | + * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+ + * clk | +-------+ | +-----+ + * +---------------+ + */ +static int phy_pipe_clksrc_register(struct qcom_phy *qphy) +{ + struct device_node *np = qphy->dev->of_node; + struct clk_fixed_rate *fixed; + struct clk_init_data init = { }; + int ret; + + ret = of_property_read_string(np, "clock-output-names", &init.name); + if (ret) { + dev_err(qphy->dev, "%s: No clock-output-names\n", np->name); + return ret; + } + + fixed = devm_kzalloc(qphy->dev, sizeof(*fixed), GFP_KERNEL); + if (!fixed) + return -ENOMEM; + + init.ops = &clk_fixed_rate_ops; + + /* controllers using QMP phys use 250MHz pipe clock interface */ + fixed->fixed_rate = 250000000; + fixed->hw.init = &init; + + return devm_clk_hw_register(qphy->dev, &fixed->hw); +} + +static int qcom_pcie2_phy_probe(struct platform_device *pdev) +{ + struct phy_provider *phy_provider; + struct qcom_phy *qphy; + struct resource *res; + struct device *dev = &pdev->dev; + struct phy *phy; + int ret; + + qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL); + if (!qphy) + return -ENOMEM; + + qphy->dev = dev; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + qphy->base = devm_ioremap_resource(dev, res); + if (IS_ERR(qphy->base)) + return PTR_ERR(qphy->base); + + ret = phy_pipe_clksrc_register(qphy); + if (ret) { + dev_err(dev, "failed to register pipe_clk\n"); + return ret; + } + + qphy->vregs[0].supply = "vdda-vp"; + qphy->vregs[1].supply = "vdda-vph"; + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(qphy->vregs), qphy->vregs); + if (ret < 0) + return ret; + + qphy->pipe_clk = devm_clk_get(dev, NULL); + if (IS_ERR(qphy->pipe_clk)) { + dev_err(dev, "failed to acquire pipe clock\n"); + return PTR_ERR(qphy->pipe_clk); + } + + qphy->phy_reset = devm_reset_control_get_exclusive(dev, "phy"); + if (IS_ERR(qphy->phy_reset)) { + dev_err(dev, "failed to acquire phy reset\n"); + return PTR_ERR(qphy->phy_reset); + } + + qphy->pipe_reset = devm_reset_control_get_exclusive(dev, "pipe"); + if (IS_ERR(qphy->pipe_reset)) { + dev_err(dev, "failed to acquire pipe reset\n"); + return PTR_ERR(qphy->pipe_reset); + } + + phy = devm_phy_create(dev, dev->of_node, &qcom_pcie2_ops); + if (IS_ERR(phy)) { + dev_err(dev, "failed to create phy\n"); + return PTR_ERR(phy); + } + + phy_set_drvdata(phy, qphy); + + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + if (IS_ERR(phy_provider)) + dev_err(dev, "failed to register phy provider\n"); + + return PTR_ERR_OR_ZERO(phy_provider); +} + +static const struct of_device_id qcom_pcie2_phy_match_table[] = { + { .compatible = "qcom,pcie2-phy" }, + {} +}; +MODULE_DEVICE_TABLE(of, qcom_pcie2_phy_match_table); + +static struct platform_driver qcom_pcie2_phy_driver = { + .probe = qcom_pcie2_phy_probe, + .driver = { + .name = "phy-qcom-pcie2", + .of_match_table = qcom_pcie2_phy_match_table, + }, +}; + +module_platform_driver(qcom_pcie2_phy_driver); + +MODULE_DESCRIPTION("Qualcomm PCIe PHY driver"); +MODULE_LICENSE("GPL v2"); -- cgit v1.2.3 From d98010817a26eba8d4d1e8a639e0b7d7f042308a Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Fri, 31 May 2019 13:05:59 +0100 Subject: phy: qcom-qusb2: fix missing assignment of ret when calling clk_prepare_enable The error return from the call to clk_prepare_enable is not being assigned to variable ret even though ret is being used to check if the call failed. Fix this by adding in the missing assignment. Addresses-Coverity: ("Logically dead code") Fixes: 891a96f65ac3 ("phy: qcom-qusb2: Add support for runtime PM") Signed-off-by: Colin Ian King Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/qualcomm/phy-qcom-qusb2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c index 1cbf1d6f28ce..bf94a52d3087 100644 --- a/drivers/phy/qualcomm/phy-qcom-qusb2.c +++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c @@ -564,7 +564,7 @@ static int __maybe_unused qusb2_phy_runtime_resume(struct device *dev) } if (!qphy->has_se_clk_scheme) { - clk_prepare_enable(qphy->ref_clk); + ret = clk_prepare_enable(qphy->ref_clk); if (ret) { dev_err(dev, "failed to enable ref clk, %d\n", ret); goto disable_ahb_clk; -- cgit v1.2.3 From 05387733ed57b6a971fc88f77cc6522eaafd46f2 Mon Sep 17 00:00:00 2001 From: YueHaibing Date: Tue, 28 May 2019 21:45:29 +0800 Subject: usb: host: ehci-st: Remove set but not used variable 'ehci' Fixes gcc '-Wunused-but-set-variable' warning: drivers/usb/host/ehci-st.c: In function st_ehci_platform_probe: drivers/usb/host/ehci-st.c:155:19: warning: variable ehci set but not used [-Wunused-but-set-variable] It is never used, so can be removed. Signed-off-by: YueHaibing Acked-by: Patrice Chotard Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-st.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/usb/host/ehci-st.c b/drivers/usb/host/ehci-st.c index dc42981047c9..ccb4e611001d 100644 --- a/drivers/usb/host/ehci-st.c +++ b/drivers/usb/host/ehci-st.c @@ -152,7 +152,6 @@ static int st_ehci_platform_probe(struct platform_device *dev) struct resource *res_mem; struct usb_ehci_pdata *pdata = &ehci_platform_defaults; struct st_ehci_platform_priv *priv; - struct ehci_hcd *ehci; int err, irq, clk = 0; if (usb_disabled()) @@ -177,7 +176,6 @@ static int st_ehci_platform_probe(struct platform_device *dev) platform_set_drvdata(dev, hcd); dev->dev.platform_data = pdata; priv = hcd_to_ehci_priv(hcd); - ehci = hcd_to_ehci(hcd); priv->phy = devm_phy_get(&dev->dev, "usb"); if (IS_ERR(priv->phy)) { -- cgit v1.2.3 From 2e5a359e4a816c3a93db18e3789b5ec739f5ee18 Mon Sep 17 00:00:00 2001 From: YueHaibing Date: Tue, 28 May 2019 21:38:49 +0800 Subject: usb: host: ohci-st: Remove set but not used variable 'ohci' Fixes gcc '-Wunused-but-set-variable' warning: drivers/usb/host/ohci-st.c: In function st_ohci_platform_probe: drivers/usb/host/ohci-st.c:135:19: warning: variable ohci set but not used [-Wunused-but-set-variable] It's never used, so can be removed. Signed-off-by: YueHaibing Acked-by: Patrice Chotard Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ohci-st.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/usb/host/ohci-st.c b/drivers/usb/host/ohci-st.c index 992807c9850a..638a92bd2cdc 100644 --- a/drivers/usb/host/ohci-st.c +++ b/drivers/usb/host/ohci-st.c @@ -132,7 +132,6 @@ static int st_ohci_platform_probe(struct platform_device *dev) struct resource *res_mem; struct usb_ohci_pdata *pdata = &ohci_platform_defaults; struct st_ohci_platform_priv *priv; - struct ohci_hcd *ohci; int err, irq, clk = 0; if (usb_disabled()) @@ -158,7 +157,6 @@ static int st_ohci_platform_probe(struct platform_device *dev) platform_set_drvdata(dev, hcd); dev->dev.platform_data = pdata; priv = hcd_to_ohci_priv(hcd); - ohci = hcd_to_ohci(hcd); priv->phy = devm_phy_get(&dev->dev, "usb"); if (IS_ERR(priv->phy)) { -- cgit v1.2.3 From 6dade7ad8876a1dee84b3e321e6bf44dd2156217 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Fri, 31 May 2019 14:53:47 +0100 Subject: usb: cdc-wdm: remove redundant assignment to rv The variable rv is assigned with a value that is never read and it is re-assigned a new value on the next statement. The assignment is redundant and can be removed. Addresses-Coverity: ("Unused value") Signed-off-by: Colin Ian King Signed-off-by: Greg Kroah-Hartman --- drivers/usb/class/cdc-wdm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index 9e9caff905d5..a7824a51f86d 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c @@ -949,7 +949,7 @@ struct usb_driver *usb_cdc_wdm_register(struct usb_interface *intf, int bufsize, int (*manage_power)(struct usb_interface *, int)) { - int rv = -EINVAL; + int rv; rv = wdm_create(intf, ep, bufsize, manage_power); if (rv < 0) -- cgit v1.2.3 From 5a1d99b11b1b1fe249581e24d95208d3671f8f14 Mon Sep 17 00:00:00 2001 From: YueHaibing Date: Tue, 28 May 2019 21:43:05 +0800 Subject: usb: ohci-s3c2410: Remove set but not used variable 'hcd' Fixes gcc '-Wunused-but-set-variable' warning: drivers/usb/host/ohci-s3c2410.c: In function s3c2410_hcd_oc: drivers/usb/host/ohci-s3c2410.c:296:18: warning: variable hcd set but not used [-Wunused-but-set-variable] It is never used, so can be removed. Signed-off-by: YueHaibing Reviewed-by: Krzysztof Kozlowski Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ohci-s3c2410.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c index 4511e27e9da8..d961097c90f0 100644 --- a/drivers/usb/host/ohci-s3c2410.c +++ b/drivers/usb/host/ohci-s3c2410.c @@ -293,7 +293,6 @@ static int ohci_s3c2410_hub_control( static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc) { struct s3c2410_hcd_port *port; - struct usb_hcd *hcd; unsigned long flags; int portno; @@ -301,7 +300,6 @@ static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc) return; port = &info->port[0]; - hcd = info->hcd; local_irq_save(flags); -- cgit v1.2.3 From 5e456a9263da2adc95d2744e2add5835f298d08d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 24 May 2019 10:30:39 +0200 Subject: USB: atm: ueagle-atm.c: fix SPDX tag to be BSD2 Thomas rightly points out that I got the BSD clause count wrong for this driver, it should be 2, not 3 based on the text in the license here, so fix that up. He also raises the question that the license text points to a v2 only license, yet the text in the header says "or later". Given that the text in the header says "or later" and all of the other USB atm drivers are licensed in that way, I am going to leave the string as-is for that mark. Reported-by: Thomas Gleixner Cc: Matthieu CASTET Cc: Stanislaw Gruszka Cc: Damien Bergamini Cc: Duncan Sands Signed-off-by: Greg Kroah-Hartman --- drivers/usb/atm/ueagle-atm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c index 2754b4ce7136..f0c622a87436 100644 --- a/drivers/usb/atm/ueagle-atm.c +++ b/drivers/usb/atm/ueagle-atm.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) +// SPDX-License-Identifier: (GPL-2.0+ OR BSD-2-Clause) /*- * Copyright (c) 2003, 2004 * Damien Bergamini . All rights reserved. -- cgit v1.2.3 From c8a93dcd0cbd341ce1b6d5e6671566d5fba76d68 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 24 May 2019 10:30:40 +0200 Subject: USB: atm: ueagle-atm.c: remove redundant license text Now that we have the correct SPDX tag for the ueagle-atm.c file, the wall of "boiler-plate" text is not needed. This is done on a quest to remove the 700+ different ways that files in the kernel describe the GPL license text. And there's unneeded stuff like the address (sometimes incorrect) for the FSF which is never needed. No copyright headers or other non-license-description text was removed. Cc: Thomas Gleixner Cc: Matthieu CASTET Cc: Stanislaw Gruszka Cc: Damien Bergamini Cc: Duncan Sands Signed-off-by: Greg Kroah-Hartman --- drivers/usb/atm/ueagle-atm.c | 46 +------------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c index f0c622a87436..8faa51b1a520 100644 --- a/drivers/usb/atm/ueagle-atm.c +++ b/drivers/usb/atm/ueagle-atm.c @@ -1,55 +1,11 @@ // SPDX-License-Identifier: (GPL-2.0+ OR BSD-2-Clause) -/*- +/* * Copyright (c) 2003, 2004 * Damien Bergamini . All rights reserved. * * Copyright (c) 2005-2007 Matthieu Castet * Copyright (c) 2005-2007 Stanislaw Gruszka * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * BSD license below: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice unmodified, this list of conditions, and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * GPL license : - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * * HISTORY : some part of the code was base on ueagle 1.3 BSD driver, * Damien Bergamini agree to put his code under a DUAL GPL/BSD license. * -- cgit v1.2.3 From 53cdff30fc333718b6470c9604636b7b6f47542a Mon Sep 17 00:00:00 2001 From: YueHaibing Date: Sat, 25 May 2019 22:38:08 +0800 Subject: USB: ohci-spear: Remove set but not used variable 'ohci' Fixes gcc '-Wunused-but-set-variable' warning: drivers/usb/host/ohci-spear.c: In function spear_ohci_hcd_drv_probe: drivers/usb/host/ohci-spear.c:38:19: warning: variable ohci set but not used [-Wunused-but-set-variable] It is never used since commit 1cc6ac59ffaa ("USB: OHCI: make ohci-spear a separate driver") Signed-off-by: YueHaibing Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ohci-spear.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/usb/host/ohci-spear.c b/drivers/usb/host/ohci-spear.c index 69fa04697793..5cc05449281c 100644 --- a/drivers/usb/host/ohci-spear.c +++ b/drivers/usb/host/ohci-spear.c @@ -35,7 +35,6 @@ static struct hc_driver __read_mostly ohci_spear_hc_driver; static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) { const struct hc_driver *driver = &ohci_spear_hc_driver; - struct ohci_hcd *ohci; struct usb_hcd *hcd = NULL; struct clk *usbh_clk; struct spear_ohci *sohci_p; @@ -85,8 +84,6 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) clk_prepare_enable(sohci_p->clk); - ohci = hcd_to_ohci(hcd); - retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0); if (retval == 0) { device_wakeup_enable(hcd->self.controller); -- cgit v1.2.3 From 8e4c5d31e9eebc0e6cc225fb8f7cd87e5446d4f2 Mon Sep 17 00:00:00 2001 From: Hariprasad Kelam Date: Sat, 25 May 2019 23:01:47 +0530 Subject: usb: ftdi-elan: fix possible condition with no effect (if == else) fix below warning reported by coccicheck ./drivers/usb/misc/ftdi-elan.c:2026:11-13: WARNING: possible condition with no effect (if == else) Signed-off-by: Hariprasad Kelam Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/ftdi-elan.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c index 257efacf3551..cdee3af33ad7 100644 --- a/drivers/usb/misc/ftdi-elan.c +++ b/drivers/usb/misc/ftdi-elan.c @@ -2023,13 +2023,6 @@ static int ftdi_elan_synchronize(struct usb_ftdi *ftdi) goto read; } else goto reset; - } else if (s1 == 0x31 && s2 == 0x60) { - if (read_stop-- > 0) { - goto read; - } else { - dev_err(&ftdi->udev->dev, "retry limit reached\n"); - continue; - } } else { if (read_stop-- > 0) { goto read; -- cgit v1.2.3 From 32adeab3e3b5bc01ebb7746600e7c734482230d7 Mon Sep 17 00:00:00 2001 From: YueHaibing Date: Wed, 29 May 2019 23:09:39 +0800 Subject: usb: phy: mv-usb: Remove set but not used variable 'phy' Fixes gcc '-Wunused-but-set-variable' warning: drivers/usb/phy/phy-mv-usb.c: In function mv_otg_work: drivers/usb/phy/phy-mv-usb.c:404:18: warning: variable phy set but not used [-Wunused-but-set-variable] It's no used since commit e47d92545c29 ("usb: move the OTG state from the USB PHY to the OTG structure") Signed-off-by: YueHaibing Signed-off-by: Greg Kroah-Hartman --- drivers/usb/phy/phy-mv-usb.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/usb/phy/phy-mv-usb.c b/drivers/usb/phy/phy-mv-usb.c index cfd9add10bf4..cf7ecdc9a9d4 100644 --- a/drivers/usb/phy/phy-mv-usb.c +++ b/drivers/usb/phy/phy-mv-usb.c @@ -401,7 +401,6 @@ static void mv_otg_update_state(struct mv_otg *mvotg) static void mv_otg_work(struct work_struct *work) { struct mv_otg *mvotg; - struct usb_phy *phy; struct usb_otg *otg; int old_state; @@ -409,7 +408,6 @@ static void mv_otg_work(struct work_struct *work) run: /* work queue is single thread, or we need spin_lock to protect */ - phy = &mvotg->phy; otg = mvotg->phy.otg; old_state = otg->state; -- cgit v1.2.3 From 4998f1efd1904dd21697aeeead270e3eb97691dd Mon Sep 17 00:00:00 2001 From: Jim Lin Date: Mon, 3 Jun 2019 18:53:43 +0800 Subject: usb: Add devaddr in struct usb_device The Clear_TT_Buffer request sent to the hub includes the address of the LS/FS child device in wValue field. usb_hub_clear_tt_buffer() uses udev->devnum to set the address wValue. This won't work for devices connected to xHC. For other host controllers udev->devnum is the same as the address of the usb device, chosen and set by usb core. With xHC the controller hardware assigns the address, and won't be the same as devnum. Here we add devaddr in "struct usb_device" for usb_hub_clear_tt_buffer() to use. Signed-off-by: Jim Lin Acked-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hub.c | 4 +++- drivers/usb/host/xhci.c | 2 ++ include/linux/usb.h | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 572e8c26a129..82cc3766cb23 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -873,7 +873,7 @@ int usb_hub_clear_tt_buffer(struct urb *urb) /* info that CLEAR_TT_BUFFER needs */ clear->tt = tt->multi ? udev->ttport : 1; clear->devinfo = usb_pipeendpoint (pipe); - clear->devinfo |= udev->devnum << 4; + clear->devinfo |= ((u16)udev->devaddr) << 4; clear->devinfo |= usb_pipecontrol(pipe) ? (USB_ENDPOINT_XFER_CONTROL << 11) : (USB_ENDPOINT_XFER_BULK << 11); @@ -2125,6 +2125,8 @@ static void update_devnum(struct usb_device *udev, int devnum) /* The address for a WUSB device is managed by wusbcore. */ if (!udev->wusb) udev->devnum = devnum; + if (!udev->devaddr) + udev->devaddr = (u8)devnum; } static void hub_free_dev(struct usb_device *udev) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 20db378a6012..4f92643e3a4c 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4125,6 +4125,8 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, /* Zero the input context control for later use */ ctrl_ctx->add_flags = 0; ctrl_ctx->drop_flags = 0; + slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); + udev->devaddr = (u8)(le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); xhci_dbg_trace(xhci, trace_xhci_dbg_address, "Internal device address = %d", diff --git a/include/linux/usb.h b/include/linux/usb.h index ae82d9d1112b..83d35d993e8c 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -578,6 +578,7 @@ struct usb3_lpm_parameters { * @bus_mA: Current available from the bus * @portnum: parent port number (origin 1) * @level: number of USB hub ancestors + * @devaddr: device address, XHCI: assigned by HW, others: same as devnum * @can_submit: URBs may be submitted * @persist_enabled: USB_PERSIST enabled for this device * @have_langid: whether string_langid is valid @@ -661,6 +662,7 @@ struct usb_device { unsigned short bus_mA; u8 portnum; u8 level; + u8 devaddr; unsigned can_submit:1; unsigned persist_enabled:1; -- cgit v1.2.3 From ef513be0a9057cc6baf5d29566aaaefa214ba344 Mon Sep 17 00:00:00 2001 From: Jim Lin Date: Mon, 3 Jun 2019 18:53:44 +0800 Subject: usb: xhci: Add Clear_TT_Buffer USB 2.0 specification chapter 11.17.5 says "as part of endpoint halt processing for full-/low-speed endpoints connected via a TT, the host software must use the Clear_TT_Buffer request to the TT to ensure that the buffer is not in the busy state". In our case, a full-speed speaker (ConferenceCam) is behind a high- speed hub (ConferenceCam Connect), sometimes once we get STALL on a request we may continue to get STALL with the folllowing requests, like Set_Interface. Here we invoke usb_hub_clear_tt_buffer() to send Clear_TT_Buffer request to the hub of the device for the following Set_Interface requests to the device to get ACK successfully. Signed-off-by: Jim Lin Acked-by: Mathias Nyman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci-ring.c | 27 ++++++++++++++++++++++++++- drivers/usb/host/xhci.c | 21 +++++++++++++++++++++ drivers/usb/host/xhci.h | 5 +++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index feffceb31e8a..a52fd96e70e9 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -399,7 +399,7 @@ void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, * stream once the endpoint is on the HW schedule. */ if ((ep_state & EP_STOP_CMD_PENDING) || (ep_state & SET_DEQ_PENDING) || - (ep_state & EP_HALTED)) + (ep_state & EP_HALTED) || (ep_state & EP_CLEARING_TT)) return; writel(DB_VALUE(ep_index, stream_id), db_addr); /* The CPU has better things to do at this point than wait for a @@ -433,6 +433,13 @@ static void ring_doorbell_for_active_rings(struct xhci_hcd *xhci, } } +void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci, + unsigned int slot_id, + unsigned int ep_index) +{ + ring_doorbell_for_active_rings(xhci, slot_id, ep_index); +} + /* Get the right ring for the given slot_id, ep_index and stream_id. * If the endpoint supports streams, boundary check the URB's stream ID. * If the endpoint doesn't support streams, return the singular endpoint ring. @@ -1794,6 +1801,23 @@ struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, return NULL; } +static void xhci_clear_hub_tt_buffer(struct xhci_hcd *xhci, struct xhci_td *td, + struct xhci_virt_ep *ep) +{ + /* + * As part of low/full-speed endpoint-halt processing + * we must clear the TT buffer (USB 2.0 specification 11.17.5). + */ + if (td->urb->dev->tt && !usb_pipeint(td->urb->pipe) && + (td->urb->dev->tt->hub != xhci_to_hcd(xhci)->self.root_hub) && + !(ep->ep_state & EP_CLEARING_TT)) { + ep->ep_state |= EP_CLEARING_TT; + td->urb->ep->hcpriv = td->urb->dev; + if (usb_hub_clear_tt_buffer(td->urb)) + ep->ep_state &= ~EP_CLEARING_TT; + } +} + static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci, unsigned int slot_id, unsigned int ep_index, unsigned int stream_id, struct xhci_td *td, @@ -1812,6 +1836,7 @@ static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci, if (reset_type == EP_HARD_RESET) { ep->ep_state |= EP_HARD_CLEAR_TOGGLE; xhci_cleanup_stalled_ring(xhci, ep_index, stream_id, td); + xhci_clear_hub_tt_buffer(xhci, td, ep); } xhci_ring_cmd_db(xhci); } diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 4f92643e3a4c..ef5702a45067 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -5163,6 +5163,26 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks) } EXPORT_SYMBOL_GPL(xhci_gen_setup); +static void xhci_clear_tt_buffer_complete(struct usb_hcd *hcd, + struct usb_host_endpoint *ep) +{ + struct xhci_hcd *xhci; + struct usb_device *udev; + unsigned int slot_id; + unsigned int ep_index; + unsigned long flags; + + xhci = hcd_to_xhci(hcd); + udev = (struct usb_device *)ep->hcpriv; + slot_id = udev->slot_id; + ep_index = xhci_get_endpoint_index(&ep->desc); + + spin_lock_irqsave(&xhci->lock, flags); + xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; + xhci_ring_doorbell_for_active_rings(xhci, slot_id, ep_index); + spin_unlock_irqrestore(&xhci->lock, flags); +} + static const struct hc_driver xhci_hc_driver = { .description = "xhci-hcd", .product_desc = "xHCI Host Controller", @@ -5224,6 +5244,7 @@ static const struct hc_driver xhci_hc_driver = { .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout, .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout, .find_raw_port_number = xhci_find_raw_port_number, + .clear_tt_buffer_complete = xhci_clear_tt_buffer_complete, }; void xhci_init_driver(struct hc_driver *drv, diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 7f8b950d1a73..34789f4db555 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -936,6 +936,8 @@ struct xhci_virt_ep { #define EP_GETTING_NO_STREAMS (1 << 5) #define EP_HARD_CLEAR_TOGGLE (1 << 6) #define EP_SOFT_CLEAR_TOGGLE (1 << 7) +/* usb_hub_clear_tt_buffer is in progress */ +#define EP_CLEARING_TT (1 << 8) /* ---- Related to URB cancellation ---- */ struct list_head cancelled_td_list; /* Watchdog timer for stop endpoint command to cancel URBs */ @@ -2102,6 +2104,9 @@ void xhci_handle_command_timeout(struct work_struct *work); void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id, unsigned int ep_index, unsigned int stream_id); +void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci, + unsigned int slot_id, + unsigned int ep_index); void xhci_cleanup_command_queue(struct xhci_hcd *xhci); void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring); unsigned int count_trbs(u64 addr, u64 len); -- cgit v1.2.3 From 32a6cfdfd168982cd7cd2898372da5eb49e56daf Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Wed, 5 Jun 2019 15:16:21 +0900 Subject: usb: renesas_usbhs: remove sudmac support SUDMAC feature was supported in v3.10, but was never used by any platform. So, this patch removes it. Signed-off-by: Yoshihiro Shimoda Reviewed-by: Geert Uytterhoeven Reviewed-by: Simon Horman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/fifo.c | 6 +----- include/linux/usb/renesas_usbhs.h | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c index 452b456ac24e..e84d2ac2a30a 100644 --- a/drivers/usb/renesas_usbhs/fifo.c +++ b/drivers/usb/renesas_usbhs/fifo.c @@ -12,7 +12,6 @@ #include "pipe.h" #define usbhsf_get_cfifo(p) (&((p)->fifo_info.cfifo)) -#define usbhsf_is_cfifo(p, f) (usbhsf_get_cfifo(p) == f) #define usbhsf_fifo_is_busy(f) ((f)->pipe) /* see usbhs_pipe_select_fifo */ @@ -325,10 +324,7 @@ static int usbhsf_fifo_select(struct usbhs_pipe *pipe, } /* "base" will be used below */ - if (usbhs_get_dparam(priv, has_sudmac) && !usbhsf_is_cfifo(priv, fifo)) - usbhs_write(priv, fifo->sel, base); - else - usbhs_write(priv, fifo->sel, base | MBW_32); + usbhs_write(priv, fifo->sel, base | MBW_32); /* check ISEL and CURPIPE value */ while (timeout--) { diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index 3f53043fb56b..a2481f4da841 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h @@ -187,7 +187,6 @@ struct renesas_usbhs_driver_param { * option: */ u32 has_otg:1; /* for controlling PWEN/EXTLP */ - u32 has_sudmac:1; /* for SUDMAC */ u32 has_usb_dmac:1; /* for USB-DMAC */ u32 runtime_pwctrl:1; u32 has_cnen:1; -- cgit v1.2.3 From e60e982375244026ca46feeba0fb5bb4d51b5a67 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Wed, 5 Jun 2019 15:16:22 +0900 Subject: usb: renesas_usbhs: remove controlling PWEN/EXTLP support Controlling PWMEN/EXTLP (named as "has_otg") was supported in v3.2, but the last user (kzm9g) was removed by the commit 30f8925a57d8ad49 ("ARM: shmobile: Remove legacy board code for KZM-A9-GT"). So, this patch remove it. Signed-off-by: Yoshihiro Shimoda Reviewed-by: Geert Uytterhoeven Reviewed-by: Simon Horman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 4 ---- include/linux/usb/renesas_usbhs.h | 1 - 2 files changed, 5 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index c7c9c5d75a56..a501ea609019 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -95,10 +95,6 @@ void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable) { u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; u16 val = DCFM | DRPD | HSE | USBE; - int has_otg = usbhs_get_dparam(priv, has_otg); - - if (has_otg) - usbhs_bset(priv, DVSTCTR, (EXTLP | PWEN), (EXTLP | PWEN)); /* * if enable diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index a2481f4da841..b2cba7c74444 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h @@ -186,7 +186,6 @@ struct renesas_usbhs_driver_param { /* * option: */ - u32 has_otg:1; /* for controlling PWEN/EXTLP */ u32 has_usb_dmac:1; /* for USB-DMAC */ u32 runtime_pwctrl:1; u32 has_cnen:1; -- cgit v1.2.3 From cf2b5010f41638e36d8adca8476f4baee64a8996 Mon Sep 17 00:00:00 2001 From: Suwan Kim Date: Tue, 4 Jun 2019 00:02:11 +0900 Subject: usbip: Replace unused kvec array with single variable in vhci_send_cmd_unlink() vhci_send_cmd_unlink() declears kvec array of size 3 but it actually uses just one element of the array. So, remove kvec array and replace it with single kvec variable. Signed-off-by: Suwan Kim Acked-by: Shuah Khan Signed-off-by: Greg Kroah-Hartman --- drivers/usb/usbip/vhci_tx.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/usb/usbip/vhci_tx.c b/drivers/usb/usbip/vhci_tx.c index 9aed15a358b7..2fa26d0578d7 100644 --- a/drivers/usb/usbip/vhci_tx.c +++ b/drivers/usb/usbip/vhci_tx.c @@ -144,16 +144,14 @@ static int vhci_send_cmd_unlink(struct vhci_device *vdev) struct vhci_unlink *unlink = NULL; struct msghdr msg; - struct kvec iov[3]; + struct kvec iov; size_t txsize; - size_t total_size = 0; while ((unlink = dequeue_from_unlink_tx(vdev)) != NULL) { int ret; struct usbip_header pdu_header; - txsize = 0; memset(&pdu_header, 0, sizeof(pdu_header)); memset(&msg, 0, sizeof(msg)); memset(&iov, 0, sizeof(iov)); @@ -169,11 +167,11 @@ static int vhci_send_cmd_unlink(struct vhci_device *vdev) usbip_header_correct_endian(&pdu_header, 1); - iov[0].iov_base = &pdu_header; - iov[0].iov_len = sizeof(pdu_header); - txsize += sizeof(pdu_header); + iov.iov_base = &pdu_header; + iov.iov_len = sizeof(pdu_header); + txsize = sizeof(pdu_header); - ret = kernel_sendmsg(vdev->ud.tcp_socket, &msg, iov, 1, txsize); + ret = kernel_sendmsg(vdev->ud.tcp_socket, &msg, &iov, 1, txsize); if (ret != txsize) { pr_err("sendmsg failed!, ret=%d for %zd\n", ret, txsize); -- cgit v1.2.3 From 0e016249f6877eb279da6369f182e4c9efe88cab Mon Sep 17 00:00:00 2001 From: Hariprasad Kelam Date: Wed, 5 Jun 2019 19:48:42 +0530 Subject: usb: host: u132-hcd: remove unneeded variable frame This patch fixes below issue reported by coccicheck drivers/usb/host/u132-hcd.c:2557:6-11: Unneeded variable: "frame". Return "0" on line 2560 Signed-off-by: Hariprasad Kelam Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/u132-hcd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c index 4a5c9b599c57..400c40bc43a6 100644 --- a/drivers/usb/host/u132-hcd.c +++ b/drivers/usb/host/u132-hcd.c @@ -2554,10 +2554,9 @@ static int u132_get_frame(struct usb_hcd *hcd) dev_err(&u132->platform_dev->dev, "device is being removed\n"); return -ESHUTDOWN; } else { - int frame = 0; dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n"); mdelay(100); - return frame; + return 0; } } -- cgit v1.2.3 From 812086d362a1d589d2b2e10957254ac13e83522b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 5 Jun 2019 14:44:40 +0200 Subject: USB: move usb debugfs directory creation to the usb common core The USB gadget subsystem wants to use the USB debugfs root directory, so move it to the common "core" USB code so that it is properly initialized and removed as needed. In order to properly do this, we need to load the common code before the usb core code, when everything is linked into the kernel, so reorder the link order of the code. Also as the usb common code has the possibility of the led trigger logic to be merged into it, handle the build option properly by only having one module init/exit function and have the common code initialize the led trigger if needed. Reported-by: Chunfeng Yun Cc: Felipe Balbi Tested-by: Chunfeng Yun Signed-off-by: Greg Kroah-Hartman --- drivers/usb/Makefile | 3 +-- drivers/usb/common/common.c | 21 +++++++++++++++++++++ drivers/usb/common/common.h | 14 ++++++++++++++ drivers/usb/common/led.c | 9 +++------ drivers/usb/core/usb.c | 10 ++++------ 5 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 drivers/usb/common/common.h diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index 7d1b8c82b208..ecc2de1ffaae 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile @@ -5,6 +5,7 @@ # Object files in subdirectories +obj-$(CONFIG_USB_COMMON) += common/ obj-$(CONFIG_USB) += core/ obj-$(CONFIG_USB_SUPPORT) += phy/ @@ -60,8 +61,6 @@ obj-$(CONFIG_USB_CHIPIDEA) += chipidea/ obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs/ obj-$(CONFIG_USB_GADGET) += gadget/ -obj-$(CONFIG_USB_COMMON) += common/ - obj-$(CONFIG_USBIP_CORE) += usbip/ obj-$(CONFIG_TYPEC) += typec/ diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index 18f5dcf58b0d..1433260d99b4 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include "common.h" static const char *const ep_type_names[] = { [USB_ENDPOINT_XFER_CONTROL] = "ctrl", @@ -291,4 +293,23 @@ struct device *usb_of_get_companion_dev(struct device *dev) EXPORT_SYMBOL_GPL(usb_of_get_companion_dev); #endif +struct dentry *usb_debug_root; +EXPORT_SYMBOL_GPL(usb_debug_root); + +static int __init usb_common_init(void) +{ + usb_debug_root = debugfs_create_dir("usb", NULL); + ledtrig_usb_init(); + return 0; +} + +static void __exit usb_common_exit(void) +{ + ledtrig_usb_exit(); + debugfs_remove_recursive(usb_debug_root); +} + +subsys_initcall(usb_common_init); +module_exit(usb_common_exit); + MODULE_LICENSE("GPL"); diff --git a/drivers/usb/common/common.h b/drivers/usb/common/common.h new file mode 100644 index 000000000000..424a91316a4b --- /dev/null +++ b/drivers/usb/common/common.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LINUX_USB_COMMON_H +#define __LINUX_USB_COMMON_H + +#if defined(CONFIG_USB_LED_TRIG) +void ledtrig_usb_init(void); +void ledtrig_usb_exit(void); +#else +static inline void ledtrig_usb_init(void) { } +static inline void ledtrig_usb_exit(void) { } +#endif + +#endif /* __LINUX_USB_COMMON_H */ diff --git a/drivers/usb/common/led.c b/drivers/usb/common/led.c index 7bd81166b77d..0865dd44a80a 100644 --- a/drivers/usb/common/led.c +++ b/drivers/usb/common/led.c @@ -10,6 +10,7 @@ #include #include #include +#include "common.h" #define BLINK_DELAY 30 @@ -36,18 +37,14 @@ void usb_led_activity(enum usb_led_event ev) EXPORT_SYMBOL_GPL(usb_led_activity); -static int __init ledtrig_usb_init(void) +void __init ledtrig_usb_init(void) { led_trigger_register_simple("usb-gadget", &ledtrig_usb_gadget); led_trigger_register_simple("usb-host", &ledtrig_usb_host); - return 0; } -static void __exit ledtrig_usb_exit(void) +void __exit ledtrig_usb_exit(void) { led_trigger_unregister_simple(ledtrig_usb_gadget); led_trigger_unregister_simple(ledtrig_usb_host); } - -module_init(ledtrig_usb_init); -module_exit(ledtrig_usb_exit); diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 7fcb9f782931..5a0df527a8ca 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -1185,19 +1185,17 @@ static struct notifier_block usb_bus_nb = { .notifier_call = usb_bus_notify, }; -struct dentry *usb_debug_root; -EXPORT_SYMBOL_GPL(usb_debug_root); +static struct dentry *usb_devices_root; static void usb_debugfs_init(void) { - usb_debug_root = debugfs_create_dir("usb", NULL); - debugfs_create_file("devices", 0444, usb_debug_root, NULL, - &usbfs_devices_fops); + usb_devices_root = debugfs_create_file("devices", 0444, usb_debug_root, + NULL, &usbfs_devices_fops); } static void usb_debugfs_cleanup(void) { - debugfs_remove_recursive(usb_debug_root); + debugfs_remove(usb_devices_root); } /* -- cgit v1.2.3 From 4c06a42e826d5bb24408c528aba2c13528225071 Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Sat, 8 Jun 2019 12:56:13 +0200 Subject: usb: typec: tcpm: fusb302: simplify getting the adapter of a client We have a dedicated pointer for that, so use it. Much easier to read and less computation involved. Signed-off-by: Wolfram Sang Reviewed-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/tcpm/fusb302.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c index 7302f7501ec9..c524088246ee 100644 --- a/drivers/usb/typec/tcpm/fusb302.c +++ b/drivers/usb/typec/tcpm/fusb302.c @@ -1697,13 +1697,12 @@ static int fusb302_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct fusb302_chip *chip; - struct i2c_adapter *adapter; + struct i2c_adapter *adapter = client->adapter; struct device *dev = &client->dev; const char *name; int ret = 0; u32 v; - adapter = to_i2c_adapter(client->dev.parent); if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { dev_err(&client->dev, "I2C/SMBus block functionality not supported!\n"); -- cgit v1.2.3 From a3fe2605a60d1d038e9a50cc3cd8a76bb48790b5 Mon Sep 17 00:00:00 2001 From: Hariprasad Kelam Date: Sun, 9 Jun 2019 08:37:52 +0530 Subject: USB: sisusbvga: Remove unneeded variable Remove unneeded variable ret in function sisusb_set_default_mode. Change return type of sisusb_set_default_mode from int to void as it never fails. Issue identified by coccicheck Signed-off-by: Hariprasad Kelam ----- changes in v2: Change return type of sisusb_set_default_mode from int to void as it never fails changes in v3: Update changelog ---- Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/sisusbvga/sisusb.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c index ea06f1fed6fa..2ab9600d0898 100644 --- a/drivers/usb/misc/sisusbvga/sisusb.c +++ b/drivers/usb/misc/sisusbvga/sisusb.c @@ -1747,10 +1747,10 @@ static int sisusb_setup_screen(struct sisusb_usb_data *sisusb, return ret; } -static int sisusb_set_default_mode(struct sisusb_usb_data *sisusb, +static void sisusb_set_default_mode(struct sisusb_usb_data *sisusb, int touchengines) { - int ret = 0, i, j, modex, bpp, du; + int i, j, modex, bpp, du; u8 sr31, cr63, tmp8; static const char attrdata[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, @@ -1873,8 +1873,6 @@ static int sisusb_set_default_mode(struct sisusb_usb_data *sisusb, } SETIREG(SISCR, 0x34, 0x44); /* we just set std mode #44 */ - - return ret; } static int sisusb_init_gfxcore(struct sisusb_usb_data *sisusb) @@ -2019,7 +2017,7 @@ static int sisusb_init_gfxcore(struct sisusb_usb_data *sisusb) ret |= SETIREG(SISCR, 0x83, 0x00); - ret |= sisusb_set_default_mode(sisusb, 0); + sisusb_set_default_mode(sisusb, 0); ret |= SETIREGAND(SISSR, 0x21, 0xdf); ret |= SETIREGOR(SISSR, 0x01, 0x20); @@ -2246,7 +2244,7 @@ static int sisusb_init_gfxdevice(struct sisusb_usb_data *sisusb, int initscreen) if (sisusb_init_gfxcore(sisusb) == 0) { sisusb->gfxinit = 1; sisusb_get_ramconfig(sisusb); - ret |= sisusb_set_default_mode(sisusb, 1); + sisusb_set_default_mode(sisusb, 1); ret |= sisusb_setup_screen(sisusb, 1, initscreen); } } -- cgit v1.2.3 From e137d34f94ebcb6508d7c8614ac045583fffbe2a Mon Sep 17 00:00:00 2001 From: Chunfeng Yun Date: Mon, 10 Jun 2019 10:52:29 +0800 Subject: Revert "usb: mtu3: fix up undefined reference to usb_debug_root" It's not needed after [1] is applied, because usb_debug_root is created by usb common core but not usbcore now. [1] 812086d362a1 ("USB: move usb debugfs directory creation to the usb common core") Signed-off-by: Chunfeng Yun Signed-off-by: Greg Kroah-Hartman --- drivers/usb/mtu3/mtu3_debugfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/mtu3/mtu3_debugfs.c b/drivers/usb/mtu3/mtu3_debugfs.c index b7c86ccd50b4..62c57ddc554e 100644 --- a/drivers/usb/mtu3/mtu3_debugfs.c +++ b/drivers/usb/mtu3/mtu3_debugfs.c @@ -528,7 +528,8 @@ void ssusb_dr_debugfs_init(struct ssusb_mtk *ssusb) void ssusb_debugfs_create_root(struct ssusb_mtk *ssusb) { - ssusb->dbgfs_root = debugfs_create_dir(dev_name(ssusb->dev), NULL); + ssusb->dbgfs_root = + debugfs_create_dir(dev_name(ssusb->dev), usb_debug_root); } void ssusb_debugfs_remove_root(struct ssusb_mtk *ssusb) -- cgit v1.2.3 From d4a36e82924d3305a17ac987a510f3902df5a4b2 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 28 May 2019 14:04:02 +0900 Subject: phy: renesas: rcar-gen2: Fix memory leak at error paths This patch fixes memory leak at error paths of the probe function. In for_each_child_of_node, if the loop returns, the driver should call of_put_node() before returns. Reported-by: Julia Lawall Fixes: 1233f59f745b237 ("phy: Renesas R-Car Gen2 PHY driver") Signed-off-by: Yoshihiro Shimoda Reviewed-by: Geert Uytterhoeven Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/renesas/phy-rcar-gen2.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/phy/renesas/phy-rcar-gen2.c b/drivers/phy/renesas/phy-rcar-gen2.c index 8dc5710d9c98..2926e4937301 100644 --- a/drivers/phy/renesas/phy-rcar-gen2.c +++ b/drivers/phy/renesas/phy-rcar-gen2.c @@ -391,6 +391,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev) error = of_property_read_u32(np, "reg", &channel_num); if (error || channel_num > 2) { dev_err(dev, "Invalid \"reg\" property\n"); + of_node_put(np); return error; } channel->select_mask = select_mask[channel_num]; @@ -406,6 +407,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev) data->gen2_phy_ops); if (IS_ERR(phy->phy)) { dev_err(dev, "Failed to create PHY\n"); + of_node_put(np); return PTR_ERR(phy->phy); } phy_set_drvdata(phy->phy, phy); -- cgit v1.2.3 From d9e100829fca6cbd270d7e005b0c0bb2d14924b8 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Wed, 22 May 2019 11:35:25 -0700 Subject: phy: usb: phy-brcm-usb: Remove sysfs attributes upon driver removal We are not destroying the sysfs attribute groupe we registered during the probe function which will make subsequent probe calls to that driver fail. Correct that with adding a remove function which only removes those attributes since the reference counting on clocks did its job already. Fixes: 415060b21f31 ("phy: usb: phy-brcm-usb: Add ability to force DRD mode to host or device") Signed-off-by: Florian Fainelli Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/broadcom/phy-brcm-usb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/phy/broadcom/phy-brcm-usb.c b/drivers/phy/broadcom/phy-brcm-usb.c index f59b1dc30399..292d5b3fc66c 100644 --- a/drivers/phy/broadcom/phy-brcm-usb.c +++ b/drivers/phy/broadcom/phy-brcm-usb.c @@ -376,6 +376,13 @@ static int brcm_usb_phy_probe(struct platform_device *pdev) return PTR_ERR_OR_ZERO(phy_provider); } +static int brcm_usb_phy_remove(struct platform_device *pdev) +{ + sysfs_remove_group(&pdev->dev.kobj, &brcm_usb_phy_group); + + return 0; +} + #ifdef CONFIG_PM_SLEEP static int brcm_usb_phy_suspend(struct device *dev) { @@ -441,6 +448,7 @@ MODULE_DEVICE_TABLE(of, brcm_usb_dt_ids); static struct platform_driver brcm_usb_driver = { .probe = brcm_usb_phy_probe, + .remove = brcm_usb_phy_remove, .driver = { .name = "brcmstb-usb-phy", .owner = THIS_MODULE, -- cgit v1.2.3 From f40043b368ae787837ef659728f0b08bd34f5317 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 25 Apr 2019 17:34:42 +0200 Subject: dt-bindings: phy: tegra-xusb: List PLL power supplies These power supplies provide power for various PLLs that are set up and driven by the XUSB pad controller. These power supplies were previously improperly added to the PCIe and XUSB controllers, but depending on the driver probe order, power to the PLLs will not be supplied soon enough and cause initialization to fail. Reviewed-by: Rob Herring Signed-off-by: Thierry Reding Acked-by: Jon Hunter Signed-off-by: Kishon Vijay Abraham I --- .../devicetree/bindings/phy/nvidia,tegra124-xusb-padctl.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/devicetree/bindings/phy/nvidia,tegra124-xusb-padctl.txt b/Documentation/devicetree/bindings/phy/nvidia,tegra124-xusb-padctl.txt index daedb15f322e..9fb682e47c29 100644 --- a/Documentation/devicetree/bindings/phy/nvidia,tegra124-xusb-padctl.txt +++ b/Documentation/devicetree/bindings/phy/nvidia,tegra124-xusb-padctl.txt @@ -42,6 +42,18 @@ Required properties: - reset-names: Must include the following entries: - "padctl" +For Tegra124: +- avdd-pll-utmip-supply: UTMI PLL power supply. Must supply 1.8 V. +- avdd-pll-erefe-supply: PLLE reference PLL power supply. Must supply 1.05 V. +- avdd-pex-pll-supply: PCIe/USB3 PLL power supply. Must supply 1.05 V. +- hvdd-pex-pll-e-supply: High-voltage PLLE power supply. Must supply 3.3 V. + +For Tegra210: +- avdd-pll-utmip-supply: UTMI PLL power supply. Must supply 1.8 V. +- avdd-pll-uerefe-supply: PLLE reference PLL power supply. Must supply 1.05 V. +- dvdd-pex-pll-supply: PCIe/USB3 PLL power supply. Must supply 1.05 V. +- hvdd-pex-pll-e-supply: High-voltage PLLE power supply. Must supply 1.8 V. + For Tegra186: - avdd-pll-erefeut-supply: UPHY brick and reference clock as well as UTMI PHY power supply. Must supply 1.8 V. -- cgit v1.2.3 From aa5452f54b9f21213364baed25a0f8241aa09050 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 25 Apr 2019 17:34:43 +0200 Subject: phy: tegra: xusb: Add Tegra124 PLL power supplies The Tegra124 SoC has four inputs that consume power in order to supply the PLLs that drive the various USB, PCI and SATA pads. Signed-off-by: Thierry Reding Acked-by: Jon Hunter Tested-by: Jon Hunter Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/tegra/xusb-tegra124.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/phy/tegra/xusb-tegra124.c b/drivers/phy/tegra/xusb-tegra124.c index c45cbedc6634..254592c47b00 100644 --- a/drivers/phy/tegra/xusb-tegra124.c +++ b/drivers/phy/tegra/xusb-tegra124.c @@ -1721,6 +1721,13 @@ static const struct tegra_xusb_padctl_ops tegra124_xusb_padctl_ops = { .hsic_set_idle = tegra124_hsic_set_idle, }; +static const char * const tegra124_xusb_padctl_supply_names[] = { + "avdd-pll-utmip", + "avdd-pll-erefe", + "avdd-pex-pll", + "hvdd-pex-pll-e", +}; + const struct tegra_xusb_padctl_soc tegra124_xusb_padctl_soc = { .num_pads = ARRAY_SIZE(tegra124_pads), .pads = tegra124_pads, @@ -1743,6 +1750,8 @@ const struct tegra_xusb_padctl_soc tegra124_xusb_padctl_soc = { }, }, .ops = &tegra124_xusb_padctl_ops, + .supply_names = tegra124_xusb_padctl_supply_names, + .num_supplies = ARRAY_SIZE(tegra124_xusb_padctl_supply_names), }; EXPORT_SYMBOL_GPL(tegra124_xusb_padctl_soc); -- cgit v1.2.3 From e3888cda394c72dcfd450afec1121d9777a59805 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 25 Apr 2019 17:34:44 +0200 Subject: phy: tegra: xusb: Add Tegra210 PLL power supplies The Tegra210 SoC has four inputs that consume power in order to supply the PLLs that drive the various USB, PCI and SATA pads. Signed-off-by: Thierry Reding Acked-by: Jon Hunter Tested-by: Jon Hunter Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/tegra/xusb-tegra210.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/phy/tegra/xusb-tegra210.c b/drivers/phy/tegra/xusb-tegra210.c index 05bee32a3a4d..eb754baa8d71 100644 --- a/drivers/phy/tegra/xusb-tegra210.c +++ b/drivers/phy/tegra/xusb-tegra210.c @@ -2017,6 +2017,13 @@ static const struct tegra_xusb_padctl_ops tegra210_xusb_padctl_ops = { .hsic_set_idle = tegra210_hsic_set_idle, }; +static const char * const tegra210_xusb_padctl_supply_names[] = { + "avdd-pll-utmip", + "avdd-pll-uerefe", + "dvdd-pex-pll", + "hvdd-pex-pll-e", +}; + const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc = { .num_pads = ARRAY_SIZE(tegra210_pads), .pads = tegra210_pads, @@ -2035,6 +2042,8 @@ const struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc = { }, }, .ops = &tegra210_xusb_padctl_ops, + .supply_names = tegra210_xusb_padctl_supply_names, + .num_supplies = ARRAY_SIZE(tegra210_xusb_padctl_supply_names), }; EXPORT_SYMBOL_GPL(tegra210_xusb_padctl_soc); -- cgit v1.2.3 From d1609c312d42f3bdfe7df9d4dd9d5b2c7ace90f4 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Sun, 28 Apr 2019 10:35:31 +0800 Subject: usb: chipidea: imx: add imx7ulp support In this commit, we add CI_HDRC_PMQOS to avoid system entering idle, at imx7ulp, if the system enters idle, the DMA will stop, so the USB transfer can't work at this case. Signed-off-by: Peter Chen --- drivers/usb/chipidea/ci_hdrc_imx.c | 28 +++++++++++++++++++++++++++- drivers/usb/chipidea/usbmisc_imx.c | 4 ++++ include/linux/usb/chipidea.h | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index ceec8d5985d4..a76708501236 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "ci.h" #include "ci_hdrc_imx.h" @@ -63,6 +64,11 @@ static const struct ci_hdrc_imx_platform_flag imx7d_usb_data = { .flags = CI_HDRC_SUPPORTS_RUNTIME_PM, }; +static const struct ci_hdrc_imx_platform_flag imx7ulp_usb_data = { + .flags = CI_HDRC_SUPPORTS_RUNTIME_PM | + CI_HDRC_PMQOS, +}; + static const struct of_device_id ci_hdrc_imx_dt_ids[] = { { .compatible = "fsl,imx23-usb", .data = &imx23_usb_data}, { .compatible = "fsl,imx28-usb", .data = &imx28_usb_data}, @@ -72,6 +78,7 @@ static const struct of_device_id ci_hdrc_imx_dt_ids[] = { { .compatible = "fsl,imx6sx-usb", .data = &imx6sx_usb_data}, { .compatible = "fsl,imx6ul-usb", .data = &imx6ul_usb_data}, { .compatible = "fsl,imx7d-usb", .data = &imx7d_usb_data}, + { .compatible = "fsl,imx7ulp-usb", .data = &imx7ulp_usb_data}, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, ci_hdrc_imx_dt_ids); @@ -93,6 +100,8 @@ struct ci_hdrc_imx_data { struct clk *clk_ahb; struct clk *clk_per; /* --------------------------------- */ + struct pm_qos_request pm_qos_req; + const struct ci_hdrc_imx_platform_flag *plat_data; }; /* Common functions shared by usbmisc drivers */ @@ -309,6 +318,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) if (!data) return -ENOMEM; + data->plat_data = imx_platform_flag; + pdata.flags |= imx_platform_flag->flags; platform_set_drvdata(pdev, data); data->usbmisc_data = usbmisc_get_init_data(dev); if (IS_ERR(data->usbmisc_data)) @@ -369,6 +380,11 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) } } } + + if (pdata.flags & CI_HDRC_PMQOS) + pm_qos_add_request(&data->pm_qos_req, + PM_QOS_CPU_DMA_LATENCY, 0); + ret = imx_get_clks(dev); if (ret) goto disable_hsic_regulator; @@ -396,7 +412,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) usb_phy_init(pdata.usb_phy); } - pdata.flags |= imx_platform_flag->flags; if (pdata.flags & CI_HDRC_SUPPORTS_RUNTIME_PM) data->supports_runtime_pm = true; @@ -439,6 +454,8 @@ err_clk: disable_hsic_regulator: if (data->hsic_pad_regulator) ret = regulator_disable(data->hsic_pad_regulator); + if (pdata.flags & CI_HDRC_PMQOS) + pm_qos_remove_request(&data->pm_qos_req); return ret; } @@ -455,6 +472,8 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev) if (data->override_phy_control) usb_phy_shutdown(data->phy); imx_disable_unprepare_clks(&pdev->dev); + if (data->plat_data->flags & CI_HDRC_PMQOS) + pm_qos_remove_request(&data->pm_qos_req); if (data->hsic_pad_regulator) regulator_disable(data->hsic_pad_regulator); @@ -480,6 +499,9 @@ static int __maybe_unused imx_controller_suspend(struct device *dev) } imx_disable_unprepare_clks(dev); + if (data->plat_data->flags & CI_HDRC_PMQOS) + pm_qos_remove_request(&data->pm_qos_req); + data->in_lpm = true; return 0; @@ -497,6 +519,10 @@ static int __maybe_unused imx_controller_resume(struct device *dev) return 0; } + if (data->plat_data->flags & CI_HDRC_PMQOS) + pm_qos_add_request(&data->pm_qos_req, + PM_QOS_CPU_DMA_LATENCY, 0); + ret = imx_prepare_enable_clks(dev); if (ret) return ret; diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index d8b67e150b12..b7a5727d0c8a 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -763,6 +763,10 @@ static const struct of_device_id usbmisc_imx_dt_ids[] = { .compatible = "fsl,imx7d-usbmisc", .data = &imx7d_usbmisc_ops, }, + { + .compatible = "fsl,imx7ulp-usbmisc", + .data = &imx7d_usbmisc_ops, + }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids); diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index 911e05af671e..edd89b7c8f18 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -61,6 +61,7 @@ struct ci_hdrc_platform_data { #define CI_HDRC_OVERRIDE_PHY_CONTROL BIT(12) /* Glue layer manages phy */ #define CI_HDRC_REQUIRES_ALIGNED_DMA BIT(13) #define CI_HDRC_IMX_IS_HSIC BIT(14) +#define CI_HDRC_PMQOS BIT(15) enum usb_dr_mode dr_mode; #define CI_HDRC_CONTROLLER_RESET_EVENT 0 #define CI_HDRC_CONTROLLER_STOPPED_EVENT 1 -- cgit v1.2.3 From ed5a419bb0195c4f79ccbb85d6bd3ae3ad0a8ac7 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Tue, 7 May 2019 09:53:55 +0800 Subject: usb: chipidea: imx: "fsl,usbphy" phandle is not mandatory now Since the chipidea common code support get the USB PHY phandle from "phys", the glue layer is not mandatory to get the "fsl,usbphy" phandle any more. Signed-off-by: Peter Chen --- drivers/usb/chipidea/ci_hdrc_imx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index a76708501236..b5abfe89190c 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -398,8 +398,9 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) ret = PTR_ERR(data->phy); /* Return -EINVAL if no usbphy is available */ if (ret == -ENODEV) - ret = -EINVAL; - goto err_clk; + data->phy = NULL; + else + goto err_clk; } pdata.usb_phy = data->phy; -- cgit v1.2.3 From b8a4f526fabafa2b701644c0a8a6220f39c3cbf1 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Wed, 5 Jun 2019 13:08:49 -0300 Subject: usb: chipidea: Use dev_err() instead of pr_err() dev_err() is more appropriate for printing error messages inside drivers, so switch to dev_err(). While at it also add the missing newlines. Signed-off-by: Fabio Estevam Signed-off-by: Peter Chen --- drivers/usb/chipidea/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 27749ace2d93..26062d610c20 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -523,8 +523,9 @@ int hw_device_reset(struct ci_hdrc *ci) hw_write(ci, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM); if (hw_read(ci, OP_USBMODE, USBMODE_CM) != USBMODE_CM_DC) { - pr_err("cannot enter in %s device mode", ci_role(ci)->name); - pr_err("lpm = %i", ci->hw_bank.lpm); + dev_err(ci->dev, "cannot enter in %s device mode\n", + ci_role(ci)->name); + dev_err(ci->dev, "lpm = %i\n", ci->hw_bank.lpm); return -ENODEV; } -- cgit v1.2.3 From 8fbd06e592304a121c61b0a01f0b85e7b5a9a05d Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Wed, 5 Jun 2019 14:37:37 -0300 Subject: usb: chipidea: imx: Use devm_platform_ioremap_resource() Use devm_platform_ioremap_resource() to simplify the code a bit. Signed-off-by: Fabio Estevam Signed-off-by: Peter Chen --- drivers/usb/chipidea/usbmisc_imx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index b7a5727d0c8a..078c1fdce493 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -773,7 +773,6 @@ MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids); static int usbmisc_imx_probe(struct platform_device *pdev) { - struct resource *res; struct imx_usbmisc *data; const struct of_device_id *of_id; @@ -787,8 +786,7 @@ static int usbmisc_imx_probe(struct platform_device *pdev) spin_lock_init(&data->lock); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - data->base = devm_ioremap_resource(&pdev->dev, res); + data->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(data->base)) return PTR_ERR(data->base); -- cgit v1.2.3 From 034252e37b313083002e1cb13b4b5d0b6d926b4c Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Wed, 5 Jun 2019 14:37:38 -0300 Subject: usb: chipidea: msm: Use devm_platform_ioremap_resource() Use devm_platform_ioremap_resource() to simplify the code a bit. Signed-off-by: Fabio Estevam Signed-off-by: Peter Chen --- drivers/usb/chipidea/ci_hdrc_msm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c b/drivers/usb/chipidea/ci_hdrc_msm.c index b8b3caad889c..bb4645a8ca46 100644 --- a/drivers/usb/chipidea/ci_hdrc_msm.c +++ b/drivers/usb/chipidea/ci_hdrc_msm.c @@ -175,7 +175,6 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev) struct platform_device *plat_ci; struct clk *clk; struct reset_control *reset; - struct resource *res; int ret; struct device_node *ulpi_node, *phy_node; @@ -209,8 +208,7 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev) if (IS_ERR(clk)) return PTR_ERR(clk); - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); - ci->base = devm_ioremap_resource(&pdev->dev, res); + ci->base = devm_platform_ioremap_resource(pdev, 1); if (IS_ERR(ci->base)) return PTR_ERR(ci->base); -- cgit v1.2.3 From 59d7d4c5178d18b58414194271ad85e30ecaff92 Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Mon, 17 Jun 2019 11:06:02 +0200 Subject: dt-bindings: usb: renesas_usbhs: Rename bindings documentation file For consistency with the naming of (most) other documentation files for DT bindings for Renesas IP blocks rename the Renesas USBHS documentation file from renesas-usbhs.txt to renesas,usbhs.txt. Signed-off-by: Simon Horman Signed-off-by: Felipe Balbi --- .../devicetree/bindings/usb/renesas,usbhs.txt | 57 ++++++++++++++++++++++ .../devicetree/bindings/usb/renesas_usbhs.txt | 57 ---------------------- 2 files changed, 57 insertions(+), 57 deletions(-) create mode 100644 Documentation/devicetree/bindings/usb/renesas,usbhs.txt delete mode 100644 Documentation/devicetree/bindings/usb/renesas_usbhs.txt diff --git a/Documentation/devicetree/bindings/usb/renesas,usbhs.txt b/Documentation/devicetree/bindings/usb/renesas,usbhs.txt new file mode 100644 index 000000000000..e39255ea6e4f --- /dev/null +++ b/Documentation/devicetree/bindings/usb/renesas,usbhs.txt @@ -0,0 +1,57 @@ +Renesas Electronics USBHS driver + +Required properties: + - compatible: Must contain one or more of the following: + + - "renesas,usbhs-r8a7743" for r8a7743 (RZ/G1M) compatible device + - "renesas,usbhs-r8a7744" for r8a7744 (RZ/G1N) compatible device + - "renesas,usbhs-r8a7745" for r8a7745 (RZ/G1E) compatible device + - "renesas,usbhs-r8a77470" for r8a77470 (RZ/G1C) compatible device + - "renesas,usbhs-r8a774a1" for r8a774a1 (RZ/G2M) compatible device + - "renesas,usbhs-r8a774c0" for r8a774c0 (RZ/G2E) compatible device + - "renesas,usbhs-r8a7790" for r8a7790 (R-Car H2) compatible device + - "renesas,usbhs-r8a7791" for r8a7791 (R-Car M2-W) compatible device + - "renesas,usbhs-r8a7792" for r8a7792 (R-Car V2H) compatible device + - "renesas,usbhs-r8a7793" for r8a7793 (R-Car M2-N) compatible device + - "renesas,usbhs-r8a7794" for r8a7794 (R-Car E2) compatible device + - "renesas,usbhs-r8a7795" for r8a7795 (R-Car H3) compatible device + - "renesas,usbhs-r8a7796" for r8a7796 (R-Car M3-W) compatible device + - "renesas,usbhs-r8a77965" for r8a77965 (R-Car M3-N) compatible device + - "renesas,usbhs-r8a77990" for r8a77990 (R-Car E3) compatible device + - "renesas,usbhs-r8a77995" for r8a77995 (R-Car D3) compatible device + - "renesas,usbhs-r7s72100" for r7s72100 (RZ/A1) compatible device + - "renesas,usbhs-r7s9210" for r7s9210 (RZ/A2) compatible device + - "renesas,rcar-gen2-usbhs" for R-Car Gen2 or RZ/G1 compatible devices + - "renesas,rcar-gen3-usbhs" for R-Car Gen3 or RZ/G2 compatible devices + - "renesas,rza1-usbhs" for RZ/A1 compatible device + - "renesas,rza2-usbhs" for RZ/A2 compatible device + + When compatible with the generic version, nodes must list the + SoC-specific version corresponding to the platform first followed + by the generic version. + + - reg: Base address and length of the register for the USBHS + - interrupts: Interrupt specifier for the USBHS + - clocks: A list of phandle + clock specifier pairs. + - In case of "renesas,rcar-gen3-usbhs", two clocks are required. + First clock should be peripheral and second one should be host. + - In case of except above, one clock is required. First clock + should be peripheral. + +Optional properties: + - renesas,buswait: Integer to use BUSWAIT register + - renesas,enable-gpio: A gpio specifier to check GPIO determining if USB + function should be enabled + - phys: phandle + phy specifier pair + - phy-names: must be "usb" + - dmas: Must contain a list of references to DMA specifiers. + - dma-names : named "ch%d", where %d is the channel number ranging from zero + to the number of channels (DnFIFOs) minus one. + +Example: + usbhs: usb@e6590000 { + compatible = "renesas,usbhs-r8a7790", "renesas,rcar-gen2-usbhs"; + reg = <0 0xe6590000 0 0x100>; + interrupts = <0 107 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&mstp7_clks R8A7790_CLK_HSUSB>; + }; diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt deleted file mode 100644 index e39255ea6e4f..000000000000 --- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt +++ /dev/null @@ -1,57 +0,0 @@ -Renesas Electronics USBHS driver - -Required properties: - - compatible: Must contain one or more of the following: - - - "renesas,usbhs-r8a7743" for r8a7743 (RZ/G1M) compatible device - - "renesas,usbhs-r8a7744" for r8a7744 (RZ/G1N) compatible device - - "renesas,usbhs-r8a7745" for r8a7745 (RZ/G1E) compatible device - - "renesas,usbhs-r8a77470" for r8a77470 (RZ/G1C) compatible device - - "renesas,usbhs-r8a774a1" for r8a774a1 (RZ/G2M) compatible device - - "renesas,usbhs-r8a774c0" for r8a774c0 (RZ/G2E) compatible device - - "renesas,usbhs-r8a7790" for r8a7790 (R-Car H2) compatible device - - "renesas,usbhs-r8a7791" for r8a7791 (R-Car M2-W) compatible device - - "renesas,usbhs-r8a7792" for r8a7792 (R-Car V2H) compatible device - - "renesas,usbhs-r8a7793" for r8a7793 (R-Car M2-N) compatible device - - "renesas,usbhs-r8a7794" for r8a7794 (R-Car E2) compatible device - - "renesas,usbhs-r8a7795" for r8a7795 (R-Car H3) compatible device - - "renesas,usbhs-r8a7796" for r8a7796 (R-Car M3-W) compatible device - - "renesas,usbhs-r8a77965" for r8a77965 (R-Car M3-N) compatible device - - "renesas,usbhs-r8a77990" for r8a77990 (R-Car E3) compatible device - - "renesas,usbhs-r8a77995" for r8a77995 (R-Car D3) compatible device - - "renesas,usbhs-r7s72100" for r7s72100 (RZ/A1) compatible device - - "renesas,usbhs-r7s9210" for r7s9210 (RZ/A2) compatible device - - "renesas,rcar-gen2-usbhs" for R-Car Gen2 or RZ/G1 compatible devices - - "renesas,rcar-gen3-usbhs" for R-Car Gen3 or RZ/G2 compatible devices - - "renesas,rza1-usbhs" for RZ/A1 compatible device - - "renesas,rza2-usbhs" for RZ/A2 compatible device - - When compatible with the generic version, nodes must list the - SoC-specific version corresponding to the platform first followed - by the generic version. - - - reg: Base address and length of the register for the USBHS - - interrupts: Interrupt specifier for the USBHS - - clocks: A list of phandle + clock specifier pairs. - - In case of "renesas,rcar-gen3-usbhs", two clocks are required. - First clock should be peripheral and second one should be host. - - In case of except above, one clock is required. First clock - should be peripheral. - -Optional properties: - - renesas,buswait: Integer to use BUSWAIT register - - renesas,enable-gpio: A gpio specifier to check GPIO determining if USB - function should be enabled - - phys: phandle + phy specifier pair - - phy-names: must be "usb" - - dmas: Must contain a list of references to DMA specifiers. - - dma-names : named "ch%d", where %d is the channel number ranging from zero - to the number of channels (DnFIFOs) minus one. - -Example: - usbhs: usb@e6590000 { - compatible = "renesas,usbhs-r8a7790", "renesas,rcar-gen2-usbhs"; - reg = <0 0xe6590000 0 0x100>; - interrupts = <0 107 IRQ_TYPE_LEVEL_HIGH>; - clocks = <&mstp7_clks R8A7790_CLK_HSUSB>; - }; -- cgit v1.2.3 From 23c46801d14cb647afefc9ec9a7f785777251e76 Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Mon, 17 Jun 2019 11:06:03 +0200 Subject: dt-bindings: usb: renesas_gen3: Rename bindings documentation file For consistency with the naming of (most) other documentation files for DT bindings for Renesas IP blocks rename the Renesas USB3.0 peripheral documentation file from renesas-gen3.txt to renesas,gen3.txt. Signed-off-by: Simon Horman Signed-off-by: Felipe Balbi --- .../devicetree/bindings/usb/renesas,usb3.txt | 41 ++++++++++++++++++++++ .../devicetree/bindings/usb/renesas_usb3.txt | 41 ---------------------- 2 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 Documentation/devicetree/bindings/usb/renesas,usb3.txt delete mode 100644 Documentation/devicetree/bindings/usb/renesas_usb3.txt diff --git a/Documentation/devicetree/bindings/usb/renesas,usb3.txt b/Documentation/devicetree/bindings/usb/renesas,usb3.txt new file mode 100644 index 000000000000..35039e720515 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/renesas,usb3.txt @@ -0,0 +1,41 @@ +Renesas Electronics USB3.0 Peripheral driver + +Required properties: + - compatible: Must contain one of the following: + - "renesas,r8a774a1-usb3-peri" + - "renesas,r8a774c0-usb3-peri" + - "renesas,r8a7795-usb3-peri" + - "renesas,r8a7796-usb3-peri" + - "renesas,r8a77965-usb3-peri" + - "renesas,r8a77990-usb3-peri" + - "renesas,rcar-gen3-usb3-peri" for a generic R-Car Gen3 or RZ/G2 + compatible device + + When compatible with the generic version, nodes must list the + SoC-specific version corresponding to the platform first + followed by the generic version. + + - reg: Base address and length of the register for the USB3.0 Peripheral + - interrupts: Interrupt specifier for the USB3.0 Peripheral + - clocks: clock phandle and specifier pair + +Optional properties: + - phys: phandle + phy specifier pair + - phy-names: must be "usb" + +Example of R-Car H3 ES1.x: + usb3_peri0: usb@ee020000 { + compatible = "renesas,r8a7795-usb3-peri", + "renesas,rcar-gen3-usb3-peri"; + reg = <0 0xee020000 0 0x400>; + interrupts = ; + clocks = <&cpg CPG_MOD 328>; + }; + + usb3_peri1: usb@ee060000 { + compatible = "renesas,r8a7795-usb3-peri", + "renesas,rcar-gen3-usb3-peri"; + reg = <0 0xee060000 0 0x400>; + interrupts = ; + clocks = <&cpg CPG_MOD 327>; + }; diff --git a/Documentation/devicetree/bindings/usb/renesas_usb3.txt b/Documentation/devicetree/bindings/usb/renesas_usb3.txt deleted file mode 100644 index 35039e720515..000000000000 --- a/Documentation/devicetree/bindings/usb/renesas_usb3.txt +++ /dev/null @@ -1,41 +0,0 @@ -Renesas Electronics USB3.0 Peripheral driver - -Required properties: - - compatible: Must contain one of the following: - - "renesas,r8a774a1-usb3-peri" - - "renesas,r8a774c0-usb3-peri" - - "renesas,r8a7795-usb3-peri" - - "renesas,r8a7796-usb3-peri" - - "renesas,r8a77965-usb3-peri" - - "renesas,r8a77990-usb3-peri" - - "renesas,rcar-gen3-usb3-peri" for a generic R-Car Gen3 or RZ/G2 - compatible device - - When compatible with the generic version, nodes must list the - SoC-specific version corresponding to the platform first - followed by the generic version. - - - reg: Base address and length of the register for the USB3.0 Peripheral - - interrupts: Interrupt specifier for the USB3.0 Peripheral - - clocks: clock phandle and specifier pair - -Optional properties: - - phys: phandle + phy specifier pair - - phy-names: must be "usb" - -Example of R-Car H3 ES1.x: - usb3_peri0: usb@ee020000 { - compatible = "renesas,r8a7795-usb3-peri", - "renesas,rcar-gen3-usb3-peri"; - reg = <0 0xee020000 0 0x400>; - interrupts = ; - clocks = <&cpg CPG_MOD 328>; - }; - - usb3_peri1: usb@ee060000 { - compatible = "renesas,r8a7795-usb3-peri", - "renesas,rcar-gen3-usb3-peri"; - reg = <0 0xee060000 0 0x400>; - interrupts = ; - clocks = <&cpg CPG_MOD 327>; - }; -- cgit v1.2.3 From 1a65a03561198f38f8198650b52f55a21cbb4b6c Mon Sep 17 00:00:00 2001 From: Nathan Huckleberry Date: Thu, 13 Jun 2019 11:58:38 -0700 Subject: usb: host: xhci-tegra: Fix Wunused-const-variable Clang produces the following warning drivers/usb/host/xhci-tegra.c:357:27: warning: unused variable 'mbox_cmd_name' [-Wunused-const-variable] static const char * const mbox_cmd_name[] = { Looks like it was intended for logging or debugging, but was never implemented. Removing mbox_cmd_name. Cc: clang-built-linux@googlegroups.com Link: https://github.com/ClangBuiltLinux/linux/issues/533 Signed-off-by: Nathan Huckleberry Acked-by: Thierry Reding Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci-tegra.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c index 294158113d62..dafc65911fc0 100644 --- a/drivers/usb/host/xhci-tegra.c +++ b/drivers/usb/host/xhci-tegra.c @@ -354,29 +354,6 @@ enum tegra_xusb_mbox_cmd { MBOX_CMD_NAK }; -static const char * const mbox_cmd_name[] = { - [ 1] = "MSG_ENABLE", - [ 2] = "INC_FALCON_CLOCK", - [ 3] = "DEC_FALCON_CLOCK", - [ 4] = "INC_SSPI_CLOCK", - [ 5] = "DEC_SSPI_CLOCK", - [ 6] = "SET_BW", - [ 7] = "SET_SS_PWR_GATING", - [ 8] = "SET_SS_PWR_UNGATING", - [ 9] = "SAVE_DFE_CTLE_CTX", - [ 10] = "AIRPLANE_MODE_ENABLED", - [ 11] = "AIRPLANE_MODE_DISABLED", - [ 12] = "START_HSIC_IDLE", - [ 13] = "STOP_HSIC_IDLE", - [ 14] = "DBC_WAKE_STACK", - [ 15] = "HSIC_PRETEND_CONNECT", - [ 16] = "RESET_SSPI", - [ 17] = "DISABLE_SS_LFPS_DETECTION", - [ 18] = "ENABLE_SS_LFPS_DETECTION", - [128] = "ACK", - [129] = "NAK", -}; - struct tegra_xusb_mbox_msg { u32 cmd; u32 data; -- cgit v1.2.3 From 6d101f24f1dd41ef6eff3d7f175417ce27a3055a Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Mon, 10 Jun 2019 15:36:58 -0700 Subject: USB: add usbfs ioctl to retrieve the connection parameters Recently usfbs gained availability to retrieve device speed, but there is sill no way to determine the bus number or list of ports the device is connected to when using usbfs. While this information can be obtained from sysfs, not all environments allow sysfs access. In a jailed environment a program might be simply given an opened file descriptor to usbfs device, and it is really important that all data can be gathered from said file descriptor. This patch introduces a new ioctl, USBDEVFS_CONNINFO_EX, which return extended connection information for the device, including the bus number, address, port list and speed. The API allows kernel to extend amount of data returned by the ioctl and userspace has an option of adjusting the amount of data it is willing to consume. A new capability, USBDEVFS_CAP_CONNINFO_EX, is introduced to help userspace in determining whether the kernel supports this new ioctl. Signed-off-by: Dmitry Torokhov Acked-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/devio.c | 42 ++++++++++++++++++++++++++++++++++++++- include/uapi/linux/usbdevice_fs.h | 26 ++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index aa17dab6c4ea..186790b06b11 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -1308,6 +1308,39 @@ static int proc_connectinfo(struct usb_dev_state *ps, void __user *arg) return 0; } +static int proc_conninfo_ex(struct usb_dev_state *ps, + void __user *arg, size_t size) +{ + struct usbdevfs_conninfo_ex ci; + struct usb_device *udev = ps->dev; + + if (size < sizeof(ci.size)) + return -EINVAL; + + memset(&ci, 0, sizeof(ci)); + ci.size = sizeof(ci); + ci.busnum = udev->bus->busnum; + ci.devnum = udev->devnum; + ci.speed = udev->speed; + + while (udev && udev->portnum != 0) { + if (++ci.num_ports <= ARRAY_SIZE(ci.ports)) + ci.ports[ARRAY_SIZE(ci.ports) - ci.num_ports] = + udev->portnum; + udev = udev->parent; + } + + if (ci.num_ports < ARRAY_SIZE(ci.ports)) + memmove(&ci.ports[0], + &ci.ports[ARRAY_SIZE(ci.ports) - ci.num_ports], + ci.num_ports); + + if (copy_to_user(arg, &ci, min(sizeof(ci), size))) + return -EFAULT; + + return 0; +} + static int proc_resetdevice(struct usb_dev_state *ps) { struct usb_host_config *actconfig = ps->dev->actconfig; @@ -2250,7 +2283,7 @@ static int proc_get_capabilities(struct usb_dev_state *ps, void __user *arg) caps = USBDEVFS_CAP_ZERO_PACKET | USBDEVFS_CAP_NO_PACKET_SIZE_LIM | USBDEVFS_CAP_REAP_AFTER_DISCONNECT | USBDEVFS_CAP_MMAP | - USBDEVFS_CAP_DROP_PRIVILEGES; + USBDEVFS_CAP_DROP_PRIVILEGES | USBDEVFS_CAP_CONNINFO_EX; if (!ps->dev->bus->no_stop_on_short) caps |= USBDEVFS_CAP_BULK_CONTINUATION; if (ps->dev->bus->sg_tablesize) @@ -2549,6 +2582,13 @@ static long usbdev_do_ioctl(struct file *file, unsigned int cmd, break; } + /* Handle variable-length commands */ + switch (cmd & ~IOCSIZE_MASK) { + case USBDEVFS_CONNINFO_EX(0): + ret = proc_conninfo_ex(ps, p, _IOC_SIZE(cmd)); + break; + } + done: usb_unlock_device(dev); if (ret >= 0) diff --git a/include/uapi/linux/usbdevice_fs.h b/include/uapi/linux/usbdevice_fs.h index 964e87217be4..4b267fe3776e 100644 --- a/include/uapi/linux/usbdevice_fs.h +++ b/include/uapi/linux/usbdevice_fs.h @@ -76,6 +76,26 @@ struct usbdevfs_connectinfo { unsigned char slow; }; +struct usbdevfs_conninfo_ex { + __u32 size; /* Size of the structure from the kernel's */ + /* point of view. Can be used by userspace */ + /* to determine how much data can be */ + /* used/trusted. */ + __u32 busnum; /* USB bus number, as enumerated by the */ + /* kernel, the device is connected to. */ + __u32 devnum; /* Device address on the bus. */ + __u32 speed; /* USB_SPEED_* constants from ch9.h */ + u8 num_ports; /* Number of ports the device is connected */ + /* to on the way to the root hub. It may */ + /* be bigger than size of 'ports' array so */ + /* userspace can detect overflows. */ + u8 ports[7]; /* List of ports on the way from the root */ + /* hub to the device. Current limit in */ + /* USB specification is 7 tiers (root hub, */ + /* 5 intermediate hubs, device), which */ + /* gives at most 6 port entries. */ +}; + #define USBDEVFS_URB_SHORT_NOT_OK 0x01 #define USBDEVFS_URB_ISO_ASAP 0x02 #define USBDEVFS_URB_BULK_CONTINUATION 0x04 @@ -137,6 +157,7 @@ struct usbdevfs_hub_portinfo { #define USBDEVFS_CAP_REAP_AFTER_DISCONNECT 0x10 #define USBDEVFS_CAP_MMAP 0x20 #define USBDEVFS_CAP_DROP_PRIVILEGES 0x40 +#define USBDEVFS_CAP_CONNINFO_EX 0x80 /* USBDEVFS_DISCONNECT_CLAIM flags & struct */ @@ -197,5 +218,10 @@ struct usbdevfs_streams { #define USBDEVFS_FREE_STREAMS _IOR('U', 29, struct usbdevfs_streams) #define USBDEVFS_DROP_PRIVILEGES _IOW('U', 30, __u32) #define USBDEVFS_GET_SPEED _IO('U', 31) +/* + * Returns struct usbdevfs_conninfo_ex; length is variable to allow + * extending size of the data returned. + */ +#define USBDEVFS_CONNINFO_EX(len) _IOC(_IOC_READ, 'U', 32, len) #endif /* _UAPI_LINUX_USBDEVICE_FS_H */ -- cgit v1.2.3 From b6409906c7c03b7ca090678614ef027bb8537196 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Mon, 17 Jun 2019 16:02:22 +0200 Subject: usb: isp1362: Spelling s/eclusive/exclusive/ Signed-off-by: Geert Uytterhoeven Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/isp1362.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/isp1362.h b/drivers/usb/host/isp1362.h index 650240846ee2..4c49688a069d 100644 --- a/drivers/usb/host/isp1362.h +++ b/drivers/usb/host/isp1362.h @@ -11,7 +11,7 @@ #define USE_32BIT 0 -/* These options are mutually eclusive */ +/* These options are mutually exclusive */ #define USE_PLATFORM_DELAY 0 #define USE_NDELAY 0 -- cgit v1.2.3 From ae748b9cf852833d121cf0c1d35bff52d566102b Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Mon, 17 Jun 2019 10:18:48 +0200 Subject: wusb: switch to cbcmac transform The wusb code takes a very peculiar approach at implementing CBC-MAC, by using plain CBC into a scratch buffer, and taking the output IV as the MAC. We can clean up this code substantially by switching to the cbcmac shash, as exposed by the CCM template. To ensure that the module is loaded on demand, add the cbcmac template name as a module alias. Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- crypto/ccm.c | 1 + drivers/usb/wusbcore/Kconfig | 8 +- drivers/usb/wusbcore/crypto.c | 169 +++++++++++------------------------------- 3 files changed, 48 insertions(+), 130 deletions(-) diff --git a/crypto/ccm.c b/crypto/ccm.c index 8c24605c791e..380eb619f657 100644 --- a/crypto/ccm.c +++ b/crypto/ccm.c @@ -1009,3 +1009,4 @@ MODULE_DESCRIPTION("Counter with CBC MAC"); MODULE_ALIAS_CRYPTO("ccm_base"); MODULE_ALIAS_CRYPTO("rfc4309"); MODULE_ALIAS_CRYPTO("ccm"); +MODULE_ALIAS_CRYPTO("cbcmac"); diff --git a/drivers/usb/wusbcore/Kconfig b/drivers/usb/wusbcore/Kconfig index 12e89189ca7d..abc0f361021f 100644 --- a/drivers/usb/wusbcore/Kconfig +++ b/drivers/usb/wusbcore/Kconfig @@ -5,11 +5,9 @@ config USB_WUSB tristate "Enable Wireless USB extensions" depends on UWB - select CRYPTO - select CRYPTO_BLKCIPHER - select CRYPTO_CBC - select CRYPTO_MANAGER - select CRYPTO_AES + select CRYPTO + select CRYPTO_AES + select CRYPTO_CCM help Enable the host-side support for Wireless USB. diff --git a/drivers/usb/wusbcore/crypto.c b/drivers/usb/wusbcore/crypto.c index edb7263bff40..9ee66483ee54 100644 --- a/drivers/usb/wusbcore/crypto.c +++ b/drivers/usb/wusbcore/crypto.c @@ -31,6 +31,9 @@ * funneled through AES are...16 bytes in size! */ +#include +#include +#include #include #include #include @@ -109,16 +112,6 @@ struct aes_ccm_a { __be16 counter; /* Value of x */ } __attribute__((packed)); -static void bytewise_xor(void *_bo, const void *_bi1, const void *_bi2, - size_t size) -{ - u8 *bo = _bo; - const u8 *bi1 = _bi1, *bi2 = _bi2; - size_t itr; - for (itr = 0; itr < size; itr++) - bo[itr] = bi1[itr] ^ bi2[itr]; -} - /* Scratch space for MAC calculations. */ struct wusb_mac_scratch { struct aes_ccm_b0 b0; @@ -150,8 +143,7 @@ struct wusb_mac_scratch { * @a: ASCII string, 14 bytes long (I guess zero padded if needed; * we use exactly 14 bytes). * - * @b: data stream to be processed; cannot be a global or const local - * (will confuse the scatterlists) + * @b: data stream to be processed * * @blen: size of b... * @@ -160,16 +152,10 @@ struct wusb_mac_scratch { * @key. We bytewise xor B0 with B1 (1) and AES-crypt that. Then we * take the payload and divide it in blocks (16 bytes), xor them with * the previous crypto result (16 bytes) and crypt it, repeat the next - * block with the output of the previous one, rinse wash (I guess this - * is what AES CBC mode means...but I truly have no idea). So we use - * the CBC(AES) blkcipher, that does precisely that. The IV (Initial + * block with the output of the previous one, rinse wash. So we use + * the CBC-MAC(AES) shash, that does precisely that. The IV (Initial * Vector) is 16 bytes and is set to zero, so * - * See rfc3610. Linux crypto has a CBC implementation, but the - * documentation is scarce, to say the least, and the example code is - * so intricated that is difficult to understand how things work. Most - * of this is guess work -- bite me. - * * (1) Created as 6.5 says, again, using as l(a) 'Blen + 14', and * using the 14 bytes of @a to fill up * b1.{mac_header,e0,security_reserved,padding}. @@ -189,44 +175,24 @@ struct wusb_mac_scratch { * NOTE: blen is not aligned to a block size, we'll pad zeros, that's * what sg[4] is for. Maybe there is a smarter way to do this. */ -static int wusb_ccm_mac(struct crypto_sync_skcipher *tfm_cbc, - struct crypto_cipher *tfm_aes, +static int wusb_ccm_mac(struct crypto_shash *tfm_cbcmac, struct wusb_mac_scratch *scratch, void *mic, const struct aes_ccm_nonce *n, const struct aes_ccm_label *a, const void *b, size_t blen) { - int result = 0; - SYNC_SKCIPHER_REQUEST_ON_STACK(req, tfm_cbc); - struct scatterlist sg[4], sg_dst; - void *dst_buf; - size_t dst_size; - u8 *iv; - size_t zero_padding; + SHASH_DESC_ON_STACK(desc, tfm_cbcmac); + u8 iv[AES_BLOCK_SIZE]; /* * These checks should be compile time optimized out * ensure @a fills b1's mac_header and following fields */ - WARN_ON(sizeof(*a) != sizeof(scratch->b1) - sizeof(scratch->b1.la)); - WARN_ON(sizeof(scratch->b0) != sizeof(struct aes_ccm_block)); - WARN_ON(sizeof(scratch->b1) != sizeof(struct aes_ccm_block)); - WARN_ON(sizeof(scratch->ax) != sizeof(struct aes_ccm_block)); - - result = -ENOMEM; - zero_padding = blen % sizeof(struct aes_ccm_block); - if (zero_padding) - zero_padding = sizeof(struct aes_ccm_block) - zero_padding; - dst_size = blen + sizeof(scratch->b0) + sizeof(scratch->b1) + - zero_padding; - dst_buf = kzalloc(dst_size, GFP_KERNEL); - if (!dst_buf) - goto error_dst_buf; - - iv = kzalloc(crypto_sync_skcipher_ivsize(tfm_cbc), GFP_KERNEL); - if (!iv) - goto error_iv; + BUILD_BUG_ON(sizeof(*a) != sizeof(scratch->b1) - sizeof(scratch->b1.la)); + BUILD_BUG_ON(sizeof(scratch->b0) != sizeof(struct aes_ccm_block)); + BUILD_BUG_ON(sizeof(scratch->b1) != sizeof(struct aes_ccm_block)); + BUILD_BUG_ON(sizeof(scratch->ax) != sizeof(struct aes_ccm_block)); /* Setup B0 */ scratch->b0.flags = 0x59; /* Format B0 */ @@ -243,46 +209,28 @@ static int wusb_ccm_mac(struct crypto_sync_skcipher *tfm_cbc, scratch->b1.la = cpu_to_be16(blen + 14); memcpy(&scratch->b1.mac_header, a, sizeof(*a)); - sg_init_table(sg, ARRAY_SIZE(sg)); - sg_set_buf(&sg[0], &scratch->b0, sizeof(scratch->b0)); - sg_set_buf(&sg[1], &scratch->b1, sizeof(scratch->b1)); - sg_set_buf(&sg[2], b, blen); - /* 0 if well behaved :) */ - sg_set_page(&sg[3], ZERO_PAGE(0), zero_padding, 0); - sg_init_one(&sg_dst, dst_buf, dst_size); - - skcipher_request_set_sync_tfm(req, tfm_cbc); - skcipher_request_set_callback(req, 0, NULL, NULL); - skcipher_request_set_crypt(req, sg, &sg_dst, dst_size, iv); - result = crypto_skcipher_encrypt(req); - skcipher_request_zero(req); - if (result < 0) { - printk(KERN_ERR "E: can't compute CBC-MAC tag (MIC): %d\n", - result); - goto error_cbc_crypt; - } + desc->tfm = tfm_cbcmac; + crypto_shash_init(desc); + crypto_shash_update(desc, (u8 *)&scratch->b0, sizeof(scratch->b0) + + sizeof(scratch->b1)); + crypto_shash_finup(desc, b, blen, iv); /* Now we crypt the MIC Tag (*iv) with Ax -- values per WUSB1.0[6.5] * The procedure is to AES crypt the A0 block and XOR the MIC * Tag against it; we only do the first 8 bytes and place it * directly in the destination buffer. - * - * POS Crypto API: size is assumed to be AES's block size. - * Thanks for documenting it -- tip taken from airo.c */ scratch->ax.flags = 0x01; /* as per WUSB 1.0 spec */ scratch->ax.ccm_nonce = *n; scratch->ax.counter = 0; - crypto_cipher_encrypt_one(tfm_aes, (void *)&scratch->ax, - (void *)&scratch->ax); - bytewise_xor(mic, &scratch->ax, iv, 8); - result = 8; -error_cbc_crypt: - kfree(iv); -error_iv: - kfree(dst_buf); -error_dst_buf: - return result; + + /* reuse the CBC-MAC transform to perform the single block encryption */ + crypto_shash_digest(desc, (u8 *)&scratch->ax, sizeof(scratch->ax), + (u8 *)&scratch->ax); + + crypto_xor_cpy(mic, (u8 *)&scratch->ax, iv, 8); + + return 8; } /* @@ -298,45 +246,28 @@ ssize_t wusb_prf(void *out, size_t out_size, { ssize_t result, bytes = 0, bitr; struct aes_ccm_nonce n = *_n; - struct crypto_sync_skcipher *tfm_cbc; - struct crypto_cipher *tfm_aes; - struct wusb_mac_scratch *scratch; + struct crypto_shash *tfm_cbcmac; + struct wusb_mac_scratch scratch; u64 sfn = 0; __le64 sfn_le; - tfm_cbc = crypto_alloc_sync_skcipher("cbc(aes)", 0, 0); - if (IS_ERR(tfm_cbc)) { - result = PTR_ERR(tfm_cbc); - printk(KERN_ERR "E: can't load CBC(AES): %d\n", (int)result); - goto error_alloc_cbc; - } - result = crypto_sync_skcipher_setkey(tfm_cbc, key, 16); - if (result < 0) { - printk(KERN_ERR "E: can't set CBC key: %d\n", (int)result); - goto error_setkey_cbc; + tfm_cbcmac = crypto_alloc_shash("cbcmac(aes)", 0, 0); + if (IS_ERR(tfm_cbcmac)) { + result = PTR_ERR(tfm_cbcmac); + printk(KERN_ERR "E: can't load CBCMAC-AES: %d\n", (int)result); + goto error_alloc_cbcmac; } - tfm_aes = crypto_alloc_cipher("aes", 0, 0); - if (IS_ERR(tfm_aes)) { - result = PTR_ERR(tfm_aes); - printk(KERN_ERR "E: can't load AES: %d\n", (int)result); - goto error_alloc_aes; - } - result = crypto_cipher_setkey(tfm_aes, key, 16); + result = crypto_shash_setkey(tfm_cbcmac, key, AES_BLOCK_SIZE); if (result < 0) { - printk(KERN_ERR "E: can't set AES key: %d\n", (int)result); - goto error_setkey_aes; - } - scratch = kmalloc(sizeof(*scratch), GFP_KERNEL); - if (!scratch) { - result = -ENOMEM; - goto error_alloc_scratch; + printk(KERN_ERR "E: can't set CBCMAC-AES key: %d\n", (int)result); + goto error_setkey_cbcmac; } for (bitr = 0; bitr < (len + 63) / 64; bitr++) { sfn_le = cpu_to_le64(sfn++); memcpy(&n.sfn, &sfn_le, sizeof(n.sfn)); /* n.sfn++... */ - result = wusb_ccm_mac(tfm_cbc, tfm_aes, scratch, out + bytes, + result = wusb_ccm_mac(tfm_cbcmac, &scratch, out + bytes, &n, a, b, blen); if (result < 0) goto error_ccm_mac; @@ -344,15 +275,10 @@ ssize_t wusb_prf(void *out, size_t out_size, } result = bytes; - kfree(scratch); -error_alloc_scratch: error_ccm_mac: -error_setkey_aes: - crypto_free_cipher(tfm_aes); -error_alloc_aes: -error_setkey_cbc: - crypto_free_sync_skcipher(tfm_cbc); -error_alloc_cbc: +error_setkey_cbcmac: + crypto_free_shash(tfm_cbcmac); +error_alloc_cbcmac: return result; } @@ -377,12 +303,8 @@ static int wusb_oob_mic_verify(void) { int result; u8 mic[8]; - /* WUSB1.0[A.2] test vectors - * - * Need to keep it in the local stack as GCC 4.1.3something - * messes up and generates noise. - */ - struct usb_handshake stv_hsmic_hs = { + /* WUSB1.0[A.2] test vectors */ + static const struct usb_handshake stv_hsmic_hs = { .bMessageNumber = 2, .bStatus = 00, .tTKID = { 0x76, 0x98, 0x01 }, @@ -457,11 +379,8 @@ static int wusb_key_derive_verify(void) { int result = 0; struct wusb_keydvt_out keydvt_out; - /* These come from WUSB1.0[A.1] + 2006/12 errata - * NOTE: can't make this const or global -- somehow it seems - * the scatterlists for crypto get confused and we get - * bad data. There is no doc on this... */ - struct wusb_keydvt_in stv_keydvt_in_a1 = { + /* These come from WUSB1.0[A.1] + 2006/12 errata */ + static const struct wusb_keydvt_in stv_keydvt_in_a1 = { .hnonce = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f -- cgit v1.2.3 From d7863de8cdea75c9a4747621b1587fc70855460c Mon Sep 17 00:00:00 2001 From: Hans Ulli Kroll Date: Thu, 13 Jun 2019 17:07:35 +0200 Subject: usb: host: fotg2: add device tree probing Add device tree probing to the fotg2 driver. Signed-off-by: Hans Ulli Kroll [Drop DMA mask coercion, drivers/of/platform.c does the job] Signed-off-by: Linus Walleij Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/fotg210-hcd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c index 0da68df259c8..e835a22b12af 100644 --- a/drivers/usb/host/fotg210-hcd.c +++ b/drivers/usb/host/fotg210-hcd.c @@ -10,6 +10,7 @@ * Most of code borrowed from the Linux-3.7 EHCI driver */ #include +#include #include #include #include @@ -5669,9 +5670,18 @@ static int fotg210_hcd_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_OF +static const struct of_device_id fotg210_of_match[] = { + { .compatible = "faraday,fotg210" }, + {}, +}; +MODULE_DEVICE_TABLE(of, fotg210_of_match); +#endif + static struct platform_driver fotg210_hcd_driver = { .driver = { .name = "fotg210-hcd", + .of_match_table = of_match_ptr(fotg210_of_match), }, .probe = fotg210_hcd_probe, .remove = fotg210_hcd_remove, -- cgit v1.2.3 From f90db10779adab4b2bb12dd5de661616b6fda9e3 Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Fri, 14 Jun 2019 10:58:24 +0200 Subject: usb: dwc3: meson-g12a: Add support for IRQ based OTG switching Add support for the OTG ID change interrupt to switch between Host and Device mode. Tested on the Hardkernel Odroid-N2 board. Signed-off-by: Neil Armstrong Reviewed-by: Martin Blumenstingl Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/dwc3-meson-g12a.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c index 2aec31a2eacb..bca7e92a10e9 100644 --- a/drivers/usb/dwc3/dwc3-meson-g12a.c +++ b/drivers/usb/dwc3/dwc3-meson-g12a.c @@ -11,9 +11,7 @@ * - Control registers for each USB2 Ports * - Control registers for the USB PHY layer * - SuperSpeed PHY can be enabled only if port is used - * - * TOFIX: - * - Add dynamic OTG switching with ID change interrupt + * - Dynamic OTG switching with ID change interrupt */ #include @@ -348,6 +346,22 @@ static enum usb_role dwc3_meson_g12a_role_get(struct device *dev) USB_ROLE_HOST : USB_ROLE_DEVICE; } +static irqreturn_t dwc3_meson_g12a_irq_thread(int irq, void *data) +{ + struct dwc3_meson_g12a *priv = data; + enum phy_mode otg_id; + + otg_id = dwc3_meson_g12a_get_id(priv); + if (otg_id != priv->otg_phy_mode) { + if (dwc3_meson_g12a_otg_mode_set(priv, otg_id)) + dev_warn(priv->dev, "Failed to switch OTG mode\n"); + } + + regmap_update_bits(priv->regmap, USB_R5, USB_R5_ID_DIG_IRQ, 0); + + return IRQ_HANDLED; +} + static struct device *dwc3_meson_g12_find_child(struct device *dev, const char *compatible) { @@ -374,7 +388,7 @@ static int dwc3_meson_g12a_probe(struct platform_device *pdev) void __iomem *base; struct resource *res; enum phy_mode otg_id; - int ret, i; + int ret, i, irq; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -436,6 +450,19 @@ static int dwc3_meson_g12a_probe(struct platform_device *pdev) /* Get dr_mode */ priv->otg_mode = usb_get_dr_mode(dev); + if (priv->otg_mode == USB_DR_MODE_OTG) { + /* Ack irq before registering */ + regmap_update_bits(priv->regmap, USB_R5, + USB_R5_ID_DIG_IRQ, 0); + + irq = platform_get_irq(pdev, 0); + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + dwc3_meson_g12a_irq_thread, + IRQF_ONESHOT, pdev->name, priv); + if (ret) + return ret; + } + dwc3_meson_g12a_usb_init(priv); /* Init PHYs */ @@ -460,7 +487,6 @@ static int dwc3_meson_g12a_probe(struct platform_device *pdev) /* Setup OTG mode corresponding to the ID pin */ if (priv->otg_mode == USB_DR_MODE_OTG) { - /* TOFIX Handle ID mode toggling via IRQ */ otg_id = dwc3_meson_g12a_get_id(priv); if (otg_id != priv->otg_phy_mode) { if (dwc3_meson_g12a_otg_mode_set(priv, otg_id)) -- cgit v1.2.3 From 1112cf4c4109473fd8a30a4678d25f9321ef5d67 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Fri, 14 Jun 2019 08:52:53 +0200 Subject: usb: dwc2: Force 8bit UTMI width for Samsung Exynos SoCs Samsung Exynos SoCs require to force UTMI width to 8bit, otherwise the host side of the shared USB2 PHY doesn't work. Reported-by: Krzysztof Kozlowski Fixes: 707d80f0a3c5 ("usb: dwc2: gadget: Replace phyif with phy_utmi_width") Signed-off-by: Marek Szyprowski Acked-by: Minas Harutyunyan Acked-by: Krzysztof Kozlowski Tested-by: Krzysztof Kozlowski Signed-off-by: Felipe Balbi --- drivers/usb/dwc2/params.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c index 6900eea57526..9ece4affb9d4 100644 --- a/drivers/usb/dwc2/params.c +++ b/drivers/usb/dwc2/params.c @@ -76,6 +76,7 @@ static void dwc2_set_s3c6400_params(struct dwc2_hsotg *hsotg) struct dwc2_core_params *p = &hsotg->params; p->power_down = 0; + p->phy_utmi_width = 8; } static void dwc2_set_rk_params(struct dwc2_hsotg *hsotg) -- cgit v1.2.3 From cd5f9726773b654f8e1cfd6ec1a989c558fa164b Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Mon, 20 May 2019 10:56:03 -0700 Subject: Documentation: dt-bindings: Add snps,need-phy-for-wake for dwc2 USB Some SoCs with a dwc2 USB controller may need to keep the PHY on to support remote wakeup. Allow specifying this as a device tree property. Reviewed-by: Rob Herring Signed-off-by: Douglas Anderson Signed-off-by: Felipe Balbi --- Documentation/devicetree/bindings/usb/dwc2.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt b/Documentation/devicetree/bindings/usb/dwc2.txt index 49eac0dc86b0..aafff3a6904d 100644 --- a/Documentation/devicetree/bindings/usb/dwc2.txt +++ b/Documentation/devicetree/bindings/usb/dwc2.txt @@ -42,6 +42,8 @@ Refer to phy/phy-bindings.txt for generic phy consumer properties - g-rx-fifo-size: size of rx fifo size in gadget mode. - g-np-tx-fifo-size: size of non-periodic tx fifo size in gadget mode. - g-tx-fifo-size: size of periodic tx fifo per endpoint (except ep0) in gadget mode. +- snps,need-phy-for-wake: If present indicates that the phy needs to be left + on for remote wakeup during suspend. - snps,reset-phy-on-wake: If present indicates that we need to reset the PHY when we detect a wakeup. This is due to a hardware errata. @@ -58,4 +60,5 @@ Example: clock-names = "otg"; phys = <&usbphy>; phy-names = "usb2-phy"; + snps,need-phy-for-wake; }; -- cgit v1.2.3 From 1d390437f605db28596ad4c4bfeca2fed052c025 Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Mon, 20 May 2019 10:56:05 -0700 Subject: ARM: dts: rockchip: Allow wakeup from rk3288-veyron's dwc2 USB ports We want to be able to wake from USB if a device is plugged in that wants remote wakeup. Enable it on both dwc2 controllers. NOTE: this is added specifically to veyron and not to rk3288 in general since it's not known whether all rk3288 boards are designed to support USB wakeup. It is plausible that some boards could shut down important rails in S3. Also note that currently wakeup doesn't seem to happen unless you use the "deep" suspend mode (where SDRAM is turned off). Presumably the shallow suspend mode is gating some sort of clock that's important but I couldn't easily figure out how to get it working. Signed-off-by: Douglas Anderson Signed-off-by: Felipe Balbi --- arch/arm/boot/dts/rk3288-veyron.dtsi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm/boot/dts/rk3288-veyron.dtsi b/arch/arm/boot/dts/rk3288-veyron.dtsi index 1252522392c7..1d8bfed7830c 100644 --- a/arch/arm/boot/dts/rk3288-veyron.dtsi +++ b/arch/arm/boot/dts/rk3288-veyron.dtsi @@ -424,6 +424,7 @@ &usb_host1 { status = "okay"; + snps,need-phy-for-wake; }; &usb_otg { @@ -432,6 +433,7 @@ assigned-clocks = <&cru SCLK_USBPHY480M_SRC>; assigned-clock-parents = <&usbphy0>; dr_mode = "host"; + snps,need-phy-for-wake; }; &vopb { -- cgit v1.2.3 From c846b03ff767149d75d4d8dca6d3d4945a21074a Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Mon, 20 May 2019 10:56:04 -0700 Subject: USB: dwc2: Don't turn off the usbphy in suspend if wakeup is enabled If the 'snps,need-phy-for-wake' is set in the device tree then: - We know that we can wakeup, so call device_set_wakeup_capable(). The USB core will use this knowledge to enable wakeup by default. - We know that we should keep the PHY on during suspend if something on our root hub needs remote wakeup. This requires the patch (USB: Export usb_wakeup_enabled_descendants()). Note that we don't keep the PHY on at suspend time if it's not needed because it would be a power draw. If we later find some users of dwc2 that can support wakeup without keeping the PHY on we may want to add a way to call device_set_wakeup_capable() without keeping the PHY on at suspend time. Signed-off-by: Douglas Anderson Signed-off-by: Chris Zhong Signed-off-by: Felipe Balbi --- drivers/usb/dwc2/core.h | 8 ++++++++ drivers/usb/dwc2/hcd.c | 19 +++++++++++++++++++ drivers/usb/dwc2/platform.c | 23 ++++++++++++++++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 152ac41dfb2d..d08d070a0fb6 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -861,6 +861,9 @@ struct dwc2_hregs_backup { * @hibernated: True if core is hibernated * @reset_phy_on_wake: Quirk saying that we should assert PHY reset on a * remote wakeup. + * @phy_off_for_suspend: Status of whether we turned the PHY off at suspend. + * @need_phy_for_wake: Quirk saying that we should keep the PHY on at + * suspend if we need USB to wake us up. * @frame_number: Frame number read from the core. For both device * and host modes. The value ranges are from 0 * to HFNUM_MAX_FRNUM. @@ -1049,6 +1052,8 @@ struct dwc2_hsotg { unsigned int ll_hw_enabled:1; unsigned int hibernated:1; unsigned int reset_phy_on_wake:1; + unsigned int need_phy_for_wake:1; + unsigned int phy_off_for_suspend:1; u16 frame_number; struct phy *phy; @@ -1438,6 +1443,7 @@ int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg); int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg); int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup, int reset); +bool dwc2_host_can_poweroff_phy(struct dwc2_hsotg *dwc2); static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg) { schedule_work(&hsotg->phy_reset_work); } #else @@ -1463,6 +1469,8 @@ static inline int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg) static inline int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup, int reset) { return 0; } +static inline bool dwc2_host_can_poweroff_phy(struct dwc2_hsotg *dwc2) +{ return false; } static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg) {} #endif diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 2192a2873c7c..4c78a390c958 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -5587,3 +5587,22 @@ int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup, dev_dbg(hsotg->dev, "Host hibernation restore complete\n"); return ret; } + +bool dwc2_host_can_poweroff_phy(struct dwc2_hsotg *dwc2) +{ + struct usb_device *root_hub = dwc2_hsotg_to_hcd(dwc2)->self.root_hub; + + /* If the controller isn't allowed to wakeup then we can power off. */ + if (!device_may_wakeup(dwc2->dev)) + return true; + + /* + * We don't want to power off the PHY if something under the + * root hub has wakeup enabled. + */ + if (usb_wakeup_enabled_descendants(root_hub)) + return false; + + /* No reason to keep the PHY powered, so allow poweroff */ + return true; +} diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index d10a7f8daec3..3e6c3c8a32ff 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -447,6 +447,10 @@ static int dwc2_driver_probe(struct platform_device *dev) if (retval) goto error; + hsotg->need_phy_for_wake = + of_property_read_bool(dev->dev.of_node, + "snps,need-phy-for-wake"); + /* * Reset before dwc2_get_hwparams() then it could get power-on real * reset value form registers. @@ -478,6 +482,14 @@ static int dwc2_driver_probe(struct platform_device *dev) hsotg->gadget_enabled = 1; } + /* + * If we need PHY for wakeup we must be wakeup capable. + * When we have a device that can wake without the PHY we + * can adjust this condition. + */ + if (hsotg->need_phy_for_wake) + device_set_wakeup_capable(&dev->dev, true); + hsotg->reset_phy_on_wake = of_property_read_bool(dev->dev.of_node, "snps,reset-phy-on-wake"); @@ -516,13 +528,17 @@ error: static int __maybe_unused dwc2_suspend(struct device *dev) { struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev); + bool is_device_mode = dwc2_is_device_mode(dwc2); int ret = 0; - if (dwc2_is_device_mode(dwc2)) + if (is_device_mode) dwc2_hsotg_suspend(dwc2); - if (dwc2->ll_hw_enabled) + if (dwc2->ll_hw_enabled && + (is_device_mode || dwc2_host_can_poweroff_phy(dwc2))) { ret = __dwc2_lowlevel_hw_disable(dwc2); + dwc2->phy_off_for_suspend = true; + } return ret; } @@ -532,11 +548,12 @@ static int __maybe_unused dwc2_resume(struct device *dev) struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev); int ret = 0; - if (dwc2->ll_hw_enabled) { + if (dwc2->phy_off_for_suspend && dwc2->ll_hw_enabled) { ret = __dwc2_lowlevel_hw_enable(dwc2); if (ret) return ret; } + dwc2->phy_off_for_suspend = false; if (dwc2_is_device_mode(dwc2)) ret = dwc2_hsotg_resume(dwc2); -- cgit v1.2.3 From 4833a94eb383f5b22775077ff92ddaae90440921 Mon Sep 17 00:00:00 2001 From: Fei Yang Date: Wed, 12 Jun 2019 15:13:26 -0700 Subject: usb: gadget: f_fs: data_len used before properly set The following line of code in function ffs_epfile_io is trying to set flag io_data->use_sg in case buffer required is larger than one page. io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; However at this point of time the variable data_len has not been set to the proper buffer size yet. The consequence is that io_data->use_sg is always set regardless what buffer size really is, because the condition (data_len > PAGE_SIZE) is effectively an unsigned comparison between -EINVAL and PAGE_SIZE which would always result in TRUE. Fixes: 772a7a724f69 ("usb: gadget: f_fs: Allow scatter-gather buffers") Signed-off-by: Fei Yang Cc: stable Signed-off-by: Felipe Balbi --- drivers/usb/gadget/function/f_fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 47be961f1bf3..c7ed90084d1a 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -997,7 +997,6 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) * earlier */ gadget = epfile->ffs->gadget; - io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; spin_lock_irq(&epfile->ffs->eps_lock); /* In the meantime, endpoint got disabled or changed. */ @@ -1012,6 +1011,8 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) */ if (io_data->read) data_len = usb_ep_align_maybe(gadget, ep->ep, data_len); + + io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; spin_unlock_irq(&epfile->ffs->eps_lock); data = ffs_alloc_buffer(io_data, data_len); -- cgit v1.2.3 From f4408a98c4e6f90af032bc473f987acd89fd81d9 Mon Sep 17 00:00:00 2001 From: Jonas Stenvall Date: Thu, 13 Jun 2019 11:34:33 +0200 Subject: usb: gadget: u_audio: Fixed variable declaration coding style issue Fixed a coding style issue, replacing unsigned with unsigned int. Reviewed-by: Eugeniu Rosca Signed-off-by: Jonas Stenvall Signed-off-by: Felipe Balbi --- drivers/usb/gadget/function/u_audio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index fb5ed97572e5..56906d15fb55 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -40,7 +40,7 @@ struct uac_rtd_params { void *rbuf; - unsigned max_psize; /* MaxPacketSize of endpoint */ + unsigned int max_psize; /* MaxPacketSize of endpoint */ struct uac_req *ureq; spinlock_t lock; @@ -78,7 +78,7 @@ static const struct snd_pcm_hardware uac_pcm_hardware = { static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) { - unsigned pending; + unsigned int pending; unsigned long flags, flags2; unsigned int hw_ptr; int status = req->status; -- cgit v1.2.3 From 0604160d8c0b6082727182398d432a68bdd58872 Mon Sep 17 00:00:00 2001 From: Biju Das Date: Fri, 31 May 2019 10:59:57 +0100 Subject: usb: gadget: udc: renesas_usb3: Enhance role switch support The RZ/G2E cat874 board has a type-c connector connected to hd3ss3220 usb type-c drp port controller. Enhance role switch support to assign the role requested by connector device using the usb role switch class framework. Reviewed-by: Yoshihiro Shimoda Tested-by: Yoshihiro Shimoda Signed-off-by: Biju Das Signed-off-by: Felipe Balbi --- drivers/usb/gadget/udc/renesas_usb3.c | 91 ++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 7 deletions(-) diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c index 7dc248546fd4..5a960fce31c5 100644 --- a/drivers/usb/gadget/udc/renesas_usb3.c +++ b/drivers/usb/gadget/udc/renesas_usb3.c @@ -351,6 +351,8 @@ struct renesas_usb3 { int disabled_count; struct usb_request *ep0_req; + + enum usb_role connection_state; u16 test_mode; u8 ep0_buf[USB3_EP0_BUF_SIZE]; bool softconnect; @@ -359,6 +361,7 @@ struct renesas_usb3 { bool extcon_usb; /* check vbus and set EXTCON_USB */ bool forced_b_device; bool start_to_connect; + bool role_sw_by_connector; }; #define gadget_to_renesas_usb3(_gadget) \ @@ -699,8 +702,11 @@ static void usb3_mode_config(struct renesas_usb3 *usb3, bool host, bool a_dev) unsigned long flags; spin_lock_irqsave(&usb3->lock, flags); - usb3_set_mode_by_role_sw(usb3, host); - usb3_vbus_out(usb3, a_dev); + if (!usb3->role_sw_by_connector || + usb3->connection_state != USB_ROLE_NONE) { + usb3_set_mode_by_role_sw(usb3, host); + usb3_vbus_out(usb3, a_dev); + } /* for A-Peripheral or forced B-device mode */ if ((!host && a_dev) || usb3->start_to_connect) usb3_connect(usb3); @@ -716,7 +722,8 @@ static void usb3_check_id(struct renesas_usb3 *usb3) { usb3->extcon_host = usb3_is_a_device(usb3); - if (usb3->extcon_host && !usb3->forced_b_device) + if ((!usb3->role_sw_by_connector && usb3->extcon_host && + !usb3->forced_b_device) || usb3->connection_state == USB_ROLE_HOST) usb3_mode_config(usb3, true, true); else usb3_mode_config(usb3, false, false); @@ -2343,14 +2350,65 @@ static enum usb_role renesas_usb3_role_switch_get(struct device *dev) return cur_role; } -static int renesas_usb3_role_switch_set(struct device *dev, - enum usb_role role) +static void handle_ext_role_switch_states(struct device *dev, + enum usb_role role) +{ + struct renesas_usb3 *usb3 = dev_get_drvdata(dev); + struct device *host = usb3->host_dev; + enum usb_role cur_role = renesas_usb3_role_switch_get(dev); + + switch (role) { + case USB_ROLE_NONE: + usb3->connection_state = USB_ROLE_NONE; + if (usb3->driver) + usb3_disconnect(usb3); + usb3_vbus_out(usb3, false); + break; + case USB_ROLE_DEVICE: + if (usb3->connection_state == USB_ROLE_NONE) { + usb3->connection_state = USB_ROLE_DEVICE; + usb3_set_mode(usb3, false); + if (usb3->driver) + usb3_connect(usb3); + } else if (cur_role == USB_ROLE_HOST) { + device_release_driver(host); + usb3_set_mode(usb3, false); + if (usb3->driver) + usb3_connect(usb3); + } + usb3_vbus_out(usb3, false); + break; + case USB_ROLE_HOST: + if (usb3->connection_state == USB_ROLE_NONE) { + if (usb3->driver) + usb3_disconnect(usb3); + + usb3->connection_state = USB_ROLE_HOST; + usb3_set_mode(usb3, true); + usb3_vbus_out(usb3, true); + if (device_attach(host) < 0) + dev_err(dev, "device_attach(host) failed\n"); + } else if (cur_role == USB_ROLE_DEVICE) { + usb3_disconnect(usb3); + /* Must set the mode before device_attach of the host */ + usb3_set_mode(usb3, true); + /* This device_attach() might sleep */ + if (device_attach(host) < 0) + dev_err(dev, "device_attach(host) failed\n"); + } + break; + default: + break; + } +} + +static void handle_role_switch_states(struct device *dev, + enum usb_role role) { struct renesas_usb3 *usb3 = dev_get_drvdata(dev); struct device *host = usb3->host_dev; enum usb_role cur_role = renesas_usb3_role_switch_get(dev); - pm_runtime_get_sync(dev); if (cur_role == USB_ROLE_HOST && role == USB_ROLE_DEVICE) { device_release_driver(host); usb3_set_mode(usb3, false); @@ -2361,6 +2419,20 @@ static int renesas_usb3_role_switch_set(struct device *dev, if (device_attach(host) < 0) dev_err(dev, "device_attach(host) failed\n"); } +} + +static int renesas_usb3_role_switch_set(struct device *dev, + enum usb_role role) +{ + struct renesas_usb3 *usb3 = dev_get_drvdata(dev); + + pm_runtime_get_sync(dev); + + if (usb3->role_sw_by_connector) + handle_ext_role_switch_states(dev, role); + else + handle_role_switch_states(dev, role); + pm_runtime_put(dev); return 0; @@ -2650,7 +2722,7 @@ static const unsigned int renesas_usb3_cable[] = { EXTCON_NONE, }; -static const struct usb_role_switch_desc renesas_usb3_role_switch_desc = { +static struct usb_role_switch_desc renesas_usb3_role_switch_desc = { .set = renesas_usb3_role_switch_set, .get = renesas_usb3_role_switch_get, .allow_userspace_control = true, @@ -2741,6 +2813,11 @@ static int renesas_usb3_probe(struct platform_device *pdev) if (ret < 0) goto err_dev_create; + if (device_property_read_bool(&pdev->dev, "usb-role-switch")) { + usb3->role_sw_by_connector = true; + renesas_usb3_role_switch_desc.fwnode = dev_fwnode(&pdev->dev); + } + INIT_WORK(&usb3->role_work, renesas_usb3_role_work); usb3->role_sw = usb_role_switch_register(&pdev->dev, &renesas_usb3_role_switch_desc); -- cgit v1.2.3 From 67929a7ded5263106931521c3455e3250f0a26ff Mon Sep 17 00:00:00 2001 From: Hariprasad Kelam Date: Wed, 5 Jun 2019 19:42:53 +0530 Subject: usb: gadget: at91_udc: Remove unneeded variable at91_wakeup is always returning -EINVAL. But usb_gadget_wakeup expects 0 on success and negative number on failure. As per current implementation this function wont fail. This patch removes unneeded variable and returns 0. Issue identified by coccicheck drivers/usb/gadget/udc/at91_udc.c:802:6-12: Unneeded variable: "status". Return "- EINVAL" on line 821 Signed-off-by: Hariprasad Kelam Signed-off-by: Felipe Balbi --- drivers/usb/gadget/udc/at91_udc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c index 03959dc86cfd..194ffb1ed462 100644 --- a/drivers/usb/gadget/udc/at91_udc.c +++ b/drivers/usb/gadget/udc/at91_udc.c @@ -799,7 +799,6 @@ static int at91_wakeup(struct usb_gadget *gadget) { struct at91_udc *udc = to_udc(gadget); u32 glbstate; - int status = -EINVAL; unsigned long flags; DBG("%s\n", __func__ ); @@ -818,7 +817,7 @@ static int at91_wakeup(struct usb_gadget *gadget) done: spin_unlock_irqrestore(&udc->lock, flags); - return status; + return 0; } /* reinit == restore initial software state */ -- cgit v1.2.3 From 811e5c3d3c4adf0b037fab3417395d3060a4492a Mon Sep 17 00:00:00 2001 From: Hariprasad Kelam Date: Wed, 5 Jun 2019 17:41:17 +0530 Subject: fotg210-udc: Remove unneeded variable This patch fixes below warning reported by coccicheck drivers/usb/gadget/udc/fotg210-udc.c:484:5-8: Unneeded variable: "ret". Return "0" on line 507 Signed-off-by: Hariprasad Kelam Signed-off-by: Felipe Balbi --- drivers/usb/gadget/udc/fotg210-udc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c index cec49294bac6..21f3e6c4e4d6 100644 --- a/drivers/usb/gadget/udc/fotg210-udc.c +++ b/drivers/usb/gadget/udc/fotg210-udc.c @@ -481,7 +481,6 @@ static int fotg210_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedge) struct fotg210_ep *ep; struct fotg210_udc *fotg210; unsigned long flags; - int ret = 0; ep = container_of(_ep, struct fotg210_ep, ep); @@ -504,7 +503,7 @@ static int fotg210_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedge) } spin_unlock_irqrestore(&ep->fotg210->lock, flags); - return ret; + return 0; } static int fotg210_ep_set_halt(struct usb_ep *_ep, int value) -- cgit v1.2.3 From 48f5e7493a6a0ac2cf6cf41835495a1f67f4a57c Mon Sep 17 00:00:00 2001 From: Hariprasad Kelam Date: Wed, 5 Jun 2019 17:34:25 +0530 Subject: USB: omap_udc: Remove unneeded variable With the current implementation omap_udc_stop is always returning -ENODEV. Added changes to return 0 and remove variable status. Issue identified with coccicheck drivers/usb/gadget/udc/omap_udc.c:2106:6-12: Unneeded variable: "status". Return "- ENODEV" on line 2128 Signed-off-by: Hariprasad Kelam Signed-off-by: Felipe Balbi --- drivers/usb/gadget/udc/omap_udc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c index fcf13ef33b31..f36f0730afab 100644 --- a/drivers/usb/gadget/udc/omap_udc.c +++ b/drivers/usb/gadget/udc/omap_udc.c @@ -2103,7 +2103,6 @@ done: static int omap_udc_stop(struct usb_gadget *g) { unsigned long flags; - int status = -ENODEV; if (udc->dc_clk != NULL) omap_udc_enable_clock(1); @@ -2125,7 +2124,7 @@ static int omap_udc_stop(struct usb_gadget *g) if (udc->dc_clk != NULL) omap_udc_enable_clock(0); - return status; + return 0; } /*-------------------------------------------------------------------------*/ -- cgit v1.2.3 From 508595515f4bcfe36246e4a565cf280937aeaade Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Mon, 3 Jun 2019 19:05:28 +0200 Subject: usb: gadget: Zero ffs_io_data In some cases the "Allocate & copy" block in ffs_epfile_io() is not executed. Consequently, in such a case ffs_alloc_buffer() is never called and struct ffs_io_data is not initialized properly. This in turn leads to problems when ffs_free_buffer() is called at the end of ffs_epfile_io(). This patch uses kzalloc() instead of kmalloc() in the aio case and memset() in non-aio case to properly initialize struct ffs_io_data. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi --- drivers/usb/gadget/function/f_fs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index c7ed90084d1a..213ff03c8a9f 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -1183,11 +1183,12 @@ static ssize_t ffs_epfile_write_iter(struct kiocb *kiocb, struct iov_iter *from) ENTER(); if (!is_sync_kiocb(kiocb)) { - p = kmalloc(sizeof(io_data), GFP_KERNEL); + p = kzalloc(sizeof(io_data), GFP_KERNEL); if (unlikely(!p)) return -ENOMEM; p->aio = true; } else { + memset(p, 0, sizeof(*p)); p->aio = false; } @@ -1219,11 +1220,12 @@ static ssize_t ffs_epfile_read_iter(struct kiocb *kiocb, struct iov_iter *to) ENTER(); if (!is_sync_kiocb(kiocb)) { - p = kmalloc(sizeof(io_data), GFP_KERNEL); + p = kzalloc(sizeof(io_data), GFP_KERNEL); if (unlikely(!p)) return -ENOMEM; p->aio = true; } else { + memset(p, 0, sizeof(*p)); p->aio = false; } -- cgit v1.2.3 From d78cc1a4b72a455ae53c434ddb8835035a332c5b Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 30 May 2019 19:14:58 +0100 Subject: usb: gadget: net2272: remove redundant assignments to pointer 's' The pointer 's' is being assigned however the pointer is never used with either of these values before it it reassigned much later on. I suspect it was going to be used in the output of the main control registers scnprintf but was omitted. The assignments of 's' to the driver name or the literal string are redundant and can be removed. Addresses-Coverity: ("Unused value") Signed-off-by: Colin Ian King Signed-off-by: Felipe Balbi --- drivers/usb/gadget/udc/net2272.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/usb/gadget/udc/net2272.c b/drivers/usb/gadget/udc/net2272.c index 564aeee1a1fe..247de0faaeb7 100644 --- a/drivers/usb/gadget/udc/net2272.c +++ b/drivers/usb/gadget/udc/net2272.c @@ -1178,11 +1178,6 @@ registers_show(struct device *_dev, struct device_attribute *attr, char *buf) size = PAGE_SIZE; spin_lock_irqsave(&dev->lock, flags); - if (dev->driver) - s = dev->driver->driver.name; - else - s = "(none)"; - /* Main Control Registers */ t = scnprintf(next, size, "%s version %s," "chiprev %02x, locctl %02x\n" -- cgit v1.2.3 From ad408a1596b45868e38d0504f2ec1d5fb06f17d4 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 29 May 2019 13:54:43 -0700 Subject: Revert "usb: dwc2: host: Setting qtd to NULL after freeing it" This reverts commit b0d659022e5c96ee5c4bd62d22d3da2d66de306b. The reverted commit does nothing but adding two unnecessary lines of code. It sets a local variable to NULL in two functions, but that variable is not used anywhere in the rest of those functions. This is just confusing, so let's remove it. Cc: Vardan Mikayelyan Cc: John Youn Cc: Douglas Anderson Cc: Felipe Balbi Acked-by: Minas Harutyunyan Reviewed-by: Douglas Anderson Signed-off-by: Guenter Roeck Signed-off-by: Felipe Balbi --- drivers/usb/dwc2/hcd.c | 1 - drivers/usb/dwc2/hcd.h | 1 - 2 files changed, 2 deletions(-) diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 4c78a390c958..ee144ff8af5b 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -4685,7 +4685,6 @@ fail2: spin_unlock_irqrestore(&hsotg->lock, flags); urb->hcpriv = NULL; kfree(qtd); - qtd = NULL; fail1: if (qh_allocated) { struct dwc2_qtd *qtd2, *qtd2_tmp; diff --git a/drivers/usb/dwc2/hcd.h b/drivers/usb/dwc2/hcd.h index ce6445a06588..8ca6d12a6f57 100644 --- a/drivers/usb/dwc2/hcd.h +++ b/drivers/usb/dwc2/hcd.h @@ -582,7 +582,6 @@ static inline void dwc2_hcd_qtd_unlink_and_free(struct dwc2_hsotg *hsotg, { list_del(&qtd->qtd_list_entry); kfree(qtd); - qtd = NULL; } /* Descriptor DMA support functions */ -- cgit v1.2.3 From 8bc529b25354d4ed1dcd3d3663ada5775e7acaec Mon Sep 17 00:00:00 2001 From: Lee Jones Date: Mon, 17 Jun 2019 13:51:02 +0100 Subject: soc: qcom: geni: Add support for ACPI When booting with ACPI as the active set of configuration tables, all; clocks, regulators, pin functions ect are expected to be at their ideal values/levels/rates, thus the associated frameworks are unavailable. Ensure calls to these APIs are shielded when ACPI is enabled. Signed-off-by: Lee Jones Acked-by: Ard Biesheuvel Signed-off-by: Felipe Balbi --- drivers/soc/qcom/qcom-geni-se.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c index 6b8ef01472e9..d5cf953b4337 100644 --- a/drivers/soc/qcom/qcom-geni-se.c +++ b/drivers/soc/qcom/qcom-geni-se.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. +#include #include #include #include @@ -450,6 +451,9 @@ int geni_se_resources_off(struct geni_se *se) { int ret; + if (has_acpi_companion(se->dev)) + return 0; + ret = pinctrl_pm_select_sleep_state(se->dev); if (ret) return ret; @@ -487,6 +491,9 @@ int geni_se_resources_on(struct geni_se *se) { int ret; + if (has_acpi_companion(se->dev)) + return 0; + ret = geni_se_clks_on(se); if (ret) return ret; @@ -724,12 +731,14 @@ static int geni_se_probe(struct platform_device *pdev) if (IS_ERR(wrapper->base)) return PTR_ERR(wrapper->base); - wrapper->ahb_clks[0].id = "m-ahb"; - wrapper->ahb_clks[1].id = "s-ahb"; - ret = devm_clk_bulk_get(dev, NUM_AHB_CLKS, wrapper->ahb_clks); - if (ret) { - dev_err(dev, "Err getting AHB clks %d\n", ret); - return ret; + if (!has_acpi_companion(&pdev->dev)) { + wrapper->ahb_clks[0].id = "m-ahb"; + wrapper->ahb_clks[1].id = "s-ahb"; + ret = devm_clk_bulk_get(dev, NUM_AHB_CLKS, wrapper->ahb_clks); + if (ret) { + dev_err(dev, "Err getting AHB clks %d\n", ret); + return ret; + } } dev_set_drvdata(dev, wrapper); -- cgit v1.2.3 From 2bc02355f8ba2c1f108ec8b16a673b467a17228c Mon Sep 17 00:00:00 2001 From: Lee Jones Date: Mon, 17 Jun 2019 13:51:03 +0100 Subject: usb: dwc3: qcom: Add support for booting with ACPI In Linux, the DWC3 core exists as its own independent platform device. Thus when describing relationships in Device Tree, the current default boot configuration table option, the DWC3 core often resides as a child of the platform specific node. Both of which are given their own address space descriptions and the drivers can be mostly agnostic to each other. However, other Operating Systems have taken a more monolithic approach, which is evident in the configuration ACPI tables for the Qualcomm Snapdragon SDM850, where all DWC3 (core and platform) components are described under a single IO memory region. To ensure successful booting using the supplied ACPI tables, we need to devise a way to chop up the address regions provided and subsequently register the DWC3 core with the resultant information, which is precisely what this patch aims to achieve. Signed-off-by: Lee Jones Reviewed-by: Bjorn Andersson Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/Kconfig | 2 +- drivers/usb/dwc3/dwc3-qcom.c | 206 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 179 insertions(+), 29 deletions(-) diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 4a62045cc812..89abc6078703 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -128,7 +128,7 @@ config USB_DWC3_QCOM tristate "Qualcomm Platform" depends on ARCH_QCOM || COMPILE_TEST depends on EXTCON || !EXTCON - depends on OF + depends on (OF || ACPI) default USB_DWC3 help Some Qualcomm SoCs use DesignWare Core IP for USB2/3 diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 184df4daa590..0cb63f6c92d9 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -4,6 +4,7 @@ * Inspired by dwc3-of-simple.c */ +#include #include #include #include @@ -38,6 +39,20 @@ #define PWR_EVNT_LPM_IN_L2_MASK BIT(4) #define PWR_EVNT_LPM_OUT_L2_MASK BIT(5) +#define SDM845_QSCRATCH_BASE_OFFSET 0xf8800 +#define SDM845_QSCRATCH_SIZE 0x400 +#define SDM845_DWC3_CORE_SIZE 0xcd00 + +struct dwc3_acpi_pdata { + u32 qscratch_base_offset; + u32 qscratch_base_size; + u32 dwc3_core_base_size; + int hs_phy_irq_index; + int dp_hs_phy_irq_index; + int dm_hs_phy_irq_index; + int ss_phy_irq_index; +}; + struct dwc3_qcom { struct device *dev; void __iomem *qscratch_base; @@ -56,6 +71,8 @@ struct dwc3_qcom { struct notifier_block vbus_nb; struct notifier_block host_nb; + const struct dwc3_acpi_pdata *acpi_pdata; + enum usb_dr_mode mode; bool is_suspended; bool pm_suspended; @@ -300,12 +317,27 @@ static void dwc3_qcom_select_utmi_clk(struct dwc3_qcom *qcom) PIPE_UTMI_CLK_DIS); } +static int dwc3_qcom_get_irq(struct platform_device *pdev, + const char *name, int num) +{ + struct device_node *np = pdev->dev.of_node; + int ret; + + if (np) + ret = platform_get_irq_byname(pdev, name); + else + ret = platform_get_irq(pdev, num); + + return ret; +} + static int dwc3_qcom_setup_irq(struct platform_device *pdev) { struct dwc3_qcom *qcom = platform_get_drvdata(pdev); + const struct dwc3_acpi_pdata *pdata = qcom->acpi_pdata; int irq, ret; - - irq = platform_get_irq_byname(pdev, "hs_phy_irq"); + irq = dwc3_qcom_get_irq(pdev, "hs_phy_irq", + pdata ? pdata->hs_phy_irq_index : -1); if (irq > 0) { /* Keep wakeup interrupts disabled until suspend */ irq_set_status_flags(irq, IRQ_NOAUTOEN); @@ -320,7 +352,8 @@ static int dwc3_qcom_setup_irq(struct platform_device *pdev) qcom->hs_phy_irq = irq; } - irq = platform_get_irq_byname(pdev, "dp_hs_phy_irq"); + irq = dwc3_qcom_get_irq(pdev, "dp_hs_phy_irq", + pdata ? pdata->dp_hs_phy_irq_index : -1); if (irq > 0) { irq_set_status_flags(irq, IRQ_NOAUTOEN); ret = devm_request_threaded_irq(qcom->dev, irq, NULL, @@ -334,7 +367,8 @@ static int dwc3_qcom_setup_irq(struct platform_device *pdev) qcom->dp_hs_phy_irq = irq; } - irq = platform_get_irq_byname(pdev, "dm_hs_phy_irq"); + irq = dwc3_qcom_get_irq(pdev, "dm_hs_phy_irq", + pdata ? pdata->dm_hs_phy_irq_index : -1); if (irq > 0) { irq_set_status_flags(irq, IRQ_NOAUTOEN); ret = devm_request_threaded_irq(qcom->dev, irq, NULL, @@ -348,7 +382,8 @@ static int dwc3_qcom_setup_irq(struct platform_device *pdev) qcom->dm_hs_phy_irq = irq; } - irq = platform_get_irq_byname(pdev, "ss_phy_irq"); + irq = dwc3_qcom_get_irq(pdev, "ss_phy_irq", + pdata ? pdata->ss_phy_irq_index : -1); if (irq > 0) { irq_set_status_flags(irq, IRQ_NOAUTOEN); ret = devm_request_threaded_irq(qcom->dev, irq, NULL, @@ -371,11 +406,11 @@ static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count) struct device_node *np = dev->of_node; int i; - qcom->num_clocks = count; - - if (!count) + if (!np || !count) return 0; + qcom->num_clocks = count; + qcom->clks = devm_kcalloc(dev, qcom->num_clocks, sizeof(struct clk *), GFP_KERNEL); if (!qcom->clks) @@ -409,12 +444,103 @@ static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count) return 0; } -static int dwc3_qcom_probe(struct platform_device *pdev) +static int dwc3_qcom_acpi_register_core(struct platform_device *pdev) { + struct dwc3_qcom *qcom = platform_get_drvdata(pdev); + struct device *dev = &pdev->dev; + struct resource *res, *child_res = NULL; + int irq; + int ret; + + qcom->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); + if (!qcom->dwc3) + return -ENOMEM; + + qcom->dwc3->dev.parent = dev; + qcom->dwc3->dev.type = dev->type; + qcom->dwc3->dev.dma_mask = dev->dma_mask; + qcom->dwc3->dev.dma_parms = dev->dma_parms; + qcom->dwc3->dev.coherent_dma_mask = dev->coherent_dma_mask; + + child_res = kcalloc(2, sizeof(*child_res), GFP_KERNEL); + if (!child_res) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, "failed to get memory resource\n"); + ret = -ENODEV; + goto out; + } + + child_res[0].flags = res->flags; + child_res[0].start = res->start; + child_res[0].end = child_res[0].start + + qcom->acpi_pdata->dwc3_core_base_size; + + irq = platform_get_irq(pdev, 0); + child_res[1].flags = IORESOURCE_IRQ; + child_res[1].start = child_res[1].end = irq; + + ret = platform_device_add_resources(qcom->dwc3, child_res, 2); + if (ret) { + dev_err(&pdev->dev, "failed to add resources\n"); + goto out; + } + + ret = platform_device_add(qcom->dwc3); + if (ret) + dev_err(&pdev->dev, "failed to add device\n"); + +out: + kfree(child_res); + return ret; +} + +static int dwc3_qcom_of_register_core(struct platform_device *pdev) +{ + struct dwc3_qcom *qcom = platform_get_drvdata(pdev); struct device_node *np = pdev->dev.of_node, *dwc3_np; struct device *dev = &pdev->dev; + int ret; + + dwc3_np = of_get_child_by_name(np, "dwc3"); + if (!dwc3_np) { + dev_err(dev, "failed to find dwc3 core child\n"); + return -ENODEV; + } + + ret = of_platform_populate(np, NULL, NULL, dev); + if (ret) { + dev_err(dev, "failed to register dwc3 core - %d\n", ret); + return ret; + } + + qcom->dwc3 = of_find_device_by_node(dwc3_np); + if (!qcom->dwc3) { + dev_err(dev, "failed to get dwc3 platform device\n"); + return -ENODEV; + } + + return 0; +} + +static const struct dwc3_acpi_pdata sdm845_acpi_pdata = { + .qscratch_base_offset = SDM845_QSCRATCH_BASE_OFFSET, + .qscratch_base_size = SDM845_QSCRATCH_SIZE, + .dwc3_core_base_size = SDM845_DWC3_CORE_SIZE, + .hs_phy_irq_index = 1, + .dp_hs_phy_irq_index = 4, + .dm_hs_phy_irq_index = 3, + .ss_phy_irq_index = 2 +}; + +static int dwc3_qcom_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; struct dwc3_qcom *qcom; - struct resource *res; + struct resource *res, *parent_res = NULL; int ret, i; bool ignore_pipe_clk; @@ -425,6 +551,14 @@ static int dwc3_qcom_probe(struct platform_device *pdev) platform_set_drvdata(pdev, qcom); qcom->dev = &pdev->dev; + if (has_acpi_companion(dev)) { + qcom->acpi_pdata = acpi_device_get_match_data(dev); + if (!qcom->acpi_pdata) { + dev_err(&pdev->dev, "no supporting ACPI device data\n"); + return -EINVAL; + } + } + qcom->resets = devm_reset_control_array_get_optional_exclusive(dev); if (IS_ERR(qcom->resets)) { ret = PTR_ERR(qcom->resets); @@ -454,7 +588,21 @@ static int dwc3_qcom_probe(struct platform_device *pdev) } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - qcom->qscratch_base = devm_ioremap_resource(dev, res); + + if (np) { + parent_res = res; + } else { + parent_res = kmemdup(res, sizeof(struct resource), GFP_KERNEL); + if (!parent_res) + return -ENOMEM; + + parent_res->start = res->start + + qcom->acpi_pdata->qscratch_base_offset; + parent_res->end = parent_res->start + + qcom->acpi_pdata->qscratch_base_size; + } + + qcom->qscratch_base = devm_ioremap_resource(dev, parent_res); if (IS_ERR(qcom->qscratch_base)) { dev_err(dev, "failed to map qscratch, err=%d\n", ret); ret = PTR_ERR(qcom->qscratch_base); @@ -462,13 +610,8 @@ static int dwc3_qcom_probe(struct platform_device *pdev) } ret = dwc3_qcom_setup_irq(pdev); - if (ret) - goto clk_disable; - - dwc3_np = of_get_child_by_name(np, "dwc3"); - if (!dwc3_np) { - dev_err(dev, "failed to find dwc3 core child\n"); - ret = -ENODEV; + if (ret) { + dev_err(dev, "failed to setup IRQs, err=%d\n", ret); goto clk_disable; } @@ -481,16 +624,13 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (ignore_pipe_clk) dwc3_qcom_select_utmi_clk(qcom); - ret = of_platform_populate(np, NULL, NULL, dev); - if (ret) { - dev_err(dev, "failed to register dwc3 core - %d\n", ret); - goto clk_disable; - } + if (np) + ret = dwc3_qcom_of_register_core(pdev); + else + ret = dwc3_qcom_acpi_register_core(pdev); - qcom->dwc3 = of_find_device_by_node(dwc3_np); - if (!qcom->dwc3) { - dev_err(&pdev->dev, "failed to get dwc3 platform device\n"); - ret = -ENODEV; + if (ret) { + dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret); goto depopulate; } @@ -514,7 +654,10 @@ static int dwc3_qcom_probe(struct platform_device *pdev) return 0; depopulate: - of_platform_depopulate(&pdev->dev); + if (np) + of_platform_depopulate(&pdev->dev); + else + platform_device_put(pdev); clk_disable: for (i = qcom->num_clocks - 1; i >= 0; i--) { clk_disable_unprepare(qcom->clks[i]); @@ -601,6 +744,12 @@ static const struct of_device_id dwc3_qcom_of_match[] = { }; MODULE_DEVICE_TABLE(of, dwc3_qcom_of_match); +static const struct acpi_device_id dwc3_qcom_acpi_match[] = { + { "QCOM2430", (unsigned long)&sdm845_acpi_pdata }, + { }, +}; +MODULE_DEVICE_TABLE(acpi, dwc3_qcom_acpi_match); + static struct platform_driver dwc3_qcom_driver = { .probe = dwc3_qcom_probe, .remove = dwc3_qcom_remove, @@ -608,6 +757,7 @@ static struct platform_driver dwc3_qcom_driver = { .name = "dwc3-qcom", .pm = &dwc3_qcom_dev_pm_ops, .of_match_table = dwc3_qcom_of_match, + .acpi_match_table = ACPI_PTR(dwc3_qcom_acpi_match), }, }; -- cgit v1.2.3 From a6e456209d088df31eacfa877d40194c755ca153 Mon Sep 17 00:00:00 2001 From: Lee Jones Date: Mon, 17 Jun 2019 13:51:04 +0100 Subject: usb: dwc3: qcom: Start USB in 'host mode' on the SDM845 When booting with Device Tree, the current default boot configuration table option, the request to boot via 'host mode' comes from the 'dr_mode' property. A property of the same name can be used inside ACPI tables too. However it is missing from the SDM845's ACPI tables so we have to supply this information using Platform Device Properties instead. This does not change the behaviour of any currently supported devices. The property is only set on ACPI enabled platforms, thus for H/W booting DT, unless a 'dr_mode' property is present, the default is still OTG (On-The-Go) as per [0]. Any new ACPI devices added will also be able to over-ride this implementation by providing a 'dr_mode' property in their ACPI tables. In cases where 'dr_mode' is omitted from the tables AND 'host mode' should not be the default (very unlikely), then we will have to add some way of choosing between them at run time - most likely by ACPI HID. [0] Documentation/devicetree/bindings/usb/generic.txt Signed-off-by: Lee Jones Reviewed-by: Bjorn Andersson Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/dwc3-qcom.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 0cb63f6c92d9..2d050303d564 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -444,6 +444,11 @@ static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count) return 0; } +static const struct property_entry dwc3_qcom_acpi_properties[] = { + PROPERTY_ENTRY_STRING("dr_mode", "host"), + {} +}; + static int dwc3_qcom_acpi_register_core(struct platform_device *pdev) { struct dwc3_qcom *qcom = platform_get_drvdata(pdev); @@ -488,6 +493,13 @@ static int dwc3_qcom_acpi_register_core(struct platform_device *pdev) goto out; } + ret = platform_device_add_properties(qcom->dwc3, + dwc3_qcom_acpi_properties); + if (ret < 0) { + dev_err(&pdev->dev, "failed to add properties\n"); + goto out; + } + ret = platform_device_add(qcom->dwc3); if (ret) dev_err(&pdev->dev, "failed to add device\n"); -- cgit v1.2.3 From 7f5d6a4696170ca7394d9dcecd5a54ebe2b9a067 Mon Sep 17 00:00:00 2001 From: Lee Jones Date: Mon, 17 Jun 2019 13:51:05 +0100 Subject: usb: dwc3: qcom: Improve error handling dwc3_qcom_clk_init() is called with of_count_phandle_with_args() as an argument. If of_count_phandle_with_args() returns an error, the number of clocks will be a negative value and will lead to undefined behaviour. Ensure we check for an error before attempting to blindly use the value. Signed-off-by: Lee Jones Reviewed-by: Bjorn Andersson Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/dwc3-qcom.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 2d050303d564..c59e9d8e8609 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -409,6 +409,9 @@ static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count) if (!np || !count) return 0; + if (count < 0) + return count; + qcom->num_clocks = count; qcom->clks = devm_kcalloc(dev, qcom->num_clocks, -- cgit v1.2.3 From dc1b5d9aed1794b5a1c6b0da46e372cc09974cbc Mon Sep 17 00:00:00 2001 From: Enric Balletbo i Serra Date: Thu, 13 Jun 2019 17:01:07 +0200 Subject: usb: dwc3: Fix core validation in probe, move after clocks are enabled The required clocks needs to be enabled before the first register access. After commit fe8abf332b8f ("usb: dwc3: support clocks and resets for DWC3 core"), this happens when the dwc3_core_is_valid function is called, but the mentioned commit adds that call in the wrong place, before the clocks are enabled. So, move that call after the clk_bulk_enable() to ensure the clocks are enabled and the reset deasserted. I detected this while, as experiment, I tried to move the clocks and resets from the glue layer to the DWC3 core on a Samsung Chromebook Plus. That was not detected before because, in most cases, the glue layer initializes SoC-specific things and then populates the child "snps,dwc3" with those clocks already enabled. Fixes: b873e2d0ea1ef ("usb: dwc3: Do core validation early on probe") Signed-off-by: Enric Balletbo i Serra Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 4aff1d8dbc4f..6e9e172010fc 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1423,11 +1423,6 @@ static int dwc3_probe(struct platform_device *pdev) dwc->regs = regs; dwc->regs_size = resource_size(&dwc_res); - if (!dwc3_core_is_valid(dwc)) { - dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); - return -ENODEV; - } - dwc3_get_properties(dwc); dwc->reset = devm_reset_control_get_optional_shared(dev, NULL); @@ -1460,6 +1455,12 @@ static int dwc3_probe(struct platform_device *pdev) if (ret) goto unprepare_clks; + if (!dwc3_core_is_valid(dwc)) { + dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); + ret = -ENODEV; + goto disable_clks; + } + platform_set_drvdata(pdev, dwc); dwc3_cache_hwparams(dwc); @@ -1525,6 +1526,7 @@ err1: pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); +disable_clks: clk_bulk_disable(dwc->num_clks, dwc->clks); unprepare_clks: clk_bulk_unprepare(dwc->num_clks, dwc->clks); -- cgit v1.2.3 From 4d20a6107050b45da976e28dc23274eb9ff1c242 Mon Sep 17 00:00:00 2001 From: Kefeng Wang Date: Sat, 25 May 2019 19:58:08 +0800 Subject: usb: dwc3: qcom: Use of_clk_get_parent_count() Use of_clk_get_parent_count() instead of open coding. Signed-off-by: Kefeng Wang Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/dwc3-qcom.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index c59e9d8e8609..261af9e38ddd 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -595,8 +595,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) goto reset_assert; } - ret = dwc3_qcom_clk_init(qcom, of_count_phandle_with_args(np, - "clocks", "#clock-cells")); + ret = dwc3_qcom_clk_init(qcom, of_clk_get_parent_count(np)); if (ret) { dev_err(dev, "failed to get clocks\n"); goto reset_assert; -- cgit v1.2.3 From 34cc761bdcc84fa7b9c5fd4e1f8548df6979f194 Mon Sep 17 00:00:00 2001 From: Anurag Kumar Vulisha Date: Fri, 10 May 2019 12:37:26 +0530 Subject: doc: dt: bindings: usb: dwc3: Update entries for disabling U1 and U2 This patch updates the documentation with the information related to the quirks that needs to be added for disabling the link entering into the U1 and U2 states Reviewed-by: Rob Herring Signed-off-by: Anurag Kumar Vulisha Signed-off-by: Felipe Balbi --- Documentation/devicetree/bindings/usb/dwc3.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt b/Documentation/devicetree/bindings/usb/dwc3.txt index 8e5265e9f658..66780a47ad85 100644 --- a/Documentation/devicetree/bindings/usb/dwc3.txt +++ b/Documentation/devicetree/bindings/usb/dwc3.txt @@ -64,6 +64,8 @@ Optional properties: - snps,dis_u2_susphy_quirk: when set core will disable USB2 suspend phy. - snps,dis_enblslpm_quirk: when set clears the enblslpm in GUSB2PHYCFG, disabling the suspend signal to the PHY. + - snps,dis-u1-entry-quirk: set if link entering into U1 needs to be disabled. + - snps,dis-u2-entry-quirk: set if link entering into U2 needs to be disabled. - snps,dis_rxdet_inp3_quirk: when set core will disable receiver detection in PHY P3 power state. - snps,dis-u2-freeclk-exists-quirk: when set, clear the u2_freeclk_exists -- cgit v1.2.3 From 4ed9890c4c44d2ead7b57ad65425e3fbe9b9d42a Mon Sep 17 00:00:00 2001 From: Anurag Kumar Vulisha Date: Fri, 10 May 2019 12:37:27 +0530 Subject: usb: gadget: send usb_gadget as an argument in get_config_params Passing struct usb_gadget * as an extra argument in get_config_params makes gadget drivers to easily update the U1DevExitLat & U2DevExitLat values based on the values passed from the device tree. This patch does the same Signed-off-by: Anurag Kumar Vulisha Signed-off-by: Felipe Balbi --- drivers/usb/gadget/composite.c | 2 +- include/linux/usb/gadget.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index b8a15840b4ff..9118b42c70b6 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -653,7 +653,7 @@ static int bos_desc(struct usb_composite_dev *cdev) /* Get Controller configuration */ if (cdev->gadget->ops->get_config_params) { - cdev->gadget->ops->get_config_params( + cdev->gadget->ops->get_config_params(cdev->gadget, &dcd_config_params); } else { dcd_config_params.bU1devExitLat = diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 7595056b96c1..fb19141151d8 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -310,7 +310,8 @@ struct usb_gadget_ops { int (*pullup) (struct usb_gadget *, int is_on); int (*ioctl)(struct usb_gadget *, unsigned code, unsigned long param); - void (*get_config_params)(struct usb_dcd_config_params *); + void (*get_config_params)(struct usb_gadget *, + struct usb_dcd_config_params *); int (*udc_start)(struct usb_gadget *, struct usb_gadget_driver *); int (*udc_stop)(struct usb_gadget *); -- cgit v1.2.3 From 729dcffd1ed319c9738456543f382d0801e768b8 Mon Sep 17 00:00:00 2001 From: Anurag Kumar Vulisha Date: Fri, 10 May 2019 12:37:28 +0530 Subject: usb: dwc3: gadget: Add support for disabling U1 and U2 entries Gadget applications may have a requirement to disable the U1 and U2 entry based on the usecase. Below are few usecases where the disabling U1/U2 entries may be possible. Usecase 1: When combining dwc3 with an redriver for a USB Type-C device solution, it sometimes have problems with leaving U1/U2 for certain hosts, resulting in link training errors and reconnects. For this U1/U2 state entries may be avoided. Usecase 2: When performing performance benchmarking on mass storage gadget the U1 and U2 entries can be disabled. Usecase 3: When periodic transfers like ISOC transfers are used with bInterval of 1 which doesn't require the link to enter into U1 or U2 state entry (since ping is issued from host for every uframe interval). In this case the U1 and U2 entry can be disabled. Disablement of U1/U2 can be done by setting U1DevExitLat and U2DevExitLat values to 0 in the BOS descriptor. Host on seeing 0 value for U1DevExitLat and U2DevExitLat, it doesn't send SET_SEL requests to the gadget. There may be some hosts which may send SET_SEL requests even after seeing 0 in the UxDevExitLat of BOS descriptor. To aviod U1/U2 entries for these type of hosts, dwc3 controller can be programmed to reject those U1/U2 requests by not enabling ACCEPTUxENA bits in DCTL register. This patch updates the same. Signed-off-by: Anurag Kumar Vulisha Signed-off-by: Claus H. Stovgaard Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/core.c | 4 ++++ drivers/usb/dwc3/core.h | 4 ++++ drivers/usb/dwc3/ep0.c | 9 ++++++++- drivers/usb/dwc3/gadget.c | 20 ++++++++++++++++++++ drivers/usb/dwc3/gadget.h | 6 ++++++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 6e9e172010fc..c9bb93a2c81e 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1282,6 +1282,10 @@ static void dwc3_get_properties(struct dwc3 *dwc) "snps,dis_u2_susphy_quirk"); dwc->dis_enblslpm_quirk = device_property_read_bool(dev, "snps,dis_enblslpm_quirk"); + dwc->dis_u1_entry_quirk = device_property_read_bool(dev, + "snps,dis-u1-entry-quirk"); + dwc->dis_u2_entry_quirk = device_property_read_bool(dev, + "snps,dis-u2-entry-quirk"); dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, "snps,dis_rxdet_inp3_quirk"); dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index f19cbeb01087..241b491489d9 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1014,6 +1014,8 @@ struct dwc3_scratchpad_array { * @dis_u2_susphy_quirk: set if we disable usb2 suspend phy * @dis_enblslpm_quirk: set if we clear enblslpm in GUSB2PHYCFG, * disabling the suspend signal to the PHY. + * @dis_u1_entry_quirk: set if link entering into U1 state needs to be disabled. + * @dis_u2_entry_quirk: set if link entering into U2 state needs to be disabled. * @dis_rxdet_inp3_quirk: set if we disable Rx.Detect in P3 * @dis_u2_freeclk_exists_quirk : set if we clear u2_freeclk_exists * in GUSB2PHYCFG, specify that USB2 PHY doesn't @@ -1205,6 +1207,8 @@ struct dwc3 { unsigned dis_u3_susphy_quirk:1; unsigned dis_u2_susphy_quirk:1; unsigned dis_enblslpm_quirk:1; + unsigned dis_u1_entry_quirk:1; + unsigned dis_u2_entry_quirk:1; unsigned dis_rxdet_inp3_quirk:1; unsigned dis_u2_freeclk_exists_quirk:1; unsigned dis_del_phy_power_chg_quirk:1; diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 8efde178eef4..3996b9c4ff8d 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -379,6 +379,8 @@ static int dwc3_ep0_handle_u1(struct dwc3 *dwc, enum usb_device_state state, if ((dwc->speed != DWC3_DSTS_SUPERSPEED) && (dwc->speed != DWC3_DSTS_SUPERSPEED_PLUS)) return -EINVAL; + if (set && dwc->dis_u1_entry_quirk) + return -EINVAL; reg = dwc3_readl(dwc->regs, DWC3_DCTL); if (set) @@ -401,6 +403,8 @@ static int dwc3_ep0_handle_u2(struct dwc3 *dwc, enum usb_device_state state, if ((dwc->speed != DWC3_DSTS_SUPERSPEED) && (dwc->speed != DWC3_DSTS_SUPERSPEED_PLUS)) return -EINVAL; + if (set && dwc->dis_u2_entry_quirk) + return -EINVAL; reg = dwc3_readl(dwc->regs, DWC3_DCTL); if (set) @@ -626,7 +630,10 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) * nothing is pending from application. */ reg = dwc3_readl(dwc->regs, DWC3_DCTL); - reg |= (DWC3_DCTL_ACCEPTU1ENA | DWC3_DCTL_ACCEPTU2ENA); + if (!dwc->dis_u1_entry_quirk) + reg |= DWC3_DCTL_ACCEPTU1ENA; + if (!dwc->dis_u2_entry_quirk) + reg |= DWC3_DCTL_ACCEPTU2ENA; dwc3_writel(dwc->regs, DWC3_DCTL, reg); } break; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index d67655384eb2..2751d3e98f5f 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2073,6 +2073,25 @@ out: return 0; } +static void dwc3_gadget_config_params(struct usb_gadget *g, + struct usb_dcd_config_params *params) +{ + struct dwc3 *dwc = gadget_to_dwc(g); + + /* U1 Device exit Latency */ + if (dwc->dis_u1_entry_quirk) + params->bU1devExitLat = 0; + else + params->bU1devExitLat = DWC3_DEFAULT_U1_DEV_EXIT_LAT; + + /* U2 Device exit Latency */ + if (dwc->dis_u2_entry_quirk) + params->bU2DevExitLat = 0; + else + params->bU2DevExitLat = + cpu_to_le16(DWC3_DEFAULT_U2_DEV_EXIT_LAT); +} + static void dwc3_gadget_set_speed(struct usb_gadget *g, enum usb_device_speed speed) { @@ -2142,6 +2161,7 @@ static const struct usb_gadget_ops dwc3_gadget_ops = { .udc_start = dwc3_gadget_start, .udc_stop = dwc3_gadget_stop, .udc_set_speed = dwc3_gadget_set_speed, + .get_config_params = dwc3_gadget_config_params, }; /* -------------------------------------------------------------------------- */ diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h index 3ed738e86ea7..5faf4d1249e0 100644 --- a/drivers/usb/dwc3/gadget.h +++ b/drivers/usb/dwc3/gadget.h @@ -48,6 +48,12 @@ struct dwc3; /* DEPXFERCFG parameter 0 */ #define DWC3_DEPXFERCFG_NUM_XFER_RES(n) ((n) & 0xffff) +/* U1 Device exit Latency */ +#define DWC3_DEFAULT_U1_DEV_EXIT_LAT 0x0A /* Less then 10 microsec */ + +/* U2 Device exit Latency */ +#define DWC3_DEFAULT_U2_DEV_EXIT_LAT 0x1FF /* Less then 511 microsec */ + /* -------------------------------------------------------------------------- */ #define to_dwc3_request(r) (container_of(r, struct dwc3_request, request)) -- cgit v1.2.3 From e70b3f5da00119e057b7faa557753fee7f786f17 Mon Sep 17 00:00:00 2001 From: EJ Hsu Date: Fri, 10 May 2019 19:02:10 +0800 Subject: usb: gadget: storage: Remove warning message This change is to fix below warning message in following scenario: usb_composite_setup_continue: Unexpected call When system tried to enter suspend, the fsg_disable() will be called to disable fsg driver and send a signal to fsg_main_thread. However, at this point, the fsg_main_thread has already been frozen and can not respond to this signal. So, this signal will be pended until fsg_main_thread wakes up. Once system resumes from suspend, fsg_main_thread will detect a signal pended and do some corresponding action (in handle_exception()). Then, host will send some setup requests (get descriptor, set configuration...) to UDC driver trying to enumerate this device. During the handling of "set configuration" request, it will try to sync up with fsg_main_thread by sending a signal (which is the same as the signal sent by fsg_disable) to it. In a similar manner, once the fsg_main_thread receives this signal, it will call handle_exception() to handle the request. However, if the fsg_main_thread wakes up from suspend a little late and "set configuration" request from Host arrives a little earlier, fsg_main_thread might come across the request from "set configuration" when it handles the signal from fsg_disable(). In this case, it will handle this request as well. So, when fsg_main_thread tries to handle the signal sent from "set configuration" later, there will nothing left to do and warning message "Unexpected call" is printed. Acked-by: Alan Stern Signed-off-by: EJ Hsu Signed-off-by: Felipe Balbi --- drivers/usb/gadget/function/f_mass_storage.c | 21 +++++++++++++++------ drivers/usb/gadget/function/storage_common.h | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 043f97ad8f22..982c3e89eb0d 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -2293,8 +2293,7 @@ static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) static void fsg_disable(struct usb_function *f) { struct fsg_dev *fsg = fsg_from_func(f); - fsg->common->new_fsg = NULL; - raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); + raise_exception(fsg->common, FSG_STATE_DISCONNECT); } @@ -2307,6 +2306,7 @@ static void handle_exception(struct fsg_common *common) enum fsg_state old_state; struct fsg_lun *curlun; unsigned int exception_req_tag; + struct fsg_dev *fsg; /* * Clear the existing signals. Anything but SIGUSR1 is converted @@ -2413,9 +2413,19 @@ static void handle_exception(struct fsg_common *common) break; case FSG_STATE_CONFIG_CHANGE: - do_set_interface(common, common->new_fsg); - if (common->new_fsg) + fsg = common->new_fsg; + /* + * Add a check here to double confirm if a disconnect event + * occurs and common->new_fsg has been cleared. + */ + if (fsg) { + do_set_interface(common, fsg); usb_composite_setup_continue(common->cdev); + } + break; + + case FSG_STATE_DISCONNECT: + do_set_interface(common, NULL); break; case FSG_STATE_EXIT: @@ -2989,8 +2999,7 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) DBG(fsg, "unbind\n"); if (fsg->common->fsg == fsg) { - fsg->common->new_fsg = NULL; - raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); + raise_exception(fsg->common, FSG_STATE_DISCONNECT); /* FIXME: make interruptible or killable somehow? */ wait_event(common->fsg_wait, common->fsg != fsg); } diff --git a/drivers/usb/gadget/function/storage_common.h b/drivers/usb/gadget/function/storage_common.h index e5e3a2553aaa..12687f7e3de9 100644 --- a/drivers/usb/gadget/function/storage_common.h +++ b/drivers/usb/gadget/function/storage_common.h @@ -161,6 +161,7 @@ enum fsg_state { FSG_STATE_ABORT_BULK_OUT, FSG_STATE_PROTOCOL_RESET, FSG_STATE_CONFIG_CHANGE, + FSG_STATE_DISCONNECT, FSG_STATE_EXIT, FSG_STATE_TERMINATED }; -- cgit v1.2.3 From d29fcf7078bc8be2b6366cbd4418265b53c94fac Mon Sep 17 00:00:00 2001 From: Kiruthika Varadarajan Date: Tue, 18 Jun 2019 08:39:06 +0000 Subject: usb: gadget: ether: Fix race between gether_disconnect and rx_submit On spin lock release in rx_submit, gether_disconnect get a chance to run, it makes port_usb NULL, rx_submit access NULL port USB, hence null pointer crash. Fixed by releasing the lock in rx_submit after port_usb is used. Fixes: 2b3d942c4878 ("usb ethernet gadget: split out network core") Cc: Signed-off-by: Kiruthika Varadarajan Signed-off-by: Felipe Balbi --- drivers/usb/gadget/function/u_ether.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index 737bd77a575d..2929bb47a618 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -186,11 +186,12 @@ rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags) out = dev->port_usb->out_ep; else out = NULL; - spin_unlock_irqrestore(&dev->lock, flags); if (!out) + { + spin_unlock_irqrestore(&dev->lock, flags); return -ENOTCONN; - + } /* Padding up to RX_EXTRA handles minor disagreements with host. * Normally we use the USB "terminate on short read" convention; @@ -214,6 +215,7 @@ rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags) if (dev->port_usb->is_fixed) size = max_t(size_t, size, dev->port_usb->fixed_out_len); + spin_unlock_irqrestore(&dev->lock, flags); skb = __netdev_alloc_skb(dev->net, size + NET_IP_ALIGN, gfp_flags); if (skb == NULL) { -- cgit v1.2.3 From aed2a26283528fb69c38e414f649411aa48fb391 Mon Sep 17 00:00:00 2001 From: Jörgen Storvist Date: Wed, 19 Jun 2019 00:30:19 +0200 Subject: USB: serial: option: add support for GosunCn ME3630 RNDIS mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added USB IDs for GosunCn ME3630 cellular module in RNDIS mode. T: Bus=03 Lev=01 Prnt=01 Port=01 Cnt=03 Dev#= 18 Spd=480 MxCh= 0 D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=19d2 ProdID=0601 Rev=03.18 S: Manufacturer=Android S: Product=Android S: SerialNumber=b950269c C: #Ifs= 5 Cfg#= 1 Atr=a0 MxPwr=500mA I: If#=0x0 Alt= 0 #EPs= 1 Cls=e0(wlcon) Sub=01 Prot=03 Driver=rndis_host I: If#=0x1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=rndis_host I: If#=0x2 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=option I: If#=0x3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option I: If#=0x4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option Signed-off-by: Jörgen Storvist Cc: stable Signed-off-by: Johan Hovold --- drivers/usb/serial/option.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index a0aaf0635359..c1582fbd1150 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c @@ -1343,6 +1343,7 @@ static const struct usb_device_id option_ids[] = { .driver_info = RSVD(4) }, { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0414, 0xff, 0xff, 0xff) }, { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0417, 0xff, 0xff, 0xff) }, + { USB_DEVICE_INTERFACE_CLASS(ZTE_VENDOR_ID, 0x0601, 0xff) }, /* GosunCn ZTE WeLink ME3630 (RNDIS mode) */ { USB_DEVICE_INTERFACE_CLASS(ZTE_VENDOR_ID, 0x0602, 0xff) }, /* GosunCn ZTE WeLink ME3630 (MBIM mode) */ { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1008, 0xff, 0xff, 0xff), .driver_info = RSVD(4) }, -- cgit v1.2.3 From b119deca1e016e37614117f56f74461eac559af5 Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Wed, 19 Jun 2019 16:36:16 +1000 Subject: USB: fix types in uapi include Signed-off-by: Stephen Rothwell Signed-off-by: Greg Kroah-Hartman --- include/uapi/linux/usbdevice_fs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/usbdevice_fs.h b/include/uapi/linux/usbdevice_fs.h index 4b267fe3776e..78efe870c2b7 100644 --- a/include/uapi/linux/usbdevice_fs.h +++ b/include/uapi/linux/usbdevice_fs.h @@ -85,11 +85,11 @@ struct usbdevfs_conninfo_ex { /* kernel, the device is connected to. */ __u32 devnum; /* Device address on the bus. */ __u32 speed; /* USB_SPEED_* constants from ch9.h */ - u8 num_ports; /* Number of ports the device is connected */ + __u8 num_ports; /* Number of ports the device is connected */ /* to on the way to the root hub. It may */ /* be bigger than size of 'ports' array so */ /* userspace can detect overflows. */ - u8 ports[7]; /* List of ports on the way from the root */ + __u8 ports[7]; /* List of ports on the way from the root */ /* hub to the device. Current limit in */ /* USB specification is 7 tiers (root hub, */ /* 5 intermediate hubs, device), which */ -- cgit v1.2.3 From 37e444c8296c14cb5768a1197b24cfc07ee8e0cd Mon Sep 17 00:00:00 2001 From: Daniel M German Date: Wed, 19 Jun 2019 21:50:38 -0700 Subject: usb: Replace snprintf with scnprintf in gether_get_ifname snprintf returns the actual length of the buffer created; however, this is not the case if snprintf truncates its parameter. See https://lwn.net/Articles/69419/ for a detailed explanation. The current code correctly handles this case at the expense of extra code in the return statement. scnprintf does returns the actual length of the buffer created making the ?: operator unnecessary in the return statement. This change does not alter the functionality of the code. Signed-off-by: Daniel M German Signed-off-by: Felipe Balbi --- drivers/usb/gadget/function/u_ether.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index 2929bb47a618..fbe96ef1ac7a 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -1006,9 +1006,9 @@ int gether_get_ifname(struct net_device *net, char *name, int len) int ret; rtnl_lock(); - ret = snprintf(name, len, "%s\n", netdev_name(net)); + ret = scnprintf(name, len, "%s\n", netdev_name(net)); rtnl_unlock(); - return ret < len ? ret : len; + return ret; } EXPORT_SYMBOL_GPL(gether_get_ifname); -- cgit v1.2.3 From dbb0569de852fb4576d6f62078d515f989a181ca Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Mon, 11 Jun 2018 11:21:12 +0300 Subject: usb: dwc3: pci: Add Support for Intel Elkhart Lake Devices This patch simply adds a new PCI Device ID Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/dwc3-pci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index 8cced3609e24..f9b550081550 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c @@ -34,6 +34,7 @@ #define PCI_DEVICE_ID_INTEL_CNPLP 0x9dee #define PCI_DEVICE_ID_INTEL_CNPH 0xa36e #define PCI_DEVICE_ID_INTEL_ICLLP 0x34ee +#define PCI_DEVICE_ID_INTEL_EHLLP 0x4b7e #define PCI_INTEL_BXT_DSM_GUID "732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511" #define PCI_INTEL_BXT_FUNC_PMU_PWR 4 @@ -339,6 +340,9 @@ static const struct pci_device_id dwc3_pci_id_table[] = { { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICLLP), (kernel_ulong_t) &dwc3_pci_intel_properties, }, + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_EHLLP), + (kernel_ulong_t) &dwc3_pci_intel_properties, }, + { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_NL_USB), (kernel_ulong_t) &dwc3_pci_amd_properties, }, { } /* Terminating Entry */ -- cgit v1.2.3 From c886ec0256d32ec219372d9a88fb31d1ae7fcb2a Mon Sep 17 00:00:00 2001 From: "Gustavo A. R. Silva" Date: Wed, 5 Jun 2019 15:00:02 -0500 Subject: phy: samsung: Use struct_size() in devm_kzalloc() One of the more common cases of allocation size calculations is finding the size of a structure that has a zero-sized array at the end, along with memory for some number of elements for that array. For example: struct samsung_usb2_phy_driver { ... struct samsung_usb2_phy_instance instances[0]; }; instance = devm_kzalloc(dev, sizeof(struct samsung_usb2_phy_driver) + count * sizeof(struct samsung_usb2_phy_instance), GFP_KERNEL); Instead of leaving these open-coded and prone to type mistakes, we can now use the new struct_size() helper: instance = devm_kzalloc(dev, struct_size(instance, instances, count), GFP_KERNEL); This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/samsung/phy-samsung-usb2.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/phy/samsung/phy-samsung-usb2.c b/drivers/phy/samsung/phy-samsung-usb2.c index ea818866985a..4616ec829900 100644 --- a/drivers/phy/samsung/phy-samsung-usb2.c +++ b/drivers/phy/samsung/phy-samsung-usb2.c @@ -159,9 +159,8 @@ static int samsung_usb2_phy_probe(struct platform_device *pdev) if (!cfg) return -EINVAL; - drv = devm_kzalloc(dev, sizeof(struct samsung_usb2_phy_driver) + - cfg->num_phys * sizeof(struct samsung_usb2_phy_instance), - GFP_KERNEL); + drv = devm_kzalloc(dev, struct_size(drv, instances, cfg->num_phys), + GFP_KERNEL); if (!drv) return -ENOMEM; -- cgit v1.2.3 From c7a787de7f3f3639b259d13190376af38068515c Mon Sep 17 00:00:00 2001 From: YueHaibing Date: Thu, 6 Jun 2019 04:28:40 +0000 Subject: phy: usb: phy-brcm-usb: Fix platform_no_drv_owner.cocci warnings Remove .owner field if calls are used which set it automatically Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci Signed-off-by: YueHaibing Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/broadcom/phy-brcm-usb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/phy/broadcom/phy-brcm-usb.c b/drivers/phy/broadcom/phy-brcm-usb.c index f59b1dc30399..5283d70a82c9 100644 --- a/drivers/phy/broadcom/phy-brcm-usb.c +++ b/drivers/phy/broadcom/phy-brcm-usb.c @@ -443,7 +443,6 @@ static struct platform_driver brcm_usb_driver = { .probe = brcm_usb_phy_probe, .driver = { .name = "brcmstb-usb-phy", - .owner = THIS_MODULE, .pm = &brcm_usb_phy_pm_ops, .of_match_table = brcm_usb_dt_ids, }, -- cgit v1.2.3 From aa23ce847ddac1fd5ffe987ff12e12ff48318e45 Mon Sep 17 00:00:00 2001 From: Chunfeng Yun Date: Thu, 20 Jun 2019 16:12:31 +0800 Subject: usb: dwc3: remove unused @lock member of dwc3_ep struct The member @lock of dwc3_ep struct is only initialized, and not used elsewhere, so remove it. Signed-off-by: Chunfeng Yun Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/core.h | 2 -- drivers/usb/dwc3/gadget.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 241b491489d9..3dd783b889cb 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -649,7 +649,6 @@ struct dwc3_event_buffer { * @cancelled_list: list of cancelled requests for this endpoint * @pending_list: list of pending requests for this endpoint * @started_list: list of started requests on this endpoint - * @lock: spinlock for endpoint request queue traversal * @regs: pointer to first endpoint register * @trb_pool: array of transaction buffers * @trb_pool_dma: dma address of @trb_pool @@ -677,7 +676,6 @@ struct dwc3_ep { struct list_head pending_list; struct list_head started_list; - spinlock_t lock; void __iomem *regs; struct dwc3_trb *trb_pool; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 2751d3e98f5f..173f5329d3d9 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2271,8 +2271,6 @@ static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum) dep->endpoint.comp_desc = NULL; } - spin_lock_init(&dep->lock); - if (num == 0) ret = dwc3_gadget_init_control_endpoint(dep); else if (direction) -- cgit v1.2.3 From d46a6024c709a7f3057e512b1e836e816ace1143 Mon Sep 17 00:00:00 2001 From: Harry Pan Date: Thu, 20 Jun 2019 13:58:23 +0800 Subject: USB: core: correct a spelling mistake in the comment Fix a spelling typo in the function comment. Signed-off-by: Harry Pan Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 82cc3766cb23..a59e1573b43b 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -2721,7 +2721,7 @@ static bool use_new_scheme(struct usb_device *udev, int retry, } /* Is a USB 3.0 port in the Inactive or Compliance Mode state? - * Port worm reset is required to recover + * Port warm reset is required to recover */ static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, u16 portstatus) -- cgit v1.2.3 From 743344a952fcebee9ca4d783807cf1f03f933baf Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Thu, 13 Jun 2019 20:18:48 +0900 Subject: usb: renesas_usbhs: Use struct assignment instead of memcpy() To avoid the error-proneness of calls to sizeof() in the memcpy, this patch uses struct assignment instead of memcpy. Signed-off-by: Yoshihiro Shimoda Reviewed-by: Simon Horman --- This patch is based on Greg's linux-usb.git / usb-next branch. Note that mod_host.c also has memcpy but we cannot use struct assignment for it because the type of urb->setup_patcket is just "unsigned char *". drivers/usb/renesas_usbhs/common.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index a501ea609019..ebbe322182bd 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -651,9 +651,8 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) return NULL; dparam = &info->driver_param; - memcpy(dparam, &data->param, sizeof(data->param)); - memcpy(&info->platform_callback, data->platform_callback, - sizeof(*data->platform_callback)); + *dparam = data->param; + info->platform_callback = *data->platform_callback; if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp)) dparam->buswait_bwait = tmp; @@ -714,17 +713,13 @@ static int usbhs_probe(struct platform_device *pdev) * care platform info */ - memcpy(&priv->dparam, - &info->driver_param, - sizeof(struct renesas_usbhs_driver_param)); + priv->dparam = info->driver_param; if (!info->platform_callback.get_id) { dev_err(&pdev->dev, "no platform callbacks"); return -EINVAL; } - memcpy(&priv->pfunc, - &info->platform_callback, - sizeof(struct renesas_usbhs_platform_callback)); + priv->pfunc = info->platform_callback; /* set driver callback functions for platform */ dfunc = &info->driver_callback; -- cgit v1.2.3 From ecefae6db042283bf88ef3777f2381b18df8ed46 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Tue, 18 Jun 2019 18:05:38 -0300 Subject: docs: usb: rename files to .rst and add them to drivers-api While there are a mix of things here, most of the stuff were written from Kernel developer's PoV. So, add them to the driver-api book. A follow up for this patch would be to move documents from there that are specific to sysadmins, adding them to the admin-guide. Signed-off-by: Mauro Carvalho Chehab Acked-by: Johan Hovold Acked-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- Documentation/index.rst | 1 + Documentation/index.rst.rej | 10 + Documentation/usb/WUSB-Design-overview.txt | 457 ------------- Documentation/usb/acm.rst | 132 ++++ Documentation/usb/acm.txt | 132 ---- Documentation/usb/authorization.rst | 132 ++++ Documentation/usb/authorization.txt | 132 ---- Documentation/usb/chipidea.rst | 133 ++++ Documentation/usb/chipidea.txt | 133 ---- Documentation/usb/dwc3.rst | 53 ++ Documentation/usb/dwc3.txt | 53 -- Documentation/usb/ehci.rst | 230 +++++++ Documentation/usb/ehci.txt | 230 ------- Documentation/usb/functionfs.rst | 68 ++ Documentation/usb/functionfs.txt | 68 -- Documentation/usb/gadget-testing.rst | 934 +++++++++++++++++++++++++++ Documentation/usb/gadget-testing.txt | 934 --------------------------- Documentation/usb/gadget_configfs.rst | 390 +++++++++++ Documentation/usb/gadget_configfs.txt | 390 ----------- Documentation/usb/gadget_hid.rst | 457 +++++++++++++ Documentation/usb/gadget_hid.txt | 457 ------------- Documentation/usb/gadget_multi.rst | 165 +++++ Documentation/usb/gadget_multi.txt | 165 ----- Documentation/usb/gadget_printer.rst | 523 +++++++++++++++ Documentation/usb/gadget_printer.txt | 523 --------------- Documentation/usb/gadget_serial.rst | 289 +++++++++ Documentation/usb/gadget_serial.txt | 289 --------- Documentation/usb/index.rst | 39 ++ Documentation/usb/iuu_phoenix.rst | 94 +++ Documentation/usb/iuu_phoenix.txt | 94 --- Documentation/usb/mass-storage.rst | 234 +++++++ Documentation/usb/mass-storage.txt | 234 ------- Documentation/usb/misc_usbsevseg.rst | 51 ++ Documentation/usb/misc_usbsevseg.txt | 51 -- Documentation/usb/mtouchusb.rst | 84 +++ Documentation/usb/mtouchusb.txt | 84 --- Documentation/usb/ohci.rst | 35 + Documentation/usb/ohci.txt | 35 - Documentation/usb/rio.rst | 109 ++++ Documentation/usb/rio.txt | 109 ---- Documentation/usb/text_files.rst | 29 + Documentation/usb/usb-help.rst | 17 + Documentation/usb/usb-help.txt | 17 - Documentation/usb/usb-serial.rst | 537 +++++++++++++++ Documentation/usb/usb-serial.txt | 537 --------------- Documentation/usb/usbip_protocol.rst | 411 ++++++++++++ Documentation/usb/usbip_protocol.txt | 411 ------------ Documentation/usb/usbmon.rst | 375 +++++++++++ Documentation/usb/usbmon.txt | 375 ----------- Documentation/usb/wusb-design-overview.rst | 457 +++++++++++++ MAINTAINERS | 12 +- drivers/usb/Kconfig | 2 +- drivers/usb/class/Kconfig | 2 +- drivers/usb/gadget/Kconfig | 6 +- drivers/usb/gadget/function/f_mass_storage.c | 2 +- drivers/usb/gadget/legacy/Kconfig | 6 +- drivers/usb/host/Kconfig | 2 +- drivers/usb/misc/Kconfig | 2 +- drivers/usb/mon/Kconfig | 2 +- drivers/usb/serial/Kconfig | 10 +- drivers/usb/serial/belkin_sa.c | 2 +- drivers/usb/serial/belkin_sa.h | 2 +- drivers/usb/serial/cypress_m8.c | 2 +- drivers/usb/serial/empeg.c | 2 +- drivers/usb/serial/ftdi_sio.c | 2 +- drivers/usb/serial/ir-usb.c | 2 +- drivers/usb/serial/keyspan_pda.c | 2 +- drivers/usb/serial/omninet.c | 2 +- drivers/usb/serial/oti6858.c | 2 +- drivers/usb/serial/pl2303.c | 2 +- drivers/usb/serial/usb-serial.c | 2 +- drivers/usb/serial/visor.c | 2 +- drivers/usb/serial/visor.h | 2 +- drivers/usb/serial/whiteheat.c | 2 +- drivers/usb/serial/whiteheat.h | 2 +- 75 files changed, 6027 insertions(+), 5948 deletions(-) create mode 100644 Documentation/index.rst.rej delete mode 100644 Documentation/usb/WUSB-Design-overview.txt create mode 100644 Documentation/usb/acm.rst delete mode 100644 Documentation/usb/acm.txt create mode 100644 Documentation/usb/authorization.rst delete mode 100644 Documentation/usb/authorization.txt create mode 100644 Documentation/usb/chipidea.rst delete mode 100644 Documentation/usb/chipidea.txt create mode 100644 Documentation/usb/dwc3.rst delete mode 100644 Documentation/usb/dwc3.txt create mode 100644 Documentation/usb/ehci.rst delete mode 100644 Documentation/usb/ehci.txt create mode 100644 Documentation/usb/functionfs.rst delete mode 100644 Documentation/usb/functionfs.txt create mode 100644 Documentation/usb/gadget-testing.rst delete mode 100644 Documentation/usb/gadget-testing.txt create mode 100644 Documentation/usb/gadget_configfs.rst delete mode 100644 Documentation/usb/gadget_configfs.txt create mode 100644 Documentation/usb/gadget_hid.rst delete mode 100644 Documentation/usb/gadget_hid.txt create mode 100644 Documentation/usb/gadget_multi.rst delete mode 100644 Documentation/usb/gadget_multi.txt create mode 100644 Documentation/usb/gadget_printer.rst delete mode 100644 Documentation/usb/gadget_printer.txt create mode 100644 Documentation/usb/gadget_serial.rst delete mode 100644 Documentation/usb/gadget_serial.txt create mode 100644 Documentation/usb/index.rst create mode 100644 Documentation/usb/iuu_phoenix.rst delete mode 100644 Documentation/usb/iuu_phoenix.txt create mode 100644 Documentation/usb/mass-storage.rst delete mode 100644 Documentation/usb/mass-storage.txt create mode 100644 Documentation/usb/misc_usbsevseg.rst delete mode 100644 Documentation/usb/misc_usbsevseg.txt create mode 100644 Documentation/usb/mtouchusb.rst delete mode 100644 Documentation/usb/mtouchusb.txt create mode 100644 Documentation/usb/ohci.rst delete mode 100644 Documentation/usb/ohci.txt create mode 100644 Documentation/usb/rio.rst delete mode 100644 Documentation/usb/rio.txt create mode 100644 Documentation/usb/text_files.rst create mode 100644 Documentation/usb/usb-help.rst delete mode 100644 Documentation/usb/usb-help.txt create mode 100644 Documentation/usb/usb-serial.rst delete mode 100644 Documentation/usb/usb-serial.txt create mode 100644 Documentation/usb/usbip_protocol.rst delete mode 100644 Documentation/usb/usbip_protocol.txt create mode 100644 Documentation/usb/usbmon.rst delete mode 100644 Documentation/usb/usbmon.txt create mode 100644 Documentation/usb/wusb-design-overview.rst diff --git a/Documentation/index.rst b/Documentation/index.rst index a7566ef62411..91055adde327 100644 --- a/Documentation/index.rst +++ b/Documentation/index.rst @@ -101,6 +101,7 @@ needed). filesystems/index vm/index bpf/index + usb/index misc-devices/index Architecture-specific documentation diff --git a/Documentation/index.rst.rej b/Documentation/index.rst.rej new file mode 100644 index 000000000000..b1af6eab22f3 --- /dev/null +++ b/Documentation/index.rst.rej @@ -0,0 +1,10 @@ +--- Documentation/index.rst ++++ Documentation/index.rst +@@ -103,6 +103,7 @@ needed). + vm/index + bpf/index + PCI/index ++ usb/index + misc-devices/index + + Architecture-specific documentation diff --git a/Documentation/usb/WUSB-Design-overview.txt b/Documentation/usb/WUSB-Design-overview.txt deleted file mode 100644 index dc5e21609bb5..000000000000 --- a/Documentation/usb/WUSB-Design-overview.txt +++ /dev/null @@ -1,457 +0,0 @@ -================================ -Linux UWB + Wireless USB + WiNET -================================ - - Copyright (C) 2005-2006 Intel Corporation - - Inaky Perez-Gonzalez - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License version - 2 as published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. - - -Please visit http://bughost.org/thewiki/Design-overview.txt-1.8 for -updated content. - - * Design-overview.txt-1.8 - -This code implements a Ultra Wide Band stack for Linux, as well as -drivers for the USB based UWB radio controllers defined in the -Wireless USB 1.0 specification (including Wireless USB host controller -and an Intel WiNET controller). - -.. Contents - 1. Introduction - 1. HWA: Host Wire adapters, your Wireless USB dongle - - 2. DWA: Device Wired Adaptor, a Wireless USB hub for wired - devices - 3. WHCI: Wireless Host Controller Interface, the PCI WUSB host - adapter - 2. The UWB stack - 1. Devices and hosts: the basic structure - - 2. Host Controller life cycle - - 3. On the air: beacons and enumerating the radio neighborhood - - 4. Device lists - 5. Bandwidth allocation - - 3. Wireless USB Host Controller drivers - - 4. Glossary - - -Introduction -============ - -UWB is a wide-band communication protocol that is to serve also as the -low-level protocol for others (much like TCP sits on IP). Currently -these others are Wireless USB and TCP/IP, but seems Bluetooth and -Firewire/1394 are coming along. - -UWB uses a band from roughly 3 to 10 GHz, transmitting at a max of -~-41dB (or 0.074 uW/MHz--geography specific data is still being -negotiated w/ regulators, so watch for changes). That band is divided in -a bunch of ~1.5 GHz wide channels (or band groups) composed of three -subbands/subchannels (528 MHz each). Each channel is independent of each -other, so you could consider them different "busses". Initially this -driver considers them all a single one. - -Radio time is divided in 65536 us long /superframes/, each one divided -in 256 256us long /MASs/ (Media Allocation Slots), which are the basic -time/media allocation units for transferring data. At the beginning of -each superframe there is a Beacon Period (BP), where every device -transmit its beacon on a single MAS. The length of the BP depends on how -many devices are present and the length of their beacons. - -Devices have a MAC (fixed, 48 bit address) and a device (changeable, 16 -bit address) and send periodic beacons to advertise themselves and pass -info on what they are and do. They advertise their capabilities and a -bunch of other stuff. - -The different logical parts of this driver are: - - * - - *UWB*: the Ultra-Wide-Band stack -- manages the radio and - associated spectrum to allow for devices sharing it. Allows to - control bandwidth assignment, beaconing, scanning, etc - - * - - *WUSB*: the layer that sits on top of UWB to provide Wireless USB. - The Wireless USB spec defines means to control a UWB radio and to - do the actual WUSB. - - -HWA: Host Wire adapters, your Wireless USB dongle -------------------------------------------------- - -WUSB also defines a device called a Host Wire Adaptor (HWA), which in -mere terms is a USB dongle that enables your PC to have UWB and Wireless -USB. The Wireless USB Host Controller in a HWA looks to the host like a -[Wireless] USB controller connected via USB (!) - -The HWA itself is broken in two or three main interfaces: - - * - - *RC*: Radio control -- this implements an interface to the - Ultra-Wide-Band radio controller. The driver for this implements a - USB-based UWB Radio Controller to the UWB stack. - - * - - *HC*: the wireless USB host controller. It looks like a USB host - whose root port is the radio and the WUSB devices connect to it. - To the system it looks like a separate USB host. The driver (will) - implement a USB host controller (similar to UHCI, OHCI or EHCI) - for which the root hub is the radio...To reiterate: it is a USB - controller that is connected via USB instead of PCI. - - * - - *WINET*: some HW provide a WiNET interface (IP over UWB). This - package provides a driver for it (it looks like a network - interface, winetX). The driver detects when there is a link up for - their type and kick into gear. - - -DWA: Device Wired Adaptor, a Wireless USB hub for wired devices ---------------------------------------------------------------- - -These are the complement to HWAs. They are a USB host for connecting -wired devices, but it is connected to your PC connected via Wireless -USB. To the system it looks like yet another USB host. To the untrained -eye, it looks like a hub that connects upstream wirelessly. - -We still offer no support for this; however, it should share a lot of -code with the HWA-RC driver; there is a bunch of factorization work that -has been done to support that in upcoming releases. - - -WHCI: Wireless Host Controller Interface, the PCI WUSB host adapter -------------------------------------------------------------------- - -This is your usual PCI device that implements WHCI. Similar in concept -to EHCI, it allows your wireless USB devices (including DWAs) to connect -to your host via a PCI interface. As in the case of the HWA, it has a -Radio Control interface and the WUSB Host Controller interface per se. - -There is still no driver support for this, but will be in upcoming -releases. - - -The UWB stack -============= - -The main mission of the UWB stack is to keep a tally of which devices -are in radio proximity to allow drivers to connect to them. As well, it -provides an API for controlling the local radio controllers (RCs from -now on), such as to start/stop beaconing, scan, allocate bandwidth, etc. - - -Devices and hosts: the basic structure --------------------------------------- - -The main building block here is the UWB device (struct uwb_dev). For -each device that pops up in radio presence (ie: the UWB host receives a -beacon from it) you get a struct uwb_dev that will show up in -/sys/bus/uwb/devices. - -For each RC that is detected, a new struct uwb_rc and struct uwb_dev are -created. An entry is also created in /sys/class/uwb_rc for each RC. - -Each RC driver is implemented by a separate driver that plugs into the -interface that the UWB stack provides through a struct uwb_rc_ops. The -spec creators have been nice enough to make the message format the same -for HWA and WHCI RCs, so the driver is really a very thin transport that -moves the requests from the UWB API to the device [/uwb_rc_ops->cmd()/] -and sends the replies and notifications back to the API -[/uwb_rc_neh_grok()/]. Notifications are handled to the UWB daemon, that -is chartered, among other things, to keep the tab of how the UWB radio -neighborhood looks, creating and destroying devices as they show up or -disappear. - -Command execution is very simple: a command block is sent and a event -block or reply is expected back. For sending/receiving command/events, a -handle called /neh/ (Notification/Event Handle) is opened with -/uwb_rc_neh_open()/. - -The HWA-RC (USB dongle) driver (drivers/uwb/hwa-rc.c) does this job for -the USB connected HWA. Eventually, drivers/whci-rc.c will do the same -for the PCI connected WHCI controller. - - -Host Controller life cycle --------------------------- - -So let's say we connect a dongle to the system: it is detected and -firmware uploaded if needed [for Intel's i1480 -/drivers/uwb/ptc/usb.c:ptc_usb_probe()/] and then it is reenumerated. -Now we have a real HWA device connected and -/drivers/uwb/hwa-rc.c:hwarc_probe()/ picks it up, that will set up the -Wire-Adaptor environment and then suck it into the UWB stack's vision of -the world [/drivers/uwb/lc-rc.c:uwb_rc_add()/]. - - * - - [*] The stack should put a new RC to scan for devices - [/uwb_rc_scan()/] so it finds what's available around and tries to - connect to them, but this is policy stuff and should be driven - from user space. As of now, the operator is expected to do it - manually; see the release notes for documentation on the procedure. - -When a dongle is disconnected, /drivers/uwb/hwa-rc.c:hwarc_disconnect()/ -takes time of tearing everything down safely (or not...). - - -On the air: beacons and enumerating the radio neighborhood ----------------------------------------------------------- - -So assuming we have devices and we have agreed for a channel to connect -on (let's say 9), we put the new RC to beacon: - - * - - $ echo 9 0 > /sys/class/uwb_rc/uwb0/beacon - -Now it is visible. If there were other devices in the same radio channel -and beacon group (that's what the zero is for), the dongle's radio -control interface will send beacon notifications on its -notification/event endpoint (NEEP). The beacon notifications are part of -the event stream that is funneled into the API with -/drivers/uwb/neh.c:uwb_rc_neh_grok()/ and delivered to the UWBD, the UWB -daemon through a notification list. - -UWBD wakes up and scans the event list; finds a beacon and adds it to -the BEACON CACHE (/uwb_beca/). If he receives a number of beacons from -the same device, he considers it to be 'onair' and creates a new device -[/drivers/uwb/lc-dev.c:uwbd_dev_onair()/]. Similarly, when no beacons -are received in some time, the device is considered gone and wiped out -[uwbd calls periodically /uwb/beacon.c:uwb_beca_purge()/ that will purge -the beacon cache of dead devices]. - - -Device lists ------------- - -All UWB devices are kept in the list of the struct bus_type uwb_bus_type. - - -Bandwidth allocation --------------------- - -The UWB stack maintains a local copy of DRP availability through -processing of incoming *DRP Availability Change* notifications. This -local copy is currently used to present the current bandwidth -availability to the user through the sysfs file -/sys/class/uwb_rc/uwbx/bw_avail. In the future the bandwidth -availability information will be used by the bandwidth reservation -routines. - -The bandwidth reservation routines are in progress and are thus not -present in the current release. When completed they will enable a user -to initiate DRP reservation requests through interaction with sysfs. DRP -reservation requests from remote UWB devices will also be handled. The -bandwidth management done by the UWB stack will include callbacks to the -higher layers will enable the higher layers to use the reservations upon -completion. [Note: The bandwidth reservation work is in progress and -subject to change.] - - -Wireless USB Host Controller drivers -==================================== - -*WARNING* This section needs a lot of work! - -As explained above, there are three different types of HCs in the WUSB -world: HWA-HC, DWA-HC and WHCI-HC. - -HWA-HC and DWA-HC share that they are Wire-Adapters (USB or WUSB -connected controllers), and their transfer management system is almost -identical. So is their notification delivery system. - -HWA-HC and WHCI-HC share that they are both WUSB host controllers, so -they have to deal with WUSB device life cycle and maintenance, wireless -root-hub - -HWA exposes a Host Controller interface (HWA-HC 0xe0/02/02). This has -three endpoints (Notifications, Data Transfer In and Data Transfer -Out--known as NEP, DTI and DTO in the code). - -We reserve UWB bandwidth for our Wireless USB Cluster, create a Cluster -ID and tell the HC to use all that. Then we start it. This means the HC -starts sending MMCs. - - * - - The MMCs are blocks of data defined somewhere in the WUSB1.0 spec - that define a stream in the UWB channel time allocated for sending - WUSB IEs (host to device commands/notifications) and Device - Notifications (device initiated to host). Each host defines a - unique Wireless USB cluster through MMCs. Devices can connect to a - single cluster at the time. The IEs are Information Elements, and - among them are the bandwidth allocations that tell each device - when can they transmit or receive. - -Now it all depends on external stimuli. - -New device connection ---------------------- - -A new device pops up, it scans the radio looking for MMCs that give out -the existence of Wireless USB channels. Once one (or more) are found, -selects which one to connect to. Sends a /DN_Connect/ (device -notification connect) during the DNTS (Device Notification Time -Slot--announced in the MMCs - -HC picks the /DN_Connect/ out (nep module sends to notif.c for delivery -into /devconnect/). This process starts the authentication process for -the device. First we allocate a /fake port/ and assign an -unauthenticated address (128 to 255--what we really do is -0x80 | fake_port_idx). We fiddle with the fake port status and /hub_wq/ -sees a new connection, so he moves on to enable the fake port with a reset. - -So now we are in the reset path -- we know we have a non-yet enumerated -device with an unauthorized address; we ask user space to authenticate -(FIXME: not yet done, similar to bluetooth pairing), then we do the key -exchange (FIXME: not yet done) and issue a /set address 0/ to bring the -device to the default state. Device is authenticated. - -From here, the USB stack takes control through the usb_hcd ops. hub_wq -has seen the port status changes, as we have been toggling them. It will -start enumerating and doing transfers through usb_hcd->urb_enqueue() to -read descriptors and move our data. - -Device life cycle and keep alives ---------------------------------- - -Every time there is a successful transfer to/from a device, we update a -per-device activity timestamp. If not, every now and then we check and -if the activity timestamp gets old, we ping the device by sending it a -Keep Alive IE; it responds with a /DN_Alive/ pong during the DNTS (this -arrives to us as a notification through -devconnect.c:wusb_handle_dn_alive(). If a device times out, we -disconnect it from the system (cleaning up internal information and -toggling the bits in the fake hub port, which kicks hub_wq into removing -the rest of the stuff). - -This is done through devconnect:__wusb_check_devs(), which will scan the -device list looking for whom needs refreshing. - -If the device wants to disconnect, it will either die (ugly) or send a -/DN_Disconnect/ that will prompt a disconnection from the system. - -Sending and receiving data --------------------------- - -Data is sent and received through /Remote Pipes/ (rpipes). An rpipe is -/aimed/ at an endpoint in a WUSB device. This is the same for HWAs and -DWAs. - -Each HC has a number of rpipes and buffers that can be assigned to them; -when doing a data transfer (xfer), first the rpipe has to be aimed and -prepared (buffers assigned), then we can start queueing requests for -data in or out. - -Data buffers have to be segmented out before sending--so we send first a -header (segment request) and then if there is any data, a data buffer -immediately after to the DTI interface (yep, even the request). If our -buffer is bigger than the max segment size, then we just do multiple -requests. - -[This sucks, because doing USB scatter gatter in Linux is resource -intensive, if any...not that the current approach is not. It just has to -be cleaned up a lot :)]. - -If reading, we don't send data buffers, just the segment headers saying -we want to read segments. - -When the xfer is executed, we receive a notification that says data is -ready in the DTI endpoint (handled through -xfer.c:wa_handle_notif_xfer()). In there we read from the DTI endpoint a -descriptor that gives us the status of the transfer, its identification -(given when we issued it) and the segment number. If it was a data read, -we issue another URB to read into the destination buffer the chunk of -data coming out of the remote endpoint. Done, wait for the next guy. The -callbacks for the URBs issued from here are the ones that will declare -the xfer complete at some point and call its callback. - -Seems simple, but the implementation is not trivial. - - * - - *WARNING* Old!! - -The main xfer descriptor, wa_xfer (equivalent to a URB) contains an -array of segments, tallys on segments and buffers and callback -information. Buried in there is a lot of URBs for executing the segments -and buffer transfers. - -For OUT xfers, there is an array of segments, one URB for each, another -one of buffer URB. When submitting, we submit URBs for segment request -1, buffer 1, segment 2, buffer 2...etc. Then we wait on the DTI for xfer -result data; when all the segments are complete, we call the callback to -finalize the transfer. - -For IN xfers, we only issue URBs for the segments we want to read and -then wait for the xfer result data. - -URB mapping into xfers -^^^^^^^^^^^^^^^^^^^^^^ - -This is done by hwahc_op_urb_[en|de]queue(). In enqueue() we aim an -rpipe to the endpoint where we have to transmit, create a transfer -context (wa_xfer) and submit it. When the xfer is done, our callback is -called and we assign the status bits and release the xfer resources. - -In dequeue() we are basically cancelling/aborting the transfer. We issue -a xfer abort request to the HC, cancel all the URBs we had submitted -and not yet done and when all that is done, the xfer callback will be -called--this will call the URB callback. - - -Glossary -======== - -*DWA* -- Device Wire Adapter - -USB host, wired for downstream devices, upstream connects wirelessly -with Wireless USB. - -*EVENT* -- Response to a command on the NEEP - -*HWA* -- Host Wire Adapter / USB dongle for UWB and Wireless USB - -*NEH* -- Notification/Event Handle - -Handle/file descriptor for receiving notifications or events. The WA -code requires you to get one of this to listen for notifications or -events on the NEEP. - -*NEEP* -- Notification/Event EndPoint - -Stuff related to the management of the first endpoint of a HWA USB -dongle that is used to deliver an stream of events and notifications to -the host. - -*NOTIFICATION* -- Message coming in the NEEP as response to something. - -*RC* -- Radio Control - -Design-overview.txt-1.8 (last edited 2006-11-04 12:22:24 by -InakyPerezGonzalez) diff --git a/Documentation/usb/acm.rst b/Documentation/usb/acm.rst new file mode 100644 index 000000000000..e8bda98e9b51 --- /dev/null +++ b/Documentation/usb/acm.rst @@ -0,0 +1,132 @@ +====================== +Linux ACM driver v0.16 +====================== + +Copyright (c) 1999 Vojtech Pavlik + +Sponsored by SuSE + +0. Disclaimer +~~~~~~~~~~~~~ +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2 of the License, or (at your option) +any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., 59 +Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Should you need to contact me, the author, you can do so either by e-mail - +mail your message to , or by paper mail: Vojtech Pavlik, +Ucitelska 1576, Prague 8, 182 00 Czech Republic + +For your convenience, the GNU General Public License version 2 is included +in the package: See the file COPYING. + +1. Usage +~~~~~~~~ +The drivers/usb/class/cdc-acm.c drivers works with USB modems and USB ISDN terminal +adapters that conform to the Universal Serial Bus Communication Device Class +Abstract Control Model (USB CDC ACM) specification. + +Many modems do, here is a list of those I know of: + + - 3Com OfficeConnect 56k + - 3Com Voice FaxModem Pro + - 3Com Sportster + - MultiTech MultiModem 56k + - Zoom 2986L FaxModem + - Compaq 56k FaxModem + - ELSA Microlink 56k + +I know of one ISDN TA that does work with the acm driver: + + - 3Com USR ISDN Pro TA + +Some cell phones also connect via USB. I know the following phones work: + + - SonyEricsson K800i + +Unfortunately many modems and most ISDN TAs use proprietary interfaces and +thus won't work with this drivers. Check for ACM compliance before buying. + +To use the modems you need these modules loaded:: + + usbcore.ko + uhci-hcd.ko ohci-hcd.ko or ehci-hcd.ko + cdc-acm.ko + +After that, the modem[s] should be accessible. You should be able to use +minicom, ppp and mgetty with them. + +2. Verifying that it works +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The first step would be to check /sys/kernel/debug/usb/devices, it should look +like this:: + + T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 + B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0 + D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 + P: Vendor=0000 ProdID=0000 Rev= 0.00 + S: Product=USB UHCI Root Hub + S: SerialNumber=6800 + C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA + I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub + E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms + T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#= 2 Spd=12 MxCh= 0 + D: Ver= 1.00 Cls=02(comm.) Sub=00 Prot=00 MxPS= 8 #Cfgs= 2 + P: Vendor=04c1 ProdID=008f Rev= 2.07 + S: Manufacturer=3Com Inc. + S: Product=3Com U.S. Robotics Pro ISDN TA + S: SerialNumber=UFT53A49BVT7 + C: #Ifs= 1 Cfg#= 1 Atr=60 MxPwr= 0mA + I: If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=acm + E: Ad=85(I) Atr=02(Bulk) MxPS= 64 Ivl= 0ms + E: Ad=04(O) Atr=02(Bulk) MxPS= 64 Ivl= 0ms + E: Ad=81(I) Atr=03(Int.) MxPS= 16 Ivl=128ms + C:* #Ifs= 2 Cfg#= 2 Atr=60 MxPwr= 0mA + I: If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm + E: Ad=81(I) Atr=03(Int.) MxPS= 16 Ivl=128ms + I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm + E: Ad=85(I) Atr=02(Bulk) MxPS= 64 Ivl= 0ms + E: Ad=04(O) Atr=02(Bulk) MxPS= 64 Ivl= 0ms + +The presence of these three lines (and the Cls= 'comm' and 'data' classes) +is important, it means it's an ACM device. The Driver=acm means the acm +driver is used for the device. If you see only Cls=ff(vend.) then you're out +of luck, you have a device with vendor specific-interface:: + + D: Ver= 1.00 Cls=02(comm.) Sub=00 Prot=00 MxPS= 8 #Cfgs= 2 + I: If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm + I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm + +In the system log you should see:: + + usb.c: USB new device connect, assigned device number 2 + usb.c: kmalloc IF c7691fa0, numif 1 + usb.c: kmalloc IF c7b5f3e0, numif 2 + usb.c: skipped 4 class/vendor specific interface descriptors + usb.c: new device strings: Mfr=1, Product=2, SerialNumber=3 + usb.c: USB device number 2 default language ID 0x409 + Manufacturer: 3Com Inc. + Product: 3Com U.S. Robotics Pro ISDN TA + SerialNumber: UFT53A49BVT7 + acm.c: probing config 1 + acm.c: probing config 2 + ttyACM0: USB ACM device + acm.c: acm_control_msg: rq: 0x22 val: 0x0 len: 0x0 result: 0 + acm.c: acm_control_msg: rq: 0x20 val: 0x0 len: 0x7 result: 7 + usb.c: acm driver claimed interface c7b5f3e0 + usb.c: acm driver claimed interface c7b5f3f8 + usb.c: acm driver claimed interface c7691fa0 + +If all this seems to be OK, fire up minicom and set it to talk to the ttyACM +device and try typing 'at'. If it responds with 'OK', then everything is +working. diff --git a/Documentation/usb/acm.txt b/Documentation/usb/acm.txt deleted file mode 100644 index e8bda98e9b51..000000000000 --- a/Documentation/usb/acm.txt +++ /dev/null @@ -1,132 +0,0 @@ -====================== -Linux ACM driver v0.16 -====================== - -Copyright (c) 1999 Vojtech Pavlik - -Sponsored by SuSE - -0. Disclaimer -~~~~~~~~~~~~~ -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., 59 -Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Should you need to contact me, the author, you can do so either by e-mail - -mail your message to , or by paper mail: Vojtech Pavlik, -Ucitelska 1576, Prague 8, 182 00 Czech Republic - -For your convenience, the GNU General Public License version 2 is included -in the package: See the file COPYING. - -1. Usage -~~~~~~~~ -The drivers/usb/class/cdc-acm.c drivers works with USB modems and USB ISDN terminal -adapters that conform to the Universal Serial Bus Communication Device Class -Abstract Control Model (USB CDC ACM) specification. - -Many modems do, here is a list of those I know of: - - - 3Com OfficeConnect 56k - - 3Com Voice FaxModem Pro - - 3Com Sportster - - MultiTech MultiModem 56k - - Zoom 2986L FaxModem - - Compaq 56k FaxModem - - ELSA Microlink 56k - -I know of one ISDN TA that does work with the acm driver: - - - 3Com USR ISDN Pro TA - -Some cell phones also connect via USB. I know the following phones work: - - - SonyEricsson K800i - -Unfortunately many modems and most ISDN TAs use proprietary interfaces and -thus won't work with this drivers. Check for ACM compliance before buying. - -To use the modems you need these modules loaded:: - - usbcore.ko - uhci-hcd.ko ohci-hcd.ko or ehci-hcd.ko - cdc-acm.ko - -After that, the modem[s] should be accessible. You should be able to use -minicom, ppp and mgetty with them. - -2. Verifying that it works -~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The first step would be to check /sys/kernel/debug/usb/devices, it should look -like this:: - - T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 - B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0 - D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 - P: Vendor=0000 ProdID=0000 Rev= 0.00 - S: Product=USB UHCI Root Hub - S: SerialNumber=6800 - C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA - I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub - E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms - T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#= 2 Spd=12 MxCh= 0 - D: Ver= 1.00 Cls=02(comm.) Sub=00 Prot=00 MxPS= 8 #Cfgs= 2 - P: Vendor=04c1 ProdID=008f Rev= 2.07 - S: Manufacturer=3Com Inc. - S: Product=3Com U.S. Robotics Pro ISDN TA - S: SerialNumber=UFT53A49BVT7 - C: #Ifs= 1 Cfg#= 1 Atr=60 MxPwr= 0mA - I: If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=acm - E: Ad=85(I) Atr=02(Bulk) MxPS= 64 Ivl= 0ms - E: Ad=04(O) Atr=02(Bulk) MxPS= 64 Ivl= 0ms - E: Ad=81(I) Atr=03(Int.) MxPS= 16 Ivl=128ms - C:* #Ifs= 2 Cfg#= 2 Atr=60 MxPwr= 0mA - I: If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm - E: Ad=81(I) Atr=03(Int.) MxPS= 16 Ivl=128ms - I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm - E: Ad=85(I) Atr=02(Bulk) MxPS= 64 Ivl= 0ms - E: Ad=04(O) Atr=02(Bulk) MxPS= 64 Ivl= 0ms - -The presence of these three lines (and the Cls= 'comm' and 'data' classes) -is important, it means it's an ACM device. The Driver=acm means the acm -driver is used for the device. If you see only Cls=ff(vend.) then you're out -of luck, you have a device with vendor specific-interface:: - - D: Ver= 1.00 Cls=02(comm.) Sub=00 Prot=00 MxPS= 8 #Cfgs= 2 - I: If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm - I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm - -In the system log you should see:: - - usb.c: USB new device connect, assigned device number 2 - usb.c: kmalloc IF c7691fa0, numif 1 - usb.c: kmalloc IF c7b5f3e0, numif 2 - usb.c: skipped 4 class/vendor specific interface descriptors - usb.c: new device strings: Mfr=1, Product=2, SerialNumber=3 - usb.c: USB device number 2 default language ID 0x409 - Manufacturer: 3Com Inc. - Product: 3Com U.S. Robotics Pro ISDN TA - SerialNumber: UFT53A49BVT7 - acm.c: probing config 1 - acm.c: probing config 2 - ttyACM0: USB ACM device - acm.c: acm_control_msg: rq: 0x22 val: 0x0 len: 0x0 result: 0 - acm.c: acm_control_msg: rq: 0x20 val: 0x0 len: 0x7 result: 7 - usb.c: acm driver claimed interface c7b5f3e0 - usb.c: acm driver claimed interface c7b5f3f8 - usb.c: acm driver claimed interface c7691fa0 - -If all this seems to be OK, fire up minicom and set it to talk to the ttyACM -device and try typing 'at'. If it responds with 'OK', then everything is -working. diff --git a/Documentation/usb/authorization.rst b/Documentation/usb/authorization.rst new file mode 100644 index 000000000000..9e53909d04c2 --- /dev/null +++ b/Documentation/usb/authorization.rst @@ -0,0 +1,132 @@ +============================================================== +Authorizing (or not) your USB devices to connect to the system +============================================================== + +Copyright (C) 2007 Inaky Perez-Gonzalez Intel Corporation + +This feature allows you to control if a USB device can be used (or +not) in a system. This feature will allow you to implement a lock-down +of USB devices, fully controlled by user space. + +As of now, when a USB device is connected it is configured and +its interfaces are immediately made available to the users. With this +modification, only if root authorizes the device to be configured will +then it be possible to use it. + +Usage +===== + +Authorize a device to connect:: + + $ echo 1 > /sys/bus/usb/devices/DEVICE/authorized + +De-authorize a device:: + + $ echo 0 > /sys/bus/usb/devices/DEVICE/authorized + +Set new devices connected to hostX to be deauthorized by default (ie: +lock down):: + + $ echo 0 > /sys/bus/usb/devices/usbX/authorized_default + +Remove the lock down:: + + $ echo 1 > /sys/bus/usb/devices/usbX/authorized_default + +By default, Wired USB devices are authorized by default to +connect. Wireless USB hosts deauthorize by default all new connected +devices (this is so because we need to do an authentication phase +before authorizing). Writing "2" to the authorized_default attribute +causes kernel to only authorize by default devices connected to internal +USB ports. + + +Example system lockdown (lame) +------------------------------ + +Imagine you want to implement a lockdown so only devices of type XYZ +can be connected (for example, it is a kiosk machine with a visible +USB port):: + + boot up + rc.local -> + + for host in /sys/bus/usb/devices/usb* + do + echo 0 > $host/authorized_default + done + +Hookup an script to udev, for new USB devices:: + + if device_is_my_type $DEV + then + echo 1 > $device_path/authorized + done + + +Now, device_is_my_type() is where the juice for a lockdown is. Just +checking if the class, type and protocol match something is the worse +security verification you can make (or the best, for someone willing +to break it). If you need something secure, use crypto and Certificate +Authentication or stuff like that. Something simple for an storage key +could be:: + + function device_is_my_type() + { + echo 1 > authorized # temporarily authorize it + # FIXME: make sure none can mount it + mount DEVICENODE /mntpoint + sum=$(md5sum /mntpoint/.signature) + if [ $sum = $(cat /etc/lockdown/keysum) ] + then + echo "We are good, connected" + umount /mntpoint + # Other stuff so others can use it + else + echo 0 > authorized + fi + } + + +Of course, this is lame, you'd want to do a real certificate +verification stuff with PKI, so you don't depend on a shared secret, +etc, but you get the idea. Anybody with access to a device gadget kit +can fake descriptors and device info. Don't trust that. You are +welcome. + + +Interface authorization +----------------------- + +There is a similar approach to allow or deny specific USB interfaces. +That allows to block only a subset of an USB device. + +Authorize an interface:: + + $ echo 1 > /sys/bus/usb/devices/INTERFACE/authorized + +Deauthorize an interface:: + + $ echo 0 > /sys/bus/usb/devices/INTERFACE/authorized + +The default value for new interfaces +on a particular USB bus can be changed, too. + +Allow interfaces per default:: + + $ echo 1 > /sys/bus/usb/devices/usbX/interface_authorized_default + +Deny interfaces per default:: + + $ echo 0 > /sys/bus/usb/devices/usbX/interface_authorized_default + +Per default the interface_authorized_default bit is 1. +So all interfaces would authorized per default. + +Note: + If a deauthorized interface will be authorized so the driver probing must + be triggered manually by writing INTERFACE to /sys/bus/usb/drivers_probe + +For drivers that need multiple interfaces all needed interfaces should be +authorized first. After that the drivers should be probed. +This avoids side effects. diff --git a/Documentation/usb/authorization.txt b/Documentation/usb/authorization.txt deleted file mode 100644 index 9e53909d04c2..000000000000 --- a/Documentation/usb/authorization.txt +++ /dev/null @@ -1,132 +0,0 @@ -============================================================== -Authorizing (or not) your USB devices to connect to the system -============================================================== - -Copyright (C) 2007 Inaky Perez-Gonzalez Intel Corporation - -This feature allows you to control if a USB device can be used (or -not) in a system. This feature will allow you to implement a lock-down -of USB devices, fully controlled by user space. - -As of now, when a USB device is connected it is configured and -its interfaces are immediately made available to the users. With this -modification, only if root authorizes the device to be configured will -then it be possible to use it. - -Usage -===== - -Authorize a device to connect:: - - $ echo 1 > /sys/bus/usb/devices/DEVICE/authorized - -De-authorize a device:: - - $ echo 0 > /sys/bus/usb/devices/DEVICE/authorized - -Set new devices connected to hostX to be deauthorized by default (ie: -lock down):: - - $ echo 0 > /sys/bus/usb/devices/usbX/authorized_default - -Remove the lock down:: - - $ echo 1 > /sys/bus/usb/devices/usbX/authorized_default - -By default, Wired USB devices are authorized by default to -connect. Wireless USB hosts deauthorize by default all new connected -devices (this is so because we need to do an authentication phase -before authorizing). Writing "2" to the authorized_default attribute -causes kernel to only authorize by default devices connected to internal -USB ports. - - -Example system lockdown (lame) ------------------------------- - -Imagine you want to implement a lockdown so only devices of type XYZ -can be connected (for example, it is a kiosk machine with a visible -USB port):: - - boot up - rc.local -> - - for host in /sys/bus/usb/devices/usb* - do - echo 0 > $host/authorized_default - done - -Hookup an script to udev, for new USB devices:: - - if device_is_my_type $DEV - then - echo 1 > $device_path/authorized - done - - -Now, device_is_my_type() is where the juice for a lockdown is. Just -checking if the class, type and protocol match something is the worse -security verification you can make (or the best, for someone willing -to break it). If you need something secure, use crypto and Certificate -Authentication or stuff like that. Something simple for an storage key -could be:: - - function device_is_my_type() - { - echo 1 > authorized # temporarily authorize it - # FIXME: make sure none can mount it - mount DEVICENODE /mntpoint - sum=$(md5sum /mntpoint/.signature) - if [ $sum = $(cat /etc/lockdown/keysum) ] - then - echo "We are good, connected" - umount /mntpoint - # Other stuff so others can use it - else - echo 0 > authorized - fi - } - - -Of course, this is lame, you'd want to do a real certificate -verification stuff with PKI, so you don't depend on a shared secret, -etc, but you get the idea. Anybody with access to a device gadget kit -can fake descriptors and device info. Don't trust that. You are -welcome. - - -Interface authorization ------------------------ - -There is a similar approach to allow or deny specific USB interfaces. -That allows to block only a subset of an USB device. - -Authorize an interface:: - - $ echo 1 > /sys/bus/usb/devices/INTERFACE/authorized - -Deauthorize an interface:: - - $ echo 0 > /sys/bus/usb/devices/INTERFACE/authorized - -The default value for new interfaces -on a particular USB bus can be changed, too. - -Allow interfaces per default:: - - $ echo 1 > /sys/bus/usb/devices/usbX/interface_authorized_default - -Deny interfaces per default:: - - $ echo 0 > /sys/bus/usb/devices/usbX/interface_authorized_default - -Per default the interface_authorized_default bit is 1. -So all interfaces would authorized per default. - -Note: - If a deauthorized interface will be authorized so the driver probing must - be triggered manually by writing INTERFACE to /sys/bus/usb/drivers_probe - -For drivers that need multiple interfaces all needed interfaces should be -authorized first. After that the drivers should be probed. -This avoids side effects. diff --git a/Documentation/usb/chipidea.rst b/Documentation/usb/chipidea.rst new file mode 100644 index 000000000000..68473abe2823 --- /dev/null +++ b/Documentation/usb/chipidea.rst @@ -0,0 +1,133 @@ +============================================== +ChipIdea Highspeed Dual Role Controller Driver +============================================== + +1. How to test OTG FSM(HNP and SRP) +----------------------------------- + +To show how to demo OTG HNP and SRP functions via sys input files +with 2 Freescale i.MX6Q sabre SD boards. + +1.1 How to enable OTG FSM +------------------------- + +1.1.1 Select CONFIG_USB_OTG_FSM in menuconfig, rebuild kernel +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Image and modules. If you want to check some internal +variables for otg fsm, mount debugfs, there are 2 files +which can show otg fsm variables and some controller registers value:: + + cat /sys/kernel/debug/ci_hdrc.0/otg + cat /sys/kernel/debug/ci_hdrc.0/registers + +1.1.2 Add below entries in your dts file for your controller node +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +:: + + otg-rev = <0x0200>; + adp-disable; + +1.2 Test operations +------------------- + +1) Power up 2 Freescale i.MX6Q sabre SD boards with gadget class driver loaded + (e.g. g_mass_storage). + +2) Connect 2 boards with usb cable with one end is micro A plug, the other end + is micro B plug. + + The A-device(with micro A plug inserted) should enumerate B-device. + +3) Role switch + + On B-device:: + + echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req + + B-device should take host role and enumerate A-device. + +4) A-device switch back to host. + + On B-device:: + + echo 0 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req + + or, by introducing HNP polling, B-Host can know when A-peripheral wish + to be host role, so this role switch also can be trigged in A-peripheral + side by answering the polling from B-Host, this can be done on A-device:: + + echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_req + + A-device should switch back to host and enumerate B-device. + +5) Remove B-device(unplug micro B plug) and insert again in 10 seconds, + A-device should enumerate B-device again. + +6) Remove B-device(unplug micro B plug) and insert again after 10 seconds, + A-device should NOT enumerate B-device. + + if A-device wants to use bus: + + On A-device:: + + echo 0 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_drop + echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_req + + if B-device wants to use bus: + + On B-device:: + + echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req + +7) A-device power down the bus. + + On A-device:: + + echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_drop + + A-device should disconnect with B-device and power down the bus. + +8) B-device does data pulse for SRP. + + On B-device:: + + echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req + + A-device should resume usb bus and enumerate B-device. + +1.3 Reference document +---------------------- +"On-The-Go and Embedded Host Supplement to the USB Revision 2.0 Specification +July 27, 2012 Revision 2.0 version 1.1a" + +2. How to enable USB as system wakeup source +-------------------------------------------- +Below is the example for how to enable USB as system wakeup source +at imx6 platform. + +2.1 Enable core's wakeup:: + + echo enabled > /sys/bus/platform/devices/ci_hdrc.0/power/wakeup + +2.2 Enable glue layer's wakeup:: + + echo enabled > /sys/bus/platform/devices/2184000.usb/power/wakeup + +2.3 Enable PHY's wakeup (optional):: + + echo enabled > /sys/bus/platform/devices/20c9000.usbphy/power/wakeup + +2.4 Enable roothub's wakeup:: + + echo enabled > /sys/bus/usb/devices/usb1/power/wakeup + +2.5 Enable related device's wakeup:: + + echo enabled > /sys/bus/usb/devices/1-1/power/wakeup + +If the system has only one usb port, and you want usb wakeup at this port, you +can use below script to enable usb wakeup:: + + for i in $(find /sys -name wakeup | grep usb);do echo enabled > $i;done; diff --git a/Documentation/usb/chipidea.txt b/Documentation/usb/chipidea.txt deleted file mode 100644 index 68473abe2823..000000000000 --- a/Documentation/usb/chipidea.txt +++ /dev/null @@ -1,133 +0,0 @@ -============================================== -ChipIdea Highspeed Dual Role Controller Driver -============================================== - -1. How to test OTG FSM(HNP and SRP) ------------------------------------ - -To show how to demo OTG HNP and SRP functions via sys input files -with 2 Freescale i.MX6Q sabre SD boards. - -1.1 How to enable OTG FSM -------------------------- - -1.1.1 Select CONFIG_USB_OTG_FSM in menuconfig, rebuild kernel -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Image and modules. If you want to check some internal -variables for otg fsm, mount debugfs, there are 2 files -which can show otg fsm variables and some controller registers value:: - - cat /sys/kernel/debug/ci_hdrc.0/otg - cat /sys/kernel/debug/ci_hdrc.0/registers - -1.1.2 Add below entries in your dts file for your controller node -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -:: - - otg-rev = <0x0200>; - adp-disable; - -1.2 Test operations -------------------- - -1) Power up 2 Freescale i.MX6Q sabre SD boards with gadget class driver loaded - (e.g. g_mass_storage). - -2) Connect 2 boards with usb cable with one end is micro A plug, the other end - is micro B plug. - - The A-device(with micro A plug inserted) should enumerate B-device. - -3) Role switch - - On B-device:: - - echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req - - B-device should take host role and enumerate A-device. - -4) A-device switch back to host. - - On B-device:: - - echo 0 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req - - or, by introducing HNP polling, B-Host can know when A-peripheral wish - to be host role, so this role switch also can be trigged in A-peripheral - side by answering the polling from B-Host, this can be done on A-device:: - - echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_req - - A-device should switch back to host and enumerate B-device. - -5) Remove B-device(unplug micro B plug) and insert again in 10 seconds, - A-device should enumerate B-device again. - -6) Remove B-device(unplug micro B plug) and insert again after 10 seconds, - A-device should NOT enumerate B-device. - - if A-device wants to use bus: - - On A-device:: - - echo 0 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_drop - echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_req - - if B-device wants to use bus: - - On B-device:: - - echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req - -7) A-device power down the bus. - - On A-device:: - - echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/a_bus_drop - - A-device should disconnect with B-device and power down the bus. - -8) B-device does data pulse for SRP. - - On B-device:: - - echo 1 > /sys/bus/platform/devices/ci_hdrc.0/inputs/b_bus_req - - A-device should resume usb bus and enumerate B-device. - -1.3 Reference document ----------------------- -"On-The-Go and Embedded Host Supplement to the USB Revision 2.0 Specification -July 27, 2012 Revision 2.0 version 1.1a" - -2. How to enable USB as system wakeup source --------------------------------------------- -Below is the example for how to enable USB as system wakeup source -at imx6 platform. - -2.1 Enable core's wakeup:: - - echo enabled > /sys/bus/platform/devices/ci_hdrc.0/power/wakeup - -2.2 Enable glue layer's wakeup:: - - echo enabled > /sys/bus/platform/devices/2184000.usb/power/wakeup - -2.3 Enable PHY's wakeup (optional):: - - echo enabled > /sys/bus/platform/devices/20c9000.usbphy/power/wakeup - -2.4 Enable roothub's wakeup:: - - echo enabled > /sys/bus/usb/devices/usb1/power/wakeup - -2.5 Enable related device's wakeup:: - - echo enabled > /sys/bus/usb/devices/1-1/power/wakeup - -If the system has only one usb port, and you want usb wakeup at this port, you -can use below script to enable usb wakeup:: - - for i in $(find /sys -name wakeup | grep usb);do echo enabled > $i;done; diff --git a/Documentation/usb/dwc3.rst b/Documentation/usb/dwc3.rst new file mode 100644 index 000000000000..f94a7ba16573 --- /dev/null +++ b/Documentation/usb/dwc3.rst @@ -0,0 +1,53 @@ +=========== +DWC3 driver +=========== + + +TODO +~~~~ + +Please pick something while reading :) + +- Convert interrupt handler to per-ep-thread-irq + + As it turns out some DWC3-commands ~1ms to complete. Currently we spin + until the command completes which is bad. + + Implementation idea: + + - dwc core implements a demultiplexing irq chip for interrupts per + endpoint. The interrupt numbers are allocated during probe and belong + to the device. If MSI provides per-endpoint interrupt this dummy + interrupt chip can be replaced with "real" interrupts. + - interrupts are requested / allocated on usb_ep_enable() and removed on + usb_ep_disable(). Worst case are 32 interrupts, the lower limit is two + for ep0/1. + - dwc3_send_gadget_ep_cmd() will sleep in wait_for_completion_timeout() + until the command completes. + - the interrupt handler is split into the following pieces: + + - primary handler of the device + goes through every event and calls generic_handle_irq() for event + it. On return from generic_handle_irq() in acknowledges the event + counter so interrupt goes away (eventually). + + - threaded handler of the device + none + + - primary handler of the EP-interrupt + reads the event and tries to process it. Everything that requires + sleeping is handed over to the Thread. The event is saved in an + per-endpoint data-structure. + We probably have to pay attention not to process events once we + handed something to thread so we don't process event X prio Y + where X > Y. + + - threaded handler of the EP-interrupt + handles the remaining EP work which might sleep such as waiting + for command completion. + + Latency: + + There should be no increase in latency since the interrupt-thread has a + high priority and will be run before an average task in user land + (except the user changed priorities). diff --git a/Documentation/usb/dwc3.txt b/Documentation/usb/dwc3.txt deleted file mode 100644 index f94a7ba16573..000000000000 --- a/Documentation/usb/dwc3.txt +++ /dev/null @@ -1,53 +0,0 @@ -=========== -DWC3 driver -=========== - - -TODO -~~~~ - -Please pick something while reading :) - -- Convert interrupt handler to per-ep-thread-irq - - As it turns out some DWC3-commands ~1ms to complete. Currently we spin - until the command completes which is bad. - - Implementation idea: - - - dwc core implements a demultiplexing irq chip for interrupts per - endpoint. The interrupt numbers are allocated during probe and belong - to the device. If MSI provides per-endpoint interrupt this dummy - interrupt chip can be replaced with "real" interrupts. - - interrupts are requested / allocated on usb_ep_enable() and removed on - usb_ep_disable(). Worst case are 32 interrupts, the lower limit is two - for ep0/1. - - dwc3_send_gadget_ep_cmd() will sleep in wait_for_completion_timeout() - until the command completes. - - the interrupt handler is split into the following pieces: - - - primary handler of the device - goes through every event and calls generic_handle_irq() for event - it. On return from generic_handle_irq() in acknowledges the event - counter so interrupt goes away (eventually). - - - threaded handler of the device - none - - - primary handler of the EP-interrupt - reads the event and tries to process it. Everything that requires - sleeping is handed over to the Thread. The event is saved in an - per-endpoint data-structure. - We probably have to pay attention not to process events once we - handed something to thread so we don't process event X prio Y - where X > Y. - - - threaded handler of the EP-interrupt - handles the remaining EP work which might sleep such as waiting - for command completion. - - Latency: - - There should be no increase in latency since the interrupt-thread has a - high priority and will be run before an average task in user land - (except the user changed priorities). diff --git a/Documentation/usb/ehci.rst b/Documentation/usb/ehci.rst new file mode 100644 index 000000000000..31f650e7c1b4 --- /dev/null +++ b/Documentation/usb/ehci.rst @@ -0,0 +1,230 @@ +=========== +EHCI driver +=========== + +27-Dec-2002 + +The EHCI driver is used to talk to high speed USB 2.0 devices using +USB 2.0-capable host controller hardware. The USB 2.0 standard is +compatible with the USB 1.1 standard. It defines three transfer speeds: + + - "High Speed" 480 Mbit/sec (60 MByte/sec) + - "Full Speed" 12 Mbit/sec (1.5 MByte/sec) + - "Low Speed" 1.5 Mbit/sec + +USB 1.1 only addressed full speed and low speed. High speed devices +can be used on USB 1.1 systems, but they slow down to USB 1.1 speeds. + +USB 1.1 devices may also be used on USB 2.0 systems. When plugged +into an EHCI controller, they are given to a USB 1.1 "companion" +controller, which is a OHCI or UHCI controller as normally used with +such devices. When USB 1.1 devices plug into USB 2.0 hubs, they +interact with the EHCI controller through a "Transaction Translator" +(TT) in the hub, which turns low or full speed transactions into +high speed "split transactions" that don't waste transfer bandwidth. + +At this writing, this driver has been seen to work with implementations +of EHCI from (in alphabetical order): Intel, NEC, Philips, and VIA. +Other EHCI implementations are becoming available from other vendors; +you should expect this driver to work with them too. + +While usb-storage devices have been available since mid-2001 (working +quite speedily on the 2.4 version of this driver), hubs have only +been available since late 2001, and other kinds of high speed devices +appear to be on hold until more systems come with USB 2.0 built-in. +Such new systems have been available since early 2002, and became much +more typical in the second half of 2002. + +Note that USB 2.0 support involves more than just EHCI. It requires +other changes to the Linux-USB core APIs, including the hub driver, +but those changes haven't needed to really change the basic "usbcore" +APIs exposed to USB device drivers. + +- David Brownell + + + +Functionality +============= + +This driver is regularly tested on x86 hardware, and has also been +used on PPC hardware so big/little endianness issues should be gone. +It's believed to do all the right PCI magic so that I/O works even on +systems with interesting DMA mapping issues. + +Transfer Types +-------------- + +At this writing the driver should comfortably handle all control, bulk, +and interrupt transfers, including requests to USB 1.1 devices through +transaction translators (TTs) in USB 2.0 hubs. But you may find bugs. + +High Speed Isochronous (ISO) transfer support is also functional, but +at this writing no Linux drivers have been using that support. + +Full Speed Isochronous transfer support, through transaction translators, +is not yet available. Note that split transaction support for ISO +transfers can't share much code with the code for high speed ISO transfers, +since EHCI represents these with a different data structure. So for now, +most USB audio and video devices can't be connected to high speed buses. + +Driver Behavior +--------------- + +Transfers of all types can be queued. This means that control transfers +from a driver on one interface (or through usbfs) won't interfere with +ones from another driver, and that interrupt transfers can use periods +of one frame without risking data loss due to interrupt processing costs. + +The EHCI root hub code hands off USB 1.1 devices to its companion +controller. This driver doesn't need to know anything about those +drivers; a OHCI or UHCI driver that works already doesn't need to change +just because the EHCI driver is also present. + +There are some issues with power management; suspend/resume doesn't +behave quite right at the moment. + +Also, some shortcuts have been taken with the scheduling periodic +transactions (interrupt and isochronous transfers). These place some +limits on the number of periodic transactions that can be scheduled, +and prevent use of polling intervals of less than one frame. + + +Use by +====== + +Assuming you have an EHCI controller (on a PCI card or motherboard) +and have compiled this driver as a module, load this like:: + + # modprobe ehci-hcd + +and remove it by:: + + # rmmod ehci-hcd + +You should also have a driver for a "companion controller", such as +"ohci-hcd" or "uhci-hcd". In case of any trouble with the EHCI driver, +remove its module and then the driver for that companion controller will +take over (at lower speed) all the devices that were previously handled +by the EHCI driver. + +Module parameters (pass to "modprobe") include: + + log2_irq_thresh (default 0): + Log2 of default interrupt delay, in microframes. The default + value is 0, indicating 1 microframe (125 usec). Maximum value + is 6, indicating 2^6 = 64 microframes. This controls how often + the EHCI controller can issue interrupts. + +If you're using this driver on a 2.5 kernel, and you've enabled USB +debugging support, you'll see three files in the "sysfs" directory for +any EHCI controller: + + "async" + dumps the asynchronous schedule, used for control + and bulk transfers. Shows each active qh and the qtds + pending, usually one qtd per urb. (Look at it with + usb-storage doing disk I/O; watch the request queues!) + "periodic" + dumps the periodic schedule, used for interrupt + and isochronous transfers. Doesn't show qtds. + "registers" + show controller register state, and + +The contents of those files can help identify driver problems. + + +Device drivers shouldn't care whether they're running over EHCI or not, +but they may want to check for "usb_device->speed == USB_SPEED_HIGH". +High speed devices can do things that full speed (or low speed) ones +can't, such as "high bandwidth" periodic (interrupt or ISO) transfers. +Also, some values in device descriptors (such as polling intervals for +periodic transfers) use different encodings when operating at high speed. + +However, do make a point of testing device drivers through USB 2.0 hubs. +Those hubs report some failures, such as disconnections, differently when +transaction translators are in use; some drivers have been seen to behave +badly when they see different faults than OHCI or UHCI report. + + +Performance +=========== + +USB 2.0 throughput is gated by two main factors: how fast the host +controller can process requests, and how fast devices can respond to +them. The 480 Mbit/sec "raw transfer rate" is obeyed by all devices, +but aggregate throughput is also affected by issues like delays between +individual high speed packets, driver intelligence, and of course the +overall system load. Latency is also a performance concern. + +Bulk transfers are most often used where throughput is an issue. It's +good to keep in mind that bulk transfers are always in 512 byte packets, +and at most 13 of those fit into one USB 2.0 microframe. Eight USB 2.0 +microframes fit in a USB 1.1 frame; a microframe is 1 msec/8 = 125 usec. + +So more than 50 MByte/sec is available for bulk transfers, when both +hardware and device driver software allow it. Periodic transfer modes +(isochronous and interrupt) allow the larger packet sizes which let you +approach the quoted 480 MBit/sec transfer rate. + +Hardware Performance +-------------------- + +At this writing, individual USB 2.0 devices tend to max out at around +20 MByte/sec transfer rates. This is of course subject to change; +and some devices now go faster, while others go slower. + +The first NEC implementation of EHCI seems to have a hardware bottleneck +at around 28 MByte/sec aggregate transfer rate. While this is clearly +enough for a single device at 20 MByte/sec, putting three such devices +onto one bus does not get you 60 MByte/sec. The issue appears to be +that the controller hardware won't do concurrent USB and PCI access, +so that it's only trying six (or maybe seven) USB transactions each +microframe rather than thirteen. (Seems like a reasonable trade off +for a product that beat all the others to market by over a year!) + +It's expected that newer implementations will better this, throwing +more silicon real estate at the problem so that new motherboard chip +sets will get closer to that 60 MByte/sec target. That includes an +updated implementation from NEC, as well as other vendors' silicon. + +There's a minimum latency of one microframe (125 usec) for the host +to receive interrupts from the EHCI controller indicating completion +of requests. That latency is tunable; there's a module option. By +default ehci-hcd driver uses the minimum latency, which means that if +you issue a control or bulk request you can often expect to learn that +it completed in less than 250 usec (depending on transfer size). + +Software Performance +-------------------- + +To get even 20 MByte/sec transfer rates, Linux-USB device drivers will +need to keep the EHCI queue full. That means issuing large requests, +or using bulk queuing if a series of small requests needs to be issued. +When drivers don't do that, their performance results will show it. + +In typical situations, a usb_bulk_msg() loop writing out 4 KB chunks is +going to waste more than half the USB 2.0 bandwidth. Delays between the +I/O completion and the driver issuing the next request will take longer +than the I/O. If that same loop used 16 KB chunks, it'd be better; a +sequence of 128 KB chunks would waste a lot less. + +But rather than depending on such large I/O buffers to make synchronous +I/O be efficient, it's better to just queue up several (bulk) requests +to the HC, and wait for them all to complete (or be canceled on error). +Such URB queuing should work with all the USB 1.1 HC drivers too. + +In the Linux 2.5 kernels, new usb_sg_*() api calls have been defined; they +queue all the buffers from a scatterlist. They also use scatterlist DMA +mapping (which might apply an IOMMU) and IRQ reduction, all of which will +help make high speed transfers run as fast as they can. + + +TBD: + Interrupt and ISO transfer performance issues. Those periodic + transfers are fully scheduled, so the main issue is likely to be how + to trigger "high bandwidth" modes. + +TBD: + More than standard 80% periodic bandwidth allocation is possible + through sysfs uframe_periodic_max parameter. Describe that. diff --git a/Documentation/usb/ehci.txt b/Documentation/usb/ehci.txt deleted file mode 100644 index 31f650e7c1b4..000000000000 --- a/Documentation/usb/ehci.txt +++ /dev/null @@ -1,230 +0,0 @@ -=========== -EHCI driver -=========== - -27-Dec-2002 - -The EHCI driver is used to talk to high speed USB 2.0 devices using -USB 2.0-capable host controller hardware. The USB 2.0 standard is -compatible with the USB 1.1 standard. It defines three transfer speeds: - - - "High Speed" 480 Mbit/sec (60 MByte/sec) - - "Full Speed" 12 Mbit/sec (1.5 MByte/sec) - - "Low Speed" 1.5 Mbit/sec - -USB 1.1 only addressed full speed and low speed. High speed devices -can be used on USB 1.1 systems, but they slow down to USB 1.1 speeds. - -USB 1.1 devices may also be used on USB 2.0 systems. When plugged -into an EHCI controller, they are given to a USB 1.1 "companion" -controller, which is a OHCI or UHCI controller as normally used with -such devices. When USB 1.1 devices plug into USB 2.0 hubs, they -interact with the EHCI controller through a "Transaction Translator" -(TT) in the hub, which turns low or full speed transactions into -high speed "split transactions" that don't waste transfer bandwidth. - -At this writing, this driver has been seen to work with implementations -of EHCI from (in alphabetical order): Intel, NEC, Philips, and VIA. -Other EHCI implementations are becoming available from other vendors; -you should expect this driver to work with them too. - -While usb-storage devices have been available since mid-2001 (working -quite speedily on the 2.4 version of this driver), hubs have only -been available since late 2001, and other kinds of high speed devices -appear to be on hold until more systems come with USB 2.0 built-in. -Such new systems have been available since early 2002, and became much -more typical in the second half of 2002. - -Note that USB 2.0 support involves more than just EHCI. It requires -other changes to the Linux-USB core APIs, including the hub driver, -but those changes haven't needed to really change the basic "usbcore" -APIs exposed to USB device drivers. - -- David Brownell - - - -Functionality -============= - -This driver is regularly tested on x86 hardware, and has also been -used on PPC hardware so big/little endianness issues should be gone. -It's believed to do all the right PCI magic so that I/O works even on -systems with interesting DMA mapping issues. - -Transfer Types --------------- - -At this writing the driver should comfortably handle all control, bulk, -and interrupt transfers, including requests to USB 1.1 devices through -transaction translators (TTs) in USB 2.0 hubs. But you may find bugs. - -High Speed Isochronous (ISO) transfer support is also functional, but -at this writing no Linux drivers have been using that support. - -Full Speed Isochronous transfer support, through transaction translators, -is not yet available. Note that split transaction support for ISO -transfers can't share much code with the code for high speed ISO transfers, -since EHCI represents these with a different data structure. So for now, -most USB audio and video devices can't be connected to high speed buses. - -Driver Behavior ---------------- - -Transfers of all types can be queued. This means that control transfers -from a driver on one interface (or through usbfs) won't interfere with -ones from another driver, and that interrupt transfers can use periods -of one frame without risking data loss due to interrupt processing costs. - -The EHCI root hub code hands off USB 1.1 devices to its companion -controller. This driver doesn't need to know anything about those -drivers; a OHCI or UHCI driver that works already doesn't need to change -just because the EHCI driver is also present. - -There are some issues with power management; suspend/resume doesn't -behave quite right at the moment. - -Also, some shortcuts have been taken with the scheduling periodic -transactions (interrupt and isochronous transfers). These place some -limits on the number of periodic transactions that can be scheduled, -and prevent use of polling intervals of less than one frame. - - -Use by -====== - -Assuming you have an EHCI controller (on a PCI card or motherboard) -and have compiled this driver as a module, load this like:: - - # modprobe ehci-hcd - -and remove it by:: - - # rmmod ehci-hcd - -You should also have a driver for a "companion controller", such as -"ohci-hcd" or "uhci-hcd". In case of any trouble with the EHCI driver, -remove its module and then the driver for that companion controller will -take over (at lower speed) all the devices that were previously handled -by the EHCI driver. - -Module parameters (pass to "modprobe") include: - - log2_irq_thresh (default 0): - Log2 of default interrupt delay, in microframes. The default - value is 0, indicating 1 microframe (125 usec). Maximum value - is 6, indicating 2^6 = 64 microframes. This controls how often - the EHCI controller can issue interrupts. - -If you're using this driver on a 2.5 kernel, and you've enabled USB -debugging support, you'll see three files in the "sysfs" directory for -any EHCI controller: - - "async" - dumps the asynchronous schedule, used for control - and bulk transfers. Shows each active qh and the qtds - pending, usually one qtd per urb. (Look at it with - usb-storage doing disk I/O; watch the request queues!) - "periodic" - dumps the periodic schedule, used for interrupt - and isochronous transfers. Doesn't show qtds. - "registers" - show controller register state, and - -The contents of those files can help identify driver problems. - - -Device drivers shouldn't care whether they're running over EHCI or not, -but they may want to check for "usb_device->speed == USB_SPEED_HIGH". -High speed devices can do things that full speed (or low speed) ones -can't, such as "high bandwidth" periodic (interrupt or ISO) transfers. -Also, some values in device descriptors (such as polling intervals for -periodic transfers) use different encodings when operating at high speed. - -However, do make a point of testing device drivers through USB 2.0 hubs. -Those hubs report some failures, such as disconnections, differently when -transaction translators are in use; some drivers have been seen to behave -badly when they see different faults than OHCI or UHCI report. - - -Performance -=========== - -USB 2.0 throughput is gated by two main factors: how fast the host -controller can process requests, and how fast devices can respond to -them. The 480 Mbit/sec "raw transfer rate" is obeyed by all devices, -but aggregate throughput is also affected by issues like delays between -individual high speed packets, driver intelligence, and of course the -overall system load. Latency is also a performance concern. - -Bulk transfers are most often used where throughput is an issue. It's -good to keep in mind that bulk transfers are always in 512 byte packets, -and at most 13 of those fit into one USB 2.0 microframe. Eight USB 2.0 -microframes fit in a USB 1.1 frame; a microframe is 1 msec/8 = 125 usec. - -So more than 50 MByte/sec is available for bulk transfers, when both -hardware and device driver software allow it. Periodic transfer modes -(isochronous and interrupt) allow the larger packet sizes which let you -approach the quoted 480 MBit/sec transfer rate. - -Hardware Performance --------------------- - -At this writing, individual USB 2.0 devices tend to max out at around -20 MByte/sec transfer rates. This is of course subject to change; -and some devices now go faster, while others go slower. - -The first NEC implementation of EHCI seems to have a hardware bottleneck -at around 28 MByte/sec aggregate transfer rate. While this is clearly -enough for a single device at 20 MByte/sec, putting three such devices -onto one bus does not get you 60 MByte/sec. The issue appears to be -that the controller hardware won't do concurrent USB and PCI access, -so that it's only trying six (or maybe seven) USB transactions each -microframe rather than thirteen. (Seems like a reasonable trade off -for a product that beat all the others to market by over a year!) - -It's expected that newer implementations will better this, throwing -more silicon real estate at the problem so that new motherboard chip -sets will get closer to that 60 MByte/sec target. That includes an -updated implementation from NEC, as well as other vendors' silicon. - -There's a minimum latency of one microframe (125 usec) for the host -to receive interrupts from the EHCI controller indicating completion -of requests. That latency is tunable; there's a module option. By -default ehci-hcd driver uses the minimum latency, which means that if -you issue a control or bulk request you can often expect to learn that -it completed in less than 250 usec (depending on transfer size). - -Software Performance --------------------- - -To get even 20 MByte/sec transfer rates, Linux-USB device drivers will -need to keep the EHCI queue full. That means issuing large requests, -or using bulk queuing if a series of small requests needs to be issued. -When drivers don't do that, their performance results will show it. - -In typical situations, a usb_bulk_msg() loop writing out 4 KB chunks is -going to waste more than half the USB 2.0 bandwidth. Delays between the -I/O completion and the driver issuing the next request will take longer -than the I/O. If that same loop used 16 KB chunks, it'd be better; a -sequence of 128 KB chunks would waste a lot less. - -But rather than depending on such large I/O buffers to make synchronous -I/O be efficient, it's better to just queue up several (bulk) requests -to the HC, and wait for them all to complete (or be canceled on error). -Such URB queuing should work with all the USB 1.1 HC drivers too. - -In the Linux 2.5 kernels, new usb_sg_*() api calls have been defined; they -queue all the buffers from a scatterlist. They also use scatterlist DMA -mapping (which might apply an IOMMU) and IRQ reduction, all of which will -help make high speed transfers run as fast as they can. - - -TBD: - Interrupt and ISO transfer performance issues. Those periodic - transfers are fully scheduled, so the main issue is likely to be how - to trigger "high bandwidth" modes. - -TBD: - More than standard 80% periodic bandwidth allocation is possible - through sysfs uframe_periodic_max parameter. Describe that. diff --git a/Documentation/usb/functionfs.rst b/Documentation/usb/functionfs.rst new file mode 100644 index 000000000000..7fdc6d840ac5 --- /dev/null +++ b/Documentation/usb/functionfs.rst @@ -0,0 +1,68 @@ +==================== +How FunctionFS works +==================== + +From kernel point of view it is just a composite function with some +unique behaviour. It may be added to an USB configuration only after +the user space driver has registered by writing descriptors and +strings (the user space program has to provide the same information +that kernel level composite functions provide when they are added to +the configuration). + +This in particular means that the composite initialisation functions +may not be in init section (ie. may not use the __init tag). + +From user space point of view it is a file system which when +mounted provides an "ep0" file. User space driver need to +write descriptors and strings to that file. It does not need +to worry about endpoints, interfaces or strings numbers but +simply provide descriptors such as if the function was the +only one (endpoints and strings numbers starting from one and +interface numbers starting from zero). The FunctionFS changes +them as needed also handling situation when numbers differ in +different configurations. + +When descriptors and strings are written "ep#" files appear +(one for each declared endpoint) which handle communication on +a single endpoint. Again, FunctionFS takes care of the real +numbers and changing of the configuration (which means that +"ep1" file may be really mapped to (say) endpoint 3 (and when +configuration changes to (say) endpoint 2)). "ep0" is used +for receiving events and handling setup requests. + +When all files are closed the function disables itself. + +What I also want to mention is that the FunctionFS is designed in such +a way that it is possible to mount it several times so in the end +a gadget could use several FunctionFS functions. The idea is that +each FunctionFS instance is identified by the device name used +when mounting. + +One can imagine a gadget that has an Ethernet, MTP and HID interfaces +where the last two are implemented via FunctionFS. On user space +level it would look like this:: + + $ insmod g_ffs.ko idVendor= iSerialNumber= functions=mtp,hid + $ mkdir /dev/ffs-mtp && mount -t functionfs mtp /dev/ffs-mtp + $ ( cd /dev/ffs-mtp && mtp-daemon ) & + $ mkdir /dev/ffs-hid && mount -t functionfs hid /dev/ffs-hid + $ ( cd /dev/ffs-hid && hid-daemon ) & + +On kernel level the gadget checks ffs_data->dev_name to identify +whether it's FunctionFS designed for MTP ("mtp") or HID ("hid"). + +If no "functions" module parameters is supplied, the driver accepts +just one function with any name. + +When "functions" module parameter is supplied, only functions +with listed names are accepted. In particular, if the "functions" +parameter's value is just a one-element list, then the behaviour +is similar to when there is no "functions" at all; however, +only a function with the specified name is accepted. + +The gadget is registered only after all the declared function +filesystems have been mounted and USB descriptors of all functions +have been written to their ep0's. + +Conversely, the gadget is unregistered after the first USB function +closes its endpoints. diff --git a/Documentation/usb/functionfs.txt b/Documentation/usb/functionfs.txt deleted file mode 100644 index 7fdc6d840ac5..000000000000 --- a/Documentation/usb/functionfs.txt +++ /dev/null @@ -1,68 +0,0 @@ -==================== -How FunctionFS works -==================== - -From kernel point of view it is just a composite function with some -unique behaviour. It may be added to an USB configuration only after -the user space driver has registered by writing descriptors and -strings (the user space program has to provide the same information -that kernel level composite functions provide when they are added to -the configuration). - -This in particular means that the composite initialisation functions -may not be in init section (ie. may not use the __init tag). - -From user space point of view it is a file system which when -mounted provides an "ep0" file. User space driver need to -write descriptors and strings to that file. It does not need -to worry about endpoints, interfaces or strings numbers but -simply provide descriptors such as if the function was the -only one (endpoints and strings numbers starting from one and -interface numbers starting from zero). The FunctionFS changes -them as needed also handling situation when numbers differ in -different configurations. - -When descriptors and strings are written "ep#" files appear -(one for each declared endpoint) which handle communication on -a single endpoint. Again, FunctionFS takes care of the real -numbers and changing of the configuration (which means that -"ep1" file may be really mapped to (say) endpoint 3 (and when -configuration changes to (say) endpoint 2)). "ep0" is used -for receiving events and handling setup requests. - -When all files are closed the function disables itself. - -What I also want to mention is that the FunctionFS is designed in such -a way that it is possible to mount it several times so in the end -a gadget could use several FunctionFS functions. The idea is that -each FunctionFS instance is identified by the device name used -when mounting. - -One can imagine a gadget that has an Ethernet, MTP and HID interfaces -where the last two are implemented via FunctionFS. On user space -level it would look like this:: - - $ insmod g_ffs.ko idVendor= iSerialNumber= functions=mtp,hid - $ mkdir /dev/ffs-mtp && mount -t functionfs mtp /dev/ffs-mtp - $ ( cd /dev/ffs-mtp && mtp-daemon ) & - $ mkdir /dev/ffs-hid && mount -t functionfs hid /dev/ffs-hid - $ ( cd /dev/ffs-hid && hid-daemon ) & - -On kernel level the gadget checks ffs_data->dev_name to identify -whether it's FunctionFS designed for MTP ("mtp") or HID ("hid"). - -If no "functions" module parameters is supplied, the driver accepts -just one function with any name. - -When "functions" module parameter is supplied, only functions -with listed names are accepted. In particular, if the "functions" -parameter's value is just a one-element list, then the behaviour -is similar to when there is no "functions" at all; however, -only a function with the specified name is accepted. - -The gadget is registered only after all the declared function -filesystems have been mounted and USB descriptors of all functions -have been written to their ep0's. - -Conversely, the gadget is unregistered after the first USB function -closes its endpoints. diff --git a/Documentation/usb/gadget-testing.rst b/Documentation/usb/gadget-testing.rst new file mode 100644 index 000000000000..2eeb3e9299e4 --- /dev/null +++ b/Documentation/usb/gadget-testing.rst @@ -0,0 +1,934 @@ +============== +Gadget Testing +============== + +This file summarizes information on basic testing of USB functions +provided by gadgets. + +.. contents + + 1. ACM function + 2. ECM function + 3. ECM subset function + 4. EEM function + 5. FFS function + 6. HID function + 7. LOOPBACK function + 8. MASS STORAGE function + 9. MIDI function + 10. NCM function + 11. OBEX function + 12. PHONET function + 13. RNDIS function + 14. SERIAL function + 15. SOURCESINK function + 16. UAC1 function (legacy implementation) + 17. UAC2 function + 18. UVC function + 19. PRINTER function + 20. UAC1 function (new API) + + +1. ACM function +=============== + +The function is provided by usb_f_acm.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "acm". +The ACM function provides just one attribute in its function directory: + + port_num + +The attribute is read-only. + +There can be at most 4 ACM/generic serial/OBEX ports in the system. + + +Testing the ACM function +------------------------ + +On the host:: + + cat > /dev/ttyACM + +On the device:: + + cat /dev/ttyGS + +then the other way round + +On the device:: + + cat > /dev/ttyGS + +On the host:: + + cat /dev/ttyACM + +2. ECM function +=============== + +The function is provided by usb_f_ecm.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "ecm". +The ECM function provides these attributes in its function directory: + + =============== ================================================== + ifname network device interface name associated with this + function instance + qmult queue length multiplier for high and super speed + host_addr MAC address of host's end of this + Ethernet over USB link + dev_addr MAC address of device's end of this + Ethernet over USB link + =============== ================================================== + +and after creating the functions/ecm. they contain default +values: qmult is 5, dev_addr and host_addr are randomly selected. +Except for ifname they can be written to until the function is linked to a +configuration. The ifname is read-only and contains the name of the interface +which was assigned by the net core, e. g. usb0. + +Testing the ECM function +------------------------ + +Configure IP addresses of the device and the host. Then: + +On the device:: + + ping + +On the host:: + + ping + +3. ECM subset function +====================== + +The function is provided by usb_f_ecm_subset.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "geth". +The ECM subset function provides these attributes in its function directory: + + =============== ================================================== + ifname network device interface name associated with this + function instance + qmult queue length multiplier for high and super speed + host_addr MAC address of host's end of this + Ethernet over USB link + dev_addr MAC address of device's end of this + Ethernet over USB link + =============== ================================================== + +and after creating the functions/ecm. they contain default +values: qmult is 5, dev_addr and host_addr are randomly selected. +Except for ifname they can be written to until the function is linked to a +configuration. The ifname is read-only and contains the name of the interface +which was assigned by the net core, e. g. usb0. + +Testing the ECM subset function +------------------------------- + +Configure IP addresses of the device and the host. Then: + +On the device:: + + ping + +On the host:: + + ping + +4. EEM function +=============== + +The function is provided by usb_f_eem.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "eem". +The EEM function provides these attributes in its function directory: + + =============== ================================================== + ifname network device interface name associated with this + function instance + qmult queue length multiplier for high and super speed + host_addr MAC address of host's end of this + Ethernet over USB link + dev_addr MAC address of device's end of this + Ethernet over USB link + =============== ================================================== + +and after creating the functions/eem. they contain default +values: qmult is 5, dev_addr and host_addr are randomly selected. +Except for ifname they can be written to until the function is linked to a +configuration. The ifname is read-only and contains the name of the interface +which was assigned by the net core, e. g. usb0. + +Testing the EEM function +------------------------ + +Configure IP addresses of the device and the host. Then: + +On the device:: + + ping + +On the host:: + + ping + +5. FFS function +=============== + +The function is provided by usb_f_fs.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "ffs". +The function directory is intentionally empty and not modifiable. + +After creating the directory there is a new instance (a "device") of FunctionFS +available in the system. Once a "device" is available, the user should follow +the standard procedure for using FunctionFS (mount it, run the userspace +process which implements the function proper). The gadget should be enabled +by writing a suitable string to usb_gadget//UDC. + +Testing the FFS function +------------------------ + +On the device: start the function's userspace daemon, enable the gadget + +On the host: use the USB function provided by the device + +6. HID function +=============== + +The function is provided by usb_f_hid.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "hid". +The HID function provides these attributes in its function directory: + + =============== =========================================== + protocol HID protocol to use + report_desc data to be used in HID reports, except data + passed with /dev/hidg + report_length HID report length + subclass HID subclass to use + =============== =========================================== + +For a keyboard the protocol and the subclass are 1, the report_length is 8, +while the report_desc is:: + + $ hd my_report_desc + 00000000 05 01 09 06 a1 01 05 07 19 e0 29 e7 15 00 25 01 |..........)...%.| + 00000010 75 01 95 08 81 02 95 01 75 08 81 03 95 05 75 01 |u.......u.....u.| + 00000020 05 08 19 01 29 05 91 02 95 01 75 03 91 03 95 06 |....).....u.....| + 00000030 75 08 15 00 25 65 05 07 19 00 29 65 81 00 c0 |u...%e....)e...| + 0000003f + +Such a sequence of bytes can be stored to the attribute with echo:: + + $ echo -ne \\x05\\x01\\x09\\x06\\xa1..... + +Testing the HID function +------------------------ + +Device: + +- create the gadget +- connect the gadget to a host, preferably not the one used + to control the gadget +- run a program which writes to /dev/hidg, e.g. + a userspace program found in Documentation/usb/gadget_hid.rst:: + + $ ./hid_gadget_test /dev/hidg0 keyboard + +Host: + +- observe the keystrokes from the gadget + +7. LOOPBACK function +==================== + +The function is provided by usb_f_ss_lb.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "Loopback". +The LOOPBACK function provides these attributes in its function directory: + + =============== ======================= + qlen depth of loopback queue + bulk_buflen buffer length + =============== ======================= + +Testing the LOOPBACK function +----------------------------- + +device: run the gadget + +host: test-usb (tools/usb/testusb.c) + +8. MASS STORAGE function +======================== + +The function is provided by usb_f_mass_storage.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "mass_storage". +The MASS STORAGE function provides these attributes in its directory: +files: + + =============== ============================================== + stall Set to permit function to halt bulk endpoints. + Disabled on some USB devices known not to work + correctly. You should set it to true. + num_buffers Number of pipeline buffers. Valid numbers + are 2..4. Available only if + CONFIG_USB_GADGET_DEBUG_FILES is set. + =============== ============================================== + +and a default lun.0 directory corresponding to SCSI LUN #0. + +A new lun can be added with mkdir:: + + $ mkdir functions/mass_storage.0/partition.5 + +Lun numbering does not have to be continuous, except for lun #0 which is +created by default. A maximum of 8 luns can be specified and they all must be +named following the . scheme. The numbers can be 0..8. +Probably a good convention is to name the luns "lun.", +although it is not mandatory. + +In each lun directory there are the following attribute files: + + =============== ============================================== + file The path to the backing file for the LUN. + Required if LUN is not marked as removable. + ro Flag specifying access to the LUN shall be + read-only. This is implied if CD-ROM emulation + is enabled as well as when it was impossible + to open "filename" in R/W mode. + removable Flag specifying that LUN shall be indicated as + being removable. + cdrom Flag specifying that LUN shall be reported as + being a CD-ROM. + nofua Flag specifying that FUA flag + in SCSI WRITE(10,12) + =============== ============================================== + +Testing the MASS STORAGE function +--------------------------------- + +device: connect the gadget, enable it +host: dmesg, see the USB drives appear (if system configured to automatically +mount) + +9. MIDI function +================ + +The function is provided by usb_f_midi.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "midi". +The MIDI function provides these attributes in its function directory: + + =============== ==================================== + buflen MIDI buffer length + id ID string for the USB MIDI adapter + in_ports number of MIDI input ports + index index value for the USB MIDI adapter + out_ports number of MIDI output ports + qlen USB read request queue length + =============== ==================================== + +Testing the MIDI function +------------------------- + +There are two cases: playing a mid from the gadget to +the host and playing a mid from the host to the gadget. + +1) Playing a mid from the gadget to the host: + +host:: + + $ arecordmidi -l + Port Client name Port name + 14:0 Midi Through Midi Through Port-0 + 24:0 MIDI Gadget MIDI Gadget MIDI 1 + $ arecordmidi -p 24:0 from_gadget.mid + +gadget:: + + $ aplaymidi -l + Port Client name Port name + 20:0 f_midi f_midi + + $ aplaymidi -p 20:0 to_host.mid + +2) Playing a mid from the host to the gadget + +gadget:: + + $ arecordmidi -l + Port Client name Port name + 20:0 f_midi f_midi + + $ arecordmidi -p 20:0 from_host.mid + +host:: + + $ aplaymidi -l + Port Client name Port name + 14:0 Midi Through Midi Through Port-0 + 24:0 MIDI Gadget MIDI Gadget MIDI 1 + + $ aplaymidi -p24:0 to_gadget.mid + +The from_gadget.mid should sound identical to the to_host.mid. + +The from_host.id should sound identical to the to_gadget.mid. + +MIDI files can be played to speakers/headphones with e.g. timidity installed:: + + $ aplaymidi -l + Port Client name Port name + 14:0 Midi Through Midi Through Port-0 + 24:0 MIDI Gadget MIDI Gadget MIDI 1 + 128:0 TiMidity TiMidity port 0 + 128:1 TiMidity TiMidity port 1 + 128:2 TiMidity TiMidity port 2 + 128:3 TiMidity TiMidity port 3 + + $ aplaymidi -p 128:0 file.mid + +MIDI ports can be logically connected using the aconnect utility, e.g.:: + + $ aconnect 24:0 128:0 # try it on the host + +After the gadget's MIDI port is connected to timidity's MIDI port, +whatever is played at the gadget side with aplaymidi -l is audible +in host's speakers/headphones. + +10. NCM function +================ + +The function is provided by usb_f_ncm.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "ncm". +The NCM function provides these attributes in its function directory: + + =============== ================================================== + ifname network device interface name associated with this + function instance + qmult queue length multiplier for high and super speed + host_addr MAC address of host's end of this + Ethernet over USB link + dev_addr MAC address of device's end of this + Ethernet over USB link + =============== ================================================== + +and after creating the functions/ncm. they contain default +values: qmult is 5, dev_addr and host_addr are randomly selected. +Except for ifname they can be written to until the function is linked to a +configuration. The ifname is read-only and contains the name of the interface +which was assigned by the net core, e. g. usb0. + +Testing the NCM function +------------------------ + +Configure IP addresses of the device and the host. Then: + +On the device:: + + ping + +On the host:: + + ping + +11. OBEX function +================= + +The function is provided by usb_f_obex.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "obex". +The OBEX function provides just one attribute in its function directory: + + port_num + +The attribute is read-only. + +There can be at most 4 ACM/generic serial/OBEX ports in the system. + +Testing the OBEX function +------------------------- + +On device:: + + seriald -f /dev/ttyGS -s 1024 + +On host:: + + serialc -v -p -i -a1 -s1024 \ + -t -r + +where seriald and serialc are Felipe's utilities found here: + + https://github.com/felipebalbi/usb-tools.git master + +12. PHONET function +=================== + +The function is provided by usb_f_phonet.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "phonet". +The PHONET function provides just one attribute in its function directory: + + =============== ================================================== + ifname network device interface name associated with this + function instance + =============== ================================================== + +Testing the PHONET function +--------------------------- + +It is not possible to test the SOCK_STREAM protocol without a specific piece +of hardware, so only SOCK_DGRAM has been tested. For the latter to work, +in the past I had to apply the patch mentioned here: + +http://www.spinics.net/lists/linux-usb/msg85689.html + +These tools are required: + +git://git.gitorious.org/meego-cellular/phonet-utils.git + +On the host:: + + $ ./phonet -a 0x10 -i usbpn0 + $ ./pnroute add 0x6c usbpn0 + $./pnroute add 0x10 usbpn0 + $ ifconfig usbpn0 up + +On the device:: + + $ ./phonet -a 0x6c -i upnlink0 + $ ./pnroute add 0x10 upnlink0 + $ ifconfig upnlink0 up + +Then a test program can be used:: + + http://www.spinics.net/lists/linux-usb/msg85690.html + +On the device:: + + $ ./pnxmit -a 0x6c -r + +On the host:: + + $ ./pnxmit -a 0x10 -s 0x6c + +As a result some data should be sent from host to device. +Then the other way round: + +On the host:: + + $ ./pnxmit -a 0x10 -r + +On the device:: + + $ ./pnxmit -a 0x6c -s 0x10 + +13. RNDIS function +================== + +The function is provided by usb_f_rndis.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "rndis". +The RNDIS function provides these attributes in its function directory: + + =============== ================================================== + ifname network device interface name associated with this + function instance + qmult queue length multiplier for high and super speed + host_addr MAC address of host's end of this + Ethernet over USB link + dev_addr MAC address of device's end of this + Ethernet over USB link + =============== ================================================== + +and after creating the functions/rndis. they contain default +values: qmult is 5, dev_addr and host_addr are randomly selected. +Except for ifname they can be written to until the function is linked to a +configuration. The ifname is read-only and contains the name of the interface +which was assigned by the net core, e. g. usb0. + +Testing the RNDIS function +-------------------------- + +Configure IP addresses of the device and the host. Then: + +On the device:: + + ping + +On the host:: + + ping + +14. SERIAL function +=================== + +The function is provided by usb_f_gser.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "gser". +The SERIAL function provides just one attribute in its function directory: + + port_num + +The attribute is read-only. + +There can be at most 4 ACM/generic serial/OBEX ports in the system. + +Testing the SERIAL function +--------------------------- + +On host:: + + insmod usbserial + echo VID PID >/sys/bus/usb-serial/drivers/generic/new_id + +On host:: + + cat > /dev/ttyUSB + +On target:: + + cat /dev/ttyGS + +then the other way round + +On target:: + + cat > /dev/ttyGS + +On host:: + + cat /dev/ttyUSB + +15. SOURCESINK function +======================= + +The function is provided by usb_f_ss_lb.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "SourceSink". +The SOURCESINK function provides these attributes in its function directory: + + =============== ================================== + pattern 0 (all zeros), 1 (mod63), 2 (none) + isoc_interval 1..16 + isoc_maxpacket 0 - 1023 (fs), 0 - 1024 (hs/ss) + isoc_mult 0..2 (hs/ss only) + isoc_maxburst 0..15 (ss only) + bulk_buflen buffer length + bulk_qlen depth of queue for bulk + iso_qlen depth of queue for iso + =============== ================================== + +Testing the SOURCESINK function +------------------------------- + +device: run the gadget + +host: test-usb (tools/usb/testusb.c) + + +16. UAC1 function (legacy implementation) +========================================= + +The function is provided by usb_f_uac1_legacy.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory +is "uac1_legacy". +The uac1 function provides these attributes in its function directory: + + =============== ==================================== + audio_buf_size audio buffer size + fn_cap capture pcm device file name + fn_cntl control device file name + fn_play playback pcm device file name + req_buf_size ISO OUT endpoint request buffer size + req_count ISO OUT endpoint request count + =============== ==================================== + +The attributes have sane default values. + +Testing the UAC1 function +------------------------- + +device: run the gadget + +host:: + + aplay -l # should list our USB Audio Gadget + +17. UAC2 function +================= + +The function is provided by usb_f_uac2.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "uac2". +The uac2 function provides these attributes in its function directory: + + =============== ==================================================== + c_chmask capture channel mask + c_srate capture sampling rate + c_ssize capture sample size (bytes) + p_chmask playback channel mask + p_srate playback sampling rate + p_ssize playback sample size (bytes) + req_number the number of pre-allocated request for both capture + and playback + =============== ==================================================== + +The attributes have sane default values. + +Testing the UAC2 function +------------------------- + +device: run the gadget +host: aplay -l # should list our USB Audio Gadget + +This function does not require real hardware support, it just +sends a stream of audio data to/from the host. In order to +actually hear something at the device side, a command similar +to this must be used at the device side:: + + $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 & + +e.g.:: + + $ arecord -f dat -t wav -D hw:CARD=UAC2Gadget,DEV=0 | \ + aplay -D default:CARD=OdroidU3 + +18. UVC function +================ + +The function is provided by usb_f_uvc.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "uvc". +The uvc function provides these attributes in its function directory: + + =================== ================================================ + streaming_interval interval for polling endpoint for data transfers + streaming_maxburst bMaxBurst for super speed companion descriptor + streaming_maxpacket maximum packet size this endpoint is capable of + sending or receiving when this configuration is + selected + =================== ================================================ + +There are also "control" and "streaming" subdirectories, each of which contain +a number of their subdirectories. There are some sane defaults provided, but +the user must provide the following: + + ================== ==================================================== + control header create in control/header, link from control/class/fs + and/or control/class/ss + streaming header create in streaming/header, link from + streaming/class/fs and/or streaming/class/hs and/or + streaming/class/ss + format description create in streaming/mjpeg and/or + streaming/uncompressed + frame description create in streaming/mjpeg/ and/or in + streaming/uncompressed/ + ================== ==================================================== + +Each frame description contains frame interval specification, and each +such specification consists of a number of lines with an inverval value +in each line. The rules stated above are best illustrated with an example:: + + # mkdir functions/uvc.usb0/control/header/h + # cd functions/uvc.usb0/control/ + # ln -s header/h class/fs + # ln -s header/h class/ss + # mkdir -p functions/uvc.usb0/streaming/uncompressed/u/360p + # cat < functions/uvc.usb0/streaming/uncompressed/u/360p/dwFrameInterval + 666666 + 1000000 + 5000000 + EOF + # cd $GADGET_CONFIGFS_ROOT + # mkdir functions/uvc.usb0/streaming/header/h + # cd functions/uvc.usb0/streaming/header/h + # ln -s ../../uncompressed/u + # cd ../../class/fs + # ln -s ../../header/h + # cd ../../class/hs + # ln -s ../../header/h + # cd ../../class/ss + # ln -s ../../header/h + + +Testing the UVC function +------------------------ + +device: run the gadget, modprobe vivid:: + + # uvc-gadget -u /dev/video -v /dev/video + +where uvc-gadget is this program: + http://git.ideasonboard.org/uvc-gadget.git + +with these patches: + + http://www.spinics.net/lists/linux-usb/msg99220.html + +host:: + + luvcview -f yuv + +19. PRINTER function +==================== + +The function is provided by usb_f_printer.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "printer". +The printer function provides these attributes in its function directory: + + ========== =========================================== + pnp_string Data to be passed to the host in pnp string + q_len Number of requests per endpoint + ========== =========================================== + +Testing the PRINTER function +---------------------------- + +The most basic testing: + +device: run the gadget:: + + # ls -l /devices/virtual/usb_printer_gadget/ + +should show g_printer. + +If udev is active, then /dev/g_printer should appear automatically. + +host: + +If udev is active, then e.g. /dev/usb/lp0 should appear. + +host->device transmission: + +device:: + + # cat /dev/g_printer + +host:: + + # cat > /dev/usb/lp0 + +device->host transmission:: + + # cat > /dev/g_printer + +host:: + + # cat /dev/usb/lp0 + +More advanced testing can be done with the prn_example +described in Documentation/usb/gadget_printer.rst. + + +20. UAC1 function (virtual ALSA card, using u_audio API) +======================================================== + +The function is provided by usb_f_uac1.ko module. +It will create a virtual ALSA card and the audio streams are simply +sinked to and sourced from it. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "uac1". +The uac1 function provides these attributes in its function directory: + + ========== ==================================================== + c_chmask capture channel mask + c_srate capture sampling rate + c_ssize capture sample size (bytes) + p_chmask playback channel mask + p_srate playback sampling rate + p_ssize playback sample size (bytes) + req_number the number of pre-allocated request for both capture + and playback + ========== ==================================================== + +The attributes have sane default values. + +Testing the UAC1 function +------------------------- + +device: run the gadget +host: aplay -l # should list our USB Audio Gadget + +This function does not require real hardware support, it just +sends a stream of audio data to/from the host. In order to +actually hear something at the device side, a command similar +to this must be used at the device side:: + + $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 & + +e.g.:: + + $ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \ + aplay -D default:CARD=OdroidU3 diff --git a/Documentation/usb/gadget-testing.txt b/Documentation/usb/gadget-testing.txt deleted file mode 100644 index 7d7f2340af42..000000000000 --- a/Documentation/usb/gadget-testing.txt +++ /dev/null @@ -1,934 +0,0 @@ -============== -Gadget Testing -============== - -This file summarizes information on basic testing of USB functions -provided by gadgets. - -.. contents - - 1. ACM function - 2. ECM function - 3. ECM subset function - 4. EEM function - 5. FFS function - 6. HID function - 7. LOOPBACK function - 8. MASS STORAGE function - 9. MIDI function - 10. NCM function - 11. OBEX function - 12. PHONET function - 13. RNDIS function - 14. SERIAL function - 15. SOURCESINK function - 16. UAC1 function (legacy implementation) - 17. UAC2 function - 18. UVC function - 19. PRINTER function - 20. UAC1 function (new API) - - -1. ACM function -=============== - -The function is provided by usb_f_acm.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "acm". -The ACM function provides just one attribute in its function directory: - - port_num - -The attribute is read-only. - -There can be at most 4 ACM/generic serial/OBEX ports in the system. - - -Testing the ACM function ------------------------- - -On the host:: - - cat > /dev/ttyACM - -On the device:: - - cat /dev/ttyGS - -then the other way round - -On the device:: - - cat > /dev/ttyGS - -On the host:: - - cat /dev/ttyACM - -2. ECM function -=============== - -The function is provided by usb_f_ecm.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "ecm". -The ECM function provides these attributes in its function directory: - - =============== ================================================== - ifname network device interface name associated with this - function instance - qmult queue length multiplier for high and super speed - host_addr MAC address of host's end of this - Ethernet over USB link - dev_addr MAC address of device's end of this - Ethernet over USB link - =============== ================================================== - -and after creating the functions/ecm. they contain default -values: qmult is 5, dev_addr and host_addr are randomly selected. -Except for ifname they can be written to until the function is linked to a -configuration. The ifname is read-only and contains the name of the interface -which was assigned by the net core, e. g. usb0. - -Testing the ECM function ------------------------- - -Configure IP addresses of the device and the host. Then: - -On the device:: - - ping - -On the host:: - - ping - -3. ECM subset function -====================== - -The function is provided by usb_f_ecm_subset.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "geth". -The ECM subset function provides these attributes in its function directory: - - =============== ================================================== - ifname network device interface name associated with this - function instance - qmult queue length multiplier for high and super speed - host_addr MAC address of host's end of this - Ethernet over USB link - dev_addr MAC address of device's end of this - Ethernet over USB link - =============== ================================================== - -and after creating the functions/ecm. they contain default -values: qmult is 5, dev_addr and host_addr are randomly selected. -Except for ifname they can be written to until the function is linked to a -configuration. The ifname is read-only and contains the name of the interface -which was assigned by the net core, e. g. usb0. - -Testing the ECM subset function -------------------------------- - -Configure IP addresses of the device and the host. Then: - -On the device:: - - ping - -On the host:: - - ping - -4. EEM function -=============== - -The function is provided by usb_f_eem.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "eem". -The EEM function provides these attributes in its function directory: - - =============== ================================================== - ifname network device interface name associated with this - function instance - qmult queue length multiplier for high and super speed - host_addr MAC address of host's end of this - Ethernet over USB link - dev_addr MAC address of device's end of this - Ethernet over USB link - =============== ================================================== - -and after creating the functions/eem. they contain default -values: qmult is 5, dev_addr and host_addr are randomly selected. -Except for ifname they can be written to until the function is linked to a -configuration. The ifname is read-only and contains the name of the interface -which was assigned by the net core, e. g. usb0. - -Testing the EEM function ------------------------- - -Configure IP addresses of the device and the host. Then: - -On the device:: - - ping - -On the host:: - - ping - -5. FFS function -=============== - -The function is provided by usb_f_fs.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "ffs". -The function directory is intentionally empty and not modifiable. - -After creating the directory there is a new instance (a "device") of FunctionFS -available in the system. Once a "device" is available, the user should follow -the standard procedure for using FunctionFS (mount it, run the userspace -process which implements the function proper). The gadget should be enabled -by writing a suitable string to usb_gadget//UDC. - -Testing the FFS function ------------------------- - -On the device: start the function's userspace daemon, enable the gadget - -On the host: use the USB function provided by the device - -6. HID function -=============== - -The function is provided by usb_f_hid.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "hid". -The HID function provides these attributes in its function directory: - - =============== =========================================== - protocol HID protocol to use - report_desc data to be used in HID reports, except data - passed with /dev/hidg - report_length HID report length - subclass HID subclass to use - =============== =========================================== - -For a keyboard the protocol and the subclass are 1, the report_length is 8, -while the report_desc is:: - - $ hd my_report_desc - 00000000 05 01 09 06 a1 01 05 07 19 e0 29 e7 15 00 25 01 |..........)...%.| - 00000010 75 01 95 08 81 02 95 01 75 08 81 03 95 05 75 01 |u.......u.....u.| - 00000020 05 08 19 01 29 05 91 02 95 01 75 03 91 03 95 06 |....).....u.....| - 00000030 75 08 15 00 25 65 05 07 19 00 29 65 81 00 c0 |u...%e....)e...| - 0000003f - -Such a sequence of bytes can be stored to the attribute with echo:: - - $ echo -ne \\x05\\x01\\x09\\x06\\xa1..... - -Testing the HID function ------------------------- - -Device: - -- create the gadget -- connect the gadget to a host, preferably not the one used - to control the gadget -- run a program which writes to /dev/hidg, e.g. - a userspace program found in Documentation/usb/gadget_hid.txt:: - - $ ./hid_gadget_test /dev/hidg0 keyboard - -Host: - -- observe the keystrokes from the gadget - -7. LOOPBACK function -==================== - -The function is provided by usb_f_ss_lb.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "Loopback". -The LOOPBACK function provides these attributes in its function directory: - - =============== ======================= - qlen depth of loopback queue - bulk_buflen buffer length - =============== ======================= - -Testing the LOOPBACK function ------------------------------ - -device: run the gadget - -host: test-usb (tools/usb/testusb.c) - -8. MASS STORAGE function -======================== - -The function is provided by usb_f_mass_storage.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "mass_storage". -The MASS STORAGE function provides these attributes in its directory: -files: - - =============== ============================================== - stall Set to permit function to halt bulk endpoints. - Disabled on some USB devices known not to work - correctly. You should set it to true. - num_buffers Number of pipeline buffers. Valid numbers - are 2..4. Available only if - CONFIG_USB_GADGET_DEBUG_FILES is set. - =============== ============================================== - -and a default lun.0 directory corresponding to SCSI LUN #0. - -A new lun can be added with mkdir:: - - $ mkdir functions/mass_storage.0/partition.5 - -Lun numbering does not have to be continuous, except for lun #0 which is -created by default. A maximum of 8 luns can be specified and they all must be -named following the . scheme. The numbers can be 0..8. -Probably a good convention is to name the luns "lun.", -although it is not mandatory. - -In each lun directory there are the following attribute files: - - =============== ============================================== - file The path to the backing file for the LUN. - Required if LUN is not marked as removable. - ro Flag specifying access to the LUN shall be - read-only. This is implied if CD-ROM emulation - is enabled as well as when it was impossible - to open "filename" in R/W mode. - removable Flag specifying that LUN shall be indicated as - being removable. - cdrom Flag specifying that LUN shall be reported as - being a CD-ROM. - nofua Flag specifying that FUA flag - in SCSI WRITE(10,12) - =============== ============================================== - -Testing the MASS STORAGE function ---------------------------------- - -device: connect the gadget, enable it -host: dmesg, see the USB drives appear (if system configured to automatically -mount) - -9. MIDI function -================ - -The function is provided by usb_f_midi.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "midi". -The MIDI function provides these attributes in its function directory: - - =============== ==================================== - buflen MIDI buffer length - id ID string for the USB MIDI adapter - in_ports number of MIDI input ports - index index value for the USB MIDI adapter - out_ports number of MIDI output ports - qlen USB read request queue length - =============== ==================================== - -Testing the MIDI function -------------------------- - -There are two cases: playing a mid from the gadget to -the host and playing a mid from the host to the gadget. - -1) Playing a mid from the gadget to the host: - -host:: - - $ arecordmidi -l - Port Client name Port name - 14:0 Midi Through Midi Through Port-0 - 24:0 MIDI Gadget MIDI Gadget MIDI 1 - $ arecordmidi -p 24:0 from_gadget.mid - -gadget:: - - $ aplaymidi -l - Port Client name Port name - 20:0 f_midi f_midi - - $ aplaymidi -p 20:0 to_host.mid - -2) Playing a mid from the host to the gadget - -gadget:: - - $ arecordmidi -l - Port Client name Port name - 20:0 f_midi f_midi - - $ arecordmidi -p 20:0 from_host.mid - -host:: - - $ aplaymidi -l - Port Client name Port name - 14:0 Midi Through Midi Through Port-0 - 24:0 MIDI Gadget MIDI Gadget MIDI 1 - - $ aplaymidi -p24:0 to_gadget.mid - -The from_gadget.mid should sound identical to the to_host.mid. - -The from_host.id should sound identical to the to_gadget.mid. - -MIDI files can be played to speakers/headphones with e.g. timidity installed:: - - $ aplaymidi -l - Port Client name Port name - 14:0 Midi Through Midi Through Port-0 - 24:0 MIDI Gadget MIDI Gadget MIDI 1 - 128:0 TiMidity TiMidity port 0 - 128:1 TiMidity TiMidity port 1 - 128:2 TiMidity TiMidity port 2 - 128:3 TiMidity TiMidity port 3 - - $ aplaymidi -p 128:0 file.mid - -MIDI ports can be logically connected using the aconnect utility, e.g.:: - - $ aconnect 24:0 128:0 # try it on the host - -After the gadget's MIDI port is connected to timidity's MIDI port, -whatever is played at the gadget side with aplaymidi -l is audible -in host's speakers/headphones. - -10. NCM function -================ - -The function is provided by usb_f_ncm.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "ncm". -The NCM function provides these attributes in its function directory: - - =============== ================================================== - ifname network device interface name associated with this - function instance - qmult queue length multiplier for high and super speed - host_addr MAC address of host's end of this - Ethernet over USB link - dev_addr MAC address of device's end of this - Ethernet over USB link - =============== ================================================== - -and after creating the functions/ncm. they contain default -values: qmult is 5, dev_addr and host_addr are randomly selected. -Except for ifname they can be written to until the function is linked to a -configuration. The ifname is read-only and contains the name of the interface -which was assigned by the net core, e. g. usb0. - -Testing the NCM function ------------------------- - -Configure IP addresses of the device and the host. Then: - -On the device:: - - ping - -On the host:: - - ping - -11. OBEX function -================= - -The function is provided by usb_f_obex.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "obex". -The OBEX function provides just one attribute in its function directory: - - port_num - -The attribute is read-only. - -There can be at most 4 ACM/generic serial/OBEX ports in the system. - -Testing the OBEX function -------------------------- - -On device:: - - seriald -f /dev/ttyGS -s 1024 - -On host:: - - serialc -v -p -i -a1 -s1024 \ - -t -r - -where seriald and serialc are Felipe's utilities found here: - - https://github.com/felipebalbi/usb-tools.git master - -12. PHONET function -=================== - -The function is provided by usb_f_phonet.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "phonet". -The PHONET function provides just one attribute in its function directory: - - =============== ================================================== - ifname network device interface name associated with this - function instance - =============== ================================================== - -Testing the PHONET function ---------------------------- - -It is not possible to test the SOCK_STREAM protocol without a specific piece -of hardware, so only SOCK_DGRAM has been tested. For the latter to work, -in the past I had to apply the patch mentioned here: - -http://www.spinics.net/lists/linux-usb/msg85689.html - -These tools are required: - -git://git.gitorious.org/meego-cellular/phonet-utils.git - -On the host:: - - $ ./phonet -a 0x10 -i usbpn0 - $ ./pnroute add 0x6c usbpn0 - $./pnroute add 0x10 usbpn0 - $ ifconfig usbpn0 up - -On the device:: - - $ ./phonet -a 0x6c -i upnlink0 - $ ./pnroute add 0x10 upnlink0 - $ ifconfig upnlink0 up - -Then a test program can be used:: - - http://www.spinics.net/lists/linux-usb/msg85690.html - -On the device:: - - $ ./pnxmit -a 0x6c -r - -On the host:: - - $ ./pnxmit -a 0x10 -s 0x6c - -As a result some data should be sent from host to device. -Then the other way round: - -On the host:: - - $ ./pnxmit -a 0x10 -r - -On the device:: - - $ ./pnxmit -a 0x6c -s 0x10 - -13. RNDIS function -================== - -The function is provided by usb_f_rndis.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "rndis". -The RNDIS function provides these attributes in its function directory: - - =============== ================================================== - ifname network device interface name associated with this - function instance - qmult queue length multiplier for high and super speed - host_addr MAC address of host's end of this - Ethernet over USB link - dev_addr MAC address of device's end of this - Ethernet over USB link - =============== ================================================== - -and after creating the functions/rndis. they contain default -values: qmult is 5, dev_addr and host_addr are randomly selected. -Except for ifname they can be written to until the function is linked to a -configuration. The ifname is read-only and contains the name of the interface -which was assigned by the net core, e. g. usb0. - -Testing the RNDIS function --------------------------- - -Configure IP addresses of the device and the host. Then: - -On the device:: - - ping - -On the host:: - - ping - -14. SERIAL function -=================== - -The function is provided by usb_f_gser.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "gser". -The SERIAL function provides just one attribute in its function directory: - - port_num - -The attribute is read-only. - -There can be at most 4 ACM/generic serial/OBEX ports in the system. - -Testing the SERIAL function ---------------------------- - -On host:: - - insmod usbserial - echo VID PID >/sys/bus/usb-serial/drivers/generic/new_id - -On host:: - - cat > /dev/ttyUSB - -On target:: - - cat /dev/ttyGS - -then the other way round - -On target:: - - cat > /dev/ttyGS - -On host:: - - cat /dev/ttyUSB - -15. SOURCESINK function -======================= - -The function is provided by usb_f_ss_lb.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "SourceSink". -The SOURCESINK function provides these attributes in its function directory: - - =============== ================================== - pattern 0 (all zeros), 1 (mod63), 2 (none) - isoc_interval 1..16 - isoc_maxpacket 0 - 1023 (fs), 0 - 1024 (hs/ss) - isoc_mult 0..2 (hs/ss only) - isoc_maxburst 0..15 (ss only) - bulk_buflen buffer length - bulk_qlen depth of queue for bulk - iso_qlen depth of queue for iso - =============== ================================== - -Testing the SOURCESINK function -------------------------------- - -device: run the gadget - -host: test-usb (tools/usb/testusb.c) - - -16. UAC1 function (legacy implementation) -========================================= - -The function is provided by usb_f_uac1_legacy.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory -is "uac1_legacy". -The uac1 function provides these attributes in its function directory: - - =============== ==================================== - audio_buf_size audio buffer size - fn_cap capture pcm device file name - fn_cntl control device file name - fn_play playback pcm device file name - req_buf_size ISO OUT endpoint request buffer size - req_count ISO OUT endpoint request count - =============== ==================================== - -The attributes have sane default values. - -Testing the UAC1 function -------------------------- - -device: run the gadget - -host:: - - aplay -l # should list our USB Audio Gadget - -17. UAC2 function -================= - -The function is provided by usb_f_uac2.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "uac2". -The uac2 function provides these attributes in its function directory: - - =============== ==================================================== - c_chmask capture channel mask - c_srate capture sampling rate - c_ssize capture sample size (bytes) - p_chmask playback channel mask - p_srate playback sampling rate - p_ssize playback sample size (bytes) - req_number the number of pre-allocated request for both capture - and playback - =============== ==================================================== - -The attributes have sane default values. - -Testing the UAC2 function -------------------------- - -device: run the gadget -host: aplay -l # should list our USB Audio Gadget - -This function does not require real hardware support, it just -sends a stream of audio data to/from the host. In order to -actually hear something at the device side, a command similar -to this must be used at the device side:: - - $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 & - -e.g.:: - - $ arecord -f dat -t wav -D hw:CARD=UAC2Gadget,DEV=0 | \ - aplay -D default:CARD=OdroidU3 - -18. UVC function -================ - -The function is provided by usb_f_uvc.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "uvc". -The uvc function provides these attributes in its function directory: - - =================== ================================================ - streaming_interval interval for polling endpoint for data transfers - streaming_maxburst bMaxBurst for super speed companion descriptor - streaming_maxpacket maximum packet size this endpoint is capable of - sending or receiving when this configuration is - selected - =================== ================================================ - -There are also "control" and "streaming" subdirectories, each of which contain -a number of their subdirectories. There are some sane defaults provided, but -the user must provide the following: - - ================== ==================================================== - control header create in control/header, link from control/class/fs - and/or control/class/ss - streaming header create in streaming/header, link from - streaming/class/fs and/or streaming/class/hs and/or - streaming/class/ss - format description create in streaming/mjpeg and/or - streaming/uncompressed - frame description create in streaming/mjpeg/ and/or in - streaming/uncompressed/ - ================== ==================================================== - -Each frame description contains frame interval specification, and each -such specification consists of a number of lines with an inverval value -in each line. The rules stated above are best illustrated with an example:: - - # mkdir functions/uvc.usb0/control/header/h - # cd functions/uvc.usb0/control/ - # ln -s header/h class/fs - # ln -s header/h class/ss - # mkdir -p functions/uvc.usb0/streaming/uncompressed/u/360p - # cat < functions/uvc.usb0/streaming/uncompressed/u/360p/dwFrameInterval - 666666 - 1000000 - 5000000 - EOF - # cd $GADGET_CONFIGFS_ROOT - # mkdir functions/uvc.usb0/streaming/header/h - # cd functions/uvc.usb0/streaming/header/h - # ln -s ../../uncompressed/u - # cd ../../class/fs - # ln -s ../../header/h - # cd ../../class/hs - # ln -s ../../header/h - # cd ../../class/ss - # ln -s ../../header/h - - -Testing the UVC function ------------------------- - -device: run the gadget, modprobe vivid:: - - # uvc-gadget -u /dev/video -v /dev/video - -where uvc-gadget is this program: - http://git.ideasonboard.org/uvc-gadget.git - -with these patches: - - http://www.spinics.net/lists/linux-usb/msg99220.html - -host:: - - luvcview -f yuv - -19. PRINTER function -==================== - -The function is provided by usb_f_printer.ko module. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "printer". -The printer function provides these attributes in its function directory: - - ========== =========================================== - pnp_string Data to be passed to the host in pnp string - q_len Number of requests per endpoint - ========== =========================================== - -Testing the PRINTER function ----------------------------- - -The most basic testing: - -device: run the gadget:: - - # ls -l /devices/virtual/usb_printer_gadget/ - -should show g_printer. - -If udev is active, then /dev/g_printer should appear automatically. - -host: - -If udev is active, then e.g. /dev/usb/lp0 should appear. - -host->device transmission: - -device:: - - # cat /dev/g_printer - -host:: - - # cat > /dev/usb/lp0 - -device->host transmission:: - - # cat > /dev/g_printer - -host:: - - # cat /dev/usb/lp0 - -More advanced testing can be done with the prn_example -described in Documentation/usb/gadget_printer.txt. - - -20. UAC1 function (virtual ALSA card, using u_audio API) -======================================================== - -The function is provided by usb_f_uac1.ko module. -It will create a virtual ALSA card and the audio streams are simply -sinked to and sourced from it. - -Function-specific configfs interface ------------------------------------- - -The function name to use when creating the function directory is "uac1". -The uac1 function provides these attributes in its function directory: - - ========== ==================================================== - c_chmask capture channel mask - c_srate capture sampling rate - c_ssize capture sample size (bytes) - p_chmask playback channel mask - p_srate playback sampling rate - p_ssize playback sample size (bytes) - req_number the number of pre-allocated request for both capture - and playback - ========== ==================================================== - -The attributes have sane default values. - -Testing the UAC1 function -------------------------- - -device: run the gadget -host: aplay -l # should list our USB Audio Gadget - -This function does not require real hardware support, it just -sends a stream of audio data to/from the host. In order to -actually hear something at the device side, a command similar -to this must be used at the device side:: - - $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 & - -e.g.:: - - $ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \ - aplay -D default:CARD=OdroidU3 diff --git a/Documentation/usb/gadget_configfs.rst b/Documentation/usb/gadget_configfs.rst new file mode 100644 index 000000000000..54fb08baae22 --- /dev/null +++ b/Documentation/usb/gadget_configfs.rst @@ -0,0 +1,390 @@ +============================================ +Linux USB gadget configured through configfs +============================================ + + +25th April 2013 + + + + +Overview +======== + +A USB Linux Gadget is a device which has a UDC (USB Device Controller) and can +be connected to a USB Host to extend it with additional functions like a serial +port or a mass storage capability. + +A gadget is seen by its host as a set of configurations, each of which contains +a number of interfaces which, from the gadget's perspective, are known as +functions, each function representing e.g. a serial connection or a SCSI disk. + +Linux provides a number of functions for gadgets to use. + +Creating a gadget means deciding what configurations there will be +and which functions each configuration will provide. + +Configfs (please see `Documentation/filesystems/configfs/*`) lends itself nicely +for the purpose of telling the kernel about the above mentioned decision. +This document is about how to do it. + +It also describes how configfs integration into gadget is designed. + + + + +Requirements +============ + +In order for this to work configfs must be available, so CONFIGFS_FS must be +'y' or 'm' in .config. As of this writing USB_LIBCOMPOSITE selects CONFIGFS_FS. + + + + +Usage +===== + +(The original post describing the first function +made available through configfs can be seen here: +http://www.spinics.net/lists/linux-usb/msg76388.html) + +:: + + $ modprobe libcomposite + $ mount none $CONFIGFS_HOME -t configfs + +where CONFIGFS_HOME is the mount point for configfs + +1. Creating the gadgets +----------------------- + +For each gadget to be created its corresponding directory must be created:: + + $ mkdir $CONFIGFS_HOME/usb_gadget/ + +e.g.:: + + $ mkdir $CONFIGFS_HOME/usb_gadget/g1 + + ... + ... + ... + + $ cd $CONFIGFS_HOME/usb_gadget/g1 + +Each gadget needs to have its vendor id and product id specified:: + + $ echo > idVendor + $ echo > idProduct + +A gadget also needs its serial number, manufacturer and product strings. +In order to have a place to store them, a strings subdirectory must be created +for each language, e.g.:: + + $ mkdir strings/0x409 + +Then the strings can be specified:: + + $ echo > strings/0x409/serialnumber + $ echo > strings/0x409/manufacturer + $ echo > strings/0x409/product + +2. Creating the configurations +------------------------------ + +Each gadget will consist of a number of configurations, their corresponding +directories must be created: + +$ mkdir configs/. + +where can be any string which is legal in a filesystem and the + is the configuration's number, e.g.:: + + $ mkdir configs/c.1 + + ... + ... + ... + +Each configuration also needs its strings, so a subdirectory must be created +for each language, e.g.:: + + $ mkdir configs/c.1/strings/0x409 + +Then the configuration string can be specified:: + + $ echo > configs/c.1/strings/0x409/configuration + +Some attributes can also be set for a configuration, e.g.:: + + $ echo 120 > configs/c.1/MaxPower + +3. Creating the functions +------------------------- + +The gadget will provide some functions, for each function its corresponding +directory must be created:: + + $ mkdir functions/. + +where corresponds to one of allowed function names and instance name +is an arbitrary string allowed in a filesystem, e.g.:: + + $ mkdir functions/ncm.usb0 # usb_f_ncm.ko gets loaded with request_module() + + ... + ... + ... + +Each function provides its specific set of attributes, with either read-only +or read-write access. Where applicable they need to be written to as +appropriate. +Please refer to Documentation/ABI/*/configfs-usb-gadget* for more information. + +4. Associating the functions with their configurations +------------------------------------------------------ + +At this moment a number of gadgets is created, each of which has a number of +configurations specified and a number of functions available. What remains +is specifying which function is available in which configuration (the same +function can be used in multiple configurations). This is achieved with +creating symbolic links:: + + $ ln -s functions/. configs/. + +e.g.:: + + $ ln -s functions/ncm.usb0 configs/c.1 + + ... + ... + ... + +5. Enabling the gadget +---------------------- + +All the above steps serve the purpose of composing the gadget of +configurations and functions. + +An example directory structure might look like this:: + + . + ./strings + ./strings/0x409 + ./strings/0x409/serialnumber + ./strings/0x409/product + ./strings/0x409/manufacturer + ./configs + ./configs/c.1 + ./configs/c.1/ncm.usb0 -> ../../../../usb_gadget/g1/functions/ncm.usb0 + ./configs/c.1/strings + ./configs/c.1/strings/0x409 + ./configs/c.1/strings/0x409/configuration + ./configs/c.1/bmAttributes + ./configs/c.1/MaxPower + ./functions + ./functions/ncm.usb0 + ./functions/ncm.usb0/ifname + ./functions/ncm.usb0/qmult + ./functions/ncm.usb0/host_addr + ./functions/ncm.usb0/dev_addr + ./UDC + ./bcdUSB + ./bcdDevice + ./idProduct + ./idVendor + ./bMaxPacketSize0 + ./bDeviceProtocol + ./bDeviceSubClass + ./bDeviceClass + + +Such a gadget must be finally enabled so that the USB host can enumerate it. + +In order to enable the gadget it must be bound to a UDC (USB Device +Controller):: + + $ echo > UDC + +where is one of those found in /sys/class/udc/* +e.g.:: + + $ echo s3c-hsotg > UDC + + +6. Disabling the gadget +----------------------- + +:: + + $ echo "" > UDC + +7. Cleaning up +-------------- + +Remove functions from configurations:: + + $ rm configs/./ + +where . specify the configuration and is +a symlink to a function being removed from the configuration, e.g.:: + + $ rm configs/c.1/ncm.usb0 + + ... + ... + ... + +Remove strings directories in configurations: + + $ rmdir configs/./strings/ + +e.g.:: + + $ rmdir configs/c.1/strings/0x409 + + ... + ... + ... + +and remove the configurations:: + + $ rmdir configs/. + +e.g.:: + + rmdir configs/c.1 + + ... + ... + ... + +Remove functions (function modules are not unloaded, though): + + $ rmdir functions/. + +e.g.:: + + $ rmdir functions/ncm.usb0 + + ... + ... + ... + +Remove strings directories in the gadget:: + + $ rmdir strings/ + +e.g.:: + + $ rmdir strings/0x409 + +and finally remove the gadget:: + + $ cd .. + $ rmdir + +e.g.:: + + $ rmdir g1 + + + + +Implementation design +===================== + +Below the idea of how configfs works is presented. +In configfs there are items and groups, both represented as directories. +The difference between an item and a group is that a group can contain +other groups. In the picture below only an item is shown. +Both items and groups can have attributes, which are represented as files. +The user can create and remove directories, but cannot remove files, +which can be read-only or read-write, depending on what they represent. + +The filesystem part of configfs operates on config_items/groups and +configfs_attributes which are generic and of the same type for all +configured elements. However, they are embedded in usage-specific +larger structures. In the picture below there is a "cs" which contains +a config_item and an "sa" which contains a configfs_attribute. + +The filesystem view would be like this:: + + ./ + ./cs (directory) + | + +--sa (file) + | + . + . + . + +Whenever a user reads/writes the "sa" file, a function is called +which accepts a struct config_item and a struct configfs_attribute. +In the said function the "cs" and "sa" are retrieved using the well +known container_of technique and an appropriate sa's function (show or +store) is called and passed the "cs" and a character buffer. The "show" +is for displaying the file's contents (copy data from the cs to the +buffer), while the "store" is for modifying the file's contents (copy data +from the buffer to the cs), but it is up to the implementer of the +two functions to decide what they actually do. + +:: + + typedef struct configured_structure cs; + typedef struct specific_attribute sa; + + sa + +----------------------------------+ + cs | (*show)(cs *, buffer); | + +-----------------+ | (*store)(cs *, buffer, length); | + | | | | + | +-------------+ | | +------------------+ | + | | struct |-|----|------>|struct | | + | | config_item | | | |configfs_attribute| | + | +-------------+ | | +------------------+ | + | | +----------------------------------+ + | data to be set | . + | | . + +-----------------+ . + +The file names are decided by the config item/group designer, while +the directories in general can be named at will. A group can have +a number of its default sub-groups created automatically. + +For more information on configfs please see +`Documentation/filesystems/configfs/*`. + +The concepts described above translate to USB gadgets like this: + +1. A gadget has its config group, which has some attributes (idVendor, +idProduct etc) and default sub-groups (configs, functions, strings). +Writing to the attributes causes the information to be stored in +appropriate locations. In the configs, functions and strings sub-groups +a user can create their sub-groups to represent configurations, functions, +and groups of strings in a given language. + +2. The user creates configurations and functions, in the configurations +creates symbolic links to functions. This information is used when the +gadget's UDC attribute is written to, which means binding the gadget +to the UDC. The code in drivers/usb/gadget/configfs.c iterates over +all configurations, and in each configuration it iterates over all +functions and binds them. This way the whole gadget is bound. + +3. The file drivers/usb/gadget/configfs.c contains code for + + - gadget's config_group + - gadget's default groups (configs, functions, strings) + - associating functions with configurations (symlinks) + +4. Each USB function naturally has its own view of what it wants +configured, so config_groups for particular functions are defined +in the functions implementation files drivers/usb/gadget/f_*.c. + +5. Function's code is written in such a way that it uses + +usb_get_function_instance(), which, in turn, calls request_module. +So, provided that modprobe works, modules for particular functions +are loaded automatically. Please note that the converse is not true: +after a gadget is disabled and torn down, the modules remain loaded. diff --git a/Documentation/usb/gadget_configfs.txt b/Documentation/usb/gadget_configfs.txt deleted file mode 100644 index 54fb08baae22..000000000000 --- a/Documentation/usb/gadget_configfs.txt +++ /dev/null @@ -1,390 +0,0 @@ -============================================ -Linux USB gadget configured through configfs -============================================ - - -25th April 2013 - - - - -Overview -======== - -A USB Linux Gadget is a device which has a UDC (USB Device Controller) and can -be connected to a USB Host to extend it with additional functions like a serial -port or a mass storage capability. - -A gadget is seen by its host as a set of configurations, each of which contains -a number of interfaces which, from the gadget's perspective, are known as -functions, each function representing e.g. a serial connection or a SCSI disk. - -Linux provides a number of functions for gadgets to use. - -Creating a gadget means deciding what configurations there will be -and which functions each configuration will provide. - -Configfs (please see `Documentation/filesystems/configfs/*`) lends itself nicely -for the purpose of telling the kernel about the above mentioned decision. -This document is about how to do it. - -It also describes how configfs integration into gadget is designed. - - - - -Requirements -============ - -In order for this to work configfs must be available, so CONFIGFS_FS must be -'y' or 'm' in .config. As of this writing USB_LIBCOMPOSITE selects CONFIGFS_FS. - - - - -Usage -===== - -(The original post describing the first function -made available through configfs can be seen here: -http://www.spinics.net/lists/linux-usb/msg76388.html) - -:: - - $ modprobe libcomposite - $ mount none $CONFIGFS_HOME -t configfs - -where CONFIGFS_HOME is the mount point for configfs - -1. Creating the gadgets ------------------------ - -For each gadget to be created its corresponding directory must be created:: - - $ mkdir $CONFIGFS_HOME/usb_gadget/ - -e.g.:: - - $ mkdir $CONFIGFS_HOME/usb_gadget/g1 - - ... - ... - ... - - $ cd $CONFIGFS_HOME/usb_gadget/g1 - -Each gadget needs to have its vendor id and product id specified:: - - $ echo > idVendor - $ echo > idProduct - -A gadget also needs its serial number, manufacturer and product strings. -In order to have a place to store them, a strings subdirectory must be created -for each language, e.g.:: - - $ mkdir strings/0x409 - -Then the strings can be specified:: - - $ echo > strings/0x409/serialnumber - $ echo > strings/0x409/manufacturer - $ echo > strings/0x409/product - -2. Creating the configurations ------------------------------- - -Each gadget will consist of a number of configurations, their corresponding -directories must be created: - -$ mkdir configs/. - -where can be any string which is legal in a filesystem and the - is the configuration's number, e.g.:: - - $ mkdir configs/c.1 - - ... - ... - ... - -Each configuration also needs its strings, so a subdirectory must be created -for each language, e.g.:: - - $ mkdir configs/c.1/strings/0x409 - -Then the configuration string can be specified:: - - $ echo > configs/c.1/strings/0x409/configuration - -Some attributes can also be set for a configuration, e.g.:: - - $ echo 120 > configs/c.1/MaxPower - -3. Creating the functions -------------------------- - -The gadget will provide some functions, for each function its corresponding -directory must be created:: - - $ mkdir functions/. - -where corresponds to one of allowed function names and instance name -is an arbitrary string allowed in a filesystem, e.g.:: - - $ mkdir functions/ncm.usb0 # usb_f_ncm.ko gets loaded with request_module() - - ... - ... - ... - -Each function provides its specific set of attributes, with either read-only -or read-write access. Where applicable they need to be written to as -appropriate. -Please refer to Documentation/ABI/*/configfs-usb-gadget* for more information. - -4. Associating the functions with their configurations ------------------------------------------------------- - -At this moment a number of gadgets is created, each of which has a number of -configurations specified and a number of functions available. What remains -is specifying which function is available in which configuration (the same -function can be used in multiple configurations). This is achieved with -creating symbolic links:: - - $ ln -s functions/. configs/. - -e.g.:: - - $ ln -s functions/ncm.usb0 configs/c.1 - - ... - ... - ... - -5. Enabling the gadget ----------------------- - -All the above steps serve the purpose of composing the gadget of -configurations and functions. - -An example directory structure might look like this:: - - . - ./strings - ./strings/0x409 - ./strings/0x409/serialnumber - ./strings/0x409/product - ./strings/0x409/manufacturer - ./configs - ./configs/c.1 - ./configs/c.1/ncm.usb0 -> ../../../../usb_gadget/g1/functions/ncm.usb0 - ./configs/c.1/strings - ./configs/c.1/strings/0x409 - ./configs/c.1/strings/0x409/configuration - ./configs/c.1/bmAttributes - ./configs/c.1/MaxPower - ./functions - ./functions/ncm.usb0 - ./functions/ncm.usb0/ifname - ./functions/ncm.usb0/qmult - ./functions/ncm.usb0/host_addr - ./functions/ncm.usb0/dev_addr - ./UDC - ./bcdUSB - ./bcdDevice - ./idProduct - ./idVendor - ./bMaxPacketSize0 - ./bDeviceProtocol - ./bDeviceSubClass - ./bDeviceClass - - -Such a gadget must be finally enabled so that the USB host can enumerate it. - -In order to enable the gadget it must be bound to a UDC (USB Device -Controller):: - - $ echo > UDC - -where is one of those found in /sys/class/udc/* -e.g.:: - - $ echo s3c-hsotg > UDC - - -6. Disabling the gadget ------------------------ - -:: - - $ echo "" > UDC - -7. Cleaning up --------------- - -Remove functions from configurations:: - - $ rm configs/./ - -where . specify the configuration and is -a symlink to a function being removed from the configuration, e.g.:: - - $ rm configs/c.1/ncm.usb0 - - ... - ... - ... - -Remove strings directories in configurations: - - $ rmdir configs/./strings/ - -e.g.:: - - $ rmdir configs/c.1/strings/0x409 - - ... - ... - ... - -and remove the configurations:: - - $ rmdir configs/. - -e.g.:: - - rmdir configs/c.1 - - ... - ... - ... - -Remove functions (function modules are not unloaded, though): - - $ rmdir functions/. - -e.g.:: - - $ rmdir functions/ncm.usb0 - - ... - ... - ... - -Remove strings directories in the gadget:: - - $ rmdir strings/ - -e.g.:: - - $ rmdir strings/0x409 - -and finally remove the gadget:: - - $ cd .. - $ rmdir - -e.g.:: - - $ rmdir g1 - - - - -Implementation design -===================== - -Below the idea of how configfs works is presented. -In configfs there are items and groups, both represented as directories. -The difference between an item and a group is that a group can contain -other groups. In the picture below only an item is shown. -Both items and groups can have attributes, which are represented as files. -The user can create and remove directories, but cannot remove files, -which can be read-only or read-write, depending on what they represent. - -The filesystem part of configfs operates on config_items/groups and -configfs_attributes which are generic and of the same type for all -configured elements. However, they are embedded in usage-specific -larger structures. In the picture below there is a "cs" which contains -a config_item and an "sa" which contains a configfs_attribute. - -The filesystem view would be like this:: - - ./ - ./cs (directory) - | - +--sa (file) - | - . - . - . - -Whenever a user reads/writes the "sa" file, a function is called -which accepts a struct config_item and a struct configfs_attribute. -In the said function the "cs" and "sa" are retrieved using the well -known container_of technique and an appropriate sa's function (show or -store) is called and passed the "cs" and a character buffer. The "show" -is for displaying the file's contents (copy data from the cs to the -buffer), while the "store" is for modifying the file's contents (copy data -from the buffer to the cs), but it is up to the implementer of the -two functions to decide what they actually do. - -:: - - typedef struct configured_structure cs; - typedef struct specific_attribute sa; - - sa - +----------------------------------+ - cs | (*show)(cs *, buffer); | - +-----------------+ | (*store)(cs *, buffer, length); | - | | | | - | +-------------+ | | +------------------+ | - | | struct |-|----|------>|struct | | - | | config_item | | | |configfs_attribute| | - | +-------------+ | | +------------------+ | - | | +----------------------------------+ - | data to be set | . - | | . - +-----------------+ . - -The file names are decided by the config item/group designer, while -the directories in general can be named at will. A group can have -a number of its default sub-groups created automatically. - -For more information on configfs please see -`Documentation/filesystems/configfs/*`. - -The concepts described above translate to USB gadgets like this: - -1. A gadget has its config group, which has some attributes (idVendor, -idProduct etc) and default sub-groups (configs, functions, strings). -Writing to the attributes causes the information to be stored in -appropriate locations. In the configs, functions and strings sub-groups -a user can create their sub-groups to represent configurations, functions, -and groups of strings in a given language. - -2. The user creates configurations and functions, in the configurations -creates symbolic links to functions. This information is used when the -gadget's UDC attribute is written to, which means binding the gadget -to the UDC. The code in drivers/usb/gadget/configfs.c iterates over -all configurations, and in each configuration it iterates over all -functions and binds them. This way the whole gadget is bound. - -3. The file drivers/usb/gadget/configfs.c contains code for - - - gadget's config_group - - gadget's default groups (configs, functions, strings) - - associating functions with configurations (symlinks) - -4. Each USB function naturally has its own view of what it wants -configured, so config_groups for particular functions are defined -in the functions implementation files drivers/usb/gadget/f_*.c. - -5. Function's code is written in such a way that it uses - -usb_get_function_instance(), which, in turn, calls request_module. -So, provided that modprobe works, modules for particular functions -are loaded automatically. Please note that the converse is not true: -after a gadget is disabled and torn down, the modules remain loaded. diff --git a/Documentation/usb/gadget_hid.rst b/Documentation/usb/gadget_hid.rst new file mode 100644 index 000000000000..098d563040cc --- /dev/null +++ b/Documentation/usb/gadget_hid.rst @@ -0,0 +1,457 @@ +=========================== +Linux USB HID gadget driver +=========================== + +Introduction +============ + +The HID Gadget driver provides emulation of USB Human Interface +Devices (HID). The basic HID handling is done in the kernel, +and HID reports can be sent/received through I/O on the +/dev/hidgX character devices. + +For more details about HID, see the developer page on +http://www.usb.org/developers/hidpage/ + +Configuration +============= + +g_hid is a platform driver, so to use it you need to add +struct platform_device(s) to your platform code defining the +HID function descriptors you want to use - E.G. something +like:: + + #include + #include + + /* hid descriptor for a keyboard */ + static struct hidg_func_descriptor my_hid_data = { + .subclass = 0, /* No subclass */ + .protocol = 1, /* Keyboard */ + .report_length = 8, + .report_desc_length = 63, + .report_desc = { + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ + 0x09, 0x06, /* USAGE (Keyboard) */ + 0xa1, 0x01, /* COLLECTION (Application) */ + 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ + 0x19, 0xe0, /* USAGE_MINIMUM (Keyboard LeftControl) */ + 0x29, 0xe7, /* USAGE_MAXIMUM (Keyboard Right GUI) */ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ + 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ + 0x75, 0x01, /* REPORT_SIZE (1) */ + 0x95, 0x08, /* REPORT_COUNT (8) */ + 0x81, 0x02, /* INPUT (Data,Var,Abs) */ + 0x95, 0x01, /* REPORT_COUNT (1) */ + 0x75, 0x08, /* REPORT_SIZE (8) */ + 0x81, 0x03, /* INPUT (Cnst,Var,Abs) */ + 0x95, 0x05, /* REPORT_COUNT (5) */ + 0x75, 0x01, /* REPORT_SIZE (1) */ + 0x05, 0x08, /* USAGE_PAGE (LEDs) */ + 0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */ + 0x29, 0x05, /* USAGE_MAXIMUM (Kana) */ + 0x91, 0x02, /* OUTPUT (Data,Var,Abs) */ + 0x95, 0x01, /* REPORT_COUNT (1) */ + 0x75, 0x03, /* REPORT_SIZE (3) */ + 0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */ + 0x95, 0x06, /* REPORT_COUNT (6) */ + 0x75, 0x08, /* REPORT_SIZE (8) */ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ + 0x25, 0x65, /* LOGICAL_MAXIMUM (101) */ + 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ + 0x19, 0x00, /* USAGE_MINIMUM (Reserved) */ + 0x29, 0x65, /* USAGE_MAXIMUM (Keyboard Application) */ + 0x81, 0x00, /* INPUT (Data,Ary,Abs) */ + 0xc0 /* END_COLLECTION */ + } + }; + + static struct platform_device my_hid = { + .name = "hidg", + .id = 0, + .num_resources = 0, + .resource = 0, + .dev.platform_data = &my_hid_data, + }; + +You can add as many HID functions as you want, only limited by +the amount of interrupt endpoints your gadget driver supports. + +Configuration with configfs +=========================== + +Instead of adding fake platform devices and drivers in order to pass +some data to the kernel, if HID is a part of a gadget composed with +configfs the hidg_func_descriptor.report_desc is passed to the kernel +by writing the appropriate stream of bytes to a configfs attribute. + +Send and receive HID reports +============================ + +HID reports can be sent/received using read/write on the +/dev/hidgX character devices. See below for an example program +to do this. + +hid_gadget_test is a small interactive program to test the HID +gadget driver. To use, point it at a hidg device and set the +device type (keyboard / mouse / joystick) - E.G.:: + + # hid_gadget_test /dev/hidg0 keyboard + +You are now in the prompt of hid_gadget_test. You can type any +combination of options and values. Available options and +values are listed at program start. In keyboard mode you can +send up to six values. + +For example type: g i s t r --left-shift + +Hit return and the corresponding report will be sent by the +HID gadget. + +Another interesting example is the caps lock test. Type +--caps-lock and hit return. A report is then sent by the +gadget and you should receive the host answer, corresponding +to the caps lock LED status:: + + --caps-lock + recv report:2 + +With this command:: + + # hid_gadget_test /dev/hidg1 mouse + +You can test the mouse emulation. Values are two signed numbers. + + +Sample code:: + + /* hid_gadget_test */ + + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #define BUF_LEN 512 + + struct options { + const char *opt; + unsigned char val; + }; + + static struct options kmod[] = { + {.opt = "--left-ctrl", .val = 0x01}, + {.opt = "--right-ctrl", .val = 0x10}, + {.opt = "--left-shift", .val = 0x02}, + {.opt = "--right-shift", .val = 0x20}, + {.opt = "--left-alt", .val = 0x04}, + {.opt = "--right-alt", .val = 0x40}, + {.opt = "--left-meta", .val = 0x08}, + {.opt = "--right-meta", .val = 0x80}, + {.opt = NULL} + }; + + static struct options kval[] = { + {.opt = "--return", .val = 0x28}, + {.opt = "--esc", .val = 0x29}, + {.opt = "--bckspc", .val = 0x2a}, + {.opt = "--tab", .val = 0x2b}, + {.opt = "--spacebar", .val = 0x2c}, + {.opt = "--caps-lock", .val = 0x39}, + {.opt = "--f1", .val = 0x3a}, + {.opt = "--f2", .val = 0x3b}, + {.opt = "--f3", .val = 0x3c}, + {.opt = "--f4", .val = 0x3d}, + {.opt = "--f5", .val = 0x3e}, + {.opt = "--f6", .val = 0x3f}, + {.opt = "--f7", .val = 0x40}, + {.opt = "--f8", .val = 0x41}, + {.opt = "--f9", .val = 0x42}, + {.opt = "--f10", .val = 0x43}, + {.opt = "--f11", .val = 0x44}, + {.opt = "--f12", .val = 0x45}, + {.opt = "--insert", .val = 0x49}, + {.opt = "--home", .val = 0x4a}, + {.opt = "--pageup", .val = 0x4b}, + {.opt = "--del", .val = 0x4c}, + {.opt = "--end", .val = 0x4d}, + {.opt = "--pagedown", .val = 0x4e}, + {.opt = "--right", .val = 0x4f}, + {.opt = "--left", .val = 0x50}, + {.opt = "--down", .val = 0x51}, + {.opt = "--kp-enter", .val = 0x58}, + {.opt = "--up", .val = 0x52}, + {.opt = "--num-lock", .val = 0x53}, + {.opt = NULL} + }; + + int keyboard_fill_report(char report[8], char buf[BUF_LEN], int *hold) + { + char *tok = strtok(buf, " "); + int key = 0; + int i = 0; + + for (; tok != NULL; tok = strtok(NULL, " ")) { + + if (strcmp(tok, "--quit") == 0) + return -1; + + if (strcmp(tok, "--hold") == 0) { + *hold = 1; + continue; + } + + if (key < 6) { + for (i = 0; kval[i].opt != NULL; i++) + if (strcmp(tok, kval[i].opt) == 0) { + report[2 + key++] = kval[i].val; + break; + } + if (kval[i].opt != NULL) + continue; + } + + if (key < 6) + if (islower(tok[0])) { + report[2 + key++] = (tok[0] - ('a' - 0x04)); + continue; + } + + for (i = 0; kmod[i].opt != NULL; i++) + if (strcmp(tok, kmod[i].opt) == 0) { + report[0] = report[0] | kmod[i].val; + break; + } + if (kmod[i].opt != NULL) + continue; + + if (key < 6) + fprintf(stderr, "unknown option: %s\n", tok); + } + return 8; + } + + static struct options mmod[] = { + {.opt = "--b1", .val = 0x01}, + {.opt = "--b2", .val = 0x02}, + {.opt = "--b3", .val = 0x04}, + {.opt = NULL} + }; + + int mouse_fill_report(char report[8], char buf[BUF_LEN], int *hold) + { + char *tok = strtok(buf, " "); + int mvt = 0; + int i = 0; + for (; tok != NULL; tok = strtok(NULL, " ")) { + + if (strcmp(tok, "--quit") == 0) + return -1; + + if (strcmp(tok, "--hold") == 0) { + *hold = 1; + continue; + } + + for (i = 0; mmod[i].opt != NULL; i++) + if (strcmp(tok, mmod[i].opt) == 0) { + report[0] = report[0] | mmod[i].val; + break; + } + if (mmod[i].opt != NULL) + continue; + + if (!(tok[0] == '-' && tok[1] == '-') && mvt < 2) { + errno = 0; + report[1 + mvt++] = (char)strtol(tok, NULL, 0); + if (errno != 0) { + fprintf(stderr, "Bad value:'%s'\n", tok); + report[1 + mvt--] = 0; + } + continue; + } + + fprintf(stderr, "unknown option: %s\n", tok); + } + return 3; + } + + static struct options jmod[] = { + {.opt = "--b1", .val = 0x10}, + {.opt = "--b2", .val = 0x20}, + {.opt = "--b3", .val = 0x40}, + {.opt = "--b4", .val = 0x80}, + {.opt = "--hat1", .val = 0x00}, + {.opt = "--hat2", .val = 0x01}, + {.opt = "--hat3", .val = 0x02}, + {.opt = "--hat4", .val = 0x03}, + {.opt = "--hatneutral", .val = 0x04}, + {.opt = NULL} + }; + + int joystick_fill_report(char report[8], char buf[BUF_LEN], int *hold) + { + char *tok = strtok(buf, " "); + int mvt = 0; + int i = 0; + + *hold = 1; + + /* set default hat position: neutral */ + report[3] = 0x04; + + for (; tok != NULL; tok = strtok(NULL, " ")) { + + if (strcmp(tok, "--quit") == 0) + return -1; + + for (i = 0; jmod[i].opt != NULL; i++) + if (strcmp(tok, jmod[i].opt) == 0) { + report[3] = (report[3] & 0xF0) | jmod[i].val; + break; + } + if (jmod[i].opt != NULL) + continue; + + if (!(tok[0] == '-' && tok[1] == '-') && mvt < 3) { + errno = 0; + report[mvt++] = (char)strtol(tok, NULL, 0); + if (errno != 0) { + fprintf(stderr, "Bad value:'%s'\n", tok); + report[mvt--] = 0; + } + continue; + } + + fprintf(stderr, "unknown option: %s\n", tok); + } + return 4; + } + + void print_options(char c) + { + int i = 0; + + if (c == 'k') { + printf(" keyboard options:\n" + " --hold\n"); + for (i = 0; kmod[i].opt != NULL; i++) + printf("\t\t%s\n", kmod[i].opt); + printf("\n keyboard values:\n" + " [a-z] or\n"); + for (i = 0; kval[i].opt != NULL; i++) + printf("\t\t%-8s%s", kval[i].opt, i % 2 ? "\n" : ""); + printf("\n"); + } else if (c == 'm') { + printf(" mouse options:\n" + " --hold\n"); + for (i = 0; mmod[i].opt != NULL; i++) + printf("\t\t%s\n", mmod[i].opt); + printf("\n mouse values:\n" + " Two signed numbers\n" + "--quit to close\n"); + } else { + printf(" joystick options:\n"); + for (i = 0; jmod[i].opt != NULL; i++) + printf("\t\t%s\n", jmod[i].opt); + printf("\n joystick values:\n" + " three signed numbers\n" + "--quit to close\n"); + } + } + + int main(int argc, const char *argv[]) + { + const char *filename = NULL; + int fd = 0; + char buf[BUF_LEN]; + int cmd_len; + char report[8]; + int to_send = 8; + int hold = 0; + fd_set rfds; + int retval, i; + + if (argc < 3) { + fprintf(stderr, "Usage: %s devname mouse|keyboard|joystick\n", + argv[0]); + return 1; + } + + if (argv[2][0] != 'k' && argv[2][0] != 'm' && argv[2][0] != 'j') + return 2; + + filename = argv[1]; + + if ((fd = open(filename, O_RDWR, 0666)) == -1) { + perror(filename); + return 3; + } + + print_options(argv[2][0]); + + while (42) { + + FD_ZERO(&rfds); + FD_SET(STDIN_FILENO, &rfds); + FD_SET(fd, &rfds); + + retval = select(fd + 1, &rfds, NULL, NULL, NULL); + if (retval == -1 && errno == EINTR) + continue; + if (retval < 0) { + perror("select()"); + return 4; + } + + if (FD_ISSET(fd, &rfds)) { + cmd_len = read(fd, buf, BUF_LEN - 1); + printf("recv report:"); + for (i = 0; i < cmd_len; i++) + printf(" %02x", buf[i]); + printf("\n"); + } + + if (FD_ISSET(STDIN_FILENO, &rfds)) { + memset(report, 0x0, sizeof(report)); + cmd_len = read(STDIN_FILENO, buf, BUF_LEN - 1); + + if (cmd_len == 0) + break; + + buf[cmd_len - 1] = '\0'; + hold = 0; + + memset(report, 0x0, sizeof(report)); + if (argv[2][0] == 'k') + to_send = keyboard_fill_report(report, buf, &hold); + else if (argv[2][0] == 'm') + to_send = mouse_fill_report(report, buf, &hold); + else + to_send = joystick_fill_report(report, buf, &hold); + + if (to_send == -1) + break; + + if (write(fd, report, to_send) != to_send) { + perror(filename); + return 5; + } + if (!hold) { + memset(report, 0x0, sizeof(report)); + if (write(fd, report, to_send) != to_send) { + perror(filename); + return 6; + } + } + } + } + + close(fd); + return 0; + } diff --git a/Documentation/usb/gadget_hid.txt b/Documentation/usb/gadget_hid.txt deleted file mode 100644 index 098d563040cc..000000000000 --- a/Documentation/usb/gadget_hid.txt +++ /dev/null @@ -1,457 +0,0 @@ -=========================== -Linux USB HID gadget driver -=========================== - -Introduction -============ - -The HID Gadget driver provides emulation of USB Human Interface -Devices (HID). The basic HID handling is done in the kernel, -and HID reports can be sent/received through I/O on the -/dev/hidgX character devices. - -For more details about HID, see the developer page on -http://www.usb.org/developers/hidpage/ - -Configuration -============= - -g_hid is a platform driver, so to use it you need to add -struct platform_device(s) to your platform code defining the -HID function descriptors you want to use - E.G. something -like:: - - #include - #include - - /* hid descriptor for a keyboard */ - static struct hidg_func_descriptor my_hid_data = { - .subclass = 0, /* No subclass */ - .protocol = 1, /* Keyboard */ - .report_length = 8, - .report_desc_length = 63, - .report_desc = { - 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ - 0x09, 0x06, /* USAGE (Keyboard) */ - 0xa1, 0x01, /* COLLECTION (Application) */ - 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ - 0x19, 0xe0, /* USAGE_MINIMUM (Keyboard LeftControl) */ - 0x29, 0xe7, /* USAGE_MAXIMUM (Keyboard Right GUI) */ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ - 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ - 0x75, 0x01, /* REPORT_SIZE (1) */ - 0x95, 0x08, /* REPORT_COUNT (8) */ - 0x81, 0x02, /* INPUT (Data,Var,Abs) */ - 0x95, 0x01, /* REPORT_COUNT (1) */ - 0x75, 0x08, /* REPORT_SIZE (8) */ - 0x81, 0x03, /* INPUT (Cnst,Var,Abs) */ - 0x95, 0x05, /* REPORT_COUNT (5) */ - 0x75, 0x01, /* REPORT_SIZE (1) */ - 0x05, 0x08, /* USAGE_PAGE (LEDs) */ - 0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */ - 0x29, 0x05, /* USAGE_MAXIMUM (Kana) */ - 0x91, 0x02, /* OUTPUT (Data,Var,Abs) */ - 0x95, 0x01, /* REPORT_COUNT (1) */ - 0x75, 0x03, /* REPORT_SIZE (3) */ - 0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */ - 0x95, 0x06, /* REPORT_COUNT (6) */ - 0x75, 0x08, /* REPORT_SIZE (8) */ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ - 0x25, 0x65, /* LOGICAL_MAXIMUM (101) */ - 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ - 0x19, 0x00, /* USAGE_MINIMUM (Reserved) */ - 0x29, 0x65, /* USAGE_MAXIMUM (Keyboard Application) */ - 0x81, 0x00, /* INPUT (Data,Ary,Abs) */ - 0xc0 /* END_COLLECTION */ - } - }; - - static struct platform_device my_hid = { - .name = "hidg", - .id = 0, - .num_resources = 0, - .resource = 0, - .dev.platform_data = &my_hid_data, - }; - -You can add as many HID functions as you want, only limited by -the amount of interrupt endpoints your gadget driver supports. - -Configuration with configfs -=========================== - -Instead of adding fake platform devices and drivers in order to pass -some data to the kernel, if HID is a part of a gadget composed with -configfs the hidg_func_descriptor.report_desc is passed to the kernel -by writing the appropriate stream of bytes to a configfs attribute. - -Send and receive HID reports -============================ - -HID reports can be sent/received using read/write on the -/dev/hidgX character devices. See below for an example program -to do this. - -hid_gadget_test is a small interactive program to test the HID -gadget driver. To use, point it at a hidg device and set the -device type (keyboard / mouse / joystick) - E.G.:: - - # hid_gadget_test /dev/hidg0 keyboard - -You are now in the prompt of hid_gadget_test. You can type any -combination of options and values. Available options and -values are listed at program start. In keyboard mode you can -send up to six values. - -For example type: g i s t r --left-shift - -Hit return and the corresponding report will be sent by the -HID gadget. - -Another interesting example is the caps lock test. Type ---caps-lock and hit return. A report is then sent by the -gadget and you should receive the host answer, corresponding -to the caps lock LED status:: - - --caps-lock - recv report:2 - -With this command:: - - # hid_gadget_test /dev/hidg1 mouse - -You can test the mouse emulation. Values are two signed numbers. - - -Sample code:: - - /* hid_gadget_test */ - - #include - #include - #include - #include - #include - #include - #include - #include - #include - - #define BUF_LEN 512 - - struct options { - const char *opt; - unsigned char val; - }; - - static struct options kmod[] = { - {.opt = "--left-ctrl", .val = 0x01}, - {.opt = "--right-ctrl", .val = 0x10}, - {.opt = "--left-shift", .val = 0x02}, - {.opt = "--right-shift", .val = 0x20}, - {.opt = "--left-alt", .val = 0x04}, - {.opt = "--right-alt", .val = 0x40}, - {.opt = "--left-meta", .val = 0x08}, - {.opt = "--right-meta", .val = 0x80}, - {.opt = NULL} - }; - - static struct options kval[] = { - {.opt = "--return", .val = 0x28}, - {.opt = "--esc", .val = 0x29}, - {.opt = "--bckspc", .val = 0x2a}, - {.opt = "--tab", .val = 0x2b}, - {.opt = "--spacebar", .val = 0x2c}, - {.opt = "--caps-lock", .val = 0x39}, - {.opt = "--f1", .val = 0x3a}, - {.opt = "--f2", .val = 0x3b}, - {.opt = "--f3", .val = 0x3c}, - {.opt = "--f4", .val = 0x3d}, - {.opt = "--f5", .val = 0x3e}, - {.opt = "--f6", .val = 0x3f}, - {.opt = "--f7", .val = 0x40}, - {.opt = "--f8", .val = 0x41}, - {.opt = "--f9", .val = 0x42}, - {.opt = "--f10", .val = 0x43}, - {.opt = "--f11", .val = 0x44}, - {.opt = "--f12", .val = 0x45}, - {.opt = "--insert", .val = 0x49}, - {.opt = "--home", .val = 0x4a}, - {.opt = "--pageup", .val = 0x4b}, - {.opt = "--del", .val = 0x4c}, - {.opt = "--end", .val = 0x4d}, - {.opt = "--pagedown", .val = 0x4e}, - {.opt = "--right", .val = 0x4f}, - {.opt = "--left", .val = 0x50}, - {.opt = "--down", .val = 0x51}, - {.opt = "--kp-enter", .val = 0x58}, - {.opt = "--up", .val = 0x52}, - {.opt = "--num-lock", .val = 0x53}, - {.opt = NULL} - }; - - int keyboard_fill_report(char report[8], char buf[BUF_LEN], int *hold) - { - char *tok = strtok(buf, " "); - int key = 0; - int i = 0; - - for (; tok != NULL; tok = strtok(NULL, " ")) { - - if (strcmp(tok, "--quit") == 0) - return -1; - - if (strcmp(tok, "--hold") == 0) { - *hold = 1; - continue; - } - - if (key < 6) { - for (i = 0; kval[i].opt != NULL; i++) - if (strcmp(tok, kval[i].opt) == 0) { - report[2 + key++] = kval[i].val; - break; - } - if (kval[i].opt != NULL) - continue; - } - - if (key < 6) - if (islower(tok[0])) { - report[2 + key++] = (tok[0] - ('a' - 0x04)); - continue; - } - - for (i = 0; kmod[i].opt != NULL; i++) - if (strcmp(tok, kmod[i].opt) == 0) { - report[0] = report[0] | kmod[i].val; - break; - } - if (kmod[i].opt != NULL) - continue; - - if (key < 6) - fprintf(stderr, "unknown option: %s\n", tok); - } - return 8; - } - - static struct options mmod[] = { - {.opt = "--b1", .val = 0x01}, - {.opt = "--b2", .val = 0x02}, - {.opt = "--b3", .val = 0x04}, - {.opt = NULL} - }; - - int mouse_fill_report(char report[8], char buf[BUF_LEN], int *hold) - { - char *tok = strtok(buf, " "); - int mvt = 0; - int i = 0; - for (; tok != NULL; tok = strtok(NULL, " ")) { - - if (strcmp(tok, "--quit") == 0) - return -1; - - if (strcmp(tok, "--hold") == 0) { - *hold = 1; - continue; - } - - for (i = 0; mmod[i].opt != NULL; i++) - if (strcmp(tok, mmod[i].opt) == 0) { - report[0] = report[0] | mmod[i].val; - break; - } - if (mmod[i].opt != NULL) - continue; - - if (!(tok[0] == '-' && tok[1] == '-') && mvt < 2) { - errno = 0; - report[1 + mvt++] = (char)strtol(tok, NULL, 0); - if (errno != 0) { - fprintf(stderr, "Bad value:'%s'\n", tok); - report[1 + mvt--] = 0; - } - continue; - } - - fprintf(stderr, "unknown option: %s\n", tok); - } - return 3; - } - - static struct options jmod[] = { - {.opt = "--b1", .val = 0x10}, - {.opt = "--b2", .val = 0x20}, - {.opt = "--b3", .val = 0x40}, - {.opt = "--b4", .val = 0x80}, - {.opt = "--hat1", .val = 0x00}, - {.opt = "--hat2", .val = 0x01}, - {.opt = "--hat3", .val = 0x02}, - {.opt = "--hat4", .val = 0x03}, - {.opt = "--hatneutral", .val = 0x04}, - {.opt = NULL} - }; - - int joystick_fill_report(char report[8], char buf[BUF_LEN], int *hold) - { - char *tok = strtok(buf, " "); - int mvt = 0; - int i = 0; - - *hold = 1; - - /* set default hat position: neutral */ - report[3] = 0x04; - - for (; tok != NULL; tok = strtok(NULL, " ")) { - - if (strcmp(tok, "--quit") == 0) - return -1; - - for (i = 0; jmod[i].opt != NULL; i++) - if (strcmp(tok, jmod[i].opt) == 0) { - report[3] = (report[3] & 0xF0) | jmod[i].val; - break; - } - if (jmod[i].opt != NULL) - continue; - - if (!(tok[0] == '-' && tok[1] == '-') && mvt < 3) { - errno = 0; - report[mvt++] = (char)strtol(tok, NULL, 0); - if (errno != 0) { - fprintf(stderr, "Bad value:'%s'\n", tok); - report[mvt--] = 0; - } - continue; - } - - fprintf(stderr, "unknown option: %s\n", tok); - } - return 4; - } - - void print_options(char c) - { - int i = 0; - - if (c == 'k') { - printf(" keyboard options:\n" - " --hold\n"); - for (i = 0; kmod[i].opt != NULL; i++) - printf("\t\t%s\n", kmod[i].opt); - printf("\n keyboard values:\n" - " [a-z] or\n"); - for (i = 0; kval[i].opt != NULL; i++) - printf("\t\t%-8s%s", kval[i].opt, i % 2 ? "\n" : ""); - printf("\n"); - } else if (c == 'm') { - printf(" mouse options:\n" - " --hold\n"); - for (i = 0; mmod[i].opt != NULL; i++) - printf("\t\t%s\n", mmod[i].opt); - printf("\n mouse values:\n" - " Two signed numbers\n" - "--quit to close\n"); - } else { - printf(" joystick options:\n"); - for (i = 0; jmod[i].opt != NULL; i++) - printf("\t\t%s\n", jmod[i].opt); - printf("\n joystick values:\n" - " three signed numbers\n" - "--quit to close\n"); - } - } - - int main(int argc, const char *argv[]) - { - const char *filename = NULL; - int fd = 0; - char buf[BUF_LEN]; - int cmd_len; - char report[8]; - int to_send = 8; - int hold = 0; - fd_set rfds; - int retval, i; - - if (argc < 3) { - fprintf(stderr, "Usage: %s devname mouse|keyboard|joystick\n", - argv[0]); - return 1; - } - - if (argv[2][0] != 'k' && argv[2][0] != 'm' && argv[2][0] != 'j') - return 2; - - filename = argv[1]; - - if ((fd = open(filename, O_RDWR, 0666)) == -1) { - perror(filename); - return 3; - } - - print_options(argv[2][0]); - - while (42) { - - FD_ZERO(&rfds); - FD_SET(STDIN_FILENO, &rfds); - FD_SET(fd, &rfds); - - retval = select(fd + 1, &rfds, NULL, NULL, NULL); - if (retval == -1 && errno == EINTR) - continue; - if (retval < 0) { - perror("select()"); - return 4; - } - - if (FD_ISSET(fd, &rfds)) { - cmd_len = read(fd, buf, BUF_LEN - 1); - printf("recv report:"); - for (i = 0; i < cmd_len; i++) - printf(" %02x", buf[i]); - printf("\n"); - } - - if (FD_ISSET(STDIN_FILENO, &rfds)) { - memset(report, 0x0, sizeof(report)); - cmd_len = read(STDIN_FILENO, buf, BUF_LEN - 1); - - if (cmd_len == 0) - break; - - buf[cmd_len - 1] = '\0'; - hold = 0; - - memset(report, 0x0, sizeof(report)); - if (argv[2][0] == 'k') - to_send = keyboard_fill_report(report, buf, &hold); - else if (argv[2][0] == 'm') - to_send = mouse_fill_report(report, buf, &hold); - else - to_send = joystick_fill_report(report, buf, &hold); - - if (to_send == -1) - break; - - if (write(fd, report, to_send) != to_send) { - perror(filename); - return 5; - } - if (!hold) { - memset(report, 0x0, sizeof(report)); - if (write(fd, report, to_send) != to_send) { - perror(filename); - return 6; - } - } - } - } - - close(fd); - return 0; - } diff --git a/Documentation/usb/gadget_multi.rst b/Documentation/usb/gadget_multi.rst new file mode 100644 index 000000000000..9806b55af301 --- /dev/null +++ b/Documentation/usb/gadget_multi.rst @@ -0,0 +1,165 @@ +============================== +Multifunction Composite Gadget +============================== + +Overview +======== + +The Multifunction Composite Gadget (or g_multi) is a composite gadget +that makes extensive use of the composite framework to provide +a... multifunction gadget. + +In it's standard configuration it provides a single USB configuration +with RNDIS[1] (that is Ethernet), USB CDC[2] ACM (that is serial) and +USB Mass Storage functions. + +A CDC ECM (Ethernet) function may be turned on via a Kconfig option +and RNDIS can be turned off. If they are both enabled the gadget will +have two configurations -- one with RNDIS and another with CDC ECM[3]. + +Please note that if you use non-standard configuration (that is enable +CDC ECM) you may need to change vendor and/or product ID. + +Host drivers +============ + +To make use of the gadget one needs to make it work on host side -- +without that there's no hope of achieving anything with the gadget. +As one might expect, things one need to do very from system to system. + +Linux host drivers +------------------ + +Since the gadget uses standard composite framework and appears as such +to Linux host it does not need any additional drivers on Linux host +side. All the functions are handled by respective drivers developed +for them. + +This is also true for two configuration set-up with RNDIS +configuration being the first one. Linux host will use the second +configuration with CDC ECM which should work better under Linux. + +Windows host drivers +-------------------- + +For the gadget to work under Windows two conditions have to be met: + +Detecting as composite gadget +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +First of all, Windows need to detect the gadget as an USB composite +gadget which on its own have some conditions[4]. If they are met, +Windows lets USB Generic Parent Driver[5] handle the device which then +tries to match drivers for each individual interface (sort of, don't +get into too many details). + +The good news is: you do not have to worry about most of the +conditions! + +The only thing to worry is that the gadget has to have a single +configuration so a dual RNDIS and CDC ECM gadget won't work unless you +create a proper INF -- and of course, if you do submit it! + +Installing drivers for each function +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The other, trickier thing is making Windows install drivers for each +individual function. + +For mass storage it is trivial since Windows detect it's an interface +implementing USB Mass Storage class and selects appropriate driver. + +Things are harder with RDNIS and CDC ACM. + +RNDIS +..... + +To make Windows select RNDIS drivers for the first function in the +gadget, one needs to use the [[file:linux.inf]] file provided with this +document. It "attaches" Window's RNDIS driver to the first interface +of the gadget. + +Please note, that while testing we encountered some issues[6] when +RNDIS was not the first interface. You do not need to worry abut it +unless you are trying to develop your own gadget in which case watch +out for this bug. + +CDC ACM +....... + +Similarly, [[file:linux-cdc-acm.inf]] is provided for CDC ACM. + +Customising the gadget +...................... + +If you intend to hack the g_multi gadget be advised that rearranging +functions will obviously change interface numbers for each of the +functionality. As an effect provided INFs won't work since they have +interface numbers hard-coded in them (it's not hard to change those +though[7]). + +This also means, that after experimenting with g_multi and changing +provided functions one should change gadget's vendor and/or product ID +so there will be no collision with other customised gadgets or the +original gadget. + +Failing to comply may cause brain damage after wondering for hours why +things don't work as intended before realising Windows have cached +some drivers information (changing USB port may sometimes help plus +you might try using USBDeview[8] to remove the phantom device). + +INF testing +........... + +Provided INF files have been tested on Windows XP SP3, Windows Vista +and Windows 7, all 32-bit versions. It should work on 64-bit versions +as well. It most likely won't work on Windows prior to Windows XP +SP2. + +Other systems +------------- + +At this moment, drivers for any other systems have not been tested. +Knowing how MacOS is based on BSD and BSD is an Open Source it is +believed that it should (read: "I have no idea whether it will") work +out-of-the-box. + +For more exotic systems I have even less to say... + +Any testing and drivers *are* *welcome*! + +Authors +======= + +This document has been written by Michal Nazarewicz +([[mailto:mina86@mina86.com]]). INF files have been hacked with +support of Marek Szyprowski ([[mailto:m.szyprowski@samsung.com]]) and +Xiaofan Chen ([[mailto:xiaofanc@gmail.com]]) basing on the MS RNDIS +template[9], Microchip's CDC ACM INF file and David Brownell's +([[mailto:dbrownell@users.sourceforge.net]]) original INF files. + +Footnotes +========= + +[1] Remote Network Driver Interface Specification, +[[http://msdn.microsoft.com/en-us/library/ee484414.aspx]]. + +[2] Communications Device Class Abstract Control Model, spec for this +and other USB classes can be found at +[[http://www.usb.org/developers/devclass_docs/]]. + +[3] CDC Ethernet Control Model. + +[4] [[http://msdn.microsoft.com/en-us/library/ff537109(v=VS.85).aspx]] + +[5] [[http://msdn.microsoft.com/en-us/library/ff539234(v=VS.85).aspx]] + +[6] To put it in some other nice words, Windows failed to respond to +any user input. + +[7] You may find [[http://www.cygnal.org/ubb/Forum9/HTML/001050.html]] +useful. + +[8] http://www.nirsoft.net/utils/usb_devices_view.html + +[9] [[http://msdn.microsoft.com/en-us/library/ff570620.aspx]] diff --git a/Documentation/usb/gadget_multi.txt b/Documentation/usb/gadget_multi.txt deleted file mode 100644 index 9806b55af301..000000000000 --- a/Documentation/usb/gadget_multi.txt +++ /dev/null @@ -1,165 +0,0 @@ -============================== -Multifunction Composite Gadget -============================== - -Overview -======== - -The Multifunction Composite Gadget (or g_multi) is a composite gadget -that makes extensive use of the composite framework to provide -a... multifunction gadget. - -In it's standard configuration it provides a single USB configuration -with RNDIS[1] (that is Ethernet), USB CDC[2] ACM (that is serial) and -USB Mass Storage functions. - -A CDC ECM (Ethernet) function may be turned on via a Kconfig option -and RNDIS can be turned off. If they are both enabled the gadget will -have two configurations -- one with RNDIS and another with CDC ECM[3]. - -Please note that if you use non-standard configuration (that is enable -CDC ECM) you may need to change vendor and/or product ID. - -Host drivers -============ - -To make use of the gadget one needs to make it work on host side -- -without that there's no hope of achieving anything with the gadget. -As one might expect, things one need to do very from system to system. - -Linux host drivers ------------------- - -Since the gadget uses standard composite framework and appears as such -to Linux host it does not need any additional drivers on Linux host -side. All the functions are handled by respective drivers developed -for them. - -This is also true for two configuration set-up with RNDIS -configuration being the first one. Linux host will use the second -configuration with CDC ECM which should work better under Linux. - -Windows host drivers --------------------- - -For the gadget to work under Windows two conditions have to be met: - -Detecting as composite gadget -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -First of all, Windows need to detect the gadget as an USB composite -gadget which on its own have some conditions[4]. If they are met, -Windows lets USB Generic Parent Driver[5] handle the device which then -tries to match drivers for each individual interface (sort of, don't -get into too many details). - -The good news is: you do not have to worry about most of the -conditions! - -The only thing to worry is that the gadget has to have a single -configuration so a dual RNDIS and CDC ECM gadget won't work unless you -create a proper INF -- and of course, if you do submit it! - -Installing drivers for each function -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The other, trickier thing is making Windows install drivers for each -individual function. - -For mass storage it is trivial since Windows detect it's an interface -implementing USB Mass Storage class and selects appropriate driver. - -Things are harder with RDNIS and CDC ACM. - -RNDIS -..... - -To make Windows select RNDIS drivers for the first function in the -gadget, one needs to use the [[file:linux.inf]] file provided with this -document. It "attaches" Window's RNDIS driver to the first interface -of the gadget. - -Please note, that while testing we encountered some issues[6] when -RNDIS was not the first interface. You do not need to worry abut it -unless you are trying to develop your own gadget in which case watch -out for this bug. - -CDC ACM -....... - -Similarly, [[file:linux-cdc-acm.inf]] is provided for CDC ACM. - -Customising the gadget -...................... - -If you intend to hack the g_multi gadget be advised that rearranging -functions will obviously change interface numbers for each of the -functionality. As an effect provided INFs won't work since they have -interface numbers hard-coded in them (it's not hard to change those -though[7]). - -This also means, that after experimenting with g_multi and changing -provided functions one should change gadget's vendor and/or product ID -so there will be no collision with other customised gadgets or the -original gadget. - -Failing to comply may cause brain damage after wondering for hours why -things don't work as intended before realising Windows have cached -some drivers information (changing USB port may sometimes help plus -you might try using USBDeview[8] to remove the phantom device). - -INF testing -........... - -Provided INF files have been tested on Windows XP SP3, Windows Vista -and Windows 7, all 32-bit versions. It should work on 64-bit versions -as well. It most likely won't work on Windows prior to Windows XP -SP2. - -Other systems -------------- - -At this moment, drivers for any other systems have not been tested. -Knowing how MacOS is based on BSD and BSD is an Open Source it is -believed that it should (read: "I have no idea whether it will") work -out-of-the-box. - -For more exotic systems I have even less to say... - -Any testing and drivers *are* *welcome*! - -Authors -======= - -This document has been written by Michal Nazarewicz -([[mailto:mina86@mina86.com]]). INF files have been hacked with -support of Marek Szyprowski ([[mailto:m.szyprowski@samsung.com]]) and -Xiaofan Chen ([[mailto:xiaofanc@gmail.com]]) basing on the MS RNDIS -template[9], Microchip's CDC ACM INF file and David Brownell's -([[mailto:dbrownell@users.sourceforge.net]]) original INF files. - -Footnotes -========= - -[1] Remote Network Driver Interface Specification, -[[http://msdn.microsoft.com/en-us/library/ee484414.aspx]]. - -[2] Communications Device Class Abstract Control Model, spec for this -and other USB classes can be found at -[[http://www.usb.org/developers/devclass_docs/]]. - -[3] CDC Ethernet Control Model. - -[4] [[http://msdn.microsoft.com/en-us/library/ff537109(v=VS.85).aspx]] - -[5] [[http://msdn.microsoft.com/en-us/library/ff539234(v=VS.85).aspx]] - -[6] To put it in some other nice words, Windows failed to respond to -any user input. - -[7] You may find [[http://www.cygnal.org/ubb/Forum9/HTML/001050.html]] -useful. - -[8] http://www.nirsoft.net/utils/usb_devices_view.html - -[9] [[http://msdn.microsoft.com/en-us/library/ff570620.aspx]] diff --git a/Documentation/usb/gadget_printer.rst b/Documentation/usb/gadget_printer.rst new file mode 100644 index 000000000000..5e5516c69075 --- /dev/null +++ b/Documentation/usb/gadget_printer.rst @@ -0,0 +1,523 @@ +=============================== +Linux USB Printer Gadget Driver +=============================== + +06/04/2007 + +Copyright (C) 2007 Craig W. Nadler + + + +General +======= + +This driver may be used if you are writing printer firmware using Linux as +the embedded OS. This driver has nothing to do with using a printer with +your Linux host system. + +You will need a USB device controller and a Linux driver for it that accepts +a gadget / "device class" driver using the Linux USB Gadget API. After the +USB device controller driver is loaded then load the printer gadget driver. +This will present a printer interface to the USB Host that your USB Device +port is connected to. + +This driver is structured for printer firmware that runs in user mode. The +user mode printer firmware will read and write data from the kernel mode +printer gadget driver using a device file. The printer returns a printer status +byte when the USB HOST sends a device request to get the printer status. The +user space firmware can read or write this status byte using a device file +/dev/g_printer . Both blocking and non-blocking read/write calls are supported. + + + + +Howto Use This Driver +===================== + +To load the USB device controller driver and the printer gadget driver. The +following example uses the Netchip 2280 USB device controller driver:: + + modprobe net2280 + modprobe g_printer + + +The follow command line parameter can be used when loading the printer gadget +(ex: modprobe g_printer idVendor=0x0525 idProduct=0xa4a8 ): + +idVendor + This is the Vendor ID used in the device descriptor. The default is + the Netchip vendor id 0x0525. YOU MUST CHANGE TO YOUR OWN VENDOR ID + BEFORE RELEASING A PRODUCT. If you plan to release a product and don't + already have a Vendor ID please see www.usb.org for details on how to + get one. + +idProduct + This is the Product ID used in the device descriptor. The default + is 0xa4a8, you should change this to an ID that's not used by any of + your other USB products if you have any. It would be a good idea to + start numbering your products starting with say 0x0001. + +bcdDevice + This is the version number of your product. It would be a good idea + to put your firmware version here. + +iManufacturer + A string containing the name of the Vendor. + +iProduct + A string containing the Product Name. + +iSerialNum + A string containing the Serial Number. This should be changed for + each unit of your product. + +iPNPstring + The PNP ID string used for this printer. You will want to set + either on the command line or hard code the PNP ID string used for + your printer product. + +qlen + The number of 8k buffers to use per endpoint. The default is 10, you + should tune this for your product. You may also want to tune the + size of each buffer for your product. + + + + +Using The Example Code +====================== + +This example code talks to stdout, instead of a print engine. + +To compile the test code below: + +1) save it to a file called prn_example.c +2) compile the code with the follow command:: + + gcc prn_example.c -o prn_example + + + +To read printer data from the host to stdout:: + + # prn_example -read_data + + +To write printer data from a file (data_file) to the host:: + + # cat data_file | prn_example -write_data + + +To get the current printer status for the gadget driver::: + + # prn_example -get_status + + Printer status is: + Printer is NOT Selected + Paper is Out + Printer OK + + +To set printer to Selected/On-line:: + + # prn_example -selected + + +To set printer to Not Selected/Off-line:: + + # prn_example -not_selected + + +To set paper status to paper out:: + + # prn_example -paper_out + + +To set paper status to paper loaded:: + + # prn_example -paper_loaded + + +To set error status to printer OK:: + + # prn_example -no_error + + +To set error status to ERROR:: + + # prn_example -error + + + + +Example Code +============ + +:: + + + #include + #include + #include + #include + #include + #include + + #define PRINTER_FILE "/dev/g_printer" + #define BUF_SIZE 512 + + + /* + * 'usage()' - Show program usage. + */ + + static void + usage(const char *option) /* I - Option string or NULL */ + { + if (option) { + fprintf(stderr,"prn_example: Unknown option \"%s\"!\n", + option); + } + + fputs("\n", stderr); + fputs("Usage: prn_example -[options]\n", stderr); + fputs("Options:\n", stderr); + fputs("\n", stderr); + fputs("-get_status Get the current printer status.\n", stderr); + fputs("-selected Set the selected status to selected.\n", stderr); + fputs("-not_selected Set the selected status to NOT selected.\n", + stderr); + fputs("-error Set the error status to error.\n", stderr); + fputs("-no_error Set the error status to NO error.\n", stderr); + fputs("-paper_out Set the paper status to paper out.\n", stderr); + fputs("-paper_loaded Set the paper status to paper loaded.\n", + stderr); + fputs("-read_data Read printer data from driver.\n", stderr); + fputs("-write_data Write printer sata to driver.\n", stderr); + fputs("-NB_read_data (Non-Blocking) Read printer data from driver.\n", + stderr); + fputs("\n\n", stderr); + + exit(1); + } + + + static int + read_printer_data() + { + struct pollfd fd[1]; + + /* Open device file for printer gadget. */ + fd[0].fd = open(PRINTER_FILE, O_RDWR); + if (fd[0].fd < 0) { + printf("Error %d opening %s\n", fd[0].fd, PRINTER_FILE); + close(fd[0].fd); + return(-1); + } + + fd[0].events = POLLIN | POLLRDNORM; + + while (1) { + static char buf[BUF_SIZE]; + int bytes_read; + int retval; + + /* Wait for up to 1 second for data. */ + retval = poll(fd, 1, 1000); + + if (retval && (fd[0].revents & POLLRDNORM)) { + + /* Read data from printer gadget driver. */ + bytes_read = read(fd[0].fd, buf, BUF_SIZE); + + if (bytes_read < 0) { + printf("Error %d reading from %s\n", + fd[0].fd, PRINTER_FILE); + close(fd[0].fd); + return(-1); + } else if (bytes_read > 0) { + /* Write data to standard OUTPUT (stdout). */ + fwrite(buf, 1, bytes_read, stdout); + fflush(stdout); + } + + } + + } + + /* Close the device file. */ + close(fd[0].fd); + + return 0; + } + + + static int + write_printer_data() + { + struct pollfd fd[1]; + + /* Open device file for printer gadget. */ + fd[0].fd = open (PRINTER_FILE, O_RDWR); + if (fd[0].fd < 0) { + printf("Error %d opening %s\n", fd[0].fd, PRINTER_FILE); + close(fd[0].fd); + return(-1); + } + + fd[0].events = POLLOUT | POLLWRNORM; + + while (1) { + int retval; + static char buf[BUF_SIZE]; + /* Read data from standard INPUT (stdin). */ + int bytes_read = fread(buf, 1, BUF_SIZE, stdin); + + if (!bytes_read) { + break; + } + + while (bytes_read) { + + /* Wait for up to 1 second to sent data. */ + retval = poll(fd, 1, 1000); + + /* Write data to printer gadget driver. */ + if (retval && (fd[0].revents & POLLWRNORM)) { + retval = write(fd[0].fd, buf, bytes_read); + if (retval < 0) { + printf("Error %d writing to %s\n", + fd[0].fd, + PRINTER_FILE); + close(fd[0].fd); + return(-1); + } else { + bytes_read -= retval; + } + + } + + } + + } + + /* Wait until the data has been sent. */ + fsync(fd[0].fd); + + /* Close the device file. */ + close(fd[0].fd); + + return 0; + } + + + static int + read_NB_printer_data() + { + int fd; + static char buf[BUF_SIZE]; + int bytes_read; + + /* Open device file for printer gadget. */ + fd = open(PRINTER_FILE, O_RDWR|O_NONBLOCK); + if (fd < 0) { + printf("Error %d opening %s\n", fd, PRINTER_FILE); + close(fd); + return(-1); + } + + while (1) { + /* Read data from printer gadget driver. */ + bytes_read = read(fd, buf, BUF_SIZE); + if (bytes_read <= 0) { + break; + } + + /* Write data to standard OUTPUT (stdout). */ + fwrite(buf, 1, bytes_read, stdout); + fflush(stdout); + } + + /* Close the device file. */ + close(fd); + + return 0; + } + + + static int + get_printer_status() + { + int retval; + int fd; + + /* Open device file for printer gadget. */ + fd = open(PRINTER_FILE, O_RDWR); + if (fd < 0) { + printf("Error %d opening %s\n", fd, PRINTER_FILE); + close(fd); + return(-1); + } + + /* Make the IOCTL call. */ + retval = ioctl(fd, GADGET_GET_PRINTER_STATUS); + if (retval < 0) { + fprintf(stderr, "ERROR: Failed to set printer status\n"); + return(-1); + } + + /* Close the device file. */ + close(fd); + + return(retval); + } + + + static int + set_printer_status(unsigned char buf, int clear_printer_status_bit) + { + int retval; + int fd; + + retval = get_printer_status(); + if (retval < 0) { + fprintf(stderr, "ERROR: Failed to get printer status\n"); + return(-1); + } + + /* Open device file for printer gadget. */ + fd = open(PRINTER_FILE, O_RDWR); + + if (fd < 0) { + printf("Error %d opening %s\n", fd, PRINTER_FILE); + close(fd); + return(-1); + } + + if (clear_printer_status_bit) { + retval &= ~buf; + } else { + retval |= buf; + } + + /* Make the IOCTL call. */ + if (ioctl(fd, GADGET_SET_PRINTER_STATUS, (unsigned char)retval)) { + fprintf(stderr, "ERROR: Failed to set printer status\n"); + return(-1); + } + + /* Close the device file. */ + close(fd); + + return 0; + } + + + static int + display_printer_status() + { + char printer_status; + + printer_status = get_printer_status(); + if (printer_status < 0) { + fprintf(stderr, "ERROR: Failed to get printer status\n"); + return(-1); + } + + printf("Printer status is:\n"); + if (printer_status & PRINTER_SELECTED) { + printf(" Printer is Selected\n"); + } else { + printf(" Printer is NOT Selected\n"); + } + if (printer_status & PRINTER_PAPER_EMPTY) { + printf(" Paper is Out\n"); + } else { + printf(" Paper is Loaded\n"); + } + if (printer_status & PRINTER_NOT_ERROR) { + printf(" Printer OK\n"); + } else { + printf(" Printer ERROR\n"); + } + + return(0); + } + + + int + main(int argc, char *argv[]) + { + int i; /* Looping var */ + int retval = 0; + + /* No Args */ + if (argc == 1) { + usage(0); + exit(0); + } + + for (i = 1; i < argc && !retval; i ++) { + + if (argv[i][0] != '-') { + continue; + } + + if (!strcmp(argv[i], "-get_status")) { + if (display_printer_status()) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-paper_loaded")) { + if (set_printer_status(PRINTER_PAPER_EMPTY, 1)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-paper_out")) { + if (set_printer_status(PRINTER_PAPER_EMPTY, 0)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-selected")) { + if (set_printer_status(PRINTER_SELECTED, 0)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-not_selected")) { + if (set_printer_status(PRINTER_SELECTED, 1)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-error")) { + if (set_printer_status(PRINTER_NOT_ERROR, 1)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-no_error")) { + if (set_printer_status(PRINTER_NOT_ERROR, 0)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-read_data")) { + if (read_printer_data()) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-write_data")) { + if (write_printer_data()) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-NB_read_data")) { + if (read_NB_printer_data()) { + retval = 1; + } + + } else { + usage(argv[i]); + retval = 1; + } + } + + exit(retval); + } diff --git a/Documentation/usb/gadget_printer.txt b/Documentation/usb/gadget_printer.txt deleted file mode 100644 index 5e5516c69075..000000000000 --- a/Documentation/usb/gadget_printer.txt +++ /dev/null @@ -1,523 +0,0 @@ -=============================== -Linux USB Printer Gadget Driver -=============================== - -06/04/2007 - -Copyright (C) 2007 Craig W. Nadler - - - -General -======= - -This driver may be used if you are writing printer firmware using Linux as -the embedded OS. This driver has nothing to do with using a printer with -your Linux host system. - -You will need a USB device controller and a Linux driver for it that accepts -a gadget / "device class" driver using the Linux USB Gadget API. After the -USB device controller driver is loaded then load the printer gadget driver. -This will present a printer interface to the USB Host that your USB Device -port is connected to. - -This driver is structured for printer firmware that runs in user mode. The -user mode printer firmware will read and write data from the kernel mode -printer gadget driver using a device file. The printer returns a printer status -byte when the USB HOST sends a device request to get the printer status. The -user space firmware can read or write this status byte using a device file -/dev/g_printer . Both blocking and non-blocking read/write calls are supported. - - - - -Howto Use This Driver -===================== - -To load the USB device controller driver and the printer gadget driver. The -following example uses the Netchip 2280 USB device controller driver:: - - modprobe net2280 - modprobe g_printer - - -The follow command line parameter can be used when loading the printer gadget -(ex: modprobe g_printer idVendor=0x0525 idProduct=0xa4a8 ): - -idVendor - This is the Vendor ID used in the device descriptor. The default is - the Netchip vendor id 0x0525. YOU MUST CHANGE TO YOUR OWN VENDOR ID - BEFORE RELEASING A PRODUCT. If you plan to release a product and don't - already have a Vendor ID please see www.usb.org for details on how to - get one. - -idProduct - This is the Product ID used in the device descriptor. The default - is 0xa4a8, you should change this to an ID that's not used by any of - your other USB products if you have any. It would be a good idea to - start numbering your products starting with say 0x0001. - -bcdDevice - This is the version number of your product. It would be a good idea - to put your firmware version here. - -iManufacturer - A string containing the name of the Vendor. - -iProduct - A string containing the Product Name. - -iSerialNum - A string containing the Serial Number. This should be changed for - each unit of your product. - -iPNPstring - The PNP ID string used for this printer. You will want to set - either on the command line or hard code the PNP ID string used for - your printer product. - -qlen - The number of 8k buffers to use per endpoint. The default is 10, you - should tune this for your product. You may also want to tune the - size of each buffer for your product. - - - - -Using The Example Code -====================== - -This example code talks to stdout, instead of a print engine. - -To compile the test code below: - -1) save it to a file called prn_example.c -2) compile the code with the follow command:: - - gcc prn_example.c -o prn_example - - - -To read printer data from the host to stdout:: - - # prn_example -read_data - - -To write printer data from a file (data_file) to the host:: - - # cat data_file | prn_example -write_data - - -To get the current printer status for the gadget driver::: - - # prn_example -get_status - - Printer status is: - Printer is NOT Selected - Paper is Out - Printer OK - - -To set printer to Selected/On-line:: - - # prn_example -selected - - -To set printer to Not Selected/Off-line:: - - # prn_example -not_selected - - -To set paper status to paper out:: - - # prn_example -paper_out - - -To set paper status to paper loaded:: - - # prn_example -paper_loaded - - -To set error status to printer OK:: - - # prn_example -no_error - - -To set error status to ERROR:: - - # prn_example -error - - - - -Example Code -============ - -:: - - - #include - #include - #include - #include - #include - #include - - #define PRINTER_FILE "/dev/g_printer" - #define BUF_SIZE 512 - - - /* - * 'usage()' - Show program usage. - */ - - static void - usage(const char *option) /* I - Option string or NULL */ - { - if (option) { - fprintf(stderr,"prn_example: Unknown option \"%s\"!\n", - option); - } - - fputs("\n", stderr); - fputs("Usage: prn_example -[options]\n", stderr); - fputs("Options:\n", stderr); - fputs("\n", stderr); - fputs("-get_status Get the current printer status.\n", stderr); - fputs("-selected Set the selected status to selected.\n", stderr); - fputs("-not_selected Set the selected status to NOT selected.\n", - stderr); - fputs("-error Set the error status to error.\n", stderr); - fputs("-no_error Set the error status to NO error.\n", stderr); - fputs("-paper_out Set the paper status to paper out.\n", stderr); - fputs("-paper_loaded Set the paper status to paper loaded.\n", - stderr); - fputs("-read_data Read printer data from driver.\n", stderr); - fputs("-write_data Write printer sata to driver.\n", stderr); - fputs("-NB_read_data (Non-Blocking) Read printer data from driver.\n", - stderr); - fputs("\n\n", stderr); - - exit(1); - } - - - static int - read_printer_data() - { - struct pollfd fd[1]; - - /* Open device file for printer gadget. */ - fd[0].fd = open(PRINTER_FILE, O_RDWR); - if (fd[0].fd < 0) { - printf("Error %d opening %s\n", fd[0].fd, PRINTER_FILE); - close(fd[0].fd); - return(-1); - } - - fd[0].events = POLLIN | POLLRDNORM; - - while (1) { - static char buf[BUF_SIZE]; - int bytes_read; - int retval; - - /* Wait for up to 1 second for data. */ - retval = poll(fd, 1, 1000); - - if (retval && (fd[0].revents & POLLRDNORM)) { - - /* Read data from printer gadget driver. */ - bytes_read = read(fd[0].fd, buf, BUF_SIZE); - - if (bytes_read < 0) { - printf("Error %d reading from %s\n", - fd[0].fd, PRINTER_FILE); - close(fd[0].fd); - return(-1); - } else if (bytes_read > 0) { - /* Write data to standard OUTPUT (stdout). */ - fwrite(buf, 1, bytes_read, stdout); - fflush(stdout); - } - - } - - } - - /* Close the device file. */ - close(fd[0].fd); - - return 0; - } - - - static int - write_printer_data() - { - struct pollfd fd[1]; - - /* Open device file for printer gadget. */ - fd[0].fd = open (PRINTER_FILE, O_RDWR); - if (fd[0].fd < 0) { - printf("Error %d opening %s\n", fd[0].fd, PRINTER_FILE); - close(fd[0].fd); - return(-1); - } - - fd[0].events = POLLOUT | POLLWRNORM; - - while (1) { - int retval; - static char buf[BUF_SIZE]; - /* Read data from standard INPUT (stdin). */ - int bytes_read = fread(buf, 1, BUF_SIZE, stdin); - - if (!bytes_read) { - break; - } - - while (bytes_read) { - - /* Wait for up to 1 second to sent data. */ - retval = poll(fd, 1, 1000); - - /* Write data to printer gadget driver. */ - if (retval && (fd[0].revents & POLLWRNORM)) { - retval = write(fd[0].fd, buf, bytes_read); - if (retval < 0) { - printf("Error %d writing to %s\n", - fd[0].fd, - PRINTER_FILE); - close(fd[0].fd); - return(-1); - } else { - bytes_read -= retval; - } - - } - - } - - } - - /* Wait until the data has been sent. */ - fsync(fd[0].fd); - - /* Close the device file. */ - close(fd[0].fd); - - return 0; - } - - - static int - read_NB_printer_data() - { - int fd; - static char buf[BUF_SIZE]; - int bytes_read; - - /* Open device file for printer gadget. */ - fd = open(PRINTER_FILE, O_RDWR|O_NONBLOCK); - if (fd < 0) { - printf("Error %d opening %s\n", fd, PRINTER_FILE); - close(fd); - return(-1); - } - - while (1) { - /* Read data from printer gadget driver. */ - bytes_read = read(fd, buf, BUF_SIZE); - if (bytes_read <= 0) { - break; - } - - /* Write data to standard OUTPUT (stdout). */ - fwrite(buf, 1, bytes_read, stdout); - fflush(stdout); - } - - /* Close the device file. */ - close(fd); - - return 0; - } - - - static int - get_printer_status() - { - int retval; - int fd; - - /* Open device file for printer gadget. */ - fd = open(PRINTER_FILE, O_RDWR); - if (fd < 0) { - printf("Error %d opening %s\n", fd, PRINTER_FILE); - close(fd); - return(-1); - } - - /* Make the IOCTL call. */ - retval = ioctl(fd, GADGET_GET_PRINTER_STATUS); - if (retval < 0) { - fprintf(stderr, "ERROR: Failed to set printer status\n"); - return(-1); - } - - /* Close the device file. */ - close(fd); - - return(retval); - } - - - static int - set_printer_status(unsigned char buf, int clear_printer_status_bit) - { - int retval; - int fd; - - retval = get_printer_status(); - if (retval < 0) { - fprintf(stderr, "ERROR: Failed to get printer status\n"); - return(-1); - } - - /* Open device file for printer gadget. */ - fd = open(PRINTER_FILE, O_RDWR); - - if (fd < 0) { - printf("Error %d opening %s\n", fd, PRINTER_FILE); - close(fd); - return(-1); - } - - if (clear_printer_status_bit) { - retval &= ~buf; - } else { - retval |= buf; - } - - /* Make the IOCTL call. */ - if (ioctl(fd, GADGET_SET_PRINTER_STATUS, (unsigned char)retval)) { - fprintf(stderr, "ERROR: Failed to set printer status\n"); - return(-1); - } - - /* Close the device file. */ - close(fd); - - return 0; - } - - - static int - display_printer_status() - { - char printer_status; - - printer_status = get_printer_status(); - if (printer_status < 0) { - fprintf(stderr, "ERROR: Failed to get printer status\n"); - return(-1); - } - - printf("Printer status is:\n"); - if (printer_status & PRINTER_SELECTED) { - printf(" Printer is Selected\n"); - } else { - printf(" Printer is NOT Selected\n"); - } - if (printer_status & PRINTER_PAPER_EMPTY) { - printf(" Paper is Out\n"); - } else { - printf(" Paper is Loaded\n"); - } - if (printer_status & PRINTER_NOT_ERROR) { - printf(" Printer OK\n"); - } else { - printf(" Printer ERROR\n"); - } - - return(0); - } - - - int - main(int argc, char *argv[]) - { - int i; /* Looping var */ - int retval = 0; - - /* No Args */ - if (argc == 1) { - usage(0); - exit(0); - } - - for (i = 1; i < argc && !retval; i ++) { - - if (argv[i][0] != '-') { - continue; - } - - if (!strcmp(argv[i], "-get_status")) { - if (display_printer_status()) { - retval = 1; - } - - } else if (!strcmp(argv[i], "-paper_loaded")) { - if (set_printer_status(PRINTER_PAPER_EMPTY, 1)) { - retval = 1; - } - - } else if (!strcmp(argv[i], "-paper_out")) { - if (set_printer_status(PRINTER_PAPER_EMPTY, 0)) { - retval = 1; - } - - } else if (!strcmp(argv[i], "-selected")) { - if (set_printer_status(PRINTER_SELECTED, 0)) { - retval = 1; - } - - } else if (!strcmp(argv[i], "-not_selected")) { - if (set_printer_status(PRINTER_SELECTED, 1)) { - retval = 1; - } - - } else if (!strcmp(argv[i], "-error")) { - if (set_printer_status(PRINTER_NOT_ERROR, 1)) { - retval = 1; - } - - } else if (!strcmp(argv[i], "-no_error")) { - if (set_printer_status(PRINTER_NOT_ERROR, 0)) { - retval = 1; - } - - } else if (!strcmp(argv[i], "-read_data")) { - if (read_printer_data()) { - retval = 1; - } - - } else if (!strcmp(argv[i], "-write_data")) { - if (write_printer_data()) { - retval = 1; - } - - } else if (!strcmp(argv[i], "-NB_read_data")) { - if (read_NB_printer_data()) { - retval = 1; - } - - } else { - usage(argv[i]); - retval = 1; - } - } - - exit(retval); - } diff --git a/Documentation/usb/gadget_serial.rst b/Documentation/usb/gadget_serial.rst new file mode 100644 index 000000000000..dce8bc1fb1f2 --- /dev/null +++ b/Documentation/usb/gadget_serial.rst @@ -0,0 +1,289 @@ +=============================== +Linux Gadget Serial Driver v2.0 +=============================== + +11/20/2004 + +(updated 8-May-2008 for v2.3) + + +License and Disclaimer +---------------------- +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of +the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public +License along with this program; if not, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, +MA 02111-1307 USA. + +This document and the gadget serial driver itself are +Copyright (C) 2004 by Al Borchers (alborchers@steinerpoint.com). + +If you have questions, problems, or suggestions for this driver +please contact Al Borchers at alborchers@steinerpoint.com. + + +Prerequisites +------------- +Versions of the gadget serial driver are available for the +2.4 Linux kernels, but this document assumes you are using +version 2.3 or later of the gadget serial driver in a 2.6 +Linux kernel. + +This document assumes that you are familiar with Linux and +Windows and know how to configure and build Linux kernels, run +standard utilities, use minicom and HyperTerminal, and work with +USB and serial devices. It also assumes you configure the Linux +gadget and usb drivers as modules. + +With version 2.3 of the driver, major and minor device nodes are +no longer statically defined. Your Linux based system should mount +sysfs in /sys, and use "mdev" (in Busybox) or "udev" to make the +/dev nodes matching the sysfs /sys/class/tty files. + + + +Overview +-------- +The gadget serial driver is a Linux USB gadget driver, a USB device +side driver. It runs on a Linux system that has USB device side +hardware; for example, a PDA, an embedded Linux system, or a PC +with a USB development card. + +The gadget serial driver talks over USB to either a CDC ACM driver +or a generic USB serial driver running on a host PC:: + + Host + -------------------------------------- + | Host-Side CDC ACM USB Host | + | Operating | or | Controller | USB + | System | Generic USB | Driver |-------- + | (Linux or | Serial | and | | + | Windows) Driver USB Stack | | + -------------------------------------- | + | + | + | + Gadget | + -------------------------------------- | + | Gadget USB Periph. | | + | Device-Side | Gadget | Controller | | + | Linux | Serial | Driver |-------- + | Operating | Driver | and | + | System USB Stack | + -------------------------------------- + +On the device-side Linux system, the gadget serial driver looks +like a serial device. + +On the host-side system, the gadget serial device looks like a +CDC ACM compliant class device or a simple vendor specific device +with bulk in and bulk out endpoints, and it is treated similarly +to other serial devices. + +The host side driver can potentially be any ACM compliant driver +or any driver that can talk to a device with a simple bulk in/out +interface. Gadget serial has been tested with the Linux ACM driver, +the Windows usbser.sys ACM driver, and the Linux USB generic serial +driver. + +With the gadget serial driver and the host side ACM or generic +serial driver running, you should be able to communicate between +the host and the gadget side systems as if they were connected by a +serial cable. + +The gadget serial driver only provides simple unreliable data +communication. It does not yet handle flow control or many other +features of normal serial devices. + + +Installing the Gadget Serial Driver +----------------------------------- +To use the gadget serial driver you must configure the Linux gadget +side kernel for "Support for USB Gadgets", for a "USB Peripheral +Controller" (for example, net2280), and for the "Serial Gadget" +driver. All this are listed under "USB Gadget Support" when +configuring the kernel. Then rebuild and install the kernel or +modules. + +Then you must load the gadget serial driver. To load it as an +ACM device (recommended for interoperability), do this:: + + modprobe g_serial + +To load it as a vendor specific bulk in/out device, do this:: + + modprobe g_serial use_acm=0 + +This will also automatically load the underlying gadget peripheral +controller driver. This must be done each time you reboot the gadget +side Linux system. You can add this to the start up scripts, if +desired. + +Your system should use mdev (from busybox) or udev to make the +device nodes. After this gadget driver has been set up you should +then see a /dev/ttyGS0 node:: + + # ls -l /dev/ttyGS0 | cat + crw-rw---- 1 root root 253, 0 May 8 14:10 /dev/ttyGS0 + # + +Note that the major number (253, above) is system-specific. If +you need to create /dev nodes by hand, the right numbers to use +will be in the /sys/class/tty/ttyGS0/dev file. + +When you link this gadget driver early, perhaps even statically, +you may want to set up an /etc/inittab entry to run "getty" on it. +The /dev/ttyGS0 line should work like most any other serial port. + + +If gadget serial is loaded as an ACM device you will want to use +either the Windows or Linux ACM driver on the host side. If gadget +serial is loaded as a bulk in/out device, you will want to use the +Linux generic serial driver on the host side. Follow the appropriate +instructions below to install the host side driver. + + +Installing the Windows Host ACM Driver +-------------------------------------- +To use the Windows ACM driver you must have the "linux-cdc-acm.inf" +file (provided along this document) which supports all recent versions +of Windows. + +When the gadget serial driver is loaded and the USB device connected +to the Windows host with a USB cable, Windows should recognize the +gadget serial device and ask for a driver. Tell Windows to find the +driver in the folder that contains the "linux-cdc-acm.inf" file. + +For example, on Windows XP, when the gadget serial device is first +plugged in, the "Found New Hardware Wizard" starts up. Select +"Install from a list or specific location (Advanced)", then on the +next screen select "Include this location in the search" and enter the +path or browse to the folder containing the "linux-cdc-acm.inf" file. +Windows will complain that the Gadget Serial driver has not passed +Windows Logo testing, but select "Continue anyway" and finish the +driver installation. + +On Windows XP, in the "Device Manager" (under "Control Panel", +"System", "Hardware") expand the "Ports (COM & LPT)" entry and you +should see "Gadget Serial" listed as the driver for one of the COM +ports. + +To uninstall the Windows XP driver for "Gadget Serial", right click +on the "Gadget Serial" entry in the "Device Manager" and select +"Uninstall". + + +Installing the Linux Host ACM Driver +------------------------------------ +To use the Linux ACM driver you must configure the Linux host side +kernel for "Support for Host-side USB" and for "USB Modem (CDC ACM) +support". + +Once the gadget serial driver is loaded and the USB device connected +to the Linux host with a USB cable, the host system should recognize +the gadget serial device. For example, the command:: + + cat /sys/kernel/debug/usb/devices + +should show something like this::: + + T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 5 Spd=480 MxCh= 0 + D: Ver= 2.00 Cls=02(comm.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 + P: Vendor=0525 ProdID=a4a7 Rev= 2.01 + S: Manufacturer=Linux 2.6.8.1 with net2280 + S: Product=Gadget Serial + S: SerialNumber=0 + C:* #Ifs= 2 Cfg#= 2 Atr=c0 MxPwr= 2mA + I: If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm + E: Ad=83(I) Atr=03(Int.) MxPS= 8 Ivl=32ms + I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm + E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms + E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms + +If the host side Linux system is configured properly, the ACM driver +should be loaded automatically. The command "lsmod" should show the +"acm" module is loaded. + + +Installing the Linux Host Generic USB Serial Driver +--------------------------------------------------- +To use the Linux generic USB serial driver you must configure the +Linux host side kernel for "Support for Host-side USB", for "USB +Serial Converter support", and for the "USB Generic Serial Driver". + +Once the gadget serial driver is loaded and the USB device connected +to the Linux host with a USB cable, the host system should recognize +the gadget serial device. For example, the command:: + + cat /sys/kernel/debug/usb/devices + +should show something like this::: + + T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 6 Spd=480 MxCh= 0 + D: Ver= 2.00 Cls=ff(vend.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 + P: Vendor=0525 ProdID=a4a6 Rev= 2.01 + S: Manufacturer=Linux 2.6.8.1 with net2280 + S: Product=Gadget Serial + S: SerialNumber=0 + C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr= 2mA + I: If#= 0 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=serial + E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms + E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms + +You must load the usbserial driver and explicitly set its parameters +to configure it to recognize the gadget serial device, like this:: + + echo 0x0525 0xA4A6 >/sys/bus/usb-serial/drivers/generic/new_id + +The legacy way is to use module parameters:: + + modprobe usbserial vendor=0x0525 product=0xA4A6 + +If everything is working, usbserial will print a message in the +system log saying something like "Gadget Serial converter now +attached to ttyUSB0". + + +Testing with Minicom or HyperTerminal +------------------------------------- +Once the gadget serial driver and the host driver are both installed, +and a USB cable connects the gadget device to the host, you should +be able to communicate over USB between the gadget and host systems. +You can use minicom or HyperTerminal to try this out. + +On the gadget side run "minicom -s" to configure a new minicom +session. Under "Serial port setup" set "/dev/ttygserial" as the +"Serial Device". Set baud rate, data bits, parity, and stop bits, +to 9600, 8, none, and 1--these settings mostly do not matter. +Under "Modem and dialing" erase all the modem and dialing strings. + +On a Linux host running the ACM driver, configure minicom similarly +but use "/dev/ttyACM0" as the "Serial Device". (If you have other +ACM devices connected, change the device name appropriately.) + +On a Linux host running the USB generic serial driver, configure +minicom similarly, but use "/dev/ttyUSB0" as the "Serial Device". +(If you have other USB serial devices connected, change the device +name appropriately.) + +On a Windows host configure a new HyperTerminal session to use the +COM port assigned to Gadget Serial. The "Port Settings" will be +set automatically when HyperTerminal connects to the gadget serial +device, so you can leave them set to the default values--these +settings mostly do not matter. + +With minicom configured and running on the gadget side and with +minicom or HyperTerminal configured and running on the host side, +you should be able to send data back and forth between the gadget +side and host side systems. Anything you type on the terminal +window on the gadget side should appear in the terminal window on +the host side and vice versa. diff --git a/Documentation/usb/gadget_serial.txt b/Documentation/usb/gadget_serial.txt deleted file mode 100644 index dce8bc1fb1f2..000000000000 --- a/Documentation/usb/gadget_serial.txt +++ /dev/null @@ -1,289 +0,0 @@ -=============================== -Linux Gadget Serial Driver v2.0 -=============================== - -11/20/2004 - -(updated 8-May-2008 for v2.3) - - -License and Disclaimer ----------------------- -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 of -the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public -License along with this program; if not, write to the Free -Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, -MA 02111-1307 USA. - -This document and the gadget serial driver itself are -Copyright (C) 2004 by Al Borchers (alborchers@steinerpoint.com). - -If you have questions, problems, or suggestions for this driver -please contact Al Borchers at alborchers@steinerpoint.com. - - -Prerequisites -------------- -Versions of the gadget serial driver are available for the -2.4 Linux kernels, but this document assumes you are using -version 2.3 or later of the gadget serial driver in a 2.6 -Linux kernel. - -This document assumes that you are familiar with Linux and -Windows and know how to configure and build Linux kernels, run -standard utilities, use minicom and HyperTerminal, and work with -USB and serial devices. It also assumes you configure the Linux -gadget and usb drivers as modules. - -With version 2.3 of the driver, major and minor device nodes are -no longer statically defined. Your Linux based system should mount -sysfs in /sys, and use "mdev" (in Busybox) or "udev" to make the -/dev nodes matching the sysfs /sys/class/tty files. - - - -Overview --------- -The gadget serial driver is a Linux USB gadget driver, a USB device -side driver. It runs on a Linux system that has USB device side -hardware; for example, a PDA, an embedded Linux system, or a PC -with a USB development card. - -The gadget serial driver talks over USB to either a CDC ACM driver -or a generic USB serial driver running on a host PC:: - - Host - -------------------------------------- - | Host-Side CDC ACM USB Host | - | Operating | or | Controller | USB - | System | Generic USB | Driver |-------- - | (Linux or | Serial | and | | - | Windows) Driver USB Stack | | - -------------------------------------- | - | - | - | - Gadget | - -------------------------------------- | - | Gadget USB Periph. | | - | Device-Side | Gadget | Controller | | - | Linux | Serial | Driver |-------- - | Operating | Driver | and | - | System USB Stack | - -------------------------------------- - -On the device-side Linux system, the gadget serial driver looks -like a serial device. - -On the host-side system, the gadget serial device looks like a -CDC ACM compliant class device or a simple vendor specific device -with bulk in and bulk out endpoints, and it is treated similarly -to other serial devices. - -The host side driver can potentially be any ACM compliant driver -or any driver that can talk to a device with a simple bulk in/out -interface. Gadget serial has been tested with the Linux ACM driver, -the Windows usbser.sys ACM driver, and the Linux USB generic serial -driver. - -With the gadget serial driver and the host side ACM or generic -serial driver running, you should be able to communicate between -the host and the gadget side systems as if they were connected by a -serial cable. - -The gadget serial driver only provides simple unreliable data -communication. It does not yet handle flow control or many other -features of normal serial devices. - - -Installing the Gadget Serial Driver ------------------------------------ -To use the gadget serial driver you must configure the Linux gadget -side kernel for "Support for USB Gadgets", for a "USB Peripheral -Controller" (for example, net2280), and for the "Serial Gadget" -driver. All this are listed under "USB Gadget Support" when -configuring the kernel. Then rebuild and install the kernel or -modules. - -Then you must load the gadget serial driver. To load it as an -ACM device (recommended for interoperability), do this:: - - modprobe g_serial - -To load it as a vendor specific bulk in/out device, do this:: - - modprobe g_serial use_acm=0 - -This will also automatically load the underlying gadget peripheral -controller driver. This must be done each time you reboot the gadget -side Linux system. You can add this to the start up scripts, if -desired. - -Your system should use mdev (from busybox) or udev to make the -device nodes. After this gadget driver has been set up you should -then see a /dev/ttyGS0 node:: - - # ls -l /dev/ttyGS0 | cat - crw-rw---- 1 root root 253, 0 May 8 14:10 /dev/ttyGS0 - # - -Note that the major number (253, above) is system-specific. If -you need to create /dev nodes by hand, the right numbers to use -will be in the /sys/class/tty/ttyGS0/dev file. - -When you link this gadget driver early, perhaps even statically, -you may want to set up an /etc/inittab entry to run "getty" on it. -The /dev/ttyGS0 line should work like most any other serial port. - - -If gadget serial is loaded as an ACM device you will want to use -either the Windows or Linux ACM driver on the host side. If gadget -serial is loaded as a bulk in/out device, you will want to use the -Linux generic serial driver on the host side. Follow the appropriate -instructions below to install the host side driver. - - -Installing the Windows Host ACM Driver --------------------------------------- -To use the Windows ACM driver you must have the "linux-cdc-acm.inf" -file (provided along this document) which supports all recent versions -of Windows. - -When the gadget serial driver is loaded and the USB device connected -to the Windows host with a USB cable, Windows should recognize the -gadget serial device and ask for a driver. Tell Windows to find the -driver in the folder that contains the "linux-cdc-acm.inf" file. - -For example, on Windows XP, when the gadget serial device is first -plugged in, the "Found New Hardware Wizard" starts up. Select -"Install from a list or specific location (Advanced)", then on the -next screen select "Include this location in the search" and enter the -path or browse to the folder containing the "linux-cdc-acm.inf" file. -Windows will complain that the Gadget Serial driver has not passed -Windows Logo testing, but select "Continue anyway" and finish the -driver installation. - -On Windows XP, in the "Device Manager" (under "Control Panel", -"System", "Hardware") expand the "Ports (COM & LPT)" entry and you -should see "Gadget Serial" listed as the driver for one of the COM -ports. - -To uninstall the Windows XP driver for "Gadget Serial", right click -on the "Gadget Serial" entry in the "Device Manager" and select -"Uninstall". - - -Installing the Linux Host ACM Driver ------------------------------------- -To use the Linux ACM driver you must configure the Linux host side -kernel for "Support for Host-side USB" and for "USB Modem (CDC ACM) -support". - -Once the gadget serial driver is loaded and the USB device connected -to the Linux host with a USB cable, the host system should recognize -the gadget serial device. For example, the command:: - - cat /sys/kernel/debug/usb/devices - -should show something like this::: - - T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 5 Spd=480 MxCh= 0 - D: Ver= 2.00 Cls=02(comm.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 - P: Vendor=0525 ProdID=a4a7 Rev= 2.01 - S: Manufacturer=Linux 2.6.8.1 with net2280 - S: Product=Gadget Serial - S: SerialNumber=0 - C:* #Ifs= 2 Cfg#= 2 Atr=c0 MxPwr= 2mA - I: If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=acm - E: Ad=83(I) Atr=03(Int.) MxPS= 8 Ivl=32ms - I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=acm - E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms - E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms - -If the host side Linux system is configured properly, the ACM driver -should be loaded automatically. The command "lsmod" should show the -"acm" module is loaded. - - -Installing the Linux Host Generic USB Serial Driver ---------------------------------------------------- -To use the Linux generic USB serial driver you must configure the -Linux host side kernel for "Support for Host-side USB", for "USB -Serial Converter support", and for the "USB Generic Serial Driver". - -Once the gadget serial driver is loaded and the USB device connected -to the Linux host with a USB cable, the host system should recognize -the gadget serial device. For example, the command:: - - cat /sys/kernel/debug/usb/devices - -should show something like this::: - - T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 6 Spd=480 MxCh= 0 - D: Ver= 2.00 Cls=ff(vend.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 - P: Vendor=0525 ProdID=a4a6 Rev= 2.01 - S: Manufacturer=Linux 2.6.8.1 with net2280 - S: Product=Gadget Serial - S: SerialNumber=0 - C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr= 2mA - I: If#= 0 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=serial - E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms - E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms - -You must load the usbserial driver and explicitly set its parameters -to configure it to recognize the gadget serial device, like this:: - - echo 0x0525 0xA4A6 >/sys/bus/usb-serial/drivers/generic/new_id - -The legacy way is to use module parameters:: - - modprobe usbserial vendor=0x0525 product=0xA4A6 - -If everything is working, usbserial will print a message in the -system log saying something like "Gadget Serial converter now -attached to ttyUSB0". - - -Testing with Minicom or HyperTerminal -------------------------------------- -Once the gadget serial driver and the host driver are both installed, -and a USB cable connects the gadget device to the host, you should -be able to communicate over USB between the gadget and host systems. -You can use minicom or HyperTerminal to try this out. - -On the gadget side run "minicom -s" to configure a new minicom -session. Under "Serial port setup" set "/dev/ttygserial" as the -"Serial Device". Set baud rate, data bits, parity, and stop bits, -to 9600, 8, none, and 1--these settings mostly do not matter. -Under "Modem and dialing" erase all the modem and dialing strings. - -On a Linux host running the ACM driver, configure minicom similarly -but use "/dev/ttyACM0" as the "Serial Device". (If you have other -ACM devices connected, change the device name appropriately.) - -On a Linux host running the USB generic serial driver, configure -minicom similarly, but use "/dev/ttyUSB0" as the "Serial Device". -(If you have other USB serial devices connected, change the device -name appropriately.) - -On a Windows host configure a new HyperTerminal session to use the -COM port assigned to Gadget Serial. The "Port Settings" will be -set automatically when HyperTerminal connects to the gadget serial -device, so you can leave them set to the default values--these -settings mostly do not matter. - -With minicom configured and running on the gadget side and with -minicom or HyperTerminal configured and running on the host side, -you should be able to send data back and forth between the gadget -side and host side systems. Anything you type on the terminal -window on the gadget side should appear in the terminal window on -the host side and vice versa. diff --git a/Documentation/usb/index.rst b/Documentation/usb/index.rst new file mode 100644 index 000000000000..e55386a4abfb --- /dev/null +++ b/Documentation/usb/index.rst @@ -0,0 +1,39 @@ +=========== +USB support +=========== + +.. toctree:: + :maxdepth: 1 + + acm + authorization + chipidea + dwc3 + ehci + functionfs + gadget_configfs + gadget_hid + gadget_multi + gadget_printer + gadget_serial + gadget-testing + iuu_phoenix + mass-storage + misc_usbsevseg + mtouchusb + ohci + rio + usbip_protocol + usbmon + usb-serial + wusb-design-overview + + usb-help + text_files + +.. only:: subproject and html + + Indices + ======= + + * :ref:`genindex` diff --git a/Documentation/usb/iuu_phoenix.rst b/Documentation/usb/iuu_phoenix.rst new file mode 100644 index 000000000000..b76268728450 --- /dev/null +++ b/Documentation/usb/iuu_phoenix.rst @@ -0,0 +1,94 @@ +============================= +Infinity Usb Unlimited Readme +============================= + +Hi all, + + +This module provide a serial interface to use your +IUU unit in phoenix mode. Loading this module will +bring a ttyUSB[0-x] interface. This driver must be +used by your favorite application to pilot the IUU + +This driver is still in beta stage, so bugs can +occur and your system may freeze. As far I now, +I never had any problem with it, but I'm not a real +guru, so don't blame me if your system is unstable + +You can plug more than one IUU. Every unit will +have his own device file(/dev/ttyUSB0,/dev/ttyUSB1,...) + + + +How to tune the reader speed? +============================= + + A few parameters can be used at load time + To use parameters, just unload the module if it is + already loaded and use modprobe iuu_phoenix param=value. + In case of prebuilt module, use the command + insmod iuu_phoenix param=value. + + Example:: + + modprobe iuu_phoenix clockmode=3 + + The parameters are: + +clockmode: + 1=3Mhz579,2=3Mhz680,3=6Mhz (int) +boost: + overclock boost percent 100 to 500 (int) +cdmode: + Card detect mode + 0=none, 1=CD, 2=!CD, 3=DSR, 4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING (int) +xmas: + xmas color enabled or not (bool) +debug: + Debug enabled or not (bool) + +- clockmode will provide 3 different base settings commonly adopted by + different software: + + 1. 3Mhz579 + 2. 3Mhz680 + 3. 6Mhz + +- boost provide a way to overclock the reader ( my favorite :-) ) + For example to have best performance than a simple clockmode=3, try this:: + + modprobe boost=195 + + This will put the reader in a base of 3Mhz579 but boosted a 195 % ! + the real clock will be now : 6979050 Hz ( 6Mhz979 ) and will increase + the speed to a score 10 to 20% better than the simple clockmode=3 !!! + + +- cdmode permit to setup the signal used to inform the userland ( ioctl answer ) + if the card is present or not. Eight signals are possible. + +- xmas is completely useless except for your eyes. This is one of my friend who was + so sad to have a nice device like the iuu without seeing all color range available. + So I have added this option to permit him to see a lot of color ( each activity change the color + and the frequency randomly ) + +- debug will produce a lot of debugging messages... + + +Last notes +========== + + Don't worry about the serial settings, the serial emulation + is an abstraction, so use any speed or parity setting will + work. ( This will not change anything ).Later I will perhaps + use this settings to deduce de boost but is that feature + really necessary ? + The autodetect feature used is the serial CD. If that doesn't + work for your software, disable detection mechanism in it. + + + Have fun ! + + Alain Degreffe + + eczema(at)ecze.com diff --git a/Documentation/usb/iuu_phoenix.txt b/Documentation/usb/iuu_phoenix.txt deleted file mode 100644 index b76268728450..000000000000 --- a/Documentation/usb/iuu_phoenix.txt +++ /dev/null @@ -1,94 +0,0 @@ -============================= -Infinity Usb Unlimited Readme -============================= - -Hi all, - - -This module provide a serial interface to use your -IUU unit in phoenix mode. Loading this module will -bring a ttyUSB[0-x] interface. This driver must be -used by your favorite application to pilot the IUU - -This driver is still in beta stage, so bugs can -occur and your system may freeze. As far I now, -I never had any problem with it, but I'm not a real -guru, so don't blame me if your system is unstable - -You can plug more than one IUU. Every unit will -have his own device file(/dev/ttyUSB0,/dev/ttyUSB1,...) - - - -How to tune the reader speed? -============================= - - A few parameters can be used at load time - To use parameters, just unload the module if it is - already loaded and use modprobe iuu_phoenix param=value. - In case of prebuilt module, use the command - insmod iuu_phoenix param=value. - - Example:: - - modprobe iuu_phoenix clockmode=3 - - The parameters are: - -clockmode: - 1=3Mhz579,2=3Mhz680,3=6Mhz (int) -boost: - overclock boost percent 100 to 500 (int) -cdmode: - Card detect mode - 0=none, 1=CD, 2=!CD, 3=DSR, 4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING (int) -xmas: - xmas color enabled or not (bool) -debug: - Debug enabled or not (bool) - -- clockmode will provide 3 different base settings commonly adopted by - different software: - - 1. 3Mhz579 - 2. 3Mhz680 - 3. 6Mhz - -- boost provide a way to overclock the reader ( my favorite :-) ) - For example to have best performance than a simple clockmode=3, try this:: - - modprobe boost=195 - - This will put the reader in a base of 3Mhz579 but boosted a 195 % ! - the real clock will be now : 6979050 Hz ( 6Mhz979 ) and will increase - the speed to a score 10 to 20% better than the simple clockmode=3 !!! - - -- cdmode permit to setup the signal used to inform the userland ( ioctl answer ) - if the card is present or not. Eight signals are possible. - -- xmas is completely useless except for your eyes. This is one of my friend who was - so sad to have a nice device like the iuu without seeing all color range available. - So I have added this option to permit him to see a lot of color ( each activity change the color - and the frequency randomly ) - -- debug will produce a lot of debugging messages... - - -Last notes -========== - - Don't worry about the serial settings, the serial emulation - is an abstraction, so use any speed or parity setting will - work. ( This will not change anything ).Later I will perhaps - use this settings to deduce de boost but is that feature - really necessary ? - The autodetect feature used is the serial CD. If that doesn't - work for your software, disable detection mechanism in it. - - - Have fun ! - - Alain Degreffe - - eczema(at)ecze.com diff --git a/Documentation/usb/mass-storage.rst b/Documentation/usb/mass-storage.rst new file mode 100644 index 000000000000..d181b47c3cb6 --- /dev/null +++ b/Documentation/usb/mass-storage.rst @@ -0,0 +1,234 @@ +========================= +Mass Storage Gadget (MSG) +========================= + +Overview +======== + + Mass Storage Gadget (or MSG) acts as a USB Mass Storage device, + appearing to the host as a disk or a CD-ROM drive. It supports + multiple logical units (LUNs). Backing storage for each LUN is + provided by a regular file or a block device, access can be limited + to read-only, and gadget can indicate that it is removable and/or + CD-ROM (the latter implies read-only access). + + Its requirements are modest; only a bulk-in and a bulk-out endpoint + are needed. The memory requirement amounts to two 16K buffers. + Support is included for full-speed, high-speed and SuperSpeed + operation. + + Note that the driver is slightly non-portable in that it assumes + a single memory/DMA buffer will be usable for bulk-in and bulk-out + endpoints. With most device controllers this is not an issue, but + there may be some with hardware restrictions that prevent a buffer + from being used by more than one endpoint. + + This document describes how to use the gadget from user space, its + relation to mass storage function (or MSF) and different gadgets + using it, and how it differs from File Storage Gadget (or FSG) + (which is no longer included in Linux). It will talk only briefly + about how to use MSF within composite gadgets. + +Module parameters +================= + + The mass storage gadget accepts the following mass storage specific + module parameters: + + - file=filename[,filename...] + + This parameter lists paths to files or block devices used for + backing storage for each logical unit. There may be at most + FSG_MAX_LUNS (8) LUNs set. If more files are specified, they will + be silently ignored. See also “luns” parameter. + + *BEWARE* that if a file is used as a backing storage, it may not + be modified by any other process. This is because the host + assumes the data does not change without its knowledge. It may be + read, but (if the logical unit is writable) due to buffering on + the host side, the contents are not well defined. + + The size of the logical unit will be rounded down to a full + logical block. The logical block size is 2048 bytes for LUNs + simulating CD-ROM, block size of the device if the backing file is + a block device, or 512 bytes otherwise. + + - removable=b[,b...] + + This parameter specifies whether each logical unit should be + removable. “b” here is either “y”, “Y” or “1” for true or “n”, + “N” or “0” for false. + + If this option is set for a logical unit, gadget will accept an + “eject” SCSI request (Start/Stop Unit). When it is sent, the + backing file will be closed to simulate ejection and the logical + unit will not be mountable by the host until a new backing file is + specified by userspace on the device (see “sysfs entries” + section). + + If a logical unit is not removable (the default), a backing file + must be specified for it with the “file” parameter as the module + is loaded. The same applies if the module is built in, no + exceptions. + + The default value of the flag is false, *HOWEVER* it used to be + true. This has been changed to better match File Storage Gadget + and because it seems like a saner default after all. Thus to + maintain compatibility with older kernels, it's best to specify + the default values. Also, if one relied on old default, explicit + “n” needs to be specified now. + + Note that “removable” means the logical unit's media can be + ejected or removed (as is true for a CD-ROM drive or a card + reader). It does *not* mean that the entire gadget can be + unplugged from the host; the proper term for that is + “hot-unpluggable”. + + - cdrom=b[,b...] + + This parameter specifies whether each logical unit should simulate + CD-ROM. The default is false. + + - ro=b[,b...] + + This parameter specifies whether each logical unit should be + reported as read only. This will prevent host from modifying the + backing files. + + Note that if this flag for given logical unit is false but the + backing file could not be opened in read/write mode, the gadget + will fall back to read only mode anyway. + + The default value for non-CD-ROM logical units is false; for + logical units simulating CD-ROM it is forced to true. + + - nofua=b[,b...] + + This parameter specifies whether FUA flag should be ignored in SCSI + Write10 and Write12 commands sent to given logical units. + + MS Windows mounts removable storage in “Removal optimised mode” by + default. All the writes to the media are synchronous, which is + achieved by setting the FUA (Force Unit Access) bit in SCSI + Write(10,12) commands. This forces each write to wait until the + data has actually been written out and prevents I/O requests + aggregation in block layer dramatically decreasing performance. + + Note that this may mean that if the device is powered from USB and + the user unplugs the device without unmounting it first (which at + least some Windows users do), the data may be lost. + + The default value is false. + + - luns=N + + This parameter specifies number of logical units the gadget will + have. It is limited by FSG_MAX_LUNS (8) and higher value will be + capped. + + If this parameter is provided, and the number of files specified + in “file” argument is greater then the value of “luns”, all excess + files will be ignored. + + If this parameter is not present, the number of logical units will + be deduced from the number of files specified in the “file” + parameter. If the file parameter is missing as well, one is + assumed. + + - stall=b + + Specifies whether the gadget is allowed to halt bulk endpoints. + The default is determined according to the type of USB device + controller, but usually true. + + In addition to the above, the gadget also accepts the following + parameters defined by the composite framework (they are common to + all composite gadgets so just a quick listing): + + - idVendor -- USB Vendor ID (16 bit integer) + - idProduct -- USB Product ID (16 bit integer) + - bcdDevice -- USB Device version (BCD) (16 bit integer) + - iManufacturer -- USB Manufacturer string (string) + - iProduct -- USB Product string (string) + - iSerialNumber -- SerialNumber string (sting) + +sysfs entries +============= + + For each logical unit, the gadget creates a directory in the sysfs + hierarchy. Inside of it the following three files are created: + + - file + + When read it returns the path to the backing file for the given + logical unit. If there is no backing file (possible only if the + logical unit is removable), the content is empty. + + When written into, it changes the backing file for given logical + unit. This change can be performed even if given logical unit is + not specified as removable (but that may look strange to the + host). It may fail, however, if host disallowed medium removal + with the Prevent-Allow Medium Removal SCSI command. + + - ro + + Reflects the state of ro flag for the given logical unit. It can + be read any time, and written to when there is no backing file + open for given logical unit. + + - nofua + + Reflects the state of nofua flag for given logical unit. It can + be read and written. + + Other then those, as usual, the values of module parameters can be + read from /sys/module/g_mass_storage/parameters/* files. + +Other gadgets using mass storage function +========================================= + + The Mass Storage Gadget uses the Mass Storage Function to handle + mass storage protocol. As a composite function, MSF may be used by + other gadgets as well (eg. g_multi and acm_ms). + + All of the information in previous sections are valid for other + gadgets using MSF, except that support for mass storage related + module parameters may be missing, or the parameters may have + a prefix. To figure out whether any of this is true one needs to + consult the gadget's documentation or its source code. + + For examples of how to include mass storage function in gadgets, one + may take a look at mass_storage.c, acm_ms.c and multi.c (sorted by + complexity). + +Relation to file storage gadget +=============================== + + The Mass Storage Function and thus the Mass Storage Gadget has been + based on the File Storage Gadget. The difference between the two is + that MSG is a composite gadget (ie. uses the composite framework) + while file storage gadget was a traditional gadget. From userspace + point of view this distinction does not really matter, but from + kernel hacker's point of view, this means that (i) MSG does not + duplicate code needed for handling basic USB protocol commands and + (ii) MSF can be used in any other composite gadget. + + Because of that, File Storage Gadget has been removed in Linux 3.8. + All users need to transition to the Mass Storage Gadget. The two + gadgets behave mostly the same from the outside except: + + 1. In FSG the “removable” and “cdrom” module parameters set the flag + for all logical units whereas in MSG they accept a list of y/n + values for each logical unit. If one uses only a single logical + unit this does not matter, but if there are more, the y/n value + needs to be repeated for each logical unit. + + 2. FSG's “serial”, “vendor”, “product” and “release” module + parameters are handled in MSG by the composite layer's parameters + named respectively: “iSerialnumber”, “idVendor”, “idProduct” and + “bcdDevice”. + + 3. MSG does not support FSG's test mode, thus “transport”, + “protocol” and “buflen” FSG's module parameters are not + supported. MSG always uses SCSI protocol with bulk only + transport mode and 16 KiB buffers. diff --git a/Documentation/usb/mass-storage.txt b/Documentation/usb/mass-storage.txt deleted file mode 100644 index d181b47c3cb6..000000000000 --- a/Documentation/usb/mass-storage.txt +++ /dev/null @@ -1,234 +0,0 @@ -========================= -Mass Storage Gadget (MSG) -========================= - -Overview -======== - - Mass Storage Gadget (or MSG) acts as a USB Mass Storage device, - appearing to the host as a disk or a CD-ROM drive. It supports - multiple logical units (LUNs). Backing storage for each LUN is - provided by a regular file or a block device, access can be limited - to read-only, and gadget can indicate that it is removable and/or - CD-ROM (the latter implies read-only access). - - Its requirements are modest; only a bulk-in and a bulk-out endpoint - are needed. The memory requirement amounts to two 16K buffers. - Support is included for full-speed, high-speed and SuperSpeed - operation. - - Note that the driver is slightly non-portable in that it assumes - a single memory/DMA buffer will be usable for bulk-in and bulk-out - endpoints. With most device controllers this is not an issue, but - there may be some with hardware restrictions that prevent a buffer - from being used by more than one endpoint. - - This document describes how to use the gadget from user space, its - relation to mass storage function (or MSF) and different gadgets - using it, and how it differs from File Storage Gadget (or FSG) - (which is no longer included in Linux). It will talk only briefly - about how to use MSF within composite gadgets. - -Module parameters -================= - - The mass storage gadget accepts the following mass storage specific - module parameters: - - - file=filename[,filename...] - - This parameter lists paths to files or block devices used for - backing storage for each logical unit. There may be at most - FSG_MAX_LUNS (8) LUNs set. If more files are specified, they will - be silently ignored. See also “luns” parameter. - - *BEWARE* that if a file is used as a backing storage, it may not - be modified by any other process. This is because the host - assumes the data does not change without its knowledge. It may be - read, but (if the logical unit is writable) due to buffering on - the host side, the contents are not well defined. - - The size of the logical unit will be rounded down to a full - logical block. The logical block size is 2048 bytes for LUNs - simulating CD-ROM, block size of the device if the backing file is - a block device, or 512 bytes otherwise. - - - removable=b[,b...] - - This parameter specifies whether each logical unit should be - removable. “b” here is either “y”, “Y” or “1” for true or “n”, - “N” or “0” for false. - - If this option is set for a logical unit, gadget will accept an - “eject” SCSI request (Start/Stop Unit). When it is sent, the - backing file will be closed to simulate ejection and the logical - unit will not be mountable by the host until a new backing file is - specified by userspace on the device (see “sysfs entries” - section). - - If a logical unit is not removable (the default), a backing file - must be specified for it with the “file” parameter as the module - is loaded. The same applies if the module is built in, no - exceptions. - - The default value of the flag is false, *HOWEVER* it used to be - true. This has been changed to better match File Storage Gadget - and because it seems like a saner default after all. Thus to - maintain compatibility with older kernels, it's best to specify - the default values. Also, if one relied on old default, explicit - “n” needs to be specified now. - - Note that “removable” means the logical unit's media can be - ejected or removed (as is true for a CD-ROM drive or a card - reader). It does *not* mean that the entire gadget can be - unplugged from the host; the proper term for that is - “hot-unpluggable”. - - - cdrom=b[,b...] - - This parameter specifies whether each logical unit should simulate - CD-ROM. The default is false. - - - ro=b[,b...] - - This parameter specifies whether each logical unit should be - reported as read only. This will prevent host from modifying the - backing files. - - Note that if this flag for given logical unit is false but the - backing file could not be opened in read/write mode, the gadget - will fall back to read only mode anyway. - - The default value for non-CD-ROM logical units is false; for - logical units simulating CD-ROM it is forced to true. - - - nofua=b[,b...] - - This parameter specifies whether FUA flag should be ignored in SCSI - Write10 and Write12 commands sent to given logical units. - - MS Windows mounts removable storage in “Removal optimised mode” by - default. All the writes to the media are synchronous, which is - achieved by setting the FUA (Force Unit Access) bit in SCSI - Write(10,12) commands. This forces each write to wait until the - data has actually been written out and prevents I/O requests - aggregation in block layer dramatically decreasing performance. - - Note that this may mean that if the device is powered from USB and - the user unplugs the device without unmounting it first (which at - least some Windows users do), the data may be lost. - - The default value is false. - - - luns=N - - This parameter specifies number of logical units the gadget will - have. It is limited by FSG_MAX_LUNS (8) and higher value will be - capped. - - If this parameter is provided, and the number of files specified - in “file” argument is greater then the value of “luns”, all excess - files will be ignored. - - If this parameter is not present, the number of logical units will - be deduced from the number of files specified in the “file” - parameter. If the file parameter is missing as well, one is - assumed. - - - stall=b - - Specifies whether the gadget is allowed to halt bulk endpoints. - The default is determined according to the type of USB device - controller, but usually true. - - In addition to the above, the gadget also accepts the following - parameters defined by the composite framework (they are common to - all composite gadgets so just a quick listing): - - - idVendor -- USB Vendor ID (16 bit integer) - - idProduct -- USB Product ID (16 bit integer) - - bcdDevice -- USB Device version (BCD) (16 bit integer) - - iManufacturer -- USB Manufacturer string (string) - - iProduct -- USB Product string (string) - - iSerialNumber -- SerialNumber string (sting) - -sysfs entries -============= - - For each logical unit, the gadget creates a directory in the sysfs - hierarchy. Inside of it the following three files are created: - - - file - - When read it returns the path to the backing file for the given - logical unit. If there is no backing file (possible only if the - logical unit is removable), the content is empty. - - When written into, it changes the backing file for given logical - unit. This change can be performed even if given logical unit is - not specified as removable (but that may look strange to the - host). It may fail, however, if host disallowed medium removal - with the Prevent-Allow Medium Removal SCSI command. - - - ro - - Reflects the state of ro flag for the given logical unit. It can - be read any time, and written to when there is no backing file - open for given logical unit. - - - nofua - - Reflects the state of nofua flag for given logical unit. It can - be read and written. - - Other then those, as usual, the values of module parameters can be - read from /sys/module/g_mass_storage/parameters/* files. - -Other gadgets using mass storage function -========================================= - - The Mass Storage Gadget uses the Mass Storage Function to handle - mass storage protocol. As a composite function, MSF may be used by - other gadgets as well (eg. g_multi and acm_ms). - - All of the information in previous sections are valid for other - gadgets using MSF, except that support for mass storage related - module parameters may be missing, or the parameters may have - a prefix. To figure out whether any of this is true one needs to - consult the gadget's documentation or its source code. - - For examples of how to include mass storage function in gadgets, one - may take a look at mass_storage.c, acm_ms.c and multi.c (sorted by - complexity). - -Relation to file storage gadget -=============================== - - The Mass Storage Function and thus the Mass Storage Gadget has been - based on the File Storage Gadget. The difference between the two is - that MSG is a composite gadget (ie. uses the composite framework) - while file storage gadget was a traditional gadget. From userspace - point of view this distinction does not really matter, but from - kernel hacker's point of view, this means that (i) MSG does not - duplicate code needed for handling basic USB protocol commands and - (ii) MSF can be used in any other composite gadget. - - Because of that, File Storage Gadget has been removed in Linux 3.8. - All users need to transition to the Mass Storage Gadget. The two - gadgets behave mostly the same from the outside except: - - 1. In FSG the “removable” and “cdrom” module parameters set the flag - for all logical units whereas in MSG they accept a list of y/n - values for each logical unit. If one uses only a single logical - unit this does not matter, but if there are more, the y/n value - needs to be repeated for each logical unit. - - 2. FSG's “serial”, “vendor”, “product” and “release” module - parameters are handled in MSG by the composite layer's parameters - named respectively: “iSerialnumber”, “idVendor”, “idProduct” and - “bcdDevice”. - - 3. MSG does not support FSG's test mode, thus “transport”, - “protocol” and “buflen” FSG's module parameters are not - supported. MSG always uses SCSI protocol with bulk only - transport mode and 16 KiB buffers. diff --git a/Documentation/usb/misc_usbsevseg.rst b/Documentation/usb/misc_usbsevseg.rst new file mode 100644 index 000000000000..6274aee083ed --- /dev/null +++ b/Documentation/usb/misc_usbsevseg.rst @@ -0,0 +1,51 @@ +============================= +USB 7-Segment Numeric Display +============================= + +Manufactured by Delcom Engineering + +Device Information +------------------ +USB VENDOR_ID 0x0fc5 +USB PRODUCT_ID 0x1227 +Both the 6 character and 8 character displays have PRODUCT_ID, +and according to Delcom Engineering no queryable information +can be obtained from the device to tell them apart. + +Device Modes +------------ +By default, the driver assumes the display is only 6 characters +The mode for 6 characters is: + + MSB 0x06; LSB 0x3f + +For the 8 character display: + + MSB 0x08; LSB 0xff + +The device can accept "text" either in raw, hex, or ascii textmode. +raw controls each segment manually, +hex expects a value between 0-15 per character, +ascii expects a value between '0'-'9' and 'A'-'F'. +The default is ascii. + +Device Operation +---------------- +1. Turn on the device: + echo 1 > /sys/bus/usb/.../powered +2. Set the device's mode: + echo $mode_msb > /sys/bus/usb/.../mode_msb + echo $mode_lsb > /sys/bus/usb/.../mode_lsb +3. Set the textmode: + echo $textmode > /sys/bus/usb/.../textmode +4. set the text (for example): + echo "123ABC" > /sys/bus/usb/.../text (ascii) + echo "A1B2" > /sys/bus/usb/.../text (ascii) + echo -ne "\x01\x02\x03" > /sys/bus/usb/.../text (hex) +5. Set the decimal places. + The device has either 6 or 8 decimal points. + to set the nth decimal place calculate 10 ** n + and echo it in to /sys/bus/usb/.../decimals + To set multiple decimals points sum up each power. + For example, to set the 0th and 3rd decimal place + echo 1001 > /sys/bus/usb/.../decimals diff --git a/Documentation/usb/misc_usbsevseg.txt b/Documentation/usb/misc_usbsevseg.txt deleted file mode 100644 index 6274aee083ed..000000000000 --- a/Documentation/usb/misc_usbsevseg.txt +++ /dev/null @@ -1,51 +0,0 @@ -============================= -USB 7-Segment Numeric Display -============================= - -Manufactured by Delcom Engineering - -Device Information ------------------- -USB VENDOR_ID 0x0fc5 -USB PRODUCT_ID 0x1227 -Both the 6 character and 8 character displays have PRODUCT_ID, -and according to Delcom Engineering no queryable information -can be obtained from the device to tell them apart. - -Device Modes ------------- -By default, the driver assumes the display is only 6 characters -The mode for 6 characters is: - - MSB 0x06; LSB 0x3f - -For the 8 character display: - - MSB 0x08; LSB 0xff - -The device can accept "text" either in raw, hex, or ascii textmode. -raw controls each segment manually, -hex expects a value between 0-15 per character, -ascii expects a value between '0'-'9' and 'A'-'F'. -The default is ascii. - -Device Operation ----------------- -1. Turn on the device: - echo 1 > /sys/bus/usb/.../powered -2. Set the device's mode: - echo $mode_msb > /sys/bus/usb/.../mode_msb - echo $mode_lsb > /sys/bus/usb/.../mode_lsb -3. Set the textmode: - echo $textmode > /sys/bus/usb/.../textmode -4. set the text (for example): - echo "123ABC" > /sys/bus/usb/.../text (ascii) - echo "A1B2" > /sys/bus/usb/.../text (ascii) - echo -ne "\x01\x02\x03" > /sys/bus/usb/.../text (hex) -5. Set the decimal places. - The device has either 6 or 8 decimal points. - to set the nth decimal place calculate 10 ** n - and echo it in to /sys/bus/usb/.../decimals - To set multiple decimals points sum up each power. - For example, to set the 0th and 3rd decimal place - echo 1001 > /sys/bus/usb/.../decimals diff --git a/Documentation/usb/mtouchusb.rst b/Documentation/usb/mtouchusb.rst new file mode 100644 index 000000000000..d1111b74bf75 --- /dev/null +++ b/Documentation/usb/mtouchusb.rst @@ -0,0 +1,84 @@ +================ +mtouchusb driver +================ + +Changes +======= + +- 0.3 - Created based off of scanner & INSTALL from the original touchscreen + driver on freecode (http://freecode.com/projects/3mtouchscreendriver) +- Amended for linux-2.4.18, then 2.4.19 + +- 0.5 - Complete rewrite using Linux Input in 2.6.3 + Unfortunately no calibration support at this time + +- 1.4 - Multiple changes to support the EXII 5000UC and house cleaning + Changed reset from standard USB dev reset to vendor reset + Changed data sent to host from compensated to raw coordinates + Eliminated vendor/product module params + Performed multiple successful tests with an EXII-5010UC + +Supported Hardware +================== + +:: + + All controllers have the Vendor: 0x0596 & Product: 0x0001 + + + Controller Description Part Number + ------------------------------------------------------ + + USB Capacitive - Pearl Case 14-205 (Discontinued) + USB Capacitive - Black Case 14-124 (Discontinued) + USB Capacitive - No Case 14-206 (Discontinued) + + USB Capacitive - Pearl Case EXII-5010UC + USB Capacitive - Black Case EXII-5030UC + USB Capacitive - No Case EXII-5050UC + +Driver Notes +============ + +Installation is simple, you only need to add Linux Input, Linux USB, and the +driver to the kernel. The driver can also be optionally built as a module. + +This driver appears to be one of possible 2 Linux USB Input Touchscreen +drivers. Although 3M produces a binary only driver available for +download, I persist in updating this driver since I would like to use the +touchscreen for embedded apps using QTEmbedded, DirectFB, etc. So I feel the +logical choice is to use Linux Input. + +Currently there is no way to calibrate the device via this driver. Even if +the device could be calibrated, the driver pulls to raw coordinate data from +the controller. This means calibration must be performed within the +userspace. + +The controller screen resolution is now 0 to 16384 for both X and Y reporting +the raw touch data. This is the same for the old and new capacitive USB +controllers. + +Perhaps at some point an abstract function will be placed into evdev so +generic functions like calibrations, resets, and vendor information can be +requested from the userspace (And the drivers would handle the vendor specific +tasks). + +TODO +==== + +Implement a control urb again to handle requests to and from the device +such as calibration, etc once/if it becomes available. + +Disclaimer +========== + +I am not a MicroTouch/3M employee, nor have I ever been. 3M does not support +this driver! If you want touch drivers only supported within X, please go to: + +http://www.3m.com/3MTouchSystems/ + +Thanks +====== + +A huge thank you to 3M Touch Systems for the EXII-5010UC controllers for +testing! diff --git a/Documentation/usb/mtouchusb.txt b/Documentation/usb/mtouchusb.txt deleted file mode 100644 index d1111b74bf75..000000000000 --- a/Documentation/usb/mtouchusb.txt +++ /dev/null @@ -1,84 +0,0 @@ -================ -mtouchusb driver -================ - -Changes -======= - -- 0.3 - Created based off of scanner & INSTALL from the original touchscreen - driver on freecode (http://freecode.com/projects/3mtouchscreendriver) -- Amended for linux-2.4.18, then 2.4.19 - -- 0.5 - Complete rewrite using Linux Input in 2.6.3 - Unfortunately no calibration support at this time - -- 1.4 - Multiple changes to support the EXII 5000UC and house cleaning - Changed reset from standard USB dev reset to vendor reset - Changed data sent to host from compensated to raw coordinates - Eliminated vendor/product module params - Performed multiple successful tests with an EXII-5010UC - -Supported Hardware -================== - -:: - - All controllers have the Vendor: 0x0596 & Product: 0x0001 - - - Controller Description Part Number - ------------------------------------------------------ - - USB Capacitive - Pearl Case 14-205 (Discontinued) - USB Capacitive - Black Case 14-124 (Discontinued) - USB Capacitive - No Case 14-206 (Discontinued) - - USB Capacitive - Pearl Case EXII-5010UC - USB Capacitive - Black Case EXII-5030UC - USB Capacitive - No Case EXII-5050UC - -Driver Notes -============ - -Installation is simple, you only need to add Linux Input, Linux USB, and the -driver to the kernel. The driver can also be optionally built as a module. - -This driver appears to be one of possible 2 Linux USB Input Touchscreen -drivers. Although 3M produces a binary only driver available for -download, I persist in updating this driver since I would like to use the -touchscreen for embedded apps using QTEmbedded, DirectFB, etc. So I feel the -logical choice is to use Linux Input. - -Currently there is no way to calibrate the device via this driver. Even if -the device could be calibrated, the driver pulls to raw coordinate data from -the controller. This means calibration must be performed within the -userspace. - -The controller screen resolution is now 0 to 16384 for both X and Y reporting -the raw touch data. This is the same for the old and new capacitive USB -controllers. - -Perhaps at some point an abstract function will be placed into evdev so -generic functions like calibrations, resets, and vendor information can be -requested from the userspace (And the drivers would handle the vendor specific -tasks). - -TODO -==== - -Implement a control urb again to handle requests to and from the device -such as calibration, etc once/if it becomes available. - -Disclaimer -========== - -I am not a MicroTouch/3M employee, nor have I ever been. 3M does not support -this driver! If you want touch drivers only supported within X, please go to: - -http://www.3m.com/3MTouchSystems/ - -Thanks -====== - -A huge thank you to 3M Touch Systems for the EXII-5010UC controllers for -testing! diff --git a/Documentation/usb/ohci.rst b/Documentation/usb/ohci.rst new file mode 100644 index 000000000000..bb3c49719e6b --- /dev/null +++ b/Documentation/usb/ohci.rst @@ -0,0 +1,35 @@ +==== +OHCI +==== + +23-Aug-2002 + +The "ohci-hcd" driver is a USB Host Controller Driver (HCD) that is derived +from the "usb-ohci" driver from the 2.4 kernel series. The "usb-ohci" code +was written primarily by Roman Weissgaerber but with +contributions from many others (read its copyright/licencing header). + +It supports the "Open Host Controller Interface" (OHCI), which standardizes +hardware register protocols used to talk to USB 1.1 host controllers. As +compared to the earlier "Universal Host Controller Interface" (UHCI) from +Intel, it pushes more intelligence into the hardware. USB 1.1 controllers +from vendors other than Intel and VIA generally use OHCI. + +Changes since the 2.4 kernel include + + - improved robustness; bugfixes; and less overhead + - supports the updated and simplified usbcore APIs + - interrupt transfers can be larger, and can be queued + - less code, by using the upper level "hcd" framework + - supports some non-PCI implementations of OHCI + - ... more + +The "ohci-hcd" driver handles all USB 1.1 transfer types. Transfers of all +types can be queued. That was also true in "usb-ohci", except for interrupt +transfers. Previously, using periods of one frame would risk data loss due +to overhead in IRQ processing. When interrupt transfers are queued, those +risks can be minimized by making sure the hardware always has transfers to +work on while the OS is getting around to the relevant IRQ processing. + +- David Brownell + diff --git a/Documentation/usb/ohci.txt b/Documentation/usb/ohci.txt deleted file mode 100644 index bb3c49719e6b..000000000000 --- a/Documentation/usb/ohci.txt +++ /dev/null @@ -1,35 +0,0 @@ -==== -OHCI -==== - -23-Aug-2002 - -The "ohci-hcd" driver is a USB Host Controller Driver (HCD) that is derived -from the "usb-ohci" driver from the 2.4 kernel series. The "usb-ohci" code -was written primarily by Roman Weissgaerber but with -contributions from many others (read its copyright/licencing header). - -It supports the "Open Host Controller Interface" (OHCI), which standardizes -hardware register protocols used to talk to USB 1.1 host controllers. As -compared to the earlier "Universal Host Controller Interface" (UHCI) from -Intel, it pushes more intelligence into the hardware. USB 1.1 controllers -from vendors other than Intel and VIA generally use OHCI. - -Changes since the 2.4 kernel include - - - improved robustness; bugfixes; and less overhead - - supports the updated and simplified usbcore APIs - - interrupt transfers can be larger, and can be queued - - less code, by using the upper level "hcd" framework - - supports some non-PCI implementations of OHCI - - ... more - -The "ohci-hcd" driver handles all USB 1.1 transfer types. Transfers of all -types can be queued. That was also true in "usb-ohci", except for interrupt -transfers. Previously, using periods of one frame would risk data loss due -to overhead in IRQ processing. When interrupt transfers are queued, those -risks can be minimized by making sure the hardware always has transfers to -work on while the OS is getting around to the relevant IRQ processing. - -- David Brownell - diff --git a/Documentation/usb/rio.rst b/Documentation/usb/rio.rst new file mode 100644 index 000000000000..ea73475471db --- /dev/null +++ b/Documentation/usb/rio.rst @@ -0,0 +1,109 @@ +============ +Diamonds Rio +============ + +Copyright (C) 1999, 2000 Bruce Tenison + +Portions Copyright (C) 1999, 2000 David Nelson + +Thanks to David Nelson for guidance and the usage of the scanner.txt +and scanner.c files to model our driver and this informative file. + +Mar. 2, 2000 + +Changes +======= + +- Initial Revision + + +Overview +======== + +This README will address issues regarding how to configure the kernel +to access a RIO 500 mp3 player. +Before I explain how to use this to access the Rio500 please be warned: + +.. warning:: + + Please note that this software is still under development. The authors + are in no way responsible for any damage that may occur, no matter how + inconsequential. + +It seems that the Rio has a problem when sending .mp3 with low batteries. +I suggest when the batteries are low and you want to transfer stuff that you +replace it with a fresh one. In my case, what happened is I lost two 16kb +blocks (they are no longer usable to store information to it). But I don't +know if that's normal or not; it could simply be a problem with the flash +memory. + +In an extreme case, I left my Rio playing overnight and the batteries wore +down to nothing and appear to have corrupted the flash memory. My RIO +needed to be replaced as a result. Diamond tech support is aware of the +problem. Do NOT allow your batteries to wear down to nothing before +changing them. It appears RIO 500 firmware does not handle low battery +power well at all. + +On systems with OHCI controllers, the kernel OHCI code appears to have +power on problems with some chipsets. If you are having problems +connecting to your RIO 500, try turning it on first and then plugging it +into the USB cable. + +Contact Information +------------------- + + The main page for the project is hosted at sourceforge.net in the following + URL: . You can also go to the project's + sourceforge home page at: . + There is also a mailing list: rio500-users@lists.sourceforge.net + +Authors +------- + +Most of the code was written by Cesar Miquel . Keith +Clayton is incharge of the PPC port and making sure +things work there. Bruce Tenison is adding support +for .fon files and also does testing. The program will mostly sure be +re-written and Pete Ikusz along with the rest will re-design it. I would +also like to thank Tri Nguyen who provided use +with some important information regarding the communication with the Rio. + +Additional Information and userspace tools + + http://rio500.sourceforge.net/ + + +Requirements +============ + +A host with a USB port running a Linux kernel with RIO 500 support enabled. + +The driver is a module called rio500, which should be automatically loaded +as you plug in your device. If that fails you can manually load it with + + modprobe rio500 + +Udev should automatically create a device node as soon as plug in your device. +If that fails, you can manually add a device for the USB rio500:: + + mknod /dev/usb/rio500 c 180 64 + +In that case, set appropriate permissions for /dev/usb/rio500 (don't forget +about group and world permissions). Both read and write permissions are +required for proper operation. + +That's it. The Rio500 Utils at: http://rio500.sourceforge.net should +be able to access the rio500. + +Limits +====== + +You can use only a single rio500 device at a time with your computer. + +Bugs +==== + +If you encounter any problems feel free to drop me an email. + +Bruce Tenison +btenison@dibbs.net diff --git a/Documentation/usb/rio.txt b/Documentation/usb/rio.txt deleted file mode 100644 index ea73475471db..000000000000 --- a/Documentation/usb/rio.txt +++ /dev/null @@ -1,109 +0,0 @@ -============ -Diamonds Rio -============ - -Copyright (C) 1999, 2000 Bruce Tenison - -Portions Copyright (C) 1999, 2000 David Nelson - -Thanks to David Nelson for guidance and the usage of the scanner.txt -and scanner.c files to model our driver and this informative file. - -Mar. 2, 2000 - -Changes -======= - -- Initial Revision - - -Overview -======== - -This README will address issues regarding how to configure the kernel -to access a RIO 500 mp3 player. -Before I explain how to use this to access the Rio500 please be warned: - -.. warning:: - - Please note that this software is still under development. The authors - are in no way responsible for any damage that may occur, no matter how - inconsequential. - -It seems that the Rio has a problem when sending .mp3 with low batteries. -I suggest when the batteries are low and you want to transfer stuff that you -replace it with a fresh one. In my case, what happened is I lost two 16kb -blocks (they are no longer usable to store information to it). But I don't -know if that's normal or not; it could simply be a problem with the flash -memory. - -In an extreme case, I left my Rio playing overnight and the batteries wore -down to nothing and appear to have corrupted the flash memory. My RIO -needed to be replaced as a result. Diamond tech support is aware of the -problem. Do NOT allow your batteries to wear down to nothing before -changing them. It appears RIO 500 firmware does not handle low battery -power well at all. - -On systems with OHCI controllers, the kernel OHCI code appears to have -power on problems with some chipsets. If you are having problems -connecting to your RIO 500, try turning it on first and then plugging it -into the USB cable. - -Contact Information -------------------- - - The main page for the project is hosted at sourceforge.net in the following - URL: . You can also go to the project's - sourceforge home page at: . - There is also a mailing list: rio500-users@lists.sourceforge.net - -Authors -------- - -Most of the code was written by Cesar Miquel . Keith -Clayton is incharge of the PPC port and making sure -things work there. Bruce Tenison is adding support -for .fon files and also does testing. The program will mostly sure be -re-written and Pete Ikusz along with the rest will re-design it. I would -also like to thank Tri Nguyen who provided use -with some important information regarding the communication with the Rio. - -Additional Information and userspace tools - - http://rio500.sourceforge.net/ - - -Requirements -============ - -A host with a USB port running a Linux kernel with RIO 500 support enabled. - -The driver is a module called rio500, which should be automatically loaded -as you plug in your device. If that fails you can manually load it with - - modprobe rio500 - -Udev should automatically create a device node as soon as plug in your device. -If that fails, you can manually add a device for the USB rio500:: - - mknod /dev/usb/rio500 c 180 64 - -In that case, set appropriate permissions for /dev/usb/rio500 (don't forget -about group and world permissions). Both read and write permissions are -required for proper operation. - -That's it. The Rio500 Utils at: http://rio500.sourceforge.net should -be able to access the rio500. - -Limits -====== - -You can use only a single rio500 device at a time with your computer. - -Bugs -==== - -If you encounter any problems feel free to drop me an email. - -Bruce Tenison -btenison@dibbs.net diff --git a/Documentation/usb/text_files.rst b/Documentation/usb/text_files.rst new file mode 100644 index 000000000000..6a8d3fcf64b6 --- /dev/null +++ b/Documentation/usb/text_files.rst @@ -0,0 +1,29 @@ +Linux CDC ACM inf +----------------- + +.. include:: linux-cdc-acm.inf + :literal: + +Linux inf +--------- + +.. include:: linux.inf + :literal: + +USB devfs drop permissions source +--------------------------------- + +.. literalinclude:: usbdevfs-drop-permissions.c + :language: c + +WUSB command line script to manipulate auth credentials +------------------------------------------------------- + +.. literalinclude:: wusb-cbaf + :language: shell + +Credits +------- + +.. include:: CREDITS + :literal: diff --git a/Documentation/usb/usb-help.rst b/Documentation/usb/usb-help.rst new file mode 100644 index 000000000000..dc23ecd4d802 --- /dev/null +++ b/Documentation/usb/usb-help.rst @@ -0,0 +1,17 @@ +============== +USB references +============== + +2008-Mar-7 + +For USB help other than the readme files that are located in +`Documentation/usb/*`, see the following: + +- Linux-USB project: http://www.linux-usb.org + mirrors at http://usb.in.tum.de/linux-usb/ + and http://it.linux-usb.org +- Linux USB Guide: http://linux-usb.sourceforge.net +- Linux-USB device overview (working devices and drivers): + http://www.qbik.ch/usb/devices/ + +The Linux-USB mailing list is at linux-usb@vger.kernel.org diff --git a/Documentation/usb/usb-help.txt b/Documentation/usb/usb-help.txt deleted file mode 100644 index dc23ecd4d802..000000000000 --- a/Documentation/usb/usb-help.txt +++ /dev/null @@ -1,17 +0,0 @@ -============== -USB references -============== - -2008-Mar-7 - -For USB help other than the readme files that are located in -`Documentation/usb/*`, see the following: - -- Linux-USB project: http://www.linux-usb.org - mirrors at http://usb.in.tum.de/linux-usb/ - and http://it.linux-usb.org -- Linux USB Guide: http://linux-usb.sourceforge.net -- Linux-USB device overview (working devices and drivers): - http://www.qbik.ch/usb/devices/ - -The Linux-USB mailing list is at linux-usb@vger.kernel.org diff --git a/Documentation/usb/usb-serial.rst b/Documentation/usb/usb-serial.rst new file mode 100644 index 000000000000..8fa7dbd3da9a --- /dev/null +++ b/Documentation/usb/usb-serial.rst @@ -0,0 +1,537 @@ +========== +USB serial +========== + +Introduction +============ + + The USB serial driver currently supports a number of different USB to + serial converter products, as well as some devices that use a serial + interface from userspace to talk to the device. + + See the individual product section below for specific information about + the different devices. + + +Configuration +============= + + Currently the driver can handle up to 256 different serial interfaces at + one time. + + The major number that the driver uses is 188 so to use the driver, + create the following nodes:: + + mknod /dev/ttyUSB0 c 188 0 + mknod /dev/ttyUSB1 c 188 1 + mknod /dev/ttyUSB2 c 188 2 + mknod /dev/ttyUSB3 c 188 3 + . + . + . + mknod /dev/ttyUSB254 c 188 254 + mknod /dev/ttyUSB255 c 188 255 + + When the device is connected and recognized by the driver, the driver + will print to the system log, which node(s) the device has been bound + to. + + +Specific Devices Supported +========================== + + +ConnectTech WhiteHEAT 4 port converter +-------------------------------------- + + ConnectTech has been very forthcoming with information about their + device, including providing a unit to test with. + + The driver is officially supported by Connect Tech Inc. + http://www.connecttech.com + + For any questions or problems with this driver, please contact + Connect Tech's Support Department at support@connecttech.com + + +HandSpring Visor, Palm USB, and Clié USB driver +----------------------------------------------- + + This driver works with all HandSpring USB, Palm USB, and Sony Clié USB + devices. + + Only when the device tries to connect to the host, will the device show + up to the host as a valid USB device. When this happens, the device is + properly enumerated, assigned a port, and then communication _should_ be + possible. The driver cleans up properly when the device is removed, or + the connection is canceled on the device. + + NOTE: + This means that in order to talk to the device, the sync button must be + pressed BEFORE trying to get any program to communicate to the device. + This goes against the current documentation for pilot-xfer and other + packages, but is the only way that it will work due to the hardware + in the device. + + When the device is connected, try talking to it on the second port + (this is usually /dev/ttyUSB1 if you do not have any other usb-serial + devices in the system.) The system log should tell you which port is + the port to use for the HotSync transfer. The "Generic" port can be used + for other device communication, such as a PPP link. + + For some Sony Clié devices, /dev/ttyUSB0 must be used to talk to the + device. This is true for all OS version 3.5 devices, and most devices + that have had a flash upgrade to a newer version of the OS. See the + kernel system log for information on which is the correct port to use. + + If after pressing the sync button, nothing shows up in the system log, + try resetting the device, first a hot reset, and then a cold reset if + necessary. Some devices need this before they can talk to the USB port + properly. + + Devices that are not compiled into the kernel can be specified with module + parameters. e.g. modprobe visor vendor=0x54c product=0x66 + + There is a webpage and mailing lists for this portion of the driver at: + http://sourceforge.net/projects/usbvisor/ + + For any questions or problems with this driver, please contact Greg + Kroah-Hartman at greg@kroah.com + + +PocketPC PDA Driver +------------------- + + This driver can be used to connect to Compaq iPAQ, HP Jornada, Casio EM500 + and other PDAs running Windows CE 3.0 or PocketPC 2002 using a USB + cable/cradle. + Most devices supported by ActiveSync are supported out of the box. + For others, please use module parameters to specify the product and vendor + id. e.g. modprobe ipaq vendor=0x3f0 product=0x1125 + + The driver presents a serial interface (usually on /dev/ttyUSB0) over + which one may run ppp and establish a TCP/IP link to the PDA. Once this + is done, you can transfer files, backup, download email etc. The most + significant advantage of using USB is speed - I can get 73 to 113 + kbytes/sec for download/upload to my iPAQ. + + This driver is only one of a set of components required to utilize + the USB connection. Please visit http://synce.sourceforge.net which + contains the necessary packages and a simple step-by-step howto. + + Once connected, you can use Win CE programs like ftpView, Pocket Outlook + from the PDA and xcerdisp, synce utilities from the Linux side. + + To use Pocket IE, follow the instructions given at + http://www.tekguru.co.uk/EM500/usbtonet.htm to achieve the same thing + on Win98. Omit the proxy server part; Linux is quite capable of forwarding + packets unlike Win98. Another modification is required at least for the + iPAQ - disable autosync by going to the Start/Settings/Connections menu + and unchecking the "Automatically synchronize ..." box. Go to + Start/Programs/Connections, connect the cable and select "usbdial" (or + whatever you named your new USB connection). You should finally wind + up with a "Connected to usbdial" window with status shown as connected. + Now start up PIE and browse away. + + If it doesn't work for some reason, load both the usbserial and ipaq module + with the module parameter "debug" set to 1 and examine the system log. + You can also try soft-resetting your PDA before attempting a connection. + + Other functionality may be possible depending on your PDA. According to + Wes Cilldhaire , with the Toshiba E570, + ...if you boot into the bootloader (hold down the power when hitting the + reset button, continuing to hold onto the power until the bootloader screen + is displayed), then put it in the cradle with the ipaq driver loaded, open + a terminal on /dev/ttyUSB0, it gives you a "USB Reflash" terminal, which can + be used to flash the ROM, as well as the microP code.. so much for needing + Toshiba's $350 serial cable for flashing!! :D + NOTE: This has NOT been tested. Use at your own risk. + + For any questions or problems with the driver, please contact Ganesh + Varadarajan + + +Keyspan PDA Serial Adapter +-------------------------- + + Single port DB-9 serial adapter, pushed as a PDA adapter for iMacs (mostly + sold in Macintosh catalogs, comes in a translucent white/green dongle). + Fairly simple device. Firmware is homebrew. + This driver also works for the Xircom/Entrega single port serial adapter. + + Current status: + + Things that work: + - basic input/output (tested with 'cu') + - blocking write when serial line can't keep up + - changing baud rates (up to 115200) + - getting/setting modem control pins (TIOCM{GET,SET,BIS,BIC}) + - sending break (although duration looks suspect) + + Things that don't: + - device strings (as logged by kernel) have trailing binary garbage + - device ID isn't right, might collide with other Keyspan products + - changing baud rates ought to flush tx/rx to avoid mangled half characters + + Big Things on the todo list: + - parity, 7 vs 8 bits per char, 1 or 2 stop bits + - HW flow control + - not all of the standard USB descriptors are handled: + Get_Status, Set_Feature, O_NONBLOCK, select() + + For any questions or problems with this driver, please contact Brian + Warner at warner@lothar.com + + +Keyspan USA-series Serial Adapters +---------------------------------- + + Single, Dual and Quad port adapters - driver uses Keyspan supplied + firmware and is being developed with their support. + + Current status: + + The USA-18X, USA-28X, USA-19, USA-19W and USA-49W are supported and + have been pretty thoroughly tested at various baud rates with 8-N-1 + character settings. Other character lengths and parity setups are + presently untested. + + The USA-28 isn't yet supported though doing so should be pretty + straightforward. Contact the maintainer if you require this + functionality. + + More information is available at: + + http://www.carnationsoftware.com/carnation/Keyspan.html + + For any questions or problems with this driver, please contact Hugh + Blemings at hugh@misc.nu + + +FTDI Single Port Serial Driver +------------------------------ + + This is a single port DB-25 serial adapter. + + Devices supported include: + + - TripNav TN-200 USB GPS + - Navis Engineering Bureau CH-4711 USB GPS + + For any questions or problems with this driver, please contact Bill Ryder. + + +ZyXEL omni.net lcd plus ISDN TA +------------------------------- + + This is an ISDN TA. Please report both successes and troubles to + azummo@towertech.it + + +Cypress M8 CY4601 Family Serial Driver +-------------------------------------- + + This driver was in most part developed by Neil "koyama" Whelchel. It + has been improved since that previous form to support dynamic serial + line settings and improved line handling. The driver is for the most + part stable and has been tested on an smp machine. (dual p2) + + Chipsets supported under CY4601 family: + + CY7C63723, CY7C63742, CY7C63743, CY7C64013 + + Devices supported: + + - DeLorme's USB Earthmate GPS (SiRF Star II lp arch) + - Cypress HID->COM RS232 adapter + + Note: + Cypress Semiconductor claims no affiliation with the + hid->com device. + + Most devices using chipsets under the CY4601 family should + work with the driver. As long as they stay true to the CY4601 + usbserial specification. + + Technical notes: + + The Earthmate starts out at 4800 8N1 by default... the driver will + upon start init to this setting. usbserial core provides the rest + of the termios settings, along with some custom termios so that the + output is in proper format and parsable. + + The device can be put into sirf mode by issuing NMEA command:: + + $PSRF100,,,,,*CHECKSUM + $PSRF100,0,9600,8,1,0*0C + + It should then be sufficient to change the port termios to match this + to begin communicating. + + As far as I can tell it supports pretty much every sirf command as + documented online available with firmware 2.31, with some unknown + message ids. + + The hid->com adapter can run at a maximum baud of 115200bps. Please note + that the device has trouble or is incapable of raising line voltage properly. + It will be fine with null modem links, as long as you do not try to link two + together without hacking the adapter to set the line high. + + The driver is smp safe. Performance with the driver is rather low when using + it for transferring files. This is being worked on, but I would be willing to + accept patches. An urb queue or packet buffer would likely fit the bill here. + + If you have any questions, problems, patches, feature requests, etc. you can + contact me here via email: + + dignome@gmail.com + + (your problems/patches can alternately be submitted to usb-devel) + + +Digi AccelePort Driver +---------------------- + + This driver supports the Digi AccelePort USB 2 and 4 devices, 2 port + (plus a parallel port) and 4 port USB serial converters. The driver + does NOT yet support the Digi AccelePort USB 8. + + This driver works under SMP with the usb-uhci driver. It does not + work under SMP with the uhci driver. + + The driver is generally working, though we still have a few more ioctls + to implement and final testing and debugging to do. The parallel port + on the USB 2 is supported as a serial to parallel converter; in other + words, it appears as another USB serial port on Linux, even though + physically it is really a parallel port. The Digi Acceleport USB 8 + is not yet supported. + + Please contact Peter Berger (pberger@brimson.com) or Al Borchers + (alborchers@steinerpoint.com) for questions or problems with this + driver. + + +Belkin USB Serial Adapter F5U103 +-------------------------------- + + Single port DB-9/PS-2 serial adapter from Belkin with firmware by eTEK Labs. + The Peracom single port serial adapter also works with this driver, as + well as the GoHubs adapter. + + Current status: + + The following have been tested and work: + + - Baud rate 300-230400 + - Data bits 5-8 + - Stop bits 1-2 + - Parity N,E,O,M,S + - Handshake None, Software (XON/XOFF), Hardware (CTSRTS,CTSDTR) [1]_ + - Break Set and clear + - Line control Input/Output query and control [2]_ + + .. [1] + Hardware input flow control is only enabled for firmware + levels above 2.06. Read source code comments describing Belkin + firmware errata. Hardware output flow control is working for all + firmware versions. + + .. [2] + Queries of inputs (CTS,DSR,CD,RI) show the last + reported state. Queries of outputs (DTR,RTS) show the last + requested state and may not reflect current state as set by + automatic hardware flow control. + + TO DO List: + - Add true modem control line query capability. Currently tracks the + states reported by the interrupt and the states requested. + - Add error reporting back to application for UART error conditions. + - Add support for flush ioctls. + - Add everything else that is missing :) + + For any questions or problems with this driver, please contact William + Greathouse at wgreathouse@smva.com + + +Empeg empeg-car Mark I/II Driver +-------------------------------- + + This is an experimental driver to provide connectivity support for the + client synchronization tools for an Empeg empeg-car mp3 player. + + Tips: + * Don't forget to create the device nodes for ttyUSB{0,1,2,...} + * modprobe empeg (modprobe is your friend) + * emptool --usb /dev/ttyUSB0 (or whatever you named your device node) + + For any questions or problems with this driver, please contact Gary + Brubaker at xavyer@ix.netcom.com + + +MCT USB Single Port Serial Adapter U232 +--------------------------------------- + + This driver is for the MCT USB-RS232 Converter (25 pin, Model No. + U232-P25) from Magic Control Technology Corp. (there is also a 9 pin + Model No. U232-P9). More information about this device can be found at + the manufacturer's web-site: http://www.mct.com.tw. + + The driver is generally working, though it still needs some more testing. + It is derived from the Belkin USB Serial Adapter F5U103 driver and its + TODO list is valid for this driver as well. + + This driver has also been found to work for other products, which have + the same Vendor ID but different Product IDs. Sitecom's U232-P25 serial + converter uses Product ID 0x230 and Vendor ID 0x711 and works with this + driver. Also, D-Link's DU-H3SP USB BAY also works with this driver. + + For any questions or problems with this driver, please contact Wolfgang + Grandegger at wolfgang@ces.ch + + +Inside Out Networks Edgeport Driver +----------------------------------- + + This driver supports all devices made by Inside Out Networks, specifically + the following models: + + - Edgeport/4 + - Rapidport/4 + - Edgeport/4t + - Edgeport/2 + - Edgeport/4i + - Edgeport/2i + - Edgeport/421 + - Edgeport/21 + - Edgeport/8 + - Edgeport/8 Dual + - Edgeport/2D8 + - Edgeport/4D8 + - Edgeport/8i + - Edgeport/2 DIN + - Edgeport/4 DIN + - Edgeport/16 Dual + + For any questions or problems with this driver, please contact Greg + Kroah-Hartman at greg@kroah.com + + +REINER SCT cyberJack pinpad/e-com USB chipcard reader +----------------------------------------------------- + + Interface to ISO 7816 compatible contactbased chipcards, e.g. GSM SIMs. + + Current status: + + This is the kernel part of the driver for this USB card reader. + There is also a user part for a CT-API driver available. A site + for downloading is TBA. For now, you can request it from the + maintainer (linux-usb@sii.li). + + For any questions or problems with this driver, please contact + linux-usb@sii.li + + +Prolific PL2303 Driver +---------------------- + + This driver supports any device that has the PL2303 chip from Prolific + in it. This includes a number of single port USB to serial converters, + more than 70% of USB GPS devices (in 2010), and some USB UPSes. Devices + from Aten (the UC-232) and IO-Data work with this driver, as does + the DCU-11 mobile-phone cable. + + For any questions or problems with this driver, please contact Greg + Kroah-Hartman at greg@kroah.com + + +KL5KUSB105 chipset / PalmConnect USB single-port adapter +-------------------------------------------------------- + +Current status: + + The driver was put together by looking at the usb bus transactions + done by Palm's driver under Windows, so a lot of functionality is + still missing. Notably, serial ioctls are sometimes faked or not yet + implemented. Support for finding out about DSR and CTS line status is + however implemented (though not nicely), so your favorite autopilot(1) + and pilot-manager -daemon calls will work. Baud rates up to 115200 + are supported, but handshaking (software or hardware) is not, which is + why it is wise to cut down on the rate used is wise for large + transfers until this is settled. + + See http://www.uuhaus.de/linux/palmconnect.html for up-to-date + information on this driver. + +Winchiphead CH341 Driver +------------------------ + + This driver is for the Winchiphead CH341 USB-RS232 Converter. This chip + also implements an IEEE 1284 parallel port, I2C and SPI, but that is not + supported by the driver. The protocol was analyzed from the behaviour + of the Windows driver, no datasheet is available at present. + + The manufacturer's website: http://www.winchiphead.com/. + + For any questions or problems with this driver, please contact + frank@kingswood-consulting.co.uk. + +Moschip MCS7720, MCS7715 driver +------------------------------- + + These chips are present in devices sold by various manufacturers, such as Syba + and Cables Unlimited. There may be others. The 7720 provides two serial + ports, and the 7715 provides one serial and one standard PC parallel port. + Support for the 7715's parallel port is enabled by a separate option, which + will not appear unless parallel port support is first enabled at the top-level + of the Device Drivers config menu. Currently only compatibility mode is + supported on the parallel port (no ECP/EPP). + + TODO: + - Implement ECP/EPP modes for the parallel port. + - Baud rates higher than 115200 are currently broken. + - Devices with a single serial port based on the Moschip MCS7703 may work + with this driver with a simple addition to the usb_device_id table. I + don't have one of these devices, so I can't say for sure. + +Generic Serial driver +--------------------- + + If your device is not one of the above listed devices, compatible with + the above models, you can try out the "generic" interface. This + interface does not provide any type of control messages sent to the + device, and does not support any kind of device flow control. All that + is required of your device is that it has at least one bulk in endpoint, + or one bulk out endpoint. + + To enable the generic driver to recognize your device, provide:: + + echo >/sys/bus/usb-serial/drivers/generic/new_id + + where the and is replaced with the hex representation of your + device's vendor id and product id. + If the driver is compiled as a module you can also provide one id when + loading the module:: + + insmod usbserial vendor=0x#### product=0x#### + + This driver has been successfully used to connect to the NetChip USB + development board, providing a way to develop USB firmware without + having to write a custom driver. + + For any questions or problems with this driver, please contact Greg + Kroah-Hartman at greg@kroah.com + + +Contact +======= + + If anyone has any problems using these drivers, with any of the above + specified products, please contact the specific driver's author listed + above, or join the Linux-USB mailing list (information on joining the + mailing list, as well as a link to its searchable archive is at + http://www.linux-usb.org/ ) + + +Greg Kroah-Hartman +greg@kroah.com diff --git a/Documentation/usb/usb-serial.txt b/Documentation/usb/usb-serial.txt deleted file mode 100644 index 8fa7dbd3da9a..000000000000 --- a/Documentation/usb/usb-serial.txt +++ /dev/null @@ -1,537 +0,0 @@ -========== -USB serial -========== - -Introduction -============ - - The USB serial driver currently supports a number of different USB to - serial converter products, as well as some devices that use a serial - interface from userspace to talk to the device. - - See the individual product section below for specific information about - the different devices. - - -Configuration -============= - - Currently the driver can handle up to 256 different serial interfaces at - one time. - - The major number that the driver uses is 188 so to use the driver, - create the following nodes:: - - mknod /dev/ttyUSB0 c 188 0 - mknod /dev/ttyUSB1 c 188 1 - mknod /dev/ttyUSB2 c 188 2 - mknod /dev/ttyUSB3 c 188 3 - . - . - . - mknod /dev/ttyUSB254 c 188 254 - mknod /dev/ttyUSB255 c 188 255 - - When the device is connected and recognized by the driver, the driver - will print to the system log, which node(s) the device has been bound - to. - - -Specific Devices Supported -========================== - - -ConnectTech WhiteHEAT 4 port converter --------------------------------------- - - ConnectTech has been very forthcoming with information about their - device, including providing a unit to test with. - - The driver is officially supported by Connect Tech Inc. - http://www.connecttech.com - - For any questions or problems with this driver, please contact - Connect Tech's Support Department at support@connecttech.com - - -HandSpring Visor, Palm USB, and Clié USB driver ------------------------------------------------ - - This driver works with all HandSpring USB, Palm USB, and Sony Clié USB - devices. - - Only when the device tries to connect to the host, will the device show - up to the host as a valid USB device. When this happens, the device is - properly enumerated, assigned a port, and then communication _should_ be - possible. The driver cleans up properly when the device is removed, or - the connection is canceled on the device. - - NOTE: - This means that in order to talk to the device, the sync button must be - pressed BEFORE trying to get any program to communicate to the device. - This goes against the current documentation for pilot-xfer and other - packages, but is the only way that it will work due to the hardware - in the device. - - When the device is connected, try talking to it on the second port - (this is usually /dev/ttyUSB1 if you do not have any other usb-serial - devices in the system.) The system log should tell you which port is - the port to use for the HotSync transfer. The "Generic" port can be used - for other device communication, such as a PPP link. - - For some Sony Clié devices, /dev/ttyUSB0 must be used to talk to the - device. This is true for all OS version 3.5 devices, and most devices - that have had a flash upgrade to a newer version of the OS. See the - kernel system log for information on which is the correct port to use. - - If after pressing the sync button, nothing shows up in the system log, - try resetting the device, first a hot reset, and then a cold reset if - necessary. Some devices need this before they can talk to the USB port - properly. - - Devices that are not compiled into the kernel can be specified with module - parameters. e.g. modprobe visor vendor=0x54c product=0x66 - - There is a webpage and mailing lists for this portion of the driver at: - http://sourceforge.net/projects/usbvisor/ - - For any questions or problems with this driver, please contact Greg - Kroah-Hartman at greg@kroah.com - - -PocketPC PDA Driver -------------------- - - This driver can be used to connect to Compaq iPAQ, HP Jornada, Casio EM500 - and other PDAs running Windows CE 3.0 or PocketPC 2002 using a USB - cable/cradle. - Most devices supported by ActiveSync are supported out of the box. - For others, please use module parameters to specify the product and vendor - id. e.g. modprobe ipaq vendor=0x3f0 product=0x1125 - - The driver presents a serial interface (usually on /dev/ttyUSB0) over - which one may run ppp and establish a TCP/IP link to the PDA. Once this - is done, you can transfer files, backup, download email etc. The most - significant advantage of using USB is speed - I can get 73 to 113 - kbytes/sec for download/upload to my iPAQ. - - This driver is only one of a set of components required to utilize - the USB connection. Please visit http://synce.sourceforge.net which - contains the necessary packages and a simple step-by-step howto. - - Once connected, you can use Win CE programs like ftpView, Pocket Outlook - from the PDA and xcerdisp, synce utilities from the Linux side. - - To use Pocket IE, follow the instructions given at - http://www.tekguru.co.uk/EM500/usbtonet.htm to achieve the same thing - on Win98. Omit the proxy server part; Linux is quite capable of forwarding - packets unlike Win98. Another modification is required at least for the - iPAQ - disable autosync by going to the Start/Settings/Connections menu - and unchecking the "Automatically synchronize ..." box. Go to - Start/Programs/Connections, connect the cable and select "usbdial" (or - whatever you named your new USB connection). You should finally wind - up with a "Connected to usbdial" window with status shown as connected. - Now start up PIE and browse away. - - If it doesn't work for some reason, load both the usbserial and ipaq module - with the module parameter "debug" set to 1 and examine the system log. - You can also try soft-resetting your PDA before attempting a connection. - - Other functionality may be possible depending on your PDA. According to - Wes Cilldhaire , with the Toshiba E570, - ...if you boot into the bootloader (hold down the power when hitting the - reset button, continuing to hold onto the power until the bootloader screen - is displayed), then put it in the cradle with the ipaq driver loaded, open - a terminal on /dev/ttyUSB0, it gives you a "USB Reflash" terminal, which can - be used to flash the ROM, as well as the microP code.. so much for needing - Toshiba's $350 serial cable for flashing!! :D - NOTE: This has NOT been tested. Use at your own risk. - - For any questions or problems with the driver, please contact Ganesh - Varadarajan - - -Keyspan PDA Serial Adapter --------------------------- - - Single port DB-9 serial adapter, pushed as a PDA adapter for iMacs (mostly - sold in Macintosh catalogs, comes in a translucent white/green dongle). - Fairly simple device. Firmware is homebrew. - This driver also works for the Xircom/Entrega single port serial adapter. - - Current status: - - Things that work: - - basic input/output (tested with 'cu') - - blocking write when serial line can't keep up - - changing baud rates (up to 115200) - - getting/setting modem control pins (TIOCM{GET,SET,BIS,BIC}) - - sending break (although duration looks suspect) - - Things that don't: - - device strings (as logged by kernel) have trailing binary garbage - - device ID isn't right, might collide with other Keyspan products - - changing baud rates ought to flush tx/rx to avoid mangled half characters - - Big Things on the todo list: - - parity, 7 vs 8 bits per char, 1 or 2 stop bits - - HW flow control - - not all of the standard USB descriptors are handled: - Get_Status, Set_Feature, O_NONBLOCK, select() - - For any questions or problems with this driver, please contact Brian - Warner at warner@lothar.com - - -Keyspan USA-series Serial Adapters ----------------------------------- - - Single, Dual and Quad port adapters - driver uses Keyspan supplied - firmware and is being developed with their support. - - Current status: - - The USA-18X, USA-28X, USA-19, USA-19W and USA-49W are supported and - have been pretty thoroughly tested at various baud rates with 8-N-1 - character settings. Other character lengths and parity setups are - presently untested. - - The USA-28 isn't yet supported though doing so should be pretty - straightforward. Contact the maintainer if you require this - functionality. - - More information is available at: - - http://www.carnationsoftware.com/carnation/Keyspan.html - - For any questions or problems with this driver, please contact Hugh - Blemings at hugh@misc.nu - - -FTDI Single Port Serial Driver ------------------------------- - - This is a single port DB-25 serial adapter. - - Devices supported include: - - - TripNav TN-200 USB GPS - - Navis Engineering Bureau CH-4711 USB GPS - - For any questions or problems with this driver, please contact Bill Ryder. - - -ZyXEL omni.net lcd plus ISDN TA -------------------------------- - - This is an ISDN TA. Please report both successes and troubles to - azummo@towertech.it - - -Cypress M8 CY4601 Family Serial Driver --------------------------------------- - - This driver was in most part developed by Neil "koyama" Whelchel. It - has been improved since that previous form to support dynamic serial - line settings and improved line handling. The driver is for the most - part stable and has been tested on an smp machine. (dual p2) - - Chipsets supported under CY4601 family: - - CY7C63723, CY7C63742, CY7C63743, CY7C64013 - - Devices supported: - - - DeLorme's USB Earthmate GPS (SiRF Star II lp arch) - - Cypress HID->COM RS232 adapter - - Note: - Cypress Semiconductor claims no affiliation with the - hid->com device. - - Most devices using chipsets under the CY4601 family should - work with the driver. As long as they stay true to the CY4601 - usbserial specification. - - Technical notes: - - The Earthmate starts out at 4800 8N1 by default... the driver will - upon start init to this setting. usbserial core provides the rest - of the termios settings, along with some custom termios so that the - output is in proper format and parsable. - - The device can be put into sirf mode by issuing NMEA command:: - - $PSRF100,,,,,*CHECKSUM - $PSRF100,0,9600,8,1,0*0C - - It should then be sufficient to change the port termios to match this - to begin communicating. - - As far as I can tell it supports pretty much every sirf command as - documented online available with firmware 2.31, with some unknown - message ids. - - The hid->com adapter can run at a maximum baud of 115200bps. Please note - that the device has trouble or is incapable of raising line voltage properly. - It will be fine with null modem links, as long as you do not try to link two - together without hacking the adapter to set the line high. - - The driver is smp safe. Performance with the driver is rather low when using - it for transferring files. This is being worked on, but I would be willing to - accept patches. An urb queue or packet buffer would likely fit the bill here. - - If you have any questions, problems, patches, feature requests, etc. you can - contact me here via email: - - dignome@gmail.com - - (your problems/patches can alternately be submitted to usb-devel) - - -Digi AccelePort Driver ----------------------- - - This driver supports the Digi AccelePort USB 2 and 4 devices, 2 port - (plus a parallel port) and 4 port USB serial converters. The driver - does NOT yet support the Digi AccelePort USB 8. - - This driver works under SMP with the usb-uhci driver. It does not - work under SMP with the uhci driver. - - The driver is generally working, though we still have a few more ioctls - to implement and final testing and debugging to do. The parallel port - on the USB 2 is supported as a serial to parallel converter; in other - words, it appears as another USB serial port on Linux, even though - physically it is really a parallel port. The Digi Acceleport USB 8 - is not yet supported. - - Please contact Peter Berger (pberger@brimson.com) or Al Borchers - (alborchers@steinerpoint.com) for questions or problems with this - driver. - - -Belkin USB Serial Adapter F5U103 --------------------------------- - - Single port DB-9/PS-2 serial adapter from Belkin with firmware by eTEK Labs. - The Peracom single port serial adapter also works with this driver, as - well as the GoHubs adapter. - - Current status: - - The following have been tested and work: - - - Baud rate 300-230400 - - Data bits 5-8 - - Stop bits 1-2 - - Parity N,E,O,M,S - - Handshake None, Software (XON/XOFF), Hardware (CTSRTS,CTSDTR) [1]_ - - Break Set and clear - - Line control Input/Output query and control [2]_ - - .. [1] - Hardware input flow control is only enabled for firmware - levels above 2.06. Read source code comments describing Belkin - firmware errata. Hardware output flow control is working for all - firmware versions. - - .. [2] - Queries of inputs (CTS,DSR,CD,RI) show the last - reported state. Queries of outputs (DTR,RTS) show the last - requested state and may not reflect current state as set by - automatic hardware flow control. - - TO DO List: - - Add true modem control line query capability. Currently tracks the - states reported by the interrupt and the states requested. - - Add error reporting back to application for UART error conditions. - - Add support for flush ioctls. - - Add everything else that is missing :) - - For any questions or problems with this driver, please contact William - Greathouse at wgreathouse@smva.com - - -Empeg empeg-car Mark I/II Driver --------------------------------- - - This is an experimental driver to provide connectivity support for the - client synchronization tools for an Empeg empeg-car mp3 player. - - Tips: - * Don't forget to create the device nodes for ttyUSB{0,1,2,...} - * modprobe empeg (modprobe is your friend) - * emptool --usb /dev/ttyUSB0 (or whatever you named your device node) - - For any questions or problems with this driver, please contact Gary - Brubaker at xavyer@ix.netcom.com - - -MCT USB Single Port Serial Adapter U232 ---------------------------------------- - - This driver is for the MCT USB-RS232 Converter (25 pin, Model No. - U232-P25) from Magic Control Technology Corp. (there is also a 9 pin - Model No. U232-P9). More information about this device can be found at - the manufacturer's web-site: http://www.mct.com.tw. - - The driver is generally working, though it still needs some more testing. - It is derived from the Belkin USB Serial Adapter F5U103 driver and its - TODO list is valid for this driver as well. - - This driver has also been found to work for other products, which have - the same Vendor ID but different Product IDs. Sitecom's U232-P25 serial - converter uses Product ID 0x230 and Vendor ID 0x711 and works with this - driver. Also, D-Link's DU-H3SP USB BAY also works with this driver. - - For any questions or problems with this driver, please contact Wolfgang - Grandegger at wolfgang@ces.ch - - -Inside Out Networks Edgeport Driver ------------------------------------ - - This driver supports all devices made by Inside Out Networks, specifically - the following models: - - - Edgeport/4 - - Rapidport/4 - - Edgeport/4t - - Edgeport/2 - - Edgeport/4i - - Edgeport/2i - - Edgeport/421 - - Edgeport/21 - - Edgeport/8 - - Edgeport/8 Dual - - Edgeport/2D8 - - Edgeport/4D8 - - Edgeport/8i - - Edgeport/2 DIN - - Edgeport/4 DIN - - Edgeport/16 Dual - - For any questions or problems with this driver, please contact Greg - Kroah-Hartman at greg@kroah.com - - -REINER SCT cyberJack pinpad/e-com USB chipcard reader ------------------------------------------------------ - - Interface to ISO 7816 compatible contactbased chipcards, e.g. GSM SIMs. - - Current status: - - This is the kernel part of the driver for this USB card reader. - There is also a user part for a CT-API driver available. A site - for downloading is TBA. For now, you can request it from the - maintainer (linux-usb@sii.li). - - For any questions or problems with this driver, please contact - linux-usb@sii.li - - -Prolific PL2303 Driver ----------------------- - - This driver supports any device that has the PL2303 chip from Prolific - in it. This includes a number of single port USB to serial converters, - more than 70% of USB GPS devices (in 2010), and some USB UPSes. Devices - from Aten (the UC-232) and IO-Data work with this driver, as does - the DCU-11 mobile-phone cable. - - For any questions or problems with this driver, please contact Greg - Kroah-Hartman at greg@kroah.com - - -KL5KUSB105 chipset / PalmConnect USB single-port adapter --------------------------------------------------------- - -Current status: - - The driver was put together by looking at the usb bus transactions - done by Palm's driver under Windows, so a lot of functionality is - still missing. Notably, serial ioctls are sometimes faked or not yet - implemented. Support for finding out about DSR and CTS line status is - however implemented (though not nicely), so your favorite autopilot(1) - and pilot-manager -daemon calls will work. Baud rates up to 115200 - are supported, but handshaking (software or hardware) is not, which is - why it is wise to cut down on the rate used is wise for large - transfers until this is settled. - - See http://www.uuhaus.de/linux/palmconnect.html for up-to-date - information on this driver. - -Winchiphead CH341 Driver ------------------------- - - This driver is for the Winchiphead CH341 USB-RS232 Converter. This chip - also implements an IEEE 1284 parallel port, I2C and SPI, but that is not - supported by the driver. The protocol was analyzed from the behaviour - of the Windows driver, no datasheet is available at present. - - The manufacturer's website: http://www.winchiphead.com/. - - For any questions or problems with this driver, please contact - frank@kingswood-consulting.co.uk. - -Moschip MCS7720, MCS7715 driver -------------------------------- - - These chips are present in devices sold by various manufacturers, such as Syba - and Cables Unlimited. There may be others. The 7720 provides two serial - ports, and the 7715 provides one serial and one standard PC parallel port. - Support for the 7715's parallel port is enabled by a separate option, which - will not appear unless parallel port support is first enabled at the top-level - of the Device Drivers config menu. Currently only compatibility mode is - supported on the parallel port (no ECP/EPP). - - TODO: - - Implement ECP/EPP modes for the parallel port. - - Baud rates higher than 115200 are currently broken. - - Devices with a single serial port based on the Moschip MCS7703 may work - with this driver with a simple addition to the usb_device_id table. I - don't have one of these devices, so I can't say for sure. - -Generic Serial driver ---------------------- - - If your device is not one of the above listed devices, compatible with - the above models, you can try out the "generic" interface. This - interface does not provide any type of control messages sent to the - device, and does not support any kind of device flow control. All that - is required of your device is that it has at least one bulk in endpoint, - or one bulk out endpoint. - - To enable the generic driver to recognize your device, provide:: - - echo >/sys/bus/usb-serial/drivers/generic/new_id - - where the and is replaced with the hex representation of your - device's vendor id and product id. - If the driver is compiled as a module you can also provide one id when - loading the module:: - - insmod usbserial vendor=0x#### product=0x#### - - This driver has been successfully used to connect to the NetChip USB - development board, providing a way to develop USB firmware without - having to write a custom driver. - - For any questions or problems with this driver, please contact Greg - Kroah-Hartman at greg@kroah.com - - -Contact -======= - - If anyone has any problems using these drivers, with any of the above - specified products, please contact the specific driver's author listed - above, or join the Linux-USB mailing list (information on joining the - mailing list, as well as a link to its searchable archive is at - http://www.linux-usb.org/ ) - - -Greg Kroah-Hartman -greg@kroah.com diff --git a/Documentation/usb/usbip_protocol.rst b/Documentation/usb/usbip_protocol.rst new file mode 100644 index 000000000000..988c832166cd --- /dev/null +++ b/Documentation/usb/usbip_protocol.rst @@ -0,0 +1,411 @@ +=============== +USB/IP protocol +=============== + +PRELIMINARY DRAFT, MAY CONTAIN MISTAKES! +28 Jun 2011 + +The USB/IP protocol follows a server/client architecture. The server exports the +USB devices and the clients imports them. The device driver for the exported +USB device runs on the client machine. + +The client may ask for the list of the exported USB devices. To get the list the +client opens a TCP/IP connection towards the server, and sends an OP_REQ_DEVLIST +packet on top of the TCP/IP connection (so the actual OP_REQ_DEVLIST may be sent +in one or more pieces at the low level transport layer). The server sends back +the OP_REP_DEVLIST packet which lists the exported USB devices. Finally the +TCP/IP connection is closed. + +:: + + virtual host controller usb host + "client" "server" + (imports USB devices) (exports USB devices) + | | + | OP_REQ_DEVLIST | + | ----------------------------------------------> | + | | + | OP_REP_DEVLIST | + | <---------------------------------------------- | + | | + +Once the client knows the list of exported USB devices it may decide to use one +of them. First the client opens a TCP/IP connection towards the server and +sends an OP_REQ_IMPORT packet. The server replies with OP_REP_IMPORT. If the +import was successful the TCP/IP connection remains open and will be used +to transfer the URB traffic between the client and the server. The client may +send two types of packets: the USBIP_CMD_SUBMIT to submit an URB, and +USBIP_CMD_UNLINK to unlink a previously submitted URB. The answers of the +server may be USBIP_RET_SUBMIT and USBIP_RET_UNLINK respectively. + +:: + + virtual host controller usb host + "client" "server" + (imports USB devices) (exports USB devices) + | | + | OP_REQ_IMPORT | + | ----------------------------------------------> | + | | + | OP_REP_IMPORT | + | <---------------------------------------------- | + | | + | | + | USBIP_CMD_SUBMIT(seqnum = n) | + | ----------------------------------------------> | + | | + | USBIP_RET_SUBMIT(seqnum = n) | + | <---------------------------------------------- | + | . | + | : | + | | + | USBIP_CMD_SUBMIT(seqnum = m) | + | ----------------------------------------------> | + | | + | USBIP_CMD_SUBMIT(seqnum = m+1) | + | ----------------------------------------------> | + | | + | USBIP_CMD_SUBMIT(seqnum = m+2) | + | ----------------------------------------------> | + | | + | USBIP_RET_SUBMIT(seqnum = m) | + | <---------------------------------------------- | + | | + | USBIP_CMD_SUBMIT(seqnum = m+3) | + | ----------------------------------------------> | + | | + | USBIP_RET_SUBMIT(seqnum = m+1) | + | <---------------------------------------------- | + | | + | USBIP_CMD_SUBMIT(seqnum = m+4) | + | ----------------------------------------------> | + | | + | USBIP_RET_SUBMIT(seqnum = m+2) | + | <---------------------------------------------- | + | . | + | : | + | | + | USBIP_CMD_UNLINK | + | ----------------------------------------------> | + | | + | USBIP_RET_UNLINK | + | <---------------------------------------------- | + | | + +The fields are in network (big endian) byte order meaning that the most significant +byte (MSB) is stored at the lowest address. + + +OP_REQ_DEVLIST: + Retrieve the list of exported USB devices. + ++-----------+--------+------------+---------------------------------------------------+ +| Offset | Length | Value | Description | ++===========+========+============+===================================================+ +| 0 | 2 | 0x0100 | Binary-coded decimal USBIP version number: v1.0.0 | ++-----------+--------+------------+---------------------------------------------------+ +| 2 | 2 | 0x8005 | Command code: Retrieve the list of exported USB | +| | | | devices. | ++-----------+--------+------------+---------------------------------------------------+ +| 4 | 4 | 0x00000000 | Status: unused, shall be set to 0 | ++-----------+--------+------------+---------------------------------------------------+ + +OP_REP_DEVLIST: + Reply with the list of exported USB devices. + ++-----------+--------+------------+---------------------------------------------------+ +| Offset | Length | Value | Description | ++===========+========+============+===================================================+ +| 0 | 2 | 0x0100 | Binary-coded decimal USBIP version number: v1.0.0.| ++-----------+--------+------------+---------------------------------------------------+ +| 2 | 2 | 0x0005 | Reply code: The list of exported USB devices. | ++-----------+--------+------------+---------------------------------------------------+ +| 4 | 4 | 0x00000000 | Status: 0 for OK | ++-----------+--------+------------+---------------------------------------------------+ +| 8 | 4 | n | Number of exported devices: 0 means no exported | +| | | | devices. | ++-----------+--------+------------+---------------------------------------------------+ +| 0x0C | | | From now on the exported n devices are described, | +| | | | if any. If no devices are exported the message | +| | | | ends with the previous "number of exported | +| | | | devices" field. | ++-----------+--------+------------+---------------------------------------------------+ +| | 256 | | path: Path of the device on the host exporting the| +| | | | USB device, string closed with zero byte, e.g. | +| | | | "/sys/devices/pci0000:00/0000:00:1d.1/usb3/3-2" | +| | | | The unused bytes shall be filled with zero | +| | | | bytes. | ++-----------+--------+------------+---------------------------------------------------+ +| 0x10C | 32 | | busid: Bus ID of the exported device, string | +| | | | closed with zero byte, e.g. "3-2". The unused | +| | | | bytes shall be filled with zero bytes. | ++-----------+--------+------------+---------------------------------------------------+ +| 0x12C | 4 | | busnum | ++-----------+--------+------------+---------------------------------------------------+ +| 0x130 | 4 | | devnum | ++-----------+--------+------------+---------------------------------------------------+ +| 0x134 | 4 | | speed | ++-----------+--------+------------+---------------------------------------------------+ +| 0x138 | 2 | | idVendor | ++-----------+--------+------------+---------------------------------------------------+ +| 0x13A | 2 | | idProduct | ++-----------+--------+------------+---------------------------------------------------+ +| 0x13C | 2 | | bcdDevice | ++-----------+--------+------------+---------------------------------------------------+ +| 0x13E | 1 | | bDeviceClass | ++-----------+--------+------------+---------------------------------------------------+ +| 0x13F | 1 | | bDeviceSubClass | ++-----------+--------+------------+---------------------------------------------------+ +| 0x140 | 1 | | bDeviceProtocol | ++-----------+--------+------------+---------------------------------------------------+ +| 0x141 | 1 | | bConfigurationValue | ++-----------+--------+------------+---------------------------------------------------+ +| 0x142 | 1 | | bNumConfigurations | ++-----------+--------+------------+---------------------------------------------------+ +| 0x143 | 1 | | bNumInterfaces | ++-----------+--------+------------+---------------------------------------------------+ +| 0x144 | | m_0 | From now on each interface is described, all | +| | | | together bNumInterfaces times, with the | +| | | | the following 4 fields: | ++-----------+--------+------------+---------------------------------------------------+ +| | 1 | | bInterfaceClass | ++-----------+--------+------------+---------------------------------------------------+ +| 0x145 | 1 | | bInterfaceSubClass | ++-----------+--------+------------+---------------------------------------------------+ +| 0x146 | 1 | | bInterfaceProtocol | ++-----------+--------+------------+---------------------------------------------------+ +| 0x147 | 1 | | padding byte for alignment, shall be set to zero | ++-----------+--------+------------+---------------------------------------------------+ +| 0xC + | | | The second exported USB device starts at i=1 | +| i*0x138 + | | | with the busid field. | +| m_(i-1)*4 | | | | ++-----------+--------+------------+---------------------------------------------------+ + +OP_REQ_IMPORT: + Request to import (attach) a remote USB device. + ++-----------+--------+------------+---------------------------------------------------+ +| Offset | Length | Value | Description | ++===========+========+============+===================================================+ +| 0 | 2 | 0x0100 | Binary-coded decimal USBIP version number: v1.0.0 | ++-----------+--------+------------+---------------------------------------------------+ +| 2 | 2 | 0x8003 | Command code: import a remote USB device. | ++-----------+--------+------------+---------------------------------------------------+ +| 4 | 4 | 0x00000000 | Status: unused, shall be set to 0 | ++-----------+--------+------------+---------------------------------------------------+ +| 8 | 32 | | busid: the busid of the exported device on the | +| | | | remote host. The possible values are taken | +| | | | from the message field OP_REP_DEVLIST.busid. | +| | | | A string closed with zero, the unused bytes | +| | | | shall be filled with zeros. | ++-----------+--------+------------+---------------------------------------------------+ + +OP_REP_IMPORT: + Reply to import (attach) a remote USB device. + ++-----------+--------+------------+---------------------------------------------------+ +| Offset | Length | Value | Description | ++===========+========+============+===================================================+ +| 0 | 2 | 0x0100 | Binary-coded decimal USBIP version number: v1.0.0 | ++-----------+--------+------------+---------------------------------------------------+ +| 2 | 2 | 0x0003 | Reply code: Reply to import. | ++-----------+--------+------------+---------------------------------------------------+ +| 4 | 4 | 0x00000000 | Status: | +| | | | | +| | | | - 0 for OK | +| | | | - 1 for error | ++-----------+--------+------------+---------------------------------------------------+ +| 8 | | | From now on comes the details of the imported | +| | | | device, if the previous status field was OK (0), | +| | | | otherwise the reply ends with the status field. | ++-----------+--------+------------+---------------------------------------------------+ +| | 256 | | path: Path of the device on the host exporting the| +| | | | USB device, string closed with zero byte, e.g. | +| | | | "/sys/devices/pci0000:00/0000:00:1d.1/usb3/3-2" | +| | | | The unused bytes shall be filled with zero | +| | | | bytes. | ++-----------+--------+------------+---------------------------------------------------+ +| 0x108 | 32 | | busid: Bus ID of the exported device, string | +| | | | closed with zero byte, e.g. "3-2". The unused | +| | | | bytes shall be filled with zero bytes. | ++-----------+--------+------------+---------------------------------------------------+ +| 0x128 | 4 | | busnum | ++-----------+--------+------------+---------------------------------------------------+ +| 0x12C | 4 | | devnum | ++-----------+--------+------------+---------------------------------------------------+ +| 0x130 | 4 | | speed | ++-----------+--------+------------+---------------------------------------------------+ +| 0x134 | 2 | | idVendor | ++-----------+--------+------------+---------------------------------------------------+ +| 0x136 | 2 | | idProduct | ++-----------+--------+------------+---------------------------------------------------+ +| 0x138 | 2 | | bcdDevice | ++-----------+--------+------------+---------------------------------------------------+ +| 0x139 | 1 | | bDeviceClass | ++-----------+--------+------------+---------------------------------------------------+ +| 0x13A | 1 | | bDeviceSubClass | ++-----------+--------+------------+---------------------------------------------------+ +| 0x13B | 1 | | bDeviceProtocol | ++-----------+--------+------------+---------------------------------------------------+ +| 0x13C | 1 | | bConfigurationValue | ++-----------+--------+------------+---------------------------------------------------+ +| 0x13D | 1 | | bNumConfigurations | ++-----------+--------+------------+---------------------------------------------------+ +| 0x13E | 1 | | bNumInterfaces | ++-----------+--------+------------+---------------------------------------------------+ + +USBIP_CMD_SUBMIT: + Submit an URB + ++-----------+--------+------------+---------------------------------------------------+ +| Offset | Length | Value | Description | ++===========+========+============+===================================================+ +| 0 | 4 | 0x00000001 | command: Submit an URB | ++-----------+--------+------------+---------------------------------------------------+ +| 4 | 4 | | seqnum: the sequence number of the URB to submit | ++-----------+--------+------------+---------------------------------------------------+ +| 8 | 4 | | devid | ++-----------+--------+------------+---------------------------------------------------+ +| 0xC | 4 | | direction: | +| | | | | +| | | | - 0: USBIP_DIR_OUT | +| | | | - 1: USBIP_DIR_IN | ++-----------+--------+------------+---------------------------------------------------+ +| 0x10 | 4 | | ep: endpoint number, possible values are: 0...15 | ++-----------+--------+------------+---------------------------------------------------+ +| 0x14 | 4 | | transfer_flags: possible values depend on the | +| | | | URB transfer type, see below | ++-----------+--------+------------+---------------------------------------------------+ +| 0x18 | 4 | | transfer_buffer_length | ++-----------+--------+------------+---------------------------------------------------+ +| 0x1C | 4 | | start_frame: specify the selected frame to | +| | | | transmit an ISO frame, ignored if URB_ISO_ASAP | +| | | | is specified at transfer_flags | ++-----------+--------+------------+---------------------------------------------------+ +| 0x20 | 4 | | number_of_packets: number of ISO packets | ++-----------+--------+------------+---------------------------------------------------+ +| 0x24 | 4 | | interval: maximum time for the request on the | +| | | | server-side host controller | ++-----------+--------+------------+---------------------------------------------------+ +| 0x28 | 8 | | setup: data bytes for USB setup, filled with | +| | | | zeros if not used | ++-----------+--------+------------+---------------------------------------------------+ +| 0x30 | | | URB data. For ISO transfers the padding between | +| | | | each ISO packets is not transmitted. | ++-----------+--------+------------+---------------------------------------------------+ + + + +-------------------------+------------+---------+-----------+----------+-------------+ + | Allowed transfer_flags | value | control | interrupt | bulk | isochronous | + +=========================+============+=========+===========+==========+=============+ + | URB_SHORT_NOT_OK | 0x00000001 | only in | only in | only in | no | + +-------------------------+------------+---------+-----------+----------+-------------+ + | URB_ISO_ASAP | 0x00000002 | no | no | no | yes | + +-------------------------+------------+---------+-----------+----------+-------------+ + | URB_NO_TRANSFER_DMA_MAP | 0x00000004 | yes | yes | yes | yes | + +-------------------------+------------+---------+-----------+----------+-------------+ + | URB_ZERO_PACKET | 0x00000040 | no | no | only out | no | + +-------------------------+------------+---------+-----------+----------+-------------+ + | URB_NO_INTERRUPT | 0x00000080 | yes | yes | yes | yes | + +-------------------------+------------+---------+-----------+----------+-------------+ + | URB_FREE_BUFFER | 0x00000100 | yes | yes | yes | yes | + +-------------------------+------------+---------+-----------+----------+-------------+ + | URB_DIR_MASK | 0x00000200 | yes | yes | yes | yes | + +-------------------------+------------+---------+-----------+----------+-------------+ + + +USBIP_RET_SUBMIT: + Reply for submitting an URB + ++-----------+--------+------------+---------------------------------------------------+ +| Offset | Length | Value | Description | ++===========+========+============+===================================================+ +| 0 | 4 | 0x00000003 | command | ++-----------+--------+------------+---------------------------------------------------+ +| 4 | 4 | | seqnum: URB sequence number | ++-----------+--------+------------+---------------------------------------------------+ +| 8 | 4 | | devid | ++-----------+--------+------------+---------------------------------------------------+ +| 0xC | 4 | | direction: | +| | | | | +| | | | - 0: USBIP_DIR_OUT | +| | | | - 1: USBIP_DIR_IN | ++-----------+--------+------------+---------------------------------------------------+ +| 0x10 | 4 | | ep: endpoint number | ++-----------+--------+------------+---------------------------------------------------+ +| 0x14 | 4 | | status: zero for successful URB transaction, | +| | | | otherwise some kind of error happened. | ++-----------+--------+------------+---------------------------------------------------+ +| 0x18 | 4 | n | actual_length: number of URB data bytes | ++-----------+--------+------------+---------------------------------------------------+ +| 0x1C | 4 | | start_frame: for an ISO frame the actually | +| | | | selected frame for transmit. | ++-----------+--------+------------+---------------------------------------------------+ +| 0x20 | 4 | | number_of_packets | ++-----------+--------+------------+---------------------------------------------------+ +| 0x24 | 4 | | error_count | ++-----------+--------+------------+---------------------------------------------------+ +| 0x28 | 8 | | setup: data bytes for USB setup, filled with | +| | | | zeros if not used | ++-----------+--------+------------+---------------------------------------------------+ +| 0x30 | n | | URB data bytes. For ISO transfers the padding | +| | | | between each ISO packets is not transmitted. | ++-----------+--------+------------+---------------------------------------------------+ + +USBIP_CMD_UNLINK: + Unlink an URB + ++-----------+--------+------------+---------------------------------------------------+ +| Offset | Length | Value | Description | ++===========+========+============+===================================================+ +| 0 | 4 | 0x00000002 | command: URB unlink command | ++-----------+--------+------------+---------------------------------------------------+ +| 4 | 4 | | seqnum: URB sequence number to unlink: | +| | | | | +| | | | FIXME: | +| | | | is this so? | ++-----------+--------+------------+---------------------------------------------------+ +| 8 | 4 | | devid | ++-----------+--------+------------+---------------------------------------------------+ +| 0xC | 4 | | direction: | +| | | | | +| | | | - 0: USBIP_DIR_OUT | +| | | | - 1: USBIP_DIR_IN | ++-----------+--------+------------+---------------------------------------------------+ +| 0x10 | 4 | | ep: endpoint number: zero | ++-----------+--------+------------+---------------------------------------------------+ +| 0x14 | 4 | | seqnum: the URB sequence number given previously | +| | | | at USBIP_CMD_SUBMIT.seqnum field | ++-----------+--------+------------+---------------------------------------------------+ +| 0x30 | n | | URB data bytes. For ISO transfers the padding | +| | | | between each ISO packets is not transmitted. | ++-----------+--------+------------+---------------------------------------------------+ + +USBIP_RET_UNLINK: + Reply for URB unlink + ++-----------+--------+------------+---------------------------------------------------+ +| Offset | Length | Value | Description | ++===========+========+============+===================================================+ +| 0 | 4 | 0x00000004 | command: reply for the URB unlink command | ++-----------+--------+------------+---------------------------------------------------+ +| 4 | 4 | | seqnum: the unlinked URB sequence number | ++-----------+--------+------------+---------------------------------------------------+ +| 8 | 4 | | devid | ++-----------+--------+------------+---------------------------------------------------+ +| 0xC | 4 | | direction: | +| | | | | +| | | | - 0: USBIP_DIR_OUT | +| | | | - 1: USBIP_DIR_IN | ++-----------+--------+------------+---------------------------------------------------+ +| 0x10 | 4 | | ep: endpoint number | ++-----------+--------+------------+---------------------------------------------------+ +| 0x14 | 4 | | status: This is the value contained in the | +| | | | urb->status in the URB completition handler. | +| | | | | +| | | | FIXME: | +| | | | a better explanation needed. | ++-----------+--------+------------+---------------------------------------------------+ +| 0x30 | n | | URB data bytes. For ISO transfers the padding | +| | | | between each ISO packets is not transmitted. | ++-----------+--------+------------+---------------------------------------------------+ diff --git a/Documentation/usb/usbip_protocol.txt b/Documentation/usb/usbip_protocol.txt deleted file mode 100644 index 988c832166cd..000000000000 --- a/Documentation/usb/usbip_protocol.txt +++ /dev/null @@ -1,411 +0,0 @@ -=============== -USB/IP protocol -=============== - -PRELIMINARY DRAFT, MAY CONTAIN MISTAKES! -28 Jun 2011 - -The USB/IP protocol follows a server/client architecture. The server exports the -USB devices and the clients imports them. The device driver for the exported -USB device runs on the client machine. - -The client may ask for the list of the exported USB devices. To get the list the -client opens a TCP/IP connection towards the server, and sends an OP_REQ_DEVLIST -packet on top of the TCP/IP connection (so the actual OP_REQ_DEVLIST may be sent -in one or more pieces at the low level transport layer). The server sends back -the OP_REP_DEVLIST packet which lists the exported USB devices. Finally the -TCP/IP connection is closed. - -:: - - virtual host controller usb host - "client" "server" - (imports USB devices) (exports USB devices) - | | - | OP_REQ_DEVLIST | - | ----------------------------------------------> | - | | - | OP_REP_DEVLIST | - | <---------------------------------------------- | - | | - -Once the client knows the list of exported USB devices it may decide to use one -of them. First the client opens a TCP/IP connection towards the server and -sends an OP_REQ_IMPORT packet. The server replies with OP_REP_IMPORT. If the -import was successful the TCP/IP connection remains open and will be used -to transfer the URB traffic between the client and the server. The client may -send two types of packets: the USBIP_CMD_SUBMIT to submit an URB, and -USBIP_CMD_UNLINK to unlink a previously submitted URB. The answers of the -server may be USBIP_RET_SUBMIT and USBIP_RET_UNLINK respectively. - -:: - - virtual host controller usb host - "client" "server" - (imports USB devices) (exports USB devices) - | | - | OP_REQ_IMPORT | - | ----------------------------------------------> | - | | - | OP_REP_IMPORT | - | <---------------------------------------------- | - | | - | | - | USBIP_CMD_SUBMIT(seqnum = n) | - | ----------------------------------------------> | - | | - | USBIP_RET_SUBMIT(seqnum = n) | - | <---------------------------------------------- | - | . | - | : | - | | - | USBIP_CMD_SUBMIT(seqnum = m) | - | ----------------------------------------------> | - | | - | USBIP_CMD_SUBMIT(seqnum = m+1) | - | ----------------------------------------------> | - | | - | USBIP_CMD_SUBMIT(seqnum = m+2) | - | ----------------------------------------------> | - | | - | USBIP_RET_SUBMIT(seqnum = m) | - | <---------------------------------------------- | - | | - | USBIP_CMD_SUBMIT(seqnum = m+3) | - | ----------------------------------------------> | - | | - | USBIP_RET_SUBMIT(seqnum = m+1) | - | <---------------------------------------------- | - | | - | USBIP_CMD_SUBMIT(seqnum = m+4) | - | ----------------------------------------------> | - | | - | USBIP_RET_SUBMIT(seqnum = m+2) | - | <---------------------------------------------- | - | . | - | : | - | | - | USBIP_CMD_UNLINK | - | ----------------------------------------------> | - | | - | USBIP_RET_UNLINK | - | <---------------------------------------------- | - | | - -The fields are in network (big endian) byte order meaning that the most significant -byte (MSB) is stored at the lowest address. - - -OP_REQ_DEVLIST: - Retrieve the list of exported USB devices. - -+-----------+--------+------------+---------------------------------------------------+ -| Offset | Length | Value | Description | -+===========+========+============+===================================================+ -| 0 | 2 | 0x0100 | Binary-coded decimal USBIP version number: v1.0.0 | -+-----------+--------+------------+---------------------------------------------------+ -| 2 | 2 | 0x8005 | Command code: Retrieve the list of exported USB | -| | | | devices. | -+-----------+--------+------------+---------------------------------------------------+ -| 4 | 4 | 0x00000000 | Status: unused, shall be set to 0 | -+-----------+--------+------------+---------------------------------------------------+ - -OP_REP_DEVLIST: - Reply with the list of exported USB devices. - -+-----------+--------+------------+---------------------------------------------------+ -| Offset | Length | Value | Description | -+===========+========+============+===================================================+ -| 0 | 2 | 0x0100 | Binary-coded decimal USBIP version number: v1.0.0.| -+-----------+--------+------------+---------------------------------------------------+ -| 2 | 2 | 0x0005 | Reply code: The list of exported USB devices. | -+-----------+--------+------------+---------------------------------------------------+ -| 4 | 4 | 0x00000000 | Status: 0 for OK | -+-----------+--------+------------+---------------------------------------------------+ -| 8 | 4 | n | Number of exported devices: 0 means no exported | -| | | | devices. | -+-----------+--------+------------+---------------------------------------------------+ -| 0x0C | | | From now on the exported n devices are described, | -| | | | if any. If no devices are exported the message | -| | | | ends with the previous "number of exported | -| | | | devices" field. | -+-----------+--------+------------+---------------------------------------------------+ -| | 256 | | path: Path of the device on the host exporting the| -| | | | USB device, string closed with zero byte, e.g. | -| | | | "/sys/devices/pci0000:00/0000:00:1d.1/usb3/3-2" | -| | | | The unused bytes shall be filled with zero | -| | | | bytes. | -+-----------+--------+------------+---------------------------------------------------+ -| 0x10C | 32 | | busid: Bus ID of the exported device, string | -| | | | closed with zero byte, e.g. "3-2". The unused | -| | | | bytes shall be filled with zero bytes. | -+-----------+--------+------------+---------------------------------------------------+ -| 0x12C | 4 | | busnum | -+-----------+--------+------------+---------------------------------------------------+ -| 0x130 | 4 | | devnum | -+-----------+--------+------------+---------------------------------------------------+ -| 0x134 | 4 | | speed | -+-----------+--------+------------+---------------------------------------------------+ -| 0x138 | 2 | | idVendor | -+-----------+--------+------------+---------------------------------------------------+ -| 0x13A | 2 | | idProduct | -+-----------+--------+------------+---------------------------------------------------+ -| 0x13C | 2 | | bcdDevice | -+-----------+--------+------------+---------------------------------------------------+ -| 0x13E | 1 | | bDeviceClass | -+-----------+--------+------------+---------------------------------------------------+ -| 0x13F | 1 | | bDeviceSubClass | -+-----------+--------+------------+---------------------------------------------------+ -| 0x140 | 1 | | bDeviceProtocol | -+-----------+--------+------------+---------------------------------------------------+ -| 0x141 | 1 | | bConfigurationValue | -+-----------+--------+------------+---------------------------------------------------+ -| 0x142 | 1 | | bNumConfigurations | -+-----------+--------+------------+---------------------------------------------------+ -| 0x143 | 1 | | bNumInterfaces | -+-----------+--------+------------+---------------------------------------------------+ -| 0x144 | | m_0 | From now on each interface is described, all | -| | | | together bNumInterfaces times, with the | -| | | | the following 4 fields: | -+-----------+--------+------------+---------------------------------------------------+ -| | 1 | | bInterfaceClass | -+-----------+--------+------------+---------------------------------------------------+ -| 0x145 | 1 | | bInterfaceSubClass | -+-----------+--------+------------+---------------------------------------------------+ -| 0x146 | 1 | | bInterfaceProtocol | -+-----------+--------+------------+---------------------------------------------------+ -| 0x147 | 1 | | padding byte for alignment, shall be set to zero | -+-----------+--------+------------+---------------------------------------------------+ -| 0xC + | | | The second exported USB device starts at i=1 | -| i*0x138 + | | | with the busid field. | -| m_(i-1)*4 | | | | -+-----------+--------+------------+---------------------------------------------------+ - -OP_REQ_IMPORT: - Request to import (attach) a remote USB device. - -+-----------+--------+------------+---------------------------------------------------+ -| Offset | Length | Value | Description | -+===========+========+============+===================================================+ -| 0 | 2 | 0x0100 | Binary-coded decimal USBIP version number: v1.0.0 | -+-----------+--------+------------+---------------------------------------------------+ -| 2 | 2 | 0x8003 | Command code: import a remote USB device. | -+-----------+--------+------------+---------------------------------------------------+ -| 4 | 4 | 0x00000000 | Status: unused, shall be set to 0 | -+-----------+--------+------------+---------------------------------------------------+ -| 8 | 32 | | busid: the busid of the exported device on the | -| | | | remote host. The possible values are taken | -| | | | from the message field OP_REP_DEVLIST.busid. | -| | | | A string closed with zero, the unused bytes | -| | | | shall be filled with zeros. | -+-----------+--------+------------+---------------------------------------------------+ - -OP_REP_IMPORT: - Reply to import (attach) a remote USB device. - -+-----------+--------+------------+---------------------------------------------------+ -| Offset | Length | Value | Description | -+===========+========+============+===================================================+ -| 0 | 2 | 0x0100 | Binary-coded decimal USBIP version number: v1.0.0 | -+-----------+--------+------------+---------------------------------------------------+ -| 2 | 2 | 0x0003 | Reply code: Reply to import. | -+-----------+--------+------------+---------------------------------------------------+ -| 4 | 4 | 0x00000000 | Status: | -| | | | | -| | | | - 0 for OK | -| | | | - 1 for error | -+-----------+--------+------------+---------------------------------------------------+ -| 8 | | | From now on comes the details of the imported | -| | | | device, if the previous status field was OK (0), | -| | | | otherwise the reply ends with the status field. | -+-----------+--------+------------+---------------------------------------------------+ -| | 256 | | path: Path of the device on the host exporting the| -| | | | USB device, string closed with zero byte, e.g. | -| | | | "/sys/devices/pci0000:00/0000:00:1d.1/usb3/3-2" | -| | | | The unused bytes shall be filled with zero | -| | | | bytes. | -+-----------+--------+------------+---------------------------------------------------+ -| 0x108 | 32 | | busid: Bus ID of the exported device, string | -| | | | closed with zero byte, e.g. "3-2". The unused | -| | | | bytes shall be filled with zero bytes. | -+-----------+--------+------------+---------------------------------------------------+ -| 0x128 | 4 | | busnum | -+-----------+--------+------------+---------------------------------------------------+ -| 0x12C | 4 | | devnum | -+-----------+--------+------------+---------------------------------------------------+ -| 0x130 | 4 | | speed | -+-----------+--------+------------+---------------------------------------------------+ -| 0x134 | 2 | | idVendor | -+-----------+--------+------------+---------------------------------------------------+ -| 0x136 | 2 | | idProduct | -+-----------+--------+------------+---------------------------------------------------+ -| 0x138 | 2 | | bcdDevice | -+-----------+--------+------------+---------------------------------------------------+ -| 0x139 | 1 | | bDeviceClass | -+-----------+--------+------------+---------------------------------------------------+ -| 0x13A | 1 | | bDeviceSubClass | -+-----------+--------+------------+---------------------------------------------------+ -| 0x13B | 1 | | bDeviceProtocol | -+-----------+--------+------------+---------------------------------------------------+ -| 0x13C | 1 | | bConfigurationValue | -+-----------+--------+------------+---------------------------------------------------+ -| 0x13D | 1 | | bNumConfigurations | -+-----------+--------+------------+---------------------------------------------------+ -| 0x13E | 1 | | bNumInterfaces | -+-----------+--------+------------+---------------------------------------------------+ - -USBIP_CMD_SUBMIT: - Submit an URB - -+-----------+--------+------------+---------------------------------------------------+ -| Offset | Length | Value | Description | -+===========+========+============+===================================================+ -| 0 | 4 | 0x00000001 | command: Submit an URB | -+-----------+--------+------------+---------------------------------------------------+ -| 4 | 4 | | seqnum: the sequence number of the URB to submit | -+-----------+--------+------------+---------------------------------------------------+ -| 8 | 4 | | devid | -+-----------+--------+------------+---------------------------------------------------+ -| 0xC | 4 | | direction: | -| | | | | -| | | | - 0: USBIP_DIR_OUT | -| | | | - 1: USBIP_DIR_IN | -+-----------+--------+------------+---------------------------------------------------+ -| 0x10 | 4 | | ep: endpoint number, possible values are: 0...15 | -+-----------+--------+------------+---------------------------------------------------+ -| 0x14 | 4 | | transfer_flags: possible values depend on the | -| | | | URB transfer type, see below | -+-----------+--------+------------+---------------------------------------------------+ -| 0x18 | 4 | | transfer_buffer_length | -+-----------+--------+------------+---------------------------------------------------+ -| 0x1C | 4 | | start_frame: specify the selected frame to | -| | | | transmit an ISO frame, ignored if URB_ISO_ASAP | -| | | | is specified at transfer_flags | -+-----------+--------+------------+---------------------------------------------------+ -| 0x20 | 4 | | number_of_packets: number of ISO packets | -+-----------+--------+------------+---------------------------------------------------+ -| 0x24 | 4 | | interval: maximum time for the request on the | -| | | | server-side host controller | -+-----------+--------+------------+---------------------------------------------------+ -| 0x28 | 8 | | setup: data bytes for USB setup, filled with | -| | | | zeros if not used | -+-----------+--------+------------+---------------------------------------------------+ -| 0x30 | | | URB data. For ISO transfers the padding between | -| | | | each ISO packets is not transmitted. | -+-----------+--------+------------+---------------------------------------------------+ - - - +-------------------------+------------+---------+-----------+----------+-------------+ - | Allowed transfer_flags | value | control | interrupt | bulk | isochronous | - +=========================+============+=========+===========+==========+=============+ - | URB_SHORT_NOT_OK | 0x00000001 | only in | only in | only in | no | - +-------------------------+------------+---------+-----------+----------+-------------+ - | URB_ISO_ASAP | 0x00000002 | no | no | no | yes | - +-------------------------+------------+---------+-----------+----------+-------------+ - | URB_NO_TRANSFER_DMA_MAP | 0x00000004 | yes | yes | yes | yes | - +-------------------------+------------+---------+-----------+----------+-------------+ - | URB_ZERO_PACKET | 0x00000040 | no | no | only out | no | - +-------------------------+------------+---------+-----------+----------+-------------+ - | URB_NO_INTERRUPT | 0x00000080 | yes | yes | yes | yes | - +-------------------------+------------+---------+-----------+----------+-------------+ - | URB_FREE_BUFFER | 0x00000100 | yes | yes | yes | yes | - +-------------------------+------------+---------+-----------+----------+-------------+ - | URB_DIR_MASK | 0x00000200 | yes | yes | yes | yes | - +-------------------------+------------+---------+-----------+----------+-------------+ - - -USBIP_RET_SUBMIT: - Reply for submitting an URB - -+-----------+--------+------------+---------------------------------------------------+ -| Offset | Length | Value | Description | -+===========+========+============+===================================================+ -| 0 | 4 | 0x00000003 | command | -+-----------+--------+------------+---------------------------------------------------+ -| 4 | 4 | | seqnum: URB sequence number | -+-----------+--------+------------+---------------------------------------------------+ -| 8 | 4 | | devid | -+-----------+--------+------------+---------------------------------------------------+ -| 0xC | 4 | | direction: | -| | | | | -| | | | - 0: USBIP_DIR_OUT | -| | | | - 1: USBIP_DIR_IN | -+-----------+--------+------------+---------------------------------------------------+ -| 0x10 | 4 | | ep: endpoint number | -+-----------+--------+------------+---------------------------------------------------+ -| 0x14 | 4 | | status: zero for successful URB transaction, | -| | | | otherwise some kind of error happened. | -+-----------+--------+------------+---------------------------------------------------+ -| 0x18 | 4 | n | actual_length: number of URB data bytes | -+-----------+--------+------------+---------------------------------------------------+ -| 0x1C | 4 | | start_frame: for an ISO frame the actually | -| | | | selected frame for transmit. | -+-----------+--------+------------+---------------------------------------------------+ -| 0x20 | 4 | | number_of_packets | -+-----------+--------+------------+---------------------------------------------------+ -| 0x24 | 4 | | error_count | -+-----------+--------+------------+---------------------------------------------------+ -| 0x28 | 8 | | setup: data bytes for USB setup, filled with | -| | | | zeros if not used | -+-----------+--------+------------+---------------------------------------------------+ -| 0x30 | n | | URB data bytes. For ISO transfers the padding | -| | | | between each ISO packets is not transmitted. | -+-----------+--------+------------+---------------------------------------------------+ - -USBIP_CMD_UNLINK: - Unlink an URB - -+-----------+--------+------------+---------------------------------------------------+ -| Offset | Length | Value | Description | -+===========+========+============+===================================================+ -| 0 | 4 | 0x00000002 | command: URB unlink command | -+-----------+--------+------------+---------------------------------------------------+ -| 4 | 4 | | seqnum: URB sequence number to unlink: | -| | | | | -| | | | FIXME: | -| | | | is this so? | -+-----------+--------+------------+---------------------------------------------------+ -| 8 | 4 | | devid | -+-----------+--------+------------+---------------------------------------------------+ -| 0xC | 4 | | direction: | -| | | | | -| | | | - 0: USBIP_DIR_OUT | -| | | | - 1: USBIP_DIR_IN | -+-----------+--------+------------+---------------------------------------------------+ -| 0x10 | 4 | | ep: endpoint number: zero | -+-----------+--------+------------+---------------------------------------------------+ -| 0x14 | 4 | | seqnum: the URB sequence number given previously | -| | | | at USBIP_CMD_SUBMIT.seqnum field | -+-----------+--------+------------+---------------------------------------------------+ -| 0x30 | n | | URB data bytes. For ISO transfers the padding | -| | | | between each ISO packets is not transmitted. | -+-----------+--------+------------+---------------------------------------------------+ - -USBIP_RET_UNLINK: - Reply for URB unlink - -+-----------+--------+------------+---------------------------------------------------+ -| Offset | Length | Value | Description | -+===========+========+============+===================================================+ -| 0 | 4 | 0x00000004 | command: reply for the URB unlink command | -+-----------+--------+------------+---------------------------------------------------+ -| 4 | 4 | | seqnum: the unlinked URB sequence number | -+-----------+--------+------------+---------------------------------------------------+ -| 8 | 4 | | devid | -+-----------+--------+------------+---------------------------------------------------+ -| 0xC | 4 | | direction: | -| | | | | -| | | | - 0: USBIP_DIR_OUT | -| | | | - 1: USBIP_DIR_IN | -+-----------+--------+------------+---------------------------------------------------+ -| 0x10 | 4 | | ep: endpoint number | -+-----------+--------+------------+---------------------------------------------------+ -| 0x14 | 4 | | status: This is the value contained in the | -| | | | urb->status in the URB completition handler. | -| | | | | -| | | | FIXME: | -| | | | a better explanation needed. | -+-----------+--------+------------+---------------------------------------------------+ -| 0x30 | n | | URB data bytes. For ISO transfers the padding | -| | | | between each ISO packets is not transmitted. | -+-----------+--------+------------+---------------------------------------------------+ diff --git a/Documentation/usb/usbmon.rst b/Documentation/usb/usbmon.rst new file mode 100644 index 000000000000..b0bd51080799 --- /dev/null +++ b/Documentation/usb/usbmon.rst @@ -0,0 +1,375 @@ +====== +usbmon +====== + +Introduction +============ + +The name "usbmon" in lowercase refers to a facility in kernel which is +used to collect traces of I/O on the USB bus. This function is analogous +to a packet socket used by network monitoring tools such as tcpdump(1) +or Ethereal. Similarly, it is expected that a tool such as usbdump or +USBMon (with uppercase letters) is used to examine raw traces produced +by usbmon. + +The usbmon reports requests made by peripheral-specific drivers to Host +Controller Drivers (HCD). So, if HCD is buggy, the traces reported by +usbmon may not correspond to bus transactions precisely. This is the same +situation as with tcpdump. + +Two APIs are currently implemented: "text" and "binary". The binary API +is available through a character device in /dev namespace and is an ABI. +The text API is deprecated since 2.6.35, but available for convenience. + +How to use usbmon to collect raw text traces +============================================ + +Unlike the packet socket, usbmon has an interface which provides traces +in a text format. This is used for two purposes. First, it serves as a +common trace exchange format for tools while more sophisticated formats +are finalized. Second, humans can read it in case tools are not available. + +To collect a raw text trace, execute following steps. + +1. Prepare +---------- + +Mount debugfs (it has to be enabled in your kernel configuration), and +load the usbmon module (if built as module). The second step is skipped +if usbmon is built into the kernel:: + + # mount -t debugfs none_debugs /sys/kernel/debug + # modprobe usbmon + # + +Verify that bus sockets are present: + + # ls /sys/kernel/debug/usb/usbmon + 0s 0u 1s 1t 1u 2s 2t 2u 3s 3t 3u 4s 4t 4u + # + +Now you can choose to either use the socket '0u' (to capture packets on all +buses), and skip to step #3, or find the bus used by your device with step #2. +This allows to filter away annoying devices that talk continuously. + +2. Find which bus connects to the desired device +------------------------------------------------ + +Run "cat /sys/kernel/debug/usb/devices", and find the T-line which corresponds +to the device. Usually you do it by looking for the vendor string. If you have +many similar devices, unplug one and compare the two +/sys/kernel/debug/usb/devices outputs. The T-line will have a bus number. + +Example:: + + T: Bus=03 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 0 + D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 + P: Vendor=0557 ProdID=2004 Rev= 1.00 + S: Manufacturer=ATEN + S: Product=UC100KM V2.00 + +"Bus=03" means it's bus 3. Alternatively, you can look at the output from +"lsusb" and get the bus number from the appropriate line. Example: + +Bus 003 Device 002: ID 0557:2004 ATEN UC100KM V2.00 + +3. Start 'cat' +-------------- + +:: + + # cat /sys/kernel/debug/usb/usbmon/3u > /tmp/1.mon.out + +to listen on a single bus, otherwise, to listen on all buses, type:: + + # cat /sys/kernel/debug/usb/usbmon/0u > /tmp/1.mon.out + +This process will read until it is killed. Naturally, the output can be +redirected to a desirable location. This is preferred, because it is going +to be quite long. + +4. Perform the desired operation on the USB bus +----------------------------------------------- + +This is where you do something that creates the traffic: plug in a flash key, +copy files, control a webcam, etc. + +5. Kill cat +----------- + +Usually it's done with a keyboard interrupt (Control-C). + +At this point the output file (/tmp/1.mon.out in this example) can be saved, +sent by e-mail, or inspected with a text editor. In the last case make sure +that the file size is not excessive for your favourite editor. + +Raw text data format +==================== + +Two formats are supported currently: the original, or '1t' format, and +the '1u' format. The '1t' format is deprecated in kernel 2.6.21. The '1u' +format adds a few fields, such as ISO frame descriptors, interval, etc. +It produces slightly longer lines, but otherwise is a perfect superset +of '1t' format. + +If it is desired to recognize one from the other in a program, look at the +"address" word (see below), where '1u' format adds a bus number. If 2 colons +are present, it's the '1t' format, otherwise '1u'. + +Any text format data consists of a stream of events, such as URB submission, +URB callback, submission error. Every event is a text line, which consists +of whitespace separated words. The number or position of words may depend +on the event type, but there is a set of words, common for all types. + +Here is the list of words, from left to right: + +- URB Tag. This is used to identify URBs, and is normally an in-kernel address + of the URB structure in hexadecimal, but can be a sequence number or any + other unique string, within reason. + +- Timestamp in microseconds, a decimal number. The timestamp's resolution + depends on available clock, and so it can be much worse than a microsecond + (if the implementation uses jiffies, for example). + +- Event Type. This type refers to the format of the event, not URB type. + Available types are: S - submission, C - callback, E - submission error. + +- "Address" word (formerly a "pipe"). It consists of four fields, separated by + colons: URB type and direction, Bus number, Device address, Endpoint number. + Type and direction are encoded with two bytes in the following manner: + + == == ============================= + Ci Co Control input and output + Zi Zo Isochronous input and output + Ii Io Interrupt input and output + Bi Bo Bulk input and output + == == ============================= + + Bus number, Device address, and Endpoint are decimal numbers, but they may + have leading zeros, for the sake of human readers. + +- URB Status word. This is either a letter, or several numbers separated + by colons: URB status, interval, start frame, and error count. Unlike the + "address" word, all fields save the status are optional. Interval is printed + only for interrupt and isochronous URBs. Start frame is printed only for + isochronous URBs. Error count is printed only for isochronous callback + events. + + The status field is a decimal number, sometimes negative, which represents + a "status" field of the URB. This field makes no sense for submissions, but + is present anyway to help scripts with parsing. When an error occurs, the + field contains the error code. + + In case of a submission of a Control packet, this field contains a Setup Tag + instead of an group of numbers. It is easy to tell whether the Setup Tag is + present because it is never a number. Thus if scripts find a set of numbers + in this word, they proceed to read Data Length (except for isochronous URBs). + If they find something else, like a letter, they read the setup packet before + reading the Data Length or isochronous descriptors. + +- Setup packet, if present, consists of 5 words: one of each for bmRequestType, + bRequest, wValue, wIndex, wLength, as specified by the USB Specification 2.0. + These words are safe to decode if Setup Tag was 's'. Otherwise, the setup + packet was present, but not captured, and the fields contain filler. + +- Number of isochronous frame descriptors and descriptors themselves. + If an Isochronous transfer event has a set of descriptors, a total number + of them in an URB is printed first, then a word per descriptor, up to a + total of 5. The word consists of 3 colon-separated decimal numbers for + status, offset, and length respectively. For submissions, initial length + is reported. For callbacks, actual length is reported. + +- Data Length. For submissions, this is the requested length. For callbacks, + this is the actual length. + +- Data tag. The usbmon may not always capture data, even if length is nonzero. + The data words are present only if this tag is '='. + +- Data words follow, in big endian hexadecimal format. Notice that they are + not machine words, but really just a byte stream split into words to make + it easier to read. Thus, the last word may contain from one to four bytes. + The length of collected data is limited and can be less than the data length + reported in the Data Length word. In the case of an Isochronous input (Zi) + completion where the received data is sparse in the buffer, the length of + the collected data can be greater than the Data Length value (because Data + Length counts only the bytes that were received whereas the Data words + contain the entire transfer buffer). + +Examples: + +An input control transfer to get a port status:: + + d5ea89a0 3575914555 S Ci:1:001:0 s a3 00 0000 0003 0004 4 < + d5ea89a0 3575914560 C Ci:1:001:0 0 4 = 01050000 + +An output bulk transfer to send a SCSI command 0x28 (READ_10) in a 31-byte +Bulk wrapper to a storage device at address 5:: + + dd65f0e8 4128379752 S Bo:1:005:2 -115 31 = 55534243 ad000000 00800000 80010a28 20000000 20000040 00000000 000000 + dd65f0e8 4128379808 C Bo:1:005:2 0 31 > + +Raw binary format and API +========================= + +The overall architecture of the API is about the same as the one above, +only the events are delivered in binary format. Each event is sent in +the following structure (its name is made up, so that we can refer to it):: + + struct usbmon_packet { + u64 id; /* 0: URB ID - from submission to callback */ + unsigned char type; /* 8: Same as text; extensible. */ + unsigned char xfer_type; /* ISO (0), Intr, Control, Bulk (3) */ + unsigned char epnum; /* Endpoint number and transfer direction */ + unsigned char devnum; /* Device address */ + u16 busnum; /* 12: Bus number */ + char flag_setup; /* 14: Same as text */ + char flag_data; /* 15: Same as text; Binary zero is OK. */ + s64 ts_sec; /* 16: gettimeofday */ + s32 ts_usec; /* 24: gettimeofday */ + int status; /* 28: */ + unsigned int length; /* 32: Length of data (submitted or actual) */ + unsigned int len_cap; /* 36: Delivered length */ + union { /* 40: */ + unsigned char setup[SETUP_LEN]; /* Only for Control S-type */ + struct iso_rec { /* Only for ISO */ + int error_count; + int numdesc; + } iso; + } s; + int interval; /* 48: Only for Interrupt and ISO */ + int start_frame; /* 52: For ISO */ + unsigned int xfer_flags; /* 56: copy of URB's transfer_flags */ + unsigned int ndesc; /* 60: Actual number of ISO descriptors */ + }; /* 64 total length */ + +These events can be received from a character device by reading with read(2), +with an ioctl(2), or by accessing the buffer with mmap. However, read(2) +only returns first 48 bytes for compatibility reasons. + +The character device is usually called /dev/usbmonN, where N is the USB bus +number. Number zero (/dev/usbmon0) is special and means "all buses". +Note that specific naming policy is set by your Linux distribution. + +If you create /dev/usbmon0 by hand, make sure that it is owned by root +and has mode 0600. Otherwise, unprivileged users will be able to snoop +keyboard traffic. + +The following ioctl calls are available, with MON_IOC_MAGIC 0x92: + + MON_IOCQ_URB_LEN, defined as _IO(MON_IOC_MAGIC, 1) + +This call returns the length of data in the next event. Note that majority of +events contain no data, so if this call returns zero, it does not mean that +no events are available. + + MON_IOCG_STATS, defined as _IOR(MON_IOC_MAGIC, 3, struct mon_bin_stats) + +The argument is a pointer to the following structure:: + + struct mon_bin_stats { + u32 queued; + u32 dropped; + }; + +The member "queued" refers to the number of events currently queued in the +buffer (and not to the number of events processed since the last reset). + +The member "dropped" is the number of events lost since the last call +to MON_IOCG_STATS. + + MON_IOCT_RING_SIZE, defined as _IO(MON_IOC_MAGIC, 4) + +This call sets the buffer size. The argument is the size in bytes. +The size may be rounded down to the next chunk (or page). If the requested +size is out of [unspecified] bounds for this kernel, the call fails with +-EINVAL. + + MON_IOCQ_RING_SIZE, defined as _IO(MON_IOC_MAGIC, 5) + +This call returns the current size of the buffer in bytes. + + MON_IOCX_GET, defined as _IOW(MON_IOC_MAGIC, 6, struct mon_get_arg) + MON_IOCX_GETX, defined as _IOW(MON_IOC_MAGIC, 10, struct mon_get_arg) + +These calls wait for events to arrive if none were in the kernel buffer, +then return the first event. The argument is a pointer to the following +structure:: + + struct mon_get_arg { + struct usbmon_packet *hdr; + void *data; + size_t alloc; /* Length of data (can be zero) */ + }; + +Before the call, hdr, data, and alloc should be filled. Upon return, the area +pointed by hdr contains the next event structure, and the data buffer contains +the data, if any. The event is removed from the kernel buffer. + +The MON_IOCX_GET copies 48 bytes to hdr area, MON_IOCX_GETX copies 64 bytes. + + MON_IOCX_MFETCH, defined as _IOWR(MON_IOC_MAGIC, 7, struct mon_mfetch_arg) + +This ioctl is primarily used when the application accesses the buffer +with mmap(2). Its argument is a pointer to the following structure:: + + struct mon_mfetch_arg { + uint32_t *offvec; /* Vector of events fetched */ + uint32_t nfetch; /* Number of events to fetch (out: fetched) */ + uint32_t nflush; /* Number of events to flush */ + }; + +The ioctl operates in 3 stages. + +First, it removes and discards up to nflush events from the kernel buffer. +The actual number of events discarded is returned in nflush. + +Second, it waits for an event to be present in the buffer, unless the pseudo- +device is open with O_NONBLOCK. + +Third, it extracts up to nfetch offsets into the mmap buffer, and stores +them into the offvec. The actual number of event offsets is stored into +the nfetch. + + MON_IOCH_MFLUSH, defined as _IO(MON_IOC_MAGIC, 8) + +This call removes a number of events from the kernel buffer. Its argument +is the number of events to remove. If the buffer contains fewer events +than requested, all events present are removed, and no error is reported. +This works when no events are available too. + + FIONBIO + +The ioctl FIONBIO may be implemented in the future, if there's a need. + +In addition to ioctl(2) and read(2), the special file of binary API can +be polled with select(2) and poll(2). But lseek(2) does not work. + +* Memory-mapped access of the kernel buffer for the binary API + +The basic idea is simple: + +To prepare, map the buffer by getting the current size, then using mmap(2). +Then, execute a loop similar to the one written in pseudo-code below:: + + struct mon_mfetch_arg fetch; + struct usbmon_packet *hdr; + int nflush = 0; + for (;;) { + fetch.offvec = vec; // Has N 32-bit words + fetch.nfetch = N; // Or less than N + fetch.nflush = nflush; + ioctl(fd, MON_IOCX_MFETCH, &fetch); // Process errors, too + nflush = fetch.nfetch; // This many packets to flush when done + for (i = 0; i < nflush; i++) { + hdr = (struct ubsmon_packet *) &mmap_area[vec[i]]; + if (hdr->type == '@') // Filler packet + continue; + caddr_t data = &mmap_area[vec[i]] + 64; + process_packet(hdr, data); + } + } + +Thus, the main idea is to execute only one ioctl per N events. + +Although the buffer is circular, the returned headers and data do not cross +the end of the buffer, so the above pseudo-code does not need any gathering. diff --git a/Documentation/usb/usbmon.txt b/Documentation/usb/usbmon.txt deleted file mode 100644 index b0bd51080799..000000000000 --- a/Documentation/usb/usbmon.txt +++ /dev/null @@ -1,375 +0,0 @@ -====== -usbmon -====== - -Introduction -============ - -The name "usbmon" in lowercase refers to a facility in kernel which is -used to collect traces of I/O on the USB bus. This function is analogous -to a packet socket used by network monitoring tools such as tcpdump(1) -or Ethereal. Similarly, it is expected that a tool such as usbdump or -USBMon (with uppercase letters) is used to examine raw traces produced -by usbmon. - -The usbmon reports requests made by peripheral-specific drivers to Host -Controller Drivers (HCD). So, if HCD is buggy, the traces reported by -usbmon may not correspond to bus transactions precisely. This is the same -situation as with tcpdump. - -Two APIs are currently implemented: "text" and "binary". The binary API -is available through a character device in /dev namespace and is an ABI. -The text API is deprecated since 2.6.35, but available for convenience. - -How to use usbmon to collect raw text traces -============================================ - -Unlike the packet socket, usbmon has an interface which provides traces -in a text format. This is used for two purposes. First, it serves as a -common trace exchange format for tools while more sophisticated formats -are finalized. Second, humans can read it in case tools are not available. - -To collect a raw text trace, execute following steps. - -1. Prepare ----------- - -Mount debugfs (it has to be enabled in your kernel configuration), and -load the usbmon module (if built as module). The second step is skipped -if usbmon is built into the kernel:: - - # mount -t debugfs none_debugs /sys/kernel/debug - # modprobe usbmon - # - -Verify that bus sockets are present: - - # ls /sys/kernel/debug/usb/usbmon - 0s 0u 1s 1t 1u 2s 2t 2u 3s 3t 3u 4s 4t 4u - # - -Now you can choose to either use the socket '0u' (to capture packets on all -buses), and skip to step #3, or find the bus used by your device with step #2. -This allows to filter away annoying devices that talk continuously. - -2. Find which bus connects to the desired device ------------------------------------------------- - -Run "cat /sys/kernel/debug/usb/devices", and find the T-line which corresponds -to the device. Usually you do it by looking for the vendor string. If you have -many similar devices, unplug one and compare the two -/sys/kernel/debug/usb/devices outputs. The T-line will have a bus number. - -Example:: - - T: Bus=03 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 0 - D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 - P: Vendor=0557 ProdID=2004 Rev= 1.00 - S: Manufacturer=ATEN - S: Product=UC100KM V2.00 - -"Bus=03" means it's bus 3. Alternatively, you can look at the output from -"lsusb" and get the bus number from the appropriate line. Example: - -Bus 003 Device 002: ID 0557:2004 ATEN UC100KM V2.00 - -3. Start 'cat' --------------- - -:: - - # cat /sys/kernel/debug/usb/usbmon/3u > /tmp/1.mon.out - -to listen on a single bus, otherwise, to listen on all buses, type:: - - # cat /sys/kernel/debug/usb/usbmon/0u > /tmp/1.mon.out - -This process will read until it is killed. Naturally, the output can be -redirected to a desirable location. This is preferred, because it is going -to be quite long. - -4. Perform the desired operation on the USB bus ------------------------------------------------ - -This is where you do something that creates the traffic: plug in a flash key, -copy files, control a webcam, etc. - -5. Kill cat ------------ - -Usually it's done with a keyboard interrupt (Control-C). - -At this point the output file (/tmp/1.mon.out in this example) can be saved, -sent by e-mail, or inspected with a text editor. In the last case make sure -that the file size is not excessive for your favourite editor. - -Raw text data format -==================== - -Two formats are supported currently: the original, or '1t' format, and -the '1u' format. The '1t' format is deprecated in kernel 2.6.21. The '1u' -format adds a few fields, such as ISO frame descriptors, interval, etc. -It produces slightly longer lines, but otherwise is a perfect superset -of '1t' format. - -If it is desired to recognize one from the other in a program, look at the -"address" word (see below), where '1u' format adds a bus number. If 2 colons -are present, it's the '1t' format, otherwise '1u'. - -Any text format data consists of a stream of events, such as URB submission, -URB callback, submission error. Every event is a text line, which consists -of whitespace separated words. The number or position of words may depend -on the event type, but there is a set of words, common for all types. - -Here is the list of words, from left to right: - -- URB Tag. This is used to identify URBs, and is normally an in-kernel address - of the URB structure in hexadecimal, but can be a sequence number or any - other unique string, within reason. - -- Timestamp in microseconds, a decimal number. The timestamp's resolution - depends on available clock, and so it can be much worse than a microsecond - (if the implementation uses jiffies, for example). - -- Event Type. This type refers to the format of the event, not URB type. - Available types are: S - submission, C - callback, E - submission error. - -- "Address" word (formerly a "pipe"). It consists of four fields, separated by - colons: URB type and direction, Bus number, Device address, Endpoint number. - Type and direction are encoded with two bytes in the following manner: - - == == ============================= - Ci Co Control input and output - Zi Zo Isochronous input and output - Ii Io Interrupt input and output - Bi Bo Bulk input and output - == == ============================= - - Bus number, Device address, and Endpoint are decimal numbers, but they may - have leading zeros, for the sake of human readers. - -- URB Status word. This is either a letter, or several numbers separated - by colons: URB status, interval, start frame, and error count. Unlike the - "address" word, all fields save the status are optional. Interval is printed - only for interrupt and isochronous URBs. Start frame is printed only for - isochronous URBs. Error count is printed only for isochronous callback - events. - - The status field is a decimal number, sometimes negative, which represents - a "status" field of the URB. This field makes no sense for submissions, but - is present anyway to help scripts with parsing. When an error occurs, the - field contains the error code. - - In case of a submission of a Control packet, this field contains a Setup Tag - instead of an group of numbers. It is easy to tell whether the Setup Tag is - present because it is never a number. Thus if scripts find a set of numbers - in this word, they proceed to read Data Length (except for isochronous URBs). - If they find something else, like a letter, they read the setup packet before - reading the Data Length or isochronous descriptors. - -- Setup packet, if present, consists of 5 words: one of each for bmRequestType, - bRequest, wValue, wIndex, wLength, as specified by the USB Specification 2.0. - These words are safe to decode if Setup Tag was 's'. Otherwise, the setup - packet was present, but not captured, and the fields contain filler. - -- Number of isochronous frame descriptors and descriptors themselves. - If an Isochronous transfer event has a set of descriptors, a total number - of them in an URB is printed first, then a word per descriptor, up to a - total of 5. The word consists of 3 colon-separated decimal numbers for - status, offset, and length respectively. For submissions, initial length - is reported. For callbacks, actual length is reported. - -- Data Length. For submissions, this is the requested length. For callbacks, - this is the actual length. - -- Data tag. The usbmon may not always capture data, even if length is nonzero. - The data words are present only if this tag is '='. - -- Data words follow, in big endian hexadecimal format. Notice that they are - not machine words, but really just a byte stream split into words to make - it easier to read. Thus, the last word may contain from one to four bytes. - The length of collected data is limited and can be less than the data length - reported in the Data Length word. In the case of an Isochronous input (Zi) - completion where the received data is sparse in the buffer, the length of - the collected data can be greater than the Data Length value (because Data - Length counts only the bytes that were received whereas the Data words - contain the entire transfer buffer). - -Examples: - -An input control transfer to get a port status:: - - d5ea89a0 3575914555 S Ci:1:001:0 s a3 00 0000 0003 0004 4 < - d5ea89a0 3575914560 C Ci:1:001:0 0 4 = 01050000 - -An output bulk transfer to send a SCSI command 0x28 (READ_10) in a 31-byte -Bulk wrapper to a storage device at address 5:: - - dd65f0e8 4128379752 S Bo:1:005:2 -115 31 = 55534243 ad000000 00800000 80010a28 20000000 20000040 00000000 000000 - dd65f0e8 4128379808 C Bo:1:005:2 0 31 > - -Raw binary format and API -========================= - -The overall architecture of the API is about the same as the one above, -only the events are delivered in binary format. Each event is sent in -the following structure (its name is made up, so that we can refer to it):: - - struct usbmon_packet { - u64 id; /* 0: URB ID - from submission to callback */ - unsigned char type; /* 8: Same as text; extensible. */ - unsigned char xfer_type; /* ISO (0), Intr, Control, Bulk (3) */ - unsigned char epnum; /* Endpoint number and transfer direction */ - unsigned char devnum; /* Device address */ - u16 busnum; /* 12: Bus number */ - char flag_setup; /* 14: Same as text */ - char flag_data; /* 15: Same as text; Binary zero is OK. */ - s64 ts_sec; /* 16: gettimeofday */ - s32 ts_usec; /* 24: gettimeofday */ - int status; /* 28: */ - unsigned int length; /* 32: Length of data (submitted or actual) */ - unsigned int len_cap; /* 36: Delivered length */ - union { /* 40: */ - unsigned char setup[SETUP_LEN]; /* Only for Control S-type */ - struct iso_rec { /* Only for ISO */ - int error_count; - int numdesc; - } iso; - } s; - int interval; /* 48: Only for Interrupt and ISO */ - int start_frame; /* 52: For ISO */ - unsigned int xfer_flags; /* 56: copy of URB's transfer_flags */ - unsigned int ndesc; /* 60: Actual number of ISO descriptors */ - }; /* 64 total length */ - -These events can be received from a character device by reading with read(2), -with an ioctl(2), or by accessing the buffer with mmap. However, read(2) -only returns first 48 bytes for compatibility reasons. - -The character device is usually called /dev/usbmonN, where N is the USB bus -number. Number zero (/dev/usbmon0) is special and means "all buses". -Note that specific naming policy is set by your Linux distribution. - -If you create /dev/usbmon0 by hand, make sure that it is owned by root -and has mode 0600. Otherwise, unprivileged users will be able to snoop -keyboard traffic. - -The following ioctl calls are available, with MON_IOC_MAGIC 0x92: - - MON_IOCQ_URB_LEN, defined as _IO(MON_IOC_MAGIC, 1) - -This call returns the length of data in the next event. Note that majority of -events contain no data, so if this call returns zero, it does not mean that -no events are available. - - MON_IOCG_STATS, defined as _IOR(MON_IOC_MAGIC, 3, struct mon_bin_stats) - -The argument is a pointer to the following structure:: - - struct mon_bin_stats { - u32 queued; - u32 dropped; - }; - -The member "queued" refers to the number of events currently queued in the -buffer (and not to the number of events processed since the last reset). - -The member "dropped" is the number of events lost since the last call -to MON_IOCG_STATS. - - MON_IOCT_RING_SIZE, defined as _IO(MON_IOC_MAGIC, 4) - -This call sets the buffer size. The argument is the size in bytes. -The size may be rounded down to the next chunk (or page). If the requested -size is out of [unspecified] bounds for this kernel, the call fails with --EINVAL. - - MON_IOCQ_RING_SIZE, defined as _IO(MON_IOC_MAGIC, 5) - -This call returns the current size of the buffer in bytes. - - MON_IOCX_GET, defined as _IOW(MON_IOC_MAGIC, 6, struct mon_get_arg) - MON_IOCX_GETX, defined as _IOW(MON_IOC_MAGIC, 10, struct mon_get_arg) - -These calls wait for events to arrive if none were in the kernel buffer, -then return the first event. The argument is a pointer to the following -structure:: - - struct mon_get_arg { - struct usbmon_packet *hdr; - void *data; - size_t alloc; /* Length of data (can be zero) */ - }; - -Before the call, hdr, data, and alloc should be filled. Upon return, the area -pointed by hdr contains the next event structure, and the data buffer contains -the data, if any. The event is removed from the kernel buffer. - -The MON_IOCX_GET copies 48 bytes to hdr area, MON_IOCX_GETX copies 64 bytes. - - MON_IOCX_MFETCH, defined as _IOWR(MON_IOC_MAGIC, 7, struct mon_mfetch_arg) - -This ioctl is primarily used when the application accesses the buffer -with mmap(2). Its argument is a pointer to the following structure:: - - struct mon_mfetch_arg { - uint32_t *offvec; /* Vector of events fetched */ - uint32_t nfetch; /* Number of events to fetch (out: fetched) */ - uint32_t nflush; /* Number of events to flush */ - }; - -The ioctl operates in 3 stages. - -First, it removes and discards up to nflush events from the kernel buffer. -The actual number of events discarded is returned in nflush. - -Second, it waits for an event to be present in the buffer, unless the pseudo- -device is open with O_NONBLOCK. - -Third, it extracts up to nfetch offsets into the mmap buffer, and stores -them into the offvec. The actual number of event offsets is stored into -the nfetch. - - MON_IOCH_MFLUSH, defined as _IO(MON_IOC_MAGIC, 8) - -This call removes a number of events from the kernel buffer. Its argument -is the number of events to remove. If the buffer contains fewer events -than requested, all events present are removed, and no error is reported. -This works when no events are available too. - - FIONBIO - -The ioctl FIONBIO may be implemented in the future, if there's a need. - -In addition to ioctl(2) and read(2), the special file of binary API can -be polled with select(2) and poll(2). But lseek(2) does not work. - -* Memory-mapped access of the kernel buffer for the binary API - -The basic idea is simple: - -To prepare, map the buffer by getting the current size, then using mmap(2). -Then, execute a loop similar to the one written in pseudo-code below:: - - struct mon_mfetch_arg fetch; - struct usbmon_packet *hdr; - int nflush = 0; - for (;;) { - fetch.offvec = vec; // Has N 32-bit words - fetch.nfetch = N; // Or less than N - fetch.nflush = nflush; - ioctl(fd, MON_IOCX_MFETCH, &fetch); // Process errors, too - nflush = fetch.nfetch; // This many packets to flush when done - for (i = 0; i < nflush; i++) { - hdr = (struct ubsmon_packet *) &mmap_area[vec[i]]; - if (hdr->type == '@') // Filler packet - continue; - caddr_t data = &mmap_area[vec[i]] + 64; - process_packet(hdr, data); - } - } - -Thus, the main idea is to execute only one ioctl per N events. - -Although the buffer is circular, the returned headers and data do not cross -the end of the buffer, so the above pseudo-code does not need any gathering. diff --git a/Documentation/usb/wusb-design-overview.rst b/Documentation/usb/wusb-design-overview.rst new file mode 100644 index 000000000000..dc5e21609bb5 --- /dev/null +++ b/Documentation/usb/wusb-design-overview.rst @@ -0,0 +1,457 @@ +================================ +Linux UWB + Wireless USB + WiNET +================================ + + Copyright (C) 2005-2006 Intel Corporation + + Inaky Perez-Gonzalez + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License version + 2 as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + +Please visit http://bughost.org/thewiki/Design-overview.txt-1.8 for +updated content. + + * Design-overview.txt-1.8 + +This code implements a Ultra Wide Band stack for Linux, as well as +drivers for the USB based UWB radio controllers defined in the +Wireless USB 1.0 specification (including Wireless USB host controller +and an Intel WiNET controller). + +.. Contents + 1. Introduction + 1. HWA: Host Wire adapters, your Wireless USB dongle + + 2. DWA: Device Wired Adaptor, a Wireless USB hub for wired + devices + 3. WHCI: Wireless Host Controller Interface, the PCI WUSB host + adapter + 2. The UWB stack + 1. Devices and hosts: the basic structure + + 2. Host Controller life cycle + + 3. On the air: beacons and enumerating the radio neighborhood + + 4. Device lists + 5. Bandwidth allocation + + 3. Wireless USB Host Controller drivers + + 4. Glossary + + +Introduction +============ + +UWB is a wide-band communication protocol that is to serve also as the +low-level protocol for others (much like TCP sits on IP). Currently +these others are Wireless USB and TCP/IP, but seems Bluetooth and +Firewire/1394 are coming along. + +UWB uses a band from roughly 3 to 10 GHz, transmitting at a max of +~-41dB (or 0.074 uW/MHz--geography specific data is still being +negotiated w/ regulators, so watch for changes). That band is divided in +a bunch of ~1.5 GHz wide channels (or band groups) composed of three +subbands/subchannels (528 MHz each). Each channel is independent of each +other, so you could consider them different "busses". Initially this +driver considers them all a single one. + +Radio time is divided in 65536 us long /superframes/, each one divided +in 256 256us long /MASs/ (Media Allocation Slots), which are the basic +time/media allocation units for transferring data. At the beginning of +each superframe there is a Beacon Period (BP), where every device +transmit its beacon on a single MAS. The length of the BP depends on how +many devices are present and the length of their beacons. + +Devices have a MAC (fixed, 48 bit address) and a device (changeable, 16 +bit address) and send periodic beacons to advertise themselves and pass +info on what they are and do. They advertise their capabilities and a +bunch of other stuff. + +The different logical parts of this driver are: + + * + + *UWB*: the Ultra-Wide-Band stack -- manages the radio and + associated spectrum to allow for devices sharing it. Allows to + control bandwidth assignment, beaconing, scanning, etc + + * + + *WUSB*: the layer that sits on top of UWB to provide Wireless USB. + The Wireless USB spec defines means to control a UWB radio and to + do the actual WUSB. + + +HWA: Host Wire adapters, your Wireless USB dongle +------------------------------------------------- + +WUSB also defines a device called a Host Wire Adaptor (HWA), which in +mere terms is a USB dongle that enables your PC to have UWB and Wireless +USB. The Wireless USB Host Controller in a HWA looks to the host like a +[Wireless] USB controller connected via USB (!) + +The HWA itself is broken in two or three main interfaces: + + * + + *RC*: Radio control -- this implements an interface to the + Ultra-Wide-Band radio controller. The driver for this implements a + USB-based UWB Radio Controller to the UWB stack. + + * + + *HC*: the wireless USB host controller. It looks like a USB host + whose root port is the radio and the WUSB devices connect to it. + To the system it looks like a separate USB host. The driver (will) + implement a USB host controller (similar to UHCI, OHCI or EHCI) + for which the root hub is the radio...To reiterate: it is a USB + controller that is connected via USB instead of PCI. + + * + + *WINET*: some HW provide a WiNET interface (IP over UWB). This + package provides a driver for it (it looks like a network + interface, winetX). The driver detects when there is a link up for + their type and kick into gear. + + +DWA: Device Wired Adaptor, a Wireless USB hub for wired devices +--------------------------------------------------------------- + +These are the complement to HWAs. They are a USB host for connecting +wired devices, but it is connected to your PC connected via Wireless +USB. To the system it looks like yet another USB host. To the untrained +eye, it looks like a hub that connects upstream wirelessly. + +We still offer no support for this; however, it should share a lot of +code with the HWA-RC driver; there is a bunch of factorization work that +has been done to support that in upcoming releases. + + +WHCI: Wireless Host Controller Interface, the PCI WUSB host adapter +------------------------------------------------------------------- + +This is your usual PCI device that implements WHCI. Similar in concept +to EHCI, it allows your wireless USB devices (including DWAs) to connect +to your host via a PCI interface. As in the case of the HWA, it has a +Radio Control interface and the WUSB Host Controller interface per se. + +There is still no driver support for this, but will be in upcoming +releases. + + +The UWB stack +============= + +The main mission of the UWB stack is to keep a tally of which devices +are in radio proximity to allow drivers to connect to them. As well, it +provides an API for controlling the local radio controllers (RCs from +now on), such as to start/stop beaconing, scan, allocate bandwidth, etc. + + +Devices and hosts: the basic structure +-------------------------------------- + +The main building block here is the UWB device (struct uwb_dev). For +each device that pops up in radio presence (ie: the UWB host receives a +beacon from it) you get a struct uwb_dev that will show up in +/sys/bus/uwb/devices. + +For each RC that is detected, a new struct uwb_rc and struct uwb_dev are +created. An entry is also created in /sys/class/uwb_rc for each RC. + +Each RC driver is implemented by a separate driver that plugs into the +interface that the UWB stack provides through a struct uwb_rc_ops. The +spec creators have been nice enough to make the message format the same +for HWA and WHCI RCs, so the driver is really a very thin transport that +moves the requests from the UWB API to the device [/uwb_rc_ops->cmd()/] +and sends the replies and notifications back to the API +[/uwb_rc_neh_grok()/]. Notifications are handled to the UWB daemon, that +is chartered, among other things, to keep the tab of how the UWB radio +neighborhood looks, creating and destroying devices as they show up or +disappear. + +Command execution is very simple: a command block is sent and a event +block or reply is expected back. For sending/receiving command/events, a +handle called /neh/ (Notification/Event Handle) is opened with +/uwb_rc_neh_open()/. + +The HWA-RC (USB dongle) driver (drivers/uwb/hwa-rc.c) does this job for +the USB connected HWA. Eventually, drivers/whci-rc.c will do the same +for the PCI connected WHCI controller. + + +Host Controller life cycle +-------------------------- + +So let's say we connect a dongle to the system: it is detected and +firmware uploaded if needed [for Intel's i1480 +/drivers/uwb/ptc/usb.c:ptc_usb_probe()/] and then it is reenumerated. +Now we have a real HWA device connected and +/drivers/uwb/hwa-rc.c:hwarc_probe()/ picks it up, that will set up the +Wire-Adaptor environment and then suck it into the UWB stack's vision of +the world [/drivers/uwb/lc-rc.c:uwb_rc_add()/]. + + * + + [*] The stack should put a new RC to scan for devices + [/uwb_rc_scan()/] so it finds what's available around and tries to + connect to them, but this is policy stuff and should be driven + from user space. As of now, the operator is expected to do it + manually; see the release notes for documentation on the procedure. + +When a dongle is disconnected, /drivers/uwb/hwa-rc.c:hwarc_disconnect()/ +takes time of tearing everything down safely (or not...). + + +On the air: beacons and enumerating the radio neighborhood +---------------------------------------------------------- + +So assuming we have devices and we have agreed for a channel to connect +on (let's say 9), we put the new RC to beacon: + + * + + $ echo 9 0 > /sys/class/uwb_rc/uwb0/beacon + +Now it is visible. If there were other devices in the same radio channel +and beacon group (that's what the zero is for), the dongle's radio +control interface will send beacon notifications on its +notification/event endpoint (NEEP). The beacon notifications are part of +the event stream that is funneled into the API with +/drivers/uwb/neh.c:uwb_rc_neh_grok()/ and delivered to the UWBD, the UWB +daemon through a notification list. + +UWBD wakes up and scans the event list; finds a beacon and adds it to +the BEACON CACHE (/uwb_beca/). If he receives a number of beacons from +the same device, he considers it to be 'onair' and creates a new device +[/drivers/uwb/lc-dev.c:uwbd_dev_onair()/]. Similarly, when no beacons +are received in some time, the device is considered gone and wiped out +[uwbd calls periodically /uwb/beacon.c:uwb_beca_purge()/ that will purge +the beacon cache of dead devices]. + + +Device lists +------------ + +All UWB devices are kept in the list of the struct bus_type uwb_bus_type. + + +Bandwidth allocation +-------------------- + +The UWB stack maintains a local copy of DRP availability through +processing of incoming *DRP Availability Change* notifications. This +local copy is currently used to present the current bandwidth +availability to the user through the sysfs file +/sys/class/uwb_rc/uwbx/bw_avail. In the future the bandwidth +availability information will be used by the bandwidth reservation +routines. + +The bandwidth reservation routines are in progress and are thus not +present in the current release. When completed they will enable a user +to initiate DRP reservation requests through interaction with sysfs. DRP +reservation requests from remote UWB devices will also be handled. The +bandwidth management done by the UWB stack will include callbacks to the +higher layers will enable the higher layers to use the reservations upon +completion. [Note: The bandwidth reservation work is in progress and +subject to change.] + + +Wireless USB Host Controller drivers +==================================== + +*WARNING* This section needs a lot of work! + +As explained above, there are three different types of HCs in the WUSB +world: HWA-HC, DWA-HC and WHCI-HC. + +HWA-HC and DWA-HC share that they are Wire-Adapters (USB or WUSB +connected controllers), and their transfer management system is almost +identical. So is their notification delivery system. + +HWA-HC and WHCI-HC share that they are both WUSB host controllers, so +they have to deal with WUSB device life cycle and maintenance, wireless +root-hub + +HWA exposes a Host Controller interface (HWA-HC 0xe0/02/02). This has +three endpoints (Notifications, Data Transfer In and Data Transfer +Out--known as NEP, DTI and DTO in the code). + +We reserve UWB bandwidth for our Wireless USB Cluster, create a Cluster +ID and tell the HC to use all that. Then we start it. This means the HC +starts sending MMCs. + + * + + The MMCs are blocks of data defined somewhere in the WUSB1.0 spec + that define a stream in the UWB channel time allocated for sending + WUSB IEs (host to device commands/notifications) and Device + Notifications (device initiated to host). Each host defines a + unique Wireless USB cluster through MMCs. Devices can connect to a + single cluster at the time. The IEs are Information Elements, and + among them are the bandwidth allocations that tell each device + when can they transmit or receive. + +Now it all depends on external stimuli. + +New device connection +--------------------- + +A new device pops up, it scans the radio looking for MMCs that give out +the existence of Wireless USB channels. Once one (or more) are found, +selects which one to connect to. Sends a /DN_Connect/ (device +notification connect) during the DNTS (Device Notification Time +Slot--announced in the MMCs + +HC picks the /DN_Connect/ out (nep module sends to notif.c for delivery +into /devconnect/). This process starts the authentication process for +the device. First we allocate a /fake port/ and assign an +unauthenticated address (128 to 255--what we really do is +0x80 | fake_port_idx). We fiddle with the fake port status and /hub_wq/ +sees a new connection, so he moves on to enable the fake port with a reset. + +So now we are in the reset path -- we know we have a non-yet enumerated +device with an unauthorized address; we ask user space to authenticate +(FIXME: not yet done, similar to bluetooth pairing), then we do the key +exchange (FIXME: not yet done) and issue a /set address 0/ to bring the +device to the default state. Device is authenticated. + +From here, the USB stack takes control through the usb_hcd ops. hub_wq +has seen the port status changes, as we have been toggling them. It will +start enumerating and doing transfers through usb_hcd->urb_enqueue() to +read descriptors and move our data. + +Device life cycle and keep alives +--------------------------------- + +Every time there is a successful transfer to/from a device, we update a +per-device activity timestamp. If not, every now and then we check and +if the activity timestamp gets old, we ping the device by sending it a +Keep Alive IE; it responds with a /DN_Alive/ pong during the DNTS (this +arrives to us as a notification through +devconnect.c:wusb_handle_dn_alive(). If a device times out, we +disconnect it from the system (cleaning up internal information and +toggling the bits in the fake hub port, which kicks hub_wq into removing +the rest of the stuff). + +This is done through devconnect:__wusb_check_devs(), which will scan the +device list looking for whom needs refreshing. + +If the device wants to disconnect, it will either die (ugly) or send a +/DN_Disconnect/ that will prompt a disconnection from the system. + +Sending and receiving data +-------------------------- + +Data is sent and received through /Remote Pipes/ (rpipes). An rpipe is +/aimed/ at an endpoint in a WUSB device. This is the same for HWAs and +DWAs. + +Each HC has a number of rpipes and buffers that can be assigned to them; +when doing a data transfer (xfer), first the rpipe has to be aimed and +prepared (buffers assigned), then we can start queueing requests for +data in or out. + +Data buffers have to be segmented out before sending--so we send first a +header (segment request) and then if there is any data, a data buffer +immediately after to the DTI interface (yep, even the request). If our +buffer is bigger than the max segment size, then we just do multiple +requests. + +[This sucks, because doing USB scatter gatter in Linux is resource +intensive, if any...not that the current approach is not. It just has to +be cleaned up a lot :)]. + +If reading, we don't send data buffers, just the segment headers saying +we want to read segments. + +When the xfer is executed, we receive a notification that says data is +ready in the DTI endpoint (handled through +xfer.c:wa_handle_notif_xfer()). In there we read from the DTI endpoint a +descriptor that gives us the status of the transfer, its identification +(given when we issued it) and the segment number. If it was a data read, +we issue another URB to read into the destination buffer the chunk of +data coming out of the remote endpoint. Done, wait for the next guy. The +callbacks for the URBs issued from here are the ones that will declare +the xfer complete at some point and call its callback. + +Seems simple, but the implementation is not trivial. + + * + + *WARNING* Old!! + +The main xfer descriptor, wa_xfer (equivalent to a URB) contains an +array of segments, tallys on segments and buffers and callback +information. Buried in there is a lot of URBs for executing the segments +and buffer transfers. + +For OUT xfers, there is an array of segments, one URB for each, another +one of buffer URB. When submitting, we submit URBs for segment request +1, buffer 1, segment 2, buffer 2...etc. Then we wait on the DTI for xfer +result data; when all the segments are complete, we call the callback to +finalize the transfer. + +For IN xfers, we only issue URBs for the segments we want to read and +then wait for the xfer result data. + +URB mapping into xfers +^^^^^^^^^^^^^^^^^^^^^^ + +This is done by hwahc_op_urb_[en|de]queue(). In enqueue() we aim an +rpipe to the endpoint where we have to transmit, create a transfer +context (wa_xfer) and submit it. When the xfer is done, our callback is +called and we assign the status bits and release the xfer resources. + +In dequeue() we are basically cancelling/aborting the transfer. We issue +a xfer abort request to the HC, cancel all the URBs we had submitted +and not yet done and when all that is done, the xfer callback will be +called--this will call the URB callback. + + +Glossary +======== + +*DWA* -- Device Wire Adapter + +USB host, wired for downstream devices, upstream connects wirelessly +with Wireless USB. + +*EVENT* -- Response to a command on the NEEP + +*HWA* -- Host Wire Adapter / USB dongle for UWB and Wireless USB + +*NEH* -- Notification/Event Handle + +Handle/file descriptor for receiving notifications or events. The WA +code requires you to get one of this to listen for notifications or +events on the NEEP. + +*NEEP* -- Notification/Event EndPoint + +Stuff related to the management of the first endpoint of a HWA USB +dongle that is used to deliver an stream of events and notifications to +the host. + +*NOTIFICATION* -- Message coming in the NEEP as response to something. + +*RC* -- Radio Control + +Design-overview.txt-1.8 (last edited 2006-11-04 12:22:24 by +InakyPerezGonzalez) diff --git a/MAINTAINERS b/MAINTAINERS index 57f496cff999..8e9d6ea73c35 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3751,7 +3751,7 @@ F: scripts/extract-cert.c CERTIFIED WIRELESS USB (WUSB) SUBSYSTEM: L: linux-usb@vger.kernel.org S: Orphan -F: Documentation/usb/WUSB-Design-overview.txt +F: Documentation/usb/wusb-design-overview.rst F: Documentation/usb/wusb-cbaf F: drivers/usb/host/hwa-hc.c F: drivers/usb/host/whci/ @@ -16238,7 +16238,7 @@ USB ACM DRIVER M: Oliver Neukum L: linux-usb@vger.kernel.org S: Maintained -F: Documentation/usb/acm.txt +F: Documentation/usb/acm.rst F: drivers/usb/class/cdc-acm.* USB AR5523 WIRELESS DRIVER @@ -16291,7 +16291,7 @@ USB EHCI DRIVER M: Alan Stern L: linux-usb@vger.kernel.org S: Maintained -F: Documentation/usb/ehci.txt +F: Documentation/usb/ehci.rst F: drivers/usb/host/ehci* USB GADGET/PERIPHERAL SUBSYSTEM @@ -16365,7 +16365,7 @@ USB OHCI DRIVER M: Alan Stern L: linux-usb@vger.kernel.org S: Maintained -F: Documentation/usb/ohci.txt +F: Documentation/usb/ohci.rst F: drivers/usb/host/ohci* USB OTG FSM (Finite State Machine) @@ -16381,7 +16381,7 @@ M: Shuah Khan M: Shuah Khan L: linux-usb@vger.kernel.org S: Maintained -F: Documentation/usb/usbip_protocol.txt +F: Documentation/usb/usbip_protocol.rst F: drivers/usb/usbip/ F: tools/usb/usbip/ F: tools/testing/selftests/drivers/usb/usbip/ @@ -16429,7 +16429,7 @@ M: Johan Hovold L: linux-usb@vger.kernel.org T: git git://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git S: Maintained -F: Documentation/usb/usb-serial.txt +F: Documentation/usb/usb-serial.rst F: drivers/usb/serial/ F: include/linux/usb/serial.h diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index e4b27413f528..94573fb68304 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -74,7 +74,7 @@ config USB After choosing your HCD, then select drivers for the USB peripherals you'll be using. You may want to check out the information provided in and especially the links given in - . + . To compile this driver as a module, choose M here: the module will be called usbcore. diff --git a/drivers/usb/class/Kconfig b/drivers/usb/class/Kconfig index 52f3a531a82f..f8a798900093 100644 --- a/drivers/usb/class/Kconfig +++ b/drivers/usb/class/Kconfig @@ -10,7 +10,7 @@ config USB_ACM ---help--- This driver supports USB modems and ISDN adapters which support the Communication Device Class Abstract Control Model interface. - Please read for details. + Please read for details. If your modem only reports "Cls=ff(vend.)" in the descriptors in /sys/kernel/debug/usb/devices, then your modem will not work with this diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index ec189d7855a0..02ff850278b1 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -228,7 +228,7 @@ config USB_CONFIGFS specified simply by creating appropriate directories in configfs. Associating functions with configurations is done by creating appropriate symbolic links. - For more information see Documentation/usb/gadget_configfs.txt. + For more information see Documentation/usb/gadget_configfs.rst. config USB_CONFIGFS_SERIAL bool "Generic serial bulk in/out" @@ -441,7 +441,7 @@ config USB_CONFIGFS_F_HID The HID function driver provides generic emulation of USB Human Interface Devices (HID). - For more information, see Documentation/usb/gadget_hid.txt. + For more information, see Documentation/usb/gadget_hid.rst. config USB_CONFIGFS_F_UVC bool "USB Webcam function" @@ -466,7 +466,7 @@ config USB_CONFIGFS_F_PRINTER receive or send printer data. It can use ioctl calls to the device file to get or set printer status. - For more information, see Documentation/usb/gadget_printer.txt + For more information, see Documentation/usb/gadget_printer.rst which includes sample code for accessing the device file. config USB_CONFIGFS_F_TCM diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 043f97ad8f22..29cc5693e05c 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -47,7 +47,7 @@ * * For more information about MSF and in particular its module * parameters and sysfs interface read the - * file. + * file. */ /* diff --git a/drivers/usb/gadget/legacy/Kconfig b/drivers/usb/gadget/legacy/Kconfig index 94fc3c462930..69ff7f8c86f5 100644 --- a/drivers/usb/gadget/legacy/Kconfig +++ b/drivers/usb/gadget/legacy/Kconfig @@ -287,7 +287,7 @@ config USB_G_SERIAL Say "y" to link the driver statically, or "m" to build a dynamically linked module called "g_serial". - For more information, see Documentation/usb/gadget_serial.txt + For more information, see Documentation/usb/gadget_serial.rst which includes instructions and a "driver info file" needed to make MS-Windows work with CDC ACM. @@ -321,7 +321,7 @@ config USB_G_PRINTER Say "y" to link the driver statically, or "m" to build a dynamically linked module called "g_printer". - For more information, see Documentation/usb/gadget_printer.txt + For more information, see Documentation/usb/gadget_printer.rst which includes sample code for accessing the device file. if TTY @@ -436,7 +436,7 @@ config USB_G_HID The HID gadget driver provides generic emulation of USB Human Interface Devices (HID). - For more information, see Documentation/usb/gadget_hid.txt which + For more information, see Documentation/usb/gadget_hid.rst which includes sample code for accessing the device files. Say "y" to link the driver statically, or "m" to build a diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index fb3406ea8592..40b5de597112 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -114,7 +114,7 @@ config USB_EHCI_HCD Controller Driver or UHCI (for Via motherboards) Host Controller Driver too. - You may want to read . + You may want to read . To compile this driver as a module, choose M here: the module will be called ehci-hcd. diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig index c97f270338bf..a829cd0ef5f3 100644 --- a/drivers/usb/misc/Kconfig +++ b/drivers/usb/misc/Kconfig @@ -51,7 +51,7 @@ config USB_RIO500 tristate "USB Diamond Rio500 support" help Say Y here if you want to connect a USB Rio500 mp3 player to your - computer's USB port. Please read + computer's USB port. Please read for more information. To compile this driver as a module, choose M here: the diff --git a/drivers/usb/mon/Kconfig b/drivers/usb/mon/Kconfig index 48f1b2dadb24..ffc7cd422874 100644 --- a/drivers/usb/mon/Kconfig +++ b/drivers/usb/mon/Kconfig @@ -8,6 +8,6 @@ config USB_MON help If you select this option, a component which captures the USB traffic between peripheral-specific drivers and HC drivers will be built. - For more information, see . + For more information, see . If unsure, say Y, if allowed, otherwise M. diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig index 7d031911d04e..67279c6bce33 100644 --- a/drivers/usb/serial/Kconfig +++ b/drivers/usb/serial/Kconfig @@ -11,7 +11,7 @@ menuconfig USB_SERIAL ports, or acts like a serial device, and you want to connect it to your USB bus. - Please read for more + Please read for more information on the specifics of the different devices that are supported, and on how to use them. @@ -47,7 +47,7 @@ config USB_SERIAL_GENERIC bool "USB Generic Serial Driver" help Say Y here if you want to use the generic USB serial driver. Please - read for more information on + read for more information on using this driver. It is recommended that the "USB Serial converter support" be compiled as a module for this driver to be used properly. @@ -163,7 +163,7 @@ config USB_SERIAL_EMPEG help Say Y here if you want to connect to your Empeg empeg-car Mark I/II mp3 player via USB. The driver uses a single ttyUSB{0,1,2,...} - device node. See for more + device node. See for more tidbits of information. To compile this driver as a module, choose M here: the @@ -199,7 +199,7 @@ config USB_SERIAL_IPAQ Say Y here if you want to connect to your Compaq iPAQ, HP Jornada or any other PDA running Windows CE 3.0 or PocketPC 2002 using a USB cradle/cable. For information on using the driver, - read . + read . To compile this driver as a module, choose M here: the module will be called ipaq. @@ -334,7 +334,7 @@ config USB_SERIAL_KLSI adapter sold by Palm Inc. for use with their Palm III and Palm V series PDAs. - Please read for more + Please read for more information. To compile this driver as a module, choose M here: the diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c index c1235d5b9fba..9bb123ab9bc9 100644 --- a/drivers/usb/serial/belkin_sa.c +++ b/drivers/usb/serial/belkin_sa.c @@ -10,7 +10,7 @@ * and associated source files. Please see the usb/serial files for * individual credits and copyrights. * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver * * TODO: diff --git a/drivers/usb/serial/belkin_sa.h b/drivers/usb/serial/belkin_sa.h index 51bc06287603..a13a98d284f2 100644 --- a/drivers/usb/serial/belkin_sa.h +++ b/drivers/usb/serial/belkin_sa.h @@ -9,7 +9,7 @@ * and associated source files. Please see the usb/serial files for * individual credits and copyrights. * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver * * 12-Mar-2001 gkh diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index 72d3ae1ebc64..216edd5826ca 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c @@ -7,7 +7,7 @@ * Copyright (C) 2003,2004 * Neil Whelchel (koyama@firstlight.net) * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver * * See http://geocities.com/i0xox0i for information on this driver and the diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c index d680bec62547..405e835e93dd 100644 --- a/drivers/usb/serial/empeg.c +++ b/drivers/usb/serial/empeg.c @@ -8,7 +8,7 @@ * Copyright (C) 1999 - 2001 * Greg Kroah-Hartman (greg@kroah.com) * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver */ diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 1d8461ae2c34..8b15bbf545d4 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -10,7 +10,7 @@ * Copyright (C) 2002 * Kuba Ober (kuba@mareimbrium.org) * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver * * See http://ftdi-usb-sio.sourceforge.net for up to date testing info diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 7643716b5299..302eb9530859 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c @@ -16,7 +16,7 @@ * was written by Roman Weissgaerber , Dag Brattli * , and Jean Tourrilhes * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver */ diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index 38d43c4b7ce5..bf988f77d400 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c @@ -6,7 +6,7 @@ * Copyright (C) 1999, 2000 Brian Warner * Copyright (C) 2000 Al Borchers * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver */ diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c index e51c9464ea42..5b6e982a9376 100644 --- a/drivers/usb/serial/omninet.c +++ b/drivers/usb/serial/omninet.c @@ -4,7 +4,7 @@ * * Copyright (C) 2013,2017 Johan Hovold * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver * * Please report both successes and troubles to the author at omninet@kroah.com diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c index 38ae0fc826cc..8151dd7a45e8 100644 --- a/drivers/usb/serial/oti6858.c +++ b/drivers/usb/serial/oti6858.c @@ -22,7 +22,7 @@ * So, THIS CODE CAN DESTROY OTi-6858 AND ANY OTHER DEVICES, THAT ARE * CONNECTED TO IT! * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver * * TODO: diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index d7abde14b3cf..9d27b76c5c6e 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -7,7 +7,7 @@ * * Original driver for 2.2.x by anonymous * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver */ diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 676c296103a2..a3179fea38c8 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c @@ -10,7 +10,7 @@ * This driver was originally based on the ACM driver by Armin Fuerst (which was * based on a driver by Brad Keryan) * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver */ diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c index 8ddbecc25d89..4412834db21c 100644 --- a/drivers/usb/serial/visor.c +++ b/drivers/usb/serial/visor.c @@ -6,7 +6,7 @@ * Copyright (C) 1999 - 2004 * Greg Kroah-Hartman (greg@kroah.com) * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver * */ diff --git a/drivers/usb/serial/visor.h b/drivers/usb/serial/visor.h index fe290243f1ce..4bd69d047036 100644 --- a/drivers/usb/serial/visor.h +++ b/drivers/usb/serial/visor.h @@ -5,7 +5,7 @@ * Copyright (C) 1999 - 2003 * Greg Kroah-Hartman (greg@kroah.com) * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver. * */ diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c index aefd84f88b59..79314d8c94a4 100644 --- a/drivers/usb/serial/whiteheat.c +++ b/drivers/usb/serial/whiteheat.c @@ -8,7 +8,7 @@ * Copyright (C) 1999 - 2001 * Greg Kroah-Hartman (greg@kroah.com) * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver */ diff --git a/drivers/usb/serial/whiteheat.h b/drivers/usb/serial/whiteheat.h index 72c1b0cf4063..00398149cd8d 100644 --- a/drivers/usb/serial/whiteheat.h +++ b/drivers/usb/serial/whiteheat.h @@ -8,7 +8,7 @@ * Copyright (C) 1999, 2000 * Greg Kroah-Hartman (greg@kroah.com) * - * See Documentation/usb/usb-serial.txt for more information on using this + * See Documentation/usb/usb-serial.rst for more information on using this * driver * */ -- cgit v1.2.3 From 1853bc0ae64b035ba49d285cf8d3fb4991e7872e Mon Sep 17 00:00:00 2001 From: YueHaibing Date: Thu, 18 Apr 2019 21:36:33 +0800 Subject: phy: ti: am654-serdes: Make serdes_am654_xlate() static Fix sparse warning: drivers/phy/ti/phy-am654-serdes.c:250:12: warning: symbol 'serdes_am654_xlate' was not declared. Should it be static? Reported-by: Hulk Robot Signed-off-by: YueHaibing Acked-by: Roger Quadros Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/ti/phy-am654-serdes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/phy/ti/phy-am654-serdes.c b/drivers/phy/ti/phy-am654-serdes.c index d3769200cb9b..f8edd0840fa2 100644 --- a/drivers/phy/ti/phy-am654-serdes.c +++ b/drivers/phy/ti/phy-am654-serdes.c @@ -247,8 +247,8 @@ static void serdes_am654_release(struct phy *x) mux_control_deselect(phy->control); } -struct phy *serdes_am654_xlate(struct device *dev, struct of_phandle_args - *args) +static struct phy *serdes_am654_xlate(struct device *dev, + struct of_phandle_args *args) { struct serdes_am654 *am654_phy; struct phy *phy; -- cgit v1.2.3 From 885bd765963b42c380db442db7f1c0f2a26076fa Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Tue, 4 Jun 2019 16:24:43 -0700 Subject: phy: qcom-qmp: Correct READY_STATUS poll break condition After issuing a PHY_START request to the QMP, the hardware documentation states that the software should wait for the PCS_READY_STATUS to become 1. With the introduction of commit c9b589791fc1 ("phy: qcom: Utilize UFS reset controller") an additional 1ms delay was introduced between the start request and the check of the status bit. This greatly increases the chances for the hardware to actually becoming ready before the status bit is read. The result can be seen in that UFS PHY enabling is now reported as a failure in 10% of the boots on SDM845, which is a clear regression from the previous rare/occasional failure. This patch fixes the "break condition" of the poll to check for the correct state of the status bit. Unfortunately PCIe on 8996 and 8998 does not specify the mask_pcs_ready register, which means that the code checks a bit that's always 0. So the patch also fixes these, in order to not regress these targets. Fixes: 73d7ec899bd8 ("phy: qcom-qmp: Add msm8998 PCIe QMP PHY support") Fixes: e78f3d15e115 ("phy: qcom-qmp: new qmp phy driver for qcom-chipsets") Cc: stable@vger.kernel.org Cc: Evan Green Cc: Marc Gonzalez Cc: Vivek Gautam Reviewed-by: Evan Green Reviewed-by: Niklas Cassel Reviewed-by: Marc Gonzalez Tested-by: Marc Gonzalez Signed-off-by: Bjorn Andersson Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/qualcomm/phy-qcom-qmp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c b/drivers/phy/qualcomm/phy-qcom-qmp.c index cd91b4179b10..43abdfd0deed 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp.c @@ -1074,6 +1074,7 @@ static const struct qmp_phy_cfg msm8996_pciephy_cfg = { .start_ctrl = PCS_START | PLL_READY_GATE_EN, .pwrdn_ctrl = SW_PWRDN | REFCLK_DRV_DSBL, + .mask_pcs_ready = PHYSTATUS, .mask_com_pcs_ready = PCS_READY, .has_phy_com_ctrl = true, @@ -1253,6 +1254,7 @@ static const struct qmp_phy_cfg msm8998_pciephy_cfg = { .start_ctrl = SERDES_START | PCS_START, .pwrdn_ctrl = SW_PWRDN | REFCLK_DRV_DSBL, + .mask_pcs_ready = PHYSTATUS, .mask_com_pcs_ready = PCS_READY, }; @@ -1547,7 +1549,7 @@ static int qcom_qmp_phy_enable(struct phy *phy) status = pcs + cfg->regs[QPHY_PCS_READY_STATUS]; mask = cfg->mask_pcs_ready; - ret = readl_poll_timeout(status, val, !(val & mask), 1, + ret = readl_poll_timeout(status, val, val & mask, 1, PHY_INIT_COMPLETE_TIMEOUT); if (ret) { dev_err(qmp->dev, "phy initialization timed-out\n"); -- cgit v1.2.3 From 67c2eccb7d6ef953c0f382adfa8348211d919ff4 Mon Sep 17 00:00:00 2001 From: Marc Gonzalez Date: Thu, 13 Jun 2019 13:05:31 +0200 Subject: phy: qcom-qmp: Drop useless msm8998_pciephy_cfg setting 'mask_com_pcs_ready' is only useful if 'has_phy_com_ctrl' is true. Since msm8998_pciephy_cfg.has_phy_com_ctrl is false, let's drop msm8998_pciephy_cfg.mask_com_pcs_ready altogether. Signed-off-by: Marc Gonzalez Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/qualcomm/phy-qcom-qmp.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c b/drivers/phy/qualcomm/phy-qcom-qmp.c index 43abdfd0deed..bb522b915fa9 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp.c @@ -1255,7 +1255,6 @@ static const struct qmp_phy_cfg msm8998_pciephy_cfg = { .start_ctrl = SERDES_START | PCS_START, .pwrdn_ctrl = SW_PWRDN | REFCLK_DRV_DSBL, .mask_pcs_ready = PHYSTATUS, - .mask_com_pcs_ready = PCS_READY, }; static const struct qmp_phy_cfg msm8998_usb3phy_cfg = { -- cgit v1.2.3 From 5c9dc6379f539c68a0fdd39e39a9d359545649e9 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Mon, 10 Jun 2019 15:23:55 +0900 Subject: phy: renesas: rcar-gen3-usb2: fix imbalance powered flag The powered flag should be set for any other phys anyway. Also the flag should be locked by the channel. Otherwise, after we have revised the device tree for the usb phy, the following warning happened during a second system suspend. And if the driver doesn't lock the flag, an imbalance is possible when enabling the regulator during system resume. So, this patch fixes the issues. < The warning > [ 56.026531] unbalanced disables for USB20_VBUS0 [ 56.031108] WARNING: CPU: 3 PID: 513 at drivers/regulator/core.c:2593 _regula tor_disable+0xe0/0x1c0 [ 56.040146] Modules linked in: rcar_du_drm rcar_lvds drm_kms_helper drm drm_p anel_orientation_quirks vsp1 videobuf2_vmalloc videobuf2_dma_contig videobuf2_me mops videobuf2_v4l2 videobuf2_common videodev snd_soc_rcar renesas_usbhs snd_soc _audio_graph_card media snd_soc_simple_card_utils crct10dif_ce renesas_usb3 snd_ soc_ak4613 rcar_fcp pwm_rcar usb_dmac phy_rcar_gen3_usb3 pwm_bl ipv6 [ 56.074047] CPU: 3 PID: 513 Comm: kworker/u16:19 Not tainted 5.2.0-rc3-00001- g5f20a19 #6 [ 56.082129] Hardware name: Renesas Salvator-X board based on r8a7795 ES2.0+ ( DT) [ 56.089524] Workqueue: events_unbound async_run_entry_fn [ 56.094832] pstate: 40000005 (nZcv daif -PAN -UAO) [ 56.099617] pc : _regulator_disable+0xe0/0x1c0 [ 56.104054] lr : _regulator_disable+0xe0/0x1c0 [ 56.108489] sp : ffff0000121c3ae0 [ 56.111796] x29: ffff0000121c3ae0 x28: 0000000000000000 [ 56.117102] x27: 0000000000000000 x26: ffff000010fe0e60 [ 56.122407] x25: 0000000000000002 x24: 0000000000000001 [ 56.127712] x23: 0000000000000002 x22: ffff8006f99d4000 [ 56.133017] x21: ffff8006f99cc000 x20: ffff8006f9846800 [ 56.138322] x19: ffff8006f9846800 x18: ffffffffffffffff [ 56.143626] x17: 0000000000000000 x16: 0000000000000000 [ 56.148931] x15: ffff0000112f96c8 x14: ffff0000921c37f7 [ 56.154235] x13: ffff0000121c3805 x12: ffff000011312000 [ 56.159540] x11: 0000000005f5e0ff x10: ffff0000112f9f20 [ 56.164844] x9 : ffff0000112d3018 x8 : 00000000000001ad [ 56.170149] x7 : 00000000ffffffcc x6 : ffff8006ff768180 [ 56.175453] x5 : ffff8006ff768180 x4 : 0000000000000000 [ 56.180758] x3 : ffff8006ff76ef10 x2 : ffff8006ff768180 [ 56.186062] x1 : 3d2eccbaead8fb00 x0 : 0000000000000000 [ 56.191367] Call trace: [ 56.193808] _regulator_disable+0xe0/0x1c0 [ 56.197899] regulator_disable+0x40/0x78 [ 56.201820] rcar_gen3_phy_usb2_power_off+0x3c/0x50 [ 56.206692] phy_power_off+0x48/0xd8 [ 56.210263] usb_phy_roothub_power_off+0x30/0x50 [ 56.214873] usb_phy_roothub_suspend+0x1c/0x50 [ 56.219311] hcd_bus_suspend+0x13c/0x168 [ 56.223226] generic_suspend+0x4c/0x58 [ 56.226969] usb_suspend_both+0x1ac/0x238 [ 56.230972] usb_suspend+0xcc/0x170 [ 56.234455] usb_dev_suspend+0x10/0x18 [ 56.238199] dpm_run_callback.isra.6+0x20/0x68 [ 56.242635] __device_suspend+0x110/0x308 [ 56.246637] async_suspend+0x24/0xa8 [ 56.250205] async_run_entry_fn+0x40/0xf8 [ 56.254210] process_one_work+0x1e0/0x320 [ 56.258211] worker_thread+0x40/0x450 [ 56.261867] kthread+0x124/0x128 [ 56.265094] ret_from_fork+0x10/0x18 [ 56.268661] ---[ end trace 86d7ec5de5c517af ]--- [ 56.273290] phy phy-ee080200.usb-phy.10: phy poweroff failed --> -5 Reported-by: Geert Uytterhoeven Fixes: 549b6b55b005 ("phy: renesas: rcar-gen3-usb2: enable/disable independent irqs") Signed-off-by: Yoshihiro Shimoda Reviewed-by: Geert Uytterhoeven Tested-by: Geert Uytterhoeven Reviewed-by: Simon Horman Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c index 1322185a00a2..8ffba67568ec 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -106,6 +107,7 @@ struct rcar_gen3_chan { struct rcar_gen3_phy rphys[NUM_OF_PHYS]; struct regulator *vbus; struct work_struct work; + struct mutex lock; /* protects rphys[...].powered */ enum usb_dr_mode dr_mode; bool extcon_host; bool is_otg_channel; @@ -437,15 +439,16 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p) struct rcar_gen3_chan *channel = rphy->ch; void __iomem *usb2_base = channel->base; u32 val; - int ret; + int ret = 0; + mutex_lock(&channel->lock); if (!rcar_gen3_are_all_rphys_power_off(channel)) - return 0; + goto out; if (channel->vbus) { ret = regulator_enable(channel->vbus); if (ret) - return ret; + goto out; } val = readl(usb2_base + USB2_USBCTR); @@ -454,7 +457,10 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p) val &= ~USB2_USBCTR_PLL_RST; writel(val, usb2_base + USB2_USBCTR); +out: + /* The powered flag should be set for any other phys anyway */ rphy->powered = true; + mutex_unlock(&channel->lock); return 0; } @@ -465,14 +471,18 @@ static int rcar_gen3_phy_usb2_power_off(struct phy *p) struct rcar_gen3_chan *channel = rphy->ch; int ret = 0; + mutex_lock(&channel->lock); rphy->powered = false; if (!rcar_gen3_are_all_rphys_power_off(channel)) - return 0; + goto out; if (channel->vbus) ret = regulator_disable(channel->vbus); +out: + mutex_unlock(&channel->lock); + return ret; } @@ -639,6 +649,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) if (!phy_usb2_ops) return -EINVAL; + mutex_init(&channel->lock); for (i = 0; i < NUM_OF_PHYS; i++) { channel->rphys[i].phy = devm_phy_create(dev, NULL, phy_usb2_ops); -- cgit v1.2.3 From 51cc0da52e16ef487e3b9f73ad0ba8243684e73d Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 20 Jun 2019 13:46:36 +0200 Subject: dt-bindings: phy-pxa-usb: add bindings This is the PHY chip for USB OTG on PXA platforms. Signed-off-by: Lubomir Rintel Acked-by: Pavel Machek Signed-off-by: Kishon Vijay Abraham I --- Documentation/devicetree/bindings/phy/phy-pxa-usb.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/phy-pxa-usb.txt diff --git a/Documentation/devicetree/bindings/phy/phy-pxa-usb.txt b/Documentation/devicetree/bindings/phy/phy-pxa-usb.txt new file mode 100644 index 000000000000..93fc09c12954 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/phy-pxa-usb.txt @@ -0,0 +1,18 @@ +Marvell PXA USB PHY +------------------- + +Required properties: +- compatible: one of: "marvell,mmp2-usb-phy", "marvell,pxa910-usb-phy", + "marvell,pxa168-usb-phy", +- #phy-cells: must be 0 + +Example: + usb-phy: usbphy@d4207000 { + compatible = "marvell,mmp2-usb-phy"; + reg = <0xd4207000 0x40>; + #phy-cells = <0>; + status = "okay"; + }; + +This document explains the device tree binding. For general +information about PHY subsystem refer to Documentation/phy.txt -- cgit v1.2.3 From 00fcc69d6e52643fc5ecd04ff7e2d560ed3e2ec0 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Thu, 20 Jun 2019 21:42:36 +0200 Subject: dt-bindings: phy: Add documentation for mixel dphy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for the MIXEL DPHY IP as found on NXP's i.MX8MQ SoCs. Signed-off-by: Guido Günther Reviewed-by: Sam Ravnborg Reviewed-by: Rob Herring Reviewed-by: Fabio Estevam Signed-off-by: Kishon Vijay Abraham I --- .../devicetree/bindings/phy/mixel,mipi-dsi-phy.txt | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/mixel,mipi-dsi-phy.txt diff --git a/Documentation/devicetree/bindings/phy/mixel,mipi-dsi-phy.txt b/Documentation/devicetree/bindings/phy/mixel,mipi-dsi-phy.txt new file mode 100644 index 000000000000..9b23407233c0 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/mixel,mipi-dsi-phy.txt @@ -0,0 +1,29 @@ +Mixel DSI PHY for i.MX8 + +The Mixel MIPI-DSI PHY IP block is e.g. found on i.MX8 platforms (along the +MIPI-DSI IP from Northwest Logic). It represents the physical layer for the +electrical signals for DSI. + +Required properties: +- compatible: Must be: + - "fsl,imx8mq-mipi-dphy" +- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Must contain the following entries: + - "phy_ref": phandle and specifier referring to the DPHY ref clock +- reg: the register range of the PHY controller +- #phy-cells: number of cells in PHY, as defined in + Documentation/devicetree/bindings/phy/phy-bindings.txt + this must be <0> + +Optional properties: +- power-domains: phandle to power domain + +Example: + dphy: dphy@30a0030 { + compatible = "fsl,imx8mq-mipi-dphy"; + clocks = <&clk IMX8MQ_CLK_DSI_PHY_REF>; + clock-names = "phy_ref"; + reg = <0x30a00300 0x100>; + power-domains = <&pd_mipi0>; + #phy-cells = <0>; + }; -- cgit v1.2.3 From f4c8116e294b12c360b724173f4b79f232573fb1 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Thu, 20 Jun 2019 21:42:37 +0200 Subject: phy: Add driver for mixel mipi dphy found on NXP's i.MX8 SoCs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds support for the Mixel DPHY as found on i.MX8 CPUs but since this is an IP core it will likely be found on others in the future. So instead of adding this to the nwl host driver make it a generic PHY driver. The driver supports the i.MX8MQ. Support for i.MX8QM and i.MX8QXP can be added once the necessary system controller bits are in via mixel_dphy_devdata. Signed-off-by: Guido Günther Co-developed-by: Robert Chiras Signed-off-by: Robert Chiras Reviewed-by: Fabio Estevam Reviewed-by: Sam Ravnborg Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/freescale/Kconfig | 10 + drivers/phy/freescale/Makefile | 1 + drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c | 497 +++++++++++++++++++++++++ 3 files changed, 508 insertions(+) create mode 100644 drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c diff --git a/drivers/phy/freescale/Kconfig b/drivers/phy/freescale/Kconfig index 832670b4952b..247be62d0981 100644 --- a/drivers/phy/freescale/Kconfig +++ b/drivers/phy/freescale/Kconfig @@ -3,3 +3,13 @@ config PHY_FSL_IMX8MQ_USB depends on OF && HAS_IOMEM select GENERIC_PHY default ARCH_MXC && ARM64 + +config PHY_MIXEL_MIPI_DPHY + tristate "Mixel MIPI DSI PHY support" + depends on OF && HAS_IOMEM + select GENERIC_PHY + select GENERIC_PHY_MIPI_DPHY + select REGMAP_MMIO + help + Enable this to add support for the Mixel DSI PHY as found + on NXP's i.MX8 family of SOCs. diff --git a/drivers/phy/freescale/Makefile b/drivers/phy/freescale/Makefile index dc2b3f1f2f80..07491c926a2c 100644 --- a/drivers/phy/freescale/Makefile +++ b/drivers/phy/freescale/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_PHY_FSL_IMX8MQ_USB) += phy-fsl-imx8mq-usb.o +obj-$(CONFIG_PHY_MIXEL_MIPI_DPHY) += phy-fsl-imx8-mipi-dphy.o diff --git a/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c b/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c new file mode 100644 index 000000000000..9f2c1da14f5a --- /dev/null +++ b/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c @@ -0,0 +1,497 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2017,2018 NXP + * Copyright 2019 Purism SPC + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* DPHY registers */ +#define DPHY_PD_DPHY 0x00 +#define DPHY_M_PRG_HS_PREPARE 0x04 +#define DPHY_MC_PRG_HS_PREPARE 0x08 +#define DPHY_M_PRG_HS_ZERO 0x0c +#define DPHY_MC_PRG_HS_ZERO 0x10 +#define DPHY_M_PRG_HS_TRAIL 0x14 +#define DPHY_MC_PRG_HS_TRAIL 0x18 +#define DPHY_PD_PLL 0x1c +#define DPHY_TST 0x20 +#define DPHY_CN 0x24 +#define DPHY_CM 0x28 +#define DPHY_CO 0x2c +#define DPHY_LOCK 0x30 +#define DPHY_LOCK_BYP 0x34 +#define DPHY_REG_BYPASS_PLL 0x4C + +#define MBPS(x) ((x) * 1000000) + +#define DATA_RATE_MAX_SPEED MBPS(1500) +#define DATA_RATE_MIN_SPEED MBPS(80) + +#define PLL_LOCK_SLEEP 10 +#define PLL_LOCK_TIMEOUT 1000 + +#define CN_BUF 0xcb7a89c0 +#define CO_BUF 0x63 +#define CM(x) ( \ + ((x) < 32) ? 0xe0 | ((x) - 16) : \ + ((x) < 64) ? 0xc0 | ((x) - 32) : \ + ((x) < 128) ? 0x80 | ((x) - 64) : \ + ((x) - 128)) +#define CN(x) (((x) == 1) ? 0x1f : (((CN_BUF) >> ((x) - 1)) & 0x1f)) +#define CO(x) ((CO_BUF) >> (8 - (x)) & 0x03) + +/* PHY power on is active low */ +#define PWR_ON 0 +#define PWR_OFF 1 + +enum mixel_dphy_devtype { + MIXEL_IMX8MQ, +}; + +struct mixel_dphy_devdata { + u8 reg_tx_rcal; + u8 reg_auto_pd_en; + u8 reg_rxlprp; + u8 reg_rxcdrp; + u8 reg_rxhs_settle; +}; + +static const struct mixel_dphy_devdata mixel_dphy_devdata[] = { + [MIXEL_IMX8MQ] = { + .reg_tx_rcal = 0x38, + .reg_auto_pd_en = 0x3c, + .reg_rxlprp = 0x40, + .reg_rxcdrp = 0x44, + .reg_rxhs_settle = 0x48, + }, +}; + +struct mixel_dphy_cfg { + /* DPHY PLL parameters */ + u32 cm; + u32 cn; + u32 co; + /* DPHY register values */ + u8 mc_prg_hs_prepare; + u8 m_prg_hs_prepare; + u8 mc_prg_hs_zero; + u8 m_prg_hs_zero; + u8 mc_prg_hs_trail; + u8 m_prg_hs_trail; + u8 rxhs_settle; +}; + +struct mixel_dphy_priv { + struct mixel_dphy_cfg cfg; + struct regmap *regmap; + struct clk *phy_ref_clk; + const struct mixel_dphy_devdata *devdata; +}; + +static const struct regmap_config mixel_dphy_regmap_config = { + .reg_bits = 8, + .val_bits = 32, + .reg_stride = 4, + .max_register = DPHY_REG_BYPASS_PLL, + .name = "mipi-dphy", +}; + +static int phy_write(struct phy *phy, u32 value, unsigned int reg) +{ + struct mixel_dphy_priv *priv = phy_get_drvdata(phy); + int ret; + + ret = regmap_write(priv->regmap, reg, value); + if (ret < 0) + dev_err(&phy->dev, "Failed to write DPHY reg %d: %d\n", reg, + ret); + return ret; +} + +/* + * Find a ratio close to the desired one using continued fraction + * approximation ending either at exact match or maximum allowed + * nominator, denominator. + */ +static void get_best_ratio(u32 *pnum, u32 *pdenom, u32 max_n, u32 max_d) +{ + u32 a = *pnum; + u32 b = *pdenom; + u32 c; + u32 n[] = {0, 1}; + u32 d[] = {1, 0}; + u32 whole; + unsigned int i = 1; + + while (b) { + i ^= 1; + whole = a / b; + n[i] += (n[i ^ 1] * whole); + d[i] += (d[i ^ 1] * whole); + if ((n[i] > max_n) || (d[i] > max_d)) { + i ^= 1; + break; + } + c = a - (b * whole); + a = b; + b = c; + } + *pnum = n[i]; + *pdenom = d[i]; +} + +static int mixel_dphy_config_from_opts(struct phy *phy, + struct phy_configure_opts_mipi_dphy *dphy_opts, + struct mixel_dphy_cfg *cfg) +{ + struct mixel_dphy_priv *priv = dev_get_drvdata(phy->dev.parent); + unsigned long ref_clk = clk_get_rate(priv->phy_ref_clk); + u32 lp_t, numerator, denominator; + unsigned long long tmp; + u32 n; + int i; + + if (dphy_opts->hs_clk_rate > DATA_RATE_MAX_SPEED || + dphy_opts->hs_clk_rate < DATA_RATE_MIN_SPEED) + return -EINVAL; + + numerator = dphy_opts->hs_clk_rate; + denominator = ref_clk; + get_best_ratio(&numerator, &denominator, 255, 256); + if (!numerator || !denominator) { + dev_err(&phy->dev, "Invalid %d/%d for %ld/%ld\n", + numerator, denominator, + dphy_opts->hs_clk_rate, ref_clk); + return -EINVAL; + } + + while ((numerator < 16) && (denominator <= 128)) { + numerator <<= 1; + denominator <<= 1; + } + /* + * CM ranges between 16 and 255 + * CN ranges between 1 and 32 + * CO is power of 2: 1, 2, 4, 8 + */ + i = __ffs(denominator); + if (i > 3) + i = 3; + cfg->cn = denominator >> i; + cfg->co = 1 << i; + cfg->cm = numerator; + + if (cfg->cm < 16 || cfg->cm > 255 || + cfg->cn < 1 || cfg->cn > 32 || + cfg->co < 1 || cfg->co > 8) { + dev_err(&phy->dev, "Invalid CM/CN/CO values: %u/%u/%u\n", + cfg->cm, cfg->cn, cfg->co); + dev_err(&phy->dev, "for hs_clk/ref_clk=%ld/%ld ~ %d/%d\n", + dphy_opts->hs_clk_rate, ref_clk, + numerator, denominator); + return -EINVAL; + } + + dev_dbg(&phy->dev, "hs_clk/ref_clk=%ld/%ld ~ %d/%d\n", + dphy_opts->hs_clk_rate, ref_clk, numerator, denominator); + + /* LP clock period */ + tmp = 1000000000000LL; + do_div(tmp, dphy_opts->lp_clk_rate); /* ps */ + if (tmp > ULONG_MAX) + return -EINVAL; + + lp_t = tmp; + dev_dbg(&phy->dev, "LP clock %lu, period: %u ps\n", + dphy_opts->lp_clk_rate, lp_t); + + /* hs_prepare: in lp clock periods */ + if (2 * dphy_opts->hs_prepare > 5 * lp_t) { + dev_err(&phy->dev, + "hs_prepare (%u) > 2.5 * lp clock period (%u)\n", + dphy_opts->hs_prepare, lp_t); + return -EINVAL; + } + /* 00: lp_t, 01: 1.5 * lp_t, 10: 2 * lp_t, 11: 2.5 * lp_t */ + if (dphy_opts->hs_prepare < lp_t) { + n = 0; + } else { + tmp = 2 * (dphy_opts->hs_prepare - lp_t); + do_div(tmp, lp_t); + n = tmp; + } + cfg->m_prg_hs_prepare = n; + + /* clk_prepare: in lp clock periods */ + if (2 * dphy_opts->clk_prepare > 3 * lp_t) { + dev_err(&phy->dev, + "clk_prepare (%u) > 1.5 * lp clock period (%u)\n", + dphy_opts->clk_prepare, lp_t); + return -EINVAL; + } + /* 00: lp_t, 01: 1.5 * lp_t */ + cfg->mc_prg_hs_prepare = dphy_opts->clk_prepare > lp_t ? 1 : 0; + + /* hs_zero: formula from NXP BSP */ + n = (144 * (dphy_opts->hs_clk_rate / 1000000) - 47500) / 10000; + cfg->m_prg_hs_zero = n < 1 ? 1 : n; + + /* clk_zero: formula from NXP BSP */ + n = (34 * (dphy_opts->hs_clk_rate / 1000000) - 2500) / 1000; + cfg->mc_prg_hs_zero = n < 1 ? 1 : n; + + /* clk_trail, hs_trail: formula from NXP BSP */ + n = (103 * (dphy_opts->hs_clk_rate / 1000000) + 10000) / 10000; + if (n > 15) + n = 15; + if (n < 1) + n = 1; + cfg->m_prg_hs_trail = n; + cfg->mc_prg_hs_trail = n; + + /* rxhs_settle: formula from NXP BSP */ + if (dphy_opts->hs_clk_rate < MBPS(80)) + cfg->rxhs_settle = 0x0d; + else if (dphy_opts->hs_clk_rate < MBPS(90)) + cfg->rxhs_settle = 0x0c; + else if (dphy_opts->hs_clk_rate < MBPS(125)) + cfg->rxhs_settle = 0x0b; + else if (dphy_opts->hs_clk_rate < MBPS(150)) + cfg->rxhs_settle = 0x0a; + else if (dphy_opts->hs_clk_rate < MBPS(225)) + cfg->rxhs_settle = 0x09; + else if (dphy_opts->hs_clk_rate < MBPS(500)) + cfg->rxhs_settle = 0x08; + else + cfg->rxhs_settle = 0x07; + + dev_dbg(&phy->dev, "phy_config: %u %u %u %u %u %u %u\n", + cfg->m_prg_hs_prepare, cfg->mc_prg_hs_prepare, + cfg->m_prg_hs_zero, cfg->mc_prg_hs_zero, + cfg->m_prg_hs_trail, cfg->mc_prg_hs_trail, + cfg->rxhs_settle); + + return 0; +} + +static void mixel_phy_set_hs_timings(struct phy *phy) +{ + struct mixel_dphy_priv *priv = phy_get_drvdata(phy); + + phy_write(phy, priv->cfg.m_prg_hs_prepare, DPHY_M_PRG_HS_PREPARE); + phy_write(phy, priv->cfg.mc_prg_hs_prepare, DPHY_MC_PRG_HS_PREPARE); + phy_write(phy, priv->cfg.m_prg_hs_zero, DPHY_M_PRG_HS_ZERO); + phy_write(phy, priv->cfg.mc_prg_hs_zero, DPHY_MC_PRG_HS_ZERO); + phy_write(phy, priv->cfg.m_prg_hs_trail, DPHY_M_PRG_HS_TRAIL); + phy_write(phy, priv->cfg.mc_prg_hs_trail, DPHY_MC_PRG_HS_TRAIL); + phy_write(phy, priv->cfg.rxhs_settle, priv->devdata->reg_rxhs_settle); +} + +static int mixel_dphy_set_pll_params(struct phy *phy) +{ + struct mixel_dphy_priv *priv = dev_get_drvdata(phy->dev.parent); + + if (priv->cfg.cm < 16 || priv->cfg.cm > 255 || + priv->cfg.cn < 1 || priv->cfg.cn > 32 || + priv->cfg.co < 1 || priv->cfg.co > 8) { + dev_err(&phy->dev, "Invalid CM/CN/CO values! (%u/%u/%u)\n", + priv->cfg.cm, priv->cfg.cn, priv->cfg.co); + return -EINVAL; + } + dev_dbg(&phy->dev, "Using CM:%u CN:%u CO:%u\n", + priv->cfg.cm, priv->cfg.cn, priv->cfg.co); + phy_write(phy, CM(priv->cfg.cm), DPHY_CM); + phy_write(phy, CN(priv->cfg.cn), DPHY_CN); + phy_write(phy, CO(priv->cfg.co), DPHY_CO); + return 0; +} + +static int mixel_dphy_configure(struct phy *phy, union phy_configure_opts *opts) +{ + struct mixel_dphy_priv *priv = phy_get_drvdata(phy); + struct mixel_dphy_cfg cfg = { 0 }; + int ret; + + ret = mixel_dphy_config_from_opts(phy, &opts->mipi_dphy, &cfg); + if (ret) + return ret; + + /* Update the configuration */ + memcpy(&priv->cfg, &cfg, sizeof(struct mixel_dphy_cfg)); + + phy_write(phy, 0x00, DPHY_LOCK_BYP); + phy_write(phy, 0x01, priv->devdata->reg_tx_rcal); + phy_write(phy, 0x00, priv->devdata->reg_auto_pd_en); + phy_write(phy, 0x02, priv->devdata->reg_rxlprp); + phy_write(phy, 0x02, priv->devdata->reg_rxcdrp); + phy_write(phy, 0x25, DPHY_TST); + + mixel_phy_set_hs_timings(phy); + ret = mixel_dphy_set_pll_params(phy); + if (ret < 0) + return ret; + + return 0; +} + +static int mixel_dphy_validate(struct phy *phy, enum phy_mode mode, int submode, + union phy_configure_opts *opts) +{ + struct mixel_dphy_cfg cfg = { 0 }; + + if (mode != PHY_MODE_MIPI_DPHY) + return -EINVAL; + + return mixel_dphy_config_from_opts(phy, &opts->mipi_dphy, &cfg); +} + +static int mixel_dphy_init(struct phy *phy) +{ + phy_write(phy, PWR_OFF, DPHY_PD_PLL); + phy_write(phy, PWR_OFF, DPHY_PD_DPHY); + + return 0; +} + +static int mixel_dphy_exit(struct phy *phy) +{ + phy_write(phy, 0, DPHY_CM); + phy_write(phy, 0, DPHY_CN); + phy_write(phy, 0, DPHY_CO); + + return 0; +} + +static int mixel_dphy_power_on(struct phy *phy) +{ + struct mixel_dphy_priv *priv = phy_get_drvdata(phy); + u32 locked; + int ret; + + ret = clk_prepare_enable(priv->phy_ref_clk); + if (ret < 0) + return ret; + + phy_write(phy, PWR_ON, DPHY_PD_PLL); + ret = regmap_read_poll_timeout(priv->regmap, DPHY_LOCK, locked, + locked, PLL_LOCK_SLEEP, + PLL_LOCK_TIMEOUT); + if (ret < 0) { + dev_err(&phy->dev, "Could not get DPHY lock (%d)!\n", ret); + goto clock_disable; + } + phy_write(phy, PWR_ON, DPHY_PD_DPHY); + + return 0; +clock_disable: + clk_disable_unprepare(priv->phy_ref_clk); + return ret; +} + +static int mixel_dphy_power_off(struct phy *phy) +{ + struct mixel_dphy_priv *priv = phy_get_drvdata(phy); + + phy_write(phy, PWR_OFF, DPHY_PD_PLL); + phy_write(phy, PWR_OFF, DPHY_PD_DPHY); + + clk_disable_unprepare(priv->phy_ref_clk); + + return 0; +} + +static const struct phy_ops mixel_dphy_phy_ops = { + .init = mixel_dphy_init, + .exit = mixel_dphy_exit, + .power_on = mixel_dphy_power_on, + .power_off = mixel_dphy_power_off, + .configure = mixel_dphy_configure, + .validate = mixel_dphy_validate, + .owner = THIS_MODULE, +}; + +static const struct of_device_id mixel_dphy_of_match[] = { + { .compatible = "fsl,imx8mq-mipi-dphy", + .data = &mixel_dphy_devdata[MIXEL_IMX8MQ] }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, mixel_dphy_of_match); + +static int mixel_dphy_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct phy_provider *phy_provider; + struct mixel_dphy_priv *priv; + struct resource *res; + struct phy *phy; + void __iomem *base; + + if (!np) + return -ENODEV; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->devdata = of_device_get_match_data(&pdev->dev); + if (!priv->devdata) + return -EINVAL; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + base = devm_ioremap_resource(dev, res); + if (IS_ERR(base)) + return PTR_ERR(base); + + priv->regmap = devm_regmap_init_mmio(&pdev->dev, base, + &mixel_dphy_regmap_config); + if (IS_ERR(priv->regmap)) { + dev_err(dev, "Couldn't create the DPHY regmap\n"); + return PTR_ERR(priv->regmap); + } + + priv->phy_ref_clk = devm_clk_get(&pdev->dev, "phy_ref"); + if (IS_ERR(priv->phy_ref_clk)) { + dev_err(dev, "No phy_ref clock found\n"); + return PTR_ERR(priv->phy_ref_clk); + } + dev_dbg(dev, "phy_ref clock rate: %lu\n", + clk_get_rate(priv->phy_ref_clk)); + + dev_set_drvdata(dev, priv); + + phy = devm_phy_create(dev, np, &mixel_dphy_phy_ops); + if (IS_ERR(phy)) { + dev_err(dev, "Failed to create phy %ld\n", PTR_ERR(phy)); + return PTR_ERR(phy); + } + phy_set_drvdata(phy, priv); + + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + + return PTR_ERR_OR_ZERO(phy_provider); +} + +static struct platform_driver mixel_dphy_driver = { + .probe = mixel_dphy_probe, + .driver = { + .name = "mixel-mipi-dphy", + .of_match_table = mixel_dphy_of_match, + } +}; +module_platform_driver(mixel_dphy_driver); + +MODULE_AUTHOR("NXP Semiconductor"); +MODULE_DESCRIPTION("Mixel MIPI-DSI PHY driver"); +MODULE_LICENSE("GPL"); -- cgit v1.2.3 From 235e6e0a8d5fd1d0285a8d13fbaa3b92112b877a Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 21 Jun 2019 15:28:35 +0200 Subject: remove Documentation/index.rst.rej It got added accidentally by a previous patch that I had to "hand apply". Reported-by: Stephen Rothwell Signed-off-by: Greg Kroah-Hartman --- Documentation/index.rst.rej | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 Documentation/index.rst.rej diff --git a/Documentation/index.rst.rej b/Documentation/index.rst.rej deleted file mode 100644 index b1af6eab22f3..000000000000 --- a/Documentation/index.rst.rej +++ /dev/null @@ -1,10 +0,0 @@ ---- Documentation/index.rst -+++ Documentation/index.rst -@@ -103,6 +103,7 @@ needed). - vm/index - bpf/index - PCI/index -+ usb/index - misc-devices/index - - Architecture-specific documentation -- cgit v1.2.3 From 4850f26abfcac9ed28a4db5817b46dc0bfbbbae0 Mon Sep 17 00:00:00 2001 From: Daniel M German Date: Fri, 21 Jun 2019 08:22:40 -0700 Subject: usb: clean up some of the computations in adu_read Replace ?: with min to calculate the number of bytes in the secondary buffer, including changing the data type of data_in_secondary to size_t to be type-consistent. data_in_secondary can never be negative. Remove some spurious calculations (copy_to_user returns zero on success), making one variable redundant (i) This change does not alter the functionality of the code. Signed-off-by: Daniel M German Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/adutux.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c index 9465fb95d70a..344d523b0502 100644 --- a/drivers/usb/misc/adutux.c +++ b/drivers/usb/misc/adutux.c @@ -343,7 +343,6 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count, struct adu_device *dev; size_t bytes_read = 0; size_t bytes_to_read = count; - int i; int retval = 0; int timeout = 0; int should_submit = 0; @@ -371,23 +370,22 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count, timeout = COMMAND_TIMEOUT; dev_dbg(&dev->udev->dev, "%s : about to start looping\n", __func__); while (bytes_to_read) { - int data_in_secondary = dev->secondary_tail - dev->secondary_head; + size_t data_in_secondary = dev->secondary_tail - dev->secondary_head; dev_dbg(&dev->udev->dev, - "%s : while, data_in_secondary=%d, status=%d\n", + "%s : while, data_in_secondary=%zu, status=%d\n", __func__, data_in_secondary, dev->interrupt_in_urb->status); if (data_in_secondary) { /* drain secondary buffer */ - int amount = bytes_to_read < data_in_secondary ? bytes_to_read : data_in_secondary; - i = copy_to_user(buffer, dev->read_buffer_secondary+dev->secondary_head, amount); - if (i) { + size_t amount = min(bytes_to_read, data_in_secondary); + if (copy_to_user(buffer, dev->read_buffer_secondary+dev->secondary_head, amount)) { retval = -EFAULT; goto exit; } - dev->secondary_head += (amount - i); - bytes_read += (amount - i); - bytes_to_read -= (amount - i); + dev->secondary_head += amount; + bytes_read += amount; + bytes_to_read -= amount; } else { /* we check the primary buffer */ spin_lock_irqsave (&dev->buflock, flags); -- cgit v1.2.3 From 5fc2aa3ec9efad97dd7c316f3c8e4c6268bbed9b Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Wed, 5 Jun 2019 11:02:15 +0200 Subject: phy: meson-g12a-usb3-pcie: disable locking for cr_regmap Locking is not needed for the phy_g12a_usb3_pcie_cr_bus_read/write() and currently it causes the following BUG because of the usage of the regmap_read_poll_timeout() running in spinlock_irq, configured by regmap fast_io. Simply disable locking in the cr_regmap config since it's only used from the PHY init callback function. BUG: sleeping function called from invalid context at drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c:85 in_atomic(): 1, irqs_disabled(): 128, pid: 60, name: kworker/3:1 [snip] Workqueue: events deferred_probe_work_func Call trace: dump_backtrace+0x0/0x190 show_stack+0x14/0x20 dump_stack+0x90/0xb4 ___might_sleep+0xec/0x110 __might_sleep+0x50/0x88 phy_g12a_usb3_pcie_cr_bus_addr.isra.0+0x80/0x1a8 phy_g12a_usb3_pcie_cr_bus_read+0x34/0x1d8 _regmap_read+0x60/0xe0 _regmap_update_bits+0xc4/0x110 regmap_update_bits_base+0x60/0x90 phy_g12a_usb3_pcie_init+0xdc/0x210 phy_init+0x74/0xd0 dwc3_meson_g12a_probe+0x2cc/0x4d0 platform_drv_probe+0x50/0xa0 really_probe+0x20c/0x3b8 driver_probe_device+0x68/0x150 __device_attach_driver+0xa8/0x170 bus_for_each_drv+0x64/0xc8 __device_attach+0xd8/0x158 device_initial_probe+0x10/0x18 bus_probe_device+0x90/0x98 deferred_probe_work_func+0x94/0xe8 process_one_work+0x1e0/0x338 worker_thread+0x230/0x458 kthread+0x134/0x138 ret_from_fork+0x10/0x1c Fixes: 36077e16c050 ("phy: amlogic: Add Amlogic G12A USB3 + PCIE Combo PHY Driver") Signed-off-by: Neil Armstrong Tested-by: Kevin Hilman Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c b/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c index 6233a7979a93..ac322d643c7a 100644 --- a/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c +++ b/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c @@ -188,7 +188,7 @@ static const struct regmap_config phy_g12a_usb3_pcie_cr_regmap_conf = { .reg_read = phy_g12a_usb3_pcie_cr_bus_read, .reg_write = phy_g12a_usb3_pcie_cr_bus_write, .max_register = 0xffff, - .fast_io = true, + .disable_locking = true, }; static int phy_g12a_usb3_init(struct phy *phy) -- cgit v1.2.3 From 5206026404190125436f81088eb3667076e56083 Mon Sep 17 00:00:00 2001 From: Marc Gonzalez Date: Thu, 13 Jun 2019 13:32:08 +0200 Subject: phy: qcom-qmp: Raise qcom_qmp_phy_enable() polling delay readl_poll_timeout() calls usleep_range() to sleep between reads. usleep_range() doesn't work efficiently for tiny values. Raise the polling delay in qcom_qmp_phy_enable() to bring it in line with the delay in qcom_qmp_phy_com_init(). Signed-off-by: Marc Gonzalez Signed-off-by: Kishon Vijay Abraham I --- drivers/phy/qualcomm/phy-qcom-qmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c b/drivers/phy/qualcomm/phy-qcom-qmp.c index bb522b915fa9..34ff6434da8f 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp.c @@ -1548,7 +1548,7 @@ static int qcom_qmp_phy_enable(struct phy *phy) status = pcs + cfg->regs[QPHY_PCS_READY_STATUS]; mask = cfg->mask_pcs_ready; - ret = readl_poll_timeout(status, val, val & mask, 1, + ret = readl_poll_timeout(status, val, val & mask, 10, PHY_INIT_COMPLETE_TIMEOUT); if (ret) { dev_err(qmp->dev, "phy initialization timed-out\n"); -- cgit v1.2.3 From ffed60971f3d95923b99ea970862c6ab6a22c20f Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Tue, 25 Jun 2019 16:03:58 -0400 Subject: USB: core: Remove usbfs_mutex Commit 4a2a8a2cce86 ("usbfs: private mutex for open, release, and remove") is now obsolete. The commit was created back when we had to handle both usbfs device nodes and the old usbdevfs filesystem (/proc/bus/usb/), but usbdevfs no longer exists. This means there's no longer any need to hold a mutex during two separate removal operations (and thus during an entire notifier chain call). Furthermore, the one remaining remove/release pair doesn't race with open thanks to the synchronization provided by the device model core in bus_find_device(). Remove and release don't race with each other because they both run with the device lock held. The upshot is that usbfs_mutex isn't needed any more. This patch removes it entirely. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/devio.c | 9 --------- drivers/usb/core/notify.c | 3 --- drivers/usb/core/usb.h | 1 - 3 files changed, 13 deletions(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 186790b06b11..0100a54165cd 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -48,9 +48,6 @@ #define USB_DEVICE_MAX (USB_MAXBUS * 128) #define USB_SG_SIZE 16384 /* split-size for large txs */ -/* Mutual exclusion for removal, open, and release */ -DEFINE_MUTEX(usbfs_mutex); - struct usb_dev_state { struct list_head list; /* state list */ struct usb_device *dev; @@ -979,15 +976,9 @@ static int usbdev_open(struct inode *inode, struct file *file) ret = -ENODEV; - /* Protect against simultaneous removal or release */ - mutex_lock(&usbfs_mutex); - /* usbdev device-node */ if (imajor(inode) == USB_DEVICE_MAJOR) dev = usbdev_lookup_by_devt(inode->i_rdev); - - mutex_unlock(&usbfs_mutex); - if (!dev) goto out_free_ps; diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c index ab474b11523e..e6143663778f 100644 --- a/drivers/usb/core/notify.c +++ b/drivers/usb/core/notify.c @@ -53,11 +53,8 @@ void usb_notify_add_device(struct usb_device *udev) void usb_notify_remove_device(struct usb_device *udev) { - /* Protect against simultaneous usbfs open */ - mutex_lock(&usbfs_mutex); blocking_notifier_call_chain(&usb_notifier_list, USB_DEVICE_REMOVE, udev); - mutex_unlock(&usbfs_mutex); } void usb_notify_add_bus(struct usb_bus *ubus) diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index d95a5358f73d..bd8d01f85a13 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h @@ -169,7 +169,6 @@ extern const struct attribute_group *usb_device_groups[]; extern const struct attribute_group *usb_interface_groups[]; /* usbfs stuff */ -extern struct mutex usbfs_mutex; extern struct usb_driver usbfs_driver; extern const struct file_operations usbfs_devices_fops; extern const struct file_operations usbdev_file_operations; -- cgit v1.2.3 From 257adc0fbe9f0a26695f4d68bdbf2886f5a3ecd0 Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Tue, 25 Jun 2019 16:00:26 -0400 Subject: USB: core: Fix compiler warnings in devio.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the current kernel, devio.c generates a number of compiler warnings about taking the address of a member of a packed structure. The warnings all look like this one: drivers/usb/core/devio.c: In function ‘proc_do_submiturb’: drivers/usb/core/devio.c:1489:43: warning: taking address of packed member of ‘struct usb_ctrlrequest’ may result in an unaligned pointer value [-Waddress-of-packed-member] 1489 | if (uurb->buffer_length < (le16_to_cpup(&dr->wLength) + 8)) { | ^~~~~~~~~~~~ These warnings can easily be eliminated by changing various le16_to_cpup() calls to use le16_to_cpu() instead. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/devio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 0100a54165cd..a951ce69f10e 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -1510,15 +1510,15 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb ret = -EFAULT; goto error; } - if (uurb->buffer_length < (le16_to_cpup(&dr->wLength) + 8)) { + if (uurb->buffer_length < (le16_to_cpu(dr->wLength) + 8)) { ret = -EINVAL; goto error; } ret = check_ctrlrecip(ps, dr->bRequestType, dr->bRequest, - le16_to_cpup(&dr->wIndex)); + le16_to_cpu(dr->wIndex)); if (ret) goto error; - uurb->buffer_length = le16_to_cpup(&dr->wLength); + uurb->buffer_length = le16_to_cpu(dr->wLength); uurb->buffer += 8; if ((dr->bRequestType & USB_DIR_IN) && uurb->buffer_length) { is_in = 1; @@ -1533,9 +1533,9 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb "bRequest=%02x wValue=%04x " "wIndex=%04x wLength=%04x\n", dr->bRequestType, dr->bRequest, - __le16_to_cpup(&dr->wValue), - __le16_to_cpup(&dr->wIndex), - __le16_to_cpup(&dr->wLength)); + __le16_to_cpu(dr->wValue), + __le16_to_cpu(dr->wIndex), + __le16_to_cpu(dr->wLength)); u = sizeof(struct usb_ctrlrequest); break; -- cgit v1.2.3 From 8fac4fee2014e8b186981177b2ac74d172001a0d Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:45 +0900 Subject: usb: renesas_usbhs: revise the irq_vbus comments Since the irq_vbus comments doesn't match with the current implementation, this patch revises it. This patch also changes new lines to reduce the source code lines. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/mod.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/renesas_usbhs/mod.h b/drivers/usb/renesas_usbhs/mod.h index a4a61d6b82a1..7117729dce7b 100644 --- a/drivers/usb/renesas_usbhs/mod.h +++ b/drivers/usb/renesas_usbhs/mod.h @@ -3,6 +3,7 @@ * Renesas USB driver * * Copyright (C) 2011 Renesas Solutions Corp. + * Copyright (C) 2019 Renesas Electronics Corporation * Kuninori Morimoto */ #ifndef RENESAS_USB_MOD_H @@ -84,12 +85,11 @@ struct usbhs_mod_info { /* * INTSTS0 :: VBINT * - * This function will be used as autonomy mode - * when platform cannot call notify_hotplug. + * This function will be used as autonomy mode (runtime_pwctrl == 0) + * when the platform doesn't have own get_vbus function. * - * This callback cannot be member of "struct usbhs_mod" - * because it will be used even though - * host/gadget has not been selected. + * This callback cannot be member of "struct usbhs_mod" because it + * will be used even though host/gadget has not been selected. */ int (*irq_vbus)(struct usbhs_priv *priv, struct usbhs_irq_state *irq_state); -- cgit v1.2.3 From 0966648dd5a5f4037d29d233866b7a4db39d07f7 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:46 +0900 Subject: usb: renesas_usbhs: remove notify_hotplug callback The notify_hotplug callback was supported in v3.10, but the last user (armadillo800eva) was removed by the commit 1fa59bda21c7 ("ARM: shmobile: Remove legacy board code for Armadillo-800 EVA"). So, this patch removes it. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 16 ++++------------ drivers/usb/renesas_usbhs/common.h | 2 ++ drivers/usb/renesas_usbhs/mod.c | 3 ++- drivers/usb/renesas_usbhs/mod_gadget.c | 3 ++- include/linux/usb/renesas_usbhs.h | 26 +------------------------- 5 files changed, 11 insertions(+), 39 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index ebbe322182bd..f6b136a4f91e 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -3,6 +3,7 @@ * Renesas USB driver * * Copyright (C) 2011 Renesas Solutions Corp. + * Copyright (C) 2019 Renesas Electronics Corporation * Kuninori Morimoto */ #include @@ -513,7 +514,7 @@ static void usbhsc_notify_hotplug(struct work_struct *work) usbhsc_hotplug(priv); } -static int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev) +int usbhsc_schedule_notify_hotplug(struct platform_device *pdev) { struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); int delay = usbhs_get_dparam(priv, detection_delay); @@ -667,7 +668,6 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) static int usbhs_probe(struct platform_device *pdev) { struct renesas_usbhs_platform_info *info = renesas_usbhs_get_info(pdev); - struct renesas_usbhs_driver_callback *dfunc; struct usbhs_priv *priv; struct resource *res, *irq_res; int ret; @@ -721,10 +721,6 @@ static int usbhs_probe(struct platform_device *pdev) } priv->pfunc = info->platform_callback; - /* set driver callback functions for platform */ - dfunc = &info->driver_callback; - dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug; - /* set default param if platform doesn't have */ if (!priv->dparam.pipe_configs) { priv->dparam.pipe_configs = usbhsc_default_pipe; @@ -818,7 +814,7 @@ static int usbhs_probe(struct platform_device *pdev) /* * manual call notify_hotplug for cold plug */ - usbhsc_drvcllbck_notify_hotplug(pdev); + usbhsc_schedule_notify_hotplug(pdev); dev_info(&pdev->dev, "probed\n"); @@ -843,13 +839,9 @@ probe_end_pipe_exit: static int usbhs_remove(struct platform_device *pdev) { struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); - struct renesas_usbhs_platform_info *info = renesas_usbhs_get_info(pdev); - struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback; dev_dbg(&pdev->dev, "usb remove\n"); - dfunc->notify_hotplug = NULL; - /* power off */ if (!usbhs_get_dparam(priv, runtime_pwctrl)) usbhsc_power_ctrl(priv, 0); @@ -894,7 +886,7 @@ static __maybe_unused int usbhsc_resume(struct device *dev) usbhs_platform_call(priv, phy_reset, pdev); - usbhsc_drvcllbck_notify_hotplug(pdev); + usbhsc_schedule_notify_hotplug(pdev); return 0; } diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h index de74ebd1a347..b2b21fbb7ce2 100644 --- a/drivers/usb/renesas_usbhs/common.h +++ b/drivers/usb/renesas_usbhs/common.h @@ -3,6 +3,7 @@ * Renesas USB driver * * Copyright (C) 2011 Renesas Solutions Corp. + * Copyright (C) 2019 Renesas Electronics Corporation * Kuninori Morimoto */ #ifndef RENESAS_USB_DRIVER_H @@ -317,6 +318,7 @@ void usbhs_bus_send_sof_enable(struct usbhs_priv *priv); void usbhs_bus_send_reset(struct usbhs_priv *priv); int usbhs_bus_get_speed(struct usbhs_priv *priv); int usbhs_vbus_ctrl(struct usbhs_priv *priv, int enable); +int usbhsc_schedule_notify_hotplug(struct platform_device *pdev); /* * frame diff --git a/drivers/usb/renesas_usbhs/mod.c b/drivers/usb/renesas_usbhs/mod.c index 7475c4f64724..540472abb23a 100644 --- a/drivers/usb/renesas_usbhs/mod.c +++ b/drivers/usb/renesas_usbhs/mod.c @@ -3,6 +3,7 @@ * Renesas USB driver * * Copyright (C) 2011 Renesas Solutions Corp. + * Copyright (C) 2019 Renesas Electronics Corporation * Kuninori Morimoto */ #include @@ -41,7 +42,7 @@ static int usbhsm_autonomy_irq_vbus(struct usbhs_priv *priv, { struct platform_device *pdev = usbhs_priv_to_pdev(priv); - renesas_usbhs_call_notify_hotplug(pdev); + usbhsc_schedule_notify_hotplug(pdev); return 0; } diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index 59cac40aafcc..0c1e8fa528fc 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c @@ -3,6 +3,7 @@ * Renesas USB driver * * Copyright (C) 2011 Renesas Solutions Corp. + * Copyright (C) 2019 Renesas Electronics Corporation * Kuninori Morimoto */ #include @@ -1023,7 +1024,7 @@ static int usbhsg_vbus_session(struct usb_gadget *gadget, int is_active) gpriv->vbus_active = !!is_active; - renesas_usbhs_call_notify_hotplug(pdev); + usbhsc_schedule_notify_hotplug(pdev); return 0; } diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index b2cba7c74444..ac601be95ec0 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h @@ -3,6 +3,7 @@ * Renesas USB * * Copyright (C) 2011 Renesas Solutions Corp. + * Copyright (C) 2019 Renesas Electronics Corporation * Kuninori Morimoto * * This program is distributed in the hope that it will be useful, @@ -32,17 +33,6 @@ enum { USBHS_MAX, }; -/* - * callback functions table for driver - * - * These functions are called from platform for driver. - * Callback function's pointer will be set before - * renesas_usbhs_platform_callback :: hardware_init was called - */ -struct renesas_usbhs_driver_callback { - int (*notify_hotplug)(struct platform_device *pdev); -}; - /* * callback functions for platform * @@ -213,12 +203,6 @@ struct renesas_usbhs_platform_info { */ struct renesas_usbhs_platform_callback platform_callback; - /* - * driver set these callback functions pointer. - * platform can use it on callback functions - */ - struct renesas_usbhs_driver_callback driver_callback; - /* * option: * @@ -232,12 +216,4 @@ struct renesas_usbhs_platform_info { */ #define renesas_usbhs_get_info(pdev)\ ((struct renesas_usbhs_platform_info *)(pdev)->dev.platform_data) - -#define renesas_usbhs_call_notify_hotplug(pdev) \ - ({ \ - struct renesas_usbhs_driver_callback *dc; \ - dc = &(renesas_usbhs_get_info(pdev)->driver_callback); \ - if (dc && dc->notify_hotplug) \ - dc->notify_hotplug(pdev); \ - }) #endif /* RENESAS_USB_H */ -- cgit v1.2.3 From edcf2b2c6629feac147e1a0abdbb3408769ff7e7 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:47 +0900 Subject: usb: renesas_usbhs: move macros from mod.c to the mod.h In the future, since other source code of this driver will use these macros, this patch moves it to the header file. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/mod.c | 9 --------- drivers/usb/renesas_usbhs/mod.h | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/usb/renesas_usbhs/mod.c b/drivers/usb/renesas_usbhs/mod.c index 540472abb23a..984bb2fff8b8 100644 --- a/drivers/usb/renesas_usbhs/mod.c +++ b/drivers/usb/renesas_usbhs/mod.c @@ -11,15 +11,6 @@ #include "common.h" #include "mod.h" -#define usbhs_priv_to_modinfo(priv) (&priv->mod_info) -#define usbhs_mod_info_call(priv, func, param...) \ -({ \ - struct usbhs_mod_info *info; \ - info = usbhs_priv_to_modinfo(priv); \ - !info->func ? 0 : \ - info->func(param); \ -}) - /* * autonomy * diff --git a/drivers/usb/renesas_usbhs/mod.h b/drivers/usb/renesas_usbhs/mod.h index 7117729dce7b..6678e8103bb1 100644 --- a/drivers/usb/renesas_usbhs/mod.h +++ b/drivers/usb/renesas_usbhs/mod.h @@ -129,6 +129,15 @@ void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod); mod->func(param); \ }) +#define usbhs_priv_to_modinfo(priv) (&priv->mod_info) +#define usbhs_mod_info_call(priv, func, param...) \ +({ \ + struct usbhs_mod_info *info; \ + info = usbhs_priv_to_modinfo(priv); \ + !info->func ? 0 : \ + info->func(param); \ +}) + /* * host / gadget control */ -- cgit v1.2.3 From ccc3264c2481c9bcbacfe935dc024aaab4423204 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:48 +0900 Subject: usb: renesas_usbhs: Avoid to write platform_data's value The very old commit 482982062f1b ("usb: gadget: renesas_usbhs: bugfix: don't modify platform data") changed to use copied whole structures values to fix the "hung-up" issue. However, we also can fix the issue if the driver copies the get_vbus function pointer to the driver's value. So, this patch adds get_vbus member into struct usbhs_mod_info and use the pointer instead of struct renesas_usbhs_platform_callback. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 4 +++- drivers/usb/renesas_usbhs/mod.c | 11 +++++++++-- drivers/usb/renesas_usbhs/mod.h | 7 +++++++ drivers/usb/renesas_usbhs/mod_gadget.c | 4 ++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index f6b136a4f91e..739fe4b4c1d5 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -448,7 +448,7 @@ static void usbhsc_hotplug(struct usbhs_priv *priv) /* * get vbus status from platform */ - enable = usbhs_platform_call(priv, get_vbus, pdev); + enable = usbhs_mod_info_call(priv, get_vbus, pdev); /* * get id from platform @@ -809,6 +809,8 @@ static int usbhs_probe(struct platform_device *pdev) if (!usbhs_get_dparam(priv, runtime_pwctrl)) { usbhsc_power_ctrl(priv, 1); usbhs_mod_autonomy_mode(priv); + } else { + usbhs_mod_non_autonomy_mode(priv); } /* diff --git a/drivers/usb/renesas_usbhs/mod.c b/drivers/usb/renesas_usbhs/mod.c index 984bb2fff8b8..ddf0153dcf16 100644 --- a/drivers/usb/renesas_usbhs/mod.c +++ b/drivers/usb/renesas_usbhs/mod.c @@ -42,12 +42,19 @@ void usbhs_mod_autonomy_mode(struct usbhs_priv *priv) { struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv); - info->irq_vbus = usbhsm_autonomy_irq_vbus; - priv->pfunc.get_vbus = usbhsm_autonomy_get_vbus; + info->irq_vbus = usbhsm_autonomy_irq_vbus; + info->get_vbus = usbhsm_autonomy_get_vbus; usbhs_irq_callback_update(priv, NULL); } +void usbhs_mod_non_autonomy_mode(struct usbhs_priv *priv) +{ + struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv); + + info->get_vbus = priv->pfunc.get_vbus; +} + /* * host / gadget functions * diff --git a/drivers/usb/renesas_usbhs/mod.h b/drivers/usb/renesas_usbhs/mod.h index 6678e8103bb1..65dc19ca528e 100644 --- a/drivers/usb/renesas_usbhs/mod.h +++ b/drivers/usb/renesas_usbhs/mod.h @@ -93,6 +93,12 @@ struct usbhs_mod_info { */ int (*irq_vbus)(struct usbhs_priv *priv, struct usbhs_irq_state *irq_state); + + /* + * This function will be used on any gadget mode. To simplify the code, + * this member is in here. + */ + int (*get_vbus)(struct platform_device *pdev); }; /* @@ -107,6 +113,7 @@ int usbhs_mod_probe(struct usbhs_priv *priv); void usbhs_mod_remove(struct usbhs_priv *priv); void usbhs_mod_autonomy_mode(struct usbhs_priv *priv); +void usbhs_mod_non_autonomy_mode(struct usbhs_priv *priv); /* * status functions diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index 0c1e8fa528fc..4d571a5205e2 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c @@ -915,8 +915,8 @@ static void usbhs_mod_phy_mode(struct usbhs_priv *priv) { struct usbhs_mod_info *info = &priv->mod_info; - info->irq_vbus = NULL; - priv->pfunc.get_vbus = usbhsm_phy_get_vbus; + info->irq_vbus = NULL; + info->get_vbus = usbhsm_phy_get_vbus; usbhs_irq_callback_update(priv, NULL); } -- cgit v1.2.3 From df9f2c278b69fcd8b04c89612310f0036d21ec4c Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:49 +0900 Subject: usb: renesas_usbhs: Use a specific flag instead of type for multi_clks To remove the type of renesas_usbhs_driver_param in the future, this patch uses a specific flag "multi_clks". Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 8 +++----- include/linux/usb/renesas_usbhs.h | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 739fe4b4c1d5..530e2eb7ab08 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -288,11 +288,7 @@ static void usbhsc_set_buswait(struct usbhs_priv *priv) static bool usbhsc_is_multi_clks(struct usbhs_priv *priv) { - if (priv->dparam.type == USBHS_TYPE_RCAR_GEN3 || - priv->dparam.type == USBHS_TYPE_RCAR_GEN3_WITH_PLL) - return true; - - return false; + return priv->dparam.multi_clks; } static int usbhsc_clk_get(struct device *dev, struct usbhs_priv *priv) @@ -544,6 +540,7 @@ static const struct usbhs_of_data rcar_gen3_data = { .param = { .type = USBHS_TYPE_RCAR_GEN3, .has_usb_dmac = 1, + .multi_clks = 1, .pipe_configs = usbhsc_new_pipe, .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), } @@ -554,6 +551,7 @@ static const struct usbhs_of_data rcar_gen3_with_pll_data = { .param = { .type = USBHS_TYPE_RCAR_GEN3_WITH_PLL, .has_usb_dmac = 1, + .multi_clks = 1, .pipe_configs = usbhsc_new_pipe, .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), } diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index ac601be95ec0..e249c217cad1 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h @@ -181,6 +181,7 @@ struct renesas_usbhs_driver_param { u32 has_cnen:1; u32 cfifo_byte_addr:1; /* CFIFO is byte addressable */ #define USBHS_USB_DMAC_XFER_SIZE 32 /* hardcode the xfer size */ + u32 multi_clks:1; }; #define USBHS_TYPE_RCAR_GEN2 1 -- cgit v1.2.3 From a4027b409fa98dc47418dacd3dcb5c99c5a76e4d Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:50 +0900 Subject: usb: renesas_usbhs: Remove type member from renesas_usbhs_driver_param Now no one uses the type member so that this patch removes it. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 5 ----- include/linux/usb/renesas_usbhs.h | 7 ------- 2 files changed, 12 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 530e2eb7ab08..18727561fa65 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -528,7 +528,6 @@ int usbhsc_schedule_notify_hotplug(struct platform_device *pdev) static const struct usbhs_of_data rcar_gen2_data = { .platform_callback = &usbhs_rcar2_ops, .param = { - .type = USBHS_TYPE_RCAR_GEN2, .has_usb_dmac = 1, .pipe_configs = usbhsc_new_pipe, .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), @@ -538,7 +537,6 @@ static const struct usbhs_of_data rcar_gen2_data = { static const struct usbhs_of_data rcar_gen3_data = { .platform_callback = &usbhs_rcar3_ops, .param = { - .type = USBHS_TYPE_RCAR_GEN3, .has_usb_dmac = 1, .multi_clks = 1, .pipe_configs = usbhsc_new_pipe, @@ -549,7 +547,6 @@ static const struct usbhs_of_data rcar_gen3_data = { static const struct usbhs_of_data rcar_gen3_with_pll_data = { .platform_callback = &usbhs_rcar3_with_pll_ops, .param = { - .type = USBHS_TYPE_RCAR_GEN3_WITH_PLL, .has_usb_dmac = 1, .multi_clks = 1, .pipe_configs = usbhsc_new_pipe, @@ -560,7 +557,6 @@ static const struct usbhs_of_data rcar_gen3_with_pll_data = { static const struct usbhs_of_data rza1_data = { .platform_callback = &usbhs_rza1_ops, .param = { - .type = USBHS_TYPE_RZA1, .pipe_configs = usbhsc_new_pipe, .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), } @@ -569,7 +565,6 @@ static const struct usbhs_of_data rza1_data = { static const struct usbhs_of_data rza2_data = { .platform_callback = &usbhs_rza2_ops, .param = { - .type = USBHS_TYPE_RZA2, .has_cnen = 1, .cfifo_byte_addr = 1, .pipe_configs = usbhsc_new_pipe, diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index e249c217cad1..fee84b7d4d2a 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h @@ -170,7 +170,6 @@ struct renesas_usbhs_driver_param { */ int pio_dma_border; /* default is 64byte */ - uintptr_t type; u32 enable_gpio; /* @@ -184,12 +183,6 @@ struct renesas_usbhs_driver_param { u32 multi_clks:1; }; -#define USBHS_TYPE_RCAR_GEN2 1 -#define USBHS_TYPE_RCAR_GEN3 2 -#define USBHS_TYPE_RCAR_GEN3_WITH_PLL 3 -#define USBHS_TYPE_RZA1 4 -#define USBHS_TYPE_RZA2 5 - /* * option: * -- cgit v1.2.3 From 31e795c61d60f7044e5e39eb94f4c5cfcb94108f Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:51 +0900 Subject: usb: renesas_usbhs: Use dev_of_node macro instead of open coded This patch uses the dev_of_node macro instead of open coded to be better. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 14 +++++++------- drivers/usb/renesas_usbhs/fifo.c | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 18727561fa65..35b06e7d4eb4 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -297,7 +297,7 @@ static int usbhsc_clk_get(struct device *dev, struct usbhs_priv *priv) return 0; /* The first clock should exist */ - priv->clks[0] = of_clk_get(dev->of_node, 0); + priv->clks[0] = of_clk_get(dev_of_node(dev), 0); if (IS_ERR(priv->clks[0])) return PTR_ERR(priv->clks[0]); @@ -305,7 +305,7 @@ static int usbhsc_clk_get(struct device *dev, struct usbhs_priv *priv) * To backward compatibility with old DT, this driver checks the return * value if it's -ENOENT or not. */ - priv->clks[1] = of_clk_get(dev->of_node, 1); + priv->clks[1] = of_clk_get(dev_of_node(dev), 1); if (PTR_ERR(priv->clks[1]) == -ENOENT) priv->clks[1] = NULL; else if (IS_ERR(priv->clks[1])) @@ -648,10 +648,10 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) *dparam = data->param; info->platform_callback = *data->platform_callback; - if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp)) + if (!of_property_read_u32(dev_of_node(dev), "renesas,buswait", &tmp)) dparam->buswait_bwait = tmp; - gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0, - NULL); + gpio = of_get_named_gpio_flags(dev_of_node(dev), "renesas,enable-gpio", + 0, NULL); if (gpio > 0) dparam->enable_gpio = gpio; @@ -666,7 +666,7 @@ static int usbhs_probe(struct platform_device *pdev) int ret; /* check device node */ - if (pdev->dev.of_node) + if (dev_of_node(&pdev->dev)) info = pdev->dev.platform_data = usbhs_parse_dt(&pdev->dev); /* check platform information */ @@ -692,7 +692,7 @@ static int usbhs_probe(struct platform_device *pdev) if (IS_ERR(priv->base)) return PTR_ERR(priv->base); - if (of_property_read_bool(pdev->dev.of_node, "extcon")) { + if (of_property_read_bool(dev_of_node(&pdev->dev), "extcon")) { priv->edev = extcon_get_edev_by_phandle(&pdev->dev, 0); if (IS_ERR(priv->edev)) return PTR_ERR(priv->edev); diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c index e84d2ac2a30a..a345b2ef976e 100644 --- a/drivers/usb/renesas_usbhs/fifo.c +++ b/drivers/usb/renesas_usbhs/fifo.c @@ -3,6 +3,7 @@ * Renesas USB driver * * Copyright (C) 2011 Renesas Solutions Corp. + * Copyright (C) 2019 Renesas Electronics Corporation * Kuninori Morimoto */ #include @@ -1277,7 +1278,7 @@ static void usbhsf_dma_init(struct usbhs_priv *priv, struct usbhs_fifo *fifo, { struct device *dev = usbhs_priv_to_dev(priv); - if (dev->of_node) + if (dev_of_node(dev)) usbhsf_dma_init_dt(dev, fifo, channel); else usbhsf_dma_init_pdev(fifo); -- cgit v1.2.3 From 98e86506c24932a30f50ffcfcbc98b04e3c9bc60 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:52 +0900 Subject: usb: renesas_usbhs: Add has_new_pipe_configs flag In the future, each struct renesas_usbhs_driver_param is stored on the each platform related source code (e.g. rcar3.c). So, to simplify the source code, this patch adds a new flag has_new_pipe_configs. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 20 +++++++++----------- include/linux/usb/renesas_usbhs.h | 1 + 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 35b06e7d4eb4..f9476a07b0e9 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -529,8 +529,7 @@ static const struct usbhs_of_data rcar_gen2_data = { .platform_callback = &usbhs_rcar2_ops, .param = { .has_usb_dmac = 1, - .pipe_configs = usbhsc_new_pipe, - .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), + .has_new_pipe_configs = 1, } }; @@ -539,8 +538,7 @@ static const struct usbhs_of_data rcar_gen3_data = { .param = { .has_usb_dmac = 1, .multi_clks = 1, - .pipe_configs = usbhsc_new_pipe, - .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), + .has_new_pipe_configs = 1, } }; @@ -549,16 +547,14 @@ static const struct usbhs_of_data rcar_gen3_with_pll_data = { .param = { .has_usb_dmac = 1, .multi_clks = 1, - .pipe_configs = usbhsc_new_pipe, - .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), + .has_new_pipe_configs = 1, } }; static const struct usbhs_of_data rza1_data = { .platform_callback = &usbhs_rza1_ops, .param = { - .pipe_configs = usbhsc_new_pipe, - .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), + .has_new_pipe_configs = 1, } }; @@ -567,8 +563,7 @@ static const struct usbhs_of_data rza2_data = { .param = { .has_cnen = 1, .cfifo_byte_addr = 1, - .pipe_configs = usbhsc_new_pipe, - .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), + .has_new_pipe_configs = 1, } }; @@ -715,7 +710,10 @@ static int usbhs_probe(struct platform_device *pdev) priv->pfunc = info->platform_callback; /* set default param if platform doesn't have */ - if (!priv->dparam.pipe_configs) { + if (usbhs_get_dparam(priv, has_new_pipe_configs)) { + priv->dparam.pipe_configs = usbhsc_new_pipe; + priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_new_pipe); + } else if (!priv->dparam.pipe_configs) { priv->dparam.pipe_configs = usbhsc_default_pipe; priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe); } diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index fee84b7d4d2a..6914475bbc86 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h @@ -181,6 +181,7 @@ struct renesas_usbhs_driver_param { u32 cfifo_byte_addr:1; /* CFIFO is byte addressable */ #define USBHS_USB_DMAC_XFER_SIZE 32 /* hardcode the xfer size */ u32 multi_clks:1; + u32 has_new_pipe_configs:1; }; /* -- cgit v1.2.3 From f08acaf0096380235e2657089d8a5e09f6d4213f Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:53 +0900 Subject: usb: renesas_usbhs: Add struct device * declaration in usbhs_probe() Since this can remove over 80 charactors in a line, this patch adds struct device * declaration in usbhs_probe(). Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index f9476a07b0e9..379b4a0e1d06 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -658,27 +658,28 @@ static int usbhs_probe(struct platform_device *pdev) struct renesas_usbhs_platform_info *info = renesas_usbhs_get_info(pdev); struct usbhs_priv *priv; struct resource *res, *irq_res; + struct device *dev = &pdev->dev; int ret; /* check device node */ - if (dev_of_node(&pdev->dev)) + if (dev_of_node(dev)) info = pdev->dev.platform_data = usbhs_parse_dt(&pdev->dev); /* check platform information */ if (!info) { - dev_err(&pdev->dev, "no platform information\n"); + dev_err(dev, "no platform information\n"); return -EINVAL; } /* platform data */ irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (!irq_res) { - dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n"); + dev_err(dev, "Not enough Renesas USB platform resources.\n"); return -ENODEV; } /* usb private data */ - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; @@ -687,13 +688,13 @@ static int usbhs_probe(struct platform_device *pdev) if (IS_ERR(priv->base)) return PTR_ERR(priv->base); - if (of_property_read_bool(dev_of_node(&pdev->dev), "extcon")) { - priv->edev = extcon_get_edev_by_phandle(&pdev->dev, 0); + if (of_property_read_bool(dev_of_node(dev), "extcon")) { + priv->edev = extcon_get_edev_by_phandle(dev, 0); if (IS_ERR(priv->edev)) return PTR_ERR(priv->edev); } - priv->rsts = devm_reset_control_array_get_optional_shared(&pdev->dev); + priv->rsts = devm_reset_control_array_get_optional_shared(dev); if (IS_ERR(priv->rsts)) return PTR_ERR(priv->rsts); @@ -704,7 +705,7 @@ static int usbhs_probe(struct platform_device *pdev) priv->dparam = info->driver_param; if (!info->platform_callback.get_id) { - dev_err(&pdev->dev, "no platform callbacks"); + dev_err(dev, "no platform callbacks\n"); return -EINVAL; } priv->pfunc = info->platform_callback; @@ -755,7 +756,7 @@ static int usbhs_probe(struct platform_device *pdev) if (ret) goto probe_fail_rst; - ret = usbhsc_clk_get(&pdev->dev, priv); + ret = usbhsc_clk_get(dev, priv); if (ret) goto probe_fail_clks; @@ -771,8 +772,7 @@ static int usbhs_probe(struct platform_device *pdev) ret = !gpio_get_value(priv->dparam.enable_gpio); gpio_free(priv->dparam.enable_gpio); if (ret) { - dev_warn(&pdev->dev, - "USB function not selected (GPIO %d)\n", + dev_warn(dev, "USB function not selected (GPIO %d)\n", priv->dparam.enable_gpio); ret = -ENOTSUPP; goto probe_end_mod_exit; @@ -788,7 +788,7 @@ static int usbhs_probe(struct platform_device *pdev) */ ret = usbhs_platform_call(priv, hardware_init, pdev); if (ret < 0) { - dev_err(&pdev->dev, "platform init failed.\n"); + dev_err(dev, "platform init failed.\n"); goto probe_end_mod_exit; } @@ -796,7 +796,7 @@ static int usbhs_probe(struct platform_device *pdev) usbhs_platform_call(priv, phy_reset, pdev); /* power control */ - pm_runtime_enable(&pdev->dev); + pm_runtime_enable(dev); if (!usbhs_get_dparam(priv, runtime_pwctrl)) { usbhsc_power_ctrl(priv, 1); usbhs_mod_autonomy_mode(priv); @@ -809,7 +809,7 @@ static int usbhs_probe(struct platform_device *pdev) */ usbhsc_schedule_notify_hotplug(pdev); - dev_info(&pdev->dev, "probed\n"); + dev_info(dev, "probed\n"); return ret; @@ -824,7 +824,7 @@ probe_end_fifo_exit: probe_end_pipe_exit: usbhs_pipe_remove(priv); - dev_info(&pdev->dev, "probe failed (%d)\n", ret); + dev_info(dev, "probe failed (%d)\n", ret); return ret; } -- cgit v1.2.3 From b3103d0b022f8ce87d68994417bbf2765329da3a Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:54 +0900 Subject: usb: renesas_usbhs: move device tree properties parsing In the future, each struct renesas_usbhs_driver_param is stored on the each platform related source code (e.g. rcar3.c) to remove usbhs_parse_dt(). So, this patch moves device tree properties parsing to usbhs_probe(). Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 379b4a0e1d06..dc5e80d12a62 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -628,8 +628,6 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) struct renesas_usbhs_platform_info *info; struct renesas_usbhs_driver_param *dparam; const struct usbhs_of_data *data; - u32 tmp; - int gpio; info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); if (!info) @@ -643,13 +641,6 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) *dparam = data->param; info->platform_callback = *data->platform_callback; - if (!of_property_read_u32(dev_of_node(dev), "renesas,buswait", &tmp)) - dparam->buswait_bwait = tmp; - gpio = of_get_named_gpio_flags(dev_of_node(dev), "renesas,enable-gpio", - 0, NULL); - if (gpio > 0) - dparam->enable_gpio = gpio; - return info; } @@ -659,7 +650,8 @@ static int usbhs_probe(struct platform_device *pdev) struct usbhs_priv *priv; struct resource *res, *irq_res; struct device *dev = &pdev->dev; - int ret; + int ret, gpio; + u32 tmp; /* check device node */ if (dev_of_node(dev)) @@ -720,6 +712,12 @@ static int usbhs_probe(struct platform_device *pdev) } if (!priv->dparam.pio_dma_border) priv->dparam.pio_dma_border = 64; /* 64byte */ + if (!of_property_read_u32(dev_of_node(dev), "renesas,buswait", &tmp)) + priv->dparam.buswait_bwait = tmp; + gpio = of_get_named_gpio_flags(dev_of_node(dev), "renesas,enable-gpio", + 0, NULL); + if (gpio > 0) + priv->dparam.enable_gpio = gpio; /* FIXME */ /* runtime power control ? */ -- cgit v1.2.3 From be0a42a7d62605cfcabd8cbba6c104a80471cd94 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:55 +0900 Subject: usb: renesas_usbhs: Add a common function for the .get_id All platform related codes (rcar[23].c and rza{2}.c) has its own .get_id function as "USBHS_GADGET". So, we can use a common function for it. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 5 +++++ drivers/usb/renesas_usbhs/common.h | 2 ++ drivers/usb/renesas_usbhs/rcar2.c | 8 ++------ drivers/usb/renesas_usbhs/rcar3.c | 11 +++-------- drivers/usb/renesas_usbhs/rza.c | 9 ++------- drivers/usb/renesas_usbhs/rza2.c | 7 +------ 6 files changed, 15 insertions(+), 27 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index dc5e80d12a62..656f9765b44b 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -84,6 +84,11 @@ struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev) return dev_get_drvdata(&pdev->dev); } +int usbhs_get_id_as_gadget(struct platform_device *pdev) +{ + return USBHS_GADGET; +} + /* * syscfg functions */ diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h index b2b21fbb7ce2..65e9abc14e20 100644 --- a/drivers/usb/renesas_usbhs/common.h +++ b/drivers/usb/renesas_usbhs/common.h @@ -297,6 +297,8 @@ void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data); #define usbhs_lock(p, f) spin_lock_irqsave(usbhs_priv_to_lock(p), f) #define usbhs_unlock(p, f) spin_unlock_irqrestore(usbhs_priv_to_lock(p), f) +int usbhs_get_id_as_gadget(struct platform_device *pdev); + /* * sysconfig */ diff --git a/drivers/usb/renesas_usbhs/rcar2.c b/drivers/usb/renesas_usbhs/rcar2.c index 0027092b1118..741bd8170117 100644 --- a/drivers/usb/renesas_usbhs/rcar2.c +++ b/drivers/usb/renesas_usbhs/rcar2.c @@ -3,6 +3,7 @@ * Renesas USB driver R-Car Gen. 2 initialization and power control * * Copyright (C) 2014 Ulrich Hecht + * Copyright (C) 2019 Renesas Electronics Corporation */ #include @@ -62,14 +63,9 @@ static int usbhs_rcar2_power_ctrl(struct platform_device *pdev, return retval; } -static int usbhs_rcar2_get_id(struct platform_device *pdev) -{ - return USBHS_GADGET; -} - const struct renesas_usbhs_platform_callback usbhs_rcar2_ops = { .hardware_init = usbhs_rcar2_hardware_init, .hardware_exit = usbhs_rcar2_hardware_exit, .power_ctrl = usbhs_rcar2_power_ctrl, - .get_id = usbhs_rcar2_get_id, + .get_id = usbhs_get_id_as_gadget, }; diff --git a/drivers/usb/renesas_usbhs/rcar3.c b/drivers/usb/renesas_usbhs/rcar3.c index 5e730e9b40ef..8dbbd148b1b4 100644 --- a/drivers/usb/renesas_usbhs/rcar3.c +++ b/drivers/usb/renesas_usbhs/rcar3.c @@ -2,7 +2,7 @@ /* * Renesas USB driver R-Car Gen. 3 initialization and power control * - * Copyright (C) 2016 Renesas Electronics Corporation + * Copyright (C) 2016-2019 Renesas Electronics Corporation */ #include @@ -95,17 +95,12 @@ static int usbhs_rcar3_power_and_pll_ctrl(struct platform_device *pdev, return 0; } -static int usbhs_rcar3_get_id(struct platform_device *pdev) -{ - return USBHS_GADGET; -} - const struct renesas_usbhs_platform_callback usbhs_rcar3_ops = { .power_ctrl = usbhs_rcar3_power_ctrl, - .get_id = usbhs_rcar3_get_id, + .get_id = usbhs_get_id_as_gadget, }; const struct renesas_usbhs_platform_callback usbhs_rcar3_with_pll_ops = { .power_ctrl = usbhs_rcar3_power_and_pll_ctrl, - .get_id = usbhs_rcar3_get_id, + .get_id = usbhs_get_id_as_gadget, }; diff --git a/drivers/usb/renesas_usbhs/rza.c b/drivers/usb/renesas_usbhs/rza.c index 8c739bd24acd..64ce584d4f0b 100644 --- a/drivers/usb/renesas_usbhs/rza.c +++ b/drivers/usb/renesas_usbhs/rza.c @@ -3,7 +3,7 @@ * Renesas USB driver RZ/A initialization and power control * * Copyright (C) 2018 Chris Brandt - * Copyright (C) 2018 Renesas Electronics Corporation + * Copyright (C) 2018-2019 Renesas Electronics Corporation */ #include @@ -41,12 +41,7 @@ static int usbhs_rza1_hardware_init(struct platform_device *pdev) return 0; } -static int usbhs_rza_get_id(struct platform_device *pdev) -{ - return USBHS_GADGET; -} - const struct renesas_usbhs_platform_callback usbhs_rza1_ops = { .hardware_init = usbhs_rza1_hardware_init, - .get_id = usbhs_rza_get_id, + .get_id = usbhs_get_id_as_gadget, }; diff --git a/drivers/usb/renesas_usbhs/rza2.c b/drivers/usb/renesas_usbhs/rza2.c index 9d8551f93533..6e32768bc9ba 100644 --- a/drivers/usb/renesas_usbhs/rza2.c +++ b/drivers/usb/renesas_usbhs/rza2.c @@ -59,14 +59,9 @@ static int usbhs_rza2_power_ctrl(struct platform_device *pdev, return retval; } -static int usbhs_rza2_get_id(struct platform_device *pdev) -{ - return USBHS_GADGET; -} - const struct renesas_usbhs_platform_callback usbhs_rza2_ops = { .hardware_init = usbhs_rza2_hardware_init, .hardware_exit = usbhs_rza2_hardware_exit, .power_ctrl = usbhs_rza2_power_ctrl, - .get_id = usbhs_rza2_get_id, + .get_id = usbhs_get_id_as_gadget, }; -- cgit v1.2.3 From 76eff170bb05e59218008a21df670cb7177110e4 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:56 +0900 Subject: usb: renesas_usbhs: Use renesas_usbhs_platform_info on of_device_id.data In device tree environment, the previous code allocates renesas_usbhs_platform_info by using devm_kzalloc() and then copies usbhs_of_data to the allocated memory. This reason is some values (e.g. .platform_callback.get_vbus) are overwritten by the driver, but the of_device_id.data is "const". Now the driver doesn't have such a code, so this patch uses renesas_usbhs_platform_info on of_device_id.data. Note that the previous code set the pdev->dev.platform_data pointer even if device tree environment, but the value is not used. So, this patch also remove such a code. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 93 +++++++------------------------------- drivers/usb/renesas_usbhs/common.h | 5 -- drivers/usb/renesas_usbhs/rcar2.c | 16 +++++-- drivers/usb/renesas_usbhs/rcar2.h | 3 +- drivers/usb/renesas_usbhs/rcar3.c | 26 ++++++++--- drivers/usb/renesas_usbhs/rcar3.h | 5 +- drivers/usb/renesas_usbhs/rza.c | 11 +++-- drivers/usb/renesas_usbhs/rza.h | 4 +- drivers/usb/renesas_usbhs/rza2.c | 17 +++++-- 9 files changed, 73 insertions(+), 107 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 656f9765b44b..fe7dc91fef98 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -530,128 +530,65 @@ int usbhsc_schedule_notify_hotplug(struct platform_device *pdev) return 0; } -static const struct usbhs_of_data rcar_gen2_data = { - .platform_callback = &usbhs_rcar2_ops, - .param = { - .has_usb_dmac = 1, - .has_new_pipe_configs = 1, - } -}; - -static const struct usbhs_of_data rcar_gen3_data = { - .platform_callback = &usbhs_rcar3_ops, - .param = { - .has_usb_dmac = 1, - .multi_clks = 1, - .has_new_pipe_configs = 1, - } -}; - -static const struct usbhs_of_data rcar_gen3_with_pll_data = { - .platform_callback = &usbhs_rcar3_with_pll_ops, - .param = { - .has_usb_dmac = 1, - .multi_clks = 1, - .has_new_pipe_configs = 1, - } -}; - -static const struct usbhs_of_data rza1_data = { - .platform_callback = &usbhs_rza1_ops, - .param = { - .has_new_pipe_configs = 1, - } -}; - -static const struct usbhs_of_data rza2_data = { - .platform_callback = &usbhs_rza2_ops, - .param = { - .has_cnen = 1, - .cfifo_byte_addr = 1, - .has_new_pipe_configs = 1, - } -}; - /* * platform functions */ static const struct of_device_id usbhs_of_match[] = { { .compatible = "renesas,usbhs-r8a774c0", - .data = &rcar_gen3_with_pll_data, + .data = &usbhs_rcar_gen3_with_pll_plat_info, }, { .compatible = "renesas,usbhs-r8a7790", - .data = &rcar_gen2_data, + .data = &usbhs_rcar_gen2_plat_info, }, { .compatible = "renesas,usbhs-r8a7791", - .data = &rcar_gen2_data, + .data = &usbhs_rcar_gen2_plat_info, }, { .compatible = "renesas,usbhs-r8a7794", - .data = &rcar_gen2_data, + .data = &usbhs_rcar_gen2_plat_info, }, { .compatible = "renesas,usbhs-r8a7795", - .data = &rcar_gen3_data, + .data = &usbhs_rcar_gen3_plat_info, }, { .compatible = "renesas,usbhs-r8a7796", - .data = &rcar_gen3_data, + .data = &usbhs_rcar_gen3_plat_info, }, { .compatible = "renesas,usbhs-r8a77990", - .data = &rcar_gen3_with_pll_data, + .data = &usbhs_rcar_gen3_with_pll_plat_info, }, { .compatible = "renesas,usbhs-r8a77995", - .data = &rcar_gen3_with_pll_data, + .data = &usbhs_rcar_gen3_with_pll_plat_info, }, { .compatible = "renesas,rcar-gen2-usbhs", - .data = &rcar_gen2_data, + .data = &usbhs_rcar_gen2_plat_info, }, { .compatible = "renesas,rcar-gen3-usbhs", - .data = &rcar_gen3_data, + .data = &usbhs_rcar_gen3_plat_info, }, { .compatible = "renesas,rza1-usbhs", - .data = &rza1_data, + .data = &usbhs_rza1_plat_info, }, { .compatible = "renesas,rza2-usbhs", - .data = &rza2_data, + .data = &usbhs_rza2_plat_info, }, { }, }; MODULE_DEVICE_TABLE(of, usbhs_of_match); -static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) -{ - struct renesas_usbhs_platform_info *info; - struct renesas_usbhs_driver_param *dparam; - const struct usbhs_of_data *data; - - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); - if (!info) - return NULL; - - data = of_device_get_match_data(dev); - if (!data) - return NULL; - - dparam = &info->driver_param; - *dparam = data->param; - info->platform_callback = *data->platform_callback; - - return info; -} - static int usbhs_probe(struct platform_device *pdev) { - struct renesas_usbhs_platform_info *info = renesas_usbhs_get_info(pdev); + const struct renesas_usbhs_platform_info *info; struct usbhs_priv *priv; struct resource *res, *irq_res; struct device *dev = &pdev->dev; @@ -660,7 +597,9 @@ static int usbhs_probe(struct platform_device *pdev) /* check device node */ if (dev_of_node(dev)) - info = pdev->dev.platform_data = usbhs_parse_dt(&pdev->dev); + info = of_device_get_match_data(dev); + else + info = renesas_usbhs_get_info(pdev); /* check platform information */ if (!info) { diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h index 65e9abc14e20..f6ffdb2c1174 100644 --- a/drivers/usb/renesas_usbhs/common.h +++ b/drivers/usb/renesas_usbhs/common.h @@ -282,11 +282,6 @@ struct usbhs_priv { struct clk *clks[2]; }; -struct usbhs_of_data { - const struct renesas_usbhs_platform_callback *platform_callback; - const struct renesas_usbhs_driver_param param; -}; - /* * common */ diff --git a/drivers/usb/renesas_usbhs/rcar2.c b/drivers/usb/renesas_usbhs/rcar2.c index 741bd8170117..440d213e1749 100644 --- a/drivers/usb/renesas_usbhs/rcar2.c +++ b/drivers/usb/renesas_usbhs/rcar2.c @@ -63,9 +63,15 @@ static int usbhs_rcar2_power_ctrl(struct platform_device *pdev, return retval; } -const struct renesas_usbhs_platform_callback usbhs_rcar2_ops = { - .hardware_init = usbhs_rcar2_hardware_init, - .hardware_exit = usbhs_rcar2_hardware_exit, - .power_ctrl = usbhs_rcar2_power_ctrl, - .get_id = usbhs_get_id_as_gadget, +const struct renesas_usbhs_platform_info usbhs_rcar_gen2_plat_info = { + .platform_callback = { + .hardware_init = usbhs_rcar2_hardware_init, + .hardware_exit = usbhs_rcar2_hardware_exit, + .power_ctrl = usbhs_rcar2_power_ctrl, + .get_id = usbhs_get_id_as_gadget, + }, + .driver_param = { + .has_usb_dmac = 1, + .has_new_pipe_configs = 1, + }, }; diff --git a/drivers/usb/renesas_usbhs/rcar2.h b/drivers/usb/renesas_usbhs/rcar2.h index 45e3526cedeb..7d88732c5bff 100644 --- a/drivers/usb/renesas_usbhs/rcar2.h +++ b/drivers/usb/renesas_usbhs/rcar2.h @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-2.0 #include "common.h" -extern const struct renesas_usbhs_platform_callback - usbhs_rcar2_ops; +extern const struct renesas_usbhs_platform_info usbhs_rcar_gen2_plat_info; diff --git a/drivers/usb/renesas_usbhs/rcar3.c b/drivers/usb/renesas_usbhs/rcar3.c index 8dbbd148b1b4..c181b2a0b9d3 100644 --- a/drivers/usb/renesas_usbhs/rcar3.c +++ b/drivers/usb/renesas_usbhs/rcar3.c @@ -95,12 +95,26 @@ static int usbhs_rcar3_power_and_pll_ctrl(struct platform_device *pdev, return 0; } -const struct renesas_usbhs_platform_callback usbhs_rcar3_ops = { - .power_ctrl = usbhs_rcar3_power_ctrl, - .get_id = usbhs_get_id_as_gadget, +const struct renesas_usbhs_platform_info usbhs_rcar_gen3_plat_info = { + .platform_callback = { + .power_ctrl = usbhs_rcar3_power_ctrl, + .get_id = usbhs_get_id_as_gadget, + }, + .driver_param = { + .has_usb_dmac = 1, + .multi_clks = 1, + .has_new_pipe_configs = 1, + }, }; -const struct renesas_usbhs_platform_callback usbhs_rcar3_with_pll_ops = { - .power_ctrl = usbhs_rcar3_power_and_pll_ctrl, - .get_id = usbhs_get_id_as_gadget, +const struct renesas_usbhs_platform_info usbhs_rcar_gen3_with_pll_plat_info = { + .platform_callback = { + .power_ctrl = usbhs_rcar3_power_and_pll_ctrl, + .get_id = usbhs_get_id_as_gadget, + }, + .driver_param = { + .has_usb_dmac = 1, + .multi_clks = 1, + .has_new_pipe_configs = 1, + }, }; diff --git a/drivers/usb/renesas_usbhs/rcar3.h b/drivers/usb/renesas_usbhs/rcar3.h index 49e535a31771..c7c5ec1e3af2 100644 --- a/drivers/usb/renesas_usbhs/rcar3.h +++ b/drivers/usb/renesas_usbhs/rcar3.h @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "common.h" -extern const struct renesas_usbhs_platform_callback usbhs_rcar3_ops; -extern const struct renesas_usbhs_platform_callback usbhs_rcar3_with_pll_ops; +extern const struct renesas_usbhs_platform_info usbhs_rcar_gen3_plat_info; +extern const struct renesas_usbhs_platform_info + usbhs_rcar_gen3_with_pll_plat_info; diff --git a/drivers/usb/renesas_usbhs/rza.c b/drivers/usb/renesas_usbhs/rza.c index 64ce584d4f0b..24de64edb674 100644 --- a/drivers/usb/renesas_usbhs/rza.c +++ b/drivers/usb/renesas_usbhs/rza.c @@ -41,7 +41,12 @@ static int usbhs_rza1_hardware_init(struct platform_device *pdev) return 0; } -const struct renesas_usbhs_platform_callback usbhs_rza1_ops = { - .hardware_init = usbhs_rza1_hardware_init, - .get_id = usbhs_get_id_as_gadget, +const struct renesas_usbhs_platform_info usbhs_rza1_plat_info = { + .platform_callback = { + .hardware_init = usbhs_rza1_hardware_init, + .get_id = usbhs_get_id_as_gadget, + }, + .driver_param = { + .has_new_pipe_configs = 1, + }, }; diff --git a/drivers/usb/renesas_usbhs/rza.h b/drivers/usb/renesas_usbhs/rza.h index 073a53d1d442..1ca42a6fd480 100644 --- a/drivers/usb/renesas_usbhs/rza.h +++ b/drivers/usb/renesas_usbhs/rza.h @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 #include "common.h" -extern const struct renesas_usbhs_platform_callback usbhs_rza1_ops; -extern const struct renesas_usbhs_platform_callback usbhs_rza2_ops; +extern const struct renesas_usbhs_platform_info usbhs_rza1_plat_info; +extern const struct renesas_usbhs_platform_info usbhs_rza2_plat_info; diff --git a/drivers/usb/renesas_usbhs/rza2.c b/drivers/usb/renesas_usbhs/rza2.c index 6e32768bc9ba..021749594389 100644 --- a/drivers/usb/renesas_usbhs/rza2.c +++ b/drivers/usb/renesas_usbhs/rza2.c @@ -59,9 +59,16 @@ static int usbhs_rza2_power_ctrl(struct platform_device *pdev, return retval; } -const struct renesas_usbhs_platform_callback usbhs_rza2_ops = { - .hardware_init = usbhs_rza2_hardware_init, - .hardware_exit = usbhs_rza2_hardware_exit, - .power_ctrl = usbhs_rza2_power_ctrl, - .get_id = usbhs_get_id_as_gadget, +const struct renesas_usbhs_platform_info usbhs_rza2_plat_info = { + .platform_callback = { + .hardware_init = usbhs_rza2_hardware_init, + .hardware_exit = usbhs_rza2_hardware_exit, + .power_ctrl = usbhs_rza2_power_ctrl, + .get_id = usbhs_get_id_as_gadget, + }, + .driver_param = { + .has_cnen = 1, + .cfifo_byte_addr = 1, + .has_new_pipe_configs = 1, + }, }; -- cgit v1.2.3 From 426d3ff2f5ab7207aea0c1769d74b25a7b51b4dd Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Tue, 25 Jun 2019 14:38:57 +0900 Subject: usb: renesas_usbhs: Use struct platform_callback pointer Now the driver fixes the issue of the commit 482982062f1b ("usb: gadget: renesas_usbhs: bugfix: don't modify platform data") by using usbhs_mod_info.get_vbus, this patches uses the pointer instead of copied value to avoid redundancy. Note that struct renesas_usbhs_driver_param has to use copied value because the driver has to set some members (e.g. buswait_bwait). Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman --- drivers/usb/renesas_usbhs/common.c | 8 ++++---- drivers/usb/renesas_usbhs/common.h | 2 +- drivers/usb/renesas_usbhs/mod.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index fe7dc91fef98..4c3de777ef6c 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -53,8 +53,8 @@ */ #define usbhs_platform_call(priv, func, args...)\ (!(priv) ? -ENODEV : \ - !((priv)->pfunc.func) ? 0 : \ - (priv)->pfunc.func(args)) + !((priv)->pfunc->func) ? 0 : \ + (priv)->pfunc->func(args)) /* * common functions @@ -644,7 +644,7 @@ static int usbhs_probe(struct platform_device *pdev) dev_err(dev, "no platform callbacks\n"); return -EINVAL; } - priv->pfunc = info->platform_callback; + priv->pfunc = &info->platform_callback; /* set default param if platform doesn't have */ if (usbhs_get_dparam(priv, has_new_pipe_configs)) { @@ -665,7 +665,7 @@ static int usbhs_probe(struct platform_device *pdev) /* FIXME */ /* runtime power control ? */ - if (priv->pfunc.get_vbus) + if (priv->pfunc->get_vbus) usbhs_get_dparam(priv, runtime_pwctrl) = 1; /* diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h index f6ffdb2c1174..d1a0a35ecfff 100644 --- a/drivers/usb/renesas_usbhs/common.h +++ b/drivers/usb/renesas_usbhs/common.h @@ -252,7 +252,7 @@ struct usbhs_priv { unsigned int irq; unsigned long irqflags; - struct renesas_usbhs_platform_callback pfunc; + const struct renesas_usbhs_platform_callback *pfunc; struct renesas_usbhs_driver_param dparam; struct delayed_work notify_hotplug_work; diff --git a/drivers/usb/renesas_usbhs/mod.c b/drivers/usb/renesas_usbhs/mod.c index ddf0153dcf16..10fc65596014 100644 --- a/drivers/usb/renesas_usbhs/mod.c +++ b/drivers/usb/renesas_usbhs/mod.c @@ -52,7 +52,7 @@ void usbhs_mod_non_autonomy_mode(struct usbhs_priv *priv) { struct usbhs_mod_info *info = usbhs_priv_to_modinfo(priv); - info->get_vbus = priv->pfunc.get_vbus; + info->get_vbus = priv->pfunc->get_vbus; } /* -- cgit v1.2.3 From f8377eff548170e8ea8022c067a1fbdf9e1c46a8 Mon Sep 17 00:00:00 2001 From: Andreas Fritiofson Date: Fri, 28 Jun 2019 15:08:34 +0200 Subject: USB: serial: ftdi_sio: add ID for isodebug v1 This adds the vid:pid of the isodebug v1 isolated JTAG/SWD+UART. Only the second channel is available for use as a serial port. Signed-off-by: Andreas Fritiofson Cc: stable Signed-off-by: Johan Hovold --- drivers/usb/serial/ftdi_sio.c | 1 + drivers/usb/serial/ftdi_sio_ids.h | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 1d8461ae2c34..23669a584bae 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -1029,6 +1029,7 @@ static const struct usb_device_id id_table_combined[] = { { USB_DEVICE(AIRBUS_DS_VID, AIRBUS_DS_P8GR) }, /* EZPrototypes devices */ { USB_DEVICE(EZPROTOTYPES_VID, HJELMSLUND_USB485_ISO_PID) }, + { USB_DEVICE_INTERFACE_NUMBER(UNJO_VID, UNJO_ISODEBUG_V1_PID, 1) }, { } /* Terminating entry */ }; diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h index 5755f0df0025..f12d806220b4 100644 --- a/drivers/usb/serial/ftdi_sio_ids.h +++ b/drivers/usb/serial/ftdi_sio_ids.h @@ -1543,3 +1543,9 @@ #define CHETCO_SEASMART_DISPLAY_PID 0xA5AD /* SeaSmart NMEA2000 Display */ #define CHETCO_SEASMART_LITE_PID 0xA5AE /* SeaSmart Lite USB Adapter */ #define CHETCO_SEASMART_ANALOG_PID 0xA5AF /* SeaSmart Analog Adapter */ + +/* + * Unjo AB + */ +#define UNJO_VID 0x22B7 +#define UNJO_ISODEBUG_V1_PID 0x150D -- cgit v1.2.3 From b3649dee5fbb0f6585010e6e9313dfcbb075b22b Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 13 Dec 2017 16:03:22 +0200 Subject: usb: dwc3: pci: add support for TigerLake Devices This patch adds the necessary PCI ID for TGP-LP devices. Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/dwc3-pci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index f9b550081550..5e8e18222f92 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c @@ -35,6 +35,7 @@ #define PCI_DEVICE_ID_INTEL_CNPH 0xa36e #define PCI_DEVICE_ID_INTEL_ICLLP 0x34ee #define PCI_DEVICE_ID_INTEL_EHLLP 0x4b7e +#define PCI_DEVICE_ID_INTEL_TGPLP 0xa0ee #define PCI_INTEL_BXT_DSM_GUID "732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511" #define PCI_INTEL_BXT_FUNC_PMU_PWR 4 @@ -343,6 +344,9 @@ static const struct pci_device_id dwc3_pci_id_table[] = { { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_EHLLP), (kernel_ulong_t) &dwc3_pci_intel_properties, }, + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_TGPLP), + (kernel_ulong_t) &dwc3_pci_intel_properties, }, + { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_NL_USB), (kernel_ulong_t) &dwc3_pci_amd_properties, }, { } /* Terminating Entry */ -- cgit v1.2.3 From e8a8b40cc8922b38f91c6562d525f21f312f235c Mon Sep 17 00:00:00 2001 From: Pawel Laszczak Date: Tue, 2 Jul 2019 14:37:57 +0100 Subject: dt-bindings: add binding for USBSS-DRD controller. This patch aim at documenting USB related dt-bindings for the Cadence USBSS-DRD controller. Signed-off-by: Pawel Laszczak Reviewed-by: Rob Herring Signed-off-by: Felipe Balbi --- .../devicetree/bindings/usb/cdns-usb3.txt | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cdns-usb3.txt diff --git a/Documentation/devicetree/bindings/usb/cdns-usb3.txt b/Documentation/devicetree/bindings/usb/cdns-usb3.txt new file mode 100644 index 000000000000..b7dc606d37b5 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/cdns-usb3.txt @@ -0,0 +1,45 @@ +Binding for the Cadence USBSS-DRD controller + +Required properties: + - reg: Physical base address and size of the controller's register areas. + Controller has 3 different regions: + - HOST registers area + - DEVICE registers area + - OTG/DRD registers area + - reg-names - register memory area names: + "xhci" - for HOST registers space + "dev" - for DEVICE registers space + "otg" - for OTG/DRD registers space + - compatible: Should contain: "cdns,usb3" + - interrupts: Interrupts used by cdns3 controller: + "host" - interrupt used by XHCI driver. + "peripheral" - interrupt used by device driver + "otg" - interrupt used by DRD/OTG part of driver + +Optional properties: + - maximum-speed : valid arguments are "super-speed", "high-speed" and + "full-speed"; refer to usb/generic.txt + - dr_mode: Should be one of "host", "peripheral" or "otg". + - phys: reference to the USB PHY + - phy-names: from the *Generic PHY* bindings; + Supported names are: + - cdns3,usb2-phy + - cdns3,usb3-phy + + - cdns,on-chip-buff-size : size of memory intended as internal memory for endpoints + buffers expressed in KB + +Example: + usb@f3000000 { + compatible = "cdns,usb3"; + interrupts = , + , + ; + interrupt-names = "host", "peripheral", "otg"; + reg = <0xf3000000 0x10000>, /* memory area for HOST registers */ + <0xf3010000 0x10000>, /* memory area for DEVICE registers */ + <0xf3020000 0x10000>; /* memory area for OTG/DRD registers */ + reg-names = "xhci", "dev", "otg"; + phys = <&usb2_phy>, <&usb3_phy>; + phy-names = "cdns3,usb2-phy", "cnds3,usb3-phy"; + }; -- cgit v1.2.3 From 3db1b636c07e15ff7410db782832dc2e7ffd2bce Mon Sep 17 00:00:00 2001 From: Pawel Laszczak Date: Tue, 2 Jul 2019 14:37:58 +0100 Subject: usb:gadget Separated decoding functions from dwc3 driver. Patch moves some decoding functions from driver/usb/dwc3/debug.h driver to driver/usb/gadget/debug.c file. These moved functions include: dwc3_decode_get_status dwc3_decode_set_clear_feature dwc3_decode_set_address dwc3_decode_get_set_descriptor dwc3_decode_get_configuration dwc3_decode_set_configuration dwc3_decode_get_intf dwc3_decode_set_intf dwc3_decode_synch_frame dwc3_decode_set_sel dwc3_decode_set_isoch_delay dwc3_decode_ctrl These functions are used also in inroduced cdns3 driver. All functions prefixes were changed from dwc3 to usb. Also, function's parameters has been extended according to the name of fields in standard SETUP packet. Additionally, patch adds usb_decode_ctrl function to include/linux/usb/gadget.h file. Signed-off-by: Pawel Laszczak Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/debug.h | 252 ----------------------------------------- drivers/usb/dwc3/trace.h | 2 +- drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/debug.c | 268 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/gadget.h | 26 +++++ 5 files changed, 296 insertions(+), 253 deletions(-) create mode 100644 drivers/usb/gadget/debug.c diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h index 068259fdfb0c..9baabed87d61 100644 --- a/drivers/usb/dwc3/debug.h +++ b/drivers/usb/dwc3/debug.h @@ -246,258 +246,6 @@ static inline const char *dwc3_gadget_event_string(char *str, size_t size, return str; } -static inline void dwc3_decode_get_status(__u8 t, __u16 i, __u16 l, char *str, - size_t size) -{ - switch (t & USB_RECIP_MASK) { - case USB_RECIP_DEVICE: - snprintf(str, size, "Get Device Status(Length = %d)", l); - break; - case USB_RECIP_INTERFACE: - snprintf(str, size, "Get Interface Status(Intf = %d, Length = %d)", - i, l); - break; - case USB_RECIP_ENDPOINT: - snprintf(str, size, "Get Endpoint Status(ep%d%s)", - i & ~USB_DIR_IN, - i & USB_DIR_IN ? "in" : "out"); - break; - } -} - -static inline void dwc3_decode_set_clear_feature(__u8 t, __u8 b, __u16 v, - __u16 i, char *str, size_t size) -{ - switch (t & USB_RECIP_MASK) { - case USB_RECIP_DEVICE: - snprintf(str, size, "%s Device Feature(%s%s)", - b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", - ({char *s; - switch (v) { - case USB_DEVICE_SELF_POWERED: - s = "Self Powered"; - break; - case USB_DEVICE_REMOTE_WAKEUP: - s = "Remote Wakeup"; - break; - case USB_DEVICE_TEST_MODE: - s = "Test Mode"; - break; - case USB_DEVICE_U1_ENABLE: - s = "U1 Enable"; - break; - case USB_DEVICE_U2_ENABLE: - s = "U2 Enable"; - break; - case USB_DEVICE_LTM_ENABLE: - s = "LTM Enable"; - break; - default: - s = "UNKNOWN"; - } s; }), - v == USB_DEVICE_TEST_MODE ? - ({ char *s; - switch (i) { - case TEST_J: - s = ": TEST_J"; - break; - case TEST_K: - s = ": TEST_K"; - break; - case TEST_SE0_NAK: - s = ": TEST_SE0_NAK"; - break; - case TEST_PACKET: - s = ": TEST_PACKET"; - break; - case TEST_FORCE_EN: - s = ": TEST_FORCE_EN"; - break; - default: - s = ": UNKNOWN"; - } s; }) : ""); - break; - case USB_RECIP_INTERFACE: - snprintf(str, size, "%s Interface Feature(%s)", - b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", - v == USB_INTRF_FUNC_SUSPEND ? - "Function Suspend" : "UNKNOWN"); - break; - case USB_RECIP_ENDPOINT: - snprintf(str, size, "%s Endpoint Feature(%s ep%d%s)", - b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", - v == USB_ENDPOINT_HALT ? "Halt" : "UNKNOWN", - i & ~USB_DIR_IN, - i & USB_DIR_IN ? "in" : "out"); - break; - } -} - -static inline void dwc3_decode_set_address(__u16 v, char *str, size_t size) -{ - snprintf(str, size, "Set Address(Addr = %02x)", v); -} - -static inline void dwc3_decode_get_set_descriptor(__u8 t, __u8 b, __u16 v, - __u16 i, __u16 l, char *str, size_t size) -{ - snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)", - b == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", - ({ char *s; - switch (v >> 8) { - case USB_DT_DEVICE: - s = "Device"; - break; - case USB_DT_CONFIG: - s = "Configuration"; - break; - case USB_DT_STRING: - s = "String"; - break; - case USB_DT_INTERFACE: - s = "Interface"; - break; - case USB_DT_ENDPOINT: - s = "Endpoint"; - break; - case USB_DT_DEVICE_QUALIFIER: - s = "Device Qualifier"; - break; - case USB_DT_OTHER_SPEED_CONFIG: - s = "Other Speed Config"; - break; - case USB_DT_INTERFACE_POWER: - s = "Interface Power"; - break; - case USB_DT_OTG: - s = "OTG"; - break; - case USB_DT_DEBUG: - s = "Debug"; - break; - case USB_DT_INTERFACE_ASSOCIATION: - s = "Interface Association"; - break; - case USB_DT_BOS: - s = "BOS"; - break; - case USB_DT_DEVICE_CAPABILITY: - s = "Device Capability"; - break; - case USB_DT_PIPE_USAGE: - s = "Pipe Usage"; - break; - case USB_DT_SS_ENDPOINT_COMP: - s = "SS Endpoint Companion"; - break; - case USB_DT_SSP_ISOC_ENDPOINT_COMP: - s = "SSP Isochronous Endpoint Companion"; - break; - default: - s = "UNKNOWN"; - break; - } s; }), v & 0xff, l); -} - - -static inline void dwc3_decode_get_configuration(__u16 l, char *str, - size_t size) -{ - snprintf(str, size, "Get Configuration(Length = %d)", l); -} - -static inline void dwc3_decode_set_configuration(__u8 v, char *str, size_t size) -{ - snprintf(str, size, "Set Configuration(Config = %d)", v); -} - -static inline void dwc3_decode_get_intf(__u16 i, __u16 l, char *str, - size_t size) -{ - snprintf(str, size, "Get Interface(Intf = %d, Length = %d)", i, l); -} - -static inline void dwc3_decode_set_intf(__u8 v, __u16 i, char *str, size_t size) -{ - snprintf(str, size, "Set Interface(Intf = %d, Alt.Setting = %d)", i, v); -} - -static inline void dwc3_decode_synch_frame(__u16 i, __u16 l, char *str, - size_t size) -{ - snprintf(str, size, "Synch Frame(Endpoint = %d, Length = %d)", i, l); -} - -static inline void dwc3_decode_set_sel(__u16 l, char *str, size_t size) -{ - snprintf(str, size, "Set SEL(Length = %d)", l); -} - -static inline void dwc3_decode_set_isoch_delay(__u8 v, char *str, size_t size) -{ - snprintf(str, size, "Set Isochronous Delay(Delay = %d ns)", v); -} - -/** - * dwc3_decode_ctrl - returns a string represetion of ctrl request - */ -static inline const char *dwc3_decode_ctrl(char *str, size_t size, - __u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, - __u16 wLength) -{ - switch (bRequest) { - case USB_REQ_GET_STATUS: - dwc3_decode_get_status(bRequestType, wIndex, wLength, str, - size); - break; - case USB_REQ_CLEAR_FEATURE: - case USB_REQ_SET_FEATURE: - dwc3_decode_set_clear_feature(bRequestType, bRequest, wValue, - wIndex, str, size); - break; - case USB_REQ_SET_ADDRESS: - dwc3_decode_set_address(wValue, str, size); - break; - case USB_REQ_GET_DESCRIPTOR: - case USB_REQ_SET_DESCRIPTOR: - dwc3_decode_get_set_descriptor(bRequestType, bRequest, wValue, - wIndex, wLength, str, size); - break; - case USB_REQ_GET_CONFIGURATION: - dwc3_decode_get_configuration(wLength, str, size); - break; - case USB_REQ_SET_CONFIGURATION: - dwc3_decode_set_configuration(wValue, str, size); - break; - case USB_REQ_GET_INTERFACE: - dwc3_decode_get_intf(wIndex, wLength, str, size); - break; - case USB_REQ_SET_INTERFACE: - dwc3_decode_set_intf(wValue, wIndex, str, size); - break; - case USB_REQ_SYNCH_FRAME: - dwc3_decode_synch_frame(wIndex, wLength, str, size); - break; - case USB_REQ_SET_SEL: - dwc3_decode_set_sel(wLength, str, size); - break; - case USB_REQ_SET_ISOCH_DELAY: - dwc3_decode_set_isoch_delay(wValue, str, size); - break; - default: - snprintf(str, size, "%02x %02x %02x %02x %02x %02x %02x %02x", - bRequestType, bRequest, - cpu_to_le16(wValue) & 0xff, - cpu_to_le16(wValue) >> 8, - cpu_to_le16(wIndex) & 0xff, - cpu_to_le16(wIndex) >> 8, - cpu_to_le16(wLength) & 0xff, - cpu_to_le16(wLength) >> 8); - } - - return str; -} - /** * dwc3_ep_event_string - returns event name * @event: then event code diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h index 818a63da1a44..9edff17111f7 100644 --- a/drivers/usb/dwc3/trace.h +++ b/drivers/usb/dwc3/trace.h @@ -86,7 +86,7 @@ DECLARE_EVENT_CLASS(dwc3_log_ctrl, __entry->wIndex = le16_to_cpu(ctrl->wIndex); __entry->wLength = le16_to_cpu(ctrl->wLength); ), - TP_printk("%s", dwc3_decode_ctrl(__get_str(str), DWC3_MSG_MAX, + TP_printk("%s", usb_decode_ctrl(__get_str(str), DWC3_MSG_MAX, __entry->bRequestType, __entry->bRequest, __entry->wValue, __entry->wIndex, __entry->wLength) diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 130dad7130b6..500a5a592abe 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -9,5 +9,6 @@ ccflags-y += -I$(srctree)/drivers/usb/gadget/udc obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o libcomposite-y := usbstring.o config.o epautoconf.o libcomposite-y += composite.o functions.o configfs.o u_f.o +libcomposite-y += debug.o obj-$(CONFIG_USB_GADGET) += udc/ function/ legacy/ diff --git a/drivers/usb/gadget/debug.c b/drivers/usb/gadget/debug.c new file mode 100644 index 000000000000..d5a469bc67a3 --- /dev/null +++ b/drivers/usb/gadget/debug.c @@ -0,0 +1,268 @@ +// SPDX-License-Identifier: GPL-2.0 +/** + * Common USB debugging functions + * + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com + * + * Authors: Felipe Balbi , + * Sebastian Andrzej Siewior + */ + +#include + +static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, + __u16 wLength, char *str, size_t size) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + snprintf(str, size, "Get Device Status(Length = %d)", wLength); + break; + case USB_RECIP_INTERFACE: + snprintf(str, size, + "Get Interface Status(Intf = %d, Length = %d)", + wIndex, wLength); + break; + case USB_RECIP_ENDPOINT: + snprintf(str, size, "Get Endpoint Status(ep%d%s)", + wIndex & ~USB_DIR_IN, + wIndex & USB_DIR_IN ? "in" : "out"); + break; + } +} + +static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, + __u16 wValue, __u16 wIndex, + char *str, size_t size) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + snprintf(str, size, "%s Device Feature(%s%s)", + bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", + ({char *s; + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + s = "Self Powered"; + break; + case USB_DEVICE_REMOTE_WAKEUP: + s = "Remote Wakeup"; + break; + case USB_DEVICE_TEST_MODE: + s = "Test Mode"; + break; + case USB_DEVICE_U1_ENABLE: + s = "U1 Enable"; + break; + case USB_DEVICE_U2_ENABLE: + s = "U2 Enable"; + break; + case USB_DEVICE_LTM_ENABLE: + s = "LTM Enable"; + break; + default: + s = "UNKNOWN"; + } s; }), + wValue == USB_DEVICE_TEST_MODE ? + ({ char *s; + switch (wIndex) { + case TEST_J: + s = ": TEST_J"; + break; + case TEST_K: + s = ": TEST_K"; + break; + case TEST_SE0_NAK: + s = ": TEST_SE0_NAK"; + break; + case TEST_PACKET: + s = ": TEST_PACKET"; + break; + case TEST_FORCE_EN: + s = ": TEST_FORCE_EN"; + break; + default: + s = ": UNKNOWN"; + } s; }) : ""); + break; + case USB_RECIP_INTERFACE: + snprintf(str, size, "%s Interface Feature(%s)", + bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", + wValue == USB_INTRF_FUNC_SUSPEND ? + "Function Suspend" : "UNKNOWN"); + break; + case USB_RECIP_ENDPOINT: + snprintf(str, size, "%s Endpoint Feature(%s ep%d%s)", + bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", + wValue == USB_ENDPOINT_HALT ? "Halt" : "UNKNOWN", + wIndex & ~USB_DIR_IN, + wIndex & USB_DIR_IN ? "in" : "out"); + break; + } +} + +static void usb_decode_set_address(__u16 wValue, char *str, size_t size) +{ + snprintf(str, size, "Set Address(Addr = %02x)", wValue); +} + +static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, + __u16 wValue, __u16 wIndex, + __u16 wLength, char *str, size_t size) +{ + snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)", + bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", + ({ char *s; + switch (wValue >> 8) { + case USB_DT_DEVICE: + s = "Device"; + break; + case USB_DT_CONFIG: + s = "Configuration"; + break; + case USB_DT_STRING: + s = "String"; + break; + case USB_DT_INTERFACE: + s = "Interface"; + break; + case USB_DT_ENDPOINT: + s = "Endpoint"; + break; + case USB_DT_DEVICE_QUALIFIER: + s = "Device Qualifier"; + break; + case USB_DT_OTHER_SPEED_CONFIG: + s = "Other Speed Config"; + break; + case USB_DT_INTERFACE_POWER: + s = "Interface Power"; + break; + case USB_DT_OTG: + s = "OTG"; + break; + case USB_DT_DEBUG: + s = "Debug"; + break; + case USB_DT_INTERFACE_ASSOCIATION: + s = "Interface Association"; + break; + case USB_DT_BOS: + s = "BOS"; + break; + case USB_DT_DEVICE_CAPABILITY: + s = "Device Capability"; + break; + case USB_DT_PIPE_USAGE: + s = "Pipe Usage"; + break; + case USB_DT_SS_ENDPOINT_COMP: + s = "SS Endpoint Companion"; + break; + case USB_DT_SSP_ISOC_ENDPOINT_COMP: + s = "SSP Isochronous Endpoint Companion"; + break; + default: + s = "UNKNOWN"; + break; + } s; }), wValue & 0xff, wLength); +} + +static void usb_decode_get_configuration(__u16 wLength, char *str, size_t size) +{ + snprintf(str, size, "Get Configuration(Length = %d)", wLength); +} + +static void usb_decode_set_configuration(__u8 wValue, char *str, size_t size) +{ + snprintf(str, size, "Set Configuration(Config = %d)", wValue); +} + +static void usb_decode_get_intf(__u16 wIndex, __u16 wLength, char *str, + size_t size) +{ + snprintf(str, size, "Get Interface(Intf = %d, Length = %d)", + wIndex, wLength); +} + +static void usb_decode_set_intf(__u8 wValue, __u16 wIndex, char *str, + size_t size) +{ + snprintf(str, size, "Set Interface(Intf = %d, Alt.Setting = %d)", + wIndex, wValue); +} + +static void usb_decode_synch_frame(__u16 wIndex, __u16 wLength, + char *str, size_t size) +{ + snprintf(str, size, "Synch Frame(Endpoint = %d, Length = %d)", + wIndex, wLength); +} + +static void usb_decode_set_sel(__u16 wLength, char *str, size_t size) +{ + snprintf(str, size, "Set SEL(Length = %d)", wLength); +} + +static void usb_decode_set_isoch_delay(__u8 wValue, char *str, size_t size) +{ + snprintf(str, size, "Set Isochronous Delay(Delay = %d ns)", wValue); +} + +/** + * usb_decode_ctrl - returns a string representation of ctrl request + */ +const char *usb_decode_ctrl(char *str, size_t size, __u8 bRequestType, + __u8 bRequest, __u16 wValue, __u16 wIndex, + __u16 wLength) +{ + switch (bRequest) { + case USB_REQ_GET_STATUS: + usb_decode_get_status(bRequestType, wIndex, wLength, str, size); + break; + case USB_REQ_CLEAR_FEATURE: + case USB_REQ_SET_FEATURE: + usb_decode_set_clear_feature(bRequestType, bRequest, wValue, + wIndex, str, size); + break; + case USB_REQ_SET_ADDRESS: + usb_decode_set_address(wValue, str, size); + break; + case USB_REQ_GET_DESCRIPTOR: + case USB_REQ_SET_DESCRIPTOR: + usb_decode_get_set_descriptor(bRequestType, bRequest, wValue, + wIndex, wLength, str, size); + break; + case USB_REQ_GET_CONFIGURATION: + usb_decode_get_configuration(wLength, str, size); + break; + case USB_REQ_SET_CONFIGURATION: + usb_decode_set_configuration(wValue, str, size); + break; + case USB_REQ_GET_INTERFACE: + usb_decode_get_intf(wIndex, wLength, str, size); + break; + case USB_REQ_SET_INTERFACE: + usb_decode_set_intf(wValue, wIndex, str, size); + break; + case USB_REQ_SYNCH_FRAME: + usb_decode_synch_frame(wIndex, wLength, str, size); + break; + case USB_REQ_SET_SEL: + usb_decode_set_sel(wLength, str, size); + break; + case USB_REQ_SET_ISOCH_DELAY: + usb_decode_set_isoch_delay(wValue, str, size); + break; + default: + snprintf(str, size, "%02x %02x %02x %02x %02x %02x %02x %02x", + bRequestType, bRequest, + (u8)(cpu_to_le16(wValue) & 0xff), + (u8)(cpu_to_le16(wValue) >> 8), + (u8)(cpu_to_le16(wIndex) & 0xff), + (u8)(cpu_to_le16(wIndex) >> 8), + (u8)(cpu_to_le16(wLength) & 0xff), + (u8)(cpu_to_le16(wLength) >> 8)); + } + + return str; +} +EXPORT_SYMBOL_GPL(usb_decode_ctrl); diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index fb19141151d8..42902fcc8696 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -889,4 +889,30 @@ extern void usb_ep_autoconfig_release(struct usb_ep *); extern void usb_ep_autoconfig_reset(struct usb_gadget *); +/*-------------------------------------------------------------------------*/ +/** + * usb_decode_ctrl - Returns human readable representation of control request. + * @str: buffer to return a human-readable representation of control request. + * This buffer should have about 200 bytes. + * @size: size of str buffer. + * @bRequestType: matches the USB bmRequestType field + * @bRequest: matches the USB bRequest field + * @wValue: matches the USB wValue field (CPU byte order) + * @wIndex: matches the USB wIndex field (CPU byte order) + * @wLength: matches the USB wLength field (CPU byte order) + * + * Function returns decoded, formatted and human-readable description of + * control request packet. + * + * The usage scenario for this is for tracepoints, so function as a return + * use the same value as in parameters. This approach allows to use this + * function in TP_printk + * + * Important: wValue, wIndex, wLength parameters before invoking this function + * should be processed by le16_to_cpu macro. + */ +extern const char *usb_decode_ctrl(char *str, size_t size, __u8 bRequestType, + __u8 bRequest, __u16 wValue, __u16 wIndex, + __u16 wLength); + #endif /* __LINUX_USB_GADGET_H */ -- cgit v1.2.3 From ca888ce7495e4e1578c86c37b0c82f6709da477c Mon Sep 17 00:00:00 2001 From: Pawel Laszczak Date: Tue, 2 Jul 2019 14:37:59 +0100 Subject: usb:gadget Patch simplify usb_decode_set_clear_feature function. Patch adds usb_decode_test_mode and usb_decode_device_feature functions, which allow to make more readable and simplify the usb_decode_set_clear_feature function. Signed-off-by: Pawel Laszczak Signed-off-by: Felipe Balbi --- drivers/usb/gadget/debug.c | 89 ++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/drivers/usb/gadget/debug.c b/drivers/usb/gadget/debug.c index d5a469bc67a3..60a9f70a0904 100644 --- a/drivers/usb/gadget/debug.c +++ b/drivers/usb/gadget/debug.c @@ -30,58 +30,55 @@ static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, } } -static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, - __u16 wValue, __u16 wIndex, - char *str, size_t size) +static const char *usb_decode_device_feature(u16 wValue) +{ + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + return "Self Powered"; + case USB_DEVICE_REMOTE_WAKEUP: + return "Remote Wakeup"; + case USB_DEVICE_TEST_MODE: + return "Test Mode"; + case USB_DEVICE_U1_ENABLE: + return "U1 Enable"; + case USB_DEVICE_U2_ENABLE: + return "U2 Enable"; + case USB_DEVICE_LTM_ENABLE: + return "LTM Enable"; + default: + return "UNKNOWN"; + } +} + +static const char *usb_decode_test_mode(u16 wIndex) +{ + switch (wIndex) { + case TEST_J: + return ": TEST_J"; + case TEST_K: + return ": TEST_K"; + case TEST_SE0_NAK: + return ": TEST_SE0_NAK"; + case TEST_PACKET: + return ": TEST_PACKET"; + case TEST_FORCE_EN: + return ": TEST_FORCE_EN"; + default: + return ": UNKNOWN"; + } +} + +static void usb_decode_set_clear_feature(__u8 bRequestType, + __u8 bRequest, __u16 wValue, + __u16 wIndex, char *str, size_t size) { switch (bRequestType & USB_RECIP_MASK) { case USB_RECIP_DEVICE: snprintf(str, size, "%s Device Feature(%s%s)", bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", - ({char *s; - switch (wValue) { - case USB_DEVICE_SELF_POWERED: - s = "Self Powered"; - break; - case USB_DEVICE_REMOTE_WAKEUP: - s = "Remote Wakeup"; - break; - case USB_DEVICE_TEST_MODE: - s = "Test Mode"; - break; - case USB_DEVICE_U1_ENABLE: - s = "U1 Enable"; - break; - case USB_DEVICE_U2_ENABLE: - s = "U2 Enable"; - break; - case USB_DEVICE_LTM_ENABLE: - s = "LTM Enable"; - break; - default: - s = "UNKNOWN"; - } s; }), + usb_decode_device_feature(wValue), wValue == USB_DEVICE_TEST_MODE ? - ({ char *s; - switch (wIndex) { - case TEST_J: - s = ": TEST_J"; - break; - case TEST_K: - s = ": TEST_K"; - break; - case TEST_SE0_NAK: - s = ": TEST_SE0_NAK"; - break; - case TEST_PACKET: - s = ": TEST_PACKET"; - break; - case TEST_FORCE_EN: - s = ": TEST_FORCE_EN"; - break; - default: - s = ": UNKNOWN"; - } s; }) : ""); + usb_decode_test_mode(wIndex) : ""); break; case USB_RECIP_INTERFACE: snprintf(str, size, "%s Interface Feature(%s)", -- cgit v1.2.3 From c2af6b07803ebd099950cd608f404a7bff9037b2 Mon Sep 17 00:00:00 2001 From: Pawel Laszczak Date: Tue, 2 Jul 2019 14:38:00 +0100 Subject: usb:gadget Simplify usb_decode_get_set_descriptor function. Patch moves switch responsible for decoding descriptor type outside snprintf. It improves code readability a little. Signed-off-by: Pawel Laszczak Signed-off-by: Felipe Balbi --- drivers/usb/gadget/debug.c | 113 +++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 55 deletions(-) diff --git a/drivers/usb/gadget/debug.c b/drivers/usb/gadget/debug.c index 60a9f70a0904..92a986aeaa5d 100644 --- a/drivers/usb/gadget/debug.c +++ b/drivers/usb/gadget/debug.c @@ -105,62 +105,65 @@ static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength, char *str, size_t size) { + char *s; + + switch (wValue >> 8) { + case USB_DT_DEVICE: + s = "Device"; + break; + case USB_DT_CONFIG: + s = "Configuration"; + break; + case USB_DT_STRING: + s = "String"; + break; + case USB_DT_INTERFACE: + s = "Interface"; + break; + case USB_DT_ENDPOINT: + s = "Endpoint"; + break; + case USB_DT_DEVICE_QUALIFIER: + s = "Device Qualifier"; + break; + case USB_DT_OTHER_SPEED_CONFIG: + s = "Other Speed Config"; + break; + case USB_DT_INTERFACE_POWER: + s = "Interface Power"; + break; + case USB_DT_OTG: + s = "OTG"; + break; + case USB_DT_DEBUG: + s = "Debug"; + break; + case USB_DT_INTERFACE_ASSOCIATION: + s = "Interface Association"; + break; + case USB_DT_BOS: + s = "BOS"; + break; + case USB_DT_DEVICE_CAPABILITY: + s = "Device Capability"; + break; + case USB_DT_PIPE_USAGE: + s = "Pipe Usage"; + break; + case USB_DT_SS_ENDPOINT_COMP: + s = "SS Endpoint Companion"; + break; + case USB_DT_SSP_ISOC_ENDPOINT_COMP: + s = "SSP Isochronous Endpoint Companion"; + break; + default: + s = "UNKNOWN"; + break; + } + snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)", - bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", - ({ char *s; - switch (wValue >> 8) { - case USB_DT_DEVICE: - s = "Device"; - break; - case USB_DT_CONFIG: - s = "Configuration"; - break; - case USB_DT_STRING: - s = "String"; - break; - case USB_DT_INTERFACE: - s = "Interface"; - break; - case USB_DT_ENDPOINT: - s = "Endpoint"; - break; - case USB_DT_DEVICE_QUALIFIER: - s = "Device Qualifier"; - break; - case USB_DT_OTHER_SPEED_CONFIG: - s = "Other Speed Config"; - break; - case USB_DT_INTERFACE_POWER: - s = "Interface Power"; - break; - case USB_DT_OTG: - s = "OTG"; - break; - case USB_DT_DEBUG: - s = "Debug"; - break; - case USB_DT_INTERFACE_ASSOCIATION: - s = "Interface Association"; - break; - case USB_DT_BOS: - s = "BOS"; - break; - case USB_DT_DEVICE_CAPABILITY: - s = "Device Capability"; - break; - case USB_DT_PIPE_USAGE: - s = "Pipe Usage"; - break; - case USB_DT_SS_ENDPOINT_COMP: - s = "SS Endpoint Companion"; - break; - case USB_DT_SSP_ISOC_ENDPOINT_COMP: - s = "SSP Isochronous Endpoint Companion"; - break; - default: - s = "UNKNOWN"; - break; - } s; }), wValue & 0xff, wLength); + bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", + s, wValue & 0xff, wLength); } static void usb_decode_get_configuration(__u16 wLength, char *str, size_t size) -- cgit v1.2.3 From 8bc1901ca7b07d864fca11461b3875b31f949765 Mon Sep 17 00:00:00 2001 From: Pawel Laszczak Date: Tue, 2 Jul 2019 14:38:01 +0100 Subject: usb:cdns3 Add Cadence USB3 DRD Driver This patch introduce new Cadence USBSS DRD driver to Linux kernel. The Cadence USBSS DRD Controller is a highly configurable IP Core which can be instantiated as Dual-Role Device (DRD), Peripheral Only and Host Only (XHCI)configurations. The current driver has been validated with FPGA platform. We have support for PCIe bus, which is used on FPGA prototyping. The host side of USBSS-DRD controller is compliant with XHCI specification, so it works with standard XHCI Linux driver. Signed-off-by: Pawel Laszczak Signed-off-by: Felipe Balbi --- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/cdns3/Kconfig | 44 + drivers/usb/cdns3/Makefile | 14 + drivers/usb/cdns3/cdns3-pci-wrap.c | 157 +++ drivers/usb/cdns3/core.c | 543 +++++++++ drivers/usb/cdns3/core.h | 121 ++ drivers/usb/cdns3/debug.h | 173 +++ drivers/usb/cdns3/debugfs.c | 153 +++ drivers/usb/cdns3/drd.c | 379 ++++++ drivers/usb/cdns3/drd.h | 166 +++ drivers/usb/cdns3/ep0.c | 920 ++++++++++++++ drivers/usb/cdns3/gadget-export.h | 28 + drivers/usb/cdns3/gadget.c | 2319 ++++++++++++++++++++++++++++++++++++ drivers/usb/cdns3/gadget.h | 1321 ++++++++++++++++++++ drivers/usb/cdns3/host-export.h | 28 + drivers/usb/cdns3/host.c | 76 ++ drivers/usb/cdns3/trace.c | 23 + drivers/usb/cdns3/trace.h | 447 +++++++ 19 files changed, 6916 insertions(+) create mode 100644 drivers/usb/cdns3/Kconfig create mode 100644 drivers/usb/cdns3/Makefile create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c create mode 100644 drivers/usb/cdns3/core.c create mode 100644 drivers/usb/cdns3/core.h create mode 100644 drivers/usb/cdns3/debug.h create mode 100644 drivers/usb/cdns3/debugfs.c create mode 100644 drivers/usb/cdns3/drd.c create mode 100644 drivers/usb/cdns3/drd.h create mode 100644 drivers/usb/cdns3/ep0.c create mode 100644 drivers/usb/cdns3/gadget-export.h create mode 100644 drivers/usb/cdns3/gadget.c create mode 100644 drivers/usb/cdns3/gadget.h create mode 100644 drivers/usb/cdns3/host-export.h create mode 100644 drivers/usb/cdns3/host.c create mode 100644 drivers/usb/cdns3/trace.c create mode 100644 drivers/usb/cdns3/trace.h diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index e4b27413f528..c2e78882f8c2 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -113,6 +113,8 @@ source "drivers/usb/usbip/Kconfig" endif +source "drivers/usb/cdns3/Kconfig" + source "drivers/usb/mtu3/Kconfig" source "drivers/usb/musb/Kconfig" diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index ecc2de1ffaae..09fc9f2448ce 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile @@ -13,6 +13,8 @@ obj-$(CONFIG_USB_DWC3) += dwc3/ obj-$(CONFIG_USB_DWC2) += dwc2/ obj-$(CONFIG_USB_ISP1760) += isp1760/ +obj-$(CONFIG_USB_CDNS3) += cdns3/ + obj-$(CONFIG_USB_MON) += mon/ obj-$(CONFIG_USB_MTU3) += mtu3/ diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig new file mode 100644 index 000000000000..118ec91c4c70 --- /dev/null +++ b/drivers/usb/cdns3/Kconfig @@ -0,0 +1,44 @@ +config USB_CDNS3 + tristate "Cadence USB3 Dual-Role Controller" + depends on USB_SUPPORT && (USB || USB_GADGET) && HAS_DMA + help + Say Y here if your system has a Cadence USB3 dual-role controller. + It supports: dual-role switch, Host-only, and Peripheral-only. + + If you choose to build this driver is a dynamically linked + as module, the module will be called cdns3.ko. + +if USB_CDNS3 + +config USB_CDNS3_GADGET + bool "Cadence USB3 device controller" + depends on USB_GADGET + help + Say Y here to enable device controller functionality of the + Cadence USBSS-DEV driver. + + This controller supports FF, HS and SS mode. It doesn't support + LS and SSP mode. + +config USB_CDNS3_HOST + bool "Cadence USB3 host controller" + depends on USB_XHCI_HCD + help + Say Y here to enable host controller functionality of the + Cadence driver. + + Host controller is compliant with XHCI so it will use + standard XHCI driver. + +config USB_CDNS3_PCI_WRAP + tristate "Cadence USB3 support on PCIe-based platforms" + depends on USB_PCI && ACPI + default USB_CDNS3 + help + If you're using the USBSS Core IP with a PCIe, please say + 'Y' or 'M' here. + + If you choose to build this driver as module it will + be dynamically linked and module will be called cdns3-pci.ko + +endif diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile new file mode 100644 index 000000000000..46c27b94b94b --- /dev/null +++ b/drivers/usb/cdns3/Makefile @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0 +# define_trace.h needs to know how to find our header +CFLAGS_trace.o := -I$(src) + +cdns3-y := core.o drd.o + +obj-$(CONFIG_USB_CDNS3) += cdns3.o +ifneq ($(CONFIG_DEBUG_FS),) + cdns3-y += debugfs.o +endif + +cdns3-$(CONFIG_USB_CDNS3_GADGET) += gadget.o ep0.o trace.o +cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o +obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci-wrap.o diff --git a/drivers/usb/cdns3/cdns3-pci-wrap.c b/drivers/usb/cdns3/cdns3-pci-wrap.c new file mode 100644 index 000000000000..65b61ea246b1 --- /dev/null +++ b/drivers/usb/cdns3/cdns3-pci-wrap.c @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS PCI Glue driver + * + * Copyright (C) 2018-2019 Cadence. + * + * Author: Pawel Laszczak + */ + +#include +#include +#include +#include +#include +#include + +struct cdns3_wrap { + struct platform_device *plat_dev; + struct pci_dev *hg_dev; + struct resource dev_res[6]; +}; + +#define RES_IRQ_HOST_ID 0 +#define RES_IRQ_PERIPHERAL_ID 1 +#define RES_IRQ_OTG_ID 2 +#define RES_HOST_ID 3 +#define RES_DEV_ID 4 +#define RES_DRD_ID 5 + +#define PCI_BAR_HOST 0 +#define PCI_BAR_DEV 2 +#define PCI_BAR_OTG 4 + +#define PCI_DEV_FN_HOST_DEVICE 0 +#define PCI_DEV_FN_OTG 1 + +#define PCI_DRIVER_NAME "cdns3-pci-usbss" +#define PLAT_DRIVER_NAME "cdns-usb3" + +#define CDNS_VENDOR_ID 0x17cd +#define CDNS_DEVICE_ID 0x0100 + +static int cdns3_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *id) +{ + struct platform_device_info plat_info; + struct cdns3_wrap *wrap; + struct resource *res; + int err; + + /* + * for GADGET/HOST PCI (devfn) function number is 0, + * for OTG PCI (devfn) function number is 1 + */ + if (!id || pdev->devfn != PCI_DEV_FN_HOST_DEVICE) + return -EINVAL; + + err = pcim_enable_device(pdev); + if (err) { + dev_err(&pdev->dev, "Enabling PCI device has failed %d\n", err); + return err; + } + + pci_set_master(pdev); + wrap = devm_kzalloc(&pdev->dev, sizeof(*wrap), GFP_KERNEL); + if (!wrap) { + pci_disable_device(pdev); + return -ENOMEM; + } + + /* function 0: host(BAR_0) + device(BAR_1) + otg(BAR_2)). */ + dev_dbg(&pdev->dev, "Initialize Device resources\n"); + res = wrap->dev_res; + + res[RES_DEV_ID].start = pci_resource_start(pdev, PCI_BAR_DEV); + res[RES_DEV_ID].end = pci_resource_end(pdev, PCI_BAR_DEV); + res[RES_DEV_ID].name = "dev"; + res[RES_DEV_ID].flags = IORESOURCE_MEM; + dev_dbg(&pdev->dev, "USBSS-DEV physical base addr: %pa\n", + &res[RES_DEV_ID].start); + + res[RES_HOST_ID].start = pci_resource_start(pdev, PCI_BAR_HOST); + res[RES_HOST_ID].end = pci_resource_end(pdev, PCI_BAR_HOST); + res[RES_HOST_ID].name = "xhci"; + res[RES_HOST_ID].flags = IORESOURCE_MEM; + dev_dbg(&pdev->dev, "USBSS-XHCI physical base addr: %pa\n", + &res[RES_HOST_ID].start); + + res[RES_DRD_ID].start = pci_resource_start(pdev, PCI_BAR_OTG); + res[RES_DRD_ID].end = pci_resource_end(pdev, PCI_BAR_OTG); + res[RES_DRD_ID].name = "otg"; + res[RES_DRD_ID].flags = IORESOURCE_MEM; + dev_dbg(&pdev->dev, "USBSS-DRD physical base addr: %pa\n", + &res[RES_DRD_ID].start); + + /* Interrupt for XHCI */ + wrap->dev_res[RES_IRQ_HOST_ID].start = pdev->irq; + wrap->dev_res[RES_IRQ_HOST_ID].name = "host"; + wrap->dev_res[RES_IRQ_HOST_ID].flags = IORESOURCE_IRQ; + + /* Interrupt device. It's the same as for HOST. */ + wrap->dev_res[RES_IRQ_PERIPHERAL_ID].start = pdev->irq; + wrap->dev_res[RES_IRQ_PERIPHERAL_ID].name = "peripheral"; + wrap->dev_res[RES_IRQ_PERIPHERAL_ID].flags = IORESOURCE_IRQ; + + /* Interrupt for OTG/DRD. */ + wrap->dev_res[RES_IRQ_OTG_ID].start = pdev->irq; + wrap->dev_res[RES_IRQ_OTG_ID].name = "otg"; + wrap->dev_res[RES_IRQ_OTG_ID].flags = IORESOURCE_IRQ; + + /* set up platform device info */ + memset(&plat_info, 0, sizeof(plat_info)); + plat_info.parent = &pdev->dev; + plat_info.fwnode = pdev->dev.fwnode; + plat_info.name = PLAT_DRIVER_NAME; + plat_info.id = pdev->devfn; + plat_info.res = wrap->dev_res; + plat_info.num_res = ARRAY_SIZE(wrap->dev_res); + plat_info.dma_mask = pdev->dma_mask; + + /* register platform device */ + wrap->plat_dev = platform_device_register_full(&plat_info); + if (IS_ERR(wrap->plat_dev)) { + pci_disable_device(pdev); + return PTR_ERR(wrap->plat_dev); + } + + pci_set_drvdata(pdev, wrap); + + return err; +} + +static void cdns3_pci_remove(struct pci_dev *pdev) +{ + struct cdns3_wrap *wrap = (struct cdns3_wrap *)pci_get_drvdata(pdev); + + platform_device_unregister(wrap->plat_dev); +} + +static const struct pci_device_id cdns3_pci_ids[] = { + { PCI_DEVICE(CDNS_VENDOR_ID, CDNS_DEVICE_ID), }, + { 0, } +}; + +static struct pci_driver cdns3_pci_driver = { + .name = PCI_DRIVER_NAME, + .id_table = cdns3_pci_ids, + .probe = cdns3_pci_probe, + .remove = cdns3_pci_remove, +}; + +module_pci_driver(cdns3_pci_driver); +MODULE_DEVICE_TABLE(pci, cdns3_pci_ids); + +MODULE_AUTHOR("Pawel Laszczak "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Cadence USBSS PCI wrapperr"); diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c new file mode 100644 index 000000000000..ddc73f1c87c5 --- /dev/null +++ b/drivers/usb/cdns3/core.c @@ -0,0 +1,543 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Driver. + * + * Copyright (C) 2018-2019 Cadence. + * Copyright (C) 2017-2018 NXP + * Copyright (C) 2019 Texas Instruments + * + * Author: Peter Chen + * Pawel Laszczak + * Roger Quadros + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "gadget.h" +#include "core.h" +#include "host-export.h" +#include "gadget-export.h" +#include "drd.h" +#include "debug.h" + +/** + * cdns3_handshake - spin reading until handshake completes or fails + * @ptr: address of device controller register to be read + * @mask: bits to look at in result of read + * @done: value of those bits when handshake succeeds + * @usec: timeout in microseconds + * + * Returns negative errno, or zero on success + * + * Success happens when the "mask" bits have the specified value (hardware + * handshake done). There are two failure modes: "usec" have passed (major + * hardware flakeout), or the register reads as all-ones (hardware removed). + */ +int cdns3_handshake(void __iomem *ptr, u32 mask, u32 done, int usec) +{ + u32 result; + + do { + result = readl(ptr); + if (result == ~(u32)0) /* card removed */ + return -ENODEV; + + result &= mask; + if (result == done) + return 0; + + udelay(1); + usec--; + } while (usec > 0); + + return -ETIMEDOUT; +} + +static inline +struct cdns3_role_driver *cdns3_get_current_role_driver(struct cdns3 *cdns) +{ + WARN_ON(cdns->role >= CDNS3_ROLE_END || !cdns->roles[cdns->role]); + return cdns->roles[cdns->role]; +} + +static int cdns3_role_start(struct cdns3 *cdns, enum cdns3_roles role) +{ + int ret; + + if (WARN_ON(role >= CDNS3_ROLE_END)) + return 0; + + if (!cdns->roles[role]) + return -ENXIO; + + if (cdns->roles[role]->state == CDNS3_ROLE_STATE_ACTIVE) + return 0; + + mutex_lock(&cdns->mutex); + cdns->role = role; + ret = cdns->roles[role]->start(cdns); + if (!ret) + cdns->roles[role]->state = CDNS3_ROLE_STATE_ACTIVE; + mutex_unlock(&cdns->mutex); + return ret; +} + +void cdns3_role_stop(struct cdns3 *cdns) +{ + enum cdns3_roles role = cdns->role; + + if (role >= CDNS3_ROLE_END) { + WARN_ON(role > CDNS3_ROLE_END); + return; + } + + if (cdns->roles[role]->state == CDNS3_ROLE_STATE_INACTIVE) + return; + + mutex_lock(&cdns->mutex); + cdns->roles[role]->stop(cdns); + cdns->roles[role]->state = CDNS3_ROLE_STATE_INACTIVE; + mutex_unlock(&cdns->mutex); +} + +static void cdns3_exit_roles(struct cdns3 *cdns) +{ + cdns3_role_stop(cdns); + cdns3_drd_exit(cdns); +} + +enum cdns3_roles cdsn3_get_real_role(struct cdns3 *cdns); + +static int cdns3_idle_role_start(struct cdns3 *cnds) +{ /* Hold PHY in RESET */ + return 0; +} + +static void cdns3_idle_role_stop(struct cdns3 *cnds) +{ + /* Program Lane swap and bring PHY out of RESET */ +} + +static int cdns3_idle_init(struct cdns3 *cdns) +{ + struct cdns3_role_driver *rdrv; + + rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); + if (!rdrv) + return -ENOMEM; + + rdrv->start = cdns3_idle_role_start; + rdrv->stop = cdns3_idle_role_stop; + rdrv->state = CDNS3_ROLE_STATE_INACTIVE; + rdrv->suspend = NULL; + rdrv->resume = NULL; + rdrv->name = "idle"; + + cdns->roles[CDNS3_ROLE_IDLE] = rdrv; + + return 0; +} + +/** + * cdns3_core_init_role - initialize role of operation + * @cdns: Pointer to cdns3 structure + * + * Returns 0 on success otherwise negative errno + */ +static int cdns3_core_init_role(struct cdns3 *cdns) +{ + struct device *dev = cdns->dev; + enum usb_dr_mode best_dr_mode; + enum usb_dr_mode dr_mode; + int ret = 0; + + dr_mode = usb_get_dr_mode(dev); + cdns->role = CDNS3_ROLE_END; + + /* + * If driver can't read mode by means of usb_get_dr_mode function then + * chooses mode according with Kernel configuration. This setting + * can be restricted later depending on strap pin configuration. + */ + if (dr_mode == USB_DR_MODE_UNKNOWN) { + if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) && + IS_ENABLED(CONFIG_USB_CDNS3_GADGET)) + dr_mode = USB_DR_MODE_OTG; + else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST)) + dr_mode = USB_DR_MODE_HOST; + else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET)) + dr_mode = USB_DR_MODE_PERIPHERAL; + } + + /* + * At this point cdns->dr_mode contains strap configuration. + * Driver try update this setting considering kernel configuration + */ + best_dr_mode = cdns->dr_mode; + + ret = cdns3_idle_init(cdns); + if (ret) + return ret; + + if (dr_mode == USB_DR_MODE_OTG) { + best_dr_mode = cdns->dr_mode; + } else if (cdns->dr_mode == USB_DR_MODE_OTG) { + best_dr_mode = dr_mode; + } else if (cdns->dr_mode != dr_mode) { + dev_err(dev, "Incorrect DRD configuration\n"); + return -EINVAL; + } + + dr_mode = best_dr_mode; + + if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { + ret = cdns3_host_init(cdns); + if (ret) { + dev_err(dev, "Host initialization failed with %d\n", + ret); + goto err; + } + } + + if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) { + ret = cdns3_gadget_init(cdns); + if (ret) { + dev_err(dev, "Device initialization failed with %d\n", + ret); + goto err; + } + } + + cdns->desired_dr_mode = dr_mode; + cdns->dr_mode = dr_mode; + + /* + * desired_dr_mode might have changed so we need to update + * the controller configuration"? + */ + ret = cdns3_drd_update_mode(cdns); + if (ret) + goto err; + + cdns->role = cdsn3_get_real_role(cdns); + + ret = cdns3_role_start(cdns, cdns->role); + if (ret) { + dev_err(dev, "can't start %s role\n", + cdns3_get_current_role_driver(cdns)->name); + goto err; + } + + return ret; +err: + cdns3_exit_roles(cdns); + return ret; +} + +/** + * cdsn3_get_real_role - get real role of controller based on hardware settings. + * @cdns: Pointer to cdns3 structure + * + * Returns role + */ +enum cdns3_roles cdsn3_get_real_role(struct cdns3 *cdns) +{ + enum cdns3_roles role; + int id, vbus; + + if (cdns->current_dr_mode != USB_DR_MODE_OTG) + goto not_otg; + + id = cdns3_get_id(cdns); + vbus = cdns3_get_vbus(cdns); + + /* + * Role change state machine + * Inputs: ID, VBUS + * Previous state: cdns->role + * Next state: role + */ + role = cdns->role; + + switch (role) { + case CDNS3_ROLE_IDLE: /* from IDLE, we can change to HOST or GADGET */ + if (!id) + role = CDNS3_ROLE_HOST; + else if (vbus) + role = CDNS3_ROLE_GADGET; + break; + case CDNS3_ROLE_HOST: /* from HOST, we can only change to IDLE */ + if (id) + role = CDNS3_ROLE_IDLE; + break; + case CDNS3_ROLE_GADGET: /* from GADGET, we can only change to IDLE */ + if (!vbus) + role = CDNS3_ROLE_IDLE; + break; + case CDNS3_ROLE_END: /* only at initialization, move to IDLE */ + role = CDNS3_ROLE_IDLE; + break; + } + + dev_dbg(cdns->dev, "role %d -> %d\n", cdns->role, role); + + return role; + +not_otg: + if (cdns3_is_host(cdns)) + role = CDNS3_ROLE_HOST; + if (cdns3_is_device(cdns)) + role = CDNS3_ROLE_GADGET; + + return role; +} + +/** + * cdns3_role_switch - work queue handler for role switch + * + * @work: work queue item structure + * + * Handles below events: + * - Role switch for dual-role devices + * - CDNS3_ROLE_GADGET <--> CDNS3_ROLE_END for peripheral-only devices + */ +static void cdns3_role_switch(struct work_struct *work) +{ + enum cdns3_roles role = CDNS3_ROLE_END; + struct cdns3_role_driver *role_drv; + enum cdns3_roles current_role; + struct cdns3 *cdns; + int ret = 0; + + cdns = container_of(work, struct cdns3, role_switch_wq); + + pm_runtime_get_sync(cdns->dev); + + role = cdsn3_get_real_role(cdns); + + role_drv = cdns3_get_current_role_driver(cdns); + + /* Disable current role if requested from debugfs */ + if (cdns->debug_disable && role_drv->state == CDNS3_ROLE_STATE_ACTIVE) { + cdns3_role_stop(cdns); + goto exit; + } + + /* Do nothing if nothing changed */ + if (cdns->role == role && role_drv->state == CDNS3_ROLE_STATE_ACTIVE) + goto exit; + + cdns3_role_stop(cdns); + + role = cdsn3_get_real_role(cdns); + + current_role = cdns->role; + dev_dbg(cdns->dev, "Switching role"); + + ret = cdns3_role_start(cdns, role); + if (ret) { + /* Back to current role */ + dev_err(cdns->dev, "set %d has failed, back to %d\n", + role, current_role); + ret = cdns3_role_start(cdns, current_role); + if (ret) + dev_err(cdns->dev, "back to %d failed too\n", + current_role); + } +exit: + pm_runtime_put_sync(cdns->dev); +} + +/** + * cdns3_probe - probe for cdns3 core device + * @pdev: Pointer to cdns3 core platform device + * + * Returns 0 on success otherwise negative errno + */ +static int cdns3_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct resource *res; + struct cdns3 *cdns; + void __iomem *regs; + int ret; + + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); + if (ret) { + dev_err(dev, "error setting dma mask: %d\n", ret); + return -ENODEV; + } + + cdns = devm_kzalloc(dev, sizeof(*cdns), GFP_KERNEL); + if (!cdns) + return -ENOMEM; + + cdns->dev = dev; + + platform_set_drvdata(pdev, cdns); + + res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "host"); + if (!res) { + dev_err(dev, "missing host IRQ\n"); + return -ENODEV; + } + + cdns->xhci_res[0] = *res; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "xhci"); + if (!res) { + dev_err(dev, "couldn't get xhci resource\n"); + return -ENXIO; + } + + cdns->xhci_res[1] = *res; + + cdns->dev_irq = platform_get_irq_byname(pdev, "peripheral"); + if (cdns->dev_irq == -EPROBE_DEFER) + return cdns->dev_irq; + + if (cdns->dev_irq < 0) + dev_err(dev, "couldn't get peripheral irq\n"); + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dev"); + regs = devm_ioremap_resource(dev, res); + if (IS_ERR(regs)) { + dev_err(dev, "couldn't iomap dev resource\n"); + return PTR_ERR(regs); + } + cdns->dev_regs = regs; + + cdns->otg_irq = platform_get_irq_byname(pdev, "otg"); + if (cdns->otg_irq == -EPROBE_DEFER) + return cdns->otg_irq; + + if (cdns->otg_irq < 0) { + dev_err(dev, "couldn't get otg irq\n"); + return cdns->otg_irq; + } + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otg"); + if (!res) { + dev_err(dev, "couldn't get otg resource\n"); + return -ENXIO; + } + + cdns->otg_res = *res; + + mutex_init(&cdns->mutex); + + cdns->usb2_phy = devm_phy_optional_get(dev, "cdns3,usb2-phy"); + if (IS_ERR(cdns->usb2_phy)) + return PTR_ERR(cdns->usb2_phy); + + phy_init(cdns->usb2_phy); + ret = phy_init(cdns->usb2_phy); + if (ret) + return ret; + + cdns->usb3_phy = devm_phy_optional_get(dev, "cdns3,usb3-phy"); + if (IS_ERR(cdns->usb3_phy)) + return PTR_ERR(cdns->usb3_phy); + + phy_init(cdns->usb3_phy); + ret = phy_init(cdns->usb3_phy); + if (ret) + return ret; + + ret = phy_power_on(cdns->usb2_phy); + if (ret) + return ret; + + ret = phy_power_on(cdns->usb3_phy); + if (ret) + goto err1; + + INIT_WORK(&cdns->role_switch_wq, cdns3_role_switch); + + ret = cdns3_drd_init(cdns); + if (ret) + goto err2; + + ret = cdns3_core_init_role(cdns); + if (ret) + goto err2; + + cdns3_debugfs_init(cdns); + device_set_wakeup_capable(dev, true); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + + /* + * The controller needs less time between bus and controller suspend, + * and we also needs a small delay to avoid frequently entering low + * power mode. + */ + pm_runtime_set_autosuspend_delay(dev, 20); + pm_runtime_mark_last_busy(dev); + pm_runtime_use_autosuspend(dev); + dev_dbg(dev, "Cadence USB3 core: probe succeed\n"); + + return 0; + +err2: + phy_power_off(cdns->usb3_phy); + +err1: + phy_power_off(cdns->usb2_phy); + phy_exit(cdns->usb2_phy); + phy_exit(cdns->usb3_phy); + + return ret; +} + +/** + * cdns3_remove - unbind drd driver and clean up + * @pdev: Pointer to Linux platform device + * + * Returns 0 on success otherwise negative errno + */ +static int cdns3_remove(struct platform_device *pdev) +{ + struct cdns3 *cdns = platform_get_drvdata(pdev); + + pm_runtime_get_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); + cdns3_debugfs_exit(cdns); + cdns3_exit_roles(cdns); + phy_power_off(cdns->usb2_phy); + phy_power_off(cdns->usb3_phy); + phy_exit(cdns->usb2_phy); + phy_exit(cdns->usb3_phy); + return 0; +} + +#ifdef CONFIG_OF +static const struct of_device_id of_cdns3_match[] = { + { .compatible = "cdns,usb3" }, + { }, +}; +MODULE_DEVICE_TABLE(of, of_cdns3_match); +#endif + +static struct platform_driver cdns3_driver = { + .probe = cdns3_probe, + .remove = cdns3_remove, + .driver = { + .name = "cdns-usb3", + .of_match_table = of_match_ptr(of_cdns3_match), + }, +}; + +module_platform_driver(cdns3_driver); + +MODULE_ALIAS("platform:cdns3"); +MODULE_AUTHOR("Pawel Laszczak "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Cadence USB3 DRD Controller Driver"); diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h new file mode 100644 index 000000000000..be95696ab17e --- /dev/null +++ b/drivers/usb/cdns3/core.h @@ -0,0 +1,121 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Cadence USBSS DRD Header File. + * + * Copyright (C) 2017-2018 NXP + * Copyright (C) 2018-2019 Cadence. + * + * Authors: Peter Chen + * Pawel Laszczak + */ +#include + +#ifndef __LINUX_CDNS3_CORE_H +#define __LINUX_CDNS3_CORE_H + +struct cdns3; +enum cdns3_roles { + CDNS3_ROLE_IDLE = 0, + CDNS3_ROLE_HOST, + CDNS3_ROLE_GADGET, + CDNS3_ROLE_END, +}; + +/** + * struct cdns3_role_driver - host/gadget role driver + * @start: start this role + * @stop: stop this role + * @suspend: suspend callback for this role + * @resume: resume callback for this role + * @irq: irq handler for this role + * @name: role name string (host/gadget) + * @state: current state + */ +struct cdns3_role_driver { + int (*start)(struct cdns3 *cdns); + void (*stop)(struct cdns3 *cdns); + int (*suspend)(struct cdns3 *cdns, bool do_wakeup); + int (*resume)(struct cdns3 *cdns, bool hibernated); + const char *name; +#define CDNS3_ROLE_STATE_INACTIVE 0 +#define CDNS3_ROLE_STATE_ACTIVE 1 + int state; +}; + +#define CDNS3_XHCI_RESOURCES_NUM 2 +/** + * struct cdns3 - Representation of Cadence USB3 DRD controller. + * @dev: pointer to Cadence device struct + * @xhci_regs: pointer to base of xhci registers + * @xhci_res: the resource for xhci + * @dev_regs: pointer to base of dev registers + * @otg_res: the resource for otg + * @otg_v0_regs: pointer to base of v0 otg registers + * @otg_v1_regs: pointer to base of v1 otg registers + * @otg_regs: pointer to base of otg registers + * @otg_irq: irq number for otg controller + * @dev_irq: irq number for device controller + * @roles: array of supported roles for this controller + * @role: current role + * @host_dev: the child host device pointer for cdns3 core + * @gadget_dev: the child gadget device pointer for cdns3 core + * @usb2_phy: pointer to USB2 PHY + * @usb3_phy: pointer to USB3 PHY + * @role_switch_wq: work queue item for role switch + * @wakeup_int: the wakeup interrupt + * @mutex: the mutex for concurrent code at driver + * @dr_mode: supported mode of operation it can be only Host, only Device + * or OTG mode that allow to switch between Device and Host mode. + * This field based on firmware setting, kernel configuration + * and hardware configuration. + * @current_dr_mode: current mode of operation when in dual-role mode + * @desired_dr_mode: desired mode of operation when in dual-role mode. + * This value can be changed during runtime. + * Available options depends on dr_mode: + * dr_mode | desired_dr_mode and current_dr_mode + * ---------------------------------------------------------------- + * USB_DR_MODE_HOST | only USB_DR_MODE_HOST + * USB_DR_MODE_PERIPHERAL | only USB_DR_MODE_PERIPHERAL + * USB_DR_MODE_OTG | USB_DR_MODE_OTG or USB_DR_MODE_HOST or + * | USB_DR_MODE_PERIPHERAL + * Desired_dr_role can be changed by means of debugfs. + * @root: debugfs root folder pointer + * @debug_disable: + */ +struct cdns3 { + struct device *dev; + void __iomem *xhci_regs; + struct resource xhci_res[CDNS3_XHCI_RESOURCES_NUM]; + struct cdns3_usb_regs __iomem *dev_regs; + + struct resource otg_res; + struct cdns3_otg_legacy_regs *otg_v0_regs; + struct cdns3_otg_regs *otg_v1_regs; + struct cdns3_otg_common_regs *otg_regs; +#define CDNS3_CONTROLLER_V0 0 +#define CDNS3_CONTROLLER_V1 1 + u32 version; + + int otg_irq; + int dev_irq; + struct cdns3_role_driver *roles[CDNS3_ROLE_END]; + enum cdns3_roles role; + struct platform_device *host_dev; + struct cdns3_device *gadget_dev; + struct phy *usb2_phy; + struct phy *usb3_phy; + struct work_struct role_switch_wq; + int wakeup_int:1; + /* mutext used in workqueue*/ + struct mutex mutex; + enum usb_dr_mode dr_mode; + enum usb_dr_mode current_dr_mode; + enum usb_dr_mode desired_dr_mode; + struct dentry *root; + int debug_disable:1; +}; + +void cdns3_role_stop(struct cdns3 *cdns); +int cdns3_handshake(void __iomem *ptr, u32 mask, u32 done, int usec); + +#endif /* __LINUX_CDNS3_CORE_H */ diff --git a/drivers/usb/cdns3/debug.h b/drivers/usb/cdns3/debug.h new file mode 100644 index 000000000000..65c3d8a6cd62 --- /dev/null +++ b/drivers/usb/cdns3/debug.h @@ -0,0 +1,173 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Cadence USBSS DRD Driver. + * Debug header file. + * + * Copyright (C) 2018-2019 Cadence. + * + * Author: Pawel Laszczak + */ +#ifndef __LINUX_CDNS3_DEBUG +#define __LINUX_CDNS3_DEBUG + +#include "core.h" + +static inline char *cdns3_decode_usb_irq(char *str, + enum usb_device_speed speed, + u32 usb_ists) +{ + int ret; + + ret = sprintf(str, "IRQ %08x = ", usb_ists); + + if (usb_ists & (USB_ISTS_CON2I | USB_ISTS_CONI)) { + ret += sprintf(str + ret, "Connection %s\n", + usb_speed_string(speed)); + } + if (usb_ists & USB_ISTS_DIS2I || usb_ists & USB_ISTS_DISI) + ret += sprintf(str + ret, "Disconnection "); + if (usb_ists & USB_ISTS_L2ENTI) + ret += sprintf(str + ret, "suspended "); + if (usb_ists & USB_ISTS_L1ENTI) + ret += sprintf(str + ret, "L1 enter "); + if (usb_ists & USB_ISTS_L1EXTI) + ret += sprintf(str + ret, "L1 exit "); + if (usb_ists & USB_ISTS_L2ENTI) + ret += sprintf(str + ret, "L2 enter "); + if (usb_ists & USB_ISTS_L2EXTI) + ret += sprintf(str + ret, "L2 exit "); + if (usb_ists & USB_ISTS_U3EXTI) + ret += sprintf(str + ret, "U3 exit "); + if (usb_ists & USB_ISTS_UWRESI) + ret += sprintf(str + ret, "Warm Reset "); + if (usb_ists & USB_ISTS_UHRESI) + ret += sprintf(str + ret, "Hot Reset "); + if (usb_ists & USB_ISTS_U2RESI) + ret += sprintf(str + ret, "Reset"); + + return str; +} + +static inline char *cdns3_decode_ep_irq(char *str, + u32 ep_sts, + const char *ep_name) +{ + int ret; + + ret = sprintf(str, "IRQ for %s: %08x ", ep_name, ep_sts); + + if (ep_sts & EP_STS_SETUP) + ret += sprintf(str + ret, "SETUP "); + if (ep_sts & EP_STS_IOC) + ret += sprintf(str + ret, "IOC "); + if (ep_sts & EP_STS_ISP) + ret += sprintf(str + ret, "ISP "); + if (ep_sts & EP_STS_DESCMIS) + ret += sprintf(str + ret, "DESCMIS "); + if (ep_sts & EP_STS_STREAMR) + ret += sprintf(str + ret, "STREAMR "); + if (ep_sts & EP_STS_MD_EXIT) + ret += sprintf(str + ret, "MD_EXIT "); + if (ep_sts & EP_STS_TRBERR) + ret += sprintf(str + ret, "TRBERR "); + if (ep_sts & EP_STS_NRDY) + ret += sprintf(str + ret, "NRDY "); + if (ep_sts & EP_STS_PRIME) + ret += sprintf(str + ret, "PRIME "); + if (ep_sts & EP_STS_SIDERR) + ret += sprintf(str + ret, "SIDERRT "); + if (ep_sts & EP_STS_OUTSMM) + ret += sprintf(str + ret, "OUTSMM "); + if (ep_sts & EP_STS_ISOERR) + ret += sprintf(str + ret, "ISOERR "); + if (ep_sts & EP_STS_IOT) + ret += sprintf(str + ret, "IOT "); + + return str; +} + +static inline char *cdns3_decode_epx_irq(char *str, + char *ep_name, + u32 ep_sts) +{ + return cdns3_decode_ep_irq(str, ep_sts, ep_name); +} + +static inline char *cdns3_decode_ep0_irq(char *str, + int dir, + u32 ep_sts) +{ + return cdns3_decode_ep_irq(str, ep_sts, + dir ? "ep0IN" : "ep0OUT"); +} + +/** + * Debug a transfer ring. + * + * Prints out all TRBs in the endpoint ring, even those after the Link TRB. + *. + */ +static inline char *cdns3_dbg_ring(struct cdns3_endpoint *priv_ep, + struct cdns3_trb *ring, char *str) +{ + dma_addr_t addr = priv_ep->trb_pool_dma; + struct cdns3_trb *trb; + int trb_per_sector; + int ret = 0; + int i; + + trb_per_sector = GET_TRBS_PER_SEGMENT(priv_ep->type); + + trb = &priv_ep->trb_pool[priv_ep->dequeue]; + ret += sprintf(str + ret, "\n\t\tRing contents for %s:", priv_ep->name); + + ret += sprintf(str + ret, + "\n\t\tRing deq index: %d, trb: %p (virt), 0x%llx (dma)\n", + priv_ep->dequeue, trb, + (unsigned long long)cdns3_trb_virt_to_dma(priv_ep, trb)); + + trb = &priv_ep->trb_pool[priv_ep->enqueue]; + ret += sprintf(str + ret, + "\t\tRing enq index: %d, trb: %p (virt), 0x%llx (dma)\n", + priv_ep->enqueue, trb, + (unsigned long long)cdns3_trb_virt_to_dma(priv_ep, trb)); + + ret += sprintf(str + ret, + "\t\tfree trbs: %d, CCS=%d, PCS=%d\n", + priv_ep->free_trbs, priv_ep->ccs, priv_ep->pcs); + + if (trb_per_sector > TRBS_PER_SEGMENT) + trb_per_sector = TRBS_PER_SEGMENT; + + if (trb_per_sector > TRBS_PER_SEGMENT) { + sprintf(str + ret, "\t\tTo big transfer ring %d\n", + trb_per_sector); + return str; + } + + for (i = 0; i < trb_per_sector; ++i) { + trb = &ring[i]; + ret += sprintf(str + ret, + "\t\t@%pad %08x %08x %08x\n", &addr, + le32_to_cpu(trb->buffer), + le32_to_cpu(trb->length), + le32_to_cpu(trb->control)); + addr += sizeof(*trb); + } + + return str; +} + +void cdns3_dbg(struct cdns3_device *priv_dev, const char *fmt, ...); + +#ifdef CONFIG_DEBUG_FS +void cdns3_debugfs_init(struct cdns3 *cdns); +void cdns3_debugfs_exit(struct cdns3 *cdns); +#else +void cdns3_debugfs_init(struct cdns3 *cdns); +{ } +void cdns3_debugfs_exit(struct cdns3 *cdns); +{ } +#endif + +#endif /*__LINUX_CDNS3_DEBUG*/ diff --git a/drivers/usb/cdns3/debugfs.c b/drivers/usb/cdns3/debugfs.c new file mode 100644 index 000000000000..44ee78a10eb8 --- /dev/null +++ b/drivers/usb/cdns3/debugfs.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Controller DebugFS filer. + * + * Copyright (C) 2018-2019 Cadence. + * + * Author: Pawel Laszczak + */ + +#include +#include +#include +#include + +#include "core.h" +#include "gadget.h" +#include "drd.h" + +static const char *const cdns3_mode[] = { + [USB_DR_MODE_UNKNOWN] = "unknown", + [USB_DR_MODE_OTG] = "otg", + [USB_DR_MODE_HOST] = "host", + [USB_DR_MODE_PERIPHERAL] = "device", +}; + +static int cdns3_mode_show(struct seq_file *s, void *unused) +{ + struct cdns3 *cdns = s->private; + + seq_puts(s, cdns3_mode[cdns->current_dr_mode]); + + return 0; +} + +static int cdns3_mode_open(struct inode *inode, struct file *file) +{ + return single_open(file, cdns3_mode_show, inode->i_private); +} + +static ssize_t cdns3_mode_write(struct file *file, + const char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct seq_file *s = file->private_data; + struct cdns3 *cdns = s->private; + char buf[32]; + int ret; + + if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) + return -EFAULT; + + if (cdns->debug_disable) { + dev_err(cdns->dev, + "Mode can't be changed when disable is set\n"); + return -EPERM; + } + + ret = match_string(cdns3_mode, ARRAY_SIZE(cdns3_mode), buf); + if (ret < 0 || ret == USB_DR_MODE_UNKNOWN) { + dev_err(cdns->dev, "Failed: incorrect mode setting\n"); + return -EINVAL; + } + + if (cdns->current_dr_mode != ret) { + cdns->desired_dr_mode = ret; + cdns3_role_stop(cdns); + ret = cdns3_drd_update_mode(cdns); + if (ret) + return ret; + + queue_work(system_freezable_wq, &cdns->role_switch_wq); + } + + return count; +} + +static const struct file_operations cdns3_mode_fops = { + .open = cdns3_mode_open, + .write = cdns3_mode_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int cdns3_disable_show(struct seq_file *s, void *unused) +{ + struct cdns3 *cdns = s->private; + + if (!cdns->debug_disable) + seq_puts(s, "0\n"); + else + seq_puts(s, "1\n"); + + return 0; +} + +static ssize_t cdns3_disable_write(struct file *file, + const char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct seq_file *s = file->private_data; + struct cdns3 *cdns = s->private; + bool disable; + char buf[16]; + + if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) + return -EFAULT; + + if (kstrtobool(buf, &disable)) { + dev_err(cdns->dev, "wrong setting\n"); + return -EINVAL; + } + + if (disable != cdns->debug_disable) { + cdns->debug_disable = disable; + queue_work(system_freezable_wq, &cdns->role_switch_wq); + } + + return count; +} + +static int cdns3_disable_open(struct inode *inode, struct file *file) +{ + return single_open(file, cdns3_disable_show, inode->i_private); +} + +static const struct file_operations cdns3_disable_fops = { + .open = cdns3_disable_open, + .write = cdns3_disable_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +void cdns3_debugfs_init(struct cdns3 *cdns) +{ + struct dentry *root; + + root = debugfs_create_dir(dev_name(cdns->dev), NULL); + cdns->root = root; + if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET) && + IS_ENABLED(CONFIG_USB_CDNS3_HOST)) + debugfs_create_file("mode", 0644, root, cdns, + &cdns3_mode_fops); + + debugfs_create_file("disable", 0644, root, cdns, + &cdns3_disable_fops); +} + +void cdns3_debugfs_exit(struct cdns3 *cdns) +{ + debugfs_remove_recursive(cdns->root); +} diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c new file mode 100644 index 000000000000..b06929fe1175 --- /dev/null +++ b/drivers/usb/cdns3/drd.c @@ -0,0 +1,379 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Driver. + * + * Copyright (C) 2018-2019 Cadence. + * Copyright (C) 2019 Texas Instruments + * + * Author: Pawel Laszczak + * Roger Quadros + * + * + */ +#include +#include +#include +#include + +#include "gadget.h" +#include "drd.h" +#include "core.h" + +/** + * cdns3_set_mode - change mode of OTG Core + * @cdns: pointer to context structure + * @mode: selected mode from cdns_role + * + * Returns 0 on success otherwise negative errno + */ +int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode) +{ + int ret = 0; + u32 reg; + + cdns->current_dr_mode = mode; + + switch (mode) { + case USB_DR_MODE_PERIPHERAL: + break; + case USB_DR_MODE_HOST: + break; + case USB_DR_MODE_OTG: + dev_dbg(cdns->dev, "Set controller to OTG mode\n"); + if (cdns->version == CDNS3_CONTROLLER_V1) { + reg = readl(&cdns->otg_v1_regs->override); + reg |= OVERRIDE_IDPULLUP; + writel(reg, &cdns->otg_v1_regs->override); + } else { + reg = readl(&cdns->otg_v0_regs->ctrl1); + reg |= OVERRIDE_IDPULLUP_V0; + writel(reg, &cdns->otg_v0_regs->ctrl1); + } + + /* + * Hardware specification says: "ID_VALUE must be valid within + * 50ms after idpullup is set to '1" so driver must wait + * 50ms before reading this pin. + */ + usleep_range(50000, 60000); + break; + default: + cdns->current_dr_mode = USB_DR_MODE_UNKNOWN; + dev_err(cdns->dev, "Unsupported mode of operation %d\n", mode); + return -EINVAL; + } + + return ret; +} + +int cdns3_get_id(struct cdns3 *cdns) +{ + int id; + + id = readl(&cdns->otg_regs->sts) & OTGSTS_ID_VALUE; + dev_dbg(cdns->dev, "OTG ID: %d", id); + + return id; +} + +int cdns3_get_vbus(struct cdns3 *cdns) +{ + int vbus; + + vbus = !!(readl(&cdns->otg_regs->sts) & OTGSTS_VBUS_VALID); + dev_dbg(cdns->dev, "OTG VBUS: %d", vbus); + return vbus; +} + +int cdns3_is_host(struct cdns3 *cdns) +{ + if (cdns->current_dr_mode == USB_DR_MODE_HOST) + return 1; + else if (!cdns3_get_id(cdns)) + return 1; + + return 0; +} + +int cdns3_is_device(struct cdns3 *cdns) +{ + if (cdns->current_dr_mode == USB_DR_MODE_PERIPHERAL) + return 1; + else if (cdns->current_dr_mode == USB_DR_MODE_OTG) + if (cdns3_get_id(cdns)) + return 1; + + return 0; +} + +/** + * cdns3_otg_disable_irq - Disable all OTG interrupts + * @cdns: Pointer to controller context structure + */ +static void cdns3_otg_disable_irq(struct cdns3 *cdns) +{ + writel(0, &cdns->otg_regs->ien); +} + +/** + * cdns3_otg_enable_irq - enable id and sess_valid interrupts + * @cdns: Pointer to controller context structure + */ +static void cdns3_otg_enable_irq(struct cdns3 *cdns) +{ + writel(OTGIEN_ID_CHANGE_INT | OTGIEN_VBUSVALID_RISE_INT | + OTGIEN_VBUSVALID_FALL_INT, &cdns->otg_regs->ien); +} + +/** + * cdns3_drd_switch_host - start/stop host + * @cdns: Pointer to controller context structure + * @on: 1 for start, 0 for stop + * + * Returns 0 on success otherwise negative errno + */ +int cdns3_drd_switch_host(struct cdns3 *cdns, int on) +{ + int ret; + u32 reg = OTGCMD_OTG_DIS; + + /* switch OTG core */ + if (on) { + writel(OTGCMD_HOST_BUS_REQ | reg, &cdns->otg_regs->cmd); + + dev_dbg(cdns->dev, "Waiting till Host mode is turned on\n"); + ret = cdns3_handshake(&cdns->otg_regs->sts, OTGSTS_XHCI_READY, + OTGSTS_XHCI_READY, 100000); + + if (ret) { + dev_err(cdns->dev, "timeout waiting for xhci_ready\n"); + return ret; + } + } else { + writel(OTGCMD_HOST_BUS_DROP | OTGCMD_DEV_BUS_DROP | + OTGCMD_DEV_POWER_OFF | OTGCMD_HOST_POWER_OFF, + &cdns->otg_regs->cmd); + /* Waiting till H_IDLE state.*/ + cdns3_handshake(&cdns->otg_regs->state, + OTGSTATE_HOST_STATE_MASK, + 0, 2000000); + } + + return 0; +} + +/** + * cdns3_drd_switch_gadget - start/stop gadget + * @cdns: Pointer to controller context structure + * @on: 1 for start, 0 for stop + * + * Returns 0 on success otherwise negative errno + */ +int cdns3_drd_switch_gadget(struct cdns3 *cdns, int on) +{ + int ret; + u32 reg = OTGCMD_OTG_DIS; + + /* switch OTG core */ + if (on) { + writel(OTGCMD_DEV_BUS_REQ | reg, &cdns->otg_regs->cmd); + + dev_dbg(cdns->dev, "Waiting till Device mode is turned on\n"); + + ret = cdns3_handshake(&cdns->otg_regs->sts, OTGSTS_DEV_READY, + OTGSTS_DEV_READY, 100000); + + if (ret) { + dev_err(cdns->dev, "timeout waiting for dev_ready\n"); + return ret; + } + } else { + /* + * driver should wait at least 10us after disabling Device + * before turning-off Device (DEV_BUS_DROP) + */ + usleep_range(20, 30); + writel(OTGCMD_HOST_BUS_DROP | OTGCMD_DEV_BUS_DROP | + OTGCMD_DEV_POWER_OFF | OTGCMD_HOST_POWER_OFF, + &cdns->otg_regs->cmd); + /* Waiting till DEV_IDLE state.*/ + cdns3_handshake(&cdns->otg_regs->state, OTGSTATE_DEV_STATE_MASK, + 0, 2000000); + } + + return 0; +} + +/** + * cdns3_init_otg_mode - initialize drd controller + * @cdns: Pointer to controller context structure + * + * Returns 0 on success otherwise negative errno + */ +static int cdns3_init_otg_mode(struct cdns3 *cdns) +{ + int ret = 0; + + cdns3_otg_disable_irq(cdns); + /* clear all interrupts */ + writel(~0, &cdns->otg_regs->ivect); + + ret = cdns3_set_mode(cdns, USB_DR_MODE_OTG); + if (ret) + return ret; + + cdns3_otg_enable_irq(cdns); + return ret; +} + +/** + * cdns3_drd_update_mode - initialize mode of operation + * @cdns: Pointer to controller context structure + * + * Returns 0 on success otherwise negative errno + */ +int cdns3_drd_update_mode(struct cdns3 *cdns) +{ + int ret = 0; + + if (cdns->desired_dr_mode == cdns->current_dr_mode) + return ret; + + switch (cdns->desired_dr_mode) { + case USB_DR_MODE_PERIPHERAL: + ret = cdns3_set_mode(cdns, USB_DR_MODE_PERIPHERAL); + break; + case USB_DR_MODE_HOST: + ret = cdns3_set_mode(cdns, USB_DR_MODE_HOST); + break; + case USB_DR_MODE_OTG: + ret = cdns3_init_otg_mode(cdns); + break; + default: + dev_err(cdns->dev, "Unsupported mode of operation %d\n", + cdns->dr_mode); + return -EINVAL; + } + + return ret; +} + +/** + * cdns3_drd_irq - interrupt handler for OTG events + * + * @irq: irq number for cdns3 core device + * @data: structure of cdns3 + * + * Returns IRQ_HANDLED or IRQ_NONE + */ +static irqreturn_t cdns3_drd_irq(int irq, void *data) +{ + irqreturn_t ret = IRQ_NONE; + struct cdns3 *cdns = data; + u32 reg; + + if (cdns->dr_mode != USB_DR_MODE_OTG) + return ret; + + reg = readl(&cdns->otg_regs->ivect); + + if (!reg) + return ret; + + if (reg & OTGIEN_ID_CHANGE_INT) { + dev_dbg(cdns->dev, "OTG IRQ: new ID: %d\n", + cdns3_get_id(cdns)); + + ret = IRQ_HANDLED; + } + + if (reg & (OTGIEN_VBUSVALID_RISE_INT | OTGIEN_VBUSVALID_FALL_INT)) { + dev_dbg(cdns->dev, "OTG IRQ: new VBUS: %d\n", + cdns3_get_vbus(cdns)); + + ret = IRQ_HANDLED; + } + + if (ret == IRQ_HANDLED) + queue_work(system_freezable_wq, &cdns->role_switch_wq); + + writel(~0, &cdns->otg_regs->ivect); + return ret; +} + +int cdns3_drd_init(struct cdns3 *cdns) +{ + void __iomem *regs; + int ret = 0; + u32 state; + + regs = devm_ioremap_resource(cdns->dev, &cdns->otg_res); + if (IS_ERR(regs)) + return PTR_ERR(regs); + + /* Detection of DRD version. Controller has been released + * in two versions. Both are similar, but they have same changes + * in register maps. + * The first register in old version is command register and it's read + * only, so driver should read 0 from it. On the other hand, in v1 + * the first register contains device ID number which is not set to 0. + * Driver uses this fact to detect the proper version of + * controller. + */ + cdns->otg_v0_regs = regs; + if (!readl(&cdns->otg_v0_regs->cmd)) { + cdns->version = CDNS3_CONTROLLER_V0; + cdns->otg_v1_regs = NULL; + cdns->otg_regs = regs; + writel(1, &cdns->otg_v0_regs->simulate); + dev_info(cdns->dev, "DRD version v0 (%08x)\n", + readl(&cdns->otg_v0_regs->version)); + } else { + cdns->otg_v0_regs = NULL; + cdns->otg_v1_regs = regs; + cdns->otg_regs = (void *)&cdns->otg_v1_regs->cmd; + cdns->version = CDNS3_CONTROLLER_V1; + writel(1, &cdns->otg_v1_regs->simulate); + dev_info(cdns->dev, "DRD version v1 (ID: %08x, rev: %08x)\n", + readl(&cdns->otg_v1_regs->did), + readl(&cdns->otg_v1_regs->rid)); + } + + state = OTGSTS_STRAP(readl(&cdns->otg_regs->sts)); + + /* Update dr_mode according to STRAP configuration. */ + cdns->dr_mode = USB_DR_MODE_OTG; + if (state == OTGSTS_STRAP_HOST) { + dev_dbg(cdns->dev, "Controller strapped to HOST\n"); + cdns->dr_mode = USB_DR_MODE_HOST; + } else if (state == OTGSTS_STRAP_GADGET) { + dev_dbg(cdns->dev, "Controller strapped to PERIPHERAL\n"); + cdns->dr_mode = USB_DR_MODE_PERIPHERAL; + } + + cdns->desired_dr_mode = cdns->dr_mode; + cdns->current_dr_mode = USB_DR_MODE_UNKNOWN; + + ret = devm_request_threaded_irq(cdns->dev, cdns->otg_irq, + cdns3_drd_irq, + NULL, IRQF_SHARED, + dev_name(cdns->dev), cdns); + + if (ret) { + dev_err(cdns->dev, "couldn't get otg_irq\n"); + return ret; + } + + state = readl(&cdns->otg_regs->sts); + if (OTGSTS_OTG_NRDY(state) != 0) { + dev_err(cdns->dev, "Cadence USB3 OTG device not ready\n"); + return -ENODEV; + } + + return ret; +} + +int cdns3_drd_exit(struct cdns3 *cdns) +{ + return 0; +} diff --git a/drivers/usb/cdns3/drd.h b/drivers/usb/cdns3/drd.h new file mode 100644 index 000000000000..bf6c7bc41b58 --- /dev/null +++ b/drivers/usb/cdns3/drd.h @@ -0,0 +1,166 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Cadence USB3 DRD header file. + * + * Copyright (C) 2018-2019 Cadence. + * + * Author: Pawel Laszczak + */ +#ifndef __LINUX_CDNS3_DRD +#define __LINUX_CDNS3_DRD + +#include +#include +#include "core.h" + +/* DRD register interface for version v1. */ +struct cdns3_otg_regs { + __le32 did; + __le32 rid; + __le32 capabilities; + __le32 reserved1; + __le32 cmd; + __le32 sts; + __le32 state; + __le32 reserved2; + __le32 ien; + __le32 ivect; + __le32 refclk; + __le32 tmr; + __le32 reserved3[4]; + __le32 simulate; + __le32 override; + __le32 susp_ctrl; + __le32 reserved4; + __le32 anasts; + __le32 adp_ramp_time; + __le32 ctrl1; + __le32 ctrl2; +}; + +/* DRD register interface for version v0. */ +struct cdns3_otg_legacy_regs { + __le32 cmd; + __le32 sts; + __le32 state; + __le32 refclk; + __le32 ien; + __le32 ivect; + __le32 reserved1[3]; + __le32 tmr; + __le32 reserved2[2]; + __le32 version; + __le32 capabilities; + __le32 reserved3[2]; + __le32 simulate; + __le32 reserved4[5]; + __le32 ctrl1; +}; + +/* + * Common registers interface for both version of DRD. + */ +struct cdns3_otg_common_regs { + __le32 cmd; + __le32 sts; + __le32 state; + __le32 different1; + __le32 ien; + __le32 ivect; +}; + +/* CDNS_RID - bitmasks */ +#define CDNS_RID(p) ((p) & GENMASK(15, 0)) + +/* CDNS_VID - bitmasks */ +#define CDNS_DID(p) ((p) & GENMASK(31, 0)) + +/* OTGCMD - bitmasks */ +/* "Request the bus for Device mode. */ +#define OTGCMD_DEV_BUS_REQ BIT(0) +/* Request the bus for Host mode */ +#define OTGCMD_HOST_BUS_REQ BIT(1) +/* Enable OTG mode. */ +#define OTGCMD_OTG_EN BIT(2) +/* Disable OTG mode */ +#define OTGCMD_OTG_DIS BIT(3) +/*"Configure OTG as A-Device. */ +#define OTGCMD_A_DEV_EN BIT(4) +/*"Configure OTG as A-Device. */ +#define OTGCMD_A_DEV_DIS BIT(5) +/* Drop the bus for Device mod e. */ +#define OTGCMD_DEV_BUS_DROP BIT(8) +/* Drop the bus for Host mode*/ +#define OTGCMD_HOST_BUS_DROP BIT(9) +/* Power Down USBSS-DEV. */ +#define OTGCMD_DEV_POWER_OFF BIT(11) +/* Power Down CDNSXHCI. */ +#define OTGCMD_HOST_POWER_OFF BIT(12) + +/* OTGIEN - bitmasks */ +/* ID change interrupt enable */ +#define OTGIEN_ID_CHANGE_INT BIT(0) +/* Vbusvalid fall detected interrupt enable.*/ +#define OTGIEN_VBUSVALID_RISE_INT BIT(4) +/* Vbusvalid fall detected interrupt enable */ +#define OTGIEN_VBUSVALID_FALL_INT BIT(5) + +/* OTGSTS - bitmasks */ +/* + * Current value of the ID pin. It is only valid when idpullup in + * OTGCTRL1_TYPE register is set to '1'. + */ +#define OTGSTS_ID_VALUE BIT(0) +/* Current value of the vbus_valid */ +#define OTGSTS_VBUS_VALID BIT(1) +/* Current value of the b_sess_vld */ +#define OTGSTS_SESSION_VALID BIT(2) +/*Device mode is active*/ +#define OTGSTS_DEV_ACTIVE BIT(3) +/* Host mode is active. */ +#define OTGSTS_HOST_ACTIVE BIT(4) +/* OTG Controller not ready. */ +#define OTGSTS_OTG_NRDY_MASK BIT(11) +#define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK) +/* + * Value of the strap pins. + * 000 - no default configuration + * 010 - Controller initiall configured as Host + * 100 - Controller initially configured as Device + */ +#define OTGSTS_STRAP(p) (((p) & GENMASK(14, 12)) >> 12) +#define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00 +#define OTGSTS_STRAP_HOST_OTG 0x01 +#define OTGSTS_STRAP_HOST 0x02 +#define OTGSTS_STRAP_GADGET 0x04 +/* Host mode is turned on. */ +#define OTGSTS_XHCI_READY BIT(26) +/* "Device mode is turned on .*/ +#define OTGSTS_DEV_READY BIT(27) + +/* OTGSTATE- bitmasks */ +#define OTGSTATE_DEV_STATE_MASK GENMASK(2, 0) +#define OTGSTATE_HOST_STATE_MASK GENMASK(5, 3) +#define OTGSTATE_HOST_STATE_IDLE 0x0 +#define OTGSTATE_HOST_STATE_VBUS_FALL 0x7 +#define OTGSTATE_HOST_STATE(p) (((p) & OTGSTATE_HOST_STATE_MASK) >> 3) + +/* OTGREFCLK - bitmasks */ +#define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31) + +/* OVERRIDE - bitmasks */ +#define OVERRIDE_IDPULLUP BIT(0) +/* Only for CDNS3_CONTROLLER_V0 version */ +#define OVERRIDE_IDPULLUP_V0 BIT(24) + +int cdns3_is_host(struct cdns3 *cdns); +int cdns3_is_device(struct cdns3 *cdns); +int cdns3_get_id(struct cdns3 *cdns); +int cdns3_get_vbus(struct cdns3 *cdns); +int cdns3_drd_init(struct cdns3 *cdns); +int cdns3_drd_exit(struct cdns3 *cdns); +int cdns3_drd_update_mode(struct cdns3 *cdns); +int cdns3_drd_switch_gadget(struct cdns3 *cdns, int on); +int cdns3_drd_switch_host(struct cdns3 *cdns, int on); + +#endif /* __LINUX_CDNS3_DRD */ diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c new file mode 100644 index 000000000000..6fa711ead6d0 --- /dev/null +++ b/drivers/usb/cdns3/ep0.c @@ -0,0 +1,920 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Driver - gadget side. + * + * Copyright (C) 2018 Cadence Design Systems. + * Copyright (C) 2017-2018 NXP + * + * Authors: Pawel Jez , + * Pawel Laszczak + * Peter Chen + */ + +#include + +#include "gadget.h" +#include "trace.h" + +static struct usb_endpoint_descriptor cdns3_gadget_ep0_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bmAttributes = USB_ENDPOINT_XFER_CONTROL, +}; + +/** + * cdns3_ep0_run_transfer - Do transfer on default endpoint hardware + * @priv_dev: extended gadget object + * @dma_addr: physical address where data is/will be stored + * @length: data length + * @erdy: set it to 1 when ERDY packet should be sent - + * exit from flow control state + */ +static void cdns3_ep0_run_transfer(struct cdns3_device *priv_dev, + dma_addr_t dma_addr, + unsigned int length, int erdy, int zlp) +{ + struct cdns3_usb_regs __iomem *regs = priv_dev->regs; + struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; + + priv_ep->trb_pool[0].buffer = TRB_BUFFER(dma_addr); + priv_ep->trb_pool[0].length = TRB_LEN(length); + + if (zlp) { + priv_ep->trb_pool[0].control = TRB_CYCLE | TRB_TYPE(TRB_NORMAL); + priv_ep->trb_pool[1].buffer = TRB_BUFFER(dma_addr); + priv_ep->trb_pool[1].length = TRB_LEN(0); + priv_ep->trb_pool[1].control = TRB_CYCLE | TRB_IOC | + TRB_TYPE(TRB_NORMAL); + } else { + priv_ep->trb_pool[0].control = TRB_CYCLE | TRB_IOC | + TRB_TYPE(TRB_NORMAL); + priv_ep->trb_pool[1].control = 0; + } + + trace_cdns3_prepare_trb(priv_ep, priv_ep->trb_pool); + + cdns3_select_ep(priv_dev, priv_dev->ep0_data_dir); + + writel(EP_STS_TRBERR, ®s->ep_sts); + writel(EP_TRADDR_TRADDR(priv_ep->trb_pool_dma), ®s->ep_traddr); + trace_cdns3_doorbell_ep0(priv_dev->ep0_data_dir ? "ep0in" : "ep0out", + readl(®s->ep_traddr)); + + /* TRB should be prepared before starting transfer. */ + writel(EP_CMD_DRDY, ®s->ep_cmd); + + /* Resume controller before arming transfer. */ + __cdns3_gadget_wakeup(priv_dev); + + if (erdy) + writel(EP_CMD_ERDY, &priv_dev->regs->ep_cmd); +} + +/** + * cdns3_ep0_delegate_req - Returns status of handling setup packet + * Setup is handled by gadget driver + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns zero on success or negative value on failure + */ +static int cdns3_ep0_delegate_req(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + int ret; + + spin_unlock(&priv_dev->lock); + priv_dev->setup_pending = 1; + ret = priv_dev->gadget_driver->setup(&priv_dev->gadget, ctrl_req); + priv_dev->setup_pending = 0; + spin_lock(&priv_dev->lock); + return ret; +} + +static void cdns3_prepare_setup_packet(struct cdns3_device *priv_dev) +{ + priv_dev->ep0_data_dir = 0; + priv_dev->ep0_stage = CDNS3_SETUP_STAGE; + cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, + sizeof(struct usb_ctrlrequest), 0, 0); +} + +static void cdns3_ep0_complete_setup(struct cdns3_device *priv_dev, + u8 send_stall, u8 send_erdy) +{ + struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; + struct usb_request *request; + + request = cdns3_next_request(&priv_ep->pending_req_list); + if (request) + list_del_init(&request->list); + + if (send_stall) { + cdns3_dbg(priv_ep->cdns3_dev, "STALL for ep0\n"); + /* set_stall on ep0 */ + cdns3_select_ep(priv_dev, 0x00); + writel(EP_CMD_SSTALL, &priv_dev->regs->ep_cmd); + } else { + cdns3_prepare_setup_packet(priv_dev); + } + + priv_dev->ep0_stage = CDNS3_SETUP_STAGE; + writel((send_erdy ? EP_CMD_ERDY : 0) | EP_CMD_REQ_CMPL, + &priv_dev->regs->ep_cmd); + + cdns3_allow_enable_l1(priv_dev, 1); +} + +/** + * cdns3_req_ep0_set_configuration - Handling of SET_CONFIG standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, USB_GADGET_DELAYED_STATUS on deferred status stage, + * error code on error + */ +static int cdns3_req_ep0_set_configuration(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + enum usb_device_state device_state = priv_dev->gadget.state; + struct cdns3_endpoint *priv_ep; + u32 config = le16_to_cpu(ctrl_req->wValue); + int result = 0; + int i; + + switch (device_state) { + case USB_STATE_ADDRESS: + /* Configure non-control EPs */ + for (i = 0; i < CDNS3_ENDPOINTS_MAX_COUNT; i++) { + priv_ep = priv_dev->eps[i]; + if (!priv_ep) + continue; + + if (priv_ep->flags & EP_CLAIMED) + cdns3_ep_config(priv_ep); + } + + result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); + + if (result) + return result; + + if (config) { + cdns3_set_hw_configuration(priv_dev); + } else { + cdns3_hw_reset_eps_config(priv_dev); + usb_gadget_set_state(&priv_dev->gadget, + USB_STATE_ADDRESS); + } + break; + case USB_STATE_CONFIGURED: + result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); + + if (!config && !result) { + cdns3_hw_reset_eps_config(priv_dev); + usb_gadget_set_state(&priv_dev->gadget, + USB_STATE_ADDRESS); + } + break; + default: + result = -EINVAL; + } + + return result; +} + +/** + * cdns3_req_ep0_set_address - Handling of SET_ADDRESS standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_set_address(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + enum usb_device_state device_state = priv_dev->gadget.state; + u32 reg; + u32 addr; + + addr = le16_to_cpu(ctrl_req->wValue); + + if (addr > USB_DEVICE_MAX_ADDRESS) { + dev_err(priv_dev->dev, + "Device address (%d) cannot be greater than %d\n", + addr, USB_DEVICE_MAX_ADDRESS); + return -EINVAL; + } + + if (device_state == USB_STATE_CONFIGURED) { + dev_err(priv_dev->dev, + "can't set_address from configured state\n"); + return -EINVAL; + } + + reg = readl(&priv_dev->regs->usb_cmd); + + writel(reg | USB_CMD_FADDR(addr) | USB_CMD_SET_ADDR, + &priv_dev->regs->usb_cmd); + + usb_gadget_set_state(&priv_dev->gadget, + (addr ? USB_STATE_ADDRESS : USB_STATE_DEFAULT)); + + return 0; +} + +/** + * cdns3_req_ep0_get_status - Handling of GET_STATUS standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl) +{ + __le16 *response_pkt; + u16 usb_status = 0; + u32 recip; + u32 reg; + + recip = ctrl->bRequestType & USB_RECIP_MASK; + + switch (recip) { + case USB_RECIP_DEVICE: + /* self powered */ + if (priv_dev->is_selfpowered) + usb_status = BIT(USB_DEVICE_SELF_POWERED); + + if (priv_dev->wake_up_flag) + usb_status |= BIT(USB_DEVICE_REMOTE_WAKEUP); + + if (priv_dev->gadget.speed != USB_SPEED_SUPER) + break; + + reg = readl(&priv_dev->regs->usb_sts); + + if (priv_dev->u1_allowed) + usb_status |= BIT(USB_DEV_STAT_U1_ENABLED); + + if (priv_dev->u2_allowed) + usb_status |= BIT(USB_DEV_STAT_U2_ENABLED); + + break; + case USB_RECIP_INTERFACE: + return cdns3_ep0_delegate_req(priv_dev, ctrl); + case USB_RECIP_ENDPOINT: + /* check if endpoint is stalled */ + cdns3_select_ep(priv_dev, ctrl->wIndex); + if (EP_STS_STALL(readl(&priv_dev->regs->ep_sts))) + usb_status = BIT(USB_ENDPOINT_HALT); + break; + default: + return -EINVAL; + } + + response_pkt = (__le16 *)priv_dev->setup_buf; + *response_pkt = cpu_to_le16(usb_status); + + cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, + sizeof(*response_pkt), 1, 0); + return 0; +} + +static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + enum usb_device_state state; + enum usb_device_speed speed; + int ret = 0; + u32 wValue; + u32 wIndex; + u16 tmode; + + wValue = le16_to_cpu(ctrl->wValue); + wIndex = le16_to_cpu(ctrl->wIndex); + state = priv_dev->gadget.state; + speed = priv_dev->gadget.speed; + + switch (ctrl->wValue) { + case USB_DEVICE_REMOTE_WAKEUP: + priv_dev->wake_up_flag = !!set; + break; + case USB_DEVICE_U1_ENABLE: + if (state != USB_STATE_CONFIGURED || speed != USB_SPEED_SUPER) + return -EINVAL; + + priv_dev->u1_allowed = !!set; + break; + case USB_DEVICE_U2_ENABLE: + if (state != USB_STATE_CONFIGURED || speed != USB_SPEED_SUPER) + return -EINVAL; + + priv_dev->u2_allowed = !!set; + break; + case USB_DEVICE_LTM_ENABLE: + ret = -EINVAL; + break; + case USB_DEVICE_TEST_MODE: + if (state != USB_STATE_CONFIGURED || speed > USB_SPEED_HIGH) + return -EINVAL; + + tmode = le16_to_cpu(ctrl->wIndex); + + if (!set || (tmode & 0xff) != 0) + return -EINVAL; + + switch (tmode >> 8) { + case TEST_J: + case TEST_K: + case TEST_SE0_NAK: + case TEST_PACKET: + cdns3_ep0_complete_setup(priv_dev, 0, 1); + /** + * Little delay to give the controller some time + * for sending status stage. + * This time should be less then 3ms. + */ + usleep_range(1000, 2000); + cdns3_set_register_bit(&priv_dev->regs->usb_cmd, + USB_CMD_STMODE | + USB_STS_TMODE_SEL(tmode - 1)); + break; + default: + ret = -EINVAL; + } + break; + default: + ret = -EINVAL; + } + + return ret; +} + +static int cdns3_ep0_feature_handle_intf(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + u32 wValue; + int ret = 0; + + wValue = le16_to_cpu(ctrl->wValue); + + switch (wValue) { + case USB_INTRF_FUNC_SUSPEND: + break; + default: + ret = -EINVAL; + } + + return ret; +} + +static int cdns3_ep0_feature_handle_endpoint(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + struct cdns3_endpoint *priv_ep; + int ret = 0; + u8 index; + + if (le16_to_cpu(ctrl->wValue) != USB_ENDPOINT_HALT) + return -EINVAL; + + if (!(ctrl->wIndex & ~USB_DIR_IN)) + return 0; + + index = cdns3_ep_addr_to_index(ctrl->wIndex); + priv_ep = priv_dev->eps[index]; + + cdns3_select_ep(priv_dev, ctrl->wIndex); + + if (set) { + cdns3_dbg(priv_ep->cdns3_dev, "Stall endpoint %s\n", + priv_ep->name); + writel(EP_CMD_SSTALL, &priv_dev->regs->ep_cmd); + priv_ep->flags |= EP_STALL; + } else { + struct usb_request *request; + + if (priv_dev->eps[index]->flags & EP_WEDGE) { + cdns3_select_ep(priv_dev, 0x00); + return 0; + } + + cdns3_dbg(priv_ep->cdns3_dev, "Clear Stalled endpoint %s\n", + priv_ep->name); + + writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd); + + /* wait for EPRST cleared */ + ret = cdns3_handshake(&priv_dev->regs->ep_cmd, + EP_CMD_EPRST, 0, 100); + if (ret) + return -EINVAL; + + priv_ep->flags &= ~EP_STALL; + + request = cdns3_next_request(&priv_ep->pending_req_list); + if (request) { + cdns3_dbg(priv_ep->cdns3_dev, "Resume transfer for %s\n", + priv_ep->name); + + cdns3_rearm_transfer(priv_ep, 1); + } + } + + return ret; +} + +/** + * cdns3_req_ep0_handle_feature - + * Handling of GET/SET_FEATURE standard USB request + * + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * @set: must be set to 1 for SET_FEATURE request + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_handle_feature(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + int ret = 0; + u32 recip; + + recip = ctrl->bRequestType & USB_RECIP_MASK; + + switch (recip) { + case USB_RECIP_DEVICE: + ret = cdns3_ep0_feature_handle_device(priv_dev, ctrl, set); + break; + case USB_RECIP_INTERFACE: + ret = cdns3_ep0_feature_handle_intf(priv_dev, ctrl, set); + break; + case USB_RECIP_ENDPOINT: + ret = cdns3_ep0_feature_handle_endpoint(priv_dev, ctrl, set); + break; + default: + return -EINVAL; + } + + return ret; +} + +/** + * cdns3_req_ep0_set_sel - Handling of SET_SEL standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_set_sel(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + if (priv_dev->gadget.state < USB_STATE_ADDRESS) + return -EINVAL; + + if (ctrl_req->wLength != 6) { + dev_err(priv_dev->dev, "Set SEL should be 6 bytes, got %d\n", + ctrl_req->wLength); + return -EINVAL; + } + + cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, 6, 1, 0); + return 0; +} + +/** + * cdns3_req_ep0_set_isoch_delay - + * Handling of GET_ISOCH_DELAY standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_set_isoch_delay(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + if (ctrl_req->wIndex || ctrl_req->wLength) + return -EINVAL; + + priv_dev->isoch_delay = ctrl_req->wValue; + + return 0; +} + +/** + * cdns3_ep0_standard_request - Handling standard USB requests + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_ep0_standard_request(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + int ret; + + switch (ctrl_req->bRequest) { + case USB_REQ_SET_ADDRESS: + ret = cdns3_req_ep0_set_address(priv_dev, ctrl_req); + break; + case USB_REQ_SET_CONFIGURATION: + ret = cdns3_req_ep0_set_configuration(priv_dev, ctrl_req); + break; + case USB_REQ_GET_STATUS: + ret = cdns3_req_ep0_get_status(priv_dev, ctrl_req); + break; + case USB_REQ_CLEAR_FEATURE: + ret = cdns3_req_ep0_handle_feature(priv_dev, ctrl_req, 0); + break; + case USB_REQ_SET_FEATURE: + ret = cdns3_req_ep0_handle_feature(priv_dev, ctrl_req, 1); + break; + case USB_REQ_SET_SEL: + ret = cdns3_req_ep0_set_sel(priv_dev, ctrl_req); + break; + case USB_REQ_SET_ISOCH_DELAY: + ret = cdns3_req_ep0_set_isoch_delay(priv_dev, ctrl_req); + break; + default: + ret = cdns3_ep0_delegate_req(priv_dev, ctrl_req); + break; + } + + return ret; +} + +static void __pending_setup_status_handler(struct cdns3_device *priv_dev) +{ + struct usb_request *request = priv_dev->pending_status_request; + + if (priv_dev->status_completion_no_call && request && + request->complete) { + request->complete(&priv_dev->eps[0]->endpoint, request); + priv_dev->status_completion_no_call = 0; + } +} + +void cdns3_pending_setup_status_handler(struct work_struct *work) +{ + struct cdns3_device *priv_dev = container_of(work, struct cdns3_device, + pending_status_wq); + unsigned long flags; + + spin_lock_irqsave(&priv_dev->lock, flags); + __pending_setup_status_handler(priv_dev); + spin_unlock_irqrestore(&priv_dev->lock, flags); +} + +/** + * cdns3_ep0_setup_phase - Handling setup USB requests + * @priv_dev: extended gadget object + */ +static void cdns3_ep0_setup_phase(struct cdns3_device *priv_dev) +{ + struct usb_ctrlrequest *ctrl = priv_dev->setup_buf; + struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; + int result; + + priv_dev->ep0_data_dir = ctrl->bRequestType & USB_DIR_IN; + + trace_cdns3_ctrl_req(ctrl); + + if (!list_empty(&priv_ep->pending_req_list)) { + struct usb_request *request; + + request = cdns3_next_request(&priv_ep->pending_req_list); + priv_ep->dir = priv_dev->ep0_data_dir; + cdns3_gadget_giveback(priv_ep, to_cdns3_request(request), + -ECONNRESET); + } + + if (le16_to_cpu(ctrl->wLength)) + priv_dev->ep0_stage = CDNS3_DATA_STAGE; + else + priv_dev->ep0_stage = CDNS3_STATUS_STAGE; + + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) + result = cdns3_ep0_standard_request(priv_dev, ctrl); + else + result = cdns3_ep0_delegate_req(priv_dev, ctrl); + + if (result == USB_GADGET_DELAYED_STATUS) + return; + + if (result < 0) + cdns3_ep0_complete_setup(priv_dev, 1, 1); + else if (priv_dev->ep0_stage == CDNS3_STATUS_STAGE) + cdns3_ep0_complete_setup(priv_dev, 0, 1); +} + +static void cdns3_transfer_completed(struct cdns3_device *priv_dev) +{ + struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; + + if (!list_empty(&priv_ep->pending_req_list)) { + struct usb_request *request; + + trace_cdns3_complete_trb(priv_ep, priv_ep->trb_pool); + request = cdns3_next_request(&priv_ep->pending_req_list); + + request->actual = + TRB_LEN(le32_to_cpu(priv_ep->trb_pool->length)); + + priv_ep->dir = priv_dev->ep0_data_dir; + cdns3_gadget_giveback(priv_ep, to_cdns3_request(request), 0); + } + + cdns3_ep0_complete_setup(priv_dev, 0, 0); +} + +/** + * cdns3_check_new_setup - Check if controller receive new SETUP packet. + * @priv_dev: extended gadget object + * + * The SETUP packet can be kept in on-chip memory or in system memory. + */ +static bool cdns3_check_new_setup(struct cdns3_device *priv_dev) +{ + u32 ep_sts_reg; + + cdns3_select_ep(priv_dev, 0 | USB_DIR_OUT); + ep_sts_reg = readl(&priv_dev->regs->ep_sts); + + return !!(ep_sts_reg & (EP_STS_SETUP | EP_STS_STPWAIT)); +} + +/** + * cdns3_check_ep0_interrupt_proceed - Processes interrupt related to endpoint 0 + * @priv_dev: extended gadget object + * @dir: USB_DIR_IN for IN direction, USB_DIR_OUT for OUT direction + */ +void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir) +{ + u32 ep_sts_reg; + + cdns3_select_ep(priv_dev, dir); + + ep_sts_reg = readl(&priv_dev->regs->ep_sts); + writel(ep_sts_reg, &priv_dev->regs->ep_sts); + + trace_cdns3_ep0_irq(priv_dev, ep_sts_reg); + + __pending_setup_status_handler(priv_dev); + + if (ep_sts_reg & EP_STS_SETUP) + priv_dev->wait_for_setup = 1; + + if (priv_dev->wait_for_setup && ep_sts_reg & EP_STS_IOC) { + priv_dev->wait_for_setup = 0; + cdns3_allow_enable_l1(priv_dev, 0); + cdns3_ep0_setup_phase(priv_dev); + } else if ((ep_sts_reg & EP_STS_IOC) || (ep_sts_reg & EP_STS_ISP)) { + priv_dev->ep0_data_dir = dir; + cdns3_transfer_completed(priv_dev); + } + + if (ep_sts_reg & EP_STS_DESCMIS) { + if (dir == 0 && !priv_dev->setup_pending) + cdns3_prepare_setup_packet(priv_dev); + } +} + +/** + * cdns3_gadget_ep0_enable + * Function shouldn't be called by gadget driver, + * endpoint 0 is allways active + */ +static int cdns3_gadget_ep0_enable(struct usb_ep *ep, + const struct usb_endpoint_descriptor *desc) +{ + return -EINVAL; +} + +/** + * cdns3_gadget_ep0_disable + * Function shouldn't be called by gadget driver, + * endpoint 0 is allways active + */ +static int cdns3_gadget_ep0_disable(struct usb_ep *ep) +{ + return -EINVAL; +} + +/** + * cdns3_gadget_ep0_set_halt + * @ep: pointer to endpoint zero object + * @value: 1 for set stall, 0 for clear stall + * + * Returns 0 + */ +static int cdns3_gadget_ep0_set_halt(struct usb_ep *ep, int value) +{ + /* TODO */ + return 0; +} + +/** + * cdns3_gadget_ep0_queue Transfer data on endpoint zero + * @ep: pointer to endpoint zero object + * @request: pointer to request object + * @gfp_flags: gfp flags + * + * Returns 0 on success, error code elsewhere + */ +static int cdns3_gadget_ep0_queue(struct usb_ep *ep, + struct usb_request *request, + gfp_t gfp_flags) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + unsigned long flags; + int erdy_sent = 0; + int ret = 0; + u8 zlp = 0; + + cdns3_dbg(priv_ep->cdns3_dev, "Queue to Ep0%s L: %d\n", + priv_dev->ep0_data_dir ? "IN" : "OUT", + request->length); + + /* cancel the request if controller receive new SETUP packet. */ + if (cdns3_check_new_setup(priv_dev)) + return -ECONNRESET; + + /* send STATUS stage. Should be called only for SET_CONFIGURATION */ + if (priv_dev->ep0_stage == CDNS3_STATUS_STAGE) { + spin_lock_irqsave(&priv_dev->lock, flags); + cdns3_select_ep(priv_dev, 0x00); + + erdy_sent = !priv_dev->hw_configured_flag; + cdns3_set_hw_configuration(priv_dev); + + if (!erdy_sent) + cdns3_ep0_complete_setup(priv_dev, 0, 1); + + cdns3_allow_enable_l1(priv_dev, 1); + + request->actual = 0; + priv_dev->status_completion_no_call = true; + priv_dev->pending_status_request = request; + spin_unlock_irqrestore(&priv_dev->lock, flags); + + /* + * Since there is no completion interrupt for status stage, + * it needs to call ->completion in software after + * ep0_queue is back. + */ + queue_work(system_freezable_wq, &priv_dev->pending_status_wq); + return 0; + } + + spin_lock_irqsave(&priv_dev->lock, flags); + if (!list_empty(&priv_ep->pending_req_list)) { + dev_err(priv_dev->dev, + "can't handle multiple requests for ep0\n"); + spin_unlock_irqrestore(&priv_dev->lock, flags); + return -EBUSY; + } + + ret = usb_gadget_map_request_by_dev(priv_dev->sysdev, request, + priv_dev->ep0_data_dir); + if (ret) { + spin_unlock_irqrestore(&priv_dev->lock, flags); + dev_err(priv_dev->dev, "failed to map request\n"); + return -EINVAL; + } + + request->status = -EINPROGRESS; + list_add_tail(&request->list, &priv_ep->pending_req_list); + + if (request->zero && request->length && + (request->length % ep->maxpacket == 0)) + zlp = 1; + + cdns3_ep0_run_transfer(priv_dev, request->dma, request->length, 1, zlp); + + spin_unlock_irqrestore(&priv_dev->lock, flags); + + return ret; +} + +/** + * cdns3_gadget_ep_set_wedge Set wedge on selected endpoint + * @ep: endpoint object + * + * Returns 0 + */ +int cdns3_gadget_ep_set_wedge(struct usb_ep *ep) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + + dev_dbg(priv_dev->dev, "Wedge for %s\n", ep->name); + cdns3_gadget_ep_set_halt(ep, 1); + priv_ep->flags |= EP_WEDGE; + + return 0; +} + +const struct usb_ep_ops cdns3_gadget_ep0_ops = { + .enable = cdns3_gadget_ep0_enable, + .disable = cdns3_gadget_ep0_disable, + .alloc_request = cdns3_gadget_ep_alloc_request, + .free_request = cdns3_gadget_ep_free_request, + .queue = cdns3_gadget_ep0_queue, + .dequeue = cdns3_gadget_ep_dequeue, + .set_halt = cdns3_gadget_ep0_set_halt, + .set_wedge = cdns3_gadget_ep_set_wedge, +}; + +/** + * cdns3_ep0_config - Configures default endpoint + * @priv_dev: extended gadget object + * + * Functions sets parameters: maximal packet size and enables interrupts + */ +void cdns3_ep0_config(struct cdns3_device *priv_dev) +{ + struct cdns3_usb_regs __iomem *regs; + struct cdns3_endpoint *priv_ep; + u32 max_packet_size = 64; + + regs = priv_dev->regs; + + if (priv_dev->gadget.speed == USB_SPEED_SUPER) + max_packet_size = 512; + + priv_ep = priv_dev->eps[0]; + + if (!list_empty(&priv_ep->pending_req_list)) { + struct usb_request *request; + + request = cdns3_next_request(&priv_ep->pending_req_list); + list_del_init(&request->list); + } + + priv_dev->u1_allowed = 0; + priv_dev->u2_allowed = 0; + + priv_dev->gadget.ep0->maxpacket = max_packet_size; + cdns3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(max_packet_size); + + /* init ep out */ + cdns3_select_ep(priv_dev, USB_DIR_OUT); + + if (priv_dev->dev_ver >= DEV_VER_V3) { + cdns3_set_register_bit(&priv_dev->regs->dtrans, + BIT(0) | BIT(16)); + cdns3_set_register_bit(&priv_dev->regs->tdl_from_trb, + BIT(0) | BIT(16)); + } + + writel(EP_CFG_ENABLE | EP_CFG_MAXPKTSIZE(max_packet_size), + ®s->ep_cfg); + + writel(EP_STS_EN_SETUPEN | EP_STS_EN_DESCMISEN | EP_STS_EN_TRBERREN, + ®s->ep_sts_en); + + /* init ep in */ + cdns3_select_ep(priv_dev, USB_DIR_IN); + + writel(EP_CFG_ENABLE | EP_CFG_MAXPKTSIZE(max_packet_size), + ®s->ep_cfg); + + writel(EP_STS_EN_SETUPEN | EP_STS_EN_TRBERREN, ®s->ep_sts_en); + + cdns3_set_register_bit(®s->usb_conf, USB_CONF_U1DS | USB_CONF_U2DS); +} + +/** + * cdns3_init_ep0 Initializes software endpoint 0 of gadget + * @priv_dev: extended gadget object + * @ep_priv: extended endpoint object + * + * Returns 0 on success else error code. + */ +int cdns3_init_ep0(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep) +{ + sprintf(priv_ep->name, "ep0"); + + /* fill linux fields */ + priv_ep->endpoint.ops = &cdns3_gadget_ep0_ops; + priv_ep->endpoint.maxburst = 1; + usb_ep_set_maxpacket_limit(&priv_ep->endpoint, + CDNS3_EP0_MAX_PACKET_LIMIT); + priv_ep->endpoint.address = 0; + priv_ep->endpoint.caps.type_control = 1; + priv_ep->endpoint.caps.dir_in = 1; + priv_ep->endpoint.caps.dir_out = 1; + priv_ep->endpoint.name = priv_ep->name; + priv_ep->endpoint.desc = &cdns3_gadget_ep0_desc; + priv_dev->gadget.ep0 = &priv_ep->endpoint; + priv_ep->type = USB_ENDPOINT_XFER_CONTROL; + + return cdns3_allocate_trb_pool(priv_ep); +} diff --git a/drivers/usb/cdns3/gadget-export.h b/drivers/usb/cdns3/gadget-export.h new file mode 100644 index 000000000000..577469eee961 --- /dev/null +++ b/drivers/usb/cdns3/gadget-export.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Cadence USBSS DRD Driver - Gadget Export APIs. + * + * Copyright (C) 2017 NXP + * Copyright (C) 2017-2018 NXP + * + * Authors: Peter Chen + */ +#ifndef __LINUX_CDNS3_GADGET_EXPORT +#define __LINUX_CDNS3_GADGET_EXPORT + +#ifdef CONFIG_USB_CDNS3_GADGET + +int cdns3_gadget_init(struct cdns3 *cdns); +void cdns3_gadget_exit(struct cdns3 *cdns); +#else + +static inline int cdns3_gadget_init(struct cdns3 *cdns) +{ + return -ENXIO; +} + +static inline void cdns3_gadget_exit(struct cdns3 *cdns) { } + +#endif + +#endif /* __LINUX_CDNS3_GADGET_EXPORT */ diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c new file mode 100644 index 000000000000..4e9e8e43f634 --- /dev/null +++ b/drivers/usb/cdns3/gadget.c @@ -0,0 +1,2319 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Driver - gadget side. + * + * Copyright (C) 2018-2019 Cadence Design Systems. + * Copyright (C) 2017-2018 NXP + * + * Authors: Pawel Jez , + * Pawel Laszczak + * Peter Chen + */ + +/* + * Work around 1: + * At some situations, the controller may get stale data address in TRB + * at below sequences: + * 1. Controller read TRB includes data address + * 2. Software updates TRBs includes data address and Cycle bit + * 3. Controller read TRB which includes Cycle bit + * 4. DMA run with stale data address + * + * To fix this problem, driver needs to make the first TRB in TD as invalid. + * After preparing all TRBs driver needs to check the position of DMA and + * if the DMA point to the first just added TRB and doorbell is 1, + * then driver must defer making this TRB as valid. This TRB will be make + * as valid during adding next TRB only if DMA is stopped or at TRBERR + * interrupt. + * + * Issue has been fixed in DEV_VER_V3 version of controller. + * + */ + +#include +#include +#include + +#include "core.h" +#include "gadget-export.h" +#include "gadget.h" +#include "trace.h" +#include "drd.h" + +static int __cdns3_gadget_ep_queue(struct usb_ep *ep, + struct usb_request *request, + gfp_t gfp_flags); + +/** + * cdns3_set_register_bit - set bit in given register. + * @ptr: address of device controller register to be read and changed + * @mask: bits requested to set + */ +void cdns3_set_register_bit(void __iomem *ptr, u32 mask) +{ + mask = readl(ptr) | mask; + writel(mask, ptr); +} + +/** + * cdns3_ep_addr_to_index - Macro converts endpoint address to + * index of endpoint object in cdns3_device.eps[] container + * @ep_addr: endpoint address for which endpoint object is required + * + */ +u8 cdns3_ep_addr_to_index(u8 ep_addr) +{ + return (((ep_addr & 0x7F)) + ((ep_addr & USB_DIR_IN) ? 16 : 0)); +} + +static int cdns3_get_dma_pos(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep) +{ + int dma_index; + + dma_index = readl(&priv_dev->regs->ep_traddr) - priv_ep->trb_pool_dma; + + return dma_index / TRB_SIZE; +} + +/** + * cdns3_next_request - returns next request from list + * @list: list containing requests + * + * Returns request or NULL if no requests in list + */ +struct usb_request *cdns3_next_request(struct list_head *list) +{ + return list_first_entry_or_null(list, struct usb_request, list); +} + +/** + * cdns3_next_align_buf - returns next buffer from list + * @list: list containing buffers + * + * Returns buffer or NULL if no buffers in list + */ +struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list) +{ + return list_first_entry_or_null(list, struct cdns3_aligned_buf, list); +} + +/** + * select_ep - selects endpoint + * @priv_dev: extended gadget object + * @ep: endpoint address + */ +void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep) +{ + if (priv_dev->selected_ep == ep) + return; + + priv_dev->selected_ep = ep; + writel(ep, &priv_dev->regs->ep_sel); +} + +dma_addr_t cdns3_trb_virt_to_dma(struct cdns3_endpoint *priv_ep, + struct cdns3_trb *trb) +{ + u32 offset = (char *)trb - (char *)priv_ep->trb_pool; + + return priv_ep->trb_pool_dma + offset; +} + +int cdns3_ring_size(struct cdns3_endpoint *priv_ep) +{ + switch (priv_ep->type) { + case USB_ENDPOINT_XFER_ISOC: + return TRB_ISO_RING_SIZE; + case USB_ENDPOINT_XFER_CONTROL: + return TRB_CTRL_RING_SIZE; + default: + return TRB_RING_SIZE; + } +} + +/** + * cdns3_allocate_trb_pool - Allocates TRB's pool for selected endpoint + * @priv_ep: endpoint object + * + * Function will return 0 on success or -ENOMEM on allocation error + */ +int cdns3_allocate_trb_pool(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + int ring_size = cdns3_ring_size(priv_ep); + struct cdns3_trb *link_trb; + + if (!priv_ep->trb_pool) { + priv_ep->trb_pool = dma_alloc_coherent(priv_dev->sysdev, + ring_size, + &priv_ep->trb_pool_dma, + GFP_DMA32 | GFP_ATOMIC); + if (!priv_ep->trb_pool) + return -ENOMEM; + } else { + memset(priv_ep->trb_pool, 0, ring_size); + } + + if (!priv_ep->num) + return 0; + + priv_ep->num_trbs = ring_size / TRB_SIZE; + /* Initialize the last TRB as Link TRB */ + link_trb = (priv_ep->trb_pool + (priv_ep->num_trbs - 1)); + link_trb->buffer = TRB_BUFFER(priv_ep->trb_pool_dma); + link_trb->control = TRB_CYCLE | TRB_TYPE(TRB_LINK) | TRB_TOGGLE; + + return 0; +} + +static void cdns3_free_trb_pool(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + + if (priv_ep->trb_pool) { + dma_free_coherent(priv_dev->sysdev, + cdns3_ring_size(priv_ep), + priv_ep->trb_pool, priv_ep->trb_pool_dma); + priv_ep->trb_pool = NULL; + } +} + +/** + * cdns3_ep_stall_flush - Stalls and flushes selected endpoint + * @priv_ep: endpoint object + * + * Endpoint must be selected before call to this function + */ +static void cdns3_ep_stall_flush(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + + cdns3_dbg(priv_ep->cdns3_dev, "Stall & flush endpoint %s\n", + priv_ep->name); + + writel(EP_CMD_DFLUSH | EP_CMD_ERDY | EP_CMD_SSTALL, + &priv_dev->regs->ep_cmd); + + /* wait for DFLUSH cleared */ + cdns3_handshake(&priv_dev->regs->ep_cmd, EP_CMD_DFLUSH, 0, 1000); + priv_ep->flags |= EP_STALL; +} + +/** + * cdns3_hw_reset_eps_config - reset endpoints configuration kept by controller. + * @priv_dev: extended gadget object + */ +void cdns3_hw_reset_eps_config(struct cdns3_device *priv_dev) +{ + writel(USB_CONF_CFGRST, &priv_dev->regs->usb_conf); + + cdns3_allow_enable_l1(priv_dev, 0); + priv_dev->hw_configured_flag = 0; + priv_dev->onchip_used_size = 0; + priv_dev->out_mem_is_allocated = 0; + priv_dev->wait_for_setup = 0; +} + +/** + * cdns3_ep_inc_trb - increment a trb index. + * @index: Pointer to the TRB index to increment. + * @cs: Cycle state + * @trb_in_seg: number of TRBs in segment + * + * The index should never point to the link TRB. After incrementing, + * if it is point to the link TRB, wrap around to the beginning and revert + * cycle state bit The + * link TRB is always at the last TRB entry. + */ +static void cdns3_ep_inc_trb(int *index, u8 *cs, int trb_in_seg) +{ + (*index)++; + if (*index == (trb_in_seg - 1)) { + *index = 0; + *cs ^= 1; + } +} + +/** + * cdns3_ep_inc_enq - increment endpoint's enqueue pointer + * @priv_ep: The endpoint whose enqueue pointer we're incrementing + */ +static void cdns3_ep_inc_enq(struct cdns3_endpoint *priv_ep) +{ + priv_ep->free_trbs--; + cdns3_ep_inc_trb(&priv_ep->enqueue, &priv_ep->pcs, priv_ep->num_trbs); +} + +/** + * cdns3_ep_inc_deq - increment endpoint's dequeue pointer + * @priv_ep: The endpoint whose dequeue pointer we're incrementing + */ +static void cdns3_ep_inc_deq(struct cdns3_endpoint *priv_ep) +{ + priv_ep->free_trbs++; + cdns3_ep_inc_trb(&priv_ep->dequeue, &priv_ep->ccs, priv_ep->num_trbs); +} + +void cdns3_move_deq_to_next_trb(struct cdns3_request *priv_req) +{ + struct cdns3_endpoint *priv_ep = priv_req->priv_ep; + int current_trb = priv_req->start_trb; + + while (current_trb != priv_req->end_trb) { + cdns3_ep_inc_deq(priv_ep); + current_trb = priv_ep->dequeue; + } + + cdns3_ep_inc_deq(priv_ep); +} + +/** + * cdns3_allow_enable_l1 - enable/disable permits to transition to L1. + * @priv_dev: Extended gadget object + * @enable: Enable/disable permit to transition to L1. + * + * If bit USB_CONF_L1EN is set and device receive Extended Token packet, + * then controller answer with ACK handshake. + * If bit USB_CONF_L1DS is set and device receive Extended Token packet, + * then controller answer with NYET handshake. + */ +void cdns3_allow_enable_l1(struct cdns3_device *priv_dev, int enable) +{ + if (enable) + writel(USB_CONF_L1EN, &priv_dev->regs->usb_conf); + else + writel(USB_CONF_L1DS, &priv_dev->regs->usb_conf); +} + +enum usb_device_speed cdns3_get_speed(struct cdns3_device *priv_dev) +{ + u32 reg; + + reg = readl(&priv_dev->regs->usb_sts); + + if (DEV_SUPERSPEED(reg)) + return USB_SPEED_SUPER; + else if (DEV_HIGHSPEED(reg)) + return USB_SPEED_HIGH; + else if (DEV_FULLSPEED(reg)) + return USB_SPEED_FULL; + else if (DEV_LOWSPEED(reg)) + return USB_SPEED_LOW; + return USB_SPEED_UNKNOWN; +} + +/** + * cdns3_start_all_request - add to ring all request not started + * @priv_dev: Extended gadget object + * @priv_ep: The endpoint for whom request will be started. + * + * Returns return ENOMEM if transfer ring i not enough TRBs to start + * all requests. + */ +static int cdns3_start_all_request(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep) +{ + struct cdns3_request *priv_req; + struct usb_request *request; + int ret = 0; + + while (!list_empty(&priv_ep->deferred_req_list)) { + request = cdns3_next_request(&priv_ep->deferred_req_list); + priv_req = to_cdns3_request(request); + + ret = cdns3_ep_run_transfer(priv_ep, request); + if (ret) + return ret; + + list_del(&request->list); + list_add_tail(&request->list, + &priv_ep->pending_req_list); + } + + priv_ep->flags &= ~EP_RING_FULL; + return ret; +} + +/** + * cdns3_gadget_giveback - call struct usb_request's ->complete callback + * @priv_ep: The endpoint to whom the request belongs to + * @priv_req: The request we're giving back + * @status: completion code for the request + * + * Must be called with controller's lock held and interrupts disabled. This + * function will unmap @req and call its ->complete() callback to notify upper + * layers that it has completed. + */ +void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, + struct cdns3_request *priv_req, + int status) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct usb_request *request = &priv_req->request; + + list_del_init(&request->list); + + if (request->status == -EINPROGRESS) + request->status = status; + + usb_gadget_unmap_request_by_dev(priv_dev->sysdev, request, + priv_ep->dir); + + if ((priv_req->flags & REQUEST_UNALIGNED) && + priv_ep->dir == USB_DIR_OUT && !request->status) + memcpy(request->buf, priv_req->aligned_buf->buf, + request->length); + + priv_req->flags &= ~(REQUEST_PENDING | REQUEST_UNALIGNED); + trace_cdns3_gadget_giveback(priv_req); + + if (request->complete) { + spin_unlock(&priv_dev->lock); + usb_gadget_giveback_request(&priv_ep->endpoint, + request); + spin_lock(&priv_dev->lock); + } + + if (request->buf == priv_dev->zlp_buf) + cdns3_gadget_ep_free_request(&priv_ep->endpoint, request); +} + +void cdns3_wa1_restore_cycle_bit(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + + /* Work around for stale data address in TRB*/ + if (priv_ep->wa1_set) { + cdns3_dbg(priv_dev, "WA1: update cycle bit\n"); + priv_ep->wa1_set = 0; + priv_ep->wa1_trb_index = 0xFFFF; + if (priv_ep->wa1_cycle_bit) { + priv_ep->wa1_trb->control = + priv_ep->wa1_trb->control | 0x1; + } else { + priv_ep->wa1_trb->control = + priv_ep->wa1_trb->control & ~0x1; + } + } +} + +static int cdns3_prepare_aligned_request_buf(struct cdns3_request *priv_req) +{ + struct cdns3_endpoint *priv_ep = priv_req->priv_ep; + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct cdns3_aligned_buf *buf; + + /* check if buffer is aligned to 8. */ + if (!((uintptr_t)priv_req->request.buf & 0x7)) + return 0; + + buf = priv_req->aligned_buf; + + if (!buf || priv_req->request.length > buf->size) { + buf = kzalloc(sizeof(*buf), GFP_ATOMIC); + if (!buf) + return -ENOMEM; + + buf->size = priv_req->request.length; + + buf->buf = dma_alloc_coherent(priv_dev->sysdev, + buf->size, + &buf->dma, + GFP_ATOMIC); + if (!buf->buf) { + kfree(buf); + return -ENOMEM; + } + + if (priv_req->aligned_buf) { + trace_cdns3_free_aligned_request(priv_req); + priv_req->aligned_buf->in_use = 0; + priv_dev->run_garbage_colector = 1; + } + + buf->in_use = 1; + priv_req->aligned_buf = buf; + + list_add_tail(&buf->list, + &priv_dev->aligned_buf_list); + } + + if (priv_ep->dir == USB_DIR_IN) { + memcpy(buf->buf, priv_req->request.buf, + priv_req->request.length); + } + + priv_req->flags |= REQUEST_UNALIGNED; + trace_cdns3_prepare_aligned_request(priv_req); + + return 0; +} + +static int cdns3_wa1_update_guard(struct cdns3_endpoint *priv_ep, + struct cdns3_trb *trb) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + + if (!priv_ep->wa1_set) { + u32 doorbell; + + doorbell = !!(readl(&priv_dev->regs->ep_cmd) & EP_CMD_DRDY); + + if (doorbell) { + priv_ep->wa1_cycle_bit = priv_ep->pcs ? TRB_CYCLE : 0; + priv_ep->wa1_set = 1; + priv_ep->wa1_trb = trb; + priv_ep->wa1_trb_index = priv_ep->enqueue; + cdns3_dbg(priv_dev, "WA1 set guard\n"); + return 0; + } + } + return 1; +} + +static void cdns3_wa1_tray_restore_cycle_bit(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep) +{ + int dma_index; + u32 doorbell; + + doorbell = !!(readl(&priv_dev->regs->ep_cmd) & EP_CMD_DRDY); + dma_index = cdns3_get_dma_pos(priv_dev, priv_ep); + + if (!doorbell || dma_index != priv_ep->wa1_trb_index) + cdns3_wa1_restore_cycle_bit(priv_ep); +} + +/** + * cdns3_ep_run_transfer - start transfer on no-default endpoint hardware + * @priv_ep: endpoint object + * + * Returns zero on success or negative value on failure + */ +int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, + struct usb_request *request) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct cdns3_request *priv_req; + struct cdns3_trb *trb; + dma_addr_t trb_dma; + u32 togle_pcs = 1; + int sg_iter = 0; + int num_trb; + int address; + u32 control; + int pcs; + + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) + num_trb = priv_ep->interval; + else + num_trb = request->num_sgs ? request->num_sgs : 1; + + if (num_trb > priv_ep->free_trbs) { + priv_ep->flags |= EP_RING_FULL; + return -ENOBUFS; + } + + priv_req = to_cdns3_request(request); + address = priv_ep->endpoint.desc->bEndpointAddress; + + priv_ep->flags |= EP_PENDING_REQUEST; + + /* must allocate buffer aligned to 8 */ + if (priv_req->flags & REQUEST_UNALIGNED) + trb_dma = priv_req->aligned_buf->dma; + else + trb_dma = request->dma; + + trb = priv_ep->trb_pool + priv_ep->enqueue; + priv_req->start_trb = priv_ep->enqueue; + priv_req->trb = trb; + + cdns3_select_ep(priv_ep->cdns3_dev, address); + + /* prepare ring */ + if ((priv_ep->enqueue + num_trb) >= (priv_ep->num_trbs - 1)) { + struct cdns3_trb *link_trb; + int doorbell, dma_index; + u32 ch_bit = 0; + + doorbell = !!(readl(&priv_dev->regs->ep_cmd) & EP_CMD_DRDY); + dma_index = cdns3_get_dma_pos(priv_dev, priv_ep); + + /* Driver can't update LINK TRB if it is current processed. */ + if (doorbell && dma_index == priv_ep->num_trbs - 1) { + priv_ep->flags |= EP_DEFERRED_DRDY; + return -ENOBUFS; + } + + /*updating C bt in Link TRB before starting DMA*/ + link_trb = priv_ep->trb_pool + (priv_ep->num_trbs - 1); + /* + * For TRs size equal 2 enabling TRB_CHAIN for epXin causes + * that DMA stuck at the LINK TRB. + * On the other hand, removing TRB_CHAIN for longer TRs for + * epXout cause that DMA stuck after handling LINK TRB. + * To eliminate this strange behavioral driver set TRB_CHAIN + * bit only for TR size > 2. + */ + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC || + TRBS_PER_SEGMENT > 2) + ch_bit = TRB_CHAIN; + + link_trb->control = ((priv_ep->pcs) ? TRB_CYCLE : 0) | + TRB_TYPE(TRB_LINK) | TRB_TOGGLE | ch_bit; + } + + if (priv_dev->dev_ver <= DEV_VER_V2) + togle_pcs = cdns3_wa1_update_guard(priv_ep, trb); + + /* set incorrect Cycle Bit for first trb*/ + control = priv_ep->pcs ? 0 : TRB_CYCLE; + + do { + u32 length; + u16 td_size = 0; + + /* fill TRB */ + control |= TRB_TYPE(TRB_NORMAL); + trb->buffer = TRB_BUFFER(request->num_sgs == 0 + ? trb_dma : request->sg[sg_iter].dma_address); + + if (likely(!request->num_sgs)) + length = request->length; + else + length = request->sg[sg_iter].length; + + if (likely(priv_dev->dev_ver >= DEV_VER_V2)) + td_size = DIV_ROUND_UP(length, + priv_ep->endpoint.maxpacket); + + trb->length = TRB_BURST_LEN(priv_ep->trb_burst_size) | + TRB_LEN(length); + if (priv_dev->gadget.speed == USB_SPEED_SUPER) + trb->length |= TRB_TDL_SS_SIZE(td_size); + else + control |= TRB_TDL_HS_SIZE(td_size); + + pcs = priv_ep->pcs ? TRB_CYCLE : 0; + + /* + * first trb should be prepared as last to avoid processing + * transfer to early + */ + if (sg_iter != 0) + control |= pcs; + + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir) { + control |= TRB_IOC | TRB_ISP; + } else { + /* for last element in TD or in SG list */ + if (sg_iter == (num_trb - 1) && sg_iter != 0) + control |= pcs | TRB_IOC | TRB_ISP; + } + + if (sg_iter) + trb->control = control; + else + priv_req->trb->control = control; + + control = 0; + ++sg_iter; + priv_req->end_trb = priv_ep->enqueue; + cdns3_ep_inc_enq(priv_ep); + trb = priv_ep->trb_pool + priv_ep->enqueue; + } while (sg_iter < num_trb); + + trb = priv_req->trb; + + priv_req->flags |= REQUEST_PENDING; + + if (sg_iter == 1) + trb->control |= TRB_IOC | TRB_ISP; + /* + * Memory barrier - cycle bit must be set before other filds in trb. + */ + wmb(); + + /* give the TD to the consumer*/ + if (togle_pcs) + trb->control = trb->control ^ 1; + + if (priv_dev->dev_ver <= DEV_VER_V2) + cdns3_wa1_tray_restore_cycle_bit(priv_dev, priv_ep); + + trace_cdns3_prepare_trb(priv_ep, priv_req->trb); + + /* + * Memory barrier - Cycle Bit must be set before trb->length and + * trb->buffer fields. + */ + wmb(); + + /* + * For DMULT mode we can set address to transfer ring only once after + * enabling endpoint. + */ + if (priv_ep->flags & EP_UPDATE_EP_TRBADDR) { + /* + * Until SW is not ready to handle the OUT transfer the ISO OUT + * Endpoint should be disabled (EP_CFG.ENABLE = 0). + * EP_CFG_ENABLE must be set before updating ep_traddr. + */ + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir && + !(priv_ep->flags & EP_QUIRK_ISO_OUT_EN)) { + priv_ep->flags |= EP_QUIRK_ISO_OUT_EN; + cdns3_set_register_bit(&priv_dev->regs->ep_cfg, + EP_CFG_ENABLE); + } + + writel(EP_TRADDR_TRADDR(priv_ep->trb_pool_dma + + priv_req->start_trb * TRB_SIZE), + &priv_dev->regs->ep_traddr); + + cdns3_dbg(priv_ep->cdns3_dev, "Update ep_trbaddr for %s to %08x\n", + priv_ep->name, readl(&priv_dev->regs->ep_traddr)); + + priv_ep->flags &= ~EP_UPDATE_EP_TRBADDR; + } + + if (!priv_ep->wa1_set && !(priv_ep->flags & EP_STALL)) { + trace_cdns3_ring(priv_ep); + /*clearing TRBERR and EP_STS_DESCMIS before seting DRDY*/ + writel(EP_STS_TRBERR | EP_STS_DESCMIS, &priv_dev->regs->ep_sts); + writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd); + trace_cdns3_doorbell_epx(priv_ep->name, + readl(&priv_dev->regs->ep_traddr)); + } + + /* WORKAROUND for transition to L0 */ + __cdns3_gadget_wakeup(priv_dev); + + return 0; +} + +void cdns3_set_hw_configuration(struct cdns3_device *priv_dev) +{ + struct cdns3_endpoint *priv_ep; + struct usb_ep *ep; + int result = 0; + + if (priv_dev->hw_configured_flag) + return; + + writel(USB_CONF_CFGSET, &priv_dev->regs->usb_conf); + writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); + + cdns3_set_register_bit(&priv_dev->regs->usb_conf, + USB_CONF_U1EN | USB_CONF_U2EN); + + /* wait until configuration set */ + result = cdns3_handshake(&priv_dev->regs->usb_sts, + USB_STS_CFGSTS_MASK, 1, 100); + + priv_dev->hw_configured_flag = 1; + + list_for_each_entry(ep, &priv_dev->gadget.ep_list, ep_list) { + if (ep->enabled) { + priv_ep = ep_to_cdns3_ep(ep); + cdns3_start_all_request(priv_dev, priv_ep); + } + } +} + +/** + * cdns3_request_handled - check whether request has been handled by DMA + * + * @priv_ep: extended endpoint object. + * @priv_req: request object for checking + * + * Endpoint must be selected before invoking this function. + * + * Returns false if request has not been handled by DMA, else returns true. + * + * SR - start ring + * ER - end ring + * DQ = priv_ep->dequeue - dequeue position + * EQ = priv_ep->enqueue - enqueue position + * ST = priv_req->start_trb - index of first TRB in transfer ring + * ET = priv_req->end_trb - index of last TRB in transfer ring + * CI = current_index - index of processed TRB by DMA. + * + * As first step, function checks if cycle bit for priv_req->start_trb is + * correct. + * + * some rules: + * 1. priv_ep->dequeue never exceed current_index. + * 2 priv_ep->enqueue never exceed priv_ep->dequeue + * 3. exception: priv_ep->enqueue == priv_ep->dequeue + * and priv_ep->free_trbs is zero. + * This case indicate that TR is full. + * + * Then We can split recognition into two parts: + * Case 1 - priv_ep->dequeue < current_index + * SR ... EQ ... DQ ... CI ... ER + * SR ... DQ ... CI ... EQ ... ER + * + * Request has been handled by DMA if ST and ET is between DQ and CI. + * + * Case 2 - priv_ep->dequeue > current_index + * This situation take place when CI go through the LINK TRB at the end of + * transfer ring. + * SR ... CI ... EQ ... DQ ... ER + * + * Request has been handled by DMA if ET is less then CI or + * ET is greater or equal DQ. + */ +static bool cdns3_request_handled(struct cdns3_endpoint *priv_ep, + struct cdns3_request *priv_req) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct cdns3_trb *trb = priv_req->trb; + int current_index = 0; + int handled = 0; + int doorbell; + + current_index = cdns3_get_dma_pos(priv_dev, priv_ep); + doorbell = !!(readl(&priv_dev->regs->ep_cmd) & EP_CMD_DRDY); + + trb = &priv_ep->trb_pool[priv_req->start_trb]; + + if ((trb->control & TRB_CYCLE) != priv_ep->ccs) + goto finish; + + if (doorbell == 1 && current_index == priv_ep->dequeue) + goto finish; + + /* The corner case for TRBS_PER_SEGMENT equal 2). */ + if (TRBS_PER_SEGMENT == 2 && priv_ep->type != USB_ENDPOINT_XFER_ISOC) { + handled = 1; + goto finish; + } + + if (priv_ep->enqueue == priv_ep->dequeue && + priv_ep->free_trbs == 0) { + handled = 1; + } else if (priv_ep->dequeue < current_index) { + if ((current_index == (priv_ep->num_trbs - 1)) && + !priv_ep->dequeue) + goto finish; + + if (priv_req->end_trb >= priv_ep->dequeue && + priv_req->end_trb < current_index) + handled = 1; + } else if (priv_ep->dequeue > current_index) { + if (priv_req->end_trb < current_index || + priv_req->end_trb >= priv_ep->dequeue) + handled = 1; + } + +finish: + trace_cdns3_request_handled(priv_req, current_index, handled); + + return handled; +} + +static void cdns3_transfer_completed(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep) +{ + struct cdns3_request *priv_req; + struct usb_request *request; + struct cdns3_trb *trb; + + while (!list_empty(&priv_ep->pending_req_list)) { + request = cdns3_next_request(&priv_ep->pending_req_list); + priv_req = to_cdns3_request(request); + + /* Re-select endpoint. It could be changed by other CPU during + * handling usb_gadget_giveback_request. + */ + cdns3_select_ep(priv_dev, priv_ep->endpoint.address); + + if (!cdns3_request_handled(priv_ep, priv_req)) + goto prepare_next_td; + + trb = priv_ep->trb_pool + priv_ep->dequeue; + trace_cdns3_complete_trb(priv_ep, trb); + + if (trb != priv_req->trb) + dev_warn(priv_dev->dev, + "request_trb=0x%p, queue_trb=0x%p\n", + priv_req->trb, trb); + + request->actual = TRB_LEN(le32_to_cpu(trb->length)); + cdns3_move_deq_to_next_trb(priv_req); + cdns3_gadget_giveback(priv_ep, priv_req, 0); + + if (priv_ep->type != USB_ENDPOINT_XFER_ISOC && + TRBS_PER_SEGMENT == 2) + break; + } + priv_ep->flags &= ~EP_PENDING_REQUEST; + +prepare_next_td: + cdns3_start_all_request(priv_dev, priv_ep); +} + +void cdns3_rearm_transfer(struct cdns3_endpoint *priv_ep, u8 rearm) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + + cdns3_wa1_restore_cycle_bit(priv_ep); + + if (rearm) { + trace_cdns3_ring(priv_ep); + + /* Cycle Bit must be updated before arming DMA. */ + wmb(); + writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd); + + __cdns3_gadget_wakeup(priv_dev); + + trace_cdns3_doorbell_epx(priv_ep->name, + readl(&priv_dev->regs->ep_traddr)); + } +} + +/** + * cdns3_check_ep_interrupt_proceed - Processes interrupt related to endpoint + * @priv_ep: endpoint object + * + * Returns 0 + */ +static int cdns3_check_ep_interrupt_proceed(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + u32 ep_sts_reg; + + cdns3_select_ep(priv_dev, priv_ep->endpoint.address); + + trace_cdns3_epx_irq(priv_dev, priv_ep); + + ep_sts_reg = readl(&priv_dev->regs->ep_sts); + writel(ep_sts_reg, &priv_dev->regs->ep_sts); + + if (ep_sts_reg & EP_STS_TRBERR) { + /* + * For isochronous transfer driver completes request on + * IOC or on TRBERR. IOC appears only when device receive + * OUT data packet. If host disable stream or lost some packet + * then the only way to finish all queued transfer is to do it + * on TRBERR event. + */ + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && + !priv_ep->wa1_set) { + if (!priv_ep->dir) { + u32 ep_cfg = readl(&priv_dev->regs->ep_cfg); + + ep_cfg &= ~EP_CFG_ENABLE; + writel(ep_cfg, &priv_dev->regs->ep_cfg); + priv_ep->flags &= ~EP_QUIRK_ISO_OUT_EN; + } + cdns3_transfer_completed(priv_dev, priv_ep); + } else { + if (priv_ep->flags & EP_DEFERRED_DRDY) { + priv_ep->flags &= ~EP_DEFERRED_DRDY; + cdns3_start_all_request(priv_dev, priv_ep); + } else { + cdns3_rearm_transfer(priv_ep, priv_ep->wa1_set); + } + } + } + + if ((ep_sts_reg & EP_STS_IOC) || (ep_sts_reg & EP_STS_ISP)) + cdns3_transfer_completed(priv_dev, priv_ep); + + return 0; +} + +/** + * cdns3_check_usb_interrupt_proceed - Processes interrupt related to device + * @priv_dev: extended gadget object + * @usb_ists: bitmap representation of device's reported interrupts + * (usb_ists register value) + */ +static void cdns3_check_usb_interrupt_proceed(struct cdns3_device *priv_dev, + u32 usb_ists) +{ + int speed = 0; + + trace_cdns3_usb_irq(priv_dev, usb_ists); + if (usb_ists & USB_ISTS_L1ENTI) { + /* + * WORKAROUND: CDNS3 controller has issue with hardware resuming + * from L1. To fix it, if any DMA transfer is pending driver + * must starts driving resume signal immediately. + */ + if (readl(&priv_dev->regs->drbl)) + __cdns3_gadget_wakeup(priv_dev); + } + + /* Connection detected */ + if (usb_ists & (USB_ISTS_CON2I | USB_ISTS_CONI)) { + speed = cdns3_get_speed(priv_dev); + priv_dev->gadget.speed = speed; + usb_gadget_set_state(&priv_dev->gadget, USB_STATE_POWERED); + cdns3_ep0_config(priv_dev); + } + + /* Disconnection detected */ + if (usb_ists & (USB_ISTS_DIS2I | USB_ISTS_DISI)) { + if (priv_dev->gadget_driver && + priv_dev->gadget_driver->disconnect) { + spin_unlock(&priv_dev->lock); + priv_dev->gadget_driver->disconnect(&priv_dev->gadget); + spin_lock(&priv_dev->lock); + } + + priv_dev->gadget.speed = USB_SPEED_UNKNOWN; + usb_gadget_set_state(&priv_dev->gadget, USB_STATE_NOTATTACHED); + cdns3_hw_reset_eps_config(priv_dev); + } + + if (usb_ists & (USB_ISTS_L2ENTI | USB_ISTS_U3ENTI)) { + if (priv_dev->gadget_driver && + priv_dev->gadget_driver->suspend) { + spin_unlock(&priv_dev->lock); + priv_dev->gadget_driver->suspend(&priv_dev->gadget); + spin_lock(&priv_dev->lock); + } + } + + if (usb_ists & (USB_ISTS_L2EXTI | USB_ISTS_U3EXTI)) { + if (priv_dev->gadget_driver && + priv_dev->gadget_driver->resume) { + spin_unlock(&priv_dev->lock); + priv_dev->gadget_driver->resume(&priv_dev->gadget); + spin_lock(&priv_dev->lock); + } + } + + /* reset*/ + if (usb_ists & (USB_ISTS_UWRESI | USB_ISTS_UHRESI | USB_ISTS_U2RESI)) { + if (priv_dev->gadget_driver) { + spin_unlock(&priv_dev->lock); + usb_gadget_udc_reset(&priv_dev->gadget, + priv_dev->gadget_driver); + spin_lock(&priv_dev->lock); + + /*read again to check the actual speed*/ + speed = cdns3_get_speed(priv_dev); + priv_dev->gadget.speed = speed; + cdns3_hw_reset_eps_config(priv_dev); + cdns3_ep0_config(priv_dev); + } + } +} + +/** + * cdns3_device_irq_handler- interrupt handler for device part of controller + * + * @irq: irq number for cdns3 core device + * @data: structure of cdns3 + * + * Returns IRQ_HANDLED or IRQ_NONE + */ +static irqreturn_t cdns3_device_irq_handler(int irq, void *data) +{ + struct cdns3_device *priv_dev; + struct cdns3 *cdns = data; + irqreturn_t ret = IRQ_NONE; + unsigned long flags; + u32 reg; + + priv_dev = cdns->gadget_dev; + spin_lock_irqsave(&priv_dev->lock, flags); + + /* check USB device interrupt */ + reg = readl(&priv_dev->regs->usb_ists); + + if (reg) { + writel(reg, &priv_dev->regs->usb_ists); + cdns3_check_usb_interrupt_proceed(priv_dev, reg); + ret = IRQ_HANDLED; + } + + /* check endpoint interrupt */ + reg = readl(&priv_dev->regs->ep_ists); + + if (reg) { + priv_dev->shadow_ep_en |= reg; + reg = ~reg & readl(&priv_dev->regs->ep_ien); + /* mask deferred interrupt. */ + writel(reg, &priv_dev->regs->ep_ien); + ret = IRQ_WAKE_THREAD; + } + + spin_unlock_irqrestore(&priv_dev->lock, flags); + return ret; +} + +/** + * cdns3_device_thread_irq_handler- interrupt handler for device part + * of controller + * + * @irq: irq number for cdns3 core device + * @data: structure of cdns3 + * + * Returns IRQ_HANDLED or IRQ_NONE + */ +static irqreturn_t cdns3_device_thread_irq_handler(int irq, void *data) +{ + struct cdns3_device *priv_dev; + struct cdns3 *cdns = data; + irqreturn_t ret = IRQ_NONE; + unsigned long flags; + u32 ep_ien; + int bit; + u32 reg; + + priv_dev = cdns->gadget_dev; + spin_lock_irqsave(&priv_dev->lock, flags); + + reg = readl(&priv_dev->regs->ep_ists); + + /* handle default endpoint OUT */ + if (reg & EP_ISTS_EP_OUT0) { + cdns3_check_ep0_interrupt_proceed(priv_dev, USB_DIR_OUT); + ret = IRQ_HANDLED; + } + + /* handle default endpoint IN */ + if (reg & EP_ISTS_EP_IN0) { + cdns3_check_ep0_interrupt_proceed(priv_dev, USB_DIR_IN); + ret = IRQ_HANDLED; + } + + /* check if interrupt from non default endpoint, if no exit */ + reg &= ~(EP_ISTS_EP_OUT0 | EP_ISTS_EP_IN0); + if (!reg) + goto irqend; + + for_each_set_bit(bit, (unsigned long *)®, + sizeof(u32) * BITS_PER_BYTE) { + priv_dev->shadow_ep_en |= BIT(bit); + cdns3_check_ep_interrupt_proceed(priv_dev->eps[bit]); + ret = IRQ_HANDLED; + } + + if (priv_dev->run_garbage_colector) { + struct cdns3_aligned_buf *buf, *tmp; + + list_for_each_entry_safe(buf, tmp, &priv_dev->aligned_buf_list, + list) { + if (!buf->in_use) { + list_del(&buf->list); + + spin_unlock_irqrestore(&priv_dev->lock, flags); + dma_free_coherent(priv_dev->sysdev, buf->size, + buf->buf, + buf->dma); + spin_lock_irqsave(&priv_dev->lock, flags); + + kfree(buf); + } + } + + priv_dev->run_garbage_colector = 0; + } + +irqend: + ep_ien = readl(&priv_dev->regs->ep_ien) | priv_dev->shadow_ep_en; + priv_dev->shadow_ep_en = 0; + /* Unmask all handled EP interrupts */ + writel(ep_ien, &priv_dev->regs->ep_ien); + spin_unlock_irqrestore(&priv_dev->lock, flags); + return ret; +} + +/** + * cdns3_ep_onchip_buffer_reserve - Try to reserve onchip buf for EP + * + * The real reservation will occur during write to EP_CFG register, + * this function is used to check if the 'size' reservation is allowed. + * + * @priv_dev: extended gadget object + * @size: the size (KB) for EP would like to allocate + * @is_in: endpoint direction + * + * Return 0 if the required size can met or negative value on failure + */ +static int cdns3_ep_onchip_buffer_reserve(struct cdns3_device *priv_dev, + int size, int is_in) +{ + int remained; + + /* 2KB are reserved for EP0*/ + remained = priv_dev->onchip_buffers - priv_dev->onchip_used_size - 2; + + if (is_in) { + if (remained < size) + return -EPERM; + + priv_dev->onchip_used_size += size; + } else { + int required; + + /** + * ALL OUT EPs are shared the same chunk onchip memory, so + * driver checks if it already has assigned enough buffers + */ + if (priv_dev->out_mem_is_allocated >= size) + return 0; + + required = size - priv_dev->out_mem_is_allocated; + + if (required > remained) + return -EPERM; + + priv_dev->out_mem_is_allocated += required; + priv_dev->onchip_used_size += required; + } + + return 0; +} + +void cdns3_configure_dmult(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep) +{ + struct cdns3_usb_regs __iomem *regs = priv_dev->regs; + + /* For dev_ver > DEV_VER_V2 DMULT is configured per endpoint */ + if (priv_dev->dev_ver <= DEV_VER_V2) + writel(USB_CONF_DMULT, ®s->usb_conf); + + if (priv_dev->dev_ver == DEV_VER_V2) + writel(USB_CONF2_EN_TDL_TRB, ®s->usb_conf2); + + if (priv_dev->dev_ver >= DEV_VER_V3 && priv_ep) { + u32 mask; + + if (priv_ep->dir) + mask = BIT(priv_ep->num + 16); + else + mask = BIT(priv_ep->num); + + if (priv_ep->type != USB_ENDPOINT_XFER_ISOC) { + cdns3_set_register_bit(®s->tdl_from_trb, mask); + cdns3_set_register_bit(®s->tdl_beh, mask); + cdns3_set_register_bit(®s->tdl_beh2, mask); + cdns3_set_register_bit(®s->dma_adv_td, mask); + } + + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir) + cdns3_set_register_bit(®s->tdl_from_trb, mask); + + cdns3_set_register_bit(®s->dtrans, mask); + } +} + +/** + * cdns3_ep_config Configure hardware endpoint + * @priv_ep: extended endpoint object + */ +void cdns3_ep_config(struct cdns3_endpoint *priv_ep) +{ + bool is_iso_ep = (priv_ep->type == USB_ENDPOINT_XFER_ISOC); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + u32 bEndpointAddress = priv_ep->num | priv_ep->dir; + u32 max_packet_size = 0; + u8 maxburst = 0; + u32 ep_cfg = 0; + u8 buffering; + u8 mult = 0; + int ret; + + buffering = CDNS3_EP_BUF_SIZE - 1; + + cdns3_configure_dmult(priv_dev, priv_ep); + + switch (priv_ep->type) { + case USB_ENDPOINT_XFER_INT: + ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_INT); + + if ((priv_dev->dev_ver == DEV_VER_V2 && !priv_ep->dir) || + priv_dev->dev_ver > DEV_VER_V2) + ep_cfg |= EP_CFG_TDL_CHK; + break; + case USB_ENDPOINT_XFER_BULK: + ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_BULK); + + if ((priv_dev->dev_ver == DEV_VER_V2 && !priv_ep->dir) || + priv_dev->dev_ver > DEV_VER_V2) + ep_cfg |= EP_CFG_TDL_CHK; + break; + default: + ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_ISOC); + mult = CDNS3_EP_ISO_HS_MULT - 1; + buffering = mult + 1; + } + + switch (priv_dev->gadget.speed) { + case USB_SPEED_FULL: + max_packet_size = is_iso_ep ? 1023 : 64; + break; + case USB_SPEED_HIGH: + max_packet_size = is_iso_ep ? 1024 : 512; + break; + case USB_SPEED_SUPER: + /* It's limitation that driver assumes in driver. */ + mult = 0; + max_packet_size = 1024; + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) { + maxburst = CDNS3_EP_ISO_SS_BURST - 1; + buffering = (mult + 1) * + (maxburst + 1); + + if (priv_ep->interval > 1) + buffering++; + } else { + maxburst = CDNS3_EP_BUF_SIZE - 1; + } + break; + default: + /* all other speed are not supported */ + return; + } + + if (max_packet_size == 1024) + priv_ep->trb_burst_size = 128; + else if (max_packet_size >= 512) + priv_ep->trb_burst_size = 64; + else + priv_ep->trb_burst_size = 16; + + ret = cdns3_ep_onchip_buffer_reserve(priv_dev, buffering + 1, + !!priv_ep->dir); + if (ret) { + dev_err(priv_dev->dev, "onchip mem is full, ep is invalid\n"); + return; + } + + ep_cfg |= EP_CFG_MAXPKTSIZE(max_packet_size) | + EP_CFG_MULT(mult) | + EP_CFG_BUFFERING(buffering) | + EP_CFG_MAXBURST(maxburst); + + cdns3_select_ep(priv_dev, bEndpointAddress); + writel(ep_cfg, &priv_dev->regs->ep_cfg); + + dev_dbg(priv_dev->dev, "Configure %s: with val %08x\n", + priv_ep->name, ep_cfg); +} + +/* Find correct direction for HW endpoint according to description */ +static int cdns3_ep_dir_is_correct(struct usb_endpoint_descriptor *desc, + struct cdns3_endpoint *priv_ep) +{ + return (priv_ep->endpoint.caps.dir_in && usb_endpoint_dir_in(desc)) || + (priv_ep->endpoint.caps.dir_out && usb_endpoint_dir_out(desc)); +} + +static struct +cdns3_endpoint *cdns3_find_available_ep(struct cdns3_device *priv_dev, + struct usb_endpoint_descriptor *desc) +{ + struct usb_ep *ep; + struct cdns3_endpoint *priv_ep; + + list_for_each_entry(ep, &priv_dev->gadget.ep_list, ep_list) { + unsigned long num; + int ret; + /* ep name pattern likes epXin or epXout */ + char c[2] = {ep->name[2], '\0'}; + + ret = kstrtoul(c, 10, &num); + if (ret) + return ERR_PTR(ret); + + priv_ep = ep_to_cdns3_ep(ep); + if (cdns3_ep_dir_is_correct(desc, priv_ep)) { + if (!(priv_ep->flags & EP_CLAIMED)) { + priv_ep->num = num; + return priv_ep; + } + } + } + + return ERR_PTR(-ENOENT); +} + +/* + * Cadence IP has one limitation that all endpoints must be configured + * (Type & MaxPacketSize) before setting configuration through hardware + * register, it means we can't change endpoints configuration after + * set_configuration. + * + * This function set EP_CLAIMED flag which is added when the gadget driver + * uses usb_ep_autoconfig to configure specific endpoint; + * When the udc driver receives set_configurion request, + * it goes through all claimed endpoints, and configure all endpoints + * accordingly. + * + * At usb_ep_ops.enable/disable, we only enable and disable endpoint through + * ep_cfg register which can be changed after set_configuration, and do + * some software operation accordingly. + */ +static struct +usb_ep *cdns3_gadget_match_ep(struct usb_gadget *gadget, + struct usb_endpoint_descriptor *desc, + struct usb_ss_ep_comp_descriptor *comp_desc) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + struct cdns3_endpoint *priv_ep; + unsigned long flags; + + priv_ep = cdns3_find_available_ep(priv_dev, desc); + if (IS_ERR(priv_ep)) { + dev_err(priv_dev->dev, "no available ep\n"); + return NULL; + } + + dev_dbg(priv_dev->dev, "match endpoint: %s\n", priv_ep->name); + + spin_lock_irqsave(&priv_dev->lock, flags); + priv_ep->endpoint.desc = desc; + priv_ep->dir = usb_endpoint_dir_in(desc) ? USB_DIR_IN : USB_DIR_OUT; + priv_ep->type = usb_endpoint_type(desc); + priv_ep->flags |= EP_CLAIMED; + priv_ep->interval = desc->bInterval ? BIT(desc->bInterval - 1) : 0; + + spin_unlock_irqrestore(&priv_dev->lock, flags); + return &priv_ep->endpoint; +} + +/** + * cdns3_gadget_ep_alloc_request Allocates request + * @ep: endpoint object associated with request + * @gfp_flags: gfp flags + * + * Returns allocated request address, NULL on allocation error + */ +struct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep, + gfp_t gfp_flags) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_request *priv_req; + + priv_req = kzalloc(sizeof(*priv_req), gfp_flags); + if (!priv_req) + return NULL; + + priv_req->priv_ep = priv_ep; + + trace_cdns3_alloc_request(priv_req); + return &priv_req->request; +} + +/** + * cdns3_gadget_ep_free_request Free memory occupied by request + * @ep: endpoint object associated with request + * @request: request to free memory + */ +void cdns3_gadget_ep_free_request(struct usb_ep *ep, + struct usb_request *request) +{ + struct cdns3_request *priv_req = to_cdns3_request(request); + + if (priv_req->aligned_buf) + priv_req->aligned_buf->in_use = 0; + + trace_cdns3_free_request(priv_req); + kfree(priv_req); +} + +/** + * cdns3_gadget_ep_enable Enable endpoint + * @ep: endpoint object + * @desc: endpoint descriptor + * + * Returns 0 on success, error code elsewhere + */ +static int cdns3_gadget_ep_enable(struct usb_ep *ep, + const struct usb_endpoint_descriptor *desc) +{ + struct cdns3_endpoint *priv_ep; + struct cdns3_device *priv_dev; + u32 reg = EP_STS_EN_TRBERREN; + u32 bEndpointAddress; + unsigned long flags; + int enable = 1; + int ret; + + priv_ep = ep_to_cdns3_ep(ep); + priv_dev = priv_ep->cdns3_dev; + + if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { + dev_dbg(priv_dev->dev, "usbss: invalid parameters\n"); + return -EINVAL; + } + + if (!desc->wMaxPacketSize) { + dev_err(priv_dev->dev, "usbss: missing wMaxPacketSize\n"); + return -EINVAL; + } + + if (dev_WARN_ONCE(priv_dev->dev, priv_ep->flags & EP_ENABLED, + "%s is already enabled\n", priv_ep->name)) + return 0; + + spin_lock_irqsave(&priv_dev->lock, flags); + + priv_ep->endpoint.desc = desc; + priv_ep->type = usb_endpoint_type(desc); + priv_ep->interval = desc->bInterval ? BIT(desc->bInterval - 1) : 0; + + if (priv_ep->interval > ISO_MAX_INTERVAL && + priv_ep->type == USB_ENDPOINT_XFER_ISOC) { + dev_err(priv_dev->dev, "Driver is limited to %d period\n", + ISO_MAX_INTERVAL); + + ret = -EINVAL; + goto exit; + } + + ret = cdns3_allocate_trb_pool(priv_ep); + + if (ret) + goto exit; + + bEndpointAddress = priv_ep->num | priv_ep->dir; + cdns3_select_ep(priv_dev, bEndpointAddress); + + trace_cdns3_gadget_ep_enable(priv_ep); + + writel(EP_CMD_EPRST, &priv_dev->regs->ep_cmd); + + ret = cdns3_handshake(&priv_dev->regs->ep_cmd, + EP_CMD_CSTALL | EP_CMD_EPRST, 0, 1000); + + if (unlikely(ret)) { + cdns3_free_trb_pool(priv_ep); + ret = -EINVAL; + goto exit; + } + + /* enable interrupt for selected endpoint */ + cdns3_set_register_bit(&priv_dev->regs->ep_ien, + BIT(cdns3_ep_addr_to_index(bEndpointAddress))); + + writel(reg, &priv_dev->regs->ep_sts_en); + + /* + * For some versions of controller at some point during ISO OUT traffic + * DMA reads Transfer Ring for the EP which has never got doorbell. + * This issue was detected only on simulation, but to avoid this issue + * driver add protection against it. To fix it driver enable ISO OUT + * endpoint before setting DRBL. This special treatment of ISO OUT + * endpoints are recommended by controller specification. + */ + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir) + enable = 0; + + if (enable) + cdns3_set_register_bit(&priv_dev->regs->ep_cfg, EP_CFG_ENABLE); + + ep->desc = desc; + priv_ep->flags &= ~(EP_PENDING_REQUEST | EP_STALL | + EP_QUIRK_ISO_OUT_EN); + priv_ep->flags |= EP_ENABLED | EP_UPDATE_EP_TRBADDR; + priv_ep->wa1_set = 0; + priv_ep->enqueue = 0; + priv_ep->dequeue = 0; + reg = readl(&priv_dev->regs->ep_sts); + priv_ep->pcs = !!EP_STS_CCS(reg); + priv_ep->ccs = !!EP_STS_CCS(reg); + /* one TRB is reserved for link TRB used in DMULT mode*/ + priv_ep->free_trbs = priv_ep->num_trbs - 1; +exit: + spin_unlock_irqrestore(&priv_dev->lock, flags); + + return ret; +} + +/** + * cdns3_gadget_ep_disable Disable endpoint + * @ep: endpoint object + * + * Returns 0 on success, error code elsewhere + */ +static int cdns3_gadget_ep_disable(struct usb_ep *ep) +{ + struct cdns3_endpoint *priv_ep; + struct cdns3_device *priv_dev; + struct usb_request *request; + unsigned long flags; + int ret = 0; + u32 ep_cfg; + + if (!ep) { + pr_err("usbss: invalid parameters\n"); + return -EINVAL; + } + + priv_ep = ep_to_cdns3_ep(ep); + priv_dev = priv_ep->cdns3_dev; + + if (dev_WARN_ONCE(priv_dev->dev, !(priv_ep->flags & EP_ENABLED), + "%s is already disabled\n", priv_ep->name)) + return 0; + + spin_lock_irqsave(&priv_dev->lock, flags); + + trace_cdns3_gadget_ep_disable(priv_ep); + + cdns3_select_ep(priv_dev, ep->desc->bEndpointAddress); + + ep_cfg = readl(&priv_dev->regs->ep_cfg); + ep_cfg &= ~EP_CFG_ENABLE; + writel(ep_cfg, &priv_dev->regs->ep_cfg); + + /** + * Driver needs some time before resetting endpoint. + * It need waits for clearing DBUSY bit or for timeout expired. + * 10us is enough time for controller to stop transfer. + */ + cdns3_handshake(&priv_dev->regs->ep_sts, + EP_STS_DBUSY, 0, 10); + + writel(EP_CMD_EPRST, &priv_dev->regs->ep_cmd); + + ret = cdns3_handshake(&priv_dev->regs->ep_cmd, + EP_CMD_CSTALL | EP_CMD_EPRST, 0, 1000); + + if (unlikely(ret)) + dev_err(priv_dev->dev, "Timeout: %s resetting failed.\n", + priv_ep->name); + + while (!list_empty(&priv_ep->pending_req_list)) { + request = cdns3_next_request(&priv_ep->pending_req_list); + + cdns3_gadget_giveback(priv_ep, to_cdns3_request(request), + -ESHUTDOWN); + } + + while (!list_empty(&priv_ep->deferred_req_list)) { + request = cdns3_next_request(&priv_ep->deferred_req_list); + + cdns3_gadget_giveback(priv_ep, to_cdns3_request(request), + -ESHUTDOWN); + } + + ep->desc = NULL; + priv_ep->flags &= ~EP_ENABLED; + + spin_unlock_irqrestore(&priv_dev->lock, flags); + + return ret; +} + +/** + * cdns3_gadget_ep_queue Transfer data on endpoint + * @ep: endpoint object + * @request: request object + * @gfp_flags: gfp flags + * + * Returns 0 on success, error code elsewhere + */ +static int __cdns3_gadget_ep_queue(struct usb_ep *ep, + struct usb_request *request, + gfp_t gfp_flags) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct cdns3_request *priv_req; + int ret = 0; + + request->actual = 0; + request->status = -EINPROGRESS; + priv_req = to_cdns3_request(request); + trace_cdns3_ep_queue(priv_req); + + ret = cdns3_prepare_aligned_request_buf(priv_req); + if (ret < 0) + return ret; + + ret = usb_gadget_map_request_by_dev(priv_dev->sysdev, request, + usb_endpoint_dir_in(ep->desc)); + if (ret) + return ret; + + list_add_tail(&request->list, &priv_ep->deferred_req_list); + + /* + * If hardware endpoint configuration has not been set yet then + * just queue request in deferred list. Transfer will be started in + * cdns3_set_hw_configuration. + */ + if (priv_dev->hw_configured_flag) + cdns3_start_all_request(priv_dev, priv_ep); + + return 0; +} + +static int cdns3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, + gfp_t gfp_flags) +{ + struct usb_request *zlp_request; + struct cdns3_endpoint *priv_ep; + struct cdns3_device *priv_dev; + unsigned long flags; + int ret; + + if (!request || !ep) + return -EINVAL; + + priv_ep = ep_to_cdns3_ep(ep); + priv_dev = priv_ep->cdns3_dev; + + spin_lock_irqsave(&priv_dev->lock, flags); + + ret = __cdns3_gadget_ep_queue(ep, request, gfp_flags); + + if (ret == 0 && request->zero && request->length && + (request->length % ep->maxpacket == 0)) { + struct cdns3_request *priv_req; + + zlp_request = cdns3_gadget_ep_alloc_request(ep, GFP_ATOMIC); + zlp_request->buf = priv_dev->zlp_buf; + zlp_request->length = 0; + + priv_req = to_cdns3_request(zlp_request); + priv_req->flags |= REQUEST_ZLP; + + dev_dbg(priv_dev->dev, "Queuing ZLP for endpoint: %s\n", + priv_ep->name); + ret = __cdns3_gadget_ep_queue(ep, zlp_request, gfp_flags); + } + + spin_unlock_irqrestore(&priv_dev->lock, flags); + return ret; +} + +/** + * cdns3_gadget_ep_dequeue Remove request from transfer queue + * @ep: endpoint object associated with request + * @request: request object + * + * Returns 0 on success, error code elsewhere + */ +int cdns3_gadget_ep_dequeue(struct usb_ep *ep, + struct usb_request *request) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct usb_request *req, *req_temp; + struct cdns3_request *priv_req; + struct cdns3_trb *link_trb; + unsigned long flags; + int ret = 0; + + if (!ep || !request || !ep->desc) + return -EINVAL; + + spin_lock_irqsave(&priv_dev->lock, flags); + + priv_req = to_cdns3_request(request); + + trace_cdns3_ep_dequeue(priv_req); + + cdns3_select_ep(priv_dev, ep->desc->bEndpointAddress); + + list_for_each_entry_safe(req, req_temp, &priv_ep->pending_req_list, + list) { + if (request == req) + goto found; + } + + list_for_each_entry_safe(req, req_temp, &priv_ep->deferred_req_list, + list) { + if (request == req) + goto found; + } + + goto not_found; + +found: + + if (priv_ep->wa1_trb == priv_req->trb) + cdns3_wa1_restore_cycle_bit(priv_ep); + + link_trb = priv_req->trb; + cdns3_move_deq_to_next_trb(priv_req); + cdns3_gadget_giveback(priv_ep, priv_req, -ECONNRESET); + + /* Update ring */ + request = cdns3_next_request(&priv_ep->deferred_req_list); + if (request) { + priv_req = to_cdns3_request(request); + + link_trb->buffer = TRB_BUFFER(priv_ep->trb_pool_dma + + (priv_req->start_trb * TRB_SIZE)); + link_trb->control = (link_trb->control & TRB_CYCLE) | + TRB_TYPE(TRB_LINK) | TRB_CHAIN | TRB_TOGGLE; + } else { + priv_ep->flags |= EP_UPDATE_EP_TRBADDR; + } + +not_found: + spin_unlock_irqrestore(&priv_dev->lock, flags); + return ret; +} + +/** + * cdns3_gadget_ep_set_halt Sets/clears stall on selected endpoint + * @ep: endpoint object to set/clear stall on + * @value: 1 for set stall, 0 for clear stall + * + * Returns 0 on success, error code elsewhere + */ +int cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + unsigned long flags; + int ret = 0; + + if (!(priv_ep->flags & EP_ENABLED)) + return -EPERM; + + spin_lock_irqsave(&priv_dev->lock, flags); + + cdns3_select_ep(priv_dev, ep->desc->bEndpointAddress); + if (value) { + cdns3_ep_stall_flush(priv_ep); + } else { + priv_ep->flags &= ~EP_WEDGE; + + cdns3_dbg(priv_ep->cdns3_dev, "Clear stalled endpoint %s\n", + priv_ep->name); + + writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd); + + /* wait for EPRST cleared */ + ret = cdns3_handshake(&priv_dev->regs->ep_cmd, + EP_CMD_EPRST, 0, 100); + if (unlikely(ret)) { + dev_err(priv_dev->dev, + "Clearing halt condition failed for %s\n", + priv_ep->name); + goto finish; + + } else { + priv_ep->flags &= ~EP_STALL; + } + } + + priv_ep->flags &= ~EP_PENDING_REQUEST; +finish: + spin_unlock_irqrestore(&priv_dev->lock, flags); + + return ret; +} + +extern const struct usb_ep_ops cdns3_gadget_ep0_ops; + +static const struct usb_ep_ops cdns3_gadget_ep_ops = { + .enable = cdns3_gadget_ep_enable, + .disable = cdns3_gadget_ep_disable, + .alloc_request = cdns3_gadget_ep_alloc_request, + .free_request = cdns3_gadget_ep_free_request, + .queue = cdns3_gadget_ep_queue, + .dequeue = cdns3_gadget_ep_dequeue, + .set_halt = cdns3_gadget_ep_set_halt, + .set_wedge = cdns3_gadget_ep_set_wedge, +}; + +/** + * cdns3_gadget_get_frame Returns number of actual ITP frame + * @gadget: gadget object + * + * Returns number of actual ITP frame + */ +static int cdns3_gadget_get_frame(struct usb_gadget *gadget) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + + return readl(&priv_dev->regs->usb_itpn); +} + +int __cdns3_gadget_wakeup(struct cdns3_device *priv_dev) +{ + enum usb_device_speed speed; + + speed = cdns3_get_speed(priv_dev); + + if (speed >= USB_SPEED_SUPER) + return 0; + + /* Start driving resume signaling to indicate remote wakeup. */ + writel(USB_CONF_LGO_L0, &priv_dev->regs->usb_conf); + + return 0; +} + +static int cdns3_gadget_wakeup(struct usb_gadget *gadget) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&priv_dev->lock, flags); + ret = __cdns3_gadget_wakeup(priv_dev); + spin_unlock_irqrestore(&priv_dev->lock, flags); + return ret; +} + +static int cdns3_gadget_set_selfpowered(struct usb_gadget *gadget, + int is_selfpowered) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + unsigned long flags; + + spin_lock_irqsave(&priv_dev->lock, flags); + priv_dev->is_selfpowered = !!is_selfpowered; + spin_unlock_irqrestore(&priv_dev->lock, flags); + return 0; +} + +static int cdns3_gadget_pullup(struct usb_gadget *gadget, int is_on) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + + if (is_on) + writel(USB_CONF_DEVEN, &priv_dev->regs->usb_conf); + else + writel(USB_CONF_DEVDS, &priv_dev->regs->usb_conf); + + return 0; +} + +static void cdns3_gadget_config(struct cdns3_device *priv_dev) +{ + struct cdns3_usb_regs __iomem *regs = priv_dev->regs; + u32 reg; + + cdns3_ep0_config(priv_dev); + + /* enable interrupts for endpoint 0 (in and out) */ + writel(EP_IEN_EP_OUT0 | EP_IEN_EP_IN0, ®s->ep_ien); + + /* + *Driver need modify LFPS minimal U1 Exit time for 0x00024505 revision + * of controller + */ + if (priv_dev->dev_ver == DEV_VER_TI_V1) { + reg = readl(®s->dbg_link1); + + reg &= ~DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_MASK; + reg |= DBG_LINK1_LFPS_MIN_GEN_U1_EXIT(0x55) | + DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_SET; + writel(reg, ®s->dbg_link1); + } + + /* + * By default some platforms has set protected access to memory. + * This cause problem with cache, so driver restore non-secure + * access to memory. + */ + reg = readl(®s->dma_axi_ctrl); + reg = DMA_AXI_CTRL_MARPROT(DMA_AXI_CTRL_NON_SECURE) | + DMA_AXI_CTRL_MAWPROT(DMA_AXI_CTRL_NON_SECURE); + writel(reg, ®s->dma_axi_ctrl); + + /* enable generic interrupt*/ + writel(USB_IEN_INIT, ®s->usb_ien); + writel(USB_CONF_CLK2OFFDS | USB_CONF_L1DS, ®s->usb_conf); + + cdns3_configure_dmult(priv_dev, NULL); + + cdns3_gadget_pullup(&priv_dev->gadget, 1); +} + +/** + * cdns3_gadget_udc_start Gadget start + * @gadget: gadget object + * @driver: driver which operates on this gadget + * + * Returns 0 on success, error code elsewhere + */ +static int cdns3_gadget_udc_start(struct usb_gadget *gadget, + struct usb_gadget_driver *driver) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + unsigned long flags; + + spin_lock_irqsave(&priv_dev->lock, flags); + priv_dev->gadget_driver = driver; + cdns3_gadget_config(priv_dev); + spin_unlock_irqrestore(&priv_dev->lock, flags); + return 0; +} + +/** + * cdns3_gadget_udc_stop Stops gadget + * @gadget: gadget object + * + * Returns 0 + */ +static int cdns3_gadget_udc_stop(struct usb_gadget *gadget) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + struct cdns3_endpoint *priv_ep; + u32 bEndpointAddress; + struct usb_ep *ep; + int ret = 0; + + priv_dev->gadget_driver = NULL; + + priv_dev->onchip_used_size = 0; + priv_dev->out_mem_is_allocated = 0; + priv_dev->gadget.speed = USB_SPEED_UNKNOWN; + + list_for_each_entry(ep, &priv_dev->gadget.ep_list, ep_list) { + priv_ep = ep_to_cdns3_ep(ep); + bEndpointAddress = priv_ep->num | priv_ep->dir; + cdns3_select_ep(priv_dev, bEndpointAddress); + writel(EP_CMD_EPRST, &priv_dev->regs->ep_cmd); + ret = cdns3_handshake(&priv_dev->regs->ep_cmd, + EP_CMD_EPRST, 0, 100); + cdns3_free_trb_pool(priv_ep); + } + + /* disable interrupt for device */ + writel(0, &priv_dev->regs->usb_ien); + writel(USB_CONF_DEVDS, &priv_dev->regs->usb_conf); + + return ret; +} + +static const struct usb_gadget_ops cdns3_gadget_ops = { + .get_frame = cdns3_gadget_get_frame, + .wakeup = cdns3_gadget_wakeup, + .set_selfpowered = cdns3_gadget_set_selfpowered, + .pullup = cdns3_gadget_pullup, + .udc_start = cdns3_gadget_udc_start, + .udc_stop = cdns3_gadget_udc_stop, + .match_ep = cdns3_gadget_match_ep, +}; + +static void cdns3_free_all_eps(struct cdns3_device *priv_dev) +{ + int i; + + /*ep0 OUT point to ep0 IN*/ + priv_dev->eps[16] = NULL; + + cdns3_free_trb_pool(priv_dev->eps[0]); + + for (i = 0; i < CDNS3_ENDPOINTS_MAX_COUNT; i++) + if (priv_dev->eps[i]) + devm_kfree(priv_dev->dev, priv_dev->eps[i]); +} + +/** + * cdns3_init_eps Initializes software endpoints of gadget + * @cdns3: extended gadget object + * + * Returns 0 on success, error code elsewhere + */ +static int cdns3_init_eps(struct cdns3_device *priv_dev) +{ + u32 ep_enabled_reg, iso_ep_reg; + struct cdns3_endpoint *priv_ep; + int ep_dir, ep_number; + u32 ep_mask; + int ret = 0; + int i; + + /* Read it from USB_CAP3 to USB_CAP5 */ + ep_enabled_reg = readl(&priv_dev->regs->usb_cap3); + iso_ep_reg = readl(&priv_dev->regs->usb_cap4); + + dev_dbg(priv_dev->dev, "Initializing non-zero endpoints\n"); + + for (i = 0; i < CDNS3_ENDPOINTS_MAX_COUNT; i++) { + ep_dir = i >> 4; /* i div 16 */ + ep_number = i & 0xF; /* i % 16 */ + ep_mask = BIT(i); + + if (!(ep_enabled_reg & ep_mask)) + continue; + + if (ep_dir && !ep_number) { + priv_dev->eps[i] = priv_dev->eps[0]; + continue; + } + + priv_ep = devm_kzalloc(priv_dev->dev, sizeof(*priv_ep), + GFP_KERNEL); + if (!priv_ep) { + ret = -ENOMEM; + goto err; + } + + /* set parent of endpoint object */ + priv_ep->cdns3_dev = priv_dev; + priv_dev->eps[i] = priv_ep; + priv_ep->num = ep_number; + priv_ep->dir = ep_dir ? USB_DIR_IN : USB_DIR_OUT; + + if (!ep_number) { + ret = cdns3_init_ep0(priv_dev, priv_ep); + if (ret) { + dev_err(priv_dev->dev, "Failed to init ep0\n"); + goto err; + } + } else { + snprintf(priv_ep->name, sizeof(priv_ep->name), "ep%d%s", + ep_number, !!ep_dir ? "in" : "out"); + priv_ep->endpoint.name = priv_ep->name; + + usb_ep_set_maxpacket_limit(&priv_ep->endpoint, + CDNS3_EP_MAX_PACKET_LIMIT); + priv_ep->endpoint.max_streams = CDNS3_EP_MAX_STREAMS; + priv_ep->endpoint.ops = &cdns3_gadget_ep_ops; + if (ep_dir) + priv_ep->endpoint.caps.dir_in = 1; + else + priv_ep->endpoint.caps.dir_out = 1; + + if (iso_ep_reg & ep_mask) + priv_ep->endpoint.caps.type_iso = 1; + + priv_ep->endpoint.caps.type_bulk = 1; + priv_ep->endpoint.caps.type_int = 1; + + list_add_tail(&priv_ep->endpoint.ep_list, + &priv_dev->gadget.ep_list); + } + + priv_ep->flags = 0; + + dev_info(priv_dev->dev, "Initialized %s support: %s %s\n", + priv_ep->name, + priv_ep->endpoint.caps.type_bulk ? "BULK, INT" : "", + priv_ep->endpoint.caps.type_iso ? "ISO" : ""); + + INIT_LIST_HEAD(&priv_ep->pending_req_list); + INIT_LIST_HEAD(&priv_ep->deferred_req_list); + } + + return 0; +err: + cdns3_free_all_eps(priv_dev); + return -ENOMEM; +} + +void cdns3_gadget_exit(struct cdns3 *cdns) +{ + struct cdns3_device *priv_dev; + + priv_dev = cdns->gadget_dev; + + devm_free_irq(cdns->dev, cdns->dev_irq, cdns); + + pm_runtime_mark_last_busy(cdns->dev); + pm_runtime_put_autosuspend(cdns->dev); + + usb_del_gadget_udc(&priv_dev->gadget); + + cdns3_free_all_eps(priv_dev); + + while (!list_empty(&priv_dev->aligned_buf_list)) { + struct cdns3_aligned_buf *buf; + + buf = cdns3_next_align_buf(&priv_dev->aligned_buf_list); + dma_free_coherent(priv_dev->sysdev, buf->size, + buf->buf, + buf->dma); + + list_del(&buf->list); + kfree(buf); + } + + dma_free_coherent(priv_dev->sysdev, 8, priv_dev->setup_buf, + priv_dev->setup_dma); + + kfree(priv_dev->zlp_buf); + kfree(priv_dev); + cdns->gadget_dev = NULL; + cdns3_drd_switch_gadget(cdns, 0); +} + +static int cdns3_gadget_start(struct cdns3 *cdns) +{ + struct cdns3_device *priv_dev; + u32 max_speed; + int ret; + + priv_dev = kzalloc(sizeof(*priv_dev), GFP_KERNEL); + if (!priv_dev) + return -ENOMEM; + + cdns->gadget_dev = priv_dev; + priv_dev->sysdev = cdns->dev; + priv_dev->dev = cdns->dev; + priv_dev->regs = cdns->dev_regs; + + device_property_read_u16(priv_dev->dev, "cdns,on-chip-buff-size", + &priv_dev->onchip_buffers); + + if (priv_dev->onchip_buffers <= 0) { + u32 reg = readl(&priv_dev->regs->usb_cap2); + + priv_dev->onchip_buffers = USB_CAP2_ACTUAL_MEM_SIZE(reg); + } + + if (!priv_dev->onchip_buffers) + priv_dev->onchip_buffers = 256; + + max_speed = usb_get_maximum_speed(cdns->dev); + + /* Check the maximum_speed parameter */ + switch (max_speed) { + case USB_SPEED_FULL: + case USB_SPEED_HIGH: + case USB_SPEED_SUPER: + break; + default: + dev_err(cdns->dev, "invalid maximum_speed parameter %d\n", + max_speed); + /* fall through */ + case USB_SPEED_UNKNOWN: + /* default to superspeed */ + max_speed = USB_SPEED_SUPER; + break; + } + + /* fill gadget fields */ + priv_dev->gadget.max_speed = max_speed; + priv_dev->gadget.speed = USB_SPEED_UNKNOWN; + priv_dev->gadget.ops = &cdns3_gadget_ops; + priv_dev->gadget.name = "usb-ss-gadget"; + priv_dev->gadget.sg_supported = 1; + + spin_lock_init(&priv_dev->lock); + INIT_WORK(&priv_dev->pending_status_wq, + cdns3_pending_setup_status_handler); + + /* initialize endpoint container */ + INIT_LIST_HEAD(&priv_dev->gadget.ep_list); + INIT_LIST_HEAD(&priv_dev->aligned_buf_list); + + ret = cdns3_init_eps(priv_dev); + if (ret) { + dev_err(priv_dev->dev, "Failed to create endpoints\n"); + goto err1; + } + + /* allocate memory for setup packet buffer */ + priv_dev->setup_buf = dma_alloc_coherent(priv_dev->sysdev, 8, + &priv_dev->setup_dma, GFP_DMA); + if (!priv_dev->setup_buf) { + ret = -ENOMEM; + goto err2; + } + + priv_dev->dev_ver = readl(&priv_dev->regs->usb_cap6); + + dev_dbg(priv_dev->dev, "Device Controller version: %08x\n", + readl(&priv_dev->regs->usb_cap6)); + dev_dbg(priv_dev->dev, "USB Capabilities:: %08x\n", + readl(&priv_dev->regs->usb_cap1)); + dev_dbg(priv_dev->dev, "On-Chip memory cnfiguration: %08x\n", + readl(&priv_dev->regs->usb_cap2)); + + priv_dev->dev_ver = GET_DEV_BASE_VERSION(priv_dev->dev_ver); + + priv_dev->zlp_buf = kzalloc(CDNS3_EP_ZLP_BUF_SIZE, GFP_KERNEL); + if (!priv_dev->zlp_buf) { + ret = -ENOMEM; + goto err3; + } + + /* add USB gadget device */ + ret = usb_add_gadget_udc(priv_dev->dev, &priv_dev->gadget); + if (ret < 0) { + dev_err(priv_dev->dev, + "Failed to register USB device controller\n"); + goto err4; + } + + return 0; +err4: + kfree(priv_dev->zlp_buf); +err3: + dma_free_coherent(priv_dev->sysdev, 8, priv_dev->setup_buf, + priv_dev->setup_dma); +err2: + cdns3_free_all_eps(priv_dev); +err1: + cdns->gadget_dev = NULL; + return ret; +} + +static int __cdns3_gadget_init(struct cdns3 *cdns) +{ + struct cdns3_device *priv_dev; + int ret = 0; + + cdns3_drd_switch_gadget(cdns, 1); + pm_runtime_get_sync(cdns->dev); + + ret = cdns3_gadget_start(cdns); + if (ret) + return ret; + + priv_dev = cdns->gadget_dev; + ret = devm_request_threaded_irq(cdns->dev, cdns->dev_irq, + cdns3_device_irq_handler, + cdns3_device_thread_irq_handler, + IRQF_SHARED, dev_name(cdns->dev), cdns); + + if (ret) + goto err0; + + return 0; +err0: + cdns3_gadget_exit(cdns); + return ret; +} + +static int cdns3_gadget_suspend(struct cdns3 *cdns, bool do_wakeup) +{ + cdns3_gadget_exit(cdns); + return 0; +} + +static int cdns3_gadget_resume(struct cdns3 *cdns, bool hibernated) +{ + return cdns3_gadget_start(cdns); +} + +/** + * cdns3_gadget_init - initialize device structure + * + * cdns: cdns3 instance + * + * This function initializes the gadget. + */ +int cdns3_gadget_init(struct cdns3 *cdns) +{ + struct cdns3_role_driver *rdrv; + + rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); + if (!rdrv) + return -ENOMEM; + + rdrv->start = __cdns3_gadget_init; + rdrv->stop = cdns3_gadget_exit; + rdrv->suspend = cdns3_gadget_suspend; + rdrv->resume = cdns3_gadget_resume; + rdrv->state = CDNS3_ROLE_STATE_INACTIVE; + rdrv->name = "gadget"; + cdns->roles[CDNS3_ROLE_GADGET] = rdrv; + + return 0; +} diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h new file mode 100644 index 000000000000..64cead1aee32 --- /dev/null +++ b/drivers/usb/cdns3/gadget.h @@ -0,0 +1,1321 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * USBSS device controller driver header file + * + * Copyright (C) 2018-2019 Cadence. + * Copyright (C) 2017-2018 NXP + * + * Author: Pawel Laszczak + * Pawel Jez + * Peter Chen + */ +#ifndef __LINUX_CDNS3_GADGET +#define __LINUX_CDNS3_GADGET +#include + +/* + * USBSS-DEV register interface. + * This corresponds to the USBSS Device Controller Interface + */ + +/** + * struct cdns3_usb_regs - device controller registers. + * @usb_conf: Global Configuration Register. + * @usb_sts: Global Status Register. + * @usb_cmd: Global Command Register. + * @usb_itpn: ITP/SOF number Register. + * @usb_lpm: Global Command Register. + * @usb_ien: USB Interrupt Enable Register. + * @usb_ists: USB Interrupt Status Register. + * @ep_sel: Endpoint Select Register. + * @ep_traddr: Endpoint Transfer Ring Address Register. + * @ep_cfg: Endpoint Configuration Register. + * @ep_cmd: Endpoint Command Register. + * @ep_sts: Endpoint Status Register. + * @ep_sts_sid: Endpoint Status Register. + * @ep_sts_en: Endpoint Status Register Enable. + * @drbl: Doorbell Register. + * @ep_ien: EP Interrupt Enable Register. + * @ep_ists: EP Interrupt Status Register. + * @usb_pwr: Global Power Configuration Register. + * @usb_conf2: Global Configuration Register 2. + * @usb_cap1: Capability Register 1. + * @usb_cap2: Capability Register 2. + * @usb_cap3: Capability Register 3. + * @usb_cap4: Capability Register 4. + * @usb_cap5: Capability Register 5. + * @usb_cap6: Capability Register 6. + * @usb_cpkt1: Custom Packet Register 1. + * @usb_cpkt2: Custom Packet Register 2. + * @usb_cpkt3: Custom Packet Register 3. + * @ep_dma_ext_addr: Upper address for DMA operations Register. + * @buf_addr: Address for On-chip Buffer operations Register. + * @buf_data: Data for On-chip Buffer operations Register. + * @buf_ctrl: On-chip Buffer Access Control Registe. + * @dtrans: DMA Transfer Mode Register. + * @tdl_from_trb: Source of TD Configuration Register. + * @tdl_beh: TDL Behavior Configuration Register. + * @ep_tdl: Endpoint TDL Register. + * @tdl_beh2: TDL Behavior 2 Configuration Register. + * @dma_adv_td: DMA Advance TD Configuration Register. + * @reserved1: Reserved. + * @cfg_regs: Configuration registers. + * @reserved2: Reserved. + * @dma_axi_ctrl: AXI Control register. + * @dma_axi_id: AXI ID register. + * @dma_axi_cap: AXI Capability register. + * @dma_axi_ctrl0: AXI Control 0 register. + * @dma_axi_ctrl1: AXI Control 1 register. + */ +struct cdns3_usb_regs { + __le32 usb_conf; + __le32 usb_sts; + __le32 usb_cmd; + __le32 usb_itpn; + __le32 usb_lpm; + __le32 usb_ien; + __le32 usb_ists; + __le32 ep_sel; + __le32 ep_traddr; + __le32 ep_cfg; + __le32 ep_cmd; + __le32 ep_sts; + __le32 ep_sts_sid; + __le32 ep_sts_en; + __le32 drbl; + __le32 ep_ien; + __le32 ep_ists; + __le32 usb_pwr; + __le32 usb_conf2; + __le32 usb_cap1; + __le32 usb_cap2; + __le32 usb_cap3; + __le32 usb_cap4; + __le32 usb_cap5; + __le32 usb_cap6; + __le32 usb_cpkt1; + __le32 usb_cpkt2; + __le32 usb_cpkt3; + __le32 ep_dma_ext_addr; + __le32 buf_addr; + __le32 buf_data; + __le32 buf_ctrl; + __le32 dtrans; + __le32 tdl_from_trb; + __le32 tdl_beh; + __le32 ep_tdl; + __le32 tdl_beh2; + __le32 dma_adv_td; + __le32 reserved1[26]; + __le32 cfg_reg1; + __le32 dbg_link1; + __le32 dbg_link2; + __le32 cfg_regs[74]; + __le32 reserved2[34]; + __le32 dma_axi_ctrl; + __le32 dma_axi_id; + __le32 dma_axi_cap; + __le32 dma_axi_ctrl0; + __le32 dma_axi_ctrl1; +}; + +/* USB_CONF - bitmasks */ +/* Reset USB device configuration. */ +#define USB_CONF_CFGRST BIT(0) +/* Set Configuration. */ +#define USB_CONF_CFGSET BIT(1) +/* Disconnect USB device in SuperSpeed. */ +#define USB_CONF_USB3DIS BIT(3) +/* Disconnect USB device in HS/FS */ +#define USB_CONF_USB2DIS BIT(4) +/* Little Endian access - default */ +#define USB_CONF_LENDIAN BIT(5) +/* + * Big Endian access. Driver assume that byte order for + * SFRs access always is as Little Endian so this bit + * is not used. + */ +#define USB_CONF_BENDIAN BIT(6) +/* Device software reset. */ +#define USB_CONF_SWRST BIT(7) +/* Singular DMA transfer mode. Only for VER < DEV_VER_V3*/ +#define USB_CONF_DSING BIT(8) +/* Multiple DMA transfers mode. Only for VER < DEV_VER_V3 */ +#define USB_CONF_DMULT BIT(9) +/* DMA clock turn-off enable. */ +#define USB_CONF_DMAOFFEN BIT(10) +/* DMA clock turn-off disable. */ +#define USB_CONF_DMAOFFDS BIT(11) +/* Clear Force Full Speed. */ +#define USB_CONF_CFORCE_FS BIT(12) +/* Set Force Full Speed. */ +#define USB_CONF_SFORCE_FS BIT(13) +/* Device enable. */ +#define USB_CONF_DEVEN BIT(14) +/* Device disable. */ +#define USB_CONF_DEVDS BIT(15) +/* L1 LPM state entry enable (used in HS/FS mode). */ +#define USB_CONF_L1EN BIT(16) +/* L1 LPM state entry disable (used in HS/FS mode). */ +#define USB_CONF_L1DS BIT(17) +/* USB 2.0 clock gate disable. */ +#define USB_CONF_CLK2OFFEN BIT(18) +/* USB 2.0 clock gate enable. */ +#define USB_CONF_CLK2OFFDS BIT(19) +/* L0 LPM state entry request (used in HS/FS mode). */ +#define USB_CONF_LGO_L0 BIT(20) +/* USB 3.0 clock gate disable. */ +#define USB_CONF_CLK3OFFEN BIT(21) +/* USB 3.0 clock gate enable. */ +#define USB_CONF_CLK3OFFDS BIT(22) +/* Bit 23 is reserved*/ +/* U1 state entry enable (used in SS mode). */ +#define USB_CONF_U1EN BIT(24) +/* U1 state entry disable (used in SS mode). */ +#define USB_CONF_U1DS BIT(25) +/* U2 state entry enable (used in SS mode). */ +#define USB_CONF_U2EN BIT(26) +/* U2 state entry disable (used in SS mode). */ +#define USB_CONF_U2DS BIT(27) +/* U0 state entry request (used in SS mode). */ +#define USB_CONF_LGO_U0 BIT(28) +/* U1 state entry request (used in SS mode). */ +#define USB_CONF_LGO_U1 BIT(29) +/* U2 state entry request (used in SS mode). */ +#define USB_CONF_LGO_U2 BIT(30) +/* SS.Inactive state entry request (used in SS mode) */ +#define USB_CONF_LGO_SSINACT BIT(31) + +/* USB_STS - bitmasks */ +/* + * Configuration status. + * 1 - device is in the configured state. + * 0 - device is not configured. + */ +#define USB_STS_CFGSTS_MASK BIT(0) +#define USB_STS_CFGSTS(p) ((p) & USB_STS_CFGSTS_MASK) +/* + * On-chip memory overflow. + * 0 - On-chip memory status OK. + * 1 - On-chip memory overflow. + */ +#define USB_STS_OV_MASK BIT(1) +#define USB_STS_OV(p) ((p) & USB_STS_OV_MASK) +/* + * SuperSpeed connection status. + * 0 - USB in SuperSpeed mode disconnected. + * 1 - USB in SuperSpeed mode connected. + */ +#define USB_STS_USB3CONS_MASK BIT(2) +#define USB_STS_USB3CONS(p) ((p) & USB_STS_USB3CONS_MASK) +/* + * DMA transfer configuration status. + * 0 - single request. + * 1 - multiple TRB chain + * Supported only for controller version < DEV_VER_V3 + */ +#define USB_STS_DTRANS_MASK BIT(3) +#define USB_STS_DTRANS(p) ((p) & USB_STS_DTRANS_MASK) +/* + * Device speed. + * 0 - Undefined (value after reset). + * 1 - Low speed + * 2 - Full speed + * 3 - High speed + * 4 - Super speed + */ +#define USB_STS_USBSPEED_MASK GENMASK(6, 4) +#define USB_STS_USBSPEED(p) (((p) & USB_STS_USBSPEED_MASK) >> 4) +#define USB_STS_LS (0x1 << 4) +#define USB_STS_FS (0x2 << 4) +#define USB_STS_HS (0x3 << 4) +#define USB_STS_SS (0x4 << 4) +#define DEV_UNDEFSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == (0x0 << 4)) +#define DEV_LOWSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_LS) +#define DEV_FULLSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_FS) +#define DEV_HIGHSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_HS) +#define DEV_SUPERSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_SS) +/* + * Endianness for SFR access. + * 0 - Little Endian order (default after hardware reset). + * 1 - Big Endian order + */ +#define USB_STS_ENDIAN_MASK BIT(7) +#define USB_STS_ENDIAN(p) ((p) & USB_STS_ENDIAN_MASK) +/* + * HS/FS clock turn-off status. + * 0 - hsfs clock is always on. + * 1 - hsfs clock turn-off in L2 (HS/FS mode) is enabled + * (default after hardware reset). + */ +#define USB_STS_CLK2OFF_MASK BIT(8) +#define USB_STS_CLK2OFF(p) ((p) & USB_STS_CLK2OFF_MASK) +/* + * PCLK clock turn-off status. + * 0 - pclk clock is always on. + * 1 - pclk clock turn-off in U3 (SS mode) is enabled + * (default after hardware reset). + */ +#define USB_STS_CLK3OFF_MASK BIT(9) +#define USB_STS_CLK3OFF(p) ((p) & USB_STS_CLK3OFF_MASK) +/* + * Controller in reset state. + * 0 - Internal reset is active. + * 1 - Internal reset is not active and controller is fully operational. + */ +#define USB_STS_IN_RST_MASK BIT(10) +#define USB_STS_IN_RST(p) ((p) & USB_STS_IN_RST_MASK) +/* + * Status of the "TDL calculation basing on TRB" feature. + * 0 - disabled + * 1 - enabled + * Supported only for DEV_VER_V2 controller version. + */ +#define USB_STS_TDL_TRB_ENABLED BIT(11) +/* + * Device enable Status. + * 0 - USB device is disabled (VBUS input is disconnected from internal logic). + * 1 - USB device is enabled (VBUS input is connected to the internal logic). + */ +#define USB_STS_DEVS_MASK BIT(14) +#define USB_STS_DEVS(p) ((p) & USB_STS_DEVS_MASK) +/* + * Address status. + * 0 - USB device is default state. + * 1 - USB device is at least in address state. + */ +#define USB_STS_ADDRESSED_MASK BIT(15) +#define USB_STS_ADDRESSED(p) ((p) & USB_STS_ADDRESSED_MASK) +/* + * L1 LPM state enable status (used in HS/FS mode). + * 0 - Entering to L1 LPM state disabled. + * 1 - Entering to L1 LPM state enabled. + */ +#define USB_STS_L1ENS_MASK BIT(16) +#define USB_STS_L1ENS(p) ((p) & USB_STS_L1ENS_MASK) +/* + * Internal VBUS connection status (used both in HS/FS and SS mode). + * 0 - internal VBUS is not detected. + * 1 - internal VBUS is detected. + */ +#define USB_STS_VBUSS_MASK BIT(17) +#define USB_STS_VBUSS(p) ((p) & USB_STS_VBUSS_MASK) +/* + * HS/FS LPM state (used in FS/HS mode). + * 0 - L0 State + * 1 - L1 State + * 2 - L2 State + * 3 - L3 State + */ +#define USB_STS_LPMST_MASK GENMASK(19, 18) +#define DEV_L0_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x0 << 18)) +#define DEV_L1_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x1 << 18)) +#define DEV_L2_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x2 << 18)) +#define DEV_L3_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x3 << 18)) +/* + * Disable HS status (used in FS/HS mode). + * 0 - the disconnect bit for HS/FS mode is set . + * 1 - the disconnect bit for HS/FS mode is not set. + */ +#define USB_STS_USB2CONS_MASK BIT(20) +#define USB_STS_USB2CONS(p) ((p) & USB_STS_USB2CONS_MASK) +/* + * HS/FS mode connection status (used in FS/HS mode). + * 0 - High Speed operations in USB2.0 (FS/HS) mode not disabled. + * 1 - High Speed operations in USB2.0 (FS/HS). + */ +#define USB_STS_DISABLE_HS_MASK BIT(21) +#define USB_STS_DISABLE_HS(p) ((p) & USB_STS_DISABLE_HS_MASK) +/* + * U1 state enable status (used in SS mode). + * 0 - Entering to U1 state disabled. + * 1 - Entering to U1 state enabled. + */ +#define USB_STS_U1ENS_MASK BIT(24) +#define USB_STS_U1ENS(p) ((p) & USB_STS_U1ENS_MASK) +/* + * U2 state enable status (used in SS mode). + * 0 - Entering to U2 state disabled. + * 1 - Entering to U2 state enabled. + */ +#define USB_STS_U2ENS_MASK BIT(25) +#define USB_STS_U2ENS(p) ((p) & USB_STS_U2ENS_MASK) +/* + * SuperSpeed Link LTSSM state. This field reflects USBSS-DEV current + * SuperSpeed link state + */ +#define USB_STS_LST_MASK GENMASK(29, 26) +#define DEV_LST_U0 (((p) & USB_STS_LST_MASK) == (0x0 << 26)) +#define DEV_LST_U1 (((p) & USB_STS_LST_MASK) == (0x1 << 26)) +#define DEV_LST_U2 (((p) & USB_STS_LST_MASK) == (0x2 << 26)) +#define DEV_LST_U3 (((p) & USB_STS_LST_MASK) == (0x3 << 26)) +#define DEV_LST_DISABLED (((p) & USB_STS_LST_MASK) == (0x4 << 26)) +#define DEV_LST_RXDETECT (((p) & USB_STS_LST_MASK) == (0x5 << 26)) +#define DEV_LST_INACTIVE (((p) & USB_STS_LST_MASK) == (0x6 << 26)) +#define DEV_LST_POLLING (((p) & USB_STS_LST_MASK) == (0x7 << 26)) +#define DEV_LST_RECOVERY (((p) & USB_STS_LST_MASK) == (0x8 << 26)) +#define DEV_LST_HOT_RESET (((p) & USB_STS_LST_MASK) == (0x9 << 26)) +#define DEV_LST_COMP_MODE (((p) & USB_STS_LST_MASK) == (0xa << 26)) +#define DEV_LST_LB_STATE (((p) & USB_STS_LST_MASK) == (0xb << 26)) +/* + * DMA clock turn-off status. + * 0 - DMA clock is always on (default after hardware reset). + * 1 - DMA clock turn-off in U1, U2 and U3 (SS mode) is enabled. + */ +#define USB_STS_DMAOFF_MASK BIT(30) +#define USB_STS_DMAOFF(p) ((p) & USB_STS_DMAOFF_MASK) +/* + * SFR Endian status. + * 0 - Little Endian order (default after hardware reset). + * 1 - Big Endian order. + */ +#define USB_STS_ENDIAN2_MASK BIT(31) +#define USB_STS_ENDIAN2(p) ((p) & USB_STS_ENDIAN2_MASK) + +/* USB_CMD - bitmasks */ +/* Set Function Address */ +#define USB_CMD_SET_ADDR BIT(0) +/* + * Function Address This field is saved to the device only when the field + * SET_ADDR is set '1 ' during write to USB_CMD register. + * Software is responsible for entering the address of the device during + * SET_ADDRESS request service. This field should be set immediately after + * the SETUP packet is decoded, and prior to confirmation of the status phase + */ +#define USB_CMD_FADDR_MASK GENMASK(7, 1) +#define USB_CMD_FADDR(p) (((p) << 1) & USB_CMD_FADDR_MASK) +/* Send Function Wake Device Notification TP (used only in SS mode). */ +#define USB_CMD_SDNFW BIT(8) +/* Set Test Mode (used only in HS/FS mode). */ +#define USB_CMD_STMODE BIT(9) +/* Test mode selector (used only in HS/FS mode) */ +#define USB_STS_TMODE_SEL_MASK GENMASK(11, 10) +#define USB_STS_TMODE_SEL(p) (((p) << 10) & USB_STS_TMODE_SEL_MASK) +/* + * Send Latency Tolerance Message Device Notification TP (used only + * in SS mode). + */ +#define USB_CMD_SDNLTM BIT(12) +/* Send Custom Transaction Packet (used only in SS mode) */ +#define USB_CMD_SPKT BIT(13) +/*Device Notification 'Function Wake' - Interface value (only in SS mode. */ +#define USB_CMD_DNFW_INT_MASK GENMASK(23, 16) +#define USB_STS_DNFW_INT(p) (((p) << 16) & USB_CMD_DNFW_INT_MASK) +/* + * Device Notification 'Latency Tolerance Message' -373 BELT value [7:0] + * (used only in SS mode). + */ +#define USB_CMD_DNLTM_BELT_MASK GENMASK(27, 16) +#define USB_STS_DNLTM_BELT(p) (((p) << 16) & USB_CMD_DNLTM_BELT_MASK) + +/* USB_ITPN - bitmasks */ +/* + * ITP(SS) / SOF (HS/FS) number + * In SS mode this field represent number of last ITP received from host. + * In HS/FS mode this field represent number of last SOF received from host. + */ +#define USB_ITPN_MASK GENMASK(13, 0) +#define USB_ITPN(p) ((p) & USB_ITPN_MASK) + +/* USB_LPM - bitmasks */ +/* Host Initiated Resume Duration. */ +#define USB_LPM_HIRD_MASK GENMASK(3, 0) +#define USB_LPM_HIRD(p) ((p) & USB_LPM_HIRD_MASK) +/* Remote Wakeup Enable (bRemoteWake). */ +#define USB_LPM_BRW BIT(4) + +/* USB_IEN - bitmasks */ +/* SS connection interrupt enable */ +#define USB_IEN_CONIEN BIT(0) +/* SS disconnection interrupt enable. */ +#define USB_IEN_DISIEN BIT(1) +/* USB SS warm reset interrupt enable. */ +#define USB_IEN_UWRESIEN BIT(2) +/* USB SS hot reset interrupt enable */ +#define USB_IEN_UHRESIEN BIT(3) +/* SS link U3 state enter interrupt enable (suspend).*/ +#define USB_IEN_U3ENTIEN BIT(4) +/* SS link U3 state exit interrupt enable (wakeup). */ +#define USB_IEN_U3EXTIEN BIT(5) +/* SS link U2 state enter interrupt enable.*/ +#define USB_IEN_U2ENTIEN BIT(6) +/* SS link U2 state exit interrupt enable.*/ +#define USB_IEN_U2EXTIEN BIT(7) +/* SS link U1 state enter interrupt enable.*/ +#define USB_IEN_U1ENTIEN BIT(8) +/* SS link U1 state exit interrupt enable.*/ +#define USB_IEN_U1EXTIEN BIT(9) +/* ITP/SOF packet detected interrupt enable.*/ +#define USB_IEN_ITPIEN BIT(10) +/* Wakeup interrupt enable.*/ +#define USB_IEN_WAKEIEN BIT(11) +/* Send Custom Packet interrupt enable.*/ +#define USB_IEN_SPKTIEN BIT(12) +/* HS/FS mode connection interrupt enable.*/ +#define USB_IEN_CON2IEN BIT(16) +/* HS/FS mode disconnection interrupt enable.*/ +#define USB_IEN_DIS2IEN BIT(17) +/* USB reset (HS/FS mode) interrupt enable.*/ +#define USB_IEN_U2RESIEN BIT(18) +/* LPM L2 state enter interrupt enable.*/ +#define USB_IEN_L2ENTIEN BIT(20) +/* LPM L2 state exit interrupt enable.*/ +#define USB_IEN_L2EXTIEN BIT(21) +/* LPM L1 state enter interrupt enable.*/ +#define USB_IEN_L1ENTIEN BIT(24) +/* LPM L1 state exit interrupt enable.*/ +#define USB_IEN_L1EXTIEN BIT(25) +/* Configuration reset interrupt enable.*/ +#define USB_IEN_CFGRESIEN BIT(26) +/* Start of the USB SS warm reset interrupt enable.*/ +#define USB_IEN_UWRESSIEN BIT(28) +/* End of the USB SS warm reset interrupt enable.*/ +#define USB_IEN_UWRESEIEN BIT(29) + +#define USB_IEN_INIT (USB_IEN_U2RESIEN | USB_ISTS_DIS2I | USB_IEN_CON2IEN \ + | USB_IEN_UHRESIEN | USB_IEN_UWRESIEN | USB_IEN_DISIEN \ + | USB_IEN_CONIEN | USB_IEN_U3EXTIEN | USB_IEN_L2ENTIEN \ + | USB_IEN_L2EXTIEN | USB_IEN_L1ENTIEN) + +/* USB_ISTS - bitmasks */ +/* SS Connection detected. */ +#define USB_ISTS_CONI BIT(0) +/* SS Disconnection detected. */ +#define USB_ISTS_DISI BIT(1) +/* UUSB warm reset detectede. */ +#define USB_ISTS_UWRESI BIT(2) +/* USB hot reset detected. */ +#define USB_ISTS_UHRESI BIT(3) +/* U3 link state enter detected (suspend).*/ +#define USB_ISTS_U3ENTI BIT(4) +/* U3 link state exit detected (wakeup). */ +#define USB_ISTS_U3EXTI BIT(5) +/* U2 link state enter detected.*/ +#define USB_ISTS_U2ENTI BIT(6) +/* U2 link state exit detected.*/ +#define USB_ISTS_U2EXTI BIT(7) +/* U1 link state enter detected.*/ +#define USB_ISTS_U1ENTI BIT(8) +/* U1 link state exit detected.*/ +#define USB_ISTS_U1EXTI BIT(9) +/* ITP/SOF packet detected.*/ +#define USB_ISTS_ITPI BIT(10) +/* Wakeup detected.*/ +#define USB_ISTS_WAKEI BIT(11) +/* Send Custom Packet detected.*/ +#define USB_ISTS_SPKTI BIT(12) +/* HS/FS mode connection detected.*/ +#define USB_ISTS_CON2I BIT(16) +/* HS/FS mode disconnection detected.*/ +#define USB_ISTS_DIS2I BIT(17) +/* USB reset (HS/FS mode) detected.*/ +#define USB_ISTS_U2RESI BIT(18) +/* LPM L2 state enter detected.*/ +#define USB_ISTS_L2ENTI BIT(20) +/* LPM L2 state exit detected.*/ +#define USB_ISTS_L2EXTI BIT(21) +/* LPM L1 state enter detected.*/ +#define USB_ISTS_L1ENTI BIT(24) +/* LPM L1 state exit detected.*/ +#define USB_ISTS_L1EXTI BIT(25) +/* USB configuration reset detected.*/ +#define USB_ISTS_CFGRESI BIT(26) +/* Start of the USB warm reset detected.*/ +#define USB_ISTS_UWRESSI BIT(28) +/* End of the USB warm reset detected.*/ +#define USB_ISTS_UWRESEI BIT(29) + +/* USB_SEL - bitmasks */ +#define EP_SEL_EPNO_MASK GENMASK(3, 0) +/* Endpoint number. */ +#define EP_SEL_EPNO(p) ((p) & EP_SEL_EPNO_MASK) +/* Endpoint direction bit - 0 - OUT, 1 - IN. */ +#define EP_SEL_DIR BIT(7) + +#define select_ep_in(nr) (EP_SEL_EPNO(p) | EP_SEL_DIR) +#define select_ep_out (EP_SEL_EPNO(p)) + +/* EP_TRADDR - bitmasks */ +/* Transfer Ring address. */ +#define EP_TRADDR_TRADDR(p) ((p)) + +/* EP_CFG - bitmasks */ +/* Endpoint enable */ +#define EP_CFG_ENABLE BIT(0) +/* + * Endpoint type. + * 1 - isochronous + * 2 - bulk + * 3 - interrupt + */ +#define EP_CFG_EPTYPE_MASK GENMASK(2, 1) +#define EP_CFG_EPTYPE(p) (((p) << 1) & EP_CFG_EPTYPE_MASK) +/* Stream support enable (only in SS mode). */ +#define EP_CFG_STREAM_EN BIT(3) +/* TDL check (only in SS mode for BULK EP). */ +#define EP_CFG_TDL_CHK BIT(4) +/* SID check (only in SS mode for BULK OUT EP). */ +#define EP_CFG_SID_CHK BIT(5) +/* DMA transfer endianness. */ +#define EP_CFG_EPENDIAN BIT(7) +/* Max burst size (used only in SS mode). */ +#define EP_CFG_MAXBURST_MASK GENMASK(11, 8) +#define EP_CFG_MAXBURST(p) (((p) << 8) & EP_CFG_MAXBURST_MASK) +/* ISO max burst. */ +#define EP_CFG_MULT_MASK GENMASK(15, 14) +#define EP_CFG_MULT(p) (((p) << 14) & EP_CFG_MULT_MASK) +/* ISO max burst. */ +#define EP_CFG_MAXPKTSIZE_MASK GENMASK(26, 16) +#define EP_CFG_MAXPKTSIZE(p) (((p) << 16) & EP_CFG_MAXPKTSIZE_MASK) +/* Max number of buffered packets. */ +#define EP_CFG_BUFFERING_MASK GENMASK(31, 27) +#define EP_CFG_BUFFERING(p) (((p) << 27) & EP_CFG_BUFFERING_MASK) + +/* EP_CMD - bitmasks */ +/* Endpoint reset. */ +#define EP_CMD_EPRST BIT(0) +/* Endpoint STALL set. */ +#define EP_CMD_SSTALL BIT(1) +/* Endpoint STALL clear. */ +#define EP_CMD_CSTALL BIT(2) +/* Send ERDY TP. */ +#define EP_CMD_ERDY BIT(3) +/* Request complete. */ +#define EP_CMD_REQ_CMPL BIT(5) +/* Transfer descriptor ready. */ +#define EP_CMD_DRDY BIT(6) +/* Data flush. */ +#define EP_CMD_DFLUSH BIT(7) +/* + * Transfer Descriptor Length write (used only for Bulk Stream capable + * endpoints in SS mode). + * Bit Removed from DEV_VER_V3 controller version. + */ +#define EP_CMD_STDL BIT(8) +/* + * Transfer Descriptor Length (used only in SS mode for bulk endpoints). + * Bits Removed from DEV_VER_V3 controller version. + */ +#define EP_CMD_TDL_MASK GENMASK(15, 9) +#define EP_CMD_TDL(p) (((p) << 9) & EP_CMD_TDL_MASK) +/* ERDY Stream ID value (used in SS mode). */ +#define EP_CMD_ERDY_SID_MASK GENMASK(31, 16) +#define EP_CMD_ERDY_SID(p) (((p) << 16) & EP_CMD_SID_MASK) + +/* EP_STS - bitmasks */ +/* Setup transfer complete. */ +#define EP_STS_SETUP BIT(0) +/* Endpoint STALL status. */ +#define EP_STS_STALL(p) ((p) & BIT(1)) +/* Interrupt On Complete. */ +#define EP_STS_IOC BIT(2) +/* Interrupt on Short Packet. */ +#define EP_STS_ISP BIT(3) +/* Transfer descriptor missing. */ +#define EP_STS_DESCMIS BIT(4) +/* Stream Rejected (used only in SS mode) */ +#define EP_STS_STREAMR BIT(5) +/* EXIT from MOVE DATA State (used only for stream transfers in SS mode). */ +#define EP_STS_MD_EXIT BIT(6) +/* TRB error. */ +#define EP_STS_TRBERR BIT(7) +/* Not ready (used only in SS mode). */ +#define EP_STS_NRDY BIT(8) +/* DMA busy bit. */ +#define EP_STS_DBUSY BIT(9) +/* Endpoint Buffer Empty */ +#define EP_STS_BUFFEMPTY(p) ((p) & BIT(10)) +/* Current Cycle Status */ +#define EP_STS_CCS(p) ((p) & BIT(11)) +/* Prime (used only in SS mode. */ +#define EP_STS_PRIME BIT(12) +/* Stream error (used only in SS mode). */ +#define EP_STS_SIDERR BIT(13) +/* OUT size mismatch. */ +#define EP_STS_OUTSMM BIT(14) +/* ISO transmission error. */ +#define EP_STS_ISOERR BIT(15) +/* Host Packet Pending (only for SS mode). */ +#define EP_STS_HOSTPP(p) ((p) & BIT(16)) +/* Stream Protocol State Machine State (only for Bulk stream endpoints). */ +#define EP_STS_SPSMST_MASK GENMASK(18, 17) +#define EP_STS_SPSMST_DISABLED(p) (((p) & EP_STS_SPSMST_MASK) >> 17) +#define EP_STS_SPSMST_IDLE(p) (((p) & EP_STS_SPSMST_MASK) >> 17) +#define EP_STS_SPSMST_START_STREAM(p) (((p) & EP_STS_SPSMST_MASK) >> 17) +#define EP_STS_SPSMST_MOVE_DATA(p) (((p) & EP_STS_SPSMST_MASK) >> 17) +/* Interrupt On Transfer complete. */ +#define EP_STS_IOT BIT(19) +/* OUT queue endpoint number. */ +#define EP_STS_OUTQ_NO_MASK GENMASK(27, 24) +#define EP_STS_OUTQ_NO(p) (((p) & EP_STS_OUTQ_NO_MASK) >> 24) +/* OUT queue valid flag. */ +#define EP_STS_OUTQ_VAL_MASK BIT(28) +#define EP_STS_OUTQ_VAL(p) ((p) & EP_STS_OUTQ_VAL_MASK) +/* SETUP WAIT. */ +#define EP_STS_STPWAIT BIT(31) + +/* EP_STS_SID - bitmasks */ +/* Stream ID (used only in SS mode). */ +#define EP_STS_SID_MASK GENMASK(15, 0) +#define EP_STS_SID(p) ((p) & EP_STS_SID_MASK) + +/* EP_STS_EN - bitmasks */ +/* SETUP interrupt enable. */ +#define EP_STS_EN_SETUPEN BIT(0) +/* OUT transfer missing descriptor enable. */ +#define EP_STS_EN_DESCMISEN BIT(4) +/* Stream Rejected enable. */ +#define EP_STS_EN_STREAMREN BIT(5) +/* Move Data Exit enable.*/ +#define EP_STS_EN_MD_EXITEN BIT(6) +/* TRB enable. */ +#define EP_STS_EN_TRBERREN BIT(7) +/* NRDY enable. */ +#define EP_STS_EN_NRDYEN BIT(8) +/* Prime enable. */ +#define EP_STS_EN_PRIMEEEN BIT(12) +/* Stream error enable. */ +#define EP_STS_EN_SIDERREN BIT(13) +/* OUT size mismatch enable. */ +#define EP_STS_EN_OUTSMMEN BIT(14) +/* ISO transmission error enable. */ +#define EP_STS_EN_ISOERREN BIT(15) +/* Interrupt on Transmission complete enable. */ +#define EP_STS_EN_IOTEN BIT(19) +/* Setup Wait interrupt enable. */ +#define EP_STS_EN_STPWAITEN BIT(31) + +/* DRBL- bitmasks */ +#define DB_VALUE_BY_INDEX(index) (1 << (index)) +#define DB_VALUE_EP0_OUT BIT(0) +#define DB_VALUE_EP0_IN BIT(16) + +/* EP_IEN - bitmasks */ +#define EP_IEN(index) (1 << (index)) +#define EP_IEN_EP_OUT0 BIT(0) +#define EP_IEN_EP_IN0 BIT(16) + +/* EP_ISTS - bitmasks */ +#define EP_ISTS(index) (1 << (index)) +#define EP_ISTS_EP_OUT0 BIT(0) +#define EP_ISTS_EP_IN0 BIT(16) + +/* USB_PWR- bitmasks */ +/*Power Shut Off capability enable*/ +#define PUSB_PWR_PSO_EN BIT(0) +/*Power Shut Off capability disable*/ +#define PUSB_PWR_PSO_DS BIT(1) +/* + * Enables turning-off Reference Clock. + * This bit is optional and implemented only when support for OTG is + * implemented (indicated by OTG_READY bit set to '1'). + */ +#define PUSB_PWR_STB_CLK_SWITCH_EN BIT(8) +/* + * Status bit indicating that operation required by STB_CLK_SWITCH_EN write + * is completed + */ +#define PUSB_PWR_STB_CLK_SWITCH_DONE BIT(9) +/* This bit informs if Fast Registers Access is enabled. */ +#define PUSB_PWR_FST_REG_ACCESS_STAT BIT(30) +/* Fast Registers Access Enable. */ +#define PUSB_PWR_FST_REG_ACCESS BIT(31) + +/* USB_CONF2- bitmasks */ +/* + * Writing 1 disables TDL calculation basing on TRB feature in controller + * for DMULT mode. + * Bit supported only for DEV_VER_V2 version. + */ +#define USB_CONF2_DIS_TDL_TRB BIT(1) +/* + * Writing 1 enables TDL calculation basing on TRB feature in controller + * for DMULT mode. + * Bit supported only for DEV_VER_V2 version. + */ +#define USB_CONF2_EN_TDL_TRB BIT(2) + +/* USB_CAP1- bitmasks */ +/* + * SFR Interface type + * These field reflects type of SFR interface implemented: + * 0x0 - OCP + * 0x1 - AHB, + * 0x2 - PLB + * 0x3 - AXI + * 0x4-0xF - reserved + */ +#define USB_CAP1_SFR_TYPE_MASK GENMASK(3, 0) +#define DEV_SFR_TYPE_OCP(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x0) +#define DEV_SFR_TYPE_AHB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x1) +#define DEV_SFR_TYPE_PLB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x2) +#define DEV_SFR_TYPE_AXI(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x3) +/* + * SFR Interface width + * These field reflects width of SFR interface implemented: + * 0x0 - 8 bit interface, + * 0x1 - 16 bit interface, + * 0x2 - 32 bit interface + * 0x3 - 64 bit interface + * 0x4-0xF - reserved + */ +#define USB_CAP1_SFR_WIDTH_MASK GENMASK(7, 4) +#define DEV_SFR_WIDTH_8(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x0 << 4)) +#define DEV_SFR_WIDTH_16(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x1 << 4)) +#define DEV_SFR_WIDTH_32(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x2 << 4)) +#define DEV_SFR_WIDTH_64(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x3 << 4)) +/* + * DMA Interface type + * These field reflects type of DMA interface implemented: + * 0x0 - OCP + * 0x1 - AHB, + * 0x2 - PLB + * 0x3 - AXI + * 0x4-0xF - reserved + */ +#define USB_CAP1_DMA_TYPE_MASK GENMASK(11, 8) +#define DEV_DMA_TYPE_OCP(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x0 << 8)) +#define DEV_DMA_TYPE_AHB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x1 << 8)) +#define DEV_DMA_TYPE_PLB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x2 << 8)) +#define DEV_DMA_TYPE_AXI(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x3 << 8)) +/* + * DMA Interface width + * These field reflects width of DMA interface implemented: + * 0x0 - reserved, + * 0x1 - reserved, + * 0x2 - 32 bit interface + * 0x3 - 64 bit interface + * 0x4-0xF - reserved + */ +#define USB_CAP1_DMA_WIDTH_MASK GENMASK(15, 12) +#define DEV_DMA_WIDTH_32(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x2 << 12)) +#define DEV_DMA_WIDTH_64(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x3 << 12)) +/* + * USB3 PHY Interface type + * These field reflects type of USB3 PHY interface implemented: + * 0x0 - USB PIPE, + * 0x1 - RMMI, + * 0x2-0xF - reserved + */ +#define USB_CAP1_U3PHY_TYPE_MASK GENMASK(19, 16) +#define DEV_U3PHY_PIPE(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x0 << 16)) +#define DEV_U3PHY_RMMI(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x1 << 16)) +/* + * USB3 PHY Interface width + * These field reflects width of USB3 PHY interface implemented: + * 0x0 - 8 bit PIPE interface, + * 0x1 - 16 bit PIPE interface, + * 0x2 - 32 bit PIPE interface, + * 0x3 - 64 bit PIPE interface + * 0x4-0xF - reserved + * Note: When SSIC interface is implemented this field shows the width of + * internal PIPE interface. The RMMI interface is always 20bit wide. + */ +#define USB_CAP1_U3PHY_WIDTH_MASK GENMASK(23, 20) +#define DEV_U3PHY_WIDTH_8(p) \ + (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x0 << 20)) +#define DEV_U3PHY_WIDTH_16(p) \ + (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x1 << 16)) +#define DEV_U3PHY_WIDTH_32(p) \ + (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x2 << 20)) +#define DEV_U3PHY_WIDTH_64(p) \ + (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x3 << 16)) + +/* + * USB2 PHY Interface enable + * These field informs if USB2 PHY interface is implemented: + * 0x0 - interface NOT implemented, + * 0x1 - interface implemented + */ +#define USB_CAP1_U2PHY_EN(p) ((p) & BIT(24)) +/* + * USB2 PHY Interface type + * These field reflects type of USB2 PHY interface implemented: + * 0x0 - UTMI, + * 0x1 - ULPI + */ +#define DEV_U2PHY_ULPI(p) ((p) & BIT(25)) +/* + * USB2 PHY Interface width + * These field reflects width of USB2 PHY interface implemented: + * 0x0 - 8 bit interface, + * 0x1 - 16 bit interface, + * Note: The ULPI interface is always 8bit wide. + */ +#define DEV_U2PHY_WIDTH_16(p) ((p) & BIT(26)) +/* + * OTG Ready + * 0x0 - pure device mode + * 0x1 - some features and ports for CDNS USB OTG controller are implemented. + */ +#define USB_CAP1_OTG_READY(p) ((p) & BIT(27)) + +/* + * When set, indicates that controller supports automatic internal TDL + * calculation basing on the size provided in TRB (TRB[22:17]) for DMULT mode + * Supported only for DEV_VER_V2 controller version. + */ +#define USB_CAP1_TDL_FROM_TRB(p) ((p) & BIT(28)) + +/* USB_CAP2- bitmasks */ +/* + * The actual size of the connected On-chip RAM memory in kB: + * - 0 means 256 kB (max supported mem size) + * - value other than 0 reflects the mem size in kB + */ +#define USB_CAP2_ACTUAL_MEM_SIZE(p) ((p) & GENMASK(7, 0)) +/* + * Max supported mem size + * These field reflects width of on-chip RAM address bus width, + * which determines max supported mem size: + * 0x0-0x7 - reserved, + * 0x8 - support for 4kB mem, + * 0x9 - support for 8kB mem, + * 0xA - support for 16kB mem, + * 0xB - support for 32kB mem, + * 0xC - support for 64kB mem, + * 0xD - support for 128kB mem, + * 0xE - support for 256kB mem, + * 0xF - reserved + */ +#define USB_CAP2_MAX_MEM_SIZE(p) ((p) & GENMASK(11, 8)) + +/* USB_CAP3- bitmasks */ +#define EP_IS_IMPLEMENTED(reg, index) ((reg) & (1 << (index))) + +/* USB_CAP4- bitmasks */ +#define EP_SUPPORT_ISO(reg, index) ((reg) & (1 << (index))) + +/* USB_CAP5- bitmasks */ +#define EP_SUPPORT_STREAM(reg, index) ((reg) & (1 << (index))) + +/* USB_CAP6- bitmasks */ +/* The USBSS-DEV Controller Internal build number. */ +#define GET_DEV_BASE_VERSION(p) ((p) & GENMASK(23, 0)) +/* The USBSS-DEV Controller version number. */ +#define GET_DEV_CUSTOM_VERSION(p) ((p) & GENMASK(31, 24)) + +#define DEV_VER_NXP_V1 0x00024502 +#define DEV_VER_TI_V1 0x00024509 +#define DEV_VER_V2 0x0002450C +#define DEV_VER_V3 0x0002450d + +/* DBG_LINK1- bitmasks */ +/* + * LFPS_MIN_DET_U1_EXIT value This parameter configures the minimum + * time required for decoding the received LFPS as an LFPS.U1_Exit. + */ +#define DBG_LINK1_LFPS_MIN_DET_U1_EXIT(p) ((p) & GENMASK(7, 0)) +/* + * LFPS_MIN_GEN_U1_EXIT value This parameter configures the minimum time for + * phytxelecidle deassertion when LFPS.U1_Exit + */ +#define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_MASK GENMASK(15, 8) +#define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT(p) (((p) << 8) & GENMASK(15, 8)) +/* + * RXDET_BREAK_DIS value This parameter configures terminating the Far-end + * Receiver termination detection sequence: + * 0: it is possible that USBSS_DEV will terminate Farend receiver + * termination detection sequence + * 1: USBSS_DEV will not terminate Far-end receiver termination + * detection sequence + */ +#define DBG_LINK1_RXDET_BREAK_DIS BIT(16) +/* LFPS_GEN_PING value This parameter configures the LFPS.Ping generation */ +#define DBG_LINK1_LFPS_GEN_PING(p) (((p) << 17) & GENMASK(21, 17)) +/* + * Set the LFPS_MIN_DET_U1_EXIT value Writing '1' to this bit writes the + * LFPS_MIN_DET_U1_EXIT field value to the device. This bit is automatically + * cleared. Writing '0' has no effect + */ +#define DBG_LINK1_LFPS_MIN_DET_U1_EXIT_SET BIT(24) +/* + * Set the LFPS_MIN_GEN_U1_EXIT value. Writing '1' to this bit writes the + * LFPS_MIN_GEN_U1_EXIT field value to the device. This bit is automatically + * cleared. Writing '0' has no effect + */ +#define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_SET BIT(25) +/* + * Set the RXDET_BREAK_DIS value Writing '1' to this bit writes + * the RXDET_BREAK_DIS field value to the device. This bit is automatically + * cleared. Writing '0' has no effect + */ +#define DBG_LINK1_RXDET_BREAK_DIS_SET BIT(26) +/* + * Set the LFPS_GEN_PING_SET value Writing '1' to this bit writes + * the LFPS_GEN_PING field value to the device. This bit is automatically + * cleared. Writing '0' has no effect." + */ +#define DBG_LINK1_LFPS_GEN_PING_SET BIT(27) + +/* DMA_AXI_CTRL- bitmasks */ +/* The mawprot pin configuration. */ +#define DMA_AXI_CTRL_MARPROT(p) ((p) & GENMASK(2, 0)) +/* The marprot pin configuration. */ +#define DMA_AXI_CTRL_MAWPROT(p) (((p) < 16) & GENMASK(18, 16)) +#define DMA_AXI_CTRL_NON_SECURE 0x02 + +#define gadget_to_cdns3_device(g) (container_of(g, struct cdns3_device, gadget)) + +#define ep_to_cdns3_ep(ep) (container_of(ep, struct cdns3_endpoint, endpoint)) + +/*-------------------------------------------------------------------------*/ +/* + * USBSS-DEV DMA interface. + */ +#define TRBS_PER_SEGMENT 40 + +#define ISO_MAX_INTERVAL 10 + +#if TRBS_PER_SEGMENT < 2 +#error "Incorrect TRBS_PER_SEGMENT. Minimal Transfer Ring size is 2." +#endif + +/* + *Only for ISOC endpoints - maximum number of TRBs is calculated as + * pow(2, bInterval-1) * number of usb requests. It is limitation made by + * driver to save memory. Controller must prepare TRB for each ITP even + * if bInterval > 1. It's the reason why driver needs so many TRBs for + * isochronous endpoints. + */ +#define TRBS_PER_ISOC_SEGMENT (ISO_MAX_INTERVAL * 8) + +#define GET_TRBS_PER_SEGMENT(ep_type) ((ep_type) == USB_ENDPOINT_XFER_ISOC ? \ + TRBS_PER_ISOC_SEGMENT : TRBS_PER_SEGMENT) +/** + * struct cdns3_trb - represent Transfer Descriptor block. + * @buffer: pointer to buffer data + * @length: length of data + * @control: control flags. + * + * This structure describes transfer block serviced by DMA module. + */ +struct cdns3_trb { + __le32 buffer; + __le32 length; + __le32 control; +}; + +#define TRB_SIZE (sizeof(struct cdns3_trb)) +#define TRB_RING_SIZE (TRB_SIZE * TRBS_PER_SEGMENT) +#define TRB_ISO_RING_SIZE (TRB_SIZE * TRBS_PER_ISOC_SEGMENT) +#define TRB_CTRL_RING_SIZE (TRB_SIZE * 2) + +/* TRB bit mask */ +#define TRB_TYPE_BITMASK GENMASK(15, 10) +#define TRB_TYPE(p) ((p) << 10) +#define TRB_FIELD_TO_TYPE(p) (((p) & TRB_TYPE_BITMASK) >> 10) + +/* TRB type IDs */ +/* bulk, interrupt, isoc , and control data stage */ +#define TRB_NORMAL 1 +/* TRB for linking ring segments */ +#define TRB_LINK 6 + +/* Cycle bit - indicates TRB ownership by driver or hw*/ +#define TRB_CYCLE BIT(0) +/* + * When set to '1', the device will toggle its interpretation of the Cycle bit + */ +#define TRB_TOGGLE BIT(1) + +/* + * Short Packet (SP). OUT EPs at DMULT=1 only. Indicates if the TRB was + * processed while USB short packet was received. No more buffers defined by + * the TD will be used. DMA will automatically advance to next TD. + * - Shall be set to 0 by Software when putting TRB on the Transfer Ring + * - Shall be set to 1 by Controller when Short Packet condition for this TRB + * is detected independent if ISP is set or not. + */ +#define TRB_SP BIT(1) + +/* Interrupt on short packet*/ +#define TRB_ISP BIT(2) +/*Setting this bit enables FIFO DMA operation mode*/ +#define TRB_FIFO_MODE BIT(3) +/* Set PCIe no snoop attribute */ +#define TRB_CHAIN BIT(4) +/* Interrupt on completion */ +#define TRB_IOC BIT(5) + +/* stream ID bitmasks. */ +#define TRB_STREAM_ID(p) ((p) & GENMASK(31, 16)) + +/* Size of TD expressed in USB packets for HS/FS mode. */ +#define TRB_TDL_HS_SIZE(p) (((p) << 16) & GENMASK(31, 16)) +#define TRB_TDL_HS_SIZE_GET(p) (((p) & GENMASK(31, 16)) >> 16) + +/* transfer_len bitmasks. */ +#define TRB_LEN(p) ((p) & GENMASK(16, 0)) + +/* Size of TD expressed in USB packets for SS mode. */ +#define TRB_TDL_SS_SIZE(p) (((p) << 17) & GENMASK(23, 17)) +#define TRB_TDL_SS_SIZE_GET(p) (((p) & GENMASK(23, 17)) >> 17) + +/* transfer_len bitmasks - bits 31:24 */ +#define TRB_BURST_LEN(p) (((p) << 24) & GENMASK(31, 24)) +#define TRB_BURST_LEN_GET(p) (((p) & GENMASK(31, 24)) >> 24) + +/* Data buffer pointer bitmasks*/ +#define TRB_BUFFER(p) ((p) & GENMASK(31, 0)) + +/*-------------------------------------------------------------------------*/ +/* Driver numeric constants */ + +/* Such declaration should be added to ch9.h */ +#define USB_DEVICE_MAX_ADDRESS 127 + +/* Endpoint init values */ +#define CDNS3_EP_MAX_PACKET_LIMIT 1024 +#define CDNS3_EP_MAX_STREAMS 15 +#define CDNS3_EP0_MAX_PACKET_LIMIT 512 + +/* All endpoints including EP0 */ +#define CDNS3_ENDPOINTS_MAX_COUNT 32 +#define CDNS3_EP_ZLP_BUF_SIZE 1024 + +#define CDNS3_EP_BUF_SIZE 2 /* KB */ +#define CDNS3_EP_ISO_HS_MULT 3 +#define CDNS3_EP_ISO_SS_BURST 3 +#define CDNS3_MAX_NUM_DESCMISS_BUF 32 +#define CDNS3_DESCMIS_BUF_SIZE 2048 /* Bytes */ +/*-------------------------------------------------------------------------*/ +/* Used structs */ + +struct cdns3_device; + +/** + * struct cdns3_endpoint - extended device side representation of USB endpoint. + * @endpoint: usb endpoint + * @pending_req_list: list of requests queuing on transfer ring. + * @deferred_req_list: list of requests waiting for queuing on transfer ring. + * @trb_pool: transfer ring - array of transaction buffers + * @trb_pool_dma: dma address of transfer ring + * @cdns3_dev: device associated with this endpoint + * @name: a human readable name e.g. ep1out + * @flags: specify the current state of endpoint + * @dir: endpoint direction + * @num: endpoint number (1 - 15) + * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK + * @interval: interval between packets used for ISOC endpoint. + * @free_trbs: number of free TRBs in transfer ring + * @num_trbs: number of all TRBs in transfer ring + * @pcs: producer cycle state + * @ccs: consumer cycle state + * @enqueue: enqueue index in transfer ring + * @dequeue: dequeue index in transfer ring + * @trb_burst_size: number of burst used in trb. + */ +struct cdns3_endpoint { + struct usb_ep endpoint; + struct list_head pending_req_list; + struct list_head deferred_req_list; + + struct cdns3_trb *trb_pool; + dma_addr_t trb_pool_dma; + + struct cdns3_device *cdns3_dev; + char name[20]; + +#define EP_ENABLED BIT(0) +#define EP_STALL BIT(1) +#define EP_WEDGE BIT(2) +#define EP_TRANSFER_STARTED BIT(3) +#define EP_UPDATE_EP_TRBADDR BIT(4) +#define EP_PENDING_REQUEST BIT(5) +#define EP_RING_FULL BIT(6) +#define EP_CLAIMED BIT(7) +#define EP_DEFERRED_DRDY BIT(8) +#define EP_QUIRK_ISO_OUT_EN BIT(9) + u32 flags; + + u8 dir; + u8 num; + u8 type; + int interval; + + int free_trbs; + int num_trbs; + u8 pcs; + u8 ccs; + int enqueue; + int dequeue; + u8 trb_burst_size; + + unsigned int wa1_set:1; + struct cdns3_trb *wa1_trb; + unsigned int wa1_trb_index; + unsigned int wa1_cycle_bit:1; +}; + +/** + * struct cdns3_aligned_buf - represent aligned buffer used for DMA transfer + * @buf: aligned to 8 bytes data buffer. Buffer address used in + * TRB shall be aligned to 8. + * @dma: dma address + * @size: size of buffer + * @in_use: inform if this buffer is associated with usb_request + * @list: used to adding instance of this object to list + */ +struct cdns3_aligned_buf { + void *buf; + dma_addr_t dma; + u32 size; + int in_use:1; + struct list_head list; +}; + +/** + * struct cdns3_request - extended device side representation of usb_request + * object . + * @request: generic usb_request object describing single I/O request. + * @priv_ep: extended representation of usb_ep object + * @trb: the first TRB association with this request + * @start_trb: number of the first TRB in transfer ring + * @end_trb: number of the last TRB in transfer ring + * @aligned_buf: object holds information about aligned buffer associated whit + * this endpoint + * @flags: flag specifying special usage of request + */ +struct cdns3_request { + struct usb_request request; + struct cdns3_endpoint *priv_ep; + struct cdns3_trb *trb; + int start_trb; + int end_trb; + struct cdns3_aligned_buf *aligned_buf; +#define REQUEST_PENDING BIT(0) +#define REQUEST_INTERNAL BIT(1) +#define REQUEST_INTERNAL_CH BIT(2) +#define REQUEST_ZLP BIT(3) +#define REQUEST_UNALIGNED BIT(4) + u32 flags; + struct list_head list; +}; + +#define to_cdns3_request(r) (container_of(r, struct cdns3_request, request)) + +/*Stages used during enumeration process.*/ +#define CDNS3_SETUP_STAGE 0x0 +#define CDNS3_DATA_STAGE 0x1 +#define CDNS3_STATUS_STAGE 0x2 + +/** + * struct cdns3_device - represent USB device. + * @dev: pointer to device structure associated whit this controller + * @sysdev: pointer to the DMA capable device + * @gadget: device side representation of the peripheral controller + * @gadget_driver: pointer to the gadget driver + * @dev_ver: device controller version. + * @lock: for synchronizing + * @regs: base address for device side registers + * @setup_buf: used while processing usb control requests + * @setup_dma: dma address for setup_buf + * @zlp_buf - zlp buffer + * @ep0_stage: ep0 stage during enumeration process. + * @ep0_data_dir: direction for control transfer + * @eps: array of pointers to all endpoints with exclusion ep0 + * @aligned_buf_list: list of aligned buffers internally allocated by driver + * @run_garbage_colector: infroms that at least one element of aligned_buf_list + * can be freed + * @selected_ep: actually selected endpoint. It's used only to improve + * performance. + * @isoch_delay: value from Set Isoch Delay request. Only valid on SS/SSP. + * @u1_allowed: allow device transition to u1 state + * @u2_allowed: allow device transition to u2 state + * @is_selfpowered: device is self powered + * @setup_pending: setup packet is processing by gadget driver + * @hw_configured_flag: hardware endpoint configuration was set. + * @wake_up_flag: allow device to remote up the host + * @status_completion_no_call: indicate that driver is waiting for status s + * stage completion. It's used in deferred SET_CONFIGURATION request. + * @onchip_buffers: number of available on-chip buffers. + * @onchip_used_size: actual size of on-chip memory assigned to endpoints. + * @pending_status_wq: workqueue handling status stage for deferred requests. + * @shadow_ep_en: hold information about endpoints that will be enabled + * in soft irq. + * @pending_status_request: request for which status stage was deferred + */ +struct cdns3_device { + struct device *dev; + struct device *sysdev; + + struct usb_gadget gadget; + struct usb_gadget_driver *gadget_driver; + +#define CDNS_REVISION_V0 0x00024501 +#define CDNS_REVISION_V1 0x00024509 + u32 dev_ver; + + /* generic spin-lock for drivers */ + spinlock_t lock; + + struct cdns3_usb_regs __iomem *regs; + + struct usb_ctrlrequest *setup_buf; + dma_addr_t setup_dma; + void *zlp_buf; + + u8 ep0_stage; + int ep0_data_dir; + + struct cdns3_endpoint *eps[CDNS3_ENDPOINTS_MAX_COUNT]; + + struct list_head aligned_buf_list; + unsigned run_garbage_colector:1; + + u32 selected_ep; + u16 isoch_delay; + + unsigned wait_for_setup:1; + unsigned u1_allowed:1; + unsigned u2_allowed:1; + unsigned is_selfpowered:1; + unsigned setup_pending:1; + int hw_configured_flag:1; + int wake_up_flag:1; + unsigned status_completion_no_call:1; + int out_mem_is_allocated; + + struct work_struct pending_status_wq; + struct usb_request *pending_status_request; + u32 shadow_ep_en; + /*in KB */ + u16 onchip_buffers; + u16 onchip_used_size; +}; + +void cdns3_set_register_bit(void __iomem *ptr, u32 mask); +dma_addr_t cdns3_trb_virt_to_dma(struct cdns3_endpoint *priv_ep, + struct cdns3_trb *trb); +enum usb_device_speed cdns3_get_speed(struct cdns3_device *priv_dev); +void cdns3_pending_setup_status_handler(struct work_struct *work); +void cdns3_hw_reset_eps_config(struct cdns3_device *priv_dev); +void cdns3_set_hw_configuration(struct cdns3_device *priv_dev); +void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep); +void cdns3_allow_enable_l1(struct cdns3_device *priv_dev, int enable); +struct usb_request *cdns3_next_request(struct list_head *list); +int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, + struct usb_request *request); +void cdns3_rearm_transfer(struct cdns3_endpoint *priv_ep, u8 rearm); +int cdns3_allocate_trb_pool(struct cdns3_endpoint *priv_ep); +u8 cdns3_ep_addr_to_index(u8 ep_addr); +int cdns3_gadget_ep_set_wedge(struct usb_ep *ep); +int cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value); +struct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep, + gfp_t gfp_flags); +void cdns3_gadget_ep_free_request(struct usb_ep *ep, + struct usb_request *request); +int cdns3_gadget_ep_dequeue(struct usb_ep *ep, struct usb_request *request); +void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, + struct cdns3_request *priv_req, + int status); + +int cdns3_init_ep0(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep); +void cdns3_ep0_config(struct cdns3_device *priv_dev); +void cdns3_ep_config(struct cdns3_endpoint *priv_ep); +void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir); +int __cdns3_gadget_wakeup(struct cdns3_device *priv_dev); + +#endif /* __LINUX_CDNS3_GADGET */ diff --git a/drivers/usb/cdns3/host-export.h b/drivers/usb/cdns3/host-export.h new file mode 100644 index 000000000000..b498a170b7e8 --- /dev/null +++ b/drivers/usb/cdns3/host-export.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Cadence USBSS DRD Driver - Host Export APIs + * + * Copyright (C) 2017-2018 NXP + * + * Authors: Peter Chen + */ +#ifndef __LINUX_CDNS3_HOST_EXPORT +#define __LINUX_CDNS3_HOST_EXPORT + +#ifdef CONFIG_USB_CDNS3_HOST + +int cdns3_host_init(struct cdns3 *cdns); +void cdns3_host_exit(struct cdns3 *cdns); + +#else + +static inline int cdns3_host_init(struct cdns3 *cdns) +{ + return -ENXIO; +} + +static inline void cdns3_host_exit(struct cdns3 *cdns) { } + +#endif /* CONFIG_USB_CDNS3_HOST */ + +#endif /* __LINUX_CDNS3_HOST_EXPORT */ diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c new file mode 100644 index 000000000000..df41ba7c6726 --- /dev/null +++ b/drivers/usb/cdns3/host.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Driver - host side + * + * Copyright (C) 2018 Cadence Design Systems. + * Copyright (C) 2017-2018 NXP + * + * Authors: Peter Chen + * Pawel Laszczak + */ + +#include +#include "core.h" +#include "drd.h" + +static int __cdns3_host_init(struct cdns3 *cdns) +{ + struct platform_device *xhci; + int ret; + + cdns3_drd_switch_host(cdns, 1); + + xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO); + if (!xhci) { + dev_err(cdns->dev, "couldn't allocate xHCI device\n"); + return -ENOMEM; + } + + xhci->dev.parent = cdns->dev; + cdns->host_dev = xhci; + + ret = platform_device_add_resources(xhci, cdns->xhci_res, + CDNS3_XHCI_RESOURCES_NUM); + if (ret) { + dev_err(cdns->dev, "couldn't add resources to xHCI device\n"); + goto err1; + } + + ret = platform_device_add(xhci); + if (ret) { + dev_err(cdns->dev, "failed to register xHCI device\n"); + goto err1; + } + + return 0; +err1: + platform_device_put(xhci); + return ret; +} + +static void cdns3_host_exit(struct cdns3 *cdns) +{ + platform_device_unregister(cdns->host_dev); + cdns->host_dev = NULL; + cdns3_drd_switch_host(cdns, 0); +} + +int cdns3_host_init(struct cdns3 *cdns) +{ + struct cdns3_role_driver *rdrv; + + rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); + if (!rdrv) + return -ENOMEM; + + rdrv->start = __cdns3_host_init; + rdrv->stop = cdns3_host_exit; + rdrv->state = CDNS3_ROLE_STATE_INACTIVE; + rdrv->suspend = NULL; + rdrv->resume = NULL; + rdrv->name = "host"; + + cdns->roles[CDNS3_ROLE_HOST] = rdrv; + + return 0; +} diff --git a/drivers/usb/cdns3/trace.c b/drivers/usb/cdns3/trace.c new file mode 100644 index 000000000000..9431eb86d4ff --- /dev/null +++ b/drivers/usb/cdns3/trace.c @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * USBSS device controller driver Trace Support + * + * Copyright (C) 2018 Cadence. + * + * Author: Pawel Laszczak + */ + +#define CREATE_TRACE_POINTS +#include "trace.h" + +void cdns3_dbg(struct cdns3_device *priv_dev, const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + trace_cdns3_log(priv_dev, &vaf); + va_end(args); +} diff --git a/drivers/usb/cdns3/trace.h b/drivers/usb/cdns3/trace.h new file mode 100644 index 000000000000..1cc2abca320c --- /dev/null +++ b/drivers/usb/cdns3/trace.h @@ -0,0 +1,447 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * USBSS device controller driver. + * Trace support header file. + * + * Copyright (C) 2018 Cadence. + * + * Author: Pawel Laszczak + */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM cdns3 + +#if !defined(__LINUX_CDNS3_TRACE) || defined(TRACE_HEADER_MULTI_READ) +#define __LINUX_CDNS3_TRACE + +#include +#include +#include +#include +#include "core.h" +#include "gadget.h" +#include "debug.h" + +#define CDNS3_MSG_MAX 500 + +TRACE_EVENT(cdns3_log, + TP_PROTO(struct cdns3_device *priv_dev, struct va_format *vaf), + TP_ARGS(priv_dev, vaf), + TP_STRUCT__entry( + __string(name, dev_name(priv_dev->dev)) + __dynamic_array(char, msg, CDNS3_MSG_MAX) + ), + TP_fast_assign( + __assign_str(name, dev_name(priv_dev->dev)); + vsnprintf(__get_str(msg), CDNS3_MSG_MAX, vaf->fmt, *vaf->va); + ), + TP_printk("%s: %s", __get_str(name), __get_str(msg)) +); + +DECLARE_EVENT_CLASS(cdns3_log_doorbell, + TP_PROTO(const char *ep_name, u32 ep_trbaddr), + TP_ARGS(ep_name, ep_trbaddr), + TP_STRUCT__entry( + __string(name, ep_name) + __field(u32, ep_trbaddr) + ), + TP_fast_assign( + __assign_str(name, ep_name); + __entry->ep_trbaddr = ep_trbaddr; + ), + TP_printk("//Ding Dong %s, ep_trbaddr %08x", __get_str(name), + __entry->ep_trbaddr) +); + +DEFINE_EVENT(cdns3_log_doorbell, cdns3_doorbell_ep0, + TP_PROTO(const char *ep_name, u32 ep_trbaddr), + TP_ARGS(ep_name, ep_trbaddr) +); + +DEFINE_EVENT(cdns3_log_doorbell, cdns3_doorbell_epx, + TP_PROTO(const char *ep_name, u32 ep_trbaddr), + TP_ARGS(ep_name, ep_trbaddr) +); + +DECLARE_EVENT_CLASS(cdns3_log_usb_irq, + TP_PROTO(struct cdns3_device *priv_dev, u32 usb_ists), + TP_ARGS(priv_dev, usb_ists), + TP_STRUCT__entry( + __field(enum usb_device_speed, speed) + __field(u32, usb_ists) + __dynamic_array(char, str, CDNS3_MSG_MAX) + ), + TP_fast_assign( + __entry->speed = cdns3_get_speed(priv_dev); + __entry->usb_ists = usb_ists; + ), + TP_printk("%s", cdns3_decode_usb_irq(__get_str(str), __entry->speed, + __entry->usb_ists)) +); + +DEFINE_EVENT(cdns3_log_usb_irq, cdns3_usb_irq, + TP_PROTO(struct cdns3_device *priv_dev, u32 usb_ists), + TP_ARGS(priv_dev, usb_ists) +); + +DECLARE_EVENT_CLASS(cdns3_log_epx_irq, + TP_PROTO(struct cdns3_device *priv_dev, struct cdns3_endpoint *priv_ep), + TP_ARGS(priv_dev, priv_ep), + TP_STRUCT__entry( + __string(ep_name, priv_ep->name) + __field(u32, ep_sts) + __field(u32, ep_traddr) + __dynamic_array(char, str, CDNS3_MSG_MAX) + ), + TP_fast_assign( + __assign_str(ep_name, priv_ep->name); + __entry->ep_sts = readl(&priv_dev->regs->ep_sts); + __entry->ep_traddr = readl(&priv_dev->regs->ep_traddr); + ), + TP_printk("%s, ep_traddr: %08x", + cdns3_decode_epx_irq(__get_str(str), + __get_str(ep_name), + __entry->ep_sts), + __entry->ep_traddr) +); + +DEFINE_EVENT(cdns3_log_epx_irq, cdns3_epx_irq, + TP_PROTO(struct cdns3_device *priv_dev, struct cdns3_endpoint *priv_ep), + TP_ARGS(priv_dev, priv_ep) +); + +DECLARE_EVENT_CLASS(cdns3_log_ep0_irq, + TP_PROTO(struct cdns3_device *priv_dev, u32 ep_sts), + TP_ARGS(priv_dev, ep_sts), + TP_STRUCT__entry( + __field(int, ep_dir) + __field(u32, ep_sts) + __dynamic_array(char, str, CDNS3_MSG_MAX) + ), + TP_fast_assign( + __entry->ep_dir = priv_dev->ep0_data_dir; + __entry->ep_sts = ep_sts; + ), + TP_printk("%s", cdns3_decode_ep0_irq(__get_str(str), + __entry->ep_dir, + __entry->ep_sts)) +); + +DEFINE_EVENT(cdns3_log_ep0_irq, cdns3_ep0_irq, + TP_PROTO(struct cdns3_device *priv_dev, u32 ep_sts), + TP_ARGS(priv_dev, ep_sts) +); + +DECLARE_EVENT_CLASS(cdns3_log_ctrl, + TP_PROTO(struct usb_ctrlrequest *ctrl), + TP_ARGS(ctrl), + TP_STRUCT__entry( + __field(u8, bRequestType) + __field(u8, bRequest) + __field(u16, wValue) + __field(u16, wIndex) + __field(u16, wLength) + __dynamic_array(char, str, CDNS3_MSG_MAX) + ), + TP_fast_assign( + __entry->bRequestType = ctrl->bRequestType; + __entry->bRequest = ctrl->bRequest; + __entry->wValue = le16_to_cpu(ctrl->wValue); + __entry->wIndex = le16_to_cpu(ctrl->wIndex); + __entry->wLength = le16_to_cpu(ctrl->wLength); + ), + TP_printk("%s", usb_decode_ctrl(__get_str(str), CDNS3_MSG_MAX, + __entry->bRequestType, + __entry->bRequest, __entry->wValue, + __entry->wIndex, __entry->wLength) + ) +); + +DEFINE_EVENT(cdns3_log_ctrl, cdns3_ctrl_req, + TP_PROTO(struct usb_ctrlrequest *ctrl), + TP_ARGS(ctrl) +); + +DECLARE_EVENT_CLASS(cdns3_log_request, + TP_PROTO(struct cdns3_request *req), + TP_ARGS(req), + TP_STRUCT__entry( + __string(name, req->priv_ep->name) + __field(struct cdns3_request *, req) + __field(void *, buf) + __field(unsigned int, actual) + __field(unsigned int, length) + __field(int, status) + __field(int, zero) + __field(int, short_not_ok) + __field(int, no_interrupt) + __field(int, start_trb) + __field(int, end_trb) + __field(struct cdns3_trb *, start_trb_addr) + __field(int, flags) + ), + TP_fast_assign( + __assign_str(name, req->priv_ep->name); + __entry->req = req; + __entry->buf = req->request.buf; + __entry->actual = req->request.actual; + __entry->length = req->request.length; + __entry->status = req->request.status; + __entry->zero = req->request.zero; + __entry->short_not_ok = req->request.short_not_ok; + __entry->no_interrupt = req->request.no_interrupt; + __entry->start_trb = req->start_trb; + __entry->end_trb = req->end_trb; + __entry->start_trb_addr = req->trb; + __entry->flags = req->flags; + ), + TP_printk("%s: req: %p, req buff %p, length: %u/%u %s%s%s, status: %d," + " trb: [start:%d, end:%d: virt addr %pa], flags:%x ", + __get_str(name), __entry->req, __entry->buf, __entry->actual, + __entry->length, + __entry->zero ? "zero | " : "", + __entry->short_not_ok ? "short | " : "", + __entry->no_interrupt ? "no int" : "", + __entry->status, + __entry->start_trb, + __entry->end_trb, + __entry->start_trb_addr, + __entry->flags + ) +); + +DEFINE_EVENT(cdns3_log_request, cdns3_alloc_request, + TP_PROTO(struct cdns3_request *req), + TP_ARGS(req) +); + +DEFINE_EVENT(cdns3_log_request, cdns3_free_request, + TP_PROTO(struct cdns3_request *req), + TP_ARGS(req) +); + +DEFINE_EVENT(cdns3_log_request, cdns3_ep_queue, + TP_PROTO(struct cdns3_request *req), + TP_ARGS(req) +); + +DEFINE_EVENT(cdns3_log_request, cdns3_ep_dequeue, + TP_PROTO(struct cdns3_request *req), + TP_ARGS(req) +); + +DEFINE_EVENT(cdns3_log_request, cdns3_gadget_giveback, + TP_PROTO(struct cdns3_request *req), + TP_ARGS(req) +); + +DECLARE_EVENT_CLASS(cdns3_log_aligned_request, + TP_PROTO(struct cdns3_request *priv_req), + TP_ARGS(priv_req), + TP_STRUCT__entry( + __string(name, priv_req->priv_ep->name) + __field(struct usb_request *, req) + __field(void *, buf) + __field(dma_addr_t, dma) + __field(void *, aligned_buf) + __field(dma_addr_t, aligned_dma) + __field(u32, aligned_buf_size) + ), + TP_fast_assign( + __assign_str(name, priv_req->priv_ep->name); + __entry->req = &priv_req->request; + __entry->buf = priv_req->request.buf; + __entry->dma = priv_req->request.dma; + __entry->aligned_buf = priv_req->aligned_buf->buf; + __entry->aligned_dma = priv_req->aligned_buf->dma; + __entry->aligned_buf_size = priv_req->aligned_buf->size; + ), + TP_printk("%s: req: %p, req buf %p, dma %pad a_buf %p a_dma %pad, size %d", + __get_str(name), __entry->req, __entry->buf, &__entry->dma, + __entry->aligned_buf, &__entry->aligned_dma, + __entry->aligned_buf_size + ) +); + +DEFINE_EVENT(cdns3_log_aligned_request, cdns3_free_aligned_request, + TP_PROTO(struct cdns3_request *req), + TP_ARGS(req) +); + +DEFINE_EVENT(cdns3_log_aligned_request, cdns3_prepare_aligned_request, + TP_PROTO(struct cdns3_request *req), + TP_ARGS(req) +); + +DECLARE_EVENT_CLASS(cdns3_log_trb, + TP_PROTO(struct cdns3_endpoint *priv_ep, struct cdns3_trb *trb), + TP_ARGS(priv_ep, trb), + TP_STRUCT__entry( + __string(name, priv_ep->name) + __field(struct cdns3_trb *, trb) + __field(u32, buffer) + __field(u32, length) + __field(u32, control) + __field(u32, type) + ), + TP_fast_assign( + __assign_str(name, priv_ep->name); + __entry->trb = trb; + __entry->buffer = trb->buffer; + __entry->length = trb->length; + __entry->control = trb->control; + __entry->type = usb_endpoint_type(priv_ep->endpoint.desc); + ), + TP_printk("%s: trb %p, dma buf: 0x%08x, size: %ld, burst: %d ctrl: 0x%08x (%s%s%s%s%s%s%s)", + __get_str(name), __entry->trb, __entry->buffer, + TRB_LEN(__entry->length), + (u8)TRB_BURST_LEN_GET(__entry->length), + __entry->control, + __entry->control & TRB_CYCLE ? "C=1, " : "C=0, ", + __entry->control & TRB_TOGGLE ? "T=1, " : "T=0, ", + __entry->control & TRB_ISP ? "ISP, " : "", + __entry->control & TRB_FIFO_MODE ? "FIFO, " : "", + __entry->control & TRB_CHAIN ? "CHAIN, " : "", + __entry->control & TRB_IOC ? "IOC, " : "", + TRB_FIELD_TO_TYPE(__entry->control) == TRB_NORMAL ? "Normal" : "LINK" + ) +); + +DEFINE_EVENT(cdns3_log_trb, cdns3_prepare_trb, + TP_PROTO(struct cdns3_endpoint *priv_ep, struct cdns3_trb *trb), + TP_ARGS(priv_ep, trb) +); + +DEFINE_EVENT(cdns3_log_trb, cdns3_complete_trb, + TP_PROTO(struct cdns3_endpoint *priv_ep, struct cdns3_trb *trb), + TP_ARGS(priv_ep, trb) +); + +DECLARE_EVENT_CLASS(cdns3_log_ring, + TP_PROTO(struct cdns3_endpoint *priv_ep), + TP_ARGS(priv_ep), + TP_STRUCT__entry( + __dynamic_array(u8, ring, TRB_RING_SIZE) + __dynamic_array(u8, priv_ep, sizeof(struct cdns3_endpoint)) + __dynamic_array(char, buffer, + (TRBS_PER_SEGMENT * 65) + CDNS3_MSG_MAX) + ), + TP_fast_assign( + memcpy(__get_dynamic_array(priv_ep), priv_ep, + sizeof(struct cdns3_endpoint)); + memcpy(__get_dynamic_array(ring), priv_ep->trb_pool, + TRB_RING_SIZE); + ), + + TP_printk("%s", + cdns3_dbg_ring((struct cdns3_endpoint *)__get_str(priv_ep), + (struct cdns3_trb *)__get_str(ring), + __get_str(buffer))) +); + +DEFINE_EVENT(cdns3_log_ring, cdns3_ring, + TP_PROTO(struct cdns3_endpoint *priv_ep), + TP_ARGS(priv_ep) +); + +DECLARE_EVENT_CLASS(cdns3_log_ep, + TP_PROTO(struct cdns3_endpoint *priv_ep), + TP_ARGS(priv_ep), + TP_STRUCT__entry( + __string(name, priv_ep->name) + __field(unsigned int, maxpacket) + __field(unsigned int, maxpacket_limit) + __field(unsigned int, max_streams) + __field(unsigned int, maxburst) + __field(unsigned int, flags) + __field(unsigned int, dir) + __field(u8, enqueue) + __field(u8, dequeue) + ), + TP_fast_assign( + __assign_str(name, priv_ep->name); + __entry->maxpacket = priv_ep->endpoint.maxpacket; + __entry->maxpacket_limit = priv_ep->endpoint.maxpacket_limit; + __entry->max_streams = priv_ep->endpoint.max_streams; + __entry->maxburst = priv_ep->endpoint.maxburst; + __entry->flags = priv_ep->flags; + __entry->dir = priv_ep->dir; + __entry->enqueue = priv_ep->enqueue; + __entry->dequeue = priv_ep->dequeue; + ), + TP_printk("%s: mps: %d/%d. streams: %d, burst: %d, enq idx: %d, " + "deq idx: %d, flags %s%s%s%s%s%s%s%s, dir: %s", + __get_str(name), __entry->maxpacket, + __entry->maxpacket_limit, __entry->max_streams, + __entry->maxburst, __entry->enqueue, + __entry->dequeue, + __entry->flags & EP_ENABLED ? "EN | " : "", + __entry->flags & EP_STALL ? "STALL | " : "", + __entry->flags & EP_WEDGE ? "WEDGE | " : "", + __entry->flags & EP_TRANSFER_STARTED ? "STARTED | " : "", + __entry->flags & EP_UPDATE_EP_TRBADDR ? "UPD TRB | " : "", + __entry->flags & EP_PENDING_REQUEST ? "REQ PEN | " : "", + __entry->flags & EP_RING_FULL ? "RING FULL |" : "", + __entry->flags & EP_CLAIMED ? "CLAIMED " : "", + __entry->dir ? "IN" : "OUT" + ) +); + +DEFINE_EVENT(cdns3_log_ep, cdns3_gadget_ep_enable, + TP_PROTO(struct cdns3_endpoint *priv_ep), + TP_ARGS(priv_ep) +); + +DEFINE_EVENT(cdns3_log_ep, cdns3_gadget_ep_disable, + TP_PROTO(struct cdns3_endpoint *priv_ep), + TP_ARGS(priv_ep) +); + +DECLARE_EVENT_CLASS(cdns3_log_request_handled, + TP_PROTO(struct cdns3_request *priv_req, int current_index, + int handled), + TP_ARGS(priv_req, current_index, handled), + TP_STRUCT__entry( + __field(struct cdns3_request *, priv_req) + __field(unsigned int, dma_position) + __field(unsigned int, handled) + __field(unsigned int, dequeue_idx) + __field(unsigned int, enqueue_idx) + __field(unsigned int, start_trb) + __field(unsigned int, end_trb) + ), + TP_fast_assign( + __entry->priv_req = priv_req; + __entry->dma_position = current_index; + __entry->handled = handled; + __entry->dequeue_idx = priv_req->priv_ep->dequeue; + __entry->enqueue_idx = priv_req->priv_ep->enqueue; + __entry->start_trb = priv_req->start_trb; + __entry->end_trb = priv_req->end_trb; + ), + TP_printk("Req: %p %s, DMA pos: %d, ep deq: %d, ep enq: %d," + " start trb: %d, end trb: %d", + __entry->priv_req, + __entry->handled ? "handled" : "not handled", + __entry->dma_position, __entry->dequeue_idx, + __entry->enqueue_idx, __entry->start_trb, + __entry->end_trb + ) +); + +DEFINE_EVENT(cdns3_log_request_handled, cdns3_request_handled, + TP_PROTO(struct cdns3_request *priv_req, int current_index, + int handled), + TP_ARGS(priv_req, current_index, handled) +); +#endif /* __LINUX_CDNS3_TRACE */ + +/* this part must be outside header guard */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . + +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE trace + +#include -- cgit v1.2.3 From 573aff747ee350a0541c3a24cacd92a286fb9522 Mon Sep 17 00:00:00 2001 From: Pawel Laszczak Date: Tue, 2 Jul 2019 14:38:02 +0100 Subject: usb:cdns3 Fix for stuck packets in on-chip OUT buffer. Controller for OUT endpoints has shared on-chip buffers for all incoming packets, including ep0out. It's FIFO buffer, so packets must be handled by DMA in correct order. If the first packet in the buffer will not be handled, then the following packets directed for other endpoints and functions will be blocked. Additionally the packets directed to one endpoint can block entire on-chip buffers. In this case transfer to other endpoints also will blocked. To resolve this issue after raising the descriptor missing interrupt driver prepares internal usb_request object and use it to arm DMA transfer. The problematic situation was observed in case when endpoint has been enabled but no usb_request were queued. Driver try detects such endpoints and will use this workaround only for these endpoint. Driver use limited number of buffer. This number can be set by macro CDNS_WA2_NUM_BUFFERS. Such blocking situation was observed on ACM gadget. For this function host send OUT data packet but ACM function is not prepared for this packet. It's cause that buffer placed in on chip memory block transfer to other endpoints. Issue has been fixed for DEV_VER_V2 version of controller. Signed-off-by: Pawel Laszczak Signed-off-by: Felipe Balbi --- drivers/usb/cdns3/gadget.c | 330 ++++++++++++++++++++++++++++++++++++++++++++- drivers/usb/cdns3/gadget.h | 13 ++ 2 files changed, 341 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 4e9e8e43f634..63cde269db98 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -28,6 +28,32 @@ * * Issue has been fixed in DEV_VER_V3 version of controller. * + * Work around 2: + * Controller for OUT endpoints has shared on-chip buffers for all incoming + * packets, including ep0out. It's FIFO buffer, so packets must be handle by DMA + * in correct order. If the first packet in the buffer will not be handled, + * then the following packets directed for other endpoints and functions + * will be blocked. + * Additionally the packets directed to one endpoint can block entire on-chip + * buffers. In this case transfer to other endpoints also will blocked. + * + * To resolve this issue after raising the descriptor missing interrupt + * driver prepares internal usb_request object and use it to arm DMA transfer. + * + * The problematic situation was observed in case when endpoint has been enabled + * but no usb_request were queued. Driver try detects such endpoints and will + * use this workaround only for these endpoint. + * + * Driver use limited number of buffer. This number can be set by macro + * CDNS3_WA2_NUM_BUFFERS. + * + * Such blocking situation was observed on ACM gadget. For this function + * host send OUT data packet but ACM function is not prepared for this packet. + * It's cause that buffer placed in on chip memory block transfer to other + * endpoints. + * + * Issue has been fixed in DEV_VER_V2 version of controller. + * */ #include @@ -98,6 +124,17 @@ struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list) return list_first_entry_or_null(list, struct cdns3_aligned_buf, list); } +/** + * cdns3_next_priv_request - returns next request from list + * @list: list containing requests + * + * Returns request or NULL if no requests in list + */ +struct cdns3_request *cdns3_next_priv_request(struct list_head *list) +{ + return list_first_entry_or_null(list, struct cdns3_request, list); +} + /** * select_ep - selects endpoint * @priv_dev: extended gadget object @@ -335,6 +372,246 @@ static int cdns3_start_all_request(struct cdns3_device *priv_dev, return ret; } +/* + * WA2: Set flag for all not ISOC OUT endpoints. If this flag is set + * driver try to detect whether endpoint need additional internal + * buffer for unblocking on-chip FIFO buffer. This flag will be cleared + * if before first DESCMISS interrupt the DMA will be armed. + */ +#define cdns3_wa2_enable_detection(priv_dev, ep_priv, reg) do { \ + if (!priv_ep->dir && priv_ep->type != USB_ENDPOINT_XFER_ISOC) { \ + priv_ep->flags |= EP_QUIRK_EXTRA_BUF_DET; \ + (reg) |= EP_STS_EN_DESCMISEN; \ + } } while (0) + +/** + * cdns3_wa2_descmiss_copy_data copy data from internal requests to + * request queued by class driver. + * @priv_ep: extended endpoint object + * @request: request object + */ +static void cdns3_wa2_descmiss_copy_data(struct cdns3_endpoint *priv_ep, + struct usb_request *request) +{ + struct usb_request *descmiss_req; + struct cdns3_request *descmiss_priv_req; + + while (!list_empty(&priv_ep->wa2_descmiss_req_list)) { + int chunk_end; + int length; + + descmiss_priv_req = + cdns3_next_priv_request(&priv_ep->wa2_descmiss_req_list); + descmiss_req = &descmiss_priv_req->request; + + /* driver can't touch pending request */ + if (descmiss_priv_req->flags & REQUEST_PENDING) + break; + + chunk_end = descmiss_priv_req->flags & REQUEST_INTERNAL_CH; + length = request->actual + descmiss_req->actual; + + request->status = descmiss_req->status; + + if (length <= request->length) { + memcpy(&((u8 *)request->buf)[request->actual], + descmiss_req->buf, + descmiss_req->actual); + request->actual = length; + } else { + /* It should never occures */ + request->status = -ENOMEM; + } + + list_del_init(&descmiss_priv_req->list); + + kfree(descmiss_req->buf); + cdns3_gadget_ep_free_request(&priv_ep->endpoint, descmiss_req); + --priv_ep->wa2_counter; + + if (!chunk_end) + break; + } +} + +struct usb_request *cdns3_wa2_gadget_giveback(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep, + struct cdns3_request *priv_req) +{ + if (priv_ep->flags & EP_QUIRK_EXTRA_BUF_EN && + priv_req->flags & REQUEST_INTERNAL) { + struct usb_request *req; + + req = cdns3_next_request(&priv_ep->deferred_req_list); + + priv_ep->descmis_req = NULL; + + if (!req) + return NULL; + + cdns3_wa2_descmiss_copy_data(priv_ep, req); + if (!(priv_ep->flags & EP_QUIRK_END_TRANSFER) && + req->length != req->actual) { + /* wait for next part of transfer */ + return NULL; + } + + if (req->status == -EINPROGRESS) + req->status = 0; + + list_del_init(&req->list); + cdns3_start_all_request(priv_dev, priv_ep); + return req; + } + + return &priv_req->request; +} + +int cdns3_wa2_gadget_ep_queue(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep, + struct cdns3_request *priv_req) +{ + int deferred = 0; + + /* + * If transfer was queued before DESCMISS appear than we + * can disable handling of DESCMISS interrupt. Driver assumes that it + * can disable special treatment for this endpoint. + */ + if (priv_ep->flags & EP_QUIRK_EXTRA_BUF_DET) { + u32 reg; + + cdns3_select_ep(priv_dev, priv_ep->num | priv_ep->dir); + priv_ep->flags &= ~EP_QUIRK_EXTRA_BUF_DET; + reg = readl(&priv_dev->regs->ep_sts_en); + reg &= ~EP_STS_EN_DESCMISEN; + writel(reg, &priv_dev->regs->ep_sts_en); + } + + if (priv_ep->flags & EP_QUIRK_EXTRA_BUF_EN) { + u8 pending_empty = list_empty(&priv_ep->pending_req_list); + u8 descmiss_empty = list_empty(&priv_ep->wa2_descmiss_req_list); + + /* + * DESCMISS transfer has been finished, so data will be + * directly copied from internal allocated usb_request + * objects. + */ + if (pending_empty && !descmiss_empty && + !(priv_req->flags & REQUEST_INTERNAL)) { + cdns3_wa2_descmiss_copy_data(priv_ep, + &priv_req->request); + list_add_tail(&priv_req->request.list, + &priv_ep->pending_req_list); + cdns3_gadget_giveback(priv_ep, priv_req, + priv_req->request.status); + + /* + * Intentionally driver returns positive value as + * correct value. It informs that transfer has + * been finished. + */ + return EINPROGRESS; + } + + /* + * Driver will wait for completion DESCMISS transfer, + * before starts new, not DESCMISS transfer. + */ + if (!pending_empty && !descmiss_empty) + deferred = 1; + + if (priv_req->flags & REQUEST_INTERNAL) + list_add_tail(&priv_req->list, + &priv_ep->wa2_descmiss_req_list); + } + + return deferred; +} + +static void cdsn3_wa2_remove_old_request(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_request *priv_req; + + while (!list_empty(&priv_ep->wa2_descmiss_req_list)) { + u8 chain; + + priv_req = cdns3_next_priv_request(&priv_ep->wa2_descmiss_req_list); + chain = !!(priv_req->flags & REQUEST_INTERNAL_CH); + + kfree(priv_req->request.buf); + cdns3_gadget_ep_free_request(&priv_ep->endpoint, + &priv_req->request); + list_del_init(&priv_req->list); + --priv_ep->wa2_counter; + + if (!chain) + break; + } +} + +/** + * cdns3_wa2_descmissing_packet - handles descriptor missing event. + * @priv_dev: extended gadget object + * + * This function is used only for WA2. For more information see Work around 2 + * description. + */ +static void cdns3_wa2_descmissing_packet(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_request *priv_req; + struct usb_request *request; + + if (priv_ep->flags & EP_QUIRK_EXTRA_BUF_DET) { + priv_ep->flags &= ~EP_QUIRK_EXTRA_BUF_DET; + priv_ep->flags |= EP_QUIRK_EXTRA_BUF_EN; + } + + cdns3_dbg(priv_ep->cdns3_dev, "WA2: Description Missing detected\n"); + + if (priv_ep->wa2_counter >= CDNS3_WA2_NUM_BUFFERS) + cdsn3_wa2_remove_old_request(priv_ep); + + request = cdns3_gadget_ep_alloc_request(&priv_ep->endpoint, + GFP_ATOMIC); + if (!request) + goto err; + + priv_req = to_cdns3_request(request); + priv_req->flags |= REQUEST_INTERNAL; + + /* if this field is still assigned it indicate that transfer related + * with this request has not been finished yet. Driver in this + * case simply allocate next request and assign flag REQUEST_INTERNAL_CH + * flag to previous one. It will indicate that current request is + * part of the previous one. + */ + if (priv_ep->descmis_req) + priv_ep->descmis_req->flags |= REQUEST_INTERNAL_CH; + + priv_req->request.buf = kzalloc(CDNS3_DESCMIS_BUF_SIZE, + GFP_ATOMIC); + priv_ep->wa2_counter++; + + if (!priv_req->request.buf) { + cdns3_gadget_ep_free_request(&priv_ep->endpoint, request); + goto err; + } + + priv_req->request.length = CDNS3_DESCMIS_BUF_SIZE; + priv_ep->descmis_req = priv_req; + + __cdns3_gadget_ep_queue(&priv_ep->endpoint, + &priv_ep->descmis_req->request, + GFP_ATOMIC); + + return; + +err: + dev_err(priv_ep->cdns3_dev->dev, + "Failed: No sufficient memory for DESCMIS\n"); +} + /** * cdns3_gadget_giveback - call struct usb_request's ->complete callback * @priv_ep: The endpoint to whom the request belongs to @@ -368,6 +645,13 @@ void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, priv_req->flags &= ~(REQUEST_PENDING | REQUEST_UNALIGNED); trace_cdns3_gadget_giveback(priv_req); + if (priv_dev->dev_ver < DEV_VER_V2) { + request = cdns3_wa2_gadget_giveback(priv_dev, priv_ep, + priv_req); + if (!request) + return; + } + if (request->complete) { spin_unlock(&priv_dev->lock); usb_gadget_giveback_request(&priv_ep->endpoint, @@ -921,8 +1205,25 @@ static int cdns3_check_ep_interrupt_proceed(struct cdns3_endpoint *priv_ep) } } - if ((ep_sts_reg & EP_STS_IOC) || (ep_sts_reg & EP_STS_ISP)) + if ((ep_sts_reg & EP_STS_IOC) || (ep_sts_reg & EP_STS_ISP)) { + if (priv_ep->flags & EP_QUIRK_EXTRA_BUF_EN) { + if (ep_sts_reg & EP_STS_ISP) + priv_ep->flags |= EP_QUIRK_END_TRANSFER; + else + priv_ep->flags &= ~EP_QUIRK_END_TRANSFER; + } + cdns3_transfer_completed(priv_dev, priv_ep); + } + + /* + * WA2: this condition should only be meet when + * priv_ep->flags & EP_QUIRK_EXTRA_BUF_DET or + * priv_ep->flags & EP_QUIRK_EXTRA_BUF_EN. + * In other cases this interrupt will be disabled/ + */ + if (ep_sts_reg & EP_STS_DESCMIS && priv_dev->dev_ver < DEV_VER_V2) + cdns3_wa2_descmissing_packet(priv_ep); return 0; } @@ -1498,6 +1799,9 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep, cdns3_set_register_bit(&priv_dev->regs->ep_ien, BIT(cdns3_ep_addr_to_index(bEndpointAddress))); + if (priv_dev->dev_ver < DEV_VER_V2) + cdns3_wa2_enable_detection(priv_dev, priv_ep, reg); + writel(reg, &priv_dev->regs->ep_sts_en); /* @@ -1516,7 +1820,7 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep, ep->desc = desc; priv_ep->flags &= ~(EP_PENDING_REQUEST | EP_STALL | - EP_QUIRK_ISO_OUT_EN); + EP_QUIRK_ISO_OUT_EN | EP_QUIRK_EXTRA_BUF_EN); priv_ep->flags |= EP_ENABLED | EP_UPDATE_EP_TRBADDR; priv_ep->wa1_set = 0; priv_ep->enqueue = 0; @@ -1541,6 +1845,7 @@ exit: static int cdns3_gadget_ep_disable(struct usb_ep *ep) { struct cdns3_endpoint *priv_ep; + struct cdns3_request *priv_req; struct cdns3_device *priv_dev; struct usb_request *request; unsigned long flags; @@ -1593,6 +1898,16 @@ static int cdns3_gadget_ep_disable(struct usb_ep *ep) -ESHUTDOWN); } + while (!list_empty(&priv_ep->wa2_descmiss_req_list)) { + priv_req = cdns3_next_priv_request(&priv_ep->wa2_descmiss_req_list); + + kfree(priv_req->request.buf); + cdns3_gadget_ep_free_request(&priv_ep->endpoint, + &priv_req->request); + list_del_init(&priv_req->list); + --priv_ep->wa2_counter; + } + while (!list_empty(&priv_ep->deferred_req_list)) { request = cdns3_next_request(&priv_ep->deferred_req_list); @@ -1600,6 +1915,8 @@ static int cdns3_gadget_ep_disable(struct usb_ep *ep) -ESHUTDOWN); } + priv_ep->descmis_req = NULL; + ep->desc = NULL; priv_ep->flags &= ~EP_ENABLED; @@ -1630,6 +1947,14 @@ static int __cdns3_gadget_ep_queue(struct usb_ep *ep, priv_req = to_cdns3_request(request); trace_cdns3_ep_queue(priv_req); + if (priv_dev->dev_ver < DEV_VER_V2) { + ret = cdns3_wa2_gadget_ep_queue(priv_dev, priv_ep, + priv_req); + + if (ret == EINPROGRESS) + return 0; + } + ret = cdns3_prepare_aligned_request_buf(priv_req); if (ret < 0) return ret; @@ -2098,6 +2423,7 @@ static int cdns3_init_eps(struct cdns3_device *priv_dev) INIT_LIST_HEAD(&priv_ep->pending_req_list); INIT_LIST_HEAD(&priv_ep->deferred_req_list); + INIT_LIST_HEAD(&priv_ep->wa2_descmiss_req_list); } return 0; diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index 64cead1aee32..42f58048975f 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1079,6 +1079,7 @@ struct cdns3_trb { #define CDNS3_EP_ISO_SS_BURST 3 #define CDNS3_MAX_NUM_DESCMISS_BUF 32 #define CDNS3_DESCMIS_BUF_SIZE 2048 /* Bytes */ +#define CDNS3_WA2_NUM_BUFFERS 128 /*-------------------------------------------------------------------------*/ /* Used structs */ @@ -1089,11 +1090,15 @@ struct cdns3_device; * @endpoint: usb endpoint * @pending_req_list: list of requests queuing on transfer ring. * @deferred_req_list: list of requests waiting for queuing on transfer ring. + * @wa2_descmiss_req_list: list of requests internally allocated by driver. * @trb_pool: transfer ring - array of transaction buffers * @trb_pool_dma: dma address of transfer ring * @cdns3_dev: device associated with this endpoint * @name: a human readable name e.g. ep1out * @flags: specify the current state of endpoint + * @descmis_req: internal transfer object used for getting data from on-chip + * buffer. It can happen only if function driver doesn't send usb_request + * object on time. * @dir: endpoint direction * @num: endpoint number (1 - 15) * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK @@ -1110,6 +1115,8 @@ struct cdns3_endpoint { struct usb_ep endpoint; struct list_head pending_req_list; struct list_head deferred_req_list; + struct list_head wa2_descmiss_req_list; + int wa2_counter; struct cdns3_trb *trb_pool; dma_addr_t trb_pool_dma; @@ -1127,8 +1134,13 @@ struct cdns3_endpoint { #define EP_CLAIMED BIT(7) #define EP_DEFERRED_DRDY BIT(8) #define EP_QUIRK_ISO_OUT_EN BIT(9) +#define EP_QUIRK_EXTRA_BUF_DET BIT(10) +#define EP_QUIRK_EXTRA_BUF_EN BIT(11) +#define EP_QUIRK_END_TRANSFER BIT(12) u32 flags; + struct cdns3_request *descmis_req; + u8 dir; u8 num; u8 type; @@ -1176,6 +1188,7 @@ struct cdns3_aligned_buf { * @aligned_buf: object holds information about aligned buffer associated whit * this endpoint * @flags: flag specifying special usage of request + * @list: used by internally allocated request to add to wa2_descmiss_req_list. */ struct cdns3_request { struct usb_request request; -- cgit v1.2.3 From 8cf8bde284b7a25229cbf119cbf8be8149132a5c Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Mon, 24 Jun 2019 10:02:51 +0800 Subject: doc: dt-binding: mxs-usb-phy: add compatible for 7ulp Add compatible for 7ulp USB PHY. Reviewed-by: Rob Herring Signed-off-by: Peter Chen Signed-off-by: Felipe Balbi --- Documentation/devicetree/bindings/phy/mxs-usb-phy.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/phy/mxs-usb-phy.txt b/Documentation/devicetree/bindings/phy/mxs-usb-phy.txt index 6ac98b3b5f57..c9f5c0caf8a9 100644 --- a/Documentation/devicetree/bindings/phy/mxs-usb-phy.txt +++ b/Documentation/devicetree/bindings/phy/mxs-usb-phy.txt @@ -7,6 +7,7 @@ Required properties: * "fsl,imx6sl-usbphy" for imx6sl * "fsl,vf610-usbphy" for Vybrid vf610 * "fsl,imx6sx-usbphy" for imx6sx + * "fsl,imx7ulp-usbphy" for imx7ulp "fsl,imx23-usbphy" is still a fallback for other strings - reg: Should contain registers location and length - interrupts: Should contain phy interrupt @@ -23,7 +24,7 @@ Optional properties: the 17.78mA TX reference current. Default: 100 Example: -usbphy1: usbphy@20c9000 { +usbphy1: usb-phy@20c9000 { compatible = "fsl,imx6q-usbphy", "fsl,imx23-usbphy"; reg = <0x020c9000 0x1000>; interrupts = <0 44 0x04>; -- cgit v1.2.3 From 99e8232b5f3ae18208930775dc8c5821c6f9384a Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Mon, 24 Jun 2019 10:02:52 +0800 Subject: usb: phy: phy-mxs-usb: add imx7ulp support At imx7ulp, the USB related analog register is located in PHY register region too, so we need to control PLL at PHY driver directly. Signed-off-by: Peter Chen Signed-off-by: Felipe Balbi --- drivers/usb/phy/phy-mxs-usb.c | 67 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c index 6fa16ab31e2e..70b8c8248caf 100644 --- a/drivers/usb/phy/phy-mxs-usb.c +++ b/drivers/usb/phy/phy-mxs-usb.c @@ -17,9 +17,11 @@ #include #include #include +#include #define DRIVER_NAME "mxs_phy" +/* Register Macro */ #define HW_USBPHY_PWD 0x00 #define HW_USBPHY_TX 0x10 #define HW_USBPHY_CTRL 0x30 @@ -37,6 +39,11 @@ #define GM_USBPHY_TX_TXCAL45DN(x) (((x) & 0xf) << 8) #define GM_USBPHY_TX_D_CAL(x) (((x) & 0xf) << 0) +/* imx7ulp */ +#define HW_USBPHY_PLL_SIC 0xa0 +#define HW_USBPHY_PLL_SIC_SET 0xa4 +#define HW_USBPHY_PLL_SIC_CLR 0xa8 + #define BM_USBPHY_CTRL_SFTRST BIT(31) #define BM_USBPHY_CTRL_CLKGATE BIT(30) #define BM_USBPHY_CTRL_OTG_ID_VALUE BIT(27) @@ -55,6 +62,12 @@ #define BM_USBPHY_IP_FIX (BIT(17) | BIT(18)) #define BM_USBPHY_DEBUG_CLKGATE BIT(30) +/* imx7ulp */ +#define BM_USBPHY_PLL_LOCK BIT(31) +#define BM_USBPHY_PLL_REG_ENABLE BIT(21) +#define BM_USBPHY_PLL_BYPASS BIT(16) +#define BM_USBPHY_PLL_POWER BIT(12) +#define BM_USBPHY_PLL_EN_USB_CLKS BIT(6) /* Anatop Registers */ #define ANADIG_ANA_MISC0 0x150 @@ -168,6 +181,9 @@ static const struct mxs_phy_data imx6ul_phy_data = { .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS, }; +static const struct mxs_phy_data imx7ulp_phy_data = { +}; + static const struct of_device_id mxs_phy_dt_ids[] = { { .compatible = "fsl,imx6sx-usbphy", .data = &imx6sx_phy_data, }, { .compatible = "fsl,imx6sl-usbphy", .data = &imx6sl_phy_data, }, @@ -175,6 +191,7 @@ static const struct of_device_id mxs_phy_dt_ids[] = { { .compatible = "fsl,imx23-usbphy", .data = &imx23_phy_data, }, { .compatible = "fsl,vf610-usbphy", .data = &vf610_phy_data, }, { .compatible = "fsl,imx6ul-usbphy", .data = &imx6ul_phy_data, }, + { .compatible = "fsl,imx7ulp-usbphy", .data = &imx7ulp_phy_data, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, mxs_phy_dt_ids); @@ -199,6 +216,11 @@ static inline bool is_imx6sl_phy(struct mxs_phy *mxs_phy) return mxs_phy->data == &imx6sl_phy_data; } +static inline bool is_imx7ulp_phy(struct mxs_phy *mxs_phy) +{ + return mxs_phy->data == &imx7ulp_phy_data; +} + /* * PHY needs some 32K cycles to switch from 32K clock to * bus (such as AHB/AXI, etc) clock. @@ -222,14 +244,49 @@ static void mxs_phy_tx_init(struct mxs_phy *mxs_phy) } } +static int mxs_phy_pll_enable(void __iomem *base, bool enable) +{ + int ret = 0; + + if (enable) { + u32 value; + + writel(BM_USBPHY_PLL_REG_ENABLE, base + HW_USBPHY_PLL_SIC_SET); + writel(BM_USBPHY_PLL_BYPASS, base + HW_USBPHY_PLL_SIC_CLR); + writel(BM_USBPHY_PLL_POWER, base + HW_USBPHY_PLL_SIC_SET); + ret = readl_poll_timeout(base + HW_USBPHY_PLL_SIC, + value, (value & BM_USBPHY_PLL_LOCK) != 0, + 100, 10000); + if (ret) + return ret; + + writel(BM_USBPHY_PLL_EN_USB_CLKS, base + + HW_USBPHY_PLL_SIC_SET); + } else { + writel(BM_USBPHY_PLL_EN_USB_CLKS, base + + HW_USBPHY_PLL_SIC_CLR); + writel(BM_USBPHY_PLL_POWER, base + HW_USBPHY_PLL_SIC_CLR); + writel(BM_USBPHY_PLL_BYPASS, base + HW_USBPHY_PLL_SIC_SET); + writel(BM_USBPHY_PLL_REG_ENABLE, base + HW_USBPHY_PLL_SIC_CLR); + } + + return ret; +} + static int mxs_phy_hw_init(struct mxs_phy *mxs_phy) { int ret; void __iomem *base = mxs_phy->phy.io_priv; + if (is_imx7ulp_phy(mxs_phy)) { + ret = mxs_phy_pll_enable(base, true); + if (ret) + return ret; + } + ret = stmp_reset_block(base + HW_USBPHY_CTRL); if (ret) - return ret; + goto disable_pll; /* Power up the PHY */ writel(0, base + HW_USBPHY_PWD); @@ -267,6 +324,11 @@ static int mxs_phy_hw_init(struct mxs_phy *mxs_phy) mxs_phy_tx_init(mxs_phy); return 0; + +disable_pll: + if (is_imx7ulp_phy(mxs_phy)) + mxs_phy_pll_enable(base, false); + return ret; } /* Return true if the vbus is there */ @@ -388,6 +450,9 @@ static void mxs_phy_shutdown(struct usb_phy *phy) writel(BM_USBPHY_CTRL_CLKGATE, phy->io_priv + HW_USBPHY_CTRL_SET); + if (is_imx7ulp_phy(mxs_phy)) + mxs_phy_pll_enable(phy->io_priv, false); + clk_disable_unprepare(mxs_phy->clk); } -- cgit v1.2.3 From d2d06c18d78ed4aa969ceac33bcfdcc524668424 Mon Sep 17 00:00:00 2001 From: Hariprasad Kelam Date: Tue, 2 Jul 2019 00:02:41 +0530 Subject: USB: gadget: function: fix issue Unneeded variable: "value" fix below issue reported by coccicheck drivers/usb/gadget/function/f_eem.c:169:7-12: Unneeded variable: "value". Return "- EOPNOTSUPP" on line 179 We can not change return type of eem_setup as its registered with callback function Signed-off-by: Hariprasad Kelam Signed-off-by: Felipe Balbi --- drivers/usb/gadget/function/f_eem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_eem.c b/drivers/usb/gadget/function/f_eem.c index c13befa31110..b81a91d504bd 100644 --- a/drivers/usb/gadget/function/f_eem.c +++ b/drivers/usb/gadget/function/f_eem.c @@ -166,7 +166,6 @@ static struct usb_gadget_strings *eem_strings[] = { static int eem_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) { struct usb_composite_dev *cdev = f->config->cdev; - int value = -EOPNOTSUPP; u16 w_index = le16_to_cpu(ctrl->wIndex); u16 w_value = le16_to_cpu(ctrl->wValue); u16 w_length = le16_to_cpu(ctrl->wLength); @@ -176,7 +175,7 @@ static int eem_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) w_value, w_index, w_length); /* device either stalls (value < 0) or reports success */ - return value; + return -EOPNOTSUPP; } -- cgit v1.2.3 From dfc4fdebc5d62ac4e2fe5428e59b273675515fb2 Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Thu, 20 Jun 2019 19:50:22 +0200 Subject: usb: dwc2: use a longer AHB idle timeout in dwc2_core_reset() Use a 10000us AHB idle timeout in dwc2_core_reset() and make it consistent with the other "wait for AHB master IDLE state" ocurrences. This fixes a problem for me where dwc2 would not want to initialize when updating to 4.19 on a MIPS Lantiq VRX200 SoC. dwc2 worked fine with 4.14. Testing on my board shows that it takes 180us until AHB master IDLE state is signalled. The very old vendor driver for this SoC (ifxhcd) used a 1 second timeout. Use the same timeout that is used everywhere when polling for GRSTCTL_AHBIDLE instead of using a timeout that "works for one board" (180us in my case) to have consistent behavior across the dwc2 driver. Cc: linux-stable # 4.19+ Acked-by: Minas Harutyunyan Signed-off-by: Martin Blumenstingl Signed-off-by: Felipe Balbi --- drivers/usb/dwc2/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index 8b499d643461..8e41d70fd298 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c @@ -531,7 +531,7 @@ int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait) } /* Wait for AHB master IDLE state */ - if (dwc2_hsotg_wait_bit_set(hsotg, GRSTCTL, GRSTCTL_AHBIDLE, 50)) { + if (dwc2_hsotg_wait_bit_set(hsotg, GRSTCTL, GRSTCTL_AHBIDLE, 10000)) { dev_warn(hsotg->dev, "%s: HANG! AHB Idle timeout GRSTCTL GRSTCTL_AHBIDLE\n", __func__); return -EBUSY; -- cgit v1.2.3 From 4aef7966060439bb4f9d440feacd5ce7697bce37 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Wed, 26 Jun 2019 17:35:17 +0100 Subject: usb: gadget: udc: renesas_usb3: remove redundant assignment to ret Variable ret is being initialized with a value that is never read and ret is being re-assigned immediately after the initialization in both paths of an if statement. This is redundant and can be removed. Addresses-Coverity: ("Unused value") Reviewed-by: Yoshihiro Shimoda Signed-off-by: Colin Ian King Signed-off-by: Felipe Balbi --- drivers/usb/gadget/udc/renesas_usb3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c index 5a960fce31c5..87062d22134d 100644 --- a/drivers/usb/gadget/udc/renesas_usb3.c +++ b/drivers/usb/gadget/udc/renesas_usb3.c @@ -1168,7 +1168,7 @@ static void usb3_set_status_stage(struct renesas_usb3_ep *usb3_ep, static void usb3_p0_xfer(struct renesas_usb3_ep *usb3_ep, struct renesas_usb3_request *usb3_req) { - int ret = -EAGAIN; + int ret; if (usb3_ep->dir_in) ret = usb3_write_pipe(usb3_ep, usb3_req, USB3_P0_WRITE); -- cgit v1.2.3 From b2357839c56ab7d06bcd4e866ebc2d0e2b7997f3 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Wed, 26 Jun 2019 22:06:33 +0900 Subject: usb: renesas_usbhs: add a workaround for a race condition of workqueue The old commit 6e4b74e4690d ("usb: renesas: fix scheduling in atomic context bug") fixed an atomic issue by using workqueue for the shdmac dmaengine driver. However, this has a potential race condition issue between the work pending and usbhsg_ep_free_request() in gadget mode. When usbhsg_ep_free_request() is called while pending the queue, since the work_struct will be freed and then the work handler is called, kernel panic happens on process_one_work(). To fix the issue, if we could call cancel_work_sync() at somewhere before the free request, it could be easy. However, the usbhsg_ep_free_request() is called on atomic (e.g. f_ncm driver calls free request via gether_disconnect()). For now, almost all users are having "USB-DMAC" and the DMAengine driver can be used on atomic. So, this patch adds a workaround for a race condition to call the DMAengine APIs without the workqueue. This means we still have TODO on shdmac environment (SH7724), but since it doesn't have SMP, the race condition might not happen. Fixes: ab330cf3888d ("usb: renesas_usbhs: add support for USB-DMAC") Cc: # v4.1+ Signed-off-by: Yoshihiro Shimoda Signed-off-by: Felipe Balbi --- drivers/usb/renesas_usbhs/fifo.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c index e84d2ac2a30a..1a0ab639dd22 100644 --- a/drivers/usb/renesas_usbhs/fifo.c +++ b/drivers/usb/renesas_usbhs/fifo.c @@ -803,9 +803,8 @@ static int __usbhsf_dma_map_ctrl(struct usbhs_pkt *pkt, int map) } static void usbhsf_dma_complete(void *arg); -static void xfer_work(struct work_struct *work) +static void usbhsf_dma_xfer_preparing(struct usbhs_pkt *pkt) { - struct usbhs_pkt *pkt = container_of(work, struct usbhs_pkt, work); struct usbhs_pipe *pipe = pkt->pipe; struct usbhs_fifo *fifo; struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); @@ -813,12 +812,10 @@ static void xfer_work(struct work_struct *work) struct dma_chan *chan; struct device *dev = usbhs_priv_to_dev(priv); enum dma_transfer_direction dir; - unsigned long flags; - usbhs_lock(priv, flags); fifo = usbhs_pipe_to_fifo(pipe); if (!fifo) - goto xfer_work_end; + return; chan = usbhsf_dma_chan_get(fifo, pkt); dir = usbhs_pipe_is_dir_in(pipe) ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV; @@ -827,7 +824,7 @@ static void xfer_work(struct work_struct *work) pkt->trans, dir, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); if (!desc) - goto xfer_work_end; + return; desc->callback = usbhsf_dma_complete; desc->callback_param = pipe; @@ -835,7 +832,7 @@ static void xfer_work(struct work_struct *work) pkt->cookie = dmaengine_submit(desc); if (pkt->cookie < 0) { dev_err(dev, "Failed to submit dma descriptor\n"); - goto xfer_work_end; + return; } dev_dbg(dev, " %s %d (%d/ %d)\n", @@ -846,8 +843,17 @@ static void xfer_work(struct work_struct *work) dma_async_issue_pending(chan); usbhsf_dma_start(pipe, fifo); usbhs_pipe_enable(pipe); +} + +static void xfer_work(struct work_struct *work) +{ + struct usbhs_pkt *pkt = container_of(work, struct usbhs_pkt, work); + struct usbhs_pipe *pipe = pkt->pipe; + struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); + unsigned long flags; -xfer_work_end: + usbhs_lock(priv, flags); + usbhsf_dma_xfer_preparing(pkt); usbhs_unlock(priv, flags); } @@ -900,8 +906,13 @@ static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done) pkt->trans = len; usbhsf_tx_irq_ctrl(pipe, 0); - INIT_WORK(&pkt->work, xfer_work); - schedule_work(&pkt->work); + /* FIXME: Workaound for usb dmac that driver can be used in atomic */ + if (usbhs_get_dparam(priv, has_usb_dmac)) { + usbhsf_dma_xfer_preparing(pkt); + } else { + INIT_WORK(&pkt->work, xfer_work); + schedule_work(&pkt->work); + } return 0; @@ -1007,8 +1018,7 @@ static int usbhsf_dma_prepare_pop_with_usb_dmac(struct usbhs_pkt *pkt, pkt->trans = pkt->length; - INIT_WORK(&pkt->work, xfer_work); - schedule_work(&pkt->work); + usbhsf_dma_xfer_preparing(pkt); return 0; -- cgit v1.2.3 From 349148785b8cea9781af520fd53c29ee8087ee74 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Tue, 18 Jun 2019 19:44:54 -0300 Subject: usb: storage: scsiglue: Do not skip VPD if try_vpd_pages is set If BLIST_TRY_VPD_PAGES is set for a device, even for an USB, it should be honored, so only set skip_vpd_pages is try_vpd_pages is not set. Signed-off-by: Marcos Paulo de Souza Acked-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/scsiglue.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c index 59190d88fa9f..30790240aec6 100644 --- a/drivers/usb/storage/scsiglue.c +++ b/drivers/usb/storage/scsiglue.c @@ -195,8 +195,11 @@ static int slave_configure(struct scsi_device *sdev) */ sdev->skip_ms_page_8 = 1; - /* Some devices don't handle VPD pages correctly */ - sdev->skip_vpd_pages = 1; + /* + * Some devices don't handle VPD pages correctly, so skip vpd + * pages if not forced by SCSI layer. + */ + sdev->skip_vpd_pages = !sdev->try_vpd_pages; /* Do not attempt to use REPORT SUPPORTED OPERATION CODES */ sdev->no_report_opcodes = 1; -- cgit v1.2.3 From 05da75fc651138e51ff74ace97174349910463f5 Mon Sep 17 00:00:00 2001 From: Nikolaus Voss Date: Fri, 28 Jun 2019 11:01:08 +0200 Subject: drivers/usb/typec/tps6598x.c: fix portinfo width Portinfo bit field is 3 bits wide, not 2 bits. This led to a wrong driver configuration for some tps6598x configurations. Fixes: 0a4c005bd171 ("usb: typec: driver for TI TPS6598x USB Power Delivery controllers") Signed-off-by: Nikolaus Voss Acked-by: Heikki Krogerus Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/tps6598x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c index c674abe3cf99..a170c49c2542 100644 --- a/drivers/usb/typec/tps6598x.c +++ b/drivers/usb/typec/tps6598x.c @@ -41,7 +41,7 @@ #define TPS_STATUS_VCONN(s) (!!((s) & BIT(7))) /* TPS_REG_SYSTEM_CONF bits */ -#define TPS_SYSCONF_PORTINFO(c) ((c) & 3) +#define TPS_SYSCONF_PORTINFO(c) ((c) & 7) enum { TPS_PORTINFO_SINK, -- cgit v1.2.3 From 2681795b5e7a5bf336537661010072f4c22cea31 Mon Sep 17 00:00:00 2001 From: Nikolaus Voss Date: Fri, 28 Jun 2019 11:01:09 +0200 Subject: drivers/usb/typec/tps6598x.c: fix 4CC cmd write Writing 4CC commands with tps6598x_write_4cc() already has a pointer arg, don't reference it when using as arg to tps6598x_block_write(). Correcting this enforces the constness of the pointer to propagate to tps6598x_block_write(), so add the const qualifier there to avoid the warning. Fixes: 0a4c005bd171 ("usb: typec: driver for TI TPS6598x USB Power Delivery controllers") Signed-off-by: Nikolaus Voss Acked-by: Heikki Krogerus Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/tps6598x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c index a170c49c2542..a38d1409f15b 100644 --- a/drivers/usb/typec/tps6598x.c +++ b/drivers/usb/typec/tps6598x.c @@ -127,7 +127,7 @@ tps6598x_block_read(struct tps6598x *tps, u8 reg, void *val, size_t len) } static int tps6598x_block_write(struct tps6598x *tps, u8 reg, - void *val, size_t len) + const void *val, size_t len) { u8 data[TPS_MAX_LEN + 1]; @@ -173,7 +173,7 @@ static inline int tps6598x_write64(struct tps6598x *tps, u8 reg, u64 val) static inline int tps6598x_write_4cc(struct tps6598x *tps, u8 reg, const char *val) { - return tps6598x_block_write(tps, reg, &val, sizeof(u32)); + return tps6598x_block_write(tps, reg, val, 4); } static int tps6598x_read_partner_identity(struct tps6598x *tps) -- cgit v1.2.3 From e244c4699f859cf7149b0781b1894c7996a8a1df Mon Sep 17 00:00:00 2001 From: "Lee, Chiasheng" Date: Thu, 20 Jun 2019 10:56:04 +0300 Subject: usb: Handle USB3 remote wakeup for LPM enabled devices correctly With Link Power Management (LPM) enabled USB3 links transition to low power U1/U2 link states from U0 state automatically. Current hub code detects USB3 remote wakeups by checking if the software state still shows suspended, but the link has transitioned from suspended U3 to enabled U0 state. As it takes some time before the hub thread reads the port link state after a USB3 wake notification, the link may have transitioned from U0 to U1/U2, and wake is not detected by hub code. Fix this by handling U1/U2 states in the same way as U0 in USB3 wakeup handling This patch should be added to stable kernels since 4.13 where LPM was kept enabled during suspend/resume Cc: # v4.13+ Signed-off-by: Lee, Chiasheng Signed-off-by: Mathias Nyman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hub.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index a59e1573b43b..236313f41f4a 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -3619,6 +3619,7 @@ static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, struct usb_device *hdev; struct usb_device *udev; int connect_change = 0; + u16 link_state; int ret; hdev = hub->hdev; @@ -3628,9 +3629,11 @@ static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, return 0; usb_clear_port_feature(hdev, port, USB_PORT_FEAT_C_SUSPEND); } else { + link_state = portstatus & USB_PORT_STAT_LINK_STATE; if (!udev || udev->state != USB_STATE_SUSPENDED || - (portstatus & USB_PORT_STAT_LINK_STATE) != - USB_SS_PORT_LS_U0) + (link_state != USB_SS_PORT_LS_U0 && + link_state != USB_SS_PORT_LS_U1 && + link_state != USB_SS_PORT_LS_U2)) return 0; } -- cgit v1.2.3 From 4f182835508c2d3dc6f5cc0e56b65b4c1ca325f8 Mon Sep 17 00:00:00 2001 From: Nikhil Badola Date: Mon, 24 Jun 2019 15:22:15 +0800 Subject: usb: fsl: Set USB_EN bit to select ULPI phy Set USB_EN bit to select ULPI phy for USB controller version 2.5 Signed-off-by: Nikhil Badola Signed-off-by: Yinbo Zhu Link: https://lore.kernel.org/r/20190624072219.15258-1-yinbo.zhu@nxp.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-fsl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index e3d0c1c25160..38674b7aa51e 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c @@ -122,6 +122,12 @@ static int fsl_ehci_drv_probe(struct platform_device *pdev) tmp |= 0x4; iowrite32be(tmp, hcd->regs + FSL_SOC_USB_CTRL); } + + /* Set USB_EN bit to select ULPI phy for USB controller version 2.5 */ + if (pdata->controller_ver == FSL_USB_VER_2_5 && + pdata->phy_mode == FSL_USB2_PHY_ULPI) + iowrite32be(USB_CTRL_USB_EN, hcd->regs + FSL_SOC_USB_CTRL); + /* * Enable UTMI phy and program PTS field in UTMI mode before asserting * controller reset for USB Controller version 2.5 -- cgit v1.2.3 From 5dfff995f9cb21c2910e40f5d4da53473356a792 Mon Sep 17 00:00:00 2001 From: Suresh Gupta Date: Mon, 24 Jun 2019 15:22:16 +0800 Subject: usb: phy: Workaround for USB erratum-A005728 PHY_CLK_VALID bit for UTMI PHY in USBDR does not set even if PHY is providing valid clock. Workaround for this involves resetting of PHY and check PHY_CLK_VALID bit multiple times. If PHY_CLK_VALID bit is still not set even after 5 retries, it would be safe to deaclare that PHY clock is not available. This erratum is applicable for USBDR less then ver 2.4. Signed-off-by: Suresh Gupta Signed-off-by: Yinbo Zhu Link: https://lore.kernel.org/r/20190624072219.15258-2-yinbo.zhu@nxp.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-fsl.c | 37 ++++++++++++++++++++++++++----------- drivers/usb/host/ehci-fsl.h | 3 +++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index 38674b7aa51e..8f3bf3efb038 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c @@ -183,6 +183,17 @@ static int fsl_ehci_drv_probe(struct platform_device *pdev) return retval; } +static bool usb_phy_clk_valid(struct usb_hcd *hcd) +{ + void __iomem *non_ehci = hcd->regs; + bool ret = true; + + if (!(ioread32be(non_ehci + FSL_SOC_USB_CTRL) & PHY_CLK_VALID)) + ret = false; + + return ret; +} + static int ehci_fsl_setup_phy(struct usb_hcd *hcd, enum fsl_usb2_phy_modes phy_mode, unsigned int port_offset) @@ -226,6 +237,16 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd, /* fall through */ case FSL_USB2_PHY_UTMI: case FSL_USB2_PHY_UTMI_DUAL: + /* PHY_CLK_VALID bit is de-featured from all controller + * versions below 2.4 and is to be checked only for + * internal UTMI phy + */ + if (pdata->controller_ver > FSL_USB_VER_2_4 && + pdata->have_sysif_regs && !usb_phy_clk_valid(hcd)) { + dev_err(dev, "USB PHY clock invalid\n"); + return -EINVAL; + } + if (pdata->have_sysif_regs && pdata->controller_ver) { /* controller version 1.6 or above */ tmp = ioread32be(non_ehci + FSL_SOC_USB_CTRL); @@ -249,17 +270,11 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd, break; } - /* - * check PHY_CLK_VALID to determine phy clock presence before writing - * to portsc - */ - if (pdata->check_phy_clk_valid) { - if (!(ioread32be(non_ehci + FSL_SOC_USB_CTRL) & - PHY_CLK_VALID)) { - dev_warn(hcd->self.controller, - "USB PHY clock invalid\n"); - return -EINVAL; - } + if (pdata->have_sysif_regs && + pdata->controller_ver > FSL_USB_VER_1_6 && + !usb_phy_clk_valid(hcd)) { + dev_warn(hcd->self.controller, "USB PHY clock invalid\n"); + return -EINVAL; } ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]); diff --git a/drivers/usb/host/ehci-fsl.h b/drivers/usb/host/ehci-fsl.h index cbc422032e50..9d18c6e6ab27 100644 --- a/drivers/usb/host/ehci-fsl.h +++ b/drivers/usb/host/ehci-fsl.h @@ -50,4 +50,7 @@ #define UTMI_PHY_EN (1<<9) #define ULPI_PHY_CLK_SEL (1<<10) #define PHY_CLK_VALID (1<<17) + +/* Retry count for checking UTMI PHY CLK validity */ +#define UTMI_PHY_CLK_VALID_CHK_RETRY 5 #endif /* _EHCI_FSL_H */ -- cgit v1.2.3 From 1a4dcb8aed681c426954b1cf7e4b78aab465690e Mon Sep 17 00:00:00 2001 From: Yinbo Zhu Date: Mon, 24 Jun 2019 15:22:17 +0800 Subject: usb: linux/fsl_device: Add platform member has_fsl_erratum_a006918 This patch is to add member has_fsl_erratum_a006918 in platform data Signed-off-by: Yinbo Zhu Link: https://lore.kernel.org/r/20190624072219.15258-3-yinbo.zhu@nxp.com Signed-off-by: Greg Kroah-Hartman --- include/linux/fsl_devices.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/fsl_devices.h b/include/linux/fsl_devices.h index cb2b46f57af3..5d231ce8709b 100644 --- a/include/linux/fsl_devices.h +++ b/include/linux/fsl_devices.h @@ -98,6 +98,7 @@ struct fsl_usb2_platform_data { unsigned has_fsl_erratum_14:1; unsigned has_fsl_erratum_a005275:1; unsigned has_fsl_erratum_a005697:1; + unsigned has_fsl_erratum_a006918:1; unsigned check_phy_clk_valid:1; /* register save area for suspend/resume */ -- cgit v1.2.3 From c1f9d2e4110cbcbbba844406e58ed41120166a73 Mon Sep 17 00:00:00 2001 From: Ramneek Mehresh Date: Mon, 24 Jun 2019 15:22:18 +0800 Subject: usb: host: Stops USB controller init if PLL fails to lock USB erratum-A006918 workaround tries to start internal PHY inside uboot (when PLL fails to lock). However, if the workaround also fails, then USB initialization is also stopped inside Linux. Erratum-A006918 workaround failure creates "fsl,erratum_a006918" node in device-tree. Presence of this node in device-tree is used to stop USB controller initialization in Linux Signed-off-by: Ramneek Mehresh Signed-off-by: Suresh Gupta Signed-off-by: Yinbo Zhu Link: https://lore.kernel.org/r/20190624072219.15258-4-yinbo.zhu@nxp.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-fsl.c | 9 +++++++++ drivers/usb/host/fsl-mph-dr-of.c | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index 8f3bf3efb038..9e9c232e896f 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c @@ -236,6 +236,15 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd, portsc |= PORT_PTS_PTW; /* fall through */ case FSL_USB2_PHY_UTMI: + /* Presence of this node "has_fsl_erratum_a006918" + * in device-tree is used to stop USB controller + * initialization in Linux + */ + if (pdata->has_fsl_erratum_a006918) { + dev_warn(dev, "USB PHY clock invalid\n"); + return -EINVAL; + } + /* fall through */ case FSL_USB2_PHY_UTMI_DUAL: /* PHY_CLK_VALID bit is de-featured from all controller * versions below 2.4 and is to be checked only for diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c index 4f8b8a08c914..762b97600ab0 100644 --- a/drivers/usb/host/fsl-mph-dr-of.c +++ b/drivers/usb/host/fsl-mph-dr-of.c @@ -224,13 +224,14 @@ static int fsl_usb2_mph_dr_of_probe(struct platform_device *ofdev) of_property_read_bool(np, "fsl,usb-erratum-a005275"); pdata->has_fsl_erratum_a005697 = of_property_read_bool(np, "fsl,usb_erratum-a005697"); + pdata->has_fsl_erratum_a006918 = + of_property_read_bool(np, "fsl,usb_erratum-a006918"); if (of_get_property(np, "fsl,usb_erratum_14", NULL)) pdata->has_fsl_erratum_14 = 1; else pdata->has_fsl_erratum_14 = 0; - /* * Determine whether phy_clk_valid needs to be checked * by reading property in device tree -- cgit v1.2.3 From a387fd90d4685b97352f1f6b2773b9402d26ec54 Mon Sep 17 00:00:00 2001 From: Nikhil Badola Date: Mon, 24 Jun 2019 15:22:19 +0800 Subject: usb :fsl: Change string format for errata property Remove USB errata checking code from driver. Applicability of erratum is retrieved by reading corresponding property in device tree. This property is written during device tree fixup. Signed-off-by: Ramneek Mehresh Signed-off-by: Nikhil Badola Signed-off-by: Yinbo Zhu Link: https://lore.kernel.org/r/20190624072219.15258-5-yinbo.zhu@nxp.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/fsl-mph-dr-of.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c index 762b97600ab0..ae8f60f6e6a5 100644 --- a/drivers/usb/host/fsl-mph-dr-of.c +++ b/drivers/usb/host/fsl-mph-dr-of.c @@ -226,11 +226,8 @@ static int fsl_usb2_mph_dr_of_probe(struct platform_device *ofdev) of_property_read_bool(np, "fsl,usb_erratum-a005697"); pdata->has_fsl_erratum_a006918 = of_property_read_bool(np, "fsl,usb_erratum-a006918"); - - if (of_get_property(np, "fsl,usb_erratum_14", NULL)) - pdata->has_fsl_erratum_14 = 1; - else - pdata->has_fsl_erratum_14 = 0; + pdata->has_fsl_erratum_14 = + of_property_read_bool(np, "fsl,usb_erratum-14"); /* * Determine whether phy_clk_valid needs to be checked -- cgit v1.2.3 From bff2a75bd77f668e538fbdf0558b1114933fbf87 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 4 Jul 2019 13:00:50 +0200 Subject: Revert "usb:cdns3 Fix for stuck packets in on-chip OUT buffer." This reverts commit 573aff747ee350a0541c3a24cacd92a286fb9522. It's broken. Reported-by: Stephen Rothwell Cc: Felipe Balbi Cc: Pawel Laszczak Signed-off-by: Greg Kroah-Hartman --- drivers/usb/cdns3/gadget.c | 330 +-------------------------------------------- drivers/usb/cdns3/gadget.h | 13 -- 2 files changed, 2 insertions(+), 341 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 63cde269db98..4e9e8e43f634 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -28,32 +28,6 @@ * * Issue has been fixed in DEV_VER_V3 version of controller. * - * Work around 2: - * Controller for OUT endpoints has shared on-chip buffers for all incoming - * packets, including ep0out. It's FIFO buffer, so packets must be handle by DMA - * in correct order. If the first packet in the buffer will not be handled, - * then the following packets directed for other endpoints and functions - * will be blocked. - * Additionally the packets directed to one endpoint can block entire on-chip - * buffers. In this case transfer to other endpoints also will blocked. - * - * To resolve this issue after raising the descriptor missing interrupt - * driver prepares internal usb_request object and use it to arm DMA transfer. - * - * The problematic situation was observed in case when endpoint has been enabled - * but no usb_request were queued. Driver try detects such endpoints and will - * use this workaround only for these endpoint. - * - * Driver use limited number of buffer. This number can be set by macro - * CDNS3_WA2_NUM_BUFFERS. - * - * Such blocking situation was observed on ACM gadget. For this function - * host send OUT data packet but ACM function is not prepared for this packet. - * It's cause that buffer placed in on chip memory block transfer to other - * endpoints. - * - * Issue has been fixed in DEV_VER_V2 version of controller. - * */ #include @@ -124,17 +98,6 @@ struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list) return list_first_entry_or_null(list, struct cdns3_aligned_buf, list); } -/** - * cdns3_next_priv_request - returns next request from list - * @list: list containing requests - * - * Returns request or NULL if no requests in list - */ -struct cdns3_request *cdns3_next_priv_request(struct list_head *list) -{ - return list_first_entry_or_null(list, struct cdns3_request, list); -} - /** * select_ep - selects endpoint * @priv_dev: extended gadget object @@ -372,246 +335,6 @@ static int cdns3_start_all_request(struct cdns3_device *priv_dev, return ret; } -/* - * WA2: Set flag for all not ISOC OUT endpoints. If this flag is set - * driver try to detect whether endpoint need additional internal - * buffer for unblocking on-chip FIFO buffer. This flag will be cleared - * if before first DESCMISS interrupt the DMA will be armed. - */ -#define cdns3_wa2_enable_detection(priv_dev, ep_priv, reg) do { \ - if (!priv_ep->dir && priv_ep->type != USB_ENDPOINT_XFER_ISOC) { \ - priv_ep->flags |= EP_QUIRK_EXTRA_BUF_DET; \ - (reg) |= EP_STS_EN_DESCMISEN; \ - } } while (0) - -/** - * cdns3_wa2_descmiss_copy_data copy data from internal requests to - * request queued by class driver. - * @priv_ep: extended endpoint object - * @request: request object - */ -static void cdns3_wa2_descmiss_copy_data(struct cdns3_endpoint *priv_ep, - struct usb_request *request) -{ - struct usb_request *descmiss_req; - struct cdns3_request *descmiss_priv_req; - - while (!list_empty(&priv_ep->wa2_descmiss_req_list)) { - int chunk_end; - int length; - - descmiss_priv_req = - cdns3_next_priv_request(&priv_ep->wa2_descmiss_req_list); - descmiss_req = &descmiss_priv_req->request; - - /* driver can't touch pending request */ - if (descmiss_priv_req->flags & REQUEST_PENDING) - break; - - chunk_end = descmiss_priv_req->flags & REQUEST_INTERNAL_CH; - length = request->actual + descmiss_req->actual; - - request->status = descmiss_req->status; - - if (length <= request->length) { - memcpy(&((u8 *)request->buf)[request->actual], - descmiss_req->buf, - descmiss_req->actual); - request->actual = length; - } else { - /* It should never occures */ - request->status = -ENOMEM; - } - - list_del_init(&descmiss_priv_req->list); - - kfree(descmiss_req->buf); - cdns3_gadget_ep_free_request(&priv_ep->endpoint, descmiss_req); - --priv_ep->wa2_counter; - - if (!chunk_end) - break; - } -} - -struct usb_request *cdns3_wa2_gadget_giveback(struct cdns3_device *priv_dev, - struct cdns3_endpoint *priv_ep, - struct cdns3_request *priv_req) -{ - if (priv_ep->flags & EP_QUIRK_EXTRA_BUF_EN && - priv_req->flags & REQUEST_INTERNAL) { - struct usb_request *req; - - req = cdns3_next_request(&priv_ep->deferred_req_list); - - priv_ep->descmis_req = NULL; - - if (!req) - return NULL; - - cdns3_wa2_descmiss_copy_data(priv_ep, req); - if (!(priv_ep->flags & EP_QUIRK_END_TRANSFER) && - req->length != req->actual) { - /* wait for next part of transfer */ - return NULL; - } - - if (req->status == -EINPROGRESS) - req->status = 0; - - list_del_init(&req->list); - cdns3_start_all_request(priv_dev, priv_ep); - return req; - } - - return &priv_req->request; -} - -int cdns3_wa2_gadget_ep_queue(struct cdns3_device *priv_dev, - struct cdns3_endpoint *priv_ep, - struct cdns3_request *priv_req) -{ - int deferred = 0; - - /* - * If transfer was queued before DESCMISS appear than we - * can disable handling of DESCMISS interrupt. Driver assumes that it - * can disable special treatment for this endpoint. - */ - if (priv_ep->flags & EP_QUIRK_EXTRA_BUF_DET) { - u32 reg; - - cdns3_select_ep(priv_dev, priv_ep->num | priv_ep->dir); - priv_ep->flags &= ~EP_QUIRK_EXTRA_BUF_DET; - reg = readl(&priv_dev->regs->ep_sts_en); - reg &= ~EP_STS_EN_DESCMISEN; - writel(reg, &priv_dev->regs->ep_sts_en); - } - - if (priv_ep->flags & EP_QUIRK_EXTRA_BUF_EN) { - u8 pending_empty = list_empty(&priv_ep->pending_req_list); - u8 descmiss_empty = list_empty(&priv_ep->wa2_descmiss_req_list); - - /* - * DESCMISS transfer has been finished, so data will be - * directly copied from internal allocated usb_request - * objects. - */ - if (pending_empty && !descmiss_empty && - !(priv_req->flags & REQUEST_INTERNAL)) { - cdns3_wa2_descmiss_copy_data(priv_ep, - &priv_req->request); - list_add_tail(&priv_req->request.list, - &priv_ep->pending_req_list); - cdns3_gadget_giveback(priv_ep, priv_req, - priv_req->request.status); - - /* - * Intentionally driver returns positive value as - * correct value. It informs that transfer has - * been finished. - */ - return EINPROGRESS; - } - - /* - * Driver will wait for completion DESCMISS transfer, - * before starts new, not DESCMISS transfer. - */ - if (!pending_empty && !descmiss_empty) - deferred = 1; - - if (priv_req->flags & REQUEST_INTERNAL) - list_add_tail(&priv_req->list, - &priv_ep->wa2_descmiss_req_list); - } - - return deferred; -} - -static void cdsn3_wa2_remove_old_request(struct cdns3_endpoint *priv_ep) -{ - struct cdns3_request *priv_req; - - while (!list_empty(&priv_ep->wa2_descmiss_req_list)) { - u8 chain; - - priv_req = cdns3_next_priv_request(&priv_ep->wa2_descmiss_req_list); - chain = !!(priv_req->flags & REQUEST_INTERNAL_CH); - - kfree(priv_req->request.buf); - cdns3_gadget_ep_free_request(&priv_ep->endpoint, - &priv_req->request); - list_del_init(&priv_req->list); - --priv_ep->wa2_counter; - - if (!chain) - break; - } -} - -/** - * cdns3_wa2_descmissing_packet - handles descriptor missing event. - * @priv_dev: extended gadget object - * - * This function is used only for WA2. For more information see Work around 2 - * description. - */ -static void cdns3_wa2_descmissing_packet(struct cdns3_endpoint *priv_ep) -{ - struct cdns3_request *priv_req; - struct usb_request *request; - - if (priv_ep->flags & EP_QUIRK_EXTRA_BUF_DET) { - priv_ep->flags &= ~EP_QUIRK_EXTRA_BUF_DET; - priv_ep->flags |= EP_QUIRK_EXTRA_BUF_EN; - } - - cdns3_dbg(priv_ep->cdns3_dev, "WA2: Description Missing detected\n"); - - if (priv_ep->wa2_counter >= CDNS3_WA2_NUM_BUFFERS) - cdsn3_wa2_remove_old_request(priv_ep); - - request = cdns3_gadget_ep_alloc_request(&priv_ep->endpoint, - GFP_ATOMIC); - if (!request) - goto err; - - priv_req = to_cdns3_request(request); - priv_req->flags |= REQUEST_INTERNAL; - - /* if this field is still assigned it indicate that transfer related - * with this request has not been finished yet. Driver in this - * case simply allocate next request and assign flag REQUEST_INTERNAL_CH - * flag to previous one. It will indicate that current request is - * part of the previous one. - */ - if (priv_ep->descmis_req) - priv_ep->descmis_req->flags |= REQUEST_INTERNAL_CH; - - priv_req->request.buf = kzalloc(CDNS3_DESCMIS_BUF_SIZE, - GFP_ATOMIC); - priv_ep->wa2_counter++; - - if (!priv_req->request.buf) { - cdns3_gadget_ep_free_request(&priv_ep->endpoint, request); - goto err; - } - - priv_req->request.length = CDNS3_DESCMIS_BUF_SIZE; - priv_ep->descmis_req = priv_req; - - __cdns3_gadget_ep_queue(&priv_ep->endpoint, - &priv_ep->descmis_req->request, - GFP_ATOMIC); - - return; - -err: - dev_err(priv_ep->cdns3_dev->dev, - "Failed: No sufficient memory for DESCMIS\n"); -} - /** * cdns3_gadget_giveback - call struct usb_request's ->complete callback * @priv_ep: The endpoint to whom the request belongs to @@ -645,13 +368,6 @@ void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, priv_req->flags &= ~(REQUEST_PENDING | REQUEST_UNALIGNED); trace_cdns3_gadget_giveback(priv_req); - if (priv_dev->dev_ver < DEV_VER_V2) { - request = cdns3_wa2_gadget_giveback(priv_dev, priv_ep, - priv_req); - if (!request) - return; - } - if (request->complete) { spin_unlock(&priv_dev->lock); usb_gadget_giveback_request(&priv_ep->endpoint, @@ -1205,25 +921,8 @@ static int cdns3_check_ep_interrupt_proceed(struct cdns3_endpoint *priv_ep) } } - if ((ep_sts_reg & EP_STS_IOC) || (ep_sts_reg & EP_STS_ISP)) { - if (priv_ep->flags & EP_QUIRK_EXTRA_BUF_EN) { - if (ep_sts_reg & EP_STS_ISP) - priv_ep->flags |= EP_QUIRK_END_TRANSFER; - else - priv_ep->flags &= ~EP_QUIRK_END_TRANSFER; - } - + if ((ep_sts_reg & EP_STS_IOC) || (ep_sts_reg & EP_STS_ISP)) cdns3_transfer_completed(priv_dev, priv_ep); - } - - /* - * WA2: this condition should only be meet when - * priv_ep->flags & EP_QUIRK_EXTRA_BUF_DET or - * priv_ep->flags & EP_QUIRK_EXTRA_BUF_EN. - * In other cases this interrupt will be disabled/ - */ - if (ep_sts_reg & EP_STS_DESCMIS && priv_dev->dev_ver < DEV_VER_V2) - cdns3_wa2_descmissing_packet(priv_ep); return 0; } @@ -1799,9 +1498,6 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep, cdns3_set_register_bit(&priv_dev->regs->ep_ien, BIT(cdns3_ep_addr_to_index(bEndpointAddress))); - if (priv_dev->dev_ver < DEV_VER_V2) - cdns3_wa2_enable_detection(priv_dev, priv_ep, reg); - writel(reg, &priv_dev->regs->ep_sts_en); /* @@ -1820,7 +1516,7 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep, ep->desc = desc; priv_ep->flags &= ~(EP_PENDING_REQUEST | EP_STALL | - EP_QUIRK_ISO_OUT_EN | EP_QUIRK_EXTRA_BUF_EN); + EP_QUIRK_ISO_OUT_EN); priv_ep->flags |= EP_ENABLED | EP_UPDATE_EP_TRBADDR; priv_ep->wa1_set = 0; priv_ep->enqueue = 0; @@ -1845,7 +1541,6 @@ exit: static int cdns3_gadget_ep_disable(struct usb_ep *ep) { struct cdns3_endpoint *priv_ep; - struct cdns3_request *priv_req; struct cdns3_device *priv_dev; struct usb_request *request; unsigned long flags; @@ -1898,16 +1593,6 @@ static int cdns3_gadget_ep_disable(struct usb_ep *ep) -ESHUTDOWN); } - while (!list_empty(&priv_ep->wa2_descmiss_req_list)) { - priv_req = cdns3_next_priv_request(&priv_ep->wa2_descmiss_req_list); - - kfree(priv_req->request.buf); - cdns3_gadget_ep_free_request(&priv_ep->endpoint, - &priv_req->request); - list_del_init(&priv_req->list); - --priv_ep->wa2_counter; - } - while (!list_empty(&priv_ep->deferred_req_list)) { request = cdns3_next_request(&priv_ep->deferred_req_list); @@ -1915,8 +1600,6 @@ static int cdns3_gadget_ep_disable(struct usb_ep *ep) -ESHUTDOWN); } - priv_ep->descmis_req = NULL; - ep->desc = NULL; priv_ep->flags &= ~EP_ENABLED; @@ -1947,14 +1630,6 @@ static int __cdns3_gadget_ep_queue(struct usb_ep *ep, priv_req = to_cdns3_request(request); trace_cdns3_ep_queue(priv_req); - if (priv_dev->dev_ver < DEV_VER_V2) { - ret = cdns3_wa2_gadget_ep_queue(priv_dev, priv_ep, - priv_req); - - if (ret == EINPROGRESS) - return 0; - } - ret = cdns3_prepare_aligned_request_buf(priv_req); if (ret < 0) return ret; @@ -2423,7 +2098,6 @@ static int cdns3_init_eps(struct cdns3_device *priv_dev) INIT_LIST_HEAD(&priv_ep->pending_req_list); INIT_LIST_HEAD(&priv_ep->deferred_req_list); - INIT_LIST_HEAD(&priv_ep->wa2_descmiss_req_list); } return 0; diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index 42f58048975f..64cead1aee32 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1079,7 +1079,6 @@ struct cdns3_trb { #define CDNS3_EP_ISO_SS_BURST 3 #define CDNS3_MAX_NUM_DESCMISS_BUF 32 #define CDNS3_DESCMIS_BUF_SIZE 2048 /* Bytes */ -#define CDNS3_WA2_NUM_BUFFERS 128 /*-------------------------------------------------------------------------*/ /* Used structs */ @@ -1090,15 +1089,11 @@ struct cdns3_device; * @endpoint: usb endpoint * @pending_req_list: list of requests queuing on transfer ring. * @deferred_req_list: list of requests waiting for queuing on transfer ring. - * @wa2_descmiss_req_list: list of requests internally allocated by driver. * @trb_pool: transfer ring - array of transaction buffers * @trb_pool_dma: dma address of transfer ring * @cdns3_dev: device associated with this endpoint * @name: a human readable name e.g. ep1out * @flags: specify the current state of endpoint - * @descmis_req: internal transfer object used for getting data from on-chip - * buffer. It can happen only if function driver doesn't send usb_request - * object on time. * @dir: endpoint direction * @num: endpoint number (1 - 15) * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK @@ -1115,8 +1110,6 @@ struct cdns3_endpoint { struct usb_ep endpoint; struct list_head pending_req_list; struct list_head deferred_req_list; - struct list_head wa2_descmiss_req_list; - int wa2_counter; struct cdns3_trb *trb_pool; dma_addr_t trb_pool_dma; @@ -1134,13 +1127,8 @@ struct cdns3_endpoint { #define EP_CLAIMED BIT(7) #define EP_DEFERRED_DRDY BIT(8) #define EP_QUIRK_ISO_OUT_EN BIT(9) -#define EP_QUIRK_EXTRA_BUF_DET BIT(10) -#define EP_QUIRK_EXTRA_BUF_EN BIT(11) -#define EP_QUIRK_END_TRANSFER BIT(12) u32 flags; - struct cdns3_request *descmis_req; - u8 dir; u8 num; u8 type; @@ -1188,7 +1176,6 @@ struct cdns3_aligned_buf { * @aligned_buf: object holds information about aligned buffer associated whit * this endpoint * @flags: flag specifying special usage of request - * @list: used by internally allocated request to add to wa2_descmiss_req_list. */ struct cdns3_request { struct usb_request request; -- cgit v1.2.3 From de4ad1b157eb4b72aada89a18ec9864e8f711754 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 4 Jul 2019 13:01:33 +0200 Subject: Revert "usb:cdns3 Add Cadence USB3 DRD Driver" This reverts commit 8bc1901ca7b07d864fca11461b3875b31f949765. It's broken. Reported-by: Stephen Rothwell Cc: Felipe Balbi Cc: Pawel Laszczak Signed-off-by: Greg Kroah-Hartman --- drivers/usb/Kconfig | 2 - drivers/usb/Makefile | 2 - drivers/usb/cdns3/Kconfig | 44 - drivers/usb/cdns3/Makefile | 14 - drivers/usb/cdns3/cdns3-pci-wrap.c | 157 --- drivers/usb/cdns3/core.c | 543 --------- drivers/usb/cdns3/core.h | 121 -- drivers/usb/cdns3/debug.h | 173 --- drivers/usb/cdns3/debugfs.c | 153 --- drivers/usb/cdns3/drd.c | 379 ------ drivers/usb/cdns3/drd.h | 166 --- drivers/usb/cdns3/ep0.c | 920 -------------- drivers/usb/cdns3/gadget-export.h | 28 - drivers/usb/cdns3/gadget.c | 2319 ------------------------------------ drivers/usb/cdns3/gadget.h | 1321 -------------------- drivers/usb/cdns3/host-export.h | 28 - drivers/usb/cdns3/host.c | 76 -- drivers/usb/cdns3/trace.c | 23 - drivers/usb/cdns3/trace.h | 447 ------- 19 files changed, 6916 deletions(-) delete mode 100644 drivers/usb/cdns3/Kconfig delete mode 100644 drivers/usb/cdns3/Makefile delete mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c delete mode 100644 drivers/usb/cdns3/core.c delete mode 100644 drivers/usb/cdns3/core.h delete mode 100644 drivers/usb/cdns3/debug.h delete mode 100644 drivers/usb/cdns3/debugfs.c delete mode 100644 drivers/usb/cdns3/drd.c delete mode 100644 drivers/usb/cdns3/drd.h delete mode 100644 drivers/usb/cdns3/ep0.c delete mode 100644 drivers/usb/cdns3/gadget-export.h delete mode 100644 drivers/usb/cdns3/gadget.c delete mode 100644 drivers/usb/cdns3/gadget.h delete mode 100644 drivers/usb/cdns3/host-export.h delete mode 100644 drivers/usb/cdns3/host.c delete mode 100644 drivers/usb/cdns3/trace.c delete mode 100644 drivers/usb/cdns3/trace.h diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 42a5b1ac5aea..94573fb68304 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -113,8 +113,6 @@ source "drivers/usb/usbip/Kconfig" endif -source "drivers/usb/cdns3/Kconfig" - source "drivers/usb/mtu3/Kconfig" source "drivers/usb/musb/Kconfig" diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index 09fc9f2448ce..ecc2de1ffaae 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile @@ -13,8 +13,6 @@ obj-$(CONFIG_USB_DWC3) += dwc3/ obj-$(CONFIG_USB_DWC2) += dwc2/ obj-$(CONFIG_USB_ISP1760) += isp1760/ -obj-$(CONFIG_USB_CDNS3) += cdns3/ - obj-$(CONFIG_USB_MON) += mon/ obj-$(CONFIG_USB_MTU3) += mtu3/ diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig deleted file mode 100644 index 118ec91c4c70..000000000000 --- a/drivers/usb/cdns3/Kconfig +++ /dev/null @@ -1,44 +0,0 @@ -config USB_CDNS3 - tristate "Cadence USB3 Dual-Role Controller" - depends on USB_SUPPORT && (USB || USB_GADGET) && HAS_DMA - help - Say Y here if your system has a Cadence USB3 dual-role controller. - It supports: dual-role switch, Host-only, and Peripheral-only. - - If you choose to build this driver is a dynamically linked - as module, the module will be called cdns3.ko. - -if USB_CDNS3 - -config USB_CDNS3_GADGET - bool "Cadence USB3 device controller" - depends on USB_GADGET - help - Say Y here to enable device controller functionality of the - Cadence USBSS-DEV driver. - - This controller supports FF, HS and SS mode. It doesn't support - LS and SSP mode. - -config USB_CDNS3_HOST - bool "Cadence USB3 host controller" - depends on USB_XHCI_HCD - help - Say Y here to enable host controller functionality of the - Cadence driver. - - Host controller is compliant with XHCI so it will use - standard XHCI driver. - -config USB_CDNS3_PCI_WRAP - tristate "Cadence USB3 support on PCIe-based platforms" - depends on USB_PCI && ACPI - default USB_CDNS3 - help - If you're using the USBSS Core IP with a PCIe, please say - 'Y' or 'M' here. - - If you choose to build this driver as module it will - be dynamically linked and module will be called cdns3-pci.ko - -endif diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile deleted file mode 100644 index 46c27b94b94b..000000000000 --- a/drivers/usb/cdns3/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# define_trace.h needs to know how to find our header -CFLAGS_trace.o := -I$(src) - -cdns3-y := core.o drd.o - -obj-$(CONFIG_USB_CDNS3) += cdns3.o -ifneq ($(CONFIG_DEBUG_FS),) - cdns3-y += debugfs.o -endif - -cdns3-$(CONFIG_USB_CDNS3_GADGET) += gadget.o ep0.o trace.o -cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o -obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci-wrap.o diff --git a/drivers/usb/cdns3/cdns3-pci-wrap.c b/drivers/usb/cdns3/cdns3-pci-wrap.c deleted file mode 100644 index 65b61ea246b1..000000000000 --- a/drivers/usb/cdns3/cdns3-pci-wrap.c +++ /dev/null @@ -1,157 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Cadence USBSS PCI Glue driver - * - * Copyright (C) 2018-2019 Cadence. - * - * Author: Pawel Laszczak - */ - -#include -#include -#include -#include -#include -#include - -struct cdns3_wrap { - struct platform_device *plat_dev; - struct pci_dev *hg_dev; - struct resource dev_res[6]; -}; - -#define RES_IRQ_HOST_ID 0 -#define RES_IRQ_PERIPHERAL_ID 1 -#define RES_IRQ_OTG_ID 2 -#define RES_HOST_ID 3 -#define RES_DEV_ID 4 -#define RES_DRD_ID 5 - -#define PCI_BAR_HOST 0 -#define PCI_BAR_DEV 2 -#define PCI_BAR_OTG 4 - -#define PCI_DEV_FN_HOST_DEVICE 0 -#define PCI_DEV_FN_OTG 1 - -#define PCI_DRIVER_NAME "cdns3-pci-usbss" -#define PLAT_DRIVER_NAME "cdns-usb3" - -#define CDNS_VENDOR_ID 0x17cd -#define CDNS_DEVICE_ID 0x0100 - -static int cdns3_pci_probe(struct pci_dev *pdev, - const struct pci_device_id *id) -{ - struct platform_device_info plat_info; - struct cdns3_wrap *wrap; - struct resource *res; - int err; - - /* - * for GADGET/HOST PCI (devfn) function number is 0, - * for OTG PCI (devfn) function number is 1 - */ - if (!id || pdev->devfn != PCI_DEV_FN_HOST_DEVICE) - return -EINVAL; - - err = pcim_enable_device(pdev); - if (err) { - dev_err(&pdev->dev, "Enabling PCI device has failed %d\n", err); - return err; - } - - pci_set_master(pdev); - wrap = devm_kzalloc(&pdev->dev, sizeof(*wrap), GFP_KERNEL); - if (!wrap) { - pci_disable_device(pdev); - return -ENOMEM; - } - - /* function 0: host(BAR_0) + device(BAR_1) + otg(BAR_2)). */ - dev_dbg(&pdev->dev, "Initialize Device resources\n"); - res = wrap->dev_res; - - res[RES_DEV_ID].start = pci_resource_start(pdev, PCI_BAR_DEV); - res[RES_DEV_ID].end = pci_resource_end(pdev, PCI_BAR_DEV); - res[RES_DEV_ID].name = "dev"; - res[RES_DEV_ID].flags = IORESOURCE_MEM; - dev_dbg(&pdev->dev, "USBSS-DEV physical base addr: %pa\n", - &res[RES_DEV_ID].start); - - res[RES_HOST_ID].start = pci_resource_start(pdev, PCI_BAR_HOST); - res[RES_HOST_ID].end = pci_resource_end(pdev, PCI_BAR_HOST); - res[RES_HOST_ID].name = "xhci"; - res[RES_HOST_ID].flags = IORESOURCE_MEM; - dev_dbg(&pdev->dev, "USBSS-XHCI physical base addr: %pa\n", - &res[RES_HOST_ID].start); - - res[RES_DRD_ID].start = pci_resource_start(pdev, PCI_BAR_OTG); - res[RES_DRD_ID].end = pci_resource_end(pdev, PCI_BAR_OTG); - res[RES_DRD_ID].name = "otg"; - res[RES_DRD_ID].flags = IORESOURCE_MEM; - dev_dbg(&pdev->dev, "USBSS-DRD physical base addr: %pa\n", - &res[RES_DRD_ID].start); - - /* Interrupt for XHCI */ - wrap->dev_res[RES_IRQ_HOST_ID].start = pdev->irq; - wrap->dev_res[RES_IRQ_HOST_ID].name = "host"; - wrap->dev_res[RES_IRQ_HOST_ID].flags = IORESOURCE_IRQ; - - /* Interrupt device. It's the same as for HOST. */ - wrap->dev_res[RES_IRQ_PERIPHERAL_ID].start = pdev->irq; - wrap->dev_res[RES_IRQ_PERIPHERAL_ID].name = "peripheral"; - wrap->dev_res[RES_IRQ_PERIPHERAL_ID].flags = IORESOURCE_IRQ; - - /* Interrupt for OTG/DRD. */ - wrap->dev_res[RES_IRQ_OTG_ID].start = pdev->irq; - wrap->dev_res[RES_IRQ_OTG_ID].name = "otg"; - wrap->dev_res[RES_IRQ_OTG_ID].flags = IORESOURCE_IRQ; - - /* set up platform device info */ - memset(&plat_info, 0, sizeof(plat_info)); - plat_info.parent = &pdev->dev; - plat_info.fwnode = pdev->dev.fwnode; - plat_info.name = PLAT_DRIVER_NAME; - plat_info.id = pdev->devfn; - plat_info.res = wrap->dev_res; - plat_info.num_res = ARRAY_SIZE(wrap->dev_res); - plat_info.dma_mask = pdev->dma_mask; - - /* register platform device */ - wrap->plat_dev = platform_device_register_full(&plat_info); - if (IS_ERR(wrap->plat_dev)) { - pci_disable_device(pdev); - return PTR_ERR(wrap->plat_dev); - } - - pci_set_drvdata(pdev, wrap); - - return err; -} - -static void cdns3_pci_remove(struct pci_dev *pdev) -{ - struct cdns3_wrap *wrap = (struct cdns3_wrap *)pci_get_drvdata(pdev); - - platform_device_unregister(wrap->plat_dev); -} - -static const struct pci_device_id cdns3_pci_ids[] = { - { PCI_DEVICE(CDNS_VENDOR_ID, CDNS_DEVICE_ID), }, - { 0, } -}; - -static struct pci_driver cdns3_pci_driver = { - .name = PCI_DRIVER_NAME, - .id_table = cdns3_pci_ids, - .probe = cdns3_pci_probe, - .remove = cdns3_pci_remove, -}; - -module_pci_driver(cdns3_pci_driver); -MODULE_DEVICE_TABLE(pci, cdns3_pci_ids); - -MODULE_AUTHOR("Pawel Laszczak "); -MODULE_LICENSE("GPL v2"); -MODULE_DESCRIPTION("Cadence USBSS PCI wrapperr"); diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c deleted file mode 100644 index ddc73f1c87c5..000000000000 --- a/drivers/usb/cdns3/core.c +++ /dev/null @@ -1,543 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Cadence USBSS DRD Driver. - * - * Copyright (C) 2018-2019 Cadence. - * Copyright (C) 2017-2018 NXP - * Copyright (C) 2019 Texas Instruments - * - * Author: Peter Chen - * Pawel Laszczak - * Roger Quadros - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "gadget.h" -#include "core.h" -#include "host-export.h" -#include "gadget-export.h" -#include "drd.h" -#include "debug.h" - -/** - * cdns3_handshake - spin reading until handshake completes or fails - * @ptr: address of device controller register to be read - * @mask: bits to look at in result of read - * @done: value of those bits when handshake succeeds - * @usec: timeout in microseconds - * - * Returns negative errno, or zero on success - * - * Success happens when the "mask" bits have the specified value (hardware - * handshake done). There are two failure modes: "usec" have passed (major - * hardware flakeout), or the register reads as all-ones (hardware removed). - */ -int cdns3_handshake(void __iomem *ptr, u32 mask, u32 done, int usec) -{ - u32 result; - - do { - result = readl(ptr); - if (result == ~(u32)0) /* card removed */ - return -ENODEV; - - result &= mask; - if (result == done) - return 0; - - udelay(1); - usec--; - } while (usec > 0); - - return -ETIMEDOUT; -} - -static inline -struct cdns3_role_driver *cdns3_get_current_role_driver(struct cdns3 *cdns) -{ - WARN_ON(cdns->role >= CDNS3_ROLE_END || !cdns->roles[cdns->role]); - return cdns->roles[cdns->role]; -} - -static int cdns3_role_start(struct cdns3 *cdns, enum cdns3_roles role) -{ - int ret; - - if (WARN_ON(role >= CDNS3_ROLE_END)) - return 0; - - if (!cdns->roles[role]) - return -ENXIO; - - if (cdns->roles[role]->state == CDNS3_ROLE_STATE_ACTIVE) - return 0; - - mutex_lock(&cdns->mutex); - cdns->role = role; - ret = cdns->roles[role]->start(cdns); - if (!ret) - cdns->roles[role]->state = CDNS3_ROLE_STATE_ACTIVE; - mutex_unlock(&cdns->mutex); - return ret; -} - -void cdns3_role_stop(struct cdns3 *cdns) -{ - enum cdns3_roles role = cdns->role; - - if (role >= CDNS3_ROLE_END) { - WARN_ON(role > CDNS3_ROLE_END); - return; - } - - if (cdns->roles[role]->state == CDNS3_ROLE_STATE_INACTIVE) - return; - - mutex_lock(&cdns->mutex); - cdns->roles[role]->stop(cdns); - cdns->roles[role]->state = CDNS3_ROLE_STATE_INACTIVE; - mutex_unlock(&cdns->mutex); -} - -static void cdns3_exit_roles(struct cdns3 *cdns) -{ - cdns3_role_stop(cdns); - cdns3_drd_exit(cdns); -} - -enum cdns3_roles cdsn3_get_real_role(struct cdns3 *cdns); - -static int cdns3_idle_role_start(struct cdns3 *cnds) -{ /* Hold PHY in RESET */ - return 0; -} - -static void cdns3_idle_role_stop(struct cdns3 *cnds) -{ - /* Program Lane swap and bring PHY out of RESET */ -} - -static int cdns3_idle_init(struct cdns3 *cdns) -{ - struct cdns3_role_driver *rdrv; - - rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); - if (!rdrv) - return -ENOMEM; - - rdrv->start = cdns3_idle_role_start; - rdrv->stop = cdns3_idle_role_stop; - rdrv->state = CDNS3_ROLE_STATE_INACTIVE; - rdrv->suspend = NULL; - rdrv->resume = NULL; - rdrv->name = "idle"; - - cdns->roles[CDNS3_ROLE_IDLE] = rdrv; - - return 0; -} - -/** - * cdns3_core_init_role - initialize role of operation - * @cdns: Pointer to cdns3 structure - * - * Returns 0 on success otherwise negative errno - */ -static int cdns3_core_init_role(struct cdns3 *cdns) -{ - struct device *dev = cdns->dev; - enum usb_dr_mode best_dr_mode; - enum usb_dr_mode dr_mode; - int ret = 0; - - dr_mode = usb_get_dr_mode(dev); - cdns->role = CDNS3_ROLE_END; - - /* - * If driver can't read mode by means of usb_get_dr_mode function then - * chooses mode according with Kernel configuration. This setting - * can be restricted later depending on strap pin configuration. - */ - if (dr_mode == USB_DR_MODE_UNKNOWN) { - if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) && - IS_ENABLED(CONFIG_USB_CDNS3_GADGET)) - dr_mode = USB_DR_MODE_OTG; - else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST)) - dr_mode = USB_DR_MODE_HOST; - else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET)) - dr_mode = USB_DR_MODE_PERIPHERAL; - } - - /* - * At this point cdns->dr_mode contains strap configuration. - * Driver try update this setting considering kernel configuration - */ - best_dr_mode = cdns->dr_mode; - - ret = cdns3_idle_init(cdns); - if (ret) - return ret; - - if (dr_mode == USB_DR_MODE_OTG) { - best_dr_mode = cdns->dr_mode; - } else if (cdns->dr_mode == USB_DR_MODE_OTG) { - best_dr_mode = dr_mode; - } else if (cdns->dr_mode != dr_mode) { - dev_err(dev, "Incorrect DRD configuration\n"); - return -EINVAL; - } - - dr_mode = best_dr_mode; - - if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { - ret = cdns3_host_init(cdns); - if (ret) { - dev_err(dev, "Host initialization failed with %d\n", - ret); - goto err; - } - } - - if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) { - ret = cdns3_gadget_init(cdns); - if (ret) { - dev_err(dev, "Device initialization failed with %d\n", - ret); - goto err; - } - } - - cdns->desired_dr_mode = dr_mode; - cdns->dr_mode = dr_mode; - - /* - * desired_dr_mode might have changed so we need to update - * the controller configuration"? - */ - ret = cdns3_drd_update_mode(cdns); - if (ret) - goto err; - - cdns->role = cdsn3_get_real_role(cdns); - - ret = cdns3_role_start(cdns, cdns->role); - if (ret) { - dev_err(dev, "can't start %s role\n", - cdns3_get_current_role_driver(cdns)->name); - goto err; - } - - return ret; -err: - cdns3_exit_roles(cdns); - return ret; -} - -/** - * cdsn3_get_real_role - get real role of controller based on hardware settings. - * @cdns: Pointer to cdns3 structure - * - * Returns role - */ -enum cdns3_roles cdsn3_get_real_role(struct cdns3 *cdns) -{ - enum cdns3_roles role; - int id, vbus; - - if (cdns->current_dr_mode != USB_DR_MODE_OTG) - goto not_otg; - - id = cdns3_get_id(cdns); - vbus = cdns3_get_vbus(cdns); - - /* - * Role change state machine - * Inputs: ID, VBUS - * Previous state: cdns->role - * Next state: role - */ - role = cdns->role; - - switch (role) { - case CDNS3_ROLE_IDLE: /* from IDLE, we can change to HOST or GADGET */ - if (!id) - role = CDNS3_ROLE_HOST; - else if (vbus) - role = CDNS3_ROLE_GADGET; - break; - case CDNS3_ROLE_HOST: /* from HOST, we can only change to IDLE */ - if (id) - role = CDNS3_ROLE_IDLE; - break; - case CDNS3_ROLE_GADGET: /* from GADGET, we can only change to IDLE */ - if (!vbus) - role = CDNS3_ROLE_IDLE; - break; - case CDNS3_ROLE_END: /* only at initialization, move to IDLE */ - role = CDNS3_ROLE_IDLE; - break; - } - - dev_dbg(cdns->dev, "role %d -> %d\n", cdns->role, role); - - return role; - -not_otg: - if (cdns3_is_host(cdns)) - role = CDNS3_ROLE_HOST; - if (cdns3_is_device(cdns)) - role = CDNS3_ROLE_GADGET; - - return role; -} - -/** - * cdns3_role_switch - work queue handler for role switch - * - * @work: work queue item structure - * - * Handles below events: - * - Role switch for dual-role devices - * - CDNS3_ROLE_GADGET <--> CDNS3_ROLE_END for peripheral-only devices - */ -static void cdns3_role_switch(struct work_struct *work) -{ - enum cdns3_roles role = CDNS3_ROLE_END; - struct cdns3_role_driver *role_drv; - enum cdns3_roles current_role; - struct cdns3 *cdns; - int ret = 0; - - cdns = container_of(work, struct cdns3, role_switch_wq); - - pm_runtime_get_sync(cdns->dev); - - role = cdsn3_get_real_role(cdns); - - role_drv = cdns3_get_current_role_driver(cdns); - - /* Disable current role if requested from debugfs */ - if (cdns->debug_disable && role_drv->state == CDNS3_ROLE_STATE_ACTIVE) { - cdns3_role_stop(cdns); - goto exit; - } - - /* Do nothing if nothing changed */ - if (cdns->role == role && role_drv->state == CDNS3_ROLE_STATE_ACTIVE) - goto exit; - - cdns3_role_stop(cdns); - - role = cdsn3_get_real_role(cdns); - - current_role = cdns->role; - dev_dbg(cdns->dev, "Switching role"); - - ret = cdns3_role_start(cdns, role); - if (ret) { - /* Back to current role */ - dev_err(cdns->dev, "set %d has failed, back to %d\n", - role, current_role); - ret = cdns3_role_start(cdns, current_role); - if (ret) - dev_err(cdns->dev, "back to %d failed too\n", - current_role); - } -exit: - pm_runtime_put_sync(cdns->dev); -} - -/** - * cdns3_probe - probe for cdns3 core device - * @pdev: Pointer to cdns3 core platform device - * - * Returns 0 on success otherwise negative errno - */ -static int cdns3_probe(struct platform_device *pdev) -{ - struct device *dev = &pdev->dev; - struct resource *res; - struct cdns3 *cdns; - void __iomem *regs; - int ret; - - ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); - if (ret) { - dev_err(dev, "error setting dma mask: %d\n", ret); - return -ENODEV; - } - - cdns = devm_kzalloc(dev, sizeof(*cdns), GFP_KERNEL); - if (!cdns) - return -ENOMEM; - - cdns->dev = dev; - - platform_set_drvdata(pdev, cdns); - - res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "host"); - if (!res) { - dev_err(dev, "missing host IRQ\n"); - return -ENODEV; - } - - cdns->xhci_res[0] = *res; - - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "xhci"); - if (!res) { - dev_err(dev, "couldn't get xhci resource\n"); - return -ENXIO; - } - - cdns->xhci_res[1] = *res; - - cdns->dev_irq = platform_get_irq_byname(pdev, "peripheral"); - if (cdns->dev_irq == -EPROBE_DEFER) - return cdns->dev_irq; - - if (cdns->dev_irq < 0) - dev_err(dev, "couldn't get peripheral irq\n"); - - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dev"); - regs = devm_ioremap_resource(dev, res); - if (IS_ERR(regs)) { - dev_err(dev, "couldn't iomap dev resource\n"); - return PTR_ERR(regs); - } - cdns->dev_regs = regs; - - cdns->otg_irq = platform_get_irq_byname(pdev, "otg"); - if (cdns->otg_irq == -EPROBE_DEFER) - return cdns->otg_irq; - - if (cdns->otg_irq < 0) { - dev_err(dev, "couldn't get otg irq\n"); - return cdns->otg_irq; - } - - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otg"); - if (!res) { - dev_err(dev, "couldn't get otg resource\n"); - return -ENXIO; - } - - cdns->otg_res = *res; - - mutex_init(&cdns->mutex); - - cdns->usb2_phy = devm_phy_optional_get(dev, "cdns3,usb2-phy"); - if (IS_ERR(cdns->usb2_phy)) - return PTR_ERR(cdns->usb2_phy); - - phy_init(cdns->usb2_phy); - ret = phy_init(cdns->usb2_phy); - if (ret) - return ret; - - cdns->usb3_phy = devm_phy_optional_get(dev, "cdns3,usb3-phy"); - if (IS_ERR(cdns->usb3_phy)) - return PTR_ERR(cdns->usb3_phy); - - phy_init(cdns->usb3_phy); - ret = phy_init(cdns->usb3_phy); - if (ret) - return ret; - - ret = phy_power_on(cdns->usb2_phy); - if (ret) - return ret; - - ret = phy_power_on(cdns->usb3_phy); - if (ret) - goto err1; - - INIT_WORK(&cdns->role_switch_wq, cdns3_role_switch); - - ret = cdns3_drd_init(cdns); - if (ret) - goto err2; - - ret = cdns3_core_init_role(cdns); - if (ret) - goto err2; - - cdns3_debugfs_init(cdns); - device_set_wakeup_capable(dev, true); - pm_runtime_set_active(dev); - pm_runtime_enable(dev); - - /* - * The controller needs less time between bus and controller suspend, - * and we also needs a small delay to avoid frequently entering low - * power mode. - */ - pm_runtime_set_autosuspend_delay(dev, 20); - pm_runtime_mark_last_busy(dev); - pm_runtime_use_autosuspend(dev); - dev_dbg(dev, "Cadence USB3 core: probe succeed\n"); - - return 0; - -err2: - phy_power_off(cdns->usb3_phy); - -err1: - phy_power_off(cdns->usb2_phy); - phy_exit(cdns->usb2_phy); - phy_exit(cdns->usb3_phy); - - return ret; -} - -/** - * cdns3_remove - unbind drd driver and clean up - * @pdev: Pointer to Linux platform device - * - * Returns 0 on success otherwise negative errno - */ -static int cdns3_remove(struct platform_device *pdev) -{ - struct cdns3 *cdns = platform_get_drvdata(pdev); - - pm_runtime_get_sync(&pdev->dev); - pm_runtime_disable(&pdev->dev); - pm_runtime_put_noidle(&pdev->dev); - cdns3_debugfs_exit(cdns); - cdns3_exit_roles(cdns); - phy_power_off(cdns->usb2_phy); - phy_power_off(cdns->usb3_phy); - phy_exit(cdns->usb2_phy); - phy_exit(cdns->usb3_phy); - return 0; -} - -#ifdef CONFIG_OF -static const struct of_device_id of_cdns3_match[] = { - { .compatible = "cdns,usb3" }, - { }, -}; -MODULE_DEVICE_TABLE(of, of_cdns3_match); -#endif - -static struct platform_driver cdns3_driver = { - .probe = cdns3_probe, - .remove = cdns3_remove, - .driver = { - .name = "cdns-usb3", - .of_match_table = of_match_ptr(of_cdns3_match), - }, -}; - -module_platform_driver(cdns3_driver); - -MODULE_ALIAS("platform:cdns3"); -MODULE_AUTHOR("Pawel Laszczak "); -MODULE_LICENSE("GPL v2"); -MODULE_DESCRIPTION("Cadence USB3 DRD Controller Driver"); diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h deleted file mode 100644 index be95696ab17e..000000000000 --- a/drivers/usb/cdns3/core.h +++ /dev/null @@ -1,121 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Cadence USBSS DRD Header File. - * - * Copyright (C) 2017-2018 NXP - * Copyright (C) 2018-2019 Cadence. - * - * Authors: Peter Chen - * Pawel Laszczak - */ -#include - -#ifndef __LINUX_CDNS3_CORE_H -#define __LINUX_CDNS3_CORE_H - -struct cdns3; -enum cdns3_roles { - CDNS3_ROLE_IDLE = 0, - CDNS3_ROLE_HOST, - CDNS3_ROLE_GADGET, - CDNS3_ROLE_END, -}; - -/** - * struct cdns3_role_driver - host/gadget role driver - * @start: start this role - * @stop: stop this role - * @suspend: suspend callback for this role - * @resume: resume callback for this role - * @irq: irq handler for this role - * @name: role name string (host/gadget) - * @state: current state - */ -struct cdns3_role_driver { - int (*start)(struct cdns3 *cdns); - void (*stop)(struct cdns3 *cdns); - int (*suspend)(struct cdns3 *cdns, bool do_wakeup); - int (*resume)(struct cdns3 *cdns, bool hibernated); - const char *name; -#define CDNS3_ROLE_STATE_INACTIVE 0 -#define CDNS3_ROLE_STATE_ACTIVE 1 - int state; -}; - -#define CDNS3_XHCI_RESOURCES_NUM 2 -/** - * struct cdns3 - Representation of Cadence USB3 DRD controller. - * @dev: pointer to Cadence device struct - * @xhci_regs: pointer to base of xhci registers - * @xhci_res: the resource for xhci - * @dev_regs: pointer to base of dev registers - * @otg_res: the resource for otg - * @otg_v0_regs: pointer to base of v0 otg registers - * @otg_v1_regs: pointer to base of v1 otg registers - * @otg_regs: pointer to base of otg registers - * @otg_irq: irq number for otg controller - * @dev_irq: irq number for device controller - * @roles: array of supported roles for this controller - * @role: current role - * @host_dev: the child host device pointer for cdns3 core - * @gadget_dev: the child gadget device pointer for cdns3 core - * @usb2_phy: pointer to USB2 PHY - * @usb3_phy: pointer to USB3 PHY - * @role_switch_wq: work queue item for role switch - * @wakeup_int: the wakeup interrupt - * @mutex: the mutex for concurrent code at driver - * @dr_mode: supported mode of operation it can be only Host, only Device - * or OTG mode that allow to switch between Device and Host mode. - * This field based on firmware setting, kernel configuration - * and hardware configuration. - * @current_dr_mode: current mode of operation when in dual-role mode - * @desired_dr_mode: desired mode of operation when in dual-role mode. - * This value can be changed during runtime. - * Available options depends on dr_mode: - * dr_mode | desired_dr_mode and current_dr_mode - * ---------------------------------------------------------------- - * USB_DR_MODE_HOST | only USB_DR_MODE_HOST - * USB_DR_MODE_PERIPHERAL | only USB_DR_MODE_PERIPHERAL - * USB_DR_MODE_OTG | USB_DR_MODE_OTG or USB_DR_MODE_HOST or - * | USB_DR_MODE_PERIPHERAL - * Desired_dr_role can be changed by means of debugfs. - * @root: debugfs root folder pointer - * @debug_disable: - */ -struct cdns3 { - struct device *dev; - void __iomem *xhci_regs; - struct resource xhci_res[CDNS3_XHCI_RESOURCES_NUM]; - struct cdns3_usb_regs __iomem *dev_regs; - - struct resource otg_res; - struct cdns3_otg_legacy_regs *otg_v0_regs; - struct cdns3_otg_regs *otg_v1_regs; - struct cdns3_otg_common_regs *otg_regs; -#define CDNS3_CONTROLLER_V0 0 -#define CDNS3_CONTROLLER_V1 1 - u32 version; - - int otg_irq; - int dev_irq; - struct cdns3_role_driver *roles[CDNS3_ROLE_END]; - enum cdns3_roles role; - struct platform_device *host_dev; - struct cdns3_device *gadget_dev; - struct phy *usb2_phy; - struct phy *usb3_phy; - struct work_struct role_switch_wq; - int wakeup_int:1; - /* mutext used in workqueue*/ - struct mutex mutex; - enum usb_dr_mode dr_mode; - enum usb_dr_mode current_dr_mode; - enum usb_dr_mode desired_dr_mode; - struct dentry *root; - int debug_disable:1; -}; - -void cdns3_role_stop(struct cdns3 *cdns); -int cdns3_handshake(void __iomem *ptr, u32 mask, u32 done, int usec); - -#endif /* __LINUX_CDNS3_CORE_H */ diff --git a/drivers/usb/cdns3/debug.h b/drivers/usb/cdns3/debug.h deleted file mode 100644 index 65c3d8a6cd62..000000000000 --- a/drivers/usb/cdns3/debug.h +++ /dev/null @@ -1,173 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Cadence USBSS DRD Driver. - * Debug header file. - * - * Copyright (C) 2018-2019 Cadence. - * - * Author: Pawel Laszczak - */ -#ifndef __LINUX_CDNS3_DEBUG -#define __LINUX_CDNS3_DEBUG - -#include "core.h" - -static inline char *cdns3_decode_usb_irq(char *str, - enum usb_device_speed speed, - u32 usb_ists) -{ - int ret; - - ret = sprintf(str, "IRQ %08x = ", usb_ists); - - if (usb_ists & (USB_ISTS_CON2I | USB_ISTS_CONI)) { - ret += sprintf(str + ret, "Connection %s\n", - usb_speed_string(speed)); - } - if (usb_ists & USB_ISTS_DIS2I || usb_ists & USB_ISTS_DISI) - ret += sprintf(str + ret, "Disconnection "); - if (usb_ists & USB_ISTS_L2ENTI) - ret += sprintf(str + ret, "suspended "); - if (usb_ists & USB_ISTS_L1ENTI) - ret += sprintf(str + ret, "L1 enter "); - if (usb_ists & USB_ISTS_L1EXTI) - ret += sprintf(str + ret, "L1 exit "); - if (usb_ists & USB_ISTS_L2ENTI) - ret += sprintf(str + ret, "L2 enter "); - if (usb_ists & USB_ISTS_L2EXTI) - ret += sprintf(str + ret, "L2 exit "); - if (usb_ists & USB_ISTS_U3EXTI) - ret += sprintf(str + ret, "U3 exit "); - if (usb_ists & USB_ISTS_UWRESI) - ret += sprintf(str + ret, "Warm Reset "); - if (usb_ists & USB_ISTS_UHRESI) - ret += sprintf(str + ret, "Hot Reset "); - if (usb_ists & USB_ISTS_U2RESI) - ret += sprintf(str + ret, "Reset"); - - return str; -} - -static inline char *cdns3_decode_ep_irq(char *str, - u32 ep_sts, - const char *ep_name) -{ - int ret; - - ret = sprintf(str, "IRQ for %s: %08x ", ep_name, ep_sts); - - if (ep_sts & EP_STS_SETUP) - ret += sprintf(str + ret, "SETUP "); - if (ep_sts & EP_STS_IOC) - ret += sprintf(str + ret, "IOC "); - if (ep_sts & EP_STS_ISP) - ret += sprintf(str + ret, "ISP "); - if (ep_sts & EP_STS_DESCMIS) - ret += sprintf(str + ret, "DESCMIS "); - if (ep_sts & EP_STS_STREAMR) - ret += sprintf(str + ret, "STREAMR "); - if (ep_sts & EP_STS_MD_EXIT) - ret += sprintf(str + ret, "MD_EXIT "); - if (ep_sts & EP_STS_TRBERR) - ret += sprintf(str + ret, "TRBERR "); - if (ep_sts & EP_STS_NRDY) - ret += sprintf(str + ret, "NRDY "); - if (ep_sts & EP_STS_PRIME) - ret += sprintf(str + ret, "PRIME "); - if (ep_sts & EP_STS_SIDERR) - ret += sprintf(str + ret, "SIDERRT "); - if (ep_sts & EP_STS_OUTSMM) - ret += sprintf(str + ret, "OUTSMM "); - if (ep_sts & EP_STS_ISOERR) - ret += sprintf(str + ret, "ISOERR "); - if (ep_sts & EP_STS_IOT) - ret += sprintf(str + ret, "IOT "); - - return str; -} - -static inline char *cdns3_decode_epx_irq(char *str, - char *ep_name, - u32 ep_sts) -{ - return cdns3_decode_ep_irq(str, ep_sts, ep_name); -} - -static inline char *cdns3_decode_ep0_irq(char *str, - int dir, - u32 ep_sts) -{ - return cdns3_decode_ep_irq(str, ep_sts, - dir ? "ep0IN" : "ep0OUT"); -} - -/** - * Debug a transfer ring. - * - * Prints out all TRBs in the endpoint ring, even those after the Link TRB. - *. - */ -static inline char *cdns3_dbg_ring(struct cdns3_endpoint *priv_ep, - struct cdns3_trb *ring, char *str) -{ - dma_addr_t addr = priv_ep->trb_pool_dma; - struct cdns3_trb *trb; - int trb_per_sector; - int ret = 0; - int i; - - trb_per_sector = GET_TRBS_PER_SEGMENT(priv_ep->type); - - trb = &priv_ep->trb_pool[priv_ep->dequeue]; - ret += sprintf(str + ret, "\n\t\tRing contents for %s:", priv_ep->name); - - ret += sprintf(str + ret, - "\n\t\tRing deq index: %d, trb: %p (virt), 0x%llx (dma)\n", - priv_ep->dequeue, trb, - (unsigned long long)cdns3_trb_virt_to_dma(priv_ep, trb)); - - trb = &priv_ep->trb_pool[priv_ep->enqueue]; - ret += sprintf(str + ret, - "\t\tRing enq index: %d, trb: %p (virt), 0x%llx (dma)\n", - priv_ep->enqueue, trb, - (unsigned long long)cdns3_trb_virt_to_dma(priv_ep, trb)); - - ret += sprintf(str + ret, - "\t\tfree trbs: %d, CCS=%d, PCS=%d\n", - priv_ep->free_trbs, priv_ep->ccs, priv_ep->pcs); - - if (trb_per_sector > TRBS_PER_SEGMENT) - trb_per_sector = TRBS_PER_SEGMENT; - - if (trb_per_sector > TRBS_PER_SEGMENT) { - sprintf(str + ret, "\t\tTo big transfer ring %d\n", - trb_per_sector); - return str; - } - - for (i = 0; i < trb_per_sector; ++i) { - trb = &ring[i]; - ret += sprintf(str + ret, - "\t\t@%pad %08x %08x %08x\n", &addr, - le32_to_cpu(trb->buffer), - le32_to_cpu(trb->length), - le32_to_cpu(trb->control)); - addr += sizeof(*trb); - } - - return str; -} - -void cdns3_dbg(struct cdns3_device *priv_dev, const char *fmt, ...); - -#ifdef CONFIG_DEBUG_FS -void cdns3_debugfs_init(struct cdns3 *cdns); -void cdns3_debugfs_exit(struct cdns3 *cdns); -#else -void cdns3_debugfs_init(struct cdns3 *cdns); -{ } -void cdns3_debugfs_exit(struct cdns3 *cdns); -{ } -#endif - -#endif /*__LINUX_CDNS3_DEBUG*/ diff --git a/drivers/usb/cdns3/debugfs.c b/drivers/usb/cdns3/debugfs.c deleted file mode 100644 index 44ee78a10eb8..000000000000 --- a/drivers/usb/cdns3/debugfs.c +++ /dev/null @@ -1,153 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Cadence USBSS DRD Controller DebugFS filer. - * - * Copyright (C) 2018-2019 Cadence. - * - * Author: Pawel Laszczak - */ - -#include -#include -#include -#include - -#include "core.h" -#include "gadget.h" -#include "drd.h" - -static const char *const cdns3_mode[] = { - [USB_DR_MODE_UNKNOWN] = "unknown", - [USB_DR_MODE_OTG] = "otg", - [USB_DR_MODE_HOST] = "host", - [USB_DR_MODE_PERIPHERAL] = "device", -}; - -static int cdns3_mode_show(struct seq_file *s, void *unused) -{ - struct cdns3 *cdns = s->private; - - seq_puts(s, cdns3_mode[cdns->current_dr_mode]); - - return 0; -} - -static int cdns3_mode_open(struct inode *inode, struct file *file) -{ - return single_open(file, cdns3_mode_show, inode->i_private); -} - -static ssize_t cdns3_mode_write(struct file *file, - const char __user *ubuf, - size_t count, loff_t *ppos) -{ - struct seq_file *s = file->private_data; - struct cdns3 *cdns = s->private; - char buf[32]; - int ret; - - if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) - return -EFAULT; - - if (cdns->debug_disable) { - dev_err(cdns->dev, - "Mode can't be changed when disable is set\n"); - return -EPERM; - } - - ret = match_string(cdns3_mode, ARRAY_SIZE(cdns3_mode), buf); - if (ret < 0 || ret == USB_DR_MODE_UNKNOWN) { - dev_err(cdns->dev, "Failed: incorrect mode setting\n"); - return -EINVAL; - } - - if (cdns->current_dr_mode != ret) { - cdns->desired_dr_mode = ret; - cdns3_role_stop(cdns); - ret = cdns3_drd_update_mode(cdns); - if (ret) - return ret; - - queue_work(system_freezable_wq, &cdns->role_switch_wq); - } - - return count; -} - -static const struct file_operations cdns3_mode_fops = { - .open = cdns3_mode_open, - .write = cdns3_mode_write, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int cdns3_disable_show(struct seq_file *s, void *unused) -{ - struct cdns3 *cdns = s->private; - - if (!cdns->debug_disable) - seq_puts(s, "0\n"); - else - seq_puts(s, "1\n"); - - return 0; -} - -static ssize_t cdns3_disable_write(struct file *file, - const char __user *ubuf, - size_t count, loff_t *ppos) -{ - struct seq_file *s = file->private_data; - struct cdns3 *cdns = s->private; - bool disable; - char buf[16]; - - if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) - return -EFAULT; - - if (kstrtobool(buf, &disable)) { - dev_err(cdns->dev, "wrong setting\n"); - return -EINVAL; - } - - if (disable != cdns->debug_disable) { - cdns->debug_disable = disable; - queue_work(system_freezable_wq, &cdns->role_switch_wq); - } - - return count; -} - -static int cdns3_disable_open(struct inode *inode, struct file *file) -{ - return single_open(file, cdns3_disable_show, inode->i_private); -} - -static const struct file_operations cdns3_disable_fops = { - .open = cdns3_disable_open, - .write = cdns3_disable_write, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -void cdns3_debugfs_init(struct cdns3 *cdns) -{ - struct dentry *root; - - root = debugfs_create_dir(dev_name(cdns->dev), NULL); - cdns->root = root; - if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET) && - IS_ENABLED(CONFIG_USB_CDNS3_HOST)) - debugfs_create_file("mode", 0644, root, cdns, - &cdns3_mode_fops); - - debugfs_create_file("disable", 0644, root, cdns, - &cdns3_disable_fops); -} - -void cdns3_debugfs_exit(struct cdns3 *cdns) -{ - debugfs_remove_recursive(cdns->root); -} diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c deleted file mode 100644 index b06929fe1175..000000000000 --- a/drivers/usb/cdns3/drd.c +++ /dev/null @@ -1,379 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Cadence USBSS DRD Driver. - * - * Copyright (C) 2018-2019 Cadence. - * Copyright (C) 2019 Texas Instruments - * - * Author: Pawel Laszczak - * Roger Quadros - * - * - */ -#include -#include -#include -#include - -#include "gadget.h" -#include "drd.h" -#include "core.h" - -/** - * cdns3_set_mode - change mode of OTG Core - * @cdns: pointer to context structure - * @mode: selected mode from cdns_role - * - * Returns 0 on success otherwise negative errno - */ -int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode) -{ - int ret = 0; - u32 reg; - - cdns->current_dr_mode = mode; - - switch (mode) { - case USB_DR_MODE_PERIPHERAL: - break; - case USB_DR_MODE_HOST: - break; - case USB_DR_MODE_OTG: - dev_dbg(cdns->dev, "Set controller to OTG mode\n"); - if (cdns->version == CDNS3_CONTROLLER_V1) { - reg = readl(&cdns->otg_v1_regs->override); - reg |= OVERRIDE_IDPULLUP; - writel(reg, &cdns->otg_v1_regs->override); - } else { - reg = readl(&cdns->otg_v0_regs->ctrl1); - reg |= OVERRIDE_IDPULLUP_V0; - writel(reg, &cdns->otg_v0_regs->ctrl1); - } - - /* - * Hardware specification says: "ID_VALUE must be valid within - * 50ms after idpullup is set to '1" so driver must wait - * 50ms before reading this pin. - */ - usleep_range(50000, 60000); - break; - default: - cdns->current_dr_mode = USB_DR_MODE_UNKNOWN; - dev_err(cdns->dev, "Unsupported mode of operation %d\n", mode); - return -EINVAL; - } - - return ret; -} - -int cdns3_get_id(struct cdns3 *cdns) -{ - int id; - - id = readl(&cdns->otg_regs->sts) & OTGSTS_ID_VALUE; - dev_dbg(cdns->dev, "OTG ID: %d", id); - - return id; -} - -int cdns3_get_vbus(struct cdns3 *cdns) -{ - int vbus; - - vbus = !!(readl(&cdns->otg_regs->sts) & OTGSTS_VBUS_VALID); - dev_dbg(cdns->dev, "OTG VBUS: %d", vbus); - return vbus; -} - -int cdns3_is_host(struct cdns3 *cdns) -{ - if (cdns->current_dr_mode == USB_DR_MODE_HOST) - return 1; - else if (!cdns3_get_id(cdns)) - return 1; - - return 0; -} - -int cdns3_is_device(struct cdns3 *cdns) -{ - if (cdns->current_dr_mode == USB_DR_MODE_PERIPHERAL) - return 1; - else if (cdns->current_dr_mode == USB_DR_MODE_OTG) - if (cdns3_get_id(cdns)) - return 1; - - return 0; -} - -/** - * cdns3_otg_disable_irq - Disable all OTG interrupts - * @cdns: Pointer to controller context structure - */ -static void cdns3_otg_disable_irq(struct cdns3 *cdns) -{ - writel(0, &cdns->otg_regs->ien); -} - -/** - * cdns3_otg_enable_irq - enable id and sess_valid interrupts - * @cdns: Pointer to controller context structure - */ -static void cdns3_otg_enable_irq(struct cdns3 *cdns) -{ - writel(OTGIEN_ID_CHANGE_INT | OTGIEN_VBUSVALID_RISE_INT | - OTGIEN_VBUSVALID_FALL_INT, &cdns->otg_regs->ien); -} - -/** - * cdns3_drd_switch_host - start/stop host - * @cdns: Pointer to controller context structure - * @on: 1 for start, 0 for stop - * - * Returns 0 on success otherwise negative errno - */ -int cdns3_drd_switch_host(struct cdns3 *cdns, int on) -{ - int ret; - u32 reg = OTGCMD_OTG_DIS; - - /* switch OTG core */ - if (on) { - writel(OTGCMD_HOST_BUS_REQ | reg, &cdns->otg_regs->cmd); - - dev_dbg(cdns->dev, "Waiting till Host mode is turned on\n"); - ret = cdns3_handshake(&cdns->otg_regs->sts, OTGSTS_XHCI_READY, - OTGSTS_XHCI_READY, 100000); - - if (ret) { - dev_err(cdns->dev, "timeout waiting for xhci_ready\n"); - return ret; - } - } else { - writel(OTGCMD_HOST_BUS_DROP | OTGCMD_DEV_BUS_DROP | - OTGCMD_DEV_POWER_OFF | OTGCMD_HOST_POWER_OFF, - &cdns->otg_regs->cmd); - /* Waiting till H_IDLE state.*/ - cdns3_handshake(&cdns->otg_regs->state, - OTGSTATE_HOST_STATE_MASK, - 0, 2000000); - } - - return 0; -} - -/** - * cdns3_drd_switch_gadget - start/stop gadget - * @cdns: Pointer to controller context structure - * @on: 1 for start, 0 for stop - * - * Returns 0 on success otherwise negative errno - */ -int cdns3_drd_switch_gadget(struct cdns3 *cdns, int on) -{ - int ret; - u32 reg = OTGCMD_OTG_DIS; - - /* switch OTG core */ - if (on) { - writel(OTGCMD_DEV_BUS_REQ | reg, &cdns->otg_regs->cmd); - - dev_dbg(cdns->dev, "Waiting till Device mode is turned on\n"); - - ret = cdns3_handshake(&cdns->otg_regs->sts, OTGSTS_DEV_READY, - OTGSTS_DEV_READY, 100000); - - if (ret) { - dev_err(cdns->dev, "timeout waiting for dev_ready\n"); - return ret; - } - } else { - /* - * driver should wait at least 10us after disabling Device - * before turning-off Device (DEV_BUS_DROP) - */ - usleep_range(20, 30); - writel(OTGCMD_HOST_BUS_DROP | OTGCMD_DEV_BUS_DROP | - OTGCMD_DEV_POWER_OFF | OTGCMD_HOST_POWER_OFF, - &cdns->otg_regs->cmd); - /* Waiting till DEV_IDLE state.*/ - cdns3_handshake(&cdns->otg_regs->state, OTGSTATE_DEV_STATE_MASK, - 0, 2000000); - } - - return 0; -} - -/** - * cdns3_init_otg_mode - initialize drd controller - * @cdns: Pointer to controller context structure - * - * Returns 0 on success otherwise negative errno - */ -static int cdns3_init_otg_mode(struct cdns3 *cdns) -{ - int ret = 0; - - cdns3_otg_disable_irq(cdns); - /* clear all interrupts */ - writel(~0, &cdns->otg_regs->ivect); - - ret = cdns3_set_mode(cdns, USB_DR_MODE_OTG); - if (ret) - return ret; - - cdns3_otg_enable_irq(cdns); - return ret; -} - -/** - * cdns3_drd_update_mode - initialize mode of operation - * @cdns: Pointer to controller context structure - * - * Returns 0 on success otherwise negative errno - */ -int cdns3_drd_update_mode(struct cdns3 *cdns) -{ - int ret = 0; - - if (cdns->desired_dr_mode == cdns->current_dr_mode) - return ret; - - switch (cdns->desired_dr_mode) { - case USB_DR_MODE_PERIPHERAL: - ret = cdns3_set_mode(cdns, USB_DR_MODE_PERIPHERAL); - break; - case USB_DR_MODE_HOST: - ret = cdns3_set_mode(cdns, USB_DR_MODE_HOST); - break; - case USB_DR_MODE_OTG: - ret = cdns3_init_otg_mode(cdns); - break; - default: - dev_err(cdns->dev, "Unsupported mode of operation %d\n", - cdns->dr_mode); - return -EINVAL; - } - - return ret; -} - -/** - * cdns3_drd_irq - interrupt handler for OTG events - * - * @irq: irq number for cdns3 core device - * @data: structure of cdns3 - * - * Returns IRQ_HANDLED or IRQ_NONE - */ -static irqreturn_t cdns3_drd_irq(int irq, void *data) -{ - irqreturn_t ret = IRQ_NONE; - struct cdns3 *cdns = data; - u32 reg; - - if (cdns->dr_mode != USB_DR_MODE_OTG) - return ret; - - reg = readl(&cdns->otg_regs->ivect); - - if (!reg) - return ret; - - if (reg & OTGIEN_ID_CHANGE_INT) { - dev_dbg(cdns->dev, "OTG IRQ: new ID: %d\n", - cdns3_get_id(cdns)); - - ret = IRQ_HANDLED; - } - - if (reg & (OTGIEN_VBUSVALID_RISE_INT | OTGIEN_VBUSVALID_FALL_INT)) { - dev_dbg(cdns->dev, "OTG IRQ: new VBUS: %d\n", - cdns3_get_vbus(cdns)); - - ret = IRQ_HANDLED; - } - - if (ret == IRQ_HANDLED) - queue_work(system_freezable_wq, &cdns->role_switch_wq); - - writel(~0, &cdns->otg_regs->ivect); - return ret; -} - -int cdns3_drd_init(struct cdns3 *cdns) -{ - void __iomem *regs; - int ret = 0; - u32 state; - - regs = devm_ioremap_resource(cdns->dev, &cdns->otg_res); - if (IS_ERR(regs)) - return PTR_ERR(regs); - - /* Detection of DRD version. Controller has been released - * in two versions. Both are similar, but they have same changes - * in register maps. - * The first register in old version is command register and it's read - * only, so driver should read 0 from it. On the other hand, in v1 - * the first register contains device ID number which is not set to 0. - * Driver uses this fact to detect the proper version of - * controller. - */ - cdns->otg_v0_regs = regs; - if (!readl(&cdns->otg_v0_regs->cmd)) { - cdns->version = CDNS3_CONTROLLER_V0; - cdns->otg_v1_regs = NULL; - cdns->otg_regs = regs; - writel(1, &cdns->otg_v0_regs->simulate); - dev_info(cdns->dev, "DRD version v0 (%08x)\n", - readl(&cdns->otg_v0_regs->version)); - } else { - cdns->otg_v0_regs = NULL; - cdns->otg_v1_regs = regs; - cdns->otg_regs = (void *)&cdns->otg_v1_regs->cmd; - cdns->version = CDNS3_CONTROLLER_V1; - writel(1, &cdns->otg_v1_regs->simulate); - dev_info(cdns->dev, "DRD version v1 (ID: %08x, rev: %08x)\n", - readl(&cdns->otg_v1_regs->did), - readl(&cdns->otg_v1_regs->rid)); - } - - state = OTGSTS_STRAP(readl(&cdns->otg_regs->sts)); - - /* Update dr_mode according to STRAP configuration. */ - cdns->dr_mode = USB_DR_MODE_OTG; - if (state == OTGSTS_STRAP_HOST) { - dev_dbg(cdns->dev, "Controller strapped to HOST\n"); - cdns->dr_mode = USB_DR_MODE_HOST; - } else if (state == OTGSTS_STRAP_GADGET) { - dev_dbg(cdns->dev, "Controller strapped to PERIPHERAL\n"); - cdns->dr_mode = USB_DR_MODE_PERIPHERAL; - } - - cdns->desired_dr_mode = cdns->dr_mode; - cdns->current_dr_mode = USB_DR_MODE_UNKNOWN; - - ret = devm_request_threaded_irq(cdns->dev, cdns->otg_irq, - cdns3_drd_irq, - NULL, IRQF_SHARED, - dev_name(cdns->dev), cdns); - - if (ret) { - dev_err(cdns->dev, "couldn't get otg_irq\n"); - return ret; - } - - state = readl(&cdns->otg_regs->sts); - if (OTGSTS_OTG_NRDY(state) != 0) { - dev_err(cdns->dev, "Cadence USB3 OTG device not ready\n"); - return -ENODEV; - } - - return ret; -} - -int cdns3_drd_exit(struct cdns3 *cdns) -{ - return 0; -} diff --git a/drivers/usb/cdns3/drd.h b/drivers/usb/cdns3/drd.h deleted file mode 100644 index bf6c7bc41b58..000000000000 --- a/drivers/usb/cdns3/drd.h +++ /dev/null @@ -1,166 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Cadence USB3 DRD header file. - * - * Copyright (C) 2018-2019 Cadence. - * - * Author: Pawel Laszczak - */ -#ifndef __LINUX_CDNS3_DRD -#define __LINUX_CDNS3_DRD - -#include -#include -#include "core.h" - -/* DRD register interface for version v1. */ -struct cdns3_otg_regs { - __le32 did; - __le32 rid; - __le32 capabilities; - __le32 reserved1; - __le32 cmd; - __le32 sts; - __le32 state; - __le32 reserved2; - __le32 ien; - __le32 ivect; - __le32 refclk; - __le32 tmr; - __le32 reserved3[4]; - __le32 simulate; - __le32 override; - __le32 susp_ctrl; - __le32 reserved4; - __le32 anasts; - __le32 adp_ramp_time; - __le32 ctrl1; - __le32 ctrl2; -}; - -/* DRD register interface for version v0. */ -struct cdns3_otg_legacy_regs { - __le32 cmd; - __le32 sts; - __le32 state; - __le32 refclk; - __le32 ien; - __le32 ivect; - __le32 reserved1[3]; - __le32 tmr; - __le32 reserved2[2]; - __le32 version; - __le32 capabilities; - __le32 reserved3[2]; - __le32 simulate; - __le32 reserved4[5]; - __le32 ctrl1; -}; - -/* - * Common registers interface for both version of DRD. - */ -struct cdns3_otg_common_regs { - __le32 cmd; - __le32 sts; - __le32 state; - __le32 different1; - __le32 ien; - __le32 ivect; -}; - -/* CDNS_RID - bitmasks */ -#define CDNS_RID(p) ((p) & GENMASK(15, 0)) - -/* CDNS_VID - bitmasks */ -#define CDNS_DID(p) ((p) & GENMASK(31, 0)) - -/* OTGCMD - bitmasks */ -/* "Request the bus for Device mode. */ -#define OTGCMD_DEV_BUS_REQ BIT(0) -/* Request the bus for Host mode */ -#define OTGCMD_HOST_BUS_REQ BIT(1) -/* Enable OTG mode. */ -#define OTGCMD_OTG_EN BIT(2) -/* Disable OTG mode */ -#define OTGCMD_OTG_DIS BIT(3) -/*"Configure OTG as A-Device. */ -#define OTGCMD_A_DEV_EN BIT(4) -/*"Configure OTG as A-Device. */ -#define OTGCMD_A_DEV_DIS BIT(5) -/* Drop the bus for Device mod e. */ -#define OTGCMD_DEV_BUS_DROP BIT(8) -/* Drop the bus for Host mode*/ -#define OTGCMD_HOST_BUS_DROP BIT(9) -/* Power Down USBSS-DEV. */ -#define OTGCMD_DEV_POWER_OFF BIT(11) -/* Power Down CDNSXHCI. */ -#define OTGCMD_HOST_POWER_OFF BIT(12) - -/* OTGIEN - bitmasks */ -/* ID change interrupt enable */ -#define OTGIEN_ID_CHANGE_INT BIT(0) -/* Vbusvalid fall detected interrupt enable.*/ -#define OTGIEN_VBUSVALID_RISE_INT BIT(4) -/* Vbusvalid fall detected interrupt enable */ -#define OTGIEN_VBUSVALID_FALL_INT BIT(5) - -/* OTGSTS - bitmasks */ -/* - * Current value of the ID pin. It is only valid when idpullup in - * OTGCTRL1_TYPE register is set to '1'. - */ -#define OTGSTS_ID_VALUE BIT(0) -/* Current value of the vbus_valid */ -#define OTGSTS_VBUS_VALID BIT(1) -/* Current value of the b_sess_vld */ -#define OTGSTS_SESSION_VALID BIT(2) -/*Device mode is active*/ -#define OTGSTS_DEV_ACTIVE BIT(3) -/* Host mode is active. */ -#define OTGSTS_HOST_ACTIVE BIT(4) -/* OTG Controller not ready. */ -#define OTGSTS_OTG_NRDY_MASK BIT(11) -#define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK) -/* - * Value of the strap pins. - * 000 - no default configuration - * 010 - Controller initiall configured as Host - * 100 - Controller initially configured as Device - */ -#define OTGSTS_STRAP(p) (((p) & GENMASK(14, 12)) >> 12) -#define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00 -#define OTGSTS_STRAP_HOST_OTG 0x01 -#define OTGSTS_STRAP_HOST 0x02 -#define OTGSTS_STRAP_GADGET 0x04 -/* Host mode is turned on. */ -#define OTGSTS_XHCI_READY BIT(26) -/* "Device mode is turned on .*/ -#define OTGSTS_DEV_READY BIT(27) - -/* OTGSTATE- bitmasks */ -#define OTGSTATE_DEV_STATE_MASK GENMASK(2, 0) -#define OTGSTATE_HOST_STATE_MASK GENMASK(5, 3) -#define OTGSTATE_HOST_STATE_IDLE 0x0 -#define OTGSTATE_HOST_STATE_VBUS_FALL 0x7 -#define OTGSTATE_HOST_STATE(p) (((p) & OTGSTATE_HOST_STATE_MASK) >> 3) - -/* OTGREFCLK - bitmasks */ -#define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31) - -/* OVERRIDE - bitmasks */ -#define OVERRIDE_IDPULLUP BIT(0) -/* Only for CDNS3_CONTROLLER_V0 version */ -#define OVERRIDE_IDPULLUP_V0 BIT(24) - -int cdns3_is_host(struct cdns3 *cdns); -int cdns3_is_device(struct cdns3 *cdns); -int cdns3_get_id(struct cdns3 *cdns); -int cdns3_get_vbus(struct cdns3 *cdns); -int cdns3_drd_init(struct cdns3 *cdns); -int cdns3_drd_exit(struct cdns3 *cdns); -int cdns3_drd_update_mode(struct cdns3 *cdns); -int cdns3_drd_switch_gadget(struct cdns3 *cdns, int on); -int cdns3_drd_switch_host(struct cdns3 *cdns, int on); - -#endif /* __LINUX_CDNS3_DRD */ diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c deleted file mode 100644 index 6fa711ead6d0..000000000000 --- a/drivers/usb/cdns3/ep0.c +++ /dev/null @@ -1,920 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Cadence USBSS DRD Driver - gadget side. - * - * Copyright (C) 2018 Cadence Design Systems. - * Copyright (C) 2017-2018 NXP - * - * Authors: Pawel Jez , - * Pawel Laszczak - * Peter Chen - */ - -#include - -#include "gadget.h" -#include "trace.h" - -static struct usb_endpoint_descriptor cdns3_gadget_ep0_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bmAttributes = USB_ENDPOINT_XFER_CONTROL, -}; - -/** - * cdns3_ep0_run_transfer - Do transfer on default endpoint hardware - * @priv_dev: extended gadget object - * @dma_addr: physical address where data is/will be stored - * @length: data length - * @erdy: set it to 1 when ERDY packet should be sent - - * exit from flow control state - */ -static void cdns3_ep0_run_transfer(struct cdns3_device *priv_dev, - dma_addr_t dma_addr, - unsigned int length, int erdy, int zlp) -{ - struct cdns3_usb_regs __iomem *regs = priv_dev->regs; - struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; - - priv_ep->trb_pool[0].buffer = TRB_BUFFER(dma_addr); - priv_ep->trb_pool[0].length = TRB_LEN(length); - - if (zlp) { - priv_ep->trb_pool[0].control = TRB_CYCLE | TRB_TYPE(TRB_NORMAL); - priv_ep->trb_pool[1].buffer = TRB_BUFFER(dma_addr); - priv_ep->trb_pool[1].length = TRB_LEN(0); - priv_ep->trb_pool[1].control = TRB_CYCLE | TRB_IOC | - TRB_TYPE(TRB_NORMAL); - } else { - priv_ep->trb_pool[0].control = TRB_CYCLE | TRB_IOC | - TRB_TYPE(TRB_NORMAL); - priv_ep->trb_pool[1].control = 0; - } - - trace_cdns3_prepare_trb(priv_ep, priv_ep->trb_pool); - - cdns3_select_ep(priv_dev, priv_dev->ep0_data_dir); - - writel(EP_STS_TRBERR, ®s->ep_sts); - writel(EP_TRADDR_TRADDR(priv_ep->trb_pool_dma), ®s->ep_traddr); - trace_cdns3_doorbell_ep0(priv_dev->ep0_data_dir ? "ep0in" : "ep0out", - readl(®s->ep_traddr)); - - /* TRB should be prepared before starting transfer. */ - writel(EP_CMD_DRDY, ®s->ep_cmd); - - /* Resume controller before arming transfer. */ - __cdns3_gadget_wakeup(priv_dev); - - if (erdy) - writel(EP_CMD_ERDY, &priv_dev->regs->ep_cmd); -} - -/** - * cdns3_ep0_delegate_req - Returns status of handling setup packet - * Setup is handled by gadget driver - * @priv_dev: extended gadget object - * @ctrl_req: pointer to received setup packet - * - * Returns zero on success or negative value on failure - */ -static int cdns3_ep0_delegate_req(struct cdns3_device *priv_dev, - struct usb_ctrlrequest *ctrl_req) -{ - int ret; - - spin_unlock(&priv_dev->lock); - priv_dev->setup_pending = 1; - ret = priv_dev->gadget_driver->setup(&priv_dev->gadget, ctrl_req); - priv_dev->setup_pending = 0; - spin_lock(&priv_dev->lock); - return ret; -} - -static void cdns3_prepare_setup_packet(struct cdns3_device *priv_dev) -{ - priv_dev->ep0_data_dir = 0; - priv_dev->ep0_stage = CDNS3_SETUP_STAGE; - cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, - sizeof(struct usb_ctrlrequest), 0, 0); -} - -static void cdns3_ep0_complete_setup(struct cdns3_device *priv_dev, - u8 send_stall, u8 send_erdy) -{ - struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; - struct usb_request *request; - - request = cdns3_next_request(&priv_ep->pending_req_list); - if (request) - list_del_init(&request->list); - - if (send_stall) { - cdns3_dbg(priv_ep->cdns3_dev, "STALL for ep0\n"); - /* set_stall on ep0 */ - cdns3_select_ep(priv_dev, 0x00); - writel(EP_CMD_SSTALL, &priv_dev->regs->ep_cmd); - } else { - cdns3_prepare_setup_packet(priv_dev); - } - - priv_dev->ep0_stage = CDNS3_SETUP_STAGE; - writel((send_erdy ? EP_CMD_ERDY : 0) | EP_CMD_REQ_CMPL, - &priv_dev->regs->ep_cmd); - - cdns3_allow_enable_l1(priv_dev, 1); -} - -/** - * cdns3_req_ep0_set_configuration - Handling of SET_CONFIG standard USB request - * @priv_dev: extended gadget object - * @ctrl_req: pointer to received setup packet - * - * Returns 0 if success, USB_GADGET_DELAYED_STATUS on deferred status stage, - * error code on error - */ -static int cdns3_req_ep0_set_configuration(struct cdns3_device *priv_dev, - struct usb_ctrlrequest *ctrl_req) -{ - enum usb_device_state device_state = priv_dev->gadget.state; - struct cdns3_endpoint *priv_ep; - u32 config = le16_to_cpu(ctrl_req->wValue); - int result = 0; - int i; - - switch (device_state) { - case USB_STATE_ADDRESS: - /* Configure non-control EPs */ - for (i = 0; i < CDNS3_ENDPOINTS_MAX_COUNT; i++) { - priv_ep = priv_dev->eps[i]; - if (!priv_ep) - continue; - - if (priv_ep->flags & EP_CLAIMED) - cdns3_ep_config(priv_ep); - } - - result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); - - if (result) - return result; - - if (config) { - cdns3_set_hw_configuration(priv_dev); - } else { - cdns3_hw_reset_eps_config(priv_dev); - usb_gadget_set_state(&priv_dev->gadget, - USB_STATE_ADDRESS); - } - break; - case USB_STATE_CONFIGURED: - result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); - - if (!config && !result) { - cdns3_hw_reset_eps_config(priv_dev); - usb_gadget_set_state(&priv_dev->gadget, - USB_STATE_ADDRESS); - } - break; - default: - result = -EINVAL; - } - - return result; -} - -/** - * cdns3_req_ep0_set_address - Handling of SET_ADDRESS standard USB request - * @priv_dev: extended gadget object - * @ctrl_req: pointer to received setup packet - * - * Returns 0 if success, error code on error - */ -static int cdns3_req_ep0_set_address(struct cdns3_device *priv_dev, - struct usb_ctrlrequest *ctrl_req) -{ - enum usb_device_state device_state = priv_dev->gadget.state; - u32 reg; - u32 addr; - - addr = le16_to_cpu(ctrl_req->wValue); - - if (addr > USB_DEVICE_MAX_ADDRESS) { - dev_err(priv_dev->dev, - "Device address (%d) cannot be greater than %d\n", - addr, USB_DEVICE_MAX_ADDRESS); - return -EINVAL; - } - - if (device_state == USB_STATE_CONFIGURED) { - dev_err(priv_dev->dev, - "can't set_address from configured state\n"); - return -EINVAL; - } - - reg = readl(&priv_dev->regs->usb_cmd); - - writel(reg | USB_CMD_FADDR(addr) | USB_CMD_SET_ADDR, - &priv_dev->regs->usb_cmd); - - usb_gadget_set_state(&priv_dev->gadget, - (addr ? USB_STATE_ADDRESS : USB_STATE_DEFAULT)); - - return 0; -} - -/** - * cdns3_req_ep0_get_status - Handling of GET_STATUS standard USB request - * @priv_dev: extended gadget object - * @ctrl_req: pointer to received setup packet - * - * Returns 0 if success, error code on error - */ -static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev, - struct usb_ctrlrequest *ctrl) -{ - __le16 *response_pkt; - u16 usb_status = 0; - u32 recip; - u32 reg; - - recip = ctrl->bRequestType & USB_RECIP_MASK; - - switch (recip) { - case USB_RECIP_DEVICE: - /* self powered */ - if (priv_dev->is_selfpowered) - usb_status = BIT(USB_DEVICE_SELF_POWERED); - - if (priv_dev->wake_up_flag) - usb_status |= BIT(USB_DEVICE_REMOTE_WAKEUP); - - if (priv_dev->gadget.speed != USB_SPEED_SUPER) - break; - - reg = readl(&priv_dev->regs->usb_sts); - - if (priv_dev->u1_allowed) - usb_status |= BIT(USB_DEV_STAT_U1_ENABLED); - - if (priv_dev->u2_allowed) - usb_status |= BIT(USB_DEV_STAT_U2_ENABLED); - - break; - case USB_RECIP_INTERFACE: - return cdns3_ep0_delegate_req(priv_dev, ctrl); - case USB_RECIP_ENDPOINT: - /* check if endpoint is stalled */ - cdns3_select_ep(priv_dev, ctrl->wIndex); - if (EP_STS_STALL(readl(&priv_dev->regs->ep_sts))) - usb_status = BIT(USB_ENDPOINT_HALT); - break; - default: - return -EINVAL; - } - - response_pkt = (__le16 *)priv_dev->setup_buf; - *response_pkt = cpu_to_le16(usb_status); - - cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, - sizeof(*response_pkt), 1, 0); - return 0; -} - -static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev, - struct usb_ctrlrequest *ctrl, - int set) -{ - enum usb_device_state state; - enum usb_device_speed speed; - int ret = 0; - u32 wValue; - u32 wIndex; - u16 tmode; - - wValue = le16_to_cpu(ctrl->wValue); - wIndex = le16_to_cpu(ctrl->wIndex); - state = priv_dev->gadget.state; - speed = priv_dev->gadget.speed; - - switch (ctrl->wValue) { - case USB_DEVICE_REMOTE_WAKEUP: - priv_dev->wake_up_flag = !!set; - break; - case USB_DEVICE_U1_ENABLE: - if (state != USB_STATE_CONFIGURED || speed != USB_SPEED_SUPER) - return -EINVAL; - - priv_dev->u1_allowed = !!set; - break; - case USB_DEVICE_U2_ENABLE: - if (state != USB_STATE_CONFIGURED || speed != USB_SPEED_SUPER) - return -EINVAL; - - priv_dev->u2_allowed = !!set; - break; - case USB_DEVICE_LTM_ENABLE: - ret = -EINVAL; - break; - case USB_DEVICE_TEST_MODE: - if (state != USB_STATE_CONFIGURED || speed > USB_SPEED_HIGH) - return -EINVAL; - - tmode = le16_to_cpu(ctrl->wIndex); - - if (!set || (tmode & 0xff) != 0) - return -EINVAL; - - switch (tmode >> 8) { - case TEST_J: - case TEST_K: - case TEST_SE0_NAK: - case TEST_PACKET: - cdns3_ep0_complete_setup(priv_dev, 0, 1); - /** - * Little delay to give the controller some time - * for sending status stage. - * This time should be less then 3ms. - */ - usleep_range(1000, 2000); - cdns3_set_register_bit(&priv_dev->regs->usb_cmd, - USB_CMD_STMODE | - USB_STS_TMODE_SEL(tmode - 1)); - break; - default: - ret = -EINVAL; - } - break; - default: - ret = -EINVAL; - } - - return ret; -} - -static int cdns3_ep0_feature_handle_intf(struct cdns3_device *priv_dev, - struct usb_ctrlrequest *ctrl, - int set) -{ - u32 wValue; - int ret = 0; - - wValue = le16_to_cpu(ctrl->wValue); - - switch (wValue) { - case USB_INTRF_FUNC_SUSPEND: - break; - default: - ret = -EINVAL; - } - - return ret; -} - -static int cdns3_ep0_feature_handle_endpoint(struct cdns3_device *priv_dev, - struct usb_ctrlrequest *ctrl, - int set) -{ - struct cdns3_endpoint *priv_ep; - int ret = 0; - u8 index; - - if (le16_to_cpu(ctrl->wValue) != USB_ENDPOINT_HALT) - return -EINVAL; - - if (!(ctrl->wIndex & ~USB_DIR_IN)) - return 0; - - index = cdns3_ep_addr_to_index(ctrl->wIndex); - priv_ep = priv_dev->eps[index]; - - cdns3_select_ep(priv_dev, ctrl->wIndex); - - if (set) { - cdns3_dbg(priv_ep->cdns3_dev, "Stall endpoint %s\n", - priv_ep->name); - writel(EP_CMD_SSTALL, &priv_dev->regs->ep_cmd); - priv_ep->flags |= EP_STALL; - } else { - struct usb_request *request; - - if (priv_dev->eps[index]->flags & EP_WEDGE) { - cdns3_select_ep(priv_dev, 0x00); - return 0; - } - - cdns3_dbg(priv_ep->cdns3_dev, "Clear Stalled endpoint %s\n", - priv_ep->name); - - writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd); - - /* wait for EPRST cleared */ - ret = cdns3_handshake(&priv_dev->regs->ep_cmd, - EP_CMD_EPRST, 0, 100); - if (ret) - return -EINVAL; - - priv_ep->flags &= ~EP_STALL; - - request = cdns3_next_request(&priv_ep->pending_req_list); - if (request) { - cdns3_dbg(priv_ep->cdns3_dev, "Resume transfer for %s\n", - priv_ep->name); - - cdns3_rearm_transfer(priv_ep, 1); - } - } - - return ret; -} - -/** - * cdns3_req_ep0_handle_feature - - * Handling of GET/SET_FEATURE standard USB request - * - * @priv_dev: extended gadget object - * @ctrl_req: pointer to received setup packet - * @set: must be set to 1 for SET_FEATURE request - * - * Returns 0 if success, error code on error - */ -static int cdns3_req_ep0_handle_feature(struct cdns3_device *priv_dev, - struct usb_ctrlrequest *ctrl, - int set) -{ - int ret = 0; - u32 recip; - - recip = ctrl->bRequestType & USB_RECIP_MASK; - - switch (recip) { - case USB_RECIP_DEVICE: - ret = cdns3_ep0_feature_handle_device(priv_dev, ctrl, set); - break; - case USB_RECIP_INTERFACE: - ret = cdns3_ep0_feature_handle_intf(priv_dev, ctrl, set); - break; - case USB_RECIP_ENDPOINT: - ret = cdns3_ep0_feature_handle_endpoint(priv_dev, ctrl, set); - break; - default: - return -EINVAL; - } - - return ret; -} - -/** - * cdns3_req_ep0_set_sel - Handling of SET_SEL standard USB request - * @priv_dev: extended gadget object - * @ctrl_req: pointer to received setup packet - * - * Returns 0 if success, error code on error - */ -static int cdns3_req_ep0_set_sel(struct cdns3_device *priv_dev, - struct usb_ctrlrequest *ctrl_req) -{ - if (priv_dev->gadget.state < USB_STATE_ADDRESS) - return -EINVAL; - - if (ctrl_req->wLength != 6) { - dev_err(priv_dev->dev, "Set SEL should be 6 bytes, got %d\n", - ctrl_req->wLength); - return -EINVAL; - } - - cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, 6, 1, 0); - return 0; -} - -/** - * cdns3_req_ep0_set_isoch_delay - - * Handling of GET_ISOCH_DELAY standard USB request - * @priv_dev: extended gadget object - * @ctrl_req: pointer to received setup packet - * - * Returns 0 if success, error code on error - */ -static int cdns3_req_ep0_set_isoch_delay(struct cdns3_device *priv_dev, - struct usb_ctrlrequest *ctrl_req) -{ - if (ctrl_req->wIndex || ctrl_req->wLength) - return -EINVAL; - - priv_dev->isoch_delay = ctrl_req->wValue; - - return 0; -} - -/** - * cdns3_ep0_standard_request - Handling standard USB requests - * @priv_dev: extended gadget object - * @ctrl_req: pointer to received setup packet - * - * Returns 0 if success, error code on error - */ -static int cdns3_ep0_standard_request(struct cdns3_device *priv_dev, - struct usb_ctrlrequest *ctrl_req) -{ - int ret; - - switch (ctrl_req->bRequest) { - case USB_REQ_SET_ADDRESS: - ret = cdns3_req_ep0_set_address(priv_dev, ctrl_req); - break; - case USB_REQ_SET_CONFIGURATION: - ret = cdns3_req_ep0_set_configuration(priv_dev, ctrl_req); - break; - case USB_REQ_GET_STATUS: - ret = cdns3_req_ep0_get_status(priv_dev, ctrl_req); - break; - case USB_REQ_CLEAR_FEATURE: - ret = cdns3_req_ep0_handle_feature(priv_dev, ctrl_req, 0); - break; - case USB_REQ_SET_FEATURE: - ret = cdns3_req_ep0_handle_feature(priv_dev, ctrl_req, 1); - break; - case USB_REQ_SET_SEL: - ret = cdns3_req_ep0_set_sel(priv_dev, ctrl_req); - break; - case USB_REQ_SET_ISOCH_DELAY: - ret = cdns3_req_ep0_set_isoch_delay(priv_dev, ctrl_req); - break; - default: - ret = cdns3_ep0_delegate_req(priv_dev, ctrl_req); - break; - } - - return ret; -} - -static void __pending_setup_status_handler(struct cdns3_device *priv_dev) -{ - struct usb_request *request = priv_dev->pending_status_request; - - if (priv_dev->status_completion_no_call && request && - request->complete) { - request->complete(&priv_dev->eps[0]->endpoint, request); - priv_dev->status_completion_no_call = 0; - } -} - -void cdns3_pending_setup_status_handler(struct work_struct *work) -{ - struct cdns3_device *priv_dev = container_of(work, struct cdns3_device, - pending_status_wq); - unsigned long flags; - - spin_lock_irqsave(&priv_dev->lock, flags); - __pending_setup_status_handler(priv_dev); - spin_unlock_irqrestore(&priv_dev->lock, flags); -} - -/** - * cdns3_ep0_setup_phase - Handling setup USB requests - * @priv_dev: extended gadget object - */ -static void cdns3_ep0_setup_phase(struct cdns3_device *priv_dev) -{ - struct usb_ctrlrequest *ctrl = priv_dev->setup_buf; - struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; - int result; - - priv_dev->ep0_data_dir = ctrl->bRequestType & USB_DIR_IN; - - trace_cdns3_ctrl_req(ctrl); - - if (!list_empty(&priv_ep->pending_req_list)) { - struct usb_request *request; - - request = cdns3_next_request(&priv_ep->pending_req_list); - priv_ep->dir = priv_dev->ep0_data_dir; - cdns3_gadget_giveback(priv_ep, to_cdns3_request(request), - -ECONNRESET); - } - - if (le16_to_cpu(ctrl->wLength)) - priv_dev->ep0_stage = CDNS3_DATA_STAGE; - else - priv_dev->ep0_stage = CDNS3_STATUS_STAGE; - - if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) - result = cdns3_ep0_standard_request(priv_dev, ctrl); - else - result = cdns3_ep0_delegate_req(priv_dev, ctrl); - - if (result == USB_GADGET_DELAYED_STATUS) - return; - - if (result < 0) - cdns3_ep0_complete_setup(priv_dev, 1, 1); - else if (priv_dev->ep0_stage == CDNS3_STATUS_STAGE) - cdns3_ep0_complete_setup(priv_dev, 0, 1); -} - -static void cdns3_transfer_completed(struct cdns3_device *priv_dev) -{ - struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; - - if (!list_empty(&priv_ep->pending_req_list)) { - struct usb_request *request; - - trace_cdns3_complete_trb(priv_ep, priv_ep->trb_pool); - request = cdns3_next_request(&priv_ep->pending_req_list); - - request->actual = - TRB_LEN(le32_to_cpu(priv_ep->trb_pool->length)); - - priv_ep->dir = priv_dev->ep0_data_dir; - cdns3_gadget_giveback(priv_ep, to_cdns3_request(request), 0); - } - - cdns3_ep0_complete_setup(priv_dev, 0, 0); -} - -/** - * cdns3_check_new_setup - Check if controller receive new SETUP packet. - * @priv_dev: extended gadget object - * - * The SETUP packet can be kept in on-chip memory or in system memory. - */ -static bool cdns3_check_new_setup(struct cdns3_device *priv_dev) -{ - u32 ep_sts_reg; - - cdns3_select_ep(priv_dev, 0 | USB_DIR_OUT); - ep_sts_reg = readl(&priv_dev->regs->ep_sts); - - return !!(ep_sts_reg & (EP_STS_SETUP | EP_STS_STPWAIT)); -} - -/** - * cdns3_check_ep0_interrupt_proceed - Processes interrupt related to endpoint 0 - * @priv_dev: extended gadget object - * @dir: USB_DIR_IN for IN direction, USB_DIR_OUT for OUT direction - */ -void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir) -{ - u32 ep_sts_reg; - - cdns3_select_ep(priv_dev, dir); - - ep_sts_reg = readl(&priv_dev->regs->ep_sts); - writel(ep_sts_reg, &priv_dev->regs->ep_sts); - - trace_cdns3_ep0_irq(priv_dev, ep_sts_reg); - - __pending_setup_status_handler(priv_dev); - - if (ep_sts_reg & EP_STS_SETUP) - priv_dev->wait_for_setup = 1; - - if (priv_dev->wait_for_setup && ep_sts_reg & EP_STS_IOC) { - priv_dev->wait_for_setup = 0; - cdns3_allow_enable_l1(priv_dev, 0); - cdns3_ep0_setup_phase(priv_dev); - } else if ((ep_sts_reg & EP_STS_IOC) || (ep_sts_reg & EP_STS_ISP)) { - priv_dev->ep0_data_dir = dir; - cdns3_transfer_completed(priv_dev); - } - - if (ep_sts_reg & EP_STS_DESCMIS) { - if (dir == 0 && !priv_dev->setup_pending) - cdns3_prepare_setup_packet(priv_dev); - } -} - -/** - * cdns3_gadget_ep0_enable - * Function shouldn't be called by gadget driver, - * endpoint 0 is allways active - */ -static int cdns3_gadget_ep0_enable(struct usb_ep *ep, - const struct usb_endpoint_descriptor *desc) -{ - return -EINVAL; -} - -/** - * cdns3_gadget_ep0_disable - * Function shouldn't be called by gadget driver, - * endpoint 0 is allways active - */ -static int cdns3_gadget_ep0_disable(struct usb_ep *ep) -{ - return -EINVAL; -} - -/** - * cdns3_gadget_ep0_set_halt - * @ep: pointer to endpoint zero object - * @value: 1 for set stall, 0 for clear stall - * - * Returns 0 - */ -static int cdns3_gadget_ep0_set_halt(struct usb_ep *ep, int value) -{ - /* TODO */ - return 0; -} - -/** - * cdns3_gadget_ep0_queue Transfer data on endpoint zero - * @ep: pointer to endpoint zero object - * @request: pointer to request object - * @gfp_flags: gfp flags - * - * Returns 0 on success, error code elsewhere - */ -static int cdns3_gadget_ep0_queue(struct usb_ep *ep, - struct usb_request *request, - gfp_t gfp_flags) -{ - struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - unsigned long flags; - int erdy_sent = 0; - int ret = 0; - u8 zlp = 0; - - cdns3_dbg(priv_ep->cdns3_dev, "Queue to Ep0%s L: %d\n", - priv_dev->ep0_data_dir ? "IN" : "OUT", - request->length); - - /* cancel the request if controller receive new SETUP packet. */ - if (cdns3_check_new_setup(priv_dev)) - return -ECONNRESET; - - /* send STATUS stage. Should be called only for SET_CONFIGURATION */ - if (priv_dev->ep0_stage == CDNS3_STATUS_STAGE) { - spin_lock_irqsave(&priv_dev->lock, flags); - cdns3_select_ep(priv_dev, 0x00); - - erdy_sent = !priv_dev->hw_configured_flag; - cdns3_set_hw_configuration(priv_dev); - - if (!erdy_sent) - cdns3_ep0_complete_setup(priv_dev, 0, 1); - - cdns3_allow_enable_l1(priv_dev, 1); - - request->actual = 0; - priv_dev->status_completion_no_call = true; - priv_dev->pending_status_request = request; - spin_unlock_irqrestore(&priv_dev->lock, flags); - - /* - * Since there is no completion interrupt for status stage, - * it needs to call ->completion in software after - * ep0_queue is back. - */ - queue_work(system_freezable_wq, &priv_dev->pending_status_wq); - return 0; - } - - spin_lock_irqsave(&priv_dev->lock, flags); - if (!list_empty(&priv_ep->pending_req_list)) { - dev_err(priv_dev->dev, - "can't handle multiple requests for ep0\n"); - spin_unlock_irqrestore(&priv_dev->lock, flags); - return -EBUSY; - } - - ret = usb_gadget_map_request_by_dev(priv_dev->sysdev, request, - priv_dev->ep0_data_dir); - if (ret) { - spin_unlock_irqrestore(&priv_dev->lock, flags); - dev_err(priv_dev->dev, "failed to map request\n"); - return -EINVAL; - } - - request->status = -EINPROGRESS; - list_add_tail(&request->list, &priv_ep->pending_req_list); - - if (request->zero && request->length && - (request->length % ep->maxpacket == 0)) - zlp = 1; - - cdns3_ep0_run_transfer(priv_dev, request->dma, request->length, 1, zlp); - - spin_unlock_irqrestore(&priv_dev->lock, flags); - - return ret; -} - -/** - * cdns3_gadget_ep_set_wedge Set wedge on selected endpoint - * @ep: endpoint object - * - * Returns 0 - */ -int cdns3_gadget_ep_set_wedge(struct usb_ep *ep) -{ - struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - - dev_dbg(priv_dev->dev, "Wedge for %s\n", ep->name); - cdns3_gadget_ep_set_halt(ep, 1); - priv_ep->flags |= EP_WEDGE; - - return 0; -} - -const struct usb_ep_ops cdns3_gadget_ep0_ops = { - .enable = cdns3_gadget_ep0_enable, - .disable = cdns3_gadget_ep0_disable, - .alloc_request = cdns3_gadget_ep_alloc_request, - .free_request = cdns3_gadget_ep_free_request, - .queue = cdns3_gadget_ep0_queue, - .dequeue = cdns3_gadget_ep_dequeue, - .set_halt = cdns3_gadget_ep0_set_halt, - .set_wedge = cdns3_gadget_ep_set_wedge, -}; - -/** - * cdns3_ep0_config - Configures default endpoint - * @priv_dev: extended gadget object - * - * Functions sets parameters: maximal packet size and enables interrupts - */ -void cdns3_ep0_config(struct cdns3_device *priv_dev) -{ - struct cdns3_usb_regs __iomem *regs; - struct cdns3_endpoint *priv_ep; - u32 max_packet_size = 64; - - regs = priv_dev->regs; - - if (priv_dev->gadget.speed == USB_SPEED_SUPER) - max_packet_size = 512; - - priv_ep = priv_dev->eps[0]; - - if (!list_empty(&priv_ep->pending_req_list)) { - struct usb_request *request; - - request = cdns3_next_request(&priv_ep->pending_req_list); - list_del_init(&request->list); - } - - priv_dev->u1_allowed = 0; - priv_dev->u2_allowed = 0; - - priv_dev->gadget.ep0->maxpacket = max_packet_size; - cdns3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(max_packet_size); - - /* init ep out */ - cdns3_select_ep(priv_dev, USB_DIR_OUT); - - if (priv_dev->dev_ver >= DEV_VER_V3) { - cdns3_set_register_bit(&priv_dev->regs->dtrans, - BIT(0) | BIT(16)); - cdns3_set_register_bit(&priv_dev->regs->tdl_from_trb, - BIT(0) | BIT(16)); - } - - writel(EP_CFG_ENABLE | EP_CFG_MAXPKTSIZE(max_packet_size), - ®s->ep_cfg); - - writel(EP_STS_EN_SETUPEN | EP_STS_EN_DESCMISEN | EP_STS_EN_TRBERREN, - ®s->ep_sts_en); - - /* init ep in */ - cdns3_select_ep(priv_dev, USB_DIR_IN); - - writel(EP_CFG_ENABLE | EP_CFG_MAXPKTSIZE(max_packet_size), - ®s->ep_cfg); - - writel(EP_STS_EN_SETUPEN | EP_STS_EN_TRBERREN, ®s->ep_sts_en); - - cdns3_set_register_bit(®s->usb_conf, USB_CONF_U1DS | USB_CONF_U2DS); -} - -/** - * cdns3_init_ep0 Initializes software endpoint 0 of gadget - * @priv_dev: extended gadget object - * @ep_priv: extended endpoint object - * - * Returns 0 on success else error code. - */ -int cdns3_init_ep0(struct cdns3_device *priv_dev, - struct cdns3_endpoint *priv_ep) -{ - sprintf(priv_ep->name, "ep0"); - - /* fill linux fields */ - priv_ep->endpoint.ops = &cdns3_gadget_ep0_ops; - priv_ep->endpoint.maxburst = 1; - usb_ep_set_maxpacket_limit(&priv_ep->endpoint, - CDNS3_EP0_MAX_PACKET_LIMIT); - priv_ep->endpoint.address = 0; - priv_ep->endpoint.caps.type_control = 1; - priv_ep->endpoint.caps.dir_in = 1; - priv_ep->endpoint.caps.dir_out = 1; - priv_ep->endpoint.name = priv_ep->name; - priv_ep->endpoint.desc = &cdns3_gadget_ep0_desc; - priv_dev->gadget.ep0 = &priv_ep->endpoint; - priv_ep->type = USB_ENDPOINT_XFER_CONTROL; - - return cdns3_allocate_trb_pool(priv_ep); -} diff --git a/drivers/usb/cdns3/gadget-export.h b/drivers/usb/cdns3/gadget-export.h deleted file mode 100644 index 577469eee961..000000000000 --- a/drivers/usb/cdns3/gadget-export.h +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Cadence USBSS DRD Driver - Gadget Export APIs. - * - * Copyright (C) 2017 NXP - * Copyright (C) 2017-2018 NXP - * - * Authors: Peter Chen - */ -#ifndef __LINUX_CDNS3_GADGET_EXPORT -#define __LINUX_CDNS3_GADGET_EXPORT - -#ifdef CONFIG_USB_CDNS3_GADGET - -int cdns3_gadget_init(struct cdns3 *cdns); -void cdns3_gadget_exit(struct cdns3 *cdns); -#else - -static inline int cdns3_gadget_init(struct cdns3 *cdns) -{ - return -ENXIO; -} - -static inline void cdns3_gadget_exit(struct cdns3 *cdns) { } - -#endif - -#endif /* __LINUX_CDNS3_GADGET_EXPORT */ diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c deleted file mode 100644 index 4e9e8e43f634..000000000000 --- a/drivers/usb/cdns3/gadget.c +++ /dev/null @@ -1,2319 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Cadence USBSS DRD Driver - gadget side. - * - * Copyright (C) 2018-2019 Cadence Design Systems. - * Copyright (C) 2017-2018 NXP - * - * Authors: Pawel Jez , - * Pawel Laszczak - * Peter Chen - */ - -/* - * Work around 1: - * At some situations, the controller may get stale data address in TRB - * at below sequences: - * 1. Controller read TRB includes data address - * 2. Software updates TRBs includes data address and Cycle bit - * 3. Controller read TRB which includes Cycle bit - * 4. DMA run with stale data address - * - * To fix this problem, driver needs to make the first TRB in TD as invalid. - * After preparing all TRBs driver needs to check the position of DMA and - * if the DMA point to the first just added TRB and doorbell is 1, - * then driver must defer making this TRB as valid. This TRB will be make - * as valid during adding next TRB only if DMA is stopped or at TRBERR - * interrupt. - * - * Issue has been fixed in DEV_VER_V3 version of controller. - * - */ - -#include -#include -#include - -#include "core.h" -#include "gadget-export.h" -#include "gadget.h" -#include "trace.h" -#include "drd.h" - -static int __cdns3_gadget_ep_queue(struct usb_ep *ep, - struct usb_request *request, - gfp_t gfp_flags); - -/** - * cdns3_set_register_bit - set bit in given register. - * @ptr: address of device controller register to be read and changed - * @mask: bits requested to set - */ -void cdns3_set_register_bit(void __iomem *ptr, u32 mask) -{ - mask = readl(ptr) | mask; - writel(mask, ptr); -} - -/** - * cdns3_ep_addr_to_index - Macro converts endpoint address to - * index of endpoint object in cdns3_device.eps[] container - * @ep_addr: endpoint address for which endpoint object is required - * - */ -u8 cdns3_ep_addr_to_index(u8 ep_addr) -{ - return (((ep_addr & 0x7F)) + ((ep_addr & USB_DIR_IN) ? 16 : 0)); -} - -static int cdns3_get_dma_pos(struct cdns3_device *priv_dev, - struct cdns3_endpoint *priv_ep) -{ - int dma_index; - - dma_index = readl(&priv_dev->regs->ep_traddr) - priv_ep->trb_pool_dma; - - return dma_index / TRB_SIZE; -} - -/** - * cdns3_next_request - returns next request from list - * @list: list containing requests - * - * Returns request or NULL if no requests in list - */ -struct usb_request *cdns3_next_request(struct list_head *list) -{ - return list_first_entry_or_null(list, struct usb_request, list); -} - -/** - * cdns3_next_align_buf - returns next buffer from list - * @list: list containing buffers - * - * Returns buffer or NULL if no buffers in list - */ -struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list) -{ - return list_first_entry_or_null(list, struct cdns3_aligned_buf, list); -} - -/** - * select_ep - selects endpoint - * @priv_dev: extended gadget object - * @ep: endpoint address - */ -void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep) -{ - if (priv_dev->selected_ep == ep) - return; - - priv_dev->selected_ep = ep; - writel(ep, &priv_dev->regs->ep_sel); -} - -dma_addr_t cdns3_trb_virt_to_dma(struct cdns3_endpoint *priv_ep, - struct cdns3_trb *trb) -{ - u32 offset = (char *)trb - (char *)priv_ep->trb_pool; - - return priv_ep->trb_pool_dma + offset; -} - -int cdns3_ring_size(struct cdns3_endpoint *priv_ep) -{ - switch (priv_ep->type) { - case USB_ENDPOINT_XFER_ISOC: - return TRB_ISO_RING_SIZE; - case USB_ENDPOINT_XFER_CONTROL: - return TRB_CTRL_RING_SIZE; - default: - return TRB_RING_SIZE; - } -} - -/** - * cdns3_allocate_trb_pool - Allocates TRB's pool for selected endpoint - * @priv_ep: endpoint object - * - * Function will return 0 on success or -ENOMEM on allocation error - */ -int cdns3_allocate_trb_pool(struct cdns3_endpoint *priv_ep) -{ - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - int ring_size = cdns3_ring_size(priv_ep); - struct cdns3_trb *link_trb; - - if (!priv_ep->trb_pool) { - priv_ep->trb_pool = dma_alloc_coherent(priv_dev->sysdev, - ring_size, - &priv_ep->trb_pool_dma, - GFP_DMA32 | GFP_ATOMIC); - if (!priv_ep->trb_pool) - return -ENOMEM; - } else { - memset(priv_ep->trb_pool, 0, ring_size); - } - - if (!priv_ep->num) - return 0; - - priv_ep->num_trbs = ring_size / TRB_SIZE; - /* Initialize the last TRB as Link TRB */ - link_trb = (priv_ep->trb_pool + (priv_ep->num_trbs - 1)); - link_trb->buffer = TRB_BUFFER(priv_ep->trb_pool_dma); - link_trb->control = TRB_CYCLE | TRB_TYPE(TRB_LINK) | TRB_TOGGLE; - - return 0; -} - -static void cdns3_free_trb_pool(struct cdns3_endpoint *priv_ep) -{ - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - - if (priv_ep->trb_pool) { - dma_free_coherent(priv_dev->sysdev, - cdns3_ring_size(priv_ep), - priv_ep->trb_pool, priv_ep->trb_pool_dma); - priv_ep->trb_pool = NULL; - } -} - -/** - * cdns3_ep_stall_flush - Stalls and flushes selected endpoint - * @priv_ep: endpoint object - * - * Endpoint must be selected before call to this function - */ -static void cdns3_ep_stall_flush(struct cdns3_endpoint *priv_ep) -{ - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - - cdns3_dbg(priv_ep->cdns3_dev, "Stall & flush endpoint %s\n", - priv_ep->name); - - writel(EP_CMD_DFLUSH | EP_CMD_ERDY | EP_CMD_SSTALL, - &priv_dev->regs->ep_cmd); - - /* wait for DFLUSH cleared */ - cdns3_handshake(&priv_dev->regs->ep_cmd, EP_CMD_DFLUSH, 0, 1000); - priv_ep->flags |= EP_STALL; -} - -/** - * cdns3_hw_reset_eps_config - reset endpoints configuration kept by controller. - * @priv_dev: extended gadget object - */ -void cdns3_hw_reset_eps_config(struct cdns3_device *priv_dev) -{ - writel(USB_CONF_CFGRST, &priv_dev->regs->usb_conf); - - cdns3_allow_enable_l1(priv_dev, 0); - priv_dev->hw_configured_flag = 0; - priv_dev->onchip_used_size = 0; - priv_dev->out_mem_is_allocated = 0; - priv_dev->wait_for_setup = 0; -} - -/** - * cdns3_ep_inc_trb - increment a trb index. - * @index: Pointer to the TRB index to increment. - * @cs: Cycle state - * @trb_in_seg: number of TRBs in segment - * - * The index should never point to the link TRB. After incrementing, - * if it is point to the link TRB, wrap around to the beginning and revert - * cycle state bit The - * link TRB is always at the last TRB entry. - */ -static void cdns3_ep_inc_trb(int *index, u8 *cs, int trb_in_seg) -{ - (*index)++; - if (*index == (trb_in_seg - 1)) { - *index = 0; - *cs ^= 1; - } -} - -/** - * cdns3_ep_inc_enq - increment endpoint's enqueue pointer - * @priv_ep: The endpoint whose enqueue pointer we're incrementing - */ -static void cdns3_ep_inc_enq(struct cdns3_endpoint *priv_ep) -{ - priv_ep->free_trbs--; - cdns3_ep_inc_trb(&priv_ep->enqueue, &priv_ep->pcs, priv_ep->num_trbs); -} - -/** - * cdns3_ep_inc_deq - increment endpoint's dequeue pointer - * @priv_ep: The endpoint whose dequeue pointer we're incrementing - */ -static void cdns3_ep_inc_deq(struct cdns3_endpoint *priv_ep) -{ - priv_ep->free_trbs++; - cdns3_ep_inc_trb(&priv_ep->dequeue, &priv_ep->ccs, priv_ep->num_trbs); -} - -void cdns3_move_deq_to_next_trb(struct cdns3_request *priv_req) -{ - struct cdns3_endpoint *priv_ep = priv_req->priv_ep; - int current_trb = priv_req->start_trb; - - while (current_trb != priv_req->end_trb) { - cdns3_ep_inc_deq(priv_ep); - current_trb = priv_ep->dequeue; - } - - cdns3_ep_inc_deq(priv_ep); -} - -/** - * cdns3_allow_enable_l1 - enable/disable permits to transition to L1. - * @priv_dev: Extended gadget object - * @enable: Enable/disable permit to transition to L1. - * - * If bit USB_CONF_L1EN is set and device receive Extended Token packet, - * then controller answer with ACK handshake. - * If bit USB_CONF_L1DS is set and device receive Extended Token packet, - * then controller answer with NYET handshake. - */ -void cdns3_allow_enable_l1(struct cdns3_device *priv_dev, int enable) -{ - if (enable) - writel(USB_CONF_L1EN, &priv_dev->regs->usb_conf); - else - writel(USB_CONF_L1DS, &priv_dev->regs->usb_conf); -} - -enum usb_device_speed cdns3_get_speed(struct cdns3_device *priv_dev) -{ - u32 reg; - - reg = readl(&priv_dev->regs->usb_sts); - - if (DEV_SUPERSPEED(reg)) - return USB_SPEED_SUPER; - else if (DEV_HIGHSPEED(reg)) - return USB_SPEED_HIGH; - else if (DEV_FULLSPEED(reg)) - return USB_SPEED_FULL; - else if (DEV_LOWSPEED(reg)) - return USB_SPEED_LOW; - return USB_SPEED_UNKNOWN; -} - -/** - * cdns3_start_all_request - add to ring all request not started - * @priv_dev: Extended gadget object - * @priv_ep: The endpoint for whom request will be started. - * - * Returns return ENOMEM if transfer ring i not enough TRBs to start - * all requests. - */ -static int cdns3_start_all_request(struct cdns3_device *priv_dev, - struct cdns3_endpoint *priv_ep) -{ - struct cdns3_request *priv_req; - struct usb_request *request; - int ret = 0; - - while (!list_empty(&priv_ep->deferred_req_list)) { - request = cdns3_next_request(&priv_ep->deferred_req_list); - priv_req = to_cdns3_request(request); - - ret = cdns3_ep_run_transfer(priv_ep, request); - if (ret) - return ret; - - list_del(&request->list); - list_add_tail(&request->list, - &priv_ep->pending_req_list); - } - - priv_ep->flags &= ~EP_RING_FULL; - return ret; -} - -/** - * cdns3_gadget_giveback - call struct usb_request's ->complete callback - * @priv_ep: The endpoint to whom the request belongs to - * @priv_req: The request we're giving back - * @status: completion code for the request - * - * Must be called with controller's lock held and interrupts disabled. This - * function will unmap @req and call its ->complete() callback to notify upper - * layers that it has completed. - */ -void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, - struct cdns3_request *priv_req, - int status) -{ - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - struct usb_request *request = &priv_req->request; - - list_del_init(&request->list); - - if (request->status == -EINPROGRESS) - request->status = status; - - usb_gadget_unmap_request_by_dev(priv_dev->sysdev, request, - priv_ep->dir); - - if ((priv_req->flags & REQUEST_UNALIGNED) && - priv_ep->dir == USB_DIR_OUT && !request->status) - memcpy(request->buf, priv_req->aligned_buf->buf, - request->length); - - priv_req->flags &= ~(REQUEST_PENDING | REQUEST_UNALIGNED); - trace_cdns3_gadget_giveback(priv_req); - - if (request->complete) { - spin_unlock(&priv_dev->lock); - usb_gadget_giveback_request(&priv_ep->endpoint, - request); - spin_lock(&priv_dev->lock); - } - - if (request->buf == priv_dev->zlp_buf) - cdns3_gadget_ep_free_request(&priv_ep->endpoint, request); -} - -void cdns3_wa1_restore_cycle_bit(struct cdns3_endpoint *priv_ep) -{ - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - - /* Work around for stale data address in TRB*/ - if (priv_ep->wa1_set) { - cdns3_dbg(priv_dev, "WA1: update cycle bit\n"); - priv_ep->wa1_set = 0; - priv_ep->wa1_trb_index = 0xFFFF; - if (priv_ep->wa1_cycle_bit) { - priv_ep->wa1_trb->control = - priv_ep->wa1_trb->control | 0x1; - } else { - priv_ep->wa1_trb->control = - priv_ep->wa1_trb->control & ~0x1; - } - } -} - -static int cdns3_prepare_aligned_request_buf(struct cdns3_request *priv_req) -{ - struct cdns3_endpoint *priv_ep = priv_req->priv_ep; - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - struct cdns3_aligned_buf *buf; - - /* check if buffer is aligned to 8. */ - if (!((uintptr_t)priv_req->request.buf & 0x7)) - return 0; - - buf = priv_req->aligned_buf; - - if (!buf || priv_req->request.length > buf->size) { - buf = kzalloc(sizeof(*buf), GFP_ATOMIC); - if (!buf) - return -ENOMEM; - - buf->size = priv_req->request.length; - - buf->buf = dma_alloc_coherent(priv_dev->sysdev, - buf->size, - &buf->dma, - GFP_ATOMIC); - if (!buf->buf) { - kfree(buf); - return -ENOMEM; - } - - if (priv_req->aligned_buf) { - trace_cdns3_free_aligned_request(priv_req); - priv_req->aligned_buf->in_use = 0; - priv_dev->run_garbage_colector = 1; - } - - buf->in_use = 1; - priv_req->aligned_buf = buf; - - list_add_tail(&buf->list, - &priv_dev->aligned_buf_list); - } - - if (priv_ep->dir == USB_DIR_IN) { - memcpy(buf->buf, priv_req->request.buf, - priv_req->request.length); - } - - priv_req->flags |= REQUEST_UNALIGNED; - trace_cdns3_prepare_aligned_request(priv_req); - - return 0; -} - -static int cdns3_wa1_update_guard(struct cdns3_endpoint *priv_ep, - struct cdns3_trb *trb) -{ - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - - if (!priv_ep->wa1_set) { - u32 doorbell; - - doorbell = !!(readl(&priv_dev->regs->ep_cmd) & EP_CMD_DRDY); - - if (doorbell) { - priv_ep->wa1_cycle_bit = priv_ep->pcs ? TRB_CYCLE : 0; - priv_ep->wa1_set = 1; - priv_ep->wa1_trb = trb; - priv_ep->wa1_trb_index = priv_ep->enqueue; - cdns3_dbg(priv_dev, "WA1 set guard\n"); - return 0; - } - } - return 1; -} - -static void cdns3_wa1_tray_restore_cycle_bit(struct cdns3_device *priv_dev, - struct cdns3_endpoint *priv_ep) -{ - int dma_index; - u32 doorbell; - - doorbell = !!(readl(&priv_dev->regs->ep_cmd) & EP_CMD_DRDY); - dma_index = cdns3_get_dma_pos(priv_dev, priv_ep); - - if (!doorbell || dma_index != priv_ep->wa1_trb_index) - cdns3_wa1_restore_cycle_bit(priv_ep); -} - -/** - * cdns3_ep_run_transfer - start transfer on no-default endpoint hardware - * @priv_ep: endpoint object - * - * Returns zero on success or negative value on failure - */ -int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, - struct usb_request *request) -{ - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - struct cdns3_request *priv_req; - struct cdns3_trb *trb; - dma_addr_t trb_dma; - u32 togle_pcs = 1; - int sg_iter = 0; - int num_trb; - int address; - u32 control; - int pcs; - - if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) - num_trb = priv_ep->interval; - else - num_trb = request->num_sgs ? request->num_sgs : 1; - - if (num_trb > priv_ep->free_trbs) { - priv_ep->flags |= EP_RING_FULL; - return -ENOBUFS; - } - - priv_req = to_cdns3_request(request); - address = priv_ep->endpoint.desc->bEndpointAddress; - - priv_ep->flags |= EP_PENDING_REQUEST; - - /* must allocate buffer aligned to 8 */ - if (priv_req->flags & REQUEST_UNALIGNED) - trb_dma = priv_req->aligned_buf->dma; - else - trb_dma = request->dma; - - trb = priv_ep->trb_pool + priv_ep->enqueue; - priv_req->start_trb = priv_ep->enqueue; - priv_req->trb = trb; - - cdns3_select_ep(priv_ep->cdns3_dev, address); - - /* prepare ring */ - if ((priv_ep->enqueue + num_trb) >= (priv_ep->num_trbs - 1)) { - struct cdns3_trb *link_trb; - int doorbell, dma_index; - u32 ch_bit = 0; - - doorbell = !!(readl(&priv_dev->regs->ep_cmd) & EP_CMD_DRDY); - dma_index = cdns3_get_dma_pos(priv_dev, priv_ep); - - /* Driver can't update LINK TRB if it is current processed. */ - if (doorbell && dma_index == priv_ep->num_trbs - 1) { - priv_ep->flags |= EP_DEFERRED_DRDY; - return -ENOBUFS; - } - - /*updating C bt in Link TRB before starting DMA*/ - link_trb = priv_ep->trb_pool + (priv_ep->num_trbs - 1); - /* - * For TRs size equal 2 enabling TRB_CHAIN for epXin causes - * that DMA stuck at the LINK TRB. - * On the other hand, removing TRB_CHAIN for longer TRs for - * epXout cause that DMA stuck after handling LINK TRB. - * To eliminate this strange behavioral driver set TRB_CHAIN - * bit only for TR size > 2. - */ - if (priv_ep->type == USB_ENDPOINT_XFER_ISOC || - TRBS_PER_SEGMENT > 2) - ch_bit = TRB_CHAIN; - - link_trb->control = ((priv_ep->pcs) ? TRB_CYCLE : 0) | - TRB_TYPE(TRB_LINK) | TRB_TOGGLE | ch_bit; - } - - if (priv_dev->dev_ver <= DEV_VER_V2) - togle_pcs = cdns3_wa1_update_guard(priv_ep, trb); - - /* set incorrect Cycle Bit for first trb*/ - control = priv_ep->pcs ? 0 : TRB_CYCLE; - - do { - u32 length; - u16 td_size = 0; - - /* fill TRB */ - control |= TRB_TYPE(TRB_NORMAL); - trb->buffer = TRB_BUFFER(request->num_sgs == 0 - ? trb_dma : request->sg[sg_iter].dma_address); - - if (likely(!request->num_sgs)) - length = request->length; - else - length = request->sg[sg_iter].length; - - if (likely(priv_dev->dev_ver >= DEV_VER_V2)) - td_size = DIV_ROUND_UP(length, - priv_ep->endpoint.maxpacket); - - trb->length = TRB_BURST_LEN(priv_ep->trb_burst_size) | - TRB_LEN(length); - if (priv_dev->gadget.speed == USB_SPEED_SUPER) - trb->length |= TRB_TDL_SS_SIZE(td_size); - else - control |= TRB_TDL_HS_SIZE(td_size); - - pcs = priv_ep->pcs ? TRB_CYCLE : 0; - - /* - * first trb should be prepared as last to avoid processing - * transfer to early - */ - if (sg_iter != 0) - control |= pcs; - - if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir) { - control |= TRB_IOC | TRB_ISP; - } else { - /* for last element in TD or in SG list */ - if (sg_iter == (num_trb - 1) && sg_iter != 0) - control |= pcs | TRB_IOC | TRB_ISP; - } - - if (sg_iter) - trb->control = control; - else - priv_req->trb->control = control; - - control = 0; - ++sg_iter; - priv_req->end_trb = priv_ep->enqueue; - cdns3_ep_inc_enq(priv_ep); - trb = priv_ep->trb_pool + priv_ep->enqueue; - } while (sg_iter < num_trb); - - trb = priv_req->trb; - - priv_req->flags |= REQUEST_PENDING; - - if (sg_iter == 1) - trb->control |= TRB_IOC | TRB_ISP; - /* - * Memory barrier - cycle bit must be set before other filds in trb. - */ - wmb(); - - /* give the TD to the consumer*/ - if (togle_pcs) - trb->control = trb->control ^ 1; - - if (priv_dev->dev_ver <= DEV_VER_V2) - cdns3_wa1_tray_restore_cycle_bit(priv_dev, priv_ep); - - trace_cdns3_prepare_trb(priv_ep, priv_req->trb); - - /* - * Memory barrier - Cycle Bit must be set before trb->length and - * trb->buffer fields. - */ - wmb(); - - /* - * For DMULT mode we can set address to transfer ring only once after - * enabling endpoint. - */ - if (priv_ep->flags & EP_UPDATE_EP_TRBADDR) { - /* - * Until SW is not ready to handle the OUT transfer the ISO OUT - * Endpoint should be disabled (EP_CFG.ENABLE = 0). - * EP_CFG_ENABLE must be set before updating ep_traddr. - */ - if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir && - !(priv_ep->flags & EP_QUIRK_ISO_OUT_EN)) { - priv_ep->flags |= EP_QUIRK_ISO_OUT_EN; - cdns3_set_register_bit(&priv_dev->regs->ep_cfg, - EP_CFG_ENABLE); - } - - writel(EP_TRADDR_TRADDR(priv_ep->trb_pool_dma + - priv_req->start_trb * TRB_SIZE), - &priv_dev->regs->ep_traddr); - - cdns3_dbg(priv_ep->cdns3_dev, "Update ep_trbaddr for %s to %08x\n", - priv_ep->name, readl(&priv_dev->regs->ep_traddr)); - - priv_ep->flags &= ~EP_UPDATE_EP_TRBADDR; - } - - if (!priv_ep->wa1_set && !(priv_ep->flags & EP_STALL)) { - trace_cdns3_ring(priv_ep); - /*clearing TRBERR and EP_STS_DESCMIS before seting DRDY*/ - writel(EP_STS_TRBERR | EP_STS_DESCMIS, &priv_dev->regs->ep_sts); - writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd); - trace_cdns3_doorbell_epx(priv_ep->name, - readl(&priv_dev->regs->ep_traddr)); - } - - /* WORKAROUND for transition to L0 */ - __cdns3_gadget_wakeup(priv_dev); - - return 0; -} - -void cdns3_set_hw_configuration(struct cdns3_device *priv_dev) -{ - struct cdns3_endpoint *priv_ep; - struct usb_ep *ep; - int result = 0; - - if (priv_dev->hw_configured_flag) - return; - - writel(USB_CONF_CFGSET, &priv_dev->regs->usb_conf); - writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); - - cdns3_set_register_bit(&priv_dev->regs->usb_conf, - USB_CONF_U1EN | USB_CONF_U2EN); - - /* wait until configuration set */ - result = cdns3_handshake(&priv_dev->regs->usb_sts, - USB_STS_CFGSTS_MASK, 1, 100); - - priv_dev->hw_configured_flag = 1; - - list_for_each_entry(ep, &priv_dev->gadget.ep_list, ep_list) { - if (ep->enabled) { - priv_ep = ep_to_cdns3_ep(ep); - cdns3_start_all_request(priv_dev, priv_ep); - } - } -} - -/** - * cdns3_request_handled - check whether request has been handled by DMA - * - * @priv_ep: extended endpoint object. - * @priv_req: request object for checking - * - * Endpoint must be selected before invoking this function. - * - * Returns false if request has not been handled by DMA, else returns true. - * - * SR - start ring - * ER - end ring - * DQ = priv_ep->dequeue - dequeue position - * EQ = priv_ep->enqueue - enqueue position - * ST = priv_req->start_trb - index of first TRB in transfer ring - * ET = priv_req->end_trb - index of last TRB in transfer ring - * CI = current_index - index of processed TRB by DMA. - * - * As first step, function checks if cycle bit for priv_req->start_trb is - * correct. - * - * some rules: - * 1. priv_ep->dequeue never exceed current_index. - * 2 priv_ep->enqueue never exceed priv_ep->dequeue - * 3. exception: priv_ep->enqueue == priv_ep->dequeue - * and priv_ep->free_trbs is zero. - * This case indicate that TR is full. - * - * Then We can split recognition into two parts: - * Case 1 - priv_ep->dequeue < current_index - * SR ... EQ ... DQ ... CI ... ER - * SR ... DQ ... CI ... EQ ... ER - * - * Request has been handled by DMA if ST and ET is between DQ and CI. - * - * Case 2 - priv_ep->dequeue > current_index - * This situation take place when CI go through the LINK TRB at the end of - * transfer ring. - * SR ... CI ... EQ ... DQ ... ER - * - * Request has been handled by DMA if ET is less then CI or - * ET is greater or equal DQ. - */ -static bool cdns3_request_handled(struct cdns3_endpoint *priv_ep, - struct cdns3_request *priv_req) -{ - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - struct cdns3_trb *trb = priv_req->trb; - int current_index = 0; - int handled = 0; - int doorbell; - - current_index = cdns3_get_dma_pos(priv_dev, priv_ep); - doorbell = !!(readl(&priv_dev->regs->ep_cmd) & EP_CMD_DRDY); - - trb = &priv_ep->trb_pool[priv_req->start_trb]; - - if ((trb->control & TRB_CYCLE) != priv_ep->ccs) - goto finish; - - if (doorbell == 1 && current_index == priv_ep->dequeue) - goto finish; - - /* The corner case for TRBS_PER_SEGMENT equal 2). */ - if (TRBS_PER_SEGMENT == 2 && priv_ep->type != USB_ENDPOINT_XFER_ISOC) { - handled = 1; - goto finish; - } - - if (priv_ep->enqueue == priv_ep->dequeue && - priv_ep->free_trbs == 0) { - handled = 1; - } else if (priv_ep->dequeue < current_index) { - if ((current_index == (priv_ep->num_trbs - 1)) && - !priv_ep->dequeue) - goto finish; - - if (priv_req->end_trb >= priv_ep->dequeue && - priv_req->end_trb < current_index) - handled = 1; - } else if (priv_ep->dequeue > current_index) { - if (priv_req->end_trb < current_index || - priv_req->end_trb >= priv_ep->dequeue) - handled = 1; - } - -finish: - trace_cdns3_request_handled(priv_req, current_index, handled); - - return handled; -} - -static void cdns3_transfer_completed(struct cdns3_device *priv_dev, - struct cdns3_endpoint *priv_ep) -{ - struct cdns3_request *priv_req; - struct usb_request *request; - struct cdns3_trb *trb; - - while (!list_empty(&priv_ep->pending_req_list)) { - request = cdns3_next_request(&priv_ep->pending_req_list); - priv_req = to_cdns3_request(request); - - /* Re-select endpoint. It could be changed by other CPU during - * handling usb_gadget_giveback_request. - */ - cdns3_select_ep(priv_dev, priv_ep->endpoint.address); - - if (!cdns3_request_handled(priv_ep, priv_req)) - goto prepare_next_td; - - trb = priv_ep->trb_pool + priv_ep->dequeue; - trace_cdns3_complete_trb(priv_ep, trb); - - if (trb != priv_req->trb) - dev_warn(priv_dev->dev, - "request_trb=0x%p, queue_trb=0x%p\n", - priv_req->trb, trb); - - request->actual = TRB_LEN(le32_to_cpu(trb->length)); - cdns3_move_deq_to_next_trb(priv_req); - cdns3_gadget_giveback(priv_ep, priv_req, 0); - - if (priv_ep->type != USB_ENDPOINT_XFER_ISOC && - TRBS_PER_SEGMENT == 2) - break; - } - priv_ep->flags &= ~EP_PENDING_REQUEST; - -prepare_next_td: - cdns3_start_all_request(priv_dev, priv_ep); -} - -void cdns3_rearm_transfer(struct cdns3_endpoint *priv_ep, u8 rearm) -{ - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - - cdns3_wa1_restore_cycle_bit(priv_ep); - - if (rearm) { - trace_cdns3_ring(priv_ep); - - /* Cycle Bit must be updated before arming DMA. */ - wmb(); - writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd); - - __cdns3_gadget_wakeup(priv_dev); - - trace_cdns3_doorbell_epx(priv_ep->name, - readl(&priv_dev->regs->ep_traddr)); - } -} - -/** - * cdns3_check_ep_interrupt_proceed - Processes interrupt related to endpoint - * @priv_ep: endpoint object - * - * Returns 0 - */ -static int cdns3_check_ep_interrupt_proceed(struct cdns3_endpoint *priv_ep) -{ - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - u32 ep_sts_reg; - - cdns3_select_ep(priv_dev, priv_ep->endpoint.address); - - trace_cdns3_epx_irq(priv_dev, priv_ep); - - ep_sts_reg = readl(&priv_dev->regs->ep_sts); - writel(ep_sts_reg, &priv_dev->regs->ep_sts); - - if (ep_sts_reg & EP_STS_TRBERR) { - /* - * For isochronous transfer driver completes request on - * IOC or on TRBERR. IOC appears only when device receive - * OUT data packet. If host disable stream or lost some packet - * then the only way to finish all queued transfer is to do it - * on TRBERR event. - */ - if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && - !priv_ep->wa1_set) { - if (!priv_ep->dir) { - u32 ep_cfg = readl(&priv_dev->regs->ep_cfg); - - ep_cfg &= ~EP_CFG_ENABLE; - writel(ep_cfg, &priv_dev->regs->ep_cfg); - priv_ep->flags &= ~EP_QUIRK_ISO_OUT_EN; - } - cdns3_transfer_completed(priv_dev, priv_ep); - } else { - if (priv_ep->flags & EP_DEFERRED_DRDY) { - priv_ep->flags &= ~EP_DEFERRED_DRDY; - cdns3_start_all_request(priv_dev, priv_ep); - } else { - cdns3_rearm_transfer(priv_ep, priv_ep->wa1_set); - } - } - } - - if ((ep_sts_reg & EP_STS_IOC) || (ep_sts_reg & EP_STS_ISP)) - cdns3_transfer_completed(priv_dev, priv_ep); - - return 0; -} - -/** - * cdns3_check_usb_interrupt_proceed - Processes interrupt related to device - * @priv_dev: extended gadget object - * @usb_ists: bitmap representation of device's reported interrupts - * (usb_ists register value) - */ -static void cdns3_check_usb_interrupt_proceed(struct cdns3_device *priv_dev, - u32 usb_ists) -{ - int speed = 0; - - trace_cdns3_usb_irq(priv_dev, usb_ists); - if (usb_ists & USB_ISTS_L1ENTI) { - /* - * WORKAROUND: CDNS3 controller has issue with hardware resuming - * from L1. To fix it, if any DMA transfer is pending driver - * must starts driving resume signal immediately. - */ - if (readl(&priv_dev->regs->drbl)) - __cdns3_gadget_wakeup(priv_dev); - } - - /* Connection detected */ - if (usb_ists & (USB_ISTS_CON2I | USB_ISTS_CONI)) { - speed = cdns3_get_speed(priv_dev); - priv_dev->gadget.speed = speed; - usb_gadget_set_state(&priv_dev->gadget, USB_STATE_POWERED); - cdns3_ep0_config(priv_dev); - } - - /* Disconnection detected */ - if (usb_ists & (USB_ISTS_DIS2I | USB_ISTS_DISI)) { - if (priv_dev->gadget_driver && - priv_dev->gadget_driver->disconnect) { - spin_unlock(&priv_dev->lock); - priv_dev->gadget_driver->disconnect(&priv_dev->gadget); - spin_lock(&priv_dev->lock); - } - - priv_dev->gadget.speed = USB_SPEED_UNKNOWN; - usb_gadget_set_state(&priv_dev->gadget, USB_STATE_NOTATTACHED); - cdns3_hw_reset_eps_config(priv_dev); - } - - if (usb_ists & (USB_ISTS_L2ENTI | USB_ISTS_U3ENTI)) { - if (priv_dev->gadget_driver && - priv_dev->gadget_driver->suspend) { - spin_unlock(&priv_dev->lock); - priv_dev->gadget_driver->suspend(&priv_dev->gadget); - spin_lock(&priv_dev->lock); - } - } - - if (usb_ists & (USB_ISTS_L2EXTI | USB_ISTS_U3EXTI)) { - if (priv_dev->gadget_driver && - priv_dev->gadget_driver->resume) { - spin_unlock(&priv_dev->lock); - priv_dev->gadget_driver->resume(&priv_dev->gadget); - spin_lock(&priv_dev->lock); - } - } - - /* reset*/ - if (usb_ists & (USB_ISTS_UWRESI | USB_ISTS_UHRESI | USB_ISTS_U2RESI)) { - if (priv_dev->gadget_driver) { - spin_unlock(&priv_dev->lock); - usb_gadget_udc_reset(&priv_dev->gadget, - priv_dev->gadget_driver); - spin_lock(&priv_dev->lock); - - /*read again to check the actual speed*/ - speed = cdns3_get_speed(priv_dev); - priv_dev->gadget.speed = speed; - cdns3_hw_reset_eps_config(priv_dev); - cdns3_ep0_config(priv_dev); - } - } -} - -/** - * cdns3_device_irq_handler- interrupt handler for device part of controller - * - * @irq: irq number for cdns3 core device - * @data: structure of cdns3 - * - * Returns IRQ_HANDLED or IRQ_NONE - */ -static irqreturn_t cdns3_device_irq_handler(int irq, void *data) -{ - struct cdns3_device *priv_dev; - struct cdns3 *cdns = data; - irqreturn_t ret = IRQ_NONE; - unsigned long flags; - u32 reg; - - priv_dev = cdns->gadget_dev; - spin_lock_irqsave(&priv_dev->lock, flags); - - /* check USB device interrupt */ - reg = readl(&priv_dev->regs->usb_ists); - - if (reg) { - writel(reg, &priv_dev->regs->usb_ists); - cdns3_check_usb_interrupt_proceed(priv_dev, reg); - ret = IRQ_HANDLED; - } - - /* check endpoint interrupt */ - reg = readl(&priv_dev->regs->ep_ists); - - if (reg) { - priv_dev->shadow_ep_en |= reg; - reg = ~reg & readl(&priv_dev->regs->ep_ien); - /* mask deferred interrupt. */ - writel(reg, &priv_dev->regs->ep_ien); - ret = IRQ_WAKE_THREAD; - } - - spin_unlock_irqrestore(&priv_dev->lock, flags); - return ret; -} - -/** - * cdns3_device_thread_irq_handler- interrupt handler for device part - * of controller - * - * @irq: irq number for cdns3 core device - * @data: structure of cdns3 - * - * Returns IRQ_HANDLED or IRQ_NONE - */ -static irqreturn_t cdns3_device_thread_irq_handler(int irq, void *data) -{ - struct cdns3_device *priv_dev; - struct cdns3 *cdns = data; - irqreturn_t ret = IRQ_NONE; - unsigned long flags; - u32 ep_ien; - int bit; - u32 reg; - - priv_dev = cdns->gadget_dev; - spin_lock_irqsave(&priv_dev->lock, flags); - - reg = readl(&priv_dev->regs->ep_ists); - - /* handle default endpoint OUT */ - if (reg & EP_ISTS_EP_OUT0) { - cdns3_check_ep0_interrupt_proceed(priv_dev, USB_DIR_OUT); - ret = IRQ_HANDLED; - } - - /* handle default endpoint IN */ - if (reg & EP_ISTS_EP_IN0) { - cdns3_check_ep0_interrupt_proceed(priv_dev, USB_DIR_IN); - ret = IRQ_HANDLED; - } - - /* check if interrupt from non default endpoint, if no exit */ - reg &= ~(EP_ISTS_EP_OUT0 | EP_ISTS_EP_IN0); - if (!reg) - goto irqend; - - for_each_set_bit(bit, (unsigned long *)®, - sizeof(u32) * BITS_PER_BYTE) { - priv_dev->shadow_ep_en |= BIT(bit); - cdns3_check_ep_interrupt_proceed(priv_dev->eps[bit]); - ret = IRQ_HANDLED; - } - - if (priv_dev->run_garbage_colector) { - struct cdns3_aligned_buf *buf, *tmp; - - list_for_each_entry_safe(buf, tmp, &priv_dev->aligned_buf_list, - list) { - if (!buf->in_use) { - list_del(&buf->list); - - spin_unlock_irqrestore(&priv_dev->lock, flags); - dma_free_coherent(priv_dev->sysdev, buf->size, - buf->buf, - buf->dma); - spin_lock_irqsave(&priv_dev->lock, flags); - - kfree(buf); - } - } - - priv_dev->run_garbage_colector = 0; - } - -irqend: - ep_ien = readl(&priv_dev->regs->ep_ien) | priv_dev->shadow_ep_en; - priv_dev->shadow_ep_en = 0; - /* Unmask all handled EP interrupts */ - writel(ep_ien, &priv_dev->regs->ep_ien); - spin_unlock_irqrestore(&priv_dev->lock, flags); - return ret; -} - -/** - * cdns3_ep_onchip_buffer_reserve - Try to reserve onchip buf for EP - * - * The real reservation will occur during write to EP_CFG register, - * this function is used to check if the 'size' reservation is allowed. - * - * @priv_dev: extended gadget object - * @size: the size (KB) for EP would like to allocate - * @is_in: endpoint direction - * - * Return 0 if the required size can met or negative value on failure - */ -static int cdns3_ep_onchip_buffer_reserve(struct cdns3_device *priv_dev, - int size, int is_in) -{ - int remained; - - /* 2KB are reserved for EP0*/ - remained = priv_dev->onchip_buffers - priv_dev->onchip_used_size - 2; - - if (is_in) { - if (remained < size) - return -EPERM; - - priv_dev->onchip_used_size += size; - } else { - int required; - - /** - * ALL OUT EPs are shared the same chunk onchip memory, so - * driver checks if it already has assigned enough buffers - */ - if (priv_dev->out_mem_is_allocated >= size) - return 0; - - required = size - priv_dev->out_mem_is_allocated; - - if (required > remained) - return -EPERM; - - priv_dev->out_mem_is_allocated += required; - priv_dev->onchip_used_size += required; - } - - return 0; -} - -void cdns3_configure_dmult(struct cdns3_device *priv_dev, - struct cdns3_endpoint *priv_ep) -{ - struct cdns3_usb_regs __iomem *regs = priv_dev->regs; - - /* For dev_ver > DEV_VER_V2 DMULT is configured per endpoint */ - if (priv_dev->dev_ver <= DEV_VER_V2) - writel(USB_CONF_DMULT, ®s->usb_conf); - - if (priv_dev->dev_ver == DEV_VER_V2) - writel(USB_CONF2_EN_TDL_TRB, ®s->usb_conf2); - - if (priv_dev->dev_ver >= DEV_VER_V3 && priv_ep) { - u32 mask; - - if (priv_ep->dir) - mask = BIT(priv_ep->num + 16); - else - mask = BIT(priv_ep->num); - - if (priv_ep->type != USB_ENDPOINT_XFER_ISOC) { - cdns3_set_register_bit(®s->tdl_from_trb, mask); - cdns3_set_register_bit(®s->tdl_beh, mask); - cdns3_set_register_bit(®s->tdl_beh2, mask); - cdns3_set_register_bit(®s->dma_adv_td, mask); - } - - if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir) - cdns3_set_register_bit(®s->tdl_from_trb, mask); - - cdns3_set_register_bit(®s->dtrans, mask); - } -} - -/** - * cdns3_ep_config Configure hardware endpoint - * @priv_ep: extended endpoint object - */ -void cdns3_ep_config(struct cdns3_endpoint *priv_ep) -{ - bool is_iso_ep = (priv_ep->type == USB_ENDPOINT_XFER_ISOC); - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - u32 bEndpointAddress = priv_ep->num | priv_ep->dir; - u32 max_packet_size = 0; - u8 maxburst = 0; - u32 ep_cfg = 0; - u8 buffering; - u8 mult = 0; - int ret; - - buffering = CDNS3_EP_BUF_SIZE - 1; - - cdns3_configure_dmult(priv_dev, priv_ep); - - switch (priv_ep->type) { - case USB_ENDPOINT_XFER_INT: - ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_INT); - - if ((priv_dev->dev_ver == DEV_VER_V2 && !priv_ep->dir) || - priv_dev->dev_ver > DEV_VER_V2) - ep_cfg |= EP_CFG_TDL_CHK; - break; - case USB_ENDPOINT_XFER_BULK: - ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_BULK); - - if ((priv_dev->dev_ver == DEV_VER_V2 && !priv_ep->dir) || - priv_dev->dev_ver > DEV_VER_V2) - ep_cfg |= EP_CFG_TDL_CHK; - break; - default: - ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_ISOC); - mult = CDNS3_EP_ISO_HS_MULT - 1; - buffering = mult + 1; - } - - switch (priv_dev->gadget.speed) { - case USB_SPEED_FULL: - max_packet_size = is_iso_ep ? 1023 : 64; - break; - case USB_SPEED_HIGH: - max_packet_size = is_iso_ep ? 1024 : 512; - break; - case USB_SPEED_SUPER: - /* It's limitation that driver assumes in driver. */ - mult = 0; - max_packet_size = 1024; - if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) { - maxburst = CDNS3_EP_ISO_SS_BURST - 1; - buffering = (mult + 1) * - (maxburst + 1); - - if (priv_ep->interval > 1) - buffering++; - } else { - maxburst = CDNS3_EP_BUF_SIZE - 1; - } - break; - default: - /* all other speed are not supported */ - return; - } - - if (max_packet_size == 1024) - priv_ep->trb_burst_size = 128; - else if (max_packet_size >= 512) - priv_ep->trb_burst_size = 64; - else - priv_ep->trb_burst_size = 16; - - ret = cdns3_ep_onchip_buffer_reserve(priv_dev, buffering + 1, - !!priv_ep->dir); - if (ret) { - dev_err(priv_dev->dev, "onchip mem is full, ep is invalid\n"); - return; - } - - ep_cfg |= EP_CFG_MAXPKTSIZE(max_packet_size) | - EP_CFG_MULT(mult) | - EP_CFG_BUFFERING(buffering) | - EP_CFG_MAXBURST(maxburst); - - cdns3_select_ep(priv_dev, bEndpointAddress); - writel(ep_cfg, &priv_dev->regs->ep_cfg); - - dev_dbg(priv_dev->dev, "Configure %s: with val %08x\n", - priv_ep->name, ep_cfg); -} - -/* Find correct direction for HW endpoint according to description */ -static int cdns3_ep_dir_is_correct(struct usb_endpoint_descriptor *desc, - struct cdns3_endpoint *priv_ep) -{ - return (priv_ep->endpoint.caps.dir_in && usb_endpoint_dir_in(desc)) || - (priv_ep->endpoint.caps.dir_out && usb_endpoint_dir_out(desc)); -} - -static struct -cdns3_endpoint *cdns3_find_available_ep(struct cdns3_device *priv_dev, - struct usb_endpoint_descriptor *desc) -{ - struct usb_ep *ep; - struct cdns3_endpoint *priv_ep; - - list_for_each_entry(ep, &priv_dev->gadget.ep_list, ep_list) { - unsigned long num; - int ret; - /* ep name pattern likes epXin or epXout */ - char c[2] = {ep->name[2], '\0'}; - - ret = kstrtoul(c, 10, &num); - if (ret) - return ERR_PTR(ret); - - priv_ep = ep_to_cdns3_ep(ep); - if (cdns3_ep_dir_is_correct(desc, priv_ep)) { - if (!(priv_ep->flags & EP_CLAIMED)) { - priv_ep->num = num; - return priv_ep; - } - } - } - - return ERR_PTR(-ENOENT); -} - -/* - * Cadence IP has one limitation that all endpoints must be configured - * (Type & MaxPacketSize) before setting configuration through hardware - * register, it means we can't change endpoints configuration after - * set_configuration. - * - * This function set EP_CLAIMED flag which is added when the gadget driver - * uses usb_ep_autoconfig to configure specific endpoint; - * When the udc driver receives set_configurion request, - * it goes through all claimed endpoints, and configure all endpoints - * accordingly. - * - * At usb_ep_ops.enable/disable, we only enable and disable endpoint through - * ep_cfg register which can be changed after set_configuration, and do - * some software operation accordingly. - */ -static struct -usb_ep *cdns3_gadget_match_ep(struct usb_gadget *gadget, - struct usb_endpoint_descriptor *desc, - struct usb_ss_ep_comp_descriptor *comp_desc) -{ - struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); - struct cdns3_endpoint *priv_ep; - unsigned long flags; - - priv_ep = cdns3_find_available_ep(priv_dev, desc); - if (IS_ERR(priv_ep)) { - dev_err(priv_dev->dev, "no available ep\n"); - return NULL; - } - - dev_dbg(priv_dev->dev, "match endpoint: %s\n", priv_ep->name); - - spin_lock_irqsave(&priv_dev->lock, flags); - priv_ep->endpoint.desc = desc; - priv_ep->dir = usb_endpoint_dir_in(desc) ? USB_DIR_IN : USB_DIR_OUT; - priv_ep->type = usb_endpoint_type(desc); - priv_ep->flags |= EP_CLAIMED; - priv_ep->interval = desc->bInterval ? BIT(desc->bInterval - 1) : 0; - - spin_unlock_irqrestore(&priv_dev->lock, flags); - return &priv_ep->endpoint; -} - -/** - * cdns3_gadget_ep_alloc_request Allocates request - * @ep: endpoint object associated with request - * @gfp_flags: gfp flags - * - * Returns allocated request address, NULL on allocation error - */ -struct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep, - gfp_t gfp_flags) -{ - struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); - struct cdns3_request *priv_req; - - priv_req = kzalloc(sizeof(*priv_req), gfp_flags); - if (!priv_req) - return NULL; - - priv_req->priv_ep = priv_ep; - - trace_cdns3_alloc_request(priv_req); - return &priv_req->request; -} - -/** - * cdns3_gadget_ep_free_request Free memory occupied by request - * @ep: endpoint object associated with request - * @request: request to free memory - */ -void cdns3_gadget_ep_free_request(struct usb_ep *ep, - struct usb_request *request) -{ - struct cdns3_request *priv_req = to_cdns3_request(request); - - if (priv_req->aligned_buf) - priv_req->aligned_buf->in_use = 0; - - trace_cdns3_free_request(priv_req); - kfree(priv_req); -} - -/** - * cdns3_gadget_ep_enable Enable endpoint - * @ep: endpoint object - * @desc: endpoint descriptor - * - * Returns 0 on success, error code elsewhere - */ -static int cdns3_gadget_ep_enable(struct usb_ep *ep, - const struct usb_endpoint_descriptor *desc) -{ - struct cdns3_endpoint *priv_ep; - struct cdns3_device *priv_dev; - u32 reg = EP_STS_EN_TRBERREN; - u32 bEndpointAddress; - unsigned long flags; - int enable = 1; - int ret; - - priv_ep = ep_to_cdns3_ep(ep); - priv_dev = priv_ep->cdns3_dev; - - if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { - dev_dbg(priv_dev->dev, "usbss: invalid parameters\n"); - return -EINVAL; - } - - if (!desc->wMaxPacketSize) { - dev_err(priv_dev->dev, "usbss: missing wMaxPacketSize\n"); - return -EINVAL; - } - - if (dev_WARN_ONCE(priv_dev->dev, priv_ep->flags & EP_ENABLED, - "%s is already enabled\n", priv_ep->name)) - return 0; - - spin_lock_irqsave(&priv_dev->lock, flags); - - priv_ep->endpoint.desc = desc; - priv_ep->type = usb_endpoint_type(desc); - priv_ep->interval = desc->bInterval ? BIT(desc->bInterval - 1) : 0; - - if (priv_ep->interval > ISO_MAX_INTERVAL && - priv_ep->type == USB_ENDPOINT_XFER_ISOC) { - dev_err(priv_dev->dev, "Driver is limited to %d period\n", - ISO_MAX_INTERVAL); - - ret = -EINVAL; - goto exit; - } - - ret = cdns3_allocate_trb_pool(priv_ep); - - if (ret) - goto exit; - - bEndpointAddress = priv_ep->num | priv_ep->dir; - cdns3_select_ep(priv_dev, bEndpointAddress); - - trace_cdns3_gadget_ep_enable(priv_ep); - - writel(EP_CMD_EPRST, &priv_dev->regs->ep_cmd); - - ret = cdns3_handshake(&priv_dev->regs->ep_cmd, - EP_CMD_CSTALL | EP_CMD_EPRST, 0, 1000); - - if (unlikely(ret)) { - cdns3_free_trb_pool(priv_ep); - ret = -EINVAL; - goto exit; - } - - /* enable interrupt for selected endpoint */ - cdns3_set_register_bit(&priv_dev->regs->ep_ien, - BIT(cdns3_ep_addr_to_index(bEndpointAddress))); - - writel(reg, &priv_dev->regs->ep_sts_en); - - /* - * For some versions of controller at some point during ISO OUT traffic - * DMA reads Transfer Ring for the EP which has never got doorbell. - * This issue was detected only on simulation, but to avoid this issue - * driver add protection against it. To fix it driver enable ISO OUT - * endpoint before setting DRBL. This special treatment of ISO OUT - * endpoints are recommended by controller specification. - */ - if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir) - enable = 0; - - if (enable) - cdns3_set_register_bit(&priv_dev->regs->ep_cfg, EP_CFG_ENABLE); - - ep->desc = desc; - priv_ep->flags &= ~(EP_PENDING_REQUEST | EP_STALL | - EP_QUIRK_ISO_OUT_EN); - priv_ep->flags |= EP_ENABLED | EP_UPDATE_EP_TRBADDR; - priv_ep->wa1_set = 0; - priv_ep->enqueue = 0; - priv_ep->dequeue = 0; - reg = readl(&priv_dev->regs->ep_sts); - priv_ep->pcs = !!EP_STS_CCS(reg); - priv_ep->ccs = !!EP_STS_CCS(reg); - /* one TRB is reserved for link TRB used in DMULT mode*/ - priv_ep->free_trbs = priv_ep->num_trbs - 1; -exit: - spin_unlock_irqrestore(&priv_dev->lock, flags); - - return ret; -} - -/** - * cdns3_gadget_ep_disable Disable endpoint - * @ep: endpoint object - * - * Returns 0 on success, error code elsewhere - */ -static int cdns3_gadget_ep_disable(struct usb_ep *ep) -{ - struct cdns3_endpoint *priv_ep; - struct cdns3_device *priv_dev; - struct usb_request *request; - unsigned long flags; - int ret = 0; - u32 ep_cfg; - - if (!ep) { - pr_err("usbss: invalid parameters\n"); - return -EINVAL; - } - - priv_ep = ep_to_cdns3_ep(ep); - priv_dev = priv_ep->cdns3_dev; - - if (dev_WARN_ONCE(priv_dev->dev, !(priv_ep->flags & EP_ENABLED), - "%s is already disabled\n", priv_ep->name)) - return 0; - - spin_lock_irqsave(&priv_dev->lock, flags); - - trace_cdns3_gadget_ep_disable(priv_ep); - - cdns3_select_ep(priv_dev, ep->desc->bEndpointAddress); - - ep_cfg = readl(&priv_dev->regs->ep_cfg); - ep_cfg &= ~EP_CFG_ENABLE; - writel(ep_cfg, &priv_dev->regs->ep_cfg); - - /** - * Driver needs some time before resetting endpoint. - * It need waits for clearing DBUSY bit or for timeout expired. - * 10us is enough time for controller to stop transfer. - */ - cdns3_handshake(&priv_dev->regs->ep_sts, - EP_STS_DBUSY, 0, 10); - - writel(EP_CMD_EPRST, &priv_dev->regs->ep_cmd); - - ret = cdns3_handshake(&priv_dev->regs->ep_cmd, - EP_CMD_CSTALL | EP_CMD_EPRST, 0, 1000); - - if (unlikely(ret)) - dev_err(priv_dev->dev, "Timeout: %s resetting failed.\n", - priv_ep->name); - - while (!list_empty(&priv_ep->pending_req_list)) { - request = cdns3_next_request(&priv_ep->pending_req_list); - - cdns3_gadget_giveback(priv_ep, to_cdns3_request(request), - -ESHUTDOWN); - } - - while (!list_empty(&priv_ep->deferred_req_list)) { - request = cdns3_next_request(&priv_ep->deferred_req_list); - - cdns3_gadget_giveback(priv_ep, to_cdns3_request(request), - -ESHUTDOWN); - } - - ep->desc = NULL; - priv_ep->flags &= ~EP_ENABLED; - - spin_unlock_irqrestore(&priv_dev->lock, flags); - - return ret; -} - -/** - * cdns3_gadget_ep_queue Transfer data on endpoint - * @ep: endpoint object - * @request: request object - * @gfp_flags: gfp flags - * - * Returns 0 on success, error code elsewhere - */ -static int __cdns3_gadget_ep_queue(struct usb_ep *ep, - struct usb_request *request, - gfp_t gfp_flags) -{ - struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - struct cdns3_request *priv_req; - int ret = 0; - - request->actual = 0; - request->status = -EINPROGRESS; - priv_req = to_cdns3_request(request); - trace_cdns3_ep_queue(priv_req); - - ret = cdns3_prepare_aligned_request_buf(priv_req); - if (ret < 0) - return ret; - - ret = usb_gadget_map_request_by_dev(priv_dev->sysdev, request, - usb_endpoint_dir_in(ep->desc)); - if (ret) - return ret; - - list_add_tail(&request->list, &priv_ep->deferred_req_list); - - /* - * If hardware endpoint configuration has not been set yet then - * just queue request in deferred list. Transfer will be started in - * cdns3_set_hw_configuration. - */ - if (priv_dev->hw_configured_flag) - cdns3_start_all_request(priv_dev, priv_ep); - - return 0; -} - -static int cdns3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, - gfp_t gfp_flags) -{ - struct usb_request *zlp_request; - struct cdns3_endpoint *priv_ep; - struct cdns3_device *priv_dev; - unsigned long flags; - int ret; - - if (!request || !ep) - return -EINVAL; - - priv_ep = ep_to_cdns3_ep(ep); - priv_dev = priv_ep->cdns3_dev; - - spin_lock_irqsave(&priv_dev->lock, flags); - - ret = __cdns3_gadget_ep_queue(ep, request, gfp_flags); - - if (ret == 0 && request->zero && request->length && - (request->length % ep->maxpacket == 0)) { - struct cdns3_request *priv_req; - - zlp_request = cdns3_gadget_ep_alloc_request(ep, GFP_ATOMIC); - zlp_request->buf = priv_dev->zlp_buf; - zlp_request->length = 0; - - priv_req = to_cdns3_request(zlp_request); - priv_req->flags |= REQUEST_ZLP; - - dev_dbg(priv_dev->dev, "Queuing ZLP for endpoint: %s\n", - priv_ep->name); - ret = __cdns3_gadget_ep_queue(ep, zlp_request, gfp_flags); - } - - spin_unlock_irqrestore(&priv_dev->lock, flags); - return ret; -} - -/** - * cdns3_gadget_ep_dequeue Remove request from transfer queue - * @ep: endpoint object associated with request - * @request: request object - * - * Returns 0 on success, error code elsewhere - */ -int cdns3_gadget_ep_dequeue(struct usb_ep *ep, - struct usb_request *request) -{ - struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - struct usb_request *req, *req_temp; - struct cdns3_request *priv_req; - struct cdns3_trb *link_trb; - unsigned long flags; - int ret = 0; - - if (!ep || !request || !ep->desc) - return -EINVAL; - - spin_lock_irqsave(&priv_dev->lock, flags); - - priv_req = to_cdns3_request(request); - - trace_cdns3_ep_dequeue(priv_req); - - cdns3_select_ep(priv_dev, ep->desc->bEndpointAddress); - - list_for_each_entry_safe(req, req_temp, &priv_ep->pending_req_list, - list) { - if (request == req) - goto found; - } - - list_for_each_entry_safe(req, req_temp, &priv_ep->deferred_req_list, - list) { - if (request == req) - goto found; - } - - goto not_found; - -found: - - if (priv_ep->wa1_trb == priv_req->trb) - cdns3_wa1_restore_cycle_bit(priv_ep); - - link_trb = priv_req->trb; - cdns3_move_deq_to_next_trb(priv_req); - cdns3_gadget_giveback(priv_ep, priv_req, -ECONNRESET); - - /* Update ring */ - request = cdns3_next_request(&priv_ep->deferred_req_list); - if (request) { - priv_req = to_cdns3_request(request); - - link_trb->buffer = TRB_BUFFER(priv_ep->trb_pool_dma + - (priv_req->start_trb * TRB_SIZE)); - link_trb->control = (link_trb->control & TRB_CYCLE) | - TRB_TYPE(TRB_LINK) | TRB_CHAIN | TRB_TOGGLE; - } else { - priv_ep->flags |= EP_UPDATE_EP_TRBADDR; - } - -not_found: - spin_unlock_irqrestore(&priv_dev->lock, flags); - return ret; -} - -/** - * cdns3_gadget_ep_set_halt Sets/clears stall on selected endpoint - * @ep: endpoint object to set/clear stall on - * @value: 1 for set stall, 0 for clear stall - * - * Returns 0 on success, error code elsewhere - */ -int cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value) -{ - struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); - struct cdns3_device *priv_dev = priv_ep->cdns3_dev; - unsigned long flags; - int ret = 0; - - if (!(priv_ep->flags & EP_ENABLED)) - return -EPERM; - - spin_lock_irqsave(&priv_dev->lock, flags); - - cdns3_select_ep(priv_dev, ep->desc->bEndpointAddress); - if (value) { - cdns3_ep_stall_flush(priv_ep); - } else { - priv_ep->flags &= ~EP_WEDGE; - - cdns3_dbg(priv_ep->cdns3_dev, "Clear stalled endpoint %s\n", - priv_ep->name); - - writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd); - - /* wait for EPRST cleared */ - ret = cdns3_handshake(&priv_dev->regs->ep_cmd, - EP_CMD_EPRST, 0, 100); - if (unlikely(ret)) { - dev_err(priv_dev->dev, - "Clearing halt condition failed for %s\n", - priv_ep->name); - goto finish; - - } else { - priv_ep->flags &= ~EP_STALL; - } - } - - priv_ep->flags &= ~EP_PENDING_REQUEST; -finish: - spin_unlock_irqrestore(&priv_dev->lock, flags); - - return ret; -} - -extern const struct usb_ep_ops cdns3_gadget_ep0_ops; - -static const struct usb_ep_ops cdns3_gadget_ep_ops = { - .enable = cdns3_gadget_ep_enable, - .disable = cdns3_gadget_ep_disable, - .alloc_request = cdns3_gadget_ep_alloc_request, - .free_request = cdns3_gadget_ep_free_request, - .queue = cdns3_gadget_ep_queue, - .dequeue = cdns3_gadget_ep_dequeue, - .set_halt = cdns3_gadget_ep_set_halt, - .set_wedge = cdns3_gadget_ep_set_wedge, -}; - -/** - * cdns3_gadget_get_frame Returns number of actual ITP frame - * @gadget: gadget object - * - * Returns number of actual ITP frame - */ -static int cdns3_gadget_get_frame(struct usb_gadget *gadget) -{ - struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); - - return readl(&priv_dev->regs->usb_itpn); -} - -int __cdns3_gadget_wakeup(struct cdns3_device *priv_dev) -{ - enum usb_device_speed speed; - - speed = cdns3_get_speed(priv_dev); - - if (speed >= USB_SPEED_SUPER) - return 0; - - /* Start driving resume signaling to indicate remote wakeup. */ - writel(USB_CONF_LGO_L0, &priv_dev->regs->usb_conf); - - return 0; -} - -static int cdns3_gadget_wakeup(struct usb_gadget *gadget) -{ - struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); - unsigned long flags; - int ret = 0; - - spin_lock_irqsave(&priv_dev->lock, flags); - ret = __cdns3_gadget_wakeup(priv_dev); - spin_unlock_irqrestore(&priv_dev->lock, flags); - return ret; -} - -static int cdns3_gadget_set_selfpowered(struct usb_gadget *gadget, - int is_selfpowered) -{ - struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); - unsigned long flags; - - spin_lock_irqsave(&priv_dev->lock, flags); - priv_dev->is_selfpowered = !!is_selfpowered; - spin_unlock_irqrestore(&priv_dev->lock, flags); - return 0; -} - -static int cdns3_gadget_pullup(struct usb_gadget *gadget, int is_on) -{ - struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); - - if (is_on) - writel(USB_CONF_DEVEN, &priv_dev->regs->usb_conf); - else - writel(USB_CONF_DEVDS, &priv_dev->regs->usb_conf); - - return 0; -} - -static void cdns3_gadget_config(struct cdns3_device *priv_dev) -{ - struct cdns3_usb_regs __iomem *regs = priv_dev->regs; - u32 reg; - - cdns3_ep0_config(priv_dev); - - /* enable interrupts for endpoint 0 (in and out) */ - writel(EP_IEN_EP_OUT0 | EP_IEN_EP_IN0, ®s->ep_ien); - - /* - *Driver need modify LFPS minimal U1 Exit time for 0x00024505 revision - * of controller - */ - if (priv_dev->dev_ver == DEV_VER_TI_V1) { - reg = readl(®s->dbg_link1); - - reg &= ~DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_MASK; - reg |= DBG_LINK1_LFPS_MIN_GEN_U1_EXIT(0x55) | - DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_SET; - writel(reg, ®s->dbg_link1); - } - - /* - * By default some platforms has set protected access to memory. - * This cause problem with cache, so driver restore non-secure - * access to memory. - */ - reg = readl(®s->dma_axi_ctrl); - reg = DMA_AXI_CTRL_MARPROT(DMA_AXI_CTRL_NON_SECURE) | - DMA_AXI_CTRL_MAWPROT(DMA_AXI_CTRL_NON_SECURE); - writel(reg, ®s->dma_axi_ctrl); - - /* enable generic interrupt*/ - writel(USB_IEN_INIT, ®s->usb_ien); - writel(USB_CONF_CLK2OFFDS | USB_CONF_L1DS, ®s->usb_conf); - - cdns3_configure_dmult(priv_dev, NULL); - - cdns3_gadget_pullup(&priv_dev->gadget, 1); -} - -/** - * cdns3_gadget_udc_start Gadget start - * @gadget: gadget object - * @driver: driver which operates on this gadget - * - * Returns 0 on success, error code elsewhere - */ -static int cdns3_gadget_udc_start(struct usb_gadget *gadget, - struct usb_gadget_driver *driver) -{ - struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); - unsigned long flags; - - spin_lock_irqsave(&priv_dev->lock, flags); - priv_dev->gadget_driver = driver; - cdns3_gadget_config(priv_dev); - spin_unlock_irqrestore(&priv_dev->lock, flags); - return 0; -} - -/** - * cdns3_gadget_udc_stop Stops gadget - * @gadget: gadget object - * - * Returns 0 - */ -static int cdns3_gadget_udc_stop(struct usb_gadget *gadget) -{ - struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); - struct cdns3_endpoint *priv_ep; - u32 bEndpointAddress; - struct usb_ep *ep; - int ret = 0; - - priv_dev->gadget_driver = NULL; - - priv_dev->onchip_used_size = 0; - priv_dev->out_mem_is_allocated = 0; - priv_dev->gadget.speed = USB_SPEED_UNKNOWN; - - list_for_each_entry(ep, &priv_dev->gadget.ep_list, ep_list) { - priv_ep = ep_to_cdns3_ep(ep); - bEndpointAddress = priv_ep->num | priv_ep->dir; - cdns3_select_ep(priv_dev, bEndpointAddress); - writel(EP_CMD_EPRST, &priv_dev->regs->ep_cmd); - ret = cdns3_handshake(&priv_dev->regs->ep_cmd, - EP_CMD_EPRST, 0, 100); - cdns3_free_trb_pool(priv_ep); - } - - /* disable interrupt for device */ - writel(0, &priv_dev->regs->usb_ien); - writel(USB_CONF_DEVDS, &priv_dev->regs->usb_conf); - - return ret; -} - -static const struct usb_gadget_ops cdns3_gadget_ops = { - .get_frame = cdns3_gadget_get_frame, - .wakeup = cdns3_gadget_wakeup, - .set_selfpowered = cdns3_gadget_set_selfpowered, - .pullup = cdns3_gadget_pullup, - .udc_start = cdns3_gadget_udc_start, - .udc_stop = cdns3_gadget_udc_stop, - .match_ep = cdns3_gadget_match_ep, -}; - -static void cdns3_free_all_eps(struct cdns3_device *priv_dev) -{ - int i; - - /*ep0 OUT point to ep0 IN*/ - priv_dev->eps[16] = NULL; - - cdns3_free_trb_pool(priv_dev->eps[0]); - - for (i = 0; i < CDNS3_ENDPOINTS_MAX_COUNT; i++) - if (priv_dev->eps[i]) - devm_kfree(priv_dev->dev, priv_dev->eps[i]); -} - -/** - * cdns3_init_eps Initializes software endpoints of gadget - * @cdns3: extended gadget object - * - * Returns 0 on success, error code elsewhere - */ -static int cdns3_init_eps(struct cdns3_device *priv_dev) -{ - u32 ep_enabled_reg, iso_ep_reg; - struct cdns3_endpoint *priv_ep; - int ep_dir, ep_number; - u32 ep_mask; - int ret = 0; - int i; - - /* Read it from USB_CAP3 to USB_CAP5 */ - ep_enabled_reg = readl(&priv_dev->regs->usb_cap3); - iso_ep_reg = readl(&priv_dev->regs->usb_cap4); - - dev_dbg(priv_dev->dev, "Initializing non-zero endpoints\n"); - - for (i = 0; i < CDNS3_ENDPOINTS_MAX_COUNT; i++) { - ep_dir = i >> 4; /* i div 16 */ - ep_number = i & 0xF; /* i % 16 */ - ep_mask = BIT(i); - - if (!(ep_enabled_reg & ep_mask)) - continue; - - if (ep_dir && !ep_number) { - priv_dev->eps[i] = priv_dev->eps[0]; - continue; - } - - priv_ep = devm_kzalloc(priv_dev->dev, sizeof(*priv_ep), - GFP_KERNEL); - if (!priv_ep) { - ret = -ENOMEM; - goto err; - } - - /* set parent of endpoint object */ - priv_ep->cdns3_dev = priv_dev; - priv_dev->eps[i] = priv_ep; - priv_ep->num = ep_number; - priv_ep->dir = ep_dir ? USB_DIR_IN : USB_DIR_OUT; - - if (!ep_number) { - ret = cdns3_init_ep0(priv_dev, priv_ep); - if (ret) { - dev_err(priv_dev->dev, "Failed to init ep0\n"); - goto err; - } - } else { - snprintf(priv_ep->name, sizeof(priv_ep->name), "ep%d%s", - ep_number, !!ep_dir ? "in" : "out"); - priv_ep->endpoint.name = priv_ep->name; - - usb_ep_set_maxpacket_limit(&priv_ep->endpoint, - CDNS3_EP_MAX_PACKET_LIMIT); - priv_ep->endpoint.max_streams = CDNS3_EP_MAX_STREAMS; - priv_ep->endpoint.ops = &cdns3_gadget_ep_ops; - if (ep_dir) - priv_ep->endpoint.caps.dir_in = 1; - else - priv_ep->endpoint.caps.dir_out = 1; - - if (iso_ep_reg & ep_mask) - priv_ep->endpoint.caps.type_iso = 1; - - priv_ep->endpoint.caps.type_bulk = 1; - priv_ep->endpoint.caps.type_int = 1; - - list_add_tail(&priv_ep->endpoint.ep_list, - &priv_dev->gadget.ep_list); - } - - priv_ep->flags = 0; - - dev_info(priv_dev->dev, "Initialized %s support: %s %s\n", - priv_ep->name, - priv_ep->endpoint.caps.type_bulk ? "BULK, INT" : "", - priv_ep->endpoint.caps.type_iso ? "ISO" : ""); - - INIT_LIST_HEAD(&priv_ep->pending_req_list); - INIT_LIST_HEAD(&priv_ep->deferred_req_list); - } - - return 0; -err: - cdns3_free_all_eps(priv_dev); - return -ENOMEM; -} - -void cdns3_gadget_exit(struct cdns3 *cdns) -{ - struct cdns3_device *priv_dev; - - priv_dev = cdns->gadget_dev; - - devm_free_irq(cdns->dev, cdns->dev_irq, cdns); - - pm_runtime_mark_last_busy(cdns->dev); - pm_runtime_put_autosuspend(cdns->dev); - - usb_del_gadget_udc(&priv_dev->gadget); - - cdns3_free_all_eps(priv_dev); - - while (!list_empty(&priv_dev->aligned_buf_list)) { - struct cdns3_aligned_buf *buf; - - buf = cdns3_next_align_buf(&priv_dev->aligned_buf_list); - dma_free_coherent(priv_dev->sysdev, buf->size, - buf->buf, - buf->dma); - - list_del(&buf->list); - kfree(buf); - } - - dma_free_coherent(priv_dev->sysdev, 8, priv_dev->setup_buf, - priv_dev->setup_dma); - - kfree(priv_dev->zlp_buf); - kfree(priv_dev); - cdns->gadget_dev = NULL; - cdns3_drd_switch_gadget(cdns, 0); -} - -static int cdns3_gadget_start(struct cdns3 *cdns) -{ - struct cdns3_device *priv_dev; - u32 max_speed; - int ret; - - priv_dev = kzalloc(sizeof(*priv_dev), GFP_KERNEL); - if (!priv_dev) - return -ENOMEM; - - cdns->gadget_dev = priv_dev; - priv_dev->sysdev = cdns->dev; - priv_dev->dev = cdns->dev; - priv_dev->regs = cdns->dev_regs; - - device_property_read_u16(priv_dev->dev, "cdns,on-chip-buff-size", - &priv_dev->onchip_buffers); - - if (priv_dev->onchip_buffers <= 0) { - u32 reg = readl(&priv_dev->regs->usb_cap2); - - priv_dev->onchip_buffers = USB_CAP2_ACTUAL_MEM_SIZE(reg); - } - - if (!priv_dev->onchip_buffers) - priv_dev->onchip_buffers = 256; - - max_speed = usb_get_maximum_speed(cdns->dev); - - /* Check the maximum_speed parameter */ - switch (max_speed) { - case USB_SPEED_FULL: - case USB_SPEED_HIGH: - case USB_SPEED_SUPER: - break; - default: - dev_err(cdns->dev, "invalid maximum_speed parameter %d\n", - max_speed); - /* fall through */ - case USB_SPEED_UNKNOWN: - /* default to superspeed */ - max_speed = USB_SPEED_SUPER; - break; - } - - /* fill gadget fields */ - priv_dev->gadget.max_speed = max_speed; - priv_dev->gadget.speed = USB_SPEED_UNKNOWN; - priv_dev->gadget.ops = &cdns3_gadget_ops; - priv_dev->gadget.name = "usb-ss-gadget"; - priv_dev->gadget.sg_supported = 1; - - spin_lock_init(&priv_dev->lock); - INIT_WORK(&priv_dev->pending_status_wq, - cdns3_pending_setup_status_handler); - - /* initialize endpoint container */ - INIT_LIST_HEAD(&priv_dev->gadget.ep_list); - INIT_LIST_HEAD(&priv_dev->aligned_buf_list); - - ret = cdns3_init_eps(priv_dev); - if (ret) { - dev_err(priv_dev->dev, "Failed to create endpoints\n"); - goto err1; - } - - /* allocate memory for setup packet buffer */ - priv_dev->setup_buf = dma_alloc_coherent(priv_dev->sysdev, 8, - &priv_dev->setup_dma, GFP_DMA); - if (!priv_dev->setup_buf) { - ret = -ENOMEM; - goto err2; - } - - priv_dev->dev_ver = readl(&priv_dev->regs->usb_cap6); - - dev_dbg(priv_dev->dev, "Device Controller version: %08x\n", - readl(&priv_dev->regs->usb_cap6)); - dev_dbg(priv_dev->dev, "USB Capabilities:: %08x\n", - readl(&priv_dev->regs->usb_cap1)); - dev_dbg(priv_dev->dev, "On-Chip memory cnfiguration: %08x\n", - readl(&priv_dev->regs->usb_cap2)); - - priv_dev->dev_ver = GET_DEV_BASE_VERSION(priv_dev->dev_ver); - - priv_dev->zlp_buf = kzalloc(CDNS3_EP_ZLP_BUF_SIZE, GFP_KERNEL); - if (!priv_dev->zlp_buf) { - ret = -ENOMEM; - goto err3; - } - - /* add USB gadget device */ - ret = usb_add_gadget_udc(priv_dev->dev, &priv_dev->gadget); - if (ret < 0) { - dev_err(priv_dev->dev, - "Failed to register USB device controller\n"); - goto err4; - } - - return 0; -err4: - kfree(priv_dev->zlp_buf); -err3: - dma_free_coherent(priv_dev->sysdev, 8, priv_dev->setup_buf, - priv_dev->setup_dma); -err2: - cdns3_free_all_eps(priv_dev); -err1: - cdns->gadget_dev = NULL; - return ret; -} - -static int __cdns3_gadget_init(struct cdns3 *cdns) -{ - struct cdns3_device *priv_dev; - int ret = 0; - - cdns3_drd_switch_gadget(cdns, 1); - pm_runtime_get_sync(cdns->dev); - - ret = cdns3_gadget_start(cdns); - if (ret) - return ret; - - priv_dev = cdns->gadget_dev; - ret = devm_request_threaded_irq(cdns->dev, cdns->dev_irq, - cdns3_device_irq_handler, - cdns3_device_thread_irq_handler, - IRQF_SHARED, dev_name(cdns->dev), cdns); - - if (ret) - goto err0; - - return 0; -err0: - cdns3_gadget_exit(cdns); - return ret; -} - -static int cdns3_gadget_suspend(struct cdns3 *cdns, bool do_wakeup) -{ - cdns3_gadget_exit(cdns); - return 0; -} - -static int cdns3_gadget_resume(struct cdns3 *cdns, bool hibernated) -{ - return cdns3_gadget_start(cdns); -} - -/** - * cdns3_gadget_init - initialize device structure - * - * cdns: cdns3 instance - * - * This function initializes the gadget. - */ -int cdns3_gadget_init(struct cdns3 *cdns) -{ - struct cdns3_role_driver *rdrv; - - rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); - if (!rdrv) - return -ENOMEM; - - rdrv->start = __cdns3_gadget_init; - rdrv->stop = cdns3_gadget_exit; - rdrv->suspend = cdns3_gadget_suspend; - rdrv->resume = cdns3_gadget_resume; - rdrv->state = CDNS3_ROLE_STATE_INACTIVE; - rdrv->name = "gadget"; - cdns->roles[CDNS3_ROLE_GADGET] = rdrv; - - return 0; -} diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h deleted file mode 100644 index 64cead1aee32..000000000000 --- a/drivers/usb/cdns3/gadget.h +++ /dev/null @@ -1,1321 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * USBSS device controller driver header file - * - * Copyright (C) 2018-2019 Cadence. - * Copyright (C) 2017-2018 NXP - * - * Author: Pawel Laszczak - * Pawel Jez - * Peter Chen - */ -#ifndef __LINUX_CDNS3_GADGET -#define __LINUX_CDNS3_GADGET -#include - -/* - * USBSS-DEV register interface. - * This corresponds to the USBSS Device Controller Interface - */ - -/** - * struct cdns3_usb_regs - device controller registers. - * @usb_conf: Global Configuration Register. - * @usb_sts: Global Status Register. - * @usb_cmd: Global Command Register. - * @usb_itpn: ITP/SOF number Register. - * @usb_lpm: Global Command Register. - * @usb_ien: USB Interrupt Enable Register. - * @usb_ists: USB Interrupt Status Register. - * @ep_sel: Endpoint Select Register. - * @ep_traddr: Endpoint Transfer Ring Address Register. - * @ep_cfg: Endpoint Configuration Register. - * @ep_cmd: Endpoint Command Register. - * @ep_sts: Endpoint Status Register. - * @ep_sts_sid: Endpoint Status Register. - * @ep_sts_en: Endpoint Status Register Enable. - * @drbl: Doorbell Register. - * @ep_ien: EP Interrupt Enable Register. - * @ep_ists: EP Interrupt Status Register. - * @usb_pwr: Global Power Configuration Register. - * @usb_conf2: Global Configuration Register 2. - * @usb_cap1: Capability Register 1. - * @usb_cap2: Capability Register 2. - * @usb_cap3: Capability Register 3. - * @usb_cap4: Capability Register 4. - * @usb_cap5: Capability Register 5. - * @usb_cap6: Capability Register 6. - * @usb_cpkt1: Custom Packet Register 1. - * @usb_cpkt2: Custom Packet Register 2. - * @usb_cpkt3: Custom Packet Register 3. - * @ep_dma_ext_addr: Upper address for DMA operations Register. - * @buf_addr: Address for On-chip Buffer operations Register. - * @buf_data: Data for On-chip Buffer operations Register. - * @buf_ctrl: On-chip Buffer Access Control Registe. - * @dtrans: DMA Transfer Mode Register. - * @tdl_from_trb: Source of TD Configuration Register. - * @tdl_beh: TDL Behavior Configuration Register. - * @ep_tdl: Endpoint TDL Register. - * @tdl_beh2: TDL Behavior 2 Configuration Register. - * @dma_adv_td: DMA Advance TD Configuration Register. - * @reserved1: Reserved. - * @cfg_regs: Configuration registers. - * @reserved2: Reserved. - * @dma_axi_ctrl: AXI Control register. - * @dma_axi_id: AXI ID register. - * @dma_axi_cap: AXI Capability register. - * @dma_axi_ctrl0: AXI Control 0 register. - * @dma_axi_ctrl1: AXI Control 1 register. - */ -struct cdns3_usb_regs { - __le32 usb_conf; - __le32 usb_sts; - __le32 usb_cmd; - __le32 usb_itpn; - __le32 usb_lpm; - __le32 usb_ien; - __le32 usb_ists; - __le32 ep_sel; - __le32 ep_traddr; - __le32 ep_cfg; - __le32 ep_cmd; - __le32 ep_sts; - __le32 ep_sts_sid; - __le32 ep_sts_en; - __le32 drbl; - __le32 ep_ien; - __le32 ep_ists; - __le32 usb_pwr; - __le32 usb_conf2; - __le32 usb_cap1; - __le32 usb_cap2; - __le32 usb_cap3; - __le32 usb_cap4; - __le32 usb_cap5; - __le32 usb_cap6; - __le32 usb_cpkt1; - __le32 usb_cpkt2; - __le32 usb_cpkt3; - __le32 ep_dma_ext_addr; - __le32 buf_addr; - __le32 buf_data; - __le32 buf_ctrl; - __le32 dtrans; - __le32 tdl_from_trb; - __le32 tdl_beh; - __le32 ep_tdl; - __le32 tdl_beh2; - __le32 dma_adv_td; - __le32 reserved1[26]; - __le32 cfg_reg1; - __le32 dbg_link1; - __le32 dbg_link2; - __le32 cfg_regs[74]; - __le32 reserved2[34]; - __le32 dma_axi_ctrl; - __le32 dma_axi_id; - __le32 dma_axi_cap; - __le32 dma_axi_ctrl0; - __le32 dma_axi_ctrl1; -}; - -/* USB_CONF - bitmasks */ -/* Reset USB device configuration. */ -#define USB_CONF_CFGRST BIT(0) -/* Set Configuration. */ -#define USB_CONF_CFGSET BIT(1) -/* Disconnect USB device in SuperSpeed. */ -#define USB_CONF_USB3DIS BIT(3) -/* Disconnect USB device in HS/FS */ -#define USB_CONF_USB2DIS BIT(4) -/* Little Endian access - default */ -#define USB_CONF_LENDIAN BIT(5) -/* - * Big Endian access. Driver assume that byte order for - * SFRs access always is as Little Endian so this bit - * is not used. - */ -#define USB_CONF_BENDIAN BIT(6) -/* Device software reset. */ -#define USB_CONF_SWRST BIT(7) -/* Singular DMA transfer mode. Only for VER < DEV_VER_V3*/ -#define USB_CONF_DSING BIT(8) -/* Multiple DMA transfers mode. Only for VER < DEV_VER_V3 */ -#define USB_CONF_DMULT BIT(9) -/* DMA clock turn-off enable. */ -#define USB_CONF_DMAOFFEN BIT(10) -/* DMA clock turn-off disable. */ -#define USB_CONF_DMAOFFDS BIT(11) -/* Clear Force Full Speed. */ -#define USB_CONF_CFORCE_FS BIT(12) -/* Set Force Full Speed. */ -#define USB_CONF_SFORCE_FS BIT(13) -/* Device enable. */ -#define USB_CONF_DEVEN BIT(14) -/* Device disable. */ -#define USB_CONF_DEVDS BIT(15) -/* L1 LPM state entry enable (used in HS/FS mode). */ -#define USB_CONF_L1EN BIT(16) -/* L1 LPM state entry disable (used in HS/FS mode). */ -#define USB_CONF_L1DS BIT(17) -/* USB 2.0 clock gate disable. */ -#define USB_CONF_CLK2OFFEN BIT(18) -/* USB 2.0 clock gate enable. */ -#define USB_CONF_CLK2OFFDS BIT(19) -/* L0 LPM state entry request (used in HS/FS mode). */ -#define USB_CONF_LGO_L0 BIT(20) -/* USB 3.0 clock gate disable. */ -#define USB_CONF_CLK3OFFEN BIT(21) -/* USB 3.0 clock gate enable. */ -#define USB_CONF_CLK3OFFDS BIT(22) -/* Bit 23 is reserved*/ -/* U1 state entry enable (used in SS mode). */ -#define USB_CONF_U1EN BIT(24) -/* U1 state entry disable (used in SS mode). */ -#define USB_CONF_U1DS BIT(25) -/* U2 state entry enable (used in SS mode). */ -#define USB_CONF_U2EN BIT(26) -/* U2 state entry disable (used in SS mode). */ -#define USB_CONF_U2DS BIT(27) -/* U0 state entry request (used in SS mode). */ -#define USB_CONF_LGO_U0 BIT(28) -/* U1 state entry request (used in SS mode). */ -#define USB_CONF_LGO_U1 BIT(29) -/* U2 state entry request (used in SS mode). */ -#define USB_CONF_LGO_U2 BIT(30) -/* SS.Inactive state entry request (used in SS mode) */ -#define USB_CONF_LGO_SSINACT BIT(31) - -/* USB_STS - bitmasks */ -/* - * Configuration status. - * 1 - device is in the configured state. - * 0 - device is not configured. - */ -#define USB_STS_CFGSTS_MASK BIT(0) -#define USB_STS_CFGSTS(p) ((p) & USB_STS_CFGSTS_MASK) -/* - * On-chip memory overflow. - * 0 - On-chip memory status OK. - * 1 - On-chip memory overflow. - */ -#define USB_STS_OV_MASK BIT(1) -#define USB_STS_OV(p) ((p) & USB_STS_OV_MASK) -/* - * SuperSpeed connection status. - * 0 - USB in SuperSpeed mode disconnected. - * 1 - USB in SuperSpeed mode connected. - */ -#define USB_STS_USB3CONS_MASK BIT(2) -#define USB_STS_USB3CONS(p) ((p) & USB_STS_USB3CONS_MASK) -/* - * DMA transfer configuration status. - * 0 - single request. - * 1 - multiple TRB chain - * Supported only for controller version < DEV_VER_V3 - */ -#define USB_STS_DTRANS_MASK BIT(3) -#define USB_STS_DTRANS(p) ((p) & USB_STS_DTRANS_MASK) -/* - * Device speed. - * 0 - Undefined (value after reset). - * 1 - Low speed - * 2 - Full speed - * 3 - High speed - * 4 - Super speed - */ -#define USB_STS_USBSPEED_MASK GENMASK(6, 4) -#define USB_STS_USBSPEED(p) (((p) & USB_STS_USBSPEED_MASK) >> 4) -#define USB_STS_LS (0x1 << 4) -#define USB_STS_FS (0x2 << 4) -#define USB_STS_HS (0x3 << 4) -#define USB_STS_SS (0x4 << 4) -#define DEV_UNDEFSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == (0x0 << 4)) -#define DEV_LOWSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_LS) -#define DEV_FULLSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_FS) -#define DEV_HIGHSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_HS) -#define DEV_SUPERSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_SS) -/* - * Endianness for SFR access. - * 0 - Little Endian order (default after hardware reset). - * 1 - Big Endian order - */ -#define USB_STS_ENDIAN_MASK BIT(7) -#define USB_STS_ENDIAN(p) ((p) & USB_STS_ENDIAN_MASK) -/* - * HS/FS clock turn-off status. - * 0 - hsfs clock is always on. - * 1 - hsfs clock turn-off in L2 (HS/FS mode) is enabled - * (default after hardware reset). - */ -#define USB_STS_CLK2OFF_MASK BIT(8) -#define USB_STS_CLK2OFF(p) ((p) & USB_STS_CLK2OFF_MASK) -/* - * PCLK clock turn-off status. - * 0 - pclk clock is always on. - * 1 - pclk clock turn-off in U3 (SS mode) is enabled - * (default after hardware reset). - */ -#define USB_STS_CLK3OFF_MASK BIT(9) -#define USB_STS_CLK3OFF(p) ((p) & USB_STS_CLK3OFF_MASK) -/* - * Controller in reset state. - * 0 - Internal reset is active. - * 1 - Internal reset is not active and controller is fully operational. - */ -#define USB_STS_IN_RST_MASK BIT(10) -#define USB_STS_IN_RST(p) ((p) & USB_STS_IN_RST_MASK) -/* - * Status of the "TDL calculation basing on TRB" feature. - * 0 - disabled - * 1 - enabled - * Supported only for DEV_VER_V2 controller version. - */ -#define USB_STS_TDL_TRB_ENABLED BIT(11) -/* - * Device enable Status. - * 0 - USB device is disabled (VBUS input is disconnected from internal logic). - * 1 - USB device is enabled (VBUS input is connected to the internal logic). - */ -#define USB_STS_DEVS_MASK BIT(14) -#define USB_STS_DEVS(p) ((p) & USB_STS_DEVS_MASK) -/* - * Address status. - * 0 - USB device is default state. - * 1 - USB device is at least in address state. - */ -#define USB_STS_ADDRESSED_MASK BIT(15) -#define USB_STS_ADDRESSED(p) ((p) & USB_STS_ADDRESSED_MASK) -/* - * L1 LPM state enable status (used in HS/FS mode). - * 0 - Entering to L1 LPM state disabled. - * 1 - Entering to L1 LPM state enabled. - */ -#define USB_STS_L1ENS_MASK BIT(16) -#define USB_STS_L1ENS(p) ((p) & USB_STS_L1ENS_MASK) -/* - * Internal VBUS connection status (used both in HS/FS and SS mode). - * 0 - internal VBUS is not detected. - * 1 - internal VBUS is detected. - */ -#define USB_STS_VBUSS_MASK BIT(17) -#define USB_STS_VBUSS(p) ((p) & USB_STS_VBUSS_MASK) -/* - * HS/FS LPM state (used in FS/HS mode). - * 0 - L0 State - * 1 - L1 State - * 2 - L2 State - * 3 - L3 State - */ -#define USB_STS_LPMST_MASK GENMASK(19, 18) -#define DEV_L0_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x0 << 18)) -#define DEV_L1_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x1 << 18)) -#define DEV_L2_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x2 << 18)) -#define DEV_L3_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x3 << 18)) -/* - * Disable HS status (used in FS/HS mode). - * 0 - the disconnect bit for HS/FS mode is set . - * 1 - the disconnect bit for HS/FS mode is not set. - */ -#define USB_STS_USB2CONS_MASK BIT(20) -#define USB_STS_USB2CONS(p) ((p) & USB_STS_USB2CONS_MASK) -/* - * HS/FS mode connection status (used in FS/HS mode). - * 0 - High Speed operations in USB2.0 (FS/HS) mode not disabled. - * 1 - High Speed operations in USB2.0 (FS/HS). - */ -#define USB_STS_DISABLE_HS_MASK BIT(21) -#define USB_STS_DISABLE_HS(p) ((p) & USB_STS_DISABLE_HS_MASK) -/* - * U1 state enable status (used in SS mode). - * 0 - Entering to U1 state disabled. - * 1 - Entering to U1 state enabled. - */ -#define USB_STS_U1ENS_MASK BIT(24) -#define USB_STS_U1ENS(p) ((p) & USB_STS_U1ENS_MASK) -/* - * U2 state enable status (used in SS mode). - * 0 - Entering to U2 state disabled. - * 1 - Entering to U2 state enabled. - */ -#define USB_STS_U2ENS_MASK BIT(25) -#define USB_STS_U2ENS(p) ((p) & USB_STS_U2ENS_MASK) -/* - * SuperSpeed Link LTSSM state. This field reflects USBSS-DEV current - * SuperSpeed link state - */ -#define USB_STS_LST_MASK GENMASK(29, 26) -#define DEV_LST_U0 (((p) & USB_STS_LST_MASK) == (0x0 << 26)) -#define DEV_LST_U1 (((p) & USB_STS_LST_MASK) == (0x1 << 26)) -#define DEV_LST_U2 (((p) & USB_STS_LST_MASK) == (0x2 << 26)) -#define DEV_LST_U3 (((p) & USB_STS_LST_MASK) == (0x3 << 26)) -#define DEV_LST_DISABLED (((p) & USB_STS_LST_MASK) == (0x4 << 26)) -#define DEV_LST_RXDETECT (((p) & USB_STS_LST_MASK) == (0x5 << 26)) -#define DEV_LST_INACTIVE (((p) & USB_STS_LST_MASK) == (0x6 << 26)) -#define DEV_LST_POLLING (((p) & USB_STS_LST_MASK) == (0x7 << 26)) -#define DEV_LST_RECOVERY (((p) & USB_STS_LST_MASK) == (0x8 << 26)) -#define DEV_LST_HOT_RESET (((p) & USB_STS_LST_MASK) == (0x9 << 26)) -#define DEV_LST_COMP_MODE (((p) & USB_STS_LST_MASK) == (0xa << 26)) -#define DEV_LST_LB_STATE (((p) & USB_STS_LST_MASK) == (0xb << 26)) -/* - * DMA clock turn-off status. - * 0 - DMA clock is always on (default after hardware reset). - * 1 - DMA clock turn-off in U1, U2 and U3 (SS mode) is enabled. - */ -#define USB_STS_DMAOFF_MASK BIT(30) -#define USB_STS_DMAOFF(p) ((p) & USB_STS_DMAOFF_MASK) -/* - * SFR Endian status. - * 0 - Little Endian order (default after hardware reset). - * 1 - Big Endian order. - */ -#define USB_STS_ENDIAN2_MASK BIT(31) -#define USB_STS_ENDIAN2(p) ((p) & USB_STS_ENDIAN2_MASK) - -/* USB_CMD - bitmasks */ -/* Set Function Address */ -#define USB_CMD_SET_ADDR BIT(0) -/* - * Function Address This field is saved to the device only when the field - * SET_ADDR is set '1 ' during write to USB_CMD register. - * Software is responsible for entering the address of the device during - * SET_ADDRESS request service. This field should be set immediately after - * the SETUP packet is decoded, and prior to confirmation of the status phase - */ -#define USB_CMD_FADDR_MASK GENMASK(7, 1) -#define USB_CMD_FADDR(p) (((p) << 1) & USB_CMD_FADDR_MASK) -/* Send Function Wake Device Notification TP (used only in SS mode). */ -#define USB_CMD_SDNFW BIT(8) -/* Set Test Mode (used only in HS/FS mode). */ -#define USB_CMD_STMODE BIT(9) -/* Test mode selector (used only in HS/FS mode) */ -#define USB_STS_TMODE_SEL_MASK GENMASK(11, 10) -#define USB_STS_TMODE_SEL(p) (((p) << 10) & USB_STS_TMODE_SEL_MASK) -/* - * Send Latency Tolerance Message Device Notification TP (used only - * in SS mode). - */ -#define USB_CMD_SDNLTM BIT(12) -/* Send Custom Transaction Packet (used only in SS mode) */ -#define USB_CMD_SPKT BIT(13) -/*Device Notification 'Function Wake' - Interface value (only in SS mode. */ -#define USB_CMD_DNFW_INT_MASK GENMASK(23, 16) -#define USB_STS_DNFW_INT(p) (((p) << 16) & USB_CMD_DNFW_INT_MASK) -/* - * Device Notification 'Latency Tolerance Message' -373 BELT value [7:0] - * (used only in SS mode). - */ -#define USB_CMD_DNLTM_BELT_MASK GENMASK(27, 16) -#define USB_STS_DNLTM_BELT(p) (((p) << 16) & USB_CMD_DNLTM_BELT_MASK) - -/* USB_ITPN - bitmasks */ -/* - * ITP(SS) / SOF (HS/FS) number - * In SS mode this field represent number of last ITP received from host. - * In HS/FS mode this field represent number of last SOF received from host. - */ -#define USB_ITPN_MASK GENMASK(13, 0) -#define USB_ITPN(p) ((p) & USB_ITPN_MASK) - -/* USB_LPM - bitmasks */ -/* Host Initiated Resume Duration. */ -#define USB_LPM_HIRD_MASK GENMASK(3, 0) -#define USB_LPM_HIRD(p) ((p) & USB_LPM_HIRD_MASK) -/* Remote Wakeup Enable (bRemoteWake). */ -#define USB_LPM_BRW BIT(4) - -/* USB_IEN - bitmasks */ -/* SS connection interrupt enable */ -#define USB_IEN_CONIEN BIT(0) -/* SS disconnection interrupt enable. */ -#define USB_IEN_DISIEN BIT(1) -/* USB SS warm reset interrupt enable. */ -#define USB_IEN_UWRESIEN BIT(2) -/* USB SS hot reset interrupt enable */ -#define USB_IEN_UHRESIEN BIT(3) -/* SS link U3 state enter interrupt enable (suspend).*/ -#define USB_IEN_U3ENTIEN BIT(4) -/* SS link U3 state exit interrupt enable (wakeup). */ -#define USB_IEN_U3EXTIEN BIT(5) -/* SS link U2 state enter interrupt enable.*/ -#define USB_IEN_U2ENTIEN BIT(6) -/* SS link U2 state exit interrupt enable.*/ -#define USB_IEN_U2EXTIEN BIT(7) -/* SS link U1 state enter interrupt enable.*/ -#define USB_IEN_U1ENTIEN BIT(8) -/* SS link U1 state exit interrupt enable.*/ -#define USB_IEN_U1EXTIEN BIT(9) -/* ITP/SOF packet detected interrupt enable.*/ -#define USB_IEN_ITPIEN BIT(10) -/* Wakeup interrupt enable.*/ -#define USB_IEN_WAKEIEN BIT(11) -/* Send Custom Packet interrupt enable.*/ -#define USB_IEN_SPKTIEN BIT(12) -/* HS/FS mode connection interrupt enable.*/ -#define USB_IEN_CON2IEN BIT(16) -/* HS/FS mode disconnection interrupt enable.*/ -#define USB_IEN_DIS2IEN BIT(17) -/* USB reset (HS/FS mode) interrupt enable.*/ -#define USB_IEN_U2RESIEN BIT(18) -/* LPM L2 state enter interrupt enable.*/ -#define USB_IEN_L2ENTIEN BIT(20) -/* LPM L2 state exit interrupt enable.*/ -#define USB_IEN_L2EXTIEN BIT(21) -/* LPM L1 state enter interrupt enable.*/ -#define USB_IEN_L1ENTIEN BIT(24) -/* LPM L1 state exit interrupt enable.*/ -#define USB_IEN_L1EXTIEN BIT(25) -/* Configuration reset interrupt enable.*/ -#define USB_IEN_CFGRESIEN BIT(26) -/* Start of the USB SS warm reset interrupt enable.*/ -#define USB_IEN_UWRESSIEN BIT(28) -/* End of the USB SS warm reset interrupt enable.*/ -#define USB_IEN_UWRESEIEN BIT(29) - -#define USB_IEN_INIT (USB_IEN_U2RESIEN | USB_ISTS_DIS2I | USB_IEN_CON2IEN \ - | USB_IEN_UHRESIEN | USB_IEN_UWRESIEN | USB_IEN_DISIEN \ - | USB_IEN_CONIEN | USB_IEN_U3EXTIEN | USB_IEN_L2ENTIEN \ - | USB_IEN_L2EXTIEN | USB_IEN_L1ENTIEN) - -/* USB_ISTS - bitmasks */ -/* SS Connection detected. */ -#define USB_ISTS_CONI BIT(0) -/* SS Disconnection detected. */ -#define USB_ISTS_DISI BIT(1) -/* UUSB warm reset detectede. */ -#define USB_ISTS_UWRESI BIT(2) -/* USB hot reset detected. */ -#define USB_ISTS_UHRESI BIT(3) -/* U3 link state enter detected (suspend).*/ -#define USB_ISTS_U3ENTI BIT(4) -/* U3 link state exit detected (wakeup). */ -#define USB_ISTS_U3EXTI BIT(5) -/* U2 link state enter detected.*/ -#define USB_ISTS_U2ENTI BIT(6) -/* U2 link state exit detected.*/ -#define USB_ISTS_U2EXTI BIT(7) -/* U1 link state enter detected.*/ -#define USB_ISTS_U1ENTI BIT(8) -/* U1 link state exit detected.*/ -#define USB_ISTS_U1EXTI BIT(9) -/* ITP/SOF packet detected.*/ -#define USB_ISTS_ITPI BIT(10) -/* Wakeup detected.*/ -#define USB_ISTS_WAKEI BIT(11) -/* Send Custom Packet detected.*/ -#define USB_ISTS_SPKTI BIT(12) -/* HS/FS mode connection detected.*/ -#define USB_ISTS_CON2I BIT(16) -/* HS/FS mode disconnection detected.*/ -#define USB_ISTS_DIS2I BIT(17) -/* USB reset (HS/FS mode) detected.*/ -#define USB_ISTS_U2RESI BIT(18) -/* LPM L2 state enter detected.*/ -#define USB_ISTS_L2ENTI BIT(20) -/* LPM L2 state exit detected.*/ -#define USB_ISTS_L2EXTI BIT(21) -/* LPM L1 state enter detected.*/ -#define USB_ISTS_L1ENTI BIT(24) -/* LPM L1 state exit detected.*/ -#define USB_ISTS_L1EXTI BIT(25) -/* USB configuration reset detected.*/ -#define USB_ISTS_CFGRESI BIT(26) -/* Start of the USB warm reset detected.*/ -#define USB_ISTS_UWRESSI BIT(28) -/* End of the USB warm reset detected.*/ -#define USB_ISTS_UWRESEI BIT(29) - -/* USB_SEL - bitmasks */ -#define EP_SEL_EPNO_MASK GENMASK(3, 0) -/* Endpoint number. */ -#define EP_SEL_EPNO(p) ((p) & EP_SEL_EPNO_MASK) -/* Endpoint direction bit - 0 - OUT, 1 - IN. */ -#define EP_SEL_DIR BIT(7) - -#define select_ep_in(nr) (EP_SEL_EPNO(p) | EP_SEL_DIR) -#define select_ep_out (EP_SEL_EPNO(p)) - -/* EP_TRADDR - bitmasks */ -/* Transfer Ring address. */ -#define EP_TRADDR_TRADDR(p) ((p)) - -/* EP_CFG - bitmasks */ -/* Endpoint enable */ -#define EP_CFG_ENABLE BIT(0) -/* - * Endpoint type. - * 1 - isochronous - * 2 - bulk - * 3 - interrupt - */ -#define EP_CFG_EPTYPE_MASK GENMASK(2, 1) -#define EP_CFG_EPTYPE(p) (((p) << 1) & EP_CFG_EPTYPE_MASK) -/* Stream support enable (only in SS mode). */ -#define EP_CFG_STREAM_EN BIT(3) -/* TDL check (only in SS mode for BULK EP). */ -#define EP_CFG_TDL_CHK BIT(4) -/* SID check (only in SS mode for BULK OUT EP). */ -#define EP_CFG_SID_CHK BIT(5) -/* DMA transfer endianness. */ -#define EP_CFG_EPENDIAN BIT(7) -/* Max burst size (used only in SS mode). */ -#define EP_CFG_MAXBURST_MASK GENMASK(11, 8) -#define EP_CFG_MAXBURST(p) (((p) << 8) & EP_CFG_MAXBURST_MASK) -/* ISO max burst. */ -#define EP_CFG_MULT_MASK GENMASK(15, 14) -#define EP_CFG_MULT(p) (((p) << 14) & EP_CFG_MULT_MASK) -/* ISO max burst. */ -#define EP_CFG_MAXPKTSIZE_MASK GENMASK(26, 16) -#define EP_CFG_MAXPKTSIZE(p) (((p) << 16) & EP_CFG_MAXPKTSIZE_MASK) -/* Max number of buffered packets. */ -#define EP_CFG_BUFFERING_MASK GENMASK(31, 27) -#define EP_CFG_BUFFERING(p) (((p) << 27) & EP_CFG_BUFFERING_MASK) - -/* EP_CMD - bitmasks */ -/* Endpoint reset. */ -#define EP_CMD_EPRST BIT(0) -/* Endpoint STALL set. */ -#define EP_CMD_SSTALL BIT(1) -/* Endpoint STALL clear. */ -#define EP_CMD_CSTALL BIT(2) -/* Send ERDY TP. */ -#define EP_CMD_ERDY BIT(3) -/* Request complete. */ -#define EP_CMD_REQ_CMPL BIT(5) -/* Transfer descriptor ready. */ -#define EP_CMD_DRDY BIT(6) -/* Data flush. */ -#define EP_CMD_DFLUSH BIT(7) -/* - * Transfer Descriptor Length write (used only for Bulk Stream capable - * endpoints in SS mode). - * Bit Removed from DEV_VER_V3 controller version. - */ -#define EP_CMD_STDL BIT(8) -/* - * Transfer Descriptor Length (used only in SS mode for bulk endpoints). - * Bits Removed from DEV_VER_V3 controller version. - */ -#define EP_CMD_TDL_MASK GENMASK(15, 9) -#define EP_CMD_TDL(p) (((p) << 9) & EP_CMD_TDL_MASK) -/* ERDY Stream ID value (used in SS mode). */ -#define EP_CMD_ERDY_SID_MASK GENMASK(31, 16) -#define EP_CMD_ERDY_SID(p) (((p) << 16) & EP_CMD_SID_MASK) - -/* EP_STS - bitmasks */ -/* Setup transfer complete. */ -#define EP_STS_SETUP BIT(0) -/* Endpoint STALL status. */ -#define EP_STS_STALL(p) ((p) & BIT(1)) -/* Interrupt On Complete. */ -#define EP_STS_IOC BIT(2) -/* Interrupt on Short Packet. */ -#define EP_STS_ISP BIT(3) -/* Transfer descriptor missing. */ -#define EP_STS_DESCMIS BIT(4) -/* Stream Rejected (used only in SS mode) */ -#define EP_STS_STREAMR BIT(5) -/* EXIT from MOVE DATA State (used only for stream transfers in SS mode). */ -#define EP_STS_MD_EXIT BIT(6) -/* TRB error. */ -#define EP_STS_TRBERR BIT(7) -/* Not ready (used only in SS mode). */ -#define EP_STS_NRDY BIT(8) -/* DMA busy bit. */ -#define EP_STS_DBUSY BIT(9) -/* Endpoint Buffer Empty */ -#define EP_STS_BUFFEMPTY(p) ((p) & BIT(10)) -/* Current Cycle Status */ -#define EP_STS_CCS(p) ((p) & BIT(11)) -/* Prime (used only in SS mode. */ -#define EP_STS_PRIME BIT(12) -/* Stream error (used only in SS mode). */ -#define EP_STS_SIDERR BIT(13) -/* OUT size mismatch. */ -#define EP_STS_OUTSMM BIT(14) -/* ISO transmission error. */ -#define EP_STS_ISOERR BIT(15) -/* Host Packet Pending (only for SS mode). */ -#define EP_STS_HOSTPP(p) ((p) & BIT(16)) -/* Stream Protocol State Machine State (only for Bulk stream endpoints). */ -#define EP_STS_SPSMST_MASK GENMASK(18, 17) -#define EP_STS_SPSMST_DISABLED(p) (((p) & EP_STS_SPSMST_MASK) >> 17) -#define EP_STS_SPSMST_IDLE(p) (((p) & EP_STS_SPSMST_MASK) >> 17) -#define EP_STS_SPSMST_START_STREAM(p) (((p) & EP_STS_SPSMST_MASK) >> 17) -#define EP_STS_SPSMST_MOVE_DATA(p) (((p) & EP_STS_SPSMST_MASK) >> 17) -/* Interrupt On Transfer complete. */ -#define EP_STS_IOT BIT(19) -/* OUT queue endpoint number. */ -#define EP_STS_OUTQ_NO_MASK GENMASK(27, 24) -#define EP_STS_OUTQ_NO(p) (((p) & EP_STS_OUTQ_NO_MASK) >> 24) -/* OUT queue valid flag. */ -#define EP_STS_OUTQ_VAL_MASK BIT(28) -#define EP_STS_OUTQ_VAL(p) ((p) & EP_STS_OUTQ_VAL_MASK) -/* SETUP WAIT. */ -#define EP_STS_STPWAIT BIT(31) - -/* EP_STS_SID - bitmasks */ -/* Stream ID (used only in SS mode). */ -#define EP_STS_SID_MASK GENMASK(15, 0) -#define EP_STS_SID(p) ((p) & EP_STS_SID_MASK) - -/* EP_STS_EN - bitmasks */ -/* SETUP interrupt enable. */ -#define EP_STS_EN_SETUPEN BIT(0) -/* OUT transfer missing descriptor enable. */ -#define EP_STS_EN_DESCMISEN BIT(4) -/* Stream Rejected enable. */ -#define EP_STS_EN_STREAMREN BIT(5) -/* Move Data Exit enable.*/ -#define EP_STS_EN_MD_EXITEN BIT(6) -/* TRB enable. */ -#define EP_STS_EN_TRBERREN BIT(7) -/* NRDY enable. */ -#define EP_STS_EN_NRDYEN BIT(8) -/* Prime enable. */ -#define EP_STS_EN_PRIMEEEN BIT(12) -/* Stream error enable. */ -#define EP_STS_EN_SIDERREN BIT(13) -/* OUT size mismatch enable. */ -#define EP_STS_EN_OUTSMMEN BIT(14) -/* ISO transmission error enable. */ -#define EP_STS_EN_ISOERREN BIT(15) -/* Interrupt on Transmission complete enable. */ -#define EP_STS_EN_IOTEN BIT(19) -/* Setup Wait interrupt enable. */ -#define EP_STS_EN_STPWAITEN BIT(31) - -/* DRBL- bitmasks */ -#define DB_VALUE_BY_INDEX(index) (1 << (index)) -#define DB_VALUE_EP0_OUT BIT(0) -#define DB_VALUE_EP0_IN BIT(16) - -/* EP_IEN - bitmasks */ -#define EP_IEN(index) (1 << (index)) -#define EP_IEN_EP_OUT0 BIT(0) -#define EP_IEN_EP_IN0 BIT(16) - -/* EP_ISTS - bitmasks */ -#define EP_ISTS(index) (1 << (index)) -#define EP_ISTS_EP_OUT0 BIT(0) -#define EP_ISTS_EP_IN0 BIT(16) - -/* USB_PWR- bitmasks */ -/*Power Shut Off capability enable*/ -#define PUSB_PWR_PSO_EN BIT(0) -/*Power Shut Off capability disable*/ -#define PUSB_PWR_PSO_DS BIT(1) -/* - * Enables turning-off Reference Clock. - * This bit is optional and implemented only when support for OTG is - * implemented (indicated by OTG_READY bit set to '1'). - */ -#define PUSB_PWR_STB_CLK_SWITCH_EN BIT(8) -/* - * Status bit indicating that operation required by STB_CLK_SWITCH_EN write - * is completed - */ -#define PUSB_PWR_STB_CLK_SWITCH_DONE BIT(9) -/* This bit informs if Fast Registers Access is enabled. */ -#define PUSB_PWR_FST_REG_ACCESS_STAT BIT(30) -/* Fast Registers Access Enable. */ -#define PUSB_PWR_FST_REG_ACCESS BIT(31) - -/* USB_CONF2- bitmasks */ -/* - * Writing 1 disables TDL calculation basing on TRB feature in controller - * for DMULT mode. - * Bit supported only for DEV_VER_V2 version. - */ -#define USB_CONF2_DIS_TDL_TRB BIT(1) -/* - * Writing 1 enables TDL calculation basing on TRB feature in controller - * for DMULT mode. - * Bit supported only for DEV_VER_V2 version. - */ -#define USB_CONF2_EN_TDL_TRB BIT(2) - -/* USB_CAP1- bitmasks */ -/* - * SFR Interface type - * These field reflects type of SFR interface implemented: - * 0x0 - OCP - * 0x1 - AHB, - * 0x2 - PLB - * 0x3 - AXI - * 0x4-0xF - reserved - */ -#define USB_CAP1_SFR_TYPE_MASK GENMASK(3, 0) -#define DEV_SFR_TYPE_OCP(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x0) -#define DEV_SFR_TYPE_AHB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x1) -#define DEV_SFR_TYPE_PLB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x2) -#define DEV_SFR_TYPE_AXI(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x3) -/* - * SFR Interface width - * These field reflects width of SFR interface implemented: - * 0x0 - 8 bit interface, - * 0x1 - 16 bit interface, - * 0x2 - 32 bit interface - * 0x3 - 64 bit interface - * 0x4-0xF - reserved - */ -#define USB_CAP1_SFR_WIDTH_MASK GENMASK(7, 4) -#define DEV_SFR_WIDTH_8(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x0 << 4)) -#define DEV_SFR_WIDTH_16(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x1 << 4)) -#define DEV_SFR_WIDTH_32(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x2 << 4)) -#define DEV_SFR_WIDTH_64(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x3 << 4)) -/* - * DMA Interface type - * These field reflects type of DMA interface implemented: - * 0x0 - OCP - * 0x1 - AHB, - * 0x2 - PLB - * 0x3 - AXI - * 0x4-0xF - reserved - */ -#define USB_CAP1_DMA_TYPE_MASK GENMASK(11, 8) -#define DEV_DMA_TYPE_OCP(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x0 << 8)) -#define DEV_DMA_TYPE_AHB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x1 << 8)) -#define DEV_DMA_TYPE_PLB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x2 << 8)) -#define DEV_DMA_TYPE_AXI(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x3 << 8)) -/* - * DMA Interface width - * These field reflects width of DMA interface implemented: - * 0x0 - reserved, - * 0x1 - reserved, - * 0x2 - 32 bit interface - * 0x3 - 64 bit interface - * 0x4-0xF - reserved - */ -#define USB_CAP1_DMA_WIDTH_MASK GENMASK(15, 12) -#define DEV_DMA_WIDTH_32(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x2 << 12)) -#define DEV_DMA_WIDTH_64(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x3 << 12)) -/* - * USB3 PHY Interface type - * These field reflects type of USB3 PHY interface implemented: - * 0x0 - USB PIPE, - * 0x1 - RMMI, - * 0x2-0xF - reserved - */ -#define USB_CAP1_U3PHY_TYPE_MASK GENMASK(19, 16) -#define DEV_U3PHY_PIPE(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x0 << 16)) -#define DEV_U3PHY_RMMI(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x1 << 16)) -/* - * USB3 PHY Interface width - * These field reflects width of USB3 PHY interface implemented: - * 0x0 - 8 bit PIPE interface, - * 0x1 - 16 bit PIPE interface, - * 0x2 - 32 bit PIPE interface, - * 0x3 - 64 bit PIPE interface - * 0x4-0xF - reserved - * Note: When SSIC interface is implemented this field shows the width of - * internal PIPE interface. The RMMI interface is always 20bit wide. - */ -#define USB_CAP1_U3PHY_WIDTH_MASK GENMASK(23, 20) -#define DEV_U3PHY_WIDTH_8(p) \ - (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x0 << 20)) -#define DEV_U3PHY_WIDTH_16(p) \ - (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x1 << 16)) -#define DEV_U3PHY_WIDTH_32(p) \ - (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x2 << 20)) -#define DEV_U3PHY_WIDTH_64(p) \ - (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x3 << 16)) - -/* - * USB2 PHY Interface enable - * These field informs if USB2 PHY interface is implemented: - * 0x0 - interface NOT implemented, - * 0x1 - interface implemented - */ -#define USB_CAP1_U2PHY_EN(p) ((p) & BIT(24)) -/* - * USB2 PHY Interface type - * These field reflects type of USB2 PHY interface implemented: - * 0x0 - UTMI, - * 0x1 - ULPI - */ -#define DEV_U2PHY_ULPI(p) ((p) & BIT(25)) -/* - * USB2 PHY Interface width - * These field reflects width of USB2 PHY interface implemented: - * 0x0 - 8 bit interface, - * 0x1 - 16 bit interface, - * Note: The ULPI interface is always 8bit wide. - */ -#define DEV_U2PHY_WIDTH_16(p) ((p) & BIT(26)) -/* - * OTG Ready - * 0x0 - pure device mode - * 0x1 - some features and ports for CDNS USB OTG controller are implemented. - */ -#define USB_CAP1_OTG_READY(p) ((p) & BIT(27)) - -/* - * When set, indicates that controller supports automatic internal TDL - * calculation basing on the size provided in TRB (TRB[22:17]) for DMULT mode - * Supported only for DEV_VER_V2 controller version. - */ -#define USB_CAP1_TDL_FROM_TRB(p) ((p) & BIT(28)) - -/* USB_CAP2- bitmasks */ -/* - * The actual size of the connected On-chip RAM memory in kB: - * - 0 means 256 kB (max supported mem size) - * - value other than 0 reflects the mem size in kB - */ -#define USB_CAP2_ACTUAL_MEM_SIZE(p) ((p) & GENMASK(7, 0)) -/* - * Max supported mem size - * These field reflects width of on-chip RAM address bus width, - * which determines max supported mem size: - * 0x0-0x7 - reserved, - * 0x8 - support for 4kB mem, - * 0x9 - support for 8kB mem, - * 0xA - support for 16kB mem, - * 0xB - support for 32kB mem, - * 0xC - support for 64kB mem, - * 0xD - support for 128kB mem, - * 0xE - support for 256kB mem, - * 0xF - reserved - */ -#define USB_CAP2_MAX_MEM_SIZE(p) ((p) & GENMASK(11, 8)) - -/* USB_CAP3- bitmasks */ -#define EP_IS_IMPLEMENTED(reg, index) ((reg) & (1 << (index))) - -/* USB_CAP4- bitmasks */ -#define EP_SUPPORT_ISO(reg, index) ((reg) & (1 << (index))) - -/* USB_CAP5- bitmasks */ -#define EP_SUPPORT_STREAM(reg, index) ((reg) & (1 << (index))) - -/* USB_CAP6- bitmasks */ -/* The USBSS-DEV Controller Internal build number. */ -#define GET_DEV_BASE_VERSION(p) ((p) & GENMASK(23, 0)) -/* The USBSS-DEV Controller version number. */ -#define GET_DEV_CUSTOM_VERSION(p) ((p) & GENMASK(31, 24)) - -#define DEV_VER_NXP_V1 0x00024502 -#define DEV_VER_TI_V1 0x00024509 -#define DEV_VER_V2 0x0002450C -#define DEV_VER_V3 0x0002450d - -/* DBG_LINK1- bitmasks */ -/* - * LFPS_MIN_DET_U1_EXIT value This parameter configures the minimum - * time required for decoding the received LFPS as an LFPS.U1_Exit. - */ -#define DBG_LINK1_LFPS_MIN_DET_U1_EXIT(p) ((p) & GENMASK(7, 0)) -/* - * LFPS_MIN_GEN_U1_EXIT value This parameter configures the minimum time for - * phytxelecidle deassertion when LFPS.U1_Exit - */ -#define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_MASK GENMASK(15, 8) -#define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT(p) (((p) << 8) & GENMASK(15, 8)) -/* - * RXDET_BREAK_DIS value This parameter configures terminating the Far-end - * Receiver termination detection sequence: - * 0: it is possible that USBSS_DEV will terminate Farend receiver - * termination detection sequence - * 1: USBSS_DEV will not terminate Far-end receiver termination - * detection sequence - */ -#define DBG_LINK1_RXDET_BREAK_DIS BIT(16) -/* LFPS_GEN_PING value This parameter configures the LFPS.Ping generation */ -#define DBG_LINK1_LFPS_GEN_PING(p) (((p) << 17) & GENMASK(21, 17)) -/* - * Set the LFPS_MIN_DET_U1_EXIT value Writing '1' to this bit writes the - * LFPS_MIN_DET_U1_EXIT field value to the device. This bit is automatically - * cleared. Writing '0' has no effect - */ -#define DBG_LINK1_LFPS_MIN_DET_U1_EXIT_SET BIT(24) -/* - * Set the LFPS_MIN_GEN_U1_EXIT value. Writing '1' to this bit writes the - * LFPS_MIN_GEN_U1_EXIT field value to the device. This bit is automatically - * cleared. Writing '0' has no effect - */ -#define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_SET BIT(25) -/* - * Set the RXDET_BREAK_DIS value Writing '1' to this bit writes - * the RXDET_BREAK_DIS field value to the device. This bit is automatically - * cleared. Writing '0' has no effect - */ -#define DBG_LINK1_RXDET_BREAK_DIS_SET BIT(26) -/* - * Set the LFPS_GEN_PING_SET value Writing '1' to this bit writes - * the LFPS_GEN_PING field value to the device. This bit is automatically - * cleared. Writing '0' has no effect." - */ -#define DBG_LINK1_LFPS_GEN_PING_SET BIT(27) - -/* DMA_AXI_CTRL- bitmasks */ -/* The mawprot pin configuration. */ -#define DMA_AXI_CTRL_MARPROT(p) ((p) & GENMASK(2, 0)) -/* The marprot pin configuration. */ -#define DMA_AXI_CTRL_MAWPROT(p) (((p) < 16) & GENMASK(18, 16)) -#define DMA_AXI_CTRL_NON_SECURE 0x02 - -#define gadget_to_cdns3_device(g) (container_of(g, struct cdns3_device, gadget)) - -#define ep_to_cdns3_ep(ep) (container_of(ep, struct cdns3_endpoint, endpoint)) - -/*-------------------------------------------------------------------------*/ -/* - * USBSS-DEV DMA interface. - */ -#define TRBS_PER_SEGMENT 40 - -#define ISO_MAX_INTERVAL 10 - -#if TRBS_PER_SEGMENT < 2 -#error "Incorrect TRBS_PER_SEGMENT. Minimal Transfer Ring size is 2." -#endif - -/* - *Only for ISOC endpoints - maximum number of TRBs is calculated as - * pow(2, bInterval-1) * number of usb requests. It is limitation made by - * driver to save memory. Controller must prepare TRB for each ITP even - * if bInterval > 1. It's the reason why driver needs so many TRBs for - * isochronous endpoints. - */ -#define TRBS_PER_ISOC_SEGMENT (ISO_MAX_INTERVAL * 8) - -#define GET_TRBS_PER_SEGMENT(ep_type) ((ep_type) == USB_ENDPOINT_XFER_ISOC ? \ - TRBS_PER_ISOC_SEGMENT : TRBS_PER_SEGMENT) -/** - * struct cdns3_trb - represent Transfer Descriptor block. - * @buffer: pointer to buffer data - * @length: length of data - * @control: control flags. - * - * This structure describes transfer block serviced by DMA module. - */ -struct cdns3_trb { - __le32 buffer; - __le32 length; - __le32 control; -}; - -#define TRB_SIZE (sizeof(struct cdns3_trb)) -#define TRB_RING_SIZE (TRB_SIZE * TRBS_PER_SEGMENT) -#define TRB_ISO_RING_SIZE (TRB_SIZE * TRBS_PER_ISOC_SEGMENT) -#define TRB_CTRL_RING_SIZE (TRB_SIZE * 2) - -/* TRB bit mask */ -#define TRB_TYPE_BITMASK GENMASK(15, 10) -#define TRB_TYPE(p) ((p) << 10) -#define TRB_FIELD_TO_TYPE(p) (((p) & TRB_TYPE_BITMASK) >> 10) - -/* TRB type IDs */ -/* bulk, interrupt, isoc , and control data stage */ -#define TRB_NORMAL 1 -/* TRB for linking ring segments */ -#define TRB_LINK 6 - -/* Cycle bit - indicates TRB ownership by driver or hw*/ -#define TRB_CYCLE BIT(0) -/* - * When set to '1', the device will toggle its interpretation of the Cycle bit - */ -#define TRB_TOGGLE BIT(1) - -/* - * Short Packet (SP). OUT EPs at DMULT=1 only. Indicates if the TRB was - * processed while USB short packet was received. No more buffers defined by - * the TD will be used. DMA will automatically advance to next TD. - * - Shall be set to 0 by Software when putting TRB on the Transfer Ring - * - Shall be set to 1 by Controller when Short Packet condition for this TRB - * is detected independent if ISP is set or not. - */ -#define TRB_SP BIT(1) - -/* Interrupt on short packet*/ -#define TRB_ISP BIT(2) -/*Setting this bit enables FIFO DMA operation mode*/ -#define TRB_FIFO_MODE BIT(3) -/* Set PCIe no snoop attribute */ -#define TRB_CHAIN BIT(4) -/* Interrupt on completion */ -#define TRB_IOC BIT(5) - -/* stream ID bitmasks. */ -#define TRB_STREAM_ID(p) ((p) & GENMASK(31, 16)) - -/* Size of TD expressed in USB packets for HS/FS mode. */ -#define TRB_TDL_HS_SIZE(p) (((p) << 16) & GENMASK(31, 16)) -#define TRB_TDL_HS_SIZE_GET(p) (((p) & GENMASK(31, 16)) >> 16) - -/* transfer_len bitmasks. */ -#define TRB_LEN(p) ((p) & GENMASK(16, 0)) - -/* Size of TD expressed in USB packets for SS mode. */ -#define TRB_TDL_SS_SIZE(p) (((p) << 17) & GENMASK(23, 17)) -#define TRB_TDL_SS_SIZE_GET(p) (((p) & GENMASK(23, 17)) >> 17) - -/* transfer_len bitmasks - bits 31:24 */ -#define TRB_BURST_LEN(p) (((p) << 24) & GENMASK(31, 24)) -#define TRB_BURST_LEN_GET(p) (((p) & GENMASK(31, 24)) >> 24) - -/* Data buffer pointer bitmasks*/ -#define TRB_BUFFER(p) ((p) & GENMASK(31, 0)) - -/*-------------------------------------------------------------------------*/ -/* Driver numeric constants */ - -/* Such declaration should be added to ch9.h */ -#define USB_DEVICE_MAX_ADDRESS 127 - -/* Endpoint init values */ -#define CDNS3_EP_MAX_PACKET_LIMIT 1024 -#define CDNS3_EP_MAX_STREAMS 15 -#define CDNS3_EP0_MAX_PACKET_LIMIT 512 - -/* All endpoints including EP0 */ -#define CDNS3_ENDPOINTS_MAX_COUNT 32 -#define CDNS3_EP_ZLP_BUF_SIZE 1024 - -#define CDNS3_EP_BUF_SIZE 2 /* KB */ -#define CDNS3_EP_ISO_HS_MULT 3 -#define CDNS3_EP_ISO_SS_BURST 3 -#define CDNS3_MAX_NUM_DESCMISS_BUF 32 -#define CDNS3_DESCMIS_BUF_SIZE 2048 /* Bytes */ -/*-------------------------------------------------------------------------*/ -/* Used structs */ - -struct cdns3_device; - -/** - * struct cdns3_endpoint - extended device side representation of USB endpoint. - * @endpoint: usb endpoint - * @pending_req_list: list of requests queuing on transfer ring. - * @deferred_req_list: list of requests waiting for queuing on transfer ring. - * @trb_pool: transfer ring - array of transaction buffers - * @trb_pool_dma: dma address of transfer ring - * @cdns3_dev: device associated with this endpoint - * @name: a human readable name e.g. ep1out - * @flags: specify the current state of endpoint - * @dir: endpoint direction - * @num: endpoint number (1 - 15) - * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK - * @interval: interval between packets used for ISOC endpoint. - * @free_trbs: number of free TRBs in transfer ring - * @num_trbs: number of all TRBs in transfer ring - * @pcs: producer cycle state - * @ccs: consumer cycle state - * @enqueue: enqueue index in transfer ring - * @dequeue: dequeue index in transfer ring - * @trb_burst_size: number of burst used in trb. - */ -struct cdns3_endpoint { - struct usb_ep endpoint; - struct list_head pending_req_list; - struct list_head deferred_req_list; - - struct cdns3_trb *trb_pool; - dma_addr_t trb_pool_dma; - - struct cdns3_device *cdns3_dev; - char name[20]; - -#define EP_ENABLED BIT(0) -#define EP_STALL BIT(1) -#define EP_WEDGE BIT(2) -#define EP_TRANSFER_STARTED BIT(3) -#define EP_UPDATE_EP_TRBADDR BIT(4) -#define EP_PENDING_REQUEST BIT(5) -#define EP_RING_FULL BIT(6) -#define EP_CLAIMED BIT(7) -#define EP_DEFERRED_DRDY BIT(8) -#define EP_QUIRK_ISO_OUT_EN BIT(9) - u32 flags; - - u8 dir; - u8 num; - u8 type; - int interval; - - int free_trbs; - int num_trbs; - u8 pcs; - u8 ccs; - int enqueue; - int dequeue; - u8 trb_burst_size; - - unsigned int wa1_set:1; - struct cdns3_trb *wa1_trb; - unsigned int wa1_trb_index; - unsigned int wa1_cycle_bit:1; -}; - -/** - * struct cdns3_aligned_buf - represent aligned buffer used for DMA transfer - * @buf: aligned to 8 bytes data buffer. Buffer address used in - * TRB shall be aligned to 8. - * @dma: dma address - * @size: size of buffer - * @in_use: inform if this buffer is associated with usb_request - * @list: used to adding instance of this object to list - */ -struct cdns3_aligned_buf { - void *buf; - dma_addr_t dma; - u32 size; - int in_use:1; - struct list_head list; -}; - -/** - * struct cdns3_request - extended device side representation of usb_request - * object . - * @request: generic usb_request object describing single I/O request. - * @priv_ep: extended representation of usb_ep object - * @trb: the first TRB association with this request - * @start_trb: number of the first TRB in transfer ring - * @end_trb: number of the last TRB in transfer ring - * @aligned_buf: object holds information about aligned buffer associated whit - * this endpoint - * @flags: flag specifying special usage of request - */ -struct cdns3_request { - struct usb_request request; - struct cdns3_endpoint *priv_ep; - struct cdns3_trb *trb; - int start_trb; - int end_trb; - struct cdns3_aligned_buf *aligned_buf; -#define REQUEST_PENDING BIT(0) -#define REQUEST_INTERNAL BIT(1) -#define REQUEST_INTERNAL_CH BIT(2) -#define REQUEST_ZLP BIT(3) -#define REQUEST_UNALIGNED BIT(4) - u32 flags; - struct list_head list; -}; - -#define to_cdns3_request(r) (container_of(r, struct cdns3_request, request)) - -/*Stages used during enumeration process.*/ -#define CDNS3_SETUP_STAGE 0x0 -#define CDNS3_DATA_STAGE 0x1 -#define CDNS3_STATUS_STAGE 0x2 - -/** - * struct cdns3_device - represent USB device. - * @dev: pointer to device structure associated whit this controller - * @sysdev: pointer to the DMA capable device - * @gadget: device side representation of the peripheral controller - * @gadget_driver: pointer to the gadget driver - * @dev_ver: device controller version. - * @lock: for synchronizing - * @regs: base address for device side registers - * @setup_buf: used while processing usb control requests - * @setup_dma: dma address for setup_buf - * @zlp_buf - zlp buffer - * @ep0_stage: ep0 stage during enumeration process. - * @ep0_data_dir: direction for control transfer - * @eps: array of pointers to all endpoints with exclusion ep0 - * @aligned_buf_list: list of aligned buffers internally allocated by driver - * @run_garbage_colector: infroms that at least one element of aligned_buf_list - * can be freed - * @selected_ep: actually selected endpoint. It's used only to improve - * performance. - * @isoch_delay: value from Set Isoch Delay request. Only valid on SS/SSP. - * @u1_allowed: allow device transition to u1 state - * @u2_allowed: allow device transition to u2 state - * @is_selfpowered: device is self powered - * @setup_pending: setup packet is processing by gadget driver - * @hw_configured_flag: hardware endpoint configuration was set. - * @wake_up_flag: allow device to remote up the host - * @status_completion_no_call: indicate that driver is waiting for status s - * stage completion. It's used in deferred SET_CONFIGURATION request. - * @onchip_buffers: number of available on-chip buffers. - * @onchip_used_size: actual size of on-chip memory assigned to endpoints. - * @pending_status_wq: workqueue handling status stage for deferred requests. - * @shadow_ep_en: hold information about endpoints that will be enabled - * in soft irq. - * @pending_status_request: request for which status stage was deferred - */ -struct cdns3_device { - struct device *dev; - struct device *sysdev; - - struct usb_gadget gadget; - struct usb_gadget_driver *gadget_driver; - -#define CDNS_REVISION_V0 0x00024501 -#define CDNS_REVISION_V1 0x00024509 - u32 dev_ver; - - /* generic spin-lock for drivers */ - spinlock_t lock; - - struct cdns3_usb_regs __iomem *regs; - - struct usb_ctrlrequest *setup_buf; - dma_addr_t setup_dma; - void *zlp_buf; - - u8 ep0_stage; - int ep0_data_dir; - - struct cdns3_endpoint *eps[CDNS3_ENDPOINTS_MAX_COUNT]; - - struct list_head aligned_buf_list; - unsigned run_garbage_colector:1; - - u32 selected_ep; - u16 isoch_delay; - - unsigned wait_for_setup:1; - unsigned u1_allowed:1; - unsigned u2_allowed:1; - unsigned is_selfpowered:1; - unsigned setup_pending:1; - int hw_configured_flag:1; - int wake_up_flag:1; - unsigned status_completion_no_call:1; - int out_mem_is_allocated; - - struct work_struct pending_status_wq; - struct usb_request *pending_status_request; - u32 shadow_ep_en; - /*in KB */ - u16 onchip_buffers; - u16 onchip_used_size; -}; - -void cdns3_set_register_bit(void __iomem *ptr, u32 mask); -dma_addr_t cdns3_trb_virt_to_dma(struct cdns3_endpoint *priv_ep, - struct cdns3_trb *trb); -enum usb_device_speed cdns3_get_speed(struct cdns3_device *priv_dev); -void cdns3_pending_setup_status_handler(struct work_struct *work); -void cdns3_hw_reset_eps_config(struct cdns3_device *priv_dev); -void cdns3_set_hw_configuration(struct cdns3_device *priv_dev); -void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep); -void cdns3_allow_enable_l1(struct cdns3_device *priv_dev, int enable); -struct usb_request *cdns3_next_request(struct list_head *list); -int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, - struct usb_request *request); -void cdns3_rearm_transfer(struct cdns3_endpoint *priv_ep, u8 rearm); -int cdns3_allocate_trb_pool(struct cdns3_endpoint *priv_ep); -u8 cdns3_ep_addr_to_index(u8 ep_addr); -int cdns3_gadget_ep_set_wedge(struct usb_ep *ep); -int cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value); -struct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep, - gfp_t gfp_flags); -void cdns3_gadget_ep_free_request(struct usb_ep *ep, - struct usb_request *request); -int cdns3_gadget_ep_dequeue(struct usb_ep *ep, struct usb_request *request); -void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, - struct cdns3_request *priv_req, - int status); - -int cdns3_init_ep0(struct cdns3_device *priv_dev, - struct cdns3_endpoint *priv_ep); -void cdns3_ep0_config(struct cdns3_device *priv_dev); -void cdns3_ep_config(struct cdns3_endpoint *priv_ep); -void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir); -int __cdns3_gadget_wakeup(struct cdns3_device *priv_dev); - -#endif /* __LINUX_CDNS3_GADGET */ diff --git a/drivers/usb/cdns3/host-export.h b/drivers/usb/cdns3/host-export.h deleted file mode 100644 index b498a170b7e8..000000000000 --- a/drivers/usb/cdns3/host-export.h +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Cadence USBSS DRD Driver - Host Export APIs - * - * Copyright (C) 2017-2018 NXP - * - * Authors: Peter Chen - */ -#ifndef __LINUX_CDNS3_HOST_EXPORT -#define __LINUX_CDNS3_HOST_EXPORT - -#ifdef CONFIG_USB_CDNS3_HOST - -int cdns3_host_init(struct cdns3 *cdns); -void cdns3_host_exit(struct cdns3 *cdns); - -#else - -static inline int cdns3_host_init(struct cdns3 *cdns) -{ - return -ENXIO; -} - -static inline void cdns3_host_exit(struct cdns3 *cdns) { } - -#endif /* CONFIG_USB_CDNS3_HOST */ - -#endif /* __LINUX_CDNS3_HOST_EXPORT */ diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c deleted file mode 100644 index df41ba7c6726..000000000000 --- a/drivers/usb/cdns3/host.c +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Cadence USBSS DRD Driver - host side - * - * Copyright (C) 2018 Cadence Design Systems. - * Copyright (C) 2017-2018 NXP - * - * Authors: Peter Chen - * Pawel Laszczak - */ - -#include -#include "core.h" -#include "drd.h" - -static int __cdns3_host_init(struct cdns3 *cdns) -{ - struct platform_device *xhci; - int ret; - - cdns3_drd_switch_host(cdns, 1); - - xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO); - if (!xhci) { - dev_err(cdns->dev, "couldn't allocate xHCI device\n"); - return -ENOMEM; - } - - xhci->dev.parent = cdns->dev; - cdns->host_dev = xhci; - - ret = platform_device_add_resources(xhci, cdns->xhci_res, - CDNS3_XHCI_RESOURCES_NUM); - if (ret) { - dev_err(cdns->dev, "couldn't add resources to xHCI device\n"); - goto err1; - } - - ret = platform_device_add(xhci); - if (ret) { - dev_err(cdns->dev, "failed to register xHCI device\n"); - goto err1; - } - - return 0; -err1: - platform_device_put(xhci); - return ret; -} - -static void cdns3_host_exit(struct cdns3 *cdns) -{ - platform_device_unregister(cdns->host_dev); - cdns->host_dev = NULL; - cdns3_drd_switch_host(cdns, 0); -} - -int cdns3_host_init(struct cdns3 *cdns) -{ - struct cdns3_role_driver *rdrv; - - rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); - if (!rdrv) - return -ENOMEM; - - rdrv->start = __cdns3_host_init; - rdrv->stop = cdns3_host_exit; - rdrv->state = CDNS3_ROLE_STATE_INACTIVE; - rdrv->suspend = NULL; - rdrv->resume = NULL; - rdrv->name = "host"; - - cdns->roles[CDNS3_ROLE_HOST] = rdrv; - - return 0; -} diff --git a/drivers/usb/cdns3/trace.c b/drivers/usb/cdns3/trace.c deleted file mode 100644 index 9431eb86d4ff..000000000000 --- a/drivers/usb/cdns3/trace.c +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * USBSS device controller driver Trace Support - * - * Copyright (C) 2018 Cadence. - * - * Author: Pawel Laszczak - */ - -#define CREATE_TRACE_POINTS -#include "trace.h" - -void cdns3_dbg(struct cdns3_device *priv_dev, const char *fmt, ...) -{ - struct va_format vaf; - va_list args; - - va_start(args, fmt); - vaf.fmt = fmt; - vaf.va = &args; - trace_cdns3_log(priv_dev, &vaf); - va_end(args); -} diff --git a/drivers/usb/cdns3/trace.h b/drivers/usb/cdns3/trace.h deleted file mode 100644 index 1cc2abca320c..000000000000 --- a/drivers/usb/cdns3/trace.h +++ /dev/null @@ -1,447 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * USBSS device controller driver. - * Trace support header file. - * - * Copyright (C) 2018 Cadence. - * - * Author: Pawel Laszczak - */ - -#undef TRACE_SYSTEM -#define TRACE_SYSTEM cdns3 - -#if !defined(__LINUX_CDNS3_TRACE) || defined(TRACE_HEADER_MULTI_READ) -#define __LINUX_CDNS3_TRACE - -#include -#include -#include -#include -#include "core.h" -#include "gadget.h" -#include "debug.h" - -#define CDNS3_MSG_MAX 500 - -TRACE_EVENT(cdns3_log, - TP_PROTO(struct cdns3_device *priv_dev, struct va_format *vaf), - TP_ARGS(priv_dev, vaf), - TP_STRUCT__entry( - __string(name, dev_name(priv_dev->dev)) - __dynamic_array(char, msg, CDNS3_MSG_MAX) - ), - TP_fast_assign( - __assign_str(name, dev_name(priv_dev->dev)); - vsnprintf(__get_str(msg), CDNS3_MSG_MAX, vaf->fmt, *vaf->va); - ), - TP_printk("%s: %s", __get_str(name), __get_str(msg)) -); - -DECLARE_EVENT_CLASS(cdns3_log_doorbell, - TP_PROTO(const char *ep_name, u32 ep_trbaddr), - TP_ARGS(ep_name, ep_trbaddr), - TP_STRUCT__entry( - __string(name, ep_name) - __field(u32, ep_trbaddr) - ), - TP_fast_assign( - __assign_str(name, ep_name); - __entry->ep_trbaddr = ep_trbaddr; - ), - TP_printk("//Ding Dong %s, ep_trbaddr %08x", __get_str(name), - __entry->ep_trbaddr) -); - -DEFINE_EVENT(cdns3_log_doorbell, cdns3_doorbell_ep0, - TP_PROTO(const char *ep_name, u32 ep_trbaddr), - TP_ARGS(ep_name, ep_trbaddr) -); - -DEFINE_EVENT(cdns3_log_doorbell, cdns3_doorbell_epx, - TP_PROTO(const char *ep_name, u32 ep_trbaddr), - TP_ARGS(ep_name, ep_trbaddr) -); - -DECLARE_EVENT_CLASS(cdns3_log_usb_irq, - TP_PROTO(struct cdns3_device *priv_dev, u32 usb_ists), - TP_ARGS(priv_dev, usb_ists), - TP_STRUCT__entry( - __field(enum usb_device_speed, speed) - __field(u32, usb_ists) - __dynamic_array(char, str, CDNS3_MSG_MAX) - ), - TP_fast_assign( - __entry->speed = cdns3_get_speed(priv_dev); - __entry->usb_ists = usb_ists; - ), - TP_printk("%s", cdns3_decode_usb_irq(__get_str(str), __entry->speed, - __entry->usb_ists)) -); - -DEFINE_EVENT(cdns3_log_usb_irq, cdns3_usb_irq, - TP_PROTO(struct cdns3_device *priv_dev, u32 usb_ists), - TP_ARGS(priv_dev, usb_ists) -); - -DECLARE_EVENT_CLASS(cdns3_log_epx_irq, - TP_PROTO(struct cdns3_device *priv_dev, struct cdns3_endpoint *priv_ep), - TP_ARGS(priv_dev, priv_ep), - TP_STRUCT__entry( - __string(ep_name, priv_ep->name) - __field(u32, ep_sts) - __field(u32, ep_traddr) - __dynamic_array(char, str, CDNS3_MSG_MAX) - ), - TP_fast_assign( - __assign_str(ep_name, priv_ep->name); - __entry->ep_sts = readl(&priv_dev->regs->ep_sts); - __entry->ep_traddr = readl(&priv_dev->regs->ep_traddr); - ), - TP_printk("%s, ep_traddr: %08x", - cdns3_decode_epx_irq(__get_str(str), - __get_str(ep_name), - __entry->ep_sts), - __entry->ep_traddr) -); - -DEFINE_EVENT(cdns3_log_epx_irq, cdns3_epx_irq, - TP_PROTO(struct cdns3_device *priv_dev, struct cdns3_endpoint *priv_ep), - TP_ARGS(priv_dev, priv_ep) -); - -DECLARE_EVENT_CLASS(cdns3_log_ep0_irq, - TP_PROTO(struct cdns3_device *priv_dev, u32 ep_sts), - TP_ARGS(priv_dev, ep_sts), - TP_STRUCT__entry( - __field(int, ep_dir) - __field(u32, ep_sts) - __dynamic_array(char, str, CDNS3_MSG_MAX) - ), - TP_fast_assign( - __entry->ep_dir = priv_dev->ep0_data_dir; - __entry->ep_sts = ep_sts; - ), - TP_printk("%s", cdns3_decode_ep0_irq(__get_str(str), - __entry->ep_dir, - __entry->ep_sts)) -); - -DEFINE_EVENT(cdns3_log_ep0_irq, cdns3_ep0_irq, - TP_PROTO(struct cdns3_device *priv_dev, u32 ep_sts), - TP_ARGS(priv_dev, ep_sts) -); - -DECLARE_EVENT_CLASS(cdns3_log_ctrl, - TP_PROTO(struct usb_ctrlrequest *ctrl), - TP_ARGS(ctrl), - TP_STRUCT__entry( - __field(u8, bRequestType) - __field(u8, bRequest) - __field(u16, wValue) - __field(u16, wIndex) - __field(u16, wLength) - __dynamic_array(char, str, CDNS3_MSG_MAX) - ), - TP_fast_assign( - __entry->bRequestType = ctrl->bRequestType; - __entry->bRequest = ctrl->bRequest; - __entry->wValue = le16_to_cpu(ctrl->wValue); - __entry->wIndex = le16_to_cpu(ctrl->wIndex); - __entry->wLength = le16_to_cpu(ctrl->wLength); - ), - TP_printk("%s", usb_decode_ctrl(__get_str(str), CDNS3_MSG_MAX, - __entry->bRequestType, - __entry->bRequest, __entry->wValue, - __entry->wIndex, __entry->wLength) - ) -); - -DEFINE_EVENT(cdns3_log_ctrl, cdns3_ctrl_req, - TP_PROTO(struct usb_ctrlrequest *ctrl), - TP_ARGS(ctrl) -); - -DECLARE_EVENT_CLASS(cdns3_log_request, - TP_PROTO(struct cdns3_request *req), - TP_ARGS(req), - TP_STRUCT__entry( - __string(name, req->priv_ep->name) - __field(struct cdns3_request *, req) - __field(void *, buf) - __field(unsigned int, actual) - __field(unsigned int, length) - __field(int, status) - __field(int, zero) - __field(int, short_not_ok) - __field(int, no_interrupt) - __field(int, start_trb) - __field(int, end_trb) - __field(struct cdns3_trb *, start_trb_addr) - __field(int, flags) - ), - TP_fast_assign( - __assign_str(name, req->priv_ep->name); - __entry->req = req; - __entry->buf = req->request.buf; - __entry->actual = req->request.actual; - __entry->length = req->request.length; - __entry->status = req->request.status; - __entry->zero = req->request.zero; - __entry->short_not_ok = req->request.short_not_ok; - __entry->no_interrupt = req->request.no_interrupt; - __entry->start_trb = req->start_trb; - __entry->end_trb = req->end_trb; - __entry->start_trb_addr = req->trb; - __entry->flags = req->flags; - ), - TP_printk("%s: req: %p, req buff %p, length: %u/%u %s%s%s, status: %d," - " trb: [start:%d, end:%d: virt addr %pa], flags:%x ", - __get_str(name), __entry->req, __entry->buf, __entry->actual, - __entry->length, - __entry->zero ? "zero | " : "", - __entry->short_not_ok ? "short | " : "", - __entry->no_interrupt ? "no int" : "", - __entry->status, - __entry->start_trb, - __entry->end_trb, - __entry->start_trb_addr, - __entry->flags - ) -); - -DEFINE_EVENT(cdns3_log_request, cdns3_alloc_request, - TP_PROTO(struct cdns3_request *req), - TP_ARGS(req) -); - -DEFINE_EVENT(cdns3_log_request, cdns3_free_request, - TP_PROTO(struct cdns3_request *req), - TP_ARGS(req) -); - -DEFINE_EVENT(cdns3_log_request, cdns3_ep_queue, - TP_PROTO(struct cdns3_request *req), - TP_ARGS(req) -); - -DEFINE_EVENT(cdns3_log_request, cdns3_ep_dequeue, - TP_PROTO(struct cdns3_request *req), - TP_ARGS(req) -); - -DEFINE_EVENT(cdns3_log_request, cdns3_gadget_giveback, - TP_PROTO(struct cdns3_request *req), - TP_ARGS(req) -); - -DECLARE_EVENT_CLASS(cdns3_log_aligned_request, - TP_PROTO(struct cdns3_request *priv_req), - TP_ARGS(priv_req), - TP_STRUCT__entry( - __string(name, priv_req->priv_ep->name) - __field(struct usb_request *, req) - __field(void *, buf) - __field(dma_addr_t, dma) - __field(void *, aligned_buf) - __field(dma_addr_t, aligned_dma) - __field(u32, aligned_buf_size) - ), - TP_fast_assign( - __assign_str(name, priv_req->priv_ep->name); - __entry->req = &priv_req->request; - __entry->buf = priv_req->request.buf; - __entry->dma = priv_req->request.dma; - __entry->aligned_buf = priv_req->aligned_buf->buf; - __entry->aligned_dma = priv_req->aligned_buf->dma; - __entry->aligned_buf_size = priv_req->aligned_buf->size; - ), - TP_printk("%s: req: %p, req buf %p, dma %pad a_buf %p a_dma %pad, size %d", - __get_str(name), __entry->req, __entry->buf, &__entry->dma, - __entry->aligned_buf, &__entry->aligned_dma, - __entry->aligned_buf_size - ) -); - -DEFINE_EVENT(cdns3_log_aligned_request, cdns3_free_aligned_request, - TP_PROTO(struct cdns3_request *req), - TP_ARGS(req) -); - -DEFINE_EVENT(cdns3_log_aligned_request, cdns3_prepare_aligned_request, - TP_PROTO(struct cdns3_request *req), - TP_ARGS(req) -); - -DECLARE_EVENT_CLASS(cdns3_log_trb, - TP_PROTO(struct cdns3_endpoint *priv_ep, struct cdns3_trb *trb), - TP_ARGS(priv_ep, trb), - TP_STRUCT__entry( - __string(name, priv_ep->name) - __field(struct cdns3_trb *, trb) - __field(u32, buffer) - __field(u32, length) - __field(u32, control) - __field(u32, type) - ), - TP_fast_assign( - __assign_str(name, priv_ep->name); - __entry->trb = trb; - __entry->buffer = trb->buffer; - __entry->length = trb->length; - __entry->control = trb->control; - __entry->type = usb_endpoint_type(priv_ep->endpoint.desc); - ), - TP_printk("%s: trb %p, dma buf: 0x%08x, size: %ld, burst: %d ctrl: 0x%08x (%s%s%s%s%s%s%s)", - __get_str(name), __entry->trb, __entry->buffer, - TRB_LEN(__entry->length), - (u8)TRB_BURST_LEN_GET(__entry->length), - __entry->control, - __entry->control & TRB_CYCLE ? "C=1, " : "C=0, ", - __entry->control & TRB_TOGGLE ? "T=1, " : "T=0, ", - __entry->control & TRB_ISP ? "ISP, " : "", - __entry->control & TRB_FIFO_MODE ? "FIFO, " : "", - __entry->control & TRB_CHAIN ? "CHAIN, " : "", - __entry->control & TRB_IOC ? "IOC, " : "", - TRB_FIELD_TO_TYPE(__entry->control) == TRB_NORMAL ? "Normal" : "LINK" - ) -); - -DEFINE_EVENT(cdns3_log_trb, cdns3_prepare_trb, - TP_PROTO(struct cdns3_endpoint *priv_ep, struct cdns3_trb *trb), - TP_ARGS(priv_ep, trb) -); - -DEFINE_EVENT(cdns3_log_trb, cdns3_complete_trb, - TP_PROTO(struct cdns3_endpoint *priv_ep, struct cdns3_trb *trb), - TP_ARGS(priv_ep, trb) -); - -DECLARE_EVENT_CLASS(cdns3_log_ring, - TP_PROTO(struct cdns3_endpoint *priv_ep), - TP_ARGS(priv_ep), - TP_STRUCT__entry( - __dynamic_array(u8, ring, TRB_RING_SIZE) - __dynamic_array(u8, priv_ep, sizeof(struct cdns3_endpoint)) - __dynamic_array(char, buffer, - (TRBS_PER_SEGMENT * 65) + CDNS3_MSG_MAX) - ), - TP_fast_assign( - memcpy(__get_dynamic_array(priv_ep), priv_ep, - sizeof(struct cdns3_endpoint)); - memcpy(__get_dynamic_array(ring), priv_ep->trb_pool, - TRB_RING_SIZE); - ), - - TP_printk("%s", - cdns3_dbg_ring((struct cdns3_endpoint *)__get_str(priv_ep), - (struct cdns3_trb *)__get_str(ring), - __get_str(buffer))) -); - -DEFINE_EVENT(cdns3_log_ring, cdns3_ring, - TP_PROTO(struct cdns3_endpoint *priv_ep), - TP_ARGS(priv_ep) -); - -DECLARE_EVENT_CLASS(cdns3_log_ep, - TP_PROTO(struct cdns3_endpoint *priv_ep), - TP_ARGS(priv_ep), - TP_STRUCT__entry( - __string(name, priv_ep->name) - __field(unsigned int, maxpacket) - __field(unsigned int, maxpacket_limit) - __field(unsigned int, max_streams) - __field(unsigned int, maxburst) - __field(unsigned int, flags) - __field(unsigned int, dir) - __field(u8, enqueue) - __field(u8, dequeue) - ), - TP_fast_assign( - __assign_str(name, priv_ep->name); - __entry->maxpacket = priv_ep->endpoint.maxpacket; - __entry->maxpacket_limit = priv_ep->endpoint.maxpacket_limit; - __entry->max_streams = priv_ep->endpoint.max_streams; - __entry->maxburst = priv_ep->endpoint.maxburst; - __entry->flags = priv_ep->flags; - __entry->dir = priv_ep->dir; - __entry->enqueue = priv_ep->enqueue; - __entry->dequeue = priv_ep->dequeue; - ), - TP_printk("%s: mps: %d/%d. streams: %d, burst: %d, enq idx: %d, " - "deq idx: %d, flags %s%s%s%s%s%s%s%s, dir: %s", - __get_str(name), __entry->maxpacket, - __entry->maxpacket_limit, __entry->max_streams, - __entry->maxburst, __entry->enqueue, - __entry->dequeue, - __entry->flags & EP_ENABLED ? "EN | " : "", - __entry->flags & EP_STALL ? "STALL | " : "", - __entry->flags & EP_WEDGE ? "WEDGE | " : "", - __entry->flags & EP_TRANSFER_STARTED ? "STARTED | " : "", - __entry->flags & EP_UPDATE_EP_TRBADDR ? "UPD TRB | " : "", - __entry->flags & EP_PENDING_REQUEST ? "REQ PEN | " : "", - __entry->flags & EP_RING_FULL ? "RING FULL |" : "", - __entry->flags & EP_CLAIMED ? "CLAIMED " : "", - __entry->dir ? "IN" : "OUT" - ) -); - -DEFINE_EVENT(cdns3_log_ep, cdns3_gadget_ep_enable, - TP_PROTO(struct cdns3_endpoint *priv_ep), - TP_ARGS(priv_ep) -); - -DEFINE_EVENT(cdns3_log_ep, cdns3_gadget_ep_disable, - TP_PROTO(struct cdns3_endpoint *priv_ep), - TP_ARGS(priv_ep) -); - -DECLARE_EVENT_CLASS(cdns3_log_request_handled, - TP_PROTO(struct cdns3_request *priv_req, int current_index, - int handled), - TP_ARGS(priv_req, current_index, handled), - TP_STRUCT__entry( - __field(struct cdns3_request *, priv_req) - __field(unsigned int, dma_position) - __field(unsigned int, handled) - __field(unsigned int, dequeue_idx) - __field(unsigned int, enqueue_idx) - __field(unsigned int, start_trb) - __field(unsigned int, end_trb) - ), - TP_fast_assign( - __entry->priv_req = priv_req; - __entry->dma_position = current_index; - __entry->handled = handled; - __entry->dequeue_idx = priv_req->priv_ep->dequeue; - __entry->enqueue_idx = priv_req->priv_ep->enqueue; - __entry->start_trb = priv_req->start_trb; - __entry->end_trb = priv_req->end_trb; - ), - TP_printk("Req: %p %s, DMA pos: %d, ep deq: %d, ep enq: %d," - " start trb: %d, end trb: %d", - __entry->priv_req, - __entry->handled ? "handled" : "not handled", - __entry->dma_position, __entry->dequeue_idx, - __entry->enqueue_idx, __entry->start_trb, - __entry->end_trb - ) -); - -DEFINE_EVENT(cdns3_log_request_handled, cdns3_request_handled, - TP_PROTO(struct cdns3_request *priv_req, int current_index, - int handled), - TP_ARGS(priv_req, current_index, handled) -); -#endif /* __LINUX_CDNS3_TRACE */ - -/* this part must be outside header guard */ - -#undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . - -#undef TRACE_INCLUDE_FILE -#define TRACE_INCLUDE_FILE trace - -#include -- cgit v1.2.3 From 40abbef1c9af849fcdd23a7061b3f9a29067067b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 4 Jul 2019 13:01:48 +0200 Subject: Revert "usb:gadget Simplify usb_decode_get_set_descriptor function." This reverts commit c2af6b07803ebd099950cd608f404a7bff9037b2. It's broken. Reported-by: Stephen Rothwell Cc: Felipe Balbi Cc: Pawel Laszczak Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/debug.c | 113 ++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 58 deletions(-) diff --git a/drivers/usb/gadget/debug.c b/drivers/usb/gadget/debug.c index 92a986aeaa5d..60a9f70a0904 100644 --- a/drivers/usb/gadget/debug.c +++ b/drivers/usb/gadget/debug.c @@ -105,65 +105,62 @@ static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength, char *str, size_t size) { - char *s; - - switch (wValue >> 8) { - case USB_DT_DEVICE: - s = "Device"; - break; - case USB_DT_CONFIG: - s = "Configuration"; - break; - case USB_DT_STRING: - s = "String"; - break; - case USB_DT_INTERFACE: - s = "Interface"; - break; - case USB_DT_ENDPOINT: - s = "Endpoint"; - break; - case USB_DT_DEVICE_QUALIFIER: - s = "Device Qualifier"; - break; - case USB_DT_OTHER_SPEED_CONFIG: - s = "Other Speed Config"; - break; - case USB_DT_INTERFACE_POWER: - s = "Interface Power"; - break; - case USB_DT_OTG: - s = "OTG"; - break; - case USB_DT_DEBUG: - s = "Debug"; - break; - case USB_DT_INTERFACE_ASSOCIATION: - s = "Interface Association"; - break; - case USB_DT_BOS: - s = "BOS"; - break; - case USB_DT_DEVICE_CAPABILITY: - s = "Device Capability"; - break; - case USB_DT_PIPE_USAGE: - s = "Pipe Usage"; - break; - case USB_DT_SS_ENDPOINT_COMP: - s = "SS Endpoint Companion"; - break; - case USB_DT_SSP_ISOC_ENDPOINT_COMP: - s = "SSP Isochronous Endpoint Companion"; - break; - default: - s = "UNKNOWN"; - break; - } - snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)", - bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", - s, wValue & 0xff, wLength); + bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", + ({ char *s; + switch (wValue >> 8) { + case USB_DT_DEVICE: + s = "Device"; + break; + case USB_DT_CONFIG: + s = "Configuration"; + break; + case USB_DT_STRING: + s = "String"; + break; + case USB_DT_INTERFACE: + s = "Interface"; + break; + case USB_DT_ENDPOINT: + s = "Endpoint"; + break; + case USB_DT_DEVICE_QUALIFIER: + s = "Device Qualifier"; + break; + case USB_DT_OTHER_SPEED_CONFIG: + s = "Other Speed Config"; + break; + case USB_DT_INTERFACE_POWER: + s = "Interface Power"; + break; + case USB_DT_OTG: + s = "OTG"; + break; + case USB_DT_DEBUG: + s = "Debug"; + break; + case USB_DT_INTERFACE_ASSOCIATION: + s = "Interface Association"; + break; + case USB_DT_BOS: + s = "BOS"; + break; + case USB_DT_DEVICE_CAPABILITY: + s = "Device Capability"; + break; + case USB_DT_PIPE_USAGE: + s = "Pipe Usage"; + break; + case USB_DT_SS_ENDPOINT_COMP: + s = "SS Endpoint Companion"; + break; + case USB_DT_SSP_ISOC_ENDPOINT_COMP: + s = "SSP Isochronous Endpoint Companion"; + break; + default: + s = "UNKNOWN"; + break; + } s; }), wValue & 0xff, wLength); } static void usb_decode_get_configuration(__u16 wLength, char *str, size_t size) -- cgit v1.2.3 From 8265fb7c2559a4d245fed095b6af97bd8629d233 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 4 Jul 2019 13:02:00 +0200 Subject: Revert "usb:gadget Patch simplify usb_decode_set_clear_feature function." This reverts commit ca888ce7495e4e1578c86c37b0c82f6709da477c. It's broken. Reported-by: Stephen Rothwell Cc: Felipe Balbi Cc: Pawel Laszczak Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/debug.c | 89 ++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/drivers/usb/gadget/debug.c b/drivers/usb/gadget/debug.c index 60a9f70a0904..d5a469bc67a3 100644 --- a/drivers/usb/gadget/debug.c +++ b/drivers/usb/gadget/debug.c @@ -30,55 +30,58 @@ static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, } } -static const char *usb_decode_device_feature(u16 wValue) -{ - switch (wValue) { - case USB_DEVICE_SELF_POWERED: - return "Self Powered"; - case USB_DEVICE_REMOTE_WAKEUP: - return "Remote Wakeup"; - case USB_DEVICE_TEST_MODE: - return "Test Mode"; - case USB_DEVICE_U1_ENABLE: - return "U1 Enable"; - case USB_DEVICE_U2_ENABLE: - return "U2 Enable"; - case USB_DEVICE_LTM_ENABLE: - return "LTM Enable"; - default: - return "UNKNOWN"; - } -} - -static const char *usb_decode_test_mode(u16 wIndex) -{ - switch (wIndex) { - case TEST_J: - return ": TEST_J"; - case TEST_K: - return ": TEST_K"; - case TEST_SE0_NAK: - return ": TEST_SE0_NAK"; - case TEST_PACKET: - return ": TEST_PACKET"; - case TEST_FORCE_EN: - return ": TEST_FORCE_EN"; - default: - return ": UNKNOWN"; - } -} - -static void usb_decode_set_clear_feature(__u8 bRequestType, - __u8 bRequest, __u16 wValue, - __u16 wIndex, char *str, size_t size) +static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, + __u16 wValue, __u16 wIndex, + char *str, size_t size) { switch (bRequestType & USB_RECIP_MASK) { case USB_RECIP_DEVICE: snprintf(str, size, "%s Device Feature(%s%s)", bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", - usb_decode_device_feature(wValue), + ({char *s; + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + s = "Self Powered"; + break; + case USB_DEVICE_REMOTE_WAKEUP: + s = "Remote Wakeup"; + break; + case USB_DEVICE_TEST_MODE: + s = "Test Mode"; + break; + case USB_DEVICE_U1_ENABLE: + s = "U1 Enable"; + break; + case USB_DEVICE_U2_ENABLE: + s = "U2 Enable"; + break; + case USB_DEVICE_LTM_ENABLE: + s = "LTM Enable"; + break; + default: + s = "UNKNOWN"; + } s; }), wValue == USB_DEVICE_TEST_MODE ? - usb_decode_test_mode(wIndex) : ""); + ({ char *s; + switch (wIndex) { + case TEST_J: + s = ": TEST_J"; + break; + case TEST_K: + s = ": TEST_K"; + break; + case TEST_SE0_NAK: + s = ": TEST_SE0_NAK"; + break; + case TEST_PACKET: + s = ": TEST_PACKET"; + break; + case TEST_FORCE_EN: + s = ": TEST_FORCE_EN"; + break; + default: + s = ": UNKNOWN"; + } s; }) : ""); break; case USB_RECIP_INTERFACE: snprintf(str, size, "%s Interface Feature(%s)", -- cgit v1.2.3 From 332694f8a4f7e49b8b7278734d0ce331f954b20e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 4 Jul 2019 13:02:09 +0200 Subject: Revert "usb:gadget Separated decoding functions from dwc3 driver." This reverts commit 3db1b636c07e15ff7410db782832dc2e7ffd2bce. It's broken. Reported-by: Stephen Rothwell Cc: Felipe Balbi Cc: Pawel Laszczak Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/debug.h | 252 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/dwc3/trace.h | 2 +- drivers/usb/gadget/Makefile | 1 - drivers/usb/gadget/debug.c | 268 -------------------------------------------- include/linux/usb/gadget.h | 26 ----- 5 files changed, 253 insertions(+), 296 deletions(-) delete mode 100644 drivers/usb/gadget/debug.c diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h index 9baabed87d61..068259fdfb0c 100644 --- a/drivers/usb/dwc3/debug.h +++ b/drivers/usb/dwc3/debug.h @@ -246,6 +246,258 @@ static inline const char *dwc3_gadget_event_string(char *str, size_t size, return str; } +static inline void dwc3_decode_get_status(__u8 t, __u16 i, __u16 l, char *str, + size_t size) +{ + switch (t & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + snprintf(str, size, "Get Device Status(Length = %d)", l); + break; + case USB_RECIP_INTERFACE: + snprintf(str, size, "Get Interface Status(Intf = %d, Length = %d)", + i, l); + break; + case USB_RECIP_ENDPOINT: + snprintf(str, size, "Get Endpoint Status(ep%d%s)", + i & ~USB_DIR_IN, + i & USB_DIR_IN ? "in" : "out"); + break; + } +} + +static inline void dwc3_decode_set_clear_feature(__u8 t, __u8 b, __u16 v, + __u16 i, char *str, size_t size) +{ + switch (t & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + snprintf(str, size, "%s Device Feature(%s%s)", + b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", + ({char *s; + switch (v) { + case USB_DEVICE_SELF_POWERED: + s = "Self Powered"; + break; + case USB_DEVICE_REMOTE_WAKEUP: + s = "Remote Wakeup"; + break; + case USB_DEVICE_TEST_MODE: + s = "Test Mode"; + break; + case USB_DEVICE_U1_ENABLE: + s = "U1 Enable"; + break; + case USB_DEVICE_U2_ENABLE: + s = "U2 Enable"; + break; + case USB_DEVICE_LTM_ENABLE: + s = "LTM Enable"; + break; + default: + s = "UNKNOWN"; + } s; }), + v == USB_DEVICE_TEST_MODE ? + ({ char *s; + switch (i) { + case TEST_J: + s = ": TEST_J"; + break; + case TEST_K: + s = ": TEST_K"; + break; + case TEST_SE0_NAK: + s = ": TEST_SE0_NAK"; + break; + case TEST_PACKET: + s = ": TEST_PACKET"; + break; + case TEST_FORCE_EN: + s = ": TEST_FORCE_EN"; + break; + default: + s = ": UNKNOWN"; + } s; }) : ""); + break; + case USB_RECIP_INTERFACE: + snprintf(str, size, "%s Interface Feature(%s)", + b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", + v == USB_INTRF_FUNC_SUSPEND ? + "Function Suspend" : "UNKNOWN"); + break; + case USB_RECIP_ENDPOINT: + snprintf(str, size, "%s Endpoint Feature(%s ep%d%s)", + b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", + v == USB_ENDPOINT_HALT ? "Halt" : "UNKNOWN", + i & ~USB_DIR_IN, + i & USB_DIR_IN ? "in" : "out"); + break; + } +} + +static inline void dwc3_decode_set_address(__u16 v, char *str, size_t size) +{ + snprintf(str, size, "Set Address(Addr = %02x)", v); +} + +static inline void dwc3_decode_get_set_descriptor(__u8 t, __u8 b, __u16 v, + __u16 i, __u16 l, char *str, size_t size) +{ + snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)", + b == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", + ({ char *s; + switch (v >> 8) { + case USB_DT_DEVICE: + s = "Device"; + break; + case USB_DT_CONFIG: + s = "Configuration"; + break; + case USB_DT_STRING: + s = "String"; + break; + case USB_DT_INTERFACE: + s = "Interface"; + break; + case USB_DT_ENDPOINT: + s = "Endpoint"; + break; + case USB_DT_DEVICE_QUALIFIER: + s = "Device Qualifier"; + break; + case USB_DT_OTHER_SPEED_CONFIG: + s = "Other Speed Config"; + break; + case USB_DT_INTERFACE_POWER: + s = "Interface Power"; + break; + case USB_DT_OTG: + s = "OTG"; + break; + case USB_DT_DEBUG: + s = "Debug"; + break; + case USB_DT_INTERFACE_ASSOCIATION: + s = "Interface Association"; + break; + case USB_DT_BOS: + s = "BOS"; + break; + case USB_DT_DEVICE_CAPABILITY: + s = "Device Capability"; + break; + case USB_DT_PIPE_USAGE: + s = "Pipe Usage"; + break; + case USB_DT_SS_ENDPOINT_COMP: + s = "SS Endpoint Companion"; + break; + case USB_DT_SSP_ISOC_ENDPOINT_COMP: + s = "SSP Isochronous Endpoint Companion"; + break; + default: + s = "UNKNOWN"; + break; + } s; }), v & 0xff, l); +} + + +static inline void dwc3_decode_get_configuration(__u16 l, char *str, + size_t size) +{ + snprintf(str, size, "Get Configuration(Length = %d)", l); +} + +static inline void dwc3_decode_set_configuration(__u8 v, char *str, size_t size) +{ + snprintf(str, size, "Set Configuration(Config = %d)", v); +} + +static inline void dwc3_decode_get_intf(__u16 i, __u16 l, char *str, + size_t size) +{ + snprintf(str, size, "Get Interface(Intf = %d, Length = %d)", i, l); +} + +static inline void dwc3_decode_set_intf(__u8 v, __u16 i, char *str, size_t size) +{ + snprintf(str, size, "Set Interface(Intf = %d, Alt.Setting = %d)", i, v); +} + +static inline void dwc3_decode_synch_frame(__u16 i, __u16 l, char *str, + size_t size) +{ + snprintf(str, size, "Synch Frame(Endpoint = %d, Length = %d)", i, l); +} + +static inline void dwc3_decode_set_sel(__u16 l, char *str, size_t size) +{ + snprintf(str, size, "Set SEL(Length = %d)", l); +} + +static inline void dwc3_decode_set_isoch_delay(__u8 v, char *str, size_t size) +{ + snprintf(str, size, "Set Isochronous Delay(Delay = %d ns)", v); +} + +/** + * dwc3_decode_ctrl - returns a string represetion of ctrl request + */ +static inline const char *dwc3_decode_ctrl(char *str, size_t size, + __u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, + __u16 wLength) +{ + switch (bRequest) { + case USB_REQ_GET_STATUS: + dwc3_decode_get_status(bRequestType, wIndex, wLength, str, + size); + break; + case USB_REQ_CLEAR_FEATURE: + case USB_REQ_SET_FEATURE: + dwc3_decode_set_clear_feature(bRequestType, bRequest, wValue, + wIndex, str, size); + break; + case USB_REQ_SET_ADDRESS: + dwc3_decode_set_address(wValue, str, size); + break; + case USB_REQ_GET_DESCRIPTOR: + case USB_REQ_SET_DESCRIPTOR: + dwc3_decode_get_set_descriptor(bRequestType, bRequest, wValue, + wIndex, wLength, str, size); + break; + case USB_REQ_GET_CONFIGURATION: + dwc3_decode_get_configuration(wLength, str, size); + break; + case USB_REQ_SET_CONFIGURATION: + dwc3_decode_set_configuration(wValue, str, size); + break; + case USB_REQ_GET_INTERFACE: + dwc3_decode_get_intf(wIndex, wLength, str, size); + break; + case USB_REQ_SET_INTERFACE: + dwc3_decode_set_intf(wValue, wIndex, str, size); + break; + case USB_REQ_SYNCH_FRAME: + dwc3_decode_synch_frame(wIndex, wLength, str, size); + break; + case USB_REQ_SET_SEL: + dwc3_decode_set_sel(wLength, str, size); + break; + case USB_REQ_SET_ISOCH_DELAY: + dwc3_decode_set_isoch_delay(wValue, str, size); + break; + default: + snprintf(str, size, "%02x %02x %02x %02x %02x %02x %02x %02x", + bRequestType, bRequest, + cpu_to_le16(wValue) & 0xff, + cpu_to_le16(wValue) >> 8, + cpu_to_le16(wIndex) & 0xff, + cpu_to_le16(wIndex) >> 8, + cpu_to_le16(wLength) & 0xff, + cpu_to_le16(wLength) >> 8); + } + + return str; +} + /** * dwc3_ep_event_string - returns event name * @event: then event code diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h index 9edff17111f7..818a63da1a44 100644 --- a/drivers/usb/dwc3/trace.h +++ b/drivers/usb/dwc3/trace.h @@ -86,7 +86,7 @@ DECLARE_EVENT_CLASS(dwc3_log_ctrl, __entry->wIndex = le16_to_cpu(ctrl->wIndex); __entry->wLength = le16_to_cpu(ctrl->wLength); ), - TP_printk("%s", usb_decode_ctrl(__get_str(str), DWC3_MSG_MAX, + TP_printk("%s", dwc3_decode_ctrl(__get_str(str), DWC3_MSG_MAX, __entry->bRequestType, __entry->bRequest, __entry->wValue, __entry->wIndex, __entry->wLength) diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 500a5a592abe..130dad7130b6 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -9,6 +9,5 @@ ccflags-y += -I$(srctree)/drivers/usb/gadget/udc obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o libcomposite-y := usbstring.o config.o epautoconf.o libcomposite-y += composite.o functions.o configfs.o u_f.o -libcomposite-y += debug.o obj-$(CONFIG_USB_GADGET) += udc/ function/ legacy/ diff --git a/drivers/usb/gadget/debug.c b/drivers/usb/gadget/debug.c deleted file mode 100644 index d5a469bc67a3..000000000000 --- a/drivers/usb/gadget/debug.c +++ /dev/null @@ -1,268 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/** - * Common USB debugging functions - * - * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com - * - * Authors: Felipe Balbi , - * Sebastian Andrzej Siewior - */ - -#include - -static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, - __u16 wLength, char *str, size_t size) -{ - switch (bRequestType & USB_RECIP_MASK) { - case USB_RECIP_DEVICE: - snprintf(str, size, "Get Device Status(Length = %d)", wLength); - break; - case USB_RECIP_INTERFACE: - snprintf(str, size, - "Get Interface Status(Intf = %d, Length = %d)", - wIndex, wLength); - break; - case USB_RECIP_ENDPOINT: - snprintf(str, size, "Get Endpoint Status(ep%d%s)", - wIndex & ~USB_DIR_IN, - wIndex & USB_DIR_IN ? "in" : "out"); - break; - } -} - -static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, - __u16 wValue, __u16 wIndex, - char *str, size_t size) -{ - switch (bRequestType & USB_RECIP_MASK) { - case USB_RECIP_DEVICE: - snprintf(str, size, "%s Device Feature(%s%s)", - bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", - ({char *s; - switch (wValue) { - case USB_DEVICE_SELF_POWERED: - s = "Self Powered"; - break; - case USB_DEVICE_REMOTE_WAKEUP: - s = "Remote Wakeup"; - break; - case USB_DEVICE_TEST_MODE: - s = "Test Mode"; - break; - case USB_DEVICE_U1_ENABLE: - s = "U1 Enable"; - break; - case USB_DEVICE_U2_ENABLE: - s = "U2 Enable"; - break; - case USB_DEVICE_LTM_ENABLE: - s = "LTM Enable"; - break; - default: - s = "UNKNOWN"; - } s; }), - wValue == USB_DEVICE_TEST_MODE ? - ({ char *s; - switch (wIndex) { - case TEST_J: - s = ": TEST_J"; - break; - case TEST_K: - s = ": TEST_K"; - break; - case TEST_SE0_NAK: - s = ": TEST_SE0_NAK"; - break; - case TEST_PACKET: - s = ": TEST_PACKET"; - break; - case TEST_FORCE_EN: - s = ": TEST_FORCE_EN"; - break; - default: - s = ": UNKNOWN"; - } s; }) : ""); - break; - case USB_RECIP_INTERFACE: - snprintf(str, size, "%s Interface Feature(%s)", - bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", - wValue == USB_INTRF_FUNC_SUSPEND ? - "Function Suspend" : "UNKNOWN"); - break; - case USB_RECIP_ENDPOINT: - snprintf(str, size, "%s Endpoint Feature(%s ep%d%s)", - bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", - wValue == USB_ENDPOINT_HALT ? "Halt" : "UNKNOWN", - wIndex & ~USB_DIR_IN, - wIndex & USB_DIR_IN ? "in" : "out"); - break; - } -} - -static void usb_decode_set_address(__u16 wValue, char *str, size_t size) -{ - snprintf(str, size, "Set Address(Addr = %02x)", wValue); -} - -static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, - __u16 wValue, __u16 wIndex, - __u16 wLength, char *str, size_t size) -{ - snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)", - bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", - ({ char *s; - switch (wValue >> 8) { - case USB_DT_DEVICE: - s = "Device"; - break; - case USB_DT_CONFIG: - s = "Configuration"; - break; - case USB_DT_STRING: - s = "String"; - break; - case USB_DT_INTERFACE: - s = "Interface"; - break; - case USB_DT_ENDPOINT: - s = "Endpoint"; - break; - case USB_DT_DEVICE_QUALIFIER: - s = "Device Qualifier"; - break; - case USB_DT_OTHER_SPEED_CONFIG: - s = "Other Speed Config"; - break; - case USB_DT_INTERFACE_POWER: - s = "Interface Power"; - break; - case USB_DT_OTG: - s = "OTG"; - break; - case USB_DT_DEBUG: - s = "Debug"; - break; - case USB_DT_INTERFACE_ASSOCIATION: - s = "Interface Association"; - break; - case USB_DT_BOS: - s = "BOS"; - break; - case USB_DT_DEVICE_CAPABILITY: - s = "Device Capability"; - break; - case USB_DT_PIPE_USAGE: - s = "Pipe Usage"; - break; - case USB_DT_SS_ENDPOINT_COMP: - s = "SS Endpoint Companion"; - break; - case USB_DT_SSP_ISOC_ENDPOINT_COMP: - s = "SSP Isochronous Endpoint Companion"; - break; - default: - s = "UNKNOWN"; - break; - } s; }), wValue & 0xff, wLength); -} - -static void usb_decode_get_configuration(__u16 wLength, char *str, size_t size) -{ - snprintf(str, size, "Get Configuration(Length = %d)", wLength); -} - -static void usb_decode_set_configuration(__u8 wValue, char *str, size_t size) -{ - snprintf(str, size, "Set Configuration(Config = %d)", wValue); -} - -static void usb_decode_get_intf(__u16 wIndex, __u16 wLength, char *str, - size_t size) -{ - snprintf(str, size, "Get Interface(Intf = %d, Length = %d)", - wIndex, wLength); -} - -static void usb_decode_set_intf(__u8 wValue, __u16 wIndex, char *str, - size_t size) -{ - snprintf(str, size, "Set Interface(Intf = %d, Alt.Setting = %d)", - wIndex, wValue); -} - -static void usb_decode_synch_frame(__u16 wIndex, __u16 wLength, - char *str, size_t size) -{ - snprintf(str, size, "Synch Frame(Endpoint = %d, Length = %d)", - wIndex, wLength); -} - -static void usb_decode_set_sel(__u16 wLength, char *str, size_t size) -{ - snprintf(str, size, "Set SEL(Length = %d)", wLength); -} - -static void usb_decode_set_isoch_delay(__u8 wValue, char *str, size_t size) -{ - snprintf(str, size, "Set Isochronous Delay(Delay = %d ns)", wValue); -} - -/** - * usb_decode_ctrl - returns a string representation of ctrl request - */ -const char *usb_decode_ctrl(char *str, size_t size, __u8 bRequestType, - __u8 bRequest, __u16 wValue, __u16 wIndex, - __u16 wLength) -{ - switch (bRequest) { - case USB_REQ_GET_STATUS: - usb_decode_get_status(bRequestType, wIndex, wLength, str, size); - break; - case USB_REQ_CLEAR_FEATURE: - case USB_REQ_SET_FEATURE: - usb_decode_set_clear_feature(bRequestType, bRequest, wValue, - wIndex, str, size); - break; - case USB_REQ_SET_ADDRESS: - usb_decode_set_address(wValue, str, size); - break; - case USB_REQ_GET_DESCRIPTOR: - case USB_REQ_SET_DESCRIPTOR: - usb_decode_get_set_descriptor(bRequestType, bRequest, wValue, - wIndex, wLength, str, size); - break; - case USB_REQ_GET_CONFIGURATION: - usb_decode_get_configuration(wLength, str, size); - break; - case USB_REQ_SET_CONFIGURATION: - usb_decode_set_configuration(wValue, str, size); - break; - case USB_REQ_GET_INTERFACE: - usb_decode_get_intf(wIndex, wLength, str, size); - break; - case USB_REQ_SET_INTERFACE: - usb_decode_set_intf(wValue, wIndex, str, size); - break; - case USB_REQ_SYNCH_FRAME: - usb_decode_synch_frame(wIndex, wLength, str, size); - break; - case USB_REQ_SET_SEL: - usb_decode_set_sel(wLength, str, size); - break; - case USB_REQ_SET_ISOCH_DELAY: - usb_decode_set_isoch_delay(wValue, str, size); - break; - default: - snprintf(str, size, "%02x %02x %02x %02x %02x %02x %02x %02x", - bRequestType, bRequest, - (u8)(cpu_to_le16(wValue) & 0xff), - (u8)(cpu_to_le16(wValue) >> 8), - (u8)(cpu_to_le16(wIndex) & 0xff), - (u8)(cpu_to_le16(wIndex) >> 8), - (u8)(cpu_to_le16(wLength) & 0xff), - (u8)(cpu_to_le16(wLength) >> 8)); - } - - return str; -} -EXPORT_SYMBOL_GPL(usb_decode_ctrl); diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 42902fcc8696..fb19141151d8 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -889,30 +889,4 @@ extern void usb_ep_autoconfig_release(struct usb_ep *); extern void usb_ep_autoconfig_reset(struct usb_gadget *); -/*-------------------------------------------------------------------------*/ -/** - * usb_decode_ctrl - Returns human readable representation of control request. - * @str: buffer to return a human-readable representation of control request. - * This buffer should have about 200 bytes. - * @size: size of str buffer. - * @bRequestType: matches the USB bmRequestType field - * @bRequest: matches the USB bRequest field - * @wValue: matches the USB wValue field (CPU byte order) - * @wIndex: matches the USB wIndex field (CPU byte order) - * @wLength: matches the USB wLength field (CPU byte order) - * - * Function returns decoded, formatted and human-readable description of - * control request packet. - * - * The usage scenario for this is for tracepoints, so function as a return - * use the same value as in parameters. This approach allows to use this - * function in TP_printk - * - * Important: wValue, wIndex, wLength parameters before invoking this function - * should be processed by le16_to_cpu macro. - */ -extern const char *usb_decode_ctrl(char *str, size_t size, __u8 bRequestType, - __u8 bRequest, __u16 wValue, __u16 wIndex, - __u16 wLength); - #endif /* __LINUX_USB_GADGET_H */ -- cgit v1.2.3 From 65d71f0095f611eb090bb9c1cca086a8967936e5 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 4 Jul 2019 13:02:18 +0200 Subject: Revert "dt-bindings: add binding for USBSS-DRD controller." This reverts commit e8a8b40cc8922b38f91c6562d525f21f312f235c. It's broken. Reported-by: Stephen Rothwell Cc: Felipe Balbi Cc: Pawel Laszczak Signed-off-by: Greg Kroah-Hartman --- .../devicetree/bindings/usb/cdns-usb3.txt | 45 ---------------------- 1 file changed, 45 deletions(-) delete mode 100644 Documentation/devicetree/bindings/usb/cdns-usb3.txt diff --git a/Documentation/devicetree/bindings/usb/cdns-usb3.txt b/Documentation/devicetree/bindings/usb/cdns-usb3.txt deleted file mode 100644 index b7dc606d37b5..000000000000 --- a/Documentation/devicetree/bindings/usb/cdns-usb3.txt +++ /dev/null @@ -1,45 +0,0 @@ -Binding for the Cadence USBSS-DRD controller - -Required properties: - - reg: Physical base address and size of the controller's register areas. - Controller has 3 different regions: - - HOST registers area - - DEVICE registers area - - OTG/DRD registers area - - reg-names - register memory area names: - "xhci" - for HOST registers space - "dev" - for DEVICE registers space - "otg" - for OTG/DRD registers space - - compatible: Should contain: "cdns,usb3" - - interrupts: Interrupts used by cdns3 controller: - "host" - interrupt used by XHCI driver. - "peripheral" - interrupt used by device driver - "otg" - interrupt used by DRD/OTG part of driver - -Optional properties: - - maximum-speed : valid arguments are "super-speed", "high-speed" and - "full-speed"; refer to usb/generic.txt - - dr_mode: Should be one of "host", "peripheral" or "otg". - - phys: reference to the USB PHY - - phy-names: from the *Generic PHY* bindings; - Supported names are: - - cdns3,usb2-phy - - cdns3,usb3-phy - - - cdns,on-chip-buff-size : size of memory intended as internal memory for endpoints - buffers expressed in KB - -Example: - usb@f3000000 { - compatible = "cdns,usb3"; - interrupts = , - , - ; - interrupt-names = "host", "peripheral", "otg"; - reg = <0xf3000000 0x10000>, /* memory area for HOST registers */ - <0xf3010000 0x10000>, /* memory area for DEVICE registers */ - <0xf3020000 0x10000>; /* memory area for OTG/DRD registers */ - reg-names = "xhci", "dev", "otg"; - phys = <&usb2_phy>, <&usb3_phy>; - phy-names = "cdns3,usb2-phy", "cnds3,usb3-phy"; - }; -- cgit v1.2.3 From 214cc39d175c89cafa5acfe4df22502e8d86c506 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 4 Jul 2019 13:05:59 +0200 Subject: Revert "usb: gadget: storage: Remove warning message" This reverts commit e70b3f5da00119e057b7faa557753fee7f786f17. EJ writes: Thinh found this patch might cause a failure in USB CV TD 9.13 Set Configuration Test. We are trying to fix it. Could you please defer the merging of this patch until we fix it? So am now dropping it. Reported-by: EJ Hsu Cc: Alan Stern Cc: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_mass_storage.c | 21 ++++++--------------- drivers/usb/gadget/function/storage_common.h | 1 - 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index b1fba3132427..29cc5693e05c 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -2293,7 +2293,8 @@ static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) static void fsg_disable(struct usb_function *f) { struct fsg_dev *fsg = fsg_from_func(f); - raise_exception(fsg->common, FSG_STATE_DISCONNECT); + fsg->common->new_fsg = NULL; + raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); } @@ -2306,7 +2307,6 @@ static void handle_exception(struct fsg_common *common) enum fsg_state old_state; struct fsg_lun *curlun; unsigned int exception_req_tag; - struct fsg_dev *fsg; /* * Clear the existing signals. Anything but SIGUSR1 is converted @@ -2413,19 +2413,9 @@ static void handle_exception(struct fsg_common *common) break; case FSG_STATE_CONFIG_CHANGE: - fsg = common->new_fsg; - /* - * Add a check here to double confirm if a disconnect event - * occurs and common->new_fsg has been cleared. - */ - if (fsg) { - do_set_interface(common, fsg); + do_set_interface(common, common->new_fsg); + if (common->new_fsg) usb_composite_setup_continue(common->cdev); - } - break; - - case FSG_STATE_DISCONNECT: - do_set_interface(common, NULL); break; case FSG_STATE_EXIT: @@ -2999,7 +2989,8 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) DBG(fsg, "unbind\n"); if (fsg->common->fsg == fsg) { - raise_exception(fsg->common, FSG_STATE_DISCONNECT); + fsg->common->new_fsg = NULL; + raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); /* FIXME: make interruptible or killable somehow? */ wait_event(common->fsg_wait, common->fsg != fsg); } diff --git a/drivers/usb/gadget/function/storage_common.h b/drivers/usb/gadget/function/storage_common.h index 12687f7e3de9..e5e3a2553aaa 100644 --- a/drivers/usb/gadget/function/storage_common.h +++ b/drivers/usb/gadget/function/storage_common.h @@ -161,7 +161,6 @@ enum fsg_state { FSG_STATE_ABORT_BULK_OUT, FSG_STATE_PROTOCOL_RESET, FSG_STATE_CONFIG_CHANGE, - FSG_STATE_DISCONNECT, FSG_STATE_EXIT, FSG_STATE_TERMINATED }; -- cgit v1.2.3