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

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

Felipe writes:

usb: patches for v3.11 merge window

All function drivers are now converted to our new configfs-based
binding. Eventually this will help us getting rid of in-kernel
gadget drivers and only keep function drivers in the kernel.

MUSB was taught that it needs to be built for host-only and
device-only modes too. We had this support long ago but it
involved a ridiculous amount of ifdefs. Now we have a much
cleaner approach.

Samsung Exynos4 platform now implements HSIC support.

We're introducing support for AB8540 and AB9540 PHYs.

MUSB module reinsertion now works as expected, before we were
getting -EBUSY being returned by the resource checks done on
driver core.

DWC3 now has minimum support for TI's AM437x series of SoCs.

OMAP5 USB3 PHY learned one extra DPLL configuration values because
that PHY is reused in TI's DRA7xx devices.

We're introducing support for Faraday fotg210 UDCs.

Last, but not least, the usual set of non-critical fixes and cleanups
ranging from usage of platform_{get,set}_drvdata to lock improvements.

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

+5803 -1229
+14
Documentation/ABI/testing/configfs-usb-gadget-eem
··· 1 + What: /config/usb-gadget/gadget/functions/eem.name 2 + Date: May 2013 3 + KenelVersion: 3.11 4 + Description: 5 + The attributes: 6 + 7 + ifname - network device interface name associated with 8 + this function instance 9 + qmult - queue length multiplier for high and 10 + super speed 11 + host_addr - MAC address of host's end of this 12 + Ethernet over USB link 13 + dev_addr - MAC address of device's end of this 14 + Ethernet over USB link
+8
Documentation/ABI/testing/configfs-usb-gadget-phonet
··· 1 + What: /config/usb-gadget/gadget/functions/phonet.name 2 + Date: May 2013 3 + KenelVersion: 3.11 4 + Description: 5 + 6 + This item contains just one readonly attribute: ifname. 7 + It contains the network interface name assigned during 8 + network device registration.
+14
Documentation/ABI/testing/configfs-usb-gadget-rndis
··· 1 + What: /config/usb-gadget/gadget/functions/rndis.name 2 + Date: May 2013 3 + KenelVersion: 3.11 4 + Description: 5 + The attributes: 6 + 7 + ifname - network device interface name associated with 8 + this function instance 9 + qmult - queue length multiplier for high and 10 + super speed 11 + host_addr - MAC address of host's end of this 12 + Ethernet over USB link 13 + dev_addr - MAC address of device's end of this 14 + Ethernet over USB link
+14
Documentation/ABI/testing/configfs-usb-gadget-subset
··· 1 + What: /config/usb-gadget/gadget/functions/geth.name 2 + Date: May 2013 3 + KenelVersion: 3.11 4 + Description: 5 + The attributes: 6 + 7 + ifname - network device interface name associated with 8 + this function instance 9 + qmult - queue length multiplier for high and 10 + super speed 11 + host_addr - MAC address of host's end of this 12 + Ethernet over USB link 13 + dev_addr - MAC address of device's end of this 14 + Ethernet over USB link
+5 -22
Documentation/devicetree/bindings/usb/nvidia,tegra20-ehci.txt
··· 6 6 and additions : 7 7 8 8 Required properties : 9 - - compatible : Should be "nvidia,tegra20-ehci" for USB controllers 10 - used in host mode. 11 - - phy_type : Should be one of "ulpi" or "utmi". 12 - - nvidia,vbus-gpio : If present, specifies a gpio that needs to be 13 - activated for the bus to be powered. 14 - - nvidia,phy : phandle of the PHY instance, the controller is connected to. 15 - 16 - Required properties for phy_type == ulpi: 17 - - nvidia,phy-reset-gpio : The GPIO used to reset the PHY. 9 + - compatible : Should be "nvidia,tegra20-ehci". 10 + - nvidia,phy : phandle of the PHY that the controller is connected to. 11 + - clocks : Contains a single entry which defines the USB controller's clock. 18 12 19 13 Optional properties: 20 - - dr_mode : dual role mode. Indicates the working mode for 21 - nvidia,tegra20-ehci compatible controllers. Can be "host", "peripheral", 22 - or "otg". Default to "host" if not defined for backward compatibility. 23 - host means this is a host controller 24 - peripheral means it is device controller 25 - otg means it can operate as either ("on the go") 26 - - nvidia,has-legacy-mode : boolean indicates whether this controller can 27 - operate in legacy mode (as APX 2500 / 2600). In legacy mode some 28 - registers are accessed through the APB_MISC base address instead of 29 - the USB controller. Since this is a legacy issue it probably does not 30 - warrant a compatible string of its own. 31 - - nvidia,needs-double-reset : boolean is to be set for some of the Tegra2 32 - USB ports, which need reset twice due to hardware issues. 14 + - nvidia,needs-double-reset : boolean is to be set for some of the Tegra20 15 + USB ports, which need reset twice due to hardware issues.
+37 -2
Documentation/devicetree/bindings/usb/nvidia,tegra20-usb-phy.txt
··· 4 4 5 5 Required properties : 6 6 - compatible : Should be "nvidia,tegra20-usb-phy". 7 - - reg : Address and length of the register set for the USB PHY interface. 8 - - phy_type : Should be one of "ulpi" or "utmi". 7 + - reg : Defines the following set of registers, in the order listed: 8 + - The PHY's own register set. 9 + Always present. 10 + - The register set of the PHY containing the UTMI pad control registers. 11 + Present if-and-only-if phy_type == utmi. 12 + - phy_type : Should be one of "utmi", "ulpi" or "hsic". 13 + - clocks : Defines the clocks listed in the clock-names property. 14 + - clock-names : The following clock names must be present: 15 + - reg: The clock needed to access the PHY's own registers. This is the 16 + associated EHCI controller's clock. Always present. 17 + - pll_u: PLL_U. Always present. 18 + - timer: The timeout clock (clk_m). Present if phy_type == utmi. 19 + - utmi-pads: The clock needed to access the UTMI pad control registers. 20 + Present if phy_type == utmi. 21 + - ulpi-link: The clock Tegra provides to the ULPI PHY (cdev2). 22 + Present if phy_type == ulpi, and ULPI link mode is in use. 9 23 10 24 Required properties for phy_type == ulpi: 11 25 - nvidia,phy-reset-gpio : The GPIO used to reset the PHY. 26 + 27 + Required PHY timing params for utmi phy: 28 + - nvidia,hssync-start-delay : Number of 480 Mhz clock cycles to wait before 29 + start of sync launches RxActive 30 + - nvidia,elastic-limit : Variable FIFO Depth of elastic input store 31 + - nvidia,idle-wait-delay : Number of 480 Mhz clock cycles of idle to wait 32 + before declare IDLE. 33 + - nvidia,term-range-adj : Range adjusment on terminations 34 + - nvidia,xcvr-setup : HS driver output control 35 + - nvidia,xcvr-lsfslew : LS falling slew rate control. 36 + - nvidia,xcvr-lsrslew : LS rising slew rate control. 12 37 13 38 Optional properties: 14 39 - nvidia,has-legacy-mode : boolean indicates whether this controller can 15 40 operate in legacy mode (as APX 2500 / 2600). In legacy mode some 16 41 registers are accessed through the APB_MISC base address instead of 17 42 the USB controller. 43 + - nvidia,is-wired : boolean. Indicates whether we can do certain kind of power 44 + optimizations for the devices that are always connected. e.g. modem. 45 + - dr_mode : dual role mode. Indicates the working mode for the PHY. Can be 46 + "host", "peripheral", or "otg". Defaults to "host" if not defined. 47 + host means this is a host controller 48 + peripheral means it is device controller 49 + otg means it can operate as either ("on the go") 50 + 51 + Required properties for dr_mode == otg: 52 + - vbus-supply: regulator for VBUS
+5 -1
arch/arm/boot/dts/tegra20-colibri-512.dtsi
··· 449 449 450 450 usb@c5004000 { 451 451 status = "okay"; 452 - nvidia,phy-reset-gpio = <&gpio 169 0>; /* gpio PV1 */ 452 + nvidia,phy-reset-gpio = <&gpio 169 1>; /* gpio PV1, active low */ 453 + }; 454 + 455 + usb-phy@c5004000 { 456 + nvidia,phy-reset-gpio = <&gpio 169 1>; /* gpio PV1, active low */ 453 457 }; 454 458 455 459 sdhci@c8000600 {
+12 -3
arch/arm/boot/dts/tegra20-harmony.dts
··· 428 428 status = "okay"; 429 429 }; 430 430 431 + usb-phy@c5000000 { 432 + status = "okay"; 433 + }; 434 + 431 435 usb@c5004000 { 432 436 status = "okay"; 433 - nvidia,phy-reset-gpio = <&gpio 169 0>; /* gpio PV1 */ 437 + nvidia,phy-reset-gpio = <&gpio 169 1>; /* gpio PV1, active low */ 438 + }; 439 + 440 + usb-phy@c5004000 { 441 + status = "okay"; 442 + nvidia,phy-reset-gpio = <&gpio 169 1>; /* gpio PV1, active low */ 434 443 }; 435 444 436 445 usb@c5008000 { 437 446 status = "okay"; 438 447 }; 439 448 440 - usb-phy@c5004400 { 441 - nvidia,phy-reset-gpio = <&gpio 169 0>; /* gpio PV1 */ 449 + usb-phy@c5008000 { 450 + status = "okay"; 442 451 }; 443 452 444 453 sdhci@c8000200 {
+8 -1
arch/arm/boot/dts/tegra20-iris-512.dts
··· 38 38 39 39 usb@c5000000 { 40 40 status = "okay"; 41 - dr_mode = "otg"; 41 + }; 42 + 43 + usb-phy@c5000000 { 44 + status = "okay"; 42 45 }; 43 46 44 47 usb@c5008000 { 48 + status = "okay"; 49 + }; 50 + 51 + usb-phy@c5008000 { 45 52 status = "okay"; 46 53 }; 47 54
+12 -3
arch/arm/boot/dts/tegra20-paz00.dts
··· 427 427 status = "okay"; 428 428 }; 429 429 430 + usb-phy@c5000000 { 431 + status = "okay"; 432 + }; 433 + 430 434 usb@c5004000 { 431 435 status = "okay"; 432 - nvidia,phy-reset-gpio = <&gpio 168 0>; /* gpio PV0 */ 436 + nvidia,phy-reset-gpio = <&gpio 168 1>; /* gpio PV0, active low */ 437 + }; 438 + 439 + usb-phy@c5004000 { 440 + status = "okay"; 441 + nvidia,phy-reset-gpio = <&gpio 168 1>; /* gpio PV0, active low */ 433 442 }; 434 443 435 444 usb@c5008000 { 436 445 status = "okay"; 437 446 }; 438 447 439 - usb-phy@c5004400 { 440 - nvidia,phy-reset-gpio = <&gpio 168 0>; /* gpio PV0 */ 448 + usb-phy@c5008000 { 449 + status = "okay"; 441 450 }; 442 451 443 452 sdhci@c8000000 {
+23 -3
arch/arm/boot/dts/tegra20-seaboard.dts
··· 569 569 dr_mode = "otg"; 570 570 }; 571 571 572 + usb-phy@c5000000 { 573 + status = "okay"; 574 + vbus-supply = <&vbus_reg>; 575 + dr_mode = "otg"; 576 + }; 577 + 572 578 usb@c5004000 { 573 579 status = "okay"; 574 - nvidia,phy-reset-gpio = <&gpio 169 0>; /* gpio PV1 */ 580 + nvidia,phy-reset-gpio = <&gpio 169 1>; /* gpio PV1, active low */ 581 + }; 582 + 583 + usb-phy@c5004000 { 584 + status = "okay"; 585 + nvidia,phy-reset-gpio = <&gpio 169 1>; /* gpio PV1, active low */ 575 586 }; 576 587 577 588 usb@c5008000 { 578 589 status = "okay"; 579 590 }; 580 591 581 - usb-phy@c5004400 { 582 - nvidia,phy-reset-gpio = <&gpio 169 0>; /* gpio PV1 */ 592 + usb-phy@c5008000 { 593 + status = "okay"; 583 594 }; 584 595 585 596 sdhci@c8000000 { ··· 817 806 regulator-max-microvolt = <1200000>; 818 807 gpio = <&pmic 1 0>; 819 808 enable-active-high; 809 + }; 810 + 811 + vbus_reg: regulator@3 { 812 + compatible = "regulator-fixed"; 813 + reg = <3>; 814 + regulator-name = "vdd_vbus_wup1"; 815 + regulator-min-microvolt = <5000000>; 816 + regulator-max-microvolt = <5000000>; 817 + gpio = <&gpio 24 0>; /* PD0 */ 820 818 }; 821 819 }; 822 820
+4
arch/arm/boot/dts/tegra20-tamonten.dtsi
··· 470 470 status = "okay"; 471 471 }; 472 472 473 + usb-phy@c5008000 { 474 + status = "okay"; 475 + }; 476 + 473 477 sdhci@c8000600 { 474 478 cd-gpios = <&gpio 58 1>; /* gpio PH2 */ 475 479 wp-gpios = <&gpio 59 0>; /* gpio PH3 */
+22 -3
arch/arm/boot/dts/tegra20-trimslice.dts
··· 314 314 nvidia,vbus-gpio = <&gpio 170 0>; /* gpio PV2 */ 315 315 }; 316 316 317 + usb-phy@c5000000 { 318 + status = "okay"; 319 + vbus-supply = <&vbus_reg>; 320 + }; 321 + 317 322 usb@c5004000 { 318 323 status = "okay"; 319 - nvidia,phy-reset-gpio = <&gpio 168 0>; /* gpio PV0 */ 324 + nvidia,phy-reset-gpio = <&gpio 168 1>; /* gpio PV0, active low */ 325 + }; 326 + 327 + usb-phy@c5004000 { 328 + status = "okay"; 329 + nvidia,phy-reset-gpio = <&gpio 168 1>; /* gpio PV0, active low */ 320 330 }; 321 331 322 332 usb@c5008000 { 323 333 status = "okay"; 324 334 }; 325 335 326 - usb-phy@c5004400 { 327 - nvidia,phy-reset-gpio = <&gpio 168 0>; /* gpio PV0 */ 336 + usb-phy@c5008000 { 337 + status = "okay"; 328 338 }; 329 339 330 340 sdhci@c8000000 { ··· 399 389 regulator-min-microvolt = <1800000>; 400 390 regulator-max-microvolt = <1800000>; 401 391 regulator-always-on; 392 + }; 393 + 394 + vbus_reg: regulator@2 { 395 + compatible = "regulator-fixed"; 396 + reg = <2>; 397 + regulator-name = "usb1_vbus"; 398 + regulator-min-microvolt = <5000000>; 399 + regulator-max-microvolt = <5000000>; 400 + gpio = <&gpio 170 0>; /* PV2 */ 402 401 }; 403 402 }; 404 403
+12 -3
arch/arm/boot/dts/tegra20-ventana.dts
··· 505 505 status = "okay"; 506 506 }; 507 507 508 + usb-phy@c5000000 { 509 + status = "okay"; 510 + }; 511 + 508 512 usb@c5004000 { 509 513 status = "okay"; 510 - nvidia,phy-reset-gpio = <&gpio 169 0>; /* gpio PV1 */ 514 + nvidia,phy-reset-gpio = <&gpio 169 1>; /* gpio PV1, active low */ 515 + }; 516 + 517 + usb-phy@c5004000 { 518 + status = "okay"; 519 + nvidia,phy-reset-gpio = <&gpio 169 1>; /* gpio PV1, active low */ 511 520 }; 512 521 513 522 usb@c5008000 { 514 523 status = "okay"; 515 524 }; 516 525 517 - usb-phy@c5004400 { 518 - nvidia,phy-reset-gpio = <&gpio 169 0>; /* gpio PV1 */ 526 + usb-phy@c5008000 { 527 + status = "okay"; 519 528 }; 520 529 521 530 sdhci@c8000000 {
+28
arch/arm/boot/dts/tegra20-whistler.dts
··· 511 511 nvidia,vbus-gpio = <&tca6416 0 0>; /* GPIO_PMU0 */ 512 512 }; 513 513 514 + usb-phy@c5000000 { 515 + status = "okay"; 516 + vbus-supply = <&vbus1_reg>; 517 + }; 518 + 514 519 usb@c5008000 { 515 520 status = "okay"; 516 521 nvidia,vbus-gpio = <&tca6416 1 0>; /* GPIO_PMU1 */ 522 + }; 523 + 524 + usb-phy@c5008000 { 525 + status = "okay"; 526 + vbus-supply = <&vbus3_reg>; 517 527 }; 518 528 519 529 sdhci@c8000400 { ··· 577 567 regulator-min-microvolt = <5000000>; 578 568 regulator-max-microvolt = <5000000>; 579 569 regulator-always-on; 570 + }; 571 + 572 + vbus1_reg: regulator@2 { 573 + compatible = "regulator-fixed"; 574 + reg = <2>; 575 + regulator-name = "vbus1"; 576 + regulator-min-microvolt = <5000000>; 577 + regulator-max-microvolt = <5000000>; 578 + gpio = <&tca6416 0 0>; /* GPIO_PMU0 */ 579 + }; 580 + 581 + vbus3_reg: regulator@3 { 582 + compatible = "regulator-fixed"; 583 + reg = <3>; 584 + regulator-name = "vbus3"; 585 + regulator-min-microvolt = <5000000>; 586 + regulator-max-microvolt = <5000000>; 587 + gpio = <&tca6416 1 0>; /* GPIO_PMU1 */ 580 588 }; 581 589 }; 582 590
+37 -12
arch/arm/boot/dts/tegra20.dtsi
··· 455 455 status = "disabled"; 456 456 }; 457 457 458 - phy1: usb-phy@c5000400 { 458 + phy1: usb-phy@c5000000 { 459 459 compatible = "nvidia,tegra20-usb-phy"; 460 - reg = <0xc5000400 0x3c00>; 460 + reg = <0xc5000000 0x4000 0xc5000000 0x4000>; 461 461 phy_type = "utmi"; 462 + clocks = <&tegra_car 22>, 463 + <&tegra_car 127>, 464 + <&tegra_car 106>, 465 + <&tegra_car 22>; 466 + clock-names = "reg", "pll_u", "timer", "utmi-pads"; 462 467 nvidia,has-legacy-mode; 463 - clocks = <&tegra_car 22>, <&tegra_car 127>; 464 - clock-names = "phy", "pll_u"; 468 + hssync_start_delay = <9>; 469 + idle_wait_delay = <17>; 470 + elastic_limit = <16>; 471 + term_range_adj = <6>; 472 + xcvr_setup = <9>; 473 + xcvr_lsfslew = <1>; 474 + xcvr_lsrslew = <1>; 475 + status = "disabled"; 465 476 }; 466 477 467 478 usb@c5004000 { ··· 485 474 status = "disabled"; 486 475 }; 487 476 488 - phy2: usb-phy@c5004400 { 477 + phy2: usb-phy@c5004000 { 489 478 compatible = "nvidia,tegra20-usb-phy"; 490 - reg = <0xc5004400 0x3c00>; 479 + reg = <0xc5004000 0x4000>; 491 480 phy_type = "ulpi"; 492 - clocks = <&tegra_car 93>, <&tegra_car 127>; 493 - clock-names = "phy", "pll_u"; 481 + clocks = <&tegra_car 58>, 482 + <&tegra_car 127>, 483 + <&tegra_car 93>; 484 + clock-names = "reg", "pll_u", "ulpi-link"; 485 + status = "disabled"; 494 486 }; 495 487 496 488 usb@c5008000 { ··· 506 492 status = "disabled"; 507 493 }; 508 494 509 - phy3: usb-phy@c5008400 { 495 + phy3: usb-phy@c5008000 { 510 496 compatible = "nvidia,tegra20-usb-phy"; 511 - reg = <0xc5008400 0x3c00>; 497 + reg = <0xc5008000 0x4000 0xc5000000 0x4000>; 512 498 phy_type = "utmi"; 513 - clocks = <&tegra_car 22>, <&tegra_car 127>; 514 - clock-names = "phy", "pll_u"; 499 + clocks = <&tegra_car 59>, 500 + <&tegra_car 127>, 501 + <&tegra_car 106>, 502 + <&tegra_car 22>; 503 + clock-names = "reg", "pll_u", "timer", "utmi-pads"; 504 + hssync_start_delay = <9>; 505 + idle_wait_delay = <17>; 506 + elastic_limit = <16>; 507 + term_range_adj = <6>; 508 + xcvr_setup = <9>; 509 + xcvr_lsfslew = <2>; 510 + xcvr_lsrslew = <2>; 511 + status = "disabled"; 515 512 }; 516 513 517 514 sdhci@c8000000 {
+190 -57
drivers/usb/dwc3/dwc3-omap.c
··· 61 61 #define USBOTGSS_REVISION 0x0000 62 62 #define USBOTGSS_SYSCONFIG 0x0010 63 63 #define USBOTGSS_IRQ_EOI 0x0020 64 + #define USBOTGSS_EOI_OFFSET 0x0008 64 65 #define USBOTGSS_IRQSTATUS_RAW_0 0x0024 65 66 #define USBOTGSS_IRQSTATUS_0 0x0028 66 67 #define USBOTGSS_IRQENABLE_SET_0 0x002c 67 68 #define USBOTGSS_IRQENABLE_CLR_0 0x0030 68 - #define USBOTGSS_IRQSTATUS_RAW_1 0x0034 69 - #define USBOTGSS_IRQSTATUS_1 0x0038 70 - #define USBOTGSS_IRQENABLE_SET_1 0x003c 71 - #define USBOTGSS_IRQENABLE_CLR_1 0x0040 69 + #define USBOTGSS_IRQ0_OFFSET 0x0004 70 + #define USBOTGSS_IRQSTATUS_RAW_1 0x0030 71 + #define USBOTGSS_IRQSTATUS_1 0x0034 72 + #define USBOTGSS_IRQENABLE_SET_1 0x0038 73 + #define USBOTGSS_IRQENABLE_CLR_1 0x003c 74 + #define USBOTGSS_IRQSTATUS_RAW_2 0x0040 75 + #define USBOTGSS_IRQSTATUS_2 0x0044 76 + #define USBOTGSS_IRQENABLE_SET_2 0x0048 77 + #define USBOTGSS_IRQENABLE_CLR_2 0x004c 78 + #define USBOTGSS_IRQSTATUS_RAW_3 0x0050 79 + #define USBOTGSS_IRQSTATUS_3 0x0054 80 + #define USBOTGSS_IRQENABLE_SET_3 0x0058 81 + #define USBOTGSS_IRQENABLE_CLR_3 0x005c 82 + #define USBOTGSS_IRQSTATUS_EOI_MISC 0x0030 83 + #define USBOTGSS_IRQSTATUS_RAW_MISC 0x0034 84 + #define USBOTGSS_IRQSTATUS_MISC 0x0038 85 + #define USBOTGSS_IRQENABLE_SET_MISC 0x003c 86 + #define USBOTGSS_IRQENABLE_CLR_MISC 0x0040 87 + #define USBOTGSS_IRQMISC_OFFSET 0x03fc 72 88 #define USBOTGSS_UTMI_OTG_CTRL 0x0080 73 89 #define USBOTGSS_UTMI_OTG_STATUS 0x0084 90 + #define USBOTGSS_UTMI_OTG_OFFSET 0x0480 91 + #define USBOTGSS_TXFIFO_DEPTH 0x0508 92 + #define USBOTGSS_RXFIFO_DEPTH 0x050c 74 93 #define USBOTGSS_MMRAM_OFFSET 0x0100 75 94 #define USBOTGSS_FLADJ 0x0104 76 95 #define USBOTGSS_DEBUG_CFG 0x0108 77 96 #define USBOTGSS_DEBUG_DATA 0x010c 97 + #define USBOTGSS_DEV_EBC_EN 0x0110 98 + #define USBOTGSS_DEBUG_OFFSET 0x0600 78 99 100 + /* REVISION REGISTER */ 101 + #define USBOTGSS_REVISION_XMAJOR(reg) ((reg >> 8) & 0x7) 102 + #define USBOTGSS_REVISION_XMAJOR1 1 103 + #define USBOTGSS_REVISION_XMAJOR2 2 79 104 /* SYSCONFIG REGISTER */ 80 105 #define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16) 81 106 ··· 110 85 /* IRQS0 BITS */ 111 86 #define USBOTGSS_IRQO_COREIRQ_ST (1 << 0) 112 87 113 - /* IRQ1 BITS */ 114 - #define USBOTGSS_IRQ1_DMADISABLECLR (1 << 17) 115 - #define USBOTGSS_IRQ1_OEVT (1 << 16) 116 - #define USBOTGSS_IRQ1_DRVVBUS_RISE (1 << 13) 117 - #define USBOTGSS_IRQ1_CHRGVBUS_RISE (1 << 12) 118 - #define USBOTGSS_IRQ1_DISCHRGVBUS_RISE (1 << 11) 119 - #define USBOTGSS_IRQ1_IDPULLUP_RISE (1 << 8) 120 - #define USBOTGSS_IRQ1_DRVVBUS_FALL (1 << 5) 121 - #define USBOTGSS_IRQ1_CHRGVBUS_FALL (1 << 4) 122 - #define USBOTGSS_IRQ1_DISCHRGVBUS_FALL (1 << 3) 123 - #define USBOTGSS_IRQ1_IDPULLUP_FALL (1 << 0) 88 + /* IRQMISC BITS */ 89 + #define USBOTGSS_IRQMISC_DMADISABLECLR (1 << 17) 90 + #define USBOTGSS_IRQMISC_OEVT (1 << 16) 91 + #define USBOTGSS_IRQMISC_DRVVBUS_RISE (1 << 13) 92 + #define USBOTGSS_IRQMISC_CHRGVBUS_RISE (1 << 12) 93 + #define USBOTGSS_IRQMISC_DISCHRGVBUS_RISE (1 << 11) 94 + #define USBOTGSS_IRQMISC_IDPULLUP_RISE (1 << 8) 95 + #define USBOTGSS_IRQMISC_DRVVBUS_FALL (1 << 5) 96 + #define USBOTGSS_IRQMISC_CHRGVBUS_FALL (1 << 4) 97 + #define USBOTGSS_IRQMISC_DISCHRGVBUS_FALL (1 << 3) 98 + #define USBOTGSS_IRQMISC_IDPULLUP_FALL (1 << 0) 124 99 125 100 /* UTMI_OTG_CTRL REGISTER */ 126 101 #define USBOTGSS_UTMI_OTG_CTRL_DRVVBUS (1 << 5) ··· 147 122 void __iomem *base; 148 123 149 124 u32 utmi_otg_status; 125 + u32 utmi_otg_offset; 126 + u32 irqmisc_offset; 127 + u32 irq_eoi_offset; 128 + u32 debug_offset; 129 + u32 irq0_offset; 130 + u32 revision; 150 131 151 132 u32 dma_status:1; 152 133 }; ··· 169 138 writel(value, base + offset); 170 139 } 171 140 141 + static u32 dwc3_omap_read_utmi_status(struct dwc3_omap *omap) 142 + { 143 + return dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS + 144 + omap->utmi_otg_offset); 145 + } 146 + 147 + static void dwc3_omap_write_utmi_status(struct dwc3_omap *omap, u32 value) 148 + { 149 + dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS + 150 + omap->utmi_otg_offset, value); 151 + 152 + } 153 + 154 + static u32 dwc3_omap_read_irq0_status(struct dwc3_omap *omap) 155 + { 156 + return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0 - 157 + omap->irq0_offset); 158 + } 159 + 160 + static void dwc3_omap_write_irq0_status(struct dwc3_omap *omap, u32 value) 161 + { 162 + dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0 - 163 + omap->irq0_offset, value); 164 + 165 + } 166 + 167 + static u32 dwc3_omap_read_irqmisc_status(struct dwc3_omap *omap) 168 + { 169 + return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_MISC + 170 + omap->irqmisc_offset); 171 + } 172 + 173 + static void dwc3_omap_write_irqmisc_status(struct dwc3_omap *omap, u32 value) 174 + { 175 + dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_MISC + 176 + omap->irqmisc_offset, value); 177 + 178 + } 179 + 180 + static void dwc3_omap_write_irqmisc_set(struct dwc3_omap *omap, u32 value) 181 + { 182 + dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_MISC + 183 + omap->irqmisc_offset, value); 184 + 185 + } 186 + 187 + static void dwc3_omap_write_irq0_set(struct dwc3_omap *omap, u32 value) 188 + { 189 + dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0 - 190 + omap->irq0_offset, value); 191 + } 192 + 172 193 int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status) 173 194 { 174 195 u32 val; ··· 233 150 case OMAP_DWC3_ID_GROUND: 234 151 dev_dbg(omap->dev, "ID GND\n"); 235 152 236 - val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 153 + val = dwc3_omap_read_utmi_status(omap); 237 154 val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG 238 155 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID 239 156 | USBOTGSS_UTMI_OTG_STATUS_SESSEND); 240 157 val |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID 241 158 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; 242 - dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); 159 + dwc3_omap_write_utmi_status(omap, val); 243 160 break; 244 161 245 162 case OMAP_DWC3_VBUS_VALID: 246 163 dev_dbg(omap->dev, "VBUS Connect\n"); 247 164 248 - val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 165 + val = dwc3_omap_read_utmi_status(omap); 249 166 val &= ~USBOTGSS_UTMI_OTG_STATUS_SESSEND; 250 167 val |= USBOTGSS_UTMI_OTG_STATUS_IDDIG 251 168 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID 252 169 | USBOTGSS_UTMI_OTG_STATUS_SESSVALID 253 170 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; 254 - dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); 171 + dwc3_omap_write_utmi_status(omap, val); 255 172 break; 256 173 257 174 case OMAP_DWC3_ID_FLOAT: 258 175 case OMAP_DWC3_VBUS_OFF: 259 176 dev_dbg(omap->dev, "VBUS Disconnect\n"); 260 177 261 - val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 178 + val = dwc3_omap_read_utmi_status(omap); 262 179 val &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSVALID 263 180 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID 264 181 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT); 265 182 val |= USBOTGSS_UTMI_OTG_STATUS_SESSEND 266 183 | USBOTGSS_UTMI_OTG_STATUS_IDDIG; 267 - dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); 184 + dwc3_omap_write_utmi_status(omap, val); 268 185 break; 269 186 270 187 default: ··· 282 199 283 200 spin_lock(&omap->lock); 284 201 285 - reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_1); 202 + reg = dwc3_omap_read_irqmisc_status(omap); 286 203 287 - if (reg & USBOTGSS_IRQ1_DMADISABLECLR) { 204 + if (reg & USBOTGSS_IRQMISC_DMADISABLECLR) { 288 205 dev_dbg(omap->dev, "DMA Disable was Cleared\n"); 289 206 omap->dma_status = false; 290 207 } 291 208 292 - if (reg & USBOTGSS_IRQ1_OEVT) 209 + if (reg & USBOTGSS_IRQMISC_OEVT) 293 210 dev_dbg(omap->dev, "OTG Event\n"); 294 211 295 - if (reg & USBOTGSS_IRQ1_DRVVBUS_RISE) 212 + if (reg & USBOTGSS_IRQMISC_DRVVBUS_RISE) 296 213 dev_dbg(omap->dev, "DRVVBUS Rise\n"); 297 214 298 - if (reg & USBOTGSS_IRQ1_CHRGVBUS_RISE) 215 + if (reg & USBOTGSS_IRQMISC_CHRGVBUS_RISE) 299 216 dev_dbg(omap->dev, "CHRGVBUS Rise\n"); 300 217 301 - if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_RISE) 218 + if (reg & USBOTGSS_IRQMISC_DISCHRGVBUS_RISE) 302 219 dev_dbg(omap->dev, "DISCHRGVBUS Rise\n"); 303 220 304 - if (reg & USBOTGSS_IRQ1_IDPULLUP_RISE) 221 + if (reg & USBOTGSS_IRQMISC_IDPULLUP_RISE) 305 222 dev_dbg(omap->dev, "IDPULLUP Rise\n"); 306 223 307 - if (reg & USBOTGSS_IRQ1_DRVVBUS_FALL) 224 + if (reg & USBOTGSS_IRQMISC_DRVVBUS_FALL) 308 225 dev_dbg(omap->dev, "DRVVBUS Fall\n"); 309 226 310 - if (reg & USBOTGSS_IRQ1_CHRGVBUS_FALL) 227 + if (reg & USBOTGSS_IRQMISC_CHRGVBUS_FALL) 311 228 dev_dbg(omap->dev, "CHRGVBUS Fall\n"); 312 229 313 - if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_FALL) 230 + if (reg & USBOTGSS_IRQMISC_DISCHRGVBUS_FALL) 314 231 dev_dbg(omap->dev, "DISCHRGVBUS Fall\n"); 315 232 316 - if (reg & USBOTGSS_IRQ1_IDPULLUP_FALL) 233 + if (reg & USBOTGSS_IRQMISC_IDPULLUP_FALL) 317 234 dev_dbg(omap->dev, "IDPULLUP Fall\n"); 318 235 319 - dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_1, reg); 236 + dwc3_omap_write_irqmisc_status(omap, reg); 320 237 321 - reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0); 322 - dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0, reg); 238 + reg = dwc3_omap_read_irq0_status(omap); 239 + 240 + dwc3_omap_write_irq0_status(omap, reg); 323 241 324 242 spin_unlock(&omap->lock); 325 243 ··· 342 258 343 259 /* enable all IRQs */ 344 260 reg = USBOTGSS_IRQO_COREIRQ_ST; 345 - dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg); 261 + dwc3_omap_write_irq0_set(omap, reg); 346 262 347 - reg = (USBOTGSS_IRQ1_OEVT | 348 - USBOTGSS_IRQ1_DRVVBUS_RISE | 349 - USBOTGSS_IRQ1_CHRGVBUS_RISE | 350 - USBOTGSS_IRQ1_DISCHRGVBUS_RISE | 351 - USBOTGSS_IRQ1_IDPULLUP_RISE | 352 - USBOTGSS_IRQ1_DRVVBUS_FALL | 353 - USBOTGSS_IRQ1_CHRGVBUS_FALL | 354 - USBOTGSS_IRQ1_DISCHRGVBUS_FALL | 355 - USBOTGSS_IRQ1_IDPULLUP_FALL); 263 + reg = (USBOTGSS_IRQMISC_OEVT | 264 + USBOTGSS_IRQMISC_DRVVBUS_RISE | 265 + USBOTGSS_IRQMISC_CHRGVBUS_RISE | 266 + USBOTGSS_IRQMISC_DISCHRGVBUS_RISE | 267 + USBOTGSS_IRQMISC_IDPULLUP_RISE | 268 + USBOTGSS_IRQMISC_DRVVBUS_FALL | 269 + USBOTGSS_IRQMISC_CHRGVBUS_FALL | 270 + USBOTGSS_IRQMISC_DISCHRGVBUS_FALL | 271 + USBOTGSS_IRQMISC_IDPULLUP_FALL); 356 272 357 - dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg); 273 + dwc3_omap_write_irqmisc_set(omap, reg); 358 274 } 359 275 360 276 static void dwc3_omap_disable_irqs(struct dwc3_omap *omap) 361 277 { 362 278 /* disable all IRQs */ 363 - dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, 0x00); 364 - dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, 0x00); 279 + dwc3_omap_write_irqmisc_set(omap, 0x00); 280 + dwc3_omap_write_irq0_set(omap, 0x00); 365 281 } 366 282 367 283 static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32); ··· 378 294 int irq; 379 295 380 296 int utmi_mode = 0; 297 + int x_major; 381 298 382 299 u32 reg; 383 300 ··· 432 347 ret = pm_runtime_get_sync(dev); 433 348 if (ret < 0) { 434 349 dev_err(dev, "get_sync failed with err %d\n", ret); 435 - return ret; 350 + goto err0; 436 351 } 437 352 438 - reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 353 + reg = dwc3_omap_readl(omap->base, USBOTGSS_REVISION); 354 + omap->revision = reg; 355 + x_major = USBOTGSS_REVISION_XMAJOR(reg); 356 + 357 + /* Differentiate between OMAP5 and AM437x */ 358 + switch (x_major) { 359 + case USBOTGSS_REVISION_XMAJOR1: 360 + case USBOTGSS_REVISION_XMAJOR2: 361 + omap->irq_eoi_offset = 0; 362 + omap->irq0_offset = 0; 363 + omap->irqmisc_offset = 0; 364 + omap->utmi_otg_offset = 0; 365 + omap->debug_offset = 0; 366 + break; 367 + default: 368 + /* Default to the latest revision */ 369 + omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET; 370 + omap->irq0_offset = USBOTGSS_IRQ0_OFFSET; 371 + omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET; 372 + omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET; 373 + omap->debug_offset = USBOTGSS_DEBUG_OFFSET; 374 + break; 375 + } 376 + 377 + /* For OMAP5(ES2.0) and AM437x x_major is 2 even though there are 378 + * changes in wrapper registers, Using dt compatible for aegis 379 + */ 380 + 381 + if (of_device_is_compatible(node, "ti,am437x-dwc3")) { 382 + omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET; 383 + omap->irq0_offset = USBOTGSS_IRQ0_OFFSET; 384 + omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET; 385 + omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET; 386 + omap->debug_offset = USBOTGSS_DEBUG_OFFSET; 387 + } 388 + 389 + reg = dwc3_omap_read_utmi_status(omap); 439 390 440 391 of_property_read_u32(node, "utmi-mode", &utmi_mode); 441 392 ··· 486 365 dev_dbg(dev, "UNKNOWN utmi mode %d\n", utmi_mode); 487 366 } 488 367 489 - dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg); 368 + dwc3_omap_write_utmi_status(omap, reg); 490 369 491 370 /* check the DMA Status */ 492 371 reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); ··· 497 376 if (ret) { 498 377 dev_err(dev, "failed to request IRQ #%d --> %d\n", 499 378 omap->irq, ret); 500 - return ret; 379 + goto err1; 501 380 } 502 381 503 382 dwc3_omap_enable_irqs(omap); ··· 505 384 ret = of_platform_populate(node, NULL, NULL, dev); 506 385 if (ret) { 507 386 dev_err(&pdev->dev, "failed to create dwc3 core\n"); 508 - return ret; 387 + goto err2; 509 388 } 510 389 511 390 return 0; 391 + 392 + err2: 393 + dwc3_omap_disable_irqs(omap); 394 + 395 + err1: 396 + pm_runtime_put_sync(dev); 397 + 398 + err0: 399 + pm_runtime_disable(dev); 400 + 401 + return ret; 512 402 } 513 403 514 404 static int dwc3_omap_remove(struct platform_device *pdev) ··· 537 405 static const struct of_device_id of_dwc3_match[] = { 538 406 { 539 407 .compatible = "ti,dwc3" 408 + }, 409 + { 410 + .compatible = "ti,am437x-dwc3" 540 411 }, 541 412 { }, 542 413 }; ··· 566 431 { 567 432 struct dwc3_omap *omap = dev_get_drvdata(dev); 568 433 569 - omap->utmi_otg_status = dwc3_omap_readl(omap->base, 570 - USBOTGSS_UTMI_OTG_STATUS); 434 + omap->utmi_otg_status = dwc3_omap_read_utmi_status(omap); 571 435 572 436 return 0; 573 437 } ··· 575 441 { 576 442 struct dwc3_omap *omap = dev_get_drvdata(dev); 577 443 578 - dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, 579 - omap->utmi_otg_status); 444 + dwc3_omap_write_utmi_status(omap, omap->utmi_otg_status); 580 445 581 446 pm_runtime_disable(dev); 582 447 pm_runtime_set_active(dev);
-1
drivers/usb/dwc3/dwc3-pci.c
··· 133 133 return -ENODEV; 134 134 } 135 135 136 - pci_set_power_state(pci, PCI_D0); 137 136 pci_set_master(pci); 138 137 139 138 ret = dwc3_pci_register_phys(glue);
+104 -8
drivers/usb/gadget/Kconfig
··· 192 192 help 193 193 Faraday usb device controller FUSB300 driver 194 194 195 + config USB_FOTG210_UDC 196 + tristate "Faraday FOTG210 USB Peripheral Controller" 197 + help 198 + Faraday USB2.0 OTG controller which can be configured as 199 + high speed or full speed USB device. This driver supppors 200 + Bulk Transfer so far. 201 + 202 + Say "y" to link the driver statically, or "m" to build a 203 + dynamically linked module called "fotg210_udc". 204 + 195 205 config USB_OMAP 196 206 tristate "OMAP USB Device Controller" 197 207 depends on ARCH_OMAP1 ··· 343 333 # 344 334 # Controllers available in both integrated and discrete versions 345 335 # 346 - 347 - # musb builds in ../musb along with host support 348 - config USB_GADGET_MUSB_HDRC 349 - tristate "Inventra HDRC USB Peripheral (TI, ADI, ...)" 350 - depends on USB_MUSB_HDRC 351 - help 352 - This OTG-capable silicon IP is used in dual designs including 353 - the TI DaVinci, OMAP 243x, OMAP 343x, TUSB 6010, and ADI Blackfin 354 336 355 337 config USB_M66592 356 338 tristate "Renesas M66592 USB Peripheral Controller" ··· 509 507 config USB_U_SERIAL 510 508 tristate 511 509 510 + config USB_U_ETHER 511 + tristate 512 + 513 + config USB_U_RNDIS 514 + tristate 515 + 512 516 config USB_F_SERIAL 513 517 tristate 514 518 515 519 config USB_F_OBEX 520 + tristate 521 + 522 + config USB_F_NCM 523 + tristate 524 + 525 + config USB_F_ECM 526 + tristate 527 + 528 + config USB_F_PHONET 529 + tristate 530 + 531 + config USB_F_EEM 532 + tristate 533 + 534 + config USB_F_SUBSET 535 + tristate 536 + 537 + config USB_F_RNDIS 516 538 tristate 517 539 518 540 choice ··· 559 533 a less common variant of a device class protocol. 560 534 561 535 # this first set of drivers all depend on bulk-capable hardware. 536 + 537 + config USB_CONFIGFS_ECM_SUBSET 538 + boolean "Ethernet Control Model (CDC ECM) subset" 539 + depends on USB_CONFIGFS 540 + depends on NET 541 + select USB_U_ETHER 542 + select USB_F_SUBSET 543 + help 544 + On hardware that can't implement the full protocol, 545 + a simple CDC subset is used, placing fewer demands on USB. 546 + 547 + config USB_CONFIGFS_RNDIS 548 + bool "RNDIS" 549 + depends on USB_CONFIGFS 550 + depends on NET 551 + select USB_U_ETHER 552 + select USB_F_RNDIS 553 + help 554 + Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, 555 + and Microsoft provides redistributable binary RNDIS drivers for 556 + older versions of Windows. 557 + 558 + To make MS-Windows work with this, use Documentation/usb/linux.inf 559 + as the "driver info file". For versions of MS-Windows older than 560 + XP, you'll need to download drivers from Microsoft's website; a URL 561 + is given in comments found in that info file. 562 + 563 + config USB_CONFIGFS_EEM 564 + bool "Ethernet Emulation Model (EEM)" 565 + depends on USB_CONFIGFS 566 + depends on NET 567 + select USB_U_ETHER 568 + select USB_F_EEM 569 + help 570 + CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM 571 + and therefore can be supported by more hardware. Technically ECM and 572 + EEM are designed for different applications. The ECM model extends 573 + the network interface to the target (e.g. a USB cable modem), and the 574 + EEM model is for mobile devices to communicate with hosts using 575 + ethernet over USB. For Linux gadgets, however, the interface with 576 + the host is the same (a usbX device), so the differences are minimal. 577 + 578 + config USB_CONFIGFS_PHONET 579 + boolean "Phonet protocol" 580 + depends on USB_CONFIGFS 581 + depends on NET 582 + depends on PHONET 583 + select USB_U_ETHER 584 + select USB_F_PHONET 585 + help 586 + The Phonet protocol implementation for USB device. 562 587 563 588 config USB_ZERO 564 589 tristate "Gadget Zero (DEVELOPMENT)" ··· 680 603 tristate "Ethernet Gadget (with CDC Ethernet support)" 681 604 depends on NET 682 605 select USB_LIBCOMPOSITE 606 + select USB_U_ETHER 607 + select USB_U_RNDIS 608 + select USB_F_ECM 609 + select USB_F_SUBSET 683 610 select CRC32 684 611 help 685 612 This driver implements Ethernet style communication, in one of ··· 720 639 bool "RNDIS support" 721 640 depends on USB_ETH 722 641 select USB_LIBCOMPOSITE 642 + select USB_F_RNDIS 723 643 default y 724 644 help 725 645 Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, ··· 740 658 bool "Ethernet Emulation Model (EEM) support" 741 659 depends on USB_ETH 742 660 select USB_LIBCOMPOSITE 661 + select USB_F_EEM 743 662 default n 744 663 help 745 664 CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM ··· 758 675 tristate "Network Control Model (NCM) support" 759 676 depends on NET 760 677 select USB_LIBCOMPOSITE 678 + select USB_U_ETHER 679 + select USB_F_NCM 761 680 select CRC32 762 681 help 763 682 This driver implements USB CDC NCM subclass standard. NCM is ··· 803 718 config USB_FUNCTIONFS_ETH 804 719 bool "Include configuration with CDC ECM (Ethernet)" 805 720 depends on USB_FUNCTIONFS && NET 721 + select USB_U_ETHER 806 722 help 807 723 Include a configuration with CDC ECM function (Ethernet) and the 808 724 Function Filesystem. ··· 811 725 config USB_FUNCTIONFS_RNDIS 812 726 bool "Include configuration with RNDIS (Ethernet)" 813 727 depends on USB_FUNCTIONFS && NET 728 + select USB_U_ETHER 729 + select USB_U_RNDIS 814 730 help 815 731 Include a configuration with RNDIS function (Ethernet) and the Filesystem. 816 732 ··· 913 825 depends on NET 914 826 select USB_LIBCOMPOSITE 915 827 select USB_U_SERIAL 828 + select USB_U_ETHER 916 829 select USB_F_ACM 830 + select USB_F_ECM 917 831 help 918 832 This driver provides two functions in one configuration: 919 833 a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link. ··· 932 842 depends on PHONET 933 843 select USB_LIBCOMPOSITE 934 844 select USB_U_SERIAL 845 + select USB_U_ETHER 935 846 select USB_F_ACM 847 + select USB_F_OBEX 848 + select USB_F_PHONET 849 + select USB_F_ECM 936 850 help 937 851 The Nokia composite gadget provides support for acm, obex 938 852 and phonet in only one composite gadget driver. ··· 963 869 select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS 964 870 select USB_LIBCOMPOSITE 965 871 select USB_U_SERIAL 872 + select USB_U_ETHER 873 + select USB_U_RNDIS 966 874 select USB_F_ACM 967 875 help 968 876 The Multifunction Composite Gadget provides Ethernet (RNDIS
+16
drivers/usb/gadget/Makefile
··· 33 33 obj-$(CONFIG_USB_MV_UDC) += mv_udc.o 34 34 mv_udc-y := mv_udc_core.o 35 35 obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o 36 + obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o 36 37 obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o 37 38 38 39 # USB Functions ··· 46 45 obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o 47 46 usb_f_obex-y := f_obex.o 48 47 obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o 48 + obj-$(CONFIG_USB_U_ETHER) += u_ether.o 49 + u_rndis-y := rndis.o 50 + obj-$(CONFIG_USB_U_RNDIS) += u_rndis.o 51 + usb_f_ncm-y := f_ncm.o 52 + obj-$(CONFIG_USB_F_NCM) += usb_f_ncm.o 53 + usb_f_ecm-y := f_ecm.o 54 + obj-$(CONFIG_USB_F_ECM) += usb_f_ecm.o 55 + usb_f_phonet-y := f_phonet.o 56 + obj-$(CONFIG_USB_F_PHONET) += usb_f_phonet.o 57 + usb_f_eem-y := f_eem.o 58 + obj-$(CONFIG_USB_F_EEM) += usb_f_eem.o 59 + usb_f_ecm_subset-y := f_subset.o 60 + obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o 61 + usb_f_rndis-y := f_rndis.o 62 + obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o 49 63 50 64 # 51 65 # USB gadget drivers
+60 -25
drivers/usb/gadget/cdc2.c
··· 15 15 16 16 #include "u_ether.h" 17 17 #include "u_serial.h" 18 + #include "u_ecm.h" 18 19 19 20 20 21 #define DRIVER_DESC "CDC Composite Gadget" ··· 33 32 #define CDC_VENDOR_NUM 0x0525 /* NetChip */ 34 33 #define CDC_PRODUCT_NUM 0xa4aa /* CDC Composite: ECM + ACM */ 35 34 36 - /*-------------------------------------------------------------------------*/ 37 35 USB_GADGET_COMPOSITE_OPTIONS(); 38 36 39 - /* 40 - * Kbuild is not very cooperative with respect to linking separately 41 - * compiled library objects into one module. So for now we won't use 42 - * separate compilation ... ensuring init/exit sections work to shrink 43 - * the runtime footprint, and giving us at least some parts of what 44 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 45 - */ 46 - #include "f_ecm.c" 47 - #include "u_ether.c" 37 + USB_ETHERNET_MODULE_PARAMETERS(); 48 38 49 39 /*-------------------------------------------------------------------------*/ 50 40 ··· 94 102 NULL, 95 103 }; 96 104 97 - static u8 hostaddr[ETH_ALEN]; 98 - static struct eth_dev *the_dev; 99 105 /*-------------------------------------------------------------------------*/ 100 106 static struct usb_function *f_acm; 101 107 static struct usb_function_instance *fi_serial; 108 + 109 + static struct usb_function *f_ecm; 110 + static struct usb_function_instance *fi_ecm; 102 111 103 112 /* 104 113 * We _always_ have both CDC ECM and CDC ACM functions. ··· 113 120 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 114 121 } 115 122 116 - status = ecm_bind_config(c, hostaddr, the_dev); 117 - if (status < 0) 118 - return status; 123 + fi_ecm = usb_get_function_instance("ecm"); 124 + if (IS_ERR(fi_ecm)) { 125 + status = PTR_ERR(fi_ecm); 126 + goto err_func_ecm; 127 + } 128 + 129 + f_ecm = usb_get_function(fi_ecm); 130 + if (IS_ERR(f_ecm)) { 131 + status = PTR_ERR(f_ecm); 132 + goto err_get_ecm; 133 + } 134 + 135 + status = usb_add_function(c, f_ecm); 136 + if (status) 137 + goto err_add_ecm; 119 138 120 139 fi_serial = usb_get_function_instance("acm"); 121 - if (IS_ERR(fi_serial)) 122 - return PTR_ERR(fi_serial); 140 + if (IS_ERR(fi_serial)) { 141 + status = PTR_ERR(fi_serial); 142 + goto err_get_acm; 143 + } 123 144 124 145 f_acm = usb_get_function(fi_serial); 125 146 if (IS_ERR(f_acm)) { ··· 143 136 144 137 status = usb_add_function(c, f_acm); 145 138 if (status) 146 - goto err_conf; 139 + goto err_add_acm; 140 + 147 141 return 0; 148 - err_conf: 142 + 143 + err_add_acm: 149 144 usb_put_function(f_acm); 150 145 err_func_acm: 151 146 usb_put_function_instance(fi_serial); 147 + err_get_acm: 148 + usb_remove_function(c, f_ecm); 149 + err_add_ecm: 150 + usb_put_function(f_ecm); 151 + err_get_ecm: 152 + usb_put_function_instance(fi_ecm); 153 + err_func_ecm: 152 154 return status; 153 155 } 154 156 ··· 173 157 static int __init cdc_bind(struct usb_composite_dev *cdev) 174 158 { 175 159 struct usb_gadget *gadget = cdev->gadget; 160 + struct f_ecm_opts *ecm_opts; 176 161 int status; 177 162 178 163 if (!can_support_ecm(cdev->gadget)) { ··· 182 165 return -EINVAL; 183 166 } 184 167 185 - /* set up network link layer */ 186 - the_dev = gether_setup(cdev->gadget, hostaddr); 187 - if (IS_ERR(the_dev)) 188 - return PTR_ERR(the_dev); 168 + fi_ecm = usb_get_function_instance("ecm"); 169 + if (IS_ERR(fi_ecm)) 170 + return PTR_ERR(fi_ecm); 171 + 172 + ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); 173 + 174 + gether_set_qmult(ecm_opts->net, qmult); 175 + if (!gether_set_host_addr(ecm_opts->net, host_addr)) 176 + pr_info("using host ethernet address: %s", host_addr); 177 + if (!gether_set_dev_addr(ecm_opts->net, dev_addr)) 178 + pr_info("using self ethernet address: %s", dev_addr); 179 + 180 + fi_serial = usb_get_function_instance("acm"); 181 + if (IS_ERR(fi_serial)) { 182 + status = PTR_ERR(fi_serial); 183 + goto fail; 184 + } 189 185 190 186 /* Allocate string descriptor numbers ... note that string 191 187 * contents can be overridden by the composite_dev glue. ··· 222 192 return 0; 223 193 224 194 fail1: 225 - gether_cleanup(the_dev); 195 + usb_put_function_instance(fi_serial); 196 + fail: 197 + usb_put_function_instance(fi_ecm); 226 198 return status; 227 199 } 228 200 ··· 232 200 { 233 201 usb_put_function(f_acm); 234 202 usb_put_function_instance(fi_serial); 235 - gether_cleanup(the_dev); 203 + if (!IS_ERR_OR_NULL(f_ecm)) 204 + usb_put_function(f_ecm); 205 + if (!IS_ERR_OR_NULL(fi_ecm)) 206 + usb_put_function_instance(fi_ecm); 236 207 return 0; 237 208 } 238 209
+146 -34
drivers/usb/gadget/ether.c
··· 14 14 /* #define VERBOSE_DEBUG */ 15 15 16 16 #include <linux/kernel.h> 17 + #include <linux/netdevice.h> 17 18 18 19 #if defined USB_ETH_RNDIS 19 20 # undef USB_ETH_RNDIS ··· 92 91 #endif 93 92 } 94 93 95 - /*-------------------------------------------------------------------------*/ 94 + #include <linux/module.h> 96 95 97 - /* 98 - * Kbuild is not very cooperative with respect to linking separately 99 - * compiled library objects into one module. So for now we won't use 100 - * separate compilation ... ensuring init/exit sections work to shrink 101 - * the runtime footprint, and giving us at least some parts of what 102 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 103 - */ 104 - #include "f_ecm.c" 105 - #include "f_subset.c" 96 + #include "u_ecm.h" 97 + #include "u_gether.h" 106 98 #ifdef USB_ETH_RNDIS 107 - #include "f_rndis.c" 108 - #include "rndis.c" 99 + #include "u_rndis.h" 100 + #include "rndis.h" 101 + #else 102 + #define rndis_borrow_net(...) do {} while (0) 109 103 #endif 110 - #include "f_eem.c" 111 - #include "u_ether.c" 104 + #include "u_eem.h" 112 105 113 106 /*-------------------------------------------------------------------------*/ 114 107 USB_GADGET_COMPOSITE_OPTIONS(); 108 + 109 + USB_ETHERNET_MODULE_PARAMETERS(); 115 110 116 111 /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! 117 112 * Instead: allocate your own, using normal USB-IF procedures. ··· 203 206 NULL, 204 207 }; 205 208 206 - static u8 hostaddr[ETH_ALEN]; 207 - static struct eth_dev *the_dev; 209 + static struct usb_function_instance *fi_ecm; 210 + static struct usb_function *f_ecm; 211 + 212 + static struct usb_function_instance *fi_eem; 213 + static struct usb_function *f_eem; 214 + 215 + static struct usb_function_instance *fi_geth; 216 + static struct usb_function *f_geth; 217 + 218 + static struct usb_function_instance *fi_rndis; 219 + static struct usb_function *f_rndis; 220 + 208 221 /*-------------------------------------------------------------------------*/ 209 222 210 223 /* ··· 224 217 */ 225 218 static int __init rndis_do_config(struct usb_configuration *c) 226 219 { 220 + int status; 221 + 227 222 /* FIXME alloc iConfiguration string, set it in c->strings */ 228 223 229 224 if (gadget_is_otg(c->cdev->gadget)) { ··· 233 224 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 234 225 } 235 226 236 - return rndis_bind_config(c, hostaddr, the_dev); 227 + f_rndis = usb_get_function(fi_rndis); 228 + if (IS_ERR(f_rndis)) 229 + return PTR_ERR(f_rndis); 230 + 231 + status = usb_add_function(c, f_rndis); 232 + if (status < 0) 233 + usb_put_function(f_rndis); 234 + 235 + return status; 237 236 } 238 237 239 238 static struct usb_configuration rndis_config_driver = { ··· 266 249 */ 267 250 static int __init eth_do_config(struct usb_configuration *c) 268 251 { 252 + int status = 0; 253 + 269 254 /* FIXME alloc iConfiguration string, set it in c->strings */ 270 255 271 256 if (gadget_is_otg(c->cdev->gadget)) { ··· 275 256 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 276 257 } 277 258 278 - if (use_eem) 279 - return eem_bind_config(c, the_dev); 280 - else if (can_support_ecm(c->cdev->gadget)) 281 - return ecm_bind_config(c, hostaddr, the_dev); 282 - else 283 - return geth_bind_config(c, hostaddr, the_dev); 259 + if (use_eem) { 260 + f_eem = usb_get_function(fi_eem); 261 + if (IS_ERR(f_eem)) 262 + return PTR_ERR(f_eem); 263 + 264 + status = usb_add_function(c, f_eem); 265 + if (status < 0) 266 + usb_put_function(f_eem); 267 + 268 + return status; 269 + } else if (can_support_ecm(c->cdev->gadget)) { 270 + f_ecm = usb_get_function(fi_ecm); 271 + if (IS_ERR(f_ecm)) 272 + return PTR_ERR(f_ecm); 273 + 274 + status = usb_add_function(c, f_ecm); 275 + if (status < 0) 276 + usb_put_function(f_ecm); 277 + 278 + return status; 279 + } else { 280 + f_geth = usb_get_function(fi_geth); 281 + if (IS_ERR(f_geth)) 282 + return PTR_ERR(f_geth); 283 + 284 + status = usb_add_function(c, f_geth); 285 + if (status < 0) 286 + usb_put_function(f_geth); 287 + 288 + return status; 289 + } 290 + 284 291 } 285 292 286 293 static struct usb_configuration eth_config_driver = { ··· 321 276 static int __init eth_bind(struct usb_composite_dev *cdev) 322 277 { 323 278 struct usb_gadget *gadget = cdev->gadget; 279 + struct f_eem_opts *eem_opts = NULL; 280 + struct f_ecm_opts *ecm_opts = NULL; 281 + struct f_gether_opts *geth_opts = NULL; 282 + struct net_device *net; 324 283 int status; 325 - 326 - /* set up network link layer */ 327 - the_dev = gether_setup(cdev->gadget, hostaddr); 328 - if (IS_ERR(the_dev)) 329 - return PTR_ERR(the_dev); 330 284 331 285 /* set up main config label and device descriptor */ 332 286 if (use_eem) { 333 287 /* EEM */ 288 + fi_eem = usb_get_function_instance("eem"); 289 + if (IS_ERR(fi_eem)) 290 + return PTR_ERR(fi_eem); 291 + 292 + eem_opts = container_of(fi_eem, struct f_eem_opts, func_inst); 293 + 294 + net = eem_opts->net; 295 + 334 296 eth_config_driver.label = "CDC Ethernet (EEM)"; 335 297 device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM); 336 298 device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM); 337 - } else if (can_support_ecm(cdev->gadget)) { 299 + } else if (can_support_ecm(gadget)) { 338 300 /* ECM */ 301 + 302 + fi_ecm = usb_get_function_instance("ecm"); 303 + if (IS_ERR(fi_ecm)) 304 + return PTR_ERR(fi_ecm); 305 + 306 + ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); 307 + 308 + net = ecm_opts->net; 309 + 339 310 eth_config_driver.label = "CDC Ethernet (ECM)"; 340 311 } else { 341 312 /* CDC Subset */ 313 + 314 + fi_geth = usb_get_function_instance("geth"); 315 + if (IS_ERR(fi_geth)) 316 + return PTR_ERR(fi_geth); 317 + 318 + geth_opts = container_of(fi_geth, struct f_gether_opts, 319 + func_inst); 320 + 321 + net = geth_opts->net; 322 + 342 323 eth_config_driver.label = "CDC Subset/SAFE"; 343 324 344 325 device_desc.idVendor = cpu_to_le16(SIMPLE_VENDOR_NUM); ··· 373 302 device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC; 374 303 } 375 304 305 + gether_set_qmult(net, qmult); 306 + if (!gether_set_host_addr(net, host_addr)) 307 + pr_info("using host ethernet address: %s", host_addr); 308 + if (!gether_set_dev_addr(net, dev_addr)) 309 + pr_info("using self ethernet address: %s", dev_addr); 310 + 376 311 if (has_rndis()) { 377 312 /* RNDIS plus ECM-or-Subset */ 313 + gether_set_gadget(net, cdev->gadget); 314 + status = gether_register_netdev(net); 315 + if (status) 316 + goto fail; 317 + 318 + if (use_eem) 319 + eem_opts->bound = true; 320 + else if (can_support_ecm(gadget)) 321 + ecm_opts->bound = true; 322 + else 323 + geth_opts->bound = true; 324 + 325 + fi_rndis = usb_get_function_instance("rndis"); 326 + if (IS_ERR(fi_rndis)) { 327 + status = PTR_ERR(fi_rndis); 328 + goto fail; 329 + } 330 + 331 + rndis_borrow_net(fi_rndis, net); 332 + 378 333 device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM); 379 334 device_desc.idProduct = cpu_to_le16(RNDIS_PRODUCT_NUM); 380 335 device_desc.bNumConfigurations = 2; ··· 412 315 413 316 status = usb_string_ids_tab(cdev, strings_dev); 414 317 if (status < 0) 415 - goto fail; 318 + goto fail1; 416 319 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; 417 320 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 418 321 ··· 421 324 status = usb_add_config(cdev, &rndis_config_driver, 422 325 rndis_do_config); 423 326 if (status < 0) 424 - goto fail; 327 + goto fail1; 425 328 } 426 329 427 330 status = usb_add_config(cdev, &eth_config_driver, eth_do_config); 428 331 if (status < 0) 429 - goto fail; 332 + goto fail1; 430 333 431 334 usb_composite_overwrite_options(cdev, &coverwrite); 432 335 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", ··· 434 337 435 338 return 0; 436 339 340 + fail1: 341 + if (has_rndis()) 342 + usb_put_function_instance(fi_rndis); 437 343 fail: 438 - gether_cleanup(the_dev); 344 + if (use_eem) 345 + usb_put_function_instance(fi_eem); 346 + else if (can_support_ecm(gadget)) 347 + usb_put_function_instance(fi_ecm); 348 + else 349 + usb_put_function_instance(fi_geth); 439 350 return status; 440 351 } 441 352 442 353 static int __exit eth_unbind(struct usb_composite_dev *cdev) 443 354 { 444 - gether_cleanup(the_dev); 355 + if (has_rndis()) 356 + usb_put_function_instance(fi_rndis); 357 + if (use_eem) 358 + usb_put_function_instance(fi_eem); 359 + else if (can_support_ecm(cdev->gadget)) 360 + usb_put_function_instance(fi_ecm); 361 + else 362 + usb_put_function_instance(fi_geth); 445 363 return 0; 446 364 } 447 365
+181 -15
drivers/usb/gadget/f_ecm.c
··· 14 14 15 15 #include <linux/slab.h> 16 16 #include <linux/kernel.h> 17 + #include <linux/module.h> 17 18 #include <linux/device.h> 18 19 #include <linux/etherdevice.h> 19 20 20 21 #include "u_ether.h" 22 + #include "u_ether_configfs.h" 23 + #include "u_ecm.h" 21 24 22 25 23 26 /* ··· 687 684 { 688 685 struct usb_composite_dev *cdev = c->cdev; 689 686 struct f_ecm *ecm = func_to_ecm(f); 687 + struct usb_string *us; 690 688 int status; 691 689 struct usb_ep *ep; 690 + 691 + #ifndef USBF_ECM_INCLUDED 692 + struct f_ecm_opts *ecm_opts; 693 + 694 + if (!can_support_ecm(cdev->gadget)) 695 + return -EINVAL; 696 + 697 + ecm_opts = container_of(f->fi, struct f_ecm_opts, func_inst); 698 + 699 + /* 700 + * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 701 + * configurations are bound in sequence with list_for_each_entry, 702 + * in each configuration its functions are bound in sequence 703 + * with list_for_each_entry, so we assume no race condition 704 + * with regard to ecm_opts->bound access 705 + */ 706 + if (!ecm_opts->bound) { 707 + mutex_lock(&ecm_opts->lock); 708 + gether_set_gadget(ecm_opts->net, cdev->gadget); 709 + status = gether_register_netdev(ecm_opts->net); 710 + mutex_unlock(&ecm_opts->lock); 711 + if (status) 712 + return status; 713 + ecm_opts->bound = true; 714 + } 715 + #endif 716 + us = usb_gstrings_attach(cdev, ecm_strings, 717 + ARRAY_SIZE(ecm_string_defs)); 718 + if (IS_ERR(us)) 719 + return PTR_ERR(us); 720 + ecm_control_intf.iInterface = us[0].id; 721 + ecm_data_intf.iInterface = us[2].id; 722 + ecm_desc.iMACAddress = us[1].id; 723 + ecm_iad_descriptor.iFunction = us[3].id; 692 724 693 725 /* allocate instance-specific interface IDs */ 694 726 status = usb_interface_id(c, f); ··· 834 796 return status; 835 797 } 836 798 799 + #ifdef USBF_ECM_INCLUDED 800 + 837 801 static void 838 - ecm_unbind(struct usb_configuration *c, struct usb_function *f) 802 + ecm_old_unbind(struct usb_configuration *c, struct usb_function *f) 839 803 { 840 804 struct f_ecm *ecm = func_to_ecm(f); 841 805 842 806 DBG(c->cdev, "ecm unbind\n"); 843 807 844 - ecm_string_defs[0].id = 0; 845 808 usb_free_all_descriptors(f); 846 809 847 810 kfree(ecm->notify_req->buf); ··· 873 834 if (!can_support_ecm(c->cdev->gadget) || !ethaddr) 874 835 return -EINVAL; 875 836 876 - if (ecm_string_defs[0].id == 0) { 877 - status = usb_string_ids_tab(c->cdev, ecm_string_defs); 878 - if (status) 879 - return status; 880 - 881 - ecm_control_intf.iInterface = ecm_string_defs[0].id; 882 - ecm_data_intf.iInterface = ecm_string_defs[2].id; 883 - ecm_desc.iMACAddress = ecm_string_defs[1].id; 884 - ecm_iad_descriptor.iFunction = ecm_string_defs[3].id; 885 - } 886 - 887 837 /* allocate and initialize one new instance */ 888 838 ecm = kzalloc(sizeof *ecm, GFP_KERNEL); 889 839 if (!ecm) ··· 886 858 ecm->port.cdc_filter = DEFAULT_FILTER; 887 859 888 860 ecm->port.func.name = "cdc_ethernet"; 889 - ecm->port.func.strings = ecm_strings; 890 861 /* descriptors are per-instance copies */ 891 862 ecm->port.func.bind = ecm_bind; 892 - ecm->port.func.unbind = ecm_unbind; 863 + ecm->port.func.unbind = ecm_old_unbind; 893 864 ecm->port.func.set_alt = ecm_set_alt; 894 865 ecm->port.func.get_alt = ecm_get_alt; 895 866 ecm->port.func.setup = ecm_setup; ··· 899 872 kfree(ecm); 900 873 return status; 901 874 } 875 + 876 + #else 877 + 878 + static inline struct f_ecm_opts *to_f_ecm_opts(struct config_item *item) 879 + { 880 + return container_of(to_config_group(item), struct f_ecm_opts, 881 + func_inst.group); 882 + } 883 + 884 + /* f_ecm_item_ops */ 885 + USB_ETHERNET_CONFIGFS_ITEM(ecm); 886 + 887 + /* f_ecm_opts_dev_addr */ 888 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ecm); 889 + 890 + /* f_ecm_opts_host_addr */ 891 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ecm); 892 + 893 + /* f_ecm_opts_qmult */ 894 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ecm); 895 + 896 + /* f_ecm_opts_ifname */ 897 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ecm); 898 + 899 + static struct configfs_attribute *ecm_attrs[] = { 900 + &f_ecm_opts_dev_addr.attr, 901 + &f_ecm_opts_host_addr.attr, 902 + &f_ecm_opts_qmult.attr, 903 + &f_ecm_opts_ifname.attr, 904 + NULL, 905 + }; 906 + 907 + static struct config_item_type ecm_func_type = { 908 + .ct_item_ops = &ecm_item_ops, 909 + .ct_attrs = ecm_attrs, 910 + .ct_owner = THIS_MODULE, 911 + }; 912 + 913 + static void ecm_free_inst(struct usb_function_instance *f) 914 + { 915 + struct f_ecm_opts *opts; 916 + 917 + opts = container_of(f, struct f_ecm_opts, func_inst); 918 + if (opts->bound) 919 + gether_cleanup(netdev_priv(opts->net)); 920 + else 921 + free_netdev(opts->net); 922 + kfree(opts); 923 + } 924 + 925 + static struct usb_function_instance *ecm_alloc_inst(void) 926 + { 927 + struct f_ecm_opts *opts; 928 + 929 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 930 + if (!opts) 931 + return ERR_PTR(-ENOMEM); 932 + mutex_init(&opts->lock); 933 + opts->func_inst.free_func_inst = ecm_free_inst; 934 + opts->net = gether_setup_default(); 935 + if (IS_ERR(opts->net)) 936 + return ERR_PTR(PTR_ERR(opts->net)); 937 + 938 + config_group_init_type_name(&opts->func_inst.group, "", &ecm_func_type); 939 + 940 + return &opts->func_inst; 941 + } 942 + 943 + static void ecm_free(struct usb_function *f) 944 + { 945 + struct f_ecm *ecm; 946 + struct f_ecm_opts *opts; 947 + 948 + ecm = func_to_ecm(f); 949 + opts = container_of(f->fi, struct f_ecm_opts, func_inst); 950 + kfree(ecm); 951 + mutex_lock(&opts->lock); 952 + opts->refcnt--; 953 + mutex_unlock(&opts->lock); 954 + } 955 + 956 + static void ecm_unbind(struct usb_configuration *c, struct usb_function *f) 957 + { 958 + struct f_ecm *ecm = func_to_ecm(f); 959 + 960 + DBG(c->cdev, "ecm unbind\n"); 961 + 962 + usb_free_all_descriptors(f); 963 + 964 + kfree(ecm->notify_req->buf); 965 + usb_ep_free_request(ecm->notify, ecm->notify_req); 966 + } 967 + 968 + struct usb_function *ecm_alloc(struct usb_function_instance *fi) 969 + { 970 + struct f_ecm *ecm; 971 + struct f_ecm_opts *opts; 972 + int status; 973 + 974 + /* allocate and initialize one new instance */ 975 + ecm = kzalloc(sizeof(*ecm), GFP_KERNEL); 976 + if (!ecm) 977 + return ERR_PTR(-ENOMEM); 978 + 979 + opts = container_of(fi, struct f_ecm_opts, func_inst); 980 + mutex_lock(&opts->lock); 981 + opts->refcnt++; 982 + 983 + /* export host's Ethernet address in CDC format */ 984 + status = gether_get_host_addr_cdc(opts->net, ecm->ethaddr, 985 + sizeof(ecm->ethaddr)); 986 + if (status < 12) { 987 + kfree(ecm); 988 + return ERR_PTR(-EINVAL); 989 + } 990 + ecm_string_defs[1].s = ecm->ethaddr; 991 + 992 + ecm->port.ioport = netdev_priv(opts->net); 993 + mutex_unlock(&opts->lock); 994 + ecm->port.cdc_filter = DEFAULT_FILTER; 995 + 996 + ecm->port.func.name = "cdc_ethernet"; 997 + /* descriptors are per-instance copies */ 998 + ecm->port.func.bind = ecm_bind; 999 + ecm->port.func.unbind = ecm_unbind; 1000 + ecm->port.func.set_alt = ecm_set_alt; 1001 + ecm->port.func.get_alt = ecm_get_alt; 1002 + ecm->port.func.setup = ecm_setup; 1003 + ecm->port.func.disable = ecm_disable; 1004 + ecm->port.func.free_func = ecm_free; 1005 + 1006 + return &ecm->port.func; 1007 + } 1008 + 1009 + DECLARE_USB_FUNCTION_INIT(ecm, ecm_alloc_inst, ecm_alloc); 1010 + MODULE_LICENSE("GPL"); 1011 + MODULE_AUTHOR("David Brownell"); 1012 + 1013 + #endif
+142 -55
drivers/usb/gadget/f_eem.c
··· 12 12 */ 13 13 14 14 #include <linux/kernel.h> 15 + #include <linux/module.h> 15 16 #include <linux/device.h> 16 17 #include <linux/etherdevice.h> 17 18 #include <linux/crc32.h> 18 19 #include <linux/slab.h> 19 20 20 21 #include "u_ether.h" 22 + #include "u_ether_configfs.h" 23 + #include "u_eem.h" 21 24 22 25 #define EEM_HLEN 2 23 26 ··· 43 40 44 41 /* interface descriptor: */ 45 42 46 - static struct usb_interface_descriptor eem_intf __initdata = { 43 + static struct usb_interface_descriptor eem_intf = { 47 44 .bLength = sizeof eem_intf, 48 45 .bDescriptorType = USB_DT_INTERFACE, 49 46 ··· 57 54 58 55 /* full speed support: */ 59 56 60 - static struct usb_endpoint_descriptor eem_fs_in_desc __initdata = { 57 + static struct usb_endpoint_descriptor eem_fs_in_desc = { 61 58 .bLength = USB_DT_ENDPOINT_SIZE, 62 59 .bDescriptorType = USB_DT_ENDPOINT, 63 60 ··· 65 62 .bmAttributes = USB_ENDPOINT_XFER_BULK, 66 63 }; 67 64 68 - static struct usb_endpoint_descriptor eem_fs_out_desc __initdata = { 65 + static struct usb_endpoint_descriptor eem_fs_out_desc = { 69 66 .bLength = USB_DT_ENDPOINT_SIZE, 70 67 .bDescriptorType = USB_DT_ENDPOINT, 71 68 ··· 73 70 .bmAttributes = USB_ENDPOINT_XFER_BULK, 74 71 }; 75 72 76 - static struct usb_descriptor_header *eem_fs_function[] __initdata = { 73 + static struct usb_descriptor_header *eem_fs_function[] = { 77 74 /* CDC EEM control descriptors */ 78 75 (struct usb_descriptor_header *) &eem_intf, 79 76 (struct usb_descriptor_header *) &eem_fs_in_desc, ··· 83 80 84 81 /* high speed support: */ 85 82 86 - static struct usb_endpoint_descriptor eem_hs_in_desc __initdata = { 83 + static struct usb_endpoint_descriptor eem_hs_in_desc = { 87 84 .bLength = USB_DT_ENDPOINT_SIZE, 88 85 .bDescriptorType = USB_DT_ENDPOINT, 89 86 ··· 92 89 .wMaxPacketSize = cpu_to_le16(512), 93 90 }; 94 91 95 - static struct usb_endpoint_descriptor eem_hs_out_desc __initdata = { 92 + static struct usb_endpoint_descriptor eem_hs_out_desc = { 96 93 .bLength = USB_DT_ENDPOINT_SIZE, 97 94 .bDescriptorType = USB_DT_ENDPOINT, 98 95 ··· 101 98 .wMaxPacketSize = cpu_to_le16(512), 102 99 }; 103 100 104 - static struct usb_descriptor_header *eem_hs_function[] __initdata = { 101 + static struct usb_descriptor_header *eem_hs_function[] = { 105 102 /* CDC EEM control descriptors */ 106 103 (struct usb_descriptor_header *) &eem_intf, 107 104 (struct usb_descriptor_header *) &eem_hs_in_desc, ··· 111 108 112 109 /* super speed support: */ 113 110 114 - static struct usb_endpoint_descriptor eem_ss_in_desc __initdata = { 111 + static struct usb_endpoint_descriptor eem_ss_in_desc = { 115 112 .bLength = USB_DT_ENDPOINT_SIZE, 116 113 .bDescriptorType = USB_DT_ENDPOINT, 117 114 ··· 120 117 .wMaxPacketSize = cpu_to_le16(1024), 121 118 }; 122 119 123 - static struct usb_endpoint_descriptor eem_ss_out_desc __initdata = { 120 + static struct usb_endpoint_descriptor eem_ss_out_desc = { 124 121 .bLength = USB_DT_ENDPOINT_SIZE, 125 122 .bDescriptorType = USB_DT_ENDPOINT, 126 123 ··· 129 126 .wMaxPacketSize = cpu_to_le16(1024), 130 127 }; 131 128 132 - static struct usb_ss_ep_comp_descriptor eem_ss_bulk_comp_desc __initdata = { 129 + static struct usb_ss_ep_comp_descriptor eem_ss_bulk_comp_desc = { 133 130 .bLength = sizeof eem_ss_bulk_comp_desc, 134 131 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 135 132 ··· 138 135 /* .bmAttributes = 0, */ 139 136 }; 140 137 141 - static struct usb_descriptor_header *eem_ss_function[] __initdata = { 138 + static struct usb_descriptor_header *eem_ss_function[] = { 142 139 /* CDC EEM control descriptors */ 143 140 (struct usb_descriptor_header *) &eem_intf, 144 141 (struct usb_descriptor_header *) &eem_ss_in_desc, ··· 245 242 246 243 /* EEM function driver setup/binding */ 247 244 248 - static int __init 249 - eem_bind(struct usb_configuration *c, struct usb_function *f) 245 + static int eem_bind(struct usb_configuration *c, struct usb_function *f) 250 246 { 251 247 struct usb_composite_dev *cdev = c->cdev; 252 248 struct f_eem *eem = func_to_eem(f); 249 + struct usb_string *us; 253 250 int status; 254 251 struct usb_ep *ep; 252 + 253 + struct f_eem_opts *eem_opts; 254 + 255 + eem_opts = container_of(f->fi, struct f_eem_opts, func_inst); 256 + /* 257 + * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 258 + * configurations are bound in sequence with list_for_each_entry, 259 + * in each configuration its functions are bound in sequence 260 + * with list_for_each_entry, so we assume no race condition 261 + * with regard to eem_opts->bound access 262 + */ 263 + if (!eem_opts->bound) { 264 + mutex_lock(&eem_opts->lock); 265 + gether_set_gadget(eem_opts->net, cdev->gadget); 266 + status = gether_register_netdev(eem_opts->net); 267 + mutex_unlock(&eem_opts->lock); 268 + if (status) 269 + return status; 270 + eem_opts->bound = true; 271 + } 272 + 273 + us = usb_gstrings_attach(cdev, eem_strings, 274 + ARRAY_SIZE(eem_string_defs)); 275 + if (IS_ERR(us)) 276 + return PTR_ERR(us); 277 + eem_intf.iInterface = us[0].id; 255 278 256 279 /* allocate instance-specific interface IDs */ 257 280 status = usb_interface_id(c, f); ··· 334 305 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 335 306 336 307 return status; 337 - } 338 - 339 - static void 340 - eem_unbind(struct usb_configuration *c, struct usb_function *f) 341 - { 342 - struct f_eem *eem = func_to_eem(f); 343 - 344 - DBG(c->cdev, "eem unbind\n"); 345 - 346 - usb_free_all_descriptors(f); 347 - kfree(eem); 348 308 } 349 309 350 310 static void eem_cmd_complete(struct usb_ep *ep, struct usb_request *req) ··· 536 518 return status; 537 519 } 538 520 539 - /** 540 - * eem_bind_config - add CDC Ethernet (EEM) network link to a configuration 541 - * @c: the configuration to support the network link 542 - * Context: single threaded during gadget setup 543 - * 544 - * Returns zero on success, else negative errno. 545 - * 546 - * Caller must have called @gether_setup(). Caller is also responsible 547 - * for calling @gether_cleanup() before module unload. 548 - */ 549 - int __init eem_bind_config(struct usb_configuration *c, struct eth_dev *dev) 521 + static inline struct f_eem_opts *to_f_eem_opts(struct config_item *item) 522 + { 523 + return container_of(to_config_group(item), struct f_eem_opts, 524 + func_inst.group); 525 + } 526 + 527 + /* f_eem_item_ops */ 528 + USB_ETHERNET_CONFIGFS_ITEM(eem); 529 + 530 + /* f_eem_opts_dev_addr */ 531 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(eem); 532 + 533 + /* f_eem_opts_host_addr */ 534 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(eem); 535 + 536 + /* f_eem_opts_qmult */ 537 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(eem); 538 + 539 + /* f_eem_opts_ifname */ 540 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(eem); 541 + 542 + static struct configfs_attribute *eem_attrs[] = { 543 + &f_eem_opts_dev_addr.attr, 544 + &f_eem_opts_host_addr.attr, 545 + &f_eem_opts_qmult.attr, 546 + &f_eem_opts_ifname.attr, 547 + NULL, 548 + }; 549 + 550 + static struct config_item_type eem_func_type = { 551 + .ct_item_ops = &eem_item_ops, 552 + .ct_attrs = eem_attrs, 553 + .ct_owner = THIS_MODULE, 554 + }; 555 + 556 + static void eem_free_inst(struct usb_function_instance *f) 557 + { 558 + struct f_eem_opts *opts; 559 + 560 + opts = container_of(f, struct f_eem_opts, func_inst); 561 + if (opts->bound) 562 + gether_cleanup(netdev_priv(opts->net)); 563 + else 564 + free_netdev(opts->net); 565 + kfree(opts); 566 + } 567 + 568 + static struct usb_function_instance *eem_alloc_inst(void) 569 + { 570 + struct f_eem_opts *opts; 571 + 572 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 573 + if (!opts) 574 + return ERR_PTR(-ENOMEM); 575 + mutex_init(&opts->lock); 576 + opts->func_inst.free_func_inst = eem_free_inst; 577 + opts->net = gether_setup_default(); 578 + if (IS_ERR(opts->net)) 579 + return ERR_CAST(opts->net); 580 + 581 + config_group_init_type_name(&opts->func_inst.group, "", &eem_func_type); 582 + 583 + return &opts->func_inst; 584 + } 585 + 586 + static void eem_free(struct usb_function *f) 587 + { 588 + struct f_eem *eem; 589 + struct f_eem_opts *opts; 590 + 591 + eem = func_to_eem(f); 592 + opts = container_of(f->fi, struct f_eem_opts, func_inst); 593 + kfree(eem); 594 + mutex_lock(&opts->lock); 595 + opts->refcnt--; 596 + mutex_unlock(&opts->lock); 597 + } 598 + 599 + static void eem_unbind(struct usb_configuration *c, struct usb_function *f) 600 + { 601 + DBG(c->cdev, "eem unbind\n"); 602 + 603 + usb_free_all_descriptors(f); 604 + } 605 + 606 + struct usb_function *eem_alloc(struct usb_function_instance *fi) 550 607 { 551 608 struct f_eem *eem; 552 - int status; 553 - 554 - /* maybe allocate device-global string IDs */ 555 - if (eem_string_defs[0].id == 0) { 556 - 557 - /* control interface label */ 558 - status = usb_string_id(c->cdev); 559 - if (status < 0) 560 - return status; 561 - eem_string_defs[0].id = status; 562 - eem_intf.iInterface = status; 563 - } 609 + struct f_eem_opts *opts; 564 610 565 611 /* allocate and initialize one new instance */ 566 - eem = kzalloc(sizeof *eem, GFP_KERNEL); 612 + eem = kzalloc(sizeof(*eem), GFP_KERNEL); 567 613 if (!eem) 568 - return -ENOMEM; 614 + return ERR_PTR(-ENOMEM); 569 615 570 - eem->port.ioport = dev; 616 + opts = container_of(fi, struct f_eem_opts, func_inst); 617 + mutex_lock(&opts->lock); 618 + opts->refcnt++; 619 + 620 + eem->port.ioport = netdev_priv(opts->net); 621 + mutex_unlock(&opts->lock); 571 622 eem->port.cdc_filter = DEFAULT_FILTER; 572 623 573 624 eem->port.func.name = "cdc_eem"; 574 - eem->port.func.strings = eem_strings; 575 625 /* descriptors are per-instance copies */ 576 626 eem->port.func.bind = eem_bind; 577 627 eem->port.func.unbind = eem_unbind; 578 628 eem->port.func.set_alt = eem_set_alt; 579 629 eem->port.func.setup = eem_setup; 580 630 eem->port.func.disable = eem_disable; 631 + eem->port.func.free_func = eem_free; 581 632 eem->port.wrap = eem_wrap; 582 633 eem->port.unwrap = eem_unwrap; 583 634 eem->port.header_len = EEM_HLEN; 584 635 585 - status = usb_add_function(c, &eem->port.func); 586 - if (status) 587 - kfree(eem); 588 - return status; 636 + return &eem->port.func; 589 637 } 590 638 639 + DECLARE_USB_FUNCTION_INIT(eem, eem_alloc_inst, eem_alloc); 640 + MODULE_LICENSE("GPL"); 641 + MODULE_AUTHOR("David Brownell");
+4 -2
drivers/usb/gadget/f_mass_storage.c
··· 413 413 /* Caller must hold fsg->lock */ 414 414 static void wakeup_thread(struct fsg_common *common) 415 415 { 416 + smp_wmb(); /* ensure the write of bh->state is complete */ 416 417 /* Tell the main thread that something has happened */ 417 418 common->thread_wakeup_needed = 1; 418 419 if (common->thread_task) ··· 633 632 } 634 633 __set_current_state(TASK_RUNNING); 635 634 common->thread_wakeup_needed = 0; 635 + smp_rmb(); /* ensure the latest bh->state is visible */ 636 636 return rc; 637 637 } 638 638 ··· 2747 2745 "%-8s%-16s%04x", cfg->vendor_name ?: "Linux", 2748 2746 /* Assume product name dependent on the first LUN */ 2749 2747 cfg->product_name ?: (common->luns->cdrom 2750 - ? "File-Stor Gadget" 2751 - : "File-CD Gadget"), 2748 + ? "File-CD Gadget" 2749 + : "File-Stor Gadget"), 2752 2750 i); 2753 2751 2754 2752 /*
+156 -67
drivers/usb/gadget/f_ncm.c
··· 16 16 */ 17 17 18 18 #include <linux/kernel.h> 19 + #include <linux/module.h> 19 20 #include <linux/device.h> 20 21 #include <linux/etherdevice.h> 21 22 #include <linux/crc32.h> ··· 24 23 #include <linux/usb/cdc.h> 25 24 26 25 #include "u_ether.h" 26 + #include "u_ether_configfs.h" 27 + #include "u_ncm.h" 27 28 28 29 /* 29 30 * This function is a "CDC Network Control Model" (CDC NCM) Ethernet link. ··· 128 125 #define NCM_STATUS_INTERVAL_MS 32 129 126 #define NCM_STATUS_BYTECOUNT 16 /* 8 byte header + data */ 130 127 131 - static struct usb_interface_assoc_descriptor ncm_iad_desc __initdata = { 128 + static struct usb_interface_assoc_descriptor ncm_iad_desc = { 132 129 .bLength = sizeof ncm_iad_desc, 133 130 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, 134 131 ··· 142 139 143 140 /* interface descriptor: */ 144 141 145 - static struct usb_interface_descriptor ncm_control_intf __initdata = { 142 + static struct usb_interface_descriptor ncm_control_intf = { 146 143 .bLength = sizeof ncm_control_intf, 147 144 .bDescriptorType = USB_DT_INTERFACE, 148 145 ··· 154 151 /* .iInterface = DYNAMIC */ 155 152 }; 156 153 157 - static struct usb_cdc_header_desc ncm_header_desc __initdata = { 154 + static struct usb_cdc_header_desc ncm_header_desc = { 158 155 .bLength = sizeof ncm_header_desc, 159 156 .bDescriptorType = USB_DT_CS_INTERFACE, 160 157 .bDescriptorSubType = USB_CDC_HEADER_TYPE, ··· 162 159 .bcdCDC = cpu_to_le16(0x0110), 163 160 }; 164 161 165 - static struct usb_cdc_union_desc ncm_union_desc __initdata = { 162 + static struct usb_cdc_union_desc ncm_union_desc = { 166 163 .bLength = sizeof(ncm_union_desc), 167 164 .bDescriptorType = USB_DT_CS_INTERFACE, 168 165 .bDescriptorSubType = USB_CDC_UNION_TYPE, ··· 170 167 /* .bSlaveInterface0 = DYNAMIC */ 171 168 }; 172 169 173 - static struct usb_cdc_ether_desc ecm_desc __initdata = { 170 + static struct usb_cdc_ether_desc ecm_desc = { 174 171 .bLength = sizeof ecm_desc, 175 172 .bDescriptorType = USB_DT_CS_INTERFACE, 176 173 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE, ··· 185 182 186 183 #define NCAPS (USB_CDC_NCM_NCAP_ETH_FILTER | USB_CDC_NCM_NCAP_CRC_MODE) 187 184 188 - static struct usb_cdc_ncm_desc ncm_desc __initdata = { 185 + static struct usb_cdc_ncm_desc ncm_desc = { 189 186 .bLength = sizeof ncm_desc, 190 187 .bDescriptorType = USB_DT_CS_INTERFACE, 191 188 .bDescriptorSubType = USB_CDC_NCM_TYPE, ··· 197 194 198 195 /* the default data interface has no endpoints ... */ 199 196 200 - static struct usb_interface_descriptor ncm_data_nop_intf __initdata = { 197 + static struct usb_interface_descriptor ncm_data_nop_intf = { 201 198 .bLength = sizeof ncm_data_nop_intf, 202 199 .bDescriptorType = USB_DT_INTERFACE, 203 200 ··· 212 209 213 210 /* ... but the "real" data interface has two bulk endpoints */ 214 211 215 - static struct usb_interface_descriptor ncm_data_intf __initdata = { 212 + static struct usb_interface_descriptor ncm_data_intf = { 216 213 .bLength = sizeof ncm_data_intf, 217 214 .bDescriptorType = USB_DT_INTERFACE, 218 215 ··· 227 224 228 225 /* full speed support: */ 229 226 230 - static struct usb_endpoint_descriptor fs_ncm_notify_desc __initdata = { 227 + static struct usb_endpoint_descriptor fs_ncm_notify_desc = { 231 228 .bLength = USB_DT_ENDPOINT_SIZE, 232 229 .bDescriptorType = USB_DT_ENDPOINT, 233 230 ··· 237 234 .bInterval = NCM_STATUS_INTERVAL_MS, 238 235 }; 239 236 240 - static struct usb_endpoint_descriptor fs_ncm_in_desc __initdata = { 237 + static struct usb_endpoint_descriptor fs_ncm_in_desc = { 241 238 .bLength = USB_DT_ENDPOINT_SIZE, 242 239 .bDescriptorType = USB_DT_ENDPOINT, 243 240 ··· 245 242 .bmAttributes = USB_ENDPOINT_XFER_BULK, 246 243 }; 247 244 248 - static struct usb_endpoint_descriptor fs_ncm_out_desc __initdata = { 245 + static struct usb_endpoint_descriptor fs_ncm_out_desc = { 249 246 .bLength = USB_DT_ENDPOINT_SIZE, 250 247 .bDescriptorType = USB_DT_ENDPOINT, 251 248 ··· 253 250 .bmAttributes = USB_ENDPOINT_XFER_BULK, 254 251 }; 255 252 256 - static struct usb_descriptor_header *ncm_fs_function[] __initdata = { 253 + static struct usb_descriptor_header *ncm_fs_function[] = { 257 254 (struct usb_descriptor_header *) &ncm_iad_desc, 258 255 /* CDC NCM control descriptors */ 259 256 (struct usb_descriptor_header *) &ncm_control_intf, ··· 272 269 273 270 /* high speed support: */ 274 271 275 - static struct usb_endpoint_descriptor hs_ncm_notify_desc __initdata = { 272 + static struct usb_endpoint_descriptor hs_ncm_notify_desc = { 276 273 .bLength = USB_DT_ENDPOINT_SIZE, 277 274 .bDescriptorType = USB_DT_ENDPOINT, 278 275 ··· 281 278 .wMaxPacketSize = cpu_to_le16(NCM_STATUS_BYTECOUNT), 282 279 .bInterval = USB_MS_TO_HS_INTERVAL(NCM_STATUS_INTERVAL_MS), 283 280 }; 284 - static struct usb_endpoint_descriptor hs_ncm_in_desc __initdata = { 281 + static struct usb_endpoint_descriptor hs_ncm_in_desc = { 285 282 .bLength = USB_DT_ENDPOINT_SIZE, 286 283 .bDescriptorType = USB_DT_ENDPOINT, 287 284 ··· 290 287 .wMaxPacketSize = cpu_to_le16(512), 291 288 }; 292 289 293 - static struct usb_endpoint_descriptor hs_ncm_out_desc __initdata = { 290 + static struct usb_endpoint_descriptor hs_ncm_out_desc = { 294 291 .bLength = USB_DT_ENDPOINT_SIZE, 295 292 .bDescriptorType = USB_DT_ENDPOINT, 296 293 ··· 299 296 .wMaxPacketSize = cpu_to_le16(512), 300 297 }; 301 298 302 - static struct usb_descriptor_header *ncm_hs_function[] __initdata = { 299 + static struct usb_descriptor_header *ncm_hs_function[] = { 303 300 (struct usb_descriptor_header *) &ncm_iad_desc, 304 301 /* CDC NCM control descriptors */ 305 302 (struct usb_descriptor_header *) &ncm_control_intf, ··· 1155 1152 1156 1153 /* ethernet function driver setup/binding */ 1157 1154 1158 - static int __init 1159 - ncm_bind(struct usb_configuration *c, struct usb_function *f) 1155 + static int ncm_bind(struct usb_configuration *c, struct usb_function *f) 1160 1156 { 1161 1157 struct usb_composite_dev *cdev = c->cdev; 1162 1158 struct f_ncm *ncm = func_to_ncm(f); 1159 + struct usb_string *us; 1163 1160 int status; 1164 1161 struct usb_ep *ep; 1162 + struct f_ncm_opts *ncm_opts; 1163 + 1164 + if (!can_support_ecm(cdev->gadget)) 1165 + return -EINVAL; 1166 + 1167 + ncm_opts = container_of(f->fi, struct f_ncm_opts, func_inst); 1168 + /* 1169 + * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 1170 + * configurations are bound in sequence with list_for_each_entry, 1171 + * in each configuration its functions are bound in sequence 1172 + * with list_for_each_entry, so we assume no race condition 1173 + * with regard to ncm_opts->bound access 1174 + */ 1175 + if (!ncm_opts->bound) { 1176 + mutex_lock(&ncm_opts->lock); 1177 + gether_set_gadget(ncm_opts->net, cdev->gadget); 1178 + status = gether_register_netdev(ncm_opts->net); 1179 + mutex_unlock(&ncm_opts->lock); 1180 + if (status) 1181 + return status; 1182 + ncm_opts->bound = true; 1183 + } 1184 + us = usb_gstrings_attach(cdev, ncm_strings, 1185 + ARRAY_SIZE(ncm_string_defs)); 1186 + if (IS_ERR(us)) 1187 + return PTR_ERR(us); 1188 + ncm_control_intf.iInterface = us[STRING_CTRL_IDX].id; 1189 + ncm_data_nop_intf.iInterface = us[STRING_DATA_IDX].id; 1190 + ncm_data_intf.iInterface = us[STRING_DATA_IDX].id; 1191 + ecm_desc.iMACAddress = us[STRING_MAC_IDX].id; 1192 + ncm_iad_desc.iFunction = us[STRING_IAD_IDX].id; 1165 1193 1166 1194 /* allocate instance-specific interface IDs */ 1167 1195 status = usb_interface_id(c, f); ··· 1293 1259 return status; 1294 1260 } 1295 1261 1296 - static void 1297 - ncm_unbind(struct usb_configuration *c, struct usb_function *f) 1262 + static inline struct f_ncm_opts *to_f_ncm_opts(struct config_item *item) 1298 1263 { 1299 - struct f_ncm *ncm = func_to_ncm(f); 1264 + return container_of(to_config_group(item), struct f_ncm_opts, 1265 + func_inst.group); 1266 + } 1267 + 1268 + /* f_ncm_item_ops */ 1269 + USB_ETHERNET_CONFIGFS_ITEM(ncm); 1270 + 1271 + /* f_ncm_opts_dev_addr */ 1272 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(ncm); 1273 + 1274 + /* f_ncm_opts_host_addr */ 1275 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(ncm); 1276 + 1277 + /* f_ncm_opts_qmult */ 1278 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm); 1279 + 1280 + /* f_ncm_opts_ifname */ 1281 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm); 1282 + 1283 + static struct configfs_attribute *ncm_attrs[] = { 1284 + &f_ncm_opts_dev_addr.attr, 1285 + &f_ncm_opts_host_addr.attr, 1286 + &f_ncm_opts_qmult.attr, 1287 + &f_ncm_opts_ifname.attr, 1288 + NULL, 1289 + }; 1290 + 1291 + static struct config_item_type ncm_func_type = { 1292 + .ct_item_ops = &ncm_item_ops, 1293 + .ct_attrs = ncm_attrs, 1294 + .ct_owner = THIS_MODULE, 1295 + }; 1296 + 1297 + static void ncm_free_inst(struct usb_function_instance *f) 1298 + { 1299 + struct f_ncm_opts *opts; 1300 + 1301 + opts = container_of(f, struct f_ncm_opts, func_inst); 1302 + if (opts->bound) 1303 + gether_cleanup(netdev_priv(opts->net)); 1304 + else 1305 + free_netdev(opts->net); 1306 + kfree(opts); 1307 + } 1308 + 1309 + static struct usb_function_instance *ncm_alloc_inst(void) 1310 + { 1311 + struct f_ncm_opts *opts; 1312 + 1313 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 1314 + if (!opts) 1315 + return ERR_PTR(-ENOMEM); 1316 + mutex_init(&opts->lock); 1317 + opts->func_inst.free_func_inst = ncm_free_inst; 1318 + opts->net = gether_setup_default(); 1319 + if (IS_ERR(opts->net)) 1320 + return ERR_PTR(PTR_ERR(opts->net)); 1321 + 1322 + config_group_init_type_name(&opts->func_inst.group, "", &ncm_func_type); 1323 + 1324 + return &opts->func_inst; 1325 + } 1326 + 1327 + static void ncm_free(struct usb_function *f) 1328 + { 1329 + struct f_ncm *ncm; 1330 + struct f_ncm_opts *opts; 1331 + 1332 + ncm = func_to_ncm(f); 1333 + opts = container_of(f->fi, struct f_ncm_opts, func_inst); 1334 + kfree(ncm); 1335 + mutex_lock(&opts->lock); 1336 + opts->refcnt--; 1337 + mutex_unlock(&opts->lock); 1338 + } 1339 + 1340 + static void ncm_unbind(struct usb_configuration *c, struct usb_function *f) 1341 + { 1342 + struct f_ncm *ncm = func_to_ncm(f); 1300 1343 1301 1344 DBG(c->cdev, "ncm unbind\n"); 1302 1345 1303 - ncm_string_defs[0].id = 0; 1304 1346 usb_free_all_descriptors(f); 1305 1347 1306 1348 kfree(ncm->notify_req->buf); 1307 1349 usb_ep_free_request(ncm->notify, ncm->notify_req); 1308 - 1309 - kfree(ncm); 1310 1350 } 1311 1351 1312 - /** 1313 - * ncm_bind_config - add CDC Network link to a configuration 1314 - * @c: the configuration to support the network link 1315 - * @ethaddr: a buffer in which the ethernet address of the host side 1316 - * side of the link was recorded 1317 - * Context: single threaded during gadget setup 1318 - * 1319 - * Returns zero on success, else negative errno. 1320 - * 1321 - * Caller must have called @gether_setup(). Caller is also responsible 1322 - * for calling @gether_cleanup() before module unload. 1323 - */ 1324 - int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 1325 - struct eth_dev *dev) 1352 + struct usb_function *ncm_alloc(struct usb_function_instance *fi) 1326 1353 { 1327 - struct f_ncm *ncm; 1328 - int status; 1329 - 1330 - if (!can_support_ecm(c->cdev->gadget) || !ethaddr) 1331 - return -EINVAL; 1332 - 1333 - if (ncm_string_defs[0].id == 0) { 1334 - status = usb_string_ids_tab(c->cdev, ncm_string_defs); 1335 - if (status < 0) 1336 - return status; 1337 - ncm_control_intf.iInterface = 1338 - ncm_string_defs[STRING_CTRL_IDX].id; 1339 - 1340 - status = ncm_string_defs[STRING_DATA_IDX].id; 1341 - ncm_data_nop_intf.iInterface = status; 1342 - ncm_data_intf.iInterface = status; 1343 - 1344 - ecm_desc.iMACAddress = ncm_string_defs[STRING_MAC_IDX].id; 1345 - ncm_iad_desc.iFunction = ncm_string_defs[STRING_IAD_IDX].id; 1346 - } 1354 + struct f_ncm *ncm; 1355 + struct f_ncm_opts *opts; 1356 + int status; 1347 1357 1348 1358 /* allocate and initialize one new instance */ 1349 - ncm = kzalloc(sizeof *ncm, GFP_KERNEL); 1359 + ncm = kzalloc(sizeof(*ncm), GFP_KERNEL); 1350 1360 if (!ncm) 1351 - return -ENOMEM; 1361 + return ERR_PTR(-ENOMEM); 1362 + 1363 + opts = container_of(fi, struct f_ncm_opts, func_inst); 1364 + mutex_lock(&opts->lock); 1365 + opts->refcnt++; 1352 1366 1353 1367 /* export host's Ethernet address in CDC format */ 1354 - snprintf(ncm->ethaddr, sizeof ncm->ethaddr, "%pm", ethaddr); 1368 + status = gether_get_host_addr_cdc(opts->net, ncm->ethaddr, 1369 + sizeof(ncm->ethaddr)); 1370 + if (status < 12) { /* strlen("01234567890a") */ 1371 + kfree(ncm); 1372 + return ERR_PTR(-EINVAL); 1373 + } 1355 1374 ncm_string_defs[STRING_MAC_IDX].s = ncm->ethaddr; 1356 1375 1357 1376 spin_lock_init(&ncm->lock); 1358 1377 ncm_reset_values(ncm); 1359 - ncm->port.ioport = dev; 1378 + ncm->port.ioport = netdev_priv(opts->net); 1379 + mutex_unlock(&opts->lock); 1360 1380 ncm->port.is_fixed = true; 1361 1381 1362 1382 ncm->port.func.name = "cdc_network"; 1363 - ncm->port.func.strings = ncm_strings; 1364 1383 /* descriptors are per-instance copies */ 1365 1384 ncm->port.func.bind = ncm_bind; 1366 1385 ncm->port.func.unbind = ncm_unbind; ··· 1421 1334 ncm->port.func.get_alt = ncm_get_alt; 1422 1335 ncm->port.func.setup = ncm_setup; 1423 1336 ncm->port.func.disable = ncm_disable; 1337 + ncm->port.func.free_func = ncm_free; 1424 1338 1425 1339 ncm->port.wrap = ncm_wrap_ntb; 1426 1340 ncm->port.unwrap = ncm_unwrap_ntb; 1427 1341 1428 - status = usb_add_function(c, &ncm->port.func); 1429 - if (status) 1430 - kfree(ncm); 1431 - return status; 1342 + return &ncm->port.func; 1432 1343 } 1344 + 1345 + DECLARE_USB_FUNCTION_INIT(ncm, ncm_alloc_inst, ncm_alloc); 1346 + MODULE_LICENSE("GPL"); 1347 + MODULE_AUTHOR("Yauheni Kaliuta");
+8 -67
drivers/usb/gadget/f_obex.c
··· 309 309 { 310 310 struct usb_composite_dev *cdev = c->cdev; 311 311 struct f_obex *obex = func_to_obex(f); 312 + struct usb_string *us; 312 313 int status; 313 314 struct usb_ep *ep; 314 315 315 316 if (!can_support_obex(c)) 316 317 return -EINVAL; 317 318 318 - if (obex_string_defs[OBEX_CTRL_IDX].id == 0) { 319 - status = usb_string_ids_tab(c->cdev, obex_string_defs); 320 - if (status < 0) 321 - return status; 322 - obex_control_intf.iInterface = 323 - obex_string_defs[OBEX_CTRL_IDX].id; 324 - 325 - status = obex_string_defs[OBEX_DATA_IDX].id; 326 - obex_data_nop_intf.iInterface = status; 327 - obex_data_intf.iInterface = status; 328 - } 319 + us = usb_gstrings_attach(cdev, obex_strings, 320 + ARRAY_SIZE(obex_string_defs)); 321 + if (IS_ERR(us)) 322 + return PTR_ERR(us); 323 + obex_control_intf.iInterface = us[OBEX_CTRL_IDX].id; 324 + obex_data_nop_intf.iInterface = us[OBEX_DATA_IDX].id; 325 + obex_data_intf.iInterface = us[OBEX_DATA_IDX].id; 329 326 330 327 /* allocate instance-specific interface IDs, and patch descriptors */ 331 328 ··· 402 405 403 406 return status; 404 407 } 405 - 406 - #ifdef USBF_OBEX_INCLUDED 407 - 408 - static void 409 - obex_old_unbind(struct usb_configuration *c, struct usb_function *f) 410 - { 411 - obex_string_defs[OBEX_CTRL_IDX].id = 0; 412 - usb_free_all_descriptors(f); 413 - kfree(func_to_obex(f)); 414 - } 415 - 416 - /** 417 - * obex_bind_config - add a CDC OBEX function to a configuration 418 - * @c: the configuration to support the CDC OBEX instance 419 - * @port_num: /dev/ttyGS* port this interface will use 420 - * Context: single threaded during gadget setup 421 - * 422 - * Returns zero on success, else negative errno. 423 - */ 424 - int __init obex_bind_config(struct usb_configuration *c, u8 port_num) 425 - { 426 - struct f_obex *obex; 427 - int status; 428 - 429 - /* allocate and initialize one new instance */ 430 - obex = kzalloc(sizeof *obex, GFP_KERNEL); 431 - if (!obex) 432 - return -ENOMEM; 433 - 434 - obex->port_num = port_num; 435 - 436 - obex->port.connect = obex_connect; 437 - obex->port.disconnect = obex_disconnect; 438 - 439 - obex->port.func.name = "obex"; 440 - obex->port.func.strings = obex_strings; 441 - /* descriptors are per-instance copies */ 442 - obex->port.func.bind = obex_bind; 443 - obex->port.func.unbind = obex_old_unbind; 444 - obex->port.func.set_alt = obex_set_alt; 445 - obex->port.func.get_alt = obex_get_alt; 446 - obex->port.func.disable = obex_disable; 447 - 448 - status = usb_add_function(c, &obex->port.func); 449 - if (status) 450 - kfree(obex); 451 - 452 - return status; 453 - } 454 - 455 - #else 456 408 457 409 static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) 458 410 { ··· 496 550 497 551 static void obex_unbind(struct usb_configuration *c, struct usb_function *f) 498 552 { 499 - obex_string_defs[OBEX_CTRL_IDX].id = 0; 500 553 usb_free_all_descriptors(f); 501 554 } 502 555 ··· 517 572 obex->port.disconnect = obex_disconnect; 518 573 519 574 obex->port.func.name = "obex"; 520 - obex->port.func.strings = obex_strings; 521 575 /* descriptors are per-instance copies */ 522 576 obex->port.func.bind = obex_bind; 523 577 obex->port.func.unbind = obex_unbind; ··· 529 585 } 530 586 531 587 DECLARE_USB_FUNCTION_INIT(obex, obex_alloc_inst, obex_alloc); 532 - 533 - #endif 534 - 535 588 MODULE_AUTHOR("Felipe Balbi"); 536 589 MODULE_LICENSE("GPL");
+150 -27
drivers/usb/gadget/f_phonet.c
··· 13 13 #include <linux/mm.h> 14 14 #include <linux/slab.h> 15 15 #include <linux/kernel.h> 16 + #include <linux/module.h> 16 17 #include <linux/device.h> 17 18 18 19 #include <linux/netdevice.h> ··· 26 25 #include <linux/usb/composite.h> 27 26 28 27 #include "u_phonet.h" 28 + #include "u_ether.h" 29 29 30 30 #define PN_MEDIA_USB 0x1B 31 31 #define MAXPACKET 512 ··· 480 478 481 479 /*-------------------------------------------------------------------------*/ 482 480 483 - static __init 484 - int pn_bind(struct usb_configuration *c, struct usb_function *f) 481 + static int pn_bind(struct usb_configuration *c, struct usb_function *f) 485 482 { 486 483 struct usb_composite_dev *cdev = c->cdev; 487 484 struct usb_gadget *gadget = cdev->gadget; 488 485 struct f_phonet *fp = func_to_pn(f); 489 486 struct usb_ep *ep; 490 487 int status, i; 488 + 489 + #ifndef USBF_PHONET_INCLUDED 490 + struct f_phonet_opts *phonet_opts; 491 + 492 + phonet_opts = container_of(f->fi, struct f_phonet_opts, func_inst); 493 + 494 + /* 495 + * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 496 + * configurations are bound in sequence with list_for_each_entry, 497 + * in each configuration its functions are bound in sequence 498 + * with list_for_each_entry, so we assume no race condition 499 + * with regard to phonet_opts->bound access 500 + */ 501 + if (!phonet_opts->bound) { 502 + gphonet_set_gadget(phonet_opts->net, gadget); 503 + status = gphonet_register_netdev(phonet_opts->net); 504 + if (status) 505 + return status; 506 + phonet_opts->bound = true; 507 + } 508 + #endif 491 509 492 510 /* Reserve interface IDs */ 493 511 status = usb_interface_id(c, f); ··· 582 560 return status; 583 561 } 584 562 585 - static void 586 - pn_unbind(struct usb_configuration *c, struct usb_function *f) 563 + static inline struct f_phonet_opts *to_f_phonet_opts(struct config_item *item) 564 + { 565 + return container_of(to_config_group(item), struct f_phonet_opts, 566 + func_inst.group); 567 + } 568 + 569 + CONFIGFS_ATTR_STRUCT(f_phonet_opts); 570 + static ssize_t f_phonet_attr_show(struct config_item *item, 571 + struct configfs_attribute *attr, 572 + char *page) 573 + { 574 + struct f_phonet_opts *opts = to_f_phonet_opts(item); 575 + struct f_phonet_opts_attribute *f_phonet_opts_attr = 576 + container_of(attr, struct f_phonet_opts_attribute, attr); 577 + ssize_t ret = 0; 578 + 579 + if (f_phonet_opts_attr->show) 580 + ret = f_phonet_opts_attr->show(opts, page); 581 + return ret; 582 + } 583 + 584 + static void phonet_attr_release(struct config_item *item) 585 + { 586 + struct f_phonet_opts *opts = to_f_phonet_opts(item); 587 + 588 + usb_put_function_instance(&opts->func_inst); 589 + } 590 + 591 + static struct configfs_item_operations phonet_item_ops = { 592 + .release = phonet_attr_release, 593 + .show_attribute = f_phonet_attr_show, 594 + }; 595 + 596 + static ssize_t f_phonet_ifname_show(struct f_phonet_opts *opts, char *page) 597 + { 598 + return gether_get_ifname(opts->net, page, PAGE_SIZE); 599 + } 600 + 601 + static struct f_phonet_opts_attribute f_phonet_ifname = 602 + __CONFIGFS_ATTR_RO(ifname, f_phonet_ifname_show); 603 + 604 + static struct configfs_attribute *phonet_attrs[] = { 605 + &f_phonet_ifname.attr, 606 + NULL, 607 + }; 608 + 609 + static struct config_item_type phonet_func_type = { 610 + .ct_item_ops = &phonet_item_ops, 611 + .ct_attrs = phonet_attrs, 612 + .ct_owner = THIS_MODULE, 613 + }; 614 + 615 + static void phonet_free_inst(struct usb_function_instance *f) 616 + { 617 + struct f_phonet_opts *opts; 618 + 619 + opts = container_of(f, struct f_phonet_opts, func_inst); 620 + if (opts->bound) 621 + gphonet_cleanup(opts->net); 622 + else 623 + free_netdev(opts->net); 624 + kfree(opts); 625 + } 626 + 627 + static struct usb_function_instance *phonet_alloc_inst(void) 628 + { 629 + struct f_phonet_opts *opts; 630 + 631 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 632 + if (!opts) 633 + return ERR_PTR(-ENOMEM); 634 + 635 + opts->func_inst.free_func_inst = phonet_free_inst; 636 + opts->net = gphonet_setup_default(); 637 + if (IS_ERR(opts->net)) 638 + return ERR_PTR(PTR_ERR(opts->net)); 639 + 640 + config_group_init_type_name(&opts->func_inst.group, "", 641 + &phonet_func_type); 642 + 643 + return &opts->func_inst; 644 + } 645 + 646 + static void phonet_free(struct usb_function *f) 647 + { 648 + struct f_phonet *phonet; 649 + 650 + phonet = func_to_pn(f); 651 + kfree(phonet); 652 + } 653 + 654 + static void pn_unbind(struct usb_configuration *c, struct usb_function *f) 587 655 { 588 656 struct f_phonet *fp = func_to_pn(f); 589 657 int i; ··· 686 574 usb_ep_free_request(fp->out_ep, fp->out_reqv[i]); 687 575 688 576 usb_free_all_descriptors(f); 689 - kfree(fp); 690 577 } 691 578 692 - /*-------------------------------------------------------------------------*/ 693 - 694 - static struct net_device *dev; 695 - 696 - int __init phonet_bind_config(struct usb_configuration *c) 579 + struct usb_function *phonet_alloc(struct usb_function_instance *fi) 697 580 { 698 581 struct f_phonet *fp; 699 - int err, size; 582 + struct f_phonet_opts *opts; 583 + int size; 700 584 701 585 size = sizeof(*fp) + (phonet_rxq_size * sizeof(struct usb_request *)); 702 586 fp = kzalloc(size, GFP_KERNEL); 703 587 if (!fp) 704 - return -ENOMEM; 588 + return ERR_PTR(-ENOMEM); 705 589 706 - fp->dev = dev; 590 + opts = container_of(fi, struct f_phonet_opts, func_inst); 591 + 592 + fp->dev = opts->net; 707 593 fp->function.name = "phonet"; 708 594 fp->function.bind = pn_bind; 709 595 fp->function.unbind = pn_unbind; 710 596 fp->function.set_alt = pn_set_alt; 711 597 fp->function.get_alt = pn_get_alt; 712 598 fp->function.disable = pn_disconnect; 599 + fp->function.free_func = phonet_free; 713 600 spin_lock_init(&fp->rx.lock); 714 601 715 - err = usb_add_function(c, &fp->function); 716 - if (err) 717 - kfree(fp); 718 - return err; 602 + return &fp->function; 719 603 } 720 604 721 - int __init gphonet_setup(struct usb_gadget *gadget) 605 + struct net_device *gphonet_setup_default(void) 722 606 { 607 + struct net_device *dev; 723 608 struct phonet_port *port; 724 - int err; 725 609 726 610 /* Create net device */ 727 - BUG_ON(dev); 728 611 dev = alloc_netdev(sizeof(*port), "upnlink%d", pn_net_setup); 729 612 if (!dev) 730 - return -ENOMEM; 613 + return ERR_PTR(-ENOMEM); 731 614 732 615 port = netdev_priv(dev); 733 616 spin_lock_init(&port->lock); 734 617 netif_carrier_off(dev); 735 - SET_NETDEV_DEV(dev, &gadget->dev); 736 618 737 - err = register_netdev(dev); 738 - if (err) 739 - free_netdev(dev); 740 - return err; 619 + return dev; 741 620 } 742 621 743 - void gphonet_cleanup(void) 622 + void gphonet_set_gadget(struct net_device *net, struct usb_gadget *g) 623 + { 624 + SET_NETDEV_DEV(net, &g->dev); 625 + } 626 + 627 + int gphonet_register_netdev(struct net_device *net) 628 + { 629 + int status; 630 + 631 + status = register_netdev(net); 632 + if (status) 633 + free_netdev(net); 634 + 635 + return status; 636 + } 637 + 638 + void gphonet_cleanup(struct net_device *dev) 744 639 { 745 640 unregister_netdev(dev); 746 641 } 642 + 643 + DECLARE_USB_FUNCTION_INIT(phonet, phonet_alloc_inst, phonet_alloc); 644 + MODULE_AUTHOR("Rémi Denis-Courmont"); 645 + MODULE_LICENSE("GPL");
+212 -35
drivers/usb/gadget/f_rndis.c
··· 17 17 18 18 #include <linux/slab.h> 19 19 #include <linux/kernel.h> 20 + #include <linux/module.h> 20 21 #include <linux/device.h> 21 22 #include <linux/etherdevice.h> 22 23 23 24 #include <linux/atomic.h> 24 25 25 26 #include "u_ether.h" 27 + #include "u_ether_configfs.h" 28 + #include "u_rndis.h" 26 29 #include "rndis.h" 27 - 28 30 29 31 /* 30 32 * This function is an RNDIS Ethernet port -- a Microsoft protocol that's ··· 657 655 658 656 /*-------------------------------------------------------------------------*/ 659 657 658 + /* Some controllers can't support RNDIS ... */ 659 + static inline bool can_support_rndis(struct usb_configuration *c) 660 + { 661 + /* everything else is *presumably* fine */ 662 + return true; 663 + } 664 + 660 665 /* ethernet function driver setup/binding */ 661 666 662 667 static int ··· 671 662 { 672 663 struct usb_composite_dev *cdev = c->cdev; 673 664 struct f_rndis *rndis = func_to_rndis(f); 665 + struct usb_string *us; 674 666 int status; 675 667 struct usb_ep *ep; 668 + 669 + #ifndef USB_FRNDIS_INCLUDED 670 + struct f_rndis_opts *rndis_opts; 671 + 672 + if (!can_support_rndis(c)) 673 + return -EINVAL; 674 + 675 + rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst); 676 + 677 + /* 678 + * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 679 + * configurations are bound in sequence with list_for_each_entry, 680 + * in each configuration its functions are bound in sequence 681 + * with list_for_each_entry, so we assume no race condition 682 + * with regard to rndis_opts->bound access 683 + */ 684 + if (!rndis_opts->bound) { 685 + gether_set_gadget(rndis_opts->net, cdev->gadget); 686 + status = gether_register_netdev(rndis_opts->net); 687 + if (status) 688 + return status; 689 + rndis_opts->bound = true; 690 + } 691 + #endif 692 + us = usb_gstrings_attach(cdev, rndis_strings, 693 + ARRAY_SIZE(rndis_string_defs)); 694 + if (IS_ERR(us)) 695 + return PTR_ERR(us); 696 + rndis_control_intf.iInterface = us[0].id; 697 + rndis_data_intf.iInterface = us[1].id; 698 + rndis_iad_descriptor.iFunction = us[2].id; 676 699 677 700 /* allocate instance-specific interface IDs */ 678 701 status = usb_interface_id(c, f); ··· 782 741 rndis->port.open = rndis_open; 783 742 rndis->port.close = rndis_close; 784 743 744 + #ifdef USB_FRNDIS_INCLUDED 785 745 status = rndis_register(rndis_response_available, rndis); 786 746 if (status < 0) 787 747 goto fail; 788 748 rndis->config = status; 749 + #endif 789 750 790 751 rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); 791 752 rndis_set_host_mac(rndis->config, rndis->ethaddr); ··· 830 787 return status; 831 788 } 832 789 790 + #ifdef USB_FRNDIS_INCLUDED 791 + 833 792 static void 834 - rndis_unbind(struct usb_configuration *c, struct usb_function *f) 793 + rndis_old_unbind(struct usb_configuration *c, struct usb_function *f) 835 794 { 836 795 struct f_rndis *rndis = func_to_rndis(f); 837 796 838 797 rndis_deregister(rndis->config); 839 - rndis_exit(); 840 798 841 - rndis_string_defs[0].id = 0; 842 799 usb_free_all_descriptors(f); 843 800 844 801 kfree(rndis->notify_req->buf); ··· 847 804 kfree(rndis); 848 805 } 849 806 850 - /* Some controllers can't support RNDIS ... */ 851 - static inline bool can_support_rndis(struct usb_configuration *c) 852 - { 853 - /* everything else is *presumably* fine */ 854 - return true; 855 - } 856 - 857 807 int 858 808 rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 859 809 u32 vendorID, const char *manufacturer, struct eth_dev *dev) 860 810 { 861 811 struct f_rndis *rndis; 862 812 int status; 863 - 864 - if (!can_support_rndis(c) || !ethaddr) 865 - return -EINVAL; 866 - 867 - if (rndis_string_defs[0].id == 0) { 868 - /* ... and setup RNDIS itself */ 869 - status = rndis_init(); 870 - if (status < 0) 871 - return status; 872 - 873 - status = usb_string_ids_tab(c->cdev, rndis_string_defs); 874 - if (status) 875 - return status; 876 - 877 - rndis_control_intf.iInterface = rndis_string_defs[0].id; 878 - rndis_data_intf.iInterface = rndis_string_defs[1].id; 879 - rndis_iad_descriptor.iFunction = rndis_string_defs[2].id; 880 - } 881 813 882 814 /* allocate and initialize one new instance */ 883 815 status = -ENOMEM; ··· 874 856 rndis->port.unwrap = rndis_rm_hdr; 875 857 876 858 rndis->port.func.name = "rndis"; 877 - rndis->port.func.strings = rndis_strings; 859 + /* descriptors are per-instance copies */ 860 + rndis->port.func.bind = rndis_bind; 861 + rndis->port.func.unbind = rndis_old_unbind; 862 + rndis->port.func.set_alt = rndis_set_alt; 863 + rndis->port.func.setup = rndis_setup; 864 + rndis->port.func.disable = rndis_disable; 865 + 866 + status = usb_add_function(c, &rndis->port.func); 867 + if (status) 868 + kfree(rndis); 869 + fail: 870 + return status; 871 + } 872 + 873 + #else 874 + 875 + void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net) 876 + { 877 + struct f_rndis_opts *opts; 878 + 879 + opts = container_of(f, struct f_rndis_opts, func_inst); 880 + if (opts->bound) 881 + gether_cleanup(netdev_priv(opts->net)); 882 + else 883 + free_netdev(opts->net); 884 + opts->borrowed_net = opts->bound = true; 885 + opts->net = net; 886 + } 887 + EXPORT_SYMBOL(rndis_borrow_net); 888 + 889 + static inline struct f_rndis_opts *to_f_rndis_opts(struct config_item *item) 890 + { 891 + return container_of(to_config_group(item), struct f_rndis_opts, 892 + func_inst.group); 893 + } 894 + 895 + /* f_rndis_item_ops */ 896 + USB_ETHERNET_CONFIGFS_ITEM(rndis); 897 + 898 + /* f_rndis_opts_dev_addr */ 899 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(rndis); 900 + 901 + /* f_rndis_opts_host_addr */ 902 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(rndis); 903 + 904 + /* f_rndis_opts_qmult */ 905 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(rndis); 906 + 907 + /* f_rndis_opts_ifname */ 908 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(rndis); 909 + 910 + static struct configfs_attribute *rndis_attrs[] = { 911 + &f_rndis_opts_dev_addr.attr, 912 + &f_rndis_opts_host_addr.attr, 913 + &f_rndis_opts_qmult.attr, 914 + &f_rndis_opts_ifname.attr, 915 + NULL, 916 + }; 917 + 918 + static struct config_item_type rndis_func_type = { 919 + .ct_item_ops = &rndis_item_ops, 920 + .ct_attrs = rndis_attrs, 921 + .ct_owner = THIS_MODULE, 922 + }; 923 + 924 + static void rndis_free_inst(struct usb_function_instance *f) 925 + { 926 + struct f_rndis_opts *opts; 927 + 928 + opts = container_of(f, struct f_rndis_opts, func_inst); 929 + if (!opts->borrowed_net) { 930 + if (opts->bound) 931 + gether_cleanup(netdev_priv(opts->net)); 932 + else 933 + free_netdev(opts->net); 934 + } 935 + kfree(opts); 936 + } 937 + 938 + static struct usb_function_instance *rndis_alloc_inst(void) 939 + { 940 + struct f_rndis_opts *opts; 941 + 942 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 943 + if (!opts) 944 + return ERR_PTR(-ENOMEM); 945 + mutex_init(&opts->lock); 946 + opts->func_inst.free_func_inst = rndis_free_inst; 947 + opts->net = gether_setup_default(); 948 + if (IS_ERR(opts->net)) 949 + return ERR_CAST(opts->net); 950 + 951 + config_group_init_type_name(&opts->func_inst.group, "", 952 + &rndis_func_type); 953 + 954 + return &opts->func_inst; 955 + } 956 + 957 + static void rndis_free(struct usb_function *f) 958 + { 959 + struct f_rndis *rndis; 960 + struct f_rndis_opts *opts; 961 + 962 + rndis = func_to_rndis(f); 963 + rndis_deregister(rndis->config); 964 + opts = container_of(f->fi, struct f_rndis_opts, func_inst); 965 + kfree(rndis); 966 + mutex_lock(&opts->lock); 967 + opts->refcnt--; 968 + mutex_unlock(&opts->lock); 969 + } 970 + 971 + static void rndis_unbind(struct usb_configuration *c, struct usb_function *f) 972 + { 973 + struct f_rndis *rndis = func_to_rndis(f); 974 + 975 + usb_free_all_descriptors(f); 976 + 977 + kfree(rndis->notify_req->buf); 978 + usb_ep_free_request(rndis->notify, rndis->notify_req); 979 + } 980 + 981 + static struct usb_function *rndis_alloc(struct usb_function_instance *fi) 982 + { 983 + struct f_rndis *rndis; 984 + struct f_rndis_opts *opts; 985 + int status; 986 + 987 + /* allocate and initialize one new instance */ 988 + rndis = kzalloc(sizeof(*rndis), GFP_KERNEL); 989 + if (!rndis) 990 + return ERR_PTR(-ENOMEM); 991 + 992 + opts = container_of(fi, struct f_rndis_opts, func_inst); 993 + mutex_lock(&opts->lock); 994 + opts->refcnt++; 995 + 996 + gether_get_host_addr_u8(opts->net, rndis->ethaddr); 997 + rndis->vendorID = opts->vendor_id; 998 + rndis->manufacturer = opts->manufacturer; 999 + 1000 + rndis->port.ioport = netdev_priv(opts->net); 1001 + mutex_unlock(&opts->lock); 1002 + /* RNDIS activates when the host changes this filter */ 1003 + rndis->port.cdc_filter = 0; 1004 + 1005 + /* RNDIS has special (and complex) framing */ 1006 + rndis->port.header_len = sizeof(struct rndis_packet_msg_type); 1007 + rndis->port.wrap = rndis_add_header; 1008 + rndis->port.unwrap = rndis_rm_hdr; 1009 + 1010 + rndis->port.func.name = "rndis"; 878 1011 /* descriptors are per-instance copies */ 879 1012 rndis->port.func.bind = rndis_bind; 880 1013 rndis->port.func.unbind = rndis_unbind; 881 1014 rndis->port.func.set_alt = rndis_set_alt; 882 1015 rndis->port.func.setup = rndis_setup; 883 1016 rndis->port.func.disable = rndis_disable; 1017 + rndis->port.func.free_func = rndis_free; 884 1018 885 - status = usb_add_function(c, &rndis->port.func); 886 - if (status) { 1019 + status = rndis_register(rndis_response_available, rndis); 1020 + if (status < 0) { 887 1021 kfree(rndis); 888 - fail: 889 - rndis_exit(); 1022 + return ERR_PTR(status); 890 1023 } 891 - return status; 1024 + rndis->config = status; 1025 + 1026 + return &rndis->port.func; 892 1027 } 1028 + 1029 + DECLARE_USB_FUNCTION_INIT(rndis, rndis_alloc_inst, rndis_alloc); 1030 + MODULE_LICENSE("GPL"); 1031 + MODULE_AUTHOR("David Brownell"); 1032 + 1033 + #endif
+164 -16
drivers/usb/gadget/f_subset.c
··· 12 12 13 13 #include <linux/slab.h> 14 14 #include <linux/kernel.h> 15 + #include <linux/module.h> 15 16 #include <linux/device.h> 16 17 #include <linux/etherdevice.h> 17 18 18 19 #include "u_ether.h" 19 - 20 + #include "u_ether_configfs.h" 21 + #include "u_gether.h" 20 22 21 23 /* 22 24 * This function packages a simple "CDC Subset" Ethernet port with no real ··· 297 295 { 298 296 struct usb_composite_dev *cdev = c->cdev; 299 297 struct f_gether *geth = func_to_geth(f); 298 + struct usb_string *us; 300 299 int status; 301 300 struct usb_ep *ep; 301 + 302 + #ifndef USB_FSUBSET_INCLUDED 303 + struct f_gether_opts *gether_opts; 304 + 305 + gether_opts = container_of(f->fi, struct f_gether_opts, func_inst); 306 + 307 + /* 308 + * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 309 + * configurations are bound in sequence with list_for_each_entry, 310 + * in each configuration its functions are bound in sequence 311 + * with list_for_each_entry, so we assume no race condition 312 + * with regard to gether_opts->bound access 313 + */ 314 + if (!gether_opts->bound) { 315 + mutex_lock(&gether_opts->lock); 316 + gether_set_gadget(gether_opts->net, cdev->gadget); 317 + status = gether_register_netdev(gether_opts->net); 318 + mutex_unlock(&gether_opts->lock); 319 + if (status) 320 + return status; 321 + gether_opts->bound = true; 322 + } 323 + #endif 324 + us = usb_gstrings_attach(cdev, geth_strings, 325 + ARRAY_SIZE(geth_string_defs)); 326 + if (IS_ERR(us)) 327 + return PTR_ERR(us); 328 + 329 + subset_data_intf.iInterface = us[0].id; 330 + ether_desc.iMACAddress = us[1].id; 302 331 303 332 /* allocate instance-specific interface IDs */ 304 333 status = usb_interface_id(c, f); ··· 393 360 return status; 394 361 } 395 362 363 + #ifdef USB_FSUBSET_INCLUDED 364 + 396 365 static void 397 - geth_unbind(struct usb_configuration *c, struct usb_function *f) 366 + geth_old_unbind(struct usb_configuration *c, struct usb_function *f) 398 367 { 399 368 geth_string_defs[0].id = 0; 400 369 usb_free_all_descriptors(f); ··· 422 387 struct f_gether *geth; 423 388 int status; 424 389 425 - if (!ethaddr) 426 - return -EINVAL; 427 - 428 - /* maybe allocate device-global string IDs */ 429 - if (geth_string_defs[0].id == 0) { 430 - status = usb_string_ids_tab(c->cdev, geth_string_defs); 431 - if (status < 0) 432 - return status; 433 - subset_data_intf.iInterface = geth_string_defs[0].id; 434 - ether_desc.iMACAddress = geth_string_defs[1].id; 435 - } 436 - 437 390 /* allocate and initialize one new instance */ 438 391 geth = kzalloc(sizeof *geth, GFP_KERNEL); 439 392 if (!geth) ··· 435 412 geth->port.cdc_filter = DEFAULT_FILTER; 436 413 437 414 geth->port.func.name = "cdc_subset"; 438 - geth->port.func.strings = geth_strings; 439 415 geth->port.func.bind = geth_bind; 440 - geth->port.func.unbind = geth_unbind; 416 + geth->port.func.unbind = geth_old_unbind; 441 417 geth->port.func.set_alt = geth_set_alt; 442 418 geth->port.func.disable = geth_disable; 443 419 ··· 445 423 kfree(geth); 446 424 return status; 447 425 } 426 + 427 + #else 428 + 429 + static inline struct f_gether_opts *to_f_gether_opts(struct config_item *item) 430 + { 431 + return container_of(to_config_group(item), struct f_gether_opts, 432 + func_inst.group); 433 + } 434 + 435 + /* f_gether_item_ops */ 436 + USB_ETHERNET_CONFIGFS_ITEM(gether); 437 + 438 + /* f_gether_opts_dev_addr */ 439 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(gether); 440 + 441 + /* f_gether_opts_host_addr */ 442 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(gether); 443 + 444 + /* f_gether_opts_qmult */ 445 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(gether); 446 + 447 + /* f_gether_opts_ifname */ 448 + USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(gether); 449 + 450 + static struct configfs_attribute *gether_attrs[] = { 451 + &f_gether_opts_dev_addr.attr, 452 + &f_gether_opts_host_addr.attr, 453 + &f_gether_opts_qmult.attr, 454 + &f_gether_opts_ifname.attr, 455 + NULL, 456 + }; 457 + 458 + static struct config_item_type gether_func_type = { 459 + .ct_item_ops = &gether_item_ops, 460 + .ct_attrs = gether_attrs, 461 + .ct_owner = THIS_MODULE, 462 + }; 463 + 464 + static void geth_free_inst(struct usb_function_instance *f) 465 + { 466 + struct f_gether_opts *opts; 467 + 468 + opts = container_of(f, struct f_gether_opts, func_inst); 469 + if (opts->bound) 470 + gether_cleanup(netdev_priv(opts->net)); 471 + else 472 + free_netdev(opts->net); 473 + kfree(opts); 474 + } 475 + 476 + static struct usb_function_instance *geth_alloc_inst(void) 477 + { 478 + struct f_gether_opts *opts; 479 + 480 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 481 + if (!opts) 482 + return ERR_PTR(-ENOMEM); 483 + mutex_init(&opts->lock); 484 + opts->func_inst.free_func_inst = geth_free_inst; 485 + opts->net = gether_setup_default(); 486 + if (IS_ERR(opts->net)) 487 + return ERR_CAST(opts->net); 488 + 489 + config_group_init_type_name(&opts->func_inst.group, "", 490 + &gether_func_type); 491 + 492 + return &opts->func_inst; 493 + } 494 + 495 + static void geth_free(struct usb_function *f) 496 + { 497 + struct f_gether *eth; 498 + 499 + eth = func_to_geth(f); 500 + kfree(eth); 501 + } 502 + 503 + static void geth_unbind(struct usb_configuration *c, struct usb_function *f) 504 + { 505 + geth_string_defs[0].id = 0; 506 + usb_free_all_descriptors(f); 507 + } 508 + 509 + static struct usb_function *geth_alloc(struct usb_function_instance *fi) 510 + { 511 + struct f_gether *geth; 512 + struct f_gether_opts *opts; 513 + int status; 514 + 515 + /* allocate and initialize one new instance */ 516 + geth = kzalloc(sizeof(*geth), GFP_KERNEL); 517 + if (!geth) 518 + return ERR_PTR(-ENOMEM); 519 + 520 + opts = container_of(fi, struct f_gether_opts, func_inst); 521 + 522 + mutex_lock(&opts->lock); 523 + opts->refcnt++; 524 + /* export host's Ethernet address in CDC format */ 525 + status = gether_get_host_addr_cdc(opts->net, geth->ethaddr, 526 + sizeof(geth->ethaddr)); 527 + if (status < 12) { 528 + kfree(geth); 529 + return ERR_PTR(-EINVAL); 530 + } 531 + geth_string_defs[1].s = geth->ethaddr; 532 + 533 + geth->port.ioport = netdev_priv(opts->net); 534 + mutex_unlock(&opts->lock); 535 + geth->port.cdc_filter = DEFAULT_FILTER; 536 + 537 + geth->port.func.name = "cdc_subset"; 538 + geth->port.func.bind = geth_bind; 539 + geth->port.func.unbind = geth_unbind; 540 + geth->port.func.set_alt = geth_set_alt; 541 + geth->port.func.disable = geth_disable; 542 + geth->port.func.free_func = geth_free; 543 + 544 + return &geth->port.func; 545 + } 546 + 547 + DECLARE_USB_FUNCTION_INIT(geth, geth_alloc_inst, geth_alloc); 548 + MODULE_LICENSE("GPL"); 549 + MODULE_AUTHOR("David Brownell"); 550 + 551 + #endif
+6 -14
drivers/usb/gadget/f_uac2.c
··· 90 90 }; 91 91 92 92 struct uac2_rtd_params { 93 + struct snd_uac2_chip *uac2; /* parent chip */ 93 94 bool ep_enabled; /* if the ep is enabled */ 94 95 /* Size of the ring buffer */ 95 96 size_t dma_bytes; ··· 170 169 } 171 170 172 171 static inline 173 - struct snd_uac2_chip *prm_to_uac2(struct uac2_rtd_params *r) 174 - { 175 - struct snd_uac2_chip *uac2 = container_of(r, 176 - struct snd_uac2_chip, c_prm); 177 - 178 - if (&uac2->c_prm != r) 179 - uac2 = container_of(r, struct snd_uac2_chip, p_prm); 180 - 181 - return uac2; 182 - } 183 - 184 - static inline 185 172 uint num_channels(uint chanmask) 186 173 { 187 174 uint num = 0; ··· 193 204 struct uac2_req *ur = req->context; 194 205 struct snd_pcm_substream *substream; 195 206 struct uac2_rtd_params *prm = ur->pp; 196 - struct snd_uac2_chip *uac2 = prm_to_uac2(prm); 207 + struct snd_uac2_chip *uac2 = prm->uac2; 197 208 198 209 /* i/f shutting down */ 199 210 if (!prm->ep_enabled) ··· 883 894 static inline void 884 895 free_ep(struct uac2_rtd_params *prm, struct usb_ep *ep) 885 896 { 886 - struct snd_uac2_chip *uac2 = prm_to_uac2(prm); 897 + struct snd_uac2_chip *uac2 = prm->uac2; 887 898 int i; 888 899 889 900 prm->ep_enabled = false; ··· 958 969 goto err; 959 970 } 960 971 agdev->in_ep->driver_data = agdev; 972 + 973 + uac2->p_prm.uac2 = uac2; 974 + uac2->c_prm.uac2 = uac2; 961 975 962 976 hs_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress; 963 977 hs_epout_desc.wMaxPacketSize = fs_epout_desc.wMaxPacketSize;
+3 -10
drivers/usb/gadget/f_uvc.c
··· 156 156 /* The wMaxPacketSize and bInterval values will be initialized from 157 157 * module parameters. 158 158 */ 159 - .wMaxPacketSize = 0, 160 - .bInterval = 0, 161 159 }; 162 160 163 161 static struct usb_endpoint_descriptor uvc_hs_streaming_ep __initdata = { ··· 167 169 /* The wMaxPacketSize and bInterval values will be initialized from 168 170 * module parameters. 169 171 */ 170 - .wMaxPacketSize = 0, 171 - .bInterval = 0, 172 172 }; 173 173 174 174 static struct usb_endpoint_descriptor uvc_ss_streaming_ep __initdata = { ··· 179 183 /* The wMaxPacketSize and bInterval values will be initialized from 180 184 * module parameters. 181 185 */ 182 - .wMaxPacketSize = 0, 183 - .bInterval = 0, 184 186 }; 185 187 186 188 static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp __initdata = { 187 189 .bLength = sizeof(uvc_ss_streaming_comp), 188 190 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 189 - /* The following 3 values can be tweaked if necessary. */ 190 - .bMaxBurst = 0, 191 - .bmAttributes = 0, 192 - .wBytesPerInterval = cpu_to_le16(1024), 191 + /* The bMaxBurst, bmAttributes and wBytesPerInterval values will be 192 + * initialized from module parameters. 193 + */ 193 194 }; 194 195 195 196 static const struct usb_descriptor_header * const uvc_fs_streaming[] = {
+1219
drivers/usb/gadget/fotg210-udc.c
··· 1 + /* 2 + * FOTG210 UDC Driver supports Bulk transfer so far 3 + * 4 + * Copyright (C) 2013 Faraday Technology Corporation 5 + * 6 + * Author : Yuan-Hsin Chen <yhchen@faraday-tech.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 as published by 10 + * the Free Software Foundation; version 2 of the License. 11 + */ 12 + 13 + #include <linux/dma-mapping.h> 14 + #include <linux/err.h> 15 + #include <linux/interrupt.h> 16 + #include <linux/io.h> 17 + #include <linux/module.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/usb/ch9.h> 20 + #include <linux/usb/gadget.h> 21 + 22 + #include "fotg210.h" 23 + 24 + #define DRIVER_DESC "FOTG210 USB Device Controller Driver" 25 + #define DRIVER_VERSION "30-April-2013" 26 + 27 + static const char udc_name[] = "fotg210_udc"; 28 + static const char * const fotg210_ep_name[] = { 29 + "ep0", "ep1", "ep2", "ep3", "ep4"}; 30 + 31 + static void fotg210_disable_fifo_int(struct fotg210_ep *ep) 32 + { 33 + u32 value = ioread32(ep->fotg210->reg + FOTG210_DMISGR1); 34 + 35 + if (ep->dir_in) 36 + value |= DMISGR1_MF_IN_INT(ep->epnum - 1); 37 + else 38 + value |= DMISGR1_MF_OUTSPK_INT(ep->epnum - 1); 39 + iowrite32(value, ep->fotg210->reg + FOTG210_DMISGR1); 40 + } 41 + 42 + static void fotg210_enable_fifo_int(struct fotg210_ep *ep) 43 + { 44 + u32 value = ioread32(ep->fotg210->reg + FOTG210_DMISGR1); 45 + 46 + if (ep->dir_in) 47 + value &= ~DMISGR1_MF_IN_INT(ep->epnum - 1); 48 + else 49 + value &= ~DMISGR1_MF_OUTSPK_INT(ep->epnum - 1); 50 + iowrite32(value, ep->fotg210->reg + FOTG210_DMISGR1); 51 + } 52 + 53 + static void fotg210_set_cxdone(struct fotg210_udc *fotg210) 54 + { 55 + u32 value = ioread32(fotg210->reg + FOTG210_DCFESR); 56 + 57 + value |= DCFESR_CX_DONE; 58 + iowrite32(value, fotg210->reg + FOTG210_DCFESR); 59 + } 60 + 61 + static void fotg210_done(struct fotg210_ep *ep, struct fotg210_request *req, 62 + int status) 63 + { 64 + list_del_init(&req->queue); 65 + 66 + /* don't modify queue heads during completion callback */ 67 + if (ep->fotg210->gadget.speed == USB_SPEED_UNKNOWN) 68 + req->req.status = -ESHUTDOWN; 69 + else 70 + req->req.status = status; 71 + 72 + spin_unlock(&ep->fotg210->lock); 73 + req->req.complete(&ep->ep, &req->req); 74 + spin_lock(&ep->fotg210->lock); 75 + 76 + if (ep->epnum) { 77 + if (list_empty(&ep->queue)) 78 + fotg210_disable_fifo_int(ep); 79 + } else { 80 + fotg210_set_cxdone(ep->fotg210); 81 + } 82 + } 83 + 84 + static void fotg210_fifo_ep_mapping(struct fotg210_ep *ep, u32 epnum, 85 + u32 dir_in) 86 + { 87 + struct fotg210_udc *fotg210 = ep->fotg210; 88 + u32 val; 89 + 90 + /* Driver should map an ep to a fifo and then map the fifo 91 + * to the ep. What a brain-damaged design! 92 + */ 93 + 94 + /* map a fifo to an ep */ 95 + val = ioread32(fotg210->reg + FOTG210_EPMAP); 96 + val &= ~EPMAP_FIFONOMSK(epnum, dir_in); 97 + val |= EPMAP_FIFONO(epnum, dir_in); 98 + iowrite32(val, fotg210->reg + FOTG210_EPMAP); 99 + 100 + /* map the ep to the fifo */ 101 + val = ioread32(fotg210->reg + FOTG210_FIFOMAP); 102 + val &= ~FIFOMAP_EPNOMSK(epnum); 103 + val |= FIFOMAP_EPNO(epnum); 104 + iowrite32(val, fotg210->reg + FOTG210_FIFOMAP); 105 + 106 + /* enable fifo */ 107 + val = ioread32(fotg210->reg + FOTG210_FIFOCF); 108 + val |= FIFOCF_FIFO_EN(epnum - 1); 109 + iowrite32(val, fotg210->reg + FOTG210_FIFOCF); 110 + } 111 + 112 + static void fotg210_set_fifo_dir(struct fotg210_ep *ep, u32 epnum, u32 dir_in) 113 + { 114 + struct fotg210_udc *fotg210 = ep->fotg210; 115 + u32 val; 116 + 117 + val = ioread32(fotg210->reg + FOTG210_FIFOMAP); 118 + val |= (dir_in ? FIFOMAP_DIRIN(epnum - 1) : FIFOMAP_DIROUT(epnum - 1)); 119 + iowrite32(val, fotg210->reg + FOTG210_FIFOMAP); 120 + } 121 + 122 + static void fotg210_set_tfrtype(struct fotg210_ep *ep, u32 epnum, u32 type) 123 + { 124 + struct fotg210_udc *fotg210 = ep->fotg210; 125 + u32 val; 126 + 127 + val = ioread32(fotg210->reg + FOTG210_FIFOCF); 128 + val |= FIFOCF_TYPE(type, epnum - 1); 129 + iowrite32(val, fotg210->reg + FOTG210_FIFOCF); 130 + } 131 + 132 + static void fotg210_set_mps(struct fotg210_ep *ep, u32 epnum, u32 mps, 133 + u32 dir_in) 134 + { 135 + struct fotg210_udc *fotg210 = ep->fotg210; 136 + u32 val; 137 + u32 offset = dir_in ? FOTG210_INEPMPSR(epnum) : 138 + FOTG210_OUTEPMPSR(epnum); 139 + 140 + val = ioread32(fotg210->reg + offset); 141 + val |= INOUTEPMPSR_MPS(mps); 142 + iowrite32(val, fotg210->reg + offset); 143 + } 144 + 145 + static int fotg210_config_ep(struct fotg210_ep *ep, 146 + const struct usb_endpoint_descriptor *desc) 147 + { 148 + struct fotg210_udc *fotg210 = ep->fotg210; 149 + 150 + fotg210_set_fifo_dir(ep, ep->epnum, ep->dir_in); 151 + fotg210_set_tfrtype(ep, ep->epnum, ep->type); 152 + fotg210_set_mps(ep, ep->epnum, ep->ep.maxpacket, ep->dir_in); 153 + fotg210_fifo_ep_mapping(ep, ep->epnum, ep->dir_in); 154 + 155 + fotg210->ep[ep->epnum] = ep; 156 + 157 + return 0; 158 + } 159 + 160 + static int fotg210_ep_enable(struct usb_ep *_ep, 161 + const struct usb_endpoint_descriptor *desc) 162 + { 163 + struct fotg210_ep *ep; 164 + 165 + ep = container_of(_ep, struct fotg210_ep, ep); 166 + 167 + ep->desc = desc; 168 + ep->epnum = usb_endpoint_num(desc); 169 + ep->type = usb_endpoint_type(desc); 170 + ep->dir_in = usb_endpoint_dir_in(desc); 171 + ep->ep.maxpacket = usb_endpoint_maxp(desc); 172 + 173 + return fotg210_config_ep(ep, desc); 174 + } 175 + 176 + static void fotg210_reset_tseq(struct fotg210_udc *fotg210, u8 epnum) 177 + { 178 + struct fotg210_ep *ep = fotg210->ep[epnum]; 179 + u32 value; 180 + void __iomem *reg; 181 + 182 + reg = (ep->dir_in) ? 183 + fotg210->reg + FOTG210_INEPMPSR(epnum) : 184 + fotg210->reg + FOTG210_OUTEPMPSR(epnum); 185 + 186 + /* Note: Driver needs to set and clear INOUTEPMPSR_RESET_TSEQ 187 + * bit. Controller wouldn't clear this bit. WTF!!! 188 + */ 189 + 190 + value = ioread32(reg); 191 + value |= INOUTEPMPSR_RESET_TSEQ; 192 + iowrite32(value, reg); 193 + 194 + value = ioread32(reg); 195 + value &= ~INOUTEPMPSR_RESET_TSEQ; 196 + iowrite32(value, reg); 197 + } 198 + 199 + static int fotg210_ep_release(struct fotg210_ep *ep) 200 + { 201 + if (!ep->epnum) 202 + return 0; 203 + ep->epnum = 0; 204 + ep->stall = 0; 205 + ep->wedged = 0; 206 + 207 + fotg210_reset_tseq(ep->fotg210, ep->epnum); 208 + 209 + return 0; 210 + } 211 + 212 + static int fotg210_ep_disable(struct usb_ep *_ep) 213 + { 214 + struct fotg210_ep *ep; 215 + struct fotg210_request *req; 216 + unsigned long flags; 217 + 218 + BUG_ON(!_ep); 219 + 220 + ep = container_of(_ep, struct fotg210_ep, ep); 221 + 222 + while (!list_empty(&ep->queue)) { 223 + req = list_entry(ep->queue.next, 224 + struct fotg210_request, queue); 225 + spin_lock_irqsave(&ep->fotg210->lock, flags); 226 + fotg210_done(ep, req, -ECONNRESET); 227 + spin_unlock_irqrestore(&ep->fotg210->lock, flags); 228 + } 229 + 230 + return fotg210_ep_release(ep); 231 + } 232 + 233 + static struct usb_request *fotg210_ep_alloc_request(struct usb_ep *_ep, 234 + gfp_t gfp_flags) 235 + { 236 + struct fotg210_request *req; 237 + 238 + req = kzalloc(sizeof(struct fotg210_request), gfp_flags); 239 + if (!req) 240 + return NULL; 241 + 242 + INIT_LIST_HEAD(&req->queue); 243 + 244 + return &req->req; 245 + } 246 + 247 + static void fotg210_ep_free_request(struct usb_ep *_ep, 248 + struct usb_request *_req) 249 + { 250 + struct fotg210_request *req; 251 + 252 + req = container_of(_req, struct fotg210_request, req); 253 + kfree(req); 254 + } 255 + 256 + static void fotg210_enable_dma(struct fotg210_ep *ep, 257 + dma_addr_t d, u32 len) 258 + { 259 + u32 value; 260 + struct fotg210_udc *fotg210 = ep->fotg210; 261 + 262 + /* set transfer length and direction */ 263 + value = ioread32(fotg210->reg + FOTG210_DMACPSR1); 264 + value &= ~(DMACPSR1_DMA_LEN(0xFFFF) | DMACPSR1_DMA_TYPE(1)); 265 + value |= DMACPSR1_DMA_LEN(len) | DMACPSR1_DMA_TYPE(ep->dir_in); 266 + iowrite32(value, fotg210->reg + FOTG210_DMACPSR1); 267 + 268 + /* set device DMA target FIFO number */ 269 + value = ioread32(fotg210->reg + FOTG210_DMATFNR); 270 + if (ep->epnum) 271 + value |= DMATFNR_ACC_FN(ep->epnum - 1); 272 + else 273 + value |= DMATFNR_ACC_CXF; 274 + iowrite32(value, fotg210->reg + FOTG210_DMATFNR); 275 + 276 + /* set DMA memory address */ 277 + iowrite32(d, fotg210->reg + FOTG210_DMACPSR2); 278 + 279 + /* enable MDMA_EROR and MDMA_CMPLT interrupt */ 280 + value = ioread32(fotg210->reg + FOTG210_DMISGR2); 281 + value &= ~(DMISGR2_MDMA_CMPLT | DMISGR2_MDMA_ERROR); 282 + iowrite32(value, fotg210->reg + FOTG210_DMISGR2); 283 + 284 + /* start DMA */ 285 + value = ioread32(fotg210->reg + FOTG210_DMACPSR1); 286 + value |= DMACPSR1_DMA_START; 287 + iowrite32(value, fotg210->reg + FOTG210_DMACPSR1); 288 + } 289 + 290 + static void fotg210_disable_dma(struct fotg210_ep *ep) 291 + { 292 + iowrite32(DMATFNR_DISDMA, ep->fotg210->reg + FOTG210_DMATFNR); 293 + } 294 + 295 + static void fotg210_wait_dma_done(struct fotg210_ep *ep) 296 + { 297 + u32 value; 298 + 299 + do { 300 + value = ioread32(ep->fotg210->reg + FOTG210_DISGR2); 301 + if ((value & DISGR2_USBRST_INT) || 302 + (value & DISGR2_DMA_ERROR)) 303 + goto dma_reset; 304 + } while (!(value & DISGR2_DMA_CMPLT)); 305 + 306 + value &= ~DISGR2_DMA_CMPLT; 307 + iowrite32(value, ep->fotg210->reg + FOTG210_DISGR2); 308 + return; 309 + 310 + dma_reset: 311 + value = ioread32(ep->fotg210->reg + FOTG210_DMACPSR1); 312 + value |= DMACPSR1_DMA_ABORT; 313 + iowrite32(value, ep->fotg210->reg + FOTG210_DMACPSR1); 314 + 315 + /* reset fifo */ 316 + if (ep->epnum) { 317 + value = ioread32(ep->fotg210->reg + 318 + FOTG210_FIBCR(ep->epnum - 1)); 319 + value |= FIBCR_FFRST; 320 + iowrite32(value, ep->fotg210->reg + 321 + FOTG210_FIBCR(ep->epnum - 1)); 322 + } else { 323 + value = ioread32(ep->fotg210->reg + FOTG210_DCFESR); 324 + value |= DCFESR_CX_CLR; 325 + iowrite32(value, ep->fotg210->reg + FOTG210_DCFESR); 326 + } 327 + } 328 + 329 + static void fotg210_start_dma(struct fotg210_ep *ep, 330 + struct fotg210_request *req) 331 + { 332 + dma_addr_t d; 333 + u8 *buffer; 334 + u32 length; 335 + 336 + if (ep->epnum) { 337 + if (ep->dir_in) { 338 + buffer = req->req.buf; 339 + length = req->req.length; 340 + } else { 341 + buffer = req->req.buf + req->req.actual; 342 + length = ioread32(ep->fotg210->reg + 343 + FOTG210_FIBCR(ep->epnum - 1)); 344 + length &= FIBCR_BCFX; 345 + } 346 + } else { 347 + buffer = req->req.buf + req->req.actual; 348 + if (req->req.length - req->req.actual > ep->ep.maxpacket) 349 + length = ep->ep.maxpacket; 350 + else 351 + length = req->req.length; 352 + } 353 + 354 + d = dma_map_single(NULL, buffer, length, 355 + ep->dir_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 356 + 357 + if (dma_mapping_error(NULL, d)) { 358 + pr_err("dma_mapping_error\n"); 359 + return; 360 + } 361 + 362 + dma_sync_single_for_device(NULL, d, length, 363 + ep->dir_in ? DMA_TO_DEVICE : 364 + DMA_FROM_DEVICE); 365 + 366 + fotg210_enable_dma(ep, d, length); 367 + 368 + /* check if dma is done */ 369 + fotg210_wait_dma_done(ep); 370 + 371 + fotg210_disable_dma(ep); 372 + 373 + /* update actual transfer length */ 374 + req->req.actual += length; 375 + 376 + dma_unmap_single(NULL, d, length, DMA_TO_DEVICE); 377 + } 378 + 379 + static void fotg210_ep0_queue(struct fotg210_ep *ep, 380 + struct fotg210_request *req) 381 + { 382 + if (!req->req.length) { 383 + fotg210_done(ep, req, 0); 384 + return; 385 + } 386 + if (ep->dir_in) { /* if IN */ 387 + if (req->req.length) { 388 + fotg210_start_dma(ep, req); 389 + } else { 390 + pr_err("%s : req->req.length = 0x%x\n", 391 + __func__, req->req.length); 392 + } 393 + if ((req->req.length == req->req.actual) || 394 + (req->req.actual < ep->ep.maxpacket)) 395 + fotg210_done(ep, req, 0); 396 + } else { /* OUT */ 397 + if (!req->req.length) { 398 + fotg210_done(ep, req, 0); 399 + } else { 400 + u32 value = ioread32(ep->fotg210->reg + 401 + FOTG210_DMISGR0); 402 + 403 + value &= ~DMISGR0_MCX_OUT_INT; 404 + iowrite32(value, ep->fotg210->reg + FOTG210_DMISGR0); 405 + } 406 + } 407 + } 408 + 409 + static int fotg210_ep_queue(struct usb_ep *_ep, struct usb_request *_req, 410 + gfp_t gfp_flags) 411 + { 412 + struct fotg210_ep *ep; 413 + struct fotg210_request *req; 414 + unsigned long flags; 415 + int request = 0; 416 + 417 + ep = container_of(_ep, struct fotg210_ep, ep); 418 + req = container_of(_req, struct fotg210_request, req); 419 + 420 + if (ep->fotg210->gadget.speed == USB_SPEED_UNKNOWN) 421 + return -ESHUTDOWN; 422 + 423 + spin_lock_irqsave(&ep->fotg210->lock, flags); 424 + 425 + if (list_empty(&ep->queue)) 426 + request = 1; 427 + 428 + list_add_tail(&req->queue, &ep->queue); 429 + 430 + req->req.actual = 0; 431 + req->req.status = -EINPROGRESS; 432 + 433 + if (!ep->epnum) /* ep0 */ 434 + fotg210_ep0_queue(ep, req); 435 + else if (request && !ep->stall) 436 + fotg210_enable_fifo_int(ep); 437 + 438 + spin_unlock_irqrestore(&ep->fotg210->lock, flags); 439 + 440 + return 0; 441 + } 442 + 443 + static int fotg210_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 444 + { 445 + struct fotg210_ep *ep; 446 + struct fotg210_request *req; 447 + unsigned long flags; 448 + 449 + ep = container_of(_ep, struct fotg210_ep, ep); 450 + req = container_of(_req, struct fotg210_request, req); 451 + 452 + spin_lock_irqsave(&ep->fotg210->lock, flags); 453 + if (!list_empty(&ep->queue)) 454 + fotg210_done(ep, req, -ECONNRESET); 455 + spin_unlock_irqrestore(&ep->fotg210->lock, flags); 456 + 457 + return 0; 458 + } 459 + 460 + static void fotg210_set_epnstall(struct fotg210_ep *ep) 461 + { 462 + struct fotg210_udc *fotg210 = ep->fotg210; 463 + u32 value; 464 + void __iomem *reg; 465 + 466 + /* check if IN FIFO is empty before stall */ 467 + if (ep->dir_in) { 468 + do { 469 + value = ioread32(fotg210->reg + FOTG210_DCFESR); 470 + } while (!(value & DCFESR_FIFO_EMPTY(ep->epnum - 1))); 471 + } 472 + 473 + reg = (ep->dir_in) ? 474 + fotg210->reg + FOTG210_INEPMPSR(ep->epnum) : 475 + fotg210->reg + FOTG210_OUTEPMPSR(ep->epnum); 476 + value = ioread32(reg); 477 + value |= INOUTEPMPSR_STL_EP; 478 + iowrite32(value, reg); 479 + } 480 + 481 + static void fotg210_clear_epnstall(struct fotg210_ep *ep) 482 + { 483 + struct fotg210_udc *fotg210 = ep->fotg210; 484 + u32 value; 485 + void __iomem *reg; 486 + 487 + reg = (ep->dir_in) ? 488 + fotg210->reg + FOTG210_INEPMPSR(ep->epnum) : 489 + fotg210->reg + FOTG210_OUTEPMPSR(ep->epnum); 490 + value = ioread32(reg); 491 + value &= ~INOUTEPMPSR_STL_EP; 492 + iowrite32(value, reg); 493 + } 494 + 495 + static int fotg210_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedge) 496 + { 497 + struct fotg210_ep *ep; 498 + struct fotg210_udc *fotg210; 499 + unsigned long flags; 500 + int ret = 0; 501 + 502 + ep = container_of(_ep, struct fotg210_ep, ep); 503 + 504 + fotg210 = ep->fotg210; 505 + 506 + spin_lock_irqsave(&ep->fotg210->lock, flags); 507 + 508 + if (value) { 509 + fotg210_set_epnstall(ep); 510 + ep->stall = 1; 511 + if (wedge) 512 + ep->wedged = 1; 513 + } else { 514 + fotg210_reset_tseq(fotg210, ep->epnum); 515 + fotg210_clear_epnstall(ep); 516 + ep->stall = 0; 517 + ep->wedged = 0; 518 + if (!list_empty(&ep->queue)) 519 + fotg210_enable_fifo_int(ep); 520 + } 521 + 522 + spin_unlock_irqrestore(&ep->fotg210->lock, flags); 523 + return ret; 524 + } 525 + 526 + static int fotg210_ep_set_halt(struct usb_ep *_ep, int value) 527 + { 528 + return fotg210_set_halt_and_wedge(_ep, value, 0); 529 + } 530 + 531 + static int fotg210_ep_set_wedge(struct usb_ep *_ep) 532 + { 533 + return fotg210_set_halt_and_wedge(_ep, 1, 1); 534 + } 535 + 536 + static void fotg210_ep_fifo_flush(struct usb_ep *_ep) 537 + { 538 + } 539 + 540 + static struct usb_ep_ops fotg210_ep_ops = { 541 + .enable = fotg210_ep_enable, 542 + .disable = fotg210_ep_disable, 543 + 544 + .alloc_request = fotg210_ep_alloc_request, 545 + .free_request = fotg210_ep_free_request, 546 + 547 + .queue = fotg210_ep_queue, 548 + .dequeue = fotg210_ep_dequeue, 549 + 550 + .set_halt = fotg210_ep_set_halt, 551 + .fifo_flush = fotg210_ep_fifo_flush, 552 + .set_wedge = fotg210_ep_set_wedge, 553 + }; 554 + 555 + static void fotg210_clear_tx0byte(struct fotg210_udc *fotg210) 556 + { 557 + u32 value = ioread32(fotg210->reg + FOTG210_TX0BYTE); 558 + 559 + value &= ~(TX0BYTE_EP1 | TX0BYTE_EP2 | TX0BYTE_EP3 560 + | TX0BYTE_EP4); 561 + iowrite32(value, fotg210->reg + FOTG210_TX0BYTE); 562 + } 563 + 564 + static void fotg210_clear_rx0byte(struct fotg210_udc *fotg210) 565 + { 566 + u32 value = ioread32(fotg210->reg + FOTG210_RX0BYTE); 567 + 568 + value &= ~(RX0BYTE_EP1 | RX0BYTE_EP2 | RX0BYTE_EP3 569 + | RX0BYTE_EP4); 570 + iowrite32(value, fotg210->reg + FOTG210_RX0BYTE); 571 + } 572 + 573 + /* read 8-byte setup packet only */ 574 + static void fotg210_rdsetupp(struct fotg210_udc *fotg210, 575 + u8 *buffer) 576 + { 577 + int i = 0; 578 + u8 *tmp = buffer; 579 + u32 data; 580 + u32 length = 8; 581 + 582 + iowrite32(DMATFNR_ACC_CXF, fotg210->reg + FOTG210_DMATFNR); 583 + 584 + for (i = (length >> 2); i > 0; i--) { 585 + data = ioread32(fotg210->reg + FOTG210_CXPORT); 586 + *tmp = data & 0xFF; 587 + *(tmp + 1) = (data >> 8) & 0xFF; 588 + *(tmp + 2) = (data >> 16) & 0xFF; 589 + *(tmp + 3) = (data >> 24) & 0xFF; 590 + tmp = tmp + 4; 591 + } 592 + 593 + switch (length % 4) { 594 + case 1: 595 + data = ioread32(fotg210->reg + FOTG210_CXPORT); 596 + *tmp = data & 0xFF; 597 + break; 598 + case 2: 599 + data = ioread32(fotg210->reg + FOTG210_CXPORT); 600 + *tmp = data & 0xFF; 601 + *(tmp + 1) = (data >> 8) & 0xFF; 602 + break; 603 + case 3: 604 + data = ioread32(fotg210->reg + FOTG210_CXPORT); 605 + *tmp = data & 0xFF; 606 + *(tmp + 1) = (data >> 8) & 0xFF; 607 + *(tmp + 2) = (data >> 16) & 0xFF; 608 + break; 609 + default: 610 + break; 611 + } 612 + 613 + iowrite32(DMATFNR_DISDMA, fotg210->reg + FOTG210_DMATFNR); 614 + } 615 + 616 + static void fotg210_set_configuration(struct fotg210_udc *fotg210) 617 + { 618 + u32 value = ioread32(fotg210->reg + FOTG210_DAR); 619 + 620 + value |= DAR_AFT_CONF; 621 + iowrite32(value, fotg210->reg + FOTG210_DAR); 622 + } 623 + 624 + static void fotg210_set_dev_addr(struct fotg210_udc *fotg210, u32 addr) 625 + { 626 + u32 value = ioread32(fotg210->reg + FOTG210_DAR); 627 + 628 + value |= (addr & 0x7F); 629 + iowrite32(value, fotg210->reg + FOTG210_DAR); 630 + } 631 + 632 + static void fotg210_set_cxstall(struct fotg210_udc *fotg210) 633 + { 634 + u32 value = ioread32(fotg210->reg + FOTG210_DCFESR); 635 + 636 + value |= DCFESR_CX_STL; 637 + iowrite32(value, fotg210->reg + FOTG210_DCFESR); 638 + } 639 + 640 + static void fotg210_request_error(struct fotg210_udc *fotg210) 641 + { 642 + fotg210_set_cxstall(fotg210); 643 + pr_err("request error!!\n"); 644 + } 645 + 646 + static void fotg210_set_address(struct fotg210_udc *fotg210, 647 + struct usb_ctrlrequest *ctrl) 648 + { 649 + if (ctrl->wValue >= 0x0100) { 650 + fotg210_request_error(fotg210); 651 + } else { 652 + fotg210_set_dev_addr(fotg210, ctrl->wValue); 653 + fotg210_set_cxdone(fotg210); 654 + } 655 + } 656 + 657 + static void fotg210_set_feature(struct fotg210_udc *fotg210, 658 + struct usb_ctrlrequest *ctrl) 659 + { 660 + switch (ctrl->bRequestType & USB_RECIP_MASK) { 661 + case USB_RECIP_DEVICE: 662 + fotg210_set_cxdone(fotg210); 663 + break; 664 + case USB_RECIP_INTERFACE: 665 + fotg210_set_cxdone(fotg210); 666 + break; 667 + case USB_RECIP_ENDPOINT: { 668 + u8 epnum; 669 + epnum = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK; 670 + if (epnum) 671 + fotg210_set_epnstall(fotg210->ep[epnum]); 672 + else 673 + fotg210_set_cxstall(fotg210); 674 + fotg210_set_cxdone(fotg210); 675 + } 676 + break; 677 + default: 678 + fotg210_request_error(fotg210); 679 + break; 680 + } 681 + } 682 + 683 + static void fotg210_clear_feature(struct fotg210_udc *fotg210, 684 + struct usb_ctrlrequest *ctrl) 685 + { 686 + struct fotg210_ep *ep = 687 + fotg210->ep[ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK]; 688 + 689 + switch (ctrl->bRequestType & USB_RECIP_MASK) { 690 + case USB_RECIP_DEVICE: 691 + fotg210_set_cxdone(fotg210); 692 + break; 693 + case USB_RECIP_INTERFACE: 694 + fotg210_set_cxdone(fotg210); 695 + break; 696 + case USB_RECIP_ENDPOINT: 697 + if (ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK) { 698 + if (ep->wedged) { 699 + fotg210_set_cxdone(fotg210); 700 + break; 701 + } 702 + if (ep->stall) 703 + fotg210_set_halt_and_wedge(&ep->ep, 0, 0); 704 + } 705 + fotg210_set_cxdone(fotg210); 706 + break; 707 + default: 708 + fotg210_request_error(fotg210); 709 + break; 710 + } 711 + } 712 + 713 + static int fotg210_is_epnstall(struct fotg210_ep *ep) 714 + { 715 + struct fotg210_udc *fotg210 = ep->fotg210; 716 + u32 value; 717 + void __iomem *reg; 718 + 719 + reg = (ep->dir_in) ? 720 + fotg210->reg + FOTG210_INEPMPSR(ep->epnum) : 721 + fotg210->reg + FOTG210_OUTEPMPSR(ep->epnum); 722 + value = ioread32(reg); 723 + return value & INOUTEPMPSR_STL_EP ? 1 : 0; 724 + } 725 + 726 + static void fotg210_get_status(struct fotg210_udc *fotg210, 727 + struct usb_ctrlrequest *ctrl) 728 + { 729 + u8 epnum; 730 + 731 + switch (ctrl->bRequestType & USB_RECIP_MASK) { 732 + case USB_RECIP_DEVICE: 733 + fotg210->ep0_data = 1 << USB_DEVICE_SELF_POWERED; 734 + break; 735 + case USB_RECIP_INTERFACE: 736 + fotg210->ep0_data = 0; 737 + break; 738 + case USB_RECIP_ENDPOINT: 739 + epnum = ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK; 740 + if (epnum) 741 + fotg210->ep0_data = 742 + fotg210_is_epnstall(fotg210->ep[epnum]) 743 + << USB_ENDPOINT_HALT; 744 + else 745 + fotg210_request_error(fotg210); 746 + break; 747 + 748 + default: 749 + fotg210_request_error(fotg210); 750 + return; /* exit */ 751 + } 752 + 753 + fotg210->ep0_req->buf = &fotg210->ep0_data; 754 + fotg210->ep0_req->length = 2; 755 + 756 + spin_unlock(&fotg210->lock); 757 + fotg210_ep_queue(fotg210->gadget.ep0, fotg210->ep0_req, GFP_KERNEL); 758 + spin_lock(&fotg210->lock); 759 + } 760 + 761 + static int fotg210_setup_packet(struct fotg210_udc *fotg210, 762 + struct usb_ctrlrequest *ctrl) 763 + { 764 + u8 *p = (u8 *)ctrl; 765 + u8 ret = 0; 766 + 767 + fotg210_rdsetupp(fotg210, p); 768 + 769 + fotg210->ep[0]->dir_in = ctrl->bRequestType & USB_DIR_IN; 770 + 771 + if (fotg210->gadget.speed == USB_SPEED_UNKNOWN) { 772 + u32 value = ioread32(fotg210->reg + FOTG210_DMCR); 773 + fotg210->gadget.speed = value & DMCR_HS_EN ? 774 + USB_SPEED_HIGH : USB_SPEED_FULL; 775 + } 776 + 777 + /* check request */ 778 + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { 779 + switch (ctrl->bRequest) { 780 + case USB_REQ_GET_STATUS: 781 + fotg210_get_status(fotg210, ctrl); 782 + break; 783 + case USB_REQ_CLEAR_FEATURE: 784 + fotg210_clear_feature(fotg210, ctrl); 785 + break; 786 + case USB_REQ_SET_FEATURE: 787 + fotg210_set_feature(fotg210, ctrl); 788 + break; 789 + case USB_REQ_SET_ADDRESS: 790 + fotg210_set_address(fotg210, ctrl); 791 + break; 792 + case USB_REQ_SET_CONFIGURATION: 793 + fotg210_set_configuration(fotg210); 794 + ret = 1; 795 + break; 796 + default: 797 + ret = 1; 798 + break; 799 + } 800 + } else { 801 + ret = 1; 802 + } 803 + 804 + return ret; 805 + } 806 + 807 + static void fotg210_ep0out(struct fotg210_udc *fotg210) 808 + { 809 + struct fotg210_ep *ep = fotg210->ep[0]; 810 + 811 + if (!list_empty(&ep->queue) && !ep->dir_in) { 812 + struct fotg210_request *req; 813 + 814 + req = list_first_entry(&ep->queue, 815 + struct fotg210_request, queue); 816 + 817 + if (req->req.length) 818 + fotg210_start_dma(ep, req); 819 + 820 + if ((req->req.length - req->req.actual) < ep->ep.maxpacket) 821 + fotg210_done(ep, req, 0); 822 + } else { 823 + pr_err("%s : empty queue\n", __func__); 824 + } 825 + } 826 + 827 + static void fotg210_ep0in(struct fotg210_udc *fotg210) 828 + { 829 + struct fotg210_ep *ep = fotg210->ep[0]; 830 + 831 + if ((!list_empty(&ep->queue)) && (ep->dir_in)) { 832 + struct fotg210_request *req; 833 + 834 + req = list_entry(ep->queue.next, 835 + struct fotg210_request, queue); 836 + 837 + if (req->req.length) 838 + fotg210_start_dma(ep, req); 839 + 840 + if ((req->req.length - req->req.actual) < ep->ep.maxpacket) 841 + fotg210_done(ep, req, 0); 842 + } else { 843 + fotg210_set_cxdone(fotg210); 844 + } 845 + } 846 + 847 + static void fotg210_clear_comabt_int(struct fotg210_udc *fotg210) 848 + { 849 + u32 value = ioread32(fotg210->reg + FOTG210_DISGR0); 850 + 851 + value &= ~DISGR0_CX_COMABT_INT; 852 + iowrite32(value, fotg210->reg + FOTG210_DISGR0); 853 + } 854 + 855 + static void fotg210_in_fifo_handler(struct fotg210_ep *ep) 856 + { 857 + struct fotg210_request *req = list_entry(ep->queue.next, 858 + struct fotg210_request, queue); 859 + 860 + if (req->req.length) 861 + fotg210_start_dma(ep, req); 862 + fotg210_done(ep, req, 0); 863 + } 864 + 865 + static void fotg210_out_fifo_handler(struct fotg210_ep *ep) 866 + { 867 + struct fotg210_request *req = list_entry(ep->queue.next, 868 + struct fotg210_request, queue); 869 + 870 + fotg210_start_dma(ep, req); 871 + 872 + /* finish out transfer */ 873 + if (req->req.length == req->req.actual || 874 + req->req.actual < ep->ep.maxpacket) 875 + fotg210_done(ep, req, 0); 876 + } 877 + 878 + static irqreturn_t fotg210_irq(int irq, void *_fotg210) 879 + { 880 + struct fotg210_udc *fotg210 = _fotg210; 881 + u32 int_grp = ioread32(fotg210->reg + FOTG210_DIGR); 882 + u32 int_msk = ioread32(fotg210->reg + FOTG210_DMIGR); 883 + 884 + int_grp &= ~int_msk; 885 + 886 + spin_lock(&fotg210->lock); 887 + 888 + if (int_grp & DIGR_INT_G2) { 889 + void __iomem *reg = fotg210->reg + FOTG210_DISGR2; 890 + u32 int_grp2 = ioread32(reg); 891 + u32 int_msk2 = ioread32(fotg210->reg + FOTG210_DMISGR2); 892 + u32 value; 893 + 894 + int_grp2 &= ~int_msk2; 895 + 896 + if (int_grp2 & DISGR2_USBRST_INT) { 897 + value = ioread32(reg); 898 + value &= ~DISGR2_USBRST_INT; 899 + iowrite32(value, reg); 900 + pr_info("fotg210 udc reset\n"); 901 + } 902 + if (int_grp2 & DISGR2_SUSP_INT) { 903 + value = ioread32(reg); 904 + value &= ~DISGR2_SUSP_INT; 905 + iowrite32(value, reg); 906 + pr_info("fotg210 udc suspend\n"); 907 + } 908 + if (int_grp2 & DISGR2_RESM_INT) { 909 + value = ioread32(reg); 910 + value &= ~DISGR2_RESM_INT; 911 + iowrite32(value, reg); 912 + pr_info("fotg210 udc resume\n"); 913 + } 914 + if (int_grp2 & DISGR2_ISO_SEQ_ERR_INT) { 915 + value = ioread32(reg); 916 + value &= ~DISGR2_ISO_SEQ_ERR_INT; 917 + iowrite32(value, reg); 918 + pr_info("fotg210 iso sequence error\n"); 919 + } 920 + if (int_grp2 & DISGR2_ISO_SEQ_ABORT_INT) { 921 + value = ioread32(reg); 922 + value &= ~DISGR2_ISO_SEQ_ABORT_INT; 923 + iowrite32(value, reg); 924 + pr_info("fotg210 iso sequence abort\n"); 925 + } 926 + if (int_grp2 & DISGR2_TX0BYTE_INT) { 927 + fotg210_clear_tx0byte(fotg210); 928 + value = ioread32(reg); 929 + value &= ~DISGR2_TX0BYTE_INT; 930 + iowrite32(value, reg); 931 + pr_info("fotg210 transferred 0 byte\n"); 932 + } 933 + if (int_grp2 & DISGR2_RX0BYTE_INT) { 934 + fotg210_clear_rx0byte(fotg210); 935 + value = ioread32(reg); 936 + value &= ~DISGR2_RX0BYTE_INT; 937 + iowrite32(value, reg); 938 + pr_info("fotg210 received 0 byte\n"); 939 + } 940 + if (int_grp2 & DISGR2_DMA_ERROR) { 941 + value = ioread32(reg); 942 + value &= ~DISGR2_DMA_ERROR; 943 + iowrite32(value, reg); 944 + } 945 + } 946 + 947 + if (int_grp & DIGR_INT_G0) { 948 + void __iomem *reg = fotg210->reg + FOTG210_DISGR0; 949 + u32 int_grp0 = ioread32(reg); 950 + u32 int_msk0 = ioread32(fotg210->reg + FOTG210_DMISGR0); 951 + struct usb_ctrlrequest ctrl; 952 + 953 + int_grp0 &= ~int_msk0; 954 + 955 + /* the highest priority in this source register */ 956 + if (int_grp0 & DISGR0_CX_COMABT_INT) { 957 + fotg210_clear_comabt_int(fotg210); 958 + pr_info("fotg210 CX command abort\n"); 959 + } 960 + 961 + if (int_grp0 & DISGR0_CX_SETUP_INT) { 962 + if (fotg210_setup_packet(fotg210, &ctrl)) { 963 + spin_unlock(&fotg210->lock); 964 + if (fotg210->driver->setup(&fotg210->gadget, 965 + &ctrl) < 0) 966 + fotg210_set_cxstall(fotg210); 967 + spin_lock(&fotg210->lock); 968 + } 969 + } 970 + if (int_grp0 & DISGR0_CX_COMEND_INT) 971 + pr_info("fotg210 cmd end\n"); 972 + 973 + if (int_grp0 & DISGR0_CX_IN_INT) 974 + fotg210_ep0in(fotg210); 975 + 976 + if (int_grp0 & DISGR0_CX_OUT_INT) 977 + fotg210_ep0out(fotg210); 978 + 979 + if (int_grp0 & DISGR0_CX_COMFAIL_INT) { 980 + fotg210_set_cxstall(fotg210); 981 + pr_info("fotg210 ep0 fail\n"); 982 + } 983 + } 984 + 985 + if (int_grp & DIGR_INT_G1) { 986 + void __iomem *reg = fotg210->reg + FOTG210_DISGR1; 987 + u32 int_grp1 = ioread32(reg); 988 + u32 int_msk1 = ioread32(fotg210->reg + FOTG210_DMISGR1); 989 + int fifo; 990 + 991 + int_grp1 &= ~int_msk1; 992 + 993 + for (fifo = 0; fifo < FOTG210_MAX_FIFO_NUM; fifo++) { 994 + if (int_grp1 & DISGR1_IN_INT(fifo)) 995 + fotg210_in_fifo_handler(fotg210->ep[fifo + 1]); 996 + 997 + if ((int_grp1 & DISGR1_OUT_INT(fifo)) || 998 + (int_grp1 & DISGR1_SPK_INT(fifo))) 999 + fotg210_out_fifo_handler(fotg210->ep[fifo + 1]); 1000 + } 1001 + } 1002 + 1003 + spin_unlock(&fotg210->lock); 1004 + 1005 + return IRQ_HANDLED; 1006 + } 1007 + 1008 + static void fotg210_disable_unplug(struct fotg210_udc *fotg210) 1009 + { 1010 + u32 reg = ioread32(fotg210->reg + FOTG210_PHYTMSR); 1011 + 1012 + reg &= ~PHYTMSR_UNPLUG; 1013 + iowrite32(reg, fotg210->reg + FOTG210_PHYTMSR); 1014 + } 1015 + 1016 + static int fotg210_udc_start(struct usb_gadget *g, 1017 + struct usb_gadget_driver *driver) 1018 + { 1019 + struct fotg210_udc *fotg210 = gadget_to_fotg210(g); 1020 + u32 value; 1021 + 1022 + /* hook up the driver */ 1023 + driver->driver.bus = NULL; 1024 + fotg210->driver = driver; 1025 + 1026 + /* enable device global interrupt */ 1027 + value = ioread32(fotg210->reg + FOTG210_DMCR); 1028 + value |= DMCR_GLINT_EN; 1029 + iowrite32(value, fotg210->reg + FOTG210_DMCR); 1030 + 1031 + return 0; 1032 + } 1033 + 1034 + static void fotg210_init(struct fotg210_udc *fotg210) 1035 + { 1036 + u32 value; 1037 + 1038 + /* disable global interrupt and set int polarity to active high */ 1039 + iowrite32(GMIR_MHC_INT | GMIR_MOTG_INT | GMIR_INT_POLARITY, 1040 + fotg210->reg + FOTG210_GMIR); 1041 + 1042 + /* disable device global interrupt */ 1043 + value = ioread32(fotg210->reg + FOTG210_DMCR); 1044 + value &= ~DMCR_GLINT_EN; 1045 + iowrite32(value, fotg210->reg + FOTG210_DMCR); 1046 + 1047 + /* disable all fifo interrupt */ 1048 + iowrite32(~(u32)0, fotg210->reg + FOTG210_DMISGR1); 1049 + 1050 + /* disable cmd end */ 1051 + value = ioread32(fotg210->reg + FOTG210_DMISGR0); 1052 + value |= DMISGR0_MCX_COMEND; 1053 + iowrite32(value, fotg210->reg + FOTG210_DMISGR0); 1054 + } 1055 + 1056 + static int fotg210_udc_stop(struct usb_gadget *g, 1057 + struct usb_gadget_driver *driver) 1058 + { 1059 + struct fotg210_udc *fotg210 = gadget_to_fotg210(g); 1060 + unsigned long flags; 1061 + 1062 + spin_lock_irqsave(&fotg210->lock, flags); 1063 + 1064 + fotg210_init(fotg210); 1065 + fotg210->driver = NULL; 1066 + 1067 + spin_unlock_irqrestore(&fotg210->lock, flags); 1068 + 1069 + return 0; 1070 + } 1071 + 1072 + static struct usb_gadget_ops fotg210_gadget_ops = { 1073 + .udc_start = fotg210_udc_start, 1074 + .udc_stop = fotg210_udc_stop, 1075 + }; 1076 + 1077 + static int __exit fotg210_udc_remove(struct platform_device *pdev) 1078 + { 1079 + struct fotg210_udc *fotg210 = dev_get_drvdata(&pdev->dev); 1080 + 1081 + usb_del_gadget_udc(&fotg210->gadget); 1082 + iounmap(fotg210->reg); 1083 + free_irq(platform_get_irq(pdev, 0), fotg210); 1084 + 1085 + fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req); 1086 + kfree(fotg210); 1087 + 1088 + return 0; 1089 + } 1090 + 1091 + static int __init fotg210_udc_probe(struct platform_device *pdev) 1092 + { 1093 + struct resource *res, *ires; 1094 + struct fotg210_udc *fotg210 = NULL; 1095 + struct fotg210_ep *_ep[FOTG210_MAX_NUM_EP]; 1096 + int ret = 0; 1097 + int i; 1098 + 1099 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1100 + if (!res) { 1101 + pr_err("platform_get_resource error.\n"); 1102 + return -ENODEV; 1103 + } 1104 + 1105 + ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1106 + if (!ires) { 1107 + pr_err("platform_get_resource IORESOURCE_IRQ error.\n"); 1108 + return -ENODEV; 1109 + } 1110 + 1111 + ret = -ENOMEM; 1112 + 1113 + /* initialize udc */ 1114 + fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL); 1115 + if (fotg210 == NULL) { 1116 + pr_err("kzalloc error\n"); 1117 + goto err_alloc; 1118 + } 1119 + 1120 + for (i = 0; i < FOTG210_MAX_NUM_EP; i++) { 1121 + _ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL); 1122 + if (_ep[i] == NULL) { 1123 + pr_err("_ep kzalloc error\n"); 1124 + goto err_alloc; 1125 + } 1126 + fotg210->ep[i] = _ep[i]; 1127 + } 1128 + 1129 + fotg210->reg = ioremap(res->start, resource_size(res)); 1130 + if (fotg210->reg == NULL) { 1131 + pr_err("ioremap error.\n"); 1132 + goto err_map; 1133 + } 1134 + 1135 + spin_lock_init(&fotg210->lock); 1136 + 1137 + dev_set_drvdata(&pdev->dev, fotg210); 1138 + 1139 + fotg210->gadget.ops = &fotg210_gadget_ops; 1140 + 1141 + fotg210->gadget.max_speed = USB_SPEED_HIGH; 1142 + fotg210->gadget.dev.parent = &pdev->dev; 1143 + fotg210->gadget.dev.dma_mask = pdev->dev.dma_mask; 1144 + fotg210->gadget.name = udc_name; 1145 + 1146 + INIT_LIST_HEAD(&fotg210->gadget.ep_list); 1147 + 1148 + for (i = 0; i < FOTG210_MAX_NUM_EP; i++) { 1149 + struct fotg210_ep *ep = fotg210->ep[i]; 1150 + 1151 + if (i) { 1152 + INIT_LIST_HEAD(&fotg210->ep[i]->ep.ep_list); 1153 + list_add_tail(&fotg210->ep[i]->ep.ep_list, 1154 + &fotg210->gadget.ep_list); 1155 + } 1156 + ep->fotg210 = fotg210; 1157 + INIT_LIST_HEAD(&ep->queue); 1158 + ep->ep.name = fotg210_ep_name[i]; 1159 + ep->ep.ops = &fotg210_ep_ops; 1160 + } 1161 + fotg210->ep[0]->ep.maxpacket = 0x40; 1162 + fotg210->gadget.ep0 = &fotg210->ep[0]->ep; 1163 + INIT_LIST_HEAD(&fotg210->gadget.ep0->ep_list); 1164 + 1165 + fotg210->ep0_req = fotg210_ep_alloc_request(&fotg210->ep[0]->ep, 1166 + GFP_KERNEL); 1167 + if (fotg210->ep0_req == NULL) 1168 + goto err_req; 1169 + 1170 + fotg210_init(fotg210); 1171 + 1172 + fotg210_disable_unplug(fotg210); 1173 + 1174 + ret = request_irq(ires->start, fotg210_irq, IRQF_SHARED, 1175 + udc_name, fotg210); 1176 + if (ret < 0) { 1177 + pr_err("request_irq error (%d)\n", ret); 1178 + goto err_irq; 1179 + } 1180 + 1181 + ret = usb_add_gadget_udc(&pdev->dev, &fotg210->gadget); 1182 + if (ret) 1183 + goto err_add_udc; 1184 + 1185 + dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1186 + 1187 + return 0; 1188 + 1189 + err_add_udc: 1190 + err_irq: 1191 + free_irq(ires->start, fotg210); 1192 + 1193 + err_req: 1194 + fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req); 1195 + 1196 + err_map: 1197 + if (fotg210->reg) 1198 + iounmap(fotg210->reg); 1199 + 1200 + err_alloc: 1201 + kfree(fotg210); 1202 + 1203 + return ret; 1204 + } 1205 + 1206 + static struct platform_driver fotg210_driver = { 1207 + .driver = { 1208 + .name = (char *)udc_name, 1209 + .owner = THIS_MODULE, 1210 + }, 1211 + .probe = fotg210_udc_probe, 1212 + .remove = fotg210_udc_remove, 1213 + }; 1214 + 1215 + module_platform_driver(fotg210_driver); 1216 + 1217 + MODULE_AUTHOR("Yuan-Hsin Chen <yhchen@faraday-tech.com>"); 1218 + MODULE_LICENSE("GPL"); 1219 + MODULE_DESCRIPTION(DRIVER_DESC);
+253
drivers/usb/gadget/fotg210.h
··· 1 + /* 2 + * Faraday FOTG210 USB OTG controller 3 + * 4 + * Copyright (C) 2013 Faraday Technology Corporation 5 + * Author: Yuan-Hsin Chen <yhchen@faraday-tech.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + */ 12 + 13 + #include <linux/kernel.h> 14 + 15 + #define FOTG210_MAX_NUM_EP 5 /* ep0...ep4 */ 16 + #define FOTG210_MAX_FIFO_NUM 4 /* fifo0...fifo4 */ 17 + 18 + /* Global Mask of HC/OTG/DEV interrupt Register(0xC4) */ 19 + #define FOTG210_GMIR 0xC4 20 + #define GMIR_INT_POLARITY 0x8 /*Active High*/ 21 + #define GMIR_MHC_INT 0x4 22 + #define GMIR_MOTG_INT 0x2 23 + #define GMIR_MDEV_INT 0x1 24 + 25 + /* Device Main Control Register(0x100) */ 26 + #define FOTG210_DMCR 0x100 27 + #define DMCR_HS_EN (1 << 6) 28 + #define DMCR_CHIP_EN (1 << 5) 29 + #define DMCR_SFRST (1 << 4) 30 + #define DMCR_GOSUSP (1 << 3) 31 + #define DMCR_GLINT_EN (1 << 2) 32 + #define DMCR_HALF_SPEED (1 << 1) 33 + #define DMCR_CAP_RMWAKUP (1 << 0) 34 + 35 + /* Device Address Register(0x104) */ 36 + #define FOTG210_DAR 0x104 37 + #define DAR_AFT_CONF (1 << 7) 38 + 39 + /* Device Test Register(0x108) */ 40 + #define FOTG210_DTR 0x108 41 + #define DTR_TST_CLRFF (1 << 0) 42 + 43 + /* PHY Test Mode Selector register(0x114) */ 44 + #define FOTG210_PHYTMSR 0x114 45 + #define PHYTMSR_TST_PKT (1 << 4) 46 + #define PHYTMSR_TST_SE0NAK (1 << 3) 47 + #define PHYTMSR_TST_KSTA (1 << 2) 48 + #define PHYTMSR_TST_JSTA (1 << 1) 49 + #define PHYTMSR_UNPLUG (1 << 0) 50 + 51 + /* Cx configuration and FIFO Empty Status register(0x120) */ 52 + #define FOTG210_DCFESR 0x120 53 + #define DCFESR_FIFO_EMPTY(fifo) (1 << 8 << (fifo)) 54 + #define DCFESR_CX_EMP (1 << 5) 55 + #define DCFESR_CX_CLR (1 << 3) 56 + #define DCFESR_CX_STL (1 << 2) 57 + #define DCFESR_TST_PKDONE (1 << 1) 58 + #define DCFESR_CX_DONE (1 << 0) 59 + 60 + /* Device IDLE Counter Register(0x124) */ 61 + #define FOTG210_DICR 0x124 62 + 63 + /* Device Mask of Interrupt Group Register (0x130) */ 64 + #define FOTG210_DMIGR 0x130 65 + #define DMIGR_MINT_G0 (1 << 0) 66 + 67 + /* Device Mask of Interrupt Source Group 0(0x134) */ 68 + #define FOTG210_DMISGR0 0x134 69 + #define DMISGR0_MCX_COMEND (1 << 3) 70 + #define DMISGR0_MCX_OUT_INT (1 << 2) 71 + #define DMISGR0_MCX_IN_INT (1 << 1) 72 + #define DMISGR0_MCX_SETUP_INT (1 << 0) 73 + 74 + /* Device Mask of Interrupt Source Group 1 Register(0x138)*/ 75 + #define FOTG210_DMISGR1 0x138 76 + #define DMISGR1_MF3_IN_INT (1 << 19) 77 + #define DMISGR1_MF2_IN_INT (1 << 18) 78 + #define DMISGR1_MF1_IN_INT (1 << 17) 79 + #define DMISGR1_MF0_IN_INT (1 << 16) 80 + #define DMISGR1_MF_IN_INT(fifo) (1 << (16 + (fifo))) 81 + #define DMISGR1_MF3_SPK_INT (1 << 7) 82 + #define DMISGR1_MF3_OUT_INT (1 << 6) 83 + #define DMISGR1_MF2_SPK_INT (1 << 5) 84 + #define DMISGR1_MF2_OUT_INT (1 << 4) 85 + #define DMISGR1_MF1_SPK_INT (1 << 3) 86 + #define DMISGR1_MF1_OUT_INT (1 << 2) 87 + #define DMISGR1_MF0_SPK_INT (1 << 1) 88 + #define DMISGR1_MF0_OUT_INT (1 << 0) 89 + #define DMISGR1_MF_OUTSPK_INT(fifo) (0x3 << (fifo) * 2) 90 + 91 + /* Device Mask of Interrupt Source Group 2 Register (0x13C) */ 92 + #define FOTG210_DMISGR2 0x13C 93 + #define DMISGR2_MDMA_ERROR (1 << 8) 94 + #define DMISGR2_MDMA_CMPLT (1 << 7) 95 + 96 + /* Device Interrupt group Register (0x140) */ 97 + #define FOTG210_DIGR 0x140 98 + #define DIGR_INT_G2 (1 << 2) 99 + #define DIGR_INT_G1 (1 << 1) 100 + #define DIGR_INT_G0 (1 << 0) 101 + 102 + /* Device Interrupt Source Group 0 Register (0x144) */ 103 + #define FOTG210_DISGR0 0x144 104 + #define DISGR0_CX_COMABT_INT (1 << 5) 105 + #define DISGR0_CX_COMFAIL_INT (1 << 4) 106 + #define DISGR0_CX_COMEND_INT (1 << 3) 107 + #define DISGR0_CX_OUT_INT (1 << 2) 108 + #define DISGR0_CX_IN_INT (1 << 1) 109 + #define DISGR0_CX_SETUP_INT (1 << 0) 110 + 111 + /* Device Interrupt Source Group 1 Register (0x148) */ 112 + #define FOTG210_DISGR1 0x148 113 + #define DISGR1_OUT_INT(fifo) (1 << ((fifo) * 2)) 114 + #define DISGR1_SPK_INT(fifo) (1 << 1 << ((fifo) * 2)) 115 + #define DISGR1_IN_INT(fifo) (1 << 16 << (fifo)) 116 + 117 + /* Device Interrupt Source Group 2 Register (0x14C) */ 118 + #define FOTG210_DISGR2 0x14C 119 + #define DISGR2_DMA_ERROR (1 << 8) 120 + #define DISGR2_DMA_CMPLT (1 << 7) 121 + #define DISGR2_RX0BYTE_INT (1 << 6) 122 + #define DISGR2_TX0BYTE_INT (1 << 5) 123 + #define DISGR2_ISO_SEQ_ABORT_INT (1 << 4) 124 + #define DISGR2_ISO_SEQ_ERR_INT (1 << 3) 125 + #define DISGR2_RESM_INT (1 << 2) 126 + #define DISGR2_SUSP_INT (1 << 1) 127 + #define DISGR2_USBRST_INT (1 << 0) 128 + 129 + /* Device Receive Zero-Length Data Packet Register (0x150)*/ 130 + #define FOTG210_RX0BYTE 0x150 131 + #define RX0BYTE_EP8 (1 << 7) 132 + #define RX0BYTE_EP7 (1 << 6) 133 + #define RX0BYTE_EP6 (1 << 5) 134 + #define RX0BYTE_EP5 (1 << 4) 135 + #define RX0BYTE_EP4 (1 << 3) 136 + #define RX0BYTE_EP3 (1 << 2) 137 + #define RX0BYTE_EP2 (1 << 1) 138 + #define RX0BYTE_EP1 (1 << 0) 139 + 140 + /* Device Transfer Zero-Length Data Packet Register (0x154)*/ 141 + #define FOTG210_TX0BYTE 0x154 142 + #define TX0BYTE_EP8 (1 << 7) 143 + #define TX0BYTE_EP7 (1 << 6) 144 + #define TX0BYTE_EP6 (1 << 5) 145 + #define TX0BYTE_EP5 (1 << 4) 146 + #define TX0BYTE_EP4 (1 << 3) 147 + #define TX0BYTE_EP3 (1 << 2) 148 + #define TX0BYTE_EP2 (1 << 1) 149 + #define TX0BYTE_EP1 (1 << 0) 150 + 151 + /* Device IN Endpoint x MaxPacketSize Register(0x160+4*(x-1)) */ 152 + #define FOTG210_INEPMPSR(ep) (0x160 + 4 * ((ep) - 1)) 153 + #define INOUTEPMPSR_MPS(mps) ((mps) & 0x2FF) 154 + #define INOUTEPMPSR_STL_EP (1 << 11) 155 + #define INOUTEPMPSR_RESET_TSEQ (1 << 12) 156 + 157 + /* Device OUT Endpoint x MaxPacketSize Register(0x180+4*(x-1)) */ 158 + #define FOTG210_OUTEPMPSR(ep) (0x180 + 4 * ((ep) - 1)) 159 + 160 + /* Device Endpoint 1~4 Map Register (0x1A0) */ 161 + #define FOTG210_EPMAP 0x1A0 162 + #define EPMAP_FIFONO(ep, dir) \ 163 + ((((ep) - 1) << ((ep) - 1) * 8) << ((dir) ? 0 : 4)) 164 + #define EPMAP_FIFONOMSK(ep, dir) \ 165 + ((3 << ((ep) - 1) * 8) << ((dir) ? 0 : 4)) 166 + 167 + /* Device FIFO Map Register (0x1A8) */ 168 + #define FOTG210_FIFOMAP 0x1A8 169 + #define FIFOMAP_DIROUT(fifo) (0x0 << 4 << (fifo) * 8) 170 + #define FIFOMAP_DIRIN(fifo) (0x1 << 4 << (fifo) * 8) 171 + #define FIFOMAP_BIDIR(fifo) (0x2 << 4 << (fifo) * 8) 172 + #define FIFOMAP_NA(fifo) (0x3 << 4 << (fifo) * 8) 173 + #define FIFOMAP_EPNO(ep) ((ep) << ((ep) - 1) * 8) 174 + #define FIFOMAP_EPNOMSK(ep) (0xF << ((ep) - 1) * 8) 175 + 176 + /* Device FIFO Confuguration Register (0x1AC) */ 177 + #define FOTG210_FIFOCF 0x1AC 178 + #define FIFOCF_TYPE(type, fifo) ((type) << (fifo) * 8) 179 + #define FIFOCF_BLK_SIN(fifo) (0x0 << (fifo) * 8 << 2) 180 + #define FIFOCF_BLK_DUB(fifo) (0x1 << (fifo) * 8 << 2) 181 + #define FIFOCF_BLK_TRI(fifo) (0x2 << (fifo) * 8 << 2) 182 + #define FIFOCF_BLKSZ_512(fifo) (0x0 << (fifo) * 8 << 4) 183 + #define FIFOCF_BLKSZ_1024(fifo) (0x1 << (fifo) * 8 << 4) 184 + #define FIFOCF_FIFO_EN(fifo) (0x1 << (fifo) * 8 << 5) 185 + 186 + /* Device FIFO n Instruction and Byte Count Register (0x1B0+4*n) */ 187 + #define FOTG210_FIBCR(fifo) (0x1B0 + (fifo) * 4) 188 + #define FIBCR_BCFX 0x7FF 189 + #define FIBCR_FFRST (1 << 12) 190 + 191 + /* Device DMA Target FIFO Number Register (0x1C0) */ 192 + #define FOTG210_DMATFNR 0x1C0 193 + #define DMATFNR_ACC_CXF (1 << 4) 194 + #define DMATFNR_ACC_F3 (1 << 3) 195 + #define DMATFNR_ACC_F2 (1 << 2) 196 + #define DMATFNR_ACC_F1 (1 << 1) 197 + #define DMATFNR_ACC_F0 (1 << 0) 198 + #define DMATFNR_ACC_FN(fifo) (1 << (fifo)) 199 + #define DMATFNR_DISDMA 0 200 + 201 + /* Device DMA Controller Parameter setting 1 Register (0x1C8) */ 202 + #define FOTG210_DMACPSR1 0x1C8 203 + #define DMACPSR1_DMA_LEN(len) (((len) & 0xFFFF) << 8) 204 + #define DMACPSR1_DMA_ABORT (1 << 3) 205 + #define DMACPSR1_DMA_TYPE(dir_in) (((dir_in) ? 1 : 0) << 1) 206 + #define DMACPSR1_DMA_START (1 << 0) 207 + 208 + /* Device DMA Controller Parameter setting 2 Register (0x1CC) */ 209 + #define FOTG210_DMACPSR2 0x1CC 210 + 211 + /* Device DMA Controller Parameter setting 3 Register (0x1CC) */ 212 + #define FOTG210_CXPORT 0x1D0 213 + 214 + struct fotg210_request { 215 + struct usb_request req; 216 + struct list_head queue; 217 + }; 218 + 219 + struct fotg210_ep { 220 + struct usb_ep ep; 221 + struct fotg210_udc *fotg210; 222 + 223 + struct list_head queue; 224 + unsigned stall:1; 225 + unsigned wedged:1; 226 + unsigned use_dma:1; 227 + 228 + unsigned char epnum; 229 + unsigned char type; 230 + unsigned char dir_in; 231 + unsigned int maxp; 232 + const struct usb_endpoint_descriptor *desc; 233 + }; 234 + 235 + struct fotg210_udc { 236 + spinlock_t lock; /* protect the struct */ 237 + void __iomem *reg; 238 + 239 + unsigned long irq_trigger; 240 + 241 + struct usb_gadget gadget; 242 + struct usb_gadget_driver *driver; 243 + 244 + struct fotg210_ep *ep[FOTG210_MAX_NUM_EP]; 245 + 246 + struct usb_request *ep0_req; /* for internal request */ 247 + __le16 ep0_data; 248 + u8 ep0_dir; /* 0/0x80 out/in */ 249 + 250 + u8 reenum; /* if re-enumeration */ 251 + }; 252 + 253 + #define gadget_to_fotg210(g) container_of((g), struct fotg210_udc, gadget)
+2 -2
drivers/usb/gadget/fsl_qe_udc.c
··· 2589 2589 if (ret) 2590 2590 goto err6; 2591 2591 2592 - dev_set_drvdata(&ofdev->dev, udc); 2592 + platform_set_drvdata(ofdev, udc); 2593 2593 dev_info(udc->dev, 2594 2594 "%s USB controller initialized as device\n", 2595 2595 (udc->soc_type == PORT_QE) ? "QE" : "CPM"); ··· 2640 2640 2641 2641 static int qe_udc_remove(struct platform_device *ofdev) 2642 2642 { 2643 - struct qe_udc *udc = dev_get_drvdata(&ofdev->dev); 2643 + struct qe_udc *udc = platform_get_drvdata(ofdev); 2644 2644 struct qe_ep *ep; 2645 2645 unsigned int size; 2646 2646 DECLARE_COMPLETION(done);
+2 -2
drivers/usb/gadget/fusb300_udc.c
··· 1347 1347 1348 1348 static int __exit fusb300_remove(struct platform_device *pdev) 1349 1349 { 1350 - struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev); 1350 + struct fusb300 *fusb300 = platform_get_drvdata(pdev); 1351 1351 1352 1352 usb_del_gadget_udc(&fusb300->gadget); 1353 1353 iounmap(fusb300->reg); ··· 1416 1416 1417 1417 spin_lock_init(&fusb300->lock); 1418 1418 1419 - dev_set_drvdata(&pdev->dev, fusb300); 1419 + platform_set_drvdata(pdev, fusb300); 1420 1420 1421 1421 fusb300->gadget.ops = &fusb300_gadget_ops; 1422 1422
+12 -6
drivers/usb/gadget/g_ffs.c
··· 28 28 # define USB_ETH_RNDIS y 29 29 # endif 30 30 31 + #define USBF_ECM_INCLUDED 31 32 # include "f_ecm.c" 33 + #define USB_FSUBSET_INCLUDED 32 34 # include "f_subset.c" 33 35 # ifdef USB_ETH_RNDIS 36 + # define USB_FRNDIS_INCLUDED 34 37 # include "f_rndis.c" 35 - # include "rndis.c" 38 + # include "rndis.h" 36 39 # endif 37 - # include "u_ether.c" 40 + # include "u_ether.h" 38 41 39 - static u8 gfs_hostaddr[ETH_ALEN]; 42 + static u8 gfs_host_mac[ETH_ALEN]; 40 43 static struct eth_dev *the_dev; 41 44 # ifdef CONFIG_USB_FUNCTIONFS_ETH 42 45 static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], ··· 48 45 #else 49 46 # define the_dev NULL 50 47 # define gether_cleanup(dev) do { } while (0) 51 - # define gfs_hostaddr NULL 48 + # define gfs_host_mac NULL 52 49 struct eth_dev; 53 50 #endif 54 51 ··· 75 72 }; 76 73 77 74 USB_GADGET_COMPOSITE_OPTIONS(); 75 + 76 + USB_ETHERNET_MODULE_PARAMETERS(); 78 77 79 78 static struct usb_device_descriptor gfs_dev_desc = { 80 79 .bLength = sizeof gfs_dev_desc, ··· 355 350 if (missing_funcs) 356 351 return -ENODEV; 357 352 #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS 358 - the_dev = gether_setup(cdev->gadget, gfs_hostaddr); 353 + the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, gfs_host_mac, 354 + qmult); 359 355 #endif 360 356 if (IS_ERR(the_dev)) { 361 357 ret = PTR_ERR(the_dev); ··· 452 446 } 453 447 454 448 if (gc->eth) { 455 - ret = gc->eth(c, gfs_hostaddr, the_dev); 449 + ret = gc->eth(c, gfs_host_mac, the_dev); 456 450 if (unlikely(ret < 0)) 457 451 return ret; 458 452 }
+2 -2
drivers/usb/gadget/m66592-udc.c
··· 1533 1533 1534 1534 static int __exit m66592_remove(struct platform_device *pdev) 1535 1535 { 1536 - struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); 1536 + struct m66592 *m66592 = platform_get_drvdata(pdev); 1537 1537 1538 1538 usb_del_gadget_udc(&m66592->gadget); 1539 1539 ··· 1602 1602 m66592->irq_trigger = ires->flags & IRQF_TRIGGER_MASK; 1603 1603 1604 1604 spin_lock_init(&m66592->lock); 1605 - dev_set_drvdata(&pdev->dev, m66592); 1605 + platform_set_drvdata(pdev, m66592); 1606 1606 1607 1607 m66592->gadget.ops = &m66592_gadget_ops; 1608 1608 m66592->gadget.max_speed = USB_SPEED_HIGH;
+11 -7
drivers/usb/gadget/multi.c
··· 43 43 */ 44 44 #include "f_mass_storage.c" 45 45 46 + #define USBF_ECM_INCLUDED 46 47 #include "f_ecm.c" 47 - #include "f_subset.c" 48 48 #ifdef USB_ETH_RNDIS 49 + # define USB_FRNDIS_INCLUDED 49 50 # include "f_rndis.c" 50 - # include "rndis.c" 51 + # include "rndis.h" 51 52 #endif 52 - #include "u_ether.c" 53 + #include "u_ether.h" 53 54 54 55 USB_GADGET_COMPOSITE_OPTIONS(); 56 + 57 + USB_ETHERNET_MODULE_PARAMETERS(); 55 58 56 59 /***************************** Device Descriptor ****************************/ 57 60 ··· 136 133 137 134 static struct fsg_common fsg_common; 138 135 139 - static u8 hostaddr[ETH_ALEN]; 136 + static u8 host_mac[ETH_ALEN]; 140 137 141 138 static struct usb_function_instance *fi_acm; 142 139 static struct eth_dev *the_dev; ··· 155 152 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 156 153 } 157 154 158 - ret = rndis_bind_config(c, hostaddr, the_dev); 155 + ret = rndis_bind_config(c, host_mac, the_dev); 159 156 if (ret < 0) 160 157 return ret; 161 158 ··· 219 216 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 220 217 } 221 218 222 - ret = ecm_bind_config(c, hostaddr, the_dev); 219 + ret = ecm_bind_config(c, host_mac, the_dev); 223 220 if (ret < 0) 224 221 return ret; 225 222 ··· 283 280 } 284 281 285 282 /* set up network link layer */ 286 - the_dev = gether_setup(cdev->gadget, hostaddr); 283 + the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac, 284 + qmult); 287 285 if (IS_ERR(the_dev)) 288 286 return PTR_ERR(the_dev); 289 287
+1 -1
drivers/usb/gadget/mv_u3d_core.c
··· 2050 2050 2051 2051 static void mv_u3d_shutdown(struct platform_device *dev) 2052 2052 { 2053 - struct mv_u3d *u3d = dev_get_drvdata(&dev->dev); 2053 + struct mv_u3d *u3d = platform_get_drvdata(dev); 2054 2054 u32 tmp; 2055 2055 2056 2056 tmp = ioread32(&u3d->op_regs->usbcmd);
+37 -21
drivers/usb/gadget/ncm.c
··· 24 24 #include <linux/usb/composite.h> 25 25 26 26 #include "u_ether.h" 27 + #include "u_ncm.h" 27 28 28 29 #define DRIVER_DESC "NCM Gadget" 29 - 30 - /*-------------------------------------------------------------------------*/ 31 - 32 - /* 33 - * Kbuild is not very cooperative with respect to linking separately 34 - * compiled library objects into one module. So for now we won't use 35 - * separate compilation ... ensuring init/exit sections work to shrink 36 - * the runtime footprint, and giving us at least some parts of what 37 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 38 - */ 39 - #include "f_ncm.c" 40 - #include "u_ether.c" 41 30 42 31 /*-------------------------------------------------------------------------*/ 43 32 ··· 42 53 43 54 /*-------------------------------------------------------------------------*/ 44 55 USB_GADGET_COMPOSITE_OPTIONS(); 56 + 57 + USB_ETHERNET_MODULE_PARAMETERS(); 45 58 46 59 static struct usb_device_descriptor device_desc = { 47 60 .bLength = sizeof device_desc, ··· 102 111 NULL, 103 112 }; 104 113 105 - struct eth_dev *the_dev; 106 - static u8 hostaddr[ETH_ALEN]; 114 + static struct usb_function_instance *f_ncm_inst; 115 + static struct usb_function *f_ncm; 107 116 108 117 /*-------------------------------------------------------------------------*/ 109 118 110 119 static int __init ncm_do_config(struct usb_configuration *c) 111 120 { 121 + int status; 122 + 112 123 /* FIXME alloc iConfiguration string, set it in c->strings */ 113 124 114 125 if (gadget_is_otg(c->cdev->gadget)) { ··· 118 125 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 119 126 } 120 127 121 - return ncm_bind_config(c, hostaddr, the_dev); 128 + f_ncm = usb_get_function(f_ncm_inst); 129 + if (IS_ERR(f_ncm)) { 130 + status = PTR_ERR(f_ncm); 131 + return status; 132 + } 133 + 134 + status = usb_add_function(c, f_ncm); 135 + if (status < 0) { 136 + usb_put_function(f_ncm); 137 + return status; 138 + } 139 + 140 + return 0; 122 141 } 123 142 124 143 static struct usb_configuration ncm_config_driver = { ··· 146 141 static int __init gncm_bind(struct usb_composite_dev *cdev) 147 142 { 148 143 struct usb_gadget *gadget = cdev->gadget; 144 + struct f_ncm_opts *ncm_opts; 149 145 int status; 150 146 151 - /* set up network link layer */ 152 - the_dev = gether_setup(cdev->gadget, hostaddr); 153 - if (IS_ERR(the_dev)) 154 - return PTR_ERR(the_dev); 147 + f_ncm_inst = usb_get_function_instance("ncm"); 148 + if (IS_ERR(f_ncm_inst)) 149 + return PTR_ERR(f_ncm_inst); 150 + 151 + ncm_opts = container_of(f_ncm_inst, struct f_ncm_opts, func_inst); 152 + 153 + gether_set_qmult(ncm_opts->net, qmult); 154 + if (!gether_set_host_addr(ncm_opts->net, host_addr)) 155 + pr_info("using host ethernet address: %s", host_addr); 156 + if (!gether_set_dev_addr(ncm_opts->net, dev_addr)) 157 + pr_info("using self ethernet address: %s", dev_addr); 155 158 156 159 /* Allocate string descriptor numbers ... note that string 157 160 * contents can be overridden by the composite_dev glue. ··· 182 169 return 0; 183 170 184 171 fail: 185 - gether_cleanup(the_dev); 172 + usb_put_function_instance(f_ncm_inst); 186 173 return status; 187 174 } 188 175 189 176 static int __exit gncm_unbind(struct usb_composite_dev *cdev) 190 177 { 191 - gether_cleanup(the_dev); 178 + if (!IS_ERR_OR_NULL(f_ncm)) 179 + usb_put_function(f_ncm); 180 + if (!IS_ERR_OR_NULL(f_ncm_inst)) 181 + usb_put_function_instance(f_ncm_inst); 192 182 return 0; 193 183 } 194 184
+157 -76
drivers/usb/gadget/nokia.c
··· 16 16 */ 17 17 18 18 #include <linux/kernel.h> 19 + #include <linux/module.h> 19 20 #include <linux/device.h> 20 21 21 22 #include "u_serial.h" 22 23 #include "u_ether.h" 23 24 #include "u_phonet.h" 25 + #include "u_ecm.h" 24 26 #include "gadget_chips.h" 25 27 26 28 /* Defines */ ··· 30 28 #define NOKIA_VERSION_NUM 0x0211 31 29 #define NOKIA_LONG_NAME "N900 (PC-Suite Mode)" 32 30 33 - /*-------------------------------------------------------------------------*/ 34 - 35 - /* 36 - * Kbuild is not very cooperative with respect to linking separately 37 - * compiled library objects into one module. So for now we won't use 38 - * separate compilation ... ensuring init/exit sections work to shrink 39 - * the runtime footprint, and giving us at least some parts of what 40 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 41 - */ 42 - #define USBF_OBEX_INCLUDED 43 - #include "f_ecm.c" 44 - #include "f_obex.c" 45 - #include "f_phonet.c" 46 - #include "u_ether.c" 47 - 48 - /*-------------------------------------------------------------------------*/ 49 31 USB_GADGET_COMPOSITE_OPTIONS(); 32 + 33 + USB_ETHERNET_MODULE_PARAMETERS(); 50 34 51 35 #define NOKIA_VENDOR_ID 0x0421 /* Nokia */ 52 36 #define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */ ··· 86 98 /*-------------------------------------------------------------------------*/ 87 99 static struct usb_function *f_acm_cfg1; 88 100 static struct usb_function *f_acm_cfg2; 89 - static u8 hostaddr[ETH_ALEN]; 90 - static struct eth_dev *the_dev; 101 + static struct usb_function *f_ecm_cfg1; 102 + static struct usb_function *f_ecm_cfg2; 103 + static struct usb_function *f_obex1_cfg1; 104 + static struct usb_function *f_obex2_cfg1; 105 + static struct usb_function *f_obex1_cfg2; 106 + static struct usb_function *f_obex2_cfg2; 107 + static struct usb_function *f_phonet_cfg1; 108 + static struct usb_function *f_phonet_cfg2; 91 109 92 - enum { 93 - TTY_PORT_OBEX0, 94 - TTY_PORT_OBEX1, 95 - TTY_PORTS_MAX, 96 - }; 97 - 98 - static unsigned char tty_lines[TTY_PORTS_MAX]; 99 110 100 111 static struct usb_configuration nokia_config_500ma_driver = { 101 112 .label = "Bus Powered", ··· 113 126 }; 114 127 115 128 static struct usb_function_instance *fi_acm; 129 + static struct usb_function_instance *fi_ecm; 130 + static struct usb_function_instance *fi_obex1; 131 + static struct usb_function_instance *fi_obex2; 132 + static struct usb_function_instance *fi_phonet; 116 133 117 134 static int __init nokia_bind_config(struct usb_configuration *c) 118 135 { 119 136 struct usb_function *f_acm; 137 + struct usb_function *f_phonet = NULL; 138 + struct usb_function *f_obex1 = NULL; 139 + struct usb_function *f_ecm; 140 + struct usb_function *f_obex2 = NULL; 120 141 int status = 0; 142 + int obex1_stat = 0; 143 + int obex2_stat = 0; 144 + int phonet_stat = 0; 121 145 122 - status = phonet_bind_config(c); 123 - if (status) 124 - printk(KERN_DEBUG "could not bind phonet config\n"); 146 + if (!IS_ERR(fi_phonet)) { 147 + f_phonet = usb_get_function(fi_phonet); 148 + if (IS_ERR(f_phonet)) 149 + pr_debug("could not get phonet function\n"); 150 + } 125 151 126 - status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX0]); 127 - if (status) 128 - printk(KERN_DEBUG "could not bind obex config %d\n", 0); 152 + if (!IS_ERR(fi_obex1)) { 153 + f_obex1 = usb_get_function(fi_obex1); 154 + if (IS_ERR(f_obex1)) 155 + pr_debug("could not get obex function 0\n"); 156 + } 129 157 130 - status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX1]); 131 - if (status) 132 - printk(KERN_DEBUG "could not bind obex config %d\n", 0); 158 + if (!IS_ERR(fi_obex2)) { 159 + f_obex2 = usb_get_function(fi_obex2); 160 + if (IS_ERR(f_obex2)) 161 + pr_debug("could not get obex function 1\n"); 162 + } 133 163 134 164 f_acm = usb_get_function(fi_acm); 135 - if (IS_ERR(f_acm)) 136 - return PTR_ERR(f_acm); 165 + if (IS_ERR(f_acm)) { 166 + status = PTR_ERR(f_acm); 167 + goto err_get_acm; 168 + } 169 + 170 + f_ecm = usb_get_function(fi_ecm); 171 + if (IS_ERR(f_ecm)) { 172 + status = PTR_ERR(f_ecm); 173 + goto err_get_ecm; 174 + } 175 + 176 + if (!IS_ERR_OR_NULL(f_phonet)) { 177 + phonet_stat = usb_add_function(c, f_phonet); 178 + if (phonet_stat) 179 + pr_debug("could not add phonet function\n"); 180 + } 181 + 182 + if (!IS_ERR_OR_NULL(f_obex1)) { 183 + obex1_stat = usb_add_function(c, f_obex1); 184 + if (obex1_stat) 185 + pr_debug("could not add obex function 0\n"); 186 + } 187 + 188 + if (!IS_ERR_OR_NULL(f_obex2)) { 189 + obex2_stat = usb_add_function(c, f_obex2); 190 + if (obex2_stat) 191 + pr_debug("could not add obex function 1\n"); 192 + } 137 193 138 194 status = usb_add_function(c, f_acm); 139 195 if (status) 140 196 goto err_conf; 141 197 142 - status = ecm_bind_config(c, hostaddr, the_dev); 198 + status = usb_add_function(c, f_ecm); 143 199 if (status) { 144 200 pr_debug("could not bind ecm config %d\n", status); 145 201 goto err_ecm; 146 202 } 147 - if (c == &nokia_config_500ma_driver) 203 + if (c == &nokia_config_500ma_driver) { 148 204 f_acm_cfg1 = f_acm; 149 - else 205 + f_ecm_cfg1 = f_ecm; 206 + f_phonet_cfg1 = f_phonet; 207 + f_obex1_cfg1 = f_obex1; 208 + f_obex2_cfg1 = f_obex2; 209 + } else { 150 210 f_acm_cfg2 = f_acm; 211 + f_ecm_cfg2 = f_ecm; 212 + f_phonet_cfg2 = f_phonet; 213 + f_obex1_cfg2 = f_obex1; 214 + f_obex2_cfg2 = f_obex2; 215 + } 151 216 152 217 return status; 153 218 err_ecm: 154 219 usb_remove_function(c, f_acm); 155 220 err_conf: 221 + if (!obex2_stat) 222 + usb_remove_function(c, f_obex2); 223 + if (!obex1_stat) 224 + usb_remove_function(c, f_obex1); 225 + if (!phonet_stat) 226 + usb_remove_function(c, f_phonet); 227 + usb_put_function(f_ecm); 228 + err_get_ecm: 156 229 usb_put_function(f_acm); 230 + err_get_acm: 231 + if (!IS_ERR_OR_NULL(f_obex2)) 232 + usb_put_function(f_obex2); 233 + if (!IS_ERR_OR_NULL(f_obex1)) 234 + usb_put_function(f_obex1); 235 + if (!IS_ERR_OR_NULL(f_phonet)) 236 + usb_put_function(f_phonet); 157 237 return status; 158 238 } 159 239 ··· 228 174 { 229 175 struct usb_gadget *gadget = cdev->gadget; 230 176 int status; 231 - int cur_line; 232 - 233 - status = gphonet_setup(cdev->gadget); 234 - if (status < 0) 235 - goto err_phonet; 236 - 237 - for (cur_line = 0; cur_line < TTY_PORTS_MAX; cur_line++) { 238 - status = gserial_alloc_line(&tty_lines[cur_line]); 239 - if (status) 240 - goto err_ether; 241 - } 242 - 243 - the_dev = gether_setup(cdev->gadget, hostaddr); 244 - if (IS_ERR(the_dev)) { 245 - status = PTR_ERR(the_dev); 246 - goto err_ether; 247 - } 248 177 249 178 status = usb_string_ids_tab(cdev, strings_dev); 250 179 if (status < 0) ··· 238 201 nokia_config_500ma_driver.iConfiguration = status; 239 202 nokia_config_100ma_driver.iConfiguration = status; 240 203 241 - if (!gadget_supports_altsettings(gadget)) 204 + if (!gadget_supports_altsettings(gadget)) { 205 + status = -ENODEV; 242 206 goto err_usb; 207 + } 208 + 209 + fi_phonet = usb_get_function_instance("phonet"); 210 + if (IS_ERR(fi_phonet)) 211 + pr_debug("could not find phonet function\n"); 212 + 213 + fi_obex1 = usb_get_function_instance("obex"); 214 + if (IS_ERR(fi_obex1)) 215 + pr_debug("could not find obex function 1\n"); 216 + 217 + fi_obex2 = usb_get_function_instance("obex"); 218 + if (IS_ERR(fi_obex2)) 219 + pr_debug("could not find obex function 2\n"); 243 220 244 221 fi_acm = usb_get_function_instance("acm"); 245 - if (IS_ERR(fi_acm)) 246 - goto err_usb; 222 + if (IS_ERR(fi_acm)) { 223 + status = PTR_ERR(fi_acm); 224 + goto err_obex2_inst; 225 + } 226 + 227 + fi_ecm = usb_get_function_instance("ecm"); 228 + if (IS_ERR(fi_ecm)) { 229 + status = PTR_ERR(fi_ecm); 230 + goto err_acm_inst; 231 + } 247 232 248 233 /* finally register the configuration */ 249 234 status = usb_add_config(cdev, &nokia_config_500ma_driver, 250 235 nokia_bind_config); 251 236 if (status < 0) 252 - goto err_acm_inst; 237 + goto err_ecm_inst; 253 238 254 239 status = usb_add_config(cdev, &nokia_config_100ma_driver, 255 240 nokia_bind_config); ··· 285 226 286 227 err_put_cfg1: 287 228 usb_put_function(f_acm_cfg1); 229 + if (!IS_ERR_OR_NULL(f_obex1_cfg1)) 230 + usb_put_function(f_obex1_cfg1); 231 + if (!IS_ERR_OR_NULL(f_obex2_cfg1)) 232 + usb_put_function(f_obex2_cfg1); 233 + if (!IS_ERR_OR_NULL(f_phonet_cfg1)) 234 + usb_put_function(f_phonet_cfg1); 235 + usb_put_function(f_ecm_cfg1); 236 + err_ecm_inst: 237 + usb_put_function_instance(fi_ecm); 288 238 err_acm_inst: 289 239 usb_put_function_instance(fi_acm); 240 + err_obex2_inst: 241 + if (!IS_ERR(fi_obex2)) 242 + usb_put_function_instance(fi_obex2); 243 + if (!IS_ERR(fi_obex1)) 244 + usb_put_function_instance(fi_obex1); 245 + if (!IS_ERR(fi_phonet)) 246 + usb_put_function_instance(fi_phonet); 290 247 err_usb: 291 - gether_cleanup(the_dev); 292 - err_ether: 293 - cur_line--; 294 - while (cur_line >= 0) 295 - gserial_free_line(tty_lines[cur_line--]); 296 - 297 - gphonet_cleanup(); 298 - err_phonet: 299 248 return status; 300 249 } 301 250 302 251 static int __exit nokia_unbind(struct usb_composite_dev *cdev) 303 252 { 304 - int i; 305 - 253 + if (!IS_ERR_OR_NULL(f_obex1_cfg2)) 254 + usb_put_function(f_obex1_cfg2); 255 + if (!IS_ERR_OR_NULL(f_obex2_cfg2)) 256 + usb_put_function(f_obex2_cfg2); 257 + if (!IS_ERR_OR_NULL(f_obex1_cfg1)) 258 + usb_put_function(f_obex1_cfg1); 259 + if (!IS_ERR_OR_NULL(f_obex2_cfg1)) 260 + usb_put_function(f_obex2_cfg1); 261 + if (!IS_ERR_OR_NULL(f_phonet_cfg1)) 262 + usb_put_function(f_phonet_cfg1); 263 + if (!IS_ERR_OR_NULL(f_phonet_cfg2)) 264 + usb_put_function(f_phonet_cfg2); 306 265 usb_put_function(f_acm_cfg1); 307 266 usb_put_function(f_acm_cfg2); 267 + usb_put_function(f_ecm_cfg1); 268 + usb_put_function(f_ecm_cfg2); 269 + 270 + usb_put_function_instance(fi_ecm); 271 + if (!IS_ERR(fi_obex2)) 272 + usb_put_function_instance(fi_obex2); 273 + if (!IS_ERR(fi_obex1)) 274 + usb_put_function_instance(fi_obex1); 275 + if (!IS_ERR(fi_phonet)) 276 + usb_put_function_instance(fi_phonet); 308 277 usb_put_function_instance(fi_acm); 309 - gphonet_cleanup(); 310 - 311 - for (i = 0; i < TTY_PORTS_MAX; i++) 312 - gserial_free_line(tty_lines[i]); 313 - 314 - gether_cleanup(the_dev); 315 278 316 279 return 0; 317 280 }
+4 -4
drivers/usb/gadget/r8a66597-udc.c
··· 1469 1469 u16 savepipe; 1470 1470 u16 mask0; 1471 1471 1472 + spin_lock(&r8a66597->lock); 1473 + 1472 1474 if (r8a66597_is_sudmac(r8a66597)) 1473 1475 r8a66597_sudmac_irq(r8a66597); 1474 - 1475 - spin_lock(&r8a66597->lock); 1476 1476 1477 1477 intsts0 = r8a66597_read(r8a66597, INTSTS0); 1478 1478 intenb0 = r8a66597_read(r8a66597, INTENB0); ··· 1822 1822 1823 1823 static int __exit r8a66597_remove(struct platform_device *pdev) 1824 1824 { 1825 - struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); 1825 + struct r8a66597 *r8a66597 = platform_get_drvdata(pdev); 1826 1826 1827 1827 usb_del_gadget_udc(&r8a66597->gadget); 1828 1828 del_timer_sync(&r8a66597->timer); ··· 1909 1909 } 1910 1910 1911 1911 spin_lock_init(&r8a66597->lock); 1912 - dev_set_drvdata(&pdev->dev, r8a66597); 1912 + platform_set_drvdata(pdev, r8a66597); 1913 1913 r8a66597->pdata = pdev->dev.platform_data; 1914 1914 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; 1915 1915
+18
drivers/usb/gadget/rndis.c
··· 761 761 return rndis_indicate_status_msg(configNr, 762 762 RNDIS_STATUS_MEDIA_CONNECT); 763 763 } 764 + EXPORT_SYMBOL(rndis_signal_connect); 764 765 765 766 int rndis_signal_disconnect(int configNr) 766 767 { ··· 770 769 return rndis_indicate_status_msg(configNr, 771 770 RNDIS_STATUS_MEDIA_DISCONNECT); 772 771 } 772 + EXPORT_SYMBOL(rndis_signal_disconnect); 773 773 774 774 void rndis_uninit(int configNr) 775 775 { ··· 785 783 while ((buf = rndis_get_next_response(configNr, &length))) 786 784 rndis_free_response(configNr, buf); 787 785 } 786 + EXPORT_SYMBOL(rndis_uninit); 788 787 789 788 void rndis_set_host_mac(int configNr, const u8 *addr) 790 789 { 791 790 rndis_per_dev_params[configNr].host_mac = addr; 792 791 } 792 + EXPORT_SYMBOL(rndis_set_host_mac); 793 793 794 794 /* 795 795 * Message Parser ··· 874 870 875 871 return -ENOTSUPP; 876 872 } 873 + EXPORT_SYMBOL(rndis_msg_parser); 877 874 878 875 int rndis_register(void (*resp_avail)(void *v), void *v) 879 876 { ··· 896 891 897 892 return -ENODEV; 898 893 } 894 + EXPORT_SYMBOL(rndis_register); 899 895 900 896 void rndis_deregister(int configNr) 901 897 { ··· 905 899 if (configNr >= RNDIS_MAX_CONFIGS) return; 906 900 rndis_per_dev_params[configNr].used = 0; 907 901 } 902 + EXPORT_SYMBOL(rndis_deregister); 908 903 909 904 int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) 910 905 { ··· 919 912 920 913 return 0; 921 914 } 915 + EXPORT_SYMBOL(rndis_set_param_dev); 922 916 923 917 int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr) 924 918 { ··· 932 924 933 925 return 0; 934 926 } 927 + EXPORT_SYMBOL(rndis_set_param_vendor); 935 928 936 929 int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed) 937 930 { ··· 944 935 945 936 return 0; 946 937 } 938 + EXPORT_SYMBOL(rndis_set_param_medium); 947 939 948 940 void rndis_add_hdr(struct sk_buff *skb) 949 941 { ··· 959 949 header->DataOffset = cpu_to_le32(36); 960 950 header->DataLength = cpu_to_le32(skb->len - sizeof(*header)); 961 951 } 952 + EXPORT_SYMBOL(rndis_add_hdr); 962 953 963 954 void rndis_free_response(int configNr, u8 *buf) 964 955 { ··· 976 965 } 977 966 } 978 967 } 968 + EXPORT_SYMBOL(rndis_free_response); 979 969 980 970 u8 *rndis_get_next_response(int configNr, u32 *length) 981 971 { ··· 998 986 999 987 return NULL; 1000 988 } 989 + EXPORT_SYMBOL(rndis_get_next_response); 1001 990 1002 991 static rndis_resp_t *rndis_add_response(int configNr, u32 length) 1003 992 { ··· 1042 1029 skb_queue_tail(list, skb); 1043 1030 return 0; 1044 1031 } 1032 + EXPORT_SYMBOL(rndis_rm_hdr); 1045 1033 1046 1034 #ifdef CONFIG_USB_GADGET_DEBUG_FILES 1047 1035 ··· 1174 1160 1175 1161 return 0; 1176 1162 } 1163 + module_init(rndis_init); 1177 1164 1178 1165 void rndis_exit(void) 1179 1166 { ··· 1188 1173 } 1189 1174 #endif 1190 1175 } 1176 + module_exit(rndis_exit); 1177 + 1178 + MODULE_LICENSE("GPL");
+1 -3
drivers/usb/gadget/rndis.h
··· 16 16 #define _LINUX_RNDIS_H 17 17 18 18 #include <linux/rndis.h> 19 + #include "u_ether.h" 19 20 #include "ndis.h" 20 21 21 22 #define RNDIS_MAXIMUM_FRAME_SIZE 1518 ··· 216 215 int rndis_signal_disconnect (int configNr); 217 216 int rndis_state (int configNr); 218 217 extern void rndis_set_host_mac (int configNr, const u8 *addr); 219 - 220 - int rndis_init(void); 221 - void rndis_exit (void); 222 218 223 219 #endif /* _LINUX_RNDIS_H */
+36
drivers/usb/gadget/u_ecm.h
··· 1 + /* 2 + * u_ecm.h 3 + * 4 + * Utility definitions for the ecm function 5 + * 6 + * Copyright (c) 2013 Samsung Electronics Co., Ltd. 7 + * http://www.samsung.com 8 + * 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef U_ECM_H 17 + #define U_ECM_H 18 + 19 + #include <linux/usb/composite.h> 20 + 21 + struct f_ecm_opts { 22 + struct usb_function_instance func_inst; 23 + struct net_device *net; 24 + bool bound; 25 + 26 + /* 27 + * Read/write access to configfs attributes is handled by configfs. 28 + * 29 + * This is to protect the data from concurrent access by read/write 30 + * and create symlink/remove symlink. 31 + */ 32 + struct mutex lock; 33 + int refcnt; 34 + }; 35 + 36 + #endif /* U_ECM_H */
+36
drivers/usb/gadget/u_eem.h
··· 1 + /* 2 + * u_eem.h 3 + * 4 + * Utility definitions for the eem function 5 + * 6 + * Copyright (c) 2013 Samsung Electronics Co., Ltd. 7 + * http://www.samsung.com 8 + * 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef U_EEM_H 17 + #define U_EEM_H 18 + 19 + #include <linux/usb/composite.h> 20 + 21 + struct f_eem_opts { 22 + struct usb_function_instance func_inst; 23 + struct net_device *net; 24 + bool bound; 25 + 26 + /* 27 + * Read/write access to configfs attributes is handled by configfs. 28 + * 29 + * This is to protect the data from concurrent access by read/write 30 + * and create symlink/remove symlink. 31 + */ 32 + struct mutex lock; 33 + int refcnt; 34 + }; 35 + 36 + #endif /* U_EEM_H */
+211 -21
drivers/usb/gadget/u_ether.c
··· 63 63 64 64 struct sk_buff_head rx_frames; 65 65 66 + unsigned qmult; 67 + 66 68 unsigned header_len; 67 69 struct sk_buff *(*wrap)(struct gether *, struct sk_buff *skb); 68 70 int (*unwrap)(struct gether *, ··· 78 76 79 77 bool zlp; 80 78 u8 host_mac[ETH_ALEN]; 79 + u8 dev_mac[ETH_ALEN]; 81 80 }; 82 81 83 82 /*-------------------------------------------------------------------------*/ ··· 87 84 88 85 #define DEFAULT_QLEN 2 /* double buffering by default */ 89 86 90 - static unsigned qmult = 5; 91 - module_param(qmult, uint, S_IRUGO|S_IWUSR); 92 - MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed"); 93 - 94 87 /* for dual-speed hardware, use deeper queues at high/super speed */ 95 - static inline int qlen(struct usb_gadget *gadget) 88 + static inline int qlen(struct usb_gadget *gadget, unsigned qmult) 96 89 { 97 90 if (gadget_is_dualspeed(gadget) && (gadget->speed == USB_SPEED_HIGH || 98 91 gadget->speed == USB_SPEED_SUPER)) ··· 587 588 if (gadget_is_dualspeed(dev->gadget)) 588 589 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH || 589 590 dev->gadget->speed == USB_SPEED_SUPER) 590 - ? ((atomic_read(&dev->tx_qlen) % qmult) != 0) 591 + ? ((atomic_read(&dev->tx_qlen) % dev->qmult) != 0) 591 592 : 0; 592 593 593 594 retval = usb_ep_queue(in, req, GFP_ATOMIC); ··· 696 697 697 698 /*-------------------------------------------------------------------------*/ 698 699 699 - /* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */ 700 - static char *dev_addr; 701 - module_param(dev_addr, charp, S_IRUGO); 702 - MODULE_PARM_DESC(dev_addr, "Device Ethernet Address"); 703 - 704 - /* this address is invisible to ifconfig */ 705 - static char *host_addr; 706 - module_param(host_addr, charp, S_IRUGO); 707 - MODULE_PARM_DESC(host_addr, "Host Ethernet Address"); 708 - 709 700 static int get_ether_addr(const char *str, u8 *dev_addr) 710 701 { 711 702 if (str) { ··· 715 726 } 716 727 eth_random_addr(dev_addr); 717 728 return 1; 729 + } 730 + 731 + static int get_ether_addr_str(u8 dev_addr[ETH_ALEN], char *str, int len) 732 + { 733 + if (len < 18) 734 + return -EINVAL; 735 + 736 + snprintf(str, len, "%02x:%02x:%02x:%02x:%02x:%02x", 737 + dev_addr[0], dev_addr[1], dev_addr[2], 738 + dev_addr[3], dev_addr[4], dev_addr[5]); 739 + return 18; 718 740 } 719 741 720 742 static const struct net_device_ops eth_netdev_ops = { ··· 755 755 * 756 756 * Returns negative errno, or zero on success 757 757 */ 758 - struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], 759 - const char *netname) 758 + struct eth_dev *gether_setup_name(struct usb_gadget *g, 759 + const char *dev_addr, const char *host_addr, 760 + u8 ethaddr[ETH_ALEN], unsigned qmult, const char *netname) 760 761 { 761 762 struct eth_dev *dev; 762 763 struct net_device *net; ··· 778 777 779 778 /* network device setup */ 780 779 dev->net = net; 780 + dev->qmult = qmult; 781 781 snprintf(net->name, sizeof(net->name), "%s%%d", netname); 782 782 783 783 if (get_ether_addr(dev_addr, net->dev_addr)) ··· 808 806 INFO(dev, "MAC %pM\n", net->dev_addr); 809 807 INFO(dev, "HOST MAC %pM\n", dev->host_mac); 810 808 811 - /* two kinds of host-initiated state changes: 809 + /* 810 + * two kinds of host-initiated state changes: 812 811 * - iff DATA transfer is active, carrier is "on" 813 812 * - tx queueing enabled if open *and* carrier is "on" 814 813 */ ··· 818 815 819 816 return dev; 820 817 } 818 + EXPORT_SYMBOL(gether_setup_name); 819 + 820 + struct net_device *gether_setup_name_default(const char *netname) 821 + { 822 + struct net_device *net; 823 + struct eth_dev *dev; 824 + 825 + net = alloc_etherdev(sizeof(*dev)); 826 + if (!net) 827 + return ERR_PTR(-ENOMEM); 828 + 829 + dev = netdev_priv(net); 830 + spin_lock_init(&dev->lock); 831 + spin_lock_init(&dev->req_lock); 832 + INIT_WORK(&dev->work, eth_work); 833 + INIT_LIST_HEAD(&dev->tx_reqs); 834 + INIT_LIST_HEAD(&dev->rx_reqs); 835 + 836 + skb_queue_head_init(&dev->rx_frames); 837 + 838 + /* network device setup */ 839 + dev->net = net; 840 + dev->qmult = QMULT_DEFAULT; 841 + snprintf(net->name, sizeof(net->name), "%s%%d", netname); 842 + 843 + eth_random_addr(dev->dev_mac); 844 + pr_warn("using random %s ethernet address\n", "self"); 845 + eth_random_addr(dev->host_mac); 846 + pr_warn("using random %s ethernet address\n", "host"); 847 + 848 + net->netdev_ops = &eth_netdev_ops; 849 + 850 + SET_ETHTOOL_OPS(net, &ops); 851 + SET_NETDEV_DEVTYPE(net, &gadget_type); 852 + 853 + return net; 854 + } 855 + EXPORT_SYMBOL(gether_setup_name_default); 856 + 857 + int gether_register_netdev(struct net_device *net) 858 + { 859 + struct eth_dev *dev; 860 + struct usb_gadget *g; 861 + struct sockaddr sa; 862 + int status; 863 + 864 + if (!net->dev.parent) 865 + return -EINVAL; 866 + dev = netdev_priv(net); 867 + g = dev->gadget; 868 + status = register_netdev(net); 869 + if (status < 0) { 870 + dev_dbg(&g->dev, "register_netdev failed, %d\n", status); 871 + return status; 872 + } else { 873 + INFO(dev, "HOST MAC %pM\n", dev->host_mac); 874 + 875 + /* two kinds of host-initiated state changes: 876 + * - iff DATA transfer is active, carrier is "on" 877 + * - tx queueing enabled if open *and* carrier is "on" 878 + */ 879 + netif_carrier_off(net); 880 + } 881 + sa.sa_family = net->type; 882 + memcpy(sa.sa_data, dev->dev_mac, ETH_ALEN); 883 + rtnl_lock(); 884 + status = dev_set_mac_address(net, &sa); 885 + rtnl_unlock(); 886 + if (status) 887 + pr_warn("cannot set self ethernet address: %d\n", status); 888 + else 889 + INFO(dev, "MAC %pM\n", dev->dev_mac); 890 + 891 + return status; 892 + } 893 + EXPORT_SYMBOL(gether_register_netdev); 894 + 895 + void gether_set_gadget(struct net_device *net, struct usb_gadget *g) 896 + { 897 + struct eth_dev *dev; 898 + 899 + dev = netdev_priv(net); 900 + dev->gadget = g; 901 + SET_NETDEV_DEV(net, &g->dev); 902 + } 903 + EXPORT_SYMBOL(gether_set_gadget); 904 + 905 + int gether_set_dev_addr(struct net_device *net, const char *dev_addr) 906 + { 907 + struct eth_dev *dev; 908 + u8 new_addr[ETH_ALEN]; 909 + 910 + dev = netdev_priv(net); 911 + if (get_ether_addr(dev_addr, new_addr)) 912 + return -EINVAL; 913 + memcpy(dev->dev_mac, new_addr, ETH_ALEN); 914 + return 0; 915 + } 916 + EXPORT_SYMBOL(gether_set_dev_addr); 917 + 918 + int gether_get_dev_addr(struct net_device *net, char *dev_addr, int len) 919 + { 920 + struct eth_dev *dev; 921 + 922 + dev = netdev_priv(net); 923 + return get_ether_addr_str(dev->dev_mac, dev_addr, len); 924 + } 925 + EXPORT_SYMBOL(gether_get_dev_addr); 926 + 927 + int gether_set_host_addr(struct net_device *net, const char *host_addr) 928 + { 929 + struct eth_dev *dev; 930 + u8 new_addr[ETH_ALEN]; 931 + 932 + dev = netdev_priv(net); 933 + if (get_ether_addr(host_addr, new_addr)) 934 + return -EINVAL; 935 + memcpy(dev->host_mac, new_addr, ETH_ALEN); 936 + return 0; 937 + } 938 + EXPORT_SYMBOL(gether_set_host_addr); 939 + 940 + int gether_get_host_addr(struct net_device *net, char *host_addr, int len) 941 + { 942 + struct eth_dev *dev; 943 + 944 + dev = netdev_priv(net); 945 + return get_ether_addr_str(dev->host_mac, host_addr, len); 946 + } 947 + EXPORT_SYMBOL(gether_get_host_addr); 948 + 949 + int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len) 950 + { 951 + struct eth_dev *dev; 952 + 953 + if (len < 13) 954 + return -EINVAL; 955 + 956 + dev = netdev_priv(net); 957 + snprintf(host_addr, len, "%pm", dev->host_mac); 958 + 959 + return strlen(host_addr); 960 + } 961 + EXPORT_SYMBOL(gether_get_host_addr_cdc); 962 + 963 + void gether_get_host_addr_u8(struct net_device *net, u8 host_mac[ETH_ALEN]) 964 + { 965 + struct eth_dev *dev; 966 + 967 + dev = netdev_priv(net); 968 + memcpy(host_mac, dev->host_mac, ETH_ALEN); 969 + } 970 + EXPORT_SYMBOL(gether_get_host_addr_u8); 971 + 972 + void gether_set_qmult(struct net_device *net, unsigned qmult) 973 + { 974 + struct eth_dev *dev; 975 + 976 + dev = netdev_priv(net); 977 + dev->qmult = qmult; 978 + } 979 + EXPORT_SYMBOL(gether_set_qmult); 980 + 981 + unsigned gether_get_qmult(struct net_device *net) 982 + { 983 + struct eth_dev *dev; 984 + 985 + dev = netdev_priv(net); 986 + return dev->qmult; 987 + } 988 + EXPORT_SYMBOL(gether_get_qmult); 989 + 990 + int gether_get_ifname(struct net_device *net, char *name, int len) 991 + { 992 + rtnl_lock(); 993 + strlcpy(name, netdev_name(net), len); 994 + rtnl_unlock(); 995 + return strlen(name); 996 + } 997 + EXPORT_SYMBOL(gether_get_ifname); 821 998 822 999 /** 823 1000 * gether_cleanup - remove Ethernet-over-USB device ··· 1014 831 flush_work(&dev->work); 1015 832 free_netdev(dev->net); 1016 833 } 834 + EXPORT_SYMBOL(gether_cleanup); 1017 835 1018 836 /** 1019 837 * gether_connect - notify network layer that USB link is active ··· 1057 873 } 1058 874 1059 875 if (result == 0) 1060 - result = alloc_requests(dev, link, qlen(dev->gadget)); 876 + result = alloc_requests(dev, link, qlen(dev->gadget, 877 + dev->qmult)); 1061 878 1062 879 if (result == 0) { 1063 880 dev->zlp = link->is_zlp_ok; 1064 - DBG(dev, "qlen %d\n", qlen(dev->gadget)); 881 + DBG(dev, "qlen %d\n", qlen(dev->gadget, dev->qmult)); 1065 882 1066 883 dev->header_len = link->header_len; 1067 884 dev->unwrap = link->unwrap; ··· 1095 910 return ERR_PTR(result); 1096 911 return dev->net; 1097 912 } 913 + EXPORT_SYMBOL(gether_connect); 1098 914 1099 915 /** 1100 916 * gether_disconnect - notify network layer that USB link is inactive ··· 1166 980 dev->port_usb = NULL; 1167 981 spin_unlock(&dev->lock); 1168 982 } 983 + EXPORT_SYMBOL(gether_disconnect); 984 + 985 + MODULE_LICENSE("GPL"); 986 + MODULE_AUTHOR("David Brownell");
+159 -7
drivers/usb/gadget/u_ether.h
··· 21 21 22 22 #include "gadget_chips.h" 23 23 24 + #define QMULT_DEFAULT 5 25 + 26 + /* 27 + * dev_addr: initial value 28 + * changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" 29 + * host_addr: this address is invisible to ifconfig 30 + */ 31 + #define USB_ETHERNET_MODULE_PARAMETERS() \ 32 + static unsigned qmult = QMULT_DEFAULT; \ 33 + module_param(qmult, uint, S_IRUGO|S_IWUSR); \ 34 + MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");\ 35 + \ 36 + static char *dev_addr; \ 37 + module_param(dev_addr, charp, S_IRUGO); \ 38 + MODULE_PARM_DESC(dev_addr, "Device Ethernet Address"); \ 39 + \ 40 + static char *host_addr; \ 41 + module_param(host_addr, charp, S_IRUGO); \ 42 + MODULE_PARM_DESC(host_addr, "Host Ethernet Address") 43 + 24 44 struct eth_dev; 25 45 26 46 /* ··· 91 71 |USB_CDC_PACKET_TYPE_DIRECTED) 92 72 93 73 /* variant of gether_setup that allows customizing network device name */ 94 - struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], 95 - const char *netname); 74 + struct eth_dev *gether_setup_name(struct usb_gadget *g, 75 + const char *dev_addr, const char *host_addr, 76 + u8 ethaddr[ETH_ALEN], unsigned qmult, const char *netname); 96 77 97 78 /* netdev setup/teardown as directed by the gadget driver */ 98 79 /* gether_setup - initialize one ethernet-over-usb link ··· 109 88 * Returns negative errno, or zero on success 110 89 */ 111 90 static inline struct eth_dev *gether_setup(struct usb_gadget *g, 112 - u8 ethaddr[ETH_ALEN]) 91 + const char *dev_addr, const char *host_addr, 92 + u8 ethaddr[ETH_ALEN], unsigned qmult) 113 93 { 114 - return gether_setup_name(g, ethaddr, "usb"); 94 + return gether_setup_name(g, dev_addr, host_addr, ethaddr, qmult, "usb"); 115 95 } 96 + 97 + /* 98 + * variant of gether_setup_default that allows customizing 99 + * network device name 100 + */ 101 + struct net_device *gether_setup_name_default(const char *netname); 102 + 103 + /* 104 + * gether_register_netdev - register the net device 105 + * @net: net device to register 106 + * 107 + * Registers the net device associated with this ethernet-over-usb link 108 + * 109 + */ 110 + int gether_register_netdev(struct net_device *net); 111 + 112 + /* gether_setup_default - initialize one ethernet-over-usb link 113 + * Context: may sleep 114 + * 115 + * This sets up the single network link that may be exported by a 116 + * gadget driver using this framework. The link layer addresses 117 + * are set to random values. 118 + * 119 + * Returns negative errno, or zero on success 120 + */ 121 + static inline struct net_device *gether_setup_default(void) 122 + { 123 + return gether_setup_name_default("usb"); 124 + } 125 + 126 + /** 127 + * gether_set_gadget - initialize one ethernet-over-usb link with a gadget 128 + * @net: device representing this link 129 + * @g: the gadget to initialize with 130 + * 131 + * This associates one ethernet-over-usb link with a gadget. 132 + */ 133 + void gether_set_gadget(struct net_device *net, struct usb_gadget *g); 134 + 135 + /** 136 + * gether_set_dev_addr - initialize an ethernet-over-usb link with eth address 137 + * @net: device representing this link 138 + * @dev_addr: eth address of this device 139 + * 140 + * This sets the device-side Ethernet address of this ethernet-over-usb link 141 + * if dev_addr is correct. 142 + * Returns negative errno if the new address is incorrect. 143 + */ 144 + int gether_set_dev_addr(struct net_device *net, const char *dev_addr); 145 + 146 + /** 147 + * gether_get_dev_addr - get an ethernet-over-usb link eth address 148 + * @net: device representing this link 149 + * @dev_addr: place to store device's eth address 150 + * @len: length of the @dev_addr buffer 151 + * 152 + * This gets the device-side Ethernet address of this ethernet-over-usb link. 153 + * Returns zero on success, else negative errno. 154 + */ 155 + int gether_get_dev_addr(struct net_device *net, char *dev_addr, int len); 156 + 157 + /** 158 + * gether_set_host_addr - initialize an ethernet-over-usb link with host address 159 + * @net: device representing this link 160 + * @host_addr: eth address of the host 161 + * 162 + * This sets the host-side Ethernet address of this ethernet-over-usb link 163 + * if host_addr is correct. 164 + * Returns negative errno if the new address is incorrect. 165 + */ 166 + int gether_set_host_addr(struct net_device *net, const char *host_addr); 167 + 168 + /** 169 + * gether_get_host_addr - get an ethernet-over-usb link host address 170 + * @net: device representing this link 171 + * @host_addr: place to store eth address of the host 172 + * @len: length of the @host_addr buffer 173 + * 174 + * This gets the host-side Ethernet address of this ethernet-over-usb link. 175 + * Returns zero on success, else negative errno. 176 + */ 177 + int gether_get_host_addr(struct net_device *net, char *host_addr, int len); 178 + 179 + /** 180 + * gether_get_host_addr_cdc - get an ethernet-over-usb link host address 181 + * @net: device representing this link 182 + * @host_addr: place to store eth address of the host 183 + * @len: length of the @host_addr buffer 184 + * 185 + * This gets the CDC formatted host-side Ethernet address of this 186 + * ethernet-over-usb link. 187 + * Returns zero on success, else negative errno. 188 + */ 189 + int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len); 190 + 191 + /** 192 + * gether_get_host_addr_u8 - get an ethernet-over-usb link host address 193 + * @net: device representing this link 194 + * @host_mac: place to store the eth address of the host 195 + * 196 + * This gets the binary formatted host-side Ethernet address of this 197 + * ethernet-over-usb link. 198 + */ 199 + void gether_get_host_addr_u8(struct net_device *net, u8 host_mac[ETH_ALEN]); 200 + 201 + /** 202 + * gether_set_qmult - initialize an ethernet-over-usb link with a multiplier 203 + * @net: device representing this link 204 + * @qmult: queue multiplier 205 + * 206 + * This sets the queue length multiplier of this ethernet-over-usb link. 207 + * For higher speeds use longer queues. 208 + */ 209 + void gether_set_qmult(struct net_device *net, unsigned qmult); 210 + 211 + /** 212 + * gether_get_qmult - get an ethernet-over-usb link multiplier 213 + * @net: device representing this link 214 + * 215 + * This gets the queue length multiplier of this ethernet-over-usb link. 216 + */ 217 + unsigned gether_get_qmult(struct net_device *net); 218 + 219 + /** 220 + * gether_get_ifname - get an ethernet-over-usb link interface name 221 + * @net: device representing this link 222 + * @name: place to store the interface name 223 + * @len: length of the @name buffer 224 + * 225 + * This gets the interface name of this ethernet-over-usb link. 226 + * Returns zero on success, else negative errno. 227 + */ 228 + int gether_get_ifname(struct net_device *net, char *name, int len); 116 229 117 230 void gether_cleanup(struct eth_dev *dev); 118 231 ··· 272 117 struct eth_dev *dev); 273 118 int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 274 119 struct eth_dev *dev); 275 - int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 276 - struct eth_dev *dev); 277 - int eem_bind_config(struct usb_configuration *c, struct eth_dev *dev); 278 120 279 121 #ifdef USB_ETH_RNDIS 280 122
+164
drivers/usb/gadget/u_ether_configfs.h
··· 1 + /* 2 + * u_ether_configfs.h 3 + * 4 + * Utility definitions for configfs support in USB Ethernet functions 5 + * 6 + * Copyright (c) 2013 Samsung Electronics Co., Ltd. 7 + * http://www.samsung.com 8 + * 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef __U_ETHER_CONFIGFS_H 17 + #define __U_ETHER_CONFIGFS_H 18 + 19 + #define USB_ETHERNET_CONFIGFS_ITEM(_f_) \ 20 + CONFIGFS_ATTR_STRUCT(f_##_f_##_opts); \ 21 + CONFIGFS_ATTR_OPS(f_##_f_##_opts); \ 22 + \ 23 + static void _f_##_attr_release(struct config_item *item) \ 24 + { \ 25 + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 26 + \ 27 + usb_put_function_instance(&opts->func_inst); \ 28 + } \ 29 + \ 30 + static struct configfs_item_operations _f_##_item_ops = { \ 31 + .release = _f_##_attr_release, \ 32 + .show_attribute = f_##_f_##_opts_attr_show, \ 33 + .store_attribute = f_##_f_##_opts_attr_store, \ 34 + } 35 + 36 + #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(_f_) \ 37 + static ssize_t _f_##_opts_dev_addr_show(struct f_##_f_##_opts *opts, \ 38 + char *page) \ 39 + { \ 40 + int result; \ 41 + \ 42 + mutex_lock(&opts->lock); \ 43 + result = gether_get_dev_addr(opts->net, page, PAGE_SIZE); \ 44 + mutex_unlock(&opts->lock); \ 45 + \ 46 + return result; \ 47 + } \ 48 + \ 49 + static ssize_t _f_##_opts_dev_addr_store(struct f_##_f_##_opts *opts, \ 50 + const char *page, size_t len)\ 51 + { \ 52 + int ret; \ 53 + \ 54 + mutex_lock(&opts->lock); \ 55 + if (opts->refcnt) { \ 56 + mutex_unlock(&opts->lock); \ 57 + return -EBUSY; \ 58 + } \ 59 + \ 60 + ret = gether_set_dev_addr(opts->net, page); \ 61 + mutex_unlock(&opts->lock); \ 62 + if (!ret) \ 63 + ret = len; \ 64 + return ret; \ 65 + } \ 66 + \ 67 + static struct f_##_f_##_opts_attribute f_##_f_##_opts_dev_addr = \ 68 + __CONFIGFS_ATTR(dev_addr, S_IRUGO | S_IWUSR, \ 69 + _f_##_opts_dev_addr_show, \ 70 + _f_##_opts_dev_addr_store) 71 + 72 + #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(_f_) \ 73 + static ssize_t _f_##_opts_host_addr_show(struct f_##_f_##_opts *opts, \ 74 + char *page) \ 75 + { \ 76 + int result; \ 77 + \ 78 + mutex_lock(&opts->lock); \ 79 + result = gether_get_host_addr(opts->net, page, PAGE_SIZE); \ 80 + mutex_unlock(&opts->lock); \ 81 + \ 82 + return result; \ 83 + } \ 84 + \ 85 + static ssize_t _f_##_opts_host_addr_store(struct f_##_f_##_opts *opts, \ 86 + const char *page, size_t len)\ 87 + { \ 88 + int ret; \ 89 + \ 90 + mutex_lock(&opts->lock); \ 91 + if (opts->refcnt) { \ 92 + mutex_unlock(&opts->lock); \ 93 + return -EBUSY; \ 94 + } \ 95 + \ 96 + ret = gether_set_host_addr(opts->net, page); \ 97 + mutex_unlock(&opts->lock); \ 98 + if (!ret) \ 99 + ret = len; \ 100 + return ret; \ 101 + } \ 102 + \ 103 + static struct f_##_f_##_opts_attribute f_##_f_##_opts_host_addr = \ 104 + __CONFIGFS_ATTR(host_addr, S_IRUGO | S_IWUSR, \ 105 + _f_##_opts_host_addr_show, \ 106 + _f_##_opts_host_addr_store) 107 + 108 + #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(_f_) \ 109 + static ssize_t _f_##_opts_qmult_show(struct f_##_f_##_opts *opts, \ 110 + char *page) \ 111 + { \ 112 + unsigned qmult; \ 113 + \ 114 + mutex_lock(&opts->lock); \ 115 + qmult = gether_get_qmult(opts->net); \ 116 + mutex_unlock(&opts->lock); \ 117 + return sprintf(page, "%d", qmult); \ 118 + } \ 119 + \ 120 + static ssize_t _f_##_opts_qmult_store(struct f_##_f_##_opts *opts, \ 121 + const char *page, size_t len)\ 122 + { \ 123 + u8 val; \ 124 + int ret; \ 125 + \ 126 + mutex_lock(&opts->lock); \ 127 + if (opts->refcnt) { \ 128 + ret = -EBUSY; \ 129 + goto out; \ 130 + } \ 131 + \ 132 + ret = kstrtou8(page, 0, &val); \ 133 + if (ret) \ 134 + goto out; \ 135 + \ 136 + gether_set_qmult(opts->net, val); \ 137 + ret = len; \ 138 + out: \ 139 + mutex_unlock(&opts->lock); \ 140 + return ret; \ 141 + } \ 142 + \ 143 + static struct f_##_f_##_opts_attribute f_##_f_##_opts_qmult = \ 144 + __CONFIGFS_ATTR(qmult, S_IRUGO | S_IWUSR, \ 145 + _f_##_opts_qmult_show, \ 146 + _f_##_opts_qmult_store) 147 + 148 + #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(_f_) \ 149 + static ssize_t _f_##_opts_ifname_show(struct f_##_f_##_opts *opts, \ 150 + char *page) \ 151 + { \ 152 + int ret; \ 153 + \ 154 + mutex_lock(&opts->lock); \ 155 + ret = gether_get_ifname(opts->net, page, PAGE_SIZE); \ 156 + mutex_unlock(&opts->lock); \ 157 + \ 158 + return ret; \ 159 + } \ 160 + \ 161 + static struct f_##_f_##_opts_attribute f_##_f_##_opts_ifname = \ 162 + __CONFIGFS_ATTR_RO(ifname, _f_##_opts_ifname_show) 163 + 164 + #endif /* __U_ETHER_CONFIGFS_H */
+36
drivers/usb/gadget/u_gether.h
··· 1 + /* 2 + * u_gether.h 3 + * 4 + * Utility definitions for the subset function 5 + * 6 + * Copyright (c) 2013 Samsung Electronics Co., Ltd. 7 + * http://www.samsung.com 8 + * 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef U_GETHER_H 17 + #define U_GETHER_H 18 + 19 + #include <linux/usb/composite.h> 20 + 21 + struct f_gether_opts { 22 + struct usb_function_instance func_inst; 23 + struct net_device *net; 24 + bool bound; 25 + 26 + /* 27 + * Read/write access to configfs attributes is handled by configfs. 28 + * 29 + * This is to protect the data from concurrent access by read/write 30 + * and create symlink/remove symlink. 31 + */ 32 + struct mutex lock; 33 + int refcnt; 34 + }; 35 + 36 + #endif /* U_GETHER_H */
+36
drivers/usb/gadget/u_ncm.h
··· 1 + /* 2 + * u_ncm.h 3 + * 4 + * Utility definitions for the ncm function 5 + * 6 + * Copyright (c) 2013 Samsung Electronics Co., Ltd. 7 + * http://www.samsung.com 8 + * 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef U_NCM_H 17 + #define U_NCM_H 18 + 19 + #include <linux/usb/composite.h> 20 + 21 + struct f_ncm_opts { 22 + struct usb_function_instance func_inst; 23 + struct net_device *net; 24 + bool bound; 25 + 26 + /* 27 + * Read/write access to configfs attributes is handled by configfs. 28 + * 29 + * This is to protect the data from concurrent access by read/write 30 + * and create symlink/remove symlink. 31 + */ 32 + struct mutex lock; 33 + int refcnt; 34 + }; 35 + 36 + #endif /* U_NCM_H */
+11 -3
drivers/usb/gadget/u_phonet.h
··· 14 14 #include <linux/usb/composite.h> 15 15 #include <linux/usb/cdc.h> 16 16 17 - int gphonet_setup(struct usb_gadget *gadget); 18 - int phonet_bind_config(struct usb_configuration *c); 19 - void gphonet_cleanup(void); 17 + struct f_phonet_opts { 18 + struct usb_function_instance func_inst; 19 + bool bound; 20 + struct net_device *net; 21 + }; 22 + 23 + struct net_device *gphonet_setup_default(void); 24 + void gphonet_set_gadget(struct net_device *net, struct usb_gadget *g); 25 + int gphonet_register_netdev(struct net_device *net); 26 + int phonet_bind_config(struct usb_configuration *c, struct net_device *dev); 27 + void gphonet_cleanup(struct net_device *dev); 20 28 21 29 #endif /* __U_PHONET_H */
+41
drivers/usb/gadget/u_rndis.h
··· 1 + /* 2 + * u_rndis.h 3 + * 4 + * Utility definitions for the subset function 5 + * 6 + * Copyright (c) 2013 Samsung Electronics Co., Ltd. 7 + * http://www.samsung.com 8 + * 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef U_RNDIS_H 17 + #define U_RNDIS_H 18 + 19 + #include <linux/usb/composite.h> 20 + 21 + struct f_rndis_opts { 22 + struct usb_function_instance func_inst; 23 + u32 vendor_id; 24 + const char *manufacturer; 25 + struct net_device *net; 26 + bool bound; 27 + bool borrowed_net; 28 + 29 + /* 30 + * Read/write access to configfs attributes is handled by configfs. 31 + * 32 + * This is to protect the data from concurrent access by read/write 33 + * and create symlink/remove symlink. 34 + */ 35 + struct mutex lock; 36 + int refcnt; 37 + }; 38 + 39 + void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net); 40 + 41 + #endif /* U_RNDIS_H */
+16
drivers/usb/gadget/uvc_queue.c
··· 103 103 spin_unlock_irqrestore(&queue->irqlock, flags); 104 104 } 105 105 106 + static void uvc_wait_prepare(struct vb2_queue *vq) 107 + { 108 + struct uvc_video_queue *queue = vb2_get_drv_priv(vq); 109 + 110 + mutex_unlock(&queue->mutex); 111 + } 112 + 113 + static void uvc_wait_finish(struct vb2_queue *vq) 114 + { 115 + struct uvc_video_queue *queue = vb2_get_drv_priv(vq); 116 + 117 + mutex_lock(&queue->mutex); 118 + } 119 + 106 120 static struct vb2_ops uvc_queue_qops = { 107 121 .queue_setup = uvc_queue_setup, 108 122 .buf_prepare = uvc_buffer_prepare, 109 123 .buf_queue = uvc_buffer_queue, 124 + .wait_prepare = uvc_wait_prepare, 125 + .wait_finish = uvc_wait_finish, 110 126 }; 111 127 112 128 static int uvc_queue_init(struct uvc_video_queue *queue,
+45 -60
drivers/usb/host/ehci-tegra.c
··· 611 611 /* Bits of PORTSC1, which will get cleared by writing 1 into them */ 612 612 #define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) 613 613 614 - static void tegra_ehci_set_pts(struct usb_phy *x, u8 pts_val) 614 + void tegra_ehci_set_pts(struct usb_phy *x, u8 pts_val) 615 615 { 616 616 unsigned long val; 617 617 struct usb_hcd *hcd = bus_to_hcd(x->otg->host); ··· 622 622 val |= TEGRA_USB_PORTSC1_PTS(pts_val & 3); 623 623 writel(val, base + TEGRA_USB_PORTSC1); 624 624 } 625 + EXPORT_SYMBOL_GPL(tegra_ehci_set_pts); 625 626 626 - static void tegra_ehci_set_phcd(struct usb_phy *x, bool enable) 627 + void tegra_ehci_set_phcd(struct usb_phy *x, bool enable) 627 628 { 628 629 unsigned long val; 629 630 struct usb_hcd *hcd = bus_to_hcd(x->otg->host); ··· 637 636 val &= ~TEGRA_USB_PORTSC1_PHCD; 638 637 writel(val, base + TEGRA_USB_PORTSC1); 639 638 } 639 + EXPORT_SYMBOL_GPL(tegra_ehci_set_phcd); 640 640 641 641 static int tegra_ehci_probe(struct platform_device *pdev) 642 642 { ··· 647 645 struct tegra_ehci_platform_data *pdata; 648 646 int err = 0; 649 647 int irq; 650 - int instance = pdev->id; 648 + struct device_node *np_phy; 651 649 struct usb_phy *u_phy; 652 650 653 651 pdata = pdev->dev.platform_data; ··· 672 670 if (!tegra) 673 671 return -ENOMEM; 674 672 675 - hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev, 676 - dev_name(&pdev->dev)); 677 - if (!hcd) { 678 - dev_err(&pdev->dev, "Unable to create HCD\n"); 679 - return -ENOMEM; 680 - } 681 - 682 - platform_set_drvdata(pdev, tegra); 683 - 684 673 tegra->clk = devm_clk_get(&pdev->dev, NULL); 685 674 if (IS_ERR(tegra->clk)) { 686 675 dev_err(&pdev->dev, "Can't get ehci clock\n"); 687 - err = PTR_ERR(tegra->clk); 688 - goto fail_clk; 676 + return PTR_ERR(tegra->clk); 689 677 } 690 678 691 679 err = clk_prepare_enable(tegra->clk); 692 680 if (err) 693 - goto fail_clk; 681 + return err; 694 682 695 683 tegra_periph_reset_assert(tegra->clk); 696 684 udelay(1); 697 685 tegra_periph_reset_deassert(tegra->clk); 698 686 687 + np_phy = of_parse_phandle(pdev->dev.of_node, "nvidia,phy", 0); 688 + if (!np_phy) { 689 + err = -ENODEV; 690 + goto cleanup_clk; 691 + } 692 + 693 + u_phy = tegra_usb_get_phy(np_phy); 694 + if (IS_ERR(u_phy)) { 695 + err = PTR_ERR(u_phy); 696 + goto cleanup_clk; 697 + } 698 + 699 699 tegra->needs_double_reset = of_property_read_bool(pdev->dev.of_node, 700 700 "nvidia,needs-double-reset"); 701 + 702 + hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev, 703 + dev_name(&pdev->dev)); 704 + if (!hcd) { 705 + dev_err(&pdev->dev, "Unable to create HCD\n"); 706 + err = -ENOMEM; 707 + goto cleanup_clk; 708 + } 709 + hcd->phy = u_phy; 701 710 702 711 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 703 712 if (!res) { 704 713 dev_err(&pdev->dev, "Failed to get I/O memory\n"); 705 714 err = -ENXIO; 706 - goto fail_io; 715 + goto cleanup_hcd_create; 707 716 } 708 717 hcd->rsrc_start = res->start; 709 718 hcd->rsrc_len = resource_size(res); ··· 722 709 if (!hcd->regs) { 723 710 dev_err(&pdev->dev, "Failed to remap I/O memory\n"); 724 711 err = -ENOMEM; 725 - goto fail_io; 712 + goto cleanup_hcd_create; 726 713 } 727 714 728 - /* This is pretty ugly and needs to be fixed when we do only 729 - * device-tree probing. Old code relies on the platform_device 730 - * numbering that we lack for device-tree-instantiated devices. 731 - */ 732 - if (instance < 0) { 733 - switch (res->start) { 734 - case TEGRA_USB_BASE: 735 - instance = 0; 736 - break; 737 - case TEGRA_USB2_BASE: 738 - instance = 1; 739 - break; 740 - case TEGRA_USB3_BASE: 741 - instance = 2; 742 - break; 743 - default: 744 - err = -ENODEV; 745 - dev_err(&pdev->dev, "unknown usb instance\n"); 746 - goto fail_io; 747 - } 715 + err = usb_phy_init(hcd->phy); 716 + if (err) { 717 + dev_err(&pdev->dev, "Failed to initialize phy\n"); 718 + goto cleanup_hcd_create; 748 719 } 749 - 750 - tegra->phy = tegra_usb_phy_open(&pdev->dev, instance, hcd->regs, 751 - pdata->phy_config, 752 - TEGRA_USB_PHY_MODE_HOST, 753 - tegra_ehci_set_pts, 754 - tegra_ehci_set_phcd); 755 - if (IS_ERR(tegra->phy)) { 756 - dev_err(&pdev->dev, "Failed to open USB phy\n"); 757 - err = -ENXIO; 758 - goto fail_io; 759 - } 760 - 761 - hcd->phy = u_phy = &tegra->phy->u_phy; 762 - usb_phy_init(hcd->phy); 763 720 764 721 u_phy->otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), 765 722 GFP_KERNEL); 766 723 if (!u_phy->otg) { 767 724 dev_err(&pdev->dev, "Failed to alloc memory for otg\n"); 768 725 err = -ENOMEM; 769 - goto fail_io; 726 + goto cleanup_phy; 770 727 } 771 728 u_phy->otg->host = hcd_to_bus(hcd); 772 729 773 730 err = usb_phy_set_suspend(hcd->phy, 0); 774 731 if (err) { 775 732 dev_err(&pdev->dev, "Failed to power on the phy\n"); 776 - goto fail_phy; 733 + goto cleanup_phy; 777 734 } 778 735 779 736 tegra->host_resumed = 1; ··· 753 770 if (!irq) { 754 771 dev_err(&pdev->dev, "Failed to get IRQ\n"); 755 772 err = -ENODEV; 756 - goto fail_phy; 773 + goto cleanup_phy; 757 774 } 758 775 759 776 if (pdata->operating_mode == TEGRA_USB_OTG) { ··· 765 782 tegra->transceiver = ERR_PTR(-ENODEV); 766 783 } 767 784 785 + platform_set_drvdata(pdev, tegra); 786 + 768 787 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 769 788 if (err) { 770 789 dev_err(&pdev->dev, "Failed to add USB HCD\n"); 771 - goto fail; 790 + goto cleanup_phy; 772 791 } 773 792 774 793 pm_runtime_set_active(&pdev->dev); ··· 783 798 pm_runtime_put_sync(&pdev->dev); 784 799 return err; 785 800 786 - fail: 801 + cleanup_phy: 787 802 if (!IS_ERR(tegra->transceiver)) 788 803 otg_set_host(tegra->transceiver->otg, NULL); 789 - fail_phy: 804 + 790 805 usb_phy_shutdown(hcd->phy); 791 - fail_io: 792 - clk_disable_unprepare(tegra->clk); 793 - fail_clk: 806 + cleanup_hcd_create: 794 807 usb_put_hcd(hcd); 808 + cleanup_clk: 809 + clk_disable_unprepare(tegra->clk); 795 810 return err; 796 811 } 797 812
+29
drivers/usb/musb/Kconfig
··· 28 28 if USB_MUSB_HDRC 29 29 30 30 choice 31 + bool "MUSB Mode Selection" 32 + default USB_MUSB_DUAL_ROLE if (USB && USB_GADGET) 33 + default USB_MUSB_HOST if (USB && !USB_GADGET) 34 + default USB_MUSB_GADGET if (!USB && USB_GADGET) 35 + 36 + config USB_MUSB_HOST 37 + bool "Host only mode" 38 + depends on USB 39 + help 40 + Select this when you want to use MUSB in host mode only, 41 + thereby the gadget feature will be regressed. 42 + 43 + config USB_MUSB_GADGET 44 + bool "Gadget only mode" 45 + depends on USB_GADGET 46 + help 47 + Select this when you want to use MUSB in gadget mode only, 48 + thereby the host feature will be regressed. 49 + 50 + config USB_MUSB_DUAL_ROLE 51 + bool "Dual Role mode" 52 + depends on (USB && USB_GADGET) 53 + help 54 + This is the default mode of working of MUSB controller where 55 + both host and gadget features are enabled. 56 + 57 + endchoice 58 + 59 + choice 31 60 prompt "Platform Glue Layer" 32 61 33 62 config USB_MUSB_DAVINCI
+2 -2
drivers/usb/musb/Makefile
··· 6 6 7 7 musb_hdrc-y := musb_core.o 8 8 9 - musb_hdrc-y += musb_gadget_ep0.o musb_gadget.o 10 - musb_hdrc-y += musb_virthub.o musb_host.o 9 + musb_hdrc-$(CONFIG_USB_MUSB_HOST)$(CONFIG_USB_MUSB_DUAL_ROLE) += musb_virthub.o musb_host.o 10 + musb_hdrc-$(CONFIG_USB_MUSB_GADGET)$(CONFIG_USB_MUSB_DUAL_ROLE) += musb_gadget_ep0.o musb_gadget.o 11 11 musb_hdrc-$(CONFIG_DEBUG_FS) += musb_debugfs.o 12 12 13 13 # Hardware Glue Layer
+16 -2
drivers/usb/musb/blackfin.c
··· 450 450 451 451 static int bfin_probe(struct platform_device *pdev) 452 452 { 453 + struct resource musb_resources[2]; 453 454 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 454 455 struct platform_device *musb; 455 456 struct bfin_glue *glue; ··· 480 479 481 480 platform_set_drvdata(pdev, glue); 482 481 483 - ret = platform_device_add_resources(musb, pdev->resource, 484 - pdev->num_resources); 482 + memset(musb_resources, 0x00, sizeof(*musb_resources) * 483 + ARRAY_SIZE(musb_resources)); 484 + 485 + musb_resources[0].name = pdev->resource[0].name; 486 + musb_resources[0].start = pdev->resource[0].start; 487 + musb_resources[0].end = pdev->resource[0].end; 488 + musb_resources[0].flags = pdev->resource[0].flags; 489 + 490 + musb_resources[1].name = pdev->resource[1].name; 491 + musb_resources[1].start = pdev->resource[1].start; 492 + musb_resources[1].end = pdev->resource[1].end; 493 + musb_resources[1].flags = pdev->resource[1].flags; 494 + 495 + ret = platform_device_add_resources(musb, musb_resources, 496 + ARRAY_SIZE(musb_resources)); 485 497 if (ret) { 486 498 dev_err(&pdev->dev, "failed to add resources\n"); 487 499 goto err3;
+16 -2
drivers/usb/musb/da8xx.c
··· 476 476 477 477 static int da8xx_probe(struct platform_device *pdev) 478 478 { 479 + struct resource musb_resources[2]; 479 480 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 480 481 struct platform_device *musb; 481 482 struct da8xx_glue *glue; ··· 522 521 523 522 platform_set_drvdata(pdev, glue); 524 523 525 - ret = platform_device_add_resources(musb, pdev->resource, 526 - pdev->num_resources); 524 + memset(musb_resources, 0x00, sizeof(*musb_resources) * 525 + ARRAY_SIZE(musb_resources)); 526 + 527 + musb_resources[0].name = pdev->resource[0].name; 528 + musb_resources[0].start = pdev->resource[0].start; 529 + musb_resources[0].end = pdev->resource[0].end; 530 + musb_resources[0].flags = pdev->resource[0].flags; 531 + 532 + musb_resources[1].name = pdev->resource[1].name; 533 + musb_resources[1].start = pdev->resource[1].start; 534 + musb_resources[1].end = pdev->resource[1].end; 535 + musb_resources[1].flags = pdev->resource[1].flags; 536 + 537 + ret = platform_device_add_resources(musb, musb_resources, 538 + ARRAY_SIZE(musb_resources)); 527 539 if (ret) { 528 540 dev_err(&pdev->dev, "failed to add resources\n"); 529 541 goto err5;
+16 -2
drivers/usb/musb/davinci.c
··· 509 509 510 510 static int davinci_probe(struct platform_device *pdev) 511 511 { 512 + struct resource musb_resources[2]; 512 513 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 513 514 struct platform_device *musb; 514 515 struct davinci_glue *glue; ··· 554 553 555 554 platform_set_drvdata(pdev, glue); 556 555 557 - ret = platform_device_add_resources(musb, pdev->resource, 558 - pdev->num_resources); 556 + memset(musb_resources, 0x00, sizeof(*musb_resources) * 557 + ARRAY_SIZE(musb_resources)); 558 + 559 + musb_resources[0].name = pdev->resource[0].name; 560 + musb_resources[0].start = pdev->resource[0].start; 561 + musb_resources[0].end = pdev->resource[0].end; 562 + musb_resources[0].flags = pdev->resource[0].flags; 563 + 564 + musb_resources[1].name = pdev->resource[1].name; 565 + musb_resources[1].start = pdev->resource[1].start; 566 + musb_resources[1].end = pdev->resource[1].end; 567 + musb_resources[1].flags = pdev->resource[1].flags; 568 + 569 + ret = platform_device_add_resources(musb, musb_resources, 570 + ARRAY_SIZE(musb_resources)); 559 571 if (ret) { 560 572 dev_err(&pdev->dev, "failed to add resources\n"); 561 573 goto err5;
+48 -89
drivers/usb/musb/musb_core.c
··· 380 380 dev_dbg(musb->controller, "HNP: Unhandled mode %s\n", 381 381 usb_otg_state_string(musb->xceiv->state)); 382 382 } 383 - musb->ignore_disconnect = 0; 384 383 spin_unlock_irqrestore(&musb->lock, flags); 385 384 } 386 385 ··· 388 389 */ 389 390 void musb_hnp_stop(struct musb *musb) 390 391 { 391 - struct usb_hcd *hcd = musb_to_hcd(musb); 392 + struct usb_hcd *hcd = musb->hcd; 392 393 void __iomem *mbase = musb->mregs; 393 394 u8 reg; 394 395 ··· 403 404 break; 404 405 case OTG_STATE_B_HOST: 405 406 dev_dbg(musb->controller, "HNP: Disabling HR\n"); 406 - hcd->self.is_b_host = 0; 407 + if (hcd) 408 + hcd->self.is_b_host = 0; 407 409 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 408 410 MUSB_DEV_MODE(musb); 409 411 reg = musb_readb(mbase, MUSB_POWER); ··· 484 484 485 485 musb->xceiv->state = OTG_STATE_A_HOST; 486 486 musb->is_active = 1; 487 - usb_hcd_resume_root_hub(musb_to_hcd(musb)); 487 + musb_host_resume_root_hub(musb); 488 488 break; 489 489 case OTG_STATE_B_WAIT_ACON: 490 490 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; ··· 501 501 case OTG_STATE_A_SUSPEND: 502 502 /* possibly DISCONNECT is upcoming */ 503 503 musb->xceiv->state = OTG_STATE_A_HOST; 504 - usb_hcd_resume_root_hub(musb_to_hcd(musb)); 504 + musb_host_resume_root_hub(musb); 505 505 break; 506 506 case OTG_STATE_B_WAIT_ACON: 507 507 case OTG_STATE_B_PERIPHERAL: ··· 643 643 * undesired detour through A_WAIT_BCON. 644 644 */ 645 645 musb_hnp_stop(musb); 646 - usb_hcd_resume_root_hub(musb_to_hcd(musb)); 646 + musb_host_resume_root_hub(musb); 647 647 musb_root_disconnect(musb); 648 648 musb_platform_try_idle(musb, jiffies 649 649 + msecs_to_jiffies(musb->a_wait_bcon ··· 685 685 } 686 686 687 687 if (int_usb & MUSB_INTR_CONNECT) { 688 - struct usb_hcd *hcd = musb_to_hcd(musb); 688 + struct usb_hcd *hcd = musb->hcd; 689 689 690 690 handled = IRQ_HANDLED; 691 691 musb->is_active = 1; ··· 726 726 dev_dbg(musb->controller, "HNP: CONNECT, now b_host\n"); 727 727 b_host: 728 728 musb->xceiv->state = OTG_STATE_B_HOST; 729 - hcd->self.is_b_host = 1; 730 - musb->ignore_disconnect = 0; 729 + if (musb->hcd) 730 + musb->hcd->self.is_b_host = 1; 731 731 del_timer(&musb->otg_timer); 732 732 break; 733 733 default: 734 734 if ((devctl & MUSB_DEVCTL_VBUS) 735 735 == (3 << MUSB_DEVCTL_VBUS_SHIFT)) { 736 736 musb->xceiv->state = OTG_STATE_A_HOST; 737 - hcd->self.is_b_host = 0; 737 + if (hcd) 738 + hcd->self.is_b_host = 0; 738 739 } 739 740 break; 740 741 } 741 742 742 - /* poke the root hub */ 743 - MUSB_HST_MODE(musb); 744 - if (hcd->status_urb) 745 - usb_hcd_poll_rh_status(hcd); 746 - else 747 - usb_hcd_resume_root_hub(hcd); 743 + musb_host_poke_root_hub(musb); 748 744 749 745 dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", 750 746 usb_otg_state_string(musb->xceiv->state), devctl); 751 747 } 752 748 753 - if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) { 749 + if (int_usb & MUSB_INTR_DISCONNECT) { 754 750 dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", 755 751 usb_otg_state_string(musb->xceiv->state), 756 752 MUSB_MODE(musb), devctl); ··· 755 759 switch (musb->xceiv->state) { 756 760 case OTG_STATE_A_HOST: 757 761 case OTG_STATE_A_SUSPEND: 758 - usb_hcd_resume_root_hub(musb_to_hcd(musb)); 762 + musb_host_resume_root_hub(musb); 759 763 musb_root_disconnect(musb); 760 764 if (musb->a_wait_bcon != 0) 761 765 musb_platform_try_idle(musb, jiffies ··· 768 772 * in hnp_stop() is currently not used... 769 773 */ 770 774 musb_root_disconnect(musb); 771 - musb_to_hcd(musb)->self.is_b_host = 0; 775 + if (musb->hcd) 776 + musb->hcd->self.is_b_host = 0; 772 777 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 773 778 MUSB_DEV_MODE(musb); 774 779 musb_g_disconnect(musb); ··· 815 818 usb_otg_state_string(musb->xceiv->state)); 816 819 switch (musb->xceiv->state) { 817 820 case OTG_STATE_A_SUSPEND: 818 - /* We need to ignore disconnect on suspend 819 - * otherwise tusb 2.0 won't reconnect after a 820 - * power cycle, which breaks otg compliance. 821 - */ 822 - musb->ignore_disconnect = 1; 823 821 musb_g_reset(musb); 824 822 /* FALLTHROUGH */ 825 823 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ ··· 826 834 + msecs_to_jiffies(TA_WAIT_BCON(musb))); 827 835 break; 828 836 case OTG_STATE_A_PERIPHERAL: 829 - musb->ignore_disconnect = 0; 830 837 del_timer(&musb->otg_timer); 831 838 musb_g_reset(musb); 832 839 break; ··· 900 909 901 910 /*-------------------------------------------------------------------------*/ 902 911 903 - /* 904 - * Program the HDRC to start (enable interrupts, dma, etc.). 905 - */ 906 - void musb_start(struct musb *musb) 907 - { 908 - void __iomem *regs = musb->mregs; 909 - u8 devctl = musb_readb(regs, MUSB_DEVCTL); 910 - 911 - dev_dbg(musb->controller, "<== devctl %02x\n", devctl); 912 - 913 - /* Set INT enable registers, enable interrupts */ 914 - musb->intrtxe = musb->epmask; 915 - musb_writew(regs, MUSB_INTRTXE, musb->intrtxe); 916 - musb->intrrxe = musb->epmask & 0xfffe; 917 - musb_writew(regs, MUSB_INTRRXE, musb->intrrxe); 918 - musb_writeb(regs, MUSB_INTRUSBE, 0xf7); 919 - 920 - musb_writeb(regs, MUSB_TESTMODE, 0); 921 - 922 - /* put into basic highspeed mode and start session */ 923 - musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE 924 - | MUSB_POWER_HSENAB 925 - /* ENSUSPEND wedges tusb */ 926 - /* | MUSB_POWER_ENSUSPEND */ 927 - ); 928 - 929 - musb->is_active = 0; 930 - devctl = musb_readb(regs, MUSB_DEVCTL); 931 - devctl &= ~MUSB_DEVCTL_SESSION; 932 - 933 - /* session started after: 934 - * (a) ID-grounded irq, host mode; 935 - * (b) vbus present/connect IRQ, peripheral mode; 936 - * (c) peripheral initiates, using SRP 937 - */ 938 - if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) 939 - musb->is_active = 1; 940 - else 941 - devctl |= MUSB_DEVCTL_SESSION; 942 - 943 - musb_platform_enable(musb); 944 - musb_writeb(regs, MUSB_DEVCTL, devctl); 945 - } 946 - 947 - 948 912 static void musb_generic_disable(struct musb *musb) 949 913 { 950 914 void __iomem *mbase = musb->mregs; ··· 953 1007 954 1008 pm_runtime_get_sync(musb->controller); 955 1009 1010 + musb_host_cleanup(musb); 956 1011 musb_gadget_cleanup(musb); 957 1012 958 1013 spin_lock_irqsave(&musb->lock, flags); ··· 1710 1763 struct musb *musb; 1711 1764 struct musb_hw_ep *ep; 1712 1765 int epnum; 1713 - struct usb_hcd *hcd; 1766 + int ret; 1714 1767 1715 - hcd = usb_create_hcd(&musb_hc_driver, dev, dev_name(dev)); 1716 - if (!hcd) 1768 + musb = devm_kzalloc(dev, sizeof(*musb), GFP_KERNEL); 1769 + if (!musb) 1717 1770 return NULL; 1718 - /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */ 1719 1771 1720 - musb = hcd_to_musb(hcd); 1721 1772 INIT_LIST_HEAD(&musb->control); 1722 1773 INIT_LIST_HEAD(&musb->in_bulk); 1723 1774 INIT_LIST_HEAD(&musb->out_bulk); 1724 1775 1725 - hcd->uses_new_polling = 1; 1726 - hcd->has_tt = 1; 1727 - 1728 1776 musb->vbuserr_retry = VBUSERR_RETRY_COUNT; 1729 1777 musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON; 1730 - dev_set_drvdata(dev, musb); 1731 1778 musb->mregs = mbase; 1732 1779 musb->ctrl_base = mbase; 1733 1780 musb->nIrq = -ENODEV; ··· 1736 1795 1737 1796 musb->controller = dev; 1738 1797 1798 + ret = musb_host_alloc(musb); 1799 + if (ret < 0) 1800 + goto err_free; 1801 + 1802 + dev_set_drvdata(dev, musb); 1803 + 1739 1804 return musb; 1805 + 1806 + err_free: 1807 + return NULL; 1740 1808 } 1741 1809 1742 1810 static void musb_free(struct musb *musb) ··· 1771 1821 dma_controller_destroy(c); 1772 1822 } 1773 1823 1774 - usb_put_hcd(musb_to_hcd(musb)); 1824 + musb_host_free(musb); 1775 1825 } 1776 1826 1777 1827 /* ··· 1788 1838 int status; 1789 1839 struct musb *musb; 1790 1840 struct musb_hdrc_platform_data *plat = dev->platform_data; 1791 - struct usb_hcd *hcd; 1792 1841 1793 1842 /* The driver might handle more features than the board; OK. 1794 1843 * Fail when the board needs a feature that's not enabled. ··· 1813 1864 musb->board_set_power = plat->set_power; 1814 1865 musb->min_power = plat->min_power; 1815 1866 musb->ops = plat->platform_ops; 1867 + musb->port_mode = plat->mode; 1816 1868 1817 1869 /* The musb_platform_init() call: 1818 1870 * - adjusts musb->mregs ··· 1889 1939 musb->irq_wake = 0; 1890 1940 } 1891 1941 1892 - /* host side needs more setup */ 1893 - hcd = musb_to_hcd(musb); 1894 - otg_set_host(musb->xceiv->otg, &hcd->self); 1895 - hcd->self.otg_port = 1; 1896 - musb->xceiv->otg->host = &hcd->self; 1897 - hcd->power_budget = 2 * (plat->power ? : 250); 1898 - 1899 1942 /* program PHY to use external vBus if required */ 1900 1943 if (plat->extvbus) { 1901 1944 u8 busctl = musb_read_ulpi_buscontrol(musb->mregs); ··· 1904 1961 musb->xceiv->state = OTG_STATE_B_IDLE; 1905 1962 } 1906 1963 1907 - status = musb_gadget_setup(musb); 1964 + switch (musb->port_mode) { 1965 + case MUSB_PORT_MODE_HOST: 1966 + status = musb_host_setup(musb, plat->power); 1967 + break; 1968 + case MUSB_PORT_MODE_GADGET: 1969 + status = musb_gadget_setup(musb); 1970 + break; 1971 + case MUSB_PORT_MODE_DUAL_ROLE: 1972 + status = musb_host_setup(musb, plat->power); 1973 + if (status < 0) 1974 + goto fail3; 1975 + status = musb_gadget_setup(musb); 1976 + break; 1977 + default: 1978 + dev_err(dev, "unsupported port mode %d\n", musb->port_mode); 1979 + break; 1980 + } 1908 1981 1909 1982 if (status < 0) 1910 1983 goto fail3;
+8 -19
drivers/usb/musb/musb_core.h
··· 77 77 #define is_peripheral_active(m) (!(m)->is_host) 78 78 #define is_host_active(m) ((m)->is_host) 79 79 80 + enum { 81 + MUSB_PORT_MODE_HOST = 1, 82 + MUSB_PORT_MODE_GADGET, 83 + MUSB_PORT_MODE_DUAL_ROLE, 84 + }; 85 + 80 86 #ifdef CONFIG_PROC_FS 81 87 #include <linux/fs.h> 82 88 #define MUSB_CONFIG_PROC_FS 83 89 #endif 84 - 85 - /****************************** PERIPHERAL ROLE *****************************/ 86 - 87 - extern irqreturn_t musb_g_ep0_irq(struct musb *); 88 - extern void musb_g_tx(struct musb *, u8); 89 - extern void musb_g_rx(struct musb *, u8); 90 - extern void musb_g_reset(struct musb *); 91 - extern void musb_g_suspend(struct musb *); 92 - extern void musb_g_resume(struct musb *); 93 - extern void musb_g_wakeup(struct musb *); 94 - extern void musb_g_disconnect(struct musb *); 95 - 96 - /****************************** HOST ROLE ***********************************/ 97 - 98 - extern irqreturn_t musb_h_ep0_irq(struct musb *); 99 - extern void musb_host_tx(struct musb *, u8); 100 - extern void musb_host_rx(struct musb *, u8); 101 90 102 91 /****************************** CONSTANTS ********************************/ 103 92 ··· 362 373 363 374 u8 min_power; /* vbus for periph, in mA/2 */ 364 375 376 + int port_mode; /* MUSB_PORT_MODE_* */ 365 377 bool is_host; 366 378 367 379 int a_wait_bcon; /* VBUS timeout in msecs */ ··· 372 382 unsigned is_active:1; 373 383 374 384 unsigned is_multipoint:1; 375 - unsigned ignore_disconnect:1; /* during bus resets */ 376 385 377 386 unsigned hb_iso_rx:1; /* high bandwidth iso rx? */ 378 387 unsigned hb_iso_tx:1; /* high bandwidth iso tx? */ ··· 408 419 enum musb_g_ep0_state ep0_state; 409 420 struct usb_gadget g; /* the gadget */ 410 421 struct usb_gadget_driver *gadget_driver; /* its driver */ 422 + struct usb_hcd *hcd; /* the usb hcd */ 411 423 412 424 /* 413 425 * FIXME: Remove this flag. ··· 510 520 511 521 extern const char musb_driver_name[]; 512 522 513 - extern void musb_start(struct musb *musb); 514 523 extern void musb_stop(struct musb *musb); 515 524 516 525 extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src);
-10
drivers/usb/musb/musb_gadget.c
··· 1820 1820 { 1821 1821 struct musb *musb = gadget_to_musb(g); 1822 1822 struct usb_otg *otg = musb->xceiv->otg; 1823 - struct usb_hcd *hcd = musb_to_hcd(musb); 1824 1823 unsigned long flags; 1825 1824 int retval = 0; 1826 1825 ··· 1846 1847 * handles power budgeting ... this way also 1847 1848 * ensures HdrcStart is indirectly called. 1848 1849 */ 1849 - retval = usb_add_hcd(hcd, 0, 0); 1850 - if (retval < 0) { 1851 - dev_dbg(musb->controller, "add_hcd failed, %d\n", retval); 1852 - goto err; 1853 - } 1854 - 1855 1850 if (musb->xceiv->last_event == USB_EVENT_ID) 1856 1851 musb_platform_set_vbus(musb, 1); 1857 - 1858 - hcd->self.uses_pio_for_control = 1; 1859 1852 1860 1853 if (musb->xceiv->last_event == USB_EVENT_NONE) 1861 1854 pm_runtime_put(musb->controller); ··· 1933 1942 musb_platform_try_idle(musb, 0); 1934 1943 spin_unlock_irqrestore(&musb->lock, flags); 1935 1944 1936 - usb_remove_hcd(musb_to_hcd(musb)); 1937 1945 /* 1938 1946 * FIXME we need to be able to register another 1939 1947 * gadget driver here and have everything work;
+32 -6
drivers/usb/musb/musb_gadget.h
··· 37 37 38 38 #include <linux/list.h> 39 39 40 + #if IS_ENABLED(CONFIG_USB_MUSB_GADGET) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE) 41 + extern irqreturn_t musb_g_ep0_irq(struct musb *); 42 + extern void musb_g_tx(struct musb *, u8); 43 + extern void musb_g_rx(struct musb *, u8); 44 + extern void musb_g_reset(struct musb *); 45 + extern void musb_g_suspend(struct musb *); 46 + extern void musb_g_resume(struct musb *); 47 + extern void musb_g_wakeup(struct musb *); 48 + extern void musb_g_disconnect(struct musb *); 49 + extern void musb_gadget_cleanup(struct musb *); 50 + extern int musb_gadget_setup(struct musb *); 51 + 52 + #else 53 + static inline irqreturn_t musb_g_ep0_irq(struct musb *musb) 54 + { 55 + return 0; 56 + } 57 + 58 + static inline void musb_g_tx(struct musb *musb, u8 epnum) {} 59 + static inline void musb_g_rx(struct musb *musb, u8 epnum) {} 60 + static inline void musb_g_reset(struct musb *musb) {} 61 + static inline void musb_g_suspend(struct musb *musb) {} 62 + static inline void musb_g_resume(struct musb *musb) {} 63 + static inline void musb_g_wakeup(struct musb *musb) {} 64 + static inline void musb_g_disconnect(struct musb *musb) {} 65 + static inline void musb_gadget_cleanup(struct musb *musb) {} 66 + static inline int musb_gadget_setup(struct musb *musb) 67 + { 68 + return 0; 69 + } 70 + #endif 71 + 40 72 enum buffer_map_state { 41 73 UN_MAPPED = 0, 42 74 PRE_MAPPED, ··· 138 106 return container_of(queue->next, struct musb_request, list); 139 107 } 140 108 141 - extern void musb_g_tx(struct musb *musb, u8 epnum); 142 - extern void musb_g_rx(struct musb *musb, u8 epnum); 143 - 144 109 extern const struct usb_ep_ops musb_g_ep0_ops; 145 - 146 - extern int musb_gadget_setup(struct musb *); 147 - extern void musb_gadget_cleanup(struct musb *); 148 110 149 111 extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int); 150 112
+81 -15
drivers/usb/musb/musb_host.c
··· 46 46 #include "musb_core.h" 47 47 #include "musb_host.h" 48 48 49 - 50 49 /* MUSB HOST status 22-mar-2006 51 50 * 52 51 * - There's still lots of partial code duplication for fault paths, so ··· 94 95 * "claimed" until its software queue is no longer refilled. No multiplexing 95 96 * of transfers between endpoints, or anything clever. 96 97 */ 98 + 99 + struct musb *hcd_to_musb(struct usb_hcd *hcd) 100 + { 101 + return *(struct musb **) hcd->hcd_priv; 102 + } 97 103 98 104 99 105 static void musb_ep_program(struct musb *musb, u8 epnum, ··· 314 310 urb->actual_length, urb->transfer_buffer_length 315 311 ); 316 312 317 - usb_hcd_unlink_urb_from_ep(musb_to_hcd(musb), urb); 313 + usb_hcd_unlink_urb_from_ep(musb->hcd, urb); 318 314 spin_unlock(&musb->lock); 319 - usb_hcd_giveback_urb(musb_to_hcd(musb), urb, status); 315 + usb_hcd_giveback_urb(musb->hcd, urb, status); 320 316 spin_lock(&musb->lock); 321 317 } 322 318 ··· 628 624 u16 csr; 629 625 u8 mode; 630 626 631 - #ifdef CONFIG_USB_INVENTRA_DMA 627 + #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA) 632 628 if (length > channel->max_len) 633 629 length = channel->max_len; 634 630 ··· 1458 1454 if (length > qh->maxpacket) 1459 1455 length = qh->maxpacket; 1460 1456 /* Unmap the buffer so that CPU can use it */ 1461 - usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb); 1457 + usb_hcd_unmap_urb_for_dma(musb->hcd, urb); 1462 1458 1463 1459 /* 1464 1460 * We need to map sg if the transfer_buffer is ··· 1660 1656 1661 1657 /* FIXME this is _way_ too much in-line logic for Mentor DMA */ 1662 1658 1663 - #ifndef CONFIG_USB_INVENTRA_DMA 1659 + #if !defined(CONFIG_USB_INVENTRA_DMA) && !defined(CONFIG_USB_UX500_DMA) 1664 1660 if (rx_csr & MUSB_RXCSR_H_REQPKT) { 1665 1661 /* REVISIT this happened for a while on some short reads... 1666 1662 * the cleanup still needs investigation... looks bad... ··· 1692 1688 | MUSB_RXCSR_RXPKTRDY); 1693 1689 musb_writew(hw_ep->regs, MUSB_RXCSR, val); 1694 1690 1695 - #ifdef CONFIG_USB_INVENTRA_DMA 1691 + #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA) 1696 1692 if (usb_pipeisoc(pipe)) { 1697 1693 struct usb_iso_packet_descriptor *d; 1698 1694 ··· 1748 1744 } 1749 1745 1750 1746 /* we are expecting IN packets */ 1751 - #ifdef CONFIG_USB_INVENTRA_DMA 1747 + #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA) 1752 1748 if (dma) { 1753 1749 struct dma_controller *c; 1754 1750 u16 rx_count; ··· 1757 1753 1758 1754 rx_count = musb_readw(epio, MUSB_RXCOUNT); 1759 1755 1760 - dev_dbg(musb->controller, "RX%d count %d, buffer 0x%x len %d/%d\n", 1756 + dev_dbg(musb->controller, "RX%d count %d, buffer 0x%llx len %d/%d\n", 1761 1757 epnum, rx_count, 1762 - urb->transfer_dma 1763 - + urb->actual_length, 1758 + (unsigned long long) urb->transfer_dma 1759 + + urb->actual_length, 1764 1760 qh->offset, 1765 1761 urb->transfer_buffer_length); 1766 1762 ··· 1872 1868 unsigned int received_len; 1873 1869 1874 1870 /* Unmap the buffer so that CPU can use it */ 1875 - usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb); 1871 + usb_hcd_unmap_urb_for_dma(musb->hcd, urb); 1876 1872 1877 1873 /* 1878 1874 * We need to map sg if the transfer_buffer is ··· 2466 2462 return 0; 2467 2463 } 2468 2464 2469 - 2470 2465 #ifndef CONFIG_MUSB_PIO_ONLY 2471 2466 2472 2467 #define MUSB_USB_DMA_ALIGN 4 ··· 2577 2574 } 2578 2575 #endif /* !CONFIG_MUSB_PIO_ONLY */ 2579 2576 2580 - const struct hc_driver musb_hc_driver = { 2577 + static const struct hc_driver musb_hc_driver = { 2581 2578 .description = "musb-hcd", 2582 2579 .product_desc = "MUSB HDRC host driver", 2583 - .hcd_priv_size = sizeof(struct musb), 2580 + .hcd_priv_size = sizeof(struct musb *), 2584 2581 .flags = HCD_USB2 | HCD_MEMORY, 2585 2582 2586 2583 /* not using irq handler or reset hooks from usbcore, since ··· 2608 2605 /* .start_port_reset = NULL, */ 2609 2606 /* .hub_irq_enable = NULL, */ 2610 2607 }; 2608 + 2609 + int musb_host_alloc(struct musb *musb) 2610 + { 2611 + struct device *dev = musb->controller; 2612 + 2613 + /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */ 2614 + musb->hcd = usb_create_hcd(&musb_hc_driver, dev, dev_name(dev)); 2615 + if (!musb->hcd) 2616 + return -EINVAL; 2617 + 2618 + *musb->hcd->hcd_priv = (unsigned long) musb; 2619 + musb->hcd->self.uses_pio_for_control = 1; 2620 + musb->hcd->uses_new_polling = 1; 2621 + musb->hcd->has_tt = 1; 2622 + 2623 + return 0; 2624 + } 2625 + 2626 + void musb_host_cleanup(struct musb *musb) 2627 + { 2628 + usb_remove_hcd(musb->hcd); 2629 + musb->hcd = NULL; 2630 + } 2631 + 2632 + void musb_host_free(struct musb *musb) 2633 + { 2634 + usb_put_hcd(musb->hcd); 2635 + } 2636 + 2637 + int musb_host_setup(struct musb *musb, int power_budget) 2638 + { 2639 + int ret; 2640 + struct usb_hcd *hcd = musb->hcd; 2641 + 2642 + MUSB_HST_MODE(musb); 2643 + musb->xceiv->otg->default_a = 1; 2644 + musb->xceiv->state = OTG_STATE_A_IDLE; 2645 + 2646 + otg_set_host(musb->xceiv->otg, &hcd->self); 2647 + hcd->self.otg_port = 1; 2648 + musb->xceiv->otg->host = &hcd->self; 2649 + hcd->power_budget = 2 * (power_budget ? : 250); 2650 + 2651 + ret = usb_add_hcd(hcd, 0, 0); 2652 + if (ret < 0) 2653 + return ret; 2654 + 2655 + return 0; 2656 + } 2657 + 2658 + void musb_host_resume_root_hub(struct musb *musb) 2659 + { 2660 + usb_hcd_resume_root_hub(musb->hcd); 2661 + } 2662 + 2663 + void musb_host_poke_root_hub(struct musb *musb) 2664 + { 2665 + MUSB_HST_MODE(musb); 2666 + if (musb->hcd->status_urb) 2667 + usb_hcd_poll_rh_status(musb->hcd); 2668 + else 2669 + usb_hcd_resume_root_hub(musb->hcd); 2670 + }
+45 -12
drivers/usb/musb/musb_host.h
··· 37 37 38 38 #include <linux/scatterlist.h> 39 39 40 - static inline struct usb_hcd *musb_to_hcd(struct musb *musb) 41 - { 42 - return container_of((void *) musb, struct usb_hcd, hcd_priv); 43 - } 44 - 45 - static inline struct musb *hcd_to_musb(struct usb_hcd *hcd) 46 - { 47 - return (struct musb *) (hcd->hcd_priv); 48 - } 49 - 50 40 /* stored in "usb_host_endpoint.hcpriv" for scheduled endpoints */ 51 41 struct musb_qh { 52 42 struct usb_host_endpoint *hep; /* usbcore info */ ··· 76 86 } 77 87 78 88 89 + #if IS_ENABLED(CONFIG_USB_MUSB_HOST) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE) 90 + extern struct musb *hcd_to_musb(struct usb_hcd *); 91 + extern irqreturn_t musb_h_ep0_irq(struct musb *); 92 + extern int musb_host_alloc(struct musb *); 93 + extern int musb_host_setup(struct musb *, int); 94 + extern void musb_host_cleanup(struct musb *); 95 + extern void musb_host_tx(struct musb *, u8); 96 + extern void musb_host_rx(struct musb *, u8); 79 97 extern void musb_root_disconnect(struct musb *musb); 98 + extern void musb_host_free(struct musb *); 99 + extern void musb_host_cleanup(struct musb *); 100 + extern void musb_host_tx(struct musb *, u8); 101 + extern void musb_host_rx(struct musb *, u8); 102 + extern void musb_root_disconnect(struct musb *musb); 103 + extern void musb_host_resume_root_hub(struct musb *musb); 104 + extern void musb_host_poke_root_hub(struct musb *musb); 105 + #else 106 + static inline struct musb *hcd_to_musb(struct usb_hcd *hcd) 107 + { 108 + return NULL; 109 + } 110 + 111 + static inline irqreturn_t musb_h_ep0_irq(struct musb *musb) 112 + { 113 + return 0; 114 + } 115 + 116 + static inline int musb_host_alloc(struct musb *musb) 117 + { 118 + return 0; 119 + } 120 + 121 + static inline int musb_host_setup(struct musb *musb, int power_budget) 122 + { 123 + return 0; 124 + } 125 + 126 + static inline void musb_host_cleanup(struct musb *musb) {} 127 + static inline void musb_host_free(struct musb *musb) {} 128 + static inline void musb_host_tx(struct musb *musb, u8 epnum) {} 129 + static inline void musb_host_rx(struct musb *musb, u8 epnum) {} 130 + static inline void musb_root_disconnect(struct musb *musb) {} 131 + static inline void musb_host_resume_root_hub(struct musb *musb) {} 132 + static inline void musb_host_poll_rh_status(struct musb *musb) {} 133 + static inline void musb_host_poke_root_hub(struct musb *musb) {} 134 + #endif 80 135 81 136 struct usb_hcd; 82 137 ··· 129 94 extern int musb_hub_control(struct usb_hcd *hcd, 130 95 u16 typeReq, u16 wValue, u16 wIndex, 131 96 char *buf, u16 wLength); 132 - 133 - extern const struct hc_driver musb_hc_driver; 134 97 135 98 static inline struct urb *next_urb(struct musb_qh *qh) 136 99 {
+48 -6
drivers/usb/musb/musb_virthub.c
··· 44 44 45 45 #include "musb_core.h" 46 46 47 + /* 48 + * Program the HDRC to start (enable interrupts, dma, etc.). 49 + */ 50 + static void musb_start(struct musb *musb) 51 + { 52 + void __iomem *regs = musb->mregs; 53 + u8 devctl = musb_readb(regs, MUSB_DEVCTL); 54 + 55 + dev_dbg(musb->controller, "<== devctl %02x\n", devctl); 56 + 57 + /* Set INT enable registers, enable interrupts */ 58 + musb->intrtxe = musb->epmask; 59 + musb_writew(regs, MUSB_INTRTXE, musb->intrtxe); 60 + musb->intrrxe = musb->epmask & 0xfffe; 61 + musb_writew(regs, MUSB_INTRRXE, musb->intrrxe); 62 + musb_writeb(regs, MUSB_INTRUSBE, 0xf7); 63 + 64 + musb_writeb(regs, MUSB_TESTMODE, 0); 65 + 66 + /* put into basic highspeed mode and start session */ 67 + musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE 68 + | MUSB_POWER_HSENAB 69 + /* ENSUSPEND wedges tusb */ 70 + /* | MUSB_POWER_ENSUSPEND */ 71 + ); 72 + 73 + musb->is_active = 0; 74 + devctl = musb_readb(regs, MUSB_DEVCTL); 75 + devctl &= ~MUSB_DEVCTL_SESSION; 76 + 77 + /* session started after: 78 + * (a) ID-grounded irq, host mode; 79 + * (b) vbus present/connect IRQ, peripheral mode; 80 + * (c) peripheral initiates, using SRP 81 + */ 82 + if (musb->port_mode != MUSB_PORT_MODE_HOST && 83 + (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) { 84 + musb->is_active = 1; 85 + } else { 86 + devctl |= MUSB_DEVCTL_SESSION; 87 + } 88 + 89 + musb_platform_enable(musb); 90 + musb_writeb(regs, MUSB_DEVCTL, devctl); 91 + } 47 92 48 93 static void musb_port_suspend(struct musb *musb, bool do_suspend) 49 94 { ··· 190 145 msleep(1); 191 146 } 192 147 193 - musb->ignore_disconnect = true; 194 148 power &= 0xf0; 195 149 musb_writeb(mbase, MUSB_POWER, 196 150 power | MUSB_POWER_RESET); ··· 202 158 musb_writeb(mbase, MUSB_POWER, 203 159 power & ~MUSB_POWER_RESET); 204 160 205 - musb->ignore_disconnect = false; 206 - 207 161 power = musb_readb(mbase, MUSB_POWER); 208 162 if (power & MUSB_POWER_HSMODE) { 209 163 dev_dbg(musb->controller, "high-speed device connected\n"); ··· 212 170 musb->port1_status |= USB_PORT_STAT_ENABLE 213 171 | (USB_PORT_STAT_C_RESET << 16) 214 172 | (USB_PORT_STAT_C_ENABLE << 16); 215 - usb_hcd_poll_rh_status(musb_to_hcd(musb)); 173 + usb_hcd_poll_rh_status(musb->hcd); 216 174 217 175 musb->vbuserr_retry = VBUSERR_RETRY_COUNT; 218 176 } ··· 225 183 musb->port1_status = USB_PORT_STAT_POWER 226 184 | (USB_PORT_STAT_C_CONNECTION << 16); 227 185 228 - usb_hcd_poll_rh_status(musb_to_hcd(musb)); 186 + usb_hcd_poll_rh_status(musb->hcd); 229 187 musb->is_active = 0; 230 188 231 189 switch (musb->xceiv->state) { ··· 379 337 musb->port1_status &= ~(USB_PORT_STAT_SUSPEND 380 338 | MUSB_PORT_STAT_RESUME); 381 339 musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; 382 - usb_hcd_poll_rh_status(musb_to_hcd(musb)); 340 + usb_hcd_poll_rh_status(musb->hcd); 383 341 /* NOTE: it might really be A_WAIT_BCON ... */ 384 342 musb->xceiv->state = OTG_STATE_A_HOST; 385 343 }
+17 -3
drivers/usb/musb/omap2430.c
··· 87 87 musb->port1_status &= ~(USB_PORT_STAT_SUSPEND 88 88 | MUSB_PORT_STAT_RESUME); 89 89 musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; 90 - usb_hcd_poll_rh_status(musb_to_hcd(musb)); 90 + usb_hcd_poll_rh_status(musb->hcd); 91 91 /* NOTE: it might really be A_WAIT_BCON ... */ 92 92 musb->xceiv->state = OTG_STATE_A_HOST; 93 93 } ··· 481 481 482 482 static int omap2430_probe(struct platform_device *pdev) 483 483 { 484 + struct resource musb_resouces[2]; 484 485 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 485 486 struct omap_musb_board_data *data; 486 487 struct platform_device *musb; ··· 568 567 569 568 INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work); 570 569 571 - ret = platform_device_add_resources(musb, pdev->resource, 572 - pdev->num_resources); 570 + memset(musb_resouces, 0x00, sizeof(*musb_resources) * 571 + ARRAY_SIZE(musb_resources)); 572 + 573 + musb_resources[0].name = pdev->resource[0].name; 574 + musb_resources[0].start = pdev->resource[0].start; 575 + musb_resources[0].end = pdev->resource[0].end; 576 + musb_resources[0].flags = pdev->resource[0].flags; 577 + 578 + musb_resources[1].name = pdev->resource[1].name; 579 + musb_resources[1].start = pdev->resource[1].start; 580 + musb_resources[1].end = pdev->resource[1].end; 581 + musb_resources[1].flags = pdev->resource[1].flags; 582 + 583 + ret = platform_device_add_resources(musb, musb_resources, 584 + ARRAY_SIZE(musb_resources)); 573 585 if (ret) { 574 586 dev_err(&pdev->dev, "failed to add resources\n"); 575 587 goto err2;
+16 -2
drivers/usb/musb/tusb6010.c
··· 1156 1156 1157 1157 static int tusb_probe(struct platform_device *pdev) 1158 1158 { 1159 + struct resource musb_resources[2]; 1159 1160 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 1160 1161 struct platform_device *musb; 1161 1162 struct tusb6010_glue *glue; ··· 1186 1185 1187 1186 platform_set_drvdata(pdev, glue); 1188 1187 1189 - ret = platform_device_add_resources(musb, pdev->resource, 1190 - pdev->num_resources); 1188 + memset(musb_resources, 0x00, sizeof(*musb_resources) * 1189 + ARRAY_SIZE(musb_resources)); 1190 + 1191 + musb_resources[0].name = pdev->resource[0].name; 1192 + musb_resources[0].start = pdev->resource[0].start; 1193 + musb_resources[0].end = pdev->resource[0].end; 1194 + musb_resources[0].flags = pdev->resource[0].flags; 1195 + 1196 + musb_resources[1].name = pdev->resource[1].name; 1197 + musb_resources[1].start = pdev->resource[1].start; 1198 + musb_resources[1].end = pdev->resource[1].end; 1199 + musb_resources[1].flags = pdev->resource[1].flags; 1200 + 1201 + ret = platform_device_add_resources(musb, musb_resources, 1202 + ARRAY_SIZE(musb_resources)); 1191 1203 if (ret) { 1192 1204 dev_err(&pdev->dev, "failed to add resources\n"); 1193 1205 goto err3;
+16 -2
drivers/usb/musb/ux500.c
··· 189 189 190 190 static int ux500_probe(struct platform_device *pdev) 191 191 { 192 + struct resource musb_resources[2]; 192 193 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 193 194 struct platform_device *musb; 194 195 struct ux500_glue *glue; ··· 233 232 234 233 platform_set_drvdata(pdev, glue); 235 234 236 - ret = platform_device_add_resources(musb, pdev->resource, 237 - pdev->num_resources); 235 + memset(musb_resources, 0x00, sizeof(*musb_resources) * 236 + ARRAY_SIZE(musb_resources)); 237 + 238 + musb_resources[0].name = pdev->resource[0].name; 239 + musb_resources[0].start = pdev->resource[0].start; 240 + musb_resources[0].end = pdev->resource[0].end; 241 + musb_resources[0].flags = pdev->resource[0].flags; 242 + 243 + musb_resources[1].name = pdev->resource[1].name; 244 + musb_resources[1].start = pdev->resource[1].start; 245 + musb_resources[1].end = pdev->resource[1].end; 246 + musb_resources[1].flags = pdev->resource[1].flags; 247 + 248 + ret = platform_device_add_resources(musb, musb_resources, 249 + ARRAY_SIZE(musb_resources)); 238 250 if (ret) { 239 251 dev_err(&pdev->dev, "failed to add resources\n"); 240 252 goto err5;
+3 -3
drivers/usb/musb/ux500_dma.c
··· 71 71 spin_lock_irqsave(&musb->lock, flags); 72 72 ux500_channel->channel.actual_len = ux500_channel->cur_len; 73 73 ux500_channel->channel.status = MUSB_DMA_STATUS_FREE; 74 - musb_dma_completion(musb, hw_ep->epnum, 75 - ux500_channel->is_tx); 74 + musb_dma_completion(musb, hw_ep->epnum, ux500_channel->is_tx); 76 75 spin_unlock_irqrestore(&musb->lock, flags); 77 76 78 77 } ··· 365 366 kfree(controller); 366 367 } 367 368 368 - struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *base) 369 + struct dma_controller *dma_controller_create(struct musb *musb, 370 + void __iomem *base) 369 371 { 370 372 struct ux500_dma_controller *controller; 371 373 struct platform_device *pdev = to_platform_device(musb->controller);
+1 -1
drivers/usb/phy/Kconfig
··· 86 86 on/off the PHY. 87 87 88 88 config SAMSUNG_USBPHY 89 - tristate "Samsung USB PHY Driver" 89 + tristate 90 90 help 91 91 Enable this to support Samsung USB phy helper driver for Samsung SoCs. 92 92 This driver provides common interface to interact, for Samsung USB 2.0 PHY
+727 -121
drivers/usb/phy/phy-ab8500-usb.c
··· 1 1 /* 2 2 * drivers/usb/otg/ab8500_usb.c 3 3 * 4 - * USB transceiver driver for AB8500 chip 4 + * USB transceiver driver for AB8500 family chips 5 5 * 6 - * Copyright (C) 2010 ST-Ericsson AB 6 + * Copyright (C) 2010-2013 ST-Ericsson AB 7 7 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> 8 + * Avinash Kumar <avinash.kumar@stericsson.com> 9 + * Thirupathi Chippakurthy <thirupathi.chippakurthy@stericsson.com> 8 10 * 9 11 * This program is free software; you can redistribute it and/or modify 10 12 * it under the terms of the GNU General Public License as published by ··· 31 29 #include <linux/notifier.h> 32 30 #include <linux/interrupt.h> 33 31 #include <linux/delay.h> 32 + #include <linux/clk.h> 33 + #include <linux/err.h> 34 34 #include <linux/mfd/abx500.h> 35 35 #include <linux/mfd/abx500/ab8500.h> 36 36 #include <linux/usb/musb-ux500.h> ··· 45 41 /* Bank AB8500_USB */ 46 42 #define AB8500_USB_LINE_STAT_REG 0x80 47 43 #define AB8505_USB_LINE_STAT_REG 0x94 44 + #define AB8540_USB_LINK_STAT_REG 0x94 45 + #define AB9540_USB_LINK_STAT_REG 0x94 46 + #define AB8540_USB_OTG_CTL_REG 0x87 48 47 #define AB8500_USB_PHY_CTRL_REG 0x8A 48 + #define AB8540_VBUS_CTRL_REG 0x82 49 49 50 50 /* Bank AB8500_DEVELOPMENT */ 51 51 #define AB8500_BANK12_ACCESS 0x00 52 52 53 53 /* Bank AB8500_DEBUG */ 54 + #define AB8540_DEBUG 0x32 54 55 #define AB8500_USB_PHY_TUNE1 0x05 55 56 #define AB8500_USB_PHY_TUNE2 0x06 56 57 #define AB8500_USB_PHY_TUNE3 0x07 58 + 59 + /* Bank AB8500_INTERRUPT */ 60 + #define AB8500_IT_SOURCE2_REG 0x01 57 61 58 62 #define AB8500_BIT_OTG_STAT_ID (1 << 0) 59 63 #define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0) 60 64 #define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1) 61 65 #define AB8500_BIT_WD_CTRL_ENABLE (1 << 0) 62 66 #define AB8500_BIT_WD_CTRL_KICK (1 << 1) 67 + #define AB8500_BIT_SOURCE2_VBUSDET (1 << 7) 68 + #define AB8540_BIT_OTG_CTL_VBUS_VALID_ENA (1 << 0) 69 + #define AB8540_BIT_OTG_CTL_ID_HOST_ENA (1 << 1) 70 + #define AB8540_BIT_OTG_CTL_ID_DEV_ENA (1 << 5) 71 + #define AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA (1 << 0) 63 72 64 73 #define AB8500_WD_KICK_DELAY_US 100 /* usec */ 65 74 #define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */ ··· 129 112 USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8505, 130 113 }; 131 114 115 + enum ab8540_usb_link_status { 116 + USB_LINK_NOT_CONFIGURED_8540 = 0, 117 + USB_LINK_STD_HOST_NC_8540, 118 + USB_LINK_STD_HOST_C_NS_8540, 119 + USB_LINK_STD_HOST_C_S_8540, 120 + USB_LINK_CDP_8540, 121 + USB_LINK_RESERVED0_8540, 122 + USB_LINK_RESERVED1_8540, 123 + USB_LINK_DEDICATED_CHG_8540, 124 + USB_LINK_ACA_RID_A_8540, 125 + USB_LINK_ACA_RID_B_8540, 126 + USB_LINK_ACA_RID_C_NM_8540, 127 + USB_LINK_RESERVED2_8540, 128 + USB_LINK_RESERVED3_8540, 129 + USB_LINK_HM_IDGND_8540, 130 + USB_LINK_CHARGERPORT_NOT_OK_8540, 131 + USB_LINK_CHARGER_DM_HIGH_8540, 132 + USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540, 133 + USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_8540, 134 + USB_LINK_STD_UPSTREAM_8540, 135 + USB_LINK_CHARGER_SE1_8540, 136 + USB_LINK_CARKIT_CHGR_1_8540, 137 + USB_LINK_CARKIT_CHGR_2_8540, 138 + USB_LINK_ACA_DOCK_CHGR_8540, 139 + USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8540, 140 + USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8540, 141 + USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8540, 142 + USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8540, 143 + USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8540 144 + }; 145 + 146 + enum ab9540_usb_link_status { 147 + USB_LINK_NOT_CONFIGURED_9540 = 0, 148 + USB_LINK_STD_HOST_NC_9540, 149 + USB_LINK_STD_HOST_C_NS_9540, 150 + USB_LINK_STD_HOST_C_S_9540, 151 + USB_LINK_CDP_9540, 152 + USB_LINK_RESERVED0_9540, 153 + USB_LINK_RESERVED1_9540, 154 + USB_LINK_DEDICATED_CHG_9540, 155 + USB_LINK_ACA_RID_A_9540, 156 + USB_LINK_ACA_RID_B_9540, 157 + USB_LINK_ACA_RID_C_NM_9540, 158 + USB_LINK_RESERVED2_9540, 159 + USB_LINK_RESERVED3_9540, 160 + USB_LINK_HM_IDGND_9540, 161 + USB_LINK_CHARGERPORT_NOT_OK_9540, 162 + USB_LINK_CHARGER_DM_HIGH_9540, 163 + USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540, 164 + USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_9540, 165 + USB_LINK_STD_UPSTREAM_9540, 166 + USB_LINK_CHARGER_SE1_9540, 167 + USB_LINK_CARKIT_CHGR_1_9540, 168 + USB_LINK_CARKIT_CHGR_2_9540, 169 + USB_LINK_ACA_DOCK_CHGR_9540, 170 + USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_9540, 171 + USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_9540, 172 + USB_LINK_SAMSUNG_UART_CBL_PHY_EN_9540, 173 + USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_9540, 174 + USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_9540 175 + }; 176 + 132 177 enum ab8500_usb_mode { 133 178 USB_IDLE = 0, 134 179 USB_PERIPHERAL, ··· 198 119 USB_DEDICATED_CHG 199 120 }; 200 121 122 + /* Register USB_LINK_STATUS interrupt */ 123 + #define AB8500_USB_FLAG_USE_LINK_STATUS_IRQ (1 << 0) 124 + /* Register ID_WAKEUP_F interrupt */ 125 + #define AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ (1 << 1) 126 + /* Register VBUS_DET_F interrupt */ 127 + #define AB8500_USB_FLAG_USE_VBUS_DET_IRQ (1 << 2) 128 + /* Driver is using the ab-iddet driver*/ 129 + #define AB8500_USB_FLAG_USE_AB_IDDET (1 << 3) 130 + /* Enable setting regulators voltage */ 131 + #define AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE (1 << 4) 132 + /* Enable the check_vbus_status workaround */ 133 + #define AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS (1 << 5) 134 + /* Enable the vbus host workaround */ 135 + #define AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK (1 << 6) 136 + 201 137 struct ab8500_usb { 202 138 struct usb_phy phy; 203 139 struct device *dev; 204 140 struct ab8500 *ab8500; 205 141 unsigned vbus_draw; 206 142 struct work_struct phy_dis_work; 143 + struct work_struct vbus_event_work; 207 144 enum ab8500_usb_mode mode; 145 + struct clk *sysclk; 208 146 struct regulator *v_ape; 209 147 struct regulator *v_musb; 210 148 struct regulator *v_ulpi; ··· 229 133 int previous_link_status_state; 230 134 struct pinctrl *pinctrl; 231 135 struct pinctrl_state *pins_sleep; 136 + bool enabled_charging_detection; 137 + unsigned int flags; 232 138 }; 233 139 234 140 static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x) ··· 269 171 if (ret) 270 172 dev_err(ab->dev, "Failed to enable v-ape\n"); 271 173 272 - if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { 174 + if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) { 273 175 ab->saved_v_ulpi = regulator_get_voltage(ab->v_ulpi); 274 176 if (ab->saved_v_ulpi < 0) 275 177 dev_err(ab->dev, "Failed to get v_ulpi voltage\n"); ··· 289 191 if (ret) 290 192 dev_err(ab->dev, "Failed to enable vddulpivio18\n"); 291 193 292 - if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { 194 + if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) { 293 195 volt = regulator_get_voltage(ab->v_ulpi); 294 196 if ((volt != 1300000) && (volt != 1350000)) 295 197 dev_err(ab->dev, "Vintcore is not set to 1.3V volt=%d\n", ··· 310 212 regulator_disable(ab->v_ulpi); 311 213 312 214 /* USB is not the only consumer of Vintcore, restore old settings */ 313 - if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { 215 + if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) { 314 216 if (ab->saved_v_ulpi > 0) { 315 217 ret = regulator_set_voltage(ab->v_ulpi, 316 218 ab->saved_v_ulpi, ab->saved_v_ulpi); ··· 350 252 if (IS_ERR(ab->pinctrl)) 351 253 dev_err(ab->dev, "could not get/set default pinstate\n"); 352 254 255 + if (clk_prepare_enable(ab->sysclk)) 256 + dev_err(ab->dev, "can't prepare/enable clock\n"); 257 + 353 258 ab8500_usb_regulator_enable(ab); 354 259 355 260 abx500_mask_and_set_register_interruptible(ab->dev, 356 261 AB8500_USB, AB8500_USB_PHY_CTRL_REG, 357 262 bit, bit); 263 + 264 + if (ab->flags & AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK) { 265 + if (sel_host) 266 + abx500_set_register_interruptible(ab->dev, 267 + AB8500_USB, AB8540_USB_OTG_CTL_REG, 268 + AB8540_BIT_OTG_CTL_VBUS_VALID_ENA | 269 + AB8540_BIT_OTG_CTL_ID_HOST_ENA | 270 + AB8540_BIT_OTG_CTL_ID_DEV_ENA); 271 + } 358 272 } 359 273 360 274 static void ab8500_usb_phy_disable(struct ab8500_usb *ab, bool sel_host) ··· 384 274 /* Needed to disable the phy.*/ 385 275 ab8500_usb_wd_workaround(ab); 386 276 277 + clk_disable_unprepare(ab->sysclk); 278 + 387 279 ab8500_usb_regulator_disable(ab); 388 280 389 281 if (!IS_ERR(ab->pinctrl)) { ··· 398 286 else if (pinctrl_select_state(ab->pinctrl, ab->pins_sleep)) 399 287 dev_err(ab->dev, "could not set pins to sleep state\n"); 400 288 401 - /* as USB pins are shared with idddet, release them to allow 289 + /* 290 + * as USB pins are shared with iddet, release them to allow 402 291 * iddet to request them 403 292 */ 404 293 pinctrl_put(ab->pinctrl); ··· 410 297 #define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_disable(ab, true) 411 298 #define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_enable(ab, false) 412 299 #define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_disable(ab, false) 300 + 301 + static int ab9540_usb_link_status_update(struct ab8500_usb *ab, 302 + enum ab9540_usb_link_status lsts) 303 + { 304 + enum ux500_musb_vbus_id_status event = 0; 305 + 306 + dev_dbg(ab->dev, "ab9540_usb_link_status_update %d\n", lsts); 307 + 308 + if (ab->previous_link_status_state == USB_LINK_HM_IDGND_9540 && 309 + (lsts == USB_LINK_STD_HOST_C_NS_9540 || 310 + lsts == USB_LINK_STD_HOST_NC_9540)) 311 + return 0; 312 + 313 + if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_9540 && 314 + (lsts == USB_LINK_STD_HOST_NC_9540)) 315 + return 0; 316 + 317 + ab->previous_link_status_state = lsts; 318 + 319 + switch (lsts) { 320 + case USB_LINK_ACA_RID_B_9540: 321 + event = UX500_MUSB_RIDB; 322 + case USB_LINK_NOT_CONFIGURED_9540: 323 + case USB_LINK_RESERVED0_9540: 324 + case USB_LINK_RESERVED1_9540: 325 + case USB_LINK_RESERVED2_9540: 326 + case USB_LINK_RESERVED3_9540: 327 + if (ab->mode == USB_PERIPHERAL) 328 + atomic_notifier_call_chain(&ab->phy.notifier, 329 + UX500_MUSB_CLEAN, &ab->vbus_draw); 330 + ab->mode = USB_IDLE; 331 + ab->phy.otg->default_a = false; 332 + ab->vbus_draw = 0; 333 + if (event != UX500_MUSB_RIDB) 334 + event = UX500_MUSB_NONE; 335 + /* Fallback to default B_IDLE as nothing is connected. */ 336 + ab->phy.state = OTG_STATE_B_IDLE; 337 + break; 338 + 339 + case USB_LINK_ACA_RID_C_NM_9540: 340 + event = UX500_MUSB_RIDC; 341 + case USB_LINK_STD_HOST_NC_9540: 342 + case USB_LINK_STD_HOST_C_NS_9540: 343 + case USB_LINK_STD_HOST_C_S_9540: 344 + case USB_LINK_CDP_9540: 345 + if (ab->mode == USB_HOST) { 346 + ab->mode = USB_PERIPHERAL; 347 + ab8500_usb_host_phy_dis(ab); 348 + ab8500_usb_peri_phy_en(ab); 349 + atomic_notifier_call_chain(&ab->phy.notifier, 350 + UX500_MUSB_PREPARE, &ab->vbus_draw); 351 + } 352 + if (ab->mode == USB_IDLE) { 353 + ab->mode = USB_PERIPHERAL; 354 + ab8500_usb_peri_phy_en(ab); 355 + atomic_notifier_call_chain(&ab->phy.notifier, 356 + UX500_MUSB_PREPARE, &ab->vbus_draw); 357 + } 358 + if (event != UX500_MUSB_RIDC) 359 + event = UX500_MUSB_VBUS; 360 + break; 361 + 362 + case USB_LINK_ACA_RID_A_9540: 363 + event = UX500_MUSB_RIDA; 364 + case USB_LINK_HM_IDGND_9540: 365 + case USB_LINK_STD_UPSTREAM_9540: 366 + if (ab->mode == USB_PERIPHERAL) { 367 + ab->mode = USB_HOST; 368 + ab8500_usb_peri_phy_dis(ab); 369 + ab8500_usb_host_phy_en(ab); 370 + atomic_notifier_call_chain(&ab->phy.notifier, 371 + UX500_MUSB_PREPARE, &ab->vbus_draw); 372 + } 373 + if (ab->mode == USB_IDLE) { 374 + ab->mode = USB_HOST; 375 + ab8500_usb_host_phy_en(ab); 376 + atomic_notifier_call_chain(&ab->phy.notifier, 377 + UX500_MUSB_PREPARE, &ab->vbus_draw); 378 + } 379 + ab->phy.otg->default_a = true; 380 + if (event != UX500_MUSB_RIDA) 381 + event = UX500_MUSB_ID; 382 + 383 + atomic_notifier_call_chain(&ab->phy.notifier, 384 + event, &ab->vbus_draw); 385 + break; 386 + 387 + case USB_LINK_DEDICATED_CHG_9540: 388 + ab->mode = USB_DEDICATED_CHG; 389 + event = UX500_MUSB_CHARGER; 390 + atomic_notifier_call_chain(&ab->phy.notifier, 391 + event, &ab->vbus_draw); 392 + break; 393 + 394 + case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540: 395 + case USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_9540: 396 + if (!(is_ab9540_2p0_or_earlier(ab->ab8500))) { 397 + event = UX500_MUSB_NONE; 398 + if (ab->mode == USB_HOST) { 399 + ab->phy.otg->default_a = false; 400 + ab->vbus_draw = 0; 401 + atomic_notifier_call_chain(&ab->phy.notifier, 402 + event, &ab->vbus_draw); 403 + ab8500_usb_host_phy_dis(ab); 404 + ab->mode = USB_IDLE; 405 + } 406 + if (ab->mode == USB_PERIPHERAL) { 407 + atomic_notifier_call_chain(&ab->phy.notifier, 408 + event, &ab->vbus_draw); 409 + ab8500_usb_peri_phy_dis(ab); 410 + atomic_notifier_call_chain(&ab->phy.notifier, 411 + UX500_MUSB_CLEAN, 412 + &ab->vbus_draw); 413 + ab->mode = USB_IDLE; 414 + ab->phy.otg->default_a = false; 415 + ab->vbus_draw = 0; 416 + } 417 + } 418 + break; 419 + 420 + default: 421 + break; 422 + } 423 + 424 + return 0; 425 + } 426 + 427 + static int ab8540_usb_link_status_update(struct ab8500_usb *ab, 428 + enum ab8540_usb_link_status lsts) 429 + { 430 + enum ux500_musb_vbus_id_status event = 0; 431 + 432 + dev_dbg(ab->dev, "ab8540_usb_link_status_update %d\n", lsts); 433 + 434 + if (ab->enabled_charging_detection) { 435 + /* Disable USB Charger detection */ 436 + abx500_mask_and_set_register_interruptible(ab->dev, 437 + AB8500_USB, AB8540_VBUS_CTRL_REG, 438 + AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA, 0x00); 439 + ab->enabled_charging_detection = false; 440 + } 441 + 442 + /* 443 + * Spurious link_status interrupts are seen in case of a 444 + * disconnection of a device in IDGND and RIDA stage 445 + */ 446 + if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8540 && 447 + (lsts == USB_LINK_STD_HOST_C_NS_8540 || 448 + lsts == USB_LINK_STD_HOST_NC_8540)) 449 + return 0; 450 + 451 + if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8540 && 452 + (lsts == USB_LINK_STD_HOST_NC_8540)) 453 + return 0; 454 + 455 + ab->previous_link_status_state = lsts; 456 + 457 + switch (lsts) { 458 + case USB_LINK_ACA_RID_B_8540: 459 + event = UX500_MUSB_RIDB; 460 + case USB_LINK_NOT_CONFIGURED_8540: 461 + case USB_LINK_RESERVED0_8540: 462 + case USB_LINK_RESERVED1_8540: 463 + case USB_LINK_RESERVED2_8540: 464 + case USB_LINK_RESERVED3_8540: 465 + ab->mode = USB_IDLE; 466 + ab->phy.otg->default_a = false; 467 + ab->vbus_draw = 0; 468 + if (event != UX500_MUSB_RIDB) 469 + event = UX500_MUSB_NONE; 470 + /* 471 + * Fallback to default B_IDLE as nothing 472 + * is connected 473 + */ 474 + ab->phy.state = OTG_STATE_B_IDLE; 475 + break; 476 + 477 + case USB_LINK_ACA_RID_C_NM_8540: 478 + event = UX500_MUSB_RIDC; 479 + case USB_LINK_STD_HOST_NC_8540: 480 + case USB_LINK_STD_HOST_C_NS_8540: 481 + case USB_LINK_STD_HOST_C_S_8540: 482 + case USB_LINK_CDP_8540: 483 + if (ab->mode == USB_IDLE) { 484 + ab->mode = USB_PERIPHERAL; 485 + ab8500_usb_peri_phy_en(ab); 486 + atomic_notifier_call_chain(&ab->phy.notifier, 487 + UX500_MUSB_PREPARE, &ab->vbus_draw); 488 + } 489 + if (event != UX500_MUSB_RIDC) 490 + event = UX500_MUSB_VBUS; 491 + break; 492 + 493 + case USB_LINK_ACA_RID_A_8540: 494 + case USB_LINK_ACA_DOCK_CHGR_8540: 495 + event = UX500_MUSB_RIDA; 496 + case USB_LINK_HM_IDGND_8540: 497 + case USB_LINK_STD_UPSTREAM_8540: 498 + if (ab->mode == USB_IDLE) { 499 + ab->mode = USB_HOST; 500 + ab8500_usb_host_phy_en(ab); 501 + atomic_notifier_call_chain(&ab->phy.notifier, 502 + UX500_MUSB_PREPARE, &ab->vbus_draw); 503 + } 504 + ab->phy.otg->default_a = true; 505 + if (event != UX500_MUSB_RIDA) 506 + event = UX500_MUSB_ID; 507 + atomic_notifier_call_chain(&ab->phy.notifier, 508 + event, &ab->vbus_draw); 509 + break; 510 + 511 + case USB_LINK_DEDICATED_CHG_8540: 512 + ab->mode = USB_DEDICATED_CHG; 513 + event = UX500_MUSB_CHARGER; 514 + atomic_notifier_call_chain(&ab->phy.notifier, 515 + event, &ab->vbus_draw); 516 + break; 517 + 518 + case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540: 519 + case USB_LINK_STD_UPSTREAM_NO_IDGNG_VBUS_8540: 520 + event = UX500_MUSB_NONE; 521 + if (ab->mode == USB_HOST) { 522 + ab->phy.otg->default_a = false; 523 + ab->vbus_draw = 0; 524 + atomic_notifier_call_chain(&ab->phy.notifier, 525 + event, &ab->vbus_draw); 526 + ab8500_usb_host_phy_dis(ab); 527 + ab->mode = USB_IDLE; 528 + } 529 + if (ab->mode == USB_PERIPHERAL) { 530 + atomic_notifier_call_chain(&ab->phy.notifier, 531 + event, &ab->vbus_draw); 532 + ab8500_usb_peri_phy_dis(ab); 533 + atomic_notifier_call_chain(&ab->phy.notifier, 534 + UX500_MUSB_CLEAN, &ab->vbus_draw); 535 + ab->mode = USB_IDLE; 536 + ab->phy.otg->default_a = false; 537 + ab->vbus_draw = 0; 538 + } 539 + break; 540 + 541 + default: 542 + event = UX500_MUSB_NONE; 543 + break; 544 + } 545 + 546 + return 0; 547 + } 413 548 414 549 static int ab8505_usb_link_status_update(struct ab8500_usb *ab, 415 550 enum ab8505_usb_link_status lsts) ··· 859 498 AB8500_USB, AB8505_USB_LINE_STAT_REG, &reg); 860 499 lsts = (reg >> 3) & 0x1F; 861 500 ret = ab8505_usb_link_status_update(ab, lsts); 501 + } else if (is_ab8540(ab->ab8500)) { 502 + enum ab8540_usb_link_status lsts; 503 + 504 + abx500_get_register_interruptible(ab->dev, 505 + AB8500_USB, AB8540_USB_LINK_STAT_REG, &reg); 506 + lsts = (reg >> 3) & 0xFF; 507 + ret = ab8540_usb_link_status_update(ab, lsts); 508 + } else if (is_ab9540(ab->ab8500)) { 509 + enum ab9540_usb_link_status lsts; 510 + 511 + abx500_get_register_interruptible(ab->dev, 512 + AB8500_USB, AB9540_USB_LINK_STAT_REG, &reg); 513 + lsts = (reg >> 3) & 0xFF; 514 + ret = ab9540_usb_link_status_update(ab, lsts); 862 515 } 863 516 864 517 return ret; ··· 928 553 929 554 static irqreturn_t ab8500_usb_link_status_irq(int irq, void *data) 930 555 { 931 - struct ab8500_usb *ab = (struct ab8500_usb *) data; 556 + struct ab8500_usb *ab = (struct ab8500_usb *)data; 932 557 933 558 abx500_usb_link_status_update(ab); 934 559 ··· 945 570 946 571 if (!ab->phy.otg->gadget) 947 572 ab8500_usb_peri_phy_dis(ab); 573 + } 574 + 575 + /* Check if VBUS is set and linkstatus has not detected a cable. */ 576 + static bool ab8500_usb_check_vbus_status(struct ab8500_usb *ab) 577 + { 578 + u8 isource2; 579 + u8 reg; 580 + enum ab8540_usb_link_status lsts; 581 + 582 + abx500_get_register_interruptible(ab->dev, 583 + AB8500_INTERRUPT, AB8500_IT_SOURCE2_REG, 584 + &isource2); 585 + 586 + /* If Vbus is below 3.6V abort */ 587 + if (!(isource2 & AB8500_BIT_SOURCE2_VBUSDET)) 588 + return false; 589 + 590 + abx500_get_register_interruptible(ab->dev, 591 + AB8500_USB, AB8540_USB_LINK_STAT_REG, 592 + &reg); 593 + 594 + lsts = (reg >> 3) & 0xFF; 595 + 596 + /* Check if linkstatus has detected a cable */ 597 + if (lsts) 598 + return false; 599 + 600 + return true; 601 + } 602 + 603 + /* re-trigger charger detection again with watchdog re-kick. */ 604 + static void ab8500_usb_vbus_turn_on_event_work(struct work_struct *work) 605 + { 606 + struct ab8500_usb *ab = container_of(work, struct ab8500_usb, 607 + vbus_event_work); 608 + 609 + if (ab->mode != USB_IDLE) 610 + return; 611 + 612 + abx500_set_register_interruptible(ab->dev, 613 + AB8500_SYS_CTRL2_BLOCK, AB8500_MAIN_WD_CTRL_REG, 614 + AB8500_BIT_WD_CTRL_ENABLE); 615 + 616 + udelay(100); 617 + 618 + abx500_set_register_interruptible(ab->dev, 619 + AB8500_SYS_CTRL2_BLOCK, AB8500_MAIN_WD_CTRL_REG, 620 + AB8500_BIT_WD_CTRL_ENABLE | AB8500_BIT_WD_CTRL_KICK); 621 + 622 + udelay(100); 623 + 624 + /* Disable Main watchdog */ 625 + abx500_set_register_interruptible(ab->dev, 626 + AB8500_SYS_CTRL2_BLOCK, AB8500_MAIN_WD_CTRL_REG, 627 + 0x0); 628 + 629 + /* Enable USB Charger detection */ 630 + abx500_mask_and_set_register_interruptible(ab->dev, 631 + AB8500_USB, AB8540_VBUS_CTRL_REG, 632 + AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA, 633 + AB8540_BIT_VBUS_CTRL_CHARG_DET_ENA); 634 + 635 + ab->enabled_charging_detection = true; 948 636 } 949 637 950 638 static unsigned ab8500_eyediagram_workaroud(struct ab8500_usb *ab, unsigned mA) ··· 1065 627 * is fixed. 1066 628 */ 1067 629 1068 - if ((ab->mode != USB_IDLE) && (!gadget)) { 630 + if ((ab->mode != USB_IDLE) && !gadget) { 1069 631 ab->mode = USB_IDLE; 1070 632 schedule_work(&ab->phy_dis_work); 1071 633 } ··· 1089 651 * is fixed. 1090 652 */ 1091 653 1092 - if ((ab->mode != USB_IDLE) && (!host)) { 654 + if ((ab->mode != USB_IDLE) && !host) { 1093 655 ab->mode = USB_IDLE; 1094 656 schedule_work(&ab->phy_dis_work); 1095 657 } 1096 658 1097 659 return 0; 660 + } 661 + 662 + static void ab8500_usb_restart_phy(struct ab8500_usb *ab) 663 + { 664 + abx500_mask_and_set_register_interruptible(ab->dev, 665 + AB8500_USB, AB8500_USB_PHY_CTRL_REG, 666 + AB8500_BIT_PHY_CTRL_DEVICE_EN, 667 + AB8500_BIT_PHY_CTRL_DEVICE_EN); 668 + 669 + udelay(100); 670 + 671 + abx500_mask_and_set_register_interruptible(ab->dev, 672 + AB8500_USB, AB8500_USB_PHY_CTRL_REG, 673 + AB8500_BIT_PHY_CTRL_DEVICE_EN, 674 + 0); 675 + 676 + abx500_mask_and_set_register_interruptible(ab->dev, 677 + AB8500_USB, AB8500_USB_PHY_CTRL_REG, 678 + AB8500_BIT_PHY_CTRL_HOST_EN, 679 + AB8500_BIT_PHY_CTRL_HOST_EN); 680 + 681 + udelay(100); 682 + 683 + abx500_mask_and_set_register_interruptible(ab->dev, 684 + AB8500_USB, AB8500_USB_PHY_CTRL_REG, 685 + AB8500_BIT_PHY_CTRL_HOST_EN, 686 + 0); 1098 687 } 1099 688 1100 689 static int ab8500_usb_regulator_get(struct ab8500_usb *ab) ··· 1158 693 int err; 1159 694 int irq; 1160 695 1161 - irq = platform_get_irq_byname(pdev, "USB_LINK_STATUS"); 1162 - if (irq < 0) { 1163 - dev_err(&pdev->dev, "Link status irq not found\n"); 1164 - return irq; 1165 - } 1166 - err = devm_request_threaded_irq(&pdev->dev, irq, NULL, 1167 - ab8500_usb_link_status_irq, 1168 - IRQF_NO_SUSPEND | IRQF_SHARED, "usb-link-status", ab); 1169 - if (err < 0) { 1170 - dev_err(ab->dev, "request_irq failed for link status irq\n"); 1171 - return err; 1172 - } 1173 - 1174 - irq = platform_get_irq_byname(pdev, "ID_WAKEUP_F"); 1175 - if (irq < 0) { 1176 - dev_err(&pdev->dev, "ID fall irq not found\n"); 1177 - return irq; 1178 - } 1179 - err = devm_request_threaded_irq(&pdev->dev, irq, NULL, 1180 - ab8500_usb_disconnect_irq, 1181 - IRQF_NO_SUSPEND | IRQF_SHARED, "usb-id-fall", ab); 1182 - if (err < 0) { 1183 - dev_err(ab->dev, "request_irq failed for ID fall irq\n"); 1184 - return err; 696 + if (ab->flags & AB8500_USB_FLAG_USE_LINK_STATUS_IRQ) { 697 + irq = platform_get_irq_byname(pdev, "USB_LINK_STATUS"); 698 + if (irq < 0) { 699 + dev_err(&pdev->dev, "Link status irq not found\n"); 700 + return irq; 701 + } 702 + err = devm_request_threaded_irq(&pdev->dev, irq, NULL, 703 + ab8500_usb_link_status_irq, 704 + IRQF_NO_SUSPEND | IRQF_SHARED, 705 + "usb-link-status", ab); 706 + if (err < 0) { 707 + dev_err(ab->dev, "request_irq failed for link status irq\n"); 708 + return err; 709 + } 1185 710 } 1186 711 1187 - irq = platform_get_irq_byname(pdev, "VBUS_DET_F"); 1188 - if (irq < 0) { 1189 - dev_err(&pdev->dev, "VBUS fall irq not found\n"); 1190 - return irq; 712 + if (ab->flags & AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ) { 713 + irq = platform_get_irq_byname(pdev, "ID_WAKEUP_F"); 714 + if (irq < 0) { 715 + dev_err(&pdev->dev, "ID fall irq not found\n"); 716 + return irq; 717 + } 718 + err = devm_request_threaded_irq(&pdev->dev, irq, NULL, 719 + ab8500_usb_disconnect_irq, 720 + IRQF_NO_SUSPEND | IRQF_SHARED, 721 + "usb-id-fall", ab); 722 + if (err < 0) { 723 + dev_err(ab->dev, "request_irq failed for ID fall irq\n"); 724 + return err; 725 + } 1191 726 } 1192 - err = devm_request_threaded_irq(&pdev->dev, irq, NULL, 1193 - ab8500_usb_disconnect_irq, 1194 - IRQF_NO_SUSPEND | IRQF_SHARED, "usb-vbus-fall", ab); 1195 - if (err < 0) { 1196 - dev_err(ab->dev, "request_irq failed for Vbus fall irq\n"); 1197 - return err; 727 + 728 + if (ab->flags & AB8500_USB_FLAG_USE_VBUS_DET_IRQ) { 729 + irq = platform_get_irq_byname(pdev, "VBUS_DET_F"); 730 + if (irq < 0) { 731 + dev_err(&pdev->dev, "VBUS fall irq not found\n"); 732 + return irq; 733 + } 734 + err = devm_request_threaded_irq(&pdev->dev, irq, NULL, 735 + ab8500_usb_disconnect_irq, 736 + IRQF_NO_SUSPEND | IRQF_SHARED, 737 + "usb-vbus-fall", ab); 738 + if (err < 0) { 739 + dev_err(ab->dev, "request_irq failed for Vbus fall irq\n"); 740 + return err; 741 + } 1198 742 } 1199 743 1200 744 return 0; 745 + } 746 + 747 + static void ab8500_usb_set_ab8500_tuning_values(struct ab8500_usb *ab) 748 + { 749 + int err; 750 + 751 + /* Enable the PBT/Bank 0x12 access */ 752 + err = abx500_set_register_interruptible(ab->dev, 753 + AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01); 754 + if (err < 0) 755 + dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", 756 + err); 757 + 758 + err = abx500_set_register_interruptible(ab->dev, 759 + AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 0xC8); 760 + if (err < 0) 761 + dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", 762 + err); 763 + 764 + err = abx500_set_register_interruptible(ab->dev, 765 + AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 0x00); 766 + if (err < 0) 767 + dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", 768 + err); 769 + 770 + err = abx500_set_register_interruptible(ab->dev, 771 + AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x78); 772 + if (err < 0) 773 + dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", 774 + err); 775 + 776 + /* Switch to normal mode/disable Bank 0x12 access */ 777 + err = abx500_set_register_interruptible(ab->dev, 778 + AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x00); 779 + if (err < 0) 780 + dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", 781 + err); 782 + } 783 + 784 + static void ab8500_usb_set_ab8505_tuning_values(struct ab8500_usb *ab) 785 + { 786 + int err; 787 + 788 + /* Enable the PBT/Bank 0x12 access */ 789 + err = abx500_mask_and_set_register_interruptible(ab->dev, 790 + AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 791 + 0x01, 0x01); 792 + if (err < 0) 793 + dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", 794 + err); 795 + 796 + err = abx500_mask_and_set_register_interruptible(ab->dev, 797 + AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 798 + 0xC8, 0xC8); 799 + if (err < 0) 800 + dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", 801 + err); 802 + 803 + err = abx500_mask_and_set_register_interruptible(ab->dev, 804 + AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 805 + 0x60, 0x60); 806 + if (err < 0) 807 + dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", 808 + err); 809 + 810 + err = abx500_mask_and_set_register_interruptible(ab->dev, 811 + AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 812 + 0xFC, 0x80); 813 + 814 + if (err < 0) 815 + dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", 816 + err); 817 + 818 + /* Switch to normal mode/disable Bank 0x12 access */ 819 + err = abx500_mask_and_set_register_interruptible(ab->dev, 820 + AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 821 + 0x00, 0x00); 822 + if (err < 0) 823 + dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", 824 + err); 825 + } 826 + 827 + static void ab8500_usb_set_ab8540_tuning_values(struct ab8500_usb *ab) 828 + { 829 + int err; 830 + 831 + err = abx500_set_register_interruptible(ab->dev, 832 + AB8540_DEBUG, AB8500_USB_PHY_TUNE1, 0xCC); 833 + if (err < 0) 834 + dev_err(ab->dev, "Failed to set PHY_TUNE1 register ret=%d\n", 835 + err); 836 + 837 + err = abx500_set_register_interruptible(ab->dev, 838 + AB8540_DEBUG, AB8500_USB_PHY_TUNE2, 0x60); 839 + if (err < 0) 840 + dev_err(ab->dev, "Failed to set PHY_TUNE2 register ret=%d\n", 841 + err); 842 + 843 + err = abx500_set_register_interruptible(ab->dev, 844 + AB8540_DEBUG, AB8500_USB_PHY_TUNE3, 0x90); 845 + if (err < 0) 846 + dev_err(ab->dev, "Failed to set PHY_TUNE3 regester ret=%d\n", 847 + err); 848 + } 849 + 850 + static void ab8500_usb_set_ab9540_tuning_values(struct ab8500_usb *ab) 851 + { 852 + int err; 853 + 854 + /* Enable the PBT/Bank 0x12 access */ 855 + err = abx500_set_register_interruptible(ab->dev, 856 + AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01); 857 + if (err < 0) 858 + dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", 859 + err); 860 + 861 + err = abx500_set_register_interruptible(ab->dev, 862 + AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 0xC8); 863 + if (err < 0) 864 + dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", 865 + err); 866 + 867 + err = abx500_set_register_interruptible(ab->dev, 868 + AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 0x60); 869 + if (err < 0) 870 + dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", 871 + err); 872 + 873 + err = abx500_set_register_interruptible(ab->dev, 874 + AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x80); 875 + if (err < 0) 876 + dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", 877 + err); 878 + 879 + /* Switch to normal mode/disable Bank 0x12 access */ 880 + err = abx500_set_register_interruptible(ab->dev, 881 + AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x00); 882 + if (err < 0) 883 + dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", 884 + err); 1201 885 } 1202 886 1203 887 static int ab8500_usb_probe(struct platform_device *pdev) ··· 1386 772 otg->set_host = ab8500_usb_set_host; 1387 773 otg->set_peripheral = ab8500_usb_set_peripheral; 1388 774 775 + if (is_ab8500(ab->ab8500)) { 776 + ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ | 777 + AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ | 778 + AB8500_USB_FLAG_USE_VBUS_DET_IRQ | 779 + AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE; 780 + } else if (is_ab8505(ab->ab8500)) { 781 + ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ | 782 + AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ | 783 + AB8500_USB_FLAG_USE_VBUS_DET_IRQ | 784 + AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE; 785 + } else if (is_ab8540(ab->ab8500)) { 786 + ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ | 787 + AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS | 788 + AB8500_USB_FLAG_USE_VBUS_HOST_QUIRK | 789 + AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE; 790 + } else if (is_ab9540(ab->ab8500)) { 791 + ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ | 792 + AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE; 793 + if (is_ab9540_2p0_or_earlier(ab->ab8500)) 794 + ab->flags |= AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ | 795 + AB8500_USB_FLAG_USE_VBUS_DET_IRQ; 796 + } 797 + 798 + /* Disable regulator voltage setting for AB8500 <= v2.0 */ 799 + if (is_ab8500_2p0_or_earlier(ab->ab8500)) 800 + ab->flags &= ~AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE; 801 + 1389 802 platform_set_drvdata(pdev, ab); 1390 803 1391 804 ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier); ··· 1420 779 /* all: Disable phy when called from set_host and set_peripheral */ 1421 780 INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work); 1422 781 782 + INIT_WORK(&ab->vbus_event_work, ab8500_usb_vbus_turn_on_event_work); 783 + 1423 784 err = ab8500_usb_regulator_get(ab); 1424 785 if (err) 1425 786 return err; 787 + 788 + ab->sysclk = devm_clk_get(ab->dev, "sysclk"); 789 + if (IS_ERR(ab->sysclk)) { 790 + dev_err(ab->dev, "Could not get sysclk.\n"); 791 + return PTR_ERR(ab->sysclk); 792 + } 1426 793 1427 794 err = ab8500_usb_irq_setup(pdev, ab); 1428 795 if (err < 0) ··· 1442 793 return err; 1443 794 } 1444 795 1445 - /* Phy tuning values for AB8500 */ 1446 - if (!is_ab8500_2p0_or_earlier(ab->ab8500)) { 1447 - /* Enable the PBT/Bank 0x12 access */ 1448 - err = abx500_set_register_interruptible(ab->dev, 1449 - AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01); 1450 - if (err < 0) 1451 - dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", 1452 - err); 1453 - 1454 - err = abx500_set_register_interruptible(ab->dev, 1455 - AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 0xC8); 1456 - if (err < 0) 1457 - dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", 1458 - err); 1459 - 1460 - err = abx500_set_register_interruptible(ab->dev, 1461 - AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 0x00); 1462 - if (err < 0) 1463 - dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", 1464 - err); 1465 - 1466 - err = abx500_set_register_interruptible(ab->dev, 1467 - AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x78); 1468 - if (err < 0) 1469 - dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", 1470 - err); 1471 - 1472 - /* Switch to normal mode/disable Bank 0x12 access */ 1473 - err = abx500_set_register_interruptible(ab->dev, 1474 - AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x00); 1475 - if (err < 0) 1476 - dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", 1477 - err); 1478 - } 1479 - 1480 - /* Phy tuning values for AB8505 */ 1481 - if (is_ab8505(ab->ab8500)) { 1482 - /* Enable the PBT/Bank 0x12 access */ 1483 - err = abx500_mask_and_set_register_interruptible(ab->dev, 1484 - AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 1485 - 0x01, 0x01); 1486 - if (err < 0) 1487 - dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", 1488 - err); 1489 - 1490 - err = abx500_mask_and_set_register_interruptible(ab->dev, 1491 - AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 1492 - 0xC8, 0xC8); 1493 - if (err < 0) 1494 - dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", 1495 - err); 1496 - 1497 - err = abx500_mask_and_set_register_interruptible(ab->dev, 1498 - AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 1499 - 0x60, 0x60); 1500 - if (err < 0) 1501 - dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", 1502 - err); 1503 - 1504 - err = abx500_mask_and_set_register_interruptible(ab->dev, 1505 - AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 1506 - 0xFC, 0x80); 1507 - 1508 - if (err < 0) 1509 - dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n", 1510 - err); 1511 - 1512 - /* Switch to normal mode/disable Bank 0x12 access */ 1513 - err = abx500_mask_and_set_register_interruptible(ab->dev, 1514 - AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 1515 - 0x00, 0x00); 1516 - if (err < 0) 1517 - dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", 1518 - err); 1519 - } 796 + if (is_ab8500(ab->ab8500) && !is_ab8500_2p0_or_earlier(ab->ab8500)) 797 + /* Phy tuning values for AB8500 > v2.0 */ 798 + ab8500_usb_set_ab8500_tuning_values(ab); 799 + else if (is_ab8505(ab->ab8500)) 800 + /* Phy tuning values for AB8505 */ 801 + ab8500_usb_set_ab8505_tuning_values(ab); 802 + else if (is_ab8540(ab->ab8500)) 803 + /* Phy tuning values for AB8540 */ 804 + ab8500_usb_set_ab8540_tuning_values(ab); 805 + else if (is_ab9540(ab->ab8500)) 806 + /* Phy tuning values for AB9540 */ 807 + ab8500_usb_set_ab9540_tuning_values(ab); 1520 808 1521 809 /* Needed to enable ID detection. */ 1522 810 ab8500_usb_wd_workaround(ab); 811 + 812 + /* 813 + * This is required for usb-link-status to work properly when a 814 + * cable is connected at boot time. 815 + */ 816 + ab8500_usb_restart_phy(ab); 817 + 818 + if (ab->flags & AB8500_USB_FLAG_USE_CHECK_VBUS_STATUS) { 819 + if (ab8500_usb_check_vbus_status(ab)) 820 + schedule_work(&ab->vbus_event_work); 821 + } 1523 822 1524 823 abx500_usb_link_status_update(ab); 1525 824 ··· 1481 884 struct ab8500_usb *ab = platform_get_drvdata(pdev); 1482 885 1483 886 cancel_work_sync(&ab->phy_dis_work); 887 + cancel_work_sync(&ab->vbus_event_work); 1484 888 1485 889 usb_remove_phy(&ab->phy); 1486 890 ··· 1493 895 return 0; 1494 896 } 1495 897 898 + static struct platform_device_id ab8500_usb_devtype[] = { 899 + { .name = "ab8500-usb", }, 900 + { .name = "ab8540-usb", }, 901 + { .name = "ab9540-usb", }, 902 + { /* sentinel */ } 903 + }; 904 + MODULE_DEVICE_TABLE(platform, ab8500_usb_devtype); 905 + 1496 906 static struct platform_driver ab8500_usb_driver = { 1497 907 .probe = ab8500_usb_probe, 1498 908 .remove = ab8500_usb_remove, 909 + .id_table = ab8500_usb_devtype, 1499 910 .driver = { 1500 - .name = "ab8500-usb", 911 + .name = "abx5x0-usb", 1501 912 .owner = THIS_MODULE, 1502 913 }, 1503 914 }; ··· 1523 916 } 1524 917 module_exit(ab8500_usb_exit); 1525 918 1526 - MODULE_ALIAS("platform:ab8500_usb"); 1527 919 MODULE_AUTHOR("ST-Ericsson AB"); 1528 - MODULE_DESCRIPTION("AB8500 usb transceiver driver"); 920 + MODULE_DESCRIPTION("AB8500 family usb transceiver driver"); 1529 921 MODULE_LICENSE("GPL");
+6 -1
drivers/usb/phy/phy-omap-usb3.c
··· 27 27 #include <linux/delay.h> 28 28 #include <linux/usb/omap_control_usb.h> 29 29 30 - #define NUM_SYS_CLKS 5 30 + #define NUM_SYS_CLKS 6 31 31 #define PLL_STATUS 0x00000004 32 32 #define PLL_GO 0x00000008 33 33 #define PLL_CONFIGURATION1 0x0000000C ··· 62 62 CLK_RATE_12MHZ, 63 63 CLK_RATE_16MHZ, 64 64 CLK_RATE_19MHZ, 65 + CLK_RATE_20MHZ, 65 66 CLK_RATE_26MHZ, 66 67 CLK_RATE_38MHZ 67 68 }; ··· 73 72 {1172, 8, 4, 20, 65537}, /* 19.2 MHz */ 74 73 {1250, 12, 4, 20, 0}, /* 26 MHz */ 75 74 {3125, 47, 4, 20, 92843}, /* 38.4 MHz */ 75 + {1000, 7, 4, 10, 0}, /* 20 MHz */ 76 + 76 77 }; 77 78 78 79 static int omap_usb3_suspend(struct usb_phy *x, int suspend) ··· 125 122 return CLK_RATE_16MHZ; 126 123 case 19200000: 127 124 return CLK_RATE_19MHZ; 125 + case 20000000: 126 + return CLK_RATE_20MHZ; 128 127 case 26000000: 129 128 return CLK_RATE_26MHZ; 130 129 case 38400000:
+82 -77
drivers/usb/phy/phy-samsung-usb.c
··· 73 73 * Here 'on = true' would mean USB PHY block is isolated, hence 74 74 * de-activated and vice-versa. 75 75 */ 76 - void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on) 76 + void samsung_usbphy_set_isolation_4210(struct samsung_usbphy *sphy, bool on) 77 77 { 78 78 void __iomem *reg = NULL; 79 79 u32 reg_val; ··· 84 84 return; 85 85 } 86 86 87 - switch (sphy->drv_data->cpu_type) { 88 - case TYPE_S3C64XX: 89 - /* 90 - * Do nothing: We will add here once S3C64xx goes for DT support 91 - */ 92 - break; 93 - case TYPE_EXYNOS4210: 94 - /* 95 - * Fall through since exynos4210 and exynos5250 have similar 96 - * register architecture: two separate registers for host and 97 - * device phy control with enable bit at position 0. 98 - */ 99 - case TYPE_EXYNOS5250: 100 - if (sphy->phy_type == USB_PHY_TYPE_DEVICE) { 101 - reg = sphy->pmuregs + 102 - sphy->drv_data->devphy_reg_offset; 103 - en_mask = sphy->drv_data->devphy_en_mask; 104 - } else if (sphy->phy_type == USB_PHY_TYPE_HOST) { 105 - reg = sphy->pmuregs + 106 - sphy->drv_data->hostphy_reg_offset; 107 - en_mask = sphy->drv_data->hostphy_en_mask; 108 - } 109 - break; 110 - default: 111 - dev_err(sphy->dev, "Invalid SoC type\n"); 112 - return; 87 + if (sphy->phy_type == USB_PHY_TYPE_DEVICE) { 88 + reg = sphy->pmuregs + sphy->drv_data->devphy_reg_offset; 89 + en_mask = sphy->drv_data->devphy_en_mask; 90 + } else if (sphy->phy_type == USB_PHY_TYPE_HOST) { 91 + reg = sphy->pmuregs + sphy->drv_data->hostphy_reg_offset; 92 + en_mask = sphy->drv_data->hostphy_en_mask; 113 93 } 114 94 115 95 reg_val = readl(reg); ··· 100 120 reg_val |= en_mask; 101 121 102 122 writel(reg_val, reg); 123 + 124 + if (sphy->drv_data->cpu_type == TYPE_EXYNOS4X12) { 125 + writel(reg_val, sphy->pmuregs + EXYNOS4X12_PHY_HSIC_CTRL0); 126 + writel(reg_val, sphy->pmuregs + EXYNOS4X12_PHY_HSIC_CTRL1); 127 + } 103 128 } 104 - EXPORT_SYMBOL_GPL(samsung_usbphy_set_isolation); 129 + EXPORT_SYMBOL_GPL(samsung_usbphy_set_isolation_4210); 105 130 106 131 /* 107 132 * Configure the mode of working of usb-phy here: HOST/DEVICE. ··· 147 162 } 148 163 EXPORT_SYMBOL_GPL(samsung_usbphy_set_type); 149 164 165 + int samsung_usbphy_rate_to_clksel_64xx(struct samsung_usbphy *sphy, 166 + unsigned long rate) 167 + { 168 + unsigned int clksel; 169 + 170 + switch (rate) { 171 + case 12 * MHZ: 172 + clksel = PHYCLK_CLKSEL_12M; 173 + break; 174 + case 24 * MHZ: 175 + clksel = PHYCLK_CLKSEL_24M; 176 + break; 177 + case 48 * MHZ: 178 + clksel = PHYCLK_CLKSEL_48M; 179 + break; 180 + default: 181 + dev_err(sphy->dev, 182 + "Invalid reference clock frequency: %lu\n", rate); 183 + return -EINVAL; 184 + } 185 + 186 + return clksel; 187 + } 188 + EXPORT_SYMBOL_GPL(samsung_usbphy_rate_to_clksel_64xx); 189 + 190 + int samsung_usbphy_rate_to_clksel_4x12(struct samsung_usbphy *sphy, 191 + unsigned long rate) 192 + { 193 + unsigned int clksel; 194 + 195 + switch (rate) { 196 + case 9600 * KHZ: 197 + clksel = FSEL_CLKSEL_9600K; 198 + break; 199 + case 10 * MHZ: 200 + clksel = FSEL_CLKSEL_10M; 201 + break; 202 + case 12 * MHZ: 203 + clksel = FSEL_CLKSEL_12M; 204 + break; 205 + case 19200 * KHZ: 206 + clksel = FSEL_CLKSEL_19200K; 207 + break; 208 + case 20 * MHZ: 209 + clksel = FSEL_CLKSEL_20M; 210 + break; 211 + case 24 * MHZ: 212 + clksel = FSEL_CLKSEL_24M; 213 + break; 214 + case 50 * MHZ: 215 + clksel = FSEL_CLKSEL_50M; 216 + break; 217 + default: 218 + dev_err(sphy->dev, 219 + "Invalid reference clock frequency: %lu\n", rate); 220 + return -EINVAL; 221 + } 222 + 223 + return clksel; 224 + } 225 + EXPORT_SYMBOL_GPL(samsung_usbphy_rate_to_clksel_4x12); 226 + 150 227 /* 151 228 * Returns reference clock frequency selection value 152 229 */ 153 230 int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy) 154 231 { 155 232 struct clk *ref_clk; 156 - int refclk_freq = 0; 233 + unsigned long rate; 234 + int refclk_freq; 157 235 158 236 /* 159 237 * In exynos5250 USB host and device PHY use 160 238 * external crystal clock XXTI 161 239 */ 162 240 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) 163 - ref_clk = devm_clk_get(sphy->dev, "ext_xtal"); 241 + ref_clk = clk_get(sphy->dev, "ext_xtal"); 164 242 else 165 - ref_clk = devm_clk_get(sphy->dev, "xusbxti"); 243 + ref_clk = clk_get(sphy->dev, "xusbxti"); 166 244 if (IS_ERR(ref_clk)) { 167 245 dev_err(sphy->dev, "Failed to get reference clock\n"); 168 246 return PTR_ERR(ref_clk); 169 247 } 170 248 171 - if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) { 172 - /* set clock frequency for PLL */ 173 - switch (clk_get_rate(ref_clk)) { 174 - case 9600 * KHZ: 175 - refclk_freq = FSEL_CLKSEL_9600K; 176 - break; 177 - case 10 * MHZ: 178 - refclk_freq = FSEL_CLKSEL_10M; 179 - break; 180 - case 12 * MHZ: 181 - refclk_freq = FSEL_CLKSEL_12M; 182 - break; 183 - case 19200 * KHZ: 184 - refclk_freq = FSEL_CLKSEL_19200K; 185 - break; 186 - case 20 * MHZ: 187 - refclk_freq = FSEL_CLKSEL_20M; 188 - break; 189 - case 50 * MHZ: 190 - refclk_freq = FSEL_CLKSEL_50M; 191 - break; 192 - case 24 * MHZ: 193 - default: 194 - /* default reference clock */ 195 - refclk_freq = FSEL_CLKSEL_24M; 196 - break; 197 - } 198 - } else { 199 - switch (clk_get_rate(ref_clk)) { 200 - case 12 * MHZ: 201 - refclk_freq = PHYCLK_CLKSEL_12M; 202 - break; 203 - case 24 * MHZ: 204 - refclk_freq = PHYCLK_CLKSEL_24M; 205 - break; 206 - case 48 * MHZ: 207 - refclk_freq = PHYCLK_CLKSEL_48M; 208 - break; 209 - default: 210 - if (sphy->drv_data->cpu_type == TYPE_S3C64XX) 211 - refclk_freq = PHYCLK_CLKSEL_48M; 212 - else 213 - refclk_freq = PHYCLK_CLKSEL_24M; 214 - break; 215 - } 216 - } 249 + rate = clk_get_rate(ref_clk); 250 + refclk_freq = sphy->drv_data->rate_to_clksel(sphy, rate); 251 + 217 252 clk_put(ref_clk); 218 253 219 254 return refclk_freq;
+23 -1
drivers/usb/phy/phy-samsung-usb.h
··· 47 47 #define RSTCON_HLINK_SWRST (0x1 << 1) 48 48 #define RSTCON_SWRST (0x1 << 0) 49 49 50 + /* EXYNOS4X12 */ 51 + #define EXYNOS4X12_PHY_HSIC_CTRL0 (0x04) 52 + #define EXYNOS4X12_PHY_HSIC_CTRL1 (0x08) 53 + 54 + #define PHYPWR_NORMAL_MASK_HSIC1 (0x7 << 12) 55 + #define PHYPWR_NORMAL_MASK_HSIC0 (0x7 << 9) 56 + #define PHYPWR_NORMAL_MASK_PHY1 (0x7 << 6) 57 + 58 + #define RSTCON_HOSTPHY_SWRST (0xf << 3) 59 + 50 60 /* EXYNOS5 */ 51 61 #define EXYNOS5_PHY_HOST_CTRL0 (0x00) 52 62 ··· 251 241 enum samsung_cpu_type { 252 242 TYPE_S3C64XX, 253 243 TYPE_EXYNOS4210, 244 + TYPE_EXYNOS4X12, 254 245 TYPE_EXYNOS5250, 255 246 }; 247 + 248 + struct samsung_usbphy; 256 249 257 250 /* 258 251 * struct samsung_usbphy_drvdata - driver data for various SoC variants ··· 281 268 int hostphy_en_mask; 282 269 u32 devphy_reg_offset; 283 270 u32 hostphy_reg_offset; 271 + int (*rate_to_clksel)(struct samsung_usbphy *, unsigned long); 272 + void (*set_isolation)(struct samsung_usbphy *, bool); 273 + void (*phy_enable)(struct samsung_usbphy *); 274 + void (*phy_disable)(struct samsung_usbphy *); 284 275 }; 285 276 286 277 /* ··· 337 320 } 338 321 339 322 extern int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy); 340 - extern void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on); 323 + extern void samsung_usbphy_set_isolation_4210(struct samsung_usbphy *sphy, 324 + bool on); 341 325 extern void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy); 342 326 extern int samsung_usbphy_set_type(struct usb_phy *phy, 343 327 enum samsung_usb_phy_type phy_type); 344 328 extern int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy); 329 + extern int samsung_usbphy_rate_to_clksel_64xx(struct samsung_usbphy *sphy, 330 + unsigned long rate); 331 + extern int samsung_usbphy_rate_to_clksel_4x12(struct samsung_usbphy *sphy, 332 + unsigned long rate);
+49 -13
drivers/usb/phy/phy-samsung-usb2.c
··· 176 176 phypwr &= ~PHYPWR_NORMAL_MASK; 177 177 rstcon |= RSTCON_SWRST; 178 178 break; 179 + case TYPE_EXYNOS4X12: 180 + phypwr &= ~(PHYPWR_NORMAL_MASK_HSIC0 | 181 + PHYPWR_NORMAL_MASK_HSIC1 | 182 + PHYPWR_NORMAL_MASK_PHY1); 183 + rstcon |= RSTCON_HOSTPHY_SWRST; 179 184 case TYPE_EXYNOS4210: 180 185 phypwr &= ~PHYPWR_NORMAL_MASK_PHY0; 181 186 rstcon |= RSTCON_SWRST; ··· 194 189 /* reset all ports of PHY and Link */ 195 190 writel(rstcon, regs + SAMSUNG_RSTCON); 196 191 udelay(10); 192 + if (sphy->drv_data->cpu_type == TYPE_EXYNOS4X12) 193 + rstcon &= ~RSTCON_HOSTPHY_SWRST; 197 194 rstcon &= ~RSTCON_SWRST; 198 195 writel(rstcon, regs + SAMSUNG_RSTCON); 199 196 } ··· 246 239 case TYPE_S3C64XX: 247 240 phypwr |= PHYPWR_NORMAL_MASK; 248 241 break; 242 + case TYPE_EXYNOS4X12: 243 + phypwr |= (PHYPWR_NORMAL_MASK_HSIC0 | 244 + PHYPWR_NORMAL_MASK_HSIC1 | 245 + PHYPWR_NORMAL_MASK_PHY1); 249 246 case TYPE_EXYNOS4210: 250 247 phypwr |= PHYPWR_NORMAL_MASK_PHY0; 251 248 default: ··· 295 284 /* Disable phy isolation */ 296 285 if (sphy->plat && sphy->plat->pmu_isolation) 297 286 sphy->plat->pmu_isolation(false); 298 - else 299 - samsung_usbphy_set_isolation(sphy, false); 287 + else if (sphy->drv_data->set_isolation) 288 + sphy->drv_data->set_isolation(sphy, false); 300 289 301 290 /* Selecting Host/OTG mode; After reset USB2.0PHY_CFG: HOST */ 302 291 samsung_usbphy_cfg_sel(sphy); 303 292 304 293 /* Initialize usb phy registers */ 305 - if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) 306 - samsung_exynos5_usb2phy_enable(sphy); 307 - else 308 - samsung_usb2phy_enable(sphy); 294 + sphy->drv_data->phy_enable(sphy); 309 295 310 296 spin_unlock_irqrestore(&sphy->lock, flags); 311 297 ··· 342 334 } 343 335 344 336 /* De-initialize usb phy registers */ 345 - if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) 346 - samsung_exynos5_usb2phy_disable(sphy); 347 - else 348 - samsung_usb2phy_disable(sphy); 337 + sphy->drv_data->phy_disable(sphy); 349 338 350 339 /* Enable phy isolation */ 351 340 if (sphy->plat && sphy->plat->pmu_isolation) 352 341 sphy->plat->pmu_isolation(true); 353 - else 354 - samsung_usbphy_set_isolation(sphy, true); 342 + else if (sphy->drv_data->set_isolation) 343 + sphy->drv_data->set_isolation(sphy, true); 355 344 356 345 spin_unlock_irqrestore(&sphy->lock, flags); 357 346 ··· 413 408 sphy->phy.label = "samsung-usb2phy"; 414 409 sphy->phy.init = samsung_usb2phy_init; 415 410 sphy->phy.shutdown = samsung_usb2phy_shutdown; 416 - sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); 411 + 412 + sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); 413 + if (sphy->ref_clk_freq < 0) 414 + return -EINVAL; 417 415 418 416 sphy->phy.otg = otg; 419 417 sphy->phy.otg->phy = &sphy->phy; ··· 446 438 static const struct samsung_usbphy_drvdata usb2phy_s3c64xx = { 447 439 .cpu_type = TYPE_S3C64XX, 448 440 .devphy_en_mask = S3C64XX_USBPHY_ENABLE, 441 + .rate_to_clksel = samsung_usbphy_rate_to_clksel_64xx, 442 + .set_isolation = NULL, /* TODO */ 443 + .phy_enable = samsung_usb2phy_enable, 444 + .phy_disable = samsung_usb2phy_disable, 449 445 }; 450 446 451 447 static const struct samsung_usbphy_drvdata usb2phy_exynos4 = { 452 448 .cpu_type = TYPE_EXYNOS4210, 453 449 .devphy_en_mask = EXYNOS_USBPHY_ENABLE, 454 450 .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, 451 + .rate_to_clksel = samsung_usbphy_rate_to_clksel_64xx, 452 + .set_isolation = samsung_usbphy_set_isolation_4210, 453 + .phy_enable = samsung_usb2phy_enable, 454 + .phy_disable = samsung_usb2phy_disable, 455 + }; 456 + 457 + static const struct samsung_usbphy_drvdata usb2phy_exynos4x12 = { 458 + .cpu_type = TYPE_EXYNOS4X12, 459 + .devphy_en_mask = EXYNOS_USBPHY_ENABLE, 460 + .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, 461 + .rate_to_clksel = samsung_usbphy_rate_to_clksel_4x12, 462 + .set_isolation = samsung_usbphy_set_isolation_4210, 463 + .phy_enable = samsung_usb2phy_enable, 464 + .phy_disable = samsung_usb2phy_disable, 455 465 }; 456 466 457 467 static struct samsung_usbphy_drvdata usb2phy_exynos5 = { 458 468 .cpu_type = TYPE_EXYNOS5250, 459 469 .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, 460 470 .hostphy_reg_offset = EXYNOS_USBHOST_PHY_CTRL_OFFSET, 471 + .rate_to_clksel = samsung_usbphy_rate_to_clksel_4x12, 472 + .set_isolation = samsung_usbphy_set_isolation_4210, 473 + .phy_enable = samsung_exynos5_usb2phy_enable, 474 + .phy_disable = samsung_exynos5_usb2phy_disable, 461 475 }; 462 476 463 477 #ifdef CONFIG_OF ··· 490 460 }, { 491 461 .compatible = "samsung,exynos4210-usb2phy", 492 462 .data = &usb2phy_exynos4, 463 + }, { 464 + .compatible = "samsung,exynos4x12-usb2phy", 465 + .data = &usb2phy_exynos4x12, 493 466 }, { 494 467 .compatible = "samsung,exynos5250-usb2phy", 495 468 .data = &usb2phy_exynos5 ··· 509 476 }, { 510 477 .name = "exynos4210-usb2phy", 511 478 .driver_data = (unsigned long)&usb2phy_exynos4, 479 + }, { 480 + .name = "exynos4x12-usb2phy", 481 + .driver_data = (unsigned long)&usb2phy_exynos4x12, 512 482 }, { 513 483 .name = "exynos5250-usb2phy", 514 484 .driver_data = (unsigned long)&usb2phy_exynos5,
+15 -8
drivers/usb/phy/phy-samsung-usb3.c
··· 65 65 return reg; 66 66 } 67 67 68 - static int samsung_exynos5_usb3phy_enable(struct samsung_usbphy *sphy) 68 + static void samsung_exynos5_usb3phy_enable(struct samsung_usbphy *sphy) 69 69 { 70 70 void __iomem *regs = sphy->regs; 71 71 u32 phyparam0; ··· 133 133 134 134 phyclkrst &= ~(PHYCLKRST_PORTRESET); 135 135 writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST); 136 - 137 - return 0; 138 136 } 139 137 140 138 static void samsung_exynos5_usb3phy_disable(struct samsung_usbphy *sphy) ··· 182 184 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); 183 185 184 186 /* Disable phy isolation */ 185 - samsung_usbphy_set_isolation(sphy, false); 187 + if (sphy->drv_data->set_isolation) 188 + sphy->drv_data->set_isolation(sphy, false); 186 189 187 190 /* Initialize usb phy registers */ 188 - samsung_exynos5_usb3phy_enable(sphy); 191 + sphy->drv_data->phy_enable(sphy); 189 192 190 193 spin_unlock_irqrestore(&sphy->lock, flags); 191 194 ··· 217 218 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); 218 219 219 220 /* De-initialize usb phy registers */ 220 - samsung_exynos5_usb3phy_disable(sphy); 221 + sphy->drv_data->phy_disable(sphy); 221 222 222 223 /* Enable phy isolation */ 223 - samsung_usbphy_set_isolation(sphy, true); 224 + if (sphy->drv_data->set_isolation) 225 + sphy->drv_data->set_isolation(sphy, true); 224 226 225 227 spin_unlock_irqrestore(&sphy->lock, flags); 226 228 ··· 274 274 sphy->phy.init = samsung_usb3phy_init; 275 275 sphy->phy.shutdown = samsung_usb3phy_shutdown; 276 276 sphy->drv_data = samsung_usbphy_get_driver_data(pdev); 277 - sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); 277 + 278 + sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); 279 + if (sphy->ref_clk_freq < 0) 280 + return -EINVAL; 278 281 279 282 spin_lock_init(&sphy->lock); 280 283 ··· 303 300 static struct samsung_usbphy_drvdata usb3phy_exynos5 = { 304 301 .cpu_type = TYPE_EXYNOS5250, 305 302 .devphy_en_mask = EXYNOS_USBPHY_ENABLE, 303 + .rate_to_clksel = samsung_usbphy_rate_to_clksel_4x12, 304 + .set_isolation = samsung_usbphy_set_isolation_4210, 305 + .phy_enable = samsung_exynos5_usb3phy_enable, 306 + .phy_disable = samsung_exynos5_usb3phy_disable, 306 307 }; 307 308 308 309 #ifdef CONFIG_OF
+193 -125
drivers/usb/phy/phy-tegra-usb.c
··· 1 1 /* 2 2 * Copyright (C) 2010 Google, Inc. 3 + * Copyright (C) 2013 NVIDIA Corporation 3 4 * 4 5 * Author: 5 6 * Erik Gilling <konkers@google.com> 6 7 * Benoit Goby <benoit@android.com> 8 + * Venu Byravarasu <vbyravarasu@nvidia.com> 7 9 * 8 10 * This software is licensed under the terms of the GNU General Public 9 11 * License version 2, as published by the Free Software Foundation, and ··· 32 30 #include <linux/usb/ulpi.h> 33 31 #include <asm/mach-types.h> 34 32 #include <linux/usb/tegra_usb_phy.h> 35 - 36 - #define TEGRA_USB_BASE 0xC5000000 37 - #define TEGRA_USB_SIZE SZ_16K 33 + #include <linux/module.h> 38 34 39 35 #define ULPI_VIEWPORT 0x170 40 36 ··· 198 198 199 199 static int utmip_pad_open(struct tegra_usb_phy *phy) 200 200 { 201 - phy->pad_clk = clk_get_sys("utmip-pad", NULL); 201 + phy->pad_clk = devm_clk_get(phy->dev, "utmi-pads"); 202 202 if (IS_ERR(phy->pad_clk)) { 203 203 pr_err("%s: can't get utmip pad clock\n", __func__); 204 204 return PTR_ERR(phy->pad_clk); 205 205 } 206 206 207 - if (phy->is_legacy_phy) { 208 - phy->pad_regs = phy->regs; 209 - } else { 210 - phy->pad_regs = ioremap(TEGRA_USB_BASE, TEGRA_USB_SIZE); 211 - if (!phy->pad_regs) { 212 - pr_err("%s: can't remap usb registers\n", __func__); 213 - clk_put(phy->pad_clk); 214 - return -ENOMEM; 215 - } 216 - } 217 207 return 0; 218 - } 219 - 220 - static void utmip_pad_close(struct tegra_usb_phy *phy) 221 - { 222 - if (!phy->is_legacy_phy) 223 - iounmap(phy->pad_regs); 224 - clk_put(phy->pad_clk); 225 208 } 226 209 227 210 static void utmip_pad_power_on(struct tegra_usb_phy *phy) ··· 282 299 val &= ~USB_SUSP_SET; 283 300 writel(val, base + USB_SUSP_CTRL); 284 301 } else 285 - phy->set_phcd(&phy->u_phy, true); 302 + tegra_ehci_set_phcd(&phy->u_phy, true); 286 303 287 304 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0) 288 305 pr_err("%s: timeout waiting for phy to stabilize\n", __func__); ··· 304 321 val &= ~USB_SUSP_CLR; 305 322 writel(val, base + USB_SUSP_CTRL); 306 323 } else 307 - phy->set_phcd(&phy->u_phy, false); 324 + tegra_ehci_set_phcd(&phy->u_phy, false); 308 325 309 326 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 310 327 USB_PHY_CLK_VALID)) ··· 427 444 utmi_phy_clk_enable(phy); 428 445 429 446 if (!phy->is_legacy_phy) 430 - phy->set_pts(&phy->u_phy, 0); 447 + tegra_ehci_set_pts(&phy->u_phy, 0); 431 448 432 449 return 0; 433 450 } ··· 524 541 int ret; 525 542 unsigned long val; 526 543 void __iomem *base = phy->regs; 527 - struct tegra_ulpi_config *config = phy->config; 528 544 529 - gpio_direction_output(config->reset_gpio, 0); 545 + ret = gpio_direction_output(phy->reset_gpio, 0); 546 + if (ret < 0) { 547 + dev_err(phy->dev, "gpio %d not set to 0\n", phy->reset_gpio); 548 + return ret; 549 + } 530 550 msleep(5); 531 - gpio_direction_output(config->reset_gpio, 1); 551 + ret = gpio_direction_output(phy->reset_gpio, 1); 552 + if (ret < 0) { 553 + dev_err(phy->dev, "gpio %d not set to 1\n", phy->reset_gpio); 554 + return ret; 555 + } 532 556 533 557 clk_prepare_enable(phy->clk); 534 558 msleep(1); ··· 593 603 594 604 static int ulpi_phy_power_off(struct tegra_usb_phy *phy) 595 605 { 596 - struct tegra_ulpi_config *config = phy->config; 597 - 598 606 clk_disable(phy->clk); 599 - return gpio_direction_output(config->reset_gpio, 0); 600 - } 601 - 602 - static int tegra_phy_init(struct usb_phy *x) 603 - { 604 - struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); 605 - struct tegra_ulpi_config *ulpi_config; 606 - int err; 607 - 608 - if (phy->is_ulpi_phy) { 609 - ulpi_config = phy->config; 610 - phy->clk = clk_get_sys(NULL, ulpi_config->clk); 611 - if (IS_ERR(phy->clk)) { 612 - pr_err("%s: can't get ulpi clock\n", __func__); 613 - err = -ENXIO; 614 - goto err1; 615 - } 616 - if (!gpio_is_valid(ulpi_config->reset_gpio)) 617 - ulpi_config->reset_gpio = 618 - of_get_named_gpio(phy->dev->of_node, 619 - "nvidia,phy-reset-gpio", 0); 620 - if (!gpio_is_valid(ulpi_config->reset_gpio)) { 621 - pr_err("%s: invalid reset gpio: %d\n", __func__, 622 - ulpi_config->reset_gpio); 623 - err = -EINVAL; 624 - goto err1; 625 - } 626 - gpio_request(ulpi_config->reset_gpio, "ulpi_phy_reset_b"); 627 - gpio_direction_output(ulpi_config->reset_gpio, 0); 628 - phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0); 629 - phy->ulpi->io_priv = phy->regs + ULPI_VIEWPORT; 630 - } else { 631 - err = utmip_pad_open(phy); 632 - if (err < 0) 633 - goto err1; 634 - } 635 - return 0; 636 - err1: 637 - clk_disable_unprepare(phy->pll_u); 638 - clk_put(phy->pll_u); 639 - return err; 607 + return gpio_direction_output(phy->reset_gpio, 0); 640 608 } 641 609 642 610 static void tegra_usb_phy_close(struct usb_phy *x) 643 611 { 644 612 struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy); 645 613 646 - if (phy->is_ulpi_phy) 647 - clk_put(phy->clk); 648 - else 649 - utmip_pad_close(phy); 650 614 clk_disable_unprepare(phy->pll_u); 651 - clk_put(phy->pll_u); 652 - kfree(phy); 653 615 } 654 616 655 617 static int tegra_usb_phy_power_on(struct tegra_usb_phy *phy) ··· 629 687 return tegra_usb_phy_power_on(phy); 630 688 } 631 689 632 - struct tegra_usb_phy *tegra_usb_phy_open(struct device *dev, int instance, 633 - void __iomem *regs, void *config, enum tegra_usb_phy_mode phy_mode, 634 - void (*set_pts)(struct usb_phy *x, u8 pts_val), 635 - void (*set_phcd)(struct usb_phy *x, bool enable)) 636 - 690 + static int ulpi_open(struct tegra_usb_phy *phy) 637 691 { 638 - struct tegra_usb_phy *phy; 692 + int err; 693 + 694 + phy->clk = devm_clk_get(phy->dev, "ulpi-link"); 695 + if (IS_ERR(phy->clk)) { 696 + pr_err("%s: can't get ulpi clock\n", __func__); 697 + return PTR_ERR(phy->clk); 698 + } 699 + 700 + err = devm_gpio_request(phy->dev, phy->reset_gpio, "ulpi_phy_reset_b"); 701 + if (err < 0) { 702 + dev_err(phy->dev, "request failed for gpio: %d\n", 703 + phy->reset_gpio); 704 + return err; 705 + } 706 + 707 + err = gpio_direction_output(phy->reset_gpio, 0); 708 + if (err < 0) { 709 + dev_err(phy->dev, "gpio %d direction not set to output\n", 710 + phy->reset_gpio); 711 + return err; 712 + } 713 + 714 + phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0); 715 + if (!phy->ulpi) { 716 + dev_err(phy->dev, "otg_ulpi_create returned NULL\n"); 717 + err = -ENOMEM; 718 + return err; 719 + } 720 + 721 + phy->ulpi->io_priv = phy->regs + ULPI_VIEWPORT; 722 + return 0; 723 + } 724 + 725 + static int tegra_usb_phy_init(struct tegra_usb_phy *phy) 726 + { 639 727 unsigned long parent_rate; 640 728 int i; 641 729 int err; 642 - struct device_node *np = dev->of_node; 643 730 644 - phy = kzalloc(sizeof(struct tegra_usb_phy), GFP_KERNEL); 645 - if (!phy) 646 - return ERR_PTR(-ENOMEM); 647 - 648 - phy->instance = instance; 649 - phy->regs = regs; 650 - phy->config = config; 651 - phy->mode = phy_mode; 652 - phy->dev = dev; 653 - phy->is_legacy_phy = 654 - of_property_read_bool(np, "nvidia,has-legacy-mode"); 655 - phy->set_pts = set_pts; 656 - phy->set_phcd = set_phcd; 657 - err = of_property_match_string(np, "phy_type", "ulpi"); 658 - if (err < 0) 659 - phy->is_ulpi_phy = false; 660 - else 661 - phy->is_ulpi_phy = true; 662 - 663 - if (!phy->config) { 664 - if (phy->is_ulpi_phy) { 665 - pr_err("%s: ulpi phy configuration missing", __func__); 666 - err = -EINVAL; 667 - goto err0; 668 - } else { 669 - phy->config = &utmip_default[instance]; 670 - } 731 + if (!phy->is_ulpi_phy) { 732 + if (phy->is_legacy_phy) 733 + phy->config = &utmip_default[0]; 734 + else 735 + phy->config = &utmip_default[2]; 671 736 } 672 737 673 - phy->pll_u = clk_get_sys(NULL, "pll_u"); 738 + phy->pll_u = devm_clk_get(phy->dev, "pll_u"); 674 739 if (IS_ERR(phy->pll_u)) { 675 740 pr_err("Can't get pll_u clock\n"); 676 - err = PTR_ERR(phy->pll_u); 677 - goto err0; 741 + return PTR_ERR(phy->pll_u); 678 742 } 679 - clk_prepare_enable(phy->pll_u); 743 + 744 + err = clk_prepare_enable(phy->pll_u); 745 + if (err) 746 + return err; 680 747 681 748 parent_rate = clk_get_rate(clk_get_parent(phy->pll_u)); 682 749 for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) { ··· 697 746 if (!phy->freq) { 698 747 pr_err("invalid pll_u parent rate %ld\n", parent_rate); 699 748 err = -EINVAL; 700 - goto err1; 749 + goto fail; 701 750 } 702 751 703 - phy->u_phy.init = tegra_phy_init; 704 - phy->u_phy.shutdown = tegra_usb_phy_close; 705 - phy->u_phy.set_suspend = tegra_usb_phy_suspend; 752 + if (phy->is_ulpi_phy) 753 + err = ulpi_open(phy); 754 + else 755 + err = utmip_pad_open(phy); 756 + if (err < 0) 757 + goto fail; 706 758 707 - return phy; 759 + return 0; 708 760 709 - err1: 761 + fail: 710 762 clk_disable_unprepare(phy->pll_u); 711 - clk_put(phy->pll_u); 712 - err0: 713 - kfree(phy); 714 - return ERR_PTR(err); 763 + return err; 715 764 } 716 - EXPORT_SYMBOL_GPL(tegra_usb_phy_open); 717 765 718 766 void tegra_usb_phy_preresume(struct usb_phy *x) 719 767 { ··· 751 801 } 752 802 EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_end); 753 803 804 + static int tegra_usb_phy_probe(struct platform_device *pdev) 805 + { 806 + struct resource *res; 807 + struct tegra_usb_phy *tegra_phy = NULL; 808 + struct device_node *np = pdev->dev.of_node; 809 + int err; 810 + 811 + tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL); 812 + if (!tegra_phy) { 813 + dev_err(&pdev->dev, "unable to allocate memory for USB2 PHY\n"); 814 + return -ENOMEM; 815 + } 816 + 817 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 818 + if (!res) { 819 + dev_err(&pdev->dev, "Failed to get I/O memory\n"); 820 + return -ENXIO; 821 + } 822 + 823 + tegra_phy->regs = devm_ioremap(&pdev->dev, res->start, 824 + resource_size(res)); 825 + if (!tegra_phy->regs) { 826 + dev_err(&pdev->dev, "Failed to remap I/O memory\n"); 827 + return -ENOMEM; 828 + } 829 + 830 + tegra_phy->is_legacy_phy = 831 + of_property_read_bool(np, "nvidia,has-legacy-mode"); 832 + 833 + err = of_property_match_string(np, "phy_type", "ulpi"); 834 + if (err < 0) { 835 + tegra_phy->is_ulpi_phy = false; 836 + 837 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 838 + if (!res) { 839 + dev_err(&pdev->dev, "Failed to get UTMI Pad regs\n"); 840 + return -ENXIO; 841 + } 842 + 843 + tegra_phy->pad_regs = devm_ioremap(&pdev->dev, res->start, 844 + resource_size(res)); 845 + if (!tegra_phy->regs) { 846 + dev_err(&pdev->dev, "Failed to remap UTMI Pad regs\n"); 847 + return -ENOMEM; 848 + } 849 + } else { 850 + tegra_phy->is_ulpi_phy = true; 851 + 852 + tegra_phy->reset_gpio = 853 + of_get_named_gpio(np, "nvidia,phy-reset-gpio", 0); 854 + if (!gpio_is_valid(tegra_phy->reset_gpio)) { 855 + dev_err(&pdev->dev, "invalid gpio: %d\n", 856 + tegra_phy->reset_gpio); 857 + return tegra_phy->reset_gpio; 858 + } 859 + } 860 + 861 + err = of_property_match_string(np, "dr_mode", "otg"); 862 + if (err < 0) { 863 + err = of_property_match_string(np, "dr_mode", "peripheral"); 864 + if (err < 0) 865 + tegra_phy->mode = TEGRA_USB_PHY_MODE_HOST; 866 + else 867 + tegra_phy->mode = TEGRA_USB_PHY_MODE_DEVICE; 868 + } else 869 + tegra_phy->mode = TEGRA_USB_PHY_MODE_OTG; 870 + 871 + tegra_phy->dev = &pdev->dev; 872 + err = tegra_usb_phy_init(tegra_phy); 873 + if (err < 0) 874 + return err; 875 + 876 + tegra_phy->u_phy.shutdown = tegra_usb_phy_close; 877 + tegra_phy->u_phy.set_suspend = tegra_usb_phy_suspend; 878 + 879 + dev_set_drvdata(&pdev->dev, tegra_phy); 880 + return 0; 881 + } 882 + 883 + static struct of_device_id tegra_usb_phy_id_table[] = { 884 + { .compatible = "nvidia,tegra20-usb-phy", }, 885 + { }, 886 + }; 887 + MODULE_DEVICE_TABLE(of, tegra_usb_phy_id_table); 888 + 889 + static struct platform_driver tegra_usb_phy_driver = { 890 + .probe = tegra_usb_phy_probe, 891 + .driver = { 892 + .name = "tegra-phy", 893 + .owner = THIS_MODULE, 894 + .of_match_table = of_match_ptr(tegra_usb_phy_id_table), 895 + }, 896 + }; 897 + module_platform_driver(tegra_usb_phy_driver); 898 + 899 + static int tegra_usb_phy_match(struct device *dev, void *data) 900 + { 901 + struct tegra_usb_phy *tegra_phy = dev_get_drvdata(dev); 902 + struct device_node *dn = data; 903 + 904 + return (tegra_phy->dev->of_node == dn) ? 1 : 0; 905 + } 906 + 907 + struct usb_phy *tegra_usb_get_phy(struct device_node *dn) 908 + { 909 + struct device *dev; 910 + struct tegra_usb_phy *tegra_phy; 911 + 912 + dev = driver_find_device(&tegra_usb_phy_driver.driver, NULL, dn, 913 + tegra_usb_phy_match); 914 + if (!dev) 915 + return ERR_PTR(-EPROBE_DEFER); 916 + 917 + tegra_phy = dev_get_drvdata(dev); 918 + 919 + return &tegra_phy->u_phy; 920 + } 921 + EXPORT_SYMBOL_GPL(tegra_usb_get_phy);
+7 -6
include/linux/usb/tegra_usb_phy.h
··· 42 42 enum tegra_usb_phy_mode { 43 43 TEGRA_USB_PHY_MODE_DEVICE, 44 44 TEGRA_USB_PHY_MODE_HOST, 45 + TEGRA_USB_PHY_MODE_OTG, 45 46 }; 46 47 47 48 struct tegra_xtal_freq; ··· 62 61 struct device *dev; 63 62 bool is_legacy_phy; 64 63 bool is_ulpi_phy; 65 - void (*set_pts)(struct usb_phy *x, u8 pts_val); 66 - void (*set_phcd)(struct usb_phy *x, bool enable); 64 + int reset_gpio; 67 65 }; 68 66 69 - struct tegra_usb_phy *tegra_usb_phy_open(struct device *dev, int instance, 70 - void __iomem *regs, void *config, enum tegra_usb_phy_mode phy_mode, 71 - void (*set_pts)(struct usb_phy *x, u8 pts_val), 72 - void (*set_phcd)(struct usb_phy *x, bool enable)); 67 + struct usb_phy *tegra_usb_get_phy(struct device_node *dn); 73 68 74 69 void tegra_usb_phy_preresume(struct usb_phy *phy); 75 70 ··· 75 78 enum tegra_usb_phy_port_speed port_speed); 76 79 77 80 void tegra_ehci_phy_restore_end(struct usb_phy *phy); 81 + 82 + void tegra_ehci_set_pts(struct usb_phy *x, u8 pts_val); 83 + 84 + void tegra_ehci_set_phcd(struct usb_phy *x, bool enable); 78 85 79 86 #endif /* __TEGRA_USB_PHY_H */