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

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

Felipe writes:

usb: patches for v4.2 merge window

- dwc2 adds hibernation support
- preparation for sunxi glue to musb driver
- new ULPI bus
- new ULPI PHY driver for TUSB1210
- musb patches to support multiple DMA engines on same binary
- support for R-Car E2 on renesas_usbhs

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

+3969 -1433
+10
Documentation/devicetree/bindings/power/twl-charger.txt
··· 1 1 TWL BCI (Battery Charger Interface) 2 2 3 + The battery charger needs to interact with the USB phy in order 4 + to know when charging is permissible, and when there is a connection 5 + or disconnection. 6 + 7 + The choice of phy cannot be configured at a hardware level, so there 8 + is no value in explicit configuration in device-tree. Rather 9 + if there is a sibling of the BCI node which is compatible with 10 + "ti,twl4030-usb", then that is used to determine when and how 11 + use USB power for charging. 12 + 3 13 Required properties: 4 14 - compatible: 5 15 - "ti,twl4030-bci"
+3 -4
Documentation/devicetree/bindings/usb/dwc3-st.txt
··· 49 49 st,syscfg = <&syscfg_core>; 50 50 resets = <&powerdown STIH407_USB3_POWERDOWN>, 51 51 <&softreset STIH407_MIPHY2_SOFTRESET>; 52 - reset-names = "powerdown", 53 - "softreset"; 52 + reset-names = "powerdown", "softreset"; 54 53 #address-cells = <1>; 55 54 #size-cells = <1>; 56 55 pinctrl-names = "default"; ··· 61 62 reg = <0x09900000 0x100000>; 62 63 interrupts = <GIC_SPI 155 IRQ_TYPE_NONE>; 63 64 dr_mode = "host"; 64 - phys-names = "usb2-phy", "usb3-phy"; 65 - phys = <&usb2_picophy2>, <&phy_port2 MIPHY_TYPE_USB>; 65 + phy-names = "usb2-phy", "usb3-phy"; 66 + phys = <&usb2_picophy2>, <&phy_port2 PHY_TYPE_USB3>; 66 67 }; 67 68 };
+2
Documentation/devicetree/bindings/usb/dwc3.txt
··· 38 38 - snps,is-utmi-l1-suspend: true when DWC3 asserts output signal 39 39 utmi_l1_suspend_n, false when asserts utmi_sleep_n 40 40 - snps,hird-threshold: HIRD threshold 41 + - snps,hsphy_interface: High-Speed PHY interface selection between "utmi" for 42 + UTMI+ and "ulpi" for ULPI when the DWC_USB3_HSPHY_INTERFACE has value 3. 41 43 42 44 This is usually a subnode to DWC3 glue to which it is connected. 43 45
+11
Documentation/devicetree/bindings/usb/msm-hsusb.txt
··· 69 69 (no, min, max) where each value represents either a voltage 70 70 in microvolts or a value corresponding to voltage corner. 71 71 72 + - qcom,manual-pullup: If present, vbus is not routed to USB controller/phy 73 + and controller driver therefore enables pull-up explicitly 74 + before starting controller using usbcmd run/stop bit. 75 + 76 + - extcon: phandles to external connector devices. First phandle 77 + should point to external connector, which provide "USB" 78 + cable events, the second should point to external connector 79 + device, which provide "USB-HOST" cable events. If one of 80 + the external connector devices is not required empty <0> 81 + phandle should be specified. 82 + 72 83 Example HSUSB OTG controller device node: 73 84 74 85 usb@f9a55000 {
+3 -4
Documentation/devicetree/bindings/usb/renesas_usbhs.txt
··· 4 4 - compatible: Must contain one of the following: 5 5 - "renesas,usbhs-r8a7790" 6 6 - "renesas,usbhs-r8a7791" 7 + - "renesas,usbhs-r8a7794" 7 8 - reg: Base address and length of the register for the USBHS 8 9 - interrupts: Interrupt specifier for the USBHS 9 10 - clocks: A list of phandle + clock specifier pairs ··· 16 15 - phys: phandle + phy specifier pair 17 16 - phy-names: must be "usb" 18 17 - dmas: Must contain a list of references to DMA specifiers. 19 - - dma-names : Must contain a list of DMA names: 20 - - tx0 ... tx<n> 21 - - rx0 ... rx<n> 22 - - This <n> means DnFIFO in USBHS module. 18 + - dma-names : named "ch%d", where %d is the channel number ranging from zero 19 + to the number of channels (DnFIFOs) minus one. 23 20 24 21 Example: 25 22 usbhs: usb@e6590000 {
+3
Documentation/devicetree/bindings/usb/twlxxxx-usb.txt
··· 30 30 - usb_mode : The mode used by the phy to connect to the controller. "1" 31 31 specifies "ULPI" mode and "2" specifies "CEA2011_3PIN" mode. 32 32 33 + If a sibling node is compatible "ti,twl4030-bci", then it will find 34 + this device and query it for USB power status. 35 + 33 36 twl4030-usb { 34 37 compatible = "ti,twl4030-usb"; 35 38 interrupts = < 10 4 >;
+1 -3
Documentation/usb/gadget-testing.txt
··· 526 526 configuration. The ifname is read-only and contains the name of the interface 527 527 which was assigned by the net core, e. g. usb0. 528 528 529 - By default there can be only 1 RNDIS interface in the system. 530 - 531 529 Testing the RNDIS function 532 530 -------------------------- 533 531 ··· 627 629 The function name to use when creating the function directory is "uac2". 628 630 The uac2 function provides these attributes in its function directory: 629 631 630 - chmask - capture channel mask 632 + c_chmask - capture channel mask 631 633 c_srate - capture sampling rate 632 634 c_ssize - capture sample size (bytes) 633 635 p_chmask - playback channel mask
+7
MAINTAINERS
··· 10489 10489 F: Documentation/video4linux/zr364xx.txt 10490 10490 F: drivers/media/usb/zr364xx/ 10491 10491 10492 + ULPI BUS 10493 + M: Heikki Krogerus <heikki.krogerus@linux.intel.com> 10494 + L: linux-usb@vger.kernel.org 10495 + S: Maintained 10496 + F: drivers/usb/common/ulpi.c 10497 + F: include/linux/ulpi/ 10498 + 10492 10499 USER-MODE LINUX (UML) 10493 10500 M: Jeff Dike <jdike@addtoit.com> 10494 10501 M: Richard Weinberger <richard@nod.at>
+7
drivers/phy/Kconfig
··· 309 309 help 310 310 Support for UFS PHY on QCOM chipsets. 311 311 312 + config PHY_TUSB1210 313 + tristate "TI TUSB1210 ULPI PHY module" 314 + depends on USB_ULPI_BUS 315 + select GENERIC_PHY 316 + help 317 + Support for TI TUSB1210 USB ULPI PHY. 318 + 312 319 endmenu
+1
drivers/phy/Makefile
··· 40 40 obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs.o 41 41 obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs-qmp-20nm.o 42 42 obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs-qmp-14nm.o 43 + obj-$(CONFIG_PHY_TUSB1210) += phy-tusb1210.o
+9
drivers/phy/phy-sun4i-usb.c
··· 30 30 #include <linux/of.h> 31 31 #include <linux/of_address.h> 32 32 #include <linux/phy/phy.h> 33 + #include <linux/phy/phy-sun4i-usb.h> 33 34 #include <linux/platform_device.h> 34 35 #include <linux/regulator/consumer.h> 35 36 #include <linux/reset.h> ··· 59 58 #define PHY_OTG_FUNC_EN 0x28 60 59 #define PHY_VBUS_DET_EN 0x29 61 60 #define PHY_DISCON_TH_SEL 0x2a 61 + #define PHY_SQUELCH_DETECT 0x3c 62 62 63 63 #define MAX_PHYS 3 64 64 ··· 204 202 regulator_disable(phy->vbus); 205 203 206 204 return 0; 205 + } 206 + 207 + void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled) 208 + { 209 + struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); 210 + 211 + sun4i_usb_phy_write(phy, PHY_SQUELCH_DETECT, enabled ? 0 : 2, 2); 207 212 } 208 213 209 214 static struct phy_ops sun4i_usb_phy_ops = {
+153
drivers/phy/phy-tusb1210.c
··· 1 + /** 2 + * tusb1210.c - TUSB1210 USB ULPI PHY driver 3 + * 4 + * Copyright (C) 2015 Intel Corporation 5 + * 6 + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.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 as 10 + * published by the Free Software Foundation. 11 + */ 12 + #include <linux/module.h> 13 + #include <linux/ulpi/driver.h> 14 + #include <linux/gpio/consumer.h> 15 + 16 + #include "ulpi_phy.h" 17 + 18 + #define TUSB1210_VENDOR_SPECIFIC2 0x80 19 + #define TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT 0 20 + #define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT 4 21 + #define TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT 6 22 + 23 + struct tusb1210 { 24 + struct ulpi *ulpi; 25 + struct phy *phy; 26 + struct gpio_desc *gpio_reset; 27 + struct gpio_desc *gpio_cs; 28 + u8 vendor_specific2; 29 + }; 30 + 31 + static int tusb1210_power_on(struct phy *phy) 32 + { 33 + struct tusb1210 *tusb = phy_get_drvdata(phy); 34 + 35 + gpiod_set_value_cansleep(tusb->gpio_reset, 1); 36 + gpiod_set_value_cansleep(tusb->gpio_cs, 1); 37 + 38 + /* Restore the optional eye diagram optimization value */ 39 + if (tusb->vendor_specific2) 40 + ulpi_write(tusb->ulpi, TUSB1210_VENDOR_SPECIFIC2, 41 + tusb->vendor_specific2); 42 + 43 + return 0; 44 + } 45 + 46 + static int tusb1210_power_off(struct phy *phy) 47 + { 48 + struct tusb1210 *tusb = phy_get_drvdata(phy); 49 + 50 + gpiod_set_value_cansleep(tusb->gpio_reset, 0); 51 + gpiod_set_value_cansleep(tusb->gpio_cs, 0); 52 + 53 + return 0; 54 + } 55 + 56 + static struct phy_ops phy_ops = { 57 + .power_on = tusb1210_power_on, 58 + .power_off = tusb1210_power_off, 59 + .owner = THIS_MODULE, 60 + }; 61 + 62 + static int tusb1210_probe(struct ulpi *ulpi) 63 + { 64 + struct gpio_desc *gpio; 65 + struct tusb1210 *tusb; 66 + u8 val, reg; 67 + int ret; 68 + 69 + tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL); 70 + if (!tusb) 71 + return -ENOMEM; 72 + 73 + gpio = devm_gpiod_get(&ulpi->dev, "reset"); 74 + if (!IS_ERR(gpio)) { 75 + ret = gpiod_direction_output(gpio, 0); 76 + if (ret) 77 + return ret; 78 + gpiod_set_value_cansleep(gpio, 1); 79 + tusb->gpio_reset = gpio; 80 + } 81 + 82 + gpio = devm_gpiod_get(&ulpi->dev, "cs"); 83 + if (!IS_ERR(gpio)) { 84 + ret = gpiod_direction_output(gpio, 0); 85 + if (ret) 86 + return ret; 87 + gpiod_set_value_cansleep(gpio, 1); 88 + tusb->gpio_cs = gpio; 89 + } 90 + 91 + /* 92 + * VENDOR_SPECIFIC2 register in TUSB1210 can be used for configuring eye 93 + * diagram optimization and DP/DM swap. 94 + */ 95 + 96 + /* High speed output drive strength configuration */ 97 + device_property_read_u8(&ulpi->dev, "ihstx", &val); 98 + reg = val << TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT; 99 + 100 + /* High speed output impedance configuration */ 101 + device_property_read_u8(&ulpi->dev, "zhsdrv", &val); 102 + reg |= val << TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT; 103 + 104 + /* DP/DM swap control */ 105 + device_property_read_u8(&ulpi->dev, "datapolarity", &val); 106 + reg |= val << TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT; 107 + 108 + if (reg) { 109 + ulpi_write(ulpi, TUSB1210_VENDOR_SPECIFIC2, reg); 110 + tusb->vendor_specific2 = reg; 111 + } 112 + 113 + tusb->phy = ulpi_phy_create(ulpi, &phy_ops); 114 + if (IS_ERR(tusb->phy)) 115 + return PTR_ERR(tusb->phy); 116 + 117 + tusb->ulpi = ulpi; 118 + 119 + phy_set_drvdata(tusb->phy, tusb); 120 + ulpi_set_drvdata(ulpi, tusb); 121 + return 0; 122 + } 123 + 124 + static void tusb1210_remove(struct ulpi *ulpi) 125 + { 126 + struct tusb1210 *tusb = ulpi_get_drvdata(ulpi); 127 + 128 + ulpi_phy_destroy(ulpi, tusb->phy); 129 + } 130 + 131 + #define TI_VENDOR_ID 0x0451 132 + 133 + static const struct ulpi_device_id tusb1210_ulpi_id[] = { 134 + { TI_VENDOR_ID, 0x1507, }, 135 + { }, 136 + }; 137 + MODULE_DEVICE_TABLE(ulpi, tusb1210_ulpi_id); 138 + 139 + static struct ulpi_driver tusb1210_driver = { 140 + .id_table = tusb1210_ulpi_id, 141 + .probe = tusb1210_probe, 142 + .remove = tusb1210_remove, 143 + .driver = { 144 + .name = "tusb1210", 145 + .owner = THIS_MODULE, 146 + }, 147 + }; 148 + 149 + module_ulpi_driver(tusb1210_driver); 150 + 151 + MODULE_AUTHOR("Intel Corporation"); 152 + MODULE_LICENSE("GPL v2"); 153 + MODULE_DESCRIPTION("TUSB1210 ULPI PHY driver");
+31
drivers/phy/ulpi_phy.h
··· 1 + #include <linux/phy/phy.h> 2 + 3 + /** 4 + * Helper that registers PHY for a ULPI device and adds a lookup for binding it 5 + * and it's controller, which is always the parent. 6 + */ 7 + static inline struct phy 8 + *ulpi_phy_create(struct ulpi *ulpi, struct phy_ops *ops) 9 + { 10 + struct phy *phy; 11 + int ret; 12 + 13 + phy = phy_create(&ulpi->dev, NULL, ops); 14 + if (IS_ERR(phy)) 15 + return phy; 16 + 17 + ret = phy_create_lookup(phy, "usb2-phy", dev_name(ulpi->dev.parent)); 18 + if (ret) { 19 + phy_destroy(phy); 20 + return ERR_PTR(ret); 21 + } 22 + 23 + return phy; 24 + } 25 + 26 + /* Remove a PHY that was created with ulpi_phy_create() and it's lookup. */ 27 + static inline void ulpi_phy_destroy(struct ulpi *ulpi, struct phy *phy) 28 + { 29 + phy_remove_lookup(phy, "usb2-phy", dev_name(ulpi->dev.parent)); 30 + phy_destroy(phy); 31 + }
+9 -12
drivers/power/twl4030_charger.c
··· 638 638 639 639 INIT_WORK(&bci->work, twl4030_bci_usb_work); 640 640 641 - bci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); 642 - if (!IS_ERR_OR_NULL(bci->transceiver)) { 643 - bci->usb_nb.notifier_call = twl4030_bci_usb_ncb; 644 - usb_register_notifier(bci->transceiver, &bci->usb_nb); 641 + bci->usb_nb.notifier_call = twl4030_bci_usb_ncb; 642 + if (bci->dev->of_node) { 643 + struct device_node *phynode; 644 + 645 + phynode = of_find_compatible_node(bci->dev->of_node->parent, 646 + NULL, "ti,twl4030-usb"); 647 + if (phynode) 648 + bci->transceiver = devm_usb_get_phy_by_node( 649 + bci->dev, phynode, &bci->usb_nb); 645 650 } 646 651 647 652 /* Enable interrupts now. */ ··· 676 671 return 0; 677 672 678 673 fail_unmask_interrupts: 679 - if (!IS_ERR_OR_NULL(bci->transceiver)) { 680 - usb_unregister_notifier(bci->transceiver, &bci->usb_nb); 681 - usb_put_phy(bci->transceiver); 682 - } 683 674 free_irq(bci->irq_bci, bci); 684 675 fail_bci_irq: 685 676 free_irq(bci->irq_chg, bci); ··· 704 703 twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff, 705 704 TWL4030_INTERRUPTS_BCIIMR2A); 706 705 707 - if (!IS_ERR_OR_NULL(bci->transceiver)) { 708 - usb_unregister_notifier(bci->transceiver, &bci->usb_nb); 709 - usb_put_phy(bci->transceiver); 710 - } 711 706 free_irq(bci->irq_bci, bci); 712 707 free_irq(bci->irq_chg, bci); 713 708 power_supply_unregister(bci->usb);
+1
drivers/usb/common/Makefile
··· 7 7 usb-common-$(CONFIG_USB_LED_TRIG) += led.o 8 8 9 9 obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o 10 + obj-$(CONFIG_USB_ULPI_BUS) += ulpi.o
+255
drivers/usb/common/ulpi.c
··· 1 + /** 2 + * ulpi.c - USB ULPI PHY bus 3 + * 4 + * Copyright (C) 2015 Intel Corporation 5 + * 6 + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.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 as 10 + * published by the Free Software Foundation. 11 + */ 12 + 13 + #include <linux/ulpi/interface.h> 14 + #include <linux/ulpi/driver.h> 15 + #include <linux/ulpi/regs.h> 16 + #include <linux/module.h> 17 + #include <linux/slab.h> 18 + #include <linux/acpi.h> 19 + 20 + /* -------------------------------------------------------------------------- */ 21 + 22 + int ulpi_read(struct ulpi *ulpi, u8 addr) 23 + { 24 + return ulpi->ops->read(ulpi->ops, addr); 25 + } 26 + EXPORT_SYMBOL_GPL(ulpi_read); 27 + 28 + int ulpi_write(struct ulpi *ulpi, u8 addr, u8 val) 29 + { 30 + return ulpi->ops->write(ulpi->ops, addr, val); 31 + } 32 + EXPORT_SYMBOL_GPL(ulpi_write); 33 + 34 + /* -------------------------------------------------------------------------- */ 35 + 36 + static int ulpi_match(struct device *dev, struct device_driver *driver) 37 + { 38 + struct ulpi_driver *drv = to_ulpi_driver(driver); 39 + struct ulpi *ulpi = to_ulpi_dev(dev); 40 + const struct ulpi_device_id *id; 41 + 42 + for (id = drv->id_table; id->vendor; id++) 43 + if (id->vendor == ulpi->id.vendor && 44 + id->product == ulpi->id.product) 45 + return 1; 46 + 47 + return 0; 48 + } 49 + 50 + static int ulpi_uevent(struct device *dev, struct kobj_uevent_env *env) 51 + { 52 + struct ulpi *ulpi = to_ulpi_dev(dev); 53 + 54 + if (add_uevent_var(env, "MODALIAS=ulpi:v%04xp%04x", 55 + ulpi->id.vendor, ulpi->id.product)) 56 + return -ENOMEM; 57 + return 0; 58 + } 59 + 60 + static int ulpi_probe(struct device *dev) 61 + { 62 + struct ulpi_driver *drv = to_ulpi_driver(dev->driver); 63 + 64 + return drv->probe(to_ulpi_dev(dev)); 65 + } 66 + 67 + static int ulpi_remove(struct device *dev) 68 + { 69 + struct ulpi_driver *drv = to_ulpi_driver(dev->driver); 70 + 71 + if (drv->remove) 72 + drv->remove(to_ulpi_dev(dev)); 73 + 74 + return 0; 75 + } 76 + 77 + static struct bus_type ulpi_bus = { 78 + .name = "ulpi", 79 + .match = ulpi_match, 80 + .uevent = ulpi_uevent, 81 + .probe = ulpi_probe, 82 + .remove = ulpi_remove, 83 + }; 84 + 85 + /* -------------------------------------------------------------------------- */ 86 + 87 + static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, 88 + char *buf) 89 + { 90 + struct ulpi *ulpi = to_ulpi_dev(dev); 91 + 92 + return sprintf(buf, "ulpi:v%04xp%04x\n", 93 + ulpi->id.vendor, ulpi->id.product); 94 + } 95 + static DEVICE_ATTR_RO(modalias); 96 + 97 + static struct attribute *ulpi_dev_attrs[] = { 98 + &dev_attr_modalias.attr, 99 + NULL 100 + }; 101 + 102 + static struct attribute_group ulpi_dev_attr_group = { 103 + .attrs = ulpi_dev_attrs, 104 + }; 105 + 106 + static const struct attribute_group *ulpi_dev_attr_groups[] = { 107 + &ulpi_dev_attr_group, 108 + NULL 109 + }; 110 + 111 + static void ulpi_dev_release(struct device *dev) 112 + { 113 + kfree(to_ulpi_dev(dev)); 114 + } 115 + 116 + static struct device_type ulpi_dev_type = { 117 + .name = "ulpi_device", 118 + .groups = ulpi_dev_attr_groups, 119 + .release = ulpi_dev_release, 120 + }; 121 + 122 + /* -------------------------------------------------------------------------- */ 123 + 124 + /** 125 + * ulpi_register_driver - register a driver with the ULPI bus 126 + * @drv: driver being registered 127 + * 128 + * Registers a driver with the ULPI bus. 129 + */ 130 + int ulpi_register_driver(struct ulpi_driver *drv) 131 + { 132 + if (!drv->probe) 133 + return -EINVAL; 134 + 135 + drv->driver.bus = &ulpi_bus; 136 + 137 + return driver_register(&drv->driver); 138 + } 139 + EXPORT_SYMBOL_GPL(ulpi_register_driver); 140 + 141 + /** 142 + * ulpi_unregister_driver - unregister a driver with the ULPI bus 143 + * @drv: driver to unregister 144 + * 145 + * Unregisters a driver with the ULPI bus. 146 + */ 147 + void ulpi_unregister_driver(struct ulpi_driver *drv) 148 + { 149 + driver_unregister(&drv->driver); 150 + } 151 + EXPORT_SYMBOL_GPL(ulpi_unregister_driver); 152 + 153 + /* -------------------------------------------------------------------------- */ 154 + 155 + static int ulpi_register(struct device *dev, struct ulpi *ulpi) 156 + { 157 + int ret; 158 + 159 + /* Test the interface */ 160 + ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa); 161 + if (ret < 0) 162 + return ret; 163 + 164 + ret = ulpi_read(ulpi, ULPI_SCRATCH); 165 + if (ret < 0) 166 + return ret; 167 + 168 + if (ret != 0xaa) 169 + return -ENODEV; 170 + 171 + ulpi->id.vendor = ulpi_read(ulpi, ULPI_VENDOR_ID_LOW); 172 + ulpi->id.vendor |= ulpi_read(ulpi, ULPI_VENDOR_ID_HIGH) << 8; 173 + 174 + ulpi->id.product = ulpi_read(ulpi, ULPI_PRODUCT_ID_LOW); 175 + ulpi->id.product |= ulpi_read(ulpi, ULPI_PRODUCT_ID_HIGH) << 8; 176 + 177 + ulpi->dev.parent = dev; 178 + ulpi->dev.bus = &ulpi_bus; 179 + ulpi->dev.type = &ulpi_dev_type; 180 + dev_set_name(&ulpi->dev, "%s.ulpi", dev_name(dev)); 181 + 182 + ACPI_COMPANION_SET(&ulpi->dev, ACPI_COMPANION(dev)); 183 + 184 + request_module("ulpi:v%04xp%04x", ulpi->id.vendor, ulpi->id.product); 185 + 186 + ret = device_register(&ulpi->dev); 187 + if (ret) 188 + return ret; 189 + 190 + dev_dbg(&ulpi->dev, "registered ULPI PHY: vendor %04x, product %04x\n", 191 + ulpi->id.vendor, ulpi->id.product); 192 + 193 + return 0; 194 + } 195 + 196 + /** 197 + * ulpi_register_interface - instantiate new ULPI device 198 + * @dev: USB controller's device interface 199 + * @ops: ULPI register access 200 + * 201 + * Allocates and registers a ULPI device and an interface for it. Called from 202 + * the USB controller that provides the ULPI interface. 203 + */ 204 + struct ulpi *ulpi_register_interface(struct device *dev, struct ulpi_ops *ops) 205 + { 206 + struct ulpi *ulpi; 207 + int ret; 208 + 209 + ulpi = kzalloc(sizeof(*ulpi), GFP_KERNEL); 210 + if (!ulpi) 211 + return ERR_PTR(-ENOMEM); 212 + 213 + ulpi->ops = ops; 214 + ops->dev = dev; 215 + 216 + ret = ulpi_register(dev, ulpi); 217 + if (ret) { 218 + kfree(ulpi); 219 + return ERR_PTR(ret); 220 + } 221 + 222 + return ulpi; 223 + } 224 + EXPORT_SYMBOL_GPL(ulpi_register_interface); 225 + 226 + /** 227 + * ulpi_unregister_interface - unregister ULPI interface 228 + * @intrf: struct ulpi_interface 229 + * 230 + * Unregisters a ULPI device and it's interface that was created with 231 + * ulpi_create_interface(). 232 + */ 233 + void ulpi_unregister_interface(struct ulpi *ulpi) 234 + { 235 + device_unregister(&ulpi->dev); 236 + } 237 + EXPORT_SYMBOL_GPL(ulpi_unregister_interface); 238 + 239 + /* -------------------------------------------------------------------------- */ 240 + 241 + static int __init ulpi_init(void) 242 + { 243 + return bus_register(&ulpi_bus); 244 + } 245 + module_init(ulpi_init); 246 + 247 + static void __exit ulpi_exit(void) 248 + { 249 + bus_unregister(&ulpi_bus); 250 + } 251 + module_exit(ulpi_exit); 252 + 253 + MODULE_AUTHOR("Intel Corporation"); 254 + MODULE_LICENSE("GPL v2"); 255 + MODULE_DESCRIPTION("USB ULPI PHY bus");
+20
drivers/usb/core/Kconfig
··· 84 84 Implements OTG Finite State Machine as specified in On-The-Go 85 85 and Embedded Host Supplement to the USB Revision 2.0 Specification. 86 86 87 + config USB_ULPI_BUS 88 + tristate "USB ULPI PHY interface support" 89 + depends on USB_SUPPORT 90 + help 91 + UTMI+ Low Pin Interface (ULPI) is specification for a commonly used 92 + USB 2.0 PHY interface. The ULPI specification defines a standard set 93 + of registers that can be used to detect the vendor and product which 94 + allows ULPI to be handled as a bus. This module is the driver for that 95 + bus. 96 + 97 + The ULPI interfaces (the buses) are registered by the drivers for USB 98 + controllers which support ULPI register access and have ULPI PHY 99 + attached to them. The ULPI PHY drivers themselves are normal PHY 100 + drivers. 101 + 102 + ULPI PHYs provide often functions such as ADP sensing/probing (OTG 103 + protocol) and USB charger detection. 104 + 105 + To compile this driver as a module, choose M here: the module will 106 + be called ulpi.
-8
drivers/usb/dwc2/Kconfig
··· 50 50 option requires USB_GADGET to be enabled. 51 51 endchoice 52 52 53 - config USB_DWC2_PLATFORM 54 - tristate "DWC2 Platform" 55 - default USB_DWC2_HOST || USB_DWC2_PERIPHERAL 56 - help 57 - The Designware USB2.0 platform interface module for 58 - controllers directly connected to the CPU. 59 - 60 53 config USB_DWC2_PCI 61 54 tristate "DWC2 PCI" 62 55 depends on PCI 63 56 default n 64 - select USB_DWC2_PLATFORM 65 57 select NOP_USB_XCEIV 66 58 help 67 59 The Designware USB2.0 PCI interface module for controllers
+5 -4
drivers/usb/dwc2/Makefile
··· 2 2 ccflags-$(CONFIG_USB_DWC2_VERBOSE) += -DVERBOSE_DEBUG 3 3 4 4 obj-$(CONFIG_USB_DWC2) += dwc2.o 5 - dwc2-y := core.o core_intr.o 5 + dwc2-y := core.o core_intr.o platform.o 6 6 7 7 ifneq ($(filter y,$(CONFIG_USB_DWC2_HOST) $(CONFIG_USB_DWC2_DUAL_ROLE)),) 8 8 dwc2-y += hcd.o hcd_intr.o ··· 13 13 dwc2-y += gadget.o 14 14 endif 15 15 16 + ifneq ($(CONFIG_DEBUG_FS),) 17 + dwc2-y += debugfs.o 18 + endif 19 + 16 20 # NOTE: The previous s3c-hsotg peripheral mode only driver has been moved to 17 21 # this location and renamed gadget.c. When building for dynamically linked 18 22 # modules, dwc2.ko will get built for host mode, peripheral mode, and dual-role ··· 25 21 26 22 obj-$(CONFIG_USB_DWC2_PCI) += dwc2_pci.o 27 23 dwc2_pci-y := pci.o 28 - 29 - obj-$(CONFIG_USB_DWC2_PLATFORM) += dwc2_platform.o 30 - dwc2_platform-y := platform.o
+438 -1
drivers/usb/dwc2/core.c
··· 56 56 #include "core.h" 57 57 #include "hcd.h" 58 58 59 + #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) 60 + /** 61 + * dwc2_backup_host_registers() - Backup controller host registers. 62 + * When suspending usb bus, registers needs to be backuped 63 + * if controller power is disabled once suspended. 64 + * 65 + * @hsotg: Programming view of the DWC_otg controller 66 + */ 67 + static int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg) 68 + { 69 + struct dwc2_hregs_backup *hr; 70 + int i; 71 + 72 + dev_dbg(hsotg->dev, "%s\n", __func__); 73 + 74 + /* Backup Host regs */ 75 + hr = hsotg->hr_backup; 76 + if (!hr) { 77 + hr = devm_kzalloc(hsotg->dev, sizeof(*hr), GFP_KERNEL); 78 + if (!hr) { 79 + dev_err(hsotg->dev, "%s: can't allocate host regs\n", 80 + __func__); 81 + return -ENOMEM; 82 + } 83 + 84 + hsotg->hr_backup = hr; 85 + } 86 + hr->hcfg = readl(hsotg->regs + HCFG); 87 + hr->haintmsk = readl(hsotg->regs + HAINTMSK); 88 + for (i = 0; i < hsotg->core_params->host_channels; ++i) 89 + hr->hcintmsk[i] = readl(hsotg->regs + HCINTMSK(i)); 90 + 91 + hr->hprt0 = readl(hsotg->regs + HPRT0); 92 + hr->hfir = readl(hsotg->regs + HFIR); 93 + 94 + return 0; 95 + } 96 + 97 + /** 98 + * dwc2_restore_host_registers() - Restore controller host registers. 99 + * When resuming usb bus, device registers needs to be restored 100 + * if controller power were disabled. 101 + * 102 + * @hsotg: Programming view of the DWC_otg controller 103 + */ 104 + static int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg) 105 + { 106 + struct dwc2_hregs_backup *hr; 107 + int i; 108 + 109 + dev_dbg(hsotg->dev, "%s\n", __func__); 110 + 111 + /* Restore host regs */ 112 + hr = hsotg->hr_backup; 113 + if (!hr) { 114 + dev_err(hsotg->dev, "%s: no host registers to restore\n", 115 + __func__); 116 + return -EINVAL; 117 + } 118 + 119 + writel(hr->hcfg, hsotg->regs + HCFG); 120 + writel(hr->haintmsk, hsotg->regs + HAINTMSK); 121 + 122 + for (i = 0; i < hsotg->core_params->host_channels; ++i) 123 + writel(hr->hcintmsk[i], hsotg->regs + HCINTMSK(i)); 124 + 125 + writel(hr->hprt0, hsotg->regs + HPRT0); 126 + writel(hr->hfir, hsotg->regs + HFIR); 127 + 128 + return 0; 129 + } 130 + #else 131 + static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg) 132 + { return 0; } 133 + 134 + static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg) 135 + { return 0; } 136 + #endif 137 + 138 + #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \ 139 + IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) 140 + /** 141 + * dwc2_backup_device_registers() - Backup controller device registers. 142 + * When suspending usb bus, registers needs to be backuped 143 + * if controller power is disabled once suspended. 144 + * 145 + * @hsotg: Programming view of the DWC_otg controller 146 + */ 147 + static int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg) 148 + { 149 + struct dwc2_dregs_backup *dr; 150 + int i; 151 + 152 + dev_dbg(hsotg->dev, "%s\n", __func__); 153 + 154 + /* Backup dev regs */ 155 + dr = hsotg->dr_backup; 156 + if (!dr) { 157 + dr = devm_kzalloc(hsotg->dev, sizeof(*dr), GFP_KERNEL); 158 + if (!dr) { 159 + dev_err(hsotg->dev, "%s: can't allocate device regs\n", 160 + __func__); 161 + return -ENOMEM; 162 + } 163 + 164 + hsotg->dr_backup = dr; 165 + } 166 + 167 + dr->dcfg = readl(hsotg->regs + DCFG); 168 + dr->dctl = readl(hsotg->regs + DCTL); 169 + dr->daintmsk = readl(hsotg->regs + DAINTMSK); 170 + dr->diepmsk = readl(hsotg->regs + DIEPMSK); 171 + dr->doepmsk = readl(hsotg->regs + DOEPMSK); 172 + 173 + for (i = 0; i < hsotg->num_of_eps; i++) { 174 + /* Backup IN EPs */ 175 + dr->diepctl[i] = readl(hsotg->regs + DIEPCTL(i)); 176 + 177 + /* Ensure DATA PID is correctly configured */ 178 + if (dr->diepctl[i] & DXEPCTL_DPID) 179 + dr->diepctl[i] |= DXEPCTL_SETD1PID; 180 + else 181 + dr->diepctl[i] |= DXEPCTL_SETD0PID; 182 + 183 + dr->dieptsiz[i] = readl(hsotg->regs + DIEPTSIZ(i)); 184 + dr->diepdma[i] = readl(hsotg->regs + DIEPDMA(i)); 185 + 186 + /* Backup OUT EPs */ 187 + dr->doepctl[i] = readl(hsotg->regs + DOEPCTL(i)); 188 + 189 + /* Ensure DATA PID is correctly configured */ 190 + if (dr->doepctl[i] & DXEPCTL_DPID) 191 + dr->doepctl[i] |= DXEPCTL_SETD1PID; 192 + else 193 + dr->doepctl[i] |= DXEPCTL_SETD0PID; 194 + 195 + dr->doeptsiz[i] = readl(hsotg->regs + DOEPTSIZ(i)); 196 + dr->doepdma[i] = readl(hsotg->regs + DOEPDMA(i)); 197 + } 198 + 199 + return 0; 200 + } 201 + 202 + /** 203 + * dwc2_restore_device_registers() - Restore controller device registers. 204 + * When resuming usb bus, device registers needs to be restored 205 + * if controller power were disabled. 206 + * 207 + * @hsotg: Programming view of the DWC_otg controller 208 + */ 209 + static int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg) 210 + { 211 + struct dwc2_dregs_backup *dr; 212 + u32 dctl; 213 + int i; 214 + 215 + dev_dbg(hsotg->dev, "%s\n", __func__); 216 + 217 + /* Restore dev regs */ 218 + dr = hsotg->dr_backup; 219 + if (!dr) { 220 + dev_err(hsotg->dev, "%s: no device registers to restore\n", 221 + __func__); 222 + return -EINVAL; 223 + } 224 + 225 + writel(dr->dcfg, hsotg->regs + DCFG); 226 + writel(dr->dctl, hsotg->regs + DCTL); 227 + writel(dr->daintmsk, hsotg->regs + DAINTMSK); 228 + writel(dr->diepmsk, hsotg->regs + DIEPMSK); 229 + writel(dr->doepmsk, hsotg->regs + DOEPMSK); 230 + 231 + for (i = 0; i < hsotg->num_of_eps; i++) { 232 + /* Restore IN EPs */ 233 + writel(dr->diepctl[i], hsotg->regs + DIEPCTL(i)); 234 + writel(dr->dieptsiz[i], hsotg->regs + DIEPTSIZ(i)); 235 + writel(dr->diepdma[i], hsotg->regs + DIEPDMA(i)); 236 + 237 + /* Restore OUT EPs */ 238 + writel(dr->doepctl[i], hsotg->regs + DOEPCTL(i)); 239 + writel(dr->doeptsiz[i], hsotg->regs + DOEPTSIZ(i)); 240 + writel(dr->doepdma[i], hsotg->regs + DOEPDMA(i)); 241 + } 242 + 243 + /* Set the Power-On Programming done bit */ 244 + dctl = readl(hsotg->regs + DCTL); 245 + dctl |= DCTL_PWRONPRGDONE; 246 + writel(dctl, hsotg->regs + DCTL); 247 + 248 + return 0; 249 + } 250 + #else 251 + static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg) 252 + { return 0; } 253 + 254 + static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg) 255 + { return 0; } 256 + #endif 257 + 258 + /** 259 + * dwc2_backup_global_registers() - Backup global controller registers. 260 + * When suspending usb bus, registers needs to be backuped 261 + * if controller power is disabled once suspended. 262 + * 263 + * @hsotg: Programming view of the DWC_otg controller 264 + */ 265 + static int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg) 266 + { 267 + struct dwc2_gregs_backup *gr; 268 + int i; 269 + 270 + /* Backup global regs */ 271 + gr = hsotg->gr_backup; 272 + if (!gr) { 273 + gr = devm_kzalloc(hsotg->dev, sizeof(*gr), GFP_KERNEL); 274 + if (!gr) { 275 + dev_err(hsotg->dev, "%s: can't allocate global regs\n", 276 + __func__); 277 + return -ENOMEM; 278 + } 279 + 280 + hsotg->gr_backup = gr; 281 + } 282 + 283 + gr->gotgctl = readl(hsotg->regs + GOTGCTL); 284 + gr->gintmsk = readl(hsotg->regs + GINTMSK); 285 + gr->gahbcfg = readl(hsotg->regs + GAHBCFG); 286 + gr->gusbcfg = readl(hsotg->regs + GUSBCFG); 287 + gr->grxfsiz = readl(hsotg->regs + GRXFSIZ); 288 + gr->gnptxfsiz = readl(hsotg->regs + GNPTXFSIZ); 289 + gr->hptxfsiz = readl(hsotg->regs + HPTXFSIZ); 290 + gr->gdfifocfg = readl(hsotg->regs + GDFIFOCFG); 291 + for (i = 0; i < MAX_EPS_CHANNELS; i++) 292 + gr->dtxfsiz[i] = readl(hsotg->regs + DPTXFSIZN(i)); 293 + 294 + return 0; 295 + } 296 + 297 + /** 298 + * dwc2_restore_global_registers() - Restore controller global registers. 299 + * When resuming usb bus, device registers needs to be restored 300 + * if controller power were disabled. 301 + * 302 + * @hsotg: Programming view of the DWC_otg controller 303 + */ 304 + static int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg) 305 + { 306 + struct dwc2_gregs_backup *gr; 307 + int i; 308 + 309 + dev_dbg(hsotg->dev, "%s\n", __func__); 310 + 311 + /* Restore global regs */ 312 + gr = hsotg->gr_backup; 313 + if (!gr) { 314 + dev_err(hsotg->dev, "%s: no global registers to restore\n", 315 + __func__); 316 + return -EINVAL; 317 + } 318 + 319 + writel(0xffffffff, hsotg->regs + GINTSTS); 320 + writel(gr->gotgctl, hsotg->regs + GOTGCTL); 321 + writel(gr->gintmsk, hsotg->regs + GINTMSK); 322 + writel(gr->gusbcfg, hsotg->regs + GUSBCFG); 323 + writel(gr->gahbcfg, hsotg->regs + GAHBCFG); 324 + writel(gr->grxfsiz, hsotg->regs + GRXFSIZ); 325 + writel(gr->gnptxfsiz, hsotg->regs + GNPTXFSIZ); 326 + writel(gr->hptxfsiz, hsotg->regs + HPTXFSIZ); 327 + writel(gr->gdfifocfg, hsotg->regs + GDFIFOCFG); 328 + for (i = 0; i < MAX_EPS_CHANNELS; i++) 329 + writel(gr->dtxfsiz[i], hsotg->regs + DPTXFSIZN(i)); 330 + 331 + return 0; 332 + } 333 + 334 + /** 335 + * dwc2_exit_hibernation() - Exit controller from Partial Power Down. 336 + * 337 + * @hsotg: Programming view of the DWC_otg controller 338 + * @restore: Controller registers need to be restored 339 + */ 340 + int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore) 341 + { 342 + u32 pcgcctl; 343 + int ret = 0; 344 + 345 + if (!hsotg->core_params->hibernation) 346 + return -ENOTSUPP; 347 + 348 + pcgcctl = readl(hsotg->regs + PCGCTL); 349 + pcgcctl &= ~PCGCTL_STOPPCLK; 350 + writel(pcgcctl, hsotg->regs + PCGCTL); 351 + 352 + pcgcctl = readl(hsotg->regs + PCGCTL); 353 + pcgcctl &= ~PCGCTL_PWRCLMP; 354 + writel(pcgcctl, hsotg->regs + PCGCTL); 355 + 356 + pcgcctl = readl(hsotg->regs + PCGCTL); 357 + pcgcctl &= ~PCGCTL_RSTPDWNMODULE; 358 + writel(pcgcctl, hsotg->regs + PCGCTL); 359 + 360 + udelay(100); 361 + if (restore) { 362 + ret = dwc2_restore_global_registers(hsotg); 363 + if (ret) { 364 + dev_err(hsotg->dev, "%s: failed to restore registers\n", 365 + __func__); 366 + return ret; 367 + } 368 + if (dwc2_is_host_mode(hsotg)) { 369 + ret = dwc2_restore_host_registers(hsotg); 370 + if (ret) { 371 + dev_err(hsotg->dev, "%s: failed to restore host registers\n", 372 + __func__); 373 + return ret; 374 + } 375 + } else { 376 + ret = dwc2_restore_device_registers(hsotg); 377 + if (ret) { 378 + dev_err(hsotg->dev, "%s: failed to restore device registers\n", 379 + __func__); 380 + return ret; 381 + } 382 + } 383 + } 384 + 385 + return ret; 386 + } 387 + 388 + /** 389 + * dwc2_enter_hibernation() - Put controller in Partial Power Down. 390 + * 391 + * @hsotg: Programming view of the DWC_otg controller 392 + */ 393 + int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg) 394 + { 395 + u32 pcgcctl; 396 + int ret = 0; 397 + 398 + if (!hsotg->core_params->hibernation) 399 + return -ENOTSUPP; 400 + 401 + /* Backup all registers */ 402 + ret = dwc2_backup_global_registers(hsotg); 403 + if (ret) { 404 + dev_err(hsotg->dev, "%s: failed to backup global registers\n", 405 + __func__); 406 + return ret; 407 + } 408 + 409 + if (dwc2_is_host_mode(hsotg)) { 410 + ret = dwc2_backup_host_registers(hsotg); 411 + if (ret) { 412 + dev_err(hsotg->dev, "%s: failed to backup host registers\n", 413 + __func__); 414 + return ret; 415 + } 416 + } else { 417 + ret = dwc2_backup_device_registers(hsotg); 418 + if (ret) { 419 + dev_err(hsotg->dev, "%s: failed to backup device registers\n", 420 + __func__); 421 + return ret; 422 + } 423 + } 424 + 425 + /* Put the controller in low power state */ 426 + pcgcctl = readl(hsotg->regs + PCGCTL); 427 + 428 + pcgcctl |= PCGCTL_PWRCLMP; 429 + writel(pcgcctl, hsotg->regs + PCGCTL); 430 + ndelay(20); 431 + 432 + pcgcctl |= PCGCTL_RSTPDWNMODULE; 433 + writel(pcgcctl, hsotg->regs + PCGCTL); 434 + ndelay(20); 435 + 436 + pcgcctl |= PCGCTL_STOPPCLK; 437 + writel(pcgcctl, hsotg->regs + PCGCTL); 438 + 439 + return ret; 440 + } 441 + 59 442 /** 60 443 * dwc2_enable_common_interrupts() - Initializes the commmon interrupts, 61 444 * used in both device and host modes ··· 460 77 461 78 if (hsotg->core_params->dma_enable <= 0) 462 79 intmsk |= GINTSTS_RXFLVL; 80 + if (hsotg->core_params->external_id_pin_ctl <= 0) 81 + intmsk |= GINTSTS_CONIDSTSCHNG; 463 82 464 - intmsk |= GINTSTS_CONIDSTSCHNG | GINTSTS_WKUPINT | GINTSTS_USBSUSP | 83 + intmsk |= GINTSTS_WKUPINT | GINTSTS_USBSUSP | 465 84 GINTSTS_SESSREQINT; 466 85 467 86 writel(intmsk, hsotg->regs + GINTMSK); ··· 2987 2602 hsotg->core_params->uframe_sched = val; 2988 2603 } 2989 2604 2605 + static void dwc2_set_param_external_id_pin_ctl(struct dwc2_hsotg *hsotg, 2606 + int val) 2607 + { 2608 + if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2609 + if (val >= 0) { 2610 + dev_err(hsotg->dev, 2611 + "'%d' invalid for parameter external_id_pin_ctl\n", 2612 + val); 2613 + dev_err(hsotg->dev, "external_id_pin_ctl must be 0 or 1\n"); 2614 + } 2615 + val = 0; 2616 + dev_dbg(hsotg->dev, "Setting external_id_pin_ctl to %d\n", val); 2617 + } 2618 + 2619 + hsotg->core_params->external_id_pin_ctl = val; 2620 + } 2621 + 2622 + static void dwc2_set_param_hibernation(struct dwc2_hsotg *hsotg, 2623 + int val) 2624 + { 2625 + if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2626 + if (val >= 0) { 2627 + dev_err(hsotg->dev, 2628 + "'%d' invalid for parameter hibernation\n", 2629 + val); 2630 + dev_err(hsotg->dev, "hibernation must be 0 or 1\n"); 2631 + } 2632 + val = 0; 2633 + dev_dbg(hsotg->dev, "Setting hibernation to %d\n", val); 2634 + } 2635 + 2636 + hsotg->core_params->hibernation = val; 2637 + } 2638 + 2990 2639 /* 2991 2640 * This function is called during module intialization to pass module parameters 2992 2641 * for the DWC_otg core. ··· 3065 2646 dwc2_set_param_ahbcfg(hsotg, params->ahbcfg); 3066 2647 dwc2_set_param_otg_ver(hsotg, params->otg_ver); 3067 2648 dwc2_set_param_uframe_sched(hsotg, params->uframe_sched); 2649 + dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl); 2650 + dwc2_set_param_hibernation(hsotg, params->hibernation); 3068 2651 } 3069 2652 3070 2653 /** ··· 3234 2813 3235 2814 return 0; 3236 2815 } 2816 + 2817 + /* 2818 + * Sets all parameters to the given value. 2819 + * 2820 + * Assumes that the dwc2_core_params struct contains only integers. 2821 + */ 2822 + void dwc2_set_all_params(struct dwc2_core_params *params, int value) 2823 + { 2824 + int *p = (int *)params; 2825 + size_t size = sizeof(*params) / sizeof(*p); 2826 + int i; 2827 + 2828 + for (i = 0; i < size; i++) 2829 + p[i] = value; 2830 + } 2831 + 3237 2832 3238 2833 u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg) 3239 2834 {
+114 -6
drivers/usb/dwc2/core.h
··· 331 331 * by the driver and are ignored in this 332 332 * configuration value. 333 333 * @uframe_sched: True to enable the microframe scheduler 334 + * @external_id_pin_ctl: Specifies whether ID pin is handled externally. 335 + * Disable CONIDSTSCHNG controller interrupt in such 336 + * case. 337 + * 0 - No (default) 338 + * 1 - Yes 339 + * @hibernation: Specifies whether the controller support hibernation. 340 + * If hibernation is enabled, the controller will enter 341 + * hibernation in both peripheral and host mode when 342 + * needed. 343 + * 0 - No (default) 344 + * 1 - Yes 334 345 * 335 346 * The following parameters may be specified when starting the module. These 336 347 * parameters define how the DWC_otg controller should be configured. A ··· 379 368 int reload_ctl; 380 369 int ahbcfg; 381 370 int uframe_sched; 371 + int external_id_pin_ctl; 372 + int hibernation; 382 373 }; 383 374 384 375 /** ··· 465 452 #define DWC2_CTRL_BUFF_SIZE 8 466 453 467 454 /** 455 + * struct dwc2_gregs_backup - Holds global registers state before entering partial 456 + * power down 457 + * @gotgctl: Backup of GOTGCTL register 458 + * @gintmsk: Backup of GINTMSK register 459 + * @gahbcfg: Backup of GAHBCFG register 460 + * @gusbcfg: Backup of GUSBCFG register 461 + * @grxfsiz: Backup of GRXFSIZ register 462 + * @gnptxfsiz: Backup of GNPTXFSIZ register 463 + * @gi2cctl: Backup of GI2CCTL register 464 + * @hptxfsiz: Backup of HPTXFSIZ register 465 + * @gdfifocfg: Backup of GDFIFOCFG register 466 + * @dtxfsiz: Backup of DTXFSIZ registers for each endpoint 467 + * @gpwrdn: Backup of GPWRDN register 468 + */ 469 + struct dwc2_gregs_backup { 470 + u32 gotgctl; 471 + u32 gintmsk; 472 + u32 gahbcfg; 473 + u32 gusbcfg; 474 + u32 grxfsiz; 475 + u32 gnptxfsiz; 476 + u32 gi2cctl; 477 + u32 hptxfsiz; 478 + u32 pcgcctl; 479 + u32 gdfifocfg; 480 + u32 dtxfsiz[MAX_EPS_CHANNELS]; 481 + u32 gpwrdn; 482 + }; 483 + 484 + /** 485 + * struct dwc2_dregs_backup - Holds device registers state before entering partial 486 + * power down 487 + * @dcfg: Backup of DCFG register 488 + * @dctl: Backup of DCTL register 489 + * @daintmsk: Backup of DAINTMSK register 490 + * @diepmsk: Backup of DIEPMSK register 491 + * @doepmsk: Backup of DOEPMSK register 492 + * @diepctl: Backup of DIEPCTL register 493 + * @dieptsiz: Backup of DIEPTSIZ register 494 + * @diepdma: Backup of DIEPDMA register 495 + * @doepctl: Backup of DOEPCTL register 496 + * @doeptsiz: Backup of DOEPTSIZ register 497 + * @doepdma: Backup of DOEPDMA register 498 + */ 499 + struct dwc2_dregs_backup { 500 + u32 dcfg; 501 + u32 dctl; 502 + u32 daintmsk; 503 + u32 diepmsk; 504 + u32 doepmsk; 505 + u32 diepctl[MAX_EPS_CHANNELS]; 506 + u32 dieptsiz[MAX_EPS_CHANNELS]; 507 + u32 diepdma[MAX_EPS_CHANNELS]; 508 + u32 doepctl[MAX_EPS_CHANNELS]; 509 + u32 doeptsiz[MAX_EPS_CHANNELS]; 510 + u32 doepdma[MAX_EPS_CHANNELS]; 511 + }; 512 + 513 + /** 514 + * struct dwc2_hregs_backup - Holds host registers state before entering partial 515 + * power down 516 + * @hcfg: Backup of HCFG register 517 + * @haintmsk: Backup of HAINTMSK register 518 + * @hcintmsk: Backup of HCINTMSK register 519 + * @hptr0: Backup of HPTR0 register 520 + * @hfir: Backup of HFIR register 521 + */ 522 + struct dwc2_hregs_backup { 523 + u32 hcfg; 524 + u32 haintmsk; 525 + u32 hcintmsk[MAX_EPS_CHANNELS]; 526 + u32 hprt0; 527 + u32 hfir; 528 + }; 529 + 530 + /** 468 531 * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic 469 532 * and periodic schedules 470 533 * ··· 570 481 * interrupt 571 482 * @wkp_timer: Timer object for handling Wakeup Detected interrupt 572 483 * @lx_state: Lx state of connected device 484 + * @gregs_backup: Backup of global registers during suspend 485 + * @dregs_backup: Backup of device registers during suspend 486 + * @hregs_backup: Backup of host registers during suspend 573 487 * 574 488 * These are for host mode: 575 489 * ··· 705 613 struct work_struct wf_otg; 706 614 struct timer_list wkp_timer; 707 615 enum dwc2_lx_state lx_state; 616 + struct dwc2_gregs_backup *gr_backup; 617 + struct dwc2_dregs_backup *dr_backup; 618 + struct dwc2_hregs_backup *hr_backup; 708 619 709 620 struct dentry *debug_root; 710 - struct dentry *debug_file; 711 - struct dentry *debug_testmode; 712 - struct dentry *debug_fifo; 621 + struct debugfs_regset32 *regset; 713 622 714 623 /* DWC OTG HW Release versions */ 715 624 #define DWC2_CORE_REV_2_71a 0x4f54271a ··· 844 751 * and the DWC_otg controller 845 752 */ 846 753 extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg); 754 + extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg); 755 + extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore); 847 756 848 757 /* 849 758 * Host core Functions. ··· 1078 983 1079 984 extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val); 1080 985 986 + extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg, 987 + const struct dwc2_core_params *params); 988 + 989 + extern void dwc2_set_all_params(struct dwc2_core_params *params, int value); 990 + 991 + extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg); 992 + 993 + 994 + 1081 995 /* 1082 996 * Dump core registers and SPRAM 1083 997 */ ··· 1109 1005 bool reset); 1110 1006 extern void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg); 1111 1007 extern void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2); 1008 + extern int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode); 1009 + #define dwc2_is_device_connected(hsotg) (hsotg->connected) 1112 1010 #else 1113 1011 static inline int s3c_hsotg_remove(struct dwc2_hsotg *dwc2) 1114 1012 { return 0; } ··· 1124 1018 bool reset) {} 1125 1019 static inline void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg) {} 1126 1020 static inline void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2) {} 1021 + static inline int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, 1022 + int testmode) 1023 + { return 0; } 1024 + #define dwc2_is_device_connected(hsotg) (0) 1127 1025 #endif 1128 1026 1129 1027 #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) ··· 1135 1025 extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg); 1136 1026 extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg); 1137 1027 #else 1138 - static inline void dwc2_set_all_params(struct dwc2_core_params *params, int value) {} 1139 1028 static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) 1140 1029 { return 0; } 1141 1030 static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {} 1142 1031 static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {} 1143 1032 static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {} 1144 - static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, 1145 - const struct dwc2_core_params *params) 1033 + static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq) 1146 1034 { return 0; } 1147 1035 #endif 1148 1036
+41 -4
drivers/usb/dwc2/core_intr.c
··· 334 334 */ 335 335 static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg) 336 336 { 337 + int ret; 337 338 dev_dbg(hsotg->dev, "++Resume or Remote Wakeup Detected Interrupt++\n"); 338 339 dev_dbg(hsotg->dev, "%s lxstate = %d\n", __func__, hsotg->lx_state); 339 340 ··· 346 345 /* Clear Remote Wakeup Signaling */ 347 346 dctl &= ~DCTL_RMTWKUPSIG; 348 347 writel(dctl, hsotg->regs + DCTL); 348 + ret = dwc2_exit_hibernation(hsotg, true); 349 + if (ret && (ret != -ENOTSUPP)) 350 + dev_err(hsotg->dev, "exit hibernation failed\n"); 351 + 352 + call_gadget(hsotg, resume); 349 353 } 350 354 /* Change to L0 state */ 351 355 hsotg->lx_state = DWC2_L0; ··· 403 397 static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg) 404 398 { 405 399 u32 dsts; 400 + int ret; 406 401 407 402 dev_dbg(hsotg->dev, "USB SUSPEND\n"); 408 403 ··· 418 411 "DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d\n", 419 412 !!(dsts & DSTS_SUSPSTS), 420 413 hsotg->hw_params.power_optimized); 414 + if ((dsts & DSTS_SUSPSTS) && hsotg->hw_params.power_optimized) { 415 + /* Ignore suspend request before enumeration */ 416 + if (!dwc2_is_device_connected(hsotg)) { 417 + dev_dbg(hsotg->dev, 418 + "ignore suspend request before enumeration\n"); 419 + goto clear_int; 420 + } 421 + 422 + ret = dwc2_enter_hibernation(hsotg); 423 + if (ret) { 424 + if (ret != -ENOTSUPP) 425 + dev_err(hsotg->dev, 426 + "enter hibernation failed\n"); 427 + goto skip_power_saving; 428 + } 429 + 430 + udelay(100); 431 + 432 + /* Ask phy to be suspended */ 433 + if (!IS_ERR_OR_NULL(hsotg->uphy)) 434 + usb_phy_set_suspend(hsotg->uphy, true); 435 + skip_power_saving: 436 + /* 437 + * Change to L2 (suspend) state before releasing 438 + * spinlock 439 + */ 440 + hsotg->lx_state = DWC2_L2; 441 + 442 + /* Call gadget suspend callback */ 443 + call_gadget(hsotg, suspend); 444 + } 421 445 } else { 422 446 if (hsotg->op_state == OTG_STATE_A_PERIPHERAL) { 423 447 dev_dbg(hsotg->dev, "a_peripheral->a_host\n"); 424 448 449 + /* Change to L2 (suspend) state */ 450 + hsotg->lx_state = DWC2_L2; 425 451 /* Clear the a_peripheral flag, back to a_host */ 426 452 spin_unlock(&hsotg->lock); 427 453 dwc2_hcd_start(hsotg); ··· 463 423 } 464 424 } 465 425 466 - /* Change to L2 (suspend) state */ 467 - hsotg->lx_state = DWC2_L2; 468 - 426 + clear_int: 469 427 /* Clear interrupt */ 470 428 writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS); 471 429 } ··· 560 522 spin_unlock(&hsotg->lock); 561 523 return retval; 562 524 } 563 - EXPORT_SYMBOL_GPL(dwc2_handle_common_intr);
+27
drivers/usb/dwc2/debug.h
··· 1 + /** 2 + * debug.h - Designware USB2 DRD controller debug header 3 + * 4 + * Copyright (C) 2015 Intel Corporation 5 + * Mian Yousaf Kaukab <yousaf.kaukab@intel.com> 6 + * 7 + * This program is free software: you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 of 9 + * the License as published by the Free Software Foundation. 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 "core.h" 18 + 19 + #ifdef CONFIG_DEBUG_FS 20 + extern int dwc2_debugfs_init(struct dwc2_hsotg *); 21 + extern void dwc2_debugfs_exit(struct dwc2_hsotg *); 22 + #else 23 + static inline int dwc2_debugfs_init(struct dwc2_hsotg *hsotg) 24 + { return 0; } 25 + static inline void dwc2_debugfs_exit(struct dwc2_hsotg *hsotg) 26 + { } 27 + #endif
+771
drivers/usb/dwc2/debugfs.c
··· 1 + /** 2 + * debugfs.c - Designware USB2 DRD controller debugfs 3 + * 4 + * Copyright (C) 2015 Intel Corporation 5 + * Mian Yousaf Kaukab <yousaf.kaukab@intel.com> 6 + * 7 + * This program is free software: you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 of 9 + * the License as published by the Free Software Foundation. 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/spinlock.h> 18 + #include <linux/debugfs.h> 19 + #include <linux/seq_file.h> 20 + #include <linux/uaccess.h> 21 + 22 + #include "core.h" 23 + #include "debug.h" 24 + 25 + #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \ 26 + IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) 27 + /** 28 + * testmode_write - debugfs: change usb test mode 29 + * @seq: The seq file to write to. 30 + * @v: Unused parameter. 31 + * 32 + * This debugfs entry modify the current usb test mode. 33 + */ 34 + static ssize_t testmode_write(struct file *file, const char __user *ubuf, size_t 35 + count, loff_t *ppos) 36 + { 37 + struct seq_file *s = file->private_data; 38 + struct dwc2_hsotg *hsotg = s->private; 39 + unsigned long flags; 40 + u32 testmode = 0; 41 + char buf[32]; 42 + 43 + if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 44 + return -EFAULT; 45 + 46 + if (!strncmp(buf, "test_j", 6)) 47 + testmode = TEST_J; 48 + else if (!strncmp(buf, "test_k", 6)) 49 + testmode = TEST_K; 50 + else if (!strncmp(buf, "test_se0_nak", 12)) 51 + testmode = TEST_SE0_NAK; 52 + else if (!strncmp(buf, "test_packet", 11)) 53 + testmode = TEST_PACKET; 54 + else if (!strncmp(buf, "test_force_enable", 17)) 55 + testmode = TEST_FORCE_EN; 56 + else 57 + testmode = 0; 58 + 59 + spin_lock_irqsave(&hsotg->lock, flags); 60 + s3c_hsotg_set_test_mode(hsotg, testmode); 61 + spin_unlock_irqrestore(&hsotg->lock, flags); 62 + return count; 63 + } 64 + 65 + /** 66 + * testmode_show - debugfs: show usb test mode state 67 + * @seq: The seq file to write to. 68 + * @v: Unused parameter. 69 + * 70 + * This debugfs entry shows which usb test mode is currently enabled. 71 + */ 72 + static int testmode_show(struct seq_file *s, void *unused) 73 + { 74 + struct dwc2_hsotg *hsotg = s->private; 75 + unsigned long flags; 76 + int dctl; 77 + 78 + spin_lock_irqsave(&hsotg->lock, flags); 79 + dctl = readl(hsotg->regs + DCTL); 80 + dctl &= DCTL_TSTCTL_MASK; 81 + dctl >>= DCTL_TSTCTL_SHIFT; 82 + spin_unlock_irqrestore(&hsotg->lock, flags); 83 + 84 + switch (dctl) { 85 + case 0: 86 + seq_puts(s, "no test\n"); 87 + break; 88 + case TEST_J: 89 + seq_puts(s, "test_j\n"); 90 + break; 91 + case TEST_K: 92 + seq_puts(s, "test_k\n"); 93 + break; 94 + case TEST_SE0_NAK: 95 + seq_puts(s, "test_se0_nak\n"); 96 + break; 97 + case TEST_PACKET: 98 + seq_puts(s, "test_packet\n"); 99 + break; 100 + case TEST_FORCE_EN: 101 + seq_puts(s, "test_force_enable\n"); 102 + break; 103 + default: 104 + seq_printf(s, "UNKNOWN %d\n", dctl); 105 + } 106 + 107 + return 0; 108 + } 109 + 110 + static int testmode_open(struct inode *inode, struct file *file) 111 + { 112 + return single_open(file, testmode_show, inode->i_private); 113 + } 114 + 115 + static const struct file_operations testmode_fops = { 116 + .owner = THIS_MODULE, 117 + .open = testmode_open, 118 + .write = testmode_write, 119 + .read = seq_read, 120 + .llseek = seq_lseek, 121 + .release = single_release, 122 + }; 123 + 124 + /** 125 + * state_show - debugfs: show overall driver and device state. 126 + * @seq: The seq file to write to. 127 + * @v: Unused parameter. 128 + * 129 + * This debugfs entry shows the overall state of the hardware and 130 + * some general information about each of the endpoints available 131 + * to the system. 132 + */ 133 + static int state_show(struct seq_file *seq, void *v) 134 + { 135 + struct dwc2_hsotg *hsotg = seq->private; 136 + void __iomem *regs = hsotg->regs; 137 + int idx; 138 + 139 + seq_printf(seq, "DCFG=0x%08x, DCTL=0x%08x, DSTS=0x%08x\n", 140 + readl(regs + DCFG), 141 + readl(regs + DCTL), 142 + readl(regs + DSTS)); 143 + 144 + seq_printf(seq, "DIEPMSK=0x%08x, DOEPMASK=0x%08x\n", 145 + readl(regs + DIEPMSK), readl(regs + DOEPMSK)); 146 + 147 + seq_printf(seq, "GINTMSK=0x%08x, GINTSTS=0x%08x\n", 148 + readl(regs + GINTMSK), 149 + readl(regs + GINTSTS)); 150 + 151 + seq_printf(seq, "DAINTMSK=0x%08x, DAINT=0x%08x\n", 152 + readl(regs + DAINTMSK), 153 + readl(regs + DAINT)); 154 + 155 + seq_printf(seq, "GNPTXSTS=0x%08x, GRXSTSR=%08x\n", 156 + readl(regs + GNPTXSTS), 157 + readl(regs + GRXSTSR)); 158 + 159 + seq_puts(seq, "\nEndpoint status:\n"); 160 + 161 + for (idx = 0; idx < hsotg->num_of_eps; idx++) { 162 + u32 in, out; 163 + 164 + in = readl(regs + DIEPCTL(idx)); 165 + out = readl(regs + DOEPCTL(idx)); 166 + 167 + seq_printf(seq, "ep%d: DIEPCTL=0x%08x, DOEPCTL=0x%08x", 168 + idx, in, out); 169 + 170 + in = readl(regs + DIEPTSIZ(idx)); 171 + out = readl(regs + DOEPTSIZ(idx)); 172 + 173 + seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", 174 + in, out); 175 + 176 + seq_puts(seq, "\n"); 177 + } 178 + 179 + return 0; 180 + } 181 + 182 + static int state_open(struct inode *inode, struct file *file) 183 + { 184 + return single_open(file, state_show, inode->i_private); 185 + } 186 + 187 + static const struct file_operations state_fops = { 188 + .owner = THIS_MODULE, 189 + .open = state_open, 190 + .read = seq_read, 191 + .llseek = seq_lseek, 192 + .release = single_release, 193 + }; 194 + 195 + /** 196 + * fifo_show - debugfs: show the fifo information 197 + * @seq: The seq_file to write data to. 198 + * @v: Unused parameter. 199 + * 200 + * Show the FIFO information for the overall fifo and all the 201 + * periodic transmission FIFOs. 202 + */ 203 + static int fifo_show(struct seq_file *seq, void *v) 204 + { 205 + struct dwc2_hsotg *hsotg = seq->private; 206 + void __iomem *regs = hsotg->regs; 207 + u32 val; 208 + int idx; 209 + 210 + seq_puts(seq, "Non-periodic FIFOs:\n"); 211 + seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ)); 212 + 213 + val = readl(regs + GNPTXFSIZ); 214 + seq_printf(seq, "NPTXFIFO: Size %d, Start 0x%08x\n", 215 + val >> FIFOSIZE_DEPTH_SHIFT, 216 + val & FIFOSIZE_DEPTH_MASK); 217 + 218 + seq_puts(seq, "\nPeriodic TXFIFOs:\n"); 219 + 220 + for (idx = 1; idx < hsotg->num_of_eps; idx++) { 221 + val = readl(regs + DPTXFSIZN(idx)); 222 + 223 + seq_printf(seq, "\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx, 224 + val >> FIFOSIZE_DEPTH_SHIFT, 225 + val & FIFOSIZE_STARTADDR_MASK); 226 + } 227 + 228 + return 0; 229 + } 230 + 231 + static int fifo_open(struct inode *inode, struct file *file) 232 + { 233 + return single_open(file, fifo_show, inode->i_private); 234 + } 235 + 236 + static const struct file_operations fifo_fops = { 237 + .owner = THIS_MODULE, 238 + .open = fifo_open, 239 + .read = seq_read, 240 + .llseek = seq_lseek, 241 + .release = single_release, 242 + }; 243 + 244 + static const char *decode_direction(int is_in) 245 + { 246 + return is_in ? "in" : "out"; 247 + } 248 + 249 + /** 250 + * ep_show - debugfs: show the state of an endpoint. 251 + * @seq: The seq_file to write data to. 252 + * @v: Unused parameter. 253 + * 254 + * This debugfs entry shows the state of the given endpoint (one is 255 + * registered for each available). 256 + */ 257 + static int ep_show(struct seq_file *seq, void *v) 258 + { 259 + struct s3c_hsotg_ep *ep = seq->private; 260 + struct dwc2_hsotg *hsotg = ep->parent; 261 + struct s3c_hsotg_req *req; 262 + void __iomem *regs = hsotg->regs; 263 + int index = ep->index; 264 + int show_limit = 15; 265 + unsigned long flags; 266 + 267 + seq_printf(seq, "Endpoint index %d, named %s, dir %s:\n", 268 + ep->index, ep->ep.name, decode_direction(ep->dir_in)); 269 + 270 + /* first show the register state */ 271 + 272 + seq_printf(seq, "\tDIEPCTL=0x%08x, DOEPCTL=0x%08x\n", 273 + readl(regs + DIEPCTL(index)), 274 + readl(regs + DOEPCTL(index))); 275 + 276 + seq_printf(seq, "\tDIEPDMA=0x%08x, DOEPDMA=0x%08x\n", 277 + readl(regs + DIEPDMA(index)), 278 + readl(regs + DOEPDMA(index))); 279 + 280 + seq_printf(seq, "\tDIEPINT=0x%08x, DOEPINT=0x%08x\n", 281 + readl(regs + DIEPINT(index)), 282 + readl(regs + DOEPINT(index))); 283 + 284 + seq_printf(seq, "\tDIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x\n", 285 + readl(regs + DIEPTSIZ(index)), 286 + readl(regs + DOEPTSIZ(index))); 287 + 288 + seq_puts(seq, "\n"); 289 + seq_printf(seq, "mps %d\n", ep->ep.maxpacket); 290 + seq_printf(seq, "total_data=%ld\n", ep->total_data); 291 + 292 + seq_printf(seq, "request list (%p,%p):\n", 293 + ep->queue.next, ep->queue.prev); 294 + 295 + spin_lock_irqsave(&hsotg->lock, flags); 296 + 297 + list_for_each_entry(req, &ep->queue, queue) { 298 + if (--show_limit < 0) { 299 + seq_puts(seq, "not showing more requests...\n"); 300 + break; 301 + } 302 + 303 + seq_printf(seq, "%c req %p: %d bytes @%p, ", 304 + req == ep->req ? '*' : ' ', 305 + req, req->req.length, req->req.buf); 306 + seq_printf(seq, "%d done, res %d\n", 307 + req->req.actual, req->req.status); 308 + } 309 + 310 + spin_unlock_irqrestore(&hsotg->lock, flags); 311 + 312 + return 0; 313 + } 314 + 315 + static int ep_open(struct inode *inode, struct file *file) 316 + { 317 + return single_open(file, ep_show, inode->i_private); 318 + } 319 + 320 + static const struct file_operations ep_fops = { 321 + .owner = THIS_MODULE, 322 + .open = ep_open, 323 + .read = seq_read, 324 + .llseek = seq_lseek, 325 + .release = single_release, 326 + }; 327 + 328 + /** 329 + * s3c_hsotg_create_debug - create debugfs directory and files 330 + * @hsotg: The driver state 331 + * 332 + * Create the debugfs files to allow the user to get information 333 + * about the state of the system. The directory name is created 334 + * with the same name as the device itself, in case we end up 335 + * with multiple blocks in future systems. 336 + */ 337 + static void s3c_hsotg_create_debug(struct dwc2_hsotg *hsotg) 338 + { 339 + struct dentry *root; 340 + struct dentry *file; 341 + unsigned epidx; 342 + 343 + root = hsotg->debug_root; 344 + 345 + /* create general state file */ 346 + 347 + file = debugfs_create_file("state", S_IRUGO, root, hsotg, &state_fops); 348 + if (IS_ERR(file)) 349 + dev_err(hsotg->dev, "%s: failed to create state\n", __func__); 350 + 351 + file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root, hsotg, 352 + &testmode_fops); 353 + if (IS_ERR(file)) 354 + dev_err(hsotg->dev, "%s: failed to create testmode\n", 355 + __func__); 356 + 357 + file = debugfs_create_file("fifo", S_IRUGO, root, hsotg, &fifo_fops); 358 + if (IS_ERR(file)) 359 + dev_err(hsotg->dev, "%s: failed to create fifo\n", __func__); 360 + 361 + /* Create one file for each out endpoint */ 362 + for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { 363 + struct s3c_hsotg_ep *ep; 364 + 365 + ep = hsotg->eps_out[epidx]; 366 + if (ep) { 367 + file = debugfs_create_file(ep->name, S_IRUGO, 368 + root, ep, &ep_fops); 369 + if (IS_ERR(file)) 370 + dev_err(hsotg->dev, "failed to create %s debug file\n", 371 + ep->name); 372 + } 373 + } 374 + /* Create one file for each in endpoint. EP0 is handled with out eps */ 375 + for (epidx = 1; epidx < hsotg->num_of_eps; epidx++) { 376 + struct s3c_hsotg_ep *ep; 377 + 378 + ep = hsotg->eps_in[epidx]; 379 + if (ep) { 380 + file = debugfs_create_file(ep->name, S_IRUGO, 381 + root, ep, &ep_fops); 382 + if (IS_ERR(file)) 383 + dev_err(hsotg->dev, "failed to create %s debug file\n", 384 + ep->name); 385 + } 386 + } 387 + } 388 + #else 389 + static inline void s3c_hsotg_create_debug(struct dwc2_hsotg *hsotg) {} 390 + #endif 391 + 392 + /* s3c_hsotg_delete_debug is removed as cleanup in done in dwc2_debugfs_exit */ 393 + 394 + #define dump_register(nm) \ 395 + { \ 396 + .name = #nm, \ 397 + .offset = nm, \ 398 + } 399 + 400 + static const struct debugfs_reg32 dwc2_regs[] = { 401 + /* 402 + * Accessing registers like this can trigger mode mismatch interrupt. 403 + * However, according to dwc2 databook, the register access, in this 404 + * case, is completed on the processor bus but is ignored by the core 405 + * and does not affect its operation. 406 + */ 407 + dump_register(GOTGCTL), 408 + dump_register(GOTGINT), 409 + dump_register(GAHBCFG), 410 + dump_register(GUSBCFG), 411 + dump_register(GRSTCTL), 412 + dump_register(GINTSTS), 413 + dump_register(GINTMSK), 414 + dump_register(GRXSTSR), 415 + dump_register(GRXSTSP), 416 + dump_register(GRXFSIZ), 417 + dump_register(GNPTXFSIZ), 418 + dump_register(GNPTXSTS), 419 + dump_register(GI2CCTL), 420 + dump_register(GPVNDCTL), 421 + dump_register(GGPIO), 422 + dump_register(GUID), 423 + dump_register(GSNPSID), 424 + dump_register(GHWCFG1), 425 + dump_register(GHWCFG2), 426 + dump_register(GHWCFG3), 427 + dump_register(GHWCFG4), 428 + dump_register(GLPMCFG), 429 + dump_register(GPWRDN), 430 + dump_register(GDFIFOCFG), 431 + dump_register(ADPCTL), 432 + dump_register(HPTXFSIZ), 433 + dump_register(DPTXFSIZN(1)), 434 + dump_register(DPTXFSIZN(2)), 435 + dump_register(DPTXFSIZN(3)), 436 + dump_register(DPTXFSIZN(4)), 437 + dump_register(DPTXFSIZN(5)), 438 + dump_register(DPTXFSIZN(6)), 439 + dump_register(DPTXFSIZN(7)), 440 + dump_register(DPTXFSIZN(8)), 441 + dump_register(DPTXFSIZN(9)), 442 + dump_register(DPTXFSIZN(10)), 443 + dump_register(DPTXFSIZN(11)), 444 + dump_register(DPTXFSIZN(12)), 445 + dump_register(DPTXFSIZN(13)), 446 + dump_register(DPTXFSIZN(14)), 447 + dump_register(DPTXFSIZN(15)), 448 + dump_register(DCFG), 449 + dump_register(DCTL), 450 + dump_register(DSTS), 451 + dump_register(DIEPMSK), 452 + dump_register(DOEPMSK), 453 + dump_register(DAINT), 454 + dump_register(DAINTMSK), 455 + dump_register(DTKNQR1), 456 + dump_register(DTKNQR2), 457 + dump_register(DTKNQR3), 458 + dump_register(DTKNQR4), 459 + dump_register(DVBUSDIS), 460 + dump_register(DVBUSPULSE), 461 + dump_register(DIEPCTL(0)), 462 + dump_register(DIEPCTL(1)), 463 + dump_register(DIEPCTL(2)), 464 + dump_register(DIEPCTL(3)), 465 + dump_register(DIEPCTL(4)), 466 + dump_register(DIEPCTL(5)), 467 + dump_register(DIEPCTL(6)), 468 + dump_register(DIEPCTL(7)), 469 + dump_register(DIEPCTL(8)), 470 + dump_register(DIEPCTL(9)), 471 + dump_register(DIEPCTL(10)), 472 + dump_register(DIEPCTL(11)), 473 + dump_register(DIEPCTL(12)), 474 + dump_register(DIEPCTL(13)), 475 + dump_register(DIEPCTL(14)), 476 + dump_register(DIEPCTL(15)), 477 + dump_register(DOEPCTL(0)), 478 + dump_register(DOEPCTL(1)), 479 + dump_register(DOEPCTL(2)), 480 + dump_register(DOEPCTL(3)), 481 + dump_register(DOEPCTL(4)), 482 + dump_register(DOEPCTL(5)), 483 + dump_register(DOEPCTL(6)), 484 + dump_register(DOEPCTL(7)), 485 + dump_register(DOEPCTL(8)), 486 + dump_register(DOEPCTL(9)), 487 + dump_register(DOEPCTL(10)), 488 + dump_register(DOEPCTL(11)), 489 + dump_register(DOEPCTL(12)), 490 + dump_register(DOEPCTL(13)), 491 + dump_register(DOEPCTL(14)), 492 + dump_register(DOEPCTL(15)), 493 + dump_register(DIEPINT(0)), 494 + dump_register(DIEPINT(1)), 495 + dump_register(DIEPINT(2)), 496 + dump_register(DIEPINT(3)), 497 + dump_register(DIEPINT(4)), 498 + dump_register(DIEPINT(5)), 499 + dump_register(DIEPINT(6)), 500 + dump_register(DIEPINT(7)), 501 + dump_register(DIEPINT(8)), 502 + dump_register(DIEPINT(9)), 503 + dump_register(DIEPINT(10)), 504 + dump_register(DIEPINT(11)), 505 + dump_register(DIEPINT(12)), 506 + dump_register(DIEPINT(13)), 507 + dump_register(DIEPINT(14)), 508 + dump_register(DIEPINT(15)), 509 + dump_register(DOEPINT(0)), 510 + dump_register(DOEPINT(1)), 511 + dump_register(DOEPINT(2)), 512 + dump_register(DOEPINT(3)), 513 + dump_register(DOEPINT(4)), 514 + dump_register(DOEPINT(5)), 515 + dump_register(DOEPINT(6)), 516 + dump_register(DOEPINT(7)), 517 + dump_register(DOEPINT(8)), 518 + dump_register(DOEPINT(9)), 519 + dump_register(DOEPINT(10)), 520 + dump_register(DOEPINT(11)), 521 + dump_register(DOEPINT(12)), 522 + dump_register(DOEPINT(13)), 523 + dump_register(DOEPINT(14)), 524 + dump_register(DOEPINT(15)), 525 + dump_register(DIEPTSIZ(0)), 526 + dump_register(DIEPTSIZ(1)), 527 + dump_register(DIEPTSIZ(2)), 528 + dump_register(DIEPTSIZ(3)), 529 + dump_register(DIEPTSIZ(4)), 530 + dump_register(DIEPTSIZ(5)), 531 + dump_register(DIEPTSIZ(6)), 532 + dump_register(DIEPTSIZ(7)), 533 + dump_register(DIEPTSIZ(8)), 534 + dump_register(DIEPTSIZ(9)), 535 + dump_register(DIEPTSIZ(10)), 536 + dump_register(DIEPTSIZ(11)), 537 + dump_register(DIEPTSIZ(12)), 538 + dump_register(DIEPTSIZ(13)), 539 + dump_register(DIEPTSIZ(14)), 540 + dump_register(DIEPTSIZ(15)), 541 + dump_register(DOEPTSIZ(0)), 542 + dump_register(DOEPTSIZ(1)), 543 + dump_register(DOEPTSIZ(2)), 544 + dump_register(DOEPTSIZ(3)), 545 + dump_register(DOEPTSIZ(4)), 546 + dump_register(DOEPTSIZ(5)), 547 + dump_register(DOEPTSIZ(6)), 548 + dump_register(DOEPTSIZ(7)), 549 + dump_register(DOEPTSIZ(8)), 550 + dump_register(DOEPTSIZ(9)), 551 + dump_register(DOEPTSIZ(10)), 552 + dump_register(DOEPTSIZ(11)), 553 + dump_register(DOEPTSIZ(12)), 554 + dump_register(DOEPTSIZ(13)), 555 + dump_register(DOEPTSIZ(14)), 556 + dump_register(DOEPTSIZ(15)), 557 + dump_register(DIEPDMA(0)), 558 + dump_register(DIEPDMA(1)), 559 + dump_register(DIEPDMA(2)), 560 + dump_register(DIEPDMA(3)), 561 + dump_register(DIEPDMA(4)), 562 + dump_register(DIEPDMA(5)), 563 + dump_register(DIEPDMA(6)), 564 + dump_register(DIEPDMA(7)), 565 + dump_register(DIEPDMA(8)), 566 + dump_register(DIEPDMA(9)), 567 + dump_register(DIEPDMA(10)), 568 + dump_register(DIEPDMA(11)), 569 + dump_register(DIEPDMA(12)), 570 + dump_register(DIEPDMA(13)), 571 + dump_register(DIEPDMA(14)), 572 + dump_register(DIEPDMA(15)), 573 + dump_register(DOEPDMA(0)), 574 + dump_register(DOEPDMA(1)), 575 + dump_register(DOEPDMA(2)), 576 + dump_register(DOEPDMA(3)), 577 + dump_register(DOEPDMA(4)), 578 + dump_register(DOEPDMA(5)), 579 + dump_register(DOEPDMA(6)), 580 + dump_register(DOEPDMA(7)), 581 + dump_register(DOEPDMA(8)), 582 + dump_register(DOEPDMA(9)), 583 + dump_register(DOEPDMA(10)), 584 + dump_register(DOEPDMA(11)), 585 + dump_register(DOEPDMA(12)), 586 + dump_register(DOEPDMA(13)), 587 + dump_register(DOEPDMA(14)), 588 + dump_register(DOEPDMA(15)), 589 + dump_register(DTXFSTS(0)), 590 + dump_register(DTXFSTS(1)), 591 + dump_register(DTXFSTS(2)), 592 + dump_register(DTXFSTS(3)), 593 + dump_register(DTXFSTS(4)), 594 + dump_register(DTXFSTS(5)), 595 + dump_register(DTXFSTS(6)), 596 + dump_register(DTXFSTS(7)), 597 + dump_register(DTXFSTS(8)), 598 + dump_register(DTXFSTS(9)), 599 + dump_register(DTXFSTS(10)), 600 + dump_register(DTXFSTS(11)), 601 + dump_register(DTXFSTS(12)), 602 + dump_register(DTXFSTS(13)), 603 + dump_register(DTXFSTS(14)), 604 + dump_register(DTXFSTS(15)), 605 + dump_register(PCGCTL), 606 + dump_register(HCFG), 607 + dump_register(HFIR), 608 + dump_register(HFNUM), 609 + dump_register(HPTXSTS), 610 + dump_register(HAINT), 611 + dump_register(HAINTMSK), 612 + dump_register(HFLBADDR), 613 + dump_register(HPRT0), 614 + dump_register(HCCHAR(0)), 615 + dump_register(HCCHAR(1)), 616 + dump_register(HCCHAR(2)), 617 + dump_register(HCCHAR(3)), 618 + dump_register(HCCHAR(4)), 619 + dump_register(HCCHAR(5)), 620 + dump_register(HCCHAR(6)), 621 + dump_register(HCCHAR(7)), 622 + dump_register(HCCHAR(8)), 623 + dump_register(HCCHAR(9)), 624 + dump_register(HCCHAR(10)), 625 + dump_register(HCCHAR(11)), 626 + dump_register(HCCHAR(12)), 627 + dump_register(HCCHAR(13)), 628 + dump_register(HCCHAR(14)), 629 + dump_register(HCCHAR(15)), 630 + dump_register(HCSPLT(0)), 631 + dump_register(HCSPLT(1)), 632 + dump_register(HCSPLT(2)), 633 + dump_register(HCSPLT(3)), 634 + dump_register(HCSPLT(4)), 635 + dump_register(HCSPLT(5)), 636 + dump_register(HCSPLT(6)), 637 + dump_register(HCSPLT(7)), 638 + dump_register(HCSPLT(8)), 639 + dump_register(HCSPLT(9)), 640 + dump_register(HCSPLT(10)), 641 + dump_register(HCSPLT(11)), 642 + dump_register(HCSPLT(12)), 643 + dump_register(HCSPLT(13)), 644 + dump_register(HCSPLT(14)), 645 + dump_register(HCSPLT(15)), 646 + dump_register(HCINT(0)), 647 + dump_register(HCINT(1)), 648 + dump_register(HCINT(2)), 649 + dump_register(HCINT(3)), 650 + dump_register(HCINT(4)), 651 + dump_register(HCINT(5)), 652 + dump_register(HCINT(6)), 653 + dump_register(HCINT(7)), 654 + dump_register(HCINT(8)), 655 + dump_register(HCINT(9)), 656 + dump_register(HCINT(10)), 657 + dump_register(HCINT(11)), 658 + dump_register(HCINT(12)), 659 + dump_register(HCINT(13)), 660 + dump_register(HCINT(14)), 661 + dump_register(HCINT(15)), 662 + dump_register(HCINTMSK(0)), 663 + dump_register(HCINTMSK(1)), 664 + dump_register(HCINTMSK(2)), 665 + dump_register(HCINTMSK(3)), 666 + dump_register(HCINTMSK(4)), 667 + dump_register(HCINTMSK(5)), 668 + dump_register(HCINTMSK(6)), 669 + dump_register(HCINTMSK(7)), 670 + dump_register(HCINTMSK(8)), 671 + dump_register(HCINTMSK(9)), 672 + dump_register(HCINTMSK(10)), 673 + dump_register(HCINTMSK(11)), 674 + dump_register(HCINTMSK(12)), 675 + dump_register(HCINTMSK(13)), 676 + dump_register(HCINTMSK(14)), 677 + dump_register(HCINTMSK(15)), 678 + dump_register(HCTSIZ(0)), 679 + dump_register(HCTSIZ(1)), 680 + dump_register(HCTSIZ(2)), 681 + dump_register(HCTSIZ(3)), 682 + dump_register(HCTSIZ(4)), 683 + dump_register(HCTSIZ(5)), 684 + dump_register(HCTSIZ(6)), 685 + dump_register(HCTSIZ(7)), 686 + dump_register(HCTSIZ(8)), 687 + dump_register(HCTSIZ(9)), 688 + dump_register(HCTSIZ(10)), 689 + dump_register(HCTSIZ(11)), 690 + dump_register(HCTSIZ(12)), 691 + dump_register(HCTSIZ(13)), 692 + dump_register(HCTSIZ(14)), 693 + dump_register(HCTSIZ(15)), 694 + dump_register(HCDMA(0)), 695 + dump_register(HCDMA(1)), 696 + dump_register(HCDMA(2)), 697 + dump_register(HCDMA(3)), 698 + dump_register(HCDMA(4)), 699 + dump_register(HCDMA(5)), 700 + dump_register(HCDMA(6)), 701 + dump_register(HCDMA(7)), 702 + dump_register(HCDMA(8)), 703 + dump_register(HCDMA(9)), 704 + dump_register(HCDMA(10)), 705 + dump_register(HCDMA(11)), 706 + dump_register(HCDMA(12)), 707 + dump_register(HCDMA(13)), 708 + dump_register(HCDMA(14)), 709 + dump_register(HCDMA(15)), 710 + dump_register(HCDMAB(0)), 711 + dump_register(HCDMAB(1)), 712 + dump_register(HCDMAB(2)), 713 + dump_register(HCDMAB(3)), 714 + dump_register(HCDMAB(4)), 715 + dump_register(HCDMAB(5)), 716 + dump_register(HCDMAB(6)), 717 + dump_register(HCDMAB(7)), 718 + dump_register(HCDMAB(8)), 719 + dump_register(HCDMAB(9)), 720 + dump_register(HCDMAB(10)), 721 + dump_register(HCDMAB(11)), 722 + dump_register(HCDMAB(12)), 723 + dump_register(HCDMAB(13)), 724 + dump_register(HCDMAB(14)), 725 + dump_register(HCDMAB(15)), 726 + }; 727 + 728 + int dwc2_debugfs_init(struct dwc2_hsotg *hsotg) 729 + { 730 + int ret; 731 + struct dentry *file; 732 + 733 + hsotg->debug_root = debugfs_create_dir(dev_name(hsotg->dev), NULL); 734 + if (!hsotg->debug_root) { 735 + ret = -ENOMEM; 736 + goto err0; 737 + } 738 + 739 + /* Add gadget debugfs nodes */ 740 + s3c_hsotg_create_debug(hsotg); 741 + 742 + hsotg->regset = devm_kzalloc(hsotg->dev, sizeof(*hsotg->regset), 743 + GFP_KERNEL); 744 + if (!hsotg->regset) { 745 + ret = -ENOMEM; 746 + goto err1; 747 + } 748 + 749 + hsotg->regset->regs = dwc2_regs; 750 + hsotg->regset->nregs = ARRAY_SIZE(dwc2_regs); 751 + hsotg->regset->base = hsotg->regs; 752 + 753 + file = debugfs_create_regset32("regdump", S_IRUGO, hsotg->debug_root, 754 + hsotg->regset); 755 + if (!file) { 756 + ret = -ENOMEM; 757 + goto err1; 758 + } 759 + 760 + return 0; 761 + err1: 762 + debugfs_remove_recursive(hsotg->debug_root); 763 + err0: 764 + return ret; 765 + } 766 + 767 + void dwc2_debugfs_exit(struct dwc2_hsotg *hsotg) 768 + { 769 + debugfs_remove_recursive(hsotg->debug_root); 770 + hsotg->debug_root = NULL; 771 + }
+42 -417
drivers/usb/dwc2/gadget.c
··· 20 20 #include <linux/interrupt.h> 21 21 #include <linux/platform_device.h> 22 22 #include <linux/dma-mapping.h> 23 - #include <linux/debugfs.h> 24 23 #include <linux/mutex.h> 25 24 #include <linux/seq_file.h> 26 25 #include <linux/delay.h> ··· 34 35 #include <linux/usb/gadget.h> 35 36 #include <linux/usb/phy.h> 36 37 #include <linux/platform_data/s3c-hsotg.h> 37 - #include <linux/uaccess.h> 38 38 39 39 #include "core.h" 40 40 #include "hw.h" ··· 790 792 ep->name, req, req->length, req->buf, req->no_interrupt, 791 793 req->zero, req->short_not_ok); 792 794 795 + /* Prevent new request submission when controller is suspended */ 796 + if (hs->lx_state == DWC2_L2) { 797 + dev_dbg(hs->dev, "%s: don't submit request while suspended\n", 798 + __func__); 799 + return -EAGAIN; 800 + } 801 + 793 802 /* initialise status of the request */ 794 803 INIT_LIST_HEAD(&hs_req->queue); 795 804 req->actual = 0; ··· 899 894 * @testmode: requested usb test mode 900 895 * Enable usb Test Mode requested by the Host. 901 896 */ 902 - static int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode) 897 + int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode) 903 898 { 904 899 int dctl = readl(hsotg->regs + DCTL); 905 900 ··· 2190 2185 2191 2186 call_gadget(hsotg, disconnect); 2192 2187 } 2193 - EXPORT_SYMBOL_GPL(s3c_hsotg_disconnect); 2194 2188 2195 2189 /** 2196 2190 * s3c_hsotg_irq_fifoempty - TX FIFO empty interrupt handler ··· 2314 2310 writel(GINTSTS_ERLYSUSP | GINTSTS_SESSREQINT | 2315 2311 GINTSTS_GOUTNAKEFF | GINTSTS_GINNAKEFF | 2316 2312 GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST | 2317 - GINTSTS_ENUMDONE | GINTSTS_OTGINT | 2318 - GINTSTS_USBSUSP | GINTSTS_WKUPINT, 2313 + GINTSTS_RESETDET | GINTSTS_ENUMDONE | 2314 + GINTSTS_OTGINT | GINTSTS_USBSUSP | 2315 + GINTSTS_WKUPINT, 2319 2316 hsotg->regs + GINTMSK); 2320 2317 2321 2318 if (using_dma(hsotg)) ··· 2482 2477 } 2483 2478 } 2484 2479 2485 - if (gintsts & GINTSTS_USBRST) { 2480 + if (gintsts & GINTSTS_RESETDET) { 2481 + dev_dbg(hsotg->dev, "%s: USBRstDet\n", __func__); 2482 + 2483 + writel(GINTSTS_RESETDET, hsotg->regs + GINTSTS); 2484 + 2485 + /* This event must be used only if controller is suspended */ 2486 + if (hsotg->lx_state == DWC2_L2) { 2487 + dwc2_exit_hibernation(hsotg, true); 2488 + hsotg->lx_state = DWC2_L0; 2489 + } 2490 + } 2491 + 2492 + if (gintsts & (GINTSTS_USBRST | GINTSTS_RESETDET)) { 2486 2493 2487 2494 u32 usb_status = readl(hsotg->regs + GOTGCTL); 2488 2495 ··· 2514 2497 kill_all_requests(hsotg, hsotg->eps_out[0], 2515 2498 -ECONNRESET); 2516 2499 2500 + hsotg->lx_state = DWC2_L0; 2517 2501 s3c_hsotg_core_init_disconnected(hsotg, true); 2518 2502 } 2519 2503 } ··· 2763 2745 * s3c_hsotg_ep_disable - disable given endpoint 2764 2746 * @ep: The endpoint to disable. 2765 2747 */ 2766 - static int s3c_hsotg_ep_disable_force(struct usb_ep *ep, bool force) 2748 + static int s3c_hsotg_ep_disable(struct usb_ep *ep) 2767 2749 { 2768 2750 struct s3c_hsotg_ep *hs_ep = our_ep(ep); 2769 2751 struct dwc2_hsotg *hsotg = hs_ep->parent; ··· 2806 2788 return 0; 2807 2789 } 2808 2790 2809 - static int s3c_hsotg_ep_disable(struct usb_ep *ep) 2810 - { 2811 - return s3c_hsotg_ep_disable_force(ep, false); 2812 - } 2813 2791 /** 2814 2792 * on_list - check request is on the given endpoint 2815 2793 * @ep: The endpoint to check. ··· 3201 3187 spin_lock_irqsave(&hsotg->lock, flags); 3202 3188 3203 3189 if (is_active) { 3190 + /* 3191 + * If controller is hibernated, it must exit from hibernation 3192 + * before being initialized 3193 + */ 3194 + if (hsotg->lx_state == DWC2_L2) { 3195 + dwc2_exit_hibernation(hsotg, false); 3196 + hsotg->lx_state = DWC2_L0; 3197 + } 3204 3198 /* Kill any ep0 requests as controller will be reinitialized */ 3205 3199 kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET); 3206 3200 s3c_hsotg_core_init_disconnected(hsotg, false); ··· 3413 3391 #endif 3414 3392 } 3415 3393 3416 - /** 3417 - * testmode_write - debugfs: change usb test mode 3418 - * @seq: The seq file to write to. 3419 - * @v: Unused parameter. 3420 - * 3421 - * This debugfs entry modify the current usb test mode. 3422 - */ 3423 - static ssize_t testmode_write(struct file *file, const char __user *ubuf, size_t 3424 - count, loff_t *ppos) 3425 - { 3426 - struct seq_file *s = file->private_data; 3427 - struct dwc2_hsotg *hsotg = s->private; 3428 - unsigned long flags; 3429 - u32 testmode = 0; 3430 - char buf[32]; 3431 - 3432 - if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 3433 - return -EFAULT; 3434 - 3435 - if (!strncmp(buf, "test_j", 6)) 3436 - testmode = TEST_J; 3437 - else if (!strncmp(buf, "test_k", 6)) 3438 - testmode = TEST_K; 3439 - else if (!strncmp(buf, "test_se0_nak", 12)) 3440 - testmode = TEST_SE0_NAK; 3441 - else if (!strncmp(buf, "test_packet", 11)) 3442 - testmode = TEST_PACKET; 3443 - else if (!strncmp(buf, "test_force_enable", 17)) 3444 - testmode = TEST_FORCE_EN; 3445 - else 3446 - testmode = 0; 3447 - 3448 - spin_lock_irqsave(&hsotg->lock, flags); 3449 - s3c_hsotg_set_test_mode(hsotg, testmode); 3450 - spin_unlock_irqrestore(&hsotg->lock, flags); 3451 - return count; 3452 - } 3453 - 3454 - /** 3455 - * testmode_show - debugfs: show usb test mode state 3456 - * @seq: The seq file to write to. 3457 - * @v: Unused parameter. 3458 - * 3459 - * This debugfs entry shows which usb test mode is currently enabled. 3460 - */ 3461 - static int testmode_show(struct seq_file *s, void *unused) 3462 - { 3463 - struct dwc2_hsotg *hsotg = s->private; 3464 - unsigned long flags; 3465 - int dctl; 3466 - 3467 - spin_lock_irqsave(&hsotg->lock, flags); 3468 - dctl = readl(hsotg->regs + DCTL); 3469 - dctl &= DCTL_TSTCTL_MASK; 3470 - dctl >>= DCTL_TSTCTL_SHIFT; 3471 - spin_unlock_irqrestore(&hsotg->lock, flags); 3472 - 3473 - switch (dctl) { 3474 - case 0: 3475 - seq_puts(s, "no test\n"); 3476 - break; 3477 - case TEST_J: 3478 - seq_puts(s, "test_j\n"); 3479 - break; 3480 - case TEST_K: 3481 - seq_puts(s, "test_k\n"); 3482 - break; 3483 - case TEST_SE0_NAK: 3484 - seq_puts(s, "test_se0_nak\n"); 3485 - break; 3486 - case TEST_PACKET: 3487 - seq_puts(s, "test_packet\n"); 3488 - break; 3489 - case TEST_FORCE_EN: 3490 - seq_puts(s, "test_force_enable\n"); 3491 - break; 3492 - default: 3493 - seq_printf(s, "UNKNOWN %d\n", dctl); 3494 - } 3495 - 3496 - return 0; 3497 - } 3498 - 3499 - static int testmode_open(struct inode *inode, struct file *file) 3500 - { 3501 - return single_open(file, testmode_show, inode->i_private); 3502 - } 3503 - 3504 - static const struct file_operations testmode_fops = { 3505 - .owner = THIS_MODULE, 3506 - .open = testmode_open, 3507 - .write = testmode_write, 3508 - .read = seq_read, 3509 - .llseek = seq_lseek, 3510 - .release = single_release, 3511 - }; 3512 - 3513 - /** 3514 - * state_show - debugfs: show overall driver and device state. 3515 - * @seq: The seq file to write to. 3516 - * @v: Unused parameter. 3517 - * 3518 - * This debugfs entry shows the overall state of the hardware and 3519 - * some general information about each of the endpoints available 3520 - * to the system. 3521 - */ 3522 - static int state_show(struct seq_file *seq, void *v) 3523 - { 3524 - struct dwc2_hsotg *hsotg = seq->private; 3525 - void __iomem *regs = hsotg->regs; 3526 - int idx; 3527 - 3528 - seq_printf(seq, "DCFG=0x%08x, DCTL=0x%08x, DSTS=0x%08x\n", 3529 - readl(regs + DCFG), 3530 - readl(regs + DCTL), 3531 - readl(regs + DSTS)); 3532 - 3533 - seq_printf(seq, "DIEPMSK=0x%08x, DOEPMASK=0x%08x\n", 3534 - readl(regs + DIEPMSK), readl(regs + DOEPMSK)); 3535 - 3536 - seq_printf(seq, "GINTMSK=0x%08x, GINTSTS=0x%08x\n", 3537 - readl(regs + GINTMSK), 3538 - readl(regs + GINTSTS)); 3539 - 3540 - seq_printf(seq, "DAINTMSK=0x%08x, DAINT=0x%08x\n", 3541 - readl(regs + DAINTMSK), 3542 - readl(regs + DAINT)); 3543 - 3544 - seq_printf(seq, "GNPTXSTS=0x%08x, GRXSTSR=%08x\n", 3545 - readl(regs + GNPTXSTS), 3546 - readl(regs + GRXSTSR)); 3547 - 3548 - seq_puts(seq, "\nEndpoint status:\n"); 3549 - 3550 - for (idx = 0; idx < hsotg->num_of_eps; idx++) { 3551 - u32 in, out; 3552 - 3553 - in = readl(regs + DIEPCTL(idx)); 3554 - out = readl(regs + DOEPCTL(idx)); 3555 - 3556 - seq_printf(seq, "ep%d: DIEPCTL=0x%08x, DOEPCTL=0x%08x", 3557 - idx, in, out); 3558 - 3559 - in = readl(regs + DIEPTSIZ(idx)); 3560 - out = readl(regs + DOEPTSIZ(idx)); 3561 - 3562 - seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", 3563 - in, out); 3564 - 3565 - seq_puts(seq, "\n"); 3566 - } 3567 - 3568 - return 0; 3569 - } 3570 - 3571 - static int state_open(struct inode *inode, struct file *file) 3572 - { 3573 - return single_open(file, state_show, inode->i_private); 3574 - } 3575 - 3576 - static const struct file_operations state_fops = { 3577 - .owner = THIS_MODULE, 3578 - .open = state_open, 3579 - .read = seq_read, 3580 - .llseek = seq_lseek, 3581 - .release = single_release, 3582 - }; 3583 - 3584 - /** 3585 - * fifo_show - debugfs: show the fifo information 3586 - * @seq: The seq_file to write data to. 3587 - * @v: Unused parameter. 3588 - * 3589 - * Show the FIFO information for the overall fifo and all the 3590 - * periodic transmission FIFOs. 3591 - */ 3592 - static int fifo_show(struct seq_file *seq, void *v) 3593 - { 3594 - struct dwc2_hsotg *hsotg = seq->private; 3595 - void __iomem *regs = hsotg->regs; 3596 - u32 val; 3597 - int idx; 3598 - 3599 - seq_puts(seq, "Non-periodic FIFOs:\n"); 3600 - seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ)); 3601 - 3602 - val = readl(regs + GNPTXFSIZ); 3603 - seq_printf(seq, "NPTXFIFO: Size %d, Start 0x%08x\n", 3604 - val >> FIFOSIZE_DEPTH_SHIFT, 3605 - val & FIFOSIZE_DEPTH_MASK); 3606 - 3607 - seq_puts(seq, "\nPeriodic TXFIFOs:\n"); 3608 - 3609 - for (idx = 1; idx < hsotg->num_of_eps; idx++) { 3610 - val = readl(regs + DPTXFSIZN(idx)); 3611 - 3612 - seq_printf(seq, "\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx, 3613 - val >> FIFOSIZE_DEPTH_SHIFT, 3614 - val & FIFOSIZE_STARTADDR_MASK); 3615 - } 3616 - 3617 - return 0; 3618 - } 3619 - 3620 - static int fifo_open(struct inode *inode, struct file *file) 3621 - { 3622 - return single_open(file, fifo_show, inode->i_private); 3623 - } 3624 - 3625 - static const struct file_operations fifo_fops = { 3626 - .owner = THIS_MODULE, 3627 - .open = fifo_open, 3628 - .read = seq_read, 3629 - .llseek = seq_lseek, 3630 - .release = single_release, 3631 - }; 3632 - 3633 - 3634 - static const char *decode_direction(int is_in) 3635 - { 3636 - return is_in ? "in" : "out"; 3637 - } 3638 - 3639 - /** 3640 - * ep_show - debugfs: show the state of an endpoint. 3641 - * @seq: The seq_file to write data to. 3642 - * @v: Unused parameter. 3643 - * 3644 - * This debugfs entry shows the state of the given endpoint (one is 3645 - * registered for each available). 3646 - */ 3647 - static int ep_show(struct seq_file *seq, void *v) 3648 - { 3649 - struct s3c_hsotg_ep *ep = seq->private; 3650 - struct dwc2_hsotg *hsotg = ep->parent; 3651 - struct s3c_hsotg_req *req; 3652 - void __iomem *regs = hsotg->regs; 3653 - int index = ep->index; 3654 - int show_limit = 15; 3655 - unsigned long flags; 3656 - 3657 - seq_printf(seq, "Endpoint index %d, named %s, dir %s:\n", 3658 - ep->index, ep->ep.name, decode_direction(ep->dir_in)); 3659 - 3660 - /* first show the register state */ 3661 - 3662 - seq_printf(seq, "\tDIEPCTL=0x%08x, DOEPCTL=0x%08x\n", 3663 - readl(regs + DIEPCTL(index)), 3664 - readl(regs + DOEPCTL(index))); 3665 - 3666 - seq_printf(seq, "\tDIEPDMA=0x%08x, DOEPDMA=0x%08x\n", 3667 - readl(regs + DIEPDMA(index)), 3668 - readl(regs + DOEPDMA(index))); 3669 - 3670 - seq_printf(seq, "\tDIEPINT=0x%08x, DOEPINT=0x%08x\n", 3671 - readl(regs + DIEPINT(index)), 3672 - readl(regs + DOEPINT(index))); 3673 - 3674 - seq_printf(seq, "\tDIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x\n", 3675 - readl(regs + DIEPTSIZ(index)), 3676 - readl(regs + DOEPTSIZ(index))); 3677 - 3678 - seq_puts(seq, "\n"); 3679 - seq_printf(seq, "mps %d\n", ep->ep.maxpacket); 3680 - seq_printf(seq, "total_data=%ld\n", ep->total_data); 3681 - 3682 - seq_printf(seq, "request list (%p,%p):\n", 3683 - ep->queue.next, ep->queue.prev); 3684 - 3685 - spin_lock_irqsave(&hsotg->lock, flags); 3686 - 3687 - list_for_each_entry(req, &ep->queue, queue) { 3688 - if (--show_limit < 0) { 3689 - seq_puts(seq, "not showing more requests...\n"); 3690 - break; 3691 - } 3692 - 3693 - seq_printf(seq, "%c req %p: %d bytes @%p, ", 3694 - req == ep->req ? '*' : ' ', 3695 - req, req->req.length, req->req.buf); 3696 - seq_printf(seq, "%d done, res %d\n", 3697 - req->req.actual, req->req.status); 3698 - } 3699 - 3700 - spin_unlock_irqrestore(&hsotg->lock, flags); 3701 - 3702 - return 0; 3703 - } 3704 - 3705 - static int ep_open(struct inode *inode, struct file *file) 3706 - { 3707 - return single_open(file, ep_show, inode->i_private); 3708 - } 3709 - 3710 - static const struct file_operations ep_fops = { 3711 - .owner = THIS_MODULE, 3712 - .open = ep_open, 3713 - .read = seq_read, 3714 - .llseek = seq_lseek, 3715 - .release = single_release, 3716 - }; 3717 - 3718 - /** 3719 - * s3c_hsotg_create_debug - create debugfs directory and files 3720 - * @hsotg: The driver state 3721 - * 3722 - * Create the debugfs files to allow the user to get information 3723 - * about the state of the system. The directory name is created 3724 - * with the same name as the device itself, in case we end up 3725 - * with multiple blocks in future systems. 3726 - */ 3727 - static void s3c_hsotg_create_debug(struct dwc2_hsotg *hsotg) 3728 - { 3729 - struct dentry *root; 3730 - unsigned epidx; 3731 - 3732 - root = debugfs_create_dir(dev_name(hsotg->dev), NULL); 3733 - hsotg->debug_root = root; 3734 - if (IS_ERR(root)) { 3735 - dev_err(hsotg->dev, "cannot create debug root\n"); 3736 - return; 3737 - } 3738 - 3739 - /* create general state file */ 3740 - 3741 - hsotg->debug_file = debugfs_create_file("state", S_IRUGO, root, 3742 - hsotg, &state_fops); 3743 - 3744 - if (IS_ERR(hsotg->debug_file)) 3745 - dev_err(hsotg->dev, "%s: failed to create state\n", __func__); 3746 - 3747 - hsotg->debug_testmode = debugfs_create_file("testmode", 3748 - S_IRUGO | S_IWUSR, root, 3749 - hsotg, &testmode_fops); 3750 - 3751 - if (IS_ERR(hsotg->debug_testmode)) 3752 - dev_err(hsotg->dev, "%s: failed to create testmode\n", 3753 - __func__); 3754 - 3755 - hsotg->debug_fifo = debugfs_create_file("fifo", S_IRUGO, root, 3756 - hsotg, &fifo_fops); 3757 - 3758 - if (IS_ERR(hsotg->debug_fifo)) 3759 - dev_err(hsotg->dev, "%s: failed to create fifo\n", __func__); 3760 - 3761 - /* Create one file for each out endpoint */ 3762 - for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { 3763 - struct s3c_hsotg_ep *ep; 3764 - 3765 - ep = hsotg->eps_out[epidx]; 3766 - if (ep) { 3767 - ep->debugfs = debugfs_create_file(ep->name, S_IRUGO, 3768 - root, ep, &ep_fops); 3769 - 3770 - if (IS_ERR(ep->debugfs)) 3771 - dev_err(hsotg->dev, "failed to create %s debug file\n", 3772 - ep->name); 3773 - } 3774 - } 3775 - /* Create one file for each in endpoint. EP0 is handled with out eps */ 3776 - for (epidx = 1; epidx < hsotg->num_of_eps; epidx++) { 3777 - struct s3c_hsotg_ep *ep; 3778 - 3779 - ep = hsotg->eps_in[epidx]; 3780 - if (ep) { 3781 - ep->debugfs = debugfs_create_file(ep->name, S_IRUGO, 3782 - root, ep, &ep_fops); 3783 - 3784 - if (IS_ERR(ep->debugfs)) 3785 - dev_err(hsotg->dev, "failed to create %s debug file\n", 3786 - ep->name); 3787 - } 3788 - } 3789 - } 3790 - 3791 - /** 3792 - * s3c_hsotg_delete_debug - cleanup debugfs entries 3793 - * @hsotg: The driver state 3794 - * 3795 - * Cleanup (remove) the debugfs files for use on module exit. 3796 - */ 3797 - static void s3c_hsotg_delete_debug(struct dwc2_hsotg *hsotg) 3798 - { 3799 - unsigned epidx; 3800 - 3801 - for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { 3802 - if (hsotg->eps_in[epidx]) 3803 - debugfs_remove(hsotg->eps_in[epidx]->debugfs); 3804 - if (hsotg->eps_out[epidx]) 3805 - debugfs_remove(hsotg->eps_out[epidx]->debugfs); 3806 - } 3807 - 3808 - debugfs_remove(hsotg->debug_file); 3809 - debugfs_remove(hsotg->debug_testmode); 3810 - debugfs_remove(hsotg->debug_fifo); 3811 - debugfs_remove(hsotg->debug_root); 3812 - } 3813 - 3814 3394 #ifdef CONFIG_OF 3815 3395 static void s3c_hsotg_of_probe(struct dwc2_hsotg *hsotg) 3816 3396 { ··· 3520 3896 hsotg->gadget.max_speed = USB_SPEED_HIGH; 3521 3897 hsotg->gadget.ops = &s3c_hsotg_gadget_ops; 3522 3898 hsotg->gadget.name = dev_name(dev); 3899 + if (hsotg->dr_mode == USB_DR_MODE_OTG) 3900 + hsotg->gadget.is_otg = 1; 3523 3901 3524 3902 /* reset the system */ 3525 3903 ··· 3654 4028 if (ret) 3655 4029 goto err_supplies; 3656 4030 3657 - s3c_hsotg_create_debug(hsotg); 3658 - 3659 4031 s3c_hsotg_dump(hsotg); 3660 4032 3661 4033 return 0; ··· 3665 4041 3666 4042 return ret; 3667 4043 } 3668 - EXPORT_SYMBOL_GPL(dwc2_gadget_init); 3669 4044 3670 4045 /** 3671 4046 * s3c_hsotg_remove - remove function for hsotg driver ··· 3673 4050 int s3c_hsotg_remove(struct dwc2_hsotg *hsotg) 3674 4051 { 3675 4052 usb_del_gadget_udc(&hsotg->gadget); 3676 - s3c_hsotg_delete_debug(hsotg); 3677 4053 clk_disable_unprepare(hsotg->clk); 3678 4054 3679 4055 return 0; 3680 4056 } 3681 - EXPORT_SYMBOL_GPL(s3c_hsotg_remove); 3682 4057 3683 4058 int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg) 3684 4059 { 3685 4060 unsigned long flags; 3686 4061 int ret = 0; 4062 + 4063 + if (hsotg->lx_state != DWC2_L0) 4064 + return ret; 3687 4065 3688 4066 mutex_lock(&hsotg->init_mutex); 3689 4067 ··· 3719 4095 3720 4096 return ret; 3721 4097 } 3722 - EXPORT_SYMBOL_GPL(s3c_hsotg_suspend); 3723 4098 3724 4099 int s3c_hsotg_resume(struct dwc2_hsotg *hsotg) 3725 4100 { 3726 4101 unsigned long flags; 3727 4102 int ret = 0; 4103 + 4104 + if (hsotg->lx_state == DWC2_L2) 4105 + return ret; 3728 4106 3729 4107 mutex_lock(&hsotg->init_mutex); 3730 4108 ··· 3750 4124 3751 4125 return ret; 3752 4126 } 3753 - EXPORT_SYMBOL_GPL(s3c_hsotg_resume);
+51 -49
drivers/usb/dwc2/hcd.c
··· 357 357 writel(0, hsotg->regs + HPRT0); 358 358 } 359 359 360 + /* Caller must hold driver lock */ 360 361 static int dwc2_hcd_urb_enqueue(struct dwc2_hsotg *hsotg, 361 362 struct dwc2_hcd_urb *urb, void **ep_handle, 362 363 gfp_t mem_flags) 363 364 { 364 365 struct dwc2_qtd *qtd; 365 - unsigned long flags; 366 366 u32 intr_mask; 367 367 int retval; 368 368 int dev_speed; ··· 413 413 */ 414 414 return 0; 415 415 416 - spin_lock_irqsave(&hsotg->lock, flags); 417 416 tr_type = dwc2_hcd_select_transactions(hsotg); 418 417 if (tr_type != DWC2_TRANSACTION_NONE) 419 418 dwc2_hcd_queue_transactions(hsotg, tr_type); 420 - spin_unlock_irqrestore(&hsotg->lock, flags); 421 419 } 422 420 423 421 return 0; ··· 719 721 /* 3072 = 3 max-size Isoc packets */ 720 722 buf_size = 3072; 721 723 722 - qh->dw_align_buf = dma_alloc_coherent(hsotg->dev, buf_size, 723 - &qh->dw_align_buf_dma, 724 - GFP_ATOMIC); 724 + qh->dw_align_buf = kmalloc(buf_size, GFP_ATOMIC | GFP_DMA); 725 725 if (!qh->dw_align_buf) 726 726 return -ENOMEM; 727 727 qh->dw_align_buf_size = buf_size; ··· 742 746 } else { 743 747 dev_warn(hsotg->dev, "no URB in dwc2_urb\n"); 744 748 } 749 + } 750 + 751 + qh->dw_align_buf_dma = dma_map_single(hsotg->dev, 752 + qh->dw_align_buf, qh->dw_align_buf_size, 753 + chan->ep_is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 754 + if (dma_mapping_error(hsotg->dev, qh->dw_align_buf_dma)) { 755 + dev_err(hsotg->dev, "can't map align_buf\n"); 756 + chan->align_buf = 0; 757 + return -EINVAL; 745 758 } 746 759 747 760 chan->align_buf = qh->dw_align_buf_dma; ··· 1779 1774 /* Not supported */ 1780 1775 break; 1781 1776 1777 + case USB_PORT_FEAT_TEST: 1778 + hprt0 = dwc2_read_hprt0(hsotg); 1779 + dev_dbg(hsotg->dev, 1780 + "SetPortFeature - USB_PORT_FEAT_TEST\n"); 1781 + hprt0 &= ~HPRT0_TSTCTL_MASK; 1782 + hprt0 |= (windex >> 8) << HPRT0_TSTCTL_SHIFT; 1783 + writel(hprt0, hsotg->regs + HPRT0); 1784 + break; 1785 + 1782 1786 default: 1783 1787 retval = -EINVAL; 1784 1788 dev_err(hsotg->dev, ··· 2327 2313 usleep_range(1000, 3000); 2328 2314 } 2329 2315 2316 + static int _dwc2_hcd_suspend(struct usb_hcd *hcd) 2317 + { 2318 + struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); 2319 + 2320 + hsotg->lx_state = DWC2_L2; 2321 + return 0; 2322 + } 2323 + 2324 + static int _dwc2_hcd_resume(struct usb_hcd *hcd) 2325 + { 2326 + struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); 2327 + 2328 + hsotg->lx_state = DWC2_L0; 2329 + return 0; 2330 + } 2331 + 2330 2332 /* Returns the current frame number */ 2331 2333 static int _dwc2_hcd_get_frame_number(struct usb_hcd *hcd) 2332 2334 { ··· 2498 2468 "%s: unaligned transfer with no transfer_buffer", 2499 2469 __func__); 2500 2470 retval = -EINVAL; 2501 - goto fail1; 2471 + goto fail0; 2502 2472 } 2503 2473 } 2504 2474 ··· 2526 2496 2527 2497 spin_lock_irqsave(&hsotg->lock, flags); 2528 2498 retval = usb_hcd_link_urb_to_ep(hcd, urb); 2529 - spin_unlock_irqrestore(&hsotg->lock, flags); 2530 2499 if (retval) 2531 2500 goto fail1; 2532 2501 ··· 2534 2505 goto fail2; 2535 2506 2536 2507 if (alloc_bandwidth) { 2537 - spin_lock_irqsave(&hsotg->lock, flags); 2538 2508 dwc2_allocate_bus_bandwidth(hcd, 2539 2509 dwc2_hcd_get_ep_bandwidth(hsotg, ep), 2540 2510 urb); 2541 - spin_unlock_irqrestore(&hsotg->lock, flags); 2542 2511 } 2512 + 2513 + spin_unlock_irqrestore(&hsotg->lock, flags); 2543 2514 2544 2515 return 0; 2545 2516 2546 2517 fail2: 2547 - spin_lock_irqsave(&hsotg->lock, flags); 2548 2518 dwc2_urb->priv = NULL; 2549 2519 usb_hcd_unlink_urb_from_ep(hcd, urb); 2550 - spin_unlock_irqrestore(&hsotg->lock, flags); 2551 2520 fail1: 2521 + spin_unlock_irqrestore(&hsotg->lock, flags); 2552 2522 urb->hcpriv = NULL; 2523 + fail0: 2553 2524 kfree(dwc2_urb); 2554 2525 2555 2526 return retval; ··· 2712 2683 .hub_status_data = _dwc2_hcd_hub_status_data, 2713 2684 .hub_control = _dwc2_hcd_hub_control, 2714 2685 .clear_tt_buffer_complete = _dwc2_hcd_clear_tt_buffer_complete, 2686 + 2687 + .bus_suspend = _dwc2_hcd_suspend, 2688 + .bus_resume = _dwc2_hcd_resume, 2715 2689 }; 2716 2690 2717 2691 /* ··· 2780 2748 destroy_workqueue(hsotg->wq_otg); 2781 2749 } 2782 2750 2783 - kfree(hsotg->core_params); 2784 - hsotg->core_params = NULL; 2785 2751 del_timer(&hsotg->wkp_timer); 2786 2752 } 2787 2753 ··· 2792 2762 } 2793 2763 2794 2764 /* 2795 - * Sets all parameters to the given value. 2796 - * 2797 - * Assumes that the dwc2_core_params struct contains only integers. 2798 - */ 2799 - void dwc2_set_all_params(struct dwc2_core_params *params, int value) 2800 - { 2801 - int *p = (int *)params; 2802 - size_t size = sizeof(*params) / sizeof(*p); 2803 - int i; 2804 - 2805 - for (i = 0; i < size; i++) 2806 - p[i] = value; 2807 - } 2808 - EXPORT_SYMBOL_GPL(dwc2_set_all_params); 2809 - 2810 - /* 2811 2765 * Initializes the HCD. This function allocates memory for and initializes the 2812 2766 * static parts of the usb_hcd and dwc2_hsotg structures. It also registers the 2813 2767 * USB bus with the core and calls the hc_driver->start() function. It returns 2814 2768 * a negative error on failure. 2815 2769 */ 2816 - int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, 2817 - const struct dwc2_core_params *params) 2770 + int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq) 2818 2771 { 2819 2772 struct usb_hcd *hcd; 2820 2773 struct dwc2_host_chan *channel; ··· 2809 2796 return -ENODEV; 2810 2797 2811 2798 dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n"); 2812 - 2813 - /* Detect config values from hardware */ 2814 - retval = dwc2_get_hwparams(hsotg); 2815 - 2816 - if (retval) 2817 - return retval; 2818 2799 2819 2800 retval = -ENOMEM; 2820 2801 ··· 2827 2820 goto error1; 2828 2821 hsotg->last_frame_num = HFNUM_MAX_FRNUM; 2829 2822 #endif 2830 - 2831 - hsotg->core_params = kzalloc(sizeof(*hsotg->core_params), GFP_KERNEL); 2832 - if (!hsotg->core_params) 2833 - goto error1; 2834 - 2835 - dwc2_set_all_params(hsotg->core_params, -1); 2836 - 2837 - /* Validate parameter values */ 2838 - dwc2_set_parameters(hsotg, params); 2839 2823 2840 2824 /* Check if the bus driver or platform code has setup a dma_mask */ 2841 2825 if (hsotg->core_params->dma_enable > 0 && ··· 2945 2947 /* Don't support SG list at this point */ 2946 2948 hcd->self.sg_tablesize = 0; 2947 2949 2950 + if (!IS_ERR_OR_NULL(hsotg->uphy)) 2951 + otg_set_host(hsotg->uphy->otg, &hcd->self); 2952 + 2948 2953 /* 2949 2954 * Finish generic HCD initialization and start the HCD. This function 2950 2955 * allocates the DMA buffer pool, registers the USB bus, requests the ··· 2980 2979 dev_err(hsotg->dev, "%s() FAILED, returning %d\n", __func__, retval); 2981 2980 return retval; 2982 2981 } 2983 - EXPORT_SYMBOL_GPL(dwc2_hcd_init); 2984 2982 2985 2983 /* 2986 2984 * Removes the HCD. ··· 3000 3000 return; 3001 3001 } 3002 3002 3003 + if (!IS_ERR_OR_NULL(hsotg->uphy)) 3004 + otg_set_host(hsotg->uphy->otg, NULL); 3005 + 3003 3006 usb_remove_hcd(hcd); 3004 3007 hsotg->priv = NULL; 3005 3008 dwc2_hcd_release(hsotg); ··· 3013 3010 kfree(hsotg->frame_num_array); 3014 3011 #endif 3015 3012 } 3016 - EXPORT_SYMBOL_GPL(dwc2_hcd_remove);
+1 -6
drivers/usb/dwc2/hcd.h
··· 451 451 return !dwc2_hcd_is_pipe_in(pipe); 452 452 } 453 453 454 - extern int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, 455 - const struct dwc2_core_params *params); 454 + extern int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq); 456 455 extern void dwc2_hcd_remove(struct dwc2_hsotg *hsotg); 457 - extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg, 458 - const struct dwc2_core_params *params); 459 - extern void dwc2_set_all_params(struct dwc2_core_params *params, int value); 460 - extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg); 461 456 462 457 /* Transaction Execution Functions */ 463 458 extern enum dwc2_transaction_type dwc2_hcd_select_transactions(
+51 -15
drivers/usb/dwc2/hcd_intr.c
··· 350 350 dev_vdbg(hsotg->dev, 351 351 "--Port Interrupt HPRT0=0x%08x Port Connect Detected--\n", 352 352 hprt0); 353 + if (hsotg->lx_state != DWC2_L0) 354 + usb_hcd_resume_root_hub(hsotg->priv); 355 + 353 356 hsotg->flags.b.port_connect_status_change = 1; 354 357 hsotg->flags.b.port_connect_status = 1; 355 358 hprt0_modify |= HPRT0_CONNDET; ··· 466 463 } 467 464 468 465 /* Non DWORD-aligned buffer case handling */ 469 - if (chan->align_buf && xfer_length && chan->ep_is_in) { 466 + if (chan->align_buf && xfer_length) { 470 467 dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); 471 - memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf, 472 - xfer_length); 468 + dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma, 469 + chan->qh->dw_align_buf_size, 470 + chan->ep_is_in ? 471 + DMA_FROM_DEVICE : DMA_TO_DEVICE); 472 + if (chan->ep_is_in) 473 + memcpy(urb->buf + urb->actual_length, 474 + chan->qh->dw_align_buf, xfer_length); 473 475 } 474 476 475 477 dev_vdbg(hsotg->dev, "urb->actual_length=%d xfer_length=%d\n", ··· 560 552 chan, chnum, qtd, halt_status, NULL); 561 553 562 554 /* Non DWORD-aligned buffer case handling */ 563 - if (chan->align_buf && frame_desc->actual_length && 564 - chan->ep_is_in) { 555 + if (chan->align_buf && frame_desc->actual_length) { 565 556 dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", 566 557 __func__); 567 - memcpy(urb->buf + frame_desc->offset + 568 - qtd->isoc_split_offset, chan->qh->dw_align_buf, 569 - frame_desc->actual_length); 558 + dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma, 559 + chan->qh->dw_align_buf_size, 560 + chan->ep_is_in ? 561 + DMA_FROM_DEVICE : DMA_TO_DEVICE); 562 + if (chan->ep_is_in) 563 + memcpy(urb->buf + frame_desc->offset + 564 + qtd->isoc_split_offset, 565 + chan->qh->dw_align_buf, 566 + frame_desc->actual_length); 570 567 } 571 568 break; 572 569 case DWC2_HC_XFER_FRAME_OVERRUN: ··· 594 581 chan, chnum, qtd, halt_status, NULL); 595 582 596 583 /* Non DWORD-aligned buffer case handling */ 597 - if (chan->align_buf && frame_desc->actual_length && 598 - chan->ep_is_in) { 584 + if (chan->align_buf && frame_desc->actual_length) { 599 585 dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", 600 586 __func__); 601 - memcpy(urb->buf + frame_desc->offset + 602 - qtd->isoc_split_offset, chan->qh->dw_align_buf, 603 - frame_desc->actual_length); 587 + dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma, 588 + chan->qh->dw_align_buf_size, 589 + chan->ep_is_in ? 590 + DMA_FROM_DEVICE : DMA_TO_DEVICE); 591 + if (chan->ep_is_in) 592 + memcpy(urb->buf + frame_desc->offset + 593 + qtd->isoc_split_offset, 594 + chan->qh->dw_align_buf, 595 + frame_desc->actual_length); 604 596 } 605 597 606 598 /* Skip whole frame */ ··· 941 923 942 924 if (chan->align_buf) { 943 925 dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); 926 + dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma, 927 + chan->qh->dw_align_buf_size, DMA_FROM_DEVICE); 944 928 memcpy(qtd->urb->buf + frame_desc->offset + 945 929 qtd->isoc_split_offset, chan->qh->dw_align_buf, len); 946 930 } ··· 1172 1152 /* Non DWORD-aligned buffer case handling */ 1173 1153 if (chan->align_buf && xfer_length && chan->ep_is_in) { 1174 1154 dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); 1175 - memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf, 1176 - xfer_length); 1155 + dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma, 1156 + chan->qh->dw_align_buf_size, 1157 + chan->ep_is_in ? 1158 + DMA_FROM_DEVICE : DMA_TO_DEVICE); 1159 + if (chan->ep_is_in) 1160 + memcpy(urb->buf + urb->actual_length, 1161 + chan->qh->dw_align_buf, 1162 + xfer_length); 1177 1163 } 1178 1164 1179 1165 urb->actual_length += xfer_length; ··· 1208 1182 struct dwc2_host_chan *chan, int chnum, 1209 1183 struct dwc2_qtd *qtd) 1210 1184 { 1185 + if (!qtd) { 1186 + dev_dbg(hsotg->dev, "%s: qtd is NULL\n", __func__); 1187 + return; 1188 + } 1189 + 1190 + if (!qtd->urb) { 1191 + dev_dbg(hsotg->dev, "%s: qtd->urb is NULL\n", __func__); 1192 + return; 1193 + } 1194 + 1211 1195 if (dbg_hc(chan)) 1212 1196 dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NAK Received--\n", 1213 1197 chnum);
+7 -11
drivers/usb/dwc2/hcd_queue.c
··· 229 229 */ 230 230 void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) 231 231 { 232 - if (hsotg->core_params->dma_desc_enable > 0) 232 + if (hsotg->core_params->dma_desc_enable > 0) { 233 233 dwc2_hcd_qh_free_ddma(hsotg, qh); 234 - else if (qh->dw_align_buf) 235 - dma_free_coherent(hsotg->dev, qh->dw_align_buf_size, 236 - qh->dw_align_buf, qh->dw_align_buf_dma); 234 + } else { 235 + /* kfree(NULL) is safe */ 236 + kfree(qh->dw_align_buf); 237 + qh->dw_align_buf_dma = (dma_addr_t)0; 238 + } 237 239 kfree(qh); 238 240 } 239 241 ··· 763 761 764 762 /** 765 763 * dwc2_hcd_qtd_add() - Adds a QTD to the QTD-list of a QH 764 + * Caller must hold driver lock. 766 765 * 767 766 * @hsotg: The DWC HCD structure 768 767 * @qtd: The QTD to add ··· 780 777 struct dwc2_qh **qh, gfp_t mem_flags) 781 778 { 782 779 struct dwc2_hcd_urb *urb = qtd->urb; 783 - unsigned long flags; 784 780 int allocated = 0; 785 781 int retval; 786 782 ··· 794 792 allocated = 1; 795 793 } 796 794 797 - spin_lock_irqsave(&hsotg->lock, flags); 798 - 799 795 retval = dwc2_hcd_qh_add(hsotg, *qh); 800 796 if (retval) 801 797 goto fail; 802 798 803 799 qtd->qh = *qh; 804 800 list_add_tail(&qtd->qtd_list_entry, &(*qh)->qtd_list); 805 - spin_unlock_irqrestore(&hsotg->lock, flags); 806 801 807 802 return 0; 808 803 ··· 816 817 qtd_list_entry) 817 818 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd2, qh_tmp); 818 819 819 - spin_unlock_irqrestore(&hsotg->lock, flags); 820 820 dwc2_hcd_qh_free(hsotg, qh_tmp); 821 - } else { 822 - spin_unlock_irqrestore(&hsotg->lock, flags); 823 821 } 824 822 825 823 return retval;
+24 -1
drivers/usb/dwc2/platform.c
··· 47 47 48 48 #include "core.h" 49 49 #include "hcd.h" 50 + #include "debug.h" 50 51 51 52 static const char dwc2_driver_name[] = "dwc2"; 52 53 ··· 77 76 .reload_ctl = 0, 78 77 .ahbcfg = 0x10, 79 78 .uframe_sched = 0, 79 + .external_id_pin_ctl = -1, 80 + .hibernation = -1, 80 81 }; 81 82 82 83 static const struct dwc2_core_params params_rk3066 = { ··· 107 104 .reload_ctl = -1, 108 105 .ahbcfg = 0x7, /* INCR16 */ 109 106 .uframe_sched = -1, 107 + .external_id_pin_ctl = -1, 108 + .hibernation = -1, 110 109 }; 111 110 112 111 /** ··· 126 121 { 127 122 struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); 128 123 124 + dwc2_debugfs_exit(hsotg); 129 125 if (hsotg->hcd_enabled) 130 126 dwc2_hcd_remove(hsotg); 131 127 if (hsotg->gadget_enabled) ··· 243 237 spin_lock_init(&hsotg->lock); 244 238 mutex_init(&hsotg->init_mutex); 245 239 240 + /* Detect config values from hardware */ 241 + retval = dwc2_get_hwparams(hsotg); 242 + if (retval) 243 + return retval; 244 + 245 + hsotg->core_params = devm_kzalloc(&dev->dev, 246 + sizeof(*hsotg->core_params), GFP_KERNEL); 247 + if (!hsotg->core_params) 248 + return -ENOMEM; 249 + 250 + dwc2_set_all_params(hsotg->core_params, -1); 251 + 252 + /* Validate parameter values */ 253 + dwc2_set_parameters(hsotg, params); 254 + 246 255 if (hsotg->dr_mode != USB_DR_MODE_HOST) { 247 256 retval = dwc2_gadget_init(hsotg, irq); 248 257 if (retval) ··· 266 245 } 267 246 268 247 if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { 269 - retval = dwc2_hcd_init(hsotg, irq, params); 248 + retval = dwc2_hcd_init(hsotg, irq); 270 249 if (retval) { 271 250 if (hsotg->gadget_enabled) 272 251 s3c_hsotg_remove(hsotg); ··· 276 255 } 277 256 278 257 platform_set_drvdata(dev, hsotg); 258 + 259 + dwc2_debugfs_init(hsotg); 279 260 280 261 return retval; 281 262 }
+7
drivers/usb/dwc3/Kconfig
··· 11 11 12 12 if USB_DWC3 13 13 14 + config USB_DWC3_ULPI 15 + bool "Register ULPI PHY Interface" 16 + depends on USB_ULPI_BUS=y || USB_ULPI_BUS=USB_DWC3 17 + help 18 + Select this if you have ULPI type PHY attached to your DWC3 19 + controller. 20 + 14 21 choice 15 22 bool "DWC3 Mode Selection" 16 23 default USB_DWC3_DUAL_ROLE if (USB && USB_GADGET)
+4
drivers/usb/dwc3/Makefile
··· 15 15 dwc3-y += gadget.o ep0.o 16 16 endif 17 17 18 + ifneq ($(CONFIG_USB_DWC3_ULPI),) 19 + dwc3-y += ulpi.o 20 + endif 21 + 18 22 ifneq ($(CONFIG_DEBUG_FS),) 19 23 dwc3-y += debugfs.o 20 24 endif
+83 -25
drivers/usb/dwc3/core.c
··· 117 117 } 118 118 119 119 /** 120 + * dwc3_soft_reset - Issue soft reset 121 + * @dwc: Pointer to our controller context structure 122 + */ 123 + static int dwc3_soft_reset(struct dwc3 *dwc) 124 + { 125 + unsigned long timeout; 126 + u32 reg; 127 + 128 + timeout = jiffies + msecs_to_jiffies(500); 129 + dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST); 130 + do { 131 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 132 + if (!(reg & DWC3_DCTL_CSFTRST)) 133 + break; 134 + 135 + if (time_after(jiffies, timeout)) { 136 + dev_err(dwc->dev, "Reset Timed Out\n"); 137 + return -ETIMEDOUT; 138 + } 139 + 140 + cpu_relax(); 141 + } while (true); 142 + 143 + return 0; 144 + } 145 + 146 + /** 120 147 * dwc3_free_one_event_buffer - Frees one event buffer 121 148 * @dwc: Pointer to our controller context structure 122 149 * @evt: Pointer to event buffer to be freed ··· 394 367 /** 395 368 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core 396 369 * @dwc: Pointer to our controller context structure 370 + * 371 + * Returns 0 on success. The USB PHY interfaces are configured but not 372 + * initialized. The PHY interfaces and the PHYs get initialized together with 373 + * the core in dwc3_core_init. 397 374 */ 398 - static void dwc3_phy_setup(struct dwc3 *dwc) 375 + static int dwc3_phy_setup(struct dwc3 *dwc) 399 376 { 400 377 u32 reg; 378 + int ret; 401 379 402 380 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); 403 381 ··· 441 409 442 410 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); 443 411 444 - mdelay(100); 445 - 446 412 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); 413 + 414 + /* Select the HS PHY interface */ 415 + switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { 416 + case DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI: 417 + if (!strncmp(dwc->hsphy_interface, "utmi", 4)) { 418 + reg &= ~DWC3_GUSB2PHYCFG_ULPI_UTMI; 419 + break; 420 + } else if (!strncmp(dwc->hsphy_interface, "ulpi", 4)) { 421 + reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI; 422 + dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); 423 + } else { 424 + dev_warn(dwc->dev, "HSPHY Interface not defined\n"); 425 + 426 + /* Relying on default value. */ 427 + if (!(reg & DWC3_GUSB2PHYCFG_ULPI_UTMI)) 428 + break; 429 + } 430 + /* FALLTHROUGH */ 431 + case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI: 432 + /* Making sure the interface and PHY are operational */ 433 + ret = dwc3_soft_reset(dwc); 434 + if (ret) 435 + return ret; 436 + 437 + udelay(1); 438 + 439 + ret = dwc3_ulpi_init(dwc); 440 + if (ret) 441 + return ret; 442 + /* FALLTHROUGH */ 443 + default: 444 + break; 445 + } 447 446 448 447 /* 449 448 * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to ··· 490 427 491 428 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); 492 429 493 - mdelay(100); 430 + return 0; 494 431 } 495 432 496 433 /** ··· 501 438 */ 502 439 static int dwc3_core_init(struct dwc3 *dwc) 503 440 { 504 - unsigned long timeout; 505 441 u32 hwparams4 = dwc->hwparams.hwparams4; 506 442 u32 reg; 507 443 int ret; ··· 528 466 } 529 467 530 468 /* issue device SoftReset too */ 531 - timeout = jiffies + msecs_to_jiffies(500); 532 - dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST); 533 - do { 534 - reg = dwc3_readl(dwc->regs, DWC3_DCTL); 535 - if (!(reg & DWC3_DCTL_CSFTRST)) 536 - break; 537 - 538 - if (time_after(jiffies, timeout)) { 539 - dev_err(dwc->dev, "Reset Timed Out\n"); 540 - ret = -ETIMEDOUT; 541 - goto err0; 542 - } 543 - 544 - cpu_relax(); 545 - } while (true); 469 + ret = dwc3_soft_reset(dwc); 470 + if (ret) 471 + goto err0; 546 472 547 473 ret = dwc3_core_soft_reset(dwc); 548 474 if (ret) ··· 604 554 dwc3_core_num_eps(dwc); 605 555 606 556 dwc3_writel(dwc->regs, DWC3_GCTL, reg); 607 - 608 - dwc3_phy_setup(dwc); 609 557 610 558 ret = dwc3_alloc_scratch_buffers(dwc); 611 559 if (ret) ··· 884 836 "snps,tx_de_emphasis_quirk"); 885 837 of_property_read_u8(node, "snps,tx_de_emphasis", 886 838 &tx_de_emphasis); 839 + of_property_read_string(node, "snps,hsphy_interface", 840 + &dwc->hsphy_interface); 887 841 } else if (pdata) { 888 842 dwc->maximum_speed = pdata->maximum_speed; 889 843 dwc->has_lpm_erratum = pdata->has_lpm_erratum; ··· 913 863 dwc->tx_de_emphasis_quirk = pdata->tx_de_emphasis_quirk; 914 864 if (pdata->tx_de_emphasis) 915 865 tx_de_emphasis = pdata->tx_de_emphasis; 866 + 867 + dwc->hsphy_interface = pdata->hsphy_interface; 916 868 } 917 869 918 870 /* default to superspeed if no maximum_speed passed */ ··· 927 875 dwc->hird_threshold = hird_threshold 928 876 | (dwc->is_utmi_l1_suspend << 4); 929 877 878 + platform_set_drvdata(pdev, dwc); 879 + dwc3_cache_hwparams(dwc); 880 + 881 + ret = dwc3_phy_setup(dwc); 882 + if (ret) 883 + goto err0; 884 + 930 885 ret = dwc3_core_get_phy(dwc); 931 886 if (ret) 932 887 goto err0; 933 888 934 889 spin_lock_init(&dwc->lock); 935 - platform_set_drvdata(pdev, dwc); 936 890 937 891 if (!dev->dma_mask) { 938 892 dev->dma_mask = dev->parent->dma_mask; ··· 949 891 pm_runtime_enable(dev); 950 892 pm_runtime_get_sync(dev); 951 893 pm_runtime_forbid(dev); 952 - 953 - dwc3_cache_hwparams(dwc); 954 894 955 895 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); 956 896 if (ret) { ··· 1020 964 1021 965 err1: 1022 966 dwc3_free_event_buffers(dwc); 967 + dwc3_ulpi_exit(dwc); 1023 968 1024 969 err0: 1025 970 /* ··· 1056 999 phy_power_off(dwc->usb3_generic_phy); 1057 1000 1058 1001 dwc3_core_exit(dwc); 1002 + dwc3_ulpi_exit(dwc); 1059 1003 1060 1004 pm_runtime_put_sync(&pdev->dev); 1061 1005 pm_runtime_disable(&pdev->dev);
+26
drivers/usb/dwc3/core.h
··· 30 30 #include <linux/usb/ch9.h> 31 31 #include <linux/usb/gadget.h> 32 32 #include <linux/usb/otg.h> 33 + #include <linux/ulpi/interface.h> 33 34 34 35 #include <linux/phy/phy.h> 35 36 ··· 174 173 /* Global USB2 PHY Configuration Register */ 175 174 #define DWC3_GUSB2PHYCFG_PHYSOFTRST (1 << 31) 176 175 #define DWC3_GUSB2PHYCFG_SUSPHY (1 << 6) 176 + #define DWC3_GUSB2PHYCFG_ULPI_UTMI (1 << 4) 177 + 178 + /* Global USB2 PHY Vendor Control Register */ 179 + #define DWC3_GUSB2PHYACC_NEWREGREQ (1 << 25) 180 + #define DWC3_GUSB2PHYACC_BUSY (1 << 23) 181 + #define DWC3_GUSB2PHYACC_WRITE (1 << 22) 182 + #define DWC3_GUSB2PHYACC_ADDR(n) (n << 16) 183 + #define DWC3_GUSB2PHYACC_EXTEND_ADDR(n) (n << 8) 184 + #define DWC3_GUSB2PHYACC_DATA(n) (n & 0xff) 177 185 178 186 /* Global USB3 PIPE Control Register */ 179 187 #define DWC3_GUSB3PIPECTL_PHYSOFTRST (1 << 31) ··· 662 652 * @usb3_phy: pointer to USB3 PHY 663 653 * @usb2_generic_phy: pointer to USB2 PHY 664 654 * @usb3_generic_phy: pointer to USB3 PHY 655 + * @ulpi: pointer to ulpi interface 665 656 * @dcfg: saved contents of DCFG register 666 657 * @gctl: saved contents of GCTL register 667 658 * @isoch_delay: wValue from Set Isochronous Delay request; ··· 684 673 * @test_mode_nr: test feature selector 685 674 * @lpm_nyet_threshold: LPM NYET response threshold 686 675 * @hird_threshold: HIRD threshold 676 + * @hsphy_interface: "utmi" or "ulpi" 687 677 * @delayed_status: true when gadget driver asks for delayed status 688 678 * @ep0_bounced: true when we used bounce buffer 689 679 * @ep0_expect_in: true when we expect a DATA IN transfer ··· 751 739 struct phy *usb2_generic_phy; 752 740 struct phy *usb3_generic_phy; 753 741 742 + struct ulpi *ulpi; 743 + 754 744 void __iomem *regs; 755 745 size_t regs_size; 756 746 ··· 813 799 u8 test_mode_nr; 814 800 u8 lpm_nyet_threshold; 815 801 u8 hird_threshold; 802 + 803 + const char *hsphy_interface; 816 804 817 805 unsigned delayed_status:1; 818 806 unsigned ep0_bounced:1; ··· 1050 1034 return 0; 1051 1035 } 1052 1036 #endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */ 1037 + 1038 + #if IS_ENABLED(CONFIG_USB_DWC3_ULPI) 1039 + int dwc3_ulpi_init(struct dwc3 *dwc); 1040 + void dwc3_ulpi_exit(struct dwc3 *dwc); 1041 + #else 1042 + static inline int dwc3_ulpi_init(struct dwc3 *dwc) 1043 + { return 0; } 1044 + static inline void dwc3_ulpi_exit(struct dwc3 *dwc) 1045 + { } 1046 + #endif 1053 1047 1054 1048 #endif /* __DRIVERS_USB_DWC3_CORE_H */
+36
drivers/usb/dwc3/dwc3-pci.c
··· 21 21 #include <linux/slab.h> 22 22 #include <linux/pci.h> 23 23 #include <linux/platform_device.h> 24 + #include <linux/gpio/consumer.h> 25 + #include <linux/acpi.h> 24 26 25 27 #include "platform_data.h" 26 28 ··· 32 30 #define PCI_DEVICE_ID_INTEL_BSW 0x22B7 33 31 #define PCI_DEVICE_ID_INTEL_SPTLP 0x9d30 34 32 #define PCI_DEVICE_ID_INTEL_SPTH 0xa130 33 + 34 + static const struct acpi_gpio_params reset_gpios = { 0, 0, false }; 35 + static const struct acpi_gpio_params cs_gpios = { 1, 0, false }; 36 + 37 + static const struct acpi_gpio_mapping acpi_dwc3_byt_gpios[] = { 38 + { "reset-gpios", &reset_gpios, 1 }, 39 + { "cs-gpios", &cs_gpios, 1 }, 40 + { }, 41 + }; 35 42 36 43 static int dwc3_pci_quirks(struct pci_dev *pdev) 37 44 { ··· 74 63 75 64 return platform_device_add_data(pci_get_drvdata(pdev), &pdata, 76 65 sizeof(pdata)); 66 + } 67 + 68 + if (pdev->vendor == PCI_VENDOR_ID_INTEL && 69 + pdev->device == PCI_DEVICE_ID_INTEL_BYT) { 70 + struct gpio_desc *gpio; 71 + 72 + acpi_dev_add_driver_gpios(ACPI_COMPANION(&pdev->dev), 73 + acpi_dwc3_byt_gpios); 74 + 75 + /* These GPIOs will turn on the USB2 PHY */ 76 + gpio = gpiod_get(&pdev->dev, "cs"); 77 + if (!IS_ERR(gpio)) { 78 + gpiod_direction_output(gpio, 0); 79 + gpiod_set_value_cansleep(gpio, 1); 80 + gpiod_put(gpio); 81 + } 82 + 83 + gpio = gpiod_get(&pdev->dev, "reset"); 84 + if (!IS_ERR(gpio)) { 85 + gpiod_direction_output(gpio, 0); 86 + gpiod_set_value_cansleep(gpio, 1); 87 + gpiod_put(gpio); 88 + usleep_range(10000, 11000); 89 + } 77 90 } 78 91 79 92 return 0; ··· 163 128 164 129 static void dwc3_pci_remove(struct pci_dev *pci) 165 130 { 131 + acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pci->dev)); 166 132 platform_device_unregister(pci_get_drvdata(pci)); 167 133 } 168 134
+9 -1
drivers/usb/dwc3/gadget.c
··· 291 291 dwc3_trace(trace_dwc3_gadget, 292 292 "Command Complete --> %d", 293 293 DWC3_DGCMD_STATUS(reg)); 294 + if (DWC3_DGCMD_STATUS(reg)) 295 + return -EINVAL; 294 296 return 0; 295 297 } 296 298 ··· 330 328 dwc3_trace(trace_dwc3_gadget, 331 329 "Command Complete --> %d", 332 330 DWC3_DEPCMD_STATUS(reg)); 331 + if (DWC3_DEPCMD_STATUS(reg)) 332 + return -EINVAL; 333 333 return 0; 334 334 } 335 335 ··· 1906 1902 { 1907 1903 unsigned status = 0; 1908 1904 int clean_busy; 1905 + u32 is_xfer_complete; 1906 + 1907 + is_xfer_complete = (event->endpoint_event == DWC3_DEPEVT_XFERCOMPLETE); 1909 1908 1910 1909 if (event->status & DEPEVT_STATUS_BUSERR) 1911 1910 status = -ECONNRESET; 1912 1911 1913 1912 clean_busy = dwc3_cleanup_done_reqs(dwc, dep, event, status); 1914 - if (clean_busy) 1913 + if (clean_busy && (is_xfer_complete || 1914 + usb_endpoint_xfer_isoc(dep->endpoint.desc))) 1915 1915 dep->flags &= ~DWC3_EP_BUSY; 1916 1916 1917 1917 /*
+2
drivers/usb/dwc3/platform_data.h
··· 45 45 46 46 unsigned tx_de_emphasis_quirk:1; 47 47 unsigned tx_de_emphasis:2; 48 + 49 + const char *hsphy_interface; 48 50 };
+91
drivers/usb/dwc3/ulpi.c
··· 1 + /** 2 + * ulpi.c - DesignWare USB3 Controller's ULPI PHY interface 3 + * 4 + * Copyright (C) 2015 Intel Corporation 5 + * 6 + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.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 as 10 + * published by the Free Software Foundation. 11 + */ 12 + 13 + #include <linux/ulpi/regs.h> 14 + 15 + #include "core.h" 16 + #include "io.h" 17 + 18 + #define DWC3_ULPI_ADDR(a) \ 19 + ((a >= ULPI_EXT_VENDOR_SPECIFIC) ? \ 20 + DWC3_GUSB2PHYACC_ADDR(ULPI_ACCESS_EXTENDED) | \ 21 + DWC3_GUSB2PHYACC_EXTEND_ADDR(a) : DWC3_GUSB2PHYACC_ADDR(a)) 22 + 23 + static int dwc3_ulpi_busyloop(struct dwc3 *dwc) 24 + { 25 + unsigned count = 1000; 26 + u32 reg; 27 + 28 + while (count--) { 29 + reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYACC(0)); 30 + if (!(reg & DWC3_GUSB2PHYACC_BUSY)) 31 + return 0; 32 + cpu_relax(); 33 + } 34 + 35 + return -ETIMEDOUT; 36 + } 37 + 38 + static int dwc3_ulpi_read(struct ulpi_ops *ops, u8 addr) 39 + { 40 + struct dwc3 *dwc = dev_get_drvdata(ops->dev); 41 + u32 reg; 42 + int ret; 43 + 44 + reg = DWC3_GUSB2PHYACC_NEWREGREQ | DWC3_ULPI_ADDR(addr); 45 + dwc3_writel(dwc->regs, DWC3_GUSB2PHYACC(0), reg); 46 + 47 + ret = dwc3_ulpi_busyloop(dwc); 48 + if (ret) 49 + return ret; 50 + 51 + reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYACC(0)); 52 + 53 + return DWC3_GUSB2PHYACC_DATA(reg); 54 + } 55 + 56 + static int dwc3_ulpi_write(struct ulpi_ops *ops, u8 addr, u8 val) 57 + { 58 + struct dwc3 *dwc = dev_get_drvdata(ops->dev); 59 + u32 reg; 60 + 61 + reg = DWC3_GUSB2PHYACC_NEWREGREQ | DWC3_ULPI_ADDR(addr); 62 + reg |= DWC3_GUSB2PHYACC_WRITE | val; 63 + dwc3_writel(dwc->regs, DWC3_GUSB2PHYACC(0), reg); 64 + 65 + return dwc3_ulpi_busyloop(dwc); 66 + } 67 + 68 + static struct ulpi_ops dwc3_ulpi_ops = { 69 + .read = dwc3_ulpi_read, 70 + .write = dwc3_ulpi_write, 71 + }; 72 + 73 + int dwc3_ulpi_init(struct dwc3 *dwc) 74 + { 75 + /* Register the interface */ 76 + dwc->ulpi = ulpi_register_interface(dwc->dev, &dwc3_ulpi_ops); 77 + if (IS_ERR(dwc->ulpi)) { 78 + dev_err(dwc->dev, "failed to register ULPI interface"); 79 + return PTR_ERR(dwc->ulpi); 80 + } 81 + 82 + return 0; 83 + } 84 + 85 + void dwc3_ulpi_exit(struct dwc3 *dwc) 86 + { 87 + if (dwc->ulpi) { 88 + ulpi_unregister_interface(dwc->ulpi); 89 + dwc->ulpi = NULL; 90 + } 91 + }
+18 -8
drivers/usb/gadget/epautoconf.c
··· 258 258 /* First, apply chip-specific "best usage" knowledge. 259 259 * This might make a good usb_gadget_ops hook ... 260 260 */ 261 - if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) { 262 - /* ep-e, ep-f are PIO with only 64 byte fifos */ 263 - ep = find_ep (gadget, "ep-e"); 264 - if (ep && ep_matches(gadget, ep, desc, ep_comp)) 265 - goto found_ep; 266 - ep = find_ep (gadget, "ep-f"); 267 - if (ep && ep_matches(gadget, ep, desc, ep_comp)) 268 - goto found_ep; 261 + if (gadget_is_net2280(gadget)) { 262 + char name[8]; 269 263 264 + if (type == USB_ENDPOINT_XFER_INT) { 265 + /* ep-e, ep-f are PIO with only 64 byte fifos */ 266 + ep = find_ep(gadget, "ep-e"); 267 + if (ep && ep_matches(gadget, ep, desc, ep_comp)) 268 + goto found_ep; 269 + ep = find_ep(gadget, "ep-f"); 270 + if (ep && ep_matches(gadget, ep, desc, ep_comp)) 271 + goto found_ep; 272 + } 273 + 274 + /* USB3380: use same address for usb and hardware endpoints */ 275 + snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc), 276 + usb_endpoint_dir_in(desc) ? "in" : "out"); 277 + ep = find_ep(gadget, name); 278 + if (ep && ep_matches(gadget, ep, desc, ep_comp)) 279 + goto found_ep; 270 280 } else if (gadget_is_goku (gadget)) { 271 281 if (USB_ENDPOINT_XFER_INT == type) { 272 282 /* single buffering is enough */
+8 -2
drivers/usb/gadget/function/f_fs.c
··· 3433 3433 static void ffs_closed(struct ffs_data *ffs) 3434 3434 { 3435 3435 struct ffs_dev *ffs_obj; 3436 + struct f_fs_opts *opts; 3436 3437 3437 3438 ENTER(); 3438 3439 ffs_dev_lock(); ··· 3447 3446 if (ffs_obj->ffs_closed_callback) 3448 3447 ffs_obj->ffs_closed_callback(ffs); 3449 3448 3450 - if (!ffs_obj->opts || ffs_obj->opts->no_configfs 3451 - || !ffs_obj->opts->func_inst.group.cg_item.ci_parent) 3449 + if (ffs_obj->opts) 3450 + opts = ffs_obj->opts; 3451 + else 3452 + goto done; 3453 + 3454 + if (opts->no_configfs || !opts->func_inst.group.cg_item.ci_parent 3455 + || !atomic_read(&opts->func_inst.group.cg_item.ci_kref.refcount)) 3452 3456 goto done; 3453 3457 3454 3458 unregister_gadget_item(ffs_obj->opts->
+20 -40
drivers/usb/gadget/function/f_rndis.c
··· 76 76 u8 ethaddr[ETH_ALEN]; 77 77 u32 vendorID; 78 78 const char *manufacturer; 79 - int config; 79 + struct rndis_params *params; 80 80 81 81 struct usb_ep *notify; 82 82 struct usb_request *notify_req; ··· 453 453 454 454 /* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */ 455 455 // spin_lock(&dev->lock); 456 - status = rndis_msg_parser(rndis->config, (u8 *) req->buf); 456 + status = rndis_msg_parser(rndis->params, (u8 *) req->buf); 457 457 if (status < 0) 458 458 pr_err("RNDIS command error %d, %d/%d\n", 459 459 status, req->actual, req->length); ··· 499 499 u32 n; 500 500 501 501 /* return the result */ 502 - buf = rndis_get_next_response(rndis->config, &n); 502 + buf = rndis_get_next_response(rndis->params, &n); 503 503 if (buf) { 504 504 memcpy(req->buf, buf, n); 505 505 req->complete = rndis_response_complete; 506 506 req->context = rndis; 507 - rndis_free_response(rndis->config, buf); 507 + rndis_free_response(rndis->params, buf); 508 508 value = n; 509 509 } 510 510 /* else stalls ... spec says to avoid that */ ··· 597 597 if (IS_ERR(net)) 598 598 return PTR_ERR(net); 599 599 600 - rndis_set_param_dev(rndis->config, net, 600 + rndis_set_param_dev(rndis->params, net, 601 601 &rndis->port.cdc_filter); 602 602 } else 603 603 goto fail; ··· 617 617 618 618 DBG(cdev, "rndis deactivated\n"); 619 619 620 - rndis_uninit(rndis->config); 620 + rndis_uninit(rndis->params); 621 621 gether_disconnect(&rndis->port); 622 622 623 623 usb_ep_disable(rndis->notify); ··· 640 640 641 641 DBG(cdev, "%s\n", __func__); 642 642 643 - rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 643 + rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3, 644 644 bitrate(cdev->gadget) / 100); 645 - rndis_signal_connect(rndis->config); 645 + rndis_signal_connect(rndis->params); 646 646 } 647 647 648 648 static void rndis_close(struct gether *geth) ··· 651 651 652 652 DBG(geth->func.config->cdev, "%s\n", __func__); 653 653 654 - rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); 655 - rndis_signal_disconnect(rndis->config); 654 + rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3, 0); 655 + rndis_signal_disconnect(rndis->params); 656 656 } 657 657 658 658 /*-------------------------------------------------------------------------*/ ··· 796 796 rndis->port.open = rndis_open; 797 797 rndis->port.close = rndis_close; 798 798 799 - rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); 800 - rndis_set_host_mac(rndis->config, rndis->ethaddr); 799 + rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3, 0); 800 + rndis_set_host_mac(rndis->params, rndis->ethaddr); 801 801 802 802 if (rndis->manufacturer && rndis->vendorID && 803 - rndis_set_param_vendor(rndis->config, rndis->vendorID, 803 + rndis_set_param_vendor(rndis->params, rndis->vendorID, 804 804 rndis->manufacturer)) { 805 805 status = -EINVAL; 806 806 goto fail_free_descs; ··· 944 944 struct f_rndis_opts *opts; 945 945 946 946 rndis = func_to_rndis(f); 947 - rndis_deregister(rndis->config); 947 + rndis_deregister(rndis->params); 948 948 opts = container_of(f->fi, struct f_rndis_opts, func_inst); 949 949 kfree(rndis); 950 950 mutex_lock(&opts->lock); ··· 968 968 { 969 969 struct f_rndis *rndis; 970 970 struct f_rndis_opts *opts; 971 - int status; 971 + struct rndis_params *params; 972 972 973 973 /* allocate and initialize one new instance */ 974 974 rndis = kzalloc(sizeof(*rndis), GFP_KERNEL); ··· 1002 1002 rndis->port.func.disable = rndis_disable; 1003 1003 rndis->port.func.free_func = rndis_free; 1004 1004 1005 - status = rndis_register(rndis_response_available, rndis); 1006 - if (status < 0) { 1005 + params = rndis_register(rndis_response_available, rndis); 1006 + if (IS_ERR(params)) { 1007 1007 kfree(rndis); 1008 - return ERR_PTR(status); 1008 + return ERR_CAST(params); 1009 1009 } 1010 - rndis->config = status; 1010 + rndis->params = params; 1011 1011 1012 1012 return &rndis->port.func; 1013 1013 } 1014 1014 1015 - DECLARE_USB_FUNCTION(rndis, rndis_alloc_inst, rndis_alloc); 1016 - 1017 - static int __init rndis_mod_init(void) 1018 - { 1019 - int ret; 1020 - 1021 - ret = rndis_init(); 1022 - if (ret) 1023 - return ret; 1024 - 1025 - return usb_function_register(&rndisusb_func); 1026 - } 1027 - module_init(rndis_mod_init); 1028 - 1029 - static void __exit rndis_mod_exit(void) 1030 - { 1031 - usb_function_unregister(&rndisusb_func); 1032 - rndis_exit(); 1033 - } 1034 - module_exit(rndis_mod_exit); 1035 - 1015 + DECLARE_USB_FUNCTION_INIT(rndis, rndis_alloc_inst, rndis_alloc); 1036 1016 MODULE_LICENSE("GPL"); 1037 1017 MODULE_AUTHOR("David Brownell");
+171 -181
drivers/usb/gadget/function/rndis.c
··· 25 25 #include <linux/moduleparam.h> 26 26 #include <linux/kernel.h> 27 27 #include <linux/errno.h> 28 + #include <linux/idr.h> 28 29 #include <linux/list.h> 29 30 #include <linux/proc_fs.h> 30 31 #include <linux/slab.h> ··· 58 57 #define rndis_debug 0 59 58 #endif 60 59 61 - #define RNDIS_MAX_CONFIGS 1 60 + #ifdef CONFIG_USB_GADGET_DEBUG_FILES 62 61 62 + #define NAME_TEMPLATE "driver/rndis-%03d" 63 63 64 - static rndis_params rndis_per_dev_params[RNDIS_MAX_CONFIGS]; 64 + #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 65 + 66 + static DEFINE_IDA(rndis_ida); 65 67 66 68 /* Driver Version */ 67 69 static const __le32 rndis_driver_version = cpu_to_le32(1); 68 70 69 71 /* Function Prototypes */ 70 - static rndis_resp_t *rndis_add_response(int configNr, u32 length); 72 + static rndis_resp_t *rndis_add_response(struct rndis_params *params, 73 + u32 length); 71 74 75 + #ifdef CONFIG_USB_GADGET_DEBUG_FILES 76 + 77 + static const struct file_operations rndis_proc_fops; 78 + 79 + #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 72 80 73 81 /* supported OIDs */ 74 82 static const u32 oid_supported_list[] = ··· 170 160 171 161 172 162 /* NDIS Functions */ 173 - static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, 163 + static int gen_ndis_query_resp(struct rndis_params *params, u32 OID, u8 *buf, 174 164 unsigned buf_len, rndis_resp_t *r) 175 165 { 176 166 int retval = -ENOTSUPP; ··· 202 192 outbuf = (__le32 *)&resp[1]; 203 193 resp->InformationBufferOffset = cpu_to_le32(16); 204 194 205 - net = rndis_per_dev_params[configNr].dev; 195 + net = params->dev; 206 196 stats = dev_get_stats(net, &temp); 207 197 208 198 switch (OID) { ··· 235 225 /* mandatory */ 236 226 case RNDIS_OID_GEN_MEDIA_SUPPORTED: 237 227 pr_debug("%s: RNDIS_OID_GEN_MEDIA_SUPPORTED\n", __func__); 238 - *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium); 228 + *outbuf = cpu_to_le32(params->medium); 239 229 retval = 0; 240 230 break; 241 231 ··· 243 233 case RNDIS_OID_GEN_MEDIA_IN_USE: 244 234 pr_debug("%s: RNDIS_OID_GEN_MEDIA_IN_USE\n", __func__); 245 235 /* one medium, one transport... (maybe you do it better) */ 246 - *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium); 236 + *outbuf = cpu_to_le32(params->medium); 247 237 retval = 0; 248 238 break; 249 239 250 240 /* mandatory */ 251 241 case RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE: 252 242 pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__); 253 - if (rndis_per_dev_params[configNr].dev) { 254 - *outbuf = cpu_to_le32( 255 - rndis_per_dev_params[configNr].dev->mtu); 243 + if (params->dev) { 244 + *outbuf = cpu_to_le32(params->dev->mtu); 256 245 retval = 0; 257 246 } 258 247 break; ··· 260 251 case RNDIS_OID_GEN_LINK_SPEED: 261 252 if (rndis_debug > 1) 262 253 pr_debug("%s: RNDIS_OID_GEN_LINK_SPEED\n", __func__); 263 - if (rndis_per_dev_params[configNr].media_state 264 - == RNDIS_MEDIA_STATE_DISCONNECTED) 254 + if (params->media_state == RNDIS_MEDIA_STATE_DISCONNECTED) 265 255 *outbuf = cpu_to_le32(0); 266 256 else 267 - *outbuf = cpu_to_le32( 268 - rndis_per_dev_params[configNr].speed); 257 + *outbuf = cpu_to_le32(params->speed); 269 258 retval = 0; 270 259 break; 271 260 272 261 /* mandatory */ 273 262 case RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE: 274 263 pr_debug("%s: RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__); 275 - if (rndis_per_dev_params[configNr].dev) { 276 - *outbuf = cpu_to_le32( 277 - rndis_per_dev_params[configNr].dev->mtu); 264 + if (params->dev) { 265 + *outbuf = cpu_to_le32(params->dev->mtu); 278 266 retval = 0; 279 267 } 280 268 break; ··· 279 273 /* mandatory */ 280 274 case RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE: 281 275 pr_debug("%s: RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__); 282 - if (rndis_per_dev_params[configNr].dev) { 283 - *outbuf = cpu_to_le32( 284 - rndis_per_dev_params[configNr].dev->mtu); 276 + if (params->dev) { 277 + *outbuf = cpu_to_le32(params->dev->mtu); 285 278 retval = 0; 286 279 } 287 280 break; ··· 288 283 /* mandatory */ 289 284 case RNDIS_OID_GEN_VENDOR_ID: 290 285 pr_debug("%s: RNDIS_OID_GEN_VENDOR_ID\n", __func__); 291 - *outbuf = cpu_to_le32( 292 - rndis_per_dev_params[configNr].vendorID); 286 + *outbuf = cpu_to_le32(params->vendorID); 293 287 retval = 0; 294 288 break; 295 289 296 290 /* mandatory */ 297 291 case RNDIS_OID_GEN_VENDOR_DESCRIPTION: 298 292 pr_debug("%s: RNDIS_OID_GEN_VENDOR_DESCRIPTION\n", __func__); 299 - if (rndis_per_dev_params[configNr].vendorDescr) { 300 - length = strlen(rndis_per_dev_params[configNr]. 301 - vendorDescr); 302 - memcpy(outbuf, 303 - rndis_per_dev_params[configNr].vendorDescr, 304 - length); 293 + if (params->vendorDescr) { 294 + length = strlen(params->vendorDescr); 295 + memcpy(outbuf, params->vendorDescr, length); 305 296 } else { 306 297 outbuf[0] = 0; 307 298 } ··· 314 313 /* mandatory */ 315 314 case RNDIS_OID_GEN_CURRENT_PACKET_FILTER: 316 315 pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER\n", __func__); 317 - *outbuf = cpu_to_le32(*rndis_per_dev_params[configNr].filter); 316 + *outbuf = cpu_to_le32(*params->filter); 318 317 retval = 0; 319 318 break; 320 319 ··· 329 328 case RNDIS_OID_GEN_MEDIA_CONNECT_STATUS: 330 329 if (rndis_debug > 1) 331 330 pr_debug("%s: RNDIS_OID_GEN_MEDIA_CONNECT_STATUS\n", __func__); 332 - *outbuf = cpu_to_le32(rndis_per_dev_params[configNr] 333 - .media_state); 331 + *outbuf = cpu_to_le32(params->media_state); 334 332 retval = 0; 335 333 break; 336 334 ··· 409 409 /* mandatory */ 410 410 case RNDIS_OID_802_3_PERMANENT_ADDRESS: 411 411 pr_debug("%s: RNDIS_OID_802_3_PERMANENT_ADDRESS\n", __func__); 412 - if (rndis_per_dev_params[configNr].dev) { 412 + if (params->dev) { 413 413 length = ETH_ALEN; 414 - memcpy(outbuf, 415 - rndis_per_dev_params[configNr].host_mac, 416 - length); 414 + memcpy(outbuf, params->host_mac, length); 417 415 retval = 0; 418 416 } 419 417 break; ··· 419 421 /* mandatory */ 420 422 case RNDIS_OID_802_3_CURRENT_ADDRESS: 421 423 pr_debug("%s: RNDIS_OID_802_3_CURRENT_ADDRESS\n", __func__); 422 - if (rndis_per_dev_params[configNr].dev) { 424 + if (params->dev) { 423 425 length = ETH_ALEN; 424 - memcpy(outbuf, 425 - rndis_per_dev_params [configNr].host_mac, 426 - length); 426 + memcpy(outbuf, params->host_mac, length); 427 427 retval = 0; 428 428 } 429 429 break; ··· 486 490 return retval; 487 491 } 488 492 489 - static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len, 490 - rndis_resp_t *r) 493 + static int gen_ndis_set_resp(struct rndis_params *params, u32 OID, 494 + u8 *buf, u32 buf_len, rndis_resp_t *r) 491 495 { 492 496 rndis_set_cmplt_type *resp; 493 497 int i, retval = -ENOTSUPP; 494 - struct rndis_params *params; 495 498 496 499 if (!r) 497 500 return -ENOMEM; ··· 509 514 } 510 515 } 511 516 512 - params = &rndis_per_dev_params[configNr]; 513 517 switch (OID) { 514 518 case RNDIS_OID_GEN_CURRENT_PACKET_FILTER: 515 519 ··· 557 563 * Response Functions 558 564 */ 559 565 560 - static int rndis_init_response(int configNr, rndis_init_msg_type *buf) 566 + static int rndis_init_response(struct rndis_params *params, 567 + rndis_init_msg_type *buf) 561 568 { 562 569 rndis_init_cmplt_type *resp; 563 570 rndis_resp_t *r; 564 - struct rndis_params *params = rndis_per_dev_params + configNr; 565 571 566 572 if (!params->dev) 567 573 return -ENOTSUPP; 568 574 569 - r = rndis_add_response(configNr, sizeof(rndis_init_cmplt_type)); 575 + r = rndis_add_response(params, sizeof(rndis_init_cmplt_type)); 570 576 if (!r) 571 577 return -ENOMEM; 572 578 resp = (rndis_init_cmplt_type *)r->buf; ··· 593 599 return 0; 594 600 } 595 601 596 - static int rndis_query_response(int configNr, rndis_query_msg_type *buf) 602 + static int rndis_query_response(struct rndis_params *params, 603 + rndis_query_msg_type *buf) 597 604 { 598 605 rndis_query_cmplt_type *resp; 599 606 rndis_resp_t *r; 600 - struct rndis_params *params = rndis_per_dev_params + configNr; 601 607 602 608 /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */ 603 609 if (!params->dev) ··· 609 615 * rndis_query_cmplt_type followed by data. 610 616 * oid_supported_list is the largest data reply 611 617 */ 612 - r = rndis_add_response(configNr, 618 + r = rndis_add_response(params, 613 619 sizeof(oid_supported_list) + sizeof(rndis_query_cmplt_type)); 614 620 if (!r) 615 621 return -ENOMEM; ··· 618 624 resp->MessageType = cpu_to_le32(RNDIS_MSG_QUERY_C); 619 625 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 620 626 621 - if (gen_ndis_query_resp(configNr, le32_to_cpu(buf->OID), 627 + if (gen_ndis_query_resp(params, le32_to_cpu(buf->OID), 622 628 le32_to_cpu(buf->InformationBufferOffset) 623 629 + 8 + (u8 *)buf, 624 630 le32_to_cpu(buf->InformationBufferLength), ··· 635 641 return 0; 636 642 } 637 643 638 - static int rndis_set_response(int configNr, rndis_set_msg_type *buf) 644 + static int rndis_set_response(struct rndis_params *params, 645 + rndis_set_msg_type *buf) 639 646 { 640 647 u32 BufLength, BufOffset; 641 648 rndis_set_cmplt_type *resp; 642 649 rndis_resp_t *r; 643 - struct rndis_params *params = rndis_per_dev_params + configNr; 644 650 645 - r = rndis_add_response(configNr, sizeof(rndis_set_cmplt_type)); 651 + r = rndis_add_response(params, sizeof(rndis_set_cmplt_type)); 646 652 if (!r) 647 653 return -ENOMEM; 648 654 resp = (rndis_set_cmplt_type *)r->buf; ··· 665 671 resp->MessageType = cpu_to_le32(RNDIS_MSG_SET_C); 666 672 resp->MessageLength = cpu_to_le32(16); 667 673 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 668 - if (gen_ndis_set_resp(configNr, le32_to_cpu(buf->OID), 674 + if (gen_ndis_set_resp(params, le32_to_cpu(buf->OID), 669 675 ((u8 *)buf) + 8 + BufOffset, BufLength, r)) 670 676 resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED); 671 677 else ··· 675 681 return 0; 676 682 } 677 683 678 - static int rndis_reset_response(int configNr, rndis_reset_msg_type *buf) 684 + static int rndis_reset_response(struct rndis_params *params, 685 + rndis_reset_msg_type *buf) 679 686 { 680 687 rndis_reset_cmplt_type *resp; 681 688 rndis_resp_t *r; 682 - struct rndis_params *params = rndis_per_dev_params + configNr; 683 689 684 - r = rndis_add_response(configNr, sizeof(rndis_reset_cmplt_type)); 690 + r = rndis_add_response(params, sizeof(rndis_reset_cmplt_type)); 685 691 if (!r) 686 692 return -ENOMEM; 687 693 resp = (rndis_reset_cmplt_type *)r->buf; ··· 696 702 return 0; 697 703 } 698 704 699 - static int rndis_keepalive_response(int configNr, 705 + static int rndis_keepalive_response(struct rndis_params *params, 700 706 rndis_keepalive_msg_type *buf) 701 707 { 702 708 rndis_keepalive_cmplt_type *resp; 703 709 rndis_resp_t *r; 704 - struct rndis_params *params = rndis_per_dev_params + configNr; 705 710 706 711 /* host "should" check only in RNDIS_DATA_INITIALIZED state */ 707 712 708 - r = rndis_add_response(configNr, sizeof(rndis_keepalive_cmplt_type)); 713 + r = rndis_add_response(params, sizeof(rndis_keepalive_cmplt_type)); 709 714 if (!r) 710 715 return -ENOMEM; 711 716 resp = (rndis_keepalive_cmplt_type *)r->buf; ··· 722 729 /* 723 730 * Device to Host Comunication 724 731 */ 725 - static int rndis_indicate_status_msg(int configNr, u32 status) 732 + static int rndis_indicate_status_msg(struct rndis_params *params, u32 status) 726 733 { 727 734 rndis_indicate_status_msg_type *resp; 728 735 rndis_resp_t *r; 729 - struct rndis_params *params = rndis_per_dev_params + configNr; 730 736 731 737 if (params->state == RNDIS_UNINITIALIZED) 732 738 return -ENOTSUPP; 733 739 734 - r = rndis_add_response(configNr, 735 - sizeof(rndis_indicate_status_msg_type)); 740 + r = rndis_add_response(params, sizeof(rndis_indicate_status_msg_type)); 736 741 if (!r) 737 742 return -ENOMEM; 738 743 resp = (rndis_indicate_status_msg_type *)r->buf; ··· 745 754 return 0; 746 755 } 747 756 748 - int rndis_signal_connect(int configNr) 757 + int rndis_signal_connect(struct rndis_params *params) 749 758 { 750 - rndis_per_dev_params[configNr].media_state 751 - = RNDIS_MEDIA_STATE_CONNECTED; 752 - return rndis_indicate_status_msg(configNr, 753 - RNDIS_STATUS_MEDIA_CONNECT); 759 + params->media_state = RNDIS_MEDIA_STATE_CONNECTED; 760 + return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_CONNECT); 754 761 } 755 762 EXPORT_SYMBOL_GPL(rndis_signal_connect); 756 763 757 - int rndis_signal_disconnect(int configNr) 764 + int rndis_signal_disconnect(struct rndis_params *params) 758 765 { 759 - rndis_per_dev_params[configNr].media_state 760 - = RNDIS_MEDIA_STATE_DISCONNECTED; 761 - return rndis_indicate_status_msg(configNr, 762 - RNDIS_STATUS_MEDIA_DISCONNECT); 766 + params->media_state = RNDIS_MEDIA_STATE_DISCONNECTED; 767 + return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_DISCONNECT); 763 768 } 764 769 EXPORT_SYMBOL_GPL(rndis_signal_disconnect); 765 770 766 - void rndis_uninit(int configNr) 771 + void rndis_uninit(struct rndis_params *params) 767 772 { 768 773 u8 *buf; 769 774 u32 length; 770 775 771 - if (configNr >= RNDIS_MAX_CONFIGS) 776 + if (!params) 772 777 return; 773 - rndis_per_dev_params[configNr].state = RNDIS_UNINITIALIZED; 778 + params->state = RNDIS_UNINITIALIZED; 774 779 775 780 /* drain the response queue */ 776 - while ((buf = rndis_get_next_response(configNr, &length))) 777 - rndis_free_response(configNr, buf); 781 + while ((buf = rndis_get_next_response(params, &length))) 782 + rndis_free_response(params, buf); 778 783 } 779 784 EXPORT_SYMBOL_GPL(rndis_uninit); 780 785 781 - void rndis_set_host_mac(int configNr, const u8 *addr) 786 + void rndis_set_host_mac(struct rndis_params *params, const u8 *addr) 782 787 { 783 - rndis_per_dev_params[configNr].host_mac = addr; 788 + params->host_mac = addr; 784 789 } 785 790 EXPORT_SYMBOL_GPL(rndis_set_host_mac); 786 791 787 792 /* 788 793 * Message Parser 789 794 */ 790 - int rndis_msg_parser(u8 configNr, u8 *buf) 795 + int rndis_msg_parser(struct rndis_params *params, u8 *buf) 791 796 { 792 797 u32 MsgType, MsgLength; 793 798 __le32 *tmp; 794 - struct rndis_params *params; 795 799 796 800 if (!buf) 797 801 return -ENOMEM; ··· 795 809 MsgType = get_unaligned_le32(tmp++); 796 810 MsgLength = get_unaligned_le32(tmp++); 797 811 798 - if (configNr >= RNDIS_MAX_CONFIGS) 812 + if (!params) 799 813 return -ENOTSUPP; 800 - params = &rndis_per_dev_params[configNr]; 801 814 802 815 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for 803 816 * rx/tx statistics and link status, in addition to KEEPALIVE traffic ··· 809 824 pr_debug("%s: RNDIS_MSG_INIT\n", 810 825 __func__); 811 826 params->state = RNDIS_INITIALIZED; 812 - return rndis_init_response(configNr, 813 - (rndis_init_msg_type *)buf); 827 + return rndis_init_response(params, (rndis_init_msg_type *)buf); 814 828 815 829 case RNDIS_MSG_HALT: 816 830 pr_debug("%s: RNDIS_MSG_HALT\n", ··· 822 838 return 0; 823 839 824 840 case RNDIS_MSG_QUERY: 825 - return rndis_query_response(configNr, 841 + return rndis_query_response(params, 826 842 (rndis_query_msg_type *)buf); 827 843 828 844 case RNDIS_MSG_SET: 829 - return rndis_set_response(configNr, 830 - (rndis_set_msg_type *)buf); 845 + return rndis_set_response(params, (rndis_set_msg_type *)buf); 831 846 832 847 case RNDIS_MSG_RESET: 833 848 pr_debug("%s: RNDIS_MSG_RESET\n", 834 849 __func__); 835 - return rndis_reset_response(configNr, 850 + return rndis_reset_response(params, 836 851 (rndis_reset_msg_type *)buf); 837 852 838 853 case RNDIS_MSG_KEEPALIVE: ··· 839 856 if (rndis_debug > 1) 840 857 pr_debug("%s: RNDIS_MSG_KEEPALIVE\n", 841 858 __func__); 842 - return rndis_keepalive_response(configNr, 859 + return rndis_keepalive_response(params, 843 860 (rndis_keepalive_msg_type *) 844 861 buf); 845 862 ··· 859 876 } 860 877 EXPORT_SYMBOL_GPL(rndis_msg_parser); 861 878 862 - int rndis_register(void (*resp_avail)(void *v), void *v) 879 + static inline int rndis_get_nr(void) 863 880 { 864 - u8 i; 881 + return ida_simple_get(&rndis_ida, 0, 0, GFP_KERNEL); 882 + } 883 + 884 + static inline void rndis_put_nr(int nr) 885 + { 886 + ida_simple_remove(&rndis_ida, nr); 887 + } 888 + 889 + struct rndis_params *rndis_register(void (*resp_avail)(void *v), void *v) 890 + { 891 + struct rndis_params *params; 892 + int i; 865 893 866 894 if (!resp_avail) 867 - return -EINVAL; 895 + return ERR_PTR(-EINVAL); 868 896 869 - for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { 870 - if (!rndis_per_dev_params[i].used) { 871 - rndis_per_dev_params[i].used = 1; 872 - rndis_per_dev_params[i].resp_avail = resp_avail; 873 - rndis_per_dev_params[i].v = v; 874 - pr_debug("%s: configNr = %d\n", __func__, i); 875 - return i; 897 + i = rndis_get_nr(); 898 + if (i < 0) { 899 + pr_debug("failed\n"); 900 + 901 + return ERR_PTR(-ENODEV); 902 + } 903 + 904 + params = kzalloc(sizeof(*params), GFP_KERNEL); 905 + if (!params) { 906 + rndis_put_nr(i); 907 + 908 + return ERR_PTR(-ENOMEM); 909 + } 910 + 911 + #ifdef CONFIG_USB_GADGET_DEBUG_FILES 912 + { 913 + struct proc_dir_entry *proc_entry; 914 + char name[20]; 915 + 916 + sprintf(name, NAME_TEMPLATE, i); 917 + proc_entry = proc_create_data(name, 0660, NULL, 918 + &rndis_proc_fops, params); 919 + if (!proc_entry) { 920 + kfree(params); 921 + rndis_put_nr(i); 922 + 923 + return ERR_PTR(-EIO); 876 924 } 877 925 } 878 - pr_debug("failed\n"); 926 + #endif 879 927 880 - return -ENODEV; 928 + params->confignr = i; 929 + params->used = 1; 930 + params->state = RNDIS_UNINITIALIZED; 931 + params->media_state = RNDIS_MEDIA_STATE_DISCONNECTED; 932 + params->resp_avail = resp_avail; 933 + params->v = v; 934 + INIT_LIST_HEAD(&(params->resp_queue)); 935 + pr_debug("%s: configNr = %d\n", __func__, i); 936 + 937 + return params; 881 938 } 882 939 EXPORT_SYMBOL_GPL(rndis_register); 883 940 884 - void rndis_deregister(int configNr) 941 + void rndis_deregister(struct rndis_params *params) 885 942 { 943 + int i; 944 + 886 945 pr_debug("%s:\n", __func__); 887 946 888 - if (configNr >= RNDIS_MAX_CONFIGS) return; 889 - rndis_per_dev_params[configNr].used = 0; 947 + if (!params) 948 + return; 949 + 950 + i = params->confignr; 951 + 952 + #ifdef CONFIG_USB_GADGET_DEBUG_FILES 953 + { 954 + char name[20]; 955 + 956 + sprintf(name, NAME_TEMPLATE, i); 957 + remove_proc_entry(name, NULL); 958 + } 959 + #endif 960 + 961 + kfree(params); 962 + rndis_put_nr(i); 890 963 } 891 964 EXPORT_SYMBOL_GPL(rndis_deregister); 892 - 893 - int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) 965 + int rndis_set_param_dev(struct rndis_params *params, struct net_device *dev, 966 + u16 *cdc_filter) 894 967 { 895 968 pr_debug("%s:\n", __func__); 896 969 if (!dev) 897 970 return -EINVAL; 898 - if (configNr >= RNDIS_MAX_CONFIGS) return -1; 971 + if (!params) 972 + return -1; 899 973 900 - rndis_per_dev_params[configNr].dev = dev; 901 - rndis_per_dev_params[configNr].filter = cdc_filter; 974 + params->dev = dev; 975 + params->filter = cdc_filter; 902 976 903 977 return 0; 904 978 } 905 979 EXPORT_SYMBOL_GPL(rndis_set_param_dev); 906 980 907 - int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr) 981 + int rndis_set_param_vendor(struct rndis_params *params, u32 vendorID, 982 + const char *vendorDescr) 908 983 { 909 984 pr_debug("%s:\n", __func__); 910 985 if (!vendorDescr) return -1; 911 - if (configNr >= RNDIS_MAX_CONFIGS) return -1; 986 + if (!params) 987 + return -1; 912 988 913 - rndis_per_dev_params[configNr].vendorID = vendorID; 914 - rndis_per_dev_params[configNr].vendorDescr = vendorDescr; 989 + params->vendorID = vendorID; 990 + params->vendorDescr = vendorDescr; 915 991 916 992 return 0; 917 993 } 918 994 EXPORT_SYMBOL_GPL(rndis_set_param_vendor); 919 995 920 - int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed) 996 + int rndis_set_param_medium(struct rndis_params *params, u32 medium, u32 speed) 921 997 { 922 998 pr_debug("%s: %u %u\n", __func__, medium, speed); 923 - if (configNr >= RNDIS_MAX_CONFIGS) return -1; 999 + if (!params) 1000 + return -1; 924 1001 925 - rndis_per_dev_params[configNr].medium = medium; 926 - rndis_per_dev_params[configNr].speed = speed; 1002 + params->medium = medium; 1003 + params->speed = speed; 927 1004 928 1005 return 0; 929 1006 } ··· 1004 961 } 1005 962 EXPORT_SYMBOL_GPL(rndis_add_hdr); 1006 963 1007 - void rndis_free_response(int configNr, u8 *buf) 964 + void rndis_free_response(struct rndis_params *params, u8 *buf) 1008 965 { 1009 966 rndis_resp_t *r; 1010 967 struct list_head *act, *tmp; 1011 968 1012 - list_for_each_safe(act, tmp, 1013 - &(rndis_per_dev_params[configNr].resp_queue)) 969 + list_for_each_safe(act, tmp, &(params->resp_queue)) 1014 970 { 1015 971 r = list_entry(act, rndis_resp_t, list); 1016 972 if (r && r->buf == buf) { ··· 1020 978 } 1021 979 EXPORT_SYMBOL_GPL(rndis_free_response); 1022 980 1023 - u8 *rndis_get_next_response(int configNr, u32 *length) 981 + u8 *rndis_get_next_response(struct rndis_params *params, u32 *length) 1024 982 { 1025 983 rndis_resp_t *r; 1026 984 struct list_head *act, *tmp; 1027 985 1028 986 if (!length) return NULL; 1029 987 1030 - list_for_each_safe(act, tmp, 1031 - &(rndis_per_dev_params[configNr].resp_queue)) 988 + list_for_each_safe(act, tmp, &(params->resp_queue)) 1032 989 { 1033 990 r = list_entry(act, rndis_resp_t, list); 1034 991 if (!r->send) { ··· 1041 1000 } 1042 1001 EXPORT_SYMBOL_GPL(rndis_get_next_response); 1043 1002 1044 - static rndis_resp_t *rndis_add_response(int configNr, u32 length) 1003 + static rndis_resp_t *rndis_add_response(struct rndis_params *params, u32 length) 1045 1004 { 1046 1005 rndis_resp_t *r; 1047 1006 ··· 1053 1012 r->length = length; 1054 1013 r->send = 0; 1055 1014 1056 - list_add_tail(&r->list, 1057 - &(rndis_per_dev_params[configNr].resp_queue)); 1015 + list_add_tail(&r->list, &(params->resp_queue)); 1058 1016 return r; 1059 1017 } 1060 1018 ··· 1143 1103 break; 1144 1104 case 'C': 1145 1105 case 'c': 1146 - rndis_signal_connect(p->confignr); 1106 + rndis_signal_connect(p); 1147 1107 break; 1148 1108 case 'D': 1149 1109 case 'd': 1150 - rndis_signal_disconnect(p->confignr); 1110 + rndis_signal_disconnect(p); 1151 1111 break; 1152 1112 default: 1153 1113 if (fl_speed) p->speed = speed; ··· 1177 1137 1178 1138 #define NAME_TEMPLATE "driver/rndis-%03d" 1179 1139 1180 - static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS]; 1181 - 1182 1140 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 1183 - 1184 - 1185 - int rndis_init(void) 1186 - { 1187 - u8 i; 1188 - 1189 - for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { 1190 - #ifdef CONFIG_USB_GADGET_DEBUG_FILES 1191 - char name [20]; 1192 - 1193 - sprintf(name, NAME_TEMPLATE, i); 1194 - rndis_connect_state[i] = proc_create_data(name, 0660, NULL, 1195 - &rndis_proc_fops, 1196 - (void *)(rndis_per_dev_params + i)); 1197 - if (!rndis_connect_state[i]) { 1198 - pr_debug("%s: remove entries", __func__); 1199 - while (i) { 1200 - sprintf(name, NAME_TEMPLATE, --i); 1201 - remove_proc_entry(name, NULL); 1202 - } 1203 - pr_debug("\n"); 1204 - return -EIO; 1205 - } 1206 - #endif 1207 - rndis_per_dev_params[i].confignr = i; 1208 - rndis_per_dev_params[i].used = 0; 1209 - rndis_per_dev_params[i].state = RNDIS_UNINITIALIZED; 1210 - rndis_per_dev_params[i].media_state 1211 - = RNDIS_MEDIA_STATE_DISCONNECTED; 1212 - INIT_LIST_HEAD(&(rndis_per_dev_params[i].resp_queue)); 1213 - } 1214 - 1215 - return 0; 1216 - } 1217 - 1218 - void rndis_exit(void) 1219 - { 1220 - #ifdef CONFIG_USB_GADGET_DEBUG_FILES 1221 - u8 i; 1222 - char name[20]; 1223 - 1224 - for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { 1225 - sprintf(name, NAME_TEMPLATE, i); 1226 - remove_proc_entry(name, NULL); 1227 - } 1228 - #endif 1229 - } 1230 -
+16 -15
drivers/usb/gadget/function/rndis.h
··· 177 177 178 178 typedef struct rndis_params 179 179 { 180 - u8 confignr; 180 + int confignr; 181 181 u8 used; 182 182 u16 saved_filter; 183 183 enum rndis_state state; ··· 197 197 } rndis_params; 198 198 199 199 /* RNDIS Message parser and other useless functions */ 200 - int rndis_msg_parser (u8 configNr, u8 *buf); 201 - int rndis_register(void (*resp_avail)(void *v), void *v); 202 - void rndis_deregister (int configNr); 203 - int rndis_set_param_dev (u8 configNr, struct net_device *dev, 200 + int rndis_msg_parser(struct rndis_params *params, u8 *buf); 201 + struct rndis_params *rndis_register(void (*resp_avail)(void *v), void *v); 202 + void rndis_deregister(struct rndis_params *params); 203 + int rndis_set_param_dev(struct rndis_params *params, struct net_device *dev, 204 204 u16 *cdc_filter); 205 - int rndis_set_param_vendor (u8 configNr, u32 vendorID, 205 + int rndis_set_param_vendor(struct rndis_params *params, u32 vendorID, 206 206 const char *vendorDescr); 207 - int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); 208 - void rndis_add_hdr (struct sk_buff *skb); 207 + int rndis_set_param_medium(struct rndis_params *params, u32 medium, 208 + u32 speed); 209 + void rndis_add_hdr(struct sk_buff *skb); 209 210 int rndis_rm_hdr(struct gether *port, struct sk_buff *skb, 210 211 struct sk_buff_head *list); 211 - u8 *rndis_get_next_response (int configNr, u32 *length); 212 - void rndis_free_response (int configNr, u8 *buf); 212 + u8 *rndis_get_next_response(struct rndis_params *params, u32 *length); 213 + void rndis_free_response(struct rndis_params *params, u8 *buf); 213 214 214 - void rndis_uninit (int configNr); 215 - int rndis_signal_connect (int configNr); 216 - int rndis_signal_disconnect (int configNr); 217 - int rndis_state (int configNr); 218 - extern void rndis_set_host_mac (int configNr, const u8 *addr); 215 + void rndis_uninit(struct rndis_params *params); 216 + int rndis_signal_connect(struct rndis_params *params); 217 + int rndis_signal_disconnect(struct rndis_params *params); 218 + int rndis_state(struct rndis_params *params); 219 + extern void rndis_set_host_mac(struct rndis_params *params, const u8 *addr); 219 220 220 221 #endif /* _LINUX_RNDIS_H */
-2
drivers/usb/gadget/function/u_rndis.h
··· 39 39 int refcnt; 40 40 }; 41 41 42 - int rndis_init(void); 43 - void rndis_exit(void); 44 42 void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net); 45 43 46 44 #endif /* U_RNDIS_H */
-1
drivers/usb/gadget/function/uvc.h
··· 56 56 #include <linux/usb/composite.h> 57 57 #include <linux/usb/gadget.h> 58 58 #include <linux/videodev2.h> 59 - #include <linux/version.h> 60 59 #include <media/v4l2-fh.h> 61 60 #include <media/v4l2-device.h> 62 61
+3 -3
drivers/usb/gadget/udc/atmel_usba_udc.c
··· 704 704 unsigned long flags; 705 705 int ret; 706 706 707 - DBG(DBG_DMA, "%s: req l/%u d/%08x %c%c%c\n", 708 - ep->ep.name, req->req.length, req->req.dma, 707 + DBG(DBG_DMA, "%s: req l/%u d/%pad %c%c%c\n", 708 + ep->ep.name, req->req.length, &req->req.dma, 709 709 req->req.zero ? 'Z' : 'z', 710 710 req->req.short_not_ok ? 'S' : 's', 711 711 req->req.no_interrupt ? 'I' : 'i'); ··· 2203 2203 return 0; 2204 2204 } 2205 2205 2206 - #ifdef CONFIG_PM 2206 + #ifdef CONFIG_PM_SLEEP 2207 2207 static int usba_udc_suspend(struct device *dev) 2208 2208 { 2209 2209 struct usba_udc *udc = dev_get_drvdata(dev);
+107 -31
drivers/usb/gadget/udc/net2280.c
··· 123 123 #define valid_bit cpu_to_le32(BIT(VALID_BIT)) 124 124 #define dma_done_ie cpu_to_le32(BIT(DMA_DONE_INTERRUPT_ENABLE)) 125 125 126 + static void ep_clear_seqnum(struct net2280_ep *ep); 127 + static void stop_activity(struct net2280 *dev, 128 + struct usb_gadget_driver *driver); 129 + static void ep0_start(struct net2280 *dev); 130 + 126 131 /*-------------------------------------------------------------------------*/ 127 132 static inline void enable_pciirqenb(struct net2280_ep *ep) 128 133 { ··· 147 142 { 148 143 struct net2280 *dev; 149 144 struct net2280_ep *ep; 150 - u32 max, tmp; 145 + u32 max; 146 + u32 tmp = 0; 147 + u32 type; 151 148 unsigned long flags; 152 149 static const u32 ep_key[9] = { 1, 0, 1, 0, 1, 1, 0, 1, 0 }; 153 150 int ret = 0; ··· 205 198 206 199 /* set type, direction, address; reset fifo counters */ 207 200 writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat); 208 - tmp = (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); 209 - if (tmp == USB_ENDPOINT_XFER_INT) { 201 + 202 + if ((dev->quirks & PLX_SUPERSPEED) && dev->enhanced_mode) { 203 + tmp = readl(&ep->cfg->ep_cfg); 204 + /* If USB ep number doesn't match hardware ep number */ 205 + if ((tmp & 0xf) != usb_endpoint_num(desc)) { 206 + ret = -EINVAL; 207 + spin_unlock_irqrestore(&dev->lock, flags); 208 + goto print_err; 209 + } 210 + if (ep->is_in) 211 + tmp &= ~USB3380_EP_CFG_MASK_IN; 212 + else 213 + tmp &= ~USB3380_EP_CFG_MASK_OUT; 214 + } 215 + type = (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); 216 + if (type == USB_ENDPOINT_XFER_INT) { 210 217 /* erratum 0105 workaround prevents hs NYET */ 211 218 if (dev->chiprev == 0100 && 212 219 dev->gadget.speed == USB_SPEED_HIGH && 213 220 !(desc->bEndpointAddress & USB_DIR_IN)) 214 221 writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE), 215 222 &ep->regs->ep_rsp); 216 - } else if (tmp == USB_ENDPOINT_XFER_BULK) { 223 + } else if (type == USB_ENDPOINT_XFER_BULK) { 217 224 /* catch some particularly blatant driver bugs */ 218 225 if ((dev->gadget.speed == USB_SPEED_SUPER && max != 1024) || 219 226 (dev->gadget.speed == USB_SPEED_HIGH && max != 512) || ··· 237 216 goto print_err; 238 217 } 239 218 } 240 - ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC); 219 + ep->is_iso = (type == USB_ENDPOINT_XFER_ISOC); 241 220 /* Enable this endpoint */ 242 221 if (dev->quirks & PLX_LEGACY) { 243 - tmp <<= ENDPOINT_TYPE; 222 + tmp |= type << ENDPOINT_TYPE; 244 223 tmp |= desc->bEndpointAddress; 245 224 /* default full fifo lines */ 246 225 tmp |= (4 << ENDPOINT_BYTE_COUNT); ··· 249 228 } else { 250 229 /* In Legacy mode, only OUT endpoints are used */ 251 230 if (dev->enhanced_mode && ep->is_in) { 252 - tmp <<= IN_ENDPOINT_TYPE; 231 + tmp |= type << IN_ENDPOINT_TYPE; 253 232 tmp |= BIT(IN_ENDPOINT_ENABLE); 254 - /* Not applicable to Legacy */ 255 - tmp |= BIT(ENDPOINT_DIRECTION); 256 233 } else { 257 - tmp <<= OUT_ENDPOINT_TYPE; 234 + tmp |= type << OUT_ENDPOINT_TYPE; 258 235 tmp |= BIT(OUT_ENDPOINT_ENABLE); 259 236 tmp |= (ep->is_in << ENDPOINT_DIRECTION); 260 237 } 261 238 262 - tmp |= usb_endpoint_num(desc); 239 + tmp |= (4 << ENDPOINT_BYTE_COUNT); 240 + if (!dev->enhanced_mode) 241 + tmp |= usb_endpoint_num(desc); 263 242 tmp |= (ep->ep.maxburst << MAX_BURST_SIZE); 264 243 } 265 244 ··· 277 256 BIT(CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp); 278 257 } 279 258 259 + if (dev->quirks & PLX_SUPERSPEED) 260 + ep_clear_seqnum(ep); 280 261 writel(tmp, &ep->cfg->ep_cfg); 281 262 282 263 /* enable irqs */ ··· 464 441 BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) | 465 442 BIT(DATA_OUT_PING_TOKEN_INTERRUPT) | 466 443 BIT(DATA_IN_TOKEN_INTERRUPT), &ep->regs->ep_stat); 444 + 445 + tmp = readl(&ep->cfg->ep_cfg); 446 + if (ep->is_in) 447 + tmp &= ~USB3380_EP_CFG_MASK_IN; 448 + else 449 + tmp &= ~USB3380_EP_CFG_MASK_OUT; 450 + writel(tmp, &ep->cfg->ep_cfg); 467 451 } 468 452 469 453 static void nuke(struct net2280_ep *); ··· 1498 1468 spin_lock_irqsave(&dev->lock, flags); 1499 1469 tmp = readl(&dev->usb->usbctl); 1500 1470 dev->softconnect = (is_on != 0); 1501 - if (is_on) 1502 - tmp |= BIT(USB_DETECT_ENABLE); 1503 - else 1504 - tmp &= ~BIT(USB_DETECT_ENABLE); 1505 - writel(tmp, &dev->usb->usbctl); 1471 + if (is_on) { 1472 + ep0_start(dev); 1473 + writel(tmp | BIT(USB_DETECT_ENABLE), &dev->usb->usbctl); 1474 + } else { 1475 + writel(tmp & ~BIT(USB_DETECT_ENABLE), &dev->usb->usbctl); 1476 + stop_activity(dev, dev->driver); 1477 + } 1478 + 1506 1479 spin_unlock_irqrestore(&dev->lock, flags); 1507 1480 1508 1481 return 0; ··· 1893 1860 tmp = ((0 << ENDPOINT_NUMBER) | BIT(ENDPOINT_DIRECTION) | 1894 1861 (2 << OUT_ENDPOINT_TYPE) | (2 << IN_ENDPOINT_TYPE) | 1895 1862 ((dev->enhanced_mode) ? 1896 - BIT(OUT_ENDPOINT_ENABLE) : BIT(ENDPOINT_ENABLE)) | 1897 - BIT(IN_ENDPOINT_ENABLE)); 1863 + BIT(OUT_ENDPOINT_ENABLE) | BIT(IN_ENDPOINT_ENABLE) : 1864 + BIT(ENDPOINT_ENABLE))); 1898 1865 1899 1866 for (i = 1; i < 5; i++) 1900 1867 writel(tmp, &dev->ep[i].cfg->ep_cfg); ··· 2008 1975 /* clear old dma and irq state */ 2009 1976 for (tmp = 0; tmp < 4; tmp++) { 2010 1977 struct net2280_ep *ep = &dev->ep[tmp + 1]; 1978 + struct net2280_dma_regs __iomem *dma; 2011 1979 2012 - if (ep->dma) 1980 + if (ep->dma) { 2013 1981 abort_dma(ep); 1982 + } else { 1983 + dma = &dev->dma[tmp]; 1984 + writel(BIT(DMA_ABORT), &dma->dmastat); 1985 + writel(0, &dma->dmactl); 1986 + } 2014 1987 } 2015 1988 2016 1989 writel(~0, &dev->regs->irqstat0), writel(~0, &dev->regs->irqstat1); ··· 2104 2065 2105 2066 if (dev->enhanced_mode) { 2106 2067 ep->cfg = &dev->epregs[ne[i]]; 2068 + /* 2069 + * Set USB endpoint number, hardware allows same number 2070 + * in both directions. 2071 + */ 2072 + if (i > 0 && i < 5) 2073 + writel(ne[i], &ep->cfg->ep_cfg); 2107 2074 ep->regs = (struct net2280_ep_regs __iomem *) 2108 2075 (((void __iomem *)&dev->epregs[ne[i]]) + 2109 2076 ep_reg_addr[i]); ··· 2919 2874 return; 2920 2875 } 2921 2876 2877 + static void usb338x_handle_ep_intr(struct net2280 *dev, u32 stat0) 2878 + { 2879 + u32 index; 2880 + u32 bit; 2881 + 2882 + for (index = 0; index < ARRAY_SIZE(ep_bit); index++) { 2883 + bit = BIT(ep_bit[index]); 2884 + 2885 + if (!stat0) 2886 + break; 2887 + 2888 + if (!(stat0 & bit)) 2889 + continue; 2890 + 2891 + stat0 &= ~bit; 2892 + 2893 + handle_ep_small(&dev->ep[index]); 2894 + } 2895 + } 2896 + 2922 2897 static void handle_stat0_irqs(struct net2280 *dev, u32 stat) 2923 2898 { 2924 2899 struct net2280_ep *ep; ··· 3163 3098 #undef w_length 3164 3099 3165 3100 next_endpoints: 3166 - /* endpoint data irq ? */ 3167 - scratch = stat & 0x7f; 3168 - stat &= ~0x7f; 3169 - for (num = 0; scratch; num++) { 3170 - u32 t; 3101 + if ((dev->quirks & PLX_SUPERSPEED) && dev->enhanced_mode) { 3102 + u32 mask = (BIT(ENDPOINT_0_INTERRUPT) | 3103 + USB3380_IRQSTAT0_EP_INTR_MASK_IN | 3104 + USB3380_IRQSTAT0_EP_INTR_MASK_OUT); 3171 3105 3172 - /* do this endpoint's FIFO and queue need tending? */ 3173 - t = BIT(num); 3174 - if ((scratch & t) == 0) 3175 - continue; 3176 - scratch ^= t; 3106 + if (stat & mask) { 3107 + usb338x_handle_ep_intr(dev, stat & mask); 3108 + stat &= ~mask; 3109 + } 3110 + } else { 3111 + /* endpoint data irq ? */ 3112 + scratch = stat & 0x7f; 3113 + stat &= ~0x7f; 3114 + for (num = 0; scratch; num++) { 3115 + u32 t; 3177 3116 3178 - ep = &dev->ep[num]; 3179 - handle_ep_small(ep); 3117 + /* do this endpoint's FIFO and queue need tending? */ 3118 + t = BIT(num); 3119 + if ((scratch & t) == 0) 3120 + continue; 3121 + scratch ^= t; 3122 + 3123 + ep = &dev->ep[num]; 3124 + handle_ep_small(ep); 3125 + } 3180 3126 } 3181 3127 3182 3128 if (stat)
+13 -15
drivers/usb/gadget/udc/s3c2410_udc.c
··· 92 92 93 93 static uint32_t s3c2410_ticks = 0; 94 94 95 - static int dprintk(int level, const char *fmt, ...) 95 + __printf(2, 3) 96 + static void dprintk(int level, const char *fmt, ...) 96 97 { 97 - static char printk_buf[1024]; 98 98 static long prevticks; 99 99 static int invocation; 100 + struct va_format vaf; 100 101 va_list args; 101 - int len; 102 102 103 103 if (level > USB_S3C2410_DEBUG_LEVEL) 104 - return 0; 104 + return; 105 + 106 + va_start(args, fmt); 107 + 108 + vaf.fmt = fmt; 109 + vaf.va = &args; 105 110 106 111 if (s3c2410_ticks != prevticks) { 107 112 prevticks = s3c2410_ticks; 108 113 invocation = 0; 109 114 } 110 115 111 - len = scnprintf(printk_buf, 112 - sizeof(printk_buf), "%1lu.%02d USB: ", 113 - prevticks, invocation++); 116 + pr_debug("%1lu.%02d USB: %pV", prevticks, invocation++, &vaf); 114 117 115 - va_start(args, fmt); 116 - len = vscnprintf(printk_buf+len, 117 - sizeof(printk_buf)-len, fmt, args); 118 118 va_end(args); 119 - 120 - pr_debug("%s", printk_buf); 121 - return len; 122 119 } 123 120 #else 124 - static int dprintk(int level, const char *fmt, ...) 121 + __printf(2, 3) 122 + static void dprintk(int level, const char *fmt, ...) 125 123 { 126 - return 0; 127 124 } 128 125 #endif 126 + 129 127 static int s3c2410_udc_debugfs_seq_show(struct seq_file *m, void *p) 130 128 { 131 129 u32 addr_reg, pwr_reg, ep_int_reg, usb_int_reg;
+6 -2
drivers/usb/musb/am35x.c
··· 438 438 } 439 439 440 440 static const struct musb_platform_ops am35x_ops = { 441 - .quirks = MUSB_INDEXED_EP, 441 + .quirks = MUSB_DMA_INVENTRA | MUSB_INDEXED_EP, 442 442 .init = am35x_musb_init, 443 443 .exit = am35x_musb_exit, 444 444 445 445 .read_fifo = am35x_read_fifo, 446 + #ifdef CONFIG_USB_INVENTRA_DMA 447 + .dma_init = musbhs_dma_controller_create, 448 + .dma_exit = musbhs_dma_controller_destroy, 449 + #endif 446 450 .enable = am35x_musb_enable, 447 451 .disable = am35x_musb_disable, 448 452 ··· 569 565 return 0; 570 566 } 571 567 572 - #ifdef CONFIG_PM 568 + #ifdef CONFIG_PM_SLEEP 573 569 static int am35x_suspend(struct device *dev) 574 570 { 575 571 struct am35x_glue *glue = dev_get_drvdata(dev);
+5
drivers/usb/musb/blackfin.c
··· 465 465 } 466 466 467 467 static const struct musb_platform_ops bfin_ops = { 468 + .quirks = MUSB_DMA_INVENTRA, 468 469 .init = bfin_musb_init, 469 470 .exit = bfin_musb_exit, 470 471 ··· 478 477 .fifo_mode = 2, 479 478 .read_fifo = bfin_read_fifo, 480 479 .write_fifo = bfin_write_fifo, 480 + #ifdef CONFIG_USB_INVENTRA_DMA 481 + .dma_init = musbhs_dma_controller_create, 482 + .dma_exit = musbhs_dma_controller_destroy, 483 + #endif 481 484 .enable = bfin_musb_enable, 482 485 .disable = bfin_musb_disable, 483 486
+6 -3
drivers/usb/musb/cppi_dma.c
··· 1297 1297 EXPORT_SYMBOL_GPL(cppi_interrupt); 1298 1298 1299 1299 /* Instantiate a software object representing a DMA controller. */ 1300 - struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *mregs) 1300 + struct dma_controller * 1301 + cppi_dma_controller_create(struct musb *musb, void __iomem *mregs) 1301 1302 { 1302 1303 struct cppi *controller; 1303 1304 struct device *dev = musb->controller; ··· 1335 1334 if (irq > 0) { 1336 1335 if (request_irq(irq, cppi_interrupt, 0, "cppi-dma", musb)) { 1337 1336 dev_err(dev, "request_irq %d failed!\n", irq); 1338 - dma_controller_destroy(&controller->controller); 1337 + musb_dma_controller_destroy(&controller->controller); 1339 1338 return NULL; 1340 1339 } 1341 1340 controller->irq = irq; ··· 1344 1343 cppi_controller_start(controller); 1345 1344 return &controller->controller; 1346 1345 } 1346 + EXPORT_SYMBOL_GPL(cppi_dma_controller_create); 1347 1347 1348 1348 /* 1349 1349 * Destroy a previously-instantiated DMA controller. 1350 1350 */ 1351 - void dma_controller_destroy(struct dma_controller *c) 1351 + void cppi_dma_controller_destroy(struct dma_controller *c) 1352 1352 { 1353 1353 struct cppi *cppi; 1354 1354 ··· 1365 1363 1366 1364 kfree(cppi); 1367 1365 } 1366 + EXPORT_SYMBOL_GPL(cppi_dma_controller_destroy); 1368 1367 1369 1368 /* 1370 1369 * Context: controller irqlocked, endpoint selected
+5 -1
drivers/usb/musb/da8xx.c
··· 458 458 } 459 459 460 460 static const struct musb_platform_ops da8xx_ops = { 461 - .quirks = MUSB_INDEXED_EP, 461 + .quirks = MUSB_DMA_CPPI | MUSB_INDEXED_EP, 462 462 .init = da8xx_musb_init, 463 463 .exit = da8xx_musb_exit, 464 464 465 465 .fifo_mode = 2, 466 + #ifdef CONFIG_USB_TI_CPPI_DMA 467 + .dma_init = cppi_dma_controller_create, 468 + .dma_exit = cppi_dma_controller_destroy, 469 + #endif 466 470 .enable = da8xx_musb_enable, 467 471 .disable = da8xx_musb_disable, 468 472
+6 -1
drivers/usb/musb/davinci.c
··· 284 284 * mask, state, "vector", and EOI registers. 285 285 */ 286 286 cppi = container_of(musb->dma_controller, struct cppi, controller); 287 - if (is_cppi_enabled() && musb->dma_controller && !cppi->irq) 287 + if (is_cppi_enabled(musb) && musb->dma_controller && !cppi->irq) 288 288 retval = cppi_interrupt(irq, __hci); 289 289 290 290 /* ack and handle non-CPPI interrupts */ ··· 491 491 } 492 492 493 493 static const struct musb_platform_ops davinci_ops = { 494 + .quirks = MUSB_DMA_CPPI, 494 495 .init = davinci_musb_init, 495 496 .exit = davinci_musb_exit, 496 497 498 + #ifdef CONFIG_USB_TI_CPPI_DMA 499 + .dma_init = cppi_dma_controller_create, 500 + .dma_exit = cppi_dma_controller_destroy, 501 + #endif 497 502 .enable = davinci_musb_enable, 498 503 .disable = davinci_musb_disable, 499 504
+5 -1
drivers/usb/musb/jz4740.c
··· 105 105 return 0; 106 106 } 107 107 108 + /* 109 + * DMA has not been confirmed to work with CONFIG_USB_INVENTRA_DMA, 110 + * so let's not set up the dma function pointers yet. 111 + */ 108 112 static const struct musb_platform_ops jz4740_musb_ops = { 109 - .quirks = MUSB_INDEXED_EP, 113 + .quirks = MUSB_DMA_INVENTRA | MUSB_INDEXED_EP, 110 114 .fifo_mode = 2, 111 115 .init = jz4740_musb_init, 112 116 .exit = jz4740_musb_exit,
+55 -34
drivers/usb/musb/musb_core.c
··· 251 251 return 0x10 + offset; 252 252 } 253 253 254 + static u32 musb_default_busctl_offset(u8 epnum, u16 offset) 255 + { 256 + return 0x80 + (0x08 * epnum) + offset; 257 + } 258 + 254 259 static u8 musb_default_readb(const void __iomem *addr, unsigned offset) 255 260 { 256 261 return __raw_readb(addr + offset); ··· 314 309 index += len & ~0x03; 315 310 } 316 311 if (len & 0x02) { 317 - musb_writew(fifo, 0, *(u16 *)&src[index]); 312 + __raw_writew(*(u16 *)&src[index], fifo); 318 313 index += 2; 319 314 } 320 315 } else { ··· 324 319 } 325 320 } 326 321 if (len & 0x01) 327 - musb_writeb(fifo, 0, src[index]); 322 + __raw_writeb(src[index], fifo); 328 323 } else { 329 324 /* byte aligned */ 330 325 iowrite8_rep(fifo, src, len); ··· 356 351 index = len & ~0x03; 357 352 } 358 353 if (len & 0x02) { 359 - *(u16 *)&dst[index] = musb_readw(fifo, 0); 354 + *(u16 *)&dst[index] = __raw_readw(fifo); 360 355 index += 2; 361 356 } 362 357 } else { ··· 366 361 } 367 362 } 368 363 if (len & 0x01) 369 - dst[index] = musb_readb(fifo, 0); 364 + dst[index] = __raw_readb(fifo); 370 365 } else { 371 366 /* byte aligned */ 372 367 ioread8_rep(fifo, dst, len); ··· 393 388 394 389 void (*musb_writel)(void __iomem *addr, unsigned offset, u32 data); 395 390 EXPORT_SYMBOL_GPL(musb_writel); 391 + 392 + #ifndef CONFIG_MUSB_PIO_ONLY 393 + struct dma_controller * 394 + (*musb_dma_controller_create)(struct musb *musb, void __iomem *base); 395 + EXPORT_SYMBOL(musb_dma_controller_create); 396 + 397 + void (*musb_dma_controller_destroy)(struct dma_controller *c); 398 + EXPORT_SYMBOL(musb_dma_controller_destroy); 399 + #endif 396 400 397 401 /* 398 402 * New style IO functions ··· 1549 1535 #endif 1550 1536 1551 1537 hw_ep->regs = musb->io.ep_offset(i, 0) + mbase; 1552 - hw_ep->target_regs = musb_read_target_reg_base(i, mbase); 1553 1538 hw_ep->rx_reinit = 1; 1554 1539 hw_ep->tx_reinit = 1; 1555 1540 ··· 1671 1658 /* called with controller lock already held */ 1672 1659 1673 1660 if (!epnum) { 1674 - #ifndef CONFIG_USB_TUSB_OMAP_DMA 1675 - if (!is_cppi_enabled()) { 1661 + if (!is_cppi_enabled(musb)) { 1676 1662 /* endpoint 0 */ 1677 1663 if (is_host_active(musb)) 1678 1664 musb_h_ep0_irq(musb); 1679 1665 else 1680 1666 musb_g_ep0_irq(musb); 1681 1667 } 1682 - #endif 1683 1668 } else { 1684 1669 /* endpoints 1..15 */ 1685 1670 if (transmit) { ··· 2032 2021 if (musb->ops->quirks) 2033 2022 musb->io.quirks = musb->ops->quirks; 2034 2023 2035 - /* At least tusb6010 has it's own offsets.. */ 2036 - if (musb->ops->ep_offset) 2037 - musb->io.ep_offset = musb->ops->ep_offset; 2038 - if (musb->ops->ep_select) 2039 - musb->io.ep_select = musb->ops->ep_select; 2040 - 2041 - /* ..and some devices use indexed offset or flat offset */ 2024 + /* Set default ep access to indexed offset or flat offset ops */ 2042 2025 if (musb->io.quirks & MUSB_INDEXED_EP) { 2043 2026 musb->io.ep_offset = musb_indexed_ep_offset; 2044 2027 musb->io.ep_select = musb_indexed_ep_select; ··· 2040 2035 musb->io.ep_offset = musb_flat_ep_offset; 2041 2036 musb->io.ep_select = musb_flat_ep_select; 2042 2037 } 2038 + /* And override them with platform specific ops if specified. */ 2039 + if (musb->ops->ep_offset) 2040 + musb->io.ep_offset = musb->ops->ep_offset; 2041 + if (musb->ops->ep_select) 2042 + musb->io.ep_select = musb->ops->ep_select; 2043 2043 2044 2044 if (musb->ops->fifo_mode) 2045 2045 fifo_mode = musb->ops->fifo_mode; ··· 2055 2045 musb->io.fifo_offset = musb->ops->fifo_offset; 2056 2046 else 2057 2047 musb->io.fifo_offset = musb_default_fifo_offset; 2048 + 2049 + if (musb->ops->busctl_offset) 2050 + musb->io.busctl_offset = musb->ops->busctl_offset; 2051 + else 2052 + musb->io.busctl_offset = musb_default_busctl_offset; 2058 2053 2059 2054 if (musb->ops->readb) 2060 2055 musb_readb = musb->ops->readb; ··· 2073 2058 musb_readl = musb->ops->readl; 2074 2059 if (musb->ops->writel) 2075 2060 musb_writel = musb->ops->writel; 2061 + 2062 + #ifndef CONFIG_MUSB_PIO_ONLY 2063 + if (!musb->ops->dma_init || !musb->ops->dma_exit) { 2064 + dev_err(dev, "DMA controller not set\n"); 2065 + goto fail2; 2066 + } 2067 + musb_dma_controller_create = musb->ops->dma_init; 2068 + musb_dma_controller_destroy = musb->ops->dma_exit; 2069 + #endif 2076 2070 2077 2071 if (musb->ops->read_fifo) 2078 2072 musb->io.read_fifo = musb->ops->read_fifo; ··· 2102 2078 pm_runtime_get_sync(musb->controller); 2103 2079 2104 2080 if (use_dma && dev->dma_mask) { 2105 - musb->dma_controller = dma_controller_create(musb, musb->mregs); 2081 + musb->dma_controller = 2082 + musb_dma_controller_create(musb, musb->mregs); 2106 2083 if (IS_ERR(musb->dma_controller)) { 2107 2084 status = PTR_ERR(musb->dma_controller); 2108 2085 goto fail2_5; ··· 2214 2189 cancel_delayed_work_sync(&musb->finish_resume_work); 2215 2190 cancel_delayed_work_sync(&musb->deassert_reset_work); 2216 2191 if (musb->dma_controller) 2217 - dma_controller_destroy(musb->dma_controller); 2192 + musb_dma_controller_destroy(musb->dma_controller); 2218 2193 fail2_5: 2219 2194 pm_runtime_put_sync(musb->controller); 2220 2195 ··· 2273 2248 musb_shutdown(pdev); 2274 2249 2275 2250 if (musb->dma_controller) 2276 - dma_controller_destroy(musb->dma_controller); 2251 + musb_dma_controller_destroy(musb->dma_controller); 2277 2252 2278 2253 cancel_work_sync(&musb->irq_work); 2279 2254 cancel_delayed_work_sync(&musb->finish_resume_work); ··· 2341 2316 musb_readb(epio, MUSB_RXINTERVAL); 2342 2317 2343 2318 musb->context.index_regs[i].txfunaddr = 2344 - musb_read_txfunaddr(musb_base, i); 2319 + musb_read_txfunaddr(musb, i); 2345 2320 musb->context.index_regs[i].txhubaddr = 2346 - musb_read_txhubaddr(musb_base, i); 2321 + musb_read_txhubaddr(musb, i); 2347 2322 musb->context.index_regs[i].txhubport = 2348 - musb_read_txhubport(musb_base, i); 2323 + musb_read_txhubport(musb, i); 2349 2324 2350 2325 musb->context.index_regs[i].rxfunaddr = 2351 - musb_read_rxfunaddr(musb_base, i); 2326 + musb_read_rxfunaddr(musb, i); 2352 2327 musb->context.index_regs[i].rxhubaddr = 2353 - musb_read_rxhubaddr(musb_base, i); 2328 + musb_read_rxhubaddr(musb, i); 2354 2329 musb->context.index_regs[i].rxhubport = 2355 - musb_read_rxhubport(musb_base, i); 2330 + musb_read_rxhubport(musb, i); 2356 2331 } 2357 2332 } 2358 2333 ··· 2360 2335 { 2361 2336 int i; 2362 2337 void __iomem *musb_base = musb->mregs; 2363 - void __iomem *ep_target_regs; 2364 2338 void __iomem *epio; 2365 2339 u8 power; 2366 2340 ··· 2420 2396 musb_writeb(epio, MUSB_RXINTERVAL, 2421 2397 2422 2398 musb->context.index_regs[i].rxinterval); 2423 - musb_write_txfunaddr(musb_base, i, 2399 + musb_write_txfunaddr(musb, i, 2424 2400 musb->context.index_regs[i].txfunaddr); 2425 - musb_write_txhubaddr(musb_base, i, 2401 + musb_write_txhubaddr(musb, i, 2426 2402 musb->context.index_regs[i].txhubaddr); 2427 - musb_write_txhubport(musb_base, i, 2403 + musb_write_txhubport(musb, i, 2428 2404 musb->context.index_regs[i].txhubport); 2429 2405 2430 - ep_target_regs = 2431 - musb_read_target_reg_base(i, musb_base); 2432 - 2433 - musb_write_rxfunaddr(ep_target_regs, 2406 + musb_write_rxfunaddr(musb, i, 2434 2407 musb->context.index_regs[i].rxfunaddr); 2435 - musb_write_rxhubaddr(ep_target_regs, 2408 + musb_write_rxhubaddr(musb, i, 2436 2409 musb->context.index_regs[i].rxhubaddr); 2437 - musb_write_rxhubport(ep_target_regs, 2410 + musb_write_rxhubport(musb, i, 2438 2411 musb->context.index_regs[i].rxhubport); 2439 2412 } 2440 2413 musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
+25 -3
drivers/usb/musb/musb_core.h
··· 67 67 #include "musb_dma.h" 68 68 69 69 #include "musb_io.h" 70 - #include "musb_regs.h" 71 70 72 71 #include "musb_gadget.h" 73 72 #include <linux/usb/hcd.h> ··· 156 157 * @writel: write 32 bits 157 158 * @read_fifo: reads the fifo 158 159 * @write_fifo: writes to fifo 160 + * @dma_init: platform specific dma init function 161 + * @dma_exit: platform specific dma exit function 159 162 * @init: turns on clocks, sets up platform-specific registers, etc 160 163 * @exit: undoes @init 161 164 * @set_mode: forcefully changes operating mode ··· 166 165 * @vbus_status: returns vbus status if possible 167 166 * @set_vbus: forces vbus status 168 167 * @adjust_channel_params: pre check for standard dma channel_program func 168 + * @pre_root_reset_end: called before the root usb port reset flag gets cleared 169 + * @post_root_reset_end: called after the root usb port reset flag gets cleared 169 170 */ 170 171 struct musb_platform_ops { 171 172 ··· 190 187 void (*ep_select)(void __iomem *mbase, u8 epnum); 191 188 u16 fifo_mode; 192 189 u32 (*fifo_offset)(u8 epnum); 190 + u32 (*busctl_offset)(u8 epnum, u16 offset); 193 191 u8 (*readb)(const void __iomem *addr, unsigned offset); 194 192 void (*writeb)(void __iomem *addr, unsigned offset, u8 data); 195 193 u16 (*readw)(const void __iomem *addr, unsigned offset); ··· 199 195 void (*writel)(void __iomem *addr, unsigned offset, u32 data); 200 196 void (*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf); 201 197 void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf); 198 + struct dma_controller * 199 + (*dma_init) (struct musb *musb, void __iomem *base); 200 + void (*dma_exit)(struct dma_controller *c); 202 201 int (*set_mode)(struct musb *musb, u8 mode); 203 202 void (*try_idle)(struct musb *musb, unsigned long timeout); 204 203 int (*recover)(struct musb *musb); ··· 212 205 int (*adjust_channel_params)(struct dma_channel *channel, 213 206 u16 packet_sz, u8 *mode, 214 207 dma_addr_t *dma_addr, u32 *len); 208 + void (*pre_root_reset_end)(struct musb *musb); 209 + void (*post_root_reset_end)(struct musb *musb); 215 210 }; 216 211 217 212 /* ··· 249 240 dma_addr_t fifo_sync; 250 241 void __iomem *fifo_sync_va; 251 242 #endif 252 - 253 - void __iomem *target_regs; 254 243 255 244 /* currently scheduled peripheral endpoint */ 256 245 struct musb_qh *in_qh; ··· 444 437 #endif 445 438 }; 446 439 440 + /* This must be included after struct musb is defined */ 441 + #include "musb_regs.h" 442 + 447 443 static inline struct musb *gadget_to_musb(struct usb_gadget *g) 448 444 { 449 445 return container_of(g, struct musb, g); ··· 598 588 return -EINVAL; 599 589 600 590 return musb->ops->exit(musb); 591 + } 592 + 593 + static inline void musb_platform_pre_root_reset_end(struct musb *musb) 594 + { 595 + if (musb->ops->pre_root_reset_end) 596 + musb->ops->pre_root_reset_end(musb); 597 + } 598 + 599 + static inline void musb_platform_post_root_reset_end(struct musb *musb) 600 + { 601 + if (musb->ops->post_root_reset_end) 602 + musb->ops->post_root_reset_end(musb); 601 603 } 602 604 603 605 #endif /* __MUSB_CORE_H__ */
+5 -3
drivers/usb/musb/musb_cppi41.c
··· 678 678 return ret; 679 679 } 680 680 681 - void dma_controller_destroy(struct dma_controller *c) 681 + void cppi41_dma_controller_destroy(struct dma_controller *c) 682 682 { 683 683 struct cppi41_dma_controller *controller = container_of(c, 684 684 struct cppi41_dma_controller, controller); ··· 687 687 cppi41_dma_controller_stop(controller); 688 688 kfree(controller); 689 689 } 690 + EXPORT_SYMBOL_GPL(cppi41_dma_controller_destroy); 690 691 691 - struct dma_controller *dma_controller_create(struct musb *musb, 692 - void __iomem *base) 692 + struct dma_controller * 693 + cppi41_dma_controller_create(struct musb *musb, void __iomem *base) 693 694 { 694 695 struct cppi41_dma_controller *controller; 695 696 int ret = 0; ··· 727 726 return ERR_PTR(ret); 728 727 return NULL; 729 728 } 729 + EXPORT_SYMBOL_GPL(cppi41_dma_controller_create);
+99 -1
drivers/usb/musb/musb_debugfs.c
··· 191 191 { 192 192 struct seq_file *s = file->private_data; 193 193 struct musb *musb = s->private; 194 - u8 test = 0; 194 + u8 test; 195 195 char buf[18]; 196 + 197 + test = musb_readb(musb->mregs, MUSB_TESTMODE); 198 + if (test) { 199 + dev_err(musb->controller, "Error: test mode is already set. " 200 + "Please do USB Bus Reset to start a new test.\n"); 201 + return count; 202 + } 196 203 197 204 memset(buf, 0x00, sizeof(buf)); 198 205 ··· 245 238 .release = single_release, 246 239 }; 247 240 241 + static int musb_softconnect_show(struct seq_file *s, void *unused) 242 + { 243 + struct musb *musb = s->private; 244 + u8 reg; 245 + int connect; 246 + 247 + switch (musb->xceiv->otg->state) { 248 + case OTG_STATE_A_HOST: 249 + case OTG_STATE_A_WAIT_BCON: 250 + reg = musb_readb(musb->mregs, MUSB_DEVCTL); 251 + connect = reg & MUSB_DEVCTL_SESSION ? 1 : 0; 252 + break; 253 + default: 254 + connect = -1; 255 + } 256 + 257 + seq_printf(s, "%d\n", connect); 258 + 259 + return 0; 260 + } 261 + 262 + static int musb_softconnect_open(struct inode *inode, struct file *file) 263 + { 264 + return single_open(file, musb_softconnect_show, inode->i_private); 265 + } 266 + 267 + static ssize_t musb_softconnect_write(struct file *file, 268 + const char __user *ubuf, size_t count, loff_t *ppos) 269 + { 270 + struct seq_file *s = file->private_data; 271 + struct musb *musb = s->private; 272 + char buf[2]; 273 + u8 reg; 274 + 275 + memset(buf, 0x00, sizeof(buf)); 276 + 277 + if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 278 + return -EFAULT; 279 + 280 + if (!strncmp(buf, "0", 1)) { 281 + switch (musb->xceiv->otg->state) { 282 + case OTG_STATE_A_HOST: 283 + musb_root_disconnect(musb); 284 + reg = musb_readb(musb->mregs, MUSB_DEVCTL); 285 + reg &= ~MUSB_DEVCTL_SESSION; 286 + musb_writeb(musb->mregs, MUSB_DEVCTL, reg); 287 + break; 288 + default: 289 + break; 290 + } 291 + } else if (!strncmp(buf, "1", 1)) { 292 + switch (musb->xceiv->otg->state) { 293 + case OTG_STATE_A_WAIT_BCON: 294 + /* 295 + * musb_save_context() called in musb_runtime_suspend() 296 + * might cache devctl with SESSION bit cleared during 297 + * soft-disconnect, so specifically set SESSION bit 298 + * here to preserve it for musb_runtime_resume(). 299 + */ 300 + musb->context.devctl |= MUSB_DEVCTL_SESSION; 301 + reg = musb_readb(musb->mregs, MUSB_DEVCTL); 302 + reg |= MUSB_DEVCTL_SESSION; 303 + musb_writeb(musb->mregs, MUSB_DEVCTL, reg); 304 + break; 305 + default: 306 + break; 307 + } 308 + } 309 + 310 + return count; 311 + } 312 + 313 + /* 314 + * In host mode, connect/disconnect the bus without physically 315 + * remove the devices. 316 + */ 317 + static const struct file_operations musb_softconnect_fops = { 318 + .open = musb_softconnect_open, 319 + .write = musb_softconnect_write, 320 + .read = seq_read, 321 + .llseek = seq_lseek, 322 + .release = single_release, 323 + }; 324 + 248 325 int musb_init_debugfs(struct musb *musb) 249 326 { 250 327 struct dentry *root; ··· 350 259 351 260 file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, 352 261 root, musb, &musb_test_mode_fops); 262 + if (!file) { 263 + ret = -ENOMEM; 264 + goto err1; 265 + } 266 + 267 + file = debugfs_create_file("softconnect", S_IRUGO | S_IWUSR, 268 + root, musb, &musb_softconnect_fops); 353 269 if (!file) { 354 270 ret = -ENOMEM; 355 271 goto err1;
+57 -10
drivers/usb/musb/musb_dma.h
··· 68 68 #define is_dma_capable() (1) 69 69 #endif 70 70 71 - #if defined(CONFIG_USB_TI_CPPI_DMA) || defined(CONFIG_USB_TI_CPPI41_DMA) 72 - #define is_cppi_enabled() 1 71 + #ifdef CONFIG_USB_UX500_DMA 72 + #define musb_dma_ux500(musb) (musb->io.quirks & MUSB_DMA_UX500) 73 73 #else 74 - #define is_cppi_enabled() 0 74 + #define musb_dma_ux500(musb) 0 75 + #endif 76 + 77 + #ifdef CONFIG_USB_TI_CPPI41_DMA 78 + #define musb_dma_cppi41(musb) (musb->io.quirks & MUSB_DMA_CPPI41) 79 + #else 80 + #define musb_dma_cppi41(musb) 0 81 + #endif 82 + 83 + #ifdef CONFIG_USB_TI_CPPI_DMA 84 + #define musb_dma_cppi(musb) (musb->io.quirks & MUSB_DMA_CPPI) 85 + #else 86 + #define musb_dma_cppi(musb) 0 75 87 #endif 76 88 77 89 #ifdef CONFIG_USB_TUSB_OMAP_DMA 78 - #define tusb_dma_omap() 1 90 + #define tusb_dma_omap(musb) (musb->io.quirks & MUSB_DMA_TUSB_OMAP) 79 91 #else 80 - #define tusb_dma_omap() 0 92 + #define tusb_dma_omap(musb) 0 93 + #endif 94 + 95 + #ifdef CONFIG_USB_INVENTRA_DMA 96 + #define musb_dma_inventra(musb) (musb->io.quirks & MUSB_DMA_INVENTRA) 97 + #else 98 + #define musb_dma_inventra(musb) 0 99 + #endif 100 + 101 + #if defined(CONFIG_USB_TI_CPPI_DMA) || defined(CONFIG_USB_TI_CPPI41_DMA) 102 + #define is_cppi_enabled(musb) \ 103 + (musb_dma_cppi(musb) || musb_dma_cppi41(musb)) 104 + #else 105 + #define is_cppi_enabled(musb) 0 81 106 #endif 82 107 83 108 /* Anomaly 05000456 - USB Receive Interrupt Is Not Generated in DMA Mode 1 ··· 202 177 extern void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit); 203 178 204 179 #ifdef CONFIG_MUSB_PIO_ONLY 205 - static inline struct dma_controller *dma_controller_create(struct musb *m, 206 - void __iomem *io) 180 + static inline struct dma_controller * 181 + musb_dma_controller_create(struct musb *m, void __iomem *io) 207 182 { 208 183 return NULL; 209 184 } 210 185 211 - static inline void dma_controller_destroy(struct dma_controller *d) { } 186 + static inline void musb_dma_controller_destroy(struct dma_controller *d) { } 212 187 213 188 #else 214 189 215 - extern struct dma_controller *dma_controller_create(struct musb *, void __iomem *); 190 + extern struct dma_controller * 191 + (*musb_dma_controller_create)(struct musb *, void __iomem *); 216 192 217 - extern void dma_controller_destroy(struct dma_controller *); 193 + extern void (*musb_dma_controller_destroy)(struct dma_controller *); 218 194 #endif 195 + 196 + /* Platform specific DMA functions */ 197 + extern struct dma_controller * 198 + musbhs_dma_controller_create(struct musb *musb, void __iomem *base); 199 + extern void musbhs_dma_controller_destroy(struct dma_controller *c); 200 + 201 + extern struct dma_controller * 202 + tusb_dma_controller_create(struct musb *musb, void __iomem *base); 203 + extern void tusb_dma_controller_destroy(struct dma_controller *c); 204 + 205 + extern struct dma_controller * 206 + cppi_dma_controller_create(struct musb *musb, void __iomem *base); 207 + extern void cppi_dma_controller_destroy(struct dma_controller *c); 208 + 209 + extern struct dma_controller * 210 + cppi41_dma_controller_create(struct musb *musb, void __iomem *base); 211 + extern void cppi41_dma_controller_destroy(struct dma_controller *c); 212 + 213 + extern struct dma_controller * 214 + ux500_dma_controller_create(struct musb *musb, void __iomem *base); 215 + extern void ux500_dma_controller_destroy(struct dma_controller *c); 219 216 220 217 #endif /* __MUSB_DMA_H__ */
+5 -1
drivers/usb/musb/musb_dsps.c
··· 634 634 } 635 635 636 636 static struct musb_platform_ops dsps_ops = { 637 - .quirks = MUSB_INDEXED_EP, 637 + .quirks = MUSB_DMA_CPPI41 | MUSB_INDEXED_EP, 638 638 .init = dsps_musb_init, 639 639 .exit = dsps_musb_exit, 640 640 641 + #ifdef CONFIG_USB_TI_CPPI41_DMA 642 + .dma_init = cppi41_dma_controller_create, 643 + .dma_exit = cppi41_dma_controller_destroy, 644 + #endif 641 645 .enable = dsps_musb_enable, 642 646 .disable = dsps_musb_disable, 643 647
+14 -10
drivers/usb/musb/musb_gadget.c
··· 366 366 } 367 367 368 368 #endif 369 - if (is_cppi_enabled()) { 369 + if (is_cppi_enabled(musb)) { 370 370 /* program endpoint CSR first, then setup DMA */ 371 371 csr &= ~(MUSB_TXCSR_P_UNDERRUN | MUSB_TXCSR_TXPKTRDY); 372 372 csr |= MUSB_TXCSR_DMAENAB | MUSB_TXCSR_DMAMODE | ··· 402 402 musb_writew(epio, MUSB_TXCSR, csr); 403 403 /* invariant: prequest->buf is non-null */ 404 404 } 405 - } else if (tusb_dma_omap()) 405 + } else if (tusb_dma_omap(musb)) 406 406 use_dma = use_dma && c->channel_program( 407 407 musb_ep->dma, musb_ep->packet_sz, 408 408 request->zero, ··· 489 489 490 490 if (request) { 491 491 u8 is_dma = 0; 492 + bool short_packet = false; 492 493 493 494 if (dma && (csr & MUSB_TXCSR_DMAENAB)) { 494 495 is_dma = 1; ··· 508 507 * First, maybe a terminating short packet. Some DMA 509 508 * engines might handle this by themselves. 510 509 */ 511 - if ((request->zero && request->length 510 + if ((request->zero && request->length) 512 511 && (request->length % musb_ep->packet_sz == 0) 513 512 && (request->actual == request->length)) 514 - #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA) 515 - || (is_dma && (!dma->desired_mode || 513 + short_packet = true; 514 + 515 + if ((musb_dma_inventra(musb) || musb_dma_ux500(musb)) && 516 + (is_dma && (!dma->desired_mode || 516 517 (request->actual & 517 - (musb_ep->packet_sz - 1)))) 518 - #endif 519 - ) { 518 + (musb_ep->packet_sz - 1))))) 519 + short_packet = true; 520 + 521 + if (short_packet) { 520 522 /* 521 523 * On DMA completion, FIFO may not be 522 524 * available yet... ··· 599 595 return; 600 596 } 601 597 602 - if (is_cppi_enabled() && is_buffer_mapped(req)) { 598 + if (is_cppi_enabled(musb) && is_buffer_mapped(req)) { 603 599 struct dma_controller *c = musb->dma_controller; 604 600 struct dma_channel *channel = musb_ep->dma; 605 601 ··· 776 772 fifo_count = min_t(unsigned, len, fifo_count); 777 773 778 774 #ifdef CONFIG_USB_TUSB_OMAP_DMA 779 - if (tusb_dma_omap() && is_buffer_mapped(req)) { 775 + if (tusb_dma_omap(musb) && is_buffer_mapped(req)) { 780 776 struct dma_controller *c = musb->dma_controller; 781 777 struct dma_channel *channel = musb_ep->dma; 782 778 u32 dma_addr = request->dma + request->actual;
+317 -208
drivers/usb/musb/musb_host.c
··· 181 181 /* NOTE: no locks here; caller should lock and select EP */ 182 182 txcsr = musb_readw(ep->regs, MUSB_TXCSR); 183 183 txcsr |= MUSB_TXCSR_DMAENAB | MUSB_TXCSR_H_WZC_BITS; 184 - if (is_cppi_enabled()) 184 + if (is_cppi_enabled(ep->musb)) 185 185 txcsr |= MUSB_TXCSR_DMAMODE; 186 186 musb_writew(ep->regs, MUSB_TXCSR, txcsr); 187 187 } ··· 294 294 295 295 if (!hw_ep->tx_channel) 296 296 musb_h_tx_start(hw_ep); 297 - else if (is_cppi_enabled() || tusb_dma_omap()) 297 + else if (is_cppi_enabled(musb) || tusb_dma_omap(musb)) 298 298 musb_h_tx_dma_start(hw_ep); 299 299 } 300 300 } ··· 555 555 * the busy/not-empty tests are basically paranoia. 556 556 */ 557 557 static void 558 - musb_rx_reinit(struct musb *musb, struct musb_qh *qh, struct musb_hw_ep *ep) 558 + musb_rx_reinit(struct musb *musb, struct musb_qh *qh, u8 epnum) 559 559 { 560 + struct musb_hw_ep *ep = musb->endpoints + epnum; 560 561 u16 csr; 561 562 562 563 /* NOTE: we know the "rx" fifo reinit never triggers for ep0. ··· 595 594 596 595 /* target addr and (for multipoint) hub addr/port */ 597 596 if (musb->is_multipoint) { 598 - musb_write_rxfunaddr(ep->target_regs, qh->addr_reg); 599 - musb_write_rxhubaddr(ep->target_regs, qh->h_addr_reg); 600 - musb_write_rxhubport(ep->target_regs, qh->h_port_reg); 601 - 597 + musb_write_rxfunaddr(musb, epnum, qh->addr_reg); 598 + musb_write_rxhubaddr(musb, epnum, qh->h_addr_reg); 599 + musb_write_rxhubport(musb, epnum, qh->h_port_reg); 602 600 } else 603 601 musb_writeb(musb->mregs, MUSB_FADDR, qh->addr_reg); 604 602 ··· 617 617 ep->rx_reinit = 0; 618 618 } 619 619 620 - static bool musb_tx_dma_program(struct dma_controller *dma, 620 + static int musb_tx_dma_set_mode_mentor(struct dma_controller *dma, 621 621 struct musb_hw_ep *hw_ep, struct musb_qh *qh, 622 - struct urb *urb, u32 offset, u32 length) 622 + struct urb *urb, u32 offset, 623 + u32 *length, u8 *mode) 623 624 { 624 625 struct dma_channel *channel = hw_ep->tx_channel; 625 626 void __iomem *epio = hw_ep->regs; 626 627 u16 pkt_size = qh->maxpacket; 627 628 u16 csr; 628 - u8 mode; 629 629 630 - #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA) 631 - if (length > channel->max_len) 632 - length = channel->max_len; 630 + if (*length > channel->max_len) 631 + *length = channel->max_len; 633 632 634 633 csr = musb_readw(epio, MUSB_TXCSR); 635 - if (length > pkt_size) { 636 - mode = 1; 634 + if (*length > pkt_size) { 635 + *mode = 1; 637 636 csr |= MUSB_TXCSR_DMAMODE | MUSB_TXCSR_DMAENAB; 638 637 /* autoset shouldn't be set in high bandwidth */ 639 638 /* ··· 648 649 can_bulk_split(hw_ep->musb, qh->type))) 649 650 csr |= MUSB_TXCSR_AUTOSET; 650 651 } else { 651 - mode = 0; 652 + *mode = 0; 652 653 csr &= ~(MUSB_TXCSR_AUTOSET | MUSB_TXCSR_DMAMODE); 653 654 csr |= MUSB_TXCSR_DMAENAB; /* against programmer's guide */ 654 655 } 655 656 channel->desired_mode = mode; 656 657 musb_writew(epio, MUSB_TXCSR, csr); 657 - #else 658 - if (!is_cppi_enabled() && !tusb_dma_omap()) 659 - return false; 658 + 659 + return 0; 660 + } 661 + 662 + static int musb_tx_dma_set_mode_cppi_tusb(struct dma_controller *dma, 663 + struct musb_hw_ep *hw_ep, 664 + struct musb_qh *qh, 665 + struct urb *urb, 666 + u32 offset, 667 + u32 *length, 668 + u8 *mode) 669 + { 670 + struct dma_channel *channel = hw_ep->tx_channel; 671 + 672 + if (!is_cppi_enabled(hw_ep->musb) && !tusb_dma_omap(hw_ep->musb)) 673 + return -ENODEV; 660 674 661 675 channel->actual_len = 0; 662 676 ··· 677 665 * TX uses "RNDIS" mode automatically but needs help 678 666 * to identify the zero-length-final-packet case. 679 667 */ 680 - mode = (urb->transfer_flags & URB_ZERO_PACKET) ? 1 : 0; 681 - #endif 668 + *mode = (urb->transfer_flags & URB_ZERO_PACKET) ? 1 : 0; 669 + 670 + return 0; 671 + } 672 + 673 + static bool musb_tx_dma_program(struct dma_controller *dma, 674 + struct musb_hw_ep *hw_ep, struct musb_qh *qh, 675 + struct urb *urb, u32 offset, u32 length) 676 + { 677 + struct dma_channel *channel = hw_ep->tx_channel; 678 + u16 pkt_size = qh->maxpacket; 679 + u8 mode; 680 + int res; 681 + 682 + if (musb_dma_inventra(hw_ep->musb) || musb_dma_ux500(hw_ep->musb)) 683 + res = musb_tx_dma_set_mode_mentor(dma, hw_ep, qh, urb, 684 + offset, &length, &mode); 685 + else 686 + res = musb_tx_dma_set_mode_cppi_tusb(dma, hw_ep, qh, urb, 687 + offset, &length, &mode); 688 + if (res) 689 + return false; 682 690 683 691 qh->segsize = length; 684 692 ··· 710 678 711 679 if (!dma->channel_program(channel, pkt_size, mode, 712 680 urb->transfer_dma + offset, length)) { 681 + void __iomem *epio = hw_ep->regs; 682 + u16 csr; 683 + 713 684 dma->channel_release(channel); 714 685 hw_ep->tx_channel = NULL; 715 686 ··· 836 801 837 802 /* target addr and (for multipoint) hub addr/port */ 838 803 if (musb->is_multipoint) { 839 - musb_write_txfunaddr(mbase, epnum, qh->addr_reg); 840 - musb_write_txhubaddr(mbase, epnum, qh->h_addr_reg); 841 - musb_write_txhubport(mbase, epnum, qh->h_port_reg); 804 + musb_write_txfunaddr(musb, epnum, qh->addr_reg); 805 + musb_write_txhubaddr(musb, epnum, qh->h_addr_reg); 806 + musb_write_txhubport(musb, epnum, qh->h_port_reg); 842 807 /* FIXME if !epnum, do the same for RX ... */ 843 808 } else 844 809 musb_writeb(mbase, MUSB_FADDR, qh->addr_reg); ··· 910 875 u16 csr; 911 876 912 877 if (hw_ep->rx_reinit) { 913 - musb_rx_reinit(musb, qh, hw_ep); 878 + musb_rx_reinit(musb, qh, epnum); 914 879 915 880 /* init new state: toggle and NYET, maybe DMA later */ 916 881 if (usb_gettoggle(urb->dev, qh->epnum, 0)) ··· 936 901 937 902 /* kick things off */ 938 903 939 - if ((is_cppi_enabled() || tusb_dma_omap()) && dma_channel) { 904 + if ((is_cppi_enabled(musb) || tusb_dma_omap(musb)) && dma_channel) { 940 905 /* Candidate for DMA */ 941 906 dma_channel->actual_len = 0L; 942 907 qh->segsize = len; ··· 1476 1441 } else if ((usb_pipeisoc(pipe) || transfer_pending) && dma) { 1477 1442 if (musb_tx_dma_program(musb->dma_controller, hw_ep, qh, urb, 1478 1443 offset, length)) { 1479 - if (is_cppi_enabled() || tusb_dma_omap()) 1444 + if (is_cppi_enabled(musb) || tusb_dma_omap(musb)) 1480 1445 musb_h_tx_dma_start(hw_ep); 1481 1446 return; 1482 1447 } ··· 1533 1498 MUSB_TXCSR_H_WZC_BITS | MUSB_TXCSR_TXPKTRDY); 1534 1499 } 1535 1500 1501 + #ifdef CONFIG_USB_TI_CPPI41_DMA 1502 + /* Seems to set up ISO for cppi41 and not advance len. See commit c57c41d */ 1503 + static int musb_rx_dma_iso_cppi41(struct dma_controller *dma, 1504 + struct musb_hw_ep *hw_ep, 1505 + struct musb_qh *qh, 1506 + struct urb *urb, 1507 + size_t len) 1508 + { 1509 + struct dma_channel *channel = hw_ep->tx_channel; 1510 + void __iomem *epio = hw_ep->regs; 1511 + dma_addr_t *buf; 1512 + u32 length, res; 1513 + u16 val; 1536 1514 1537 - #ifdef CONFIG_USB_INVENTRA_DMA 1515 + buf = (void *)urb->iso_frame_desc[qh->iso_idx].offset + 1516 + (u32)urb->transfer_dma; 1538 1517 1518 + length = urb->iso_frame_desc[qh->iso_idx].length; 1519 + 1520 + val = musb_readw(epio, MUSB_RXCSR); 1521 + val |= MUSB_RXCSR_DMAENAB; 1522 + musb_writew(hw_ep->regs, MUSB_RXCSR, val); 1523 + 1524 + res = dma->channel_program(channel, qh->maxpacket, 0, 1525 + (u32)buf, length); 1526 + 1527 + return res; 1528 + } 1529 + #else 1530 + static inline int musb_rx_dma_iso_cppi41(struct dma_controller *dma, 1531 + struct musb_hw_ep *hw_ep, 1532 + struct musb_qh *qh, 1533 + struct urb *urb, 1534 + size_t len) 1535 + { 1536 + return false; 1537 + } 1538 + #endif 1539 + 1540 + #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA) || \ 1541 + defined(CONFIG_USB_TI_CPPI41_DMA) 1539 1542 /* Host side RX (IN) using Mentor DMA works as follows: 1540 1543 submit_urb -> 1541 1544 - if queue was empty, ProgramEndpoint ··· 1608 1535 * thus be a great candidate for using mode 1 ... for all but the 1609 1536 * last packet of one URB's transfer. 1610 1537 */ 1538 + static int musb_rx_dma_inventra_cppi41(struct dma_controller *dma, 1539 + struct musb_hw_ep *hw_ep, 1540 + struct musb_qh *qh, 1541 + struct urb *urb, 1542 + size_t len) 1543 + { 1544 + struct dma_channel *channel = hw_ep->rx_channel; 1545 + void __iomem *epio = hw_ep->regs; 1546 + u16 val; 1547 + int pipe; 1548 + bool done; 1611 1549 1550 + pipe = urb->pipe; 1551 + 1552 + if (usb_pipeisoc(pipe)) { 1553 + struct usb_iso_packet_descriptor *d; 1554 + 1555 + d = urb->iso_frame_desc + qh->iso_idx; 1556 + d->actual_length = len; 1557 + 1558 + /* even if there was an error, we did the dma 1559 + * for iso_frame_desc->length 1560 + */ 1561 + if (d->status != -EILSEQ && d->status != -EOVERFLOW) 1562 + d->status = 0; 1563 + 1564 + if (++qh->iso_idx >= urb->number_of_packets) { 1565 + done = true; 1566 + } else { 1567 + /* REVISIT: Why ignore return value here? */ 1568 + if (musb_dma_cppi41(hw_ep->musb)) 1569 + done = musb_rx_dma_iso_cppi41(dma, hw_ep, qh, 1570 + urb, len); 1571 + done = false; 1572 + } 1573 + 1574 + } else { 1575 + /* done if urb buffer is full or short packet is recd */ 1576 + done = (urb->actual_length + len >= 1577 + urb->transfer_buffer_length 1578 + || channel->actual_len < qh->maxpacket 1579 + || channel->rx_packet_done); 1580 + } 1581 + 1582 + /* send IN token for next packet, without AUTOREQ */ 1583 + if (!done) { 1584 + val = musb_readw(epio, MUSB_RXCSR); 1585 + val |= MUSB_RXCSR_H_REQPKT; 1586 + musb_writew(epio, MUSB_RXCSR, MUSB_RXCSR_H_WZC_BITS | val); 1587 + } 1588 + 1589 + return done; 1590 + } 1591 + 1592 + /* Disadvantage of using mode 1: 1593 + * It's basically usable only for mass storage class; essentially all 1594 + * other protocols also terminate transfers on short packets. 1595 + * 1596 + * Details: 1597 + * An extra IN token is sent at the end of the transfer (due to AUTOREQ) 1598 + * If you try to use mode 1 for (transfer_buffer_length - 512), and try 1599 + * to use the extra IN token to grab the last packet using mode 0, then 1600 + * the problem is that you cannot be sure when the device will send the 1601 + * last packet and RxPktRdy set. Sometimes the packet is recd too soon 1602 + * such that it gets lost when RxCSR is re-set at the end of the mode 1 1603 + * transfer, while sometimes it is recd just a little late so that if you 1604 + * try to configure for mode 0 soon after the mode 1 transfer is 1605 + * completed, you will find rxcount 0. Okay, so you might think why not 1606 + * wait for an interrupt when the pkt is recd. Well, you won't get any! 1607 + */ 1608 + static int musb_rx_dma_in_inventra_cppi41(struct dma_controller *dma, 1609 + struct musb_hw_ep *hw_ep, 1610 + struct musb_qh *qh, 1611 + struct urb *urb, 1612 + size_t len, 1613 + u8 iso_err) 1614 + { 1615 + struct musb *musb = hw_ep->musb; 1616 + void __iomem *epio = hw_ep->regs; 1617 + struct dma_channel *channel = hw_ep->rx_channel; 1618 + u16 rx_count, val; 1619 + int length, pipe, done; 1620 + dma_addr_t buf; 1621 + 1622 + rx_count = musb_readw(epio, MUSB_RXCOUNT); 1623 + pipe = urb->pipe; 1624 + 1625 + if (usb_pipeisoc(pipe)) { 1626 + int d_status = 0; 1627 + struct usb_iso_packet_descriptor *d; 1628 + 1629 + d = urb->iso_frame_desc + qh->iso_idx; 1630 + 1631 + if (iso_err) { 1632 + d_status = -EILSEQ; 1633 + urb->error_count++; 1634 + } 1635 + if (rx_count > d->length) { 1636 + if (d_status == 0) { 1637 + d_status = -EOVERFLOW; 1638 + urb->error_count++; 1639 + } 1640 + dev_dbg(musb->controller, "** OVERFLOW %d into %d\n", 1641 + rx_count, d->length); 1642 + 1643 + length = d->length; 1644 + } else 1645 + length = rx_count; 1646 + d->status = d_status; 1647 + buf = urb->transfer_dma + d->offset; 1648 + } else { 1649 + length = rx_count; 1650 + buf = urb->transfer_dma + urb->actual_length; 1651 + } 1652 + 1653 + channel->desired_mode = 0; 1654 + #ifdef USE_MODE1 1655 + /* because of the issue below, mode 1 will 1656 + * only rarely behave with correct semantics. 1657 + */ 1658 + if ((urb->transfer_flags & URB_SHORT_NOT_OK) 1659 + && (urb->transfer_buffer_length - urb->actual_length) 1660 + > qh->maxpacket) 1661 + channel->desired_mode = 1; 1662 + if (rx_count < hw_ep->max_packet_sz_rx) { 1663 + length = rx_count; 1664 + channel->desired_mode = 0; 1665 + } else { 1666 + length = urb->transfer_buffer_length; 1667 + } 1668 + #endif 1669 + 1670 + /* See comments above on disadvantages of using mode 1 */ 1671 + val = musb_readw(epio, MUSB_RXCSR); 1672 + val &= ~MUSB_RXCSR_H_REQPKT; 1673 + 1674 + if (channel->desired_mode == 0) 1675 + val &= ~MUSB_RXCSR_H_AUTOREQ; 1676 + else 1677 + val |= MUSB_RXCSR_H_AUTOREQ; 1678 + val |= MUSB_RXCSR_DMAENAB; 1679 + 1680 + /* autoclear shouldn't be set in high bandwidth */ 1681 + if (qh->hb_mult == 1) 1682 + val |= MUSB_RXCSR_AUTOCLEAR; 1683 + 1684 + musb_writew(epio, MUSB_RXCSR, MUSB_RXCSR_H_WZC_BITS | val); 1685 + 1686 + /* REVISIT if when actual_length != 0, 1687 + * transfer_buffer_length needs to be 1688 + * adjusted first... 1689 + */ 1690 + done = dma->channel_program(channel, qh->maxpacket, 1691 + channel->desired_mode, 1692 + buf, length); 1693 + 1694 + if (!done) { 1695 + dma->channel_release(channel); 1696 + hw_ep->rx_channel = NULL; 1697 + channel = NULL; 1698 + val = musb_readw(epio, MUSB_RXCSR); 1699 + val &= ~(MUSB_RXCSR_DMAENAB 1700 + | MUSB_RXCSR_H_AUTOREQ 1701 + | MUSB_RXCSR_AUTOCLEAR); 1702 + musb_writew(epio, MUSB_RXCSR, val); 1703 + } 1704 + 1705 + return done; 1706 + } 1707 + #else 1708 + static inline int musb_rx_dma_inventra_cppi41(struct dma_controller *dma, 1709 + struct musb_hw_ep *hw_ep, 1710 + struct musb_qh *qh, 1711 + struct urb *urb, 1712 + size_t len) 1713 + { 1714 + return false; 1715 + } 1716 + 1717 + static inline int musb_rx_dma_in_inventra_cppi41(struct dma_controller *dma, 1718 + struct musb_hw_ep *hw_ep, 1719 + struct musb_qh *qh, 1720 + struct urb *urb, 1721 + size_t len, 1722 + u8 iso_err) 1723 + { 1724 + return false; 1725 + } 1612 1726 #endif 1613 1727 1614 1728 /* ··· 1806 1546 { 1807 1547 struct urb *urb; 1808 1548 struct musb_hw_ep *hw_ep = musb->endpoints + epnum; 1549 + struct dma_controller *c = musb->dma_controller; 1809 1550 void __iomem *epio = hw_ep->regs; 1810 1551 struct musb_qh *qh = hw_ep->in_qh; 1811 1552 size_t xfer_len; ··· 1922 1661 */ 1923 1662 1924 1663 /* FIXME this is _way_ too much in-line logic for Mentor DMA */ 1925 - 1926 - #if !defined(CONFIG_USB_INVENTRA_DMA) && !defined(CONFIG_USB_UX500_DMA) 1927 - if (rx_csr & MUSB_RXCSR_H_REQPKT) { 1664 + if (!musb_dma_inventra(musb) && !musb_dma_ux500(musb) && 1665 + (rx_csr & MUSB_RXCSR_H_REQPKT)) { 1928 1666 /* REVISIT this happened for a while on some short reads... 1929 1667 * the cleanup still needs investigation... looks bad... 1930 1668 * and also duplicates dma cleanup code above ... plus, ··· 1944 1684 musb_writew(epio, MUSB_RXCSR, 1945 1685 MUSB_RXCSR_H_WZC_BITS | rx_csr); 1946 1686 } 1947 - #endif 1687 + 1948 1688 if (dma && (rx_csr & MUSB_RXCSR_DMAENAB)) { 1949 1689 xfer_len = dma->actual_len; 1950 1690 ··· 1954 1694 | MUSB_RXCSR_RXPKTRDY); 1955 1695 musb_writew(hw_ep->regs, MUSB_RXCSR, val); 1956 1696 1957 - #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA) || \ 1958 - defined(CONFIG_USB_TI_CPPI41_DMA) 1959 - if (usb_pipeisoc(pipe)) { 1960 - struct usb_iso_packet_descriptor *d; 1961 - 1962 - d = urb->iso_frame_desc + qh->iso_idx; 1963 - d->actual_length = xfer_len; 1964 - 1965 - /* even if there was an error, we did the dma 1966 - * for iso_frame_desc->length 1967 - */ 1968 - if (d->status != -EILSEQ && d->status != -EOVERFLOW) 1969 - d->status = 0; 1970 - 1971 - if (++qh->iso_idx >= urb->number_of_packets) { 1972 - done = true; 1973 - } else { 1974 - #if defined(CONFIG_USB_TI_CPPI41_DMA) 1975 - struct dma_controller *c; 1976 - dma_addr_t *buf; 1977 - u32 length, ret; 1978 - 1979 - c = musb->dma_controller; 1980 - buf = (void *) 1981 - urb->iso_frame_desc[qh->iso_idx].offset 1982 - + (u32)urb->transfer_dma; 1983 - 1984 - length = 1985 - urb->iso_frame_desc[qh->iso_idx].length; 1986 - 1987 - val |= MUSB_RXCSR_DMAENAB; 1988 - musb_writew(hw_ep->regs, MUSB_RXCSR, val); 1989 - 1990 - ret = c->channel_program(dma, qh->maxpacket, 1991 - 0, (u32) buf, length); 1992 - #endif 1993 - done = false; 1994 - } 1995 - 1996 - } else { 1997 - /* done if urb buffer is full or short packet is recd */ 1998 - done = (urb->actual_length + xfer_len >= 1999 - urb->transfer_buffer_length 2000 - || dma->actual_len < qh->maxpacket 2001 - || dma->rx_packet_done); 1697 + if (musb_dma_inventra(musb) || musb_dma_ux500(musb) || 1698 + musb_dma_cppi41(musb)) { 1699 + done = musb_rx_dma_inventra_cppi41(c, hw_ep, qh, urb, xfer_len); 1700 + dev_dbg(hw_ep->musb->controller, 1701 + "ep %d dma %s, rxcsr %04x, rxcount %d\n", 1702 + epnum, done ? "off" : "reset", 1703 + musb_readw(epio, MUSB_RXCSR), 1704 + musb_readw(epio, MUSB_RXCOUNT)); 1705 + } else { 1706 + done = true; 2002 1707 } 2003 1708 2004 - /* send IN token for next packet, without AUTOREQ */ 2005 - if (!done) { 2006 - val |= MUSB_RXCSR_H_REQPKT; 2007 - musb_writew(epio, MUSB_RXCSR, 2008 - MUSB_RXCSR_H_WZC_BITS | val); 2009 - } 2010 - 2011 - dev_dbg(musb->controller, "ep %d dma %s, rxcsr %04x, rxcount %d\n", epnum, 2012 - done ? "off" : "reset", 2013 - musb_readw(epio, MUSB_RXCSR), 2014 - musb_readw(epio, MUSB_RXCOUNT)); 2015 - #else 2016 - done = true; 2017 - #endif 2018 1709 } else if (urb->status == -EINPROGRESS) { 2019 1710 /* if no errors, be sure a packet is ready for unloading */ 2020 1711 if (unlikely(!(rx_csr & MUSB_RXCSR_RXPKTRDY))) { ··· 1983 1772 } 1984 1773 1985 1774 /* we are expecting IN packets */ 1986 - #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA) || \ 1987 - defined(CONFIG_USB_TI_CPPI41_DMA) 1988 - if (dma) { 1989 - struct dma_controller *c; 1990 - u16 rx_count; 1991 - int ret, length; 1992 - dma_addr_t buf; 1775 + if ((musb_dma_inventra(musb) || musb_dma_ux500(musb) || 1776 + musb_dma_cppi41(musb)) && dma) { 1777 + dev_dbg(hw_ep->musb->controller, 1778 + "RX%d count %d, buffer 0x%llx len %d/%d\n", 1779 + epnum, musb_readw(epio, MUSB_RXCOUNT), 1780 + (unsigned long long) urb->transfer_dma 1781 + + urb->actual_length, 1782 + qh->offset, 1783 + urb->transfer_buffer_length); 1993 1784 1994 - rx_count = musb_readw(epio, MUSB_RXCOUNT); 1995 - 1996 - dev_dbg(musb->controller, "RX%d count %d, buffer 0x%llx len %d/%d\n", 1997 - epnum, rx_count, 1998 - (unsigned long long) urb->transfer_dma 1999 - + urb->actual_length, 2000 - qh->offset, 2001 - urb->transfer_buffer_length); 2002 - 2003 - c = musb->dma_controller; 2004 - 2005 - if (usb_pipeisoc(pipe)) { 2006 - int d_status = 0; 2007 - struct usb_iso_packet_descriptor *d; 2008 - 2009 - d = urb->iso_frame_desc + qh->iso_idx; 2010 - 2011 - if (iso_err) { 2012 - d_status = -EILSEQ; 2013 - urb->error_count++; 2014 - } 2015 - if (rx_count > d->length) { 2016 - if (d_status == 0) { 2017 - d_status = -EOVERFLOW; 2018 - urb->error_count++; 2019 - } 2020 - dev_dbg(musb->controller, "** OVERFLOW %d into %d\n",\ 2021 - rx_count, d->length); 2022 - 2023 - length = d->length; 2024 - } else 2025 - length = rx_count; 2026 - d->status = d_status; 2027 - buf = urb->transfer_dma + d->offset; 2028 - } else { 2029 - length = rx_count; 2030 - buf = urb->transfer_dma + 2031 - urb->actual_length; 2032 - } 2033 - 2034 - dma->desired_mode = 0; 2035 - #ifdef USE_MODE1 2036 - /* because of the issue below, mode 1 will 2037 - * only rarely behave with correct semantics. 2038 - */ 2039 - if ((urb->transfer_flags & 2040 - URB_SHORT_NOT_OK) 2041 - && (urb->transfer_buffer_length - 2042 - urb->actual_length) 2043 - > qh->maxpacket) 2044 - dma->desired_mode = 1; 2045 - if (rx_count < hw_ep->max_packet_sz_rx) { 2046 - length = rx_count; 2047 - dma->desired_mode = 0; 2048 - } else { 2049 - length = urb->transfer_buffer_length; 2050 - } 2051 - #endif 2052 - 2053 - /* Disadvantage of using mode 1: 2054 - * It's basically usable only for mass storage class; essentially all 2055 - * other protocols also terminate transfers on short packets. 2056 - * 2057 - * Details: 2058 - * An extra IN token is sent at the end of the transfer (due to AUTOREQ) 2059 - * If you try to use mode 1 for (transfer_buffer_length - 512), and try 2060 - * to use the extra IN token to grab the last packet using mode 0, then 2061 - * the problem is that you cannot be sure when the device will send the 2062 - * last packet and RxPktRdy set. Sometimes the packet is recd too soon 2063 - * such that it gets lost when RxCSR is re-set at the end of the mode 1 2064 - * transfer, while sometimes it is recd just a little late so that if you 2065 - * try to configure for mode 0 soon after the mode 1 transfer is 2066 - * completed, you will find rxcount 0. Okay, so you might think why not 2067 - * wait for an interrupt when the pkt is recd. Well, you won't get any! 2068 - */ 2069 - 2070 - val = musb_readw(epio, MUSB_RXCSR); 2071 - val &= ~MUSB_RXCSR_H_REQPKT; 2072 - 2073 - if (dma->desired_mode == 0) 2074 - val &= ~MUSB_RXCSR_H_AUTOREQ; 1785 + done = musb_rx_dma_in_inventra_cppi41(c, hw_ep, qh, 1786 + urb, xfer_len, 1787 + iso_err); 1788 + if (done) 1789 + goto finish; 2075 1790 else 2076 - val |= MUSB_RXCSR_H_AUTOREQ; 2077 - val |= MUSB_RXCSR_DMAENAB; 2078 - 2079 - /* autoclear shouldn't be set in high bandwidth */ 2080 - if (qh->hb_mult == 1) 2081 - val |= MUSB_RXCSR_AUTOCLEAR; 2082 - 2083 - musb_writew(epio, MUSB_RXCSR, 2084 - MUSB_RXCSR_H_WZC_BITS | val); 2085 - 2086 - /* REVISIT if when actual_length != 0, 2087 - * transfer_buffer_length needs to be 2088 - * adjusted first... 2089 - */ 2090 - ret = c->channel_program( 2091 - dma, qh->maxpacket, 2092 - dma->desired_mode, buf, length); 2093 - 2094 - if (!ret) { 2095 - c->channel_release(dma); 2096 - hw_ep->rx_channel = NULL; 2097 - dma = NULL; 2098 - val = musb_readw(epio, MUSB_RXCSR); 2099 - val &= ~(MUSB_RXCSR_DMAENAB 2100 - | MUSB_RXCSR_H_AUTOREQ 2101 - | MUSB_RXCSR_AUTOCLEAR); 2102 - musb_writew(epio, MUSB_RXCSR, val); 2103 - } 1791 + dev_err(musb->controller, "error: rx_dma failed\n"); 2104 1792 } 2105 - #endif /* Mentor DMA */ 2106 1793 2107 1794 if (!dma) { 2108 1795 unsigned int received_len;
+2
drivers/usb/musb/musb_io.h
··· 47 47 * @fifo_offset: platform specific function to get fifo offset 48 48 * @read_fifo: platform specific function to read fifo 49 49 * @write_fifo: platform specific function to write fifo 50 + * @busctl_offset: platform specific function to get busctl offset 50 51 */ 51 52 struct musb_io { 52 53 u32 quirks; ··· 56 55 u32 (*fifo_offset)(u8 epnum); 57 56 void (*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf); 58 57 void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf); 58 + u32 (*busctl_offset)(u8 epnum, u16 offset); 59 59 }; 60 60 61 61 /* Do not add new entries here, add them the struct musb_io instead */
+52 -54
drivers/usb/musb/musb_regs.h
··· 300 300 #define MUSB_RXHUBADDR 0x06 301 301 #define MUSB_RXHUBPORT 0x07 302 302 303 - #define MUSB_BUSCTL_OFFSET(_epnum, _offset) \ 304 - (0x80 + (8*(_epnum)) + (_offset)) 305 - 306 303 static inline void musb_write_txfifosz(void __iomem *mbase, u8 c_size) 307 304 { 308 305 musb_writeb(mbase, MUSB_TXFIFOSZ, c_size); ··· 361 364 return musb_readw(mbase, MUSB_HWVERS); 362 365 } 363 366 364 - static inline void __iomem *musb_read_target_reg_base(u8 i, void __iomem *mbase) 365 - { 366 - return (MUSB_BUSCTL_OFFSET(i, 0) + mbase); 367 - } 368 - 369 - static inline void musb_write_rxfunaddr(void __iomem *ep_target_regs, 367 + static inline void musb_write_rxfunaddr(struct musb *musb, u8 epnum, 370 368 u8 qh_addr_reg) 371 369 { 372 - musb_writeb(ep_target_regs, MUSB_RXFUNCADDR, qh_addr_reg); 370 + musb_writeb(musb->mregs, 371 + musb->io.busctl_offset(epnum, MUSB_RXFUNCADDR), 372 + qh_addr_reg); 373 373 } 374 374 375 - static inline void musb_write_rxhubaddr(void __iomem *ep_target_regs, 375 + static inline void musb_write_rxhubaddr(struct musb *musb, u8 epnum, 376 376 u8 qh_h_addr_reg) 377 377 { 378 - musb_writeb(ep_target_regs, MUSB_RXHUBADDR, qh_h_addr_reg); 378 + musb_writeb(musb->mregs, musb->io.busctl_offset(epnum, MUSB_RXHUBADDR), 379 + qh_h_addr_reg); 379 380 } 380 381 381 - static inline void musb_write_rxhubport(void __iomem *ep_target_regs, 382 + static inline void musb_write_rxhubport(struct musb *musb, u8 epnum, 382 383 u8 qh_h_port_reg) 383 384 { 384 - musb_writeb(ep_target_regs, MUSB_RXHUBPORT, qh_h_port_reg); 385 - } 386 - 387 - static inline void musb_write_txfunaddr(void __iomem *mbase, u8 epnum, 388 - u8 qh_addr_reg) 389 - { 390 - musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXFUNCADDR), 391 - qh_addr_reg); 392 - } 393 - 394 - static inline void musb_write_txhubaddr(void __iomem *mbase, u8 epnum, 395 - u8 qh_addr_reg) 396 - { 397 - musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBADDR), 398 - qh_addr_reg); 399 - } 400 - 401 - static inline void musb_write_txhubport(void __iomem *mbase, u8 epnum, 402 - u8 qh_h_port_reg) 403 - { 404 - musb_writeb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBPORT), 385 + musb_writeb(musb->mregs, musb->io.busctl_offset(epnum, MUSB_RXHUBPORT), 405 386 qh_h_port_reg); 406 387 } 407 388 408 - static inline u8 musb_read_rxfunaddr(void __iomem *mbase, u8 epnum) 389 + static inline void musb_write_txfunaddr(struct musb *musb, u8 epnum, 390 + u8 qh_addr_reg) 409 391 { 410 - return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXFUNCADDR)); 392 + musb_writeb(musb->mregs, 393 + musb->io.busctl_offset(epnum, MUSB_TXFUNCADDR), 394 + qh_addr_reg); 411 395 } 412 396 413 - static inline u8 musb_read_rxhubaddr(void __iomem *mbase, u8 epnum) 397 + static inline void musb_write_txhubaddr(struct musb *musb, u8 epnum, 398 + u8 qh_addr_reg) 414 399 { 415 - return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBADDR)); 400 + musb_writeb(musb->mregs, musb->io.busctl_offset(epnum, MUSB_TXHUBADDR), 401 + qh_addr_reg); 416 402 } 417 403 418 - static inline u8 musb_read_rxhubport(void __iomem *mbase, u8 epnum) 404 + static inline void musb_write_txhubport(struct musb *musb, u8 epnum, 405 + u8 qh_h_port_reg) 419 406 { 420 - return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBPORT)); 407 + musb_writeb(musb->mregs, musb->io.busctl_offset(epnum, MUSB_TXHUBPORT), 408 + qh_h_port_reg); 421 409 } 422 410 423 - static inline u8 musb_read_txfunaddr(void __iomem *mbase, u8 epnum) 411 + static inline u8 musb_read_rxfunaddr(struct musb *musb, u8 epnum) 424 412 { 425 - return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXFUNCADDR)); 413 + return musb_readb(musb->mregs, 414 + musb->io.busctl_offset(epnum, MUSB_RXFUNCADDR)); 426 415 } 427 416 428 - static inline u8 musb_read_txhubaddr(void __iomem *mbase, u8 epnum) 417 + static inline u8 musb_read_rxhubaddr(struct musb *musb, u8 epnum) 429 418 { 430 - return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBADDR)); 419 + return musb_readb(musb->mregs, 420 + musb->io.busctl_offset(epnum, MUSB_RXHUBADDR)); 431 421 } 432 422 433 - static inline u8 musb_read_txhubport(void __iomem *mbase, u8 epnum) 423 + static inline u8 musb_read_rxhubport(struct musb *musb, u8 epnum) 434 424 { 435 - return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBPORT)); 425 + return musb_readb(musb->mregs, 426 + musb->io.busctl_offset(epnum, MUSB_RXHUBPORT)); 427 + } 428 + 429 + static inline u8 musb_read_txfunaddr(struct musb *musb, u8 epnum) 430 + { 431 + return musb_readb(musb->mregs, 432 + musb->io.busctl_offset(epnum, MUSB_TXFUNCADDR)); 433 + } 434 + 435 + static inline u8 musb_read_txhubaddr(struct musb *musb, u8 epnum) 436 + { 437 + return musb_readb(musb->mregs, 438 + musb->io.busctl_offset(epnum, MUSB_TXHUBADDR)); 439 + } 440 + 441 + static inline u8 musb_read_txhubport(struct musb *musb, u8 epnum) 442 + { 443 + return musb_readb(musb->mregs, 444 + musb->io.busctl_offset(epnum, MUSB_TXHUBPORT)); 436 445 } 437 446 438 447 #else /* CONFIG_BLACKFIN */ ··· 559 556 return MUSB_HWVERS_1900; 560 557 } 561 558 562 - static inline void __iomem *musb_read_target_reg_base(u8 i, void __iomem *mbase) 563 - { 564 - return NULL; 565 - } 566 - 567 - static inline void musb_write_rxfunaddr(void __iomem *ep_target_regs, 559 + static inline void musb_write_rxfunaddr(void __iomem *mbase, u8 epnum, 568 560 u8 qh_addr_req) 569 561 { 570 562 } 571 563 572 - static inline void musb_write_rxhubaddr(void __iomem *ep_target_regs, 564 + static inline void musb_write_rxhubaddr(void __iomem *mbase, u8 epnum, 573 565 u8 qh_h_addr_reg) 574 566 { 575 567 } 576 568 577 - static inline void musb_write_rxhubport(void __iomem *ep_target_regs, 569 + static inline void musb_write_rxhubport(void __iomem *mbase, u8 epnum, 578 570 u8 qh_h_port_reg) 579 571 { 580 572 }
+2
drivers/usb/musb/musb_virthub.c
··· 195 195 msecs_to_jiffies(50)); 196 196 } else { 197 197 dev_dbg(musb->controller, "root port reset stopped\n"); 198 + musb_platform_pre_root_reset_end(musb); 198 199 musb_writeb(mbase, MUSB_POWER, 199 200 power & ~MUSB_POWER_RESET); 201 + musb_platform_post_root_reset_end(musb); 200 202 201 203 power = musb_readb(mbase, MUSB_POWER); 202 204 if (power & MUSB_POWER_HSMODE) {
+6 -3
drivers/usb/musb/musbhsdma.c
··· 357 357 return retval; 358 358 } 359 359 360 - void dma_controller_destroy(struct dma_controller *c) 360 + void musbhs_dma_controller_destroy(struct dma_controller *c) 361 361 { 362 362 struct musb_dma_controller *controller = container_of(c, 363 363 struct musb_dma_controller, controller); ··· 369 369 370 370 kfree(controller); 371 371 } 372 + EXPORT_SYMBOL_GPL(musbhs_dma_controller_destroy); 372 373 373 - struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *base) 374 + struct dma_controller *musbhs_dma_controller_create(struct musb *musb, 375 + void __iomem *base) 374 376 { 375 377 struct musb_dma_controller *controller; 376 378 struct device *dev = musb->controller; ··· 400 398 if (request_irq(irq, dma_controller_irq, 0, 401 399 dev_name(musb->controller), &controller->controller)) { 402 400 dev_err(dev, "request_irq %d failed!\n", irq); 403 - dma_controller_destroy(&controller->controller); 401 + musb_dma_controller_destroy(&controller->controller); 404 402 405 403 return NULL; 406 404 } ··· 409 407 410 408 return &controller->controller; 411 409 } 410 + EXPORT_SYMBOL_GPL(musbhs_dma_controller_create);
+5
drivers/usb/musb/omap2430.c
··· 493 493 } 494 494 495 495 static const struct musb_platform_ops omap2430_ops = { 496 + .quirks = MUSB_DMA_INVENTRA, 497 + #ifdef CONFIG_USB_INVENTRA_DMA 498 + .dma_init = musbhs_dma_controller_create, 499 + .dma_exit = musbhs_dma_controller_destroy, 500 + #endif 496 501 .init = omap2430_musb_init, 497 502 .exit = omap2430_musb_exit, 498 503
+6 -2
drivers/usb/musb/tusb6010.c
··· 890 890 891 891 dev_dbg(musb->controller, "DMA IRQ %08x\n", dma_src); 892 892 real_dma_src = ~real_dma_src & dma_src; 893 - if (tusb_dma_omap() && real_dma_src) { 893 + if (tusb_dma_omap(musb) && real_dma_src) { 894 894 int tx_source = (real_dma_src & 0xffff); 895 895 int i; 896 896 ··· 1181 1181 } 1182 1182 1183 1183 static const struct musb_platform_ops tusb_ops = { 1184 - .quirks = MUSB_IN_TUSB, 1184 + .quirks = MUSB_DMA_TUSB_OMAP | MUSB_IN_TUSB, 1185 1185 .init = tusb_musb_init, 1186 1186 .exit = tusb_musb_exit, 1187 1187 ··· 1192 1192 .writeb = tusb_writeb, 1193 1193 .read_fifo = tusb_read_fifo, 1194 1194 .write_fifo = tusb_write_fifo, 1195 + #ifdef CONFIG_USB_TUSB_OMAP_DMA 1196 + .dma_init = tusb_dma_controller_create, 1197 + .dma_exit = tusb_dma_controller_destroy, 1198 + #endif 1195 1199 .enable = tusb_musb_enable, 1196 1200 .disable = tusb_musb_disable, 1197 1201
-6
drivers/usb/musb/tusb6010.h
··· 12 12 #ifndef __TUSB6010_H__ 13 13 #define __TUSB6010_H__ 14 14 15 - #ifdef CONFIG_USB_TUSB_OMAP_DMA 16 - #define tusb_dma_omap() 1 17 - #else 18 - #define tusb_dma_omap() 0 19 - #endif 20 - 21 15 /* VLYNQ control register. 32-bit at offset 0x000 */ 22 16 #define TUSB_VLYNQ_CTRL 0x004 23 17
+6 -3
drivers/usb/musb/tusb6010_omap.c
··· 625 625 channel = NULL; 626 626 } 627 627 628 - void dma_controller_destroy(struct dma_controller *c) 628 + void tusb_dma_controller_destroy(struct dma_controller *c) 629 629 { 630 630 struct tusb_omap_dma *tusb_dma; 631 631 int i; ··· 644 644 645 645 kfree(tusb_dma); 646 646 } 647 + EXPORT_SYMBOL_GPL(tusb_dma_controller_destroy); 647 648 648 - struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *base) 649 + struct dma_controller * 650 + tusb_dma_controller_create(struct musb *musb, void __iomem *base) 649 651 { 650 652 void __iomem *tbase = musb->ctrl_base; 651 653 struct tusb_omap_dma *tusb_dma; ··· 703 701 return &tusb_dma->controller; 704 702 705 703 cleanup: 706 - dma_controller_destroy(&tusb_dma->controller); 704 + musb_dma_controller_destroy(&tusb_dma->controller); 707 705 out: 708 706 return NULL; 709 707 } 708 + EXPORT_SYMBOL_GPL(tusb_dma_controller_create);
+6 -2
drivers/usb/musb/ux500.c
··· 188 188 } 189 189 190 190 static const struct musb_platform_ops ux500_ops = { 191 - .quirks = MUSB_INDEXED_EP, 191 + .quirks = MUSB_DMA_UX500 | MUSB_INDEXED_EP, 192 + #ifdef CONFIG_USB_UX500_DMA 193 + .dma_init = ux500_dma_controller_create, 194 + .dma_exit = ux500_dma_controller_destroy, 195 + #endif 192 196 .init = ux500_musb_init, 193 197 .exit = ux500_musb_exit, 194 198 .fifo_mode = 5, ··· 342 338 return 0; 343 339 } 344 340 345 - #ifdef CONFIG_PM 341 + #ifdef CONFIG_PM_SLEEP 346 342 static int ux500_suspend(struct device *dev) 347 343 { 348 344 struct ux500_glue *glue = dev_get_drvdata(dev);
+5 -3
drivers/usb/musb/ux500_dma.c
··· 359 359 return 0; 360 360 } 361 361 362 - void dma_controller_destroy(struct dma_controller *c) 362 + void ux500_dma_controller_destroy(struct dma_controller *c) 363 363 { 364 364 struct ux500_dma_controller *controller = container_of(c, 365 365 struct ux500_dma_controller, controller); ··· 367 367 ux500_dma_controller_stop(controller); 368 368 kfree(controller); 369 369 } 370 + EXPORT_SYMBOL_GPL(ux500_dma_controller_destroy); 370 371 371 - struct dma_controller *dma_controller_create(struct musb *musb, 372 - void __iomem *base) 372 + struct dma_controller * 373 + ux500_dma_controller_create(struct musb *musb, void __iomem *base) 373 374 { 374 375 struct ux500_dma_controller *controller; 375 376 struct platform_device *pdev = to_platform_device(musb->controller); ··· 408 407 kzalloc_fail: 409 408 return NULL; 410 409 } 410 + EXPORT_SYMBOL_GPL(ux500_dma_controller_create);
+2 -1
drivers/usb/phy/Kconfig
··· 91 91 92 92 config USB_GPIO_VBUS 93 93 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'" 94 - depends on GPIOLIB 94 + depends on GPIOLIB || COMPILE_TEST 95 95 select USB_PHY 96 96 help 97 97 Provides simple GPIO VBUS sensing for controllers with an ··· 141 141 tristate "Qualcomm on-chip USB OTG controller support" 142 142 depends on (USB || USB_GADGET) && (ARCH_QCOM || COMPILE_TEST) 143 143 depends on RESET_CONTROLLER 144 + depends on EXTCON 144 145 select USB_PHY 145 146 help 146 147 Enable this to support the USB OTG transceiver on Qualcomm chips. It
+110
drivers/usb/phy/phy-msm-usb.c
··· 240 240 static int msm_phy_notify_disconnect(struct usb_phy *phy, 241 241 enum usb_device_speed speed) 242 242 { 243 + struct msm_otg *motg = container_of(phy, struct msm_otg, phy); 243 244 int val; 245 + 246 + if (motg->manual_pullup) { 247 + val = ULPI_MISC_A_VBUSVLDEXT | ULPI_MISC_A_VBUSVLDEXTSEL; 248 + usb_phy_io_write(phy, val, ULPI_CLR(ULPI_MISC_A)); 249 + } 244 250 245 251 /* 246 252 * Put the transceiver in non-driving mode. Otherwise host ··· 426 420 writel(val, USB_OTGSC); 427 421 ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_RISE); 428 422 ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_FALL); 423 + } 424 + 425 + if (motg->manual_pullup) { 426 + val = ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT; 427 + ulpi_write(phy, val, ULPI_SET(ULPI_MISC_A)); 428 + 429 + val = readl(USB_GENCONFIG_2); 430 + val |= GENCONFIG_2_SESS_VLD_CTRL_EN; 431 + writel(val, USB_GENCONFIG_2); 432 + 433 + val = readl(USB_USBCMD); 434 + val |= USBCMD_SESS_VLD_CTRL; 435 + writel(val, USB_USBCMD); 436 + 437 + val = ulpi_read(phy, ULPI_FUNC_CTRL); 438 + val &= ~ULPI_FUNC_CTRL_OPMODE_MASK; 439 + val |= ULPI_FUNC_CTRL_OPMODE_NORMAL; 440 + ulpi_write(phy, val, ULPI_FUNC_CTRL); 429 441 } 430 442 431 443 if (motg->phy_number) ··· 1460 1436 }; 1461 1437 MODULE_DEVICE_TABLE(of, msm_otg_dt_match); 1462 1438 1439 + static int msm_otg_vbus_notifier(struct notifier_block *nb, unsigned long event, 1440 + void *ptr) 1441 + { 1442 + struct msm_usb_cable *vbus = container_of(nb, struct msm_usb_cable, nb); 1443 + struct msm_otg *motg = container_of(vbus, struct msm_otg, vbus); 1444 + 1445 + if (event) 1446 + set_bit(B_SESS_VLD, &motg->inputs); 1447 + else 1448 + clear_bit(B_SESS_VLD, &motg->inputs); 1449 + 1450 + schedule_work(&motg->sm_work); 1451 + 1452 + return NOTIFY_DONE; 1453 + } 1454 + 1455 + static int msm_otg_id_notifier(struct notifier_block *nb, unsigned long event, 1456 + void *ptr) 1457 + { 1458 + struct msm_usb_cable *id = container_of(nb, struct msm_usb_cable, nb); 1459 + struct msm_otg *motg = container_of(id, struct msm_otg, id); 1460 + 1461 + if (event) 1462 + clear_bit(ID, &motg->inputs); 1463 + else 1464 + set_bit(ID, &motg->inputs); 1465 + 1466 + schedule_work(&motg->sm_work); 1467 + 1468 + return NOTIFY_DONE; 1469 + } 1470 + 1463 1471 static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) 1464 1472 { 1465 1473 struct msm_otg_platform_data *pdata; 1474 + struct extcon_dev *ext_id, *ext_vbus; 1466 1475 const struct of_device_id *id; 1467 1476 struct device_node *node = pdev->dev.of_node; 1468 1477 struct property *prop; ··· 1542 1485 motg->vdd_levels[VDD_LEVEL_NONE] = tmp[VDD_LEVEL_NONE]; 1543 1486 motg->vdd_levels[VDD_LEVEL_MIN] = tmp[VDD_LEVEL_MIN]; 1544 1487 motg->vdd_levels[VDD_LEVEL_MAX] = tmp[VDD_LEVEL_MAX]; 1488 + } 1489 + 1490 + motg->manual_pullup = of_property_read_bool(node, "qcom,manual-pullup"); 1491 + 1492 + ext_id = ERR_PTR(-ENODEV); 1493 + ext_vbus = ERR_PTR(-ENODEV); 1494 + if (of_property_read_bool(node, "extcon")) { 1495 + 1496 + /* Each one of them is not mandatory */ 1497 + ext_vbus = extcon_get_edev_by_phandle(&pdev->dev, 0); 1498 + if (IS_ERR(ext_vbus) && PTR_ERR(ext_vbus) != -ENODEV) 1499 + return PTR_ERR(ext_vbus); 1500 + 1501 + ext_id = extcon_get_edev_by_phandle(&pdev->dev, 1); 1502 + if (IS_ERR(ext_id) && PTR_ERR(ext_id) != -ENODEV) 1503 + return PTR_ERR(ext_id); 1504 + } 1505 + 1506 + if (!IS_ERR(ext_vbus)) { 1507 + motg->vbus.nb.notifier_call = msm_otg_vbus_notifier; 1508 + ret = extcon_register_interest(&motg->vbus.conn, ext_vbus->name, 1509 + "USB", &motg->vbus.nb); 1510 + if (ret < 0) { 1511 + dev_err(&pdev->dev, "register VBUS notifier failed\n"); 1512 + return ret; 1513 + } 1514 + 1515 + ret = extcon_get_cable_state(ext_vbus, "USB"); 1516 + if (ret) 1517 + set_bit(B_SESS_VLD, &motg->inputs); 1518 + else 1519 + clear_bit(B_SESS_VLD, &motg->inputs); 1520 + } 1521 + 1522 + if (!IS_ERR(ext_id)) { 1523 + motg->id.nb.notifier_call = msm_otg_id_notifier; 1524 + ret = extcon_register_interest(&motg->id.conn, ext_id->name, 1525 + "USB-HOST", &motg->id.nb); 1526 + if (ret < 0) { 1527 + dev_err(&pdev->dev, "register ID notifier failed\n"); 1528 + return ret; 1529 + } 1530 + 1531 + ret = extcon_get_cable_state(ext_id, "USB-HOST"); 1532 + if (ret) 1533 + clear_bit(ID, &motg->inputs); 1534 + else 1535 + set_bit(ID, &motg->inputs); 1545 1536 } 1546 1537 1547 1538 prop = of_find_property(node, "qcom,phy-init-sequence", &len); ··· 1804 1699 1805 1700 if (phy->otg->host || phy->otg->gadget) 1806 1701 return -EBUSY; 1702 + 1703 + if (motg->id.conn.edev) 1704 + extcon_unregister_interest(&motg->id.conn); 1705 + if (motg->vbus.conn.edev) 1706 + extcon_unregister_interest(&motg->vbus.conn); 1807 1707 1808 1708 msm_otg_debugfs_cleanup(); 1809 1709 cancel_delayed_work_sync(&motg->chg_work);
+70 -27
drivers/usb/phy/phy.c
··· 22 22 static LIST_HEAD(phy_bind_list); 23 23 static DEFINE_SPINLOCK(phy_lock); 24 24 25 + struct phy_devm { 26 + struct usb_phy *phy; 27 + struct notifier_block *nb; 28 + }; 29 + 25 30 static struct usb_phy *__usb_find_phy(struct list_head *list, 26 31 enum usb_phy_type type) 27 32 { ··· 82 77 struct usb_phy *phy = *(struct usb_phy **)res; 83 78 84 79 usb_put_phy(phy); 80 + } 81 + 82 + static void devm_usb_phy_release2(struct device *dev, void *_res) 83 + { 84 + struct phy_devm *res = _res; 85 + 86 + if (res->nb) 87 + usb_unregister_notifier(res->phy, res->nb); 88 + usb_put_phy(res->phy); 85 89 } 86 90 87 91 static int devm_usb_phy_match(struct device *dev, void *res, void *match_data) ··· 167 153 EXPORT_SYMBOL_GPL(usb_get_phy); 168 154 169 155 /** 170 - * devm_usb_get_phy_by_phandle - find the USB PHY by phandle 156 + * devm_usb_get_phy_by_node - find the USB PHY by device_node 171 157 * @dev - device that requests this phy 172 - * @phandle - name of the property holding the phy phandle value 173 - * @index - the index of the phy 158 + * @node - the device_node for the phy device. 159 + * @nb - a notifier_block to register with the phy. 174 160 * 175 - * Returns the phy driver associated with the given phandle value, 161 + * Returns the phy driver associated with the given device_node, 176 162 * after getting a refcount to it, -ENODEV if there is no such phy or 177 - * -EPROBE_DEFER if there is a phandle to the phy, but the device is 178 - * not yet loaded. While at that, it also associates the device with 163 + * -EPROBE_DEFER if the device is not yet loaded. While at that, it 164 + * also associates the device with 179 165 * the phy using devres. On driver detach, release function is invoked 180 166 * on the devres data, then, devres data is freed. 181 167 * 182 - * For use by USB host and peripheral drivers. 168 + * For use by peripheral drivers for devices related to a phy, 169 + * such as a charger. 183 170 */ 184 - struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev, 185 - const char *phandle, u8 index) 171 + struct usb_phy *devm_usb_get_phy_by_node(struct device *dev, 172 + struct device_node *node, 173 + struct notifier_block *nb) 186 174 { 187 - struct usb_phy *phy = ERR_PTR(-ENOMEM), **ptr; 175 + struct usb_phy *phy = ERR_PTR(-ENOMEM); 176 + struct phy_devm *ptr; 188 177 unsigned long flags; 189 - struct device_node *node; 190 178 191 - if (!dev->of_node) { 192 - dev_dbg(dev, "device does not have a device node entry\n"); 193 - return ERR_PTR(-EINVAL); 194 - } 195 - 196 - node = of_parse_phandle(dev->of_node, phandle, index); 197 - if (!node) { 198 - dev_dbg(dev, "failed to get %s phandle in %s node\n", phandle, 199 - dev->of_node->full_name); 200 - return ERR_PTR(-ENODEV); 201 - } 202 - 203 - ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL); 179 + ptr = devres_alloc(devm_usb_phy_release2, sizeof(*ptr), GFP_KERNEL); 204 180 if (!ptr) { 205 181 dev_dbg(dev, "failed to allocate memory for devres\n"); 206 182 goto err0; ··· 209 205 devres_free(ptr); 210 206 goto err1; 211 207 } 212 - 213 - *ptr = phy; 208 + if (nb) 209 + usb_register_notifier(phy, nb); 210 + ptr->phy = phy; 211 + ptr->nb = nb; 214 212 devres_add(dev, ptr); 215 213 216 214 get_device(phy->dev); ··· 221 215 spin_unlock_irqrestore(&phy_lock, flags); 222 216 223 217 err0: 224 - of_node_put(node); 225 218 219 + return phy; 220 + } 221 + EXPORT_SYMBOL_GPL(devm_usb_get_phy_by_node); 222 + 223 + /** 224 + * devm_usb_get_phy_by_phandle - find the USB PHY by phandle 225 + * @dev - device that requests this phy 226 + * @phandle - name of the property holding the phy phandle value 227 + * @index - the index of the phy 228 + * 229 + * Returns the phy driver associated with the given phandle value, 230 + * after getting a refcount to it, -ENODEV if there is no such phy or 231 + * -EPROBE_DEFER if there is a phandle to the phy, but the device is 232 + * not yet loaded. While at that, it also associates the device with 233 + * the phy using devres. On driver detach, release function is invoked 234 + * on the devres data, then, devres data is freed. 235 + * 236 + * For use by USB host and peripheral drivers. 237 + */ 238 + struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev, 239 + const char *phandle, u8 index) 240 + { 241 + struct device_node *node; 242 + struct usb_phy *phy; 243 + 244 + if (!dev->of_node) { 245 + dev_dbg(dev, "device does not have a device node entry\n"); 246 + return ERR_PTR(-EINVAL); 247 + } 248 + 249 + node = of_parse_phandle(dev->of_node, phandle, index); 250 + if (!node) { 251 + dev_dbg(dev, "failed to get %s phandle in %s node\n", phandle, 252 + dev->of_node->full_name); 253 + return ERR_PTR(-ENODEV); 254 + } 255 + phy = devm_usb_get_phy_by_node(dev, node, NULL); 256 + of_node_put(node); 226 257 return phy; 227 258 } 228 259 EXPORT_SYMBOL_GPL(devm_usb_get_phy_by_phandle);
+8 -11
drivers/usb/renesas_usbhs/common.c
··· 466 466 static const struct of_device_id usbhs_of_match[] = { 467 467 { 468 468 .compatible = "renesas,usbhs-r8a7790", 469 - .data = (void *)USBHS_TYPE_R8A7790, 469 + .data = (void *)USBHS_TYPE_RCAR_GEN2, 470 470 }, 471 471 { 472 472 .compatible = "renesas,usbhs-r8a7791", 473 - .data = (void *)USBHS_TYPE_R8A7791, 473 + .data = (void *)USBHS_TYPE_RCAR_GEN2, 474 + }, 475 + { 476 + .compatible = "renesas,usbhs-r8a7794", 477 + .data = (void *)USBHS_TYPE_RCAR_GEN2, 474 478 }, 475 479 { }, 476 480 }; ··· 501 497 if (gpio > 0) 502 498 dparam->enable_gpio = gpio; 503 499 504 - switch (dparam->type) { 505 - case USBHS_TYPE_R8A7790: 506 - case USBHS_TYPE_R8A7791: 500 + if (dparam->type == USBHS_TYPE_RCAR_GEN2) 507 501 dparam->has_usb_dmac = 1; 508 - break; 509 - default: 510 - break; 511 - } 512 502 513 503 return info; 514 504 } ··· 557 559 sizeof(struct renesas_usbhs_driver_param)); 558 560 559 561 switch (priv->dparam.type) { 560 - case USBHS_TYPE_R8A7790: 561 - case USBHS_TYPE_R8A7791: 562 + case USBHS_TYPE_RCAR_GEN2: 562 563 priv->pfunc = usbhs_rcar2_ops; 563 564 if (!priv->dparam.pipe_type) { 564 565 priv->dparam.pipe_type = usbhsc_new_pipe_type;
+15 -9
drivers/usb/renesas_usbhs/fifo.c
··· 1239 1239 { 1240 1240 char name[16]; 1241 1241 1242 - snprintf(name, sizeof(name), "tx%d", channel); 1243 - fifo->tx_chan = dma_request_slave_channel_reason(dev, name); 1244 - if (IS_ERR(fifo->tx_chan)) 1245 - fifo->tx_chan = NULL; 1246 - 1247 - snprintf(name, sizeof(name), "rx%d", channel); 1248 - fifo->rx_chan = dma_request_slave_channel_reason(dev, name); 1249 - if (IS_ERR(fifo->rx_chan)) 1250 - fifo->rx_chan = NULL; 1242 + /* 1243 + * To avoid complex handing for DnFIFOs, the driver uses each 1244 + * DnFIFO as TX or RX direction (not bi-direction). 1245 + * So, the driver uses odd channels for TX, even channels for RX. 1246 + */ 1247 + snprintf(name, sizeof(name), "ch%d", channel); 1248 + if (channel & 1) { 1249 + fifo->tx_chan = dma_request_slave_channel_reason(dev, name); 1250 + if (IS_ERR(fifo->tx_chan)) 1251 + fifo->tx_chan = NULL; 1252 + } else { 1253 + fifo->rx_chan = dma_request_slave_channel_reason(dev, name); 1254 + if (IS_ERR(fifo->rx_chan)) 1255 + fifo->rx_chan = NULL; 1256 + } 1251 1257 } 1252 1258 1253 1259 static void usbhsf_dma_init(struct usbhs_priv *priv, struct usbhs_fifo *fifo,
+5 -4
drivers/usb/renesas_usbhs/fifo.h
··· 44 44 struct usbhs_fifo dfifo[USBHS_MAX_NUM_DFIFO]; 45 45 }; 46 46 #define usbhsf_get_dnfifo(p, n) (&((p)->fifo_info.dfifo[n])) 47 - #define usbhs_for_each_dfifo(priv, dfifo, i) \ 48 - for ((i) = 0, dfifo = usbhsf_get_dnfifo(priv, (i)); \ 49 - ((i) < USBHS_MAX_NUM_DFIFO); \ 50 - (i)++, dfifo = usbhsf_get_dnfifo(priv, (i))) 47 + #define usbhs_for_each_dfifo(priv, dfifo, i) \ 48 + for ((i) = 0; \ 49 + ((i) < USBHS_MAX_NUM_DFIFO) && \ 50 + ((dfifo) = usbhsf_get_dnfifo(priv, (i))); \ 51 + (i)++) 51 52 52 53 struct usbhs_pkt_handle; 53 54 struct usbhs_pkt {
+36 -27
drivers/usb/renesas_usbhs/mod.c
··· 218 218 /******************** spin lock ********************/ 219 219 usbhs_lock(priv, flags); 220 220 state->intsts0 = usbhs_read(priv, INTSTS0); 221 - state->intsts1 = usbhs_read(priv, INTSTS1); 222 - 223 221 intenb0 = usbhs_read(priv, INTENB0); 224 - intenb1 = usbhs_read(priv, INTENB1); 222 + 223 + if (usbhs_mod_is_host(priv)) { 224 + state->intsts1 = usbhs_read(priv, INTSTS1); 225 + intenb1 = usbhs_read(priv, INTENB1); 226 + } else { 227 + state->intsts1 = intenb1 = 0; 228 + } 225 229 226 230 /* mask */ 227 231 if (mod) { ··· 279 275 * - Function :: VALID bit should 0 280 276 */ 281 277 usbhs_write(priv, INTSTS0, ~irq_state.intsts0 & INTSTS0_MAGIC); 282 - usbhs_write(priv, INTSTS1, ~irq_state.intsts1 & INTSTS1_MAGIC); 278 + if (usbhs_mod_is_host(priv)) 279 + usbhs_write(priv, INTSTS1, ~irq_state.intsts1 & INTSTS1_MAGIC); 283 280 284 281 usbhs_write(priv, BRDYSTS, ~irq_state.brdysts); 285 282 usbhs_write(priv, NRDYSTS, ~irq_state.nrdysts); ··· 308 303 if (irq_state.intsts0 & BRDY) 309 304 usbhs_mod_call(priv, irq_ready, priv, &irq_state); 310 305 311 - /* INTSTS1 */ 312 - if (irq_state.intsts1 & ATTCH) 313 - usbhs_mod_call(priv, irq_attch, priv, &irq_state); 306 + if (usbhs_mod_is_host(priv)) { 307 + /* INTSTS1 */ 308 + if (irq_state.intsts1 & ATTCH) 309 + usbhs_mod_call(priv, irq_attch, priv, &irq_state); 314 310 315 - if (irq_state.intsts1 & DTCH) 316 - usbhs_mod_call(priv, irq_dtch, priv, &irq_state); 311 + if (irq_state.intsts1 & DTCH) 312 + usbhs_mod_call(priv, irq_dtch, priv, &irq_state); 317 313 318 - if (irq_state.intsts1 & SIGN) 319 - usbhs_mod_call(priv, irq_sign, priv, &irq_state); 314 + if (irq_state.intsts1 & SIGN) 315 + usbhs_mod_call(priv, irq_sign, priv, &irq_state); 320 316 321 - if (irq_state.intsts1 & SACK) 322 - usbhs_mod_call(priv, irq_sack, priv, &irq_state); 323 - 317 + if (irq_state.intsts1 & SACK) 318 + usbhs_mod_call(priv, irq_sack, priv, &irq_state); 319 + } 324 320 return IRQ_HANDLED; 325 321 } 326 322 ··· 340 334 * - update INTSTS0 341 335 */ 342 336 usbhs_write(priv, INTENB0, 0); 343 - usbhs_write(priv, INTENB1, 0); 337 + if (usbhs_mod_is_host(priv)) 338 + usbhs_write(priv, INTENB1, 0); 344 339 345 340 usbhs_write(priv, BEMPENB, 0); 346 341 usbhs_write(priv, BRDYENB, 0); ··· 375 368 intenb0 |= BRDYE; 376 369 } 377 370 378 - /* 379 - * INTSTS1 380 - */ 381 - if (mod->irq_attch) 382 - intenb1 |= ATTCHE; 371 + if (usbhs_mod_is_host(priv)) { 372 + /* 373 + * INTSTS1 374 + */ 375 + if (mod->irq_attch) 376 + intenb1 |= ATTCHE; 383 377 384 - if (mod->irq_dtch) 385 - intenb1 |= DTCHE; 378 + if (mod->irq_dtch) 379 + intenb1 |= DTCHE; 386 380 387 - if (mod->irq_sign) 388 - intenb1 |= SIGNE; 381 + if (mod->irq_sign) 382 + intenb1 |= SIGNE; 389 383 390 - if (mod->irq_sack) 391 - intenb1 |= SACKE; 384 + if (mod->irq_sack) 385 + intenb1 |= SACKE; 386 + } 392 387 } 393 388 394 389 if (intenb0) 395 390 usbhs_write(priv, INTENB0, intenb0); 396 391 397 - if (intenb1) 392 + if (usbhs_mod_is_host(priv) && intenb1) 398 393 usbhs_write(priv, INTENB1, intenb1); 399 394 }
+6
include/linux/mod_devicetable.h
··· 629 629 kernel_ulong_t driver_data; 630 630 }; 631 631 632 + struct ulpi_device_id { 633 + __u16 vendor; 634 + __u16 product; 635 + kernel_ulong_t driver_data; 636 + }; 637 + 632 638 #endif /* LINUX_MOD_DEVICETABLE_H */
+26
include/linux/phy/phy-sun4i-usb.h
··· 1 + /* 2 + * Copyright (c) 2015 Hans de Goede <hdegoede@redhat.com> 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 and 6 + * only version 2 as published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #ifndef PHY_SUN4I_USB_H_ 15 + #define PHY_SUN4I_USB_H_ 16 + 17 + #include "phy.h" 18 + 19 + /** 20 + * sun4i_usb_phy_set_squelch_detect() - Enable/disable squelch detect 21 + * @phy: reference to a sun4i usb phy 22 + * @enabled: wether to enable or disable squelch detect 23 + */ 24 + void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled); 25 + 26 + #endif
+60
include/linux/ulpi/driver.h
··· 1 + #ifndef __LINUX_ULPI_DRIVER_H 2 + #define __LINUX_ULPI_DRIVER_H 3 + 4 + #include <linux/mod_devicetable.h> 5 + 6 + #include <linux/device.h> 7 + 8 + struct ulpi_ops; 9 + 10 + /** 11 + * struct ulpi - describes ULPI PHY device 12 + * @id: vendor and product ids for ULPI device 13 + * @ops: I/O access 14 + * @dev: device interface 15 + */ 16 + struct ulpi { 17 + struct ulpi_device_id id; 18 + struct ulpi_ops *ops; 19 + struct device dev; 20 + }; 21 + 22 + #define to_ulpi_dev(d) container_of(d, struct ulpi, dev) 23 + 24 + static inline void ulpi_set_drvdata(struct ulpi *ulpi, void *data) 25 + { 26 + dev_set_drvdata(&ulpi->dev, data); 27 + } 28 + 29 + static inline void *ulpi_get_drvdata(struct ulpi *ulpi) 30 + { 31 + return dev_get_drvdata(&ulpi->dev); 32 + } 33 + 34 + /** 35 + * struct ulpi_driver - describes a ULPI PHY driver 36 + * @id_table: array of device identifiers supported by this driver 37 + * @probe: binds this driver to ULPI device 38 + * @remove: unbinds this driver from ULPI device 39 + * @driver: the name and owner members must be initialized by the drivers 40 + */ 41 + struct ulpi_driver { 42 + const struct ulpi_device_id *id_table; 43 + int (*probe)(struct ulpi *ulpi); 44 + void (*remove)(struct ulpi *ulpi); 45 + struct device_driver driver; 46 + }; 47 + 48 + #define to_ulpi_driver(d) container_of(d, struct ulpi_driver, driver) 49 + 50 + int ulpi_register_driver(struct ulpi_driver *drv); 51 + void ulpi_unregister_driver(struct ulpi_driver *drv); 52 + 53 + #define module_ulpi_driver(__ulpi_driver) \ 54 + module_driver(__ulpi_driver, ulpi_register_driver, \ 55 + ulpi_unregister_driver) 56 + 57 + int ulpi_read(struct ulpi *ulpi, u8 addr); 58 + int ulpi_write(struct ulpi *ulpi, u8 addr, u8 val); 59 + 60 + #endif /* __LINUX_ULPI_DRIVER_H */
+23
include/linux/ulpi/interface.h
··· 1 + #ifndef __LINUX_ULPI_INTERFACE_H 2 + #define __LINUX_ULPI_INTERFACE_H 3 + 4 + #include <linux/types.h> 5 + 6 + struct ulpi; 7 + 8 + /** 9 + * struct ulpi_ops - ULPI register access 10 + * @dev: the interface provider 11 + * @read: read operation for ULPI register access 12 + * @write: write operation for ULPI register access 13 + */ 14 + struct ulpi_ops { 15 + struct device *dev; 16 + int (*read)(struct ulpi_ops *ops, u8 addr); 17 + int (*write)(struct ulpi_ops *ops, u8 addr, u8 val); 18 + }; 19 + 20 + struct ulpi *ulpi_register_interface(struct device *, struct ulpi_ops *); 21 + void ulpi_unregister_interface(struct ulpi *); 22 + 23 + #endif /* __LINUX_ULPI_INTERFACE_H */
+130
include/linux/ulpi/regs.h
··· 1 + #ifndef __LINUX_ULPI_REGS_H 2 + #define __LINUX_ULPI_REGS_H 3 + 4 + /* 5 + * Macros for Set and Clear 6 + * See ULPI 1.1 specification to find the registers with Set and Clear offsets 7 + */ 8 + #define ULPI_SET(a) (a + 1) 9 + #define ULPI_CLR(a) (a + 2) 10 + 11 + /* 12 + * Register Map 13 + */ 14 + #define ULPI_VENDOR_ID_LOW 0x00 15 + #define ULPI_VENDOR_ID_HIGH 0x01 16 + #define ULPI_PRODUCT_ID_LOW 0x02 17 + #define ULPI_PRODUCT_ID_HIGH 0x03 18 + #define ULPI_FUNC_CTRL 0x04 19 + #define ULPI_IFC_CTRL 0x07 20 + #define ULPI_OTG_CTRL 0x0a 21 + #define ULPI_USB_INT_EN_RISE 0x0d 22 + #define ULPI_USB_INT_EN_FALL 0x10 23 + #define ULPI_USB_INT_STS 0x13 24 + #define ULPI_USB_INT_LATCH 0x14 25 + #define ULPI_DEBUG 0x15 26 + #define ULPI_SCRATCH 0x16 27 + /* Optional Carkit Registers */ 28 + #define ULPI_CARKIT_CTRL 0x19 29 + #define ULPI_CARKIT_INT_DELAY 0x1c 30 + #define ULPI_CARKIT_INT_EN 0x1d 31 + #define ULPI_CARKIT_INT_STS 0x20 32 + #define ULPI_CARKIT_INT_LATCH 0x21 33 + #define ULPI_CARKIT_PLS_CTRL 0x22 34 + /* Other Optional Registers */ 35 + #define ULPI_TX_POS_WIDTH 0x25 36 + #define ULPI_TX_NEG_WIDTH 0x26 37 + #define ULPI_POLARITY_RECOVERY 0x27 38 + /* Access Extended Register Set */ 39 + #define ULPI_ACCESS_EXTENDED 0x2f 40 + /* Vendor Specific */ 41 + #define ULPI_VENDOR_SPECIFIC 0x30 42 + /* Extended Registers */ 43 + #define ULPI_EXT_VENDOR_SPECIFIC 0x80 44 + 45 + /* 46 + * Register Bits 47 + */ 48 + 49 + /* Function Control */ 50 + #define ULPI_FUNC_CTRL_XCVRSEL BIT(0) 51 + #define ULPI_FUNC_CTRL_XCVRSEL_MASK 0x3 52 + #define ULPI_FUNC_CTRL_HIGH_SPEED 0x0 53 + #define ULPI_FUNC_CTRL_FULL_SPEED 0x1 54 + #define ULPI_FUNC_CTRL_LOW_SPEED 0x2 55 + #define ULPI_FUNC_CTRL_FS4LS 0x3 56 + #define ULPI_FUNC_CTRL_TERMSELECT BIT(2) 57 + #define ULPI_FUNC_CTRL_OPMODE BIT(3) 58 + #define ULPI_FUNC_CTRL_OPMODE_MASK (0x3 << 3) 59 + #define ULPI_FUNC_CTRL_OPMODE_NORMAL (0x0 << 3) 60 + #define ULPI_FUNC_CTRL_OPMODE_NONDRIVING (0x1 << 3) 61 + #define ULPI_FUNC_CTRL_OPMODE_DISABLE_NRZI (0x2 << 3) 62 + #define ULPI_FUNC_CTRL_OPMODE_NOSYNC_NOEOP (0x3 << 3) 63 + #define ULPI_FUNC_CTRL_RESET BIT(5) 64 + #define ULPI_FUNC_CTRL_SUSPENDM BIT(6) 65 + 66 + /* Interface Control */ 67 + #define ULPI_IFC_CTRL_6_PIN_SERIAL_MODE BIT(0) 68 + #define ULPI_IFC_CTRL_3_PIN_SERIAL_MODE BIT(1) 69 + #define ULPI_IFC_CTRL_CARKITMODE BIT(2) 70 + #define ULPI_IFC_CTRL_CLOCKSUSPENDM BIT(3) 71 + #define ULPI_IFC_CTRL_AUTORESUME BIT(4) 72 + #define ULPI_IFC_CTRL_EXTERNAL_VBUS BIT(5) 73 + #define ULPI_IFC_CTRL_PASSTHRU BIT(6) 74 + #define ULPI_IFC_CTRL_PROTECT_IFC_DISABLE BIT(7) 75 + 76 + /* OTG Control */ 77 + #define ULPI_OTG_CTRL_ID_PULLUP BIT(0) 78 + #define ULPI_OTG_CTRL_DP_PULLDOWN BIT(1) 79 + #define ULPI_OTG_CTRL_DM_PULLDOWN BIT(2) 80 + #define ULPI_OTG_CTRL_DISCHRGVBUS BIT(3) 81 + #define ULPI_OTG_CTRL_CHRGVBUS BIT(4) 82 + #define ULPI_OTG_CTRL_DRVVBUS BIT(5) 83 + #define ULPI_OTG_CTRL_DRVVBUS_EXT BIT(6) 84 + #define ULPI_OTG_CTRL_EXTVBUSIND BIT(7) 85 + 86 + /* USB Interrupt Enable Rising, 87 + * USB Interrupt Enable Falling, 88 + * USB Interrupt Status and 89 + * USB Interrupt Latch 90 + */ 91 + #define ULPI_INT_HOST_DISCONNECT BIT(0) 92 + #define ULPI_INT_VBUS_VALID BIT(1) 93 + #define ULPI_INT_SESS_VALID BIT(2) 94 + #define ULPI_INT_SESS_END BIT(3) 95 + #define ULPI_INT_IDGRD BIT(4) 96 + 97 + /* Debug */ 98 + #define ULPI_DEBUG_LINESTATE0 BIT(0) 99 + #define ULPI_DEBUG_LINESTATE1 BIT(1) 100 + 101 + /* Carkit Control */ 102 + #define ULPI_CARKIT_CTRL_CARKITPWR BIT(0) 103 + #define ULPI_CARKIT_CTRL_IDGNDDRV BIT(1) 104 + #define ULPI_CARKIT_CTRL_TXDEN BIT(2) 105 + #define ULPI_CARKIT_CTRL_RXDEN BIT(3) 106 + #define ULPI_CARKIT_CTRL_SPKLEFTEN BIT(4) 107 + #define ULPI_CARKIT_CTRL_SPKRIGHTEN BIT(5) 108 + #define ULPI_CARKIT_CTRL_MICEN BIT(6) 109 + 110 + /* Carkit Interrupt Enable */ 111 + #define ULPI_CARKIT_INT_EN_IDFLOAT_RISE BIT(0) 112 + #define ULPI_CARKIT_INT_EN_IDFLOAT_FALL BIT(1) 113 + #define ULPI_CARKIT_INT_EN_CARINTDET BIT(2) 114 + #define ULPI_CARKIT_INT_EN_DP_RISE BIT(3) 115 + #define ULPI_CARKIT_INT_EN_DP_FALL BIT(4) 116 + 117 + /* Carkit Interrupt Status and 118 + * Carkit Interrupt Latch 119 + */ 120 + #define ULPI_CARKIT_INT_IDFLOAT BIT(0) 121 + #define ULPI_CARKIT_INT_CARINTDET BIT(1) 122 + #define ULPI_CARKIT_INT_DP BIT(2) 123 + 124 + /* Carkit Pulse Control*/ 125 + #define ULPI_CARKIT_PLS_CTRL_TXPLSEN BIT(0) 126 + #define ULPI_CARKIT_PLS_CTRL_RXPLSEN BIT(1) 127 + #define ULPI_CARKIT_PLS_CTRL_SPKRLEFT_BIASEN BIT(2) 128 + #define ULPI_CARKIT_PLS_CTRL_SPKRRIGHT_BIASEN BIT(3) 129 + 130 + #endif /* __LINUX_ULPI_REGS_H */
+22
include/linux/usb/msm_hsusb.h
··· 18 18 #ifndef __ASM_ARCH_MSM_HSUSB_H 19 19 #define __ASM_ARCH_MSM_HSUSB_H 20 20 21 + #include <linux/extcon.h> 21 22 #include <linux/types.h> 22 23 #include <linux/usb/otg.h> 23 24 #include <linux/clk.h> ··· 121 120 }; 122 121 123 122 /** 123 + * struct msm_usb_cable - structure for exteternal connector cable 124 + * state tracking 125 + * @nb: hold event notification callback 126 + * @conn: used for notification registration 127 + */ 128 + struct msm_usb_cable { 129 + struct notifier_block nb; 130 + struct extcon_specific_cable_nb conn; 131 + }; 132 + 133 + /** 124 134 * struct msm_otg: OTG driver data. Shared by HCD and DCD. 125 135 * @otg: USB OTG Transceiver structure. 126 136 * @pdata: otg device platform data. ··· 150 138 * @chg_type: The type of charger attached. 151 139 * @dcd_retires: The retry count used to track Data contact 152 140 * detection process. 141 + * @manual_pullup: true if VBUS is not routed to USB controller/phy 142 + * and controller driver therefore enables pull-up explicitly before 143 + * starting controller using usbcmd run/stop bit. 144 + * @vbus: VBUS signal state trakining, using extcon framework 145 + * @id: ID signal state trakining, using extcon framework 153 146 */ 154 147 struct msm_otg { 155 148 struct usb_phy phy; ··· 183 166 struct reset_control *phy_rst; 184 167 struct reset_control *link_rst; 185 168 int vdd_levels[3]; 169 + 170 + bool manual_pullup; 171 + 172 + struct msm_usb_cable vbus; 173 + struct msm_usb_cable id; 186 174 }; 187 175 188 176 #endif
+9
include/linux/usb/msm_hsusb_hw.h
··· 21 21 22 22 #define USB_AHBBURST (MSM_USB_BASE + 0x0090) 23 23 #define USB_AHBMODE (MSM_USB_BASE + 0x0098) 24 + #define USB_GENCONFIG_2 (MSM_USB_BASE + 0x00a0) 25 + 24 26 #define USB_CAPLENGTH (MSM_USB_BASE + 0x0100) /* 8 bit */ 25 27 26 28 #define USB_USBCMD (MSM_USB_BASE + 0x0140) ··· 31 29 #define USB_USBMODE (MSM_USB_BASE + 0x01A8) 32 30 #define USB_PHY_CTRL (MSM_USB_BASE + 0x0240) 33 31 #define USB_PHY_CTRL2 (MSM_USB_BASE + 0x0278) 32 + 33 + #define GENCONFIG_2_SESS_VLD_CTRL_EN BIT(7) 34 + #define USBCMD_SESS_VLD_CTRL BIT(25) 34 35 35 36 #define USBCMD_RESET 2 36 37 #define USB_USBINTR (MSM_USB_BASE + 0x0148) ··· 54 49 /* synopsys 28nm phy registers */ 55 50 #define ULPI_PWR_CLK_MNG_REG 0x88 56 51 #define OTG_COMP_DISABLE BIT(0) 52 + 53 + #define ULPI_MISC_A 0x96 54 + #define ULPI_MISC_A_VBUSVLDEXTSEL BIT(1) 55 + #define ULPI_MISC_A_VBUSVLDEXT BIT(0) 57 56 58 57 #define ASYNC_INTR_CTRL (1 << 29) /* Enable async interrupt */ 59 58 #define ULPI_STP_CTRL (1 << 30) /* Block communication with PHY */
+3
include/linux/usb/net2280.h
··· 168 168 #define ENDPOINT_B_INTERRUPT 2 169 169 #define ENDPOINT_A_INTERRUPT 1 170 170 #define ENDPOINT_0_INTERRUPT 0 171 + #define USB3380_IRQSTAT0_EP_INTR_MASK_IN (0xF << 17) 172 + #define USB3380_IRQSTAT0_EP_INTR_MASK_OUT (0xF << 1) 173 + 171 174 u32 irqstat1; 172 175 #define POWER_STATE_CHANGE_INTERRUPT 27 173 176 #define PCI_ARBITER_TIMEOUT_INTERRUPT 26
+8
include/linux/usb/phy.h
··· 205 205 extern struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index); 206 206 extern struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev, 207 207 const char *phandle, u8 index); 208 + extern struct usb_phy *devm_usb_get_phy_by_node(struct device *dev, 209 + struct device_node *node, struct notifier_block *nb); 208 210 extern void usb_put_phy(struct usb_phy *); 209 211 extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x); 210 212 extern int usb_bind_phy(const char *dev_name, u8 index, ··· 236 234 237 235 static inline struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev, 238 236 const char *phandle, u8 index) 237 + { 238 + return ERR_PTR(-ENXIO); 239 + } 240 + 241 + static inline struct usb_phy *devm_usb_get_phy_by_node(struct device *dev, 242 + struct device_node *node, struct notifier_block *nb) 239 243 { 240 244 return ERR_PTR(-ENXIO); 241 245 }
+1 -2
include/linux/usb/renesas_usbhs.h
··· 169 169 #define USBHS_USB_DMAC_XFER_SIZE 32 /* hardcode the xfer size */ 170 170 }; 171 171 172 - #define USBHS_TYPE_R8A7790 1 173 - #define USBHS_TYPE_R8A7791 2 172 + #define USBHS_TYPE_RCAR_GEN2 1 174 173 175 174 /* 176 175 * option:
+2 -132
include/linux/usb/ulpi.h
··· 12 12 #define __LINUX_USB_ULPI_H 13 13 14 14 #include <linux/usb/otg.h> 15 + #include <linux/ulpi/regs.h> 16 + 15 17 /*-------------------------------------------------------------------------*/ 16 18 17 19 /* ··· 48 46 #define ULPI_FC_OP_NSYNC_NEOP (1 << 24) 49 47 #define ULPI_FC_RST (1 << 25) 50 48 #define ULPI_FC_SUSPM (1 << 26) 51 - 52 - /*-------------------------------------------------------------------------*/ 53 - 54 - /* 55 - * Macros for Set and Clear 56 - * See ULPI 1.1 specification to find the registers with Set and Clear offsets 57 - */ 58 - #define ULPI_SET(a) (a + 1) 59 - #define ULPI_CLR(a) (a + 2) 60 - 61 - /*-------------------------------------------------------------------------*/ 62 - 63 - /* 64 - * Register Map 65 - */ 66 - #define ULPI_VENDOR_ID_LOW 0x00 67 - #define ULPI_VENDOR_ID_HIGH 0x01 68 - #define ULPI_PRODUCT_ID_LOW 0x02 69 - #define ULPI_PRODUCT_ID_HIGH 0x03 70 - #define ULPI_FUNC_CTRL 0x04 71 - #define ULPI_IFC_CTRL 0x07 72 - #define ULPI_OTG_CTRL 0x0a 73 - #define ULPI_USB_INT_EN_RISE 0x0d 74 - #define ULPI_USB_INT_EN_FALL 0x10 75 - #define ULPI_USB_INT_STS 0x13 76 - #define ULPI_USB_INT_LATCH 0x14 77 - #define ULPI_DEBUG 0x15 78 - #define ULPI_SCRATCH 0x16 79 - /* Optional Carkit Registers */ 80 - #define ULPI_CARCIT_CTRL 0x19 81 - #define ULPI_CARCIT_INT_DELAY 0x1c 82 - #define ULPI_CARCIT_INT_EN 0x1d 83 - #define ULPI_CARCIT_INT_STS 0x20 84 - #define ULPI_CARCIT_INT_LATCH 0x21 85 - #define ULPI_CARCIT_PLS_CTRL 0x22 86 - /* Other Optional Registers */ 87 - #define ULPI_TX_POS_WIDTH 0x25 88 - #define ULPI_TX_NEG_WIDTH 0x26 89 - #define ULPI_POLARITY_RECOVERY 0x27 90 - /* Access Extended Register Set */ 91 - #define ULPI_ACCESS_EXTENDED 0x2f 92 - /* Vendor Specific */ 93 - #define ULPI_VENDOR_SPECIFIC 0x30 94 - /* Extended Registers */ 95 - #define ULPI_EXT_VENDOR_SPECIFIC 0x80 96 - 97 - /*-------------------------------------------------------------------------*/ 98 - 99 - /* 100 - * Register Bits 101 - */ 102 - 103 - /* Function Control */ 104 - #define ULPI_FUNC_CTRL_XCVRSEL (1 << 0) 105 - #define ULPI_FUNC_CTRL_XCVRSEL_MASK (3 << 0) 106 - #define ULPI_FUNC_CTRL_HIGH_SPEED (0 << 0) 107 - #define ULPI_FUNC_CTRL_FULL_SPEED (1 << 0) 108 - #define ULPI_FUNC_CTRL_LOW_SPEED (2 << 0) 109 - #define ULPI_FUNC_CTRL_FS4LS (3 << 0) 110 - #define ULPI_FUNC_CTRL_TERMSELECT (1 << 2) 111 - #define ULPI_FUNC_CTRL_OPMODE (1 << 3) 112 - #define ULPI_FUNC_CTRL_OPMODE_MASK (3 << 3) 113 - #define ULPI_FUNC_CTRL_OPMODE_NORMAL (0 << 3) 114 - #define ULPI_FUNC_CTRL_OPMODE_NONDRIVING (1 << 3) 115 - #define ULPI_FUNC_CTRL_OPMODE_DISABLE_NRZI (2 << 3) 116 - #define ULPI_FUNC_CTRL_OPMODE_NOSYNC_NOEOP (3 << 3) 117 - #define ULPI_FUNC_CTRL_RESET (1 << 5) 118 - #define ULPI_FUNC_CTRL_SUSPENDM (1 << 6) 119 - 120 - /* Interface Control */ 121 - #define ULPI_IFC_CTRL_6_PIN_SERIAL_MODE (1 << 0) 122 - #define ULPI_IFC_CTRL_3_PIN_SERIAL_MODE (1 << 1) 123 - #define ULPI_IFC_CTRL_CARKITMODE (1 << 2) 124 - #define ULPI_IFC_CTRL_CLOCKSUSPENDM (1 << 3) 125 - #define ULPI_IFC_CTRL_AUTORESUME (1 << 4) 126 - #define ULPI_IFC_CTRL_EXTERNAL_VBUS (1 << 5) 127 - #define ULPI_IFC_CTRL_PASSTHRU (1 << 6) 128 - #define ULPI_IFC_CTRL_PROTECT_IFC_DISABLE (1 << 7) 129 - 130 - /* OTG Control */ 131 - #define ULPI_OTG_CTRL_ID_PULLUP (1 << 0) 132 - #define ULPI_OTG_CTRL_DP_PULLDOWN (1 << 1) 133 - #define ULPI_OTG_CTRL_DM_PULLDOWN (1 << 2) 134 - #define ULPI_OTG_CTRL_DISCHRGVBUS (1 << 3) 135 - #define ULPI_OTG_CTRL_CHRGVBUS (1 << 4) 136 - #define ULPI_OTG_CTRL_DRVVBUS (1 << 5) 137 - #define ULPI_OTG_CTRL_DRVVBUS_EXT (1 << 6) 138 - #define ULPI_OTG_CTRL_EXTVBUSIND (1 << 7) 139 - 140 - /* USB Interrupt Enable Rising, 141 - * USB Interrupt Enable Falling, 142 - * USB Interrupt Status and 143 - * USB Interrupt Latch 144 - */ 145 - #define ULPI_INT_HOST_DISCONNECT (1 << 0) 146 - #define ULPI_INT_VBUS_VALID (1 << 1) 147 - #define ULPI_INT_SESS_VALID (1 << 2) 148 - #define ULPI_INT_SESS_END (1 << 3) 149 - #define ULPI_INT_IDGRD (1 << 4) 150 - 151 - /* Debug */ 152 - #define ULPI_DEBUG_LINESTATE0 (1 << 0) 153 - #define ULPI_DEBUG_LINESTATE1 (1 << 1) 154 - 155 - /* Carkit Control */ 156 - #define ULPI_CARKIT_CTRL_CARKITPWR (1 << 0) 157 - #define ULPI_CARKIT_CTRL_IDGNDDRV (1 << 1) 158 - #define ULPI_CARKIT_CTRL_TXDEN (1 << 2) 159 - #define ULPI_CARKIT_CTRL_RXDEN (1 << 3) 160 - #define ULPI_CARKIT_CTRL_SPKLEFTEN (1 << 4) 161 - #define ULPI_CARKIT_CTRL_SPKRIGHTEN (1 << 5) 162 - #define ULPI_CARKIT_CTRL_MICEN (1 << 6) 163 - 164 - /* Carkit Interrupt Enable */ 165 - #define ULPI_CARKIT_INT_EN_IDFLOAT_RISE (1 << 0) 166 - #define ULPI_CARKIT_INT_EN_IDFLOAT_FALL (1 << 1) 167 - #define ULPI_CARKIT_INT_EN_CARINTDET (1 << 2) 168 - #define ULPI_CARKIT_INT_EN_DP_RISE (1 << 3) 169 - #define ULPI_CARKIT_INT_EN_DP_FALL (1 << 4) 170 - 171 - /* Carkit Interrupt Status and 172 - * Carkit Interrupt Latch 173 - */ 174 - #define ULPI_CARKIT_INT_IDFLOAT (1 << 0) 175 - #define ULPI_CARKIT_INT_CARINTDET (1 << 1) 176 - #define ULPI_CARKIT_INT_DP (1 << 2) 177 - 178 - /* Carkit Pulse Control*/ 179 - #define ULPI_CARKIT_PLS_CTRL_TXPLSEN (1 << 0) 180 - #define ULPI_CARKIT_PLS_CTRL_RXPLSEN (1 << 1) 181 - #define ULPI_CARKIT_PLS_CTRL_SPKRLEFT_BIASEN (1 << 2) 182 - #define ULPI_CARKIT_PLS_CTRL_SPKRRIGHT_BIASEN (1 << 3) 183 49 184 50 /*-------------------------------------------------------------------------*/ 185 51
+4
include/linux/usb/usb338x.h
··· 43 43 #define IN_ENDPOINT_TYPE 12 44 44 #define OUT_ENDPOINT_ENABLE 10 45 45 #define OUT_ENDPOINT_TYPE 8 46 + #define USB3380_EP_CFG_MASK_IN ((0x3 << IN_ENDPOINT_TYPE) | \ 47 + BIT(IN_ENDPOINT_ENABLE)) 48 + #define USB3380_EP_CFG_MASK_OUT ((0x3 << OUT_ENDPOINT_TYPE) | \ 49 + BIT(OUT_ENDPOINT_ENABLE)) 46 50 47 51 struct usb338x_usb_ext_regs { 48 52 u32 usbclass;
+4
scripts/mod/devicetable-offsets.c
··· 189 189 DEVID_FIELD(rio_device_id, asm_did); 190 190 DEVID_FIELD(rio_device_id, asm_vid); 191 191 192 + DEVID(ulpi_device_id); 193 + DEVID_FIELD(ulpi_device_id, vendor); 194 + DEVID_FIELD(ulpi_device_id, product); 195 + 192 196 return 0; 193 197 }
+13
scripts/mod/file2alias.c
··· 1192 1192 } 1193 1193 ADD_TO_DEVTABLE("rapidio", rio_device_id, do_rio_entry); 1194 1194 1195 + /* Looks like: ulpi:vNpN */ 1196 + static int do_ulpi_entry(const char *filename, void *symval, 1197 + char *alias) 1198 + { 1199 + DEF_FIELD(symval, ulpi_device_id, vendor); 1200 + DEF_FIELD(symval, ulpi_device_id, product); 1201 + 1202 + sprintf(alias, "ulpi:v%04xp%04x", vendor, product); 1203 + 1204 + return 1; 1205 + } 1206 + ADD_TO_DEVTABLE("ulpi", ulpi_device_id, do_ulpi_entry); 1207 + 1195 1208 /* Does namelen bytes of name exactly match the symbol? */ 1196 1209 static bool sym_is(const char *name, unsigned namelen, const char *symbol) 1197 1210 {