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

Merge tag 'usb-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB patches from Greg Kroah-Hartman:
"Here's the big USB merge for 3.9-rc1

Nothing major, lots of gadget fixes, and of course, xhci stuff.

All of this has been in linux-next for a while, with the exception of
the last 3 patches, which were reverts of patches in the tree that
caused problems, they went in yesterday."

* tag 'usb-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (190 commits)
Revert "USB: EHCI: make ehci-vt8500 a separate driver"
Revert "USB: EHCI: make ehci-orion a separate driver"
Revert "USB: update host controller Kconfig entries"
USB: update host controller Kconfig entries
USB: EHCI: make ehci-orion a separate driver
USB: EHCI: make ehci-vt8500 a separate driver
USB: usb-storage: unusual_devs update for Super TOP SATA bridge
USB: ehci-omap: Fix autoloading of module
USB: ehci-omap: Don't free gpios that we didn't request
USB: option: add Huawei "ACM" devices using protocol = vendor
USB: serial: fix null-pointer dereferences on disconnect
USB: option: add Yota / Megafon M100-1 4g modem
drivers/usb: add missing GENERIC_HARDIRQS dependencies
USB: storage: properly handle the endian issues of idProduct
testusb: remove all mentions of 'usbfs'
usb: gadget: imx_udc: make it depend on BROKEN
usb: omap_control_usb: fix compile warning
ARM: OMAP: USB: Add phy binding information
ARM: OMAP2: MUSB: Specify omap4 has mailbox
ARM: OMAP: devices: create device for usb part of control module
...

+6397 -2525
+9
Documentation/ABI/testing/sysfs-bus-usb
··· 227 227 Description: 228 228 The /sys/bus/usb/devices/.../(hub interface)/portX 229 229 is usb port device's sysfs directory. 230 + 231 + What: /sys/bus/usb/devices/.../(hub interface)/portX/connect_type 232 + Date: January 2013 233 + Contact: Lan Tianyu <tianyu.lan@intel.com> 234 + Description: 235 + Some platforms provide usb port connect types through ACPI. 236 + This attribute is to expose these information to user space. 237 + The file will read "hotplug", "wired" and "not used" if the 238 + information is available, and "unknown" otherwise.
+22
Documentation/devicetree/bindings/usb/dwc3.txt
··· 1 + synopsys DWC3 CORE 2 + 3 + DWC3- USB3 CONTROLLER 4 + 5 + Required properties: 6 + - compatible: must be "synopsys,dwc3" 7 + - reg : Address and length of the register set for the device 8 + - interrupts: Interrupts used by the dwc3 controller. 9 + - usb-phy : array of phandle for the PHY device 10 + 11 + Optional properties: 12 + - tx-fifo-resize: determines if the FIFO *has* to be reallocated. 13 + 14 + This is usually a subnode to DWC3 glue to which it is connected. 15 + 16 + dwc3@4a030000 { 17 + compatible = "synopsys,dwc3"; 18 + reg = <0x4a030000 0xcfff>; 19 + interrupts = <0 92 4> 20 + usb-phy = <&usb2_phy>, <&usb3,phy>; 21 + tx-fifo-resize; 22 + };
+33 -1
Documentation/devicetree/bindings/usb/omap-usb.txt
··· 1 - OMAP GLUE 1 + OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS 2 2 3 3 OMAP MUSB GLUE 4 4 - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb" 5 5 - ti,hwmods : must be "usb_otg_hs" 6 + - ti,has-mailbox : to specify that omap uses an external mailbox 7 + (in control module) to communicate with the musb core during device connect 8 + and disconnect. 6 9 - multipoint : Should be "1" indicating the musb controller supports 7 10 multipoint. This is a MUSB configuration-specific setting. 8 11 - num_eps : Specifies the number of endpoints. This is also a ··· 19 16 - power : Should be "50". This signifies the controller can supply upto 20 17 100mA when operating in host mode. 21 18 19 + Optional properties: 20 + - ctrl-module : phandle of the control module this glue uses to write to 21 + mailbox 22 + 22 23 SOC specific device node entry 23 24 usb_otg_hs: usb_otg_hs@4a0ab000 { 24 25 compatible = "ti,omap4-musb"; 25 26 ti,hwmods = "usb_otg_hs"; 27 + ti,has-mailbox; 26 28 multipoint = <1>; 27 29 num_eps = <16>; 28 30 ram_bits = <12>; 31 + ctrl-module = <&omap_control_usb>; 29 32 }; 30 33 31 34 Board specific device node entry ··· 39 30 interface_type = <1>; 40 31 mode = <3>; 41 32 power = <50>; 33 + }; 34 + 35 + OMAP CONTROL USB 36 + 37 + Required properties: 38 + - compatible: Should be "ti,omap-control-usb" 39 + - reg : Address and length of the register set for the device. It contains 40 + the address of "control_dev_conf" and "otghs_control" or "phy_power_usb" 41 + depending upon omap4 or omap5. 42 + - reg-names: The names of the register addresses corresponding to the registers 43 + filled in "reg". 44 + - ti,type: This is used to differentiate whether the control module has 45 + usb mailbox or usb3 phy power. omap4 has usb mailbox in control module to 46 + notify events to the musb core and omap5 has usb3 phy power register to 47 + power on usb3 phy. Should be "1" if it has mailbox and "2" if it has usb3 48 + phy power. 49 + 50 + omap_control_usb: omap-control-usb@4a002300 { 51 + compatible = "ti,omap-control-usb"; 52 + reg = <0x4a002300 0x4>, 53 + <0x4a00233c 0x4>; 54 + reg-names = "control_dev_conf", "otghs_control"; 55 + ti,type = <1>; 42 56 };
+55
Documentation/devicetree/bindings/usb/samsung-usbphy.txt
··· 1 + * Samsung's usb phy transceiver 2 + 3 + The Samsung's phy transceiver is used for controlling usb phy for 4 + s3c-hsotg as well as ehci-s5p and ohci-exynos usb controllers 5 + across Samsung SOCs. 6 + TODO: Adding the PHY binding with controller(s) according to the under 7 + developement generic PHY driver. 8 + 9 + Required properties: 10 + 11 + Exynos4210: 12 + - compatible : should be "samsung,exynos4210-usbphy" 13 + - reg : base physical address of the phy registers and length of memory mapped 14 + region. 15 + 16 + Exynos5250: 17 + - compatible : should be "samsung,exynos5250-usbphy" 18 + - reg : base physical address of the phy registers and length of memory mapped 19 + region. 20 + 21 + Optional properties: 22 + - #address-cells: should be '1' when usbphy node has a child node with 'reg' 23 + property. 24 + - #size-cells: should be '1' when usbphy node has a child node with 'reg' 25 + property. 26 + - ranges: allows valid translation between child's address space and parent's 27 + address space. 28 + 29 + - The child node 'usbphy-sys' to the node 'usbphy' is for the system controller 30 + interface for usb-phy. It should provide the following information required by 31 + usb-phy controller to control phy. 32 + - reg : base physical address of PHY_CONTROL registers. 33 + The size of this register is the total sum of size of all PHY_CONTROL 34 + registers that the SoC has. For example, the size will be 35 + '0x4' in case we have only one PHY_CONTROL register (e.g. 36 + OTHERS register in S3C64XX or USB_PHY_CONTROL register in S5PV210) 37 + and, '0x8' in case we have two PHY_CONTROL registers (e.g. 38 + USBDEVICE_PHY_CONTROL and USBHOST_PHY_CONTROL registers in exynos4x). 39 + and so on. 40 + 41 + Example: 42 + - Exynos4210 43 + 44 + usbphy@125B0000 { 45 + #address-cells = <1>; 46 + #size-cells = <1>; 47 + compatible = "samsung,exynos4210-usbphy"; 48 + reg = <0x125B0000 0x100>; 49 + ranges; 50 + 51 + usbphy-sys { 52 + /* USB device and host PHY_CONTROL registers */ 53 + reg = <0x10020704 0x8>; 54 + }; 55 + };
+30 -5
Documentation/devicetree/bindings/usb/usb-phy.txt
··· 4 4 5 5 Required properties: 6 6 - compatible: Should be "ti,omap-usb2" 7 - - reg : Address and length of the register set for the device. Also 8 - add the address of control module dev conf register until a driver for 9 - control module is added 7 + - reg : Address and length of the register set for the device. 8 + 9 + Optional properties: 10 + - ctrl-module : phandle of the control module used by PHY driver to power on 11 + the PHY. 10 12 11 13 This is usually a subnode of ocp2scp to which it is connected. 12 14 13 15 usb2phy@4a0ad080 { 14 16 compatible = "ti,omap-usb2"; 15 - reg = <0x4a0ad080 0x58>, 16 - <0x4a002300 0x4>; 17 + reg = <0x4a0ad080 0x58>; 18 + ctrl-module = <&omap_control_usb>; 19 + }; 20 + 21 + OMAP USB3 PHY 22 + 23 + Required properties: 24 + - compatible: Should be "ti,omap-usb3" 25 + - reg : Address and length of the register set for the device. 26 + - reg-names: The names of the register addresses corresponding to the registers 27 + filled in "reg". 28 + 29 + Optional properties: 30 + - ctrl-module : phandle of the control module used by PHY driver to power on 31 + the PHY. 32 + 33 + This is usually a subnode of ocp2scp to which it is connected. 34 + 35 + usb3phy@4a084400 { 36 + compatible = "ti,omap-usb3"; 37 + reg = <0x4a084400 0x80>, 38 + <0x4a084800 0x64>, 39 + <0x4a084c00 0x40>; 40 + reg-names = "phy_rx", "phy_tx", "pll_ctrl"; 41 + ctrl-module = <&omap_control_usb>; 17 42 };
+20
Documentation/devicetree/bindings/usb/usb3503.txt
··· 1 + SMSC USB3503 High-Speed Hub Controller 2 + 3 + Required properties: 4 + - compatible: Should be "smsc,usb3503". 5 + - reg: Specifies the i2c slave address, it should be 0x08. 6 + - connect-gpios: Should specify GPIO for connect. 7 + - intn-gpios: Should specify GPIO for interrupt. 8 + - reset-gpios: Should specify GPIO for reset. 9 + - initial-mode: Should specify initial mode. 10 + (1 for HUB mode, 2 for STANDBY mode) 11 + 12 + Examples: 13 + usb3503@08 { 14 + compatible = "smsc,usb3503"; 15 + reg = <0x08>; 16 + connect-gpios = <&gpx3 0 1>; 17 + intn-gpios = <&gpx3 4 1>; 18 + reset-gpios = <&gpx3 5 1>; 19 + initial-mode = <1>; 20 + };
+2 -1
MAINTAINERS
··· 7927 7927 USB ATTACHED SCSI 7928 7928 M: Matthew Wilcox <willy@linux.intel.com> 7929 7929 M: Sarah Sharp <sarah.a.sharp@linux.intel.com> 7930 + M: Gerd Hoffmann <kraxel@redhat.com> 7930 7931 L: linux-usb@vger.kernel.org 7931 7932 L: linux-scsi@vger.kernel.org 7932 - S: Supported 7933 + S: Maintained 7933 7934 F: drivers/usb/storage/uas.c 7934 7935 7935 7936 USB CDC ETHERNET DRIVER
+2
arch/arm/mach-omap2/board-2430sdp.c
··· 27 27 #include <linux/clk.h> 28 28 #include <linux/io.h> 29 29 #include <linux/gpio.h> 30 + #include <linux/usb/phy.h> 30 31 31 32 #include <asm/mach-types.h> 32 33 #include <asm/mach/arch.h> ··· 264 263 omap_hsmmc_init(mmc); 265 264 266 265 omap_mux_init_signal("usb0hs_stp", OMAP_PULL_ENA | OMAP_PULL_UP); 266 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 267 267 usb_musb_init(NULL); 268 268 269 269 board_smc91x_init();
+2
arch/arm/mach-omap2/board-3430sdp.c
··· 25 25 #include <linux/gpio.h> 26 26 #include <linux/mmc/host.h> 27 27 #include <linux/platform_data/spi-omap2-mcspi.h> 28 + #include <linux/usb/phy.h> 28 29 29 30 #include <asm/mach-types.h> 30 31 #include <asm/mach/arch.h> ··· 580 579 omap_ads7846_init(1, gpio_pendown, 310, NULL); 581 580 omap_serial_init(); 582 581 omap_sdrc_init(hyb18m512160af6_sdrc_params, NULL); 582 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 583 583 usb_musb_init(NULL); 584 584 board_smc91x_init(); 585 585 board_flash_init(sdp_flash_partitions, chip_sel_3430, 0);
+2
arch/arm/mach-omap2/board-4430sdp.c
··· 28 28 #include <linux/leds_pwm.h> 29 29 #include <linux/platform_data/omap4-keypad.h> 30 30 #include <linux/usb/musb.h> 31 + #include <linux/usb/phy.h> 31 32 32 33 #include <asm/hardware/gic.h> 33 34 #include <asm/mach-types.h> ··· 697 696 omap4_sdp4430_wifi_init(); 698 697 omap4_twl6030_hsmmc_init(mmc); 699 698 699 + usb_bind_phy("musb-hdrc.0.auto", 0, "omap-usb2.1.auto"); 700 700 usb_musb_init(&musb_board_data); 701 701 702 702 status = omap_ethernet_init();
+2
arch/arm/mach-omap2/board-cm-t35.c
··· 30 30 #include <linux/regulator/fixed.h> 31 31 #include <linux/regulator/machine.h> 32 32 #include <linux/mmc/host.h> 33 + #include <linux/usb/phy.h> 33 34 34 35 #include <linux/spi/spi.h> 35 36 #include <linux/spi/tdo24m.h> ··· 725 724 cm_t35_init_display(); 726 725 omap_twl4030_audio_init("cm-t3x"); 727 726 727 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 728 728 usb_musb_init(NULL); 729 729 cm_t35_init_usbh(); 730 730 cm_t35_init_camera();
+2
arch/arm/mach-omap2/board-devkit8000.c
··· 29 29 #include <linux/mtd/partitions.h> 30 30 #include <linux/mtd/nand.h> 31 31 #include <linux/mmc/host.h> 32 + #include <linux/usb/phy.h> 32 33 33 34 #include <linux/regulator/machine.h> 34 35 #include <linux/i2c/twl.h> ··· 623 622 624 623 omap_ads7846_init(2, OMAP3_DEVKIT_TS_GPIO, 0, NULL); 625 624 625 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 626 626 usb_musb_init(NULL); 627 627 usbhs_init(&usbhs_bdata); 628 628 board_nand_init(devkit8000_nand_partitions,
+2
arch/arm/mach-omap2/board-igep0020.c
··· 18 18 #include <linux/gpio.h> 19 19 #include <linux/interrupt.h> 20 20 #include <linux/input.h> 21 + #include <linux/usb/phy.h> 21 22 22 23 #include <linux/regulator/machine.h> 23 24 #include <linux/regulator/fixed.h> ··· 626 625 omap_serial_init(); 627 626 omap_sdrc_init(m65kxxxxam_sdrc_params, 628 627 m65kxxxxam_sdrc_params); 628 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 629 629 usb_musb_init(NULL); 630 630 631 631 igep_flash_init();
+2
arch/arm/mach-omap2/board-ldp.c
··· 28 28 #include <linux/io.h> 29 29 #include <linux/smsc911x.h> 30 30 #include <linux/mmc/host.h> 31 + #include <linux/usb/phy.h> 31 32 #include <linux/platform_data/spi-omap2-mcspi.h> 32 33 33 34 #include <asm/mach-types.h> ··· 419 418 omap_ads7846_init(1, 54, 310, NULL); 420 419 omap_serial_init(); 421 420 omap_sdrc_init(NULL, NULL); 421 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 422 422 usb_musb_init(NULL); 423 423 board_nand_init(ldp_nand_partitions, ARRAY_SIZE(ldp_nand_partitions), 424 424 ZOOM_NAND_CS, 0, nand_default_timings);
+2
arch/arm/mach-omap2/board-omap3beagle.c
··· 30 30 #include <linux/mtd/partitions.h> 31 31 #include <linux/mtd/nand.h> 32 32 #include <linux/mmc/host.h> 33 + #include <linux/usb/phy.h> 33 34 34 35 #include <linux/regulator/machine.h> 35 36 #include <linux/i2c/twl.h> ··· 520 519 omap_sdrc_init(mt46h32m32lf6_sdrc_params, 521 520 mt46h32m32lf6_sdrc_params); 522 521 522 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 523 523 usb_musb_init(NULL); 524 524 usbhs_init(&usbhs_bdata); 525 525 board_nand_init(omap3beagle_nand_partitions,
+2
arch/arm/mach-omap2/board-omap3evm.c
··· 41 41 #include <linux/regulator/machine.h> 42 42 #include <linux/mmc/host.h> 43 43 #include <linux/export.h> 44 + #include <linux/usb/phy.h> 44 45 45 46 #include <asm/mach-types.h> 46 47 #include <asm/mach/arch.h> ··· 735 734 omap_mux_init_gpio(135, OMAP_PIN_OUTPUT); 736 735 usbhs_bdata.reset_gpio_port[1] = 135; 737 736 } 737 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 738 738 usb_musb_init(&musb_board_data); 739 739 usbhs_init(&usbhs_bdata); 740 740 board_nand_init(omap3evm_nand_partitions,
+2
arch/arm/mach-omap2/board-omap3logic.c
··· 29 29 30 30 #include <linux/i2c/twl.h> 31 31 #include <linux/mmc/host.h> 32 + #include <linux/usb/phy.h> 32 33 33 34 #include <asm/mach-types.h> 34 35 #include <asm/mach/arch.h> ··· 216 215 board_mmc_init(); 217 216 board_smsc911x_init(); 218 217 218 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 219 219 usb_musb_init(NULL); 220 220 221 221 /* Ensure SDRC pins are mux'd for self-refresh */
+2
arch/arm/mach-omap2/board-omap3pandora.c
··· 35 35 #include <linux/mmc/host.h> 36 36 #include <linux/mmc/card.h> 37 37 #include <linux/regulator/fixed.h> 38 + #include <linux/usb/phy.h> 38 39 #include <linux/platform_data/spi-omap2-mcspi.h> 39 40 40 41 #include <asm/mach-types.h> ··· 602 601 ARRAY_SIZE(omap3pandora_spi_board_info)); 603 602 omap_ads7846_init(1, OMAP3_PANDORA_TS_GPIO, 0, NULL); 604 603 usbhs_init(&usbhs_bdata); 604 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 605 605 usb_musb_init(NULL); 606 606 gpmc_nand_init(&pandora_nand_data, NULL); 607 607
+2
arch/arm/mach-omap2/board-omap3stalker.c
··· 33 33 #include <linux/interrupt.h> 34 34 #include <linux/smsc911x.h> 35 35 #include <linux/i2c/at24.h> 36 + #include <linux/usb/phy.h> 36 37 37 38 #include <asm/mach-types.h> 38 39 #include <asm/mach/arch.h> ··· 405 404 406 405 omap_serial_init(); 407 406 omap_sdrc_init(mt46h32m32lf6_sdrc_params, NULL); 407 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 408 408 usb_musb_init(NULL); 409 409 usbhs_init(&usbhs_bdata); 410 410 omap_ads7846_init(1, OMAP3_STALKER_TS_GPIO, 310, NULL);
+2
arch/arm/mach-omap2/board-omap3touchbook.c
··· 28 28 #include <linux/mtd/partitions.h> 29 29 #include <linux/mtd/nand.h> 30 30 #include <linux/mmc/host.h> 31 + #include <linux/usb/phy.h> 31 32 32 33 #include <linux/platform_data/spi-omap2-mcspi.h> 33 34 #include <linux/spi/spi.h> ··· 366 365 367 366 /* Touchscreen and accelerometer */ 368 367 omap_ads7846_init(4, OMAP3_TS_GPIO, 310, &ads7846_pdata); 368 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 369 369 usb_musb_init(NULL); 370 370 usbhs_init(&usbhs_bdata); 371 371 board_nand_init(omap3touchbook_nand_partitions,
+2
arch/arm/mach-omap2/board-omap4panda.c
··· 30 30 #include <linux/regulator/fixed.h> 31 31 #include <linux/ti_wilink_st.h> 32 32 #include <linux/usb/musb.h> 33 + #include <linux/usb/phy.h> 33 34 #include <linux/wl12xx.h> 34 35 #include <linux/platform_data/omap-abe-twl6040.h> 35 36 ··· 448 447 omap_sdrc_init(NULL, NULL); 449 448 omap4_twl6030_hsmmc_init(mmc); 450 449 omap4_ehci_init(); 450 + usb_bind_phy("musb-hdrc.0.auto", 0, "omap-usb2.1.auto"); 451 451 usb_musb_init(&musb_board_data); 452 452 omap4_panda_display_init(); 453 453 }
+2
arch/arm/mach-omap2/board-overo.c
··· 36 36 #include <linux/mtd/nand.h> 37 37 #include <linux/mtd/partitions.h> 38 38 #include <linux/mmc/host.h> 39 + #include <linux/usb/phy.h> 39 40 40 41 #include <linux/platform_data/mtd-nand-omap2.h> 41 42 #include <linux/platform_data/spi-omap2-mcspi.h> ··· 500 499 mt46h32m32lf6_sdrc_params); 501 500 board_nand_init(overo_nand_partitions, 502 501 ARRAY_SIZE(overo_nand_partitions), NAND_CS, 0, NULL); 502 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 503 503 usb_musb_init(NULL); 504 504 usbhs_init(&usbhs_bdata); 505 505 overo_spi_init();
+2
arch/arm/mach-omap2/board-rm680.c
··· 18 18 #include <linux/regulator/machine.h> 19 19 #include <linux/regulator/consumer.h> 20 20 #include <linux/platform_data/mtd-onenand-omap2.h> 21 + #include <linux/usb/phy.h> 21 22 22 23 #include <asm/mach/arch.h> 23 24 #include <asm/mach-types.h> ··· 135 134 sdrc_params = nokia_get_sdram_timings(); 136 135 omap_sdrc_init(sdrc_params, sdrc_params); 137 136 137 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 138 138 usb_musb_init(NULL); 139 139 rm680_peripherals_init(); 140 140 }
+2
arch/arm/mach-omap2/board-zoom-peripherals.c
··· 20 20 #include <linux/wl12xx.h> 21 21 #include <linux/mmc/host.h> 22 22 #include <linux/platform_data/gpio-omap.h> 23 + #include <linux/usb/phy.h> 23 24 24 25 #include <asm/mach-types.h> 25 26 #include <asm/mach/arch.h> ··· 299 298 omap_hsmmc_init(mmc); 300 299 omap_i2c_init(); 301 300 platform_device_register(&omap_vwlan_device); 301 + usb_bind_phy("musb-hdrc.0.auto", 0, "twl4030_usb"); 302 302 usb_musb_init(NULL); 303 303 enable_board_wakeup_source(); 304 304 omap_serial_init();
+45
arch/arm/mach-omap2/devices.c
··· 20 20 #include <linux/pinctrl/machine.h> 21 21 #include <linux/platform_data/omap4-keypad.h> 22 22 #include <linux/platform_data/omap_ocp2scp.h> 23 + #include <linux/usb/omap_control_usb.h> 23 24 24 25 #include <asm/mach-types.h> 25 26 #include <asm/mach/map.h> ··· 254 253 platform_device_register(&omap2cam_device); 255 254 #endif 256 255 } 256 + 257 + #if IS_ENABLED(CONFIG_OMAP_CONTROL_USB) 258 + static struct omap_control_usb_platform_data omap4_control_usb_pdata = { 259 + .type = 1, 260 + }; 261 + 262 + struct resource omap4_control_usb_res[] = { 263 + { 264 + .name = "control_dev_conf", 265 + .start = 0x4a002300, 266 + .end = 0x4a002303, 267 + .flags = IORESOURCE_MEM, 268 + }, 269 + { 270 + .name = "otghs_control", 271 + .start = 0x4a00233c, 272 + .end = 0x4a00233f, 273 + .flags = IORESOURCE_MEM, 274 + }, 275 + }; 276 + 277 + static struct platform_device omap4_control_usb = { 278 + .name = "omap-control-usb", 279 + .id = -1, 280 + .dev = { 281 + .platform_data = &omap4_control_usb_pdata, 282 + }, 283 + .num_resources = 2, 284 + .resource = omap4_control_usb_res, 285 + }; 286 + 287 + static inline void __init omap_init_control_usb(void) 288 + { 289 + if (!cpu_is_omap44xx()) 290 + return; 291 + 292 + if (platform_device_register(&omap4_control_usb)) 293 + pr_err("Error registering omap_control_usb device\n"); 294 + } 295 + 296 + #else 297 + static inline void omap_init_control_usb(void) { } 298 + #endif /* CONFIG_OMAP_CONTROL_USB */ 257 299 258 300 int __init omap4_keyboard_init(struct omap4_keypad_platform_data 259 301 *sdp4430_keypad_data, struct omap_board_data *bdata) ··· 765 721 omap_init_mbox(); 766 722 /* If dtb is there, the devices will be created dynamically */ 767 723 if (!of_have_populated_dt()) { 724 + omap_init_control_usb(); 768 725 omap_init_dmic(); 769 726 omap_init_mcpdm(); 770 727 omap_init_mcspi();
-13
arch/arm/mach-omap2/omap_hwmod_44xx_data.c
··· 2702 2702 .end = 0x4a0ae000, 2703 2703 .flags = IORESOURCE_MEM, 2704 2704 }, 2705 - { 2706 - /* XXX: Remove this once control module driver is in place */ 2707 - .name = "ctrl_dev", 2708 - .start = 0x4a002300, 2709 - .end = 0x4a002303, 2710 - .flags = IORESOURCE_MEM, 2711 - }, 2712 2705 { } 2713 2706 }; 2714 2707 ··· 6147 6154 { 6148 6155 .pa_start = 0x4a0ab000, 6149 6156 .pa_end = 0x4a0ab7ff, 6150 - .flags = ADDR_TYPE_RT 6151 - }, 6152 - { 6153 - /* XXX: Remove this once control module driver is in place */ 6154 - .pa_start = 0x4a00233c, 6155 - .pa_end = 0x4a00233f, 6156 6157 .flags = ADDR_TYPE_RT 6157 6158 }, 6158 6159 { }
+3
arch/arm/mach-omap2/usb-musb.c
··· 85 85 musb_plat.mode = board_data->mode; 86 86 musb_plat.extvbus = board_data->extvbus; 87 87 88 + if (cpu_is_omap44xx()) 89 + musb_plat.has_mailbox = true; 90 + 88 91 if (soc_is_am35xx()) { 89 92 oh_name = "am35x_otg_hs"; 90 93 name = "musb-am35x";
+1
drivers/base/power/qos.c
··· 91 91 92 92 return ret; 93 93 } 94 + EXPORT_SYMBOL_GPL(dev_pm_qos_flags); 94 95 95 96 /** 96 97 * __dev_pm_qos_read_value - Get PM QoS constraint for a given device.
+1 -1
drivers/usb/c67x00/c67x00-ll-hpi.c
··· 237 237 /* -------------------------------------------------------------------------- */ 238 238 /* Transactions */ 239 239 240 - static inline u16 ll_recv_msg(struct c67x00_device *dev) 240 + static inline int ll_recv_msg(struct c67x00_device *dev) 241 241 { 242 242 u16 res; 243 243
+1 -1
drivers/usb/chipidea/ci13xxx_imx.h
··· 19 19 struct device *dev; /* usb controller device */ 20 20 int index; 21 21 22 - int disable_oc:1; /* over current detect disabled */ 22 + unsigned int disable_oc:1; /* over current detect disabled */ 23 23 }; 24 24 25 25 int usbmisc_set_ops(const struct usbmisc_ops *ops);
+1 -1
drivers/usb/chipidea/core.c
··· 411 411 } 412 412 413 413 base = devm_request_and_ioremap(dev, res); 414 - if (!res) { 414 + if (!base) { 415 415 dev_err(dev, "can't request and ioremap resource\n"); 416 416 return -ENOMEM; 417 417 }
+1
drivers/usb/core/Makefile
··· 7 7 usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o 8 8 usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o 9 9 usbcore-y += devio.o notify.o generic.o quirks.o devices.o 10 + usbcore-y += port.o 10 11 11 12 usbcore-$(CONFIG_PCI) += hcd-pci.o 12 13 usbcore-$(CONFIG_ACPI) += usb-acpi.o
+10 -3
drivers/usb/core/devices.c
··· 316 316 */ 317 317 static char *usb_dump_config_descriptor(char *start, char *end, 318 318 const struct usb_config_descriptor *desc, 319 - int active) 319 + int active, int speed) 320 320 { 321 + int mul; 322 + 321 323 if (start > end) 322 324 return start; 325 + if (speed == USB_SPEED_SUPER) 326 + mul = 8; 327 + else 328 + mul = 2; 323 329 start += sprintf(start, format_config, 324 330 /* mark active/actual/current cfg. */ 325 331 active ? '*' : ' ', 326 332 desc->bNumInterfaces, 327 333 desc->bConfigurationValue, 328 334 desc->bmAttributes, 329 - desc->bMaxPower * 2); 335 + desc->bMaxPower * mul); 330 336 return start; 331 337 } 332 338 ··· 348 342 if (!config) 349 343 /* getting these some in 2.3.7; none in 2.3.6 */ 350 344 return start + sprintf(start, "(null Cfg. desc.)\n"); 351 - start = usb_dump_config_descriptor(start, end, &config->desc, active); 345 + start = usb_dump_config_descriptor(start, end, &config->desc, active, 346 + speed); 352 347 for (i = 0; i < USB_MAXIADS; i++) { 353 348 if (config->intf_assoc[i] == NULL) 354 349 break;
+2 -1
drivers/usb/core/devio.c
··· 40 40 #include <linux/signal.h> 41 41 #include <linux/poll.h> 42 42 #include <linux/module.h> 43 + #include <linux/string.h> 43 44 #include <linux/usb.h> 44 45 #include <linux/usbdevice_fs.h> 45 46 #include <linux/usb/hcd.h> /* for usbcore internals */ ··· 1078 1077 if (!intf || !intf->dev.driver) 1079 1078 ret = -ENODATA; 1080 1079 else { 1081 - strncpy(gd.driver, intf->dev.driver->name, 1080 + strlcpy(gd.driver, intf->dev.driver->name, 1082 1081 sizeof(gd.driver)); 1083 1082 ret = (copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0); 1084 1083 }
+1 -1
drivers/usb/core/generic.c
··· 100 100 */ 101 101 102 102 /* Rule out configs that draw too much bus current */ 103 - if (c->desc.bMaxPower * 2 > udev->bus_mA) { 103 + if (usb_get_max_power(udev, c) > udev->bus_mA) { 104 104 insufficient_power++; 105 105 continue; 106 106 }
+4 -1
drivers/usb/core/hcd.c
··· 620 620 status = hcd->driver->hub_control (hcd, 621 621 typeReq, wValue, wIndex, 622 622 tbuf, wLength); 623 + 624 + if (typeReq == GetHubDescriptor) 625 + usb_hub_adjust_deviceremovable(hcd->self.root_hub, 626 + (struct usb_hub_descriptor *)tbuf); 623 627 break; 624 628 error: 625 629 /* "protocol stall" on error */ ··· 2554 2550 } 2555 2551 2556 2552 /* starting here, usbcore will pay attention to this root hub */ 2557 - rhdev->bus_mA = min(500u, hcd->power_budget); 2558 2553 if ((retval = register_root_hub(hcd)) != 0) 2559 2554 goto err_register_root_hub; 2560 2555
+344 -272
drivers/usb/core/hub.c
··· 26 26 #include <linux/mutex.h> 27 27 #include <linux/freezer.h> 28 28 #include <linux/random.h> 29 + #include <linux/pm_qos.h> 29 30 30 31 #include <asm/uaccess.h> 31 32 #include <asm/byteorder.h> 32 33 33 - #include "usb.h" 34 + #include "hub.h" 34 35 35 36 /* if we are in debug mode, always announce new devices */ 36 37 #ifdef DEBUG ··· 42 41 43 42 #define USB_VENDOR_GENESYS_LOGIC 0x05e3 44 43 #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 45 - 46 - struct usb_port { 47 - struct usb_device *child; 48 - struct device dev; 49 - struct dev_state *port_owner; 50 - enum usb_port_connect_type connect_type; 51 - }; 52 - 53 - struct usb_hub { 54 - struct device *intfdev; /* the "interface" device */ 55 - struct usb_device *hdev; 56 - struct kref kref; 57 - struct urb *urb; /* for interrupt polling pipe */ 58 - 59 - /* buffer for urb ... with extra space in case of babble */ 60 - char (*buffer)[8]; 61 - union { 62 - struct usb_hub_status hub; 63 - struct usb_port_status port; 64 - } *status; /* buffer for status reports */ 65 - struct mutex status_mutex; /* for the status buffer */ 66 - 67 - int error; /* last reported error */ 68 - int nerrors; /* track consecutive errors */ 69 - 70 - struct list_head event_list; /* hubs w/data or errs ready */ 71 - unsigned long event_bits[1]; /* status change bitmask */ 72 - unsigned long change_bits[1]; /* ports with logical connect 73 - status change */ 74 - unsigned long busy_bits[1]; /* ports being reset or 75 - resumed */ 76 - unsigned long removed_bits[1]; /* ports with a "removed" 77 - device present */ 78 - unsigned long wakeup_bits[1]; /* ports that have signaled 79 - remote wakeup */ 80 - #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ 81 - #error event_bits[] is too short! 82 - #endif 83 - 84 - struct usb_hub_descriptor *descriptor; /* class descriptor */ 85 - struct usb_tt tt; /* Transaction Translator */ 86 - 87 - unsigned mA_per_port; /* current for each child */ 88 - 89 - unsigned limited_power:1; 90 - unsigned quiescing:1; 91 - unsigned disconnected:1; 92 - 93 - unsigned quirk_check_port_auto_suspend:1; 94 - 95 - unsigned has_indicators:1; 96 - u8 indicator[USB_MAXCHILDREN]; 97 - struct delayed_work leds; 98 - struct delayed_work init_work; 99 - struct usb_port **ports; 100 - }; 101 44 102 45 static inline int hub_is_superspeed(struct usb_device *hdev) 103 46 { ··· 109 164 DECLARE_RWSEM(ehci_cf_port_reset_rwsem); 110 165 EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem); 111 166 112 - #define HUB_DEBOUNCE_TIMEOUT 1500 167 + #define HUB_DEBOUNCE_TIMEOUT 2000 113 168 #define HUB_DEBOUNCE_STEP 25 114 169 #define HUB_DEBOUNCE_STABLE 100 115 - 116 - #define to_usb_port(_dev) \ 117 - container_of(_dev, struct usb_port, dev) 118 170 119 171 static int usb_reset_and_verify_device(struct usb_device *udev); 120 172 ··· 128 186 } 129 187 130 188 /* Note that hdev or one of its children must be locked! */ 131 - static struct usb_hub *hdev_to_hub(struct usb_device *hdev) 189 + struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev) 132 190 { 133 191 if (!hdev || !hdev->actconfig || !hdev->maxchild) 134 192 return NULL; ··· 302 360 if (!udev->lpm_capable || udev->speed != USB_SPEED_SUPER) 303 361 return; 304 362 305 - hub = hdev_to_hub(udev->parent); 363 + hub = usb_hub_to_struct_hub(udev->parent); 306 364 /* It doesn't take time to transition the roothub into U0, since it 307 365 * doesn't have an upstream link. 308 366 */ ··· 394 452 /* 395 453 * USB 2.0 spec Section 11.24.2.2 396 454 */ 397 - static int clear_port_feature(struct usb_device *hdev, int port1, int feature) 455 + int usb_clear_port_feature(struct usb_device *hdev, int port1, int feature) 398 456 { 399 457 return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), 400 458 USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port1, ··· 587 645 588 646 void usb_kick_khubd(struct usb_device *hdev) 589 647 { 590 - struct usb_hub *hub = hdev_to_hub(hdev); 648 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 591 649 592 650 if (hub) 593 651 kick_khubd(hub); ··· 609 667 if (!hdev) 610 668 return; 611 669 612 - hub = hdev_to_hub(hdev); 670 + hub = usb_hub_to_struct_hub(hdev); 613 671 if (hub) { 614 672 set_bit(portnum, hub->wakeup_bits); 615 673 kick_khubd(hub); ··· 716 774 } 717 775 718 776 /** 777 + * usb_hub_set_port_power - control hub port's power state 778 + * @hdev: target hub 779 + * @port1: port index 780 + * @set: expected status 781 + * 782 + * call this function to control port's power via setting or 783 + * clearing the port's PORT_POWER feature. 784 + */ 785 + int usb_hub_set_port_power(struct usb_device *hdev, int port1, 786 + bool set) 787 + { 788 + int ret; 789 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 790 + struct usb_port *port_dev = hub->ports[port1 - 1]; 791 + 792 + if (set) 793 + ret = set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); 794 + else 795 + ret = usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_POWER); 796 + 797 + if (!ret) 798 + port_dev->power_is_on = set; 799 + return ret; 800 + } 801 + 802 + /** 719 803 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub 720 804 * @urb: an URB associated with the failed or incomplete split transaction 721 805 * ··· 817 849 dev_dbg(hub->intfdev, "trying to enable port power on " 818 850 "non-switchable hub\n"); 819 851 for (port1 = 1; port1 <= hub->descriptor->bNbrPorts; port1++) 820 - set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); 852 + if (hub->ports[port1 - 1]->power_is_on) 853 + set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); 854 + else 855 + usb_clear_port_feature(hub->hdev, port1, 856 + USB_PORT_FEAT_POWER); 821 857 822 858 /* Wait at least 100 msec for power to become stable */ 823 859 delay = max(pgood_delay, (unsigned) 100); ··· 915 943 if (hub_is_superspeed(hub->hdev)) 916 944 ret = hub_usb3_port_disable(hub, port1); 917 945 else 918 - ret = clear_port_feature(hdev, port1, 946 + ret = usb_clear_port_feature(hdev, port1, 919 947 USB_PORT_FEAT_ENABLE); 920 948 } 921 949 if (ret) ··· 964 992 965 993 if (!udev->parent) /* Can't remove a root hub */ 966 994 return -EINVAL; 967 - hub = hdev_to_hub(udev->parent); 995 + hub = usb_hub_to_struct_hub(udev->parent); 968 996 intf = to_usb_interface(hub->intfdev); 969 997 970 998 usb_autopm_get_interface(intf); ··· 1096 1124 * Do not disable USB3 protocol ports. 1097 1125 */ 1098 1126 if (!hub_is_superspeed(hdev)) { 1099 - clear_port_feature(hdev, port1, 1127 + usb_clear_port_feature(hdev, port1, 1100 1128 USB_PORT_FEAT_ENABLE); 1101 1129 portstatus &= ~USB_PORT_STAT_ENABLE; 1102 1130 } else { ··· 1108 1136 /* Clear status-change flags; we'll debounce later */ 1109 1137 if (portchange & USB_PORT_STAT_C_CONNECTION) { 1110 1138 need_debounce_delay = true; 1111 - clear_port_feature(hub->hdev, port1, 1139 + usb_clear_port_feature(hub->hdev, port1, 1112 1140 USB_PORT_FEAT_C_CONNECTION); 1113 1141 } 1114 1142 if (portchange & USB_PORT_STAT_C_ENABLE) { 1115 1143 need_debounce_delay = true; 1116 - clear_port_feature(hub->hdev, port1, 1144 + usb_clear_port_feature(hub->hdev, port1, 1117 1145 USB_PORT_FEAT_C_ENABLE); 1118 1146 } 1119 1147 if ((portchange & USB_PORT_STAT_C_BH_RESET) && 1120 1148 hub_is_superspeed(hub->hdev)) { 1121 1149 need_debounce_delay = true; 1122 - clear_port_feature(hub->hdev, port1, 1150 + usb_clear_port_feature(hub->hdev, port1, 1123 1151 USB_PORT_FEAT_C_BH_PORT_RESET); 1124 1152 } 1125 1153 /* We can forget about a "removed" device when there's a ··· 1153 1181 set_bit(port1, hub->change_bits); 1154 1182 1155 1183 } else if (udev->persist_enabled) { 1184 + struct usb_port *port_dev = hub->ports[port1 - 1]; 1185 + 1156 1186 #ifdef CONFIG_PM 1157 1187 udev->reset_resume = 1; 1158 1188 #endif 1159 - set_bit(port1, hub->change_bits); 1189 + /* Don't set the change_bits when the device 1190 + * was powered off. 1191 + */ 1192 + if (port_dev->power_is_on) 1193 + set_bit(port1, hub->change_bits); 1160 1194 1161 1195 } else { 1162 1196 /* The power session is gone; tell khubd */ ··· 1272 1294 return 0; 1273 1295 } 1274 1296 1275 - static void usb_port_device_release(struct device *dev) 1276 - { 1277 - struct usb_port *port_dev = to_usb_port(dev); 1278 - 1279 - kfree(port_dev); 1280 - } 1281 - 1282 - static void usb_hub_remove_port_device(struct usb_hub *hub, 1283 - int port1) 1284 - { 1285 - device_unregister(&hub->ports[port1 - 1]->dev); 1286 - } 1287 - 1288 - struct device_type usb_port_device_type = { 1289 - .name = "usb_port", 1290 - .release = usb_port_device_release, 1291 - }; 1292 - 1293 - static int usb_hub_create_port_device(struct usb_hub *hub, 1294 - int port1) 1295 - { 1296 - struct usb_port *port_dev = NULL; 1297 - int retval; 1298 - 1299 - port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL); 1300 - if (!port_dev) { 1301 - retval = -ENOMEM; 1302 - goto exit; 1303 - } 1304 - 1305 - hub->ports[port1 - 1] = port_dev; 1306 - port_dev->dev.parent = hub->intfdev; 1307 - port_dev->dev.type = &usb_port_device_type; 1308 - dev_set_name(&port_dev->dev, "port%d", port1); 1309 - 1310 - retval = device_register(&port_dev->dev); 1311 - if (retval) 1312 - goto error_register; 1313 - return 0; 1314 - 1315 - error_register: 1316 - put_device(&port_dev->dev); 1317 - exit: 1318 - return retval; 1319 - } 1320 - 1321 1297 static int hub_configure(struct usb_hub *hub, 1322 1298 struct usb_endpoint_descriptor *endpoint) 1323 1299 { ··· 1283 1351 unsigned int pipe; 1284 1352 int maxp, ret, i; 1285 1353 char *message = "out of memory"; 1354 + unsigned unit_load; 1355 + unsigned full_load; 1286 1356 1287 1357 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); 1288 1358 if (!hub->buffer) { ··· 1331 1397 } 1332 1398 1333 1399 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); 1400 + if (hub_is_superspeed(hdev)) { 1401 + unit_load = 150; 1402 + full_load = 900; 1403 + } else { 1404 + unit_load = 100; 1405 + full_load = 500; 1406 + } 1334 1407 1335 1408 /* FIXME for USB 3.0, skip for now */ 1336 1409 if ((wHubCharacteristics & HUB_CHAR_COMPOUND) && ··· 1457 1516 goto fail; 1458 1517 } 1459 1518 le16_to_cpus(&hubstatus); 1519 + hcd = bus_to_hcd(hdev->bus); 1460 1520 if (hdev == hdev->bus->root_hub) { 1461 - if (hdev->bus_mA == 0 || hdev->bus_mA >= 500) 1462 - hub->mA_per_port = 500; 1521 + if (hcd->power_budget > 0) 1522 + hdev->bus_mA = hcd->power_budget; 1523 + else 1524 + hdev->bus_mA = full_load * hdev->maxchild; 1525 + if (hdev->bus_mA >= full_load) 1526 + hub->mA_per_port = full_load; 1463 1527 else { 1464 1528 hub->mA_per_port = hdev->bus_mA; 1465 1529 hub->limited_power = 1; 1466 1530 } 1467 1531 } else if ((hubstatus & (1 << USB_DEVICE_SELF_POWERED)) == 0) { 1532 + int remaining = hdev->bus_mA - 1533 + hub->descriptor->bHubContrCurrent; 1534 + 1468 1535 dev_dbg(hub_dev, "hub controller current requirement: %dmA\n", 1469 1536 hub->descriptor->bHubContrCurrent); 1470 1537 hub->limited_power = 1; 1471 - if (hdev->maxchild > 0) { 1472 - int remaining = hdev->bus_mA - 1473 - hub->descriptor->bHubContrCurrent; 1474 1538 1475 - if (remaining < hdev->maxchild * 100) 1476 - dev_warn(hub_dev, 1539 + if (remaining < hdev->maxchild * unit_load) 1540 + dev_warn(hub_dev, 1477 1541 "insufficient power available " 1478 1542 "to use all downstream ports\n"); 1479 - hub->mA_per_port = 100; /* 7.2.1.1 */ 1480 - } 1543 + hub->mA_per_port = unit_load; /* 7.2.1 */ 1544 + 1481 1545 } else { /* Self-powered external hub */ 1482 1546 /* FIXME: What about battery-powered external hubs that 1483 1547 * provide less current per port? */ 1484 - hub->mA_per_port = 500; 1548 + hub->mA_per_port = full_load; 1485 1549 } 1486 - if (hub->mA_per_port < 500) 1550 + if (hub->mA_per_port < full_load) 1487 1551 dev_dbg(hub_dev, "%umA bus power budget for each child\n", 1488 1552 hub->mA_per_port); 1489 1553 1490 1554 /* Update the HCD's internal representation of this hub before khubd 1491 1555 * starts getting port status changes for devices under the hub. 1492 1556 */ 1493 - hcd = bus_to_hcd(hdev->bus); 1494 1557 if (hcd->driver->update_hub_device) { 1495 1558 ret = hcd->driver->update_hub_device(hcd, hdev, 1496 1559 &hub->tt, GFP_KERNEL); ··· 1550 1605 dev_err(hub->intfdev, 1551 1606 "couldn't create port%d device.\n", i + 1); 1552 1607 1608 + usb_hub_adjust_deviceremovable(hdev, hub->descriptor); 1609 + 1553 1610 hub_activate(hub, HUB_INIT); 1554 1611 return 0; 1555 1612 ··· 1606 1659 kfree(hub->status); 1607 1660 kfree(hub->buffer); 1608 1661 1662 + pm_suspend_ignore_children(&intf->dev, false); 1609 1663 kref_put(&hub->kref, hub_release); 1610 1664 } 1611 1665 ··· 1709 1761 1710 1762 usb_set_intfdata (intf, hub); 1711 1763 intf->needs_remote_wakeup = 1; 1764 + pm_suspend_ignore_children(&intf->dev, true); 1712 1765 1713 1766 if (hdev->speed == USB_SPEED_HIGH) 1714 1767 highspeed_hubs++; ··· 1728 1779 hub_ioctl(struct usb_interface *intf, unsigned int code, void *user_data) 1729 1780 { 1730 1781 struct usb_device *hdev = interface_to_usbdev (intf); 1731 - struct usb_hub *hub = hdev_to_hub(hdev); 1782 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 1732 1783 1733 1784 /* assert ifno == 0 (part of hub spec) */ 1734 1785 switch (code) { ··· 1774 1825 /* This assumes that devices not managed by the hub driver 1775 1826 * will always have maxchild equal to 0. 1776 1827 */ 1777 - *ppowner = &(hdev_to_hub(hdev)->ports[port1 - 1]->port_owner); 1828 + *ppowner = &(usb_hub_to_struct_hub(hdev)->ports[port1 - 1]->port_owner); 1778 1829 return 0; 1779 1830 } 1780 1831 ··· 1811 1862 1812 1863 void usb_hub_release_all_ports(struct usb_device *hdev, struct dev_state *owner) 1813 1864 { 1814 - struct usb_hub *hub = hdev_to_hub(hdev); 1865 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 1815 1866 int n; 1816 1867 1817 1868 for (n = 0; n < hdev->maxchild; n++) { ··· 1828 1879 1829 1880 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) 1830 1881 return false; 1831 - hub = hdev_to_hub(udev->parent); 1882 + hub = usb_hub_to_struct_hub(udev->parent); 1832 1883 return !!hub->ports[udev->portnum - 1]->port_owner; 1833 1884 } 1834 1885 1835 1886 static void recursively_mark_NOTATTACHED(struct usb_device *udev) 1836 1887 { 1837 - struct usb_hub *hub = hdev_to_hub(udev); 1888 + struct usb_hub *hub = usb_hub_to_struct_hub(udev); 1838 1889 int i; 1839 1890 1840 1891 for (i = 0; i < udev->maxchild; ++i) { ··· 2003 2054 void usb_disconnect(struct usb_device **pdev) 2004 2055 { 2005 2056 struct usb_device *udev = *pdev; 2006 - struct usb_hub *hub = hdev_to_hub(udev); 2057 + struct usb_hub *hub = usb_hub_to_struct_hub(udev); 2007 2058 int i; 2008 2059 2009 2060 /* mark the device as inactive, so any further urb submissions for ··· 2029 2080 dev_dbg (&udev->dev, "unregistering device\n"); 2030 2081 usb_disable_device(udev, 0); 2031 2082 usb_hcd_synchronize_unlinks(udev); 2083 + 2084 + if (udev->parent) { 2085 + struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); 2086 + struct usb_port *port_dev = hub->ports[udev->portnum - 1]; 2087 + 2088 + sysfs_remove_link(&udev->dev.kobj, "port"); 2089 + sysfs_remove_link(&port_dev->dev.kobj, "device"); 2090 + 2091 + if (!port_dev->did_runtime_put) 2092 + pm_runtime_put(&port_dev->dev); 2093 + else 2094 + port_dev->did_runtime_put = false; 2095 + } 2032 2096 2033 2097 usb_remove_ep_devs(&udev->ep0); 2034 2098 usb_unlock_device(udev); ··· 2229 2267 if (!hdev) 2230 2268 return; 2231 2269 2232 - hub = hdev_to_hub(udev->parent); 2270 + hub = usb_hub_to_struct_hub(udev->parent); 2233 2271 2234 2272 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); 2235 2273 ··· 2333 2371 if (err) { 2334 2372 dev_err(&udev->dev, "can't device_add, error %d\n", err); 2335 2373 goto fail; 2374 + } 2375 + 2376 + /* Create link files between child device and usb port device. */ 2377 + if (udev->parent) { 2378 + struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); 2379 + struct usb_port *port_dev = hub->ports[udev->portnum - 1]; 2380 + 2381 + err = sysfs_create_link(&udev->dev.kobj, 2382 + &port_dev->dev.kobj, "port"); 2383 + if (err) 2384 + goto fail; 2385 + 2386 + err = sysfs_create_link(&port_dev->dev.kobj, 2387 + &udev->dev.kobj, "device"); 2388 + if (err) { 2389 + sysfs_remove_link(&udev->dev.kobj, "port"); 2390 + goto fail; 2391 + } 2392 + 2393 + pm_runtime_get_sync(&port_dev->dev); 2336 2394 } 2337 2395 2338 2396 (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); ··· 2517 2535 return ret; 2518 2536 2519 2537 /* The port state is unknown until the reset completes. */ 2520 - if ((portstatus & USB_PORT_STAT_RESET)) 2521 - goto delay; 2538 + if (!(portstatus & USB_PORT_STAT_RESET)) 2539 + break; 2522 2540 2523 - /* 2524 - * Some buggy devices require a warm reset to be issued even 2525 - * when the port appears not to be connected. 2526 - */ 2527 - if (!warm) { 2528 - /* 2529 - * Some buggy devices can cause an NEC host controller 2530 - * to transition to the "Error" state after a hot port 2531 - * reset. This will show up as the port state in 2532 - * "Inactive", and the port may also report a 2533 - * disconnect. Forcing a warm port reset seems to make 2534 - * the device work. 2535 - * 2536 - * See https://bugzilla.kernel.org/show_bug.cgi?id=41752 2537 - */ 2538 - if (hub_port_warm_reset_required(hub, portstatus)) { 2539 - int ret; 2540 - 2541 - if ((portchange & USB_PORT_STAT_C_CONNECTION)) 2542 - clear_port_feature(hub->hdev, port1, 2543 - USB_PORT_FEAT_C_CONNECTION); 2544 - if (portchange & USB_PORT_STAT_C_LINK_STATE) 2545 - clear_port_feature(hub->hdev, port1, 2546 - USB_PORT_FEAT_C_PORT_LINK_STATE); 2547 - if (portchange & USB_PORT_STAT_C_RESET) 2548 - clear_port_feature(hub->hdev, port1, 2549 - USB_PORT_FEAT_C_RESET); 2550 - dev_dbg(hub->intfdev, "hot reset failed, warm reset port %d\n", 2551 - port1); 2552 - ret = hub_port_reset(hub, port1, 2553 - udev, HUB_BH_RESET_TIME, 2554 - true); 2555 - if ((portchange & USB_PORT_STAT_C_CONNECTION)) 2556 - clear_port_feature(hub->hdev, port1, 2557 - USB_PORT_FEAT_C_CONNECTION); 2558 - return ret; 2559 - } 2560 - /* Device went away? */ 2561 - if (!(portstatus & USB_PORT_STAT_CONNECTION)) 2562 - return -ENOTCONN; 2563 - 2564 - /* bomb out completely if the connection bounced */ 2565 - if ((portchange & USB_PORT_STAT_C_CONNECTION)) 2566 - return -ENOTCONN; 2567 - 2568 - if ((portstatus & USB_PORT_STAT_ENABLE)) { 2569 - if (hub_is_wusb(hub)) 2570 - udev->speed = USB_SPEED_WIRELESS; 2571 - else if (hub_is_superspeed(hub->hdev)) 2572 - udev->speed = USB_SPEED_SUPER; 2573 - else if (portstatus & USB_PORT_STAT_HIGH_SPEED) 2574 - udev->speed = USB_SPEED_HIGH; 2575 - else if (portstatus & USB_PORT_STAT_LOW_SPEED) 2576 - udev->speed = USB_SPEED_LOW; 2577 - else 2578 - udev->speed = USB_SPEED_FULL; 2579 - return 0; 2580 - } 2581 - } else { 2582 - if (!(portstatus & USB_PORT_STAT_CONNECTION) || 2583 - hub_port_warm_reset_required(hub, 2584 - portstatus)) 2585 - return -ENOTCONN; 2586 - 2587 - return 0; 2588 - } 2589 - 2590 - delay: 2591 2541 /* switch to the long delay after two short delay failures */ 2592 2542 if (delay_time >= 2 * HUB_SHORT_RESET_TIME) 2593 2543 delay = HUB_LONG_RESET_TIME; ··· 2529 2615 port1, warm ? "warm " : "", delay); 2530 2616 } 2531 2617 2532 - return -EBUSY; 2618 + if ((portstatus & USB_PORT_STAT_RESET)) 2619 + return -EBUSY; 2620 + 2621 + if (hub_port_warm_reset_required(hub, portstatus)) 2622 + return -ENOTCONN; 2623 + 2624 + /* Device went away? */ 2625 + if (!(portstatus & USB_PORT_STAT_CONNECTION)) 2626 + return -ENOTCONN; 2627 + 2628 + /* bomb out completely if the connection bounced. A USB 3.0 2629 + * connection may bounce if multiple warm resets were issued, 2630 + * but the device may have successfully re-connected. Ignore it. 2631 + */ 2632 + if (!hub_is_superspeed(hub->hdev) && 2633 + (portchange & USB_PORT_STAT_C_CONNECTION)) 2634 + return -ENOTCONN; 2635 + 2636 + if (!(portstatus & USB_PORT_STAT_ENABLE)) 2637 + return -EBUSY; 2638 + 2639 + if (!udev) 2640 + return 0; 2641 + 2642 + if (hub_is_wusb(hub)) 2643 + udev->speed = USB_SPEED_WIRELESS; 2644 + else if (hub_is_superspeed(hub->hdev)) 2645 + udev->speed = USB_SPEED_SUPER; 2646 + else if (portstatus & USB_PORT_STAT_HIGH_SPEED) 2647 + udev->speed = USB_SPEED_HIGH; 2648 + else if (portstatus & USB_PORT_STAT_LOW_SPEED) 2649 + udev->speed = USB_SPEED_LOW; 2650 + else 2651 + udev->speed = USB_SPEED_FULL; 2652 + return 0; 2533 2653 } 2534 2654 2535 2655 static void hub_port_finish_reset(struct usb_hub *hub, int port1, 2536 - struct usb_device *udev, int *status, bool warm) 2656 + struct usb_device *udev, int *status) 2537 2657 { 2538 2658 switch (*status) { 2539 2659 case 0: 2540 - if (!warm) { 2541 - struct usb_hcd *hcd; 2542 - /* TRSTRCY = 10 ms; plus some extra */ 2543 - msleep(10 + 40); 2660 + /* TRSTRCY = 10 ms; plus some extra */ 2661 + msleep(10 + 40); 2662 + if (udev) { 2663 + struct usb_hcd *hcd = bus_to_hcd(udev->bus); 2664 + 2544 2665 update_devnum(udev, 0); 2545 - hcd = bus_to_hcd(udev->bus); 2546 2666 /* The xHC may think the device is already reset, 2547 2667 * so ignore the status. 2548 2668 */ ··· 2586 2638 /* FALL THROUGH */ 2587 2639 case -ENOTCONN: 2588 2640 case -ENODEV: 2589 - clear_port_feature(hub->hdev, 2641 + usb_clear_port_feature(hub->hdev, 2590 2642 port1, USB_PORT_FEAT_C_RESET); 2591 - /* FIXME need disconnect() for NOTATTACHED device */ 2592 2643 if (hub_is_superspeed(hub->hdev)) { 2593 - clear_port_feature(hub->hdev, port1, 2644 + usb_clear_port_feature(hub->hdev, port1, 2594 2645 USB_PORT_FEAT_C_BH_PORT_RESET); 2595 - clear_port_feature(hub->hdev, port1, 2646 + usb_clear_port_feature(hub->hdev, port1, 2596 2647 USB_PORT_FEAT_C_PORT_LINK_STATE); 2648 + usb_clear_port_feature(hub->hdev, port1, 2649 + USB_PORT_FEAT_C_CONNECTION); 2597 2650 } 2598 - if (!warm) 2651 + if (udev) 2599 2652 usb_set_device_state(udev, *status 2600 2653 ? USB_STATE_NOTATTACHED 2601 2654 : USB_STATE_DEFAULT); ··· 2609 2660 struct usb_device *udev, unsigned int delay, bool warm) 2610 2661 { 2611 2662 int i, status; 2663 + u16 portchange, portstatus; 2612 2664 2613 - if (!warm) { 2614 - /* Block EHCI CF initialization during the port reset. 2615 - * Some companion controllers don't like it when they mix. 2616 - */ 2617 - down_read(&ehci_cf_port_reset_rwsem); 2618 - } else { 2619 - if (!hub_is_superspeed(hub->hdev)) { 2665 + if (!hub_is_superspeed(hub->hdev)) { 2666 + if (warm) { 2620 2667 dev_err(hub->intfdev, "only USB3 hub support " 2621 2668 "warm reset\n"); 2622 2669 return -EINVAL; 2623 2670 } 2671 + /* Block EHCI CF initialization during the port reset. 2672 + * Some companion controllers don't like it when they mix. 2673 + */ 2674 + down_read(&ehci_cf_port_reset_rwsem); 2675 + } else if (!warm) { 2676 + /* 2677 + * If the caller hasn't explicitly requested a warm reset, 2678 + * double check and see if one is needed. 2679 + */ 2680 + status = hub_port_status(hub, port1, 2681 + &portstatus, &portchange); 2682 + if (status < 0) 2683 + goto done; 2684 + 2685 + if (hub_port_warm_reset_required(hub, portstatus)) 2686 + warm = true; 2624 2687 } 2625 2688 2626 2689 /* Reset the port */ ··· 2653 2692 status); 2654 2693 } 2655 2694 2656 - /* return on disconnect or reset */ 2695 + /* Check for disconnect or reset */ 2657 2696 if (status == 0 || status == -ENOTCONN || status == -ENODEV) { 2658 - hub_port_finish_reset(hub, port1, udev, &status, warm); 2659 - goto done; 2697 + hub_port_finish_reset(hub, port1, udev, &status); 2698 + 2699 + if (!hub_is_superspeed(hub->hdev)) 2700 + goto done; 2701 + 2702 + /* 2703 + * If a USB 3.0 device migrates from reset to an error 2704 + * state, re-issue the warm reset. 2705 + */ 2706 + if (hub_port_status(hub, port1, 2707 + &portstatus, &portchange) < 0) 2708 + goto done; 2709 + 2710 + if (!hub_port_warm_reset_required(hub, portstatus)) 2711 + goto done; 2712 + 2713 + /* 2714 + * If the port is in SS.Inactive or Compliance Mode, the 2715 + * hot or warm reset failed. Try another warm reset. 2716 + */ 2717 + if (!warm) { 2718 + dev_dbg(hub->intfdev, "hot reset failed, warm reset port %d\n", 2719 + port1); 2720 + warm = true; 2721 + } 2660 2722 } 2661 2723 2662 2724 dev_dbg (hub->intfdev, ··· 2693 2709 port1); 2694 2710 2695 2711 done: 2696 - if (!warm) 2712 + if (!hub_is_superspeed(hub->hdev)) 2697 2713 up_read(&ehci_cf_port_reset_rwsem); 2698 2714 2699 2715 return status; ··· 2767 2783 2768 2784 /* Late port handoff can set status-change bits */ 2769 2785 if (portchange & USB_PORT_STAT_C_CONNECTION) 2770 - clear_port_feature(hub->hdev, port1, 2786 + usb_clear_port_feature(hub->hdev, port1, 2771 2787 USB_PORT_FEAT_C_CONNECTION); 2772 2788 if (portchange & USB_PORT_STAT_C_ENABLE) 2773 - clear_port_feature(hub->hdev, port1, 2789 + usb_clear_port_feature(hub->hdev, port1, 2774 2790 USB_PORT_FEAT_C_ENABLE); 2775 2791 } 2776 2792 ··· 2888 2904 */ 2889 2905 int usb_port_suspend(struct usb_device *udev, pm_message_t msg) 2890 2906 { 2891 - struct usb_hub *hub = hdev_to_hub(udev->parent); 2907 + struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); 2908 + struct usb_port *port_dev = hub->ports[udev->portnum - 1]; 2909 + enum pm_qos_flags_status pm_qos_stat; 2892 2910 int port1 = udev->portnum; 2893 2911 int status; 2894 2912 ··· 2948 2962 2949 2963 /* see 7.1.7.6 */ 2950 2964 if (hub_is_superspeed(hub->hdev)) 2951 - status = set_port_feature(hub->hdev, 2952 - port1 | (USB_SS_PORT_LS_U3 << 3), 2953 - USB_PORT_FEAT_LINK_STATE); 2965 + status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3); 2954 2966 else 2955 2967 status = set_port_feature(hub->hdev, port1, 2956 2968 USB_PORT_FEAT_SUSPEND); ··· 2990 3006 udev->port_is_suspended = 1; 2991 3007 msleep(10); 2992 3008 } 3009 + 3010 + /* 3011 + * Check whether current status meets the requirement of 3012 + * usb port power off mechanism 3013 + */ 3014 + pm_qos_stat = dev_pm_qos_flags(&port_dev->dev, 3015 + PM_QOS_FLAG_NO_POWER_OFF); 3016 + if (!udev->do_remote_wakeup 3017 + && pm_qos_stat != PM_QOS_FLAGS_ALL 3018 + && udev->persist_enabled 3019 + && !status) { 3020 + pm_runtime_put_sync(&port_dev->dev); 3021 + port_dev->did_runtime_put = true; 3022 + } 3023 + 2993 3024 usb_mark_last_busy(hub->hdev); 2994 3025 return status; 2995 3026 } ··· 3140 3141 */ 3141 3142 int usb_port_resume(struct usb_device *udev, pm_message_t msg) 3142 3143 { 3143 - struct usb_hub *hub = hdev_to_hub(udev->parent); 3144 + struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); 3145 + struct usb_port *port_dev = hub->ports[udev->portnum - 1]; 3144 3146 int port1 = udev->portnum; 3145 3147 int status; 3146 3148 u16 portchange, portstatus; 3149 + 3150 + if (port_dev->did_runtime_put) { 3151 + status = pm_runtime_get_sync(&port_dev->dev); 3152 + port_dev->did_runtime_put = false; 3153 + if (status < 0) { 3154 + dev_dbg(&udev->dev, "can't resume usb port, status %d\n", 3155 + status); 3156 + return status; 3157 + } 3158 + } 3147 3159 3148 3160 /* Skip the initial Clear-Suspend step for a remote wakeup */ 3149 3161 status = hub_port_status(hub, port1, &portstatus, &portchange); ··· 3167 3157 3168 3158 /* see 7.1.7.7; affects power usage, but not budgeting */ 3169 3159 if (hub_is_superspeed(hub->hdev)) 3170 - status = set_port_feature(hub->hdev, 3171 - port1 | (USB_SS_PORT_LS_U0 << 3), 3172 - USB_PORT_FEAT_LINK_STATE); 3160 + status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0); 3173 3161 else 3174 - status = clear_port_feature(hub->hdev, 3162 + status = usb_clear_port_feature(hub->hdev, 3175 3163 port1, USB_PORT_FEAT_SUSPEND); 3176 3164 if (status) { 3177 3165 dev_dbg(hub->intfdev, "can't resume port %d, status %d\n", ··· 3195 3187 udev->port_is_suspended = 0; 3196 3188 if (hub_is_superspeed(hub->hdev)) { 3197 3189 if (portchange & USB_PORT_STAT_C_LINK_STATE) 3198 - clear_port_feature(hub->hdev, port1, 3190 + usb_clear_port_feature(hub->hdev, port1, 3199 3191 USB_PORT_FEAT_C_PORT_LINK_STATE); 3200 3192 } else { 3201 3193 if (portchange & USB_PORT_STAT_C_SUSPEND) 3202 - clear_port_feature(hub->hdev, port1, 3194 + usb_clear_port_feature(hub->hdev, port1, 3203 3195 USB_PORT_FEAT_C_SUSPEND); 3204 3196 } 3205 3197 } ··· 3255 3247 3256 3248 int usb_port_resume(struct usb_device *udev, pm_message_t msg) 3257 3249 { 3258 - struct usb_hub *hub = hdev_to_hub(udev->parent); 3250 + struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); 3259 3251 int port1 = udev->portnum; 3260 3252 int status; 3261 3253 u16 portchange, portstatus; ··· 3834 3826 * every 25ms for transient disconnects. When the port status has been 3835 3827 * unchanged for 100ms it returns the port status. 3836 3828 */ 3837 - static int hub_port_debounce(struct usb_hub *hub, int port1) 3829 + int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) 3838 3830 { 3839 3831 int ret; 3840 3832 int total_time, stable_time = 0; ··· 3848 3840 3849 3841 if (!(portchange & USB_PORT_STAT_C_CONNECTION) && 3850 3842 (portstatus & USB_PORT_STAT_CONNECTION) == connection) { 3851 - stable_time += HUB_DEBOUNCE_STEP; 3843 + if (!must_be_connected || 3844 + (connection == USB_PORT_STAT_CONNECTION)) 3845 + stable_time += HUB_DEBOUNCE_STEP; 3852 3846 if (stable_time >= HUB_DEBOUNCE_STABLE) 3853 3847 break; 3854 3848 } else { ··· 3859 3849 } 3860 3850 3861 3851 if (portchange & USB_PORT_STAT_C_CONNECTION) { 3862 - clear_port_feature(hub->hdev, port1, 3852 + usb_clear_port_feature(hub->hdev, port1, 3863 3853 USB_PORT_FEAT_C_CONNECTION); 3864 3854 } 3865 3855 ··· 4256 4246 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { 4257 4247 struct usb_device *udev = hub->ports[port1 - 1]->child; 4258 4248 int delta; 4249 + unsigned unit_load; 4259 4250 4260 4251 if (!udev) 4261 4252 continue; 4253 + if (hub_is_superspeed(udev)) 4254 + unit_load = 150; 4255 + else 4256 + unit_load = 100; 4262 4257 4263 - /* Unconfigured devices may not use more than 100mA, 4264 - * or 8mA for OTG ports */ 4258 + /* 4259 + * Unconfigured devices may not use more than one unit load, 4260 + * or 8mA for OTG ports 4261 + */ 4265 4262 if (udev->actconfig) 4266 - delta = udev->actconfig->desc.bMaxPower * 2; 4263 + delta = usb_get_max_power(udev, udev->actconfig); 4267 4264 else if (port1 != udev->bus->otg_port || hdev->parent) 4268 - delta = 100; 4265 + delta = unit_load; 4269 4266 else 4270 4267 delta = 8; 4271 4268 if (delta > hub->mA_per_port) ··· 4307 4290 le16_to_cpu(hub->descriptor->wHubCharacteristics); 4308 4291 struct usb_device *udev; 4309 4292 int status, i; 4293 + unsigned unit_load; 4310 4294 4311 4295 dev_dbg (hub_dev, 4312 4296 "port %d, status %04x, change %04x, %s\n", ··· 4371 4353 4372 4354 if (portchange & (USB_PORT_STAT_C_CONNECTION | 4373 4355 USB_PORT_STAT_C_ENABLE)) { 4374 - status = hub_port_debounce(hub, port1); 4356 + status = hub_port_debounce_be_stable(hub, port1); 4375 4357 if (status < 0) { 4376 4358 if (printk_ratelimit()) 4377 4359 dev_err(hub_dev, "connect-debounce failed, " ··· 4397 4379 goto done; 4398 4380 return; 4399 4381 } 4382 + if (hub_is_superspeed(hub->hdev)) 4383 + unit_load = 150; 4384 + else 4385 + unit_load = 100; 4400 4386 4401 4387 for (i = 0; i < SET_CONFIG_TRIES; i++) { 4402 4388 ··· 4448 4426 * on the parent. 4449 4427 */ 4450 4428 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB 4451 - && udev->bus_mA <= 100) { 4429 + && udev->bus_mA <= unit_load) { 4452 4430 u16 devstat; 4453 4431 4454 4432 status = usb_get_status(udev, USB_RECIP_DEVICE, 0, ··· 4550 4528 if (!hub_is_superspeed(hdev)) { 4551 4529 if (!(portchange & USB_PORT_STAT_C_SUSPEND)) 4552 4530 return 0; 4553 - clear_port_feature(hdev, port, USB_PORT_FEAT_C_SUSPEND); 4531 + usb_clear_port_feature(hdev, port, USB_PORT_FEAT_C_SUSPEND); 4554 4532 } else { 4555 4533 if (!udev || udev->state != USB_STATE_SUSPENDED || 4556 4534 (portstatus & USB_PORT_STAT_LINK_STATE) != ··· 4678 4656 continue; 4679 4657 4680 4658 if (portchange & USB_PORT_STAT_C_CONNECTION) { 4681 - clear_port_feature(hdev, i, 4659 + usb_clear_port_feature(hdev, i, 4682 4660 USB_PORT_FEAT_C_CONNECTION); 4683 4661 connect_change = 1; 4684 4662 } ··· 4689 4667 "port %d enable change, " 4690 4668 "status %08x\n", 4691 4669 i, portstatus); 4692 - clear_port_feature(hdev, i, 4670 + usb_clear_port_feature(hdev, i, 4693 4671 USB_PORT_FEAT_C_ENABLE); 4694 4672 4695 4673 /* ··· 4720 4698 4721 4699 dev_dbg(hub_dev, "over-current change on port " 4722 4700 "%d\n", i); 4723 - clear_port_feature(hdev, i, 4701 + usb_clear_port_feature(hdev, i, 4724 4702 USB_PORT_FEAT_C_OVER_CURRENT); 4725 4703 msleep(100); /* Cool down */ 4726 4704 hub_power_on(hub, true); ··· 4734 4712 dev_dbg (hub_dev, 4735 4713 "reset change on port %d\n", 4736 4714 i); 4737 - clear_port_feature(hdev, i, 4715 + usb_clear_port_feature(hdev, i, 4738 4716 USB_PORT_FEAT_C_RESET); 4739 4717 } 4740 4718 if ((portchange & USB_PORT_STAT_C_BH_RESET) && ··· 4742 4720 dev_dbg(hub_dev, 4743 4721 "warm reset change on port %d\n", 4744 4722 i); 4745 - clear_port_feature(hdev, i, 4723 + usb_clear_port_feature(hdev, i, 4746 4724 USB_PORT_FEAT_C_BH_PORT_RESET); 4747 4725 } 4748 4726 if (portchange & USB_PORT_STAT_C_LINK_STATE) { 4749 - clear_port_feature(hub->hdev, i, 4727 + usb_clear_port_feature(hub->hdev, i, 4750 4728 USB_PORT_FEAT_C_PORT_LINK_STATE); 4751 4729 } 4752 4730 if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) { 4753 4731 dev_warn(hub_dev, 4754 4732 "config error on port %d\n", 4755 4733 i); 4756 - clear_port_feature(hub->hdev, i, 4734 + usb_clear_port_feature(hub->hdev, i, 4757 4735 USB_PORT_FEAT_C_PORT_CONFIG_ERROR); 4758 4736 } 4759 4737 ··· 4762 4740 */ 4763 4741 if (hub_port_warm_reset_required(hub, portstatus)) { 4764 4742 int status; 4743 + struct usb_device *udev = 4744 + hub->ports[i - 1]->child; 4765 4745 4766 4746 dev_dbg(hub_dev, "warm reset port %d\n", i); 4767 - status = hub_port_reset(hub, i, NULL, 4768 - HUB_BH_RESET_TIME, true); 4769 - if (status < 0) 4770 - hub_port_disable(hub, i, 1); 4747 + if (!udev) { 4748 + status = hub_port_reset(hub, i, 4749 + NULL, HUB_BH_RESET_TIME, 4750 + true); 4751 + if (status < 0) 4752 + hub_port_disable(hub, i, 1); 4753 + } else { 4754 + usb_lock_device(udev); 4755 + status = usb_reset_device(udev); 4756 + usb_unlock_device(udev); 4757 + } 4771 4758 connect_change = 0; 4772 4759 } 4773 4760 ··· 5037 5006 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); 5038 5007 return -EISDIR; 5039 5008 } 5040 - parent_hub = hdev_to_hub(parent_hdev); 5009 + parent_hub = usb_hub_to_struct_hub(parent_hdev); 5041 5010 5042 5011 /* Disable LPM and LTM while we reset the device and reinstall the alt 5043 5012 * settings. Device-initiated LPM settings, and system exit latency ··· 5293 5262 struct usb_device *usb_hub_find_child(struct usb_device *hdev, 5294 5263 int port1) 5295 5264 { 5296 - struct usb_hub *hub = hdev_to_hub(hdev); 5265 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 5297 5266 5298 5267 if (port1 < 1 || port1 > hdev->maxchild) 5299 5268 return NULL; ··· 5310 5279 void usb_set_hub_port_connect_type(struct usb_device *hdev, int port1, 5311 5280 enum usb_port_connect_type type) 5312 5281 { 5313 - struct usb_hub *hub = hdev_to_hub(hdev); 5282 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 5314 5283 5315 5284 hub->ports[port1 - 1]->connect_type = type; 5316 5285 } ··· 5326 5295 enum usb_port_connect_type 5327 5296 usb_get_hub_port_connect_type(struct usb_device *hdev, int port1) 5328 5297 { 5329 - struct usb_hub *hub = hdev_to_hub(hdev); 5298 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 5330 5299 5331 5300 return hub->ports[port1 - 1]->connect_type; 5301 + } 5302 + 5303 + void usb_hub_adjust_deviceremovable(struct usb_device *hdev, 5304 + struct usb_hub_descriptor *desc) 5305 + { 5306 + enum usb_port_connect_type connect_type; 5307 + int i; 5308 + 5309 + if (!hub_is_superspeed(hdev)) { 5310 + for (i = 1; i <= hdev->maxchild; i++) { 5311 + connect_type = usb_get_hub_port_connect_type(hdev, i); 5312 + 5313 + if (connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { 5314 + u8 mask = 1 << (i%8); 5315 + 5316 + if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { 5317 + dev_dbg(&hdev->dev, "usb port%d's DeviceRemovable is changed to 1 according to platform information.\n", 5318 + i); 5319 + desc->u.hs.DeviceRemovable[i/8] |= mask; 5320 + } 5321 + } 5322 + } 5323 + } else { 5324 + u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); 5325 + 5326 + for (i = 1; i <= hdev->maxchild; i++) { 5327 + connect_type = usb_get_hub_port_connect_type(hdev, i); 5328 + 5329 + if (connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { 5330 + u16 mask = 1 << i; 5331 + 5332 + if (!(port_removable & mask)) { 5333 + dev_dbg(&hdev->dev, "usb port%d's DeviceRemovable is changed to 1 according to platform information.\n", 5334 + i); 5335 + port_removable |= mask; 5336 + } 5337 + } 5338 + } 5339 + 5340 + desc->u.ss.DeviceRemovable = cpu_to_le16(port_removable); 5341 + } 5332 5342 } 5333 5343 5334 5344 #ifdef CONFIG_ACPI ··· 5384 5312 acpi_handle usb_get_hub_port_acpi_handle(struct usb_device *hdev, 5385 5313 int port1) 5386 5314 { 5387 - struct usb_hub *hub = hdev_to_hub(hdev); 5315 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 5388 5316 5389 5317 return DEVICE_ACPI_HANDLE(&hub->ports[port1 - 1]->dev); 5390 5318 }
+122
drivers/usb/core/hub.h
··· 1 + /* 2 + * usb hub driver head file 3 + * 4 + * Copyright (C) 1999 Linus Torvalds 5 + * Copyright (C) 1999 Johannes Erdfelt 6 + * Copyright (C) 1999 Gregory P. Smith 7 + * Copyright (C) 2001 Brad Hards (bhards@bigpond.net.au) 8 + * Copyright (C) 2012 Intel Corp (tianyu.lan@intel.com) 9 + * 10 + * move struct usb_hub to this file. 11 + * 12 + * This program is free software; you can redistribute it and/or modify 13 + * it under the terms of the GNU General Public License version 2 as 14 + * published by the Free Software Foundation. 15 + * 16 + * This program is distributed in the hope that it will be useful, but 17 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 + * for more details. 20 + */ 21 + 22 + #include <linux/usb.h> 23 + #include <linux/usb/ch11.h> 24 + #include <linux/usb/hcd.h> 25 + #include "usb.h" 26 + 27 + struct usb_hub { 28 + struct device *intfdev; /* the "interface" device */ 29 + struct usb_device *hdev; 30 + struct kref kref; 31 + struct urb *urb; /* for interrupt polling pipe */ 32 + 33 + /* buffer for urb ... with extra space in case of babble */ 34 + u8 (*buffer)[8]; 35 + union { 36 + struct usb_hub_status hub; 37 + struct usb_port_status port; 38 + } *status; /* buffer for status reports */ 39 + struct mutex status_mutex; /* for the status buffer */ 40 + 41 + int error; /* last reported error */ 42 + int nerrors; /* track consecutive errors */ 43 + 44 + struct list_head event_list; /* hubs w/data or errs ready */ 45 + unsigned long event_bits[1]; /* status change bitmask */ 46 + unsigned long change_bits[1]; /* ports with logical connect 47 + status change */ 48 + unsigned long busy_bits[1]; /* ports being reset or 49 + resumed */ 50 + unsigned long removed_bits[1]; /* ports with a "removed" 51 + device present */ 52 + unsigned long wakeup_bits[1]; /* ports that have signaled 53 + remote wakeup */ 54 + #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ 55 + #error event_bits[] is too short! 56 + #endif 57 + 58 + struct usb_hub_descriptor *descriptor; /* class descriptor */ 59 + struct usb_tt tt; /* Transaction Translator */ 60 + 61 + unsigned mA_per_port; /* current for each child */ 62 + 63 + unsigned limited_power:1; 64 + unsigned quiescing:1; 65 + unsigned disconnected:1; 66 + 67 + unsigned quirk_check_port_auto_suspend:1; 68 + 69 + unsigned has_indicators:1; 70 + u8 indicator[USB_MAXCHILDREN]; 71 + struct delayed_work leds; 72 + struct delayed_work init_work; 73 + struct usb_port **ports; 74 + }; 75 + 76 + /** 77 + * struct usb port - kernel's representation of a usb port 78 + * @child: usb device attatched to the port 79 + * @dev: generic device interface 80 + * @port_owner: port's owner 81 + * @connect_type: port's connect type 82 + * @portnum: port index num based one 83 + * @power_is_on: port's power state 84 + * @did_runtime_put: port has done pm_runtime_put(). 85 + */ 86 + struct usb_port { 87 + struct usb_device *child; 88 + struct device dev; 89 + struct dev_state *port_owner; 90 + enum usb_port_connect_type connect_type; 91 + u8 portnum; 92 + unsigned power_is_on:1; 93 + unsigned did_runtime_put:1; 94 + }; 95 + 96 + #define to_usb_port(_dev) \ 97 + container_of(_dev, struct usb_port, dev) 98 + 99 + extern int usb_hub_create_port_device(struct usb_hub *hub, 100 + int port1); 101 + extern void usb_hub_remove_port_device(struct usb_hub *hub, 102 + int port1); 103 + extern int usb_hub_set_port_power(struct usb_device *hdev, 104 + int port1, bool set); 105 + extern struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev); 106 + extern int hub_port_debounce(struct usb_hub *hub, int port1, 107 + bool must_be_connected); 108 + extern int usb_clear_port_feature(struct usb_device *hdev, 109 + int port1, int feature); 110 + 111 + static inline int hub_port_debounce_be_connected(struct usb_hub *hub, 112 + int port1) 113 + { 114 + return hub_port_debounce(hub, port1, true); 115 + } 116 + 117 + static inline int hub_port_debounce_be_stable(struct usb_hub *hub, 118 + int port1) 119 + { 120 + return hub_port_debounce(hub, port1, false); 121 + } 122 +
+1 -1
drivers/usb/core/message.c
··· 1751 1751 } 1752 1752 } 1753 1753 1754 - i = dev->bus_mA - cp->desc.bMaxPower * 2; 1754 + i = dev->bus_mA - usb_get_max_power(dev, cp); 1755 1755 if (i < 0) 1756 1756 dev_warn(&dev->dev, "new config #%d exceeds power " 1757 1757 "limit by %dmA\n",
+202
drivers/usb/core/port.c
··· 1 + /* 2 + * usb port device code 3 + * 4 + * Copyright (C) 2012 Intel Corp 5 + * 6 + * Author: Lan Tianyu <tianyu.lan@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 + * This program is distributed in the hope that it will be useful, but 13 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 + * for more details. 16 + * 17 + */ 18 + 19 + #include <linux/slab.h> 20 + #include <linux/pm_qos.h> 21 + 22 + #include "hub.h" 23 + 24 + static const struct attribute_group *port_dev_group[]; 25 + 26 + static ssize_t show_port_connect_type(struct device *dev, 27 + struct device_attribute *attr, char *buf) 28 + { 29 + struct usb_port *port_dev = to_usb_port(dev); 30 + char *result; 31 + 32 + switch (port_dev->connect_type) { 33 + case USB_PORT_CONNECT_TYPE_HOT_PLUG: 34 + result = "hotplug"; 35 + break; 36 + case USB_PORT_CONNECT_TYPE_HARD_WIRED: 37 + result = "hardwired"; 38 + break; 39 + case USB_PORT_NOT_USED: 40 + result = "not used"; 41 + break; 42 + default: 43 + result = "unknown"; 44 + break; 45 + } 46 + 47 + return sprintf(buf, "%s\n", result); 48 + } 49 + static DEVICE_ATTR(connect_type, S_IRUGO, show_port_connect_type, 50 + NULL); 51 + 52 + static struct attribute *port_dev_attrs[] = { 53 + &dev_attr_connect_type.attr, 54 + NULL, 55 + }; 56 + 57 + static struct attribute_group port_dev_attr_grp = { 58 + .attrs = port_dev_attrs, 59 + }; 60 + 61 + static const struct attribute_group *port_dev_group[] = { 62 + &port_dev_attr_grp, 63 + NULL, 64 + }; 65 + 66 + static void usb_port_device_release(struct device *dev) 67 + { 68 + struct usb_port *port_dev = to_usb_port(dev); 69 + 70 + dev_pm_qos_hide_flags(dev); 71 + kfree(port_dev); 72 + } 73 + 74 + #ifdef CONFIG_USB_SUSPEND 75 + static int usb_port_runtime_resume(struct device *dev) 76 + { 77 + struct usb_port *port_dev = to_usb_port(dev); 78 + struct usb_device *hdev = to_usb_device(dev->parent->parent); 79 + struct usb_interface *intf = to_usb_interface(dev->parent); 80 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 81 + int port1 = port_dev->portnum; 82 + int retval; 83 + 84 + if (!hub) 85 + return -EINVAL; 86 + 87 + usb_autopm_get_interface(intf); 88 + set_bit(port1, hub->busy_bits); 89 + 90 + retval = usb_hub_set_port_power(hdev, port1, true); 91 + if (port_dev->child && !retval) { 92 + /* 93 + * Wait for usb hub port to be reconnected in order to make 94 + * the resume procedure successful. 95 + */ 96 + retval = hub_port_debounce_be_connected(hub, port1); 97 + if (retval < 0) { 98 + dev_dbg(&port_dev->dev, "can't get reconnection after setting port power on, status %d\n", 99 + retval); 100 + goto out; 101 + } 102 + usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_ENABLE); 103 + 104 + /* Set return value to 0 if debounce successful */ 105 + retval = 0; 106 + } 107 + 108 + out: 109 + clear_bit(port1, hub->busy_bits); 110 + usb_autopm_put_interface(intf); 111 + return retval; 112 + } 113 + 114 + static int usb_port_runtime_suspend(struct device *dev) 115 + { 116 + struct usb_port *port_dev = to_usb_port(dev); 117 + struct usb_device *hdev = to_usb_device(dev->parent->parent); 118 + struct usb_interface *intf = to_usb_interface(dev->parent); 119 + struct usb_hub *hub = usb_hub_to_struct_hub(hdev); 120 + int port1 = port_dev->portnum; 121 + int retval; 122 + 123 + if (!hub) 124 + return -EINVAL; 125 + 126 + if (dev_pm_qos_flags(&port_dev->dev, PM_QOS_FLAG_NO_POWER_OFF) 127 + == PM_QOS_FLAGS_ALL) 128 + return -EAGAIN; 129 + 130 + usb_autopm_get_interface(intf); 131 + set_bit(port1, hub->busy_bits); 132 + retval = usb_hub_set_port_power(hdev, port1, false); 133 + usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_CONNECTION); 134 + usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_ENABLE); 135 + clear_bit(port1, hub->busy_bits); 136 + usb_autopm_put_interface(intf); 137 + return retval; 138 + } 139 + #endif 140 + 141 + static const struct dev_pm_ops usb_port_pm_ops = { 142 + #ifdef CONFIG_USB_SUSPEND 143 + .runtime_suspend = usb_port_runtime_suspend, 144 + .runtime_resume = usb_port_runtime_resume, 145 + .runtime_idle = pm_generic_runtime_idle, 146 + #endif 147 + }; 148 + 149 + struct device_type usb_port_device_type = { 150 + .name = "usb_port", 151 + .release = usb_port_device_release, 152 + .pm = &usb_port_pm_ops, 153 + }; 154 + 155 + int usb_hub_create_port_device(struct usb_hub *hub, int port1) 156 + { 157 + struct usb_port *port_dev = NULL; 158 + int retval; 159 + 160 + port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL); 161 + if (!port_dev) { 162 + retval = -ENOMEM; 163 + goto exit; 164 + } 165 + 166 + hub->ports[port1 - 1] = port_dev; 167 + port_dev->portnum = port1; 168 + port_dev->power_is_on = true; 169 + port_dev->dev.parent = hub->intfdev; 170 + port_dev->dev.groups = port_dev_group; 171 + port_dev->dev.type = &usb_port_device_type; 172 + dev_set_name(&port_dev->dev, "port%d", port1); 173 + 174 + retval = device_register(&port_dev->dev); 175 + if (retval) 176 + goto error_register; 177 + 178 + pm_runtime_set_active(&port_dev->dev); 179 + 180 + /* It would be dangerous if user space couldn't 181 + * prevent usb device from being powered off. So don't 182 + * enable port runtime pm if failed to expose port's pm qos. 183 + */ 184 + if (!dev_pm_qos_expose_flags(&port_dev->dev, 185 + PM_QOS_FLAG_NO_POWER_OFF)) 186 + pm_runtime_enable(&port_dev->dev); 187 + 188 + device_enable_async_suspend(&port_dev->dev); 189 + return 0; 190 + 191 + error_register: 192 + put_device(&port_dev->dev); 193 + exit: 194 + return retval; 195 + } 196 + 197 + void usb_hub_remove_port_device(struct usb_hub *hub, 198 + int port1) 199 + { 200 + device_unregister(&hub->ports[port1 - 1]->dev); 201 + } 202 +
+22 -9
drivers/usb/core/sysfs.c
··· 17 17 #include "usb.h" 18 18 19 19 /* Active configuration fields */ 20 - #define usb_actconfig_show(field, multiplier, format_string) \ 20 + #define usb_actconfig_show(field, format_string) \ 21 21 static ssize_t show_##field(struct device *dev, \ 22 22 struct device_attribute *attr, char *buf) \ 23 23 { \ ··· 28 28 actconfig = udev->actconfig; \ 29 29 if (actconfig) \ 30 30 return sprintf(buf, format_string, \ 31 - actconfig->desc.field * multiplier); \ 31 + actconfig->desc.field); \ 32 32 else \ 33 33 return 0; \ 34 34 } \ 35 35 36 - #define usb_actconfig_attr(field, multiplier, format_string) \ 37 - usb_actconfig_show(field, multiplier, format_string) \ 38 - static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL); 36 + #define usb_actconfig_attr(field, format_string) \ 37 + usb_actconfig_show(field, format_string) \ 38 + static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL); 39 39 40 - usb_actconfig_attr(bNumInterfaces, 1, "%2d\n") 41 - usb_actconfig_attr(bmAttributes, 1, "%2x\n") 42 - usb_actconfig_attr(bMaxPower, 2, "%3dmA\n") 40 + usb_actconfig_attr(bNumInterfaces, "%2d\n") 41 + usb_actconfig_attr(bmAttributes, "%2x\n") 42 + 43 + static ssize_t show_bMaxPower(struct device *dev, 44 + struct device_attribute *attr, char *buf) 45 + { 46 + struct usb_device *udev; 47 + struct usb_host_config *actconfig; 48 + 49 + udev = to_usb_device(dev); 50 + actconfig = udev->actconfig; 51 + if (!actconfig) 52 + return 0; 53 + return sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig)); 54 + } 55 + static DEVICE_ATTR(bMaxPower, S_IRUGO, show_bMaxPower, NULL); 43 56 44 57 static ssize_t show_configuration_string(struct device *dev, 45 58 struct device_attribute *attr, char *buf) ··· 69 56 static DEVICE_ATTR(configuration, S_IRUGO, show_configuration_string, NULL); 70 57 71 58 /* configuration value is always present, and r/w */ 72 - usb_actconfig_show(bConfigurationValue, 1, "%u\n"); 59 + usb_actconfig_show(bConfigurationValue, "%u\n"); 73 60 74 61 static ssize_t 75 62 set_bConfigurationValue(struct device *dev, struct device_attribute *attr,
+12
drivers/usb/core/usb.h
··· 1 1 #include <linux/pm.h> 2 2 #include <linux/acpi.h> 3 3 4 + struct usb_hub_descriptor; 4 5 struct dev_state; 5 6 6 7 /* Functions local to drivers/usb/core/ */ ··· 38 37 extern char *usb_cache_string(struct usb_device *udev, int index); 39 38 extern int usb_set_configuration(struct usb_device *dev, int configuration); 40 39 extern int usb_choose_configuration(struct usb_device *udev); 40 + 41 + static inline unsigned usb_get_max_power(struct usb_device *udev, 42 + struct usb_host_config *c) 43 + { 44 + /* SuperSpeed power is in 8 mA units; others are in 2 mA units */ 45 + unsigned mul = (udev->speed == USB_SPEED_SUPER ? 8 : 2); 46 + 47 + return c->desc.bMaxPower * mul; 48 + } 41 49 42 50 extern void usb_kick_khubd(struct usb_device *dev); 43 51 extern int usb_match_one_id_intf(struct usb_device *dev, ··· 183 173 usb_get_hub_port_connect_type(struct usb_device *hdev, int port1); 184 174 extern void usb_set_hub_port_connect_type(struct usb_device *hdev, int port1, 185 175 enum usb_port_connect_type type); 176 + extern void usb_hub_adjust_deviceremovable(struct usb_device *hdev, 177 + struct usb_hub_descriptor *desc); 186 178 187 179 #ifdef CONFIG_ACPI 188 180 extern int usb_acpi_register(void);
+30 -1
drivers/usb/dwc3/Kconfig
··· 1 1 config USB_DWC3 2 2 tristate "DesignWare USB3 DRD Core Support" 3 - depends on (USB && USB_GADGET) 3 + depends on (USB || USB_GADGET) && GENERIC_HARDIRQS 4 4 select USB_OTG_UTILS 5 5 select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD 6 6 help ··· 11 11 module, the module will be called dwc3.ko. 12 12 13 13 if USB_DWC3 14 + 15 + choice 16 + bool "DWC3 Mode Selection" 17 + default USB_DWC3_DUAL_ROLE if (USB && USB_GADGET) 18 + default USB_DWC3_HOST if (USB && !USB_GADGET) 19 + default USB_DWC3_GADGET if (!USB && USB_GADGET) 20 + 21 + config USB_DWC3_HOST 22 + bool "Host only mode" 23 + depends on USB 24 + help 25 + Select this when you want to use DWC3 in host mode only, 26 + thereby the gadget feature will be regressed. 27 + 28 + config USB_DWC3_GADGET 29 + bool "Gadget only mode" 30 + depends on USB_GADGET 31 + help 32 + Select this when you want to use DWC3 in gadget mode only, 33 + thereby the host feature will be regressed. 34 + 35 + config USB_DWC3_DUAL_ROLE 36 + bool "Dual Role mode" 37 + depends on (USB && USB_GADGET) 38 + help 39 + This is the default mode of working of DWC3 controller where 40 + both host and gadget features are enabled. 41 + 42 + endchoice 14 43 15 44 config USB_DWC3_DEBUG 16 45 bool "Enable Debugging Messages"
+8 -2
drivers/usb/dwc3/Makefile
··· 4 4 obj-$(CONFIG_USB_DWC3) += dwc3.o 5 5 6 6 dwc3-y := core.o 7 - dwc3-y += host.o 8 - dwc3-y += gadget.o ep0.o 7 + 8 + ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST) $(CONFIG_USB_DWC3_DUAL_ROLE)),) 9 + dwc3-y += host.o 10 + endif 11 + 12 + ifneq ($(filter y,$(CONFIG_USB_DWC3_GADGET) $(CONFIG_USB_DWC3_DUAL_ROLE)),) 13 + dwc3-y += gadget.o ep0.o 14 + endif 9 15 10 16 ifneq ($(CONFIG_DEBUG_FS),) 11 17 dwc3-y += debugfs.o
+25 -6
drivers/usb/dwc3/core.c
··· 420 420 return -ENOMEM; 421 421 } 422 422 423 - dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 423 + if (node) { 424 + dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); 425 + dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); 426 + } else { 427 + dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 428 + dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); 429 + } 430 + 424 431 if (IS_ERR_OR_NULL(dwc->usb2_phy)) { 425 432 dev_err(dev, "no usb2 phy configured\n"); 426 433 return -EPROBE_DEFER; 427 434 } 428 435 429 - dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); 430 436 if (IS_ERR_OR_NULL(dwc->usb3_phy)) { 431 437 dev_err(dev, "no usb3 phy configured\n"); 432 438 return -EPROBE_DEFER; 433 439 } 440 + 441 + usb_phy_set_suspend(dwc->usb2_phy, 0); 442 + usb_phy_set_suspend(dwc->usb3_phy, 0); 434 443 435 444 spin_lock_init(&dwc->lock); 436 445 platform_set_drvdata(pdev, dwc); ··· 459 450 else 460 451 dwc->maximum_speed = DWC3_DCFG_SUPERSPEED; 461 452 462 - if (of_get_property(node, "tx-fifo-resize", NULL)) 463 - dwc->needs_fifo_resize = true; 453 + dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize"); 464 454 465 455 pm_runtime_enable(dev); 466 456 pm_runtime_get_sync(dev); ··· 558 550 static int dwc3_remove(struct platform_device *pdev) 559 551 { 560 552 struct dwc3 *dwc = platform_get_drvdata(pdev); 561 - struct resource *res; 562 553 563 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 554 + usb_phy_set_suspend(dwc->usb2_phy, 1); 555 + usb_phy_set_suspend(dwc->usb3_phy, 1); 564 556 565 557 pm_runtime_put(&pdev->dev); 566 558 pm_runtime_disable(&pdev->dev); ··· 588 580 return 0; 589 581 } 590 582 583 + #ifdef CONFIG_OF 584 + static const struct of_device_id of_dwc3_match[] = { 585 + { 586 + .compatible = "synopsys,dwc3" 587 + }, 588 + { }, 589 + }; 590 + MODULE_DEVICE_TABLE(of, of_dwc3_match); 591 + #endif 592 + 591 593 static struct platform_driver dwc3_driver = { 592 594 .probe = dwc3_probe, 593 595 .remove = dwc3_remove, 594 596 .driver = { 595 597 .name = "dwc3", 598 + .of_match_table = of_match_ptr(of_dwc3_match), 596 599 }, 597 600 }; 598 601
+19 -3
drivers/usb/dwc3/core.h
··· 55 55 #define DWC3_ENDPOINTS_NUM 32 56 56 #define DWC3_XHCI_RESOURCES_NUM 2 57 57 58 - #define DWC3_EVENT_BUFFERS_SIZE PAGE_SIZE 58 + #define DWC3_EVENT_SIZE 4 /* bytes */ 59 + #define DWC3_EVENT_MAX_NUM 64 /* 2 events/endpoint */ 60 + #define DWC3_EVENT_BUFFERS_SIZE (DWC3_EVENT_SIZE * DWC3_EVENT_MAX_NUM) 59 61 #define DWC3_EVENT_TYPE_MASK 0xfe 60 62 61 63 #define DWC3_EVENT_TYPE_DEV 0 ··· 407 405 * @number: endpoint number (1 - 15) 408 406 * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK 409 407 * @resource_index: Resource transfer index 410 - * @current_uf: Current uf received through last event parameter 411 408 * @interval: the intervall on which the ISOC transfer is started 412 409 * @name: a human readable name e.g. ep1out-bulk 413 410 * @direction: true for TX, false for RX ··· 440 439 u8 number; 441 440 u8 type; 442 441 u8 resource_index; 443 - u16 current_uf; 444 442 u32 interval; 445 443 446 444 char name[20]; ··· 581 581 struct usb_request request; 582 582 struct list_head list; 583 583 struct dwc3_ep *dep; 584 + u32 start_slot; 584 585 585 586 u8 epnum; 586 587 struct dwc3_trb *trb; ··· 722 721 723 722 struct dwc3_hwparams hwparams; 724 723 struct dentry *root; 724 + struct debugfs_regset32 *regset; 725 725 726 726 u8 test_mode; 727 727 u8 test_mode_nr; ··· 864 862 void dwc3_set_mode(struct dwc3 *dwc, u32 mode); 865 863 int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc); 866 864 865 + #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) 867 866 int dwc3_host_init(struct dwc3 *dwc); 868 867 void dwc3_host_exit(struct dwc3 *dwc); 868 + #else 869 + static inline int dwc3_host_init(struct dwc3 *dwc) 870 + { return 0; } 871 + static inline void dwc3_host_exit(struct dwc3 *dwc) 872 + { } 873 + #endif 869 874 875 + #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) 870 876 int dwc3_gadget_init(struct dwc3 *dwc); 871 877 void dwc3_gadget_exit(struct dwc3 *dwc); 878 + #else 879 + static inline int dwc3_gadget_init(struct dwc3 *dwc) 880 + { return 0; } 881 + static inline void dwc3_gadget_exit(struct dwc3 *dwc) 882 + { } 883 + #endif 872 884 873 885 #endif /* __DRIVERS_USB_DWC3_CORE_H */
+14 -24
drivers/usb/dwc3/debugfs.c
··· 59 59 .offset = DWC3_ ##nm - DWC3_GLOBALS_REGS_START, \ 60 60 } 61 61 62 - static const struct debugfs_reg32 dwc3_regs[] = { 62 + static struct debugfs_reg32 dwc3_regs[] = { 63 63 dump_register(GSBUSCFG0), 64 64 dump_register(GSBUSCFG1), 65 65 dump_register(GTXTHRCFG), ··· 376 376 dump_register(OSTS), 377 377 }; 378 378 379 - static int dwc3_regdump_show(struct seq_file *s, void *unused) 380 - { 381 - struct dwc3 *dwc = s->private; 382 - 383 - seq_printf(s, "DesignWare USB3 Core Register Dump\n"); 384 - debugfs_print_regs32(s, dwc3_regs, ARRAY_SIZE(dwc3_regs), 385 - dwc->regs, ""); 386 - return 0; 387 - } 388 - 389 - static int dwc3_regdump_open(struct inode *inode, struct file *file) 390 - { 391 - return single_open(file, dwc3_regdump_show, inode->i_private); 392 - } 393 - 394 - static const struct file_operations dwc3_regdump_fops = { 395 - .open = dwc3_regdump_open, 396 - .read = seq_read, 397 - .release = single_release, 398 - }; 399 - 400 379 static int dwc3_mode_show(struct seq_file *s, void *unused) 401 380 { 402 381 struct dwc3 *dwc = s->private; ··· 645 666 646 667 dwc->root = root; 647 668 648 - file = debugfs_create_file("regdump", S_IRUGO, root, dwc, 649 - &dwc3_regdump_fops); 669 + dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL); 670 + if (!dwc->regset) { 671 + ret = -ENOMEM; 672 + goto err1; 673 + } 674 + 675 + dwc->regset->regs = dwc3_regs; 676 + dwc->regset->nregs = ARRAY_SIZE(dwc3_regs); 677 + dwc->regset->base = dwc->regs; 678 + 679 + file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset); 650 680 if (!file) { 651 681 ret = -ENOMEM; 652 682 goto err1; 653 683 } 654 684 685 + #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) 655 686 file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root, 656 687 dwc, &dwc3_mode_fops); 657 688 if (!file) { ··· 682 693 ret = -ENOMEM; 683 694 goto err1; 684 695 } 696 + #endif 685 697 686 698 return 0; 687 699
+29 -34
drivers/usb/dwc3/dwc3-exynos.c
··· 42 42 43 43 memset(&pdata, 0x00, sizeof(pdata)); 44 44 45 - pdev = platform_device_alloc("nop_usb_xceiv", 0); 45 + pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO); 46 46 if (!pdev) 47 47 return -ENOMEM; 48 48 ··· 53 53 if (ret) 54 54 goto err1; 55 55 56 - pdev = platform_device_alloc("nop_usb_xceiv", 1); 56 + pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO); 57 57 if (!pdev) { 58 58 ret = -ENOMEM; 59 59 goto err1; ··· 95 95 struct platform_device *dwc3; 96 96 struct dwc3_exynos *exynos; 97 97 struct clk *clk; 98 + struct device *dev = &pdev->dev; 98 99 99 100 int ret = -ENOMEM; 100 101 101 - exynos = kzalloc(sizeof(*exynos), GFP_KERNEL); 102 + exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); 102 103 if (!exynos) { 103 - dev_err(&pdev->dev, "not enough memory\n"); 104 - goto err0; 104 + dev_err(dev, "not enough memory\n"); 105 + return -ENOMEM; 105 106 } 106 107 107 108 /* ··· 117 116 118 117 ret = dwc3_exynos_register_phys(exynos); 119 118 if (ret) { 120 - dev_err(&pdev->dev, "couldn't register PHYs\n"); 121 - goto err1; 119 + dev_err(dev, "couldn't register PHYs\n"); 120 + return ret; 122 121 } 123 122 124 123 dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); 125 124 if (!dwc3) { 126 - dev_err(&pdev->dev, "couldn't allocate dwc3 device\n"); 125 + dev_err(dev, "couldn't allocate dwc3 device\n"); 126 + return -ENOMEM; 127 + } 128 + 129 + clk = devm_clk_get(dev, "usbdrd30"); 130 + if (IS_ERR(clk)) { 131 + dev_err(dev, "couldn't get clock\n"); 132 + ret = -EINVAL; 127 133 goto err1; 128 134 } 129 135 130 - clk = clk_get(&pdev->dev, "usbdrd30"); 131 - if (IS_ERR(clk)) { 132 - dev_err(&pdev->dev, "couldn't get clock\n"); 133 - ret = -EINVAL; 134 - goto err3; 135 - } 136 + dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask); 136 137 137 - dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask); 138 - 139 - dwc3->dev.parent = &pdev->dev; 140 - dwc3->dev.dma_mask = pdev->dev.dma_mask; 141 - dwc3->dev.dma_parms = pdev->dev.dma_parms; 138 + dwc3->dev.parent = dev; 139 + dwc3->dev.dma_mask = dev->dma_mask; 140 + dwc3->dev.dma_parms = dev->dma_parms; 142 141 exynos->dwc3 = dwc3; 143 - exynos->dev = &pdev->dev; 142 + exynos->dev = dev; 144 143 exynos->clk = clk; 145 144 146 145 clk_enable(exynos->clk); ··· 148 147 ret = platform_device_add_resources(dwc3, pdev->resource, 149 148 pdev->num_resources); 150 149 if (ret) { 151 - dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n"); 152 - goto err4; 150 + dev_err(dev, "couldn't add resources to dwc3 device\n"); 151 + goto err2; 153 152 } 154 153 155 154 ret = platform_device_add(dwc3); 156 155 if (ret) { 157 - dev_err(&pdev->dev, "failed to register dwc3 device\n"); 158 - goto err4; 156 + dev_err(dev, "failed to register dwc3 device\n"); 157 + goto err2; 159 158 } 160 159 161 160 return 0; 162 161 163 - err4: 162 + err2: 164 163 clk_disable(clk); 165 - clk_put(clk); 166 - err3: 167 - platform_device_put(dwc3); 168 164 err1: 169 - kfree(exynos); 170 - err0: 165 + platform_device_put(dwc3); 166 + 171 167 return ret; 172 168 } 173 169 ··· 177 179 platform_device_unregister(exynos->usb3_phy); 178 180 179 181 clk_disable(exynos->clk); 180 - clk_put(exynos->clk); 181 - 182 - kfree(exynos); 183 182 184 183 return 0; 185 184 } 186 185 187 186 #ifdef CONFIG_OF 188 187 static const struct of_device_id exynos_dwc3_match[] = { 189 - { .compatible = "samsung,exynos-dwc3" }, 188 + { .compatible = "samsung,exynos5250-dwusb3" }, 190 189 {}, 191 190 }; 192 191 MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
+93 -59
drivers/usb/dwc3/dwc3-omap.c
··· 43 43 #include <linux/spinlock.h> 44 44 #include <linux/platform_device.h> 45 45 #include <linux/platform_data/dwc3-omap.h> 46 + #include <linux/usb/dwc3-omap.h> 47 + #include <linux/pm_runtime.h> 46 48 #include <linux/dma-mapping.h> 47 49 #include <linux/ioport.h> 48 50 #include <linux/io.h> 49 51 #include <linux/of.h> 52 + #include <linux/of_platform.h> 50 53 51 54 #include <linux/usb/otg.h> 52 55 #include <linux/usb/nop-usb-xceiv.h> ··· 81 78 82 79 /* SYSCONFIG REGISTER */ 83 80 #define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16) 84 - #define USBOTGSS_SYSCONFIG_STANDBYMODE(x) ((x) << 4) 85 - 86 - #define USBOTGSS_STANDBYMODE_FORCE_STANDBY 0 87 - #define USBOTGSS_STANDBYMODE_NO_STANDBY 1 88 - #define USBOTGSS_STANDBYMODE_SMART_STANDBY 2 89 - #define USBOTGSS_STANDBYMODE_SMART_WAKEUP 3 90 - 91 - #define USBOTGSS_STANDBYMODE_MASK (0x03 << 4) 92 - 93 - #define USBOTGSS_SYSCONFIG_IDLEMODE(x) ((x) << 2) 94 - 95 - #define USBOTGSS_IDLEMODE_FORCE_IDLE 0 96 - #define USBOTGSS_IDLEMODE_NO_IDLE 1 97 - #define USBOTGSS_IDLEMODE_SMART_IDLE 2 98 - #define USBOTGSS_IDLEMODE_SMART_WAKEUP 3 99 - 100 - #define USBOTGSS_IDLEMODE_MASK (0x03 << 2) 101 81 102 82 /* IRQ_EOI REGISTER */ 103 83 #define USBOTGSS_IRQ_EOI_LINE_NUMBER (1 << 0) ··· 119 133 /* device lock */ 120 134 spinlock_t lock; 121 135 122 - struct platform_device *dwc3; 123 136 struct platform_device *usb2_phy; 124 137 struct platform_device *usb3_phy; 125 138 struct device *dev; ··· 132 147 u32 dma_status:1; 133 148 }; 134 149 150 + struct dwc3_omap *_omap; 151 + 135 152 static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset) 136 153 { 137 154 return readl(base + offset); ··· 144 157 writel(value, base + offset); 145 158 } 146 159 160 + void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status) 161 + { 162 + u32 val; 163 + struct dwc3_omap *omap = _omap; 164 + 165 + switch (status) { 166 + case OMAP_DWC3_ID_GROUND: 167 + dev_dbg(omap->dev, "ID GND\n"); 168 + 169 + val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 170 + val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG 171 + | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID 172 + | USBOTGSS_UTMI_OTG_STATUS_SESSEND); 173 + val |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID 174 + | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; 175 + dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); 176 + break; 177 + 178 + case OMAP_DWC3_VBUS_VALID: 179 + dev_dbg(omap->dev, "VBUS Connect\n"); 180 + 181 + val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 182 + val &= ~USBOTGSS_UTMI_OTG_STATUS_SESSEND; 183 + val |= USBOTGSS_UTMI_OTG_STATUS_IDDIG 184 + | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID 185 + | USBOTGSS_UTMI_OTG_STATUS_SESSVALID 186 + | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; 187 + dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); 188 + break; 189 + 190 + case OMAP_DWC3_ID_FLOAT: 191 + case OMAP_DWC3_VBUS_OFF: 192 + dev_dbg(omap->dev, "VBUS Disconnect\n"); 193 + 194 + val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 195 + val &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSVALID 196 + | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID 197 + | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT); 198 + val |= USBOTGSS_UTMI_OTG_STATUS_SESSEND 199 + | USBOTGSS_UTMI_OTG_STATUS_IDDIG; 200 + dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); 201 + break; 202 + 203 + default: 204 + dev_dbg(omap->dev, "ID float\n"); 205 + } 206 + 207 + return; 208 + } 209 + EXPORT_SYMBOL_GPL(dwc3_omap_mailbox); 210 + 147 211 static int dwc3_omap_register_phys(struct dwc3_omap *omap) 148 212 { 149 213 struct nop_usb_xceiv_platform_data pdata; ··· 203 165 204 166 memset(&pdata, 0x00, sizeof(pdata)); 205 167 206 - pdev = platform_device_alloc("nop_usb_xceiv", 0); 168 + pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO); 207 169 if (!pdev) 208 170 return -ENOMEM; 209 171 ··· 214 176 if (ret) 215 177 goto err1; 216 178 217 - pdev = platform_device_alloc("nop_usb_xceiv", 1); 179 + pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO); 218 180 if (!pdev) { 219 181 ret = -ENOMEM; 220 182 goto err1; ··· 300 262 return IRQ_HANDLED; 301 263 } 302 264 265 + static int dwc3_omap_remove_core(struct device *dev, void *c) 266 + { 267 + struct platform_device *pdev = to_platform_device(dev); 268 + 269 + platform_device_unregister(pdev); 270 + 271 + return 0; 272 + } 273 + 303 274 static int dwc3_omap_probe(struct platform_device *pdev) 304 275 { 305 276 struct dwc3_omap_data *pdata = pdev->dev.platform_data; 306 277 struct device_node *node = pdev->dev.of_node; 307 278 308 - struct platform_device *dwc3; 309 279 struct dwc3_omap *omap; 310 280 struct resource *res; 311 281 struct device *dev = &pdev->dev; ··· 360 314 return ret; 361 315 } 362 316 363 - dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); 364 - if (!dwc3) { 365 - dev_err(dev, "couldn't allocate dwc3 device\n"); 366 - return -ENOMEM; 367 - } 368 - 369 317 context = devm_kzalloc(dev, resource_size(res), GFP_KERNEL); 370 318 if (!context) { 371 319 dev_err(dev, "couldn't allocate dwc3 context memory\n"); 372 - goto err2; 320 + return -ENOMEM; 373 321 } 374 322 375 323 spin_lock_init(&omap->lock); 376 - dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask); 377 324 378 - dwc3->dev.parent = dev; 379 - dwc3->dev.dma_mask = dev->dma_mask; 380 - dwc3->dev.dma_parms = dev->dma_parms; 381 325 omap->resource_size = resource_size(res); 382 326 omap->context = context; 383 327 omap->dev = dev; 384 328 omap->irq = irq; 385 329 omap->base = base; 386 - omap->dwc3 = dwc3; 330 + 331 + /* 332 + * REVISIT if we ever have two instances of the wrapper, we will be 333 + * in big trouble 334 + */ 335 + _omap = omap; 336 + 337 + pm_runtime_enable(dev); 338 + ret = pm_runtime_get_sync(dev); 339 + if (ret < 0) { 340 + dev_err(dev, "get_sync failed with err %d\n", ret); 341 + return ret; 342 + } 387 343 388 344 reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 389 345 ··· 416 368 reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); 417 369 omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE); 418 370 419 - /* Set No-Idle and No-Standby */ 420 - reg &= ~(USBOTGSS_STANDBYMODE_MASK 421 - | USBOTGSS_IDLEMODE_MASK); 422 - 423 - reg |= (USBOTGSS_SYSCONFIG_STANDBYMODE(USBOTGSS_STANDBYMODE_NO_STANDBY) 424 - | USBOTGSS_SYSCONFIG_IDLEMODE(USBOTGSS_IDLEMODE_NO_IDLE)); 425 - 426 - dwc3_omap_writel(omap->base, USBOTGSS_SYSCONFIG, reg); 427 - 428 371 ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0, 429 372 "dwc3-omap", omap); 430 373 if (ret) { 431 374 dev_err(dev, "failed to request IRQ #%d --> %d\n", 432 375 omap->irq, ret); 433 - goto err2; 376 + return ret; 434 377 } 435 378 436 379 /* enable all IRQs */ ··· 440 401 441 402 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg); 442 403 443 - ret = platform_device_add_resources(dwc3, pdev->resource, 444 - pdev->num_resources); 445 - if (ret) { 446 - dev_err(dev, "couldn't add resources to dwc3 device\n"); 447 - goto err2; 448 - } 449 - 450 - ret = platform_device_add(dwc3); 451 - if (ret) { 452 - dev_err(dev, "failed to register dwc3 device\n"); 453 - goto err2; 404 + if (node) { 405 + ret = of_platform_populate(node, NULL, NULL, dev); 406 + if (ret) { 407 + dev_err(&pdev->dev, 408 + "failed to add create dwc3 core\n"); 409 + return ret; 410 + } 454 411 } 455 412 456 413 return 0; 457 - 458 - err2: 459 - platform_device_put(dwc3); 460 - return ret; 461 414 } 462 415 463 416 static int dwc3_omap_remove(struct platform_device *pdev) 464 417 { 465 418 struct dwc3_omap *omap = platform_get_drvdata(pdev); 466 419 467 - platform_device_unregister(omap->dwc3); 468 420 platform_device_unregister(omap->usb2_phy); 469 421 platform_device_unregister(omap->usb3_phy); 422 + pm_runtime_put_sync(&pdev->dev); 423 + pm_runtime_disable(&pdev->dev); 424 + device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core); 425 + 470 426 return 0; 471 427 } 472 428
+180 -114
drivers/usb/dwc3/gadget.c
··· 241 241 int status) 242 242 { 243 243 struct dwc3 *dwc = dep->dwc; 244 + int i; 244 245 245 246 if (req->queued) { 246 - if (req->request.num_mapped_sgs) 247 - dep->busy_slot += req->request.num_mapped_sgs; 248 - else 247 + i = 0; 248 + do { 249 249 dep->busy_slot++; 250 - 251 - /* 252 - * Skip LINK TRB. We can't use req->trb and check for 253 - * DWC3_TRBCTL_LINK_TRB because it points the TRB we just 254 - * completed (not the LINK TRB). 255 - */ 256 - if (((dep->busy_slot & DWC3_TRB_MASK) == DWC3_TRB_NUM - 1) && 250 + /* 251 + * Skip LINK TRB. We can't use req->trb and check for 252 + * DWC3_TRBCTL_LINK_TRB because it points the TRB we 253 + * just completed (not the LINK TRB). 254 + */ 255 + if (((dep->busy_slot & DWC3_TRB_MASK) == 256 + DWC3_TRB_NUM- 1) && 257 257 usb_endpoint_xfer_isoc(dep->endpoint.desc)) 258 - dep->busy_slot++; 258 + dep->busy_slot++; 259 + } while(++i < req->request.num_mapped_sgs); 260 + req->queued = false; 259 261 } 260 262 list_del(&req->list); 261 263 req->trb = NULL; ··· 751 749 */ 752 750 static void dwc3_prepare_one_trb(struct dwc3_ep *dep, 753 751 struct dwc3_request *req, dma_addr_t dma, 754 - unsigned length, unsigned last, unsigned chain) 752 + unsigned length, unsigned last, unsigned chain, unsigned node) 755 753 { 756 754 struct dwc3 *dwc = dep->dwc; 757 755 struct dwc3_trb *trb; 758 - 759 - unsigned int cur_slot; 760 756 761 757 dev_vdbg(dwc->dev, "%s: req %p dma %08llx length %d%s%s\n", 762 758 dep->name, req, (unsigned long long) dma, 763 759 length, last ? " last" : "", 764 760 chain ? " chain" : ""); 765 761 766 - trb = &dep->trb_pool[dep->free_slot & DWC3_TRB_MASK]; 767 - cur_slot = dep->free_slot; 768 - dep->free_slot++; 769 - 770 762 /* Skip the LINK-TRB on ISOC */ 771 - if (((cur_slot & DWC3_TRB_MASK) == DWC3_TRB_NUM - 1) && 763 + if (((dep->free_slot & DWC3_TRB_MASK) == DWC3_TRB_NUM - 1) && 772 764 usb_endpoint_xfer_isoc(dep->endpoint.desc)) 773 - return; 765 + dep->free_slot++; 766 + 767 + trb = &dep->trb_pool[dep->free_slot & DWC3_TRB_MASK]; 774 768 775 769 if (!req->trb) { 776 770 dwc3_gadget_move_request_queued(req); 777 771 req->trb = trb; 778 772 req->trb_dma = dwc3_trb_dma_offset(dep, trb); 773 + req->start_slot = dep->free_slot & DWC3_TRB_MASK; 779 774 } 775 + 776 + dep->free_slot++; 780 777 781 778 trb->size = DWC3_TRB_SIZE_LENGTH(length); 782 779 trb->bpl = lower_32_bits(dma); ··· 787 786 break; 788 787 789 788 case USB_ENDPOINT_XFER_ISOC: 790 - trb->ctrl = DWC3_TRBCTL_ISOCHRONOUS_FIRST; 789 + if (!node) 790 + trb->ctrl = DWC3_TRBCTL_ISOCHRONOUS_FIRST; 791 + else 792 + trb->ctrl = DWC3_TRBCTL_ISOCHRONOUS; 791 793 792 - if (!req->request.no_interrupt) 794 + if (!req->request.no_interrupt && !chain) 793 795 trb->ctrl |= DWC3_TRB_CTRL_IOC; 794 796 break; 795 797 ··· 811 807 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { 812 808 trb->ctrl |= DWC3_TRB_CTRL_ISP_IMI; 813 809 trb->ctrl |= DWC3_TRB_CTRL_CSP; 814 - } else { 815 - if (chain) 816 - trb->ctrl |= DWC3_TRB_CTRL_CHN; 817 - 818 - if (last) 819 - trb->ctrl |= DWC3_TRB_CTRL_LST; 810 + } else if (last) { 811 + trb->ctrl |= DWC3_TRB_CTRL_LST; 820 812 } 813 + 814 + if (chain) 815 + trb->ctrl |= DWC3_TRB_CTRL_CHN; 821 816 822 817 if (usb_endpoint_xfer_bulk(dep->endpoint.desc) && dep->stream_capable) 823 818 trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(req->request.stream_id); ··· 888 885 list_for_each_entry_safe(req, n, &dep->request_list, list) { 889 886 unsigned length; 890 887 dma_addr_t dma; 888 + last_one = false; 891 889 892 890 if (req->request.num_mapped_sgs > 0) { 893 891 struct usb_request *request = &req->request; ··· 904 900 905 901 if (i == (request->num_mapped_sgs - 1) || 906 902 sg_is_last(s)) { 907 - last_one = true; 903 + if (list_is_last(&req->list, 904 + &dep->request_list)) 905 + last_one = true; 908 906 chain = false; 909 907 } 910 908 ··· 918 912 chain = false; 919 913 920 914 dwc3_prepare_one_trb(dep, req, dma, length, 921 - last_one, chain); 915 + last_one, chain, i); 922 916 923 917 if (last_one) 924 918 break; ··· 936 930 last_one = 1; 937 931 938 932 dwc3_prepare_one_trb(dep, req, dma, length, 939 - last_one, false); 933 + last_one, false, 0); 940 934 941 935 if (last_one) 942 936 break; ··· 983 977 } 984 978 985 979 memset(&params, 0, sizeof(params)); 986 - params.param0 = upper_32_bits(req->trb_dma); 987 - params.param1 = lower_32_bits(req->trb_dma); 988 980 989 - if (start_new) 981 + if (start_new) { 982 + params.param0 = upper_32_bits(req->trb_dma); 983 + params.param1 = lower_32_bits(req->trb_dma); 990 984 cmd = DWC3_DEPCMD_STARTTRANSFER; 991 - else 985 + } else { 992 986 cmd = DWC3_DEPCMD_UPDATETRANSFER; 987 + } 993 988 994 989 cmd |= DWC3_DEPCMD_PARAM(cmd_param); 995 990 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); ··· 1089 1082 * 1090 1083 */ 1091 1084 if (dep->flags & DWC3_EP_PENDING_REQUEST) { 1092 - int ret; 1093 - 1094 1085 /* 1095 1086 * If xfernotready is already elapsed and it is a case 1096 1087 * of isoc transfer, then issue END TRANSFER, so that ··· 1096 1091 * notion of current microframe. 1097 1092 */ 1098 1093 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { 1099 - dwc3_stop_active_transfer(dwc, dep->number); 1094 + if (list_empty(&dep->req_queued)) { 1095 + dwc3_stop_active_transfer(dwc, dep->number); 1096 + dep->flags = DWC3_EP_ENABLED; 1097 + } 1100 1098 return 0; 1101 1099 } 1102 1100 ··· 1107 1099 if (ret && ret != -EBUSY) 1108 1100 dev_dbg(dwc->dev, "%s: failed to kick transfers\n", 1109 1101 dep->name); 1102 + return ret; 1110 1103 } 1111 1104 1112 1105 /* ··· 1124 1115 if (ret && ret != -EBUSY) 1125 1116 dev_dbg(dwc->dev, "%s: failed to kick transfers\n", 1126 1117 dep->name); 1127 - } 1128 - 1129 - /* 1130 - * 3. Missed ISOC Handling. We need to start isoc transfer on the saved 1131 - * uframe number. 1132 - */ 1133 - if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && 1134 - (dep->flags & DWC3_EP_MISSED_ISOC)) { 1135 - __dwc3_gadget_start_isoc(dwc, dep, dep->current_uf); 1136 - dep->flags &= ~DWC3_EP_MISSED_ISOC; 1118 + return ret; 1137 1119 } 1138 1120 1139 1121 return 0; ··· 1652 1652 } 1653 1653 1654 1654 /* -------------------------------------------------------------------------- */ 1655 + static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep, 1656 + struct dwc3_request *req, struct dwc3_trb *trb, 1657 + const struct dwc3_event_depevt *event, int status) 1658 + { 1659 + unsigned int count; 1660 + unsigned int s_pkt = 0; 1661 + unsigned int trb_status; 1662 + 1663 + if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN) 1664 + /* 1665 + * We continue despite the error. There is not much we 1666 + * can do. If we don't clean it up we loop forever. If 1667 + * we skip the TRB then it gets overwritten after a 1668 + * while since we use them in a ring buffer. A BUG() 1669 + * would help. Lets hope that if this occurs, someone 1670 + * fixes the root cause instead of looking away :) 1671 + */ 1672 + dev_err(dwc->dev, "%s's TRB (%p) still owned by HW\n", 1673 + dep->name, trb); 1674 + count = trb->size & DWC3_TRB_SIZE_MASK; 1675 + 1676 + if (dep->direction) { 1677 + if (count) { 1678 + trb_status = DWC3_TRB_SIZE_TRBSTS(trb->size); 1679 + if (trb_status == DWC3_TRBSTS_MISSED_ISOC) { 1680 + dev_dbg(dwc->dev, "incomplete IN transfer %s\n", 1681 + dep->name); 1682 + /* 1683 + * If missed isoc occurred and there is 1684 + * no request queued then issue END 1685 + * TRANSFER, so that core generates 1686 + * next xfernotready and we will issue 1687 + * a fresh START TRANSFER. 1688 + * If there are still queued request 1689 + * then wait, do not issue either END 1690 + * or UPDATE TRANSFER, just attach next 1691 + * request in request_list during 1692 + * giveback.If any future queued request 1693 + * is successfully transferred then we 1694 + * will issue UPDATE TRANSFER for all 1695 + * request in the request_list. 1696 + */ 1697 + dep->flags |= DWC3_EP_MISSED_ISOC; 1698 + } else { 1699 + dev_err(dwc->dev, "incomplete IN transfer %s\n", 1700 + dep->name); 1701 + status = -ECONNRESET; 1702 + } 1703 + } else { 1704 + dep->flags &= ~DWC3_EP_MISSED_ISOC; 1705 + } 1706 + } else { 1707 + if (count && (event->status & DEPEVT_STATUS_SHORT)) 1708 + s_pkt = 1; 1709 + } 1710 + 1711 + /* 1712 + * We assume here we will always receive the entire data block 1713 + * which we should receive. Meaning, if we program RX to 1714 + * receive 4K but we receive only 2K, we assume that's all we 1715 + * should receive and we simply bounce the request back to the 1716 + * gadget driver for further processing. 1717 + */ 1718 + req->request.actual += req->request.length - count; 1719 + if (s_pkt) 1720 + return 1; 1721 + if ((event->status & DEPEVT_STATUS_LST) && 1722 + (trb->ctrl & (DWC3_TRB_CTRL_LST | 1723 + DWC3_TRB_CTRL_HWO))) 1724 + return 1; 1725 + if ((event->status & DEPEVT_STATUS_IOC) && 1726 + (trb->ctrl & DWC3_TRB_CTRL_IOC)) 1727 + return 1; 1728 + return 0; 1729 + } 1730 + 1655 1731 static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep, 1656 1732 const struct dwc3_event_depevt *event, int status) 1657 1733 { 1658 1734 struct dwc3_request *req; 1659 1735 struct dwc3_trb *trb; 1660 - unsigned int count; 1661 - unsigned int s_pkt = 0; 1662 - unsigned int trb_status; 1736 + unsigned int slot; 1737 + unsigned int i; 1738 + int ret; 1663 1739 1664 1740 do { 1665 1741 req = next_request(&dep->req_queued); ··· 1743 1667 WARN_ON_ONCE(1); 1744 1668 return 1; 1745 1669 } 1670 + i = 0; 1671 + do { 1672 + slot = req->start_slot + i; 1673 + if ((slot == DWC3_TRB_NUM - 1) && 1674 + usb_endpoint_xfer_isoc(dep->endpoint.desc)) 1675 + slot++; 1676 + slot %= DWC3_TRB_NUM; 1677 + trb = &dep->trb_pool[slot]; 1746 1678 1747 - trb = req->trb; 1679 + ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb, 1680 + event, status); 1681 + if (ret) 1682 + break; 1683 + }while (++i < req->request.num_mapped_sgs); 1748 1684 1749 - if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN) 1750 - /* 1751 - * We continue despite the error. There is not much we 1752 - * can do. If we don't clean it up we loop forever. If 1753 - * we skip the TRB then it gets overwritten after a 1754 - * while since we use them in a ring buffer. A BUG() 1755 - * would help. Lets hope that if this occurs, someone 1756 - * fixes the root cause instead of looking away :) 1757 - */ 1758 - dev_err(dwc->dev, "%s's TRB (%p) still owned by HW\n", 1759 - dep->name, req->trb); 1760 - count = trb->size & DWC3_TRB_SIZE_MASK; 1761 - 1762 - if (dep->direction) { 1763 - if (count) { 1764 - trb_status = DWC3_TRB_SIZE_TRBSTS(trb->size); 1765 - if (trb_status == DWC3_TRBSTS_MISSED_ISOC) { 1766 - dev_dbg(dwc->dev, "incomplete IN transfer %s\n", 1767 - dep->name); 1768 - dep->current_uf = event->parameters & 1769 - ~(dep->interval - 1); 1770 - dep->flags |= DWC3_EP_MISSED_ISOC; 1771 - } else { 1772 - dev_err(dwc->dev, "incomplete IN transfer %s\n", 1773 - dep->name); 1774 - status = -ECONNRESET; 1775 - } 1776 - } 1777 - } else { 1778 - if (count && (event->status & DEPEVT_STATUS_SHORT)) 1779 - s_pkt = 1; 1780 - } 1781 - 1782 - /* 1783 - * We assume here we will always receive the entire data block 1784 - * which we should receive. Meaning, if we program RX to 1785 - * receive 4K but we receive only 2K, we assume that's all we 1786 - * should receive and we simply bounce the request back to the 1787 - * gadget driver for further processing. 1788 - */ 1789 - req->request.actual += req->request.length - count; 1790 1685 dwc3_gadget_giveback(dep, req, status); 1791 - if (s_pkt) 1792 - break; 1793 - if ((event->status & DEPEVT_STATUS_LST) && 1794 - (trb->ctrl & (DWC3_TRB_CTRL_LST | 1795 - DWC3_TRB_CTRL_HWO))) 1796 - break; 1797 - if ((event->status & DEPEVT_STATUS_IOC) && 1798 - (trb->ctrl & DWC3_TRB_CTRL_IOC)) 1686 + 1687 + if (ret) 1799 1688 break; 1800 1689 } while (1); 1690 + 1691 + if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && 1692 + list_empty(&dep->req_queued)) { 1693 + if (list_empty(&dep->request_list)) { 1694 + /* 1695 + * If there is no entry in request list then do 1696 + * not issue END TRANSFER now. Just set PENDING 1697 + * flag, so that END TRANSFER is issued when an 1698 + * entry is added into request list. 1699 + */ 1700 + dep->flags = DWC3_EP_PENDING_REQUEST; 1701 + } else { 1702 + dwc3_stop_active_transfer(dwc, dep->number); 1703 + dep->flags = DWC3_EP_ENABLED; 1704 + } 1705 + return 1; 1706 + } 1801 1707 1802 1708 if ((event->status & DEPEVT_STATUS_IOC) && 1803 1709 (trb->ctrl & DWC3_TRB_CTRL_IOC)) ··· 2215 2157 break; 2216 2158 } 2217 2159 2160 + /* Enable USB2 LPM Capability */ 2161 + 2162 + if ((dwc->revision > DWC3_REVISION_194A) 2163 + && (speed != DWC3_DCFG_SUPERSPEED)) { 2164 + reg = dwc3_readl(dwc->regs, DWC3_DCFG); 2165 + reg |= DWC3_DCFG_LPM_CAP; 2166 + dwc3_writel(dwc->regs, DWC3_DCFG, reg); 2167 + 2168 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 2169 + reg &= ~(DWC3_DCTL_HIRD_THRES_MASK | DWC3_DCTL_L1_HIBER_EN); 2170 + 2171 + /* 2172 + * TODO: This should be configurable. For now using 2173 + * maximum allowed HIRD threshold value of 0b1100 2174 + */ 2175 + reg |= DWC3_DCTL_HIRD_THRES(12); 2176 + 2177 + dwc3_writel(dwc->regs, DWC3_DCTL, reg); 2178 + } 2179 + 2218 2180 /* Recent versions support automatic phy suspend and don't need this */ 2219 2181 if (dwc->revision < DWC3_REVISION_194A) { 2220 2182 /* Suspend unneeded PHY */ ··· 2541 2463 DWC3_DEVTEN_DISCONNEVTEN); 2542 2464 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); 2543 2465 2544 - /* Enable USB2 LPM and automatic phy suspend only on recent versions */ 2466 + /* automatic phy suspend only on recent versions */ 2545 2467 if (dwc->revision >= DWC3_REVISION_194A) { 2546 - reg = dwc3_readl(dwc->regs, DWC3_DCFG); 2547 - reg |= DWC3_DCFG_LPM_CAP; 2548 - dwc3_writel(dwc->regs, DWC3_DCFG, reg); 2549 - 2550 - reg = dwc3_readl(dwc->regs, DWC3_DCTL); 2551 - reg &= ~(DWC3_DCTL_HIRD_THRES_MASK | DWC3_DCTL_L1_HIBER_EN); 2552 - 2553 - /* TODO: This should be configurable */ 2554 - reg |= DWC3_DCTL_HIRD_THRES(28); 2555 - 2556 - dwc3_writel(dwc->regs, DWC3_DCTL, reg); 2557 - 2558 2468 dwc3_gadget_usb2_phy_suspend(dwc, false); 2559 2469 dwc3_gadget_usb3_phy_suspend(dwc, false); 2560 2470 }
+1 -1
drivers/usb/dwc3/host.c
··· 44 44 struct platform_device *xhci; 45 45 int ret; 46 46 47 - xhci = platform_device_alloc("xhci-hcd", -1); 47 + xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO); 48 48 if (!xhci) { 49 49 dev_err(dwc->dev, "couldn't allocate xHCI device\n"); 50 50 ret = -ENOMEM;
+23 -1
drivers/usb/gadget/Kconfig
··· 281 281 config USB_IMX 282 282 tristate "Freescale i.MX1 USB Peripheral Controller" 283 283 depends on ARCH_MXC 284 + depends on BROKEN 284 285 help 285 286 Freescale's i.MX1 includes an integrated full speed 286 287 USB 1.1 device controller. ··· 320 319 321 320 config USB_MV_UDC 322 321 tristate "Marvell USB2.0 Device Controller" 322 + depends on GENERIC_HARDIRQS 323 323 help 324 324 Marvell Socs (including PXA and MMP series) include a high speed 325 325 USB2.0 OTG controller, which can be configured as high speed or ··· 442 440 443 441 config USB_EG20T 444 442 tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC" 445 - depends on PCI 443 + depends on PCI && GENERIC_HARDIRQS 446 444 help 447 445 This is a USB device driver for EG20T PCH. 448 446 EG20T PCH is the platform controller hub that is used in Intel's ··· 502 500 tristate 503 501 depends on USB_GADGET 504 502 503 + config USB_F_ACM 504 + tristate 505 + 506 + config USB_F_SS_LB 507 + tristate 508 + 509 + config USB_U_SERIAL 510 + tristate 511 + 505 512 choice 506 513 tristate "USB Gadget Drivers" 507 514 default USB_ETH ··· 535 524 config USB_ZERO 536 525 tristate "Gadget Zero (DEVELOPMENT)" 537 526 select USB_LIBCOMPOSITE 527 + select USB_F_SS_LB 538 528 help 539 529 Gadget Zero is a two-configuration device. It either sinks and 540 530 sources bulk data; or it loops back a configurable number of ··· 762 750 763 751 config USB_G_SERIAL 764 752 tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" 753 + select USB_U_SERIAL 754 + select USB_F_ACM 765 755 select USB_LIBCOMPOSITE 766 756 help 767 757 The Serial Gadget talks to the Linux-USB generic serial driver. ··· 817 803 tristate "CDC Composite Device (Ethernet and ACM)" 818 804 depends on NET 819 805 select USB_LIBCOMPOSITE 806 + select USB_U_SERIAL 807 + select USB_F_ACM 820 808 help 821 809 This driver provides two functions in one configuration: 822 810 a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link. ··· 834 818 tristate "Nokia composite gadget" 835 819 depends on PHONET 836 820 select USB_LIBCOMPOSITE 821 + select USB_U_SERIAL 837 822 help 838 823 The Nokia composite gadget provides support for acm, obex 839 824 and phonet in only one composite gadget driver. ··· 846 829 tristate "CDC Composite Device (ACM and mass storage)" 847 830 depends on BLOCK 848 831 select USB_LIBCOMPOSITE 832 + select USB_U_SERIAL 833 + select USB_F_ACM 849 834 help 850 835 This driver provides two functions in one configuration: 851 836 a mass storage, and a CDC ACM (serial port) link. ··· 860 841 depends on BLOCK && NET 861 842 select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS 862 843 select USB_LIBCOMPOSITE 844 + select USB_U_SERIAL 845 + select USB_F_ACM 863 846 help 864 847 The Multifunction Composite Gadget provides Ethernet (RNDIS 865 848 and/or CDC Ethernet), mass storage and ACM serial link ··· 937 916 938 917 config USB_G_DBGP_SERIAL 939 918 depends on USB_G_DBGP 919 + select USB_U_SERIAL 940 920 bool "serial" 941 921 help 942 922 Userland can interact using /dev/ttyGSxxx.
+7 -1
drivers/usb/gadget/Makefile
··· 6 6 obj-$(CONFIG_USB_GADGET) += udc-core.o 7 7 obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o 8 8 libcomposite-y := usbstring.o config.o epautoconf.o 9 - libcomposite-y += composite.o 9 + libcomposite-y += composite.o functions.o 10 10 obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 11 11 obj-$(CONFIG_USB_NET2272) += net2272.o 12 12 obj-$(CONFIG_USB_NET2280) += net2280.o ··· 74 74 obj-$(CONFIG_USB_G_NCM) += g_ncm.o 75 75 obj-$(CONFIG_USB_G_ACM_MS) += g_acm_ms.o 76 76 obj-$(CONFIG_USB_GADGET_TARGET) += tcm_usb_gadget.o 77 + 78 + # USB Functions 79 + obj-$(CONFIG_USB_F_ACM) += f_acm.o 80 + f_ss_lb-y := f_loopback.o f_sourcesink.o 81 + obj-$(CONFIG_USB_F_SS_LB) += f_ss_lb.o 82 + obj-$(CONFIG_USB_U_SERIAL) += u_serial.o
+31 -11
drivers/usb/gadget/acm_ms.c
··· 40 40 * the runtime footprint, and giving us at least some parts of what 41 41 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 42 42 */ 43 - 44 - #include "u_serial.c" 45 - #include "f_acm.c" 46 43 #include "f_mass_storage.c" 47 44 48 45 /*-------------------------------------------------------------------------*/ ··· 109 112 static struct fsg_common fsg_common; 110 113 111 114 /*-------------------------------------------------------------------------*/ 112 - 115 + static unsigned char tty_line; 116 + static struct usb_function *f_acm; 117 + static struct usb_function_instance *f_acm_inst; 113 118 /* 114 119 * We _always_ have both ACM and mass storage functions. 115 120 */ 116 121 static int __init acm_ms_do_config(struct usb_configuration *c) 117 122 { 123 + struct f_serial_opts *opts; 118 124 int status; 119 125 120 126 if (gadget_is_otg(c->cdev->gadget)) { ··· 125 125 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 126 126 } 127 127 128 + f_acm_inst = usb_get_function_instance("acm"); 129 + if (IS_ERR(f_acm_inst)) 130 + return PTR_ERR(f_acm_inst); 128 131 129 - status = acm_bind_config(c, 0); 132 + opts = container_of(f_acm_inst, struct f_serial_opts, func_inst); 133 + opts->port_num = tty_line; 134 + 135 + f_acm = usb_get_function(f_acm_inst); 136 + if (IS_ERR(f_acm)) { 137 + status = PTR_ERR(f_acm); 138 + goto err_func; 139 + } 140 + 141 + status = usb_add_function(c, f_acm); 130 142 if (status < 0) 131 - return status; 143 + goto err_conf; 132 144 133 145 status = fsg_bind_config(c->cdev, c, &fsg_common); 134 146 if (status < 0) 135 - return status; 147 + goto err_fsg; 136 148 137 149 return 0; 150 + err_fsg: 151 + usb_remove_function(c, f_acm); 152 + err_conf: 153 + usb_put_function(f_acm); 154 + err_func: 155 + usb_put_function_instance(f_acm_inst); 156 + return status; 138 157 } 139 158 140 159 static struct usb_configuration acm_ms_config_driver = { ··· 172 153 void *retp; 173 154 174 155 /* set up serial link layer */ 175 - status = gserial_setup(cdev->gadget, 1); 156 + status = gserial_alloc_line(&tty_line); 176 157 if (status < 0) 177 158 return status; 178 159 ··· 208 189 fail1: 209 190 fsg_common_put(&fsg_common); 210 191 fail0: 211 - gserial_cleanup(); 192 + gserial_free_line(tty_line); 212 193 return status; 213 194 } 214 195 215 196 static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) 216 197 { 217 - gserial_cleanup(); 218 - 198 + usb_put_function(f_acm); 199 + usb_put_function_instance(f_acm_inst); 200 + gserial_free_line(tty_line); 219 201 return 0; 220 202 } 221 203
+14 -45
drivers/usb/gadget/amd5536udc.c
··· 1400 1400 return 0; 1401 1401 } 1402 1402 1403 - static int amd5536_start(struct usb_gadget_driver *driver, 1404 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1405 - static int amd5536_stop(struct usb_gadget_driver *driver); 1403 + static int amd5536_udc_start(struct usb_gadget *g, 1404 + struct usb_gadget_driver *driver); 1405 + static int amd5536_udc_stop(struct usb_gadget *g, 1406 + struct usb_gadget_driver *driver); 1406 1407 /* gadget operations */ 1407 1408 static const struct usb_gadget_ops udc_ops = { 1408 1409 .wakeup = udc_wakeup, 1409 1410 .get_frame = udc_get_frame, 1410 - .start = amd5536_start, 1411 - .stop = amd5536_stop, 1411 + .udc_start = amd5536_udc_start, 1412 + .udc_stop = amd5536_udc_stop, 1412 1413 }; 1413 1414 1414 1415 /* Setups endpoint parameters, adds endpoints to linked list */ ··· 1914 1913 } 1915 1914 1916 1915 /* Called by gadget driver to register itself */ 1917 - static int amd5536_start(struct usb_gadget_driver *driver, 1918 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1916 + static int amd5536_udc_start(struct usb_gadget *g, 1917 + struct usb_gadget_driver *driver) 1919 1918 { 1920 - struct udc *dev = udc; 1921 - int retval; 1919 + struct udc *dev = to_amd5536_udc(g); 1922 1920 u32 tmp; 1923 - 1924 - if (!driver || !bind || !driver->setup 1925 - || driver->max_speed < USB_SPEED_HIGH) 1926 - return -EINVAL; 1927 - if (!dev) 1928 - return -ENODEV; 1929 - if (dev->driver) 1930 - return -EBUSY; 1931 1921 1932 1922 driver->driver.bus = NULL; 1933 1923 dev->driver = driver; 1934 1924 dev->gadget.dev.driver = &driver->driver; 1935 - 1936 - retval = bind(&dev->gadget, driver); 1937 1925 1938 1926 /* Some gadget drivers use both ep0 directions. 1939 1927 * NOTE: to gadget driver, ep0 is just one endpoint... 1940 1928 */ 1941 1929 dev->ep[UDC_EP0OUT_IX].ep.driver_data = 1942 1930 dev->ep[UDC_EP0IN_IX].ep.driver_data; 1943 - 1944 - if (retval) { 1945 - DBG(dev, "binding to %s returning %d\n", 1946 - driver->driver.name, retval); 1947 - dev->driver = NULL; 1948 - dev->gadget.dev.driver = NULL; 1949 - return retval; 1950 - } 1951 1931 1952 1932 /* get ready for ep0 traffic */ 1953 1933 setup_ep0(dev); ··· 1951 1969 { 1952 1970 int tmp; 1953 1971 1954 - if (dev->gadget.speed != USB_SPEED_UNKNOWN) { 1955 - spin_unlock(&dev->lock); 1956 - driver->disconnect(&dev->gadget); 1957 - spin_lock(&dev->lock); 1958 - } 1959 - 1960 1972 /* empty queues and init hardware */ 1961 1973 udc_basic_init(dev); 1974 + 1962 1975 for (tmp = 0; tmp < UDC_EP_NUM; tmp++) 1963 1976 empty_req_queue(&dev->ep[tmp]); 1964 1977 ··· 1961 1984 } 1962 1985 1963 1986 /* Called by gadget driver to unregister itself */ 1964 - static int amd5536_stop(struct usb_gadget_driver *driver) 1987 + static int amd5536_udc_stop(struct usb_gadget *g, 1988 + struct usb_gadget_driver *driver) 1965 1989 { 1966 - struct udc *dev = udc; 1967 - unsigned long flags; 1990 + struct udc *dev = to_amd5536_udc(g); 1991 + unsigned long flags; 1968 1992 u32 tmp; 1969 - 1970 - if (!dev) 1971 - return -ENODEV; 1972 - if (!driver || driver != dev->driver || !driver->unbind) 1973 - return -EINVAL; 1974 1993 1975 1994 spin_lock_irqsave(&dev->lock, flags); 1976 1995 udc_mask_unused_interrupts(dev); 1977 1996 shutdown(dev, driver); 1978 1997 spin_unlock_irqrestore(&dev->lock, flags); 1979 1998 1980 - driver->unbind(&dev->gadget); 1981 1999 dev->gadget.dev.driver = NULL; 1982 2000 dev->driver = NULL; 1983 2001 ··· 1980 2008 tmp = readl(&dev->regs->ctl); 1981 2009 tmp |= AMD_BIT(UDC_DEVCTL_SD); 1982 2010 writel(tmp, &dev->regs->ctl); 1983 - 1984 - 1985 - DBG(dev, "%s: unregistered\n", driver->driver.name); 1986 2011 1987 2012 return 0; 1988 2013 }
+2
drivers/usb/gadget/amd5536udc.h
··· 563 563 u16 cur_alt; 564 564 }; 565 565 566 + #define to_amd5536_udc(g) (container_of((g), struct udc, gadget)) 567 + 566 568 /* setup request data */ 567 569 union udc_setup_data { 568 570 u32 data[2];
+2 -3
drivers/usb/gadget/at91_udc.c
··· 1621 1621 * bus such as i2c or spi which may sleep, so schedule some work 1622 1622 * to read the vbus gpio 1623 1623 */ 1624 - if (!work_pending(&udc->vbus_timer_work)) 1625 - schedule_work(&udc->vbus_timer_work); 1624 + schedule_work(&udc->vbus_timer_work); 1626 1625 } 1627 1626 1628 1627 static int at91_start(struct usb_gadget *gadget, ··· 1738 1739 1739 1740 /* rm9200 needs manual D+ pullup; off by default */ 1740 1741 if (cpu_is_at91rm9200()) { 1741 - if (gpio_is_valid(udc->board.pullup_pin)) { 1742 + if (!gpio_is_valid(udc->board.pullup_pin)) { 1742 1743 DBG("no D+ pullup?\n"); 1743 1744 retval = -ENODEV; 1744 1745 goto fail0;
+27 -9
drivers/usb/gadget/cdc2.c
··· 42 42 * the runtime footprint, and giving us at least some parts of what 43 43 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 44 44 */ 45 - 46 - #include "u_serial.c" 47 - #include "f_acm.c" 48 45 #include "f_ecm.c" 49 46 #include "u_ether.c" 50 47 ··· 105 108 static u8 hostaddr[ETH_ALEN]; 106 109 107 110 /*-------------------------------------------------------------------------*/ 111 + static struct usb_function *f_acm; 112 + static struct usb_function_instance *fi_serial; 108 113 114 + static unsigned char tty_line; 109 115 /* 110 116 * We _always_ have both CDC ECM and CDC ACM functions. 111 117 */ 112 118 static int __init cdc_do_config(struct usb_configuration *c) 113 119 { 120 + struct f_serial_opts *opts; 114 121 int status; 115 122 116 123 if (gadget_is_otg(c->cdev->gadget)) { ··· 126 125 if (status < 0) 127 126 return status; 128 127 129 - status = acm_bind_config(c, 0); 130 - if (status < 0) 131 - return status; 128 + fi_serial = usb_get_function_instance("acm"); 129 + if (IS_ERR(fi_serial)) 130 + return PTR_ERR(fi_serial); 132 131 132 + opts = container_of(fi_serial, struct f_serial_opts, func_inst); 133 + opts->port_num = tty_line; 134 + 135 + f_acm = usb_get_function(fi_serial); 136 + if (IS_ERR(f_acm)) 137 + goto err_func_acm; 138 + 139 + status = usb_add_function(c, f_acm); 140 + if (status) 141 + goto err_conf; 133 142 return 0; 143 + err_conf: 144 + usb_put_function(f_acm); 145 + err_func_acm: 146 + usb_put_function_instance(fi_serial); 147 + return status; 134 148 } 135 149 136 150 static struct usb_configuration cdc_config_driver = { ··· 174 158 return status; 175 159 176 160 /* set up serial link layer */ 177 - status = gserial_setup(cdev->gadget, 1); 161 + status = gserial_alloc_line(&tty_line); 178 162 if (status < 0) 179 163 goto fail0; 180 164 ··· 200 184 return 0; 201 185 202 186 fail1: 203 - gserial_cleanup(); 187 + gserial_free_line(tty_line); 204 188 fail0: 205 189 gether_cleanup(); 206 190 return status; ··· 208 192 209 193 static int __exit cdc_unbind(struct usb_composite_dev *cdev) 210 194 { 211 - gserial_cleanup(); 195 + usb_put_function(f_acm); 196 + usb_put_function_instance(fi_serial); 197 + gserial_free_line(tty_line); 212 198 gether_cleanup(); 213 199 return 0; 214 200 }
+268 -58
drivers/usb/gadget/composite.c
··· 28 28 * with the relevant device-wide data. 29 29 */ 30 30 31 + static struct usb_gadget_strings **get_containers_gs( 32 + struct usb_gadget_string_container *uc) 33 + { 34 + return (struct usb_gadget_strings **)uc->stash; 35 + } 36 + 31 37 /** 32 38 * next_ep_desc() - advance to the next EP descriptor 33 39 * @t: currect pointer within descriptor array ··· 221 215 } 222 216 EXPORT_SYMBOL_GPL(usb_add_function); 223 217 218 + void usb_remove_function(struct usb_configuration *c, struct usb_function *f) 219 + { 220 + if (f->disable) 221 + f->disable(f); 222 + 223 + bitmap_zero(f->endpoints, 32); 224 + list_del(&f->list); 225 + if (f->unbind) 226 + f->unbind(c, f); 227 + } 228 + EXPORT_SYMBOL_GPL(usb_remove_function); 229 + 224 230 /** 225 231 * usb_function_deactivate - prevent function and gadget enumeration 226 232 * @function: the function that isn't yet ready to respond ··· 338 320 } 339 321 EXPORT_SYMBOL_GPL(usb_interface_id); 340 322 323 + static u8 encode_bMaxPower(enum usb_device_speed speed, 324 + struct usb_configuration *c) 325 + { 326 + unsigned val; 327 + 328 + if (c->MaxPower) 329 + val = c->MaxPower; 330 + else 331 + val = CONFIG_USB_GADGET_VBUS_DRAW; 332 + if (!val) 333 + return 0; 334 + switch (speed) { 335 + case USB_SPEED_SUPER: 336 + return DIV_ROUND_UP(val, 8); 337 + default: 338 + return DIV_ROUND_UP(val, 2); 339 + }; 340 + } 341 + 341 342 static int config_buf(struct usb_configuration *config, 342 343 enum usb_device_speed speed, void *buf, u8 type) 343 344 { ··· 376 339 c->bConfigurationValue = config->bConfigurationValue; 377 340 c->iConfiguration = config->iConfiguration; 378 341 c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes; 379 - c->bMaxPower = config->bMaxPower ? : (CONFIG_USB_GADGET_VBUS_DRAW / 2); 342 + c->bMaxPower = encode_bMaxPower(speed, config); 380 343 381 344 /* There may be e.g. OTG descriptors */ 382 345 if (config->descriptors) { ··· 693 656 } 694 657 695 658 /* when we return, be sure our power usage is valid */ 696 - power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW; 659 + power = c->MaxPower ? c->MaxPower : CONFIG_USB_GADGET_VBUS_DRAW; 697 660 done: 698 661 usb_gadget_vbus_draw(gadget, power); 699 662 if (result >= 0 && cdev->delayed_status) 700 663 result = USB_GADGET_DELAYED_STATUS; 701 664 return result; 702 665 } 666 + 667 + int usb_add_config_only(struct usb_composite_dev *cdev, 668 + struct usb_configuration *config) 669 + { 670 + struct usb_configuration *c; 671 + 672 + if (!config->bConfigurationValue) 673 + return -EINVAL; 674 + 675 + /* Prevent duplicate configuration identifiers */ 676 + list_for_each_entry(c, &cdev->configs, list) { 677 + if (c->bConfigurationValue == config->bConfigurationValue) 678 + return -EBUSY; 679 + } 680 + 681 + config->cdev = cdev; 682 + list_add_tail(&config->list, &cdev->configs); 683 + 684 + INIT_LIST_HEAD(&config->functions); 685 + config->next_interface_id = 0; 686 + memset(config->interface, 0, sizeof(config->interface)); 687 + 688 + return 0; 689 + } 690 + EXPORT_SYMBOL_GPL(usb_add_config_only); 703 691 704 692 /** 705 693 * usb_add_config() - add a configuration to a device. ··· 746 684 int (*bind)(struct usb_configuration *)) 747 685 { 748 686 int status = -EINVAL; 749 - struct usb_configuration *c; 687 + 688 + if (!bind) 689 + goto done; 750 690 751 691 DBG(cdev, "adding config #%u '%s'/%p\n", 752 692 config->bConfigurationValue, 753 693 config->label, config); 754 694 755 - if (!config->bConfigurationValue || !bind) 695 + status = usb_add_config_only(cdev, config); 696 + if (status) 756 697 goto done; 757 - 758 - /* Prevent duplicate configuration identifiers */ 759 - list_for_each_entry(c, &cdev->configs, list) { 760 - if (c->bConfigurationValue == config->bConfigurationValue) { 761 - status = -EBUSY; 762 - goto done; 763 - } 764 - } 765 - 766 - config->cdev = cdev; 767 - list_add_tail(&config->list, &cdev->configs); 768 - 769 - INIT_LIST_HEAD(&config->functions); 770 - config->next_interface_id = 0; 771 - memset(config->interface, 0, sizeof(config->interface)); 772 698 773 699 status = bind(config); 774 700 if (status < 0) { ··· 910 860 void *buf, u16 language, int id) 911 861 { 912 862 struct usb_composite_driver *composite = cdev->driver; 863 + struct usb_gadget_string_container *uc; 913 864 struct usb_configuration *c; 914 865 struct usb_function *f; 915 866 int len; ··· 943 892 collect_langs(sp, s->wData); 944 893 } 945 894 } 895 + list_for_each_entry(uc, &cdev->gstrings, list) { 896 + struct usb_gadget_strings **sp; 897 + 898 + sp = get_containers_gs(uc); 899 + collect_langs(sp, s->wData); 900 + } 946 901 947 902 for (len = 0; len <= 126 && s->wData[len]; len++) 948 903 continue; ··· 957 900 958 901 s->bLength = 2 * (len + 1); 959 902 return s->bLength; 903 + } 904 + 905 + list_for_each_entry(uc, &cdev->gstrings, list) { 906 + struct usb_gadget_strings **sp; 907 + 908 + sp = get_containers_gs(uc); 909 + len = lookup_string(sp, buf, language, id); 910 + if (len > 0) 911 + return len; 960 912 } 961 913 962 914 /* String IDs are device-scoped, so we look up each string ··· 1053 987 } 1054 988 EXPORT_SYMBOL_GPL(usb_string_ids_tab); 1055 989 990 + static struct usb_gadget_string_container *copy_gadget_strings( 991 + struct usb_gadget_strings **sp, unsigned n_gstrings, 992 + unsigned n_strings) 993 + { 994 + struct usb_gadget_string_container *uc; 995 + struct usb_gadget_strings **gs_array; 996 + struct usb_gadget_strings *gs; 997 + struct usb_string *s; 998 + unsigned mem; 999 + unsigned n_gs; 1000 + unsigned n_s; 1001 + void *stash; 1002 + 1003 + mem = sizeof(*uc); 1004 + mem += sizeof(void *) * (n_gstrings + 1); 1005 + mem += sizeof(struct usb_gadget_strings) * n_gstrings; 1006 + mem += sizeof(struct usb_string) * (n_strings + 1) * (n_gstrings); 1007 + uc = kmalloc(mem, GFP_KERNEL); 1008 + if (!uc) 1009 + return ERR_PTR(-ENOMEM); 1010 + gs_array = get_containers_gs(uc); 1011 + stash = uc->stash; 1012 + stash += sizeof(void *) * (n_gstrings + 1); 1013 + for (n_gs = 0; n_gs < n_gstrings; n_gs++) { 1014 + struct usb_string *org_s; 1015 + 1016 + gs_array[n_gs] = stash; 1017 + gs = gs_array[n_gs]; 1018 + stash += sizeof(struct usb_gadget_strings); 1019 + gs->language = sp[n_gs]->language; 1020 + gs->strings = stash; 1021 + org_s = sp[n_gs]->strings; 1022 + 1023 + for (n_s = 0; n_s < n_strings; n_s++) { 1024 + s = stash; 1025 + stash += sizeof(struct usb_string); 1026 + if (org_s->s) 1027 + s->s = org_s->s; 1028 + else 1029 + s->s = ""; 1030 + org_s++; 1031 + } 1032 + s = stash; 1033 + s->s = NULL; 1034 + stash += sizeof(struct usb_string); 1035 + 1036 + } 1037 + gs_array[n_gs] = NULL; 1038 + return uc; 1039 + } 1040 + 1041 + /** 1042 + * usb_gstrings_attach() - attach gadget strings to a cdev and assign ids 1043 + * @cdev: the device whose string descriptor IDs are being allocated 1044 + * and attached. 1045 + * @sp: an array of usb_gadget_strings to attach. 1046 + * @n_strings: number of entries in each usb_strings array (sp[]->strings) 1047 + * 1048 + * This function will create a deep copy of usb_gadget_strings and usb_string 1049 + * and attach it to the cdev. The actual string (usb_string.s) will not be 1050 + * copied but only a referenced will be made. The struct usb_gadget_strings 1051 + * array may contain multiple languges and should be NULL terminated. 1052 + * The ->language pointer of each struct usb_gadget_strings has to contain the 1053 + * same amount of entries. 1054 + * For instance: sp[0] is en-US, sp[1] is es-ES. It is expected that the first 1055 + * usb_string entry of es-ES containts the translation of the first usb_string 1056 + * entry of en-US. Therefore both entries become the same id assign. 1057 + */ 1058 + struct usb_string *usb_gstrings_attach(struct usb_composite_dev *cdev, 1059 + struct usb_gadget_strings **sp, unsigned n_strings) 1060 + { 1061 + struct usb_gadget_string_container *uc; 1062 + struct usb_gadget_strings **n_gs; 1063 + unsigned n_gstrings = 0; 1064 + unsigned i; 1065 + int ret; 1066 + 1067 + for (i = 0; sp[i]; i++) 1068 + n_gstrings++; 1069 + 1070 + if (!n_gstrings) 1071 + return ERR_PTR(-EINVAL); 1072 + 1073 + uc = copy_gadget_strings(sp, n_gstrings, n_strings); 1074 + if (IS_ERR(uc)) 1075 + return ERR_PTR(PTR_ERR(uc)); 1076 + 1077 + n_gs = get_containers_gs(uc); 1078 + ret = usb_string_ids_tab(cdev, n_gs[0]->strings); 1079 + if (ret) 1080 + goto err; 1081 + 1082 + for (i = 1; i < n_gstrings; i++) { 1083 + struct usb_string *m_s; 1084 + struct usb_string *s; 1085 + unsigned n; 1086 + 1087 + m_s = n_gs[0]->strings; 1088 + s = n_gs[i]->strings; 1089 + for (n = 0; n < n_strings; n++) { 1090 + s->id = m_s->id; 1091 + s++; 1092 + m_s++; 1093 + } 1094 + } 1095 + list_add_tail(&uc->list, &cdev->gstrings); 1096 + return n_gs[0]->strings; 1097 + err: 1098 + kfree(uc); 1099 + return ERR_PTR(ret); 1100 + } 1101 + EXPORT_SYMBOL_GPL(usb_gstrings_attach); 1102 + 1056 1103 /** 1057 1104 * usb_string_ids_n() - allocate unused string IDs in batch 1058 1105 * @c: the device whose string descriptor IDs are being allocated ··· 1212 1033 * housekeeping for the gadget function we're implementing. Most of 1213 1034 * the work is in config and function specific setup. 1214 1035 */ 1215 - static int 1036 + int 1216 1037 composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) 1217 1038 { 1218 1039 struct usb_composite_dev *cdev = get_gadget_data(gadget); ··· 1479 1300 return value; 1480 1301 } 1481 1302 1482 - static void composite_disconnect(struct usb_gadget *gadget) 1303 + void composite_disconnect(struct usb_gadget *gadget) 1483 1304 { 1484 1305 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1485 1306 unsigned long flags; ··· 1509 1330 1510 1331 static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL); 1511 1332 1512 - static void 1513 - composite_unbind(struct usb_gadget *gadget) 1333 + static void __composite_unbind(struct usb_gadget *gadget, bool unbind_driver) 1514 1334 { 1515 1335 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1516 1336 ··· 1526 1348 struct usb_configuration, list); 1527 1349 remove_config(cdev, c); 1528 1350 } 1529 - if (cdev->driver->unbind) 1351 + if (cdev->driver->unbind && unbind_driver) 1530 1352 cdev->driver->unbind(cdev); 1531 1353 1532 - if (cdev->req) { 1533 - kfree(cdev->req->buf); 1534 - usb_ep_free_request(gadget->ep0, cdev->req); 1535 - } 1536 - device_remove_file(&gadget->dev, &dev_attr_suspended); 1354 + composite_dev_cleanup(cdev); 1355 + 1537 1356 kfree(cdev->def_manufacturer); 1538 1357 kfree(cdev); 1539 1358 set_gadget_data(gadget, NULL); 1359 + } 1360 + 1361 + static void composite_unbind(struct usb_gadget *gadget) 1362 + { 1363 + __composite_unbind(gadget, true); 1540 1364 } 1541 1365 1542 1366 static void update_unchanged_dev_desc(struct usb_device_descriptor *new, ··· 1579 1399 new->iProduct = iProduct; 1580 1400 } 1581 1401 1582 - static struct usb_composite_driver *to_cdriver(struct usb_gadget_driver *gdrv) 1402 + int composite_dev_prepare(struct usb_composite_driver *composite, 1403 + struct usb_composite_dev *cdev) 1583 1404 { 1584 - return container_of(gdrv, struct usb_composite_driver, gadget_driver); 1585 - } 1586 - 1587 - static int composite_bind(struct usb_gadget *gadget, 1588 - struct usb_gadget_driver *gdriver) 1589 - { 1590 - struct usb_composite_dev *cdev; 1591 - struct usb_composite_driver *composite = to_cdriver(gdriver); 1592 - int status = -ENOMEM; 1593 - 1594 - cdev = kzalloc(sizeof *cdev, GFP_KERNEL); 1595 - if (!cdev) 1596 - return status; 1597 - 1598 - spin_lock_init(&cdev->lock); 1599 - cdev->gadget = gadget; 1600 - set_gadget_data(gadget, cdev); 1601 - INIT_LIST_HEAD(&cdev->configs); 1405 + struct usb_gadget *gadget = cdev->gadget; 1406 + int ret = -ENOMEM; 1602 1407 1603 1408 /* preallocate control response and buffer */ 1604 1409 cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); 1605 1410 if (!cdev->req) 1606 - goto fail; 1411 + return -ENOMEM; 1412 + 1607 1413 cdev->req->buf = kmalloc(USB_COMP_EP0_BUFSIZ, GFP_KERNEL); 1608 1414 if (!cdev->req->buf) 1609 1415 goto fail; 1416 + 1417 + ret = device_create_file(&gadget->dev, &dev_attr_suspended); 1418 + if (ret) 1419 + goto fail_dev; 1420 + 1610 1421 cdev->req->complete = composite_setup_complete; 1611 1422 gadget->ep0->driver_data = cdev; 1612 1423 ··· 1615 1444 * we force endpoints to start unassigned; few controller 1616 1445 * drivers will zero ep->driver_data. 1617 1446 */ 1618 - usb_ep_autoconfig_reset(cdev->gadget); 1447 + usb_ep_autoconfig_reset(gadget); 1448 + return 0; 1449 + fail_dev: 1450 + kfree(cdev->req->buf); 1451 + fail: 1452 + usb_ep_free_request(gadget->ep0, cdev->req); 1453 + cdev->req = NULL; 1454 + return ret; 1455 + } 1456 + 1457 + void composite_dev_cleanup(struct usb_composite_dev *cdev) 1458 + { 1459 + struct usb_gadget_string_container *uc, *tmp; 1460 + 1461 + list_for_each_entry_safe(uc, tmp, &cdev->gstrings, list) { 1462 + list_del(&uc->list); 1463 + kfree(uc); 1464 + } 1465 + if (cdev->req) { 1466 + kfree(cdev->req->buf); 1467 + usb_ep_free_request(cdev->gadget->ep0, cdev->req); 1468 + } 1469 + device_remove_file(&cdev->gadget->dev, &dev_attr_suspended); 1470 + } 1471 + 1472 + static int composite_bind(struct usb_gadget *gadget, 1473 + struct usb_gadget_driver *gdriver) 1474 + { 1475 + struct usb_composite_dev *cdev; 1476 + struct usb_composite_driver *composite = to_cdriver(gdriver); 1477 + int status = -ENOMEM; 1478 + 1479 + cdev = kzalloc(sizeof *cdev, GFP_KERNEL); 1480 + if (!cdev) 1481 + return status; 1482 + 1483 + spin_lock_init(&cdev->lock); 1484 + cdev->gadget = gadget; 1485 + set_gadget_data(gadget, cdev); 1486 + INIT_LIST_HEAD(&cdev->configs); 1487 + INIT_LIST_HEAD(&cdev->gstrings); 1488 + 1489 + status = composite_dev_prepare(composite, cdev); 1490 + if (status) 1491 + goto fail; 1619 1492 1620 1493 /* composite gadget needs to assign strings for whole device (like 1621 1494 * serial number), register function drivers, potentially update ··· 1675 1460 if (composite->needs_serial && !cdev->desc.iSerialNumber) 1676 1461 WARNING(cdev, "userspace failed to provide iSerialNumber\n"); 1677 1462 1678 - /* finish up */ 1679 - status = device_create_file(&gadget->dev, &dev_attr_suspended); 1680 - if (status) 1681 - goto fail; 1682 - 1683 1463 INFO(cdev, "%s ready\n", composite->name); 1684 1464 return 0; 1685 1465 1686 1466 fail: 1687 - composite_unbind(gadget); 1467 + __composite_unbind(gadget, false); 1688 1468 return status; 1689 1469 } 1690 1470 ··· 1728 1518 f->resume(f); 1729 1519 } 1730 1520 1731 - maxpower = cdev->config->bMaxPower; 1521 + maxpower = cdev->config->MaxPower; 1732 1522 1733 1523 usb_gadget_vbus_draw(gadget, maxpower ? 1734 - (2 * maxpower) : CONFIG_USB_GADGET_VBUS_DRAW); 1524 + maxpower : CONFIG_USB_GADGET_VBUS_DRAW); 1735 1525 } 1736 1526 1737 1527 cdev->suspended = 0;
+8 -6
drivers/usb/gadget/dbgp.c
··· 13 13 #include <linux/usb/ch9.h> 14 14 #include <linux/usb/gadget.h> 15 15 16 - #ifdef CONFIG_USB_G_DBGP_SERIAL 17 - #include "u_serial.c" 18 - #endif 16 + #include "u_serial.h" 19 17 20 18 #define DRIVER_VENDOR_ID 0x0525 /* NetChip */ 21 19 #define DRIVER_PRODUCT_ID 0xc0de /* undefined */ ··· 231 233 gadget->ep0->driver_data = NULL; 232 234 } 233 235 236 + #ifdef CONFIG_USB_G_DBGP_SERIAL 237 + static unsigned char tty_line; 238 + #endif 239 + 234 240 static int __init dbgp_configure_endpoints(struct usb_gadget *gadget) 235 241 { 236 242 int stp; ··· 272 270 dbgp.serial->in->desc = &i_desc; 273 271 dbgp.serial->out->desc = &o_desc; 274 272 275 - if (gserial_setup(gadget, 1) < 0) { 273 + if (gserial_alloc_line(&tty_line)) { 276 274 stp = 3; 277 275 goto fail_3; 278 276 } ··· 381 379 #ifdef CONFIG_USB_G_DBGP_PRINTK 382 380 err = dbgp_enable_ep(); 383 381 #else 384 - err = gserial_connect(dbgp.serial, 0); 382 + err = gserial_connect(dbgp.serial, tty_line); 385 383 #endif 386 384 if (err < 0) 387 385 goto fail; ··· 424 422 { 425 423 usb_gadget_unregister_driver(&dbgp_driver); 426 424 #ifdef CONFIG_USB_G_DBGP_SERIAL 427 - gserial_cleanup(); 425 + gserial_free_line(tty_line); 428 426 #endif 429 427 } 430 428
+104 -49
drivers/usb/gadget/f_acm.c
··· 16 16 17 17 #include <linux/slab.h> 18 18 #include <linux/kernel.h> 19 + #include <linux/module.h> 19 20 #include <linux/device.h> 21 + #include <linux/err.h> 20 22 21 23 #include "u_serial.h" 22 24 #include "gadget_chips.h" ··· 285 283 [ACM_CTRL_IDX].s = "CDC Abstract Control Model (ACM)", 286 284 [ACM_DATA_IDX].s = "CDC ACM Data", 287 285 [ACM_IAD_IDX ].s = "CDC Serial", 288 - { /* ZEROES END LIST */ }, 289 286 }; 290 287 291 288 static struct usb_gadget_strings acm_string_table = { ··· 606 605 { 607 606 struct usb_composite_dev *cdev = c->cdev; 608 607 struct f_acm *acm = func_to_acm(f); 608 + struct usb_string *us; 609 609 int status; 610 610 struct usb_ep *ep; 611 + 612 + /* REVISIT might want instance-specific strings to help 613 + * distinguish instances ... 614 + */ 615 + 616 + /* maybe allocate device-global string IDs, and patch descriptors */ 617 + us = usb_gstrings_attach(cdev, acm_strings, 618 + ARRAY_SIZE(acm_string_defs)); 619 + if (IS_ERR(us)) 620 + return PTR_ERR(us); 621 + acm_control_interface_desc.iInterface = us[ACM_CTRL_IDX].id; 622 + acm_data_interface_desc.iInterface = us[ACM_DATA_IDX].id; 623 + acm_iad_descriptor.iFunction = us[ACM_IAD_IDX].id; 611 624 612 625 /* allocate instance-specific interface IDs, and patch descriptors */ 613 626 status = usb_interface_id(c, f); ··· 715 700 return status; 716 701 } 717 702 703 + static struct f_acm *acm_alloc_basic_func(void) 704 + { 705 + struct f_acm *acm; 706 + 707 + acm = kzalloc(sizeof(*acm), GFP_KERNEL); 708 + if (!acm) 709 + return NULL; 710 + 711 + spin_lock_init(&acm->lock); 712 + 713 + acm->port.connect = acm_connect; 714 + acm->port.disconnect = acm_disconnect; 715 + acm->port.send_break = acm_send_break; 716 + 717 + acm->port.func.name = "acm"; 718 + /* descriptors are per-instance copies */ 719 + acm->port.func.bind = acm_bind; 720 + acm->port.func.set_alt = acm_set_alt; 721 + acm->port.func.setup = acm_setup; 722 + acm->port.func.disable = acm_disable; 723 + 724 + return acm; 725 + } 726 + 727 + #ifdef USB_FACM_INCLUDED 718 728 static void 719 - acm_unbind(struct usb_configuration *c, struct usb_function *f) 729 + acm_old_unbind(struct usb_configuration *c, struct usb_function *f) 720 730 { 721 731 struct f_acm *acm = func_to_acm(f); 722 732 723 - acm_string_defs[0].id = 0; 724 733 usb_free_all_descriptors(f); 725 - gs_free_req(acm->notify, acm->notify_req); 734 + if (acm->notify_req) 735 + gs_free_req(acm->notify, acm->notify_req); 726 736 kfree(acm); 727 - } 728 - 729 - /* Some controllers can't support CDC ACM ... */ 730 - static inline bool can_support_cdc(struct usb_configuration *c) 731 - { 732 - /* everything else is *probably* fine ... */ 733 - return true; 734 737 } 735 738 736 739 /** ··· 759 726 * 760 727 * Returns zero on success, else negative errno. 761 728 * 762 - * Caller must have called @gserial_setup() with enough ports to 763 - * handle all the ones it binds. Caller is also responsible 764 - * for calling @gserial_cleanup() before module unload. 765 729 */ 766 730 int acm_bind_config(struct usb_configuration *c, u8 port_num) 767 731 { 768 732 struct f_acm *acm; 769 733 int status; 770 734 771 - if (!can_support_cdc(c)) 772 - return -EINVAL; 773 - 774 - /* REVISIT might want instance-specific strings to help 775 - * distinguish instances ... 776 - */ 777 - 778 - /* maybe allocate device-global string IDs, and patch descriptors */ 779 - if (acm_string_defs[0].id == 0) { 780 - status = usb_string_ids_tab(c->cdev, acm_string_defs); 781 - if (status < 0) 782 - return status; 783 - acm_control_interface_desc.iInterface = 784 - acm_string_defs[ACM_CTRL_IDX].id; 785 - acm_data_interface_desc.iInterface = 786 - acm_string_defs[ACM_DATA_IDX].id; 787 - acm_iad_descriptor.iFunction = acm_string_defs[ACM_IAD_IDX].id; 788 - } 789 - 790 735 /* allocate and initialize one new instance */ 791 - acm = kzalloc(sizeof *acm, GFP_KERNEL); 736 + acm = acm_alloc_basic_func(); 792 737 if (!acm) 793 738 return -ENOMEM; 794 739 795 - spin_lock_init(&acm->lock); 796 - 797 740 acm->port_num = port_num; 798 - 799 - acm->port.connect = acm_connect; 800 - acm->port.disconnect = acm_disconnect; 801 - acm->port.send_break = acm_send_break; 802 - 803 - acm->port.func.name = "acm"; 804 - acm->port.func.strings = acm_strings; 805 - /* descriptors are per-instance copies */ 806 - acm->port.func.bind = acm_bind; 807 - acm->port.func.unbind = acm_unbind; 808 - acm->port.func.set_alt = acm_set_alt; 809 - acm->port.func.setup = acm_setup; 810 - acm->port.func.disable = acm_disable; 741 + acm->port.func.unbind = acm_old_unbind; 811 742 812 743 status = usb_add_function(c, &acm->port.func); 813 744 if (status) 814 745 kfree(acm); 815 746 return status; 816 747 } 748 + 749 + #else 750 + 751 + static void acm_unbind(struct usb_configuration *c, struct usb_function *f) 752 + { 753 + struct f_acm *acm = func_to_acm(f); 754 + 755 + acm_string_defs[0].id = 0; 756 + usb_free_all_descriptors(f); 757 + if (acm->notify_req) 758 + gs_free_req(acm->notify, acm->notify_req); 759 + } 760 + 761 + static void acm_free_func(struct usb_function *f) 762 + { 763 + struct f_acm *acm = func_to_acm(f); 764 + 765 + kfree(acm); 766 + } 767 + 768 + static struct usb_function *acm_alloc_func(struct usb_function_instance *fi) 769 + { 770 + struct f_serial_opts *opts; 771 + struct f_acm *acm; 772 + 773 + acm = acm_alloc_basic_func(); 774 + if (!acm) 775 + return ERR_PTR(-ENOMEM); 776 + 777 + opts = container_of(fi, struct f_serial_opts, func_inst); 778 + acm->port_num = opts->port_num; 779 + acm->port.func.unbind = acm_unbind; 780 + acm->port.func.free_func = acm_free_func; 781 + 782 + return &acm->port.func; 783 + } 784 + 785 + static void acm_free_instance(struct usb_function_instance *fi) 786 + { 787 + struct f_serial_opts *opts; 788 + 789 + opts = container_of(fi, struct f_serial_opts, func_inst); 790 + kfree(opts); 791 + } 792 + 793 + static struct usb_function_instance *acm_alloc_instance(void) 794 + { 795 + struct f_serial_opts *opts; 796 + 797 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 798 + if (!opts) 799 + return ERR_PTR(-ENOMEM); 800 + opts->func_inst.free_func_inst = acm_free_instance; 801 + return &opts->func_inst; 802 + } 803 + DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func); 804 + MODULE_LICENSE("GPL"); 805 + #endif
+2 -3
drivers/usb/gadget/f_fs.c
··· 1103 1103 return 0; 1104 1104 1105 1105 for (;;) { 1106 - char *end, *eq, *comma; 1107 1106 unsigned long value; 1107 + char *eq, *comma; 1108 1108 1109 1109 /* Option limit */ 1110 1110 comma = strchr(opts, ','); ··· 1120 1120 *eq = 0; 1121 1121 1122 1122 /* Parse value */ 1123 - value = simple_strtoul(eq + 1, &end, 0); 1124 - if (unlikely(*end != ',' && *end != 0)) { 1123 + if (kstrtoul(eq + 1, 0, &value)) { 1125 1124 pr_err("%s: invalid value: %s\n", opts, eq + 1); 1126 1125 return -EINVAL; 1127 1126 }
+58 -53
drivers/usb/gadget/f_loopback.c
··· 15 15 #include <linux/slab.h> 16 16 #include <linux/kernel.h> 17 17 #include <linux/device.h> 18 + #include <linux/module.h> 19 + #include <linux/err.h> 20 + #include <linux/usb/composite.h> 18 21 19 22 #include "g_zero.h" 20 - #include "gadget_chips.h" 21 - 22 23 23 24 /* 24 25 * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals, ··· 45 44 return container_of(f, struct f_loopback, function); 46 45 } 47 46 48 - static unsigned qlen = 32; 49 - module_param(qlen, uint, 0); 50 - MODULE_PARM_DESC(qlenn, "depth of loopback queue"); 47 + static unsigned qlen; 48 + static unsigned buflen; 51 49 52 50 /*-------------------------------------------------------------------------*/ 53 51 ··· 171 171 172 172 /*-------------------------------------------------------------------------*/ 173 173 174 - static int __init 175 - loopback_bind(struct usb_configuration *c, struct usb_function *f) 174 + static int loopback_bind(struct usb_configuration *c, struct usb_function *f) 176 175 { 177 176 struct usb_composite_dev *cdev = c->cdev; 178 177 struct f_loopback *loop = func_to_loop(f); ··· 183 184 if (id < 0) 184 185 return id; 185 186 loopback_intf.bInterfaceNumber = id; 187 + 188 + id = usb_string_id(cdev); 189 + if (id < 0) 190 + return id; 191 + strings_loopback[0].id = id; 192 + loopback_intf.iInterface = id; 186 193 187 194 /* allocate endpoints */ 188 195 ··· 228 223 return 0; 229 224 } 230 225 231 - static void 232 - loopback_unbind(struct usb_configuration *c, struct usb_function *f) 226 + static void lb_free_func(struct usb_function *f) 233 227 { 234 228 usb_free_all_descriptors(f); 235 229 kfree(func_to_loop(f)); ··· 370 366 disable_loopback(loop); 371 367 } 372 368 373 - /*-------------------------------------------------------------------------*/ 374 - 375 - static int __init loopback_bind_config(struct usb_configuration *c) 369 + static struct usb_function *loopback_alloc(struct usb_function_instance *fi) 376 370 { 377 371 struct f_loopback *loop; 378 - int status; 372 + struct f_lb_opts *lb_opts; 379 373 380 374 loop = kzalloc(sizeof *loop, GFP_KERNEL); 381 375 if (!loop) 382 - return -ENOMEM; 376 + return ERR_PTR(-ENOMEM); 377 + 378 + lb_opts = container_of(fi, struct f_lb_opts, func_inst); 379 + buflen = lb_opts->bulk_buflen; 380 + qlen = lb_opts->qlen; 381 + if (!qlen) 382 + qlen = 32; 383 383 384 384 loop->function.name = "loopback"; 385 385 loop->function.bind = loopback_bind; 386 - loop->function.unbind = loopback_unbind; 387 386 loop->function.set_alt = loopback_set_alt; 388 387 loop->function.disable = loopback_disable; 388 + loop->function.strings = loopback_strings; 389 389 390 - status = usb_add_function(c, &loop->function); 391 - if (status) 392 - kfree(loop); 393 - return status; 390 + loop->function.free_func = lb_free_func; 391 + 392 + return &loop->function; 394 393 } 395 394 396 - static struct usb_configuration loopback_driver = { 397 - .label = "loopback", 398 - .strings = loopback_strings, 399 - .bConfigurationValue = 2, 400 - .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 401 - /* .iConfiguration = DYNAMIC */ 402 - }; 403 - 404 - /** 405 - * loopback_add - add a loopback testing configuration to a device 406 - * @cdev: the device to support the loopback configuration 407 - */ 408 - int __init loopback_add(struct usb_composite_dev *cdev, bool autoresume) 395 + static void lb_free_instance(struct usb_function_instance *fi) 409 396 { 410 - int id; 397 + struct f_lb_opts *lb_opts; 411 398 412 - /* allocate string ID(s) */ 413 - id = usb_string_id(cdev); 414 - if (id < 0) 415 - return id; 416 - strings_loopback[0].id = id; 417 - 418 - loopback_intf.iInterface = id; 419 - loopback_driver.iConfiguration = id; 420 - 421 - /* support autoresume for remote wakeup testing */ 422 - if (autoresume) 423 - loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 424 - 425 - /* support OTG systems */ 426 - if (gadget_is_otg(cdev->gadget)) { 427 - loopback_driver.descriptors = otg_desc; 428 - loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 429 - } 430 - 431 - return usb_add_config(cdev, &loopback_driver, loopback_bind_config); 399 + lb_opts = container_of(fi, struct f_lb_opts, func_inst); 400 + kfree(lb_opts); 432 401 } 402 + 403 + static struct usb_function_instance *loopback_alloc_instance(void) 404 + { 405 + struct f_lb_opts *lb_opts; 406 + 407 + lb_opts = kzalloc(sizeof(*lb_opts), GFP_KERNEL); 408 + if (!lb_opts) 409 + return ERR_PTR(-ENOMEM); 410 + lb_opts->func_inst.free_func_inst = lb_free_instance; 411 + return &lb_opts->func_inst; 412 + } 413 + DECLARE_USB_FUNCTION(Loopback, loopback_alloc_instance, loopback_alloc); 414 + 415 + int __init lb_modinit(void) 416 + { 417 + int ret; 418 + 419 + ret = usb_function_register(&Loopbackusb_func); 420 + if (ret) 421 + return ret; 422 + return ret; 423 + } 424 + void __exit lb_modexit(void) 425 + { 426 + usb_function_unregister(&Loopbackusb_func); 427 + } 428 + 429 + MODULE_LICENSE("GPL");
+5 -32
drivers/usb/gadget/f_mass_storage.c
··· 246 246 * set). 247 247 */ 248 248 int (*thread_exits)(struct fsg_common *common); 249 - 250 - /* 251 - * Called prior to ejection. Negative return means error, 252 - * zero means to continue with ejection, positive means not to 253 - * eject. 254 - */ 255 - int (*pre_eject)(struct fsg_common *common, 256 - struct fsg_lun *lun, int num); 257 - /* 258 - * Called after ejection. Negative return means error, zero 259 - * or positive is just a success. 260 - */ 261 - int (*post_eject)(struct fsg_common *common, 262 - struct fsg_lun *lun, int num); 263 249 }; 264 250 265 251 /* Data shared by all the FSG instances. */ ··· 1360 1374 if (!loej) 1361 1375 return 0; 1362 1376 1363 - /* Simulate an unload/eject */ 1364 - if (common->ops && common->ops->pre_eject) { 1365 - int r = common->ops->pre_eject(common, curlun, 1366 - curlun - common->luns); 1367 - if (unlikely(r < 0)) 1368 - return r; 1369 - else if (r) 1370 - return 0; 1371 - } 1372 - 1373 1377 up_read(&common->filesem); 1374 1378 down_write(&common->filesem); 1375 1379 fsg_lun_close(curlun); 1376 1380 up_write(&common->filesem); 1377 1381 down_read(&common->filesem); 1378 1382 1379 - return common->ops && common->ops->post_eject 1380 - ? min(0, common->ops->post_eject(common, curlun, 1381 - curlun - common->luns)) 1382 - : 0; 1383 + return 0; 1383 1384 } 1384 1385 1385 1386 static int do_prevent_allow(struct fsg_common *common) ··· 1691 1718 int needs_medium, const char *name) 1692 1719 { 1693 1720 int i; 1694 - int lun = common->cmnd[1] >> 5; 1721 + unsigned int lun = common->cmnd[1] >> 5; 1695 1722 static const char dirletter[4] = {'u', 'o', 'i', 'n'}; 1696 1723 char hdlen[20]; 1697 1724 struct fsg_lun *curlun; ··· 1757 1784 1758 1785 /* Check that the LUN values are consistent */ 1759 1786 if (common->lun != lun) 1760 - DBG(common, "using LUN %d from CBW, not LUN %d from CDB\n", 1787 + DBG(common, "using LUN %u from CBW, not LUN %u from CDB\n", 1761 1788 common->lun, lun); 1762 1789 1763 1790 /* Check the LUN */ ··· 1777 1804 */ 1778 1805 if (common->cmnd[0] != INQUIRY && 1779 1806 common->cmnd[0] != REQUEST_SENSE) { 1780 - DBG(common, "unsupported LUN %d\n", common->lun); 1807 + DBG(common, "unsupported LUN %u\n", common->lun); 1781 1808 return -EINVAL; 1782 1809 } 1783 1810 } ··· 2169 2196 if (common->data_size == 0) 2170 2197 common->data_dir = DATA_DIR_NONE; 2171 2198 common->lun = cbw->Lun; 2172 - if (common->lun >= 0 && common->lun < common->nluns) 2199 + if (common->lun < common->nluns) 2173 2200 common->curlun = &common->luns[common->lun]; 2174 2201 else 2175 2202 common->curlun = NULL;
+9 -9
drivers/usb/gadget/f_ncm.c
··· 56 56 u8 notify_state; 57 57 bool is_open; 58 58 59 - struct ndp_parser_opts *parser_opts; 59 + const struct ndp_parser_opts *parser_opts; 60 60 bool is_crc; 61 + u32 ndp_sign; 61 62 62 63 /* 63 64 * for notification, it is accessed from both ··· 391 390 .next_fp_index = 2, \ 392 391 } 393 392 394 - static struct ndp_parser_opts ndp16_opts = INIT_NDP16_OPTS; 395 - static struct ndp_parser_opts ndp32_opts = INIT_NDP32_OPTS; 393 + static const struct ndp_parser_opts ndp16_opts = INIT_NDP16_OPTS; 394 + static const struct ndp_parser_opts ndp32_opts = INIT_NDP32_OPTS; 396 395 397 396 static inline void put_ncm(__le16 **p, unsigned size, unsigned val) 398 397 { ··· 733 732 default: 734 733 goto invalid; 735 734 } 736 - ncm->parser_opts->ndp_sign &= ~NCM_NDP_HDR_CRC_MASK; 737 - ncm->parser_opts->ndp_sign |= ndp_hdr_crc; 735 + ncm->ndp_sign = ncm->parser_opts->ndp_sign | ndp_hdr_crc; 738 736 value = 0; 739 737 break; 740 738 } ··· 875 875 int ndp_align; 876 876 int ndp_pad; 877 877 unsigned max_size = ncm->port.fixed_in_len; 878 - struct ndp_parser_opts *opts = ncm->parser_opts; 878 + const struct ndp_parser_opts *opts = ncm->parser_opts; 879 879 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; 880 880 881 881 div = le16_to_cpu(ntb_parameters.wNdpInDivisor); ··· 921 921 tmp = (void *)tmp + ndp_pad; 922 922 923 923 /* NDP */ 924 - put_unaligned_le32(opts->ndp_sign, tmp); /* dwSignature */ 924 + put_unaligned_le32(ncm->ndp_sign, tmp); /* dwSignature */ 925 925 tmp += 2; 926 926 /* wLength */ 927 927 put_unaligned_le16(ncb_len - opts->nth_size - pad, tmp++); ··· 965 965 struct sk_buff *skb2; 966 966 int ret = -EINVAL; 967 967 unsigned max_size = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); 968 - struct ndp_parser_opts *opts = ncm->parser_opts; 968 + const struct ndp_parser_opts *opts = ncm->parser_opts; 969 969 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; 970 970 int dgram_counter; 971 971 ··· 1002 1002 1003 1003 /* walk through NDP */ 1004 1004 tmp = ((void *)skb->data) + index; 1005 - if (get_unaligned_le32(tmp) != opts->ndp_sign) { 1005 + if (get_unaligned_le32(tmp) != ncm->ndp_sign) { 1006 1006 INFO(port->func.config->cdev, "Wrong NDP SIGN\n"); 1007 1007 goto err; 1008 1008 }
-4
drivers/usb/gadget/f_obex.c
··· 406 406 * Context: single threaded during gadget setup 407 407 * 408 408 * Returns zero on success, else negative errno. 409 - * 410 - * Caller must have called @gserial_setup() with enough ports to 411 - * handle all the ones it binds. Caller is also responsible 412 - * for calling @gserial_cleanup() before module unload. 413 409 */ 414 410 int __init obex_bind_config(struct usb_configuration *c, u8 port_num) 415 411 {
-4
drivers/usb/gadget/f_serial.c
··· 260 260 * Context: single threaded during gadget setup 261 261 * 262 262 * Returns zero on success, else negative errno. 263 - * 264 - * Caller must have called @gserial_setup() with enough ports to 265 - * handle all the ones it binds. Caller is also responsible 266 - * for calling @gserial_cleanup() before module unload. 267 263 */ 268 264 int __init gser_bind_config(struct usb_configuration *c, u8 port_num) 269 265 {
+126 -76
drivers/usb/gadget/f_sourcesink.c
··· 16 16 #include <linux/kernel.h> 17 17 #include <linux/device.h> 18 18 #include <linux/module.h> 19 + #include <linux/usb/composite.h> 20 + #include <linux/err.h> 19 21 20 22 #include "g_zero.h" 21 23 #include "gadget_chips.h" 22 - 23 24 24 25 /* 25 26 * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral ··· 63 62 } 64 63 65 64 static unsigned pattern; 66 - module_param(pattern, uint, S_IRUGO|S_IWUSR); 67 - MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63, 2 = none"); 68 - 69 - static unsigned isoc_interval = 4; 70 - module_param(isoc_interval, uint, S_IRUGO|S_IWUSR); 71 - MODULE_PARM_DESC(isoc_interval, "1 - 16"); 72 - 73 - static unsigned isoc_maxpacket = 1024; 74 - module_param(isoc_maxpacket, uint, S_IRUGO|S_IWUSR); 75 - MODULE_PARM_DESC(isoc_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)"); 76 - 65 + static unsigned isoc_interval; 66 + static unsigned isoc_maxpacket; 77 67 static unsigned isoc_mult; 78 - module_param(isoc_mult, uint, S_IRUGO|S_IWUSR); 79 - MODULE_PARM_DESC(isoc_mult, "0 - 2 (hs/ss only)"); 80 - 81 68 static unsigned isoc_maxburst; 82 - module_param(isoc_maxburst, uint, S_IRUGO|S_IWUSR); 83 - MODULE_PARM_DESC(isoc_maxburst, "0 - 15 (ss only)"); 69 + static unsigned buflen; 84 70 85 71 /*-------------------------------------------------------------------------*/ 86 72 ··· 301 313 302 314 /*-------------------------------------------------------------------------*/ 303 315 304 - static int __init 316 + struct usb_request *alloc_ep_req(struct usb_ep *ep, int len) 317 + { 318 + struct usb_request *req; 319 + 320 + req = usb_ep_alloc_request(ep, GFP_ATOMIC); 321 + if (req) { 322 + if (len) 323 + req->length = len; 324 + else 325 + req->length = buflen; 326 + req->buf = kmalloc(req->length, GFP_ATOMIC); 327 + if (!req->buf) { 328 + usb_ep_free_request(ep, req); 329 + req = NULL; 330 + } 331 + } 332 + return req; 333 + } 334 + 335 + void free_ep_req(struct usb_ep *ep, struct usb_request *req) 336 + { 337 + kfree(req->buf); 338 + usb_ep_free_request(ep, req); 339 + } 340 + 341 + static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep) 342 + { 343 + int value; 344 + 345 + if (ep->driver_data) { 346 + value = usb_ep_disable(ep); 347 + if (value < 0) 348 + DBG(cdev, "disable %s --> %d\n", 349 + ep->name, value); 350 + ep->driver_data = NULL; 351 + } 352 + } 353 + 354 + void disable_endpoints(struct usb_composite_dev *cdev, 355 + struct usb_ep *in, struct usb_ep *out, 356 + struct usb_ep *iso_in, struct usb_ep *iso_out) 357 + { 358 + disable_ep(cdev, in); 359 + disable_ep(cdev, out); 360 + if (iso_in) 361 + disable_ep(cdev, iso_in); 362 + if (iso_out) 363 + disable_ep(cdev, iso_out); 364 + } 365 + 366 + static int 305 367 sourcesink_bind(struct usb_configuration *c, struct usb_function *f) 306 368 { 307 369 struct usb_composite_dev *cdev = c->cdev; ··· 488 450 } 489 451 490 452 static void 491 - sourcesink_unbind(struct usb_configuration *c, struct usb_function *f) 453 + sourcesink_free_func(struct usb_function *f) 492 454 { 493 455 usb_free_all_descriptors(f); 494 456 kfree(func_to_ss(f)); ··· 569 531 check_read_data(ss, req); 570 532 if (pattern != 2) 571 533 memset(req->buf, 0x55, req->length); 572 - } else 573 - reinit_write_data(ep, req); 534 + } 574 535 break; 575 536 576 537 /* this endpoint is normally active while we're configured */ ··· 795 758 796 759 /*-------------------------------------------------------------------------*/ 797 760 798 - static int __init sourcesink_bind_config(struct usb_configuration *c) 799 - { 800 - struct f_sourcesink *ss; 801 - int status; 802 - 803 - ss = kzalloc(sizeof *ss, GFP_KERNEL); 804 - if (!ss) 805 - return -ENOMEM; 806 - 807 - ss->function.name = "source/sink"; 808 - ss->function.bind = sourcesink_bind; 809 - ss->function.unbind = sourcesink_unbind; 810 - ss->function.set_alt = sourcesink_set_alt; 811 - ss->function.get_alt = sourcesink_get_alt; 812 - ss->function.disable = sourcesink_disable; 813 - 814 - status = usb_add_function(c, &ss->function); 815 - if (status) 816 - kfree(ss); 817 - return status; 818 - } 819 - 820 - static int sourcesink_setup(struct usb_configuration *c, 761 + static int sourcesink_setup(struct usb_function *f, 821 762 const struct usb_ctrlrequest *ctrl) 822 763 { 764 + struct usb_configuration *c = f->config; 823 765 struct usb_request *req = c->cdev->req; 824 766 int value = -EOPNOTSUPP; 825 767 u16 w_index = le16_to_cpu(ctrl->wIndex); ··· 867 851 return value; 868 852 } 869 853 870 - static struct usb_configuration sourcesink_driver = { 871 - .label = "source/sink", 872 - .strings = sourcesink_strings, 873 - .setup = sourcesink_setup, 874 - .bConfigurationValue = 3, 875 - .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 876 - /* .iConfiguration = DYNAMIC */ 877 - }; 878 - 879 - /** 880 - * sourcesink_add - add a source/sink testing configuration to a device 881 - * @cdev: the device to support the configuration 882 - */ 883 - int __init sourcesink_add(struct usb_composite_dev *cdev, bool autoresume) 854 + static struct usb_function *source_sink_alloc_func( 855 + struct usb_function_instance *fi) 884 856 { 885 - int id; 857 + struct f_sourcesink *ss; 858 + struct f_ss_opts *ss_opts; 886 859 887 - /* allocate string ID(s) */ 888 - id = usb_string_id(cdev); 889 - if (id < 0) 890 - return id; 891 - strings_sourcesink[0].id = id; 860 + ss = kzalloc(sizeof(*ss), GFP_KERNEL); 861 + if (!ss) 862 + return NULL; 892 863 893 - source_sink_intf_alt0.iInterface = id; 894 - source_sink_intf_alt1.iInterface = id; 895 - sourcesink_driver.iConfiguration = id; 864 + ss_opts = container_of(fi, struct f_ss_opts, func_inst); 865 + pattern = ss_opts->pattern; 866 + isoc_interval = ss_opts->isoc_interval; 867 + isoc_maxpacket = ss_opts->isoc_maxpacket; 868 + isoc_mult = ss_opts->isoc_mult; 869 + isoc_maxburst = ss_opts->isoc_maxburst; 870 + buflen = ss_opts->bulk_buflen; 896 871 897 - /* support autoresume for remote wakeup testing */ 898 - if (autoresume) 899 - sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 872 + ss->function.name = "source/sink"; 873 + ss->function.bind = sourcesink_bind; 874 + ss->function.set_alt = sourcesink_set_alt; 875 + ss->function.get_alt = sourcesink_get_alt; 876 + ss->function.disable = sourcesink_disable; 877 + ss->function.setup = sourcesink_setup; 878 + ss->function.strings = sourcesink_strings; 900 879 901 - /* support OTG systems */ 902 - if (gadget_is_otg(cdev->gadget)) { 903 - sourcesink_driver.descriptors = otg_desc; 904 - sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 905 - } 880 + ss->function.free_func = sourcesink_free_func; 906 881 907 - return usb_add_config(cdev, &sourcesink_driver, sourcesink_bind_config); 882 + return &ss->function; 908 883 } 884 + 885 + static void acm_free_instance(struct usb_function_instance *fi) 886 + { 887 + struct f_ss_opts *ss_opts; 888 + 889 + ss_opts = container_of(fi, struct f_ss_opts, func_inst); 890 + kfree(ss_opts); 891 + } 892 + 893 + static struct usb_function_instance *source_sink_alloc_inst(void) 894 + { 895 + struct f_ss_opts *ss_opts; 896 + 897 + ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL); 898 + if (!ss_opts) 899 + return ERR_PTR(-ENOMEM); 900 + ss_opts->func_inst.free_func_inst = acm_free_instance; 901 + return &ss_opts->func_inst; 902 + } 903 + DECLARE_USB_FUNCTION(SourceSink, source_sink_alloc_inst, 904 + source_sink_alloc_func); 905 + 906 + static int __init sslb_modinit(void) 907 + { 908 + int ret; 909 + 910 + ret = usb_function_register(&SourceSinkusb_func); 911 + if (ret) 912 + return ret; 913 + ret = lb_modinit(); 914 + if (ret) 915 + usb_function_unregister(&SourceSinkusb_func); 916 + return ret; 917 + } 918 + static void __exit sslb_modexit(void) 919 + { 920 + usb_function_unregister(&SourceSinkusb_func); 921 + lb_modexit(); 922 + } 923 + module_init(sslb_modinit); 924 + module_exit(sslb_modexit); 925 + 926 + MODULE_LICENSE("GPL");
+2 -7
drivers/usb/gadget/f_uac2.c
··· 260 260 uac2_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 261 261 { 262 262 struct snd_uac2_chip *uac2 = snd_pcm_substream_chip(substream); 263 - struct audio_dev *agdev = uac2_to_agdev(uac2); 264 263 struct uac2_rtd_params *prm; 265 264 unsigned long flags; 266 - struct usb_ep *ep; 267 265 int err = 0; 268 266 269 - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 270 - ep = agdev->in_ep; 267 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 271 268 prm = &uac2->p_prm; 272 - } else { 273 - ep = agdev->out_ep; 269 + else 274 270 prm = &uac2->c_prm; 275 - } 276 271 277 272 spin_lock_irqsave(&prm->lock, flags); 278 273
+2 -1
drivers/usb/gadget/f_uvc.c
··· 16 16 #include <linux/fs.h> 17 17 #include <linux/list.h> 18 18 #include <linux/mutex.h> 19 + #include <linux/string.h> 19 20 #include <linux/usb/ch9.h> 20 21 #include <linux/usb/gadget.h> 21 22 #include <linux/usb/video.h> ··· 420 419 video->parent = &cdev->gadget->dev; 421 420 video->fops = &uvc_v4l2_fops; 422 421 video->release = video_device_release; 423 - strncpy(video->name, cdev->gadget->name, sizeof(video->name)); 422 + strlcpy(video->name, cdev->gadget->name, sizeof(video->name)); 424 423 425 424 uvc->vdev = video; 426 425 video_set_drvdata(video, uvc);
+1 -1
drivers/usb/gadget/fsl_qe_udc.c
··· 1894 1894 struct usb_gadget_driver *driver); 1895 1895 1896 1896 /* defined in usb_gadget.h */ 1897 - static struct usb_gadget_ops qe_gadget_ops = { 1897 + static const struct usb_gadget_ops qe_gadget_ops = { 1898 1898 .get_frame = qe_get_frame, 1899 1899 .udc_start = fsl_qe_start, 1900 1900 .udc_stop = fsl_qe_stop,
+12 -48
drivers/usb/gadget/fsl_udc_core.c
··· 1255 1255 return 0; 1256 1256 } 1257 1257 1258 - static int fsl_start(struct usb_gadget_driver *driver, 1259 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1260 - static int fsl_stop(struct usb_gadget_driver *driver); 1258 + static int fsl_udc_start(struct usb_gadget *g, 1259 + struct usb_gadget_driver *driver); 1260 + static int fsl_udc_stop(struct usb_gadget *g, 1261 + struct usb_gadget_driver *driver); 1261 1262 /* defined in gadget.h */ 1262 - static struct usb_gadget_ops fsl_gadget_ops = { 1263 + static const struct usb_gadget_ops fsl_gadget_ops = { 1263 1264 .get_frame = fsl_get_frame, 1264 1265 .wakeup = fsl_wakeup, 1265 1266 /* .set_selfpowered = fsl_set_selfpowered, */ /* Always selfpowered */ 1266 1267 .vbus_session = fsl_vbus_session, 1267 1268 .vbus_draw = fsl_vbus_draw, 1268 1269 .pullup = fsl_pullup, 1269 - .start = fsl_start, 1270 - .stop = fsl_stop, 1270 + .udc_start = fsl_udc_start, 1271 + .udc_stop = fsl_udc_stop, 1271 1272 }; 1272 1273 1273 1274 /* Set protocol stall on ep0, protocol stall will automatically be cleared ··· 1952 1951 * Hook to gadget drivers 1953 1952 * Called by initialization code of gadget drivers 1954 1953 *----------------------------------------------------------------*/ 1955 - static int fsl_start(struct usb_gadget_driver *driver, 1956 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1954 + static int fsl_udc_start(struct usb_gadget *g, 1955 + struct usb_gadget_driver *driver) 1957 1956 { 1958 - int retval = -ENODEV; 1957 + int retval = 0; 1959 1958 unsigned long flags = 0; 1960 - 1961 - if (!udc_controller) 1962 - return -ENODEV; 1963 - 1964 - if (!driver || driver->max_speed < USB_SPEED_FULL 1965 - || !bind || !driver->disconnect || !driver->setup) 1966 - return -EINVAL; 1967 - 1968 - if (udc_controller->driver) 1969 - return -EBUSY; 1970 1959 1971 1960 /* lock is needed but whether should use this lock or another */ 1972 1961 spin_lock_irqsave(&udc_controller->lock, flags); ··· 1966 1975 udc_controller->driver = driver; 1967 1976 udc_controller->gadget.dev.driver = &driver->driver; 1968 1977 spin_unlock_irqrestore(&udc_controller->lock, flags); 1969 - 1970 - /* bind udc driver to gadget driver */ 1971 - retval = bind(&udc_controller->gadget, driver); 1972 - if (retval) { 1973 - VDBG("bind to %s --> %d", driver->driver.name, retval); 1974 - udc_controller->gadget.dev.driver = NULL; 1975 - udc_controller->driver = NULL; 1976 - goto out; 1977 - } 1978 1978 1979 1979 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) { 1980 1980 /* Suspend the controller until OTG enable it */ ··· 1992 2010 udc_controller->ep0_state = WAIT_FOR_SETUP; 1993 2011 udc_controller->ep0_dir = 0; 1994 2012 } 1995 - printk(KERN_INFO "%s: bind to driver %s\n", 1996 - udc_controller->gadget.name, driver->driver.name); 1997 2013 1998 - out: 1999 - if (retval) 2000 - printk(KERN_WARNING "gadget driver register failed %d\n", 2001 - retval); 2002 2014 return retval; 2003 2015 } 2004 2016 2005 2017 /* Disconnect from gadget driver */ 2006 - static int fsl_stop(struct usb_gadget_driver *driver) 2018 + static int fsl_udc_stop(struct usb_gadget *g, 2019 + struct usb_gadget_driver *driver) 2007 2020 { 2008 2021 struct fsl_ep *loop_ep; 2009 2022 unsigned long flags; 2010 - 2011 - if (!udc_controller) 2012 - return -ENODEV; 2013 - 2014 - if (!driver || driver != udc_controller->driver || !driver->unbind) 2015 - return -EINVAL; 2016 2023 2017 2024 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) 2018 2025 otg_set_peripheral(udc_controller->transceiver->otg, NULL); ··· 2023 2052 nuke(loop_ep, -ESHUTDOWN); 2024 2053 spin_unlock_irqrestore(&udc_controller->lock, flags); 2025 2054 2026 - /* report disconnect; the controller is already quiesced */ 2027 - driver->disconnect(&udc_controller->gadget); 2028 - 2029 - /* unbind gadget and unhook driver. */ 2030 - driver->unbind(&udc_controller->gadget); 2031 2055 udc_controller->gadget.dev.driver = NULL; 2032 2056 udc_controller->driver = NULL; 2033 2057 2034 - printk(KERN_WARNING "unregistered gadget driver '%s'\n", 2035 - driver->driver.name); 2036 2058 return 0; 2037 2059 } 2038 2060
+116
drivers/usb/gadget/functions.c
··· 1 + #include <linux/kernel.h> 2 + #include <linux/slab.h> 3 + #include <linux/module.h> 4 + #include <linux/err.h> 5 + 6 + #include <linux/usb/composite.h> 7 + 8 + static LIST_HEAD(func_list); 9 + static DEFINE_MUTEX(func_lock); 10 + 11 + static struct usb_function_instance *try_get_usb_function_instance(const char *name) 12 + { 13 + struct usb_function_driver *fd; 14 + struct usb_function_instance *fi; 15 + 16 + fi = ERR_PTR(-ENOENT); 17 + mutex_lock(&func_lock); 18 + list_for_each_entry(fd, &func_list, list) { 19 + 20 + if (strcmp(name, fd->name)) 21 + continue; 22 + 23 + if (!try_module_get(fd->mod)) { 24 + fi = ERR_PTR(-EBUSY); 25 + break; 26 + } 27 + fi = fd->alloc_inst(); 28 + if (IS_ERR(fi)) 29 + module_put(fd->mod); 30 + else 31 + fi->fd = fd; 32 + break; 33 + } 34 + mutex_unlock(&func_lock); 35 + return fi; 36 + } 37 + 38 + struct usb_function_instance *usb_get_function_instance(const char *name) 39 + { 40 + struct usb_function_instance *fi; 41 + int ret; 42 + 43 + fi = try_get_usb_function_instance(name); 44 + if (!IS_ERR(fi)) 45 + return fi; 46 + ret = PTR_ERR(fi); 47 + if (ret != -ENOENT) 48 + return fi; 49 + ret = request_module("usbfunc:%s", name); 50 + if (ret < 0) 51 + return ERR_PTR(ret); 52 + return try_get_usb_function_instance(name); 53 + } 54 + EXPORT_SYMBOL_GPL(usb_get_function_instance); 55 + 56 + struct usb_function *usb_get_function(struct usb_function_instance *fi) 57 + { 58 + struct usb_function *f; 59 + 60 + f = fi->fd->alloc_func(fi); 61 + if (IS_ERR(f)) 62 + return f; 63 + f->fi = fi; 64 + return f; 65 + } 66 + EXPORT_SYMBOL_GPL(usb_get_function); 67 + 68 + void usb_put_function_instance(struct usb_function_instance *fi) 69 + { 70 + struct module *mod; 71 + 72 + if (!fi) 73 + return; 74 + 75 + mod = fi->fd->mod; 76 + fi->free_func_inst(fi); 77 + module_put(mod); 78 + } 79 + EXPORT_SYMBOL_GPL(usb_put_function_instance); 80 + 81 + void usb_put_function(struct usb_function *f) 82 + { 83 + if (!f) 84 + return; 85 + 86 + f->free_func(f); 87 + } 88 + EXPORT_SYMBOL_GPL(usb_put_function); 89 + 90 + int usb_function_register(struct usb_function_driver *newf) 91 + { 92 + struct usb_function_driver *fd; 93 + int ret; 94 + 95 + ret = -EEXIST; 96 + 97 + mutex_lock(&func_lock); 98 + list_for_each_entry(fd, &func_list, list) { 99 + if (!strcmp(fd->name, newf->name)) 100 + goto out; 101 + } 102 + ret = 0; 103 + list_add_tail(&newf->list, &func_list); 104 + out: 105 + mutex_unlock(&func_lock); 106 + return ret; 107 + } 108 + EXPORT_SYMBOL_GPL(usb_function_register); 109 + 110 + void usb_function_unregister(struct usb_function_driver *fd) 111 + { 112 + mutex_lock(&func_lock); 113 + list_del(&fd->list); 114 + mutex_unlock(&func_lock); 115 + } 116 + EXPORT_SYMBOL_GPL(usb_function_unregister);
+19 -48
drivers/usb/gadget/fusb300_udc.c
··· 1308 1308 iowrite32(0xcfffff9f, fusb300->reg + FUSB300_OFFSET_IGER1); 1309 1309 } 1310 1310 /*------------------------------------------------------------------------*/ 1311 - static struct fusb300 *the_controller; 1312 - 1313 - static int fusb300_udc_start(struct usb_gadget_driver *driver, 1314 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1311 + static int fusb300_udc_start(struct usb_gadget *g, 1312 + struct usb_gadget_driver *driver) 1315 1313 { 1316 - struct fusb300 *fusb300 = the_controller; 1317 - int retval; 1318 - 1319 - if (!driver 1320 - || driver->max_speed < USB_SPEED_FULL 1321 - || !bind 1322 - || !driver->setup) 1323 - return -EINVAL; 1324 - 1325 - if (!fusb300) 1326 - return -ENODEV; 1327 - 1328 - if (fusb300->driver) 1329 - return -EBUSY; 1314 + struct fusb300 *fusb300 = to_fusb300(g); 1330 1315 1331 1316 /* hook up the driver */ 1332 1317 driver->driver.bus = NULL; 1333 1318 fusb300->driver = driver; 1334 1319 fusb300->gadget.dev.driver = &driver->driver; 1335 1320 1336 - retval = device_add(&fusb300->gadget.dev); 1337 - if (retval) { 1338 - pr_err("device_add error (%d)\n", retval); 1339 - goto error; 1340 - } 1341 - 1342 - retval = bind(&fusb300->gadget, driver); 1343 - if (retval) { 1344 - pr_err("bind to driver error (%d)\n", retval); 1345 - device_del(&fusb300->gadget.dev); 1346 - goto error; 1347 - } 1348 - 1349 1321 return 0; 1350 - 1351 - error: 1352 - fusb300->driver = NULL; 1353 - fusb300->gadget.dev.driver = NULL; 1354 - 1355 - return retval; 1356 1322 } 1357 1323 1358 - static int fusb300_udc_stop(struct usb_gadget_driver *driver) 1324 + static int fusb300_udc_stop(struct usb_gadget *g, 1325 + struct usb_gadget_driver *driver) 1359 1326 { 1360 - struct fusb300 *fusb300 = the_controller; 1361 - 1362 - if (driver != fusb300->driver || !driver->unbind) 1363 - return -EINVAL; 1327 + struct fusb300 *fusb300 = to_fusb300(g); 1364 1328 1365 1329 driver->unbind(&fusb300->gadget); 1366 1330 fusb300->gadget.dev.driver = NULL; 1367 1331 1368 1332 init_controller(fusb300); 1369 - device_del(&fusb300->gadget.dev); 1370 1333 fusb300->driver = NULL; 1371 1334 1372 1335 return 0; ··· 1341 1378 return 0; 1342 1379 } 1343 1380 1344 - static struct usb_gadget_ops fusb300_gadget_ops = { 1381 + static const struct usb_gadget_ops fusb300_gadget_ops = { 1345 1382 .pullup = fusb300_udc_pullup, 1346 - .start = fusb300_udc_start, 1347 - .stop = fusb300_udc_stop, 1383 + .udc_start = fusb300_udc_start, 1384 + .udc_stop = fusb300_udc_stop, 1348 1385 }; 1349 1386 1350 1387 static int __exit fusb300_remove(struct platform_device *pdev) ··· 1468 1505 fusb300->gadget.ep0 = &fusb300->ep[0]->ep; 1469 1506 INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list); 1470 1507 1471 - the_controller = fusb300; 1472 - 1473 1508 fusb300->ep0_req = fusb300_alloc_request(&fusb300->ep[0]->ep, 1474 1509 GFP_KERNEL); 1475 1510 if (fusb300->ep0_req == NULL) ··· 1478 1517 if (ret) 1479 1518 goto err_add_udc; 1480 1519 1520 + ret = device_add(&fusb300->gadget.dev); 1521 + if (ret) { 1522 + pr_err("device_add error (%d)\n", ret); 1523 + goto err_add_device; 1524 + } 1525 + 1481 1526 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1482 1527 1483 1528 return 0; 1529 + 1530 + err_add_device: 1531 + usb_del_gadget_udc(&fusb300->gadget); 1532 + 1484 1533 err_add_udc: 1485 1534 fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req); 1486 1535
+2
drivers/usb/gadget/fusb300_udc.h
··· 673 673 u8 reenum; /* if re-enumeration */ 674 674 }; 675 675 676 + #define to_fusb300(g) (container_of((g), struct fusb300, gadget)) 677 + 676 678 #endif
+27 -8
drivers/usb/gadget/g_zero.h
··· 6 6 #ifndef __G_ZERO_H 7 7 #define __G_ZERO_H 8 8 9 - #include <linux/usb/composite.h> 9 + struct usb_zero_options { 10 + unsigned pattern; 11 + unsigned isoc_interval; 12 + unsigned isoc_maxpacket; 13 + unsigned isoc_mult; 14 + unsigned isoc_maxburst; 15 + unsigned bulk_buflen; 16 + unsigned qlen; 17 + }; 10 18 11 - /* global state */ 12 - extern unsigned buflen; 13 - extern const struct usb_descriptor_header *otg_desc[]; 19 + struct f_ss_opts { 20 + struct usb_function_instance func_inst; 21 + unsigned pattern; 22 + unsigned isoc_interval; 23 + unsigned isoc_maxpacket; 24 + unsigned isoc_mult; 25 + unsigned isoc_maxburst; 26 + unsigned bulk_buflen; 27 + }; 28 + 29 + struct f_lb_opts { 30 + struct usb_function_instance func_inst; 31 + unsigned bulk_buflen; 32 + unsigned qlen; 33 + }; 34 + 35 + void lb_modexit(void); 36 + int lb_modinit(void); 14 37 15 38 /* common utilities */ 16 39 struct usb_request *alloc_ep_req(struct usb_ep *ep, int len); ··· 41 18 void disable_endpoints(struct usb_composite_dev *cdev, 42 19 struct usb_ep *in, struct usb_ep *out, 43 20 struct usb_ep *iso_in, struct usb_ep *iso_out); 44 - 45 - /* configuration-specific linkup */ 46 - int sourcesink_add(struct usb_composite_dev *cdev, bool autoresume); 47 - int loopback_add(struct usb_composite_dev *cdev, bool autoresume); 48 21 49 22 #endif /* __G_ZERO_H */
+1 -1
drivers/usb/gadget/gmidi.c
··· 125 125 .bConfigurationValue = 1, 126 126 /* .iConfiguration = DYNAMIC */ 127 127 .bmAttributes = USB_CONFIG_ATT_ONE, 128 - .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, 128 + .MaxPower = CONFIG_USB_GADGET_VBUS_DRAW, 129 129 }; 130 130 131 131 static int __init midi_bind_config(struct usb_configuration *c)
+14 -56
drivers/usb/gadget/goku_udc.c
··· 993 993 return -EOPNOTSUPP; 994 994 } 995 995 996 - static int goku_start(struct usb_gadget_driver *driver, 997 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 998 - static int goku_stop(struct usb_gadget_driver *driver); 996 + static int goku_udc_start(struct usb_gadget *g, 997 + struct usb_gadget_driver *driver); 998 + static int goku_udc_stop(struct usb_gadget *g, 999 + struct usb_gadget_driver *driver); 999 1000 1000 1001 static const struct usb_gadget_ops goku_ops = { 1001 1002 .get_frame = goku_get_frame, 1002 - .start = goku_start, 1003 - .stop = goku_stop, 1003 + .udc_start = goku_udc_start, 1004 + .udc_stop = goku_udc_stop, 1004 1005 // no remote wakeup 1005 1006 // not selfpowered 1006 1007 }; ··· 1340 1339 * - one function driver, initted second 1341 1340 */ 1342 1341 1343 - static struct goku_udc *the_controller; 1344 - 1345 1342 /* when a driver is successfully registered, it will receive 1346 1343 * control requests including set_configuration(), which enables 1347 1344 * non-control requests. then usb traffic follows until a 1348 1345 * disconnect is reported. then a host may connect again, or 1349 1346 * the driver might get unbound. 1350 1347 */ 1351 - static int goku_start(struct usb_gadget_driver *driver, 1352 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1348 + static int goku_udc_start(struct usb_gadget *g, 1349 + struct usb_gadget_driver *driver) 1353 1350 { 1354 - struct goku_udc *dev = the_controller; 1355 - int retval; 1356 - 1357 - if (!driver 1358 - || driver->max_speed < USB_SPEED_FULL 1359 - || !bind 1360 - || !driver->disconnect 1361 - || !driver->setup) 1362 - return -EINVAL; 1363 - if (!dev) 1364 - return -ENODEV; 1365 - if (dev->driver) 1366 - return -EBUSY; 1351 + struct goku_udc *dev = to_goku_udc(g); 1367 1352 1368 1353 /* hook up the driver */ 1369 1354 driver->driver.bus = NULL; 1370 1355 dev->driver = driver; 1371 1356 dev->gadget.dev.driver = &driver->driver; 1372 - retval = bind(&dev->gadget, driver); 1373 - if (retval) { 1374 - DBG(dev, "bind to driver %s --> error %d\n", 1375 - driver->driver.name, retval); 1376 - dev->driver = NULL; 1377 - dev->gadget.dev.driver = NULL; 1378 - return retval; 1379 - } 1380 1357 1381 - /* then enable host detection and ep0; and we're ready 1358 + /* 1359 + * then enable host detection and ep0; and we're ready 1382 1360 * for set_configuration as well as eventual disconnect. 1383 1361 */ 1384 1362 udc_enable(dev); 1385 1363 1386 - DBG(dev, "registered gadget driver '%s'\n", driver->driver.name); 1387 1364 return 0; 1388 1365 } 1389 1366 ··· 1379 1400 udc_reset (dev); 1380 1401 for (i = 0; i < 4; i++) 1381 1402 nuke(&dev->ep [i], -ESHUTDOWN); 1382 - if (driver) { 1383 - spin_unlock(&dev->lock); 1384 - driver->disconnect(&dev->gadget); 1385 - spin_lock(&dev->lock); 1386 - } 1387 1403 1388 1404 if (dev->driver) 1389 1405 udc_enable(dev); 1390 1406 } 1391 1407 1392 - static int goku_stop(struct usb_gadget_driver *driver) 1408 + static int goku_udc_stop(struct usb_gadget *g, 1409 + struct usb_gadget_driver *driver) 1393 1410 { 1394 - struct goku_udc *dev = the_controller; 1411 + struct goku_udc *dev = to_goku_udc(g); 1395 1412 unsigned long flags; 1396 - 1397 - if (!dev) 1398 - return -ENODEV; 1399 - if (!driver || driver != dev->driver || !driver->unbind) 1400 - return -EINVAL; 1401 1413 1402 1414 spin_lock_irqsave(&dev->lock, flags); 1403 1415 dev->driver = NULL; 1404 1416 stop_activity(dev, driver); 1405 1417 spin_unlock_irqrestore(&dev->lock, flags); 1406 - 1407 - driver->unbind(&dev->gadget); 1408 1418 dev->gadget.dev.driver = NULL; 1409 1419 1410 - DBG(dev, "unregistered driver '%s'\n", driver->driver.name); 1411 1420 return 0; 1412 1421 } 1413 1422 ··· 1721 1754 1722 1755 pci_set_drvdata(pdev, NULL); 1723 1756 dev->regs = NULL; 1724 - the_controller = NULL; 1725 1757 1726 1758 INFO(dev, "unbind\n"); 1727 1759 } ··· 1736 1770 void __iomem *base = NULL; 1737 1771 int retval; 1738 1772 1739 - /* if you want to support more than one controller in a system, 1740 - * usb_gadget_driver_{register,unregister}() must change. 1741 - */ 1742 - if (the_controller) { 1743 - pr_warning("ignoring %s\n", pci_name(pdev)); 1744 - return -EBUSY; 1745 - } 1746 1773 if (!pdev->irq) { 1747 1774 printk(KERN_ERR "Check PCI %s IRQ setup!\n", pci_name(pdev)); 1748 1775 retval = -ENODEV; ··· 1810 1851 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev); 1811 1852 #endif 1812 1853 1813 - the_controller = dev; 1814 1854 retval = device_register(&dev->gadget.dev); 1815 1855 if (retval) { 1816 1856 put_device(&dev->gadget.dev);
+1
drivers/usb/gadget/goku_udc.h
··· 261 261 /* statistics... */ 262 262 unsigned long irqs; 263 263 }; 264 + #define to_goku_udc(g) (container_of((g), struct goku_udc, gadget)) 264 265 265 266 /*-------------------------------------------------------------------------*/ 266 267
+20 -52
drivers/usb/gadget/m66592-udc.c
··· 1463 1463 }; 1464 1464 1465 1465 /*-------------------------------------------------------------------------*/ 1466 - static struct m66592 *the_controller; 1467 - 1468 - static int m66592_start(struct usb_gadget_driver *driver, 1469 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1466 + static int m66592_udc_start(struct usb_gadget *g, 1467 + struct usb_gadget_driver *driver) 1470 1468 { 1471 - struct m66592 *m66592 = the_controller; 1472 - int retval; 1473 - 1474 - if (!driver 1475 - || driver->max_speed < USB_SPEED_HIGH 1476 - || !bind 1477 - || !driver->setup) 1478 - return -EINVAL; 1479 - if (!m66592) 1480 - return -ENODEV; 1481 - if (m66592->driver) 1482 - return -EBUSY; 1469 + struct m66592 *m66592 = to_m66592(g); 1483 1470 1484 1471 /* hook up the driver */ 1485 1472 driver->driver.bus = NULL; 1486 1473 m66592->driver = driver; 1487 1474 m66592->gadget.dev.driver = &driver->driver; 1488 - 1489 - retval = device_add(&m66592->gadget.dev); 1490 - if (retval) { 1491 - pr_err("device_add error (%d)\n", retval); 1492 - goto error; 1493 - } 1494 - 1495 - retval = bind(&m66592->gadget, driver); 1496 - if (retval) { 1497 - pr_err("bind to driver error (%d)\n", retval); 1498 - device_del(&m66592->gadget.dev); 1499 - goto error; 1500 - } 1501 1475 1502 1476 m66592_bset(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); 1503 1477 if (m66592_read(m66592, M66592_INTSTS0) & M66592_VBSTS) { ··· 1484 1510 } 1485 1511 1486 1512 return 0; 1487 - 1488 - error: 1489 - m66592->driver = NULL; 1490 - m66592->gadget.dev.driver = NULL; 1491 - 1492 - return retval; 1493 1513 } 1494 1514 1495 - static int m66592_stop(struct usb_gadget_driver *driver) 1515 + static int m66592_udc_stop(struct usb_gadget *g, 1516 + struct usb_gadget_driver *driver) 1496 1517 { 1497 - struct m66592 *m66592 = the_controller; 1498 - unsigned long flags; 1499 - 1500 - if (driver != m66592->driver || !driver->unbind) 1501 - return -EINVAL; 1502 - 1503 - spin_lock_irqsave(&m66592->lock, flags); 1504 - if (m66592->gadget.speed != USB_SPEED_UNKNOWN) 1505 - m66592_usb_disconnect(m66592); 1506 - spin_unlock_irqrestore(&m66592->lock, flags); 1518 + struct m66592 *m66592 = to_m66592(g); 1507 1519 1508 1520 m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); 1509 1521 ··· 1499 1539 init_controller(m66592); 1500 1540 disable_controller(m66592); 1501 1541 1502 - device_del(&m66592->gadget.dev); 1503 1542 m66592->driver = NULL; 1543 + 1504 1544 return 0; 1505 1545 } 1506 1546 ··· 1526 1566 return 0; 1527 1567 } 1528 1568 1529 - static struct usb_gadget_ops m66592_gadget_ops = { 1569 + static const struct usb_gadget_ops m66592_gadget_ops = { 1530 1570 .get_frame = m66592_get_frame, 1531 - .start = m66592_start, 1532 - .stop = m66592_stop, 1571 + .udc_start = m66592_udc_start, 1572 + .udc_stop = m66592_udc_stop, 1533 1573 .pullup = m66592_pullup, 1534 1574 }; 1535 1575 ··· 1538 1578 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); 1539 1579 1540 1580 usb_del_gadget_udc(&m66592->gadget); 1581 + device_del(&m66592->gadget.dev); 1541 1582 1542 1583 del_timer_sync(&m66592->timer); 1543 1584 iounmap(m66592->reg); ··· 1667 1706 m66592->pipenum2ep[0] = &m66592->ep[0]; 1668 1707 m66592->epaddr2ep[0] = &m66592->ep[0]; 1669 1708 1670 - the_controller = m66592; 1671 - 1672 1709 m66592->ep0_req = m66592_alloc_request(&m66592->ep[0].ep, GFP_KERNEL); 1673 1710 if (m66592->ep0_req == NULL) 1674 1711 goto clean_up3; 1675 1712 m66592->ep0_req->complete = nop_completion; 1676 1713 1677 1714 init_controller(m66592); 1715 + 1716 + ret = device_add(&m66592->gadget.dev); 1717 + if (ret) { 1718 + pr_err("device_add error (%d)\n", ret); 1719 + goto err_device_add; 1720 + } 1678 1721 1679 1722 ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget); 1680 1723 if (ret) ··· 1688 1723 return 0; 1689 1724 1690 1725 err_add_udc: 1726 + device_del(&m66592->gadget.dev); 1727 + 1728 + err_device_add: 1691 1729 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); 1692 1730 1693 1731 clean_up3:
+1
drivers/usb/gadget/m66592-udc.h
··· 492 492 int isochronous; 493 493 int num_dma; 494 494 }; 495 + #define to_m66592(g) (container_of((g), struct m66592, gadget)) 495 496 496 497 #define gadget_to_m66592(_gadget) container_of(_gadget, struct m66592, gadget) 497 498 #define m66592_to_gadget(m66592) (&m66592->gadget)
+56 -15
drivers/usb/gadget/multi.c
··· 16 16 #include <linux/kernel.h> 17 17 #include <linux/module.h> 18 18 19 + #include "u_serial.h" 19 20 #if defined USB_ETH_RNDIS 20 21 # undef USB_ETH_RNDIS 21 22 #endif ··· 42 41 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 43 42 */ 44 43 #include "f_mass_storage.c" 45 - 46 - #include "u_serial.c" 47 - #include "f_acm.c" 48 44 49 45 #include "f_ecm.c" 50 46 #include "f_subset.c" ··· 135 137 136 138 static u8 hostaddr[ETH_ALEN]; 137 139 140 + static unsigned char tty_line; 141 + static struct usb_function_instance *fi_acm; 138 142 139 143 /********** RNDIS **********/ 140 144 141 145 #ifdef USB_ETH_RNDIS 146 + static struct usb_function *f_acm_rndis; 142 147 143 148 static __init int rndis_do_config(struct usb_configuration *c) 144 149 { ··· 156 155 if (ret < 0) 157 156 return ret; 158 157 159 - ret = acm_bind_config(c, 0); 160 - if (ret < 0) 161 - return ret; 158 + f_acm_rndis = usb_get_function(fi_acm); 159 + if (IS_ERR(f_acm_rndis)) 160 + goto err_func_acm; 161 + 162 + ret = usb_add_function(c, f_acm_rndis); 163 + if (ret) 164 + goto err_conf; 162 165 163 166 ret = fsg_bind_config(c->cdev, c, &fsg_common); 164 167 if (ret < 0) 165 - return ret; 168 + goto err_fsg; 166 169 167 170 return 0; 171 + err_fsg: 172 + usb_remove_function(c, f_acm_rndis); 173 + err_conf: 174 + usb_put_function(f_acm_rndis); 175 + err_func_acm: 176 + return ret; 168 177 } 169 178 170 179 static int rndis_config_register(struct usb_composite_dev *cdev) ··· 203 192 /********** CDC ECM **********/ 204 193 205 194 #ifdef CONFIG_USB_G_MULTI_CDC 195 + static struct usb_function *f_acm_multi; 206 196 207 197 static __init int cdc_do_config(struct usb_configuration *c) 208 198 { ··· 218 206 if (ret < 0) 219 207 return ret; 220 208 221 - ret = acm_bind_config(c, 0); 222 - if (ret < 0) 223 - return ret; 209 + /* implicit port_num is zero */ 210 + f_acm_multi = usb_get_function(fi_acm); 211 + if (IS_ERR(f_acm_multi)) 212 + goto err_func_acm; 213 + 214 + ret = usb_add_function(c, f_acm_multi); 215 + if (ret) 216 + goto err_conf; 224 217 225 218 ret = fsg_bind_config(c->cdev, c, &fsg_common); 226 219 if (ret < 0) 227 - return ret; 220 + goto err_fsg; 228 221 229 222 return 0; 223 + err_fsg: 224 + usb_remove_function(c, f_acm_multi); 225 + err_conf: 226 + usb_put_function(f_acm_multi); 227 + err_func_acm: 228 + return ret; 230 229 } 231 230 232 231 static int cdc_config_register(struct usb_composite_dev *cdev) ··· 266 243 267 244 /****************************** Gadget Bind ******************************/ 268 245 269 - 270 246 static int __ref multi_bind(struct usb_composite_dev *cdev) 271 247 { 272 248 struct usb_gadget *gadget = cdev->gadget; 249 + struct f_serial_opts *opts; 273 250 int status; 274 251 275 252 if (!can_support_ecm(cdev->gadget)) { ··· 284 261 return status; 285 262 286 263 /* set up serial link layer */ 287 - status = gserial_setup(cdev->gadget, 1); 264 + status = gserial_alloc_line(&tty_line); 288 265 if (status < 0) 289 266 goto fail0; 267 + 268 + fi_acm = usb_get_function_instance("acm"); 269 + if (IS_ERR(fi_acm)) { 270 + status = PTR_ERR(fi_acm); 271 + goto fail0dot5; 272 + } 273 + 274 + opts = container_of(fi_acm, struct f_serial_opts, func_inst); 275 + opts->port_num = tty_line; 290 276 291 277 /* set up mass storage function */ 292 278 { ··· 333 301 fail2: 334 302 fsg_common_put(&fsg_common); 335 303 fail1: 336 - gserial_cleanup(); 304 + usb_put_function_instance(fi_acm); 305 + fail0dot5: 306 + gserial_free_line(tty_line); 337 307 fail0: 338 308 gether_cleanup(); 339 309 return status; ··· 343 309 344 310 static int __exit multi_unbind(struct usb_composite_dev *cdev) 345 311 { 346 - gserial_cleanup(); 312 + #ifdef CONFIG_USB_G_MULTI_CDC 313 + usb_put_function(f_acm_multi); 314 + #endif 315 + #ifdef USB_ETH_RNDIS 316 + usb_put_function(f_acm_rndis); 317 + #endif 318 + usb_put_function_instance(fi_acm); 319 + gserial_free_line(tty_line); 347 320 gether_cleanup(); 348 321 return 0; 349 322 }
+99 -147
drivers/usb/gadget/mv_udc_core.c
··· 61 61 static const char driver_name[] = "mv_udc"; 62 62 static const char driver_desc[] = DRIVER_DESC; 63 63 64 - /* controller device global variable */ 65 - static struct mv_udc *the_controller; 66 - 67 64 static void nuke(struct mv_ep *ep, int status); 68 65 static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver); 69 66 ··· 1265 1268 return retval; 1266 1269 } 1267 1270 1268 - static int mv_udc_start(struct usb_gadget_driver *driver, 1269 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1270 - static int mv_udc_stop(struct usb_gadget_driver *driver); 1271 + static int mv_udc_start(struct usb_gadget *, struct usb_gadget_driver *); 1272 + static int mv_udc_stop(struct usb_gadget *, struct usb_gadget_driver *); 1271 1273 /* device controller usb_gadget_ops structure */ 1272 1274 static const struct usb_gadget_ops mv_ops = { 1273 1275 ··· 1281 1285 1282 1286 /* D+ pullup, software-controlled connect/disconnect to USB host */ 1283 1287 .pullup = mv_udc_pullup, 1284 - .start = mv_udc_start, 1285 - .stop = mv_udc_stop, 1288 + .udc_start = mv_udc_start, 1289 + .udc_stop = mv_udc_stop, 1286 1290 }; 1287 1291 1288 1292 static int eps_init(struct mv_udc *udc) ··· 1369 1373 } 1370 1374 } 1371 1375 1372 - static int mv_udc_start(struct usb_gadget_driver *driver, 1373 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1376 + static int mv_udc_start(struct usb_gadget *gadget, 1377 + struct usb_gadget_driver *driver) 1374 1378 { 1375 - struct mv_udc *udc = the_controller; 1379 + struct mv_udc *udc; 1376 1380 int retval = 0; 1377 1381 unsigned long flags; 1378 1382 1379 - if (!udc) 1380 - return -ENODEV; 1383 + udc = container_of(gadget, struct mv_udc, gadget); 1381 1384 1382 1385 if (udc->driver) 1383 1386 return -EBUSY; ··· 1394 1399 1395 1400 spin_unlock_irqrestore(&udc->lock, flags); 1396 1401 1397 - retval = bind(&udc->gadget, driver); 1398 - if (retval) { 1399 - dev_err(&udc->dev->dev, "bind to driver %s --> %d\n", 1400 - driver->driver.name, retval); 1401 - udc->driver = NULL; 1402 - udc->gadget.dev.driver = NULL; 1403 - return retval; 1404 - } 1405 - 1406 - if (!IS_ERR_OR_NULL(udc->transceiver)) { 1402 + if (udc->transceiver) { 1407 1403 retval = otg_set_peripheral(udc->transceiver->otg, 1408 1404 &udc->gadget); 1409 1405 if (retval) { 1410 1406 dev_err(&udc->dev->dev, 1411 1407 "unable to register peripheral to otg\n"); 1412 - if (driver->unbind) { 1413 - driver->unbind(&udc->gadget); 1414 - udc->gadget.dev.driver = NULL; 1415 - udc->driver = NULL; 1416 - } 1408 + udc->driver = NULL; 1409 + udc->gadget.dev.driver = NULL; 1417 1410 return retval; 1418 1411 } 1419 1412 } ··· 1416 1433 return 0; 1417 1434 } 1418 1435 1419 - static int mv_udc_stop(struct usb_gadget_driver *driver) 1436 + static int mv_udc_stop(struct usb_gadget *gadget, 1437 + struct usb_gadget_driver *driver) 1420 1438 { 1421 - struct mv_udc *udc = the_controller; 1439 + struct mv_udc *udc; 1422 1440 unsigned long flags; 1423 1441 1424 - if (!udc) 1425 - return -ENODEV; 1442 + udc = container_of(gadget, struct mv_udc, gadget); 1426 1443 1427 1444 spin_lock_irqsave(&udc->lock, flags); 1428 1445 ··· 1437 1454 spin_unlock_irqrestore(&udc->lock, flags); 1438 1455 1439 1456 /* unbind gadget driver */ 1440 - driver->unbind(&udc->gadget); 1441 1457 udc->gadget.dev.driver = NULL; 1442 1458 udc->driver = NULL; 1443 1459 ··· 1454 1472 1455 1473 static void prime_status_complete(struct usb_ep *ep, struct usb_request *_req) 1456 1474 { 1457 - struct mv_udc *udc = the_controller; 1475 + struct mv_ep *mvep = container_of(ep, struct mv_ep, ep); 1458 1476 struct mv_req *req = container_of(_req, struct mv_req, req); 1477 + struct mv_udc *udc; 1459 1478 unsigned long flags; 1479 + 1480 + udc = mvep->udc; 1460 1481 1461 1482 dev_info(&udc->dev->dev, "switch to test mode %d\n", req->test_mode); 1462 1483 ··· 2108 2123 /* release device structure */ 2109 2124 static void gadget_release(struct device *_dev) 2110 2125 { 2111 - struct mv_udc *udc = the_controller; 2126 + struct mv_udc *udc; 2127 + 2128 + udc = dev_get_drvdata(_dev); 2112 2129 2113 2130 complete(udc->done); 2114 2131 } 2115 2132 2116 - static int mv_udc_remove(struct platform_device *dev) 2133 + static int mv_udc_remove(struct platform_device *pdev) 2117 2134 { 2118 - struct mv_udc *udc = the_controller; 2119 - int clk_i; 2135 + struct mv_udc *udc; 2136 + 2137 + udc = platform_get_drvdata(pdev); 2120 2138 2121 2139 usb_del_gadget_udc(&udc->gadget); 2122 2140 ··· 2128 2140 destroy_workqueue(udc->qwork); 2129 2141 } 2130 2142 2131 - /* 2132 - * If we have transceiver inited, 2133 - * then vbus irq will not be requested in udc driver. 2134 - */ 2135 - if (udc->pdata && udc->pdata->vbus 2136 - && udc->clock_gating && IS_ERR_OR_NULL(udc->transceiver)) 2137 - free_irq(udc->pdata->vbus->irq, &dev->dev); 2138 - 2139 2143 /* free memory allocated in probe */ 2140 2144 if (udc->dtd_pool) 2141 2145 dma_pool_destroy(udc->dtd_pool); 2142 2146 2143 2147 if (udc->ep_dqh) 2144 - dma_free_coherent(&dev->dev, udc->ep_dqh_size, 2148 + dma_free_coherent(&pdev->dev, udc->ep_dqh_size, 2145 2149 udc->ep_dqh, udc->ep_dqh_dma); 2146 2150 2147 - kfree(udc->eps); 2148 - 2149 - if (udc->irq) 2150 - free_irq(udc->irq, &dev->dev); 2151 - 2152 2151 mv_udc_disable(udc); 2153 - 2154 - if (udc->cap_regs) 2155 - iounmap(udc->cap_regs); 2156 - 2157 - if (udc->phy_regs) 2158 - iounmap(udc->phy_regs); 2159 - 2160 - if (udc->status_req) { 2161 - kfree(udc->status_req->req.buf); 2162 - kfree(udc->status_req); 2163 - } 2164 - 2165 - for (clk_i = 0; clk_i <= udc->clknum; clk_i++) 2166 - clk_put(udc->clk[clk_i]); 2167 2152 2168 2153 device_unregister(&udc->gadget.dev); 2169 2154 2170 2155 /* free dev, wait for the release() finished */ 2171 2156 wait_for_completion(udc->done); 2172 - kfree(udc); 2173 - 2174 - the_controller = NULL; 2175 2157 2176 2158 return 0; 2177 2159 } 2178 2160 2179 - static int mv_udc_probe(struct platform_device *dev) 2161 + static int mv_udc_probe(struct platform_device *pdev) 2180 2162 { 2181 - struct mv_usb_platform_data *pdata = dev->dev.platform_data; 2163 + struct mv_usb_platform_data *pdata = pdev->dev.platform_data; 2182 2164 struct mv_udc *udc; 2183 2165 int retval = 0; 2184 2166 int clk_i = 0; ··· 2156 2198 size_t size; 2157 2199 2158 2200 if (pdata == NULL) { 2159 - dev_err(&dev->dev, "missing platform_data\n"); 2201 + dev_err(&pdev->dev, "missing platform_data\n"); 2160 2202 return -ENODEV; 2161 2203 } 2162 2204 2163 2205 size = sizeof(*udc) + sizeof(struct clk *) * pdata->clknum; 2164 - udc = kzalloc(size, GFP_KERNEL); 2206 + udc = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); 2165 2207 if (udc == NULL) { 2166 - dev_err(&dev->dev, "failed to allocate memory for udc\n"); 2208 + dev_err(&pdev->dev, "failed to allocate memory for udc\n"); 2167 2209 return -ENOMEM; 2168 2210 } 2169 2211 2170 - the_controller = udc; 2171 2212 udc->done = &release_done; 2172 - udc->pdata = dev->dev.platform_data; 2213 + udc->pdata = pdev->dev.platform_data; 2173 2214 spin_lock_init(&udc->lock); 2174 2215 2175 - udc->dev = dev; 2216 + udc->dev = pdev; 2176 2217 2177 2218 #ifdef CONFIG_USB_OTG_UTILS 2178 - if (pdata->mode == MV_USB_MODE_OTG) 2179 - udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); 2219 + if (pdata->mode == MV_USB_MODE_OTG) { 2220 + udc->transceiver = devm_usb_get_phy(&pdev->dev, 2221 + USB_PHY_TYPE_USB2); 2222 + if (IS_ERR_OR_NULL(udc->transceiver)) { 2223 + udc->transceiver = NULL; 2224 + return -ENODEV; 2225 + } 2226 + } 2180 2227 #endif 2181 2228 2182 2229 udc->clknum = pdata->clknum; 2183 2230 for (clk_i = 0; clk_i < udc->clknum; clk_i++) { 2184 - udc->clk[clk_i] = clk_get(&dev->dev, pdata->clkname[clk_i]); 2231 + udc->clk[clk_i] = devm_clk_get(&pdev->dev, 2232 + pdata->clkname[clk_i]); 2185 2233 if (IS_ERR(udc->clk[clk_i])) { 2186 2234 retval = PTR_ERR(udc->clk[clk_i]); 2187 - goto err_put_clk; 2235 + return retval; 2188 2236 } 2189 2237 } 2190 2238 2191 2239 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "capregs"); 2192 2240 if (r == NULL) { 2193 - dev_err(&dev->dev, "no I/O memory resource defined\n"); 2194 - retval = -ENODEV; 2195 - goto err_put_clk; 2241 + dev_err(&pdev->dev, "no I/O memory resource defined\n"); 2242 + return -ENODEV; 2196 2243 } 2197 2244 2198 2245 udc->cap_regs = (struct mv_cap_regs __iomem *) 2199 - ioremap(r->start, resource_size(r)); 2246 + devm_ioremap(&pdev->dev, r->start, resource_size(r)); 2200 2247 if (udc->cap_regs == NULL) { 2201 - dev_err(&dev->dev, "failed to map I/O memory\n"); 2202 - retval = -EBUSY; 2203 - goto err_put_clk; 2248 + dev_err(&pdev->dev, "failed to map I/O memory\n"); 2249 + return -EBUSY; 2204 2250 } 2205 2251 2206 2252 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "phyregs"); 2207 2253 if (r == NULL) { 2208 - dev_err(&dev->dev, "no phy I/O memory resource defined\n"); 2209 - retval = -ENODEV; 2210 - goto err_iounmap_capreg; 2254 + dev_err(&pdev->dev, "no phy I/O memory resource defined\n"); 2255 + return -ENODEV; 2211 2256 } 2212 2257 2213 2258 udc->phy_regs = ioremap(r->start, resource_size(r)); 2214 2259 if (udc->phy_regs == NULL) { 2215 - dev_err(&dev->dev, "failed to map phy I/O memory\n"); 2216 - retval = -EBUSY; 2217 - goto err_iounmap_capreg; 2260 + dev_err(&pdev->dev, "failed to map phy I/O memory\n"); 2261 + return -EBUSY; 2218 2262 } 2219 2263 2220 2264 /* we will acces controller register, so enable the clk */ 2221 2265 retval = mv_udc_enable_internal(udc); 2222 2266 if (retval) 2223 - goto err_iounmap_phyreg; 2267 + return retval; 2224 2268 2225 2269 udc->op_regs = 2226 2270 (struct mv_op_regs __iomem *)((unsigned long)udc->cap_regs ··· 2239 2279 2240 2280 size = udc->max_eps * sizeof(struct mv_dqh) *2; 2241 2281 size = (size + DQH_ALIGNMENT - 1) & ~(DQH_ALIGNMENT - 1); 2242 - udc->ep_dqh = dma_alloc_coherent(&dev->dev, size, 2282 + udc->ep_dqh = dma_alloc_coherent(&pdev->dev, size, 2243 2283 &udc->ep_dqh_dma, GFP_KERNEL); 2244 2284 2245 2285 if (udc->ep_dqh == NULL) { 2246 - dev_err(&dev->dev, "allocate dQH memory failed\n"); 2286 + dev_err(&pdev->dev, "allocate dQH memory failed\n"); 2247 2287 retval = -ENOMEM; 2248 2288 goto err_disable_clock; 2249 2289 } ··· 2251 2291 2252 2292 /* create dTD dma_pool resource */ 2253 2293 udc->dtd_pool = dma_pool_create("mv_dtd", 2254 - &dev->dev, 2294 + &pdev->dev, 2255 2295 sizeof(struct mv_dtd), 2256 2296 DTD_ALIGNMENT, 2257 2297 DMA_BOUNDARY); ··· 2262 2302 } 2263 2303 2264 2304 size = udc->max_eps * sizeof(struct mv_ep) *2; 2265 - udc->eps = kzalloc(size, GFP_KERNEL); 2305 + udc->eps = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); 2266 2306 if (udc->eps == NULL) { 2267 - dev_err(&dev->dev, "allocate ep memory failed\n"); 2307 + dev_err(&pdev->dev, "allocate ep memory failed\n"); 2268 2308 retval = -ENOMEM; 2269 2309 goto err_destroy_dma; 2270 2310 } 2271 2311 2272 2312 /* initialize ep0 status request structure */ 2273 - udc->status_req = kzalloc(sizeof(struct mv_req), GFP_KERNEL); 2313 + udc->status_req = devm_kzalloc(&pdev->dev, sizeof(struct mv_req), 2314 + GFP_KERNEL); 2274 2315 if (!udc->status_req) { 2275 - dev_err(&dev->dev, "allocate status_req memory failed\n"); 2316 + dev_err(&pdev->dev, "allocate status_req memory failed\n"); 2276 2317 retval = -ENOMEM; 2277 - goto err_free_eps; 2318 + goto err_destroy_dma; 2278 2319 } 2279 2320 INIT_LIST_HEAD(&udc->status_req->queue); 2280 2321 ··· 2290 2329 2291 2330 r = platform_get_resource(udc->dev, IORESOURCE_IRQ, 0); 2292 2331 if (r == NULL) { 2293 - dev_err(&dev->dev, "no IRQ resource defined\n"); 2332 + dev_err(&pdev->dev, "no IRQ resource defined\n"); 2294 2333 retval = -ENODEV; 2295 - goto err_free_status_req; 2334 + goto err_destroy_dma; 2296 2335 } 2297 2336 udc->irq = r->start; 2298 - if (request_irq(udc->irq, mv_udc_irq, 2337 + if (devm_request_irq(&pdev->dev, udc->irq, mv_udc_irq, 2299 2338 IRQF_SHARED, driver_name, udc)) { 2300 - dev_err(&dev->dev, "Request irq %d for UDC failed\n", 2339 + dev_err(&pdev->dev, "Request irq %d for UDC failed\n", 2301 2340 udc->irq); 2302 2341 retval = -ENODEV; 2303 - goto err_free_status_req; 2342 + goto err_destroy_dma; 2304 2343 } 2305 2344 2306 2345 /* initialize gadget structure */ ··· 2312 2351 2313 2352 /* the "gadget" abstracts/virtualizes the controller */ 2314 2353 dev_set_name(&udc->gadget.dev, "gadget"); 2315 - udc->gadget.dev.parent = &dev->dev; 2316 - udc->gadget.dev.dma_mask = dev->dev.dma_mask; 2354 + udc->gadget.dev.parent = &pdev->dev; 2355 + udc->gadget.dev.dma_mask = pdev->dev.dma_mask; 2317 2356 udc->gadget.dev.release = gadget_release; 2318 2357 udc->gadget.name = driver_name; /* gadget name */ 2319 2358 2320 2359 retval = device_register(&udc->gadget.dev); 2321 2360 if (retval) 2322 - goto err_free_irq; 2361 + goto err_destroy_dma; 2323 2362 2324 2363 eps_init(udc); 2325 2364 2326 2365 /* VBUS detect: we can disable/enable clock on demand.*/ 2327 - if (!IS_ERR_OR_NULL(udc->transceiver)) 2366 + if (udc->transceiver) 2328 2367 udc->clock_gating = 1; 2329 2368 else if (pdata->vbus) { 2330 2369 udc->clock_gating = 1; 2331 - retval = request_threaded_irq(pdata->vbus->irq, NULL, 2370 + retval = devm_request_threaded_irq(&pdev->dev, 2371 + pdata->vbus->irq, NULL, 2332 2372 mv_udc_vbus_irq, IRQF_ONESHOT, "vbus", udc); 2333 2373 if (retval) { 2334 - dev_info(&dev->dev, 2374 + dev_info(&pdev->dev, 2335 2375 "Can not request irq for VBUS, " 2336 2376 "disable clock gating\n"); 2337 2377 udc->clock_gating = 0; ··· 2340 2378 2341 2379 udc->qwork = create_singlethread_workqueue("mv_udc_queue"); 2342 2380 if (!udc->qwork) { 2343 - dev_err(&dev->dev, "cannot create workqueue\n"); 2381 + dev_err(&pdev->dev, "cannot create workqueue\n"); 2344 2382 retval = -ENOMEM; 2345 2383 goto err_unregister; 2346 2384 } ··· 2358 2396 else 2359 2397 udc->vbus_active = 1; 2360 2398 2361 - retval = usb_add_gadget_udc(&dev->dev, &udc->gadget); 2399 + retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 2362 2400 if (retval) 2363 - goto err_unregister; 2401 + goto err_create_workqueue; 2364 2402 2365 - dev_info(&dev->dev, "successful probe UDC device %s clock gating.\n", 2403 + platform_set_drvdata(pdev, udc); 2404 + dev_info(&pdev->dev, "successful probe UDC device %s clock gating.\n", 2366 2405 udc->clock_gating ? "with" : "without"); 2367 2406 2368 2407 return 0; 2369 2408 2409 + err_create_workqueue: 2410 + destroy_workqueue(udc->qwork); 2370 2411 err_unregister: 2371 - if (udc->pdata && udc->pdata->vbus 2372 - && udc->clock_gating && IS_ERR_OR_NULL(udc->transceiver)) 2373 - free_irq(pdata->vbus->irq, &dev->dev); 2374 2412 device_unregister(&udc->gadget.dev); 2375 - err_free_irq: 2376 - free_irq(udc->irq, &dev->dev); 2377 - err_free_status_req: 2378 - kfree(udc->status_req->req.buf); 2379 - kfree(udc->status_req); 2380 - err_free_eps: 2381 - kfree(udc->eps); 2382 2413 err_destroy_dma: 2383 2414 dma_pool_destroy(udc->dtd_pool); 2384 2415 err_free_dma: 2385 - dma_free_coherent(&dev->dev, udc->ep_dqh_size, 2416 + dma_free_coherent(&pdev->dev, udc->ep_dqh_size, 2386 2417 udc->ep_dqh, udc->ep_dqh_dma); 2387 2418 err_disable_clock: 2388 2419 mv_udc_disable_internal(udc); 2389 - err_iounmap_phyreg: 2390 - iounmap(udc->phy_regs); 2391 - err_iounmap_capreg: 2392 - iounmap(udc->cap_regs); 2393 - err_put_clk: 2394 - for (clk_i--; clk_i >= 0; clk_i--) 2395 - clk_put(udc->clk[clk_i]); 2396 - the_controller = NULL; 2397 - kfree(udc); 2420 + 2398 2421 return retval; 2399 2422 } 2400 2423 2401 2424 #ifdef CONFIG_PM 2402 - static int mv_udc_suspend(struct device *_dev) 2425 + static int mv_udc_suspend(struct device *dev) 2403 2426 { 2404 - struct mv_udc *udc = the_controller; 2427 + struct mv_udc *udc; 2428 + 2429 + udc = dev_get_drvdata(dev); 2405 2430 2406 2431 /* if OTG is enabled, the following will be done in OTG driver*/ 2407 - if (!IS_ERR_OR_NULL(udc->transceiver)) 2432 + if (udc->transceiver) 2408 2433 return 0; 2409 2434 2410 2435 if (udc->pdata->vbus && udc->pdata->vbus->poll) ··· 2418 2469 return 0; 2419 2470 } 2420 2471 2421 - static int mv_udc_resume(struct device *_dev) 2472 + static int mv_udc_resume(struct device *dev) 2422 2473 { 2423 - struct mv_udc *udc = the_controller; 2474 + struct mv_udc *udc; 2424 2475 int retval; 2425 2476 2477 + udc = dev_get_drvdata(dev); 2478 + 2426 2479 /* if OTG is enabled, the following will be done in OTG driver*/ 2427 - if (!IS_ERR_OR_NULL(udc->transceiver)) 2480 + if (udc->transceiver) 2428 2481 return 0; 2429 2482 2430 2483 if (!udc->clock_gating) { ··· 2450 2499 }; 2451 2500 #endif 2452 2501 2453 - static void mv_udc_shutdown(struct platform_device *dev) 2502 + static void mv_udc_shutdown(struct platform_device *pdev) 2454 2503 { 2455 - struct mv_udc *udc = the_controller; 2504 + struct mv_udc *udc; 2456 2505 u32 mode; 2457 2506 2507 + udc = platform_get_drvdata(pdev); 2458 2508 /* reset controller mode to IDLE */ 2459 2509 mv_udc_enable(udc); 2460 2510 mode = readl(&udc->op_regs->usbmode); ··· 2466 2514 2467 2515 static struct platform_driver udc_driver = { 2468 2516 .probe = mv_udc_probe, 2469 - .remove = __exit_p(mv_udc_remove), 2517 + .remove = mv_udc_remove, 2470 2518 .shutdown = mv_udc_shutdown, 2471 2519 .driver = { 2472 2520 .owner = THIS_MODULE,
+15
drivers/usb/gadget/net2280.c
··· 116 116 /* "modprobe net2280 enable_suspend=1" etc */ 117 117 module_param (enable_suspend, bool, S_IRUGO); 118 118 119 + /* force full-speed operation */ 120 + static bool full_speed; 121 + module_param(full_speed, bool, 0444); 122 + MODULE_PARM_DESC(full_speed, "force full-speed mode -- for testing only!"); 119 123 120 124 #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out") 121 125 ··· 1903 1899 retval = device_create_file (&dev->pdev->dev, &dev_attr_queues); 1904 1900 if (retval) goto err_func; 1905 1901 1902 + /* Enable force-full-speed testing mode, if desired */ 1903 + if (full_speed) 1904 + writel(1 << FORCE_FULL_SPEED_MODE, &dev->usb->xcvrdiag); 1905 + 1906 1906 /* ... then enable host detection and ep0; and we're ready 1907 1907 * for set_configuration as well as eventual disconnect. 1908 1908 */ ··· 1965 1957 dev->driver = NULL; 1966 1958 1967 1959 net2280_led_active (dev, 0); 1960 + 1961 + /* Disable full-speed test mode */ 1962 + writel(0, &dev->usb->xcvrdiag); 1963 + 1968 1964 device_remove_file (&dev->pdev->dev, &dev_attr_function); 1969 1965 device_remove_file (&dev->pdev->dev, &dev_attr_queues); 1970 1966 ··· 2853 2841 2854 2842 /* disable the pullup so the host will think we're gone */ 2855 2843 writel (0, &dev->usb->usbctl); 2844 + 2845 + /* Disable full-speed test mode */ 2846 + writel(0, &dev->usb->xcvrdiag); 2856 2847 } 2857 2848 2858 2849
+31 -12
drivers/usb/gadget/nokia.c
··· 37 37 * the runtime footprint, and giving us at least some parts of what 38 38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 39 39 */ 40 - #include "u_serial.c" 40 + #define USB_FACM_INCLUDED 41 41 #include "f_acm.c" 42 42 #include "f_ecm.c" 43 43 #include "f_obex.c" ··· 101 101 102 102 static u8 hostaddr[ETH_ALEN]; 103 103 104 + enum { 105 + TTY_PORT_OBEX0, 106 + TTY_PORT_OBEX1, 107 + TTY_PORT_ACM, 108 + TTY_PORTS_MAX, 109 + }; 110 + 111 + static unsigned char tty_lines[TTY_PORTS_MAX]; 112 + 104 113 static int __init nokia_bind_config(struct usb_configuration *c) 105 114 { 106 115 int status = 0; ··· 118 109 if (status) 119 110 printk(KERN_DEBUG "could not bind phonet config\n"); 120 111 121 - status = obex_bind_config(c, 0); 112 + status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX0]); 122 113 if (status) 123 114 printk(KERN_DEBUG "could not bind obex config %d\n", 0); 124 115 125 - status = obex_bind_config(c, 1); 116 + status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX1]); 126 117 if (status) 127 118 printk(KERN_DEBUG "could not bind obex config %d\n", 0); 128 119 129 - status = acm_bind_config(c, 2); 120 + status = acm_bind_config(c, tty_lines[TTY_PORT_ACM]); 130 121 if (status) 131 122 printk(KERN_DEBUG "could not bind acm config\n"); 132 123 ··· 142 133 .bConfigurationValue = 1, 143 134 /* .iConfiguration = DYNAMIC */ 144 135 .bmAttributes = USB_CONFIG_ATT_ONE, 145 - .bMaxPower = 250, /* 500mA */ 136 + .MaxPower = 500, 146 137 }; 147 138 148 139 static struct usb_configuration nokia_config_100ma_driver = { ··· 150 141 .bConfigurationValue = 2, 151 142 /* .iConfiguration = DYNAMIC */ 152 143 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, 153 - .bMaxPower = 50, /* 100 mA */ 144 + .MaxPower = 100, 154 145 }; 155 146 156 147 static int __init nokia_bind(struct usb_composite_dev *cdev) 157 148 { 158 149 struct usb_gadget *gadget = cdev->gadget; 159 150 int status; 151 + int cur_line; 160 152 161 153 status = gphonet_setup(cdev->gadget); 162 154 if (status < 0) 163 155 goto err_phonet; 164 156 165 - status = gserial_setup(cdev->gadget, 3); 166 - if (status < 0) 167 - goto err_serial; 157 + for (cur_line = 0; cur_line < TTY_PORTS_MAX; cur_line++) { 158 + status = gserial_alloc_line(&tty_lines[cur_line]); 159 + if (status) 160 + goto err_ether; 161 + } 168 162 169 163 status = gether_setup(cdev->gadget, hostaddr); 170 164 if (status < 0) ··· 204 192 err_usb: 205 193 gether_cleanup(); 206 194 err_ether: 207 - gserial_cleanup(); 208 - err_serial: 195 + cur_line--; 196 + while (cur_line >= 0) 197 + gserial_free_line(tty_lines[cur_line--]); 198 + 209 199 gphonet_cleanup(); 210 200 err_phonet: 211 201 return status; ··· 215 201 216 202 static int __exit nokia_unbind(struct usb_composite_dev *cdev) 217 203 { 204 + int i; 205 + 218 206 gphonet_cleanup(); 219 - gserial_cleanup(); 207 + 208 + for (i = 0; i < TTY_PORTS_MAX; i++) 209 + gserial_free_line(tty_lines[i]); 210 + 220 211 gether_cleanup(); 221 212 222 213 return 0;
+13 -38
drivers/usb/gadget/omap_udc.c
··· 1309 1309 return 0; 1310 1310 } 1311 1311 1312 - static int omap_udc_start(struct usb_gadget_driver *driver, 1313 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1314 - static int omap_udc_stop(struct usb_gadget_driver *driver); 1312 + static int omap_udc_start(struct usb_gadget *g, 1313 + struct usb_gadget_driver *driver) 1314 + static int omap_udc_stop(struct usb_gadget *g, 1315 + struct usb_gadget_driver *driver); 1315 1316 1316 - static struct usb_gadget_ops omap_gadget_ops = { 1317 + static const struct usb_gadget_ops omap_gadget_ops = { 1317 1318 .get_frame = omap_get_frame, 1318 1319 .wakeup = omap_wakeup, 1319 1320 .set_selfpowered = omap_set_selfpowered, 1320 1321 .vbus_session = omap_vbus_session, 1321 1322 .vbus_draw = omap_vbus_draw, 1322 1323 .pullup = omap_pullup, 1323 - .start = omap_udc_start, 1324 - .stop = omap_udc_stop, 1324 + .udc_start = omap_udc_start, 1325 + .udc_stop = omap_udc_stop, 1325 1326 }; 1326 1327 1327 1328 /*-------------------------------------------------------------------------*/ ··· 2042 2041 || cpu_is_omap7xx(); 2043 2042 } 2044 2043 2045 - static int omap_udc_start(struct usb_gadget_driver *driver, 2046 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 2044 + static int omap_udc_start(struct usb_gadget *g, 2045 + struct usb_gadget_driver *driver) 2047 2046 { 2048 2047 int status = -ENODEV; 2049 2048 struct omap_ep *ep; 2050 2049 unsigned long flags; 2051 2050 2052 - /* basic sanity tests */ 2053 - if (!udc) 2054 - return -ENODEV; 2055 - if (!driver 2056 - /* FIXME if otg, check: driver->is_otg */ 2057 - || driver->max_speed < USB_SPEED_FULL 2058 - || !bind || !driver->setup) 2059 - return -EINVAL; 2060 2051 2061 2052 spin_lock_irqsave(&udc->lock, flags); 2062 - if (udc->driver) { 2063 - spin_unlock_irqrestore(&udc->lock, flags); 2064 - return -EBUSY; 2065 - } 2066 - 2067 2053 /* reset state */ 2068 2054 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { 2069 2055 ep->irqs = 0; ··· 2071 2083 2072 2084 if (udc->dc_clk != NULL) 2073 2085 omap_udc_enable_clock(1); 2074 - 2075 - status = bind(&udc->gadget, driver); 2076 - if (status) { 2077 - DBG("bind to %s --> %d\n", driver->driver.name, status); 2078 - udc->gadget.dev.driver = NULL; 2079 - udc->driver = NULL; 2080 - goto done; 2081 - } 2082 - DBG("bound to driver %s\n", driver->driver.name); 2083 2086 2084 2087 omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC); 2085 2088 ··· 2103 2124 done: 2104 2125 if (udc->dc_clk != NULL) 2105 2126 omap_udc_enable_clock(0); 2127 + 2106 2128 return status; 2107 2129 } 2108 2130 2109 - static int omap_udc_stop(struct usb_gadget_driver *driver) 2131 + static int omap_udc_stop(struct usb_gadget *g, 2132 + struct usb_gadget_driver *driver) 2110 2133 { 2111 2134 unsigned long flags; 2112 2135 int status = -ENODEV; 2113 - 2114 - if (!udc) 2115 - return -ENODEV; 2116 - if (!driver || driver != udc->driver || !driver->unbind) 2117 - return -EINVAL; 2118 2136 2119 2137 if (udc->dc_clk != NULL) 2120 2138 omap_udc_enable_clock(1); ··· 2128 2152 udc_quiesce(udc); 2129 2153 spin_unlock_irqrestore(&udc->lock, flags); 2130 2154 2131 - driver->unbind(&udc->gadget); 2132 2155 udc->gadget.dev.driver = NULL; 2133 2156 udc->driver = NULL; 2134 2157 2135 2158 if (udc->dc_clk != NULL) 2136 2159 omap_udc_enable_clock(0); 2137 - DBG("unregistered driver '%s'\n", driver->driver.name); 2160 + 2138 2161 return status; 2139 2162 } 2140 2163
+14 -53
drivers/usb/gadget/pch_udc.c
··· 375 375 struct pch_udc_cfg_data cfg_data; 376 376 struct pch_vbus_gpio_data vbus_gpio; 377 377 }; 378 + #define to_pch_udc(g) (container_of((g), struct pch_udc_dev, gadget)) 378 379 379 380 #define PCH_UDC_PCI_BAR 1 380 381 #define PCI_DEVICE_ID_INTEL_EG20T_UDC 0x8808 ··· 385 384 386 385 static const char ep0_string[] = "ep0in"; 387 386 static DEFINE_SPINLOCK(udc_stall_spinlock); /* stall spin lock */ 388 - struct pch_udc_dev *pch_udc; /* pointer to device object */ 389 387 static bool speed_fs; 390 388 module_param_named(speed_fs, speed_fs, bool, S_IRUGO); 391 389 MODULE_PARM_DESC(speed_fs, "true for Full speed operation"); ··· 1235 1235 return -EOPNOTSUPP; 1236 1236 } 1237 1237 1238 - static int pch_udc_start(struct usb_gadget_driver *driver, 1239 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1240 - static int pch_udc_stop(struct usb_gadget_driver *driver); 1238 + static int pch_udc_start(struct usb_gadget *g, 1239 + struct usb_gadget_driver *driver); 1240 + static int pch_udc_stop(struct usb_gadget *g, 1241 + struct usb_gadget_driver *driver); 1241 1242 static const struct usb_gadget_ops pch_udc_ops = { 1242 1243 .get_frame = pch_udc_pcd_get_frame, 1243 1244 .wakeup = pch_udc_pcd_wakeup, ··· 1246 1245 .pullup = pch_udc_pcd_pullup, 1247 1246 .vbus_session = pch_udc_pcd_vbus_session, 1248 1247 .vbus_draw = pch_udc_pcd_vbus_draw, 1249 - .start = pch_udc_start, 1250 - .stop = pch_udc_stop, 1248 + .udc_start = pch_udc_start, 1249 + .udc_stop = pch_udc_stop, 1251 1250 }; 1252 1251 1253 1252 /** ··· 2982 2981 return 0; 2983 2982 } 2984 2983 2985 - static int pch_udc_start(struct usb_gadget_driver *driver, 2986 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 2984 + static int pch_udc_start(struct usb_gadget *g, 2985 + struct usb_gadget_driver *driver) 2987 2986 { 2988 - struct pch_udc_dev *dev = pch_udc; 2989 - int retval; 2987 + struct pch_udc_dev *dev = to_pch_udc(g); 2990 2988 2991 - if (!driver || (driver->max_speed == USB_SPEED_UNKNOWN) || !bind || 2992 - !driver->setup || !driver->unbind || !driver->disconnect) { 2993 - dev_err(&dev->pdev->dev, 2994 - "%s: invalid driver parameter\n", __func__); 2995 - return -EINVAL; 2996 - } 2997 - 2998 - if (!dev) 2999 - return -ENODEV; 3000 - 3001 - if (dev->driver) { 3002 - dev_err(&dev->pdev->dev, "%s: already bound\n", __func__); 3003 - return -EBUSY; 3004 - } 3005 2989 driver->driver.bus = NULL; 3006 2990 dev->driver = driver; 3007 2991 dev->gadget.dev.driver = &driver->driver; 3008 2992 3009 - /* Invoke the bind routine of the gadget driver */ 3010 - retval = bind(&dev->gadget, driver); 3011 - 3012 - if (retval) { 3013 - dev_err(&dev->pdev->dev, "%s: binding to %s returning %d\n", 3014 - __func__, driver->driver.name, retval); 3015 - dev->driver = NULL; 3016 - dev->gadget.dev.driver = NULL; 3017 - return retval; 3018 - } 3019 2993 /* get ready for ep0 traffic */ 3020 2994 pch_udc_setup_ep0(dev); 3021 2995 ··· 3002 3026 return 0; 3003 3027 } 3004 3028 3005 - static int pch_udc_stop(struct usb_gadget_driver *driver) 3029 + static int pch_udc_stop(struct usb_gadget *g, 3030 + struct usb_gadget_driver *driver) 3006 3031 { 3007 - struct pch_udc_dev *dev = pch_udc; 3008 - 3009 - if (!dev) 3010 - return -ENODEV; 3011 - 3012 - if (!driver || (driver != dev->driver)) { 3013 - dev_err(&dev->pdev->dev, 3014 - "%s: invalid driver parameter\n", __func__); 3015 - return -EINVAL; 3016 - } 3032 + struct pch_udc_dev *dev = to_pch_udc(g); 3017 3033 3018 3034 pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK); 3019 3035 3020 3036 /* Assures that there are no pending requests with this driver */ 3021 - driver->disconnect(&dev->gadget); 3022 - driver->unbind(&dev->gadget); 3023 3037 dev->gadget.dev.driver = NULL; 3024 3038 dev->driver = NULL; 3025 3039 dev->connected = 0; 3026 3040 3027 3041 /* set SD */ 3028 3042 pch_udc_set_disconnect(dev); 3043 + 3029 3044 return 0; 3030 3045 } 3031 3046 ··· 3131 3164 int retval; 3132 3165 struct pch_udc_dev *dev; 3133 3166 3134 - /* one udc only */ 3135 - if (pch_udc) { 3136 - pr_err("%s: already probed\n", __func__); 3137 - return -EBUSY; 3138 - } 3139 3167 /* init */ 3140 3168 dev = kzalloc(sizeof *dev, GFP_KERNEL); 3141 3169 if (!dev) { ··· 3169 3207 retval = -ENODEV; 3170 3208 goto finished; 3171 3209 } 3172 - pch_udc = dev; 3173 3210 /* initialize the hardware */ 3174 3211 if (pch_udc_pcd_init(dev)) { 3175 3212 retval = -ENODEV;
+14 -48
drivers/usb/gadget/pxa25x_udc.c
··· 996 996 return -EOPNOTSUPP; 997 997 } 998 998 999 - static int pxa25x_start(struct usb_gadget_driver *driver, 1000 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1001 - static int pxa25x_stop(struct usb_gadget_driver *driver); 999 + static int pxa25x_udc_start(struct usb_gadget *g, 1000 + struct usb_gadget_driver *driver); 1001 + static int pxa25x_udc_stop(struct usb_gadget *g, 1002 + struct usb_gadget_driver *driver); 1002 1003 1003 1004 static const struct usb_gadget_ops pxa25x_udc_ops = { 1004 1005 .get_frame = pxa25x_udc_get_frame, ··· 1007 1006 .vbus_session = pxa25x_udc_vbus_session, 1008 1007 .pullup = pxa25x_udc_pullup, 1009 1008 .vbus_draw = pxa25x_udc_vbus_draw, 1010 - .start = pxa25x_start, 1011 - .stop = pxa25x_stop, 1009 + .udc_start = pxa25x_udc_start, 1010 + .udc_stop = pxa25x_udc_stop, 1012 1011 }; 1013 1012 1014 1013 /*-------------------------------------------------------------------------*/ ··· 1255 1254 * disconnect is reported. then a host may connect again, or 1256 1255 * the driver might get unbound. 1257 1256 */ 1258 - static int pxa25x_start(struct usb_gadget_driver *driver, 1259 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1257 + static int pxa25x_udc_start(struct usb_gadget *g, 1258 + struct usb_gadget_driver *driver) 1260 1259 { 1261 - struct pxa25x_udc *dev = the_controller; 1260 + struct pxa25x_udc *dev = to_pxa25x(g); 1262 1261 int retval; 1263 - 1264 - if (!driver 1265 - || driver->max_speed < USB_SPEED_FULL 1266 - || !bind 1267 - || !driver->disconnect 1268 - || !driver->setup) 1269 - return -EINVAL; 1270 - if (!dev) 1271 - return -ENODEV; 1272 - if (dev->driver) 1273 - return -EBUSY; 1274 1262 1275 1263 /* first hook up the driver ... */ 1276 1264 dev->driver = driver; ··· 1268 1278 1269 1279 retval = device_add (&dev->gadget.dev); 1270 1280 if (retval) { 1271 - fail: 1272 1281 dev->driver = NULL; 1273 1282 dev->gadget.dev.driver = NULL; 1274 1283 return retval; 1275 - } 1276 - retval = bind(&dev->gadget, driver); 1277 - if (retval) { 1278 - DMSG("bind to driver %s --> error %d\n", 1279 - driver->driver.name, retval); 1280 - device_del (&dev->gadget.dev); 1281 - goto fail; 1282 1284 } 1283 1285 1284 1286 /* ... then enable host detection and ep0; and we're ready 1285 1287 * for set_configuration as well as eventual disconnect. 1286 1288 */ 1287 - DMSG("registered gadget driver '%s'\n", driver->driver.name); 1288 - 1289 1289 /* connect to bus through transceiver */ 1290 1290 if (!IS_ERR_OR_NULL(dev->transceiver)) { 1291 1291 retval = otg_set_peripheral(dev->transceiver->otg, 1292 1292 &dev->gadget); 1293 - if (retval) { 1294 - DMSG("can't bind to transceiver\n"); 1295 - if (driver->unbind) 1296 - driver->unbind(&dev->gadget); 1293 + if (retval) 1297 1294 goto bind_fail; 1298 - } 1299 1295 } 1300 1296 1301 1297 pullup(dev); ··· 1310 1334 } 1311 1335 del_timer_sync(&dev->timer); 1312 1336 1313 - /* report disconnect; the driver is already quiesced */ 1314 - if (driver) 1315 - driver->disconnect(&dev->gadget); 1316 - 1317 1337 /* re-init driver-visible data structures */ 1318 1338 udc_reinit(dev); 1319 1339 } 1320 1340 1321 - static int pxa25x_stop(struct usb_gadget_driver *driver) 1341 + static int pxa25x_udc_stop(struct usb_gadget*g, 1342 + struct usb_gadget_driver *driver) 1322 1343 { 1323 - struct pxa25x_udc *dev = the_controller; 1324 - 1325 - if (!dev) 1326 - return -ENODEV; 1327 - if (!driver || driver != dev->driver || !driver->unbind) 1328 - return -EINVAL; 1344 + struct pxa25x_udc *dev = to_pxa25x(g); 1329 1345 1330 1346 local_irq_disable(); 1331 1347 dev->pullup = 0; ··· 1328 1360 if (!IS_ERR_OR_NULL(dev->transceiver)) 1329 1361 (void) otg_set_peripheral(dev->transceiver->otg, NULL); 1330 1362 1331 - driver->unbind(&dev->gadget); 1332 1363 dev->gadget.dev.driver = NULL; 1333 1364 dev->driver = NULL; 1334 1365 1335 1366 device_del (&dev->gadget.dev); 1336 - 1337 - DMSG("unregistered gadget driver '%s'\n", driver->driver.name); 1338 1367 dump_state(dev); 1368 + 1339 1369 return 0; 1340 1370 } 1341 1371
+1
drivers/usb/gadget/pxa25x_udc.h
··· 126 126 struct dentry *debugfs_udc; 127 127 #endif 128 128 }; 129 + #define to_pxa25x(g) (container_of((g), struct pxa25x_udc, gadget)) 129 130 130 131 /*-------------------------------------------------------------------------*/ 131 132
+15 -46
drivers/usb/gadget/pxa27x_udc.c
··· 1671 1671 return -EOPNOTSUPP; 1672 1672 } 1673 1673 1674 - static int pxa27x_udc_start(struct usb_gadget_driver *driver, 1675 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1676 - static int pxa27x_udc_stop(struct usb_gadget_driver *driver); 1674 + static int pxa27x_udc_start(struct usb_gadget *g, 1675 + struct usb_gadget_driver *driver); 1676 + static int pxa27x_udc_stop(struct usb_gadget *g, 1677 + struct usb_gadget_driver *driver); 1677 1678 1678 1679 static const struct usb_gadget_ops pxa_udc_ops = { 1679 1680 .get_frame = pxa_udc_get_frame, ··· 1682 1681 .pullup = pxa_udc_pullup, 1683 1682 .vbus_session = pxa_udc_vbus_session, 1684 1683 .vbus_draw = pxa_udc_vbus_draw, 1685 - .start = pxa27x_udc_start, 1686 - .stop = pxa27x_udc_stop, 1684 + .udc_start = pxa27x_udc_start, 1685 + .udc_stop = pxa27x_udc_stop, 1687 1686 }; 1688 1687 1689 1688 /** ··· 1803 1802 * 1804 1803 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise 1805 1804 */ 1806 - static int pxa27x_udc_start(struct usb_gadget_driver *driver, 1807 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1805 + static int pxa27x_udc_start(struct usb_gadget *g, 1806 + struct usb_gadget_driver *driver) 1808 1807 { 1809 - struct pxa_udc *udc = the_controller; 1808 + struct pxa_udc *udc = to_pxa(g); 1810 1809 int retval; 1811 - 1812 - if (!driver || driver->max_speed < USB_SPEED_FULL || !bind 1813 - || !driver->disconnect || !driver->setup) 1814 - return -EINVAL; 1815 - if (!udc) 1816 - return -ENODEV; 1817 - if (udc->driver) 1818 - return -EBUSY; 1819 1810 1820 1811 /* first hook up the driver ... */ 1821 1812 udc->driver = driver; ··· 1817 1824 retval = device_add(&udc->gadget.dev); 1818 1825 if (retval) { 1819 1826 dev_err(udc->dev, "device_add error %d\n", retval); 1820 - goto add_fail; 1827 + goto fail; 1821 1828 } 1822 - retval = bind(&udc->gadget, driver); 1823 - if (retval) { 1824 - dev_err(udc->dev, "bind to driver %s --> error %d\n", 1825 - driver->driver.name, retval); 1826 - goto bind_fail; 1827 - } 1828 - dev_dbg(udc->dev, "registered gadget driver '%s'\n", 1829 - driver->driver.name); 1830 - 1831 1829 if (!IS_ERR_OR_NULL(udc->transceiver)) { 1832 1830 retval = otg_set_peripheral(udc->transceiver->otg, 1833 1831 &udc->gadget); 1834 1832 if (retval) { 1835 1833 dev_err(udc->dev, "can't bind to transceiver\n"); 1836 - goto transceiver_fail; 1834 + goto fail; 1837 1835 } 1838 1836 } 1839 1837 ··· 1832 1848 udc_enable(udc); 1833 1849 return 0; 1834 1850 1835 - transceiver_fail: 1836 - if (driver->unbind) 1837 - driver->unbind(&udc->gadget); 1838 - bind_fail: 1839 - device_del(&udc->gadget.dev); 1840 - add_fail: 1851 + fail: 1841 1852 udc->driver = NULL; 1842 1853 udc->gadget.dev.driver = NULL; 1843 1854 return retval; ··· 1857 1878 1858 1879 for (i = 0; i < NR_USB_ENDPOINTS; i++) 1859 1880 pxa_ep_disable(&udc->udc_usb_ep[i].usb_ep); 1860 - 1861 - if (driver) 1862 - driver->disconnect(&udc->gadget); 1863 1881 } 1864 1882 1865 1883 /** ··· 1865 1889 * 1866 1890 * Returns 0 if no error, -ENODEV, -EINVAL otherwise 1867 1891 */ 1868 - static int pxa27x_udc_stop(struct usb_gadget_driver *driver) 1892 + static int pxa27x_udc_stop(struct usb_gadget *g, 1893 + struct usb_gadget_driver *driver) 1869 1894 { 1870 - struct pxa_udc *udc = the_controller; 1871 - 1872 - if (!udc) 1873 - return -ENODEV; 1874 - if (!driver || driver != udc->driver || !driver->unbind) 1875 - return -EINVAL; 1895 + struct pxa_udc *udc = to_pxa(g); 1876 1896 1877 1897 stop_activity(udc, driver); 1878 1898 udc_disable(udc); 1879 1899 dplus_pullup(udc, 0); 1880 1900 1881 - driver->unbind(&udc->gadget); 1882 1901 udc->driver = NULL; 1883 1902 1884 1903 device_del(&udc->gadget.dev); 1885 - dev_info(udc->dev, "unregistered gadget driver '%s'\n", 1886 - driver->driver.name); 1887 1904 1888 1905 if (!IS_ERR_OR_NULL(udc->transceiver)) 1889 1906 return otg_set_peripheral(udc->transceiver->otg, NULL);
+1
drivers/usb/gadget/pxa27x_udc.h
··· 473 473 struct dentry *debugfs_eps; 474 474 #endif 475 475 }; 476 + #define to_pxa(g) (container_of((g), struct pxa_udc, gadget)) 476 477 477 478 static inline struct pxa_udc *to_gadget_udc(struct usb_gadget *gadget) 478 479 {
+1 -1
drivers/usb/gadget/r8a66597-udc.c
··· 1812 1812 return 0; 1813 1813 } 1814 1814 1815 - static struct usb_gadget_ops r8a66597_gadget_ops = { 1815 + static const struct usb_gadget_ops r8a66597_gadget_ops = { 1816 1816 .get_frame = r8a66597_get_frame, 1817 1817 .udc_start = r8a66597_start, 1818 1818 .udc_stop = r8a66597_stop,
+29 -15
drivers/usb/gadget/s3c-hsotg.c
··· 32 32 33 33 #include <linux/usb/ch9.h> 34 34 #include <linux/usb/gadget.h> 35 + #include <linux/usb/phy.h> 35 36 #include <linux/platform_data/s3c-hsotg.h> 36 37 37 38 #include <mach/map.h> ··· 134 133 * struct s3c_hsotg - driver state. 135 134 * @dev: The parent device supplied to the probe function 136 135 * @driver: USB gadget driver 137 - * @plat: The platform specific configuration data. 136 + * @phy: The otg phy transceiver structure for phy control. 137 + * @plat: The platform specific configuration data. This can be removed once 138 + * all SoCs support usb transceiver. 138 139 * @regs: The memory area mapped for accessing registers. 139 140 * @irq: The IRQ number we are using 140 141 * @supplies: Definition of USB power supplies ··· 156 153 struct s3c_hsotg { 157 154 struct device *dev; 158 155 struct usb_gadget_driver *driver; 156 + struct usb_phy *phy; 159 157 struct s3c_hsotg_plat *plat; 160 158 161 159 spinlock_t lock; ··· 2858 2854 struct platform_device *pdev = to_platform_device(hsotg->dev); 2859 2855 2860 2856 dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev); 2861 - if (hsotg->plat->phy_init) 2857 + 2858 + if (hsotg->phy) 2859 + usb_phy_init(hsotg->phy); 2860 + else if (hsotg->plat->phy_init) 2862 2861 hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); 2863 2862 } 2864 2863 ··· 2876 2869 { 2877 2870 struct platform_device *pdev = to_platform_device(hsotg->dev); 2878 2871 2879 - if (hsotg->plat->phy_exit) 2872 + if (hsotg->phy) 2873 + usb_phy_shutdown(hsotg->phy); 2874 + else if (hsotg->plat->phy_exit) 2880 2875 hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); 2881 2876 } 2882 2877 ··· 3064 3055 return 0; 3065 3056 } 3066 3057 3067 - static struct usb_gadget_ops s3c_hsotg_gadget_ops = { 3058 + static const struct usb_gadget_ops s3c_hsotg_gadget_ops = { 3068 3059 .get_frame = s3c_hsotg_gadget_getframe, 3069 3060 .udc_start = s3c_hsotg_udc_start, 3070 3061 .udc_stop = s3c_hsotg_udc_stop, ··· 3501 3492 static int s3c_hsotg_probe(struct platform_device *pdev) 3502 3493 { 3503 3494 struct s3c_hsotg_plat *plat = pdev->dev.platform_data; 3495 + struct usb_phy *phy; 3504 3496 struct device *dev = &pdev->dev; 3505 3497 struct s3c_hsotg_ep *eps; 3506 3498 struct s3c_hsotg *hsotg; ··· 3510 3500 int ret; 3511 3501 int i; 3512 3502 3513 - plat = pdev->dev.platform_data; 3514 - if (!plat) { 3515 - dev_err(&pdev->dev, "no platform data defined\n"); 3516 - return -EINVAL; 3517 - } 3518 - 3519 3503 hsotg = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsotg), GFP_KERNEL); 3520 3504 if (!hsotg) { 3521 3505 dev_err(dev, "cannot get memory\n"); 3522 3506 return -ENOMEM; 3523 3507 } 3524 3508 3509 + phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 3510 + if (IS_ERR_OR_NULL(phy)) { 3511 + /* Fallback for pdata */ 3512 + plat = pdev->dev.platform_data; 3513 + if (!plat) { 3514 + dev_err(&pdev->dev, "no platform data or transceiver defined\n"); 3515 + return -EPROBE_DEFER; 3516 + } else { 3517 + hsotg->plat = plat; 3518 + } 3519 + } else { 3520 + hsotg->phy = phy; 3521 + } 3522 + 3525 3523 hsotg->dev = dev; 3526 - hsotg->plat = plat; 3527 3524 3528 3525 hsotg->clk = devm_clk_get(&pdev->dev, "otg"); 3529 3526 if (IS_ERR(hsotg->clk)) { ··· 3588 3571 for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++) 3589 3572 hsotg->supplies[i].supply = s3c_hsotg_supply_names[i]; 3590 3573 3591 - ret = regulator_bulk_get(dev, ARRAY_SIZE(hsotg->supplies), 3574 + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(hsotg->supplies), 3592 3575 hsotg->supplies); 3593 3576 if (ret) { 3594 3577 dev_err(dev, "failed to request supplies: %d\n", ret); ··· 3678 3661 kfree(eps); 3679 3662 err_supplies: 3680 3663 s3c_hsotg_phy_disable(hsotg); 3681 - regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); 3682 - 3683 3664 err_clk: 3684 3665 clk_disable_unprepare(hsotg->clk); 3685 3666 ··· 3702 3687 } 3703 3688 3704 3689 s3c_hsotg_phy_disable(hsotg); 3705 - regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); 3706 3690 3707 3691 clk_disable_unprepare(hsotg->clk); 3708 3692
+6 -7
drivers/usb/gadget/s3c-hsudc.c
··· 435 435 struct s3c_hsudc_req *hsreq; 436 436 u32 csr; 437 437 438 - csr = readl((u32)hsudc->regs + S3C_ESR); 438 + csr = readl(hsudc->regs + S3C_ESR); 439 439 if (csr & S3C_ESR_STALL) { 440 440 writel(S3C_ESR_STALL, hsudc->regs + S3C_ESR); 441 441 return; ··· 468 468 struct s3c_hsudc_req *hsreq; 469 469 u32 csr; 470 470 471 - csr = readl((u32)hsudc->regs + S3C_ESR); 471 + csr = readl(hsudc->regs + S3C_ESR); 472 472 if (csr & S3C_ESR_STALL) { 473 473 writel(S3C_ESR_STALL, hsudc->regs + S3C_ESR); 474 474 return; ··· 901 901 if (list_empty(&hsep->queue) && !hsep->stopped) { 902 902 offset = (ep_index(hsep)) ? S3C_ESR : S3C_EP0SR; 903 903 if (ep_is_in(hsep)) { 904 - csr = readl((u32)hsudc->regs + offset); 904 + csr = readl(hsudc->regs + offset); 905 905 if (!(csr & S3C_ESR_TX_SUCCESS) && 906 906 (s3c_hsudc_write_fifo(hsep, hsreq) == 1)) 907 907 hsreq = NULL; 908 908 } else { 909 - csr = readl((u32)hsudc->regs + offset); 909 + csr = readl(hsudc->regs + offset); 910 910 if ((csr & S3C_ESR_RX_SUCCESS) 911 911 && (s3c_hsudc_read_fifo(hsep, hsreq) == 1)) 912 912 hsreq = NULL; ··· 1254 1254 return -EOPNOTSUPP; 1255 1255 } 1256 1256 1257 - static struct usb_gadget_ops s3c_hsudc_gadget_ops = { 1257 + static const struct usb_gadget_ops s3c_hsudc_gadget_ops = { 1258 1258 .get_frame = s3c_hsudc_gadget_getframe, 1259 1259 .udc_start = s3c_hsudc_start, 1260 1260 .udc_stop = s3c_hsudc_stop, ··· 1286 1286 for (i = 0; i < ARRAY_SIZE(hsudc->supplies); i++) 1287 1287 hsudc->supplies[i].supply = s3c_hsudc_supply_names[i]; 1288 1288 1289 - ret = regulator_bulk_get(dev, ARRAY_SIZE(hsudc->supplies), 1289 + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(hsudc->supplies), 1290 1290 hsudc->supplies); 1291 1291 if (ret != 0) { 1292 1292 dev_err(dev, "failed to request supplies: %d\n", ret); ··· 1366 1366 if (!IS_ERR_OR_NULL(hsudc->transceiver)) 1367 1367 usb_put_phy(hsudc->transceiver); 1368 1368 1369 - regulator_bulk_free(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); 1370 1369 err_supplies: 1371 1370 return ret; 1372 1371 }
+12 -53
drivers/usb/gadget/s3c2410_udc.c
··· 1538 1538 return -ENOTSUPP; 1539 1539 } 1540 1540 1541 - static int s3c2410_udc_start(struct usb_gadget_driver *driver, 1542 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1543 - static int s3c2410_udc_stop(struct usb_gadget_driver *driver); 1541 + static int s3c2410_udc_start(struct usb_gadget *g, 1542 + struct usb_gadget_driver *driver); 1543 + static int s3c2410_udc_stop(struct usb_gadget *g, 1544 + struct usb_gadget_driver *driver); 1544 1545 1545 1546 static const struct usb_gadget_ops s3c2410_ops = { 1546 1547 .get_frame = s3c2410_udc_get_frame, ··· 1550 1549 .pullup = s3c2410_udc_pullup, 1551 1550 .vbus_session = s3c2410_udc_vbus_session, 1552 1551 .vbus_draw = s3c2410_vbus_draw, 1553 - .start = s3c2410_udc_start, 1554 - .stop = s3c2410_udc_stop, 1552 + .udc_start = s3c2410_udc_start, 1553 + .udc_stop = s3c2410_udc_stop, 1555 1554 }; 1556 1555 1557 1556 static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd) ··· 1665 1664 s3c2410_udc_command(S3C2410_UDC_P_ENABLE); 1666 1665 } 1667 1666 1668 - static int s3c2410_udc_start(struct usb_gadget_driver *driver, 1669 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1667 + static int s3c2410_udc_start(struct usb_gadget *g, 1668 + struct usb_gadget_driver *driver) 1670 1669 { 1671 - struct s3c2410_udc *udc = the_controller; 1670 + struct s3c2410_udc *udc = to_s3c2410(g) 1672 1671 int retval; 1673 1672 1674 1673 dprintk(DEBUG_NORMAL, "%s() '%s'\n", __func__, driver->driver.name); 1675 - 1676 - /* Sanity checks */ 1677 - if (!udc) 1678 - return -ENODEV; 1679 - 1680 - if (udc->driver) 1681 - return -EBUSY; 1682 - 1683 - if (!bind || !driver->setup || driver->max_speed < USB_SPEED_FULL) { 1684 - dev_err(&udc->gadget.dev, "Invalid driver: bind %p setup %p speed %d\n", 1685 - bind, driver->setup, driver->max_speed); 1686 - return -EINVAL; 1687 - } 1688 - #if defined(MODULE) 1689 - if (!driver->unbind) { 1690 - dev_err(&udc->gadget.dev, "Invalid driver: no unbind method\n"); 1691 - return -EINVAL; 1692 - } 1693 - #endif 1694 1674 1695 1675 /* Hook the driver */ 1696 1676 udc->driver = driver; ··· 1681 1699 retval = device_add(&udc->gadget.dev); 1682 1700 if (retval) { 1683 1701 dev_err(&udc->gadget.dev, "Error in device_add() : %d\n", retval); 1684 - goto register_error; 1685 - } 1686 - 1687 - dprintk(DEBUG_NORMAL, "binding gadget driver '%s'\n", 1688 - driver->driver.name); 1689 - 1690 - retval = bind(&udc->gadget, driver); 1691 - if (retval) { 1692 - device_del(&udc->gadget.dev); 1693 1702 goto register_error; 1694 1703 } 1695 1704 ··· 1695 1722 return retval; 1696 1723 } 1697 1724 1698 - static int s3c2410_udc_stop(struct usb_gadget_driver *driver) 1725 + static int s3c2410_udc_stop(struct usb_gadget *g, 1726 + struct usb_gadget_driver *driver) 1699 1727 { 1700 - struct s3c2410_udc *udc = the_controller; 1701 - 1702 - if (!udc) 1703 - return -ENODEV; 1704 - 1705 - if (!driver || driver != udc->driver || !driver->unbind) 1706 - return -EINVAL; 1707 - 1708 - dprintk(DEBUG_NORMAL, "usb_gadget_unregister_driver() '%s'\n", 1709 - driver->driver.name); 1710 - 1711 - /* report disconnect */ 1712 - if (driver->disconnect) 1713 - driver->disconnect(&udc->gadget); 1714 - 1715 - driver->unbind(&udc->gadget); 1728 + struct s3c2410_udc *udc = to_s3c2410(g); 1716 1729 1717 1730 device_del(&udc->gadget.dev); 1718 1731 udc->driver = NULL;
+1
drivers/usb/gadget/s3c2410_udc.h
··· 95 95 u8 vbus; 96 96 struct dentry *regs_info; 97 97 }; 98 + #define to_s3c2410(g) (container_of((g), struct s3c2410_udc, gadget)) 98 99 99 100 #endif
+100 -18
drivers/usb/gadget/serial.c
··· 36 36 * the runtime footprint, and giving us at least some parts of what 37 37 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 38 38 */ 39 - #include "f_acm.c" 40 39 #include "f_obex.c" 41 40 #include "f_serial.c" 42 - #include "u_serial.c" 43 41 44 42 /*-------------------------------------------------------------------------*/ 45 43 USB_GADGET_COMPOSITE_OPTIONS(); ··· 126 128 MODULE_PARM_DESC(n_ports, "number of ports to create, default=1"); 127 129 128 130 /*-------------------------------------------------------------------------*/ 131 + static unsigned char tty_lines[MAX_U_SERIAL_PORTS]; 129 132 130 - static int __init serial_bind_config(struct usb_configuration *c) 133 + static int __init serial_bind_obex_config(struct usb_configuration *c) 131 134 { 132 135 unsigned i; 133 136 int status = 0; 134 137 135 - for (i = 0; i < n_ports && status == 0; i++) { 136 - if (use_acm) 137 - status = acm_bind_config(c, i); 138 - else if (use_obex) 139 - status = obex_bind_config(c, i); 140 - else 141 - status = gser_bind_config(c, i); 142 - } 138 + for (i = 0; i < n_ports && status == 0; i++) 139 + status = obex_bind_config(c, tty_lines[i]); 140 + return status; 141 + } 142 + 143 + static int __init serial_bind_gser_config(struct usb_configuration *c) 144 + { 145 + unsigned i; 146 + int status = 0; 147 + 148 + for (i = 0; i < n_ports && status == 0; i++) 149 + status = gser_bind_config(c, tty_lines[i]); 143 150 return status; 144 151 } 145 152 ··· 155 152 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 156 153 }; 157 154 155 + static struct usb_function_instance *fi_serial[MAX_U_SERIAL_PORTS]; 156 + static struct usb_function *f_serial[MAX_U_SERIAL_PORTS]; 157 + 158 + static int serial_register_ports(struct usb_composite_dev *cdev, 159 + struct usb_configuration *c, const char *f_name) 160 + { 161 + int i; 162 + int ret; 163 + 164 + ret = usb_add_config_only(cdev, c); 165 + if (ret) 166 + goto out; 167 + 168 + for (i = 0; i < n_ports; i++) { 169 + struct f_serial_opts *opts; 170 + 171 + fi_serial[i] = usb_get_function_instance(f_name); 172 + if (IS_ERR(fi_serial[i])) { 173 + ret = PTR_ERR(fi_serial[i]); 174 + goto fail; 175 + } 176 + opts = container_of(fi_serial[i], struct f_serial_opts, func_inst); 177 + opts->port_num = tty_lines[i]; 178 + 179 + f_serial[i] = usb_get_function(fi_serial[i]); 180 + if (IS_ERR(f_serial[i])) { 181 + ret = PTR_ERR(f_serial[i]); 182 + goto err_get_func; 183 + } 184 + 185 + ret = usb_add_function(c, f_serial[i]); 186 + if (ret) 187 + goto err_add_func; 188 + } 189 + 190 + return 0; 191 + 192 + err_add_func: 193 + usb_put_function(f_serial[i]); 194 + err_get_func: 195 + usb_put_function_instance(fi_serial[i]); 196 + 197 + fail: 198 + i--; 199 + while (i >= 0) { 200 + usb_remove_function(c, f_serial[i]); 201 + usb_put_function(f_serial[i]); 202 + usb_put_function_instance(fi_serial[i]); 203 + i--; 204 + } 205 + out: 206 + return ret; 207 + } 208 + 158 209 static int __init gs_bind(struct usb_composite_dev *cdev) 159 210 { 160 211 int status; 212 + int cur_line; 161 213 162 - status = gserial_setup(cdev->gadget, n_ports); 163 - if (status < 0) 164 - return status; 214 + for (cur_line = 0; cur_line < n_ports; cur_line++) { 215 + status = gserial_alloc_line(&tty_lines[cur_line]); 216 + if (status) 217 + goto fail; 218 + } 165 219 166 220 /* Allocate string descriptor numbers ... note that string 167 221 * contents can be overridden by the composite_dev glue. ··· 238 178 } 239 179 240 180 /* register our configuration */ 241 - status = usb_add_config(cdev, &serial_config_driver, 242 - serial_bind_config); 181 + if (use_acm) { 182 + status = serial_register_ports(cdev, &serial_config_driver, 183 + "acm"); 184 + usb_ep_autoconfig_reset(cdev->gadget); 185 + } else if (use_obex) 186 + status = usb_add_config(cdev, &serial_config_driver, 187 + serial_bind_obex_config); 188 + else 189 + status = usb_add_config(cdev, &serial_config_driver, 190 + serial_bind_gser_config); 243 191 if (status < 0) 244 192 goto fail; 245 193 ··· 257 189 return 0; 258 190 259 191 fail: 260 - gserial_cleanup(); 192 + cur_line--; 193 + while (cur_line >= 0) 194 + gserial_free_line(tty_lines[cur_line--]); 261 195 return status; 196 + } 197 + 198 + static int gs_unbind(struct usb_composite_dev *cdev) 199 + { 200 + int i; 201 + 202 + for (i = 0; i < n_ports; i++) { 203 + usb_put_function(f_serial[i]); 204 + usb_put_function_instance(fi_serial[i]); 205 + gserial_free_line(tty_lines[i]); 206 + } 207 + return 0; 262 208 } 263 209 264 210 static __refdata struct usb_composite_driver gserial_driver = { ··· 281 199 .strings = dev_strings, 282 200 .max_speed = USB_SPEED_SUPER, 283 201 .bind = gs_bind, 202 + .unbind = gs_unbind, 284 203 }; 285 204 286 205 static int __init init(void) ··· 317 234 static void __exit cleanup(void) 318 235 { 319 236 usb_composite_unregister(&gserial_driver); 320 - gserial_cleanup(); 321 237 } 322 238 module_exit(cleanup);
-61
drivers/usb/gadget/storage_common.c
··· 93 93 94 94 /*-------------------------------------------------------------------------*/ 95 95 96 - /* CBI Interrupt data structure */ 97 - struct interrupt_data { 98 - u8 bType; 99 - u8 bValue; 100 - }; 101 - 102 - #define CBI_INTERRUPT_DATA_LEN 2 103 - 104 - /* CBI Accept Device-Specific Command request */ 105 - #define USB_CBI_ADSC_REQUEST 0x00 106 - 107 - 108 96 /* Length of a SCSI Command Data Block */ 109 97 #define MAX_COMMAND_SIZE 16 110 98 ··· 373 385 /*.bMaxBurst = DYNAMIC, */ 374 386 }; 375 387 376 - static __maybe_unused struct usb_ext_cap_descriptor fsg_ext_cap_desc = { 377 - .bLength = USB_DT_USB_EXT_CAP_SIZE, 378 - .bDescriptorType = USB_DT_DEVICE_CAPABILITY, 379 - .bDevCapabilityType = USB_CAP_TYPE_EXT, 380 - 381 - .bmAttributes = cpu_to_le32(USB_LPM_SUPPORT), 382 - }; 383 - 384 - static __maybe_unused struct usb_ss_cap_descriptor fsg_ss_cap_desc = { 385 - .bLength = USB_DT_USB_SS_CAP_SIZE, 386 - .bDescriptorType = USB_DT_DEVICE_CAPABILITY, 387 - .bDevCapabilityType = USB_SS_CAP_TYPE, 388 - 389 - /* .bmAttributes = LTM is not supported yet */ 390 - 391 - .wSpeedSupported = cpu_to_le16(USB_LOW_SPEED_OPERATION 392 - | USB_FULL_SPEED_OPERATION 393 - | USB_HIGH_SPEED_OPERATION 394 - | USB_5GBPS_OPERATION), 395 - .bFunctionalitySupport = USB_LOW_SPEED_OPERATION, 396 - .bU1devExitLat = USB_DEFAULT_U1_DEV_EXIT_LAT, 397 - .bU2DevExitLat = cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT), 398 - }; 399 - 400 - static __maybe_unused struct usb_bos_descriptor fsg_bos_desc = { 401 - .bLength = USB_DT_BOS_SIZE, 402 - .bDescriptorType = USB_DT_BOS, 403 - 404 - .wTotalLength = cpu_to_le16(USB_DT_BOS_SIZE 405 - + USB_DT_USB_EXT_CAP_SIZE 406 - + USB_DT_USB_SS_CAP_SIZE), 407 - 408 - .bNumDeviceCaps = 2, 409 - }; 410 - 411 388 static struct usb_descriptor_header *fsg_ss_function[] = { 412 389 (struct usb_descriptor_header *) &fsg_intf_desc, 413 390 (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc, ··· 381 428 (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, 382 429 NULL, 383 430 }; 384 - 385 - /* Maxpacket and other transfer characteristics vary by speed. */ 386 - static __maybe_unused struct usb_endpoint_descriptor * 387 - fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, 388 - struct usb_endpoint_descriptor *hs, 389 - struct usb_endpoint_descriptor *ss) 390 - { 391 - if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) 392 - return ss; 393 - else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 394 - return hs; 395 - return fs; 396 - } 397 - 398 431 399 432 /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ 400 433 static struct usb_string fsg_strings[] = {
+162 -161
drivers/usb/gadget/u_serial.c
··· 26 26 #include <linux/tty_flip.h> 27 27 #include <linux/slab.h> 28 28 #include <linux/export.h> 29 + #include <linux/module.h> 29 30 30 31 #include "u_serial.h" 31 32 ··· 36 35 * "serial port" functionality through the USB gadget stack. Each such 37 36 * port is exposed through a /dev/ttyGS* node. 38 37 * 39 - * After initialization (gserial_setup), these TTY port devices stay 40 - * available until they are removed (gserial_cleanup). Each one may be 41 - * connected to a USB function (gserial_connect), or disconnected (with 42 - * gserial_disconnect) when the USB host issues a config change event. 43 - * Data can only flow when the port is connected to the host. 38 + * After this module has been loaded, the individual TTY port can be requested 39 + * (gserial_alloc_line()) and it will stay available until they are removed 40 + * (gserial_free_line()). Each one may be connected to a USB function 41 + * (gserial_connect), or disconnected (with gserial_disconnect) when the USB 42 + * host issues a config change event. Data can only flow when the port is 43 + * connected to the host. 44 44 * 45 45 * A given TTY port can be made available in multiple configurations. 46 46 * For example, each one might expose a ttyGS0 node which provides a ··· 121 119 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */ 122 120 }; 123 121 124 - /* increase N_PORTS if you need more */ 125 - #define N_PORTS 4 126 122 static struct portmaster { 127 123 struct mutex lock; /* protect open/close */ 128 124 struct gs_port *port; 129 - } ports[N_PORTS]; 130 - static unsigned n_ports; 125 + } ports[MAX_U_SERIAL_PORTS]; 131 126 132 127 #define GS_CLOSE_TIMEOUT 15 /* seconds */ 133 128 ··· 308 309 309 310 return req; 310 311 } 312 + EXPORT_SYMBOL_GPL(gs_alloc_req); 311 313 312 314 /* 313 315 * gs_free_req ··· 320 320 kfree(req->buf); 321 321 usb_ep_free_request(ep, req); 322 322 } 323 + EXPORT_SYMBOL_GPL(gs_free_req); 323 324 324 325 /* 325 326 * gs_send_packet ··· 1031 1030 gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) 1032 1031 { 1033 1032 struct gs_port *port; 1033 + int ret = 0; 1034 + 1035 + mutex_lock(&ports[port_num].lock); 1036 + if (ports[port_num].port) { 1037 + ret = -EBUSY; 1038 + goto out; 1039 + } 1034 1040 1035 1041 port = kzalloc(sizeof(struct gs_port), GFP_KERNEL); 1036 - if (port == NULL) 1037 - return -ENOMEM; 1042 + if (port == NULL) { 1043 + ret = -ENOMEM; 1044 + goto out; 1045 + } 1038 1046 1039 1047 tty_port_init(&port->port); 1040 1048 spin_lock_init(&port->port_lock); ··· 1059 1049 port->port_line_coding = *coding; 1060 1050 1061 1051 ports[port_num].port = port; 1062 - 1063 - return 0; 1064 - } 1065 - 1066 - /** 1067 - * gserial_setup - initialize TTY driver for one or more ports 1068 - * @g: gadget to associate with these ports 1069 - * @count: how many ports to support 1070 - * Context: may sleep 1071 - * 1072 - * The TTY stack needs to know in advance how many devices it should 1073 - * plan to manage. Use this call to set up the ports you will be 1074 - * exporting through USB. Later, connect them to functions based 1075 - * on what configuration is activated by the USB host; and disconnect 1076 - * them as appropriate. 1077 - * 1078 - * An example would be a two-configuration device in which both 1079 - * configurations expose port 0, but through different functions. 1080 - * One configuration could even expose port 1 while the other 1081 - * one doesn't. 1082 - * 1083 - * Returns negative errno or zero. 1084 - */ 1085 - int gserial_setup(struct usb_gadget *g, unsigned count) 1086 - { 1087 - unsigned i; 1088 - struct usb_cdc_line_coding coding; 1089 - int status; 1090 - 1091 - if (count == 0 || count > N_PORTS) 1092 - return -EINVAL; 1093 - 1094 - gs_tty_driver = alloc_tty_driver(count); 1095 - if (!gs_tty_driver) 1096 - return -ENOMEM; 1097 - 1098 - gs_tty_driver->driver_name = "g_serial"; 1099 - gs_tty_driver->name = PREFIX; 1100 - /* uses dynamically assigned dev_t values */ 1101 - 1102 - gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; 1103 - gs_tty_driver->subtype = SERIAL_TYPE_NORMAL; 1104 - gs_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 1105 - gs_tty_driver->init_termios = tty_std_termios; 1106 - 1107 - /* 9600-8-N-1 ... matches defaults expected by "usbser.sys" on 1108 - * MS-Windows. Otherwise, most of these flags shouldn't affect 1109 - * anything unless we were to actually hook up to a serial line. 1110 - */ 1111 - gs_tty_driver->init_termios.c_cflag = 1112 - B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1113 - gs_tty_driver->init_termios.c_ispeed = 9600; 1114 - gs_tty_driver->init_termios.c_ospeed = 9600; 1115 - 1116 - coding.dwDTERate = cpu_to_le32(9600); 1117 - coding.bCharFormat = 8; 1118 - coding.bParityType = USB_CDC_NO_PARITY; 1119 - coding.bDataBits = USB_CDC_1_STOP_BITS; 1120 - 1121 - tty_set_operations(gs_tty_driver, &gs_tty_ops); 1122 - 1123 - /* make devices be openable */ 1124 - for (i = 0; i < count; i++) { 1125 - mutex_init(&ports[i].lock); 1126 - status = gs_port_alloc(i, &coding); 1127 - if (status) { 1128 - count = i; 1129 - goto fail; 1130 - } 1131 - } 1132 - n_ports = count; 1133 - 1134 - /* export the driver ... */ 1135 - status = tty_register_driver(gs_tty_driver); 1136 - if (status) { 1137 - pr_err("%s: cannot register, err %d\n", 1138 - __func__, status); 1139 - goto fail; 1140 - } 1141 - 1142 - /* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */ 1143 - for (i = 0; i < count; i++) { 1144 - struct device *tty_dev; 1145 - 1146 - tty_dev = tty_port_register_device(&ports[i].port->port, 1147 - gs_tty_driver, i, &g->dev); 1148 - if (IS_ERR(tty_dev)) 1149 - pr_warning("%s: no classdev for port %d, err %ld\n", 1150 - __func__, i, PTR_ERR(tty_dev)); 1151 - } 1152 - 1153 - pr_debug("%s: registered %d ttyGS* device%s\n", __func__, 1154 - count, (count == 1) ? "" : "s"); 1155 - 1156 - return status; 1157 - fail: 1158 - while (count--) { 1159 - tty_port_destroy(&ports[count].port->port); 1160 - kfree(ports[count].port); 1161 - } 1162 - put_tty_driver(gs_tty_driver); 1163 - gs_tty_driver = NULL; 1164 - return status; 1052 + out: 1053 + mutex_unlock(&ports[port_num].lock); 1054 + return ret; 1165 1055 } 1166 1056 1167 1057 static int gs_closed(struct gs_port *port) ··· 1074 1164 return cond; 1075 1165 } 1076 1166 1077 - /** 1078 - * gserial_cleanup - remove TTY-over-USB driver and devices 1079 - * Context: may sleep 1080 - * 1081 - * This is called to free all resources allocated by @gserial_setup(). 1082 - * Accordingly, it may need to wait until some open /dev/ files have 1083 - * closed. 1084 - * 1085 - * The caller must have issued @gserial_disconnect() for any ports 1086 - * that had previously been connected, so that there is never any 1087 - * I/O pending when it's called. 1088 - */ 1089 - void gserial_cleanup(void) 1167 + static void gserial_free_port(struct gs_port *port) 1090 1168 { 1091 - unsigned i; 1169 + tasklet_kill(&port->push); 1170 + /* wait for old opens to finish */ 1171 + wait_event(port->port.close_wait, gs_closed(port)); 1172 + WARN_ON(port->port_usb != NULL); 1173 + tty_port_destroy(&port->port); 1174 + kfree(port); 1175 + } 1176 + 1177 + void gserial_free_line(unsigned char port_num) 1178 + { 1092 1179 struct gs_port *port; 1093 1180 1094 - if (!gs_tty_driver) 1181 + mutex_lock(&ports[port_num].lock); 1182 + if (WARN_ON(!ports[port_num].port)) { 1183 + mutex_unlock(&ports[port_num].lock); 1095 1184 return; 1096 - 1097 - /* start sysfs and /dev/ttyGS* node removal */ 1098 - for (i = 0; i < n_ports; i++) 1099 - tty_unregister_device(gs_tty_driver, i); 1100 - 1101 - for (i = 0; i < n_ports; i++) { 1102 - /* prevent new opens */ 1103 - mutex_lock(&ports[i].lock); 1104 - port = ports[i].port; 1105 - ports[i].port = NULL; 1106 - mutex_unlock(&ports[i].lock); 1107 - 1108 - tasklet_kill(&port->push); 1109 - 1110 - /* wait for old opens to finish */ 1111 - wait_event(port->port.close_wait, gs_closed(port)); 1112 - 1113 - WARN_ON(port->port_usb != NULL); 1114 - 1115 - tty_port_destroy(&port->port); 1116 - kfree(port); 1117 1185 } 1118 - n_ports = 0; 1186 + port = ports[port_num].port; 1187 + ports[port_num].port = NULL; 1188 + mutex_unlock(&ports[port_num].lock); 1119 1189 1120 - tty_unregister_driver(gs_tty_driver); 1121 - put_tty_driver(gs_tty_driver); 1122 - gs_tty_driver = NULL; 1123 - 1124 - pr_debug("%s: cleaned up ttyGS* support\n", __func__); 1190 + gserial_free_port(port); 1191 + tty_unregister_device(gs_tty_driver, port_num); 1125 1192 } 1193 + EXPORT_SYMBOL_GPL(gserial_free_line); 1194 + 1195 + int gserial_alloc_line(unsigned char *line_num) 1196 + { 1197 + struct usb_cdc_line_coding coding; 1198 + struct device *tty_dev; 1199 + int ret; 1200 + int port_num; 1201 + 1202 + coding.dwDTERate = cpu_to_le32(9600); 1203 + coding.bCharFormat = 8; 1204 + coding.bParityType = USB_CDC_NO_PARITY; 1205 + coding.bDataBits = USB_CDC_1_STOP_BITS; 1206 + 1207 + for (port_num = 0; port_num < MAX_U_SERIAL_PORTS; port_num++) { 1208 + ret = gs_port_alloc(port_num, &coding); 1209 + if (ret == -EBUSY) 1210 + continue; 1211 + if (ret) 1212 + return ret; 1213 + break; 1214 + } 1215 + if (ret) 1216 + return ret; 1217 + 1218 + /* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */ 1219 + 1220 + tty_dev = tty_port_register_device(&ports[port_num].port->port, 1221 + gs_tty_driver, port_num, NULL); 1222 + if (IS_ERR(tty_dev)) { 1223 + struct gs_port *port; 1224 + pr_err("%s: failed to register tty for port %d, err %ld\n", 1225 + __func__, port_num, PTR_ERR(tty_dev)); 1226 + 1227 + ret = PTR_ERR(tty_dev); 1228 + port = ports[port_num].port; 1229 + ports[port_num].port = NULL; 1230 + gserial_free_port(port); 1231 + goto err; 1232 + } 1233 + *line_num = port_num; 1234 + err: 1235 + return ret; 1236 + } 1237 + EXPORT_SYMBOL_GPL(gserial_alloc_line); 1126 1238 1127 1239 /** 1128 1240 * gserial_connect - notify TTY I/O glue that USB link is active ··· 1161 1229 * 1162 1230 * Caller needs to have set up the endpoints and USB function in @dev 1163 1231 * before calling this, as well as the appropriate (speed-specific) 1164 - * endpoint descriptors, and also have set up the TTY driver by calling 1165 - * @gserial_setup(). 1232 + * endpoint descriptors, and also have allocate @port_num by calling 1233 + * @gserial_alloc_line(). 1166 1234 * 1167 1235 * Returns negative errno or zero. 1168 1236 * On success, ep->driver_data will be overwritten. ··· 1173 1241 unsigned long flags; 1174 1242 int status; 1175 1243 1176 - if (!gs_tty_driver || port_num >= n_ports) 1244 + if (port_num >= MAX_U_SERIAL_PORTS) 1177 1245 return -ENXIO; 1178 1246 1179 - /* we "know" gserial_cleanup() hasn't been called */ 1180 1247 port = ports[port_num].port; 1248 + if (!port) { 1249 + pr_err("serial line %d not allocated.\n", port_num); 1250 + return -EINVAL; 1251 + } 1252 + if (port->port_usb) { 1253 + pr_err("serial line %d is in use.\n", port_num); 1254 + return -EBUSY; 1255 + } 1181 1256 1182 1257 /* activate the endpoints */ 1183 1258 status = usb_ep_enable(gser->in); ··· 1231 1292 gser->in->driver_data = NULL; 1232 1293 return status; 1233 1294 } 1234 - 1295 + EXPORT_SYMBOL_GPL(gserial_connect); 1235 1296 /** 1236 1297 * gserial_disconnect - notify TTY I/O glue that USB link is inactive 1237 1298 * @gser: the function, on which gserial_connect() was called ··· 1286 1347 1287 1348 spin_unlock_irqrestore(&port->port_lock, flags); 1288 1349 } 1350 + EXPORT_SYMBOL_GPL(gserial_disconnect); 1351 + 1352 + static int userial_init(void) 1353 + { 1354 + unsigned i; 1355 + int status; 1356 + 1357 + gs_tty_driver = alloc_tty_driver(MAX_U_SERIAL_PORTS); 1358 + if (!gs_tty_driver) 1359 + return -ENOMEM; 1360 + 1361 + gs_tty_driver->driver_name = "g_serial"; 1362 + gs_tty_driver->name = PREFIX; 1363 + /* uses dynamically assigned dev_t values */ 1364 + 1365 + gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; 1366 + gs_tty_driver->subtype = SERIAL_TYPE_NORMAL; 1367 + gs_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 1368 + gs_tty_driver->init_termios = tty_std_termios; 1369 + 1370 + /* 9600-8-N-1 ... matches defaults expected by "usbser.sys" on 1371 + * MS-Windows. Otherwise, most of these flags shouldn't affect 1372 + * anything unless we were to actually hook up to a serial line. 1373 + */ 1374 + gs_tty_driver->init_termios.c_cflag = 1375 + B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1376 + gs_tty_driver->init_termios.c_ispeed = 9600; 1377 + gs_tty_driver->init_termios.c_ospeed = 9600; 1378 + 1379 + tty_set_operations(gs_tty_driver, &gs_tty_ops); 1380 + for (i = 0; i < MAX_U_SERIAL_PORTS; i++) 1381 + mutex_init(&ports[i].lock); 1382 + 1383 + /* export the driver ... */ 1384 + status = tty_register_driver(gs_tty_driver); 1385 + if (status) { 1386 + pr_err("%s: cannot register, err %d\n", 1387 + __func__, status); 1388 + goto fail; 1389 + } 1390 + 1391 + pr_debug("%s: registered %d ttyGS* device%s\n", __func__, 1392 + MAX_U_SERIAL_PORTS, 1393 + (MAX_U_SERIAL_PORTS == 1) ? "" : "s"); 1394 + 1395 + return status; 1396 + fail: 1397 + put_tty_driver(gs_tty_driver); 1398 + gs_tty_driver = NULL; 1399 + return status; 1400 + } 1401 + module_init(userial_init); 1402 + 1403 + static void userial_cleanup(void) 1404 + { 1405 + tty_unregister_driver(gs_tty_driver); 1406 + put_tty_driver(gs_tty_driver); 1407 + gs_tty_driver = NULL; 1408 + } 1409 + module_exit(userial_cleanup); 1410 + 1411 + MODULE_LICENSE("GPL");
+10 -3
drivers/usb/gadget/u_serial.h
··· 15 15 #include <linux/usb/composite.h> 16 16 #include <linux/usb/cdc.h> 17 17 18 + #define MAX_U_SERIAL_PORTS 4 19 + 20 + struct f_serial_opts { 21 + struct usb_function_instance func_inst; 22 + u8 port_num; 23 + }; 24 + 18 25 /* 19 26 * One non-multiplexed "serial" I/O port ... there can be several of these 20 27 * on any given USB peripheral device, if it provides enough endpoints. ··· 56 49 struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags); 57 50 void gs_free_req(struct usb_ep *, struct usb_request *req); 58 51 59 - /* port setup/teardown is handled by gadget driver */ 60 - int gserial_setup(struct usb_gadget *g, unsigned n_ports); 61 - void gserial_cleanup(void); 52 + /* management of individual TTY ports */ 53 + int gserial_alloc_line(unsigned char *port_line); 54 + void gserial_free_line(unsigned char port_line); 62 55 63 56 /* connect/disconnect is handled by individual functions */ 64 57 int gserial_connect(struct gserial *, u8 port_num);
+63 -94
drivers/usb/gadget/udc-core.c
··· 102 102 /* ------------------------------------------------------------------------- */ 103 103 104 104 /** 105 - * usb_gadget_start - tells usb device controller to start up 106 - * @gadget: The gadget we want to get started 107 - * @driver: The driver we want to bind to @gadget 108 - * @bind: The bind function for @driver 109 - * 110 - * This call is issued by the UDC Class driver when it's about 111 - * to register a gadget driver to the device controller, before 112 - * calling gadget driver's bind() method. 113 - * 114 - * It allows the controller to be powered off until strictly 115 - * necessary to have it powered on. 116 - * 117 - * Returns zero on success, else negative errno. 118 - */ 119 - static inline int usb_gadget_start(struct usb_gadget *gadget, 120 - struct usb_gadget_driver *driver, 121 - int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 122 - { 123 - return gadget->ops->start(driver, bind); 124 - } 125 - 126 - /** 127 105 * usb_gadget_udc_start - tells usb device controller to start up 128 106 * @gadget: The gadget we want to get started 129 107 * @driver: The driver we want to bind to @gadget ··· 119 141 struct usb_gadget_driver *driver) 120 142 { 121 143 return gadget->ops->udc_start(gadget, driver); 122 - } 123 - 124 - /** 125 - * usb_gadget_stop - tells usb device controller we don't need it anymore 126 - * @gadget: The device we want to stop activity 127 - * @driver: The driver to unbind from @gadget 128 - * 129 - * This call is issued by the UDC Class driver after calling 130 - * gadget driver's unbind() method. 131 - * 132 - * The details are implementation specific, but it can go as 133 - * far as powering off UDC completely and disable its data 134 - * line pullups. 135 - */ 136 - static inline void usb_gadget_stop(struct usb_gadget *gadget, 137 - struct usb_gadget_driver *driver) 138 - { 139 - gadget->ops->stop(driver); 140 144 } 141 145 142 146 /** ··· 206 246 } 207 247 EXPORT_SYMBOL_GPL(usb_add_gadget_udc); 208 248 209 - static int udc_is_newstyle(struct usb_udc *udc) 210 - { 211 - if (udc->gadget->ops->udc_start && udc->gadget->ops->udc_stop) 212 - return 1; 213 - return 0; 214 - } 215 - 216 - 217 249 static void usb_gadget_remove_driver(struct usb_udc *udc) 218 250 { 219 251 dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n", ··· 213 261 214 262 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 215 263 216 - if (udc_is_newstyle(udc)) { 217 - usb_gadget_disconnect(udc->gadget); 218 - udc->driver->disconnect(udc->gadget); 219 - udc->driver->unbind(udc->gadget); 220 - usb_gadget_udc_stop(udc->gadget, udc->driver); 221 - } else { 222 - usb_gadget_stop(udc->gadget, udc->driver); 223 - } 264 + usb_gadget_disconnect(udc->gadget); 265 + udc->driver->disconnect(udc->gadget); 266 + udc->driver->unbind(udc->gadget); 267 + usb_gadget_udc_stop(udc->gadget, udc->driver); 224 268 225 269 udc->driver = NULL; 226 270 udc->dev.driver = NULL; ··· 259 311 260 312 /* ------------------------------------------------------------------------- */ 261 313 314 + static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver) 315 + { 316 + int ret; 317 + 318 + dev_dbg(&udc->dev, "registering UDC driver [%s]\n", 319 + driver->function); 320 + 321 + udc->driver = driver; 322 + udc->dev.driver = &driver->driver; 323 + 324 + ret = driver->bind(udc->gadget, driver); 325 + if (ret) 326 + goto err1; 327 + ret = usb_gadget_udc_start(udc->gadget, driver); 328 + if (ret) { 329 + driver->unbind(udc->gadget); 330 + goto err1; 331 + } 332 + usb_gadget_connect(udc->gadget); 333 + 334 + kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 335 + return 0; 336 + err1: 337 + dev_err(&udc->dev, "failed to start %s: %d\n", 338 + udc->driver->function, ret); 339 + udc->driver = NULL; 340 + udc->dev.driver = NULL; 341 + return ret; 342 + } 343 + 344 + int udc_attach_driver(const char *name, struct usb_gadget_driver *driver) 345 + { 346 + struct usb_udc *udc = NULL; 347 + int ret = -ENODEV; 348 + 349 + mutex_lock(&udc_lock); 350 + list_for_each_entry(udc, &udc_list, list) { 351 + ret = strcmp(name, dev_name(&udc->dev)); 352 + if (!ret) 353 + break; 354 + } 355 + if (ret) { 356 + ret = -ENODEV; 357 + goto out; 358 + } 359 + if (udc->driver) { 360 + ret = -EBUSY; 361 + goto out; 362 + } 363 + ret = udc_bind_to_driver(udc, driver); 364 + out: 365 + mutex_unlock(&udc_lock); 366 + return ret; 367 + } 368 + EXPORT_SYMBOL_GPL(udc_attach_driver); 369 + 262 370 int usb_gadget_probe_driver(struct usb_gadget_driver *driver) 263 371 { 264 372 struct usb_udc *udc = NULL; ··· 333 329 pr_debug("couldn't find an available UDC\n"); 334 330 mutex_unlock(&udc_lock); 335 331 return -ENODEV; 336 - 337 332 found: 338 - dev_dbg(&udc->dev, "registering UDC driver [%s]\n", 339 - driver->function); 340 - 341 - udc->driver = driver; 342 - udc->dev.driver = &driver->driver; 343 - 344 - if (udc_is_newstyle(udc)) { 345 - ret = driver->bind(udc->gadget, driver); 346 - if (ret) 347 - goto err1; 348 - ret = usb_gadget_udc_start(udc->gadget, driver); 349 - if (ret) { 350 - driver->unbind(udc->gadget); 351 - goto err1; 352 - } 353 - usb_gadget_connect(udc->gadget); 354 - } else { 355 - 356 - ret = usb_gadget_start(udc->gadget, driver, driver->bind); 357 - if (ret) 358 - goto err1; 359 - 360 - } 361 - 362 - kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 363 - mutex_unlock(&udc_lock); 364 - return 0; 365 - 366 - err1: 367 - dev_err(&udc->dev, "failed to start %s: %d\n", 368 - udc->driver->function, ret); 369 - udc->driver = NULL; 370 - udc->dev.driver = NULL; 333 + ret = udc_bind_to_driver(udc, driver); 371 334 mutex_unlock(&udc_lock); 372 335 return ret; 373 336 } ··· 381 410 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 382 411 383 412 if (sysfs_streq(buf, "connect")) { 384 - if (udc_is_newstyle(udc)) 385 - usb_gadget_udc_start(udc->gadget, udc->driver); 413 + usb_gadget_udc_start(udc->gadget, udc->driver); 386 414 usb_gadget_connect(udc->gadget); 387 415 } else if (sysfs_streq(buf, "disconnect")) { 388 416 usb_gadget_disconnect(udc->gadget); 389 - if (udc_is_newstyle(udc)) 390 - usb_gadget_udc_stop(udc->gadget, udc->driver); 417 + usb_gadget_udc_stop(udc->gadget, udc->driver); 391 418 } else { 392 419 dev_err(dev, "unsupported command '%s'\n", buf); 393 420 return -EINVAL;
+1 -1
drivers/usb/gadget/webcam.c
··· 336 336 .bConfigurationValue = 1, 337 337 .iConfiguration = 0, /* dynamic */ 338 338 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 339 - .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, 339 + .MaxPower = CONFIG_USB_GADGET_VBUS_DRAW, 340 340 }; 341 341 342 342 static int /* __init_or_exit */
+157 -76
drivers/usb/gadget/zero.c
··· 10 10 * (at your option) any later version. 11 11 */ 12 12 13 - 14 13 /* 15 14 * Gadget Zero only needs two bulk endpoints, and is an example of how you 16 15 * can write a hardware-agnostic gadget driver running inside a USB device. ··· 42 43 #include <linux/kernel.h> 43 44 #include <linux/slab.h> 44 45 #include <linux/device.h> 46 + #include <linux/module.h> 47 + #include <linux/err.h> 48 + #include <linux/usb/composite.h> 45 49 46 50 #include "g_zero.h" 47 - #include "gadget_chips.h" 48 - 49 - 50 - /*-------------------------------------------------------------------------*/ 51 - 52 - /* 53 - * Kbuild is not very cooperative with respect to linking separately 54 - * compiled library objects into one module. So for now we won't use 55 - * separate compilation ... ensuring init/exit sections work to shrink 56 - * the runtime footprint, and giving us at least some parts of what 57 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 58 - */ 59 - #include "f_sourcesink.c" 60 - #include "f_loopback.c" 61 - 62 51 /*-------------------------------------------------------------------------*/ 63 52 USB_GADGET_COMPOSITE_OPTIONS(); 64 53 65 54 #define DRIVER_VERSION "Cinco de Mayo 2008" 66 55 67 56 static const char longname[] = "Gadget Zero"; 68 - 69 - unsigned buflen = 4096; /* only used for bulk endpoints */ 70 - module_param(buflen, uint, 0); 71 57 72 58 /* 73 59 * Normally the "loopback" configuration is second (index 1) so ··· 62 78 */ 63 79 static bool loopdefault = 0; 64 80 module_param(loopdefault, bool, S_IRUGO|S_IWUSR); 81 + 82 + static struct usb_zero_options gzero_options = { 83 + .isoc_interval = 4, 84 + .isoc_maxpacket = 1024, 85 + .bulk_buflen = 4096, 86 + .qlen = 32, 87 + }; 65 88 66 89 /*-------------------------------------------------------------------------*/ 67 90 ··· 120 129 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, 121 130 }; 122 131 123 - const struct usb_descriptor_header *otg_desc[] = { 132 + static const struct usb_descriptor_header *otg_desc[] = { 124 133 (struct usb_descriptor_header *) &otg_descriptor, 125 134 NULL, 126 135 }; 136 + #else 137 + #define otg_desc NULL 127 138 #endif 128 139 129 140 /* string IDs are assigned dynamically */ 130 141 /* default serial number takes at least two packets */ 131 142 static char serial[] = "0123456789.0123456789.0123456789"; 132 143 144 + #define USB_GZERO_SS_DESC (USB_GADGET_FIRST_AVAIL_IDX + 0) 145 + #define USB_GZERO_LB_DESC (USB_GADGET_FIRST_AVAIL_IDX + 1) 146 + 133 147 static struct usb_string strings_dev[] = { 134 148 [USB_GADGET_MANUFACTURER_IDX].s = "", 135 149 [USB_GADGET_PRODUCT_IDX].s = longname, 136 150 [USB_GADGET_SERIAL_IDX].s = serial, 151 + [USB_GZERO_SS_DESC].s = "source and sink data", 152 + [USB_GZERO_LB_DESC].s = "loop input to output", 137 153 { } /* end of list */ 138 154 }; 139 155 ··· 153 155 &stringtab_dev, 154 156 NULL, 155 157 }; 156 - 157 - /*-------------------------------------------------------------------------*/ 158 - 159 - struct usb_request *alloc_ep_req(struct usb_ep *ep, int len) 160 - { 161 - struct usb_request *req; 162 - 163 - req = usb_ep_alloc_request(ep, GFP_ATOMIC); 164 - if (req) { 165 - if (len) 166 - req->length = len; 167 - else 168 - req->length = buflen; 169 - req->buf = kmalloc(req->length, GFP_ATOMIC); 170 - if (!req->buf) { 171 - usb_ep_free_request(ep, req); 172 - req = NULL; 173 - } 174 - } 175 - return req; 176 - } 177 - 178 - void free_ep_req(struct usb_ep *ep, struct usb_request *req) 179 - { 180 - kfree(req->buf); 181 - usb_ep_free_request(ep, req); 182 - } 183 - 184 - static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep) 185 - { 186 - int value; 187 - 188 - if (ep->driver_data) { 189 - value = usb_ep_disable(ep); 190 - if (value < 0) 191 - DBG(cdev, "disable %s --> %d\n", 192 - ep->name, value); 193 - ep->driver_data = NULL; 194 - } 195 - } 196 - 197 - void disable_endpoints(struct usb_composite_dev *cdev, 198 - struct usb_ep *in, struct usb_ep *out, 199 - struct usb_ep *iso_in, struct usb_ep *iso_out) 200 - { 201 - disable_ep(cdev, in); 202 - disable_ep(cdev, out); 203 - if (iso_in) 204 - disable_ep(cdev, iso_in); 205 - if (iso_out) 206 - disable_ep(cdev, iso_out); 207 - } 208 158 209 159 /*-------------------------------------------------------------------------*/ 210 160 ··· 197 251 198 252 /*-------------------------------------------------------------------------*/ 199 253 254 + static struct usb_configuration loopback_driver = { 255 + .label = "loopback", 256 + .bConfigurationValue = 2, 257 + .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 258 + /* .iConfiguration = DYNAMIC */ 259 + }; 260 + 261 + static struct usb_function *func_ss; 262 + static struct usb_function_instance *func_inst_ss; 263 + 264 + static int ss_config_setup(struct usb_configuration *c, 265 + const struct usb_ctrlrequest *ctrl) 266 + { 267 + switch (ctrl->bRequest) { 268 + case 0x5b: 269 + case 0x5c: 270 + return func_ss->setup(func_ss, ctrl); 271 + default: 272 + return -EOPNOTSUPP; 273 + } 274 + } 275 + 276 + static struct usb_configuration sourcesink_driver = { 277 + .label = "source/sink", 278 + .setup = ss_config_setup, 279 + .bConfigurationValue = 3, 280 + .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 281 + /* .iConfiguration = DYNAMIC */ 282 + }; 283 + 284 + module_param_named(buflen, gzero_options.bulk_buflen, uint, 0); 285 + module_param_named(pattern, gzero_options.pattern, uint, S_IRUGO|S_IWUSR); 286 + MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63, 2 = none"); 287 + 288 + module_param_named(isoc_interval, gzero_options.isoc_interval, uint, 289 + S_IRUGO|S_IWUSR); 290 + MODULE_PARM_DESC(isoc_interval, "1 - 16"); 291 + 292 + module_param_named(isoc_maxpacket, gzero_options.isoc_maxpacket, uint, 293 + S_IRUGO|S_IWUSR); 294 + MODULE_PARM_DESC(isoc_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)"); 295 + 296 + module_param_named(isoc_mult, gzero_options.isoc_mult, uint, S_IRUGO|S_IWUSR); 297 + MODULE_PARM_DESC(isoc_mult, "0 - 2 (hs/ss only)"); 298 + 299 + module_param_named(isoc_maxburst, gzero_options.isoc_maxburst, uint, 300 + S_IRUGO|S_IWUSR); 301 + MODULE_PARM_DESC(isoc_maxburst, "0 - 15 (ss only)"); 302 + 303 + static struct usb_function *func_lb; 304 + static struct usb_function_instance *func_inst_lb; 305 + 306 + module_param_named(qlen, gzero_options.qlen, uint, S_IRUGO|S_IWUSR); 307 + MODULE_PARM_DESC(qlen, "depth of loopback queue"); 308 + 200 309 static int __init zero_bind(struct usb_composite_dev *cdev) 201 310 { 311 + struct f_ss_opts *ss_opts; 312 + struct f_lb_opts *lb_opts; 202 313 int status; 203 314 204 315 /* Allocate string descriptor numbers ... note that string ··· 271 268 272 269 setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev); 273 270 271 + func_inst_ss = usb_get_function_instance("SourceSink"); 272 + if (IS_ERR(func_inst_ss)) 273 + return PTR_ERR(func_inst_ss); 274 + 275 + ss_opts = container_of(func_inst_ss, struct f_ss_opts, func_inst); 276 + ss_opts->pattern = gzero_options.pattern; 277 + ss_opts->isoc_interval = gzero_options.isoc_interval; 278 + ss_opts->isoc_maxpacket = gzero_options.isoc_maxpacket; 279 + ss_opts->isoc_mult = gzero_options.isoc_mult; 280 + ss_opts->isoc_maxburst = gzero_options.isoc_maxpacket; 281 + ss_opts->bulk_buflen = gzero_options.bulk_buflen; 282 + 283 + func_ss = usb_get_function(func_inst_ss); 284 + if (IS_ERR(func_ss)) 285 + goto err_put_func_inst_ss; 286 + 287 + func_inst_lb = usb_get_function_instance("Loopback"); 288 + if (IS_ERR(func_inst_lb)) 289 + goto err_put_func_ss; 290 + 291 + lb_opts = container_of(func_inst_lb, struct f_lb_opts, func_inst); 292 + lb_opts->bulk_buflen = gzero_options.bulk_buflen; 293 + lb_opts->qlen = gzero_options.qlen; 294 + 295 + func_lb = usb_get_function(func_inst_lb); 296 + if (IS_ERR(func_lb)) { 297 + status = PTR_ERR(func_lb); 298 + goto err_put_func_inst_lb; 299 + } 300 + 301 + sourcesink_driver.iConfiguration = strings_dev[USB_GZERO_SS_DESC].id; 302 + loopback_driver.iConfiguration = strings_dev[USB_GZERO_LB_DESC].id; 303 + 304 + /* support autoresume for remote wakeup testing */ 305 + sourcesink_driver.bmAttributes &= ~USB_CONFIG_ATT_WAKEUP; 306 + loopback_driver.bmAttributes &= ~USB_CONFIG_ATT_WAKEUP; 307 + sourcesink_driver.descriptors = NULL; 308 + loopback_driver.descriptors = NULL; 309 + if (autoresume) { 310 + sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 311 + loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 312 + } 313 + 314 + /* support OTG systems */ 315 + if (gadget_is_otg(cdev->gadget)) { 316 + sourcesink_driver.descriptors = otg_desc; 317 + sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 318 + loopback_driver.descriptors = otg_desc; 319 + loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 320 + } 321 + 274 322 /* Register primary, then secondary configuration. Note that 275 323 * SH3 only allows one config... 276 324 */ 277 325 if (loopdefault) { 278 - loopback_add(cdev, autoresume != 0); 279 - sourcesink_add(cdev, autoresume != 0); 326 + usb_add_config_only(cdev, &loopback_driver); 327 + usb_add_config_only(cdev, &sourcesink_driver); 280 328 } else { 281 - sourcesink_add(cdev, autoresume != 0); 282 - loopback_add(cdev, autoresume != 0); 329 + usb_add_config_only(cdev, &sourcesink_driver); 330 + usb_add_config_only(cdev, &loopback_driver); 283 331 } 332 + status = usb_add_function(&sourcesink_driver, func_ss); 333 + if (status) 334 + goto err_conf_flb; 284 335 336 + usb_ep_autoconfig_reset(cdev->gadget); 337 + status = usb_add_function(&loopback_driver, func_lb); 338 + if (status) 339 + goto err_conf_flb; 340 + 341 + usb_ep_autoconfig_reset(cdev->gadget); 285 342 usb_composite_overwrite_options(cdev, &coverwrite); 286 343 287 344 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname); 288 345 289 346 return 0; 347 + 348 + err_conf_flb: 349 + usb_put_function(func_lb); 350 + func_lb = NULL; 351 + err_put_func_inst_lb: 352 + usb_put_function_instance(func_inst_lb); 353 + func_inst_lb = NULL; 354 + err_put_func_ss: 355 + usb_put_function(func_ss); 356 + func_ss = NULL; 357 + err_put_func_inst_ss: 358 + usb_put_function_instance(func_inst_ss); 359 + func_inst_ss = NULL; 360 + return status; 290 361 } 291 362 292 363 static int zero_unbind(struct usb_composite_dev *cdev) 293 364 { 294 365 del_timer_sync(&autoresume_timer); 366 + if (!IS_ERR_OR_NULL(func_ss)) 367 + usb_put_function(func_ss); 368 + if (!IS_ERR_OR_NULL(func_lb)) 369 + usb_put_function(func_lb); 295 370 return 0; 296 371 } 297 372
+1 -1
drivers/usb/host/Kconfig
··· 246 246 247 247 config USB_OXU210HP_HCD 248 248 tristate "OXU210HP HCD support" 249 - depends on USB 249 + depends on USB && GENERIC_HARDIRQS 250 250 ---help--- 251 251 The OXU210HP is an USB host/OTG/device controller. Enable this 252 252 option if your board has this chip. If unsure, say N.
-1
drivers/usb/host/ehci-mv.c
··· 302 302 { 303 303 struct ehci_hcd_mv *ehci_mv = platform_get_drvdata(pdev); 304 304 struct usb_hcd *hcd = ehci_mv->hcd; 305 - int clk_i; 306 305 307 306 if (hcd->rh_registered) 308 307 usb_remove_hcd(hcd);
-20
drivers/usb/host/ehci-mxc.c
··· 57 57 struct usb_hcd *hcd; 58 58 struct resource *res; 59 59 int irq, ret; 60 - unsigned int flags; 61 60 struct ehci_mxc_priv *priv; 62 61 struct device *dev = &pdev->dev; 63 62 struct ehci_hcd *ehci; ··· 160 161 ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 161 162 if (ret) 162 163 goto err_add; 163 - 164 - if (pdata->otg) { 165 - /* 166 - * efikamx and efikasb have some hardware bug which is 167 - * preventing usb to work unless CHRGVBUS is set. 168 - * It's in violation of USB specs 169 - */ 170 - if (machine_is_mx51_efikamx() || machine_is_mx51_efikasb()) { 171 - flags = usb_phy_io_read(pdata->otg, 172 - ULPI_OTG_CTRL); 173 - flags |= ULPI_OTG_CTRL_CHRGVBUS; 174 - ret = usb_phy_io_write(pdata->otg, flags, 175 - ULPI_OTG_CTRL); 176 - if (ret) { 177 - dev_err(dev, "unable to set CHRVBUS\n"); 178 - goto err_add; 179 - } 180 - } 181 - } 182 164 183 165 return 0; 184 166
+1 -9
drivers/usb/host/ehci-omap.c
··· 288 288 { 289 289 struct device *dev = &pdev->dev; 290 290 struct usb_hcd *hcd = dev_get_drvdata(dev); 291 - struct ehci_hcd_omap_platform_data *pdata = dev->platform_data; 292 291 293 292 usb_remove_hcd(hcd); 294 293 disable_put_regulator(dev->platform_data); ··· 297 298 pm_runtime_put_sync(dev); 298 299 pm_runtime_disable(dev); 299 300 300 - if (pdata->phy_reset) { 301 - if (gpio_is_valid(pdata->reset_gpio_port[0])) 302 - gpio_free(pdata->reset_gpio_port[0]); 303 - 304 - if (gpio_is_valid(pdata->reset_gpio_port[1])) 305 - gpio_free(pdata->reset_gpio_port[1]); 306 - } 307 301 return 0; 308 302 } 309 303 ··· 364 372 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 365 373 }; 366 374 367 - MODULE_ALIAS("platform:omap-ehci"); 375 + MODULE_ALIAS("platform:ehci-omap"); 368 376 MODULE_AUTHOR("Texas Instruments, Inc."); 369 377 MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>"); 370 378
+61 -22
drivers/usb/host/ehci-s5p.c
··· 17 17 #include <linux/platform_device.h> 18 18 #include <linux/of_gpio.h> 19 19 #include <linux/platform_data/usb-ehci-s5p.h> 20 + #include <linux/usb/phy.h> 21 + #include <linux/usb/samsung_usb_phy.h> 20 22 #include <plat/usb-phy.h> 21 23 22 24 #define EHCI_INSNREG00(base) (base + 0x90) ··· 34 32 struct device *dev; 35 33 struct usb_hcd *hcd; 36 34 struct clk *clk; 35 + struct usb_phy *phy; 36 + struct usb_otg *otg; 37 + struct s5p_ehci_platdata *pdata; 37 38 }; 38 39 39 40 static const struct hc_driver s5p_ehci_hc_driver = { ··· 70 65 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 71 66 }; 72 67 68 + static void s5p_ehci_phy_enable(struct s5p_ehci_hcd *s5p_ehci) 69 + { 70 + struct platform_device *pdev = to_platform_device(s5p_ehci->dev); 71 + 72 + if (s5p_ehci->phy) 73 + usb_phy_init(s5p_ehci->phy); 74 + else if (s5p_ehci->pdata->phy_init) 75 + s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST); 76 + } 77 + 78 + static void s5p_ehci_phy_disable(struct s5p_ehci_hcd *s5p_ehci) 79 + { 80 + struct platform_device *pdev = to_platform_device(s5p_ehci->dev); 81 + 82 + if (s5p_ehci->phy) 83 + usb_phy_shutdown(s5p_ehci->phy); 84 + else if (s5p_ehci->pdata->phy_exit) 85 + s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST); 86 + } 87 + 73 88 static void s5p_setup_vbus_gpio(struct platform_device *pdev) 74 89 { 75 90 int err; ··· 112 87 113 88 static int s5p_ehci_probe(struct platform_device *pdev) 114 89 { 115 - struct s5p_ehci_platdata *pdata; 90 + struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; 116 91 struct s5p_ehci_hcd *s5p_ehci; 117 92 struct usb_hcd *hcd; 118 93 struct ehci_hcd *ehci; 119 94 struct resource *res; 95 + struct usb_phy *phy; 120 96 int irq; 121 97 int err; 122 - 123 - pdata = pdev->dev.platform_data; 124 - if (!pdata) { 125 - dev_err(&pdev->dev, "No platform data defined\n"); 126 - return -EINVAL; 127 - } 128 98 129 99 /* 130 100 * Right now device-tree probed devices don't get dma_mask set. ··· 137 117 GFP_KERNEL); 138 118 if (!s5p_ehci) 139 119 return -ENOMEM; 120 + 121 + phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 122 + if (IS_ERR_OR_NULL(phy)) { 123 + /* Fallback to pdata */ 124 + if (!pdata) { 125 + dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); 126 + return -EPROBE_DEFER; 127 + } else { 128 + s5p_ehci->pdata = pdata; 129 + } 130 + } else { 131 + s5p_ehci->phy = phy; 132 + s5p_ehci->otg = phy->otg; 133 + } 140 134 141 135 s5p_ehci->dev = &pdev->dev; 142 136 ··· 197 163 goto fail_io; 198 164 } 199 165 200 - if (pdata->phy_init) 201 - pdata->phy_init(pdev, S5P_USB_PHY_HOST); 166 + if (s5p_ehci->otg) 167 + s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self); 168 + 169 + s5p_ehci_phy_enable(s5p_ehci); 202 170 203 171 ehci = hcd_to_ehci(hcd); 204 172 ehci->caps = hcd->regs; ··· 211 175 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 212 176 if (err) { 213 177 dev_err(&pdev->dev, "Failed to add USB HCD\n"); 214 - goto fail_io; 178 + goto fail_add_hcd; 215 179 } 216 180 217 181 platform_set_drvdata(pdev, s5p_ehci); 218 182 219 183 return 0; 220 184 185 + fail_add_hcd: 186 + s5p_ehci_phy_disable(s5p_ehci); 221 187 fail_io: 222 188 clk_disable_unprepare(s5p_ehci->clk); 223 189 fail_clk: ··· 229 191 230 192 static int s5p_ehci_remove(struct platform_device *pdev) 231 193 { 232 - struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; 233 194 struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); 234 195 struct usb_hcd *hcd = s5p_ehci->hcd; 235 196 236 197 usb_remove_hcd(hcd); 237 198 238 - if (pdata && pdata->phy_exit) 239 - pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 199 + if (s5p_ehci->otg) 200 + s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self); 201 + 202 + s5p_ehci_phy_disable(s5p_ehci); 240 203 241 204 clk_disable_unprepare(s5p_ehci->clk); 242 205 ··· 261 222 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev); 262 223 struct usb_hcd *hcd = s5p_ehci->hcd; 263 224 bool do_wakeup = device_may_wakeup(dev); 264 - struct platform_device *pdev = to_platform_device(dev); 265 - struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; 266 225 int rc; 267 226 268 227 rc = ehci_suspend(hcd, do_wakeup); 269 228 270 - if (pdata && pdata->phy_exit) 271 - pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 229 + if (s5p_ehci->otg) 230 + s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self); 231 + 232 + s5p_ehci_phy_disable(s5p_ehci); 272 233 273 234 clk_disable_unprepare(s5p_ehci->clk); 274 235 ··· 279 240 { 280 241 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev); 281 242 struct usb_hcd *hcd = s5p_ehci->hcd; 282 - struct platform_device *pdev = to_platform_device(dev); 283 - struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; 284 243 285 244 clk_prepare_enable(s5p_ehci->clk); 286 245 287 - if (pdata && pdata->phy_init) 288 - pdata->phy_init(pdev, S5P_USB_PHY_HOST); 246 + if (s5p_ehci->otg) 247 + s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self); 248 + 249 + s5p_ehci_phy_enable(s5p_ehci); 289 250 290 251 /* DMA burst Enable */ 291 252 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); ··· 305 266 306 267 #ifdef CONFIG_OF 307 268 static const struct of_device_id exynos_ehci_match[] = { 308 - { .compatible = "samsung,exynos-ehci" }, 269 + { .compatible = "samsung,exynos4210-ehci" }, 309 270 {}, 310 271 }; 311 272 MODULE_DEVICE_TABLE(of, exynos_ehci_match);
+2 -2
drivers/usb/host/isp1760-hcd.c
··· 932 932 } 933 933 } 934 934 935 - void schedule_ptds(struct usb_hcd *hcd) 935 + static void schedule_ptds(struct usb_hcd *hcd) 936 936 { 937 937 struct isp1760_hcd *priv; 938 938 struct isp1760_qh *qh, *qh_next; ··· 1285 1285 #define SLOT_CHECK_PERIOD 200 1286 1286 static struct timer_list errata2_timer; 1287 1287 1288 - void errata2_function(unsigned long data) 1288 + static void errata2_function(unsigned long data) 1289 1289 { 1290 1290 struct usb_hcd *hcd = (struct usb_hcd *) data; 1291 1291 struct isp1760_hcd *priv = hcd_to_priv(hcd);
+65 -22
drivers/usb/host/ohci-exynos.c
··· 15 15 #include <linux/of.h> 16 16 #include <linux/platform_device.h> 17 17 #include <linux/platform_data/usb-exynos.h> 18 + #include <linux/usb/phy.h> 19 + #include <linux/usb/samsung_usb_phy.h> 18 20 #include <plat/usb-phy.h> 19 21 20 22 struct exynos_ohci_hcd { 21 23 struct device *dev; 22 24 struct usb_hcd *hcd; 23 25 struct clk *clk; 26 + struct usb_phy *phy; 27 + struct usb_otg *otg; 28 + struct exynos4_ohci_platdata *pdata; 24 29 }; 30 + 31 + static void exynos_ohci_phy_enable(struct exynos_ohci_hcd *exynos_ohci) 32 + { 33 + struct platform_device *pdev = to_platform_device(exynos_ohci->dev); 34 + 35 + if (exynos_ohci->phy) 36 + usb_phy_init(exynos_ohci->phy); 37 + else if (exynos_ohci->pdata->phy_init) 38 + exynos_ohci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST); 39 + } 40 + 41 + static void exynos_ohci_phy_disable(struct exynos_ohci_hcd *exynos_ohci) 42 + { 43 + struct platform_device *pdev = to_platform_device(exynos_ohci->dev); 44 + 45 + if (exynos_ohci->phy) 46 + usb_phy_shutdown(exynos_ohci->phy); 47 + else if (exynos_ohci->pdata->phy_exit) 48 + exynos_ohci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST); 49 + } 25 50 26 51 static int ohci_exynos_reset(struct usb_hcd *hcd) 27 52 { ··· 103 78 104 79 static int exynos_ohci_probe(struct platform_device *pdev) 105 80 { 106 - struct exynos4_ohci_platdata *pdata; 81 + struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data; 107 82 struct exynos_ohci_hcd *exynos_ohci; 108 83 struct usb_hcd *hcd; 109 84 struct ohci_hcd *ohci; 110 85 struct resource *res; 86 + struct usb_phy *phy; 111 87 int irq; 112 88 int err; 113 - 114 - pdata = pdev->dev.platform_data; 115 - if (!pdata) { 116 - dev_err(&pdev->dev, "No platform data defined\n"); 117 - return -EINVAL; 118 - } 119 89 120 90 /* 121 91 * Right now device-tree probed devices don't get dma_mask set. ··· 126 106 GFP_KERNEL); 127 107 if (!exynos_ohci) 128 108 return -ENOMEM; 109 + 110 + phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 111 + if (IS_ERR_OR_NULL(phy)) { 112 + /* Fallback to pdata */ 113 + if (!pdata) { 114 + dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); 115 + return -EPROBE_DEFER; 116 + } else { 117 + exynos_ohci->pdata = pdata; 118 + } 119 + } else { 120 + exynos_ohci->phy = phy; 121 + exynos_ohci->otg = phy->otg; 122 + } 129 123 130 124 exynos_ohci->dev = &pdev->dev; 131 125 ··· 186 152 goto fail_io; 187 153 } 188 154 189 - if (pdata->phy_init) 190 - pdata->phy_init(pdev, S5P_USB_PHY_HOST); 155 + if (exynos_ohci->otg) 156 + exynos_ohci->otg->set_host(exynos_ohci->otg, 157 + &exynos_ohci->hcd->self); 158 + 159 + exynos_ohci_phy_enable(exynos_ohci); 191 160 192 161 ohci = hcd_to_ohci(hcd); 193 162 ohci_hcd_init(ohci); ··· 198 161 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 199 162 if (err) { 200 163 dev_err(&pdev->dev, "Failed to add USB HCD\n"); 201 - goto fail_io; 164 + goto fail_add_hcd; 202 165 } 203 166 204 167 platform_set_drvdata(pdev, exynos_ohci); 205 168 206 169 return 0; 207 170 171 + fail_add_hcd: 172 + exynos_ohci_phy_disable(exynos_ohci); 208 173 fail_io: 209 174 clk_disable_unprepare(exynos_ohci->clk); 210 175 fail_clk: ··· 216 177 217 178 static int exynos_ohci_remove(struct platform_device *pdev) 218 179 { 219 - struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data; 220 180 struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev); 221 181 struct usb_hcd *hcd = exynos_ohci->hcd; 222 182 223 183 usb_remove_hcd(hcd); 224 184 225 - if (pdata && pdata->phy_exit) 226 - pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 185 + if (exynos_ohci->otg) 186 + exynos_ohci->otg->set_host(exynos_ohci->otg, 187 + &exynos_ohci->hcd->self); 188 + 189 + exynos_ohci_phy_disable(exynos_ohci); 227 190 228 191 clk_disable_unprepare(exynos_ohci->clk); 229 192 ··· 249 208 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev); 250 209 struct usb_hcd *hcd = exynos_ohci->hcd; 251 210 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 252 - struct platform_device *pdev = to_platform_device(dev); 253 - struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data; 254 211 unsigned long flags; 255 212 int rc = 0; 256 213 ··· 267 228 268 229 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 269 230 270 - if (pdata && pdata->phy_exit) 271 - pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 231 + if (exynos_ohci->otg) 232 + exynos_ohci->otg->set_host(exynos_ohci->otg, 233 + &exynos_ohci->hcd->self); 234 + 235 + exynos_ohci_phy_disable(exynos_ohci); 272 236 273 237 clk_disable_unprepare(exynos_ohci->clk); 274 238 ··· 285 243 { 286 244 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev); 287 245 struct usb_hcd *hcd = exynos_ohci->hcd; 288 - struct platform_device *pdev = to_platform_device(dev); 289 - struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data; 290 246 291 247 clk_prepare_enable(exynos_ohci->clk); 292 248 293 - if (pdata && pdata->phy_init) 294 - pdata->phy_init(pdev, S5P_USB_PHY_HOST); 249 + if (exynos_ohci->otg) 250 + exynos_ohci->otg->set_host(exynos_ohci->otg, 251 + &exynos_ohci->hcd->self); 252 + 253 + exynos_ohci_phy_enable(exynos_ohci); 295 254 296 255 ohci_resume(hcd, false); 297 256 ··· 310 267 311 268 #ifdef CONFIG_OF 312 269 static const struct of_device_id exynos_ohci_match[] = { 313 - { .compatible = "samsung,exynos-ohci" }, 270 + { .compatible = "samsung,exynos4210-ohci" }, 314 271 {}, 315 272 }; 316 273 MODULE_DEVICE_TABLE(of, exynos_ohci_match);
+1
drivers/usb/host/ohci-q.c
··· 44 44 // ASSERT (urb->hcpriv != 0); 45 45 46 46 urb_free_priv (ohci, urb->hcpriv); 47 + urb->hcpriv = NULL; 47 48 if (likely(status == -EINPROGRESS)) 48 49 status = 0; 49 50
+120 -58
drivers/usb/host/uhci-debug.c
··· 16 16 17 17 #include "uhci-hcd.h" 18 18 19 + #define EXTRA_SPACE 1024 20 + 19 21 static struct dentry *uhci_debugfs_root; 20 22 21 23 #ifdef DEBUG ··· 46 44 char *spid; 47 45 u32 status, token; 48 46 49 - /* Try to make sure there's enough memory */ 50 - if (len < 160) 51 - return 0; 52 - 53 47 status = td_status(uhci, td); 54 48 out += sprintf(out, "%*s[%p] link (%08x) ", space, "", td, 55 49 hc32_to_cpu(uhci, td->link)); ··· 62 64 (status & TD_CTRL_CRCTIMEO) ? "CRC/Timeo " : "", 63 65 (status & TD_CTRL_BITSTUFF) ? "BitStuff " : "", 64 66 status & 0x7ff); 67 + if (out - buf > len) 68 + goto done; 65 69 66 70 token = td_token(uhci, td); 67 71 switch (uhci_packetid(token)) { ··· 90 90 spid); 91 91 out += sprintf(out, "(buf=%08x)\n", hc32_to_cpu(uhci, td->buffer)); 92 92 93 + done: 94 + if (out - buf > len) 95 + out += sprintf(out, " ...\n"); 93 96 return out - buf; 94 97 } 95 98 ··· 104 101 int i, nactive, ninactive; 105 102 char *ptype; 106 103 107 - if (len < 200) 108 - return 0; 109 104 110 105 out += sprintf(out, "urb_priv [%p] ", urbp); 111 106 out += sprintf(out, "urb [%p] ", urbp->urb); ··· 111 110 out += sprintf(out, "Dev=%d ", usb_pipedevice(urbp->urb->pipe)); 112 111 out += sprintf(out, "EP=%x(%s) ", usb_pipeendpoint(urbp->urb->pipe), 113 112 (usb_pipein(urbp->urb->pipe) ? "IN" : "OUT")); 113 + if (out - buf > len) 114 + goto done; 114 115 115 116 switch (usb_pipetype(urbp->urb->pipe)) { 116 117 case PIPE_ISOCHRONOUS: ptype = "ISO"; break; ··· 131 128 out += sprintf(out, " Unlinked=%d", urbp->urb->unlinked); 132 129 out += sprintf(out, "\n"); 133 130 131 + if (out - buf > len) 132 + goto done; 133 + 134 134 i = nactive = ninactive = 0; 135 135 list_for_each_entry(td, &urbp->td_list, list) { 136 136 if (urbp->qh->type != USB_ENDPOINT_XFER_ISOC && ··· 141 135 out += sprintf(out, "%*s%d: ", space + 2, "", i); 142 136 out += uhci_show_td(uhci, td, out, 143 137 len - (out - buf), 0); 138 + if (out - buf > len) 139 + goto tail; 144 140 } else { 145 141 if (td_status(uhci, td) & TD_CTRL_ACTIVE) 146 142 ++nactive; ··· 151 143 } 152 144 } 153 145 if (nactive + ninactive > 0) 154 - out += sprintf(out, "%*s[skipped %d inactive and %d active " 155 - "TDs]\n", 146 + out += sprintf(out, 147 + "%*s[skipped %d inactive and %d active TDs]\n", 156 148 space, "", ninactive, nactive); 157 - 149 + done: 150 + if (out - buf > len) 151 + out += sprintf(out, " ...\n"); 152 + tail: 158 153 return out - buf; 159 154 } 160 155 ··· 168 157 int i, nurbs; 169 158 __hc32 element = qh_element(qh); 170 159 char *qtype; 171 - 172 - /* Try to make sure there's enough memory */ 173 - if (len < 80 * 7) 174 - return 0; 175 160 176 161 switch (qh->type) { 177 162 case USB_ENDPOINT_XFER_ISOC: qtype = "ISO"; break; ··· 182 175 hc32_to_cpu(uhci, qh->link), 183 176 hc32_to_cpu(uhci, element)); 184 177 if (qh->type == USB_ENDPOINT_XFER_ISOC) 185 - out += sprintf(out, "%*s period %d phase %d load %d us, " 186 - "frame %x desc [%p]\n", 178 + out += sprintf(out, 179 + "%*s period %d phase %d load %d us, frame %x desc [%p]\n", 187 180 space, "", qh->period, qh->phase, qh->load, 188 181 qh->iso_frame, qh->iso_packet_desc); 189 182 else if (qh->type == USB_ENDPOINT_XFER_INT) 190 183 out += sprintf(out, "%*s period %d phase %d load %d us\n", 191 184 space, "", qh->period, qh->phase, qh->load); 185 + if (out - buf > len) 186 + goto done; 192 187 193 188 if (element & UHCI_PTR_QH(uhci)) 194 189 out += sprintf(out, "%*s Element points to QH (bug?)\n", space, ""); ··· 204 195 if (!(element & ~(UHCI_PTR_QH(uhci) | UHCI_PTR_DEPTH(uhci)))) 205 196 out += sprintf(out, "%*s Element is NULL (bug?)\n", space, ""); 206 197 198 + if (out - buf > len) 199 + goto done; 200 + 207 201 if (list_empty(&qh->queue)) { 208 202 out += sprintf(out, "%*s queue is empty\n", space, ""); 209 - if (qh == uhci->skel_async_qh) 203 + if (qh == uhci->skel_async_qh) { 210 204 out += uhci_show_td(uhci, uhci->term_td, out, 211 205 len - (out - buf), 0); 206 + if (out - buf > len) 207 + goto tail; 208 + } 212 209 } else { 213 210 struct urb_priv *urbp = list_entry(qh->queue.next, 214 211 struct urb_priv, node); ··· 226 211 space, ""); 227 212 i = nurbs = 0; 228 213 list_for_each_entry(urbp, &qh->queue, node) { 229 - if (++i <= 10) 214 + if (++i <= 10) { 230 215 out += uhci_show_urbp(uhci, urbp, out, 231 216 len - (out - buf), space + 2); 217 + if (out - buf > len) 218 + goto tail; 219 + } 232 220 else 233 221 ++nurbs; 234 222 } ··· 240 222 space, "", nurbs); 241 223 } 242 224 225 + if (out - buf > len) 226 + goto done; 227 + 243 228 if (qh->dummy_td) { 244 229 out += sprintf(out, "%*s Dummy TD\n", space, ""); 245 230 out += uhci_show_td(uhci, qh->dummy_td, out, 246 231 len - (out - buf), 0); 232 + if (out - buf > len) 233 + goto tail; 247 234 } 248 235 236 + done: 237 + if (out - buf > len) 238 + out += sprintf(out, " ...\n"); 239 + tail: 249 240 return out - buf; 250 241 } 251 242 252 - static int uhci_show_sc(int port, unsigned short status, char *buf, int len) 243 + static int uhci_show_sc(int port, unsigned short status, char *buf) 253 244 { 254 - char *out = buf; 255 - 256 - /* Try to make sure there's enough memory */ 257 - if (len < 160) 258 - return 0; 259 - 260 - out += sprintf(out, " stat%d = %04x %s%s%s%s%s%s%s%s%s%s\n", 245 + return sprintf(buf, " stat%d = %04x %s%s%s%s%s%s%s%s%s%s\n", 261 246 port, 262 247 status, 263 248 (status & USBPORTSC_SUSP) ? " Suspend" : "", ··· 273 252 (status & USBPORTSC_PE) ? " Enabled" : "", 274 253 (status & USBPORTSC_CSC) ? " ConnectChange" : "", 275 254 (status & USBPORTSC_CCS) ? " Connected" : ""); 276 - 277 - return out - buf; 278 255 } 279 256 280 - static int uhci_show_root_hub_state(struct uhci_hcd *uhci, char *buf, int len) 257 + static int uhci_show_root_hub_state(struct uhci_hcd *uhci, char *buf) 281 258 { 282 - char *out = buf; 283 259 char *rh_state; 284 - 285 - /* Try to make sure there's enough memory */ 286 - if (len < 60) 287 - return 0; 288 260 289 261 switch (uhci->rh_state) { 290 262 case UHCI_RH_RESET: ··· 297 283 default: 298 284 rh_state = "?"; break; 299 285 } 300 - out += sprintf(out, "Root-hub state: %s FSBR: %d\n", 286 + return sprintf(buf, "Root-hub state: %s FSBR: %d\n", 301 287 rh_state, uhci->fsbr_is_on); 302 - return out - buf; 303 288 } 304 289 305 290 static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len) ··· 309 296 unsigned char sof; 310 297 unsigned short portsc1, portsc2; 311 298 312 - /* Try to make sure there's enough memory */ 313 - if (len < 80 * 9) 314 - return 0; 315 299 316 300 usbcmd = uhci_readw(uhci, 0); 317 301 usbstat = uhci_readw(uhci, 2); ··· 329 319 (usbcmd & USBCMD_GRESET) ? "GRESET " : "", 330 320 (usbcmd & USBCMD_HCRESET) ? "HCRESET " : "", 331 321 (usbcmd & USBCMD_RS) ? "RS " : ""); 322 + if (out - buf > len) 323 + goto done; 332 324 333 325 out += sprintf(out, " usbstat = %04x %s%s%s%s%s%s\n", 334 326 usbstat, ··· 340 328 (usbstat & USBSTS_RD) ? "ResumeDetect " : "", 341 329 (usbstat & USBSTS_ERROR) ? "USBError " : "", 342 330 (usbstat & USBSTS_USBINT) ? "USBINT " : ""); 331 + if (out - buf > len) 332 + goto done; 343 333 344 334 out += sprintf(out, " usbint = %04x\n", usbint); 345 335 out += sprintf(out, " usbfrnum = (%d)%03x\n", (usbfrnum >> 10) & 1, 346 336 0xfff & (4*(unsigned int)usbfrnum)); 347 337 out += sprintf(out, " flbaseadd = %08x\n", flbaseadd); 348 338 out += sprintf(out, " sof = %02x\n", sof); 349 - out += uhci_show_sc(1, portsc1, out, len - (out - buf)); 350 - out += uhci_show_sc(2, portsc2, out, len - (out - buf)); 351 - out += sprintf(out, "Most recent frame: %x (%d) " 352 - "Last ISO frame: %x (%d)\n", 339 + if (out - buf > len) 340 + goto done; 341 + 342 + out += uhci_show_sc(1, portsc1, out); 343 + if (out - buf > len) 344 + goto done; 345 + 346 + out += uhci_show_sc(2, portsc2, out); 347 + if (out - buf > len) 348 + goto done; 349 + 350 + out += sprintf(out, 351 + "Most recent frame: %x (%d) Last ISO frame: %x (%d)\n", 353 352 uhci->frame_number, uhci->frame_number & 1023, 354 353 uhci->last_iso_frame, uhci->last_iso_frame & 1023); 355 354 355 + done: 356 + if (out - buf > len) 357 + out += sprintf(out, " ...\n"); 356 358 return out - buf; 357 359 } 358 360 ··· 386 360 "int8", "int4", "int2", "async", "term" 387 361 }; 388 362 389 - out += uhci_show_root_hub_state(uhci, out, len - (out - buf)); 363 + out += uhci_show_root_hub_state(uhci, out); 364 + if (out - buf > len) 365 + goto done; 390 366 out += sprintf(out, "HC status\n"); 391 367 out += uhci_show_status(uhci, out, len - (out - buf)); 368 + if (out - buf > len) 369 + goto tail; 392 370 393 371 out += sprintf(out, "Periodic load table\n"); 394 372 for (i = 0; i < MAX_PHASE; ++i) { ··· 405 375 uhci_to_hcd(uhci)->self.bandwidth_int_reqs, 406 376 uhci_to_hcd(uhci)->self.bandwidth_isoc_reqs); 407 377 if (debug <= 1) 408 - return out - buf; 378 + goto tail; 409 379 410 380 out += sprintf(out, "Frame List\n"); 411 381 nframes = 10; ··· 413 383 for (i = 0; i < UHCI_NUMFRAMES; ++i) { 414 384 __hc32 qh_dma; 415 385 386 + if (out - buf > len) 387 + goto done; 416 388 j = 0; 417 389 td = uhci->frame_cpu[i]; 418 390 link = uhci->frame[i]; ··· 433 401 td = list_entry(tmp, struct uhci_td, fl_list); 434 402 tmp = tmp->next; 435 403 if (link != LINK_TO_TD(uhci, td)) { 436 - if (nframes > 0) 437 - out += sprintf(out, " link does " 438 - "not match list entry!\n"); 439 - else 404 + if (nframes > 0) { 405 + out += sprintf(out, 406 + " link does not match list entry!\n"); 407 + if (out - buf > len) 408 + goto done; 409 + } else 440 410 ++nerrs; 441 411 } 442 - if (nframes > 0) 412 + if (nframes > 0) { 443 413 out += uhci_show_td(uhci, td, out, 444 414 len - (out - buf), 4); 415 + if (out - buf > len) 416 + goto tail; 417 + } 445 418 link = td->link; 446 419 } while (tmp != head); 447 420 ··· 460 423 i, hc32_to_cpu(uhci, link)); 461 424 j = 1; 462 425 } 463 - out += sprintf(out, " link does not match " 464 - "QH (%08x)!\n", 426 + out += sprintf(out, 427 + " link does not match QH (%08x)!\n", 465 428 hc32_to_cpu(uhci, qh_dma)); 429 + if (out - buf > len) 430 + goto done; 466 431 } else 467 432 ++nerrs; 468 433 } ··· 475 436 476 437 out += sprintf(out, "Skeleton QHs\n"); 477 438 439 + if (out - buf > len) 440 + goto done; 441 + 478 442 fsbr_link = 0; 479 443 for (i = 0; i < UHCI_NUM_SKELQH; ++i) { 480 444 int cnt = 0; 481 445 482 446 qh = uhci->skelqh[i]; 483 - out += sprintf(out, "- skel_%s_qh\n", qh_names[i]); \ 447 + out += sprintf(out, "- skel_%s_qh\n", qh_names[i]); 484 448 out += uhci_show_qh(uhci, qh, out, len - (out - buf), 4); 449 + if (out - buf > len) 450 + goto tail; 485 451 486 452 /* Last QH is the Terminating QH, it's different */ 487 453 if (i == SKEL_TERM) { 488 - if (qh_element(qh) != LINK_TO_TD(uhci, uhci->term_td)) 489 - out += sprintf(out, " skel_term_qh element is not set to term_td!\n"); 454 + if (qh_element(qh) != LINK_TO_TD(uhci, uhci->term_td)) { 455 + out += sprintf(out, 456 + " skel_term_qh element is not set to term_td!\n"); 457 + if (out - buf > len) 458 + goto done; 459 + } 490 460 link = fsbr_link; 491 461 if (!link) 492 462 link = LINK_TO_QH(uhci, uhci->skel_term_qh); ··· 508 460 while (tmp != head) { 509 461 qh = list_entry(tmp, struct uhci_qh, node); 510 462 tmp = tmp->next; 511 - if (++cnt <= 10) 463 + if (++cnt <= 10) { 512 464 out += uhci_show_qh(uhci, qh, out, 513 465 len - (out - buf), 4); 466 + if (out - buf > len) 467 + goto tail; 468 + } 514 469 if (!fsbr_link && qh->skel >= SKEL_FSBR) 515 470 fsbr_link = LINK_TO_QH(uhci, qh); 516 471 } ··· 531 480 link = LINK_TO_QH(uhci, uhci->skel_term_qh); 532 481 check_qh_link: 533 482 if (qh->link != link) 534 - out += sprintf(out, " last QH not linked to next skeleton!\n"); 483 + out += sprintf(out, 484 + " last QH not linked to next skeleton!\n"); 485 + 486 + if (out - buf > len) 487 + goto done; 535 488 } 536 489 490 + done: 491 + if (out - buf > len) 492 + out += sprintf(out, " ...\n"); 493 + tail: 537 494 return out - buf; 538 495 } 539 496 ··· 573 514 up->size = 0; 574 515 spin_lock_irqsave(&uhci->lock, flags); 575 516 if (uhci->is_initialized) 576 - up->size = uhci_sprint_schedule(uhci, up->data, MAX_OUTPUT); 517 + up->size = uhci_sprint_schedule(uhci, up->data, 518 + MAX_OUTPUT - EXTRA_SPACE); 577 519 spin_unlock_irqrestore(&uhci->lock, flags); 578 520 579 521 file->private_data = up; ··· 589 529 590 530 up = file->private_data; 591 531 592 - /* XXX: atomic 64bit seek access, but that needs to be fixed in the VFS */ 532 + /* 533 + * XXX: atomic 64bit seek access, but that needs to be fixed in the VFS 534 + */ 593 535 switch (whence) { 594 536 case 0: 595 537 new = off;
+15 -16
drivers/usb/host/uhci-hcd.c
··· 453 453 454 454 if (status & ~(USBSTS_USBINT | USBSTS_ERROR | USBSTS_RD)) { 455 455 if (status & USBSTS_HSE) 456 - dev_err(uhci_dev(uhci), "host system error, " 457 - "PCI problems?\n"); 456 + dev_err(uhci_dev(uhci), 457 + "host system error, PCI problems?\n"); 458 458 if (status & USBSTS_HCPE) 459 - dev_err(uhci_dev(uhci), "host controller process " 460 - "error, something bad happened!\n"); 459 + dev_err(uhci_dev(uhci), 460 + "host controller process error, something bad happened!\n"); 461 461 if (status & USBSTS_HCH) { 462 462 if (uhci->rh_state >= UHCI_RH_RUNNING) { 463 463 dev_err(uhci_dev(uhci), 464 - "host controller halted, " 465 - "very bad!\n"); 464 + "host controller halted, very bad!\n"); 466 465 if (debug > 1 && errbuf) { 467 466 /* Print the schedule for debugging */ 468 - uhci_sprint_schedule(uhci, 469 - errbuf, ERRBUF_LEN); 467 + uhci_sprint_schedule(uhci, errbuf, 468 + ERRBUF_LEN - EXTRA_SPACE); 470 469 lprintk(errbuf); 471 470 } 472 471 uhci_hc_died(uhci); ··· 591 592 UHCI_NUMFRAMES * sizeof(*uhci->frame), 592 593 &uhci->frame_dma_handle, 0); 593 594 if (!uhci->frame) { 594 - dev_err(uhci_dev(uhci), "unable to allocate " 595 - "consistent memory for frame list\n"); 595 + dev_err(uhci_dev(uhci), 596 + "unable to allocate consistent memory for frame list\n"); 596 597 goto err_alloc_frame; 597 598 } 598 599 memset(uhci->frame, 0, UHCI_NUMFRAMES * sizeof(*uhci->frame)); ··· 600 601 uhci->frame_cpu = kcalloc(UHCI_NUMFRAMES, sizeof(*uhci->frame_cpu), 601 602 GFP_KERNEL); 602 603 if (!uhci->frame_cpu) { 603 - dev_err(uhci_dev(uhci), "unable to allocate " 604 - "memory for frame pointers\n"); 604 + dev_err(uhci_dev(uhci), 605 + "unable to allocate memory for frame pointers\n"); 605 606 goto err_alloc_frame_cpu; 606 607 } 607 608 ··· 736 737 */ 737 738 else if (hcd->self.root_hub->do_remote_wakeup && 738 739 uhci->resuming_ports) { 739 - dev_dbg(uhci_dev(uhci), "suspend failed because a port " 740 - "is resuming\n"); 740 + dev_dbg(uhci_dev(uhci), 741 + "suspend failed because a port is resuming\n"); 741 742 rc = -EBUSY; 742 743 } else 743 744 suspend_rh(uhci, UHCI_RH_SUSPENDED); ··· 828 829 829 830 /* Anything greater than 7 is weird so we'll ignore it. */ 830 831 if (port > UHCI_RH_MAXCHILD) { 831 - dev_info(uhci_dev(uhci), "port count misdetected? " 832 - "forcing to 2 ports\n"); 832 + dev_info(uhci_dev(uhci), 833 + "port count misdetected? forcing to 2 ports\n"); 833 834 port = 2; 834 835 } 835 836
-4
drivers/usb/host/uhci-hcd.h
··· 212 212 #define TD_CTRL_BITSTUFF (1 << 17) /* Bit Stuff Error */ 213 213 #define TD_CTRL_ACTLEN_MASK 0x7FF /* actual length, encoded as n - 1 */ 214 214 215 - #define TD_CTRL_ANY_ERROR (TD_CTRL_STALLED | TD_CTRL_DBUFERR | \ 216 - TD_CTRL_BABBLE | TD_CTRL_CRCTIME | \ 217 - TD_CTRL_BITSTUFF) 218 - 219 215 #define uhci_maxerr(err) ((err) << TD_CTRL_C_ERR_SHIFT) 220 216 #define uhci_status_bits(ctrl_sts) ((ctrl_sts) & 0xF60000) 221 217 #define uhci_actual_length(ctrl_sts) (((ctrl_sts) + 1) & \
+2 -2
drivers/usb/host/uhci-hub.c
··· 21 21 0x00, /* (per-port OC, no power switching) */ 22 22 0x01, /* __u8 bPwrOn2pwrGood; 2ms */ 23 23 0x00, /* __u8 bHubContrCurrent; 0 mA */ 24 - 0x00, /* __u8 DeviceRemovable; *** 7 Ports max *** */ 25 - 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */ 24 + 0x00, /* __u8 DeviceRemovable; *** 7 Ports max */ 25 + 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max */ 26 26 }; 27 27 28 28 #define UHCI_RH_MAXCHILD 7
+1 -1
drivers/usb/host/uhci-q.c
··· 1200 1200 if (debug > 1 && errbuf) { 1201 1201 /* Print the chain for debugging */ 1202 1202 uhci_show_qh(uhci, urbp->qh, errbuf, 1203 - ERRBUF_LEN, 0); 1203 + ERRBUF_LEN - EXTRA_SPACE, 0); 1204 1204 lprintk(errbuf); 1205 1205 } 1206 1206 }
-2
drivers/usb/host/xhci-ring.c
··· 2708 2708 { 2709 2709 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 2710 2710 u32 status; 2711 - union xhci_trb *trb; 2712 2711 u64 temp_64; 2713 2712 union xhci_trb *event_ring_deq; 2714 2713 dma_addr_t deq; 2715 2714 2716 2715 spin_lock(&xhci->lock); 2717 - trb = xhci->event_ring->dequeue; 2718 2716 /* Check if the xHC generated the interrupt, or the irq is shared */ 2719 2717 status = xhci_readl(xhci, &xhci->op_regs->status); 2720 2718 if (status == 0xffffffff)
+6
drivers/usb/misc/Kconfig
··· 250 250 help 251 251 Say Y here if you need EZUSB device support. 252 252 (Cypress FX/FX2/FX2LP microcontrollers) 253 + 254 + config USB_HSIC_USB3503 255 + tristate "USB3503 HSIC to USB20 Driver" 256 + depends on I2C 257 + help 258 + This option enables support for SMSC USB3503 HSIC to USB 2.0 Driver.
+1
drivers/usb/misc/Makefile
··· 26 26 obj-$(CONFIG_USB_USS720) += uss720.o 27 27 obj-$(CONFIG_USB_SEVSEG) += usbsevseg.o 28 28 obj-$(CONFIG_USB_YUREX) += yurex.o 29 + obj-$(CONFIG_USB_HSIC_USB3503) += usb3503.o 29 30 30 31 obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/
+325
drivers/usb/misc/usb3503.c
··· 1 + /* 2 + * Driver for SMSC USB3503 USB 2.0 hub controller driver 3 + * 4 + * Copyright (c) 2012-2013 Dongjin Kim (tobetter@gmail.com) 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * 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 + * You should have received a copy of the GNU General Public License 17 + * along with this program; if not, write to the Free Software 18 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 + */ 20 + 21 + #include <linux/i2c.h> 22 + #include <linux/gpio.h> 23 + #include <linux/delay.h> 24 + #include <linux/slab.h> 25 + #include <linux/module.h> 26 + #include <linux/of_gpio.h> 27 + #include <linux/platform_device.h> 28 + #include <linux/platform_data/usb3503.h> 29 + 30 + #define USB3503_VIDL 0x00 31 + #define USB3503_VIDM 0x01 32 + #define USB3503_PIDL 0x02 33 + #define USB3503_PIDM 0x03 34 + #define USB3503_DIDL 0x04 35 + #define USB3503_DIDM 0x05 36 + 37 + #define USB3503_CFG1 0x06 38 + #define USB3503_SELF_BUS_PWR (1 << 7) 39 + 40 + #define USB3503_CFG2 0x07 41 + #define USB3503_CFG3 0x08 42 + #define USB3503_NRD 0x09 43 + 44 + #define USB3503_PDS 0x0a 45 + #define USB3503_PORT1 (1 << 1) 46 + #define USB3503_PORT2 (1 << 2) 47 + #define USB3503_PORT3 (1 << 3) 48 + 49 + #define USB3503_SP_ILOCK 0xe7 50 + #define USB3503_SPILOCK_CONNECT (1 << 1) 51 + #define USB3503_SPILOCK_CONFIG (1 << 0) 52 + 53 + #define USB3503_CFGP 0xee 54 + #define USB3503_CLKSUSP (1 << 7) 55 + 56 + struct usb3503 { 57 + enum usb3503_mode mode; 58 + struct i2c_client *client; 59 + int gpio_intn; 60 + int gpio_reset; 61 + int gpio_connect; 62 + }; 63 + 64 + static int usb3503_write_register(struct i2c_client *client, 65 + char reg, char data) 66 + { 67 + return i2c_smbus_write_byte_data(client, reg, data); 68 + } 69 + 70 + static int usb3503_read_register(struct i2c_client *client, char reg) 71 + { 72 + return i2c_smbus_read_byte_data(client, reg); 73 + } 74 + 75 + static int usb3503_set_bits(struct i2c_client *client, char reg, char req) 76 + { 77 + int err; 78 + 79 + err = usb3503_read_register(client, reg); 80 + if (err < 0) 81 + return err; 82 + 83 + err = usb3503_write_register(client, reg, err | req); 84 + if (err < 0) 85 + return err; 86 + 87 + return 0; 88 + } 89 + 90 + static int usb3503_clear_bits(struct i2c_client *client, char reg, char req) 91 + { 92 + int err; 93 + 94 + err = usb3503_read_register(client, reg); 95 + if (err < 0) 96 + return err; 97 + 98 + err = usb3503_write_register(client, reg, err & ~req); 99 + if (err < 0) 100 + return err; 101 + 102 + return 0; 103 + } 104 + 105 + static int usb3503_reset(int gpio_reset, int state) 106 + { 107 + if (gpio_is_valid(gpio_reset)) 108 + gpio_set_value(gpio_reset, state); 109 + 110 + /* Wait RefClk when RESET_N is released, otherwise Hub will 111 + * not transition to Hub Communication Stage. 112 + */ 113 + if (state) 114 + msleep(100); 115 + 116 + return 0; 117 + } 118 + 119 + static int usb3503_switch_mode(struct usb3503 *hub, enum usb3503_mode mode) 120 + { 121 + struct i2c_client *i2c = hub->client; 122 + int err = 0; 123 + 124 + switch (mode) { 125 + case USB3503_MODE_HUB: 126 + usb3503_reset(hub->gpio_reset, 1); 127 + 128 + /* SP_ILOCK: set connect_n, config_n for config */ 129 + err = usb3503_write_register(i2c, USB3503_SP_ILOCK, 130 + (USB3503_SPILOCK_CONNECT 131 + | USB3503_SPILOCK_CONFIG)); 132 + if (err < 0) { 133 + dev_err(&i2c->dev, "SP_ILOCK failed (%d)\n", err); 134 + goto err_hubmode; 135 + } 136 + 137 + /* PDS : Port2,3 Disable For Self Powered Operation */ 138 + err = usb3503_set_bits(i2c, USB3503_PDS, 139 + (USB3503_PORT2 | USB3503_PORT3)); 140 + if (err < 0) { 141 + dev_err(&i2c->dev, "PDS failed (%d)\n", err); 142 + goto err_hubmode; 143 + } 144 + 145 + /* CFG1 : SELF_BUS_PWR -> Self-Powerd operation */ 146 + err = usb3503_set_bits(i2c, USB3503_CFG1, USB3503_SELF_BUS_PWR); 147 + if (err < 0) { 148 + dev_err(&i2c->dev, "CFG1 failed (%d)\n", err); 149 + goto err_hubmode; 150 + } 151 + 152 + /* SP_LOCK: clear connect_n, config_n for hub connect */ 153 + err = usb3503_clear_bits(i2c, USB3503_SP_ILOCK, 154 + (USB3503_SPILOCK_CONNECT 155 + | USB3503_SPILOCK_CONFIG)); 156 + if (err < 0) { 157 + dev_err(&i2c->dev, "SP_ILOCK failed (%d)\n", err); 158 + goto err_hubmode; 159 + } 160 + 161 + hub->mode = mode; 162 + dev_info(&i2c->dev, "switched to HUB mode\n"); 163 + break; 164 + 165 + case USB3503_MODE_STANDBY: 166 + usb3503_reset(hub->gpio_reset, 0); 167 + 168 + hub->mode = mode; 169 + dev_info(&i2c->dev, "switched to STANDBY mode\n"); 170 + break; 171 + 172 + default: 173 + dev_err(&i2c->dev, "unknown mode is request\n"); 174 + err = -EINVAL; 175 + break; 176 + } 177 + 178 + err_hubmode: 179 + return err; 180 + } 181 + 182 + static int usb3503_probe(struct i2c_client *i2c, const struct i2c_device_id *id) 183 + { 184 + struct usb3503_platform_data *pdata = i2c->dev.platform_data; 185 + struct device_node *np = i2c->dev.of_node; 186 + struct usb3503 *hub; 187 + int err = -ENOMEM; 188 + u32 mode = USB3503_MODE_UNKNOWN; 189 + 190 + hub = kzalloc(sizeof(struct usb3503), GFP_KERNEL); 191 + if (!hub) { 192 + dev_err(&i2c->dev, "private data alloc fail\n"); 193 + return err; 194 + } 195 + 196 + i2c_set_clientdata(i2c, hub); 197 + hub->client = i2c; 198 + 199 + if (pdata) { 200 + hub->gpio_intn = pdata->gpio_intn; 201 + hub->gpio_connect = pdata->gpio_connect; 202 + hub->gpio_reset = pdata->gpio_reset; 203 + hub->mode = pdata->initial_mode; 204 + } else if (np) { 205 + hub->gpio_intn = of_get_named_gpio(np, "connect-gpios", 0); 206 + if (hub->gpio_intn == -EPROBE_DEFER) 207 + return -EPROBE_DEFER; 208 + hub->gpio_connect = of_get_named_gpio(np, "intn-gpios", 0); 209 + if (hub->gpio_connect == -EPROBE_DEFER) 210 + return -EPROBE_DEFER; 211 + hub->gpio_reset = of_get_named_gpio(np, "reset-gpios", 0); 212 + if (hub->gpio_reset == -EPROBE_DEFER) 213 + return -EPROBE_DEFER; 214 + of_property_read_u32(np, "initial-mode", &mode); 215 + hub->mode = mode; 216 + } 217 + 218 + if (gpio_is_valid(hub->gpio_intn)) { 219 + err = gpio_request_one(hub->gpio_intn, 220 + GPIOF_OUT_INIT_HIGH, "usb3503 intn"); 221 + if (err) { 222 + dev_err(&i2c->dev, 223 + "unable to request GPIO %d as connect pin (%d)\n", 224 + hub->gpio_intn, err); 225 + goto err_out; 226 + } 227 + } 228 + 229 + if (gpio_is_valid(hub->gpio_connect)) { 230 + err = gpio_request_one(hub->gpio_connect, 231 + GPIOF_OUT_INIT_HIGH, "usb3503 connect"); 232 + if (err) { 233 + dev_err(&i2c->dev, 234 + "unable to request GPIO %d as connect pin (%d)\n", 235 + hub->gpio_connect, err); 236 + goto err_gpio_connect; 237 + } 238 + } 239 + 240 + if (gpio_is_valid(hub->gpio_reset)) { 241 + err = gpio_request_one(hub->gpio_reset, 242 + GPIOF_OUT_INIT_LOW, "usb3503 reset"); 243 + if (err) { 244 + dev_err(&i2c->dev, 245 + "unable to request GPIO %d as reset pin (%d)\n", 246 + hub->gpio_reset, err); 247 + goto err_gpio_reset; 248 + } 249 + } 250 + 251 + usb3503_switch_mode(hub, hub->mode); 252 + 253 + dev_info(&i2c->dev, "%s: probed on %s mode\n", __func__, 254 + (hub->mode == USB3503_MODE_HUB) ? "hub" : "standby"); 255 + 256 + return 0; 257 + 258 + err_gpio_reset: 259 + if (gpio_is_valid(hub->gpio_connect)) 260 + gpio_free(hub->gpio_connect); 261 + err_gpio_connect: 262 + if (gpio_is_valid(hub->gpio_intn)) 263 + gpio_free(hub->gpio_intn); 264 + err_out: 265 + kfree(hub); 266 + 267 + return err; 268 + } 269 + 270 + static int usb3503_remove(struct i2c_client *i2c) 271 + { 272 + struct usb3503 *hub = i2c_get_clientdata(i2c); 273 + 274 + if (gpio_is_valid(hub->gpio_intn)) 275 + gpio_free(hub->gpio_intn); 276 + if (gpio_is_valid(hub->gpio_connect)) 277 + gpio_free(hub->gpio_connect); 278 + if (gpio_is_valid(hub->gpio_reset)) 279 + gpio_free(hub->gpio_reset); 280 + 281 + kfree(hub); 282 + 283 + return 0; 284 + } 285 + 286 + static const struct i2c_device_id usb3503_id[] = { 287 + { USB3503_I2C_NAME, 0 }, 288 + { } 289 + }; 290 + MODULE_DEVICE_TABLE(i2c, usb3503_id); 291 + 292 + #ifdef CONFIG_OF 293 + static const struct of_device_id usb3503_of_match[] = { 294 + { .compatible = "smsc,usb3503", }, 295 + {}, 296 + }; 297 + MODULE_DEVICE_TABLE(of, usb3503_of_match); 298 + #endif 299 + 300 + static struct i2c_driver usb3503_driver = { 301 + .driver = { 302 + .name = USB3503_I2C_NAME, 303 + .of_match_table = of_match_ptr(usb3503_of_match), 304 + }, 305 + .probe = usb3503_probe, 306 + .remove = usb3503_remove, 307 + .id_table = usb3503_id, 308 + }; 309 + 310 + static int __init usb3503_init(void) 311 + { 312 + return i2c_add_driver(&usb3503_driver); 313 + } 314 + 315 + static void __exit usb3503_exit(void) 316 + { 317 + i2c_del_driver(&usb3503_driver); 318 + } 319 + 320 + module_init(usb3503_init); 321 + module_exit(usb3503_exit); 322 + 323 + MODULE_AUTHOR("Dongjin Kim <tobetter@gmail.com>"); 324 + MODULE_DESCRIPTION("USB3503 USB HUB driver"); 325 + MODULE_LICENSE("GPL");
+12 -1
drivers/usb/misc/usbtest.c
··· 13 13 14 14 /*-------------------------------------------------------------------------*/ 15 15 16 + static int override_alt = -1; 17 + module_param_named(alt, override_alt, int, 0644); 18 + MODULE_PARM_DESC(alt, ">= 0 to override altsetting selection"); 19 + 20 + /*-------------------------------------------------------------------------*/ 21 + 16 22 /* FIXME make these public somewhere; usbdevfs.h? */ 17 23 struct usbtest_param { 18 24 /* inputs */ ··· 109 103 iso_in = iso_out = NULL; 110 104 alt = intf->altsetting + tmp; 111 105 106 + if (override_alt >= 0 && 107 + override_alt != alt->desc.bAlternateSetting) 108 + continue; 109 + 112 110 /* take the first altsetting with in-bulk + out-bulk; 113 111 * ignore other endpoints and altsettings. 114 112 */ ··· 154 144 155 145 found: 156 146 udev = testdev_to_usbdev(dev); 147 + dev->info->alt = alt->desc.bAlternateSetting; 157 148 if (alt->desc.bAlternateSetting != 0) { 158 149 tmp = usb_set_interface(udev, 159 150 alt->desc.bInterfaceNumber, ··· 2291 2280 wtest = " intr-out"; 2292 2281 } 2293 2282 } else { 2294 - if (info->autoconf) { 2283 + if (override_alt >= 0 || info->autoconf) { 2295 2284 int status; 2296 2285 2297 2286 status = get_endpoints(dev, intf);
+2
drivers/usb/musb/Kconfig
··· 11 11 select NOP_USB_XCEIV if (SOC_TI81XX || SOC_AM33XX) 12 12 select TWL4030_USB if MACH_OMAP_3430SDP 13 13 select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA 14 + select OMAP_CONTROL_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA 14 15 select USB_OTG_UTILS 15 16 help 16 17 Say Y here if your system has a dual role high speed USB ··· 46 45 47 46 config USB_MUSB_TUSB6010 48 47 tristate "TUSB6010" 48 + depends on GENERIC_HARDIRQS 49 49 50 50 config USB_MUSB_OMAP2PLUS 51 51 tristate "OMAP2430 and onwards"
+1 -1
drivers/usb/musb/am35x.c
··· 365 365 usb_nop_xceiv_register(); 366 366 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 367 367 if (IS_ERR_OR_NULL(musb->xceiv)) 368 - return -ENODEV; 368 + return -EPROBE_DEFER; 369 369 370 370 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb); 371 371
+1 -1
drivers/usb/musb/blackfin.c
··· 406 406 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 407 407 if (IS_ERR_OR_NULL(musb->xceiv)) { 408 408 gpio_free(musb->config->gpio_vrsel); 409 - return -ENODEV; 409 + return -EPROBE_DEFER; 410 410 } 411 411 412 412 bfin_musb_reg_init(musb);
+5 -2
drivers/usb/musb/da8xx.c
··· 410 410 { 411 411 void __iomem *reg_base = musb->ctrl_base; 412 412 u32 rev; 413 + int ret = -ENODEV; 413 414 414 415 musb->mregs += DA8XX_MENTOR_CORE_OFFSET; 415 416 ··· 421 420 422 421 usb_nop_xceiv_register(); 423 422 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 424 - if (IS_ERR_OR_NULL(musb->xceiv)) 423 + if (IS_ERR_OR_NULL(musb->xceiv)) { 424 + ret = -EPROBE_DEFER; 425 425 goto fail; 426 + } 426 427 427 428 setup_timer(&otg_workaround, otg_timer, (unsigned long)musb); 428 429 ··· 444 441 musb->isr = da8xx_musb_interrupt; 445 442 return 0; 446 443 fail: 447 - return -ENODEV; 444 + return ret; 448 445 } 449 446 450 447 static int da8xx_musb_exit(struct musb *musb)
+5 -2
drivers/usb/musb/davinci.c
··· 380 380 { 381 381 void __iomem *tibase = musb->ctrl_base; 382 382 u32 revision; 383 + int ret = -ENODEV; 383 384 384 385 usb_nop_xceiv_register(); 385 386 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 386 - if (IS_ERR_OR_NULL(musb->xceiv)) 387 + if (IS_ERR_OR_NULL(musb->xceiv)) { 388 + ret = -EPROBE_DEFER; 387 389 goto unregister; 390 + } 388 391 389 392 musb->mregs += DAVINCI_BASE_OFFSET; 390 393 ··· 441 438 usb_put_phy(musb->xceiv); 442 439 unregister: 443 440 usb_nop_xceiv_unregister(); 444 - return -ENODEV; 441 + return ret; 445 442 } 446 443 447 444 static int davinci_musb_exit(struct musb *musb)
+1
drivers/usb/musb/musb_core.c
··· 1993 1993 musb_platform_exit(musb); 1994 1994 1995 1995 fail1: 1996 + pm_runtime_disable(musb->controller); 1996 1997 dev_err(musb->controller, 1997 1998 "musb_init_controller failed with status %d\n", status); 1998 1999
+1 -2
drivers/usb/musb/musb_dsps.c
··· 31 31 32 32 #include <linux/init.h> 33 33 #include <linux/io.h> 34 - #include <linux/of.h> 35 34 #include <linux/err.h> 36 35 #include <linux/platform_device.h> 37 36 #include <linux/dma-mapping.h> ··· 418 419 usb_nop_xceiv_register(); 419 420 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 420 421 if (IS_ERR_OR_NULL(musb->xceiv)) 421 - return -ENODEV; 422 + return -EPROBE_DEFER; 422 423 423 424 /* Returns zero if e.g. not clocked */ 424 425 rev = dsps_readl(reg_base, wrp->revision);
+19 -3
drivers/usb/musb/musb_gadget.c
··· 408 408 csr |= (MUSB_TXCSR_DMAENAB 409 409 | MUSB_TXCSR_DMAMODE 410 410 | MUSB_TXCSR_MODE); 411 - if (!musb_ep->hb_mult) 411 + /* 412 + * Enable Autoset according to table 413 + * below 414 + * bulk_split hb_mult Autoset_Enable 415 + * 0 0 Yes(Normal) 416 + * 0 >0 No(High BW ISO) 417 + * 1 0 Yes(HS bulk) 418 + * 1 >0 Yes(FS bulk) 419 + */ 420 + if (!musb_ep->hb_mult || 421 + (musb_ep->hb_mult && 422 + can_bulk_split(musb, 423 + musb_ep->type))) 412 424 csr |= MUSB_TXCSR_AUTOSET; 413 425 } 414 426 csr &= ~MUSB_TXCSR_P_UNDERRUN; ··· 1122 1110 /* Set TXMAXP with the FIFO size of the endpoint 1123 1111 * to disable double buffering mode. 1124 1112 */ 1125 - if (musb->double_buffer_not_ok) 1113 + if (musb->double_buffer_not_ok) { 1126 1114 musb_writew(regs, MUSB_TXMAXP, hw_ep->max_packet_sz_tx); 1127 - else 1115 + } else { 1116 + if (can_bulk_split(musb, musb_ep->type)) 1117 + musb_ep->hb_mult = (hw_ep->max_packet_sz_tx / 1118 + musb_ep->packet_sz) - 1; 1128 1119 musb_writew(regs, MUSB_TXMAXP, musb_ep->packet_sz 1129 1120 | (musb_ep->hb_mult << 11)); 1121 + } 1130 1122 1131 1123 csr = MUSB_TXCSR_MODE | MUSB_TXCSR_CLRDATATOG; 1132 1124 if (musb_readw(regs, MUSB_TXCSR)
+32 -12
drivers/usb/musb/musb_host.c
··· 634 634 mode = 1; 635 635 csr |= MUSB_TXCSR_DMAMODE | MUSB_TXCSR_DMAENAB; 636 636 /* autoset shouldn't be set in high bandwidth */ 637 - if (qh->hb_mult == 1) 637 + /* 638 + * Enable Autoset according to table 639 + * below 640 + * bulk_split hb_mult Autoset_Enable 641 + * 0 1 Yes(Normal) 642 + * 0 >1 No(High BW ISO) 643 + * 1 1 Yes(HS bulk) 644 + * 1 >1 Yes(FS bulk) 645 + */ 646 + if (qh->hb_mult == 1 || (qh->hb_mult > 1 && 647 + can_bulk_split(hw_ep->musb, qh->type))) 638 648 csr |= MUSB_TXCSR_AUTOSET; 639 649 } else { 640 650 mode = 0; ··· 756 746 /* general endpoint setup */ 757 747 if (epnum) { 758 748 /* flush all old state, set default */ 759 - musb_h_tx_flush_fifo(hw_ep); 749 + /* 750 + * We could be flushing valid 751 + * packets in double buffering 752 + * case 753 + */ 754 + if (!hw_ep->tx_double_buffered) 755 + musb_h_tx_flush_fifo(hw_ep); 760 756 761 757 /* 762 758 * We must not clear the DMAMODE bit before or in ··· 779 763 ); 780 764 csr |= MUSB_TXCSR_MODE; 781 765 782 - if (usb_gettoggle(urb->dev, qh->epnum, 1)) 783 - csr |= MUSB_TXCSR_H_WR_DATATOGGLE 784 - | MUSB_TXCSR_H_DATATOGGLE; 785 - else 786 - csr |= MUSB_TXCSR_CLRDATATOG; 766 + if (!hw_ep->tx_double_buffered) { 767 + if (usb_gettoggle(urb->dev, qh->epnum, 1)) 768 + csr |= MUSB_TXCSR_H_WR_DATATOGGLE 769 + | MUSB_TXCSR_H_DATATOGGLE; 770 + else 771 + csr |= MUSB_TXCSR_CLRDATATOG; 772 + } 787 773 788 774 musb_writew(epio, MUSB_TXCSR, csr); 789 775 /* REVISIT may need to clear FLUSHFIFO ... */ ··· 809 791 /* protocol/endpoint/interval/NAKlimit */ 810 792 if (epnum) { 811 793 musb_writeb(epio, MUSB_TXTYPE, qh->type_reg); 812 - if (musb->double_buffer_not_ok) 794 + if (musb->double_buffer_not_ok) { 813 795 musb_writew(epio, MUSB_TXMAXP, 814 796 hw_ep->max_packet_sz_tx); 815 - else if (can_bulk_split(musb, qh->type)) 797 + } else if (can_bulk_split(musb, qh->type)) { 798 + qh->hb_mult = hw_ep->max_packet_sz_tx 799 + / packet_sz; 816 800 musb_writew(epio, MUSB_TXMAXP, packet_sz 817 - | ((hw_ep->max_packet_sz_tx / 818 - packet_sz) - 1) << 11); 819 - else 801 + | ((qh->hb_mult) - 1) << 11); 802 + } else { 820 803 musb_writew(epio, MUSB_TXMAXP, 821 804 qh->maxpacket | 822 805 ((qh->hb_mult - 1) << 11)); 806 + } 823 807 musb_writeb(epio, MUSB_TXINTERVAL, qh->intv_reg); 824 808 } else { 825 809 musb_writeb(epio, MUSB_NAKLIMIT0, qh->intv_reg);
+36 -53
drivers/usb/musb/omap2430.c
··· 37 37 #include <linux/err.h> 38 38 #include <linux/delay.h> 39 39 #include <linux/usb/musb-omap.h> 40 + #include <linux/usb/omap_control_usb.h> 40 41 41 42 #include "musb_core.h" 42 43 #include "omap2430.h" ··· 47 46 struct platform_device *musb; 48 47 enum omap_musb_vbus_id_status status; 49 48 struct work_struct omap_musb_mailbox_work; 50 - u32 __iomem *control_otghs; 49 + struct device *control_otghs; 51 50 }; 52 51 #define glue_to_musb(g) platform_get_drvdata(g->musb) 53 52 54 53 struct omap2430_glue *_glue; 55 54 56 55 static struct timer_list musb_idle_timer; 57 - 58 - /** 59 - * omap4_usb_phy_mailbox - write to usb otg mailbox 60 - * @glue: struct omap2430_glue * 61 - * @val: the value to be written to the mailbox 62 - * 63 - * On detection of a device (ID pin is grounded), this API should be called 64 - * to set AVALID, VBUSVALID and ID pin is grounded. 65 - * 66 - * When OMAP is connected to a host (OMAP in device mode), this API 67 - * is called to set AVALID, VBUSVALID and ID pin in high impedance. 68 - * 69 - * XXX: This function will be removed once we have a seperate driver for 70 - * control module 71 - */ 72 - static void omap4_usb_phy_mailbox(struct omap2430_glue *glue, u32 val) 73 - { 74 - if (glue->control_otghs) 75 - writel(val, glue->control_otghs); 76 - } 77 56 78 57 static void musb_do_idle(unsigned long _musb) 79 58 { ··· 236 255 void omap_musb_mailbox(enum omap_musb_vbus_id_status status) 237 256 { 238 257 struct omap2430_glue *glue = _glue; 239 - struct musb *musb = glue_to_musb(glue); 240 258 241 - glue->status = status; 242 - if (!musb) { 243 - dev_err(glue->dev, "musb core is not yet ready\n"); 259 + if (glue && glue_to_musb(glue)) { 260 + glue->status = status; 261 + } else { 262 + pr_err("%s: musb core is not yet ready\n", __func__); 244 263 return; 245 264 } 246 265 ··· 250 269 251 270 static void omap_musb_set_mailbox(struct omap2430_glue *glue) 252 271 { 253 - u32 val; 254 272 struct musb *musb = glue_to_musb(glue); 255 273 struct device *dev = musb->controller; 256 274 struct musb_hdrc_platform_data *pdata = dev->platform_data; ··· 265 285 musb->xceiv->last_event = USB_EVENT_ID; 266 286 if (musb->gadget_driver) { 267 287 pm_runtime_get_sync(dev); 268 - val = AVALID | VBUSVALID; 269 - omap4_usb_phy_mailbox(glue, val); 288 + omap_control_usb_set_mode(glue->control_otghs, 289 + USB_MODE_HOST); 270 290 omap2430_musb_set_vbus(musb, 1); 271 291 } 272 292 break; ··· 279 299 musb->xceiv->last_event = USB_EVENT_VBUS; 280 300 if (musb->gadget_driver) 281 301 pm_runtime_get_sync(dev); 282 - val = IDDIG | AVALID | VBUSVALID; 283 - omap4_usb_phy_mailbox(glue, val); 302 + omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE); 284 303 break; 285 304 286 305 case OMAP_MUSB_ID_FLOAT: ··· 296 317 if (musb->xceiv->otg->set_vbus) 297 318 otg_set_vbus(musb->xceiv->otg, 0); 298 319 } 299 - val = SESSEND | IDDIG; 300 - omap4_usb_phy_mailbox(glue, val); 320 + omap_control_usb_set_mode(glue->control_otghs, 321 + USB_MODE_DISCONNECT); 301 322 break; 302 323 default: 303 324 dev_dbg(dev, "ID float\n"); ··· 345 366 * up through ULPI. TWL4030-family PMICs include one, 346 367 * which needs a driver, drivers aren't always needed. 347 368 */ 348 - musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 369 + if (dev->parent->of_node) 370 + musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent, 371 + "usb-phy", 0); 372 + else 373 + musb->xceiv = devm_usb_get_phy_dev(dev, 0); 374 + 349 375 if (IS_ERR_OR_NULL(musb->xceiv)) { 350 376 pr_err("HS USB OTG: no transceiver configured\n"); 351 - return -ENODEV; 377 + return -EPROBE_DEFER; 352 378 } 353 379 354 380 musb->isr = omap2430_musb_interrupt; ··· 399 415 static void omap2430_musb_enable(struct musb *musb) 400 416 { 401 417 u8 devctl; 402 - u32 val; 403 418 unsigned long timeout = jiffies + msecs_to_jiffies(1000); 404 419 struct device *dev = musb->controller; 405 420 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); ··· 408 425 switch (glue->status) { 409 426 410 427 case OMAP_MUSB_ID_GROUND: 411 - val = AVALID | VBUSVALID; 412 - omap4_usb_phy_mailbox(glue, val); 428 + omap_control_usb_set_mode(glue->control_otghs, USB_MODE_HOST); 413 429 if (data->interface_type != MUSB_INTERFACE_UTMI) 414 430 break; 415 431 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); ··· 427 445 break; 428 446 429 447 case OMAP_MUSB_VBUS_VALID: 430 - val = IDDIG | AVALID | VBUSVALID; 431 - omap4_usb_phy_mailbox(glue, val); 448 + omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE); 432 449 break; 433 450 434 451 default: ··· 437 456 438 457 static void omap2430_musb_disable(struct musb *musb) 439 458 { 440 - u32 val; 441 459 struct device *dev = musb->controller; 442 460 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 443 461 444 - if (glue->status != OMAP_MUSB_UNKNOWN) { 445 - val = SESSEND | IDDIG; 446 - omap4_usb_phy_mailbox(glue, val); 447 - } 462 + if (glue->status != OMAP_MUSB_UNKNOWN) 463 + omap_control_usb_set_mode(glue->control_otghs, 464 + USB_MODE_DISCONNECT); 448 465 } 449 466 450 467 static int omap2430_musb_exit(struct musb *musb) ··· 477 498 struct omap2430_glue *glue; 478 499 struct device_node *np = pdev->dev.of_node; 479 500 struct musb_hdrc_config *config; 480 - struct resource *res; 481 501 int ret = -ENOMEM; 482 502 483 503 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); ··· 499 521 glue->musb = musb; 500 522 glue->status = OMAP_MUSB_UNKNOWN; 501 523 502 - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 503 - 504 - glue->control_otghs = devm_ioremap_resource(&pdev->dev, res); 505 - 506 524 if (np) { 507 525 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 508 526 if (!pdata) { 509 527 dev_err(&pdev->dev, 510 528 "failed to allocate musb platfrom data\n"); 511 - ret = -ENOMEM; 512 529 goto err2; 513 530 } 514 531 515 532 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 516 533 if (!data) { 517 534 dev_err(&pdev->dev, 518 - "failed to allocate musb board data\n"); 519 - ret = -ENOMEM; 535 + "failed to allocate musb board data\n"); 520 536 goto err2; 521 537 } 522 538 523 539 config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL); 524 - if (!data) { 540 + if (!config) { 525 541 dev_err(&pdev->dev, 526 542 "failed to allocate musb hdrc config\n"); 527 543 goto err2; ··· 528 556 of_property_read_u32(np, "ram_bits", (u32 *)&config->ram_bits); 529 557 of_property_read_u32(np, "power", (u32 *)&pdata->power); 530 558 config->multipoint = of_property_read_bool(np, "multipoint"); 559 + pdata->has_mailbox = of_property_read_bool(np, 560 + "ti,has-mailbox"); 531 561 532 562 pdata->board_data = data; 533 563 pdata->config = config; 534 564 } 535 565 566 + if (pdata->has_mailbox) { 567 + glue->control_otghs = omap_get_control_dev(); 568 + if (IS_ERR(glue->control_otghs)) { 569 + dev_vdbg(&pdev->dev, "Failed to get control device\n"); 570 + return -ENODEV; 571 + } 572 + } else { 573 + glue->control_otghs = ERR_PTR(-ENODEV); 574 + } 536 575 pdata->platform_ops = &omap2430_ops; 537 576 538 577 platform_set_drvdata(pdev, glue);
-9
drivers/usb/musb/omap2430.h
··· 49 49 #define OTG_FORCESTDBY 0x414 50 50 # define ENABLEFORCE (1 << 0) 51 51 52 - /* 53 - * Control Module bit definitions 54 - * XXX: Will be removed once we have a driver for control module. 55 - */ 56 - #define AVALID BIT(0) 57 - #define BVALID BIT(1) 58 - #define VBUSVALID BIT(2) 59 - #define SESSEND BIT(3) 60 - #define IDDIG BIT(4) 61 52 #endif /* __MUSB_OMAP243X_H__ */
+1 -1
drivers/usb/musb/tusb6010.c
··· 1069 1069 usb_nop_xceiv_register(); 1070 1070 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 1071 1071 if (IS_ERR_OR_NULL(musb->xceiv)) 1072 - return -ENODEV; 1072 + return -EPROBE_DEFER; 1073 1073 1074 1074 pdev = to_platform_device(musb->controller); 1075 1075
+6 -6
drivers/usb/musb/ux500.c
··· 61 61 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 62 62 if (IS_ERR_OR_NULL(musb->xceiv)) { 63 63 pr_err("HS USB OTG: no transceiver configured\n"); 64 - return -ENODEV; 64 + return -EPROBE_DEFER; 65 65 } 66 66 67 67 musb->isr = ux500_musb_interrupt; ··· 108 108 goto err3; 109 109 } 110 110 111 - ret = clk_enable(clk); 111 + ret = clk_prepare_enable(clk); 112 112 if (ret) { 113 113 dev_err(&pdev->dev, "failed to enable clock\n"); 114 114 goto err4; ··· 148 148 return 0; 149 149 150 150 err5: 151 - clk_disable(clk); 151 + clk_disable_unprepare(clk); 152 152 153 153 err4: 154 154 clk_put(clk); ··· 168 168 struct ux500_glue *glue = platform_get_drvdata(pdev); 169 169 170 170 platform_device_unregister(glue->musb); 171 - clk_disable(glue->clk); 171 + clk_disable_unprepare(glue->clk); 172 172 clk_put(glue->clk); 173 173 kfree(glue); 174 174 ··· 182 182 struct musb *musb = glue_to_musb(glue); 183 183 184 184 usb_phy_set_suspend(musb->xceiv, 1); 185 - clk_disable(glue->clk); 185 + clk_disable_unprepare(glue->clk); 186 186 187 187 return 0; 188 188 } ··· 193 193 struct musb *musb = glue_to_musb(glue); 194 194 int ret; 195 195 196 - ret = clk_enable(glue->clk); 196 + ret = clk_prepare_enable(glue->clk); 197 197 if (ret) { 198 198 dev_err(dev, "failed to enable clock\n"); 199 199 return ret;
+23 -61
drivers/usb/otg/mv_otg.c
··· 420 420 struct usb_otg *otg; 421 421 int old_state; 422 422 423 - mvotg = container_of((struct delayed_work *)work, struct mv_otg, work); 423 + mvotg = container_of(to_delayed_work(work), struct mv_otg, work); 424 424 425 425 run: 426 426 /* work queue is single thread, or we need spin_lock to protect */ ··· 662 662 int mv_otg_remove(struct platform_device *pdev) 663 663 { 664 664 struct mv_otg *mvotg = platform_get_drvdata(pdev); 665 - int clk_i; 666 665 667 666 sysfs_remove_group(&mvotg->pdev->dev.kobj, &inputs_attr_group); 668 - 669 - if (mvotg->irq) 670 - free_irq(mvotg->irq, mvotg); 671 - 672 - if (mvotg->pdata->vbus) 673 - free_irq(mvotg->pdata->vbus->irq, mvotg); 674 - if (mvotg->pdata->id) 675 - free_irq(mvotg->pdata->id->irq, mvotg); 676 667 677 668 if (mvotg->qwork) { 678 669 flush_workqueue(mvotg->qwork); ··· 672 681 673 682 mv_otg_disable(mvotg); 674 683 675 - if (mvotg->cap_regs) 676 - iounmap(mvotg->cap_regs); 677 - 678 - if (mvotg->phy_regs) 679 - iounmap(mvotg->phy_regs); 680 - 681 - for (clk_i = 0; clk_i <= mvotg->clknum; clk_i++) 682 - clk_put(mvotg->clk[clk_i]); 683 - 684 684 usb_remove_phy(&mvotg->phy); 685 685 platform_set_drvdata(pdev, NULL); 686 - 687 - kfree(mvotg->phy.otg); 688 - kfree(mvotg); 689 686 690 687 return 0; 691 688 } ··· 693 714 } 694 715 695 716 size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum; 696 - mvotg = kzalloc(size, GFP_KERNEL); 717 + mvotg = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); 697 718 if (!mvotg) { 698 719 dev_err(&pdev->dev, "failed to allocate memory!\n"); 699 720 return -ENOMEM; 700 721 } 701 722 702 - otg = kzalloc(sizeof *otg, GFP_KERNEL); 703 - if (!otg) { 704 - kfree(mvotg); 723 + otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); 724 + if (!otg) 705 725 return -ENOMEM; 706 - } 707 726 708 727 platform_set_drvdata(pdev, mvotg); 709 728 ··· 710 733 711 734 mvotg->clknum = pdata->clknum; 712 735 for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) { 713 - mvotg->clk[clk_i] = clk_get(&pdev->dev, pdata->clkname[clk_i]); 736 + mvotg->clk[clk_i] = devm_clk_get(&pdev->dev, 737 + pdata->clkname[clk_i]); 714 738 if (IS_ERR(mvotg->clk[clk_i])) { 715 739 retval = PTR_ERR(mvotg->clk[clk_i]); 716 - goto err_put_clk; 740 + return retval; 717 741 } 718 742 } 719 743 720 744 mvotg->qwork = create_singlethread_workqueue("mv_otg_queue"); 721 745 if (!mvotg->qwork) { 722 746 dev_dbg(&pdev->dev, "cannot create workqueue for OTG\n"); 723 - retval = -ENOMEM; 724 - goto err_put_clk; 747 + return -ENOMEM; 725 748 } 726 749 727 750 INIT_DELAYED_WORK(&mvotg->work, mv_otg_work); ··· 749 772 goto err_destroy_workqueue; 750 773 } 751 774 752 - mvotg->phy_regs = ioremap(r->start, resource_size(r)); 775 + mvotg->phy_regs = devm_ioremap(&pdev->dev, r->start, resource_size(r)); 753 776 if (mvotg->phy_regs == NULL) { 754 777 dev_err(&pdev->dev, "failed to map phy I/O memory\n"); 755 778 retval = -EFAULT; ··· 761 784 if (r == NULL) { 762 785 dev_err(&pdev->dev, "no I/O memory resource defined\n"); 763 786 retval = -ENODEV; 764 - goto err_unmap_phyreg; 787 + goto err_destroy_workqueue; 765 788 } 766 789 767 - mvotg->cap_regs = ioremap(r->start, resource_size(r)); 790 + mvotg->cap_regs = devm_ioremap(&pdev->dev, r->start, resource_size(r)); 768 791 if (mvotg->cap_regs == NULL) { 769 792 dev_err(&pdev->dev, "failed to map I/O memory\n"); 770 793 retval = -EFAULT; 771 - goto err_unmap_phyreg; 794 + goto err_destroy_workqueue; 772 795 } 773 796 774 797 /* we will acces controller register, so enable the udc controller */ 775 798 retval = mv_otg_enable_internal(mvotg); 776 799 if (retval) { 777 800 dev_err(&pdev->dev, "mv otg enable error %d\n", retval); 778 - goto err_unmap_capreg; 801 + goto err_destroy_workqueue; 779 802 } 780 803 781 804 mvotg->op_regs = ··· 783 806 + (readl(mvotg->cap_regs) & CAPLENGTH_MASK)); 784 807 785 808 if (pdata->id) { 786 - retval = request_threaded_irq(pdata->id->irq, NULL, 787 - mv_otg_inputs_irq, 788 - IRQF_ONESHOT, "id", mvotg); 809 + retval = devm_request_threaded_irq(&pdev->dev, pdata->id->irq, 810 + NULL, mv_otg_inputs_irq, 811 + IRQF_ONESHOT, "id", mvotg); 789 812 if (retval) { 790 813 dev_info(&pdev->dev, 791 814 "Failed to request irq for ID\n"); ··· 795 818 796 819 if (pdata->vbus) { 797 820 mvotg->clock_gating = 1; 798 - retval = request_threaded_irq(pdata->vbus->irq, NULL, 799 - mv_otg_inputs_irq, 800 - IRQF_ONESHOT, "vbus", mvotg); 821 + retval = devm_request_threaded_irq(&pdev->dev, pdata->vbus->irq, 822 + NULL, mv_otg_inputs_irq, 823 + IRQF_ONESHOT, "vbus", mvotg); 801 824 if (retval) { 802 825 dev_info(&pdev->dev, 803 826 "Failed to request irq for VBUS, " ··· 821 844 } 822 845 823 846 mvotg->irq = r->start; 824 - if (request_irq(mvotg->irq, mv_otg_irq, IRQF_SHARED, 847 + if (devm_request_irq(&pdev->dev, mvotg->irq, mv_otg_irq, IRQF_SHARED, 825 848 driver_name, mvotg)) { 826 849 dev_err(&pdev->dev, "Request irq %d for OTG failed\n", 827 850 mvotg->irq); ··· 834 857 if (retval < 0) { 835 858 dev_err(&pdev->dev, "can't register transceiver, %d\n", 836 859 retval); 837 - goto err_free_irq; 860 + goto err_disable_clk; 838 861 } 839 862 840 863 retval = sysfs_create_group(&pdev->dev.kobj, &inputs_attr_group); 841 864 if (retval < 0) { 842 865 dev_dbg(&pdev->dev, 843 866 "Can't register sysfs attr group: %d\n", retval); 844 - goto err_set_transceiver; 867 + goto err_remove_phy; 845 868 } 846 869 847 870 spin_lock_init(&mvotg->wq_lock); ··· 856 879 857 880 return 0; 858 881 859 - err_set_transceiver: 882 + err_remove_phy: 860 883 usb_remove_phy(&mvotg->phy); 861 - err_free_irq: 862 - free_irq(mvotg->irq, mvotg); 863 884 err_disable_clk: 864 - if (pdata->vbus) 865 - free_irq(pdata->vbus->irq, mvotg); 866 - if (pdata->id) 867 - free_irq(pdata->id->irq, mvotg); 868 885 mv_otg_disable_internal(mvotg); 869 - err_unmap_capreg: 870 - iounmap(mvotg->cap_regs); 871 - err_unmap_phyreg: 872 - iounmap(mvotg->phy_regs); 873 886 err_destroy_workqueue: 874 887 flush_workqueue(mvotg->qwork); 875 888 destroy_workqueue(mvotg->qwork); 876 - err_put_clk: 877 - for (clk_i--; clk_i >= 0; clk_i--) 878 - clk_put(mvotg->clk[clk_i]); 879 889 880 890 platform_set_drvdata(pdev, NULL); 881 - kfree(otg); 882 - kfree(mvotg); 883 891 884 892 return retval; 885 893 }
+20
drivers/usb/otg/mxs-phy.c
··· 76 76 clk_disable_unprepare(mxs_phy->clk); 77 77 } 78 78 79 + static int mxs_phy_suspend(struct usb_phy *x, int suspend) 80 + { 81 + struct mxs_phy *mxs_phy = to_mxs_phy(x); 82 + 83 + if (suspend) { 84 + writel_relaxed(0xffffffff, x->io_priv + HW_USBPHY_PWD); 85 + writel_relaxed(BM_USBPHY_CTRL_CLKGATE, 86 + x->io_priv + HW_USBPHY_CTRL_SET); 87 + clk_disable_unprepare(mxs_phy->clk); 88 + } else { 89 + clk_prepare_enable(mxs_phy->clk); 90 + writel_relaxed(BM_USBPHY_CTRL_CLKGATE, 91 + x->io_priv + HW_USBPHY_CTRL_CLR); 92 + writel_relaxed(0, x->io_priv + HW_USBPHY_PWD); 93 + } 94 + 95 + return 0; 96 + } 97 + 79 98 static int mxs_phy_on_connect(struct usb_phy *phy, 80 99 enum usb_device_speed speed) 81 100 { ··· 156 137 mxs_phy->phy.label = DRIVER_NAME; 157 138 mxs_phy->phy.init = mxs_phy_init; 158 139 mxs_phy->phy.shutdown = mxs_phy_shutdown; 140 + mxs_phy->phy.set_suspend = mxs_phy_suspend; 159 141 mxs_phy->phy.notify_connect = mxs_phy_on_connect; 160 142 mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect; 161 143
+234 -1
drivers/usb/otg/otg.c
··· 13 13 #include <linux/export.h> 14 14 #include <linux/err.h> 15 15 #include <linux/device.h> 16 + #include <linux/module.h> 16 17 #include <linux/slab.h> 18 + #include <linux/of.h> 17 19 18 20 #include <linux/usb/otg.h> 19 21 20 22 static LIST_HEAD(phy_list); 23 + static LIST_HEAD(phy_bind_list); 21 24 static DEFINE_SPINLOCK(phy_lock); 22 25 23 26 static struct usb_phy *__usb_find_phy(struct list_head *list, ··· 30 27 31 28 list_for_each_entry(phy, list, head) { 32 29 if (phy->type != type) 30 + continue; 31 + 32 + return phy; 33 + } 34 + 35 + return ERR_PTR(-ENODEV); 36 + } 37 + 38 + static struct usb_phy *__usb_find_phy_dev(struct device *dev, 39 + struct list_head *list, u8 index) 40 + { 41 + struct usb_phy_bind *phy_bind = NULL; 42 + 43 + list_for_each_entry(phy_bind, list, list) { 44 + if (!(strcmp(phy_bind->dev_name, dev_name(dev))) && 45 + phy_bind->index == index) { 46 + if (phy_bind->phy) 47 + return phy_bind->phy; 48 + else 49 + return ERR_PTR(-EPROBE_DEFER); 50 + } 51 + } 52 + 53 + return ERR_PTR(-ENODEV); 54 + } 55 + 56 + static struct usb_phy *__of_usb_find_phy(struct device_node *node) 57 + { 58 + struct usb_phy *phy; 59 + 60 + list_for_each_entry(phy, &phy_list, head) { 61 + if (node != phy->dev->of_node) 33 62 continue; 34 63 35 64 return phy; ··· 145 110 } 146 111 EXPORT_SYMBOL(usb_get_phy); 147 112 113 + /** 114 + * devm_usb_get_phy_by_phandle - find the USB PHY by phandle 115 + * @dev - device that requests this phy 116 + * @phandle - name of the property holding the phy phandle value 117 + * @index - the index of the phy 118 + * 119 + * Returns the phy driver associated with the given phandle value, 120 + * after getting a refcount to it, -ENODEV if there is no such phy or 121 + * -EPROBE_DEFER if there is a phandle to the phy, but the device is 122 + * not yet loaded. While at that, it also associates the device with 123 + * the phy using devres. On driver detach, release function is invoked 124 + * on the devres data, then, devres data is freed. 125 + * 126 + * For use by USB host and peripheral drivers. 127 + */ 128 + struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev, 129 + const char *phandle, u8 index) 130 + { 131 + struct usb_phy *phy = ERR_PTR(-ENOMEM), **ptr; 132 + unsigned long flags; 133 + struct device_node *node; 134 + 135 + if (!dev->of_node) { 136 + dev_dbg(dev, "device does not have a device node entry\n"); 137 + return ERR_PTR(-EINVAL); 138 + } 139 + 140 + node = of_parse_phandle(dev->of_node, phandle, index); 141 + if (!node) { 142 + dev_dbg(dev, "failed to get %s phandle in %s node\n", phandle, 143 + dev->of_node->full_name); 144 + return ERR_PTR(-ENODEV); 145 + } 146 + 147 + ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL); 148 + if (!ptr) { 149 + dev_dbg(dev, "failed to allocate memory for devres\n"); 150 + goto err0; 151 + } 152 + 153 + spin_lock_irqsave(&phy_lock, flags); 154 + 155 + phy = __of_usb_find_phy(node); 156 + if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) { 157 + phy = ERR_PTR(-EPROBE_DEFER); 158 + devres_free(ptr); 159 + goto err1; 160 + } 161 + 162 + *ptr = phy; 163 + devres_add(dev, ptr); 164 + 165 + get_device(phy->dev); 166 + 167 + err1: 168 + spin_unlock_irqrestore(&phy_lock, flags); 169 + 170 + err0: 171 + of_node_put(node); 172 + 173 + return phy; 174 + } 175 + EXPORT_SYMBOL(devm_usb_get_phy_by_phandle); 176 + 177 + /** 178 + * usb_get_phy_dev - find the USB PHY 179 + * @dev - device that requests this phy 180 + * @index - the index of the phy 181 + * 182 + * Returns the phy driver, after getting a refcount to it; or 183 + * -ENODEV if there is no such phy. The caller is responsible for 184 + * calling usb_put_phy() to release that count. 185 + * 186 + * For use by USB host and peripheral drivers. 187 + */ 188 + struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index) 189 + { 190 + struct usb_phy *phy = NULL; 191 + unsigned long flags; 192 + 193 + spin_lock_irqsave(&phy_lock, flags); 194 + 195 + phy = __usb_find_phy_dev(dev, &phy_bind_list, index); 196 + if (IS_ERR(phy)) { 197 + pr_err("unable to find transceiver\n"); 198 + goto err0; 199 + } 200 + 201 + get_device(phy->dev); 202 + 203 + err0: 204 + spin_unlock_irqrestore(&phy_lock, flags); 205 + 206 + return phy; 207 + } 208 + EXPORT_SYMBOL(usb_get_phy_dev); 209 + 210 + /** 211 + * devm_usb_get_phy_dev - find the USB PHY using device ptr and index 212 + * @dev - device that requests this phy 213 + * @index - the index of the phy 214 + * 215 + * Gets the phy using usb_get_phy_dev(), and associates a device with it using 216 + * devres. On driver detach, release function is invoked on the devres data, 217 + * then, devres data is freed. 218 + * 219 + * For use by USB host and peripheral drivers. 220 + */ 221 + struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index) 222 + { 223 + struct usb_phy **ptr, *phy; 224 + 225 + ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL); 226 + if (!ptr) 227 + return NULL; 228 + 229 + phy = usb_get_phy_dev(dev, index); 230 + if (!IS_ERR(phy)) { 231 + *ptr = phy; 232 + devres_add(dev, ptr); 233 + } else 234 + devres_free(ptr); 235 + 236 + return phy; 237 + } 238 + EXPORT_SYMBOL(devm_usb_get_phy_dev); 239 + 148 240 /** 149 241 * devm_usb_put_phy - release the USB PHY 150 242 * @dev - device that wants to release this phy ··· 347 185 EXPORT_SYMBOL(usb_add_phy); 348 186 349 187 /** 188 + * usb_add_phy_dev - declare the USB PHY 189 + * @x: the USB phy to be used; or NULL 190 + * 191 + * This call is exclusively for use by phy drivers, which 192 + * coordinate the activities of drivers for host and peripheral 193 + * controllers, and in some cases for VBUS current regulation. 194 + */ 195 + int usb_add_phy_dev(struct usb_phy *x) 196 + { 197 + struct usb_phy_bind *phy_bind; 198 + unsigned long flags; 199 + 200 + if (!x->dev) { 201 + dev_err(x->dev, "no device provided for PHY\n"); 202 + return -EINVAL; 203 + } 204 + 205 + spin_lock_irqsave(&phy_lock, flags); 206 + list_for_each_entry(phy_bind, &phy_bind_list, list) 207 + if (!(strcmp(phy_bind->phy_dev_name, dev_name(x->dev)))) 208 + phy_bind->phy = x; 209 + 210 + list_add_tail(&x->head, &phy_list); 211 + 212 + spin_unlock_irqrestore(&phy_lock, flags); 213 + return 0; 214 + } 215 + EXPORT_SYMBOL(usb_add_phy_dev); 216 + 217 + /** 350 218 * usb_remove_phy - remove the OTG PHY 351 219 * @x: the USB OTG PHY to be removed; 352 220 * ··· 385 193 void usb_remove_phy(struct usb_phy *x) 386 194 { 387 195 unsigned long flags; 196 + struct usb_phy_bind *phy_bind; 388 197 389 198 spin_lock_irqsave(&phy_lock, flags); 390 - if (x) 199 + if (x) { 200 + list_for_each_entry(phy_bind, &phy_bind_list, list) 201 + if (phy_bind->phy == x) 202 + phy_bind->phy = NULL; 391 203 list_del(&x->head); 204 + } 392 205 spin_unlock_irqrestore(&phy_lock, flags); 393 206 } 394 207 EXPORT_SYMBOL(usb_remove_phy); 208 + 209 + /** 210 + * usb_bind_phy - bind the phy and the controller that uses the phy 211 + * @dev_name: the device name of the device that will bind to the phy 212 + * @index: index to specify the port number 213 + * @phy_dev_name: the device name of the phy 214 + * 215 + * Fills the phy_bind structure with the dev_name and phy_dev_name. This will 216 + * be used when the phy driver registers the phy and when the controller 217 + * requests this phy. 218 + * 219 + * To be used by platform specific initialization code. 220 + */ 221 + int __init usb_bind_phy(const char *dev_name, u8 index, 222 + const char *phy_dev_name) 223 + { 224 + struct usb_phy_bind *phy_bind; 225 + unsigned long flags; 226 + 227 + phy_bind = kzalloc(sizeof(*phy_bind), GFP_KERNEL); 228 + if (!phy_bind) { 229 + pr_err("phy_bind(): No memory for phy_bind"); 230 + return -ENOMEM; 231 + } 232 + 233 + phy_bind->dev_name = dev_name; 234 + phy_bind->phy_dev_name = phy_dev_name; 235 + phy_bind->index = index; 236 + 237 + spin_lock_irqsave(&phy_lock, flags); 238 + list_add_tail(&phy_bind->list, &phy_bind_list); 239 + spin_unlock_irqrestore(&phy_lock, flags); 240 + 241 + return 0; 242 + } 243 + EXPORT_SYMBOL_GPL(usb_bind_phy); 395 244 396 245 const char *otg_state_string(enum usb_otg_state state) 397 246 {
+2 -1
drivers/usb/otg/twl4030-usb.c
··· 610 610 twl->phy.dev = twl->dev; 611 611 twl->phy.label = "twl4030"; 612 612 twl->phy.otg = otg; 613 + twl->phy.type = USB_PHY_TYPE_USB2; 613 614 twl->phy.set_suspend = twl4030_set_suspend; 614 615 615 616 otg->phy = &twl->phy; ··· 625 624 dev_err(&pdev->dev, "ldo init failed\n"); 626 625 return err; 627 626 } 628 - usb_add_phy(&twl->phy, USB_PHY_TYPE_USB2); 627 + usb_add_phy_dev(&twl->phy); 629 628 630 629 platform_set_drvdata(pdev, twl); 631 630 if (device_create_file(&pdev->dev, &dev_attr_vbus))
+28
drivers/usb/phy/Kconfig
··· 8 8 tristate "OMAP USB2 PHY Driver" 9 9 depends on ARCH_OMAP2PLUS 10 10 select USB_OTG_UTILS 11 + select OMAP_CONTROL_USB 11 12 help 12 13 Enable this to support the transceiver that is part of SOC. This 13 14 driver takes care of all the PHY functionality apart from comparator. 14 15 The USB OTG controller communicates with the comparator using this 15 16 driver. 17 + 18 + config OMAP_USB3 19 + tristate "OMAP USB3 PHY Driver" 20 + select USB_OTG_UTILS 21 + select OMAP_CONTROL_USB 22 + help 23 + Enable this to support the USB3 PHY that is part of SOC. This 24 + driver takes care of all the PHY functionality apart from comparator. 25 + This driver interacts with the "OMAP Control USB Driver" to power 26 + on/off the PHY. 27 + 28 + config OMAP_CONTROL_USB 29 + tristate "OMAP CONTROL USB Driver" 30 + help 31 + Enable this to add support for the USB part present in the control 32 + module. This driver has API to power on the USB2 PHY and to write to 33 + the mailbox. The mailbox is present only in omap4 and the register to 34 + power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an 35 + additional register to power on USB3 PHY. 16 36 17 37 config USB_ISP1301 18 38 tristate "NXP ISP1301 USB transceiver support" ··· 65 45 66 46 To compile this driver as a module, choose M here: the 67 47 module will be called rcar-phy. 48 + 49 + config SAMSUNG_USBPHY 50 + bool "Samsung USB PHY controller Driver" 51 + depends on USB_S3C_HSOTG || USB_EHCI_S5P || USB_OHCI_EXYNOS 52 + select USB_OTG_UTILS 53 + help 54 + Enable this to support Samsung USB phy controller for samsung 55 + SoCs.
+3
drivers/usb/phy/Makefile
··· 5 5 ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG 6 6 7 7 obj-$(CONFIG_OMAP_USB2) += omap-usb2.o 8 + obj-$(CONFIG_OMAP_USB3) += omap-usb3.o 9 + obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o 8 10 obj-$(CONFIG_USB_ISP1301) += isp1301.o 9 11 obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o 10 12 obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.o 11 13 obj-$(CONFIG_USB_RCAR_PHY) += rcar-phy.o 14 + obj-$(CONFIG_SAMSUNG_USBPHY) += samsung-usbphy.o
+295
drivers/usb/phy/omap-control-usb.c
··· 1 + /* 2 + * omap-control-usb.c - The USB part of control module. 3 + * 4 + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation; either version 2 of the License, or 8 + * (at your option) any later version. 9 + * 10 + * Author: Kishon Vijay Abraham I <kishon@ti.com> 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + */ 18 + 19 + #include <linux/module.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/slab.h> 22 + #include <linux/of.h> 23 + #include <linux/err.h> 24 + #include <linux/io.h> 25 + #include <linux/clk.h> 26 + #include <linux/usb/omap_control_usb.h> 27 + 28 + static struct omap_control_usb *control_usb; 29 + 30 + /** 31 + * omap_get_control_dev - returns the device pointer for this control device 32 + * 33 + * This API should be called to get the device pointer for this control 34 + * module device. This device pointer should be used for called other 35 + * exported API's in this driver. 36 + * 37 + * To be used by PHY driver and glue driver. 38 + */ 39 + struct device *omap_get_control_dev(void) 40 + { 41 + if (!control_usb) 42 + return ERR_PTR(-ENODEV); 43 + 44 + return control_usb->dev; 45 + } 46 + EXPORT_SYMBOL_GPL(omap_get_control_dev); 47 + 48 + /** 49 + * omap_control_usb3_phy_power - power on/off the serializer using control 50 + * module 51 + * @dev: the control module device 52 + * @on: 0 to off and 1 to on based on powering on or off the PHY 53 + * 54 + * usb3 PHY driver should call this API to power on or off the PHY. 55 + */ 56 + void omap_control_usb3_phy_power(struct device *dev, bool on) 57 + { 58 + u32 val; 59 + unsigned long rate; 60 + struct omap_control_usb *control_usb = dev_get_drvdata(dev); 61 + 62 + if (control_usb->type != OMAP_CTRL_DEV_TYPE2) 63 + return; 64 + 65 + rate = clk_get_rate(control_usb->sys_clk); 66 + rate = rate/1000000; 67 + 68 + val = readl(control_usb->phy_power); 69 + 70 + if (on) { 71 + val &= ~(OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK | 72 + OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK); 73 + val |= OMAP_CTRL_USB3_PHY_TX_RX_POWERON << 74 + OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT; 75 + val |= rate << OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT; 76 + } else { 77 + val &= ~OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK; 78 + val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF << 79 + OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT; 80 + } 81 + 82 + writel(val, control_usb->phy_power); 83 + } 84 + EXPORT_SYMBOL_GPL(omap_control_usb3_phy_power); 85 + 86 + /** 87 + * omap_control_usb_phy_power - power on/off the phy using control module reg 88 + * @dev: the control module device 89 + * @on: 0 or 1, based on powering on or off the PHY 90 + */ 91 + void omap_control_usb_phy_power(struct device *dev, int on) 92 + { 93 + u32 val; 94 + struct omap_control_usb *control_usb = dev_get_drvdata(dev); 95 + 96 + val = readl(control_usb->dev_conf); 97 + 98 + if (on) 99 + val &= ~OMAP_CTRL_DEV_PHY_PD; 100 + else 101 + val |= OMAP_CTRL_DEV_PHY_PD; 102 + 103 + writel(val, control_usb->dev_conf); 104 + } 105 + EXPORT_SYMBOL_GPL(omap_control_usb_phy_power); 106 + 107 + /** 108 + * omap_control_usb_host_mode - set AVALID, VBUSVALID and ID pin in grounded 109 + * @ctrl_usb: struct omap_control_usb * 110 + * 111 + * Writes to the mailbox register to notify the usb core that a usb 112 + * device has been connected. 113 + */ 114 + static void omap_control_usb_host_mode(struct omap_control_usb *ctrl_usb) 115 + { 116 + u32 val; 117 + 118 + val = readl(ctrl_usb->otghs_control); 119 + val &= ~(OMAP_CTRL_DEV_IDDIG | OMAP_CTRL_DEV_SESSEND); 120 + val |= OMAP_CTRL_DEV_AVALID | OMAP_CTRL_DEV_VBUSVALID; 121 + writel(val, ctrl_usb->otghs_control); 122 + } 123 + 124 + /** 125 + * omap_control_usb_device_mode - set AVALID, VBUSVALID and ID pin in high 126 + * impedance 127 + * @ctrl_usb: struct omap_control_usb * 128 + * 129 + * Writes to the mailbox register to notify the usb core that it has been 130 + * connected to a usb host. 131 + */ 132 + static void omap_control_usb_device_mode(struct omap_control_usb *ctrl_usb) 133 + { 134 + u32 val; 135 + 136 + val = readl(ctrl_usb->otghs_control); 137 + val &= ~OMAP_CTRL_DEV_SESSEND; 138 + val |= OMAP_CTRL_DEV_IDDIG | OMAP_CTRL_DEV_AVALID | 139 + OMAP_CTRL_DEV_VBUSVALID; 140 + writel(val, ctrl_usb->otghs_control); 141 + } 142 + 143 + /** 144 + * omap_control_usb_set_sessionend - Enable SESSIONEND and IDIG to high 145 + * impedance 146 + * @ctrl_usb: struct omap_control_usb * 147 + * 148 + * Writes to the mailbox register to notify the usb core it's now in 149 + * disconnected state. 150 + */ 151 + static void omap_control_usb_set_sessionend(struct omap_control_usb *ctrl_usb) 152 + { 153 + u32 val; 154 + 155 + val = readl(ctrl_usb->otghs_control); 156 + val &= ~(OMAP_CTRL_DEV_AVALID | OMAP_CTRL_DEV_VBUSVALID); 157 + val |= OMAP_CTRL_DEV_IDDIG | OMAP_CTRL_DEV_SESSEND; 158 + writel(val, ctrl_usb->otghs_control); 159 + } 160 + 161 + /** 162 + * omap_control_usb_set_mode - Calls to functions to set USB in one of host mode 163 + * or device mode or to denote disconnected state 164 + * @dev: the control module device 165 + * @mode: The mode to which usb should be configured 166 + * 167 + * This is an API to write to the mailbox register to notify the usb core that 168 + * a usb device has been connected. 169 + */ 170 + void omap_control_usb_set_mode(struct device *dev, 171 + enum omap_control_usb_mode mode) 172 + { 173 + struct omap_control_usb *ctrl_usb; 174 + 175 + if (IS_ERR(dev) || control_usb->type != OMAP_CTRL_DEV_TYPE1) 176 + return; 177 + 178 + ctrl_usb = dev_get_drvdata(dev); 179 + 180 + switch (mode) { 181 + case USB_MODE_HOST: 182 + omap_control_usb_host_mode(ctrl_usb); 183 + break; 184 + case USB_MODE_DEVICE: 185 + omap_control_usb_device_mode(ctrl_usb); 186 + break; 187 + case USB_MODE_DISCONNECT: 188 + omap_control_usb_set_sessionend(ctrl_usb); 189 + break; 190 + default: 191 + dev_vdbg(dev, "invalid omap control usb mode\n"); 192 + } 193 + } 194 + EXPORT_SYMBOL_GPL(omap_control_usb_set_mode); 195 + 196 + static int omap_control_usb_probe(struct platform_device *pdev) 197 + { 198 + struct resource *res; 199 + struct device_node *np = pdev->dev.of_node; 200 + struct omap_control_usb_platform_data *pdata = pdev->dev.platform_data; 201 + 202 + control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb), 203 + GFP_KERNEL); 204 + if (!control_usb) { 205 + dev_err(&pdev->dev, "unable to alloc memory for control usb\n"); 206 + return -ENOMEM; 207 + } 208 + 209 + if (np) { 210 + of_property_read_u32(np, "ti,type", &control_usb->type); 211 + } else if (pdata) { 212 + control_usb->type = pdata->type; 213 + } else { 214 + dev_err(&pdev->dev, "no pdata present\n"); 215 + return -EINVAL; 216 + } 217 + 218 + control_usb->dev = &pdev->dev; 219 + 220 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 221 + "control_dev_conf"); 222 + control_usb->dev_conf = devm_request_and_ioremap(&pdev->dev, res); 223 + if (!control_usb->dev_conf) { 224 + dev_err(&pdev->dev, "Failed to obtain io memory\n"); 225 + return -EADDRNOTAVAIL; 226 + } 227 + 228 + if (control_usb->type == OMAP_CTRL_DEV_TYPE1) { 229 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 230 + "otghs_control"); 231 + control_usb->otghs_control = devm_request_and_ioremap( 232 + &pdev->dev, res); 233 + if (!control_usb->otghs_control) { 234 + dev_err(&pdev->dev, "Failed to obtain io memory\n"); 235 + return -EADDRNOTAVAIL; 236 + } 237 + } 238 + 239 + if (control_usb->type == OMAP_CTRL_DEV_TYPE2) { 240 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 241 + "phy_power_usb"); 242 + control_usb->phy_power = devm_request_and_ioremap( 243 + &pdev->dev, res); 244 + if (!control_usb->phy_power) { 245 + dev_dbg(&pdev->dev, "Failed to obtain io memory\n"); 246 + return -EADDRNOTAVAIL; 247 + } 248 + 249 + control_usb->sys_clk = devm_clk_get(control_usb->dev, 250 + "sys_clkin"); 251 + if (IS_ERR(control_usb->sys_clk)) { 252 + pr_err("%s: unable to get sys_clkin\n", __func__); 253 + return -EINVAL; 254 + } 255 + } 256 + 257 + 258 + dev_set_drvdata(control_usb->dev, control_usb); 259 + 260 + return 0; 261 + } 262 + 263 + #ifdef CONFIG_OF 264 + static const struct of_device_id omap_control_usb_id_table[] = { 265 + { .compatible = "ti,omap-control-usb" }, 266 + {} 267 + }; 268 + MODULE_DEVICE_TABLE(of, omap_control_usb_id_table); 269 + #endif 270 + 271 + static struct platform_driver omap_control_usb_driver = { 272 + .probe = omap_control_usb_probe, 273 + .driver = { 274 + .name = "omap-control-usb", 275 + .owner = THIS_MODULE, 276 + .of_match_table = of_match_ptr(omap_control_usb_id_table), 277 + }, 278 + }; 279 + 280 + static int __init omap_control_usb_init(void) 281 + { 282 + return platform_driver_register(&omap_control_usb_driver); 283 + } 284 + subsys_initcall(omap_control_usb_init); 285 + 286 + static void __exit omap_control_usb_exit(void) 287 + { 288 + platform_driver_unregister(&omap_control_usb_driver); 289 + } 290 + module_exit(omap_control_usb_exit); 291 + 292 + MODULE_ALIAS("platform: omap_control_usb"); 293 + MODULE_AUTHOR("Texas Instruments Inc."); 294 + MODULE_DESCRIPTION("OMAP Control Module USB Driver"); 295 + MODULE_LICENSE("GPL v2");
+38 -34
drivers/usb/phy/omap-usb2.c
··· 27 27 #include <linux/err.h> 28 28 #include <linux/pm_runtime.h> 29 29 #include <linux/delay.h> 30 + #include <linux/usb/omap_control_usb.h> 30 31 31 32 /** 32 33 * omap_usb2_set_comparator - links the comparator present in the sytem with ··· 52 51 return 0; 53 52 } 54 53 EXPORT_SYMBOL_GPL(omap_usb2_set_comparator); 55 - 56 - /** 57 - * omap_usb_phy_power - power on/off the phy using control module reg 58 - * @phy: struct omap_usb * 59 - * @on: 0 or 1, based on powering on or off the PHY 60 - * 61 - * XXX: Remove this function once control module driver gets merged 62 - */ 63 - static void omap_usb_phy_power(struct omap_usb *phy, int on) 64 - { 65 - u32 val; 66 - 67 - if (on) { 68 - val = readl(phy->control_dev); 69 - if (val & PHY_PD) { 70 - writel(~PHY_PD, phy->control_dev); 71 - /* XXX: add proper documentation for this delay */ 72 - mdelay(200); 73 - } 74 - } else { 75 - writel(PHY_PD, phy->control_dev); 76 - } 77 - } 78 54 79 55 static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled) 80 56 { ··· 102 124 struct omap_usb *phy = phy_to_omapusb(x); 103 125 104 126 if (suspend && !phy->is_suspended) { 105 - omap_usb_phy_power(phy, 0); 127 + omap_control_usb_phy_power(phy->control_dev, 0); 106 128 pm_runtime_put_sync(phy->dev); 107 129 phy->is_suspended = 1; 108 130 } else if (!suspend && phy->is_suspended) { ··· 112 134 ret); 113 135 return ret; 114 136 } 115 - omap_usb_phy_power(phy, 1); 137 + omap_control_usb_phy_power(phy->control_dev, 1); 116 138 phy->is_suspended = 0; 117 139 } 118 140 ··· 123 145 { 124 146 struct omap_usb *phy; 125 147 struct usb_otg *otg; 126 - struct resource *res; 127 148 128 149 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); 129 150 if (!phy) { ··· 142 165 phy->phy.label = "omap-usb2"; 143 166 phy->phy.set_suspend = omap_usb2_suspend; 144 167 phy->phy.otg = otg; 168 + phy->phy.type = USB_PHY_TYPE_USB2; 145 169 146 - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 147 - 148 - phy->control_dev = devm_ioremap_resource(&pdev->dev, res); 149 - if (IS_ERR(phy->control_dev)) 150 - return PTR_ERR(phy->control_dev); 170 + phy->control_dev = omap_get_control_dev(); 171 + if (IS_ERR(phy->control_dev)) { 172 + dev_dbg(&pdev->dev, "Failed to get control device\n"); 173 + return -ENODEV; 174 + } 151 175 152 176 phy->is_suspended = 1; 153 - omap_usb_phy_power(phy, 0); 177 + omap_control_usb_phy_power(phy->control_dev, 0); 154 178 155 179 otg->set_host = omap_usb_set_host; 156 180 otg->set_peripheral = omap_usb_set_peripheral; ··· 166 188 } 167 189 clk_prepare(phy->wkupclk); 168 190 169 - usb_add_phy(&phy->phy, USB_PHY_TYPE_USB2); 191 + phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m"); 192 + if (IS_ERR(phy->optclk)) 193 + dev_vdbg(&pdev->dev, "unable to get refclk960m\n"); 194 + else 195 + clk_prepare(phy->optclk); 196 + 197 + usb_add_phy_dev(&phy->phy); 170 198 171 199 platform_set_drvdata(pdev, phy); 172 200 ··· 186 202 struct omap_usb *phy = platform_get_drvdata(pdev); 187 203 188 204 clk_unprepare(phy->wkupclk); 205 + if (!IS_ERR(phy->optclk)) 206 + clk_unprepare(phy->optclk); 189 207 usb_remove_phy(&phy->phy); 190 208 191 209 return 0; ··· 201 215 struct omap_usb *phy = platform_get_drvdata(pdev); 202 216 203 217 clk_disable(phy->wkupclk); 218 + if (!IS_ERR(phy->optclk)) 219 + clk_disable(phy->optclk); 204 220 205 221 return 0; 206 222 } ··· 214 226 struct omap_usb *phy = platform_get_drvdata(pdev); 215 227 216 228 ret = clk_enable(phy->wkupclk); 217 - if (ret < 0) 229 + if (ret < 0) { 218 230 dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret); 231 + goto err0; 232 + } 219 233 234 + if (!IS_ERR(phy->optclk)) { 235 + ret = clk_enable(phy->optclk); 236 + if (ret < 0) { 237 + dev_err(phy->dev, "Failed to enable optclk %d\n", ret); 238 + goto err1; 239 + } 240 + } 241 + 242 + return 0; 243 + 244 + err1: 245 + clk_disable(phy->wkupclk); 246 + 247 + err0: 220 248 return ret; 221 249 } 222 250
+355
drivers/usb/phy/omap-usb3.c
··· 1 + /* 2 + * omap-usb3 - USB PHY, talking to dwc3 controller in OMAP. 3 + * 4 + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation; either version 2 of the License, or 8 + * (at your option) any later version. 9 + * 10 + * Author: Kishon Vijay Abraham I <kishon@ti.com> 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + */ 18 + 19 + #include <linux/module.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/slab.h> 22 + #include <linux/usb/omap_usb.h> 23 + #include <linux/of.h> 24 + #include <linux/clk.h> 25 + #include <linux/err.h> 26 + #include <linux/pm_runtime.h> 27 + #include <linux/delay.h> 28 + #include <linux/usb/omap_control_usb.h> 29 + 30 + #define NUM_SYS_CLKS 5 31 + #define PLL_STATUS 0x00000004 32 + #define PLL_GO 0x00000008 33 + #define PLL_CONFIGURATION1 0x0000000C 34 + #define PLL_CONFIGURATION2 0x00000010 35 + #define PLL_CONFIGURATION3 0x00000014 36 + #define PLL_CONFIGURATION4 0x00000020 37 + 38 + #define PLL_REGM_MASK 0x001FFE00 39 + #define PLL_REGM_SHIFT 0x9 40 + #define PLL_REGM_F_MASK 0x0003FFFF 41 + #define PLL_REGM_F_SHIFT 0x0 42 + #define PLL_REGN_MASK 0x000001FE 43 + #define PLL_REGN_SHIFT 0x1 44 + #define PLL_SELFREQDCO_MASK 0x0000000E 45 + #define PLL_SELFREQDCO_SHIFT 0x1 46 + #define PLL_SD_MASK 0x0003FC00 47 + #define PLL_SD_SHIFT 0x9 48 + #define SET_PLL_GO 0x1 49 + #define PLL_TICOPWDN 0x10000 50 + #define PLL_LOCK 0x2 51 + #define PLL_IDLE 0x1 52 + 53 + /* 54 + * This is an Empirical value that works, need to confirm the actual 55 + * value required for the USB3PHY_PLL_CONFIGURATION2.PLL_IDLE status 56 + * to be correctly reflected in the USB3PHY_PLL_STATUS register. 57 + */ 58 + # define PLL_IDLE_TIME 100; 59 + 60 + enum sys_clk_rate { 61 + CLK_RATE_UNDEFINED = -1, 62 + CLK_RATE_12MHZ, 63 + CLK_RATE_16MHZ, 64 + CLK_RATE_19MHZ, 65 + CLK_RATE_26MHZ, 66 + CLK_RATE_38MHZ 67 + }; 68 + 69 + static struct usb_dpll_params omap_usb3_dpll_params[NUM_SYS_CLKS] = { 70 + {1250, 5, 4, 20, 0}, /* 12 MHz */ 71 + {3125, 20, 4, 20, 0}, /* 16.8 MHz */ 72 + {1172, 8, 4, 20, 65537}, /* 19.2 MHz */ 73 + {1250, 12, 4, 20, 0}, /* 26 MHz */ 74 + {3125, 47, 4, 20, 92843}, /* 38.4 MHz */ 75 + }; 76 + 77 + static int omap_usb3_suspend(struct usb_phy *x, int suspend) 78 + { 79 + struct omap_usb *phy = phy_to_omapusb(x); 80 + int val; 81 + int timeout = PLL_IDLE_TIME; 82 + 83 + if (suspend && !phy->is_suspended) { 84 + val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2); 85 + val |= PLL_IDLE; 86 + omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val); 87 + 88 + do { 89 + val = omap_usb_readl(phy->pll_ctrl_base, PLL_STATUS); 90 + if (val & PLL_TICOPWDN) 91 + break; 92 + udelay(1); 93 + } while (--timeout); 94 + 95 + omap_control_usb3_phy_power(phy->control_dev, 0); 96 + 97 + phy->is_suspended = 1; 98 + } else if (!suspend && phy->is_suspended) { 99 + phy->is_suspended = 0; 100 + 101 + val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2); 102 + val &= ~PLL_IDLE; 103 + omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val); 104 + 105 + do { 106 + val = omap_usb_readl(phy->pll_ctrl_base, PLL_STATUS); 107 + if (!(val & PLL_TICOPWDN)) 108 + break; 109 + udelay(1); 110 + } while (--timeout); 111 + } 112 + 113 + return 0; 114 + } 115 + 116 + static inline enum sys_clk_rate __get_sys_clk_index(unsigned long rate) 117 + { 118 + switch (rate) { 119 + case 12000000: 120 + return CLK_RATE_12MHZ; 121 + case 16800000: 122 + return CLK_RATE_16MHZ; 123 + case 19200000: 124 + return CLK_RATE_19MHZ; 125 + case 26000000: 126 + return CLK_RATE_26MHZ; 127 + case 38400000: 128 + return CLK_RATE_38MHZ; 129 + default: 130 + return CLK_RATE_UNDEFINED; 131 + } 132 + } 133 + 134 + static void omap_usb_dpll_relock(struct omap_usb *phy) 135 + { 136 + u32 val; 137 + unsigned long timeout; 138 + 139 + omap_usb_writel(phy->pll_ctrl_base, PLL_GO, SET_PLL_GO); 140 + 141 + timeout = jiffies + msecs_to_jiffies(20); 142 + do { 143 + val = omap_usb_readl(phy->pll_ctrl_base, PLL_STATUS); 144 + if (val & PLL_LOCK) 145 + break; 146 + } while (!WARN_ON(time_after(jiffies, timeout))); 147 + } 148 + 149 + static int omap_usb_dpll_lock(struct omap_usb *phy) 150 + { 151 + u32 val; 152 + unsigned long rate; 153 + enum sys_clk_rate clk_index; 154 + 155 + rate = clk_get_rate(phy->sys_clk); 156 + clk_index = __get_sys_clk_index(rate); 157 + 158 + if (clk_index == CLK_RATE_UNDEFINED) { 159 + pr_err("dpll cannot be locked for sys clk freq:%luHz\n", rate); 160 + return -EINVAL; 161 + } 162 + 163 + val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1); 164 + val &= ~PLL_REGN_MASK; 165 + val |= omap_usb3_dpll_params[clk_index].n << PLL_REGN_SHIFT; 166 + omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val); 167 + 168 + val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2); 169 + val &= ~PLL_SELFREQDCO_MASK; 170 + val |= omap_usb3_dpll_params[clk_index].freq << PLL_SELFREQDCO_SHIFT; 171 + omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val); 172 + 173 + val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1); 174 + val &= ~PLL_REGM_MASK; 175 + val |= omap_usb3_dpll_params[clk_index].m << PLL_REGM_SHIFT; 176 + omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val); 177 + 178 + val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION4); 179 + val &= ~PLL_REGM_F_MASK; 180 + val |= omap_usb3_dpll_params[clk_index].mf << PLL_REGM_F_SHIFT; 181 + omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION4, val); 182 + 183 + val = omap_usb_readl(phy->pll_ctrl_base, PLL_CONFIGURATION3); 184 + val &= ~PLL_SD_MASK; 185 + val |= omap_usb3_dpll_params[clk_index].sd << PLL_SD_SHIFT; 186 + omap_usb_writel(phy->pll_ctrl_base, PLL_CONFIGURATION3, val); 187 + 188 + omap_usb_dpll_relock(phy); 189 + 190 + return 0; 191 + } 192 + 193 + static int omap_usb3_init(struct usb_phy *x) 194 + { 195 + struct omap_usb *phy = phy_to_omapusb(x); 196 + 197 + omap_usb_dpll_lock(phy); 198 + omap_control_usb3_phy_power(phy->control_dev, 1); 199 + 200 + return 0; 201 + } 202 + 203 + static int omap_usb3_probe(struct platform_device *pdev) 204 + { 205 + struct omap_usb *phy; 206 + struct resource *res; 207 + 208 + phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); 209 + if (!phy) { 210 + dev_err(&pdev->dev, "unable to alloc mem for OMAP USB3 PHY\n"); 211 + return -ENOMEM; 212 + } 213 + 214 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pll_ctrl"); 215 + phy->pll_ctrl_base = devm_request_and_ioremap(&pdev->dev, res); 216 + if (!phy->pll_ctrl_base) { 217 + dev_err(&pdev->dev, "ioremap of pll_ctrl failed\n"); 218 + return -ENOMEM; 219 + } 220 + 221 + phy->dev = &pdev->dev; 222 + 223 + phy->phy.dev = phy->dev; 224 + phy->phy.label = "omap-usb3"; 225 + phy->phy.init = omap_usb3_init; 226 + phy->phy.set_suspend = omap_usb3_suspend; 227 + phy->phy.type = USB_PHY_TYPE_USB3; 228 + 229 + phy->is_suspended = 1; 230 + phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k"); 231 + if (IS_ERR(phy->wkupclk)) { 232 + dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n"); 233 + return PTR_ERR(phy->wkupclk); 234 + } 235 + clk_prepare(phy->wkupclk); 236 + 237 + phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m"); 238 + if (IS_ERR(phy->optclk)) { 239 + dev_err(&pdev->dev, "unable to get usb_otg_ss_refclk960m\n"); 240 + return PTR_ERR(phy->optclk); 241 + } 242 + clk_prepare(phy->optclk); 243 + 244 + phy->sys_clk = devm_clk_get(phy->dev, "sys_clkin"); 245 + if (IS_ERR(phy->sys_clk)) { 246 + pr_err("%s: unable to get sys_clkin\n", __func__); 247 + return -EINVAL; 248 + } 249 + 250 + phy->control_dev = omap_get_control_dev(); 251 + if (IS_ERR(phy->control_dev)) { 252 + dev_dbg(&pdev->dev, "Failed to get control device\n"); 253 + return -ENODEV; 254 + } 255 + 256 + omap_control_usb3_phy_power(phy->control_dev, 0); 257 + usb_add_phy_dev(&phy->phy); 258 + 259 + platform_set_drvdata(pdev, phy); 260 + 261 + pm_runtime_enable(phy->dev); 262 + pm_runtime_get(&pdev->dev); 263 + 264 + return 0; 265 + } 266 + 267 + static int omap_usb3_remove(struct platform_device *pdev) 268 + { 269 + struct omap_usb *phy = platform_get_drvdata(pdev); 270 + 271 + clk_unprepare(phy->wkupclk); 272 + clk_unprepare(phy->optclk); 273 + usb_remove_phy(&phy->phy); 274 + if (!pm_runtime_suspended(&pdev->dev)) 275 + pm_runtime_put(&pdev->dev); 276 + pm_runtime_disable(&pdev->dev); 277 + 278 + return 0; 279 + } 280 + 281 + #ifdef CONFIG_PM_RUNTIME 282 + 283 + static int omap_usb3_runtime_suspend(struct device *dev) 284 + { 285 + struct platform_device *pdev = to_platform_device(dev); 286 + struct omap_usb *phy = platform_get_drvdata(pdev); 287 + 288 + clk_disable(phy->wkupclk); 289 + clk_disable(phy->optclk); 290 + 291 + return 0; 292 + } 293 + 294 + static int omap_usb3_runtime_resume(struct device *dev) 295 + { 296 + u32 ret = 0; 297 + struct platform_device *pdev = to_platform_device(dev); 298 + struct omap_usb *phy = platform_get_drvdata(pdev); 299 + 300 + ret = clk_enable(phy->optclk); 301 + if (ret) { 302 + dev_err(phy->dev, "Failed to enable optclk %d\n", ret); 303 + goto err1; 304 + } 305 + 306 + ret = clk_enable(phy->wkupclk); 307 + if (ret) { 308 + dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret); 309 + goto err2; 310 + } 311 + 312 + return 0; 313 + 314 + err2: 315 + clk_disable(phy->optclk); 316 + 317 + err1: 318 + return ret; 319 + } 320 + 321 + static const struct dev_pm_ops omap_usb3_pm_ops = { 322 + SET_RUNTIME_PM_OPS(omap_usb3_runtime_suspend, omap_usb3_runtime_resume, 323 + NULL) 324 + }; 325 + 326 + #define DEV_PM_OPS (&omap_usb3_pm_ops) 327 + #else 328 + #define DEV_PM_OPS NULL 329 + #endif 330 + 331 + #ifdef CONFIG_OF 332 + static const struct of_device_id omap_usb3_id_table[] = { 333 + { .compatible = "ti,omap-usb3" }, 334 + {} 335 + }; 336 + MODULE_DEVICE_TABLE(of, omap_usb3_id_table); 337 + #endif 338 + 339 + static struct platform_driver omap_usb3_driver = { 340 + .probe = omap_usb3_probe, 341 + .remove = omap_usb3_remove, 342 + .driver = { 343 + .name = "omap-usb3", 344 + .owner = THIS_MODULE, 345 + .pm = DEV_PM_OPS, 346 + .of_match_table = of_match_ptr(omap_usb3_id_table), 347 + }, 348 + }; 349 + 350 + module_platform_driver(omap_usb3_driver); 351 + 352 + MODULE_ALIAS("platform: omap_usb3"); 353 + MODULE_AUTHOR("Texas Instruments Inc."); 354 + MODULE_DESCRIPTION("OMAP USB3 phy driver"); 355 + MODULE_LICENSE("GPL v2");
+930
drivers/usb/phy/samsung-usbphy.c
··· 1 + /* linux/drivers/usb/phy/samsung-usbphy.c 2 + * 3 + * Copyright (c) 2012 Samsung Electronics Co., Ltd. 4 + * http://www.samsung.com 5 + * 6 + * Author: Praveen Paneri <p.paneri@samsung.com> 7 + * 8 + * Samsung USB2.0 PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and 9 + * OHCI-EXYNOS controllers. 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + * 15 + * This program is distributed in the hope that it will be useful, 16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 + * GNU General Public License for more details. 19 + */ 20 + 21 + #include <linux/module.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/clk.h> 24 + #include <linux/delay.h> 25 + #include <linux/device.h> 26 + #include <linux/err.h> 27 + #include <linux/io.h> 28 + #include <linux/of.h> 29 + #include <linux/of_address.h> 30 + #include <linux/usb/otg.h> 31 + #include <linux/usb/samsung_usb_phy.h> 32 + #include <linux/platform_data/samsung-usbphy.h> 33 + 34 + /* Register definitions */ 35 + 36 + #define SAMSUNG_PHYPWR (0x00) 37 + 38 + #define PHYPWR_NORMAL_MASK (0x19 << 0) 39 + #define PHYPWR_OTG_DISABLE (0x1 << 4) 40 + #define PHYPWR_ANALOG_POWERDOWN (0x1 << 3) 41 + #define PHYPWR_FORCE_SUSPEND (0x1 << 1) 42 + /* For Exynos4 */ 43 + #define PHYPWR_NORMAL_MASK_PHY0 (0x39 << 0) 44 + #define PHYPWR_SLEEP_PHY0 (0x1 << 5) 45 + 46 + #define SAMSUNG_PHYCLK (0x04) 47 + 48 + #define PHYCLK_MODE_USB11 (0x1 << 6) 49 + #define PHYCLK_EXT_OSC (0x1 << 5) 50 + #define PHYCLK_COMMON_ON_N (0x1 << 4) 51 + #define PHYCLK_ID_PULL (0x1 << 2) 52 + #define PHYCLK_CLKSEL_MASK (0x3 << 0) 53 + #define PHYCLK_CLKSEL_48M (0x0 << 0) 54 + #define PHYCLK_CLKSEL_12M (0x2 << 0) 55 + #define PHYCLK_CLKSEL_24M (0x3 << 0) 56 + 57 + #define SAMSUNG_RSTCON (0x08) 58 + 59 + #define RSTCON_PHYLINK_SWRST (0x1 << 2) 60 + #define RSTCON_HLINK_SWRST (0x1 << 1) 61 + #define RSTCON_SWRST (0x1 << 0) 62 + 63 + /* EXYNOS5 */ 64 + #define EXYNOS5_PHY_HOST_CTRL0 (0x00) 65 + 66 + #define HOST_CTRL0_PHYSWRSTALL (0x1 << 31) 67 + 68 + #define HOST_CTRL0_REFCLKSEL_MASK (0x3 << 19) 69 + #define HOST_CTRL0_REFCLKSEL_XTAL (0x0 << 19) 70 + #define HOST_CTRL0_REFCLKSEL_EXTL (0x1 << 19) 71 + #define HOST_CTRL0_REFCLKSEL_CLKCORE (0x2 << 19) 72 + 73 + #define HOST_CTRL0_FSEL_MASK (0x7 << 16) 74 + #define HOST_CTRL0_FSEL(_x) ((_x) << 16) 75 + 76 + #define FSEL_CLKSEL_50M (0x7) 77 + #define FSEL_CLKSEL_24M (0x5) 78 + #define FSEL_CLKSEL_20M (0x4) 79 + #define FSEL_CLKSEL_19200K (0x3) 80 + #define FSEL_CLKSEL_12M (0x2) 81 + #define FSEL_CLKSEL_10M (0x1) 82 + #define FSEL_CLKSEL_9600K (0x0) 83 + 84 + #define HOST_CTRL0_TESTBURNIN (0x1 << 11) 85 + #define HOST_CTRL0_RETENABLE (0x1 << 10) 86 + #define HOST_CTRL0_COMMONON_N (0x1 << 9) 87 + #define HOST_CTRL0_SIDDQ (0x1 << 6) 88 + #define HOST_CTRL0_FORCESLEEP (0x1 << 5) 89 + #define HOST_CTRL0_FORCESUSPEND (0x1 << 4) 90 + #define HOST_CTRL0_WORDINTERFACE (0x1 << 3) 91 + #define HOST_CTRL0_UTMISWRST (0x1 << 2) 92 + #define HOST_CTRL0_LINKSWRST (0x1 << 1) 93 + #define HOST_CTRL0_PHYSWRST (0x1 << 0) 94 + 95 + #define EXYNOS5_PHY_HOST_TUNE0 (0x04) 96 + 97 + #define EXYNOS5_PHY_HSIC_CTRL1 (0x10) 98 + 99 + #define EXYNOS5_PHY_HSIC_TUNE1 (0x14) 100 + 101 + #define EXYNOS5_PHY_HSIC_CTRL2 (0x20) 102 + 103 + #define EXYNOS5_PHY_HSIC_TUNE2 (0x24) 104 + 105 + #define HSIC_CTRL_REFCLKSEL_MASK (0x3 << 23) 106 + #define HSIC_CTRL_REFCLKSEL (0x2 << 23) 107 + 108 + #define HSIC_CTRL_REFCLKDIV_MASK (0x7f << 16) 109 + #define HSIC_CTRL_REFCLKDIV(_x) ((_x) << 16) 110 + #define HSIC_CTRL_REFCLKDIV_12 (0x24 << 16) 111 + #define HSIC_CTRL_REFCLKDIV_15 (0x1c << 16) 112 + #define HSIC_CTRL_REFCLKDIV_16 (0x1a << 16) 113 + #define HSIC_CTRL_REFCLKDIV_19_2 (0x15 << 16) 114 + #define HSIC_CTRL_REFCLKDIV_20 (0x14 << 16) 115 + 116 + #define HSIC_CTRL_SIDDQ (0x1 << 6) 117 + #define HSIC_CTRL_FORCESLEEP (0x1 << 5) 118 + #define HSIC_CTRL_FORCESUSPEND (0x1 << 4) 119 + #define HSIC_CTRL_WORDINTERFACE (0x1 << 3) 120 + #define HSIC_CTRL_UTMISWRST (0x1 << 2) 121 + #define HSIC_CTRL_PHYSWRST (0x1 << 0) 122 + 123 + #define EXYNOS5_PHY_HOST_EHCICTRL (0x30) 124 + 125 + #define HOST_EHCICTRL_ENAINCRXALIGN (0x1 << 29) 126 + #define HOST_EHCICTRL_ENAINCR4 (0x1 << 28) 127 + #define HOST_EHCICTRL_ENAINCR8 (0x1 << 27) 128 + #define HOST_EHCICTRL_ENAINCR16 (0x1 << 26) 129 + 130 + #define EXYNOS5_PHY_HOST_OHCICTRL (0x34) 131 + 132 + #define HOST_OHCICTRL_SUSPLGCY (0x1 << 3) 133 + #define HOST_OHCICTRL_APPSTARTCLK (0x1 << 2) 134 + #define HOST_OHCICTRL_CNTSEL (0x1 << 1) 135 + #define HOST_OHCICTRL_CLKCKTRST (0x1 << 0) 136 + 137 + #define EXYNOS5_PHY_OTG_SYS (0x38) 138 + 139 + #define OTG_SYS_PHYLINK_SWRESET (0x1 << 14) 140 + #define OTG_SYS_LINKSWRST_UOTG (0x1 << 13) 141 + #define OTG_SYS_PHY0_SWRST (0x1 << 12) 142 + 143 + #define OTG_SYS_REFCLKSEL_MASK (0x3 << 9) 144 + #define OTG_SYS_REFCLKSEL_XTAL (0x0 << 9) 145 + #define OTG_SYS_REFCLKSEL_EXTL (0x1 << 9) 146 + #define OTG_SYS_REFCLKSEL_CLKCORE (0x2 << 9) 147 + 148 + #define OTG_SYS_IDPULLUP_UOTG (0x1 << 8) 149 + #define OTG_SYS_COMMON_ON (0x1 << 7) 150 + 151 + #define OTG_SYS_FSEL_MASK (0x7 << 4) 152 + #define OTG_SYS_FSEL(_x) ((_x) << 4) 153 + 154 + #define OTG_SYS_FORCESLEEP (0x1 << 3) 155 + #define OTG_SYS_OTGDISABLE (0x1 << 2) 156 + #define OTG_SYS_SIDDQ_UOTG (0x1 << 1) 157 + #define OTG_SYS_FORCESUSPEND (0x1 << 0) 158 + 159 + #define EXYNOS5_PHY_OTG_TUNE (0x40) 160 + 161 + #ifndef MHZ 162 + #define MHZ (1000*1000) 163 + #endif 164 + 165 + #ifndef KHZ 166 + #define KHZ (1000) 167 + #endif 168 + 169 + #define EXYNOS_USBHOST_PHY_CTRL_OFFSET (0x4) 170 + #define S3C64XX_USBPHY_ENABLE (0x1 << 16) 171 + #define EXYNOS_USBPHY_ENABLE (0x1 << 0) 172 + #define EXYNOS_USB20PHY_CFG_HOST_LINK (0x1 << 0) 173 + 174 + enum samsung_cpu_type { 175 + TYPE_S3C64XX, 176 + TYPE_EXYNOS4210, 177 + TYPE_EXYNOS5250, 178 + }; 179 + 180 + /* 181 + * struct samsung_usbphy_drvdata - driver data for various SoC variants 182 + * @cpu_type: machine identifier 183 + * @devphy_en_mask: device phy enable mask for PHY CONTROL register 184 + * @hostphy_en_mask: host phy enable mask for PHY CONTROL register 185 + * @devphy_reg_offset: offset to DEVICE PHY CONTROL register from 186 + * mapped address of system controller. 187 + * @hostphy_reg_offset: offset to HOST PHY CONTROL register from 188 + * mapped address of system controller. 189 + * 190 + * Here we have a separate mask for device type phy. 191 + * Having different masks for host and device type phy helps 192 + * in setting independent masks in case of SoCs like S5PV210, 193 + * in which PHY0 and PHY1 enable bits belong to same register 194 + * placed at position 0 and 1 respectively. 195 + * Although for newer SoCs like exynos these bits belong to 196 + * different registers altogether placed at position 0. 197 + */ 198 + struct samsung_usbphy_drvdata { 199 + int cpu_type; 200 + int devphy_en_mask; 201 + int hostphy_en_mask; 202 + u32 devphy_reg_offset; 203 + u32 hostphy_reg_offset; 204 + }; 205 + 206 + /* 207 + * struct samsung_usbphy - transceiver driver state 208 + * @phy: transceiver structure 209 + * @plat: platform data 210 + * @dev: The parent device supplied to the probe function 211 + * @clk: usb phy clock 212 + * @regs: usb phy controller registers memory base 213 + * @pmuregs: USB device PHY_CONTROL register memory base 214 + * @sysreg: USB2.0 PHY_CFG register memory base 215 + * @ref_clk_freq: reference clock frequency selection 216 + * @drv_data: driver data available for different SoCs 217 + * @phy_type: Samsung SoCs specific phy types: #HOST 218 + * #DEVICE 219 + * @phy_usage: usage count for phy 220 + * @lock: lock for phy operations 221 + */ 222 + struct samsung_usbphy { 223 + struct usb_phy phy; 224 + struct samsung_usbphy_data *plat; 225 + struct device *dev; 226 + struct clk *clk; 227 + void __iomem *regs; 228 + void __iomem *pmuregs; 229 + void __iomem *sysreg; 230 + int ref_clk_freq; 231 + const struct samsung_usbphy_drvdata *drv_data; 232 + enum samsung_usb_phy_type phy_type; 233 + atomic_t phy_usage; 234 + spinlock_t lock; 235 + }; 236 + 237 + #define phy_to_sphy(x) container_of((x), struct samsung_usbphy, phy) 238 + 239 + int samsung_usbphy_set_host(struct usb_otg *otg, struct usb_bus *host) 240 + { 241 + if (!otg) 242 + return -ENODEV; 243 + 244 + if (!otg->host) 245 + otg->host = host; 246 + 247 + return 0; 248 + } 249 + 250 + static int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy) 251 + { 252 + struct device_node *usbphy_sys; 253 + 254 + /* Getting node for system controller interface for usb-phy */ 255 + usbphy_sys = of_get_child_by_name(sphy->dev->of_node, "usbphy-sys"); 256 + if (!usbphy_sys) { 257 + dev_err(sphy->dev, "No sys-controller interface for usb-phy\n"); 258 + return -ENODEV; 259 + } 260 + 261 + sphy->pmuregs = of_iomap(usbphy_sys, 0); 262 + 263 + if (sphy->pmuregs == NULL) { 264 + dev_err(sphy->dev, "Can't get usb-phy pmu control register\n"); 265 + goto err0; 266 + } 267 + 268 + sphy->sysreg = of_iomap(usbphy_sys, 1); 269 + 270 + /* 271 + * Not returning error code here, since this situation is not fatal. 272 + * Few SoCs may not have this switch available 273 + */ 274 + if (sphy->sysreg == NULL) 275 + dev_warn(sphy->dev, "Can't get usb-phy sysreg cfg register\n"); 276 + 277 + of_node_put(usbphy_sys); 278 + 279 + return 0; 280 + 281 + err0: 282 + of_node_put(usbphy_sys); 283 + return -ENXIO; 284 + } 285 + 286 + /* 287 + * Set isolation here for phy. 288 + * Here 'on = true' would mean USB PHY block is isolated, hence 289 + * de-activated and vice-versa. 290 + */ 291 + static void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on) 292 + { 293 + void __iomem *reg = NULL; 294 + u32 reg_val; 295 + u32 en_mask = 0; 296 + 297 + if (!sphy->pmuregs) { 298 + dev_warn(sphy->dev, "Can't set pmu isolation\n"); 299 + return; 300 + } 301 + 302 + switch (sphy->drv_data->cpu_type) { 303 + case TYPE_S3C64XX: 304 + /* 305 + * Do nothing: We will add here once S3C64xx goes for DT support 306 + */ 307 + break; 308 + case TYPE_EXYNOS4210: 309 + /* 310 + * Fall through since exynos4210 and exynos5250 have similar 311 + * register architecture: two separate registers for host and 312 + * device phy control with enable bit at position 0. 313 + */ 314 + case TYPE_EXYNOS5250: 315 + if (sphy->phy_type == USB_PHY_TYPE_DEVICE) { 316 + reg = sphy->pmuregs + 317 + sphy->drv_data->devphy_reg_offset; 318 + en_mask = sphy->drv_data->devphy_en_mask; 319 + } else if (sphy->phy_type == USB_PHY_TYPE_HOST) { 320 + reg = sphy->pmuregs + 321 + sphy->drv_data->hostphy_reg_offset; 322 + en_mask = sphy->drv_data->hostphy_en_mask; 323 + } 324 + break; 325 + default: 326 + dev_err(sphy->dev, "Invalid SoC type\n"); 327 + return; 328 + } 329 + 330 + reg_val = readl(reg); 331 + 332 + if (on) 333 + reg_val &= ~en_mask; 334 + else 335 + reg_val |= en_mask; 336 + 337 + writel(reg_val, reg); 338 + } 339 + 340 + /* 341 + * Configure the mode of working of usb-phy here: HOST/DEVICE. 342 + */ 343 + static void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy) 344 + { 345 + u32 reg; 346 + 347 + if (!sphy->sysreg) { 348 + dev_warn(sphy->dev, "Can't configure specified phy mode\n"); 349 + return; 350 + } 351 + 352 + reg = readl(sphy->sysreg); 353 + 354 + if (sphy->phy_type == USB_PHY_TYPE_DEVICE) 355 + reg &= ~EXYNOS_USB20PHY_CFG_HOST_LINK; 356 + else if (sphy->phy_type == USB_PHY_TYPE_HOST) 357 + reg |= EXYNOS_USB20PHY_CFG_HOST_LINK; 358 + 359 + writel(reg, sphy->sysreg); 360 + } 361 + 362 + /* 363 + * PHYs are different for USB Device and USB Host. 364 + * This make sure that correct PHY type is selected before 365 + * any operation on PHY. 366 + */ 367 + static int samsung_usbphy_set_type(struct usb_phy *phy, 368 + enum samsung_usb_phy_type phy_type) 369 + { 370 + struct samsung_usbphy *sphy = phy_to_sphy(phy); 371 + 372 + sphy->phy_type = phy_type; 373 + 374 + return 0; 375 + } 376 + 377 + /* 378 + * Returns reference clock frequency selection value 379 + */ 380 + static int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy) 381 + { 382 + struct clk *ref_clk; 383 + int refclk_freq = 0; 384 + 385 + /* 386 + * In exynos5250 USB host and device PHY use 387 + * external crystal clock XXTI 388 + */ 389 + if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) 390 + ref_clk = clk_get(sphy->dev, "ext_xtal"); 391 + else 392 + ref_clk = clk_get(sphy->dev, "xusbxti"); 393 + if (IS_ERR(ref_clk)) { 394 + dev_err(sphy->dev, "Failed to get reference clock\n"); 395 + return PTR_ERR(ref_clk); 396 + } 397 + 398 + if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) { 399 + /* set clock frequency for PLL */ 400 + switch (clk_get_rate(ref_clk)) { 401 + case 9600 * KHZ: 402 + refclk_freq = FSEL_CLKSEL_9600K; 403 + break; 404 + case 10 * MHZ: 405 + refclk_freq = FSEL_CLKSEL_10M; 406 + break; 407 + case 12 * MHZ: 408 + refclk_freq = FSEL_CLKSEL_12M; 409 + break; 410 + case 19200 * KHZ: 411 + refclk_freq = FSEL_CLKSEL_19200K; 412 + break; 413 + case 20 * MHZ: 414 + refclk_freq = FSEL_CLKSEL_20M; 415 + break; 416 + case 50 * MHZ: 417 + refclk_freq = FSEL_CLKSEL_50M; 418 + break; 419 + case 24 * MHZ: 420 + default: 421 + /* default reference clock */ 422 + refclk_freq = FSEL_CLKSEL_24M; 423 + break; 424 + } 425 + } else { 426 + switch (clk_get_rate(ref_clk)) { 427 + case 12 * MHZ: 428 + refclk_freq = PHYCLK_CLKSEL_12M; 429 + break; 430 + case 24 * MHZ: 431 + refclk_freq = PHYCLK_CLKSEL_24M; 432 + break; 433 + case 48 * MHZ: 434 + refclk_freq = PHYCLK_CLKSEL_48M; 435 + break; 436 + default: 437 + if (sphy->drv_data->cpu_type == TYPE_S3C64XX) 438 + refclk_freq = PHYCLK_CLKSEL_48M; 439 + else 440 + refclk_freq = PHYCLK_CLKSEL_24M; 441 + break; 442 + } 443 + } 444 + clk_put(ref_clk); 445 + 446 + return refclk_freq; 447 + } 448 + 449 + static bool exynos5_phyhost_is_on(void *regs) 450 + { 451 + u32 reg; 452 + 453 + reg = readl(regs + EXYNOS5_PHY_HOST_CTRL0); 454 + 455 + return !(reg & HOST_CTRL0_SIDDQ); 456 + } 457 + 458 + static void samsung_exynos5_usbphy_enable(struct samsung_usbphy *sphy) 459 + { 460 + void __iomem *regs = sphy->regs; 461 + u32 phyclk = sphy->ref_clk_freq; 462 + u32 phyhost; 463 + u32 phyotg; 464 + u32 phyhsic; 465 + u32 ehcictrl; 466 + u32 ohcictrl; 467 + 468 + /* 469 + * phy_usage helps in keeping usage count for phy 470 + * so that the first consumer enabling the phy is also 471 + * the last consumer to disable it. 472 + */ 473 + 474 + atomic_inc(&sphy->phy_usage); 475 + 476 + if (exynos5_phyhost_is_on(regs)) { 477 + dev_info(sphy->dev, "Already power on PHY\n"); 478 + return; 479 + } 480 + 481 + /* Host configuration */ 482 + phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); 483 + 484 + /* phy reference clock configuration */ 485 + phyhost &= ~HOST_CTRL0_FSEL_MASK; 486 + phyhost |= HOST_CTRL0_FSEL(phyclk); 487 + 488 + /* host phy reset */ 489 + phyhost &= ~(HOST_CTRL0_PHYSWRST | 490 + HOST_CTRL0_PHYSWRSTALL | 491 + HOST_CTRL0_SIDDQ | 492 + /* Enable normal mode of operation */ 493 + HOST_CTRL0_FORCESUSPEND | 494 + HOST_CTRL0_FORCESLEEP); 495 + 496 + /* Link reset */ 497 + phyhost |= (HOST_CTRL0_LINKSWRST | 498 + HOST_CTRL0_UTMISWRST | 499 + /* COMMON Block configuration during suspend */ 500 + HOST_CTRL0_COMMONON_N); 501 + writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); 502 + udelay(10); 503 + phyhost &= ~(HOST_CTRL0_LINKSWRST | 504 + HOST_CTRL0_UTMISWRST); 505 + writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); 506 + 507 + /* OTG configuration */ 508 + phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS); 509 + 510 + /* phy reference clock configuration */ 511 + phyotg &= ~OTG_SYS_FSEL_MASK; 512 + phyotg |= OTG_SYS_FSEL(phyclk); 513 + 514 + /* Enable normal mode of operation */ 515 + phyotg &= ~(OTG_SYS_FORCESUSPEND | 516 + OTG_SYS_SIDDQ_UOTG | 517 + OTG_SYS_FORCESLEEP | 518 + OTG_SYS_REFCLKSEL_MASK | 519 + /* COMMON Block configuration during suspend */ 520 + OTG_SYS_COMMON_ON); 521 + 522 + /* OTG phy & link reset */ 523 + phyotg |= (OTG_SYS_PHY0_SWRST | 524 + OTG_SYS_LINKSWRST_UOTG | 525 + OTG_SYS_PHYLINK_SWRESET | 526 + OTG_SYS_OTGDISABLE | 527 + /* Set phy refclk */ 528 + OTG_SYS_REFCLKSEL_CLKCORE); 529 + 530 + writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); 531 + udelay(10); 532 + phyotg &= ~(OTG_SYS_PHY0_SWRST | 533 + OTG_SYS_LINKSWRST_UOTG | 534 + OTG_SYS_PHYLINK_SWRESET); 535 + writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); 536 + 537 + /* HSIC phy configuration */ 538 + phyhsic = (HSIC_CTRL_REFCLKDIV_12 | 539 + HSIC_CTRL_REFCLKSEL | 540 + HSIC_CTRL_PHYSWRST); 541 + writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); 542 + writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); 543 + udelay(10); 544 + phyhsic &= ~HSIC_CTRL_PHYSWRST; 545 + writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); 546 + writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); 547 + 548 + udelay(80); 549 + 550 + /* enable EHCI DMA burst */ 551 + ehcictrl = readl(regs + EXYNOS5_PHY_HOST_EHCICTRL); 552 + ehcictrl |= (HOST_EHCICTRL_ENAINCRXALIGN | 553 + HOST_EHCICTRL_ENAINCR4 | 554 + HOST_EHCICTRL_ENAINCR8 | 555 + HOST_EHCICTRL_ENAINCR16); 556 + writel(ehcictrl, regs + EXYNOS5_PHY_HOST_EHCICTRL); 557 + 558 + /* set ohci_suspend_on_n */ 559 + ohcictrl = readl(regs + EXYNOS5_PHY_HOST_OHCICTRL); 560 + ohcictrl |= HOST_OHCICTRL_SUSPLGCY; 561 + writel(ohcictrl, regs + EXYNOS5_PHY_HOST_OHCICTRL); 562 + } 563 + 564 + static void samsung_usbphy_enable(struct samsung_usbphy *sphy) 565 + { 566 + void __iomem *regs = sphy->regs; 567 + u32 phypwr; 568 + u32 phyclk; 569 + u32 rstcon; 570 + 571 + /* set clock frequency for PLL */ 572 + phyclk = sphy->ref_clk_freq; 573 + phypwr = readl(regs + SAMSUNG_PHYPWR); 574 + rstcon = readl(regs + SAMSUNG_RSTCON); 575 + 576 + switch (sphy->drv_data->cpu_type) { 577 + case TYPE_S3C64XX: 578 + phyclk &= ~PHYCLK_COMMON_ON_N; 579 + phypwr &= ~PHYPWR_NORMAL_MASK; 580 + rstcon |= RSTCON_SWRST; 581 + break; 582 + case TYPE_EXYNOS4210: 583 + phypwr &= ~PHYPWR_NORMAL_MASK_PHY0; 584 + rstcon |= RSTCON_SWRST; 585 + default: 586 + break; 587 + } 588 + 589 + writel(phyclk, regs + SAMSUNG_PHYCLK); 590 + /* Configure PHY0 for normal operation*/ 591 + writel(phypwr, regs + SAMSUNG_PHYPWR); 592 + /* reset all ports of PHY and Link */ 593 + writel(rstcon, regs + SAMSUNG_RSTCON); 594 + udelay(10); 595 + rstcon &= ~RSTCON_SWRST; 596 + writel(rstcon, regs + SAMSUNG_RSTCON); 597 + } 598 + 599 + static void samsung_exynos5_usbphy_disable(struct samsung_usbphy *sphy) 600 + { 601 + void __iomem *regs = sphy->regs; 602 + u32 phyhost; 603 + u32 phyotg; 604 + u32 phyhsic; 605 + 606 + if (atomic_dec_return(&sphy->phy_usage) > 0) { 607 + dev_info(sphy->dev, "still being used\n"); 608 + return; 609 + } 610 + 611 + phyhsic = (HSIC_CTRL_REFCLKDIV_12 | 612 + HSIC_CTRL_REFCLKSEL | 613 + HSIC_CTRL_SIDDQ | 614 + HSIC_CTRL_FORCESLEEP | 615 + HSIC_CTRL_FORCESUSPEND); 616 + writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); 617 + writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); 618 + 619 + phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); 620 + phyhost |= (HOST_CTRL0_SIDDQ | 621 + HOST_CTRL0_FORCESUSPEND | 622 + HOST_CTRL0_FORCESLEEP | 623 + HOST_CTRL0_PHYSWRST | 624 + HOST_CTRL0_PHYSWRSTALL); 625 + writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); 626 + 627 + phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS); 628 + phyotg |= (OTG_SYS_FORCESUSPEND | 629 + OTG_SYS_SIDDQ_UOTG | 630 + OTG_SYS_FORCESLEEP); 631 + writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); 632 + } 633 + 634 + static void samsung_usbphy_disable(struct samsung_usbphy *sphy) 635 + { 636 + void __iomem *regs = sphy->regs; 637 + u32 phypwr; 638 + 639 + phypwr = readl(regs + SAMSUNG_PHYPWR); 640 + 641 + switch (sphy->drv_data->cpu_type) { 642 + case TYPE_S3C64XX: 643 + phypwr |= PHYPWR_NORMAL_MASK; 644 + break; 645 + case TYPE_EXYNOS4210: 646 + phypwr |= PHYPWR_NORMAL_MASK_PHY0; 647 + default: 648 + break; 649 + } 650 + 651 + /* Disable analog and otg block power */ 652 + writel(phypwr, regs + SAMSUNG_PHYPWR); 653 + } 654 + 655 + /* 656 + * The function passed to the usb driver for phy initialization 657 + */ 658 + static int samsung_usbphy_init(struct usb_phy *phy) 659 + { 660 + struct samsung_usbphy *sphy; 661 + struct usb_bus *host = NULL; 662 + unsigned long flags; 663 + int ret = 0; 664 + 665 + sphy = phy_to_sphy(phy); 666 + 667 + host = phy->otg->host; 668 + 669 + /* Enable the phy clock */ 670 + ret = clk_prepare_enable(sphy->clk); 671 + if (ret) { 672 + dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); 673 + return ret; 674 + } 675 + 676 + spin_lock_irqsave(&sphy->lock, flags); 677 + 678 + if (host) { 679 + /* setting default phy-type for USB 2.0 */ 680 + if (!strstr(dev_name(host->controller), "ehci") || 681 + !strstr(dev_name(host->controller), "ohci")) 682 + samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST); 683 + } else { 684 + samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); 685 + } 686 + 687 + /* Disable phy isolation */ 688 + if (sphy->plat && sphy->plat->pmu_isolation) 689 + sphy->plat->pmu_isolation(false); 690 + else 691 + samsung_usbphy_set_isolation(sphy, false); 692 + 693 + /* Selecting Host/OTG mode; After reset USB2.0PHY_CFG: HOST */ 694 + samsung_usbphy_cfg_sel(sphy); 695 + 696 + /* Initialize usb phy registers */ 697 + if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) 698 + samsung_exynos5_usbphy_enable(sphy); 699 + else 700 + samsung_usbphy_enable(sphy); 701 + 702 + spin_unlock_irqrestore(&sphy->lock, flags); 703 + 704 + /* Disable the phy clock */ 705 + clk_disable_unprepare(sphy->clk); 706 + 707 + return ret; 708 + } 709 + 710 + /* 711 + * The function passed to the usb driver for phy shutdown 712 + */ 713 + static void samsung_usbphy_shutdown(struct usb_phy *phy) 714 + { 715 + struct samsung_usbphy *sphy; 716 + struct usb_bus *host = NULL; 717 + unsigned long flags; 718 + 719 + sphy = phy_to_sphy(phy); 720 + 721 + host = phy->otg->host; 722 + 723 + if (clk_prepare_enable(sphy->clk)) { 724 + dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); 725 + return; 726 + } 727 + 728 + spin_lock_irqsave(&sphy->lock, flags); 729 + 730 + if (host) { 731 + /* setting default phy-type for USB 2.0 */ 732 + if (!strstr(dev_name(host->controller), "ehci") || 733 + !strstr(dev_name(host->controller), "ohci")) 734 + samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST); 735 + } else { 736 + samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); 737 + } 738 + 739 + /* De-initialize usb phy registers */ 740 + if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) 741 + samsung_exynos5_usbphy_disable(sphy); 742 + else 743 + samsung_usbphy_disable(sphy); 744 + 745 + /* Enable phy isolation */ 746 + if (sphy->plat && sphy->plat->pmu_isolation) 747 + sphy->plat->pmu_isolation(true); 748 + else 749 + samsung_usbphy_set_isolation(sphy, true); 750 + 751 + spin_unlock_irqrestore(&sphy->lock, flags); 752 + 753 + clk_disable_unprepare(sphy->clk); 754 + } 755 + 756 + static const struct of_device_id samsung_usbphy_dt_match[]; 757 + 758 + static inline const struct samsung_usbphy_drvdata 759 + *samsung_usbphy_get_driver_data(struct platform_device *pdev) 760 + { 761 + if (pdev->dev.of_node) { 762 + const struct of_device_id *match; 763 + match = of_match_node(samsung_usbphy_dt_match, 764 + pdev->dev.of_node); 765 + return match->data; 766 + } 767 + 768 + return (struct samsung_usbphy_drvdata *) 769 + platform_get_device_id(pdev)->driver_data; 770 + } 771 + 772 + static int samsung_usbphy_probe(struct platform_device *pdev) 773 + { 774 + struct samsung_usbphy *sphy; 775 + struct usb_otg *otg; 776 + struct samsung_usbphy_data *pdata = pdev->dev.platform_data; 777 + const struct samsung_usbphy_drvdata *drv_data; 778 + struct device *dev = &pdev->dev; 779 + struct resource *phy_mem; 780 + void __iomem *phy_base; 781 + struct clk *clk; 782 + int ret; 783 + 784 + phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 785 + if (!phy_mem) { 786 + dev_err(dev, "%s: missing mem resource\n", __func__); 787 + return -ENODEV; 788 + } 789 + 790 + phy_base = devm_request_and_ioremap(dev, phy_mem); 791 + if (!phy_base) { 792 + dev_err(dev, "%s: register mapping failed\n", __func__); 793 + return -ENXIO; 794 + } 795 + 796 + sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL); 797 + if (!sphy) 798 + return -ENOMEM; 799 + 800 + otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL); 801 + if (!otg) 802 + return -ENOMEM; 803 + 804 + drv_data = samsung_usbphy_get_driver_data(pdev); 805 + 806 + if (drv_data->cpu_type == TYPE_EXYNOS5250) 807 + clk = devm_clk_get(dev, "usbhost"); 808 + else 809 + clk = devm_clk_get(dev, "otg"); 810 + 811 + if (IS_ERR(clk)) { 812 + dev_err(dev, "Failed to get otg clock\n"); 813 + return PTR_ERR(clk); 814 + } 815 + 816 + sphy->dev = dev; 817 + 818 + if (dev->of_node) { 819 + ret = samsung_usbphy_parse_dt(sphy); 820 + if (ret < 0) 821 + return ret; 822 + } else { 823 + if (!pdata) { 824 + dev_err(dev, "no platform data specified\n"); 825 + return -EINVAL; 826 + } 827 + } 828 + 829 + sphy->plat = pdata; 830 + sphy->regs = phy_base; 831 + sphy->clk = clk; 832 + sphy->drv_data = drv_data; 833 + sphy->phy.dev = sphy->dev; 834 + sphy->phy.label = "samsung-usbphy"; 835 + sphy->phy.init = samsung_usbphy_init; 836 + sphy->phy.shutdown = samsung_usbphy_shutdown; 837 + sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); 838 + 839 + sphy->phy.otg = otg; 840 + sphy->phy.otg->phy = &sphy->phy; 841 + sphy->phy.otg->set_host = samsung_usbphy_set_host; 842 + 843 + spin_lock_init(&sphy->lock); 844 + 845 + platform_set_drvdata(pdev, sphy); 846 + 847 + return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB2); 848 + } 849 + 850 + static int samsung_usbphy_remove(struct platform_device *pdev) 851 + { 852 + struct samsung_usbphy *sphy = platform_get_drvdata(pdev); 853 + 854 + usb_remove_phy(&sphy->phy); 855 + 856 + if (sphy->pmuregs) 857 + iounmap(sphy->pmuregs); 858 + if (sphy->sysreg) 859 + iounmap(sphy->sysreg); 860 + 861 + return 0; 862 + } 863 + 864 + static const struct samsung_usbphy_drvdata usbphy_s3c64xx = { 865 + .cpu_type = TYPE_S3C64XX, 866 + .devphy_en_mask = S3C64XX_USBPHY_ENABLE, 867 + }; 868 + 869 + static const struct samsung_usbphy_drvdata usbphy_exynos4 = { 870 + .cpu_type = TYPE_EXYNOS4210, 871 + .devphy_en_mask = EXYNOS_USBPHY_ENABLE, 872 + .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, 873 + }; 874 + 875 + static struct samsung_usbphy_drvdata usbphy_exynos5 = { 876 + .cpu_type = TYPE_EXYNOS5250, 877 + .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, 878 + .hostphy_reg_offset = EXYNOS_USBHOST_PHY_CTRL_OFFSET, 879 + }; 880 + 881 + #ifdef CONFIG_OF 882 + static const struct of_device_id samsung_usbphy_dt_match[] = { 883 + { 884 + .compatible = "samsung,s3c64xx-usbphy", 885 + .data = &usbphy_s3c64xx, 886 + }, { 887 + .compatible = "samsung,exynos4210-usbphy", 888 + .data = &usbphy_exynos4, 889 + }, { 890 + .compatible = "samsung,exynos5250-usbphy", 891 + .data = &usbphy_exynos5 892 + }, 893 + {}, 894 + }; 895 + MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match); 896 + #endif 897 + 898 + static struct platform_device_id samsung_usbphy_driver_ids[] = { 899 + { 900 + .name = "s3c64xx-usbphy", 901 + .driver_data = (unsigned long)&usbphy_s3c64xx, 902 + }, { 903 + .name = "exynos4210-usbphy", 904 + .driver_data = (unsigned long)&usbphy_exynos4, 905 + }, { 906 + .name = "exynos5250-usbphy", 907 + .driver_data = (unsigned long)&usbphy_exynos5, 908 + }, 909 + {}, 910 + }; 911 + 912 + MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids); 913 + 914 + static struct platform_driver samsung_usbphy_driver = { 915 + .probe = samsung_usbphy_probe, 916 + .remove = samsung_usbphy_remove, 917 + .id_table = samsung_usbphy_driver_ids, 918 + .driver = { 919 + .name = "samsung-usbphy", 920 + .owner = THIS_MODULE, 921 + .of_match_table = of_match_ptr(samsung_usbphy_dt_match), 922 + }, 923 + }; 924 + 925 + module_platform_driver(samsung_usbphy_driver); 926 + 927 + MODULE_DESCRIPTION("Samsung USB phy controller"); 928 + MODULE_AUTHOR("Praveen Paneri <p.paneri@samsung.com>"); 929 + MODULE_LICENSE("GPL"); 930 + MODULE_ALIAS("platform:samsung-usbphy");
+1 -1
drivers/usb/renesas_usbhs/Kconfig
··· 4 4 5 5 config USB_RENESAS_USBHS 6 6 tristate 'Renesas USBHS controller' 7 - depends on USB && USB_GADGET 7 + depends on USB && USB_GADGET && GENERIC_HARDIRQS 8 8 default n 9 9 help 10 10 Renesas USBHS is a discrete USB host and peripheral controller chip
+1 -1
drivers/usb/renesas_usbhs/mod_gadget.c
··· 900 900 return 0; 901 901 } 902 902 903 - static struct usb_gadget_ops usbhsg_gadget_ops = { 903 + static const struct usb_gadget_ops usbhsg_gadget_ops = { 904 904 .get_frame = usbhsg_get_frame, 905 905 .set_selfpowered = usbhsg_set_selfpowered, 906 906 .udc_start = usbhsg_gadget_start,
+12
drivers/usb/serial/Kconfig
··· 647 647 To compile this driver as a module, choose M here: the 648 648 module will be called vivopay-serial. 649 649 650 + config USB_SERIAL_XSENS_MT 651 + tristate "Xsens motion tracker serial interface driver" 652 + help 653 + Say Y here if you want to use Xsens motion trackers. 654 + 655 + This driver supports the new generation of motion trackers 656 + by Xsens. Older devices can be accessed using the FTDI_SIO 657 + driver. 658 + 659 + To compile this driver as a module, choose M here: the 660 + module will be called xsens_mt. 661 + 650 662 config USB_SERIAL_ZIO 651 663 tristate "ZIO Motherboard USB serial interface driver" 652 664 help
+1
drivers/usb/serial/Makefile
··· 61 61 obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o 62 62 obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o 63 63 obj-$(CONFIG_USB_SERIAL_VIVOPAY_SERIAL) += vivopay-serial.o 64 + obj-$(CONFIG_USB_SERIAL_XSENS_MT) += xsens_mt.o 64 65 obj-$(CONFIG_USB_SERIAL_ZIO) += zio.o 65 66 obj-$(CONFIG_USB_SERIAL_ZTE) += zte_ev.o
+9 -11
drivers/usb/serial/ftdi_sio.c
··· 1886 1886 { 1887 1887 struct ftdi_private *priv = usb_get_serial_port_data(port); 1888 1888 1889 - mutex_lock(&port->serial->disc_mutex); 1890 - if (!port->serial->disconnected) { 1891 - /* Disable flow control */ 1892 - if (!on && usb_control_msg(port->serial->dev, 1889 + /* Disable flow control */ 1890 + if (!on) { 1891 + if (usb_control_msg(port->serial->dev, 1893 1892 usb_sndctrlpipe(port->serial->dev, 0), 1894 1893 FTDI_SIO_SET_FLOW_CTRL_REQUEST, 1895 1894 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 1896 1895 0, priv->interface, NULL, 0, 1897 1896 WDR_TIMEOUT) < 0) { 1898 - dev_err(&port->dev, "error from flowcontrol urb\n"); 1897 + dev_err(&port->dev, "error from flowcontrol urb\n"); 1899 1898 } 1900 - /* drop RTS and DTR */ 1901 - if (on) 1902 - set_mctrl(port, TIOCM_DTR | TIOCM_RTS); 1903 - else 1904 - clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 1905 1899 } 1906 - mutex_unlock(&port->serial->disc_mutex); 1900 + /* drop RTS and DTR */ 1901 + if (on) 1902 + set_mctrl(port, TIOCM_DTR | TIOCM_RTS); 1903 + else 1904 + clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 1907 1905 } 1908 1906 1909 1907 /*
+22 -67
drivers/usb/serial/io_ti.c
··· 521 521 return bytes_left; 522 522 } 523 523 524 - static void chase_port(struct edgeport_port *port, unsigned long timeout, 525 - int flush) 526 - { 527 - int baud_rate; 528 - struct tty_struct *tty = tty_port_tty_get(&port->port->port); 529 - struct usb_serial *serial = port->port->serial; 530 - wait_queue_t wait; 531 - unsigned long flags; 532 - 533 - if (!tty) 534 - return; 535 - 536 - if (!timeout) 537 - timeout = (HZ * EDGE_CLOSING_WAIT)/100; 538 - 539 - /* wait for data to drain from the buffer */ 540 - spin_lock_irqsave(&port->ep_lock, flags); 541 - init_waitqueue_entry(&wait, current); 542 - add_wait_queue(&tty->write_wait, &wait); 543 - for (;;) { 544 - set_current_state(TASK_INTERRUPTIBLE); 545 - if (kfifo_len(&port->write_fifo) == 0 546 - || timeout == 0 || signal_pending(current) 547 - || serial->disconnected) 548 - /* disconnect */ 549 - break; 550 - spin_unlock_irqrestore(&port->ep_lock, flags); 551 - timeout = schedule_timeout(timeout); 552 - spin_lock_irqsave(&port->ep_lock, flags); 553 - } 554 - set_current_state(TASK_RUNNING); 555 - remove_wait_queue(&tty->write_wait, &wait); 556 - if (flush) 557 - kfifo_reset_out(&port->write_fifo); 558 - spin_unlock_irqrestore(&port->ep_lock, flags); 559 - tty_kref_put(tty); 560 - 561 - /* wait for data to drain from the device */ 562 - timeout += jiffies; 563 - while ((long)(jiffies - timeout) < 0 && !signal_pending(current) 564 - && !serial->disconnected) { 565 - /* not disconnected */ 566 - if (!tx_active(port)) 567 - break; 568 - msleep(10); 569 - } 570 - 571 - /* disconnected */ 572 - if (serial->disconnected) 573 - return; 574 - 575 - /* wait one more character time, based on baud rate */ 576 - /* (tx_active doesn't seem to wait for the last byte) */ 577 - baud_rate = port->baud_rate; 578 - if (baud_rate == 0) 579 - baud_rate = 50; 580 - msleep(max(1, DIV_ROUND_UP(10000, baud_rate))); 581 - } 582 - 583 524 static int choose_config(struct usb_device *dev) 584 525 { 585 526 /* ··· 1885 1944 1886 1945 ++edge_serial->num_ports_open; 1887 1946 1947 + port->port.drain_delay = 1; 1948 + 1888 1949 goto release_es_lock; 1889 1950 1890 1951 unlink_int_urb: ··· 1902 1959 struct edgeport_serial *edge_serial; 1903 1960 struct edgeport_port *edge_port; 1904 1961 struct usb_serial *serial = port->serial; 1962 + unsigned long flags; 1905 1963 int port_number; 1906 1964 1907 1965 edge_serial = usb_get_serial_data(port->serial); ··· 1914 1970 * this flag and dump add read data */ 1915 1971 edge_port->close_pending = 1; 1916 1972 1917 - /* chase the port close and flush */ 1918 - chase_port(edge_port, (HZ * closing_wait) / 100, 1); 1919 - 1920 1973 usb_kill_urb(port->read_urb); 1921 1974 usb_kill_urb(port->write_urb); 1922 1975 edge_port->ep_write_urb_in_use = 0; 1976 + spin_lock_irqsave(&edge_port->ep_lock, flags); 1977 + kfifo_reset_out(&edge_port->write_fifo); 1978 + spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1923 1979 1924 1980 /* assuming we can still talk to the device, 1925 1981 * send a close port command to it */ ··· 2045 2101 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2046 2102 int chars = 0; 2047 2103 unsigned long flags; 2104 + int ret; 2048 2105 2049 2106 if (edge_port == NULL) 2050 - return 0; 2051 - if (edge_port->close_pending == 1) 2052 2107 return 0; 2053 2108 2054 2109 spin_lock_irqsave(&edge_port->ep_lock, flags); 2055 2110 chars = kfifo_len(&edge_port->write_fifo); 2056 2111 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2112 + 2113 + if (!chars) { 2114 + ret = tx_active(edge_port); 2115 + if (ret > 0) 2116 + chars = ret; 2117 + } 2057 2118 2058 2119 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); 2059 2120 return chars; ··· 2397 2448 struct serial_struct __user *retinfo) 2398 2449 { 2399 2450 struct serial_struct tmp; 2451 + unsigned cwait; 2400 2452 2401 2453 if (!retinfo) 2402 2454 return -EFAULT; 2455 + 2456 + cwait = edge_port->port->port.closing_wait; 2457 + if (cwait != ASYNC_CLOSING_WAIT_NONE) 2458 + cwait = jiffies_to_msecs(closing_wait) / 10; 2403 2459 2404 2460 memset(&tmp, 0, sizeof(tmp)); 2405 2461 ··· 2416 2462 tmp.xmit_fifo_size = edge_port->port->bulk_out_size; 2417 2463 tmp.baud_base = 9600; 2418 2464 tmp.close_delay = 5*HZ; 2419 - tmp.closing_wait = closing_wait; 2465 + tmp.closing_wait = cwait; 2420 2466 2421 2467 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 2422 2468 return -EFAULT; ··· 2471 2517 int status; 2472 2518 int bv = 0; /* Off */ 2473 2519 2474 - /* chase the port close */ 2475 - chase_port(edge_port, 0, 0); 2520 + tty_wait_until_sent(tty, 0); 2476 2521 2477 2522 if (break_state == -1) 2478 2523 bv = 1; /* On */ ··· 2543 2590 kfree(edge_port); 2544 2591 return ret; 2545 2592 } 2593 + 2594 + port->port.closing_wait = msecs_to_jiffies(closing_wait * 10); 2546 2595 2547 2596 return 0; 2548 2597 }
+2 -2
drivers/usb/serial/keyspan.c
··· 298 298 endpoint = usb_pipeendpoint(urb->pipe); 299 299 300 300 if (status) { 301 - dev_dbg(&urb->dev->dev,"%s - nonzero status: %x on endpoint %d.\n", 301 + dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n", 302 302 __func__, status, endpoint); 303 303 return; 304 304 } ··· 532 532 533 533 /* 534 534 dev_dbg(&urb->dev->dev, 535 - "%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__, 535 + "%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__, 536 536 data[0], data[1], data[2], data[3], data[4], data[5], 537 537 data[6], data[7], data[8], data[9], data[10], data[11]); 538 538 */
+9 -13
drivers/usb/serial/mct_u232.c
··· 499 499 unsigned int control_state; 500 500 struct mct_u232_private *priv = usb_get_serial_port_data(port); 501 501 502 - mutex_lock(&port->serial->disc_mutex); 503 - if (!port->serial->disconnected) { 504 - /* drop DTR and RTS */ 505 - spin_lock_irq(&priv->lock); 506 - if (on) 507 - priv->control_state |= TIOCM_DTR | TIOCM_RTS; 508 - else 509 - priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); 510 - control_state = priv->control_state; 511 - spin_unlock_irq(&priv->lock); 512 - mct_u232_set_modem_ctrl(port, control_state); 513 - } 514 - mutex_unlock(&port->serial->disc_mutex); 502 + spin_lock_irq(&priv->lock); 503 + if (on) 504 + priv->control_state |= TIOCM_DTR | TIOCM_RTS; 505 + else 506 + priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); 507 + control_state = priv->control_state; 508 + spin_unlock_irq(&priv->lock); 509 + 510 + mct_u232_set_modem_ctrl(port, control_state); 515 511 } 516 512 517 513 static void mct_u232_close(struct usb_serial_port *port)
+15 -1
drivers/usb/serial/option.c
··· 479 479 480 480 static const struct option_blacklist_info alcatel_x200_blacklist = { 481 481 .sendsetup = BIT(0) | BIT(1), 482 + .reserved = BIT(4), 482 483 }; 483 484 484 485 static const struct option_blacklist_info zte_0037_blacklist = { ··· 576 575 { USB_DEVICE(QUANTA_VENDOR_ID, QUANTA_PRODUCT_GLX) }, 577 576 { USB_DEVICE(QUANTA_VENDOR_ID, QUANTA_PRODUCT_GKE) }, 578 577 { USB_DEVICE(QUANTA_VENDOR_ID, QUANTA_PRODUCT_GLE) }, 578 + { USB_DEVICE(QUANTA_VENDOR_ID, 0xea42), 579 + .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 580 + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x1c05, USB_CLASS_COMM, 0x02, 0xff) }, 581 + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x1c23, USB_CLASS_COMM, 0x02, 0xff) }, 579 582 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E173, 0xff, 0xff, 0xff), 580 583 .driver_info = (kernel_ulong_t) &net_intf1_blacklist }, 584 + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x1441, USB_CLASS_COMM, 0x02, 0xff) }, 585 + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x1442, USB_CLASS_COMM, 0x02, 0xff) }, 581 586 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff), 582 587 .driver_info = (kernel_ulong_t) &huawei_cdc12_blacklist }, 583 588 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff), ··· 1222 1215 { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_X060S_X200), 1223 1216 .driver_info = (kernel_ulong_t)&alcatel_x200_blacklist 1224 1217 }, 1225 - { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_X220_X500D) }, 1218 + { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_X220_X500D), 1219 + .driver_info = (kernel_ulong_t)&net_intf6_blacklist }, 1220 + { USB_DEVICE(ALCATEL_VENDOR_ID, 0x0052), 1221 + .driver_info = (kernel_ulong_t)&net_intf6_blacklist }, 1222 + { USB_DEVICE(ALCATEL_VENDOR_ID, 0x00b6), 1223 + .driver_info = (kernel_ulong_t)&net_intf3_blacklist }, 1224 + { USB_DEVICE(ALCATEL_VENDOR_ID, 0x00b7), 1225 + .driver_info = (kernel_ulong_t)&net_intf5_blacklist }, 1226 1226 { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_L100V), 1227 1227 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 1228 1228 { USB_DEVICE(AIRPLUS_VENDOR_ID, AIRPLUS_PRODUCT_MCD650) },
+8 -10
drivers/usb/serial/quatech2.c
··· 945 945 struct usb_device *dev = port->serial->dev; 946 946 struct qt2_port_private *port_priv = usb_get_serial_port_data(port); 947 947 948 - mutex_lock(&port->serial->disc_mutex); 949 - if (!port->serial->disconnected) { 950 - /* Disable flow control */ 951 - if (!on && qt2_setregister(dev, port_priv->device_port, 948 + /* Disable flow control */ 949 + if (!on) { 950 + if (qt2_setregister(dev, port_priv->device_port, 952 951 UART_MCR, 0) < 0) 953 952 dev_warn(&port->dev, "error from flowcontrol urb\n"); 954 - /* drop RTS and DTR */ 955 - if (on) 956 - update_mctrl(port_priv, TIOCM_DTR | TIOCM_RTS, 0); 957 - else 958 - update_mctrl(port_priv, 0, TIOCM_DTR | TIOCM_RTS); 959 953 } 960 - mutex_unlock(&port->serial->disc_mutex); 954 + /* drop RTS and DTR */ 955 + if (on) 956 + update_mctrl(port_priv, TIOCM_DTR | TIOCM_RTS, 0); 957 + else 958 + update_mctrl(port_priv, 0, TIOCM_DTR | TIOCM_RTS); 961 959 } 962 960 963 961 static void qt2_update_msr(struct usb_serial_port *port, unsigned char *ch)
+1 -7
drivers/usb/serial/sierra.c
··· 861 861 862 862 static void sierra_dtr_rts(struct usb_serial_port *port, int on) 863 863 { 864 - struct usb_serial *serial = port->serial; 865 864 struct sierra_port_private *portdata; 866 865 867 866 portdata = usb_get_serial_port_data(port); 868 867 portdata->rts_state = on; 869 868 portdata->dtr_state = on; 870 869 871 - if (serial->dev) { 872 - mutex_lock(&serial->disc_mutex); 873 - if (!serial->disconnected) 874 - sierra_send_setup(port); 875 - mutex_unlock(&serial->disc_mutex); 876 - } 870 + sierra_send_setup(port); 877 871 } 878 872 879 873 static int sierra_startup(struct usb_serial *serial)
+8 -11
drivers/usb/serial/ssu100.c
··· 506 506 { 507 507 struct usb_device *dev = port->serial->dev; 508 508 509 - mutex_lock(&port->serial->disc_mutex); 510 - if (!port->serial->disconnected) { 511 - /* Disable flow control */ 512 - if (!on && 513 - ssu100_setregister(dev, 0, UART_MCR, 0) < 0) 509 + /* Disable flow control */ 510 + if (!on) { 511 + if (ssu100_setregister(dev, 0, UART_MCR, 0) < 0) 514 512 dev_err(&port->dev, "error from flowcontrol urb\n"); 515 - /* drop RTS and DTR */ 516 - if (on) 517 - set_mctrl(dev, TIOCM_DTR | TIOCM_RTS); 518 - else 519 - clear_mctrl(dev, TIOCM_DTR | TIOCM_RTS); 520 513 } 521 - mutex_unlock(&port->serial->disc_mutex); 514 + /* drop RTS and DTR */ 515 + if (on) 516 + set_mctrl(dev, TIOCM_DTR | TIOCM_RTS); 517 + else 518 + clear_mctrl(dev, TIOCM_DTR | TIOCM_RTS); 522 519 } 523 520 524 521 static void ssu100_update_msr(struct usb_serial_port *port, u8 msr)
+22 -6
drivers/usb/serial/usb-serial.c
··· 361 361 static int serial_chars_in_buffer(struct tty_struct *tty) 362 362 { 363 363 struct usb_serial_port *port = tty->driver_data; 364 + struct usb_serial *serial = port->serial; 365 + int count = 0; 364 366 365 367 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 366 368 369 + mutex_lock(&serial->disc_mutex); 367 370 /* if the device was unplugged then any remaining characters 368 371 fell out of the connector ;) */ 369 - if (port->serial->disconnected) 370 - return 0; 371 - /* pass on to the driver specific version of this function */ 372 - return port->serial->type->chars_in_buffer(tty); 372 + if (serial->disconnected) 373 + count = 0; 374 + else 375 + count = serial->type->chars_in_buffer(tty); 376 + mutex_unlock(&serial->disc_mutex); 377 + 378 + return count; 373 379 } 374 380 375 381 static void serial_throttle(struct tty_struct *tty) ··· 694 688 static void serial_dtr_rts(struct tty_port *port, int on) 695 689 { 696 690 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); 697 - struct usb_serial_driver *drv = p->serial->type; 691 + struct usb_serial *serial = p->serial; 692 + struct usb_serial_driver *drv = serial->type; 698 693 699 - if (drv->dtr_rts) 694 + if (!drv->dtr_rts) 695 + return; 696 + /* 697 + * Work-around bug in the tty-layer which can result in dtr_rts 698 + * being called after a disconnect (and tty_unregister_device 699 + * has returned). Remove once bug has been squashed. 700 + */ 701 + mutex_lock(&serial->disc_mutex); 702 + if (!serial->disconnected) 700 703 drv->dtr_rts(p, on); 704 + mutex_unlock(&serial->disc_mutex); 701 705 } 702 706 703 707 static const struct tty_port_operations serial_port_ops = {
+3 -5
drivers/usb/serial/usb_wwan.c
··· 38 38 39 39 void usb_wwan_dtr_rts(struct usb_serial_port *port, int on) 40 40 { 41 - struct usb_serial *serial = port->serial; 42 41 struct usb_wwan_port_private *portdata; 43 42 struct usb_wwan_intf_private *intfdata; 44 43 ··· 47 48 return; 48 49 49 50 portdata = usb_get_serial_port_data(port); 50 - mutex_lock(&serial->disc_mutex); 51 + /* FIXME: locking */ 51 52 portdata->rts_state = on; 52 53 portdata->dtr_state = on; 53 - if (serial->dev) 54 - intfdata->send_setup(port); 55 - mutex_unlock(&serial->disc_mutex); 54 + 55 + intfdata->send_setup(port); 56 56 } 57 57 EXPORT_SYMBOL(usb_wwan_dtr_rts); 58 58
+86
drivers/usb/serial/xsens_mt.c
··· 1 + /* 2 + * Xsens MT USB driver 3 + * 4 + * Copyright (C) 2013 Xsens <info@xsens.com> 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public License version 8 + * 2 as published by the Free Software Foundation. 9 + */ 10 + 11 + #include <linux/kernel.h> 12 + #include <linux/init.h> 13 + #include <linux/tty.h> 14 + #include <linux/module.h> 15 + #include <linux/usb.h> 16 + #include <linux/usb/serial.h> 17 + #include <linux/uaccess.h> 18 + 19 + #define XSENS_VID 0x2639 20 + 21 + #define MTi_10_IMU_PID 0x0001 22 + #define MTi_20_VRU_PID 0x0002 23 + #define MTi_30_AHRS_PID 0x0003 24 + 25 + #define MTi_100_IMU_PID 0x0011 26 + #define MTi_200_VRU_PID 0x0012 27 + #define MTi_300_AHRS_PID 0x0013 28 + 29 + #define MTi_G_700_GPS_INS_PID 0x0017 30 + 31 + static const struct usb_device_id id_table[] = { 32 + { USB_DEVICE(XSENS_VID, MTi_10_IMU_PID) }, 33 + { USB_DEVICE(XSENS_VID, MTi_20_VRU_PID) }, 34 + { USB_DEVICE(XSENS_VID, MTi_30_AHRS_PID) }, 35 + 36 + { USB_DEVICE(XSENS_VID, MTi_100_IMU_PID) }, 37 + { USB_DEVICE(XSENS_VID, MTi_200_VRU_PID) }, 38 + { USB_DEVICE(XSENS_VID, MTi_300_AHRS_PID) }, 39 + 40 + { USB_DEVICE(XSENS_VID, MTi_G_700_GPS_INS_PID) }, 41 + { }, 42 + }; 43 + MODULE_DEVICE_TABLE(usb, id_table); 44 + 45 + static int has_required_endpoints(const struct usb_host_interface *interface) 46 + { 47 + __u8 i; 48 + int has_bulk_in = 0; 49 + int has_bulk_out = 0; 50 + 51 + for (i = 0; i < interface->desc.bNumEndpoints; ++i) { 52 + if (usb_endpoint_is_bulk_in(&interface->endpoint[i].desc)) 53 + has_bulk_in = 1; 54 + else if (usb_endpoint_is_bulk_out(&interface->endpoint[i].desc)) 55 + has_bulk_out = 1; 56 + } 57 + 58 + return has_bulk_in && has_bulk_out; 59 + } 60 + 61 + static int xsens_mt_probe(struct usb_serial *serial, 62 + const struct usb_device_id *id) 63 + { 64 + if (!has_required_endpoints(serial->interface->cur_altsetting)) 65 + return -ENODEV; 66 + return 0; 67 + } 68 + 69 + static struct usb_serial_driver xsens_mt_device = { 70 + .driver = { 71 + .owner = THIS_MODULE, 72 + .name = "xsens_mt", 73 + }, 74 + .id_table = id_table, 75 + .num_ports = 1, 76 + 77 + .probe = xsens_mt_probe, 78 + }; 79 + 80 + static struct usb_serial_driver * const serial_drivers[] = { 81 + &xsens_mt_device, NULL 82 + }; 83 + 84 + module_usb_serial_driver(serial_drivers, id_table); 85 + 86 + MODULE_LICENSE("GPL");
+2 -2
drivers/usb/storage/initializers.c
··· 147 147 int idProduct; 148 148 149 149 idesc = &us->pusb_intf->cur_altsetting->desc; 150 - idProduct = us->pusb_dev->descriptor.idProduct; 150 + idProduct = le16_to_cpu(us->pusb_dev->descriptor.idProduct); 151 151 /* The first port is CDROM, 152 152 * means the dongle in the single port mode, 153 153 * and a switch command is required to be sent. */ ··· 169 169 int result = 0; 170 170 171 171 if (usb_stor_huawei_dongles_pid(us)) { 172 - if (us->pusb_dev->descriptor.idProduct >= 0x1446) 172 + if (le16_to_cpu(us->pusb_dev->descriptor.idProduct) >= 0x1446) 173 173 result = usb_stor_huawei_scsi_init(us); 174 174 else 175 175 result = usb_stor_huawei_feature_init(us);
+108 -16
drivers/usb/storage/uas.c
··· 66 66 DATA_OUT_URB_INFLIGHT = (1 << 10), 67 67 COMMAND_COMPLETED = (1 << 11), 68 68 COMMAND_ABORTED = (1 << 12), 69 + UNLINK_DATA_URBS = (1 << 13), 70 + IS_IN_WORK_LIST = (1 << 14), 69 71 }; 70 72 71 73 /* Overrides scsi_pointer */ ··· 84 82 static int uas_submit_urbs(struct scsi_cmnd *cmnd, 85 83 struct uas_dev_info *devinfo, gfp_t gfp); 86 84 static void uas_do_work(struct work_struct *work); 85 + static int uas_try_complete(struct scsi_cmnd *cmnd, const char *caller); 87 86 88 87 static DECLARE_WORK(uas_work, uas_do_work); 89 88 static DEFINE_SPINLOCK(uas_work_lock); 90 89 static LIST_HEAD(uas_work_list); 90 + 91 + static void uas_unlink_data_urbs(struct uas_dev_info *devinfo, 92 + struct uas_cmd_info *cmdinfo) 93 + { 94 + unsigned long flags; 95 + 96 + /* 97 + * The UNLINK_DATA_URBS flag makes sure uas_try_complete 98 + * (called by urb completion) doesn't release cmdinfo 99 + * underneath us. 100 + */ 101 + spin_lock_irqsave(&devinfo->lock, flags); 102 + cmdinfo->state |= UNLINK_DATA_URBS; 103 + spin_unlock_irqrestore(&devinfo->lock, flags); 104 + 105 + if (cmdinfo->data_in_urb) 106 + usb_unlink_urb(cmdinfo->data_in_urb); 107 + if (cmdinfo->data_out_urb) 108 + usb_unlink_urb(cmdinfo->data_out_urb); 109 + 110 + spin_lock_irqsave(&devinfo->lock, flags); 111 + cmdinfo->state &= ~UNLINK_DATA_URBS; 112 + spin_unlock_irqrestore(&devinfo->lock, flags); 113 + } 91 114 92 115 static void uas_do_work(struct work_struct *work) 93 116 { ··· 133 106 struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; 134 107 spin_lock_irqsave(&devinfo->lock, flags); 135 108 err = uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_ATOMIC); 109 + if (!err) 110 + cmdinfo->state &= ~IS_IN_WORK_LIST; 136 111 spin_unlock_irqrestore(&devinfo->lock, flags); 137 112 if (err) { 138 113 list_del(&cmdinfo->list); ··· 144 115 schedule_work(&uas_work); 145 116 } 146 117 } 118 + } 119 + 120 + static void uas_abort_work(struct uas_dev_info *devinfo) 121 + { 122 + struct uas_cmd_info *cmdinfo; 123 + struct uas_cmd_info *temp; 124 + struct list_head list; 125 + unsigned long flags; 126 + 127 + spin_lock_irq(&uas_work_lock); 128 + list_replace_init(&uas_work_list, &list); 129 + spin_unlock_irq(&uas_work_lock); 130 + 131 + spin_lock_irqsave(&devinfo->lock, flags); 132 + list_for_each_entry_safe(cmdinfo, temp, &list, list) { 133 + struct scsi_pointer *scp = (void *)cmdinfo; 134 + struct scsi_cmnd *cmnd = container_of(scp, 135 + struct scsi_cmnd, SCp); 136 + struct uas_dev_info *di = (void *)cmnd->device->hostdata; 137 + 138 + if (di == devinfo) { 139 + cmdinfo->state |= COMMAND_ABORTED; 140 + cmdinfo->state &= ~IS_IN_WORK_LIST; 141 + if (devinfo->resetting) { 142 + /* uas_stat_cmplt() will not do that 143 + * when a device reset is in 144 + * progress */ 145 + cmdinfo->state &= ~COMMAND_INFLIGHT; 146 + } 147 + uas_try_complete(cmnd, __func__); 148 + } else { 149 + /* not our uas device, relink into list */ 150 + list_del(&cmdinfo->list); 151 + spin_lock_irq(&uas_work_lock); 152 + list_add_tail(&cmdinfo->list, &uas_work_list); 153 + spin_unlock_irq(&uas_work_lock); 154 + } 155 + } 156 + spin_unlock_irqrestore(&devinfo->lock, flags); 147 157 } 148 158 149 159 static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd) ··· 236 168 struct uas_cmd_info *ci = (void *)&cmnd->SCp; 237 169 238 170 scmd_printk(KERN_INFO, cmnd, "%s %p tag %d, inflight:" 239 - "%s%s%s%s%s%s%s%s%s%s%s%s\n", 171 + "%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", 240 172 caller, cmnd, cmnd->request->tag, 241 173 (ci->state & SUBMIT_STATUS_URB) ? " s-st" : "", 242 174 (ci->state & ALLOC_DATA_IN_URB) ? " a-in" : "", ··· 249 181 (ci->state & DATA_IN_URB_INFLIGHT) ? " IN" : "", 250 182 (ci->state & DATA_OUT_URB_INFLIGHT) ? " OUT" : "", 251 183 (ci->state & COMMAND_COMPLETED) ? " done" : "", 252 - (ci->state & COMMAND_ABORTED) ? " abort" : ""); 184 + (ci->state & COMMAND_ABORTED) ? " abort" : "", 185 + (ci->state & UNLINK_DATA_URBS) ? " unlink": "", 186 + (ci->state & IS_IN_WORK_LIST) ? " work" : ""); 253 187 } 254 188 255 189 static int uas_try_complete(struct scsi_cmnd *cmnd, const char *caller) ··· 262 192 WARN_ON(!spin_is_locked(&devinfo->lock)); 263 193 if (cmdinfo->state & (COMMAND_INFLIGHT | 264 194 DATA_IN_URB_INFLIGHT | 265 - DATA_OUT_URB_INFLIGHT)) 195 + DATA_OUT_URB_INFLIGHT | 196 + UNLINK_DATA_URBS)) 266 197 return -EBUSY; 267 198 BUG_ON(cmdinfo->state & COMMAND_COMPLETED); 268 199 cmdinfo->state |= COMMAND_COMPLETED; ··· 288 217 if (err) { 289 218 spin_lock(&uas_work_lock); 290 219 list_add_tail(&cmdinfo->list, &uas_work_list); 220 + cmdinfo->state |= IS_IN_WORK_LIST; 291 221 spin_unlock(&uas_work_lock); 292 222 schedule_work(&uas_work); 293 223 } ··· 346 274 uas_sense(urb, cmnd); 347 275 if (cmnd->result != 0) { 348 276 /* cancel data transfers on error */ 349 - if (cmdinfo->state & DATA_IN_URB_INFLIGHT) { 350 - spin_unlock_irqrestore(&devinfo->lock, flags); 351 - usb_unlink_urb(cmdinfo->data_in_urb); 352 - spin_lock_irqsave(&devinfo->lock, flags); 353 - } 354 - if (cmdinfo->state & DATA_OUT_URB_INFLIGHT) { 355 - spin_unlock_irqrestore(&devinfo->lock, flags); 356 - usb_unlink_urb(cmdinfo->data_out_urb); 357 - spin_lock_irqsave(&devinfo->lock, flags); 358 - } 277 + spin_unlock_irqrestore(&devinfo->lock, flags); 278 + uas_unlink_data_urbs(devinfo, cmdinfo); 279 + spin_lock_irqsave(&devinfo->lock, flags); 359 280 } 360 281 cmdinfo->state &= ~COMMAND_INFLIGHT; 361 282 uas_try_complete(cmnd, __func__); ··· 644 579 645 580 BUILD_BUG_ON(sizeof(struct uas_cmd_info) > sizeof(struct scsi_pointer)); 646 581 582 + if (devinfo->resetting) { 583 + cmnd->result = DID_ERROR << 16; 584 + cmnd->scsi_done(cmnd); 585 + return 0; 586 + } 587 + 647 588 spin_lock_irqsave(&devinfo->lock, flags); 648 589 if (devinfo->cmnd) { 649 590 spin_unlock_irqrestore(&devinfo->lock, flags); ··· 694 623 } 695 624 spin_lock(&uas_work_lock); 696 625 list_add_tail(&cmdinfo->list, &uas_work_list); 626 + cmdinfo->state |= IS_IN_WORK_LIST; 697 627 spin_unlock(&uas_work_lock); 698 628 schedule_work(&uas_work); 699 629 } ··· 761 689 uas_log_cmd_state(cmnd, __func__); 762 690 spin_lock_irqsave(&devinfo->lock, flags); 763 691 cmdinfo->state |= COMMAND_ABORTED; 764 - spin_unlock_irqrestore(&devinfo->lock, flags); 765 - ret = uas_eh_task_mgmt(cmnd, "ABORT TASK", TMF_ABORT_TASK); 692 + if (cmdinfo->state & IS_IN_WORK_LIST) { 693 + spin_lock(&uas_work_lock); 694 + list_del(&cmdinfo->list); 695 + cmdinfo->state &= ~IS_IN_WORK_LIST; 696 + spin_unlock(&uas_work_lock); 697 + } 698 + if (cmdinfo->state & COMMAND_INFLIGHT) { 699 + spin_unlock_irqrestore(&devinfo->lock, flags); 700 + ret = uas_eh_task_mgmt(cmnd, "ABORT TASK", TMF_ABORT_TASK); 701 + } else { 702 + spin_unlock_irqrestore(&devinfo->lock, flags); 703 + uas_unlink_data_urbs(devinfo, cmdinfo); 704 + spin_lock_irqsave(&devinfo->lock, flags); 705 + uas_try_complete(cmnd, __func__); 706 + spin_unlock_irqrestore(&devinfo->lock, flags); 707 + ret = SUCCESS; 708 + } 766 709 return ret; 767 710 } 768 711 ··· 796 709 int err; 797 710 798 711 devinfo->resetting = 1; 712 + uas_abort_work(devinfo); 799 713 usb_kill_anchored_urbs(&devinfo->cmd_urbs); 800 714 usb_kill_anchored_urbs(&devinfo->sense_urbs); 801 715 usb_kill_anchored_urbs(&devinfo->data_urbs); ··· 991 903 992 904 shost->max_cmd_len = 16 + 252; 993 905 shost->max_id = 1; 906 + shost->max_lun = 256; 907 + shost->max_channel = 0; 994 908 shost->sg_tablesize = udev->bus->sg_tablesize; 995 909 996 910 devinfo->intf = intf; ··· 1044 954 struct Scsi_Host *shost = usb_get_intfdata(intf); 1045 955 struct uas_dev_info *devinfo = (void *)shost->hostdata[0]; 1046 956 1047 - scsi_remove_host(shost); 957 + devinfo->resetting = 1; 958 + uas_abort_work(devinfo); 1048 959 usb_kill_anchored_urbs(&devinfo->cmd_urbs); 1049 960 usb_kill_anchored_urbs(&devinfo->sense_urbs); 1050 961 usb_kill_anchored_urbs(&devinfo->data_urbs); 962 + scsi_remove_host(shost); 1051 963 uas_free_streams(devinfo); 1052 964 kfree(devinfo); 1053 965 }
+1 -1
drivers/usb/storage/unusual_cypress.h
··· 31 31 "Cypress ISD-300LP", 32 32 USB_SC_CYP_ATACB, USB_PR_DEVICE, NULL, 0), 33 33 34 - UNUSUAL_DEV( 0x14cd, 0x6116, 0x0000, 0x9999, 34 + UNUSUAL_DEV( 0x14cd, 0x6116, 0x0000, 0x0219, 35 35 "Super Top", 36 36 "USB 2.0 SATA BRIDGE", 37 37 USB_SC_CYP_ATACB, USB_PR_DEVICE, NULL, 0),
+3
drivers/usb/storage/usb.c
··· 988 988 if (us->fflags & US_FL_SINGLE_LUN) 989 989 us->max_lun = 0; 990 990 991 + if (!(us->fflags & US_FL_SCM_MULT_TARG)) 992 + us_to_host(us)->max_id = 1; 993 + 991 994 /* Find the endpoints and calculate pipe values */ 992 995 result = get_pipes(us); 993 996 if (result)
+3 -3
drivers/usb/wusbcore/wa-xfer.c
··· 695 695 cnt--; 696 696 error_seg_kzalloc: 697 697 /* use the fact that cnt is left at were it failed */ 698 - for (; cnt > 0; cnt--) { 699 - if (xfer->is_inbound == 0) 700 - kfree(xfer->seg[cnt]->dto_urb); 698 + for (; cnt >= 0; cnt--) { 699 + if (xfer->seg[cnt] && xfer->is_inbound == 0) 700 + usb_free_urb(xfer->seg[cnt]->dto_urb); 701 701 kfree(xfer->seg[cnt]); 702 702 } 703 703 error_segs_kzalloc:
+27
include/linux/platform_data/samsung-usbphy.h
··· 1 + /* 2 + * Copyright (C) 2012 Samsung Electronics Co.Ltd 3 + * http://www.samsung.com/ 4 + * Author: Praveen Paneri <p.paneri@samsung.com> 5 + * 6 + * Defines platform data for samsung usb phy driver. 7 + * 8 + * This program is free software; you can redistribute it and/or modify it 9 + * under the terms of the GNU General Public License as published by the 10 + * Free Software Foundation; either version 2 of the License, or (at your 11 + * option) any later version. 12 + */ 13 + 14 + #ifndef __SAMSUNG_USBPHY_PLATFORM_H 15 + #define __SAMSUNG_USBPHY_PLATFORM_H 16 + 17 + /** 18 + * samsung_usbphy_data - Platform data for USB PHY driver. 19 + * @pmu_isolation: Function to control usb phy isolation in PMU. 20 + */ 21 + struct samsung_usbphy_data { 22 + void (*pmu_isolation)(int on); 23 + }; 24 + 25 + extern void samsung_usbphy_set_pdata(struct samsung_usbphy_data *pd); 26 + 27 + #endif /* __SAMSUNG_USBPHY_PLATFORM_H */
+19
include/linux/platform_data/usb3503.h
··· 1 + #ifndef __USB3503_H__ 2 + #define __USB3503_H__ 3 + 4 + #define USB3503_I2C_NAME "usb3503" 5 + 6 + enum usb3503_mode { 7 + USB3503_MODE_UNKNOWN, 8 + USB3503_MODE_HUB, 9 + USB3503_MODE_STANDBY, 10 + }; 11 + 12 + struct usb3503_platform_data { 13 + enum usb3503_mode initial_mode; 14 + int gpio_intn; 15 + int gpio_connect; 16 + int gpio_reset; 17 + }; 18 + 19 + #endif
+73 -2
include/linux/usb/composite.h
··· 77 77 * in interface or class descriptors; endpoints; I/O buffers; and so on. 78 78 * @unbind: Reverses @bind; called as a side effect of unregistering the 79 79 * driver which added this function. 80 + * @free_func: free the struct usb_function. 81 + * @mod: (internal) points to the module that created this structure. 80 82 * @set_alt: (REQUIRED) Reconfigures altsettings; function drivers may 81 83 * initialize usb_ep.driver data at this time (when it is used). 82 84 * Note that setting an interface to its current altsetting resets ··· 118 116 * two or more distinct instances within the same configuration, providing 119 117 * several independent logical data links to a USB host. 120 118 */ 119 + 121 120 struct usb_function { 122 121 const char *name; 123 122 struct usb_gadget_strings **strings; ··· 139 136 struct usb_function *); 140 137 void (*unbind)(struct usb_configuration *, 141 138 struct usb_function *); 139 + void (*free_func)(struct usb_function *f); 140 + struct module *mod; 142 141 143 142 /* runtime state management */ 144 143 int (*set_alt)(struct usb_function *, ··· 161 156 /* internals */ 162 157 struct list_head list; 163 158 DECLARE_BITMAP(endpoints, 32); 159 + const struct usb_function_instance *fi; 164 160 }; 165 161 166 162 int usb_add_function(struct usb_configuration *, struct usb_function *); ··· 190 184 * @bConfigurationValue: Copied into configuration descriptor. 191 185 * @iConfiguration: Copied into configuration descriptor. 192 186 * @bmAttributes: Copied into configuration descriptor. 193 - * @bMaxPower: Copied into configuration descriptor. 187 + * @MaxPower: Power consumtion in mA. Used to compute bMaxPower in the 188 + * configuration descriptor after considering the bus speed. 194 189 * @cdev: assigned by @usb_add_config() before calling @bind(); this is 195 190 * the device associated with this configuration. 196 191 * ··· 237 230 u8 bConfigurationValue; 238 231 u8 iConfiguration; 239 232 u8 bmAttributes; 240 - u8 bMaxPower; 233 + u16 MaxPower; 241 234 242 235 struct usb_composite_dev *cdev; 243 236 ··· 323 316 extern int usb_composite_probe(struct usb_composite_driver *driver); 324 317 extern void usb_composite_unregister(struct usb_composite_driver *driver); 325 318 extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); 319 + extern int composite_dev_prepare(struct usb_composite_driver *composite, 320 + struct usb_composite_dev *cdev); 321 + void composite_dev_cleanup(struct usb_composite_dev *cdev); 326 322 323 + static inline struct usb_composite_driver *to_cdriver( 324 + struct usb_gadget_driver *gdrv) 325 + { 326 + return container_of(gdrv, struct usb_composite_driver, gadget_driver); 327 + } 327 328 328 329 /** 329 330 * struct usb_composite_device - represents one composite usb gadget ··· 375 360 unsigned int suspended:1; 376 361 struct usb_device_descriptor desc; 377 362 struct list_head configs; 363 + struct list_head gstrings; 378 364 struct usb_composite_driver *driver; 379 365 u8 next_string_id; 380 366 char *def_manufacturer; ··· 397 381 extern int usb_string_id(struct usb_composite_dev *c); 398 382 extern int usb_string_ids_tab(struct usb_composite_dev *c, 399 383 struct usb_string *str); 384 + extern struct usb_string *usb_gstrings_attach(struct usb_composite_dev *cdev, 385 + struct usb_gadget_strings **sp, unsigned n_strings); 386 + 400 387 extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); 388 + 389 + extern void composite_disconnect(struct usb_gadget *gadget); 390 + extern int composite_setup(struct usb_gadget *gadget, 391 + const struct usb_ctrlrequest *ctrl); 401 392 402 393 /* 403 394 * Some systems will need runtime overrides for the product identifiers ··· 453 430 bcdDevice |= bin2bcd((LINUX_VERSION_CODE >> 8 & 0xff)); 454 431 return bcdDevice; 455 432 } 433 + 434 + struct usb_function_driver { 435 + const char *name; 436 + struct module *mod; 437 + struct list_head list; 438 + struct usb_function_instance *(*alloc_inst)(void); 439 + struct usb_function *(*alloc_func)(struct usb_function_instance *inst); 440 + }; 441 + 442 + struct usb_function_instance { 443 + struct usb_function_driver *fd; 444 + void (*free_func_inst)(struct usb_function_instance *inst); 445 + }; 446 + 447 + void usb_function_unregister(struct usb_function_driver *f); 448 + int usb_function_register(struct usb_function_driver *newf); 449 + void usb_put_function_instance(struct usb_function_instance *fi); 450 + void usb_put_function(struct usb_function *f); 451 + struct usb_function_instance *usb_get_function_instance(const char *name); 452 + struct usb_function *usb_get_function(struct usb_function_instance *fi); 453 + 454 + struct usb_configuration *usb_get_config(struct usb_composite_dev *cdev, 455 + int val); 456 + int usb_add_config_only(struct usb_composite_dev *cdev, 457 + struct usb_configuration *config); 458 + void usb_remove_function(struct usb_configuration *c, struct usb_function *f); 459 + 460 + #define DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc) \ 461 + static struct usb_function_driver _name ## usb_func = { \ 462 + .name = __stringify(_name), \ 463 + .mod = THIS_MODULE, \ 464 + .alloc_inst = _inst_alloc, \ 465 + .alloc_func = _func_alloc, \ 466 + }; \ 467 + MODULE_ALIAS("usbfunc:"__stringify(_name)); 468 + 469 + #define DECLARE_USB_FUNCTION_INIT(_name, _inst_alloc, _func_alloc) \ 470 + DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc) \ 471 + static int __init _name ## mod_init(void) \ 472 + { \ 473 + return usb_function_register(&_name ## usb_func); \ 474 + } \ 475 + static void __exit _name ## mod_exit(void) \ 476 + { \ 477 + usb_function_unregister(&_name ## usb_func); \ 478 + } \ 479 + module_init(_name ## mod_init); \ 480 + module_exit(_name ## mod_exit) 456 481 457 482 /* messaging utils */ 458 483 #define DBG(d, fmt, args...) \
+30
include/linux/usb/dwc3-omap.h
··· 1 + /* 2 + * Copyright (C) 2013 by Texas Instruments 3 + * 4 + * The Inventra Controller Driver for Linux is free software; you 5 + * can redistribute it and/or modify it under the terms of the GNU 6 + * General Public License version 2 as published by the Free Software 7 + * Foundation. 8 + */ 9 + 10 + #ifndef __DWC3_OMAP_H__ 11 + #define __DWC3_OMAP_H__ 12 + 13 + enum omap_dwc3_vbus_id_status { 14 + OMAP_DWC3_UNKNOWN = 0, 15 + OMAP_DWC3_ID_GROUND, 16 + OMAP_DWC3_ID_FLOAT, 17 + OMAP_DWC3_VBUS_VALID, 18 + OMAP_DWC3_VBUS_OFF, 19 + }; 20 + 21 + #if (defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_DWC3_MODULE)) 22 + extern void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status); 23 + #else 24 + static inline void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status) 25 + { 26 + return; 27 + } 28 + #endif 29 + 30 + #endif /* __DWC3_OMAP_H__ */
+7 -6
include/linux/usb/gadget.h
··· 471 471 struct usb_gadget_driver *); 472 472 int (*udc_stop)(struct usb_gadget *, 473 473 struct usb_gadget_driver *); 474 - 475 - /* Those two are deprecated */ 476 - int (*start)(struct usb_gadget_driver *, 477 - int (*bind)(struct usb_gadget *, 478 - struct usb_gadget_driver *driver)); 479 - int (*stop)(struct usb_gadget_driver *); 480 474 }; 481 475 482 476 /** ··· 874 880 875 881 extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); 876 882 extern void usb_del_gadget_udc(struct usb_gadget *gadget); 883 + extern int udc_attach_driver(const char *name, 884 + struct usb_gadget_driver *driver); 877 885 878 886 /*-------------------------------------------------------------------------*/ 879 887 ··· 905 909 struct usb_gadget_strings { 906 910 u16 language; /* 0x0409 for en-us */ 907 911 struct usb_string *strings; 912 + }; 913 + 914 + struct usb_gadget_string_container { 915 + struct list_head list; 916 + u8 *stash[0]; 908 917 }; 909 918 910 919 /* put descriptor for string with that id into buf (buflen >= 256) */
+2
include/linux/usb/musb.h
··· 99 99 /* MUSB_HOST, MUSB_PERIPHERAL, or MUSB_OTG */ 100 100 u8 mode; 101 101 102 + u8 has_mailbox:1; 103 + 102 104 /* for clk_get() */ 103 105 const char *clock; 104 106
+92
include/linux/usb/omap_control_usb.h
··· 1 + /* 2 + * omap_control_usb.h - Header file for the USB part of control module. 3 + * 4 + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation; either version 2 of the License, or 8 + * (at your option) any later version. 9 + * 10 + * Author: Kishon Vijay Abraham I <kishon@ti.com> 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + */ 18 + 19 + #ifndef __OMAP_CONTROL_USB_H__ 20 + #define __OMAP_CONTROL_USB_H__ 21 + 22 + struct omap_control_usb { 23 + struct device *dev; 24 + 25 + u32 __iomem *dev_conf; 26 + u32 __iomem *otghs_control; 27 + u32 __iomem *phy_power; 28 + 29 + struct clk *sys_clk; 30 + 31 + u32 type; 32 + }; 33 + 34 + struct omap_control_usb_platform_data { 35 + u8 type; 36 + }; 37 + 38 + enum omap_control_usb_mode { 39 + USB_MODE_UNDEFINED = 0, 40 + USB_MODE_HOST, 41 + USB_MODE_DEVICE, 42 + USB_MODE_DISCONNECT, 43 + }; 44 + 45 + /* To differentiate ctrl module IP having either mailbox or USB3 PHY power */ 46 + #define OMAP_CTRL_DEV_TYPE1 0x1 47 + #define OMAP_CTRL_DEV_TYPE2 0x2 48 + 49 + #define OMAP_CTRL_DEV_PHY_PD BIT(0) 50 + 51 + #define OMAP_CTRL_DEV_AVALID BIT(0) 52 + #define OMAP_CTRL_DEV_BVALID BIT(1) 53 + #define OMAP_CTRL_DEV_VBUSVALID BIT(2) 54 + #define OMAP_CTRL_DEV_SESSEND BIT(3) 55 + #define OMAP_CTRL_DEV_IDDIG BIT(4) 56 + 57 + #define OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK 0x003FC000 58 + #define OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT 0xE 59 + 60 + #define OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK 0xFFC00000 61 + #define OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT 0x16 62 + 63 + #define OMAP_CTRL_USB3_PHY_TX_RX_POWERON 0x3 64 + #define OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF 0x0 65 + 66 + #if IS_ENABLED(CONFIG_OMAP_CONTROL_USB) 67 + extern struct device *omap_get_control_dev(void); 68 + extern void omap_control_usb_phy_power(struct device *dev, int on); 69 + extern void omap_control_usb3_phy_power(struct device *dev, bool on); 70 + extern void omap_control_usb_set_mode(struct device *dev, 71 + enum omap_control_usb_mode mode); 72 + #else 73 + static inline struct device *omap_get_control_dev(void) 74 + { 75 + return ERR_PTR(-ENODEV); 76 + } 77 + 78 + static inline void omap_control_usb_phy_power(struct device *dev, int on) 79 + { 80 + } 81 + 82 + static inline void omap_control_usb3_phy_power(struct device *dev, int on) 83 + { 84 + } 85 + 86 + static inline void omap_control_usb_set_mode(struct device *dev, 87 + enum omap_control_usb_mode mode) 88 + { 89 + } 90 + #endif 91 + 92 + #endif /* __OMAP_CONTROL_USB_H__ */
+24 -3
include/linux/usb/omap_usb.h
··· 19 19 #ifndef __DRIVERS_OMAP_USB2_H 20 20 #define __DRIVERS_OMAP_USB2_H 21 21 22 + #include <linux/io.h> 22 23 #include <linux/usb/otg.h> 24 + 25 + struct usb_dpll_params { 26 + u16 m; 27 + u8 n; 28 + u8 freq:3; 29 + u8 sd; 30 + u32 mf; 31 + }; 23 32 24 33 struct omap_usb { 25 34 struct usb_phy phy; 26 35 struct phy_companion *comparator; 36 + void __iomem *pll_ctrl_base; 27 37 struct device *dev; 28 - u32 __iomem *control_dev; 38 + struct device *control_dev; 29 39 struct clk *wkupclk; 40 + struct clk *sys_clk; 41 + struct clk *optclk; 30 42 u8 is_suspended:1; 31 43 }; 32 - 33 - #define PHY_PD 0x1 34 44 35 45 #define phy_to_omapusb(x) container_of((x), struct omap_usb, phy) 36 46 ··· 52 42 return -ENODEV; 53 43 } 54 44 #endif 45 + 46 + static inline u32 omap_usb_readl(void __iomem *addr, unsigned offset) 47 + { 48 + return __raw_readl(addr + offset); 49 + } 50 + 51 + static inline void omap_usb_writel(void __iomem *addr, unsigned offset, 52 + u32 data) 53 + { 54 + __raw_writel(data, addr + offset); 55 + } 55 56 56 57 #endif /* __DRIVERS_OMAP_USB_H */
+43
include/linux/usb/phy.h
··· 106 106 enum usb_device_speed speed); 107 107 }; 108 108 109 + /** 110 + * struct usb_phy_bind - represent the binding for the phy 111 + * @dev_name: the device name of the device that will bind to the phy 112 + * @phy_dev_name: the device name of the phy 113 + * @index: used if a single controller uses multiple phys 114 + * @phy: reference to the phy 115 + * @list: to maintain a linked list of the binding information 116 + */ 117 + struct usb_phy_bind { 118 + const char *dev_name; 119 + const char *phy_dev_name; 120 + u8 index; 121 + struct usb_phy *phy; 122 + struct list_head list; 123 + }; 109 124 110 125 /* for board-specific init logic */ 111 126 extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type); 127 + extern int usb_add_phy_dev(struct usb_phy *); 112 128 extern void usb_remove_phy(struct usb_phy *); 113 129 114 130 /* helpers for direct access thru low-level io interface */ ··· 165 149 extern struct usb_phy *usb_get_phy(enum usb_phy_type type); 166 150 extern struct usb_phy *devm_usb_get_phy(struct device *dev, 167 151 enum usb_phy_type type); 152 + extern struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index); 153 + extern struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index); 154 + extern struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev, 155 + const char *phandle, u8 index); 168 156 extern void usb_put_phy(struct usb_phy *); 169 157 extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x); 158 + extern int usb_bind_phy(const char *dev_name, u8 index, 159 + const char *phy_dev_name); 170 160 #else 171 161 static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) 172 162 { ··· 185 163 return NULL; 186 164 } 187 165 166 + static inline struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index) 167 + { 168 + return NULL; 169 + } 170 + 171 + static inline struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index) 172 + { 173 + return NULL; 174 + } 175 + 176 + static inline struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev, 177 + const char *phandle, u8 index) 178 + { 179 + return NULL; 180 + } 181 + 188 182 static inline void usb_put_phy(struct usb_phy *x) 189 183 { 190 184 } ··· 209 171 { 210 172 } 211 173 174 + static inline int usb_bind_phy(const char *dev_name, u8 index, 175 + const char *phy_dev_name) 176 + { 177 + return -EOPNOTSUPP; 178 + } 212 179 #endif 213 180 214 181 static inline int
+16
include/linux/usb/samsung_usb_phy.h
··· 1 + /* 2 + * Copyright (C) 2012 Samsung Electronics Co.Ltd 3 + * http://www.samsung.com/ 4 + * 5 + * Defines phy types for samsung usb phy controllers - HOST or DEIVCE. 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License as published by the 9 + * Free Software Foundation; either version 2 of the License, or (at your 10 + * option) any later version. 11 + */ 12 + 13 + enum samsung_usb_phy_type { 14 + USB_PHY_TYPE_DEVICE, 15 + USB_PHY_TYPE_HOST, 16 + };
+14 -17
tools/usb/testusb.c
··· 279 279 280 280 entry->ifnum = ifnum; 281 281 282 - /* FIXME ask usbfs what speed; update USBDEVFS_CONNECTINFO so 283 - * it tells about high speed etc */ 282 + /* FIXME update USBDEVFS_CONNECTINFO so it tells about high speed etc */ 284 283 285 284 fprintf(stderr, "%s speed\t%s\t%u\n", 286 285 speed(entry->speed), entry->name, entry->ifnum); ··· 350 351 return arg; 351 352 } 352 353 353 - static const char *usbfs_dir_find(void) 354 + static const char *usb_dir_find(void) 354 355 { 355 356 static char udev_usb_path[] = "/dev/bus/usb"; 356 357 ··· 379 380 int c; 380 381 struct testdev *entry; 381 382 char *device; 382 - const char *usbfs_dir = NULL; 383 + const char *usb_dir = NULL; 383 384 int all = 0, forever = 0, not = 0; 384 385 int test = -1 /* all */; 385 386 struct usbtest_param param; ··· 406 407 case 'D': /* device, if only one */ 407 408 device = optarg; 408 409 continue; 409 - case 'A': /* use all devices with specified usbfs dir */ 410 - usbfs_dir = optarg; 410 + case 'A': /* use all devices with specified USB dir */ 411 + usb_dir = optarg; 411 412 /* FALL THROUGH */ 412 413 case 'a': /* use all devices */ 413 414 device = NULL; ··· 448 449 "usage: %s [options]\n" 449 450 "Options:\n" 450 451 "\t-D dev only test specific device\n" 451 - "\t-A usbfs-dir\n" 452 + "\t-A usb-dir\n" 452 453 "\t-a test all recognized devices\n" 453 454 "\t-l loop forever(for stress test)\n" 454 455 "\t-t testnum only run specified case\n" ··· 469 470 goto usage; 470 471 } 471 472 472 - /* Find usbfs mount point */ 473 - if (!usbfs_dir) { 474 - usbfs_dir = usbfs_dir_find(); 475 - if (!usbfs_dir) { 476 - fputs ("usbfs files are missing\n", stderr); 473 + /* Find usb device subdirectory */ 474 + if (!usb_dir) { 475 + usb_dir = usb_dir_find(); 476 + if (!usb_dir) { 477 + fputs ("USB device files are missing\n", stderr); 477 478 return -1; 478 479 } 479 480 } 480 481 481 482 /* collect and list the test devices */ 482 - if (ftw (usbfs_dir, find_testdev, 3) != 0) { 483 - fputs ("ftw failed; is usbfs missing?\n", stderr); 483 + if (ftw (usb_dir, find_testdev, 3) != 0) { 484 + fputs ("ftw failed; are USB device files missing?\n", stderr); 484 485 return -1; 485 486 } 486 487 ··· 506 507 return handle_testdev (entry) != entry; 507 508 } 508 509 status = pthread_create (&entry->thread, 0, handle_testdev, entry); 509 - if (status) { 510 + if (status) 510 511 perror ("pthread_create"); 511 - continue; 512 - } 513 512 } 514 513 if (device) { 515 514 struct testdev dev;