diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-11-25 12:31:14 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-11-25 12:31:14 -0500 |
commit | 2d4d9f35bab1cad7f83d10864291d1e50b12c3f9 (patch) | |
tree | 24b5f23a1c98e29b8d2daad46133bfb261a8abae | |
parent | 2193dda5eec60373c7a061c129c6ab9d658f78e9 (diff) | |
parent | ebf3992061db1f7b3aa093f37fb308acc74fbc82 (diff) |
Merge tag 'usb-for-v3.19' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
Felipe writes:
usb: patches for v3.19 merge window
This time, a very pull request with 216 non-merge
commits. Most of the commits contained here are
sparse or coccinelle fixes ranging from missing
'static' to returning 0 in case of errors.
More importantly, we have the removal the now
unnecessary 'driver' argument to ->udc_stop().
DWC2 learned about Dual-Role builds. Users of
this IP can now have a single driver built for
host and device roles.
DWC3 got support for two new HW platforms: Exynos7
and AMD.
The Broadcom USB 3.0 Device Controller IP is now
supported and so is PLX USB338x, which means DWC3
has lost is badge as the only USB 3.0 peripheral
IP supported on Linux.
Thanks for Tony Lindgren's work, we can now have
a distro-like kernel where all MUSB glue layers
can be built into the same kernel (statically
or dynamically linked) and it'll work in PIO (DMA
will come probably on v3.20).
Other than these, the usual set of cleanups and
non-critical fixes.
Signed-off-by: Felipe Balbi <balbi@ti.com>
154 files changed, 7983 insertions, 1957 deletions
diff --git a/Documentation/ABI/stable/sysfs-class-udc b/Documentation/ABI/stable/sysfs-class-udc new file mode 100644 index 000000000000..85d3dac2e204 --- /dev/null +++ b/Documentation/ABI/stable/sysfs-class-udc | |||
@@ -0,0 +1,93 @@ | |||
1 | What: /sys/class/udc/<udc>/a_alt_hnp_support | ||
2 | Date: June 2011 | ||
3 | KernelVersion: 3.1 | ||
4 | Contact: Felipe Balbi <balbi@kernel.org> | ||
5 | Description: | ||
6 | Indicates if an OTG A-Host supports HNP at an alternate port. | ||
7 | Users: | ||
8 | |||
9 | What: /sys/class/udc/<udc>/a_hnp_support | ||
10 | Date: June 2011 | ||
11 | KernelVersion: 3.1 | ||
12 | Contact: Felipe Balbi <balbi@kernel.org> | ||
13 | Description: | ||
14 | Indicates if an OTG A-Host supports HNP at this port. | ||
15 | Users: | ||
16 | |||
17 | What: /sys/class/udc/<udc>/b_hnp_enable | ||
18 | Date: June 2011 | ||
19 | KernelVersion: 3.1 | ||
20 | Contact: Felipe Balbi <balbi@kernel.org> | ||
21 | Description: | ||
22 | Indicates if an OTG A-Host enabled HNP support. | ||
23 | Users: | ||
24 | |||
25 | What: /sys/class/udc/<udc>/current_speed | ||
26 | Date: June 2011 | ||
27 | KernelVersion: 3.1 | ||
28 | Contact: Felipe Balbi <balbi@kernel.org> | ||
29 | Description: | ||
30 | Indicates the current negotiated speed at this port. | ||
31 | Users: | ||
32 | |||
33 | What: /sys/class/udc/<udc>/is_a_peripheral | ||
34 | Date: June 2011 | ||
35 | KernelVersion: 3.1 | ||
36 | Contact: Felipe Balbi <balbi@kernel.org> | ||
37 | Description: | ||
38 | Indicates that this port is the default Host on an OTG session | ||
39 | but HNP was used to switch roles. | ||
40 | Users: | ||
41 | |||
42 | What: /sys/class/udc/<udc>/is_otg | ||
43 | Date: June 2011 | ||
44 | KernelVersion: 3.1 | ||
45 | Contact: Felipe Balbi <balbi@kernel.org> | ||
46 | Description: | ||
47 | Indicates that this port support OTG. | ||
48 | Users: | ||
49 | |||
50 | What: /sys/class/udc/<udc>/maximum_speed | ||
51 | Date: June 2011 | ||
52 | KernelVersion: 3.1 | ||
53 | Contact: Felipe Balbi <balbi@kernel.org> | ||
54 | Description: | ||
55 | Indicates the maximum USB speed supported by this port. | ||
56 | Users: | ||
57 | |||
58 | What: /sys/class/udc/<udc>/maximum_speed | ||
59 | Date: June 2011 | ||
60 | KernelVersion: 3.1 | ||
61 | Contact: Felipe Balbi <balbi@kernel.org> | ||
62 | Description: | ||
63 | Indicates the maximum USB speed supported by this port. | ||
64 | Users: | ||
65 | |||
66 | What: /sys/class/udc/<udc>/soft_connect | ||
67 | Date: June 2011 | ||
68 | KernelVersion: 3.1 | ||
69 | Contact: Felipe Balbi <balbi@kernel.org> | ||
70 | Description: | ||
71 | Allows users to disconnect data pullup resistors thus causing a | ||
72 | logical disconnection from the USB Host. | ||
73 | Users: | ||
74 | |||
75 | What: /sys/class/udc/<udc>/srp | ||
76 | Date: June 2011 | ||
77 | KernelVersion: 3.1 | ||
78 | Contact: Felipe Balbi <balbi@kernel.org> | ||
79 | Description: | ||
80 | Allows users to manually start Session Request Protocol. | ||
81 | Users: | ||
82 | |||
83 | What: /sys/class/udc/<udc>/state | ||
84 | Date: June 2011 | ||
85 | KernelVersion: 3.1 | ||
86 | Contact: Felipe Balbi <balbi@kernel.org> | ||
87 | Description: | ||
88 | Indicates current state of the USB Device Controller. Valid | ||
89 | states are: 'not-attached', 'attached', 'powered', | ||
90 | 'reconnecting', 'unauthenticated', 'default', 'addressed', | ||
91 | 'configured', and 'suspended'; however not all USB Device | ||
92 | Controllers support reporting all states. | ||
93 | Users: | ||
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-hid b/Documentation/ABI/testing/configfs-usb-gadget-hid new file mode 100644 index 000000000000..f12e00e6baa3 --- /dev/null +++ b/Documentation/ABI/testing/configfs-usb-gadget-hid | |||
@@ -0,0 +1,11 @@ | |||
1 | What: /config/usb-gadget/gadget/functions/hid.name | ||
2 | Date: Nov 2014 | ||
3 | KernelVersion: 3.19 | ||
4 | Description: | ||
5 | The attributes: | ||
6 | |||
7 | protocol - HID protocol to use | ||
8 | report_desc - blob corresponding to HID report descriptors | ||
9 | except the data passed through /dev/hidg<N> | ||
10 | report_length - HID report length | ||
11 | subclass - HID device subclass to use | ||
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-midi b/Documentation/ABI/testing/configfs-usb-gadget-midi new file mode 100644 index 000000000000..6b341df7249c --- /dev/null +++ b/Documentation/ABI/testing/configfs-usb-gadget-midi | |||
@@ -0,0 +1,12 @@ | |||
1 | What: /config/usb-gadget/gadget/functions/midi.name | ||
2 | Date: Nov 2014 | ||
3 | KernelVersion: 3.19 | ||
4 | Description: | ||
5 | The attributes: | ||
6 | |||
7 | index - index value for the USB MIDI adapter | ||
8 | id - ID string for the USB MIDI adapter | ||
9 | buflen - MIDI buffer length | ||
10 | qlen - USB read request queue length | ||
11 | in_ports - number of MIDI input ports | ||
12 | out_ports - number of MIDI output ports | ||
diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt b/Documentation/devicetree/bindings/usb/dwc3.txt index 471366d6a129..cd7f0454e13a 100644 --- a/Documentation/devicetree/bindings/usb/dwc3.txt +++ b/Documentation/devicetree/bindings/usb/dwc3.txt | |||
@@ -14,6 +14,29 @@ Optional properties: | |||
14 | - phys: from the *Generic PHY* bindings | 14 | - phys: from the *Generic PHY* bindings |
15 | - phy-names: from the *Generic PHY* bindings | 15 | - phy-names: from the *Generic PHY* bindings |
16 | - tx-fifo-resize: determines if the FIFO *has* to be reallocated. | 16 | - tx-fifo-resize: determines if the FIFO *has* to be reallocated. |
17 | - snps,disable_scramble_quirk: true when SW should disable data scrambling. | ||
18 | Only really useful for FPGA builds. | ||
19 | - snps,has-lpm-erratum: true when DWC3 was configured with LPM Erratum enabled | ||
20 | - snps,lpm-nyet-threshold: LPM NYET threshold | ||
21 | - snps,u2exit_lfps_quirk: set if we want to enable u2exit lfps quirk | ||
22 | - snps,u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk | ||
23 | - snps,req_p1p2p3_quirk: when set, the core will always request for | ||
24 | P1/P2/P3 transition sequence. | ||
25 | - snps,del_p1p2p3_quirk: when set core will delay P1/P2/P3 until a certain | ||
26 | amount of 8B10B errors occur. | ||
27 | - snps,del_phy_power_chg_quirk: when set core will delay PHY power change | ||
28 | from P0 to P1/P2/P3. | ||
29 | - snps,lfps_filter_quirk: when set core will filter LFPS reception. | ||
30 | - snps,rx_detect_poll_quirk: when set core will disable a 400us delay to start | ||
31 | Polling LFPS after RX.Detect. | ||
32 | - snps,tx_de_emphasis_quirk: when set core will set Tx de-emphasis value. | ||
33 | - snps,tx_de_emphasis: the value driven to the PHY is controlled by the | ||
34 | LTSSM during USB3 Compliance mode. | ||
35 | - snps,dis_u3_susphy_quirk: when set core will disable USB3 suspend phy. | ||
36 | - snps,dis_u2_susphy_quirk: when set core will disable USB2 suspend phy. | ||
37 | - snps,is-utmi-l1-suspend: true when DWC3 asserts output signal | ||
38 | utmi_l1_suspend_n, false when asserts utmi_sleep_n | ||
39 | - snps,hird-threshold: HIRD threshold | ||
17 | 40 | ||
18 | This is usually a subnode to DWC3 glue to which it is connected. | 41 | This is usually a subnode to DWC3 glue to which it is connected. |
19 | 42 | ||
diff --git a/Documentation/devicetree/bindings/usb/exynos-usb.txt b/Documentation/devicetree/bindings/usb/exynos-usb.txt index a3b5990d0f2c..9b4dbe3b2acc 100644 --- a/Documentation/devicetree/bindings/usb/exynos-usb.txt +++ b/Documentation/devicetree/bindings/usb/exynos-usb.txt | |||
@@ -82,8 +82,10 @@ Example: | |||
82 | 82 | ||
83 | DWC3 | 83 | DWC3 |
84 | Required properties: | 84 | Required properties: |
85 | - compatible: should be "samsung,exynos5250-dwusb3" for USB 3.0 DWC3 | 85 | - compatible: should be one of the following - |
86 | controller. | 86 | "samsung,exynos5250-dwusb3": for USB 3.0 DWC3 controller on |
87 | Exynos5250/5420. | ||
88 | "samsung,exynos7-dwusb3": for USB 3.0 DWC3 controller on Exynos7. | ||
87 | - #address-cells, #size-cells : should be '1' if the device has sub-nodes | 89 | - #address-cells, #size-cells : should be '1' if the device has sub-nodes |
88 | with 'reg' property. | 90 | with 'reg' property. |
89 | - ranges: allows valid 1:1 translation between child's address space and | 91 | - ranges: allows valid 1:1 translation between child's address space and |
diff --git a/Documentation/devicetree/bindings/usb/pxa-usb.txt b/Documentation/devicetree/bindings/usb/pxa-usb.txt index 79729a948d5a..9c331799b87c 100644 --- a/Documentation/devicetree/bindings/usb/pxa-usb.txt +++ b/Documentation/devicetree/bindings/usb/pxa-usb.txt | |||
@@ -29,3 +29,25 @@ Example: | |||
29 | marvell,port-mode = <2>; /* PMM_GLOBAL_MODE */ | 29 | marvell,port-mode = <2>; /* PMM_GLOBAL_MODE */ |
30 | }; | 30 | }; |
31 | 31 | ||
32 | UDC | ||
33 | |||
34 | Required properties: | ||
35 | - compatible: Should be "marvell,pxa270-udc" for USB controllers | ||
36 | used in device mode. | ||
37 | - reg: usb device MMIO address space | ||
38 | - interrupts: single interrupt generated by the UDC IP | ||
39 | - clocks: input clock of the UDC IP (see clock-bindings.txt) | ||
40 | |||
41 | Optional properties: | ||
42 | - gpios: | ||
43 | - gpio activated to control the USB D+ pullup (see gpio.txt) | ||
44 | |||
45 | Example: | ||
46 | |||
47 | pxa27x_udc: udc@40600000 { | ||
48 | compatible = "marvell,pxa270-udc"; | ||
49 | reg = <0x40600000 0x10000>; | ||
50 | interrupts = <11>; | ||
51 | clocks = <&pxa2xx_clks 11>; | ||
52 | gpios = <&gpio 22 GPIO_ACTIVE_LOW>; | ||
53 | }; | ||
diff --git a/Documentation/usb/gadget_hid.txt b/Documentation/usb/gadget_hid.txt index 12696c2e43fb..7a0fb8e16e27 100644 --- a/Documentation/usb/gadget_hid.txt +++ b/Documentation/usb/gadget_hid.txt | |||
@@ -74,6 +74,13 @@ static struct platform_device my_hid = { | |||
74 | You can add as many HID functions as you want, only limited by | 74 | You can add as many HID functions as you want, only limited by |
75 | the amount of interrupt endpoints your gadget driver supports. | 75 | the amount of interrupt endpoints your gadget driver supports. |
76 | 76 | ||
77 | Configuration with configfs | ||
78 | |||
79 | Instead of adding fake platform devices and drivers in order to pass | ||
80 | some data to the kernel, if HID is a part of a gadget composed with | ||
81 | configfs the hidg_func_descriptor.report_desc is passed to the kernel | ||
82 | by writing the appropriate stream of bytes to a configfs attribute. | ||
83 | |||
77 | Send and receive HID reports | 84 | Send and receive HID reports |
78 | 85 | ||
79 | HID reports can be sent/received using read/write on the | 86 | HID reports can be sent/received using read/write on the |
diff --git a/arch/arm/boot/dts/am4372.dtsi b/arch/arm/boot/dts/am4372.dtsi index 46660ffd2b65..e19068d24737 100644 --- a/arch/arm/boot/dts/am4372.dtsi +++ b/arch/arm/boot/dts/am4372.dtsi | |||
@@ -817,6 +817,8 @@ | |||
817 | maximum-speed = "high-speed"; | 817 | maximum-speed = "high-speed"; |
818 | dr_mode = "otg"; | 818 | dr_mode = "otg"; |
819 | status = "disabled"; | 819 | status = "disabled"; |
820 | snps,dis_u3_susphy_quirk; | ||
821 | snps,dis_u2_susphy_quirk; | ||
820 | }; | 822 | }; |
821 | }; | 823 | }; |
822 | 824 | ||
@@ -839,6 +841,8 @@ | |||
839 | maximum-speed = "high-speed"; | 841 | maximum-speed = "high-speed"; |
840 | dr_mode = "otg"; | 842 | dr_mode = "otg"; |
841 | status = "disabled"; | 843 | status = "disabled"; |
844 | snps,dis_u3_susphy_quirk; | ||
845 | snps,dis_u2_susphy_quirk; | ||
842 | }; | 846 | }; |
843 | }; | 847 | }; |
844 | 848 | ||
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 90acb32c85b1..ed6f89b6efe5 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c | |||
@@ -379,6 +379,26 @@ static void quirk_ati_exploding_mce(struct pci_dev *dev) | |||
379 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS100, quirk_ati_exploding_mce); | 379 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS100, quirk_ati_exploding_mce); |
380 | 380 | ||
381 | /* | 381 | /* |
382 | * In the AMD NL platform, this device ([1022:7912]) has a class code of | ||
383 | * PCI_CLASS_SERIAL_USB_XHCI (0x0c0330), which means the xhci driver will | ||
384 | * claim it. | ||
385 | * But the dwc3 driver is a more specific driver for this device, and we'd | ||
386 | * prefer to use it instead of xhci. To prevent xhci from claiming the | ||
387 | * device, change the class code to 0x0c03fe, which the PCI r3.0 spec | ||
388 | * defines as "USB device (not host controller)". The dwc3 driver can then | ||
389 | * claim it based on its Vendor and Device ID. | ||
390 | */ | ||
391 | static void quirk_amd_nl_class(struct pci_dev *pdev) | ||
392 | { | ||
393 | /* | ||
394 | * Use 'USB Device' (0x0c03fe) instead of PCI header provided | ||
395 | */ | ||
396 | pdev->class = 0x0c03fe; | ||
397 | } | ||
398 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB, | ||
399 | quirk_amd_nl_class); | ||
400 | |||
401 | /* | ||
382 | * Let's make the southbridge information explicit instead | 402 | * Let's make the southbridge information explicit instead |
383 | * of having to worry about people probing the ACPI areas, | 403 | * of having to worry about people probing the ACPI areas, |
384 | * for example.. (Yes, it happens, and if you read the wrong | 404 | * for example.. (Yes, it happens, and if you read the wrong |
diff --git a/drivers/phy/phy-omap-usb2.c b/drivers/phy/phy-omap-usb2.c index f091576b6449..08f2da270837 100644 --- a/drivers/phy/phy-omap-usb2.c +++ b/drivers/phy/phy-omap-usb2.c | |||
@@ -60,7 +60,7 @@ EXPORT_SYMBOL_GPL(omap_usb2_set_comparator); | |||
60 | 60 | ||
61 | static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled) | 61 | static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled) |
62 | { | 62 | { |
63 | struct omap_usb *phy = phy_to_omapusb(otg->phy); | 63 | struct omap_usb *phy = phy_to_omapusb(otg->usb_phy); |
64 | 64 | ||
65 | if (!phy->comparator) | 65 | if (!phy->comparator) |
66 | return -ENODEV; | 66 | return -ENODEV; |
@@ -70,7 +70,7 @@ static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled) | |||
70 | 70 | ||
71 | static int omap_usb_start_srp(struct usb_otg *otg) | 71 | static int omap_usb_start_srp(struct usb_otg *otg) |
72 | { | 72 | { |
73 | struct omap_usb *phy = phy_to_omapusb(otg->phy); | 73 | struct omap_usb *phy = phy_to_omapusb(otg->usb_phy); |
74 | 74 | ||
75 | if (!phy->comparator) | 75 | if (!phy->comparator) |
76 | return -ENODEV; | 76 | return -ENODEV; |
@@ -80,11 +80,9 @@ static int omap_usb_start_srp(struct usb_otg *otg) | |||
80 | 80 | ||
81 | static int omap_usb_set_host(struct usb_otg *otg, struct usb_bus *host) | 81 | static int omap_usb_set_host(struct usb_otg *otg, struct usb_bus *host) |
82 | { | 82 | { |
83 | struct usb_phy *phy = otg->phy; | ||
84 | |||
85 | otg->host = host; | 83 | otg->host = host; |
86 | if (!host) | 84 | if (!host) |
87 | phy->state = OTG_STATE_UNDEFINED; | 85 | otg->state = OTG_STATE_UNDEFINED; |
88 | 86 | ||
89 | return 0; | 87 | return 0; |
90 | } | 88 | } |
@@ -92,11 +90,9 @@ static int omap_usb_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
92 | static int omap_usb_set_peripheral(struct usb_otg *otg, | 90 | static int omap_usb_set_peripheral(struct usb_otg *otg, |
93 | struct usb_gadget *gadget) | 91 | struct usb_gadget *gadget) |
94 | { | 92 | { |
95 | struct usb_phy *phy = otg->phy; | ||
96 | |||
97 | otg->gadget = gadget; | 93 | otg->gadget = gadget; |
98 | if (!gadget) | 94 | if (!gadget) |
99 | phy->state = OTG_STATE_UNDEFINED; | 95 | otg->state = OTG_STATE_UNDEFINED; |
100 | 96 | ||
101 | return 0; | 97 | return 0; |
102 | } | 98 | } |
@@ -255,7 +251,7 @@ static int omap_usb2_probe(struct platform_device *pdev) | |||
255 | otg->set_vbus = omap_usb_set_vbus; | 251 | otg->set_vbus = omap_usb_set_vbus; |
256 | if (phy_data->flags & OMAP_USB2_HAS_START_SRP) | 252 | if (phy_data->flags & OMAP_USB2_HAS_START_SRP) |
257 | otg->start_srp = omap_usb_start_srp; | 253 | otg->start_srp = omap_usb_start_srp; |
258 | otg->phy = &phy->phy; | 254 | otg->usb_phy = &phy->phy; |
259 | 255 | ||
260 | platform_set_drvdata(pdev, phy); | 256 | platform_set_drvdata(pdev, phy); |
261 | pm_runtime_enable(phy->dev); | 257 | pm_runtime_enable(phy->dev); |
diff --git a/drivers/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c index 7b04befd5271..e2698d29f436 100644 --- a/drivers/phy/phy-twl4030-usb.c +++ b/drivers/phy/phy-twl4030-usb.c | |||
@@ -606,7 +606,7 @@ static int twl4030_set_peripheral(struct usb_otg *otg, | |||
606 | 606 | ||
607 | otg->gadget = gadget; | 607 | otg->gadget = gadget; |
608 | if (!gadget) | 608 | if (!gadget) |
609 | otg->phy->state = OTG_STATE_UNDEFINED; | 609 | otg->state = OTG_STATE_UNDEFINED; |
610 | 610 | ||
611 | return 0; | 611 | return 0; |
612 | } | 612 | } |
@@ -618,7 +618,7 @@ static int twl4030_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
618 | 618 | ||
619 | otg->host = host; | 619 | otg->host = host; |
620 | if (!host) | 620 | if (!host) |
621 | otg->phy->state = OTG_STATE_UNDEFINED; | 621 | otg->state = OTG_STATE_UNDEFINED; |
622 | 622 | ||
623 | return 0; | 623 | return 0; |
624 | } | 624 | } |
@@ -676,7 +676,7 @@ static int twl4030_usb_probe(struct platform_device *pdev) | |||
676 | twl->phy.otg = otg; | 676 | twl->phy.otg = otg; |
677 | twl->phy.type = USB_PHY_TYPE_USB2; | 677 | twl->phy.type = USB_PHY_TYPE_USB2; |
678 | 678 | ||
679 | otg->phy = &twl->phy; | 679 | otg->usb_phy = &twl->phy; |
680 | otg->set_host = twl4030_set_host; | 680 | otg->set_host = twl4030_set_host; |
681 | otg->set_peripheral = twl4030_set_peripheral; | 681 | otg->set_peripheral = twl4030_set_peripheral; |
682 | 682 | ||
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index ea40626e0246..5bbfcc73cf70 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h | |||
@@ -161,7 +161,8 @@ struct hw_bank { | |||
161 | * @test_mode: the selected test mode | 161 | * @test_mode: the selected test mode |
162 | * @platdata: platform specific information supplied by parent device | 162 | * @platdata: platform specific information supplied by parent device |
163 | * @vbus_active: is VBUS active | 163 | * @vbus_active: is VBUS active |
164 | * @transceiver: pointer to USB PHY, if any | 164 | * @phy: pointer to PHY, if any |
165 | * @usb_phy: pointer to USB PHY, if any and if using the USB PHY framework | ||
165 | * @hcd: pointer to usb_hcd for ehci host driver | 166 | * @hcd: pointer to usb_hcd for ehci host driver |
166 | * @debugfs: root dentry for this controller in debugfs | 167 | * @debugfs: root dentry for this controller in debugfs |
167 | * @id_event: indicates there is an id event, and handled at ci_otg_work | 168 | * @id_event: indicates there is an id event, and handled at ci_otg_work |
@@ -177,6 +178,7 @@ struct ci_hdrc { | |||
177 | struct ci_role_driver *roles[CI_ROLE_END]; | 178 | struct ci_role_driver *roles[CI_ROLE_END]; |
178 | enum ci_role role; | 179 | enum ci_role role; |
179 | bool is_otg; | 180 | bool is_otg; |
181 | struct usb_otg otg; | ||
180 | struct otg_fsm fsm; | 182 | struct otg_fsm fsm; |
181 | struct ci_otg_fsm_timer_list *fsm_timer; | 183 | struct ci_otg_fsm_timer_list *fsm_timer; |
182 | struct work_struct work; | 184 | struct work_struct work; |
@@ -201,7 +203,9 @@ struct ci_hdrc { | |||
201 | 203 | ||
202 | struct ci_hdrc_platform_data *platdata; | 204 | struct ci_hdrc_platform_data *platdata; |
203 | int vbus_active; | 205 | int vbus_active; |
204 | struct usb_phy *transceiver; | 206 | struct phy *phy; |
207 | /* old usb_phy interface */ | ||
208 | struct usb_phy *usb_phy; | ||
205 | struct usb_hcd *hcd; | 209 | struct usb_hcd *hcd; |
206 | struct dentry *debugfs; | 210 | struct dentry *debugfs; |
207 | bool id_event; | 211 | bool id_event; |
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index a7ab0f15926e..6f8b1b1045b5 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c | |||
@@ -147,7 +147,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) | |||
147 | goto err_clk; | 147 | goto err_clk; |
148 | } | 148 | } |
149 | 149 | ||
150 | pdata.phy = data->phy; | 150 | pdata.usb_phy = data->phy; |
151 | 151 | ||
152 | if (imx_platform_flag->flags & CI_HDRC_IMX_IMX28_WRITE_FIX) | 152 | if (imx_platform_flag->flags & CI_HDRC_IMX_IMX28_WRITE_FIX) |
153 | pdata.flags |= CI_HDRC_IMX28_WRITE_FIX; | 153 | pdata.flags |= CI_HDRC_IMX28_WRITE_FIX; |
diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c b/drivers/usb/chipidea/ci_hdrc_msm.c index 4935ac38fd00..3edf969ed797 100644 --- a/drivers/usb/chipidea/ci_hdrc_msm.c +++ b/drivers/usb/chipidea/ci_hdrc_msm.c | |||
@@ -26,15 +26,15 @@ static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event) | |||
26 | dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n"); | 26 | dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n"); |
27 | writel(0, USB_AHBBURST); | 27 | writel(0, USB_AHBBURST); |
28 | writel(0, USB_AHBMODE); | 28 | writel(0, USB_AHBMODE); |
29 | usb_phy_init(ci->transceiver); | 29 | usb_phy_init(ci->usb_phy); |
30 | break; | 30 | break; |
31 | case CI_HDRC_CONTROLLER_STOPPED_EVENT: | 31 | case CI_HDRC_CONTROLLER_STOPPED_EVENT: |
32 | dev_dbg(dev, "CI_HDRC_CONTROLLER_STOPPED_EVENT received\n"); | 32 | dev_dbg(dev, "CI_HDRC_CONTROLLER_STOPPED_EVENT received\n"); |
33 | /* | 33 | /* |
34 | * Put the transceiver in non-driving mode. Otherwise host | 34 | * Put the phy in non-driving mode. Otherwise host |
35 | * may not detect soft-disconnection. | 35 | * may not detect soft-disconnection. |
36 | */ | 36 | */ |
37 | usb_phy_notify_disconnect(ci->transceiver, USB_SPEED_UNKNOWN); | 37 | usb_phy_notify_disconnect(ci->usb_phy, USB_SPEED_UNKNOWN); |
38 | break; | 38 | break; |
39 | default: | 39 | default: |
40 | dev_dbg(dev, "unknown ci_hdrc event\n"); | 40 | dev_dbg(dev, "unknown ci_hdrc event\n"); |
@@ -68,7 +68,7 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev) | |||
68 | if (IS_ERR(phy)) | 68 | if (IS_ERR(phy)) |
69 | return PTR_ERR(phy); | 69 | return PTR_ERR(phy); |
70 | 70 | ||
71 | ci_hdrc_msm_platdata.phy = phy; | 71 | ci_hdrc_msm_platdata.usb_phy = phy; |
72 | 72 | ||
73 | plat_ci = ci_hdrc_add_device(&pdev->dev, | 73 | plat_ci = ci_hdrc_add_device(&pdev->dev, |
74 | pdev->resource, pdev->num_resources, | 74 | pdev->resource, pdev->num_resources, |
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 9bdc6bd73432..60578d9c896d 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c | |||
@@ -47,6 +47,7 @@ | |||
47 | #include <linux/delay.h> | 47 | #include <linux/delay.h> |
48 | #include <linux/device.h> | 48 | #include <linux/device.h> |
49 | #include <linux/dma-mapping.h> | 49 | #include <linux/dma-mapping.h> |
50 | #include <linux/phy/phy.h> | ||
50 | #include <linux/platform_device.h> | 51 | #include <linux/platform_device.h> |
51 | #include <linux/module.h> | 52 | #include <linux/module.h> |
52 | #include <linux/idr.h> | 53 | #include <linux/idr.h> |
@@ -299,6 +300,49 @@ static void hw_phymode_configure(struct ci_hdrc *ci) | |||
299 | } | 300 | } |
300 | 301 | ||
301 | /** | 302 | /** |
303 | * _ci_usb_phy_init: initialize phy taking in account both phy and usb_phy | ||
304 | * interfaces | ||
305 | * @ci: the controller | ||
306 | * | ||
307 | * This function returns an error code if the phy failed to init | ||
308 | */ | ||
309 | static int _ci_usb_phy_init(struct ci_hdrc *ci) | ||
310 | { | ||
311 | int ret; | ||
312 | |||
313 | if (ci->phy) { | ||
314 | ret = phy_init(ci->phy); | ||
315 | if (ret) | ||
316 | return ret; | ||
317 | |||
318 | ret = phy_power_on(ci->phy); | ||
319 | if (ret) { | ||
320 | phy_exit(ci->phy); | ||
321 | return ret; | ||
322 | } | ||
323 | } else { | ||
324 | ret = usb_phy_init(ci->usb_phy); | ||
325 | } | ||
326 | |||
327 | return ret; | ||
328 | } | ||
329 | |||
330 | /** | ||
331 | * _ci_usb_phy_exit: deinitialize phy taking in account both phy and usb_phy | ||
332 | * interfaces | ||
333 | * @ci: the controller | ||
334 | */ | ||
335 | static void ci_usb_phy_exit(struct ci_hdrc *ci) | ||
336 | { | ||
337 | if (ci->phy) { | ||
338 | phy_power_off(ci->phy); | ||
339 | phy_exit(ci->phy); | ||
340 | } else { | ||
341 | usb_phy_shutdown(ci->usb_phy); | ||
342 | } | ||
343 | } | ||
344 | |||
345 | /** | ||
302 | * ci_usb_phy_init: initialize phy according to different phy type | 346 | * ci_usb_phy_init: initialize phy according to different phy type |
303 | * @ci: the controller | 347 | * @ci: the controller |
304 | * | 348 | * |
@@ -312,7 +356,7 @@ static int ci_usb_phy_init(struct ci_hdrc *ci) | |||
312 | case USBPHY_INTERFACE_MODE_UTMI: | 356 | case USBPHY_INTERFACE_MODE_UTMI: |
313 | case USBPHY_INTERFACE_MODE_UTMIW: | 357 | case USBPHY_INTERFACE_MODE_UTMIW: |
314 | case USBPHY_INTERFACE_MODE_HSIC: | 358 | case USBPHY_INTERFACE_MODE_HSIC: |
315 | ret = usb_phy_init(ci->transceiver); | 359 | ret = _ci_usb_phy_init(ci); |
316 | if (ret) | 360 | if (ret) |
317 | return ret; | 361 | return ret; |
318 | hw_phymode_configure(ci); | 362 | hw_phymode_configure(ci); |
@@ -320,12 +364,12 @@ static int ci_usb_phy_init(struct ci_hdrc *ci) | |||
320 | case USBPHY_INTERFACE_MODE_ULPI: | 364 | case USBPHY_INTERFACE_MODE_ULPI: |
321 | case USBPHY_INTERFACE_MODE_SERIAL: | 365 | case USBPHY_INTERFACE_MODE_SERIAL: |
322 | hw_phymode_configure(ci); | 366 | hw_phymode_configure(ci); |
323 | ret = usb_phy_init(ci->transceiver); | 367 | ret = _ci_usb_phy_init(ci); |
324 | if (ret) | 368 | if (ret) |
325 | return ret; | 369 | return ret; |
326 | break; | 370 | break; |
327 | default: | 371 | default: |
328 | ret = usb_phy_init(ci->transceiver); | 372 | ret = _ci_usb_phy_init(ci); |
329 | } | 373 | } |
330 | 374 | ||
331 | return ret; | 375 | return ret; |
@@ -605,23 +649,26 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
605 | return -ENODEV; | 649 | return -ENODEV; |
606 | } | 650 | } |
607 | 651 | ||
608 | if (ci->platdata->phy) | 652 | if (ci->platdata->phy) { |
609 | ci->transceiver = ci->platdata->phy; | 653 | ci->phy = ci->platdata->phy; |
610 | else | 654 | } else if (ci->platdata->usb_phy) { |
611 | ci->transceiver = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); | 655 | ci->usb_phy = ci->platdata->usb_phy; |
612 | 656 | } else { | |
613 | if (IS_ERR(ci->transceiver)) { | 657 | ci->phy = devm_phy_get(dev, "usb-phy"); |
614 | ret = PTR_ERR(ci->transceiver); | 658 | ci->usb_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); |
615 | /* | 659 | |
616 | * if -ENXIO is returned, it means PHY layer wasn't | 660 | /* if both generic PHY and USB PHY layers aren't enabled */ |
617 | * enabled, so it makes no sense to return -EPROBE_DEFER | 661 | if (PTR_ERR(ci->phy) == -ENOSYS && |
618 | * in that case, since no PHY driver will ever probe. | 662 | PTR_ERR(ci->usb_phy) == -ENXIO) |
619 | */ | 663 | return -ENXIO; |
620 | if (ret == -ENXIO) | 664 | |
621 | return ret; | 665 | if (IS_ERR(ci->phy) && IS_ERR(ci->usb_phy)) |
666 | return -EPROBE_DEFER; | ||
622 | 667 | ||
623 | dev_err(dev, "no usb2 phy configured\n"); | 668 | if (IS_ERR(ci->phy)) |
624 | return -EPROBE_DEFER; | 669 | ci->phy = NULL; |
670 | else if (IS_ERR(ci->usb_phy)) | ||
671 | ci->usb_phy = NULL; | ||
625 | } | 672 | } |
626 | 673 | ||
627 | ret = ci_usb_phy_init(ci); | 674 | ret = ci_usb_phy_init(ci); |
@@ -728,7 +775,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
728 | stop: | 775 | stop: |
729 | ci_role_destroy(ci); | 776 | ci_role_destroy(ci); |
730 | deinit_phy: | 777 | deinit_phy: |
731 | usb_phy_shutdown(ci->transceiver); | 778 | ci_usb_phy_exit(ci); |
732 | 779 | ||
733 | return ret; | 780 | return ret; |
734 | } | 781 | } |
@@ -741,7 +788,7 @@ static int ci_hdrc_remove(struct platform_device *pdev) | |||
741 | free_irq(ci->irq, ci); | 788 | free_irq(ci->irq, ci); |
742 | ci_role_destroy(ci); | 789 | ci_role_destroy(ci); |
743 | ci_hdrc_enter_lpm(ci, true); | 790 | ci_hdrc_enter_lpm(ci, true); |
744 | usb_phy_shutdown(ci->transceiver); | 791 | ci_usb_phy_exit(ci); |
745 | 792 | ||
746 | return 0; | 793 | return 0; |
747 | } | 794 | } |
diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c index 795d6538d630..268e4236e84c 100644 --- a/drivers/usb/chipidea/debug.c +++ b/drivers/usb/chipidea/debug.c | |||
@@ -220,7 +220,7 @@ static int ci_otg_show(struct seq_file *s, void *unused) | |||
220 | 220 | ||
221 | /* ------ State ----- */ | 221 | /* ------ State ----- */ |
222 | seq_printf(s, "OTG state: %s\n\n", | 222 | seq_printf(s, "OTG state: %s\n\n", |
223 | usb_otg_state_string(ci->transceiver->state)); | 223 | usb_otg_state_string(ci->otg.state)); |
224 | 224 | ||
225 | /* ------ State Machine Variables ----- */ | 225 | /* ------ State Machine Variables ----- */ |
226 | seq_printf(s, "a_bus_drop: %d\n", fsm->a_bus_drop); | 226 | seq_printf(s, "a_bus_drop: %d\n", fsm->a_bus_drop); |
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index 33027abb5349..48731d0bab35 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c | |||
@@ -98,8 +98,11 @@ static int host_start(struct ci_hdrc *ci) | |||
98 | hcd->has_tt = 1; | 98 | hcd->has_tt = 1; |
99 | 99 | ||
100 | hcd->power_budget = ci->platdata->power_budget; | 100 | hcd->power_budget = ci->platdata->power_budget; |
101 | hcd->usb_phy = ci->transceiver; | ||
102 | hcd->tpl_support = ci->platdata->tpl_support; | 101 | hcd->tpl_support = ci->platdata->tpl_support; |
102 | if (ci->phy) | ||
103 | hcd->phy = ci->phy; | ||
104 | else | ||
105 | hcd->usb_phy = ci->usb_phy; | ||
103 | 106 | ||
104 | ehci = hcd_to_ehci(hcd); | 107 | ehci = hcd_to_ehci(hcd); |
105 | ehci->caps = ci->hw_bank.cap; | 108 | ehci->caps = ci->hw_bank.cap; |
@@ -117,10 +120,11 @@ static int host_start(struct ci_hdrc *ci) | |||
117 | if (ret) { | 120 | if (ret) { |
118 | goto put_hcd; | 121 | goto put_hcd; |
119 | } else { | 122 | } else { |
120 | struct usb_otg *otg = ci->transceiver->otg; | 123 | struct usb_otg *otg = &ci->otg; |
121 | 124 | ||
122 | ci->hcd = hcd; | 125 | ci->hcd = hcd; |
123 | if (otg) { | 126 | |
127 | if (ci_otg_is_fsm_mode(ci)) { | ||
124 | otg->host = &hcd->self; | 128 | otg->host = &hcd->self; |
125 | hcd->self.otg_port = 1; | 129 | hcd->self.otg_port = 1; |
126 | } | 130 | } |
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c index e683595f9e69..368cc8e94fd6 100644 --- a/drivers/usb/chipidea/otg_fsm.c +++ b/drivers/usb/chipidea/otg_fsm.c | |||
@@ -328,7 +328,7 @@ static void b_ssend_srp_tmout_func(void *ptr, unsigned long indicator) | |||
328 | set_tmout(ci, indicator); | 328 | set_tmout(ci, indicator); |
329 | 329 | ||
330 | /* only vbus fall below B_sess_vld in b_idle state */ | 330 | /* only vbus fall below B_sess_vld in b_idle state */ |
331 | if (ci->transceiver->state == OTG_STATE_B_IDLE) | 331 | if (ci->fsm.otg->state == OTG_STATE_B_IDLE) |
332 | ci_otg_queue_work(ci); | 332 | ci_otg_queue_work(ci); |
333 | } | 333 | } |
334 | 334 | ||
@@ -582,11 +582,11 @@ int ci_otg_fsm_work(struct ci_hdrc *ci) | |||
582 | * when there is no gadget class driver | 582 | * when there is no gadget class driver |
583 | */ | 583 | */ |
584 | if (ci->fsm.id && !(ci->driver) && | 584 | if (ci->fsm.id && !(ci->driver) && |
585 | ci->transceiver->state < OTG_STATE_A_IDLE) | 585 | ci->fsm.otg->state < OTG_STATE_A_IDLE) |
586 | return 0; | 586 | return 0; |
587 | 587 | ||
588 | if (otg_statemachine(&ci->fsm)) { | 588 | if (otg_statemachine(&ci->fsm)) { |
589 | if (ci->transceiver->state == OTG_STATE_A_IDLE) { | 589 | if (ci->fsm.otg->state == OTG_STATE_A_IDLE) { |
590 | /* | 590 | /* |
591 | * Further state change for cases: | 591 | * Further state change for cases: |
592 | * a_idle to b_idle; or | 592 | * a_idle to b_idle; or |
@@ -600,7 +600,7 @@ int ci_otg_fsm_work(struct ci_hdrc *ci) | |||
600 | ci_otg_queue_work(ci); | 600 | ci_otg_queue_work(ci); |
601 | if (ci->id_event) | 601 | if (ci->id_event) |
602 | ci->id_event = false; | 602 | ci->id_event = false; |
603 | } else if (ci->transceiver->state == OTG_STATE_B_IDLE) { | 603 | } else if (ci->fsm.otg->state == OTG_STATE_B_IDLE) { |
604 | if (ci->fsm.b_sess_vld) { | 604 | if (ci->fsm.b_sess_vld) { |
605 | ci->fsm.power_up = 0; | 605 | ci->fsm.power_up = 0; |
606 | /* | 606 | /* |
@@ -627,7 +627,7 @@ static void ci_otg_fsm_event(struct ci_hdrc *ci) | |||
627 | otg_bsess_vld = hw_read_otgsc(ci, OTGSC_BSV); | 627 | otg_bsess_vld = hw_read_otgsc(ci, OTGSC_BSV); |
628 | port_conn = hw_read(ci, OP_PORTSC, PORTSC_CCS); | 628 | port_conn = hw_read(ci, OP_PORTSC, PORTSC_CCS); |
629 | 629 | ||
630 | switch (ci->transceiver->state) { | 630 | switch (ci->fsm.otg->state) { |
631 | case OTG_STATE_A_WAIT_BCON: | 631 | case OTG_STATE_A_WAIT_BCON: |
632 | if (port_conn) { | 632 | if (port_conn) { |
633 | fsm->b_conn = 1; | 633 | fsm->b_conn = 1; |
@@ -778,20 +778,17 @@ void ci_hdrc_otg_fsm_start(struct ci_hdrc *ci) | |||
778 | int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci) | 778 | int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci) |
779 | { | 779 | { |
780 | int retval = 0; | 780 | int retval = 0; |
781 | struct usb_otg *otg; | ||
782 | 781 | ||
783 | otg = devm_kzalloc(ci->dev, | 782 | if (ci->phy) |
784 | sizeof(struct usb_otg), GFP_KERNEL); | 783 | ci->otg.phy = ci->phy; |
785 | if (!otg) | 784 | else |
786 | return -ENOMEM; | 785 | ci->otg.usb_phy = ci->usb_phy; |
787 | 786 | ||
788 | otg->phy = ci->transceiver; | 787 | ci->otg.gadget = &ci->gadget; |
789 | otg->gadget = &ci->gadget; | 788 | ci->fsm.otg = &ci->otg; |
790 | ci->fsm.otg = otg; | ||
791 | ci->transceiver->otg = ci->fsm.otg; | ||
792 | ci->fsm.power_up = 1; | 789 | ci->fsm.power_up = 1; |
793 | ci->fsm.id = hw_read_otgsc(ci, OTGSC_ID) ? 1 : 0; | 790 | ci->fsm.id = hw_read_otgsc(ci, OTGSC_ID) ? 1 : 0; |
794 | ci->transceiver->state = OTG_STATE_UNDEFINED; | 791 | ci->fsm.otg->state = OTG_STATE_UNDEFINED; |
795 | ci->fsm.ops = &ci_otg_ops; | 792 | ci->fsm.ops = &ci_otg_ops; |
796 | 793 | ||
797 | mutex_init(&ci->fsm.lock); | 794 | mutex_init(&ci->fsm.lock); |
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 0444d3f8971a..bdaa7bac6f4a 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c | |||
@@ -692,10 +692,8 @@ __acquires(ci->lock) | |||
692 | int retval; | 692 | int retval; |
693 | 693 | ||
694 | spin_unlock(&ci->lock); | 694 | spin_unlock(&ci->lock); |
695 | if (ci->gadget.speed != USB_SPEED_UNKNOWN) { | 695 | if (ci->gadget.speed != USB_SPEED_UNKNOWN) |
696 | if (ci->driver) | 696 | usb_gadget_udc_reset(&ci->gadget, ci->driver); |
697 | ci->driver->disconnect(&ci->gadget); | ||
698 | } | ||
699 | 697 | ||
700 | retval = _gadget_stop_activity(&ci->gadget); | 698 | retval = _gadget_stop_activity(&ci->gadget); |
701 | if (retval) | 699 | if (retval) |
@@ -709,8 +707,6 @@ __acquires(ci->lock) | |||
709 | if (ci->status == NULL) | 707 | if (ci->status == NULL) |
710 | retval = -ENOMEM; | 708 | retval = -ENOMEM; |
711 | 709 | ||
712 | usb_gadget_set_state(&ci->gadget, USB_STATE_DEFAULT); | ||
713 | |||
714 | done: | 710 | done: |
715 | spin_lock(&ci->lock); | 711 | spin_lock(&ci->lock); |
716 | 712 | ||
@@ -1519,8 +1515,8 @@ static int ci_udc_vbus_draw(struct usb_gadget *_gadget, unsigned ma) | |||
1519 | { | 1515 | { |
1520 | struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); | 1516 | struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); |
1521 | 1517 | ||
1522 | if (ci->transceiver) | 1518 | if (ci->usb_phy) |
1523 | return usb_phy_set_power(ci->transceiver, ma); | 1519 | return usb_phy_set_power(ci->usb_phy, ma); |
1524 | return -ENOTSUPP; | 1520 | return -ENOTSUPP; |
1525 | } | 1521 | } |
1526 | 1522 | ||
@@ -1544,8 +1540,7 @@ static int ci_udc_pullup(struct usb_gadget *_gadget, int is_on) | |||
1544 | 1540 | ||
1545 | static int ci_udc_start(struct usb_gadget *gadget, | 1541 | static int ci_udc_start(struct usb_gadget *gadget, |
1546 | struct usb_gadget_driver *driver); | 1542 | struct usb_gadget_driver *driver); |
1547 | static int ci_udc_stop(struct usb_gadget *gadget, | 1543 | static int ci_udc_stop(struct usb_gadget *gadget); |
1548 | struct usb_gadget_driver *driver); | ||
1549 | /** | 1544 | /** |
1550 | * Device operations part of the API to the USB controller hardware, | 1545 | * Device operations part of the API to the USB controller hardware, |
1551 | * which don't involve endpoints (or i/o) | 1546 | * which don't involve endpoints (or i/o) |
@@ -1682,8 +1677,7 @@ static int ci_udc_start(struct usb_gadget *gadget, | |||
1682 | /** | 1677 | /** |
1683 | * ci_udc_stop: unregister a gadget driver | 1678 | * ci_udc_stop: unregister a gadget driver |
1684 | */ | 1679 | */ |
1685 | static int ci_udc_stop(struct usb_gadget *gadget, | 1680 | static int ci_udc_stop(struct usb_gadget *gadget) |
1686 | struct usb_gadget_driver *driver) | ||
1687 | { | 1681 | { |
1688 | struct ci_hdrc *ci = container_of(gadget, struct ci_hdrc, gadget); | 1682 | struct ci_hdrc *ci = container_of(gadget, struct ci_hdrc, gadget); |
1689 | unsigned long flags; | 1683 | unsigned long flags; |
diff --git a/drivers/usb/common/usb-otg-fsm.c b/drivers/usb/common/usb-otg-fsm.c index 98e8340a5bb1..c6b35b77dab7 100644 --- a/drivers/usb/common/usb-otg-fsm.c +++ b/drivers/usb/common/usb-otg-fsm.c | |||
@@ -124,10 +124,10 @@ static void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state) | |||
124 | static int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) | 124 | static int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) |
125 | { | 125 | { |
126 | state_changed = 1; | 126 | state_changed = 1; |
127 | if (fsm->otg->phy->state == new_state) | 127 | if (fsm->otg->state == new_state) |
128 | return 0; | 128 | return 0; |
129 | VDBG("Set state: %s\n", usb_otg_state_string(new_state)); | 129 | VDBG("Set state: %s\n", usb_otg_state_string(new_state)); |
130 | otg_leave_state(fsm, fsm->otg->phy->state); | 130 | otg_leave_state(fsm, fsm->otg->state); |
131 | switch (new_state) { | 131 | switch (new_state) { |
132 | case OTG_STATE_B_IDLE: | 132 | case OTG_STATE_B_IDLE: |
133 | otg_drv_vbus(fsm, 0); | 133 | otg_drv_vbus(fsm, 0); |
@@ -236,7 +236,7 @@ static int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) | |||
236 | break; | 236 | break; |
237 | } | 237 | } |
238 | 238 | ||
239 | fsm->otg->phy->state = new_state; | 239 | fsm->otg->state = new_state; |
240 | return 0; | 240 | return 0; |
241 | } | 241 | } |
242 | 242 | ||
@@ -247,7 +247,7 @@ int otg_statemachine(struct otg_fsm *fsm) | |||
247 | 247 | ||
248 | mutex_lock(&fsm->lock); | 248 | mutex_lock(&fsm->lock); |
249 | 249 | ||
250 | state = fsm->otg->phy->state; | 250 | state = fsm->otg->state; |
251 | state_changed = 0; | 251 | state_changed = 0; |
252 | /* State machine state change judgement */ | 252 | /* State machine state change judgement */ |
253 | 253 | ||
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index a6efb4184f2b..2f2118fa36a8 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -2650,7 +2650,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2650 | } | 2650 | } |
2651 | } | 2651 | } |
2652 | 2652 | ||
2653 | if (IS_ENABLED(CONFIG_GENERIC_PHY)) { | 2653 | if (IS_ENABLED(CONFIG_GENERIC_PHY) && !hcd->phy) { |
2654 | struct phy *phy = phy_get(hcd->self.controller, "usb"); | 2654 | struct phy *phy = phy_get(hcd->self.controller, "usb"); |
2655 | 2655 | ||
2656 | if (IS_ERR(phy)) { | 2656 | if (IS_ERR(phy)) { |
@@ -2670,6 +2670,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2670 | goto err_phy; | 2670 | goto err_phy; |
2671 | } | 2671 | } |
2672 | hcd->phy = phy; | 2672 | hcd->phy = phy; |
2673 | hcd->remove_phy = 1; | ||
2673 | } | 2674 | } |
2674 | } | 2675 | } |
2675 | 2676 | ||
@@ -2816,7 +2817,7 @@ err_allocate_root_hub: | |||
2816 | err_register_bus: | 2817 | err_register_bus: |
2817 | hcd_buffer_destroy(hcd); | 2818 | hcd_buffer_destroy(hcd); |
2818 | err_create_buf: | 2819 | err_create_buf: |
2819 | if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->phy) { | 2820 | if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->remove_phy && hcd->phy) { |
2820 | phy_power_off(hcd->phy); | 2821 | phy_power_off(hcd->phy); |
2821 | phy_exit(hcd->phy); | 2822 | phy_exit(hcd->phy); |
2822 | phy_put(hcd->phy); | 2823 | phy_put(hcd->phy); |
@@ -2900,7 +2901,7 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2900 | usb_deregister_bus(&hcd->self); | 2901 | usb_deregister_bus(&hcd->self); |
2901 | hcd_buffer_destroy(hcd); | 2902 | hcd_buffer_destroy(hcd); |
2902 | 2903 | ||
2903 | if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->phy) { | 2904 | if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->remove_phy && hcd->phy) { |
2904 | phy_power_off(hcd->phy); | 2905 | phy_power_off(hcd->phy); |
2905 | phy_exit(hcd->phy); | 2906 | phy_exit(hcd->phy); |
2906 | phy_put(hcd->phy); | 2907 | phy_put(hcd->phy); |
diff --git a/drivers/usb/dwc2/Kconfig b/drivers/usb/dwc2/Kconfig index f93807b3631a..b323c4c11b0a 100644 --- a/drivers/usb/dwc2/Kconfig +++ b/drivers/usb/dwc2/Kconfig | |||
@@ -1,6 +1,6 @@ | |||
1 | config USB_DWC2 | 1 | config USB_DWC2 |
2 | bool "DesignWare USB2 DRD Core Support" | 2 | tristate "DesignWare USB2 DRD Core Support" |
3 | depends on USB | 3 | depends on USB || USB_GADGET |
4 | help | 4 | help |
5 | Say Y here if your system has a Dual Role Hi-Speed USB | 5 | Say Y here if your system has a Dual Role Hi-Speed USB |
6 | controller based on the DesignWare HSOTG IP Core. | 6 | controller based on the DesignWare HSOTG IP Core. |
@@ -10,49 +10,61 @@ config USB_DWC2 | |||
10 | bus interface module (if you have a PCI bus system) will be | 10 | bus interface module (if you have a PCI bus system) will be |
11 | called dwc2_pci.ko, and the platform interface module (for | 11 | called dwc2_pci.ko, and the platform interface module (for |
12 | controllers directly connected to the CPU) will be called | 12 | controllers directly connected to the CPU) will be called |
13 | dwc2_platform.ko. For gadget mode, there will be a single | 13 | dwc2_platform.ko. For all modes(host, gadget and dual-role), there |
14 | module called dwc2_gadget.ko. | 14 | will be an additional module named dwc2.ko. |
15 | |||
16 | NOTE: The s3c-hsotg driver is now renamed to dwc2_gadget. The | ||
17 | host and gadget drivers are still currently separate drivers. | ||
18 | There are plans to merge the dwc2_gadget driver with the dwc2 | ||
19 | host driver in the near future to create a dual-role driver. | ||
20 | 15 | ||
21 | if USB_DWC2 | 16 | if USB_DWC2 |
22 | 17 | ||
18 | choice | ||
19 | bool "DWC2 Mode Selection" | ||
20 | default USB_DWC2_DUAL_ROLE if (USB && USB_GADGET) | ||
21 | default USB_DWC2_HOST if (USB && !USB_GADGET) | ||
22 | default USB_DWC2_PERIPHERAL if (!USB && USB_GADGET) | ||
23 | |||
23 | config USB_DWC2_HOST | 24 | config USB_DWC2_HOST |
24 | tristate "Host only mode" | 25 | bool "Host only mode" |
25 | depends on USB | 26 | depends on USB |
26 | help | 27 | help |
27 | The Designware USB2.0 high-speed host controller | 28 | The Designware USB2.0 high-speed host controller |
28 | integrated into many SoCs. | 29 | integrated into many SoCs. Select this option if you want the |
30 | driver to operate in Host-only mode. | ||
29 | 31 | ||
30 | config USB_DWC2_PLATFORM | 32 | comment "Gadget/Dual-role mode requires USB Gadget support to be enabled" |
31 | bool "DWC2 Platform" | 33 | |
32 | depends on USB_DWC2_HOST | 34 | config USB_DWC2_PERIPHERAL |
33 | default USB_DWC2_HOST | 35 | bool "Gadget only mode" |
36 | depends on USB_GADGET=y || USB_GADGET=USB_DWC2 | ||
34 | help | 37 | help |
35 | The Designware USB2.0 platform interface module for | 38 | The Designware USB2.0 high-speed gadget controller |
36 | controllers directly connected to the CPU. This is only | 39 | integrated into many SoCs. Select this option if you want the |
37 | used for host mode. | 40 | driver to operate in Peripheral-only mode. This option requires |
41 | USB_GADGET to be enabled. | ||
42 | |||
43 | config USB_DWC2_DUAL_ROLE | ||
44 | bool "Dual Role mode" | ||
45 | depends on (USB=y || USB=USB_DWC2) && (USB_GADGET=y || USB_GADGET=USB_DWC2) | ||
46 | help | ||
47 | Select this option if you want the driver to work in a dual-role | ||
48 | mode. In this mode both host and gadget features are enabled, and | ||
49 | the role will be determined by the cable that gets plugged-in. This | ||
50 | option requires USB_GADGET to be enabled. | ||
51 | endchoice | ||
52 | |||
53 | config USB_DWC2_PLATFORM | ||
54 | tristate "DWC2 Platform" | ||
55 | default USB_DWC2_HOST || USB_DWC2_PERIPHERAL | ||
56 | help | ||
57 | The Designware USB2.0 platform interface module for | ||
58 | controllers directly connected to the CPU. | ||
38 | 59 | ||
39 | config USB_DWC2_PCI | 60 | config USB_DWC2_PCI |
40 | bool "DWC2 PCI" | 61 | tristate "DWC2 PCI" |
41 | depends on USB_DWC2_HOST && PCI | 62 | depends on USB_DWC2_HOST && PCI |
42 | default USB_DWC2_HOST | 63 | default USB_DWC2_HOST |
43 | help | 64 | help |
44 | The Designware USB2.0 PCI interface module for controllers | 65 | The Designware USB2.0 PCI interface module for controllers |
45 | connected to a PCI bus. This is only used for host mode. | 66 | connected to a PCI bus. This is only used for host mode. |
46 | 67 | ||
47 | comment "Gadget mode requires USB Gadget support to be enabled" | ||
48 | |||
49 | config USB_DWC2_PERIPHERAL | ||
50 | tristate "Gadget only mode" | ||
51 | depends on USB_GADGET | ||
52 | help | ||
53 | The Designware USB2.0 high-speed gadget controller | ||
54 | integrated into many SoCs. | ||
55 | |||
56 | config USB_DWC2_DEBUG | 68 | config USB_DWC2_DEBUG |
57 | bool "Enable Debugging Messages" | 69 | bool "Enable Debugging Messages" |
58 | help | 70 | help |
diff --git a/drivers/usb/dwc2/Makefile b/drivers/usb/dwc2/Makefile index b73d2a527970..8f752679752a 100644 --- a/drivers/usb/dwc2/Makefile +++ b/drivers/usb/dwc2/Makefile | |||
@@ -1,28 +1,28 @@ | |||
1 | ccflags-$(CONFIG_USB_DWC2_DEBUG) += -DDEBUG | 1 | ccflags-$(CONFIG_USB_DWC2_DEBUG) += -DDEBUG |
2 | ccflags-$(CONFIG_USB_DWC2_VERBOSE) += -DVERBOSE_DEBUG | 2 | ccflags-$(CONFIG_USB_DWC2_VERBOSE) += -DVERBOSE_DEBUG |
3 | 3 | ||
4 | obj-$(CONFIG_USB_DWC2_HOST) += dwc2.o | 4 | obj-$(CONFIG_USB_DWC2) += dwc2.o |
5 | dwc2-y := core.o core_intr.o | 5 | dwc2-y := core.o core_intr.o |
6 | dwc2-y += hcd.o hcd_intr.o | 6 | |
7 | dwc2-y += hcd_queue.o hcd_ddma.o | 7 | ifneq ($(filter y,$(CONFIG_USB_DWC2_HOST) $(CONFIG_USB_DWC2_DUAL_ROLE)),) |
8 | dwc2-y += hcd.o hcd_intr.o | ||
9 | dwc2-y += hcd_queue.o hcd_ddma.o | ||
10 | endif | ||
11 | |||
12 | ifneq ($(filter y,$(CONFIG_USB_DWC2_PERIPHERAL) $(CONFIG_USB_DWC2_DUAL_ROLE)),) | ||
13 | dwc2-y += gadget.o | ||
14 | endif | ||
8 | 15 | ||
9 | # NOTE: The previous s3c-hsotg peripheral mode only driver has been moved to | 16 | # NOTE: The previous s3c-hsotg peripheral mode only driver has been moved to |
10 | # this location and renamed gadget.c. When building for dynamically linked | 17 | # this location and renamed gadget.c. When building for dynamically linked |
11 | # modules, dwc2_gadget.ko will get built for peripheral mode. For host mode, | 18 | # modules, dwc2.ko will get built for host mode, peripheral mode, and dual-role |
12 | # the core module will be dwc2.ko, the PCI bus interface module will called | 19 | # mode. The PCI bus interface module will called dwc2_pci.ko and the platform |
13 | # dwc2_pci.ko and the platform interface module will be called dwc2_platform.ko. | 20 | # interface module will be called dwc2_platform.ko. |
14 | # At present the host and gadget driver will be separate drivers, but there | ||
15 | # are plans in the near future to create a dual-role driver. | ||
16 | 21 | ||
17 | ifneq ($(CONFIG_USB_DWC2_PCI),) | 22 | ifneq ($(CONFIG_USB_DWC2_PCI),) |
18 | obj-$(CONFIG_USB_DWC2_HOST) += dwc2_pci.o | 23 | obj-$(CONFIG_USB_DWC2) += dwc2_pci.o |
19 | dwc2_pci-y := pci.o | 24 | dwc2_pci-y := pci.o |
20 | endif | 25 | endif |
21 | 26 | ||
22 | ifneq ($(CONFIG_USB_DWC2_PLATFORM),) | 27 | obj-$(CONFIG_USB_DWC2_PLATFORM) += dwc2_platform.o |
23 | obj-$(CONFIG_USB_DWC2_HOST) += dwc2_platform.o | 28 | dwc2_platform-y := platform.o |
24 | dwc2_platform-y := platform.o | ||
25 | endif | ||
26 | |||
27 | obj-$(CONFIG_USB_DWC2_PERIPHERAL) += dwc2_gadget.o | ||
28 | dwc2_gadget-y := gadget.o | ||
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index d9269459d481..7605850b7a9c 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c | |||
@@ -458,16 +458,6 @@ int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq) | |||
458 | /* Clear the SRP success bit for FS-I2c */ | 458 | /* Clear the SRP success bit for FS-I2c */ |
459 | hsotg->srp_success = 0; | 459 | hsotg->srp_success = 0; |
460 | 460 | ||
461 | if (irq >= 0) { | ||
462 | dev_dbg(hsotg->dev, "registering common handler for irq%d\n", | ||
463 | irq); | ||
464 | retval = devm_request_irq(hsotg->dev, irq, | ||
465 | dwc2_handle_common_intr, IRQF_SHARED, | ||
466 | dev_name(hsotg->dev), hsotg); | ||
467 | if (retval) | ||
468 | return retval; | ||
469 | } | ||
470 | |||
471 | /* Enable common interrupts */ | 461 | /* Enable common interrupts */ |
472 | dwc2_enable_common_interrupts(hsotg); | 462 | dwc2_enable_common_interrupts(hsotg); |
473 | 463 | ||
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 55c90c53f2d6..7a70a1349334 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h | |||
@@ -84,7 +84,7 @@ static const char * const s3c_hsotg_supply_names[] = { | |||
84 | */ | 84 | */ |
85 | #define EP0_MPS_LIMIT 64 | 85 | #define EP0_MPS_LIMIT 64 |
86 | 86 | ||
87 | struct s3c_hsotg; | 87 | struct dwc2_hsotg; |
88 | struct s3c_hsotg_req; | 88 | struct s3c_hsotg_req; |
89 | 89 | ||
90 | /** | 90 | /** |
@@ -130,7 +130,7 @@ struct s3c_hsotg_req; | |||
130 | struct s3c_hsotg_ep { | 130 | struct s3c_hsotg_ep { |
131 | struct usb_ep ep; | 131 | struct usb_ep ep; |
132 | struct list_head queue; | 132 | struct list_head queue; |
133 | struct s3c_hsotg *parent; | 133 | struct dwc2_hsotg *parent; |
134 | struct s3c_hsotg_req *req; | 134 | struct s3c_hsotg_req *req; |
135 | struct dentry *debugfs; | 135 | struct dentry *debugfs; |
136 | 136 | ||
@@ -155,67 +155,6 @@ struct s3c_hsotg_ep { | |||
155 | }; | 155 | }; |
156 | 156 | ||
157 | /** | 157 | /** |
158 | * struct s3c_hsotg - driver state. | ||
159 | * @dev: The parent device supplied to the probe function | ||
160 | * @driver: USB gadget driver | ||
161 | * @phy: The otg phy transceiver structure for phy control. | ||
162 | * @uphy: The otg phy transceiver structure for old USB phy control. | ||
163 | * @plat: The platform specific configuration data. This can be removed once | ||
164 | * all SoCs support usb transceiver. | ||
165 | * @regs: The memory area mapped for accessing registers. | ||
166 | * @irq: The IRQ number we are using | ||
167 | * @supplies: Definition of USB power supplies | ||
168 | * @phyif: PHY interface width | ||
169 | * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. | ||
170 | * @num_of_eps: Number of available EPs (excluding EP0) | ||
171 | * @debug_root: root directrory for debugfs. | ||
172 | * @debug_file: main status file for debugfs. | ||
173 | * @debug_fifo: FIFO status file for debugfs. | ||
174 | * @ep0_reply: Request used for ep0 reply. | ||
175 | * @ep0_buff: Buffer for EP0 reply data, if needed. | ||
176 | * @ctrl_buff: Buffer for EP0 control requests. | ||
177 | * @ctrl_req: Request for EP0 control packets. | ||
178 | * @setup: NAK management for EP0 SETUP | ||
179 | * @last_rst: Time of last reset | ||
180 | * @eps: The endpoints being supplied to the gadget framework | ||
181 | */ | ||
182 | struct s3c_hsotg { | ||
183 | struct device *dev; | ||
184 | struct usb_gadget_driver *driver; | ||
185 | struct phy *phy; | ||
186 | struct usb_phy *uphy; | ||
187 | struct s3c_hsotg_plat *plat; | ||
188 | |||
189 | spinlock_t lock; | ||
190 | |||
191 | void __iomem *regs; | ||
192 | int irq; | ||
193 | struct clk *clk; | ||
194 | |||
195 | struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; | ||
196 | |||
197 | u32 phyif; | ||
198 | int fifo_mem; | ||
199 | unsigned int dedicated_fifos:1; | ||
200 | unsigned char num_of_eps; | ||
201 | u32 fifo_map; | ||
202 | |||
203 | struct dentry *debug_root; | ||
204 | struct dentry *debug_file; | ||
205 | struct dentry *debug_fifo; | ||
206 | |||
207 | struct usb_request *ep0_reply; | ||
208 | struct usb_request *ctrl_req; | ||
209 | u8 ep0_buff[8]; | ||
210 | u8 ctrl_buff[8]; | ||
211 | |||
212 | struct usb_gadget gadget; | ||
213 | unsigned int setup; | ||
214 | unsigned long last_rst; | ||
215 | struct s3c_hsotg_ep *eps; | ||
216 | }; | ||
217 | |||
218 | /** | ||
219 | * struct s3c_hsotg_req - data transfer request | 158 | * struct s3c_hsotg_req - data transfer request |
220 | * @req: The USB gadget request | 159 | * @req: The USB gadget request |
221 | * @queue: The list of requests for the endpoint this is queued for. | 160 | * @queue: The list of requests for the endpoint this is queued for. |
@@ -229,6 +168,7 @@ struct s3c_hsotg_req { | |||
229 | unsigned char mapped; | 168 | unsigned char mapped; |
230 | }; | 169 | }; |
231 | 170 | ||
171 | #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) | ||
232 | #define call_gadget(_hs, _entry) \ | 172 | #define call_gadget(_hs, _entry) \ |
233 | do { \ | 173 | do { \ |
234 | if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \ | 174 | if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \ |
@@ -238,6 +178,9 @@ do { \ | |||
238 | spin_lock(&_hs->lock); \ | 178 | spin_lock(&_hs->lock); \ |
239 | } \ | 179 | } \ |
240 | } while (0) | 180 | } while (0) |
181 | #else | ||
182 | #define call_gadget(_hs, _entry) do {} while (0) | ||
183 | #endif | ||
241 | 184 | ||
242 | struct dwc2_hsotg; | 185 | struct dwc2_hsotg; |
243 | struct dwc2_host_chan; | 186 | struct dwc2_host_chan; |
@@ -495,11 +438,13 @@ struct dwc2_hw_params { | |||
495 | * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic | 438 | * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic |
496 | * and periodic schedules | 439 | * and periodic schedules |
497 | * | 440 | * |
441 | * These are common for both host and peripheral modes: | ||
442 | * | ||
498 | * @dev: The struct device pointer | 443 | * @dev: The struct device pointer |
499 | * @regs: Pointer to controller regs | 444 | * @regs: Pointer to controller regs |
500 | * @core_params: Parameters that define how the core should be configured | ||
501 | * @hw_params: Parameters that were autodetected from the | 445 | * @hw_params: Parameters that were autodetected from the |
502 | * hardware registers | 446 | * hardware registers |
447 | * @core_params: Parameters that define how the core should be configured | ||
503 | * @op_state: The operational State, during transitions (a_host=> | 448 | * @op_state: The operational State, during transitions (a_host=> |
504 | * a_peripheral and b_device=>b_host) this may not match | 449 | * a_peripheral and b_device=>b_host) this may not match |
505 | * the core, but allows the software to determine | 450 | * the core, but allows the software to determine |
@@ -508,6 +453,8 @@ struct dwc2_hw_params { | |||
508 | * - USB_DR_MODE_PERIPHERAL | 453 | * - USB_DR_MODE_PERIPHERAL |
509 | * - USB_DR_MODE_HOST | 454 | * - USB_DR_MODE_HOST |
510 | * - USB_DR_MODE_OTG | 455 | * - USB_DR_MODE_OTG |
456 | * @lock: Spinlock that protects all the driver data structures | ||
457 | * @priv: Stores a pointer to the struct usb_hcd | ||
511 | * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth | 458 | * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth |
512 | * transfer are in process of being queued | 459 | * transfer are in process of being queued |
513 | * @srp_success: Stores status of SRP request in the case of a FS PHY | 460 | * @srp_success: Stores status of SRP request in the case of a FS PHY |
@@ -517,6 +464,9 @@ struct dwc2_hw_params { | |||
517 | * interrupt | 464 | * interrupt |
518 | * @wkp_timer: Timer object for handling Wakeup Detected interrupt | 465 | * @wkp_timer: Timer object for handling Wakeup Detected interrupt |
519 | * @lx_state: Lx state of connected device | 466 | * @lx_state: Lx state of connected device |
467 | * | ||
468 | * These are for host mode: | ||
469 | * | ||
520 | * @flags: Flags for handling root port state changes | 470 | * @flags: Flags for handling root port state changes |
521 | * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule. | 471 | * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule. |
522 | * Transfers associated with these QHs are not currently | 472 | * Transfers associated with these QHs are not currently |
@@ -585,11 +535,31 @@ struct dwc2_hw_params { | |||
585 | * @status_buf_dma: DMA address for status_buf | 535 | * @status_buf_dma: DMA address for status_buf |
586 | * @start_work: Delayed work for handling host A-cable connection | 536 | * @start_work: Delayed work for handling host A-cable connection |
587 | * @reset_work: Delayed work for handling a port reset | 537 | * @reset_work: Delayed work for handling a port reset |
588 | * @lock: Spinlock that protects all the driver data structures | ||
589 | * @priv: Stores a pointer to the struct usb_hcd | ||
590 | * @otg_port: OTG port number | 538 | * @otg_port: OTG port number |
591 | * @frame_list: Frame list | 539 | * @frame_list: Frame list |
592 | * @frame_list_dma: Frame list DMA address | 540 | * @frame_list_dma: Frame list DMA address |
541 | * | ||
542 | * These are for peripheral mode: | ||
543 | * | ||
544 | * @driver: USB gadget driver | ||
545 | * @phy: The otg phy transceiver structure for phy control. | ||
546 | * @uphy: The otg phy transceiver structure for old USB phy control. | ||
547 | * @plat: The platform specific configuration data. This can be removed once | ||
548 | * all SoCs support usb transceiver. | ||
549 | * @supplies: Definition of USB power supplies | ||
550 | * @phyif: PHY interface width | ||
551 | * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. | ||
552 | * @num_of_eps: Number of available EPs (excluding EP0) | ||
553 | * @debug_root: Root directrory for debugfs. | ||
554 | * @debug_file: Main status file for debugfs. | ||
555 | * @debug_fifo: FIFO status file for debugfs. | ||
556 | * @ep0_reply: Request used for ep0 reply. | ||
557 | * @ep0_buff: Buffer for EP0 reply data, if needed. | ||
558 | * @ctrl_buff: Buffer for EP0 control requests. | ||
559 | * @ctrl_req: Request for EP0 control packets. | ||
560 | * @setup: NAK management for EP0 SETUP | ||
561 | * @last_rst: Time of last reset | ||
562 | * @eps: The endpoints being supplied to the gadget framework | ||
593 | */ | 563 | */ |
594 | struct dwc2_hsotg { | 564 | struct dwc2_hsotg { |
595 | struct device *dev; | 565 | struct device *dev; |
@@ -601,6 +571,16 @@ struct dwc2_hsotg { | |||
601 | enum usb_otg_state op_state; | 571 | enum usb_otg_state op_state; |
602 | enum usb_dr_mode dr_mode; | 572 | enum usb_dr_mode dr_mode; |
603 | 573 | ||
574 | struct phy *phy; | ||
575 | struct usb_phy *uphy; | ||
576 | struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; | ||
577 | |||
578 | spinlock_t lock; | ||
579 | struct mutex init_mutex; | ||
580 | void *priv; | ||
581 | int irq; | ||
582 | struct clk *clk; | ||
583 | |||
604 | unsigned int queuing_high_bandwidth:1; | 584 | unsigned int queuing_high_bandwidth:1; |
605 | unsigned int srp_success:1; | 585 | unsigned int srp_success:1; |
606 | 586 | ||
@@ -609,6 +589,18 @@ struct dwc2_hsotg { | |||
609 | struct timer_list wkp_timer; | 589 | struct timer_list wkp_timer; |
610 | enum dwc2_lx_state lx_state; | 590 | enum dwc2_lx_state lx_state; |
611 | 591 | ||
592 | struct dentry *debug_root; | ||
593 | struct dentry *debug_file; | ||
594 | struct dentry *debug_fifo; | ||
595 | |||
596 | /* DWC OTG HW Release versions */ | ||
597 | #define DWC2_CORE_REV_2_71a 0x4f54271a | ||
598 | #define DWC2_CORE_REV_2_90a 0x4f54290a | ||
599 | #define DWC2_CORE_REV_2_92a 0x4f54292a | ||
600 | #define DWC2_CORE_REV_2_94a 0x4f54294a | ||
601 | #define DWC2_CORE_REV_3_00a 0x4f54300a | ||
602 | |||
603 | #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) | ||
612 | union dwc2_hcd_internal_flags { | 604 | union dwc2_hcd_internal_flags { |
613 | u32 d32; | 605 | u32 d32; |
614 | struct { | 606 | struct { |
@@ -655,19 +647,10 @@ struct dwc2_hsotg { | |||
655 | 647 | ||
656 | struct delayed_work start_work; | 648 | struct delayed_work start_work; |
657 | struct delayed_work reset_work; | 649 | struct delayed_work reset_work; |
658 | spinlock_t lock; | ||
659 | void *priv; | ||
660 | u8 otg_port; | 650 | u8 otg_port; |
661 | u32 *frame_list; | 651 | u32 *frame_list; |
662 | dma_addr_t frame_list_dma; | 652 | dma_addr_t frame_list_dma; |
663 | 653 | ||
664 | /* DWC OTG HW Release versions */ | ||
665 | #define DWC2_CORE_REV_2_71a 0x4f54271a | ||
666 | #define DWC2_CORE_REV_2_90a 0x4f54290a | ||
667 | #define DWC2_CORE_REV_2_92a 0x4f54292a | ||
668 | #define DWC2_CORE_REV_2_94a 0x4f54294a | ||
669 | #define DWC2_CORE_REV_3_00a 0x4f54300a | ||
670 | |||
671 | #ifdef DEBUG | 654 | #ifdef DEBUG |
672 | u32 frrem_samples; | 655 | u32 frrem_samples; |
673 | u64 frrem_accum; | 656 | u64 frrem_accum; |
@@ -686,6 +669,31 @@ struct dwc2_hsotg { | |||
686 | u32 hfnum_other_samples_b; | 669 | u32 hfnum_other_samples_b; |
687 | u64 hfnum_other_frrem_accum_b; | 670 | u64 hfnum_other_frrem_accum_b; |
688 | #endif | 671 | #endif |
672 | #endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */ | ||
673 | |||
674 | #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) | ||
675 | /* Gadget structures */ | ||
676 | struct usb_gadget_driver *driver; | ||
677 | struct s3c_hsotg_plat *plat; | ||
678 | |||
679 | u32 phyif; | ||
680 | int fifo_mem; | ||
681 | unsigned int dedicated_fifos:1; | ||
682 | unsigned char num_of_eps; | ||
683 | u32 fifo_map; | ||
684 | |||
685 | struct usb_request *ep0_reply; | ||
686 | struct usb_request *ctrl_req; | ||
687 | u8 ep0_buff[8]; | ||
688 | u8 ctrl_buff[8]; | ||
689 | |||
690 | struct usb_gadget gadget; | ||
691 | unsigned int enabled:1; | ||
692 | unsigned int connected:1; | ||
693 | unsigned int setup:1; | ||
694 | unsigned long last_rst; | ||
695 | struct s3c_hsotg_ep *eps; | ||
696 | #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */ | ||
689 | }; | 697 | }; |
690 | 698 | ||
691 | /* Reasons for halting a host channel */ | 699 | /* Reasons for halting a host channel */ |
@@ -955,4 +963,43 @@ extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg); | |||
955 | */ | 963 | */ |
956 | extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg); | 964 | extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg); |
957 | 965 | ||
966 | /* Gadget defines */ | ||
967 | #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) | ||
968 | extern int s3c_hsotg_remove(struct dwc2_hsotg *hsotg); | ||
969 | extern int s3c_hsotg_suspend(struct dwc2_hsotg *dwc2); | ||
970 | extern int s3c_hsotg_resume(struct dwc2_hsotg *dwc2); | ||
971 | extern int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq); | ||
972 | extern void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2); | ||
973 | extern void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg); | ||
974 | extern void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2); | ||
975 | #else | ||
976 | static inline int s3c_hsotg_remove(struct dwc2_hsotg *dwc2) | ||
977 | { return 0; } | ||
978 | static inline int s3c_hsotg_suspend(struct dwc2_hsotg *dwc2) | ||
979 | { return 0; } | ||
980 | static inline int s3c_hsotg_resume(struct dwc2_hsotg *dwc2) | ||
981 | { return 0; } | ||
982 | static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) | ||
983 | { return 0; } | ||
984 | static inline void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2) {} | ||
985 | static inline void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg) {} | ||
986 | static inline void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2) {} | ||
987 | #endif | ||
988 | |||
989 | #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) | ||
990 | extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg); | ||
991 | extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg); | ||
992 | extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg); | ||
993 | #else | ||
994 | static inline void dwc2_set_all_params(struct dwc2_core_params *params, int value) {} | ||
995 | static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) | ||
996 | { return 0; } | ||
997 | static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {} | ||
998 | static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {} | ||
999 | static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {} | ||
1000 | static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, | ||
1001 | const struct dwc2_core_params *params) | ||
1002 | { return 0; } | ||
1003 | #endif | ||
1004 | |||
958 | #endif /* __DWC2_CORE_H__ */ | 1005 | #endif /* __DWC2_CORE_H__ */ |
diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c index c93918b70d03..ad43c5bc1ef1 100644 --- a/drivers/usb/dwc2/core_intr.c +++ b/drivers/usb/dwc2/core_intr.c | |||
@@ -128,6 +128,9 @@ static void dwc2_handle_otg_intr(struct dwc2_hsotg *hsotg) | |||
128 | dwc2_op_state_str(hsotg)); | 128 | dwc2_op_state_str(hsotg)); |
129 | gotgctl = readl(hsotg->regs + GOTGCTL); | 129 | gotgctl = readl(hsotg->regs + GOTGCTL); |
130 | 130 | ||
131 | if (dwc2_is_device_mode(hsotg)) | ||
132 | s3c_hsotg_disconnect(hsotg); | ||
133 | |||
131 | if (hsotg->op_state == OTG_STATE_B_HOST) { | 134 | if (hsotg->op_state == OTG_STATE_B_HOST) { |
132 | hsotg->op_state = OTG_STATE_B_PERIPHERAL; | 135 | hsotg->op_state = OTG_STATE_B_PERIPHERAL; |
133 | } else { | 136 | } else { |
@@ -287,9 +290,11 @@ static void dwc2_handle_conn_id_status_change_intr(struct dwc2_hsotg *hsotg) | |||
287 | * Release lock before scheduling workq as it holds spinlock during | 290 | * Release lock before scheduling workq as it holds spinlock during |
288 | * scheduling. | 291 | * scheduling. |
289 | */ | 292 | */ |
290 | spin_unlock(&hsotg->lock); | 293 | if (hsotg->wq_otg) { |
291 | queue_work(hsotg->wq_otg, &hsotg->wf_otg); | 294 | spin_unlock(&hsotg->lock); |
292 | spin_lock(&hsotg->lock); | 295 | queue_work(hsotg->wq_otg, &hsotg->wf_otg); |
296 | spin_lock(&hsotg->lock); | ||
297 | } | ||
293 | 298 | ||
294 | /* Clear interrupt */ | 299 | /* Clear interrupt */ |
295 | writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS); | 300 | writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS); |
@@ -312,6 +317,12 @@ static void dwc2_handle_session_req_intr(struct dwc2_hsotg *hsotg) | |||
312 | 317 | ||
313 | /* Clear interrupt */ | 318 | /* Clear interrupt */ |
314 | writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS); | 319 | writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS); |
320 | |||
321 | /* | ||
322 | * Report disconnect if there is any previous session established | ||
323 | */ | ||
324 | if (dwc2_is_device_mode(hsotg)) | ||
325 | s3c_hsotg_disconnect(hsotg); | ||
315 | } | 326 | } |
316 | 327 | ||
317 | /* | 328 | /* |
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 8b5c079c7b7d..200168ec2d75 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
22 | #include <linux/dma-mapping.h> | 22 | #include <linux/dma-mapping.h> |
23 | #include <linux/debugfs.h> | 23 | #include <linux/debugfs.h> |
24 | #include <linux/mutex.h> | ||
24 | #include <linux/seq_file.h> | 25 | #include <linux/seq_file.h> |
25 | #include <linux/delay.h> | 26 | #include <linux/delay.h> |
26 | #include <linux/io.h> | 27 | #include <linux/io.h> |
@@ -36,6 +37,7 @@ | |||
36 | #include <linux/platform_data/s3c-hsotg.h> | 37 | #include <linux/platform_data/s3c-hsotg.h> |
37 | 38 | ||
38 | #include "core.h" | 39 | #include "core.h" |
40 | #include "hw.h" | ||
39 | 41 | ||
40 | /* conversion functions */ | 42 | /* conversion functions */ |
41 | static inline struct s3c_hsotg_req *our_req(struct usb_request *req) | 43 | static inline struct s3c_hsotg_req *our_req(struct usb_request *req) |
@@ -48,9 +50,9 @@ static inline struct s3c_hsotg_ep *our_ep(struct usb_ep *ep) | |||
48 | return container_of(ep, struct s3c_hsotg_ep, ep); | 50 | return container_of(ep, struct s3c_hsotg_ep, ep); |
49 | } | 51 | } |
50 | 52 | ||
51 | static inline struct s3c_hsotg *to_hsotg(struct usb_gadget *gadget) | 53 | static inline struct dwc2_hsotg *to_hsotg(struct usb_gadget *gadget) |
52 | { | 54 | { |
53 | return container_of(gadget, struct s3c_hsotg, gadget); | 55 | return container_of(gadget, struct dwc2_hsotg, gadget); |
54 | } | 56 | } |
55 | 57 | ||
56 | static inline void __orr32(void __iomem *ptr, u32 val) | 58 | static inline void __orr32(void __iomem *ptr, u32 val) |
@@ -64,7 +66,7 @@ static inline void __bic32(void __iomem *ptr, u32 val) | |||
64 | } | 66 | } |
65 | 67 | ||
66 | /* forward decleration of functions */ | 68 | /* forward decleration of functions */ |
67 | static void s3c_hsotg_dump(struct s3c_hsotg *hsotg); | 69 | static void s3c_hsotg_dump(struct dwc2_hsotg *hsotg); |
68 | 70 | ||
69 | /** | 71 | /** |
70 | * using_dma - return the DMA status of the driver. | 72 | * using_dma - return the DMA status of the driver. |
@@ -85,7 +87,7 @@ static void s3c_hsotg_dump(struct s3c_hsotg *hsotg); | |||
85 | * | 87 | * |
86 | * Until this issue is sorted out, we always return 'false'. | 88 | * Until this issue is sorted out, we always return 'false'. |
87 | */ | 89 | */ |
88 | static inline bool using_dma(struct s3c_hsotg *hsotg) | 90 | static inline bool using_dma(struct dwc2_hsotg *hsotg) |
89 | { | 91 | { |
90 | return false; /* support is not complete */ | 92 | return false; /* support is not complete */ |
91 | } | 93 | } |
@@ -95,7 +97,7 @@ static inline bool using_dma(struct s3c_hsotg *hsotg) | |||
95 | * @hsotg: The device state | 97 | * @hsotg: The device state |
96 | * @ints: A bitmask of the interrupts to enable | 98 | * @ints: A bitmask of the interrupts to enable |
97 | */ | 99 | */ |
98 | static void s3c_hsotg_en_gsint(struct s3c_hsotg *hsotg, u32 ints) | 100 | static void s3c_hsotg_en_gsint(struct dwc2_hsotg *hsotg, u32 ints) |
99 | { | 101 | { |
100 | u32 gsintmsk = readl(hsotg->regs + GINTMSK); | 102 | u32 gsintmsk = readl(hsotg->regs + GINTMSK); |
101 | u32 new_gsintmsk; | 103 | u32 new_gsintmsk; |
@@ -113,7 +115,7 @@ static void s3c_hsotg_en_gsint(struct s3c_hsotg *hsotg, u32 ints) | |||
113 | * @hsotg: The device state | 115 | * @hsotg: The device state |
114 | * @ints: A bitmask of the interrupts to enable | 116 | * @ints: A bitmask of the interrupts to enable |
115 | */ | 117 | */ |
116 | static void s3c_hsotg_disable_gsint(struct s3c_hsotg *hsotg, u32 ints) | 118 | static void s3c_hsotg_disable_gsint(struct dwc2_hsotg *hsotg, u32 ints) |
117 | { | 119 | { |
118 | u32 gsintmsk = readl(hsotg->regs + GINTMSK); | 120 | u32 gsintmsk = readl(hsotg->regs + GINTMSK); |
119 | u32 new_gsintmsk; | 121 | u32 new_gsintmsk; |
@@ -134,7 +136,7 @@ static void s3c_hsotg_disable_gsint(struct s3c_hsotg *hsotg, u32 ints) | |||
134 | * Set or clear the mask for an individual endpoint's interrupt | 136 | * Set or clear the mask for an individual endpoint's interrupt |
135 | * request. | 137 | * request. |
136 | */ | 138 | */ |
137 | static void s3c_hsotg_ctrl_epint(struct s3c_hsotg *hsotg, | 139 | static void s3c_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg, |
138 | unsigned int ep, unsigned int dir_in, | 140 | unsigned int ep, unsigned int dir_in, |
139 | unsigned int en) | 141 | unsigned int en) |
140 | { | 142 | { |
@@ -159,7 +161,7 @@ static void s3c_hsotg_ctrl_epint(struct s3c_hsotg *hsotg, | |||
159 | * s3c_hsotg_init_fifo - initialise non-periodic FIFOs | 161 | * s3c_hsotg_init_fifo - initialise non-periodic FIFOs |
160 | * @hsotg: The device instance. | 162 | * @hsotg: The device instance. |
161 | */ | 163 | */ |
162 | static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) | 164 | static void s3c_hsotg_init_fifo(struct dwc2_hsotg *hsotg) |
163 | { | 165 | { |
164 | unsigned int ep; | 166 | unsigned int ep; |
165 | unsigned int addr; | 167 | unsigned int addr; |
@@ -283,7 +285,7 @@ static inline int is_ep_periodic(struct s3c_hsotg_ep *hs_ep) | |||
283 | * This is the reverse of s3c_hsotg_map_dma(), called for the completion | 285 | * This is the reverse of s3c_hsotg_map_dma(), called for the completion |
284 | * of a request to ensure the buffer is ready for access by the caller. | 286 | * of a request to ensure the buffer is ready for access by the caller. |
285 | */ | 287 | */ |
286 | static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, | 288 | static void s3c_hsotg_unmap_dma(struct dwc2_hsotg *hsotg, |
287 | struct s3c_hsotg_ep *hs_ep, | 289 | struct s3c_hsotg_ep *hs_ep, |
288 | struct s3c_hsotg_req *hs_req) | 290 | struct s3c_hsotg_req *hs_req) |
289 | { | 291 | { |
@@ -312,7 +314,7 @@ static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, | |||
312 | * | 314 | * |
313 | * This routine is only needed for PIO | 315 | * This routine is only needed for PIO |
314 | */ | 316 | */ |
315 | static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | 317 | static int s3c_hsotg_write_fifo(struct dwc2_hsotg *hsotg, |
316 | struct s3c_hsotg_ep *hs_ep, | 318 | struct s3c_hsotg_ep *hs_ep, |
317 | struct s3c_hsotg_req *hs_req) | 319 | struct s3c_hsotg_req *hs_req) |
318 | { | 320 | { |
@@ -517,7 +519,7 @@ static unsigned get_ep_limit(struct s3c_hsotg_ep *hs_ep) | |||
517 | * Start the given request running by setting the endpoint registers | 519 | * Start the given request running by setting the endpoint registers |
518 | * appropriately, and writing any data to the FIFOs. | 520 | * appropriately, and writing any data to the FIFOs. |
519 | */ | 521 | */ |
520 | static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | 522 | static void s3c_hsotg_start_req(struct dwc2_hsotg *hsotg, |
521 | struct s3c_hsotg_ep *hs_ep, | 523 | struct s3c_hsotg_ep *hs_ep, |
522 | struct s3c_hsotg_req *hs_req, | 524 | struct s3c_hsotg_req *hs_req, |
523 | bool continuing) | 525 | bool continuing) |
@@ -707,7 +709,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
707 | * DMA memory, then we map the memory and mark our request to allow us to | 709 | * DMA memory, then we map the memory and mark our request to allow us to |
708 | * cleanup on completion. | 710 | * cleanup on completion. |
709 | */ | 711 | */ |
710 | static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg, | 712 | static int s3c_hsotg_map_dma(struct dwc2_hsotg *hsotg, |
711 | struct s3c_hsotg_ep *hs_ep, | 713 | struct s3c_hsotg_ep *hs_ep, |
712 | struct usb_request *req) | 714 | struct usb_request *req) |
713 | { | 715 | { |
@@ -736,7 +738,7 @@ static int s3c_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req, | |||
736 | { | 738 | { |
737 | struct s3c_hsotg_req *hs_req = our_req(req); | 739 | struct s3c_hsotg_req *hs_req = our_req(req); |
738 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 740 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
739 | struct s3c_hsotg *hs = hs_ep->parent; | 741 | struct dwc2_hsotg *hs = hs_ep->parent; |
740 | bool first; | 742 | bool first; |
741 | 743 | ||
742 | dev_dbg(hs->dev, "%s: req %p: %d@%p, noi=%d, zero=%d, snok=%d\n", | 744 | dev_dbg(hs->dev, "%s: req %p: %d@%p, noi=%d, zero=%d, snok=%d\n", |
@@ -768,7 +770,7 @@ static int s3c_hsotg_ep_queue_lock(struct usb_ep *ep, struct usb_request *req, | |||
768 | gfp_t gfp_flags) | 770 | gfp_t gfp_flags) |
769 | { | 771 | { |
770 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 772 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
771 | struct s3c_hsotg *hs = hs_ep->parent; | 773 | struct dwc2_hsotg *hs = hs_ep->parent; |
772 | unsigned long flags = 0; | 774 | unsigned long flags = 0; |
773 | int ret = 0; | 775 | int ret = 0; |
774 | 776 | ||
@@ -799,7 +801,7 @@ static void s3c_hsotg_complete_oursetup(struct usb_ep *ep, | |||
799 | struct usb_request *req) | 801 | struct usb_request *req) |
800 | { | 802 | { |
801 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 803 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
802 | struct s3c_hsotg *hsotg = hs_ep->parent; | 804 | struct dwc2_hsotg *hsotg = hs_ep->parent; |
803 | 805 | ||
804 | dev_dbg(hsotg->dev, "%s: ep %p, req %p\n", __func__, ep, req); | 806 | dev_dbg(hsotg->dev, "%s: ep %p, req %p\n", __func__, ep, req); |
805 | 807 | ||
@@ -814,7 +816,7 @@ static void s3c_hsotg_complete_oursetup(struct usb_ep *ep, | |||
814 | * Convert the given wIndex into a pointer to an driver endpoint | 816 | * Convert the given wIndex into a pointer to an driver endpoint |
815 | * structure, or return NULL if it is not a valid endpoint. | 817 | * structure, or return NULL if it is not a valid endpoint. |
816 | */ | 818 | */ |
817 | static struct s3c_hsotg_ep *ep_from_windex(struct s3c_hsotg *hsotg, | 819 | static struct s3c_hsotg_ep *ep_from_windex(struct dwc2_hsotg *hsotg, |
818 | u32 windex) | 820 | u32 windex) |
819 | { | 821 | { |
820 | struct s3c_hsotg_ep *ep = &hsotg->eps[windex & 0x7F]; | 822 | struct s3c_hsotg_ep *ep = &hsotg->eps[windex & 0x7F]; |
@@ -843,7 +845,7 @@ static struct s3c_hsotg_ep *ep_from_windex(struct s3c_hsotg *hsotg, | |||
843 | * Create a request and queue it on the given endpoint. This is useful as | 845 | * Create a request and queue it on the given endpoint. This is useful as |
844 | * an internal method of sending replies to certain control requests, etc. | 846 | * an internal method of sending replies to certain control requests, etc. |
845 | */ | 847 | */ |
846 | static int s3c_hsotg_send_reply(struct s3c_hsotg *hsotg, | 848 | static int s3c_hsotg_send_reply(struct dwc2_hsotg *hsotg, |
847 | struct s3c_hsotg_ep *ep, | 849 | struct s3c_hsotg_ep *ep, |
848 | void *buff, | 850 | void *buff, |
849 | int length) | 851 | int length) |
@@ -884,7 +886,7 @@ static int s3c_hsotg_send_reply(struct s3c_hsotg *hsotg, | |||
884 | * @hsotg: The device state | 886 | * @hsotg: The device state |
885 | * @ctrl: USB control request | 887 | * @ctrl: USB control request |
886 | */ | 888 | */ |
887 | static int s3c_hsotg_process_req_status(struct s3c_hsotg *hsotg, | 889 | static int s3c_hsotg_process_req_status(struct dwc2_hsotg *hsotg, |
888 | struct usb_ctrlrequest *ctrl) | 890 | struct usb_ctrlrequest *ctrl) |
889 | { | 891 | { |
890 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; | 892 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; |
@@ -955,7 +957,7 @@ static struct s3c_hsotg_req *get_ep_head(struct s3c_hsotg_ep *hs_ep) | |||
955 | * @hsotg: The device state | 957 | * @hsotg: The device state |
956 | * @ctrl: USB control request | 958 | * @ctrl: USB control request |
957 | */ | 959 | */ |
958 | static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, | 960 | static int s3c_hsotg_process_req_feature(struct dwc2_hsotg *hsotg, |
959 | struct usb_ctrlrequest *ctrl) | 961 | struct usb_ctrlrequest *ctrl) |
960 | { | 962 | { |
961 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; | 963 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; |
@@ -1028,8 +1030,7 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, | |||
1028 | return 1; | 1030 | return 1; |
1029 | } | 1031 | } |
1030 | 1032 | ||
1031 | static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg); | 1033 | static void s3c_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg); |
1032 | static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg); | ||
1033 | 1034 | ||
1034 | /** | 1035 | /** |
1035 | * s3c_hsotg_stall_ep0 - stall ep0 | 1036 | * s3c_hsotg_stall_ep0 - stall ep0 |
@@ -1037,7 +1038,7 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg); | |||
1037 | * | 1038 | * |
1038 | * Set stall for ep0 as response for setup request. | 1039 | * Set stall for ep0 as response for setup request. |
1039 | */ | 1040 | */ |
1040 | static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg) | 1041 | static void s3c_hsotg_stall_ep0(struct dwc2_hsotg *hsotg) |
1041 | { | 1042 | { |
1042 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; | 1043 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; |
1043 | u32 reg; | 1044 | u32 reg; |
@@ -1076,7 +1077,7 @@ static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg) | |||
1076 | * needs to work out what to do next (and whether to pass it on to the | 1077 | * needs to work out what to do next (and whether to pass it on to the |
1077 | * gadget driver). | 1078 | * gadget driver). |
1078 | */ | 1079 | */ |
1079 | static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, | 1080 | static void s3c_hsotg_process_control(struct dwc2_hsotg *hsotg, |
1080 | struct usb_ctrlrequest *ctrl) | 1081 | struct usb_ctrlrequest *ctrl) |
1081 | { | 1082 | { |
1082 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; | 1083 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; |
@@ -1107,7 +1108,6 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, | |||
1107 | if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { | 1108 | if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { |
1108 | switch (ctrl->bRequest) { | 1109 | switch (ctrl->bRequest) { |
1109 | case USB_REQ_SET_ADDRESS: | 1110 | case USB_REQ_SET_ADDRESS: |
1110 | s3c_hsotg_disconnect(hsotg); | ||
1111 | dcfg = readl(hsotg->regs + DCFG); | 1111 | dcfg = readl(hsotg->regs + DCFG); |
1112 | dcfg &= ~DCFG_DEVADDR_MASK; | 1112 | dcfg &= ~DCFG_DEVADDR_MASK; |
1113 | dcfg |= (le16_to_cpu(ctrl->wValue) << | 1113 | dcfg |= (le16_to_cpu(ctrl->wValue) << |
@@ -1161,7 +1161,7 @@ static void s3c_hsotg_complete_setup(struct usb_ep *ep, | |||
1161 | struct usb_request *req) | 1161 | struct usb_request *req) |
1162 | { | 1162 | { |
1163 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 1163 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
1164 | struct s3c_hsotg *hsotg = hs_ep->parent; | 1164 | struct dwc2_hsotg *hsotg = hs_ep->parent; |
1165 | 1165 | ||
1166 | if (req->status < 0) { | 1166 | if (req->status < 0) { |
1167 | dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status); | 1167 | dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status); |
@@ -1183,7 +1183,7 @@ static void s3c_hsotg_complete_setup(struct usb_ep *ep, | |||
1183 | * Enqueue a request on EP0 if necessary to received any SETUP packets | 1183 | * Enqueue a request on EP0 if necessary to received any SETUP packets |
1184 | * received from the host. | 1184 | * received from the host. |
1185 | */ | 1185 | */ |
1186 | static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg) | 1186 | static void s3c_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg) |
1187 | { | 1187 | { |
1188 | struct usb_request *req = hsotg->ctrl_req; | 1188 | struct usb_request *req = hsotg->ctrl_req; |
1189 | struct s3c_hsotg_req *hs_req = our_req(req); | 1189 | struct s3c_hsotg_req *hs_req = our_req(req); |
@@ -1226,7 +1226,7 @@ static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg) | |||
1226 | * | 1226 | * |
1227 | * Note, expects the ep to already be locked as appropriate. | 1227 | * Note, expects the ep to already be locked as appropriate. |
1228 | */ | 1228 | */ |
1229 | static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | 1229 | static void s3c_hsotg_complete_request(struct dwc2_hsotg *hsotg, |
1230 | struct s3c_hsotg_ep *hs_ep, | 1230 | struct s3c_hsotg_ep *hs_ep, |
1231 | struct s3c_hsotg_req *hs_req, | 1231 | struct s3c_hsotg_req *hs_req, |
1232 | int result) | 1232 | int result) |
@@ -1291,7 +1291,7 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | |||
1291 | * endpoint, so sort out whether we need to read the data into a request | 1291 | * endpoint, so sort out whether we need to read the data into a request |
1292 | * that has been made for that endpoint. | 1292 | * that has been made for that endpoint. |
1293 | */ | 1293 | */ |
1294 | static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) | 1294 | static void s3c_hsotg_rx_data(struct dwc2_hsotg *hsotg, int ep_idx, int size) |
1295 | { | 1295 | { |
1296 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep_idx]; | 1296 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep_idx]; |
1297 | struct s3c_hsotg_req *hs_req = hs_ep->req; | 1297 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
@@ -1356,7 +1356,7 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) | |||
1356 | * currently believed that we do not need to wait for any space in | 1356 | * currently believed that we do not need to wait for any space in |
1357 | * the TxFIFO. | 1357 | * the TxFIFO. |
1358 | */ | 1358 | */ |
1359 | static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg, | 1359 | static void s3c_hsotg_send_zlp(struct dwc2_hsotg *hsotg, |
1360 | struct s3c_hsotg_req *req) | 1360 | struct s3c_hsotg_req *req) |
1361 | { | 1361 | { |
1362 | u32 ctrl; | 1362 | u32 ctrl; |
@@ -1398,7 +1398,7 @@ static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg, | |||
1398 | * transfer for an OUT endpoint has been completed, either by a short | 1398 | * transfer for an OUT endpoint has been completed, either by a short |
1399 | * packet or by the finish of a transfer. | 1399 | * packet or by the finish of a transfer. |
1400 | */ | 1400 | */ |
1401 | static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | 1401 | static void s3c_hsotg_handle_outdone(struct dwc2_hsotg *hsotg, |
1402 | int epnum, bool was_setup) | 1402 | int epnum, bool was_setup) |
1403 | { | 1403 | { |
1404 | u32 epsize = readl(hsotg->regs + DOEPTSIZ(epnum)); | 1404 | u32 epsize = readl(hsotg->regs + DOEPTSIZ(epnum)); |
@@ -1471,7 +1471,7 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | |||
1471 | * | 1471 | * |
1472 | * Return the current frame number | 1472 | * Return the current frame number |
1473 | */ | 1473 | */ |
1474 | static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg) | 1474 | static u32 s3c_hsotg_read_frameno(struct dwc2_hsotg *hsotg) |
1475 | { | 1475 | { |
1476 | u32 dsts; | 1476 | u32 dsts; |
1477 | 1477 | ||
@@ -1498,7 +1498,7 @@ static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg) | |||
1498 | * as the actual data should be sent to the memory directly and we turn | 1498 | * as the actual data should be sent to the memory directly and we turn |
1499 | * on the completion interrupts to get notifications of transfer completion. | 1499 | * on the completion interrupts to get notifications of transfer completion. |
1500 | */ | 1500 | */ |
1501 | static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) | 1501 | static void s3c_hsotg_handle_rx(struct dwc2_hsotg *hsotg) |
1502 | { | 1502 | { |
1503 | u32 grxstsr = readl(hsotg->regs + GRXSTSP); | 1503 | u32 grxstsr = readl(hsotg->regs + GRXSTSP); |
1504 | u32 epnum, status, size; | 1504 | u32 epnum, status, size; |
@@ -1590,7 +1590,7 @@ static u32 s3c_hsotg_ep0_mps(unsigned int mps) | |||
1590 | * Configure the maximum packet size for the given endpoint, updating | 1590 | * Configure the maximum packet size for the given endpoint, updating |
1591 | * the hardware control registers to reflect this. | 1591 | * the hardware control registers to reflect this. |
1592 | */ | 1592 | */ |
1593 | static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg, | 1593 | static void s3c_hsotg_set_ep_maxpacket(struct dwc2_hsotg *hsotg, |
1594 | unsigned int ep, unsigned int mps) | 1594 | unsigned int ep, unsigned int mps) |
1595 | { | 1595 | { |
1596 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep]; | 1596 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep]; |
@@ -1645,7 +1645,7 @@ bad_mps: | |||
1645 | * @hsotg: The driver state | 1645 | * @hsotg: The driver state |
1646 | * @idx: The index for the endpoint (0..15) | 1646 | * @idx: The index for the endpoint (0..15) |
1647 | */ | 1647 | */ |
1648 | static void s3c_hsotg_txfifo_flush(struct s3c_hsotg *hsotg, unsigned int idx) | 1648 | static void s3c_hsotg_txfifo_flush(struct dwc2_hsotg *hsotg, unsigned int idx) |
1649 | { | 1649 | { |
1650 | int timeout; | 1650 | int timeout; |
1651 | int val; | 1651 | int val; |
@@ -1681,7 +1681,7 @@ static void s3c_hsotg_txfifo_flush(struct s3c_hsotg *hsotg, unsigned int idx) | |||
1681 | * Check to see if there is a request that has data to send, and if so | 1681 | * Check to see if there is a request that has data to send, and if so |
1682 | * make an attempt to write data into the FIFO. | 1682 | * make an attempt to write data into the FIFO. |
1683 | */ | 1683 | */ |
1684 | static int s3c_hsotg_trytx(struct s3c_hsotg *hsotg, | 1684 | static int s3c_hsotg_trytx(struct dwc2_hsotg *hsotg, |
1685 | struct s3c_hsotg_ep *hs_ep) | 1685 | struct s3c_hsotg_ep *hs_ep) |
1686 | { | 1686 | { |
1687 | struct s3c_hsotg_req *hs_req = hs_ep->req; | 1687 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
@@ -1714,7 +1714,7 @@ static int s3c_hsotg_trytx(struct s3c_hsotg *hsotg, | |||
1714 | * An IN transfer has been completed, update the transfer's state and then | 1714 | * An IN transfer has been completed, update the transfer's state and then |
1715 | * call the relevant completion routines. | 1715 | * call the relevant completion routines. |
1716 | */ | 1716 | */ |
1717 | static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, | 1717 | static void s3c_hsotg_complete_in(struct dwc2_hsotg *hsotg, |
1718 | struct s3c_hsotg_ep *hs_ep) | 1718 | struct s3c_hsotg_ep *hs_ep) |
1719 | { | 1719 | { |
1720 | struct s3c_hsotg_req *hs_req = hs_ep->req; | 1720 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
@@ -1791,7 +1791,7 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, | |||
1791 | * | 1791 | * |
1792 | * Process and clear any interrupt pending for an individual endpoint | 1792 | * Process and clear any interrupt pending for an individual endpoint |
1793 | */ | 1793 | */ |
1794 | static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | 1794 | static void s3c_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx, |
1795 | int dir_in) | 1795 | int dir_in) |
1796 | { | 1796 | { |
1797 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[idx]; | 1797 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[idx]; |
@@ -1916,7 +1916,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1916 | * Handle updating the device settings after the enumeration phase has | 1916 | * Handle updating the device settings after the enumeration phase has |
1917 | * been completed. | 1917 | * been completed. |
1918 | */ | 1918 | */ |
1919 | static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | 1919 | static void s3c_hsotg_irq_enumdone(struct dwc2_hsotg *hsotg) |
1920 | { | 1920 | { |
1921 | u32 dsts = readl(hsotg->regs + DSTS); | 1921 | u32 dsts = readl(hsotg->regs + DSTS); |
1922 | int ep0_mps = 0, ep_mps = 8; | 1922 | int ep0_mps = 0, ep_mps = 8; |
@@ -1993,7 +1993,7 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | |||
1993 | * Go through the requests on the given endpoint and mark them | 1993 | * Go through the requests on the given endpoint and mark them |
1994 | * completed with the given result code. | 1994 | * completed with the given result code. |
1995 | */ | 1995 | */ |
1996 | static void kill_all_requests(struct s3c_hsotg *hsotg, | 1996 | static void kill_all_requests(struct dwc2_hsotg *hsotg, |
1997 | struct s3c_hsotg_ep *ep, | 1997 | struct s3c_hsotg_ep *ep, |
1998 | int result, bool force) | 1998 | int result, bool force) |
1999 | { | 1999 | { |
@@ -2027,22 +2027,27 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, | |||
2027 | * transactions and signal the gadget driver that this | 2027 | * transactions and signal the gadget driver that this |
2028 | * has happened. | 2028 | * has happened. |
2029 | */ | 2029 | */ |
2030 | static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) | 2030 | void s3c_hsotg_disconnect(struct dwc2_hsotg *hsotg) |
2031 | { | 2031 | { |
2032 | unsigned ep; | 2032 | unsigned ep; |
2033 | 2033 | ||
2034 | if (!hsotg->connected) | ||
2035 | return; | ||
2036 | |||
2037 | hsotg->connected = 0; | ||
2034 | for (ep = 0; ep < hsotg->num_of_eps; ep++) | 2038 | for (ep = 0; ep < hsotg->num_of_eps; ep++) |
2035 | kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true); | 2039 | kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true); |
2036 | 2040 | ||
2037 | call_gadget(hsotg, disconnect); | 2041 | call_gadget(hsotg, disconnect); |
2038 | } | 2042 | } |
2043 | EXPORT_SYMBOL_GPL(s3c_hsotg_disconnect); | ||
2039 | 2044 | ||
2040 | /** | 2045 | /** |
2041 | * s3c_hsotg_irq_fifoempty - TX FIFO empty interrupt handler | 2046 | * s3c_hsotg_irq_fifoempty - TX FIFO empty interrupt handler |
2042 | * @hsotg: The device state: | 2047 | * @hsotg: The device state: |
2043 | * @periodic: True if this is a periodic FIFO interrupt | 2048 | * @periodic: True if this is a periodic FIFO interrupt |
2044 | */ | 2049 | */ |
2045 | static void s3c_hsotg_irq_fifoempty(struct s3c_hsotg *hsotg, bool periodic) | 2050 | static void s3c_hsotg_irq_fifoempty(struct dwc2_hsotg *hsotg, bool periodic) |
2046 | { | 2051 | { |
2047 | struct s3c_hsotg_ep *ep; | 2052 | struct s3c_hsotg_ep *ep; |
2048 | int epno, ret; | 2053 | int epno, ret; |
@@ -2076,7 +2081,7 @@ static void s3c_hsotg_irq_fifoempty(struct s3c_hsotg *hsotg, bool periodic) | |||
2076 | * | 2081 | * |
2077 | * Issue a soft reset to the core, and await the core finishing it. | 2082 | * Issue a soft reset to the core, and await the core finishing it. |
2078 | */ | 2083 | */ |
2079 | static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) | 2084 | static int s3c_hsotg_corereset(struct dwc2_hsotg *hsotg) |
2080 | { | 2085 | { |
2081 | int timeout; | 2086 | int timeout; |
2082 | u32 grstctl; | 2087 | u32 grstctl; |
@@ -2124,7 +2129,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) | |||
2124 | * | 2129 | * |
2125 | * Issue a soft reset to the core, and await the core finishing it. | 2130 | * Issue a soft reset to the core, and await the core finishing it. |
2126 | */ | 2131 | */ |
2127 | static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | 2132 | void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg) |
2128 | { | 2133 | { |
2129 | s3c_hsotg_corereset(hsotg); | 2134 | s3c_hsotg_corereset(hsotg); |
2130 | 2135 | ||
@@ -2241,12 +2246,23 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2241 | readl(hsotg->regs + DOEPCTL0)); | 2246 | readl(hsotg->regs + DOEPCTL0)); |
2242 | 2247 | ||
2243 | /* clear global NAKs */ | 2248 | /* clear global NAKs */ |
2244 | writel(DCTL_CGOUTNAK | DCTL_CGNPINNAK, | 2249 | writel(DCTL_CGOUTNAK | DCTL_CGNPINNAK | DCTL_SFTDISCON, |
2245 | hsotg->regs + DCTL); | 2250 | hsotg->regs + DCTL); |
2246 | 2251 | ||
2247 | /* must be at-least 3ms to allow bus to see disconnect */ | 2252 | /* must be at-least 3ms to allow bus to see disconnect */ |
2248 | mdelay(3); | 2253 | mdelay(3); |
2249 | 2254 | ||
2255 | hsotg->last_rst = jiffies; | ||
2256 | } | ||
2257 | |||
2258 | static void s3c_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) | ||
2259 | { | ||
2260 | /* set the soft-disconnect bit */ | ||
2261 | __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); | ||
2262 | } | ||
2263 | |||
2264 | void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg) | ||
2265 | { | ||
2250 | /* remove the soft-disconnect and let's go */ | 2266 | /* remove the soft-disconnect and let's go */ |
2251 | __bic32(hsotg->regs + DCTL, DCTL_SFTDISCON); | 2267 | __bic32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
2252 | } | 2268 | } |
@@ -2258,7 +2274,7 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2258 | */ | 2274 | */ |
2259 | static irqreturn_t s3c_hsotg_irq(int irq, void *pw) | 2275 | static irqreturn_t s3c_hsotg_irq(int irq, void *pw) |
2260 | { | 2276 | { |
2261 | struct s3c_hsotg *hsotg = pw; | 2277 | struct dwc2_hsotg *hsotg = pw; |
2262 | int retry_count = 8; | 2278 | int retry_count = 8; |
2263 | u32 gintsts; | 2279 | u32 gintsts; |
2264 | u32 gintmsk; | 2280 | u32 gintmsk; |
@@ -2273,31 +2289,11 @@ irq_retry: | |||
2273 | 2289 | ||
2274 | gintsts &= gintmsk; | 2290 | gintsts &= gintmsk; |
2275 | 2291 | ||
2276 | if (gintsts & GINTSTS_OTGINT) { | ||
2277 | u32 otgint = readl(hsotg->regs + GOTGINT); | ||
2278 | |||
2279 | dev_info(hsotg->dev, "OTGInt: %08x\n", otgint); | ||
2280 | |||
2281 | writel(otgint, hsotg->regs + GOTGINT); | ||
2282 | } | ||
2283 | |||
2284 | if (gintsts & GINTSTS_SESSREQINT) { | ||
2285 | dev_dbg(hsotg->dev, "%s: SessReqInt\n", __func__); | ||
2286 | writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS); | ||
2287 | } | ||
2288 | |||
2289 | if (gintsts & GINTSTS_ENUMDONE) { | 2292 | if (gintsts & GINTSTS_ENUMDONE) { |
2290 | writel(GINTSTS_ENUMDONE, hsotg->regs + GINTSTS); | 2293 | writel(GINTSTS_ENUMDONE, hsotg->regs + GINTSTS); |
2291 | 2294 | ||
2292 | s3c_hsotg_irq_enumdone(hsotg); | 2295 | s3c_hsotg_irq_enumdone(hsotg); |
2293 | } | 2296 | hsotg->connected = 1; |
2294 | |||
2295 | if (gintsts & GINTSTS_CONIDSTSCHNG) { | ||
2296 | dev_dbg(hsotg->dev, "ConIDStsChg (DSTS=0x%08x, GOTCTL=%08x)\n", | ||
2297 | readl(hsotg->regs + DSTS), | ||
2298 | readl(hsotg->regs + GOTGCTL)); | ||
2299 | |||
2300 | writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS); | ||
2301 | } | 2297 | } |
2302 | 2298 | ||
2303 | if (gintsts & (GINTSTS_OEPINT | GINTSTS_IEPINT)) { | 2299 | if (gintsts & (GINTSTS_OEPINT | GINTSTS_IEPINT)) { |
@@ -2340,8 +2336,8 @@ irq_retry: | |||
2340 | kill_all_requests(hsotg, &hsotg->eps[0], | 2336 | kill_all_requests(hsotg, &hsotg->eps[0], |
2341 | -ECONNRESET, true); | 2337 | -ECONNRESET, true); |
2342 | 2338 | ||
2343 | s3c_hsotg_core_init(hsotg); | 2339 | s3c_hsotg_core_init_disconnected(hsotg); |
2344 | hsotg->last_rst = jiffies; | 2340 | s3c_hsotg_core_connect(hsotg); |
2345 | } | 2341 | } |
2346 | } | 2342 | } |
2347 | } | 2343 | } |
@@ -2380,25 +2376,6 @@ irq_retry: | |||
2380 | s3c_hsotg_handle_rx(hsotg); | 2376 | s3c_hsotg_handle_rx(hsotg); |
2381 | } | 2377 | } |
2382 | 2378 | ||
2383 | if (gintsts & GINTSTS_MODEMIS) { | ||
2384 | dev_warn(hsotg->dev, "warning, mode mismatch triggered\n"); | ||
2385 | writel(GINTSTS_MODEMIS, hsotg->regs + GINTSTS); | ||
2386 | } | ||
2387 | |||
2388 | if (gintsts & GINTSTS_USBSUSP) { | ||
2389 | dev_info(hsotg->dev, "GINTSTS_USBSusp\n"); | ||
2390 | writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS); | ||
2391 | |||
2392 | call_gadget(hsotg, suspend); | ||
2393 | } | ||
2394 | |||
2395 | if (gintsts & GINTSTS_WKUPINT) { | ||
2396 | dev_info(hsotg->dev, "GINTSTS_WkUpIn\n"); | ||
2397 | writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS); | ||
2398 | |||
2399 | call_gadget(hsotg, resume); | ||
2400 | } | ||
2401 | |||
2402 | if (gintsts & GINTSTS_ERLYSUSP) { | 2379 | if (gintsts & GINTSTS_ERLYSUSP) { |
2403 | dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); | 2380 | dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); |
2404 | writel(GINTSTS_ERLYSUSP, hsotg->regs + GINTSTS); | 2381 | writel(GINTSTS_ERLYSUSP, hsotg->regs + GINTSTS); |
@@ -2450,7 +2427,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2450 | const struct usb_endpoint_descriptor *desc) | 2427 | const struct usb_endpoint_descriptor *desc) |
2451 | { | 2428 | { |
2452 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 2429 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
2453 | struct s3c_hsotg *hsotg = hs_ep->parent; | 2430 | struct dwc2_hsotg *hsotg = hs_ep->parent; |
2454 | unsigned long flags; | 2431 | unsigned long flags; |
2455 | int index = hs_ep->index; | 2432 | int index = hs_ep->index; |
2456 | u32 epctrl_reg; | 2433 | u32 epctrl_reg; |
@@ -2593,7 +2570,7 @@ error: | |||
2593 | static int s3c_hsotg_ep_disable(struct usb_ep *ep) | 2570 | static int s3c_hsotg_ep_disable(struct usb_ep *ep) |
2594 | { | 2571 | { |
2595 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 2572 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
2596 | struct s3c_hsotg *hsotg = hs_ep->parent; | 2573 | struct dwc2_hsotg *hsotg = hs_ep->parent; |
2597 | int dir_in = hs_ep->dir_in; | 2574 | int dir_in = hs_ep->dir_in; |
2598 | int index = hs_ep->index; | 2575 | int index = hs_ep->index; |
2599 | unsigned long flags; | 2576 | unsigned long flags; |
@@ -2658,7 +2635,7 @@ static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) | |||
2658 | { | 2635 | { |
2659 | struct s3c_hsotg_req *hs_req = our_req(req); | 2636 | struct s3c_hsotg_req *hs_req = our_req(req); |
2660 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 2637 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
2661 | struct s3c_hsotg *hs = hs_ep->parent; | 2638 | struct dwc2_hsotg *hs = hs_ep->parent; |
2662 | unsigned long flags; | 2639 | unsigned long flags; |
2663 | 2640 | ||
2664 | dev_dbg(hs->dev, "ep_dequeue(%p,%p)\n", ep, req); | 2641 | dev_dbg(hs->dev, "ep_dequeue(%p,%p)\n", ep, req); |
@@ -2684,7 +2661,7 @@ static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) | |||
2684 | static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) | 2661 | static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) |
2685 | { | 2662 | { |
2686 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 2663 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
2687 | struct s3c_hsotg *hs = hs_ep->parent; | 2664 | struct dwc2_hsotg *hs = hs_ep->parent; |
2688 | int index = hs_ep->index; | 2665 | int index = hs_ep->index; |
2689 | u32 epreg; | 2666 | u32 epreg; |
2690 | u32 epctl; | 2667 | u32 epctl; |
@@ -2748,7 +2725,7 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) | |||
2748 | static int s3c_hsotg_ep_sethalt_lock(struct usb_ep *ep, int value) | 2725 | static int s3c_hsotg_ep_sethalt_lock(struct usb_ep *ep, int value) |
2749 | { | 2726 | { |
2750 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 2727 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
2751 | struct s3c_hsotg *hs = hs_ep->parent; | 2728 | struct dwc2_hsotg *hs = hs_ep->parent; |
2752 | unsigned long flags = 0; | 2729 | unsigned long flags = 0; |
2753 | int ret = 0; | 2730 | int ret = 0; |
2754 | 2731 | ||
@@ -2777,7 +2754,7 @@ static struct usb_ep_ops s3c_hsotg_ep_ops = { | |||
2777 | * A wrapper for platform code responsible for controlling | 2754 | * A wrapper for platform code responsible for controlling |
2778 | * low-level USB code | 2755 | * low-level USB code |
2779 | */ | 2756 | */ |
2780 | static void s3c_hsotg_phy_enable(struct s3c_hsotg *hsotg) | 2757 | static void s3c_hsotg_phy_enable(struct dwc2_hsotg *hsotg) |
2781 | { | 2758 | { |
2782 | struct platform_device *pdev = to_platform_device(hsotg->dev); | 2759 | struct platform_device *pdev = to_platform_device(hsotg->dev); |
2783 | 2760 | ||
@@ -2800,7 +2777,7 @@ static void s3c_hsotg_phy_enable(struct s3c_hsotg *hsotg) | |||
2800 | * A wrapper for platform code responsible for controlling | 2777 | * A wrapper for platform code responsible for controlling |
2801 | * low-level USB code | 2778 | * low-level USB code |
2802 | */ | 2779 | */ |
2803 | static void s3c_hsotg_phy_disable(struct s3c_hsotg *hsotg) | 2780 | static void s3c_hsotg_phy_disable(struct dwc2_hsotg *hsotg) |
2804 | { | 2781 | { |
2805 | struct platform_device *pdev = to_platform_device(hsotg->dev); | 2782 | struct platform_device *pdev = to_platform_device(hsotg->dev); |
2806 | 2783 | ||
@@ -2818,7 +2795,7 @@ static void s3c_hsotg_phy_disable(struct s3c_hsotg *hsotg) | |||
2818 | * s3c_hsotg_init - initalize the usb core | 2795 | * s3c_hsotg_init - initalize the usb core |
2819 | * @hsotg: The driver state | 2796 | * @hsotg: The driver state |
2820 | */ | 2797 | */ |
2821 | static void s3c_hsotg_init(struct s3c_hsotg *hsotg) | 2798 | static void s3c_hsotg_init(struct dwc2_hsotg *hsotg) |
2822 | { | 2799 | { |
2823 | /* unmask subset of endpoint interrupts */ | 2800 | /* unmask subset of endpoint interrupts */ |
2824 | 2801 | ||
@@ -2868,7 +2845,8 @@ static void s3c_hsotg_init(struct s3c_hsotg *hsotg) | |||
2868 | static int s3c_hsotg_udc_start(struct usb_gadget *gadget, | 2845 | static int s3c_hsotg_udc_start(struct usb_gadget *gadget, |
2869 | struct usb_gadget_driver *driver) | 2846 | struct usb_gadget_driver *driver) |
2870 | { | 2847 | { |
2871 | struct s3c_hsotg *hsotg = to_hsotg(gadget); | 2848 | struct dwc2_hsotg *hsotg = to_hsotg(gadget); |
2849 | unsigned long flags; | ||
2872 | int ret; | 2850 | int ret; |
2873 | 2851 | ||
2874 | if (!hsotg) { | 2852 | if (!hsotg) { |
@@ -2889,6 +2867,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, | |||
2889 | return -EINVAL; | 2867 | return -EINVAL; |
2890 | } | 2868 | } |
2891 | 2869 | ||
2870 | mutex_lock(&hsotg->init_mutex); | ||
2892 | WARN_ON(hsotg->driver); | 2871 | WARN_ON(hsotg->driver); |
2893 | 2872 | ||
2894 | driver->driver.bus = NULL; | 2873 | driver->driver.bus = NULL; |
@@ -2905,11 +2884,22 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, | |||
2905 | goto err; | 2884 | goto err; |
2906 | } | 2885 | } |
2907 | 2886 | ||
2908 | hsotg->last_rst = jiffies; | 2887 | s3c_hsotg_phy_enable(hsotg); |
2888 | |||
2889 | spin_lock_irqsave(&hsotg->lock, flags); | ||
2890 | s3c_hsotg_init(hsotg); | ||
2891 | s3c_hsotg_core_init_disconnected(hsotg); | ||
2892 | hsotg->enabled = 0; | ||
2893 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
2894 | |||
2909 | dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); | 2895 | dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); |
2896 | |||
2897 | mutex_unlock(&hsotg->init_mutex); | ||
2898 | |||
2910 | return 0; | 2899 | return 0; |
2911 | 2900 | ||
2912 | err: | 2901 | err: |
2902 | mutex_unlock(&hsotg->init_mutex); | ||
2913 | hsotg->driver = NULL; | 2903 | hsotg->driver = NULL; |
2914 | return ret; | 2904 | return ret; |
2915 | } | 2905 | } |
@@ -2921,16 +2911,17 @@ err: | |||
2921 | * | 2911 | * |
2922 | * Stop udc hw block and stay tunned for future transmissions | 2912 | * Stop udc hw block and stay tunned for future transmissions |
2923 | */ | 2913 | */ |
2924 | static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, | 2914 | static int s3c_hsotg_udc_stop(struct usb_gadget *gadget) |
2925 | struct usb_gadget_driver *driver) | ||
2926 | { | 2915 | { |
2927 | struct s3c_hsotg *hsotg = to_hsotg(gadget); | 2916 | struct dwc2_hsotg *hsotg = to_hsotg(gadget); |
2928 | unsigned long flags = 0; | 2917 | unsigned long flags = 0; |
2929 | int ep; | 2918 | int ep; |
2930 | 2919 | ||
2931 | if (!hsotg) | 2920 | if (!hsotg) |
2932 | return -ENODEV; | 2921 | return -ENODEV; |
2933 | 2922 | ||
2923 | mutex_lock(&hsotg->init_mutex); | ||
2924 | |||
2934 | /* all endpoints should be shutdown */ | 2925 | /* all endpoints should be shutdown */ |
2935 | for (ep = 1; ep < hsotg->num_of_eps; ep++) | 2926 | for (ep = 1; ep < hsotg->num_of_eps; ep++) |
2936 | s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); | 2927 | s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); |
@@ -2939,13 +2930,18 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, | |||
2939 | 2930 | ||
2940 | hsotg->driver = NULL; | 2931 | hsotg->driver = NULL; |
2941 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; | 2932 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
2933 | hsotg->enabled = 0; | ||
2942 | 2934 | ||
2943 | spin_unlock_irqrestore(&hsotg->lock, flags); | 2935 | spin_unlock_irqrestore(&hsotg->lock, flags); |
2944 | 2936 | ||
2937 | s3c_hsotg_phy_disable(hsotg); | ||
2938 | |||
2945 | regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); | 2939 | regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); |
2946 | 2940 | ||
2947 | clk_disable(hsotg->clk); | 2941 | clk_disable(hsotg->clk); |
2948 | 2942 | ||
2943 | mutex_unlock(&hsotg->init_mutex); | ||
2944 | |||
2949 | return 0; | 2945 | return 0; |
2950 | } | 2946 | } |
2951 | 2947 | ||
@@ -2969,23 +2965,26 @@ static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) | |||
2969 | */ | 2965 | */ |
2970 | static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) | 2966 | static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) |
2971 | { | 2967 | { |
2972 | struct s3c_hsotg *hsotg = to_hsotg(gadget); | 2968 | struct dwc2_hsotg *hsotg = to_hsotg(gadget); |
2973 | unsigned long flags = 0; | 2969 | unsigned long flags = 0; |
2974 | 2970 | ||
2975 | dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, is_on); | 2971 | dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, is_on); |
2976 | 2972 | ||
2973 | mutex_lock(&hsotg->init_mutex); | ||
2977 | spin_lock_irqsave(&hsotg->lock, flags); | 2974 | spin_lock_irqsave(&hsotg->lock, flags); |
2978 | if (is_on) { | 2975 | if (is_on) { |
2979 | s3c_hsotg_phy_enable(hsotg); | ||
2980 | clk_enable(hsotg->clk); | 2976 | clk_enable(hsotg->clk); |
2981 | s3c_hsotg_core_init(hsotg); | 2977 | hsotg->enabled = 1; |
2978 | s3c_hsotg_core_connect(hsotg); | ||
2982 | } else { | 2979 | } else { |
2980 | s3c_hsotg_core_disconnect(hsotg); | ||
2981 | hsotg->enabled = 0; | ||
2983 | clk_disable(hsotg->clk); | 2982 | clk_disable(hsotg->clk); |
2984 | s3c_hsotg_phy_disable(hsotg); | ||
2985 | } | 2983 | } |
2986 | 2984 | ||
2987 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; | 2985 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
2988 | spin_unlock_irqrestore(&hsotg->lock, flags); | 2986 | spin_unlock_irqrestore(&hsotg->lock, flags); |
2987 | mutex_unlock(&hsotg->init_mutex); | ||
2989 | 2988 | ||
2990 | return 0; | 2989 | return 0; |
2991 | } | 2990 | } |
@@ -3007,7 +3006,7 @@ static const struct usb_gadget_ops s3c_hsotg_gadget_ops = { | |||
3007 | * creation) to give to the gadget driver. Setup the endpoint name, any | 3006 | * creation) to give to the gadget driver. Setup the endpoint name, any |
3008 | * direction information and other state that may be required. | 3007 | * direction information and other state that may be required. |
3009 | */ | 3008 | */ |
3010 | static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, | 3009 | static void s3c_hsotg_initep(struct dwc2_hsotg *hsotg, |
3011 | struct s3c_hsotg_ep *hs_ep, | 3010 | struct s3c_hsotg_ep *hs_ep, |
3012 | int epnum) | 3011 | int epnum) |
3013 | { | 3012 | { |
@@ -3056,7 +3055,7 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
3056 | * | 3055 | * |
3057 | * Read the USB core HW configuration registers | 3056 | * Read the USB core HW configuration registers |
3058 | */ | 3057 | */ |
3059 | static void s3c_hsotg_hw_cfg(struct s3c_hsotg *hsotg) | 3058 | static void s3c_hsotg_hw_cfg(struct dwc2_hsotg *hsotg) |
3060 | { | 3059 | { |
3061 | u32 cfg2, cfg3, cfg4; | 3060 | u32 cfg2, cfg3, cfg4; |
3062 | /* check hardware configuration */ | 3061 | /* check hardware configuration */ |
@@ -3080,7 +3079,7 @@ static void s3c_hsotg_hw_cfg(struct s3c_hsotg *hsotg) | |||
3080 | * s3c_hsotg_dump - dump state of the udc | 3079 | * s3c_hsotg_dump - dump state of the udc |
3081 | * @param: The device state | 3080 | * @param: The device state |
3082 | */ | 3081 | */ |
3083 | static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) | 3082 | static void s3c_hsotg_dump(struct dwc2_hsotg *hsotg) |
3084 | { | 3083 | { |
3085 | #ifdef DEBUG | 3084 | #ifdef DEBUG |
3086 | struct device *dev = hsotg->dev; | 3085 | struct device *dev = hsotg->dev; |
@@ -3139,7 +3138,7 @@ static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) | |||
3139 | */ | 3138 | */ |
3140 | static int state_show(struct seq_file *seq, void *v) | 3139 | static int state_show(struct seq_file *seq, void *v) |
3141 | { | 3140 | { |
3142 | struct s3c_hsotg *hsotg = seq->private; | 3141 | struct dwc2_hsotg *hsotg = seq->private; |
3143 | void __iomem *regs = hsotg->regs; | 3142 | void __iomem *regs = hsotg->regs; |
3144 | int idx; | 3143 | int idx; |
3145 | 3144 | ||
@@ -3209,7 +3208,7 @@ static const struct file_operations state_fops = { | |||
3209 | */ | 3208 | */ |
3210 | static int fifo_show(struct seq_file *seq, void *v) | 3209 | static int fifo_show(struct seq_file *seq, void *v) |
3211 | { | 3210 | { |
3212 | struct s3c_hsotg *hsotg = seq->private; | 3211 | struct dwc2_hsotg *hsotg = seq->private; |
3213 | void __iomem *regs = hsotg->regs; | 3212 | void __iomem *regs = hsotg->regs; |
3214 | u32 val; | 3213 | u32 val; |
3215 | int idx; | 3214 | int idx; |
@@ -3265,7 +3264,7 @@ static const char *decode_direction(int is_in) | |||
3265 | static int ep_show(struct seq_file *seq, void *v) | 3264 | static int ep_show(struct seq_file *seq, void *v) |
3266 | { | 3265 | { |
3267 | struct s3c_hsotg_ep *ep = seq->private; | 3266 | struct s3c_hsotg_ep *ep = seq->private; |
3268 | struct s3c_hsotg *hsotg = ep->parent; | 3267 | struct dwc2_hsotg *hsotg = ep->parent; |
3269 | struct s3c_hsotg_req *req; | 3268 | struct s3c_hsotg_req *req; |
3270 | void __iomem *regs = hsotg->regs; | 3269 | void __iomem *regs = hsotg->regs; |
3271 | int index = ep->index; | 3270 | int index = ep->index; |
@@ -3342,7 +3341,7 @@ static const struct file_operations ep_fops = { | |||
3342 | * with the same name as the device itself, in case we end up | 3341 | * with the same name as the device itself, in case we end up |
3343 | * with multiple blocks in future systems. | 3342 | * with multiple blocks in future systems. |
3344 | */ | 3343 | */ |
3345 | static void s3c_hsotg_create_debug(struct s3c_hsotg *hsotg) | 3344 | static void s3c_hsotg_create_debug(struct dwc2_hsotg *hsotg) |
3346 | { | 3345 | { |
3347 | struct dentry *root; | 3346 | struct dentry *root; |
3348 | unsigned epidx; | 3347 | unsigned epidx; |
@@ -3388,7 +3387,7 @@ static void s3c_hsotg_create_debug(struct s3c_hsotg *hsotg) | |||
3388 | * | 3387 | * |
3389 | * Cleanup (remove) the debugfs files for use on module exit. | 3388 | * Cleanup (remove) the debugfs files for use on module exit. |
3390 | */ | 3389 | */ |
3391 | static void s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) | 3390 | static void s3c_hsotg_delete_debug(struct dwc2_hsotg *hsotg) |
3392 | { | 3391 | { |
3393 | unsigned epidx; | 3392 | unsigned epidx; |
3394 | 3393 | ||
@@ -3403,27 +3402,21 @@ static void s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) | |||
3403 | } | 3402 | } |
3404 | 3403 | ||
3405 | /** | 3404 | /** |
3406 | * s3c_hsotg_probe - probe function for hsotg driver | 3405 | * dwc2_gadget_init - init function for gadget |
3407 | * @pdev: The platform information for the driver | 3406 | * @dwc2: The data structure for the DWC2 driver. |
3407 | * @irq: The IRQ number for the controller. | ||
3408 | */ | 3408 | */ |
3409 | 3409 | int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) | |
3410 | static int s3c_hsotg_probe(struct platform_device *pdev) | ||
3411 | { | 3410 | { |
3412 | struct s3c_hsotg_plat *plat = dev_get_platdata(&pdev->dev); | 3411 | struct device *dev = hsotg->dev; |
3412 | struct s3c_hsotg_plat *plat = dev->platform_data; | ||
3413 | struct phy *phy; | 3413 | struct phy *phy; |
3414 | struct usb_phy *uphy; | 3414 | struct usb_phy *uphy; |
3415 | struct device *dev = &pdev->dev; | ||
3416 | struct s3c_hsotg_ep *eps; | 3415 | struct s3c_hsotg_ep *eps; |
3417 | struct s3c_hsotg *hsotg; | ||
3418 | struct resource *res; | ||
3419 | int epnum; | 3416 | int epnum; |
3420 | int ret; | 3417 | int ret; |
3421 | int i; | 3418 | int i; |
3422 | 3419 | ||
3423 | hsotg = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsotg), GFP_KERNEL); | ||
3424 | if (!hsotg) | ||
3425 | return -ENOMEM; | ||
3426 | |||
3427 | /* Set default UTMI width */ | 3420 | /* Set default UTMI width */ |
3428 | hsotg->phyif = GUSBCFG_PHYIF16; | 3421 | hsotg->phyif = GUSBCFG_PHYIF16; |
3429 | 3422 | ||
@@ -3431,14 +3424,14 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3431 | * Attempt to find a generic PHY, then look for an old style | 3424 | * Attempt to find a generic PHY, then look for an old style |
3432 | * USB PHY, finally fall back to pdata | 3425 | * USB PHY, finally fall back to pdata |
3433 | */ | 3426 | */ |
3434 | phy = devm_phy_get(&pdev->dev, "usb2-phy"); | 3427 | phy = devm_phy_get(dev, "usb2-phy"); |
3435 | if (IS_ERR(phy)) { | 3428 | if (IS_ERR(phy)) { |
3436 | uphy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); | 3429 | uphy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); |
3437 | if (IS_ERR(uphy)) { | 3430 | if (IS_ERR(uphy)) { |
3438 | /* Fallback for pdata */ | 3431 | /* Fallback for pdata */ |
3439 | plat = dev_get_platdata(&pdev->dev); | 3432 | plat = dev_get_platdata(dev); |
3440 | if (!plat) { | 3433 | if (!plat) { |
3441 | dev_err(&pdev->dev, | 3434 | dev_err(dev, |
3442 | "no platform data or transceiver defined\n"); | 3435 | "no platform data or transceiver defined\n"); |
3443 | return -EPROBE_DEFER; | 3436 | return -EPROBE_DEFER; |
3444 | } | 3437 | } |
@@ -3455,43 +3448,24 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3455 | hsotg->phyif = GUSBCFG_PHYIF8; | 3448 | hsotg->phyif = GUSBCFG_PHYIF8; |
3456 | } | 3449 | } |
3457 | 3450 | ||
3458 | hsotg->dev = dev; | 3451 | hsotg->clk = devm_clk_get(dev, "otg"); |
3459 | |||
3460 | hsotg->clk = devm_clk_get(&pdev->dev, "otg"); | ||
3461 | if (IS_ERR(hsotg->clk)) { | 3452 | if (IS_ERR(hsotg->clk)) { |
3462 | dev_err(dev, "cannot get otg clock\n"); | 3453 | hsotg->clk = NULL; |
3463 | return PTR_ERR(hsotg->clk); | 3454 | dev_dbg(dev, "cannot get otg clock\n"); |
3464 | } | ||
3465 | |||
3466 | platform_set_drvdata(pdev, hsotg); | ||
3467 | |||
3468 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
3469 | |||
3470 | hsotg->regs = devm_ioremap_resource(&pdev->dev, res); | ||
3471 | if (IS_ERR(hsotg->regs)) { | ||
3472 | ret = PTR_ERR(hsotg->regs); | ||
3473 | goto err_clk; | ||
3474 | } | 3455 | } |
3475 | 3456 | ||
3476 | ret = platform_get_irq(pdev, 0); | ||
3477 | if (ret < 0) { | ||
3478 | dev_err(dev, "cannot find IRQ\n"); | ||
3479 | goto err_clk; | ||
3480 | } | ||
3481 | |||
3482 | spin_lock_init(&hsotg->lock); | ||
3483 | |||
3484 | hsotg->irq = ret; | ||
3485 | |||
3486 | dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq); | ||
3487 | |||
3488 | hsotg->gadget.max_speed = USB_SPEED_HIGH; | 3457 | hsotg->gadget.max_speed = USB_SPEED_HIGH; |
3489 | hsotg->gadget.ops = &s3c_hsotg_gadget_ops; | 3458 | hsotg->gadget.ops = &s3c_hsotg_gadget_ops; |
3490 | hsotg->gadget.name = dev_name(dev); | 3459 | hsotg->gadget.name = dev_name(dev); |
3491 | 3460 | ||
3492 | /* reset the system */ | 3461 | /* reset the system */ |
3493 | 3462 | ||
3494 | clk_prepare_enable(hsotg->clk); | 3463 | ret = clk_prepare_enable(hsotg->clk); |
3464 | if (ret) { | ||
3465 | dev_err(dev, "failed to enable otg clk\n"); | ||
3466 | goto err_clk; | ||
3467 | } | ||
3468 | |||
3495 | 3469 | ||
3496 | /* regulators */ | 3470 | /* regulators */ |
3497 | 3471 | ||
@@ -3509,7 +3483,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3509 | hsotg->supplies); | 3483 | hsotg->supplies); |
3510 | 3484 | ||
3511 | if (ret) { | 3485 | if (ret) { |
3512 | dev_err(hsotg->dev, "failed to enable supplies: %d\n", ret); | 3486 | dev_err(dev, "failed to enable supplies: %d\n", ret); |
3513 | goto err_supplies; | 3487 | goto err_supplies; |
3514 | } | 3488 | } |
3515 | 3489 | ||
@@ -3520,14 +3494,14 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3520 | s3c_hsotg_hw_cfg(hsotg); | 3494 | s3c_hsotg_hw_cfg(hsotg); |
3521 | s3c_hsotg_init(hsotg); | 3495 | s3c_hsotg_init(hsotg); |
3522 | 3496 | ||
3523 | ret = devm_request_irq(&pdev->dev, hsotg->irq, s3c_hsotg_irq, 0, | 3497 | ret = devm_request_irq(hsotg->dev, irq, s3c_hsotg_irq, IRQF_SHARED, |
3524 | dev_name(dev), hsotg); | 3498 | dev_name(hsotg->dev), hsotg); |
3525 | if (ret < 0) { | 3499 | if (ret < 0) { |
3526 | s3c_hsotg_phy_disable(hsotg); | 3500 | s3c_hsotg_phy_disable(hsotg); |
3527 | clk_disable_unprepare(hsotg->clk); | 3501 | clk_disable_unprepare(hsotg->clk); |
3528 | regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), | 3502 | regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), |
3529 | hsotg->supplies); | 3503 | hsotg->supplies); |
3530 | dev_err(dev, "cannot claim IRQ\n"); | 3504 | dev_err(dev, "cannot claim IRQ for gadget\n"); |
3531 | goto err_clk; | 3505 | goto err_clk; |
3532 | } | 3506 | } |
3533 | 3507 | ||
@@ -3573,11 +3547,11 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3573 | ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), | 3547 | ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), |
3574 | hsotg->supplies); | 3548 | hsotg->supplies); |
3575 | if (ret) { | 3549 | if (ret) { |
3576 | dev_err(hsotg->dev, "failed to disable supplies: %d\n", ret); | 3550 | dev_err(dev, "failed to disable supplies: %d\n", ret); |
3577 | goto err_ep_mem; | 3551 | goto err_ep_mem; |
3578 | } | 3552 | } |
3579 | 3553 | ||
3580 | ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget); | 3554 | ret = usb_add_gadget_udc(dev, &hsotg->gadget); |
3581 | if (ret) | 3555 | if (ret) |
3582 | goto err_ep_mem; | 3556 | goto err_ep_mem; |
3583 | 3557 | ||
@@ -3596,47 +3570,44 @@ err_clk: | |||
3596 | 3570 | ||
3597 | return ret; | 3571 | return ret; |
3598 | } | 3572 | } |
3573 | EXPORT_SYMBOL_GPL(dwc2_gadget_init); | ||
3599 | 3574 | ||
3600 | /** | 3575 | /** |
3601 | * s3c_hsotg_remove - remove function for hsotg driver | 3576 | * s3c_hsotg_remove - remove function for hsotg driver |
3602 | * @pdev: The platform information for the driver | 3577 | * @pdev: The platform information for the driver |
3603 | */ | 3578 | */ |
3604 | static int s3c_hsotg_remove(struct platform_device *pdev) | 3579 | int s3c_hsotg_remove(struct dwc2_hsotg *hsotg) |
3605 | { | 3580 | { |
3606 | struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); | ||
3607 | |||
3608 | usb_del_gadget_udc(&hsotg->gadget); | 3581 | usb_del_gadget_udc(&hsotg->gadget); |
3609 | |||
3610 | s3c_hsotg_delete_debug(hsotg); | 3582 | s3c_hsotg_delete_debug(hsotg); |
3611 | |||
3612 | if (hsotg->driver) { | ||
3613 | /* should have been done already by driver model core */ | ||
3614 | usb_gadget_unregister_driver(hsotg->driver); | ||
3615 | } | ||
3616 | |||
3617 | clk_disable_unprepare(hsotg->clk); | 3583 | clk_disable_unprepare(hsotg->clk); |
3618 | 3584 | ||
3619 | return 0; | 3585 | return 0; |
3620 | } | 3586 | } |
3587 | EXPORT_SYMBOL_GPL(s3c_hsotg_remove); | ||
3621 | 3588 | ||
3622 | static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) | 3589 | int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg) |
3623 | { | 3590 | { |
3624 | struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); | ||
3625 | unsigned long flags; | 3591 | unsigned long flags; |
3626 | int ret = 0; | 3592 | int ret = 0; |
3627 | 3593 | ||
3628 | if (hsotg->driver) | 3594 | mutex_lock(&hsotg->init_mutex); |
3595 | |||
3596 | if (hsotg->driver) { | ||
3597 | int ep; | ||
3598 | |||
3629 | dev_info(hsotg->dev, "suspending usb gadget %s\n", | 3599 | dev_info(hsotg->dev, "suspending usb gadget %s\n", |
3630 | hsotg->driver->driver.name); | 3600 | hsotg->driver->driver.name); |
3631 | 3601 | ||
3632 | spin_lock_irqsave(&hsotg->lock, flags); | 3602 | spin_lock_irqsave(&hsotg->lock, flags); |
3633 | s3c_hsotg_disconnect(hsotg); | 3603 | if (hsotg->enabled) |
3634 | s3c_hsotg_phy_disable(hsotg); | 3604 | s3c_hsotg_core_disconnect(hsotg); |
3635 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; | 3605 | s3c_hsotg_disconnect(hsotg); |
3636 | spin_unlock_irqrestore(&hsotg->lock, flags); | 3606 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
3607 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
3608 | |||
3609 | s3c_hsotg_phy_disable(hsotg); | ||
3637 | 3610 | ||
3638 | if (hsotg->driver) { | ||
3639 | int ep; | ||
3640 | for (ep = 0; ep < hsotg->num_of_eps; ep++) | 3611 | for (ep = 0; ep < hsotg->num_of_eps; ep++) |
3641 | s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); | 3612 | s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); |
3642 | 3613 | ||
@@ -3645,57 +3616,37 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) | |||
3645 | clk_disable(hsotg->clk); | 3616 | clk_disable(hsotg->clk); |
3646 | } | 3617 | } |
3647 | 3618 | ||
3619 | mutex_unlock(&hsotg->init_mutex); | ||
3620 | |||
3648 | return ret; | 3621 | return ret; |
3649 | } | 3622 | } |
3623 | EXPORT_SYMBOL_GPL(s3c_hsotg_suspend); | ||
3650 | 3624 | ||
3651 | static int s3c_hsotg_resume(struct platform_device *pdev) | 3625 | int s3c_hsotg_resume(struct dwc2_hsotg *hsotg) |
3652 | { | 3626 | { |
3653 | struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); | ||
3654 | unsigned long flags; | 3627 | unsigned long flags; |
3655 | int ret = 0; | 3628 | int ret = 0; |
3656 | 3629 | ||
3630 | mutex_lock(&hsotg->init_mutex); | ||
3631 | |||
3657 | if (hsotg->driver) { | 3632 | if (hsotg->driver) { |
3658 | dev_info(hsotg->dev, "resuming usb gadget %s\n", | 3633 | dev_info(hsotg->dev, "resuming usb gadget %s\n", |
3659 | hsotg->driver->driver.name); | 3634 | hsotg->driver->driver.name); |
3660 | 3635 | ||
3661 | clk_enable(hsotg->clk); | 3636 | clk_enable(hsotg->clk); |
3662 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), | 3637 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
3663 | hsotg->supplies); | 3638 | hsotg->supplies); |
3664 | } | ||
3665 | 3639 | ||
3666 | spin_lock_irqsave(&hsotg->lock, flags); | 3640 | s3c_hsotg_phy_enable(hsotg); |
3667 | hsotg->last_rst = jiffies; | 3641 | |
3668 | s3c_hsotg_phy_enable(hsotg); | 3642 | spin_lock_irqsave(&hsotg->lock, flags); |
3669 | s3c_hsotg_core_init(hsotg); | 3643 | s3c_hsotg_core_init_disconnected(hsotg); |
3670 | spin_unlock_irqrestore(&hsotg->lock, flags); | 3644 | if (hsotg->enabled) |
3645 | s3c_hsotg_core_connect(hsotg); | ||
3646 | spin_unlock_irqrestore(&hsotg->lock, flags); | ||
3647 | } | ||
3648 | mutex_unlock(&hsotg->init_mutex); | ||
3671 | 3649 | ||
3672 | return ret; | 3650 | return ret; |
3673 | } | 3651 | } |
3674 | 3652 | EXPORT_SYMBOL_GPL(s3c_hsotg_resume); | |
3675 | #ifdef CONFIG_OF | ||
3676 | static const struct of_device_id s3c_hsotg_of_ids[] = { | ||
3677 | { .compatible = "samsung,s3c6400-hsotg", }, | ||
3678 | { .compatible = "snps,dwc2", }, | ||
3679 | { /* sentinel */ } | ||
3680 | }; | ||
3681 | MODULE_DEVICE_TABLE(of, s3c_hsotg_of_ids); | ||
3682 | #endif | ||
3683 | |||
3684 | static struct platform_driver s3c_hsotg_driver = { | ||
3685 | .driver = { | ||
3686 | .name = "s3c-hsotg", | ||
3687 | .owner = THIS_MODULE, | ||
3688 | .of_match_table = of_match_ptr(s3c_hsotg_of_ids), | ||
3689 | }, | ||
3690 | .probe = s3c_hsotg_probe, | ||
3691 | .remove = s3c_hsotg_remove, | ||
3692 | .suspend = s3c_hsotg_suspend, | ||
3693 | .resume = s3c_hsotg_resume, | ||
3694 | }; | ||
3695 | |||
3696 | module_platform_driver(s3c_hsotg_driver); | ||
3697 | |||
3698 | MODULE_DESCRIPTION("Samsung S3C USB High-speed/OtG device"); | ||
3699 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); | ||
3700 | MODULE_LICENSE("GPL"); | ||
3701 | MODULE_ALIAS("platform:s3c-hsotg"); | ||
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 0a0e6f0ad15f..a0cd9db6f4cd 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c | |||
@@ -1371,6 +1371,8 @@ static void dwc2_conn_id_status_change(struct work_struct *work) | |||
1371 | hsotg->op_state = OTG_STATE_B_PERIPHERAL; | 1371 | hsotg->op_state = OTG_STATE_B_PERIPHERAL; |
1372 | dwc2_core_init(hsotg, false, -1); | 1372 | dwc2_core_init(hsotg, false, -1); |
1373 | dwc2_enable_global_interrupts(hsotg); | 1373 | dwc2_enable_global_interrupts(hsotg); |
1374 | s3c_hsotg_core_init_disconnected(hsotg); | ||
1375 | s3c_hsotg_core_connect(hsotg); | ||
1374 | } else { | 1376 | } else { |
1375 | /* A-Device connector (Host Mode) */ | 1377 | /* A-Device connector (Host Mode) */ |
1376 | dev_dbg(hsotg->dev, "connId A\n"); | 1378 | dev_dbg(hsotg->dev, "connId A\n"); |
@@ -1471,6 +1473,30 @@ static void dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex) | |||
1471 | } | 1473 | } |
1472 | } | 1474 | } |
1473 | 1475 | ||
1476 | static void dwc2_port_resume(struct dwc2_hsotg *hsotg) | ||
1477 | { | ||
1478 | u32 hprt0; | ||
1479 | |||
1480 | /* After clear the Stop PHY clock bit, we should wait for a moment | ||
1481 | * for PLL work stable with clock output. | ||
1482 | */ | ||
1483 | writel(0, hsotg->regs + PCGCTL); | ||
1484 | usleep_range(2000, 4000); | ||
1485 | |||
1486 | hprt0 = dwc2_read_hprt0(hsotg); | ||
1487 | hprt0 |= HPRT0_RES; | ||
1488 | writel(hprt0, hsotg->regs + HPRT0); | ||
1489 | hprt0 &= ~HPRT0_SUSP; | ||
1490 | /* according to USB2.0 Spec 7.1.7.7, the host must send the resume | ||
1491 | * signal for at least 20ms | ||
1492 | */ | ||
1493 | usleep_range(20000, 25000); | ||
1494 | |||
1495 | hprt0 &= ~HPRT0_RES; | ||
1496 | writel(hprt0, hsotg->regs + HPRT0); | ||
1497 | hsotg->lx_state = DWC2_L0; | ||
1498 | } | ||
1499 | |||
1474 | /* Handles hub class-specific requests */ | 1500 | /* Handles hub class-specific requests */ |
1475 | static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, | 1501 | static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, |
1476 | u16 wvalue, u16 windex, char *buf, u16 wlength) | 1502 | u16 wvalue, u16 windex, char *buf, u16 wlength) |
@@ -1516,17 +1542,7 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, | |||
1516 | case USB_PORT_FEAT_SUSPEND: | 1542 | case USB_PORT_FEAT_SUSPEND: |
1517 | dev_dbg(hsotg->dev, | 1543 | dev_dbg(hsotg->dev, |
1518 | "ClearPortFeature USB_PORT_FEAT_SUSPEND\n"); | 1544 | "ClearPortFeature USB_PORT_FEAT_SUSPEND\n"); |
1519 | writel(0, hsotg->regs + PCGCTL); | 1545 | dwc2_port_resume(hsotg); |
1520 | usleep_range(20000, 40000); | ||
1521 | |||
1522 | hprt0 = dwc2_read_hprt0(hsotg); | ||
1523 | hprt0 |= HPRT0_RES; | ||
1524 | writel(hprt0, hsotg->regs + HPRT0); | ||
1525 | hprt0 &= ~HPRT0_SUSP; | ||
1526 | usleep_range(100000, 150000); | ||
1527 | |||
1528 | hprt0 &= ~HPRT0_RES; | ||
1529 | writel(hprt0, hsotg->regs + HPRT0); | ||
1530 | break; | 1546 | break; |
1531 | 1547 | ||
1532 | case USB_PORT_FEAT_POWER: | 1548 | case USB_PORT_FEAT_POWER: |
@@ -2299,6 +2315,55 @@ static void _dwc2_hcd_stop(struct usb_hcd *hcd) | |||
2299 | usleep_range(1000, 3000); | 2315 | usleep_range(1000, 3000); |
2300 | } | 2316 | } |
2301 | 2317 | ||
2318 | static int _dwc2_hcd_suspend(struct usb_hcd *hcd) | ||
2319 | { | ||
2320 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2321 | u32 hprt0; | ||
2322 | |||
2323 | if (!((hsotg->op_state == OTG_STATE_B_HOST) || | ||
2324 | (hsotg->op_state == OTG_STATE_A_HOST))) | ||
2325 | return 0; | ||
2326 | |||
2327 | /* TODO: We get into suspend from 'on' state, maybe we need to do | ||
2328 | * something if we get here from DWC2_L1(LPM sleep) state one day. | ||
2329 | */ | ||
2330 | if (hsotg->lx_state != DWC2_L0) | ||
2331 | return 0; | ||
2332 | |||
2333 | hprt0 = dwc2_read_hprt0(hsotg); | ||
2334 | if (hprt0 & HPRT0_CONNSTS) { | ||
2335 | dwc2_port_suspend(hsotg, 1); | ||
2336 | } else { | ||
2337 | u32 pcgctl = readl(hsotg->regs + PCGCTL); | ||
2338 | |||
2339 | pcgctl |= PCGCTL_STOPPCLK; | ||
2340 | writel(pcgctl, hsotg->regs + PCGCTL); | ||
2341 | } | ||
2342 | |||
2343 | return 0; | ||
2344 | } | ||
2345 | |||
2346 | static int _dwc2_hcd_resume(struct usb_hcd *hcd) | ||
2347 | { | ||
2348 | struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); | ||
2349 | u32 hprt0; | ||
2350 | |||
2351 | if (!((hsotg->op_state == OTG_STATE_B_HOST) || | ||
2352 | (hsotg->op_state == OTG_STATE_A_HOST))) | ||
2353 | return 0; | ||
2354 | |||
2355 | if (hsotg->lx_state != DWC2_L2) | ||
2356 | return 0; | ||
2357 | |||
2358 | hprt0 = dwc2_read_hprt0(hsotg); | ||
2359 | if ((hprt0 & HPRT0_CONNSTS) && (hprt0 & HPRT0_SUSP)) | ||
2360 | dwc2_port_resume(hsotg); | ||
2361 | else | ||
2362 | writel(0, hsotg->regs + PCGCTL); | ||
2363 | |||
2364 | return 0; | ||
2365 | } | ||
2366 | |||
2302 | /* Returns the current frame number */ | 2367 | /* Returns the current frame number */ |
2303 | static int _dwc2_hcd_get_frame_number(struct usb_hcd *hcd) | 2368 | static int _dwc2_hcd_get_frame_number(struct usb_hcd *hcd) |
2304 | { | 2369 | { |
@@ -2669,6 +2734,9 @@ static struct hc_driver dwc2_hc_driver = { | |||
2669 | .hub_status_data = _dwc2_hcd_hub_status_data, | 2734 | .hub_status_data = _dwc2_hcd_hub_status_data, |
2670 | .hub_control = _dwc2_hcd_hub_control, | 2735 | .hub_control = _dwc2_hcd_hub_control, |
2671 | .clear_tt_buffer_complete = _dwc2_hcd_clear_tt_buffer_complete, | 2736 | .clear_tt_buffer_complete = _dwc2_hcd_clear_tt_buffer_complete, |
2737 | |||
2738 | .bus_suspend = _dwc2_hcd_suspend, | ||
2739 | .bus_resume = _dwc2_hcd_resume, | ||
2672 | }; | 2740 | }; |
2673 | 2741 | ||
2674 | /* | 2742 | /* |
@@ -2778,6 +2846,9 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, | |||
2778 | int i, num_channels; | 2846 | int i, num_channels; |
2779 | int retval; | 2847 | int retval; |
2780 | 2848 | ||
2849 | if (usb_disabled()) | ||
2850 | return -ENODEV; | ||
2851 | |||
2781 | dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n"); | 2852 | dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n"); |
2782 | 2853 | ||
2783 | /* Detect config values from hardware */ | 2854 | /* Detect config values from hardware */ |
@@ -2839,7 +2910,6 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, | |||
2839 | 2910 | ||
2840 | hcd->has_tt = 1; | 2911 | hcd->has_tt = 1; |
2841 | 2912 | ||
2842 | spin_lock_init(&hsotg->lock); | ||
2843 | ((struct wrapper_priv_data *) &hcd->hcd_priv)->hsotg = hsotg; | 2913 | ((struct wrapper_priv_data *) &hcd->hcd_priv)->hsotg = hsotg; |
2844 | hsotg->priv = hcd; | 2914 | hsotg->priv = hcd; |
2845 | 2915 | ||
diff --git a/drivers/usb/dwc2/hcd.h b/drivers/usb/dwc2/hcd.h index a12bb1538666..e69a843d8928 100644 --- a/drivers/usb/dwc2/hcd.h +++ b/drivers/usb/dwc2/hcd.h | |||
@@ -668,9 +668,6 @@ extern irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg); | |||
668 | */ | 668 | */ |
669 | extern void dwc2_hcd_stop(struct dwc2_hsotg *hsotg); | 669 | extern void dwc2_hcd_stop(struct dwc2_hsotg *hsotg); |
670 | 670 | ||
671 | extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg); | ||
672 | extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg); | ||
673 | |||
674 | /** | 671 | /** |
675 | * dwc2_hcd_is_b_host() - Returns 1 if core currently is acting as B host, | 672 | * dwc2_hcd_is_b_host() - Returns 1 if core currently is acting as B host, |
676 | * and 0 otherwise | 673 | * and 0 otherwise |
@@ -680,13 +677,6 @@ extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg); | |||
680 | extern int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg); | 677 | extern int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg); |
681 | 678 | ||
682 | /** | 679 | /** |
683 | * dwc2_hcd_get_frame_number() - Returns current frame number | ||
684 | * | ||
685 | * @hsotg: The DWC2 HCD | ||
686 | */ | ||
687 | extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg); | ||
688 | |||
689 | /** | ||
690 | * dwc2_hcd_dump_state() - Dumps hsotg state | 680 | * dwc2_hcd_dump_state() - Dumps hsotg state |
691 | * | 681 | * |
692 | * @hsotg: The DWC2 HCD | 682 | * @hsotg: The DWC2 HCD |
diff --git a/drivers/usb/dwc2/pci.c b/drivers/usb/dwc2/pci.c index c291fca5d21f..a4e724b0a62e 100644 --- a/drivers/usb/dwc2/pci.c +++ b/drivers/usb/dwc2/pci.c | |||
@@ -141,6 +141,13 @@ static int dwc2_driver_probe(struct pci_dev *dev, | |||
141 | 141 | ||
142 | pci_set_master(dev); | 142 | pci_set_master(dev); |
143 | 143 | ||
144 | retval = devm_request_irq(hsotg->dev, dev->irq, | ||
145 | dwc2_handle_common_intr, IRQF_SHARED, | ||
146 | dev_name(hsotg->dev), hsotg); | ||
147 | if (retval) | ||
148 | return retval; | ||
149 | |||
150 | spin_lock_init(&hsotg->lock); | ||
144 | retval = dwc2_hcd_init(hsotg, dev->irq, &dwc2_module_params); | 151 | retval = dwc2_hcd_init(hsotg, dev->irq, &dwc2_module_params); |
145 | if (retval) { | 152 | if (retval) { |
146 | pci_disable_device(dev); | 153 | pci_disable_device(dev); |
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 121dbdafc06b..6a795aa2ff05 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/device.h> | 40 | #include <linux/device.h> |
41 | #include <linux/dma-mapping.h> | 41 | #include <linux/dma-mapping.h> |
42 | #include <linux/of_device.h> | 42 | #include <linux/of_device.h> |
43 | #include <linux/mutex.h> | ||
43 | #include <linux/platform_device.h> | 44 | #include <linux/platform_device.h> |
44 | 45 | ||
45 | #include <linux/usb/of.h> | 46 | #include <linux/usb/of.h> |
@@ -121,6 +122,7 @@ static int dwc2_driver_remove(struct platform_device *dev) | |||
121 | struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); | 122 | struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); |
122 | 123 | ||
123 | dwc2_hcd_remove(hsotg); | 124 | dwc2_hcd_remove(hsotg); |
125 | s3c_hsotg_remove(hsotg); | ||
124 | 126 | ||
125 | return 0; | 127 | return 0; |
126 | } | 128 | } |
@@ -129,6 +131,7 @@ static const struct of_device_id dwc2_of_match_table[] = { | |||
129 | { .compatible = "brcm,bcm2835-usb", .data = ¶ms_bcm2835 }, | 131 | { .compatible = "brcm,bcm2835-usb", .data = ¶ms_bcm2835 }, |
130 | { .compatible = "rockchip,rk3066-usb", .data = ¶ms_rk3066 }, | 132 | { .compatible = "rockchip,rk3066-usb", .data = ¶ms_rk3066 }, |
131 | { .compatible = "snps,dwc2", .data = NULL }, | 133 | { .compatible = "snps,dwc2", .data = NULL }, |
134 | { .compatible = "samsung,s3c6400-hsotg", .data = NULL}, | ||
132 | {}, | 135 | {}, |
133 | }; | 136 | }; |
134 | MODULE_DEVICE_TABLE(of, dwc2_of_match_table); | 137 | MODULE_DEVICE_TABLE(of, dwc2_of_match_table); |
@@ -155,9 +158,6 @@ static int dwc2_driver_probe(struct platform_device *dev) | |||
155 | int retval; | 158 | int retval; |
156 | int irq; | 159 | int irq; |
157 | 160 | ||
158 | if (usb_disabled()) | ||
159 | return -ENODEV; | ||
160 | |||
161 | match = of_match_device(dwc2_of_match_table, &dev->dev); | 161 | match = of_match_device(dwc2_of_match_table, &dev->dev); |
162 | if (match && match->data) { | 162 | if (match && match->data) { |
163 | params = match->data; | 163 | params = match->data; |
@@ -194,6 +194,14 @@ static int dwc2_driver_probe(struct platform_device *dev) | |||
194 | return irq; | 194 | return irq; |
195 | } | 195 | } |
196 | 196 | ||
197 | dev_dbg(hsotg->dev, "registering common handler for irq%d\n", | ||
198 | irq); | ||
199 | retval = devm_request_irq(hsotg->dev, irq, | ||
200 | dwc2_handle_common_intr, IRQF_SHARED, | ||
201 | dev_name(hsotg->dev), hsotg); | ||
202 | if (retval) | ||
203 | return retval; | ||
204 | |||
197 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); | 205 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); |
198 | hsotg->regs = devm_ioremap_resource(&dev->dev, res); | 206 | hsotg->regs = devm_ioremap_resource(&dev->dev, res); |
199 | if (IS_ERR(hsotg->regs)) | 207 | if (IS_ERR(hsotg->regs)) |
@@ -204,6 +212,11 @@ static int dwc2_driver_probe(struct platform_device *dev) | |||
204 | 212 | ||
205 | hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node); | 213 | hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node); |
206 | 214 | ||
215 | spin_lock_init(&hsotg->lock); | ||
216 | mutex_init(&hsotg->init_mutex); | ||
217 | retval = dwc2_gadget_init(hsotg, irq); | ||
218 | if (retval) | ||
219 | return retval; | ||
207 | retval = dwc2_hcd_init(hsotg, irq, params); | 220 | retval = dwc2_hcd_init(hsotg, irq, params); |
208 | if (retval) | 221 | if (retval) |
209 | return retval; | 222 | return retval; |
@@ -213,10 +226,35 @@ static int dwc2_driver_probe(struct platform_device *dev) | |||
213 | return retval; | 226 | return retval; |
214 | } | 227 | } |
215 | 228 | ||
229 | static int __maybe_unused dwc2_suspend(struct device *dev) | ||
230 | { | ||
231 | struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev); | ||
232 | int ret = 0; | ||
233 | |||
234 | if (dwc2_is_device_mode(dwc2)) | ||
235 | ret = s3c_hsotg_suspend(dwc2); | ||
236 | return ret; | ||
237 | } | ||
238 | |||
239 | static int __maybe_unused dwc2_resume(struct device *dev) | ||
240 | { | ||
241 | struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev); | ||
242 | int ret = 0; | ||
243 | |||
244 | if (dwc2_is_device_mode(dwc2)) | ||
245 | ret = s3c_hsotg_resume(dwc2); | ||
246 | return ret; | ||
247 | } | ||
248 | |||
249 | static const struct dev_pm_ops dwc2_dev_pm_ops = { | ||
250 | SET_SYSTEM_SLEEP_PM_OPS(dwc2_suspend, dwc2_resume) | ||
251 | }; | ||
252 | |||
216 | static struct platform_driver dwc2_platform_driver = { | 253 | static struct platform_driver dwc2_platform_driver = { |
217 | .driver = { | 254 | .driver = { |
218 | .name = dwc2_driver_name, | 255 | .name = dwc2_driver_name, |
219 | .of_match_table = dwc2_of_match_table, | 256 | .of_match_table = dwc2_of_match_table, |
257 | .pm = &dwc2_dev_pm_ops, | ||
220 | }, | 258 | }, |
221 | .probe = dwc2_driver_probe, | 259 | .probe = dwc2_driver_probe, |
222 | .remove = dwc2_driver_remove, | 260 | .remove = dwc2_driver_remove, |
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index f4e5cc60db0b..58b5b2cde4c5 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig | |||
@@ -55,7 +55,7 @@ config USB_DWC3_OMAP | |||
55 | 55 | ||
56 | config USB_DWC3_EXYNOS | 56 | config USB_DWC3_EXYNOS |
57 | tristate "Samsung Exynos Platform" | 57 | tristate "Samsung Exynos Platform" |
58 | depends on ARCH_EXYNOS || COMPILE_TEST | 58 | depends on ARCH_EXYNOS && OF || COMPILE_TEST |
59 | default USB_DWC3 | 59 | default USB_DWC3 |
60 | help | 60 | help |
61 | Recent Exynos5 SoCs ship with one DesignWare Core USB3 IP inside, | 61 | Recent Exynos5 SoCs ship with one DesignWare Core USB3 IP inside, |
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index b0f4d52b7f04..25ddc39efad8 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c | |||
@@ -19,6 +19,7 @@ | |||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <linux/version.h> | ||
22 | #include <linux/module.h> | 23 | #include <linux/module.h> |
23 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
24 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
@@ -32,6 +33,7 @@ | |||
32 | #include <linux/delay.h> | 33 | #include <linux/delay.h> |
33 | #include <linux/dma-mapping.h> | 34 | #include <linux/dma-mapping.h> |
34 | #include <linux/of.h> | 35 | #include <linux/of.h> |
36 | #include <linux/acpi.h> | ||
35 | 37 | ||
36 | #include <linux/usb/ch9.h> | 38 | #include <linux/usb/ch9.h> |
37 | #include <linux/usb/gadget.h> | 39 | #include <linux/usb/gadget.h> |
@@ -363,6 +365,72 @@ static void dwc3_cache_hwparams(struct dwc3 *dwc) | |||
363 | } | 365 | } |
364 | 366 | ||
365 | /** | 367 | /** |
368 | * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core | ||
369 | * @dwc: Pointer to our controller context structure | ||
370 | */ | ||
371 | static void dwc3_phy_setup(struct dwc3 *dwc) | ||
372 | { | ||
373 | u32 reg; | ||
374 | |||
375 | reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); | ||
376 | |||
377 | /* | ||
378 | * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY | ||
379 | * to '0' during coreConsultant configuration. So default value | ||
380 | * will be '0' when the core is reset. Application needs to set it | ||
381 | * to '1' after the core initialization is completed. | ||
382 | */ | ||
383 | if (dwc->revision > DWC3_REVISION_194A) | ||
384 | reg |= DWC3_GUSB3PIPECTL_SUSPHY; | ||
385 | |||
386 | if (dwc->u2ss_inp3_quirk) | ||
387 | reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK; | ||
388 | |||
389 | if (dwc->req_p1p2p3_quirk) | ||
390 | reg |= DWC3_GUSB3PIPECTL_REQP1P2P3; | ||
391 | |||
392 | if (dwc->del_p1p2p3_quirk) | ||
393 | reg |= DWC3_GUSB3PIPECTL_DEP1P2P3_EN; | ||
394 | |||
395 | if (dwc->del_phy_power_chg_quirk) | ||
396 | reg |= DWC3_GUSB3PIPECTL_DEPOCHANGE; | ||
397 | |||
398 | if (dwc->lfps_filter_quirk) | ||
399 | reg |= DWC3_GUSB3PIPECTL_LFPSFILT; | ||
400 | |||
401 | if (dwc->rx_detect_poll_quirk) | ||
402 | reg |= DWC3_GUSB3PIPECTL_RX_DETOPOLL; | ||
403 | |||
404 | if (dwc->tx_de_emphasis_quirk) | ||
405 | reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); | ||
406 | |||
407 | if (dwc->dis_u3_susphy_quirk) | ||
408 | reg &= ~DWC3_GUSB3PIPECTL_SUSPHY; | ||
409 | |||
410 | dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); | ||
411 | |||
412 | mdelay(100); | ||
413 | |||
414 | reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); | ||
415 | |||
416 | /* | ||
417 | * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to | ||
418 | * '0' during coreConsultant configuration. So default value will | ||
419 | * be '0' when the core is reset. Application needs to set it to | ||
420 | * '1' after the core initialization is completed. | ||
421 | */ | ||
422 | if (dwc->revision > DWC3_REVISION_194A) | ||
423 | reg |= DWC3_GUSB2PHYCFG_SUSPHY; | ||
424 | |||
425 | if (dwc->dis_u2_susphy_quirk) | ||
426 | reg &= ~DWC3_GUSB2PHYCFG_SUSPHY; | ||
427 | |||
428 | dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); | ||
429 | |||
430 | mdelay(100); | ||
431 | } | ||
432 | |||
433 | /** | ||
366 | * dwc3_core_init - Low-level initialization of DWC3 Core | 434 | * dwc3_core_init - Low-level initialization of DWC3 Core |
367 | * @dwc: Pointer to our controller context structure | 435 | * @dwc: Pointer to our controller context structure |
368 | * | 436 | * |
@@ -384,6 +452,12 @@ static int dwc3_core_init(struct dwc3 *dwc) | |||
384 | } | 452 | } |
385 | dwc->revision = reg; | 453 | dwc->revision = reg; |
386 | 454 | ||
455 | /* | ||
456 | * Write Linux Version Code to our GUID register so it's easy to figure | ||
457 | * out which kernel version a bug was found. | ||
458 | */ | ||
459 | dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); | ||
460 | |||
387 | /* Handle USB2.0-only core configuration */ | 461 | /* Handle USB2.0-only core configuration */ |
388 | if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) == | 462 | if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) == |
389 | DWC3_GHWPARAMS3_SSPHY_IFC_DIS) { | 463 | DWC3_GHWPARAMS3_SSPHY_IFC_DIS) { |
@@ -414,7 +488,6 @@ static int dwc3_core_init(struct dwc3 *dwc) | |||
414 | 488 | ||
415 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); | 489 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
416 | reg &= ~DWC3_GCTL_SCALEDOWN_MASK; | 490 | reg &= ~DWC3_GCTL_SCALEDOWN_MASK; |
417 | reg &= ~DWC3_GCTL_DISSCRAMBLE; | ||
418 | 491 | ||
419 | switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { | 492 | switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { |
420 | case DWC3_GHWPARAMS1_EN_PWROPT_CLK: | 493 | case DWC3_GHWPARAMS1_EN_PWROPT_CLK: |
@@ -441,11 +514,34 @@ static int dwc3_core_init(struct dwc3 *dwc) | |||
441 | case DWC3_GHWPARAMS1_EN_PWROPT_HIB: | 514 | case DWC3_GHWPARAMS1_EN_PWROPT_HIB: |
442 | /* enable hibernation here */ | 515 | /* enable hibernation here */ |
443 | dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4); | 516 | dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4); |
517 | |||
518 | /* | ||
519 | * REVISIT Enabling this bit so that host-mode hibernation | ||
520 | * will work. Device-mode hibernation is not yet implemented. | ||
521 | */ | ||
522 | reg |= DWC3_GCTL_GBLHIBERNATIONEN; | ||
444 | break; | 523 | break; |
445 | default: | 524 | default: |
446 | dev_dbg(dwc->dev, "No power optimization available\n"); | 525 | dev_dbg(dwc->dev, "No power optimization available\n"); |
447 | } | 526 | } |
448 | 527 | ||
528 | /* check if current dwc3 is on simulation board */ | ||
529 | if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { | ||
530 | dev_dbg(dwc->dev, "it is on FPGA board\n"); | ||
531 | dwc->is_fpga = true; | ||
532 | } | ||
533 | |||
534 | WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, | ||
535 | "disable_scramble cannot be used on non-FPGA builds\n"); | ||
536 | |||
537 | if (dwc->disable_scramble_quirk && dwc->is_fpga) | ||
538 | reg |= DWC3_GCTL_DISSCRAMBLE; | ||
539 | else | ||
540 | reg &= ~DWC3_GCTL_DISSCRAMBLE; | ||
541 | |||
542 | if (dwc->u2exit_lfps_quirk) | ||
543 | reg |= DWC3_GCTL_U2EXIT_LFPS; | ||
544 | |||
449 | /* | 545 | /* |
450 | * WORKAROUND: DWC3 revisions <1.90a have a bug | 546 | * WORKAROUND: DWC3 revisions <1.90a have a bug |
451 | * where the device can fail to connect at SuperSpeed | 547 | * where the device can fail to connect at SuperSpeed |
@@ -459,6 +555,8 @@ static int dwc3_core_init(struct dwc3 *dwc) | |||
459 | 555 | ||
460 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); | 556 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
461 | 557 | ||
558 | dwc3_phy_setup(dwc); | ||
559 | |||
462 | ret = dwc3_alloc_scratch_buffers(dwc); | 560 | ret = dwc3_alloc_scratch_buffers(dwc); |
463 | if (ret) | 561 | if (ret) |
464 | goto err1; | 562 | goto err1; |
@@ -630,6 +728,9 @@ static int dwc3_probe(struct platform_device *pdev) | |||
630 | struct device_node *node = dev->of_node; | 728 | struct device_node *node = dev->of_node; |
631 | struct resource *res; | 729 | struct resource *res; |
632 | struct dwc3 *dwc; | 730 | struct dwc3 *dwc; |
731 | u8 lpm_nyet_threshold; | ||
732 | u8 tx_de_emphasis; | ||
733 | u8 hird_threshold; | ||
633 | 734 | ||
634 | int ret; | 735 | int ret; |
635 | 736 | ||
@@ -685,22 +786,96 @@ static int dwc3_probe(struct platform_device *pdev) | |||
685 | */ | 786 | */ |
686 | res->start -= DWC3_GLOBALS_REGS_START; | 787 | res->start -= DWC3_GLOBALS_REGS_START; |
687 | 788 | ||
789 | /* default to highest possible threshold */ | ||
790 | lpm_nyet_threshold = 0xff; | ||
791 | |||
792 | /* default to -3.5dB de-emphasis */ | ||
793 | tx_de_emphasis = 1; | ||
794 | |||
795 | /* | ||
796 | * default to assert utmi_sleep_n and use maximum allowed HIRD | ||
797 | * threshold value of 0b1100 | ||
798 | */ | ||
799 | hird_threshold = 12; | ||
800 | |||
688 | if (node) { | 801 | if (node) { |
689 | dwc->maximum_speed = of_usb_get_maximum_speed(node); | 802 | dwc->maximum_speed = of_usb_get_maximum_speed(node); |
690 | 803 | dwc->has_lpm_erratum = of_property_read_bool(node, | |
691 | dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize"); | 804 | "snps,has-lpm-erratum"); |
805 | of_property_read_u8(node, "snps,lpm-nyet-threshold", | ||
806 | &lpm_nyet_threshold); | ||
807 | dwc->is_utmi_l1_suspend = of_property_read_bool(node, | ||
808 | "snps,is-utmi-l1-suspend"); | ||
809 | of_property_read_u8(node, "snps,hird-threshold", | ||
810 | &hird_threshold); | ||
811 | |||
812 | dwc->needs_fifo_resize = of_property_read_bool(node, | ||
813 | "tx-fifo-resize"); | ||
692 | dwc->dr_mode = of_usb_get_dr_mode(node); | 814 | dwc->dr_mode = of_usb_get_dr_mode(node); |
815 | |||
816 | dwc->disable_scramble_quirk = of_property_read_bool(node, | ||
817 | "snps,disable_scramble_quirk"); | ||
818 | dwc->u2exit_lfps_quirk = of_property_read_bool(node, | ||
819 | "snps,u2exit_lfps_quirk"); | ||
820 | dwc->u2ss_inp3_quirk = of_property_read_bool(node, | ||
821 | "snps,u2ss_inp3_quirk"); | ||
822 | dwc->req_p1p2p3_quirk = of_property_read_bool(node, | ||
823 | "snps,req_p1p2p3_quirk"); | ||
824 | dwc->del_p1p2p3_quirk = of_property_read_bool(node, | ||
825 | "snps,del_p1p2p3_quirk"); | ||
826 | dwc->del_phy_power_chg_quirk = of_property_read_bool(node, | ||
827 | "snps,del_phy_power_chg_quirk"); | ||
828 | dwc->lfps_filter_quirk = of_property_read_bool(node, | ||
829 | "snps,lfps_filter_quirk"); | ||
830 | dwc->rx_detect_poll_quirk = of_property_read_bool(node, | ||
831 | "snps,rx_detect_poll_quirk"); | ||
832 | dwc->dis_u3_susphy_quirk = of_property_read_bool(node, | ||
833 | "snps,dis_u3_susphy_quirk"); | ||
834 | dwc->dis_u2_susphy_quirk = of_property_read_bool(node, | ||
835 | "snps,dis_u2_susphy_quirk"); | ||
836 | |||
837 | dwc->tx_de_emphasis_quirk = of_property_read_bool(node, | ||
838 | "snps,tx_de_emphasis_quirk"); | ||
839 | of_property_read_u8(node, "snps,tx_de_emphasis", | ||
840 | &tx_de_emphasis); | ||
693 | } else if (pdata) { | 841 | } else if (pdata) { |
694 | dwc->maximum_speed = pdata->maximum_speed; | 842 | dwc->maximum_speed = pdata->maximum_speed; |
843 | dwc->has_lpm_erratum = pdata->has_lpm_erratum; | ||
844 | if (pdata->lpm_nyet_threshold) | ||
845 | lpm_nyet_threshold = pdata->lpm_nyet_threshold; | ||
846 | dwc->is_utmi_l1_suspend = pdata->is_utmi_l1_suspend; | ||
847 | if (pdata->hird_threshold) | ||
848 | hird_threshold = pdata->hird_threshold; | ||
695 | 849 | ||
696 | dwc->needs_fifo_resize = pdata->tx_fifo_resize; | 850 | dwc->needs_fifo_resize = pdata->tx_fifo_resize; |
697 | dwc->dr_mode = pdata->dr_mode; | 851 | dwc->dr_mode = pdata->dr_mode; |
852 | |||
853 | dwc->disable_scramble_quirk = pdata->disable_scramble_quirk; | ||
854 | dwc->u2exit_lfps_quirk = pdata->u2exit_lfps_quirk; | ||
855 | dwc->u2ss_inp3_quirk = pdata->u2ss_inp3_quirk; | ||
856 | dwc->req_p1p2p3_quirk = pdata->req_p1p2p3_quirk; | ||
857 | dwc->del_p1p2p3_quirk = pdata->del_p1p2p3_quirk; | ||
858 | dwc->del_phy_power_chg_quirk = pdata->del_phy_power_chg_quirk; | ||
859 | dwc->lfps_filter_quirk = pdata->lfps_filter_quirk; | ||
860 | dwc->rx_detect_poll_quirk = pdata->rx_detect_poll_quirk; | ||
861 | dwc->dis_u3_susphy_quirk = pdata->dis_u3_susphy_quirk; | ||
862 | dwc->dis_u2_susphy_quirk = pdata->dis_u2_susphy_quirk; | ||
863 | |||
864 | dwc->tx_de_emphasis_quirk = pdata->tx_de_emphasis_quirk; | ||
865 | if (pdata->tx_de_emphasis) | ||
866 | tx_de_emphasis = pdata->tx_de_emphasis; | ||
698 | } | 867 | } |
699 | 868 | ||
700 | /* default to superspeed if no maximum_speed passed */ | 869 | /* default to superspeed if no maximum_speed passed */ |
701 | if (dwc->maximum_speed == USB_SPEED_UNKNOWN) | 870 | if (dwc->maximum_speed == USB_SPEED_UNKNOWN) |
702 | dwc->maximum_speed = USB_SPEED_SUPER; | 871 | dwc->maximum_speed = USB_SPEED_SUPER; |
703 | 872 | ||
873 | dwc->lpm_nyet_threshold = lpm_nyet_threshold; | ||
874 | dwc->tx_de_emphasis = tx_de_emphasis; | ||
875 | |||
876 | dwc->hird_threshold = hird_threshold | ||
877 | | (dwc->is_utmi_l1_suspend << 4); | ||
878 | |||
704 | ret = dwc3_core_get_phy(dwc); | 879 | ret = dwc3_core_get_phy(dwc); |
705 | if (ret) | 880 | if (ret) |
706 | return ret; | 881 | return ret; |
@@ -708,9 +883,11 @@ static int dwc3_probe(struct platform_device *pdev) | |||
708 | spin_lock_init(&dwc->lock); | 883 | spin_lock_init(&dwc->lock); |
709 | platform_set_drvdata(pdev, dwc); | 884 | platform_set_drvdata(pdev, dwc); |
710 | 885 | ||
711 | dev->dma_mask = dev->parent->dma_mask; | 886 | if (!dev->dma_mask) { |
712 | dev->dma_parms = dev->parent->dma_parms; | 887 | dev->dma_mask = dev->parent->dma_mask; |
713 | dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask); | 888 | dev->dma_parms = dev->parent->dma_parms; |
889 | dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask); | ||
890 | } | ||
714 | 891 | ||
715 | pm_runtime_enable(dev); | 892 | pm_runtime_enable(dev); |
716 | pm_runtime_get_sync(dev); | 893 | pm_runtime_get_sync(dev); |
@@ -815,50 +992,6 @@ static int dwc3_remove(struct platform_device *pdev) | |||
815 | } | 992 | } |
816 | 993 | ||
817 | #ifdef CONFIG_PM_SLEEP | 994 | #ifdef CONFIG_PM_SLEEP |
818 | static int dwc3_prepare(struct device *dev) | ||
819 | { | ||
820 | struct dwc3 *dwc = dev_get_drvdata(dev); | ||
821 | unsigned long flags; | ||
822 | |||
823 | spin_lock_irqsave(&dwc->lock, flags); | ||
824 | |||
825 | switch (dwc->dr_mode) { | ||
826 | case USB_DR_MODE_PERIPHERAL: | ||
827 | case USB_DR_MODE_OTG: | ||
828 | dwc3_gadget_prepare(dwc); | ||
829 | /* FALLTHROUGH */ | ||
830 | case USB_DR_MODE_HOST: | ||
831 | default: | ||
832 | dwc3_event_buffers_cleanup(dwc); | ||
833 | break; | ||
834 | } | ||
835 | |||
836 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
837 | |||
838 | return 0; | ||
839 | } | ||
840 | |||
841 | static void dwc3_complete(struct device *dev) | ||
842 | { | ||
843 | struct dwc3 *dwc = dev_get_drvdata(dev); | ||
844 | unsigned long flags; | ||
845 | |||
846 | spin_lock_irqsave(&dwc->lock, flags); | ||
847 | |||
848 | dwc3_event_buffers_setup(dwc); | ||
849 | switch (dwc->dr_mode) { | ||
850 | case USB_DR_MODE_PERIPHERAL: | ||
851 | case USB_DR_MODE_OTG: | ||
852 | dwc3_gadget_complete(dwc); | ||
853 | /* FALLTHROUGH */ | ||
854 | case USB_DR_MODE_HOST: | ||
855 | default: | ||
856 | break; | ||
857 | } | ||
858 | |||
859 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
860 | } | ||
861 | |||
862 | static int dwc3_suspend(struct device *dev) | 995 | static int dwc3_suspend(struct device *dev) |
863 | { | 996 | { |
864 | struct dwc3 *dwc = dev_get_drvdata(dev); | 997 | struct dwc3 *dwc = dev_get_drvdata(dev); |
@@ -873,7 +1006,7 @@ static int dwc3_suspend(struct device *dev) | |||
873 | /* FALLTHROUGH */ | 1006 | /* FALLTHROUGH */ |
874 | case USB_DR_MODE_HOST: | 1007 | case USB_DR_MODE_HOST: |
875 | default: | 1008 | default: |
876 | /* do nothing */ | 1009 | dwc3_event_buffers_cleanup(dwc); |
877 | break; | 1010 | break; |
878 | } | 1011 | } |
879 | 1012 | ||
@@ -906,6 +1039,7 @@ static int dwc3_resume(struct device *dev) | |||
906 | 1039 | ||
907 | spin_lock_irqsave(&dwc->lock, flags); | 1040 | spin_lock_irqsave(&dwc->lock, flags); |
908 | 1041 | ||
1042 | dwc3_event_buffers_setup(dwc); | ||
909 | dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl); | 1043 | dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl); |
910 | 1044 | ||
911 | switch (dwc->dr_mode) { | 1045 | switch (dwc->dr_mode) { |
@@ -934,9 +1068,6 @@ err_usb2phy_init: | |||
934 | } | 1068 | } |
935 | 1069 | ||
936 | static const struct dev_pm_ops dwc3_dev_pm_ops = { | 1070 | static const struct dev_pm_ops dwc3_dev_pm_ops = { |
937 | .prepare = dwc3_prepare, | ||
938 | .complete = dwc3_complete, | ||
939 | |||
940 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) | 1071 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) |
941 | }; | 1072 | }; |
942 | 1073 | ||
@@ -958,12 +1089,24 @@ static const struct of_device_id of_dwc3_match[] = { | |||
958 | MODULE_DEVICE_TABLE(of, of_dwc3_match); | 1089 | MODULE_DEVICE_TABLE(of, of_dwc3_match); |
959 | #endif | 1090 | #endif |
960 | 1091 | ||
1092 | #ifdef CONFIG_ACPI | ||
1093 | |||
1094 | #define ACPI_ID_INTEL_BSW "808622B7" | ||
1095 | |||
1096 | static const struct acpi_device_id dwc3_acpi_match[] = { | ||
1097 | { ACPI_ID_INTEL_BSW, 0 }, | ||
1098 | { }, | ||
1099 | }; | ||
1100 | MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match); | ||
1101 | #endif | ||
1102 | |||
961 | static struct platform_driver dwc3_driver = { | 1103 | static struct platform_driver dwc3_driver = { |
962 | .probe = dwc3_probe, | 1104 | .probe = dwc3_probe, |
963 | .remove = dwc3_remove, | 1105 | .remove = dwc3_remove, |
964 | .driver = { | 1106 | .driver = { |
965 | .name = "dwc3", | 1107 | .name = "dwc3", |
966 | .of_match_table = of_match_ptr(of_dwc3_match), | 1108 | .of_match_table = of_match_ptr(of_dwc3_match), |
1109 | .acpi_match_table = ACPI_PTR(dwc3_acpi_match), | ||
967 | .pm = DWC3_PM_OPS, | 1110 | .pm = DWC3_PM_OPS, |
968 | }, | 1111 | }, |
969 | }; | 1112 | }; |
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 66f62563bcf9..4bb9aa696ede 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h | |||
@@ -166,6 +166,7 @@ | |||
166 | #define DWC3_GCTL_SCALEDOWN(n) ((n) << 4) | 166 | #define DWC3_GCTL_SCALEDOWN(n) ((n) << 4) |
167 | #define DWC3_GCTL_SCALEDOWN_MASK DWC3_GCTL_SCALEDOWN(3) | 167 | #define DWC3_GCTL_SCALEDOWN_MASK DWC3_GCTL_SCALEDOWN(3) |
168 | #define DWC3_GCTL_DISSCRAMBLE (1 << 3) | 168 | #define DWC3_GCTL_DISSCRAMBLE (1 << 3) |
169 | #define DWC3_GCTL_U2EXIT_LFPS (1 << 2) | ||
169 | #define DWC3_GCTL_GBLHIBERNATIONEN (1 << 1) | 170 | #define DWC3_GCTL_GBLHIBERNATIONEN (1 << 1) |
170 | #define DWC3_GCTL_DSBLCLKGTNG (1 << 0) | 171 | #define DWC3_GCTL_DSBLCLKGTNG (1 << 0) |
171 | 172 | ||
@@ -175,7 +176,17 @@ | |||
175 | 176 | ||
176 | /* Global USB3 PIPE Control Register */ | 177 | /* Global USB3 PIPE Control Register */ |
177 | #define DWC3_GUSB3PIPECTL_PHYSOFTRST (1 << 31) | 178 | #define DWC3_GUSB3PIPECTL_PHYSOFTRST (1 << 31) |
179 | #define DWC3_GUSB3PIPECTL_U2SSINP3OK (1 << 29) | ||
180 | #define DWC3_GUSB3PIPECTL_REQP1P2P3 (1 << 24) | ||
181 | #define DWC3_GUSB3PIPECTL_DEP1P2P3(n) ((n) << 19) | ||
182 | #define DWC3_GUSB3PIPECTL_DEP1P2P3_MASK DWC3_GUSB3PIPECTL_DEP1P2P3(7) | ||
183 | #define DWC3_GUSB3PIPECTL_DEP1P2P3_EN DWC3_GUSB3PIPECTL_DEP1P2P3(1) | ||
184 | #define DWC3_GUSB3PIPECTL_DEPOCHANGE (1 << 18) | ||
178 | #define DWC3_GUSB3PIPECTL_SUSPHY (1 << 17) | 185 | #define DWC3_GUSB3PIPECTL_SUSPHY (1 << 17) |
186 | #define DWC3_GUSB3PIPECTL_LFPSFILT (1 << 9) | ||
187 | #define DWC3_GUSB3PIPECTL_RX_DETOPOLL (1 << 8) | ||
188 | #define DWC3_GUSB3PIPECTL_TX_DEEPH_MASK DWC3_GUSB3PIPECTL_TX_DEEPH(3) | ||
189 | #define DWC3_GUSB3PIPECTL_TX_DEEPH(n) ((n) << 1) | ||
179 | 190 | ||
180 | /* Global TX Fifo Size Register */ | 191 | /* Global TX Fifo Size Register */ |
181 | #define DWC3_GTXFIFOSIZ_TXFDEF(n) ((n) & 0xffff) | 192 | #define DWC3_GTXFIFOSIZ_TXFDEF(n) ((n) & 0xffff) |
@@ -210,6 +221,9 @@ | |||
210 | #define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n) (((n) & (0x0f << 13)) >> 13) | 221 | #define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n) (((n) & (0x0f << 13)) >> 13) |
211 | #define DWC3_MAX_HIBER_SCRATCHBUFS 15 | 222 | #define DWC3_MAX_HIBER_SCRATCHBUFS 15 |
212 | 223 | ||
224 | /* Global HWPARAMS6 Register */ | ||
225 | #define DWC3_GHWPARAMS6_EN_FPGA (1 << 7) | ||
226 | |||
213 | /* Device Configuration Register */ | 227 | /* Device Configuration Register */ |
214 | #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3) | 228 | #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3) |
215 | #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f) | 229 | #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f) |
@@ -243,16 +257,19 @@ | |||
243 | #define DWC3_DCTL_TRGTULST_SS_INACT (DWC3_DCTL_TRGTULST(6)) | 257 | #define DWC3_DCTL_TRGTULST_SS_INACT (DWC3_DCTL_TRGTULST(6)) |
244 | 258 | ||
245 | /* These apply for core versions 1.94a and later */ | 259 | /* These apply for core versions 1.94a and later */ |
246 | #define DWC3_DCTL_KEEP_CONNECT (1 << 19) | 260 | #define DWC3_DCTL_LPM_ERRATA_MASK DWC3_DCTL_LPM_ERRATA(0xf) |
247 | #define DWC3_DCTL_L1_HIBER_EN (1 << 18) | 261 | #define DWC3_DCTL_LPM_ERRATA(n) ((n) << 20) |
248 | #define DWC3_DCTL_CRS (1 << 17) | 262 | |
249 | #define DWC3_DCTL_CSS (1 << 16) | 263 | #define DWC3_DCTL_KEEP_CONNECT (1 << 19) |
264 | #define DWC3_DCTL_L1_HIBER_EN (1 << 18) | ||
265 | #define DWC3_DCTL_CRS (1 << 17) | ||
266 | #define DWC3_DCTL_CSS (1 << 16) | ||
250 | 267 | ||
251 | #define DWC3_DCTL_INITU2ENA (1 << 12) | 268 | #define DWC3_DCTL_INITU2ENA (1 << 12) |
252 | #define DWC3_DCTL_ACCEPTU2ENA (1 << 11) | 269 | #define DWC3_DCTL_ACCEPTU2ENA (1 << 11) |
253 | #define DWC3_DCTL_INITU1ENA (1 << 10) | 270 | #define DWC3_DCTL_INITU1ENA (1 << 10) |
254 | #define DWC3_DCTL_ACCEPTU1ENA (1 << 9) | 271 | #define DWC3_DCTL_ACCEPTU1ENA (1 << 9) |
255 | #define DWC3_DCTL_TSTCTRL_MASK (0xf << 1) | 272 | #define DWC3_DCTL_TSTCTRL_MASK (0xf << 1) |
256 | 273 | ||
257 | #define DWC3_DCTL_ULSTCHNGREQ_MASK (0x0f << 5) | 274 | #define DWC3_DCTL_ULSTCHNGREQ_MASK (0x0f << 5) |
258 | #define DWC3_DCTL_ULSTCHNGREQ(n) (((n) << 5) & DWC3_DCTL_ULSTCHNGREQ_MASK) | 275 | #define DWC3_DCTL_ULSTCHNGREQ(n) (((n) << 5) & DWC3_DCTL_ULSTCHNGREQ_MASK) |
@@ -657,17 +674,41 @@ struct dwc3_scratchpad_array { | |||
657 | * @regset: debugfs pointer to regdump file | 674 | * @regset: debugfs pointer to regdump file |
658 | * @test_mode: true when we're entering a USB test mode | 675 | * @test_mode: true when we're entering a USB test mode |
659 | * @test_mode_nr: test feature selector | 676 | * @test_mode_nr: test feature selector |
677 | * @lpm_nyet_threshold: LPM NYET response threshold | ||
678 | * @hird_threshold: HIRD threshold | ||
660 | * @delayed_status: true when gadget driver asks for delayed status | 679 | * @delayed_status: true when gadget driver asks for delayed status |
661 | * @ep0_bounced: true when we used bounce buffer | 680 | * @ep0_bounced: true when we used bounce buffer |
662 | * @ep0_expect_in: true when we expect a DATA IN transfer | 681 | * @ep0_expect_in: true when we expect a DATA IN transfer |
663 | * @has_hibernation: true when dwc3 was configured with Hibernation | 682 | * @has_hibernation: true when dwc3 was configured with Hibernation |
683 | * @has_lpm_erratum: true when core was configured with LPM Erratum. Note that | ||
684 | * there's now way for software to detect this in runtime. | ||
685 | * @is_utmi_l1_suspend: the core asserts output signal | ||
686 | * 0 - utmi_sleep_n | ||
687 | * 1 - utmi_l1_suspend_n | ||
664 | * @is_selfpowered: true when we are selfpowered | 688 | * @is_selfpowered: true when we are selfpowered |
689 | * @is_fpga: true when we are using the FPGA board | ||
665 | * @needs_fifo_resize: not all users might want fifo resizing, flag it | 690 | * @needs_fifo_resize: not all users might want fifo resizing, flag it |
666 | * @pullups_connected: true when Run/Stop bit is set | 691 | * @pullups_connected: true when Run/Stop bit is set |
667 | * @resize_fifos: tells us it's ok to reconfigure our TxFIFO sizes. | 692 | * @resize_fifos: tells us it's ok to reconfigure our TxFIFO sizes. |
668 | * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround | 693 | * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround |
669 | * @start_config_issued: true when StartConfig command has been issued | 694 | * @start_config_issued: true when StartConfig command has been issued |
670 | * @three_stage_setup: set if we perform a three phase setup | 695 | * @three_stage_setup: set if we perform a three phase setup |
696 | * @disable_scramble_quirk: set if we enable the disable scramble quirk | ||
697 | * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk | ||
698 | * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk | ||
699 | * @req_p1p2p3_quirk: set if we enable request p1p2p3 quirk | ||
700 | * @del_p1p2p3_quirk: set if we enable delay p1p2p3 quirk | ||
701 | * @del_phy_power_chg_quirk: set if we enable delay phy power change quirk | ||
702 | * @lfps_filter_quirk: set if we enable LFPS filter quirk | ||
703 | * @rx_detect_poll_quirk: set if we enable rx_detect to polling lfps quirk | ||
704 | * @dis_u3_susphy_quirk: set if we disable usb3 suspend phy | ||
705 | * @dis_u2_susphy_quirk: set if we disable usb2 suspend phy | ||
706 | * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk | ||
707 | * @tx_de_emphasis: Tx de-emphasis value | ||
708 | * 0 - -6dB de-emphasis | ||
709 | * 1 - -3.5dB de-emphasis | ||
710 | * 2 - No de-emphasis | ||
711 | * 3 - Reserved | ||
671 | */ | 712 | */ |
672 | struct dwc3 { | 713 | struct dwc3 { |
673 | struct usb_ctrlrequest *ctrl_req; | 714 | struct usb_ctrlrequest *ctrl_req; |
@@ -759,18 +800,37 @@ struct dwc3 { | |||
759 | 800 | ||
760 | u8 test_mode; | 801 | u8 test_mode; |
761 | u8 test_mode_nr; | 802 | u8 test_mode_nr; |
803 | u8 lpm_nyet_threshold; | ||
804 | u8 hird_threshold; | ||
762 | 805 | ||
763 | unsigned delayed_status:1; | 806 | unsigned delayed_status:1; |
764 | unsigned ep0_bounced:1; | 807 | unsigned ep0_bounced:1; |
765 | unsigned ep0_expect_in:1; | 808 | unsigned ep0_expect_in:1; |
766 | unsigned has_hibernation:1; | 809 | unsigned has_hibernation:1; |
810 | unsigned has_lpm_erratum:1; | ||
811 | unsigned is_utmi_l1_suspend:1; | ||
767 | unsigned is_selfpowered:1; | 812 | unsigned is_selfpowered:1; |
813 | unsigned is_fpga:1; | ||
768 | unsigned needs_fifo_resize:1; | 814 | unsigned needs_fifo_resize:1; |
769 | unsigned pullups_connected:1; | 815 | unsigned pullups_connected:1; |
770 | unsigned resize_fifos:1; | 816 | unsigned resize_fifos:1; |
771 | unsigned setup_packet_pending:1; | 817 | unsigned setup_packet_pending:1; |
772 | unsigned start_config_issued:1; | 818 | unsigned start_config_issued:1; |
773 | unsigned three_stage_setup:1; | 819 | unsigned three_stage_setup:1; |
820 | |||
821 | unsigned disable_scramble_quirk:1; | ||
822 | unsigned u2exit_lfps_quirk:1; | ||
823 | unsigned u2ss_inp3_quirk:1; | ||
824 | unsigned req_p1p2p3_quirk:1; | ||
825 | unsigned del_p1p2p3_quirk:1; | ||
826 | unsigned del_phy_power_chg_quirk:1; | ||
827 | unsigned lfps_filter_quirk:1; | ||
828 | unsigned rx_detect_poll_quirk:1; | ||
829 | unsigned dis_u3_susphy_quirk:1; | ||
830 | unsigned dis_u2_susphy_quirk:1; | ||
831 | |||
832 | unsigned tx_de_emphasis_quirk:1; | ||
833 | unsigned tx_de_emphasis:2; | ||
774 | }; | 834 | }; |
775 | 835 | ||
776 | /* -------------------------------------------------------------------------- */ | 836 | /* -------------------------------------------------------------------------- */ |
@@ -964,20 +1024,9 @@ static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc, | |||
964 | 1024 | ||
965 | /* power management interface */ | 1025 | /* power management interface */ |
966 | #if !IS_ENABLED(CONFIG_USB_DWC3_HOST) | 1026 | #if !IS_ENABLED(CONFIG_USB_DWC3_HOST) |
967 | int dwc3_gadget_prepare(struct dwc3 *dwc); | ||
968 | void dwc3_gadget_complete(struct dwc3 *dwc); | ||
969 | int dwc3_gadget_suspend(struct dwc3 *dwc); | 1027 | int dwc3_gadget_suspend(struct dwc3 *dwc); |
970 | int dwc3_gadget_resume(struct dwc3 *dwc); | 1028 | int dwc3_gadget_resume(struct dwc3 *dwc); |
971 | #else | 1029 | #else |
972 | static inline int dwc3_gadget_prepare(struct dwc3 *dwc) | ||
973 | { | ||
974 | return 0; | ||
975 | } | ||
976 | |||
977 | static inline void dwc3_gadget_complete(struct dwc3 *dwc) | ||
978 | { | ||
979 | } | ||
980 | |||
981 | static inline int dwc3_gadget_suspend(struct dwc3 *dwc) | 1030 | static inline int dwc3_gadget_suspend(struct dwc3 *dwc) |
982 | { | 1031 | { |
983 | return 0; | 1032 | return 0; |
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index 3951a65fea04..7bd0a95b2815 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
22 | #include <linux/platform_device.h> | 22 | #include <linux/platform_device.h> |
23 | #include <linux/platform_data/dwc3-exynos.h> | ||
24 | #include <linux/dma-mapping.h> | 23 | #include <linux/dma-mapping.h> |
25 | #include <linux/clk.h> | 24 | #include <linux/clk.h> |
26 | #include <linux/usb/otg.h> | 25 | #include <linux/usb/otg.h> |
@@ -35,6 +34,9 @@ struct dwc3_exynos { | |||
35 | struct device *dev; | 34 | struct device *dev; |
36 | 35 | ||
37 | struct clk *clk; | 36 | struct clk *clk; |
37 | struct clk *susp_clk; | ||
38 | struct clk *axius_clk; | ||
39 | |||
38 | struct regulator *vdd33; | 40 | struct regulator *vdd33; |
39 | struct regulator *vdd10; | 41 | struct regulator *vdd10; |
40 | }; | 42 | }; |
@@ -106,7 +108,6 @@ static int dwc3_exynos_remove_child(struct device *dev, void *unused) | |||
106 | static int dwc3_exynos_probe(struct platform_device *pdev) | 108 | static int dwc3_exynos_probe(struct platform_device *pdev) |
107 | { | 109 | { |
108 | struct dwc3_exynos *exynos; | 110 | struct dwc3_exynos *exynos; |
109 | struct clk *clk; | ||
110 | struct device *dev = &pdev->dev; | 111 | struct device *dev = &pdev->dev; |
111 | struct device_node *node = dev->of_node; | 112 | struct device_node *node = dev->of_node; |
112 | 113 | ||
@@ -133,16 +134,32 @@ static int dwc3_exynos_probe(struct platform_device *pdev) | |||
133 | return ret; | 134 | return ret; |
134 | } | 135 | } |
135 | 136 | ||
136 | clk = devm_clk_get(dev, "usbdrd30"); | 137 | exynos->dev = dev; |
137 | if (IS_ERR(clk)) { | 138 | |
139 | exynos->clk = devm_clk_get(dev, "usbdrd30"); | ||
140 | if (IS_ERR(exynos->clk)) { | ||
138 | dev_err(dev, "couldn't get clock\n"); | 141 | dev_err(dev, "couldn't get clock\n"); |
139 | return -EINVAL; | 142 | return -EINVAL; |
140 | } | 143 | } |
144 | clk_prepare_enable(exynos->clk); | ||
141 | 145 | ||
142 | exynos->dev = dev; | 146 | exynos->susp_clk = devm_clk_get(dev, "usbdrd30_susp_clk"); |
143 | exynos->clk = clk; | 147 | if (IS_ERR(exynos->susp_clk)) { |
148 | dev_dbg(dev, "no suspend clk specified\n"); | ||
149 | exynos->susp_clk = NULL; | ||
150 | } | ||
151 | clk_prepare_enable(exynos->susp_clk); | ||
144 | 152 | ||
145 | clk_prepare_enable(exynos->clk); | 153 | if (of_device_is_compatible(node, "samsung,exynos7-dwusb3")) { |
154 | exynos->axius_clk = devm_clk_get(dev, "usbdrd30_axius_clk"); | ||
155 | if (IS_ERR(exynos->axius_clk)) { | ||
156 | dev_err(dev, "no AXI UpScaler clk specified\n"); | ||
157 | return -ENODEV; | ||
158 | } | ||
159 | clk_prepare_enable(exynos->axius_clk); | ||
160 | } else { | ||
161 | exynos->axius_clk = NULL; | ||
162 | } | ||
146 | 163 | ||
147 | exynos->vdd33 = devm_regulator_get(dev, "vdd33"); | 164 | exynos->vdd33 = devm_regulator_get(dev, "vdd33"); |
148 | if (IS_ERR(exynos->vdd33)) { | 165 | if (IS_ERR(exynos->vdd33)) { |
@@ -185,7 +202,9 @@ err4: | |||
185 | err3: | 202 | err3: |
186 | regulator_disable(exynos->vdd33); | 203 | regulator_disable(exynos->vdd33); |
187 | err2: | 204 | err2: |
188 | clk_disable_unprepare(clk); | 205 | clk_disable_unprepare(exynos->axius_clk); |
206 | clk_disable_unprepare(exynos->susp_clk); | ||
207 | clk_disable_unprepare(exynos->clk); | ||
189 | return ret; | 208 | return ret; |
190 | } | 209 | } |
191 | 210 | ||
@@ -197,6 +216,8 @@ static int dwc3_exynos_remove(struct platform_device *pdev) | |||
197 | platform_device_unregister(exynos->usb2_phy); | 216 | platform_device_unregister(exynos->usb2_phy); |
198 | platform_device_unregister(exynos->usb3_phy); | 217 | platform_device_unregister(exynos->usb3_phy); |
199 | 218 | ||
219 | clk_disable_unprepare(exynos->axius_clk); | ||
220 | clk_disable_unprepare(exynos->susp_clk); | ||
200 | clk_disable_unprepare(exynos->clk); | 221 | clk_disable_unprepare(exynos->clk); |
201 | 222 | ||
202 | regulator_disable(exynos->vdd33); | 223 | regulator_disable(exynos->vdd33); |
@@ -205,19 +226,19 @@ static int dwc3_exynos_remove(struct platform_device *pdev) | |||
205 | return 0; | 226 | return 0; |
206 | } | 227 | } |
207 | 228 | ||
208 | #ifdef CONFIG_OF | ||
209 | static const struct of_device_id exynos_dwc3_match[] = { | 229 | static const struct of_device_id exynos_dwc3_match[] = { |
210 | { .compatible = "samsung,exynos5250-dwusb3" }, | 230 | { .compatible = "samsung,exynos5250-dwusb3" }, |
231 | { .compatible = "samsung,exynos7-dwusb3" }, | ||
211 | {}, | 232 | {}, |
212 | }; | 233 | }; |
213 | MODULE_DEVICE_TABLE(of, exynos_dwc3_match); | 234 | MODULE_DEVICE_TABLE(of, exynos_dwc3_match); |
214 | #endif | ||
215 | 235 | ||
216 | #ifdef CONFIG_PM_SLEEP | 236 | #ifdef CONFIG_PM_SLEEP |
217 | static int dwc3_exynos_suspend(struct device *dev) | 237 | static int dwc3_exynos_suspend(struct device *dev) |
218 | { | 238 | { |
219 | struct dwc3_exynos *exynos = dev_get_drvdata(dev); | 239 | struct dwc3_exynos *exynos = dev_get_drvdata(dev); |
220 | 240 | ||
241 | clk_disable(exynos->axius_clk); | ||
221 | clk_disable(exynos->clk); | 242 | clk_disable(exynos->clk); |
222 | 243 | ||
223 | regulator_disable(exynos->vdd33); | 244 | regulator_disable(exynos->vdd33); |
@@ -243,6 +264,7 @@ static int dwc3_exynos_resume(struct device *dev) | |||
243 | } | 264 | } |
244 | 265 | ||
245 | clk_enable(exynos->clk); | 266 | clk_enable(exynos->clk); |
267 | clk_enable(exynos->axius_clk); | ||
246 | 268 | ||
247 | /* runtime set active to reflect active state. */ | 269 | /* runtime set active to reflect active state. */ |
248 | pm_runtime_disable(dev); | 270 | pm_runtime_disable(dev); |
@@ -266,7 +288,7 @@ static struct platform_driver dwc3_exynos_driver = { | |||
266 | .remove = dwc3_exynos_remove, | 288 | .remove = dwc3_exynos_remove, |
267 | .driver = { | 289 | .driver = { |
268 | .name = "exynos-dwc3", | 290 | .name = "exynos-dwc3", |
269 | .of_match_table = of_match_ptr(exynos_dwc3_match), | 291 | .of_match_table = exynos_dwc3_match, |
270 | .pm = DEV_PM_OPS, | 292 | .pm = DEV_PM_OPS, |
271 | }, | 293 | }, |
272 | }; | 294 | }; |
diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c index dd8d2df6db31..fe3b9335a74e 100644 --- a/drivers/usb/dwc3/dwc3-keystone.c +++ b/drivers/usb/dwc3/dwc3-keystone.c | |||
@@ -123,6 +123,7 @@ static int kdwc3_probe(struct platform_device *pdev) | |||
123 | irq = platform_get_irq(pdev, 0); | 123 | irq = platform_get_irq(pdev, 0); |
124 | if (irq < 0) { | 124 | if (irq < 0) { |
125 | dev_err(&pdev->dev, "missing irq\n"); | 125 | dev_err(&pdev->dev, "missing irq\n"); |
126 | error = irq; | ||
126 | goto err_irq; | 127 | goto err_irq; |
127 | } | 128 | } |
128 | 129 | ||
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c index a0aa9f3da441..172d64e585b6 100644 --- a/drivers/usb/dwc3/dwc3-omap.c +++ b/drivers/usb/dwc3/dwc3-omap.c | |||
@@ -593,27 +593,12 @@ static const struct of_device_id of_dwc3_match[] = { | |||
593 | MODULE_DEVICE_TABLE(of, of_dwc3_match); | 593 | MODULE_DEVICE_TABLE(of, of_dwc3_match); |
594 | 594 | ||
595 | #ifdef CONFIG_PM_SLEEP | 595 | #ifdef CONFIG_PM_SLEEP |
596 | static int dwc3_omap_prepare(struct device *dev) | ||
597 | { | ||
598 | struct dwc3_omap *omap = dev_get_drvdata(dev); | ||
599 | |||
600 | dwc3_omap_disable_irqs(omap); | ||
601 | |||
602 | return 0; | ||
603 | } | ||
604 | |||
605 | static void dwc3_omap_complete(struct device *dev) | ||
606 | { | ||
607 | struct dwc3_omap *omap = dev_get_drvdata(dev); | ||
608 | |||
609 | dwc3_omap_enable_irqs(omap); | ||
610 | } | ||
611 | |||
612 | static int dwc3_omap_suspend(struct device *dev) | 596 | static int dwc3_omap_suspend(struct device *dev) |
613 | { | 597 | { |
614 | struct dwc3_omap *omap = dev_get_drvdata(dev); | 598 | struct dwc3_omap *omap = dev_get_drvdata(dev); |
615 | 599 | ||
616 | omap->utmi_otg_status = dwc3_omap_read_utmi_status(omap); | 600 | omap->utmi_otg_status = dwc3_omap_read_utmi_status(omap); |
601 | dwc3_omap_disable_irqs(omap); | ||
617 | 602 | ||
618 | return 0; | 603 | return 0; |
619 | } | 604 | } |
@@ -623,6 +608,7 @@ static int dwc3_omap_resume(struct device *dev) | |||
623 | struct dwc3_omap *omap = dev_get_drvdata(dev); | 608 | struct dwc3_omap *omap = dev_get_drvdata(dev); |
624 | 609 | ||
625 | dwc3_omap_write_utmi_status(omap, omap->utmi_otg_status); | 610 | dwc3_omap_write_utmi_status(omap, omap->utmi_otg_status); |
611 | dwc3_omap_enable_irqs(omap); | ||
626 | 612 | ||
627 | pm_runtime_disable(dev); | 613 | pm_runtime_disable(dev); |
628 | pm_runtime_set_active(dev); | 614 | pm_runtime_set_active(dev); |
@@ -632,8 +618,6 @@ static int dwc3_omap_resume(struct device *dev) | |||
632 | } | 618 | } |
633 | 619 | ||
634 | static const struct dev_pm_ops dwc3_omap_dev_pm_ops = { | 620 | static const struct dev_pm_ops dwc3_omap_dev_pm_ops = { |
635 | .prepare = dwc3_omap_prepare, | ||
636 | .complete = dwc3_omap_complete, | ||
637 | 621 | ||
638 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume) | 622 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume) |
639 | }; | 623 | }; |
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index a36cf66302fb..7c4faf738747 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c | |||
@@ -25,6 +25,8 @@ | |||
25 | #include <linux/usb/otg.h> | 25 | #include <linux/usb/otg.h> |
26 | #include <linux/usb/usb_phy_generic.h> | 26 | #include <linux/usb/usb_phy_generic.h> |
27 | 27 | ||
28 | #include "platform_data.h" | ||
29 | |||
28 | /* FIXME define these in <linux/pci_ids.h> */ | 30 | /* FIXME define these in <linux/pci_ids.h> */ |
29 | #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 | 31 | #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 |
30 | #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd | 32 | #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd |
@@ -102,6 +104,9 @@ static int dwc3_pci_probe(struct pci_dev *pci, | |||
102 | struct dwc3_pci *glue; | 104 | struct dwc3_pci *glue; |
103 | int ret; | 105 | int ret; |
104 | struct device *dev = &pci->dev; | 106 | struct device *dev = &pci->dev; |
107 | struct dwc3_platform_data dwc3_pdata; | ||
108 | |||
109 | memset(&dwc3_pdata, 0x00, sizeof(dwc3_pdata)); | ||
105 | 110 | ||
106 | glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); | 111 | glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); |
107 | if (!glue) | 112 | if (!glue) |
@@ -140,6 +145,31 @@ static int dwc3_pci_probe(struct pci_dev *pci, | |||
140 | res[1].name = "dwc_usb3"; | 145 | res[1].name = "dwc_usb3"; |
141 | res[1].flags = IORESOURCE_IRQ; | 146 | res[1].flags = IORESOURCE_IRQ; |
142 | 147 | ||
148 | if (pci->vendor == PCI_VENDOR_ID_AMD && | ||
149 | pci->device == PCI_DEVICE_ID_AMD_NL_USB) { | ||
150 | dwc3_pdata.has_lpm_erratum = true; | ||
151 | dwc3_pdata.lpm_nyet_threshold = 0xf; | ||
152 | |||
153 | dwc3_pdata.u2exit_lfps_quirk = true; | ||
154 | dwc3_pdata.u2ss_inp3_quirk = true; | ||
155 | dwc3_pdata.req_p1p2p3_quirk = true; | ||
156 | dwc3_pdata.del_p1p2p3_quirk = true; | ||
157 | dwc3_pdata.del_phy_power_chg_quirk = true; | ||
158 | dwc3_pdata.lfps_filter_quirk = true; | ||
159 | dwc3_pdata.rx_detect_poll_quirk = true; | ||
160 | |||
161 | dwc3_pdata.tx_de_emphasis_quirk = true; | ||
162 | dwc3_pdata.tx_de_emphasis = 1; | ||
163 | |||
164 | /* | ||
165 | * FIXME these quirks should be removed when AMD NL | ||
166 | * taps out | ||
167 | */ | ||
168 | dwc3_pdata.disable_scramble_quirk = true; | ||
169 | dwc3_pdata.dis_u3_susphy_quirk = true; | ||
170 | dwc3_pdata.dis_u2_susphy_quirk = true; | ||
171 | } | ||
172 | |||
143 | ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res)); | 173 | ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res)); |
144 | if (ret) { | 174 | if (ret) { |
145 | dev_err(dev, "couldn't add resources to dwc3 device\n"); | 175 | dev_err(dev, "couldn't add resources to dwc3 device\n"); |
@@ -148,6 +178,10 @@ static int dwc3_pci_probe(struct pci_dev *pci, | |||
148 | 178 | ||
149 | pci_set_drvdata(pci, glue); | 179 | pci_set_drvdata(pci, glue); |
150 | 180 | ||
181 | ret = platform_device_add_data(dwc3, &dwc3_pdata, sizeof(dwc3_pdata)); | ||
182 | if (ret) | ||
183 | goto err3; | ||
184 | |||
151 | dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask); | 185 | dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask); |
152 | 186 | ||
153 | dwc3->dev.dma_mask = dev->dma_mask; | 187 | dwc3->dev.dma_mask = dev->dma_mask; |
@@ -185,6 +219,7 @@ static const struct pci_device_id dwc3_pci_id_table[] = { | |||
185 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), }, | 219 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), }, |
186 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), }, | 220 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), }, |
187 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), }, | 221 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), }, |
222 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), }, | ||
188 | { } /* Terminating Entry */ | 223 | { } /* Terminating Entry */ |
189 | }; | 224 | }; |
190 | MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); | 225 | MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); |
diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c index c7602b5362ad..4a1a543deeda 100644 --- a/drivers/usb/dwc3/dwc3-st.c +++ b/drivers/usb/dwc3/dwc3-st.c | |||
@@ -243,7 +243,7 @@ static int st_dwc3_probe(struct platform_device *pdev) | |||
243 | dwc3_data->rstc_rst = devm_reset_control_get(dev, "softreset"); | 243 | dwc3_data->rstc_rst = devm_reset_control_get(dev, "softreset"); |
244 | if (IS_ERR(dwc3_data->rstc_rst)) { | 244 | if (IS_ERR(dwc3_data->rstc_rst)) { |
245 | dev_err(&pdev->dev, "could not get reset controller\n"); | 245 | dev_err(&pdev->dev, "could not get reset controller\n"); |
246 | ret = PTR_ERR(dwc3_data->rstc_pwrdn); | 246 | ret = PTR_ERR(dwc3_data->rstc_rst); |
247 | goto undo_powerdown; | 247 | goto undo_powerdown; |
248 | } | 248 | } |
249 | 249 | ||
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 711b23019d54..baeedbd67f77 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c | |||
@@ -86,6 +86,8 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma, | |||
86 | params.param0 = upper_32_bits(dwc->ep0_trb_addr); | 86 | params.param0 = upper_32_bits(dwc->ep0_trb_addr); |
87 | params.param1 = lower_32_bits(dwc->ep0_trb_addr); | 87 | params.param1 = lower_32_bits(dwc->ep0_trb_addr); |
88 | 88 | ||
89 | trace_dwc3_prepare_trb(dep, trb); | ||
90 | |||
89 | ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, | 91 | ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, |
90 | DWC3_DEPCMD_STARTTRANSFER, ¶ms); | 92 | DWC3_DEPCMD_STARTTRANSFER, ¶ms); |
91 | if (ret < 0) { | 93 | if (ret < 0) { |
@@ -441,7 +443,6 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, | |||
441 | 443 | ||
442 | case USB_DEVICE_LTM_ENABLE: | 444 | case USB_DEVICE_LTM_ENABLE: |
443 | return -EINVAL; | 445 | return -EINVAL; |
444 | break; | ||
445 | 446 | ||
446 | case USB_DEVICE_TEST_MODE: | 447 | case USB_DEVICE_TEST_MODE: |
447 | if ((wIndex & 0xff) != 0) | 448 | if ((wIndex & 0xff) != 0) |
@@ -550,7 +551,6 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | |||
550 | switch (state) { | 551 | switch (state) { |
551 | case USB_STATE_DEFAULT: | 552 | case USB_STATE_DEFAULT: |
552 | return -EINVAL; | 553 | return -EINVAL; |
553 | break; | ||
554 | 554 | ||
555 | case USB_STATE_ADDRESS: | 555 | case USB_STATE_ADDRESS: |
556 | ret = dwc3_ep0_delegate_req(dwc, ctrl); | 556 | ret = dwc3_ep0_delegate_req(dwc, ctrl); |
@@ -700,35 +700,35 @@ static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | |||
700 | 700 | ||
701 | switch (ctrl->bRequest) { | 701 | switch (ctrl->bRequest) { |
702 | case USB_REQ_GET_STATUS: | 702 | case USB_REQ_GET_STATUS: |
703 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_GET_STATUS\n"); | 703 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_GET_STATUS"); |
704 | ret = dwc3_ep0_handle_status(dwc, ctrl); | 704 | ret = dwc3_ep0_handle_status(dwc, ctrl); |
705 | break; | 705 | break; |
706 | case USB_REQ_CLEAR_FEATURE: | 706 | case USB_REQ_CLEAR_FEATURE: |
707 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_CLEAR_FEATURE\n"); | 707 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_CLEAR_FEATURE"); |
708 | ret = dwc3_ep0_handle_feature(dwc, ctrl, 0); | 708 | ret = dwc3_ep0_handle_feature(dwc, ctrl, 0); |
709 | break; | 709 | break; |
710 | case USB_REQ_SET_FEATURE: | 710 | case USB_REQ_SET_FEATURE: |
711 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_FEATURE\n"); | 711 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_FEATURE"); |
712 | ret = dwc3_ep0_handle_feature(dwc, ctrl, 1); | 712 | ret = dwc3_ep0_handle_feature(dwc, ctrl, 1); |
713 | break; | 713 | break; |
714 | case USB_REQ_SET_ADDRESS: | 714 | case USB_REQ_SET_ADDRESS: |
715 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ADDRESS\n"); | 715 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ADDRESS"); |
716 | ret = dwc3_ep0_set_address(dwc, ctrl); | 716 | ret = dwc3_ep0_set_address(dwc, ctrl); |
717 | break; | 717 | break; |
718 | case USB_REQ_SET_CONFIGURATION: | 718 | case USB_REQ_SET_CONFIGURATION: |
719 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_CONFIGURATION\n"); | 719 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_CONFIGURATION"); |
720 | ret = dwc3_ep0_set_config(dwc, ctrl); | 720 | ret = dwc3_ep0_set_config(dwc, ctrl); |
721 | break; | 721 | break; |
722 | case USB_REQ_SET_SEL: | 722 | case USB_REQ_SET_SEL: |
723 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_SEL\n"); | 723 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_SEL"); |
724 | ret = dwc3_ep0_set_sel(dwc, ctrl); | 724 | ret = dwc3_ep0_set_sel(dwc, ctrl); |
725 | break; | 725 | break; |
726 | case USB_REQ_SET_ISOCH_DELAY: | 726 | case USB_REQ_SET_ISOCH_DELAY: |
727 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ISOCH_DELAY\n"); | 727 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ISOCH_DELAY"); |
728 | ret = dwc3_ep0_set_isoch_delay(dwc, ctrl); | 728 | ret = dwc3_ep0_set_isoch_delay(dwc, ctrl); |
729 | break; | 729 | break; |
730 | default: | 730 | default: |
731 | dwc3_trace(trace_dwc3_ep0, "Forwarding to gadget driver\n"); | 731 | dwc3_trace(trace_dwc3_ep0, "Forwarding to gadget driver"); |
732 | ret = dwc3_ep0_delegate_req(dwc, ctrl); | 732 | ret = dwc3_ep0_delegate_req(dwc, ctrl); |
733 | break; | 733 | break; |
734 | } | 734 | } |
@@ -791,6 +791,8 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc, | |||
791 | 791 | ||
792 | trb = dwc->ep0_trb; | 792 | trb = dwc->ep0_trb; |
793 | 793 | ||
794 | trace_dwc3_complete_trb(ep0, trb); | ||
795 | |||
794 | status = DWC3_TRB_SIZE_TRBSTS(trb->size); | 796 | status = DWC3_TRB_SIZE_TRBSTS(trb->size); |
795 | if (status == DWC3_TRBSTS_SETUP_PENDING) { | 797 | if (status == DWC3_TRBSTS_SETUP_PENDING) { |
796 | dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); | 798 | dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); |
@@ -855,6 +857,8 @@ static void dwc3_ep0_complete_status(struct dwc3 *dwc, | |||
855 | dep = dwc->eps[0]; | 857 | dep = dwc->eps[0]; |
856 | trb = dwc->ep0_trb; | 858 | trb = dwc->ep0_trb; |
857 | 859 | ||
860 | trace_dwc3_complete_trb(dep, trb); | ||
861 | |||
858 | if (!list_empty(&dep->request_list)) { | 862 | if (!list_empty(&dep->request_list)) { |
859 | r = next_request(&dep->request_list); | 863 | r = next_request(&dep->request_list); |
860 | 864 | ||
@@ -875,7 +879,7 @@ static void dwc3_ep0_complete_status(struct dwc3 *dwc, | |||
875 | 879 | ||
876 | status = DWC3_TRB_SIZE_TRBSTS(trb->size); | 880 | status = DWC3_TRB_SIZE_TRBSTS(trb->size); |
877 | if (status == DWC3_TRBSTS_SETUP_PENDING) | 881 | if (status == DWC3_TRBSTS_SETUP_PENDING) |
878 | dwc3_trace(trace_dwc3_ep0, "Setup Pending received\n"); | 882 | dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); |
879 | 883 | ||
880 | dwc->ep0state = EP0_SETUP_PHASE; | 884 | dwc->ep0state = EP0_SETUP_PHASE; |
881 | dwc3_ep0_out_start(dwc); | 885 | dwc3_ep0_out_start(dwc); |
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 546ea5431b8c..f03b136ecfce 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c | |||
@@ -1140,8 +1140,14 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, | |||
1140 | if (!dep->endpoint.desc) { | 1140 | if (!dep->endpoint.desc) { |
1141 | dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n", | 1141 | dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n", |
1142 | request, ep->name); | 1142 | request, ep->name); |
1143 | spin_unlock_irqrestore(&dwc->lock, flags); | 1143 | ret = -ESHUTDOWN; |
1144 | return -ESHUTDOWN; | 1144 | goto out; |
1145 | } | ||
1146 | |||
1147 | if (WARN(req->dep != dep, "request %p belongs to '%s'\n", | ||
1148 | request, req->dep->name)) { | ||
1149 | ret = -EINVAL; | ||
1150 | goto out; | ||
1145 | } | 1151 | } |
1146 | 1152 | ||
1147 | dev_vdbg(dwc->dev, "queing request %p to %s length %d\n", | 1153 | dev_vdbg(dwc->dev, "queing request %p to %s length %d\n", |
@@ -1149,6 +1155,8 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, | |||
1149 | trace_dwc3_ep_queue(req); | 1155 | trace_dwc3_ep_queue(req); |
1150 | 1156 | ||
1151 | ret = __dwc3_gadget_ep_queue(dep, req); | 1157 | ret = __dwc3_gadget_ep_queue(dep, req); |
1158 | |||
1159 | out: | ||
1152 | spin_unlock_irqrestore(&dwc->lock, flags); | 1160 | spin_unlock_irqrestore(&dwc->lock, flags); |
1153 | 1161 | ||
1154 | return ret; | 1162 | return ret; |
@@ -1622,8 +1630,7 @@ err0: | |||
1622 | return ret; | 1630 | return ret; |
1623 | } | 1631 | } |
1624 | 1632 | ||
1625 | static int dwc3_gadget_stop(struct usb_gadget *g, | 1633 | static int dwc3_gadget_stop(struct usb_gadget *g) |
1626 | struct usb_gadget_driver *driver) | ||
1627 | { | 1634 | { |
1628 | struct dwc3 *dwc = gadget_to_dwc(g); | 1635 | struct dwc3 *dwc = gadget_to_dwc(g); |
1629 | unsigned long flags; | 1636 | unsigned long flags; |
@@ -2034,6 +2041,17 @@ static void dwc3_resume_gadget(struct dwc3 *dwc) | |||
2034 | if (dwc->gadget_driver && dwc->gadget_driver->resume) { | 2041 | if (dwc->gadget_driver && dwc->gadget_driver->resume) { |
2035 | spin_unlock(&dwc->lock); | 2042 | spin_unlock(&dwc->lock); |
2036 | dwc->gadget_driver->resume(&dwc->gadget); | 2043 | dwc->gadget_driver->resume(&dwc->gadget); |
2044 | } | ||
2045 | } | ||
2046 | |||
2047 | static void dwc3_reset_gadget(struct dwc3 *dwc) | ||
2048 | { | ||
2049 | if (!dwc->gadget_driver) | ||
2050 | return; | ||
2051 | |||
2052 | if (dwc->gadget.speed != USB_SPEED_UNKNOWN) { | ||
2053 | spin_unlock(&dwc->lock); | ||
2054 | usb_gadget_udc_reset(&dwc->gadget, dwc->gadget_driver); | ||
2037 | spin_lock(&dwc->lock); | 2055 | spin_lock(&dwc->lock); |
2038 | } | 2056 | } |
2039 | } | 2057 | } |
@@ -2140,6 +2158,7 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) | |||
2140 | 2158 | ||
2141 | dwc->gadget.speed = USB_SPEED_UNKNOWN; | 2159 | dwc->gadget.speed = USB_SPEED_UNKNOWN; |
2142 | dwc->setup_packet_pending = false; | 2160 | dwc->setup_packet_pending = false; |
2161 | usb_gadget_set_state(&dwc->gadget, USB_STATE_NOTATTACHED); | ||
2143 | } | 2162 | } |
2144 | 2163 | ||
2145 | static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) | 2164 | static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) |
@@ -2177,11 +2196,7 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) | |||
2177 | dwc3_gadget_disconnect_interrupt(dwc); | 2196 | dwc3_gadget_disconnect_interrupt(dwc); |
2178 | } | 2197 | } |
2179 | 2198 | ||
2180 | /* after reset -> Default State */ | 2199 | dwc3_reset_gadget(dwc); |
2181 | usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); | ||
2182 | |||
2183 | if (dwc->gadget.speed != USB_SPEED_UNKNOWN) | ||
2184 | dwc3_disconnect_gadget(dwc); | ||
2185 | 2200 | ||
2186 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); | 2201 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
2187 | reg &= ~DWC3_DCTL_TSTCTRL_MASK; | 2202 | reg &= ~DWC3_DCTL_TSTCTRL_MASK; |
@@ -2287,11 +2302,20 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) | |||
2287 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); | 2302 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
2288 | reg &= ~(DWC3_DCTL_HIRD_THRES_MASK | DWC3_DCTL_L1_HIBER_EN); | 2303 | reg &= ~(DWC3_DCTL_HIRD_THRES_MASK | DWC3_DCTL_L1_HIBER_EN); |
2289 | 2304 | ||
2305 | reg |= DWC3_DCTL_HIRD_THRES(dwc->hird_threshold); | ||
2306 | |||
2290 | /* | 2307 | /* |
2291 | * TODO: This should be configurable. For now using | 2308 | * When dwc3 revisions >= 2.40a, LPM Erratum is enabled and |
2292 | * maximum allowed HIRD threshold value of 0b1100 | 2309 | * DCFG.LPMCap is set, core responses with an ACK and the |
2310 | * BESL value in the LPM token is less than or equal to LPM | ||
2311 | * NYET threshold. | ||
2293 | */ | 2312 | */ |
2294 | reg |= DWC3_DCTL_HIRD_THRES(12); | 2313 | WARN_ONCE(dwc->revision < DWC3_REVISION_240A |
2314 | && dwc->has_lpm_erratum, | ||
2315 | "LPM Erratum not available on dwc3 revisisions < 2.40a\n"); | ||
2316 | |||
2317 | if (dwc->has_lpm_erratum && dwc->revision >= DWC3_REVISION_240A) | ||
2318 | reg |= DWC3_DCTL_LPM_ERRATA(dwc->lpm_nyet_threshold); | ||
2295 | 2319 | ||
2296 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); | 2320 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); |
2297 | } else { | 2321 | } else { |
@@ -2744,26 +2768,13 @@ void dwc3_gadget_exit(struct dwc3 *dwc) | |||
2744 | dwc->ctrl_req, dwc->ctrl_req_addr); | 2768 | dwc->ctrl_req, dwc->ctrl_req_addr); |
2745 | } | 2769 | } |
2746 | 2770 | ||
2747 | int dwc3_gadget_prepare(struct dwc3 *dwc) | 2771 | int dwc3_gadget_suspend(struct dwc3 *dwc) |
2748 | { | 2772 | { |
2749 | if (dwc->pullups_connected) { | 2773 | if (dwc->pullups_connected) { |
2750 | dwc3_gadget_disable_irq(dwc); | 2774 | dwc3_gadget_disable_irq(dwc); |
2751 | dwc3_gadget_run_stop(dwc, true, true); | 2775 | dwc3_gadget_run_stop(dwc, true, true); |
2752 | } | 2776 | } |
2753 | 2777 | ||
2754 | return 0; | ||
2755 | } | ||
2756 | |||
2757 | void dwc3_gadget_complete(struct dwc3 *dwc) | ||
2758 | { | ||
2759 | if (dwc->pullups_connected) { | ||
2760 | dwc3_gadget_enable_irq(dwc); | ||
2761 | dwc3_gadget_run_stop(dwc, true, false); | ||
2762 | } | ||
2763 | } | ||
2764 | |||
2765 | int dwc3_gadget_suspend(struct dwc3 *dwc) | ||
2766 | { | ||
2767 | __dwc3_gadget_ep_disable(dwc->eps[0]); | 2778 | __dwc3_gadget_ep_disable(dwc->eps[0]); |
2768 | __dwc3_gadget_ep_disable(dwc->eps[1]); | 2779 | __dwc3_gadget_ep_disable(dwc->eps[1]); |
2769 | 2780 | ||
@@ -2798,6 +2809,11 @@ int dwc3_gadget_resume(struct dwc3 *dwc) | |||
2798 | 2809 | ||
2799 | dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg); | 2810 | dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg); |
2800 | 2811 | ||
2812 | if (dwc->pullups_connected) { | ||
2813 | dwc3_gadget_enable_irq(dwc); | ||
2814 | dwc3_gadget_run_stop(dwc, true, false); | ||
2815 | } | ||
2816 | |||
2801 | return 0; | 2817 | return 0; |
2802 | 2818 | ||
2803 | err1: | 2819 | err1: |
diff --git a/drivers/usb/dwc3/platform_data.h b/drivers/usb/dwc3/platform_data.h index 7db34f00b89a..a3a3b6d5668c 100644 --- a/drivers/usb/dwc3/platform_data.h +++ b/drivers/usb/dwc3/platform_data.h | |||
@@ -24,4 +24,24 @@ struct dwc3_platform_data { | |||
24 | enum usb_device_speed maximum_speed; | 24 | enum usb_device_speed maximum_speed; |
25 | enum usb_dr_mode dr_mode; | 25 | enum usb_dr_mode dr_mode; |
26 | bool tx_fifo_resize; | 26 | bool tx_fifo_resize; |
27 | |||
28 | unsigned is_utmi_l1_suspend:1; | ||
29 | u8 hird_threshold; | ||
30 | |||
31 | u8 lpm_nyet_threshold; | ||
32 | |||
33 | unsigned disable_scramble_quirk:1; | ||
34 | unsigned has_lpm_erratum:1; | ||
35 | unsigned u2exit_lfps_quirk:1; | ||
36 | unsigned u2ss_inp3_quirk:1; | ||
37 | unsigned req_p1p2p3_quirk:1; | ||
38 | unsigned del_p1p2p3_quirk:1; | ||
39 | unsigned del_phy_power_chg_quirk:1; | ||
40 | unsigned lfps_filter_quirk:1; | ||
41 | unsigned rx_detect_poll_quirk:1; | ||
42 | unsigned dis_u3_susphy_quirk:1; | ||
43 | unsigned dis_u2_susphy_quirk:1; | ||
44 | |||
45 | unsigned tx_de_emphasis_quirk:1; | ||
46 | unsigned tx_de_emphasis:2; | ||
27 | }; | 47 | }; |
diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h index 60b0f41eafc4..9fc20b33dd8e 100644 --- a/drivers/usb/dwc3/trace.h +++ b/drivers/usb/dwc3/trace.h | |||
@@ -61,7 +61,7 @@ DECLARE_EVENT_CLASS(dwc3_log_event, | |||
61 | TP_fast_assign( | 61 | TP_fast_assign( |
62 | __entry->event = event; | 62 | __entry->event = event; |
63 | ), | 63 | ), |
64 | TP_printk("event %08x\n", __entry->event) | 64 | TP_printk("event %08x", __entry->event) |
65 | ); | 65 | ); |
66 | 66 | ||
67 | DEFINE_EVENT(dwc3_log_event, dwc3_event, | 67 | DEFINE_EVENT(dwc3_log_event, dwc3_event, |
@@ -157,7 +157,7 @@ DECLARE_EVENT_CLASS(dwc3_log_generic_cmd, | |||
157 | __entry->cmd = cmd; | 157 | __entry->cmd = cmd; |
158 | __entry->param = param; | 158 | __entry->param = param; |
159 | ), | 159 | ), |
160 | TP_printk("cmd '%s' [%d] param %08x\n", | 160 | TP_printk("cmd '%s' [%d] param %08x", |
161 | dwc3_gadget_generic_cmd_string(__entry->cmd), | 161 | dwc3_gadget_generic_cmd_string(__entry->cmd), |
162 | __entry->cmd, __entry->param | 162 | __entry->cmd, __entry->param |
163 | ) | 163 | ) |
@@ -175,17 +175,21 @@ DECLARE_EVENT_CLASS(dwc3_log_gadget_ep_cmd, | |||
175 | TP_STRUCT__entry( | 175 | TP_STRUCT__entry( |
176 | __dynamic_array(char, name, DWC3_MSG_MAX) | 176 | __dynamic_array(char, name, DWC3_MSG_MAX) |
177 | __field(unsigned int, cmd) | 177 | __field(unsigned int, cmd) |
178 | __field(struct dwc3_gadget_ep_cmd_params *, params) | 178 | __field(u32, param0) |
179 | __field(u32, param1) | ||
180 | __field(u32, param2) | ||
179 | ), | 181 | ), |
180 | TP_fast_assign( | 182 | TP_fast_assign( |
181 | snprintf(__get_str(name), DWC3_MSG_MAX, "%s", dep->name); | 183 | snprintf(__get_str(name), DWC3_MSG_MAX, "%s", dep->name); |
182 | __entry->cmd = cmd; | 184 | __entry->cmd = cmd; |
183 | __entry->params = params; | 185 | __entry->param0 = params->param0; |
186 | __entry->param1 = params->param1; | ||
187 | __entry->param2 = params->param2; | ||
184 | ), | 188 | ), |
185 | TP_printk("%s: cmd '%s' [%d] params %08x %08x %08x\n", | 189 | TP_printk("%s: cmd '%s' [%d] params %08x %08x %08x", |
186 | __get_str(name), dwc3_gadget_ep_cmd_string(__entry->cmd), | 190 | __get_str(name), dwc3_gadget_ep_cmd_string(__entry->cmd), |
187 | __entry->cmd, __entry->params->param0, | 191 | __entry->cmd, __entry->param0, |
188 | __entry->params->param1, __entry->params->param2 | 192 | __entry->param1, __entry->param2 |
189 | ) | 193 | ) |
190 | ); | 194 | ); |
191 | 195 | ||
@@ -214,7 +218,7 @@ DECLARE_EVENT_CLASS(dwc3_log_trb, | |||
214 | __entry->size = trb->size; | 218 | __entry->size = trb->size; |
215 | __entry->ctrl = trb->ctrl; | 219 | __entry->ctrl = trb->ctrl; |
216 | ), | 220 | ), |
217 | TP_printk("%s: trb %p bph %08x bpl %08x size %08x ctrl %08x\n", | 221 | TP_printk("%s: trb %p bph %08x bpl %08x size %08x ctrl %08x", |
218 | __get_str(name), __entry->trb, __entry->bph, __entry->bpl, | 222 | __get_str(name), __entry->trb, __entry->bph, __entry->bpl, |
219 | __entry->size, __entry->ctrl | 223 | __entry->size, __entry->ctrl |
220 | ) | 224 | ) |
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index c4880fc0d86e..747ef53bda14 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -190,6 +190,12 @@ config USB_F_UAC2 | |||
190 | config USB_F_UVC | 190 | config USB_F_UVC |
191 | tristate | 191 | tristate |
192 | 192 | ||
193 | config USB_F_MIDI | ||
194 | tristate | ||
195 | |||
196 | config USB_F_HID | ||
197 | tristate | ||
198 | |||
193 | choice | 199 | choice |
194 | tristate "USB Gadget Drivers" | 200 | tristate "USB Gadget Drivers" |
195 | default USB_ETH | 201 | default USB_ETH |
@@ -362,6 +368,61 @@ config USB_CONFIGFS_F_FS | |||
362 | implemented in kernel space (for instance Ethernet, serial or | 368 | implemented in kernel space (for instance Ethernet, serial or |
363 | mass storage) and other are implemented in user space. | 369 | mass storage) and other are implemented in user space. |
364 | 370 | ||
371 | config USB_CONFIGFS_F_UAC1 | ||
372 | boolean "Audio Class 1.0" | ||
373 | depends on USB_CONFIGFS | ||
374 | depends on SND | ||
375 | select USB_LIBCOMPOSITE | ||
376 | select SND_PCM | ||
377 | select USB_F_UAC1 | ||
378 | help | ||
379 | This Audio function implements 1 AudioControl interface, | ||
380 | 1 AudioStreaming Interface each for USB-OUT and USB-IN. | ||
381 | This driver requires a real Audio codec to be present | ||
382 | on the device. | ||
383 | |||
384 | config USB_CONFIGFS_F_UAC2 | ||
385 | boolean "Audio Class 2.0" | ||
386 | depends on USB_CONFIGFS | ||
387 | depends on SND | ||
388 | select USB_LIBCOMPOSITE | ||
389 | select SND_PCM | ||
390 | select USB_F_UAC2 | ||
391 | help | ||
392 | This Audio function is compatible with USB Audio Class | ||
393 | specification 2.0. It implements 1 AudioControl interface, | ||
394 | 1 AudioStreaming Interface each for USB-OUT and USB-IN. | ||
395 | This driver doesn't expect any real Audio codec to be present | ||
396 | on the device - the audio streams are simply sinked to and | ||
397 | sourced from a virtual ALSA sound card created. The user-space | ||
398 | application may choose to do whatever it wants with the data | ||
399 | received from the USB Host and choose to provide whatever it | ||
400 | wants as audio data to the USB Host. | ||
401 | |||
402 | config USB_CONFIGFS_F_MIDI | ||
403 | boolean "MIDI function" | ||
404 | depends on USB_CONFIGFS | ||
405 | depends on SND | ||
406 | select USB_LIBCOMPOSITE | ||
407 | select SND_RAWMIDI | ||
408 | select USB_F_MIDI | ||
409 | help | ||
410 | The MIDI Function acts as a USB Audio device, with one MIDI | ||
411 | input and one MIDI output. These MIDI jacks appear as | ||
412 | a sound "card" in the ALSA sound system. Other MIDI | ||
413 | connections can then be made on the gadget system, using | ||
414 | ALSA's aconnect utility etc. | ||
415 | |||
416 | config USB_CONFIGFS_F_HID | ||
417 | boolean "HID function" | ||
418 | depends on USB_CONFIGFS | ||
419 | select USB_F_HID | ||
420 | help | ||
421 | The HID function driver provides generic emulation of USB | ||
422 | Human Interface Devices (HID). | ||
423 | |||
424 | For more information, see Documentation/usb/gadget_hid.txt. | ||
425 | |||
365 | source "drivers/usb/gadget/legacy/Kconfig" | 426 | source "drivers/usb/gadget/legacy/Kconfig" |
366 | 427 | ||
367 | endchoice | 428 | endchoice |
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index f6a51fddd5b5..617835348569 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -1246,10 +1246,49 @@ EXPORT_SYMBOL_GPL(usb_string_ids_n); | |||
1246 | 1246 | ||
1247 | static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req) | 1247 | static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req) |
1248 | { | 1248 | { |
1249 | struct usb_composite_dev *cdev; | ||
1250 | |||
1249 | if (req->status || req->actual != req->length) | 1251 | if (req->status || req->actual != req->length) |
1250 | DBG((struct usb_composite_dev *) ep->driver_data, | 1252 | DBG((struct usb_composite_dev *) ep->driver_data, |
1251 | "setup complete --> %d, %d/%d\n", | 1253 | "setup complete --> %d, %d/%d\n", |
1252 | req->status, req->actual, req->length); | 1254 | req->status, req->actual, req->length); |
1255 | |||
1256 | /* | ||
1257 | * REVIST The same ep0 requests are shared with function drivers | ||
1258 | * so they don't have to maintain the same ->complete() stubs. | ||
1259 | * | ||
1260 | * Because of that, we need to check for the validity of ->context | ||
1261 | * here, even though we know we've set it to something useful. | ||
1262 | */ | ||
1263 | if (!req->context) | ||
1264 | return; | ||
1265 | |||
1266 | cdev = req->context; | ||
1267 | |||
1268 | if (cdev->req == req) | ||
1269 | cdev->setup_pending = false; | ||
1270 | else if (cdev->os_desc_req == req) | ||
1271 | cdev->os_desc_pending = false; | ||
1272 | else | ||
1273 | WARN(1, "unknown request %p\n", req); | ||
1274 | } | ||
1275 | |||
1276 | static int composite_ep0_queue(struct usb_composite_dev *cdev, | ||
1277 | struct usb_request *req, gfp_t gfp_flags) | ||
1278 | { | ||
1279 | int ret; | ||
1280 | |||
1281 | ret = usb_ep_queue(cdev->gadget->ep0, req, gfp_flags); | ||
1282 | if (ret == 0) { | ||
1283 | if (cdev->req == req) | ||
1284 | cdev->setup_pending = true; | ||
1285 | else if (cdev->os_desc_req == req) | ||
1286 | cdev->os_desc_pending = true; | ||
1287 | else | ||
1288 | WARN(1, "unknown request %p\n", req); | ||
1289 | } | ||
1290 | |||
1291 | return ret; | ||
1253 | } | 1292 | } |
1254 | 1293 | ||
1255 | static int count_ext_compat(struct usb_configuration *c) | 1294 | static int count_ext_compat(struct usb_configuration *c) |
@@ -1428,6 +1467,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1428 | * when we delegate to it. | 1467 | * when we delegate to it. |
1429 | */ | 1468 | */ |
1430 | req->zero = 0; | 1469 | req->zero = 0; |
1470 | req->context = cdev; | ||
1431 | req->complete = composite_setup_complete; | 1471 | req->complete = composite_setup_complete; |
1432 | req->length = 0; | 1472 | req->length = 0; |
1433 | gadget->ep0->driver_data = cdev; | 1473 | gadget->ep0->driver_data = cdev; |
@@ -1624,6 +1664,7 @@ unknown: | |||
1624 | int count = 0; | 1664 | int count = 0; |
1625 | 1665 | ||
1626 | req = cdev->os_desc_req; | 1666 | req = cdev->os_desc_req; |
1667 | req->context = cdev; | ||
1627 | req->complete = composite_setup_complete; | 1668 | req->complete = composite_setup_complete; |
1628 | buf = req->buf; | 1669 | buf = req->buf; |
1629 | os_desc_cfg = cdev->os_desc_config; | 1670 | os_desc_cfg = cdev->os_desc_config; |
@@ -1686,8 +1727,9 @@ unknown: | |||
1686 | break; | 1727 | break; |
1687 | } | 1728 | } |
1688 | req->length = value; | 1729 | req->length = value; |
1730 | req->context = cdev; | ||
1689 | req->zero = value < w_length; | 1731 | req->zero = value < w_length; |
1690 | value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); | 1732 | value = composite_ep0_queue(cdev, req, GFP_ATOMIC); |
1691 | if (value < 0) { | 1733 | if (value < 0) { |
1692 | DBG(cdev, "ep_queue --> %d\n", value); | 1734 | DBG(cdev, "ep_queue --> %d\n", value); |
1693 | req->status = 0; | 1735 | req->status = 0; |
@@ -1757,8 +1799,9 @@ unknown: | |||
1757 | /* respond with data transfer before status phase? */ | 1799 | /* respond with data transfer before status phase? */ |
1758 | if (value >= 0 && value != USB_GADGET_DELAYED_STATUS) { | 1800 | if (value >= 0 && value != USB_GADGET_DELAYED_STATUS) { |
1759 | req->length = value; | 1801 | req->length = value; |
1802 | req->context = cdev; | ||
1760 | req->zero = value < w_length; | 1803 | req->zero = value < w_length; |
1761 | value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); | 1804 | value = composite_ep0_queue(cdev, req, GFP_ATOMIC); |
1762 | if (value < 0) { | 1805 | if (value < 0) { |
1763 | DBG(cdev, "ep_queue --> %d\n", value); | 1806 | DBG(cdev, "ep_queue --> %d\n", value); |
1764 | req->status = 0; | 1807 | req->status = 0; |
@@ -1893,6 +1936,7 @@ int composite_dev_prepare(struct usb_composite_driver *composite, | |||
1893 | goto fail_dev; | 1936 | goto fail_dev; |
1894 | 1937 | ||
1895 | cdev->req->complete = composite_setup_complete; | 1938 | cdev->req->complete = composite_setup_complete; |
1939 | cdev->req->context = cdev; | ||
1896 | gadget->ep0->driver_data = cdev; | 1940 | gadget->ep0->driver_data = cdev; |
1897 | 1941 | ||
1898 | cdev->driver = composite; | 1942 | cdev->driver = composite; |
@@ -1937,6 +1981,7 @@ int composite_os_desc_req_prepare(struct usb_composite_dev *cdev, | |||
1937 | kfree(cdev->os_desc_req); | 1981 | kfree(cdev->os_desc_req); |
1938 | goto end; | 1982 | goto end; |
1939 | } | 1983 | } |
1984 | cdev->os_desc_req->context = cdev; | ||
1940 | cdev->os_desc_req->complete = composite_setup_complete; | 1985 | cdev->os_desc_req->complete = composite_setup_complete; |
1941 | end: | 1986 | end: |
1942 | return ret; | 1987 | return ret; |
@@ -1951,10 +1996,16 @@ void composite_dev_cleanup(struct usb_composite_dev *cdev) | |||
1951 | kfree(uc); | 1996 | kfree(uc); |
1952 | } | 1997 | } |
1953 | if (cdev->os_desc_req) { | 1998 | if (cdev->os_desc_req) { |
1999 | if (cdev->os_desc_pending) | ||
2000 | usb_ep_dequeue(cdev->gadget->ep0, cdev->os_desc_req); | ||
2001 | |||
1954 | kfree(cdev->os_desc_req->buf); | 2002 | kfree(cdev->os_desc_req->buf); |
1955 | usb_ep_free_request(cdev->gadget->ep0, cdev->os_desc_req); | 2003 | usb_ep_free_request(cdev->gadget->ep0, cdev->os_desc_req); |
1956 | } | 2004 | } |
1957 | if (cdev->req) { | 2005 | if (cdev->req) { |
2006 | if (cdev->setup_pending) | ||
2007 | usb_ep_dequeue(cdev->gadget->ep0, cdev->req); | ||
2008 | |||
1958 | kfree(cdev->req->buf); | 2009 | kfree(cdev->req->buf); |
1959 | usb_ep_free_request(cdev->gadget->ep0, cdev->req); | 2010 | usb_ep_free_request(cdev->gadget->ep0, cdev->req); |
1960 | } | 2011 | } |
@@ -2013,8 +2064,7 @@ fail: | |||
2013 | 2064 | ||
2014 | /*-------------------------------------------------------------------------*/ | 2065 | /*-------------------------------------------------------------------------*/ |
2015 | 2066 | ||
2016 | static void | 2067 | void composite_suspend(struct usb_gadget *gadget) |
2017 | composite_suspend(struct usb_gadget *gadget) | ||
2018 | { | 2068 | { |
2019 | struct usb_composite_dev *cdev = get_gadget_data(gadget); | 2069 | struct usb_composite_dev *cdev = get_gadget_data(gadget); |
2020 | struct usb_function *f; | 2070 | struct usb_function *f; |
@@ -2037,8 +2087,7 @@ composite_suspend(struct usb_gadget *gadget) | |||
2037 | usb_gadget_vbus_draw(gadget, 2); | 2087 | usb_gadget_vbus_draw(gadget, 2); |
2038 | } | 2088 | } |
2039 | 2089 | ||
2040 | static void | 2090 | void composite_resume(struct usb_gadget *gadget) |
2041 | composite_resume(struct usb_gadget *gadget) | ||
2042 | { | 2091 | { |
2043 | struct usb_composite_dev *cdev = get_gadget_data(gadget); | 2092 | struct usb_composite_dev *cdev = get_gadget_data(gadget); |
2044 | struct usb_function *f; | 2093 | struct usb_function *f; |
@@ -2158,7 +2207,8 @@ void usb_composite_setup_continue(struct usb_composite_dev *cdev) | |||
2158 | } else if (--cdev->delayed_status == 0) { | 2207 | } else if (--cdev->delayed_status == 0) { |
2159 | DBG(cdev, "%s: Completing delayed status\n", __func__); | 2208 | DBG(cdev, "%s: Completing delayed status\n", __func__); |
2160 | req->length = 0; | 2209 | req->length = 0; |
2161 | value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); | 2210 | req->context = cdev; |
2211 | value = composite_ep0_queue(cdev, req, GFP_ATOMIC); | ||
2162 | if (value < 0) { | 2212 | if (value < 0) { |
2163 | DBG(cdev, "ep_queue --> %d\n", value); | 2213 | DBG(cdev, "ep_queue --> %d\n", value); |
2164 | req->status = 0; | 2214 | req->status = 0; |
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 34034333f7f6..75648145dc1b 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c | |||
@@ -271,7 +271,7 @@ static ssize_t gadget_dev_desc_UDC_store(struct gadget_info *gi, | |||
271 | ret = -EBUSY; | 271 | ret = -EBUSY; |
272 | goto err; | 272 | goto err; |
273 | } | 273 | } |
274 | ret = udc_attach_driver(name, &gi->composite.gadget_driver); | 274 | ret = usb_udc_attach_driver(name, &gi->composite.gadget_driver); |
275 | if (ret) | 275 | if (ret) |
276 | goto err; | 276 | goto err; |
277 | gi->udc_name = name; | 277 | gi->udc_name = name; |
@@ -1453,6 +1453,9 @@ static const struct usb_gadget_driver configfs_driver_template = { | |||
1453 | .reset = composite_disconnect, | 1453 | .reset = composite_disconnect, |
1454 | .disconnect = composite_disconnect, | 1454 | .disconnect = composite_disconnect, |
1455 | 1455 | ||
1456 | .suspend = composite_suspend, | ||
1457 | .resume = composite_resume, | ||
1458 | |||
1456 | .max_speed = USB_SPEED_SUPER, | 1459 | .max_speed = USB_SPEED_SUPER, |
1457 | .driver = { | 1460 | .driver = { |
1458 | .owner = THIS_MODULE, | 1461 | .owner = THIS_MODULE, |
diff --git a/drivers/usb/gadget/function/Makefile b/drivers/usb/gadget/function/Makefile index 90701aa5a826..dd68091d92f0 100644 --- a/drivers/usb/gadget/function/Makefile +++ b/drivers/usb/gadget/function/Makefile | |||
@@ -38,3 +38,7 @@ usb_f_uac2-y := f_uac2.o | |||
38 | obj-$(CONFIG_USB_F_UAC2) += usb_f_uac2.o | 38 | obj-$(CONFIG_USB_F_UAC2) += usb_f_uac2.o |
39 | usb_f_uvc-y := f_uvc.o uvc_queue.o uvc_v4l2.o uvc_video.o | 39 | usb_f_uvc-y := f_uvc.o uvc_queue.o uvc_v4l2.o uvc_video.o |
40 | obj-$(CONFIG_USB_F_UVC) += usb_f_uvc.o | 40 | obj-$(CONFIG_USB_F_UVC) += usb_f_uvc.o |
41 | usb_f_midi-y := f_midi.o | ||
42 | obj-$(CONFIG_USB_F_MIDI) += usb_f_midi.o | ||
43 | usb_f_hid-y := f_hid.o | ||
44 | obj-$(CONFIG_USB_F_HID) += usb_f_hid.o | ||
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c index 59ab62c92b66..488ac66aae9e 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/hid.h> | 14 | #include <linux/hid.h> |
15 | #include <linux/idr.h> | ||
15 | #include <linux/cdev.h> | 16 | #include <linux/cdev.h> |
16 | #include <linux/mutex.h> | 17 | #include <linux/mutex.h> |
17 | #include <linux/poll.h> | 18 | #include <linux/poll.h> |
@@ -21,9 +22,14 @@ | |||
21 | #include <linux/usb/g_hid.h> | 22 | #include <linux/usb/g_hid.h> |
22 | 23 | ||
23 | #include "u_f.h" | 24 | #include "u_f.h" |
25 | #include "u_hid.h" | ||
26 | |||
27 | #define HIDG_MINORS 4 | ||
24 | 28 | ||
25 | static int major, minors; | 29 | static int major, minors; |
26 | static struct class *hidg_class; | 30 | static struct class *hidg_class; |
31 | static DEFINE_IDA(hidg_ida); | ||
32 | static DEFINE_MUTEX(hidg_ida_lock); /* protects access to hidg_ida */ | ||
27 | 33 | ||
28 | /*-------------------------------------------------------------------------*/ | 34 | /*-------------------------------------------------------------------------*/ |
29 | /* HID gadget struct */ | 35 | /* HID gadget struct */ |
@@ -161,6 +167,26 @@ static struct usb_descriptor_header *hidg_fs_descriptors[] = { | |||
161 | }; | 167 | }; |
162 | 168 | ||
163 | /*-------------------------------------------------------------------------*/ | 169 | /*-------------------------------------------------------------------------*/ |
170 | /* Strings */ | ||
171 | |||
172 | #define CT_FUNC_HID_IDX 0 | ||
173 | |||
174 | static struct usb_string ct_func_string_defs[] = { | ||
175 | [CT_FUNC_HID_IDX].s = "HID Interface", | ||
176 | {}, /* end of list */ | ||
177 | }; | ||
178 | |||
179 | static struct usb_gadget_strings ct_func_string_table = { | ||
180 | .language = 0x0409, /* en-US */ | ||
181 | .strings = ct_func_string_defs, | ||
182 | }; | ||
183 | |||
184 | static struct usb_gadget_strings *ct_func_strings[] = { | ||
185 | &ct_func_string_table, | ||
186 | NULL, | ||
187 | }; | ||
188 | |||
189 | /*-------------------------------------------------------------------------*/ | ||
164 | /* Char Device */ | 190 | /* Char Device */ |
165 | 191 | ||
166 | static ssize_t f_hidg_read(struct file *file, char __user *buffer, | 192 | static ssize_t f_hidg_read(struct file *file, char __user *buffer, |
@@ -552,13 +578,22 @@ const struct file_operations f_hidg_fops = { | |||
552 | .llseek = noop_llseek, | 578 | .llseek = noop_llseek, |
553 | }; | 579 | }; |
554 | 580 | ||
555 | static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f) | 581 | static int hidg_bind(struct usb_configuration *c, struct usb_function *f) |
556 | { | 582 | { |
557 | struct usb_ep *ep; | 583 | struct usb_ep *ep; |
558 | struct f_hidg *hidg = func_to_hidg(f); | 584 | struct f_hidg *hidg = func_to_hidg(f); |
585 | struct usb_string *us; | ||
586 | struct device *device; | ||
559 | int status; | 587 | int status; |
560 | dev_t dev; | 588 | dev_t dev; |
561 | 589 | ||
590 | /* maybe allocate device-global string IDs, and patch descriptors */ | ||
591 | us = usb_gstrings_attach(c->cdev, ct_func_strings, | ||
592 | ARRAY_SIZE(ct_func_string_defs)); | ||
593 | if (IS_ERR(us)) | ||
594 | return PTR_ERR(us); | ||
595 | hidg_interface_desc.iInterface = us[CT_FUNC_HID_IDX].id; | ||
596 | |||
562 | /* allocate instance-specific interface IDs, and patch descriptors */ | 597 | /* allocate instance-specific interface IDs, and patch descriptors */ |
563 | status = usb_interface_id(c, f); | 598 | status = usb_interface_id(c, f); |
564 | if (status < 0) | 599 | if (status < 0) |
@@ -623,10 +658,16 @@ static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f) | |||
623 | if (status) | 658 | if (status) |
624 | goto fail_free_descs; | 659 | goto fail_free_descs; |
625 | 660 | ||
626 | device_create(hidg_class, NULL, dev, NULL, "%s%d", "hidg", hidg->minor); | 661 | device = device_create(hidg_class, NULL, dev, NULL, |
662 | "%s%d", "hidg", hidg->minor); | ||
663 | if (IS_ERR(device)) { | ||
664 | status = PTR_ERR(device); | ||
665 | goto del; | ||
666 | } | ||
627 | 667 | ||
628 | return 0; | 668 | return 0; |
629 | 669 | del: | |
670 | cdev_del(&hidg->cdev); | ||
630 | fail_free_descs: | 671 | fail_free_descs: |
631 | usb_free_all_descriptors(f); | 672 | usb_free_all_descriptors(f); |
632 | fail: | 673 | fail: |
@@ -640,116 +681,313 @@ fail: | |||
640 | return status; | 681 | return status; |
641 | } | 682 | } |
642 | 683 | ||
643 | static void hidg_unbind(struct usb_configuration *c, struct usb_function *f) | 684 | static inline int hidg_get_minor(void) |
644 | { | 685 | { |
645 | struct f_hidg *hidg = func_to_hidg(f); | 686 | int ret; |
646 | 687 | ||
647 | device_destroy(hidg_class, MKDEV(major, hidg->minor)); | 688 | ret = ida_simple_get(&hidg_ida, 0, 0, GFP_KERNEL); |
648 | cdev_del(&hidg->cdev); | ||
649 | 689 | ||
650 | /* disable/free request and end point */ | 690 | return ret; |
651 | usb_ep_disable(hidg->in_ep); | 691 | } |
652 | usb_ep_dequeue(hidg->in_ep, hidg->req); | ||
653 | kfree(hidg->req->buf); | ||
654 | usb_ep_free_request(hidg->in_ep, hidg->req); | ||
655 | |||
656 | usb_free_all_descriptors(f); | ||
657 | 692 | ||
658 | kfree(hidg->report_desc); | 693 | static inline struct f_hid_opts *to_f_hid_opts(struct config_item *item) |
659 | kfree(hidg); | 694 | { |
695 | return container_of(to_config_group(item), struct f_hid_opts, | ||
696 | func_inst.group); | ||
660 | } | 697 | } |
661 | 698 | ||
662 | /*-------------------------------------------------------------------------*/ | 699 | CONFIGFS_ATTR_STRUCT(f_hid_opts); |
663 | /* Strings */ | 700 | CONFIGFS_ATTR_OPS(f_hid_opts); |
664 | 701 | ||
665 | #define CT_FUNC_HID_IDX 0 | 702 | static void hid_attr_release(struct config_item *item) |
703 | { | ||
704 | struct f_hid_opts *opts = to_f_hid_opts(item); | ||
666 | 705 | ||
667 | static struct usb_string ct_func_string_defs[] = { | 706 | usb_put_function_instance(&opts->func_inst); |
668 | [CT_FUNC_HID_IDX].s = "HID Interface", | 707 | } |
669 | {}, /* end of list */ | ||
670 | }; | ||
671 | 708 | ||
672 | static struct usb_gadget_strings ct_func_string_table = { | 709 | static struct configfs_item_operations hidg_item_ops = { |
673 | .language = 0x0409, /* en-US */ | 710 | .release = hid_attr_release, |
674 | .strings = ct_func_string_defs, | 711 | .show_attribute = f_hid_opts_attr_show, |
712 | .store_attribute = f_hid_opts_attr_store, | ||
675 | }; | 713 | }; |
676 | 714 | ||
677 | static struct usb_gadget_strings *ct_func_strings[] = { | 715 | #define F_HID_OPT(name, prec, limit) \ |
678 | &ct_func_string_table, | 716 | static ssize_t f_hid_opts_##name##_show(struct f_hid_opts *opts, char *page)\ |
717 | { \ | ||
718 | int result; \ | ||
719 | \ | ||
720 | mutex_lock(&opts->lock); \ | ||
721 | result = sprintf(page, "%d\n", opts->name); \ | ||
722 | mutex_unlock(&opts->lock); \ | ||
723 | \ | ||
724 | return result; \ | ||
725 | } \ | ||
726 | \ | ||
727 | static ssize_t f_hid_opts_##name##_store(struct f_hid_opts *opts, \ | ||
728 | const char *page, size_t len) \ | ||
729 | { \ | ||
730 | int ret; \ | ||
731 | u##prec num; \ | ||
732 | \ | ||
733 | mutex_lock(&opts->lock); \ | ||
734 | if (opts->refcnt) { \ | ||
735 | ret = -EBUSY; \ | ||
736 | goto end; \ | ||
737 | } \ | ||
738 | \ | ||
739 | ret = kstrtou##prec(page, 0, &num); \ | ||
740 | if (ret) \ | ||
741 | goto end; \ | ||
742 | \ | ||
743 | if (num > limit) { \ | ||
744 | ret = -EINVAL; \ | ||
745 | goto end; \ | ||
746 | } \ | ||
747 | opts->name = num; \ | ||
748 | ret = len; \ | ||
749 | \ | ||
750 | end: \ | ||
751 | mutex_unlock(&opts->lock); \ | ||
752 | return ret; \ | ||
753 | } \ | ||
754 | \ | ||
755 | static struct f_hid_opts_attribute f_hid_opts_##name = \ | ||
756 | __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, f_hid_opts_##name##_show,\ | ||
757 | f_hid_opts_##name##_store) | ||
758 | |||
759 | F_HID_OPT(subclass, 8, 255); | ||
760 | F_HID_OPT(protocol, 8, 255); | ||
761 | F_HID_OPT(report_length, 16, 65536); | ||
762 | |||
763 | static ssize_t f_hid_opts_report_desc_show(struct f_hid_opts *opts, char *page) | ||
764 | { | ||
765 | int result; | ||
766 | |||
767 | mutex_lock(&opts->lock); | ||
768 | result = opts->report_desc_length; | ||
769 | memcpy(page, opts->report_desc, opts->report_desc_length); | ||
770 | mutex_unlock(&opts->lock); | ||
771 | |||
772 | return result; | ||
773 | } | ||
774 | |||
775 | static ssize_t f_hid_opts_report_desc_store(struct f_hid_opts *opts, | ||
776 | const char *page, size_t len) | ||
777 | { | ||
778 | int ret = -EBUSY; | ||
779 | char *d; | ||
780 | |||
781 | mutex_lock(&opts->lock); | ||
782 | |||
783 | if (opts->refcnt) | ||
784 | goto end; | ||
785 | if (len > PAGE_SIZE) { | ||
786 | ret = -ENOSPC; | ||
787 | goto end; | ||
788 | } | ||
789 | d = kmemdup(page, len, GFP_KERNEL); | ||
790 | if (!d) { | ||
791 | ret = -ENOMEM; | ||
792 | goto end; | ||
793 | } | ||
794 | kfree(opts->report_desc); | ||
795 | opts->report_desc = d; | ||
796 | opts->report_desc_length = len; | ||
797 | opts->report_desc_alloc = true; | ||
798 | ret = len; | ||
799 | end: | ||
800 | mutex_unlock(&opts->lock); | ||
801 | return ret; | ||
802 | } | ||
803 | |||
804 | static struct f_hid_opts_attribute f_hid_opts_report_desc = | ||
805 | __CONFIGFS_ATTR(report_desc, S_IRUGO | S_IWUSR, | ||
806 | f_hid_opts_report_desc_show, | ||
807 | f_hid_opts_report_desc_store); | ||
808 | |||
809 | static struct configfs_attribute *hid_attrs[] = { | ||
810 | &f_hid_opts_subclass.attr, | ||
811 | &f_hid_opts_protocol.attr, | ||
812 | &f_hid_opts_report_length.attr, | ||
813 | &f_hid_opts_report_desc.attr, | ||
679 | NULL, | 814 | NULL, |
680 | }; | 815 | }; |
681 | 816 | ||
682 | /*-------------------------------------------------------------------------*/ | 817 | static struct config_item_type hid_func_type = { |
683 | /* usb_configuration */ | 818 | .ct_item_ops = &hidg_item_ops, |
819 | .ct_attrs = hid_attrs, | ||
820 | .ct_owner = THIS_MODULE, | ||
821 | }; | ||
684 | 822 | ||
685 | int __init hidg_bind_config(struct usb_configuration *c, | 823 | static inline void hidg_put_minor(int minor) |
686 | struct hidg_func_descriptor *fdesc, int index) | ||
687 | { | 824 | { |
688 | struct f_hidg *hidg; | 825 | ida_simple_remove(&hidg_ida, minor); |
689 | int status; | 826 | } |
690 | 827 | ||
691 | if (index >= minors) | 828 | static void hidg_free_inst(struct usb_function_instance *f) |
692 | return -ENOENT; | 829 | { |
830 | struct f_hid_opts *opts; | ||
693 | 831 | ||
694 | /* maybe allocate device-global string IDs, and patch descriptors */ | 832 | opts = container_of(f, struct f_hid_opts, func_inst); |
695 | if (ct_func_string_defs[CT_FUNC_HID_IDX].id == 0) { | 833 | |
696 | status = usb_string_id(c->cdev); | 834 | mutex_lock(&hidg_ida_lock); |
697 | if (status < 0) | 835 | |
698 | return status; | 836 | hidg_put_minor(opts->minor); |
699 | ct_func_string_defs[CT_FUNC_HID_IDX].id = status; | 837 | if (idr_is_empty(&hidg_ida.idr)) |
700 | hidg_interface_desc.iInterface = status; | 838 | ghid_cleanup(); |
839 | |||
840 | mutex_unlock(&hidg_ida_lock); | ||
841 | |||
842 | if (opts->report_desc_alloc) | ||
843 | kfree(opts->report_desc); | ||
844 | |||
845 | kfree(opts); | ||
846 | } | ||
847 | |||
848 | static struct usb_function_instance *hidg_alloc_inst(void) | ||
849 | { | ||
850 | struct f_hid_opts *opts; | ||
851 | struct usb_function_instance *ret; | ||
852 | int status = 0; | ||
853 | |||
854 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
855 | if (!opts) | ||
856 | return ERR_PTR(-ENOMEM); | ||
857 | mutex_init(&opts->lock); | ||
858 | opts->func_inst.free_func_inst = hidg_free_inst; | ||
859 | ret = &opts->func_inst; | ||
860 | |||
861 | mutex_lock(&hidg_ida_lock); | ||
862 | |||
863 | if (idr_is_empty(&hidg_ida.idr)) { | ||
864 | status = ghid_setup(NULL, HIDG_MINORS); | ||
865 | if (status) { | ||
866 | ret = ERR_PTR(status); | ||
867 | kfree(opts); | ||
868 | goto unlock; | ||
869 | } | ||
870 | } | ||
871 | |||
872 | opts->minor = hidg_get_minor(); | ||
873 | if (opts->minor < 0) { | ||
874 | ret = ERR_PTR(opts->minor); | ||
875 | kfree(opts); | ||
876 | if (idr_is_empty(&hidg_ida.idr)) | ||
877 | ghid_cleanup(); | ||
878 | goto unlock; | ||
701 | } | 879 | } |
880 | config_group_init_type_name(&opts->func_inst.group, "", &hid_func_type); | ||
881 | |||
882 | unlock: | ||
883 | mutex_unlock(&hidg_ida_lock); | ||
884 | return ret; | ||
885 | } | ||
886 | |||
887 | static void hidg_free(struct usb_function *f) | ||
888 | { | ||
889 | struct f_hidg *hidg; | ||
890 | struct f_hid_opts *opts; | ||
891 | |||
892 | hidg = func_to_hidg(f); | ||
893 | opts = container_of(f->fi, struct f_hid_opts, func_inst); | ||
894 | kfree(hidg->report_desc); | ||
895 | kfree(hidg); | ||
896 | mutex_lock(&opts->lock); | ||
897 | --opts->refcnt; | ||
898 | mutex_unlock(&opts->lock); | ||
899 | } | ||
900 | |||
901 | static void hidg_unbind(struct usb_configuration *c, struct usb_function *f) | ||
902 | { | ||
903 | struct f_hidg *hidg = func_to_hidg(f); | ||
904 | |||
905 | device_destroy(hidg_class, MKDEV(major, hidg->minor)); | ||
906 | cdev_del(&hidg->cdev); | ||
907 | |||
908 | /* disable/free request and end point */ | ||
909 | usb_ep_disable(hidg->in_ep); | ||
910 | usb_ep_dequeue(hidg->in_ep, hidg->req); | ||
911 | kfree(hidg->req->buf); | ||
912 | usb_ep_free_request(hidg->in_ep, hidg->req); | ||
913 | |||
914 | usb_free_all_descriptors(f); | ||
915 | } | ||
916 | |||
917 | static struct usb_function *hidg_alloc(struct usb_function_instance *fi) | ||
918 | { | ||
919 | struct f_hidg *hidg; | ||
920 | struct f_hid_opts *opts; | ||
702 | 921 | ||
703 | /* allocate and initialize one new instance */ | 922 | /* allocate and initialize one new instance */ |
704 | hidg = kzalloc(sizeof *hidg, GFP_KERNEL); | 923 | hidg = kzalloc(sizeof(*hidg), GFP_KERNEL); |
705 | if (!hidg) | 924 | if (!hidg) |
706 | return -ENOMEM; | 925 | return ERR_PTR(-ENOMEM); |
707 | 926 | ||
708 | hidg->minor = index; | 927 | opts = container_of(fi, struct f_hid_opts, func_inst); |
709 | hidg->bInterfaceSubClass = fdesc->subclass; | 928 | |
710 | hidg->bInterfaceProtocol = fdesc->protocol; | 929 | mutex_lock(&opts->lock); |
711 | hidg->report_length = fdesc->report_length; | 930 | ++opts->refcnt; |
712 | hidg->report_desc_length = fdesc->report_desc_length; | 931 | |
713 | hidg->report_desc = kmemdup(fdesc->report_desc, | 932 | hidg->minor = opts->minor; |
714 | fdesc->report_desc_length, | 933 | hidg->bInterfaceSubClass = opts->subclass; |
715 | GFP_KERNEL); | 934 | hidg->bInterfaceProtocol = opts->protocol; |
716 | if (!hidg->report_desc) { | 935 | hidg->report_length = opts->report_length; |
717 | kfree(hidg); | 936 | hidg->report_desc_length = opts->report_desc_length; |
718 | return -ENOMEM; | 937 | if (opts->report_desc) { |
938 | hidg->report_desc = kmemdup(opts->report_desc, | ||
939 | opts->report_desc_length, | ||
940 | GFP_KERNEL); | ||
941 | if (!hidg->report_desc) { | ||
942 | kfree(hidg); | ||
943 | mutex_unlock(&opts->lock); | ||
944 | return ERR_PTR(-ENOMEM); | ||
945 | } | ||
719 | } | 946 | } |
720 | 947 | ||
948 | mutex_unlock(&opts->lock); | ||
949 | |||
721 | hidg->func.name = "hid"; | 950 | hidg->func.name = "hid"; |
722 | hidg->func.strings = ct_func_strings; | ||
723 | hidg->func.bind = hidg_bind; | 951 | hidg->func.bind = hidg_bind; |
724 | hidg->func.unbind = hidg_unbind; | 952 | hidg->func.unbind = hidg_unbind; |
725 | hidg->func.set_alt = hidg_set_alt; | 953 | hidg->func.set_alt = hidg_set_alt; |
726 | hidg->func.disable = hidg_disable; | 954 | hidg->func.disable = hidg_disable; |
727 | hidg->func.setup = hidg_setup; | 955 | hidg->func.setup = hidg_setup; |
956 | hidg->func.free_func = hidg_free; | ||
728 | 957 | ||
729 | /* this could me made configurable at some point */ | 958 | /* this could me made configurable at some point */ |
730 | hidg->qlen = 4; | 959 | hidg->qlen = 4; |
731 | 960 | ||
732 | status = usb_add_function(c, &hidg->func); | 961 | return &hidg->func; |
733 | if (status) | ||
734 | kfree(hidg); | ||
735 | |||
736 | return status; | ||
737 | } | 962 | } |
738 | 963 | ||
739 | int __init ghid_setup(struct usb_gadget *g, int count) | 964 | DECLARE_USB_FUNCTION_INIT(hid, hidg_alloc_inst, hidg_alloc); |
965 | MODULE_LICENSE("GPL"); | ||
966 | MODULE_AUTHOR("Fabien Chouteau"); | ||
967 | |||
968 | int ghid_setup(struct usb_gadget *g, int count) | ||
740 | { | 969 | { |
741 | int status; | 970 | int status; |
742 | dev_t dev; | 971 | dev_t dev; |
743 | 972 | ||
744 | hidg_class = class_create(THIS_MODULE, "hidg"); | 973 | hidg_class = class_create(THIS_MODULE, "hidg"); |
974 | if (IS_ERR(hidg_class)) { | ||
975 | status = PTR_ERR(hidg_class); | ||
976 | hidg_class = NULL; | ||
977 | return status; | ||
978 | } | ||
745 | 979 | ||
746 | status = alloc_chrdev_region(&dev, 0, count, "hidg"); | 980 | status = alloc_chrdev_region(&dev, 0, count, "hidg"); |
747 | if (!status) { | 981 | if (status) { |
748 | major = MAJOR(dev); | 982 | class_destroy(hidg_class); |
749 | minors = count; | 983 | hidg_class = NULL; |
984 | return status; | ||
750 | } | 985 | } |
751 | 986 | ||
752 | return status; | 987 | major = MAJOR(dev); |
988 | minors = count; | ||
989 | |||
990 | return 0; | ||
753 | } | 991 | } |
754 | 992 | ||
755 | void ghid_cleanup(void) | 993 | void ghid_cleanup(void) |
diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c index 807b31c0edc3..a90440300735 100644 --- a/drivers/usb/gadget/function/f_midi.c +++ b/drivers/usb/gadget/function/f_midi.c | |||
@@ -20,6 +20,7 @@ | |||
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
23 | #include <linux/module.h> | ||
23 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
24 | #include <linux/device.h> | 25 | #include <linux/device.h> |
25 | 26 | ||
@@ -33,6 +34,7 @@ | |||
33 | #include <linux/usb/midi.h> | 34 | #include <linux/usb/midi.h> |
34 | 35 | ||
35 | #include "u_f.h" | 36 | #include "u_f.h" |
37 | #include "u_midi.h" | ||
36 | 38 | ||
37 | MODULE_AUTHOR("Ben Williamson"); | 39 | MODULE_AUTHOR("Ben Williamson"); |
38 | MODULE_LICENSE("GPL v2"); | 40 | MODULE_LICENSE("GPL v2"); |
@@ -99,7 +101,7 @@ DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); | |||
99 | DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(16); | 101 | DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(16); |
100 | 102 | ||
101 | /* B.3.1 Standard AC Interface Descriptor */ | 103 | /* B.3.1 Standard AC Interface Descriptor */ |
102 | static struct usb_interface_descriptor ac_interface_desc __initdata = { | 104 | static struct usb_interface_descriptor ac_interface_desc = { |
103 | .bLength = USB_DT_INTERFACE_SIZE, | 105 | .bLength = USB_DT_INTERFACE_SIZE, |
104 | .bDescriptorType = USB_DT_INTERFACE, | 106 | .bDescriptorType = USB_DT_INTERFACE, |
105 | /* .bInterfaceNumber = DYNAMIC */ | 107 | /* .bInterfaceNumber = DYNAMIC */ |
@@ -110,7 +112,7 @@ static struct usb_interface_descriptor ac_interface_desc __initdata = { | |||
110 | }; | 112 | }; |
111 | 113 | ||
112 | /* B.3.2 Class-Specific AC Interface Descriptor */ | 114 | /* B.3.2 Class-Specific AC Interface Descriptor */ |
113 | static struct uac1_ac_header_descriptor_1 ac_header_desc __initdata = { | 115 | static struct uac1_ac_header_descriptor_1 ac_header_desc = { |
114 | .bLength = UAC_DT_AC_HEADER_SIZE(1), | 116 | .bLength = UAC_DT_AC_HEADER_SIZE(1), |
115 | .bDescriptorType = USB_DT_CS_INTERFACE, | 117 | .bDescriptorType = USB_DT_CS_INTERFACE, |
116 | .bDescriptorSubtype = USB_MS_HEADER, | 118 | .bDescriptorSubtype = USB_MS_HEADER, |
@@ -121,7 +123,7 @@ static struct uac1_ac_header_descriptor_1 ac_header_desc __initdata = { | |||
121 | }; | 123 | }; |
122 | 124 | ||
123 | /* B.4.1 Standard MS Interface Descriptor */ | 125 | /* B.4.1 Standard MS Interface Descriptor */ |
124 | static struct usb_interface_descriptor ms_interface_desc __initdata = { | 126 | static struct usb_interface_descriptor ms_interface_desc = { |
125 | .bLength = USB_DT_INTERFACE_SIZE, | 127 | .bLength = USB_DT_INTERFACE_SIZE, |
126 | .bDescriptorType = USB_DT_INTERFACE, | 128 | .bDescriptorType = USB_DT_INTERFACE, |
127 | /* .bInterfaceNumber = DYNAMIC */ | 129 | /* .bInterfaceNumber = DYNAMIC */ |
@@ -132,7 +134,7 @@ static struct usb_interface_descriptor ms_interface_desc __initdata = { | |||
132 | }; | 134 | }; |
133 | 135 | ||
134 | /* B.4.2 Class-Specific MS Interface Descriptor */ | 136 | /* B.4.2 Class-Specific MS Interface Descriptor */ |
135 | static struct usb_ms_header_descriptor ms_header_desc __initdata = { | 137 | static struct usb_ms_header_descriptor ms_header_desc = { |
136 | .bLength = USB_DT_MS_HEADER_SIZE, | 138 | .bLength = USB_DT_MS_HEADER_SIZE, |
137 | .bDescriptorType = USB_DT_CS_INTERFACE, | 139 | .bDescriptorType = USB_DT_CS_INTERFACE, |
138 | .bDescriptorSubtype = USB_MS_HEADER, | 140 | .bDescriptorSubtype = USB_MS_HEADER, |
@@ -387,29 +389,6 @@ static void f_midi_disable(struct usb_function *f) | |||
387 | usb_ep_disable(midi->out_ep); | 389 | usb_ep_disable(midi->out_ep); |
388 | } | 390 | } |
389 | 391 | ||
390 | static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f) | ||
391 | { | ||
392 | struct usb_composite_dev *cdev = f->config->cdev; | ||
393 | struct f_midi *midi = func_to_midi(f); | ||
394 | struct snd_card *card; | ||
395 | |||
396 | DBG(cdev, "unbind\n"); | ||
397 | |||
398 | /* just to be sure */ | ||
399 | f_midi_disable(f); | ||
400 | |||
401 | card = midi->card; | ||
402 | midi->card = NULL; | ||
403 | if (card) | ||
404 | snd_card_free(card); | ||
405 | |||
406 | kfree(midi->id); | ||
407 | midi->id = NULL; | ||
408 | |||
409 | usb_free_all_descriptors(f); | ||
410 | kfree(midi); | ||
411 | } | ||
412 | |||
413 | static int f_midi_snd_free(struct snd_device *device) | 392 | static int f_midi_snd_free(struct snd_device *device) |
414 | { | 393 | { |
415 | return 0; | 394 | return 0; |
@@ -654,6 +633,14 @@ static struct snd_rawmidi_ops gmidi_out_ops = { | |||
654 | .trigger = f_midi_out_trigger | 633 | .trigger = f_midi_out_trigger |
655 | }; | 634 | }; |
656 | 635 | ||
636 | static inline void f_midi_unregister_card(struct f_midi *midi) | ||
637 | { | ||
638 | if (midi->card) { | ||
639 | snd_card_free(midi->card); | ||
640 | midi->card = NULL; | ||
641 | } | ||
642 | } | ||
643 | |||
657 | /* register as a sound "card" */ | 644 | /* register as a sound "card" */ |
658 | static int f_midi_register_card(struct f_midi *midi) | 645 | static int f_midi_register_card(struct f_midi *midi) |
659 | { | 646 | { |
@@ -715,17 +702,13 @@ static int f_midi_register_card(struct f_midi *midi) | |||
715 | return 0; | 702 | return 0; |
716 | 703 | ||
717 | fail: | 704 | fail: |
718 | if (midi->card) { | 705 | f_midi_unregister_card(midi); |
719 | snd_card_free(midi->card); | ||
720 | midi->card = NULL; | ||
721 | } | ||
722 | return err; | 706 | return err; |
723 | } | 707 | } |
724 | 708 | ||
725 | /* MIDI function driver setup/binding */ | 709 | /* MIDI function driver setup/binding */ |
726 | 710 | ||
727 | static int __init | 711 | static int f_midi_bind(struct usb_configuration *c, struct usb_function *f) |
728 | f_midi_bind(struct usb_configuration *c, struct usb_function *f) | ||
729 | { | 712 | { |
730 | struct usb_descriptor_header **midi_function; | 713 | struct usb_descriptor_header **midi_function; |
731 | struct usb_midi_in_jack_descriptor jack_in_ext_desc[MAX_PORTS]; | 714 | struct usb_midi_in_jack_descriptor jack_in_ext_desc[MAX_PORTS]; |
@@ -734,15 +717,23 @@ f_midi_bind(struct usb_configuration *c, struct usb_function *f) | |||
734 | struct usb_midi_out_jack_descriptor_1 jack_out_emb_desc[MAX_PORTS]; | 717 | struct usb_midi_out_jack_descriptor_1 jack_out_emb_desc[MAX_PORTS]; |
735 | struct usb_composite_dev *cdev = c->cdev; | 718 | struct usb_composite_dev *cdev = c->cdev; |
736 | struct f_midi *midi = func_to_midi(f); | 719 | struct f_midi *midi = func_to_midi(f); |
720 | struct usb_string *us; | ||
737 | int status, n, jack = 1, i = 0; | 721 | int status, n, jack = 1, i = 0; |
738 | 722 | ||
723 | midi->gadget = cdev->gadget; | ||
724 | tasklet_init(&midi->tasklet, f_midi_in_tasklet, (unsigned long) midi); | ||
725 | status = f_midi_register_card(midi); | ||
726 | if (status < 0) | ||
727 | goto fail_register; | ||
728 | |||
739 | /* maybe allocate device-global string ID */ | 729 | /* maybe allocate device-global string ID */ |
740 | if (midi_string_defs[0].id == 0) { | 730 | us = usb_gstrings_attach(c->cdev, midi_strings, |
741 | status = usb_string_id(c->cdev); | 731 | ARRAY_SIZE(midi_string_defs)); |
742 | if (status < 0) | 732 | if (IS_ERR(us)) { |
743 | goto fail; | 733 | status = PTR_ERR(us); |
744 | midi_string_defs[0].id = status; | 734 | goto fail; |
745 | } | 735 | } |
736 | ac_interface_desc.iInterface = us[STRING_FUNC_IDX].id; | ||
746 | 737 | ||
747 | /* We have two interfaces, AudioControl and MIDIStreaming */ | 738 | /* We have two interfaces, AudioControl and MIDIStreaming */ |
748 | status = usb_interface_id(c, f); | 739 | status = usb_interface_id(c, f); |
@@ -892,6 +883,8 @@ fail_f_midi: | |||
892 | kfree(midi_function); | 883 | kfree(midi_function); |
893 | usb_free_descriptors(f->hs_descriptors); | 884 | usb_free_descriptors(f->hs_descriptors); |
894 | fail: | 885 | fail: |
886 | f_midi_unregister_card(midi); | ||
887 | fail_register: | ||
895 | /* we might as well release our claims on endpoints */ | 888 | /* we might as well release our claims on endpoints */ |
896 | if (midi->out_ep) | 889 | if (midi->out_ep) |
897 | midi->out_ep->driver_data = NULL; | 890 | midi->out_ep->driver_data = NULL; |
@@ -903,42 +896,235 @@ fail: | |||
903 | return status; | 896 | return status; |
904 | } | 897 | } |
905 | 898 | ||
906 | /** | 899 | static inline struct f_midi_opts *to_f_midi_opts(struct config_item *item) |
907 | * f_midi_bind_config - add USB MIDI function to a configuration | 900 | { |
908 | * @c: the configuration to supcard the USB audio function | 901 | return container_of(to_config_group(item), struct f_midi_opts, |
909 | * @index: the soundcard index to use for the ALSA device creation | 902 | func_inst.group); |
910 | * @id: the soundcard id to use for the ALSA device creation | 903 | } |
911 | * @buflen: the buffer length to use | 904 | |
912 | * @qlen the number of read requests to pre-allocate | 905 | CONFIGFS_ATTR_STRUCT(f_midi_opts); |
913 | * Context: single threaded during gadget setup | 906 | CONFIGFS_ATTR_OPS(f_midi_opts); |
914 | * | 907 | |
915 | * Returns zero on success, else negative errno. | 908 | static void midi_attr_release(struct config_item *item) |
916 | */ | 909 | { |
917 | int __init f_midi_bind_config(struct usb_configuration *c, | 910 | struct f_midi_opts *opts = to_f_midi_opts(item); |
918 | int index, char *id, | 911 | |
919 | unsigned int in_ports, | 912 | usb_put_function_instance(&opts->func_inst); |
920 | unsigned int out_ports, | 913 | } |
921 | unsigned int buflen, | 914 | |
922 | unsigned int qlen) | 915 | static struct configfs_item_operations midi_item_ops = { |
916 | .release = midi_attr_release, | ||
917 | .show_attribute = f_midi_opts_attr_show, | ||
918 | .store_attribute = f_midi_opts_attr_store, | ||
919 | }; | ||
920 | |||
921 | #define F_MIDI_OPT(name, test_limit, limit) \ | ||
922 | static ssize_t f_midi_opts_##name##_show(struct f_midi_opts *opts, char *page) \ | ||
923 | { \ | ||
924 | int result; \ | ||
925 | \ | ||
926 | mutex_lock(&opts->lock); \ | ||
927 | result = sprintf(page, "%d\n", opts->name); \ | ||
928 | mutex_unlock(&opts->lock); \ | ||
929 | \ | ||
930 | return result; \ | ||
931 | } \ | ||
932 | \ | ||
933 | static ssize_t f_midi_opts_##name##_store(struct f_midi_opts *opts, \ | ||
934 | const char *page, size_t len) \ | ||
935 | { \ | ||
936 | int ret; \ | ||
937 | u32 num; \ | ||
938 | \ | ||
939 | mutex_lock(&opts->lock); \ | ||
940 | if (opts->refcnt) { \ | ||
941 | ret = -EBUSY; \ | ||
942 | goto end; \ | ||
943 | } \ | ||
944 | \ | ||
945 | ret = kstrtou32(page, 0, &num); \ | ||
946 | if (ret) \ | ||
947 | goto end; \ | ||
948 | \ | ||
949 | if (test_limit && num > limit) { \ | ||
950 | ret = -EINVAL; \ | ||
951 | goto end; \ | ||
952 | } \ | ||
953 | opts->name = num; \ | ||
954 | ret = len; \ | ||
955 | \ | ||
956 | end: \ | ||
957 | mutex_unlock(&opts->lock); \ | ||
958 | return ret; \ | ||
959 | } \ | ||
960 | \ | ||
961 | static struct f_midi_opts_attribute f_midi_opts_##name = \ | ||
962 | __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, f_midi_opts_##name##_show, \ | ||
963 | f_midi_opts_##name##_store) | ||
964 | |||
965 | F_MIDI_OPT(index, true, SNDRV_CARDS); | ||
966 | F_MIDI_OPT(buflen, false, 0); | ||
967 | F_MIDI_OPT(qlen, false, 0); | ||
968 | F_MIDI_OPT(in_ports, true, MAX_PORTS); | ||
969 | F_MIDI_OPT(out_ports, true, MAX_PORTS); | ||
970 | |||
971 | static ssize_t f_midi_opts_id_show(struct f_midi_opts *opts, char *page) | ||
972 | { | ||
973 | int result; | ||
974 | |||
975 | mutex_lock(&opts->lock); | ||
976 | result = strlcpy(page, opts->id, PAGE_SIZE); | ||
977 | mutex_unlock(&opts->lock); | ||
978 | |||
979 | return result; | ||
980 | } | ||
981 | |||
982 | static ssize_t f_midi_opts_id_store(struct f_midi_opts *opts, | ||
983 | const char *page, size_t len) | ||
984 | { | ||
985 | int ret; | ||
986 | char *c; | ||
987 | |||
988 | mutex_lock(&opts->lock); | ||
989 | if (opts->refcnt) { | ||
990 | ret = -EBUSY; | ||
991 | goto end; | ||
992 | } | ||
993 | |||
994 | c = kstrndup(page, len, GFP_KERNEL); | ||
995 | if (!c) { | ||
996 | ret = -ENOMEM; | ||
997 | goto end; | ||
998 | } | ||
999 | if (opts->id_allocated) | ||
1000 | kfree(opts->id); | ||
1001 | opts->id = c; | ||
1002 | opts->id_allocated = true; | ||
1003 | ret = len; | ||
1004 | end: | ||
1005 | mutex_unlock(&opts->lock); | ||
1006 | return ret; | ||
1007 | } | ||
1008 | |||
1009 | static struct f_midi_opts_attribute f_midi_opts_id = | ||
1010 | __CONFIGFS_ATTR(id, S_IRUGO | S_IWUSR, f_midi_opts_id_show, | ||
1011 | f_midi_opts_id_store); | ||
1012 | |||
1013 | static struct configfs_attribute *midi_attrs[] = { | ||
1014 | &f_midi_opts_index.attr, | ||
1015 | &f_midi_opts_buflen.attr, | ||
1016 | &f_midi_opts_qlen.attr, | ||
1017 | &f_midi_opts_in_ports.attr, | ||
1018 | &f_midi_opts_out_ports.attr, | ||
1019 | &f_midi_opts_id.attr, | ||
1020 | NULL, | ||
1021 | }; | ||
1022 | |||
1023 | static struct config_item_type midi_func_type = { | ||
1024 | .ct_item_ops = &midi_item_ops, | ||
1025 | .ct_attrs = midi_attrs, | ||
1026 | .ct_owner = THIS_MODULE, | ||
1027 | }; | ||
1028 | |||
1029 | static void f_midi_free_inst(struct usb_function_instance *f) | ||
1030 | { | ||
1031 | struct f_midi_opts *opts; | ||
1032 | |||
1033 | opts = container_of(f, struct f_midi_opts, func_inst); | ||
1034 | |||
1035 | if (opts->id_allocated) | ||
1036 | kfree(opts->id); | ||
1037 | |||
1038 | kfree(opts); | ||
1039 | } | ||
1040 | |||
1041 | static struct usb_function_instance *f_midi_alloc_inst(void) | ||
1042 | { | ||
1043 | struct f_midi_opts *opts; | ||
1044 | |||
1045 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
1046 | if (!opts) | ||
1047 | return ERR_PTR(-ENOMEM); | ||
1048 | |||
1049 | mutex_init(&opts->lock); | ||
1050 | opts->func_inst.free_func_inst = f_midi_free_inst; | ||
1051 | opts->index = SNDRV_DEFAULT_IDX1; | ||
1052 | opts->id = SNDRV_DEFAULT_STR1; | ||
1053 | opts->buflen = 256; | ||
1054 | opts->qlen = 32; | ||
1055 | opts->in_ports = 1; | ||
1056 | opts->out_ports = 1; | ||
1057 | |||
1058 | config_group_init_type_name(&opts->func_inst.group, "", | ||
1059 | &midi_func_type); | ||
1060 | |||
1061 | return &opts->func_inst; | ||
1062 | } | ||
1063 | |||
1064 | static void f_midi_free(struct usb_function *f) | ||
1065 | { | ||
1066 | struct f_midi *midi; | ||
1067 | struct f_midi_opts *opts; | ||
1068 | int i; | ||
1069 | |||
1070 | midi = func_to_midi(f); | ||
1071 | opts = container_of(f->fi, struct f_midi_opts, func_inst); | ||
1072 | kfree(midi->id); | ||
1073 | mutex_lock(&opts->lock); | ||
1074 | for (i = opts->in_ports - 1; i >= 0; --i) | ||
1075 | kfree(midi->in_port[i]); | ||
1076 | kfree(midi); | ||
1077 | --opts->refcnt; | ||
1078 | mutex_unlock(&opts->lock); | ||
1079 | } | ||
1080 | |||
1081 | static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f) | ||
1082 | { | ||
1083 | struct usb_composite_dev *cdev = f->config->cdev; | ||
1084 | struct f_midi *midi = func_to_midi(f); | ||
1085 | struct snd_card *card; | ||
1086 | |||
1087 | DBG(cdev, "unbind\n"); | ||
1088 | |||
1089 | /* just to be sure */ | ||
1090 | f_midi_disable(f); | ||
1091 | |||
1092 | card = midi->card; | ||
1093 | midi->card = NULL; | ||
1094 | if (card) | ||
1095 | snd_card_free(card); | ||
1096 | |||
1097 | usb_free_all_descriptors(f); | ||
1098 | } | ||
1099 | |||
1100 | static struct usb_function *f_midi_alloc(struct usb_function_instance *fi) | ||
923 | { | 1101 | { |
924 | struct f_midi *midi; | 1102 | struct f_midi *midi; |
1103 | struct f_midi_opts *opts; | ||
925 | int status, i; | 1104 | int status, i; |
926 | 1105 | ||
1106 | opts = container_of(fi, struct f_midi_opts, func_inst); | ||
1107 | |||
1108 | mutex_lock(&opts->lock); | ||
927 | /* sanity check */ | 1109 | /* sanity check */ |
928 | if (in_ports > MAX_PORTS || out_ports > MAX_PORTS) | 1110 | if (opts->in_ports > MAX_PORTS || opts->out_ports > MAX_PORTS) { |
929 | return -EINVAL; | 1111 | mutex_unlock(&opts->lock); |
1112 | return ERR_PTR(-EINVAL); | ||
1113 | } | ||
930 | 1114 | ||
931 | /* allocate and initialize one new instance */ | 1115 | /* allocate and initialize one new instance */ |
932 | midi = kzalloc(sizeof *midi, GFP_KERNEL); | 1116 | midi = kzalloc(sizeof(*midi), GFP_KERNEL); |
933 | if (!midi) { | 1117 | if (!midi) { |
934 | status = -ENOMEM; | 1118 | mutex_unlock(&opts->lock); |
935 | goto fail; | 1119 | return ERR_PTR(-ENOMEM); |
936 | } | 1120 | } |
937 | 1121 | ||
938 | for (i = 0; i < in_ports; i++) { | 1122 | for (i = 0; i < opts->in_ports; i++) { |
939 | struct gmidi_in_port *port = kzalloc(sizeof(*port), GFP_KERNEL); | 1123 | struct gmidi_in_port *port = kzalloc(sizeof(*port), GFP_KERNEL); |
1124 | |||
940 | if (!port) { | 1125 | if (!port) { |
941 | status = -ENOMEM; | 1126 | status = -ENOMEM; |
1127 | mutex_unlock(&opts->lock); | ||
942 | goto setup_fail; | 1128 | goto setup_fail; |
943 | } | 1129 | } |
944 | 1130 | ||
@@ -948,39 +1134,37 @@ int __init f_midi_bind_config(struct usb_configuration *c, | |||
948 | midi->in_port[i] = port; | 1134 | midi->in_port[i] = port; |
949 | } | 1135 | } |
950 | 1136 | ||
951 | midi->gadget = c->cdev->gadget; | ||
952 | tasklet_init(&midi->tasklet, f_midi_in_tasklet, (unsigned long) midi); | ||
953 | |||
954 | /* set up ALSA midi devices */ | 1137 | /* set up ALSA midi devices */ |
955 | midi->in_ports = in_ports; | 1138 | midi->id = kstrdup(opts->id, GFP_KERNEL); |
956 | midi->out_ports = out_ports; | 1139 | if (opts->id && !midi->id) { |
957 | status = f_midi_register_card(midi); | 1140 | status = -ENOMEM; |
958 | if (status < 0) | 1141 | mutex_unlock(&opts->lock); |
959 | goto setup_fail; | 1142 | goto kstrdup_fail; |
960 | 1143 | } | |
961 | midi->func.name = "gmidi function"; | 1144 | midi->in_ports = opts->in_ports; |
962 | midi->func.strings = midi_strings; | 1145 | midi->out_ports = opts->out_ports; |
963 | midi->func.bind = f_midi_bind; | 1146 | midi->index = opts->index; |
964 | midi->func.unbind = f_midi_unbind; | 1147 | midi->buflen = opts->buflen; |
965 | midi->func.set_alt = f_midi_set_alt; | 1148 | midi->qlen = opts->qlen; |
966 | midi->func.disable = f_midi_disable; | 1149 | ++opts->refcnt; |
967 | 1150 | mutex_unlock(&opts->lock); | |
968 | midi->id = kstrdup(id, GFP_KERNEL); | 1151 | |
969 | midi->index = index; | 1152 | midi->func.name = "gmidi function"; |
970 | midi->buflen = buflen; | 1153 | midi->func.bind = f_midi_bind; |
971 | midi->qlen = qlen; | 1154 | midi->func.unbind = f_midi_unbind; |
972 | 1155 | midi->func.set_alt = f_midi_set_alt; | |
973 | status = usb_add_function(c, &midi->func); | 1156 | midi->func.disable = f_midi_disable; |
974 | if (status) | 1157 | midi->func.free_func = f_midi_free; |
975 | goto setup_fail; | 1158 | |
976 | 1159 | return &midi->func; | |
977 | return 0; | 1160 | |
978 | 1161 | kstrdup_fail: | |
1162 | f_midi_unregister_card(midi); | ||
979 | setup_fail: | 1163 | setup_fail: |
980 | for (--i; i >= 0; i--) | 1164 | for (--i; i >= 0; i--) |
981 | kfree(midi->in_port[i]); | 1165 | kfree(midi->in_port[i]); |
982 | kfree(midi); | 1166 | kfree(midi); |
983 | fail: | 1167 | return ERR_PTR(status); |
984 | return status; | ||
985 | } | 1168 | } |
986 | 1169 | ||
1170 | DECLARE_USB_FUNCTION_INIT(midi, f_midi_alloc_inst, f_midi_alloc); | ||
diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index 16361b0a8b46..bdcda9f5148e 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c | |||
@@ -1441,6 +1441,9 @@ static int ncm_bind(struct usb_configuration *c, struct usb_function *f) | |||
1441 | 1441 | ||
1442 | status = usb_assign_descriptors(f, ncm_fs_function, ncm_hs_function, | 1442 | status = usb_assign_descriptors(f, ncm_fs_function, ncm_hs_function, |
1443 | NULL); | 1443 | NULL); |
1444 | if (status) | ||
1445 | goto fail; | ||
1446 | |||
1444 | /* | 1447 | /* |
1445 | * NOTE: all that is done without knowing or caring about | 1448 | * NOTE: all that is done without knowing or caring about |
1446 | * the network link ... which is unavailable to this code | 1449 | * the network link ... which is unavailable to this code |
diff --git a/drivers/usb/gadget/function/f_rndis.c b/drivers/usb/gadget/function/f_rndis.c index f13fc6a58565..829edf878dac 100644 --- a/drivers/usb/gadget/function/f_rndis.c +++ b/drivers/usb/gadget/function/f_rndis.c | |||
@@ -375,8 +375,7 @@ static struct sk_buff *rndis_add_header(struct gether *port, | |||
375 | struct sk_buff *skb2; | 375 | struct sk_buff *skb2; |
376 | 376 | ||
377 | skb2 = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type)); | 377 | skb2 = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type)); |
378 | if (skb2) | 378 | rndis_add_hdr(skb2); |
379 | rndis_add_hdr(skb2); | ||
380 | 379 | ||
381 | dev_kfree_skb(skb); | 380 | dev_kfree_skb(skb); |
382 | return skb2; | 381 | return skb2; |
diff --git a/drivers/usb/gadget/function/u_hid.h b/drivers/usb/gadget/function/u_hid.h new file mode 100644 index 000000000000..aaa0e368a159 --- /dev/null +++ b/drivers/usb/gadget/function/u_hid.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * u_hid.h | ||
3 | * | ||
4 | * Utility definitions for the hid function | ||
5 | * | ||
6 | * Copyright (c) 2014 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_HID_H | ||
17 | #define U_HID_H | ||
18 | |||
19 | #include <linux/usb/composite.h> | ||
20 | |||
21 | struct f_hid_opts { | ||
22 | struct usb_function_instance func_inst; | ||
23 | int minor; | ||
24 | unsigned char subclass; | ||
25 | unsigned char protocol; | ||
26 | unsigned short report_length; | ||
27 | unsigned short report_desc_length; | ||
28 | unsigned char *report_desc; | ||
29 | bool report_desc_alloc; | ||
30 | |||
31 | /* | ||
32 | * Protect the data form concurrent access by read/write | ||
33 | * and create symlink/remove symlink. | ||
34 | */ | ||
35 | struct mutex lock; | ||
36 | int refcnt; | ||
37 | }; | ||
38 | |||
39 | int ghid_setup(struct usb_gadget *g, int count); | ||
40 | void ghid_cleanup(void); | ||
41 | |||
42 | #endif /* U_HID_H */ | ||
diff --git a/drivers/usb/gadget/function/u_midi.h b/drivers/usb/gadget/function/u_midi.h new file mode 100644 index 000000000000..22510189758e --- /dev/null +++ b/drivers/usb/gadget/function/u_midi.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * u_midi.h | ||
3 | * | ||
4 | * Utility definitions for the midi function | ||
5 | * | ||
6 | * Copyright (c) 2014 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_MIDI_H | ||
17 | #define U_MIDI_H | ||
18 | |||
19 | #include <linux/usb/composite.h> | ||
20 | |||
21 | struct f_midi_opts { | ||
22 | struct usb_function_instance func_inst; | ||
23 | int index; | ||
24 | char *id; | ||
25 | bool id_allocated; | ||
26 | unsigned int in_ports; | ||
27 | unsigned int out_ports; | ||
28 | unsigned int buflen; | ||
29 | unsigned int qlen; | ||
30 | |||
31 | /* | ||
32 | * Protect the data form concurrent access by read/write | ||
33 | * and create symlink/remove symlink. | ||
34 | */ | ||
35 | struct mutex lock; | ||
36 | int refcnt; | ||
37 | }; | ||
38 | |||
39 | #endif /* U_MIDI_H */ | ||
40 | |||
diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c index a44a07f30281..53842a1b947f 100644 --- a/drivers/usb/gadget/function/u_uac1.c +++ b/drivers/usb/gadget/function/u_uac1.c | |||
@@ -213,9 +213,6 @@ static int gaudio_open_snd_dev(struct gaudio *card) | |||
213 | fn_cap = opts->fn_cap; | 213 | fn_cap = opts->fn_cap; |
214 | fn_cntl = opts->fn_cntl; | 214 | fn_cntl = opts->fn_cntl; |
215 | 215 | ||
216 | if (!card) | ||
217 | return -ENODEV; | ||
218 | |||
219 | /* Open control device */ | 216 | /* Open control device */ |
220 | snd = &card->control; | 217 | snd = &card->control; |
221 | snd->filp = filp_open(fn_cntl, O_RDWR, 0); | 218 | snd->filp = filp_open(fn_cntl, O_RDWR, 0); |
diff --git a/drivers/usb/gadget/legacy/Kconfig b/drivers/usb/gadget/legacy/Kconfig index 24392d269709..fd48ef3af4eb 100644 --- a/drivers/usb/gadget/legacy/Kconfig +++ b/drivers/usb/gadget/legacy/Kconfig | |||
@@ -287,6 +287,7 @@ config USB_MIDI_GADGET | |||
287 | depends on SND | 287 | depends on SND |
288 | select USB_LIBCOMPOSITE | 288 | select USB_LIBCOMPOSITE |
289 | select SND_RAWMIDI | 289 | select SND_RAWMIDI |
290 | select USB_F_MIDI | ||
290 | help | 291 | help |
291 | The MIDI Gadget acts as a USB Audio device, with one MIDI | 292 | The MIDI Gadget acts as a USB Audio device, with one MIDI |
292 | input and one MIDI output. These MIDI jacks appear as | 293 | input and one MIDI output. These MIDI jacks appear as |
@@ -419,6 +420,7 @@ endif # TTY | |||
419 | config USB_G_HID | 420 | config USB_G_HID |
420 | tristate "HID Gadget" | 421 | tristate "HID Gadget" |
421 | select USB_LIBCOMPOSITE | 422 | select USB_LIBCOMPOSITE |
423 | select USB_F_HID | ||
422 | help | 424 | help |
423 | The HID gadget driver provides generic emulation of USB | 425 | The HID gadget driver provides generic emulation of USB |
424 | Human Interface Devices (HID). | 426 | Human Interface Devices (HID). |
diff --git a/drivers/usb/gadget/legacy/dbgp.c b/drivers/usb/gadget/legacy/dbgp.c index 1b075132f8f1..633683a72a11 100644 --- a/drivers/usb/gadget/legacy/dbgp.c +++ b/drivers/usb/gadget/legacy/dbgp.c | |||
@@ -237,7 +237,7 @@ static void dbgp_unbind(struct usb_gadget *gadget) | |||
237 | static unsigned char tty_line; | 237 | static unsigned char tty_line; |
238 | #endif | 238 | #endif |
239 | 239 | ||
240 | static int __init dbgp_configure_endpoints(struct usb_gadget *gadget) | 240 | static int dbgp_configure_endpoints(struct usb_gadget *gadget) |
241 | { | 241 | { |
242 | int stp; | 242 | int stp; |
243 | 243 | ||
@@ -273,19 +273,10 @@ static int __init dbgp_configure_endpoints(struct usb_gadget *gadget) | |||
273 | 273 | ||
274 | dbgp.serial->in->desc = &i_desc; | 274 | dbgp.serial->in->desc = &i_desc; |
275 | dbgp.serial->out->desc = &o_desc; | 275 | dbgp.serial->out->desc = &o_desc; |
276 | 276 | #endif | |
277 | if (gserial_alloc_line(&tty_line)) { | ||
278 | stp = 3; | ||
279 | goto fail_3; | ||
280 | } | ||
281 | 277 | ||
282 | return 0; | 278 | return 0; |
283 | 279 | ||
284 | fail_3: | ||
285 | dbgp.o_ep->driver_data = NULL; | ||
286 | #else | ||
287 | return 0; | ||
288 | #endif | ||
289 | fail_2: | 280 | fail_2: |
290 | dbgp.i_ep->driver_data = NULL; | 281 | dbgp.i_ep->driver_data = NULL; |
291 | fail_1: | 282 | fail_1: |
@@ -324,10 +315,17 @@ static int __init dbgp_bind(struct usb_gadget *gadget, | |||
324 | err = -ENOMEM; | 315 | err = -ENOMEM; |
325 | goto fail; | 316 | goto fail; |
326 | } | 317 | } |
318 | |||
319 | if (gserial_alloc_line(&tty_line)) { | ||
320 | stp = 4; | ||
321 | err = -ENODEV; | ||
322 | goto fail; | ||
323 | } | ||
327 | #endif | 324 | #endif |
325 | |||
328 | err = dbgp_configure_endpoints(gadget); | 326 | err = dbgp_configure_endpoints(gadget); |
329 | if (err < 0) { | 327 | if (err < 0) { |
330 | stp = 4; | 328 | stp = 5; |
331 | goto fail; | 329 | goto fail; |
332 | } | 330 | } |
333 | 331 | ||
@@ -383,6 +381,10 @@ static int dbgp_setup(struct usb_gadget *gadget, | |||
383 | #ifdef CONFIG_USB_G_DBGP_PRINTK | 381 | #ifdef CONFIG_USB_G_DBGP_PRINTK |
384 | err = dbgp_enable_ep(); | 382 | err = dbgp_enable_ep(); |
385 | #else | 383 | #else |
384 | err = dbgp_configure_endpoints(gadget); | ||
385 | if (err < 0) { | ||
386 | goto fail; | ||
387 | } | ||
386 | err = gserial_connect(dbgp.serial, tty_line); | 388 | err = gserial_connect(dbgp.serial, tty_line); |
387 | #endif | 389 | #endif |
388 | if (err < 0) | 390 | if (err < 0) |
diff --git a/drivers/usb/gadget/legacy/gmidi.c b/drivers/usb/gadget/legacy/gmidi.c index 3d696b86ff76..e02a095294ac 100644 --- a/drivers/usb/gadget/legacy/gmidi.c +++ b/drivers/usb/gadget/legacy/gmidi.c | |||
@@ -37,7 +37,7 @@ | |||
37 | 37 | ||
38 | #include "gadget_chips.h" | 38 | #include "gadget_chips.h" |
39 | 39 | ||
40 | #include "f_midi.c" | 40 | #include "u_midi.h" |
41 | 41 | ||
42 | /*-------------------------------------------------------------------------*/ | 42 | /*-------------------------------------------------------------------------*/ |
43 | 43 | ||
@@ -115,8 +115,13 @@ static struct usb_gadget_strings *dev_strings[] = { | |||
115 | NULL, | 115 | NULL, |
116 | }; | 116 | }; |
117 | 117 | ||
118 | static struct usb_function_instance *fi_midi; | ||
119 | static struct usb_function *f_midi; | ||
120 | |||
118 | static int __exit midi_unbind(struct usb_composite_dev *dev) | 121 | static int __exit midi_unbind(struct usb_composite_dev *dev) |
119 | { | 122 | { |
123 | usb_put_function(f_midi); | ||
124 | usb_put_function_instance(fi_midi); | ||
120 | return 0; | 125 | return 0; |
121 | } | 126 | } |
122 | 127 | ||
@@ -130,28 +135,54 @@ static struct usb_configuration midi_config = { | |||
130 | 135 | ||
131 | static int __init midi_bind_config(struct usb_configuration *c) | 136 | static int __init midi_bind_config(struct usb_configuration *c) |
132 | { | 137 | { |
133 | return f_midi_bind_config(c, index, id, | 138 | int status; |
134 | in_ports, out_ports, | 139 | |
135 | buflen, qlen); | 140 | f_midi = usb_get_function(fi_midi); |
141 | if (IS_ERR(f_midi)) | ||
142 | return PTR_ERR(f_midi); | ||
143 | |||
144 | status = usb_add_function(c, f_midi); | ||
145 | if (status < 0) { | ||
146 | usb_put_function(f_midi); | ||
147 | return status; | ||
148 | } | ||
149 | |||
150 | return 0; | ||
136 | } | 151 | } |
137 | 152 | ||
138 | static int __init midi_bind(struct usb_composite_dev *cdev) | 153 | static int __init midi_bind(struct usb_composite_dev *cdev) |
139 | { | 154 | { |
155 | struct f_midi_opts *midi_opts; | ||
140 | int status; | 156 | int status; |
141 | 157 | ||
158 | fi_midi = usb_get_function_instance("midi"); | ||
159 | if (IS_ERR(fi_midi)) | ||
160 | return PTR_ERR(fi_midi); | ||
161 | |||
162 | midi_opts = container_of(fi_midi, struct f_midi_opts, func_inst); | ||
163 | midi_opts->index = index; | ||
164 | midi_opts->id = id; | ||
165 | midi_opts->in_ports = in_ports; | ||
166 | midi_opts->out_ports = out_ports; | ||
167 | midi_opts->buflen = buflen; | ||
168 | midi_opts->qlen = qlen; | ||
169 | |||
142 | status = usb_string_ids_tab(cdev, strings_dev); | 170 | status = usb_string_ids_tab(cdev, strings_dev); |
143 | if (status < 0) | 171 | if (status < 0) |
144 | return status; | 172 | goto put; |
145 | device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; | 173 | device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; |
146 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; | 174 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; |
147 | midi_config.iConfiguration = strings_dev[STRING_DESCRIPTION_IDX].id; | 175 | midi_config.iConfiguration = strings_dev[STRING_DESCRIPTION_IDX].id; |
148 | 176 | ||
149 | status = usb_add_config(cdev, &midi_config, midi_bind_config); | 177 | status = usb_add_config(cdev, &midi_config, midi_bind_config); |
150 | if (status < 0) | 178 | if (status < 0) |
151 | return status; | 179 | goto put; |
152 | usb_composite_overwrite_options(cdev, &coverwrite); | 180 | usb_composite_overwrite_options(cdev, &coverwrite); |
153 | pr_info("%s\n", longname); | 181 | pr_info("%s\n", longname); |
154 | return 0; | 182 | return 0; |
183 | put: | ||
184 | usb_put_function_instance(fi_midi); | ||
185 | return status; | ||
155 | } | 186 | } |
156 | 187 | ||
157 | static __refdata struct usb_composite_driver midi_driver = { | 188 | static __refdata struct usb_composite_driver midi_driver = { |
diff --git a/drivers/usb/gadget/legacy/hid.c b/drivers/usb/gadget/legacy/hid.c index 778613eb37af..633fe7e07688 100644 --- a/drivers/usb/gadget/legacy/hid.c +++ b/drivers/usb/gadget/legacy/hid.c | |||
@@ -17,11 +17,14 @@ | |||
17 | #include <linux/list.h> | 17 | #include <linux/list.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/usb/composite.h> | 19 | #include <linux/usb/composite.h> |
20 | #include <linux/usb/g_hid.h> | ||
20 | 21 | ||
21 | #include "gadget_chips.h" | 22 | #include "gadget_chips.h" |
22 | #define DRIVER_DESC "HID Gadget" | 23 | #define DRIVER_DESC "HID Gadget" |
23 | #define DRIVER_VERSION "2010/03/16" | 24 | #define DRIVER_VERSION "2010/03/16" |
24 | 25 | ||
26 | #include "u_hid.h" | ||
27 | |||
25 | /*-------------------------------------------------------------------------*/ | 28 | /*-------------------------------------------------------------------------*/ |
26 | 29 | ||
27 | #define HIDG_VENDOR_NUM 0x0525 /* XXX NetChip */ | 30 | #define HIDG_VENDOR_NUM 0x0525 /* XXX NetChip */ |
@@ -29,17 +32,9 @@ | |||
29 | 32 | ||
30 | /*-------------------------------------------------------------------------*/ | 33 | /*-------------------------------------------------------------------------*/ |
31 | 34 | ||
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_hid.c" | ||
40 | |||
41 | |||
42 | struct hidg_func_node { | 35 | struct hidg_func_node { |
36 | struct usb_function_instance *fi; | ||
37 | struct usb_function *f; | ||
43 | struct list_head node; | 38 | struct list_head node; |
44 | struct hidg_func_descriptor *func; | 39 | struct hidg_func_descriptor *func; |
45 | }; | 40 | }; |
@@ -113,8 +108,8 @@ static struct usb_gadget_strings *dev_strings[] = { | |||
113 | 108 | ||
114 | static int __init do_config(struct usb_configuration *c) | 109 | static int __init do_config(struct usb_configuration *c) |
115 | { | 110 | { |
116 | struct hidg_func_node *e; | 111 | struct hidg_func_node *e, *n; |
117 | int func = 0, status = 0; | 112 | int status = 0; |
118 | 113 | ||
119 | if (gadget_is_otg(c->cdev->gadget)) { | 114 | if (gadget_is_otg(c->cdev->gadget)) { |
120 | c->descriptors = otg_desc; | 115 | c->descriptors = otg_desc; |
@@ -122,11 +117,24 @@ static int __init do_config(struct usb_configuration *c) | |||
122 | } | 117 | } |
123 | 118 | ||
124 | list_for_each_entry(e, &hidg_func_list, node) { | 119 | list_for_each_entry(e, &hidg_func_list, node) { |
125 | status = hidg_bind_config(c, e->func, func++); | 120 | e->f = usb_get_function(e->fi); |
126 | if (status) | 121 | if (IS_ERR(e->f)) |
127 | break; | 122 | goto put; |
123 | status = usb_add_function(c, e->f); | ||
124 | if (status < 0) { | ||
125 | usb_put_function(e->f); | ||
126 | goto put; | ||
127 | } | ||
128 | } | 128 | } |
129 | 129 | ||
130 | return 0; | ||
131 | put: | ||
132 | list_for_each_entry(n, &hidg_func_list, node) { | ||
133 | if (n == e) | ||
134 | break; | ||
135 | usb_remove_function(c, n->f); | ||
136 | usb_put_function(n->f); | ||
137 | } | ||
130 | return status; | 138 | return status; |
131 | } | 139 | } |
132 | 140 | ||
@@ -143,6 +151,8 @@ static int __init hid_bind(struct usb_composite_dev *cdev) | |||
143 | { | 151 | { |
144 | struct usb_gadget *gadget = cdev->gadget; | 152 | struct usb_gadget *gadget = cdev->gadget; |
145 | struct list_head *tmp; | 153 | struct list_head *tmp; |
154 | struct hidg_func_node *n, *m; | ||
155 | struct f_hid_opts *hid_opts; | ||
146 | int status, funcs = 0; | 156 | int status, funcs = 0; |
147 | 157 | ||
148 | list_for_each(tmp, &hidg_func_list) | 158 | list_for_each(tmp, &hidg_func_list) |
@@ -151,10 +161,20 @@ static int __init hid_bind(struct usb_composite_dev *cdev) | |||
151 | if (!funcs) | 161 | if (!funcs) |
152 | return -ENODEV; | 162 | return -ENODEV; |
153 | 163 | ||
154 | /* set up HID */ | 164 | list_for_each_entry(n, &hidg_func_list, node) { |
155 | status = ghid_setup(cdev->gadget, funcs); | 165 | n->fi = usb_get_function_instance("hid"); |
156 | if (status < 0) | 166 | if (IS_ERR(n->fi)) { |
157 | return status; | 167 | status = PTR_ERR(n->fi); |
168 | goto put; | ||
169 | } | ||
170 | hid_opts = container_of(n->fi, struct f_hid_opts, func_inst); | ||
171 | hid_opts->subclass = n->func->subclass; | ||
172 | hid_opts->protocol = n->func->protocol; | ||
173 | hid_opts->report_length = n->func->report_length; | ||
174 | hid_opts->report_desc_length = n->func->report_desc_length; | ||
175 | hid_opts->report_desc = n->func->report_desc; | ||
176 | } | ||
177 | |||
158 | 178 | ||
159 | /* Allocate string descriptor numbers ... note that string | 179 | /* Allocate string descriptor numbers ... note that string |
160 | * contents can be overridden by the composite_dev glue. | 180 | * contents can be overridden by the composite_dev glue. |
@@ -162,24 +182,37 @@ static int __init hid_bind(struct usb_composite_dev *cdev) | |||
162 | 182 | ||
163 | status = usb_string_ids_tab(cdev, strings_dev); | 183 | status = usb_string_ids_tab(cdev, strings_dev); |
164 | if (status < 0) | 184 | if (status < 0) |
165 | return status; | 185 | goto put; |
166 | device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; | 186 | device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; |
167 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; | 187 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; |
168 | 188 | ||
169 | /* register our configuration */ | 189 | /* register our configuration */ |
170 | status = usb_add_config(cdev, &config_driver, do_config); | 190 | status = usb_add_config(cdev, &config_driver, do_config); |
171 | if (status < 0) | 191 | if (status < 0) |
172 | return status; | 192 | goto put; |
173 | 193 | ||
174 | usb_composite_overwrite_options(cdev, &coverwrite); | 194 | usb_composite_overwrite_options(cdev, &coverwrite); |
175 | dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); | 195 | dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); |
176 | 196 | ||
177 | return 0; | 197 | return 0; |
198 | |||
199 | put: | ||
200 | list_for_each_entry(m, &hidg_func_list, node) { | ||
201 | if (m == n) | ||
202 | break; | ||
203 | usb_put_function_instance(m->fi); | ||
204 | } | ||
205 | return status; | ||
178 | } | 206 | } |
179 | 207 | ||
180 | static int __exit hid_unbind(struct usb_composite_dev *cdev) | 208 | static int __exit hid_unbind(struct usb_composite_dev *cdev) |
181 | { | 209 | { |
182 | ghid_cleanup(); | 210 | struct hidg_func_node *n; |
211 | |||
212 | list_for_each_entry(n, &hidg_func_list, node) { | ||
213 | usb_put_function(n->f); | ||
214 | usb_put_function_instance(n->fi); | ||
215 | } | ||
183 | return 0; | 216 | return 0; |
184 | } | 217 | } |
185 | 218 | ||
@@ -260,7 +293,7 @@ module_init(hidg_init); | |||
260 | 293 | ||
261 | static void __exit hidg_cleanup(void) | 294 | static void __exit hidg_cleanup(void) |
262 | { | 295 | { |
263 | platform_driver_unregister(&hidg_plat_driver); | ||
264 | usb_composite_unregister(&hidg_driver); | 296 | usb_composite_unregister(&hidg_driver); |
297 | platform_driver_unregister(&hidg_plat_driver); | ||
265 | } | 298 | } |
266 | module_exit(hidg_cleanup); | 299 | module_exit(hidg_cleanup); |
diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 6474081dcbaf..90545980542f 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c | |||
@@ -208,6 +208,43 @@ static struct usb_descriptor_header *hs_printer_function[] = { | |||
208 | NULL | 208 | NULL |
209 | }; | 209 | }; |
210 | 210 | ||
211 | /* | ||
212 | * Added endpoint descriptors for 3.0 devices | ||
213 | */ | ||
214 | |||
215 | static struct usb_endpoint_descriptor ss_ep_in_desc = { | ||
216 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
217 | .bDescriptorType = USB_DT_ENDPOINT, | ||
218 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
219 | .wMaxPacketSize = cpu_to_le16(1024), | ||
220 | }; | ||
221 | |||
222 | static struct usb_ss_ep_comp_descriptor ss_ep_in_comp_desc = { | ||
223 | .bLength = sizeof(ss_ep_in_comp_desc), | ||
224 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
225 | }; | ||
226 | |||
227 | static struct usb_endpoint_descriptor ss_ep_out_desc = { | ||
228 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
229 | .bDescriptorType = USB_DT_ENDPOINT, | ||
230 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
231 | .wMaxPacketSize = cpu_to_le16(1024), | ||
232 | }; | ||
233 | |||
234 | static struct usb_ss_ep_comp_descriptor ss_ep_out_comp_desc = { | ||
235 | .bLength = sizeof(ss_ep_out_comp_desc), | ||
236 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
237 | }; | ||
238 | |||
239 | static struct usb_descriptor_header *ss_printer_function[] = { | ||
240 | (struct usb_descriptor_header *) &intf_desc, | ||
241 | (struct usb_descriptor_header *) &ss_ep_in_desc, | ||
242 | (struct usb_descriptor_header *) &ss_ep_in_comp_desc, | ||
243 | (struct usb_descriptor_header *) &ss_ep_out_desc, | ||
244 | (struct usb_descriptor_header *) &ss_ep_out_comp_desc, | ||
245 | NULL | ||
246 | }; | ||
247 | |||
211 | static struct usb_otg_descriptor otg_descriptor = { | 248 | static struct usb_otg_descriptor otg_descriptor = { |
212 | .bLength = sizeof otg_descriptor, | 249 | .bLength = sizeof otg_descriptor, |
213 | .bDescriptorType = USB_DT_OTG, | 250 | .bDescriptorType = USB_DT_OTG, |
@@ -220,7 +257,20 @@ static const struct usb_descriptor_header *otg_desc[] = { | |||
220 | }; | 257 | }; |
221 | 258 | ||
222 | /* maxpacket and other transfer characteristics vary by speed. */ | 259 | /* maxpacket and other transfer characteristics vary by speed. */ |
223 | #define ep_desc(g, hs, fs) (((g)->speed == USB_SPEED_HIGH)?(hs):(fs)) | 260 | static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget *gadget, |
261 | struct usb_endpoint_descriptor *fs, | ||
262 | struct usb_endpoint_descriptor *hs, | ||
263 | struct usb_endpoint_descriptor *ss) | ||
264 | { | ||
265 | switch (gadget->speed) { | ||
266 | case USB_SPEED_SUPER: | ||
267 | return ss; | ||
268 | case USB_SPEED_HIGH: | ||
269 | return hs; | ||
270 | default: | ||
271 | return fs; | ||
272 | } | ||
273 | } | ||
224 | 274 | ||
225 | /*-------------------------------------------------------------------------*/ | 275 | /*-------------------------------------------------------------------------*/ |
226 | 276 | ||
@@ -793,11 +843,12 @@ set_printer_interface(struct printer_dev *dev) | |||
793 | { | 843 | { |
794 | int result = 0; | 844 | int result = 0; |
795 | 845 | ||
796 | dev->in_ep->desc = ep_desc(dev->gadget, &hs_ep_in_desc, &fs_ep_in_desc); | 846 | dev->in_ep->desc = ep_desc(dev->gadget, &fs_ep_in_desc, &hs_ep_in_desc, |
847 | &ss_ep_in_desc); | ||
797 | dev->in_ep->driver_data = dev; | 848 | dev->in_ep->driver_data = dev; |
798 | 849 | ||
799 | dev->out_ep->desc = ep_desc(dev->gadget, &hs_ep_out_desc, | 850 | dev->out_ep->desc = ep_desc(dev->gadget, &fs_ep_out_desc, |
800 | &fs_ep_out_desc); | 851 | &hs_ep_out_desc, &ss_ep_out_desc); |
801 | dev->out_ep->driver_data = dev; | 852 | dev->out_ep->driver_data = dev; |
802 | 853 | ||
803 | result = usb_ep_enable(dev->in_ep); | 854 | result = usb_ep_enable(dev->in_ep); |
@@ -1016,9 +1067,11 @@ autoconf_fail: | |||
1016 | /* assumes that all endpoints are dual-speed */ | 1067 | /* assumes that all endpoints are dual-speed */ |
1017 | hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; | 1068 | hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; |
1018 | hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; | 1069 | hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; |
1070 | ss_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; | ||
1071 | ss_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; | ||
1019 | 1072 | ||
1020 | ret = usb_assign_descriptors(f, fs_printer_function, | 1073 | ret = usb_assign_descriptors(f, fs_printer_function, |
1021 | hs_printer_function, NULL); | 1074 | hs_printer_function, ss_printer_function); |
1022 | if (ret) | 1075 | if (ret) |
1023 | return ret; | 1076 | return ret; |
1024 | 1077 | ||
@@ -1253,7 +1306,7 @@ static __refdata struct usb_composite_driver printer_driver = { | |||
1253 | .name = shortname, | 1306 | .name = shortname, |
1254 | .dev = &device_desc, | 1307 | .dev = &device_desc, |
1255 | .strings = dev_strings, | 1308 | .strings = dev_strings, |
1256 | .max_speed = USB_SPEED_HIGH, | 1309 | .max_speed = USB_SPEED_SUPER, |
1257 | .bind = printer_bind, | 1310 | .bind = printer_bind, |
1258 | .unbind = printer_unbind, | 1311 | .unbind = printer_unbind, |
1259 | }; | 1312 | }; |
diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig index 217365d35a25..b8e213eb36cc 100644 --- a/drivers/usb/gadget/udc/Kconfig +++ b/drivers/usb/gadget/udc/Kconfig | |||
@@ -241,6 +241,8 @@ config USB_M66592 | |||
241 | dynamically linked module called "m66592_udc" and force all | 241 | dynamically linked module called "m66592_udc" and force all |
242 | gadget drivers to also be dynamically linked. | 242 | gadget drivers to also be dynamically linked. |
243 | 243 | ||
244 | source "drivers/usb/gadget/udc/bdc/Kconfig" | ||
245 | |||
244 | # | 246 | # |
245 | # Controllers available only in discrete form (and all PCI controllers) | 247 | # Controllers available only in discrete form (and all PCI controllers) |
246 | # | 248 | # |
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile index a7f4491593f1..fba2049bf985 100644 --- a/drivers/usb/gadget/udc/Makefile +++ b/drivers/usb/gadget/udc/Makefile | |||
@@ -30,3 +30,4 @@ obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o | |||
30 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o | 30 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o |
31 | obj-$(CONFIG_USB_GR_UDC) += gr_udc.o | 31 | obj-$(CONFIG_USB_GR_UDC) += gr_udc.o |
32 | obj-$(CONFIG_USB_GADGET_XILINX) += udc-xilinx.o | 32 | obj-$(CONFIG_USB_GADGET_XILINX) += udc-xilinx.o |
33 | obj-$(CONFIG_USB_BDC_UDC) += bdc/ | ||
diff --git a/drivers/usb/gadget/udc/amd5536udc.c b/drivers/usb/gadget/udc/amd5536udc.c index 3b9d13848a4f..de7e5e2ccf1c 100644 --- a/drivers/usb/gadget/udc/amd5536udc.c +++ b/drivers/usb/gadget/udc/amd5536udc.c | |||
@@ -1401,9 +1401,8 @@ static int udc_wakeup(struct usb_gadget *gadget) | |||
1401 | 1401 | ||
1402 | static int amd5536_udc_start(struct usb_gadget *g, | 1402 | static int amd5536_udc_start(struct usb_gadget *g, |
1403 | struct usb_gadget_driver *driver); | 1403 | struct usb_gadget_driver *driver); |
1404 | static int amd5536_udc_stop(struct usb_gadget *g, | 1404 | static int amd5536_udc_stop(struct usb_gadget *g); |
1405 | struct usb_gadget_driver *driver); | 1405 | |
1406 | /* gadget operations */ | ||
1407 | static const struct usb_gadget_ops udc_ops = { | 1406 | static const struct usb_gadget_ops udc_ops = { |
1408 | .wakeup = udc_wakeup, | 1407 | .wakeup = udc_wakeup, |
1409 | .get_frame = udc_get_frame, | 1408 | .get_frame = udc_get_frame, |
@@ -1962,8 +1961,7 @@ __acquires(dev->lock) | |||
1962 | } | 1961 | } |
1963 | 1962 | ||
1964 | /* Called by gadget driver to unregister itself */ | 1963 | /* Called by gadget driver to unregister itself */ |
1965 | static int amd5536_udc_stop(struct usb_gadget *g, | 1964 | static int amd5536_udc_stop(struct usb_gadget *g) |
1966 | struct usb_gadget_driver *driver) | ||
1967 | { | 1965 | { |
1968 | struct udc *dev = to_amd5536_udc(g); | 1966 | struct udc *dev = to_amd5536_udc(g); |
1969 | unsigned long flags; | 1967 | unsigned long flags; |
@@ -1971,7 +1969,7 @@ static int amd5536_udc_stop(struct usb_gadget *g, | |||
1971 | 1969 | ||
1972 | spin_lock_irqsave(&dev->lock, flags); | 1970 | spin_lock_irqsave(&dev->lock, flags); |
1973 | udc_mask_unused_interrupts(dev); | 1971 | udc_mask_unused_interrupts(dev); |
1974 | shutdown(dev, driver); | 1972 | shutdown(dev, NULL); |
1975 | spin_unlock_irqrestore(&dev->lock, flags); | 1973 | spin_unlock_irqrestore(&dev->lock, flags); |
1976 | 1974 | ||
1977 | dev->driver = NULL; | 1975 | dev->driver = NULL; |
@@ -2873,7 +2871,7 @@ __acquires(dev->lock) | |||
2873 | dev->driver->resume(&dev->gadget); | 2871 | dev->driver->resume(&dev->gadget); |
2874 | dev->sys_suspended = 0; | 2872 | dev->sys_suspended = 0; |
2875 | } | 2873 | } |
2876 | dev->driver->disconnect(&dev->gadget); | 2874 | usb_gadget_udc_reset(&dev->gadget, dev->driver); |
2877 | spin_lock(&dev->lock); | 2875 | spin_lock(&dev->lock); |
2878 | 2876 | ||
2879 | /* disable ep0 to empty req queue */ | 2877 | /* disable ep0 to empty req queue */ |
diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c index 9968f5331fe4..eb2999c5d03c 100644 --- a/drivers/usb/gadget/udc/at91_udc.c +++ b/drivers/usb/gadget/udc/at91_udc.c | |||
@@ -840,6 +840,31 @@ static void udc_reinit(struct at91_udc *udc) | |||
840 | } | 840 | } |
841 | } | 841 | } |
842 | 842 | ||
843 | static void reset_gadget(struct at91_udc *udc) | ||
844 | { | ||
845 | struct usb_gadget_driver *driver = udc->driver; | ||
846 | int i; | ||
847 | |||
848 | if (udc->gadget.speed == USB_SPEED_UNKNOWN) | ||
849 | driver = NULL; | ||
850 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
851 | udc->suspended = 0; | ||
852 | |||
853 | for (i = 0; i < NUM_ENDPOINTS; i++) { | ||
854 | struct at91_ep *ep = &udc->ep[i]; | ||
855 | |||
856 | ep->stopped = 1; | ||
857 | nuke(ep, -ESHUTDOWN); | ||
858 | } | ||
859 | if (driver) { | ||
860 | spin_unlock(&udc->lock); | ||
861 | usb_gadget_udc_reset(&udc->gadget, driver); | ||
862 | spin_lock(&udc->lock); | ||
863 | } | ||
864 | |||
865 | udc_reinit(udc); | ||
866 | } | ||
867 | |||
843 | static void stop_activity(struct at91_udc *udc) | 868 | static void stop_activity(struct at91_udc *udc) |
844 | { | 869 | { |
845 | struct usb_gadget_driver *driver = udc->driver; | 870 | struct usb_gadget_driver *driver = udc->driver; |
@@ -870,12 +895,10 @@ static void clk_on(struct at91_udc *udc) | |||
870 | return; | 895 | return; |
871 | udc->clocked = 1; | 896 | udc->clocked = 1; |
872 | 897 | ||
873 | if (IS_ENABLED(CONFIG_COMMON_CLK)) { | 898 | if (IS_ENABLED(CONFIG_COMMON_CLK)) |
874 | clk_set_rate(udc->uclk, 48000000); | 899 | clk_enable(udc->uclk); |
875 | clk_prepare_enable(udc->uclk); | 900 | clk_enable(udc->iclk); |
876 | } | 901 | clk_enable(udc->fclk); |
877 | clk_prepare_enable(udc->iclk); | ||
878 | clk_prepare_enable(udc->fclk); | ||
879 | } | 902 | } |
880 | 903 | ||
881 | static void clk_off(struct at91_udc *udc) | 904 | static void clk_off(struct at91_udc *udc) |
@@ -884,10 +907,10 @@ static void clk_off(struct at91_udc *udc) | |||
884 | return; | 907 | return; |
885 | udc->clocked = 0; | 908 | udc->clocked = 0; |
886 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 909 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
887 | clk_disable_unprepare(udc->fclk); | 910 | clk_disable(udc->fclk); |
888 | clk_disable_unprepare(udc->iclk); | 911 | clk_disable(udc->iclk); |
889 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | 912 | if (IS_ENABLED(CONFIG_COMMON_CLK)) |
890 | clk_disable_unprepare(udc->uclk); | 913 | clk_disable(udc->uclk); |
891 | } | 914 | } |
892 | 915 | ||
893 | /* | 916 | /* |
@@ -984,8 +1007,8 @@ static int at91_set_selfpowered(struct usb_gadget *gadget, int is_on) | |||
984 | 1007 | ||
985 | static int at91_start(struct usb_gadget *gadget, | 1008 | static int at91_start(struct usb_gadget *gadget, |
986 | struct usb_gadget_driver *driver); | 1009 | struct usb_gadget_driver *driver); |
987 | static int at91_stop(struct usb_gadget *gadget, | 1010 | static int at91_stop(struct usb_gadget *gadget); |
988 | struct usb_gadget_driver *driver); | 1011 | |
989 | static const struct usb_gadget_ops at91_udc_ops = { | 1012 | static const struct usb_gadget_ops at91_udc_ops = { |
990 | .get_frame = at91_get_frame, | 1013 | .get_frame = at91_get_frame, |
991 | .wakeup = at91_wakeup, | 1014 | .wakeup = at91_wakeup, |
@@ -1426,7 +1449,7 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) | |||
1426 | at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_ENDBUSRES); | 1449 | at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_ENDBUSRES); |
1427 | VDBG("end bus reset\n"); | 1450 | VDBG("end bus reset\n"); |
1428 | udc->addr = 0; | 1451 | udc->addr = 0; |
1429 | stop_activity(udc); | 1452 | reset_gadget(udc); |
1430 | 1453 | ||
1431 | /* enable ep0 */ | 1454 | /* enable ep0 */ |
1432 | at91_udp_write(udc, AT91_UDP_CSR(0), | 1455 | at91_udp_write(udc, AT91_UDP_CSR(0), |
@@ -1512,20 +1535,11 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) | |||
1512 | 1535 | ||
1513 | /*-------------------------------------------------------------------------*/ | 1536 | /*-------------------------------------------------------------------------*/ |
1514 | 1537 | ||
1515 | static void nop_release(struct device *dev) | ||
1516 | { | ||
1517 | /* nothing to free */ | ||
1518 | } | ||
1519 | |||
1520 | static struct at91_udc controller = { | 1538 | static struct at91_udc controller = { |
1521 | .gadget = { | 1539 | .gadget = { |
1522 | .ops = &at91_udc_ops, | 1540 | .ops = &at91_udc_ops, |
1523 | .ep0 = &controller.ep[0].ep, | 1541 | .ep0 = &controller.ep[0].ep, |
1524 | .name = driver_name, | 1542 | .name = driver_name, |
1525 | .dev = { | ||
1526 | .init_name = "gadget", | ||
1527 | .release = nop_release, | ||
1528 | } | ||
1529 | }, | 1543 | }, |
1530 | .ep[0] = { | 1544 | .ep[0] = { |
1531 | .ep = { | 1545 | .ep = { |
@@ -1641,12 +1655,10 @@ static int at91_start(struct usb_gadget *gadget, | |||
1641 | udc->enabled = 1; | 1655 | udc->enabled = 1; |
1642 | udc->selfpowered = 1; | 1656 | udc->selfpowered = 1; |
1643 | 1657 | ||
1644 | DBG("bound to %s\n", driver->driver.name); | ||
1645 | return 0; | 1658 | return 0; |
1646 | } | 1659 | } |
1647 | 1660 | ||
1648 | static int at91_stop(struct usb_gadget *gadget, | 1661 | static int at91_stop(struct usb_gadget *gadget) |
1649 | struct usb_gadget_driver *driver) | ||
1650 | { | 1662 | { |
1651 | struct at91_udc *udc; | 1663 | struct at91_udc *udc; |
1652 | unsigned long flags; | 1664 | unsigned long flags; |
@@ -1659,7 +1671,6 @@ static int at91_stop(struct usb_gadget *gadget, | |||
1659 | 1671 | ||
1660 | udc->driver = NULL; | 1672 | udc->driver = NULL; |
1661 | 1673 | ||
1662 | DBG("unbound from %s\n", driver->driver.name); | ||
1663 | return 0; | 1674 | return 0; |
1664 | } | 1675 | } |
1665 | 1676 | ||
@@ -1780,14 +1791,24 @@ static int at91udc_probe(struct platform_device *pdev) | |||
1780 | } | 1791 | } |
1781 | 1792 | ||
1782 | /* don't do anything until we have both gadget driver and VBUS */ | 1793 | /* don't do anything until we have both gadget driver and VBUS */ |
1794 | if (IS_ENABLED(CONFIG_COMMON_CLK)) { | ||
1795 | clk_set_rate(udc->uclk, 48000000); | ||
1796 | retval = clk_prepare(udc->uclk); | ||
1797 | if (retval) | ||
1798 | goto fail1; | ||
1799 | } | ||
1800 | retval = clk_prepare(udc->fclk); | ||
1801 | if (retval) | ||
1802 | goto fail1a; | ||
1803 | |||
1783 | retval = clk_prepare_enable(udc->iclk); | 1804 | retval = clk_prepare_enable(udc->iclk); |
1784 | if (retval) | 1805 | if (retval) |
1785 | goto fail1; | 1806 | goto fail1b; |
1786 | at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); | 1807 | at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); |
1787 | at91_udp_write(udc, AT91_UDP_IDR, 0xffffffff); | 1808 | at91_udp_write(udc, AT91_UDP_IDR, 0xffffffff); |
1788 | /* Clear all pending interrupts - UDP may be used by bootloader. */ | 1809 | /* Clear all pending interrupts - UDP may be used by bootloader. */ |
1789 | at91_udp_write(udc, AT91_UDP_ICR, 0xffffffff); | 1810 | at91_udp_write(udc, AT91_UDP_ICR, 0xffffffff); |
1790 | clk_disable_unprepare(udc->iclk); | 1811 | clk_disable(udc->iclk); |
1791 | 1812 | ||
1792 | /* request UDC and maybe VBUS irqs */ | 1813 | /* request UDC and maybe VBUS irqs */ |
1793 | udc->udp_irq = platform_get_irq(pdev, 0); | 1814 | udc->udp_irq = platform_get_irq(pdev, 0); |
@@ -1795,7 +1816,7 @@ static int at91udc_probe(struct platform_device *pdev) | |||
1795 | 0, driver_name, udc); | 1816 | 0, driver_name, udc); |
1796 | if (retval < 0) { | 1817 | if (retval < 0) { |
1797 | DBG("request irq %d failed\n", udc->udp_irq); | 1818 | DBG("request irq %d failed\n", udc->udp_irq); |
1798 | goto fail1; | 1819 | goto fail1c; |
1799 | } | 1820 | } |
1800 | if (gpio_is_valid(udc->board.vbus_pin)) { | 1821 | if (gpio_is_valid(udc->board.vbus_pin)) { |
1801 | retval = gpio_request(udc->board.vbus_pin, "udc_vbus"); | 1822 | retval = gpio_request(udc->board.vbus_pin, "udc_vbus"); |
@@ -1848,6 +1869,13 @@ fail3: | |||
1848 | gpio_free(udc->board.vbus_pin); | 1869 | gpio_free(udc->board.vbus_pin); |
1849 | fail2: | 1870 | fail2: |
1850 | free_irq(udc->udp_irq, udc); | 1871 | free_irq(udc->udp_irq, udc); |
1872 | fail1c: | ||
1873 | clk_unprepare(udc->iclk); | ||
1874 | fail1b: | ||
1875 | clk_unprepare(udc->fclk); | ||
1876 | fail1a: | ||
1877 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | ||
1878 | clk_unprepare(udc->uclk); | ||
1851 | fail1: | 1879 | fail1: |
1852 | if (IS_ENABLED(CONFIG_COMMON_CLK) && !IS_ERR(udc->uclk)) | 1880 | if (IS_ENABLED(CONFIG_COMMON_CLK) && !IS_ERR(udc->uclk)) |
1853 | clk_put(udc->uclk); | 1881 | clk_put(udc->uclk); |
@@ -1896,6 +1924,11 @@ static int __exit at91udc_remove(struct platform_device *pdev) | |||
1896 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1924 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1897 | release_mem_region(res->start, resource_size(res)); | 1925 | release_mem_region(res->start, resource_size(res)); |
1898 | 1926 | ||
1927 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | ||
1928 | clk_unprepare(udc->uclk); | ||
1929 | clk_unprepare(udc->fclk); | ||
1930 | clk_unprepare(udc->iclk); | ||
1931 | |||
1899 | clk_put(udc->iclk); | 1932 | clk_put(udc->iclk); |
1900 | clk_put(udc->fclk); | 1933 | clk_put(udc->fclk); |
1901 | if (IS_ENABLED(CONFIG_COMMON_CLK)) | 1934 | if (IS_ENABLED(CONFIG_COMMON_CLK)) |
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index 1529926e20a0..b31747979c4a 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c | |||
@@ -987,8 +987,8 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered) | |||
987 | 987 | ||
988 | static int atmel_usba_start(struct usb_gadget *gadget, | 988 | static int atmel_usba_start(struct usb_gadget *gadget, |
989 | struct usb_gadget_driver *driver); | 989 | struct usb_gadget_driver *driver); |
990 | static int atmel_usba_stop(struct usb_gadget *gadget, | 990 | static int atmel_usba_stop(struct usb_gadget *gadget); |
991 | struct usb_gadget_driver *driver); | 991 | |
992 | static const struct usb_gadget_ops usba_udc_ops = { | 992 | static const struct usb_gadget_ops usba_udc_ops = { |
993 | .get_frame = usba_udc_get_frame, | 993 | .get_frame = usba_udc_get_frame, |
994 | .wakeup = usba_udc_wakeup, | 994 | .wakeup = usba_udc_wakeup, |
@@ -1007,19 +1007,10 @@ static struct usb_endpoint_descriptor usba_ep0_desc = { | |||
1007 | .bInterval = 1, | 1007 | .bInterval = 1, |
1008 | }; | 1008 | }; |
1009 | 1009 | ||
1010 | static void nop_release(struct device *dev) | ||
1011 | { | ||
1012 | |||
1013 | } | ||
1014 | |||
1015 | static struct usb_gadget usba_gadget_template = { | 1010 | static struct usb_gadget usba_gadget_template = { |
1016 | .ops = &usba_udc_ops, | 1011 | .ops = &usba_udc_ops, |
1017 | .max_speed = USB_SPEED_HIGH, | 1012 | .max_speed = USB_SPEED_HIGH, |
1018 | .name = "atmel_usba_udc", | 1013 | .name = "atmel_usba_udc", |
1019 | .dev = { | ||
1020 | .init_name = "gadget", | ||
1021 | .release = nop_release, | ||
1022 | }, | ||
1023 | }; | 1014 | }; |
1024 | 1015 | ||
1025 | /* | 1016 | /* |
@@ -1685,11 +1676,10 @@ static irqreturn_t usba_udc_irq(int irq, void *devid) | |||
1685 | usba_writel(udc, INT_CLR, USBA_END_OF_RESET); | 1676 | usba_writel(udc, INT_CLR, USBA_END_OF_RESET); |
1686 | reset_all_endpoints(udc); | 1677 | reset_all_endpoints(udc); |
1687 | 1678 | ||
1688 | if (udc->gadget.speed != USB_SPEED_UNKNOWN | 1679 | if (udc->gadget.speed != USB_SPEED_UNKNOWN && udc->driver) { |
1689 | && udc->driver && udc->driver->disconnect) { | ||
1690 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 1680 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
1691 | spin_unlock(&udc->lock); | 1681 | spin_unlock(&udc->lock); |
1692 | udc->driver->disconnect(&udc->gadget); | 1682 | usb_gadget_udc_reset(&udc->gadget, udc->driver); |
1693 | spin_lock(&udc->lock); | 1683 | spin_lock(&udc->lock); |
1694 | } | 1684 | } |
1695 | 1685 | ||
@@ -1791,8 +1781,6 @@ static int atmel_usba_start(struct usb_gadget *gadget, | |||
1791 | return ret; | 1781 | return ret; |
1792 | } | 1782 | } |
1793 | 1783 | ||
1794 | DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name); | ||
1795 | |||
1796 | udc->vbus_prev = 0; | 1784 | udc->vbus_prev = 0; |
1797 | if (gpio_is_valid(udc->vbus_pin)) | 1785 | if (gpio_is_valid(udc->vbus_pin)) |
1798 | enable_irq(gpio_to_irq(udc->vbus_pin)); | 1786 | enable_irq(gpio_to_irq(udc->vbus_pin)); |
@@ -1809,8 +1797,7 @@ static int atmel_usba_start(struct usb_gadget *gadget, | |||
1809 | return 0; | 1797 | return 0; |
1810 | } | 1798 | } |
1811 | 1799 | ||
1812 | static int atmel_usba_stop(struct usb_gadget *gadget, | 1800 | static int atmel_usba_stop(struct usb_gadget *gadget) |
1813 | struct usb_gadget_driver *driver) | ||
1814 | { | 1801 | { |
1815 | struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); | 1802 | struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); |
1816 | unsigned long flags; | 1803 | unsigned long flags; |
@@ -1830,8 +1817,6 @@ static int atmel_usba_stop(struct usb_gadget *gadget, | |||
1830 | clk_disable_unprepare(udc->hclk); | 1817 | clk_disable_unprepare(udc->hclk); |
1831 | clk_disable_unprepare(udc->pclk); | 1818 | clk_disable_unprepare(udc->pclk); |
1832 | 1819 | ||
1833 | DBG(DBG_GADGET, "unregistered driver `%s'\n", udc->driver->driver.name); | ||
1834 | |||
1835 | udc->driver = NULL; | 1820 | udc->driver = NULL; |
1836 | 1821 | ||
1837 | return 0; | 1822 | return 0; |
diff --git a/drivers/usb/gadget/udc/bcm63xx_udc.c b/drivers/usb/gadget/udc/bcm63xx_udc.c index 2235b8808700..c790918b337b 100644 --- a/drivers/usb/gadget/udc/bcm63xx_udc.c +++ b/drivers/usb/gadget/udc/bcm63xx_udc.c | |||
@@ -1836,8 +1836,7 @@ static int bcm63xx_udc_start(struct usb_gadget *gadget, | |||
1836 | * @gadget: USB slave device. | 1836 | * @gadget: USB slave device. |
1837 | * @driver: Driver for USB slave devices. | 1837 | * @driver: Driver for USB slave devices. |
1838 | */ | 1838 | */ |
1839 | static int bcm63xx_udc_stop(struct usb_gadget *gadget, | 1839 | static int bcm63xx_udc_stop(struct usb_gadget *gadget) |
1840 | struct usb_gadget_driver *driver) | ||
1841 | { | 1840 | { |
1842 | struct bcm63xx_udc *udc = gadget_to_udc(gadget); | 1841 | struct bcm63xx_udc *udc = gadget_to_udc(gadget); |
1843 | unsigned long flags; | 1842 | unsigned long flags; |
@@ -1963,7 +1962,7 @@ static irqreturn_t bcm63xx_udc_ctrl_isr(int irq, void *dev_id) | |||
1963 | { | 1962 | { |
1964 | struct bcm63xx_udc *udc = dev_id; | 1963 | struct bcm63xx_udc *udc = dev_id; |
1965 | u32 stat; | 1964 | u32 stat; |
1966 | bool disconnected = false; | 1965 | bool disconnected = false, bus_reset = false; |
1967 | 1966 | ||
1968 | stat = usbd_readl(udc, USBD_EVENT_IRQ_STATUS_REG) & | 1967 | stat = usbd_readl(udc, USBD_EVENT_IRQ_STATUS_REG) & |
1969 | usbd_readl(udc, USBD_EVENT_IRQ_MASK_REG); | 1968 | usbd_readl(udc, USBD_EVENT_IRQ_MASK_REG); |
@@ -1991,7 +1990,7 @@ static irqreturn_t bcm63xx_udc_ctrl_isr(int irq, void *dev_id) | |||
1991 | 1990 | ||
1992 | udc->ep0_req_reset = 1; | 1991 | udc->ep0_req_reset = 1; |
1993 | schedule_work(&udc->ep0_wq); | 1992 | schedule_work(&udc->ep0_wq); |
1994 | disconnected = true; | 1993 | bus_reset = true; |
1995 | } | 1994 | } |
1996 | if (stat & BIT(USBD_EVENT_IRQ_SETUP)) { | 1995 | if (stat & BIT(USBD_EVENT_IRQ_SETUP)) { |
1997 | if (bcm63xx_update_link_speed(udc)) { | 1996 | if (bcm63xx_update_link_speed(udc)) { |
@@ -2014,6 +2013,8 @@ static irqreturn_t bcm63xx_udc_ctrl_isr(int irq, void *dev_id) | |||
2014 | 2013 | ||
2015 | if (disconnected && udc->driver) | 2014 | if (disconnected && udc->driver) |
2016 | udc->driver->disconnect(&udc->gadget); | 2015 | udc->driver->disconnect(&udc->gadget); |
2016 | else if (bus_reset && udc->driver) | ||
2017 | usb_gadget_udc_reset(&udc->gadget, udc->driver); | ||
2017 | 2018 | ||
2018 | return IRQ_HANDLED; | 2019 | return IRQ_HANDLED; |
2019 | } | 2020 | } |
@@ -2324,10 +2325,8 @@ static int bcm63xx_udc_probe(struct platform_device *pdev) | |||
2324 | int rc = -ENOMEM, i, irq; | 2325 | int rc = -ENOMEM, i, irq; |
2325 | 2326 | ||
2326 | udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL); | 2327 | udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL); |
2327 | if (!udc) { | 2328 | if (!udc) |
2328 | dev_err(dev, "cannot allocate memory\n"); | ||
2329 | return -ENOMEM; | 2329 | return -ENOMEM; |
2330 | } | ||
2331 | 2330 | ||
2332 | platform_set_drvdata(pdev, udc); | 2331 | platform_set_drvdata(pdev, udc); |
2333 | udc->dev = dev; | 2332 | udc->dev = dev; |
diff --git a/drivers/usb/gadget/udc/bdc/Kconfig b/drivers/usb/gadget/udc/bdc/Kconfig new file mode 100644 index 000000000000..0d7b8c9f72fd --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/Kconfig | |||
@@ -0,0 +1,21 @@ | |||
1 | config USB_BDC_UDC | ||
2 | tristate "Broadcom USB3.0 device controller IP driver(BDC)" | ||
3 | depends on USB_GADGET && HAS_DMA | ||
4 | |||
5 | help | ||
6 | BDC is Broadcom's USB3.0 device controller IP. If your SOC has a BDC IP | ||
7 | then select this driver. | ||
8 | |||
9 | Say "y" here to link the driver statically, or "m" to build a dynamically | ||
10 | linked module called "bdc". | ||
11 | |||
12 | if USB_BDC_UDC | ||
13 | |||
14 | comment "Platform Support" | ||
15 | config USB_BDC_PCI | ||
16 | tristate "BDC support for PCIe based platforms" | ||
17 | depends on PCI | ||
18 | default USB_BDC_UDC | ||
19 | help | ||
20 | Enable support for platforms which have BDC connected through PCIe, such as Lego3 FPGA platform. | ||
21 | endif | ||
diff --git a/drivers/usb/gadget/udc/bdc/Makefile b/drivers/usb/gadget/udc/bdc/Makefile new file mode 100644 index 000000000000..5cf6a3bcdf0f --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/Makefile | |||
@@ -0,0 +1,8 @@ | |||
1 | obj-$(CONFIG_USB_BDC_UDC) += bdc.o | ||
2 | bdc-y := bdc_core.o bdc_cmd.o bdc_ep.o bdc_udc.o | ||
3 | |||
4 | ifneq ($(CONFIG_USB_GADGET_VERBOSE),) | ||
5 | bdc-y += bdc_dbg.o | ||
6 | endif | ||
7 | |||
8 | obj-$(CONFIG_USB_BDC_PCI) += bdc_pci.o | ||
diff --git a/drivers/usb/gadget/udc/bdc/bdc.h b/drivers/usb/gadget/udc/bdc/bdc.h new file mode 100644 index 000000000000..dc18a20bf040 --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/bdc.h | |||
@@ -0,0 +1,490 @@ | |||
1 | /* | ||
2 | * bdc.h - header for the BRCM BDC USB3.0 device controller | ||
3 | * | ||
4 | * Copyright (C) 2014 Broadcom Corporation | ||
5 | * | ||
6 | * Author: Ashwini Pahuja | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #ifndef __LINUX_BDC_H__ | ||
16 | #define __LINUX_BDC_H__ | ||
17 | |||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/usb.h> | ||
20 | #include <linux/device.h> | ||
21 | #include <linux/spinlock.h> | ||
22 | #include <linux/list.h> | ||
23 | #include <linux/dma-mapping.h> | ||
24 | #include <linux/mm.h> | ||
25 | #include <linux/debugfs.h> | ||
26 | #include <linux/usb/ch9.h> | ||
27 | #include <linux/usb/gadget.h> | ||
28 | #include <asm/unaligned.h> | ||
29 | |||
30 | #define BRCM_BDC_NAME "bdc_usb3" | ||
31 | #define BRCM_BDC_DESC "BDC device controller driver" | ||
32 | |||
33 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
34 | |||
35 | /* BDC command operation timeout in usec*/ | ||
36 | #define BDC_CMD_TIMEOUT 1000 | ||
37 | /* BDC controller operation timeout in usec*/ | ||
38 | #define BDC_COP_TIMEOUT 500 | ||
39 | |||
40 | /* | ||
41 | * Maximum size of ep0 response buffer for ch9 requests, | ||
42 | * the set_sel request uses 6 so far, the max. | ||
43 | */ | ||
44 | #define EP0_RESPONSE_BUFF 6 | ||
45 | /* Start with SS as default */ | ||
46 | #define EP0_MAX_PKT_SIZE 512 | ||
47 | |||
48 | /* 64 entries in a SRR */ | ||
49 | #define NUM_SR_ENTRIES 64 | ||
50 | |||
51 | /* Num of bds per table */ | ||
52 | #define NUM_BDS_PER_TABLE 32 | ||
53 | |||
54 | /* Num of tables in bd list for control,bulk and Int ep */ | ||
55 | #define NUM_TABLES 2 | ||
56 | |||
57 | /* Num of tables in bd list for Isoch ep */ | ||
58 | #define NUM_TABLES_ISOCH 6 | ||
59 | |||
60 | /* U1 Timeout default: 248usec */ | ||
61 | #define U1_TIMEOUT 0xf8 | ||
62 | |||
63 | /* Interrupt coalescence in usec */ | ||
64 | #define INT_CLS 500 | ||
65 | |||
66 | /* Register offsets */ | ||
67 | /* Configuration and Capability registers */ | ||
68 | #define BDC_BDCCFG0 0x00 | ||
69 | #define BDC_BDCCFG1 0x04 | ||
70 | #define BDC_BDCCAP0 0x08 | ||
71 | #define BDC_BDCCAP1 0x0c | ||
72 | #define BDC_CMDPAR0 0x10 | ||
73 | #define BDC_CMDPAR1 0x14 | ||
74 | #define BDC_CMDPAR2 0x18 | ||
75 | #define BDC_CMDSC 0x1c | ||
76 | #define BDC_USPC 0x20 | ||
77 | #define BDC_USPPMS 0x28 | ||
78 | #define BDC_USPPM2 0x2c | ||
79 | #define BDC_SPBBAL 0x38 | ||
80 | #define BDC_SPBBAH 0x3c | ||
81 | #define BDC_BDCSC 0x40 | ||
82 | #define BDC_XSFNTF 0x4c | ||
83 | |||
84 | #define BDC_DVCSA 0x50 | ||
85 | #define BDC_DVCSB 0x54 | ||
86 | #define BDC_EPSTS0(n) (0x60 + (n * 0x10)) | ||
87 | #define BDC_EPSTS1(n) (0x64 + (n * 0x10)) | ||
88 | #define BDC_EPSTS2(n) (0x68 + (n * 0x10)) | ||
89 | #define BDC_EPSTS3(n) (0x6c + (n * 0x10)) | ||
90 | #define BDC_EPSTS4(n) (0x70 + (n * 0x10)) | ||
91 | #define BDC_EPSTS5(n) (0x74 + (n * 0x10)) | ||
92 | #define BDC_EPSTS6(n) (0x78 + (n * 0x10)) | ||
93 | #define BDC_EPSTS7(n) (0x7c + (n * 0x10)) | ||
94 | #define BDC_SRRBAL(n) (0x200 + (n * 0x10)) | ||
95 | #define BDC_SRRBAH(n) (0x204 + (n * 0x10)) | ||
96 | #define BDC_SRRINT(n) (0x208 + (n * 0x10)) | ||
97 | #define BDC_INTCTLS(n) (0x20c + (n * 0x10)) | ||
98 | |||
99 | /* Extended capability regs */ | ||
100 | #define BDC_FSCNOC 0xcd4 | ||
101 | #define BDC_FSCNIC 0xce4 | ||
102 | #define NUM_NCS(p) (p >> 28) | ||
103 | |||
104 | /* Register bit fields and Masks */ | ||
105 | /* BDC Configuration 0 */ | ||
106 | #define BDC_PGS(p) (((p) & (0x7 << 8)) >> 8) | ||
107 | #define BDC_SPB(p) (p & 0x7) | ||
108 | |||
109 | /* BDC Capability1 */ | ||
110 | #define BDC_P64 (1 << 0) | ||
111 | |||
112 | /* BDC Command register */ | ||
113 | #define BDC_CMD_FH 0xe | ||
114 | #define BDC_CMD_DNC 0x6 | ||
115 | #define BDC_CMD_EPO 0x4 | ||
116 | #define BDC_CMD_BLA 0x3 | ||
117 | #define BDC_CMD_EPC 0x2 | ||
118 | #define BDC_CMD_DVC 0x1 | ||
119 | #define BDC_CMD_CWS (0x1 << 5) | ||
120 | #define BDC_CMD_CST(p) (((p) & (0xf << 6))>>6) | ||
121 | #define BDC_CMD_EPN(p) ((p & 0x1f) << 10) | ||
122 | #define BDC_SUB_CMD_ADD (0x1 << 17) | ||
123 | #define BDC_SUB_CMD_FWK (0x4 << 17) | ||
124 | /* Reset sequence number */ | ||
125 | #define BDC_CMD_EPO_RST_SN (0x1 << 16) | ||
126 | #define BDC_CMD_EP0_XSD (0x1 << 16) | ||
127 | #define BDC_SUB_CMD_ADD_EP (0x1 << 17) | ||
128 | #define BDC_SUB_CMD_DRP_EP (0x2 << 17) | ||
129 | #define BDC_SUB_CMD_EP_STP (0x2 << 17) | ||
130 | #define BDC_SUB_CMD_EP_STL (0x4 << 17) | ||
131 | #define BDC_SUB_CMD_EP_RST (0x1 << 17) | ||
132 | #define BDC_CMD_SRD (1 << 27) | ||
133 | |||
134 | /* CMD completion status */ | ||
135 | #define BDC_CMDS_SUCC 0x1 | ||
136 | #define BDC_CMDS_PARA 0x3 | ||
137 | #define BDC_CMDS_STAT 0x4 | ||
138 | #define BDC_CMDS_FAIL 0x5 | ||
139 | #define BDC_CMDS_INTL 0x6 | ||
140 | #define BDC_CMDS_BUSY 0xf | ||
141 | |||
142 | /* CMDSC Param 2 shifts */ | ||
143 | #define EPT_SHIFT 22 | ||
144 | #define MP_SHIFT 10 | ||
145 | #define MB_SHIFT 6 | ||
146 | #define EPM_SHIFT 4 | ||
147 | |||
148 | /* BDC USPSC */ | ||
149 | #define BDC_VBC (1 << 31) | ||
150 | #define BDC_PRC (1 << 30) | ||
151 | #define BDC_PCE (1 << 29) | ||
152 | #define BDC_CFC (1 << 28) | ||
153 | #define BDC_PCC (1 << 27) | ||
154 | #define BDC_PSC (1 << 26) | ||
155 | #define BDC_VBS (1 << 25) | ||
156 | #define BDC_PRS (1 << 24) | ||
157 | #define BDC_PCS (1 << 23) | ||
158 | #define BDC_PSP(p) (((p) & (0x7 << 20))>>20) | ||
159 | #define BDC_SCN (1 << 8) | ||
160 | #define BDC_SDC (1 << 7) | ||
161 | #define BDC_SWS (1 << 4) | ||
162 | |||
163 | #define BDC_USPSC_RW (BDC_SCN|BDC_SDC|BDC_SWS|0xf) | ||
164 | #define BDC_PSP(p) (((p) & (0x7 << 20))>>20) | ||
165 | |||
166 | #define BDC_SPEED_FS 0x1 | ||
167 | #define BDC_SPEED_LS 0x2 | ||
168 | #define BDC_SPEED_HS 0x3 | ||
169 | #define BDC_SPEED_SS 0x4 | ||
170 | |||
171 | #define BDC_PST(p) (p & 0xf) | ||
172 | #define BDC_PST_MASK 0xf | ||
173 | |||
174 | /* USPPMS */ | ||
175 | #define BDC_U2E (0x1 << 31) | ||
176 | #define BDC_U1E (0x1 << 30) | ||
177 | #define BDC_U2A (0x1 << 29) | ||
178 | #define BDC_PORT_W1S (0x1 << 17) | ||
179 | #define BDC_U1T(p) ((p) & 0xff) | ||
180 | #define BDC_U2T(p) (((p) & 0xff) << 8) | ||
181 | #define BDC_U1T_MASK 0xff | ||
182 | |||
183 | /* USBPM2 */ | ||
184 | /* Hardware LPM Enable */ | ||
185 | #define BDC_HLE (1 << 16) | ||
186 | |||
187 | /* BDC Status and Control */ | ||
188 | #define BDC_COP_RST (1 << 29) | ||
189 | #define BDC_COP_RUN (2 << 29) | ||
190 | #define BDC_COP_STP (4 << 29) | ||
191 | |||
192 | #define BDC_COP_MASK (BDC_COP_RST|BDC_COP_RUN|BDC_COP_STP) | ||
193 | |||
194 | #define BDC_COS (1 << 28) | ||
195 | #define BDC_CSTS(p) (((p) & (0x7 << 20)) >> 20) | ||
196 | #define BDC_MASK_MCW (1 << 7) | ||
197 | #define BDC_GIE (1 << 1) | ||
198 | #define BDC_GIP (1 << 0) | ||
199 | |||
200 | #define BDC_HLT 1 | ||
201 | #define BDC_NOR 2 | ||
202 | #define BDC_OIP 7 | ||
203 | |||
204 | /* Buffer descriptor and Status report bit fields and masks */ | ||
205 | #define BD_TYPE_BITMASK (0xf) | ||
206 | #define BD_CHAIN 0xf | ||
207 | |||
208 | #define BD_TFS_SHIFT 4 | ||
209 | #define BD_SOT (1 << 26) | ||
210 | #define BD_EOT (1 << 27) | ||
211 | #define BD_ISP (1 << 29) | ||
212 | #define BD_IOC (1 << 30) | ||
213 | #define BD_SBF (1 << 31) | ||
214 | |||
215 | #define BD_INTR_TARGET(p) (((p) & 0x1f) << 27) | ||
216 | |||
217 | #define BDC_SRR_RWS (1 << 4) | ||
218 | #define BDC_SRR_RST (1 << 3) | ||
219 | #define BDC_SRR_ISR (1 << 2) | ||
220 | #define BDC_SRR_IE (1 << 1) | ||
221 | #define BDC_SRR_IP (1 << 0) | ||
222 | #define BDC_SRR_EPI(p) (((p) & (0xff << 24)) >> 24) | ||
223 | #define BDC_SRR_DPI(p) (((p) & (0xff << 16)) >> 16) | ||
224 | #define BDC_SRR_DPI_MASK 0x00ff0000 | ||
225 | |||
226 | #define MARK_CHAIN_BD (BD_CHAIN|BD_EOT|BD_SOT) | ||
227 | |||
228 | /* Control transfer BD specific fields */ | ||
229 | #define BD_DIR_IN (1 << 25) | ||
230 | |||
231 | #define BDC_PTC_MASK 0xf0000000 | ||
232 | |||
233 | /* status report defines */ | ||
234 | #define SR_XSF 0 | ||
235 | #define SR_USPC 4 | ||
236 | #define SR_BD_LEN(p) (p & 0xffffff) | ||
237 | |||
238 | #define XSF_SUCC 0x1 | ||
239 | #define XSF_SHORT 0x3 | ||
240 | #define XSF_BABB 0x4 | ||
241 | #define XSF_SETUP_RECV 0x6 | ||
242 | #define XSF_DATA_START 0x7 | ||
243 | #define XSF_STATUS_START 0x8 | ||
244 | |||
245 | #define XSF_STS(p) (((p) >> 28) & 0xf) | ||
246 | |||
247 | /* Transfer BD fields */ | ||
248 | #define BD_LEN(p) ((p) & 0x1ffff) | ||
249 | #define BD_LTF (1 << 25) | ||
250 | #define BD_TYPE_DS 0x1 | ||
251 | #define BD_TYPE_SS 0x2 | ||
252 | |||
253 | #define BDC_EP_ENABLED (1 << 0) | ||
254 | #define BDC_EP_STALL (1 << 1) | ||
255 | #define BDC_EP_STOP (1 << 2) | ||
256 | |||
257 | /* One BD can transfer max 65536 bytes */ | ||
258 | #define BD_MAX_BUFF_SIZE (1 << 16) | ||
259 | /* Maximum bytes in one XFR, Refer to BDC spec */ | ||
260 | #define MAX_XFR_LEN 16777215 | ||
261 | |||
262 | /* defines for Force Header command */ | ||
263 | #define DEV_NOTF_TYPE 6 | ||
264 | #define FWK_SUBTYPE 1 | ||
265 | #define TRA_PACKET 4 | ||
266 | |||
267 | #define to_bdc_ep(e) container_of(e, struct bdc_ep, usb_ep) | ||
268 | #define to_bdc_req(r) container_of(r, struct bdc_req, usb_req) | ||
269 | #define gadget_to_bdc(g) container_of(g, struct bdc, gadget) | ||
270 | |||
271 | /* FUNCTION WAKE DEV NOTIFICATION interval, USB3 spec table 8.13 */ | ||
272 | #define BDC_TNOTIFY 2500 /*in ms*/ | ||
273 | /* Devstatus bitfields */ | ||
274 | #define REMOTE_WAKEUP_ISSUED (1 << 16) | ||
275 | #define DEVICE_SUSPENDED (1 << 17) | ||
276 | #define FUNC_WAKE_ISSUED (1 << 18) | ||
277 | #define REMOTE_WAKE_ENABLE (1 << USB_DEVICE_REMOTE_WAKEUP) | ||
278 | |||
279 | /* On disconnect, preserve these bits and clear rest */ | ||
280 | #define DEVSTATUS_CLEAR (1 << USB_DEVICE_SELF_POWERED) | ||
281 | /* Hardware and software Data structures */ | ||
282 | |||
283 | /* Endpoint bd: buffer descriptor */ | ||
284 | struct bdc_bd { | ||
285 | __le32 offset[4]; | ||
286 | }; | ||
287 | |||
288 | /* Status report in Status report ring(srr) */ | ||
289 | struct bdc_sr { | ||
290 | __le32 offset[4]; | ||
291 | }; | ||
292 | |||
293 | /* bd_table: contigous bd's in a table */ | ||
294 | struct bd_table { | ||
295 | struct bdc_bd *start_bd; | ||
296 | /* dma address of start bd of table*/ | ||
297 | dma_addr_t dma; | ||
298 | }; | ||
299 | |||
300 | /* | ||
301 | * Each endpoint has a bdl(buffer descriptor list), bdl consists of 1 or more bd | ||
302 | * table's chained to each other through a chain bd, every table has equal | ||
303 | * number of bds. the software uses bdi(bd index) to refer to particular bd in | ||
304 | * the list. | ||
305 | */ | ||
306 | struct bd_list { | ||
307 | /* Array of bd table pointers*/ | ||
308 | struct bd_table **bd_table_array; | ||
309 | /* How many tables chained to each other */ | ||
310 | int num_tabs; | ||
311 | /* Max_bdi = num_tabs * num_bds_table - 1 */ | ||
312 | int max_bdi; | ||
313 | /* current enq bdi from sw point of view */ | ||
314 | int eqp_bdi; | ||
315 | /* current deq bdi from sw point of view */ | ||
316 | int hwd_bdi; | ||
317 | /* numbers of bds per table */ | ||
318 | int num_bds_table; | ||
319 | }; | ||
320 | |||
321 | struct bdc_req; | ||
322 | |||
323 | /* Representation of a transfer, one transfer can have multiple bd's */ | ||
324 | struct bd_transfer { | ||
325 | struct bdc_req *req; | ||
326 | /* start bd index */ | ||
327 | int start_bdi; | ||
328 | /* this will be the next hw dqp when this transfer completes */ | ||
329 | int next_hwd_bdi; | ||
330 | /* number of bds in this transfer */ | ||
331 | int num_bds; | ||
332 | }; | ||
333 | |||
334 | /* | ||
335 | * Representation of a gadget request, every gadget request is contained | ||
336 | * by 1 bd_transfer. | ||
337 | */ | ||
338 | struct bdc_req { | ||
339 | struct usb_request usb_req; | ||
340 | struct list_head queue; | ||
341 | struct bdc_ep *ep; | ||
342 | /* only one Transfer per request */ | ||
343 | struct bd_transfer bd_xfr; | ||
344 | int epnum; | ||
345 | }; | ||
346 | |||
347 | /* scratchpad buffer needed by bdc hardware */ | ||
348 | struct bdc_scratchpad { | ||
349 | dma_addr_t sp_dma; | ||
350 | void *buff; | ||
351 | u32 size; | ||
352 | }; | ||
353 | |||
354 | /* endpoint representation */ | ||
355 | struct bdc_ep { | ||
356 | struct usb_ep usb_ep; | ||
357 | struct list_head queue; | ||
358 | struct bdc *bdc; | ||
359 | u8 ep_type; | ||
360 | u8 dir; | ||
361 | u8 ep_num; | ||
362 | const struct usb_ss_ep_comp_descriptor *comp_desc; | ||
363 | const struct usb_endpoint_descriptor *desc; | ||
364 | unsigned int flags; | ||
365 | char name[20]; | ||
366 | /* endpoint bd list*/ | ||
367 | struct bd_list bd_list; | ||
368 | /* | ||
369 | * HW generates extra event for multi bd tranfers, this flag helps in | ||
370 | * ignoring the extra event | ||
371 | */ | ||
372 | bool ignore_next_sr; | ||
373 | }; | ||
374 | |||
375 | /* bdc cmmand parameter structure */ | ||
376 | struct bdc_cmd_params { | ||
377 | u32 param2; | ||
378 | u32 param1; | ||
379 | u32 param0; | ||
380 | }; | ||
381 | |||
382 | /* status report ring(srr), currently one srr is supported for entire system */ | ||
383 | struct srr { | ||
384 | struct bdc_sr *sr_bds; | ||
385 | u16 eqp_index; | ||
386 | u16 dqp_index; | ||
387 | dma_addr_t dma_addr; | ||
388 | }; | ||
389 | |||
390 | /* EP0 states */ | ||
391 | enum bdc_ep0_state { | ||
392 | WAIT_FOR_SETUP = 0, | ||
393 | WAIT_FOR_DATA_START, | ||
394 | WAIT_FOR_DATA_XMIT, | ||
395 | WAIT_FOR_STATUS_START, | ||
396 | WAIT_FOR_STATUS_XMIT, | ||
397 | STATUS_PENDING | ||
398 | }; | ||
399 | |||
400 | /* Link states */ | ||
401 | enum bdc_link_state { | ||
402 | BDC_LINK_STATE_U0 = 0x00, | ||
403 | BDC_LINK_STATE_U3 = 0x03, | ||
404 | BDC_LINK_STATE_RX_DET = 0x05, | ||
405 | BDC_LINK_STATE_RESUME = 0x0f | ||
406 | }; | ||
407 | |||
408 | /* representation of bdc */ | ||
409 | struct bdc { | ||
410 | struct usb_gadget gadget; | ||
411 | struct usb_gadget_driver *gadget_driver; | ||
412 | struct device *dev; | ||
413 | /* device lock */ | ||
414 | spinlock_t lock; | ||
415 | |||
416 | /* num of endpoints for a particular instantiation of IP */ | ||
417 | unsigned int num_eps; | ||
418 | /* | ||
419 | * Array of ep's, it uses the same index covention as bdc hw i.e. | ||
420 | * 1 for ep0, 2 for 1out,3 for 1in .... | ||
421 | */ | ||
422 | struct bdc_ep **bdc_ep_array; | ||
423 | void __iomem *regs; | ||
424 | struct bdc_scratchpad scratchpad; | ||
425 | u32 sp_buff_size; | ||
426 | /* current driver supports 1 status ring */ | ||
427 | struct srr srr; | ||
428 | /* Last received setup packet */ | ||
429 | struct usb_ctrlrequest setup_pkt; | ||
430 | struct bdc_req ep0_req; | ||
431 | struct bdc_req status_req; | ||
432 | enum bdc_ep0_state ep0_state; | ||
433 | bool delayed_status; | ||
434 | bool zlp_needed; | ||
435 | bool reinit; | ||
436 | bool pullup; | ||
437 | /* Bits 0-15 are standard and 16-31 for proprietary information */ | ||
438 | u32 devstatus; | ||
439 | int irq; | ||
440 | void *mem; | ||
441 | u32 dev_addr; | ||
442 | /* DMA pools */ | ||
443 | struct dma_pool *bd_table_pool; | ||
444 | u8 test_mode; | ||
445 | /* array of callbacks for various status report handlers */ | ||
446 | void (*sr_handler[2])(struct bdc *, struct bdc_sr *); | ||
447 | /* ep0 callback handlers */ | ||
448 | void (*sr_xsf_ep0[3])(struct bdc *, struct bdc_sr *); | ||
449 | /* ep0 response buffer for ch9 requests like GET_STATUS and SET_SEL */ | ||
450 | unsigned char ep0_response_buff[EP0_RESPONSE_BUFF]; | ||
451 | /* | ||
452 | * Timer to check if host resumed transfer after bdc sent Func wake | ||
453 | * notification packet after a remote wakeup. if not, then resend the | ||
454 | * Func Wake packet every 2.5 secs. Refer to USB3 spec section 8.5.6.4 | ||
455 | */ | ||
456 | struct delayed_work func_wake_notify; | ||
457 | }; | ||
458 | |||
459 | static inline u32 bdc_readl(void __iomem *base, u32 offset) | ||
460 | { | ||
461 | return readl(base + offset); | ||
462 | } | ||
463 | |||
464 | static inline void bdc_writel(void __iomem *base, u32 offset, u32 value) | ||
465 | { | ||
466 | writel(value, base + offset); | ||
467 | } | ||
468 | |||
469 | /* Buffer descriptor list operations */ | ||
470 | void bdc_notify_xfr(struct bdc *, u32); | ||
471 | void bdc_softconn(struct bdc *); | ||
472 | void bdc_softdisconn(struct bdc *); | ||
473 | int bdc_run(struct bdc *); | ||
474 | int bdc_stop(struct bdc *); | ||
475 | int bdc_reset(struct bdc *); | ||
476 | int bdc_udc_init(struct bdc *); | ||
477 | void bdc_udc_exit(struct bdc *); | ||
478 | int bdc_reinit(struct bdc *); | ||
479 | |||
480 | /* Status report handlers */ | ||
481 | /* Upstream port status change sr */ | ||
482 | void bdc_sr_uspc(struct bdc *, struct bdc_sr *); | ||
483 | /* transfer sr */ | ||
484 | void bdc_sr_xsf(struct bdc *, struct bdc_sr *); | ||
485 | /* EP0 XSF handlers */ | ||
486 | void bdc_xsf_ep0_setup_recv(struct bdc *, struct bdc_sr *); | ||
487 | void bdc_xsf_ep0_data_start(struct bdc *, struct bdc_sr *); | ||
488 | void bdc_xsf_ep0_status_start(struct bdc *, struct bdc_sr *); | ||
489 | |||
490 | #endif /* __LINUX_BDC_H__ */ | ||
diff --git a/drivers/usb/gadget/udc/bdc/bdc_cmd.c b/drivers/usb/gadget/udc/bdc/bdc_cmd.c new file mode 100644 index 000000000000..6a4155c4bd86 --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/bdc_cmd.c | |||
@@ -0,0 +1,376 @@ | |||
1 | /* | ||
2 | * bdc_cmd.c - BRCM BDC USB3.0 device controller | ||
3 | * | ||
4 | * Copyright (C) 2014 Broadcom Corporation | ||
5 | * | ||
6 | * Author: Ashwini Pahuja | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | #include <linux/scatterlist.h> | ||
15 | #include <linux/slab.h> | ||
16 | |||
17 | #include "bdc.h" | ||
18 | #include "bdc_cmd.h" | ||
19 | #include "bdc_dbg.h" | ||
20 | |||
21 | /* Issues a cmd to cmd processor and waits for cmd completion */ | ||
22 | static int bdc_issue_cmd(struct bdc *bdc, u32 cmd_sc, u32 param0, | ||
23 | u32 param1, u32 param2) | ||
24 | { | ||
25 | u32 timeout = BDC_CMD_TIMEOUT; | ||
26 | u32 cmd_status; | ||
27 | u32 temp; | ||
28 | |||
29 | bdc_writel(bdc->regs, BDC_CMDPAR0, param0); | ||
30 | bdc_writel(bdc->regs, BDC_CMDPAR1, param1); | ||
31 | bdc_writel(bdc->regs, BDC_CMDPAR2, param2); | ||
32 | |||
33 | /* Issue the cmd */ | ||
34 | /* Make sure the cmd params are written before asking HW to exec cmd */ | ||
35 | wmb(); | ||
36 | bdc_writel(bdc->regs, BDC_CMDSC, cmd_sc | BDC_CMD_CWS | BDC_CMD_SRD); | ||
37 | do { | ||
38 | temp = bdc_readl(bdc->regs, BDC_CMDSC); | ||
39 | dev_dbg_ratelimited(bdc->dev, "cmdsc=%x", temp); | ||
40 | cmd_status = BDC_CMD_CST(temp); | ||
41 | if (cmd_status != BDC_CMDS_BUSY) { | ||
42 | dev_dbg(bdc->dev, | ||
43 | "command completed cmd_sts:%x\n", cmd_status); | ||
44 | return cmd_status; | ||
45 | } | ||
46 | udelay(1); | ||
47 | } while (timeout--); | ||
48 | |||
49 | dev_err(bdc->dev, | ||
50 | "command operation timedout cmd_status=%d\n", cmd_status); | ||
51 | |||
52 | return cmd_status; | ||
53 | } | ||
54 | |||
55 | /* Submits cmd and analyze the return value of bdc_issue_cmd */ | ||
56 | static int bdc_submit_cmd(struct bdc *bdc, u32 cmd_sc, | ||
57 | u32 param0, u32 param1, u32 param2) | ||
58 | { | ||
59 | u32 temp, cmd_status; | ||
60 | int reset_bdc = 0; | ||
61 | int ret; | ||
62 | |||
63 | temp = bdc_readl(bdc->regs, BDC_CMDSC); | ||
64 | dev_dbg(bdc->dev, | ||
65 | "%s:CMDSC:%08x cmdsc:%08x param0=%08x param1=%08x param2=%08x\n", | ||
66 | __func__, temp, cmd_sc, param0, param1, param2); | ||
67 | |||
68 | cmd_status = BDC_CMD_CST(temp); | ||
69 | if (cmd_status == BDC_CMDS_BUSY) { | ||
70 | dev_err(bdc->dev, "command processor busy: %x\n", cmd_status); | ||
71 | return -EBUSY; | ||
72 | } | ||
73 | ret = bdc_issue_cmd(bdc, cmd_sc, param0, param1, param2); | ||
74 | switch (ret) { | ||
75 | case BDC_CMDS_SUCC: | ||
76 | dev_dbg(bdc->dev, "command completed successfully\n"); | ||
77 | ret = 0; | ||
78 | break; | ||
79 | |||
80 | case BDC_CMDS_PARA: | ||
81 | dev_err(bdc->dev, "command parameter error\n"); | ||
82 | ret = -EINVAL; | ||
83 | break; | ||
84 | |||
85 | case BDC_CMDS_STAT: | ||
86 | dev_err(bdc->dev, "Invalid device/ep state\n"); | ||
87 | ret = -EINVAL; | ||
88 | break; | ||
89 | |||
90 | case BDC_CMDS_FAIL: | ||
91 | dev_err(bdc->dev, "Command failed?\n"); | ||
92 | ret = -EAGAIN; | ||
93 | break; | ||
94 | |||
95 | case BDC_CMDS_INTL: | ||
96 | dev_err(bdc->dev, "BDC Internal error\n"); | ||
97 | reset_bdc = 1; | ||
98 | ret = -ECONNRESET; | ||
99 | break; | ||
100 | |||
101 | case BDC_CMDS_BUSY: | ||
102 | dev_err(bdc->dev, | ||
103 | "command timedout waited for %dusec\n", | ||
104 | BDC_CMD_TIMEOUT); | ||
105 | reset_bdc = 1; | ||
106 | ret = -ECONNRESET; | ||
107 | break; | ||
108 | default: | ||
109 | dev_dbg(bdc->dev, "Unknown command completion code:%x\n", ret); | ||
110 | } | ||
111 | |||
112 | return ret; | ||
113 | } | ||
114 | |||
115 | /* Deconfigure the endpoint from HW */ | ||
116 | int bdc_dconfig_ep(struct bdc *bdc, struct bdc_ep *ep) | ||
117 | { | ||
118 | u32 cmd_sc; | ||
119 | |||
120 | cmd_sc = BDC_SUB_CMD_DRP_EP|BDC_CMD_EPN(ep->ep_num)|BDC_CMD_EPC; | ||
121 | dev_dbg(bdc->dev, "%s ep->ep_num =%d cmd_sc=%x\n", __func__, | ||
122 | ep->ep_num, cmd_sc); | ||
123 | |||
124 | return bdc_submit_cmd(bdc, cmd_sc, 0, 0, 0); | ||
125 | } | ||
126 | |||
127 | /* Reinitalize the bdlist after config ep command */ | ||
128 | static void ep_bd_list_reinit(struct bdc_ep *ep) | ||
129 | { | ||
130 | struct bdc *bdc = ep->bdc; | ||
131 | struct bdc_bd *bd; | ||
132 | |||
133 | ep->bd_list.eqp_bdi = 0; | ||
134 | ep->bd_list.hwd_bdi = 0; | ||
135 | bd = ep->bd_list.bd_table_array[0]->start_bd; | ||
136 | dev_dbg(bdc->dev, "%s ep:%p bd:%p\n", __func__, ep, bd); | ||
137 | memset(bd, 0, sizeof(struct bdc_bd)); | ||
138 | bd->offset[3] |= cpu_to_le32(BD_SBF); | ||
139 | } | ||
140 | |||
141 | /* Configure an endpoint */ | ||
142 | int bdc_config_ep(struct bdc *bdc, struct bdc_ep *ep) | ||
143 | { | ||
144 | const struct usb_ss_ep_comp_descriptor *comp_desc; | ||
145 | const struct usb_endpoint_descriptor *desc; | ||
146 | u32 param0, param1, param2, cmd_sc; | ||
147 | u32 mps, mbs, mul, si; | ||
148 | int ret; | ||
149 | |||
150 | desc = ep->desc; | ||
151 | comp_desc = ep->comp_desc; | ||
152 | cmd_sc = mul = mbs = param2 = 0; | ||
153 | param0 = lower_32_bits(ep->bd_list.bd_table_array[0]->dma); | ||
154 | param1 = upper_32_bits(ep->bd_list.bd_table_array[0]->dma); | ||
155 | cpu_to_le32s(¶m0); | ||
156 | cpu_to_le32s(¶m1); | ||
157 | |||
158 | dev_dbg(bdc->dev, "%s: param0=%08x param1=%08x", | ||
159 | __func__, param0, param1); | ||
160 | si = desc->bInterval; | ||
161 | si = clamp_val(si, 1, 16) - 1; | ||
162 | |||
163 | mps = usb_endpoint_maxp(desc); | ||
164 | mps &= 0x7ff; | ||
165 | param2 |= mps << MP_SHIFT; | ||
166 | param2 |= usb_endpoint_type(desc) << EPT_SHIFT; | ||
167 | |||
168 | switch (bdc->gadget.speed) { | ||
169 | case USB_SPEED_SUPER: | ||
170 | if (usb_endpoint_xfer_int(desc) || | ||
171 | usb_endpoint_xfer_isoc(desc)) { | ||
172 | param2 |= si; | ||
173 | if (usb_endpoint_xfer_isoc(desc) && comp_desc) | ||
174 | mul = comp_desc->bmAttributes; | ||
175 | |||
176 | } | ||
177 | param2 |= mul << EPM_SHIFT; | ||
178 | if (comp_desc) | ||
179 | mbs = comp_desc->bMaxBurst; | ||
180 | param2 |= mbs << MB_SHIFT; | ||
181 | break; | ||
182 | |||
183 | case USB_SPEED_HIGH: | ||
184 | if (usb_endpoint_xfer_isoc(desc) || | ||
185 | usb_endpoint_xfer_int(desc)) { | ||
186 | param2 |= si; | ||
187 | |||
188 | mbs = (usb_endpoint_maxp(desc) & 0x1800) >> 11; | ||
189 | param2 |= mbs << MB_SHIFT; | ||
190 | } | ||
191 | break; | ||
192 | |||
193 | case USB_SPEED_FULL: | ||
194 | case USB_SPEED_LOW: | ||
195 | /* the hardware accepts SI in 125usec range */ | ||
196 | if (usb_endpoint_xfer_isoc(desc)) | ||
197 | si += 3; | ||
198 | |||
199 | /* | ||
200 | * FS Int endpoints can have si of 1-255ms but the controller | ||
201 | * accepts 2^bInterval*125usec, so convert ms to nearest power | ||
202 | * of 2 | ||
203 | */ | ||
204 | if (usb_endpoint_xfer_int(desc)) | ||
205 | si = fls(desc->bInterval * 8) - 1; | ||
206 | |||
207 | param2 |= si; | ||
208 | break; | ||
209 | default: | ||
210 | dev_err(bdc->dev, "UNKNOWN speed ERR\n"); | ||
211 | return -EINVAL; | ||
212 | } | ||
213 | |||
214 | cmd_sc |= BDC_CMD_EPC|BDC_CMD_EPN(ep->ep_num)|BDC_SUB_CMD_ADD_EP; | ||
215 | |||
216 | dev_dbg(bdc->dev, "cmd_sc=%x param2=%08x\n", cmd_sc, param2); | ||
217 | ret = bdc_submit_cmd(bdc, cmd_sc, param0, param1, param2); | ||
218 | if (ret) { | ||
219 | dev_err(bdc->dev, "command failed :%x\n", ret); | ||
220 | return ret; | ||
221 | } | ||
222 | ep_bd_list_reinit(ep); | ||
223 | |||
224 | return ret; | ||
225 | } | ||
226 | |||
227 | /* | ||
228 | * Change the HW deq pointer, if this command is successful, HW will start | ||
229 | * fetching the next bd from address dma_addr. | ||
230 | */ | ||
231 | int bdc_ep_bla(struct bdc *bdc, struct bdc_ep *ep, dma_addr_t dma_addr) | ||
232 | { | ||
233 | u32 param0, param1; | ||
234 | u32 cmd_sc = 0; | ||
235 | |||
236 | dev_dbg(bdc->dev, "%s: add=%08llx\n", __func__, | ||
237 | (unsigned long long)(dma_addr)); | ||
238 | param0 = lower_32_bits(dma_addr); | ||
239 | param1 = upper_32_bits(dma_addr); | ||
240 | cpu_to_le32s(¶m0); | ||
241 | cpu_to_le32s(¶m1); | ||
242 | |||
243 | cmd_sc |= BDC_CMD_EPN(ep->ep_num)|BDC_CMD_BLA; | ||
244 | dev_dbg(bdc->dev, "cmd_sc=%x\n", cmd_sc); | ||
245 | |||
246 | return bdc_submit_cmd(bdc, cmd_sc, param0, param1, 0); | ||
247 | } | ||
248 | |||
249 | /* Set the address sent bu Host in SET_ADD request */ | ||
250 | int bdc_address_device(struct bdc *bdc, u32 add) | ||
251 | { | ||
252 | u32 cmd_sc = 0; | ||
253 | u32 param2; | ||
254 | |||
255 | dev_dbg(bdc->dev, "%s: add=%d\n", __func__, add); | ||
256 | cmd_sc |= BDC_SUB_CMD_ADD|BDC_CMD_DVC; | ||
257 | param2 = add & 0x7f; | ||
258 | |||
259 | return bdc_submit_cmd(bdc, cmd_sc, 0, 0, param2); | ||
260 | } | ||
261 | |||
262 | /* Send a Function Wake notification packet using FH command */ | ||
263 | int bdc_function_wake_fh(struct bdc *bdc, u8 intf) | ||
264 | { | ||
265 | u32 param0, param1; | ||
266 | u32 cmd_sc = 0; | ||
267 | |||
268 | param0 = param1 = 0; | ||
269 | dev_dbg(bdc->dev, "%s intf=%d\n", __func__, intf); | ||
270 | cmd_sc |= BDC_CMD_FH; | ||
271 | param0 |= TRA_PACKET; | ||
272 | param0 |= (bdc->dev_addr << 25); | ||
273 | param1 |= DEV_NOTF_TYPE; | ||
274 | param1 |= (FWK_SUBTYPE<<4); | ||
275 | dev_dbg(bdc->dev, "param0=%08x param1=%08x\n", param0, param1); | ||
276 | |||
277 | return bdc_submit_cmd(bdc, cmd_sc, param0, param1, 0); | ||
278 | } | ||
279 | |||
280 | /* Send a Function Wake notification packet using DNC command */ | ||
281 | int bdc_function_wake(struct bdc *bdc, u8 intf) | ||
282 | { | ||
283 | u32 cmd_sc = 0; | ||
284 | u32 param2 = 0; | ||
285 | |||
286 | dev_dbg(bdc->dev, "%s intf=%d", __func__, intf); | ||
287 | param2 |= intf; | ||
288 | cmd_sc |= BDC_SUB_CMD_FWK|BDC_CMD_DNC; | ||
289 | |||
290 | return bdc_submit_cmd(bdc, cmd_sc, 0, 0, param2); | ||
291 | } | ||
292 | |||
293 | /* Stall the endpoint */ | ||
294 | int bdc_ep_set_stall(struct bdc *bdc, int epnum) | ||
295 | { | ||
296 | u32 cmd_sc = 0; | ||
297 | |||
298 | dev_dbg(bdc->dev, "%s epnum=%d\n", __func__, epnum); | ||
299 | /* issue a stall endpoint command */ | ||
300 | cmd_sc |= BDC_SUB_CMD_EP_STL | BDC_CMD_EPN(epnum) | BDC_CMD_EPO; | ||
301 | |||
302 | return bdc_submit_cmd(bdc, cmd_sc, 0, 0, 0); | ||
303 | } | ||
304 | |||
305 | /* resets the endpoint, called when host sends CLEAR_FEATURE(HALT) */ | ||
306 | int bdc_ep_clear_stall(struct bdc *bdc, int epnum) | ||
307 | { | ||
308 | struct bdc_ep *ep; | ||
309 | u32 cmd_sc = 0; | ||
310 | int ret; | ||
311 | |||
312 | dev_dbg(bdc->dev, "%s: epnum=%d\n", __func__, epnum); | ||
313 | ep = bdc->bdc_ep_array[epnum]; | ||
314 | /* | ||
315 | * If we are not in stalled then stall Endpoint and issue clear stall, | ||
316 | * his will reset the seq number for non EP0. | ||
317 | */ | ||
318 | if (epnum != 1) { | ||
319 | /* if the endpoint it not stallled */ | ||
320 | if (!(ep->flags & BDC_EP_STALL)) { | ||
321 | ret = bdc_ep_set_stall(bdc, epnum); | ||
322 | if (ret) | ||
323 | return ret; | ||
324 | } | ||
325 | } | ||
326 | /* Preserve the seq number for ep0 only */ | ||
327 | if (epnum != 1) | ||
328 | cmd_sc |= BDC_CMD_EPO_RST_SN; | ||
329 | |||
330 | /* issue a reset endpoint command */ | ||
331 | cmd_sc |= BDC_SUB_CMD_EP_RST | BDC_CMD_EPN(epnum) | BDC_CMD_EPO; | ||
332 | |||
333 | ret = bdc_submit_cmd(bdc, cmd_sc, 0, 0, 0); | ||
334 | if (ret) { | ||
335 | dev_err(bdc->dev, "command failed:%x\n", ret); | ||
336 | return ret; | ||
337 | } | ||
338 | bdc_notify_xfr(bdc, epnum); | ||
339 | |||
340 | return ret; | ||
341 | } | ||
342 | |||
343 | /* Stop the endpoint, called when software wants to dequeue some request */ | ||
344 | int bdc_stop_ep(struct bdc *bdc, int epnum) | ||
345 | { | ||
346 | struct bdc_ep *ep; | ||
347 | u32 cmd_sc = 0; | ||
348 | int ret; | ||
349 | |||
350 | ep = bdc->bdc_ep_array[epnum]; | ||
351 | dev_dbg(bdc->dev, "%s: ep:%s ep->flags:%08x\n", __func__, | ||
352 | ep->name, ep->flags); | ||
353 | /* Endpoint has to be in running state to execute stop ep command */ | ||
354 | if (!(ep->flags & BDC_EP_ENABLED)) { | ||
355 | dev_err(bdc->dev, "stop endpoint called for disabled ep\n"); | ||
356 | return -EINVAL; | ||
357 | } | ||
358 | if ((ep->flags & BDC_EP_STALL) || (ep->flags & BDC_EP_STOP)) | ||
359 | return 0; | ||
360 | |||
361 | /* issue a stop endpoint command */ | ||
362 | cmd_sc |= BDC_CMD_EP0_XSD | BDC_SUB_CMD_EP_STP | ||
363 | | BDC_CMD_EPN(epnum) | BDC_CMD_EPO; | ||
364 | |||
365 | ret = bdc_submit_cmd(bdc, cmd_sc, 0, 0, 0); | ||
366 | if (ret) { | ||
367 | dev_err(bdc->dev, | ||
368 | "stop endpoint command didn't complete:%d ep:%s\n", | ||
369 | ret, ep->name); | ||
370 | return ret; | ||
371 | } | ||
372 | ep->flags |= BDC_EP_STOP; | ||
373 | bdc_dump_epsts(bdc); | ||
374 | |||
375 | return ret; | ||
376 | } | ||
diff --git a/drivers/usb/gadget/udc/bdc/bdc_cmd.h b/drivers/usb/gadget/udc/bdc/bdc_cmd.h new file mode 100644 index 000000000000..61d0e3bf9853 --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/bdc_cmd.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | * bdc_cmd.h - header for the BDC debug functions | ||
3 | * | ||
4 | * Copyright (C) 2014 Broadcom Corporation | ||
5 | * | ||
6 | * Author: Ashwini Pahuja | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | #ifndef __LINUX_BDC_CMD_H__ | ||
15 | #define __LINUX_BDC_CMD_H__ | ||
16 | |||
17 | /* Command operations */ | ||
18 | int bdc_address_device(struct bdc *, u32); | ||
19 | int bdc_config_ep(struct bdc *, struct bdc_ep *); | ||
20 | int bdc_dconfig_ep(struct bdc *, struct bdc_ep *); | ||
21 | int bdc_stop_ep(struct bdc *, int); | ||
22 | int bdc_ep_set_stall(struct bdc *, int); | ||
23 | int bdc_ep_clear_stall(struct bdc *, int); | ||
24 | int bdc_ep_set_halt(struct bdc_ep *, u32 , int); | ||
25 | int bdc_ep_bla(struct bdc *, struct bdc_ep *, dma_addr_t); | ||
26 | int bdc_function_wake(struct bdc*, u8); | ||
27 | int bdc_function_wake_fh(struct bdc*, u8); | ||
28 | |||
29 | #endif /* __LINUX_BDC_CMD_H__ */ | ||
diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c new file mode 100644 index 000000000000..c6dfef8c7bbc --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/bdc_core.c | |||
@@ -0,0 +1,533 @@ | |||
1 | /* | ||
2 | * bdc_core.c - BRCM BDC USB3.0 device controller core operations | ||
3 | * | ||
4 | * Copyright (C) 2014 Broadcom Corporation | ||
5 | * | ||
6 | * Author: Ashwini Pahuja | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/spinlock.h> | ||
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <linux/ioport.h> | ||
21 | #include <linux/io.h> | ||
22 | #include <linux/list.h> | ||
23 | #include <linux/delay.h> | ||
24 | #include <linux/dma-mapping.h> | ||
25 | #include <linux/dmapool.h> | ||
26 | #include <linux/of.h> | ||
27 | #include <linux/moduleparam.h> | ||
28 | #include <linux/usb/ch9.h> | ||
29 | #include <linux/usb/gadget.h> | ||
30 | |||
31 | #include "bdc.h" | ||
32 | #include "bdc_dbg.h" | ||
33 | |||
34 | /* Poll till controller status is not OIP */ | ||
35 | static int poll_oip(struct bdc *bdc, int usec) | ||
36 | { | ||
37 | u32 status; | ||
38 | /* Poll till STS!= OIP */ | ||
39 | while (usec) { | ||
40 | status = bdc_readl(bdc->regs, BDC_BDCSC); | ||
41 | if (BDC_CSTS(status) != BDC_OIP) { | ||
42 | dev_dbg(bdc->dev, | ||
43 | "poll_oip complete status=%d", | ||
44 | BDC_CSTS(status)); | ||
45 | return 0; | ||
46 | } | ||
47 | udelay(10); | ||
48 | usec -= 10; | ||
49 | } | ||
50 | dev_err(bdc->dev, "Err: operation timedout BDCSC: 0x%08x\n", status); | ||
51 | |||
52 | return -ETIMEDOUT; | ||
53 | } | ||
54 | |||
55 | /* Stop the BDC controller */ | ||
56 | int bdc_stop(struct bdc *bdc) | ||
57 | { | ||
58 | int ret; | ||
59 | u32 temp; | ||
60 | |||
61 | dev_dbg(bdc->dev, "%s ()\n\n", __func__); | ||
62 | temp = bdc_readl(bdc->regs, BDC_BDCSC); | ||
63 | /* Check if BDC is already halted */ | ||
64 | if (BDC_CSTS(temp) == BDC_HLT) { | ||
65 | dev_vdbg(bdc->dev, "BDC already halted\n"); | ||
66 | return 0; | ||
67 | } | ||
68 | temp &= ~BDC_COP_MASK; | ||
69 | temp |= BDC_COS|BDC_COP_STP; | ||
70 | bdc_writel(bdc->regs, BDC_BDCSC, temp); | ||
71 | |||
72 | ret = poll_oip(bdc, BDC_COP_TIMEOUT); | ||
73 | if (ret) | ||
74 | dev_err(bdc->dev, "bdc stop operation failed"); | ||
75 | |||
76 | return ret; | ||
77 | } | ||
78 | |||
79 | /* Issue a reset to BDC controller */ | ||
80 | int bdc_reset(struct bdc *bdc) | ||
81 | { | ||
82 | u32 temp; | ||
83 | int ret; | ||
84 | |||
85 | dev_dbg(bdc->dev, "%s ()\n", __func__); | ||
86 | /* First halt the controller */ | ||
87 | ret = bdc_stop(bdc); | ||
88 | if (ret) | ||
89 | return ret; | ||
90 | |||
91 | temp = bdc_readl(bdc->regs, BDC_BDCSC); | ||
92 | temp &= ~BDC_COP_MASK; | ||
93 | temp |= BDC_COS|BDC_COP_RST; | ||
94 | bdc_writel(bdc->regs, BDC_BDCSC, temp); | ||
95 | ret = poll_oip(bdc, BDC_COP_TIMEOUT); | ||
96 | if (ret) | ||
97 | dev_err(bdc->dev, "bdc reset operation failed"); | ||
98 | |||
99 | return ret; | ||
100 | } | ||
101 | |||
102 | /* Run the BDC controller */ | ||
103 | int bdc_run(struct bdc *bdc) | ||
104 | { | ||
105 | u32 temp; | ||
106 | int ret; | ||
107 | |||
108 | dev_dbg(bdc->dev, "%s ()\n", __func__); | ||
109 | temp = bdc_readl(bdc->regs, BDC_BDCSC); | ||
110 | /* if BDC is already in running state then do not do anything */ | ||
111 | if (BDC_CSTS(temp) == BDC_NOR) { | ||
112 | dev_warn(bdc->dev, "bdc is already in running state\n"); | ||
113 | return 0; | ||
114 | } | ||
115 | temp &= ~BDC_COP_MASK; | ||
116 | temp |= BDC_COP_RUN; | ||
117 | temp |= BDC_COS; | ||
118 | bdc_writel(bdc->regs, BDC_BDCSC, temp); | ||
119 | ret = poll_oip(bdc, BDC_COP_TIMEOUT); | ||
120 | if (ret) { | ||
121 | dev_err(bdc->dev, "bdc run operation failed:%d", ret); | ||
122 | return ret; | ||
123 | } | ||
124 | temp = bdc_readl(bdc->regs, BDC_BDCSC); | ||
125 | if (BDC_CSTS(temp) != BDC_NOR) { | ||
126 | dev_err(bdc->dev, "bdc not in normal mode after RUN op :%d\n", | ||
127 | BDC_CSTS(temp)); | ||
128 | return -ESHUTDOWN; | ||
129 | } | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | /* | ||
135 | * Present the termination to the host, typically called from upstream port | ||
136 | * event with Vbus present =1 | ||
137 | */ | ||
138 | void bdc_softconn(struct bdc *bdc) | ||
139 | { | ||
140 | u32 uspc; | ||
141 | |||
142 | uspc = bdc_readl(bdc->regs, BDC_USPC); | ||
143 | uspc &= ~BDC_PST_MASK; | ||
144 | uspc |= BDC_LINK_STATE_RX_DET; | ||
145 | uspc |= BDC_SWS; | ||
146 | dev_dbg(bdc->dev, "%s () uspc=%08x\n", __func__, uspc); | ||
147 | bdc_writel(bdc->regs, BDC_USPC, uspc); | ||
148 | } | ||
149 | |||
150 | /* Remove the termination */ | ||
151 | void bdc_softdisconn(struct bdc *bdc) | ||
152 | { | ||
153 | u32 uspc; | ||
154 | |||
155 | uspc = bdc_readl(bdc->regs, BDC_USPC); | ||
156 | uspc |= BDC_SDC; | ||
157 | uspc &= ~BDC_SCN; | ||
158 | dev_dbg(bdc->dev, "%s () uspc=%x\n", __func__, uspc); | ||
159 | bdc_writel(bdc->regs, BDC_USPC, uspc); | ||
160 | } | ||
161 | |||
162 | /* Set up the scratchpad buffer array and scratchpad buffers, if needed. */ | ||
163 | static int scratchpad_setup(struct bdc *bdc) | ||
164 | { | ||
165 | int sp_buff_size; | ||
166 | u32 low32; | ||
167 | u32 upp32; | ||
168 | |||
169 | sp_buff_size = BDC_SPB(bdc_readl(bdc->regs, BDC_BDCCFG0)); | ||
170 | dev_dbg(bdc->dev, "%s() sp_buff_size=%d\n", __func__, sp_buff_size); | ||
171 | if (!sp_buff_size) { | ||
172 | dev_dbg(bdc->dev, "Scratchpad buffer not needed\n"); | ||
173 | return 0; | ||
174 | } | ||
175 | /* Refer to BDC spec, Table 4 for description of SPB */ | ||
176 | sp_buff_size = 1 << (sp_buff_size + 5); | ||
177 | dev_dbg(bdc->dev, "Allocating %d bytes for scratchpad\n", sp_buff_size); | ||
178 | bdc->scratchpad.buff = dma_zalloc_coherent(bdc->dev, sp_buff_size, | ||
179 | &bdc->scratchpad.sp_dma, GFP_KERNEL); | ||
180 | |||
181 | if (!bdc->scratchpad.buff) | ||
182 | goto fail; | ||
183 | |||
184 | bdc->sp_buff_size = sp_buff_size; | ||
185 | bdc->scratchpad.size = sp_buff_size; | ||
186 | low32 = lower_32_bits(bdc->scratchpad.sp_dma); | ||
187 | upp32 = upper_32_bits(bdc->scratchpad.sp_dma); | ||
188 | cpu_to_le32s(&low32); | ||
189 | cpu_to_le32s(&upp32); | ||
190 | bdc_writel(bdc->regs, BDC_SPBBAL, low32); | ||
191 | bdc_writel(bdc->regs, BDC_SPBBAH, upp32); | ||
192 | return 0; | ||
193 | |||
194 | fail: | ||
195 | bdc->scratchpad.buff = NULL; | ||
196 | |||
197 | return -ENOMEM; | ||
198 | } | ||
199 | |||
200 | /* Allocate the status report ring */ | ||
201 | static int setup_srr(struct bdc *bdc, int interrupter) | ||
202 | { | ||
203 | dev_dbg(bdc->dev, "%s() NUM_SR_ENTRIES:%d\n", __func__, NUM_SR_ENTRIES); | ||
204 | /* Reset the SRR */ | ||
205 | bdc_writel(bdc->regs, BDC_SRRINT(0), BDC_SRR_RWS | BDC_SRR_RST); | ||
206 | bdc->srr.dqp_index = 0; | ||
207 | /* allocate the status report descriptors */ | ||
208 | bdc->srr.sr_bds = dma_zalloc_coherent( | ||
209 | bdc->dev, | ||
210 | NUM_SR_ENTRIES * sizeof(struct bdc_bd), | ||
211 | &bdc->srr.dma_addr, | ||
212 | GFP_KERNEL); | ||
213 | if (!bdc->srr.sr_bds) | ||
214 | return -ENOMEM; | ||
215 | |||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | /* Initialize the HW regs and internal data structures */ | ||
220 | static void bdc_mem_init(struct bdc *bdc, bool reinit) | ||
221 | { | ||
222 | u8 size = 0; | ||
223 | u32 usb2_pm; | ||
224 | u32 low32; | ||
225 | u32 upp32; | ||
226 | u32 temp; | ||
227 | |||
228 | dev_dbg(bdc->dev, "%s ()\n", __func__); | ||
229 | bdc->ep0_state = WAIT_FOR_SETUP; | ||
230 | bdc->dev_addr = 0; | ||
231 | bdc->srr.eqp_index = 0; | ||
232 | bdc->srr.dqp_index = 0; | ||
233 | bdc->zlp_needed = false; | ||
234 | bdc->delayed_status = false; | ||
235 | |||
236 | bdc_writel(bdc->regs, BDC_SPBBAL, bdc->scratchpad.sp_dma); | ||
237 | /* Init the SRR */ | ||
238 | temp = BDC_SRR_RWS | BDC_SRR_RST; | ||
239 | /* Reset the SRR */ | ||
240 | bdc_writel(bdc->regs, BDC_SRRINT(0), temp); | ||
241 | dev_dbg(bdc->dev, "bdc->srr.sr_bds =%p\n", bdc->srr.sr_bds); | ||
242 | temp = lower_32_bits(bdc->srr.dma_addr); | ||
243 | size = fls(NUM_SR_ENTRIES) - 2; | ||
244 | temp |= size; | ||
245 | dev_dbg(bdc->dev, "SRRBAL[0]=%08x NUM_SR_ENTRIES:%d size:%d\n", | ||
246 | temp, NUM_SR_ENTRIES, size); | ||
247 | |||
248 | low32 = lower_32_bits(temp); | ||
249 | upp32 = upper_32_bits(bdc->srr.dma_addr); | ||
250 | cpu_to_le32s(&low32); | ||
251 | cpu_to_le32s(&upp32); | ||
252 | |||
253 | /* Write the dma addresses into regs*/ | ||
254 | bdc_writel(bdc->regs, BDC_SRRBAL(0), low32); | ||
255 | bdc_writel(bdc->regs, BDC_SRRBAH(0), upp32); | ||
256 | |||
257 | temp = bdc_readl(bdc->regs, BDC_SRRINT(0)); | ||
258 | temp |= BDC_SRR_IE; | ||
259 | temp &= ~(BDC_SRR_RST | BDC_SRR_RWS); | ||
260 | bdc_writel(bdc->regs, BDC_SRRINT(0), temp); | ||
261 | |||
262 | /* Set the Interrupt Coalescence ~500 usec */ | ||
263 | temp = bdc_readl(bdc->regs, BDC_INTCTLS(0)); | ||
264 | temp &= ~0xffff; | ||
265 | temp |= INT_CLS; | ||
266 | bdc_writel(bdc->regs, BDC_INTCTLS(0), temp); | ||
267 | |||
268 | usb2_pm = bdc_readl(bdc->regs, BDC_USPPM2); | ||
269 | dev_dbg(bdc->dev, "usb2_pm=%08x", usb2_pm); | ||
270 | /* Enable hardware LPM Enable */ | ||
271 | usb2_pm |= BDC_HLE; | ||
272 | bdc_writel(bdc->regs, BDC_USPPM2, usb2_pm); | ||
273 | |||
274 | /* readback for debug */ | ||
275 | usb2_pm = bdc_readl(bdc->regs, BDC_USPPM2); | ||
276 | dev_dbg(bdc->dev, "usb2_pm=%08x\n", usb2_pm); | ||
277 | |||
278 | /* Disable any unwanted SR's on SRR */ | ||
279 | temp = bdc_readl(bdc->regs, BDC_BDCSC); | ||
280 | /* We don't want Microframe counter wrap SR */ | ||
281 | temp |= BDC_MASK_MCW; | ||
282 | bdc_writel(bdc->regs, BDC_BDCSC, temp); | ||
283 | |||
284 | /* | ||
285 | * In some error cases, driver has to reset the entire BDC controller | ||
286 | * in that case reinit is passed as 1 | ||
287 | */ | ||
288 | if (reinit) { | ||
289 | /* Enable interrupts */ | ||
290 | temp = bdc_readl(bdc->regs, BDC_BDCSC); | ||
291 | temp |= BDC_GIE; | ||
292 | bdc_writel(bdc->regs, BDC_BDCSC, temp); | ||
293 | /* Init scratchpad to 0 */ | ||
294 | memset(bdc->scratchpad.buff, 0, bdc->sp_buff_size); | ||
295 | /* Initialize SRR to 0 */ | ||
296 | memset(bdc->srr.sr_bds, 0, | ||
297 | NUM_SR_ENTRIES * sizeof(struct bdc_bd)); | ||
298 | } else { | ||
299 | /* One time initiaization only */ | ||
300 | /* Enable status report function pointers */ | ||
301 | bdc->sr_handler[0] = bdc_sr_xsf; | ||
302 | bdc->sr_handler[1] = bdc_sr_uspc; | ||
303 | |||
304 | /* EP0 status report function pointers */ | ||
305 | bdc->sr_xsf_ep0[0] = bdc_xsf_ep0_setup_recv; | ||
306 | bdc->sr_xsf_ep0[1] = bdc_xsf_ep0_data_start; | ||
307 | bdc->sr_xsf_ep0[2] = bdc_xsf_ep0_status_start; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | /* Free the dynamic memory */ | ||
312 | static void bdc_mem_free(struct bdc *bdc) | ||
313 | { | ||
314 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
315 | /* Free SRR */ | ||
316 | if (bdc->srr.sr_bds) | ||
317 | dma_free_coherent(bdc->dev, | ||
318 | NUM_SR_ENTRIES * sizeof(struct bdc_bd), | ||
319 | bdc->srr.sr_bds, bdc->srr.dma_addr); | ||
320 | |||
321 | /* Free scratchpad */ | ||
322 | if (bdc->scratchpad.buff) | ||
323 | dma_free_coherent(bdc->dev, bdc->sp_buff_size, | ||
324 | bdc->scratchpad.buff, bdc->scratchpad.sp_dma); | ||
325 | |||
326 | /* Destroy the dma pools */ | ||
327 | if (bdc->bd_table_pool) | ||
328 | dma_pool_destroy(bdc->bd_table_pool); | ||
329 | |||
330 | /* Free the bdc_ep array */ | ||
331 | kfree(bdc->bdc_ep_array); | ||
332 | |||
333 | bdc->srr.sr_bds = NULL; | ||
334 | bdc->scratchpad.buff = NULL; | ||
335 | bdc->bd_table_pool = NULL; | ||
336 | bdc->bdc_ep_array = NULL; | ||
337 | } | ||
338 | |||
339 | /* | ||
340 | * bdc reinit gives a controller reset and reinitialize the registers, | ||
341 | * called from disconnect/bus reset scenario's, to ensure proper HW cleanup | ||
342 | */ | ||
343 | int bdc_reinit(struct bdc *bdc) | ||
344 | { | ||
345 | int ret; | ||
346 | |||
347 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
348 | ret = bdc_stop(bdc); | ||
349 | if (ret) | ||
350 | goto out; | ||
351 | |||
352 | ret = bdc_reset(bdc); | ||
353 | if (ret) | ||
354 | goto out; | ||
355 | |||
356 | /* the reinit flag is 1 */ | ||
357 | bdc_mem_init(bdc, true); | ||
358 | ret = bdc_run(bdc); | ||
359 | out: | ||
360 | bdc->reinit = false; | ||
361 | |||
362 | return ret; | ||
363 | } | ||
364 | |||
365 | /* Allocate all the dyanmic memory */ | ||
366 | static int bdc_mem_alloc(struct bdc *bdc) | ||
367 | { | ||
368 | u32 page_size; | ||
369 | unsigned int num_ieps, num_oeps; | ||
370 | |||
371 | dev_dbg(bdc->dev, | ||
372 | "%s() NUM_BDS_PER_TABLE:%d\n", __func__, | ||
373 | NUM_BDS_PER_TABLE); | ||
374 | page_size = BDC_PGS(bdc_readl(bdc->regs, BDC_BDCCFG0)); | ||
375 | /* page size is 2^pgs KB */ | ||
376 | page_size = 1 << page_size; | ||
377 | /* KB */ | ||
378 | page_size <<= 10; | ||
379 | dev_dbg(bdc->dev, "page_size=%d\n", page_size); | ||
380 | |||
381 | /* Create a pool of bd tables */ | ||
382 | bdc->bd_table_pool = | ||
383 | dma_pool_create("BDC BD tables", bdc->dev, NUM_BDS_PER_TABLE * 16, | ||
384 | 16, page_size); | ||
385 | |||
386 | if (!bdc->bd_table_pool) | ||
387 | goto fail; | ||
388 | |||
389 | if (scratchpad_setup(bdc)) | ||
390 | goto fail; | ||
391 | |||
392 | /* read from regs */ | ||
393 | num_ieps = NUM_NCS(bdc_readl(bdc->regs, BDC_FSCNIC)); | ||
394 | num_oeps = NUM_NCS(bdc_readl(bdc->regs, BDC_FSCNOC)); | ||
395 | /* +2: 1 for ep0 and the other is rsvd i.e. bdc_ep[0] is rsvd */ | ||
396 | bdc->num_eps = num_ieps + num_oeps + 2; | ||
397 | dev_dbg(bdc->dev, | ||
398 | "ieps:%d eops:%d num_eps:%d\n", | ||
399 | num_ieps, num_oeps, bdc->num_eps); | ||
400 | /* allocate array of ep pointers */ | ||
401 | bdc->bdc_ep_array = kcalloc(bdc->num_eps, sizeof(struct bdc_ep *), | ||
402 | GFP_KERNEL); | ||
403 | if (!bdc->bdc_ep_array) | ||
404 | goto fail; | ||
405 | |||
406 | dev_dbg(bdc->dev, "Allocating sr report0\n"); | ||
407 | if (setup_srr(bdc, 0)) | ||
408 | goto fail; | ||
409 | |||
410 | return 0; | ||
411 | fail: | ||
412 | dev_warn(bdc->dev, "Couldn't initialize memory\n"); | ||
413 | bdc_mem_free(bdc); | ||
414 | |||
415 | return -ENOMEM; | ||
416 | } | ||
417 | |||
418 | /* opposite to bdc_hw_init */ | ||
419 | static void bdc_hw_exit(struct bdc *bdc) | ||
420 | { | ||
421 | dev_dbg(bdc->dev, "%s ()\n", __func__); | ||
422 | bdc_mem_free(bdc); | ||
423 | } | ||
424 | |||
425 | /* Initialize the bdc HW and memory */ | ||
426 | static int bdc_hw_init(struct bdc *bdc) | ||
427 | { | ||
428 | int ret; | ||
429 | |||
430 | dev_dbg(bdc->dev, "%s ()\n", __func__); | ||
431 | ret = bdc_reset(bdc); | ||
432 | if (ret) { | ||
433 | dev_err(bdc->dev, "err resetting bdc abort bdc init%d\n", ret); | ||
434 | return ret; | ||
435 | } | ||
436 | ret = bdc_mem_alloc(bdc); | ||
437 | if (ret) { | ||
438 | dev_err(bdc->dev, "Mem alloc failed, aborting\n"); | ||
439 | return -ENOMEM; | ||
440 | } | ||
441 | bdc_mem_init(bdc, 0); | ||
442 | bdc_dbg_regs(bdc); | ||
443 | dev_dbg(bdc->dev, "HW Init done\n"); | ||
444 | |||
445 | return 0; | ||
446 | } | ||
447 | |||
448 | static int bdc_probe(struct platform_device *pdev) | ||
449 | { | ||
450 | struct bdc *bdc; | ||
451 | struct resource *res; | ||
452 | int ret = -ENOMEM; | ||
453 | int irq; | ||
454 | u32 temp; | ||
455 | struct device *dev = &pdev->dev; | ||
456 | |||
457 | dev_dbg(dev, "%s()\n", __func__); | ||
458 | bdc = devm_kzalloc(dev, sizeof(*bdc), GFP_KERNEL); | ||
459 | if (!bdc) | ||
460 | return -ENOMEM; | ||
461 | |||
462 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
463 | bdc->regs = devm_ioremap_resource(dev, res); | ||
464 | if (IS_ERR(bdc->regs)) { | ||
465 | dev_err(dev, "ioremap error\n"); | ||
466 | return -ENOMEM; | ||
467 | } | ||
468 | irq = platform_get_irq(pdev, 0); | ||
469 | if (irq < 0) { | ||
470 | dev_err(dev, "platform_get_irq failed:%d\n", irq); | ||
471 | return irq; | ||
472 | } | ||
473 | spin_lock_init(&bdc->lock); | ||
474 | platform_set_drvdata(pdev, bdc); | ||
475 | bdc->irq = irq; | ||
476 | bdc->dev = dev; | ||
477 | dev_dbg(bdc->dev, "bdc->regs: %p irq=%d\n", bdc->regs, bdc->irq); | ||
478 | |||
479 | temp = bdc_readl(bdc->regs, BDC_BDCSC); | ||
480 | if ((temp & BDC_P64) && | ||
481 | !dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) { | ||
482 | dev_dbg(bdc->dev, "Using 64-bit address\n"); | ||
483 | } else { | ||
484 | ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); | ||
485 | if (ret) { | ||
486 | dev_err(bdc->dev, "No suitable DMA config available, abort\n"); | ||
487 | return -ENOTSUPP; | ||
488 | } | ||
489 | dev_dbg(bdc->dev, "Using 32-bit address\n"); | ||
490 | } | ||
491 | ret = bdc_hw_init(bdc); | ||
492 | if (ret) { | ||
493 | dev_err(bdc->dev, "BDC init failure:%d\n", ret); | ||
494 | return ret; | ||
495 | } | ||
496 | ret = bdc_udc_init(bdc); | ||
497 | if (ret) { | ||
498 | dev_err(bdc->dev, "BDC Gadget init failure:%d\n", ret); | ||
499 | goto cleanup; | ||
500 | } | ||
501 | return 0; | ||
502 | |||
503 | cleanup: | ||
504 | bdc_hw_exit(bdc); | ||
505 | |||
506 | return ret; | ||
507 | } | ||
508 | |||
509 | static int bdc_remove(struct platform_device *pdev) | ||
510 | { | ||
511 | struct bdc *bdc; | ||
512 | |||
513 | bdc = platform_get_drvdata(pdev); | ||
514 | dev_dbg(bdc->dev, "%s ()\n", __func__); | ||
515 | bdc_udc_exit(bdc); | ||
516 | bdc_hw_exit(bdc); | ||
517 | |||
518 | return 0; | ||
519 | } | ||
520 | |||
521 | static struct platform_driver bdc_driver = { | ||
522 | .driver = { | ||
523 | .name = BRCM_BDC_NAME, | ||
524 | .owner = THIS_MODULE | ||
525 | }, | ||
526 | .probe = bdc_probe, | ||
527 | .remove = bdc_remove, | ||
528 | }; | ||
529 | |||
530 | module_platform_driver(bdc_driver); | ||
531 | MODULE_AUTHOR("Ashwini Pahuja <ashwini.linux@gmail.com>"); | ||
532 | MODULE_LICENSE("GPL"); | ||
533 | MODULE_DESCRIPTION(BRCM_BDC_DESC); | ||
diff --git a/drivers/usb/gadget/udc/bdc/bdc_dbg.c b/drivers/usb/gadget/udc/bdc/bdc_dbg.c new file mode 100644 index 000000000000..5945dbc47825 --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/bdc_dbg.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | * bdc_dbg.c - BRCM BDC USB3.0 device controller debug functions | ||
3 | * | ||
4 | * Copyright (C) 2014 Broadcom Corporation | ||
5 | * | ||
6 | * Author: Ashwini Pahuja | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include "bdc.h" | ||
16 | #include "bdc_dbg.h" | ||
17 | |||
18 | void bdc_dbg_regs(struct bdc *bdc) | ||
19 | { | ||
20 | u32 temp; | ||
21 | |||
22 | dev_vdbg(bdc->dev, "bdc->regs:%p\n", bdc->regs); | ||
23 | temp = bdc_readl(bdc->regs, BDC_BDCCFG0); | ||
24 | dev_vdbg(bdc->dev, "bdccfg0:0x%08x\n", temp); | ||
25 | temp = bdc_readl(bdc->regs, BDC_BDCCFG1); | ||
26 | dev_vdbg(bdc->dev, "bdccfg1:0x%08x\n", temp); | ||
27 | temp = bdc_readl(bdc->regs, BDC_BDCCAP0); | ||
28 | dev_vdbg(bdc->dev, "bdccap0:0x%08x\n", temp); | ||
29 | temp = bdc_readl(bdc->regs, BDC_BDCCAP1); | ||
30 | dev_vdbg(bdc->dev, "bdccap1:0x%08x\n", temp); | ||
31 | temp = bdc_readl(bdc->regs, BDC_USPC); | ||
32 | dev_vdbg(bdc->dev, "uspc:0x%08x\n", temp); | ||
33 | temp = bdc_readl(bdc->regs, BDC_DVCSA); | ||
34 | dev_vdbg(bdc->dev, "dvcsa:0x%08x\n", temp); | ||
35 | temp = bdc_readl(bdc->regs, BDC_DVCSB); | ||
36 | dev_vdbg(bdc->dev, "dvcsb:0x%x08\n", temp); | ||
37 | } | ||
38 | |||
39 | void bdc_dump_epsts(struct bdc *bdc) | ||
40 | { | ||
41 | u32 temp; | ||
42 | |||
43 | temp = bdc_readl(bdc->regs, BDC_EPSTS0(0)); | ||
44 | dev_vdbg(bdc->dev, "BDC_EPSTS0:0x%08x\n", temp); | ||
45 | |||
46 | temp = bdc_readl(bdc->regs, BDC_EPSTS1(0)); | ||
47 | dev_vdbg(bdc->dev, "BDC_EPSTS1:0x%x\n", temp); | ||
48 | |||
49 | temp = bdc_readl(bdc->regs, BDC_EPSTS2(0)); | ||
50 | dev_vdbg(bdc->dev, "BDC_EPSTS2:0x%08x\n", temp); | ||
51 | |||
52 | temp = bdc_readl(bdc->regs, BDC_EPSTS3(0)); | ||
53 | dev_vdbg(bdc->dev, "BDC_EPSTS3:0x%08x\n", temp); | ||
54 | |||
55 | temp = bdc_readl(bdc->regs, BDC_EPSTS4(0)); | ||
56 | dev_vdbg(bdc->dev, "BDC_EPSTS4:0x%08x\n", temp); | ||
57 | |||
58 | temp = bdc_readl(bdc->regs, BDC_EPSTS5(0)); | ||
59 | dev_vdbg(bdc->dev, "BDC_EPSTS5:0x%08x\n", temp); | ||
60 | |||
61 | temp = bdc_readl(bdc->regs, BDC_EPSTS6(0)); | ||
62 | dev_vdbg(bdc->dev, "BDC_EPSTS6:0x%08x\n", temp); | ||
63 | |||
64 | temp = bdc_readl(bdc->regs, BDC_EPSTS7(0)); | ||
65 | dev_vdbg(bdc->dev, "BDC_EPSTS7:0x%08x\n", temp); | ||
66 | } | ||
67 | |||
68 | void bdc_dbg_srr(struct bdc *bdc, u32 srr_num) | ||
69 | { | ||
70 | struct bdc_sr *sr; | ||
71 | dma_addr_t addr; | ||
72 | int i; | ||
73 | |||
74 | sr = bdc->srr.sr_bds; | ||
75 | addr = bdc->srr.dma_addr; | ||
76 | dev_vdbg(bdc->dev, "bdc_dbg_srr sr:%p dqp_index:%d\n", | ||
77 | sr, bdc->srr.dqp_index); | ||
78 | for (i = 0; i < NUM_SR_ENTRIES; i++) { | ||
79 | sr = &bdc->srr.sr_bds[i]; | ||
80 | dev_vdbg(bdc->dev, "%llx %08x %08x %08x %08x\n", | ||
81 | (unsigned long long)addr, | ||
82 | le32_to_cpu(sr->offset[0]), | ||
83 | le32_to_cpu(sr->offset[1]), | ||
84 | le32_to_cpu(sr->offset[2]), | ||
85 | le32_to_cpu(sr->offset[3])); | ||
86 | addr += sizeof(*sr); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | void bdc_dbg_bd_list(struct bdc *bdc, struct bdc_ep *ep) | ||
91 | { | ||
92 | struct bd_list *bd_list = &ep->bd_list; | ||
93 | struct bd_table *bd_table; | ||
94 | struct bdc_bd *bd; | ||
95 | int tbi, bdi, gbdi; | ||
96 | dma_addr_t dma; | ||
97 | |||
98 | gbdi = 0; | ||
99 | dev_vdbg(bdc->dev, | ||
100 | "Dump bd list for %s epnum:%d\n", | ||
101 | ep->name, ep->ep_num); | ||
102 | |||
103 | dev_vdbg(bdc->dev, | ||
104 | "tabs:%d max_bdi:%d eqp_bdi:%d hwd_bdi:%d num_bds_table:%d\n", | ||
105 | bd_list->num_tabs, bd_list->max_bdi, bd_list->eqp_bdi, | ||
106 | bd_list->hwd_bdi, bd_list->num_bds_table); | ||
107 | |||
108 | for (tbi = 0; tbi < bd_list->num_tabs; tbi++) { | ||
109 | bd_table = bd_list->bd_table_array[tbi]; | ||
110 | for (bdi = 0; bdi < bd_list->num_bds_table; bdi++) { | ||
111 | bd = bd_table->start_bd + bdi; | ||
112 | dma = bd_table->dma + (sizeof(struct bdc_bd) * bdi); | ||
113 | dev_vdbg(bdc->dev, | ||
114 | "tbi:%2d bdi:%2d gbdi:%2d virt:%p phys:%llx %08x %08x %08x %08x\n", | ||
115 | tbi, bdi, gbdi++, bd, (unsigned long long)dma, | ||
116 | le32_to_cpu(bd->offset[0]), | ||
117 | le32_to_cpu(bd->offset[1]), | ||
118 | le32_to_cpu(bd->offset[2]), | ||
119 | le32_to_cpu(bd->offset[3])); | ||
120 | } | ||
121 | dev_vdbg(bdc->dev, "\n\n"); | ||
122 | } | ||
123 | } | ||
diff --git a/drivers/usb/gadget/udc/bdc/bdc_dbg.h b/drivers/usb/gadget/udc/bdc/bdc_dbg.h new file mode 100644 index 000000000000..338a6c701315 --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/bdc_dbg.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * bdc_dbg.h - header for the BDC debug functions | ||
3 | * | ||
4 | * Copyright (C) 2014 Broadcom Corporation | ||
5 | * | ||
6 | * Author: Ashwini Pahuja | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | #ifndef __LINUX_BDC_DBG_H__ | ||
15 | #define __LINUX_BDC_DBG_H__ | ||
16 | |||
17 | #include "bdc.h" | ||
18 | |||
19 | #ifdef CONFIG_USB_GADGET_VERBOSE | ||
20 | void bdc_dbg_bd_list(struct bdc *, struct bdc_ep*); | ||
21 | void bdc_dbg_srr(struct bdc *, u32); | ||
22 | void bdc_dbg_regs(struct bdc *); | ||
23 | void bdc_dump_epsts(struct bdc *); | ||
24 | #else | ||
25 | static inline void bdc_dbg_regs(struct bdc *bdc) | ||
26 | { } | ||
27 | |||
28 | static inline void bdc_dbg_srr(struct bdc *bdc, u32 srr_num) | ||
29 | { } | ||
30 | |||
31 | static inline void bdc_dbg_bd_list(struct bdc *bdc, struct bdc_ep *ep) | ||
32 | { } | ||
33 | |||
34 | static inline void bdc_dump_epsts(struct bdc *bdc) | ||
35 | { } | ||
36 | #endif /* CONFIG_USB_GADGET_VERBOSE */ | ||
37 | #endif /* __LINUX_BDC_DBG_H__ */ | ||
diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c b/drivers/usb/gadget/udc/bdc/bdc_ep.c new file mode 100644 index 000000000000..15da5b1e76c0 --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c | |||
@@ -0,0 +1,2023 @@ | |||
1 | /* | ||
2 | * bdc_ep.c - BRCM BDC USB3.0 device controller endpoint related functions | ||
3 | * | ||
4 | * Copyright (C) 2014 Broadcom Corporation | ||
5 | * | ||
6 | * Author: Ashwini Pahuja | ||
7 | * | ||
8 | * Based on drivers under drivers/usb/ | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | */ | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/pci.h> | ||
18 | #include <linux/dma-mapping.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/dmapool.h> | ||
22 | #include <linux/ioport.h> | ||
23 | #include <linux/sched.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/errno.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/timer.h> | ||
28 | #include <linux/list.h> | ||
29 | #include <linux/interrupt.h> | ||
30 | #include <linux/moduleparam.h> | ||
31 | #include <linux/device.h> | ||
32 | #include <linux/usb/ch9.h> | ||
33 | #include <linux/usb/gadget.h> | ||
34 | #include <linux/usb/otg.h> | ||
35 | #include <linux/pm.h> | ||
36 | #include <linux/io.h> | ||
37 | #include <linux/irq.h> | ||
38 | #include <asm/unaligned.h> | ||
39 | #include <linux/platform_device.h> | ||
40 | #include <linux/usb/composite.h> | ||
41 | |||
42 | #include "bdc.h" | ||
43 | #include "bdc_ep.h" | ||
44 | #include "bdc_cmd.h" | ||
45 | #include "bdc_dbg.h" | ||
46 | |||
47 | static const char * const ep0_state_string[] = { | ||
48 | "WAIT_FOR_SETUP", | ||
49 | "WAIT_FOR_DATA_START", | ||
50 | "WAIT_FOR_DATA_XMIT", | ||
51 | "WAIT_FOR_STATUS_START", | ||
52 | "WAIT_FOR_STATUS_XMIT", | ||
53 | "STATUS_PENDING" | ||
54 | }; | ||
55 | |||
56 | /* Free the bdl during ep disable */ | ||
57 | static void ep_bd_list_free(struct bdc_ep *ep, u32 num_tabs) | ||
58 | { | ||
59 | struct bd_list *bd_list = &ep->bd_list; | ||
60 | struct bdc *bdc = ep->bdc; | ||
61 | struct bd_table *bd_table; | ||
62 | int index; | ||
63 | |||
64 | dev_dbg(bdc->dev, "%s ep:%s num_tabs:%d\n", | ||
65 | __func__, ep->name, num_tabs); | ||
66 | |||
67 | if (!bd_list->bd_table_array) { | ||
68 | dev_dbg(bdc->dev, "%s already freed\n", ep->name); | ||
69 | return; | ||
70 | } | ||
71 | for (index = 0; index < num_tabs; index++) { | ||
72 | /* | ||
73 | * check if the bd_table struct is allocated ? | ||
74 | * if yes, then check if bd memory has been allocated, then | ||
75 | * free the dma_pool and also the bd_table struct memory | ||
76 | */ | ||
77 | bd_table = bd_list->bd_table_array[index]; | ||
78 | dev_dbg(bdc->dev, "bd_table:%p index:%d\n", bd_table, index); | ||
79 | if (!bd_table) { | ||
80 | dev_dbg(bdc->dev, "bd_table not allocated\n"); | ||
81 | continue; | ||
82 | } | ||
83 | if (!bd_table->start_bd) { | ||
84 | dev_dbg(bdc->dev, "bd dma pool not allocted\n"); | ||
85 | continue; | ||
86 | } | ||
87 | |||
88 | dev_dbg(bdc->dev, | ||
89 | "Free dma pool start_bd:%p dma:%llx\n", | ||
90 | bd_table->start_bd, | ||
91 | (unsigned long long)bd_table->dma); | ||
92 | |||
93 | dma_pool_free(bdc->bd_table_pool, | ||
94 | bd_table->start_bd, | ||
95 | bd_table->dma); | ||
96 | /* Free the bd_table structure */ | ||
97 | kfree(bd_table); | ||
98 | } | ||
99 | /* Free the bd table array */ | ||
100 | kfree(ep->bd_list.bd_table_array); | ||
101 | } | ||
102 | |||
103 | /* | ||
104 | * chain the tables, by insteting a chain bd at the end of prev_table, pointing | ||
105 | * to next_table | ||
106 | */ | ||
107 | static inline void chain_table(struct bd_table *prev_table, | ||
108 | struct bd_table *next_table, | ||
109 | u32 bd_p_tab) | ||
110 | { | ||
111 | /* Chain the prev table to next table */ | ||
112 | prev_table->start_bd[bd_p_tab-1].offset[0] = | ||
113 | cpu_to_le32(lower_32_bits(next_table->dma)); | ||
114 | |||
115 | prev_table->start_bd[bd_p_tab-1].offset[1] = | ||
116 | cpu_to_le32(upper_32_bits(next_table->dma)); | ||
117 | |||
118 | prev_table->start_bd[bd_p_tab-1].offset[2] = | ||
119 | 0x0; | ||
120 | |||
121 | prev_table->start_bd[bd_p_tab-1].offset[3] = | ||
122 | cpu_to_le32(MARK_CHAIN_BD); | ||
123 | } | ||
124 | |||
125 | /* Allocate the bdl for ep, during config ep */ | ||
126 | static int ep_bd_list_alloc(struct bdc_ep *ep) | ||
127 | { | ||
128 | struct bd_table *prev_table = NULL; | ||
129 | int index, num_tabs, bd_p_tab; | ||
130 | struct bdc *bdc = ep->bdc; | ||
131 | struct bd_table *bd_table; | ||
132 | dma_addr_t dma; | ||
133 | |||
134 | if (usb_endpoint_xfer_isoc(ep->desc)) | ||
135 | num_tabs = NUM_TABLES_ISOCH; | ||
136 | else | ||
137 | num_tabs = NUM_TABLES; | ||
138 | |||
139 | bd_p_tab = NUM_BDS_PER_TABLE; | ||
140 | /* if there is only 1 table in bd list then loop chain to self */ | ||
141 | dev_dbg(bdc->dev, | ||
142 | "%s ep:%p num_tabs:%d\n", | ||
143 | __func__, ep, num_tabs); | ||
144 | |||
145 | /* Allocate memory for table array */ | ||
146 | ep->bd_list.bd_table_array = kzalloc( | ||
147 | num_tabs * sizeof(struct bd_table *), | ||
148 | GFP_ATOMIC); | ||
149 | if (!ep->bd_list.bd_table_array) | ||
150 | return -ENOMEM; | ||
151 | |||
152 | /* Allocate memory for each table */ | ||
153 | for (index = 0; index < num_tabs; index++) { | ||
154 | /* Allocate memory for bd_table structure */ | ||
155 | bd_table = kzalloc(sizeof(struct bd_table), GFP_ATOMIC); | ||
156 | if (!bd_table) | ||
157 | goto fail; | ||
158 | |||
159 | bd_table->start_bd = dma_pool_alloc(bdc->bd_table_pool, | ||
160 | GFP_ATOMIC, | ||
161 | &dma); | ||
162 | if (!bd_table->start_bd) | ||
163 | goto fail; | ||
164 | |||
165 | bd_table->dma = dma; | ||
166 | |||
167 | dev_dbg(bdc->dev, | ||
168 | "index:%d start_bd:%p dma=%08llx prev_table:%p\n", | ||
169 | index, bd_table->start_bd, | ||
170 | (unsigned long long)bd_table->dma, prev_table); | ||
171 | |||
172 | ep->bd_list.bd_table_array[index] = bd_table; | ||
173 | memset(bd_table->start_bd, 0, bd_p_tab * sizeof(struct bdc_bd)); | ||
174 | if (prev_table) | ||
175 | chain_table(prev_table, bd_table, bd_p_tab); | ||
176 | |||
177 | prev_table = bd_table; | ||
178 | } | ||
179 | chain_table(prev_table, ep->bd_list.bd_table_array[0], bd_p_tab); | ||
180 | /* Memory allocation is successful, now init the internal fields */ | ||
181 | ep->bd_list.num_tabs = num_tabs; | ||
182 | ep->bd_list.max_bdi = (num_tabs * bd_p_tab) - 1; | ||
183 | ep->bd_list.num_tabs = num_tabs; | ||
184 | ep->bd_list.num_bds_table = bd_p_tab; | ||
185 | ep->bd_list.eqp_bdi = 0; | ||
186 | ep->bd_list.hwd_bdi = 0; | ||
187 | |||
188 | return 0; | ||
189 | fail: | ||
190 | /* Free the bd_table_array, bd_table struct, bd's */ | ||
191 | ep_bd_list_free(ep, num_tabs); | ||
192 | |||
193 | return -ENOMEM; | ||
194 | } | ||
195 | |||
196 | /* returns how many bd's are need for this transfer */ | ||
197 | static inline int bd_needed_req(struct bdc_req *req) | ||
198 | { | ||
199 | int bd_needed = 0; | ||
200 | int remaining; | ||
201 | |||
202 | /* 1 bd needed for 0 byte transfer */ | ||
203 | if (req->usb_req.length == 0) | ||
204 | return 1; | ||
205 | |||
206 | /* remaining bytes after tranfering all max BD size BD's */ | ||
207 | remaining = req->usb_req.length % BD_MAX_BUFF_SIZE; | ||
208 | if (remaining) | ||
209 | bd_needed++; | ||
210 | |||
211 | /* How many maximum BUFF size BD's ? */ | ||
212 | remaining = req->usb_req.length / BD_MAX_BUFF_SIZE; | ||
213 | bd_needed += remaining; | ||
214 | |||
215 | return bd_needed; | ||
216 | } | ||
217 | |||
218 | /* returns the bd index(bdi) corresponding to bd dma address */ | ||
219 | static int bd_add_to_bdi(struct bdc_ep *ep, dma_addr_t bd_dma_addr) | ||
220 | { | ||
221 | struct bd_list *bd_list = &ep->bd_list; | ||
222 | dma_addr_t dma_first_bd, dma_last_bd; | ||
223 | struct bdc *bdc = ep->bdc; | ||
224 | struct bd_table *bd_table; | ||
225 | bool found = false; | ||
226 | int tbi, bdi; | ||
227 | |||
228 | dma_first_bd = dma_last_bd = 0; | ||
229 | dev_dbg(bdc->dev, "%s %llx\n", | ||
230 | __func__, (unsigned long long)bd_dma_addr); | ||
231 | /* | ||
232 | * Find in which table this bd_dma_addr belongs?, go through the table | ||
233 | * array and compare addresses of first and last address of bd of each | ||
234 | * table | ||
235 | */ | ||
236 | for (tbi = 0; tbi < bd_list->num_tabs; tbi++) { | ||
237 | bd_table = bd_list->bd_table_array[tbi]; | ||
238 | dma_first_bd = bd_table->dma; | ||
239 | dma_last_bd = bd_table->dma + | ||
240 | (sizeof(struct bdc_bd) * | ||
241 | (bd_list->num_bds_table - 1)); | ||
242 | dev_dbg(bdc->dev, "dma_first_bd:%llx dma_last_bd:%llx\n", | ||
243 | (unsigned long long)dma_first_bd, | ||
244 | (unsigned long long)dma_last_bd); | ||
245 | if (bd_dma_addr >= dma_first_bd && bd_dma_addr <= dma_last_bd) { | ||
246 | found = true; | ||
247 | break; | ||
248 | } | ||
249 | } | ||
250 | if (unlikely(!found)) { | ||
251 | dev_err(bdc->dev, "%s FATAL err, bd not found\n", __func__); | ||
252 | return -EINVAL; | ||
253 | } | ||
254 | /* Now we know the table, find the bdi */ | ||
255 | bdi = (bd_dma_addr - dma_first_bd) / sizeof(struct bdc_bd); | ||
256 | |||
257 | /* return the global bdi, to compare with ep eqp_bdi */ | ||
258 | return (bdi + (tbi * bd_list->num_bds_table)); | ||
259 | } | ||
260 | |||
261 | /* returns the table index(tbi) of the given bdi */ | ||
262 | static int bdi_to_tbi(struct bdc_ep *ep, int bdi) | ||
263 | { | ||
264 | int tbi; | ||
265 | |||
266 | tbi = bdi / ep->bd_list.num_bds_table; | ||
267 | dev_vdbg(ep->bdc->dev, | ||
268 | "bdi:%d num_bds_table:%d tbi:%d\n", | ||
269 | bdi, ep->bd_list.num_bds_table, tbi); | ||
270 | |||
271 | return tbi; | ||
272 | } | ||
273 | |||
274 | /* Find the bdi last bd in the transfer */ | ||
275 | static inline int find_end_bdi(struct bdc_ep *ep, int next_hwd_bdi) | ||
276 | { | ||
277 | int end_bdi; | ||
278 | |||
279 | end_bdi = next_hwd_bdi - 1; | ||
280 | if (end_bdi < 0) | ||
281 | end_bdi = ep->bd_list.max_bdi - 1; | ||
282 | else if ((end_bdi % (ep->bd_list.num_bds_table-1)) == 0) | ||
283 | end_bdi--; | ||
284 | |||
285 | return end_bdi; | ||
286 | } | ||
287 | |||
288 | /* | ||
289 | * How many transfer bd's are available on this ep bdl, chain bds are not | ||
290 | * counted in available bds | ||
291 | */ | ||
292 | static int bd_available_ep(struct bdc_ep *ep) | ||
293 | { | ||
294 | struct bd_list *bd_list = &ep->bd_list; | ||
295 | int available1, available2; | ||
296 | struct bdc *bdc = ep->bdc; | ||
297 | int chain_bd1, chain_bd2; | ||
298 | int available_bd = 0; | ||
299 | |||
300 | available1 = available2 = chain_bd1 = chain_bd2 = 0; | ||
301 | /* if empty then we have all bd's available - number of chain bd's */ | ||
302 | if (bd_list->eqp_bdi == bd_list->hwd_bdi) | ||
303 | return bd_list->max_bdi - bd_list->num_tabs; | ||
304 | |||
305 | /* | ||
306 | * Depending upon where eqp and dqp pointers are, caculate number | ||
307 | * of avaialble bd's | ||
308 | */ | ||
309 | if (bd_list->hwd_bdi < bd_list->eqp_bdi) { | ||
310 | /* available bd's are from eqp..max_bds + 0..dqp - chain_bds */ | ||
311 | available1 = bd_list->max_bdi - bd_list->eqp_bdi; | ||
312 | available2 = bd_list->hwd_bdi; | ||
313 | chain_bd1 = available1 / bd_list->num_bds_table; | ||
314 | chain_bd2 = available2 / bd_list->num_bds_table; | ||
315 | dev_vdbg(bdc->dev, "chain_bd1:%d chain_bd2:%d\n", | ||
316 | chain_bd1, chain_bd2); | ||
317 | available_bd = available1 + available2 - chain_bd1 - chain_bd2; | ||
318 | } else { | ||
319 | /* available bd's are from eqp..dqp - number of chain bd's */ | ||
320 | available1 = bd_list->hwd_bdi - bd_list->eqp_bdi; | ||
321 | /* if gap between eqp and dqp is less than NUM_BDS_PER_TABLE */ | ||
322 | if ((bd_list->hwd_bdi - bd_list->eqp_bdi) | ||
323 | <= bd_list->num_bds_table) { | ||
324 | /* If there any chain bd in between */ | ||
325 | if (!(bdi_to_tbi(ep, bd_list->hwd_bdi) | ||
326 | == bdi_to_tbi(ep, bd_list->eqp_bdi))) { | ||
327 | available_bd = available1 - 1; | ||
328 | } | ||
329 | } else { | ||
330 | chain_bd1 = available1 / bd_list->num_bds_table; | ||
331 | available_bd = available1 - chain_bd1; | ||
332 | } | ||
333 | } | ||
334 | /* | ||
335 | * we need to keep one extra bd to check if ring is full or empty so | ||
336 | * reduce by 1 | ||
337 | */ | ||
338 | available_bd--; | ||
339 | dev_vdbg(bdc->dev, "available_bd:%d\n", available_bd); | ||
340 | |||
341 | return available_bd; | ||
342 | } | ||
343 | |||
344 | /* Notify the hardware after queueing the bd to bdl */ | ||
345 | void bdc_notify_xfr(struct bdc *bdc, u32 epnum) | ||
346 | { | ||
347 | struct bdc_ep *ep = bdc->bdc_ep_array[epnum]; | ||
348 | |||
349 | dev_vdbg(bdc->dev, "%s epnum:%d\n", __func__, epnum); | ||
350 | /* | ||
351 | * We don't have anyway to check if ep state is running, | ||
352 | * except the software flags. | ||
353 | */ | ||
354 | if (unlikely(ep->flags & BDC_EP_STOP)) | ||
355 | ep->flags &= ~BDC_EP_STOP; | ||
356 | |||
357 | bdc_writel(bdc->regs, BDC_XSFNTF, epnum); | ||
358 | } | ||
359 | |||
360 | /* returns the bd corresponding to bdi */ | ||
361 | static struct bdc_bd *bdi_to_bd(struct bdc_ep *ep, int bdi) | ||
362 | { | ||
363 | int tbi = bdi_to_tbi(ep, bdi); | ||
364 | int local_bdi = 0; | ||
365 | |||
366 | local_bdi = bdi - (tbi * ep->bd_list.num_bds_table); | ||
367 | dev_vdbg(ep->bdc->dev, | ||
368 | "%s bdi:%d local_bdi:%d\n", | ||
369 | __func__, bdi, local_bdi); | ||
370 | |||
371 | return (ep->bd_list.bd_table_array[tbi]->start_bd + local_bdi); | ||
372 | } | ||
373 | |||
374 | /* Advance the enqueue pointer */ | ||
375 | static void ep_bdlist_eqp_adv(struct bdc_ep *ep) | ||
376 | { | ||
377 | ep->bd_list.eqp_bdi++; | ||
378 | /* if it's chain bd, then move to next */ | ||
379 | if (((ep->bd_list.eqp_bdi + 1) % ep->bd_list.num_bds_table) == 0) | ||
380 | ep->bd_list.eqp_bdi++; | ||
381 | |||
382 | /* if the eqp is pointing to last + 1 then move back to 0 */ | ||
383 | if (ep->bd_list.eqp_bdi == (ep->bd_list.max_bdi + 1)) | ||
384 | ep->bd_list.eqp_bdi = 0; | ||
385 | } | ||
386 | |||
387 | /* Setup the first bd for ep0 transfer */ | ||
388 | static int setup_first_bd_ep0(struct bdc *bdc, struct bdc_req *req, u32 *dword3) | ||
389 | { | ||
390 | u16 wValue; | ||
391 | u32 req_len; | ||
392 | |||
393 | req->ep->dir = 0; | ||
394 | req_len = req->usb_req.length; | ||
395 | switch (bdc->ep0_state) { | ||
396 | case WAIT_FOR_DATA_START: | ||
397 | *dword3 |= BD_TYPE_DS; | ||
398 | if (bdc->setup_pkt.bRequestType & USB_DIR_IN) | ||
399 | *dword3 |= BD_DIR_IN; | ||
400 | |||
401 | /* check if zlp will be needed */ | ||
402 | wValue = le16_to_cpu(bdc->setup_pkt.wValue); | ||
403 | if ((wValue > req_len) && | ||
404 | (req_len % bdc->gadget.ep0->maxpacket == 0)) { | ||
405 | dev_dbg(bdc->dev, "ZLP needed wVal:%d len:%d MaxP:%d\n", | ||
406 | wValue, req_len, | ||
407 | bdc->gadget.ep0->maxpacket); | ||
408 | bdc->zlp_needed = true; | ||
409 | } | ||
410 | break; | ||
411 | |||
412 | case WAIT_FOR_STATUS_START: | ||
413 | *dword3 |= BD_TYPE_SS; | ||
414 | if (!le16_to_cpu(bdc->setup_pkt.wLength) || | ||
415 | !(bdc->setup_pkt.bRequestType & USB_DIR_IN)) | ||
416 | *dword3 |= BD_DIR_IN; | ||
417 | break; | ||
418 | default: | ||
419 | dev_err(bdc->dev, | ||
420 | "Unknown ep0 state for queueing bd ep0_state:%s\n", | ||
421 | ep0_state_string[bdc->ep0_state]); | ||
422 | return -EINVAL; | ||
423 | } | ||
424 | |||
425 | return 0; | ||
426 | } | ||
427 | |||
428 | /* Setup the bd dma descriptor for a given request */ | ||
429 | static int setup_bd_list_xfr(struct bdc *bdc, struct bdc_req *req, int num_bds) | ||
430 | { | ||
431 | dma_addr_t buf_add = req->usb_req.dma; | ||
432 | u32 maxp, tfs, dword2, dword3; | ||
433 | struct bd_transfer *bd_xfr; | ||
434 | struct bd_list *bd_list; | ||
435 | struct bdc_ep *ep; | ||
436 | struct bdc_bd *bd; | ||
437 | int ret, bdnum; | ||
438 | u32 req_len; | ||
439 | |||
440 | ep = req->ep; | ||
441 | bd_list = &ep->bd_list; | ||
442 | bd_xfr = &req->bd_xfr; | ||
443 | bd_xfr->req = req; | ||
444 | bd_xfr->start_bdi = bd_list->eqp_bdi; | ||
445 | bd = bdi_to_bd(ep, bd_list->eqp_bdi); | ||
446 | req_len = req->usb_req.length; | ||
447 | maxp = usb_endpoint_maxp(ep->desc) & 0x7ff; | ||
448 | tfs = roundup(req->usb_req.length, maxp); | ||
449 | tfs = tfs/maxp; | ||
450 | dev_vdbg(bdc->dev, "%s ep:%s num_bds:%d tfs:%d r_len:%d bd:%p\n", | ||
451 | __func__, ep->name, num_bds, tfs, req_len, bd); | ||
452 | |||
453 | for (bdnum = 0; bdnum < num_bds; bdnum++) { | ||
454 | dword2 = dword3 = 0; | ||
455 | /* First bd */ | ||
456 | if (!bdnum) { | ||
457 | dword3 |= BD_SOT|BD_SBF|(tfs<<BD_TFS_SHIFT); | ||
458 | dword2 |= BD_LTF; | ||
459 | /* format of first bd for ep0 is different than other */ | ||
460 | if (ep->ep_num == 1) | ||
461 | ret = setup_first_bd_ep0(bdc, req, &dword3); | ||
462 | if (ret) | ||
463 | return ret; | ||
464 | } | ||
465 | if (!req->ep->dir) | ||
466 | dword3 |= BD_ISP; | ||
467 | |||
468 | if (req_len > BD_MAX_BUFF_SIZE) { | ||
469 | dword2 |= BD_MAX_BUFF_SIZE; | ||
470 | req_len -= BD_MAX_BUFF_SIZE; | ||
471 | } else { | ||
472 | /* this should be the last bd */ | ||
473 | dword2 |= req_len; | ||
474 | dword3 |= BD_IOC; | ||
475 | dword3 |= BD_EOT; | ||
476 | } | ||
477 | /* Currently only 1 INT target is supported */ | ||
478 | dword2 |= BD_INTR_TARGET(0); | ||
479 | bd = bdi_to_bd(ep, ep->bd_list.eqp_bdi); | ||
480 | if (unlikely(!bd)) { | ||
481 | dev_err(bdc->dev, "Err bd pointing to wrong addr\n"); | ||
482 | return -EINVAL; | ||
483 | } | ||
484 | /* write bd */ | ||
485 | bd->offset[0] = cpu_to_le32(lower_32_bits(buf_add)); | ||
486 | bd->offset[1] = cpu_to_le32(upper_32_bits(buf_add)); | ||
487 | bd->offset[2] = cpu_to_le32(dword2); | ||
488 | bd->offset[3] = cpu_to_le32(dword3); | ||
489 | /* advance eqp pointer */ | ||
490 | ep_bdlist_eqp_adv(ep); | ||
491 | /* advance the buff pointer */ | ||
492 | buf_add += BD_MAX_BUFF_SIZE; | ||
493 | dev_vdbg(bdc->dev, "buf_add:%08llx req_len:%d bd:%p eqp:%d\n", | ||
494 | (unsigned long long)buf_add, req_len, bd, | ||
495 | ep->bd_list.eqp_bdi); | ||
496 | bd = bdi_to_bd(ep, ep->bd_list.eqp_bdi); | ||
497 | bd->offset[3] = cpu_to_le32(BD_SBF); | ||
498 | } | ||
499 | /* clear the STOP BD fetch bit from the first bd of this xfr */ | ||
500 | bd = bdi_to_bd(ep, bd_xfr->start_bdi); | ||
501 | bd->offset[3] &= cpu_to_le32(~BD_SBF); | ||
502 | /* the new eqp will be next hw dqp */ | ||
503 | bd_xfr->num_bds = num_bds; | ||
504 | bd_xfr->next_hwd_bdi = ep->bd_list.eqp_bdi; | ||
505 | /* everything is written correctly before notifying the HW */ | ||
506 | wmb(); | ||
507 | |||
508 | return 0; | ||
509 | } | ||
510 | |||
511 | /* Queue the xfr */ | ||
512 | static int bdc_queue_xfr(struct bdc *bdc, struct bdc_req *req) | ||
513 | { | ||
514 | int num_bds, bd_available; | ||
515 | struct bdc_ep *ep; | ||
516 | int ret; | ||
517 | |||
518 | ep = req->ep; | ||
519 | dev_dbg(bdc->dev, "%s req:%p\n", __func__, req); | ||
520 | dev_dbg(bdc->dev, "eqp_bdi:%d hwd_bdi:%d\n", | ||
521 | ep->bd_list.eqp_bdi, ep->bd_list.hwd_bdi); | ||
522 | |||
523 | num_bds = bd_needed_req(req); | ||
524 | bd_available = bd_available_ep(ep); | ||
525 | |||
526 | /* how many bd's are avaialble on ep */ | ||
527 | if (num_bds > bd_available) | ||
528 | return -ENOMEM; | ||
529 | |||
530 | ret = setup_bd_list_xfr(bdc, req, num_bds); | ||
531 | if (ret) | ||
532 | return ret; | ||
533 | list_add_tail(&req->queue, &ep->queue); | ||
534 | bdc_dbg_bd_list(bdc, ep); | ||
535 | bdc_notify_xfr(bdc, ep->ep_num); | ||
536 | |||
537 | return 0; | ||
538 | } | ||
539 | |||
540 | /* callback to gadget layer when xfr completes */ | ||
541 | static void bdc_req_complete(struct bdc_ep *ep, struct bdc_req *req, | ||
542 | int status) | ||
543 | { | ||
544 | struct bdc *bdc = ep->bdc; | ||
545 | |||
546 | if (req == NULL || &req->queue == NULL || &req->usb_req == NULL) | ||
547 | return; | ||
548 | |||
549 | dev_dbg(bdc->dev, "%s ep:%s status:%d\n", __func__, ep->name, status); | ||
550 | list_del(&req->queue); | ||
551 | req->usb_req.status = status; | ||
552 | usb_gadget_unmap_request(&bdc->gadget, &req->usb_req, ep->dir); | ||
553 | if (req->usb_req.complete) { | ||
554 | spin_unlock(&bdc->lock); | ||
555 | usb_gadget_giveback_request(&ep->usb_ep, &req->usb_req); | ||
556 | spin_lock(&bdc->lock); | ||
557 | } | ||
558 | } | ||
559 | |||
560 | /* Disable the endpoint */ | ||
561 | int bdc_ep_disable(struct bdc_ep *ep) | ||
562 | { | ||
563 | struct bdc_req *req; | ||
564 | struct bdc *bdc; | ||
565 | int ret; | ||
566 | |||
567 | ret = 0; | ||
568 | bdc = ep->bdc; | ||
569 | dev_dbg(bdc->dev, "%s() ep->ep_num=%d\n", __func__, ep->ep_num); | ||
570 | /* Stop the endpoint */ | ||
571 | ret = bdc_stop_ep(bdc, ep->ep_num); | ||
572 | |||
573 | /* | ||
574 | * Intentionally don't check the ret value of stop, it can fail in | ||
575 | * disconnect scenarios, continue with dconfig | ||
576 | */ | ||
577 | /* de-queue any pending requests */ | ||
578 | while (!list_empty(&ep->queue)) { | ||
579 | req = list_entry(ep->queue.next, struct bdc_req, | ||
580 | queue); | ||
581 | bdc_req_complete(ep, req, -ESHUTDOWN); | ||
582 | } | ||
583 | /* deconfigure the endpoint */ | ||
584 | ret = bdc_dconfig_ep(bdc, ep); | ||
585 | if (ret) | ||
586 | dev_warn(bdc->dev, | ||
587 | "dconfig fail but continue with memory free"); | ||
588 | |||
589 | ep->flags = 0; | ||
590 | /* ep0 memory is not freed, but reused on next connect sr */ | ||
591 | if (ep->ep_num == 1) | ||
592 | return 0; | ||
593 | |||
594 | /* Free the bdl memory */ | ||
595 | ep_bd_list_free(ep, ep->bd_list.num_tabs); | ||
596 | ep->desc = NULL; | ||
597 | ep->comp_desc = NULL; | ||
598 | ep->usb_ep.desc = NULL; | ||
599 | ep->ep_type = 0; | ||
600 | |||
601 | return ret; | ||
602 | } | ||
603 | |||
604 | /* Enable the ep */ | ||
605 | int bdc_ep_enable(struct bdc_ep *ep) | ||
606 | { | ||
607 | struct bdc *bdc; | ||
608 | int ret = 0; | ||
609 | |||
610 | bdc = ep->bdc; | ||
611 | dev_dbg(bdc->dev, "%s NUM_TABLES:%d %d\n", | ||
612 | __func__, NUM_TABLES, NUM_TABLES_ISOCH); | ||
613 | |||
614 | ret = ep_bd_list_alloc(ep); | ||
615 | if (ret) { | ||
616 | dev_err(bdc->dev, "ep bd list allocation failed:%d\n", ret); | ||
617 | return -ENOMEM; | ||
618 | } | ||
619 | bdc_dbg_bd_list(bdc, ep); | ||
620 | /* only for ep0: config ep is called for ep0 from connect event */ | ||
621 | ep->flags |= BDC_EP_ENABLED; | ||
622 | if (ep->ep_num == 1) | ||
623 | return ret; | ||
624 | |||
625 | /* Issue a configure endpoint command */ | ||
626 | ret = bdc_config_ep(bdc, ep); | ||
627 | if (ret) | ||
628 | return ret; | ||
629 | |||
630 | ep->usb_ep.maxpacket = usb_endpoint_maxp(ep->desc); | ||
631 | ep->usb_ep.desc = ep->desc; | ||
632 | ep->usb_ep.comp_desc = ep->comp_desc; | ||
633 | ep->ep_type = usb_endpoint_type(ep->desc); | ||
634 | ep->flags |= BDC_EP_ENABLED; | ||
635 | |||
636 | return 0; | ||
637 | } | ||
638 | |||
639 | /* EP0 related code */ | ||
640 | |||
641 | /* Queue a status stage BD */ | ||
642 | static int ep0_queue_status_stage(struct bdc *bdc) | ||
643 | { | ||
644 | struct bdc_req *status_req; | ||
645 | struct bdc_ep *ep; | ||
646 | |||
647 | status_req = &bdc->status_req; | ||
648 | ep = bdc->bdc_ep_array[1]; | ||
649 | status_req->ep = ep; | ||
650 | status_req->usb_req.length = 0; | ||
651 | status_req->usb_req.status = -EINPROGRESS; | ||
652 | status_req->usb_req.actual = 0; | ||
653 | status_req->usb_req.complete = NULL; | ||
654 | bdc_queue_xfr(bdc, status_req); | ||
655 | |||
656 | return 0; | ||
657 | } | ||
658 | |||
659 | /* Queue xfr on ep0 */ | ||
660 | static int ep0_queue(struct bdc_ep *ep, struct bdc_req *req) | ||
661 | { | ||
662 | struct bdc *bdc; | ||
663 | int ret; | ||
664 | |||
665 | bdc = ep->bdc; | ||
666 | dev_dbg(bdc->dev, "%s()\n", __func__); | ||
667 | req->usb_req.actual = 0; | ||
668 | req->usb_req.status = -EINPROGRESS; | ||
669 | req->epnum = ep->ep_num; | ||
670 | |||
671 | if (bdc->delayed_status) { | ||
672 | bdc->delayed_status = false; | ||
673 | /* if status stage was delayed? */ | ||
674 | if (bdc->ep0_state == WAIT_FOR_STATUS_START) { | ||
675 | /* Queue a status stage BD */ | ||
676 | ep0_queue_status_stage(bdc); | ||
677 | bdc->ep0_state = WAIT_FOR_STATUS_XMIT; | ||
678 | return 0; | ||
679 | } | ||
680 | } else { | ||
681 | /* | ||
682 | * if delayed status is false and 0 length transfer is requested | ||
683 | * i.e. for status stage of some setup request, then just | ||
684 | * return from here the status stage is queued independently | ||
685 | */ | ||
686 | if (req->usb_req.length == 0) | ||
687 | return 0; | ||
688 | |||
689 | } | ||
690 | ret = usb_gadget_map_request(&bdc->gadget, &req->usb_req, ep->dir); | ||
691 | if (ret) { | ||
692 | dev_err(bdc->dev, "dma mapping failed %s\n", ep->name); | ||
693 | return ret; | ||
694 | } | ||
695 | |||
696 | return bdc_queue_xfr(bdc, req); | ||
697 | } | ||
698 | |||
699 | /* Queue data stage */ | ||
700 | static int ep0_queue_data_stage(struct bdc *bdc) | ||
701 | { | ||
702 | struct usb_request *ep0_usb_req; | ||
703 | struct bdc_ep *ep; | ||
704 | |||
705 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
706 | ep0_usb_req = &bdc->ep0_req.usb_req; | ||
707 | ep = bdc->bdc_ep_array[1]; | ||
708 | bdc->ep0_req.ep = ep; | ||
709 | bdc->ep0_req.usb_req.complete = NULL; | ||
710 | |||
711 | return ep0_queue(ep, &bdc->ep0_req); | ||
712 | } | ||
713 | |||
714 | /* Queue req on ep */ | ||
715 | static int ep_queue(struct bdc_ep *ep, struct bdc_req *req) | ||
716 | { | ||
717 | struct bdc *bdc; | ||
718 | int ret = 0; | ||
719 | |||
720 | bdc = ep->bdc; | ||
721 | if (!req || !ep || !ep->usb_ep.desc) | ||
722 | return -EINVAL; | ||
723 | |||
724 | req->usb_req.actual = 0; | ||
725 | req->usb_req.status = -EINPROGRESS; | ||
726 | req->epnum = ep->ep_num; | ||
727 | |||
728 | ret = usb_gadget_map_request(&bdc->gadget, &req->usb_req, ep->dir); | ||
729 | if (ret) { | ||
730 | dev_err(bdc->dev, "dma mapping failed\n"); | ||
731 | return ret; | ||
732 | } | ||
733 | |||
734 | return bdc_queue_xfr(bdc, req); | ||
735 | } | ||
736 | |||
737 | /* Dequeue a request from ep */ | ||
738 | static int ep_dequeue(struct bdc_ep *ep, struct bdc_req *req) | ||
739 | { | ||
740 | int start_bdi, end_bdi, tbi, eqp_bdi, curr_hw_dqpi; | ||
741 | bool start_pending, end_pending; | ||
742 | bool first_remove = false; | ||
743 | struct bdc_req *first_req; | ||
744 | struct bdc_bd *bd_start; | ||
745 | struct bd_table *table; | ||
746 | dma_addr_t next_bd_dma; | ||
747 | u64 deq_ptr_64 = 0; | ||
748 | struct bdc *bdc; | ||
749 | u32 tmp_32; | ||
750 | int ret; | ||
751 | |||
752 | bdc = ep->bdc; | ||
753 | start_pending = end_pending = false; | ||
754 | eqp_bdi = ep->bd_list.eqp_bdi - 1; | ||
755 | |||
756 | if (eqp_bdi < 0) | ||
757 | eqp_bdi = ep->bd_list.max_bdi; | ||
758 | |||
759 | start_bdi = req->bd_xfr.start_bdi; | ||
760 | end_bdi = find_end_bdi(ep, req->bd_xfr.next_hwd_bdi); | ||
761 | |||
762 | dev_dbg(bdc->dev, "%s ep:%s start:%d end:%d\n", | ||
763 | __func__, ep->name, start_bdi, end_bdi); | ||
764 | dev_dbg(bdc->dev, "ep_dequeue ep=%p ep->desc=%p\n", | ||
765 | ep, (void *)ep->usb_ep.desc); | ||
766 | /* Stop the ep to see where the HW is ? */ | ||
767 | ret = bdc_stop_ep(bdc, ep->ep_num); | ||
768 | /* if there is an issue with stopping ep, then no need to go further */ | ||
769 | if (ret) | ||
770 | return 0; | ||
771 | |||
772 | /* | ||
773 | * After endpoint is stopped, there can be 3 cases, the request | ||
774 | * is processed, pending or in the middle of processing | ||
775 | */ | ||
776 | |||
777 | /* The current hw dequeue pointer */ | ||
778 | tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS0(0)); | ||
779 | deq_ptr_64 = tmp_32; | ||
780 | tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS0(1)); | ||
781 | deq_ptr_64 |= ((u64)tmp_32 << 32); | ||
782 | |||
783 | /* we have the dma addr of next bd that will be fetched by hardware */ | ||
784 | curr_hw_dqpi = bd_add_to_bdi(ep, deq_ptr_64); | ||
785 | if (curr_hw_dqpi < 0) | ||
786 | return curr_hw_dqpi; | ||
787 | |||
788 | /* | ||
789 | * curr_hw_dqpi points to actual dqp of HW and HW owns bd's from | ||
790 | * curr_hw_dqbdi..eqp_bdi. | ||
791 | */ | ||
792 | |||
793 | /* Check if start_bdi and end_bdi are in range of HW owned BD's */ | ||
794 | if (curr_hw_dqpi > eqp_bdi) { | ||
795 | /* there is a wrap from last to 0 */ | ||
796 | if (start_bdi >= curr_hw_dqpi || start_bdi <= eqp_bdi) { | ||
797 | start_pending = true; | ||
798 | end_pending = true; | ||
799 | } else if (end_bdi >= curr_hw_dqpi || end_bdi <= eqp_bdi) { | ||
800 | end_pending = true; | ||
801 | } | ||
802 | } else { | ||
803 | if (start_bdi >= curr_hw_dqpi) { | ||
804 | start_pending = true; | ||
805 | end_pending = true; | ||
806 | } else if (end_bdi >= curr_hw_dqpi) { | ||
807 | end_pending = true; | ||
808 | } | ||
809 | } | ||
810 | dev_dbg(bdc->dev, | ||
811 | "start_pending:%d end_pending:%d speed:%d\n", | ||
812 | start_pending, end_pending, bdc->gadget.speed); | ||
813 | |||
814 | /* If both start till end are processes, we cannot deq req */ | ||
815 | if (!start_pending && !end_pending) | ||
816 | return -EINVAL; | ||
817 | |||
818 | /* | ||
819 | * if ep_dequeue is called after disconnect then just return | ||
820 | * success from here | ||
821 | */ | ||
822 | if (bdc->gadget.speed == USB_SPEED_UNKNOWN) | ||
823 | return 0; | ||
824 | tbi = bdi_to_tbi(ep, req->bd_xfr.next_hwd_bdi); | ||
825 | table = ep->bd_list.bd_table_array[tbi]; | ||
826 | next_bd_dma = table->dma + | ||
827 | sizeof(struct bdc_bd)*(req->bd_xfr.next_hwd_bdi - | ||
828 | tbi * ep->bd_list.num_bds_table); | ||
829 | |||
830 | first_req = list_first_entry(&ep->queue, struct bdc_req, | ||
831 | queue); | ||
832 | |||
833 | if (req == first_req) | ||
834 | first_remove = true; | ||
835 | |||
836 | /* | ||
837 | * Due to HW limitation we need to bypadd chain bd's and issue ep_bla, | ||
838 | * incase if start is pending this is the first request in the list | ||
839 | * then issue ep_bla instead of marking as chain bd | ||
840 | */ | ||
841 | if (start_pending && !first_remove) { | ||
842 | /* | ||
843 | * Mark the start bd as Chain bd, and point the chain | ||
844 | * bd to next_bd_dma | ||
845 | */ | ||
846 | bd_start = bdi_to_bd(ep, start_bdi); | ||
847 | bd_start->offset[0] = cpu_to_le32(lower_32_bits(next_bd_dma)); | ||
848 | bd_start->offset[1] = cpu_to_le32(upper_32_bits(next_bd_dma)); | ||
849 | bd_start->offset[2] = 0x0; | ||
850 | bd_start->offset[3] = cpu_to_le32(MARK_CHAIN_BD); | ||
851 | bdc_dbg_bd_list(bdc, ep); | ||
852 | } else if (end_pending) { | ||
853 | /* | ||
854 | * The transfer is stopped in the middle, move the | ||
855 | * HW deq pointer to next_bd_dma | ||
856 | */ | ||
857 | ret = bdc_ep_bla(bdc, ep, next_bd_dma); | ||
858 | if (ret) { | ||
859 | dev_err(bdc->dev, "error in ep_bla:%d\n", ret); | ||
860 | return ret; | ||
861 | } | ||
862 | } | ||
863 | |||
864 | return 0; | ||
865 | } | ||
866 | |||
867 | /* Halt/Clear the ep based on value */ | ||
868 | static int ep_set_halt(struct bdc_ep *ep, u32 value) | ||
869 | { | ||
870 | struct bdc *bdc; | ||
871 | int ret; | ||
872 | |||
873 | bdc = ep->bdc; | ||
874 | dev_dbg(bdc->dev, "%s ep:%s value=%d\n", __func__, ep->name, value); | ||
875 | |||
876 | if (value) { | ||
877 | dev_dbg(bdc->dev, "Halt\n"); | ||
878 | if (ep->ep_num == 1) | ||
879 | bdc->ep0_state = WAIT_FOR_SETUP; | ||
880 | |||
881 | ret = bdc_ep_set_stall(bdc, ep->ep_num); | ||
882 | if (ret) | ||
883 | dev_err(bdc->dev, "failed to %s STALL on %s\n", | ||
884 | value ? "set" : "clear", ep->name); | ||
885 | else | ||
886 | ep->flags |= BDC_EP_STALL; | ||
887 | } else { | ||
888 | /* Clear */ | ||
889 | dev_dbg(bdc->dev, "Before Clear\n"); | ||
890 | ret = bdc_ep_clear_stall(bdc, ep->ep_num); | ||
891 | if (ret) | ||
892 | dev_err(bdc->dev, "failed to %s STALL on %s\n", | ||
893 | value ? "set" : "clear", ep->name); | ||
894 | else | ||
895 | ep->flags &= ~BDC_EP_STALL; | ||
896 | dev_dbg(bdc->dev, "After Clear\n"); | ||
897 | } | ||
898 | |||
899 | return ret; | ||
900 | } | ||
901 | |||
902 | /* Free all the ep */ | ||
903 | void bdc_free_ep(struct bdc *bdc) | ||
904 | { | ||
905 | struct bdc_ep *ep; | ||
906 | u8 epnum; | ||
907 | |||
908 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
909 | for (epnum = 1; epnum < bdc->num_eps; epnum++) { | ||
910 | ep = bdc->bdc_ep_array[epnum]; | ||
911 | if (!ep) | ||
912 | continue; | ||
913 | |||
914 | if (ep->flags & BDC_EP_ENABLED) | ||
915 | ep_bd_list_free(ep, ep->bd_list.num_tabs); | ||
916 | |||
917 | /* ep0 is not in this gadget list */ | ||
918 | if (epnum != 1) | ||
919 | list_del(&ep->usb_ep.ep_list); | ||
920 | |||
921 | kfree(ep); | ||
922 | } | ||
923 | } | ||
924 | |||
925 | /* USB2 spec, section 7.1.20 */ | ||
926 | static int bdc_set_test_mode(struct bdc *bdc) | ||
927 | { | ||
928 | u32 usb2_pm; | ||
929 | |||
930 | usb2_pm = bdc_readl(bdc->regs, BDC_USPPM2); | ||
931 | usb2_pm &= ~BDC_PTC_MASK; | ||
932 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
933 | switch (bdc->test_mode) { | ||
934 | case TEST_J: | ||
935 | case TEST_K: | ||
936 | case TEST_SE0_NAK: | ||
937 | case TEST_PACKET: | ||
938 | case TEST_FORCE_EN: | ||
939 | usb2_pm |= bdc->test_mode << 28; | ||
940 | break; | ||
941 | default: | ||
942 | return -EINVAL; | ||
943 | } | ||
944 | dev_dbg(bdc->dev, "usb2_pm=%08x", usb2_pm); | ||
945 | bdc_writel(bdc->regs, BDC_USPPM2, usb2_pm); | ||
946 | |||
947 | return 0; | ||
948 | } | ||
949 | |||
950 | /* | ||
951 | * Helper function to handle Transfer status report with status as either | ||
952 | * success or short | ||
953 | */ | ||
954 | static void handle_xsr_succ_status(struct bdc *bdc, struct bdc_ep *ep, | ||
955 | struct bdc_sr *sreport) | ||
956 | { | ||
957 | int short_bdi, start_bdi, end_bdi, max_len_bds, chain_bds; | ||
958 | struct bd_list *bd_list = &ep->bd_list; | ||
959 | int actual_length, length_short; | ||
960 | struct bd_transfer *bd_xfr; | ||
961 | struct bdc_bd *short_bd; | ||
962 | struct bdc_req *req; | ||
963 | u64 deq_ptr_64 = 0; | ||
964 | int status = 0; | ||
965 | int sr_status; | ||
966 | u32 tmp_32; | ||
967 | |||
968 | dev_dbg(bdc->dev, "%s ep:%p\n", __func__, ep); | ||
969 | bdc_dbg_srr(bdc, 0); | ||
970 | /* do not process thie sr if ignore flag is set */ | ||
971 | if (ep->ignore_next_sr) { | ||
972 | ep->ignore_next_sr = false; | ||
973 | return; | ||
974 | } | ||
975 | |||
976 | if (unlikely(list_empty(&ep->queue))) { | ||
977 | dev_warn(bdc->dev, "xfr srr with no BD's queued\n"); | ||
978 | return; | ||
979 | } | ||
980 | req = list_entry(ep->queue.next, struct bdc_req, | ||
981 | queue); | ||
982 | |||
983 | bd_xfr = &req->bd_xfr; | ||
984 | sr_status = XSF_STS(le32_to_cpu(sreport->offset[3])); | ||
985 | |||
986 | /* | ||
987 | * sr_status is short and this transfer has more than 1 bd then it needs | ||
988 | * special handling, this is only applicable for bulk and ctrl | ||
989 | */ | ||
990 | if (sr_status == XSF_SHORT && bd_xfr->num_bds > 1) { | ||
991 | /* | ||
992 | * This is multi bd xfr, lets see which bd | ||
993 | * caused short transfer and how many bytes have been | ||
994 | * transferred so far. | ||
995 | */ | ||
996 | tmp_32 = le32_to_cpu(sreport->offset[0]); | ||
997 | deq_ptr_64 = tmp_32; | ||
998 | tmp_32 = le32_to_cpu(sreport->offset[1]); | ||
999 | deq_ptr_64 |= ((u64)tmp_32 << 32); | ||
1000 | short_bdi = bd_add_to_bdi(ep, deq_ptr_64); | ||
1001 | if (unlikely(short_bdi < 0)) | ||
1002 | dev_warn(bdc->dev, "bd doesn't exist?\n"); | ||
1003 | |||
1004 | start_bdi = bd_xfr->start_bdi; | ||
1005 | /* | ||
1006 | * We know the start_bdi and short_bdi, how many xfr | ||
1007 | * bds in between | ||
1008 | */ | ||
1009 | if (start_bdi <= short_bdi) { | ||
1010 | max_len_bds = short_bdi - start_bdi; | ||
1011 | if (max_len_bds <= bd_list->num_bds_table) { | ||
1012 | if (!(bdi_to_tbi(ep, start_bdi) == | ||
1013 | bdi_to_tbi(ep, short_bdi))) | ||
1014 | max_len_bds--; | ||
1015 | } else { | ||
1016 | chain_bds = max_len_bds/bd_list->num_bds_table; | ||
1017 | max_len_bds -= chain_bds; | ||
1018 | } | ||
1019 | } else { | ||
1020 | /* there is a wrap in the ring within a xfr */ | ||
1021 | chain_bds = (bd_list->max_bdi - start_bdi)/ | ||
1022 | bd_list->num_bds_table; | ||
1023 | chain_bds += short_bdi/bd_list->num_bds_table; | ||
1024 | max_len_bds = bd_list->max_bdi - start_bdi; | ||
1025 | max_len_bds += short_bdi; | ||
1026 | max_len_bds -= chain_bds; | ||
1027 | } | ||
1028 | /* max_len_bds is the number of full length bds */ | ||
1029 | end_bdi = find_end_bdi(ep, bd_xfr->next_hwd_bdi); | ||
1030 | if (!(end_bdi == short_bdi)) | ||
1031 | ep->ignore_next_sr = true; | ||
1032 | |||
1033 | actual_length = max_len_bds * BD_MAX_BUFF_SIZE; | ||
1034 | short_bd = bdi_to_bd(ep, short_bdi); | ||
1035 | /* length queued */ | ||
1036 | length_short = le32_to_cpu(short_bd->offset[2]) & 0x1FFFFF; | ||
1037 | /* actual length trensfered */ | ||
1038 | length_short -= SR_BD_LEN(le32_to_cpu(sreport->offset[2])); | ||
1039 | actual_length += length_short; | ||
1040 | req->usb_req.actual = actual_length; | ||
1041 | } else { | ||
1042 | req->usb_req.actual = req->usb_req.length - | ||
1043 | SR_BD_LEN(le32_to_cpu(sreport->offset[2])); | ||
1044 | dev_dbg(bdc->dev, | ||
1045 | "len=%d actual=%d bd_xfr->next_hwd_bdi:%d\n", | ||
1046 | req->usb_req.length, req->usb_req.actual, | ||
1047 | bd_xfr->next_hwd_bdi); | ||
1048 | } | ||
1049 | |||
1050 | /* Update the dequeue pointer */ | ||
1051 | ep->bd_list.hwd_bdi = bd_xfr->next_hwd_bdi; | ||
1052 | if (req->usb_req.actual < req->usb_req.length) { | ||
1053 | dev_dbg(bdc->dev, "short xfr on %d\n", ep->ep_num); | ||
1054 | if (req->usb_req.short_not_ok) | ||
1055 | status = -EREMOTEIO; | ||
1056 | } | ||
1057 | bdc_req_complete(ep, bd_xfr->req, status); | ||
1058 | } | ||
1059 | |||
1060 | /* EP0 setup related packet handlers */ | ||
1061 | |||
1062 | /* | ||
1063 | * Setup packet received, just store the packet and process on next DS or SS | ||
1064 | * started SR | ||
1065 | */ | ||
1066 | void bdc_xsf_ep0_setup_recv(struct bdc *bdc, struct bdc_sr *sreport) | ||
1067 | { | ||
1068 | struct usb_ctrlrequest *setup_pkt; | ||
1069 | u32 len; | ||
1070 | |||
1071 | dev_dbg(bdc->dev, | ||
1072 | "%s ep0_state:%s\n", | ||
1073 | __func__, ep0_state_string[bdc->ep0_state]); | ||
1074 | /* Store received setup packet */ | ||
1075 | setup_pkt = &bdc->setup_pkt; | ||
1076 | memcpy(setup_pkt, &sreport->offset[0], sizeof(*setup_pkt)); | ||
1077 | len = le16_to_cpu(setup_pkt->wLength); | ||
1078 | if (!len) | ||
1079 | bdc->ep0_state = WAIT_FOR_STATUS_START; | ||
1080 | else | ||
1081 | bdc->ep0_state = WAIT_FOR_DATA_START; | ||
1082 | |||
1083 | |||
1084 | dev_dbg(bdc->dev, | ||
1085 | "%s exit ep0_state:%s\n", | ||
1086 | __func__, ep0_state_string[bdc->ep0_state]); | ||
1087 | } | ||
1088 | |||
1089 | /* Stall ep0 */ | ||
1090 | static void ep0_stall(struct bdc *bdc) | ||
1091 | { | ||
1092 | struct bdc_ep *ep = bdc->bdc_ep_array[1]; | ||
1093 | struct bdc_req *req; | ||
1094 | |||
1095 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
1096 | bdc->delayed_status = false; | ||
1097 | ep_set_halt(ep, 1); | ||
1098 | |||
1099 | /* de-queue any pendig requests */ | ||
1100 | while (!list_empty(&ep->queue)) { | ||
1101 | req = list_entry(ep->queue.next, struct bdc_req, | ||
1102 | queue); | ||
1103 | bdc_req_complete(ep, req, -ESHUTDOWN); | ||
1104 | } | ||
1105 | } | ||
1106 | |||
1107 | /* SET_ADD handlers */ | ||
1108 | static int ep0_set_address(struct bdc *bdc, struct usb_ctrlrequest *ctrl) | ||
1109 | { | ||
1110 | enum usb_device_state state = bdc->gadget.state; | ||
1111 | int ret = 0; | ||
1112 | u32 addr; | ||
1113 | |||
1114 | addr = le16_to_cpu(ctrl->wValue); | ||
1115 | dev_dbg(bdc->dev, | ||
1116 | "%s addr:%d dev state:%d\n", | ||
1117 | __func__, addr, state); | ||
1118 | |||
1119 | if (addr > 127) | ||
1120 | return -EINVAL; | ||
1121 | |||
1122 | switch (state) { | ||
1123 | case USB_STATE_DEFAULT: | ||
1124 | case USB_STATE_ADDRESS: | ||
1125 | /* Issue Address device command */ | ||
1126 | ret = bdc_address_device(bdc, addr); | ||
1127 | if (ret) | ||
1128 | return ret; | ||
1129 | |||
1130 | if (addr) | ||
1131 | usb_gadget_set_state(&bdc->gadget, USB_STATE_ADDRESS); | ||
1132 | else | ||
1133 | usb_gadget_set_state(&bdc->gadget, USB_STATE_DEFAULT); | ||
1134 | |||
1135 | bdc->dev_addr = addr; | ||
1136 | break; | ||
1137 | default: | ||
1138 | dev_warn(bdc->dev, | ||
1139 | "SET Address in wrong device state %d\n", | ||
1140 | state); | ||
1141 | ret = -EINVAL; | ||
1142 | } | ||
1143 | |||
1144 | return ret; | ||
1145 | } | ||
1146 | |||
1147 | /* Handler for SET/CLEAR FEATURE requests for device */ | ||
1148 | static int ep0_handle_feature_dev(struct bdc *bdc, u16 wValue, | ||
1149 | u16 wIndex, bool set) | ||
1150 | { | ||
1151 | enum usb_device_state state = bdc->gadget.state; | ||
1152 | u32 usppms = 0; | ||
1153 | |||
1154 | dev_dbg(bdc->dev, "%s set:%d dev state:%d\n", | ||
1155 | __func__, set, state); | ||
1156 | switch (wValue) { | ||
1157 | case USB_DEVICE_REMOTE_WAKEUP: | ||
1158 | dev_dbg(bdc->dev, "USB_DEVICE_REMOTE_WAKEUP\n"); | ||
1159 | if (set) | ||
1160 | bdc->devstatus |= REMOTE_WAKE_ENABLE; | ||
1161 | else | ||
1162 | bdc->devstatus &= ~REMOTE_WAKE_ENABLE; | ||
1163 | break; | ||
1164 | |||
1165 | case USB_DEVICE_TEST_MODE: | ||
1166 | dev_dbg(bdc->dev, "USB_DEVICE_TEST_MODE\n"); | ||
1167 | if ((wIndex & 0xFF) || | ||
1168 | (bdc->gadget.speed != USB_SPEED_HIGH) || !set) | ||
1169 | return -EINVAL; | ||
1170 | |||
1171 | bdc->test_mode = wIndex >> 8; | ||
1172 | break; | ||
1173 | |||
1174 | case USB_DEVICE_U1_ENABLE: | ||
1175 | dev_dbg(bdc->dev, "USB_DEVICE_U1_ENABLE\n"); | ||
1176 | |||
1177 | if (bdc->gadget.speed != USB_SPEED_SUPER || | ||
1178 | state != USB_STATE_CONFIGURED) | ||
1179 | return -EINVAL; | ||
1180 | |||
1181 | usppms = bdc_readl(bdc->regs, BDC_USPPMS); | ||
1182 | if (set) { | ||
1183 | /* clear previous u1t */ | ||
1184 | usppms &= ~BDC_U1T(BDC_U1T_MASK); | ||
1185 | usppms |= BDC_U1T(U1_TIMEOUT); | ||
1186 | usppms |= BDC_U1E | BDC_PORT_W1S; | ||
1187 | bdc->devstatus |= (1 << USB_DEV_STAT_U1_ENABLED); | ||
1188 | } else { | ||
1189 | usppms &= ~BDC_U1E; | ||
1190 | usppms |= BDC_PORT_W1S; | ||
1191 | bdc->devstatus &= ~(1 << USB_DEV_STAT_U1_ENABLED); | ||
1192 | } | ||
1193 | bdc_writel(bdc->regs, BDC_USPPMS, usppms); | ||
1194 | break; | ||
1195 | |||
1196 | case USB_DEVICE_U2_ENABLE: | ||
1197 | dev_dbg(bdc->dev, "USB_DEVICE_U2_ENABLE\n"); | ||
1198 | |||
1199 | if (bdc->gadget.speed != USB_SPEED_SUPER || | ||
1200 | state != USB_STATE_CONFIGURED) | ||
1201 | return -EINVAL; | ||
1202 | |||
1203 | usppms = bdc_readl(bdc->regs, BDC_USPPMS); | ||
1204 | if (set) { | ||
1205 | usppms |= BDC_U2E; | ||
1206 | usppms |= BDC_U2A; | ||
1207 | bdc->devstatus |= (1 << USB_DEV_STAT_U2_ENABLED); | ||
1208 | } else { | ||
1209 | usppms &= ~BDC_U2E; | ||
1210 | usppms &= ~BDC_U2A; | ||
1211 | bdc->devstatus &= ~(1 << USB_DEV_STAT_U2_ENABLED); | ||
1212 | } | ||
1213 | bdc_writel(bdc->regs, BDC_USPPMS, usppms); | ||
1214 | break; | ||
1215 | |||
1216 | case USB_DEVICE_LTM_ENABLE: | ||
1217 | dev_dbg(bdc->dev, "USB_DEVICE_LTM_ENABLE?\n"); | ||
1218 | if (bdc->gadget.speed != USB_SPEED_SUPER || | ||
1219 | state != USB_STATE_CONFIGURED) | ||
1220 | return -EINVAL; | ||
1221 | break; | ||
1222 | default: | ||
1223 | dev_err(bdc->dev, "Unknown wValue:%d\n", wValue); | ||
1224 | return -EOPNOTSUPP; | ||
1225 | } /* USB_RECIP_DEVICE end */ | ||
1226 | |||
1227 | return 0; | ||
1228 | } | ||
1229 | |||
1230 | /* SET/CLEAR FEATURE handler */ | ||
1231 | static int ep0_handle_feature(struct bdc *bdc, | ||
1232 | struct usb_ctrlrequest *setup_pkt, bool set) | ||
1233 | { | ||
1234 | enum usb_device_state state = bdc->gadget.state; | ||
1235 | struct bdc_ep *ep; | ||
1236 | u16 wValue; | ||
1237 | u16 wIndex; | ||
1238 | int epnum; | ||
1239 | |||
1240 | wValue = le16_to_cpu(setup_pkt->wValue); | ||
1241 | wIndex = le16_to_cpu(setup_pkt->wIndex); | ||
1242 | |||
1243 | dev_dbg(bdc->dev, | ||
1244 | "%s wValue=%d wIndex=%d devstate=%08x speed=%d set=%d", | ||
1245 | __func__, wValue, wIndex, state, | ||
1246 | bdc->gadget.speed, set); | ||
1247 | |||
1248 | switch (setup_pkt->bRequestType & USB_RECIP_MASK) { | ||
1249 | case USB_RECIP_DEVICE: | ||
1250 | return ep0_handle_feature_dev(bdc, wValue, wIndex, set); | ||
1251 | case USB_RECIP_INTERFACE: | ||
1252 | dev_dbg(bdc->dev, "USB_RECIP_INTERFACE\n"); | ||
1253 | /* USB3 spec, sec 9.4.9 */ | ||
1254 | if (wValue != USB_INTRF_FUNC_SUSPEND) | ||
1255 | return -EINVAL; | ||
1256 | /* USB3 spec, Table 9-8 */ | ||
1257 | if (set) { | ||
1258 | if (wIndex & USB_INTRF_FUNC_SUSPEND_RW) { | ||
1259 | dev_dbg(bdc->dev, "SET REMOTE_WAKEUP\n"); | ||
1260 | bdc->devstatus |= REMOTE_WAKE_ENABLE; | ||
1261 | } else { | ||
1262 | dev_dbg(bdc->dev, "CLEAR REMOTE_WAKEUP\n"); | ||
1263 | bdc->devstatus &= ~REMOTE_WAKE_ENABLE; | ||
1264 | } | ||
1265 | } | ||
1266 | break; | ||
1267 | |||
1268 | case USB_RECIP_ENDPOINT: | ||
1269 | dev_dbg(bdc->dev, "USB_RECIP_ENDPOINT\n"); | ||
1270 | if (wValue != USB_ENDPOINT_HALT) | ||
1271 | return -EINVAL; | ||
1272 | |||
1273 | epnum = wIndex & USB_ENDPOINT_NUMBER_MASK; | ||
1274 | if (epnum) { | ||
1275 | if ((wIndex & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) | ||
1276 | epnum = epnum * 2 + 1; | ||
1277 | else | ||
1278 | epnum *= 2; | ||
1279 | } else { | ||
1280 | epnum = 1; /*EP0*/ | ||
1281 | } | ||
1282 | /* | ||
1283 | * If CLEAR_FEATURE on ep0 then don't do anything as the stall | ||
1284 | * condition on ep0 has already been cleared when SETUP packet | ||
1285 | * was received. | ||
1286 | */ | ||
1287 | if (epnum == 1 && !set) { | ||
1288 | dev_dbg(bdc->dev, "ep0 stall already cleared\n"); | ||
1289 | return 0; | ||
1290 | } | ||
1291 | dev_dbg(bdc->dev, "epnum=%d\n", epnum); | ||
1292 | ep = bdc->bdc_ep_array[epnum]; | ||
1293 | if (!ep) | ||
1294 | return -EINVAL; | ||
1295 | |||
1296 | return ep_set_halt(ep, set); | ||
1297 | default: | ||
1298 | dev_err(bdc->dev, "Unknown recipient\n"); | ||
1299 | return -EINVAL; | ||
1300 | } | ||
1301 | |||
1302 | return 0; | ||
1303 | } | ||
1304 | |||
1305 | /* GET_STATUS request handler */ | ||
1306 | static int ep0_handle_status(struct bdc *bdc, | ||
1307 | struct usb_ctrlrequest *setup_pkt) | ||
1308 | { | ||
1309 | enum usb_device_state state = bdc->gadget.state; | ||
1310 | struct bdc_ep *ep; | ||
1311 | u16 usb_status = 0; | ||
1312 | u32 epnum; | ||
1313 | u16 wIndex; | ||
1314 | |||
1315 | /* USB2.0 spec sec 9.4.5 */ | ||
1316 | if (state == USB_STATE_DEFAULT) | ||
1317 | return -EINVAL; | ||
1318 | wIndex = le16_to_cpu(setup_pkt->wIndex); | ||
1319 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
1320 | usb_status = bdc->devstatus; | ||
1321 | switch (setup_pkt->bRequestType & USB_RECIP_MASK) { | ||
1322 | case USB_RECIP_DEVICE: | ||
1323 | dev_dbg(bdc->dev, | ||
1324 | "USB_RECIP_DEVICE devstatus:%08x\n", | ||
1325 | bdc->devstatus); | ||
1326 | /* USB3 spec, sec 9.4.5 */ | ||
1327 | if (bdc->gadget.speed == USB_SPEED_SUPER) | ||
1328 | usb_status &= ~REMOTE_WAKE_ENABLE; | ||
1329 | break; | ||
1330 | |||
1331 | case USB_RECIP_INTERFACE: | ||
1332 | dev_dbg(bdc->dev, "USB_RECIP_INTERFACE\n"); | ||
1333 | if (bdc->gadget.speed == USB_SPEED_SUPER) { | ||
1334 | /* | ||
1335 | * This should come from func for Func remote wkup | ||
1336 | * usb_status |=1; | ||
1337 | */ | ||
1338 | if (bdc->devstatus & REMOTE_WAKE_ENABLE) | ||
1339 | usb_status |= REMOTE_WAKE_ENABLE; | ||
1340 | } else { | ||
1341 | usb_status = 0; | ||
1342 | } | ||
1343 | |||
1344 | break; | ||
1345 | |||
1346 | case USB_RECIP_ENDPOINT: | ||
1347 | dev_dbg(bdc->dev, "USB_RECIP_ENDPOINT\n"); | ||
1348 | epnum = wIndex & USB_ENDPOINT_NUMBER_MASK; | ||
1349 | if (epnum) { | ||
1350 | if ((wIndex & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) | ||
1351 | epnum = epnum*2 + 1; | ||
1352 | else | ||
1353 | epnum *= 2; | ||
1354 | } else { | ||
1355 | epnum = 1; /* EP0 */ | ||
1356 | } | ||
1357 | |||
1358 | ep = bdc->bdc_ep_array[epnum]; | ||
1359 | if (!ep) { | ||
1360 | dev_err(bdc->dev, "ISSUE, GET_STATUS for invalid EP ?"); | ||
1361 | return -EINVAL; | ||
1362 | } | ||
1363 | if (ep->flags & BDC_EP_STALL) | ||
1364 | usb_status |= 1 << USB_ENDPOINT_HALT; | ||
1365 | |||
1366 | break; | ||
1367 | default: | ||
1368 | dev_err(bdc->dev, "Unknown recipient for get_status\n"); | ||
1369 | return -EINVAL; | ||
1370 | } | ||
1371 | /* prepare a data stage for GET_STATUS */ | ||
1372 | dev_dbg(bdc->dev, "usb_status=%08x\n", usb_status); | ||
1373 | *(__le16 *)bdc->ep0_response_buff = cpu_to_le16(usb_status); | ||
1374 | bdc->ep0_req.usb_req.length = 2; | ||
1375 | bdc->ep0_req.usb_req.buf = &bdc->ep0_response_buff; | ||
1376 | ep0_queue_data_stage(bdc); | ||
1377 | |||
1378 | return 0; | ||
1379 | } | ||
1380 | |||
1381 | static void ep0_set_sel_cmpl(struct usb_ep *_ep, struct usb_request *_req) | ||
1382 | { | ||
1383 | /* ep0_set_sel_cmpl */ | ||
1384 | } | ||
1385 | |||
1386 | /* Queue data stage to handle 6 byte SET_SEL request */ | ||
1387 | static int ep0_set_sel(struct bdc *bdc, | ||
1388 | struct usb_ctrlrequest *setup_pkt) | ||
1389 | { | ||
1390 | struct bdc_ep *ep; | ||
1391 | u16 wLength; | ||
1392 | u16 wValue; | ||
1393 | |||
1394 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
1395 | wValue = le16_to_cpu(setup_pkt->wValue); | ||
1396 | wLength = le16_to_cpu(setup_pkt->wLength); | ||
1397 | if (unlikely(wLength != 6)) { | ||
1398 | dev_err(bdc->dev, "%s Wrong wLength:%d\n", __func__, wLength); | ||
1399 | return -EINVAL; | ||
1400 | } | ||
1401 | ep = bdc->bdc_ep_array[1]; | ||
1402 | bdc->ep0_req.ep = ep; | ||
1403 | bdc->ep0_req.usb_req.length = 6; | ||
1404 | bdc->ep0_req.usb_req.buf = bdc->ep0_response_buff; | ||
1405 | bdc->ep0_req.usb_req.complete = ep0_set_sel_cmpl; | ||
1406 | ep0_queue_data_stage(bdc); | ||
1407 | |||
1408 | return 0; | ||
1409 | } | ||
1410 | |||
1411 | /* | ||
1412 | * Queue a 0 byte bd only if wLength is more than the length and and length is | ||
1413 | * a multiple of MaxPacket then queue 0 byte BD | ||
1414 | */ | ||
1415 | static int ep0_queue_zlp(struct bdc *bdc) | ||
1416 | { | ||
1417 | int ret; | ||
1418 | |||
1419 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
1420 | bdc->ep0_req.ep = bdc->bdc_ep_array[1]; | ||
1421 | bdc->ep0_req.usb_req.length = 0; | ||
1422 | bdc->ep0_req.usb_req.complete = NULL; | ||
1423 | bdc->ep0_state = WAIT_FOR_DATA_START; | ||
1424 | ret = bdc_queue_xfr(bdc, &bdc->ep0_req); | ||
1425 | if (ret) { | ||
1426 | dev_err(bdc->dev, "err queueing zlp :%d\n", ret); | ||
1427 | return ret; | ||
1428 | } | ||
1429 | bdc->ep0_state = WAIT_FOR_DATA_XMIT; | ||
1430 | |||
1431 | return 0; | ||
1432 | } | ||
1433 | |||
1434 | /* Control request handler */ | ||
1435 | static int handle_control_request(struct bdc *bdc) | ||
1436 | { | ||
1437 | enum usb_device_state state = bdc->gadget.state; | ||
1438 | struct usb_ctrlrequest *setup_pkt; | ||
1439 | int delegate_setup = 0; | ||
1440 | int ret = 0; | ||
1441 | int config = 0; | ||
1442 | |||
1443 | setup_pkt = &bdc->setup_pkt; | ||
1444 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
1445 | if ((setup_pkt->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { | ||
1446 | switch (setup_pkt->bRequest) { | ||
1447 | case USB_REQ_SET_ADDRESS: | ||
1448 | dev_dbg(bdc->dev, "USB_REQ_SET_ADDRESS\n"); | ||
1449 | ret = ep0_set_address(bdc, setup_pkt); | ||
1450 | bdc->devstatus &= DEVSTATUS_CLEAR; | ||
1451 | break; | ||
1452 | |||
1453 | case USB_REQ_SET_CONFIGURATION: | ||
1454 | dev_dbg(bdc->dev, "USB_REQ_SET_CONFIGURATION\n"); | ||
1455 | if (state == USB_STATE_ADDRESS) { | ||
1456 | usb_gadget_set_state(&bdc->gadget, | ||
1457 | USB_STATE_CONFIGURED); | ||
1458 | } else if (state == USB_STATE_CONFIGURED) { | ||
1459 | /* | ||
1460 | * USB2 spec sec 9.4.7, if wValue is 0 then dev | ||
1461 | * is moved to addressed state | ||
1462 | */ | ||
1463 | config = le16_to_cpu(setup_pkt->wValue); | ||
1464 | if (!config) | ||
1465 | usb_gadget_set_state( | ||
1466 | &bdc->gadget, | ||
1467 | USB_STATE_ADDRESS); | ||
1468 | } | ||
1469 | delegate_setup = 1; | ||
1470 | break; | ||
1471 | |||
1472 | case USB_REQ_SET_FEATURE: | ||
1473 | dev_dbg(bdc->dev, "USB_REQ_SET_FEATURE\n"); | ||
1474 | ret = ep0_handle_feature(bdc, setup_pkt, 1); | ||
1475 | break; | ||
1476 | |||
1477 | case USB_REQ_CLEAR_FEATURE: | ||
1478 | dev_dbg(bdc->dev, "USB_REQ_CLEAR_FEATURE\n"); | ||
1479 | ret = ep0_handle_feature(bdc, setup_pkt, 0); | ||
1480 | break; | ||
1481 | |||
1482 | case USB_REQ_GET_STATUS: | ||
1483 | dev_dbg(bdc->dev, "USB_REQ_GET_STATUS\n"); | ||
1484 | ret = ep0_handle_status(bdc, setup_pkt); | ||
1485 | break; | ||
1486 | |||
1487 | case USB_REQ_SET_SEL: | ||
1488 | dev_dbg(bdc->dev, "USB_REQ_SET_SEL\n"); | ||
1489 | ret = ep0_set_sel(bdc, setup_pkt); | ||
1490 | break; | ||
1491 | |||
1492 | case USB_REQ_SET_ISOCH_DELAY: | ||
1493 | dev_warn(bdc->dev, | ||
1494 | "USB_REQ_SET_ISOCH_DELAY not handled\n"); | ||
1495 | ret = 0; | ||
1496 | break; | ||
1497 | default: | ||
1498 | delegate_setup = 1; | ||
1499 | } | ||
1500 | } else { | ||
1501 | delegate_setup = 1; | ||
1502 | } | ||
1503 | |||
1504 | if (delegate_setup) { | ||
1505 | spin_unlock(&bdc->lock); | ||
1506 | ret = bdc->gadget_driver->setup(&bdc->gadget, setup_pkt); | ||
1507 | spin_lock(&bdc->lock); | ||
1508 | } | ||
1509 | |||
1510 | return ret; | ||
1511 | } | ||
1512 | |||
1513 | /* EP0: Data stage started */ | ||
1514 | void bdc_xsf_ep0_data_start(struct bdc *bdc, struct bdc_sr *sreport) | ||
1515 | { | ||
1516 | struct bdc_ep *ep; | ||
1517 | int ret = 0; | ||
1518 | |||
1519 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
1520 | ep = bdc->bdc_ep_array[1]; | ||
1521 | /* If ep0 was stalled, the clear it first */ | ||
1522 | if (ep->flags & BDC_EP_STALL) { | ||
1523 | ret = ep_set_halt(ep, 0); | ||
1524 | if (ret) | ||
1525 | goto err; | ||
1526 | } | ||
1527 | if (bdc->ep0_state != WAIT_FOR_DATA_START) | ||
1528 | dev_warn(bdc->dev, | ||
1529 | "Data stage not expected ep0_state:%s\n", | ||
1530 | ep0_state_string[bdc->ep0_state]); | ||
1531 | |||
1532 | ret = handle_control_request(bdc); | ||
1533 | if (ret == USB_GADGET_DELAYED_STATUS) { | ||
1534 | /* | ||
1535 | * The ep0 state will remain WAIT_FOR_DATA_START till | ||
1536 | * we received ep_queue on ep0 | ||
1537 | */ | ||
1538 | bdc->delayed_status = true; | ||
1539 | return; | ||
1540 | } | ||
1541 | if (!ret) { | ||
1542 | bdc->ep0_state = WAIT_FOR_DATA_XMIT; | ||
1543 | dev_dbg(bdc->dev, | ||
1544 | "ep0_state:%s", ep0_state_string[bdc->ep0_state]); | ||
1545 | return; | ||
1546 | } | ||
1547 | err: | ||
1548 | ep0_stall(bdc); | ||
1549 | } | ||
1550 | |||
1551 | /* EP0: status stage started */ | ||
1552 | void bdc_xsf_ep0_status_start(struct bdc *bdc, struct bdc_sr *sreport) | ||
1553 | { | ||
1554 | struct usb_ctrlrequest *setup_pkt; | ||
1555 | struct bdc_ep *ep; | ||
1556 | int ret = 0; | ||
1557 | |||
1558 | dev_dbg(bdc->dev, | ||
1559 | "%s ep0_state:%s", | ||
1560 | __func__, ep0_state_string[bdc->ep0_state]); | ||
1561 | ep = bdc->bdc_ep_array[1]; | ||
1562 | |||
1563 | /* check if ZLP was queued? */ | ||
1564 | if (bdc->zlp_needed) | ||
1565 | bdc->zlp_needed = false; | ||
1566 | |||
1567 | if (ep->flags & BDC_EP_STALL) { | ||
1568 | ret = ep_set_halt(ep, 0); | ||
1569 | if (ret) | ||
1570 | goto err; | ||
1571 | } | ||
1572 | |||
1573 | if ((bdc->ep0_state != WAIT_FOR_STATUS_START) && | ||
1574 | (bdc->ep0_state != WAIT_FOR_DATA_XMIT)) | ||
1575 | dev_err(bdc->dev, | ||
1576 | "Status stage recv but ep0_state:%s\n", | ||
1577 | ep0_state_string[bdc->ep0_state]); | ||
1578 | |||
1579 | /* check if data stage is in progress ? */ | ||
1580 | if (bdc->ep0_state == WAIT_FOR_DATA_XMIT) { | ||
1581 | bdc->ep0_state = STATUS_PENDING; | ||
1582 | /* Status stage will be queued upon Data stage transmit event */ | ||
1583 | dev_dbg(bdc->dev, | ||
1584 | "status started but data not transmitted yet\n"); | ||
1585 | return; | ||
1586 | } | ||
1587 | setup_pkt = &bdc->setup_pkt; | ||
1588 | |||
1589 | /* | ||
1590 | * 2 stage setup then only process the setup, for 3 stage setup the date | ||
1591 | * stage is already handled | ||
1592 | */ | ||
1593 | if (!le16_to_cpu(setup_pkt->wLength)) { | ||
1594 | ret = handle_control_request(bdc); | ||
1595 | if (ret == USB_GADGET_DELAYED_STATUS) { | ||
1596 | bdc->delayed_status = true; | ||
1597 | /* ep0_state will remain WAIT_FOR_STATUS_START */ | ||
1598 | return; | ||
1599 | } | ||
1600 | } | ||
1601 | if (!ret) { | ||
1602 | /* Queue a status stage BD */ | ||
1603 | ep0_queue_status_stage(bdc); | ||
1604 | bdc->ep0_state = WAIT_FOR_STATUS_XMIT; | ||
1605 | dev_dbg(bdc->dev, | ||
1606 | "ep0_state:%s", ep0_state_string[bdc->ep0_state]); | ||
1607 | return; | ||
1608 | } | ||
1609 | err: | ||
1610 | ep0_stall(bdc); | ||
1611 | } | ||
1612 | |||
1613 | /* Helper function to update ep0 upon SR with xsf_succ or xsf_short */ | ||
1614 | static void ep0_xsf_complete(struct bdc *bdc, struct bdc_sr *sreport) | ||
1615 | { | ||
1616 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
1617 | switch (bdc->ep0_state) { | ||
1618 | case WAIT_FOR_DATA_XMIT: | ||
1619 | bdc->ep0_state = WAIT_FOR_STATUS_START; | ||
1620 | break; | ||
1621 | case WAIT_FOR_STATUS_XMIT: | ||
1622 | bdc->ep0_state = WAIT_FOR_SETUP; | ||
1623 | if (bdc->test_mode) { | ||
1624 | int ret; | ||
1625 | |||
1626 | dev_dbg(bdc->dev, "test_mode:%d\n", bdc->test_mode); | ||
1627 | ret = bdc_set_test_mode(bdc); | ||
1628 | if (ret < 0) { | ||
1629 | dev_err(bdc->dev, "Err in setting Test mode\n"); | ||
1630 | return; | ||
1631 | } | ||
1632 | bdc->test_mode = 0; | ||
1633 | } | ||
1634 | break; | ||
1635 | case STATUS_PENDING: | ||
1636 | bdc_xsf_ep0_status_start(bdc, sreport); | ||
1637 | break; | ||
1638 | |||
1639 | default: | ||
1640 | dev_err(bdc->dev, | ||
1641 | "Unknown ep0_state:%s\n", | ||
1642 | ep0_state_string[bdc->ep0_state]); | ||
1643 | |||
1644 | } | ||
1645 | } | ||
1646 | |||
1647 | /* xfr completion status report handler */ | ||
1648 | void bdc_sr_xsf(struct bdc *bdc, struct bdc_sr *sreport) | ||
1649 | { | ||
1650 | struct bdc_ep *ep; | ||
1651 | u32 sr_status; | ||
1652 | u8 ep_num; | ||
1653 | |||
1654 | ep_num = (le32_to_cpu(sreport->offset[3])>>4) & 0x1f; | ||
1655 | ep = bdc->bdc_ep_array[ep_num]; | ||
1656 | if (!ep || !(ep->flags & BDC_EP_ENABLED)) { | ||
1657 | dev_err(bdc->dev, "xsf for ep not enabled\n"); | ||
1658 | return; | ||
1659 | } | ||
1660 | /* | ||
1661 | * check if this transfer is after link went from U3->U0 due | ||
1662 | * to remote wakeup | ||
1663 | */ | ||
1664 | if (bdc->devstatus & FUNC_WAKE_ISSUED) { | ||
1665 | bdc->devstatus &= ~(FUNC_WAKE_ISSUED); | ||
1666 | dev_dbg(bdc->dev, "%s clearing FUNC_WAKE_ISSUED flag\n", | ||
1667 | __func__); | ||
1668 | } | ||
1669 | sr_status = XSF_STS(le32_to_cpu(sreport->offset[3])); | ||
1670 | dev_dbg_ratelimited(bdc->dev, "%s sr_status=%d ep:%s\n", | ||
1671 | __func__, sr_status, ep->name); | ||
1672 | |||
1673 | switch (sr_status) { | ||
1674 | case XSF_SUCC: | ||
1675 | case XSF_SHORT: | ||
1676 | handle_xsr_succ_status(bdc, ep, sreport); | ||
1677 | if (ep_num == 1) | ||
1678 | ep0_xsf_complete(bdc, sreport); | ||
1679 | break; | ||
1680 | |||
1681 | case XSF_SETUP_RECV: | ||
1682 | case XSF_DATA_START: | ||
1683 | case XSF_STATUS_START: | ||
1684 | if (ep_num != 1) { | ||
1685 | dev_err(bdc->dev, | ||
1686 | "ep0 related packets on non ep0 endpoint"); | ||
1687 | return; | ||
1688 | } | ||
1689 | bdc->sr_xsf_ep0[sr_status - XSF_SETUP_RECV](bdc, sreport); | ||
1690 | break; | ||
1691 | |||
1692 | case XSF_BABB: | ||
1693 | if (ep_num == 1) { | ||
1694 | dev_dbg(bdc->dev, "Babble on ep0 zlp_need:%d\n", | ||
1695 | bdc->zlp_needed); | ||
1696 | /* | ||
1697 | * If the last completed transfer had wLength >Data Len, | ||
1698 | * and Len is multiple of MaxPacket,then queue ZLP | ||
1699 | */ | ||
1700 | if (bdc->zlp_needed) { | ||
1701 | /* queue 0 length bd */ | ||
1702 | ep0_queue_zlp(bdc); | ||
1703 | return; | ||
1704 | } | ||
1705 | } | ||
1706 | dev_warn(bdc->dev, "Babble on ep not handled\n"); | ||
1707 | break; | ||
1708 | default: | ||
1709 | dev_warn(bdc->dev, "sr status not handled:%x\n", sr_status); | ||
1710 | break; | ||
1711 | } | ||
1712 | } | ||
1713 | |||
1714 | static int bdc_gadget_ep_queue(struct usb_ep *_ep, | ||
1715 | struct usb_request *_req, gfp_t gfp_flags) | ||
1716 | { | ||
1717 | struct bdc_req *req; | ||
1718 | unsigned long flags; | ||
1719 | struct bdc_ep *ep; | ||
1720 | struct bdc *bdc; | ||
1721 | int ret; | ||
1722 | |||
1723 | if (!_ep || !_ep->desc) | ||
1724 | return -ESHUTDOWN; | ||
1725 | |||
1726 | if (!_req || !_req->complete || !_req->buf) | ||
1727 | return -EINVAL; | ||
1728 | |||
1729 | ep = to_bdc_ep(_ep); | ||
1730 | req = to_bdc_req(_req); | ||
1731 | bdc = ep->bdc; | ||
1732 | dev_dbg(bdc->dev, "%s ep:%p req:%p\n", __func__, ep, req); | ||
1733 | dev_dbg(bdc->dev, "queuing request %p to %s length %d zero:%d\n", | ||
1734 | _req, ep->name, _req->length, _req->zero); | ||
1735 | |||
1736 | if (!ep->usb_ep.desc) { | ||
1737 | dev_warn(bdc->dev, | ||
1738 | "trying to queue req %p to disabled %s\n", | ||
1739 | _req, ep->name); | ||
1740 | return -ESHUTDOWN; | ||
1741 | } | ||
1742 | |||
1743 | if (_req->length > MAX_XFR_LEN) { | ||
1744 | dev_warn(bdc->dev, | ||
1745 | "req length > supported MAX:%d requested:%d\n", | ||
1746 | MAX_XFR_LEN, _req->length); | ||
1747 | return -EOPNOTSUPP; | ||
1748 | } | ||
1749 | spin_lock_irqsave(&bdc->lock, flags); | ||
1750 | if (ep == bdc->bdc_ep_array[1]) | ||
1751 | ret = ep0_queue(ep, req); | ||
1752 | else | ||
1753 | ret = ep_queue(ep, req); | ||
1754 | |||
1755 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
1756 | |||
1757 | return ret; | ||
1758 | } | ||
1759 | |||
1760 | static int bdc_gadget_ep_dequeue(struct usb_ep *_ep, | ||
1761 | struct usb_request *_req) | ||
1762 | { | ||
1763 | struct bdc_req *req; | ||
1764 | unsigned long flags; | ||
1765 | struct bdc_ep *ep; | ||
1766 | struct bdc *bdc; | ||
1767 | int ret; | ||
1768 | |||
1769 | if (!_ep || !_req) | ||
1770 | return -EINVAL; | ||
1771 | |||
1772 | ep = to_bdc_ep(_ep); | ||
1773 | req = to_bdc_req(_req); | ||
1774 | bdc = ep->bdc; | ||
1775 | dev_dbg(bdc->dev, "%s ep:%s req:%p\n", __func__, ep->name, req); | ||
1776 | bdc_dbg_bd_list(bdc, ep); | ||
1777 | spin_lock_irqsave(&bdc->lock, flags); | ||
1778 | /* make sure it's still queued on this endpoint */ | ||
1779 | list_for_each_entry(req, &ep->queue, queue) { | ||
1780 | if (&req->usb_req == _req) | ||
1781 | break; | ||
1782 | } | ||
1783 | if (&req->usb_req != _req) { | ||
1784 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
1785 | dev_err(bdc->dev, "usb_req !=req n"); | ||
1786 | return -EINVAL; | ||
1787 | } | ||
1788 | ret = ep_dequeue(ep, req); | ||
1789 | if (ret) { | ||
1790 | ret = -EOPNOTSUPP; | ||
1791 | goto err; | ||
1792 | } | ||
1793 | bdc_req_complete(ep, req, -ECONNRESET); | ||
1794 | |||
1795 | err: | ||
1796 | bdc_dbg_bd_list(bdc, ep); | ||
1797 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
1798 | |||
1799 | return ret; | ||
1800 | } | ||
1801 | |||
1802 | static int bdc_gadget_ep_set_halt(struct usb_ep *_ep, int value) | ||
1803 | { | ||
1804 | unsigned long flags; | ||
1805 | struct bdc_ep *ep; | ||
1806 | struct bdc *bdc; | ||
1807 | int ret; | ||
1808 | |||
1809 | ep = to_bdc_ep(_ep); | ||
1810 | bdc = ep->bdc; | ||
1811 | dev_dbg(bdc->dev, "%s ep:%s value=%d\n", __func__, ep->name, value); | ||
1812 | spin_lock_irqsave(&bdc->lock, flags); | ||
1813 | if (usb_endpoint_xfer_isoc(ep->usb_ep.desc)) | ||
1814 | ret = -EINVAL; | ||
1815 | else if (!list_empty(&ep->queue)) | ||
1816 | ret = -EAGAIN; | ||
1817 | else | ||
1818 | ret = ep_set_halt(ep, value); | ||
1819 | |||
1820 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
1821 | |||
1822 | return ret; | ||
1823 | } | ||
1824 | |||
1825 | static struct usb_request *bdc_gadget_alloc_request(struct usb_ep *_ep, | ||
1826 | gfp_t gfp_flags) | ||
1827 | { | ||
1828 | struct bdc_req *req; | ||
1829 | struct bdc_ep *ep; | ||
1830 | |||
1831 | req = kzalloc(sizeof(*req), gfp_flags); | ||
1832 | if (!req) | ||
1833 | return NULL; | ||
1834 | |||
1835 | ep = to_bdc_ep(_ep); | ||
1836 | req->ep = ep; | ||
1837 | req->epnum = ep->ep_num; | ||
1838 | req->usb_req.dma = DMA_ADDR_INVALID; | ||
1839 | dev_dbg(ep->bdc->dev, "%s ep:%s req:%p\n", __func__, ep->name, req); | ||
1840 | |||
1841 | return &req->usb_req; | ||
1842 | } | ||
1843 | |||
1844 | static void bdc_gadget_free_request(struct usb_ep *_ep, | ||
1845 | struct usb_request *_req) | ||
1846 | { | ||
1847 | struct bdc_req *req; | ||
1848 | |||
1849 | req = to_bdc_req(_req); | ||
1850 | kfree(req); | ||
1851 | } | ||
1852 | |||
1853 | /* endpoint operations */ | ||
1854 | |||
1855 | /* configure endpoint and also allocate resources */ | ||
1856 | static int bdc_gadget_ep_enable(struct usb_ep *_ep, | ||
1857 | const struct usb_endpoint_descriptor *desc) | ||
1858 | { | ||
1859 | unsigned long flags; | ||
1860 | struct bdc_ep *ep; | ||
1861 | struct bdc *bdc; | ||
1862 | int ret; | ||
1863 | |||
1864 | if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { | ||
1865 | pr_debug("bdc_gadget_ep_enable invalid parameters\n"); | ||
1866 | return -EINVAL; | ||
1867 | } | ||
1868 | |||
1869 | if (!desc->wMaxPacketSize) { | ||
1870 | pr_debug("bdc_gadget_ep_enable missing wMaxPacketSize\n"); | ||
1871 | return -EINVAL; | ||
1872 | } | ||
1873 | |||
1874 | ep = to_bdc_ep(_ep); | ||
1875 | bdc = ep->bdc; | ||
1876 | |||
1877 | /* Sanity check, upper layer will not send enable for ep0 */ | ||
1878 | if (ep == bdc->bdc_ep_array[1]) | ||
1879 | return -EINVAL; | ||
1880 | |||
1881 | if (!bdc->gadget_driver | ||
1882 | || bdc->gadget.speed == USB_SPEED_UNKNOWN) { | ||
1883 | return -ESHUTDOWN; | ||
1884 | } | ||
1885 | |||
1886 | dev_dbg(bdc->dev, "%s Enabling %s\n", __func__, ep->name); | ||
1887 | spin_lock_irqsave(&bdc->lock, flags); | ||
1888 | ep->desc = desc; | ||
1889 | ep->comp_desc = _ep->comp_desc; | ||
1890 | ret = bdc_ep_enable(ep); | ||
1891 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
1892 | |||
1893 | return ret; | ||
1894 | } | ||
1895 | |||
1896 | static int bdc_gadget_ep_disable(struct usb_ep *_ep) | ||
1897 | { | ||
1898 | unsigned long flags; | ||
1899 | struct bdc_ep *ep; | ||
1900 | struct bdc *bdc; | ||
1901 | int ret; | ||
1902 | |||
1903 | if (!_ep) { | ||
1904 | pr_debug("bdc: invalid parameters\n"); | ||
1905 | return -EINVAL; | ||
1906 | } | ||
1907 | ep = to_bdc_ep(_ep); | ||
1908 | bdc = ep->bdc; | ||
1909 | |||
1910 | /* Upper layer will not call this for ep0, but do a sanity check */ | ||
1911 | if (ep == bdc->bdc_ep_array[1]) { | ||
1912 | dev_warn(bdc->dev, "%s called for ep0\n", __func__); | ||
1913 | return -EINVAL; | ||
1914 | } | ||
1915 | dev_dbg(bdc->dev, | ||
1916 | "%s() ep:%s ep->flags:%08x\n", | ||
1917 | __func__, ep->name, ep->flags); | ||
1918 | |||
1919 | if (!(ep->flags & BDC_EP_ENABLED)) { | ||
1920 | dev_warn(bdc->dev, "%s is already disabled\n", ep->name); | ||
1921 | return 0; | ||
1922 | } | ||
1923 | spin_lock_irqsave(&bdc->lock, flags); | ||
1924 | ret = bdc_ep_disable(ep); | ||
1925 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
1926 | |||
1927 | return ret; | ||
1928 | } | ||
1929 | |||
1930 | static const struct usb_ep_ops bdc_gadget_ep_ops = { | ||
1931 | .enable = bdc_gadget_ep_enable, | ||
1932 | .disable = bdc_gadget_ep_disable, | ||
1933 | .alloc_request = bdc_gadget_alloc_request, | ||
1934 | .free_request = bdc_gadget_free_request, | ||
1935 | .queue = bdc_gadget_ep_queue, | ||
1936 | .dequeue = bdc_gadget_ep_dequeue, | ||
1937 | .set_halt = bdc_gadget_ep_set_halt | ||
1938 | }; | ||
1939 | |||
1940 | /* dir = 1 is IN */ | ||
1941 | static int init_ep(struct bdc *bdc, u32 epnum, u32 dir) | ||
1942 | { | ||
1943 | struct bdc_ep *ep; | ||
1944 | |||
1945 | dev_dbg(bdc->dev, "%s epnum=%d dir=%d\n", __func__, epnum, dir); | ||
1946 | ep = kzalloc(sizeof(*ep), GFP_KERNEL); | ||
1947 | if (!ep) | ||
1948 | return -ENOMEM; | ||
1949 | |||
1950 | ep->bdc = bdc; | ||
1951 | ep->dir = dir; | ||
1952 | |||
1953 | /* ep->ep_num is the index inside bdc_ep */ | ||
1954 | if (epnum == 1) { | ||
1955 | ep->ep_num = 1; | ||
1956 | bdc->bdc_ep_array[ep->ep_num] = ep; | ||
1957 | snprintf(ep->name, sizeof(ep->name), "ep%d", epnum - 1); | ||
1958 | usb_ep_set_maxpacket_limit(&ep->usb_ep, EP0_MAX_PKT_SIZE); | ||
1959 | ep->comp_desc = NULL; | ||
1960 | bdc->gadget.ep0 = &ep->usb_ep; | ||
1961 | } else { | ||
1962 | if (dir) | ||
1963 | ep->ep_num = epnum * 2 - 1; | ||
1964 | else | ||
1965 | ep->ep_num = epnum * 2 - 2; | ||
1966 | |||
1967 | bdc->bdc_ep_array[ep->ep_num] = ep; | ||
1968 | snprintf(ep->name, sizeof(ep->name), "ep%d%s", epnum - 1, | ||
1969 | dir & 1 ? "in" : "out"); | ||
1970 | |||
1971 | usb_ep_set_maxpacket_limit(&ep->usb_ep, 1024); | ||
1972 | ep->usb_ep.max_streams = 0; | ||
1973 | list_add_tail(&ep->usb_ep.ep_list, &bdc->gadget.ep_list); | ||
1974 | } | ||
1975 | ep->usb_ep.ops = &bdc_gadget_ep_ops; | ||
1976 | ep->usb_ep.name = ep->name; | ||
1977 | ep->flags = 0; | ||
1978 | ep->ignore_next_sr = false; | ||
1979 | dev_dbg(bdc->dev, "ep=%p ep->usb_ep.name=%s epnum=%d ep->epnum=%d\n", | ||
1980 | ep, ep->usb_ep.name, epnum, ep->ep_num); | ||
1981 | |||
1982 | INIT_LIST_HEAD(&ep->queue); | ||
1983 | |||
1984 | return 0; | ||
1985 | } | ||
1986 | |||
1987 | /* Init all ep */ | ||
1988 | int bdc_init_ep(struct bdc *bdc) | ||
1989 | { | ||
1990 | u8 epnum; | ||
1991 | int ret; | ||
1992 | |||
1993 | dev_dbg(bdc->dev, "%s()\n", __func__); | ||
1994 | INIT_LIST_HEAD(&bdc->gadget.ep_list); | ||
1995 | /* init ep0 */ | ||
1996 | ret = init_ep(bdc, 1, 0); | ||
1997 | if (ret) { | ||
1998 | dev_err(bdc->dev, "init ep ep0 fail %d\n", ret); | ||
1999 | return ret; | ||
2000 | } | ||
2001 | |||
2002 | for (epnum = 2; epnum <= bdc->num_eps / 2; epnum++) { | ||
2003 | /* OUT */ | ||
2004 | ret = init_ep(bdc, epnum, 0); | ||
2005 | if (ret) { | ||
2006 | dev_err(bdc->dev, | ||
2007 | "init ep failed for:%d error: %d\n", | ||
2008 | epnum, ret); | ||
2009 | return ret; | ||
2010 | } | ||
2011 | |||
2012 | /* IN */ | ||
2013 | ret = init_ep(bdc, epnum, 1); | ||
2014 | if (ret) { | ||
2015 | dev_err(bdc->dev, | ||
2016 | "init ep failed for:%d error: %d\n", | ||
2017 | epnum, ret); | ||
2018 | return ret; | ||
2019 | } | ||
2020 | } | ||
2021 | |||
2022 | return 0; | ||
2023 | } | ||
diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.h b/drivers/usb/gadget/udc/bdc/bdc_ep.h new file mode 100644 index 000000000000..8a6b36cbf2ea --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/bdc_ep.h | |||
@@ -0,0 +1,22 @@ | |||
1 | /* | ||
2 | * bdc_ep.h - header for the BDC debug functions | ||
3 | * | ||
4 | * Copyright (C) 2014 Broadcom Corporation | ||
5 | * | ||
6 | * Author: Ashwini Pahuja | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | #ifndef __LINUX_BDC_EP_H__ | ||
15 | #define __LINUX_BDC_EP_H__ | ||
16 | |||
17 | int bdc_init_ep(struct bdc *); | ||
18 | int bdc_ep_disable(struct bdc_ep *); | ||
19 | int bdc_ep_enable(struct bdc_ep *); | ||
20 | void bdc_free_ep(struct bdc *); | ||
21 | |||
22 | #endif /* __LINUX_BDC_EP_H__ */ | ||
diff --git a/drivers/usb/gadget/udc/bdc/bdc_pci.c b/drivers/usb/gadget/udc/bdc/bdc_pci.c new file mode 100644 index 000000000000..02968842b359 --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/bdc_pci.c | |||
@@ -0,0 +1,132 @@ | |||
1 | /* | ||
2 | * bdc_pci.c - BRCM BDC USB3.0 device controller PCI interface file. | ||
3 | * | ||
4 | * Copyright (C) 2014 Broadcom Corporation | ||
5 | * | ||
6 | * Author: Ashwini Pahuja | ||
7 | * | ||
8 | * Based on drivers under drivers/usb/ | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/slab.h> | ||
20 | #include <linux/pci.h> | ||
21 | #include <linux/pci_ids.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | |||
24 | #include "bdc.h" | ||
25 | |||
26 | #define BDC_PCI_PID 0x1570 | ||
27 | |||
28 | struct bdc_pci { | ||
29 | struct device *dev; | ||
30 | struct platform_device *bdc; | ||
31 | }; | ||
32 | |||
33 | static int bdc_setup_msi(struct pci_dev *pci) | ||
34 | { | ||
35 | int ret; | ||
36 | |||
37 | ret = pci_enable_msi(pci); | ||
38 | if (ret) { | ||
39 | pr_err("failed to allocate MSI entry\n"); | ||
40 | return ret; | ||
41 | } | ||
42 | |||
43 | return ret; | ||
44 | } | ||
45 | |||
46 | static int bdc_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) | ||
47 | { | ||
48 | struct resource res[2]; | ||
49 | struct platform_device *bdc; | ||
50 | struct bdc_pci *glue; | ||
51 | int ret = -ENOMEM; | ||
52 | |||
53 | glue = devm_kzalloc(&pci->dev, sizeof(*glue), GFP_KERNEL); | ||
54 | if (!glue) | ||
55 | return -ENOMEM; | ||
56 | |||
57 | glue->dev = &pci->dev; | ||
58 | ret = pci_enable_device(pci); | ||
59 | if (ret) { | ||
60 | dev_err(&pci->dev, "failed to enable pci device\n"); | ||
61 | return -ENODEV; | ||
62 | } | ||
63 | pci_set_master(pci); | ||
64 | |||
65 | bdc = platform_device_alloc(BRCM_BDC_NAME, PLATFORM_DEVID_AUTO); | ||
66 | if (!bdc) | ||
67 | return -ENOMEM; | ||
68 | |||
69 | memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); | ||
70 | bdc_setup_msi(pci); | ||
71 | |||
72 | res[0].start = pci_resource_start(pci, 0); | ||
73 | res[0].end = pci_resource_end(pci, 0); | ||
74 | res[0].name = BRCM_BDC_NAME; | ||
75 | res[0].flags = IORESOURCE_MEM; | ||
76 | |||
77 | res[1].start = pci->irq; | ||
78 | res[1].name = BRCM_BDC_NAME; | ||
79 | res[1].flags = IORESOURCE_IRQ; | ||
80 | |||
81 | ret = platform_device_add_resources(bdc, res, ARRAY_SIZE(res)); | ||
82 | if (ret) { | ||
83 | dev_err(&pci->dev, | ||
84 | "couldn't add resources to bdc device\n"); | ||
85 | return ret; | ||
86 | } | ||
87 | |||
88 | pci_set_drvdata(pci, glue); | ||
89 | |||
90 | dma_set_coherent_mask(&bdc->dev, pci->dev.coherent_dma_mask); | ||
91 | |||
92 | bdc->dev.dma_mask = pci->dev.dma_mask; | ||
93 | bdc->dev.dma_parms = pci->dev.dma_parms; | ||
94 | bdc->dev.parent = &pci->dev; | ||
95 | glue->bdc = bdc; | ||
96 | |||
97 | ret = platform_device_add(bdc); | ||
98 | if (ret) { | ||
99 | dev_err(&pci->dev, "failed to register bdc device\n"); | ||
100 | platform_device_put(bdc); | ||
101 | return ret; | ||
102 | } | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static void bdc_pci_remove(struct pci_dev *pci) | ||
108 | { | ||
109 | struct bdc_pci *glue = pci_get_drvdata(pci); | ||
110 | |||
111 | platform_device_unregister(glue->bdc); | ||
112 | pci_disable_msi(pci); | ||
113 | } | ||
114 | |||
115 | static struct pci_device_id bdc_pci_id_table[] = { | ||
116 | { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BDC_PCI_PID), }, | ||
117 | {} /* Terminating Entry */ | ||
118 | }; | ||
119 | |||
120 | MODULE_DEVICE_TABLE(pci, bdc_pci_id_table); | ||
121 | |||
122 | static struct pci_driver bdc_pci_driver = { | ||
123 | .name = "bdc-pci", | ||
124 | .id_table = bdc_pci_id_table, | ||
125 | .probe = bdc_pci_probe, | ||
126 | .remove = bdc_pci_remove, | ||
127 | }; | ||
128 | |||
129 | MODULE_AUTHOR("Ashwini Pahuja <ashwini.linux@gmail.com>"); | ||
130 | MODULE_LICENSE("GPL"); | ||
131 | MODULE_DESCRIPTION("BRCM BDC USB3 PCI Glue layer"); | ||
132 | module_pci_driver(bdc_pci_driver); | ||
diff --git a/drivers/usb/gadget/udc/bdc/bdc_udc.c b/drivers/usb/gadget/udc/bdc/bdc_udc.c new file mode 100644 index 000000000000..3700ce70b0be --- /dev/null +++ b/drivers/usb/gadget/udc/bdc/bdc_udc.c | |||
@@ -0,0 +1,587 @@ | |||
1 | /* | ||
2 | * bdc_udc.c - BRCM BDC USB3.0 device controller gagdet ops | ||
3 | * | ||
4 | * Copyright (C) 2014 Broadcom Corporation | ||
5 | * | ||
6 | * Author: Ashwini Pahuja | ||
7 | * | ||
8 | * Based on drivers under drivers/usb/gadget/udc/ | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | */ | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/pci.h> | ||
18 | #include <linux/dma-mapping.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/ioport.h> | ||
22 | #include <linux/sched.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/errno.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/timer.h> | ||
27 | #include <linux/list.h> | ||
28 | #include <linux/interrupt.h> | ||
29 | #include <linux/moduleparam.h> | ||
30 | #include <linux/device.h> | ||
31 | #include <linux/usb/ch9.h> | ||
32 | #include <linux/usb/gadget.h> | ||
33 | #include <linux/usb/otg.h> | ||
34 | #include <linux/pm.h> | ||
35 | #include <linux/io.h> | ||
36 | #include <linux/irq.h> | ||
37 | #include <asm/unaligned.h> | ||
38 | #include <linux/platform_device.h> | ||
39 | |||
40 | #include "bdc.h" | ||
41 | #include "bdc_ep.h" | ||
42 | #include "bdc_cmd.h" | ||
43 | #include "bdc_dbg.h" | ||
44 | |||
45 | static const struct usb_gadget_ops bdc_gadget_ops; | ||
46 | |||
47 | static const char * const conn_speed_str[] = { | ||
48 | "Not connected", | ||
49 | "Full Speed", | ||
50 | "Low Speed", | ||
51 | "High Speed", | ||
52 | "Super Speed", | ||
53 | }; | ||
54 | |||
55 | /* EP0 initial descripror */ | ||
56 | static struct usb_endpoint_descriptor bdc_gadget_ep0_desc = { | ||
57 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
58 | .bDescriptorType = USB_DT_ENDPOINT, | ||
59 | .bmAttributes = USB_ENDPOINT_XFER_CONTROL, | ||
60 | .bEndpointAddress = 0, | ||
61 | .wMaxPacketSize = cpu_to_le16(EP0_MAX_PKT_SIZE), | ||
62 | }; | ||
63 | |||
64 | /* Advance the srr dqp maintained by SW */ | ||
65 | static void srr_dqp_index_advc(struct bdc *bdc, u32 srr_num) | ||
66 | { | ||
67 | struct srr *srr; | ||
68 | |||
69 | srr = &bdc->srr; | ||
70 | dev_dbg_ratelimited(bdc->dev, "srr->dqp_index:%d\n", srr->dqp_index); | ||
71 | srr->dqp_index++; | ||
72 | /* rollback to 0 if we are past the last */ | ||
73 | if (srr->dqp_index == NUM_SR_ENTRIES) | ||
74 | srr->dqp_index = 0; | ||
75 | } | ||
76 | |||
77 | /* connect sr */ | ||
78 | static void bdc_uspc_connected(struct bdc *bdc) | ||
79 | { | ||
80 | u32 speed, temp; | ||
81 | u32 usppms; | ||
82 | int ret; | ||
83 | |||
84 | temp = bdc_readl(bdc->regs, BDC_USPC); | ||
85 | speed = BDC_PSP(temp); | ||
86 | dev_dbg(bdc->dev, "%s speed=%x\n", __func__, speed); | ||
87 | switch (speed) { | ||
88 | case BDC_SPEED_SS: | ||
89 | bdc_gadget_ep0_desc.wMaxPacketSize = | ||
90 | cpu_to_le16(EP0_MAX_PKT_SIZE); | ||
91 | bdc->gadget.ep0->maxpacket = EP0_MAX_PKT_SIZE; | ||
92 | bdc->gadget.speed = USB_SPEED_SUPER; | ||
93 | /* Enable U1T in SS mode */ | ||
94 | usppms = bdc_readl(bdc->regs, BDC_USPPMS); | ||
95 | usppms &= ~BDC_U1T(0xff); | ||
96 | usppms |= BDC_U1T(U1_TIMEOUT); | ||
97 | usppms |= BDC_PORT_W1S; | ||
98 | bdc_writel(bdc->regs, BDC_USPPMS, usppms); | ||
99 | break; | ||
100 | |||
101 | case BDC_SPEED_HS: | ||
102 | bdc_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); | ||
103 | bdc->gadget.ep0->maxpacket = 64; | ||
104 | bdc->gadget.speed = USB_SPEED_HIGH; | ||
105 | break; | ||
106 | |||
107 | case BDC_SPEED_FS: | ||
108 | bdc_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); | ||
109 | bdc->gadget.ep0->maxpacket = 64; | ||
110 | bdc->gadget.speed = USB_SPEED_FULL; | ||
111 | break; | ||
112 | |||
113 | case BDC_SPEED_LS: | ||
114 | bdc_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(8); | ||
115 | bdc->gadget.ep0->maxpacket = 8; | ||
116 | bdc->gadget.speed = USB_SPEED_LOW; | ||
117 | break; | ||
118 | default: | ||
119 | dev_err(bdc->dev, "UNDEFINED SPEED\n"); | ||
120 | return; | ||
121 | } | ||
122 | dev_dbg(bdc->dev, "connected at %s\n", conn_speed_str[speed]); | ||
123 | /* Now we know the speed, configure ep0 */ | ||
124 | bdc->bdc_ep_array[1]->desc = &bdc_gadget_ep0_desc; | ||
125 | ret = bdc_config_ep(bdc, bdc->bdc_ep_array[1]); | ||
126 | if (ret) | ||
127 | dev_err(bdc->dev, "EP0 config failed\n"); | ||
128 | bdc->bdc_ep_array[1]->usb_ep.desc = &bdc_gadget_ep0_desc; | ||
129 | bdc->bdc_ep_array[1]->flags |= BDC_EP_ENABLED; | ||
130 | usb_gadget_set_state(&bdc->gadget, USB_STATE_DEFAULT); | ||
131 | } | ||
132 | |||
133 | /* device got disconnected */ | ||
134 | static void bdc_uspc_disconnected(struct bdc *bdc, bool reinit) | ||
135 | { | ||
136 | struct bdc_ep *ep; | ||
137 | |||
138 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
139 | /* | ||
140 | * Only stop ep0 from here, rest of the endpoints will be disabled | ||
141 | * from gadget_disconnect | ||
142 | */ | ||
143 | ep = bdc->bdc_ep_array[1]; | ||
144 | if (ep && (ep->flags & BDC_EP_ENABLED)) | ||
145 | /* if enabled then stop and remove requests */ | ||
146 | bdc_ep_disable(ep); | ||
147 | |||
148 | if (bdc->gadget_driver && bdc->gadget_driver->disconnect) { | ||
149 | spin_unlock(&bdc->lock); | ||
150 | bdc->gadget_driver->disconnect(&bdc->gadget); | ||
151 | spin_lock(&bdc->lock); | ||
152 | } | ||
153 | /* Set Unknown speed */ | ||
154 | bdc->gadget.speed = USB_SPEED_UNKNOWN; | ||
155 | bdc->devstatus &= DEVSTATUS_CLEAR; | ||
156 | bdc->delayed_status = false; | ||
157 | bdc->reinit = reinit; | ||
158 | bdc->test_mode = false; | ||
159 | } | ||
160 | |||
161 | /* TNotify wkaeup timer */ | ||
162 | static void bdc_func_wake_timer(struct work_struct *work) | ||
163 | { | ||
164 | struct bdc *bdc = container_of(work, struct bdc, func_wake_notify.work); | ||
165 | unsigned long flags; | ||
166 | |||
167 | dev_dbg(bdc->dev, "%s\n", __func__); | ||
168 | spin_lock_irqsave(&bdc->lock, flags); | ||
169 | /* | ||
170 | * Check if host has started transferring on endpoints | ||
171 | * FUNC_WAKE_ISSUED is cleared when transfer has started after resume | ||
172 | */ | ||
173 | if (bdc->devstatus & FUNC_WAKE_ISSUED) { | ||
174 | dev_dbg(bdc->dev, "FUNC_WAKE_ISSUED FLAG IS STILL SET\n"); | ||
175 | /* flag is still set, so again send func wake */ | ||
176 | bdc_function_wake_fh(bdc, 0); | ||
177 | schedule_delayed_work(&bdc->func_wake_notify, | ||
178 | msecs_to_jiffies(BDC_TNOTIFY)); | ||
179 | } | ||
180 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
181 | } | ||
182 | |||
183 | /* handler for Link state change condition */ | ||
184 | static void handle_link_state_change(struct bdc *bdc, u32 uspc) | ||
185 | { | ||
186 | u32 link_state; | ||
187 | |||
188 | dev_dbg(bdc->dev, "Link state change"); | ||
189 | link_state = BDC_PST(uspc); | ||
190 | switch (link_state) { | ||
191 | case BDC_LINK_STATE_U3: | ||
192 | if ((bdc->gadget.speed != USB_SPEED_UNKNOWN) && | ||
193 | bdc->gadget_driver->suspend) { | ||
194 | dev_dbg(bdc->dev, "Entered Suspend mode\n"); | ||
195 | spin_unlock(&bdc->lock); | ||
196 | bdc->devstatus |= DEVICE_SUSPENDED; | ||
197 | bdc->gadget_driver->suspend(&bdc->gadget); | ||
198 | spin_lock(&bdc->lock); | ||
199 | } | ||
200 | break; | ||
201 | case BDC_LINK_STATE_U0: | ||
202 | if (bdc->devstatus & REMOTE_WAKEUP_ISSUED) { | ||
203 | bdc->devstatus &= ~REMOTE_WAKEUP_ISSUED; | ||
204 | if (bdc->gadget.speed == USB_SPEED_SUPER) { | ||
205 | bdc_function_wake_fh(bdc, 0); | ||
206 | bdc->devstatus |= FUNC_WAKE_ISSUED; | ||
207 | /* | ||
208 | * Start a Notification timer and check if the | ||
209 | * Host transferred anything on any of the EPs, | ||
210 | * if not then send function wake again every | ||
211 | * TNotification secs until host initiates | ||
212 | * transfer to BDC, USB3 spec Table 8.13 | ||
213 | */ | ||
214 | schedule_delayed_work( | ||
215 | &bdc->func_wake_notify, | ||
216 | msecs_to_jiffies(BDC_TNOTIFY)); | ||
217 | dev_dbg(bdc->dev, "sched func_wake_notify\n"); | ||
218 | } | ||
219 | } | ||
220 | break; | ||
221 | |||
222 | case BDC_LINK_STATE_RESUME: | ||
223 | dev_dbg(bdc->dev, "Resumed from Suspend\n"); | ||
224 | if (bdc->devstatus & DEVICE_SUSPENDED) { | ||
225 | bdc->gadget_driver->resume(&bdc->gadget); | ||
226 | bdc->devstatus &= ~DEVICE_SUSPENDED; | ||
227 | } | ||
228 | break; | ||
229 | default: | ||
230 | dev_dbg(bdc->dev, "link state:%d\n", link_state); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | /* something changes on upstream port, handle it here */ | ||
235 | void bdc_sr_uspc(struct bdc *bdc, struct bdc_sr *sreport) | ||
236 | { | ||
237 | u32 clear_flags = 0; | ||
238 | u32 uspc; | ||
239 | bool connected = false; | ||
240 | bool disconn = false; | ||
241 | |||
242 | uspc = bdc_readl(bdc->regs, BDC_USPC); | ||
243 | dev_dbg(bdc->dev, "%s uspc=0x%08x\n", __func__, uspc); | ||
244 | |||
245 | /* Port connect changed */ | ||
246 | if (uspc & BDC_PCC) { | ||
247 | /* Vbus not present, and not connected to Downstream port */ | ||
248 | if ((uspc & BDC_VBC) && !(uspc & BDC_VBS) && !(uspc & BDC_PCS)) | ||
249 | disconn = true; | ||
250 | else if ((uspc & BDC_PCS) && !BDC_PST(uspc)) | ||
251 | connected = true; | ||
252 | } | ||
253 | |||
254 | /* Change in VBus and VBus is present */ | ||
255 | if ((uspc & BDC_VBC) && (uspc & BDC_VBS)) { | ||
256 | if (bdc->pullup) { | ||
257 | dev_dbg(bdc->dev, "Do a softconnect\n"); | ||
258 | /* Attached state, do a softconnect */ | ||
259 | bdc_softconn(bdc); | ||
260 | usb_gadget_set_state(&bdc->gadget, USB_STATE_POWERED); | ||
261 | } | ||
262 | clear_flags = BDC_VBC; | ||
263 | } else if ((uspc & BDC_PRS) || (uspc & BDC_PRC) || disconn) { | ||
264 | /* Hot reset, warm reset, 2.0 bus reset or disconn */ | ||
265 | dev_dbg(bdc->dev, "Port reset or disconn\n"); | ||
266 | bdc_uspc_disconnected(bdc, disconn); | ||
267 | clear_flags = BDC_PCC|BDC_PCS|BDC_PRS|BDC_PRC; | ||
268 | } else if ((uspc & BDC_PSC) && (uspc & BDC_PCS)) { | ||
269 | /* Change in Link state */ | ||
270 | handle_link_state_change(bdc, uspc); | ||
271 | clear_flags = BDC_PSC|BDC_PCS; | ||
272 | } | ||
273 | |||
274 | /* | ||
275 | * In SS we might not have PRC bit set before connection, but in 2.0 | ||
276 | * the PRC bit is set before connection, so moving this condition out | ||
277 | * of bus reset to handle both SS/2.0 speeds. | ||
278 | */ | ||
279 | if (connected) { | ||
280 | /* This is the connect event for U0/L0 */ | ||
281 | dev_dbg(bdc->dev, "Connected\n"); | ||
282 | bdc_uspc_connected(bdc); | ||
283 | bdc->devstatus &= ~(DEVICE_SUSPENDED); | ||
284 | } | ||
285 | uspc = bdc_readl(bdc->regs, BDC_USPC); | ||
286 | uspc &= (~BDC_USPSC_RW); | ||
287 | dev_dbg(bdc->dev, "uspc=%x\n", uspc); | ||
288 | bdc_writel(bdc->regs, BDC_USPC, clear_flags); | ||
289 | } | ||
290 | |||
291 | /* Main interrupt handler for bdc */ | ||
292 | static irqreturn_t bdc_udc_interrupt(int irq, void *_bdc) | ||
293 | { | ||
294 | u32 eqp_index, dqp_index, sr_type, srr_int; | ||
295 | struct bdc_sr *sreport; | ||
296 | struct bdc *bdc = _bdc; | ||
297 | u32 status; | ||
298 | int ret; | ||
299 | |||
300 | spin_lock(&bdc->lock); | ||
301 | status = bdc_readl(bdc->regs, BDC_BDCSC); | ||
302 | if (!(status & BDC_GIP)) { | ||
303 | spin_unlock(&bdc->lock); | ||
304 | return IRQ_NONE; | ||
305 | } | ||
306 | srr_int = bdc_readl(bdc->regs, BDC_SRRINT(0)); | ||
307 | /* Check if the SRR IP bit it set? */ | ||
308 | if (!(srr_int & BDC_SRR_IP)) { | ||
309 | dev_warn(bdc->dev, "Global irq pending but SRR IP is 0\n"); | ||
310 | spin_unlock(&bdc->lock); | ||
311 | return IRQ_NONE; | ||
312 | } | ||
313 | eqp_index = BDC_SRR_EPI(srr_int); | ||
314 | dqp_index = BDC_SRR_DPI(srr_int); | ||
315 | dev_dbg(bdc->dev, | ||
316 | "%s eqp_index=%d dqp_index=%d srr.dqp_index=%d\n\n", | ||
317 | __func__, eqp_index, dqp_index, bdc->srr.dqp_index); | ||
318 | |||
319 | /* check for ring empty condition */ | ||
320 | if (eqp_index == dqp_index) { | ||
321 | dev_dbg(bdc->dev, "SRR empty?\n"); | ||
322 | spin_unlock(&bdc->lock); | ||
323 | return IRQ_HANDLED; | ||
324 | } | ||
325 | |||
326 | while (bdc->srr.dqp_index != eqp_index) { | ||
327 | sreport = &bdc->srr.sr_bds[bdc->srr.dqp_index]; | ||
328 | /* sreport is read before using it */ | ||
329 | rmb(); | ||
330 | sr_type = le32_to_cpu(sreport->offset[3]) & BD_TYPE_BITMASK; | ||
331 | dev_dbg_ratelimited(bdc->dev, "sr_type=%d\n", sr_type); | ||
332 | switch (sr_type) { | ||
333 | case SR_XSF: | ||
334 | bdc->sr_handler[0](bdc, sreport); | ||
335 | break; | ||
336 | |||
337 | case SR_USPC: | ||
338 | bdc->sr_handler[1](bdc, sreport); | ||
339 | break; | ||
340 | default: | ||
341 | dev_warn(bdc->dev, "SR:%d not handled\n", sr_type); | ||
342 | } | ||
343 | /* Advance the srr dqp index */ | ||
344 | srr_dqp_index_advc(bdc, 0); | ||
345 | } | ||
346 | /* update the hw dequeue pointer */ | ||
347 | srr_int = bdc_readl(bdc->regs, BDC_SRRINT(0)); | ||
348 | srr_int &= ~BDC_SRR_DPI_MASK; | ||
349 | srr_int &= ~(BDC_SRR_RWS|BDC_SRR_RST|BDC_SRR_ISR); | ||
350 | srr_int |= ((bdc->srr.dqp_index) << 16); | ||
351 | srr_int |= BDC_SRR_IP; | ||
352 | bdc_writel(bdc->regs, BDC_SRRINT(0), srr_int); | ||
353 | srr_int = bdc_readl(bdc->regs, BDC_SRRINT(0)); | ||
354 | if (bdc->reinit) { | ||
355 | ret = bdc_reinit(bdc); | ||
356 | if (ret) | ||
357 | dev_err(bdc->dev, "err in bdc reinit\n"); | ||
358 | } | ||
359 | |||
360 | spin_unlock(&bdc->lock); | ||
361 | |||
362 | return IRQ_HANDLED; | ||
363 | } | ||
364 | |||
365 | /* Gadget ops */ | ||
366 | static int bdc_udc_start(struct usb_gadget *gadget, | ||
367 | struct usb_gadget_driver *driver) | ||
368 | { | ||
369 | struct bdc *bdc = gadget_to_bdc(gadget); | ||
370 | unsigned long flags; | ||
371 | int ret = 0; | ||
372 | |||
373 | dev_dbg(bdc->dev, "%s()\n", __func__); | ||
374 | spin_lock_irqsave(&bdc->lock, flags); | ||
375 | if (bdc->gadget_driver) { | ||
376 | dev_err(bdc->dev, "%s is already bound to %s\n", | ||
377 | bdc->gadget.name, | ||
378 | bdc->gadget_driver->driver.name); | ||
379 | ret = -EBUSY; | ||
380 | goto err; | ||
381 | } | ||
382 | /* | ||
383 | * Run the controller from here and when BDC is connected to | ||
384 | * Host then driver will receive a USPC SR with VBUS present | ||
385 | * and then driver will do a softconnect. | ||
386 | */ | ||
387 | ret = bdc_run(bdc); | ||
388 | if (ret) { | ||
389 | dev_err(bdc->dev, "%s bdc run fail\n", __func__); | ||
390 | goto err; | ||
391 | } | ||
392 | bdc->gadget_driver = driver; | ||
393 | bdc->gadget.dev.driver = &driver->driver; | ||
394 | err: | ||
395 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
396 | |||
397 | return ret; | ||
398 | } | ||
399 | |||
400 | static int bdc_udc_stop(struct usb_gadget *gadget) | ||
401 | { | ||
402 | struct bdc *bdc = gadget_to_bdc(gadget); | ||
403 | unsigned long flags; | ||
404 | |||
405 | dev_dbg(bdc->dev, "%s()\n", __func__); | ||
406 | spin_lock_irqsave(&bdc->lock, flags); | ||
407 | bdc_stop(bdc); | ||
408 | bdc->gadget_driver = NULL; | ||
409 | bdc->gadget.dev.driver = NULL; | ||
410 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
411 | |||
412 | return 0; | ||
413 | } | ||
414 | |||
415 | static int bdc_udc_pullup(struct usb_gadget *gadget, int is_on) | ||
416 | { | ||
417 | struct bdc *bdc = gadget_to_bdc(gadget); | ||
418 | unsigned long flags; | ||
419 | u32 uspc; | ||
420 | |||
421 | dev_dbg(bdc->dev, "%s() is_on:%d\n", __func__, is_on); | ||
422 | if (!gadget) | ||
423 | return -EINVAL; | ||
424 | |||
425 | spin_lock_irqsave(&bdc->lock, flags); | ||
426 | if (!is_on) { | ||
427 | bdc_softdisconn(bdc); | ||
428 | bdc->pullup = false; | ||
429 | } else { | ||
430 | /* | ||
431 | * For a self powered device, we need to wait till we receive | ||
432 | * a VBUS change and Vbus present event, then if pullup flag | ||
433 | * is set, then only we present the Termintation. | ||
434 | */ | ||
435 | bdc->pullup = true; | ||
436 | /* | ||
437 | * Check if BDC is already connected to Host i.e Vbus=1, | ||
438 | * if yes, then present TERM now, this is typical for bus | ||
439 | * powered devices. | ||
440 | */ | ||
441 | uspc = bdc_readl(bdc->regs, BDC_USPC); | ||
442 | if (uspc & BDC_VBS) | ||
443 | bdc_softconn(bdc); | ||
444 | } | ||
445 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
446 | |||
447 | return 0; | ||
448 | } | ||
449 | |||
450 | static int bdc_udc_set_selfpowered(struct usb_gadget *gadget, | ||
451 | int is_self) | ||
452 | { | ||
453 | struct bdc *bdc = gadget_to_bdc(gadget); | ||
454 | unsigned long flags; | ||
455 | |||
456 | dev_dbg(bdc->dev, "%s()\n", __func__); | ||
457 | spin_lock_irqsave(&bdc->lock, flags); | ||
458 | if (!is_self) | ||
459 | bdc->devstatus |= 1 << USB_DEVICE_SELF_POWERED; | ||
460 | else | ||
461 | bdc->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED); | ||
462 | |||
463 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
464 | |||
465 | return 0; | ||
466 | } | ||
467 | |||
468 | static int bdc_udc_wakeup(struct usb_gadget *gadget) | ||
469 | { | ||
470 | struct bdc *bdc = gadget_to_bdc(gadget); | ||
471 | unsigned long flags; | ||
472 | u8 link_state; | ||
473 | u32 uspc; | ||
474 | int ret = 0; | ||
475 | |||
476 | dev_dbg(bdc->dev, | ||
477 | "%s() bdc->devstatus=%08x\n", | ||
478 | __func__, bdc->devstatus); | ||
479 | |||
480 | if (!(bdc->devstatus & REMOTE_WAKE_ENABLE)) | ||
481 | return -EOPNOTSUPP; | ||
482 | |||
483 | spin_lock_irqsave(&bdc->lock, flags); | ||
484 | uspc = bdc_readl(bdc->regs, BDC_USPC); | ||
485 | link_state = BDC_PST(uspc); | ||
486 | dev_dbg(bdc->dev, "link_state =%d portsc=%x", link_state, uspc); | ||
487 | if (link_state != BDC_LINK_STATE_U3) { | ||
488 | dev_warn(bdc->dev, | ||
489 | "can't wakeup from link state %d\n", | ||
490 | link_state); | ||
491 | ret = -EINVAL; | ||
492 | goto out; | ||
493 | } | ||
494 | if (bdc->gadget.speed == USB_SPEED_SUPER) | ||
495 | bdc->devstatus |= REMOTE_WAKEUP_ISSUED; | ||
496 | |||
497 | uspc &= ~BDC_PST_MASK; | ||
498 | uspc &= (~BDC_USPSC_RW); | ||
499 | uspc |= BDC_PST(BDC_LINK_STATE_U0); | ||
500 | uspc |= BDC_SWS; | ||
501 | bdc_writel(bdc->regs, BDC_USPC, uspc); | ||
502 | uspc = bdc_readl(bdc->regs, BDC_USPC); | ||
503 | link_state = BDC_PST(uspc); | ||
504 | dev_dbg(bdc->dev, "link_state =%d portsc=%x", link_state, uspc); | ||
505 | out: | ||
506 | spin_unlock_irqrestore(&bdc->lock, flags); | ||
507 | |||
508 | return ret; | ||
509 | } | ||
510 | |||
511 | static const struct usb_gadget_ops bdc_gadget_ops = { | ||
512 | .wakeup = bdc_udc_wakeup, | ||
513 | .set_selfpowered = bdc_udc_set_selfpowered, | ||
514 | .pullup = bdc_udc_pullup, | ||
515 | .udc_start = bdc_udc_start, | ||
516 | .udc_stop = bdc_udc_stop, | ||
517 | }; | ||
518 | |||
519 | /* Init the gadget interface and register the udc */ | ||
520 | int bdc_udc_init(struct bdc *bdc) | ||
521 | { | ||
522 | u32 temp; | ||
523 | int ret; | ||
524 | |||
525 | dev_dbg(bdc->dev, "%s()\n", __func__); | ||
526 | bdc->gadget.ops = &bdc_gadget_ops; | ||
527 | bdc->gadget.max_speed = USB_SPEED_SUPER; | ||
528 | bdc->gadget.speed = USB_SPEED_UNKNOWN; | ||
529 | bdc->gadget.dev.parent = bdc->dev; | ||
530 | |||
531 | bdc->gadget.sg_supported = false; | ||
532 | |||
533 | |||
534 | bdc->gadget.name = BRCM_BDC_NAME; | ||
535 | ret = devm_request_irq(bdc->dev, bdc->irq, bdc_udc_interrupt, | ||
536 | IRQF_SHARED , BRCM_BDC_NAME, bdc); | ||
537 | if (ret) { | ||
538 | dev_err(bdc->dev, | ||
539 | "failed to request irq #%d %d\n", | ||
540 | bdc->irq, ret); | ||
541 | return ret; | ||
542 | } | ||
543 | |||
544 | ret = bdc_init_ep(bdc); | ||
545 | if (ret) { | ||
546 | dev_err(bdc->dev, "bdc init ep fail: %d\n", ret); | ||
547 | return ret; | ||
548 | } | ||
549 | |||
550 | ret = usb_add_gadget_udc(bdc->dev, &bdc->gadget); | ||
551 | if (ret) { | ||
552 | dev_err(bdc->dev, "failed to register udc\n"); | ||
553 | goto err0; | ||
554 | } | ||
555 | usb_gadget_set_state(&bdc->gadget, USB_STATE_NOTATTACHED); | ||
556 | bdc->bdc_ep_array[1]->desc = &bdc_gadget_ep0_desc; | ||
557 | /* | ||
558 | * Allocate bd list for ep0 only, ep0 will be enabled on connect | ||
559 | * status report when the speed is known | ||
560 | */ | ||
561 | ret = bdc_ep_enable(bdc->bdc_ep_array[1]); | ||
562 | if (ret) { | ||
563 | dev_err(bdc->dev, "fail to enable %s\n", | ||
564 | bdc->bdc_ep_array[1]->name); | ||
565 | goto err1; | ||
566 | } | ||
567 | INIT_DELAYED_WORK(&bdc->func_wake_notify, bdc_func_wake_timer); | ||
568 | /* Enable Interrupts */ | ||
569 | temp = bdc_readl(bdc->regs, BDC_BDCSC); | ||
570 | temp |= BDC_GIE; | ||
571 | bdc_writel(bdc->regs, BDC_BDCSC, temp); | ||
572 | return 0; | ||
573 | err1: | ||
574 | usb_del_gadget_udc(&bdc->gadget); | ||
575 | err0: | ||
576 | bdc_free_ep(bdc); | ||
577 | |||
578 | return ret; | ||
579 | } | ||
580 | |||
581 | void bdc_udc_exit(struct bdc *bdc) | ||
582 | { | ||
583 | dev_dbg(bdc->dev, "%s()\n", __func__); | ||
584 | bdc_ep_disable(bdc->bdc_ep_array[1]); | ||
585 | usb_del_gadget_udc(&bdc->gadget); | ||
586 | bdc_free_ep(bdc); | ||
587 | } | ||
diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c index 81dc5959e36b..1c69c760408e 100644 --- a/drivers/usb/gadget/udc/dummy_hcd.c +++ b/drivers/usb/gadget/udc/dummy_hcd.c | |||
@@ -367,19 +367,22 @@ static void set_link_state(struct dummy_hcd *dum_hcd) | |||
367 | dum_hcd->active) | 367 | dum_hcd->active) |
368 | dum_hcd->resuming = 0; | 368 | dum_hcd->resuming = 0; |
369 | 369 | ||
370 | /* if !connected or reset */ | 370 | /* Currently !connected or in reset */ |
371 | if ((dum_hcd->port_status & USB_PORT_STAT_CONNECTION) == 0 || | 371 | if ((dum_hcd->port_status & USB_PORT_STAT_CONNECTION) == 0 || |
372 | (dum_hcd->port_status & USB_PORT_STAT_RESET) != 0) { | 372 | (dum_hcd->port_status & USB_PORT_STAT_RESET) != 0) { |
373 | /* | 373 | unsigned disconnect = USB_PORT_STAT_CONNECTION & |
374 | * We're connected and not reset (reset occurred now), | 374 | dum_hcd->old_status & (~dum_hcd->port_status); |
375 | * and driver attached - disconnect! | 375 | unsigned reset = USB_PORT_STAT_RESET & |
376 | */ | 376 | (~dum_hcd->old_status) & dum_hcd->port_status; |
377 | if ((dum_hcd->old_status & USB_PORT_STAT_CONNECTION) != 0 && | 377 | |
378 | (dum_hcd->old_status & USB_PORT_STAT_RESET) == 0 && | 378 | /* Report reset and disconnect events to the driver */ |
379 | dum->driver) { | 379 | if (dum->driver && (disconnect || reset)) { |
380 | stop_activity(dum); | 380 | stop_activity(dum); |
381 | spin_unlock(&dum->lock); | 381 | spin_unlock(&dum->lock); |
382 | dum->driver->disconnect(&dum->gadget); | 382 | if (reset) |
383 | usb_gadget_udc_reset(&dum->gadget, dum->driver); | ||
384 | else | ||
385 | dum->driver->disconnect(&dum->gadget); | ||
383 | spin_lock(&dum->lock); | 386 | spin_lock(&dum->lock); |
384 | } | 387 | } |
385 | } else if (dum_hcd->active != dum_hcd->old_active) { | 388 | } else if (dum_hcd->active != dum_hcd->old_active) { |
@@ -851,8 +854,7 @@ static int dummy_pullup(struct usb_gadget *_gadget, int value) | |||
851 | 854 | ||
852 | static int dummy_udc_start(struct usb_gadget *g, | 855 | static int dummy_udc_start(struct usb_gadget *g, |
853 | struct usb_gadget_driver *driver); | 856 | struct usb_gadget_driver *driver); |
854 | static int dummy_udc_stop(struct usb_gadget *g, | 857 | static int dummy_udc_stop(struct usb_gadget *g); |
855 | struct usb_gadget_driver *driver); | ||
856 | 858 | ||
857 | static const struct usb_gadget_ops dummy_ops = { | 859 | static const struct usb_gadget_ops dummy_ops = { |
858 | .get_frame = dummy_g_get_frame, | 860 | .get_frame = dummy_g_get_frame, |
@@ -908,23 +910,16 @@ static int dummy_udc_start(struct usb_gadget *g, | |||
908 | */ | 910 | */ |
909 | 911 | ||
910 | dum->devstatus = 0; | 912 | dum->devstatus = 0; |
911 | |||
912 | dum->driver = driver; | 913 | dum->driver = driver; |
913 | dev_dbg(udc_dev(dum), "binding gadget driver '%s'\n", | 914 | |
914 | driver->driver.name); | ||
915 | return 0; | 915 | return 0; |
916 | } | 916 | } |
917 | 917 | ||
918 | static int dummy_udc_stop(struct usb_gadget *g, | 918 | static int dummy_udc_stop(struct usb_gadget *g) |
919 | struct usb_gadget_driver *driver) | ||
920 | { | 919 | { |
921 | struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g); | 920 | struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g); |
922 | struct dummy *dum = dum_hcd->dum; | 921 | struct dummy *dum = dum_hcd->dum; |
923 | 922 | ||
924 | if (driver) | ||
925 | dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n", | ||
926 | driver->driver.name); | ||
927 | |||
928 | dum->driver = NULL; | 923 | dum->driver = NULL; |
929 | 924 | ||
930 | return 0; | 925 | return 0; |
@@ -2370,7 +2365,6 @@ static void dummy_stop(struct usb_hcd *hcd) | |||
2370 | 2365 | ||
2371 | dum = hcd_to_dummy_hcd(hcd)->dum; | 2366 | dum = hcd_to_dummy_hcd(hcd)->dum; |
2372 | device_remove_file(dummy_dev(hcd_to_dummy_hcd(hcd)), &dev_attr_urbs); | 2367 | device_remove_file(dummy_dev(hcd_to_dummy_hcd(hcd)), &dev_attr_urbs); |
2373 | usb_gadget_unregister_driver(dum->driver); | ||
2374 | dev_info(dummy_dev(hcd_to_dummy_hcd(hcd)), "stopped\n"); | 2368 | dev_info(dummy_dev(hcd_to_dummy_hcd(hcd)), "stopped\n"); |
2375 | } | 2369 | } |
2376 | 2370 | ||
diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c index 1d315921bf34..1ca52e11eb98 100644 --- a/drivers/usb/gadget/udc/fotg210-udc.c +++ b/drivers/usb/gadget/udc/fotg210-udc.c | |||
@@ -1053,8 +1053,7 @@ static void fotg210_init(struct fotg210_udc *fotg210) | |||
1053 | iowrite32(value, fotg210->reg + FOTG210_DMISGR0); | 1053 | iowrite32(value, fotg210->reg + FOTG210_DMISGR0); |
1054 | } | 1054 | } |
1055 | 1055 | ||
1056 | static int fotg210_udc_stop(struct usb_gadget *g, | 1056 | static int fotg210_udc_stop(struct usb_gadget *g) |
1057 | struct usb_gadget_driver *driver) | ||
1058 | { | 1057 | { |
1059 | struct fotg210_udc *fotg210 = gadget_to_fotg210(g); | 1058 | struct fotg210_udc *fotg210 = gadget_to_fotg210(g); |
1060 | unsigned long flags; | 1059 | unsigned long flags; |
diff --git a/drivers/usb/gadget/udc/fsl_qe_udc.c b/drivers/usb/gadget/udc/fsl_qe_udc.c index dd18ea38e391..d201f9a89ce3 100644 --- a/drivers/usb/gadget/udc/fsl_qe_udc.c +++ b/drivers/usb/gadget/udc/fsl_qe_udc.c | |||
@@ -1887,8 +1887,7 @@ static int qe_get_frame(struct usb_gadget *gadget) | |||
1887 | 1887 | ||
1888 | static int fsl_qe_start(struct usb_gadget *gadget, | 1888 | static int fsl_qe_start(struct usb_gadget *gadget, |
1889 | struct usb_gadget_driver *driver); | 1889 | struct usb_gadget_driver *driver); |
1890 | static int fsl_qe_stop(struct usb_gadget *gadget, | 1890 | static int fsl_qe_stop(struct usb_gadget *gadget); |
1891 | struct usb_gadget_driver *driver); | ||
1892 | 1891 | ||
1893 | /* defined in usb_gadget.h */ | 1892 | /* defined in usb_gadget.h */ |
1894 | static const struct usb_gadget_ops qe_gadget_ops = { | 1893 | static const struct usb_gadget_ops qe_gadget_ops = { |
@@ -1918,7 +1917,7 @@ static int reset_queues(struct qe_udc *udc) | |||
1918 | 1917 | ||
1919 | /* report disconnect; the driver is already quiesced */ | 1918 | /* report disconnect; the driver is already quiesced */ |
1920 | spin_unlock(&udc->lock); | 1919 | spin_unlock(&udc->lock); |
1921 | udc->driver->disconnect(&udc->gadget); | 1920 | usb_gadget_udc_reset(&udc->gadget, udc->driver); |
1922 | spin_lock(&udc->lock); | 1921 | spin_lock(&udc->lock); |
1923 | 1922 | ||
1924 | return 0; | 1923 | return 0; |
@@ -2305,13 +2304,10 @@ static int fsl_qe_start(struct usb_gadget *gadget, | |||
2305 | udc->ep0_dir = USB_DIR_OUT; | 2304 | udc->ep0_dir = USB_DIR_OUT; |
2306 | spin_unlock_irqrestore(&udc->lock, flags); | 2305 | spin_unlock_irqrestore(&udc->lock, flags); |
2307 | 2306 | ||
2308 | dev_info(udc->dev, "%s bind to driver %s\n", udc->gadget.name, | ||
2309 | driver->driver.name); | ||
2310 | return 0; | 2307 | return 0; |
2311 | } | 2308 | } |
2312 | 2309 | ||
2313 | static int fsl_qe_stop(struct usb_gadget *gadget, | 2310 | static int fsl_qe_stop(struct usb_gadget *gadget) |
2314 | struct usb_gadget_driver *driver) | ||
2315 | { | 2311 | { |
2316 | struct qe_udc *udc; | 2312 | struct qe_udc *udc; |
2317 | struct qe_ep *loop_ep; | 2313 | struct qe_ep *loop_ep; |
@@ -2336,8 +2332,6 @@ static int fsl_qe_stop(struct usb_gadget *gadget, | |||
2336 | 2332 | ||
2337 | udc->driver = NULL; | 2333 | udc->driver = NULL; |
2338 | 2334 | ||
2339 | dev_info(udc->dev, "unregistered gadget driver '%s'\r\n", | ||
2340 | driver->driver.name); | ||
2341 | return 0; | 2335 | return 0; |
2342 | } | 2336 | } |
2343 | 2337 | ||
@@ -2538,7 +2532,6 @@ static int qe_udc_probe(struct platform_device *ofdev) | |||
2538 | /* create a buf for ZLP send, need to remain zeroed */ | 2532 | /* create a buf for ZLP send, need to remain zeroed */ |
2539 | udc->nullbuf = devm_kzalloc(&ofdev->dev, 256, GFP_KERNEL); | 2533 | udc->nullbuf = devm_kzalloc(&ofdev->dev, 256, GFP_KERNEL); |
2540 | if (udc->nullbuf == NULL) { | 2534 | if (udc->nullbuf == NULL) { |
2541 | dev_err(udc->dev, "cannot alloc nullbuf\n"); | ||
2542 | ret = -ENOMEM; | 2535 | ret = -ENOMEM; |
2543 | goto err3; | 2536 | goto err3; |
2544 | } | 2537 | } |
diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c b/drivers/usb/gadget/udc/fsl_udc_core.c index c3620791a315..f340181da23c 100644 --- a/drivers/usb/gadget/udc/fsl_udc_core.c +++ b/drivers/usb/gadget/udc/fsl_udc_core.c | |||
@@ -1236,9 +1236,8 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on) | |||
1236 | 1236 | ||
1237 | static int fsl_udc_start(struct usb_gadget *g, | 1237 | static int fsl_udc_start(struct usb_gadget *g, |
1238 | struct usb_gadget_driver *driver); | 1238 | struct usb_gadget_driver *driver); |
1239 | static int fsl_udc_stop(struct usb_gadget *g, | 1239 | static int fsl_udc_stop(struct usb_gadget *g); |
1240 | struct usb_gadget_driver *driver); | 1240 | |
1241 | /* defined in gadget.h */ | ||
1242 | static const struct usb_gadget_ops fsl_gadget_ops = { | 1241 | static const struct usb_gadget_ops fsl_gadget_ops = { |
1243 | .get_frame = fsl_get_frame, | 1242 | .get_frame = fsl_get_frame, |
1244 | .wakeup = fsl_wakeup, | 1243 | .wakeup = fsl_wakeup, |
@@ -1772,7 +1771,7 @@ static void bus_resume(struct fsl_udc *udc) | |||
1772 | } | 1771 | } |
1773 | 1772 | ||
1774 | /* Clear up all ep queues */ | 1773 | /* Clear up all ep queues */ |
1775 | static int reset_queues(struct fsl_udc *udc) | 1774 | static int reset_queues(struct fsl_udc *udc, bool bus_reset) |
1776 | { | 1775 | { |
1777 | u8 pipe; | 1776 | u8 pipe; |
1778 | 1777 | ||
@@ -1781,7 +1780,10 @@ static int reset_queues(struct fsl_udc *udc) | |||
1781 | 1780 | ||
1782 | /* report disconnect; the driver is already quiesced */ | 1781 | /* report disconnect; the driver is already quiesced */ |
1783 | spin_unlock(&udc->lock); | 1782 | spin_unlock(&udc->lock); |
1784 | udc->driver->disconnect(&udc->gadget); | 1783 | if (bus_reset) |
1784 | usb_gadget_udc_reset(&udc->gadget, udc->driver); | ||
1785 | else | ||
1786 | udc->driver->disconnect(&udc->gadget); | ||
1785 | spin_lock(&udc->lock); | 1787 | spin_lock(&udc->lock); |
1786 | 1788 | ||
1787 | return 0; | 1789 | return 0; |
@@ -1835,7 +1837,7 @@ static void reset_irq(struct fsl_udc *udc) | |||
1835 | udc->bus_reset = 1; | 1837 | udc->bus_reset = 1; |
1836 | /* Reset all the queues, include XD, dTD, EP queue | 1838 | /* Reset all the queues, include XD, dTD, EP queue |
1837 | * head and TR Queue */ | 1839 | * head and TR Queue */ |
1838 | reset_queues(udc); | 1840 | reset_queues(udc, true); |
1839 | udc->usb_state = USB_STATE_DEFAULT; | 1841 | udc->usb_state = USB_STATE_DEFAULT; |
1840 | } else { | 1842 | } else { |
1841 | VDBG("Controller reset"); | 1843 | VDBG("Controller reset"); |
@@ -1844,7 +1846,7 @@ static void reset_irq(struct fsl_udc *udc) | |||
1844 | dr_controller_setup(udc); | 1846 | dr_controller_setup(udc); |
1845 | 1847 | ||
1846 | /* Reset all internal used Queues */ | 1848 | /* Reset all internal used Queues */ |
1847 | reset_queues(udc); | 1849 | reset_queues(udc, false); |
1848 | 1850 | ||
1849 | ep0_setup(udc); | 1851 | ep0_setup(udc); |
1850 | 1852 | ||
@@ -1975,8 +1977,7 @@ static int fsl_udc_start(struct usb_gadget *g, | |||
1975 | } | 1977 | } |
1976 | 1978 | ||
1977 | /* Disconnect from gadget driver */ | 1979 | /* Disconnect from gadget driver */ |
1978 | static int fsl_udc_stop(struct usb_gadget *g, | 1980 | static int fsl_udc_stop(struct usb_gadget *g) |
1979 | struct usb_gadget_driver *driver) | ||
1980 | { | 1981 | { |
1981 | struct fsl_ep *loop_ep; | 1982 | struct fsl_ep *loop_ep; |
1982 | unsigned long flags; | 1983 | unsigned long flags; |
diff --git a/drivers/usb/gadget/udc/fusb300_udc.c b/drivers/usb/gadget/udc/fusb300_udc.c index 8286df72add4..a1b33f534b52 100644 --- a/drivers/usb/gadget/udc/fusb300_udc.c +++ b/drivers/usb/gadget/udc/fusb300_udc.c | |||
@@ -1320,8 +1320,7 @@ static int fusb300_udc_start(struct usb_gadget *g, | |||
1320 | return 0; | 1320 | return 0; |
1321 | } | 1321 | } |
1322 | 1322 | ||
1323 | static int fusb300_udc_stop(struct usb_gadget *g, | 1323 | static int fusb300_udc_stop(struct usb_gadget *g) |
1324 | struct usb_gadget_driver *driver) | ||
1325 | { | 1324 | { |
1326 | struct fusb300 *fusb300 = to_fusb300(g); | 1325 | struct fusb300 *fusb300 = to_fusb300(g); |
1327 | 1326 | ||
diff --git a/drivers/usb/gadget/udc/goku_udc.c b/drivers/usb/gadget/udc/goku_udc.c index bf9c5ef8b56b..5b9176e7202a 100644 --- a/drivers/usb/gadget/udc/goku_udc.c +++ b/drivers/usb/gadget/udc/goku_udc.c | |||
@@ -992,8 +992,7 @@ static int goku_get_frame(struct usb_gadget *_gadget) | |||
992 | 992 | ||
993 | static int goku_udc_start(struct usb_gadget *g, | 993 | static int goku_udc_start(struct usb_gadget *g, |
994 | struct usb_gadget_driver *driver); | 994 | struct usb_gadget_driver *driver); |
995 | static int goku_udc_stop(struct usb_gadget *g, | 995 | static int goku_udc_stop(struct usb_gadget *g); |
996 | struct usb_gadget_driver *driver); | ||
997 | 996 | ||
998 | static const struct usb_gadget_ops goku_ops = { | 997 | static const struct usb_gadget_ops goku_ops = { |
999 | .get_frame = goku_get_frame, | 998 | .get_frame = goku_get_frame, |
@@ -1364,8 +1363,7 @@ static void stop_activity(struct goku_udc *dev) | |||
1364 | udc_enable(dev); | 1363 | udc_enable(dev); |
1365 | } | 1364 | } |
1366 | 1365 | ||
1367 | static int goku_udc_stop(struct usb_gadget *g, | 1366 | static int goku_udc_stop(struct usb_gadget *g) |
1368 | struct usb_gadget_driver *driver) | ||
1369 | { | 1367 | { |
1370 | struct goku_udc *dev = to_goku_udc(g); | 1368 | struct goku_udc *dev = to_goku_udc(g); |
1371 | unsigned long flags; | 1369 | unsigned long flags; |
diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c index 1b3048a6a2a3..320df9a250ff 100644 --- a/drivers/usb/gadget/udc/gr_udc.c +++ b/drivers/usb/gadget/udc/gr_udc.c | |||
@@ -1932,14 +1932,10 @@ static int gr_udc_start(struct usb_gadget *gadget, | |||
1932 | 1932 | ||
1933 | spin_unlock(&dev->lock); | 1933 | spin_unlock(&dev->lock); |
1934 | 1934 | ||
1935 | dev_info(dev->dev, "Started with gadget driver '%s'\n", | ||
1936 | driver->driver.name); | ||
1937 | |||
1938 | return 0; | 1935 | return 0; |
1939 | } | 1936 | } |
1940 | 1937 | ||
1941 | static int gr_udc_stop(struct usb_gadget *gadget, | 1938 | static int gr_udc_stop(struct usb_gadget *gadget) |
1942 | struct usb_gadget_driver *driver) | ||
1943 | { | 1939 | { |
1944 | struct gr_udc *dev = to_gr_udc(gadget); | 1940 | struct gr_udc *dev = to_gr_udc(gadget); |
1945 | unsigned long flags; | 1941 | unsigned long flags; |
@@ -1951,8 +1947,6 @@ static int gr_udc_stop(struct usb_gadget *gadget, | |||
1951 | 1947 | ||
1952 | spin_unlock_irqrestore(&dev->lock, flags); | 1948 | spin_unlock_irqrestore(&dev->lock, flags); |
1953 | 1949 | ||
1954 | dev_info(dev->dev, "Stopped\n"); | ||
1955 | |||
1956 | return 0; | 1950 | return 0; |
1957 | } | 1951 | } |
1958 | 1952 | ||
diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c index feab0bac8fdc..976529631c19 100644 --- a/drivers/usb/gadget/udc/lpc32xx_udc.c +++ b/drivers/usb/gadget/udc/lpc32xx_udc.c | |||
@@ -582,8 +582,7 @@ static void create_debug_file(struct lpc32xx_udc *udc) | |||
582 | 582 | ||
583 | static void remove_debug_file(struct lpc32xx_udc *udc) | 583 | static void remove_debug_file(struct lpc32xx_udc *udc) |
584 | { | 584 | { |
585 | if (udc->pde) | 585 | debugfs_remove(udc->pde); |
586 | debugfs_remove(udc->pde); | ||
587 | } | 586 | } |
588 | 587 | ||
589 | #else | 588 | #else |
@@ -2559,7 +2558,7 @@ static int lpc32xx_pullup(struct usb_gadget *gadget, int is_on) | |||
2559 | } | 2558 | } |
2560 | 2559 | ||
2561 | static int lpc32xx_start(struct usb_gadget *, struct usb_gadget_driver *); | 2560 | static int lpc32xx_start(struct usb_gadget *, struct usb_gadget_driver *); |
2562 | static int lpc32xx_stop(struct usb_gadget *, struct usb_gadget_driver *); | 2561 | static int lpc32xx_stop(struct usb_gadget *); |
2563 | 2562 | ||
2564 | static const struct usb_gadget_ops lpc32xx_udc_ops = { | 2563 | static const struct usb_gadget_ops lpc32xx_udc_ops = { |
2565 | .get_frame = lpc32xx_get_frame, | 2564 | .get_frame = lpc32xx_get_frame, |
@@ -2961,15 +2960,11 @@ static int lpc32xx_start(struct usb_gadget *gadget, | |||
2961 | return 0; | 2960 | return 0; |
2962 | } | 2961 | } |
2963 | 2962 | ||
2964 | static int lpc32xx_stop(struct usb_gadget *gadget, | 2963 | static int lpc32xx_stop(struct usb_gadget *gadget) |
2965 | struct usb_gadget_driver *driver) | ||
2966 | { | 2964 | { |
2967 | int i; | 2965 | int i; |
2968 | struct lpc32xx_udc *udc = to_udc(gadget); | 2966 | struct lpc32xx_udc *udc = to_udc(gadget); |
2969 | 2967 | ||
2970 | if (!driver || driver != udc->driver) | ||
2971 | return -EINVAL; | ||
2972 | |||
2973 | for (i = IRQ_USB_LP; i <= IRQ_USB_ATX; i++) | 2968 | for (i = IRQ_USB_LP; i <= IRQ_USB_ATX; i++) |
2974 | disable_irq(udc->udp_irq[i]); | 2969 | disable_irq(udc->udp_irq[i]); |
2975 | 2970 | ||
diff --git a/drivers/usb/gadget/udc/m66592-udc.c b/drivers/usb/gadget/udc/m66592-udc.c index 898565687a8c..ef3f73dd9099 100644 --- a/drivers/usb/gadget/udc/m66592-udc.c +++ b/drivers/usb/gadget/udc/m66592-udc.c | |||
@@ -1142,7 +1142,7 @@ static void irq_device_state(struct m66592 *m66592) | |||
1142 | m66592_write(m66592, ~M66592_DVST, M66592_INTSTS0); | 1142 | m66592_write(m66592, ~M66592_DVST, M66592_INTSTS0); |
1143 | 1143 | ||
1144 | if (dvsq == M66592_DS_DFLT) { /* bus reset */ | 1144 | if (dvsq == M66592_DS_DFLT) { /* bus reset */ |
1145 | m66592->driver->disconnect(&m66592->gadget); | 1145 | usb_gadget_udc_reset(&m66592->gadget, m66592->driver); |
1146 | m66592_update_usb_speed(m66592); | 1146 | m66592_update_usb_speed(m66592); |
1147 | } | 1147 | } |
1148 | if (m66592->old_dvsq == M66592_DS_CNFG && dvsq != M66592_DS_CNFG) | 1148 | if (m66592->old_dvsq == M66592_DS_CNFG && dvsq != M66592_DS_CNFG) |
@@ -1485,8 +1485,7 @@ static int m66592_udc_start(struct usb_gadget *g, | |||
1485 | return 0; | 1485 | return 0; |
1486 | } | 1486 | } |
1487 | 1487 | ||
1488 | static int m66592_udc_stop(struct usb_gadget *g, | 1488 | static int m66592_udc_stop(struct usb_gadget *g) |
1489 | struct usb_gadget_driver *driver) | ||
1490 | { | 1489 | { |
1491 | struct m66592 *m66592 = to_m66592(g); | 1490 | struct m66592 *m66592 = to_m66592(g); |
1492 | 1491 | ||
diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c index 046a1f808b0d..ea422ac79990 100644 --- a/drivers/usb/gadget/udc/mv_u3d_core.c +++ b/drivers/usb/gadget/udc/mv_u3d_core.c | |||
@@ -1266,8 +1266,7 @@ static int mv_u3d_start(struct usb_gadget *g, | |||
1266 | return 0; | 1266 | return 0; |
1267 | } | 1267 | } |
1268 | 1268 | ||
1269 | static int mv_u3d_stop(struct usb_gadget *g, | 1269 | static int mv_u3d_stop(struct usb_gadget *g) |
1270 | struct usb_gadget_driver *driver) | ||
1271 | { | 1270 | { |
1272 | struct mv_u3d *u3d = container_of(g, struct mv_u3d, gadget); | 1271 | struct mv_u3d *u3d = container_of(g, struct mv_u3d, gadget); |
1273 | struct mv_usb_platform_data *pdata = dev_get_platdata(u3d->dev); | 1272 | struct mv_usb_platform_data *pdata = dev_get_platdata(u3d->dev); |
@@ -1284,7 +1283,7 @@ static int mv_u3d_stop(struct usb_gadget *g, | |||
1284 | mv_u3d_controller_stop(u3d); | 1283 | mv_u3d_controller_stop(u3d); |
1285 | /* stop all usb activities */ | 1284 | /* stop all usb activities */ |
1286 | u3d->gadget.speed = USB_SPEED_UNKNOWN; | 1285 | u3d->gadget.speed = USB_SPEED_UNKNOWN; |
1287 | mv_u3d_stop_activity(u3d, driver); | 1286 | mv_u3d_stop_activity(u3d, NULL); |
1288 | mv_u3d_disable(u3d); | 1287 | mv_u3d_disable(u3d); |
1289 | 1288 | ||
1290 | if (pdata->phy_deinit) | 1289 | if (pdata->phy_deinit) |
diff --git a/drivers/usb/gadget/udc/mv_udc_core.c b/drivers/usb/gadget/udc/mv_udc_core.c index 3c5db80ae325..d4edd763e963 100644 --- a/drivers/usb/gadget/udc/mv_udc_core.c +++ b/drivers/usb/gadget/udc/mv_udc_core.c | |||
@@ -1223,7 +1223,7 @@ static int mv_udc_pullup(struct usb_gadget *gadget, int is_on) | |||
1223 | } | 1223 | } |
1224 | 1224 | ||
1225 | static int mv_udc_start(struct usb_gadget *, struct usb_gadget_driver *); | 1225 | static int mv_udc_start(struct usb_gadget *, struct usb_gadget_driver *); |
1226 | static int mv_udc_stop(struct usb_gadget *, struct usb_gadget_driver *); | 1226 | static int mv_udc_stop(struct usb_gadget *); |
1227 | /* device controller usb_gadget_ops structure */ | 1227 | /* device controller usb_gadget_ops structure */ |
1228 | static const struct usb_gadget_ops mv_ops = { | 1228 | static const struct usb_gadget_ops mv_ops = { |
1229 | 1229 | ||
@@ -1307,6 +1307,23 @@ static void nuke(struct mv_ep *ep, int status) | |||
1307 | } | 1307 | } |
1308 | } | 1308 | } |
1309 | 1309 | ||
1310 | static void gadget_reset(struct mv_udc *udc, struct usb_gadget_driver *driver) | ||
1311 | { | ||
1312 | struct mv_ep *ep; | ||
1313 | |||
1314 | nuke(&udc->eps[0], -ESHUTDOWN); | ||
1315 | |||
1316 | list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { | ||
1317 | nuke(ep, -ESHUTDOWN); | ||
1318 | } | ||
1319 | |||
1320 | /* report reset; the driver is already quiesced */ | ||
1321 | if (driver) { | ||
1322 | spin_unlock(&udc->lock); | ||
1323 | usb_gadget_udc_reset(&udc->gadget, driver); | ||
1324 | spin_lock(&udc->lock); | ||
1325 | } | ||
1326 | } | ||
1310 | /* stop all USB activities */ | 1327 | /* stop all USB activities */ |
1311 | static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver) | 1328 | static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver) |
1312 | { | 1329 | { |
@@ -1371,8 +1388,7 @@ static int mv_udc_start(struct usb_gadget *gadget, | |||
1371 | return 0; | 1388 | return 0; |
1372 | } | 1389 | } |
1373 | 1390 | ||
1374 | static int mv_udc_stop(struct usb_gadget *gadget, | 1391 | static int mv_udc_stop(struct usb_gadget *gadget) |
1375 | struct usb_gadget_driver *driver) | ||
1376 | { | 1392 | { |
1377 | struct mv_udc *udc; | 1393 | struct mv_udc *udc; |
1378 | unsigned long flags; | 1394 | unsigned long flags; |
@@ -1386,7 +1402,7 @@ static int mv_udc_stop(struct usb_gadget *gadget, | |||
1386 | 1402 | ||
1387 | /* stop all usb activities */ | 1403 | /* stop all usb activities */ |
1388 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 1404 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
1389 | stop_activity(udc, driver); | 1405 | stop_activity(udc, NULL); |
1390 | mv_udc_disable(udc); | 1406 | mv_udc_disable(udc); |
1391 | 1407 | ||
1392 | spin_unlock_irqrestore(&udc->lock, flags); | 1408 | spin_unlock_irqrestore(&udc->lock, flags); |
@@ -1882,7 +1898,7 @@ static void irq_process_reset(struct mv_udc *udc) | |||
1882 | dev_info(&udc->dev->dev, "usb bus reset\n"); | 1898 | dev_info(&udc->dev->dev, "usb bus reset\n"); |
1883 | udc->usb_state = USB_STATE_DEFAULT; | 1899 | udc->usb_state = USB_STATE_DEFAULT; |
1884 | /* reset all the queues, stop all USB activities */ | 1900 | /* reset all the queues, stop all USB activities */ |
1885 | stop_activity(udc, udc->driver); | 1901 | gadget_reset(udc, udc->driver); |
1886 | } else { | 1902 | } else { |
1887 | dev_info(&udc->dev->dev, "USB reset portsc 0x%x\n", | 1903 | dev_info(&udc->dev->dev, "USB reset portsc 0x%x\n", |
1888 | readl(&udc->op_regs->portsc)); | 1904 | readl(&udc->op_regs->portsc)); |
@@ -2107,10 +2123,8 @@ static int mv_udc_probe(struct platform_device *pdev) | |||
2107 | } | 2123 | } |
2108 | 2124 | ||
2109 | udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); | 2125 | udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); |
2110 | if (udc == NULL) { | 2126 | if (udc == NULL) |
2111 | dev_err(&pdev->dev, "failed to allocate memory for udc\n"); | ||
2112 | return -ENOMEM; | 2127 | return -ENOMEM; |
2113 | } | ||
2114 | 2128 | ||
2115 | udc->done = &release_done; | 2129 | udc->done = &release_done; |
2116 | udc->pdata = dev_get_platdata(&pdev->dev); | 2130 | udc->pdata = dev_get_platdata(&pdev->dev); |
@@ -2207,7 +2221,6 @@ static int mv_udc_probe(struct platform_device *pdev) | |||
2207 | size = udc->max_eps * sizeof(struct mv_ep) *2; | 2221 | size = udc->max_eps * sizeof(struct mv_ep) *2; |
2208 | udc->eps = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); | 2222 | udc->eps = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); |
2209 | if (udc->eps == NULL) { | 2223 | if (udc->eps == NULL) { |
2210 | dev_err(&pdev->dev, "allocate ep memory failed\n"); | ||
2211 | retval = -ENOMEM; | 2224 | retval = -ENOMEM; |
2212 | goto err_destroy_dma; | 2225 | goto err_destroy_dma; |
2213 | } | 2226 | } |
@@ -2216,7 +2229,6 @@ static int mv_udc_probe(struct platform_device *pdev) | |||
2216 | udc->status_req = devm_kzalloc(&pdev->dev, sizeof(struct mv_req), | 2229 | udc->status_req = devm_kzalloc(&pdev->dev, sizeof(struct mv_req), |
2217 | GFP_KERNEL); | 2230 | GFP_KERNEL); |
2218 | if (!udc->status_req) { | 2231 | if (!udc->status_req) { |
2219 | dev_err(&pdev->dev, "allocate status_req memory failed\n"); | ||
2220 | retval = -ENOMEM; | 2232 | retval = -ENOMEM; |
2221 | goto err_destroy_dma; | 2233 | goto err_destroy_dma; |
2222 | } | 2234 | } |
diff --git a/drivers/usb/gadget/udc/net2272.c b/drivers/usb/gadget/udc/net2272.c index 84d7162a8022..3a90856625f2 100644 --- a/drivers/usb/gadget/udc/net2272.c +++ b/drivers/usb/gadget/udc/net2272.c | |||
@@ -1169,8 +1169,7 @@ net2272_pullup(struct usb_gadget *_gadget, int is_on) | |||
1169 | 1169 | ||
1170 | static int net2272_start(struct usb_gadget *_gadget, | 1170 | static int net2272_start(struct usb_gadget *_gadget, |
1171 | struct usb_gadget_driver *driver); | 1171 | struct usb_gadget_driver *driver); |
1172 | static int net2272_stop(struct usb_gadget *_gadget, | 1172 | static int net2272_stop(struct usb_gadget *_gadget); |
1173 | struct usb_gadget_driver *driver); | ||
1174 | 1173 | ||
1175 | static const struct usb_gadget_ops net2272_ops = { | 1174 | static const struct usb_gadget_ops net2272_ops = { |
1176 | .get_frame = net2272_get_frame, | 1175 | .get_frame = net2272_get_frame, |
@@ -1471,8 +1470,6 @@ static int net2272_start(struct usb_gadget *_gadget, | |||
1471 | */ | 1470 | */ |
1472 | net2272_ep0_start(dev); | 1471 | net2272_ep0_start(dev); |
1473 | 1472 | ||
1474 | dev_dbg(dev->dev, "%s ready\n", driver->driver.name); | ||
1475 | |||
1476 | return 0; | 1473 | return 0; |
1477 | } | 1474 | } |
1478 | 1475 | ||
@@ -1502,8 +1499,7 @@ stop_activity(struct net2272 *dev, struct usb_gadget_driver *driver) | |||
1502 | net2272_usb_reinit(dev); | 1499 | net2272_usb_reinit(dev); |
1503 | } | 1500 | } |
1504 | 1501 | ||
1505 | static int net2272_stop(struct usb_gadget *_gadget, | 1502 | static int net2272_stop(struct usb_gadget *_gadget) |
1506 | struct usb_gadget_driver *driver) | ||
1507 | { | 1503 | { |
1508 | struct net2272 *dev; | 1504 | struct net2272 *dev; |
1509 | unsigned long flags; | 1505 | unsigned long flags; |
@@ -1511,12 +1507,11 @@ static int net2272_stop(struct usb_gadget *_gadget, | |||
1511 | dev = container_of(_gadget, struct net2272, gadget); | 1507 | dev = container_of(_gadget, struct net2272, gadget); |
1512 | 1508 | ||
1513 | spin_lock_irqsave(&dev->lock, flags); | 1509 | spin_lock_irqsave(&dev->lock, flags); |
1514 | stop_activity(dev, driver); | 1510 | stop_activity(dev, NULL); |
1515 | spin_unlock_irqrestore(&dev->lock, flags); | 1511 | spin_unlock_irqrestore(&dev->lock, flags); |
1516 | 1512 | ||
1517 | dev->driver = NULL; | 1513 | dev->driver = NULL; |
1518 | 1514 | ||
1519 | dev_dbg(dev->dev, "unregistered driver '%s'\n", driver->driver.name); | ||
1520 | return 0; | 1515 | return 0; |
1521 | } | 1516 | } |
1522 | 1517 | ||
@@ -1987,17 +1982,42 @@ net2272_handle_stat1_irqs(struct net2272 *dev, u8 stat) | |||
1987 | mask = (1 << USB_HIGH_SPEED) | (1 << USB_FULL_SPEED); | 1982 | mask = (1 << USB_HIGH_SPEED) | (1 << USB_FULL_SPEED); |
1988 | 1983 | ||
1989 | if (stat & tmp) { | 1984 | if (stat & tmp) { |
1985 | bool reset = false; | ||
1986 | bool disconnect = false; | ||
1987 | |||
1988 | /* | ||
1989 | * Ignore disconnects and resets if the speed hasn't been set. | ||
1990 | * VBUS can bounce and there's always an initial reset. | ||
1991 | */ | ||
1990 | net2272_write(dev, IRQSTAT1, tmp); | 1992 | net2272_write(dev, IRQSTAT1, tmp); |
1991 | if ((((stat & (1 << ROOT_PORT_RESET_INTERRUPT)) && | 1993 | if (dev->gadget.speed != USB_SPEED_UNKNOWN) { |
1992 | ((net2272_read(dev, USBCTL1) & mask) == 0)) | 1994 | if ((stat & (1 << VBUS_INTERRUPT)) && |
1993 | || ((net2272_read(dev, USBCTL1) & (1 << VBUS_PIN)) | 1995 | (net2272_read(dev, USBCTL1) & |
1994 | == 0)) | 1996 | (1 << VBUS_PIN)) == 0) { |
1995 | && (dev->gadget.speed != USB_SPEED_UNKNOWN)) { | 1997 | disconnect = true; |
1996 | dev_dbg(dev->dev, "disconnect %s\n", | 1998 | dev_dbg(dev->dev, "disconnect %s\n", |
1997 | dev->driver->driver.name); | 1999 | dev->driver->driver.name); |
1998 | stop_activity(dev, dev->driver); | 2000 | } else if ((stat & (1 << ROOT_PORT_RESET_INTERRUPT)) && |
1999 | net2272_ep0_start(dev); | 2001 | (net2272_read(dev, USBCTL1) & mask) |
2000 | return; | 2002 | == 0) { |
2003 | reset = true; | ||
2004 | dev_dbg(dev->dev, "reset %s\n", | ||
2005 | dev->driver->driver.name); | ||
2006 | } | ||
2007 | |||
2008 | if (disconnect || reset) { | ||
2009 | stop_activity(dev, dev->driver); | ||
2010 | net2272_ep0_start(dev); | ||
2011 | spin_unlock(&dev->lock); | ||
2012 | if (reset) | ||
2013 | usb_gadget_udc_reset | ||
2014 | (&dev->gadget, dev->driver); | ||
2015 | else | ||
2016 | (dev->driver->disconnect) | ||
2017 | (&dev->gadget); | ||
2018 | spin_lock(&dev->lock); | ||
2019 | return; | ||
2020 | } | ||
2001 | } | 2021 | } |
2002 | stat &= ~tmp; | 2022 | stat &= ~tmp; |
2003 | 2023 | ||
@@ -2200,18 +2220,8 @@ static void | |||
2200 | net2272_remove(struct net2272 *dev) | 2220 | net2272_remove(struct net2272 *dev) |
2201 | { | 2221 | { |
2202 | usb_del_gadget_udc(&dev->gadget); | 2222 | usb_del_gadget_udc(&dev->gadget); |
2203 | |||
2204 | /* start with the driver above us */ | ||
2205 | if (dev->driver) { | ||
2206 | /* should have been done already by driver model core */ | ||
2207 | dev_warn(dev->dev, "pci remove, driver '%s' is still registered\n", | ||
2208 | dev->driver->driver.name); | ||
2209 | usb_gadget_unregister_driver(dev->driver); | ||
2210 | } | ||
2211 | |||
2212 | free_irq(dev->irq, dev); | 2223 | free_irq(dev->irq, dev); |
2213 | iounmap(dev->base_addr); | 2224 | iounmap(dev->base_addr); |
2214 | |||
2215 | device_remove_file(dev->dev, &dev_attr_registers); | 2225 | device_remove_file(dev->dev, &dev_attr_registers); |
2216 | 2226 | ||
2217 | dev_info(dev->dev, "unbind\n"); | 2227 | dev_info(dev->dev, "unbind\n"); |
diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index 8d13337e2dde..d6411e0a8e03 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c | |||
@@ -1118,10 +1118,10 @@ static void scan_dma_completions(struct net2280_ep *ep) | |||
1118 | break; | 1118 | break; |
1119 | } else if (!ep->is_in && | 1119 | } else if (!ep->is_in && |
1120 | (req->req.length % ep->ep.maxpacket) != 0) { | 1120 | (req->req.length % ep->ep.maxpacket) != 0) { |
1121 | tmp = readl(&ep->regs->ep_stat); | ||
1122 | if (ep->dev->quirks & PLX_SUPERSPEED) | 1121 | if (ep->dev->quirks & PLX_SUPERSPEED) |
1123 | return dma_done(ep, req, tmp, 0); | 1122 | return dma_done(ep, req, tmp, 0); |
1124 | 1123 | ||
1124 | tmp = readl(&ep->regs->ep_stat); | ||
1125 | /* AVOID TROUBLE HERE by not issuing short reads from | 1125 | /* AVOID TROUBLE HERE by not issuing short reads from |
1126 | * your gadget driver. That helps avoids errata 0121, | 1126 | * your gadget driver. That helps avoids errata 0121, |
1127 | * 0122, and 0124; not all cases trigger the warning. | 1127 | * 0122, and 0124; not all cases trigger the warning. |
@@ -1548,8 +1548,7 @@ static int net2280_pullup(struct usb_gadget *_gadget, int is_on) | |||
1548 | 1548 | ||
1549 | static int net2280_start(struct usb_gadget *_gadget, | 1549 | static int net2280_start(struct usb_gadget *_gadget, |
1550 | struct usb_gadget_driver *driver); | 1550 | struct usb_gadget_driver *driver); |
1551 | static int net2280_stop(struct usb_gadget *_gadget, | 1551 | static int net2280_stop(struct usb_gadget *_gadget); |
1552 | struct usb_gadget_driver *driver); | ||
1553 | 1552 | ||
1554 | static const struct usb_gadget_ops net2280_ops = { | 1553 | static const struct usb_gadget_ops net2280_ops = { |
1555 | .get_frame = net2280_get_frame, | 1554 | .get_frame = net2280_get_frame, |
@@ -2397,11 +2396,6 @@ static int net2280_start(struct usb_gadget *_gadget, | |||
2397 | 2396 | ||
2398 | ep0_start(dev); | 2397 | ep0_start(dev); |
2399 | 2398 | ||
2400 | ep_dbg(dev, "%s ready, usbctl %08x stdrsp %08x\n", | ||
2401 | driver->driver.name, | ||
2402 | readl(&dev->usb->usbctl), | ||
2403 | readl(&dev->usb->stdrsp)); | ||
2404 | |||
2405 | /* pci writes may still be posted */ | 2399 | /* pci writes may still be posted */ |
2406 | return 0; | 2400 | return 0; |
2407 | 2401 | ||
@@ -2437,8 +2431,7 @@ static void stop_activity(struct net2280 *dev, struct usb_gadget_driver *driver) | |||
2437 | usb_reinit(dev); | 2431 | usb_reinit(dev); |
2438 | } | 2432 | } |
2439 | 2433 | ||
2440 | static int net2280_stop(struct usb_gadget *_gadget, | 2434 | static int net2280_stop(struct usb_gadget *_gadget) |
2441 | struct usb_gadget_driver *driver) | ||
2442 | { | 2435 | { |
2443 | struct net2280 *dev; | 2436 | struct net2280 *dev; |
2444 | unsigned long flags; | 2437 | unsigned long flags; |
@@ -2446,11 +2439,9 @@ static int net2280_stop(struct usb_gadget *_gadget, | |||
2446 | dev = container_of(_gadget, struct net2280, gadget); | 2439 | dev = container_of(_gadget, struct net2280, gadget); |
2447 | 2440 | ||
2448 | spin_lock_irqsave(&dev->lock, flags); | 2441 | spin_lock_irqsave(&dev->lock, flags); |
2449 | stop_activity(dev, driver); | 2442 | stop_activity(dev, NULL); |
2450 | spin_unlock_irqrestore(&dev->lock, flags); | 2443 | spin_unlock_irqrestore(&dev->lock, flags); |
2451 | 2444 | ||
2452 | dev->driver = NULL; | ||
2453 | |||
2454 | net2280_led_active(dev, 0); | 2445 | net2280_led_active(dev, 0); |
2455 | 2446 | ||
2456 | /* Disable full-speed test mode */ | 2447 | /* Disable full-speed test mode */ |
@@ -2460,8 +2451,7 @@ static int net2280_stop(struct usb_gadget *_gadget, | |||
2460 | device_remove_file(&dev->pdev->dev, &dev_attr_function); | 2451 | device_remove_file(&dev->pdev->dev, &dev_attr_function); |
2461 | device_remove_file(&dev->pdev->dev, &dev_attr_queues); | 2452 | device_remove_file(&dev->pdev->dev, &dev_attr_queues); |
2462 | 2453 | ||
2463 | ep_dbg(dev, "unregistered driver '%s'\n", | 2454 | dev->driver = NULL; |
2464 | driver ? driver->driver.name : ""); | ||
2465 | 2455 | ||
2466 | return 0; | 2456 | return 0; |
2467 | } | 2457 | } |
@@ -3318,17 +3308,42 @@ static void handle_stat1_irqs(struct net2280 *dev, u32 stat) | |||
3318 | * only indicates a change in the reset state). | 3308 | * only indicates a change in the reset state). |
3319 | */ | 3309 | */ |
3320 | if (stat & tmp) { | 3310 | if (stat & tmp) { |
3311 | bool reset = false; | ||
3312 | bool disconnect = false; | ||
3313 | |||
3314 | /* | ||
3315 | * Ignore disconnects and resets if the speed hasn't been set. | ||
3316 | * VBUS can bounce and there's always an initial reset. | ||
3317 | */ | ||
3321 | writel(tmp, &dev->regs->irqstat1); | 3318 | writel(tmp, &dev->regs->irqstat1); |
3322 | if ((((stat & BIT(ROOT_PORT_RESET_INTERRUPT)) && | 3319 | if (dev->gadget.speed != USB_SPEED_UNKNOWN) { |
3323 | ((readl(&dev->usb->usbstat) & mask) == 0)) || | 3320 | if ((stat & BIT(VBUS_INTERRUPT)) && |
3324 | ((readl(&dev->usb->usbctl) & | 3321 | (readl(&dev->usb->usbctl) & |
3325 | BIT(VBUS_PIN)) == 0)) && | 3322 | BIT(VBUS_PIN)) == 0) { |
3326 | (dev->gadget.speed != USB_SPEED_UNKNOWN)) { | 3323 | disconnect = true; |
3327 | ep_dbg(dev, "disconnect %s\n", | 3324 | ep_dbg(dev, "disconnect %s\n", |
3328 | dev->driver->driver.name); | 3325 | dev->driver->driver.name); |
3329 | stop_activity(dev, dev->driver); | 3326 | } else if ((stat & BIT(ROOT_PORT_RESET_INTERRUPT)) && |
3330 | ep0_start(dev); | 3327 | (readl(&dev->usb->usbstat) & mask) |
3331 | return; | 3328 | == 0) { |
3329 | reset = true; | ||
3330 | ep_dbg(dev, "reset %s\n", | ||
3331 | dev->driver->driver.name); | ||
3332 | } | ||
3333 | |||
3334 | if (disconnect || reset) { | ||
3335 | stop_activity(dev, dev->driver); | ||
3336 | ep0_start(dev); | ||
3337 | spin_unlock(&dev->lock); | ||
3338 | if (reset) | ||
3339 | usb_gadget_udc_reset | ||
3340 | (&dev->gadget, dev->driver); | ||
3341 | else | ||
3342 | (dev->driver->disconnect) | ||
3343 | (&dev->gadget); | ||
3344 | spin_lock(&dev->lock); | ||
3345 | return; | ||
3346 | } | ||
3332 | } | 3347 | } |
3333 | stat &= ~tmp; | 3348 | stat &= ~tmp; |
3334 | 3349 | ||
diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c index dcdfea46003b..534b85c07feb 100644 --- a/drivers/usb/gadget/udc/omap_udc.c +++ b/drivers/usb/gadget/udc/omap_udc.c | |||
@@ -1311,8 +1311,7 @@ static int omap_pullup(struct usb_gadget *gadget, int is_on) | |||
1311 | 1311 | ||
1312 | static int omap_udc_start(struct usb_gadget *g, | 1312 | static int omap_udc_start(struct usb_gadget *g, |
1313 | struct usb_gadget_driver *driver); | 1313 | struct usb_gadget_driver *driver); |
1314 | static int omap_udc_stop(struct usb_gadget *g, | 1314 | static int omap_udc_stop(struct usb_gadget *g); |
1315 | struct usb_gadget_driver *driver); | ||
1316 | 1315 | ||
1317 | static const struct usb_gadget_ops omap_gadget_ops = { | 1316 | static const struct usb_gadget_ops omap_gadget_ops = { |
1318 | .get_frame = omap_get_frame, | 1317 | .get_frame = omap_get_frame, |
@@ -2102,8 +2101,7 @@ done: | |||
2102 | return status; | 2101 | return status; |
2103 | } | 2102 | } |
2104 | 2103 | ||
2105 | static int omap_udc_stop(struct usb_gadget *g, | 2104 | static int omap_udc_stop(struct usb_gadget *g) |
2106 | struct usb_gadget_driver *driver) | ||
2107 | { | 2105 | { |
2108 | unsigned long flags; | 2106 | unsigned long flags; |
2109 | int status = -ENODEV; | 2107 | int status = -ENODEV; |
diff --git a/drivers/usb/gadget/udc/pch_udc.c b/drivers/usb/gadget/udc/pch_udc.c index ccbe3d4a2a50..1c7379ac2379 100644 --- a/drivers/usb/gadget/udc/pch_udc.c +++ b/drivers/usb/gadget/udc/pch_udc.c | |||
@@ -1240,8 +1240,8 @@ static int pch_udc_pcd_vbus_draw(struct usb_gadget *gadget, unsigned int mA) | |||
1240 | 1240 | ||
1241 | static int pch_udc_start(struct usb_gadget *g, | 1241 | static int pch_udc_start(struct usb_gadget *g, |
1242 | struct usb_gadget_driver *driver); | 1242 | struct usb_gadget_driver *driver); |
1243 | static int pch_udc_stop(struct usb_gadget *g, | 1243 | static int pch_udc_stop(struct usb_gadget *g); |
1244 | struct usb_gadget_driver *driver); | 1244 | |
1245 | static const struct usb_gadget_ops pch_udc_ops = { | 1245 | static const struct usb_gadget_ops pch_udc_ops = { |
1246 | .get_frame = pch_udc_pcd_get_frame, | 1246 | .get_frame = pch_udc_pcd_get_frame, |
1247 | .wakeup = pch_udc_pcd_wakeup, | 1247 | .wakeup = pch_udc_pcd_wakeup, |
@@ -2592,9 +2592,9 @@ static void pch_udc_svc_ur_interrupt(struct pch_udc_dev *dev) | |||
2592 | /* Complete request queue */ | 2592 | /* Complete request queue */ |
2593 | empty_req_queue(ep); | 2593 | empty_req_queue(ep); |
2594 | } | 2594 | } |
2595 | if (dev->driver && dev->driver->disconnect) { | 2595 | if (dev->driver) { |
2596 | spin_unlock(&dev->lock); | 2596 | spin_unlock(&dev->lock); |
2597 | dev->driver->disconnect(&dev->gadget); | 2597 | usb_gadget_udc_reset(&dev->gadget, dev->driver); |
2598 | spin_lock(&dev->lock); | 2598 | spin_lock(&dev->lock); |
2599 | } | 2599 | } |
2600 | } | 2600 | } |
@@ -3008,8 +3008,7 @@ static int pch_udc_start(struct usb_gadget *g, | |||
3008 | return 0; | 3008 | return 0; |
3009 | } | 3009 | } |
3010 | 3010 | ||
3011 | static int pch_udc_stop(struct usb_gadget *g, | 3011 | static int pch_udc_stop(struct usb_gadget *g) |
3012 | struct usb_gadget_driver *driver) | ||
3013 | { | 3012 | { |
3014 | struct pch_udc_dev *dev = to_pch_udc(g); | 3013 | struct pch_udc_dev *dev = to_pch_udc(g); |
3015 | 3014 | ||
diff --git a/drivers/usb/gadget/udc/pxa25x_udc.c b/drivers/usb/gadget/udc/pxa25x_udc.c index 42f7eeb8ff6f..347a05b5afc1 100644 --- a/drivers/usb/gadget/udc/pxa25x_udc.c +++ b/drivers/usb/gadget/udc/pxa25x_udc.c | |||
@@ -998,8 +998,7 @@ static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA) | |||
998 | 998 | ||
999 | static int pxa25x_udc_start(struct usb_gadget *g, | 999 | static int pxa25x_udc_start(struct usb_gadget *g, |
1000 | struct usb_gadget_driver *driver); | 1000 | struct usb_gadget_driver *driver); |
1001 | static int pxa25x_udc_stop(struct usb_gadget *g, | 1001 | static int pxa25x_udc_stop(struct usb_gadget *g); |
1002 | struct usb_gadget_driver *driver); | ||
1003 | 1002 | ||
1004 | static const struct usb_gadget_ops pxa25x_udc_ops = { | 1003 | static const struct usb_gadget_ops pxa25x_udc_ops = { |
1005 | .get_frame = pxa25x_udc_get_frame, | 1004 | .get_frame = pxa25x_udc_get_frame, |
@@ -1135,11 +1134,7 @@ static const struct file_operations debug_fops = { | |||
1135 | dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \ | 1134 | dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \ |
1136 | S_IRUGO, NULL, dev, &debug_fops); \ | 1135 | S_IRUGO, NULL, dev, &debug_fops); \ |
1137 | } while (0) | 1136 | } while (0) |
1138 | #define remove_debug_files(dev) \ | 1137 | #define remove_debug_files(dev) debugfs_remove(dev->debugfs_udc) |
1139 | do { \ | ||
1140 | if (dev->debugfs_udc) \ | ||
1141 | debugfs_remove(dev->debugfs_udc); \ | ||
1142 | } while (0) | ||
1143 | 1138 | ||
1144 | #else /* !CONFIG_USB_GADGET_DEBUG_FILES */ | 1139 | #else /* !CONFIG_USB_GADGET_DEBUG_FILES */ |
1145 | 1140 | ||
@@ -1285,6 +1280,33 @@ bind_fail: | |||
1285 | } | 1280 | } |
1286 | 1281 | ||
1287 | static void | 1282 | static void |
1283 | reset_gadget(struct pxa25x_udc *dev, struct usb_gadget_driver *driver) | ||
1284 | { | ||
1285 | int i; | ||
1286 | |||
1287 | /* don't disconnect drivers more than once */ | ||
1288 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1289 | driver = NULL; | ||
1290 | dev->gadget.speed = USB_SPEED_UNKNOWN; | ||
1291 | |||
1292 | /* prevent new request submissions, kill any outstanding requests */ | ||
1293 | for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) { | ||
1294 | struct pxa25x_ep *ep = &dev->ep[i]; | ||
1295 | |||
1296 | ep->stopped = 1; | ||
1297 | nuke(ep, -ESHUTDOWN); | ||
1298 | } | ||
1299 | del_timer_sync(&dev->timer); | ||
1300 | |||
1301 | /* report reset; the driver is already quiesced */ | ||
1302 | if (driver) | ||
1303 | usb_gadget_udc_reset(&dev->gadget, driver); | ||
1304 | |||
1305 | /* re-init driver-visible data structures */ | ||
1306 | udc_reinit(dev); | ||
1307 | } | ||
1308 | |||
1309 | static void | ||
1288 | stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver) | 1310 | stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver) |
1289 | { | 1311 | { |
1290 | int i; | 1312 | int i; |
@@ -1311,15 +1333,14 @@ stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver) | |||
1311 | udc_reinit(dev); | 1333 | udc_reinit(dev); |
1312 | } | 1334 | } |
1313 | 1335 | ||
1314 | static int pxa25x_udc_stop(struct usb_gadget*g, | 1336 | static int pxa25x_udc_stop(struct usb_gadget*g) |
1315 | struct usb_gadget_driver *driver) | ||
1316 | { | 1337 | { |
1317 | struct pxa25x_udc *dev = to_pxa25x(g); | 1338 | struct pxa25x_udc *dev = to_pxa25x(g); |
1318 | 1339 | ||
1319 | local_irq_disable(); | 1340 | local_irq_disable(); |
1320 | dev->pullup = 0; | 1341 | dev->pullup = 0; |
1321 | pullup(dev); | 1342 | pullup(dev); |
1322 | stop_activity(dev, driver); | 1343 | stop_activity(dev, NULL); |
1323 | local_irq_enable(); | 1344 | local_irq_enable(); |
1324 | 1345 | ||
1325 | if (!IS_ERR_OR_NULL(dev->transceiver)) | 1346 | if (!IS_ERR_OR_NULL(dev->transceiver)) |
@@ -1723,7 +1744,7 @@ pxa25x_udc_irq(int irq, void *_dev) | |||
1723 | /* reset driver and endpoints, | 1744 | /* reset driver and endpoints, |
1724 | * in case that's not yet done | 1745 | * in case that's not yet done |
1725 | */ | 1746 | */ |
1726 | stop_activity (dev, dev->driver); | 1747 | reset_gadget(dev, dev->driver); |
1727 | 1748 | ||
1728 | } else { | 1749 | } else { |
1729 | DBG(DBG_VERBOSE, "USB reset end\n"); | 1750 | DBG(DBG_VERBOSE, "USB reset end\n"); |
diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c index 4868369eeec6..9b03fab13707 100644 --- a/drivers/usb/gadget/udc/pxa27x_udc.c +++ b/drivers/usb/gadget/udc/pxa27x_udc.c | |||
@@ -22,10 +22,13 @@ | |||
22 | #include <linux/clk.h> | 22 | #include <linux/clk.h> |
23 | #include <linux/irq.h> | 23 | #include <linux/irq.h> |
24 | #include <linux/gpio.h> | 24 | #include <linux/gpio.h> |
25 | #include <linux/gpio/consumer.h> | ||
25 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
26 | #include <linux/prefetch.h> | 27 | #include <linux/prefetch.h> |
27 | #include <linux/byteorder/generic.h> | 28 | #include <linux/byteorder/generic.h> |
28 | #include <linux/platform_data/pxa2xx_udc.h> | 29 | #include <linux/platform_data/pxa2xx_udc.h> |
30 | #include <linux/of_device.h> | ||
31 | #include <linux/of_gpio.h> | ||
29 | 32 | ||
30 | #include <linux/usb.h> | 33 | #include <linux/usb.h> |
31 | #include <linux/usb/ch9.h> | 34 | #include <linux/usb/ch9.h> |
@@ -1507,18 +1510,13 @@ static struct usb_ep_ops pxa_ep_ops = { | |||
1507 | */ | 1510 | */ |
1508 | static void dplus_pullup(struct pxa_udc *udc, int on) | 1511 | static void dplus_pullup(struct pxa_udc *udc, int on) |
1509 | { | 1512 | { |
1510 | if (on) { | 1513 | if (udc->gpiod) { |
1511 | if (gpio_is_valid(udc->mach->gpio_pullup)) | 1514 | gpiod_set_value(udc->gpiod, on); |
1512 | gpio_set_value(udc->mach->gpio_pullup, | 1515 | } else if (udc->udc_command) { |
1513 | !udc->mach->gpio_pullup_inverted); | 1516 | if (on) |
1514 | if (udc->mach->udc_command) | 1517 | udc->udc_command(PXA2XX_UDC_CMD_CONNECT); |
1515 | udc->mach->udc_command(PXA2XX_UDC_CMD_CONNECT); | 1518 | else |
1516 | } else { | 1519 | udc->udc_command(PXA2XX_UDC_CMD_DISCONNECT); |
1517 | if (gpio_is_valid(udc->mach->gpio_pullup)) | ||
1518 | gpio_set_value(udc->mach->gpio_pullup, | ||
1519 | udc->mach->gpio_pullup_inverted); | ||
1520 | if (udc->mach->udc_command) | ||
1521 | udc->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); | ||
1522 | } | 1520 | } |
1523 | udc->pullup_on = on; | 1521 | udc->pullup_on = on; |
1524 | } | 1522 | } |
@@ -1609,7 +1607,7 @@ static int pxa_udc_pullup(struct usb_gadget *_gadget, int is_active) | |||
1609 | { | 1607 | { |
1610 | struct pxa_udc *udc = to_gadget_udc(_gadget); | 1608 | struct pxa_udc *udc = to_gadget_udc(_gadget); |
1611 | 1609 | ||
1612 | if (!gpio_is_valid(udc->mach->gpio_pullup) && !udc->mach->udc_command) | 1610 | if (!udc->gpiod && !udc->udc_command) |
1613 | return -EOPNOTSUPP; | 1611 | return -EOPNOTSUPP; |
1614 | 1612 | ||
1615 | dplus_pullup(udc, is_active); | 1613 | dplus_pullup(udc, is_active); |
@@ -1671,8 +1669,7 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA) | |||
1671 | 1669 | ||
1672 | static int pxa27x_udc_start(struct usb_gadget *g, | 1670 | static int pxa27x_udc_start(struct usb_gadget *g, |
1673 | struct usb_gadget_driver *driver); | 1671 | struct usb_gadget_driver *driver); |
1674 | static int pxa27x_udc_stop(struct usb_gadget *g, | 1672 | static int pxa27x_udc_stop(struct usb_gadget *g); |
1675 | struct usb_gadget_driver *driver); | ||
1676 | 1673 | ||
1677 | static const struct usb_gadget_ops pxa_udc_ops = { | 1674 | static const struct usb_gadget_ops pxa_udc_ops = { |
1678 | .get_frame = pxa_udc_get_frame, | 1675 | .get_frame = pxa_udc_get_frame, |
@@ -1701,10 +1698,10 @@ static void udc_disable(struct pxa_udc *udc) | |||
1701 | udc_writel(udc, UDCICR1, 0); | 1698 | udc_writel(udc, UDCICR1, 0); |
1702 | 1699 | ||
1703 | udc_clear_mask_UDCCR(udc, UDCCR_UDE); | 1700 | udc_clear_mask_UDCCR(udc, UDCCR_UDE); |
1704 | clk_disable(udc->clk); | ||
1705 | 1701 | ||
1706 | ep0_idle(udc); | 1702 | ep0_idle(udc); |
1707 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 1703 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
1704 | clk_disable(udc->clk); | ||
1708 | 1705 | ||
1709 | udc->enabled = 0; | 1706 | udc->enabled = 0; |
1710 | } | 1707 | } |
@@ -1757,16 +1754,16 @@ static void udc_enable(struct pxa_udc *udc) | |||
1757 | if (udc->enabled) | 1754 | if (udc->enabled) |
1758 | return; | 1755 | return; |
1759 | 1756 | ||
1757 | clk_enable(udc->clk); | ||
1760 | udc_writel(udc, UDCICR0, 0); | 1758 | udc_writel(udc, UDCICR0, 0); |
1761 | udc_writel(udc, UDCICR1, 0); | 1759 | udc_writel(udc, UDCICR1, 0); |
1762 | udc_clear_mask_UDCCR(udc, UDCCR_UDE); | 1760 | udc_clear_mask_UDCCR(udc, UDCCR_UDE); |
1763 | 1761 | ||
1764 | clk_enable(udc->clk); | ||
1765 | |||
1766 | ep0_idle(udc); | 1762 | ep0_idle(udc); |
1767 | udc->gadget.speed = USB_SPEED_FULL; | 1763 | udc->gadget.speed = USB_SPEED_FULL; |
1768 | memset(&udc->stats, 0, sizeof(udc->stats)); | 1764 | memset(&udc->stats, 0, sizeof(udc->stats)); |
1769 | 1765 | ||
1766 | pxa_eps_setup(udc); | ||
1770 | udc_set_mask_UDCCR(udc, UDCCR_UDE); | 1767 | udc_set_mask_UDCCR(udc, UDCCR_UDE); |
1771 | ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_ACM); | 1768 | ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_ACM); |
1772 | udelay(2); | 1769 | udelay(2); |
@@ -1859,12 +1856,11 @@ static void stop_activity(struct pxa_udc *udc, struct usb_gadget_driver *driver) | |||
1859 | * | 1856 | * |
1860 | * Returns 0 if no error, -ENODEV, -EINVAL otherwise | 1857 | * Returns 0 if no error, -ENODEV, -EINVAL otherwise |
1861 | */ | 1858 | */ |
1862 | static int pxa27x_udc_stop(struct usb_gadget *g, | 1859 | static int pxa27x_udc_stop(struct usb_gadget *g) |
1863 | struct usb_gadget_driver *driver) | ||
1864 | { | 1860 | { |
1865 | struct pxa_udc *udc = to_pxa(g); | 1861 | struct pxa_udc *udc = to_pxa(g); |
1866 | 1862 | ||
1867 | stop_activity(udc, driver); | 1863 | stop_activity(udc, NULL); |
1868 | udc_disable(udc); | 1864 | udc_disable(udc); |
1869 | dplus_pullup(udc, 0); | 1865 | dplus_pullup(udc, 0); |
1870 | 1866 | ||
@@ -2404,6 +2400,14 @@ static struct pxa_udc memory = { | |||
2404 | } | 2400 | } |
2405 | }; | 2401 | }; |
2406 | 2402 | ||
2403 | #if defined(CONFIG_OF) | ||
2404 | static struct of_device_id udc_pxa_dt_ids[] = { | ||
2405 | { .compatible = "marvell,pxa270-udc" }, | ||
2406 | {} | ||
2407 | }; | ||
2408 | MODULE_DEVICE_TABLE(of, udc_pxa_dt_ids); | ||
2409 | #endif | ||
2410 | |||
2407 | /** | 2411 | /** |
2408 | * pxa_udc_probe - probes the udc device | 2412 | * pxa_udc_probe - probes the udc device |
2409 | * @_dev: platform device | 2413 | * @_dev: platform device |
@@ -2416,81 +2420,77 @@ static int pxa_udc_probe(struct platform_device *pdev) | |||
2416 | struct resource *regs; | 2420 | struct resource *regs; |
2417 | struct pxa_udc *udc = &memory; | 2421 | struct pxa_udc *udc = &memory; |
2418 | int retval = 0, gpio; | 2422 | int retval = 0, gpio; |
2423 | struct pxa2xx_udc_mach_info *mach = dev_get_platdata(&pdev->dev); | ||
2424 | unsigned long gpio_flags; | ||
2425 | |||
2426 | if (mach) { | ||
2427 | gpio_flags = mach->gpio_pullup_inverted ? GPIOF_ACTIVE_LOW : 0; | ||
2428 | gpio = mach->gpio_pullup; | ||
2429 | if (gpio_is_valid(gpio)) { | ||
2430 | retval = devm_gpio_request_one(&pdev->dev, gpio, | ||
2431 | gpio_flags, | ||
2432 | "USB D+ pullup"); | ||
2433 | if (retval) | ||
2434 | return retval; | ||
2435 | udc->gpiod = gpio_to_desc(mach->gpio_pullup); | ||
2436 | } | ||
2437 | udc->udc_command = mach->udc_command; | ||
2438 | } else { | ||
2439 | udc->gpiod = devm_gpiod_get(&pdev->dev, NULL); | ||
2440 | } | ||
2419 | 2441 | ||
2420 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 2442 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
2421 | if (!regs) | 2443 | udc->regs = devm_ioremap_resource(&pdev->dev, regs); |
2422 | return -ENXIO; | 2444 | if (IS_ERR(udc->regs)) |
2445 | return PTR_ERR(udc->regs); | ||
2423 | udc->irq = platform_get_irq(pdev, 0); | 2446 | udc->irq = platform_get_irq(pdev, 0); |
2424 | if (udc->irq < 0) | 2447 | if (udc->irq < 0) |
2425 | return udc->irq; | 2448 | return udc->irq; |
2426 | 2449 | ||
2427 | udc->dev = &pdev->dev; | 2450 | udc->dev = &pdev->dev; |
2428 | udc->mach = dev_get_platdata(&pdev->dev); | ||
2429 | udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); | 2451 | udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); |
2430 | 2452 | ||
2431 | gpio = udc->mach->gpio_pullup; | 2453 | if (IS_ERR(udc->gpiod)) { |
2432 | if (gpio_is_valid(gpio)) { | 2454 | dev_err(&pdev->dev, "Couldn't find or request D+ gpio : %ld\n", |
2433 | retval = gpio_request(gpio, "USB D+ pullup"); | 2455 | PTR_ERR(udc->gpiod)); |
2434 | if (retval == 0) | 2456 | return PTR_ERR(udc->gpiod); |
2435 | gpio_direction_output(gpio, | ||
2436 | udc->mach->gpio_pullup_inverted); | ||
2437 | } | ||
2438 | if (retval) { | ||
2439 | dev_err(&pdev->dev, "Couldn't request gpio %d : %d\n", | ||
2440 | gpio, retval); | ||
2441 | return retval; | ||
2442 | } | 2457 | } |
2458 | if (udc->gpiod) | ||
2459 | gpiod_direction_output(udc->gpiod, 0); | ||
2460 | |||
2461 | udc->clk = devm_clk_get(&pdev->dev, NULL); | ||
2462 | if (IS_ERR(udc->clk)) | ||
2463 | return PTR_ERR(udc->clk); | ||
2443 | 2464 | ||
2444 | udc->clk = clk_get(&pdev->dev, NULL); | ||
2445 | if (IS_ERR(udc->clk)) { | ||
2446 | retval = PTR_ERR(udc->clk); | ||
2447 | goto err_clk; | ||
2448 | } | ||
2449 | retval = clk_prepare(udc->clk); | 2465 | retval = clk_prepare(udc->clk); |
2450 | if (retval) | 2466 | if (retval) |
2451 | goto err_clk_prepare; | 2467 | return retval; |
2452 | |||
2453 | retval = -ENOMEM; | ||
2454 | udc->regs = ioremap(regs->start, resource_size(regs)); | ||
2455 | if (!udc->regs) { | ||
2456 | dev_err(&pdev->dev, "Unable to map UDC I/O memory\n"); | ||
2457 | goto err_map; | ||
2458 | } | ||
2459 | 2468 | ||
2460 | udc->vbus_sensed = 0; | 2469 | udc->vbus_sensed = 0; |
2461 | 2470 | ||
2462 | the_controller = udc; | 2471 | the_controller = udc; |
2463 | platform_set_drvdata(pdev, udc); | 2472 | platform_set_drvdata(pdev, udc); |
2464 | udc_init_data(udc); | 2473 | udc_init_data(udc); |
2465 | pxa_eps_setup(udc); | ||
2466 | 2474 | ||
2467 | /* irq setup after old hardware state is cleaned up */ | 2475 | /* irq setup after old hardware state is cleaned up */ |
2468 | retval = request_irq(udc->irq, pxa_udc_irq, | 2476 | retval = devm_request_irq(&pdev->dev, udc->irq, pxa_udc_irq, |
2469 | IRQF_SHARED, driver_name, udc); | 2477 | IRQF_SHARED, driver_name, udc); |
2470 | if (retval != 0) { | 2478 | if (retval != 0) { |
2471 | dev_err(udc->dev, "%s: can't get irq %i, err %d\n", | 2479 | dev_err(udc->dev, "%s: can't get irq %i, err %d\n", |
2472 | driver_name, udc->irq, retval); | 2480 | driver_name, udc->irq, retval); |
2473 | goto err_irq; | 2481 | goto err; |
2474 | } | 2482 | } |
2475 | 2483 | ||
2476 | retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | 2484 | retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); |
2477 | if (retval) | 2485 | if (retval) |
2478 | goto err_add_udc; | 2486 | goto err; |
2479 | 2487 | ||
2480 | pxa_init_debugfs(udc); | 2488 | pxa_init_debugfs(udc); |
2481 | 2489 | if (should_enable_udc(udc)) | |
2490 | udc_enable(udc); | ||
2482 | return 0; | 2491 | return 0; |
2483 | 2492 | err: | |
2484 | err_add_udc: | ||
2485 | free_irq(udc->irq, udc); | ||
2486 | err_irq: | ||
2487 | iounmap(udc->regs); | ||
2488 | err_map: | ||
2489 | clk_unprepare(udc->clk); | 2493 | clk_unprepare(udc->clk); |
2490 | err_clk_prepare: | ||
2491 | clk_put(udc->clk); | ||
2492 | udc->clk = NULL; | ||
2493 | err_clk: | ||
2494 | return retval; | 2494 | return retval; |
2495 | } | 2495 | } |
2496 | 2496 | ||
@@ -2501,22 +2501,15 @@ err_clk: | |||
2501 | static int pxa_udc_remove(struct platform_device *_dev) | 2501 | static int pxa_udc_remove(struct platform_device *_dev) |
2502 | { | 2502 | { |
2503 | struct pxa_udc *udc = platform_get_drvdata(_dev); | 2503 | struct pxa_udc *udc = platform_get_drvdata(_dev); |
2504 | int gpio = udc->mach->gpio_pullup; | ||
2505 | 2504 | ||
2506 | usb_del_gadget_udc(&udc->gadget); | 2505 | usb_del_gadget_udc(&udc->gadget); |
2507 | usb_gadget_unregister_driver(udc->driver); | ||
2508 | free_irq(udc->irq, udc); | ||
2509 | pxa_cleanup_debugfs(udc); | 2506 | pxa_cleanup_debugfs(udc); |
2510 | if (gpio_is_valid(gpio)) | ||
2511 | gpio_free(gpio); | ||
2512 | 2507 | ||
2513 | usb_put_phy(udc->transceiver); | 2508 | usb_put_phy(udc->transceiver); |
2514 | 2509 | ||
2515 | udc->transceiver = NULL; | 2510 | udc->transceiver = NULL; |
2516 | the_controller = NULL; | 2511 | the_controller = NULL; |
2517 | clk_unprepare(udc->clk); | 2512 | clk_unprepare(udc->clk); |
2518 | clk_put(udc->clk); | ||
2519 | iounmap(udc->regs); | ||
2520 | 2513 | ||
2521 | return 0; | 2514 | return 0; |
2522 | } | 2515 | } |
@@ -2546,19 +2539,11 @@ extern void pxa27x_clear_otgph(void); | |||
2546 | */ | 2539 | */ |
2547 | static int pxa_udc_suspend(struct platform_device *_dev, pm_message_t state) | 2540 | static int pxa_udc_suspend(struct platform_device *_dev, pm_message_t state) |
2548 | { | 2541 | { |
2549 | int i; | ||
2550 | struct pxa_udc *udc = platform_get_drvdata(_dev); | 2542 | struct pxa_udc *udc = platform_get_drvdata(_dev); |
2551 | struct pxa_ep *ep; | 2543 | struct pxa_ep *ep; |
2552 | 2544 | ||
2553 | ep = &udc->pxa_ep[0]; | 2545 | ep = &udc->pxa_ep[0]; |
2554 | udc->udccsr0 = udc_ep_readl(ep, UDCCSR); | 2546 | udc->udccsr0 = udc_ep_readl(ep, UDCCSR); |
2555 | for (i = 1; i < NR_PXA_ENDPOINTS; i++) { | ||
2556 | ep = &udc->pxa_ep[i]; | ||
2557 | ep->udccsr_value = udc_ep_readl(ep, UDCCSR); | ||
2558 | ep->udccr_value = udc_ep_readl(ep, UDCCR); | ||
2559 | ep_dbg(ep, "udccsr:0x%03x, udccr:0x%x\n", | ||
2560 | ep->udccsr_value, ep->udccr_value); | ||
2561 | } | ||
2562 | 2547 | ||
2563 | udc_disable(udc); | 2548 | udc_disable(udc); |
2564 | udc->pullup_resume = udc->pullup_on; | 2549 | udc->pullup_resume = udc->pullup_on; |
@@ -2576,19 +2561,11 @@ static int pxa_udc_suspend(struct platform_device *_dev, pm_message_t state) | |||
2576 | */ | 2561 | */ |
2577 | static int pxa_udc_resume(struct platform_device *_dev) | 2562 | static int pxa_udc_resume(struct platform_device *_dev) |
2578 | { | 2563 | { |
2579 | int i; | ||
2580 | struct pxa_udc *udc = platform_get_drvdata(_dev); | 2564 | struct pxa_udc *udc = platform_get_drvdata(_dev); |
2581 | struct pxa_ep *ep; | 2565 | struct pxa_ep *ep; |
2582 | 2566 | ||
2583 | ep = &udc->pxa_ep[0]; | 2567 | ep = &udc->pxa_ep[0]; |
2584 | udc_ep_writel(ep, UDCCSR, udc->udccsr0 & (UDCCSR0_FST | UDCCSR0_DME)); | 2568 | udc_ep_writel(ep, UDCCSR, udc->udccsr0 & (UDCCSR0_FST | UDCCSR0_DME)); |
2585 | for (i = 1; i < NR_PXA_ENDPOINTS; i++) { | ||
2586 | ep = &udc->pxa_ep[i]; | ||
2587 | udc_ep_writel(ep, UDCCSR, ep->udccsr_value); | ||
2588 | udc_ep_writel(ep, UDCCR, ep->udccr_value); | ||
2589 | ep_dbg(ep, "udccsr:0x%03x, udccr:0x%x\n", | ||
2590 | ep->udccsr_value, ep->udccr_value); | ||
2591 | } | ||
2592 | 2569 | ||
2593 | dplus_pullup(udc, udc->pullup_resume); | 2570 | dplus_pullup(udc, udc->pullup_resume); |
2594 | if (should_enable_udc(udc)) | 2571 | if (should_enable_udc(udc)) |
@@ -2615,6 +2592,7 @@ static struct platform_driver udc_driver = { | |||
2615 | .driver = { | 2592 | .driver = { |
2616 | .name = "pxa27x-udc", | 2593 | .name = "pxa27x-udc", |
2617 | .owner = THIS_MODULE, | 2594 | .owner = THIS_MODULE, |
2595 | .of_match_table = of_match_ptr(udc_pxa_dt_ids), | ||
2618 | }, | 2596 | }, |
2619 | .probe = pxa_udc_probe, | 2597 | .probe = pxa_udc_probe, |
2620 | .remove = pxa_udc_remove, | 2598 | .remove = pxa_udc_remove, |
diff --git a/drivers/usb/gadget/udc/pxa27x_udc.h b/drivers/usb/gadget/udc/pxa27x_udc.h index 28f2b53530f5..11e14232794b 100644 --- a/drivers/usb/gadget/udc/pxa27x_udc.h +++ b/drivers/usb/gadget/udc/pxa27x_udc.h | |||
@@ -420,7 +420,8 @@ struct udc_stats { | |||
420 | * @usb_gadget: udc gadget structure | 420 | * @usb_gadget: udc gadget structure |
421 | * @driver: bound gadget (zero, g_ether, g_mass_storage, ...) | 421 | * @driver: bound gadget (zero, g_ether, g_mass_storage, ...) |
422 | * @dev: device | 422 | * @dev: device |
423 | * @mach: machine info, used to activate specific GPIO | 423 | * @udc_command: machine specific function to activate D+ pullup |
424 | * @gpiod: gpio descriptor of gpio for D+ pullup (or NULL if none) | ||
424 | * @transceiver: external transceiver to handle vbus sense and D+ pullup | 425 | * @transceiver: external transceiver to handle vbus sense and D+ pullup |
425 | * @ep0state: control endpoint state machine state | 426 | * @ep0state: control endpoint state machine state |
426 | * @stats: statistics on udc usage | 427 | * @stats: statistics on udc usage |
@@ -446,7 +447,8 @@ struct pxa_udc { | |||
446 | struct usb_gadget gadget; | 447 | struct usb_gadget gadget; |
447 | struct usb_gadget_driver *driver; | 448 | struct usb_gadget_driver *driver; |
448 | struct device *dev; | 449 | struct device *dev; |
449 | struct pxa2xx_udc_mach_info *mach; | 450 | void (*udc_command)(int); |
451 | struct gpio_desc *gpiod; | ||
450 | struct usb_phy *transceiver; | 452 | struct usb_phy *transceiver; |
451 | 453 | ||
452 | enum ep0_state ep0state; | 454 | enum ep0_state ep0state; |
diff --git a/drivers/usb/gadget/udc/r8a66597-udc.c b/drivers/usb/gadget/udc/r8a66597-udc.c index f8186613b53e..06870da0b988 100644 --- a/drivers/usb/gadget/udc/r8a66597-udc.c +++ b/drivers/usb/gadget/udc/r8a66597-udc.c | |||
@@ -1345,7 +1345,7 @@ static void irq_device_state(struct r8a66597 *r8a66597) | |||
1345 | if (dvsq == DS_DFLT) { | 1345 | if (dvsq == DS_DFLT) { |
1346 | /* bus reset */ | 1346 | /* bus reset */ |
1347 | spin_unlock(&r8a66597->lock); | 1347 | spin_unlock(&r8a66597->lock); |
1348 | r8a66597->driver->disconnect(&r8a66597->gadget); | 1348 | usb_gadget_udc_reset(&r8a66597->gadget, r8a66597->driver); |
1349 | spin_lock(&r8a66597->lock); | 1349 | spin_lock(&r8a66597->lock); |
1350 | r8a66597_update_usb_speed(r8a66597); | 1350 | r8a66597_update_usb_speed(r8a66597); |
1351 | } | 1351 | } |
@@ -1763,8 +1763,7 @@ static int r8a66597_start(struct usb_gadget *gadget, | |||
1763 | return 0; | 1763 | return 0; |
1764 | } | 1764 | } |
1765 | 1765 | ||
1766 | static int r8a66597_stop(struct usb_gadget *gadget, | 1766 | static int r8a66597_stop(struct usb_gadget *gadget) |
1767 | struct usb_gadget_driver *driver) | ||
1768 | { | 1767 | { |
1769 | struct r8a66597 *r8a66597 = gadget_to_r8a66597(gadget); | 1768 | struct r8a66597 *r8a66597 = gadget_to_r8a66597(gadget); |
1770 | unsigned long flags; | 1769 | unsigned long flags; |
@@ -1846,10 +1845,7 @@ static int r8a66597_sudmac_ioremap(struct r8a66597 *r8a66597, | |||
1846 | 1845 | ||
1847 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sudmac"); | 1846 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sudmac"); |
1848 | r8a66597->sudmac_reg = devm_ioremap_resource(&pdev->dev, res); | 1847 | r8a66597->sudmac_reg = devm_ioremap_resource(&pdev->dev, res); |
1849 | if (IS_ERR(r8a66597->sudmac_reg)) | 1848 | return PTR_ERR_OR_ZERO(r8a66597->sudmac_reg); |
1850 | return PTR_ERR(r8a66597->sudmac_reg); | ||
1851 | |||
1852 | return 0; | ||
1853 | } | 1849 | } |
1854 | 1850 | ||
1855 | static int r8a66597_probe(struct platform_device *pdev) | 1851 | static int r8a66597_probe(struct platform_device *pdev) |
diff --git a/drivers/usb/gadget/udc/s3c-hsudc.c b/drivers/usb/gadget/udc/s3c-hsudc.c index dfbf55797360..97d3a9144381 100644 --- a/drivers/usb/gadget/udc/s3c-hsudc.c +++ b/drivers/usb/gadget/udc/s3c-hsudc.c | |||
@@ -1172,8 +1172,6 @@ static int s3c_hsudc_start(struct usb_gadget *gadget, | |||
1172 | } | 1172 | } |
1173 | 1173 | ||
1174 | enable_irq(hsudc->irq); | 1174 | enable_irq(hsudc->irq); |
1175 | dev_info(hsudc->dev, "bound driver %s\n", driver->driver.name); | ||
1176 | |||
1177 | s3c_hsudc_reconfig(hsudc); | 1175 | s3c_hsudc_reconfig(hsudc); |
1178 | 1176 | ||
1179 | pm_runtime_get_sync(hsudc->dev); | 1177 | pm_runtime_get_sync(hsudc->dev); |
@@ -1190,8 +1188,7 @@ err_supplies: | |||
1190 | return ret; | 1188 | return ret; |
1191 | } | 1189 | } |
1192 | 1190 | ||
1193 | static int s3c_hsudc_stop(struct usb_gadget *gadget, | 1191 | static int s3c_hsudc_stop(struct usb_gadget *gadget) |
1194 | struct usb_gadget_driver *driver) | ||
1195 | { | 1192 | { |
1196 | struct s3c_hsudc *hsudc = to_hsudc(gadget); | 1193 | struct s3c_hsudc *hsudc = to_hsudc(gadget); |
1197 | unsigned long flags; | 1194 | unsigned long flags; |
@@ -1199,11 +1196,7 @@ static int s3c_hsudc_stop(struct usb_gadget *gadget, | |||
1199 | if (!hsudc) | 1196 | if (!hsudc) |
1200 | return -ENODEV; | 1197 | return -ENODEV; |
1201 | 1198 | ||
1202 | if (!driver || driver != hsudc->driver) | ||
1203 | return -EINVAL; | ||
1204 | |||
1205 | spin_lock_irqsave(&hsudc->lock, flags); | 1199 | spin_lock_irqsave(&hsudc->lock, flags); |
1206 | hsudc->driver = NULL; | ||
1207 | hsudc->gadget.speed = USB_SPEED_UNKNOWN; | 1200 | hsudc->gadget.speed = USB_SPEED_UNKNOWN; |
1208 | s3c_hsudc_uninit_phy(); | 1201 | s3c_hsudc_uninit_phy(); |
1209 | 1202 | ||
@@ -1220,9 +1213,8 @@ static int s3c_hsudc_stop(struct usb_gadget *gadget, | |||
1220 | disable_irq(hsudc->irq); | 1213 | disable_irq(hsudc->irq); |
1221 | 1214 | ||
1222 | regulator_bulk_disable(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); | 1215 | regulator_bulk_disable(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); |
1216 | hsudc->driver = NULL; | ||
1223 | 1217 | ||
1224 | dev_info(hsudc->dev, "unregistered gadget driver '%s'\n", | ||
1225 | driver->driver.name); | ||
1226 | return 0; | 1218 | return 0; |
1227 | } | 1219 | } |
1228 | 1220 | ||
@@ -1267,10 +1259,8 @@ static int s3c_hsudc_probe(struct platform_device *pdev) | |||
1267 | hsudc = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsudc) + | 1259 | hsudc = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsudc) + |
1268 | sizeof(struct s3c_hsudc_ep) * pd->epnum, | 1260 | sizeof(struct s3c_hsudc_ep) * pd->epnum, |
1269 | GFP_KERNEL); | 1261 | GFP_KERNEL); |
1270 | if (!hsudc) { | 1262 | if (!hsudc) |
1271 | dev_err(dev, "cannot allocate memory\n"); | ||
1272 | return -ENOMEM; | 1263 | return -ENOMEM; |
1273 | } | ||
1274 | 1264 | ||
1275 | platform_set_drvdata(pdev, dev); | 1265 | platform_set_drvdata(pdev, dev); |
1276 | hsudc->dev = dev; | 1266 | hsudc->dev = dev; |
diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c b/drivers/usb/gadget/udc/s3c2410_udc.c index ff423d15beff..2a8e36d31488 100644 --- a/drivers/usb/gadget/udc/s3c2410_udc.c +++ b/drivers/usb/gadget/udc/s3c2410_udc.c | |||
@@ -1541,8 +1541,7 @@ static int s3c2410_vbus_draw(struct usb_gadget *_gadget, unsigned ma) | |||
1541 | 1541 | ||
1542 | static int s3c2410_udc_start(struct usb_gadget *g, | 1542 | static int s3c2410_udc_start(struct usb_gadget *g, |
1543 | struct usb_gadget_driver *driver); | 1543 | struct usb_gadget_driver *driver); |
1544 | static int s3c2410_udc_stop(struct usb_gadget *g, | 1544 | static int s3c2410_udc_stop(struct usb_gadget *g); |
1545 | struct usb_gadget_driver *driver); | ||
1546 | 1545 | ||
1547 | static const struct usb_gadget_ops s3c2410_ops = { | 1546 | static const struct usb_gadget_ops s3c2410_ops = { |
1548 | .get_frame = s3c2410_udc_get_frame, | 1547 | .get_frame = s3c2410_udc_get_frame, |
@@ -1683,8 +1682,7 @@ static int s3c2410_udc_start(struct usb_gadget *g, | |||
1683 | return 0; | 1682 | return 0; |
1684 | } | 1683 | } |
1685 | 1684 | ||
1686 | static int s3c2410_udc_stop(struct usb_gadget *g, | 1685 | static int s3c2410_udc_stop(struct usb_gadget *g) |
1687 | struct usb_gadget_driver *driver) | ||
1688 | { | 1686 | { |
1689 | struct s3c2410_udc *udc = to_s3c2410(g); | 1687 | struct s3c2410_udc *udc = to_s3c2410(g); |
1690 | 1688 | ||
diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index f2054659f25b..e31d574d8860 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c | |||
@@ -174,8 +174,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); | |||
174 | 174 | ||
175 | /** | 175 | /** |
176 | * usb_gadget_udc_start - tells usb device controller to start up | 176 | * usb_gadget_udc_start - tells usb device controller to start up |
177 | * @gadget: The gadget we want to get started | 177 | * @udc: The UDC to be started |
178 | * @driver: The driver we want to bind to @gadget | ||
179 | * | 178 | * |
180 | * This call is issued by the UDC Class driver when it's about | 179 | * This call is issued by the UDC Class driver when it's about |
181 | * to register a gadget driver to the device controller, before | 180 | * to register a gadget driver to the device controller, before |
@@ -186,10 +185,9 @@ EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); | |||
186 | * | 185 | * |
187 | * Returns zero on success, else negative errno. | 186 | * Returns zero on success, else negative errno. |
188 | */ | 187 | */ |
189 | static inline int usb_gadget_udc_start(struct usb_gadget *gadget, | 188 | static inline int usb_gadget_udc_start(struct usb_udc *udc) |
190 | struct usb_gadget_driver *driver) | ||
191 | { | 189 | { |
192 | return gadget->ops->udc_start(gadget, driver); | 190 | return udc->gadget->ops->udc_start(udc->gadget, udc->driver); |
193 | } | 191 | } |
194 | 192 | ||
195 | /** | 193 | /** |
@@ -204,10 +202,9 @@ static inline int usb_gadget_udc_start(struct usb_gadget *gadget, | |||
204 | * far as powering off UDC completely and disable its data | 202 | * far as powering off UDC completely and disable its data |
205 | * line pullups. | 203 | * line pullups. |
206 | */ | 204 | */ |
207 | static inline void usb_gadget_udc_stop(struct usb_gadget *gadget, | 205 | static inline void usb_gadget_udc_stop(struct usb_udc *udc) |
208 | struct usb_gadget_driver *driver) | ||
209 | { | 206 | { |
210 | gadget->ops->udc_stop(gadget, driver); | 207 | udc->gadget->ops->udc_stop(udc->gadget); |
211 | } | 208 | } |
212 | 209 | ||
213 | /** | 210 | /** |
@@ -328,14 +325,14 @@ EXPORT_SYMBOL_GPL(usb_add_gadget_udc); | |||
328 | static void usb_gadget_remove_driver(struct usb_udc *udc) | 325 | static void usb_gadget_remove_driver(struct usb_udc *udc) |
329 | { | 326 | { |
330 | dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n", | 327 | dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n", |
331 | udc->gadget->name); | 328 | udc->driver->function); |
332 | 329 | ||
333 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); | 330 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); |
334 | 331 | ||
335 | usb_gadget_disconnect(udc->gadget); | 332 | usb_gadget_disconnect(udc->gadget); |
336 | udc->driver->disconnect(udc->gadget); | 333 | udc->driver->disconnect(udc->gadget); |
337 | udc->driver->unbind(udc->gadget); | 334 | udc->driver->unbind(udc->gadget); |
338 | usb_gadget_udc_stop(udc->gadget, NULL); | 335 | usb_gadget_udc_stop(udc); |
339 | 336 | ||
340 | udc->driver = NULL; | 337 | udc->driver = NULL; |
341 | udc->dev.driver = NULL; | 338 | udc->dev.driver = NULL; |
@@ -395,7 +392,7 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri | |||
395 | ret = driver->bind(udc->gadget, driver); | 392 | ret = driver->bind(udc->gadget, driver); |
396 | if (ret) | 393 | if (ret) |
397 | goto err1; | 394 | goto err1; |
398 | ret = usb_gadget_udc_start(udc->gadget, driver); | 395 | ret = usb_gadget_udc_start(udc); |
399 | if (ret) { | 396 | if (ret) { |
400 | driver->unbind(udc->gadget); | 397 | driver->unbind(udc->gadget); |
401 | goto err1; | 398 | goto err1; |
@@ -414,7 +411,7 @@ err1: | |||
414 | return ret; | 411 | return ret; |
415 | } | 412 | } |
416 | 413 | ||
417 | int udc_attach_driver(const char *name, struct usb_gadget_driver *driver) | 414 | int usb_udc_attach_driver(const char *name, struct usb_gadget_driver *driver) |
418 | { | 415 | { |
419 | struct usb_udc *udc = NULL; | 416 | struct usb_udc *udc = NULL; |
420 | int ret = -ENODEV; | 417 | int ret = -ENODEV; |
@@ -438,7 +435,7 @@ out: | |||
438 | mutex_unlock(&udc_lock); | 435 | mutex_unlock(&udc_lock); |
439 | return ret; | 436 | return ret; |
440 | } | 437 | } |
441 | EXPORT_SYMBOL_GPL(udc_attach_driver); | 438 | EXPORT_SYMBOL_GPL(usb_udc_attach_driver); |
442 | 439 | ||
443 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver) | 440 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver) |
444 | { | 441 | { |
@@ -513,11 +510,12 @@ static ssize_t usb_udc_softconn_store(struct device *dev, | |||
513 | } | 510 | } |
514 | 511 | ||
515 | if (sysfs_streq(buf, "connect")) { | 512 | if (sysfs_streq(buf, "connect")) { |
516 | usb_gadget_udc_start(udc->gadget, udc->driver); | 513 | usb_gadget_udc_start(udc); |
517 | usb_gadget_connect(udc->gadget); | 514 | usb_gadget_connect(udc->gadget); |
518 | } else if (sysfs_streq(buf, "disconnect")) { | 515 | } else if (sysfs_streq(buf, "disconnect")) { |
519 | usb_gadget_disconnect(udc->gadget); | 516 | usb_gadget_disconnect(udc->gadget); |
520 | usb_gadget_udc_stop(udc->gadget, udc->driver); | 517 | udc->driver->disconnect(udc->gadget); |
518 | usb_gadget_udc_stop(udc); | ||
521 | } else { | 519 | } else { |
522 | dev_err(dev, "unsupported command '%s'\n", buf); | 520 | dev_err(dev, "unsupported command '%s'\n", buf); |
523 | return -EINVAL; | 521 | return -EINVAL; |
diff --git a/drivers/usb/gadget/udc/udc-xilinx.c b/drivers/usb/gadget/udc/udc-xilinx.c index ed27e1687a4e..1eac56fc384d 100644 --- a/drivers/usb/gadget/udc/udc-xilinx.c +++ b/drivers/usb/gadget/udc/udc-xilinx.c | |||
@@ -1403,8 +1403,7 @@ err: | |||
1403 | * | 1403 | * |
1404 | * Return: zero always | 1404 | * Return: zero always |
1405 | */ | 1405 | */ |
1406 | static int xudc_stop(struct usb_gadget *gadget, | 1406 | static int xudc_stop(struct usb_gadget *gadget) |
1407 | struct usb_gadget_driver *driver) | ||
1408 | { | 1407 | { |
1409 | struct xusb_udc *udc = to_udc(gadget); | 1408 | struct xusb_udc *udc = to_udc(gadget); |
1410 | unsigned long flags; | 1409 | unsigned long flags; |
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c index 0231606d47c2..3e5df5af3740 100644 --- a/drivers/usb/host/ohci-omap.c +++ b/drivers/usb/host/ohci-omap.c | |||
@@ -183,7 +183,7 @@ static void start_hnp(struct ohci_hcd *ohci) | |||
183 | otg_start_hnp(hcd->usb_phy->otg); | 183 | otg_start_hnp(hcd->usb_phy->otg); |
184 | 184 | ||
185 | local_irq_save(flags); | 185 | local_irq_save(flags); |
186 | hcd->usb_phy->state = OTG_STATE_A_SUSPEND; | 186 | hcd->usb_phy->otg->state = OTG_STATE_A_SUSPEND; |
187 | writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]); | 187 | writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]); |
188 | l = omap_readl(OTG_CTRL); | 188 | l = omap_readl(OTG_CTRL); |
189 | l &= ~OTG_A_BUSREQ; | 189 | l &= ~OTG_A_BUSREQ; |
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig index 06cc5d6ea681..9d68372dd9aa 100644 --- a/drivers/usb/musb/Kconfig +++ b/drivers/usb/musb/Kconfig | |||
@@ -58,8 +58,7 @@ config USB_MUSB_DUAL_ROLE | |||
58 | 58 | ||
59 | endchoice | 59 | endchoice |
60 | 60 | ||
61 | choice | 61 | comment "Platform Glue Layer" |
62 | prompt "Platform Glue Layer" | ||
63 | 62 | ||
64 | config USB_MUSB_DAVINCI | 63 | config USB_MUSB_DAVINCI |
65 | tristate "DaVinci" | 64 | tristate "DaVinci" |
@@ -101,8 +100,6 @@ config USB_MUSB_JZ4740 | |||
101 | depends on USB_MUSB_GADGET | 100 | depends on USB_MUSB_GADGET |
102 | depends on USB_OTG_BLACKLIST_HUB | 101 | depends on USB_OTG_BLACKLIST_HUB |
103 | 102 | ||
104 | endchoice | ||
105 | |||
106 | config USB_MUSB_AM335X_CHILD | 103 | config USB_MUSB_AM335X_CHILD |
107 | tristate | 104 | tristate |
108 | 105 | ||
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c index a2735df24cc6..220fd4d3b41c 100644 --- a/drivers/usb/musb/am35x.c +++ b/drivers/usb/musb/am35x.c | |||
@@ -149,25 +149,25 @@ static void otg_timer(unsigned long _musb) | |||
149 | */ | 149 | */ |
150 | devctl = musb_readb(mregs, MUSB_DEVCTL); | 150 | devctl = musb_readb(mregs, MUSB_DEVCTL); |
151 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, | 151 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, |
152 | usb_otg_state_string(musb->xceiv->state)); | 152 | usb_otg_state_string(musb->xceiv->otg->state)); |
153 | 153 | ||
154 | spin_lock_irqsave(&musb->lock, flags); | 154 | spin_lock_irqsave(&musb->lock, flags); |
155 | switch (musb->xceiv->state) { | 155 | switch (musb->xceiv->otg->state) { |
156 | case OTG_STATE_A_WAIT_BCON: | 156 | case OTG_STATE_A_WAIT_BCON: |
157 | devctl &= ~MUSB_DEVCTL_SESSION; | 157 | devctl &= ~MUSB_DEVCTL_SESSION; |
158 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | 158 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
159 | 159 | ||
160 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 160 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
161 | if (devctl & MUSB_DEVCTL_BDEVICE) { | 161 | if (devctl & MUSB_DEVCTL_BDEVICE) { |
162 | musb->xceiv->state = OTG_STATE_B_IDLE; | 162 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
163 | MUSB_DEV_MODE(musb); | 163 | MUSB_DEV_MODE(musb); |
164 | } else { | 164 | } else { |
165 | musb->xceiv->state = OTG_STATE_A_IDLE; | 165 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
166 | MUSB_HST_MODE(musb); | 166 | MUSB_HST_MODE(musb); |
167 | } | 167 | } |
168 | break; | 168 | break; |
169 | case OTG_STATE_A_WAIT_VFALL: | 169 | case OTG_STATE_A_WAIT_VFALL: |
170 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 170 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
171 | musb_writel(musb->ctrl_base, CORE_INTR_SRC_SET_REG, | 171 | musb_writel(musb->ctrl_base, CORE_INTR_SRC_SET_REG, |
172 | MUSB_INTR_VBUSERROR << AM35X_INTR_USB_SHIFT); | 172 | MUSB_INTR_VBUSERROR << AM35X_INTR_USB_SHIFT); |
173 | break; | 173 | break; |
@@ -176,7 +176,7 @@ static void otg_timer(unsigned long _musb) | |||
176 | if (devctl & MUSB_DEVCTL_BDEVICE) | 176 | if (devctl & MUSB_DEVCTL_BDEVICE) |
177 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 177 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
178 | else | 178 | else |
179 | musb->xceiv->state = OTG_STATE_A_IDLE; | 179 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
180 | break; | 180 | break; |
181 | default: | 181 | default: |
182 | break; | 182 | break; |
@@ -193,9 +193,9 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
193 | 193 | ||
194 | /* Never idle if active, or when VBUS timeout is not set as host */ | 194 | /* Never idle if active, or when VBUS timeout is not set as host */ |
195 | if (musb->is_active || (musb->a_wait_bcon == 0 && | 195 | if (musb->is_active || (musb->a_wait_bcon == 0 && |
196 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { | 196 | musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) { |
197 | dev_dbg(musb->controller, "%s active, deleting timer\n", | 197 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
198 | usb_otg_state_string(musb->xceiv->state)); | 198 | usb_otg_state_string(musb->xceiv->otg->state)); |
199 | del_timer(&otg_workaround); | 199 | del_timer(&otg_workaround); |
200 | last_timer = jiffies; | 200 | last_timer = jiffies; |
201 | return; | 201 | return; |
@@ -208,7 +208,7 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
208 | last_timer = timeout; | 208 | last_timer = timeout; |
209 | 209 | ||
210 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", | 210 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", |
211 | usb_otg_state_string(musb->xceiv->state), | 211 | usb_otg_state_string(musb->xceiv->otg->state), |
212 | jiffies_to_msecs(timeout - jiffies)); | 212 | jiffies_to_msecs(timeout - jiffies)); |
213 | mod_timer(&otg_workaround, timeout); | 213 | mod_timer(&otg_workaround, timeout); |
214 | } | 214 | } |
@@ -278,27 +278,27 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci) | |||
278 | * devctl. | 278 | * devctl. |
279 | */ | 279 | */ |
280 | musb->int_usb &= ~MUSB_INTR_VBUSERROR; | 280 | musb->int_usb &= ~MUSB_INTR_VBUSERROR; |
281 | musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; | 281 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; |
282 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 282 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
283 | WARNING("VBUS error workaround (delay coming)\n"); | 283 | WARNING("VBUS error workaround (delay coming)\n"); |
284 | } else if (drvvbus) { | 284 | } else if (drvvbus) { |
285 | MUSB_HST_MODE(musb); | 285 | MUSB_HST_MODE(musb); |
286 | otg->default_a = 1; | 286 | otg->default_a = 1; |
287 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 287 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
288 | portstate(musb->port1_status |= USB_PORT_STAT_POWER); | 288 | portstate(musb->port1_status |= USB_PORT_STAT_POWER); |
289 | del_timer(&otg_workaround); | 289 | del_timer(&otg_workaround); |
290 | } else { | 290 | } else { |
291 | musb->is_active = 0; | 291 | musb->is_active = 0; |
292 | MUSB_DEV_MODE(musb); | 292 | MUSB_DEV_MODE(musb); |
293 | otg->default_a = 0; | 293 | otg->default_a = 0; |
294 | musb->xceiv->state = OTG_STATE_B_IDLE; | 294 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
295 | portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); | 295 | portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); |
296 | } | 296 | } |
297 | 297 | ||
298 | /* NOTE: this must complete power-on within 100 ms. */ | 298 | /* NOTE: this must complete power-on within 100 ms. */ |
299 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", | 299 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", |
300 | drvvbus ? "on" : "off", | 300 | drvvbus ? "on" : "off", |
301 | usb_otg_state_string(musb->xceiv->state), | 301 | usb_otg_state_string(musb->xceiv->otg->state), |
302 | err ? " ERROR" : "", | 302 | err ? " ERROR" : "", |
303 | devctl); | 303 | devctl); |
304 | ret = IRQ_HANDLED; | 304 | ret = IRQ_HANDLED; |
@@ -324,7 +324,7 @@ eoi: | |||
324 | } | 324 | } |
325 | 325 | ||
326 | /* Poll for ID change */ | 326 | /* Poll for ID change */ |
327 | if (musb->xceiv->state == OTG_STATE_B_IDLE) | 327 | if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) |
328 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 328 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
329 | 329 | ||
330 | spin_unlock_irqrestore(&musb->lock, flags); | 330 | spin_unlock_irqrestore(&musb->lock, flags); |
@@ -408,7 +408,7 @@ static int am35x_musb_exit(struct musb *musb) | |||
408 | } | 408 | } |
409 | 409 | ||
410 | /* AM35x supports only 32bit read operation */ | 410 | /* AM35x supports only 32bit read operation */ |
411 | void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) | 411 | static void am35x_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) |
412 | { | 412 | { |
413 | void __iomem *fifo = hw_ep->fifo; | 413 | void __iomem *fifo = hw_ep->fifo; |
414 | u32 val; | 414 | u32 val; |
@@ -438,9 +438,11 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) | |||
438 | } | 438 | } |
439 | 439 | ||
440 | static const struct musb_platform_ops am35x_ops = { | 440 | static const struct musb_platform_ops am35x_ops = { |
441 | .quirks = MUSB_INDEXED_EP, | ||
441 | .init = am35x_musb_init, | 442 | .init = am35x_musb_init, |
442 | .exit = am35x_musb_exit, | 443 | .exit = am35x_musb_exit, |
443 | 444 | ||
445 | .read_fifo = am35x_read_fifo, | ||
444 | .enable = am35x_musb_enable, | 446 | .enable = am35x_musb_enable, |
445 | .disable = am35x_musb_disable, | 447 | .disable = am35x_musb_disable, |
446 | 448 | ||
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c index ac4422b33dcd..a441a2de8619 100644 --- a/drivers/usb/musb/blackfin.c +++ b/drivers/usb/musb/blackfin.c | |||
@@ -33,10 +33,45 @@ struct bfin_glue { | |||
33 | }; | 33 | }; |
34 | #define glue_to_musb(g) platform_get_drvdata(g->musb) | 34 | #define glue_to_musb(g) platform_get_drvdata(g->musb) |
35 | 35 | ||
36 | static u32 bfin_fifo_offset(u8 epnum) | ||
37 | { | ||
38 | return USB_OFFSET(USB_EP0_FIFO) + (epnum * 8); | ||
39 | } | ||
40 | |||
41 | static u8 bfin_readb(const void __iomem *addr, unsigned offset) | ||
42 | { | ||
43 | return (u8)(bfin_read16(addr + offset)); | ||
44 | } | ||
45 | |||
46 | static u16 bfin_readw(const void __iomem *addr, unsigned offset) | ||
47 | { | ||
48 | return bfin_read16(addr + offset); | ||
49 | } | ||
50 | |||
51 | static u32 bfin_readl(const void __iomem *addr, unsigned offset) | ||
52 | { | ||
53 | return (u32)(bfin_read16(addr + offset)); | ||
54 | } | ||
55 | |||
56 | static void bfin_writeb(void __iomem *addr, unsigned offset, u8 data) | ||
57 | { | ||
58 | bfin_write16(addr + offset, (u16)data); | ||
59 | } | ||
60 | |||
61 | static void bfin_writew(void __iomem *addr, unsigned offset, u16 data) | ||
62 | { | ||
63 | bfin_write16(addr + offset, data); | ||
64 | } | ||
65 | |||
66 | static void binf_writel(void __iomem *addr, unsigned offset, u32 data) | ||
67 | { | ||
68 | bfin_write16(addr + offset, (u16)data); | ||
69 | } | ||
70 | |||
36 | /* | 71 | /* |
37 | * Load an endpoint's FIFO | 72 | * Load an endpoint's FIFO |
38 | */ | 73 | */ |
39 | void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src) | 74 | static void bfin_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src) |
40 | { | 75 | { |
41 | struct musb *musb = hw_ep->musb; | 76 | struct musb *musb = hw_ep->musb; |
42 | void __iomem *fifo = hw_ep->fifo; | 77 | void __iomem *fifo = hw_ep->fifo; |
@@ -100,7 +135,7 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src) | |||
100 | /* | 135 | /* |
101 | * Unload an endpoint's FIFO | 136 | * Unload an endpoint's FIFO |
102 | */ | 137 | */ |
103 | void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) | 138 | static void bfin_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) |
104 | { | 139 | { |
105 | struct musb *musb = hw_ep->musb; | 140 | struct musb *musb = hw_ep->musb; |
106 | void __iomem *fifo = hw_ep->fifo; | 141 | void __iomem *fifo = hw_ep->fifo; |
@@ -185,8 +220,8 @@ static irqreturn_t blackfin_interrupt(int irq, void *__hci) | |||
185 | } | 220 | } |
186 | 221 | ||
187 | /* Start sampling ID pin, when plug is removed from MUSB */ | 222 | /* Start sampling ID pin, when plug is removed from MUSB */ |
188 | if ((musb->xceiv->state == OTG_STATE_B_IDLE | 223 | if ((musb->xceiv->otg->state == OTG_STATE_B_IDLE |
189 | || musb->xceiv->state == OTG_STATE_A_WAIT_BCON) || | 224 | || musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON) || |
190 | (musb->int_usb & MUSB_INTR_DISCONNECT && is_host_active(musb))) { | 225 | (musb->int_usb & MUSB_INTR_DISCONNECT && is_host_active(musb))) { |
191 | mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); | 226 | mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); |
192 | musb->a_wait_bcon = TIMER_DELAY; | 227 | musb->a_wait_bcon = TIMER_DELAY; |
@@ -205,7 +240,7 @@ static void musb_conn_timer_handler(unsigned long _musb) | |||
205 | static u8 toggle; | 240 | static u8 toggle; |
206 | 241 | ||
207 | spin_lock_irqsave(&musb->lock, flags); | 242 | spin_lock_irqsave(&musb->lock, flags); |
208 | switch (musb->xceiv->state) { | 243 | switch (musb->xceiv->otg->state) { |
209 | case OTG_STATE_A_IDLE: | 244 | case OTG_STATE_A_IDLE: |
210 | case OTG_STATE_A_WAIT_BCON: | 245 | case OTG_STATE_A_WAIT_BCON: |
211 | /* Start a new session */ | 246 | /* Start a new session */ |
@@ -219,7 +254,7 @@ static void musb_conn_timer_handler(unsigned long _musb) | |||
219 | 254 | ||
220 | if (!(val & MUSB_DEVCTL_BDEVICE)) { | 255 | if (!(val & MUSB_DEVCTL_BDEVICE)) { |
221 | gpio_set_value(musb->config->gpio_vrsel, 1); | 256 | gpio_set_value(musb->config->gpio_vrsel, 1); |
222 | musb->xceiv->state = OTG_STATE_A_WAIT_BCON; | 257 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; |
223 | } else { | 258 | } else { |
224 | gpio_set_value(musb->config->gpio_vrsel, 0); | 259 | gpio_set_value(musb->config->gpio_vrsel, 0); |
225 | /* Ignore VBUSERROR and SUSPEND IRQ */ | 260 | /* Ignore VBUSERROR and SUSPEND IRQ */ |
@@ -229,7 +264,7 @@ static void musb_conn_timer_handler(unsigned long _musb) | |||
229 | 264 | ||
230 | val = MUSB_INTR_SUSPEND | MUSB_INTR_VBUSERROR; | 265 | val = MUSB_INTR_SUSPEND | MUSB_INTR_VBUSERROR; |
231 | musb_writeb(musb->mregs, MUSB_INTRUSB, val); | 266 | musb_writeb(musb->mregs, MUSB_INTRUSB, val); |
232 | musb->xceiv->state = OTG_STATE_B_IDLE; | 267 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
233 | } | 268 | } |
234 | mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); | 269 | mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); |
235 | break; | 270 | break; |
@@ -245,7 +280,7 @@ static void musb_conn_timer_handler(unsigned long _musb) | |||
245 | 280 | ||
246 | if (!(val & MUSB_DEVCTL_BDEVICE)) { | 281 | if (!(val & MUSB_DEVCTL_BDEVICE)) { |
247 | gpio_set_value(musb->config->gpio_vrsel, 1); | 282 | gpio_set_value(musb->config->gpio_vrsel, 1); |
248 | musb->xceiv->state = OTG_STATE_A_WAIT_BCON; | 283 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; |
249 | } else { | 284 | } else { |
250 | gpio_set_value(musb->config->gpio_vrsel, 0); | 285 | gpio_set_value(musb->config->gpio_vrsel, 0); |
251 | 286 | ||
@@ -280,13 +315,13 @@ static void musb_conn_timer_handler(unsigned long _musb) | |||
280 | break; | 315 | break; |
281 | default: | 316 | default: |
282 | dev_dbg(musb->controller, "%s state not handled\n", | 317 | dev_dbg(musb->controller, "%s state not handled\n", |
283 | usb_otg_state_string(musb->xceiv->state)); | 318 | usb_otg_state_string(musb->xceiv->otg->state)); |
284 | break; | 319 | break; |
285 | } | 320 | } |
286 | spin_unlock_irqrestore(&musb->lock, flags); | 321 | spin_unlock_irqrestore(&musb->lock, flags); |
287 | 322 | ||
288 | dev_dbg(musb->controller, "state is %s\n", | 323 | dev_dbg(musb->controller, "state is %s\n", |
289 | usb_otg_state_string(musb->xceiv->state)); | 324 | usb_otg_state_string(musb->xceiv->otg->state)); |
290 | } | 325 | } |
291 | 326 | ||
292 | static void bfin_musb_enable(struct musb *musb) | 327 | static void bfin_musb_enable(struct musb *musb) |
@@ -307,7 +342,7 @@ static void bfin_musb_set_vbus(struct musb *musb, int is_on) | |||
307 | 342 | ||
308 | dev_dbg(musb->controller, "VBUS %s, devctl %02x " | 343 | dev_dbg(musb->controller, "VBUS %s, devctl %02x " |
309 | /* otg %3x conf %08x prcm %08x */ "\n", | 344 | /* otg %3x conf %08x prcm %08x */ "\n", |
310 | usb_otg_state_string(musb->xceiv->state), | 345 | usb_otg_state_string(musb->xceiv->otg->state), |
311 | musb_readb(musb->mregs, MUSB_DEVCTL)); | 346 | musb_readb(musb->mregs, MUSB_DEVCTL)); |
312 | } | 347 | } |
313 | 348 | ||
@@ -433,6 +468,15 @@ static const struct musb_platform_ops bfin_ops = { | |||
433 | .init = bfin_musb_init, | 468 | .init = bfin_musb_init, |
434 | .exit = bfin_musb_exit, | 469 | .exit = bfin_musb_exit, |
435 | 470 | ||
471 | .readb = bfin_readb, | ||
472 | .writeb = bfin_writeb, | ||
473 | .readw = bfin_readw, | ||
474 | .writew = bfin_writew, | ||
475 | .readl = bfin_readl, | ||
476 | .writel = bfin_writel, | ||
477 | .fifo_mode = 2, | ||
478 | .read_fifo = bfin_read_fifo, | ||
479 | .write_fifo = bfin_write_fifo, | ||
436 | .enable = bfin_musb_enable, | 480 | .enable = bfin_musb_enable, |
437 | .disable = bfin_musb_disable, | 481 | .disable = bfin_musb_disable, |
438 | 482 | ||
@@ -456,16 +500,12 @@ static int bfin_probe(struct platform_device *pdev) | |||
456 | int ret = -ENOMEM; | 500 | int ret = -ENOMEM; |
457 | 501 | ||
458 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); | 502 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
459 | if (!glue) { | 503 | if (!glue) |
460 | dev_err(&pdev->dev, "failed to allocate glue context\n"); | ||
461 | goto err0; | 504 | goto err0; |
462 | } | ||
463 | 505 | ||
464 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | 506 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); |
465 | if (!musb) { | 507 | if (!musb) |
466 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | ||
467 | goto err0; | 508 | goto err0; |
468 | } | ||
469 | 509 | ||
470 | musb->dev.parent = &pdev->dev; | 510 | musb->dev.parent = &pdev->dev; |
471 | musb->dev.dma_mask = &bfin_dmamask; | 511 | musb->dev.dma_mask = &bfin_dmamask; |
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c index 058775e647ad..9a9c82a4d35d 100644 --- a/drivers/usb/musb/da8xx.c +++ b/drivers/usb/musb/da8xx.c | |||
@@ -198,20 +198,20 @@ static void otg_timer(unsigned long _musb) | |||
198 | */ | 198 | */ |
199 | devctl = musb_readb(mregs, MUSB_DEVCTL); | 199 | devctl = musb_readb(mregs, MUSB_DEVCTL); |
200 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, | 200 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, |
201 | usb_otg_state_string(musb->xceiv->state)); | 201 | usb_otg_state_string(musb->xceiv->otg->state)); |
202 | 202 | ||
203 | spin_lock_irqsave(&musb->lock, flags); | 203 | spin_lock_irqsave(&musb->lock, flags); |
204 | switch (musb->xceiv->state) { | 204 | switch (musb->xceiv->otg->state) { |
205 | case OTG_STATE_A_WAIT_BCON: | 205 | case OTG_STATE_A_WAIT_BCON: |
206 | devctl &= ~MUSB_DEVCTL_SESSION; | 206 | devctl &= ~MUSB_DEVCTL_SESSION; |
207 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | 207 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
208 | 208 | ||
209 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 209 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
210 | if (devctl & MUSB_DEVCTL_BDEVICE) { | 210 | if (devctl & MUSB_DEVCTL_BDEVICE) { |
211 | musb->xceiv->state = OTG_STATE_B_IDLE; | 211 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
212 | MUSB_DEV_MODE(musb); | 212 | MUSB_DEV_MODE(musb); |
213 | } else { | 213 | } else { |
214 | musb->xceiv->state = OTG_STATE_A_IDLE; | 214 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
215 | MUSB_HST_MODE(musb); | 215 | MUSB_HST_MODE(musb); |
216 | } | 216 | } |
217 | break; | 217 | break; |
@@ -226,7 +226,7 @@ static void otg_timer(unsigned long _musb) | |||
226 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 226 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
227 | break; | 227 | break; |
228 | } | 228 | } |
229 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 229 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
230 | musb_writel(musb->ctrl_base, DA8XX_USB_INTR_SRC_SET_REG, | 230 | musb_writel(musb->ctrl_base, DA8XX_USB_INTR_SRC_SET_REG, |
231 | MUSB_INTR_VBUSERROR << DA8XX_INTR_USB_SHIFT); | 231 | MUSB_INTR_VBUSERROR << DA8XX_INTR_USB_SHIFT); |
232 | break; | 232 | break; |
@@ -248,7 +248,7 @@ static void otg_timer(unsigned long _musb) | |||
248 | if (devctl & MUSB_DEVCTL_BDEVICE) | 248 | if (devctl & MUSB_DEVCTL_BDEVICE) |
249 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 249 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
250 | else | 250 | else |
251 | musb->xceiv->state = OTG_STATE_A_IDLE; | 251 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
252 | break; | 252 | break; |
253 | default: | 253 | default: |
254 | break; | 254 | break; |
@@ -265,9 +265,9 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
265 | 265 | ||
266 | /* Never idle if active, or when VBUS timeout is not set as host */ | 266 | /* Never idle if active, or when VBUS timeout is not set as host */ |
267 | if (musb->is_active || (musb->a_wait_bcon == 0 && | 267 | if (musb->is_active || (musb->a_wait_bcon == 0 && |
268 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { | 268 | musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) { |
269 | dev_dbg(musb->controller, "%s active, deleting timer\n", | 269 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
270 | usb_otg_state_string(musb->xceiv->state)); | 270 | usb_otg_state_string(musb->xceiv->otg->state)); |
271 | del_timer(&otg_workaround); | 271 | del_timer(&otg_workaround); |
272 | last_timer = jiffies; | 272 | last_timer = jiffies; |
273 | return; | 273 | return; |
@@ -280,7 +280,7 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
280 | last_timer = timeout; | 280 | last_timer = timeout; |
281 | 281 | ||
282 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", | 282 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", |
283 | usb_otg_state_string(musb->xceiv->state), | 283 | usb_otg_state_string(musb->xceiv->otg->state), |
284 | jiffies_to_msecs(timeout - jiffies)); | 284 | jiffies_to_msecs(timeout - jiffies)); |
285 | mod_timer(&otg_workaround, timeout); | 285 | mod_timer(&otg_workaround, timeout); |
286 | } | 286 | } |
@@ -341,26 +341,26 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci) | |||
341 | * devctl. | 341 | * devctl. |
342 | */ | 342 | */ |
343 | musb->int_usb &= ~MUSB_INTR_VBUSERROR; | 343 | musb->int_usb &= ~MUSB_INTR_VBUSERROR; |
344 | musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; | 344 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; |
345 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 345 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
346 | WARNING("VBUS error workaround (delay coming)\n"); | 346 | WARNING("VBUS error workaround (delay coming)\n"); |
347 | } else if (drvvbus) { | 347 | } else if (drvvbus) { |
348 | MUSB_HST_MODE(musb); | 348 | MUSB_HST_MODE(musb); |
349 | otg->default_a = 1; | 349 | otg->default_a = 1; |
350 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 350 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
351 | portstate(musb->port1_status |= USB_PORT_STAT_POWER); | 351 | portstate(musb->port1_status |= USB_PORT_STAT_POWER); |
352 | del_timer(&otg_workaround); | 352 | del_timer(&otg_workaround); |
353 | } else { | 353 | } else { |
354 | musb->is_active = 0; | 354 | musb->is_active = 0; |
355 | MUSB_DEV_MODE(musb); | 355 | MUSB_DEV_MODE(musb); |
356 | otg->default_a = 0; | 356 | otg->default_a = 0; |
357 | musb->xceiv->state = OTG_STATE_B_IDLE; | 357 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
358 | portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); | 358 | portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); |
359 | } | 359 | } |
360 | 360 | ||
361 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", | 361 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", |
362 | drvvbus ? "on" : "off", | 362 | drvvbus ? "on" : "off", |
363 | usb_otg_state_string(musb->xceiv->state), | 363 | usb_otg_state_string(musb->xceiv->otg->state), |
364 | err ? " ERROR" : "", | 364 | err ? " ERROR" : "", |
365 | devctl); | 365 | devctl); |
366 | ret = IRQ_HANDLED; | 366 | ret = IRQ_HANDLED; |
@@ -375,7 +375,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci) | |||
375 | musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0); | 375 | musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0); |
376 | 376 | ||
377 | /* Poll for ID change */ | 377 | /* Poll for ID change */ |
378 | if (musb->xceiv->state == OTG_STATE_B_IDLE) | 378 | if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) |
379 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 379 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
380 | 380 | ||
381 | spin_unlock_irqrestore(&musb->lock, flags); | 381 | spin_unlock_irqrestore(&musb->lock, flags); |
@@ -458,9 +458,11 @@ static int da8xx_musb_exit(struct musb *musb) | |||
458 | } | 458 | } |
459 | 459 | ||
460 | static const struct musb_platform_ops da8xx_ops = { | 460 | static const struct musb_platform_ops da8xx_ops = { |
461 | .quirks = MUSB_INDEXED_EP, | ||
461 | .init = da8xx_musb_init, | 462 | .init = da8xx_musb_init, |
462 | .exit = da8xx_musb_exit, | 463 | .exit = da8xx_musb_exit, |
463 | 464 | ||
465 | .fifo_mode = 2, | ||
464 | .enable = da8xx_musb_enable, | 466 | .enable = da8xx_musb_enable, |
465 | .disable = da8xx_musb_disable, | 467 | .disable = da8xx_musb_disable, |
466 | 468 | ||
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c index 110b78415bf0..3c1d9b211b51 100644 --- a/drivers/usb/musb/davinci.c +++ b/drivers/usb/musb/davinci.c | |||
@@ -214,10 +214,10 @@ static void otg_timer(unsigned long _musb) | |||
214 | */ | 214 | */ |
215 | devctl = musb_readb(mregs, MUSB_DEVCTL); | 215 | devctl = musb_readb(mregs, MUSB_DEVCTL); |
216 | dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl, | 216 | dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl, |
217 | usb_otg_state_string(musb->xceiv->state)); | 217 | usb_otg_state_string(musb->xceiv->otg->state)); |
218 | 218 | ||
219 | spin_lock_irqsave(&musb->lock, flags); | 219 | spin_lock_irqsave(&musb->lock, flags); |
220 | switch (musb->xceiv->state) { | 220 | switch (musb->xceiv->otg->state) { |
221 | case OTG_STATE_A_WAIT_VFALL: | 221 | case OTG_STATE_A_WAIT_VFALL: |
222 | /* Wait till VBUS falls below SessionEnd (~0.2V); the 1.3 RTL | 222 | /* Wait till VBUS falls below SessionEnd (~0.2V); the 1.3 RTL |
223 | * seems to mis-handle session "start" otherwise (or in our | 223 | * seems to mis-handle session "start" otherwise (or in our |
@@ -228,7 +228,7 @@ static void otg_timer(unsigned long _musb) | |||
228 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 228 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
229 | break; | 229 | break; |
230 | } | 230 | } |
231 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 231 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
232 | musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG, | 232 | musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG, |
233 | MUSB_INTR_VBUSERROR << DAVINCI_USB_USBINT_SHIFT); | 233 | MUSB_INTR_VBUSERROR << DAVINCI_USB_USBINT_SHIFT); |
234 | break; | 234 | break; |
@@ -251,7 +251,7 @@ static void otg_timer(unsigned long _musb) | |||
251 | if (devctl & MUSB_DEVCTL_BDEVICE) | 251 | if (devctl & MUSB_DEVCTL_BDEVICE) |
252 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 252 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
253 | else | 253 | else |
254 | musb->xceiv->state = OTG_STATE_A_IDLE; | 254 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
255 | break; | 255 | break; |
256 | default: | 256 | default: |
257 | break; | 257 | break; |
@@ -325,20 +325,20 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci) | |||
325 | * to stop registering in devctl. | 325 | * to stop registering in devctl. |
326 | */ | 326 | */ |
327 | musb->int_usb &= ~MUSB_INTR_VBUSERROR; | 327 | musb->int_usb &= ~MUSB_INTR_VBUSERROR; |
328 | musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; | 328 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; |
329 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 329 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
330 | WARNING("VBUS error workaround (delay coming)\n"); | 330 | WARNING("VBUS error workaround (delay coming)\n"); |
331 | } else if (drvvbus) { | 331 | } else if (drvvbus) { |
332 | MUSB_HST_MODE(musb); | 332 | MUSB_HST_MODE(musb); |
333 | otg->default_a = 1; | 333 | otg->default_a = 1; |
334 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 334 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
335 | portstate(musb->port1_status |= USB_PORT_STAT_POWER); | 335 | portstate(musb->port1_status |= USB_PORT_STAT_POWER); |
336 | del_timer(&otg_workaround); | 336 | del_timer(&otg_workaround); |
337 | } else { | 337 | } else { |
338 | musb->is_active = 0; | 338 | musb->is_active = 0; |
339 | MUSB_DEV_MODE(musb); | 339 | MUSB_DEV_MODE(musb); |
340 | otg->default_a = 0; | 340 | otg->default_a = 0; |
341 | musb->xceiv->state = OTG_STATE_B_IDLE; | 341 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
342 | portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); | 342 | portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); |
343 | } | 343 | } |
344 | 344 | ||
@@ -348,7 +348,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci) | |||
348 | davinci_musb_source_power(musb, drvvbus, 0); | 348 | davinci_musb_source_power(musb, drvvbus, 0); |
349 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", | 349 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", |
350 | drvvbus ? "on" : "off", | 350 | drvvbus ? "on" : "off", |
351 | usb_otg_state_string(musb->xceiv->state), | 351 | usb_otg_state_string(musb->xceiv->otg->state), |
352 | err ? " ERROR" : "", | 352 | err ? " ERROR" : "", |
353 | devctl); | 353 | devctl); |
354 | retval = IRQ_HANDLED; | 354 | retval = IRQ_HANDLED; |
@@ -361,7 +361,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci) | |||
361 | musb_writel(tibase, DAVINCI_USB_EOI_REG, 0); | 361 | musb_writel(tibase, DAVINCI_USB_EOI_REG, 0); |
362 | 362 | ||
363 | /* poll for ID change */ | 363 | /* poll for ID change */ |
364 | if (musb->xceiv->state == OTG_STATE_B_IDLE) | 364 | if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) |
365 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); | 365 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
366 | 366 | ||
367 | spin_unlock_irqrestore(&musb->lock, flags); | 367 | spin_unlock_irqrestore(&musb->lock, flags); |
@@ -520,10 +520,8 @@ static int davinci_probe(struct platform_device *pdev) | |||
520 | int ret = -ENOMEM; | 520 | int ret = -ENOMEM; |
521 | 521 | ||
522 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); | 522 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
523 | if (!glue) { | 523 | if (!glue) |
524 | dev_err(&pdev->dev, "failed to allocate glue context\n"); | ||
525 | goto err0; | 524 | goto err0; |
526 | } | ||
527 | 525 | ||
528 | clk = devm_clk_get(&pdev->dev, "usb"); | 526 | clk = devm_clk_get(&pdev->dev, "usb"); |
529 | if (IS_ERR(clk)) { | 527 | if (IS_ERR(clk)) { |
diff --git a/drivers/usb/musb/jz4740.c b/drivers/usb/musb/jz4740.c index d1187290d4e3..bb7b26325a74 100644 --- a/drivers/usb/musb/jz4740.c +++ b/drivers/usb/musb/jz4740.c | |||
@@ -106,6 +106,8 @@ static int jz4740_musb_exit(struct musb *musb) | |||
106 | } | 106 | } |
107 | 107 | ||
108 | static const struct musb_platform_ops jz4740_musb_ops = { | 108 | static const struct musb_platform_ops jz4740_musb_ops = { |
109 | .quirks = MUSB_INDEXED_EP, | ||
110 | .fifo_mode = 2, | ||
109 | .init = jz4740_musb_init, | 111 | .init = jz4740_musb_init, |
110 | .exit = jz4740_musb_exit, | 112 | .exit = jz4740_musb_exit, |
111 | }; | 113 | }; |
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 55ebd4b1daac..55fe0ff6fd87 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c | |||
@@ -224,12 +224,67 @@ static struct usb_phy_io_ops musb_ulpi_access = { | |||
224 | 224 | ||
225 | /*-------------------------------------------------------------------------*/ | 225 | /*-------------------------------------------------------------------------*/ |
226 | 226 | ||
227 | #if !defined(CONFIG_USB_MUSB_TUSB6010) && !defined(CONFIG_USB_MUSB_BLACKFIN) | 227 | static u32 musb_default_fifo_offset(u8 epnum) |
228 | { | ||
229 | return 0x20 + (epnum * 4); | ||
230 | } | ||
231 | |||
232 | /* "flat" mapping: each endpoint has its own i/o address */ | ||
233 | static void musb_flat_ep_select(void __iomem *mbase, u8 epnum) | ||
234 | { | ||
235 | } | ||
236 | |||
237 | static u32 musb_flat_ep_offset(u8 epnum, u16 offset) | ||
238 | { | ||
239 | return 0x100 + (0x10 * epnum) + offset; | ||
240 | } | ||
241 | |||
242 | /* "indexed" mapping: INDEX register controls register bank select */ | ||
243 | static void musb_indexed_ep_select(void __iomem *mbase, u8 epnum) | ||
244 | { | ||
245 | musb_writeb(mbase, MUSB_INDEX, epnum); | ||
246 | } | ||
247 | |||
248 | static u32 musb_indexed_ep_offset(u8 epnum, u16 offset) | ||
249 | { | ||
250 | return 0x10 + offset; | ||
251 | } | ||
252 | |||
253 | static u8 musb_default_readb(const void __iomem *addr, unsigned offset) | ||
254 | { | ||
255 | return __raw_readb(addr + offset); | ||
256 | } | ||
257 | |||
258 | static void musb_default_writeb(void __iomem *addr, unsigned offset, u8 data) | ||
259 | { | ||
260 | __raw_writeb(data, addr + offset); | ||
261 | } | ||
262 | |||
263 | static u16 musb_default_readw(const void __iomem *addr, unsigned offset) | ||
264 | { | ||
265 | return __raw_readw(addr + offset); | ||
266 | } | ||
267 | |||
268 | static void musb_default_writew(void __iomem *addr, unsigned offset, u16 data) | ||
269 | { | ||
270 | __raw_writew(data, addr + offset); | ||
271 | } | ||
272 | |||
273 | static u32 musb_default_readl(const void __iomem *addr, unsigned offset) | ||
274 | { | ||
275 | return __raw_readl(addr + offset); | ||
276 | } | ||
277 | |||
278 | static void musb_default_writel(void __iomem *addr, unsigned offset, u32 data) | ||
279 | { | ||
280 | __raw_writel(data, addr + offset); | ||
281 | } | ||
228 | 282 | ||
229 | /* | 283 | /* |
230 | * Load an endpoint's FIFO | 284 | * Load an endpoint's FIFO |
231 | */ | 285 | */ |
232 | void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src) | 286 | static void musb_default_write_fifo(struct musb_hw_ep *hw_ep, u16 len, |
287 | const u8 *src) | ||
233 | { | 288 | { |
234 | struct musb *musb = hw_ep->musb; | 289 | struct musb *musb = hw_ep->musb; |
235 | void __iomem *fifo = hw_ep->fifo; | 290 | void __iomem *fifo = hw_ep->fifo; |
@@ -270,11 +325,10 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src) | |||
270 | } | 325 | } |
271 | } | 326 | } |
272 | 327 | ||
273 | #if !defined(CONFIG_USB_MUSB_AM35X) | ||
274 | /* | 328 | /* |
275 | * Unload an endpoint's FIFO | 329 | * Unload an endpoint's FIFO |
276 | */ | 330 | */ |
277 | void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) | 331 | static void musb_default_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) |
278 | { | 332 | { |
279 | struct musb *musb = hw_ep->musb; | 333 | struct musb *musb = hw_ep->musb; |
280 | void __iomem *fifo = hw_ep->fifo; | 334 | void __iomem *fifo = hw_ep->fifo; |
@@ -312,10 +366,40 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) | |||
312 | ioread8_rep(fifo, dst, len); | 366 | ioread8_rep(fifo, dst, len); |
313 | } | 367 | } |
314 | } | 368 | } |
315 | #endif | ||
316 | 369 | ||
317 | #endif /* normal PIO */ | 370 | /* |
371 | * Old style IO functions | ||
372 | */ | ||
373 | u8 (*musb_readb)(const void __iomem *addr, unsigned offset); | ||
374 | EXPORT_SYMBOL_GPL(musb_readb); | ||
375 | |||
376 | void (*musb_writeb)(void __iomem *addr, unsigned offset, u8 data); | ||
377 | EXPORT_SYMBOL_GPL(musb_writeb); | ||
378 | |||
379 | u16 (*musb_readw)(const void __iomem *addr, unsigned offset); | ||
380 | EXPORT_SYMBOL_GPL(musb_readw); | ||
381 | |||
382 | void (*musb_writew)(void __iomem *addr, unsigned offset, u16 data); | ||
383 | EXPORT_SYMBOL_GPL(musb_writew); | ||
318 | 384 | ||
385 | u32 (*musb_readl)(const void __iomem *addr, unsigned offset); | ||
386 | EXPORT_SYMBOL_GPL(musb_readl); | ||
387 | |||
388 | void (*musb_writel)(void __iomem *addr, unsigned offset, u32 data); | ||
389 | EXPORT_SYMBOL_GPL(musb_writel); | ||
390 | |||
391 | /* | ||
392 | * New style IO functions | ||
393 | */ | ||
394 | void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) | ||
395 | { | ||
396 | return hw_ep->musb->io.read_fifo(hw_ep, len, dst); | ||
397 | } | ||
398 | |||
399 | void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src) | ||
400 | { | ||
401 | return hw_ep->musb->io.write_fifo(hw_ep, len, src); | ||
402 | } | ||
319 | 403 | ||
320 | /*-------------------------------------------------------------------------*/ | 404 | /*-------------------------------------------------------------------------*/ |
321 | 405 | ||
@@ -360,23 +444,23 @@ static void musb_otg_timer_func(unsigned long data) | |||
360 | unsigned long flags; | 444 | unsigned long flags; |
361 | 445 | ||
362 | spin_lock_irqsave(&musb->lock, flags); | 446 | spin_lock_irqsave(&musb->lock, flags); |
363 | switch (musb->xceiv->state) { | 447 | switch (musb->xceiv->otg->state) { |
364 | case OTG_STATE_B_WAIT_ACON: | 448 | case OTG_STATE_B_WAIT_ACON: |
365 | dev_dbg(musb->controller, "HNP: b_wait_acon timeout; back to b_peripheral\n"); | 449 | dev_dbg(musb->controller, "HNP: b_wait_acon timeout; back to b_peripheral\n"); |
366 | musb_g_disconnect(musb); | 450 | musb_g_disconnect(musb); |
367 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 451 | musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; |
368 | musb->is_active = 0; | 452 | musb->is_active = 0; |
369 | break; | 453 | break; |
370 | case OTG_STATE_A_SUSPEND: | 454 | case OTG_STATE_A_SUSPEND: |
371 | case OTG_STATE_A_WAIT_BCON: | 455 | case OTG_STATE_A_WAIT_BCON: |
372 | dev_dbg(musb->controller, "HNP: %s timeout\n", | 456 | dev_dbg(musb->controller, "HNP: %s timeout\n", |
373 | usb_otg_state_string(musb->xceiv->state)); | 457 | usb_otg_state_string(musb->xceiv->otg->state)); |
374 | musb_platform_set_vbus(musb, 0); | 458 | musb_platform_set_vbus(musb, 0); |
375 | musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; | 459 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; |
376 | break; | 460 | break; |
377 | default: | 461 | default: |
378 | dev_dbg(musb->controller, "HNP: Unhandled mode %s\n", | 462 | dev_dbg(musb->controller, "HNP: Unhandled mode %s\n", |
379 | usb_otg_state_string(musb->xceiv->state)); | 463 | usb_otg_state_string(musb->xceiv->otg->state)); |
380 | } | 464 | } |
381 | spin_unlock_irqrestore(&musb->lock, flags); | 465 | spin_unlock_irqrestore(&musb->lock, flags); |
382 | } | 466 | } |
@@ -391,19 +475,19 @@ void musb_hnp_stop(struct musb *musb) | |||
391 | u8 reg; | 475 | u8 reg; |
392 | 476 | ||
393 | dev_dbg(musb->controller, "HNP: stop from %s\n", | 477 | dev_dbg(musb->controller, "HNP: stop from %s\n", |
394 | usb_otg_state_string(musb->xceiv->state)); | 478 | usb_otg_state_string(musb->xceiv->otg->state)); |
395 | 479 | ||
396 | switch (musb->xceiv->state) { | 480 | switch (musb->xceiv->otg->state) { |
397 | case OTG_STATE_A_PERIPHERAL: | 481 | case OTG_STATE_A_PERIPHERAL: |
398 | musb_g_disconnect(musb); | 482 | musb_g_disconnect(musb); |
399 | dev_dbg(musb->controller, "HNP: back to %s\n", | 483 | dev_dbg(musb->controller, "HNP: back to %s\n", |
400 | usb_otg_state_string(musb->xceiv->state)); | 484 | usb_otg_state_string(musb->xceiv->otg->state)); |
401 | break; | 485 | break; |
402 | case OTG_STATE_B_HOST: | 486 | case OTG_STATE_B_HOST: |
403 | dev_dbg(musb->controller, "HNP: Disabling HR\n"); | 487 | dev_dbg(musb->controller, "HNP: Disabling HR\n"); |
404 | if (hcd) | 488 | if (hcd) |
405 | hcd->self.is_b_host = 0; | 489 | hcd->self.is_b_host = 0; |
406 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 490 | musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; |
407 | MUSB_DEV_MODE(musb); | 491 | MUSB_DEV_MODE(musb); |
408 | reg = musb_readb(mbase, MUSB_POWER); | 492 | reg = musb_readb(mbase, MUSB_POWER); |
409 | reg |= MUSB_POWER_SUSPENDM; | 493 | reg |= MUSB_POWER_SUSPENDM; |
@@ -412,7 +496,7 @@ void musb_hnp_stop(struct musb *musb) | |||
412 | break; | 496 | break; |
413 | default: | 497 | default: |
414 | dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n", | 498 | dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n", |
415 | usb_otg_state_string(musb->xceiv->state)); | 499 | usb_otg_state_string(musb->xceiv->otg->state)); |
416 | } | 500 | } |
417 | 501 | ||
418 | /* | 502 | /* |
@@ -423,6 +507,7 @@ void musb_hnp_stop(struct musb *musb) | |||
423 | musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16); | 507 | musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16); |
424 | } | 508 | } |
425 | 509 | ||
510 | static void musb_generic_disable(struct musb *musb); | ||
426 | /* | 511 | /* |
427 | * Interrupt Service Routine to record USB "global" interrupts. | 512 | * Interrupt Service Routine to record USB "global" interrupts. |
428 | * Since these do not happen often and signify things of | 513 | * Since these do not happen often and signify things of |
@@ -449,13 +534,13 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
449 | */ | 534 | */ |
450 | if (int_usb & MUSB_INTR_RESUME) { | 535 | if (int_usb & MUSB_INTR_RESUME) { |
451 | handled = IRQ_HANDLED; | 536 | handled = IRQ_HANDLED; |
452 | dev_dbg(musb->controller, "RESUME (%s)\n", usb_otg_state_string(musb->xceiv->state)); | 537 | dev_dbg(musb->controller, "RESUME (%s)\n", usb_otg_state_string(musb->xceiv->otg->state)); |
453 | 538 | ||
454 | if (devctl & MUSB_DEVCTL_HM) { | 539 | if (devctl & MUSB_DEVCTL_HM) { |
455 | void __iomem *mbase = musb->mregs; | 540 | void __iomem *mbase = musb->mregs; |
456 | u8 power; | 541 | u8 power; |
457 | 542 | ||
458 | switch (musb->xceiv->state) { | 543 | switch (musb->xceiv->otg->state) { |
459 | case OTG_STATE_A_SUSPEND: | 544 | case OTG_STATE_A_SUSPEND: |
460 | /* remote wakeup? later, GetPortStatus | 545 | /* remote wakeup? later, GetPortStatus |
461 | * will stop RESUME signaling | 546 | * will stop RESUME signaling |
@@ -478,29 +563,26 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
478 | | MUSB_PORT_STAT_RESUME; | 563 | | MUSB_PORT_STAT_RESUME; |
479 | musb->rh_timer = jiffies | 564 | musb->rh_timer = jiffies |
480 | + msecs_to_jiffies(20); | 565 | + msecs_to_jiffies(20); |
481 | schedule_delayed_work( | 566 | musb->need_finish_resume = 1; |
482 | &musb->finish_resume_work, | ||
483 | msecs_to_jiffies(20)); | ||
484 | 567 | ||
485 | musb->xceiv->state = OTG_STATE_A_HOST; | 568 | musb->xceiv->otg->state = OTG_STATE_A_HOST; |
486 | musb->is_active = 1; | 569 | musb->is_active = 1; |
487 | musb_host_resume_root_hub(musb); | ||
488 | break; | 570 | break; |
489 | case OTG_STATE_B_WAIT_ACON: | 571 | case OTG_STATE_B_WAIT_ACON: |
490 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 572 | musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; |
491 | musb->is_active = 1; | 573 | musb->is_active = 1; |
492 | MUSB_DEV_MODE(musb); | 574 | MUSB_DEV_MODE(musb); |
493 | break; | 575 | break; |
494 | default: | 576 | default: |
495 | WARNING("bogus %s RESUME (%s)\n", | 577 | WARNING("bogus %s RESUME (%s)\n", |
496 | "host", | 578 | "host", |
497 | usb_otg_state_string(musb->xceiv->state)); | 579 | usb_otg_state_string(musb->xceiv->otg->state)); |
498 | } | 580 | } |
499 | } else { | 581 | } else { |
500 | switch (musb->xceiv->state) { | 582 | switch (musb->xceiv->otg->state) { |
501 | case OTG_STATE_A_SUSPEND: | 583 | case OTG_STATE_A_SUSPEND: |
502 | /* possibly DISCONNECT is upcoming */ | 584 | /* possibly DISCONNECT is upcoming */ |
503 | musb->xceiv->state = OTG_STATE_A_HOST; | 585 | musb->xceiv->otg->state = OTG_STATE_A_HOST; |
504 | musb_host_resume_root_hub(musb); | 586 | musb_host_resume_root_hub(musb); |
505 | break; | 587 | break; |
506 | case OTG_STATE_B_WAIT_ACON: | 588 | case OTG_STATE_B_WAIT_ACON: |
@@ -523,7 +605,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
523 | default: | 605 | default: |
524 | WARNING("bogus %s RESUME (%s)\n", | 606 | WARNING("bogus %s RESUME (%s)\n", |
525 | "peripheral", | 607 | "peripheral", |
526 | usb_otg_state_string(musb->xceiv->state)); | 608 | usb_otg_state_string(musb->xceiv->otg->state)); |
527 | } | 609 | } |
528 | } | 610 | } |
529 | } | 611 | } |
@@ -539,7 +621,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
539 | } | 621 | } |
540 | 622 | ||
541 | dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n", | 623 | dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n", |
542 | usb_otg_state_string(musb->xceiv->state)); | 624 | usb_otg_state_string(musb->xceiv->otg->state)); |
543 | 625 | ||
544 | /* IRQ arrives from ID pin sense or (later, if VBUS power | 626 | /* IRQ arrives from ID pin sense or (later, if VBUS power |
545 | * is removed) SRP. responses are time critical: | 627 | * is removed) SRP. responses are time critical: |
@@ -550,7 +632,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
550 | */ | 632 | */ |
551 | musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION); | 633 | musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION); |
552 | musb->ep0_stage = MUSB_EP0_START; | 634 | musb->ep0_stage = MUSB_EP0_START; |
553 | musb->xceiv->state = OTG_STATE_A_IDLE; | 635 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
554 | MUSB_HST_MODE(musb); | 636 | MUSB_HST_MODE(musb); |
555 | musb_platform_set_vbus(musb, 1); | 637 | musb_platform_set_vbus(musb, 1); |
556 | 638 | ||
@@ -576,7 +658,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
576 | * REVISIT: do delays from lots of DEBUG_KERNEL checks | 658 | * REVISIT: do delays from lots of DEBUG_KERNEL checks |
577 | * make trouble here, keeping VBUS < 4.4V ? | 659 | * make trouble here, keeping VBUS < 4.4V ? |
578 | */ | 660 | */ |
579 | switch (musb->xceiv->state) { | 661 | switch (musb->xceiv->otg->state) { |
580 | case OTG_STATE_A_HOST: | 662 | case OTG_STATE_A_HOST: |
581 | /* recovery is dicey once we've gotten past the | 663 | /* recovery is dicey once we've gotten past the |
582 | * initial stages of enumeration, but if VBUS | 664 | * initial stages of enumeration, but if VBUS |
@@ -605,7 +687,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
605 | 687 | ||
606 | dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller, | 688 | dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller, |
607 | "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n", | 689 | "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n", |
608 | usb_otg_state_string(musb->xceiv->state), | 690 | usb_otg_state_string(musb->xceiv->otg->state), |
609 | devctl, | 691 | devctl, |
610 | ({ char *s; | 692 | ({ char *s; |
611 | switch (devctl & MUSB_DEVCTL_VBUS) { | 693 | switch (devctl & MUSB_DEVCTL_VBUS) { |
@@ -630,10 +712,10 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
630 | 712 | ||
631 | if (int_usb & MUSB_INTR_SUSPEND) { | 713 | if (int_usb & MUSB_INTR_SUSPEND) { |
632 | dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x\n", | 714 | dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x\n", |
633 | usb_otg_state_string(musb->xceiv->state), devctl); | 715 | usb_otg_state_string(musb->xceiv->otg->state), devctl); |
634 | handled = IRQ_HANDLED; | 716 | handled = IRQ_HANDLED; |
635 | 717 | ||
636 | switch (musb->xceiv->state) { | 718 | switch (musb->xceiv->otg->state) { |
637 | case OTG_STATE_A_PERIPHERAL: | 719 | case OTG_STATE_A_PERIPHERAL: |
638 | /* We also come here if the cable is removed, since | 720 | /* We also come here if the cable is removed, since |
639 | * this silicon doesn't report ID-no-longer-grounded. | 721 | * this silicon doesn't report ID-no-longer-grounded. |
@@ -657,7 +739,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
657 | musb_g_suspend(musb); | 739 | musb_g_suspend(musb); |
658 | musb->is_active = musb->g.b_hnp_enable; | 740 | musb->is_active = musb->g.b_hnp_enable; |
659 | if (musb->is_active) { | 741 | if (musb->is_active) { |
660 | musb->xceiv->state = OTG_STATE_B_WAIT_ACON; | 742 | musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON; |
661 | dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n"); | 743 | dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n"); |
662 | mod_timer(&musb->otg_timer, jiffies | 744 | mod_timer(&musb->otg_timer, jiffies |
663 | + msecs_to_jiffies( | 745 | + msecs_to_jiffies( |
@@ -670,7 +752,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
670 | + msecs_to_jiffies(musb->a_wait_bcon)); | 752 | + msecs_to_jiffies(musb->a_wait_bcon)); |
671 | break; | 753 | break; |
672 | case OTG_STATE_A_HOST: | 754 | case OTG_STATE_A_HOST: |
673 | musb->xceiv->state = OTG_STATE_A_SUSPEND; | 755 | musb->xceiv->otg->state = OTG_STATE_A_SUSPEND; |
674 | musb->is_active = musb->hcd->self.b_hnp_enable; | 756 | musb->is_active = musb->hcd->self.b_hnp_enable; |
675 | break; | 757 | break; |
676 | case OTG_STATE_B_HOST: | 758 | case OTG_STATE_B_HOST: |
@@ -713,7 +795,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
713 | musb->port1_status |= USB_PORT_STAT_LOW_SPEED; | 795 | musb->port1_status |= USB_PORT_STAT_LOW_SPEED; |
714 | 796 | ||
715 | /* indicate new connection to OTG machine */ | 797 | /* indicate new connection to OTG machine */ |
716 | switch (musb->xceiv->state) { | 798 | switch (musb->xceiv->otg->state) { |
717 | case OTG_STATE_B_PERIPHERAL: | 799 | case OTG_STATE_B_PERIPHERAL: |
718 | if (int_usb & MUSB_INTR_SUSPEND) { | 800 | if (int_usb & MUSB_INTR_SUSPEND) { |
719 | dev_dbg(musb->controller, "HNP: SUSPEND+CONNECT, now b_host\n"); | 801 | dev_dbg(musb->controller, "HNP: SUSPEND+CONNECT, now b_host\n"); |
@@ -725,7 +807,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
725 | case OTG_STATE_B_WAIT_ACON: | 807 | case OTG_STATE_B_WAIT_ACON: |
726 | dev_dbg(musb->controller, "HNP: CONNECT, now b_host\n"); | 808 | dev_dbg(musb->controller, "HNP: CONNECT, now b_host\n"); |
727 | b_host: | 809 | b_host: |
728 | musb->xceiv->state = OTG_STATE_B_HOST; | 810 | musb->xceiv->otg->state = OTG_STATE_B_HOST; |
729 | if (musb->hcd) | 811 | if (musb->hcd) |
730 | musb->hcd->self.is_b_host = 1; | 812 | musb->hcd->self.is_b_host = 1; |
731 | del_timer(&musb->otg_timer); | 813 | del_timer(&musb->otg_timer); |
@@ -733,7 +815,7 @@ b_host: | |||
733 | default: | 815 | default: |
734 | if ((devctl & MUSB_DEVCTL_VBUS) | 816 | if ((devctl & MUSB_DEVCTL_VBUS) |
735 | == (3 << MUSB_DEVCTL_VBUS_SHIFT)) { | 817 | == (3 << MUSB_DEVCTL_VBUS_SHIFT)) { |
736 | musb->xceiv->state = OTG_STATE_A_HOST; | 818 | musb->xceiv->otg->state = OTG_STATE_A_HOST; |
737 | if (hcd) | 819 | if (hcd) |
738 | hcd->self.is_b_host = 0; | 820 | hcd->self.is_b_host = 0; |
739 | } | 821 | } |
@@ -743,16 +825,16 @@ b_host: | |||
743 | musb_host_poke_root_hub(musb); | 825 | musb_host_poke_root_hub(musb); |
744 | 826 | ||
745 | dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", | 827 | dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", |
746 | usb_otg_state_string(musb->xceiv->state), devctl); | 828 | usb_otg_state_string(musb->xceiv->otg->state), devctl); |
747 | } | 829 | } |
748 | 830 | ||
749 | if (int_usb & MUSB_INTR_DISCONNECT) { | 831 | if (int_usb & MUSB_INTR_DISCONNECT) { |
750 | dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", | 832 | dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", |
751 | usb_otg_state_string(musb->xceiv->state), | 833 | usb_otg_state_string(musb->xceiv->otg->state), |
752 | MUSB_MODE(musb), devctl); | 834 | MUSB_MODE(musb), devctl); |
753 | handled = IRQ_HANDLED; | 835 | handled = IRQ_HANDLED; |
754 | 836 | ||
755 | switch (musb->xceiv->state) { | 837 | switch (musb->xceiv->otg->state) { |
756 | case OTG_STATE_A_HOST: | 838 | case OTG_STATE_A_HOST: |
757 | case OTG_STATE_A_SUSPEND: | 839 | case OTG_STATE_A_SUSPEND: |
758 | musb_host_resume_root_hub(musb); | 840 | musb_host_resume_root_hub(musb); |
@@ -770,7 +852,7 @@ b_host: | |||
770 | musb_root_disconnect(musb); | 852 | musb_root_disconnect(musb); |
771 | if (musb->hcd) | 853 | if (musb->hcd) |
772 | musb->hcd->self.is_b_host = 0; | 854 | musb->hcd->self.is_b_host = 0; |
773 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 855 | musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; |
774 | MUSB_DEV_MODE(musb); | 856 | MUSB_DEV_MODE(musb); |
775 | musb_g_disconnect(musb); | 857 | musb_g_disconnect(musb); |
776 | break; | 858 | break; |
@@ -786,7 +868,7 @@ b_host: | |||
786 | break; | 868 | break; |
787 | default: | 869 | default: |
788 | WARNING("unhandled DISCONNECT transition (%s)\n", | 870 | WARNING("unhandled DISCONNECT transition (%s)\n", |
789 | usb_otg_state_string(musb->xceiv->state)); | 871 | usb_otg_state_string(musb->xceiv->otg->state)); |
790 | break; | 872 | break; |
791 | } | 873 | } |
792 | } | 874 | } |
@@ -812,15 +894,15 @@ b_host: | |||
812 | } | 894 | } |
813 | } else { | 895 | } else { |
814 | dev_dbg(musb->controller, "BUS RESET as %s\n", | 896 | dev_dbg(musb->controller, "BUS RESET as %s\n", |
815 | usb_otg_state_string(musb->xceiv->state)); | 897 | usb_otg_state_string(musb->xceiv->otg->state)); |
816 | switch (musb->xceiv->state) { | 898 | switch (musb->xceiv->otg->state) { |
817 | case OTG_STATE_A_SUSPEND: | 899 | case OTG_STATE_A_SUSPEND: |
818 | musb_g_reset(musb); | 900 | musb_g_reset(musb); |
819 | /* FALLTHROUGH */ | 901 | /* FALLTHROUGH */ |
820 | case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ | 902 | case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ |
821 | /* never use invalid T(a_wait_bcon) */ | 903 | /* never use invalid T(a_wait_bcon) */ |
822 | dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n", | 904 | dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n", |
823 | usb_otg_state_string(musb->xceiv->state), | 905 | usb_otg_state_string(musb->xceiv->otg->state), |
824 | TA_WAIT_BCON(musb)); | 906 | TA_WAIT_BCON(musb)); |
825 | mod_timer(&musb->otg_timer, jiffies | 907 | mod_timer(&musb->otg_timer, jiffies |
826 | + msecs_to_jiffies(TA_WAIT_BCON(musb))); | 908 | + msecs_to_jiffies(TA_WAIT_BCON(musb))); |
@@ -831,27 +913,29 @@ b_host: | |||
831 | break; | 913 | break; |
832 | case OTG_STATE_B_WAIT_ACON: | 914 | case OTG_STATE_B_WAIT_ACON: |
833 | dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n", | 915 | dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n", |
834 | usb_otg_state_string(musb->xceiv->state)); | 916 | usb_otg_state_string(musb->xceiv->otg->state)); |
835 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 917 | musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; |
836 | musb_g_reset(musb); | 918 | musb_g_reset(musb); |
837 | break; | 919 | break; |
838 | case OTG_STATE_B_IDLE: | 920 | case OTG_STATE_B_IDLE: |
839 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 921 | musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; |
840 | /* FALLTHROUGH */ | 922 | /* FALLTHROUGH */ |
841 | case OTG_STATE_B_PERIPHERAL: | 923 | case OTG_STATE_B_PERIPHERAL: |
842 | musb_g_reset(musb); | 924 | musb_g_reset(musb); |
843 | break; | 925 | break; |
844 | default: | 926 | default: |
845 | dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n", | 927 | dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n", |
846 | usb_otg_state_string(musb->xceiv->state)); | 928 | usb_otg_state_string(musb->xceiv->otg->state)); |
847 | } | 929 | } |
848 | } | 930 | } |
849 | } | 931 | } |
850 | 932 | ||
851 | /* handle babble condition */ | 933 | /* handle babble condition */ |
852 | if (int_usb & MUSB_INTR_BABBLE && is_host_active(musb)) | 934 | if (int_usb & MUSB_INTR_BABBLE && is_host_active(musb)) { |
935 | musb_generic_disable(musb); | ||
853 | schedule_delayed_work(&musb->recover_work, | 936 | schedule_delayed_work(&musb->recover_work, |
854 | msecs_to_jiffies(100)); | 937 | msecs_to_jiffies(100)); |
938 | } | ||
855 | 939 | ||
856 | #if 0 | 940 | #if 0 |
857 | /* REVISIT ... this would be for multiplexing periodic endpoints, or | 941 | /* REVISIT ... this would be for multiplexing periodic endpoints, or |
@@ -1032,21 +1116,7 @@ static void musb_shutdown(struct platform_device *pdev) | |||
1032 | * We don't currently use dynamic fifo setup capability to do anything | 1116 | * We don't currently use dynamic fifo setup capability to do anything |
1033 | * more than selecting one of a bunch of predefined configurations. | 1117 | * more than selecting one of a bunch of predefined configurations. |
1034 | */ | 1118 | */ |
1035 | #if defined(CONFIG_USB_MUSB_TUSB6010) \ | 1119 | static ushort fifo_mode; |
1036 | || defined(CONFIG_USB_MUSB_TUSB6010_MODULE) \ | ||
1037 | || defined(CONFIG_USB_MUSB_OMAP2PLUS) \ | ||
1038 | || defined(CONFIG_USB_MUSB_OMAP2PLUS_MODULE) \ | ||
1039 | || defined(CONFIG_USB_MUSB_AM35X) \ | ||
1040 | || defined(CONFIG_USB_MUSB_AM35X_MODULE) \ | ||
1041 | || defined(CONFIG_USB_MUSB_DSPS) \ | ||
1042 | || defined(CONFIG_USB_MUSB_DSPS_MODULE) | ||
1043 | static ushort fifo_mode = 4; | ||
1044 | #elif defined(CONFIG_USB_MUSB_UX500) \ | ||
1045 | || defined(CONFIG_USB_MUSB_UX500_MODULE) | ||
1046 | static ushort fifo_mode = 5; | ||
1047 | #else | ||
1048 | static ushort fifo_mode = 2; | ||
1049 | #endif | ||
1050 | 1120 | ||
1051 | /* "modprobe ... fifo_mode=1" etc */ | 1121 | /* "modprobe ... fifo_mode=1" etc */ |
1052 | module_param(fifo_mode, ushort, 0); | 1122 | module_param(fifo_mode, ushort, 0); |
@@ -1456,20 +1526,25 @@ static int musb_core_init(u16 musb_type, struct musb *musb) | |||
1456 | for (i = 0; i < musb->nr_endpoints; i++) { | 1526 | for (i = 0; i < musb->nr_endpoints; i++) { |
1457 | struct musb_hw_ep *hw_ep = musb->endpoints + i; | 1527 | struct musb_hw_ep *hw_ep = musb->endpoints + i; |
1458 | 1528 | ||
1459 | hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase; | 1529 | hw_ep->fifo = musb->io.fifo_offset(i) + mbase; |
1460 | #if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE) | 1530 | #if IS_ENABLED(CONFIG_USB_MUSB_TUSB6010) |
1461 | hw_ep->fifo_async = musb->async + 0x400 + MUSB_FIFO_OFFSET(i); | 1531 | if (musb->io.quirks & MUSB_IN_TUSB) { |
1462 | hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_FIFO_OFFSET(i); | 1532 | hw_ep->fifo_async = musb->async + 0x400 + |
1463 | hw_ep->fifo_sync_va = | 1533 | musb->io.fifo_offset(i); |
1464 | musb->sync_va + 0x400 + MUSB_FIFO_OFFSET(i); | 1534 | hw_ep->fifo_sync = musb->sync + 0x400 + |
1465 | 1535 | musb->io.fifo_offset(i); | |
1466 | if (i == 0) | 1536 | hw_ep->fifo_sync_va = |
1467 | hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF; | 1537 | musb->sync_va + 0x400 + musb->io.fifo_offset(i); |
1468 | else | 1538 | |
1469 | hw_ep->conf = mbase + 0x400 + (((i - 1) & 0xf) << 2); | 1539 | if (i == 0) |
1540 | hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF; | ||
1541 | else | ||
1542 | hw_ep->conf = mbase + 0x400 + | ||
1543 | (((i - 1) & 0xf) << 2); | ||
1544 | } | ||
1470 | #endif | 1545 | #endif |
1471 | 1546 | ||
1472 | hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase; | 1547 | hw_ep->regs = musb->io.ep_offset(i, 0) + mbase; |
1473 | hw_ep->target_regs = musb_read_target_reg_base(i, mbase); | 1548 | hw_ep->target_regs = musb_read_target_reg_base(i, mbase); |
1474 | hw_ep->rx_reinit = 1; | 1549 | hw_ep->rx_reinit = 1; |
1475 | hw_ep->tx_reinit = 1; | 1550 | hw_ep->tx_reinit = 1; |
@@ -1630,7 +1705,7 @@ musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf) | |||
1630 | int ret = -EINVAL; | 1705 | int ret = -EINVAL; |
1631 | 1706 | ||
1632 | spin_lock_irqsave(&musb->lock, flags); | 1707 | spin_lock_irqsave(&musb->lock, flags); |
1633 | ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->state)); | 1708 | ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->otg->state)); |
1634 | spin_unlock_irqrestore(&musb->lock, flags); | 1709 | spin_unlock_irqrestore(&musb->lock, flags); |
1635 | 1710 | ||
1636 | return ret; | 1711 | return ret; |
@@ -1675,7 +1750,7 @@ musb_vbus_store(struct device *dev, struct device_attribute *attr, | |||
1675 | spin_lock_irqsave(&musb->lock, flags); | 1750 | spin_lock_irqsave(&musb->lock, flags); |
1676 | /* force T(a_wait_bcon) to be zero/unlimited *OR* valid */ | 1751 | /* force T(a_wait_bcon) to be zero/unlimited *OR* valid */ |
1677 | musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ; | 1752 | musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ; |
1678 | if (musb->xceiv->state == OTG_STATE_A_WAIT_BCON) | 1753 | if (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON) |
1679 | musb->is_active = 0; | 1754 | musb->is_active = 0; |
1680 | musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val)); | 1755 | musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val)); |
1681 | spin_unlock_irqrestore(&musb->lock, flags); | 1756 | spin_unlock_irqrestore(&musb->lock, flags); |
@@ -1743,8 +1818,8 @@ static void musb_irq_work(struct work_struct *data) | |||
1743 | { | 1818 | { |
1744 | struct musb *musb = container_of(data, struct musb, irq_work); | 1819 | struct musb *musb = container_of(data, struct musb, irq_work); |
1745 | 1820 | ||
1746 | if (musb->xceiv->state != musb->xceiv_old_state) { | 1821 | if (musb->xceiv->otg->state != musb->xceiv_old_state) { |
1747 | musb->xceiv_old_state = musb->xceiv->state; | 1822 | musb->xceiv_old_state = musb->xceiv->otg->state; |
1748 | sysfs_notify(&musb->controller->kobj, NULL, "mode"); | 1823 | sysfs_notify(&musb->controller->kobj, NULL, "mode"); |
1749 | } | 1824 | } |
1750 | } | 1825 | } |
@@ -1903,6 +1978,18 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1903 | musb->ops = plat->platform_ops; | 1978 | musb->ops = plat->platform_ops; |
1904 | musb->port_mode = plat->mode; | 1979 | musb->port_mode = plat->mode; |
1905 | 1980 | ||
1981 | /* | ||
1982 | * Initialize the default IO functions. At least omap2430 needs | ||
1983 | * these early. We initialize the platform specific IO functions | ||
1984 | * later on. | ||
1985 | */ | ||
1986 | musb_readb = musb_default_readb; | ||
1987 | musb_writeb = musb_default_writeb; | ||
1988 | musb_readw = musb_default_readw; | ||
1989 | musb_writew = musb_default_writew; | ||
1990 | musb_readl = musb_default_readl; | ||
1991 | musb_writel = musb_default_writel; | ||
1992 | |||
1906 | /* The musb_platform_init() call: | 1993 | /* The musb_platform_init() call: |
1907 | * - adjusts musb->mregs | 1994 | * - adjusts musb->mregs |
1908 | * - sets the musb->isr | 1995 | * - sets the musb->isr |
@@ -1924,6 +2011,57 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1924 | goto fail2; | 2011 | goto fail2; |
1925 | } | 2012 | } |
1926 | 2013 | ||
2014 | if (musb->ops->quirks) | ||
2015 | musb->io.quirks = musb->ops->quirks; | ||
2016 | |||
2017 | /* At least tusb6010 has it's own offsets.. */ | ||
2018 | if (musb->ops->ep_offset) | ||
2019 | musb->io.ep_offset = musb->ops->ep_offset; | ||
2020 | if (musb->ops->ep_select) | ||
2021 | musb->io.ep_select = musb->ops->ep_select; | ||
2022 | |||
2023 | /* ..and some devices use indexed offset or flat offset */ | ||
2024 | if (musb->io.quirks & MUSB_INDEXED_EP) { | ||
2025 | musb->io.ep_offset = musb_indexed_ep_offset; | ||
2026 | musb->io.ep_select = musb_indexed_ep_select; | ||
2027 | } else { | ||
2028 | musb->io.ep_offset = musb_flat_ep_offset; | ||
2029 | musb->io.ep_select = musb_flat_ep_select; | ||
2030 | } | ||
2031 | |||
2032 | if (musb->ops->fifo_mode) | ||
2033 | fifo_mode = musb->ops->fifo_mode; | ||
2034 | else | ||
2035 | fifo_mode = 4; | ||
2036 | |||
2037 | if (musb->ops->fifo_offset) | ||
2038 | musb->io.fifo_offset = musb->ops->fifo_offset; | ||
2039 | else | ||
2040 | musb->io.fifo_offset = musb_default_fifo_offset; | ||
2041 | |||
2042 | if (musb->ops->readb) | ||
2043 | musb_readb = musb->ops->readb; | ||
2044 | if (musb->ops->writeb) | ||
2045 | musb_writeb = musb->ops->writeb; | ||
2046 | if (musb->ops->readw) | ||
2047 | musb_readw = musb->ops->readw; | ||
2048 | if (musb->ops->writew) | ||
2049 | musb_writew = musb->ops->writew; | ||
2050 | if (musb->ops->readl) | ||
2051 | musb_readl = musb->ops->readl; | ||
2052 | if (musb->ops->writel) | ||
2053 | musb_writel = musb->ops->writel; | ||
2054 | |||
2055 | if (musb->ops->read_fifo) | ||
2056 | musb->io.read_fifo = musb->ops->read_fifo; | ||
2057 | else | ||
2058 | musb->io.read_fifo = musb_default_read_fifo; | ||
2059 | |||
2060 | if (musb->ops->write_fifo) | ||
2061 | musb->io.write_fifo = musb->ops->write_fifo; | ||
2062 | else | ||
2063 | musb->io.write_fifo = musb_default_write_fifo; | ||
2064 | |||
1927 | if (!musb->xceiv->io_ops) { | 2065 | if (!musb->xceiv->io_ops) { |
1928 | musb->xceiv->io_dev = musb->controller; | 2066 | musb->xceiv->io_dev = musb->controller; |
1929 | musb->xceiv->io_priv = musb->mregs; | 2067 | musb->xceiv->io_priv = musb->mregs; |
@@ -1983,10 +2121,10 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1983 | 2121 | ||
1984 | if (musb->xceiv->otg->default_a) { | 2122 | if (musb->xceiv->otg->default_a) { |
1985 | MUSB_HST_MODE(musb); | 2123 | MUSB_HST_MODE(musb); |
1986 | musb->xceiv->state = OTG_STATE_A_IDLE; | 2124 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
1987 | } else { | 2125 | } else { |
1988 | MUSB_DEV_MODE(musb); | 2126 | MUSB_DEV_MODE(musb); |
1989 | musb->xceiv->state = OTG_STATE_B_IDLE; | 2127 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
1990 | } | 2128 | } |
1991 | 2129 | ||
1992 | switch (musb->port_mode) { | 2130 | switch (musb->port_mode) { |
@@ -2297,9 +2435,11 @@ static int musb_suspend(struct device *dev) | |||
2297 | return 0; | 2435 | return 0; |
2298 | } | 2436 | } |
2299 | 2437 | ||
2300 | static int musb_resume_noirq(struct device *dev) | 2438 | static int musb_resume(struct device *dev) |
2301 | { | 2439 | { |
2302 | struct musb *musb = dev_to_musb(dev); | 2440 | struct musb *musb = dev_to_musb(dev); |
2441 | u8 devctl; | ||
2442 | u8 mask; | ||
2303 | 2443 | ||
2304 | /* | 2444 | /* |
2305 | * For static cmos like DaVinci, register values were preserved | 2445 | * For static cmos like DaVinci, register values were preserved |
@@ -2313,6 +2453,23 @@ static int musb_resume_noirq(struct device *dev) | |||
2313 | 2453 | ||
2314 | musb_restore_context(musb); | 2454 | musb_restore_context(musb); |
2315 | 2455 | ||
2456 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | ||
2457 | mask = MUSB_DEVCTL_BDEVICE | MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV; | ||
2458 | if ((devctl & mask) != (musb->context.devctl & mask)) | ||
2459 | musb->port1_status = 0; | ||
2460 | if (musb->need_finish_resume) { | ||
2461 | musb->need_finish_resume = 0; | ||
2462 | schedule_delayed_work(&musb->finish_resume_work, | ||
2463 | msecs_to_jiffies(20)); | ||
2464 | } | ||
2465 | |||
2466 | /* | ||
2467 | * The USB HUB code expects the device to be in RPM_ACTIVE once it came | ||
2468 | * out of suspend | ||
2469 | */ | ||
2470 | pm_runtime_disable(dev); | ||
2471 | pm_runtime_set_active(dev); | ||
2472 | pm_runtime_enable(dev); | ||
2316 | return 0; | 2473 | return 0; |
2317 | } | 2474 | } |
2318 | 2475 | ||
@@ -2348,7 +2505,7 @@ static int musb_runtime_resume(struct device *dev) | |||
2348 | 2505 | ||
2349 | static const struct dev_pm_ops musb_dev_pm_ops = { | 2506 | static const struct dev_pm_ops musb_dev_pm_ops = { |
2350 | .suspend = musb_suspend, | 2507 | .suspend = musb_suspend, |
2351 | .resume_noirq = musb_resume_noirq, | 2508 | .resume = musb_resume, |
2352 | .runtime_suspend = musb_runtime_suspend, | 2509 | .runtime_suspend = musb_runtime_suspend, |
2353 | .runtime_resume = musb_runtime_resume, | 2510 | .runtime_resume = musb_runtime_resume, |
2354 | }; | 2511 | }; |
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index 414e57a984bb..5e65958f7915 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h | |||
@@ -124,41 +124,6 @@ enum musb_g_ep0_state { | |||
124 | #define OTG_TIME_A_AIDL_BDIS 200 /* min 200 msec */ | 124 | #define OTG_TIME_A_AIDL_BDIS 200 /* min 200 msec */ |
125 | #define OTG_TIME_B_ASE0_BRST 100 /* min 3.125 ms */ | 125 | #define OTG_TIME_B_ASE0_BRST 100 /* min 3.125 ms */ |
126 | 126 | ||
127 | |||
128 | /*************************** REGISTER ACCESS ********************************/ | ||
129 | |||
130 | /* Endpoint registers (other than dynfifo setup) can be accessed either | ||
131 | * directly with the "flat" model, or after setting up an index register. | ||
132 | */ | ||
133 | |||
134 | #if defined(CONFIG_ARCH_DAVINCI) || defined(CONFIG_SOC_OMAP2430) \ | ||
135 | || defined(CONFIG_SOC_OMAP3430) || defined(CONFIG_BLACKFIN) \ | ||
136 | || defined(CONFIG_ARCH_OMAP4) | ||
137 | /* REVISIT indexed access seemed to | ||
138 | * misbehave (on DaVinci) for at least peripheral IN ... | ||
139 | */ | ||
140 | #define MUSB_FLAT_REG | ||
141 | #endif | ||
142 | |||
143 | /* TUSB mapping: "flat" plus ep0 special cases */ | ||
144 | #if defined(CONFIG_USB_MUSB_TUSB6010) || \ | ||
145 | defined(CONFIG_USB_MUSB_TUSB6010_MODULE) | ||
146 | #define musb_ep_select(_mbase, _epnum) \ | ||
147 | musb_writeb((_mbase), MUSB_INDEX, (_epnum)) | ||
148 | #define MUSB_EP_OFFSET MUSB_TUSB_OFFSET | ||
149 | |||
150 | /* "flat" mapping: each endpoint has its own i/o address */ | ||
151 | #elif defined(MUSB_FLAT_REG) | ||
152 | #define musb_ep_select(_mbase, _epnum) (((void)(_mbase)), ((void)(_epnum))) | ||
153 | #define MUSB_EP_OFFSET MUSB_FLAT_OFFSET | ||
154 | |||
155 | /* "indexed" mapping: INDEX register controls register bank select */ | ||
156 | #else | ||
157 | #define musb_ep_select(_mbase, _epnum) \ | ||
158 | musb_writeb((_mbase), MUSB_INDEX, (_epnum)) | ||
159 | #define MUSB_EP_OFFSET MUSB_INDEXED_OFFSET | ||
160 | #endif | ||
161 | |||
162 | /****************************** FUNCTIONS ********************************/ | 127 | /****************************** FUNCTIONS ********************************/ |
163 | 128 | ||
164 | #define MUSB_HST_MODE(_musb)\ | 129 | #define MUSB_HST_MODE(_musb)\ |
@@ -173,8 +138,25 @@ enum musb_g_ep0_state { | |||
173 | 138 | ||
174 | /******************************** TYPES *************************************/ | 139 | /******************************** TYPES *************************************/ |
175 | 140 | ||
141 | struct musb_io; | ||
142 | |||
176 | /** | 143 | /** |
177 | * struct musb_platform_ops - Operations passed to musb_core by HW glue layer | 144 | * struct musb_platform_ops - Operations passed to musb_core by HW glue layer |
145 | * @quirks: flags for platform specific quirks | ||
146 | * @enable: enable device | ||
147 | * @disable: disable device | ||
148 | * @ep_offset: returns the end point offset | ||
149 | * @ep_select: selects the specified end point | ||
150 | * @fifo_mode: sets the fifo mode | ||
151 | * @fifo_offset: returns the fifo offset | ||
152 | * @readb: read 8 bits | ||
153 | * @writeb: write 8 bits | ||
154 | * @readw: read 16 bits | ||
155 | * @writew: write 16 bits | ||
156 | * @readl: read 32 bits | ||
157 | * @writel: write 32 bits | ||
158 | * @read_fifo: reads the fifo | ||
159 | * @write_fifo: writes to fifo | ||
178 | * @init: turns on clocks, sets up platform-specific registers, etc | 160 | * @init: turns on clocks, sets up platform-specific registers, etc |
179 | * @exit: undoes @init | 161 | * @exit: undoes @init |
180 | * @set_mode: forcefully changes operating mode | 162 | * @set_mode: forcefully changes operating mode |
@@ -184,12 +166,34 @@ enum musb_g_ep0_state { | |||
184 | * @adjust_channel_params: pre check for standard dma channel_program func | 166 | * @adjust_channel_params: pre check for standard dma channel_program func |
185 | */ | 167 | */ |
186 | struct musb_platform_ops { | 168 | struct musb_platform_ops { |
169 | |||
170 | #define MUSB_DMA_UX500 BIT(6) | ||
171 | #define MUSB_DMA_CPPI41 BIT(5) | ||
172 | #define MUSB_DMA_CPPI BIT(4) | ||
173 | #define MUSB_DMA_TUSB_OMAP BIT(3) | ||
174 | #define MUSB_DMA_INVENTRA BIT(2) | ||
175 | #define MUSB_IN_TUSB BIT(1) | ||
176 | #define MUSB_INDEXED_EP BIT(0) | ||
177 | u32 quirks; | ||
178 | |||
187 | int (*init)(struct musb *musb); | 179 | int (*init)(struct musb *musb); |
188 | int (*exit)(struct musb *musb); | 180 | int (*exit)(struct musb *musb); |
189 | 181 | ||
190 | void (*enable)(struct musb *musb); | 182 | void (*enable)(struct musb *musb); |
191 | void (*disable)(struct musb *musb); | 183 | void (*disable)(struct musb *musb); |
192 | 184 | ||
185 | u32 (*ep_offset)(u8 epnum, u16 offset); | ||
186 | void (*ep_select)(void __iomem *mbase, u8 epnum); | ||
187 | u16 fifo_mode; | ||
188 | u32 (*fifo_offset)(u8 epnum); | ||
189 | u8 (*readb)(const void __iomem *addr, unsigned offset); | ||
190 | void (*writeb)(void __iomem *addr, unsigned offset, u8 data); | ||
191 | u16 (*readw)(const void __iomem *addr, unsigned offset); | ||
192 | void (*writew)(void __iomem *addr, unsigned offset, u16 data); | ||
193 | u32 (*readl)(const void __iomem *addr, unsigned offset); | ||
194 | void (*writel)(void __iomem *addr, unsigned offset, u32 data); | ||
195 | void (*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf); | ||
196 | void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf); | ||
193 | int (*set_mode)(struct musb *musb, u8 mode); | 197 | int (*set_mode)(struct musb *musb, u8 mode); |
194 | void (*try_idle)(struct musb *musb, unsigned long timeout); | 198 | void (*try_idle)(struct musb *musb, unsigned long timeout); |
195 | int (*reset)(struct musb *musb); | 199 | int (*reset)(struct musb *musb); |
@@ -212,8 +216,7 @@ struct musb_hw_ep { | |||
212 | void __iomem *fifo; | 216 | void __iomem *fifo; |
213 | void __iomem *regs; | 217 | void __iomem *regs; |
214 | 218 | ||
215 | #if defined(CONFIG_USB_MUSB_TUSB6010) || \ | 219 | #if IS_ENABLED(CONFIG_USB_MUSB_TUSB6010) |
216 | defined(CONFIG_USB_MUSB_TUSB6010_MODULE) | ||
217 | void __iomem *conf; | 220 | void __iomem *conf; |
218 | #endif | 221 | #endif |
219 | 222 | ||
@@ -230,8 +233,7 @@ struct musb_hw_ep { | |||
230 | struct dma_channel *tx_channel; | 233 | struct dma_channel *tx_channel; |
231 | struct dma_channel *rx_channel; | 234 | struct dma_channel *rx_channel; |
232 | 235 | ||
233 | #if defined(CONFIG_USB_MUSB_TUSB6010) || \ | 236 | #if IS_ENABLED(CONFIG_USB_MUSB_TUSB6010) |
234 | defined(CONFIG_USB_MUSB_TUSB6010_MODULE) | ||
235 | /* TUSB has "asynchronous" and "synchronous" dma modes */ | 237 | /* TUSB has "asynchronous" and "synchronous" dma modes */ |
236 | dma_addr_t fifo_async; | 238 | dma_addr_t fifo_async; |
237 | dma_addr_t fifo_sync; | 239 | dma_addr_t fifo_sync; |
@@ -292,6 +294,7 @@ struct musb { | |||
292 | /* device lock */ | 294 | /* device lock */ |
293 | spinlock_t lock; | 295 | spinlock_t lock; |
294 | 296 | ||
297 | struct musb_io io; | ||
295 | const struct musb_platform_ops *ops; | 298 | const struct musb_platform_ops *ops; |
296 | struct musb_context_registers context; | 299 | struct musb_context_registers context; |
297 | 300 | ||
@@ -334,8 +337,7 @@ struct musb { | |||
334 | void __iomem *ctrl_base; | 337 | void __iomem *ctrl_base; |
335 | void __iomem *mregs; | 338 | void __iomem *mregs; |
336 | 339 | ||
337 | #if defined(CONFIG_USB_MUSB_TUSB6010) || \ | 340 | #if IS_ENABLED(CONFIG_USB_MUSB_TUSB6010) |
338 | defined(CONFIG_USB_MUSB_TUSB6010_MODULE) | ||
339 | dma_addr_t async; | 341 | dma_addr_t async; |
340 | dma_addr_t sync; | 342 | dma_addr_t sync; |
341 | void __iomem *sync_va; | 343 | void __iomem *sync_va; |
@@ -390,6 +392,7 @@ struct musb { | |||
390 | 392 | ||
391 | /* is_suspended means USB B_PERIPHERAL suspend */ | 393 | /* is_suspended means USB B_PERIPHERAL suspend */ |
392 | unsigned is_suspended:1; | 394 | unsigned is_suspended:1; |
395 | unsigned need_finish_resume :1; | ||
393 | 396 | ||
394 | /* may_wakeup means remote wakeup is enabled */ | 397 | /* may_wakeup means remote wakeup is enabled */ |
395 | unsigned may_wakeup:1; | 398 | unsigned may_wakeup:1; |
@@ -474,7 +477,7 @@ static inline int musb_read_fifosize(struct musb *musb, | |||
474 | u8 reg = 0; | 477 | u8 reg = 0; |
475 | 478 | ||
476 | /* read from core using indexed model */ | 479 | /* read from core using indexed model */ |
477 | reg = musb_readb(mbase, MUSB_EP_OFFSET(epnum, MUSB_FIFOSIZE)); | 480 | reg = musb_readb(mbase, musb->io.ep_offset(epnum, MUSB_FIFOSIZE)); |
478 | /* 0's returned when no more endpoints */ | 481 | /* 0's returned when no more endpoints */ |
479 | if (!reg) | 482 | if (!reg) |
480 | return -ENODEV; | 483 | return -ENODEV; |
diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c index 5a9b977fbc19..f64fd964dc6d 100644 --- a/drivers/usb/musb/musb_cppi41.c +++ b/drivers/usb/musb/musb_cppi41.c | |||
@@ -253,6 +253,7 @@ static void cppi41_dma_callback(void *private_data) | |||
253 | cppi41_trans_done(cppi41_channel); | 253 | cppi41_trans_done(cppi41_channel); |
254 | } else { | 254 | } else { |
255 | struct cppi41_dma_controller *controller; | 255 | struct cppi41_dma_controller *controller; |
256 | int is_hs = 0; | ||
256 | /* | 257 | /* |
257 | * On AM335x it has been observed that the TX interrupt fires | 258 | * On AM335x it has been observed that the TX interrupt fires |
258 | * too early that means the TXFIFO is not yet empty but the DMA | 259 | * too early that means the TXFIFO is not yet empty but the DMA |
@@ -265,7 +266,14 @@ static void cppi41_dma_callback(void *private_data) | |||
265 | */ | 266 | */ |
266 | controller = cppi41_channel->controller; | 267 | controller = cppi41_channel->controller; |
267 | 268 | ||
268 | if (musb->g.speed == USB_SPEED_HIGH) { | 269 | if (is_host_active(musb)) { |
270 | if (musb->port1_status & USB_PORT_STAT_HIGH_SPEED) | ||
271 | is_hs = 1; | ||
272 | } else { | ||
273 | if (musb->g.speed == USB_SPEED_HIGH) | ||
274 | is_hs = 1; | ||
275 | } | ||
276 | if (is_hs) { | ||
269 | unsigned wait = 25; | 277 | unsigned wait = 25; |
270 | 278 | ||
271 | do { | 279 | do { |
diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c index 4c216790e86b..ad3701a97389 100644 --- a/drivers/usb/musb/musb_debugfs.c +++ b/drivers/usb/musb/musb_debugfs.c | |||
@@ -49,33 +49,36 @@ struct musb_register_map { | |||
49 | }; | 49 | }; |
50 | 50 | ||
51 | static const struct musb_register_map musb_regmap[] = { | 51 | static const struct musb_register_map musb_regmap[] = { |
52 | { "FAddr", 0x00, 8 }, | 52 | { "FAddr", MUSB_FADDR, 8 }, |
53 | { "Power", 0x01, 8 }, | 53 | { "Power", MUSB_POWER, 8 }, |
54 | { "Frame", 0x0c, 16 }, | 54 | { "Frame", MUSB_FRAME, 16 }, |
55 | { "Index", 0x0e, 8 }, | 55 | { "Index", MUSB_INDEX, 8 }, |
56 | { "Testmode", 0x0f, 8 }, | 56 | { "Testmode", MUSB_TESTMODE, 8 }, |
57 | { "TxMaxPp", 0x10, 16 }, | 57 | { "TxMaxPp", MUSB_TXMAXP, 16 }, |
58 | { "TxCSRp", 0x12, 16 }, | 58 | { "TxCSRp", MUSB_TXCSR, 16 }, |
59 | { "RxMaxPp", 0x14, 16 }, | 59 | { "RxMaxPp", MUSB_RXMAXP, 16 }, |
60 | { "RxCSR", 0x16, 16 }, | 60 | { "RxCSR", MUSB_RXCSR, 16 }, |
61 | { "RxCount", 0x18, 16 }, | 61 | { "RxCount", MUSB_RXCOUNT, 16 }, |
62 | { "ConfigData", 0x1f, 8 }, | 62 | { "ConfigData", MUSB_CONFIGDATA,8 }, |
63 | { "DevCtl", 0x60, 8 }, | 63 | { "IntrRxE", MUSB_INTRRXE, 16 }, |
64 | { "MISC", 0x61, 8 }, | 64 | { "IntrTxE", MUSB_INTRTXE, 16 }, |
65 | { "TxFIFOsz", 0x62, 8 }, | 65 | { "IntrUsbE", MUSB_INTRUSBE, 8 }, |
66 | { "RxFIFOsz", 0x63, 8 }, | 66 | { "DevCtl", MUSB_DEVCTL, 8 }, |
67 | { "TxFIFOadd", 0x64, 16 }, | 67 | { "BabbleCtl", MUSB_BABBLE_CTL,8 }, |
68 | { "RxFIFOadd", 0x66, 16 }, | 68 | { "TxFIFOsz", MUSB_TXFIFOSZ, 8 }, |
69 | { "VControl", 0x68, 32 }, | 69 | { "RxFIFOsz", MUSB_RXFIFOSZ, 8 }, |
70 | { "HWVers", 0x6C, 16 }, | 70 | { "TxFIFOadd", MUSB_TXFIFOADD, 16 }, |
71 | { "EPInfo", 0x78, 8 }, | 71 | { "RxFIFOadd", MUSB_RXFIFOADD, 16 }, |
72 | { "RAMInfo", 0x79, 8 }, | 72 | { "VControl", 0x68, 32 }, |
73 | { "LinkInfo", 0x7A, 8 }, | 73 | { "HWVers", 0x69, 16 }, |
74 | { "VPLen", 0x7B, 8 }, | 74 | { "EPInfo", MUSB_EPINFO, 8 }, |
75 | { "HS_EOF1", 0x7C, 8 }, | 75 | { "RAMInfo", MUSB_RAMINFO, 8 }, |
76 | { "FS_EOF1", 0x7D, 8 }, | 76 | { "LinkInfo", MUSB_LINKINFO, 8 }, |
77 | { "LS_EOF1", 0x7E, 8 }, | 77 | { "VPLen", MUSB_VPLEN, 8 }, |
78 | { "SOFT_RST", 0x7F, 8 }, | 78 | { "HS_EOF1", MUSB_HS_EOF1, 8 }, |
79 | { "FS_EOF1", MUSB_FS_EOF1, 8 }, | ||
80 | { "LS_EOF1", MUSB_LS_EOF1, 8 }, | ||
81 | { "SOFT_RST", 0x7F, 8 }, | ||
79 | { "DMA_CNTLch0", 0x204, 16 }, | 82 | { "DMA_CNTLch0", 0x204, 16 }, |
80 | { "DMA_ADDRch0", 0x208, 32 }, | 83 | { "DMA_ADDRch0", 0x208, 32 }, |
81 | { "DMA_COUNTch0", 0x20C, 32 }, | 84 | { "DMA_COUNTch0", 0x20C, 32 }, |
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index 965c552f7035..53bd0e71d19f 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c | |||
@@ -179,9 +179,9 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
179 | 179 | ||
180 | /* Never idle if active, or when VBUS timeout is not set as host */ | 180 | /* Never idle if active, or when VBUS timeout is not set as host */ |
181 | if (musb->is_active || (musb->a_wait_bcon == 0 && | 181 | if (musb->is_active || (musb->a_wait_bcon == 0 && |
182 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { | 182 | musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) { |
183 | dev_dbg(musb->controller, "%s active, deleting timer\n", | 183 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
184 | usb_otg_state_string(musb->xceiv->state)); | 184 | usb_otg_state_string(musb->xceiv->otg->state)); |
185 | del_timer(&glue->timer); | 185 | del_timer(&glue->timer); |
186 | glue->last_timer = jiffies; | 186 | glue->last_timer = jiffies; |
187 | return; | 187 | return; |
@@ -201,7 +201,7 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
201 | glue->last_timer = timeout; | 201 | glue->last_timer = timeout; |
202 | 202 | ||
203 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", | 203 | dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", |
204 | usb_otg_state_string(musb->xceiv->state), | 204 | usb_otg_state_string(musb->xceiv->otg->state), |
205 | jiffies_to_msecs(timeout - jiffies)); | 205 | jiffies_to_msecs(timeout - jiffies)); |
206 | mod_timer(&glue->timer, timeout); | 206 | mod_timer(&glue->timer, timeout); |
207 | } | 207 | } |
@@ -265,10 +265,10 @@ static void otg_timer(unsigned long _musb) | |||
265 | */ | 265 | */ |
266 | devctl = dsps_readb(mregs, MUSB_DEVCTL); | 266 | devctl = dsps_readb(mregs, MUSB_DEVCTL); |
267 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, | 267 | dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, |
268 | usb_otg_state_string(musb->xceiv->state)); | 268 | usb_otg_state_string(musb->xceiv->otg->state)); |
269 | 269 | ||
270 | spin_lock_irqsave(&musb->lock, flags); | 270 | spin_lock_irqsave(&musb->lock, flags); |
271 | switch (musb->xceiv->state) { | 271 | switch (musb->xceiv->otg->state) { |
272 | case OTG_STATE_A_WAIT_BCON: | 272 | case OTG_STATE_A_WAIT_BCON: |
273 | dsps_writeb(musb->mregs, MUSB_DEVCTL, 0); | 273 | dsps_writeb(musb->mregs, MUSB_DEVCTL, 0); |
274 | skip_session = 1; | 274 | skip_session = 1; |
@@ -277,10 +277,10 @@ static void otg_timer(unsigned long _musb) | |||
277 | case OTG_STATE_A_IDLE: | 277 | case OTG_STATE_A_IDLE: |
278 | case OTG_STATE_B_IDLE: | 278 | case OTG_STATE_B_IDLE: |
279 | if (devctl & MUSB_DEVCTL_BDEVICE) { | 279 | if (devctl & MUSB_DEVCTL_BDEVICE) { |
280 | musb->xceiv->state = OTG_STATE_B_IDLE; | 280 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
281 | MUSB_DEV_MODE(musb); | 281 | MUSB_DEV_MODE(musb); |
282 | } else { | 282 | } else { |
283 | musb->xceiv->state = OTG_STATE_A_IDLE; | 283 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
284 | MUSB_HST_MODE(musb); | 284 | MUSB_HST_MODE(musb); |
285 | } | 285 | } |
286 | if (!(devctl & MUSB_DEVCTL_SESSION) && !skip_session) | 286 | if (!(devctl & MUSB_DEVCTL_SESSION) && !skip_session) |
@@ -288,7 +288,7 @@ static void otg_timer(unsigned long _musb) | |||
288 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); | 288 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); |
289 | break; | 289 | break; |
290 | case OTG_STATE_A_WAIT_VFALL: | 290 | case OTG_STATE_A_WAIT_VFALL: |
291 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 291 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
292 | dsps_writel(musb->ctrl_base, wrp->coreintr_set, | 292 | dsps_writel(musb->ctrl_base, wrp->coreintr_set, |
293 | MUSB_INTR_VBUSERROR << wrp->usb_shift); | 293 | MUSB_INTR_VBUSERROR << wrp->usb_shift); |
294 | break; | 294 | break; |
@@ -373,26 +373,26 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) | |||
373 | * devctl. | 373 | * devctl. |
374 | */ | 374 | */ |
375 | musb->int_usb &= ~MUSB_INTR_VBUSERROR; | 375 | musb->int_usb &= ~MUSB_INTR_VBUSERROR; |
376 | musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; | 376 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; |
377 | mod_timer(&glue->timer, | 377 | mod_timer(&glue->timer, |
378 | jiffies + wrp->poll_seconds * HZ); | 378 | jiffies + wrp->poll_seconds * HZ); |
379 | WARNING("VBUS error workaround (delay coming)\n"); | 379 | WARNING("VBUS error workaround (delay coming)\n"); |
380 | } else if (drvvbus) { | 380 | } else if (drvvbus) { |
381 | MUSB_HST_MODE(musb); | 381 | MUSB_HST_MODE(musb); |
382 | musb->xceiv->otg->default_a = 1; | 382 | musb->xceiv->otg->default_a = 1; |
383 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 383 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
384 | del_timer(&glue->timer); | 384 | del_timer(&glue->timer); |
385 | } else { | 385 | } else { |
386 | musb->is_active = 0; | 386 | musb->is_active = 0; |
387 | MUSB_DEV_MODE(musb); | 387 | MUSB_DEV_MODE(musb); |
388 | musb->xceiv->otg->default_a = 0; | 388 | musb->xceiv->otg->default_a = 0; |
389 | musb->xceiv->state = OTG_STATE_B_IDLE; | 389 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
390 | } | 390 | } |
391 | 391 | ||
392 | /* NOTE: this must complete power-on within 100 ms. */ | 392 | /* NOTE: this must complete power-on within 100 ms. */ |
393 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", | 393 | dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", |
394 | drvvbus ? "on" : "off", | 394 | drvvbus ? "on" : "off", |
395 | usb_otg_state_string(musb->xceiv->state), | 395 | usb_otg_state_string(musb->xceiv->otg->state), |
396 | err ? " ERROR" : "", | 396 | err ? " ERROR" : "", |
397 | devctl); | 397 | devctl); |
398 | ret = IRQ_HANDLED; | 398 | ret = IRQ_HANDLED; |
@@ -402,7 +402,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) | |||
402 | ret |= musb_interrupt(musb); | 402 | ret |= musb_interrupt(musb); |
403 | 403 | ||
404 | /* Poll for ID change in OTG port mode */ | 404 | /* Poll for ID change in OTG port mode */ |
405 | if (musb->xceiv->state == OTG_STATE_B_IDLE && | 405 | if (musb->xceiv->otg->state == OTG_STATE_B_IDLE && |
406 | musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) | 406 | musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) |
407 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); | 407 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); |
408 | out: | 408 | out: |
@@ -633,6 +633,7 @@ static int dsps_musb_reset(struct musb *musb) | |||
633 | } | 633 | } |
634 | 634 | ||
635 | static struct musb_platform_ops dsps_ops = { | 635 | static struct musb_platform_ops dsps_ops = { |
636 | .quirks = MUSB_INDEXED_EP, | ||
636 | .init = dsps_musb_init, | 637 | .init = dsps_musb_init, |
637 | .exit = dsps_musb_exit, | 638 | .exit = dsps_musb_exit, |
638 | 639 | ||
@@ -726,7 +727,6 @@ static int dsps_create_musb_pdev(struct dsps_glue *glue, | |||
726 | 727 | ||
727 | config = devm_kzalloc(&parent->dev, sizeof(*config), GFP_KERNEL); | 728 | config = devm_kzalloc(&parent->dev, sizeof(*config), GFP_KERNEL); |
728 | if (!config) { | 729 | if (!config) { |
729 | dev_err(dev, "failed to allocate musb hdrc config\n"); | ||
730 | ret = -ENOMEM; | 730 | ret = -ENOMEM; |
731 | goto err; | 731 | goto err; |
732 | } | 732 | } |
@@ -778,10 +778,8 @@ static int dsps_probe(struct platform_device *pdev) | |||
778 | 778 | ||
779 | /* allocate glue */ | 779 | /* allocate glue */ |
780 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); | 780 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
781 | if (!glue) { | 781 | if (!glue) |
782 | dev_err(&pdev->dev, "unable to allocate glue memory\n"); | ||
783 | return -ENOMEM; | 782 | return -ENOMEM; |
784 | } | ||
785 | 783 | ||
786 | glue->dev = &pdev->dev; | 784 | glue->dev = &pdev->dev; |
787 | glue->wrp = wrp; | 785 | glue->wrp = wrp; |
@@ -903,7 +901,7 @@ static int dsps_resume(struct device *dev) | |||
903 | dsps_writel(mbase, wrp->mode, glue->context.mode); | 901 | dsps_writel(mbase, wrp->mode, glue->context.mode); |
904 | dsps_writel(mbase, wrp->tx_mode, glue->context.tx_mode); | 902 | dsps_writel(mbase, wrp->tx_mode, glue->context.tx_mode); |
905 | dsps_writel(mbase, wrp->rx_mode, glue->context.rx_mode); | 903 | dsps_writel(mbase, wrp->rx_mode, glue->context.rx_mode); |
906 | if (musb->xceiv->state == OTG_STATE_B_IDLE && | 904 | if (musb->xceiv->otg->state == OTG_STATE_B_IDLE && |
907 | musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) | 905 | musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) |
908 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); | 906 | mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); |
909 | 907 | ||
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 24c8c0219790..49b04cb6f5ca 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c | |||
@@ -1546,7 +1546,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget) | |||
1546 | 1546 | ||
1547 | spin_lock_irqsave(&musb->lock, flags); | 1547 | spin_lock_irqsave(&musb->lock, flags); |
1548 | 1548 | ||
1549 | switch (musb->xceiv->state) { | 1549 | switch (musb->xceiv->otg->state) { |
1550 | case OTG_STATE_B_PERIPHERAL: | 1550 | case OTG_STATE_B_PERIPHERAL: |
1551 | /* NOTE: OTG state machine doesn't include B_SUSPENDED; | 1551 | /* NOTE: OTG state machine doesn't include B_SUSPENDED; |
1552 | * that's part of the standard usb 1.1 state machine, and | 1552 | * that's part of the standard usb 1.1 state machine, and |
@@ -1587,7 +1587,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget) | |||
1587 | goto done; | 1587 | goto done; |
1588 | default: | 1588 | default: |
1589 | dev_dbg(musb->controller, "Unhandled wake: %s\n", | 1589 | dev_dbg(musb->controller, "Unhandled wake: %s\n", |
1590 | usb_otg_state_string(musb->xceiv->state)); | 1590 | usb_otg_state_string(musb->xceiv->otg->state)); |
1591 | goto done; | 1591 | goto done; |
1592 | } | 1592 | } |
1593 | 1593 | ||
@@ -1684,8 +1684,7 @@ static int musb_gadget_pullup(struct usb_gadget *gadget, int is_on) | |||
1684 | 1684 | ||
1685 | static int musb_gadget_start(struct usb_gadget *g, | 1685 | static int musb_gadget_start(struct usb_gadget *g, |
1686 | struct usb_gadget_driver *driver); | 1686 | struct usb_gadget_driver *driver); |
1687 | static int musb_gadget_stop(struct usb_gadget *g, | 1687 | static int musb_gadget_stop(struct usb_gadget *g); |
1688 | struct usb_gadget_driver *driver); | ||
1689 | 1688 | ||
1690 | static const struct usb_gadget_ops musb_gadget_operations = { | 1689 | static const struct usb_gadget_ops musb_gadget_operations = { |
1691 | .get_frame = musb_gadget_get_frame, | 1690 | .get_frame = musb_gadget_get_frame, |
@@ -1792,7 +1791,7 @@ int musb_gadget_setup(struct musb *musb) | |||
1792 | 1791 | ||
1793 | MUSB_DEV_MODE(musb); | 1792 | MUSB_DEV_MODE(musb); |
1794 | musb->xceiv->otg->default_a = 0; | 1793 | musb->xceiv->otg->default_a = 0; |
1795 | musb->xceiv->state = OTG_STATE_B_IDLE; | 1794 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
1796 | 1795 | ||
1797 | /* this "gadget" abstracts/virtualizes the controller */ | 1796 | /* this "gadget" abstracts/virtualizes the controller */ |
1798 | musb->g.name = musb_driver_name; | 1797 | musb->g.name = musb_driver_name; |
@@ -1851,8 +1850,6 @@ static int musb_gadget_start(struct usb_gadget *g, | |||
1851 | 1850 | ||
1852 | pm_runtime_get_sync(musb->controller); | 1851 | pm_runtime_get_sync(musb->controller); |
1853 | 1852 | ||
1854 | dev_dbg(musb->controller, "registering driver %s\n", driver->function); | ||
1855 | |||
1856 | musb->softconnect = 0; | 1853 | musb->softconnect = 0; |
1857 | musb->gadget_driver = driver; | 1854 | musb->gadget_driver = driver; |
1858 | 1855 | ||
@@ -1860,7 +1857,7 @@ static int musb_gadget_start(struct usb_gadget *g, | |||
1860 | musb->is_active = 1; | 1857 | musb->is_active = 1; |
1861 | 1858 | ||
1862 | otg_set_peripheral(otg, &musb->g); | 1859 | otg_set_peripheral(otg, &musb->g); |
1863 | musb->xceiv->state = OTG_STATE_B_IDLE; | 1860 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
1864 | spin_unlock_irqrestore(&musb->lock, flags); | 1861 | spin_unlock_irqrestore(&musb->lock, flags); |
1865 | 1862 | ||
1866 | musb_start(musb); | 1863 | musb_start(musb); |
@@ -1925,8 +1922,7 @@ static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver) | |||
1925 | * | 1922 | * |
1926 | * @param driver the gadget driver to unregister | 1923 | * @param driver the gadget driver to unregister |
1927 | */ | 1924 | */ |
1928 | static int musb_gadget_stop(struct usb_gadget *g, | 1925 | static int musb_gadget_stop(struct usb_gadget *g) |
1929 | struct usb_gadget_driver *driver) | ||
1930 | { | 1926 | { |
1931 | struct musb *musb = gadget_to_musb(g); | 1927 | struct musb *musb = gadget_to_musb(g); |
1932 | unsigned long flags; | 1928 | unsigned long flags; |
@@ -1945,13 +1941,10 @@ static int musb_gadget_stop(struct usb_gadget *g, | |||
1945 | 1941 | ||
1946 | (void) musb_gadget_vbus_draw(&musb->g, 0); | 1942 | (void) musb_gadget_vbus_draw(&musb->g, 0); |
1947 | 1943 | ||
1948 | musb->xceiv->state = OTG_STATE_UNDEFINED; | 1944 | musb->xceiv->otg->state = OTG_STATE_UNDEFINED; |
1949 | stop_activity(musb, driver); | 1945 | stop_activity(musb, NULL); |
1950 | otg_set_peripheral(musb->xceiv->otg, NULL); | 1946 | otg_set_peripheral(musb->xceiv->otg, NULL); |
1951 | 1947 | ||
1952 | dev_dbg(musb->controller, "unregistering driver %s\n", | ||
1953 | driver ? driver->function : "(removed)"); | ||
1954 | |||
1955 | musb->is_active = 0; | 1948 | musb->is_active = 0; |
1956 | musb->gadget_driver = NULL; | 1949 | musb->gadget_driver = NULL; |
1957 | musb_platform_try_idle(musb, 0); | 1950 | musb_platform_try_idle(musb, 0); |
@@ -1975,7 +1968,7 @@ static int musb_gadget_stop(struct usb_gadget *g, | |||
1975 | void musb_g_resume(struct musb *musb) | 1968 | void musb_g_resume(struct musb *musb) |
1976 | { | 1969 | { |
1977 | musb->is_suspended = 0; | 1970 | musb->is_suspended = 0; |
1978 | switch (musb->xceiv->state) { | 1971 | switch (musb->xceiv->otg->state) { |
1979 | case OTG_STATE_B_IDLE: | 1972 | case OTG_STATE_B_IDLE: |
1980 | break; | 1973 | break; |
1981 | case OTG_STATE_B_WAIT_ACON: | 1974 | case OTG_STATE_B_WAIT_ACON: |
@@ -1989,7 +1982,7 @@ void musb_g_resume(struct musb *musb) | |||
1989 | break; | 1982 | break; |
1990 | default: | 1983 | default: |
1991 | WARNING("unhandled RESUME transition (%s)\n", | 1984 | WARNING("unhandled RESUME transition (%s)\n", |
1992 | usb_otg_state_string(musb->xceiv->state)); | 1985 | usb_otg_state_string(musb->xceiv->otg->state)); |
1993 | } | 1986 | } |
1994 | } | 1987 | } |
1995 | 1988 | ||
@@ -2001,10 +1994,10 @@ void musb_g_suspend(struct musb *musb) | |||
2001 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 1994 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
2002 | dev_dbg(musb->controller, "devctl %02x\n", devctl); | 1995 | dev_dbg(musb->controller, "devctl %02x\n", devctl); |
2003 | 1996 | ||
2004 | switch (musb->xceiv->state) { | 1997 | switch (musb->xceiv->otg->state) { |
2005 | case OTG_STATE_B_IDLE: | 1998 | case OTG_STATE_B_IDLE: |
2006 | if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) | 1999 | if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) |
2007 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 2000 | musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; |
2008 | break; | 2001 | break; |
2009 | case OTG_STATE_B_PERIPHERAL: | 2002 | case OTG_STATE_B_PERIPHERAL: |
2010 | musb->is_suspended = 1; | 2003 | musb->is_suspended = 1; |
@@ -2019,7 +2012,7 @@ void musb_g_suspend(struct musb *musb) | |||
2019 | * A_PERIPHERAL may need care too | 2012 | * A_PERIPHERAL may need care too |
2020 | */ | 2013 | */ |
2021 | WARNING("unhandled SUSPEND transition (%s)\n", | 2014 | WARNING("unhandled SUSPEND transition (%s)\n", |
2022 | usb_otg_state_string(musb->xceiv->state)); | 2015 | usb_otg_state_string(musb->xceiv->otg->state)); |
2023 | } | 2016 | } |
2024 | } | 2017 | } |
2025 | 2018 | ||
@@ -2050,22 +2043,22 @@ void musb_g_disconnect(struct musb *musb) | |||
2050 | spin_lock(&musb->lock); | 2043 | spin_lock(&musb->lock); |
2051 | } | 2044 | } |
2052 | 2045 | ||
2053 | switch (musb->xceiv->state) { | 2046 | switch (musb->xceiv->otg->state) { |
2054 | default: | 2047 | default: |
2055 | dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n", | 2048 | dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n", |
2056 | usb_otg_state_string(musb->xceiv->state)); | 2049 | usb_otg_state_string(musb->xceiv->otg->state)); |
2057 | musb->xceiv->state = OTG_STATE_A_IDLE; | 2050 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
2058 | MUSB_HST_MODE(musb); | 2051 | MUSB_HST_MODE(musb); |
2059 | break; | 2052 | break; |
2060 | case OTG_STATE_A_PERIPHERAL: | 2053 | case OTG_STATE_A_PERIPHERAL: |
2061 | musb->xceiv->state = OTG_STATE_A_WAIT_BCON; | 2054 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; |
2062 | MUSB_HST_MODE(musb); | 2055 | MUSB_HST_MODE(musb); |
2063 | break; | 2056 | break; |
2064 | case OTG_STATE_B_WAIT_ACON: | 2057 | case OTG_STATE_B_WAIT_ACON: |
2065 | case OTG_STATE_B_HOST: | 2058 | case OTG_STATE_B_HOST: |
2066 | case OTG_STATE_B_PERIPHERAL: | 2059 | case OTG_STATE_B_PERIPHERAL: |
2067 | case OTG_STATE_B_IDLE: | 2060 | case OTG_STATE_B_IDLE: |
2068 | musb->xceiv->state = OTG_STATE_B_IDLE; | 2061 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
2069 | break; | 2062 | break; |
2070 | case OTG_STATE_B_SRP_INIT: | 2063 | case OTG_STATE_B_SRP_INIT: |
2071 | break; | 2064 | break; |
@@ -2090,9 +2083,12 @@ __acquires(musb->lock) | |||
2090 | : NULL | 2083 | : NULL |
2091 | ); | 2084 | ); |
2092 | 2085 | ||
2093 | /* report disconnect, if we didn't already (flushing EP state) */ | 2086 | /* report reset, if we didn't already (flushing EP state) */ |
2094 | if (musb->g.speed != USB_SPEED_UNKNOWN) | 2087 | if (musb->gadget_driver && musb->g.speed != USB_SPEED_UNKNOWN) { |
2095 | musb_g_disconnect(musb); | 2088 | spin_unlock(&musb->lock); |
2089 | usb_gadget_udc_reset(&musb->g, musb->gadget_driver); | ||
2090 | spin_lock(&musb->lock); | ||
2091 | } | ||
2096 | 2092 | ||
2097 | /* clear HR */ | 2093 | /* clear HR */ |
2098 | else if (devctl & MUSB_DEVCTL_HR) | 2094 | else if (devctl & MUSB_DEVCTL_HR) |
@@ -2125,13 +2121,13 @@ __acquires(musb->lock) | |||
2125 | * In that case, do not rely on devctl for setting | 2121 | * In that case, do not rely on devctl for setting |
2126 | * peripheral mode. | 2122 | * peripheral mode. |
2127 | */ | 2123 | */ |
2128 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 2124 | musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; |
2129 | musb->g.is_a_peripheral = 0; | 2125 | musb->g.is_a_peripheral = 0; |
2130 | } else if (devctl & MUSB_DEVCTL_BDEVICE) { | 2126 | } else if (devctl & MUSB_DEVCTL_BDEVICE) { |
2131 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 2127 | musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL; |
2132 | musb->g.is_a_peripheral = 0; | 2128 | musb->g.is_a_peripheral = 0; |
2133 | } else { | 2129 | } else { |
2134 | musb->xceiv->state = OTG_STATE_A_PERIPHERAL; | 2130 | musb->xceiv->otg->state = OTG_STATE_A_PERIPHERAL; |
2135 | musb->g.is_a_peripheral = 1; | 2131 | musb->g.is_a_peripheral = 1; |
2136 | } | 2132 | } |
2137 | 2133 | ||
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c index 855793d701bb..23d474d3d7f4 100644 --- a/drivers/usb/musb/musb_host.c +++ b/drivers/usb/musb/musb_host.c | |||
@@ -2463,7 +2463,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) | |||
2463 | if (!is_host_active(musb)) | 2463 | if (!is_host_active(musb)) |
2464 | return 0; | 2464 | return 0; |
2465 | 2465 | ||
2466 | switch (musb->xceiv->state) { | 2466 | switch (musb->xceiv->otg->state) { |
2467 | case OTG_STATE_A_SUSPEND: | 2467 | case OTG_STATE_A_SUSPEND: |
2468 | return 0; | 2468 | return 0; |
2469 | case OTG_STATE_A_WAIT_VRISE: | 2469 | case OTG_STATE_A_WAIT_VRISE: |
@@ -2473,7 +2473,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) | |||
2473 | */ | 2473 | */ |
2474 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 2474 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
2475 | if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) | 2475 | if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) |
2476 | musb->xceiv->state = OTG_STATE_A_WAIT_BCON; | 2476 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; |
2477 | break; | 2477 | break; |
2478 | default: | 2478 | default: |
2479 | break; | 2479 | break; |
@@ -2481,7 +2481,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) | |||
2481 | 2481 | ||
2482 | if (musb->is_active) { | 2482 | if (musb->is_active) { |
2483 | WARNING("trying to suspend as %s while active\n", | 2483 | WARNING("trying to suspend as %s while active\n", |
2484 | usb_otg_state_string(musb->xceiv->state)); | 2484 | usb_otg_state_string(musb->xceiv->otg->state)); |
2485 | return -EBUSY; | 2485 | return -EBUSY; |
2486 | } else | 2486 | } else |
2487 | return 0; | 2487 | return 0; |
@@ -2678,7 +2678,7 @@ int musb_host_setup(struct musb *musb, int power_budget) | |||
2678 | 2678 | ||
2679 | MUSB_HST_MODE(musb); | 2679 | MUSB_HST_MODE(musb); |
2680 | musb->xceiv->otg->default_a = 1; | 2680 | musb->xceiv->otg->default_a = 1; |
2681 | musb->xceiv->state = OTG_STATE_A_IDLE; | 2681 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
2682 | 2682 | ||
2683 | otg_set_host(musb->xceiv->otg, &hcd->self); | 2683 | otg_set_host(musb->xceiv->otg, &hcd->self); |
2684 | hcd->self.otg_port = 1; | 2684 | hcd->self.otg_port = 1; |
diff --git a/drivers/usb/musb/musb_io.h b/drivers/usb/musb/musb_io.h index eebeed78edd6..8a57a6f4b3a6 100644 --- a/drivers/usb/musb/musb_io.h +++ b/drivers/usb/musb/musb_io.h | |||
@@ -37,86 +37,32 @@ | |||
37 | 37 | ||
38 | #include <linux/io.h> | 38 | #include <linux/io.h> |
39 | 39 | ||
40 | #ifndef CONFIG_BLACKFIN | 40 | #define musb_ep_select(_mbase, _epnum) musb->io.ep_select((_mbase), (_epnum)) |
41 | 41 | ||
42 | /* NOTE: these offsets are all in bytes */ | 42 | /** |
43 | 43 | * struct musb_io - IO functions for MUSB | |
44 | static inline u16 musb_readw(const void __iomem *addr, unsigned offset) | 44 | * @quirks: platform specific flags |
45 | { return __raw_readw(addr + offset); } | 45 | * @ep_offset: platform specific function to get end point offset |
46 | 46 | * @ep_select: platform specific function to select end point | |
47 | static inline u32 musb_readl(const void __iomem *addr, unsigned offset) | 47 | * @fifo_offset: platform specific function to get fifo offset |
48 | { return __raw_readl(addr + offset); } | 48 | * @read_fifo: platform specific function to read fifo |
49 | 49 | * @write_fifo: platform specific function to write fifo | |
50 | |||
51 | static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data) | ||
52 | { __raw_writew(data, addr + offset); } | ||
53 | |||
54 | static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data) | ||
55 | { __raw_writel(data, addr + offset); } | ||
56 | |||
57 | |||
58 | #if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE) | ||
59 | |||
60 | /* | ||
61 | * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum. | ||
62 | */ | 50 | */ |
63 | static inline u8 musb_readb(const void __iomem *addr, unsigned offset) | 51 | struct musb_io { |
64 | { | 52 | u32 quirks; |
65 | u16 tmp; | 53 | u32 (*ep_offset)(u8 epnum, u16 offset); |
66 | u8 val; | 54 | void (*ep_select)(void __iomem *mbase, u8 epnum); |
67 | 55 | u32 (*fifo_offset)(u8 epnum); | |
68 | tmp = __raw_readw(addr + (offset & ~1)); | 56 | void (*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf); |
69 | if (offset & 1) | 57 | void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf); |
70 | val = (tmp >> 8); | 58 | }; |
71 | else | 59 | |
72 | val = tmp & 0xff; | 60 | /* Do not add new entries here, add them the struct musb_io instead */ |
73 | 61 | extern u8 (*musb_readb)(const void __iomem *addr, unsigned offset); | |
74 | return val; | 62 | extern void (*musb_writeb)(void __iomem *addr, unsigned offset, u8 data); |
75 | } | 63 | extern u16 (*musb_readw)(const void __iomem *addr, unsigned offset); |
76 | 64 | extern void (*musb_writew)(void __iomem *addr, unsigned offset, u16 data); | |
77 | static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data) | 65 | extern u32 (*musb_readl)(const void __iomem *addr, unsigned offset); |
78 | { | 66 | extern void (*musb_writel)(void __iomem *addr, unsigned offset, u32 data); |
79 | u16 tmp; | ||
80 | |||
81 | tmp = __raw_readw(addr + (offset & ~1)); | ||
82 | if (offset & 1) | ||
83 | tmp = (data << 8) | (tmp & 0xff); | ||
84 | else | ||
85 | tmp = (tmp & 0xff00) | data; | ||
86 | |||
87 | __raw_writew(tmp, addr + (offset & ~1)); | ||
88 | } | ||
89 | |||
90 | #else | ||
91 | |||
92 | static inline u8 musb_readb(const void __iomem *addr, unsigned offset) | ||
93 | { return __raw_readb(addr + offset); } | ||
94 | |||
95 | static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data) | ||
96 | { __raw_writeb(data, addr + offset); } | ||
97 | |||
98 | #endif /* CONFIG_USB_MUSB_TUSB6010 */ | ||
99 | |||
100 | #else | ||
101 | |||
102 | static inline u8 musb_readb(const void __iomem *addr, unsigned offset) | ||
103 | { return (u8) (bfin_read16(addr + offset)); } | ||
104 | |||
105 | static inline u16 musb_readw(const void __iomem *addr, unsigned offset) | ||
106 | { return bfin_read16(addr + offset); } | ||
107 | |||
108 | static inline u32 musb_readl(const void __iomem *addr, unsigned offset) | ||
109 | { return (u32) (bfin_read16(addr + offset)); } | ||
110 | |||
111 | static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data) | ||
112 | { bfin_write16(addr + offset, (u16) data); } | ||
113 | |||
114 | static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data) | ||
115 | { bfin_write16(addr + offset, data); } | ||
116 | |||
117 | static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data) | ||
118 | { bfin_write16(addr + offset, (u16) data); } | ||
119 | |||
120 | #endif /* CONFIG_BLACKFIN */ | ||
121 | 67 | ||
122 | #endif | 68 | #endif |
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h index 37122a480bc1..11f0be07491e 100644 --- a/drivers/usb/musb/musb_regs.h +++ b/drivers/usb/musb/musb_regs.h | |||
@@ -239,14 +239,6 @@ | |||
239 | #define MUSB_INDEX 0x0E /* 8 bit */ | 239 | #define MUSB_INDEX 0x0E /* 8 bit */ |
240 | #define MUSB_TESTMODE 0x0F /* 8 bit */ | 240 | #define MUSB_TESTMODE 0x0F /* 8 bit */ |
241 | 241 | ||
242 | /* Get offset for a given FIFO from musb->mregs */ | ||
243 | #if defined(CONFIG_USB_MUSB_TUSB6010) || \ | ||
244 | defined(CONFIG_USB_MUSB_TUSB6010_MODULE) | ||
245 | #define MUSB_FIFO_OFFSET(epnum) (0x200 + ((epnum) * 0x20)) | ||
246 | #else | ||
247 | #define MUSB_FIFO_OFFSET(epnum) (0x20 + ((epnum) * 4)) | ||
248 | #endif | ||
249 | |||
250 | /* | 242 | /* |
251 | * Additional Control Registers | 243 | * Additional Control Registers |
252 | */ | 244 | */ |
@@ -295,21 +287,7 @@ | |||
295 | #define MUSB_FIFOSIZE 0x0F | 287 | #define MUSB_FIFOSIZE 0x0F |
296 | #define MUSB_CONFIGDATA MUSB_FIFOSIZE /* Re-used for EP0 */ | 288 | #define MUSB_CONFIGDATA MUSB_FIFOSIZE /* Re-used for EP0 */ |
297 | 289 | ||
298 | /* Offsets to endpoint registers in indexed model (using INDEX register) */ | ||
299 | #define MUSB_INDEXED_OFFSET(_epnum, _offset) \ | ||
300 | (0x10 + (_offset)) | ||
301 | |||
302 | /* Offsets to endpoint registers in flat models */ | ||
303 | #define MUSB_FLAT_OFFSET(_epnum, _offset) \ | ||
304 | (0x100 + (0x10*(_epnum)) + (_offset)) | ||
305 | |||
306 | #if defined(CONFIG_USB_MUSB_TUSB6010) || \ | ||
307 | defined(CONFIG_USB_MUSB_TUSB6010_MODULE) | ||
308 | /* TUSB6010 EP0 configuration register is special */ | ||
309 | #define MUSB_TUSB_OFFSET(_epnum, _offset) \ | ||
310 | (0x10 + _offset) | ||
311 | #include "tusb6010.h" /* Needed "only" for TUSB_EP0_CONF */ | 290 | #include "tusb6010.h" /* Needed "only" for TUSB_EP0_CONF */ |
312 | #endif | ||
313 | 291 | ||
314 | #define MUSB_TXCSR_MODE 0x2000 | 292 | #define MUSB_TXCSR_MODE 0x2000 |
315 | 293 | ||
@@ -480,10 +458,6 @@ static inline u8 musb_read_txhubport(void __iomem *mbase, u8 epnum) | |||
480 | #define MUSB_INDEX USB_OFFSET(USB_INDEX) /* 8 bit */ | 458 | #define MUSB_INDEX USB_OFFSET(USB_INDEX) /* 8 bit */ |
481 | #define MUSB_TESTMODE USB_OFFSET(USB_TESTMODE)/* 8 bit */ | 459 | #define MUSB_TESTMODE USB_OFFSET(USB_TESTMODE)/* 8 bit */ |
482 | 460 | ||
483 | /* Get offset for a given FIFO from musb->mregs */ | ||
484 | #define MUSB_FIFO_OFFSET(epnum) \ | ||
485 | (USB_OFFSET(USB_EP0_FIFO) + ((epnum) * 8)) | ||
486 | |||
487 | /* | 461 | /* |
488 | * Additional Control Registers | 462 | * Additional Control Registers |
489 | */ | 463 | */ |
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c index e2d2d8c9891b..b072420e44f5 100644 --- a/drivers/usb/musb/musb_virthub.c +++ b/drivers/usb/musb/musb_virthub.c | |||
@@ -69,9 +69,10 @@ void musb_host_finish_resume(struct work_struct *work) | |||
69 | musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; | 69 | musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; |
70 | usb_hcd_poll_rh_status(musb->hcd); | 70 | usb_hcd_poll_rh_status(musb->hcd); |
71 | /* NOTE: it might really be A_WAIT_BCON ... */ | 71 | /* NOTE: it might really be A_WAIT_BCON ... */ |
72 | musb->xceiv->state = OTG_STATE_A_HOST; | 72 | musb->xceiv->otg->state = OTG_STATE_A_HOST; |
73 | 73 | ||
74 | spin_unlock_irqrestore(&musb->lock, flags); | 74 | spin_unlock_irqrestore(&musb->lock, flags); |
75 | musb_host_resume_root_hub(musb); | ||
75 | } | 76 | } |
76 | 77 | ||
77 | void musb_port_suspend(struct musb *musb, bool do_suspend) | 78 | void musb_port_suspend(struct musb *musb, bool do_suspend) |
@@ -107,9 +108,9 @@ void musb_port_suspend(struct musb *musb, bool do_suspend) | |||
107 | dev_dbg(musb->controller, "Root port suspended, power %02x\n", power); | 108 | dev_dbg(musb->controller, "Root port suspended, power %02x\n", power); |
108 | 109 | ||
109 | musb->port1_status |= USB_PORT_STAT_SUSPEND; | 110 | musb->port1_status |= USB_PORT_STAT_SUSPEND; |
110 | switch (musb->xceiv->state) { | 111 | switch (musb->xceiv->otg->state) { |
111 | case OTG_STATE_A_HOST: | 112 | case OTG_STATE_A_HOST: |
112 | musb->xceiv->state = OTG_STATE_A_SUSPEND; | 113 | musb->xceiv->otg->state = OTG_STATE_A_SUSPEND; |
113 | musb->is_active = otg->host->b_hnp_enable; | 114 | musb->is_active = otg->host->b_hnp_enable; |
114 | if (musb->is_active) | 115 | if (musb->is_active) |
115 | mod_timer(&musb->otg_timer, jiffies | 116 | mod_timer(&musb->otg_timer, jiffies |
@@ -118,13 +119,13 @@ void musb_port_suspend(struct musb *musb, bool do_suspend) | |||
118 | musb_platform_try_idle(musb, 0); | 119 | musb_platform_try_idle(musb, 0); |
119 | break; | 120 | break; |
120 | case OTG_STATE_B_HOST: | 121 | case OTG_STATE_B_HOST: |
121 | musb->xceiv->state = OTG_STATE_B_WAIT_ACON; | 122 | musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON; |
122 | musb->is_active = otg->host->b_hnp_enable; | 123 | musb->is_active = otg->host->b_hnp_enable; |
123 | musb_platform_try_idle(musb, 0); | 124 | musb_platform_try_idle(musb, 0); |
124 | break; | 125 | break; |
125 | default: | 126 | default: |
126 | dev_dbg(musb->controller, "bogus rh suspend? %s\n", | 127 | dev_dbg(musb->controller, "bogus rh suspend? %s\n", |
127 | usb_otg_state_string(musb->xceiv->state)); | 128 | usb_otg_state_string(musb->xceiv->otg->state)); |
128 | } | 129 | } |
129 | } else if (power & MUSB_POWER_SUSPENDM) { | 130 | } else if (power & MUSB_POWER_SUSPENDM) { |
130 | power &= ~MUSB_POWER_SUSPENDM; | 131 | power &= ~MUSB_POWER_SUSPENDM; |
@@ -145,7 +146,7 @@ void musb_port_reset(struct musb *musb, bool do_reset) | |||
145 | u8 power; | 146 | u8 power; |
146 | void __iomem *mbase = musb->mregs; | 147 | void __iomem *mbase = musb->mregs; |
147 | 148 | ||
148 | if (musb->xceiv->state == OTG_STATE_B_IDLE) { | 149 | if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) { |
149 | dev_dbg(musb->controller, "HNP: Returning from HNP; no hub reset from b_idle\n"); | 150 | dev_dbg(musb->controller, "HNP: Returning from HNP; no hub reset from b_idle\n"); |
150 | musb->port1_status &= ~USB_PORT_STAT_RESET; | 151 | musb->port1_status &= ~USB_PORT_STAT_RESET; |
151 | return; | 152 | return; |
@@ -224,24 +225,24 @@ void musb_root_disconnect(struct musb *musb) | |||
224 | usb_hcd_poll_rh_status(musb->hcd); | 225 | usb_hcd_poll_rh_status(musb->hcd); |
225 | musb->is_active = 0; | 226 | musb->is_active = 0; |
226 | 227 | ||
227 | switch (musb->xceiv->state) { | 228 | switch (musb->xceiv->otg->state) { |
228 | case OTG_STATE_A_SUSPEND: | 229 | case OTG_STATE_A_SUSPEND: |
229 | if (otg->host->b_hnp_enable) { | 230 | if (otg->host->b_hnp_enable) { |
230 | musb->xceiv->state = OTG_STATE_A_PERIPHERAL; | 231 | musb->xceiv->otg->state = OTG_STATE_A_PERIPHERAL; |
231 | musb->g.is_a_peripheral = 1; | 232 | musb->g.is_a_peripheral = 1; |
232 | break; | 233 | break; |
233 | } | 234 | } |
234 | /* FALLTHROUGH */ | 235 | /* FALLTHROUGH */ |
235 | case OTG_STATE_A_HOST: | 236 | case OTG_STATE_A_HOST: |
236 | musb->xceiv->state = OTG_STATE_A_WAIT_BCON; | 237 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; |
237 | musb->is_active = 0; | 238 | musb->is_active = 0; |
238 | break; | 239 | break; |
239 | case OTG_STATE_A_WAIT_VFALL: | 240 | case OTG_STATE_A_WAIT_VFALL: |
240 | musb->xceiv->state = OTG_STATE_B_IDLE; | 241 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
241 | break; | 242 | break; |
242 | default: | 243 | default: |
243 | dev_dbg(musb->controller, "host disconnect (%s)\n", | 244 | dev_dbg(musb->controller, "host disconnect (%s)\n", |
244 | usb_otg_state_string(musb->xceiv->state)); | 245 | usb_otg_state_string(musb->xceiv->otg->state)); |
245 | } | 246 | } |
246 | } | 247 | } |
247 | 248 | ||
diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c index e8e9f9aab203..ab7ec09a8afe 100644 --- a/drivers/usb/musb/musbhsdma.c +++ b/drivers/usb/musb/musbhsdma.c | |||
@@ -195,6 +195,7 @@ static int dma_channel_abort(struct dma_channel *channel) | |||
195 | { | 195 | { |
196 | struct musb_dma_channel *musb_channel = channel->private_data; | 196 | struct musb_dma_channel *musb_channel = channel->private_data; |
197 | void __iomem *mbase = musb_channel->controller->base; | 197 | void __iomem *mbase = musb_channel->controller->base; |
198 | struct musb *musb = musb_channel->controller->private_data; | ||
198 | 199 | ||
199 | u8 bchannel = musb_channel->idx; | 200 | u8 bchannel = musb_channel->idx; |
200 | int offset; | 201 | int offset; |
@@ -202,7 +203,7 @@ static int dma_channel_abort(struct dma_channel *channel) | |||
202 | 203 | ||
203 | if (channel->status == MUSB_DMA_STATUS_BUSY) { | 204 | if (channel->status == MUSB_DMA_STATUS_BUSY) { |
204 | if (musb_channel->transmit) { | 205 | if (musb_channel->transmit) { |
205 | offset = MUSB_EP_OFFSET(musb_channel->epnum, | 206 | offset = musb->io.ep_offset(musb_channel->epnum, |
206 | MUSB_TXCSR); | 207 | MUSB_TXCSR); |
207 | 208 | ||
208 | /* | 209 | /* |
@@ -215,7 +216,7 @@ static int dma_channel_abort(struct dma_channel *channel) | |||
215 | csr &= ~MUSB_TXCSR_DMAMODE; | 216 | csr &= ~MUSB_TXCSR_DMAMODE; |
216 | musb_writew(mbase, offset, csr); | 217 | musb_writew(mbase, offset, csr); |
217 | } else { | 218 | } else { |
218 | offset = MUSB_EP_OFFSET(musb_channel->epnum, | 219 | offset = musb->io.ep_offset(musb_channel->epnum, |
219 | MUSB_RXCSR); | 220 | MUSB_RXCSR); |
220 | 221 | ||
221 | csr = musb_readw(mbase, offset); | 222 | csr = musb_readw(mbase, offset); |
@@ -326,7 +327,7 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data) | |||
326 | (musb_channel->max_packet_sz - 1))) | 327 | (musb_channel->max_packet_sz - 1))) |
327 | ) { | 328 | ) { |
328 | u8 epnum = musb_channel->epnum; | 329 | u8 epnum = musb_channel->epnum; |
329 | int offset = MUSB_EP_OFFSET(epnum, | 330 | int offset = musb->io.ep_offset(epnum, |
330 | MUSB_TXCSR); | 331 | MUSB_TXCSR); |
331 | u16 txcsr; | 332 | u16 txcsr; |
332 | 333 | ||
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index d369bf1f3936..763649eb4987 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c | |||
@@ -65,15 +65,15 @@ static void musb_do_idle(unsigned long _musb) | |||
65 | 65 | ||
66 | spin_lock_irqsave(&musb->lock, flags); | 66 | spin_lock_irqsave(&musb->lock, flags); |
67 | 67 | ||
68 | switch (musb->xceiv->state) { | 68 | switch (musb->xceiv->otg->state) { |
69 | case OTG_STATE_A_WAIT_BCON: | 69 | case OTG_STATE_A_WAIT_BCON: |
70 | 70 | ||
71 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 71 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
72 | if (devctl & MUSB_DEVCTL_BDEVICE) { | 72 | if (devctl & MUSB_DEVCTL_BDEVICE) { |
73 | musb->xceiv->state = OTG_STATE_B_IDLE; | 73 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
74 | MUSB_DEV_MODE(musb); | 74 | MUSB_DEV_MODE(musb); |
75 | } else { | 75 | } else { |
76 | musb->xceiv->state = OTG_STATE_A_IDLE; | 76 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
77 | MUSB_HST_MODE(musb); | 77 | MUSB_HST_MODE(musb); |
78 | } | 78 | } |
79 | break; | 79 | break; |
@@ -90,15 +90,15 @@ static void musb_do_idle(unsigned long _musb) | |||
90 | musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; | 90 | musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16; |
91 | usb_hcd_poll_rh_status(musb->hcd); | 91 | usb_hcd_poll_rh_status(musb->hcd); |
92 | /* NOTE: it might really be A_WAIT_BCON ... */ | 92 | /* NOTE: it might really be A_WAIT_BCON ... */ |
93 | musb->xceiv->state = OTG_STATE_A_HOST; | 93 | musb->xceiv->otg->state = OTG_STATE_A_HOST; |
94 | } | 94 | } |
95 | break; | 95 | break; |
96 | case OTG_STATE_A_HOST: | 96 | case OTG_STATE_A_HOST: |
97 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 97 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
98 | if (devctl & MUSB_DEVCTL_BDEVICE) | 98 | if (devctl & MUSB_DEVCTL_BDEVICE) |
99 | musb->xceiv->state = OTG_STATE_B_IDLE; | 99 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
100 | else | 100 | else |
101 | musb->xceiv->state = OTG_STATE_A_WAIT_BCON; | 101 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; |
102 | default: | 102 | default: |
103 | break; | 103 | break; |
104 | } | 104 | } |
@@ -116,9 +116,9 @@ static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
116 | 116 | ||
117 | /* Never idle if active, or when VBUS timeout is not set as host */ | 117 | /* Never idle if active, or when VBUS timeout is not set as host */ |
118 | if (musb->is_active || ((musb->a_wait_bcon == 0) | 118 | if (musb->is_active || ((musb->a_wait_bcon == 0) |
119 | && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { | 119 | && (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON))) { |
120 | dev_dbg(musb->controller, "%s active, deleting timer\n", | 120 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
121 | usb_otg_state_string(musb->xceiv->state)); | 121 | usb_otg_state_string(musb->xceiv->otg->state)); |
122 | del_timer(&musb_idle_timer); | 122 | del_timer(&musb_idle_timer); |
123 | last_timer = jiffies; | 123 | last_timer = jiffies; |
124 | return; | 124 | return; |
@@ -135,7 +135,7 @@ static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
135 | last_timer = timeout; | 135 | last_timer = timeout; |
136 | 136 | ||
137 | dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", | 137 | dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", |
138 | usb_otg_state_string(musb->xceiv->state), | 138 | usb_otg_state_string(musb->xceiv->otg->state), |
139 | (unsigned long)jiffies_to_msecs(timeout - jiffies)); | 139 | (unsigned long)jiffies_to_msecs(timeout - jiffies)); |
140 | mod_timer(&musb_idle_timer, timeout); | 140 | mod_timer(&musb_idle_timer, timeout); |
141 | } | 141 | } |
@@ -153,7 +153,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on) | |||
153 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 153 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
154 | 154 | ||
155 | if (is_on) { | 155 | if (is_on) { |
156 | if (musb->xceiv->state == OTG_STATE_A_IDLE) { | 156 | if (musb->xceiv->otg->state == OTG_STATE_A_IDLE) { |
157 | int loops = 100; | 157 | int loops = 100; |
158 | /* start the session */ | 158 | /* start the session */ |
159 | devctl |= MUSB_DEVCTL_SESSION; | 159 | devctl |= MUSB_DEVCTL_SESSION; |
@@ -162,7 +162,8 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on) | |||
162 | * Wait for the musb to set as A device to enable the | 162 | * Wait for the musb to set as A device to enable the |
163 | * VBUS | 163 | * VBUS |
164 | */ | 164 | */ |
165 | while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) { | 165 | while (musb_readb(musb->mregs, MUSB_DEVCTL) & |
166 | MUSB_DEVCTL_BDEVICE) { | ||
166 | 167 | ||
167 | mdelay(5); | 168 | mdelay(5); |
168 | cpu_relax(); | 169 | cpu_relax(); |
@@ -179,7 +180,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on) | |||
179 | } else { | 180 | } else { |
180 | musb->is_active = 1; | 181 | musb->is_active = 1; |
181 | otg->default_a = 1; | 182 | otg->default_a = 1; |
182 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 183 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
183 | devctl |= MUSB_DEVCTL_SESSION; | 184 | devctl |= MUSB_DEVCTL_SESSION; |
184 | MUSB_HST_MODE(musb); | 185 | MUSB_HST_MODE(musb); |
185 | } | 186 | } |
@@ -191,7 +192,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on) | |||
191 | */ | 192 | */ |
192 | 193 | ||
193 | otg->default_a = 0; | 194 | otg->default_a = 0; |
194 | musb->xceiv->state = OTG_STATE_B_IDLE; | 195 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
195 | devctl &= ~MUSB_DEVCTL_SESSION; | 196 | devctl &= ~MUSB_DEVCTL_SESSION; |
196 | 197 | ||
197 | MUSB_DEV_MODE(musb); | 198 | MUSB_DEV_MODE(musb); |
@@ -200,7 +201,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on) | |||
200 | 201 | ||
201 | dev_dbg(musb->controller, "VBUS %s, devctl %02x " | 202 | dev_dbg(musb->controller, "VBUS %s, devctl %02x " |
202 | /* otg %3x conf %08x prcm %08x */ "\n", | 203 | /* otg %3x conf %08x prcm %08x */ "\n", |
203 | usb_otg_state_string(musb->xceiv->state), | 204 | usb_otg_state_string(musb->xceiv->otg->state), |
204 | musb_readb(musb->mregs, MUSB_DEVCTL)); | 205 | musb_readb(musb->mregs, MUSB_DEVCTL)); |
205 | } | 206 | } |
206 | 207 | ||
@@ -265,7 +266,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue) | |||
265 | dev_dbg(dev, "ID GND\n"); | 266 | dev_dbg(dev, "ID GND\n"); |
266 | 267 | ||
267 | otg->default_a = true; | 268 | otg->default_a = true; |
268 | musb->xceiv->state = OTG_STATE_A_IDLE; | 269 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
269 | musb->xceiv->last_event = USB_EVENT_ID; | 270 | musb->xceiv->last_event = USB_EVENT_ID; |
270 | if (musb->gadget_driver) { | 271 | if (musb->gadget_driver) { |
271 | pm_runtime_get_sync(dev); | 272 | pm_runtime_get_sync(dev); |
@@ -279,7 +280,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue) | |||
279 | dev_dbg(dev, "VBUS Connect\n"); | 280 | dev_dbg(dev, "VBUS Connect\n"); |
280 | 281 | ||
281 | otg->default_a = false; | 282 | otg->default_a = false; |
282 | musb->xceiv->state = OTG_STATE_B_IDLE; | 283 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
283 | musb->xceiv->last_event = USB_EVENT_VBUS; | 284 | musb->xceiv->last_event = USB_EVENT_VBUS; |
284 | if (musb->gadget_driver) | 285 | if (musb->gadget_driver) |
285 | pm_runtime_get_sync(dev); | 286 | pm_runtime_get_sync(dev); |
@@ -518,10 +519,8 @@ static int omap2430_probe(struct platform_device *pdev) | |||
518 | int ret = -ENOMEM; | 519 | int ret = -ENOMEM; |
519 | 520 | ||
520 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); | 521 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
521 | if (!glue) { | 522 | if (!glue) |
522 | dev_err(&pdev->dev, "failed to allocate glue context\n"); | ||
523 | goto err0; | 523 | goto err0; |
524 | } | ||
525 | 524 | ||
526 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | 525 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); |
527 | if (!musb) { | 526 | if (!musb) { |
@@ -543,25 +542,16 @@ static int omap2430_probe(struct platform_device *pdev) | |||
543 | struct platform_device *control_pdev; | 542 | struct platform_device *control_pdev; |
544 | 543 | ||
545 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | 544 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
546 | if (!pdata) { | 545 | if (!pdata) |
547 | dev_err(&pdev->dev, | ||
548 | "failed to allocate musb platform data\n"); | ||
549 | goto err2; | 546 | goto err2; |
550 | } | ||
551 | 547 | ||
552 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | 548 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
553 | if (!data) { | 549 | if (!data) |
554 | dev_err(&pdev->dev, | ||
555 | "failed to allocate musb board data\n"); | ||
556 | goto err2; | 550 | goto err2; |
557 | } | ||
558 | 551 | ||
559 | config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL); | 552 | config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL); |
560 | if (!config) { | 553 | if (!config) |
561 | dev_err(&pdev->dev, | ||
562 | "failed to allocate musb hdrc config\n"); | ||
563 | goto err2; | 554 | goto err2; |
564 | } | ||
565 | 555 | ||
566 | of_property_read_u32(np, "mode", (u32 *)&pdata->mode); | 556 | of_property_read_u32(np, "mode", (u32 *)&pdata->mode); |
567 | of_property_read_u32(np, "interface-type", | 557 | of_property_read_u32(np, "interface-type", |
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c index 2daa779f1382..3a5ffd575438 100644 --- a/drivers/usb/musb/tusb6010.c +++ b/drivers/usb/musb/tusb6010.c | |||
@@ -126,6 +126,52 @@ static void tusb_wbus_quirk(struct musb *musb, int enabled) | |||
126 | } | 126 | } |
127 | } | 127 | } |
128 | 128 | ||
129 | static u32 tusb_fifo_offset(u8 epnum) | ||
130 | { | ||
131 | return 0x200 + (epnum * 0x20); | ||
132 | } | ||
133 | |||
134 | static u32 tusb_ep_offset(u8 epnum, u16 offset) | ||
135 | { | ||
136 | return 0x10 + offset; | ||
137 | } | ||
138 | |||
139 | /* TUSB mapping: "flat" plus ep0 special cases */ | ||
140 | static void tusb_ep_select(void __iomem *mbase, u8 epnum) | ||
141 | { | ||
142 | musb_writeb(mbase, MUSB_INDEX, epnum); | ||
143 | } | ||
144 | |||
145 | /* | ||
146 | * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum. | ||
147 | */ | ||
148 | static u8 tusb_readb(const void __iomem *addr, unsigned offset) | ||
149 | { | ||
150 | u16 tmp; | ||
151 | u8 val; | ||
152 | |||
153 | tmp = __raw_readw(addr + (offset & ~1)); | ||
154 | if (offset & 1) | ||
155 | val = (tmp >> 8); | ||
156 | else | ||
157 | val = tmp & 0xff; | ||
158 | |||
159 | return val; | ||
160 | } | ||
161 | |||
162 | static void tusb_writeb(void __iomem *addr, unsigned offset, u8 data) | ||
163 | { | ||
164 | u16 tmp; | ||
165 | |||
166 | tmp = __raw_readw(addr + (offset & ~1)); | ||
167 | if (offset & 1) | ||
168 | tmp = (data << 8) | (tmp & 0xff); | ||
169 | else | ||
170 | tmp = (tmp & 0xff00) | data; | ||
171 | |||
172 | __raw_writew(tmp, addr + (offset & ~1)); | ||
173 | } | ||
174 | |||
129 | /* | 175 | /* |
130 | * TUSB 6010 may use a parallel bus that doesn't support byte ops; | 176 | * TUSB 6010 may use a parallel bus that doesn't support byte ops; |
131 | * so both loading and unloading FIFOs need explicit byte counts. | 177 | * so both loading and unloading FIFOs need explicit byte counts. |
@@ -173,7 +219,7 @@ static inline void tusb_fifo_read_unaligned(void __iomem *fifo, | |||
173 | } | 219 | } |
174 | } | 220 | } |
175 | 221 | ||
176 | void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf) | 222 | static void tusb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf) |
177 | { | 223 | { |
178 | struct musb *musb = hw_ep->musb; | 224 | struct musb *musb = hw_ep->musb; |
179 | void __iomem *ep_conf = hw_ep->conf; | 225 | void __iomem *ep_conf = hw_ep->conf; |
@@ -223,7 +269,7 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf) | |||
223 | tusb_fifo_write_unaligned(fifo, buf, len); | 269 | tusb_fifo_write_unaligned(fifo, buf, len); |
224 | } | 270 | } |
225 | 271 | ||
226 | void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *buf) | 272 | static void tusb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *buf) |
227 | { | 273 | { |
228 | struct musb *musb = hw_ep->musb; | 274 | struct musb *musb = hw_ep->musb; |
229 | void __iomem *ep_conf = hw_ep->conf; | 275 | void __iomem *ep_conf = hw_ep->conf; |
@@ -415,13 +461,13 @@ static void musb_do_idle(unsigned long _musb) | |||
415 | 461 | ||
416 | spin_lock_irqsave(&musb->lock, flags); | 462 | spin_lock_irqsave(&musb->lock, flags); |
417 | 463 | ||
418 | switch (musb->xceiv->state) { | 464 | switch (musb->xceiv->otg->state) { |
419 | case OTG_STATE_A_WAIT_BCON: | 465 | case OTG_STATE_A_WAIT_BCON: |
420 | if ((musb->a_wait_bcon != 0) | 466 | if ((musb->a_wait_bcon != 0) |
421 | && (musb->idle_timeout == 0 | 467 | && (musb->idle_timeout == 0 |
422 | || time_after(jiffies, musb->idle_timeout))) { | 468 | || time_after(jiffies, musb->idle_timeout))) { |
423 | dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n", | 469 | dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n", |
424 | usb_otg_state_string(musb->xceiv->state)); | 470 | usb_otg_state_string(musb->xceiv->otg->state)); |
425 | } | 471 | } |
426 | /* FALLTHROUGH */ | 472 | /* FALLTHROUGH */ |
427 | case OTG_STATE_A_IDLE: | 473 | case OTG_STATE_A_IDLE: |
@@ -474,9 +520,9 @@ static void tusb_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
474 | 520 | ||
475 | /* Never idle if active, or when VBUS timeout is not set as host */ | 521 | /* Never idle if active, or when VBUS timeout is not set as host */ |
476 | if (musb->is_active || ((musb->a_wait_bcon == 0) | 522 | if (musb->is_active || ((musb->a_wait_bcon == 0) |
477 | && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { | 523 | && (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON))) { |
478 | dev_dbg(musb->controller, "%s active, deleting timer\n", | 524 | dev_dbg(musb->controller, "%s active, deleting timer\n", |
479 | usb_otg_state_string(musb->xceiv->state)); | 525 | usb_otg_state_string(musb->xceiv->otg->state)); |
480 | del_timer(&musb_idle_timer); | 526 | del_timer(&musb_idle_timer); |
481 | last_timer = jiffies; | 527 | last_timer = jiffies; |
482 | return; | 528 | return; |
@@ -493,7 +539,7 @@ static void tusb_musb_try_idle(struct musb *musb, unsigned long timeout) | |||
493 | last_timer = timeout; | 539 | last_timer = timeout; |
494 | 540 | ||
495 | dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", | 541 | dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", |
496 | usb_otg_state_string(musb->xceiv->state), | 542 | usb_otg_state_string(musb->xceiv->otg->state), |
497 | (unsigned long)jiffies_to_msecs(timeout - jiffies)); | 543 | (unsigned long)jiffies_to_msecs(timeout - jiffies)); |
498 | mod_timer(&musb_idle_timer, timeout); | 544 | mod_timer(&musb_idle_timer, timeout); |
499 | } | 545 | } |
@@ -524,7 +570,7 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on) | |||
524 | if (is_on) { | 570 | if (is_on) { |
525 | timer = OTG_TIMER_MS(OTG_TIME_A_WAIT_VRISE); | 571 | timer = OTG_TIMER_MS(OTG_TIME_A_WAIT_VRISE); |
526 | otg->default_a = 1; | 572 | otg->default_a = 1; |
527 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 573 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
528 | devctl |= MUSB_DEVCTL_SESSION; | 574 | devctl |= MUSB_DEVCTL_SESSION; |
529 | 575 | ||
530 | conf |= TUSB_DEV_CONF_USB_HOST_MODE; | 576 | conf |= TUSB_DEV_CONF_USB_HOST_MODE; |
@@ -537,16 +583,16 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on) | |||
537 | /* If ID pin is grounded, we want to be a_idle */ | 583 | /* If ID pin is grounded, we want to be a_idle */ |
538 | otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT); | 584 | otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT); |
539 | if (!(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS)) { | 585 | if (!(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS)) { |
540 | switch (musb->xceiv->state) { | 586 | switch (musb->xceiv->otg->state) { |
541 | case OTG_STATE_A_WAIT_VRISE: | 587 | case OTG_STATE_A_WAIT_VRISE: |
542 | case OTG_STATE_A_WAIT_BCON: | 588 | case OTG_STATE_A_WAIT_BCON: |
543 | musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; | 589 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; |
544 | break; | 590 | break; |
545 | case OTG_STATE_A_WAIT_VFALL: | 591 | case OTG_STATE_A_WAIT_VFALL: |
546 | musb->xceiv->state = OTG_STATE_A_IDLE; | 592 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
547 | break; | 593 | break; |
548 | default: | 594 | default: |
549 | musb->xceiv->state = OTG_STATE_A_IDLE; | 595 | musb->xceiv->otg->state = OTG_STATE_A_IDLE; |
550 | } | 596 | } |
551 | musb->is_active = 0; | 597 | musb->is_active = 0; |
552 | otg->default_a = 1; | 598 | otg->default_a = 1; |
@@ -554,7 +600,7 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on) | |||
554 | } else { | 600 | } else { |
555 | musb->is_active = 0; | 601 | musb->is_active = 0; |
556 | otg->default_a = 0; | 602 | otg->default_a = 0; |
557 | musb->xceiv->state = OTG_STATE_B_IDLE; | 603 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
558 | MUSB_DEV_MODE(musb); | 604 | MUSB_DEV_MODE(musb); |
559 | } | 605 | } |
560 | 606 | ||
@@ -569,7 +615,7 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on) | |||
569 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | 615 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
570 | 616 | ||
571 | dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n", | 617 | dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n", |
572 | usb_otg_state_string(musb->xceiv->state), | 618 | usb_otg_state_string(musb->xceiv->otg->state), |
573 | musb_readb(musb->mregs, MUSB_DEVCTL), | 619 | musb_readb(musb->mregs, MUSB_DEVCTL), |
574 | musb_readl(tbase, TUSB_DEV_OTG_STAT), | 620 | musb_readl(tbase, TUSB_DEV_OTG_STAT), |
575 | conf, prcm); | 621 | conf, prcm); |
@@ -668,23 +714,23 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase) | |||
668 | 714 | ||
669 | if (otg_stat & TUSB_DEV_OTG_STAT_SESS_END) { | 715 | if (otg_stat & TUSB_DEV_OTG_STAT_SESS_END) { |
670 | dev_dbg(musb->controller, "Forcing disconnect (no interrupt)\n"); | 716 | dev_dbg(musb->controller, "Forcing disconnect (no interrupt)\n"); |
671 | if (musb->xceiv->state != OTG_STATE_B_IDLE) { | 717 | if (musb->xceiv->otg->state != OTG_STATE_B_IDLE) { |
672 | /* INTR_DISCONNECT can hide... */ | 718 | /* INTR_DISCONNECT can hide... */ |
673 | musb->xceiv->state = OTG_STATE_B_IDLE; | 719 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
674 | musb->int_usb |= MUSB_INTR_DISCONNECT; | 720 | musb->int_usb |= MUSB_INTR_DISCONNECT; |
675 | } | 721 | } |
676 | musb->is_active = 0; | 722 | musb->is_active = 0; |
677 | } | 723 | } |
678 | dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", | 724 | dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", |
679 | usb_otg_state_string(musb->xceiv->state), otg_stat); | 725 | usb_otg_state_string(musb->xceiv->otg->state), otg_stat); |
680 | idle_timeout = jiffies + (1 * HZ); | 726 | idle_timeout = jiffies + (1 * HZ); |
681 | schedule_work(&musb->irq_work); | 727 | schedule_work(&musb->irq_work); |
682 | 728 | ||
683 | } else /* A-dev state machine */ { | 729 | } else /* A-dev state machine */ { |
684 | dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", | 730 | dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", |
685 | usb_otg_state_string(musb->xceiv->state), otg_stat); | 731 | usb_otg_state_string(musb->xceiv->otg->state), otg_stat); |
686 | 732 | ||
687 | switch (musb->xceiv->state) { | 733 | switch (musb->xceiv->otg->state) { |
688 | case OTG_STATE_A_IDLE: | 734 | case OTG_STATE_A_IDLE: |
689 | dev_dbg(musb->controller, "Got SRP, turning on VBUS\n"); | 735 | dev_dbg(musb->controller, "Got SRP, turning on VBUS\n"); |
690 | musb_platform_set_vbus(musb, 1); | 736 | musb_platform_set_vbus(musb, 1); |
@@ -731,9 +777,9 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase) | |||
731 | u8 devctl; | 777 | u8 devctl; |
732 | 778 | ||
733 | dev_dbg(musb->controller, "%s timer, %03x\n", | 779 | dev_dbg(musb->controller, "%s timer, %03x\n", |
734 | usb_otg_state_string(musb->xceiv->state), otg_stat); | 780 | usb_otg_state_string(musb->xceiv->otg->state), otg_stat); |
735 | 781 | ||
736 | switch (musb->xceiv->state) { | 782 | switch (musb->xceiv->otg->state) { |
737 | case OTG_STATE_A_WAIT_VRISE: | 783 | case OTG_STATE_A_WAIT_VRISE: |
738 | /* VBUS has probably been valid for a while now, | 784 | /* VBUS has probably been valid for a while now, |
739 | * but may well have bounced out of range a bit | 785 | * but may well have bounced out of range a bit |
@@ -745,7 +791,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase) | |||
745 | dev_dbg(musb->controller, "devctl %02x\n", devctl); | 791 | dev_dbg(musb->controller, "devctl %02x\n", devctl); |
746 | break; | 792 | break; |
747 | } | 793 | } |
748 | musb->xceiv->state = OTG_STATE_A_WAIT_BCON; | 794 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; |
749 | musb->is_active = 0; | 795 | musb->is_active = 0; |
750 | idle_timeout = jiffies | 796 | idle_timeout = jiffies |
751 | + msecs_to_jiffies(musb->a_wait_bcon); | 797 | + msecs_to_jiffies(musb->a_wait_bcon); |
@@ -1135,9 +1181,17 @@ static int tusb_musb_exit(struct musb *musb) | |||
1135 | } | 1181 | } |
1136 | 1182 | ||
1137 | static const struct musb_platform_ops tusb_ops = { | 1183 | static const struct musb_platform_ops tusb_ops = { |
1184 | .quirks = MUSB_IN_TUSB, | ||
1138 | .init = tusb_musb_init, | 1185 | .init = tusb_musb_init, |
1139 | .exit = tusb_musb_exit, | 1186 | .exit = tusb_musb_exit, |
1140 | 1187 | ||
1188 | .ep_offset = tusb_ep_offset, | ||
1189 | .ep_select = tusb_ep_select, | ||
1190 | .fifo_offset = tusb_fifo_offset, | ||
1191 | .readb = tusb_readb, | ||
1192 | .writeb = tusb_writeb, | ||
1193 | .read_fifo = tusb_read_fifo, | ||
1194 | .write_fifo = tusb_write_fifo, | ||
1141 | .enable = tusb_musb_enable, | 1195 | .enable = tusb_musb_enable, |
1142 | .disable = tusb_musb_disable, | 1196 | .disable = tusb_musb_disable, |
1143 | 1197 | ||
@@ -1164,10 +1218,8 @@ static int tusb_probe(struct platform_device *pdev) | |||
1164 | int ret; | 1218 | int ret; |
1165 | 1219 | ||
1166 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); | 1220 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
1167 | if (!glue) { | 1221 | if (!glue) |
1168 | dev_err(&pdev->dev, "failed to allocate glue context\n"); | ||
1169 | return -ENOMEM; | 1222 | return -ENOMEM; |
1170 | } | ||
1171 | 1223 | ||
1172 | glue->dev = &pdev->dev; | 1224 | glue->dev = &pdev->dev; |
1173 | 1225 | ||
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c index dc666e96f45f..abf72728825f 100644 --- a/drivers/usb/musb/ux500.c +++ b/drivers/usb/musb/ux500.c | |||
@@ -56,7 +56,7 @@ static void ux500_musb_set_vbus(struct musb *musb, int is_on) | |||
56 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | 56 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
57 | 57 | ||
58 | if (is_on) { | 58 | if (is_on) { |
59 | if (musb->xceiv->state == OTG_STATE_A_IDLE) { | 59 | if (musb->xceiv->otg->state == OTG_STATE_A_IDLE) { |
60 | /* start the session */ | 60 | /* start the session */ |
61 | devctl |= MUSB_DEVCTL_SESSION; | 61 | devctl |= MUSB_DEVCTL_SESSION; |
62 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | 62 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
@@ -76,7 +76,7 @@ static void ux500_musb_set_vbus(struct musb *musb, int is_on) | |||
76 | } else { | 76 | } else { |
77 | musb->is_active = 1; | 77 | musb->is_active = 1; |
78 | musb->xceiv->otg->default_a = 1; | 78 | musb->xceiv->otg->default_a = 1; |
79 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; | 79 | musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; |
80 | devctl |= MUSB_DEVCTL_SESSION; | 80 | devctl |= MUSB_DEVCTL_SESSION; |
81 | MUSB_HST_MODE(musb); | 81 | MUSB_HST_MODE(musb); |
82 | } | 82 | } |
@@ -102,7 +102,7 @@ static void ux500_musb_set_vbus(struct musb *musb, int is_on) | |||
102 | mdelay(200); | 102 | mdelay(200); |
103 | 103 | ||
104 | dev_dbg(musb->controller, "VBUS %s, devctl %02x\n", | 104 | dev_dbg(musb->controller, "VBUS %s, devctl %02x\n", |
105 | usb_otg_state_string(musb->xceiv->state), | 105 | usb_otg_state_string(musb->xceiv->otg->state), |
106 | musb_readb(musb->mregs, MUSB_DEVCTL)); | 106 | musb_readb(musb->mregs, MUSB_DEVCTL)); |
107 | } | 107 | } |
108 | 108 | ||
@@ -112,7 +112,7 @@ static int musb_otg_notifications(struct notifier_block *nb, | |||
112 | struct musb *musb = container_of(nb, struct musb, nb); | 112 | struct musb *musb = container_of(nb, struct musb, nb); |
113 | 113 | ||
114 | dev_dbg(musb->controller, "musb_otg_notifications %ld %s\n", | 114 | dev_dbg(musb->controller, "musb_otg_notifications %ld %s\n", |
115 | event, usb_otg_state_string(musb->xceiv->state)); | 115 | event, usb_otg_state_string(musb->xceiv->otg->state)); |
116 | 116 | ||
117 | switch (event) { | 117 | switch (event) { |
118 | case UX500_MUSB_ID: | 118 | case UX500_MUSB_ID: |
@@ -127,7 +127,7 @@ static int musb_otg_notifications(struct notifier_block *nb, | |||
127 | if (is_host_active(musb)) | 127 | if (is_host_active(musb)) |
128 | ux500_musb_set_vbus(musb, 0); | 128 | ux500_musb_set_vbus(musb, 0); |
129 | else | 129 | else |
130 | musb->xceiv->state = OTG_STATE_B_IDLE; | 130 | musb->xceiv->otg->state = OTG_STATE_B_IDLE; |
131 | break; | 131 | break; |
132 | default: | 132 | default: |
133 | dev_dbg(musb->controller, "ID float\n"); | 133 | dev_dbg(musb->controller, "ID float\n"); |
@@ -188,8 +188,10 @@ static int ux500_musb_exit(struct musb *musb) | |||
188 | } | 188 | } |
189 | 189 | ||
190 | static const struct musb_platform_ops ux500_ops = { | 190 | static const struct musb_platform_ops ux500_ops = { |
191 | .quirks = MUSB_INDEXED_EP, | ||
191 | .init = ux500_musb_init, | 192 | .init = ux500_musb_init, |
192 | .exit = ux500_musb_exit, | 193 | .exit = ux500_musb_exit, |
194 | .fifo_mode = 5, | ||
193 | 195 | ||
194 | .set_vbus = ux500_musb_set_vbus, | 196 | .set_vbus = ux500_musb_set_vbus, |
195 | }; | 197 | }; |
@@ -247,10 +249,8 @@ static int ux500_probe(struct platform_device *pdev) | |||
247 | } | 249 | } |
248 | 250 | ||
249 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); | 251 | glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); |
250 | if (!glue) { | 252 | if (!glue) |
251 | dev_err(&pdev->dev, "failed to allocate glue context\n"); | ||
252 | goto err0; | 253 | goto err0; |
253 | } | ||
254 | 254 | ||
255 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); | 255 | musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); |
256 | if (!musb) { | 256 | if (!musb) { |
diff --git a/drivers/usb/musb/ux500_dma.c b/drivers/usb/musb/ux500_dma.c index 221faed9f074..e93845c26bdb 100644 --- a/drivers/usb/musb/ux500_dma.c +++ b/drivers/usb/musb/ux500_dma.c | |||
@@ -91,9 +91,9 @@ static bool ux500_configure_channel(struct dma_channel *channel, | |||
91 | struct scatterlist sg; | 91 | struct scatterlist sg; |
92 | struct dma_slave_config slave_conf; | 92 | struct dma_slave_config slave_conf; |
93 | enum dma_slave_buswidth addr_width; | 93 | enum dma_slave_buswidth addr_width; |
94 | dma_addr_t usb_fifo_addr = (MUSB_FIFO_OFFSET(hw_ep->epnum) + | ||
95 | ux500_channel->controller->phy_base); | ||
96 | struct musb *musb = ux500_channel->controller->private_data; | 94 | struct musb *musb = ux500_channel->controller->private_data; |
95 | dma_addr_t usb_fifo_addr = (musb->io.fifo_offset(hw_ep->epnum) + | ||
96 | ux500_channel->controller->phy_base); | ||
97 | 97 | ||
98 | dev_dbg(musb->controller, | 98 | dev_dbg(musb->controller, |
99 | "packet_sz=%d, mode=%d, dma_addr=0x%llx, len=%d is_tx=%d\n", | 99 | "packet_sz=%d, mode=%d, dma_addr=0x%llx, len=%d is_tx=%d\n", |
@@ -121,8 +121,7 @@ static bool ux500_configure_channel(struct dma_channel *channel, | |||
121 | slave_conf.dst_maxburst = 16; | 121 | slave_conf.dst_maxburst = 16; |
122 | slave_conf.device_fc = false; | 122 | slave_conf.device_fc = false; |
123 | 123 | ||
124 | dma_chan->device->device_control(dma_chan, DMA_SLAVE_CONFIG, | 124 | dmaengine_slave_config(dma_chan, &slave_conf); |
125 | (unsigned long) &slave_conf); | ||
126 | 125 | ||
127 | dma_desc = dmaengine_prep_slave_sg(dma_chan, &sg, 1, direction, | 126 | dma_desc = dmaengine_prep_slave_sg(dma_chan, &sg, 1, direction, |
128 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | 127 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
@@ -246,9 +245,7 @@ static int ux500_dma_channel_abort(struct dma_channel *channel) | |||
246 | musb_writew(epio, MUSB_RXCSR, csr); | 245 | musb_writew(epio, MUSB_RXCSR, csr); |
247 | } | 246 | } |
248 | 247 | ||
249 | ux500_channel->dma_chan->device-> | 248 | dmaengine_terminate_all(ux500_channel->dma_chan); |
250 | device_control(ux500_channel->dma_chan, | ||
251 | DMA_TERMINATE_ALL, 0); | ||
252 | channel->status = MUSB_DMA_STATUS_FREE; | 249 | channel->status = MUSB_DMA_STATUS_FREE; |
253 | } | 250 | } |
254 | return 0; | 251 | return 0; |
diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c index 11ab2c45e462..8cd7d193c2ca 100644 --- a/drivers/usb/phy/phy-ab8500-usb.c +++ b/drivers/usb/phy/phy-ab8500-usb.c | |||
@@ -1,6 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * drivers/usb/otg/ab8500_usb.c | ||
3 | * | ||
4 | * USB transceiver driver for AB8500 family chips | 2 | * USB transceiver driver for AB8500 family chips |
5 | * | 3 | * |
6 | * Copyright (C) 2010-2013 ST-Ericsson AB | 4 | * Copyright (C) 2010-2013 ST-Ericsson AB |
@@ -446,7 +444,8 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, | |||
446 | if (event != UX500_MUSB_RIDB) | 444 | if (event != UX500_MUSB_RIDB) |
447 | event = UX500_MUSB_NONE; | 445 | event = UX500_MUSB_NONE; |
448 | /* Fallback to default B_IDLE as nothing is connected. */ | 446 | /* Fallback to default B_IDLE as nothing is connected. */ |
449 | ab->phy.state = OTG_STATE_B_IDLE; | 447 | ab->phy.otg->state = OTG_STATE_B_IDLE; |
448 | usb_phy_set_event(&ab->phy, USB_EVENT_NONE); | ||
450 | break; | 449 | break; |
451 | 450 | ||
452 | case USB_LINK_ACA_RID_C_NM_9540: | 451 | case USB_LINK_ACA_RID_C_NM_9540: |
@@ -461,12 +460,14 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, | |||
461 | ab8500_usb_peri_phy_en(ab); | 460 | ab8500_usb_peri_phy_en(ab); |
462 | atomic_notifier_call_chain(&ab->phy.notifier, | 461 | atomic_notifier_call_chain(&ab->phy.notifier, |
463 | UX500_MUSB_PREPARE, &ab->vbus_draw); | 462 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
463 | usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED); | ||
464 | } | 464 | } |
465 | if (ab->mode == USB_IDLE) { | 465 | if (ab->mode == USB_IDLE) { |
466 | ab->mode = USB_PERIPHERAL; | 466 | ab->mode = USB_PERIPHERAL; |
467 | ab8500_usb_peri_phy_en(ab); | 467 | ab8500_usb_peri_phy_en(ab); |
468 | atomic_notifier_call_chain(&ab->phy.notifier, | 468 | atomic_notifier_call_chain(&ab->phy.notifier, |
469 | UX500_MUSB_PREPARE, &ab->vbus_draw); | 469 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
470 | usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED); | ||
470 | } | 471 | } |
471 | if (event != UX500_MUSB_RIDC) | 472 | if (event != UX500_MUSB_RIDC) |
472 | event = UX500_MUSB_VBUS; | 473 | event = UX500_MUSB_VBUS; |
@@ -502,6 +503,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, | |||
502 | event = UX500_MUSB_CHARGER; | 503 | event = UX500_MUSB_CHARGER; |
503 | atomic_notifier_call_chain(&ab->phy.notifier, | 504 | atomic_notifier_call_chain(&ab->phy.notifier, |
504 | event, &ab->vbus_draw); | 505 | event, &ab->vbus_draw); |
506 | usb_phy_set_event(&ab->phy, USB_EVENT_CHARGER); | ||
505 | break; | 507 | break; |
506 | 508 | ||
507 | case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540: | 509 | case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540: |
@@ -526,6 +528,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, | |||
526 | ab->mode = USB_IDLE; | 528 | ab->mode = USB_IDLE; |
527 | ab->phy.otg->default_a = false; | 529 | ab->phy.otg->default_a = false; |
528 | ab->vbus_draw = 0; | 530 | ab->vbus_draw = 0; |
531 | usb_phy_set_event(&ab->phy, USB_EVENT_NONE); | ||
529 | } | 532 | } |
530 | } | 533 | } |
531 | break; | 534 | break; |
@@ -584,7 +587,8 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, | |||
584 | * Fallback to default B_IDLE as nothing | 587 | * Fallback to default B_IDLE as nothing |
585 | * is connected | 588 | * is connected |
586 | */ | 589 | */ |
587 | ab->phy.state = OTG_STATE_B_IDLE; | 590 | ab->phy.otg->state = OTG_STATE_B_IDLE; |
591 | usb_phy_set_event(&ab->phy, USB_EVENT_NONE); | ||
588 | break; | 592 | break; |
589 | 593 | ||
590 | case USB_LINK_ACA_RID_C_NM_8540: | 594 | case USB_LINK_ACA_RID_C_NM_8540: |
@@ -598,6 +602,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, | |||
598 | ab8500_usb_peri_phy_en(ab); | 602 | ab8500_usb_peri_phy_en(ab); |
599 | atomic_notifier_call_chain(&ab->phy.notifier, | 603 | atomic_notifier_call_chain(&ab->phy.notifier, |
600 | UX500_MUSB_PREPARE, &ab->vbus_draw); | 604 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
605 | usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED); | ||
601 | } | 606 | } |
602 | if (event != UX500_MUSB_RIDC) | 607 | if (event != UX500_MUSB_RIDC) |
603 | event = UX500_MUSB_VBUS; | 608 | event = UX500_MUSB_VBUS; |
@@ -626,6 +631,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, | |||
626 | event = UX500_MUSB_CHARGER; | 631 | event = UX500_MUSB_CHARGER; |
627 | atomic_notifier_call_chain(&ab->phy.notifier, | 632 | atomic_notifier_call_chain(&ab->phy.notifier, |
628 | event, &ab->vbus_draw); | 633 | event, &ab->vbus_draw); |
634 | usb_phy_set_event(&ab->phy, USB_EVENT_CHARGER); | ||
629 | break; | 635 | break; |
630 | 636 | ||
631 | case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540: | 637 | case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540: |
@@ -648,6 +654,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, | |||
648 | ab->mode = USB_IDLE; | 654 | ab->mode = USB_IDLE; |
649 | ab->phy.otg->default_a = false; | 655 | ab->phy.otg->default_a = false; |
650 | ab->vbus_draw = 0; | 656 | ab->vbus_draw = 0; |
657 | usb_phy_set_event(&ab->phy, USB_EVENT_NONE); | ||
651 | } | 658 | } |
652 | break; | 659 | break; |
653 | 660 | ||
@@ -693,7 +700,8 @@ static int ab8505_usb_link_status_update(struct ab8500_usb *ab, | |||
693 | * Fallback to default B_IDLE as nothing | 700 | * Fallback to default B_IDLE as nothing |
694 | * is connected | 701 | * is connected |
695 | */ | 702 | */ |
696 | ab->phy.state = OTG_STATE_B_IDLE; | 703 | ab->phy.otg->state = OTG_STATE_B_IDLE; |
704 | usb_phy_set_event(&ab->phy, USB_EVENT_NONE); | ||
697 | break; | 705 | break; |
698 | 706 | ||
699 | case USB_LINK_ACA_RID_C_NM_8505: | 707 | case USB_LINK_ACA_RID_C_NM_8505: |
@@ -707,6 +715,7 @@ static int ab8505_usb_link_status_update(struct ab8500_usb *ab, | |||
707 | ab8500_usb_peri_phy_en(ab); | 715 | ab8500_usb_peri_phy_en(ab); |
708 | atomic_notifier_call_chain(&ab->phy.notifier, | 716 | atomic_notifier_call_chain(&ab->phy.notifier, |
709 | UX500_MUSB_PREPARE, &ab->vbus_draw); | 717 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
718 | usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED); | ||
710 | } | 719 | } |
711 | if (event != UX500_MUSB_RIDC) | 720 | if (event != UX500_MUSB_RIDC) |
712 | event = UX500_MUSB_VBUS; | 721 | event = UX500_MUSB_VBUS; |
@@ -734,6 +743,7 @@ static int ab8505_usb_link_status_update(struct ab8500_usb *ab, | |||
734 | event = UX500_MUSB_CHARGER; | 743 | event = UX500_MUSB_CHARGER; |
735 | atomic_notifier_call_chain(&ab->phy.notifier, | 744 | atomic_notifier_call_chain(&ab->phy.notifier, |
736 | event, &ab->vbus_draw); | 745 | event, &ab->vbus_draw); |
746 | usb_phy_set_event(&ab->phy, USB_EVENT_CHARGER); | ||
737 | break; | 747 | break; |
738 | 748 | ||
739 | default: | 749 | default: |
@@ -776,7 +786,8 @@ static int ab8500_usb_link_status_update(struct ab8500_usb *ab, | |||
776 | if (event != UX500_MUSB_RIDB) | 786 | if (event != UX500_MUSB_RIDB) |
777 | event = UX500_MUSB_NONE; | 787 | event = UX500_MUSB_NONE; |
778 | /* Fallback to default B_IDLE as nothing is connected */ | 788 | /* Fallback to default B_IDLE as nothing is connected */ |
779 | ab->phy.state = OTG_STATE_B_IDLE; | 789 | ab->phy.otg->state = OTG_STATE_B_IDLE; |
790 | usb_phy_set_event(&ab->phy, USB_EVENT_NONE); | ||
780 | break; | 791 | break; |
781 | 792 | ||
782 | case USB_LINK_ACA_RID_C_NM_8500: | 793 | case USB_LINK_ACA_RID_C_NM_8500: |
@@ -794,6 +805,7 @@ static int ab8500_usb_link_status_update(struct ab8500_usb *ab, | |||
794 | ab8500_usb_peri_phy_en(ab); | 805 | ab8500_usb_peri_phy_en(ab); |
795 | atomic_notifier_call_chain(&ab->phy.notifier, | 806 | atomic_notifier_call_chain(&ab->phy.notifier, |
796 | UX500_MUSB_PREPARE, &ab->vbus_draw); | 807 | UX500_MUSB_PREPARE, &ab->vbus_draw); |
808 | usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED); | ||
797 | } | 809 | } |
798 | if (event != UX500_MUSB_RIDC) | 810 | if (event != UX500_MUSB_RIDC) |
799 | event = UX500_MUSB_VBUS; | 811 | event = UX500_MUSB_VBUS; |
@@ -820,6 +832,7 @@ static int ab8500_usb_link_status_update(struct ab8500_usb *ab, | |||
820 | event = UX500_MUSB_CHARGER; | 832 | event = UX500_MUSB_CHARGER; |
821 | atomic_notifier_call_chain(&ab->phy.notifier, | 833 | atomic_notifier_call_chain(&ab->phy.notifier, |
822 | event, &ab->vbus_draw); | 834 | event, &ab->vbus_draw); |
835 | usb_phy_set_event(&ab->phy, USB_EVENT_CHARGER); | ||
823 | break; | 836 | break; |
824 | 837 | ||
825 | case USB_LINK_RESERVED_8500: | 838 | case USB_LINK_RESERVED_8500: |
@@ -1056,7 +1069,7 @@ static int ab8500_usb_set_peripheral(struct usb_otg *otg, | |||
1056 | if (!otg) | 1069 | if (!otg) |
1057 | return -ENODEV; | 1070 | return -ENODEV; |
1058 | 1071 | ||
1059 | ab = phy_to_ab(otg->phy); | 1072 | ab = phy_to_ab(otg->usb_phy); |
1060 | 1073 | ||
1061 | ab->phy.otg->gadget = gadget; | 1074 | ab->phy.otg->gadget = gadget; |
1062 | 1075 | ||
@@ -1080,7 +1093,7 @@ static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
1080 | if (!otg) | 1093 | if (!otg) |
1081 | return -ENODEV; | 1094 | return -ENODEV; |
1082 | 1095 | ||
1083 | ab = phy_to_ab(otg->phy); | 1096 | ab = phy_to_ab(otg->usb_phy); |
1084 | 1097 | ||
1085 | ab->phy.otg->host = host; | 1098 | ab->phy.otg->host = host; |
1086 | 1099 | ||
@@ -1380,9 +1393,9 @@ static int ab8500_usb_probe(struct platform_device *pdev) | |||
1380 | ab->phy.label = "ab8500"; | 1393 | ab->phy.label = "ab8500"; |
1381 | ab->phy.set_suspend = ab8500_usb_set_suspend; | 1394 | ab->phy.set_suspend = ab8500_usb_set_suspend; |
1382 | ab->phy.set_power = ab8500_usb_set_power; | 1395 | ab->phy.set_power = ab8500_usb_set_power; |
1383 | ab->phy.state = OTG_STATE_UNDEFINED; | 1396 | ab->phy.otg->state = OTG_STATE_UNDEFINED; |
1384 | 1397 | ||
1385 | otg->phy = &ab->phy; | 1398 | otg->usb_phy = &ab->phy; |
1386 | otg->set_host = ab8500_usb_set_host; | 1399 | otg->set_host = ab8500_usb_set_host; |
1387 | otg->set_peripheral = ab8500_usb_set_peripheral; | 1400 | otg->set_peripheral = ab8500_usb_set_peripheral; |
1388 | 1401 | ||
diff --git a/drivers/usb/phy/phy-am335x-control.c b/drivers/usb/phy/phy-am335x-control.c index 35b6083b7999..2e923c581809 100644 --- a/drivers/usb/phy/phy-am335x-control.c +++ b/drivers/usb/phy/phy-am335x-control.c | |||
@@ -147,10 +147,8 @@ static int am335x_control_usb_probe(struct platform_device *pdev) | |||
147 | phy_ctrl = of_id->data; | 147 | phy_ctrl = of_id->data; |
148 | 148 | ||
149 | ctrl_usb = devm_kzalloc(&pdev->dev, sizeof(*ctrl_usb), GFP_KERNEL); | 149 | ctrl_usb = devm_kzalloc(&pdev->dev, sizeof(*ctrl_usb), GFP_KERNEL); |
150 | if (!ctrl_usb) { | 150 | if (!ctrl_usb) |
151 | dev_err(&pdev->dev, "unable to alloc memory for control usb\n"); | ||
152 | return -ENOMEM; | 151 | return -ENOMEM; |
153 | } | ||
154 | 152 | ||
155 | ctrl_usb->dev = &pdev->dev; | 153 | ctrl_usb->dev = &pdev->dev; |
156 | 154 | ||
diff --git a/drivers/usb/phy/phy-fsl-usb.c b/drivers/usb/phy/phy-fsl-usb.c index f1ea5990a50a..ab38aa32a6c1 100644 --- a/drivers/usb/phy/phy-fsl-usb.c +++ b/drivers/usb/phy/phy-fsl-usb.c | |||
@@ -274,7 +274,7 @@ void b_srp_end(unsigned long foo) | |||
274 | fsl_otg_dischrg_vbus(0); | 274 | fsl_otg_dischrg_vbus(0); |
275 | srp_wait_done = 1; | 275 | srp_wait_done = 1; |
276 | 276 | ||
277 | if ((fsl_otg_dev->phy.state == OTG_STATE_B_SRP_INIT) && | 277 | if ((fsl_otg_dev->phy.otg->state == OTG_STATE_B_SRP_INIT) && |
278 | fsl_otg_dev->fsm.b_sess_vld) | 278 | fsl_otg_dev->fsm.b_sess_vld) |
279 | fsl_otg_dev->fsm.b_srp_done = 1; | 279 | fsl_otg_dev->fsm.b_srp_done = 1; |
280 | } | 280 | } |
@@ -499,7 +499,8 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on) | |||
499 | { | 499 | { |
500 | struct usb_otg *otg = fsm->otg; | 500 | struct usb_otg *otg = fsm->otg; |
501 | struct device *dev; | 501 | struct device *dev; |
502 | struct fsl_otg *otg_dev = container_of(otg->phy, struct fsl_otg, phy); | 502 | struct fsl_otg *otg_dev = |
503 | container_of(otg->usb_phy, struct fsl_otg, phy); | ||
503 | u32 retval = 0; | 504 | u32 retval = 0; |
504 | 505 | ||
505 | if (!otg->host) | 506 | if (!otg->host) |
@@ -594,7 +595,7 @@ static int fsl_otg_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
594 | if (!otg) | 595 | if (!otg) |
595 | return -ENODEV; | 596 | return -ENODEV; |
596 | 597 | ||
597 | otg_dev = container_of(otg->phy, struct fsl_otg, phy); | 598 | otg_dev = container_of(otg->usb_phy, struct fsl_otg, phy); |
598 | if (otg_dev != fsl_otg_dev) | 599 | if (otg_dev != fsl_otg_dev) |
599 | return -ENODEV; | 600 | return -ENODEV; |
600 | 601 | ||
@@ -623,7 +624,7 @@ static int fsl_otg_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
623 | /* Mini-A cable connected */ | 624 | /* Mini-A cable connected */ |
624 | struct otg_fsm *fsm = &otg_dev->fsm; | 625 | struct otg_fsm *fsm = &otg_dev->fsm; |
625 | 626 | ||
626 | otg->phy->state = OTG_STATE_UNDEFINED; | 627 | otg->state = OTG_STATE_UNDEFINED; |
627 | fsm->protocol = PROTO_UNDEF; | 628 | fsm->protocol = PROTO_UNDEF; |
628 | } | 629 | } |
629 | } | 630 | } |
@@ -644,7 +645,7 @@ static int fsl_otg_set_peripheral(struct usb_otg *otg, | |||
644 | if (!otg) | 645 | if (!otg) |
645 | return -ENODEV; | 646 | return -ENODEV; |
646 | 647 | ||
647 | otg_dev = container_of(otg->phy, struct fsl_otg, phy); | 648 | otg_dev = container_of(otg->usb_phy, struct fsl_otg, phy); |
648 | VDBG("otg_dev 0x%x\n", (int)otg_dev); | 649 | VDBG("otg_dev 0x%x\n", (int)otg_dev); |
649 | VDBG("fsl_otg_dev 0x%x\n", (int)fsl_otg_dev); | 650 | VDBG("fsl_otg_dev 0x%x\n", (int)fsl_otg_dev); |
650 | if (otg_dev != fsl_otg_dev) | 651 | if (otg_dev != fsl_otg_dev) |
@@ -681,7 +682,7 @@ static int fsl_otg_set_power(struct usb_phy *phy, unsigned mA) | |||
681 | { | 682 | { |
682 | if (!fsl_otg_dev) | 683 | if (!fsl_otg_dev) |
683 | return -ENODEV; | 684 | return -ENODEV; |
684 | if (phy->state == OTG_STATE_B_PERIPHERAL) | 685 | if (phy->otg->state == OTG_STATE_B_PERIPHERAL) |
685 | pr_info("FSL OTG: Draw %d mA\n", mA); | 686 | pr_info("FSL OTG: Draw %d mA\n", mA); |
686 | 687 | ||
687 | return 0; | 688 | return 0; |
@@ -714,10 +715,10 @@ static int fsl_otg_start_srp(struct usb_otg *otg) | |||
714 | { | 715 | { |
715 | struct fsl_otg *otg_dev; | 716 | struct fsl_otg *otg_dev; |
716 | 717 | ||
717 | if (!otg || otg->phy->state != OTG_STATE_B_IDLE) | 718 | if (!otg || otg->state != OTG_STATE_B_IDLE) |
718 | return -ENODEV; | 719 | return -ENODEV; |
719 | 720 | ||
720 | otg_dev = container_of(otg->phy, struct fsl_otg, phy); | 721 | otg_dev = container_of(otg->usb_phy, struct fsl_otg, phy); |
721 | if (otg_dev != fsl_otg_dev) | 722 | if (otg_dev != fsl_otg_dev) |
722 | return -ENODEV; | 723 | return -ENODEV; |
723 | 724 | ||
@@ -735,7 +736,7 @@ static int fsl_otg_start_hnp(struct usb_otg *otg) | |||
735 | if (!otg) | 736 | if (!otg) |
736 | return -ENODEV; | 737 | return -ENODEV; |
737 | 738 | ||
738 | otg_dev = container_of(otg->phy, struct fsl_otg, phy); | 739 | otg_dev = container_of(otg->usb_phy, struct fsl_otg, phy); |
739 | if (otg_dev != fsl_otg_dev) | 740 | if (otg_dev != fsl_otg_dev) |
740 | return -ENODEV; | 741 | return -ENODEV; |
741 | 742 | ||
@@ -857,7 +858,7 @@ static int fsl_otg_conf(struct platform_device *pdev) | |||
857 | fsl_otg_tc->phy.dev = &pdev->dev; | 858 | fsl_otg_tc->phy.dev = &pdev->dev; |
858 | fsl_otg_tc->phy.set_power = fsl_otg_set_power; | 859 | fsl_otg_tc->phy.set_power = fsl_otg_set_power; |
859 | 860 | ||
860 | fsl_otg_tc->phy.otg->phy = &fsl_otg_tc->phy; | 861 | fsl_otg_tc->phy.otg->usb_phy = &fsl_otg_tc->phy; |
861 | fsl_otg_tc->phy.otg->set_host = fsl_otg_set_host; | 862 | fsl_otg_tc->phy.otg->set_host = fsl_otg_set_host; |
862 | fsl_otg_tc->phy.otg->set_peripheral = fsl_otg_set_peripheral; | 863 | fsl_otg_tc->phy.otg->set_peripheral = fsl_otg_set_peripheral; |
863 | fsl_otg_tc->phy.otg->start_hnp = fsl_otg_start_hnp; | 864 | fsl_otg_tc->phy.otg->start_hnp = fsl_otg_start_hnp; |
@@ -989,10 +990,10 @@ int usb_otg_start(struct platform_device *pdev) | |||
989 | * Also: record initial state of ID pin | 990 | * Also: record initial state of ID pin |
990 | */ | 991 | */ |
991 | if (fsl_readl(&p_otg->dr_mem_map->otgsc) & OTGSC_STS_USB_ID) { | 992 | if (fsl_readl(&p_otg->dr_mem_map->otgsc) & OTGSC_STS_USB_ID) { |
992 | p_otg->phy.state = OTG_STATE_UNDEFINED; | 993 | p_otg->phy.otg->state = OTG_STATE_UNDEFINED; |
993 | p_otg->fsm.id = 1; | 994 | p_otg->fsm.id = 1; |
994 | } else { | 995 | } else { |
995 | p_otg->phy.state = OTG_STATE_A_IDLE; | 996 | p_otg->phy.otg->state = OTG_STATE_A_IDLE; |
996 | p_otg->fsm.id = 0; | 997 | p_otg->fsm.id = 0; |
997 | } | 998 | } |
998 | 999 | ||
@@ -1047,7 +1048,7 @@ static int show_fsl_usb2_otg_state(struct device *dev, | |||
1047 | /* State */ | 1048 | /* State */ |
1048 | t = scnprintf(next, size, | 1049 | t = scnprintf(next, size, |
1049 | "OTG state: %s\n\n", | 1050 | "OTG state: %s\n\n", |
1050 | usb_otg_state_string(fsl_otg_dev->phy.state)); | 1051 | usb_otg_state_string(fsl_otg_dev->phy.otg->state)); |
1051 | size -= t; | 1052 | size -= t; |
1052 | next += t; | 1053 | next += t; |
1053 | 1054 | ||
diff --git a/drivers/usb/phy/phy-fsl-usb.h b/drivers/usb/phy/phy-fsl-usb.h index 5986c96354df..23149954a09c 100644 --- a/drivers/usb/phy/phy-fsl-usb.h +++ b/drivers/usb/phy/phy-fsl-usb.h | |||
@@ -298,7 +298,7 @@ | |||
298 | /* SE0 Time Before SRP */ | 298 | /* SE0 Time Before SRP */ |
299 | #define TB_SE0_SRP (2) /* b_idle,minimum 2 ms, section:5.3.2 */ | 299 | #define TB_SE0_SRP (2) /* b_idle,minimum 2 ms, section:5.3.2 */ |
300 | 300 | ||
301 | #define SET_OTG_STATE(otg_ptr, newstate) ((otg_ptr)->state = newstate) | 301 | #define SET_OTG_STATE(phy, newstate) ((phy)->otg->state = newstate) |
302 | 302 | ||
303 | struct usb_dr_mmap { | 303 | struct usb_dr_mmap { |
304 | /* Capability register */ | 304 | /* Capability register */ |
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c index 7594e5069ae5..4ba1f57220f6 100644 --- a/drivers/usb/phy/phy-generic.c +++ b/drivers/usb/phy/phy-generic.c | |||
@@ -1,6 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * drivers/usb/otg/nop-usb-xceiv.c | ||
3 | * | ||
4 | * NOP USB transceiver for all USB transceiver which are either built-in | 2 | * NOP USB transceiver for all USB transceiver which are either built-in |
5 | * into USB IP or which are mostly autonomous. | 3 | * into USB IP or which are mostly autonomous. |
6 | * | 4 | * |
@@ -123,7 +121,7 @@ static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) | |||
123 | } | 121 | } |
124 | 122 | ||
125 | otg->gadget = gadget; | 123 | otg->gadget = gadget; |
126 | otg->phy->state = OTG_STATE_B_IDLE; | 124 | otg->state = OTG_STATE_B_IDLE; |
127 | return 0; | 125 | return 0; |
128 | } | 126 | } |
129 | 127 | ||
@@ -225,10 +223,10 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop, | |||
225 | nop->phy.dev = nop->dev; | 223 | nop->phy.dev = nop->dev; |
226 | nop->phy.label = "nop-xceiv"; | 224 | nop->phy.label = "nop-xceiv"; |
227 | nop->phy.set_suspend = nop_set_suspend; | 225 | nop->phy.set_suspend = nop_set_suspend; |
228 | nop->phy.state = OTG_STATE_UNDEFINED; | ||
229 | nop->phy.type = type; | 226 | nop->phy.type = type; |
230 | 227 | ||
231 | nop->phy.otg->phy = &nop->phy; | 228 | nop->phy.otg->state = OTG_STATE_UNDEFINED; |
229 | nop->phy.otg->usb_phy = &nop->phy; | ||
232 | nop->phy.otg->set_host = nop_set_host; | 230 | nop->phy.otg->set_host = nop_set_host; |
233 | nop->phy.otg->set_peripheral = nop_set_peripheral; | 231 | nop->phy.otg->set_peripheral = nop_set_peripheral; |
234 | 232 | ||
diff --git a/drivers/usb/phy/phy-gpio-vbus-usb.c b/drivers/usb/phy/phy-gpio-vbus-usb.c index f4b14bd97e14..54511725caaf 100644 --- a/drivers/usb/phy/phy-gpio-vbus-usb.c +++ b/drivers/usb/phy/phy-gpio-vbus-usb.c | |||
@@ -121,7 +121,7 @@ static void gpio_vbus_work(struct work_struct *work) | |||
121 | 121 | ||
122 | if (vbus) { | 122 | if (vbus) { |
123 | status = USB_EVENT_VBUS; | 123 | status = USB_EVENT_VBUS; |
124 | gpio_vbus->phy.state = OTG_STATE_B_PERIPHERAL; | 124 | gpio_vbus->phy.otg->state = OTG_STATE_B_PERIPHERAL; |
125 | gpio_vbus->phy.last_event = status; | 125 | gpio_vbus->phy.last_event = status; |
126 | usb_gadget_vbus_connect(gpio_vbus->phy.otg->gadget); | 126 | usb_gadget_vbus_connect(gpio_vbus->phy.otg->gadget); |
127 | 127 | ||
@@ -134,6 +134,7 @@ static void gpio_vbus_work(struct work_struct *work) | |||
134 | 134 | ||
135 | atomic_notifier_call_chain(&gpio_vbus->phy.notifier, | 135 | atomic_notifier_call_chain(&gpio_vbus->phy.notifier, |
136 | status, gpio_vbus->phy.otg->gadget); | 136 | status, gpio_vbus->phy.otg->gadget); |
137 | usb_phy_set_event(&gpio_vbus->phy, USB_EVENT_ENUMERATED); | ||
137 | } else { | 138 | } else { |
138 | /* optionally disable D+ pullup */ | 139 | /* optionally disable D+ pullup */ |
139 | if (gpio_is_valid(gpio)) | 140 | if (gpio_is_valid(gpio)) |
@@ -143,11 +144,12 @@ static void gpio_vbus_work(struct work_struct *work) | |||
143 | 144 | ||
144 | usb_gadget_vbus_disconnect(gpio_vbus->phy.otg->gadget); | 145 | usb_gadget_vbus_disconnect(gpio_vbus->phy.otg->gadget); |
145 | status = USB_EVENT_NONE; | 146 | status = USB_EVENT_NONE; |
146 | gpio_vbus->phy.state = OTG_STATE_B_IDLE; | 147 | gpio_vbus->phy.otg->state = OTG_STATE_B_IDLE; |
147 | gpio_vbus->phy.last_event = status; | 148 | gpio_vbus->phy.last_event = status; |
148 | 149 | ||
149 | atomic_notifier_call_chain(&gpio_vbus->phy.notifier, | 150 | atomic_notifier_call_chain(&gpio_vbus->phy.notifier, |
150 | status, gpio_vbus->phy.otg->gadget); | 151 | status, gpio_vbus->phy.otg->gadget); |
152 | usb_phy_set_event(&gpio_vbus->phy, USB_EVENT_NONE); | ||
151 | } | 153 | } |
152 | } | 154 | } |
153 | 155 | ||
@@ -180,7 +182,7 @@ static int gpio_vbus_set_peripheral(struct usb_otg *otg, | |||
180 | struct platform_device *pdev; | 182 | struct platform_device *pdev; |
181 | int gpio; | 183 | int gpio; |
182 | 184 | ||
183 | gpio_vbus = container_of(otg->phy, struct gpio_vbus_data, phy); | 185 | gpio_vbus = container_of(otg->usb_phy, struct gpio_vbus_data, phy); |
184 | pdev = to_platform_device(gpio_vbus->dev); | 186 | pdev = to_platform_device(gpio_vbus->dev); |
185 | pdata = dev_get_platdata(gpio_vbus->dev); | 187 | pdata = dev_get_platdata(gpio_vbus->dev); |
186 | gpio = pdata->gpio_pullup; | 188 | gpio = pdata->gpio_pullup; |
@@ -196,7 +198,7 @@ static int gpio_vbus_set_peripheral(struct usb_otg *otg, | |||
196 | set_vbus_draw(gpio_vbus, 0); | 198 | set_vbus_draw(gpio_vbus, 0); |
197 | 199 | ||
198 | usb_gadget_vbus_disconnect(otg->gadget); | 200 | usb_gadget_vbus_disconnect(otg->gadget); |
199 | otg->phy->state = OTG_STATE_UNDEFINED; | 201 | otg->state = OTG_STATE_UNDEFINED; |
200 | 202 | ||
201 | otg->gadget = NULL; | 203 | otg->gadget = NULL; |
202 | return 0; | 204 | return 0; |
@@ -218,7 +220,7 @@ static int gpio_vbus_set_power(struct usb_phy *phy, unsigned mA) | |||
218 | 220 | ||
219 | gpio_vbus = container_of(phy, struct gpio_vbus_data, phy); | 221 | gpio_vbus = container_of(phy, struct gpio_vbus_data, phy); |
220 | 222 | ||
221 | if (phy->state == OTG_STATE_B_PERIPHERAL) | 223 | if (phy->otg->state == OTG_STATE_B_PERIPHERAL) |
222 | set_vbus_draw(gpio_vbus, mA); | 224 | set_vbus_draw(gpio_vbus, mA); |
223 | return 0; | 225 | return 0; |
224 | } | 226 | } |
@@ -269,9 +271,9 @@ static int gpio_vbus_probe(struct platform_device *pdev) | |||
269 | gpio_vbus->phy.dev = gpio_vbus->dev; | 271 | gpio_vbus->phy.dev = gpio_vbus->dev; |
270 | gpio_vbus->phy.set_power = gpio_vbus_set_power; | 272 | gpio_vbus->phy.set_power = gpio_vbus_set_power; |
271 | gpio_vbus->phy.set_suspend = gpio_vbus_set_suspend; | 273 | gpio_vbus->phy.set_suspend = gpio_vbus_set_suspend; |
272 | gpio_vbus->phy.state = OTG_STATE_UNDEFINED; | ||
273 | 274 | ||
274 | gpio_vbus->phy.otg->phy = &gpio_vbus->phy; | 275 | gpio_vbus->phy.otg->state = OTG_STATE_UNDEFINED; |
276 | gpio_vbus->phy.otg->usb_phy = &gpio_vbus->phy; | ||
275 | gpio_vbus->phy.otg->set_peripheral = gpio_vbus_set_peripheral; | 277 | gpio_vbus->phy.otg->set_peripheral = gpio_vbus_set_peripheral; |
276 | 278 | ||
277 | err = devm_gpio_request(&pdev->dev, gpio, "vbus_detect"); | 279 | err = devm_gpio_request(&pdev->dev, gpio, "vbus_detect"); |
diff --git a/drivers/usb/phy/phy-isp1301-omap.c b/drivers/usb/phy/phy-isp1301-omap.c index 8eea56d3ded6..a2dfb2ae520e 100644 --- a/drivers/usb/phy/phy-isp1301-omap.c +++ b/drivers/usb/phy/phy-isp1301-omap.c | |||
@@ -234,7 +234,7 @@ isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits) | |||
234 | 234 | ||
235 | static inline const char *state_name(struct isp1301 *isp) | 235 | static inline const char *state_name(struct isp1301 *isp) |
236 | { | 236 | { |
237 | return usb_otg_state_string(isp->phy.state); | 237 | return usb_otg_state_string(isp->phy.otg->state); |
238 | } | 238 | } |
239 | 239 | ||
240 | /*-------------------------------------------------------------------------*/ | 240 | /*-------------------------------------------------------------------------*/ |
@@ -249,7 +249,7 @@ static inline const char *state_name(struct isp1301 *isp) | |||
249 | 249 | ||
250 | static void power_down(struct isp1301 *isp) | 250 | static void power_down(struct isp1301 *isp) |
251 | { | 251 | { |
252 | isp->phy.state = OTG_STATE_UNDEFINED; | 252 | isp->phy.otg->state = OTG_STATE_UNDEFINED; |
253 | 253 | ||
254 | // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN); | 254 | // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN); |
255 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND); | 255 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND); |
@@ -339,7 +339,7 @@ static void a_idle(struct isp1301 *isp, const char *tag) | |||
339 | { | 339 | { |
340 | u32 l; | 340 | u32 l; |
341 | 341 | ||
342 | if (isp->phy.state == OTG_STATE_A_IDLE) | 342 | if (isp->phy.otg->state == OTG_STATE_A_IDLE) |
343 | return; | 343 | return; |
344 | 344 | ||
345 | isp->phy.otg->default_a = 1; | 345 | isp->phy.otg->default_a = 1; |
@@ -351,7 +351,7 @@ static void a_idle(struct isp1301 *isp, const char *tag) | |||
351 | isp->phy.otg->gadget->is_a_peripheral = 1; | 351 | isp->phy.otg->gadget->is_a_peripheral = 1; |
352 | gadget_suspend(isp); | 352 | gadget_suspend(isp); |
353 | } | 353 | } |
354 | isp->phy.state = OTG_STATE_A_IDLE; | 354 | isp->phy.otg->state = OTG_STATE_A_IDLE; |
355 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; | 355 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; |
356 | omap_writel(l, OTG_CTRL); | 356 | omap_writel(l, OTG_CTRL); |
357 | isp->last_otg_ctrl = l; | 357 | isp->last_otg_ctrl = l; |
@@ -363,7 +363,7 @@ static void b_idle(struct isp1301 *isp, const char *tag) | |||
363 | { | 363 | { |
364 | u32 l; | 364 | u32 l; |
365 | 365 | ||
366 | if (isp->phy.state == OTG_STATE_B_IDLE) | 366 | if (isp->phy.otg->state == OTG_STATE_B_IDLE) |
367 | return; | 367 | return; |
368 | 368 | ||
369 | isp->phy.otg->default_a = 0; | 369 | isp->phy.otg->default_a = 0; |
@@ -375,7 +375,7 @@ static void b_idle(struct isp1301 *isp, const char *tag) | |||
375 | isp->phy.otg->gadget->is_a_peripheral = 0; | 375 | isp->phy.otg->gadget->is_a_peripheral = 0; |
376 | gadget_suspend(isp); | 376 | gadget_suspend(isp); |
377 | } | 377 | } |
378 | isp->phy.state = OTG_STATE_B_IDLE; | 378 | isp->phy.otg->state = OTG_STATE_B_IDLE; |
379 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; | 379 | l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS; |
380 | omap_writel(l, OTG_CTRL); | 380 | omap_writel(l, OTG_CTRL); |
381 | isp->last_otg_ctrl = l; | 381 | isp->last_otg_ctrl = l; |
@@ -474,7 +474,7 @@ static void check_state(struct isp1301 *isp, const char *tag) | |||
474 | default: | 474 | default: |
475 | break; | 475 | break; |
476 | } | 476 | } |
477 | if (isp->phy.state == state && !extra) | 477 | if (isp->phy.otg->state == state && !extra) |
478 | return; | 478 | return; |
479 | pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag, | 479 | pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag, |
480 | usb_otg_state_string(state), fsm, state_name(isp), | 480 | usb_otg_state_string(state), fsm, state_name(isp), |
@@ -498,23 +498,23 @@ static void update_otg1(struct isp1301 *isp, u8 int_src) | |||
498 | 498 | ||
499 | if (int_src & INTR_SESS_VLD) | 499 | if (int_src & INTR_SESS_VLD) |
500 | otg_ctrl |= OTG_ASESSVLD; | 500 | otg_ctrl |= OTG_ASESSVLD; |
501 | else if (isp->phy.state == OTG_STATE_A_WAIT_VFALL) { | 501 | else if (isp->phy.otg->state == OTG_STATE_A_WAIT_VFALL) { |
502 | a_idle(isp, "vfall"); | 502 | a_idle(isp, "vfall"); |
503 | otg_ctrl &= ~OTG_CTRL_BITS; | 503 | otg_ctrl &= ~OTG_CTRL_BITS; |
504 | } | 504 | } |
505 | if (int_src & INTR_VBUS_VLD) | 505 | if (int_src & INTR_VBUS_VLD) |
506 | otg_ctrl |= OTG_VBUSVLD; | 506 | otg_ctrl |= OTG_VBUSVLD; |
507 | if (int_src & INTR_ID_GND) { /* default-A */ | 507 | if (int_src & INTR_ID_GND) { /* default-A */ |
508 | if (isp->phy.state == OTG_STATE_B_IDLE | 508 | if (isp->phy.otg->state == OTG_STATE_B_IDLE |
509 | || isp->phy.state | 509 | || isp->phy.otg->state |
510 | == OTG_STATE_UNDEFINED) { | 510 | == OTG_STATE_UNDEFINED) { |
511 | a_idle(isp, "init"); | 511 | a_idle(isp, "init"); |
512 | return; | 512 | return; |
513 | } | 513 | } |
514 | } else { /* default-B */ | 514 | } else { /* default-B */ |
515 | otg_ctrl |= OTG_ID; | 515 | otg_ctrl |= OTG_ID; |
516 | if (isp->phy.state == OTG_STATE_A_IDLE | 516 | if (isp->phy.otg->state == OTG_STATE_A_IDLE |
517 | || isp->phy.state == OTG_STATE_UNDEFINED) { | 517 | || isp->phy.otg->state == OTG_STATE_UNDEFINED) { |
518 | b_idle(isp, "init"); | 518 | b_idle(isp, "init"); |
519 | return; | 519 | return; |
520 | } | 520 | } |
@@ -548,14 +548,14 @@ static void otg_update_isp(struct isp1301 *isp) | |||
548 | isp->last_otg_ctrl = otg_ctrl; | 548 | isp->last_otg_ctrl = otg_ctrl; |
549 | otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS; | 549 | otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS; |
550 | 550 | ||
551 | switch (isp->phy.state) { | 551 | switch (isp->phy.otg->state) { |
552 | case OTG_STATE_B_IDLE: | 552 | case OTG_STATE_B_IDLE: |
553 | case OTG_STATE_B_PERIPHERAL: | 553 | case OTG_STATE_B_PERIPHERAL: |
554 | case OTG_STATE_B_SRP_INIT: | 554 | case OTG_STATE_B_SRP_INIT: |
555 | if (!(otg_ctrl & OTG_PULLUP)) { | 555 | if (!(otg_ctrl & OTG_PULLUP)) { |
556 | // if (otg_ctrl & OTG_B_HNPEN) { | 556 | // if (otg_ctrl & OTG_B_HNPEN) { |
557 | if (isp->phy.otg->gadget->b_hnp_enable) { | 557 | if (isp->phy.otg->gadget->b_hnp_enable) { |
558 | isp->phy.state = OTG_STATE_B_WAIT_ACON; | 558 | isp->phy.otg->state = OTG_STATE_B_WAIT_ACON; |
559 | pr_debug(" --> b_wait_acon\n"); | 559 | pr_debug(" --> b_wait_acon\n"); |
560 | } | 560 | } |
561 | goto pulldown; | 561 | goto pulldown; |
@@ -585,7 +585,7 @@ pulldown: | |||
585 | if (!(isp->phy.otg->host)) | 585 | if (!(isp->phy.otg->host)) |
586 | otg_ctrl &= ~OTG_DRV_VBUS; | 586 | otg_ctrl &= ~OTG_DRV_VBUS; |
587 | 587 | ||
588 | switch (isp->phy.state) { | 588 | switch (isp->phy.otg->state) { |
589 | case OTG_STATE_A_SUSPEND: | 589 | case OTG_STATE_A_SUSPEND: |
590 | if (otg_ctrl & OTG_DRV_VBUS) { | 590 | if (otg_ctrl & OTG_DRV_VBUS) { |
591 | set |= OTG1_VBUS_DRV; | 591 | set |= OTG1_VBUS_DRV; |
@@ -596,7 +596,7 @@ pulldown: | |||
596 | 596 | ||
597 | /* FALLTHROUGH */ | 597 | /* FALLTHROUGH */ |
598 | case OTG_STATE_A_VBUS_ERR: | 598 | case OTG_STATE_A_VBUS_ERR: |
599 | isp->phy.state = OTG_STATE_A_WAIT_VFALL; | 599 | isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL; |
600 | pr_debug(" --> a_wait_vfall\n"); | 600 | pr_debug(" --> a_wait_vfall\n"); |
601 | /* FALLTHROUGH */ | 601 | /* FALLTHROUGH */ |
602 | case OTG_STATE_A_WAIT_VFALL: | 602 | case OTG_STATE_A_WAIT_VFALL: |
@@ -605,7 +605,7 @@ pulldown: | |||
605 | break; | 605 | break; |
606 | case OTG_STATE_A_IDLE: | 606 | case OTG_STATE_A_IDLE: |
607 | if (otg_ctrl & OTG_DRV_VBUS) { | 607 | if (otg_ctrl & OTG_DRV_VBUS) { |
608 | isp->phy.state = OTG_STATE_A_WAIT_VRISE; | 608 | isp->phy.otg->state = OTG_STATE_A_WAIT_VRISE; |
609 | pr_debug(" --> a_wait_vrise\n"); | 609 | pr_debug(" --> a_wait_vrise\n"); |
610 | } | 610 | } |
611 | /* FALLTHROUGH */ | 611 | /* FALLTHROUGH */ |
@@ -625,17 +625,17 @@ pulldown: | |||
625 | if (otg_change & OTG_PULLUP) { | 625 | if (otg_change & OTG_PULLUP) { |
626 | u32 l; | 626 | u32 l; |
627 | 627 | ||
628 | switch (isp->phy.state) { | 628 | switch (isp->phy.otg->state) { |
629 | case OTG_STATE_B_IDLE: | 629 | case OTG_STATE_B_IDLE: |
630 | if (clr & OTG1_DP_PULLUP) | 630 | if (clr & OTG1_DP_PULLUP) |
631 | break; | 631 | break; |
632 | isp->phy.state = OTG_STATE_B_PERIPHERAL; | 632 | isp->phy.otg->state = OTG_STATE_B_PERIPHERAL; |
633 | pr_debug(" --> b_peripheral\n"); | 633 | pr_debug(" --> b_peripheral\n"); |
634 | break; | 634 | break; |
635 | case OTG_STATE_A_SUSPEND: | 635 | case OTG_STATE_A_SUSPEND: |
636 | if (clr & OTG1_DP_PULLUP) | 636 | if (clr & OTG1_DP_PULLUP) |
637 | break; | 637 | break; |
638 | isp->phy.state = OTG_STATE_A_PERIPHERAL; | 638 | isp->phy.otg->state = OTG_STATE_A_PERIPHERAL; |
639 | pr_debug(" --> a_peripheral\n"); | 639 | pr_debug(" --> a_peripheral\n"); |
640 | break; | 640 | break; |
641 | default: | 641 | default: |
@@ -673,7 +673,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp) | |||
673 | * remote wakeup (SRP, normal) using their own timer | 673 | * remote wakeup (SRP, normal) using their own timer |
674 | * to give "check cable and A-device" messages. | 674 | * to give "check cable and A-device" messages. |
675 | */ | 675 | */ |
676 | if (isp->phy.state == OTG_STATE_B_SRP_INIT) | 676 | if (isp->phy.otg->state == OTG_STATE_B_SRP_INIT) |
677 | b_idle(isp, "srp_timeout"); | 677 | b_idle(isp, "srp_timeout"); |
678 | 678 | ||
679 | omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC); | 679 | omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC); |
@@ -691,7 +691,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp) | |||
691 | omap_writel(otg_ctrl, OTG_CTRL); | 691 | omap_writel(otg_ctrl, OTG_CTRL); |
692 | 692 | ||
693 | /* subset of b_peripheral()... */ | 693 | /* subset of b_peripheral()... */ |
694 | isp->phy.state = OTG_STATE_B_PERIPHERAL; | 694 | isp->phy.otg->state = OTG_STATE_B_PERIPHERAL; |
695 | pr_debug(" --> b_peripheral\n"); | 695 | pr_debug(" --> b_peripheral\n"); |
696 | 696 | ||
697 | omap_writew(B_HNP_FAIL, OTG_IRQ_SRC); | 697 | omap_writew(B_HNP_FAIL, OTG_IRQ_SRC); |
@@ -703,7 +703,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp) | |||
703 | state_name(isp), omap_readl(OTG_CTRL)); | 703 | state_name(isp), omap_readl(OTG_CTRL)); |
704 | 704 | ||
705 | isp1301_defer_work(isp, WORK_UPDATE_OTG); | 705 | isp1301_defer_work(isp, WORK_UPDATE_OTG); |
706 | switch (isp->phy.state) { | 706 | switch (isp->phy.otg->state) { |
707 | case OTG_STATE_A_IDLE: | 707 | case OTG_STATE_A_IDLE: |
708 | if (!otg->host) | 708 | if (!otg->host) |
709 | break; | 709 | break; |
@@ -734,7 +734,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp) | |||
734 | otg_ctrl |= OTG_BUSDROP; | 734 | otg_ctrl |= OTG_BUSDROP; |
735 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; | 735 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; |
736 | omap_writel(otg_ctrl, OTG_CTRL); | 736 | omap_writel(otg_ctrl, OTG_CTRL); |
737 | isp->phy.state = OTG_STATE_A_WAIT_VFALL; | 737 | isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL; |
738 | 738 | ||
739 | omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC); | 739 | omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC); |
740 | ret = IRQ_HANDLED; | 740 | ret = IRQ_HANDLED; |
@@ -748,7 +748,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp) | |||
748 | otg_ctrl |= OTG_BUSDROP; | 748 | otg_ctrl |= OTG_BUSDROP; |
749 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; | 749 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; |
750 | omap_writel(otg_ctrl, OTG_CTRL); | 750 | omap_writel(otg_ctrl, OTG_CTRL); |
751 | isp->phy.state = OTG_STATE_A_VBUS_ERR; | 751 | isp->phy.otg->state = OTG_STATE_A_VBUS_ERR; |
752 | 752 | ||
753 | omap_writew(A_VBUS_ERR, OTG_IRQ_SRC); | 753 | omap_writew(A_VBUS_ERR, OTG_IRQ_SRC); |
754 | ret = IRQ_HANDLED; | 754 | ret = IRQ_HANDLED; |
@@ -769,7 +769,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp) | |||
769 | 769 | ||
770 | /* role is peripheral */ | 770 | /* role is peripheral */ |
771 | if (otg_ctrl & OTG_DRIVER_SEL) { | 771 | if (otg_ctrl & OTG_DRIVER_SEL) { |
772 | switch (isp->phy.state) { | 772 | switch (isp->phy.otg->state) { |
773 | case OTG_STATE_A_IDLE: | 773 | case OTG_STATE_A_IDLE: |
774 | b_idle(isp, __func__); | 774 | b_idle(isp, __func__); |
775 | break; | 775 | break; |
@@ -786,18 +786,18 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp) | |||
786 | } | 786 | } |
787 | 787 | ||
788 | if (otg->host) { | 788 | if (otg->host) { |
789 | switch (isp->phy.state) { | 789 | switch (isp->phy.otg->state) { |
790 | case OTG_STATE_B_WAIT_ACON: | 790 | case OTG_STATE_B_WAIT_ACON: |
791 | isp->phy.state = OTG_STATE_B_HOST; | 791 | isp->phy.otg->state = OTG_STATE_B_HOST; |
792 | pr_debug(" --> b_host\n"); | 792 | pr_debug(" --> b_host\n"); |
793 | kick = 1; | 793 | kick = 1; |
794 | break; | 794 | break; |
795 | case OTG_STATE_A_WAIT_BCON: | 795 | case OTG_STATE_A_WAIT_BCON: |
796 | isp->phy.state = OTG_STATE_A_HOST; | 796 | isp->phy.otg->state = OTG_STATE_A_HOST; |
797 | pr_debug(" --> a_host\n"); | 797 | pr_debug(" --> a_host\n"); |
798 | break; | 798 | break; |
799 | case OTG_STATE_A_PERIPHERAL: | 799 | case OTG_STATE_A_PERIPHERAL: |
800 | isp->phy.state = OTG_STATE_A_WAIT_BCON; | 800 | isp->phy.otg->state = OTG_STATE_A_WAIT_BCON; |
801 | pr_debug(" --> a_wait_bcon\n"); | 801 | pr_debug(" --> a_wait_bcon\n"); |
802 | break; | 802 | break; |
803 | default: | 803 | default: |
@@ -937,7 +937,7 @@ static void b_peripheral(struct isp1301 *isp) | |||
937 | /* UDC driver just set OTG_BSESSVLD */ | 937 | /* UDC driver just set OTG_BSESSVLD */ |
938 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP); | 938 | isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP); |
939 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN); | 939 | isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN); |
940 | isp->phy.state = OTG_STATE_B_PERIPHERAL; | 940 | isp->phy.otg->state = OTG_STATE_B_PERIPHERAL; |
941 | pr_debug(" --> b_peripheral\n"); | 941 | pr_debug(" --> b_peripheral\n"); |
942 | dump_regs(isp, "2periph"); | 942 | dump_regs(isp, "2periph"); |
943 | #endif | 943 | #endif |
@@ -947,7 +947,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat) | |||
947 | { | 947 | { |
948 | struct usb_otg *otg = isp->phy.otg; | 948 | struct usb_otg *otg = isp->phy.otg; |
949 | u8 isp_stat, isp_bstat; | 949 | u8 isp_stat, isp_bstat; |
950 | enum usb_otg_state state = isp->phy.state; | 950 | enum usb_otg_state state = isp->phy.otg->state; |
951 | 951 | ||
952 | if (stat & INTR_BDIS_ACON) | 952 | if (stat & INTR_BDIS_ACON) |
953 | pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp)); | 953 | pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp)); |
@@ -970,7 +970,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat) | |||
970 | * when HNP is used. | 970 | * when HNP is used. |
971 | */ | 971 | */ |
972 | if (isp_stat & INTR_VBUS_VLD) | 972 | if (isp_stat & INTR_VBUS_VLD) |
973 | isp->phy.state = OTG_STATE_A_HOST; | 973 | isp->phy.otg->state = OTG_STATE_A_HOST; |
974 | break; | 974 | break; |
975 | case OTG_STATE_A_WAIT_VFALL: | 975 | case OTG_STATE_A_WAIT_VFALL: |
976 | if (!(isp_stat & INTR_SESS_VLD)) | 976 | if (!(isp_stat & INTR_SESS_VLD)) |
@@ -978,7 +978,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat) | |||
978 | break; | 978 | break; |
979 | default: | 979 | default: |
980 | if (!(isp_stat & INTR_VBUS_VLD)) | 980 | if (!(isp_stat & INTR_VBUS_VLD)) |
981 | isp->phy.state = OTG_STATE_A_VBUS_ERR; | 981 | isp->phy.otg->state = OTG_STATE_A_VBUS_ERR; |
982 | break; | 982 | break; |
983 | } | 983 | } |
984 | isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS); | 984 | isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS); |
@@ -1007,7 +1007,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat) | |||
1007 | if (otg->default_a) { | 1007 | if (otg->default_a) { |
1008 | switch (state) { | 1008 | switch (state) { |
1009 | default: | 1009 | default: |
1010 | isp->phy.state = OTG_STATE_A_WAIT_VFALL; | 1010 | isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL; |
1011 | break; | 1011 | break; |
1012 | case OTG_STATE_A_WAIT_VFALL: | 1012 | case OTG_STATE_A_WAIT_VFALL: |
1013 | state = OTG_STATE_A_IDLE; | 1013 | state = OTG_STATE_A_IDLE; |
@@ -1020,7 +1020,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat) | |||
1020 | host_suspend(isp); | 1020 | host_suspend(isp); |
1021 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, | 1021 | isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, |
1022 | MC1_BDIS_ACON_EN); | 1022 | MC1_BDIS_ACON_EN); |
1023 | isp->phy.state = OTG_STATE_B_IDLE; | 1023 | isp->phy.otg->state = OTG_STATE_B_IDLE; |
1024 | l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; | 1024 | l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; |
1025 | l &= ~OTG_CTRL_BITS; | 1025 | l &= ~OTG_CTRL_BITS; |
1026 | omap_writel(l, OTG_CTRL); | 1026 | omap_writel(l, OTG_CTRL); |
@@ -1031,7 +1031,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat) | |||
1031 | } | 1031 | } |
1032 | isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS); | 1032 | isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS); |
1033 | 1033 | ||
1034 | switch (isp->phy.state) { | 1034 | switch (isp->phy.otg->state) { |
1035 | case OTG_STATE_B_PERIPHERAL: | 1035 | case OTG_STATE_B_PERIPHERAL: |
1036 | case OTG_STATE_B_WAIT_ACON: | 1036 | case OTG_STATE_B_WAIT_ACON: |
1037 | case OTG_STATE_B_HOST: | 1037 | case OTG_STATE_B_HOST: |
@@ -1071,7 +1071,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat) | |||
1071 | } | 1071 | } |
1072 | } | 1072 | } |
1073 | 1073 | ||
1074 | if (state != isp->phy.state) | 1074 | if (state != isp->phy.otg->state) |
1075 | pr_debug(" isp, %s -> %s\n", | 1075 | pr_debug(" isp, %s -> %s\n", |
1076 | usb_otg_state_string(state), state_name(isp)); | 1076 | usb_otg_state_string(state), state_name(isp)); |
1077 | 1077 | ||
@@ -1129,10 +1129,10 @@ isp1301_work(struct work_struct *work) | |||
1129 | * skip A_WAIT_VRISE; hc transitions invisibly | 1129 | * skip A_WAIT_VRISE; hc transitions invisibly |
1130 | * skip A_WAIT_BCON; same. | 1130 | * skip A_WAIT_BCON; same. |
1131 | */ | 1131 | */ |
1132 | switch (isp->phy.state) { | 1132 | switch (isp->phy.otg->state) { |
1133 | case OTG_STATE_A_WAIT_BCON: | 1133 | case OTG_STATE_A_WAIT_BCON: |
1134 | case OTG_STATE_A_WAIT_VRISE: | 1134 | case OTG_STATE_A_WAIT_VRISE: |
1135 | isp->phy.state = OTG_STATE_A_HOST; | 1135 | isp->phy.otg->state = OTG_STATE_A_HOST; |
1136 | pr_debug(" --> a_host\n"); | 1136 | pr_debug(" --> a_host\n"); |
1137 | otg_ctrl = omap_readl(OTG_CTRL); | 1137 | otg_ctrl = omap_readl(OTG_CTRL); |
1138 | otg_ctrl |= OTG_A_BUSREQ; | 1138 | otg_ctrl |= OTG_A_BUSREQ; |
@@ -1141,7 +1141,7 @@ isp1301_work(struct work_struct *work) | |||
1141 | omap_writel(otg_ctrl, OTG_CTRL); | 1141 | omap_writel(otg_ctrl, OTG_CTRL); |
1142 | break; | 1142 | break; |
1143 | case OTG_STATE_B_WAIT_ACON: | 1143 | case OTG_STATE_B_WAIT_ACON: |
1144 | isp->phy.state = OTG_STATE_B_HOST; | 1144 | isp->phy.otg->state = OTG_STATE_B_HOST; |
1145 | pr_debug(" --> b_host (acon)\n"); | 1145 | pr_debug(" --> b_host (acon)\n"); |
1146 | break; | 1146 | break; |
1147 | case OTG_STATE_B_HOST: | 1147 | case OTG_STATE_B_HOST: |
@@ -1275,7 +1275,7 @@ static int isp1301_otg_enable(struct isp1301 *isp) | |||
1275 | static int | 1275 | static int |
1276 | isp1301_set_host(struct usb_otg *otg, struct usb_bus *host) | 1276 | isp1301_set_host(struct usb_otg *otg, struct usb_bus *host) |
1277 | { | 1277 | { |
1278 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); | 1278 | struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy); |
1279 | 1279 | ||
1280 | if (isp != the_transceiver) | 1280 | if (isp != the_transceiver) |
1281 | return -ENODEV; | 1281 | return -ENODEV; |
@@ -1331,7 +1331,7 @@ isp1301_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
1331 | static int | 1331 | static int |
1332 | isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) | 1332 | isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) |
1333 | { | 1333 | { |
1334 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); | 1334 | struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy); |
1335 | 1335 | ||
1336 | if (isp != the_transceiver) | 1336 | if (isp != the_transceiver) |
1337 | return -ENODEV; | 1337 | return -ENODEV; |
@@ -1368,7 +1368,7 @@ isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) | |||
1368 | } | 1368 | } |
1369 | 1369 | ||
1370 | power_up(isp); | 1370 | power_up(isp); |
1371 | isp->phy.state = OTG_STATE_B_IDLE; | 1371 | isp->phy.otg->state = OTG_STATE_B_IDLE; |
1372 | 1372 | ||
1373 | if (machine_is_omap_h2() || machine_is_omap_h3()) | 1373 | if (machine_is_omap_h2() || machine_is_omap_h3()) |
1374 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); | 1374 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); |
@@ -1403,7 +1403,7 @@ isp1301_set_power(struct usb_phy *dev, unsigned mA) | |||
1403 | { | 1403 | { |
1404 | if (!the_transceiver) | 1404 | if (!the_transceiver) |
1405 | return -ENODEV; | 1405 | return -ENODEV; |
1406 | if (dev->state == OTG_STATE_B_PERIPHERAL) | 1406 | if (dev->otg->state == OTG_STATE_B_PERIPHERAL) |
1407 | enable_vbus_draw(the_transceiver, mA); | 1407 | enable_vbus_draw(the_transceiver, mA); |
1408 | return 0; | 1408 | return 0; |
1409 | } | 1409 | } |
@@ -1411,10 +1411,10 @@ isp1301_set_power(struct usb_phy *dev, unsigned mA) | |||
1411 | static int | 1411 | static int |
1412 | isp1301_start_srp(struct usb_otg *otg) | 1412 | isp1301_start_srp(struct usb_otg *otg) |
1413 | { | 1413 | { |
1414 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); | 1414 | struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy); |
1415 | u32 otg_ctrl; | 1415 | u32 otg_ctrl; |
1416 | 1416 | ||
1417 | if (isp != the_transceiver || isp->phy.state != OTG_STATE_B_IDLE) | 1417 | if (isp != the_transceiver || isp->phy.otg->state != OTG_STATE_B_IDLE) |
1418 | return -ENODEV; | 1418 | return -ENODEV; |
1419 | 1419 | ||
1420 | otg_ctrl = omap_readl(OTG_CTRL); | 1420 | otg_ctrl = omap_readl(OTG_CTRL); |
@@ -1424,7 +1424,7 @@ isp1301_start_srp(struct usb_otg *otg) | |||
1424 | otg_ctrl |= OTG_B_BUSREQ; | 1424 | otg_ctrl |= OTG_B_BUSREQ; |
1425 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK; | 1425 | otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK; |
1426 | omap_writel(otg_ctrl, OTG_CTRL); | 1426 | omap_writel(otg_ctrl, OTG_CTRL); |
1427 | isp->phy.state = OTG_STATE_B_SRP_INIT; | 1427 | isp->phy.otg->state = OTG_STATE_B_SRP_INIT; |
1428 | 1428 | ||
1429 | pr_debug("otg: SRP, %s ... %06x\n", state_name(isp), | 1429 | pr_debug("otg: SRP, %s ... %06x\n", state_name(isp), |
1430 | omap_readl(OTG_CTRL)); | 1430 | omap_readl(OTG_CTRL)); |
@@ -1438,7 +1438,7 @@ static int | |||
1438 | isp1301_start_hnp(struct usb_otg *otg) | 1438 | isp1301_start_hnp(struct usb_otg *otg) |
1439 | { | 1439 | { |
1440 | #ifdef CONFIG_USB_OTG | 1440 | #ifdef CONFIG_USB_OTG |
1441 | struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); | 1441 | struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy); |
1442 | u32 l; | 1442 | u32 l; |
1443 | 1443 | ||
1444 | if (isp != the_transceiver) | 1444 | if (isp != the_transceiver) |
@@ -1452,9 +1452,9 @@ isp1301_start_hnp(struct usb_otg *otg) | |||
1452 | /* We want hardware to manage most HNP protocol timings. | 1452 | /* We want hardware to manage most HNP protocol timings. |
1453 | * So do this part as early as possible... | 1453 | * So do this part as early as possible... |
1454 | */ | 1454 | */ |
1455 | switch (isp->phy.state) { | 1455 | switch (isp->phy.otg->state) { |
1456 | case OTG_STATE_B_HOST: | 1456 | case OTG_STATE_B_HOST: |
1457 | isp->phy.state = OTG_STATE_B_PERIPHERAL; | 1457 | isp->phy.otg->state = OTG_STATE_B_PERIPHERAL; |
1458 | /* caller will suspend next */ | 1458 | /* caller will suspend next */ |
1459 | break; | 1459 | break; |
1460 | case OTG_STATE_A_HOST: | 1460 | case OTG_STATE_A_HOST: |
@@ -1583,7 +1583,7 @@ isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id) | |||
1583 | isp->phy.label = DRIVER_NAME; | 1583 | isp->phy.label = DRIVER_NAME; |
1584 | isp->phy.set_power = isp1301_set_power, | 1584 | isp->phy.set_power = isp1301_set_power, |
1585 | 1585 | ||
1586 | isp->phy.otg->phy = &isp->phy; | 1586 | isp->phy.otg->usb_phy = &isp->phy; |
1587 | isp->phy.otg->set_host = isp1301_set_host, | 1587 | isp->phy.otg->set_host = isp1301_set_host, |
1588 | isp->phy.otg->set_peripheral = isp1301_set_peripheral, | 1588 | isp->phy.otg->set_peripheral = isp1301_set_peripheral, |
1589 | isp->phy.otg->start_srp = isp1301_start_srp, | 1589 | isp->phy.otg->start_srp = isp1301_start_srp, |
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c index 7843ef7dd0ff..e120d87778b2 100644 --- a/drivers/usb/phy/phy-msm-usb.c +++ b/drivers/usb/phy/phy-msm-usb.c | |||
@@ -708,7 +708,7 @@ static void msm_otg_start_host(struct usb_phy *phy, int on) | |||
708 | 708 | ||
709 | static int msm_otg_set_host(struct usb_otg *otg, struct usb_bus *host) | 709 | static int msm_otg_set_host(struct usb_otg *otg, struct usb_bus *host) |
710 | { | 710 | { |
711 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); | 711 | struct msm_otg *motg = container_of(otg->usb_phy, struct msm_otg, phy); |
712 | struct usb_hcd *hcd; | 712 | struct usb_hcd *hcd; |
713 | 713 | ||
714 | /* | 714 | /* |
@@ -716,16 +716,16 @@ static int msm_otg_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
716 | * only peripheral configuration. | 716 | * only peripheral configuration. |
717 | */ | 717 | */ |
718 | if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL) { | 718 | if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL) { |
719 | dev_info(otg->phy->dev, "Host mode is not supported\n"); | 719 | dev_info(otg->usb_phy->dev, "Host mode is not supported\n"); |
720 | return -ENODEV; | 720 | return -ENODEV; |
721 | } | 721 | } |
722 | 722 | ||
723 | if (!host) { | 723 | if (!host) { |
724 | if (otg->phy->state == OTG_STATE_A_HOST) { | 724 | if (otg->state == OTG_STATE_A_HOST) { |
725 | pm_runtime_get_sync(otg->phy->dev); | 725 | pm_runtime_get_sync(otg->usb_phy->dev); |
726 | msm_otg_start_host(otg->phy, 0); | 726 | msm_otg_start_host(otg->usb_phy, 0); |
727 | otg->host = NULL; | 727 | otg->host = NULL; |
728 | otg->phy->state = OTG_STATE_UNDEFINED; | 728 | otg->state = OTG_STATE_UNDEFINED; |
729 | schedule_work(&motg->sm_work); | 729 | schedule_work(&motg->sm_work); |
730 | } else { | 730 | } else { |
731 | otg->host = NULL; | 731 | otg->host = NULL; |
@@ -738,14 +738,14 @@ static int msm_otg_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
738 | hcd->power_budget = motg->pdata->power_budget; | 738 | hcd->power_budget = motg->pdata->power_budget; |
739 | 739 | ||
740 | otg->host = host; | 740 | otg->host = host; |
741 | dev_dbg(otg->phy->dev, "host driver registered w/ tranceiver\n"); | 741 | dev_dbg(otg->usb_phy->dev, "host driver registered w/ tranceiver\n"); |
742 | 742 | ||
743 | /* | 743 | /* |
744 | * Kick the state machine work, if peripheral is not supported | 744 | * Kick the state machine work, if peripheral is not supported |
745 | * or peripheral is already registered with us. | 745 | * or peripheral is already registered with us. |
746 | */ | 746 | */ |
747 | if (motg->pdata->mode == USB_DR_MODE_HOST || otg->gadget) { | 747 | if (motg->pdata->mode == USB_DR_MODE_HOST || otg->gadget) { |
748 | pm_runtime_get_sync(otg->phy->dev); | 748 | pm_runtime_get_sync(otg->usb_phy->dev); |
749 | schedule_work(&motg->sm_work); | 749 | schedule_work(&motg->sm_work); |
750 | } | 750 | } |
751 | 751 | ||
@@ -782,23 +782,23 @@ static void msm_otg_start_peripheral(struct usb_phy *phy, int on) | |||
782 | static int msm_otg_set_peripheral(struct usb_otg *otg, | 782 | static int msm_otg_set_peripheral(struct usb_otg *otg, |
783 | struct usb_gadget *gadget) | 783 | struct usb_gadget *gadget) |
784 | { | 784 | { |
785 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); | 785 | struct msm_otg *motg = container_of(otg->usb_phy, struct msm_otg, phy); |
786 | 786 | ||
787 | /* | 787 | /* |
788 | * Fail peripheral registration if this board can support | 788 | * Fail peripheral registration if this board can support |
789 | * only host configuration. | 789 | * only host configuration. |
790 | */ | 790 | */ |
791 | if (motg->pdata->mode == USB_DR_MODE_HOST) { | 791 | if (motg->pdata->mode == USB_DR_MODE_HOST) { |
792 | dev_info(otg->phy->dev, "Peripheral mode is not supported\n"); | 792 | dev_info(otg->usb_phy->dev, "Peripheral mode is not supported\n"); |
793 | return -ENODEV; | 793 | return -ENODEV; |
794 | } | 794 | } |
795 | 795 | ||
796 | if (!gadget) { | 796 | if (!gadget) { |
797 | if (otg->phy->state == OTG_STATE_B_PERIPHERAL) { | 797 | if (otg->state == OTG_STATE_B_PERIPHERAL) { |
798 | pm_runtime_get_sync(otg->phy->dev); | 798 | pm_runtime_get_sync(otg->usb_phy->dev); |
799 | msm_otg_start_peripheral(otg->phy, 0); | 799 | msm_otg_start_peripheral(otg->usb_phy, 0); |
800 | otg->gadget = NULL; | 800 | otg->gadget = NULL; |
801 | otg->phy->state = OTG_STATE_UNDEFINED; | 801 | otg->state = OTG_STATE_UNDEFINED; |
802 | schedule_work(&motg->sm_work); | 802 | schedule_work(&motg->sm_work); |
803 | } else { | 803 | } else { |
804 | otg->gadget = NULL; | 804 | otg->gadget = NULL; |
@@ -807,14 +807,15 @@ static int msm_otg_set_peripheral(struct usb_otg *otg, | |||
807 | return 0; | 807 | return 0; |
808 | } | 808 | } |
809 | otg->gadget = gadget; | 809 | otg->gadget = gadget; |
810 | dev_dbg(otg->phy->dev, "peripheral driver registered w/ tranceiver\n"); | 810 | dev_dbg(otg->usb_phy->dev, |
811 | "peripheral driver registered w/ tranceiver\n"); | ||
811 | 812 | ||
812 | /* | 813 | /* |
813 | * Kick the state machine work, if host is not supported | 814 | * Kick the state machine work, if host is not supported |
814 | * or host is already registered with us. | 815 | * or host is already registered with us. |
815 | */ | 816 | */ |
816 | if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL || otg->host) { | 817 | if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL || otg->host) { |
817 | pm_runtime_get_sync(otg->phy->dev); | 818 | pm_runtime_get_sync(otg->usb_phy->dev); |
818 | schedule_work(&motg->sm_work); | 819 | schedule_work(&motg->sm_work); |
819 | } | 820 | } |
820 | 821 | ||
@@ -1170,20 +1171,20 @@ static void msm_otg_sm_work(struct work_struct *w) | |||
1170 | struct msm_otg *motg = container_of(w, struct msm_otg, sm_work); | 1171 | struct msm_otg *motg = container_of(w, struct msm_otg, sm_work); |
1171 | struct usb_otg *otg = motg->phy.otg; | 1172 | struct usb_otg *otg = motg->phy.otg; |
1172 | 1173 | ||
1173 | switch (otg->phy->state) { | 1174 | switch (otg->state) { |
1174 | case OTG_STATE_UNDEFINED: | 1175 | case OTG_STATE_UNDEFINED: |
1175 | dev_dbg(otg->phy->dev, "OTG_STATE_UNDEFINED state\n"); | 1176 | dev_dbg(otg->usb_phy->dev, "OTG_STATE_UNDEFINED state\n"); |
1176 | msm_otg_reset(otg->phy); | 1177 | msm_otg_reset(otg->usb_phy); |
1177 | msm_otg_init_sm(motg); | 1178 | msm_otg_init_sm(motg); |
1178 | otg->phy->state = OTG_STATE_B_IDLE; | 1179 | otg->state = OTG_STATE_B_IDLE; |
1179 | /* FALL THROUGH */ | 1180 | /* FALL THROUGH */ |
1180 | case OTG_STATE_B_IDLE: | 1181 | case OTG_STATE_B_IDLE: |
1181 | dev_dbg(otg->phy->dev, "OTG_STATE_B_IDLE state\n"); | 1182 | dev_dbg(otg->usb_phy->dev, "OTG_STATE_B_IDLE state\n"); |
1182 | if (!test_bit(ID, &motg->inputs) && otg->host) { | 1183 | if (!test_bit(ID, &motg->inputs) && otg->host) { |
1183 | /* disable BSV bit */ | 1184 | /* disable BSV bit */ |
1184 | writel(readl(USB_OTGSC) & ~OTGSC_BSVIE, USB_OTGSC); | 1185 | writel(readl(USB_OTGSC) & ~OTGSC_BSVIE, USB_OTGSC); |
1185 | msm_otg_start_host(otg->phy, 1); | 1186 | msm_otg_start_host(otg->usb_phy, 1); |
1186 | otg->phy->state = OTG_STATE_A_HOST; | 1187 | otg->state = OTG_STATE_A_HOST; |
1187 | } else if (test_bit(B_SESS_VLD, &motg->inputs)) { | 1188 | } else if (test_bit(B_SESS_VLD, &motg->inputs)) { |
1188 | switch (motg->chg_state) { | 1189 | switch (motg->chg_state) { |
1189 | case USB_CHG_STATE_UNDEFINED: | 1190 | case USB_CHG_STATE_UNDEFINED: |
@@ -1198,14 +1199,16 @@ static void msm_otg_sm_work(struct work_struct *w) | |||
1198 | case USB_CDP_CHARGER: | 1199 | case USB_CDP_CHARGER: |
1199 | msm_otg_notify_charger(motg, | 1200 | msm_otg_notify_charger(motg, |
1200 | IDEV_CHG_MAX); | 1201 | IDEV_CHG_MAX); |
1201 | msm_otg_start_peripheral(otg->phy, 1); | 1202 | msm_otg_start_peripheral(otg->usb_phy, |
1202 | otg->phy->state | 1203 | 1); |
1204 | otg->state | ||
1203 | = OTG_STATE_B_PERIPHERAL; | 1205 | = OTG_STATE_B_PERIPHERAL; |
1204 | break; | 1206 | break; |
1205 | case USB_SDP_CHARGER: | 1207 | case USB_SDP_CHARGER: |
1206 | msm_otg_notify_charger(motg, IUNIT); | 1208 | msm_otg_notify_charger(motg, IUNIT); |
1207 | msm_otg_start_peripheral(otg->phy, 1); | 1209 | msm_otg_start_peripheral(otg->usb_phy, |
1208 | otg->phy->state | 1210 | 1); |
1211 | otg->state | ||
1209 | = OTG_STATE_B_PERIPHERAL; | 1212 | = OTG_STATE_B_PERIPHERAL; |
1210 | break; | 1213 | break; |
1211 | default: | 1214 | default: |
@@ -1222,36 +1225,36 @@ static void msm_otg_sm_work(struct work_struct *w) | |||
1222 | * is incremented in charger detection work. | 1225 | * is incremented in charger detection work. |
1223 | */ | 1226 | */ |
1224 | if (cancel_delayed_work_sync(&motg->chg_work)) { | 1227 | if (cancel_delayed_work_sync(&motg->chg_work)) { |
1225 | pm_runtime_put_sync(otg->phy->dev); | 1228 | pm_runtime_put_sync(otg->usb_phy->dev); |
1226 | msm_otg_reset(otg->phy); | 1229 | msm_otg_reset(otg->usb_phy); |
1227 | } | 1230 | } |
1228 | msm_otg_notify_charger(motg, 0); | 1231 | msm_otg_notify_charger(motg, 0); |
1229 | motg->chg_state = USB_CHG_STATE_UNDEFINED; | 1232 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
1230 | motg->chg_type = USB_INVALID_CHARGER; | 1233 | motg->chg_type = USB_INVALID_CHARGER; |
1231 | } | 1234 | } |
1232 | 1235 | ||
1233 | if (otg->phy->state == OTG_STATE_B_IDLE) | 1236 | if (otg->state == OTG_STATE_B_IDLE) |
1234 | pm_runtime_put_sync(otg->phy->dev); | 1237 | pm_runtime_put_sync(otg->usb_phy->dev); |
1235 | break; | 1238 | break; |
1236 | case OTG_STATE_B_PERIPHERAL: | 1239 | case OTG_STATE_B_PERIPHERAL: |
1237 | dev_dbg(otg->phy->dev, "OTG_STATE_B_PERIPHERAL state\n"); | 1240 | dev_dbg(otg->usb_phy->dev, "OTG_STATE_B_PERIPHERAL state\n"); |
1238 | if (!test_bit(B_SESS_VLD, &motg->inputs) || | 1241 | if (!test_bit(B_SESS_VLD, &motg->inputs) || |
1239 | !test_bit(ID, &motg->inputs)) { | 1242 | !test_bit(ID, &motg->inputs)) { |
1240 | msm_otg_notify_charger(motg, 0); | 1243 | msm_otg_notify_charger(motg, 0); |
1241 | msm_otg_start_peripheral(otg->phy, 0); | 1244 | msm_otg_start_peripheral(otg->usb_phy, 0); |
1242 | motg->chg_state = USB_CHG_STATE_UNDEFINED; | 1245 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
1243 | motg->chg_type = USB_INVALID_CHARGER; | 1246 | motg->chg_type = USB_INVALID_CHARGER; |
1244 | otg->phy->state = OTG_STATE_B_IDLE; | 1247 | otg->state = OTG_STATE_B_IDLE; |
1245 | msm_otg_reset(otg->phy); | 1248 | msm_otg_reset(otg->usb_phy); |
1246 | schedule_work(w); | 1249 | schedule_work(w); |
1247 | } | 1250 | } |
1248 | break; | 1251 | break; |
1249 | case OTG_STATE_A_HOST: | 1252 | case OTG_STATE_A_HOST: |
1250 | dev_dbg(otg->phy->dev, "OTG_STATE_A_HOST state\n"); | 1253 | dev_dbg(otg->usb_phy->dev, "OTG_STATE_A_HOST state\n"); |
1251 | if (test_bit(ID, &motg->inputs)) { | 1254 | if (test_bit(ID, &motg->inputs)) { |
1252 | msm_otg_start_host(otg->phy, 0); | 1255 | msm_otg_start_host(otg->usb_phy, 0); |
1253 | otg->phy->state = OTG_STATE_B_IDLE; | 1256 | otg->state = OTG_STATE_B_IDLE; |
1254 | msm_otg_reset(otg->phy); | 1257 | msm_otg_reset(otg->usb_phy); |
1255 | schedule_work(w); | 1258 | schedule_work(w); |
1256 | } | 1259 | } |
1257 | break; | 1260 | break; |
@@ -1303,7 +1306,7 @@ static int msm_otg_mode_show(struct seq_file *s, void *unused) | |||
1303 | struct msm_otg *motg = s->private; | 1306 | struct msm_otg *motg = s->private; |
1304 | struct usb_otg *otg = motg->phy.otg; | 1307 | struct usb_otg *otg = motg->phy.otg; |
1305 | 1308 | ||
1306 | switch (otg->phy->state) { | 1309 | switch (otg->state) { |
1307 | case OTG_STATE_A_HOST: | 1310 | case OTG_STATE_A_HOST: |
1308 | seq_puts(s, "host\n"); | 1311 | seq_puts(s, "host\n"); |
1309 | break; | 1312 | break; |
@@ -1353,7 +1356,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, | |||
1353 | 1356 | ||
1354 | switch (req_mode) { | 1357 | switch (req_mode) { |
1355 | case USB_DR_MODE_UNKNOWN: | 1358 | case USB_DR_MODE_UNKNOWN: |
1356 | switch (otg->phy->state) { | 1359 | switch (otg->state) { |
1357 | case OTG_STATE_A_HOST: | 1360 | case OTG_STATE_A_HOST: |
1358 | case OTG_STATE_B_PERIPHERAL: | 1361 | case OTG_STATE_B_PERIPHERAL: |
1359 | set_bit(ID, &motg->inputs); | 1362 | set_bit(ID, &motg->inputs); |
@@ -1364,7 +1367,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, | |||
1364 | } | 1367 | } |
1365 | break; | 1368 | break; |
1366 | case USB_DR_MODE_PERIPHERAL: | 1369 | case USB_DR_MODE_PERIPHERAL: |
1367 | switch (otg->phy->state) { | 1370 | switch (otg->state) { |
1368 | case OTG_STATE_B_IDLE: | 1371 | case OTG_STATE_B_IDLE: |
1369 | case OTG_STATE_A_HOST: | 1372 | case OTG_STATE_A_HOST: |
1370 | set_bit(ID, &motg->inputs); | 1373 | set_bit(ID, &motg->inputs); |
@@ -1375,7 +1378,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, | |||
1375 | } | 1378 | } |
1376 | break; | 1379 | break; |
1377 | case USB_DR_MODE_HOST: | 1380 | case USB_DR_MODE_HOST: |
1378 | switch (otg->phy->state) { | 1381 | switch (otg->state) { |
1379 | case OTG_STATE_B_IDLE: | 1382 | case OTG_STATE_B_IDLE: |
1380 | case OTG_STATE_B_PERIPHERAL: | 1383 | case OTG_STATE_B_PERIPHERAL: |
1381 | clear_bit(ID, &motg->inputs); | 1384 | clear_bit(ID, &motg->inputs); |
@@ -1388,7 +1391,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, | |||
1388 | goto out; | 1391 | goto out; |
1389 | } | 1392 | } |
1390 | 1393 | ||
1391 | pm_runtime_get_sync(otg->phy->dev); | 1394 | pm_runtime_get_sync(otg->usb_phy->dev); |
1392 | schedule_work(&motg->sm_work); | 1395 | schedule_work(&motg->sm_work); |
1393 | out: | 1396 | out: |
1394 | return status; | 1397 | return status; |
@@ -1505,10 +1508,8 @@ static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) | |||
1505 | } | 1508 | } |
1506 | 1509 | ||
1507 | pdata->phy_init_seq = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); | 1510 | pdata->phy_init_seq = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); |
1508 | if (!pdata->phy_init_seq) { | 1511 | if (!pdata->phy_init_seq) |
1509 | dev_warn(&pdev->dev, "No space for PHY init sequence\n"); | ||
1510 | return 0; | 1512 | return 0; |
1511 | } | ||
1512 | 1513 | ||
1513 | ret = of_property_read_u32_array(node, "qcom,phy-init-sequence", | 1514 | ret = of_property_read_u32_array(node, "qcom,phy-init-sequence", |
1514 | pdata->phy_init_seq, words); | 1515 | pdata->phy_init_seq, words); |
@@ -1530,10 +1531,8 @@ static int msm_otg_probe(struct platform_device *pdev) | |||
1530 | void __iomem *phy_select; | 1531 | void __iomem *phy_select; |
1531 | 1532 | ||
1532 | motg = devm_kzalloc(&pdev->dev, sizeof(struct msm_otg), GFP_KERNEL); | 1533 | motg = devm_kzalloc(&pdev->dev, sizeof(struct msm_otg), GFP_KERNEL); |
1533 | if (!motg) { | 1534 | if (!motg) |
1534 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); | ||
1535 | return -ENOMEM; | 1535 | return -ENOMEM; |
1536 | } | ||
1537 | 1536 | ||
1538 | pdata = dev_get_platdata(&pdev->dev); | 1537 | pdata = dev_get_platdata(&pdev->dev); |
1539 | if (!pdata) { | 1538 | if (!pdata) { |
@@ -1546,10 +1545,8 @@ static int msm_otg_probe(struct platform_device *pdev) | |||
1546 | 1545 | ||
1547 | motg->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), | 1546 | motg->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), |
1548 | GFP_KERNEL); | 1547 | GFP_KERNEL); |
1549 | if (!motg->phy.otg) { | 1548 | if (!motg->phy.otg) |
1550 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); | ||
1551 | return -ENOMEM; | 1549 | return -ENOMEM; |
1552 | } | ||
1553 | 1550 | ||
1554 | phy = &motg->phy; | 1551 | phy = &motg->phy; |
1555 | phy->dev = &pdev->dev; | 1552 | phy->dev = &pdev->dev; |
@@ -1674,7 +1671,7 @@ static int msm_otg_probe(struct platform_device *pdev) | |||
1674 | 1671 | ||
1675 | phy->io_ops = &msm_otg_io_ops; | 1672 | phy->io_ops = &msm_otg_io_ops; |
1676 | 1673 | ||
1677 | phy->otg->phy = &motg->phy; | 1674 | phy->otg->usb_phy = &motg->phy; |
1678 | phy->otg->set_host = msm_otg_set_host; | 1675 | phy->otg->set_host = msm_otg_set_host; |
1679 | phy->otg->set_peripheral = msm_otg_set_peripheral; | 1676 | phy->otg->set_peripheral = msm_otg_set_peripheral; |
1680 | 1677 | ||
@@ -1775,7 +1772,7 @@ static int msm_otg_runtime_idle(struct device *dev) | |||
1775 | * This 1 sec delay also prevents entering into LPM immediately | 1772 | * This 1 sec delay also prevents entering into LPM immediately |
1776 | * after asynchronous interrupt. | 1773 | * after asynchronous interrupt. |
1777 | */ | 1774 | */ |
1778 | if (otg->phy->state != OTG_STATE_UNDEFINED) | 1775 | if (otg->state != OTG_STATE_UNDEFINED) |
1779 | pm_schedule_suspend(dev, 1000); | 1776 | pm_schedule_suspend(dev, 1000); |
1780 | 1777 | ||
1781 | return -EAGAIN; | 1778 | return -EAGAIN; |
diff --git a/drivers/usb/phy/phy-mv-usb.c b/drivers/usb/phy/phy-mv-usb.c index 7d80c54f0ac6..b234d46cd58b 100644 --- a/drivers/usb/phy/phy-mv-usb.c +++ b/drivers/usb/phy/phy-mv-usb.c | |||
@@ -56,7 +56,7 @@ static char *state_string[] = { | |||
56 | 56 | ||
57 | static int mv_otg_set_vbus(struct usb_otg *otg, bool on) | 57 | static int mv_otg_set_vbus(struct usb_otg *otg, bool on) |
58 | { | 58 | { |
59 | struct mv_otg *mvotg = container_of(otg->phy, struct mv_otg, phy); | 59 | struct mv_otg *mvotg = container_of(otg->usb_phy, struct mv_otg, phy); |
60 | if (mvotg->pdata->set_vbus == NULL) | 60 | if (mvotg->pdata->set_vbus == NULL) |
61 | return -ENODEV; | 61 | return -ENODEV; |
62 | 62 | ||
@@ -339,68 +339,68 @@ static void mv_otg_update_state(struct mv_otg *mvotg) | |||
339 | { | 339 | { |
340 | struct mv_otg_ctrl *otg_ctrl = &mvotg->otg_ctrl; | 340 | struct mv_otg_ctrl *otg_ctrl = &mvotg->otg_ctrl; |
341 | struct usb_phy *phy = &mvotg->phy; | 341 | struct usb_phy *phy = &mvotg->phy; |
342 | int old_state = phy->state; | 342 | int old_state = mvotg->phy.otg->state; |
343 | 343 | ||
344 | switch (old_state) { | 344 | switch (old_state) { |
345 | case OTG_STATE_UNDEFINED: | 345 | case OTG_STATE_UNDEFINED: |
346 | phy->state = OTG_STATE_B_IDLE; | 346 | mvotg->phy.otg->state = OTG_STATE_B_IDLE; |
347 | /* FALL THROUGH */ | 347 | /* FALL THROUGH */ |
348 | case OTG_STATE_B_IDLE: | 348 | case OTG_STATE_B_IDLE: |
349 | if (otg_ctrl->id == 0) | 349 | if (otg_ctrl->id == 0) |
350 | phy->state = OTG_STATE_A_IDLE; | 350 | mvotg->phy.otg->state = OTG_STATE_A_IDLE; |
351 | else if (otg_ctrl->b_sess_vld) | 351 | else if (otg_ctrl->b_sess_vld) |
352 | phy->state = OTG_STATE_B_PERIPHERAL; | 352 | mvotg->phy.otg->state = OTG_STATE_B_PERIPHERAL; |
353 | break; | 353 | break; |
354 | case OTG_STATE_B_PERIPHERAL: | 354 | case OTG_STATE_B_PERIPHERAL: |
355 | if (!otg_ctrl->b_sess_vld || otg_ctrl->id == 0) | 355 | if (!otg_ctrl->b_sess_vld || otg_ctrl->id == 0) |
356 | phy->state = OTG_STATE_B_IDLE; | 356 | mvotg->phy.otg->state = OTG_STATE_B_IDLE; |
357 | break; | 357 | break; |
358 | case OTG_STATE_A_IDLE: | 358 | case OTG_STATE_A_IDLE: |
359 | if (otg_ctrl->id) | 359 | if (otg_ctrl->id) |
360 | phy->state = OTG_STATE_B_IDLE; | 360 | mvotg->phy.otg->state = OTG_STATE_B_IDLE; |
361 | else if (!(otg_ctrl->a_bus_drop) && | 361 | else if (!(otg_ctrl->a_bus_drop) && |
362 | (otg_ctrl->a_bus_req || otg_ctrl->a_srp_det)) | 362 | (otg_ctrl->a_bus_req || otg_ctrl->a_srp_det)) |
363 | phy->state = OTG_STATE_A_WAIT_VRISE; | 363 | mvotg->phy.otg->state = OTG_STATE_A_WAIT_VRISE; |
364 | break; | 364 | break; |
365 | case OTG_STATE_A_WAIT_VRISE: | 365 | case OTG_STATE_A_WAIT_VRISE: |
366 | if (otg_ctrl->a_vbus_vld) | 366 | if (otg_ctrl->a_vbus_vld) |
367 | phy->state = OTG_STATE_A_WAIT_BCON; | 367 | mvotg->phy.otg->state = OTG_STATE_A_WAIT_BCON; |
368 | break; | 368 | break; |
369 | case OTG_STATE_A_WAIT_BCON: | 369 | case OTG_STATE_A_WAIT_BCON: |
370 | if (otg_ctrl->id || otg_ctrl->a_bus_drop | 370 | if (otg_ctrl->id || otg_ctrl->a_bus_drop |
371 | || otg_ctrl->a_wait_bcon_timeout) { | 371 | || otg_ctrl->a_wait_bcon_timeout) { |
372 | mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); | 372 | mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); |
373 | mvotg->otg_ctrl.a_wait_bcon_timeout = 0; | 373 | mvotg->otg_ctrl.a_wait_bcon_timeout = 0; |
374 | phy->state = OTG_STATE_A_WAIT_VFALL; | 374 | mvotg->phy.otg->state = OTG_STATE_A_WAIT_VFALL; |
375 | otg_ctrl->a_bus_req = 0; | 375 | otg_ctrl->a_bus_req = 0; |
376 | } else if (!otg_ctrl->a_vbus_vld) { | 376 | } else if (!otg_ctrl->a_vbus_vld) { |
377 | mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); | 377 | mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); |
378 | mvotg->otg_ctrl.a_wait_bcon_timeout = 0; | 378 | mvotg->otg_ctrl.a_wait_bcon_timeout = 0; |
379 | phy->state = OTG_STATE_A_VBUS_ERR; | 379 | mvotg->phy.otg->state = OTG_STATE_A_VBUS_ERR; |
380 | } else if (otg_ctrl->b_conn) { | 380 | } else if (otg_ctrl->b_conn) { |
381 | mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); | 381 | mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); |
382 | mvotg->otg_ctrl.a_wait_bcon_timeout = 0; | 382 | mvotg->otg_ctrl.a_wait_bcon_timeout = 0; |
383 | phy->state = OTG_STATE_A_HOST; | 383 | mvotg->phy.otg->state = OTG_STATE_A_HOST; |
384 | } | 384 | } |
385 | break; | 385 | break; |
386 | case OTG_STATE_A_HOST: | 386 | case OTG_STATE_A_HOST: |
387 | if (otg_ctrl->id || !otg_ctrl->b_conn | 387 | if (otg_ctrl->id || !otg_ctrl->b_conn |
388 | || otg_ctrl->a_bus_drop) | 388 | || otg_ctrl->a_bus_drop) |
389 | phy->state = OTG_STATE_A_WAIT_BCON; | 389 | mvotg->phy.otg->state = OTG_STATE_A_WAIT_BCON; |
390 | else if (!otg_ctrl->a_vbus_vld) | 390 | else if (!otg_ctrl->a_vbus_vld) |
391 | phy->state = OTG_STATE_A_VBUS_ERR; | 391 | mvotg->phy.otg->state = OTG_STATE_A_VBUS_ERR; |
392 | break; | 392 | break; |
393 | case OTG_STATE_A_WAIT_VFALL: | 393 | case OTG_STATE_A_WAIT_VFALL: |
394 | if (otg_ctrl->id | 394 | if (otg_ctrl->id |
395 | || (!otg_ctrl->b_conn && otg_ctrl->a_sess_vld) | 395 | || (!otg_ctrl->b_conn && otg_ctrl->a_sess_vld) |
396 | || otg_ctrl->a_bus_req) | 396 | || otg_ctrl->a_bus_req) |
397 | phy->state = OTG_STATE_A_IDLE; | 397 | mvotg->phy.otg->state = OTG_STATE_A_IDLE; |
398 | break; | 398 | break; |
399 | case OTG_STATE_A_VBUS_ERR: | 399 | case OTG_STATE_A_VBUS_ERR: |
400 | if (otg_ctrl->id || otg_ctrl->a_clr_err | 400 | if (otg_ctrl->id || otg_ctrl->a_clr_err |
401 | || otg_ctrl->a_bus_drop) { | 401 | || otg_ctrl->a_bus_drop) { |
402 | otg_ctrl->a_clr_err = 0; | 402 | otg_ctrl->a_clr_err = 0; |
403 | phy->state = OTG_STATE_A_WAIT_VFALL; | 403 | mvotg->phy.otg->state = OTG_STATE_A_WAIT_VFALL; |
404 | } | 404 | } |
405 | break; | 405 | break; |
406 | default: | 406 | default: |
@@ -420,8 +420,8 @@ static void mv_otg_work(struct work_struct *work) | |||
420 | run: | 420 | run: |
421 | /* work queue is single thread, or we need spin_lock to protect */ | 421 | /* work queue is single thread, or we need spin_lock to protect */ |
422 | phy = &mvotg->phy; | 422 | phy = &mvotg->phy; |
423 | otg = phy->otg; | 423 | otg = mvotg->phy.otg; |
424 | old_state = phy->state; | 424 | old_state = otg->state; |
425 | 425 | ||
426 | if (!mvotg->active) | 426 | if (!mvotg->active) |
427 | return; | 427 | return; |
@@ -429,22 +429,24 @@ run: | |||
429 | mv_otg_update_inputs(mvotg); | 429 | mv_otg_update_inputs(mvotg); |
430 | mv_otg_update_state(mvotg); | 430 | mv_otg_update_state(mvotg); |
431 | 431 | ||
432 | if (old_state != phy->state) { | 432 | if (old_state != mvotg->phy.otg->state) { |
433 | dev_info(&mvotg->pdev->dev, "change from state %s to %s\n", | 433 | dev_info(&mvotg->pdev->dev, "change from state %s to %s\n", |
434 | state_string[old_state], | 434 | state_string[old_state], |
435 | state_string[phy->state]); | 435 | state_string[mvotg->phy.otg->state]); |
436 | 436 | ||
437 | switch (phy->state) { | 437 | switch (mvotg->phy.otg->state) { |
438 | case OTG_STATE_B_IDLE: | 438 | case OTG_STATE_B_IDLE: |
439 | otg->default_a = 0; | 439 | otg->default_a = 0; |
440 | if (old_state == OTG_STATE_B_PERIPHERAL) | 440 | if (old_state == OTG_STATE_B_PERIPHERAL) |
441 | mv_otg_start_periphrals(mvotg, 0); | 441 | mv_otg_start_periphrals(mvotg, 0); |
442 | mv_otg_reset(mvotg); | 442 | mv_otg_reset(mvotg); |
443 | mv_otg_disable(mvotg); | 443 | mv_otg_disable(mvotg); |
444 | usb_phy_set_event(&mvotg->phy, USB_EVENT_NONE); | ||
444 | break; | 445 | break; |
445 | case OTG_STATE_B_PERIPHERAL: | 446 | case OTG_STATE_B_PERIPHERAL: |
446 | mv_otg_enable(mvotg); | 447 | mv_otg_enable(mvotg); |
447 | mv_otg_start_periphrals(mvotg, 1); | 448 | mv_otg_start_periphrals(mvotg, 1); |
449 | usb_phy_set_event(&mvotg->phy, USB_EVENT_ENUMERATED); | ||
448 | break; | 450 | break; |
449 | case OTG_STATE_A_IDLE: | 451 | case OTG_STATE_A_IDLE: |
450 | otg->default_a = 1; | 452 | otg->default_a = 1; |
@@ -545,8 +547,8 @@ set_a_bus_req(struct device *dev, struct device_attribute *attr, | |||
545 | return -1; | 547 | return -1; |
546 | 548 | ||
547 | /* We will use this interface to change to A device */ | 549 | /* We will use this interface to change to A device */ |
548 | if (mvotg->phy.state != OTG_STATE_B_IDLE | 550 | if (mvotg->phy.otg->state != OTG_STATE_B_IDLE |
549 | && mvotg->phy.state != OTG_STATE_A_IDLE) | 551 | && mvotg->phy.otg->state != OTG_STATE_A_IDLE) |
550 | return -1; | 552 | return -1; |
551 | 553 | ||
552 | /* The clock may disabled and we need to set irq for ID detected */ | 554 | /* The clock may disabled and we need to set irq for ID detected */ |
@@ -686,10 +688,8 @@ static int mv_otg_probe(struct platform_device *pdev) | |||
686 | } | 688 | } |
687 | 689 | ||
688 | mvotg = devm_kzalloc(&pdev->dev, sizeof(*mvotg), GFP_KERNEL); | 690 | mvotg = devm_kzalloc(&pdev->dev, sizeof(*mvotg), GFP_KERNEL); |
689 | if (!mvotg) { | 691 | if (!mvotg) |
690 | dev_err(&pdev->dev, "failed to allocate memory!\n"); | ||
691 | return -ENOMEM; | 692 | return -ENOMEM; |
692 | } | ||
693 | 693 | ||
694 | otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); | 694 | otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); |
695 | if (!otg) | 695 | if (!otg) |
@@ -717,9 +717,9 @@ static int mv_otg_probe(struct platform_device *pdev) | |||
717 | mvotg->phy.dev = &pdev->dev; | 717 | mvotg->phy.dev = &pdev->dev; |
718 | mvotg->phy.otg = otg; | 718 | mvotg->phy.otg = otg; |
719 | mvotg->phy.label = driver_name; | 719 | mvotg->phy.label = driver_name; |
720 | mvotg->phy.state = OTG_STATE_UNDEFINED; | ||
721 | 720 | ||
722 | otg->phy = &mvotg->phy; | 721 | otg->state = OTG_STATE_UNDEFINED; |
722 | otg->usb_phy = &mvotg->phy; | ||
723 | otg->set_host = mv_otg_set_host; | 723 | otg->set_host = mv_otg_set_host; |
724 | otg->set_peripheral = mv_otg_set_peripheral; | 724 | otg->set_peripheral = mv_otg_set_peripheral; |
725 | otg->set_vbus = mv_otg_set_vbus; | 725 | otg->set_vbus = mv_otg_set_vbus; |
diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c index 0e0c41587a08..a55dadcd47f3 100644 --- a/drivers/usb/phy/phy-mxs-usb.c +++ b/drivers/usb/phy/phy-mxs-usb.c | |||
@@ -390,10 +390,8 @@ static int mxs_phy_probe(struct platform_device *pdev) | |||
390 | } | 390 | } |
391 | 391 | ||
392 | mxs_phy = devm_kzalloc(&pdev->dev, sizeof(*mxs_phy), GFP_KERNEL); | 392 | mxs_phy = devm_kzalloc(&pdev->dev, sizeof(*mxs_phy), GFP_KERNEL); |
393 | if (!mxs_phy) { | 393 | if (!mxs_phy) |
394 | dev_err(&pdev->dev, "Failed to allocate USB PHY structure!\n"); | ||
395 | return -ENOMEM; | 394 | return -ENOMEM; |
396 | } | ||
397 | 395 | ||
398 | /* Some SoCs don't have anatop registers */ | 396 | /* Some SoCs don't have anatop registers */ |
399 | if (of_get_property(np, "fsl,anatop", NULL)) { | 397 | if (of_get_property(np, "fsl,anatop", NULL)) { |
diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c b/drivers/usb/phy/phy-rcar-gen2-usb.c index 388d89f6b141..f83808413ba2 100644 --- a/drivers/usb/phy/phy-rcar-gen2-usb.c +++ b/drivers/usb/phy/phy-rcar-gen2-usb.c | |||
@@ -195,10 +195,8 @@ static int rcar_gen2_usb_phy_probe(struct platform_device *pdev) | |||
195 | return PTR_ERR(base); | 195 | return PTR_ERR(base); |
196 | 196 | ||
197 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | 197 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
198 | if (!priv) { | 198 | if (!priv) |
199 | dev_err(dev, "Memory allocation failed\n"); | ||
200 | return -ENOMEM; | 199 | return -ENOMEM; |
201 | } | ||
202 | 200 | ||
203 | spin_lock_init(&priv->lock); | 201 | spin_lock_init(&priv->lock); |
204 | priv->clk = clk; | 202 | priv->clk = clk; |
diff --git a/drivers/usb/phy/phy-rcar-usb.c b/drivers/usb/phy/phy-rcar-usb.c index e9f3a93e42b7..1e09b8377885 100644 --- a/drivers/usb/phy/phy-rcar-usb.c +++ b/drivers/usb/phy/phy-rcar-usb.c | |||
@@ -200,10 +200,8 @@ static int rcar_usb_phy_probe(struct platform_device *pdev) | |||
200 | return PTR_ERR(reg1); | 200 | return PTR_ERR(reg1); |
201 | 201 | ||
202 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | 202 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
203 | if (!priv) { | 203 | if (!priv) |
204 | dev_err(dev, "priv data allocation error\n"); | ||
205 | return -ENOMEM; | 204 | return -ENOMEM; |
206 | } | ||
207 | 205 | ||
208 | priv->reg0 = reg0; | 206 | priv->reg0 = reg0; |
209 | priv->reg1 = reg1; | 207 | priv->reg1 = reg1; |
diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c index cc61ee44b911..d391c79a542a 100644 --- a/drivers/usb/phy/phy-tahvo.c +++ b/drivers/usb/phy/phy-tahvo.c | |||
@@ -81,33 +81,35 @@ static void check_vbus_state(struct tahvo_usb *tu) | |||
81 | 81 | ||
82 | reg = retu_read(rdev, TAHVO_REG_IDSR); | 82 | reg = retu_read(rdev, TAHVO_REG_IDSR); |
83 | if (reg & TAHVO_STAT_VBUS) { | 83 | if (reg & TAHVO_STAT_VBUS) { |
84 | switch (tu->phy.state) { | 84 | switch (tu->phy.otg->state) { |
85 | case OTG_STATE_B_IDLE: | 85 | case OTG_STATE_B_IDLE: |
86 | /* Enable the gadget driver */ | 86 | /* Enable the gadget driver */ |
87 | if (tu->phy.otg->gadget) | 87 | if (tu->phy.otg->gadget) |
88 | usb_gadget_vbus_connect(tu->phy.otg->gadget); | 88 | usb_gadget_vbus_connect(tu->phy.otg->gadget); |
89 | tu->phy.state = OTG_STATE_B_PERIPHERAL; | 89 | tu->phy.otg->state = OTG_STATE_B_PERIPHERAL; |
90 | usb_phy_set_event(&tu->phy, USB_EVENT_ENUMERATED); | ||
90 | break; | 91 | break; |
91 | case OTG_STATE_A_IDLE: | 92 | case OTG_STATE_A_IDLE: |
92 | /* | 93 | /* |
93 | * Session is now valid assuming the USB hub is driving | 94 | * Session is now valid assuming the USB hub is driving |
94 | * Vbus. | 95 | * Vbus. |
95 | */ | 96 | */ |
96 | tu->phy.state = OTG_STATE_A_HOST; | 97 | tu->phy.otg->state = OTG_STATE_A_HOST; |
97 | break; | 98 | break; |
98 | default: | 99 | default: |
99 | break; | 100 | break; |
100 | } | 101 | } |
101 | dev_info(&tu->pt_dev->dev, "USB cable connected\n"); | 102 | dev_info(&tu->pt_dev->dev, "USB cable connected\n"); |
102 | } else { | 103 | } else { |
103 | switch (tu->phy.state) { | 104 | switch (tu->phy.otg->state) { |
104 | case OTG_STATE_B_PERIPHERAL: | 105 | case OTG_STATE_B_PERIPHERAL: |
105 | if (tu->phy.otg->gadget) | 106 | if (tu->phy.otg->gadget) |
106 | usb_gadget_vbus_disconnect(tu->phy.otg->gadget); | 107 | usb_gadget_vbus_disconnect(tu->phy.otg->gadget); |
107 | tu->phy.state = OTG_STATE_B_IDLE; | 108 | tu->phy.otg->state = OTG_STATE_B_IDLE; |
109 | usb_phy_set_event(&tu->phy, USB_EVENT_NONE); | ||
108 | break; | 110 | break; |
109 | case OTG_STATE_A_HOST: | 111 | case OTG_STATE_A_HOST: |
110 | tu->phy.state = OTG_STATE_A_IDLE; | 112 | tu->phy.otg->state = OTG_STATE_A_IDLE; |
111 | break; | 113 | break; |
112 | default: | 114 | default: |
113 | break; | 115 | break; |
@@ -132,14 +134,14 @@ static void tahvo_usb_become_host(struct tahvo_usb *tu) | |||
132 | /* Power up the transceiver in USB host mode */ | 134 | /* Power up the transceiver in USB host mode */ |
133 | retu_write(rdev, TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND | | 135 | retu_write(rdev, TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND | |
134 | USBR_MASTER_SW2 | USBR_MASTER_SW1); | 136 | USBR_MASTER_SW2 | USBR_MASTER_SW1); |
135 | tu->phy.state = OTG_STATE_A_IDLE; | 137 | tu->phy.otg->state = OTG_STATE_A_IDLE; |
136 | 138 | ||
137 | check_vbus_state(tu); | 139 | check_vbus_state(tu); |
138 | } | 140 | } |
139 | 141 | ||
140 | static void tahvo_usb_stop_host(struct tahvo_usb *tu) | 142 | static void tahvo_usb_stop_host(struct tahvo_usb *tu) |
141 | { | 143 | { |
142 | tu->phy.state = OTG_STATE_A_IDLE; | 144 | tu->phy.otg->state = OTG_STATE_A_IDLE; |
143 | } | 145 | } |
144 | 146 | ||
145 | static void tahvo_usb_become_peripheral(struct tahvo_usb *tu) | 147 | static void tahvo_usb_become_peripheral(struct tahvo_usb *tu) |
@@ -151,7 +153,7 @@ static void tahvo_usb_become_peripheral(struct tahvo_usb *tu) | |||
151 | /* Power up transceiver and set it in USB peripheral mode */ | 153 | /* Power up transceiver and set it in USB peripheral mode */ |
152 | retu_write(rdev, TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT | | 154 | retu_write(rdev, TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT | |
153 | USBR_NSUSPEND | USBR_SLAVE_SW); | 155 | USBR_NSUSPEND | USBR_SLAVE_SW); |
154 | tu->phy.state = OTG_STATE_B_IDLE; | 156 | tu->phy.otg->state = OTG_STATE_B_IDLE; |
155 | 157 | ||
156 | check_vbus_state(tu); | 158 | check_vbus_state(tu); |
157 | } | 159 | } |
@@ -160,7 +162,7 @@ static void tahvo_usb_stop_peripheral(struct tahvo_usb *tu) | |||
160 | { | 162 | { |
161 | if (tu->phy.otg->gadget) | 163 | if (tu->phy.otg->gadget) |
162 | usb_gadget_vbus_disconnect(tu->phy.otg->gadget); | 164 | usb_gadget_vbus_disconnect(tu->phy.otg->gadget); |
163 | tu->phy.state = OTG_STATE_B_IDLE; | 165 | tu->phy.otg->state = OTG_STATE_B_IDLE; |
164 | } | 166 | } |
165 | 167 | ||
166 | static void tahvo_usb_power_off(struct tahvo_usb *tu) | 168 | static void tahvo_usb_power_off(struct tahvo_usb *tu) |
@@ -173,7 +175,7 @@ static void tahvo_usb_power_off(struct tahvo_usb *tu) | |||
173 | 175 | ||
174 | /* Power off transceiver */ | 176 | /* Power off transceiver */ |
175 | retu_write(rdev, TAHVO_REG_USBR, 0); | 177 | retu_write(rdev, TAHVO_REG_USBR, 0); |
176 | tu->phy.state = OTG_STATE_UNDEFINED; | 178 | tu->phy.otg->state = OTG_STATE_UNDEFINED; |
177 | } | 179 | } |
178 | 180 | ||
179 | static int tahvo_usb_set_suspend(struct usb_phy *dev, int suspend) | 181 | static int tahvo_usb_set_suspend(struct usb_phy *dev, int suspend) |
@@ -196,7 +198,8 @@ static int tahvo_usb_set_suspend(struct usb_phy *dev, int suspend) | |||
196 | 198 | ||
197 | static int tahvo_usb_set_host(struct usb_otg *otg, struct usb_bus *host) | 199 | static int tahvo_usb_set_host(struct usb_otg *otg, struct usb_bus *host) |
198 | { | 200 | { |
199 | struct tahvo_usb *tu = container_of(otg->phy, struct tahvo_usb, phy); | 201 | struct tahvo_usb *tu = container_of(otg->usb_phy, struct tahvo_usb, |
202 | phy); | ||
200 | 203 | ||
201 | dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, host); | 204 | dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, host); |
202 | 205 | ||
@@ -225,7 +228,8 @@ static int tahvo_usb_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
225 | static int tahvo_usb_set_peripheral(struct usb_otg *otg, | 228 | static int tahvo_usb_set_peripheral(struct usb_otg *otg, |
226 | struct usb_gadget *gadget) | 229 | struct usb_gadget *gadget) |
227 | { | 230 | { |
228 | struct tahvo_usb *tu = container_of(otg->phy, struct tahvo_usb, phy); | 231 | struct tahvo_usb *tu = container_of(otg->usb_phy, struct tahvo_usb, |
232 | phy); | ||
229 | 233 | ||
230 | dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, gadget); | 234 | dev_dbg(&tu->pt_dev->dev, "%s %p\n", __func__, gadget); |
231 | 235 | ||
@@ -379,11 +383,11 @@ static int tahvo_usb_probe(struct platform_device *pdev) | |||
379 | /* Create OTG interface */ | 383 | /* Create OTG interface */ |
380 | tahvo_usb_power_off(tu); | 384 | tahvo_usb_power_off(tu); |
381 | tu->phy.dev = &pdev->dev; | 385 | tu->phy.dev = &pdev->dev; |
382 | tu->phy.state = OTG_STATE_UNDEFINED; | 386 | tu->phy.otg->state = OTG_STATE_UNDEFINED; |
383 | tu->phy.label = DRIVER_NAME; | 387 | tu->phy.label = DRIVER_NAME; |
384 | tu->phy.set_suspend = tahvo_usb_set_suspend; | 388 | tu->phy.set_suspend = tahvo_usb_set_suspend; |
385 | 389 | ||
386 | tu->phy.otg->phy = &tu->phy; | 390 | tu->phy.otg->usb_phy = &tu->phy; |
387 | tu->phy.otg->set_host = tahvo_usb_set_host; | 391 | tu->phy.otg->set_host = tahvo_usb_set_host; |
388 | tu->phy.otg->set_peripheral = tahvo_usb_set_peripheral; | 392 | tu->phy.otg->set_peripheral = tahvo_usb_set_peripheral; |
389 | 393 | ||
diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c index 886f1807a67b..fa2bfa4ee34e 100644 --- a/drivers/usb/phy/phy-tegra-usb.c +++ b/drivers/usb/phy/phy-tegra-usb.c | |||
@@ -880,11 +880,8 @@ static int utmi_phy_probe(struct tegra_usb_phy *tegra_phy, | |||
880 | 880 | ||
881 | tegra_phy->config = devm_kzalloc(&pdev->dev, sizeof(*config), | 881 | tegra_phy->config = devm_kzalloc(&pdev->dev, sizeof(*config), |
882 | GFP_KERNEL); | 882 | GFP_KERNEL); |
883 | if (!tegra_phy->config) { | 883 | if (!tegra_phy->config) |
884 | dev_err(&pdev->dev, | ||
885 | "unable to allocate memory for USB UTMIP config\n"); | ||
886 | return -ENOMEM; | 884 | return -ENOMEM; |
887 | } | ||
888 | 885 | ||
889 | config = tegra_phy->config; | 886 | config = tegra_phy->config; |
890 | 887 | ||
@@ -979,10 +976,8 @@ static int tegra_usb_phy_probe(struct platform_device *pdev) | |||
979 | int err; | 976 | int err; |
980 | 977 | ||
981 | tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL); | 978 | tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL); |
982 | if (!tegra_phy) { | 979 | if (!tegra_phy) |
983 | dev_err(&pdev->dev, "unable to allocate memory for USB2 PHY\n"); | ||
984 | return -ENOMEM; | 980 | return -ENOMEM; |
985 | } | ||
986 | 981 | ||
987 | match = of_match_device(tegra_usb_phy_id_table, &pdev->dev); | 982 | match = of_match_device(tegra_usb_phy_id_table, &pdev->dev); |
988 | if (!match) { | 983 | if (!match) { |
diff --git a/drivers/usb/phy/phy-ulpi.c b/drivers/usb/phy/phy-ulpi.c index 4e3877c329f2..f48a7a21e3c2 100644 --- a/drivers/usb/phy/phy-ulpi.c +++ b/drivers/usb/phy/phy-ulpi.c | |||
@@ -211,7 +211,7 @@ static int ulpi_init(struct usb_phy *phy) | |||
211 | 211 | ||
212 | static int ulpi_set_host(struct usb_otg *otg, struct usb_bus *host) | 212 | static int ulpi_set_host(struct usb_otg *otg, struct usb_bus *host) |
213 | { | 213 | { |
214 | struct usb_phy *phy = otg->phy; | 214 | struct usb_phy *phy = otg->usb_phy; |
215 | unsigned int flags = usb_phy_io_read(phy, ULPI_IFC_CTRL); | 215 | unsigned int flags = usb_phy_io_read(phy, ULPI_IFC_CTRL); |
216 | 216 | ||
217 | if (!host) { | 217 | if (!host) { |
@@ -237,7 +237,7 @@ static int ulpi_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
237 | 237 | ||
238 | static int ulpi_set_vbus(struct usb_otg *otg, bool on) | 238 | static int ulpi_set_vbus(struct usb_otg *otg, bool on) |
239 | { | 239 | { |
240 | struct usb_phy *phy = otg->phy; | 240 | struct usb_phy *phy = otg->usb_phy; |
241 | unsigned int flags = usb_phy_io_read(phy, ULPI_OTG_CTRL); | 241 | unsigned int flags = usb_phy_io_read(phy, ULPI_OTG_CTRL); |
242 | 242 | ||
243 | flags &= ~(ULPI_OTG_CTRL_DRVVBUS | ULPI_OTG_CTRL_DRVVBUS_EXT); | 243 | flags &= ~(ULPI_OTG_CTRL_DRVVBUS | ULPI_OTG_CTRL_DRVVBUS_EXT); |
@@ -276,7 +276,7 @@ otg_ulpi_create(struct usb_phy_io_ops *ops, | |||
276 | phy->otg = otg; | 276 | phy->otg = otg; |
277 | phy->init = ulpi_init; | 277 | phy->init = ulpi_init; |
278 | 278 | ||
279 | otg->phy = phy; | 279 | otg->usb_phy = phy; |
280 | otg->set_host = ulpi_set_host; | 280 | otg->set_host = ulpi_set_host; |
281 | otg->set_vbus = ulpi_set_vbus; | 281 | otg->set_vbus = ulpi_set_vbus; |
282 | 282 | ||
diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 045cd309367a..b4066a001ba0 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c | |||
@@ -191,7 +191,9 @@ struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev, | |||
191 | 191 | ||
192 | phy = __of_usb_find_phy(node); | 192 | phy = __of_usb_find_phy(node); |
193 | if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) { | 193 | if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) { |
194 | phy = ERR_PTR(-EPROBE_DEFER); | 194 | if (!IS_ERR(phy)) |
195 | phy = ERR_PTR(-EPROBE_DEFER); | ||
196 | |||
195 | devres_free(ptr); | 197 | devres_free(ptr); |
196 | goto err1; | 198 | goto err1; |
197 | } | 199 | } |
@@ -444,3 +446,15 @@ int usb_bind_phy(const char *dev_name, u8 index, | |||
444 | return 0; | 446 | return 0; |
445 | } | 447 | } |
446 | EXPORT_SYMBOL_GPL(usb_bind_phy); | 448 | EXPORT_SYMBOL_GPL(usb_bind_phy); |
449 | |||
450 | /** | ||
451 | * usb_phy_set_event - set event to phy event | ||
452 | * @x: the phy returned by usb_get_phy(); | ||
453 | * | ||
454 | * This sets event to phy event | ||
455 | */ | ||
456 | void usb_phy_set_event(struct usb_phy *x, unsigned long event) | ||
457 | { | ||
458 | x->last_event = event; | ||
459 | } | ||
460 | EXPORT_SYMBOL_GPL(usb_phy_set_event); | ||
diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 169307ba08b7..371478704899 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c | |||
@@ -126,13 +126,15 @@ void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable) | |||
126 | void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable) | 126 | void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable) |
127 | { | 127 | { |
128 | u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; | 128 | u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; |
129 | u16 val = DPRPU | HSE | USBE; | 129 | u16 val = HSE | USBE; |
130 | 130 | ||
131 | /* | 131 | /* |
132 | * if enable | 132 | * if enable |
133 | * | 133 | * |
134 | * - select Function mode | 134 | * - select Function mode |
135 | * - D+ Line Pull-up | 135 | * - D+ Line Pull-up is disabled |
136 | * When D+ Line Pull-up is enabled, | ||
137 | * calling usbhs_sys_function_pullup(,1) | ||
136 | */ | 138 | */ |
137 | usbhs_bset(priv, SYSCFG, mask, enable ? val : 0); | 139 | usbhs_bset(priv, SYSCFG, mask, enable ? val : 0); |
138 | } | 140 | } |
diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h index a7996da6a1bd..0427cdd1a483 100644 --- a/drivers/usb/renesas_usbhs/common.h +++ b/drivers/usb/renesas_usbhs/common.h | |||
@@ -102,6 +102,10 @@ struct usbhs_priv; | |||
102 | #define DEVADD8 0x00E0 | 102 | #define DEVADD8 0x00E0 |
103 | #define DEVADD9 0x00E2 | 103 | #define DEVADD9 0x00E2 |
104 | #define DEVADDA 0x00E4 | 104 | #define DEVADDA 0x00E4 |
105 | #define D2FIFOSEL 0x00F0 /* for R-Car Gen2 */ | ||
106 | #define D2FIFOCTR 0x00F2 /* for R-Car Gen2 */ | ||
107 | #define D3FIFOSEL 0x00F4 /* for R-Car Gen2 */ | ||
108 | #define D3FIFOCTR 0x00F6 /* for R-Car Gen2 */ | ||
105 | 109 | ||
106 | /* SYSCFG */ | 110 | /* SYSCFG */ |
107 | #define SCKE (1 << 10) /* USB Module Clock Enable */ | 111 | #define SCKE (1 << 10) /* USB Module Clock Enable */ |
@@ -269,7 +273,8 @@ struct usbhs_priv { | |||
269 | */ | 273 | */ |
270 | struct usbhs_fifo_info fifo_info; | 274 | struct usbhs_fifo_info fifo_info; |
271 | 275 | ||
272 | struct usb_phy *phy; | 276 | struct usb_phy *usb_phy; |
277 | struct phy *phy; | ||
273 | }; | 278 | }; |
274 | 279 | ||
275 | /* | 280 | /* |
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c index b0c97a3f1bfe..f46271ce1b15 100644 --- a/drivers/usb/renesas_usbhs/fifo.c +++ b/drivers/usb/renesas_usbhs/fifo.c | |||
@@ -21,8 +21,6 @@ | |||
21 | #include "pipe.h" | 21 | #include "pipe.h" |
22 | 22 | ||
23 | #define usbhsf_get_cfifo(p) (&((p)->fifo_info.cfifo)) | 23 | #define usbhsf_get_cfifo(p) (&((p)->fifo_info.cfifo)) |
24 | #define usbhsf_get_d0fifo(p) (&((p)->fifo_info.d0fifo)) | ||
25 | #define usbhsf_get_d1fifo(p) (&((p)->fifo_info.d1fifo)) | ||
26 | #define usbhsf_is_cfifo(p, f) (usbhsf_get_cfifo(p) == f) | 24 | #define usbhsf_is_cfifo(p, f) (usbhsf_get_cfifo(p) == f) |
27 | 25 | ||
28 | #define usbhsf_fifo_is_busy(f) ((f)->pipe) /* see usbhs_pipe_select_fifo */ | 26 | #define usbhsf_fifo_is_busy(f) ((f)->pipe) /* see usbhs_pipe_select_fifo */ |
@@ -577,14 +575,6 @@ static int usbhsf_pio_try_push(struct usbhs_pkt *pkt, int *is_done) | |||
577 | usbhs_pipe_number(pipe), | 575 | usbhs_pipe_number(pipe), |
578 | pkt->length, pkt->actual, *is_done, pkt->zero); | 576 | pkt->length, pkt->actual, *is_done, pkt->zero); |
579 | 577 | ||
580 | /* | ||
581 | * Transmission end | ||
582 | */ | ||
583 | if (*is_done) { | ||
584 | if (usbhs_pipe_is_dcp(pipe)) | ||
585 | usbhs_dcp_control_transfer_done(pipe); | ||
586 | } | ||
587 | |||
588 | usbhsf_fifo_unselect(pipe, fifo); | 578 | usbhsf_fifo_unselect(pipe, fifo); |
589 | 579 | ||
590 | return 0; | 580 | return 0; |
@@ -722,14 +712,6 @@ usbhs_fifo_read_end: | |||
722 | usbhs_pipe_number(pipe), | 712 | usbhs_pipe_number(pipe), |
723 | pkt->length, pkt->actual, *is_done, pkt->zero); | 713 | pkt->length, pkt->actual, *is_done, pkt->zero); |
724 | 714 | ||
725 | /* | ||
726 | * Transmission end | ||
727 | */ | ||
728 | if (*is_done) { | ||
729 | if (usbhs_pipe_is_dcp(pipe)) | ||
730 | usbhs_dcp_control_transfer_done(pipe); | ||
731 | } | ||
732 | |||
733 | usbhs_fifo_read_busy: | 715 | usbhs_fifo_read_busy: |
734 | usbhsf_fifo_unselect(pipe, fifo); | 716 | usbhsf_fifo_unselect(pipe, fifo); |
735 | 717 | ||
@@ -777,18 +759,13 @@ static struct usbhs_fifo *usbhsf_get_dma_fifo(struct usbhs_priv *priv, | |||
777 | struct usbhs_pkt *pkt) | 759 | struct usbhs_pkt *pkt) |
778 | { | 760 | { |
779 | struct usbhs_fifo *fifo; | 761 | struct usbhs_fifo *fifo; |
762 | int i; | ||
780 | 763 | ||
781 | /* DMA :: D0FIFO */ | 764 | usbhs_for_each_dfifo(priv, fifo, i) { |
782 | fifo = usbhsf_get_d0fifo(priv); | 765 | if (usbhsf_dma_chan_get(fifo, pkt) && |
783 | if (usbhsf_dma_chan_get(fifo, pkt) && | 766 | !usbhsf_fifo_is_busy(fifo)) |
784 | !usbhsf_fifo_is_busy(fifo)) | 767 | return fifo; |
785 | return fifo; | 768 | } |
786 | |||
787 | /* DMA :: D1FIFO */ | ||
788 | fifo = usbhsf_get_d1fifo(priv); | ||
789 | if (usbhsf_dma_chan_get(fifo, pkt) && | ||
790 | !usbhsf_fifo_is_busy(fifo)) | ||
791 | return fifo; | ||
792 | 769 | ||
793 | return NULL; | 770 | return NULL; |
794 | } | 771 | } |
@@ -1176,6 +1153,24 @@ static void usbhsf_dma_complete(void *arg) | |||
1176 | usbhs_pipe_number(pipe), ret); | 1153 | usbhs_pipe_number(pipe), ret); |
1177 | } | 1154 | } |
1178 | 1155 | ||
1156 | void usbhs_fifo_clear_dcp(struct usbhs_pipe *pipe) | ||
1157 | { | ||
1158 | struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); | ||
1159 | struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */ | ||
1160 | |||
1161 | /* clear DCP FIFO of transmission */ | ||
1162 | if (usbhsf_fifo_select(pipe, fifo, 1) < 0) | ||
1163 | return; | ||
1164 | usbhsf_fifo_clear(pipe, fifo); | ||
1165 | usbhsf_fifo_unselect(pipe, fifo); | ||
1166 | |||
1167 | /* clear DCP FIFO of reception */ | ||
1168 | if (usbhsf_fifo_select(pipe, fifo, 0) < 0) | ||
1169 | return; | ||
1170 | usbhsf_fifo_clear(pipe, fifo); | ||
1171 | usbhsf_fifo_unselect(pipe, fifo); | ||
1172 | } | ||
1173 | |||
1179 | /* | 1174 | /* |
1180 | * fifo init | 1175 | * fifo init |
1181 | */ | 1176 | */ |
@@ -1183,8 +1178,8 @@ void usbhs_fifo_init(struct usbhs_priv *priv) | |||
1183 | { | 1178 | { |
1184 | struct usbhs_mod *mod = usbhs_mod_get_current(priv); | 1179 | struct usbhs_mod *mod = usbhs_mod_get_current(priv); |
1185 | struct usbhs_fifo *cfifo = usbhsf_get_cfifo(priv); | 1180 | struct usbhs_fifo *cfifo = usbhsf_get_cfifo(priv); |
1186 | struct usbhs_fifo *d0fifo = usbhsf_get_d0fifo(priv); | 1181 | struct usbhs_fifo *dfifo; |
1187 | struct usbhs_fifo *d1fifo = usbhsf_get_d1fifo(priv); | 1182 | int i; |
1188 | 1183 | ||
1189 | mod->irq_empty = usbhsf_irq_empty; | 1184 | mod->irq_empty = usbhsf_irq_empty; |
1190 | mod->irq_ready = usbhsf_irq_ready; | 1185 | mod->irq_ready = usbhsf_irq_ready; |
@@ -1192,8 +1187,8 @@ void usbhs_fifo_init(struct usbhs_priv *priv) | |||
1192 | mod->irq_brdysts = 0; | 1187 | mod->irq_brdysts = 0; |
1193 | 1188 | ||
1194 | cfifo->pipe = NULL; | 1189 | cfifo->pipe = NULL; |
1195 | d0fifo->pipe = NULL; | 1190 | usbhs_for_each_dfifo(priv, dfifo, i) |
1196 | d1fifo->pipe = NULL; | 1191 | dfifo->pipe = NULL; |
1197 | } | 1192 | } |
1198 | 1193 | ||
1199 | void usbhs_fifo_quit(struct usbhs_priv *priv) | 1194 | void usbhs_fifo_quit(struct usbhs_priv *priv) |
@@ -1206,6 +1201,25 @@ void usbhs_fifo_quit(struct usbhs_priv *priv) | |||
1206 | mod->irq_brdysts = 0; | 1201 | mod->irq_brdysts = 0; |
1207 | } | 1202 | } |
1208 | 1203 | ||
1204 | #define __USBHS_DFIFO_INIT(priv, fifo, channel, fifo_port) \ | ||
1205 | do { \ | ||
1206 | fifo = usbhsf_get_dnfifo(priv, channel); \ | ||
1207 | fifo->name = "D"#channel"FIFO"; \ | ||
1208 | fifo->port = fifo_port; \ | ||
1209 | fifo->sel = D##channel##FIFOSEL; \ | ||
1210 | fifo->ctr = D##channel##FIFOCTR; \ | ||
1211 | fifo->tx_slave.shdma_slave.slave_id = \ | ||
1212 | usbhs_get_dparam(priv, d##channel##_tx_id); \ | ||
1213 | fifo->rx_slave.shdma_slave.slave_id = \ | ||
1214 | usbhs_get_dparam(priv, d##channel##_rx_id); \ | ||
1215 | usbhsf_dma_init(priv, fifo); \ | ||
1216 | } while (0) | ||
1217 | |||
1218 | #define USBHS_DFIFO_INIT(priv, fifo, channel) \ | ||
1219 | __USBHS_DFIFO_INIT(priv, fifo, channel, D##channel##FIFO) | ||
1220 | #define USBHS_DFIFO_INIT_NO_PORT(priv, fifo, channel) \ | ||
1221 | __USBHS_DFIFO_INIT(priv, fifo, channel, 0) | ||
1222 | |||
1209 | int usbhs_fifo_probe(struct usbhs_priv *priv) | 1223 | int usbhs_fifo_probe(struct usbhs_priv *priv) |
1210 | { | 1224 | { |
1211 | struct usbhs_fifo *fifo; | 1225 | struct usbhs_fifo *fifo; |
@@ -1217,31 +1231,20 @@ int usbhs_fifo_probe(struct usbhs_priv *priv) | |||
1217 | fifo->sel = CFIFOSEL; | 1231 | fifo->sel = CFIFOSEL; |
1218 | fifo->ctr = CFIFOCTR; | 1232 | fifo->ctr = CFIFOCTR; |
1219 | 1233 | ||
1220 | /* D0FIFO */ | 1234 | /* DFIFO */ |
1221 | fifo = usbhsf_get_d0fifo(priv); | 1235 | USBHS_DFIFO_INIT(priv, fifo, 0); |
1222 | fifo->name = "D0FIFO"; | 1236 | USBHS_DFIFO_INIT(priv, fifo, 1); |
1223 | fifo->port = D0FIFO; | 1237 | USBHS_DFIFO_INIT_NO_PORT(priv, fifo, 2); |
1224 | fifo->sel = D0FIFOSEL; | 1238 | USBHS_DFIFO_INIT_NO_PORT(priv, fifo, 3); |
1225 | fifo->ctr = D0FIFOCTR; | ||
1226 | fifo->tx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d0_tx_id); | ||
1227 | fifo->rx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d0_rx_id); | ||
1228 | usbhsf_dma_init(priv, fifo); | ||
1229 | |||
1230 | /* D1FIFO */ | ||
1231 | fifo = usbhsf_get_d1fifo(priv); | ||
1232 | fifo->name = "D1FIFO"; | ||
1233 | fifo->port = D1FIFO; | ||
1234 | fifo->sel = D1FIFOSEL; | ||
1235 | fifo->ctr = D1FIFOCTR; | ||
1236 | fifo->tx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d1_tx_id); | ||
1237 | fifo->rx_slave.shdma_slave.slave_id = usbhs_get_dparam(priv, d1_rx_id); | ||
1238 | usbhsf_dma_init(priv, fifo); | ||
1239 | 1239 | ||
1240 | return 0; | 1240 | return 0; |
1241 | } | 1241 | } |
1242 | 1242 | ||
1243 | void usbhs_fifo_remove(struct usbhs_priv *priv) | 1243 | void usbhs_fifo_remove(struct usbhs_priv *priv) |
1244 | { | 1244 | { |
1245 | usbhsf_dma_quit(priv, usbhsf_get_d0fifo(priv)); | 1245 | struct usbhs_fifo *fifo; |
1246 | usbhsf_dma_quit(priv, usbhsf_get_d1fifo(priv)); | 1246 | int i; |
1247 | |||
1248 | usbhs_for_each_dfifo(priv, fifo, i) | ||
1249 | usbhsf_dma_quit(priv, fifo); | ||
1247 | } | 1250 | } |
diff --git a/drivers/usb/renesas_usbhs/fifo.h b/drivers/usb/renesas_usbhs/fifo.h index a168a1760fce..f07037c1185f 100644 --- a/drivers/usb/renesas_usbhs/fifo.h +++ b/drivers/usb/renesas_usbhs/fifo.h | |||
@@ -38,11 +38,16 @@ struct usbhs_fifo { | |||
38 | struct sh_dmae_slave rx_slave; | 38 | struct sh_dmae_slave rx_slave; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | #define USBHS_MAX_NUM_DFIFO 4 | ||
41 | struct usbhs_fifo_info { | 42 | struct usbhs_fifo_info { |
42 | struct usbhs_fifo cfifo; | 43 | struct usbhs_fifo cfifo; |
43 | struct usbhs_fifo d0fifo; | 44 | struct usbhs_fifo dfifo[USBHS_MAX_NUM_DFIFO]; |
44 | struct usbhs_fifo d1fifo; | ||
45 | }; | 45 | }; |
46 | #define usbhsf_get_dnfifo(p, n) (&((p)->fifo_info.dfifo[n])) | ||
47 | #define usbhs_for_each_dfifo(priv, dfifo, i) \ | ||
48 | for ((i) = 0, dfifo = usbhsf_get_dnfifo(priv, (i)); \ | ||
49 | ((i) < USBHS_MAX_NUM_DFIFO); \ | ||
50 | (i)++, dfifo = usbhsf_get_dnfifo(priv, (i))) | ||
46 | 51 | ||
47 | struct usbhs_pkt_handle; | 52 | struct usbhs_pkt_handle; |
48 | struct usbhs_pkt { | 53 | struct usbhs_pkt { |
@@ -74,6 +79,7 @@ int usbhs_fifo_probe(struct usbhs_priv *priv); | |||
74 | void usbhs_fifo_remove(struct usbhs_priv *priv); | 79 | void usbhs_fifo_remove(struct usbhs_priv *priv); |
75 | void usbhs_fifo_init(struct usbhs_priv *priv); | 80 | void usbhs_fifo_init(struct usbhs_priv *priv); |
76 | void usbhs_fifo_quit(struct usbhs_priv *priv); | 81 | void usbhs_fifo_quit(struct usbhs_priv *priv); |
82 | void usbhs_fifo_clear_dcp(struct usbhs_pipe *pipe); | ||
77 | 83 | ||
78 | /* | 84 | /* |
79 | * packet info | 85 | * packet info |
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index 2d17c10a0428..8697e6efcabf 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c | |||
@@ -56,6 +56,7 @@ struct usbhsg_gpriv { | |||
56 | #define USBHSG_STATUS_REGISTERD (1 << 1) | 56 | #define USBHSG_STATUS_REGISTERD (1 << 1) |
57 | #define USBHSG_STATUS_WEDGE (1 << 2) | 57 | #define USBHSG_STATUS_WEDGE (1 << 2) |
58 | #define USBHSG_STATUS_SELF_POWERED (1 << 3) | 58 | #define USBHSG_STATUS_SELF_POWERED (1 << 3) |
59 | #define USBHSG_STATUS_SOFT_CONNECT (1 << 4) | ||
59 | }; | 60 | }; |
60 | 61 | ||
61 | struct usbhsg_recip_handle { | 62 | struct usbhsg_recip_handle { |
@@ -484,6 +485,9 @@ static int usbhsg_irq_ctrl_stage(struct usbhs_priv *priv, | |||
484 | case NODATA_STATUS_STAGE: | 485 | case NODATA_STATUS_STAGE: |
485 | pipe->handler = &usbhs_ctrl_stage_end_handler; | 486 | pipe->handler = &usbhs_ctrl_stage_end_handler; |
486 | break; | 487 | break; |
488 | case READ_STATUS_STAGE: | ||
489 | case WRITE_STATUS_STAGE: | ||
490 | usbhs_dcp_control_transfer_done(pipe); | ||
487 | default: | 491 | default: |
488 | return ret; | 492 | return ret; |
489 | } | 493 | } |
@@ -602,6 +606,9 @@ static int usbhsg_ep_disable(struct usb_ep *ep) | |||
602 | struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep); | 606 | struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep); |
603 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); | 607 | struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); |
604 | 608 | ||
609 | if (!pipe) | ||
610 | return -EINVAL; | ||
611 | |||
605 | usbhsg_pipe_disable(uep); | 612 | usbhsg_pipe_disable(uep); |
606 | usbhs_pipe_free(pipe); | 613 | usbhs_pipe_free(pipe); |
607 | 614 | ||
@@ -723,6 +730,25 @@ static struct usb_ep_ops usbhsg_ep_ops = { | |||
723 | }; | 730 | }; |
724 | 731 | ||
725 | /* | 732 | /* |
733 | * pullup control | ||
734 | */ | ||
735 | static int usbhsg_can_pullup(struct usbhs_priv *priv) | ||
736 | { | ||
737 | struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); | ||
738 | |||
739 | return gpriv->driver && | ||
740 | usbhsg_status_has(gpriv, USBHSG_STATUS_SOFT_CONNECT); | ||
741 | } | ||
742 | |||
743 | static void usbhsg_update_pullup(struct usbhs_priv *priv) | ||
744 | { | ||
745 | if (usbhsg_can_pullup(priv)) | ||
746 | usbhs_sys_function_pullup(priv, 1); | ||
747 | else | ||
748 | usbhs_sys_function_pullup(priv, 0); | ||
749 | } | ||
750 | |||
751 | /* | ||
726 | * usb module start/end | 752 | * usb module start/end |
727 | */ | 753 | */ |
728 | static int usbhsg_try_start(struct usbhs_priv *priv, u32 status) | 754 | static int usbhsg_try_start(struct usbhs_priv *priv, u32 status) |
@@ -756,9 +782,9 @@ static int usbhsg_try_start(struct usbhs_priv *priv, u32 status) | |||
756 | /* | 782 | /* |
757 | * pipe initialize and enable DCP | 783 | * pipe initialize and enable DCP |
758 | */ | 784 | */ |
785 | usbhs_fifo_init(priv); | ||
759 | usbhs_pipe_init(priv, | 786 | usbhs_pipe_init(priv, |
760 | usbhsg_dma_map_ctrl); | 787 | usbhsg_dma_map_ctrl); |
761 | usbhs_fifo_init(priv); | ||
762 | 788 | ||
763 | /* dcp init instead of usbhsg_ep_enable() */ | 789 | /* dcp init instead of usbhsg_ep_enable() */ |
764 | dcp->pipe = usbhs_dcp_malloc(priv); | 790 | dcp->pipe = usbhs_dcp_malloc(priv); |
@@ -772,6 +798,7 @@ static int usbhsg_try_start(struct usbhs_priv *priv, u32 status) | |||
772 | * - usb module | 798 | * - usb module |
773 | */ | 799 | */ |
774 | usbhs_sys_function_ctrl(priv, 1); | 800 | usbhs_sys_function_ctrl(priv, 1); |
801 | usbhsg_update_pullup(priv); | ||
775 | 802 | ||
776 | /* | 803 | /* |
777 | * enable irq callback | 804 | * enable irq callback |
@@ -851,8 +878,7 @@ static int usbhsg_gadget_start(struct usb_gadget *gadget, | |||
851 | return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD); | 878 | return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD); |
852 | } | 879 | } |
853 | 880 | ||
854 | static int usbhsg_gadget_stop(struct usb_gadget *gadget, | 881 | static int usbhsg_gadget_stop(struct usb_gadget *gadget) |
855 | struct usb_gadget_driver *driver) | ||
856 | { | 882 | { |
857 | struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); | 883 | struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); |
858 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); | 884 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); |
@@ -878,8 +904,15 @@ static int usbhsg_pullup(struct usb_gadget *gadget, int is_on) | |||
878 | { | 904 | { |
879 | struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); | 905 | struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); |
880 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); | 906 | struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); |
907 | unsigned long flags; | ||
881 | 908 | ||
882 | usbhs_sys_function_pullup(priv, is_on); | 909 | usbhs_lock(priv, flags); |
910 | if (is_on) | ||
911 | usbhsg_status_set(gpriv, USBHSG_STATUS_SOFT_CONNECT); | ||
912 | else | ||
913 | usbhsg_status_clr(gpriv, USBHSG_STATUS_SOFT_CONNECT); | ||
914 | usbhsg_update_pullup(priv); | ||
915 | usbhs_unlock(priv, flags); | ||
883 | 916 | ||
884 | return 0; | 917 | return 0; |
885 | } | 918 | } |
diff --git a/drivers/usb/renesas_usbhs/mod_host.c b/drivers/usb/renesas_usbhs/mod_host.c index 10e1ded9c9cc..f0d323125871 100644 --- a/drivers/usb/renesas_usbhs/mod_host.c +++ b/drivers/usb/renesas_usbhs/mod_host.c | |||
@@ -1474,9 +1474,9 @@ static int usbhsh_start(struct usbhs_priv *priv) | |||
1474 | /* | 1474 | /* |
1475 | * pipe initialize and enable DCP | 1475 | * pipe initialize and enable DCP |
1476 | */ | 1476 | */ |
1477 | usbhs_fifo_init(priv); | ||
1477 | usbhs_pipe_init(priv, | 1478 | usbhs_pipe_init(priv, |
1478 | usbhsh_dma_map_ctrl); | 1479 | usbhsh_dma_map_ctrl); |
1479 | usbhs_fifo_init(priv); | ||
1480 | usbhsh_pipe_init_for_host(priv); | 1480 | usbhsh_pipe_init_for_host(priv); |
1481 | 1481 | ||
1482 | /* | 1482 | /* |
diff --git a/drivers/usb/renesas_usbhs/pipe.c b/drivers/usb/renesas_usbhs/pipe.c index 040bcefcb040..007f45abe96c 100644 --- a/drivers/usb/renesas_usbhs/pipe.c +++ b/drivers/usb/renesas_usbhs/pipe.c | |||
@@ -618,8 +618,12 @@ void usbhs_pipe_data_sequence(struct usbhs_pipe *pipe, int sequence) | |||
618 | 618 | ||
619 | void usbhs_pipe_clear(struct usbhs_pipe *pipe) | 619 | void usbhs_pipe_clear(struct usbhs_pipe *pipe) |
620 | { | 620 | { |
621 | usbhsp_pipectrl_set(pipe, ACLRM, ACLRM); | 621 | if (usbhs_pipe_is_dcp(pipe)) { |
622 | usbhsp_pipectrl_set(pipe, ACLRM, 0); | 622 | usbhs_fifo_clear_dcp(pipe); |
623 | } else { | ||
624 | usbhsp_pipectrl_set(pipe, ACLRM, ACLRM); | ||
625 | usbhsp_pipectrl_set(pipe, ACLRM, 0); | ||
626 | } | ||
623 | } | 627 | } |
624 | 628 | ||
625 | static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type) | 629 | static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type) |
diff --git a/drivers/usb/renesas_usbhs/rcar2.c b/drivers/usb/renesas_usbhs/rcar2.c index e6b9dcc1c289..8fc15c0ba339 100644 --- a/drivers/usb/renesas_usbhs/rcar2.c +++ b/drivers/usb/renesas_usbhs/rcar2.c | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #include <linux/gpio.h> | 13 | #include <linux/gpio.h> |
14 | #include <linux/of_gpio.h> | 14 | #include <linux/of_gpio.h> |
15 | #include <linux/phy/phy.h> | ||
15 | #include <linux/platform_data/gpio-rcar.h> | 16 | #include <linux/platform_data/gpio-rcar.h> |
16 | #include <linux/usb/phy.h> | 17 | #include <linux/usb/phy.h> |
17 | #include "common.h" | 18 | #include "common.h" |
@@ -20,25 +21,43 @@ | |||
20 | static int usbhs_rcar2_hardware_init(struct platform_device *pdev) | 21 | static int usbhs_rcar2_hardware_init(struct platform_device *pdev) |
21 | { | 22 | { |
22 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); | 23 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); |
23 | struct usb_phy *phy; | ||
24 | 24 | ||
25 | phy = usb_get_phy_dev(&pdev->dev, 0); | 25 | if (IS_ENABLED(CONFIG_GENERIC_PHY)) { |
26 | if (IS_ERR(phy)) | 26 | struct phy *phy = phy_get(&pdev->dev, "usb"); |
27 | return PTR_ERR(phy); | ||
28 | 27 | ||
29 | priv->phy = phy; | 28 | if (IS_ERR(phy)) |
30 | return 0; | 29 | return PTR_ERR(phy); |
30 | |||
31 | priv->phy = phy; | ||
32 | return 0; | ||
33 | } | ||
34 | |||
35 | if (IS_ENABLED(CONFIG_USB_PHY)) { | ||
36 | struct usb_phy *usb_phy = usb_get_phy_dev(&pdev->dev, 0); | ||
37 | |||
38 | if (IS_ERR(usb_phy)) | ||
39 | return PTR_ERR(usb_phy); | ||
40 | |||
41 | priv->usb_phy = usb_phy; | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | return -ENXIO; | ||
31 | } | 46 | } |
32 | 47 | ||
33 | static int usbhs_rcar2_hardware_exit(struct platform_device *pdev) | 48 | static int usbhs_rcar2_hardware_exit(struct platform_device *pdev) |
34 | { | 49 | { |
35 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); | 50 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); |
36 | 51 | ||
37 | if (!priv->phy) | 52 | if (priv->phy) { |
38 | return 0; | 53 | phy_put(priv->phy); |
54 | priv->phy = NULL; | ||
55 | } | ||
39 | 56 | ||
40 | usb_put_phy(priv->phy); | 57 | if (priv->usb_phy) { |
41 | priv->phy = NULL; | 58 | usb_put_phy(priv->usb_phy); |
59 | priv->usb_phy = NULL; | ||
60 | } | ||
42 | 61 | ||
43 | return 0; | 62 | return 0; |
44 | } | 63 | } |
@@ -47,21 +66,35 @@ static int usbhs_rcar2_power_ctrl(struct platform_device *pdev, | |||
47 | void __iomem *base, int enable) | 66 | void __iomem *base, int enable) |
48 | { | 67 | { |
49 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); | 68 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); |
69 | int retval = -ENODEV; | ||
70 | |||
71 | if (priv->phy) { | ||
72 | if (enable) { | ||
73 | retval = phy_init(priv->phy); | ||
50 | 74 | ||
51 | if (!priv->phy) | 75 | if (!retval) |
52 | return -ENODEV; | 76 | retval = phy_power_on(priv->phy); |
77 | } else { | ||
78 | phy_power_off(priv->phy); | ||
79 | phy_exit(priv->phy); | ||
80 | retval = 0; | ||
81 | } | ||
82 | } | ||
53 | 83 | ||
54 | if (enable) { | 84 | if (priv->usb_phy) { |
55 | int retval = usb_phy_init(priv->phy); | 85 | if (enable) { |
86 | retval = usb_phy_init(priv->usb_phy); | ||
56 | 87 | ||
57 | if (!retval) | 88 | if (!retval) |
58 | retval = usb_phy_set_suspend(priv->phy, 0); | 89 | retval = usb_phy_set_suspend(priv->usb_phy, 0); |
59 | return retval; | 90 | } else { |
91 | usb_phy_set_suspend(priv->usb_phy, 1); | ||
92 | usb_phy_shutdown(priv->usb_phy); | ||
93 | retval = 0; | ||
94 | } | ||
60 | } | 95 | } |
61 | 96 | ||
62 | usb_phy_set_suspend(priv->phy, 1); | 97 | return retval; |
63 | usb_phy_shutdown(priv->phy); | ||
64 | return 0; | ||
65 | } | 98 | } |
66 | 99 | ||
67 | static int usbhs_rcar2_get_id(struct platform_device *pdev) | 100 | static int usbhs_rcar2_get_id(struct platform_device *pdev) |
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h index 1fa99a301817..5decad77d8ed 100644 --- a/include/linux/pci_ids.h +++ b/include/linux/pci_ids.h | |||
@@ -562,6 +562,7 @@ | |||
562 | #define PCI_DEVICE_ID_AMD_8131_BRIDGE 0x7450 | 562 | #define PCI_DEVICE_ID_AMD_8131_BRIDGE 0x7450 |
563 | #define PCI_DEVICE_ID_AMD_8131_APIC 0x7451 | 563 | #define PCI_DEVICE_ID_AMD_8131_APIC 0x7451 |
564 | #define PCI_DEVICE_ID_AMD_8132_BRIDGE 0x7458 | 564 | #define PCI_DEVICE_ID_AMD_8132_BRIDGE 0x7458 |
565 | #define PCI_DEVICE_ID_AMD_NL_USB 0x7912 | ||
565 | #define PCI_DEVICE_ID_AMD_CS5535_IDE 0x208F | 566 | #define PCI_DEVICE_ID_AMD_CS5535_IDE 0x208F |
566 | #define PCI_DEVICE_ID_AMD_CS5536_ISA 0x2090 | 567 | #define PCI_DEVICE_ID_AMD_CS5536_ISA 0x2090 |
567 | #define PCI_DEVICE_ID_AMD_CS5536_FLASH 0x2091 | 568 | #define PCI_DEVICE_ID_AMD_CS5536_FLASH 0x2091 |
diff --git a/include/linux/platform_data/dwc3-exynos.h b/include/linux/platform_data/dwc3-exynos.h deleted file mode 100644 index 5eb7da9b3772..000000000000 --- a/include/linux/platform_data/dwc3-exynos.h +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | /** | ||
2 | * dwc3-exynos.h - Samsung EXYNOS DWC3 Specific Glue layer, header. | ||
3 | * | ||
4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. | ||
5 | * http://www.samsung.com | ||
6 | * | ||
7 | * Author: Anton Tikhomirov <av.tikhomirov@samsung.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | */ | ||
14 | |||
15 | #ifndef _DWC3_EXYNOS_H_ | ||
16 | #define _DWC3_EXYNOS_H_ | ||
17 | |||
18 | struct dwc3_exynos_data { | ||
19 | int phy_type; | ||
20 | int (*phy_init)(struct platform_device *pdev, int type); | ||
21 | int (*phy_exit)(struct platform_device *pdev, int type); | ||
22 | }; | ||
23 | |||
24 | #endif /* _DWC3_EXYNOS_H_ */ | ||
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index e14c09a45c5a..c01bf4ea27b9 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h | |||
@@ -13,7 +13,9 @@ struct ci_hdrc_platform_data { | |||
13 | /* offset of the capability registers */ | 13 | /* offset of the capability registers */ |
14 | uintptr_t capoffset; | 14 | uintptr_t capoffset; |
15 | unsigned power_budget; | 15 | unsigned power_budget; |
16 | struct usb_phy *phy; | 16 | struct phy *phy; |
17 | /* old usb_phy interface */ | ||
18 | struct usb_phy *usb_phy; | ||
17 | enum usb_phy_interface phy_mode; | 19 | enum usb_phy_interface phy_mode; |
18 | unsigned long flags; | 20 | unsigned long flags; |
19 | #define CI_HDRC_REGS_SHARED BIT(0) | 21 | #define CI_HDRC_REGS_SHARED BIT(0) |
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index c330f5ef42cf..3d87defcc527 100644 --- a/include/linux/usb/composite.h +++ b/include/linux/usb/composite.h | |||
@@ -427,6 +427,8 @@ static inline struct usb_composite_driver *to_cdriver( | |||
427 | * @b_vendor_code: bMS_VendorCode part of the OS string | 427 | * @b_vendor_code: bMS_VendorCode part of the OS string |
428 | * @use_os_string: false by default, interested gadgets set it | 428 | * @use_os_string: false by default, interested gadgets set it |
429 | * @os_desc_config: the configuration to be used with OS descriptors | 429 | * @os_desc_config: the configuration to be used with OS descriptors |
430 | * @setup_pending: true when setup request is queued but not completed | ||
431 | * @os_desc_pending: true when os_desc request is queued but not completed | ||
430 | * | 432 | * |
431 | * One of these devices is allocated and initialized before the | 433 | * One of these devices is allocated and initialized before the |
432 | * associated device driver's bind() is called. | 434 | * associated device driver's bind() is called. |
@@ -488,6 +490,9 @@ struct usb_composite_dev { | |||
488 | 490 | ||
489 | /* protects deactivations and delayed_status counts*/ | 491 | /* protects deactivations and delayed_status counts*/ |
490 | spinlock_t lock; | 492 | spinlock_t lock; |
493 | |||
494 | unsigned setup_pending:1; | ||
495 | unsigned os_desc_pending:1; | ||
491 | }; | 496 | }; |
492 | 497 | ||
493 | extern int usb_string_id(struct usb_composite_dev *c); | 498 | extern int usb_string_id(struct usb_composite_dev *c); |
@@ -501,6 +506,8 @@ extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); | |||
501 | extern void composite_disconnect(struct usb_gadget *gadget); | 506 | extern void composite_disconnect(struct usb_gadget *gadget); |
502 | extern int composite_setup(struct usb_gadget *gadget, | 507 | extern int composite_setup(struct usb_gadget *gadget, |
503 | const struct usb_ctrlrequest *ctrl); | 508 | const struct usb_ctrlrequest *ctrl); |
509 | extern void composite_suspend(struct usb_gadget *gadget); | ||
510 | extern void composite_resume(struct usb_gadget *gadget); | ||
504 | 511 | ||
505 | /* | 512 | /* |
506 | * Some systems will need runtime overrides for the product identifiers | 513 | * Some systems will need runtime overrides for the product identifiers |
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 522cafe26790..70ddb3943b62 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h | |||
@@ -490,8 +490,7 @@ struct usb_gadget_ops { | |||
490 | void (*get_config_params)(struct usb_dcd_config_params *); | 490 | void (*get_config_params)(struct usb_dcd_config_params *); |
491 | int (*udc_start)(struct usb_gadget *, | 491 | int (*udc_start)(struct usb_gadget *, |
492 | struct usb_gadget_driver *); | 492 | struct usb_gadget_driver *); |
493 | int (*udc_stop)(struct usb_gadget *, | 493 | int (*udc_stop)(struct usb_gadget *); |
494 | struct usb_gadget_driver *); | ||
495 | }; | 494 | }; |
496 | 495 | ||
497 | /** | 496 | /** |
@@ -925,7 +924,7 @@ extern int usb_add_gadget_udc_release(struct device *parent, | |||
925 | struct usb_gadget *gadget, void (*release)(struct device *dev)); | 924 | struct usb_gadget *gadget, void (*release)(struct device *dev)); |
926 | extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); | 925 | extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); |
927 | extern void usb_del_gadget_udc(struct usb_gadget *gadget); | 926 | extern void usb_del_gadget_udc(struct usb_gadget *gadget); |
928 | extern int udc_attach_driver(const char *name, | 927 | extern int usb_udc_attach_driver(const char *name, |
929 | struct usb_gadget_driver *driver); | 928 | struct usb_gadget_driver *driver); |
930 | 929 | ||
931 | /*-------------------------------------------------------------------------*/ | 930 | /*-------------------------------------------------------------------------*/ |
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 154332b7c8c0..52661c5da690 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h | |||
@@ -9,15 +9,20 @@ | |||
9 | #ifndef __LINUX_USB_OTG_H | 9 | #ifndef __LINUX_USB_OTG_H |
10 | #define __LINUX_USB_OTG_H | 10 | #define __LINUX_USB_OTG_H |
11 | 11 | ||
12 | #include <linux/phy/phy.h> | ||
12 | #include <linux/usb/phy.h> | 13 | #include <linux/usb/phy.h> |
13 | 14 | ||
14 | struct usb_otg { | 15 | struct usb_otg { |
15 | u8 default_a; | 16 | u8 default_a; |
16 | 17 | ||
17 | struct usb_phy *phy; | 18 | struct phy *phy; |
19 | /* old usb_phy interface */ | ||
20 | struct usb_phy *usb_phy; | ||
18 | struct usb_bus *host; | 21 | struct usb_bus *host; |
19 | struct usb_gadget *gadget; | 22 | struct usb_gadget *gadget; |
20 | 23 | ||
24 | enum usb_otg_state state; | ||
25 | |||
21 | /* bind/unbind the host controller */ | 26 | /* bind/unbind the host controller */ |
22 | int (*set_host)(struct usb_otg *otg, struct usb_bus *host); | 27 | int (*set_host)(struct usb_otg *otg, struct usb_bus *host); |
23 | 28 | ||
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 353053a33f21..f499c23e6342 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h | |||
@@ -77,7 +77,6 @@ struct usb_phy { | |||
77 | unsigned int flags; | 77 | unsigned int flags; |
78 | 78 | ||
79 | enum usb_phy_type type; | 79 | enum usb_phy_type type; |
80 | enum usb_otg_state state; | ||
81 | enum usb_phy_events last_event; | 80 | enum usb_phy_events last_event; |
82 | 81 | ||
83 | struct usb_otg *otg; | 82 | struct usb_otg *otg; |
@@ -210,6 +209,7 @@ extern void usb_put_phy(struct usb_phy *); | |||
210 | extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x); | 209 | extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x); |
211 | extern int usb_bind_phy(const char *dev_name, u8 index, | 210 | extern int usb_bind_phy(const char *dev_name, u8 index, |
212 | const char *phy_dev_name); | 211 | const char *phy_dev_name); |
212 | extern void usb_phy_set_event(struct usb_phy *x, unsigned long event); | ||
213 | #else | 213 | #else |
214 | static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) | 214 | static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) |
215 | { | 215 | { |
@@ -251,6 +251,10 @@ static inline int usb_bind_phy(const char *dev_name, u8 index, | |||
251 | { | 251 | { |
252 | return -EOPNOTSUPP; | 252 | return -EOPNOTSUPP; |
253 | } | 253 | } |
254 | |||
255 | static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event) | ||
256 | { | ||
257 | } | ||
254 | #endif | 258 | #endif |
255 | 259 | ||
256 | static inline int | 260 | static inline int |
diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index d5952bb66752..9fd9e481ea98 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h | |||
@@ -145,6 +145,10 @@ struct renesas_usbhs_driver_param { | |||
145 | int d0_rx_id; | 145 | int d0_rx_id; |
146 | int d1_tx_id; | 146 | int d1_tx_id; |
147 | int d1_rx_id; | 147 | int d1_rx_id; |
148 | int d2_tx_id; | ||
149 | int d2_rx_id; | ||
150 | int d3_tx_id; | ||
151 | int d3_rx_id; | ||
148 | 152 | ||
149 | /* | 153 | /* |
150 | * option: | 154 | * option: |