Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'usb-for-v3.14' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

Felipe writes:

usb: changes for v3.14 merge window

This pull request is quite extensive, containing
105 non-merge commits. Because of that, we describe
the changes in sections below:

New drivers:
- Keystone PHY driver and DWC3 Glue Layer
- Aeroflex Gaisler GRUSBDC
- Tahvo PHY driver for N770
- JZ4740 MUSB gluer Layer
- Broadcom PHY Driver

Important new features:
- MUSB DSPS learned about suspend/resume
- New quirk_ep_out_aligned_size flag added to struct usb_gadget
- DWC3 initializes the new quirk flag so gadget drivers can use it.
- AM335x PHY Driver learns about remote wakeup
- Renesas USBHS now requests DMA Engine only once
- s3c-hsotg is now re-used on Broadcom devices
- USB PHY layer now makes sure to initialize the notifier for all
drivers
- omap-control learned about TI's new AM437x devices
- few other usb gadget/function drivers learned about the new
configfs-based binding.

Misc Fixes and Clean Ups:
- Several sparse fixes all over the place
- Removal of redundant of_match_ptr()
- r-car gen2 phy now uses usb_add_phy_dev()
- removal of DEFINE_PCI_DEVICE_TABLE() from a few drivers
- conversion to clk_prepare/clk_unprepare on r8a66597-udc
- some randconfig errors and build warnings were fixed
- removal of unnecessary lock on dwc3-omap.c

Signed-of-by: Felipe Balbi <balbi@ti.com>

+6450 -1287
+9
Documentation/ABI/testing/configfs-usb-gadget-ffs
··· 1 + What: /config/usb-gadget/gadget/functions/ffs.name 2 + Date: Nov 2013 3 + KenelVersion: 3.13 4 + Description: The purpose of this directory is to create and remove it. 5 + 6 + A corresponding USB function instance is created/removed. 7 + There are no attributes here. 8 + 9 + All parameters are set through FunctionFS.
+8
Documentation/ABI/testing/configfs-usb-gadget-loopback
··· 1 + What: /config/usb-gadget/gadget/functions/Loopback.name 2 + Date: Nov 2013 3 + KenelVersion: 3.13 4 + Description: 5 + The attributes: 6 + 7 + qlen - depth of loopback queue 8 + bulk_buflen - buffer length
+12
Documentation/ABI/testing/configfs-usb-gadget-sourcesink
··· 1 + What: /config/usb-gadget/gadget/functions/SourceSink.name 2 + Date: Nov 2013 3 + KenelVersion: 3.13 4 + Description: 5 + The attributes: 6 + 7 + pattern - 0 (all zeros), 1 (mod63), 2 (none) 8 + isoc_interval - 1..16 9 + isoc_maxpacket - 0 - 1023 (fs), 0 - 1024 (hs/ss) 10 + isoc_mult - 0..2 (hs/ss only) 11 + isoc_maxburst - 0..15 (ss only) 12 + qlen - buffer length
+16
Documentation/ABI/testing/sysfs-platform-tahvo-usb
··· 1 + What: /sys/bus/platform/devices/tahvo-usb/otg_mode 2 + Date: December 2013 3 + Contact: Aaro Koskinen <aaro.koskinen@iki.fi> 4 + Description: 5 + Set or read the current OTG mode. Valid values are "host" and 6 + "peripheral". 7 + 8 + Reading: returns the current mode. 9 + 10 + What: /sys/bus/platform/devices/tahvo-usb/vbus 11 + Date: December 2013 12 + Contact: Aaro Koskinen <aaro.koskinen@iki.fi> 13 + Description: 14 + Read the current VBUS state. 15 + 16 + Reading: returns "on" or "off".
+15
Documentation/devicetree/bindings/phy/bcm-phy.txt
··· 1 + BROADCOM KONA USB2 PHY 2 + 3 + Required properties: 4 + - compatible: brcm,kona-usb2-phy 5 + - reg: offset and length of the PHY registers 6 + - #phy-cells: must be 0 7 + Refer to phy/phy-bindings.txt for the generic PHY binding properties 8 + 9 + Example: 10 + 11 + usbphy: usb-phy@3f130000 { 12 + compatible = "brcm,kona-usb2-phy"; 13 + reg = <0x3f130000 0x28>; 14 + #phy-cells = <0>; 15 + };
+12
Documentation/devicetree/bindings/staging/dwc2.txt
··· 5 5 - compatible : "snps,dwc2" 6 6 - reg : Should contain 1 register range (address and length) 7 7 - interrupts : Should contain 1 interrupt 8 + - clocks: clock provider specifier 9 + - clock-names: shall be "otg" 10 + Refer to clk/clock-bindings.txt for generic clock consumer properties 11 + 12 + Optional properties: 13 + - phys: phy provider specifier 14 + - phy-names: shall be "device" 15 + Refer to phy/phy-bindings.txt for generic phy consumer properties 8 16 9 17 Example: 10 18 ··· 20 12 compatible = "ralink,rt3050-usb, snps,dwc2"; 21 13 reg = <0x101c0000 40000>; 22 14 interrupts = <18>; 15 + clocks = <&usb_otg_ahb_clk>; 16 + clock-names = "otg"; 17 + phys = <&usbphy>; 18 + phy-names = "usb2-phy"; 23 19 };
+28
Documentation/devicetree/bindings/usb/gr-udc.txt
··· 1 + USB Peripheral Controller driver for Aeroflex Gaisler GRUSBDC. 2 + 3 + The GRUSBDC USB Device Controller core is available in the GRLIB VHDL 4 + IP core library. 5 + 6 + Note: In the ordinary environment for the core, a Leon SPARC system, 7 + these properties are built from information in the AMBA plug&play. 8 + 9 + Required properties: 10 + 11 + - name : Should be "GAISLER_USBDC" or "01_021" 12 + 13 + - reg : Address and length of the register set for the device 14 + 15 + - interrupts : Interrupt numbers for this device 16 + 17 + Optional properties: 18 + 19 + - epobufsizes : An array of buffer sizes for OUT endpoints. If the property is 20 + not present, or for endpoints outside of the array, 1024 is assumed by 21 + the driver. 22 + 23 + - epibufsizes : An array of buffer sizes for IN endpoints. If the property is 24 + not present, or for endpoints outside of the array, 1024 is assumed by 25 + the driver. 26 + 27 + For further information look in the documentation for the GLIB IP core library: 28 + http://www.gaisler.com/products/grlib/grip.pdf
+2
Documentation/devicetree/bindings/usb/omap-usb.txt
··· 87 87 e.g. USB3 PHY and SATA PHY on OMAP5. 88 88 "ti,control-phy-dra7usb2" - if it has power down register like USB2 PHY on 89 89 DRA7 platform. 90 + "ti,control-phy-am437usb2" - if it has power down register like USB2 PHY on 91 + AM437 platform. 90 92 - reg : Address and length of the register set for the device. It contains 91 93 the address of "otghs_control" for control-phy-otghs or "power" register 92 94 for other types.
+1 -37
arch/arm/mach-omap1/include/mach/usb.h
··· 8 8 #define is_usb0_device(config) 0 9 9 #endif 10 10 11 - struct omap_usb_config { 12 - /* Configure drivers according to the connectors on your board: 13 - * - "A" connector (rectagular) 14 - * ... for host/OHCI use, set "register_host". 15 - * - "B" connector (squarish) or "Mini-B" 16 - * ... for device/gadget use, set "register_dev". 17 - * - "Mini-AB" connector (very similar to Mini-B) 18 - * ... for OTG use as device OR host, initialize "otg" 19 - */ 20 - unsigned register_host:1; 21 - unsigned register_dev:1; 22 - u8 otg; /* port number, 1-based: usb1 == 2 */ 23 - 24 - u8 hmc_mode; 25 - 26 - /* implicitly true if otg: host supports remote wakeup? */ 27 - u8 rwc; 28 - 29 - /* signaling pins used to talk to transceiver on usbN: 30 - * 0 == usbN unused 31 - * 2 == usb0-only, using internal transceiver 32 - * 3 == 3 wire bidirectional 33 - * 4 == 4 wire bidirectional 34 - * 6 == 6 wire unidirectional (or TLL) 35 - */ 36 - u8 pins[3]; 37 - 38 - struct platform_device *udc_device; 39 - struct platform_device *ohci_device; 40 - struct platform_device *otg_device; 41 - 42 - u32 (*usb0_init)(unsigned nwires, unsigned is_device); 43 - u32 (*usb1_init)(unsigned nwires); 44 - u32 (*usb2_init)(unsigned nwires, unsigned alt_pingroup); 45 - 46 - int (*ocpi_enable)(void); 47 - }; 11 + #include <linux/platform_data/usb-omap1.h> 48 12 49 13 void omap_otg_init(struct omap_usb_config *config); 50 14
+6
drivers/phy/Kconfig
··· 51 51 help 52 52 Support for Display Port PHY found on Samsung EXYNOS SoCs. 53 53 54 + config BCM_KONA_USB2_PHY 55 + tristate "Broadcom Kona USB2 PHY Driver" 56 + depends on GENERIC_PHY 57 + help 58 + Enable this to support the Broadcom Kona USB 2.0 PHY. 59 + 54 60 endmenu
+1
drivers/phy/Makefile
··· 3 3 # 4 4 5 5 obj-$(CONFIG_GENERIC_PHY) += phy-core.o 6 + obj-$(CONFIG_BCM_KONA_USB2_PHY) += phy-bcm-kona-usb2.o 6 7 obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o 7 8 obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO) += phy-exynos-mipi-video.o 8 9 obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
+158
drivers/phy/phy-bcm-kona-usb2.c
··· 1 + /* 2 + * phy-bcm-kona-usb2.c - Broadcom Kona USB2 Phy Driver 3 + * 4 + * Copyright (C) 2013 Linaro Limited 5 + * Matt Porter <mporter@linaro.org> 6 + * 7 + * This software is licensed under the terms of the GNU General Public 8 + * License version 2, as published by the Free Software Foundation, and 9 + * may be copied, distributed, and modified under those terms. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + 17 + #include <linux/clk.h> 18 + #include <linux/delay.h> 19 + #include <linux/err.h> 20 + #include <linux/io.h> 21 + #include <linux/module.h> 22 + #include <linux/of.h> 23 + #include <linux/phy/phy.h> 24 + #include <linux/platform_device.h> 25 + 26 + #define OTGCTL (0) 27 + #define OTGCTL_OTGSTAT2 BIT(31) 28 + #define OTGCTL_OTGSTAT1 BIT(30) 29 + #define OTGCTL_PRST_N_SW BIT(11) 30 + #define OTGCTL_HRESET_N BIT(10) 31 + #define OTGCTL_UTMI_LINE_STATE1 BIT(9) 32 + #define OTGCTL_UTMI_LINE_STATE0 BIT(8) 33 + 34 + #define P1CTL (8) 35 + #define P1CTL_SOFT_RESET BIT(1) 36 + #define P1CTL_NON_DRIVING BIT(0) 37 + 38 + struct bcm_kona_usb { 39 + void __iomem *regs; 40 + }; 41 + 42 + static void bcm_kona_usb_phy_power(struct bcm_kona_usb *phy, int on) 43 + { 44 + u32 val; 45 + 46 + val = readl(phy->regs + OTGCTL); 47 + if (on) { 48 + /* Configure and power PHY */ 49 + val &= ~(OTGCTL_OTGSTAT2 | OTGCTL_OTGSTAT1 | 50 + OTGCTL_UTMI_LINE_STATE1 | OTGCTL_UTMI_LINE_STATE0); 51 + val |= OTGCTL_PRST_N_SW | OTGCTL_HRESET_N; 52 + } else { 53 + val &= ~(OTGCTL_PRST_N_SW | OTGCTL_HRESET_N); 54 + } 55 + writel(val, phy->regs + OTGCTL); 56 + } 57 + 58 + static int bcm_kona_usb_phy_init(struct phy *gphy) 59 + { 60 + struct bcm_kona_usb *phy = phy_get_drvdata(gphy); 61 + u32 val; 62 + 63 + /* Soft reset PHY */ 64 + val = readl(phy->regs + P1CTL); 65 + val &= ~P1CTL_NON_DRIVING; 66 + val |= P1CTL_SOFT_RESET; 67 + writel(val, phy->regs + P1CTL); 68 + writel(val & ~P1CTL_SOFT_RESET, phy->regs + P1CTL); 69 + /* Reset needs to be asserted for 2ms */ 70 + mdelay(2); 71 + writel(val | P1CTL_SOFT_RESET, phy->regs + P1CTL); 72 + 73 + return 0; 74 + } 75 + 76 + static int bcm_kona_usb_phy_power_on(struct phy *gphy) 77 + { 78 + struct bcm_kona_usb *phy = phy_get_drvdata(gphy); 79 + 80 + bcm_kona_usb_phy_power(phy, 1); 81 + 82 + return 0; 83 + } 84 + 85 + static int bcm_kona_usb_phy_power_off(struct phy *gphy) 86 + { 87 + struct bcm_kona_usb *phy = phy_get_drvdata(gphy); 88 + 89 + bcm_kona_usb_phy_power(phy, 0); 90 + 91 + return 0; 92 + } 93 + 94 + static struct phy_ops ops = { 95 + .init = bcm_kona_usb_phy_init, 96 + .power_on = bcm_kona_usb_phy_power_on, 97 + .power_off = bcm_kona_usb_phy_power_off, 98 + .owner = THIS_MODULE, 99 + }; 100 + 101 + static int bcm_kona_usb2_probe(struct platform_device *pdev) 102 + { 103 + struct device *dev = &pdev->dev; 104 + struct bcm_kona_usb *phy; 105 + struct resource *res; 106 + struct phy *gphy; 107 + struct phy_provider *phy_provider; 108 + 109 + phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); 110 + if (!phy) 111 + return -ENOMEM; 112 + 113 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 114 + phy->regs = devm_ioremap_resource(&pdev->dev, res); 115 + if (IS_ERR(phy->regs)) 116 + return PTR_ERR(phy->regs); 117 + 118 + platform_set_drvdata(pdev, phy); 119 + 120 + gphy = devm_phy_create(dev, &ops, NULL); 121 + if (IS_ERR(gphy)) 122 + return PTR_ERR(gphy); 123 + 124 + /* The Kona PHY supports an 8-bit wide UTMI interface */ 125 + phy_set_bus_width(gphy, 8); 126 + 127 + phy_set_drvdata(gphy, phy); 128 + 129 + phy_provider = devm_of_phy_provider_register(dev, 130 + of_phy_simple_xlate); 131 + if (IS_ERR(phy_provider)) 132 + return PTR_ERR(phy_provider); 133 + 134 + return 0; 135 + } 136 + 137 + static const struct of_device_id bcm_kona_usb2_dt_ids[] = { 138 + { .compatible = "brcm,kona-usb2-phy" }, 139 + { /* sentinel */ } 140 + }; 141 + 142 + MODULE_DEVICE_TABLE(of, bcm_kona_usb2_dt_ids); 143 + 144 + static struct platform_driver bcm_kona_usb2_driver = { 145 + .probe = bcm_kona_usb2_probe, 146 + .driver = { 147 + .name = "bcm-kona-usb2", 148 + .owner = THIS_MODULE, 149 + .of_match_table = bcm_kona_usb2_dt_ids, 150 + }, 151 + }; 152 + 153 + module_platform_driver(bcm_kona_usb2_driver); 154 + 155 + MODULE_ALIAS("platform:bcm-kona-usb2"); 156 + MODULE_AUTHOR("Matt Porter <mporter@linaro.org>"); 157 + MODULE_DESCRIPTION("BCM Kona USB 2.0 PHY driver"); 158 + MODULE_LICENSE("GPL v2");
+2 -2
drivers/usb/Kconfig
··· 94 94 95 95 source "drivers/usb/host/Kconfig" 96 96 97 - source "drivers/usb/musb/Kconfig" 98 - 99 97 source "drivers/usb/renesas_usbhs/Kconfig" 100 98 101 99 source "drivers/usb/class/Kconfig" ··· 103 105 source "drivers/usb/image/Kconfig" 104 106 105 107 endif 108 + 109 + source "drivers/usb/musb/Kconfig" 106 110 107 111 source "drivers/usb/dwc3/Kconfig" 108 112
+2 -2
drivers/usb/chipidea/udc.c
··· 1566 1566 * eps, maxP is set by epautoconfig() called 1567 1567 * by gadget layer 1568 1568 */ 1569 - hwep->ep.maxpacket = (unsigned short)~0; 1569 + usb_ep_set_maxpacket_limit(&hwep->ep, (unsigned short)~0); 1570 1570 1571 1571 INIT_LIST_HEAD(&hwep->qh.queue); 1572 1572 hwep->qh.ptr = dma_pool_alloc(ci->qh_pool, GFP_KERNEL, ··· 1586 1586 else 1587 1587 ci->ep0in = hwep; 1588 1588 1589 - hwep->ep.maxpacket = CTRL_PAYLOAD_MAX; 1589 + usb_ep_set_maxpacket_limit(&hwep->ep, CTRL_PAYLOAD_MAX); 1590 1590 continue; 1591 1591 } 1592 1592
+7
drivers/usb/dwc3/Kconfig
··· 70 70 One such PCIe-based platform is Synopsys' PCIe HAPS model of 71 71 this IP. 72 72 73 + config USB_DWC3_KEYSTONE 74 + tristate "Texas Instruments Keystone2 Platforms" 75 + default USB_DWC3 76 + help 77 + Support of USB2/3 functionality in TI Keystone2 platforms. 78 + Say 'Y' or 'M' here if you have one such device 79 + 73 80 comment "Debugging features" 74 81 75 82 config USB_DWC3_DEBUG
+1
drivers/usb/dwc3/Makefile
··· 32 32 obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o 33 33 obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o 34 34 obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o 35 + obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o
+1
drivers/usb/dwc3/dwc3-exynos.c
··· 50 50 51 51 exynos->usb2_phy = pdev; 52 52 pdata.type = USB_PHY_TYPE_USB2; 53 + pdata.gpio_reset = -1; 53 54 54 55 ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata)); 55 56 if (ret)
+202
drivers/usb/dwc3/dwc3-keystone.c
··· 1 + /** 2 + * dwc3-keystone.c - Keystone Specific Glue layer 3 + * 4 + * Copyright (C) 2010-2013 Texas Instruments Incorporated - http://www.ti.com 5 + * 6 + * Author: WingMan Kwok <w-kwok2@ti.com> 7 + * 8 + * This program is free software: you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 of 10 + * the License as published by the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/clk.h> 19 + #include <linux/module.h> 20 + #include <linux/kernel.h> 21 + #include <linux/interrupt.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/dma-mapping.h> 24 + #include <linux/io.h> 25 + #include <linux/of_platform.h> 26 + 27 + /* USBSS register offsets */ 28 + #define USBSS_REVISION 0x0000 29 + #define USBSS_SYSCONFIG 0x0010 30 + #define USBSS_IRQ_EOI 0x0018 31 + #define USBSS_IRQSTATUS_RAW_0 0x0020 32 + #define USBSS_IRQSTATUS_0 0x0024 33 + #define USBSS_IRQENABLE_SET_0 0x0028 34 + #define USBSS_IRQENABLE_CLR_0 0x002c 35 + 36 + /* IRQ register bits */ 37 + #define USBSS_IRQ_EOI_LINE(n) BIT(n) 38 + #define USBSS_IRQ_EVENT_ST BIT(0) 39 + #define USBSS_IRQ_COREIRQ_EN BIT(0) 40 + #define USBSS_IRQ_COREIRQ_CLR BIT(0) 41 + 42 + static u64 kdwc3_dma_mask; 43 + 44 + struct dwc3_keystone { 45 + struct device *dev; 46 + struct clk *clk; 47 + void __iomem *usbss; 48 + }; 49 + 50 + static inline u32 kdwc3_readl(void __iomem *base, u32 offset) 51 + { 52 + return readl(base + offset); 53 + } 54 + 55 + static inline void kdwc3_writel(void __iomem *base, u32 offset, u32 value) 56 + { 57 + writel(value, base + offset); 58 + } 59 + 60 + static void kdwc3_enable_irqs(struct dwc3_keystone *kdwc) 61 + { 62 + u32 val; 63 + 64 + val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0); 65 + val |= USBSS_IRQ_COREIRQ_EN; 66 + kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val); 67 + } 68 + 69 + static void kdwc3_disable_irqs(struct dwc3_keystone *kdwc) 70 + { 71 + u32 val; 72 + 73 + val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0); 74 + val &= ~USBSS_IRQ_COREIRQ_EN; 75 + kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val); 76 + } 77 + 78 + static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc) 79 + { 80 + struct dwc3_keystone *kdwc = _kdwc; 81 + 82 + kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_CLR_0, USBSS_IRQ_COREIRQ_CLR); 83 + kdwc3_writel(kdwc->usbss, USBSS_IRQSTATUS_0, USBSS_IRQ_EVENT_ST); 84 + kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, USBSS_IRQ_COREIRQ_EN); 85 + kdwc3_writel(kdwc->usbss, USBSS_IRQ_EOI, USBSS_IRQ_EOI_LINE(0)); 86 + 87 + return IRQ_HANDLED; 88 + } 89 + 90 + static int kdwc3_probe(struct platform_device *pdev) 91 + { 92 + struct device *dev = &pdev->dev; 93 + struct device_node *node = pdev->dev.of_node; 94 + struct dwc3_keystone *kdwc; 95 + struct resource *res; 96 + int error, irq; 97 + 98 + kdwc = devm_kzalloc(dev, sizeof(*kdwc), GFP_KERNEL); 99 + if (!kdwc) 100 + return -ENOMEM; 101 + 102 + platform_set_drvdata(pdev, kdwc); 103 + 104 + kdwc->dev = dev; 105 + 106 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 107 + if (!res) { 108 + dev_err(dev, "missing usbss resource\n"); 109 + return -EINVAL; 110 + } 111 + 112 + kdwc->usbss = devm_ioremap_resource(dev, res); 113 + if (IS_ERR(kdwc->usbss)) 114 + return PTR_ERR(kdwc->usbss); 115 + 116 + kdwc3_dma_mask = dma_get_mask(dev); 117 + dev->dma_mask = &kdwc3_dma_mask; 118 + 119 + kdwc->clk = devm_clk_get(kdwc->dev, "usb"); 120 + 121 + error = clk_prepare_enable(kdwc->clk); 122 + if (error < 0) { 123 + dev_dbg(kdwc->dev, "unable to enable usb clock, err %d\n", 124 + error); 125 + return error; 126 + } 127 + 128 + irq = platform_get_irq(pdev, 0); 129 + if (irq < 0) { 130 + dev_err(&pdev->dev, "missing irq\n"); 131 + goto err_irq; 132 + } 133 + 134 + error = devm_request_irq(dev, irq, dwc3_keystone_interrupt, IRQF_SHARED, 135 + dev_name(dev), kdwc); 136 + if (error) { 137 + dev_err(dev, "failed to request IRQ #%d --> %d\n", 138 + irq, error); 139 + goto err_irq; 140 + } 141 + 142 + kdwc3_enable_irqs(kdwc); 143 + 144 + error = of_platform_populate(node, NULL, NULL, dev); 145 + if (error) { 146 + dev_err(&pdev->dev, "failed to create dwc3 core\n"); 147 + goto err_core; 148 + } 149 + 150 + return 0; 151 + 152 + err_core: 153 + kdwc3_disable_irqs(kdwc); 154 + err_irq: 155 + clk_disable_unprepare(kdwc->clk); 156 + 157 + return error; 158 + } 159 + 160 + static int kdwc3_remove_core(struct device *dev, void *c) 161 + { 162 + struct platform_device *pdev = to_platform_device(dev); 163 + 164 + platform_device_unregister(pdev); 165 + 166 + return 0; 167 + } 168 + 169 + static int kdwc3_remove(struct platform_device *pdev) 170 + { 171 + struct dwc3_keystone *kdwc = platform_get_drvdata(pdev); 172 + 173 + kdwc3_disable_irqs(kdwc); 174 + device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core); 175 + clk_disable_unprepare(kdwc->clk); 176 + platform_set_drvdata(pdev, NULL); 177 + 178 + return 0; 179 + } 180 + 181 + static const struct of_device_id kdwc3_of_match[] = { 182 + { .compatible = "ti,keystone-dwc3", }, 183 + {}, 184 + }; 185 + MODULE_DEVICE_TABLE(of, kdwc3_of_match); 186 + 187 + static struct platform_driver kdwc3_driver = { 188 + .probe = kdwc3_probe, 189 + .remove = kdwc3_remove, 190 + .driver = { 191 + .name = "keystone-dwc3", 192 + .owner = THIS_MODULE, 193 + .of_match_table = kdwc3_of_match, 194 + }, 195 + }; 196 + 197 + module_platform_driver(kdwc3_driver); 198 + 199 + MODULE_ALIAS("platform:keystone-dwc3"); 200 + MODULE_AUTHOR("WingMan Kwok <w-kwok2@ti.com>"); 201 + MODULE_LICENSE("GPL v2"); 202 + MODULE_DESCRIPTION("DesignWare USB3 KEYSTONE Glue Layer");
+1 -11
drivers/usb/dwc3/dwc3-omap.c
··· 20 20 #include <linux/kernel.h> 21 21 #include <linux/slab.h> 22 22 #include <linux/interrupt.h> 23 - #include <linux/spinlock.h> 24 23 #include <linux/platform_device.h> 25 24 #include <linux/platform_data/dwc3-omap.h> 26 25 #include <linux/pm_runtime.h> ··· 119 120 #define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1) 120 121 121 122 struct dwc3_omap { 122 - /* device lock */ 123 - spinlock_t lock; 124 - 125 123 struct device *dev; 126 124 127 125 int irq; ··· 276 280 struct dwc3_omap *omap = _omap; 277 281 u32 reg; 278 282 279 - spin_lock(&omap->lock); 280 - 281 283 reg = dwc3_omap_read_irqmisc_status(omap); 282 284 283 285 if (reg & USBOTGSS_IRQMISC_DMADISABLECLR) { ··· 315 321 reg = dwc3_omap_read_irq0_status(omap); 316 322 317 323 dwc3_omap_write_irq0_status(omap, reg); 318 - 319 - spin_unlock(&omap->lock); 320 324 321 325 return IRQ_HANDLED; 322 326 } ··· 441 449 } 442 450 } 443 451 444 - spin_lock_init(&omap->lock); 445 - 446 452 omap->dev = dev; 447 453 omap->irq = irq; 448 454 omap->base = base; ··· 525 535 edev = of_extcon_get_extcon_dev(dev, 0); 526 536 if (IS_ERR(edev)) { 527 537 dev_vdbg(dev, "couldn't get extcon device\n"); 528 - ret = PTR_ERR(edev); 538 + ret = -EPROBE_DEFER; 529 539 goto err2; 530 540 } 531 541
+1
drivers/usb/dwc3/dwc3-pci.c
··· 52 52 53 53 glue->usb2_phy = pdev; 54 54 pdata.type = USB_PHY_TYPE_USB2; 55 + pdata.gpio_reset = -1; 55 56 56 57 ret = platform_device_add_data(glue->usb2_phy, &pdata, sizeof(pdata)); 57 58 if (ret)
+8 -2
drivers/usb/dwc3/gadget.c
··· 1650 1650 dev_vdbg(dwc->dev, "initializing %s\n", dep->name); 1651 1651 1652 1652 if (epnum == 0 || epnum == 1) { 1653 - dep->endpoint.maxpacket = 512; 1653 + usb_ep_set_maxpacket_limit(&dep->endpoint, 512); 1654 1654 dep->endpoint.maxburst = 1; 1655 1655 dep->endpoint.ops = &dwc3_gadget_ep0_ops; 1656 1656 if (!epnum) ··· 1658 1658 } else { 1659 1659 int ret; 1660 1660 1661 - dep->endpoint.maxpacket = 1024; 1661 + usb_ep_set_maxpacket_limit(&dep->endpoint, 1024); 1662 1662 dep->endpoint.max_streams = 15; 1663 1663 dep->endpoint.ops = &dwc3_gadget_ep_ops; 1664 1664 list_add_tail(&dep->endpoint.ep_list, ··· 2595 2595 dwc->gadget.speed = USB_SPEED_UNKNOWN; 2596 2596 dwc->gadget.sg_supported = true; 2597 2597 dwc->gadget.name = "dwc3-gadget"; 2598 + 2599 + /* 2600 + * Per databook, DWC3 needs buffer size to be aligned to MaxPacketSize 2601 + * on ep out. 2602 + */ 2603 + dwc->gadget.quirk_ep_out_aligned_size = true; 2598 2604 2599 2605 /* 2600 2606 * REVISIT: Here we should clear all pending IRQs to be
+43 -11
drivers/usb/gadget/Kconfig
··· 216 216 Say "y" to link the driver statically, or "m" to build a 217 217 dynamically linked module called "fotg210_udc". 218 218 219 + config USB_GR_UDC 220 + tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver" 221 + depends on HAS_DMA 222 + help 223 + Select this to support Aeroflex Gaisler GRUSBDC cores from the GRLIB 224 + VHDL IP core library. 225 + 219 226 config USB_OMAP 220 227 tristate "OMAP USB Device Controller" 221 228 depends on ARCH_OMAP1 ··· 301 294 gadget drivers to also be dynamically linked. 302 295 303 296 config USB_S3C_HSOTG 304 - tristate "S3C HS/OtG USB Device controller" 305 - depends on S3C_DEV_USB_HSOTG 297 + depends on ARM 298 + tristate "Designware/S3C HS/OtG USB Device controller" 306 299 help 307 - The Samsung S3C64XX USB2.0 high-speed gadget controller 308 - integrated into the S3C64XX series SoC. 300 + The Designware USB2.0 high-speed gadget controller 301 + integrated into many SoCs. 309 302 310 303 config USB_S3C2410 311 304 tristate "S3C2410 USB Device Controller" ··· 519 512 config USB_U_ETHER 520 513 tristate 521 514 522 - config USB_U_RNDIS 523 - tristate 524 - 525 515 config USB_F_SERIAL 526 516 tristate 527 517 ··· 544 540 tristate 545 541 546 542 config USB_F_MASS_STORAGE 543 + tristate 544 + 545 + config USB_F_FS 547 546 tristate 548 547 549 548 choice ··· 649 642 depends on USB_CONFIGFS 650 643 depends on NET 651 644 select USB_U_ETHER 652 - select USB_U_RNDIS 653 645 select USB_F_RNDIS 654 646 help 655 647 Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, ··· 695 689 As its storage repository it can use a regular file or a block 696 690 device (in much the same way as the "loop" device driver), 697 691 specified as a module parameter or sysfs option. 692 + 693 + config USB_CONFIGFS_F_LB_SS 694 + boolean "Loopback and sourcesink function (for testing)" 695 + depends on USB_CONFIGFS 696 + select USB_F_SS_LB 697 + help 698 + Loopback function loops back a configurable number of transfers. 699 + Sourcesink function either sinks and sources bulk data. 700 + It also implements control requests, for "chapter 9" conformance. 701 + Make this be the first driver you try using on top of any new 702 + USB peripheral controller driver. Then you can use host-side 703 + test software, like the "usbtest" driver, to put your hardware 704 + and its driver through a basic set of functional tests. 705 + 706 + config USB_CONFIGFS_F_FS 707 + boolean "Function filesystem (FunctionFS)" 708 + depends on USB_CONFIGFS 709 + select USB_F_FS 710 + help 711 + The Function Filesystem (FunctionFS) lets one create USB 712 + composite functions in user space in the same way GadgetFS 713 + lets one create USB gadgets in user space. This allows creation 714 + of composite gadgets such that some of the functions are 715 + implemented in kernel space (for instance Ethernet, serial or 716 + mass storage) and other are implemented in user space. 698 717 699 718 config USB_ZERO 700 719 tristate "Gadget Zero (DEVELOPMENT)" ··· 791 760 depends on NET 792 761 select USB_LIBCOMPOSITE 793 762 select USB_U_ETHER 794 - select USB_U_RNDIS 795 763 select USB_F_ECM 796 764 select USB_F_SUBSET 797 765 select CRC32 ··· 894 864 config USB_FUNCTIONFS 895 865 tristate "Function Filesystem" 896 866 select USB_LIBCOMPOSITE 867 + select USB_F_FS 897 868 select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) 898 869 help 899 870 The Function Filesystem (FunctionFS) lets one create USB ··· 914 883 bool "Include configuration with CDC ECM (Ethernet)" 915 884 depends on USB_FUNCTIONFS && NET 916 885 select USB_U_ETHER 886 + select USB_F_ECM 887 + select USB_F_SUBSET 917 888 help 918 889 Include a configuration with CDC ECM function (Ethernet) and the 919 890 Function Filesystem. ··· 924 891 bool "Include configuration with RNDIS (Ethernet)" 925 892 depends on USB_FUNCTIONFS && NET 926 893 select USB_U_ETHER 927 - select USB_U_RNDIS 894 + select USB_F_RNDIS 928 895 help 929 896 Include a configuration with RNDIS function (Ethernet) and the Filesystem. 930 897 ··· 1098 1065 config USB_G_MULTI_RNDIS 1099 1066 bool "RNDIS + CDC Serial + Storage configuration" 1100 1067 depends on USB_G_MULTI 1101 - select USB_U_RNDIS 1102 1068 select USB_F_RNDIS 1103 1069 default y 1104 1070 help
+5 -4
drivers/usb/gadget/Makefile
··· 7 7 obj-$(CONFIG_USB_GADGET) += udc-core.o 8 8 obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o 9 9 libcomposite-y := usbstring.o config.o epautoconf.o 10 - libcomposite-y += composite.o functions.o configfs.o 10 + libcomposite-y += composite.o functions.o configfs.o u_f.o 11 11 obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 12 12 obj-$(CONFIG_USB_NET2272) += net2272.o 13 13 obj-$(CONFIG_USB_NET2280) += net2280.o ··· 35 35 obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o 36 36 obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o 37 37 obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o 38 + obj-$(CONFIG_USB_GR_UDC) += gr_udc.o 38 39 39 40 # USB Functions 40 41 usb_f_acm-y := f_acm.o ··· 48 47 usb_f_obex-y := f_obex.o 49 48 obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o 50 49 obj-$(CONFIG_USB_U_ETHER) += u_ether.o 51 - u_rndis-y := rndis.o 52 - obj-$(CONFIG_USB_U_RNDIS) += u_rndis.o 53 50 usb_f_ncm-y := f_ncm.o 54 51 obj-$(CONFIG_USB_F_NCM) += usb_f_ncm.o 55 52 usb_f_ecm-y := f_ecm.o ··· 58 59 obj-$(CONFIG_USB_F_EEM) += usb_f_eem.o 59 60 usb_f_ecm_subset-y := f_subset.o 60 61 obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o 61 - usb_f_rndis-y := f_rndis.o 62 + usb_f_rndis-y := f_rndis.o rndis.o 62 63 obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o 63 64 usb_f_mass_storage-y := f_mass_storage.o storage_common.o 64 65 obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o 66 + usb_f_fs-y := f_fs.o 67 + obj-$(CONFIG_USB_F_FS) += usb_f_fs.o 65 68 66 69 # 67 70 # USB gadget drivers
+9 -6
drivers/usb/gadget/amd5536udc.c
··· 446 446 ep->ep.ops = &udc_ep_ops; 447 447 INIT_LIST_HEAD(&ep->queue); 448 448 449 - ep->ep.maxpacket = (u16) ~0; 449 + usb_ep_set_maxpacket_limit(&ep->ep,(u16) ~0); 450 450 /* set NAK */ 451 451 tmp = readl(&ep->regs->ctl); 452 452 tmp |= AMD_BIT(UDC_EPCTL_SNAK); ··· 1564 1564 } 1565 1565 /* EP0 max packet */ 1566 1566 if (dev->gadget.speed == USB_SPEED_FULL) { 1567 - dev->ep[UDC_EP0IN_IX].ep.maxpacket = UDC_FS_EP0IN_MAX_PKT_SIZE; 1568 - dev->ep[UDC_EP0OUT_IX].ep.maxpacket = 1569 - UDC_FS_EP0OUT_MAX_PKT_SIZE; 1567 + usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0IN_IX].ep, 1568 + UDC_FS_EP0IN_MAX_PKT_SIZE); 1569 + usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0OUT_IX].ep, 1570 + UDC_FS_EP0OUT_MAX_PKT_SIZE); 1570 1571 } else if (dev->gadget.speed == USB_SPEED_HIGH) { 1571 - dev->ep[UDC_EP0IN_IX].ep.maxpacket = UDC_EP0IN_MAX_PKT_SIZE; 1572 - dev->ep[UDC_EP0OUT_IX].ep.maxpacket = UDC_EP0OUT_MAX_PKT_SIZE; 1572 + usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0IN_IX].ep, 1573 + UDC_EP0IN_MAX_PKT_SIZE); 1574 + usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0OUT_IX].ep, 1575 + UDC_EP0OUT_MAX_PKT_SIZE); 1573 1576 } 1574 1577 1575 1578 /*
+8 -8
drivers/usb/gadget/at91_udc.c
··· 834 834 ep->ep.desc = NULL; 835 835 ep->stopped = 0; 836 836 ep->fifo_bank = 0; 837 - ep->ep.maxpacket = ep->maxpacket; 837 + usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); 838 838 ep->creg = (void __iomem *) udc->udp_baseaddr + AT91_UDP_CSR(i); 839 839 /* initialize one queue per endpoint */ 840 840 INIT_LIST_HEAD(&ep->queue); ··· 1759 1759 1760 1760 /* newer chips have more FIFO memory than rm9200 */ 1761 1761 if (cpu_is_at91sam9260() || cpu_is_at91sam9g20()) { 1762 - udc->ep[0].maxpacket = 64; 1763 - udc->ep[3].maxpacket = 64; 1764 - udc->ep[4].maxpacket = 512; 1765 - udc->ep[5].maxpacket = 512; 1762 + usb_ep_set_maxpacket_limit(&udc->ep[0].ep, 64); 1763 + usb_ep_set_maxpacket_limit(&udc->ep[3].ep, 64); 1764 + usb_ep_set_maxpacket_limit(&udc->ep[4].ep, 512); 1765 + usb_ep_set_maxpacket_limit(&udc->ep[5].ep, 512); 1766 1766 } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) { 1767 - udc->ep[3].maxpacket = 64; 1767 + usb_ep_set_maxpacket_limit(&udc->ep[3].ep, 64); 1768 1768 } else if (cpu_is_at91sam9263()) { 1769 - udc->ep[0].maxpacket = 64; 1770 - udc->ep[3].maxpacket = 64; 1769 + usb_ep_set_maxpacket_limit(&udc->ep[0].ep, 64); 1770 + usb_ep_set_maxpacket_limit(&udc->ep[3].ep, 64); 1771 1771 } 1772 1772 1773 1773 udc->udp_baseaddr = ioremap(res->start, resource_size(res));
+21 -50
drivers/usb/gadget/atmel_usba_udc.c
··· 1012 1012 1013 1013 } 1014 1014 1015 - struct usb_gadget usba_gadget_template = { 1015 + static struct usb_gadget usba_gadget_template = { 1016 1016 .ops = &usba_udc_ops, 1017 1017 .max_speed = USB_SPEED_HIGH, 1018 1018 .name = "atmel_usba_udc", ··· 1904 1904 ep->dma_regs = udc->regs + USBA_DMA_BASE(i); 1905 1905 ep->fifo = udc->fifo + USBA_FIFO_BASE(i); 1906 1906 ep->ep.ops = &usba_ep_ops; 1907 - ep->ep.maxpacket = ep->fifo_size; 1907 + usb_ep_set_maxpacket_limit(&ep->ep, ep->fifo_size); 1908 1908 ep->udc = udc; 1909 1909 INIT_LIST_HEAD(&ep->queue); 1910 1910 ··· 1957 1957 ep->fifo = udc->fifo + USBA_FIFO_BASE(i); 1958 1958 ep->ep.ops = &usba_ep_ops; 1959 1959 ep->ep.name = pdata->ep[i].name; 1960 - ep->fifo_size = ep->ep.maxpacket = pdata->ep[i].fifo_size; 1960 + ep->fifo_size = pdata->ep[i].fifo_size; 1961 + usb_ep_set_maxpacket_limit(&ep->ep, ep->fifo_size); 1961 1962 ep->udc = udc; 1962 1963 INIT_LIST_HEAD(&ep->queue); 1963 1964 ep->nr_banks = pdata->ep[i].nr_banks; ··· 1996 1995 if (irq < 0) 1997 1996 return irq; 1998 1997 1999 - pclk = clk_get(&pdev->dev, "pclk"); 1998 + pclk = devm_clk_get(&pdev->dev, "pclk"); 2000 1999 if (IS_ERR(pclk)) 2001 2000 return PTR_ERR(pclk); 2002 - hclk = clk_get(&pdev->dev, "hclk"); 2003 - if (IS_ERR(hclk)) { 2004 - ret = PTR_ERR(hclk); 2005 - goto err_get_hclk; 2006 - } 2001 + hclk = devm_clk_get(&pdev->dev, "hclk"); 2002 + if (IS_ERR(hclk)) 2003 + return PTR_ERR(hclk); 2007 2004 2008 2005 spin_lock_init(&udc->lock); 2009 2006 udc->pdev = pdev; ··· 2010 2011 udc->vbus_pin = -ENODEV; 2011 2012 2012 2013 ret = -ENOMEM; 2013 - udc->regs = ioremap(regs->start, resource_size(regs)); 2014 + udc->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs)); 2014 2015 if (!udc->regs) { 2015 2016 dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n"); 2016 - goto err_map_regs; 2017 + return ret; 2017 2018 } 2018 2019 dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n", 2019 2020 (unsigned long)regs->start, udc->regs); 2020 - udc->fifo = ioremap(fifo->start, resource_size(fifo)); 2021 + udc->fifo = devm_ioremap(&pdev->dev, fifo->start, resource_size(fifo)); 2021 2022 if (!udc->fifo) { 2022 2023 dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n"); 2023 - goto err_map_fifo; 2024 + return ret; 2024 2025 } 2025 2026 dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n", 2026 2027 (unsigned long)fifo->start, udc->fifo); ··· 2031 2032 ret = clk_prepare_enable(pclk); 2032 2033 if (ret) { 2033 2034 dev_err(&pdev->dev, "Unable to enable pclk, aborting.\n"); 2034 - goto err_clk_enable; 2035 + return ret; 2035 2036 } 2036 2037 toggle_bias(0); 2037 2038 usba_writel(udc, CTRL, USBA_DISABLE_MASK); ··· 2042 2043 else 2043 2044 udc->usba_ep = usba_udc_pdata(pdev, udc); 2044 2045 2045 - if (IS_ERR(udc->usba_ep)) { 2046 - ret = PTR_ERR(udc->usba_ep); 2047 - goto err_alloc_ep; 2048 - } 2046 + if (IS_ERR(udc->usba_ep)) 2047 + return PTR_ERR(udc->usba_ep); 2049 2048 2050 - ret = request_irq(irq, usba_udc_irq, 0, "atmel_usba_udc", udc); 2049 + ret = devm_request_irq(&pdev->dev, irq, usba_udc_irq, 0, 2050 + "atmel_usba_udc", udc); 2051 2051 if (ret) { 2052 2052 dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n", 2053 2053 irq, ret); 2054 - goto err_request_irq; 2054 + return ret; 2055 2055 } 2056 2056 udc->irq = irq; 2057 2057 2058 2058 if (gpio_is_valid(udc->vbus_pin)) { 2059 2059 if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, "atmel_usba_udc")) { 2060 - ret = request_irq(gpio_to_irq(udc->vbus_pin), 2060 + ret = devm_request_irq(&pdev->dev, 2061 + gpio_to_irq(udc->vbus_pin), 2061 2062 usba_vbus_irq, 0, 2062 2063 "atmel_usba_udc", udc); 2063 2064 if (ret) { ··· 2076 2077 2077 2078 ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 2078 2079 if (ret) 2079 - goto err_add_udc; 2080 + return ret; 2080 2081 2081 2082 usba_init_debugfs(udc); 2082 2083 for (i = 1; i < udc->num_ep; i++) 2083 2084 usba_ep_init_debugfs(udc, &udc->usba_ep[i]); 2084 2085 2085 2086 return 0; 2086 - 2087 - err_add_udc: 2088 - if (gpio_is_valid(udc->vbus_pin)) 2089 - free_irq(gpio_to_irq(udc->vbus_pin), udc); 2090 - 2091 - free_irq(irq, udc); 2092 - err_request_irq: 2093 - err_alloc_ep: 2094 - err_clk_enable: 2095 - iounmap(udc->fifo); 2096 - err_map_fifo: 2097 - iounmap(udc->regs); 2098 - err_map_regs: 2099 - clk_put(hclk); 2100 - err_get_hclk: 2101 - clk_put(pclk); 2102 - 2103 - return ret; 2104 2087 } 2105 2088 2106 2089 static int __exit usba_udc_remove(struct platform_device *pdev) ··· 2097 2116 for (i = 1; i < udc->num_ep; i++) 2098 2117 usba_ep_cleanup_debugfs(&udc->usba_ep[i]); 2099 2118 usba_cleanup_debugfs(udc); 2100 - 2101 - if (gpio_is_valid(udc->vbus_pin)) { 2102 - free_irq(gpio_to_irq(udc->vbus_pin), udc); 2103 - } 2104 - 2105 - free_irq(udc->irq, udc); 2106 - iounmap(udc->fifo); 2107 - iounmap(udc->regs); 2108 - clk_put(udc->hclk); 2109 - clk_put(udc->pclk); 2110 2119 2111 2120 return 0; 2112 2121 }
+2 -2
drivers/usb/gadget/bcm63xx_udc.c
··· 549 549 550 550 if (idx < 0) 551 551 continue; 552 - udc->bep[idx].ep.maxpacket = max_pkt; 552 + usb_ep_set_maxpacket_limit(&udc->bep[idx].ep, max_pkt); 553 553 554 554 val = (idx << USBD_CSR_EP_LOG_SHIFT) | 555 555 (cfg->dir << USBD_CSR_EP_DIR_SHIFT) | ··· 943 943 bep->ep.ops = &bcm63xx_udc_ep_ops; 944 944 list_add_tail(&bep->ep.ep_list, &udc->gadget.ep_list); 945 945 bep->halted = 0; 946 - bep->ep.maxpacket = BCM63XX_MAX_CTRL_PKT; 946 + usb_ep_set_maxpacket_limit(&bep->ep, BCM63XX_MAX_CTRL_PKT); 947 947 bep->udc = udc; 948 948 bep->ep.desc = NULL; 949 949 INIT_LIST_HEAD(&bep->queue);
+16 -2
drivers/usb/gadget/composite.c
··· 1452 1452 struct usb_configuration *c; 1453 1453 1454 1454 c = cdev->config; 1455 - if (c && c->setup) 1455 + if (!c) 1456 + goto done; 1457 + 1458 + /* try current config's setup */ 1459 + if (c->setup) { 1456 1460 value = c->setup(c, ctrl); 1461 + goto done; 1462 + } 1463 + 1464 + /* try the only function in the current config */ 1465 + if (!list_is_singular(&c->functions)) 1466 + goto done; 1467 + f = list_first_entry(&c->functions, struct usb_function, 1468 + list); 1469 + if (f->setup) 1470 + value = f->setup(f, ctrl); 1457 1471 } 1458 1472 1459 1473 goto done; ··· 1728 1714 { 1729 1715 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1730 1716 struct usb_function *f; 1731 - u8 maxpower; 1717 + u16 maxpower; 1732 1718 1733 1719 /* REVISIT: should we have config level 1734 1720 * suspend/resume callbacks?
+8
drivers/usb/gadget/configfs.c
··· 4 4 #include <linux/device.h> 5 5 #include <linux/usb/composite.h> 6 6 #include <linux/usb/gadget_configfs.h> 7 + #include "configfs.h" 7 8 8 9 int check_user_usb_string(const char *name, 9 10 struct usb_gadget_strings *stringtab_dev) ··· 564 563 if (ret) { 565 564 usb_put_function_instance(fi); 566 565 return ERR_PTR(ret); 566 + } 567 + if (fi->set_inst_name) { 568 + ret = fi->set_inst_name(fi, instance_name); 569 + if (ret) { 570 + usb_put_function_instance(fi); 571 + return ERR_PTR(ret); 572 + } 567 573 } 568 574 569 575 gi = container_of(group, struct gadget_info, functions_group);
+1 -1
drivers/usb/gadget/dummy_hcd.c
··· 951 951 list_add_tail(&ep->ep.ep_list, &dum->gadget.ep_list); 952 952 ep->halted = ep->wedged = ep->already_seen = 953 953 ep->setup_stage = 0; 954 - ep->ep.maxpacket = ~0; 954 + usb_ep_set_maxpacket_limit(&ep->ep, ~0); 955 955 ep->ep.max_streams = 16; 956 956 ep->last_io = jiffies; 957 957 ep->gadget = &dum->gadget;
+4 -4
drivers/usb/gadget/epautoconf.c
··· 58 58 return 0; 59 59 60 60 /* only support ep0 for portable CONTROL traffic */ 61 - type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; 61 + type = usb_endpoint_type(desc); 62 62 if (USB_ENDPOINT_XFER_CONTROL == type) 63 63 return 0; 64 64 ··· 129 129 * and wants to know the maximum possible, provide the info. 130 130 */ 131 131 if (desc->wMaxPacketSize == 0) 132 - desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket); 132 + desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket_limit); 133 133 134 134 /* endpoint maxpacket size is an input parameter, except for bulk 135 135 * where it's an output parameter representing the full speed limit. ··· 145 145 146 146 case USB_ENDPOINT_XFER_ISOC: 147 147 /* ISO: limit 1023 bytes full speed, 1024 high/super speed */ 148 - if (ep->maxpacket < max) 148 + if (ep->maxpacket_limit < max) 149 149 return 0; 150 150 if (!gadget_is_dualspeed(gadget) && max > 1023) 151 151 return 0; ··· 178 178 179 179 /* report (variable) full speed bulk maxpacket */ 180 180 if ((USB_ENDPOINT_XFER_BULK == type) && !ep_comp) { 181 - int size = ep->maxpacket; 181 + int size = ep->maxpacket_limit; 182 182 183 183 /* min() doesn't work on bitfields with gcc-3.5 */ 184 184 if (size > 64)
+1 -72
drivers/usb/gadget/f_ecm.c
··· 691 691 int status; 692 692 struct usb_ep *ep; 693 693 694 - #ifndef USBF_ECM_INCLUDED 695 694 struct f_ecm_opts *ecm_opts; 696 695 697 696 if (!can_support_ecm(cdev->gadget)) ··· 714 715 return status; 715 716 ecm_opts->bound = true; 716 717 } 717 - #endif 718 + 718 719 us = usb_gstrings_attach(cdev, ecm_strings, 719 720 ARRAY_SIZE(ecm_string_defs)); 720 721 if (IS_ERR(us)) ··· 832 833 833 834 return status; 834 835 } 835 - 836 - #ifdef USBF_ECM_INCLUDED 837 - 838 - static void 839 - ecm_old_unbind(struct usb_configuration *c, struct usb_function *f) 840 - { 841 - struct f_ecm *ecm = func_to_ecm(f); 842 - 843 - DBG(c->cdev, "ecm unbind\n"); 844 - 845 - usb_free_all_descriptors(f); 846 - 847 - kfree(ecm->notify_req->buf); 848 - usb_ep_free_request(ecm->notify, ecm->notify_req); 849 - kfree(ecm); 850 - } 851 - 852 - /** 853 - * ecm_bind_config - add CDC Ethernet network link to a configuration 854 - * @c: the configuration to support the network link 855 - * @ethaddr: a buffer in which the ethernet address of the host side 856 - * side of the link was recorded 857 - * @dev: eth_dev structure 858 - * Context: single threaded during gadget setup 859 - * 860 - * Returns zero on success, else negative errno. 861 - * 862 - * Caller must have called @gether_setup(). Caller is also responsible 863 - * for calling @gether_cleanup() before module unload. 864 - */ 865 - int 866 - ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 867 - struct eth_dev *dev) 868 - { 869 - struct f_ecm *ecm; 870 - int status; 871 - 872 - if (!can_support_ecm(c->cdev->gadget) || !ethaddr) 873 - return -EINVAL; 874 - 875 - /* allocate and initialize one new instance */ 876 - ecm = kzalloc(sizeof *ecm, GFP_KERNEL); 877 - if (!ecm) 878 - return -ENOMEM; 879 - 880 - /* export host's Ethernet address in CDC format */ 881 - snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr); 882 - ecm_string_defs[1].s = ecm->ethaddr; 883 - 884 - ecm->port.ioport = dev; 885 - ecm->port.cdc_filter = DEFAULT_FILTER; 886 - 887 - ecm->port.func.name = "cdc_ethernet"; 888 - /* descriptors are per-instance copies */ 889 - ecm->port.func.bind = ecm_bind; 890 - ecm->port.func.unbind = ecm_old_unbind; 891 - ecm->port.func.set_alt = ecm_set_alt; 892 - ecm->port.func.get_alt = ecm_get_alt; 893 - ecm->port.func.setup = ecm_setup; 894 - ecm->port.func.disable = ecm_disable; 895 - 896 - status = usb_add_function(c, &ecm->port.func); 897 - if (status) 898 - kfree(ecm); 899 - return status; 900 - } 901 - 902 - #else 903 836 904 837 static inline struct f_ecm_opts *to_f_ecm_opts(struct config_item *item) 905 838 { ··· 971 1040 DECLARE_USB_FUNCTION_INIT(ecm, ecm_alloc_inst, ecm_alloc); 972 1041 MODULE_LICENSE("GPL"); 973 1042 MODULE_AUTHOR("David Brownell"); 974 - 975 - #endif
+633 -403
drivers/usb/gadget/f_fs.c
··· 22 22 #include <linux/pagemap.h> 23 23 #include <linux/export.h> 24 24 #include <linux/hid.h> 25 + #include <linux/module.h> 25 26 #include <asm/unaligned.h> 26 27 27 28 #include <linux/usb/composite.h> 28 29 #include <linux/usb/functionfs.h> 29 30 31 + #include "u_fs.h" 32 + #include "configfs.h" 30 33 31 34 #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ 32 35 36 + /* Variable Length Array Macros **********************************************/ 37 + #define vla_group(groupname) size_t groupname##__next = 0 38 + #define vla_group_size(groupname) groupname##__next 33 39 34 - /* Debugging ****************************************************************/ 40 + #define vla_item(groupname, type, name, n) \ 41 + size_t groupname##_##name##__offset = ({ \ 42 + size_t align_mask = __alignof__(type) - 1; \ 43 + size_t offset = (groupname##__next + align_mask) & ~align_mask;\ 44 + size_t size = (n) * sizeof(type); \ 45 + groupname##__next = offset + size; \ 46 + offset; \ 47 + }) 35 48 36 - #ifdef VERBOSE_DEBUG 37 - #ifndef pr_vdebug 38 - # define pr_vdebug pr_debug 39 - #endif /* pr_vdebug */ 40 - # define ffs_dump_mem(prefix, ptr, len) \ 41 - print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len) 42 - #else 43 - #ifndef pr_vdebug 44 - # define pr_vdebug(...) do { } while (0) 45 - #endif /* pr_vdebug */ 46 - # define ffs_dump_mem(prefix, ptr, len) do { } while (0) 47 - #endif /* VERBOSE_DEBUG */ 49 + #define vla_item_with_sz(groupname, type, name, n) \ 50 + size_t groupname##_##name##__sz = (n) * sizeof(type); \ 51 + size_t groupname##_##name##__offset = ({ \ 52 + size_t align_mask = __alignof__(type) - 1; \ 53 + size_t offset = (groupname##__next + align_mask) & ~align_mask;\ 54 + size_t size = groupname##_##name##__sz; \ 55 + groupname##__next = offset + size; \ 56 + offset; \ 57 + }) 48 58 49 - #define ENTER() pr_vdebug("%s()\n", __func__) 50 - 51 - 52 - /* The data structure and setup file ****************************************/ 53 - 54 - enum ffs_state { 55 - /* 56 - * Waiting for descriptors and strings. 57 - * 58 - * In this state no open(2), read(2) or write(2) on epfiles 59 - * may succeed (which should not be the problem as there 60 - * should be no such files opened in the first place). 61 - */ 62 - FFS_READ_DESCRIPTORS, 63 - FFS_READ_STRINGS, 64 - 65 - /* 66 - * We've got descriptors and strings. We are or have called 67 - * functionfs_ready_callback(). functionfs_bind() may have 68 - * been called but we don't know. 69 - * 70 - * This is the only state in which operations on epfiles may 71 - * succeed. 72 - */ 73 - FFS_ACTIVE, 74 - 75 - /* 76 - * All endpoints have been closed. This state is also set if 77 - * we encounter an unrecoverable error. The only 78 - * unrecoverable error is situation when after reading strings 79 - * from user space we fail to initialise epfiles or 80 - * functionfs_ready_callback() returns with error (<0). 81 - * 82 - * In this state no open(2), read(2) or write(2) (both on ep0 83 - * as well as epfile) may succeed (at this point epfiles are 84 - * unlinked and all closed so this is not a problem; ep0 is 85 - * also closed but ep0 file exists and so open(2) on ep0 must 86 - * fail). 87 - */ 88 - FFS_CLOSING 89 - }; 90 - 91 - 92 - enum ffs_setup_state { 93 - /* There is no setup request pending. */ 94 - FFS_NO_SETUP, 95 - /* 96 - * User has read events and there was a setup request event 97 - * there. The next read/write on ep0 will handle the 98 - * request. 99 - */ 100 - FFS_SETUP_PENDING, 101 - /* 102 - * There was event pending but before user space handled it 103 - * some other event was introduced which canceled existing 104 - * setup. If this state is set read/write on ep0 return 105 - * -EIDRM. This state is only set when adding event. 106 - */ 107 - FFS_SETUP_CANCELED 108 - }; 109 - 110 - 111 - 112 - struct ffs_epfile; 113 - struct ffs_function; 114 - 115 - struct ffs_data { 116 - struct usb_gadget *gadget; 117 - 118 - /* 119 - * Protect access read/write operations, only one read/write 120 - * at a time. As a consequence protects ep0req and company. 121 - * While setup request is being processed (queued) this is 122 - * held. 123 - */ 124 - struct mutex mutex; 125 - 126 - /* 127 - * Protect access to endpoint related structures (basically 128 - * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for 129 - * endpoint zero. 130 - */ 131 - spinlock_t eps_lock; 132 - 133 - /* 134 - * XXX REVISIT do we need our own request? Since we are not 135 - * handling setup requests immediately user space may be so 136 - * slow that another setup will be sent to the gadget but this 137 - * time not to us but another function and then there could be 138 - * a race. Is that the case? Or maybe we can use cdev->req 139 - * after all, maybe we just need some spinlock for that? 140 - */ 141 - struct usb_request *ep0req; /* P: mutex */ 142 - struct completion ep0req_completion; /* P: mutex */ 143 - int ep0req_status; /* P: mutex */ 144 - 145 - /* reference counter */ 146 - atomic_t ref; 147 - /* how many files are opened (EP0 and others) */ 148 - atomic_t opened; 149 - 150 - /* EP0 state */ 151 - enum ffs_state state; 152 - 153 - /* 154 - * Possible transitions: 155 - * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock 156 - * happens only in ep0 read which is P: mutex 157 - * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock 158 - * happens only in ep0 i/o which is P: mutex 159 - * + FFS_SETUP_PENDING -> FFS_SETUP_CANCELED -- P: ev.waitq.lock 160 - * + FFS_SETUP_CANCELED -> FFS_NO_SETUP -- cmpxchg 161 - */ 162 - enum ffs_setup_state setup_state; 163 - 164 - #define FFS_SETUP_STATE(ffs) \ 165 - ((enum ffs_setup_state)cmpxchg(&(ffs)->setup_state, \ 166 - FFS_SETUP_CANCELED, FFS_NO_SETUP)) 167 - 168 - /* Events & such. */ 169 - struct { 170 - u8 types[4]; 171 - unsigned short count; 172 - /* XXX REVISIT need to update it in some places, or do we? */ 173 - unsigned short can_stall; 174 - struct usb_ctrlrequest setup; 175 - 176 - wait_queue_head_t waitq; 177 - } ev; /* the whole structure, P: ev.waitq.lock */ 178 - 179 - /* Flags */ 180 - unsigned long flags; 181 - #define FFS_FL_CALL_CLOSED_CALLBACK 0 182 - #define FFS_FL_BOUND 1 183 - 184 - /* Active function */ 185 - struct ffs_function *func; 186 - 187 - /* 188 - * Device name, write once when file system is mounted. 189 - * Intended for user to read if she wants. 190 - */ 191 - const char *dev_name; 192 - /* Private data for our user (ie. gadget). Managed by user. */ 193 - void *private_data; 194 - 195 - /* filled by __ffs_data_got_descs() */ 196 - /* 197 - * Real descriptors are 16 bytes after raw_descs (so you need 198 - * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the 199 - * first full speed descriptor). raw_descs_length and 200 - * raw_fs_descs_length do not have those 16 bytes added. 201 - */ 202 - const void *raw_descs; 203 - unsigned raw_descs_length; 204 - unsigned raw_fs_descs_length; 205 - unsigned fs_descs_count; 206 - unsigned hs_descs_count; 207 - 208 - unsigned short strings_count; 209 - unsigned short interfaces_count; 210 - unsigned short eps_count; 211 - unsigned short _pad1; 212 - 213 - /* filled by __ffs_data_got_strings() */ 214 - /* ids in stringtabs are set in functionfs_bind() */ 215 - const void *raw_strings; 216 - struct usb_gadget_strings **stringtabs; 217 - 218 - /* 219 - * File system's super block, write once when file system is 220 - * mounted. 221 - */ 222 - struct super_block *sb; 223 - 224 - /* File permissions, written once when fs is mounted */ 225 - struct ffs_file_perms { 226 - umode_t mode; 227 - kuid_t uid; 228 - kgid_t gid; 229 - } file_perms; 230 - 231 - /* 232 - * The endpoint files, filled by ffs_epfiles_create(), 233 - * destroyed by ffs_epfiles_destroy(). 234 - */ 235 - struct ffs_epfile *epfiles; 236 - }; 59 + #define vla_ptr(ptr, groupname, name) \ 60 + ((void *) ((char *)ptr + groupname##_##name##__offset)) 237 61 238 62 /* Reference counter handling */ 239 63 static void ffs_data_get(struct ffs_data *ffs); ··· 98 274 return container_of(f, struct ffs_function, function); 99 275 } 100 276 101 - static void ffs_func_free(struct ffs_function *func); 102 277 103 278 static void ffs_func_eps_disable(struct ffs_function *func); 104 279 static int __must_check ffs_func_eps_enable(struct ffs_function *func); 105 280 106 281 static int ffs_func_bind(struct usb_configuration *, 107 282 struct usb_function *); 108 - static void ffs_func_unbind(struct usb_configuration *, 109 - struct usb_function *); 110 283 static int ffs_func_set_alt(struct usb_function *, unsigned, unsigned); 111 284 static void ffs_func_disable(struct usb_function *); 112 285 static int ffs_func_setup(struct usb_function *, ··· 156 335 const struct file_operations *fops, 157 336 struct dentry **dentry_p); 158 337 338 + /* Devices management *******************************************************/ 339 + 340 + DEFINE_MUTEX(ffs_lock); 341 + EXPORT_SYMBOL(ffs_lock); 342 + 343 + static struct ffs_dev *ffs_find_dev(const char *name); 344 + static int _ffs_name_dev(struct ffs_dev *dev, const char *name); 345 + static void *ffs_acquire_dev(const char *dev_name); 346 + static void ffs_release_dev(struct ffs_data *ffs_data); 347 + static int ffs_ready(struct ffs_data *ffs); 348 + static void ffs_closed(struct ffs_data *ffs); 159 349 160 350 /* Misc helper functions ****************************************************/ 161 351 ··· 292 460 ffs->state = FFS_ACTIVE; 293 461 mutex_unlock(&ffs->mutex); 294 462 295 - ret = functionfs_ready_callback(ffs); 463 + ret = ffs_ready(ffs); 296 464 if (unlikely(ret < 0)) { 297 465 ffs->state = FFS_CLOSING; 298 466 return ret; ··· 585 753 char __user *buf, size_t len, int read) 586 754 { 587 755 struct ffs_epfile *epfile = file->private_data; 756 + struct usb_gadget *gadget = epfile->ffs->gadget; 588 757 struct ffs_ep *ep; 589 758 char *data = NULL; 590 - ssize_t ret; 759 + ssize_t ret, data_len; 591 760 int halt; 592 761 593 - goto first_try; 594 - do { 762 + /* Are we still active? */ 763 + if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) { 764 + ret = -ENODEV; 765 + goto error; 766 + } 767 + 768 + /* Wait for endpoint to be enabled */ 769 + ep = epfile->ep; 770 + if (!ep) { 771 + if (file->f_flags & O_NONBLOCK) { 772 + ret = -EAGAIN; 773 + goto error; 774 + } 775 + 776 + ret = wait_event_interruptible(epfile->wait, (ep = epfile->ep)); 777 + if (ret) { 778 + ret = -EINTR; 779 + goto error; 780 + } 781 + } 782 + 783 + /* Do we halt? */ 784 + halt = !read == !epfile->in; 785 + if (halt && epfile->isoc) { 786 + ret = -EINVAL; 787 + goto error; 788 + } 789 + 790 + /* Allocate & copy */ 791 + if (!halt) { 792 + /* 793 + * Controller may require buffer size to be aligned to 794 + * maxpacketsize of an out endpoint. 795 + */ 796 + data_len = read ? usb_ep_align_maybe(gadget, ep->ep, len) : len; 797 + 798 + data = kmalloc(data_len, GFP_KERNEL); 799 + if (unlikely(!data)) 800 + return -ENOMEM; 801 + 802 + if (!read && unlikely(copy_from_user(data, buf, len))) { 803 + ret = -EFAULT; 804 + goto error; 805 + } 806 + } 807 + 808 + /* We will be using request */ 809 + ret = ffs_mutex_lock(&epfile->mutex, file->f_flags & O_NONBLOCK); 810 + if (unlikely(ret)) 811 + goto error; 812 + 813 + spin_lock_irq(&epfile->ffs->eps_lock); 814 + 815 + if (epfile->ep != ep) { 816 + /* In the meantime, endpoint got disabled or changed. */ 817 + ret = -ESHUTDOWN; 595 818 spin_unlock_irq(&epfile->ffs->eps_lock); 596 - mutex_unlock(&epfile->mutex); 597 - 598 - first_try: 599 - /* Are we still active? */ 600 - if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) { 601 - ret = -ENODEV; 602 - goto error; 603 - } 604 - 605 - /* Wait for endpoint to be enabled */ 606 - ep = epfile->ep; 607 - if (!ep) { 608 - if (file->f_flags & O_NONBLOCK) { 609 - ret = -EAGAIN; 610 - goto error; 611 - } 612 - 613 - if (wait_event_interruptible(epfile->wait, 614 - (ep = epfile->ep))) { 615 - ret = -EINTR; 616 - goto error; 617 - } 618 - } 619 - 620 - /* Do we halt? */ 621 - halt = !read == !epfile->in; 622 - if (halt && epfile->isoc) { 623 - ret = -EINVAL; 624 - goto error; 625 - } 626 - 627 - /* Allocate & copy */ 628 - if (!halt && !data) { 629 - data = kzalloc(len, GFP_KERNEL); 630 - if (unlikely(!data)) 631 - return -ENOMEM; 632 - 633 - if (!read && 634 - unlikely(__copy_from_user(data, buf, len))) { 635 - ret = -EFAULT; 636 - goto error; 637 - } 638 - } 639 - 640 - /* We will be using request */ 641 - ret = ffs_mutex_lock(&epfile->mutex, 642 - file->f_flags & O_NONBLOCK); 643 - if (unlikely(ret)) 644 - goto error; 645 - 646 - /* 647 - * We're called from user space, we can use _irq rather then 648 - * _irqsave 649 - */ 650 - spin_lock_irq(&epfile->ffs->eps_lock); 651 - 652 - /* 653 - * While we were acquiring mutex endpoint got disabled 654 - * or changed? 655 - */ 656 - } while (unlikely(epfile->ep != ep)); 657 - 658 - /* Halt */ 659 - if (unlikely(halt)) { 819 + } else if (halt) { 820 + /* Halt */ 660 821 if (likely(epfile->ep == ep) && !WARN_ON(!ep->ep)) 661 822 usb_ep_set_halt(ep->ep); 662 823 spin_unlock_irq(&epfile->ffs->eps_lock); ··· 662 837 req->context = &done; 663 838 req->complete = ffs_epfile_io_complete; 664 839 req->buf = data; 665 - req->length = len; 840 + req->length = data_len; 666 841 667 842 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); 668 843 ··· 674 849 ret = -EINTR; 675 850 usb_ep_dequeue(ep->ep, req); 676 851 } else { 852 + /* 853 + * XXX We may end up silently droping data here. 854 + * Since data_len (i.e. req->length) may be bigger 855 + * than len (after being rounded up to maxpacketsize), 856 + * we may end up with more data then user space has 857 + * space for. 858 + */ 677 859 ret = ep->status; 678 860 if (read && ret > 0 && 679 - unlikely(copy_to_user(buf, data, ret))) 861 + unlikely(copy_to_user(buf, data, 862 + min_t(size_t, ret, len)))) 680 863 ret = -EFAULT; 681 864 } 682 865 } ··· 1024 1191 return ERR_PTR(-ENOMEM); 1025 1192 } 1026 1193 1027 - ffs_dev = functionfs_acquire_dev_callback(dev_name); 1194 + ffs_dev = ffs_acquire_dev(dev_name); 1028 1195 if (IS_ERR(ffs_dev)) { 1029 1196 ffs_data_put(ffs); 1030 1197 return ERR_CAST(ffs_dev); ··· 1034 1201 1035 1202 rv = mount_nodev(t, flags, &data, ffs_sb_fill); 1036 1203 if (IS_ERR(rv) && data.ffs_data) { 1037 - functionfs_release_dev_callback(data.ffs_data); 1204 + ffs_release_dev(data.ffs_data); 1038 1205 ffs_data_put(data.ffs_data); 1039 1206 } 1040 1207 return rv; ··· 1047 1214 1048 1215 kill_litter_super(sb); 1049 1216 if (sb->s_fs_info) { 1050 - functionfs_release_dev_callback(sb->s_fs_info); 1217 + ffs_release_dev(sb->s_fs_info); 1051 1218 ffs_data_put(sb->s_fs_info); 1052 1219 } 1053 1220 } ··· 1160 1327 ENTER(); 1161 1328 1162 1329 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags)) 1163 - functionfs_closed_callback(ffs); 1330 + ffs_closed(ffs); 1164 1331 1165 1332 BUG_ON(ffs->gadget); 1166 1333 ··· 1296 1463 kfree(epfiles); 1297 1464 } 1298 1465 1299 - static int functionfs_bind_config(struct usb_composite_dev *cdev, 1300 - struct usb_configuration *c, 1301 - struct ffs_data *ffs) 1302 - { 1303 - struct ffs_function *func; 1304 - int ret; 1305 - 1306 - ENTER(); 1307 - 1308 - func = kzalloc(sizeof *func, GFP_KERNEL); 1309 - if (unlikely(!func)) 1310 - return -ENOMEM; 1311 - 1312 - func->function.name = "Function FS Gadget"; 1313 - func->function.strings = ffs->stringtabs; 1314 - 1315 - func->function.bind = ffs_func_bind; 1316 - func->function.unbind = ffs_func_unbind; 1317 - func->function.set_alt = ffs_func_set_alt; 1318 - func->function.disable = ffs_func_disable; 1319 - func->function.setup = ffs_func_setup; 1320 - func->function.suspend = ffs_func_suspend; 1321 - func->function.resume = ffs_func_resume; 1322 - 1323 - func->conf = c; 1324 - func->gadget = cdev->gadget; 1325 - func->ffs = ffs; 1326 - ffs_data_get(ffs); 1327 - 1328 - ret = usb_add_function(c, &func->function); 1329 - if (unlikely(ret)) 1330 - ffs_func_free(func); 1331 - 1332 - return ret; 1333 - } 1334 - 1335 - static void ffs_func_free(struct ffs_function *func) 1336 - { 1337 - struct ffs_ep *ep = func->eps; 1338 - unsigned count = func->ffs->eps_count; 1339 - unsigned long flags; 1340 - 1341 - ENTER(); 1342 - 1343 - /* cleanup after autoconfig */ 1344 - spin_lock_irqsave(&func->ffs->eps_lock, flags); 1345 - do { 1346 - if (ep->ep && ep->req) 1347 - usb_ep_free_request(ep->ep, ep->req); 1348 - ep->req = NULL; 1349 - ++ep; 1350 - } while (--count); 1351 - spin_unlock_irqrestore(&func->ffs->eps_lock, flags); 1352 - 1353 - ffs_data_put(func->ffs); 1354 - 1355 - kfree(func->eps); 1356 - /* 1357 - * eps and interfaces_nums are allocated in the same chunk so 1358 - * only one free is required. Descriptors are also allocated 1359 - * in the same chunk. 1360 - */ 1361 - 1362 - kfree(func); 1363 - } 1364 1466 1365 1467 static void ffs_func_eps_disable(struct ffs_function *func) 1366 1468 { ··· 1669 1901 1670 1902 /* Allocate everything in one chunk so there's less maintenance. */ 1671 1903 { 1672 - struct { 1673 - struct usb_gadget_strings *stringtabs[lang_count + 1]; 1674 - struct usb_gadget_strings stringtab[lang_count]; 1675 - struct usb_string strings[lang_count*(needed_count+1)]; 1676 - } *d; 1677 1904 unsigned i = 0; 1905 + vla_group(d); 1906 + vla_item(d, struct usb_gadget_strings *, stringtabs, 1907 + lang_count + 1); 1908 + vla_item(d, struct usb_gadget_strings, stringtab, lang_count); 1909 + vla_item(d, struct usb_string, strings, 1910 + lang_count*(needed_count+1)); 1678 1911 1679 - d = kmalloc(sizeof *d, GFP_KERNEL); 1680 - if (unlikely(!d)) { 1912 + char *vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL); 1913 + 1914 + if (unlikely(!vlabuf)) { 1681 1915 kfree(_data); 1682 1916 return -ENOMEM; 1683 1917 } 1684 1918 1685 - stringtabs = d->stringtabs; 1686 - t = d->stringtab; 1919 + /* Initialize the VLA pointers */ 1920 + stringtabs = vla_ptr(vlabuf, d, stringtabs); 1921 + t = vla_ptr(vlabuf, d, stringtab); 1687 1922 i = lang_count; 1688 1923 do { 1689 1924 *stringtabs++ = t++; 1690 1925 } while (--i); 1691 1926 *stringtabs = NULL; 1692 1927 1693 - stringtabs = d->stringtabs; 1694 - t = d->stringtab; 1695 - s = d->strings; 1928 + /* stringtabs = vlabuf = d_stringtabs for later kfree */ 1929 + stringtabs = vla_ptr(vlabuf, d, stringtabs); 1930 + t = vla_ptr(vlabuf, d, stringtab); 1931 + s = vla_ptr(vlabuf, d, strings); 1696 1932 strings = s; 1697 1933 } 1698 1934 ··· 1959 2187 return 0; 1960 2188 } 1961 2189 1962 - static int ffs_func_bind(struct usb_configuration *c, 1963 - struct usb_function *f) 2190 + static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f, 2191 + struct usb_configuration *c) 2192 + { 2193 + struct ffs_function *func = ffs_func_from_usb(f); 2194 + struct f_fs_opts *ffs_opts = 2195 + container_of(f->fi, struct f_fs_opts, func_inst); 2196 + int ret; 2197 + 2198 + ENTER(); 2199 + 2200 + /* 2201 + * Legacy gadget triggers binding in functionfs_ready_callback, 2202 + * which already uses locking; taking the same lock here would 2203 + * cause a deadlock. 2204 + * 2205 + * Configfs-enabled gadgets however do need ffs_dev_lock. 2206 + */ 2207 + if (!ffs_opts->no_configfs) 2208 + ffs_dev_lock(); 2209 + ret = ffs_opts->dev->desc_ready ? 0 : -ENODEV; 2210 + func->ffs = ffs_opts->dev->ffs_data; 2211 + if (!ffs_opts->no_configfs) 2212 + ffs_dev_unlock(); 2213 + if (ret) 2214 + return ERR_PTR(ret); 2215 + 2216 + func->conf = c; 2217 + func->gadget = c->cdev->gadget; 2218 + 2219 + ffs_data_get(func->ffs); 2220 + 2221 + /* 2222 + * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 2223 + * configurations are bound in sequence with list_for_each_entry, 2224 + * in each configuration its functions are bound in sequence 2225 + * with list_for_each_entry, so we assume no race condition 2226 + * with regard to ffs_opts->bound access 2227 + */ 2228 + if (!ffs_opts->refcnt) { 2229 + ret = functionfs_bind(func->ffs, c->cdev); 2230 + if (ret) 2231 + return ERR_PTR(ret); 2232 + } 2233 + ffs_opts->refcnt++; 2234 + func->function.strings = func->ffs->stringtabs; 2235 + 2236 + return ffs_opts; 2237 + } 2238 + 2239 + static int _ffs_func_bind(struct usb_configuration *c, 2240 + struct usb_function *f) 1964 2241 { 1965 2242 struct ffs_function *func = ffs_func_from_usb(f); 1966 2243 struct ffs_data *ffs = func->ffs; ··· 2021 2200 int ret; 2022 2201 2023 2202 /* Make it a single chunk, less management later on */ 2024 - struct { 2025 - struct ffs_ep eps[ffs->eps_count]; 2026 - struct usb_descriptor_header 2027 - *fs_descs[full ? ffs->fs_descs_count + 1 : 0]; 2028 - struct usb_descriptor_header 2029 - *hs_descs[high ? ffs->hs_descs_count + 1 : 0]; 2030 - short inums[ffs->interfaces_count]; 2031 - char raw_descs[high ? ffs->raw_descs_length 2032 - : ffs->raw_fs_descs_length]; 2033 - } *data; 2203 + vla_group(d); 2204 + vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); 2205 + vla_item_with_sz(d, struct usb_descriptor_header *, fs_descs, 2206 + full ? ffs->fs_descs_count + 1 : 0); 2207 + vla_item_with_sz(d, struct usb_descriptor_header *, hs_descs, 2208 + high ? ffs->hs_descs_count + 1 : 0); 2209 + vla_item_with_sz(d, short, inums, ffs->interfaces_count); 2210 + vla_item_with_sz(d, char, raw_descs, 2211 + high ? ffs->raw_descs_length : ffs->raw_fs_descs_length); 2212 + char *vlabuf; 2034 2213 2035 2214 ENTER(); 2036 2215 ··· 2038 2217 if (unlikely(!(full | high))) 2039 2218 return -ENOTSUPP; 2040 2219 2041 - /* Allocate */ 2042 - data = kmalloc(sizeof *data, GFP_KERNEL); 2043 - if (unlikely(!data)) 2220 + /* Allocate a single chunk, less management later on */ 2221 + vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL); 2222 + if (unlikely(!vlabuf)) 2044 2223 return -ENOMEM; 2045 2224 2046 2225 /* Zero */ 2047 - memset(data->eps, 0, sizeof data->eps); 2048 - memcpy(data->raw_descs, ffs->raw_descs + 16, sizeof data->raw_descs); 2049 - memset(data->inums, 0xff, sizeof data->inums); 2050 - for (ret = ffs->eps_count; ret; --ret) 2051 - data->eps[ret].num = -1; 2226 + memset(vla_ptr(vlabuf, d, eps), 0, d_eps__sz); 2227 + memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs + 16, 2228 + d_raw_descs__sz); 2229 + memset(vla_ptr(vlabuf, d, inums), 0xff, d_inums__sz); 2230 + for (ret = ffs->eps_count; ret; --ret) { 2231 + struct ffs_ep *ptr; 2052 2232 2053 - /* Save pointers */ 2054 - func->eps = data->eps; 2055 - func->interfaces_nums = data->inums; 2233 + ptr = vla_ptr(vlabuf, d, eps); 2234 + ptr[ret].num = -1; 2235 + } 2236 + 2237 + /* Save pointers 2238 + * d_eps == vlabuf, func->eps used to kfree vlabuf later 2239 + */ 2240 + func->eps = vla_ptr(vlabuf, d, eps); 2241 + func->interfaces_nums = vla_ptr(vlabuf, d, inums); 2056 2242 2057 2243 /* 2058 2244 * Go through all the endpoint descriptors and allocate ··· 2067 2239 * numbers without worrying that it may be described later on. 2068 2240 */ 2069 2241 if (likely(full)) { 2070 - func->function.fs_descriptors = data->fs_descs; 2242 + func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs); 2071 2243 ret = ffs_do_descs(ffs->fs_descs_count, 2072 - data->raw_descs, 2073 - sizeof data->raw_descs, 2244 + vla_ptr(vlabuf, d, raw_descs), 2245 + d_raw_descs__sz, 2074 2246 __ffs_func_bind_do_descs, func); 2075 2247 if (unlikely(ret < 0)) 2076 2248 goto error; ··· 2079 2251 } 2080 2252 2081 2253 if (likely(high)) { 2082 - func->function.hs_descriptors = data->hs_descs; 2254 + func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs); 2083 2255 ret = ffs_do_descs(ffs->hs_descs_count, 2084 - data->raw_descs + ret, 2085 - (sizeof data->raw_descs) - ret, 2256 + vla_ptr(vlabuf, d, raw_descs) + ret, 2257 + d_raw_descs__sz - ret, 2086 2258 __ffs_func_bind_do_descs, func); 2087 2259 if (unlikely(ret < 0)) 2088 2260 goto error; ··· 2095 2267 */ 2096 2268 ret = ffs_do_descs(ffs->fs_descs_count + 2097 2269 (high ? ffs->hs_descs_count : 0), 2098 - data->raw_descs, sizeof data->raw_descs, 2270 + vla_ptr(vlabuf, d, raw_descs), d_raw_descs__sz, 2099 2271 __ffs_func_bind_do_nums, func); 2100 2272 if (unlikely(ret < 0)) 2101 2273 goto error; ··· 2109 2281 return ret; 2110 2282 } 2111 2283 2284 + static int ffs_func_bind(struct usb_configuration *c, 2285 + struct usb_function *f) 2286 + { 2287 + struct f_fs_opts *ffs_opts = ffs_do_functionfs_bind(f, c); 2288 + 2289 + if (IS_ERR(ffs_opts)) 2290 + return PTR_ERR(ffs_opts); 2291 + 2292 + return _ffs_func_bind(c, f); 2293 + } 2294 + 2112 2295 2113 2296 /* Other USB function hooks *************************************************/ 2114 - 2115 - static void ffs_func_unbind(struct usb_configuration *c, 2116 - struct usb_function *f) 2117 - { 2118 - struct ffs_function *func = ffs_func_from_usb(f); 2119 - struct ffs_data *ffs = func->ffs; 2120 - 2121 - ENTER(); 2122 - 2123 - if (ffs->func == func) { 2124 - ffs_func_eps_disable(func); 2125 - ffs->func = NULL; 2126 - } 2127 - 2128 - ffs_event_add(ffs, FUNCTIONFS_UNBIND); 2129 - 2130 - ffs_func_free(func); 2131 - } 2132 2297 2133 2298 static int ffs_func_set_alt(struct usb_function *f, 2134 2299 unsigned interface, unsigned alt) ··· 2249 2428 } 2250 2429 2251 2430 2431 + /* Devices management *******************************************************/ 2432 + 2433 + static LIST_HEAD(ffs_devices); 2434 + 2435 + static struct ffs_dev *_ffs_find_dev(const char *name) 2436 + { 2437 + struct ffs_dev *dev; 2438 + 2439 + list_for_each_entry(dev, &ffs_devices, entry) { 2440 + if (!dev->name || !name) 2441 + continue; 2442 + if (strcmp(dev->name, name) == 0) 2443 + return dev; 2444 + } 2445 + 2446 + return NULL; 2447 + } 2448 + 2449 + /* 2450 + * ffs_lock must be taken by the caller of this function 2451 + */ 2452 + static struct ffs_dev *ffs_get_single_dev(void) 2453 + { 2454 + struct ffs_dev *dev; 2455 + 2456 + if (list_is_singular(&ffs_devices)) { 2457 + dev = list_first_entry(&ffs_devices, struct ffs_dev, entry); 2458 + if (dev->single) 2459 + return dev; 2460 + } 2461 + 2462 + return NULL; 2463 + } 2464 + 2465 + /* 2466 + * ffs_lock must be taken by the caller of this function 2467 + */ 2468 + static struct ffs_dev *ffs_find_dev(const char *name) 2469 + { 2470 + struct ffs_dev *dev; 2471 + 2472 + dev = ffs_get_single_dev(); 2473 + if (dev) 2474 + return dev; 2475 + 2476 + return _ffs_find_dev(name); 2477 + } 2478 + 2479 + /* Configfs support *********************************************************/ 2480 + 2481 + static inline struct f_fs_opts *to_ffs_opts(struct config_item *item) 2482 + { 2483 + return container_of(to_config_group(item), struct f_fs_opts, 2484 + func_inst.group); 2485 + } 2486 + 2487 + static void ffs_attr_release(struct config_item *item) 2488 + { 2489 + struct f_fs_opts *opts = to_ffs_opts(item); 2490 + 2491 + usb_put_function_instance(&opts->func_inst); 2492 + } 2493 + 2494 + static struct configfs_item_operations ffs_item_ops = { 2495 + .release = ffs_attr_release, 2496 + }; 2497 + 2498 + static struct config_item_type ffs_func_type = { 2499 + .ct_item_ops = &ffs_item_ops, 2500 + .ct_owner = THIS_MODULE, 2501 + }; 2502 + 2503 + 2504 + /* Function registration interface ******************************************/ 2505 + 2506 + static void ffs_free_inst(struct usb_function_instance *f) 2507 + { 2508 + struct f_fs_opts *opts; 2509 + 2510 + opts = to_f_fs_opts(f); 2511 + ffs_dev_lock(); 2512 + ffs_free_dev(opts->dev); 2513 + ffs_dev_unlock(); 2514 + kfree(opts); 2515 + } 2516 + 2517 + #define MAX_INST_NAME_LEN 40 2518 + 2519 + static int ffs_set_inst_name(struct usb_function_instance *fi, const char *name) 2520 + { 2521 + struct f_fs_opts *opts; 2522 + char *ptr; 2523 + const char *tmp; 2524 + int name_len, ret; 2525 + 2526 + name_len = strlen(name) + 1; 2527 + if (name_len > MAX_INST_NAME_LEN) 2528 + return -ENAMETOOLONG; 2529 + 2530 + ptr = kstrndup(name, name_len, GFP_KERNEL); 2531 + if (!ptr) 2532 + return -ENOMEM; 2533 + 2534 + opts = to_f_fs_opts(fi); 2535 + tmp = NULL; 2536 + 2537 + ffs_dev_lock(); 2538 + 2539 + tmp = opts->dev->name_allocated ? opts->dev->name : NULL; 2540 + ret = _ffs_name_dev(opts->dev, ptr); 2541 + if (ret) { 2542 + kfree(ptr); 2543 + ffs_dev_unlock(); 2544 + return ret; 2545 + } 2546 + opts->dev->name_allocated = true; 2547 + 2548 + ffs_dev_unlock(); 2549 + 2550 + kfree(tmp); 2551 + 2552 + return 0; 2553 + } 2554 + 2555 + static struct usb_function_instance *ffs_alloc_inst(void) 2556 + { 2557 + struct f_fs_opts *opts; 2558 + struct ffs_dev *dev; 2559 + 2560 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 2561 + if (!opts) 2562 + return ERR_PTR(-ENOMEM); 2563 + 2564 + opts->func_inst.set_inst_name = ffs_set_inst_name; 2565 + opts->func_inst.free_func_inst = ffs_free_inst; 2566 + ffs_dev_lock(); 2567 + dev = ffs_alloc_dev(); 2568 + ffs_dev_unlock(); 2569 + if (IS_ERR(dev)) { 2570 + kfree(opts); 2571 + return ERR_CAST(dev); 2572 + } 2573 + opts->dev = dev; 2574 + dev->opts = opts; 2575 + 2576 + config_group_init_type_name(&opts->func_inst.group, "", 2577 + &ffs_func_type); 2578 + return &opts->func_inst; 2579 + } 2580 + 2581 + static void ffs_free(struct usb_function *f) 2582 + { 2583 + kfree(ffs_func_from_usb(f)); 2584 + } 2585 + 2586 + static void ffs_func_unbind(struct usb_configuration *c, 2587 + struct usb_function *f) 2588 + { 2589 + struct ffs_function *func = ffs_func_from_usb(f); 2590 + struct ffs_data *ffs = func->ffs; 2591 + struct f_fs_opts *opts = 2592 + container_of(f->fi, struct f_fs_opts, func_inst); 2593 + struct ffs_ep *ep = func->eps; 2594 + unsigned count = ffs->eps_count; 2595 + unsigned long flags; 2596 + 2597 + ENTER(); 2598 + if (ffs->func == func) { 2599 + ffs_func_eps_disable(func); 2600 + ffs->func = NULL; 2601 + } 2602 + 2603 + if (!--opts->refcnt) 2604 + functionfs_unbind(ffs); 2605 + 2606 + /* cleanup after autoconfig */ 2607 + spin_lock_irqsave(&func->ffs->eps_lock, flags); 2608 + do { 2609 + if (ep->ep && ep->req) 2610 + usb_ep_free_request(ep->ep, ep->req); 2611 + ep->req = NULL; 2612 + ++ep; 2613 + } while (--count); 2614 + spin_unlock_irqrestore(&func->ffs->eps_lock, flags); 2615 + kfree(func->eps); 2616 + func->eps = NULL; 2617 + /* 2618 + * eps, descriptors and interfaces_nums are allocated in the 2619 + * same chunk so only one free is required. 2620 + */ 2621 + func->function.fs_descriptors = NULL; 2622 + func->function.hs_descriptors = NULL; 2623 + func->interfaces_nums = NULL; 2624 + 2625 + ffs_event_add(ffs, FUNCTIONFS_UNBIND); 2626 + } 2627 + 2628 + static struct usb_function *ffs_alloc(struct usb_function_instance *fi) 2629 + { 2630 + struct ffs_function *func; 2631 + 2632 + ENTER(); 2633 + 2634 + func = kzalloc(sizeof(*func), GFP_KERNEL); 2635 + if (unlikely(!func)) 2636 + return ERR_PTR(-ENOMEM); 2637 + 2638 + func->function.name = "Function FS Gadget"; 2639 + 2640 + func->function.bind = ffs_func_bind; 2641 + func->function.unbind = ffs_func_unbind; 2642 + func->function.set_alt = ffs_func_set_alt; 2643 + func->function.disable = ffs_func_disable; 2644 + func->function.setup = ffs_func_setup; 2645 + func->function.suspend = ffs_func_suspend; 2646 + func->function.resume = ffs_func_resume; 2647 + func->function.free_func = ffs_free; 2648 + 2649 + return &func->function; 2650 + } 2651 + 2652 + /* 2653 + * ffs_lock must be taken by the caller of this function 2654 + */ 2655 + struct ffs_dev *ffs_alloc_dev(void) 2656 + { 2657 + struct ffs_dev *dev; 2658 + int ret; 2659 + 2660 + if (ffs_get_single_dev()) 2661 + return ERR_PTR(-EBUSY); 2662 + 2663 + dev = kzalloc(sizeof(*dev), GFP_KERNEL); 2664 + if (!dev) 2665 + return ERR_PTR(-ENOMEM); 2666 + 2667 + if (list_empty(&ffs_devices)) { 2668 + ret = functionfs_init(); 2669 + if (ret) { 2670 + kfree(dev); 2671 + return ERR_PTR(ret); 2672 + } 2673 + } 2674 + 2675 + list_add(&dev->entry, &ffs_devices); 2676 + 2677 + return dev; 2678 + } 2679 + 2680 + /* 2681 + * ffs_lock must be taken by the caller of this function 2682 + * The caller is responsible for "name" being available whenever f_fs needs it 2683 + */ 2684 + static int _ffs_name_dev(struct ffs_dev *dev, const char *name) 2685 + { 2686 + struct ffs_dev *existing; 2687 + 2688 + existing = _ffs_find_dev(name); 2689 + if (existing) 2690 + return -EBUSY; 2691 + 2692 + dev->name = name; 2693 + 2694 + return 0; 2695 + } 2696 + 2697 + /* 2698 + * The caller is responsible for "name" being available whenever f_fs needs it 2699 + */ 2700 + int ffs_name_dev(struct ffs_dev *dev, const char *name) 2701 + { 2702 + int ret; 2703 + 2704 + ffs_dev_lock(); 2705 + ret = _ffs_name_dev(dev, name); 2706 + ffs_dev_unlock(); 2707 + 2708 + return ret; 2709 + } 2710 + EXPORT_SYMBOL(ffs_name_dev); 2711 + 2712 + int ffs_single_dev(struct ffs_dev *dev) 2713 + { 2714 + int ret; 2715 + 2716 + ret = 0; 2717 + ffs_dev_lock(); 2718 + 2719 + if (!list_is_singular(&ffs_devices)) 2720 + ret = -EBUSY; 2721 + else 2722 + dev->single = true; 2723 + 2724 + ffs_dev_unlock(); 2725 + return ret; 2726 + } 2727 + EXPORT_SYMBOL(ffs_single_dev); 2728 + 2729 + /* 2730 + * ffs_lock must be taken by the caller of this function 2731 + */ 2732 + void ffs_free_dev(struct ffs_dev *dev) 2733 + { 2734 + list_del(&dev->entry); 2735 + if (dev->name_allocated) 2736 + kfree(dev->name); 2737 + kfree(dev); 2738 + if (list_empty(&ffs_devices)) 2739 + functionfs_cleanup(); 2740 + } 2741 + 2742 + static void *ffs_acquire_dev(const char *dev_name) 2743 + { 2744 + struct ffs_dev *ffs_dev; 2745 + 2746 + ENTER(); 2747 + ffs_dev_lock(); 2748 + 2749 + ffs_dev = ffs_find_dev(dev_name); 2750 + if (!ffs_dev) 2751 + ffs_dev = ERR_PTR(-ENODEV); 2752 + else if (ffs_dev->mounted) 2753 + ffs_dev = ERR_PTR(-EBUSY); 2754 + else if (ffs_dev->ffs_acquire_dev_callback && 2755 + ffs_dev->ffs_acquire_dev_callback(ffs_dev)) 2756 + ffs_dev = ERR_PTR(-ENODEV); 2757 + else 2758 + ffs_dev->mounted = true; 2759 + 2760 + ffs_dev_unlock(); 2761 + return ffs_dev; 2762 + } 2763 + 2764 + static void ffs_release_dev(struct ffs_data *ffs_data) 2765 + { 2766 + struct ffs_dev *ffs_dev; 2767 + 2768 + ENTER(); 2769 + ffs_dev_lock(); 2770 + 2771 + ffs_dev = ffs_data->private_data; 2772 + if (ffs_dev) 2773 + ffs_dev->mounted = false; 2774 + 2775 + if (ffs_dev->ffs_release_dev_callback) 2776 + ffs_dev->ffs_release_dev_callback(ffs_dev); 2777 + 2778 + ffs_dev_unlock(); 2779 + } 2780 + 2781 + static int ffs_ready(struct ffs_data *ffs) 2782 + { 2783 + struct ffs_dev *ffs_obj; 2784 + int ret = 0; 2785 + 2786 + ENTER(); 2787 + ffs_dev_lock(); 2788 + 2789 + ffs_obj = ffs->private_data; 2790 + if (!ffs_obj) { 2791 + ret = -EINVAL; 2792 + goto done; 2793 + } 2794 + if (WARN_ON(ffs_obj->desc_ready)) { 2795 + ret = -EBUSY; 2796 + goto done; 2797 + } 2798 + 2799 + ffs_obj->desc_ready = true; 2800 + ffs_obj->ffs_data = ffs; 2801 + 2802 + if (ffs_obj->ffs_ready_callback) 2803 + ret = ffs_obj->ffs_ready_callback(ffs); 2804 + 2805 + done: 2806 + ffs_dev_unlock(); 2807 + return ret; 2808 + } 2809 + 2810 + static void ffs_closed(struct ffs_data *ffs) 2811 + { 2812 + struct ffs_dev *ffs_obj; 2813 + 2814 + ENTER(); 2815 + ffs_dev_lock(); 2816 + 2817 + ffs_obj = ffs->private_data; 2818 + if (!ffs_obj) 2819 + goto done; 2820 + 2821 + ffs_obj->desc_ready = false; 2822 + 2823 + if (ffs_obj->ffs_closed_callback) 2824 + ffs_obj->ffs_closed_callback(ffs); 2825 + 2826 + if (!ffs_obj->opts || ffs_obj->opts->no_configfs 2827 + || !ffs_obj->opts->func_inst.group.cg_item.ci_parent) 2828 + goto done; 2829 + 2830 + unregister_gadget_item(ffs_obj->opts-> 2831 + func_inst.group.cg_item.ci_parent->ci_parent); 2832 + done: 2833 + ffs_dev_unlock(); 2834 + } 2835 + 2252 2836 /* Misc helper functions ****************************************************/ 2253 2837 2254 2838 static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock) ··· 2684 2458 2685 2459 return data; 2686 2460 } 2461 + 2462 + DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc); 2463 + MODULE_LICENSE("GPL"); 2464 + MODULE_AUTHOR("Michal Nazarewicz");
+5 -13
drivers/usb/gadget/f_hid.c
··· 20 20 #include <linux/sched.h> 21 21 #include <linux/usb/g_hid.h> 22 22 23 + #include "u_f.h" 24 + 23 25 static int major, minors; 24 26 static struct class *hidg_class; 25 27 ··· 336 334 /*-------------------------------------------------------------------------*/ 337 335 /* usb_function */ 338 336 339 - static struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep, unsigned length) 337 + static inline struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep, 338 + unsigned length) 340 339 { 341 - struct usb_request *req; 342 - 343 - req = usb_ep_alloc_request(ep, GFP_ATOMIC); 344 - if (req) { 345 - req->length = length; 346 - req->buf = kmalloc(length, GFP_ATOMIC); 347 - if (!req->buf) { 348 - usb_ep_free_request(ep, req); 349 - req = NULL; 350 - } 351 - } 352 - return req; 340 + return alloc_ep_req(ep, length, length); 353 341 } 354 342 355 343 static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req)
+141 -3
drivers/usb/gadget/f_loopback.c
··· 20 20 #include <linux/usb/composite.h> 21 21 22 22 #include "g_zero.h" 23 + #include "u_f.h" 23 24 24 25 /* 25 26 * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals, ··· 120 119 .wMaxPacketSize = cpu_to_le16(1024), 121 120 }; 122 121 123 - struct usb_ss_ep_comp_descriptor ss_loop_source_comp_desc = { 122 + static struct usb_ss_ep_comp_descriptor ss_loop_source_comp_desc = { 124 123 .bLength = USB_DT_SS_EP_COMP_SIZE, 125 124 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 126 125 .bMaxBurst = 0, ··· 136 135 .wMaxPacketSize = cpu_to_le16(1024), 137 136 }; 138 137 139 - struct usb_ss_ep_comp_descriptor ss_loop_sink_comp_desc = { 138 + static struct usb_ss_ep_comp_descriptor ss_loop_sink_comp_desc = { 140 139 .bLength = USB_DT_SS_EP_COMP_SIZE, 141 140 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 142 141 .bMaxBurst = 0, ··· 231 230 232 231 static void lb_free_func(struct usb_function *f) 233 232 { 233 + struct f_lb_opts *opts; 234 + 235 + opts = container_of(f->fi, struct f_lb_opts, func_inst); 236 + 237 + mutex_lock(&opts->lock); 238 + opts->refcnt--; 239 + mutex_unlock(&opts->lock); 240 + 234 241 usb_free_all_descriptors(f); 235 242 kfree(func_to_loop(f)); 236 243 } ··· 302 293 VDBG(cdev, "%s disabled\n", loop->function.name); 303 294 } 304 295 296 + static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int len) 297 + { 298 + return alloc_ep_req(ep, len, buflen); 299 + } 300 + 305 301 static int 306 302 enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop) 307 303 { ··· 346 332 * than 'buflen' bytes each. 347 333 */ 348 334 for (i = 0; i < qlen && result == 0; i++) { 349 - req = alloc_ep_req(ep, 0); 335 + req = lb_alloc_ep_req(ep, 0); 350 336 if (req) { 351 337 req->complete = loopback_complete; 352 338 result = usb_ep_queue(ep, req, GFP_ATOMIC); ··· 394 380 return ERR_PTR(-ENOMEM); 395 381 396 382 lb_opts = container_of(fi, struct f_lb_opts, func_inst); 383 + 384 + mutex_lock(&lb_opts->lock); 385 + lb_opts->refcnt++; 386 + mutex_unlock(&lb_opts->lock); 387 + 397 388 buflen = lb_opts->bulk_buflen; 398 389 qlen = lb_opts->qlen; 399 390 if (!qlen) ··· 415 396 return &loop->function; 416 397 } 417 398 399 + static inline struct f_lb_opts *to_f_lb_opts(struct config_item *item) 400 + { 401 + return container_of(to_config_group(item), struct f_lb_opts, 402 + func_inst.group); 403 + } 404 + 405 + CONFIGFS_ATTR_STRUCT(f_lb_opts); 406 + CONFIGFS_ATTR_OPS(f_lb_opts); 407 + 408 + static void lb_attr_release(struct config_item *item) 409 + { 410 + struct f_lb_opts *lb_opts = to_f_lb_opts(item); 411 + 412 + usb_put_function_instance(&lb_opts->func_inst); 413 + } 414 + 415 + static struct configfs_item_operations lb_item_ops = { 416 + .release = lb_attr_release, 417 + .show_attribute = f_lb_opts_attr_show, 418 + .store_attribute = f_lb_opts_attr_store, 419 + }; 420 + 421 + static ssize_t f_lb_opts_qlen_show(struct f_lb_opts *opts, char *page) 422 + { 423 + int result; 424 + 425 + mutex_lock(&opts->lock); 426 + result = sprintf(page, "%d", opts->qlen); 427 + mutex_unlock(&opts->lock); 428 + 429 + return result; 430 + } 431 + 432 + static ssize_t f_lb_opts_qlen_store(struct f_lb_opts *opts, 433 + const char *page, size_t len) 434 + { 435 + int ret; 436 + u32 num; 437 + 438 + mutex_lock(&opts->lock); 439 + if (opts->refcnt) { 440 + ret = -EBUSY; 441 + goto end; 442 + } 443 + 444 + ret = kstrtou32(page, 0, &num); 445 + if (ret) 446 + goto end; 447 + 448 + opts->qlen = num; 449 + ret = len; 450 + end: 451 + mutex_unlock(&opts->lock); 452 + return ret; 453 + } 454 + 455 + static struct f_lb_opts_attribute f_lb_opts_qlen = 456 + __CONFIGFS_ATTR(qlen, S_IRUGO | S_IWUSR, 457 + f_lb_opts_qlen_show, 458 + f_lb_opts_qlen_store); 459 + 460 + static ssize_t f_lb_opts_bulk_buflen_show(struct f_lb_opts *opts, char *page) 461 + { 462 + int result; 463 + 464 + mutex_lock(&opts->lock); 465 + result = sprintf(page, "%d", opts->bulk_buflen); 466 + mutex_unlock(&opts->lock); 467 + 468 + return result; 469 + } 470 + 471 + static ssize_t f_lb_opts_bulk_buflen_store(struct f_lb_opts *opts, 472 + const char *page, size_t len) 473 + { 474 + int ret; 475 + u32 num; 476 + 477 + mutex_lock(&opts->lock); 478 + if (opts->refcnt) { 479 + ret = -EBUSY; 480 + goto end; 481 + } 482 + 483 + ret = kstrtou32(page, 0, &num); 484 + if (ret) 485 + goto end; 486 + 487 + opts->bulk_buflen = num; 488 + ret = len; 489 + end: 490 + mutex_unlock(&opts->lock); 491 + return ret; 492 + } 493 + 494 + static struct f_lb_opts_attribute f_lb_opts_bulk_buflen = 495 + __CONFIGFS_ATTR(buflen, S_IRUGO | S_IWUSR, 496 + f_lb_opts_bulk_buflen_show, 497 + f_lb_opts_bulk_buflen_store); 498 + 499 + static struct configfs_attribute *lb_attrs[] = { 500 + &f_lb_opts_qlen.attr, 501 + &f_lb_opts_bulk_buflen.attr, 502 + NULL, 503 + }; 504 + 505 + static struct config_item_type lb_func_type = { 506 + .ct_item_ops = &lb_item_ops, 507 + .ct_attrs = lb_attrs, 508 + .ct_owner = THIS_MODULE, 509 + }; 510 + 418 511 static void lb_free_instance(struct usb_function_instance *fi) 419 512 { 420 513 struct f_lb_opts *lb_opts; ··· 542 411 lb_opts = kzalloc(sizeof(*lb_opts), GFP_KERNEL); 543 412 if (!lb_opts) 544 413 return ERR_PTR(-ENOMEM); 414 + mutex_init(&lb_opts->lock); 545 415 lb_opts->func_inst.free_func_inst = lb_free_instance; 416 + lb_opts->bulk_buflen = GZERO_BULK_BUFLEN; 417 + lb_opts->qlen = GZERO_QLEN; 418 + 419 + config_group_init_type_name(&lb_opts->func_inst.group, "", 420 + &lb_func_type); 421 + 546 422 return &lb_opts->func_inst; 547 423 } 548 424 DECLARE_USB_FUNCTION(Loopback, loopback_alloc_instance, loopback_alloc);
+7 -15
drivers/usb/gadget/f_midi.c
··· 32 32 #include <linux/usb/audio.h> 33 33 #include <linux/usb/midi.h> 34 34 35 + #include "u_f.h" 36 + 35 37 MODULE_AUTHOR("Ben Williamson"); 36 38 MODULE_LICENSE("GPL v2"); 37 39 ··· 193 191 NULL, 194 192 }; 195 193 196 - static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length) 194 + static inline struct usb_request *midi_alloc_ep_req(struct usb_ep *ep, 195 + unsigned length) 197 196 { 198 - struct usb_request *req; 199 - 200 - req = usb_ep_alloc_request(ep, GFP_ATOMIC); 201 - if (req) { 202 - req->length = length; 203 - req->buf = kmalloc(length, GFP_ATOMIC); 204 - if (!req->buf) { 205 - usb_ep_free_request(ep, req); 206 - req = NULL; 207 - } 208 - } 209 - return req; 197 + return alloc_ep_req(ep, length, length); 210 198 } 211 199 212 200 static void free_ep_req(struct usb_ep *ep, struct usb_request *req) ··· 357 365 /* allocate a bunch of read buffers and queue them all at once. */ 358 366 for (i = 0; i < midi->qlen && err == 0; i++) { 359 367 struct usb_request *req = 360 - alloc_ep_req(midi->out_ep, midi->buflen); 368 + midi_alloc_ep_req(midi->out_ep, midi->buflen); 361 369 if (req == NULL) 362 370 return -ENOMEM; 363 371 ··· 538 546 return; 539 547 540 548 if (!req) 541 - req = alloc_ep_req(ep, midi->buflen); 549 + req = midi_alloc_ep_req(ep, midi->buflen); 542 550 543 551 if (!req) { 544 552 ERROR(midi, "gmidi_transmit: alloc_ep_request failed\n");
+1 -1
drivers/usb/gadget/f_ncm.c
··· 1386 1386 usb_ep_free_request(ncm->notify, ncm->notify_req); 1387 1387 } 1388 1388 1389 - struct usb_function *ncm_alloc(struct usb_function_instance *fi) 1389 + static struct usb_function *ncm_alloc(struct usb_function_instance *fi) 1390 1390 { 1391 1391 struct f_ncm *ncm; 1392 1392 struct f_ncm_opts *opts;
+1 -1
drivers/usb/gadget/f_obex.c
··· 499 499 usb_free_all_descriptors(f); 500 500 } 501 501 502 - struct usb_function *obex_alloc(struct usb_function_instance *fi) 502 + static struct usb_function *obex_alloc(struct usb_function_instance *fi) 503 503 { 504 504 struct f_obex *obex; 505 505 struct f_serial_opts *opts;
+1 -1
drivers/usb/gadget/f_phonet.c
··· 689 689 usb_free_all_descriptors(f); 690 690 } 691 691 692 - struct usb_function *phonet_alloc(struct usb_function_instance *fi) 692 + static struct usb_function *phonet_alloc(struct usb_function_instance *fi) 693 693 { 694 694 struct f_phonet *fp; 695 695 struct f_phonet_opts *opts;
+22 -72
drivers/usb/gadget/f_rndis.c
··· 675 675 int status; 676 676 struct usb_ep *ep; 677 677 678 - #ifndef USB_FRNDIS_INCLUDED 679 678 struct f_rndis_opts *rndis_opts; 680 679 681 680 if (!can_support_rndis(c)) ··· 696 697 return status; 697 698 rndis_opts->bound = true; 698 699 } 699 - #endif 700 + 700 701 us = usb_gstrings_attach(cdev, rndis_strings, 701 702 ARRAY_SIZE(rndis_string_defs)); 702 703 if (IS_ERR(us)) ··· 781 782 rndis->port.open = rndis_open; 782 783 rndis->port.close = rndis_close; 783 784 784 - #ifdef USB_FRNDIS_INCLUDED 785 - status = rndis_register(rndis_response_available, rndis); 786 - if (status < 0) 787 - goto fail; 788 - rndis->config = status; 789 - #endif 790 - 791 785 rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); 792 786 rndis_set_host_mac(rndis->config, rndis->ethaddr); 793 787 ··· 821 829 822 830 return status; 823 831 } 824 - 825 - #ifdef USB_FRNDIS_INCLUDED 826 - 827 - static void 828 - rndis_old_unbind(struct usb_configuration *c, struct usb_function *f) 829 - { 830 - struct f_rndis *rndis = func_to_rndis(f); 831 - 832 - rndis_deregister(rndis->config); 833 - 834 - usb_free_all_descriptors(f); 835 - 836 - kfree(rndis->notify_req->buf); 837 - usb_ep_free_request(rndis->notify, rndis->notify_req); 838 - 839 - kfree(rndis); 840 - } 841 - 842 - int 843 - rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 844 - u32 vendorID, const char *manufacturer, struct eth_dev *dev) 845 - { 846 - struct f_rndis *rndis; 847 - int status; 848 - 849 - /* allocate and initialize one new instance */ 850 - status = -ENOMEM; 851 - rndis = kzalloc(sizeof *rndis, GFP_KERNEL); 852 - if (!rndis) 853 - goto fail; 854 - 855 - memcpy(rndis->ethaddr, ethaddr, ETH_ALEN); 856 - rndis->vendorID = vendorID; 857 - rndis->manufacturer = manufacturer; 858 - 859 - rndis->port.ioport = dev; 860 - /* RNDIS activates when the host changes this filter */ 861 - rndis->port.cdc_filter = 0; 862 - 863 - /* RNDIS has special (and complex) framing */ 864 - rndis->port.header_len = sizeof(struct rndis_packet_msg_type); 865 - rndis->port.wrap = rndis_add_header; 866 - rndis->port.unwrap = rndis_rm_hdr; 867 - 868 - rndis->port.func.name = "rndis"; 869 - /* descriptors are per-instance copies */ 870 - rndis->port.func.bind = rndis_bind; 871 - rndis->port.func.unbind = rndis_old_unbind; 872 - rndis->port.func.set_alt = rndis_set_alt; 873 - rndis->port.func.setup = rndis_setup; 874 - rndis->port.func.disable = rndis_disable; 875 - 876 - status = usb_add_function(c, &rndis->port.func); 877 - if (status) 878 - kfree(rndis); 879 - fail: 880 - return status; 881 - } 882 - 883 - #else 884 832 885 833 void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net) 886 834 { ··· 979 1047 return &rndis->port.func; 980 1048 } 981 1049 982 - DECLARE_USB_FUNCTION_INIT(rndis, rndis_alloc_inst, rndis_alloc); 1050 + DECLARE_USB_FUNCTION(rndis, rndis_alloc_inst, rndis_alloc); 1051 + 1052 + static int __init rndis_mod_init(void) 1053 + { 1054 + int ret; 1055 + 1056 + ret = rndis_init(); 1057 + if (ret) 1058 + return ret; 1059 + 1060 + return usb_function_register(&rndisusb_func); 1061 + } 1062 + module_init(rndis_mod_init); 1063 + 1064 + static void __exit rndis_mod_exit(void) 1065 + { 1066 + usb_function_unregister(&rndisusb_func); 1067 + rndis_exit(); 1068 + } 1069 + module_exit(rndis_mod_exit); 1070 + 983 1071 MODULE_LICENSE("GPL"); 984 1072 MODULE_AUTHOR("David Brownell"); 985 - 986 - #endif
+1 -1
drivers/usb/gadget/f_serial.c
··· 354 354 usb_free_all_descriptors(f); 355 355 } 356 356 357 - struct usb_function *gser_alloc(struct usb_function_instance *fi) 357 + static struct usb_function *gser_alloc(struct usb_function_instance *fi) 358 358 { 359 359 struct f_gser *gser; 360 360 struct f_serial_opts *opts;
+327 -22
drivers/usb/gadget/f_sourcesink.c
··· 21 21 22 22 #include "g_zero.h" 23 23 #include "gadget_chips.h" 24 + #include "u_f.h" 24 25 25 26 /* 26 27 * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral ··· 202 201 .wMaxPacketSize = cpu_to_le16(1024), 203 202 }; 204 203 205 - struct usb_ss_ep_comp_descriptor ss_source_comp_desc = { 204 + static struct usb_ss_ep_comp_descriptor ss_source_comp_desc = { 206 205 .bLength = USB_DT_SS_EP_COMP_SIZE, 207 206 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 208 207 ··· 219 218 .wMaxPacketSize = cpu_to_le16(1024), 220 219 }; 221 220 222 - struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = { 221 + static struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = { 223 222 .bLength = USB_DT_SS_EP_COMP_SIZE, 224 223 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 225 224 ··· 237 236 .bInterval = 4, 238 237 }; 239 238 240 - struct usb_ss_ep_comp_descriptor ss_iso_source_comp_desc = { 239 + static struct usb_ss_ep_comp_descriptor ss_iso_source_comp_desc = { 241 240 .bLength = USB_DT_SS_EP_COMP_SIZE, 242 241 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 243 242 ··· 255 254 .bInterval = 4, 256 255 }; 257 256 258 - struct usb_ss_ep_comp_descriptor ss_iso_sink_comp_desc = { 257 + static struct usb_ss_ep_comp_descriptor ss_iso_sink_comp_desc = { 259 258 .bLength = USB_DT_SS_EP_COMP_SIZE, 260 259 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 261 260 ··· 302 301 303 302 /*-------------------------------------------------------------------------*/ 304 303 305 - struct usb_request *alloc_ep_req(struct usb_ep *ep, int len) 304 + static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len) 306 305 { 307 - struct usb_request *req; 308 - 309 - req = usb_ep_alloc_request(ep, GFP_ATOMIC); 310 - if (req) { 311 - if (len) 312 - req->length = len; 313 - else 314 - req->length = buflen; 315 - req->buf = kmalloc(req->length, GFP_ATOMIC); 316 - if (!req->buf) { 317 - usb_ep_free_request(ep, req); 318 - req = NULL; 319 - } 320 - } 321 - return req; 306 + return alloc_ep_req(ep, len, buflen); 322 307 } 323 308 324 309 void free_ep_req(struct usb_ep *ep, struct usb_request *req) ··· 477 490 static void 478 491 sourcesink_free_func(struct usb_function *f) 479 492 { 493 + struct f_ss_opts *opts; 494 + 495 + opts = container_of(f->fi, struct f_ss_opts, func_inst); 496 + 497 + mutex_lock(&opts->lock); 498 + opts->refcnt--; 499 + mutex_unlock(&opts->lock); 500 + 480 501 usb_free_all_descriptors(f); 481 502 kfree(func_to_ss(f)); 482 503 } ··· 623 628 break; 624 629 } 625 630 ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; 626 - req = alloc_ep_req(ep, size); 631 + req = ss_alloc_ep_req(ep, size); 627 632 } else { 628 633 ep = is_in ? ss->in_ep : ss->out_ep; 629 - req = alloc_ep_req(ep, 0); 634 + req = ss_alloc_ep_req(ep, 0); 630 635 } 631 636 632 637 if (!req) ··· 873 878 return NULL; 874 879 875 880 ss_opts = container_of(fi, struct f_ss_opts, func_inst); 881 + 882 + mutex_lock(&ss_opts->lock); 883 + ss_opts->refcnt++; 884 + mutex_unlock(&ss_opts->lock); 885 + 876 886 pattern = ss_opts->pattern; 877 887 isoc_interval = ss_opts->isoc_interval; 878 888 isoc_maxpacket = ss_opts->isoc_maxpacket; ··· 898 898 return &ss->function; 899 899 } 900 900 901 + static inline struct f_ss_opts *to_f_ss_opts(struct config_item *item) 902 + { 903 + return container_of(to_config_group(item), struct f_ss_opts, 904 + func_inst.group); 905 + } 906 + 907 + CONFIGFS_ATTR_STRUCT(f_ss_opts); 908 + CONFIGFS_ATTR_OPS(f_ss_opts); 909 + 910 + static void ss_attr_release(struct config_item *item) 911 + { 912 + struct f_ss_opts *ss_opts = to_f_ss_opts(item); 913 + 914 + usb_put_function_instance(&ss_opts->func_inst); 915 + } 916 + 917 + static struct configfs_item_operations ss_item_ops = { 918 + .release = ss_attr_release, 919 + .show_attribute = f_ss_opts_attr_show, 920 + .store_attribute = f_ss_opts_attr_store, 921 + }; 922 + 923 + static ssize_t f_ss_opts_pattern_show(struct f_ss_opts *opts, char *page) 924 + { 925 + int result; 926 + 927 + mutex_lock(&opts->lock); 928 + result = sprintf(page, "%d", opts->pattern); 929 + mutex_unlock(&opts->lock); 930 + 931 + return result; 932 + } 933 + 934 + static ssize_t f_ss_opts_pattern_store(struct f_ss_opts *opts, 935 + const char *page, size_t len) 936 + { 937 + int ret; 938 + u8 num; 939 + 940 + mutex_lock(&opts->lock); 941 + if (opts->refcnt) { 942 + ret = -EBUSY; 943 + goto end; 944 + } 945 + 946 + ret = kstrtou8(page, 0, &num); 947 + if (ret) 948 + goto end; 949 + 950 + if (num != 0 && num != 1 && num != 2) { 951 + ret = -EINVAL; 952 + goto end; 953 + } 954 + 955 + opts->pattern = num; 956 + ret = len; 957 + end: 958 + mutex_unlock(&opts->lock); 959 + return ret; 960 + } 961 + 962 + static struct f_ss_opts_attribute f_ss_opts_pattern = 963 + __CONFIGFS_ATTR(pattern, S_IRUGO | S_IWUSR, 964 + f_ss_opts_pattern_show, 965 + f_ss_opts_pattern_store); 966 + 967 + static ssize_t f_ss_opts_isoc_interval_show(struct f_ss_opts *opts, char *page) 968 + { 969 + int result; 970 + 971 + mutex_lock(&opts->lock); 972 + result = sprintf(page, "%d", opts->isoc_interval); 973 + mutex_unlock(&opts->lock); 974 + 975 + return result; 976 + } 977 + 978 + static ssize_t f_ss_opts_isoc_interval_store(struct f_ss_opts *opts, 979 + const char *page, size_t len) 980 + { 981 + int ret; 982 + u8 num; 983 + 984 + mutex_lock(&opts->lock); 985 + if (opts->refcnt) { 986 + ret = -EBUSY; 987 + goto end; 988 + } 989 + 990 + ret = kstrtou8(page, 0, &num); 991 + if (ret) 992 + goto end; 993 + 994 + if (num > 16) { 995 + ret = -EINVAL; 996 + goto end; 997 + } 998 + 999 + opts->isoc_interval = num; 1000 + ret = len; 1001 + end: 1002 + mutex_unlock(&opts->lock); 1003 + return ret; 1004 + } 1005 + 1006 + static struct f_ss_opts_attribute f_ss_opts_isoc_interval = 1007 + __CONFIGFS_ATTR(isoc_interval, S_IRUGO | S_IWUSR, 1008 + f_ss_opts_isoc_interval_show, 1009 + f_ss_opts_isoc_interval_store); 1010 + 1011 + static ssize_t f_ss_opts_isoc_maxpacket_show(struct f_ss_opts *opts, char *page) 1012 + { 1013 + int result; 1014 + 1015 + mutex_lock(&opts->lock); 1016 + result = sprintf(page, "%d", opts->isoc_maxpacket); 1017 + mutex_unlock(&opts->lock); 1018 + 1019 + return result; 1020 + } 1021 + 1022 + static ssize_t f_ss_opts_isoc_maxpacket_store(struct f_ss_opts *opts, 1023 + const char *page, size_t len) 1024 + { 1025 + int ret; 1026 + u16 num; 1027 + 1028 + mutex_lock(&opts->lock); 1029 + if (opts->refcnt) { 1030 + ret = -EBUSY; 1031 + goto end; 1032 + } 1033 + 1034 + ret = kstrtou16(page, 0, &num); 1035 + if (ret) 1036 + goto end; 1037 + 1038 + if (num > 1024) { 1039 + ret = -EINVAL; 1040 + goto end; 1041 + } 1042 + 1043 + opts->isoc_maxpacket = num; 1044 + ret = len; 1045 + end: 1046 + mutex_unlock(&opts->lock); 1047 + return ret; 1048 + } 1049 + 1050 + static struct f_ss_opts_attribute f_ss_opts_isoc_maxpacket = 1051 + __CONFIGFS_ATTR(isoc_maxpacket, S_IRUGO | S_IWUSR, 1052 + f_ss_opts_isoc_maxpacket_show, 1053 + f_ss_opts_isoc_maxpacket_store); 1054 + 1055 + static ssize_t f_ss_opts_isoc_mult_show(struct f_ss_opts *opts, char *page) 1056 + { 1057 + int result; 1058 + 1059 + mutex_lock(&opts->lock); 1060 + result = sprintf(page, "%d", opts->isoc_mult); 1061 + mutex_unlock(&opts->lock); 1062 + 1063 + return result; 1064 + } 1065 + 1066 + static ssize_t f_ss_opts_isoc_mult_store(struct f_ss_opts *opts, 1067 + const char *page, size_t len) 1068 + { 1069 + int ret; 1070 + u8 num; 1071 + 1072 + mutex_lock(&opts->lock); 1073 + if (opts->refcnt) { 1074 + ret = -EBUSY; 1075 + goto end; 1076 + } 1077 + 1078 + ret = kstrtou8(page, 0, &num); 1079 + if (ret) 1080 + goto end; 1081 + 1082 + if (num > 2) { 1083 + ret = -EINVAL; 1084 + goto end; 1085 + } 1086 + 1087 + opts->isoc_mult = num; 1088 + ret = len; 1089 + end: 1090 + mutex_unlock(&opts->lock); 1091 + return ret; 1092 + } 1093 + 1094 + static struct f_ss_opts_attribute f_ss_opts_isoc_mult = 1095 + __CONFIGFS_ATTR(isoc_mult, S_IRUGO | S_IWUSR, 1096 + f_ss_opts_isoc_mult_show, 1097 + f_ss_opts_isoc_mult_store); 1098 + 1099 + static ssize_t f_ss_opts_isoc_maxburst_show(struct f_ss_opts *opts, char *page) 1100 + { 1101 + int result; 1102 + 1103 + mutex_lock(&opts->lock); 1104 + result = sprintf(page, "%d", opts->isoc_maxburst); 1105 + mutex_unlock(&opts->lock); 1106 + 1107 + return result; 1108 + } 1109 + 1110 + static ssize_t f_ss_opts_isoc_maxburst_store(struct f_ss_opts *opts, 1111 + const char *page, size_t len) 1112 + { 1113 + int ret; 1114 + u8 num; 1115 + 1116 + mutex_lock(&opts->lock); 1117 + if (opts->refcnt) { 1118 + ret = -EBUSY; 1119 + goto end; 1120 + } 1121 + 1122 + ret = kstrtou8(page, 0, &num); 1123 + if (ret) 1124 + goto end; 1125 + 1126 + if (num > 15) { 1127 + ret = -EINVAL; 1128 + goto end; 1129 + } 1130 + 1131 + opts->isoc_maxburst = num; 1132 + ret = len; 1133 + end: 1134 + mutex_unlock(&opts->lock); 1135 + return ret; 1136 + } 1137 + 1138 + static struct f_ss_opts_attribute f_ss_opts_isoc_maxburst = 1139 + __CONFIGFS_ATTR(isoc_maxburst, S_IRUGO | S_IWUSR, 1140 + f_ss_opts_isoc_maxburst_show, 1141 + f_ss_opts_isoc_maxburst_store); 1142 + 1143 + static ssize_t f_ss_opts_bulk_buflen_show(struct f_ss_opts *opts, char *page) 1144 + { 1145 + int result; 1146 + 1147 + mutex_lock(&opts->lock); 1148 + result = sprintf(page, "%d", opts->bulk_buflen); 1149 + mutex_unlock(&opts->lock); 1150 + 1151 + return result; 1152 + } 1153 + 1154 + static ssize_t f_ss_opts_bulk_buflen_store(struct f_ss_opts *opts, 1155 + const char *page, size_t len) 1156 + { 1157 + int ret; 1158 + u32 num; 1159 + 1160 + mutex_lock(&opts->lock); 1161 + if (opts->refcnt) { 1162 + ret = -EBUSY; 1163 + goto end; 1164 + } 1165 + 1166 + ret = kstrtou32(page, 0, &num); 1167 + if (ret) 1168 + goto end; 1169 + 1170 + opts->bulk_buflen = num; 1171 + ret = len; 1172 + end: 1173 + mutex_unlock(&opts->lock); 1174 + return ret; 1175 + } 1176 + 1177 + static struct f_ss_opts_attribute f_ss_opts_bulk_buflen = 1178 + __CONFIGFS_ATTR(buflen, S_IRUGO | S_IWUSR, 1179 + f_ss_opts_bulk_buflen_show, 1180 + f_ss_opts_bulk_buflen_store); 1181 + 1182 + static struct configfs_attribute *ss_attrs[] = { 1183 + &f_ss_opts_pattern.attr, 1184 + &f_ss_opts_isoc_interval.attr, 1185 + &f_ss_opts_isoc_maxpacket.attr, 1186 + &f_ss_opts_isoc_mult.attr, 1187 + &f_ss_opts_isoc_maxburst.attr, 1188 + &f_ss_opts_bulk_buflen.attr, 1189 + NULL, 1190 + }; 1191 + 1192 + static struct config_item_type ss_func_type = { 1193 + .ct_item_ops = &ss_item_ops, 1194 + .ct_attrs = ss_attrs, 1195 + .ct_owner = THIS_MODULE, 1196 + }; 1197 + 901 1198 static void source_sink_free_instance(struct usb_function_instance *fi) 902 1199 { 903 1200 struct f_ss_opts *ss_opts; ··· 1210 913 ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL); 1211 914 if (!ss_opts) 1212 915 return ERR_PTR(-ENOMEM); 916 + mutex_init(&ss_opts->lock); 1213 917 ss_opts->func_inst.free_func_inst = source_sink_free_instance; 918 + ss_opts->isoc_interval = GZERO_ISOC_INTERVAL; 919 + ss_opts->isoc_maxpacket = GZERO_ISOC_MAXPACKET; 920 + ss_opts->bulk_buflen = GZERO_BULK_BUFLEN; 921 + 922 + config_group_init_type_name(&ss_opts->func_inst.group, "", 923 + &ss_func_type); 924 + 1214 925 return &ss_opts->func_inst; 1215 926 } 1216 927 DECLARE_USB_FUNCTION(SourceSink, source_sink_alloc_inst,
+1 -59
drivers/usb/gadget/f_subset.c
··· 301 301 int status; 302 302 struct usb_ep *ep; 303 303 304 - #ifndef USB_FSUBSET_INCLUDED 305 304 struct f_gether_opts *gether_opts; 306 305 307 306 gether_opts = container_of(f->fi, struct f_gether_opts, func_inst); ··· 321 322 return status; 322 323 gether_opts->bound = true; 323 324 } 324 - #endif 325 + 325 326 us = usb_gstrings_attach(cdev, geth_strings, 326 327 ARRAY_SIZE(geth_string_defs)); 327 328 if (IS_ERR(us)) ··· 391 392 392 393 return status; 393 394 } 394 - 395 - #ifdef USB_FSUBSET_INCLUDED 396 - 397 - static void 398 - geth_old_unbind(struct usb_configuration *c, struct usb_function *f) 399 - { 400 - geth_string_defs[0].id = 0; 401 - usb_free_all_descriptors(f); 402 - kfree(func_to_geth(f)); 403 - } 404 - 405 - /** 406 - * geth_bind_config - add CDC Subset network link to a configuration 407 - * @c: the configuration to support the network link 408 - * @ethaddr: a buffer in which the ethernet address of the host side 409 - * side of the link was recorded 410 - * @dev: eth_dev structure 411 - * Context: single threaded during gadget setup 412 - * 413 - * Returns zero on success, else negative errno. 414 - * 415 - * Caller must have called @gether_setup(). Caller is also responsible 416 - * for calling @gether_cleanup() before module unload. 417 - */ 418 - int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 419 - struct eth_dev *dev) 420 - { 421 - struct f_gether *geth; 422 - int status; 423 - 424 - /* allocate and initialize one new instance */ 425 - geth = kzalloc(sizeof *geth, GFP_KERNEL); 426 - if (!geth) 427 - return -ENOMEM; 428 - 429 - /* export host's Ethernet address in CDC format */ 430 - snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr); 431 - geth_string_defs[1].s = geth->ethaddr; 432 - 433 - geth->port.ioport = dev; 434 - geth->port.cdc_filter = DEFAULT_FILTER; 435 - 436 - geth->port.func.name = "cdc_subset"; 437 - geth->port.func.bind = geth_bind; 438 - geth->port.func.unbind = geth_old_unbind; 439 - geth->port.func.set_alt = geth_set_alt; 440 - geth->port.func.disable = geth_disable; 441 - 442 - status = usb_add_function(c, &geth->port.func); 443 - if (status) 444 - kfree(geth); 445 - return status; 446 - } 447 - 448 - #else 449 395 450 396 static inline struct f_gether_opts *to_f_gether_opts(struct config_item *item) 451 397 { ··· 517 573 DECLARE_USB_FUNCTION_INIT(geth, geth_alloc_inst, geth_alloc); 518 574 MODULE_LICENSE("GPL"); 519 575 MODULE_AUTHOR("David Brownell"); 520 - 521 - #endif
+2 -1
drivers/usb/gadget/fotg210-udc.c
··· 1157 1157 INIT_LIST_HEAD(&ep->queue); 1158 1158 ep->ep.name = fotg210_ep_name[i]; 1159 1159 ep->ep.ops = &fotg210_ep_ops; 1160 + usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); 1160 1161 } 1161 - fotg210->ep[0]->ep.maxpacket = 0x40; 1162 + usb_ep_set_maxpacket_limit(&fotg210->ep[0]->ep, 0x40); 1162 1163 fotg210->gadget.ep0 = &fotg210->ep[0]->ep; 1163 1164 INIT_LIST_HEAD(&fotg210->gadget.ep0->ep_list); 1164 1165
+1 -1
drivers/usb/gadget/fsl_qe_udc.c
··· 2429 2429 2430 2430 ep->ep.ops = &qe_ep_ops; 2431 2431 ep->stopped = 1; 2432 - ep->ep.maxpacket = (unsigned short) ~0; 2432 + usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); 2433 2433 ep->ep.desc = NULL; 2434 2434 ep->dir = 0xff; 2435 2435 ep->epnum = (u8)pipe_num;
+3 -2
drivers/usb/gadget/fsl_udc_core.c
··· 2311 2311 /* for ep0: maxP defined in desc 2312 2312 * for other eps, maxP is set by epautoconfig() called by gadget layer 2313 2313 */ 2314 - ep->ep.maxpacket = (unsigned short) ~0; 2314 + usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); 2315 2315 2316 2316 /* the queue lists any req for this ep */ 2317 2317 INIT_LIST_HEAD(&ep->queue); ··· 2469 2469 * for other eps, gadget layer called ep_enable with defined desc 2470 2470 */ 2471 2471 udc_controller->eps[0].ep.desc = &fsl_ep0_desc; 2472 - udc_controller->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD; 2472 + usb_ep_set_maxpacket_limit(&udc_controller->eps[0].ep, 2473 + USB_MAX_CTRL_PAYLOAD); 2473 2474 2474 2475 /* setup the udc->eps[] for non-control endpoints and link 2475 2476 * to gadget.ep_list */
+2 -2
drivers/usb/gadget/fusb300_udc.c
··· 1452 1452 INIT_LIST_HEAD(&ep->queue); 1453 1453 ep->ep.name = fusb300_ep_name[i]; 1454 1454 ep->ep.ops = &fusb300_ep_ops; 1455 - ep->ep.maxpacket = HS_BULK_MAX_PACKET_SIZE; 1455 + usb_ep_set_maxpacket_limit(&ep->ep, HS_BULK_MAX_PACKET_SIZE); 1456 1456 } 1457 - fusb300->ep[0]->ep.maxpacket = HS_CTL_MAX_PACKET_SIZE; 1457 + usb_ep_set_maxpacket_limit(&fusb300->ep[0]->ep, HS_CTL_MAX_PACKET_SIZE); 1458 1458 fusb300->ep[0]->epnum = 0; 1459 1459 fusb300->gadget.ep0 = &fusb300->ep[0]->ep; 1460 1460 INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list);
+280 -192
drivers/usb/gadget/g_ffs.c
··· 13 13 #define pr_fmt(fmt) "g_ffs: " fmt 14 14 15 15 #include <linux/module.h> 16 - /* 17 - * kbuild is not very cooperative with respect to linking separately 18 - * compiled library objects into one module. So for now we won't use 19 - * separate compilation ... ensuring init/exit sections work to shrink 20 - * the runtime footprint, and giving us at least some parts of what 21 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 22 - */ 16 + 23 17 #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS 18 + #include <linux/netdevice.h> 19 + 24 20 # if defined USB_ETH_RNDIS 25 21 # undef USB_ETH_RNDIS 26 22 # endif ··· 24 28 # define USB_ETH_RNDIS y 25 29 # endif 26 30 27 - #define USBF_ECM_INCLUDED 28 - # include "f_ecm.c" 29 - #define USB_FSUBSET_INCLUDED 30 - # include "f_subset.c" 31 + # include "u_ecm.h" 32 + # include "u_gether.h" 31 33 # ifdef USB_ETH_RNDIS 32 - # define USB_FRNDIS_INCLUDED 33 - # include "f_rndis.c" 34 + # include "u_rndis.h" 34 35 # include "rndis.h" 35 36 # endif 36 37 # include "u_ether.h" 37 38 38 - static u8 gfs_host_mac[ETH_ALEN]; 39 - static struct eth_dev *the_dev; 39 + USB_ETHERNET_MODULE_PARAMETERS(); 40 + 40 41 # ifdef CONFIG_USB_FUNCTIONFS_ETH 41 - static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 42 - struct eth_dev *dev); 42 + static int eth_bind_config(struct usb_configuration *c); 43 + static struct usb_function_instance *fi_ecm; 44 + static struct usb_function *f_ecm; 45 + static struct usb_function_instance *fi_geth; 46 + static struct usb_function *f_geth; 43 47 # endif 44 - #else 45 - # define the_dev NULL 46 - # define gether_cleanup(dev) do { } while (0) 47 - # define gfs_host_mac NULL 48 - struct eth_dev; 48 + # ifdef CONFIG_USB_FUNCTIONFS_RNDIS 49 + static int bind_rndis_config(struct usb_configuration *c); 50 + static struct usb_function_instance *fi_rndis; 51 + static struct usb_function *f_rndis; 52 + # endif 49 53 #endif 50 54 51 - #include "f_fs.c" 55 + #include "u_fs.h" 52 56 53 57 #define DRIVER_NAME "g_ffs" 54 58 #define DRIVER_DESC "USB Function Filesystem" ··· 63 67 64 68 #define GFS_MAX_DEVS 10 65 69 66 - struct gfs_ffs_obj { 67 - const char *name; 68 - bool mounted; 69 - bool desc_ready; 70 - struct ffs_data *ffs_data; 71 - }; 72 - 73 70 USB_GADGET_COMPOSITE_OPTIONS(); 74 - 75 - #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS 76 - USB_ETHERNET_MODULE_PARAMETERS(); 77 - #endif 78 71 79 72 static struct usb_device_descriptor gfs_dev_desc = { 80 73 .bLength = sizeof gfs_dev_desc, ··· 131 146 132 147 struct gfs_configuration { 133 148 struct usb_configuration c; 134 - int (*eth)(struct usb_configuration *c, u8 *ethaddr, 135 - struct eth_dev *dev); 149 + int (*eth)(struct usb_configuration *c); 150 + int num; 136 151 } gfs_configurations[] = { 137 152 #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 138 153 { 139 - .eth = rndis_bind_config, 154 + .eth = bind_rndis_config, 140 155 }, 141 156 #endif 142 157 ··· 152 167 #endif 153 168 }; 154 169 170 + static void *functionfs_acquire_dev(struct ffs_dev *dev); 171 + static void functionfs_release_dev(struct ffs_dev *dev); 172 + static int functionfs_ready_callback(struct ffs_data *ffs); 173 + static void functionfs_closed_callback(struct ffs_data *ffs); 155 174 static int gfs_bind(struct usb_composite_dev *cdev); 156 175 static int gfs_unbind(struct usb_composite_dev *cdev); 157 176 static int gfs_do_config(struct usb_configuration *c); 177 + 158 178 159 179 static __refdata struct usb_composite_driver gfs_driver = { 160 180 .name = DRIVER_NAME, ··· 170 180 .unbind = gfs_unbind, 171 181 }; 172 182 173 - static DEFINE_MUTEX(gfs_lock); 174 183 static unsigned int missing_funcs; 175 - static bool gfs_ether_setup; 176 184 static bool gfs_registered; 177 185 static bool gfs_single_func; 178 - static struct gfs_ffs_obj *ffs_tab; 186 + static struct usb_function_instance **fi_ffs; 187 + static struct usb_function **f_ffs[] = { 188 + #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 189 + NULL, 190 + #endif 191 + 192 + #ifdef CONFIG_USB_FUNCTIONFS_ETH 193 + NULL, 194 + #endif 195 + 196 + #ifdef CONFIG_USB_FUNCTIONFS_GENERIC 197 + NULL, 198 + #endif 199 + }; 200 + 201 + #define N_CONF ARRAY_SIZE(f_ffs) 179 202 180 203 static int __init gfs_init(void) 181 204 { 205 + struct f_fs_opts *opts; 182 206 int i; 207 + int ret = 0; 183 208 184 209 ENTER(); 185 210 186 - if (!func_num) { 211 + if (func_num < 2) { 187 212 gfs_single_func = true; 188 213 func_num = 1; 189 214 } 190 215 191 - ffs_tab = kcalloc(func_num, sizeof *ffs_tab, GFP_KERNEL); 192 - if (!ffs_tab) 193 - return -ENOMEM; 216 + /* 217 + * Allocate in one chunk for easier maintenance 218 + */ 219 + f_ffs[0] = kcalloc(func_num * N_CONF, sizeof(*f_ffs), GFP_KERNEL); 220 + if (!f_ffs[0]) { 221 + ret = -ENOMEM; 222 + goto no_func; 223 + } 224 + for (i = 1; i < N_CONF; ++i) 225 + f_ffs[i] = f_ffs[0] + i * func_num; 194 226 195 - if (!gfs_single_func) 196 - for (i = 0; i < func_num; i++) 197 - ffs_tab[i].name = func_names[i]; 227 + fi_ffs = kcalloc(func_num, sizeof(*fi_ffs), GFP_KERNEL); 228 + if (!fi_ffs) { 229 + ret = -ENOMEM; 230 + goto no_func; 231 + } 232 + 233 + for (i = 0; i < func_num; i++) { 234 + fi_ffs[i] = usb_get_function_instance("ffs"); 235 + if (IS_ERR(fi_ffs[i])) { 236 + ret = PTR_ERR(fi_ffs[i]); 237 + --i; 238 + goto no_dev; 239 + } 240 + opts = to_f_fs_opts(fi_ffs[i]); 241 + if (gfs_single_func) 242 + ret = ffs_single_dev(opts->dev); 243 + else 244 + ret = ffs_name_dev(opts->dev, func_names[i]); 245 + if (ret) 246 + goto no_dev; 247 + opts->dev->ffs_ready_callback = functionfs_ready_callback; 248 + opts->dev->ffs_closed_callback = functionfs_closed_callback; 249 + opts->dev->ffs_acquire_dev_callback = functionfs_acquire_dev; 250 + opts->dev->ffs_release_dev_callback = functionfs_release_dev; 251 + opts->no_configfs = true; 252 + } 198 253 199 254 missing_funcs = func_num; 200 255 201 - return functionfs_init(); 256 + return 0; 257 + no_dev: 258 + while (i >= 0) 259 + usb_put_function_instance(fi_ffs[i--]); 260 + kfree(fi_ffs); 261 + no_func: 262 + kfree(f_ffs[0]); 263 + return ret; 202 264 } 203 265 module_init(gfs_init); 204 266 205 267 static void __exit gfs_exit(void) 206 268 { 269 + int i; 270 + 207 271 ENTER(); 208 - mutex_lock(&gfs_lock); 209 272 210 273 if (gfs_registered) 211 274 usb_composite_unregister(&gfs_driver); 212 275 gfs_registered = false; 213 276 214 - functionfs_cleanup(); 277 + kfree(f_ffs[0]); 215 278 216 - mutex_unlock(&gfs_lock); 217 - kfree(ffs_tab); 279 + for (i = 0; i < func_num; i++) 280 + usb_put_function_instance(fi_ffs[i]); 281 + 282 + kfree(fi_ffs); 218 283 } 219 284 module_exit(gfs_exit); 220 285 221 - static struct gfs_ffs_obj *gfs_find_dev(const char *dev_name) 286 + static void *functionfs_acquire_dev(struct ffs_dev *dev) 222 287 { 223 - int i; 224 - 225 - ENTER(); 226 - 227 - if (gfs_single_func) 228 - return &ffs_tab[0]; 229 - 230 - for (i = 0; i < func_num; i++) 231 - if (strcmp(ffs_tab[i].name, dev_name) == 0) 232 - return &ffs_tab[i]; 233 - 234 - return NULL; 288 + if (!try_module_get(THIS_MODULE)) 289 + return ERR_PTR(-ENODEV); 290 + 291 + return 0; 235 292 } 236 293 294 + static void functionfs_release_dev(struct ffs_dev *dev) 295 + { 296 + module_put(THIS_MODULE); 297 + } 298 + 299 + /* 300 + * The caller of this function takes ffs_lock 301 + */ 237 302 static int functionfs_ready_callback(struct ffs_data *ffs) 238 303 { 239 - struct gfs_ffs_obj *ffs_obj; 240 - int ret; 304 + int ret = 0; 241 305 242 - ENTER(); 243 - mutex_lock(&gfs_lock); 306 + if (--missing_funcs) 307 + return 0; 244 308 245 - ffs_obj = ffs->private_data; 246 - if (!ffs_obj) { 247 - ret = -EINVAL; 248 - goto done; 249 - } 309 + if (gfs_registered) 310 + return -EBUSY; 250 311 251 - if (WARN_ON(ffs_obj->desc_ready)) { 252 - ret = -EBUSY; 253 - goto done; 254 - } 255 - ffs_obj->desc_ready = true; 256 - ffs_obj->ffs_data = ffs; 257 - 258 - if (--missing_funcs) { 259 - ret = 0; 260 - goto done; 261 - } 262 - 263 - if (gfs_registered) { 264 - ret = -EBUSY; 265 - goto done; 266 - } 267 312 gfs_registered = true; 268 313 269 314 ret = usb_composite_probe(&gfs_driver); 270 315 if (unlikely(ret < 0)) 271 316 gfs_registered = false; 272 - 273 - done: 274 - mutex_unlock(&gfs_lock); 317 + 275 318 return ret; 276 319 } 277 320 321 + /* 322 + * The caller of this function takes ffs_lock 323 + */ 278 324 static void functionfs_closed_callback(struct ffs_data *ffs) 279 325 { 280 - struct gfs_ffs_obj *ffs_obj; 281 - 282 - ENTER(); 283 - mutex_lock(&gfs_lock); 284 - 285 - ffs_obj = ffs->private_data; 286 - if (!ffs_obj) 287 - goto done; 288 - 289 - ffs_obj->desc_ready = false; 290 326 missing_funcs++; 291 327 292 328 if (gfs_registered) 293 329 usb_composite_unregister(&gfs_driver); 294 330 gfs_registered = false; 295 - 296 - done: 297 - mutex_unlock(&gfs_lock); 298 - } 299 - 300 - static void *functionfs_acquire_dev_callback(const char *dev_name) 301 - { 302 - struct gfs_ffs_obj *ffs_dev; 303 - 304 - ENTER(); 305 - mutex_lock(&gfs_lock); 306 - 307 - ffs_dev = gfs_find_dev(dev_name); 308 - if (!ffs_dev) { 309 - ffs_dev = ERR_PTR(-ENODEV); 310 - goto done; 311 - } 312 - 313 - if (ffs_dev->mounted) { 314 - ffs_dev = ERR_PTR(-EBUSY); 315 - goto done; 316 - } 317 - ffs_dev->mounted = true; 318 - 319 - done: 320 - mutex_unlock(&gfs_lock); 321 - return ffs_dev; 322 - } 323 - 324 - static void functionfs_release_dev_callback(struct ffs_data *ffs_data) 325 - { 326 - struct gfs_ffs_obj *ffs_dev; 327 - 328 - ENTER(); 329 - mutex_lock(&gfs_lock); 330 - 331 - ffs_dev = ffs_data->private_data; 332 - if (ffs_dev) 333 - ffs_dev->mounted = false; 334 - 335 - mutex_unlock(&gfs_lock); 336 331 } 337 332 338 333 /* 339 - * It is assumed that gfs_bind is called from a context where gfs_lock is held 334 + * It is assumed that gfs_bind is called from a context where ffs_lock is held 340 335 */ 341 336 static int gfs_bind(struct usb_composite_dev *cdev) 342 337 { 338 + #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS 339 + struct net_device *net; 340 + #endif 343 341 int ret, i; 344 342 345 343 ENTER(); 346 344 347 345 if (missing_funcs) 348 346 return -ENODEV; 349 - #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS 350 - the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, gfs_host_mac, 351 - qmult); 352 - #endif 353 - if (IS_ERR(the_dev)) { 354 - ret = PTR_ERR(the_dev); 355 - goto error_quick; 347 + #if defined CONFIG_USB_FUNCTIONFS_ETH 348 + if (can_support_ecm(cdev->gadget)) { 349 + struct f_ecm_opts *ecm_opts; 350 + 351 + fi_ecm = usb_get_function_instance("ecm"); 352 + if (IS_ERR(fi_ecm)) 353 + return PTR_ERR(fi_ecm); 354 + ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); 355 + net = ecm_opts->net; 356 + } else { 357 + struct f_gether_opts *geth_opts; 358 + 359 + fi_geth = usb_get_function_instance("geth"); 360 + if (IS_ERR(fi_geth)) 361 + return PTR_ERR(fi_geth); 362 + geth_opts = container_of(fi_geth, struct f_gether_opts, 363 + func_inst); 364 + net = geth_opts->net; 356 365 } 357 - gfs_ether_setup = true; 366 + #endif 358 367 359 - ret = usb_string_ids_tab(cdev, gfs_strings); 360 - if (unlikely(ret < 0)) 361 - goto error; 362 - gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id; 368 + #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 369 + { 370 + struct f_rndis_opts *rndis_opts; 363 371 364 - for (i = func_num; i--; ) { 365 - ret = functionfs_bind(ffs_tab[i].ffs_data, cdev); 366 - if (unlikely(ret < 0)) { 367 - while (++i < func_num) 368 - functionfs_unbind(ffs_tab[i].ffs_data); 372 + fi_rndis = usb_get_function_instance("rndis"); 373 + if (IS_ERR(fi_rndis)) { 374 + ret = PTR_ERR(fi_rndis); 369 375 goto error; 370 376 } 377 + rndis_opts = container_of(fi_rndis, struct f_rndis_opts, 378 + func_inst); 379 + #ifndef CONFIG_USB_FUNCTIONFS_ETH 380 + net = rndis_opts->net; 381 + #endif 371 382 } 383 + #endif 384 + 385 + #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS 386 + gether_set_qmult(net, qmult); 387 + if (!gether_set_host_addr(net, host_addr)) 388 + pr_info("using host ethernet address: %s", host_addr); 389 + if (!gether_set_dev_addr(net, dev_addr)) 390 + pr_info("using self ethernet address: %s", dev_addr); 391 + #endif 392 + 393 + #if defined CONFIG_USB_FUNCTIONFS_RNDIS && defined CONFIG_USB_FUNCTIONFS_ETH 394 + gether_set_gadget(net, cdev->gadget); 395 + ret = gether_register_netdev(net); 396 + if (ret) 397 + goto error_rndis; 398 + 399 + if (can_support_ecm(cdev->gadget)) { 400 + struct f_ecm_opts *ecm_opts; 401 + 402 + ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); 403 + ecm_opts->bound = true; 404 + } else { 405 + struct f_gether_opts *geth_opts; 406 + 407 + geth_opts = container_of(fi_geth, struct f_gether_opts, 408 + func_inst); 409 + geth_opts->bound = true; 410 + } 411 + 412 + rndis_borrow_net(fi_rndis, net); 413 + #endif 414 + 415 + /* TODO: gstrings_attach? */ 416 + ret = usb_string_ids_tab(cdev, gfs_strings); 417 + if (unlikely(ret < 0)) 418 + goto error_rndis; 419 + gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id; 372 420 373 421 for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { 374 422 struct gfs_configuration *c = gfs_configurations + i; ··· 417 389 c->c.bConfigurationValue = 1 + i; 418 390 c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; 419 391 392 + c->num = i; 393 + 420 394 ret = usb_add_config(cdev, &c->c, gfs_do_config); 421 395 if (unlikely(ret < 0)) 422 396 goto error_unbind; ··· 426 396 usb_composite_overwrite_options(cdev, &coverwrite); 427 397 return 0; 428 398 399 + /* TODO */ 429 400 error_unbind: 430 - for (i = 0; i < func_num; i++) 431 - functionfs_unbind(ffs_tab[i].ffs_data); 401 + error_rndis: 402 + #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 403 + usb_put_function_instance(fi_rndis); 432 404 error: 433 - gether_cleanup(the_dev); 434 - error_quick: 435 - gfs_ether_setup = false; 405 + #endif 406 + #if defined CONFIG_USB_FUNCTIONFS_ETH 407 + if (can_support_ecm(cdev->gadget)) 408 + usb_put_function_instance(fi_ecm); 409 + else 410 + usb_put_function_instance(fi_geth); 411 + #endif 436 412 return ret; 437 413 } 438 414 439 415 /* 440 - * It is assumed that gfs_unbind is called from a context where gfs_lock is held 416 + * It is assumed that gfs_unbind is called from a context where ffs_lock is held 441 417 */ 442 418 static int gfs_unbind(struct usb_composite_dev *cdev) 443 419 { ··· 451 415 452 416 ENTER(); 453 417 454 - /* 455 - * We may have been called in an error recovery from 456 - * composite_bind() after gfs_unbind() failure so we need to 457 - * check if gfs_ffs_data is not NULL since gfs_bind() handles 458 - * all error recovery itself. I'd rather we werent called 459 - * from composite on orror recovery, but what you're gonna 460 - * do...? 461 - */ 462 - if (gfs_ether_setup) 463 - gether_cleanup(the_dev); 464 - gfs_ether_setup = false; 465 418 466 - for (i = func_num; i--; ) 467 - if (ffs_tab[i].ffs_data) 468 - functionfs_unbind(ffs_tab[i].ffs_data); 419 + #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 420 + usb_put_function(f_rndis); 421 + usb_put_function_instance(fi_rndis); 422 + #endif 423 + 424 + #if defined CONFIG_USB_FUNCTIONFS_ETH 425 + if (can_support_ecm(cdev->gadget)) { 426 + usb_put_function(f_ecm); 427 + usb_put_function_instance(fi_ecm); 428 + } else { 429 + usb_put_function(f_geth); 430 + usb_put_function_instance(fi_geth); 431 + } 432 + #endif 433 + for (i = 0; i < N_CONF * func_num; ++i) 434 + usb_put_function(*(f_ffs[0] + i)); 469 435 470 436 return 0; 471 437 } 472 438 473 439 /* 474 440 * It is assumed that gfs_do_config is called from a context where 475 - * gfs_lock is held 441 + * ffs_lock is held 476 442 */ 477 443 static int gfs_do_config(struct usb_configuration *c) 478 444 { ··· 492 454 } 493 455 494 456 if (gc->eth) { 495 - ret = gc->eth(c, gfs_host_mac, the_dev); 457 + ret = gc->eth(c); 496 458 if (unlikely(ret < 0)) 497 459 return ret; 498 460 } 499 461 500 462 for (i = 0; i < func_num; i++) { 501 - ret = functionfs_bind_config(c->cdev, c, ffs_tab[i].ffs_data); 502 - if (unlikely(ret < 0)) 503 - return ret; 463 + f_ffs[gc->num][i] = usb_get_function(fi_ffs[i]); 464 + if (IS_ERR(f_ffs[gc->num][i])) { 465 + ret = PTR_ERR(f_ffs[gc->num][i]); 466 + goto error; 467 + } 468 + ret = usb_add_function(c, f_ffs[gc->num][i]); 469 + if (ret < 0) { 470 + usb_put_function(f_ffs[gc->num][i]); 471 + goto error; 472 + } 504 473 } 505 474 506 475 /* ··· 524 479 c->interface[c->next_interface_id] = NULL; 525 480 526 481 return 0; 482 + error: 483 + while (--i >= 0) { 484 + if (!IS_ERR(f_ffs[gc->num][i])) 485 + usb_remove_function(c, f_ffs[gc->num][i]); 486 + usb_put_function(f_ffs[gc->num][i]); 487 + } 488 + return ret; 527 489 } 528 490 529 491 #ifdef CONFIG_USB_FUNCTIONFS_ETH 530 492 531 - static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 532 - struct eth_dev *dev) 493 + static int eth_bind_config(struct usb_configuration *c) 533 494 { 534 - return can_support_ecm(c->cdev->gadget) 535 - ? ecm_bind_config(c, ethaddr, dev) 536 - : geth_bind_config(c, ethaddr, dev); 495 + int status = 0; 496 + 497 + if (can_support_ecm(c->cdev->gadget)) { 498 + f_ecm = usb_get_function(fi_ecm); 499 + if (IS_ERR(f_ecm)) 500 + return PTR_ERR(f_ecm); 501 + 502 + status = usb_add_function(c, f_ecm); 503 + if (status < 0) 504 + usb_put_function(f_ecm); 505 + 506 + } else { 507 + f_geth = usb_get_function(fi_geth); 508 + if (IS_ERR(f_geth)) 509 + return PTR_ERR(f_geth); 510 + 511 + status = usb_add_function(c, f_geth); 512 + if (status < 0) 513 + usb_put_function(f_geth); 514 + } 515 + return status; 516 + } 517 + 518 + #endif 519 + 520 + #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 521 + 522 + static int bind_rndis_config(struct usb_configuration *c) 523 + { 524 + int status = 0; 525 + 526 + f_rndis = usb_get_function(fi_rndis); 527 + if (IS_ERR(f_rndis)) 528 + return PTR_ERR(f_rndis); 529 + 530 + status = usb_add_function(c, f_rndis); 531 + if (status < 0) 532 + usb_put_function(f_rndis); 533 + 534 + return status; 537 535 } 538 536 539 537 #endif
+23 -1
drivers/usb/gadget/g_zero.h
··· 6 6 #ifndef __G_ZERO_H 7 7 #define __G_ZERO_H 8 8 9 + #define GZERO_BULK_BUFLEN 4096 10 + #define GZERO_QLEN 32 11 + #define GZERO_ISOC_INTERVAL 4 12 + #define GZERO_ISOC_MAXPACKET 1024 13 + 9 14 struct usb_zero_options { 10 15 unsigned pattern; 11 16 unsigned isoc_interval; ··· 29 24 unsigned isoc_mult; 30 25 unsigned isoc_maxburst; 31 26 unsigned bulk_buflen; 27 + 28 + /* 29 + * Read/write access to configfs attributes is handled by configfs. 30 + * 31 + * This is to protect the data from concurrent access by read/write 32 + * and create symlink/remove symlink. 33 + */ 34 + struct mutex lock; 35 + int refcnt; 32 36 }; 33 37 34 38 struct f_lb_opts { 35 39 struct usb_function_instance func_inst; 36 40 unsigned bulk_buflen; 37 41 unsigned qlen; 42 + 43 + /* 44 + * Read/write access to configfs attributes is handled by configfs. 45 + * 46 + * This is to protect the data from concurrent access by read/write 47 + * and create symlink/remove symlink. 48 + */ 49 + struct mutex lock; 50 + int refcnt; 38 51 }; 39 52 40 53 void lb_modexit(void); 41 54 int lb_modinit(void); 42 55 43 56 /* common utilities */ 44 - struct usb_request *alloc_ep_req(struct usb_ep *ep, int len); 45 57 void free_ep_req(struct usb_ep *ep, struct usb_request *req); 46 58 void disable_endpoints(struct usb_composite_dev *cdev, 47 59 struct usb_ep *in, struct usb_ep *out,
+6 -10
drivers/usb/gadget/goku_udc.c
··· 231 231 } 232 232 } 233 233 234 - ep->ep.maxpacket = MAX_FIFO_SIZE; 234 + usb_ep_set_maxpacket_limit(&ep->ep, MAX_FIFO_SIZE); 235 235 ep->ep.desc = NULL; 236 236 ep->stopped = 1; 237 237 ep->irqs = 0; ··· 1251 1251 } 1252 1252 1253 1253 dev->ep[0].reg_mode = NULL; 1254 - dev->ep[0].ep.maxpacket = MAX_EP0_SIZE; 1254 + usb_ep_set_maxpacket_limit(&dev->ep[0].ep, MAX_EP0_SIZE); 1255 1255 list_del_init (&dev->ep[0].ep.ep_list); 1256 1256 } 1257 1257 ··· 1350 1350 return 0; 1351 1351 } 1352 1352 1353 - static void 1354 - stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver) 1353 + static void stop_activity(struct goku_udc *dev) 1355 1354 { 1356 1355 unsigned i; 1357 1356 1358 1357 DBG (dev, "%s\n", __func__); 1359 - 1360 - if (dev->gadget.speed == USB_SPEED_UNKNOWN) 1361 - driver = NULL; 1362 1358 1363 1359 /* disconnect gadget driver after quiesceing hw and the driver */ 1364 1360 udc_reset (dev); ··· 1373 1377 1374 1378 spin_lock_irqsave(&dev->lock, flags); 1375 1379 dev->driver = NULL; 1376 - stop_activity(dev, driver); 1380 + stop_activity(dev); 1377 1381 spin_unlock_irqrestore(&dev->lock, flags); 1378 1382 1379 1383 return 0; ··· 1517 1521 if (unlikely(stat & INT_DEVWIDE)) { 1518 1522 if (stat & INT_SYSERROR) { 1519 1523 ERROR(dev, "system error\n"); 1520 - stop_activity(dev, dev->driver); 1524 + stop_activity(dev); 1521 1525 stat = 0; 1522 1526 handled = 1; 1523 1527 // FIXME have a neater way to prevent re-enumeration ··· 1532 1536 } else { 1533 1537 DBG(dev, "disconnect\n"); 1534 1538 if (dev->gadget.speed == USB_SPEED_FULL) 1535 - stop_activity(dev, dev->driver); 1539 + stop_activity(dev); 1536 1540 dev->ep0state = EP0_DISCONNECT; 1537 1541 dev->int_enable = INT_DEVWIDE; 1538 1542 writel(dev->int_enable, &dev->regs->int_enable);
+2242
drivers/usb/gadget/gr_udc.c
··· 1 + /* 2 + * USB Peripheral Controller driver for Aeroflex Gaisler GRUSBDC. 3 + * 4 + * 2013 (c) Aeroflex Gaisler AB 5 + * 6 + * This driver supports GRUSBDC USB Device Controller cores available in the 7 + * GRLIB VHDL IP core library. 8 + * 9 + * Full documentation of the GRUSBDC core can be found here: 10 + * http://www.gaisler.com/products/grlib/grip.pdf 11 + * 12 + * This program is free software; you can redistribute it and/or modify it 13 + * under the terms of the GNU General Public License as published by the 14 + * Free Software Foundation; either version 2 of the License, or (at your 15 + * option) any later version. 16 + * 17 + * Contributors: 18 + * - Andreas Larsson <andreas@gaisler.com> 19 + * - Marko Isomaki 20 + */ 21 + 22 + /* 23 + * A GRUSBDC core can have up to 16 IN endpoints and 16 OUT endpoints each 24 + * individually configurable to any of the four USB transfer types. This driver 25 + * only supports cores in DMA mode. 26 + */ 27 + 28 + #include <linux/kernel.h> 29 + #include <linux/module.h> 30 + #include <linux/slab.h> 31 + #include <linux/spinlock.h> 32 + #include <linux/errno.h> 33 + #include <linux/init.h> 34 + #include <linux/list.h> 35 + #include <linux/interrupt.h> 36 + #include <linux/device.h> 37 + #include <linux/usb/ch9.h> 38 + #include <linux/usb/gadget.h> 39 + #include <linux/dma-mapping.h> 40 + #include <linux/dmapool.h> 41 + #include <linux/debugfs.h> 42 + #include <linux/seq_file.h> 43 + #include <linux/of_platform.h> 44 + #include <linux/of_irq.h> 45 + #include <linux/of_address.h> 46 + 47 + #include <asm/byteorder.h> 48 + 49 + #include "gr_udc.h" 50 + 51 + #define DRIVER_NAME "gr_udc" 52 + #define DRIVER_DESC "Aeroflex Gaisler GRUSBDC USB Peripheral Controller" 53 + 54 + static const char driver_name[] = DRIVER_NAME; 55 + static const char driver_desc[] = DRIVER_DESC; 56 + 57 + #define gr_read32(x) (ioread32be((x))) 58 + #define gr_write32(x, v) (iowrite32be((v), (x))) 59 + 60 + /* USB speed and corresponding string calculated from status register value */ 61 + #define GR_SPEED(status) \ 62 + ((status & GR_STATUS_SP) ? USB_SPEED_FULL : USB_SPEED_HIGH) 63 + #define GR_SPEED_STR(status) usb_speed_string(GR_SPEED(status)) 64 + 65 + /* Size of hardware buffer calculated from epctrl register value */ 66 + #define GR_BUFFER_SIZE(epctrl) \ 67 + ((((epctrl) & GR_EPCTRL_BUFSZ_MASK) >> GR_EPCTRL_BUFSZ_POS) * \ 68 + GR_EPCTRL_BUFSZ_SCALER) 69 + 70 + /* ---------------------------------------------------------------------- */ 71 + /* Debug printout functionality */ 72 + 73 + static const char * const gr_modestring[] = {"control", "iso", "bulk", "int"}; 74 + 75 + static const char *gr_ep0state_string(enum gr_ep0state state) 76 + { 77 + static const char *const names[] = { 78 + [GR_EP0_DISCONNECT] = "disconnect", 79 + [GR_EP0_SETUP] = "setup", 80 + [GR_EP0_IDATA] = "idata", 81 + [GR_EP0_ODATA] = "odata", 82 + [GR_EP0_ISTATUS] = "istatus", 83 + [GR_EP0_OSTATUS] = "ostatus", 84 + [GR_EP0_STALL] = "stall", 85 + [GR_EP0_SUSPEND] = "suspend", 86 + }; 87 + 88 + if (state < 0 || state >= ARRAY_SIZE(names)) 89 + return "UNKNOWN"; 90 + 91 + return names[state]; 92 + } 93 + 94 + #ifdef VERBOSE_DEBUG 95 + 96 + static void gr_dbgprint_request(const char *str, struct gr_ep *ep, 97 + struct gr_request *req) 98 + { 99 + int buflen = ep->is_in ? req->req.length : req->req.actual; 100 + int rowlen = 32; 101 + int plen = min(rowlen, buflen); 102 + 103 + dev_dbg(ep->dev->dev, "%s: 0x%p, %d bytes data%s:\n", str, req, buflen, 104 + (buflen > plen ? " (truncated)" : "")); 105 + print_hex_dump_debug(" ", DUMP_PREFIX_NONE, 106 + rowlen, 4, req->req.buf, plen, false); 107 + } 108 + 109 + static void gr_dbgprint_devreq(struct gr_udc *dev, u8 type, u8 request, 110 + u16 value, u16 index, u16 length) 111 + { 112 + dev_vdbg(dev->dev, "REQ: %02x.%02x v%04x i%04x l%04x\n", 113 + type, request, value, index, length); 114 + } 115 + #else /* !VERBOSE_DEBUG */ 116 + 117 + static void gr_dbgprint_request(const char *str, struct gr_ep *ep, 118 + struct gr_request *req) {} 119 + 120 + static void gr_dbgprint_devreq(struct gr_udc *dev, u8 type, u8 request, 121 + u16 value, u16 index, u16 length) {} 122 + 123 + #endif /* VERBOSE_DEBUG */ 124 + 125 + /* ---------------------------------------------------------------------- */ 126 + /* Debugfs functionality */ 127 + 128 + #ifdef CONFIG_USB_GADGET_DEBUG_FS 129 + 130 + static void gr_seq_ep_show(struct seq_file *seq, struct gr_ep *ep) 131 + { 132 + u32 epctrl = gr_read32(&ep->regs->epctrl); 133 + u32 epstat = gr_read32(&ep->regs->epstat); 134 + int mode = (epctrl & GR_EPCTRL_TT_MASK) >> GR_EPCTRL_TT_POS; 135 + struct gr_request *req; 136 + 137 + seq_printf(seq, "%s:\n", ep->ep.name); 138 + seq_printf(seq, " mode = %s\n", gr_modestring[mode]); 139 + seq_printf(seq, " halted: %d\n", !!(epctrl & GR_EPCTRL_EH)); 140 + seq_printf(seq, " disabled: %d\n", !!(epctrl & GR_EPCTRL_ED)); 141 + seq_printf(seq, " valid: %d\n", !!(epctrl & GR_EPCTRL_EV)); 142 + seq_printf(seq, " dma_start = %d\n", ep->dma_start); 143 + seq_printf(seq, " stopped = %d\n", ep->stopped); 144 + seq_printf(seq, " wedged = %d\n", ep->wedged); 145 + seq_printf(seq, " callback = %d\n", ep->callback); 146 + seq_printf(seq, " maxpacket = %d\n", ep->ep.maxpacket); 147 + seq_printf(seq, " bytes_per_buffer = %d\n", ep->bytes_per_buffer); 148 + if (mode == 1 || mode == 3) 149 + seq_printf(seq, " nt = %d\n", 150 + (epctrl & GR_EPCTRL_NT_MASK) >> GR_EPCTRL_NT_POS); 151 + 152 + seq_printf(seq, " Buffer 0: %s %s%d\n", 153 + epstat & GR_EPSTAT_B0 ? "valid" : "invalid", 154 + epstat & GR_EPSTAT_BS ? " " : "selected ", 155 + (epstat & GR_EPSTAT_B0CNT_MASK) >> GR_EPSTAT_B0CNT_POS); 156 + seq_printf(seq, " Buffer 1: %s %s%d\n", 157 + epstat & GR_EPSTAT_B1 ? "valid" : "invalid", 158 + epstat & GR_EPSTAT_BS ? "selected " : " ", 159 + (epstat & GR_EPSTAT_B1CNT_MASK) >> GR_EPSTAT_B1CNT_POS); 160 + 161 + if (list_empty(&ep->queue)) { 162 + seq_puts(seq, " Queue: empty\n\n"); 163 + return; 164 + } 165 + 166 + seq_puts(seq, " Queue:\n"); 167 + list_for_each_entry(req, &ep->queue, queue) { 168 + struct gr_dma_desc *desc; 169 + struct gr_dma_desc *next; 170 + 171 + seq_printf(seq, " 0x%p: 0x%p %d %d\n", req, 172 + &req->req.buf, req->req.actual, req->req.length); 173 + 174 + next = req->first_desc; 175 + do { 176 + desc = next; 177 + next = desc->next_desc; 178 + seq_printf(seq, " %c 0x%p (0x%08x): 0x%05x 0x%08x\n", 179 + desc == req->curr_desc ? 'c' : ' ', 180 + desc, desc->paddr, desc->ctrl, desc->data); 181 + } while (desc != req->last_desc); 182 + } 183 + seq_puts(seq, "\n"); 184 + } 185 + 186 + 187 + static int gr_seq_show(struct seq_file *seq, void *v) 188 + { 189 + struct gr_udc *dev = seq->private; 190 + u32 control = gr_read32(&dev->regs->control); 191 + u32 status = gr_read32(&dev->regs->status); 192 + struct gr_ep *ep; 193 + 194 + seq_printf(seq, "usb state = %s\n", 195 + usb_state_string(dev->gadget.state)); 196 + seq_printf(seq, "address = %d\n", 197 + (control & GR_CONTROL_UA_MASK) >> GR_CONTROL_UA_POS); 198 + seq_printf(seq, "speed = %s\n", GR_SPEED_STR(status)); 199 + seq_printf(seq, "ep0state = %s\n", gr_ep0state_string(dev->ep0state)); 200 + seq_printf(seq, "irq_enabled = %d\n", dev->irq_enabled); 201 + seq_printf(seq, "remote_wakeup = %d\n", dev->remote_wakeup); 202 + seq_printf(seq, "test_mode = %d\n", dev->test_mode); 203 + seq_puts(seq, "\n"); 204 + 205 + list_for_each_entry(ep, &dev->ep_list, ep_list) 206 + gr_seq_ep_show(seq, ep); 207 + 208 + return 0; 209 + } 210 + 211 + static int gr_dfs_open(struct inode *inode, struct file *file) 212 + { 213 + return single_open(file, gr_seq_show, inode->i_private); 214 + } 215 + 216 + static const struct file_operations gr_dfs_fops = { 217 + .owner = THIS_MODULE, 218 + .open = gr_dfs_open, 219 + .read = seq_read, 220 + .llseek = seq_lseek, 221 + .release = single_release, 222 + }; 223 + 224 + static void gr_dfs_create(struct gr_udc *dev) 225 + { 226 + const char *name = "gr_udc_state"; 227 + 228 + dev->dfs_root = debugfs_create_dir(dev_name(dev->dev), NULL); 229 + if (IS_ERR(dev->dfs_root)) { 230 + dev_err(dev->dev, "Failed to create debugfs directory\n"); 231 + return; 232 + } 233 + dev->dfs_state = debugfs_create_file(name, 0444, dev->dfs_root, 234 + dev, &gr_dfs_fops); 235 + if (IS_ERR(dev->dfs_state)) 236 + dev_err(dev->dev, "Failed to create debugfs file %s\n", name); 237 + } 238 + 239 + static void gr_dfs_delete(struct gr_udc *dev) 240 + { 241 + /* Handles NULL and ERR pointers internally */ 242 + debugfs_remove(dev->dfs_state); 243 + debugfs_remove(dev->dfs_root); 244 + } 245 + 246 + #else /* !CONFIG_USB_GADGET_DEBUG_FS */ 247 + 248 + static void gr_dfs_create(struct gr_udc *dev) {} 249 + static void gr_dfs_delete(struct gr_udc *dev) {} 250 + 251 + #endif /* CONFIG_USB_GADGET_DEBUG_FS */ 252 + 253 + /* ---------------------------------------------------------------------- */ 254 + /* DMA and request handling */ 255 + 256 + /* Allocates a new struct gr_dma_desc, sets paddr and zeroes the rest */ 257 + static struct gr_dma_desc *gr_alloc_dma_desc(struct gr_ep *ep, gfp_t gfp_flags) 258 + { 259 + dma_addr_t paddr; 260 + struct gr_dma_desc *dma_desc; 261 + 262 + dma_desc = dma_pool_alloc(ep->dev->desc_pool, gfp_flags, &paddr); 263 + if (!dma_desc) { 264 + dev_err(ep->dev->dev, "Could not allocate from DMA pool\n"); 265 + return NULL; 266 + } 267 + 268 + memset(dma_desc, 0, sizeof(*dma_desc)); 269 + dma_desc->paddr = paddr; 270 + 271 + return dma_desc; 272 + } 273 + 274 + static inline void gr_free_dma_desc(struct gr_udc *dev, 275 + struct gr_dma_desc *desc) 276 + { 277 + dma_pool_free(dev->desc_pool, desc, (dma_addr_t)desc->paddr); 278 + } 279 + 280 + /* Frees the chain of struct gr_dma_desc for the given request */ 281 + static void gr_free_dma_desc_chain(struct gr_udc *dev, struct gr_request *req) 282 + { 283 + struct gr_dma_desc *desc; 284 + struct gr_dma_desc *next; 285 + 286 + next = req->first_desc; 287 + if (!next) 288 + return; 289 + 290 + do { 291 + desc = next; 292 + next = desc->next_desc; 293 + gr_free_dma_desc(dev, desc); 294 + } while (desc != req->last_desc); 295 + 296 + req->first_desc = NULL; 297 + req->curr_desc = NULL; 298 + req->last_desc = NULL; 299 + } 300 + 301 + static void gr_ep0_setup(struct gr_udc *dev, struct gr_request *req); 302 + 303 + /* 304 + * Frees allocated resources and calls the appropriate completion function/setup 305 + * package handler for a finished request. 306 + * 307 + * Must be called with dev->lock held and irqs disabled. 308 + */ 309 + static void gr_finish_request(struct gr_ep *ep, struct gr_request *req, 310 + int status) 311 + __releases(&dev->lock) 312 + __acquires(&dev->lock) 313 + { 314 + struct gr_udc *dev; 315 + 316 + list_del_init(&req->queue); 317 + 318 + if (likely(req->req.status == -EINPROGRESS)) 319 + req->req.status = status; 320 + else 321 + status = req->req.status; 322 + 323 + dev = ep->dev; 324 + usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in); 325 + gr_free_dma_desc_chain(dev, req); 326 + 327 + if (ep->is_in) /* For OUT, actual gets updated bit by bit */ 328 + req->req.actual = req->req.length; 329 + 330 + if (!status) { 331 + if (ep->is_in) 332 + gr_dbgprint_request("SENT", ep, req); 333 + else 334 + gr_dbgprint_request("RECV", ep, req); 335 + } 336 + 337 + /* Prevent changes to ep->queue during callback */ 338 + ep->callback = 1; 339 + if (req == dev->ep0reqo && !status) { 340 + if (req->setup) 341 + gr_ep0_setup(dev, req); 342 + else 343 + dev_err(dev->dev, 344 + "Unexpected non setup packet on ep0in\n"); 345 + } else if (req->req.complete) { 346 + spin_unlock(&dev->lock); 347 + 348 + req->req.complete(&ep->ep, &req->req); 349 + 350 + spin_lock(&dev->lock); 351 + } 352 + ep->callback = 0; 353 + } 354 + 355 + static struct usb_request *gr_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) 356 + { 357 + struct gr_request *req; 358 + 359 + req = kzalloc(sizeof(*req), gfp_flags); 360 + if (!req) 361 + return NULL; 362 + 363 + INIT_LIST_HEAD(&req->queue); 364 + 365 + return &req->req; 366 + } 367 + 368 + /* 369 + * Starts DMA for endpoint ep if there are requests in the queue. 370 + * 371 + * Must be called with dev->lock held and with !ep->stopped. 372 + */ 373 + static void gr_start_dma(struct gr_ep *ep) 374 + { 375 + struct gr_request *req; 376 + u32 dmactrl; 377 + 378 + if (list_empty(&ep->queue)) { 379 + ep->dma_start = 0; 380 + return; 381 + } 382 + 383 + req = list_first_entry(&ep->queue, struct gr_request, queue); 384 + 385 + /* A descriptor should already have been allocated */ 386 + BUG_ON(!req->curr_desc); 387 + 388 + wmb(); /* Make sure all is settled before handing it over to DMA */ 389 + 390 + /* Set the descriptor pointer in the hardware */ 391 + gr_write32(&ep->regs->dmaaddr, req->curr_desc->paddr); 392 + 393 + /* Announce available descriptors */ 394 + dmactrl = gr_read32(&ep->regs->dmactrl); 395 + gr_write32(&ep->regs->dmactrl, dmactrl | GR_DMACTRL_DA); 396 + 397 + ep->dma_start = 1; 398 + } 399 + 400 + /* 401 + * Finishes the first request in the ep's queue and, if available, starts the 402 + * next request in queue. 403 + * 404 + * Must be called with dev->lock held, irqs disabled and with !ep->stopped. 405 + */ 406 + static void gr_dma_advance(struct gr_ep *ep, int status) 407 + { 408 + struct gr_request *req; 409 + 410 + req = list_first_entry(&ep->queue, struct gr_request, queue); 411 + gr_finish_request(ep, req, status); 412 + gr_start_dma(ep); /* Regardless of ep->dma_start */ 413 + } 414 + 415 + /* 416 + * Abort DMA for an endpoint. Sets the abort DMA bit which causes an ongoing DMA 417 + * transfer to be canceled and clears GR_DMACTRL_DA. 418 + * 419 + * Must be called with dev->lock held. 420 + */ 421 + static void gr_abort_dma(struct gr_ep *ep) 422 + { 423 + u32 dmactrl; 424 + 425 + dmactrl = gr_read32(&ep->regs->dmactrl); 426 + gr_write32(&ep->regs->dmactrl, dmactrl | GR_DMACTRL_AD); 427 + } 428 + 429 + /* 430 + * Allocates and sets up a struct gr_dma_desc and putting it on the descriptor 431 + * chain. 432 + * 433 + * Size is not used for OUT endpoints. Hardware can not be instructed to handle 434 + * smaller buffer than MAXPL in the OUT direction. 435 + */ 436 + static int gr_add_dma_desc(struct gr_ep *ep, struct gr_request *req, 437 + dma_addr_t data, unsigned size, gfp_t gfp_flags) 438 + { 439 + struct gr_dma_desc *desc; 440 + 441 + desc = gr_alloc_dma_desc(ep, gfp_flags); 442 + if (!desc) 443 + return -ENOMEM; 444 + 445 + desc->data = data; 446 + if (ep->is_in) 447 + desc->ctrl = 448 + (GR_DESC_IN_CTRL_LEN_MASK & size) | GR_DESC_IN_CTRL_EN; 449 + else 450 + desc->ctrl = GR_DESC_OUT_CTRL_IE; 451 + 452 + if (!req->first_desc) { 453 + req->first_desc = desc; 454 + req->curr_desc = desc; 455 + } else { 456 + req->last_desc->next_desc = desc; 457 + req->last_desc->next = desc->paddr; 458 + req->last_desc->ctrl |= GR_DESC_OUT_CTRL_NX; 459 + } 460 + req->last_desc = desc; 461 + 462 + return 0; 463 + } 464 + 465 + /* 466 + * Sets up a chain of struct gr_dma_descriptors pointing to buffers that 467 + * together covers req->req.length bytes of the buffer at DMA address 468 + * req->req.dma for the OUT direction. 469 + * 470 + * The first descriptor in the chain is enabled, the rest disabled. The 471 + * interrupt handler will later enable them one by one when needed so we can 472 + * find out when the transfer is finished. For OUT endpoints, all descriptors 473 + * therefore generate interrutps. 474 + */ 475 + static int gr_setup_out_desc_list(struct gr_ep *ep, struct gr_request *req, 476 + gfp_t gfp_flags) 477 + { 478 + u16 bytes_left; /* Bytes left to provide descriptors for */ 479 + u16 bytes_used; /* Bytes accommodated for */ 480 + int ret = 0; 481 + 482 + req->first_desc = NULL; /* Signals that no allocation is done yet */ 483 + bytes_left = req->req.length; 484 + bytes_used = 0; 485 + while (bytes_left > 0) { 486 + dma_addr_t start = req->req.dma + bytes_used; 487 + u16 size = min(bytes_left, ep->bytes_per_buffer); 488 + 489 + /* Should not happen however - gr_queue stops such lengths */ 490 + if (size < ep->bytes_per_buffer) 491 + dev_warn(ep->dev->dev, 492 + "Buffer overrun risk: %u < %u bytes/buffer\n", 493 + size, ep->bytes_per_buffer); 494 + 495 + ret = gr_add_dma_desc(ep, req, start, size, gfp_flags); 496 + if (ret) 497 + goto alloc_err; 498 + 499 + bytes_left -= size; 500 + bytes_used += size; 501 + } 502 + 503 + req->first_desc->ctrl |= GR_DESC_OUT_CTRL_EN; 504 + 505 + return 0; 506 + 507 + alloc_err: 508 + gr_free_dma_desc_chain(ep->dev, req); 509 + 510 + return ret; 511 + } 512 + 513 + /* 514 + * Sets up a chain of struct gr_dma_descriptors pointing to buffers that 515 + * together covers req->req.length bytes of the buffer at DMA address 516 + * req->req.dma for the IN direction. 517 + * 518 + * When more data is provided than the maximum payload size, the hardware splits 519 + * this up into several payloads automatically. Moreover, ep->bytes_per_buffer 520 + * is always set to a multiple of the maximum payload (restricted to the valid 521 + * number of maximum payloads during high bandwidth isochronous or interrupt 522 + * transfers) 523 + * 524 + * All descriptors are enabled from the beginning and we only generate an 525 + * interrupt for the last one indicating that the entire request has been pushed 526 + * to hardware. 527 + */ 528 + static int gr_setup_in_desc_list(struct gr_ep *ep, struct gr_request *req, 529 + gfp_t gfp_flags) 530 + { 531 + u16 bytes_left; /* Bytes left in req to provide descriptors for */ 532 + u16 bytes_used; /* Bytes in req accommodated for */ 533 + int ret = 0; 534 + 535 + req->first_desc = NULL; /* Signals that no allocation is done yet */ 536 + bytes_left = req->req.length; 537 + bytes_used = 0; 538 + do { /* Allow for zero length packets */ 539 + dma_addr_t start = req->req.dma + bytes_used; 540 + u16 size = min(bytes_left, ep->bytes_per_buffer); 541 + 542 + ret = gr_add_dma_desc(ep, req, start, size, gfp_flags); 543 + if (ret) 544 + goto alloc_err; 545 + 546 + bytes_left -= size; 547 + bytes_used += size; 548 + } while (bytes_left > 0); 549 + 550 + /* 551 + * Send an extra zero length packet to indicate that no more data is 552 + * available when req->req.zero is set and the data length is even 553 + * multiples of ep->ep.maxpacket. 554 + */ 555 + if (req->req.zero && (req->req.length % ep->ep.maxpacket == 0)) { 556 + ret = gr_add_dma_desc(ep, req, 0, 0, gfp_flags); 557 + if (ret) 558 + goto alloc_err; 559 + } 560 + 561 + /* 562 + * For IN packets we only want to know when the last packet has been 563 + * transmitted (not just put into internal buffers). 564 + */ 565 + req->last_desc->ctrl |= GR_DESC_IN_CTRL_PI; 566 + 567 + return 0; 568 + 569 + alloc_err: 570 + gr_free_dma_desc_chain(ep->dev, req); 571 + 572 + return ret; 573 + } 574 + 575 + /* Must be called with dev->lock held */ 576 + static int gr_queue(struct gr_ep *ep, struct gr_request *req, gfp_t gfp_flags) 577 + { 578 + struct gr_udc *dev = ep->dev; 579 + int ret; 580 + 581 + if (unlikely(!ep->ep.desc && ep->num != 0)) { 582 + dev_err(dev->dev, "No ep descriptor for %s\n", ep->ep.name); 583 + return -EINVAL; 584 + } 585 + 586 + if (unlikely(!req->req.buf || !list_empty(&req->queue))) { 587 + dev_err(dev->dev, 588 + "Invalid request for %s: buf=%p list_empty=%d\n", 589 + ep->ep.name, req->req.buf, list_empty(&req->queue)); 590 + return -EINVAL; 591 + } 592 + 593 + /* 594 + * The DMA controller can not handle smaller OUT buffers than 595 + * maxpacket. It could lead to buffer overruns if unexpectedly long 596 + * packet are received. 597 + */ 598 + if (!ep->is_in && (req->req.length % ep->ep.maxpacket) != 0) { 599 + dev_err(dev->dev, 600 + "OUT request length %d is not multiple of maxpacket\n", 601 + req->req.length); 602 + return -EMSGSIZE; 603 + } 604 + 605 + if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) { 606 + dev_err(dev->dev, "-ESHUTDOWN"); 607 + return -ESHUTDOWN; 608 + } 609 + 610 + /* Can't touch registers when suspended */ 611 + if (dev->ep0state == GR_EP0_SUSPEND) { 612 + dev_err(dev->dev, "-EBUSY"); 613 + return -EBUSY; 614 + } 615 + 616 + /* Set up DMA mapping in case the caller didn't */ 617 + ret = usb_gadget_map_request(&dev->gadget, &req->req, ep->is_in); 618 + if (ret) { 619 + dev_err(dev->dev, "usb_gadget_map_request"); 620 + return ret; 621 + } 622 + 623 + if (ep->is_in) 624 + ret = gr_setup_in_desc_list(ep, req, gfp_flags); 625 + else 626 + ret = gr_setup_out_desc_list(ep, req, gfp_flags); 627 + if (ret) 628 + return ret; 629 + 630 + req->req.status = -EINPROGRESS; 631 + req->req.actual = 0; 632 + list_add_tail(&req->queue, &ep->queue); 633 + 634 + /* Start DMA if not started, otherwise interrupt handler handles it */ 635 + if (!ep->dma_start && likely(!ep->stopped)) 636 + gr_start_dma(ep); 637 + 638 + return 0; 639 + } 640 + 641 + /* 642 + * Queue a request from within the driver. 643 + * 644 + * Must be called with dev->lock held. 645 + */ 646 + static inline int gr_queue_int(struct gr_ep *ep, struct gr_request *req, 647 + gfp_t gfp_flags) 648 + { 649 + if (ep->is_in) 650 + gr_dbgprint_request("RESP", ep, req); 651 + 652 + return gr_queue(ep, req, gfp_flags); 653 + } 654 + 655 + /* ---------------------------------------------------------------------- */ 656 + /* General helper functions */ 657 + 658 + /* 659 + * Dequeue ALL requests. 660 + * 661 + * Must be called with dev->lock held and irqs disabled. 662 + */ 663 + static void gr_ep_nuke(struct gr_ep *ep) 664 + { 665 + struct gr_request *req; 666 + struct gr_udc *dev; 667 + 668 + dev = ep->dev; 669 + 670 + ep->stopped = 1; 671 + ep->dma_start = 0; 672 + gr_abort_dma(ep); 673 + 674 + while (!list_empty(&ep->queue)) { 675 + req = list_first_entry(&ep->queue, struct gr_request, queue); 676 + gr_finish_request(ep, req, -ESHUTDOWN); 677 + } 678 + } 679 + 680 + /* 681 + * Reset the hardware state of this endpoint. 682 + * 683 + * Must be called with dev->lock held. 684 + */ 685 + static void gr_ep_reset(struct gr_ep *ep) 686 + { 687 + gr_write32(&ep->regs->epctrl, 0); 688 + gr_write32(&ep->regs->dmactrl, 0); 689 + 690 + ep->ep.maxpacket = MAX_CTRL_PL_SIZE; 691 + ep->ep.desc = NULL; 692 + ep->stopped = 1; 693 + ep->dma_start = 0; 694 + } 695 + 696 + /* 697 + * Generate STALL on ep0in/out. 698 + * 699 + * Must be called with dev->lock held. 700 + */ 701 + static void gr_control_stall(struct gr_udc *dev) 702 + { 703 + u32 epctrl; 704 + 705 + epctrl = gr_read32(&dev->epo[0].regs->epctrl); 706 + gr_write32(&dev->epo[0].regs->epctrl, epctrl | GR_EPCTRL_CS); 707 + epctrl = gr_read32(&dev->epi[0].regs->epctrl); 708 + gr_write32(&dev->epi[0].regs->epctrl, epctrl | GR_EPCTRL_CS); 709 + 710 + dev->ep0state = GR_EP0_STALL; 711 + } 712 + 713 + /* 714 + * Halts, halts and wedges, or clears halt for an endpoint. 715 + * 716 + * Must be called with dev->lock held. 717 + */ 718 + static int gr_ep_halt_wedge(struct gr_ep *ep, int halt, int wedge, int fromhost) 719 + { 720 + u32 epctrl; 721 + int retval = 0; 722 + 723 + if (ep->num && !ep->ep.desc) 724 + return -EINVAL; 725 + 726 + if (ep->num && ep->ep.desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) 727 + return -EOPNOTSUPP; 728 + 729 + /* Never actually halt ep0, and therefore never clear halt for ep0 */ 730 + if (!ep->num) { 731 + if (halt && !fromhost) { 732 + /* ep0 halt from gadget - generate protocol stall */ 733 + gr_control_stall(ep->dev); 734 + dev_dbg(ep->dev->dev, "EP: stall ep0\n"); 735 + return 0; 736 + } 737 + return -EINVAL; 738 + } 739 + 740 + dev_dbg(ep->dev->dev, "EP: %s halt %s\n", 741 + (halt ? (wedge ? "wedge" : "set") : "clear"), ep->ep.name); 742 + 743 + epctrl = gr_read32(&ep->regs->epctrl); 744 + if (halt) { 745 + /* Set HALT */ 746 + gr_write32(&ep->regs->epctrl, epctrl | GR_EPCTRL_EH); 747 + ep->stopped = 1; 748 + if (wedge) 749 + ep->wedged = 1; 750 + } else { 751 + gr_write32(&ep->regs->epctrl, epctrl & ~GR_EPCTRL_EH); 752 + ep->stopped = 0; 753 + ep->wedged = 0; 754 + 755 + /* Things might have been queued up in the meantime */ 756 + if (!ep->dma_start) 757 + gr_start_dma(ep); 758 + } 759 + 760 + return retval; 761 + } 762 + 763 + /* Must be called with dev->lock held */ 764 + static inline void gr_set_ep0state(struct gr_udc *dev, enum gr_ep0state value) 765 + { 766 + if (dev->ep0state != value) 767 + dev_vdbg(dev->dev, "STATE: ep0state=%s\n", 768 + gr_ep0state_string(value)); 769 + dev->ep0state = value; 770 + } 771 + 772 + /* 773 + * Should only be called when endpoints can not generate interrupts. 774 + * 775 + * Must be called with dev->lock held. 776 + */ 777 + static void gr_disable_interrupts_and_pullup(struct gr_udc *dev) 778 + { 779 + gr_write32(&dev->regs->control, 0); 780 + wmb(); /* Make sure that we do not deny one of our interrupts */ 781 + dev->irq_enabled = 0; 782 + } 783 + 784 + /* 785 + * Stop all device activity and disable data line pullup. 786 + * 787 + * Must be called with dev->lock held and irqs disabled. 788 + */ 789 + static void gr_stop_activity(struct gr_udc *dev) 790 + { 791 + struct gr_ep *ep; 792 + 793 + list_for_each_entry(ep, &dev->ep_list, ep_list) 794 + gr_ep_nuke(ep); 795 + 796 + gr_disable_interrupts_and_pullup(dev); 797 + 798 + gr_set_ep0state(dev, GR_EP0_DISCONNECT); 799 + usb_gadget_set_state(&dev->gadget, USB_STATE_NOTATTACHED); 800 + } 801 + 802 + /* ---------------------------------------------------------------------- */ 803 + /* ep0 setup packet handling */ 804 + 805 + static void gr_ep0_testmode_complete(struct usb_ep *_ep, 806 + struct usb_request *_req) 807 + { 808 + struct gr_ep *ep; 809 + struct gr_udc *dev; 810 + u32 control; 811 + 812 + ep = container_of(_ep, struct gr_ep, ep); 813 + dev = ep->dev; 814 + 815 + spin_lock(&dev->lock); 816 + 817 + control = gr_read32(&dev->regs->control); 818 + control |= GR_CONTROL_TM | (dev->test_mode << GR_CONTROL_TS_POS); 819 + gr_write32(&dev->regs->control, control); 820 + 821 + spin_unlock(&dev->lock); 822 + } 823 + 824 + static void gr_ep0_dummy_complete(struct usb_ep *_ep, struct usb_request *_req) 825 + { 826 + /* Nothing needs to be done here */ 827 + } 828 + 829 + /* 830 + * Queue a response on ep0in. 831 + * 832 + * Must be called with dev->lock held. 833 + */ 834 + static int gr_ep0_respond(struct gr_udc *dev, u8 *buf, int length, 835 + void (*complete)(struct usb_ep *ep, 836 + struct usb_request *req)) 837 + { 838 + u8 *reqbuf = dev->ep0reqi->req.buf; 839 + int status; 840 + int i; 841 + 842 + for (i = 0; i < length; i++) 843 + reqbuf[i] = buf[i]; 844 + dev->ep0reqi->req.length = length; 845 + dev->ep0reqi->req.complete = complete; 846 + 847 + status = gr_queue_int(&dev->epi[0], dev->ep0reqi, GFP_ATOMIC); 848 + if (status < 0) 849 + dev_err(dev->dev, 850 + "Could not queue ep0in setup response: %d\n", status); 851 + 852 + return status; 853 + } 854 + 855 + /* 856 + * Queue a 2 byte response on ep0in. 857 + * 858 + * Must be called with dev->lock held. 859 + */ 860 + static inline int gr_ep0_respond_u16(struct gr_udc *dev, u16 response) 861 + { 862 + __le16 le_response = cpu_to_le16(response); 863 + 864 + return gr_ep0_respond(dev, (u8 *)&le_response, 2, 865 + gr_ep0_dummy_complete); 866 + } 867 + 868 + /* 869 + * Queue a ZLP response on ep0in. 870 + * 871 + * Must be called with dev->lock held. 872 + */ 873 + static inline int gr_ep0_respond_empty(struct gr_udc *dev) 874 + { 875 + return gr_ep0_respond(dev, NULL, 0, gr_ep0_dummy_complete); 876 + } 877 + 878 + /* 879 + * This is run when a SET_ADDRESS request is received. First writes 880 + * the new address to the control register which is updated internally 881 + * when the next IN packet is ACKED. 882 + * 883 + * Must be called with dev->lock held. 884 + */ 885 + static void gr_set_address(struct gr_udc *dev, u8 address) 886 + { 887 + u32 control; 888 + 889 + control = gr_read32(&dev->regs->control) & ~GR_CONTROL_UA_MASK; 890 + control |= (address << GR_CONTROL_UA_POS) & GR_CONTROL_UA_MASK; 891 + control |= GR_CONTROL_SU; 892 + gr_write32(&dev->regs->control, control); 893 + } 894 + 895 + /* 896 + * Returns negative for STALL, 0 for successful handling and positive for 897 + * delegation. 898 + * 899 + * Must be called with dev->lock held. 900 + */ 901 + static int gr_device_request(struct gr_udc *dev, u8 type, u8 request, 902 + u16 value, u16 index) 903 + { 904 + u16 response; 905 + u8 test; 906 + 907 + switch (request) { 908 + case USB_REQ_SET_ADDRESS: 909 + dev_dbg(dev->dev, "STATUS: address %d\n", value & 0xff); 910 + gr_set_address(dev, value & 0xff); 911 + if (value) 912 + usb_gadget_set_state(&dev->gadget, USB_STATE_ADDRESS); 913 + else 914 + usb_gadget_set_state(&dev->gadget, USB_STATE_DEFAULT); 915 + return gr_ep0_respond_empty(dev); 916 + 917 + case USB_REQ_GET_STATUS: 918 + /* Self powered | remote wakeup */ 919 + response = 0x0001 | (dev->remote_wakeup ? 0x0002 : 0); 920 + return gr_ep0_respond_u16(dev, response); 921 + 922 + case USB_REQ_SET_FEATURE: 923 + switch (value) { 924 + case USB_DEVICE_REMOTE_WAKEUP: 925 + /* Allow remote wakeup */ 926 + dev->remote_wakeup = 1; 927 + return gr_ep0_respond_empty(dev); 928 + 929 + case USB_DEVICE_TEST_MODE: 930 + /* The hardware does not support TEST_FORCE_EN */ 931 + test = index >> 8; 932 + if (test >= TEST_J && test <= TEST_PACKET) { 933 + dev->test_mode = test; 934 + return gr_ep0_respond(dev, NULL, 0, 935 + gr_ep0_testmode_complete); 936 + } 937 + } 938 + break; 939 + 940 + case USB_REQ_CLEAR_FEATURE: 941 + switch (value) { 942 + case USB_DEVICE_REMOTE_WAKEUP: 943 + /* Disallow remote wakeup */ 944 + dev->remote_wakeup = 0; 945 + return gr_ep0_respond_empty(dev); 946 + } 947 + break; 948 + } 949 + 950 + return 1; /* Delegate the rest */ 951 + } 952 + 953 + /* 954 + * Returns negative for STALL, 0 for successful handling and positive for 955 + * delegation. 956 + * 957 + * Must be called with dev->lock held. 958 + */ 959 + static int gr_interface_request(struct gr_udc *dev, u8 type, u8 request, 960 + u16 value, u16 index) 961 + { 962 + if (dev->gadget.state != USB_STATE_CONFIGURED) 963 + return -1; 964 + 965 + /* 966 + * Should return STALL for invalid interfaces, but udc driver does not 967 + * know anything about that. However, many gadget drivers do not handle 968 + * GET_STATUS so we need to take care of that. 969 + */ 970 + 971 + switch (request) { 972 + case USB_REQ_GET_STATUS: 973 + return gr_ep0_respond_u16(dev, 0x0000); 974 + 975 + case USB_REQ_SET_FEATURE: 976 + case USB_REQ_CLEAR_FEATURE: 977 + /* 978 + * No possible valid standard requests. Still let gadget drivers 979 + * have a go at it. 980 + */ 981 + break; 982 + } 983 + 984 + return 1; /* Delegate the rest */ 985 + } 986 + 987 + /* 988 + * Returns negative for STALL, 0 for successful handling and positive for 989 + * delegation. 990 + * 991 + * Must be called with dev->lock held. 992 + */ 993 + static int gr_endpoint_request(struct gr_udc *dev, u8 type, u8 request, 994 + u16 value, u16 index) 995 + { 996 + struct gr_ep *ep; 997 + int status; 998 + int halted; 999 + u8 epnum = index & USB_ENDPOINT_NUMBER_MASK; 1000 + u8 is_in = index & USB_ENDPOINT_DIR_MASK; 1001 + 1002 + if ((is_in && epnum >= dev->nepi) || (!is_in && epnum >= dev->nepo)) 1003 + return -1; 1004 + 1005 + if (dev->gadget.state != USB_STATE_CONFIGURED && epnum != 0) 1006 + return -1; 1007 + 1008 + ep = (is_in ? &dev->epi[epnum] : &dev->epo[epnum]); 1009 + 1010 + switch (request) { 1011 + case USB_REQ_GET_STATUS: 1012 + halted = gr_read32(&ep->regs->epctrl) & GR_EPCTRL_EH; 1013 + return gr_ep0_respond_u16(dev, halted ? 0x0001 : 0); 1014 + 1015 + case USB_REQ_SET_FEATURE: 1016 + switch (value) { 1017 + case USB_ENDPOINT_HALT: 1018 + status = gr_ep_halt_wedge(ep, 1, 0, 1); 1019 + if (status >= 0) 1020 + status = gr_ep0_respond_empty(dev); 1021 + return status; 1022 + } 1023 + break; 1024 + 1025 + case USB_REQ_CLEAR_FEATURE: 1026 + switch (value) { 1027 + case USB_ENDPOINT_HALT: 1028 + if (ep->wedged) 1029 + return -1; 1030 + status = gr_ep_halt_wedge(ep, 0, 0, 1); 1031 + if (status >= 0) 1032 + status = gr_ep0_respond_empty(dev); 1033 + return status; 1034 + } 1035 + break; 1036 + } 1037 + 1038 + return 1; /* Delegate the rest */ 1039 + } 1040 + 1041 + /* Must be called with dev->lock held */ 1042 + static void gr_ep0out_requeue(struct gr_udc *dev) 1043 + { 1044 + int ret = gr_queue_int(&dev->epo[0], dev->ep0reqo, GFP_ATOMIC); 1045 + 1046 + if (ret) 1047 + dev_err(dev->dev, "Could not queue ep0out setup request: %d\n", 1048 + ret); 1049 + } 1050 + 1051 + /* 1052 + * The main function dealing with setup requests on ep0. 1053 + * 1054 + * Must be called with dev->lock held and irqs disabled 1055 + */ 1056 + static void gr_ep0_setup(struct gr_udc *dev, struct gr_request *req) 1057 + __releases(&dev->lock) 1058 + __acquires(&dev->lock) 1059 + { 1060 + union { 1061 + struct usb_ctrlrequest ctrl; 1062 + u8 raw[8]; 1063 + u32 word[2]; 1064 + } u; 1065 + u8 type; 1066 + u8 request; 1067 + u16 value; 1068 + u16 index; 1069 + u16 length; 1070 + int i; 1071 + int status; 1072 + 1073 + /* Restore from ep0 halt */ 1074 + if (dev->ep0state == GR_EP0_STALL) { 1075 + gr_set_ep0state(dev, GR_EP0_SETUP); 1076 + if (!req->req.actual) 1077 + goto out; 1078 + } 1079 + 1080 + if (dev->ep0state == GR_EP0_ISTATUS) { 1081 + gr_set_ep0state(dev, GR_EP0_SETUP); 1082 + if (req->req.actual > 0) 1083 + dev_dbg(dev->dev, 1084 + "Unexpected setup packet at state %s\n", 1085 + gr_ep0state_string(GR_EP0_ISTATUS)); 1086 + else 1087 + goto out; /* Got expected ZLP */ 1088 + } else if (dev->ep0state != GR_EP0_SETUP) { 1089 + dev_info(dev->dev, 1090 + "Unexpected ep0out request at state %s - stalling\n", 1091 + gr_ep0state_string(dev->ep0state)); 1092 + gr_control_stall(dev); 1093 + gr_set_ep0state(dev, GR_EP0_SETUP); 1094 + goto out; 1095 + } else if (!req->req.actual) { 1096 + dev_dbg(dev->dev, "Unexpected ZLP at state %s\n", 1097 + gr_ep0state_string(dev->ep0state)); 1098 + goto out; 1099 + } 1100 + 1101 + /* Handle SETUP packet */ 1102 + for (i = 0; i < req->req.actual; i++) 1103 + u.raw[i] = ((u8 *)req->req.buf)[i]; 1104 + 1105 + type = u.ctrl.bRequestType; 1106 + request = u.ctrl.bRequest; 1107 + value = le16_to_cpu(u.ctrl.wValue); 1108 + index = le16_to_cpu(u.ctrl.wIndex); 1109 + length = le16_to_cpu(u.ctrl.wLength); 1110 + 1111 + gr_dbgprint_devreq(dev, type, request, value, index, length); 1112 + 1113 + /* Check for data stage */ 1114 + if (length) { 1115 + if (type & USB_DIR_IN) 1116 + gr_set_ep0state(dev, GR_EP0_IDATA); 1117 + else 1118 + gr_set_ep0state(dev, GR_EP0_ODATA); 1119 + } 1120 + 1121 + status = 1; /* Positive status flags delegation */ 1122 + if ((type & USB_TYPE_MASK) == USB_TYPE_STANDARD) { 1123 + switch (type & USB_RECIP_MASK) { 1124 + case USB_RECIP_DEVICE: 1125 + status = gr_device_request(dev, type, request, 1126 + value, index); 1127 + break; 1128 + case USB_RECIP_ENDPOINT: 1129 + status = gr_endpoint_request(dev, type, request, 1130 + value, index); 1131 + break; 1132 + case USB_RECIP_INTERFACE: 1133 + status = gr_interface_request(dev, type, request, 1134 + value, index); 1135 + break; 1136 + } 1137 + } 1138 + 1139 + if (status > 0) { 1140 + spin_unlock(&dev->lock); 1141 + 1142 + dev_vdbg(dev->dev, "DELEGATE\n"); 1143 + status = dev->driver->setup(&dev->gadget, &u.ctrl); 1144 + 1145 + spin_lock(&dev->lock); 1146 + } 1147 + 1148 + /* Generate STALL on both ep0out and ep0in if requested */ 1149 + if (unlikely(status < 0)) { 1150 + dev_vdbg(dev->dev, "STALL\n"); 1151 + gr_control_stall(dev); 1152 + } 1153 + 1154 + if ((type & USB_TYPE_MASK) == USB_TYPE_STANDARD && 1155 + request == USB_REQ_SET_CONFIGURATION) { 1156 + if (!value) { 1157 + dev_dbg(dev->dev, "STATUS: deconfigured\n"); 1158 + usb_gadget_set_state(&dev->gadget, USB_STATE_ADDRESS); 1159 + } else if (status >= 0) { 1160 + /* Not configured unless gadget OK:s it */ 1161 + dev_dbg(dev->dev, "STATUS: configured: %d\n", value); 1162 + usb_gadget_set_state(&dev->gadget, 1163 + USB_STATE_CONFIGURED); 1164 + } 1165 + } 1166 + 1167 + /* Get ready for next stage */ 1168 + if (dev->ep0state == GR_EP0_ODATA) 1169 + gr_set_ep0state(dev, GR_EP0_OSTATUS); 1170 + else if (dev->ep0state == GR_EP0_IDATA) 1171 + gr_set_ep0state(dev, GR_EP0_ISTATUS); 1172 + else 1173 + gr_set_ep0state(dev, GR_EP0_SETUP); 1174 + 1175 + out: 1176 + gr_ep0out_requeue(dev); 1177 + } 1178 + 1179 + /* ---------------------------------------------------------------------- */ 1180 + /* VBUS and USB reset handling */ 1181 + 1182 + /* Must be called with dev->lock held and irqs disabled */ 1183 + static void gr_vbus_connected(struct gr_udc *dev, u32 status) 1184 + { 1185 + u32 control; 1186 + 1187 + dev->gadget.speed = GR_SPEED(status); 1188 + usb_gadget_set_state(&dev->gadget, USB_STATE_POWERED); 1189 + 1190 + /* Turn on full interrupts and pullup */ 1191 + control = (GR_CONTROL_SI | GR_CONTROL_UI | GR_CONTROL_VI | 1192 + GR_CONTROL_SP | GR_CONTROL_EP); 1193 + gr_write32(&dev->regs->control, control); 1194 + } 1195 + 1196 + /* Must be called with dev->lock held */ 1197 + static void gr_enable_vbus_detect(struct gr_udc *dev) 1198 + { 1199 + u32 status; 1200 + 1201 + dev->irq_enabled = 1; 1202 + wmb(); /* Make sure we do not ignore an interrupt */ 1203 + gr_write32(&dev->regs->control, GR_CONTROL_VI); 1204 + 1205 + /* Take care of the case we are already plugged in at this point */ 1206 + status = gr_read32(&dev->regs->status); 1207 + if (status & GR_STATUS_VB) 1208 + gr_vbus_connected(dev, status); 1209 + } 1210 + 1211 + /* Must be called with dev->lock held and irqs disabled */ 1212 + static void gr_vbus_disconnected(struct gr_udc *dev) 1213 + { 1214 + gr_stop_activity(dev); 1215 + 1216 + /* Report disconnect */ 1217 + if (dev->driver && dev->driver->disconnect) { 1218 + spin_unlock(&dev->lock); 1219 + 1220 + dev->driver->disconnect(&dev->gadget); 1221 + 1222 + spin_lock(&dev->lock); 1223 + } 1224 + 1225 + gr_enable_vbus_detect(dev); 1226 + } 1227 + 1228 + /* Must be called with dev->lock held and irqs disabled */ 1229 + static void gr_udc_usbreset(struct gr_udc *dev, u32 status) 1230 + { 1231 + gr_set_address(dev, 0); 1232 + gr_set_ep0state(dev, GR_EP0_SETUP); 1233 + usb_gadget_set_state(&dev->gadget, USB_STATE_DEFAULT); 1234 + dev->gadget.speed = GR_SPEED(status); 1235 + 1236 + gr_ep_nuke(&dev->epo[0]); 1237 + gr_ep_nuke(&dev->epi[0]); 1238 + dev->epo[0].stopped = 0; 1239 + dev->epi[0].stopped = 0; 1240 + gr_ep0out_requeue(dev); 1241 + } 1242 + 1243 + /* ---------------------------------------------------------------------- */ 1244 + /* Irq handling */ 1245 + 1246 + /* 1247 + * Handles interrupts from in endpoints. Returns whether something was handled. 1248 + * 1249 + * Must be called with dev->lock held, irqs disabled and with !ep->stopped. 1250 + */ 1251 + static int gr_handle_in_ep(struct gr_ep *ep) 1252 + { 1253 + struct gr_request *req; 1254 + 1255 + req = list_first_entry(&ep->queue, struct gr_request, queue); 1256 + if (!req->last_desc) 1257 + return 0; 1258 + 1259 + if (ACCESS_ONCE(req->last_desc->ctrl) & GR_DESC_IN_CTRL_EN) 1260 + return 0; /* Not put in hardware buffers yet */ 1261 + 1262 + if (gr_read32(&ep->regs->epstat) & (GR_EPSTAT_B1 | GR_EPSTAT_B0)) 1263 + return 0; /* Not transmitted yet, still in hardware buffers */ 1264 + 1265 + /* Write complete */ 1266 + gr_dma_advance(ep, 0); 1267 + 1268 + return 1; 1269 + } 1270 + 1271 + /* 1272 + * Handles interrupts from out endpoints. Returns whether something was handled. 1273 + * 1274 + * Must be called with dev->lock held, irqs disabled and with !ep->stopped. 1275 + */ 1276 + static int gr_handle_out_ep(struct gr_ep *ep) 1277 + { 1278 + u32 ep_dmactrl; 1279 + u32 ctrl; 1280 + u16 len; 1281 + struct gr_request *req; 1282 + struct gr_udc *dev = ep->dev; 1283 + 1284 + req = list_first_entry(&ep->queue, struct gr_request, queue); 1285 + if (!req->curr_desc) 1286 + return 0; 1287 + 1288 + ctrl = ACCESS_ONCE(req->curr_desc->ctrl); 1289 + if (ctrl & GR_DESC_OUT_CTRL_EN) 1290 + return 0; /* Not received yet */ 1291 + 1292 + /* Read complete */ 1293 + len = ctrl & GR_DESC_OUT_CTRL_LEN_MASK; 1294 + req->req.actual += len; 1295 + if (ctrl & GR_DESC_OUT_CTRL_SE) 1296 + req->setup = 1; 1297 + 1298 + if (len < ep->ep.maxpacket || req->req.actual == req->req.length) { 1299 + /* Short packet or the expected size - we are done */ 1300 + 1301 + if ((ep == &dev->epo[0]) && (dev->ep0state == GR_EP0_OSTATUS)) { 1302 + /* 1303 + * Send a status stage ZLP to ack the DATA stage in the 1304 + * OUT direction. This needs to be done before 1305 + * gr_dma_advance as that can lead to a call to 1306 + * ep0_setup that can change dev->ep0state. 1307 + */ 1308 + gr_ep0_respond_empty(dev); 1309 + gr_set_ep0state(dev, GR_EP0_SETUP); 1310 + } 1311 + 1312 + gr_dma_advance(ep, 0); 1313 + } else { 1314 + /* Not done yet. Enable the next descriptor to receive more. */ 1315 + req->curr_desc = req->curr_desc->next_desc; 1316 + req->curr_desc->ctrl |= GR_DESC_OUT_CTRL_EN; 1317 + 1318 + ep_dmactrl = gr_read32(&ep->regs->dmactrl); 1319 + gr_write32(&ep->regs->dmactrl, ep_dmactrl | GR_DMACTRL_DA); 1320 + } 1321 + 1322 + return 1; 1323 + } 1324 + 1325 + /* 1326 + * Handle state changes. Returns whether something was handled. 1327 + * 1328 + * Must be called with dev->lock held and irqs disabled. 1329 + */ 1330 + static int gr_handle_state_changes(struct gr_udc *dev) 1331 + { 1332 + u32 status = gr_read32(&dev->regs->status); 1333 + int handled = 0; 1334 + int powstate = !(dev->gadget.state == USB_STATE_NOTATTACHED || 1335 + dev->gadget.state == USB_STATE_ATTACHED); 1336 + 1337 + /* VBUS valid detected */ 1338 + if (!powstate && (status & GR_STATUS_VB)) { 1339 + dev_dbg(dev->dev, "STATUS: vbus valid detected\n"); 1340 + gr_vbus_connected(dev, status); 1341 + handled = 1; 1342 + } 1343 + 1344 + /* Disconnect */ 1345 + if (powstate && !(status & GR_STATUS_VB)) { 1346 + dev_dbg(dev->dev, "STATUS: vbus invalid detected\n"); 1347 + gr_vbus_disconnected(dev); 1348 + handled = 1; 1349 + } 1350 + 1351 + /* USB reset detected */ 1352 + if (status & GR_STATUS_UR) { 1353 + dev_dbg(dev->dev, "STATUS: USB reset - speed is %s\n", 1354 + GR_SPEED_STR(status)); 1355 + gr_write32(&dev->regs->status, GR_STATUS_UR); 1356 + gr_udc_usbreset(dev, status); 1357 + handled = 1; 1358 + } 1359 + 1360 + /* Speed change */ 1361 + if (dev->gadget.speed != GR_SPEED(status)) { 1362 + dev_dbg(dev->dev, "STATUS: USB Speed change to %s\n", 1363 + GR_SPEED_STR(status)); 1364 + dev->gadget.speed = GR_SPEED(status); 1365 + handled = 1; 1366 + } 1367 + 1368 + /* Going into suspend */ 1369 + if ((dev->ep0state != GR_EP0_SUSPEND) && !(status & GR_STATUS_SU)) { 1370 + dev_dbg(dev->dev, "STATUS: USB suspend\n"); 1371 + gr_set_ep0state(dev, GR_EP0_SUSPEND); 1372 + dev->suspended_from = dev->gadget.state; 1373 + usb_gadget_set_state(&dev->gadget, USB_STATE_SUSPENDED); 1374 + 1375 + if ((dev->gadget.speed != USB_SPEED_UNKNOWN) && 1376 + dev->driver && dev->driver->suspend) { 1377 + spin_unlock(&dev->lock); 1378 + 1379 + dev->driver->suspend(&dev->gadget); 1380 + 1381 + spin_lock(&dev->lock); 1382 + } 1383 + handled = 1; 1384 + } 1385 + 1386 + /* Coming out of suspend */ 1387 + if ((dev->ep0state == GR_EP0_SUSPEND) && (status & GR_STATUS_SU)) { 1388 + dev_dbg(dev->dev, "STATUS: USB resume\n"); 1389 + if (dev->suspended_from == USB_STATE_POWERED) 1390 + gr_set_ep0state(dev, GR_EP0_DISCONNECT); 1391 + else 1392 + gr_set_ep0state(dev, GR_EP0_SETUP); 1393 + usb_gadget_set_state(&dev->gadget, dev->suspended_from); 1394 + 1395 + if ((dev->gadget.speed != USB_SPEED_UNKNOWN) && 1396 + dev->driver && dev->driver->resume) { 1397 + spin_unlock(&dev->lock); 1398 + 1399 + dev->driver->resume(&dev->gadget); 1400 + 1401 + spin_lock(&dev->lock); 1402 + } 1403 + handled = 1; 1404 + } 1405 + 1406 + return handled; 1407 + } 1408 + 1409 + /* Non-interrupt context irq handler */ 1410 + static irqreturn_t gr_irq_handler(int irq, void *_dev) 1411 + { 1412 + struct gr_udc *dev = _dev; 1413 + struct gr_ep *ep; 1414 + int handled = 0; 1415 + int i; 1416 + unsigned long flags; 1417 + 1418 + spin_lock_irqsave(&dev->lock, flags); 1419 + 1420 + if (!dev->irq_enabled) 1421 + goto out; 1422 + 1423 + /* 1424 + * Check IN ep interrupts. We check these before the OUT eps because 1425 + * some gadgets reuse the request that might already be currently 1426 + * outstanding and needs to be completed (mainly setup requests). 1427 + */ 1428 + for (i = 0; i < dev->nepi; i++) { 1429 + ep = &dev->epi[i]; 1430 + if (!ep->stopped && !ep->callback && !list_empty(&ep->queue)) 1431 + handled = gr_handle_in_ep(ep) || handled; 1432 + } 1433 + 1434 + /* Check OUT ep interrupts */ 1435 + for (i = 0; i < dev->nepo; i++) { 1436 + ep = &dev->epo[i]; 1437 + if (!ep->stopped && !ep->callback && !list_empty(&ep->queue)) 1438 + handled = gr_handle_out_ep(ep) || handled; 1439 + } 1440 + 1441 + /* Check status interrupts */ 1442 + handled = gr_handle_state_changes(dev) || handled; 1443 + 1444 + /* 1445 + * Check AMBA DMA errors. Only check if we didn't find anything else to 1446 + * handle because this shouldn't happen if we did everything right. 1447 + */ 1448 + if (!handled) { 1449 + list_for_each_entry(ep, &dev->ep_list, ep_list) { 1450 + if (gr_read32(&ep->regs->dmactrl) & GR_DMACTRL_AE) { 1451 + dev_err(dev->dev, 1452 + "AMBA Error occurred for %s\n", 1453 + ep->ep.name); 1454 + handled = 1; 1455 + } 1456 + } 1457 + } 1458 + 1459 + out: 1460 + spin_unlock_irqrestore(&dev->lock, flags); 1461 + 1462 + return handled ? IRQ_HANDLED : IRQ_NONE; 1463 + } 1464 + 1465 + /* Interrupt context irq handler */ 1466 + static irqreturn_t gr_irq(int irq, void *_dev) 1467 + { 1468 + struct gr_udc *dev = _dev; 1469 + 1470 + if (!dev->irq_enabled) 1471 + return IRQ_NONE; 1472 + 1473 + return IRQ_WAKE_THREAD; 1474 + } 1475 + 1476 + /* ---------------------------------------------------------------------- */ 1477 + /* USB ep ops */ 1478 + 1479 + /* Enable endpoint. Not for ep0in and ep0out that are handled separately. */ 1480 + static int gr_ep_enable(struct usb_ep *_ep, 1481 + const struct usb_endpoint_descriptor *desc) 1482 + { 1483 + struct gr_udc *dev; 1484 + struct gr_ep *ep; 1485 + u8 mode; 1486 + u8 nt; 1487 + u16 max; 1488 + u16 buffer_size = 0; 1489 + u32 epctrl; 1490 + 1491 + ep = container_of(_ep, struct gr_ep, ep); 1492 + if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) 1493 + return -EINVAL; 1494 + 1495 + dev = ep->dev; 1496 + 1497 + /* 'ep0' IN and OUT are reserved */ 1498 + if (ep == &dev->epo[0] || ep == &dev->epi[0]) 1499 + return -EINVAL; 1500 + 1501 + if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) 1502 + return -ESHUTDOWN; 1503 + 1504 + /* Make sure we are clear for enabling */ 1505 + epctrl = gr_read32(&ep->regs->epctrl); 1506 + if (epctrl & GR_EPCTRL_EV) 1507 + return -EBUSY; 1508 + 1509 + /* Check that directions match */ 1510 + if (!ep->is_in != !usb_endpoint_dir_in(desc)) 1511 + return -EINVAL; 1512 + 1513 + /* Check ep num */ 1514 + if ((!ep->is_in && ep->num >= dev->nepo) || 1515 + (ep->is_in && ep->num >= dev->nepi)) 1516 + return -EINVAL; 1517 + 1518 + if (usb_endpoint_xfer_control(desc)) { 1519 + mode = 0; 1520 + } else if (usb_endpoint_xfer_isoc(desc)) { 1521 + mode = 1; 1522 + } else if (usb_endpoint_xfer_bulk(desc)) { 1523 + mode = 2; 1524 + } else if (usb_endpoint_xfer_int(desc)) { 1525 + mode = 3; 1526 + } else { 1527 + dev_err(dev->dev, "Unknown transfer type for %s\n", 1528 + ep->ep.name); 1529 + return -EINVAL; 1530 + } 1531 + 1532 + /* 1533 + * Bits 10-0 set the max payload. 12-11 set the number of 1534 + * additional transactions. 1535 + */ 1536 + max = 0x7ff & usb_endpoint_maxp(desc); 1537 + nt = 0x3 & (usb_endpoint_maxp(desc) >> 11); 1538 + buffer_size = GR_BUFFER_SIZE(epctrl); 1539 + if (nt && (mode == 0 || mode == 2)) { 1540 + dev_err(dev->dev, 1541 + "%s mode: multiple trans./microframe not valid\n", 1542 + (mode == 2 ? "Bulk" : "Control")); 1543 + return -EINVAL; 1544 + } else if (nt == 0x11) { 1545 + dev_err(dev->dev, "Invalid value for trans./microframe\n"); 1546 + return -EINVAL; 1547 + } else if ((nt + 1) * max > buffer_size) { 1548 + dev_err(dev->dev, "Hw buffer size %d < max payload %d * %d\n", 1549 + buffer_size, (nt + 1), max); 1550 + return -EINVAL; 1551 + } else if (max == 0) { 1552 + dev_err(dev->dev, "Max payload cannot be set to 0\n"); 1553 + return -EINVAL; 1554 + } 1555 + 1556 + spin_lock(&ep->dev->lock); 1557 + 1558 + if (!ep->stopped) { 1559 + spin_unlock(&ep->dev->lock); 1560 + return -EBUSY; 1561 + } 1562 + 1563 + ep->stopped = 0; 1564 + ep->wedged = 0; 1565 + ep->ep.desc = desc; 1566 + ep->ep.maxpacket = max; 1567 + ep->dma_start = 0; 1568 + 1569 + 1570 + if (nt) { 1571 + /* 1572 + * Maximum possible size of all payloads in one microframe 1573 + * regardless of direction when using high-bandwidth mode. 1574 + */ 1575 + ep->bytes_per_buffer = (nt + 1) * max; 1576 + } else if (ep->is_in) { 1577 + /* 1578 + * The biggest multiple of maximum packet size that fits into 1579 + * the buffer. The hardware will split up into many packets in 1580 + * the IN direction. 1581 + */ 1582 + ep->bytes_per_buffer = (buffer_size / max) * max; 1583 + } else { 1584 + /* 1585 + * Only single packets will be placed the buffers in the OUT 1586 + * direction. 1587 + */ 1588 + ep->bytes_per_buffer = max; 1589 + } 1590 + 1591 + epctrl = (max << GR_EPCTRL_MAXPL_POS) 1592 + | (nt << GR_EPCTRL_NT_POS) 1593 + | (mode << GR_EPCTRL_TT_POS) 1594 + | GR_EPCTRL_EV; 1595 + if (ep->is_in) 1596 + epctrl |= GR_EPCTRL_PI; 1597 + gr_write32(&ep->regs->epctrl, epctrl); 1598 + 1599 + gr_write32(&ep->regs->dmactrl, GR_DMACTRL_IE | GR_DMACTRL_AI); 1600 + 1601 + spin_unlock(&ep->dev->lock); 1602 + 1603 + dev_dbg(ep->dev->dev, "EP: %s enabled - %s with %d bytes/buffer\n", 1604 + ep->ep.name, gr_modestring[mode], ep->bytes_per_buffer); 1605 + return 0; 1606 + } 1607 + 1608 + /* Disable endpoint. Not for ep0in and ep0out that are handled separately. */ 1609 + static int gr_ep_disable(struct usb_ep *_ep) 1610 + { 1611 + struct gr_ep *ep; 1612 + struct gr_udc *dev; 1613 + unsigned long flags; 1614 + 1615 + ep = container_of(_ep, struct gr_ep, ep); 1616 + if (!_ep || !ep->ep.desc) 1617 + return -ENODEV; 1618 + 1619 + dev = ep->dev; 1620 + 1621 + /* 'ep0' IN and OUT are reserved */ 1622 + if (ep == &dev->epo[0] || ep == &dev->epi[0]) 1623 + return -EINVAL; 1624 + 1625 + if (dev->ep0state == GR_EP0_SUSPEND) 1626 + return -EBUSY; 1627 + 1628 + dev_dbg(ep->dev->dev, "EP: disable %s\n", ep->ep.name); 1629 + 1630 + spin_lock_irqsave(&dev->lock, flags); 1631 + 1632 + gr_ep_nuke(ep); 1633 + gr_ep_reset(ep); 1634 + ep->ep.desc = NULL; 1635 + 1636 + spin_unlock_irqrestore(&dev->lock, flags); 1637 + 1638 + return 0; 1639 + } 1640 + 1641 + /* 1642 + * Frees a request, but not any DMA buffers associated with it 1643 + * (gr_finish_request should already have taken care of that). 1644 + */ 1645 + static void gr_free_request(struct usb_ep *_ep, struct usb_request *_req) 1646 + { 1647 + struct gr_request *req; 1648 + 1649 + if (!_ep || !_req) 1650 + return; 1651 + req = container_of(_req, struct gr_request, req); 1652 + 1653 + /* Leads to memory leak */ 1654 + WARN(!list_empty(&req->queue), 1655 + "request not dequeued properly before freeing\n"); 1656 + 1657 + kfree(req); 1658 + } 1659 + 1660 + /* Queue a request from the gadget */ 1661 + static int gr_queue_ext(struct usb_ep *_ep, struct usb_request *_req, 1662 + gfp_t gfp_flags) 1663 + { 1664 + struct gr_ep *ep; 1665 + struct gr_request *req; 1666 + struct gr_udc *dev; 1667 + int ret; 1668 + 1669 + if (unlikely(!_ep || !_req)) 1670 + return -EINVAL; 1671 + 1672 + ep = container_of(_ep, struct gr_ep, ep); 1673 + req = container_of(_req, struct gr_request, req); 1674 + dev = ep->dev; 1675 + 1676 + spin_lock(&ep->dev->lock); 1677 + 1678 + /* 1679 + * The ep0 pointer in the gadget struct is used both for ep0in and 1680 + * ep0out. In a data stage in the out direction ep0out needs to be used 1681 + * instead of the default ep0in. Completion functions might use 1682 + * driver_data, so that needs to be copied as well. 1683 + */ 1684 + if ((ep == &dev->epi[0]) && (dev->ep0state == GR_EP0_ODATA)) { 1685 + ep = &dev->epo[0]; 1686 + ep->ep.driver_data = dev->epi[0].ep.driver_data; 1687 + } 1688 + 1689 + if (ep->is_in) 1690 + gr_dbgprint_request("EXTERN", ep, req); 1691 + 1692 + ret = gr_queue(ep, req, gfp_flags); 1693 + 1694 + spin_unlock(&ep->dev->lock); 1695 + 1696 + return ret; 1697 + } 1698 + 1699 + /* Dequeue JUST ONE request */ 1700 + static int gr_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1701 + { 1702 + struct gr_request *req; 1703 + struct gr_ep *ep; 1704 + struct gr_udc *dev; 1705 + int ret = 0; 1706 + unsigned long flags; 1707 + 1708 + ep = container_of(_ep, struct gr_ep, ep); 1709 + if (!_ep || !_req || (!ep->ep.desc && ep->num != 0)) 1710 + return -EINVAL; 1711 + dev = ep->dev; 1712 + if (!dev->driver) 1713 + return -ESHUTDOWN; 1714 + 1715 + /* We can't touch (DMA) registers when suspended */ 1716 + if (dev->ep0state == GR_EP0_SUSPEND) 1717 + return -EBUSY; 1718 + 1719 + spin_lock_irqsave(&dev->lock, flags); 1720 + 1721 + /* Make sure it's actually queued on this endpoint */ 1722 + list_for_each_entry(req, &ep->queue, queue) { 1723 + if (&req->req == _req) 1724 + break; 1725 + } 1726 + if (&req->req != _req) { 1727 + ret = -EINVAL; 1728 + goto out; 1729 + } 1730 + 1731 + if (list_first_entry(&ep->queue, struct gr_request, queue) == req) { 1732 + /* This request is currently being processed */ 1733 + gr_abort_dma(ep); 1734 + if (ep->stopped) 1735 + gr_finish_request(ep, req, -ECONNRESET); 1736 + else 1737 + gr_dma_advance(ep, -ECONNRESET); 1738 + } else if (!list_empty(&req->queue)) { 1739 + /* Not being processed - gr_finish_request dequeues it */ 1740 + gr_finish_request(ep, req, -ECONNRESET); 1741 + } else { 1742 + ret = -EOPNOTSUPP; 1743 + } 1744 + 1745 + out: 1746 + spin_unlock_irqrestore(&dev->lock, flags); 1747 + 1748 + return ret; 1749 + } 1750 + 1751 + /* Helper for gr_set_halt and gr_set_wedge */ 1752 + static int gr_set_halt_wedge(struct usb_ep *_ep, int halt, int wedge) 1753 + { 1754 + int ret; 1755 + struct gr_ep *ep; 1756 + 1757 + if (!_ep) 1758 + return -ENODEV; 1759 + ep = container_of(_ep, struct gr_ep, ep); 1760 + 1761 + spin_lock(&ep->dev->lock); 1762 + 1763 + /* Halting an IN endpoint should fail if queue is not empty */ 1764 + if (halt && ep->is_in && !list_empty(&ep->queue)) { 1765 + ret = -EAGAIN; 1766 + goto out; 1767 + } 1768 + 1769 + ret = gr_ep_halt_wedge(ep, halt, wedge, 0); 1770 + 1771 + out: 1772 + spin_unlock(&ep->dev->lock); 1773 + 1774 + return ret; 1775 + } 1776 + 1777 + /* Halt endpoint */ 1778 + static int gr_set_halt(struct usb_ep *_ep, int halt) 1779 + { 1780 + return gr_set_halt_wedge(_ep, halt, 0); 1781 + } 1782 + 1783 + /* Halt and wedge endpoint */ 1784 + static int gr_set_wedge(struct usb_ep *_ep) 1785 + { 1786 + return gr_set_halt_wedge(_ep, 1, 1); 1787 + } 1788 + 1789 + /* 1790 + * Return the total number of bytes currently stored in the internal buffers of 1791 + * the endpoint. 1792 + */ 1793 + static int gr_fifo_status(struct usb_ep *_ep) 1794 + { 1795 + struct gr_ep *ep; 1796 + u32 epstat; 1797 + u32 bytes = 0; 1798 + 1799 + if (!_ep) 1800 + return -ENODEV; 1801 + ep = container_of(_ep, struct gr_ep, ep); 1802 + 1803 + epstat = gr_read32(&ep->regs->epstat); 1804 + 1805 + if (epstat & GR_EPSTAT_B0) 1806 + bytes += (epstat & GR_EPSTAT_B0CNT_MASK) >> GR_EPSTAT_B0CNT_POS; 1807 + if (epstat & GR_EPSTAT_B1) 1808 + bytes += (epstat & GR_EPSTAT_B1CNT_MASK) >> GR_EPSTAT_B1CNT_POS; 1809 + 1810 + return bytes; 1811 + } 1812 + 1813 + 1814 + /* Empty data from internal buffers of an endpoint. */ 1815 + static void gr_fifo_flush(struct usb_ep *_ep) 1816 + { 1817 + struct gr_ep *ep; 1818 + u32 epctrl; 1819 + 1820 + if (!_ep) 1821 + return; 1822 + ep = container_of(_ep, struct gr_ep, ep); 1823 + dev_vdbg(ep->dev->dev, "EP: flush fifo %s\n", ep->ep.name); 1824 + 1825 + spin_lock(&ep->dev->lock); 1826 + 1827 + epctrl = gr_read32(&ep->regs->epctrl); 1828 + epctrl |= GR_EPCTRL_CB; 1829 + gr_write32(&ep->regs->epctrl, epctrl); 1830 + 1831 + spin_unlock(&ep->dev->lock); 1832 + } 1833 + 1834 + static struct usb_ep_ops gr_ep_ops = { 1835 + .enable = gr_ep_enable, 1836 + .disable = gr_ep_disable, 1837 + 1838 + .alloc_request = gr_alloc_request, 1839 + .free_request = gr_free_request, 1840 + 1841 + .queue = gr_queue_ext, 1842 + .dequeue = gr_dequeue, 1843 + 1844 + .set_halt = gr_set_halt, 1845 + .set_wedge = gr_set_wedge, 1846 + .fifo_status = gr_fifo_status, 1847 + .fifo_flush = gr_fifo_flush, 1848 + }; 1849 + 1850 + /* ---------------------------------------------------------------------- */ 1851 + /* USB Gadget ops */ 1852 + 1853 + static int gr_get_frame(struct usb_gadget *_gadget) 1854 + { 1855 + struct gr_udc *dev; 1856 + 1857 + if (!_gadget) 1858 + return -ENODEV; 1859 + dev = container_of(_gadget, struct gr_udc, gadget); 1860 + return gr_read32(&dev->regs->status) & GR_STATUS_FN_MASK; 1861 + } 1862 + 1863 + static int gr_wakeup(struct usb_gadget *_gadget) 1864 + { 1865 + struct gr_udc *dev; 1866 + 1867 + if (!_gadget) 1868 + return -ENODEV; 1869 + dev = container_of(_gadget, struct gr_udc, gadget); 1870 + 1871 + /* Remote wakeup feature not enabled by host*/ 1872 + if (!dev->remote_wakeup) 1873 + return -EINVAL; 1874 + 1875 + spin_lock(&dev->lock); 1876 + 1877 + gr_write32(&dev->regs->control, 1878 + gr_read32(&dev->regs->control) | GR_CONTROL_RW); 1879 + 1880 + spin_unlock(&dev->lock); 1881 + 1882 + return 0; 1883 + } 1884 + 1885 + static int gr_pullup(struct usb_gadget *_gadget, int is_on) 1886 + { 1887 + struct gr_udc *dev; 1888 + u32 control; 1889 + 1890 + if (!_gadget) 1891 + return -ENODEV; 1892 + dev = container_of(_gadget, struct gr_udc, gadget); 1893 + 1894 + spin_lock(&dev->lock); 1895 + 1896 + control = gr_read32(&dev->regs->control); 1897 + if (is_on) 1898 + control |= GR_CONTROL_EP; 1899 + else 1900 + control &= ~GR_CONTROL_EP; 1901 + gr_write32(&dev->regs->control, control); 1902 + 1903 + spin_unlock(&dev->lock); 1904 + 1905 + return 0; 1906 + } 1907 + 1908 + static int gr_udc_start(struct usb_gadget *gadget, 1909 + struct usb_gadget_driver *driver) 1910 + { 1911 + struct gr_udc *dev = to_gr_udc(gadget); 1912 + 1913 + spin_lock(&dev->lock); 1914 + 1915 + /* Hook up the driver */ 1916 + driver->driver.bus = NULL; 1917 + dev->driver = driver; 1918 + 1919 + /* Get ready for host detection */ 1920 + gr_enable_vbus_detect(dev); 1921 + 1922 + spin_unlock(&dev->lock); 1923 + 1924 + dev_info(dev->dev, "Started with gadget driver '%s'\n", 1925 + driver->driver.name); 1926 + 1927 + return 0; 1928 + } 1929 + 1930 + static int gr_udc_stop(struct usb_gadget *gadget, 1931 + struct usb_gadget_driver *driver) 1932 + { 1933 + struct gr_udc *dev = to_gr_udc(gadget); 1934 + unsigned long flags; 1935 + 1936 + spin_lock_irqsave(&dev->lock, flags); 1937 + 1938 + dev->driver = NULL; 1939 + gr_stop_activity(dev); 1940 + 1941 + spin_unlock_irqrestore(&dev->lock, flags); 1942 + 1943 + dev_info(dev->dev, "Stopped\n"); 1944 + 1945 + return 0; 1946 + } 1947 + 1948 + static const struct usb_gadget_ops gr_ops = { 1949 + .get_frame = gr_get_frame, 1950 + .wakeup = gr_wakeup, 1951 + .pullup = gr_pullup, 1952 + .udc_start = gr_udc_start, 1953 + .udc_stop = gr_udc_stop, 1954 + /* Other operations not supported */ 1955 + }; 1956 + 1957 + /* ---------------------------------------------------------------------- */ 1958 + /* Module probe, removal and of-matching */ 1959 + 1960 + static const char * const onames[] = { 1961 + "ep0out", "ep1out", "ep2out", "ep3out", "ep4out", "ep5out", 1962 + "ep6out", "ep7out", "ep8out", "ep9out", "ep10out", "ep11out", 1963 + "ep12out", "ep13out", "ep14out", "ep15out" 1964 + }; 1965 + 1966 + static const char * const inames[] = { 1967 + "ep0in", "ep1in", "ep2in", "ep3in", "ep4in", "ep5in", 1968 + "ep6in", "ep7in", "ep8in", "ep9in", "ep10in", "ep11in", 1969 + "ep12in", "ep13in", "ep14in", "ep15in" 1970 + }; 1971 + 1972 + /* Must be called with dev->lock held */ 1973 + static int gr_ep_init(struct gr_udc *dev, int num, int is_in, u32 maxplimit) 1974 + { 1975 + struct gr_ep *ep; 1976 + struct gr_request *req; 1977 + struct usb_request *_req; 1978 + void *buf; 1979 + 1980 + if (is_in) { 1981 + ep = &dev->epi[num]; 1982 + ep->ep.name = inames[num]; 1983 + ep->regs = &dev->regs->epi[num]; 1984 + } else { 1985 + ep = &dev->epo[num]; 1986 + ep->ep.name = onames[num]; 1987 + ep->regs = &dev->regs->epo[num]; 1988 + } 1989 + 1990 + gr_ep_reset(ep); 1991 + ep->num = num; 1992 + ep->is_in = is_in; 1993 + ep->dev = dev; 1994 + ep->ep.ops = &gr_ep_ops; 1995 + INIT_LIST_HEAD(&ep->queue); 1996 + 1997 + if (num == 0) { 1998 + _req = gr_alloc_request(&ep->ep, GFP_KERNEL); 1999 + buf = devm_kzalloc(dev->dev, PAGE_SIZE, GFP_DMA | GFP_KERNEL); 2000 + if (!_req || !buf) { 2001 + /* possible _req freed by gr_probe via gr_remove */ 2002 + return -ENOMEM; 2003 + } 2004 + 2005 + req = container_of(_req, struct gr_request, req); 2006 + req->req.buf = buf; 2007 + req->req.length = MAX_CTRL_PL_SIZE; 2008 + 2009 + if (is_in) 2010 + dev->ep0reqi = req; /* Complete gets set as used */ 2011 + else 2012 + dev->ep0reqo = req; /* Completion treated separately */ 2013 + 2014 + usb_ep_set_maxpacket_limit(&ep->ep, MAX_CTRL_PL_SIZE); 2015 + ep->bytes_per_buffer = MAX_CTRL_PL_SIZE; 2016 + } else { 2017 + usb_ep_set_maxpacket_limit(&ep->ep, (u16)maxplimit); 2018 + list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); 2019 + } 2020 + list_add_tail(&ep->ep_list, &dev->ep_list); 2021 + 2022 + return 0; 2023 + } 2024 + 2025 + /* Must be called with dev->lock held */ 2026 + static int gr_udc_init(struct gr_udc *dev) 2027 + { 2028 + struct device_node *np = dev->dev->of_node; 2029 + u32 epctrl_val; 2030 + u32 dmactrl_val; 2031 + int i; 2032 + int ret = 0; 2033 + u32 *bufsizes; 2034 + u32 bufsize; 2035 + int len; 2036 + 2037 + gr_set_address(dev, 0); 2038 + 2039 + INIT_LIST_HEAD(&dev->gadget.ep_list); 2040 + dev->gadget.speed = USB_SPEED_UNKNOWN; 2041 + dev->gadget.ep0 = &dev->epi[0].ep; 2042 + 2043 + INIT_LIST_HEAD(&dev->ep_list); 2044 + gr_set_ep0state(dev, GR_EP0_DISCONNECT); 2045 + 2046 + bufsizes = (u32 *)of_get_property(np, "epobufsizes", &len); 2047 + len /= sizeof(u32); 2048 + for (i = 0; i < dev->nepo; i++) { 2049 + bufsize = (bufsizes && i < len) ? bufsizes[i] : 1024; 2050 + ret = gr_ep_init(dev, i, 0, bufsize); 2051 + if (ret) 2052 + return ret; 2053 + } 2054 + 2055 + bufsizes = (u32 *)of_get_property(np, "epibufsizes", &len); 2056 + len /= sizeof(u32); 2057 + for (i = 0; i < dev->nepi; i++) { 2058 + bufsize = (bufsizes && i < len) ? bufsizes[i] : 1024; 2059 + ret = gr_ep_init(dev, i, 1, bufsize); 2060 + if (ret) 2061 + return ret; 2062 + } 2063 + 2064 + /* Must be disabled by default */ 2065 + dev->remote_wakeup = 0; 2066 + 2067 + /* Enable ep0out and ep0in */ 2068 + epctrl_val = (MAX_CTRL_PL_SIZE << GR_EPCTRL_MAXPL_POS) | GR_EPCTRL_EV; 2069 + dmactrl_val = GR_DMACTRL_IE | GR_DMACTRL_AI; 2070 + gr_write32(&dev->epo[0].regs->epctrl, epctrl_val); 2071 + gr_write32(&dev->epi[0].regs->epctrl, epctrl_val | GR_EPCTRL_PI); 2072 + gr_write32(&dev->epo[0].regs->dmactrl, dmactrl_val); 2073 + gr_write32(&dev->epi[0].regs->dmactrl, dmactrl_val); 2074 + 2075 + return 0; 2076 + } 2077 + 2078 + static int gr_remove(struct platform_device *ofdev) 2079 + { 2080 + struct gr_udc *dev = dev_get_drvdata(&ofdev->dev); 2081 + 2082 + if (dev->added) 2083 + usb_del_gadget_udc(&dev->gadget); /* Shuts everything down */ 2084 + if (dev->driver) 2085 + return -EBUSY; 2086 + 2087 + gr_dfs_delete(dev); 2088 + if (dev->desc_pool) 2089 + dma_pool_destroy(dev->desc_pool); 2090 + dev_set_drvdata(&ofdev->dev, NULL); 2091 + 2092 + gr_free_request(&dev->epi[0].ep, &dev->ep0reqi->req); 2093 + gr_free_request(&dev->epo[0].ep, &dev->ep0reqo->req); 2094 + 2095 + return 0; 2096 + } 2097 + static int gr_request_irq(struct gr_udc *dev, int irq) 2098 + { 2099 + return devm_request_threaded_irq(dev->dev, irq, gr_irq, gr_irq_handler, 2100 + IRQF_SHARED, driver_name, dev); 2101 + } 2102 + 2103 + static int gr_probe(struct platform_device *ofdev) 2104 + { 2105 + struct gr_udc *dev; 2106 + struct resource *res; 2107 + struct gr_regs __iomem *regs; 2108 + int retval; 2109 + u32 status; 2110 + 2111 + dev = devm_kzalloc(&ofdev->dev, sizeof(*dev), GFP_KERNEL); 2112 + if (!dev) 2113 + return -ENOMEM; 2114 + dev->dev = &ofdev->dev; 2115 + 2116 + res = platform_get_resource(ofdev, IORESOURCE_MEM, 0); 2117 + regs = devm_ioremap_resource(dev->dev, res); 2118 + if (IS_ERR(regs)) 2119 + return PTR_ERR(regs); 2120 + 2121 + dev->irq = irq_of_parse_and_map(dev->dev->of_node, 0); 2122 + if (!dev->irq) { 2123 + dev_err(dev->dev, "No irq found\n"); 2124 + return -ENODEV; 2125 + } 2126 + 2127 + /* Some core configurations has separate irqs for IN and OUT events */ 2128 + dev->irqi = irq_of_parse_and_map(dev->dev->of_node, 1); 2129 + if (dev->irqi) { 2130 + dev->irqo = irq_of_parse_and_map(dev->dev->of_node, 2); 2131 + if (!dev->irqo) { 2132 + dev_err(dev->dev, "Found irqi but not irqo\n"); 2133 + return -ENODEV; 2134 + } 2135 + } 2136 + 2137 + dev->gadget.name = driver_name; 2138 + dev->gadget.max_speed = USB_SPEED_HIGH; 2139 + dev->gadget.ops = &gr_ops; 2140 + dev->gadget.quirk_ep_out_aligned_size = true; 2141 + 2142 + spin_lock_init(&dev->lock); 2143 + dev->regs = regs; 2144 + 2145 + dev_set_drvdata(&ofdev->dev, dev); 2146 + 2147 + /* Determine number of endpoints and data interface mode */ 2148 + status = gr_read32(&dev->regs->status); 2149 + dev->nepi = ((status & GR_STATUS_NEPI_MASK) >> GR_STATUS_NEPI_POS) + 1; 2150 + dev->nepo = ((status & GR_STATUS_NEPO_MASK) >> GR_STATUS_NEPO_POS) + 1; 2151 + 2152 + if (!(status & GR_STATUS_DM)) { 2153 + dev_err(dev->dev, "Slave mode cores are not supported\n"); 2154 + return -ENODEV; 2155 + } 2156 + 2157 + /* --- Effects of the following calls might need explicit cleanup --- */ 2158 + 2159 + /* Create DMA pool for descriptors */ 2160 + dev->desc_pool = dma_pool_create("desc_pool", dev->dev, 2161 + sizeof(struct gr_dma_desc), 4, 0); 2162 + if (!dev->desc_pool) { 2163 + dev_err(dev->dev, "Could not allocate DMA pool"); 2164 + return -ENOMEM; 2165 + } 2166 + 2167 + spin_lock(&dev->lock); 2168 + 2169 + /* Inside lock so that no gadget can use this udc until probe is done */ 2170 + retval = usb_add_gadget_udc(dev->dev, &dev->gadget); 2171 + if (retval) { 2172 + dev_err(dev->dev, "Could not add gadget udc"); 2173 + goto out; 2174 + } 2175 + dev->added = 1; 2176 + 2177 + retval = gr_udc_init(dev); 2178 + if (retval) 2179 + goto out; 2180 + 2181 + gr_dfs_create(dev); 2182 + 2183 + /* Clear all interrupt enables that might be left on since last boot */ 2184 + gr_disable_interrupts_and_pullup(dev); 2185 + 2186 + retval = gr_request_irq(dev, dev->irq); 2187 + if (retval) { 2188 + dev_err(dev->dev, "Failed to request irq %d\n", dev->irq); 2189 + goto out; 2190 + } 2191 + 2192 + if (dev->irqi) { 2193 + retval = gr_request_irq(dev, dev->irqi); 2194 + if (retval) { 2195 + dev_err(dev->dev, "Failed to request irqi %d\n", 2196 + dev->irqi); 2197 + goto out; 2198 + } 2199 + retval = gr_request_irq(dev, dev->irqo); 2200 + if (retval) { 2201 + dev_err(dev->dev, "Failed to request irqo %d\n", 2202 + dev->irqo); 2203 + goto out; 2204 + } 2205 + } 2206 + 2207 + if (dev->irqi) 2208 + dev_info(dev->dev, "regs: %p, irqs %d, %d, %d\n", dev->regs, 2209 + dev->irq, dev->irqi, dev->irqo); 2210 + else 2211 + dev_info(dev->dev, "regs: %p, irq %d\n", dev->regs, dev->irq); 2212 + 2213 + out: 2214 + spin_unlock(&dev->lock); 2215 + 2216 + if (retval) 2217 + gr_remove(ofdev); 2218 + 2219 + return retval; 2220 + } 2221 + 2222 + static struct of_device_id gr_match[] = { 2223 + {.name = "GAISLER_USBDC"}, 2224 + {.name = "01_021"}, 2225 + {}, 2226 + }; 2227 + MODULE_DEVICE_TABLE(of, gr_match); 2228 + 2229 + static struct platform_driver gr_driver = { 2230 + .driver = { 2231 + .name = DRIVER_NAME, 2232 + .owner = THIS_MODULE, 2233 + .of_match_table = gr_match, 2234 + }, 2235 + .probe = gr_probe, 2236 + .remove = gr_remove, 2237 + }; 2238 + module_platform_driver(gr_driver); 2239 + 2240 + MODULE_AUTHOR("Aeroflex Gaisler AB."); 2241 + MODULE_DESCRIPTION(DRIVER_DESC); 2242 + MODULE_LICENSE("GPL");
+220
drivers/usb/gadget/gr_udc.h
··· 1 + /* 2 + * USB Peripheral Controller driver for Aeroflex Gaisler GRUSBDC. 3 + * 4 + * 2013 (c) Aeroflex Gaisler AB 5 + * 6 + * This driver supports GRUSBDC USB Device Controller cores available in the 7 + * GRLIB VHDL IP core library. 8 + * 9 + * Full documentation of the GRUSBDC core can be found here: 10 + * http://www.gaisler.com/products/grlib/grip.pdf 11 + * 12 + * This program is free software; you can redistribute it and/or modify it 13 + * under the terms of the GNU General Public License as published by the 14 + * Free Software Foundation; either version 2 of the License, or (at your 15 + * option) any later version. 16 + * 17 + * Contributors: 18 + * - Andreas Larsson <andreas@gaisler.com> 19 + * - Marko Isomaki 20 + */ 21 + 22 + /* Control registers on the AMBA bus */ 23 + 24 + #define GR_MAXEP 16 /* Max # endpoints for *each* direction */ 25 + 26 + struct gr_epregs { 27 + u32 epctrl; 28 + union { 29 + struct { /* Slave mode*/ 30 + u32 slvctrl; 31 + u32 slvdata; 32 + }; 33 + struct { /* DMA mode*/ 34 + u32 dmactrl; 35 + u32 dmaaddr; 36 + }; 37 + }; 38 + u32 epstat; 39 + }; 40 + 41 + struct gr_regs { 42 + struct gr_epregs epo[GR_MAXEP]; /* 0x000 - 0x0fc */ 43 + struct gr_epregs epi[GR_MAXEP]; /* 0x100 - 0x1fc */ 44 + u32 control; /* 0x200 */ 45 + u32 status; /* 0x204 */ 46 + }; 47 + 48 + #define GR_EPCTRL_BUFSZ_SCALER 8 49 + #define GR_EPCTRL_BUFSZ_MASK 0xffe00000 50 + #define GR_EPCTRL_BUFSZ_POS 21 51 + #define GR_EPCTRL_PI BIT(20) 52 + #define GR_EPCTRL_CB BIT(19) 53 + #define GR_EPCTRL_CS BIT(18) 54 + #define GR_EPCTRL_MAXPL_MASK 0x0003ff80 55 + #define GR_EPCTRL_MAXPL_POS 7 56 + #define GR_EPCTRL_NT_MASK 0x00000060 57 + #define GR_EPCTRL_NT_POS 5 58 + #define GR_EPCTRL_TT_MASK 0x00000018 59 + #define GR_EPCTRL_TT_POS 3 60 + #define GR_EPCTRL_EH BIT(2) 61 + #define GR_EPCTRL_ED BIT(1) 62 + #define GR_EPCTRL_EV BIT(0) 63 + 64 + #define GR_DMACTRL_AE BIT(10) 65 + #define GR_DMACTRL_AD BIT(3) 66 + #define GR_DMACTRL_AI BIT(2) 67 + #define GR_DMACTRL_IE BIT(1) 68 + #define GR_DMACTRL_DA BIT(0) 69 + 70 + #define GR_EPSTAT_PT BIT(29) 71 + #define GR_EPSTAT_PR BIT(29) 72 + #define GR_EPSTAT_B1CNT_MASK 0x1fff0000 73 + #define GR_EPSTAT_B1CNT_POS 16 74 + #define GR_EPSTAT_B0CNT_MASK 0x0000fff8 75 + #define GR_EPSTAT_B0CNT_POS 3 76 + #define GR_EPSTAT_B1 BIT(2) 77 + #define GR_EPSTAT_B0 BIT(1) 78 + #define GR_EPSTAT_BS BIT(0) 79 + 80 + #define GR_CONTROL_SI BIT(31) 81 + #define GR_CONTROL_UI BIT(30) 82 + #define GR_CONTROL_VI BIT(29) 83 + #define GR_CONTROL_SP BIT(28) 84 + #define GR_CONTROL_FI BIT(27) 85 + #define GR_CONTROL_EP BIT(14) 86 + #define GR_CONTROL_DH BIT(13) 87 + #define GR_CONTROL_RW BIT(12) 88 + #define GR_CONTROL_TS_MASK 0x00000e00 89 + #define GR_CONTROL_TS_POS 9 90 + #define GR_CONTROL_TM BIT(8) 91 + #define GR_CONTROL_UA_MASK 0x000000fe 92 + #define GR_CONTROL_UA_POS 1 93 + #define GR_CONTROL_SU BIT(0) 94 + 95 + #define GR_STATUS_NEPI_MASK 0xf0000000 96 + #define GR_STATUS_NEPI_POS 28 97 + #define GR_STATUS_NEPO_MASK 0x0f000000 98 + #define GR_STATUS_NEPO_POS 24 99 + #define GR_STATUS_DM BIT(23) 100 + #define GR_STATUS_SU BIT(17) 101 + #define GR_STATUS_UR BIT(16) 102 + #define GR_STATUS_VB BIT(15) 103 + #define GR_STATUS_SP BIT(14) 104 + #define GR_STATUS_AF_MASK 0x00003800 105 + #define GR_STATUS_AF_POS 11 106 + #define GR_STATUS_FN_MASK 0x000007ff 107 + #define GR_STATUS_FN_POS 0 108 + 109 + 110 + #define MAX_CTRL_PL_SIZE 64 /* As per USB standard for full and high speed */ 111 + 112 + /*-------------------------------------------------------------------------*/ 113 + 114 + /* Driver data structures and utilities */ 115 + 116 + struct gr_dma_desc { 117 + u32 ctrl; 118 + u32 data; 119 + u32 next; 120 + 121 + /* These must be last because hw uses the previous three */ 122 + u32 paddr; 123 + struct gr_dma_desc *next_desc; 124 + }; 125 + 126 + #define GR_DESC_OUT_CTRL_SE BIT(17) 127 + #define GR_DESC_OUT_CTRL_IE BIT(15) 128 + #define GR_DESC_OUT_CTRL_NX BIT(14) 129 + #define GR_DESC_OUT_CTRL_EN BIT(13) 130 + #define GR_DESC_OUT_CTRL_LEN_MASK 0x00001fff 131 + 132 + #define GR_DESC_IN_CTRL_MO BIT(18) 133 + #define GR_DESC_IN_CTRL_PI BIT(17) 134 + #define GR_DESC_IN_CTRL_ML BIT(16) 135 + #define GR_DESC_IN_CTRL_IE BIT(15) 136 + #define GR_DESC_IN_CTRL_NX BIT(14) 137 + #define GR_DESC_IN_CTRL_EN BIT(13) 138 + #define GR_DESC_IN_CTRL_LEN_MASK 0x00001fff 139 + 140 + #define GR_DESC_DMAADDR_MASK 0xfffffffc 141 + 142 + struct gr_ep { 143 + struct usb_ep ep; 144 + struct gr_udc *dev; 145 + u16 bytes_per_buffer; 146 + unsigned int dma_start; 147 + struct gr_epregs __iomem *regs; 148 + 149 + unsigned num:8; 150 + unsigned is_in:1; 151 + unsigned stopped:1; 152 + unsigned wedged:1; 153 + unsigned callback:1; 154 + 155 + /* analogous to a host-side qh */ 156 + struct list_head queue; 157 + 158 + struct list_head ep_list; 159 + }; 160 + 161 + struct gr_request { 162 + struct usb_request req; 163 + struct list_head queue; 164 + 165 + /* Chain of dma descriptors */ 166 + struct gr_dma_desc *first_desc; /* First in the chain */ 167 + struct gr_dma_desc *curr_desc; /* Current descriptor */ 168 + struct gr_dma_desc *last_desc; /* Last in the chain */ 169 + 170 + u8 setup; /* Setup packet */ 171 + }; 172 + 173 + enum gr_ep0state { 174 + GR_EP0_DISCONNECT = 0, /* No host */ 175 + GR_EP0_SETUP, /* Between STATUS ack and SETUP report */ 176 + GR_EP0_IDATA, /* IN data stage */ 177 + GR_EP0_ODATA, /* OUT data stage */ 178 + GR_EP0_ISTATUS, /* Status stage after IN data stage */ 179 + GR_EP0_OSTATUS, /* Status stage after OUT data stage */ 180 + GR_EP0_STALL, /* Data or status stages */ 181 + GR_EP0_SUSPEND, /* USB suspend */ 182 + }; 183 + 184 + struct gr_udc { 185 + struct usb_gadget gadget; 186 + struct gr_ep epi[GR_MAXEP]; 187 + struct gr_ep epo[GR_MAXEP]; 188 + struct usb_gadget_driver *driver; 189 + struct dma_pool *desc_pool; 190 + struct device *dev; 191 + 192 + enum gr_ep0state ep0state; 193 + struct gr_request *ep0reqo; 194 + struct gr_request *ep0reqi; 195 + 196 + struct gr_regs __iomem *regs; 197 + int irq; 198 + int irqi; 199 + int irqo; 200 + 201 + unsigned added:1; 202 + unsigned irq_enabled:1; 203 + unsigned remote_wakeup:1; 204 + 205 + u8 test_mode; 206 + 207 + enum usb_device_state suspended_from; 208 + 209 + unsigned int nepi; 210 + unsigned int nepo; 211 + 212 + struct list_head ep_list; 213 + 214 + spinlock_t lock; /* General lock, a.k.a. "dev->lock" in comments */ 215 + 216 + struct dentry *dfs_root; 217 + struct dentry *dfs_state; 218 + }; 219 + 220 + #define to_gr_udc(gadget) (container_of((gadget), struct gr_udc, gadget))
+1 -1
drivers/usb/gadget/lpc32xx_udc.c
··· 1449 1449 1450 1450 if (i != 0) 1451 1451 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); 1452 - ep->ep.maxpacket = ep->maxpacket; 1452 + usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); 1453 1453 INIT_LIST_HEAD(&ep->queue); 1454 1454 ep->req_pending = 0; 1455 1455 }
+2 -2
drivers/usb/gadget/m66592-udc.c
··· 1647 1647 INIT_LIST_HEAD(&ep->queue); 1648 1648 ep->ep.name = m66592_ep_name[i]; 1649 1649 ep->ep.ops = &m66592_ep_ops; 1650 - ep->ep.maxpacket = 512; 1650 + usb_ep_set_maxpacket_limit(&ep->ep, 512); 1651 1651 } 1652 - m66592->ep[0].ep.maxpacket = 64; 1652 + usb_ep_set_maxpacket_limit(&m66592->ep[0].ep, 64); 1653 1653 m66592->ep[0].pipenum = 0; 1654 1654 m66592->ep[0].fifoaddr = M66592_CFIFO; 1655 1655 m66592->ep[0].fifosel = M66592_CFIFOSEL;
+2 -2
drivers/usb/gadget/mv_u3d_core.c
··· 1336 1336 ep->ep.name = ep->name; 1337 1337 ep->ep.ops = &mv_u3d_ep_ops; 1338 1338 ep->wedge = 0; 1339 - ep->ep.maxpacket = MV_U3D_EP0_MAX_PKT_SIZE; 1339 + usb_ep_set_maxpacket_limit(&ep->ep, MV_U3D_EP0_MAX_PKT_SIZE); 1340 1340 ep->ep_num = 0; 1341 1341 ep->ep.desc = &mv_u3d_ep0_desc; 1342 1342 INIT_LIST_HEAD(&ep->queue); ··· 1361 1361 ep->ep.name = ep->name; 1362 1362 1363 1363 ep->ep.ops = &mv_u3d_ep_ops; 1364 - ep->ep.maxpacket = (unsigned short) ~0; 1364 + usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); 1365 1365 ep->ep_num = i / 2; 1366 1366 1367 1367 INIT_LIST_HEAD(&ep->queue);
+2 -2
drivers/usb/gadget/mv_udc_core.c
··· 1261 1261 ep->ep.ops = &mv_ep_ops; 1262 1262 ep->wedge = 0; 1263 1263 ep->stopped = 0; 1264 - ep->ep.maxpacket = EP0_MAX_PKT_SIZE; 1264 + usb_ep_set_maxpacket_limit(&ep->ep, EP0_MAX_PKT_SIZE); 1265 1265 ep->ep_num = 0; 1266 1266 ep->ep.desc = &mv_ep0_desc; 1267 1267 INIT_LIST_HEAD(&ep->queue); ··· 1284 1284 1285 1285 ep->ep.ops = &mv_ep_ops; 1286 1286 ep->stopped = 0; 1287 - ep->ep.maxpacket = (unsigned short) ~0; 1287 + usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); 1288 1288 ep->ep_num = i / 2; 1289 1289 1290 1290 INIT_LIST_HEAD(&ep->queue);
+2 -2
drivers/usb/gadget/net2272.c
··· 266 266 ep->desc = NULL; 267 267 INIT_LIST_HEAD(&ep->queue); 268 268 269 - ep->ep.maxpacket = ~0; 269 + usb_ep_set_maxpacket_limit(&ep->ep, ~0); 270 270 ep->ep.ops = &net2272_ep_ops; 271 271 272 272 /* disable irqs, endpoint */ ··· 1409 1409 ep->fifo_size = 64; 1410 1410 net2272_ep_reset(ep); 1411 1411 } 1412 - dev->ep[0].ep.maxpacket = 64; 1412 + usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 64); 1413 1413 1414 1414 dev->gadget.ep0 = &dev->ep[0].ep; 1415 1415 dev->ep[0].stopped = 0;
+4 -4
drivers/usb/gadget/net2280.c
··· 293 293 ep->desc = NULL; 294 294 INIT_LIST_HEAD (&ep->queue); 295 295 296 - ep->ep.maxpacket = ~0; 296 + usb_ep_set_maxpacket_limit(&ep->ep, ~0); 297 297 ep->ep.ops = &net2280_ep_ops; 298 298 299 299 /* disable the dma, irqs, endpoint... */ ··· 1805 1805 ep->regs = &dev->epregs [tmp]; 1806 1806 ep_reset (dev->regs, ep); 1807 1807 } 1808 - dev->ep [0].ep.maxpacket = 64; 1809 - dev->ep [5].ep.maxpacket = 64; 1810 - dev->ep [6].ep.maxpacket = 64; 1808 + usb_ep_set_maxpacket_limit(&dev->ep [0].ep, 64); 1809 + usb_ep_set_maxpacket_limit(&dev->ep [5].ep, 64); 1810 + usb_ep_set_maxpacket_limit(&dev->ep [6].ep, 64); 1811 1811 1812 1812 dev->gadget.ep0 = &dev->ep [0].ep; 1813 1813 dev->ep [0].stopped = 0;
+3 -3
drivers/usb/gadget/nokia.c
··· 126 126 struct usb_function *f_ecm; 127 127 struct usb_function *f_obex2 = NULL; 128 128 int status = 0; 129 - int obex1_stat = 0; 130 - int obex2_stat = 0; 131 - int phonet_stat = 0; 129 + int obex1_stat = -1; 130 + int obex2_stat = -1; 131 + int phonet_stat = -1; 132 132 133 133 if (!IS_ERR(fi_phonet)) { 134 134 f_phonet = usb_get_function(fi_phonet);
+2 -1
drivers/usb/gadget/omap_udc.c
··· 2586 2586 2587 2587 ep->ep.name = ep->name; 2588 2588 ep->ep.ops = &omap_ep_ops; 2589 - ep->ep.maxpacket = ep->maxpacket = maxp; 2589 + ep->maxpacket = maxp; 2590 + usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); 2590 2591 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); 2591 2592 2592 2593 return buf;
+3 -3
drivers/usb/gadget/pch_udc.c
··· 2896 2896 ep->offset_addr = (UDC_EPINT_OUT_SHIFT + ep->num) * 2897 2897 UDC_EP_REG_SHIFT; 2898 2898 /* need to set ep->ep.maxpacket and set Default Configuration?*/ 2899 - ep->ep.maxpacket = UDC_BULK_MAX_PKT_SIZE; 2899 + usb_ep_set_maxpacket_limit(&ep->ep, UDC_BULK_MAX_PKT_SIZE); 2900 2900 list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); 2901 2901 INIT_LIST_HEAD(&ep->queue); 2902 2902 } 2903 - dev->ep[UDC_EP0IN_IDX].ep.maxpacket = UDC_EP0IN_MAX_PKT_SIZE; 2904 - dev->ep[UDC_EP0OUT_IDX].ep.maxpacket = UDC_EP0OUT_MAX_PKT_SIZE; 2903 + usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0IN_IDX].ep, UDC_EP0IN_MAX_PKT_SIZE); 2904 + usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0OUT_IDX].ep, UDC_EP0OUT_MAX_PKT_SIZE); 2905 2905 2906 2906 /* remove ep0 in and out from the list. They have own pointer */ 2907 2907 list_del_init(&dev->ep[UDC_EP0IN_IDX].ep.ep_list);
+1
drivers/usb/gadget/pxa25x_udc.c
··· 1194 1194 ep->stopped = 0; 1195 1195 INIT_LIST_HEAD (&ep->queue); 1196 1196 ep->pio_irqs = 0; 1197 + usb_ep_set_maxpacket_limit(&ep->ep, ep->ep.maxpacket); 1197 1198 } 1198 1199 1199 1200 /* the rest was statically initialized, and is read-only */
+4 -1
drivers/usb/gadget/pxa27x_udc.c
··· 1737 1737 } 1738 1738 1739 1739 /* USB endpoints init */ 1740 - for (i = 1; i < NR_USB_ENDPOINTS; i++) 1740 + for (i = 1; i < NR_USB_ENDPOINTS; i++) { 1741 1741 list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list, 1742 1742 &dev->gadget.ep_list); 1743 + usb_ep_set_maxpacket_limit(&dev->udc_usb_ep[i].usb_ep, 1744 + dev->udc_usb_ep[i].usb_ep.maxpacket); 1745 + } 1743 1746 } 1744 1747 1745 1748 /**
+5 -5
drivers/usb/gadget/r8a66597-udc.c
··· 1833 1833 r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); 1834 1834 1835 1835 if (r8a66597->pdata->on_chip) { 1836 - clk_disable(r8a66597->clk); 1836 + clk_disable_unprepare(r8a66597->clk); 1837 1837 clk_put(r8a66597->clk); 1838 1838 } 1839 1839 ··· 1931 1931 ret = PTR_ERR(r8a66597->clk); 1932 1932 goto clean_up; 1933 1933 } 1934 - clk_enable(r8a66597->clk); 1934 + clk_prepare_enable(r8a66597->clk); 1935 1935 } 1936 1936 1937 1937 if (r8a66597->pdata->sudmac) { ··· 1964 1964 INIT_LIST_HEAD(&ep->queue); 1965 1965 ep->ep.name = r8a66597_ep_name[i]; 1966 1966 ep->ep.ops = &r8a66597_ep_ops; 1967 - ep->ep.maxpacket = 512; 1967 + usb_ep_set_maxpacket_limit(&ep->ep, 512); 1968 1968 } 1969 - r8a66597->ep[0].ep.maxpacket = 64; 1969 + usb_ep_set_maxpacket_limit(&r8a66597->ep[0].ep, 64); 1970 1970 r8a66597->ep[0].pipenum = 0; 1971 1971 r8a66597->ep[0].fifoaddr = CFIFO; 1972 1972 r8a66597->ep[0].fifosel = CFIFOSEL; ··· 1996 1996 free_irq(irq, r8a66597); 1997 1997 clean_up2: 1998 1998 if (r8a66597->pdata->on_chip) { 1999 - clk_disable(r8a66597->clk); 1999 + clk_disable_unprepare(r8a66597->clk); 2000 2000 clk_put(r8a66597->clk); 2001 2001 } 2002 2002 clean_up:
+2 -5
drivers/usb/gadget/rndis.c
··· 1142 1142 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 1143 1143 1144 1144 1145 - static int rndis_init(void) 1145 + int rndis_init(void) 1146 1146 { 1147 1147 u8 i; 1148 1148 ··· 1174 1174 1175 1175 return 0; 1176 1176 } 1177 - module_init(rndis_init); 1178 1177 1179 - static void rndis_exit(void) 1178 + void rndis_exit(void) 1180 1179 { 1181 1180 #ifdef CONFIG_USB_GADGET_DEBUG_FILES 1182 1181 u8 i; ··· 1187 1188 } 1188 1189 #endif 1189 1190 } 1190 - module_exit(rndis_exit); 1191 1191 1192 - MODULE_LICENSE("GPL");
+59 -22
drivers/usb/gadget/s3c-hsotg.c
··· 30 30 #include <linux/clk.h> 31 31 #include <linux/regulator/consumer.h> 32 32 #include <linux/of_platform.h> 33 + #include <linux/phy/phy.h> 34 + #include <linux/usb/phy.h> 33 35 34 36 #include <linux/usb/ch9.h> 35 37 #include <linux/usb/gadget.h> 36 38 #include <linux/usb/phy.h> 37 39 #include <linux/platform_data/s3c-hsotg.h> 38 - 39 - #include <mach/map.h> 40 40 41 41 #include "s3c-hsotg.h" 42 42 ··· 140 140 * @dev: The parent device supplied to the probe function 141 141 * @driver: USB gadget driver 142 142 * @phy: The otg phy transceiver structure for phy control. 143 + * @uphy: The otg phy transceiver structure for old USB phy control. 143 144 * @plat: The platform specific configuration data. This can be removed once 144 145 * all SoCs support usb transceiver. 145 146 * @regs: The memory area mapped for accessing registers. 146 147 * @irq: The IRQ number we are using 147 148 * @supplies: Definition of USB power supplies 149 + * @phyif: PHY interface width 148 150 * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. 149 151 * @num_of_eps: Number of available EPs (excluding EP0) 150 152 * @debug_root: root directrory for debugfs. ··· 163 161 struct s3c_hsotg { 164 162 struct device *dev; 165 163 struct usb_gadget_driver *driver; 166 - struct usb_phy *phy; 164 + struct phy *phy; 165 + struct usb_phy *uphy; 167 166 struct s3c_hsotg_plat *plat; 168 167 169 168 spinlock_t lock; ··· 175 172 176 173 struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; 177 174 175 + u32 phyif; 178 176 unsigned int dedicated_fifos:1; 179 177 unsigned char num_of_eps; 180 178 ··· 2090 2086 case DSTS_EnumSpd_FS48: 2091 2087 hsotg->gadget.speed = USB_SPEED_FULL; 2092 2088 ep0_mps = EP0_MPS_LIMIT; 2093 - ep_mps = 64; 2089 + ep_mps = 1023; 2094 2090 break; 2095 2091 2096 2092 case DSTS_EnumSpd_HS: 2097 2093 hsotg->gadget.speed = USB_SPEED_HIGH; 2098 2094 ep0_mps = EP0_MPS_LIMIT; 2099 - ep_mps = 512; 2095 + ep_mps = 1024; 2100 2096 break; 2101 2097 2102 2098 case DSTS_EnumSpd_LS: ··· 2160 2156 s3c_hsotg_complete_request(hsotg, ep, req, 2161 2157 result); 2162 2158 } 2159 + if(hsotg->dedicated_fifos) 2160 + if ((readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072) 2161 + s3c_hsotg_txfifo_flush(hsotg, ep->index); 2163 2162 } 2164 2163 2165 2164 #define call_gadget(_hs, _entry) \ ··· 2290 2283 */ 2291 2284 2292 2285 /* set the PLL on, remove the HNP/SRP and set the PHY */ 2293 - writel(GUSBCFG_PHYIf16 | GUSBCFG_TOutCal(7) | 2286 + writel(hsotg->phyif | GUSBCFG_TOutCal(7) | 2294 2287 (0x5 << 10), hsotg->regs + GUSBCFG); 2295 2288 2296 2289 s3c_hsotg_init_fifo(hsotg); ··· 2915 2908 2916 2909 dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev); 2917 2910 2918 - if (hsotg->phy) 2919 - usb_phy_init(hsotg->phy); 2911 + if (hsotg->phy) { 2912 + phy_init(hsotg->phy); 2913 + phy_power_on(hsotg->phy); 2914 + } else if (hsotg->uphy) 2915 + usb_phy_init(hsotg->uphy); 2920 2916 else if (hsotg->plat->phy_init) 2921 2917 hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); 2922 2918 } ··· 2935 2925 { 2936 2926 struct platform_device *pdev = to_platform_device(hsotg->dev); 2937 2927 2938 - if (hsotg->phy) 2939 - usb_phy_shutdown(hsotg->phy); 2928 + if (hsotg->phy) { 2929 + phy_power_off(hsotg->phy); 2930 + phy_exit(hsotg->phy); 2931 + } else if (hsotg->uphy) 2932 + usb_phy_shutdown(hsotg->uphy); 2940 2933 else if (hsotg->plat->phy_exit) 2941 2934 hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); 2942 2935 } ··· 3165 3152 3166 3153 hs_ep->parent = hsotg; 3167 3154 hs_ep->ep.name = hs_ep->name; 3168 - hs_ep->ep.maxpacket = epnum ? 1024 : EP0_MPS_LIMIT; 3155 + usb_ep_set_maxpacket_limit(&hs_ep->ep, epnum ? 1024 : EP0_MPS_LIMIT); 3169 3156 hs_ep->ep.ops = &s3c_hsotg_ep_ops; 3170 3157 3171 3158 /* ··· 3546 3533 static int s3c_hsotg_probe(struct platform_device *pdev) 3547 3534 { 3548 3535 struct s3c_hsotg_plat *plat = dev_get_platdata(&pdev->dev); 3549 - struct usb_phy *phy; 3536 + struct phy *phy; 3537 + struct usb_phy *uphy; 3550 3538 struct device *dev = &pdev->dev; 3551 3539 struct s3c_hsotg_ep *eps; 3552 3540 struct s3c_hsotg *hsotg; ··· 3562 3548 return -ENOMEM; 3563 3549 } 3564 3550 3565 - phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 3551 + /* 3552 + * Attempt to find a generic PHY, then look for an old style 3553 + * USB PHY, finally fall back to pdata 3554 + */ 3555 + phy = devm_phy_get(&pdev->dev, "usb2-phy"); 3566 3556 if (IS_ERR(phy)) { 3567 - /* Fallback for pdata */ 3568 - plat = dev_get_platdata(&pdev->dev); 3569 - if (!plat) { 3570 - dev_err(&pdev->dev, "no platform data or transceiver defined\n"); 3571 - return -EPROBE_DEFER; 3572 - } else { 3557 + uphy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 3558 + if (IS_ERR(uphy)) { 3559 + /* Fallback for pdata */ 3560 + plat = dev_get_platdata(&pdev->dev); 3561 + if (!plat) { 3562 + dev_err(&pdev->dev, 3563 + "no platform data or transceiver defined\n"); 3564 + return -EPROBE_DEFER; 3565 + } 3573 3566 hsotg->plat = plat; 3574 - } 3575 - } else { 3567 + } else 3568 + hsotg->uphy = uphy; 3569 + } else 3576 3570 hsotg->phy = phy; 3577 - } 3578 3571 3579 3572 hsotg->dev = dev; 3580 3573 ··· 3647 3626 dev_err(hsotg->dev, "failed to enable supplies: %d\n", ret); 3648 3627 goto err_supplies; 3649 3628 } 3629 + 3630 + /* Set default UTMI width */ 3631 + hsotg->phyif = GUSBCFG_PHYIf16; 3632 + 3633 + /* 3634 + * If using the generic PHY framework, check if the PHY bus 3635 + * width is 8-bit and set the phyif appropriately. 3636 + */ 3637 + if (hsotg->phy && (phy_get_bus_width(phy) == 8)) 3638 + hsotg->phyif = GUSBCFG_PHYIf8; 3639 + 3640 + if (hsotg->phy) 3641 + phy_init(hsotg->phy); 3650 3642 3651 3643 /* usb phy enable */ 3652 3644 s3c_hsotg_phy_enable(hsotg); ··· 3754 3720 } 3755 3721 3756 3722 s3c_hsotg_phy_disable(hsotg); 3723 + if (hsotg->phy) 3724 + phy_exit(hsotg->phy); 3757 3725 clk_disable_unprepare(hsotg->clk); 3758 3726 3759 3727 return 0; ··· 3769 3733 #ifdef CONFIG_OF 3770 3734 static const struct of_device_id s3c_hsotg_of_ids[] = { 3771 3735 { .compatible = "samsung,s3c6400-hsotg", }, 3736 + { .compatible = "snps,dwc2", }, 3772 3737 { /* sentinel */ } 3773 3738 }; 3774 3739 MODULE_DEVICE_TABLE(of, s3c_hsotg_of_ids);
+1
drivers/usb/gadget/s3c-hsotg.h
··· 55 55 #define GUSBCFG_HNPCap (1 << 9) 56 56 #define GUSBCFG_SRPCap (1 << 8) 57 57 #define GUSBCFG_PHYIf16 (1 << 3) 58 + #define GUSBCFG_PHYIf8 (0 << 3) 58 59 #define GUSBCFG_TOutCal_MASK (0x7 << 0) 59 60 #define GUSBCFG_TOutCal_SHIFT (0) 60 61 #define GUSBCFG_TOutCal_LIMIT (0x7)
+1 -1
drivers/usb/gadget/s3c-hsudc.c
··· 999 999 1000 1000 hsep->dev = hsudc; 1001 1001 hsep->ep.name = hsep->name; 1002 - hsep->ep.maxpacket = epnum ? 512 : 64; 1002 + usb_ep_set_maxpacket_limit(&hsep->ep, epnum ? 512 : 64); 1003 1003 hsep->ep.ops = &s3c_hsudc_ep_ops; 1004 1004 hsep->fifo = hsudc->regs + S3C_BR(epnum); 1005 1005 hsep->ep.desc = NULL;
+1
drivers/usb/gadget/s3c2410_udc.c
··· 1629 1629 ep->ep.desc = NULL; 1630 1630 ep->halted = 0; 1631 1631 INIT_LIST_HEAD(&ep->queue); 1632 + usb_ep_set_maxpacket_limit(&ep->ep, &ep->ep.maxpacket); 1632 1633 } 1633 1634 } 1634 1635
+1 -1
drivers/usb/gadget/u_ether.c
··· 753 753 * gadget driver using this framework. The link layer addresses are 754 754 * set up using module parameters. 755 755 * 756 - * Returns negative errno, or zero on success 756 + * Returns an eth_dev pointer on success, or an ERR_PTR on failure. 757 757 */ 758 758 struct eth_dev *gether_setup_name(struct usb_gadget *g, 759 759 const char *dev_addr, const char *host_addr,
+1 -42
drivers/usb/gadget/u_ether.h
··· 106 106 * gadget driver using this framework. The link layer addresses are 107 107 * set up using module parameters. 108 108 * 109 - * Returns negative errno, or zero on success 109 + * Returns a eth_dev pointer on success, or an ERR_PTR on failure 110 110 */ 111 111 static inline struct eth_dev *gether_setup(struct usb_gadget *g, 112 112 const char *dev_addr, const char *host_addr, ··· 266 266 */ 267 267 return true; 268 268 } 269 - 270 - /* each configuration may bind one instance of an ethernet link */ 271 - int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 272 - struct eth_dev *dev); 273 - int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 274 - struct eth_dev *dev); 275 - 276 - #ifdef USB_ETH_RNDIS 277 - 278 - int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 279 - u32 vendorID, const char *manufacturer, struct eth_dev *dev); 280 - 281 - #else 282 - 283 - static inline int 284 - rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 285 - u32 vendorID, const char *manufacturer, struct eth_dev *dev) 286 - { 287 - return 0; 288 - } 289 - 290 - #endif 291 - 292 - /** 293 - * rndis_bind_config - add RNDIS network link to a configuration 294 - * @c: the configuration to support the network link 295 - * @ethaddr: a buffer in which the ethernet address of the host side 296 - * side of the link was recorded 297 - * Context: single threaded during gadget setup 298 - * 299 - * Returns zero on success, else negative errno. 300 - * 301 - * Caller must have called @gether_setup(). Caller is also responsible 302 - * for calling @gether_cleanup() before module unload. 303 - */ 304 - static inline int rndis_bind_config(struct usb_configuration *c, 305 - u8 ethaddr[ETH_ALEN], struct eth_dev *dev) 306 - { 307 - return rndis_bind_config_vendor(c, ethaddr, 0, NULL, dev); 308 - } 309 - 310 269 311 270 #endif /* __U_ETHER_H */
+32
drivers/usb/gadget/u_f.c
··· 1 + /* 2 + * u_f.c -- USB function utilities for Gadget stack 3 + * 4 + * Copyright (c) 2013 Samsung Electronics Co., Ltd. 5 + * http://www.samsung.com 6 + * 7 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 8 + * 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License version 2 as 11 + * published by the Free Software Foundation. 12 + */ 13 + 14 + #include <linux/usb/gadget.h> 15 + #include "u_f.h" 16 + 17 + struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len) 18 + { 19 + struct usb_request *req; 20 + 21 + req = usb_ep_alloc_request(ep, GFP_ATOMIC); 22 + if (req) { 23 + req->length = len ?: default_len; 24 + req->buf = kmalloc(req->length, GFP_ATOMIC); 25 + if (!req->buf) { 26 + usb_ep_free_request(ep, req); 27 + req = NULL; 28 + } 29 + } 30 + return req; 31 + } 32 + EXPORT_SYMBOL(alloc_ep_req);
+26
drivers/usb/gadget/u_f.h
··· 1 + /* 2 + * u_f.h 3 + * 4 + * Utility definitions for USB functions 5 + * 6 + * Copyright (c) 2013 Samsung Electronics Co., Ltd. 7 + * http://www.samsung.com 8 + * 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef __U_F_H__ 17 + #define __U_F_H__ 18 + 19 + struct usb_ep; 20 + struct usb_request; 21 + 22 + struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len); 23 + 24 + #endif /* __U_F_H__ */ 25 + 26 +
+267
drivers/usb/gadget/u_fs.h
··· 1 + /* 2 + * u_fs.h 3 + * 4 + * Utility definitions for the FunctionFS 5 + * 6 + * Copyright (c) 2013 Samsung Electronics Co., Ltd. 7 + * http://www.samsung.com 8 + * 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef U_FFS_H 17 + #define U_FFS_H 18 + 19 + #include <linux/usb/composite.h> 20 + #include <linux/list.h> 21 + #include <linux/mutex.h> 22 + 23 + #ifdef VERBOSE_DEBUG 24 + #ifndef pr_vdebug 25 + # define pr_vdebug pr_debug 26 + #endif /* pr_vdebug */ 27 + # define ffs_dump_mem(prefix, ptr, len) \ 28 + print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len) 29 + #else 30 + #ifndef pr_vdebug 31 + # define pr_vdebug(...) do { } while (0) 32 + #endif /* pr_vdebug */ 33 + # define ffs_dump_mem(prefix, ptr, len) do { } while (0) 34 + #endif /* VERBOSE_DEBUG */ 35 + 36 + #define ENTER() pr_vdebug("%s()\n", __func__) 37 + 38 + struct f_fs_opts; 39 + 40 + struct ffs_dev { 41 + const char *name; 42 + bool name_allocated; 43 + bool mounted; 44 + bool desc_ready; 45 + bool single; 46 + struct ffs_data *ffs_data; 47 + struct f_fs_opts *opts; 48 + struct list_head entry; 49 + 50 + int (*ffs_ready_callback)(struct ffs_data *ffs); 51 + void (*ffs_closed_callback)(struct ffs_data *ffs); 52 + void *(*ffs_acquire_dev_callback)(struct ffs_dev *dev); 53 + void (*ffs_release_dev_callback)(struct ffs_dev *dev); 54 + }; 55 + 56 + extern struct mutex ffs_lock; 57 + 58 + static inline void ffs_dev_lock(void) 59 + { 60 + mutex_lock(&ffs_lock); 61 + } 62 + 63 + static inline void ffs_dev_unlock(void) 64 + { 65 + mutex_unlock(&ffs_lock); 66 + } 67 + 68 + struct ffs_dev *ffs_alloc_dev(void); 69 + int ffs_name_dev(struct ffs_dev *dev, const char *name); 70 + int ffs_single_dev(struct ffs_dev *dev); 71 + void ffs_free_dev(struct ffs_dev *dev); 72 + 73 + struct ffs_epfile; 74 + struct ffs_function; 75 + 76 + enum ffs_state { 77 + /* 78 + * Waiting for descriptors and strings. 79 + * 80 + * In this state no open(2), read(2) or write(2) on epfiles 81 + * may succeed (which should not be the problem as there 82 + * should be no such files opened in the first place). 83 + */ 84 + FFS_READ_DESCRIPTORS, 85 + FFS_READ_STRINGS, 86 + 87 + /* 88 + * We've got descriptors and strings. We are or have called 89 + * functionfs_ready_callback(). functionfs_bind() may have 90 + * been called but we don't know. 91 + * 92 + * This is the only state in which operations on epfiles may 93 + * succeed. 94 + */ 95 + FFS_ACTIVE, 96 + 97 + /* 98 + * All endpoints have been closed. This state is also set if 99 + * we encounter an unrecoverable error. The only 100 + * unrecoverable error is situation when after reading strings 101 + * from user space we fail to initialise epfiles or 102 + * functionfs_ready_callback() returns with error (<0). 103 + * 104 + * In this state no open(2), read(2) or write(2) (both on ep0 105 + * as well as epfile) may succeed (at this point epfiles are 106 + * unlinked and all closed so this is not a problem; ep0 is 107 + * also closed but ep0 file exists and so open(2) on ep0 must 108 + * fail). 109 + */ 110 + FFS_CLOSING 111 + }; 112 + 113 + enum ffs_setup_state { 114 + /* There is no setup request pending. */ 115 + FFS_NO_SETUP, 116 + /* 117 + * User has read events and there was a setup request event 118 + * there. The next read/write on ep0 will handle the 119 + * request. 120 + */ 121 + FFS_SETUP_PENDING, 122 + /* 123 + * There was event pending but before user space handled it 124 + * some other event was introduced which canceled existing 125 + * setup. If this state is set read/write on ep0 return 126 + * -EIDRM. This state is only set when adding event. 127 + */ 128 + FFS_SETUP_CANCELED 129 + }; 130 + 131 + struct ffs_data { 132 + struct usb_gadget *gadget; 133 + 134 + /* 135 + * Protect access read/write operations, only one read/write 136 + * at a time. As a consequence protects ep0req and company. 137 + * While setup request is being processed (queued) this is 138 + * held. 139 + */ 140 + struct mutex mutex; 141 + 142 + /* 143 + * Protect access to endpoint related structures (basically 144 + * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for 145 + * endpoint zero. 146 + */ 147 + spinlock_t eps_lock; 148 + 149 + /* 150 + * XXX REVISIT do we need our own request? Since we are not 151 + * handling setup requests immediately user space may be so 152 + * slow that another setup will be sent to the gadget but this 153 + * time not to us but another function and then there could be 154 + * a race. Is that the case? Or maybe we can use cdev->req 155 + * after all, maybe we just need some spinlock for that? 156 + */ 157 + struct usb_request *ep0req; /* P: mutex */ 158 + struct completion ep0req_completion; /* P: mutex */ 159 + int ep0req_status; /* P: mutex */ 160 + 161 + /* reference counter */ 162 + atomic_t ref; 163 + /* how many files are opened (EP0 and others) */ 164 + atomic_t opened; 165 + 166 + /* EP0 state */ 167 + enum ffs_state state; 168 + 169 + /* 170 + * Possible transitions: 171 + * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock 172 + * happens only in ep0 read which is P: mutex 173 + * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock 174 + * happens only in ep0 i/o which is P: mutex 175 + * + FFS_SETUP_PENDING -> FFS_SETUP_CANCELED -- P: ev.waitq.lock 176 + * + FFS_SETUP_CANCELED -> FFS_NO_SETUP -- cmpxchg 177 + */ 178 + enum ffs_setup_state setup_state; 179 + 180 + #define FFS_SETUP_STATE(ffs) \ 181 + ((enum ffs_setup_state)cmpxchg(&(ffs)->setup_state, \ 182 + FFS_SETUP_CANCELED, FFS_NO_SETUP)) 183 + 184 + /* Events & such. */ 185 + struct { 186 + u8 types[4]; 187 + unsigned short count; 188 + /* XXX REVISIT need to update it in some places, or do we? */ 189 + unsigned short can_stall; 190 + struct usb_ctrlrequest setup; 191 + 192 + wait_queue_head_t waitq; 193 + } ev; /* the whole structure, P: ev.waitq.lock */ 194 + 195 + /* Flags */ 196 + unsigned long flags; 197 + #define FFS_FL_CALL_CLOSED_CALLBACK 0 198 + #define FFS_FL_BOUND 1 199 + 200 + /* Active function */ 201 + struct ffs_function *func; 202 + 203 + /* 204 + * Device name, write once when file system is mounted. 205 + * Intended for user to read if she wants. 206 + */ 207 + const char *dev_name; 208 + /* Private data for our user (ie. gadget). Managed by user. */ 209 + void *private_data; 210 + 211 + /* filled by __ffs_data_got_descs() */ 212 + /* 213 + * Real descriptors are 16 bytes after raw_descs (so you need 214 + * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the 215 + * first full speed descriptor). raw_descs_length and 216 + * raw_fs_descs_length do not have those 16 bytes added. 217 + */ 218 + const void *raw_descs; 219 + unsigned raw_descs_length; 220 + unsigned raw_fs_descs_length; 221 + unsigned fs_descs_count; 222 + unsigned hs_descs_count; 223 + 224 + unsigned short strings_count; 225 + unsigned short interfaces_count; 226 + unsigned short eps_count; 227 + unsigned short _pad1; 228 + 229 + /* filled by __ffs_data_got_strings() */ 230 + /* ids in stringtabs are set in functionfs_bind() */ 231 + const void *raw_strings; 232 + struct usb_gadget_strings **stringtabs; 233 + 234 + /* 235 + * File system's super block, write once when file system is 236 + * mounted. 237 + */ 238 + struct super_block *sb; 239 + 240 + /* File permissions, written once when fs is mounted */ 241 + struct ffs_file_perms { 242 + umode_t mode; 243 + kuid_t uid; 244 + kgid_t gid; 245 + } file_perms; 246 + 247 + /* 248 + * The endpoint files, filled by ffs_epfiles_create(), 249 + * destroyed by ffs_epfiles_destroy(). 250 + */ 251 + struct ffs_epfile *epfiles; 252 + }; 253 + 254 + 255 + struct f_fs_opts { 256 + struct usb_function_instance func_inst; 257 + struct ffs_dev *dev; 258 + unsigned refcnt; 259 + bool no_configfs; 260 + }; 261 + 262 + static inline struct f_fs_opts *to_f_fs_opts(struct usb_function_instance *fi) 263 + { 264 + return container_of(fi, struct f_fs_opts, func_inst); 265 + } 266 + 267 + #endif /* U_FFS_H */
+2
drivers/usb/gadget/u_rndis.h
··· 36 36 int refcnt; 37 37 }; 38 38 39 + int rndis_init(void); 40 + void rndis_exit(void); 39 41 void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net); 40 42 41 43 #endif /* U_RNDIS_H */
+4 -4
drivers/usb/gadget/zero.c
··· 64 64 module_param(loopdefault, bool, S_IRUGO|S_IWUSR); 65 65 66 66 static struct usb_zero_options gzero_options = { 67 - .isoc_interval = 4, 68 - .isoc_maxpacket = 1024, 69 - .bulk_buflen = 4096, 70 - .qlen = 32, 67 + .isoc_interval = GZERO_ISOC_INTERVAL, 68 + .isoc_maxpacket = GZERO_ISOC_MAXPACKET, 69 + .bulk_buflen = GZERO_BULK_BUFLEN, 70 + .qlen = GZERO_QLEN, 71 71 }; 72 72 73 73 /*-------------------------------------------------------------------------*/
+11 -5
drivers/usb/musb/Kconfig
··· 6 6 # (M)HDRC = (Multipoint) Highspeed Dual-Role Controller 7 7 config USB_MUSB_HDRC 8 8 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' 9 - depends on USB_GADGET 9 + depends on (USB || USB_GADGET) 10 10 help 11 11 Say Y here if your system has a dual role high speed USB 12 12 controller based on the Mentor Graphics silicon IP. Then ··· 35 35 36 36 config USB_MUSB_HOST 37 37 bool "Host only mode" 38 - depends on USB 38 + depends on USB=y || USB=USB_MUSB_HDRC 39 39 help 40 40 Select this when you want to use MUSB in host mode only, 41 41 thereby the gadget feature will be regressed. 42 42 43 43 config USB_MUSB_GADGET 44 44 bool "Gadget only mode" 45 - depends on USB_GADGET 45 + depends on USB_GADGET=y || USB_GADGET=USB_MUSB_HDRC 46 46 help 47 47 Select this when you want to use MUSB in gadget mode only, 48 48 thereby the host feature will be regressed. 49 49 50 50 config USB_MUSB_DUAL_ROLE 51 51 bool "Dual Role mode" 52 - depends on (USB && USB_GADGET) 52 + depends on ((USB=y || USB=USB_MUSB_HDRC) && (USB_GADGET=y || USB_GADGET=USB_MUSB_HDRC)) 53 53 help 54 54 This is the default mode of working of MUSB controller where 55 55 both host and gadget features are enabled. ··· 93 93 config USB_MUSB_UX500 94 94 tristate "Ux500 platforms" 95 95 96 + config USB_MUSB_JZ4740 97 + tristate "JZ4740" 98 + depends on MACH_JZ4740 || COMPILE_TEST 99 + depends on USB_MUSB_GADGET 100 + depends on USB_OTG_BLACKLIST_HUB 101 + 96 102 endchoice 97 103 98 104 config USB_MUSB_AM335X_CHILD ··· 106 100 107 101 choice 108 102 prompt 'MUSB DMA mode' 109 - default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM 103 + default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM || USB_MUSB_JZ4740 110 104 default USB_UX500_DMA if USB_MUSB_UX500 111 105 default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN 112 106 default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI
+1
drivers/usb/musb/Makefile
··· 19 19 obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o 20 20 obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o 21 21 obj-$(CONFIG_USB_MUSB_UX500) += ux500.o 22 + obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o 22 23 23 24 24 25 obj-$(CONFIG_USB_MUSB_AM335X_CHILD) += musb_am335x.o
+201
drivers/usb/musb/jz4740.c
··· 1 + /* 2 + * Ingenic JZ4740 "glue layer" 3 + * 4 + * Copyright (C) 2013, Apelete Seketeli <apelete@seketeli.net> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * You should have received a copy of the GNU General Public License along 12 + * with this program; if not, write to the Free Software Foundation, Inc., 13 + * 675 Mass Ave, Cambridge, MA 02139, USA. 14 + */ 15 + 16 + #include <linux/clk.h> 17 + #include <linux/dma-mapping.h> 18 + #include <linux/errno.h> 19 + #include <linux/kernel.h> 20 + #include <linux/module.h> 21 + #include <linux/platform_device.h> 22 + 23 + #include "musb_core.h" 24 + 25 + struct jz4740_glue { 26 + struct device *dev; 27 + struct platform_device *musb; 28 + struct clk *clk; 29 + }; 30 + 31 + static irqreturn_t jz4740_musb_interrupt(int irq, void *__hci) 32 + { 33 + unsigned long flags; 34 + irqreturn_t retval = IRQ_NONE; 35 + struct musb *musb = __hci; 36 + 37 + spin_lock_irqsave(&musb->lock, flags); 38 + 39 + musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); 40 + musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); 41 + musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); 42 + 43 + /* 44 + * The controller is gadget only, the state of the host mode IRQ bits is 45 + * undefined. Mask them to make sure that the musb driver core will 46 + * never see them set 47 + */ 48 + musb->int_usb &= MUSB_INTR_SUSPEND | MUSB_INTR_RESUME | 49 + MUSB_INTR_RESET | MUSB_INTR_SOF; 50 + 51 + if (musb->int_usb || musb->int_tx || musb->int_rx) 52 + retval = musb_interrupt(musb); 53 + 54 + spin_unlock_irqrestore(&musb->lock, flags); 55 + 56 + return retval; 57 + } 58 + 59 + static struct musb_fifo_cfg jz4740_musb_fifo_cfg[] = { 60 + { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 61 + { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 62 + { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 64, }, 63 + }; 64 + 65 + static struct musb_hdrc_config jz4740_musb_config = { 66 + /* Silicon does not implement USB OTG. */ 67 + .multipoint = 0, 68 + /* Max EPs scanned, driver will decide which EP can be used. */ 69 + .num_eps = 4, 70 + /* RAMbits needed to configure EPs from table */ 71 + .ram_bits = 9, 72 + .fifo_cfg = jz4740_musb_fifo_cfg, 73 + .fifo_cfg_size = ARRAY_SIZE(jz4740_musb_fifo_cfg), 74 + }; 75 + 76 + static struct musb_hdrc_platform_data jz4740_musb_platform_data = { 77 + .mode = MUSB_PERIPHERAL, 78 + .config = &jz4740_musb_config, 79 + }; 80 + 81 + static int jz4740_musb_init(struct musb *musb) 82 + { 83 + musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 84 + if (!musb->xceiv) { 85 + pr_err("HS UDC: no transceiver configured\n"); 86 + return -ENODEV; 87 + } 88 + 89 + /* Silicon does not implement ConfigData register. 90 + * Set dyn_fifo to avoid reading EP config from hardware. 91 + */ 92 + musb->dyn_fifo = true; 93 + 94 + musb->isr = jz4740_musb_interrupt; 95 + 96 + return 0; 97 + } 98 + 99 + static int jz4740_musb_exit(struct musb *musb) 100 + { 101 + usb_put_phy(musb->xceiv); 102 + 103 + return 0; 104 + } 105 + 106 + static const struct musb_platform_ops jz4740_musb_ops = { 107 + .init = jz4740_musb_init, 108 + .exit = jz4740_musb_exit, 109 + }; 110 + 111 + static int jz4740_probe(struct platform_device *pdev) 112 + { 113 + struct musb_hdrc_platform_data *pdata = &jz4740_musb_platform_data; 114 + struct platform_device *musb; 115 + struct jz4740_glue *glue; 116 + struct clk *clk; 117 + int ret; 118 + 119 + glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); 120 + if (!glue) 121 + return -ENOMEM; 122 + 123 + musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); 124 + if (!musb) { 125 + dev_err(&pdev->dev, "failed to allocate musb device\n"); 126 + return -ENOMEM; 127 + } 128 + 129 + clk = devm_clk_get(&pdev->dev, "udc"); 130 + if (IS_ERR(clk)) { 131 + dev_err(&pdev->dev, "failed to get clock\n"); 132 + ret = PTR_ERR(clk); 133 + goto err_platform_device_put; 134 + } 135 + 136 + ret = clk_prepare_enable(clk); 137 + if (ret) { 138 + dev_err(&pdev->dev, "failed to enable clock\n"); 139 + goto err_platform_device_put; 140 + } 141 + 142 + musb->dev.parent = &pdev->dev; 143 + 144 + glue->dev = &pdev->dev; 145 + glue->musb = musb; 146 + glue->clk = clk; 147 + 148 + pdata->platform_ops = &jz4740_musb_ops; 149 + 150 + platform_set_drvdata(pdev, glue); 151 + 152 + ret = platform_device_add_resources(musb, pdev->resource, 153 + pdev->num_resources); 154 + if (ret) { 155 + dev_err(&pdev->dev, "failed to add resources\n"); 156 + goto err_clk_disable; 157 + } 158 + 159 + ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 160 + if (ret) { 161 + dev_err(&pdev->dev, "failed to add platform_data\n"); 162 + goto err_clk_disable; 163 + } 164 + 165 + ret = platform_device_add(musb); 166 + if (ret) { 167 + dev_err(&pdev->dev, "failed to register musb device\n"); 168 + goto err_clk_disable; 169 + } 170 + 171 + return 0; 172 + 173 + err_clk_disable: 174 + clk_disable_unprepare(clk); 175 + err_platform_device_put: 176 + platform_device_put(musb); 177 + return ret; 178 + } 179 + 180 + static int jz4740_remove(struct platform_device *pdev) 181 + { 182 + struct jz4740_glue *glue = platform_get_drvdata(pdev); 183 + 184 + platform_device_unregister(glue->musb); 185 + clk_disable_unprepare(glue->clk); 186 + 187 + return 0; 188 + } 189 + 190 + static struct platform_driver jz4740_driver = { 191 + .probe = jz4740_probe, 192 + .remove = jz4740_remove, 193 + .driver = { 194 + .name = "musb-jz4740", 195 + }, 196 + }; 197 + 198 + MODULE_DESCRIPTION("JZ4740 MUSB Glue Layer"); 199 + MODULE_AUTHOR("Apelete Seketeli <apelete@seketeli.net>"); 200 + MODULE_LICENSE("GPL v2"); 201 + module_platform_driver(jz4740_driver);
+47 -20
drivers/usb/musb/musb_core.c
··· 478 478 musb->port1_status |= 479 479 (USB_PORT_STAT_C_SUSPEND << 16) 480 480 | MUSB_PORT_STAT_RESUME; 481 - musb->rh_timer = jiffies 482 - + msecs_to_jiffies(20); 481 + schedule_delayed_work( 482 + &musb->finish_resume_work, 20); 483 483 484 484 musb->xceiv->state = OTG_STATE_A_HOST; 485 485 musb->is_active = 1; ··· 1813 1813 musb_host_free(musb); 1814 1814 } 1815 1815 1816 + static void musb_deassert_reset(struct work_struct *work) 1817 + { 1818 + struct musb *musb; 1819 + unsigned long flags; 1820 + 1821 + musb = container_of(work, struct musb, deassert_reset_work.work); 1822 + 1823 + spin_lock_irqsave(&musb->lock, flags); 1824 + 1825 + if (musb->port1_status & USB_PORT_STAT_RESET) 1826 + musb_port_reset(musb, false); 1827 + 1828 + spin_unlock_irqrestore(&musb->lock, flags); 1829 + } 1830 + 1816 1831 /* 1817 1832 * Perform generic per-controller initialization. 1818 1833 * ··· 1912 1897 1913 1898 /* Init IRQ workqueue before request_irq */ 1914 1899 INIT_WORK(&musb->irq_work, musb_irq_work); 1900 + INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); 1901 + INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); 1915 1902 1916 1903 /* setup musb parts of the core (especially endpoints) */ 1917 1904 status = musb_core_init(plat->config->multipoint ··· 1957 1940 switch (musb->port_mode) { 1958 1941 case MUSB_PORT_MODE_HOST: 1959 1942 status = musb_host_setup(musb, plat->power); 1943 + if (status < 0) 1944 + goto fail3; 1945 + status = musb_platform_set_mode(musb, MUSB_HOST); 1960 1946 break; 1961 1947 case MUSB_PORT_MODE_GADGET: 1962 1948 status = musb_gadget_setup(musb); 1949 + if (status < 0) 1950 + goto fail3; 1951 + status = musb_platform_set_mode(musb, MUSB_PERIPHERAL); 1963 1952 break; 1964 1953 case MUSB_PORT_MODE_DUAL_ROLE: 1965 1954 status = musb_host_setup(musb, plat->power); 1966 1955 if (status < 0) 1967 1956 goto fail3; 1968 1957 status = musb_gadget_setup(musb); 1969 - if (status) 1958 + if (status) { 1970 1959 musb_host_cleanup(musb); 1960 + goto fail3; 1961 + } 1962 + status = musb_platform_set_mode(musb, MUSB_OTG); 1971 1963 break; 1972 1964 default: 1973 1965 dev_err(dev, "unsupported port mode %d\n", musb->port_mode); ··· 2007 1981 2008 1982 fail3: 2009 1983 cancel_work_sync(&musb->irq_work); 1984 + cancel_delayed_work_sync(&musb->finish_resume_work); 1985 + cancel_delayed_work_sync(&musb->deassert_reset_work); 2010 1986 if (musb->dma_controller) 2011 1987 dma_controller_destroy(musb->dma_controller); 2012 1988 fail2_5: ··· 2072 2044 dma_controller_destroy(musb->dma_controller); 2073 2045 2074 2046 cancel_work_sync(&musb->irq_work); 2047 + cancel_delayed_work_sync(&musb->finish_resume_work); 2048 + cancel_delayed_work_sync(&musb->deassert_reset_work); 2075 2049 musb_free(musb); 2076 2050 device_init_wakeup(dev, 0); 2077 2051 return 0; ··· 2246 2216 */ 2247 2217 } 2248 2218 2219 + musb_save_context(musb); 2220 + 2249 2221 spin_unlock_irqrestore(&musb->lock, flags); 2250 2222 return 0; 2251 2223 } 2252 2224 2253 2225 static int musb_resume_noirq(struct device *dev) 2254 2226 { 2255 - /* for static cmos like DaVinci, register values were preserved 2227 + struct musb *musb = dev_to_musb(dev); 2228 + 2229 + /* 2230 + * For static cmos like DaVinci, register values were preserved 2256 2231 * unless for some reason the whole soc powered down or the USB 2257 2232 * module got reset through the PSC (vs just being disabled). 2233 + * 2234 + * For the DSPS glue layer though, a full register restore has to 2235 + * be done. As it shouldn't harm other platforms, we do it 2236 + * unconditionally. 2258 2237 */ 2238 + 2239 + musb_restore_context(musb); 2240 + 2259 2241 return 0; 2260 2242 } 2261 2243 ··· 2325 2283 .shutdown = musb_shutdown, 2326 2284 }; 2327 2285 2328 - /*-------------------------------------------------------------------------*/ 2329 - 2330 - static int __init musb_init(void) 2331 - { 2332 - if (usb_disabled()) 2333 - return 0; 2334 - 2335 - return platform_driver_register(&musb_driver); 2336 - } 2337 - module_init(musb_init); 2338 - 2339 - static void __exit musb_cleanup(void) 2340 - { 2341 - platform_driver_unregister(&musb_driver); 2342 - } 2343 - module_exit(musb_cleanup); 2286 + module_platform_driver(musb_driver);
+3
drivers/usb/musb/musb_core.h
··· 47 47 #include <linux/usb/otg.h> 48 48 #include <linux/usb/musb.h> 49 49 #include <linux/phy/phy.h> 50 + #include <linux/workqueue.h> 50 51 51 52 struct musb; 52 53 struct musb_hw_ep; ··· 296 295 297 296 irqreturn_t (*isr)(int, void *); 298 297 struct work_struct irq_work; 298 + struct delayed_work deassert_reset_work; 299 + struct delayed_work finish_resume_work; 299 300 u16 hwvers; 300 301 301 302 u16 intrrxe;
+115 -2
drivers/usb/musb/musb_dsps.c
··· 83 83 u16 coreintr_status; 84 84 u16 phy_utmi; 85 85 u16 mode; 86 + u16 tx_mode; 87 + u16 rx_mode; 86 88 87 89 /* bit positions for control */ 88 90 unsigned reset:5; ··· 108 106 109 107 /* bit positions for mode */ 110 108 unsigned iddig:5; 109 + unsigned iddig_mux:5; 111 110 /* miscellaneous stuff */ 112 111 u8 poll_seconds; 112 + }; 113 + 114 + /* 115 + * register shadow for suspend 116 + */ 117 + struct dsps_context { 118 + u32 control; 119 + u32 epintr; 120 + u32 coreintr; 121 + u32 phy_utmi; 122 + u32 mode; 123 + u32 tx_mode; 124 + u32 rx_mode; 113 125 }; 114 126 115 127 /** ··· 135 119 const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */ 136 120 struct timer_list timer; /* otg_workaround timer */ 137 121 unsigned long last_timer; /* last timer data for each instance */ 122 + 123 + struct dsps_context context; 138 124 }; 139 125 140 126 static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) ··· 359 341 if (musb->int_tx || musb->int_rx || musb->int_usb) 360 342 ret |= musb_interrupt(musb); 361 343 362 - /* Poll for ID change */ 363 - if (musb->xceiv->state == OTG_STATE_B_IDLE) 344 + /* Poll for ID change in OTG port mode */ 345 + if (musb->xceiv->state == OTG_STATE_B_IDLE && 346 + musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) 364 347 mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); 365 348 out: 366 349 spin_unlock_irqrestore(&musb->lock, flags); ··· 425 406 return 0; 426 407 } 427 408 409 + static int dsps_musb_set_mode(struct musb *musb, u8 mode) 410 + { 411 + struct device *dev = musb->controller; 412 + struct dsps_glue *glue = dev_get_drvdata(dev->parent); 413 + const struct dsps_musb_wrapper *wrp = glue->wrp; 414 + void __iomem *ctrl_base = musb->ctrl_base; 415 + void __iomem *base = musb->mregs; 416 + u32 reg; 417 + 418 + reg = dsps_readl(base, wrp->mode); 419 + 420 + switch (mode) { 421 + case MUSB_HOST: 422 + reg &= ~(1 << wrp->iddig); 423 + 424 + /* 425 + * if we're setting mode to host-only or device-only, we're 426 + * going to ignore whatever the PHY sends us and just force 427 + * ID pin status by SW 428 + */ 429 + reg |= (1 << wrp->iddig_mux); 430 + 431 + dsps_writel(base, wrp->mode, reg); 432 + dsps_writel(ctrl_base, wrp->phy_utmi, 0x02); 433 + break; 434 + case MUSB_PERIPHERAL: 435 + reg |= (1 << wrp->iddig); 436 + 437 + /* 438 + * if we're setting mode to host-only or device-only, we're 439 + * going to ignore whatever the PHY sends us and just force 440 + * ID pin status by SW 441 + */ 442 + reg |= (1 << wrp->iddig_mux); 443 + 444 + dsps_writel(base, wrp->mode, reg); 445 + break; 446 + case MUSB_OTG: 447 + dsps_writel(base, wrp->phy_utmi, 0x02); 448 + break; 449 + default: 450 + dev_err(glue->dev, "unsupported mode %d\n", mode); 451 + return -EINVAL; 452 + } 453 + 454 + return 0; 455 + } 456 + 428 457 static struct musb_platform_ops dsps_ops = { 429 458 .init = dsps_musb_init, 430 459 .exit = dsps_musb_exit, ··· 481 414 .disable = dsps_musb_disable, 482 415 483 416 .try_idle = dsps_musb_try_idle, 417 + .set_mode = dsps_musb_set_mode, 484 418 }; 485 419 486 420 static u64 musb_dmamask = DMA_BIT_MASK(32); ··· 575 507 576 508 config->num_eps = get_int_prop(dn, "mentor,num-eps"); 577 509 config->ram_bits = get_int_prop(dn, "mentor,ram-bits"); 510 + config->host_port_deassert_reset_at_resume = 1; 578 511 pdata.mode = get_musb_port_mode(dev); 579 512 /* DT keeps this entry in mA, musb expects it as per USB spec */ 580 513 pdata.power = get_int_prop(dn, "mentor,power") / 2; ··· 674 605 .coreintr_status = 0x34, 675 606 .phy_utmi = 0xe0, 676 607 .mode = 0xe8, 608 + .tx_mode = 0x70, 609 + .rx_mode = 0x74, 677 610 .reset = 0, 678 611 .otg_disable = 21, 679 612 .iddig = 8, 613 + .iddig_mux = 7, 680 614 .usb_shift = 0, 681 615 .usb_mask = 0x1ff, 682 616 .usb_bitmap = (0x1ff << 0), ··· 700 628 }; 701 629 MODULE_DEVICE_TABLE(of, musb_dsps_of_match); 702 630 631 + #ifdef CONFIG_PM 632 + static int dsps_suspend(struct device *dev) 633 + { 634 + struct dsps_glue *glue = dev_get_drvdata(dev); 635 + const struct dsps_musb_wrapper *wrp = glue->wrp; 636 + struct musb *musb = platform_get_drvdata(glue->musb); 637 + void __iomem *mbase = musb->ctrl_base; 638 + 639 + glue->context.control = dsps_readl(mbase, wrp->control); 640 + glue->context.epintr = dsps_readl(mbase, wrp->epintr_set); 641 + glue->context.coreintr = dsps_readl(mbase, wrp->coreintr_set); 642 + glue->context.phy_utmi = dsps_readl(mbase, wrp->phy_utmi); 643 + glue->context.mode = dsps_readl(mbase, wrp->mode); 644 + glue->context.tx_mode = dsps_readl(mbase, wrp->tx_mode); 645 + glue->context.rx_mode = dsps_readl(mbase, wrp->rx_mode); 646 + 647 + return 0; 648 + } 649 + 650 + static int dsps_resume(struct device *dev) 651 + { 652 + struct dsps_glue *glue = dev_get_drvdata(dev); 653 + const struct dsps_musb_wrapper *wrp = glue->wrp; 654 + struct musb *musb = platform_get_drvdata(glue->musb); 655 + void __iomem *mbase = musb->ctrl_base; 656 + 657 + dsps_writel(mbase, wrp->control, glue->context.control); 658 + dsps_writel(mbase, wrp->epintr_set, glue->context.epintr); 659 + dsps_writel(mbase, wrp->coreintr_set, glue->context.coreintr); 660 + dsps_writel(mbase, wrp->phy_utmi, glue->context.phy_utmi); 661 + dsps_writel(mbase, wrp->mode, glue->context.mode); 662 + dsps_writel(mbase, wrp->tx_mode, glue->context.tx_mode); 663 + dsps_writel(mbase, wrp->rx_mode, glue->context.rx_mode); 664 + 665 + return 0; 666 + } 667 + #endif 668 + 669 + static SIMPLE_DEV_PM_OPS(dsps_pm_ops, dsps_suspend, dsps_resume); 670 + 703 671 static struct platform_driver dsps_usbss_driver = { 704 672 .probe = dsps_probe, 705 673 .remove = dsps_remove, 706 674 .driver = { 707 675 .name = "musb-dsps", 676 + .pm = &dsps_pm_ops, 708 677 .of_match_table = musb_dsps_of_match, 709 678 }, 710 679 };
+12 -4
drivers/usb/musb/musb_gadget.c
··· 1727 1727 ep->end_point.name = ep->name; 1728 1728 INIT_LIST_HEAD(&ep->end_point.ep_list); 1729 1729 if (!epnum) { 1730 - ep->end_point.maxpacket = 64; 1730 + usb_ep_set_maxpacket_limit(&ep->end_point, 64); 1731 1731 ep->end_point.ops = &musb_g_ep0_ops; 1732 1732 musb->g.ep0 = &ep->end_point; 1733 1733 } else { 1734 1734 if (is_in) 1735 - ep->end_point.maxpacket = hw_ep->max_packet_sz_tx; 1735 + usb_ep_set_maxpacket_limit(&ep->end_point, hw_ep->max_packet_sz_tx); 1736 1736 else 1737 - ep->end_point.maxpacket = hw_ep->max_packet_sz_rx; 1737 + usb_ep_set_maxpacket_limit(&ep->end_point, hw_ep->max_packet_sz_rx); 1738 1738 ep->end_point.ops = &musb_ep_ops; 1739 1739 list_add_tail(&ep->end_point.ep_list, &musb->g.ep_list); 1740 1740 } ··· 2119 2119 /* Normal reset, as B-Device; 2120 2120 * or else after HNP, as A-Device 2121 2121 */ 2122 - if (devctl & MUSB_DEVCTL_BDEVICE) { 2122 + if (!musb->g.is_otg) { 2123 + /* USB device controllers that are not OTG compatible 2124 + * may not have DEVCTL register in silicon. 2125 + * In that case, do not rely on devctl for setting 2126 + * peripheral mode. 2127 + */ 2128 + musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 2129 + musb->g.is_a_peripheral = 0; 2130 + } else if (devctl & MUSB_DEVCTL_BDEVICE) { 2123 2131 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 2124 2132 musb->g.is_a_peripheral = 0; 2125 2133 } else {
+8 -1
drivers/usb/musb/musb_host.c
··· 2433 2433 struct musb *musb = hcd_to_musb(hcd); 2434 2434 u8 devctl; 2435 2435 2436 + musb_port_suspend(musb, true); 2437 + 2436 2438 if (!is_host_active(musb)) 2437 2439 return 0; 2438 2440 ··· 2464 2462 2465 2463 static int musb_bus_resume(struct usb_hcd *hcd) 2466 2464 { 2467 - /* resuming child port does the work */ 2465 + struct musb *musb = hcd_to_musb(hcd); 2466 + 2467 + if (musb->config && 2468 + musb->config->host_port_deassert_reset_at_resume) 2469 + musb_port_reset(musb, false); 2470 + 2468 2471 return 0; 2469 2472 } 2470 2473
+6
drivers/usb/musb/musb_host.h
··· 92 92 extern void musb_root_disconnect(struct musb *musb); 93 93 extern void musb_host_resume_root_hub(struct musb *musb); 94 94 extern void musb_host_poke_root_hub(struct musb *musb); 95 + extern void musb_port_suspend(struct musb *musb, bool do_suspend); 96 + extern void musb_port_reset(struct musb *musb, bool do_reset); 97 + extern void musb_host_finish_resume(struct work_struct *work); 95 98 #else 96 99 static inline struct musb *hcd_to_musb(struct usb_hcd *hcd) 97 100 { ··· 124 121 static inline void musb_host_resume_root_hub(struct musb *musb) {} 125 122 static inline void musb_host_poll_rh_status(struct musb *musb) {} 126 123 static inline void musb_host_poke_root_hub(struct musb *musb) {} 124 + static inline void musb_port_suspend(struct musb *musb, bool do_suspend) {} 125 + static inline void musb_port_reset(struct musb *musb, bool do_reset) {} 126 + static inline void musb_host_finish_resume(struct work_struct *work) {} 127 127 #endif 128 128 129 129 struct usb_hcd;
+35 -34
drivers/usb/musb/musb_virthub.c
··· 44 44 45 45 #include "musb_core.h" 46 46 47 - static void musb_port_suspend(struct musb *musb, bool do_suspend) 47 + void musb_host_finish_resume(struct work_struct *work) 48 + { 49 + struct musb *musb; 50 + unsigned long flags; 51 + u8 power; 52 + 53 + musb = container_of(work, struct musb, finish_resume_work.work); 54 + 55 + spin_lock_irqsave(&musb->lock, flags); 56 + 57 + power = musb_readb(musb->mregs, MUSB_POWER); 58 + power &= ~MUSB_POWER_RESUME; 59 + dev_dbg(musb->controller, "root port resume stopped, power %02x\n", 60 + power); 61 + musb_writeb(musb->mregs, MUSB_POWER, power); 62 + 63 + /* 64 + * ISSUE: DaVinci (RTL 1.300) disconnects after 65 + * resume of high speed peripherals (but not full 66 + * speed ones). 67 + */ 68 + musb->is_active = 1; 69 + musb->port1_status &= ~(USB_PORT_STAT_SUSPEND | MUSB_PORT_STAT_RESUME); 70 + musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; 71 + usb_hcd_poll_rh_status(musb->hcd); 72 + /* NOTE: it might really be A_WAIT_BCON ... */ 73 + musb->xceiv->state = OTG_STATE_A_HOST; 74 + 75 + spin_unlock_irqrestore(&musb->lock, flags); 76 + } 77 + 78 + void musb_port_suspend(struct musb *musb, bool do_suspend) 48 79 { 49 80 struct usb_otg *otg = musb->xceiv->otg; 50 81 u8 power; ··· 136 105 137 106 /* later, GetPortStatus will stop RESUME signaling */ 138 107 musb->port1_status |= MUSB_PORT_STAT_RESUME; 139 - musb->rh_timer = jiffies + msecs_to_jiffies(20); 108 + schedule_delayed_work(&musb->finish_resume_work, 20); 140 109 } 141 110 } 142 111 143 - static void musb_port_reset(struct musb *musb, bool do_reset) 112 + void musb_port_reset(struct musb *musb, bool do_reset) 144 113 { 145 114 u8 power; 146 115 void __iomem *mbase = musb->mregs; ··· 181 150 182 151 musb->port1_status |= USB_PORT_STAT_RESET; 183 152 musb->port1_status &= ~USB_PORT_STAT_ENABLE; 184 - musb->rh_timer = jiffies + msecs_to_jiffies(50); 153 + schedule_delayed_work(&musb->deassert_reset_work, 50); 185 154 } else { 186 155 dev_dbg(musb->controller, "root port reset stopped\n"); 187 156 musb_writeb(mbase, MUSB_POWER, ··· 355 324 case GetPortStatus: 356 325 if (wIndex != 1) 357 326 goto error; 358 - 359 - /* finish RESET signaling? */ 360 - if ((musb->port1_status & USB_PORT_STAT_RESET) 361 - && time_after_eq(jiffies, musb->rh_timer)) 362 - musb_port_reset(musb, false); 363 - 364 - /* finish RESUME signaling? */ 365 - if ((musb->port1_status & MUSB_PORT_STAT_RESUME) 366 - && time_after_eq(jiffies, musb->rh_timer)) { 367 - u8 power; 368 - 369 - power = musb_readb(musb->mregs, MUSB_POWER); 370 - power &= ~MUSB_POWER_RESUME; 371 - dev_dbg(musb->controller, "root port resume stopped, power %02x\n", 372 - power); 373 - musb_writeb(musb->mregs, MUSB_POWER, power); 374 - 375 - /* ISSUE: DaVinci (RTL 1.300) disconnects after 376 - * resume of high speed peripherals (but not full 377 - * speed ones). 378 - */ 379 - 380 - musb->is_active = 1; 381 - musb->port1_status &= ~(USB_PORT_STAT_SUSPEND 382 - | MUSB_PORT_STAT_RESUME); 383 - musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; 384 - usb_hcd_poll_rh_status(musb->hcd); 385 - /* NOTE: it might really be A_WAIT_BCON ... */ 386 - musb->xceiv->state = OTG_STATE_A_HOST; 387 - } 388 327 389 328 put_unaligned(cpu_to_le32(musb->port1_status 390 329 & ~MUSB_PORT_STAT_RESUME),
+3 -1
drivers/usb/musb/ux500_dma.c
··· 336 336 data ? 337 337 data->dma_filter : 338 338 NULL, 339 - param_array[ch_num]); 339 + param_array ? 340 + param_array[ch_num] : 341 + NULL); 340 342 341 343 if (!ux500_channel->dma_chan) { 342 344 ERR("Dma pipe allocation error dir=%d ch=%d\n",
+47 -5
drivers/usb/phy/Kconfig
··· 6 6 config USB_PHY 7 7 def_bool n 8 8 9 + config USB_OTG_FSM 10 + tristate "USB 2.0 OTG FSM implementation" 11 + depends on USB 12 + select USB_OTG 13 + select USB_PHY 14 + help 15 + Implements OTG Final State Machine as specified in On-The-Go 16 + and Embedded Host Supplement to the USB Revision 2.0 Specification. 17 + 9 18 # 10 19 # USB Transceiver Drivers 11 20 # ··· 28 19 in host mode, low speed. 29 20 30 21 config FSL_USB2_OTG 31 - tristate "Freescale USB OTG Transceiver Driver" 32 - depends on USB_EHCI_FSL && USB_FSL_USB2 && PM_RUNTIME 33 - depends on USB 22 + bool "Freescale USB OTG Transceiver Driver" 23 + depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_OTG_FSM && PM_RUNTIME 34 24 select USB_OTG 35 25 select USB_PHY 36 26 help ··· 48 40 Instruments OMAP processors. 49 41 50 42 This driver can also be built as a module. If so, the module 51 - will be called isp1301_omap. 43 + will be called phy-isp1301-omap. 44 + 45 + config KEYSTONE_USB_PHY 46 + tristate "Keystone USB PHY Driver" 47 + depends on ARCH_KEYSTONE || COMPILE_TEST 48 + select NOP_USB_XCEIV 49 + help 50 + Enable this to support Keystone USB phy. This driver provides 51 + interface to interact with USB 2.0 and USB 3.0 PHY that is part 52 + of the Keystone SOC. 52 53 53 54 config MV_U3D_PHY 54 55 bool "Marvell USB 3.0 PHY controller Driver" ··· 153 136 optionally control of a D+ pullup GPIO as well as a VBUS 154 137 current limit regulator. 155 138 139 + config OMAP_OTG 140 + tristate "OMAP USB OTG controller driver" 141 + depends on ARCH_OMAP_OTG && EXTCON 142 + help 143 + Enable this to support some transceivers on OMAP1 platforms. OTG 144 + controller is needed to switch between host and peripheral modes. 145 + 146 + This driver can also be built as a module. If so, the module 147 + will be called phy-omap-otg. 148 + 149 + config TAHVO_USB 150 + tristate "Tahvo USB transceiver driver" 151 + depends on MFD_RETU && EXTCON 152 + select USB_PHY 153 + help 154 + Enable this to support USB transceiver on Tahvo. This is used 155 + at least on Nokia 770. 156 + 157 + config TAHVO_USB_HOST_BY_DEFAULT 158 + depends on TAHVO_USB 159 + boolean "Device in USB host mode by default" 160 + help 161 + Say Y here, if you want the device to enter USB host mode 162 + by default on bootup. 163 + 156 164 config USB_ISP1301 157 165 tristate "NXP ISP1301 USB transceiver support" 158 166 depends on USB || USB_GADGET ··· 189 147 and OTG drivers (to be selected separately). 190 148 191 149 To compile this driver as a module, choose M here: the 192 - module will be called isp1301. 150 + module will be called phy-isp1301. 193 151 194 152 config USB_MSM_OTG 195 153 tristate "OTG support for Qualcomm on-chip USB controller"
+5 -2
drivers/usb/phy/Makefile
··· 3 3 # 4 4 obj-$(CONFIG_USB_PHY) += phy.o 5 5 obj-$(CONFIG_OF) += of.o 6 + obj-$(CONFIG_USB_OTG_FSM) += phy-fsm-usb.o 6 7 7 8 # transceiver drivers, keep the list sorted 8 9 9 10 obj-$(CONFIG_AB8500_USB) += phy-ab8500-usb.o 10 - phy-fsl-usb2-objs := phy-fsl-usb.o phy-fsm-usb.o 11 - obj-$(CONFIG_FSL_USB2_OTG) += phy-fsl-usb2.o 11 + obj-$(CONFIG_FSL_USB2_OTG) += phy-fsl-usb.o 12 12 obj-$(CONFIG_ISP1301_OMAP) += phy-isp1301-omap.o 13 13 obj-$(CONFIG_MV_U3D_PHY) += phy-mv-u3d-usb.o 14 14 obj-$(CONFIG_NOP_USB_XCEIV) += phy-generic.o 15 + obj-$(CONFIG_TAHVO_USB) += phy-tahvo.o 15 16 obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o 16 17 obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o 17 18 obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o 19 + obj-$(CONFIG_OMAP_OTG) += phy-omap-otg.o 18 20 obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o 19 21 obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o 20 22 obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o ··· 32 30 obj-$(CONFIG_USB_RCAR_GEN2_PHY) += phy-rcar-gen2-usb.o 33 31 obj-$(CONFIG_USB_ULPI) += phy-ulpi.o 34 32 obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o 33 + obj-$(CONFIG_KEYSTONE_USB_PHY) += phy-keystone.o
-2
drivers/usb/phy/phy-ab8500-usb.c
··· 1415 1415 1416 1416 platform_set_drvdata(pdev, ab); 1417 1417 1418 - ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier); 1419 - 1420 1418 /* all: Disable phy when called from set_host and set_peripheral */ 1421 1419 INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work); 1422 1420
+1 -5
drivers/usb/phy/phy-am335x-control.c
··· 3 3 #include <linux/err.h> 4 4 #include <linux/of.h> 5 5 #include <linux/io.h> 6 - 7 - struct phy_control { 8 - void (*phy_power)(struct phy_control *phy_ctrl, u32 id, bool on); 9 - void (*phy_wkup)(struct phy_control *phy_ctrl, u32 id, bool on); 10 - }; 6 + #include "am35x-phy-control.h" 11 7 12 8 struct am335x_control_usb { 13 9 struct device *dev;
+31 -8
drivers/usb/phy/phy-am335x.c
··· 63 63 am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown; 64 64 65 65 platform_set_drvdata(pdev, am_phy); 66 + device_init_wakeup(dev, true); 67 + 68 + /* 69 + * If we leave PHY wakeup enabled then AM33XX wakes up 70 + * immediately from DS0. To avoid this we mark dev->power.can_wakeup 71 + * to false. The same is checked in suspend routine to decide 72 + * on whether to enable PHY wakeup or not. 73 + * PHY wakeup works fine in standby mode, there by allowing us to 74 + * handle remote wakeup, wakeup on disconnect and connect. 75 + */ 76 + 77 + device_set_wakeup_enable(dev, false); 78 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); 66 79 67 80 return 0; 68 81 } ··· 88 75 return 0; 89 76 } 90 77 91 - #ifdef CONFIG_PM_RUNTIME 92 - 93 - static int am335x_phy_runtime_suspend(struct device *dev) 78 + #ifdef CONFIG_PM_SLEEP 79 + static int am335x_phy_suspend(struct device *dev) 94 80 { 95 81 struct platform_device *pdev = to_platform_device(dev); 96 82 struct am335x_phy *am_phy = platform_get_drvdata(pdev); 97 83 84 + /* 85 + * Enable phy wakeup only if dev->power.can_wakeup is true. 86 + * Make sure to enable wakeup to support remote wakeup in 87 + * standby mode ( same is not supported in OFF(DS0) mode). 88 + * Enable it by doing 89 + * echo enabled > /sys/bus/platform/devices/<usb-phy-id>/power/wakeup 90 + */ 91 + 98 92 if (device_may_wakeup(dev)) 99 93 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true); 94 + 100 95 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); 96 + 101 97 return 0; 102 98 } 103 99 104 - static int am335x_phy_runtime_resume(struct device *dev) 100 + static int am335x_phy_resume(struct device *dev) 105 101 { 106 102 struct platform_device *pdev = to_platform_device(dev); 107 103 struct am335x_phy *am_phy = platform_get_drvdata(pdev); 108 104 109 105 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); 106 + 110 107 if (device_may_wakeup(dev)) 111 108 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false); 109 + 112 110 return 0; 113 111 } 114 112 115 113 static const struct dev_pm_ops am335x_pm_ops = { 116 - SET_RUNTIME_PM_OPS(am335x_phy_runtime_suspend, 117 - am335x_phy_runtime_resume, NULL) 114 + SET_SYSTEM_SLEEP_PM_OPS(am335x_phy_suspend, am335x_phy_resume) 118 115 }; 119 116 120 - #define DEV_PM_OPS (&am335x_pm_ops) 117 + #define DEV_PM_OPS (&am335x_pm_ops) 121 118 #else 122 - #define DEV_PM_OPS NULL 119 + #define DEV_PM_OPS NULL 123 120 #endif 124 121 125 122 static const struct of_device_id am335x_phy_ids[] = {
+3 -4
drivers/usb/phy/phy-fsl-usb.c
··· 848 848 pr_info("Couldn't init OTG timers\n"); 849 849 goto err; 850 850 } 851 - spin_lock_init(&fsl_otg_tc->fsm.lock); 851 + mutex_init(&fsl_otg_tc->fsm.lock); 852 852 853 853 /* Set OTG state machine operations */ 854 854 fsl_otg_tc->fsm.ops = &fsl_otg_ops; ··· 1017 1017 struct otg_fsm *fsm = &fsl_otg_dev->fsm; 1018 1018 char *next = buf; 1019 1019 unsigned size = PAGE_SIZE; 1020 - unsigned long flags; 1021 1020 int t; 1022 1021 1023 - spin_lock_irqsave(&fsm->lock, flags); 1022 + mutex_lock(&fsm->lock); 1024 1023 1025 1024 /* basic driver infomation */ 1026 1025 t = scnprintf(next, size, ··· 1087 1088 size -= t; 1088 1089 next += t; 1089 1090 1090 - spin_unlock_irqrestore(&fsm->lock, flags); 1091 + mutex_unlock(&fsm->lock); 1091 1092 1092 1093 return PAGE_SIZE - size; 1093 1094 }
+1 -1
drivers/usb/phy/phy-fsl-usb.h
··· 15 15 * 675 Mass Ave, Cambridge, MA 02139, USA. 16 16 */ 17 17 18 - #include "phy-fsm-usb.h" 18 + #include <linux/usb/otg-fsm.h> 19 19 #include <linux/usb/otg.h> 20 20 #include <linux/ioctl.h> 21 21
+6 -8
drivers/usb/phy/phy-fsm-usb.c
··· 23 23 24 24 #include <linux/kernel.h> 25 25 #include <linux/types.h> 26 - #include <linux/spinlock.h> 26 + #include <linux/mutex.h> 27 27 #include <linux/delay.h> 28 28 #include <linux/usb.h> 29 29 #include <linux/usb/gadget.h> 30 30 #include <linux/usb/otg.h> 31 - 32 - #include "phy-fsm-usb.h" 31 + #include <linux/usb/otg-fsm.h> 33 32 34 33 /* Change USB protocol when there is a protocol change */ 35 34 static int otg_set_protocol(struct otg_fsm *fsm, int protocol) ··· 64 65 static int state_changed; 65 66 66 67 /* Called when leaving a state. Do state clean up jobs here */ 67 - void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state) 68 + static void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state) 68 69 { 69 70 switch (old_state) { 70 71 case OTG_STATE_B_IDLE: ··· 121 122 } 122 123 123 124 /* Called when entering a state */ 124 - int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) 125 + static int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) 125 126 { 126 127 state_changed = 1; 127 128 if (fsm->otg->phy->state == new_state) ··· 244 245 int otg_statemachine(struct otg_fsm *fsm) 245 246 { 246 247 enum usb_otg_state state; 247 - unsigned long flags; 248 248 249 - spin_lock_irqsave(&fsm->lock, flags); 249 + mutex_lock(&fsm->lock); 250 250 251 251 state = fsm->otg->phy->state; 252 252 state_changed = 0; ··· 357 359 default: 358 360 break; 359 361 } 360 - spin_unlock_irqrestore(&fsm->lock, flags); 362 + mutex_unlock(&fsm->lock); 361 363 362 364 VDBG("quit statemachine, changed = %d\n", state_changed); 363 365 return state_changed;
+9 -1
drivers/usb/phy/phy-fsm-usb.h include/linux/usb/otg-fsm.h
··· 15 15 * 675 Mass Ave, Cambridge, MA 02139, USA. 16 16 */ 17 17 18 + #ifndef __LINUX_USB_OTG_FSM_H 19 + #define __LINUX_USB_OTG_FSM_H 20 + 21 + #include <linux/mutex.h> 22 + #include <linux/errno.h> 23 + 18 24 #undef VERBOSE 19 25 20 26 #ifdef VERBOSE ··· 116 110 117 111 /* Current usb protocol used: 0:undefine; 1:host; 2:client */ 118 112 int protocol; 119 - spinlock_t lock; 113 + struct mutex lock; 120 114 }; 121 115 122 116 struct otg_fsm_ops { ··· 240 234 } 241 235 242 236 int otg_statemachine(struct otg_fsm *fsm); 237 + 238 + #endif /* __LINUX_USB_OTG_FSM_H */
-1
drivers/usb/phy/phy-generic.c
··· 241 241 nop->phy.otg->set_host = nop_set_host; 242 242 nop->phy.otg->set_peripheral = nop_set_peripheral; 243 243 244 - ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier); 245 244 return 0; 246 245 } 247 246 EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy);
-2
drivers/usb/phy/phy-gpio-vbus-usb.c
··· 314 314 goto err_irq; 315 315 } 316 316 317 - ATOMIC_INIT_NOTIFIER_HEAD(&gpio_vbus->phy.notifier); 318 - 319 317 INIT_DELAYED_WORK(&gpio_vbus->work, gpio_vbus_work); 320 318 321 319 gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw");
+4 -5
drivers/usb/phy/phy-isp1301-omap.c
··· 1277 1277 { 1278 1278 struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); 1279 1279 1280 - if (!otg || isp != the_transceiver) 1280 + if (isp != the_transceiver) 1281 1281 return -ENODEV; 1282 1282 1283 1283 if (!host) { ··· 1333 1333 { 1334 1334 struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); 1335 1335 1336 - if (!otg || isp != the_transceiver) 1336 + if (isp != the_transceiver) 1337 1337 return -ENODEV; 1338 1338 1339 1339 if (!gadget) { ··· 1414 1414 struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); 1415 1415 u32 otg_ctrl; 1416 1416 1417 - if (!otg || isp != the_transceiver 1418 - || isp->phy.state != OTG_STATE_B_IDLE) 1417 + if (isp != the_transceiver || isp->phy.state != OTG_STATE_B_IDLE) 1419 1418 return -ENODEV; 1420 1419 1421 1420 otg_ctrl = omap_readl(OTG_CTRL); ··· 1441 1442 struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); 1442 1443 u32 l; 1443 1444 1444 - if (!otg || isp != the_transceiver) 1445 + if (isp != the_transceiver) 1445 1446 return -ENODEV; 1446 1447 if (otg->default_a && (otg->host == NULL || !otg->host->b_hnp_enable)) 1447 1448 return -ENOTCONN;
+136
drivers/usb/phy/phy-keystone.c
··· 1 + /* 2 + * phy-keystone - USB PHY, talking to dwc3 controller in Keystone. 3 + * 4 + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation; either version 2 of the License, or 8 + * (at your option) any later version. 9 + * 10 + * Author: WingMan Kwok <w-kwok2@ti.com> 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + */ 18 + 19 + #include <linux/module.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/usb/usb_phy_gen_xceiv.h> 22 + #include <linux/io.h> 23 + #include <linux/of.h> 24 + 25 + #include "phy-generic.h" 26 + 27 + /* USB PHY control register offsets */ 28 + #define USB_PHY_CTL_UTMI 0x0000 29 + #define USB_PHY_CTL_PIPE 0x0004 30 + #define USB_PHY_CTL_PARAM_1 0x0008 31 + #define USB_PHY_CTL_PARAM_2 0x000c 32 + #define USB_PHY_CTL_CLOCK 0x0010 33 + #define USB_PHY_CTL_PLL 0x0014 34 + 35 + #define PHY_REF_SSP_EN BIT(29) 36 + 37 + struct keystone_usbphy { 38 + struct usb_phy_gen_xceiv usb_phy_gen; 39 + void __iomem *phy_ctrl; 40 + }; 41 + 42 + static inline u32 keystone_usbphy_readl(void __iomem *base, u32 offset) 43 + { 44 + return readl(base + offset); 45 + } 46 + 47 + static inline void keystone_usbphy_writel(void __iomem *base, 48 + u32 offset, u32 value) 49 + { 50 + writel(value, base + offset); 51 + } 52 + 53 + static int keystone_usbphy_init(struct usb_phy *phy) 54 + { 55 + struct keystone_usbphy *k_phy = dev_get_drvdata(phy->dev); 56 + u32 val; 57 + 58 + val = keystone_usbphy_readl(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK); 59 + keystone_usbphy_writel(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK, 60 + val | PHY_REF_SSP_EN); 61 + return 0; 62 + } 63 + 64 + static void keystone_usbphy_shutdown(struct usb_phy *phy) 65 + { 66 + struct keystone_usbphy *k_phy = dev_get_drvdata(phy->dev); 67 + u32 val; 68 + 69 + val = keystone_usbphy_readl(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK); 70 + keystone_usbphy_writel(k_phy->phy_ctrl, USB_PHY_CTL_CLOCK, 71 + val &= ~PHY_REF_SSP_EN); 72 + } 73 + 74 + static int keystone_usbphy_probe(struct platform_device *pdev) 75 + { 76 + struct device *dev = &pdev->dev; 77 + struct keystone_usbphy *k_phy; 78 + struct resource *res; 79 + int ret; 80 + 81 + k_phy = devm_kzalloc(dev, sizeof(*k_phy), GFP_KERNEL); 82 + if (!k_phy) 83 + return -ENOMEM; 84 + 85 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 86 + k_phy->phy_ctrl = devm_ioremap_resource(dev, res); 87 + if (IS_ERR(k_phy->phy_ctrl)) 88 + return PTR_ERR(k_phy->phy_ctrl); 89 + 90 + ret = usb_phy_gen_create_phy(dev, &k_phy->usb_phy_gen, NULL); 91 + if (ret) 92 + return ret; 93 + 94 + k_phy->usb_phy_gen.phy.init = keystone_usbphy_init; 95 + k_phy->usb_phy_gen.phy.shutdown = keystone_usbphy_shutdown; 96 + 97 + platform_set_drvdata(pdev, k_phy); 98 + 99 + ret = usb_add_phy_dev(&k_phy->usb_phy_gen.phy); 100 + if (ret) 101 + return ret; 102 + 103 + return 0; 104 + } 105 + 106 + static int keystone_usbphy_remove(struct platform_device *pdev) 107 + { 108 + struct keystone_usbphy *k_phy = platform_get_drvdata(pdev); 109 + 110 + usb_remove_phy(&k_phy->usb_phy_gen.phy); 111 + 112 + return 0; 113 + } 114 + 115 + static const struct of_device_id keystone_usbphy_ids[] = { 116 + { .compatible = "ti,keystone-usbphy" }, 117 + { } 118 + }; 119 + MODULE_DEVICE_TABLE(of, keystone_usbphy_ids); 120 + 121 + static struct platform_driver keystone_usbphy_driver = { 122 + .probe = keystone_usbphy_probe, 123 + .remove = keystone_usbphy_remove, 124 + .driver = { 125 + .name = "keystone-usbphy", 126 + .owner = THIS_MODULE, 127 + .of_match_table = keystone_usbphy_ids, 128 + }, 129 + }; 130 + 131 + module_platform_driver(keystone_usbphy_driver); 132 + 133 + MODULE_ALIAS("platform:keystone-usbphy"); 134 + MODULE_AUTHOR("Texas Instruments Inc."); 135 + MODULE_DESCRIPTION("Keystone USB phy driver"); 136 + MODULE_LICENSE("GPL v2");
+9 -4
drivers/usb/phy/phy-mxs-usb.c
··· 63 63 64 64 static int mxs_phy_init(struct usb_phy *phy) 65 65 { 66 + int ret; 66 67 struct mxs_phy *mxs_phy = to_mxs_phy(phy); 67 68 68 - clk_prepare_enable(mxs_phy->clk); 69 + ret = clk_prepare_enable(mxs_phy->clk); 70 + if (ret) 71 + return ret; 72 + 69 73 return mxs_phy_hw_init(mxs_phy); 70 74 } 71 75 ··· 85 81 86 82 static int mxs_phy_suspend(struct usb_phy *x, int suspend) 87 83 { 84 + int ret; 88 85 struct mxs_phy *mxs_phy = to_mxs_phy(x); 89 86 90 87 if (suspend) { ··· 94 89 x->io_priv + HW_USBPHY_CTRL_SET); 95 90 clk_disable_unprepare(mxs_phy->clk); 96 91 } else { 97 - clk_prepare_enable(mxs_phy->clk); 92 + ret = clk_prepare_enable(mxs_phy->clk); 93 + if (ret) 94 + return ret; 98 95 writel(BM_USBPHY_CTRL_CLKGATE, 99 96 x->io_priv + HW_USBPHY_CTRL_CLR); 100 97 writel(0, x->io_priv + HW_USBPHY_PWD); ··· 166 159 mxs_phy->phy.notify_connect = mxs_phy_on_connect; 167 160 mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect; 168 161 mxs_phy->phy.type = USB_PHY_TYPE_USB2; 169 - 170 - ATOMIC_INIT_NOTIFIER_HEAD(&mxs_phy->phy.notifier); 171 162 172 163 mxs_phy->clk = clk; 173 164
+19
drivers/usb/phy/phy-omap-control.c
··· 84 84 else 85 85 val |= OMAP_CTRL_USB2_PHY_PD; 86 86 break; 87 + 88 + case OMAP_CTRL_TYPE_AM437USB2: 89 + if (on) { 90 + val &= ~(AM437X_CTRL_USB2_PHY_PD | 91 + AM437X_CTRL_USB2_OTG_PD); 92 + val |= (AM437X_CTRL_USB2_OTGVDET_EN | 93 + AM437X_CTRL_USB2_OTGSESSEND_EN); 94 + } else { 95 + val &= ~(AM437X_CTRL_USB2_OTGVDET_EN | 96 + AM437X_CTRL_USB2_OTGSESSEND_EN); 97 + val |= (AM437X_CTRL_USB2_PHY_PD | 98 + AM437X_CTRL_USB2_OTG_PD); 99 + } 100 + break; 87 101 default: 88 102 dev_err(dev, "%s: type %d not recognized\n", 89 103 __func__, control_usb->type); ··· 211 197 static const enum omap_control_usb_type usb2_data = OMAP_CTRL_TYPE_USB2; 212 198 static const enum omap_control_usb_type pipe3_data = OMAP_CTRL_TYPE_PIPE3; 213 199 static const enum omap_control_usb_type dra7usb2_data = OMAP_CTRL_TYPE_DRA7USB2; 200 + static const enum omap_control_usb_type am437usb2_data = OMAP_CTRL_TYPE_AM437USB2; 214 201 215 202 static const struct of_device_id omap_control_usb_id_table[] = { 216 203 { ··· 229 214 { 230 215 .compatible = "ti,control-phy-dra7usb2", 231 216 .data = &dra7usb2_data, 217 + }, 218 + { 219 + .compatible = "ti,control-phy-am437usb2", 220 + .data = &am437usb2_data, 232 221 }, 233 222 {}, 234 223 };
+169
drivers/usb/phy/phy-omap-otg.c
··· 1 + /* 2 + * OMAP OTG controller driver 3 + * 4 + * Based on code from tahvo-usb.c and isp1301_omap.c drivers. 5 + * 6 + * Copyright (C) 2005-2006 Nokia Corporation 7 + * Copyright (C) 2004 Texas Instruments 8 + * Copyright (C) 2004 David Brownell 9 + * 10 + * This file is subject to the terms and conditions of the GNU General 11 + * Public License. See the file "COPYING" in the main directory of this 12 + * archive for more details. 13 + * 14 + * This program is distributed in the hope that it will be useful, 15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 + * GNU General Public License for more details. 18 + */ 19 + 20 + #include <linux/io.h> 21 + #include <linux/err.h> 22 + #include <linux/extcon.h> 23 + #include <linux/kernel.h> 24 + #include <linux/module.h> 25 + #include <linux/interrupt.h> 26 + #include <linux/platform_device.h> 27 + #include <linux/platform_data/usb-omap1.h> 28 + 29 + struct otg_device { 30 + void __iomem *base; 31 + bool id; 32 + bool vbus; 33 + struct extcon_specific_cable_nb vbus_dev; 34 + struct extcon_specific_cable_nb id_dev; 35 + struct notifier_block vbus_nb; 36 + struct notifier_block id_nb; 37 + }; 38 + 39 + #define OMAP_OTG_CTRL 0x0c 40 + #define OMAP_OTG_ASESSVLD (1 << 20) 41 + #define OMAP_OTG_BSESSEND (1 << 19) 42 + #define OMAP_OTG_BSESSVLD (1 << 18) 43 + #define OMAP_OTG_VBUSVLD (1 << 17) 44 + #define OMAP_OTG_ID (1 << 16) 45 + #define OMAP_OTG_XCEIV_OUTPUTS \ 46 + (OMAP_OTG_ASESSVLD | OMAP_OTG_BSESSEND | OMAP_OTG_BSESSVLD | \ 47 + OMAP_OTG_VBUSVLD | OMAP_OTG_ID) 48 + 49 + static void omap_otg_ctrl(struct otg_device *otg_dev, u32 outputs) 50 + { 51 + u32 l; 52 + 53 + l = readl(otg_dev->base + OMAP_OTG_CTRL); 54 + l &= ~OMAP_OTG_XCEIV_OUTPUTS; 55 + l |= outputs; 56 + writel(l, otg_dev->base + OMAP_OTG_CTRL); 57 + } 58 + 59 + static void omap_otg_set_mode(struct otg_device *otg_dev) 60 + { 61 + if (!otg_dev->id && otg_dev->vbus) 62 + /* Set B-session valid. */ 63 + omap_otg_ctrl(otg_dev, OMAP_OTG_ID | OMAP_OTG_BSESSVLD); 64 + else if (otg_dev->vbus) 65 + /* Set A-session valid. */ 66 + omap_otg_ctrl(otg_dev, OMAP_OTG_ASESSVLD); 67 + else if (!otg_dev->id) 68 + /* Set B-session end to indicate no VBUS. */ 69 + omap_otg_ctrl(otg_dev, OMAP_OTG_ID | OMAP_OTG_BSESSEND); 70 + } 71 + 72 + static int omap_otg_id_notifier(struct notifier_block *nb, 73 + unsigned long event, void *ptr) 74 + { 75 + struct otg_device *otg_dev = container_of(nb, struct otg_device, id_nb); 76 + 77 + otg_dev->id = event; 78 + omap_otg_set_mode(otg_dev); 79 + 80 + return NOTIFY_DONE; 81 + } 82 + 83 + static int omap_otg_vbus_notifier(struct notifier_block *nb, 84 + unsigned long event, void *ptr) 85 + { 86 + struct otg_device *otg_dev = container_of(nb, struct otg_device, 87 + vbus_nb); 88 + 89 + otg_dev->vbus = event; 90 + omap_otg_set_mode(otg_dev); 91 + 92 + return NOTIFY_DONE; 93 + } 94 + 95 + static int omap_otg_probe(struct platform_device *pdev) 96 + { 97 + const struct omap_usb_config *config = pdev->dev.platform_data; 98 + struct otg_device *otg_dev; 99 + struct extcon_dev *extcon; 100 + int ret; 101 + u32 rev; 102 + 103 + if (!config || !config->extcon) 104 + return -ENODEV; 105 + 106 + extcon = extcon_get_extcon_dev(config->extcon); 107 + if (!extcon) 108 + return -EPROBE_DEFER; 109 + 110 + otg_dev = devm_kzalloc(&pdev->dev, sizeof(*otg_dev), GFP_KERNEL); 111 + if (!otg_dev) 112 + return -ENOMEM; 113 + 114 + otg_dev->base = devm_ioremap_resource(&pdev->dev, &pdev->resource[0]); 115 + if (IS_ERR(otg_dev->base)) 116 + return PTR_ERR(otg_dev->base); 117 + 118 + otg_dev->id_nb.notifier_call = omap_otg_id_notifier; 119 + otg_dev->vbus_nb.notifier_call = omap_otg_vbus_notifier; 120 + 121 + ret = extcon_register_interest(&otg_dev->id_dev, config->extcon, 122 + "USB-HOST", &otg_dev->id_nb); 123 + if (ret) 124 + return ret; 125 + 126 + ret = extcon_register_interest(&otg_dev->vbus_dev, config->extcon, 127 + "USB", &otg_dev->vbus_nb); 128 + if (ret) { 129 + extcon_unregister_interest(&otg_dev->id_dev); 130 + return ret; 131 + } 132 + 133 + otg_dev->id = extcon_get_cable_state(extcon, "USB-HOST"); 134 + otg_dev->vbus = extcon_get_cable_state(extcon, "USB"); 135 + omap_otg_set_mode(otg_dev); 136 + 137 + rev = readl(otg_dev->base); 138 + 139 + dev_info(&pdev->dev, 140 + "OMAP USB OTG controller rev %d.%d (%s, id=%d, vbus=%d)\n", 141 + (rev >> 4) & 0xf, rev & 0xf, config->extcon, otg_dev->id, 142 + otg_dev->vbus); 143 + 144 + return 0; 145 + } 146 + 147 + static int omap_otg_remove(struct platform_device *pdev) 148 + { 149 + struct otg_device *otg_dev = platform_get_drvdata(pdev); 150 + 151 + extcon_unregister_interest(&otg_dev->id_dev); 152 + extcon_unregister_interest(&otg_dev->vbus_dev); 153 + 154 + return 0; 155 + } 156 + 157 + static struct platform_driver omap_otg_driver = { 158 + .probe = omap_otg_probe, 159 + .remove = omap_otg_remove, 160 + .driver = { 161 + .owner = THIS_MODULE, 162 + .name = "omap_otg", 163 + }, 164 + }; 165 + module_platform_driver(omap_otg_driver); 166 + 167 + MODULE_DESCRIPTION("OMAP USB OTG controller driver"); 168 + MODULE_LICENSE("GPL"); 169 + MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
+1 -1
drivers/usb/phy/phy-rcar-gen2-usb.c
··· 213 213 priv->phy.shutdown = rcar_gen2_usb_phy_shutdown; 214 214 priv->phy.set_suspend = rcar_gen2_usb_phy_set_suspend; 215 215 216 - retval = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2); 216 + retval = usb_add_phy_dev(&priv->phy); 217 217 if (retval < 0) { 218 218 dev_err(dev, "Failed to add USB phy\n"); 219 219 return retval;
+457
drivers/usb/phy/phy-tahvo.c
··· 1 + /* 2 + * Tahvo USB transceiver driver 3 + * 4 + * Copyright (C) 2005-2006 Nokia Corporation 5 + * 6 + * Parts copied from isp1301_omap.c. 7 + * Copyright (C) 2004 Texas Instruments 8 + * Copyright (C) 2004 David Brownell 9 + * 10 + * Original driver written by Juha Yrjölä, Tony Lindgren and Timo Teräs. 11 + * Modified for Retu/Tahvo MFD by Aaro Koskinen. 12 + * 13 + * This file is subject to the terms and conditions of the GNU General 14 + * Public License. See the file "COPYING" in the main directory of this 15 + * archive for more details. 16 + * 17 + * This program is distributed in the hope that it will be useful, 18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 + * GNU General Public License for more details. 21 + */ 22 + 23 + #include <linux/io.h> 24 + #include <linux/clk.h> 25 + #include <linux/usb.h> 26 + #include <linux/extcon.h> 27 + #include <linux/kernel.h> 28 + #include <linux/module.h> 29 + #include <linux/usb/otg.h> 30 + #include <linux/mfd/retu.h> 31 + #include <linux/usb/gadget.h> 32 + #include <linux/platform_device.h> 33 + 34 + #define DRIVER_NAME "tahvo-usb" 35 + 36 + #define TAHVO_REG_IDSR 0x02 37 + #define TAHVO_REG_USBR 0x06 38 + 39 + #define USBR_SLAVE_CONTROL (1 << 8) 40 + #define USBR_VPPVIO_SW (1 << 7) 41 + #define USBR_SPEED (1 << 6) 42 + #define USBR_REGOUT (1 << 5) 43 + #define USBR_MASTER_SW2 (1 << 4) 44 + #define USBR_MASTER_SW1 (1 << 3) 45 + #define USBR_SLAVE_SW (1 << 2) 46 + #define USBR_NSUSPEND (1 << 1) 47 + #define USBR_SEMODE (1 << 0) 48 + 49 + #define TAHVO_MODE_HOST 0 50 + #define TAHVO_MODE_PERIPHERAL 1 51 + 52 + struct tahvo_usb { 53 + struct platform_device *pt_dev; 54 + struct usb_phy phy; 55 + int vbus_state; 56 + struct mutex serialize; 57 + struct clk *ick; 58 + int irq; 59 + int tahvo_mode; 60 + struct extcon_dev extcon; 61 + }; 62 + 63 + static const char *tahvo_cable[] = { 64 + "USB-HOST", 65 + "USB", 66 + NULL, 67 + }; 68 + 69 + static ssize_t vbus_state_show(struct device *device, 70 + struct device_attribute *attr, char *buf) 71 + { 72 + struct tahvo_usb *tu = dev_get_drvdata(device); 73 + return sprintf(buf, "%s\n", tu->vbus_state ? "on" : "off"); 74 + } 75 + static DEVICE_ATTR(vbus, 0444, vbus_state_show, NULL); 76 + 77 + static void check_vbus_state(struct tahvo_usb *tu) 78 + { 79 + struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); 80 + int reg, prev_state; 81 + 82 + reg = retu_read(rdev, TAHVO_REG_IDSR); 83 + if (reg & TAHVO_STAT_VBUS) { 84 + switch (tu->phy.state) { 85 + case OTG_STATE_B_IDLE: 86 + /* Enable the gadget driver */ 87 + if (tu->phy.otg->gadget) 88 + usb_gadget_vbus_connect(tu->phy.otg->gadget); 89 + tu->phy.state = OTG_STATE_B_PERIPHERAL; 90 + break; 91 + case OTG_STATE_A_IDLE: 92 + /* 93 + * Session is now valid assuming the USB hub is driving 94 + * Vbus. 95 + */ 96 + tu->phy.state = OTG_STATE_A_HOST; 97 + break; 98 + default: 99 + break; 100 + } 101 + dev_info(&tu->pt_dev->dev, "USB cable connected\n"); 102 + } else { 103 + switch (tu->phy.state) { 104 + case OTG_STATE_B_PERIPHERAL: 105 + if (tu->phy.otg->gadget) 106 + usb_gadget_vbus_disconnect(tu->phy.otg->gadget); 107 + tu->phy.state = OTG_STATE_B_IDLE; 108 + break; 109 + case OTG_STATE_A_HOST: 110 + tu->phy.state = OTG_STATE_A_IDLE; 111 + break; 112 + default: 113 + break; 114 + } 115 + dev_info(&tu->pt_dev->dev, "USB cable disconnected\n"); 116 + } 117 + 118 + prev_state = tu->vbus_state; 119 + tu->vbus_state = reg & TAHVO_STAT_VBUS; 120 + if (prev_state != tu->vbus_state) { 121 + extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state); 122 + sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state"); 123 + } 124 + } 125 + 126 + static void tahvo_usb_become_host(struct tahvo_usb *tu) 127 + { 128 + struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); 129 + 130 + extcon_set_cable_state(&tu->extcon, "USB-HOST", true); 131 + 132 + /* Power up the transceiver in USB host mode */ 133 + retu_write(rdev, TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND | 134 + USBR_MASTER_SW2 | USBR_MASTER_SW1); 135 + tu->phy.state = OTG_STATE_A_IDLE; 136 + 137 + check_vbus_state(tu); 138 + } 139 + 140 + static void tahvo_usb_stop_host(struct tahvo_usb *tu) 141 + { 142 + tu->phy.state = OTG_STATE_A_IDLE; 143 + } 144 + 145 + static void tahvo_usb_become_peripheral(struct tahvo_usb *tu) 146 + { 147 + struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); 148 + 149 + extcon_set_cable_state(&tu->extcon, "USB-HOST", false); 150 + 151 + /* Power up transceiver and set it in USB peripheral mode */ 152 + retu_write(rdev, TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT | 153 + USBR_NSUSPEND | USBR_SLAVE_SW); 154 + tu->phy.state = OTG_STATE_B_IDLE; 155 + 156 + check_vbus_state(tu); 157 + } 158 + 159 + static void tahvo_usb_stop_peripheral(struct tahvo_usb *tu) 160 + { 161 + if (tu->phy.otg->gadget) 162 + usb_gadget_vbus_disconnect(tu->phy.otg->gadget); 163 + tu->phy.state = OTG_STATE_B_IDLE; 164 + } 165 + 166 + static void tahvo_usb_power_off(struct tahvo_usb *tu) 167 + { 168 + struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); 169 + 170 + /* Disable gadget controller if any */ 171 + if (tu->phy.otg->gadget) 172 + usb_gadget_vbus_disconnect(tu->phy.otg->gadget); 173 + 174 + /* Power off transceiver */ 175 + retu_write(rdev, TAHVO_REG_USBR, 0); 176 + tu->phy.state = OTG_STATE_UNDEFINED; 177 + } 178 + 179 + static int tahvo_usb_set_suspend(struct usb_phy *dev, int suspend) 180 + { 181 + struct tahvo_usb *tu = container_of(dev, struct tahvo_usb, phy); 182 + struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent); 183 + u16 w; 184 + 185 + dev_dbg(&tu->pt_dev->dev, "%s\n", __func__); 186 + 187 + w = retu_read(rdev, TAHVO_REG_USBR); 188 + if (suspend) 189 + w &= ~USBR_NSUSPEND; 190 + else 191 + w |= USBR_NSUSPEND; 192 + retu_write(rdev, TAHVO_REG_USBR, w); 193 + 194 + return 0; 195 + } 196 + 197 + static int tahvo_usb_set_host(struct usb_otg *otg, struct usb_bus *host) 198 + { 199 + struct tahvo_usb *tu = container_of(otg->phy, struct tahvo_usb, phy); 200 + 201 + dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, host); 202 + 203 + mutex_lock(&tu->serialize); 204 + 205 + if (host == NULL) { 206 + if (tu->tahvo_mode == TAHVO_MODE_HOST) 207 + tahvo_usb_power_off(tu); 208 + otg->host = NULL; 209 + mutex_unlock(&tu->serialize); 210 + return 0; 211 + } 212 + 213 + if (tu->tahvo_mode == TAHVO_MODE_HOST) { 214 + otg->host = NULL; 215 + tahvo_usb_become_host(tu); 216 + } 217 + 218 + otg->host = host; 219 + 220 + mutex_unlock(&tu->serialize); 221 + 222 + return 0; 223 + } 224 + 225 + static int tahvo_usb_set_peripheral(struct usb_otg *otg, 226 + struct usb_gadget *gadget) 227 + { 228 + struct tahvo_usb *tu = container_of(otg->phy, struct tahvo_usb, phy); 229 + 230 + dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, gadget); 231 + 232 + mutex_lock(&tu->serialize); 233 + 234 + if (!gadget) { 235 + if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) 236 + tahvo_usb_power_off(tu); 237 + tu->phy.otg->gadget = NULL; 238 + mutex_unlock(&tu->serialize); 239 + return 0; 240 + } 241 + 242 + tu->phy.otg->gadget = gadget; 243 + if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) 244 + tahvo_usb_become_peripheral(tu); 245 + 246 + mutex_unlock(&tu->serialize); 247 + 248 + return 0; 249 + } 250 + 251 + static irqreturn_t tahvo_usb_vbus_interrupt(int irq, void *_tu) 252 + { 253 + struct tahvo_usb *tu = _tu; 254 + 255 + mutex_lock(&tu->serialize); 256 + check_vbus_state(tu); 257 + mutex_unlock(&tu->serialize); 258 + 259 + return IRQ_HANDLED; 260 + } 261 + 262 + static ssize_t otg_mode_show(struct device *device, 263 + struct device_attribute *attr, char *buf) 264 + { 265 + struct tahvo_usb *tu = dev_get_drvdata(device); 266 + 267 + switch (tu->tahvo_mode) { 268 + case TAHVO_MODE_HOST: 269 + return sprintf(buf, "host\n"); 270 + case TAHVO_MODE_PERIPHERAL: 271 + return sprintf(buf, "peripheral\n"); 272 + } 273 + 274 + return -EINVAL; 275 + } 276 + 277 + static ssize_t otg_mode_store(struct device *device, 278 + struct device_attribute *attr, 279 + const char *buf, size_t count) 280 + { 281 + struct tahvo_usb *tu = dev_get_drvdata(device); 282 + int r; 283 + 284 + mutex_lock(&tu->serialize); 285 + if (count >= 4 && strncmp(buf, "host", 4) == 0) { 286 + if (tu->tahvo_mode == TAHVO_MODE_PERIPHERAL) 287 + tahvo_usb_stop_peripheral(tu); 288 + tu->tahvo_mode = TAHVO_MODE_HOST; 289 + if (tu->phy.otg->host) { 290 + dev_info(device, "HOST mode: host controller present\n"); 291 + tahvo_usb_become_host(tu); 292 + } else { 293 + dev_info(device, "HOST mode: no host controller, powering off\n"); 294 + tahvo_usb_power_off(tu); 295 + } 296 + r = strlen(buf); 297 + } else if (count >= 10 && strncmp(buf, "peripheral", 10) == 0) { 298 + if (tu->tahvo_mode == TAHVO_MODE_HOST) 299 + tahvo_usb_stop_host(tu); 300 + tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; 301 + if (tu->phy.otg->gadget) { 302 + dev_info(device, "PERIPHERAL mode: gadget driver present\n"); 303 + tahvo_usb_become_peripheral(tu); 304 + } else { 305 + dev_info(device, "PERIPHERAL mode: no gadget driver, powering off\n"); 306 + tahvo_usb_power_off(tu); 307 + } 308 + r = strlen(buf); 309 + } else { 310 + r = -EINVAL; 311 + } 312 + mutex_unlock(&tu->serialize); 313 + 314 + return r; 315 + } 316 + static DEVICE_ATTR(otg_mode, 0644, otg_mode_show, otg_mode_store); 317 + 318 + static struct attribute *tahvo_attributes[] = { 319 + &dev_attr_vbus.attr, 320 + &dev_attr_otg_mode.attr, 321 + NULL 322 + }; 323 + 324 + static struct attribute_group tahvo_attr_group = { 325 + .attrs = tahvo_attributes, 326 + }; 327 + 328 + static int tahvo_usb_probe(struct platform_device *pdev) 329 + { 330 + struct retu_dev *rdev = dev_get_drvdata(pdev->dev.parent); 331 + struct tahvo_usb *tu; 332 + int ret; 333 + 334 + tu = devm_kzalloc(&pdev->dev, sizeof(*tu), GFP_KERNEL); 335 + if (!tu) 336 + return -ENOMEM; 337 + 338 + tu->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*tu->phy.otg), 339 + GFP_KERNEL); 340 + if (!tu->phy.otg) 341 + return -ENOMEM; 342 + 343 + tu->pt_dev = pdev; 344 + 345 + /* Default mode */ 346 + #ifdef CONFIG_TAHVO_USB_HOST_BY_DEFAULT 347 + tu->tahvo_mode = TAHVO_MODE_HOST; 348 + #else 349 + tu->tahvo_mode = TAHVO_MODE_PERIPHERAL; 350 + #endif 351 + 352 + mutex_init(&tu->serialize); 353 + 354 + tu->ick = devm_clk_get(&pdev->dev, "usb_l4_ick"); 355 + if (!IS_ERR(tu->ick)) 356 + clk_enable(tu->ick); 357 + 358 + /* 359 + * Set initial state, so that we generate kevents only on state changes. 360 + */ 361 + tu->vbus_state = retu_read(rdev, TAHVO_REG_IDSR) & TAHVO_STAT_VBUS; 362 + 363 + tu->extcon.name = DRIVER_NAME; 364 + tu->extcon.supported_cable = tahvo_cable; 365 + tu->extcon.dev.parent = &pdev->dev; 366 + 367 + ret = extcon_dev_register(&tu->extcon); 368 + if (ret) { 369 + dev_err(&pdev->dev, "could not register extcon device: %d\n", 370 + ret); 371 + goto err_disable_clk; 372 + } 373 + 374 + /* Set the initial cable state. */ 375 + extcon_set_cable_state(&tu->extcon, "USB-HOST", 376 + tu->tahvo_mode == TAHVO_MODE_HOST); 377 + extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state); 378 + 379 + /* Create OTG interface */ 380 + tahvo_usb_power_off(tu); 381 + tu->phy.dev = &pdev->dev; 382 + tu->phy.state = OTG_STATE_UNDEFINED; 383 + tu->phy.label = DRIVER_NAME; 384 + tu->phy.set_suspend = tahvo_usb_set_suspend; 385 + 386 + tu->phy.otg->phy = &tu->phy; 387 + tu->phy.otg->set_host = tahvo_usb_set_host; 388 + tu->phy.otg->set_peripheral = tahvo_usb_set_peripheral; 389 + 390 + ret = usb_add_phy(&tu->phy, USB_PHY_TYPE_USB2); 391 + if (ret < 0) { 392 + dev_err(&pdev->dev, "cannot register USB transceiver: %d\n", 393 + ret); 394 + goto err_extcon_unreg; 395 + } 396 + 397 + dev_set_drvdata(&pdev->dev, tu); 398 + 399 + tu->irq = platform_get_irq(pdev, 0); 400 + ret = request_threaded_irq(tu->irq, NULL, tahvo_usb_vbus_interrupt, 0, 401 + "tahvo-vbus", tu); 402 + if (ret) { 403 + dev_err(&pdev->dev, "could not register tahvo-vbus irq: %d\n", 404 + ret); 405 + goto err_remove_phy; 406 + } 407 + 408 + /* Attributes */ 409 + ret = sysfs_create_group(&pdev->dev.kobj, &tahvo_attr_group); 410 + if (ret) { 411 + dev_err(&pdev->dev, "cannot create sysfs group: %d\n", ret); 412 + goto err_free_irq; 413 + } 414 + 415 + return 0; 416 + 417 + err_free_irq: 418 + free_irq(tu->irq, tu); 419 + err_remove_phy: 420 + usb_remove_phy(&tu->phy); 421 + err_extcon_unreg: 422 + extcon_dev_unregister(&tu->extcon); 423 + err_disable_clk: 424 + if (!IS_ERR(tu->ick)) 425 + clk_disable(tu->ick); 426 + 427 + return ret; 428 + } 429 + 430 + static int tahvo_usb_remove(struct platform_device *pdev) 431 + { 432 + struct tahvo_usb *tu = platform_get_drvdata(pdev); 433 + 434 + sysfs_remove_group(&pdev->dev.kobj, &tahvo_attr_group); 435 + free_irq(tu->irq, tu); 436 + usb_remove_phy(&tu->phy); 437 + extcon_dev_unregister(&tu->extcon); 438 + if (!IS_ERR(tu->ick)) 439 + clk_disable(tu->ick); 440 + 441 + return 0; 442 + } 443 + 444 + static struct platform_driver tahvo_usb_driver = { 445 + .probe = tahvo_usb_probe, 446 + .remove = tahvo_usb_remove, 447 + .driver = { 448 + .name = "tahvo-usb", 449 + .owner = THIS_MODULE, 450 + }, 451 + }; 452 + module_platform_driver(tahvo_usb_driver); 453 + 454 + MODULE_DESCRIPTION("Tahvo USB transceiver driver"); 455 + MODULE_LICENSE("GPL"); 456 + MODULE_AUTHOR("Juha Yrjölä, Tony Lindgren, and Timo Teräs"); 457 + MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
+1 -1
drivers/usb/phy/phy-twl6030-usb.c
··· 328 328 struct device *dev = &pdev->dev; 329 329 struct twl4030_usb_data *pdata = dev_get_platdata(dev); 330 330 331 - twl = devm_kzalloc(dev, sizeof *twl, GFP_KERNEL); 331 + twl = devm_kzalloc(dev, sizeof(*twl), GFP_KERNEL); 332 332 if (!twl) 333 333 return -ENOMEM; 334 334
+4
drivers/usb/phy/phy.c
··· 329 329 return -EINVAL; 330 330 } 331 331 332 + ATOMIC_INIT_NOTIFIER_HEAD(&x->notifier); 333 + 332 334 spin_lock_irqsave(&phy_lock, flags); 333 335 334 336 list_for_each_entry(phy, &phy_list, head) { ··· 368 366 dev_err(x->dev, "no device provided for PHY\n"); 369 367 return -EINVAL; 370 368 } 369 + 370 + ATOMIC_INIT_NOTIFIER_HEAD(&x->notifier); 371 371 372 372 spin_lock_irqsave(&phy_lock, flags); 373 373 list_for_each_entry(phy_bind, &phy_bind_list, list)
+4 -14
drivers/usb/renesas_usbhs/fifo.c
··· 1124 1124 mod->irq_brdysts = 0; 1125 1125 1126 1126 cfifo->pipe = NULL; 1127 - cfifo->tx_chan = NULL; 1128 - cfifo->rx_chan = NULL; 1129 - 1130 1127 d0fifo->pipe = NULL; 1131 - d0fifo->tx_chan = NULL; 1132 - d0fifo->rx_chan = NULL; 1133 - 1134 1128 d1fifo->pipe = NULL; 1135 - d1fifo->tx_chan = NULL; 1136 - d1fifo->rx_chan = NULL; 1137 - 1138 - usbhsf_dma_init(priv, usbhsf_get_d0fifo(priv)); 1139 - usbhsf_dma_init(priv, usbhsf_get_d1fifo(priv)); 1140 1129 } 1141 1130 1142 1131 void usbhs_fifo_quit(struct usbhs_priv *priv) ··· 1136 1147 mod->irq_ready = NULL; 1137 1148 mod->irq_bempsts = 0; 1138 1149 mod->irq_brdysts = 0; 1139 - 1140 - usbhsf_dma_quit(priv, usbhsf_get_d0fifo(priv)); 1141 - usbhsf_dma_quit(priv, usbhsf_get_d1fifo(priv)); 1142 1150 } 1143 1151 1144 1152 int usbhs_fifo_probe(struct usbhs_priv *priv) ··· 1157 1171 fifo->ctr = D0FIFOCTR; 1158 1172 fifo->tx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d0_tx_id); 1159 1173 fifo->rx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d0_rx_id); 1174 + usbhsf_dma_init(priv, fifo); 1160 1175 1161 1176 /* D1FIFO */ 1162 1177 fifo = usbhsf_get_d1fifo(priv); ··· 1167 1180 fifo->ctr = D1FIFOCTR; 1168 1181 fifo->tx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d1_tx_id); 1169 1182 fifo->rx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d1_rx_id); 1183 + usbhsf_dma_init(priv, fifo); 1170 1184 1171 1185 return 0; 1172 1186 } 1173 1187 1174 1188 void usbhs_fifo_remove(struct usbhs_priv *priv) 1175 1189 { 1190 + usbhsf_dma_quit(priv, usbhsf_get_d0fifo(priv)); 1191 + usbhsf_dma_quit(priv, usbhsf_get_d1fifo(priv)); 1176 1192 }
+2 -2
drivers/usb/renesas_usbhs/mod_gadget.c
··· 987 987 /* init DCP */ 988 988 if (usbhsg_is_dcp(uep)) { 989 989 gpriv->gadget.ep0 = &uep->ep; 990 - uep->ep.maxpacket = 64; 990 + usb_ep_set_maxpacket_limit(&uep->ep, 64); 991 991 } 992 992 /* init normal pipe */ 993 993 else { 994 - uep->ep.maxpacket = 512; 994 + usb_ep_set_maxpacket_limit(&uep->ep, 512); 995 995 list_add_tail(&uep->ep.ep_list, &gpriv->gadget.ep_list); 996 996 } 997 997 }
+28
include/linux/phy/phy.h
··· 38 38 }; 39 39 40 40 /** 41 + * struct phy_attrs - represents phy attributes 42 + * @bus_width: Data path width implemented by PHY 43 + */ 44 + struct phy_attrs { 45 + u32 bus_width; 46 + }; 47 + 48 + /** 41 49 * struct phy - represents the phy device 42 50 * @dev: phy device 43 51 * @id: id of the phy device ··· 54 46 * @mutex: mutex to protect phy_ops 55 47 * @init_count: used to protect when the PHY is used by multiple consumers 56 48 * @power_count: used to protect when the PHY is used by multiple consumers 49 + * @phy_attrs: used to specify PHY specific attributes 57 50 */ 58 51 struct phy { 59 52 struct device dev; ··· 64 55 struct mutex mutex; 65 56 int init_count; 66 57 int power_count; 58 + struct phy_attrs attrs; 67 59 }; 68 60 69 61 /** ··· 137 127 int phy_exit(struct phy *phy); 138 128 int phy_power_on(struct phy *phy); 139 129 int phy_power_off(struct phy *phy); 130 + static inline int phy_get_bus_width(struct phy *phy) 131 + { 132 + return phy->attrs.bus_width; 133 + } 134 + static inline void phy_set_bus_width(struct phy *phy, int bus_width) 135 + { 136 + phy->attrs.bus_width = bus_width; 137 + } 140 138 struct phy *phy_get(struct device *dev, const char *string); 141 139 struct phy *devm_phy_get(struct device *dev, const char *string); 142 140 void phy_put(struct phy *phy); ··· 215 197 static inline int phy_power_off(struct phy *phy) 216 198 { 217 199 return -ENOSYS; 200 + } 201 + 202 + static inline int phy_get_bus_width(struct phy *phy) 203 + { 204 + return -ENOSYS; 205 + } 206 + 207 + static inline void phy_set_bus_width(struct phy *phy, int bus_width) 208 + { 209 + return; 218 210 } 219 211 220 212 static inline struct phy *phy_get(struct device *dev, const char *string)
+53
include/linux/platform_data/usb-omap1.h
··· 1 + /* 2 + * Platform data for OMAP1 USB 3 + * 4 + * This file is subject to the terms and conditions of the GNU General Public 5 + * License. See the file "COPYING" in the main directory of this archive for 6 + * more details. 7 + */ 8 + #ifndef __LINUX_USB_OMAP1_H 9 + #define __LINUX_USB_OMAP1_H 10 + 11 + #include <linux/platform_device.h> 12 + 13 + struct omap_usb_config { 14 + /* Configure drivers according to the connectors on your board: 15 + * - "A" connector (rectagular) 16 + * ... for host/OHCI use, set "register_host". 17 + * - "B" connector (squarish) or "Mini-B" 18 + * ... for device/gadget use, set "register_dev". 19 + * - "Mini-AB" connector (very similar to Mini-B) 20 + * ... for OTG use as device OR host, initialize "otg" 21 + */ 22 + unsigned register_host:1; 23 + unsigned register_dev:1; 24 + u8 otg; /* port number, 1-based: usb1 == 2 */ 25 + 26 + const char *extcon; /* extcon device for OTG */ 27 + 28 + u8 hmc_mode; 29 + 30 + /* implicitly true if otg: host supports remote wakeup? */ 31 + u8 rwc; 32 + 33 + /* signaling pins used to talk to transceiver on usbN: 34 + * 0 == usbN unused 35 + * 2 == usb0-only, using internal transceiver 36 + * 3 == 3 wire bidirectional 37 + * 4 == 4 wire bidirectional 38 + * 6 == 6 wire unidirectional (or TLL) 39 + */ 40 + u8 pins[3]; 41 + 42 + struct platform_device *udc_device; 43 + struct platform_device *ohci_device; 44 + struct platform_device *otg_device; 45 + 46 + u32 (*usb0_init)(unsigned nwires, unsigned is_device); 47 + u32 (*usb1_init)(unsigned nwires); 48 + u32 (*usb2_init)(unsigned nwires, unsigned alt_pingroup); 49 + 50 + int (*ocpi_enable)(void); 51 + }; 52 + 53 + #endif /* __LINUX_USB_OMAP1_H */
+2
include/linux/usb/composite.h
··· 468 468 struct config_group group; 469 469 struct list_head cfs_list; 470 470 struct usb_function_driver *fd; 471 + int (*set_inst_name)(struct usb_function_instance *inst, 472 + const char *name); 471 473 void (*free_func_inst)(struct usb_function_instance *inst); 472 474 }; 473 475
-30
include/linux/usb/functionfs.h
··· 3 3 4 4 #include <uapi/linux/usb/functionfs.h> 5 5 6 - 7 - struct ffs_data; 8 - struct usb_composite_dev; 9 - struct usb_configuration; 10 - 11 - 12 - static int functionfs_init(void) __attribute__((warn_unused_result)); 13 - static void functionfs_cleanup(void); 14 - 15 - static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) 16 - __attribute__((warn_unused_result, nonnull)); 17 - static void functionfs_unbind(struct ffs_data *ffs) 18 - __attribute__((nonnull)); 19 - 20 - static int functionfs_bind_config(struct usb_composite_dev *cdev, 21 - struct usb_configuration *c, 22 - struct ffs_data *ffs) 23 - __attribute__((warn_unused_result, nonnull)); 24 - 25 - 26 - static int functionfs_ready_callback(struct ffs_data *ffs) 27 - __attribute__((warn_unused_result, nonnull)); 28 - static void functionfs_closed_callback(struct ffs_data *ffs) 29 - __attribute__((nonnull)); 30 - static void *functionfs_acquire_dev_callback(const char *dev_name) 31 - __attribute__((warn_unused_result, nonnull)); 32 - static void functionfs_release_dev_callback(struct ffs_data *ffs_data) 33 - __attribute__((nonnull)); 34 - 35 - 36 6 #endif
+49 -9
include/linux/usb/gadget.h
··· 148 148 * @maxpacket:The maximum packet size used on this endpoint. The initial 149 149 * value can sometimes be reduced (hardware allowing), according to 150 150 * the endpoint descriptor used to configure the endpoint. 151 + * @maxpacket_limit:The maximum packet size value which can be handled by this 152 + * endpoint. It's set once by UDC driver when endpoint is initialized, and 153 + * should not be changed. Should not be confused with maxpacket. 151 154 * @max_streams: The maximum number of streams supported 152 155 * by this EP (0 - 16, actual number is 2^n) 153 156 * @mult: multiplier, 'mult' value for SS Isoc EPs ··· 174 171 const struct usb_ep_ops *ops; 175 172 struct list_head ep_list; 176 173 unsigned maxpacket:16; 174 + unsigned maxpacket_limit:16; 177 175 unsigned max_streams:16; 178 176 unsigned mult:2; 179 177 unsigned maxburst:5; ··· 184 180 }; 185 181 186 182 /*-------------------------------------------------------------------------*/ 183 + 184 + /** 185 + * usb_ep_set_maxpacket_limit - set maximum packet size limit for endpoint 186 + * @ep:the endpoint being configured 187 + * @maxpacket_limit:value of maximum packet size limit 188 + * 189 + * This function shoud be used only in UDC drivers to initialize endpoint 190 + * (usually in probe function). 191 + */ 192 + static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep, 193 + unsigned maxpacket_limit) 194 + { 195 + ep->maxpacket_limit = maxpacket_limit; 196 + ep->maxpacket = maxpacket_limit; 197 + } 187 198 188 199 /** 189 200 * usb_ep_enable - configure endpoint, making it usable ··· 504 485 * @max_speed: Maximal speed the UDC can handle. UDC must support this 505 486 * and all slower speeds. 506 487 * @state: the state we are now (attached, suspended, configured, etc) 488 + * @name: Identifies the controller hardware type. Used in diagnostics 489 + * and sometimes configuration. 490 + * @dev: Driver model state for this abstract device. 491 + * @out_epnum: last used out ep number 492 + * @in_epnum: last used in ep number 507 493 * @sg_supported: true if we can handle scatter-gather 508 494 * @is_otg: True if the USB device port uses a Mini-AB jack, so that the 509 495 * gadget driver must provide a USB OTG descriptor. ··· 521 497 * only supports HNP on a different root port. 522 498 * @b_hnp_enable: OTG device feature flag, indicating that the A-Host 523 499 * enabled HNP support. 524 - * @name: Identifies the controller hardware type. Used in diagnostics 525 - * and sometimes configuration. 526 - * @dev: Driver model state for this abstract device. 527 - * @out_epnum: last used out ep number 528 - * @in_epnum: last used in ep number 500 + * @quirk_ep_out_aligned_size: epout requires buffer size to be aligned to 501 + * MaxPacketSize. 529 502 * 530 503 * Gadgets have a mostly-portable "gadget driver" implementing device 531 504 * functions, handling all usb configurations and interfaces. Gadget ··· 551 530 enum usb_device_speed speed; 552 531 enum usb_device_speed max_speed; 553 532 enum usb_device_state state; 533 + const char *name; 534 + struct device dev; 535 + unsigned out_epnum; 536 + unsigned in_epnum; 537 + 554 538 unsigned sg_supported:1; 555 539 unsigned is_otg:1; 556 540 unsigned is_a_peripheral:1; 557 541 unsigned b_hnp_enable:1; 558 542 unsigned a_hnp_support:1; 559 543 unsigned a_alt_hnp_support:1; 560 - const char *name; 561 - struct device dev; 562 - unsigned out_epnum; 563 - unsigned in_epnum; 544 + unsigned quirk_ep_out_aligned_size:1; 564 545 }; 565 546 #define work_to_gadget(w) (container_of((w), struct usb_gadget, work)) 566 547 ··· 579 556 #define gadget_for_each_ep(tmp, gadget) \ 580 557 list_for_each_entry(tmp, &(gadget)->ep_list, ep_list) 581 558 559 + 560 + /** 561 + * usb_ep_align_maybe - returns @len aligned to ep's maxpacketsize if gadget 562 + * requires quirk_ep_out_aligned_size, otherwise reguens len. 563 + * @g: controller to check for quirk 564 + * @ep: the endpoint whose maxpacketsize is used to align @len 565 + * @len: buffer size's length to align to @ep's maxpacketsize 566 + * 567 + * This helper is used in case it's required for any reason to check and maybe 568 + * align buffer's size to an ep's maxpacketsize. 569 + */ 570 + static inline size_t 571 + usb_ep_align_maybe(struct usb_gadget *g, struct usb_ep *ep, size_t len) 572 + { 573 + return !g->quirk_ep_out_aligned_size ? len : 574 + round_up(len, (size_t)ep->desc->wMaxPacketSize); 575 + } 582 576 583 577 /** 584 578 * gadget_is_dualspeed - return true iff the hardware handles high speed
+3
include/linux/usb/musb.h
··· 76 76 unsigned dma:1 __deprecated; /* supports DMA */ 77 77 unsigned vendor_req:1 __deprecated; /* vendor registers required */ 78 78 79 + /* need to explicitly de-assert the port reset after resume? */ 80 + unsigned host_port_deassert_reset_at_resume:1; 81 + 79 82 u8 num_eps; /* number of endpoints _with_ ep0 */ 80 83 u8 dma_channels __deprecated; /* number of dma channels */ 81 84 u8 dyn_fifo_size; /* dynamic size in bytes */
+6
include/linux/usb/omap_control_usb.h
··· 24 24 OMAP_CTRL_TYPE_USB2, /* USB2_PHY, power down in CONTROL_DEV_CONF */ 25 25 OMAP_CTRL_TYPE_PIPE3, /* PIPE3 PHY, DPLL & seperate Rx/Tx power */ 26 26 OMAP_CTRL_TYPE_DRA7USB2, /* USB2 PHY, power and power_aux e.g. DRA7 */ 27 + OMAP_CTRL_TYPE_AM437USB2, /* USB2 PHY, power e.g. AM437x */ 27 28 }; 28 29 29 30 struct omap_control_usb { ··· 64 63 #define OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF 0x0 65 64 66 65 #define OMAP_CTRL_USB2_PHY_PD BIT(28) 66 + 67 + #define AM437X_CTRL_USB2_PHY_PD BIT(0) 68 + #define AM437X_CTRL_USB2_OTG_PD BIT(1) 69 + #define AM437X_CTRL_USB2_OTGVDET_EN BIT(19) 70 + #define AM437X_CTRL_USB2_OTGSESSEND_EN BIT(20) 67 71 68 72 #if IS_ENABLED(CONFIG_OMAP_CONTROL_USB) 69 73 extern void omap_control_usb_phy_power(struct device *dev, int on);