aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-08-22 16:16:06 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-08-22 16:16:06 -0400
commit34a0036748257dd97b22b76ef64aa44559f2ef6f (patch)
tree48384dca01f8fd8bbf566ca0df07e80b18d32fec
parenta85c0f8db3329ab433dab49322616e6985317cd7 (diff)
parent0852659ef071ccd84e85e37195e7c2f3e7c64d1f (diff)
Merge tag 'usb-for-v4.14' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
Felipe writes: usb: changes for v4.14 merge window Not a big pull request this time around. Only 49 non-merge commits. This pull request is, however, all over the place. Most of the changes are in the bdc driver adding support for USB Phy layer and PM. Renesas adds support for R-Car H3 ES2.0 and R-Car M3-W SoCs. Also here is PM_RUNTIME support for dwc3-keystone. UDC Core got a DMA unmap fix to make sure we only unmap requests that were, indeed, mapped. Other than these, we have a lot of cleanups, many of them adding 'const' to several places.
-rw-r--r--Documentation/ABI/testing/configfs-usb-gadget-rndis3
-rw-r--r--Documentation/devicetree/bindings/mfd/wm831x.txt1
-rw-r--r--Documentation/devicetree/bindings/usb/brcm,bdc.txt29
-rw-r--r--Documentation/devicetree/bindings/usb/keystone-usb.txt17
-rw-r--r--Documentation/devicetree/bindings/usb/renesas_usb3.txt16
-rw-r--r--drivers/power/supply/wm831x_power.c72
-rw-r--r--drivers/usb/dwc2/gadget.c2
-rw-r--r--drivers/usb/dwc2/hcd.c6
-rw-r--r--drivers/usb/dwc3/dwc3-keystone.c22
-rw-r--r--drivers/usb/dwc3/dwc3-of-simple.c4
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c4
-rw-r--r--drivers/usb/gadget/Kconfig2
-rw-r--r--drivers/usb/gadget/function/f_fs.c7
-rw-r--r--drivers/usb/gadget/function/f_hid.c17
-rw-r--r--drivers/usb/gadget/function/f_midi.c68
-rw-r--r--drivers/usb/gadget/function/f_ncm.c2
-rw-r--r--drivers/usb/gadget/function/f_rndis.c20
-rw-r--r--drivers/usb/gadget/function/u_ether.c2
-rw-r--r--drivers/usb/gadget/function/u_ether.h1
-rw-r--r--drivers/usb/gadget/function/u_ether_configfs.h35
-rw-r--r--drivers/usb/gadget/function/u_rndis.h4
-rw-r--r--drivers/usb/gadget/function/u_serial.c2
-rw-r--r--drivers/usb/gadget/udc/bdc/Kconfig1
-rw-r--r--drivers/usb/gadget/udc/bdc/bdc.h24
-rw-r--r--drivers/usb/gadget/udc/bdc/bdc_core.c148
-rw-r--r--drivers/usb/gadget/udc/bdc/bdc_dbg.c16
-rw-r--r--drivers/usb/gadget/udc/bdc/bdc_ep.c4
-rw-r--r--drivers/usb/gadget/udc/bdc/bdc_udc.c7
-rw-r--r--drivers/usb/gadget/udc/core.c20
-rw-r--r--drivers/usb/gadget/udc/dummy_hcd.c2
-rw-r--r--drivers/usb/gadget/udc/renesas_usb3.c117
-rw-r--r--drivers/usb/mtu3/mtu3_plat.c1
-rw-r--r--drivers/usb/phy/phy-qcom-8x16-usb.c9
-rw-r--r--drivers/usb/phy/phy.c272
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c4
-rw-r--r--include/linux/hid.h6
-rw-r--r--include/linux/usb/gadget.h2
-rw-r--r--include/linux/usb/phy.h49
-rw-r--r--include/uapi/linux/usb/charger.h31
39 files changed, 950 insertions, 99 deletions
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-rndis b/Documentation/ABI/testing/configfs-usb-gadget-rndis
index e32879b84b4d..137399095d74 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-rndis
+++ b/Documentation/ABI/testing/configfs-usb-gadget-rndis
@@ -12,3 +12,6 @@ Description:
12 Ethernet over USB link 12 Ethernet over USB link
13 dev_addr - MAC address of device's end of this 13 dev_addr - MAC address of device's end of this
14 Ethernet over USB link 14 Ethernet over USB link
15 class - USB interface class, default is 02 (hex)
16 subclass - USB interface subclass, default is 06 (hex)
17 protocol - USB interface protocol, default is 00 (hex)
diff --git a/Documentation/devicetree/bindings/mfd/wm831x.txt b/Documentation/devicetree/bindings/mfd/wm831x.txt
index 9f8b7430673c..505709403d3f 100644
--- a/Documentation/devicetree/bindings/mfd/wm831x.txt
+++ b/Documentation/devicetree/bindings/mfd/wm831x.txt
@@ -31,6 +31,7 @@ Required properties:
31 ../interrupt-controller/interrupts.txt 31 ../interrupt-controller/interrupts.txt
32 32
33Optional sub-nodes: 33Optional sub-nodes:
34 - phys : Contains a phandle to the USB PHY.
34 - regulators : Contains sub-nodes for each of the regulators supplied by 35 - regulators : Contains sub-nodes for each of the regulators supplied by
35 the device. The regulators are bound using their names listed below: 36 the device. The regulators are bound using their names listed below:
36 37
diff --git a/Documentation/devicetree/bindings/usb/brcm,bdc.txt b/Documentation/devicetree/bindings/usb/brcm,bdc.txt
new file mode 100644
index 000000000000..63e63af3bf59
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/brcm,bdc.txt
@@ -0,0 +1,29 @@
1Broadcom USB Device Controller (BDC)
2====================================
3
4Required properties:
5
6- compatible: must be one of:
7 "brcm,bdc-v0.16"
8 "brcm,bdc"
9- reg: the base register address and length
10- interrupts: the interrupt line for this controller
11
12Optional properties:
13
14On Broadcom STB platforms, these properties are required:
15
16- phys: phandle to one or two USB PHY blocks
17 NOTE: Some SoC's have a single phy and some have
18 USB 2.0 and USB 3.0 phys
19- clocks: phandle to the functional clock of this block
20
21Example:
22
23 bdc@f0b02000 {
24 compatible = "brcm,bdc-v0.16";
25 reg = <0xf0b02000 0xfc4>;
26 interrupts = <0x0 0x60 0x0>;
27 phys = <&usbphy_0 0x0>;
28 clocks = <&sw_usbd>;
29 };
diff --git a/Documentation/devicetree/bindings/usb/keystone-usb.txt b/Documentation/devicetree/bindings/usb/keystone-usb.txt
index 60527d335b58..2d1bef16f149 100644
--- a/Documentation/devicetree/bindings/usb/keystone-usb.txt
+++ b/Documentation/devicetree/bindings/usb/keystone-usb.txt
@@ -12,8 +12,21 @@ Required properties:
12 MPU. 12 MPU.
13 - ranges: allows valid 1:1 translation between child's address space and 13 - ranges: allows valid 1:1 translation between child's address space and
14 parent's address space. 14 parent's address space.
15 - clocks: Clock IDs array as required by the controller. 15
16 - clock-names: names of clocks correseponding to IDs in the clock property. 16SoC-specific Required Properties:
17The following are mandatory properties for Keystone 2 66AK2HK, 66AK2L and 66AK2E
18SoCs only:
19
20- clocks: Clock ID for USB functional clock.
21- clock-names: Must be "usb".
22
23
24The following are mandatory properties for Keystone 2 66AK2G SoCs only:
25
26- power-domains: Should contain a phandle to a PM domain provider node
27 and an args specifier containing the USB device id
28 value. This property is as per the binding,
29 Documentation/devicetree/bindings/soc/ti/sci-pm-domain.txt
17 30
18Sub-nodes: 31Sub-nodes:
19The dwc3 core should be added as subnode to Keystone DWC3 glue. 32The dwc3 core should be added as subnode to Keystone DWC3 glue.
diff --git a/Documentation/devicetree/bindings/usb/renesas_usb3.txt b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
index 8d52766f07b9..e28025883b79 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usb3.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
@@ -3,20 +3,30 @@ Renesas Electronics USB3.0 Peripheral driver
3Required properties: 3Required properties:
4 - compatible: Must contain one of the following: 4 - compatible: Must contain one of the following:
5 - "renesas,r8a7795-usb3-peri" 5 - "renesas,r8a7795-usb3-peri"
6 - "renesas,r8a7796-usb3-peri"
7 - "renesas,rcar-gen3-usb3-peri" for a generic R-Car Gen3 compatible
8 device
9
10 When compatible with the generic version, nodes must list the
11 SoC-specific version corresponding to the platform first
12 followed by the generic version.
13
6 - reg: Base address and length of the register for the USB3.0 Peripheral 14 - reg: Base address and length of the register for the USB3.0 Peripheral
7 - interrupts: Interrupt specifier for the USB3.0 Peripheral 15 - interrupts: Interrupt specifier for the USB3.0 Peripheral
8 - clocks: clock phandle and specifier pair 16 - clocks: clock phandle and specifier pair
9 17
10Example: 18Example of R-Car H3 ES1.x:
11 usb3_peri0: usb@ee020000 { 19 usb3_peri0: usb@ee020000 {
12 compatible = "renesas,r8a7795-usb3-peri"; 20 compatible = "renesas,r8a7795-usb3-peri",
21 "renesas,rcar-gen3-usb3-peri";
13 reg = <0 0xee020000 0 0x400>; 22 reg = <0 0xee020000 0 0x400>;
14 interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>; 23 interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
15 clocks = <&cpg CPG_MOD 328>; 24 clocks = <&cpg CPG_MOD 328>;
16 }; 25 };
17 26
18 usb3_peri1: usb@ee060000 { 27 usb3_peri1: usb@ee060000 {
19 compatible = "renesas,r8a7795-usb3-peri"; 28 compatible = "renesas,r8a7795-usb3-peri",
29 "renesas,rcar-gen3-usb3-peri";
20 reg = <0 0xee060000 0 0x400>; 30 reg = <0 0xee060000 0 0x400>;
21 interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>; 31 interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
22 clocks = <&cpg CPG_MOD 327>; 32 clocks = <&cpg CPG_MOD 327>;
diff --git a/drivers/power/supply/wm831x_power.c b/drivers/power/supply/wm831x_power.c
index 7082301da945..927050d4444d 100644
--- a/drivers/power/supply/wm831x_power.c
+++ b/drivers/power/supply/wm831x_power.c
@@ -13,6 +13,7 @@
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/power_supply.h> 14#include <linux/power_supply.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/usb/phy.h>
16 17
17#include <linux/mfd/wm831x/core.h> 18#include <linux/mfd/wm831x/core.h>
18#include <linux/mfd/wm831x/auxadc.h> 19#include <linux/mfd/wm831x/auxadc.h>
@@ -31,6 +32,8 @@ struct wm831x_power {
31 char usb_name[20]; 32 char usb_name[20];
32 char battery_name[20]; 33 char battery_name[20];
33 bool have_battery; 34 bool have_battery;
35 struct usb_phy *usb_phy;
36 struct notifier_block usb_notify;
34}; 37};
35 38
36static int wm831x_power_check_online(struct wm831x *wm831x, int supply, 39static int wm831x_power_check_online(struct wm831x *wm831x, int supply,
@@ -125,6 +128,43 @@ static enum power_supply_property wm831x_usb_props[] = {
125 POWER_SUPPLY_PROP_VOLTAGE_NOW, 128 POWER_SUPPLY_PROP_VOLTAGE_NOW,
126}; 129};
127 130
131/* In milliamps */
132static const unsigned int wm831x_usb_limits[] = {
133 0,
134 2,
135 100,
136 500,
137 900,
138 1500,
139 1800,
140 550,
141};
142
143static int wm831x_usb_limit_change(struct notifier_block *nb,
144 unsigned long limit, void *data)
145{
146 struct wm831x_power *wm831x_power = container_of(nb,
147 struct wm831x_power,
148 usb_notify);
149 unsigned int i, best;
150
151 /* Find the highest supported limit */
152 best = 0;
153 for (i = 0; i < ARRAY_SIZE(wm831x_usb_limits); i++) {
154 if (limit >= wm831x_usb_limits[i] &&
155 wm831x_usb_limits[best] < wm831x_usb_limits[i])
156 best = i;
157 }
158
159 dev_dbg(wm831x_power->wm831x->dev,
160 "Limiting USB current to %umA", wm831x_usb_limits[best]);
161
162 wm831x_set_bits(wm831x_power->wm831x, WM831X_POWER_STATE,
163 WM831X_USB_ILIM_MASK, best);
164
165 return 0;
166}
167
128/********************************************************************* 168/*********************************************************************
129 * Battery properties 169 * Battery properties
130 *********************************************************************/ 170 *********************************************************************/
@@ -607,6 +647,33 @@ static int wm831x_power_probe(struct platform_device *pdev)
607 } 647 }
608 } 648 }
609 649
650 power->usb_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "phys", 0);
651 ret = PTR_ERR_OR_ZERO(power->usb_phy);
652
653 switch (ret) {
654 case 0:
655 power->usb_notify.notifier_call = wm831x_usb_limit_change;
656 ret = usb_register_notifier(power->usb_phy, &power->usb_notify);
657 if (ret) {
658 dev_err(&pdev->dev, "Failed to register notifier: %d\n",
659 ret);
660 goto err_bat_irq;
661 }
662 break;
663 case -EINVAL:
664 case -ENODEV:
665 /* ignore missing usb-phy, it's optional */
666 power->usb_phy = NULL;
667 ret = 0;
668 break;
669 default:
670 dev_err(&pdev->dev, "Failed to find USB phy: %d\n", ret);
671 /* fall-through */
672 case -EPROBE_DEFER:
673 goto err_bat_irq;
674 break;
675 }
676
610 return ret; 677 return ret;
611 678
612err_bat_irq: 679err_bat_irq:
@@ -637,6 +704,11 @@ static int wm831x_power_remove(struct platform_device *pdev)
637 struct wm831x *wm831x = wm831x_power->wm831x; 704 struct wm831x *wm831x = wm831x_power->wm831x;
638 int irq, i; 705 int irq, i;
639 706
707 if (wm831x_power->usb_phy) {
708 usb_unregister_notifier(wm831x_power->usb_phy,
709 &wm831x_power->usb_notify);
710 }
711
640 for (i = 0; i < ARRAY_SIZE(wm831x_bat_irqs); i++) { 712 for (i = 0; i < ARRAY_SIZE(wm831x_bat_irqs); i++) {
641 irq = wm831x_irq(wm831x, 713 irq = wm831x_irq(wm831x,
642 platform_get_irq_byname(pdev, 714 platform_get_irq_byname(pdev,
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index c4066cd77e47..0d8e09ccb59c 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -4179,7 +4179,7 @@ static int dwc2_hsotg_ep_sethalt_lock(struct usb_ep *ep, int value)
4179 return ret; 4179 return ret;
4180} 4180}
4181 4181
4182static struct usb_ep_ops dwc2_hsotg_ep_ops = { 4182static const struct usb_ep_ops dwc2_hsotg_ep_ops = {
4183 .enable = dwc2_hsotg_ep_enable, 4183 .enable = dwc2_hsotg_ep_enable,
4184 .disable = dwc2_hsotg_ep_disable, 4184 .disable = dwc2_hsotg_ep_disable,
4185 .alloc_request = dwc2_hsotg_ep_alloc_request, 4185 .alloc_request = dwc2_hsotg_ep_alloc_request,
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 740c7e86d31b..c2631145f404 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -4388,6 +4388,9 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
4388 4388
4389 spin_lock_irqsave(&hsotg->lock, flags); 4389 spin_lock_irqsave(&hsotg->lock, flags);
4390 4390
4391 if (dwc2_is_device_mode(hsotg))
4392 goto unlock;
4393
4391 if (hsotg->lx_state != DWC2_L0) 4394 if (hsotg->lx_state != DWC2_L0)
4392 goto unlock; 4395 goto unlock;
4393 4396
@@ -4446,6 +4449,9 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
4446 4449
4447 spin_lock_irqsave(&hsotg->lock, flags); 4450 spin_lock_irqsave(&hsotg->lock, flags);
4448 4451
4452 if (dwc2_is_device_mode(hsotg))
4453 goto unlock;
4454
4449 if (hsotg->lx_state != DWC2_L2) 4455 if (hsotg->lx_state != DWC2_L2)
4450 goto unlock; 4456 goto unlock;
4451 4457
diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
index 12ee23f53cdd..d2ed9523e77c 100644
--- a/drivers/usb/dwc3/dwc3-keystone.c
+++ b/drivers/usb/dwc3/dwc3-keystone.c
@@ -15,7 +15,6 @@
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 */ 16 */
17 17
18#include <linux/clk.h>
19#include <linux/module.h> 18#include <linux/module.h>
20#include <linux/kernel.h> 19#include <linux/kernel.h>
21#include <linux/interrupt.h> 20#include <linux/interrupt.h>
@@ -23,6 +22,7 @@
23#include <linux/dma-mapping.h> 22#include <linux/dma-mapping.h>
24#include <linux/io.h> 23#include <linux/io.h>
25#include <linux/of_platform.h> 24#include <linux/of_platform.h>
25#include <linux/pm_runtime.h>
26 26
27/* USBSS register offsets */ 27/* USBSS register offsets */
28#define USBSS_REVISION 0x0000 28#define USBSS_REVISION 0x0000
@@ -41,7 +41,6 @@
41 41
42struct dwc3_keystone { 42struct dwc3_keystone {
43 struct device *dev; 43 struct device *dev;
44 struct clk *clk;
45 void __iomem *usbss; 44 void __iomem *usbss;
46}; 45};
47 46
@@ -106,17 +105,13 @@ static int kdwc3_probe(struct platform_device *pdev)
106 if (IS_ERR(kdwc->usbss)) 105 if (IS_ERR(kdwc->usbss))
107 return PTR_ERR(kdwc->usbss); 106 return PTR_ERR(kdwc->usbss);
108 107
109 kdwc->clk = devm_clk_get(kdwc->dev, "usb"); 108 pm_runtime_enable(kdwc->dev);
110 if (IS_ERR(kdwc->clk)) {
111 dev_err(kdwc->dev, "unable to get usb clock\n");
112 return PTR_ERR(kdwc->clk);
113 }
114 109
115 error = clk_prepare_enable(kdwc->clk); 110 error = pm_runtime_get_sync(kdwc->dev);
116 if (error < 0) { 111 if (error < 0) {
117 dev_err(kdwc->dev, "unable to enable usb clock, error %d\n", 112 dev_err(kdwc->dev, "pm_runtime_get_sync failed, error %d\n",
118 error); 113 error);
119 return error; 114 goto err_irq;
120 } 115 }
121 116
122 irq = platform_get_irq(pdev, 0); 117 irq = platform_get_irq(pdev, 0);
@@ -147,7 +142,8 @@ static int kdwc3_probe(struct platform_device *pdev)
147err_core: 142err_core:
148 kdwc3_disable_irqs(kdwc); 143 kdwc3_disable_irqs(kdwc);
149err_irq: 144err_irq:
150 clk_disable_unprepare(kdwc->clk); 145 pm_runtime_put_sync(kdwc->dev);
146 pm_runtime_disable(kdwc->dev);
151 147
152 return error; 148 return error;
153} 149}
@@ -167,7 +163,9 @@ static int kdwc3_remove(struct platform_device *pdev)
167 163
168 kdwc3_disable_irqs(kdwc); 164 kdwc3_disable_irqs(kdwc);
169 device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core); 165 device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core);
170 clk_disable_unprepare(kdwc->clk); 166 pm_runtime_put_sync(kdwc->dev);
167 pm_runtime_disable(kdwc->dev);
168
171 platform_set_drvdata(pdev, NULL); 169 platform_set_drvdata(pdev, NULL);
172 170
173 return 0; 171 return 0;
diff --git a/drivers/usb/dwc3/dwc3-of-simple.c b/drivers/usb/dwc3/dwc3-of-simple.c
index fe414e7a9c78..4cef7d4f9cd0 100644
--- a/drivers/usb/dwc3/dwc3-of-simple.c
+++ b/drivers/usb/dwc3/dwc3-of-simple.c
@@ -25,7 +25,6 @@
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/dma-mapping.h> 26#include <linux/dma-mapping.h>
27#include <linux/clk.h> 27#include <linux/clk.h>
28#include <linux/clk-provider.h>
29#include <linux/of.h> 28#include <linux/of.h>
30#include <linux/of_platform.h> 29#include <linux/of_platform.h>
31#include <linux/pm_runtime.h> 30#include <linux/pm_runtime.h>
@@ -96,7 +95,8 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
96 platform_set_drvdata(pdev, simple); 95 platform_set_drvdata(pdev, simple);
97 simple->dev = dev; 96 simple->dev = dev;
98 97
99 ret = dwc3_of_simple_clk_init(simple, of_clk_get_parent_count(np)); 98 ret = dwc3_of_simple_clk_init(simple, of_count_phandle_with_args(np,
99 "clocks", "#clock-cells"));
100 if (ret) 100 if (ret)
101 return ret; 101 return ret;
102 102
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index f5aaa0cf3873..3530795bbb8f 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -478,8 +478,8 @@ static int dwc3_omap_probe(struct platform_device *pdev)
478 478
479 irq = platform_get_irq(pdev, 0); 479 irq = platform_get_irq(pdev, 0);
480 if (irq < 0) { 480 if (irq < 0) {
481 dev_err(dev, "missing IRQ resource\n"); 481 dev_err(dev, "missing IRQ resource: %d\n", irq);
482 return -EINVAL; 482 return irq;
483 } 483 }
484 484
485 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 485 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 35cc641d9f31..31cce7805eb2 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -130,7 +130,7 @@ config USB_GADGET_STORAGE_NUM_BUFFERS
130 130
131config U_SERIAL_CONSOLE 131config U_SERIAL_CONSOLE
132 bool "Serial gadget console support" 132 bool "Serial gadget console support"
133 depends on USB_G_SERIAL 133 depends on USB_U_SERIAL
134 help 134 help
135 It supports the serial gadget can be used as a console. 135 It supports the serial gadget can be used as a console.
136 136
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index d21874b35cf6..9990944a7245 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -961,10 +961,9 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
961 /* In the meantime, endpoint got disabled or changed. */ 961 /* In the meantime, endpoint got disabled or changed. */
962 ret = -ESHUTDOWN; 962 ret = -ESHUTDOWN;
963 } else if (halt) { 963 } else if (halt) {
964 /* Halt */ 964 ret = usb_ep_set_halt(ep->ep);
965 if (likely(epfile->ep == ep) && !WARN_ON(!ep->ep)) 965 if (!ret)
966 usb_ep_set_halt(ep->ep); 966 ret = -EBADMSG;
967 ret = -EBADMSG;
968 } else if (unlikely(data_len == -EINVAL)) { 967 } else if (unlikely(data_len == -EINVAL)) {
969 /* 968 /*
970 * Sanity Check: even though data_len can't be used 969 * Sanity Check: even though data_len can't be used
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 5eea44823ca0..d8e359ef6eb1 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -44,6 +44,7 @@ struct f_hidg {
44 /* configuration */ 44 /* configuration */
45 unsigned char bInterfaceSubClass; 45 unsigned char bInterfaceSubClass;
46 unsigned char bInterfaceProtocol; 46 unsigned char bInterfaceProtocol;
47 unsigned char protocol;
47 unsigned short report_desc_length; 48 unsigned short report_desc_length;
48 char *report_desc; 49 char *report_desc;
49 unsigned short report_length; 50 unsigned short report_length;
@@ -527,7 +528,9 @@ static int hidg_setup(struct usb_function *f,
527 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8 528 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
528 | HID_REQ_GET_PROTOCOL): 529 | HID_REQ_GET_PROTOCOL):
529 VDBG(cdev, "get_protocol\n"); 530 VDBG(cdev, "get_protocol\n");
530 goto stall; 531 length = min_t(unsigned int, length, 1);
532 ((u8 *) req->buf)[0] = hidg->protocol;
533 goto respond;
531 break; 534 break;
532 535
533 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8 536 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
@@ -539,6 +542,17 @@ static int hidg_setup(struct usb_function *f,
539 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8 542 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
540 | HID_REQ_SET_PROTOCOL): 543 | HID_REQ_SET_PROTOCOL):
541 VDBG(cdev, "set_protocol\n"); 544 VDBG(cdev, "set_protocol\n");
545 if (value > HID_REPORT_PROTOCOL)
546 goto stall;
547 length = 0;
548 /*
549 * We assume that programs implementing the Boot protocol
550 * are also compatible with the Report Protocol
551 */
552 if (hidg->bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) {
553 hidg->protocol = value;
554 goto respond;
555 }
542 goto stall; 556 goto stall;
543 break; 557 break;
544 558
@@ -768,6 +782,7 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
768 /* set descriptor dynamic values */ 782 /* set descriptor dynamic values */
769 hidg_interface_desc.bInterfaceSubClass = hidg->bInterfaceSubClass; 783 hidg_interface_desc.bInterfaceSubClass = hidg->bInterfaceSubClass;
770 hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol; 784 hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol;
785 hidg->protocol = HID_REPORT_PROTOCOL;
771 hidg_ss_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); 786 hidg_ss_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
772 hidg_ss_in_comp_desc.wBytesPerInterval = 787 hidg_ss_in_comp_desc.wBytesPerInterval =
773 cpu_to_le16(hidg->report_length); 788 cpu_to_le16(hidg->report_length);
diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
index a5719f271bf0..5d3d7941d2c2 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -98,6 +98,7 @@ struct f_midi {
98 DECLARE_KFIFO_PTR(in_req_fifo, struct usb_request *); 98 DECLARE_KFIFO_PTR(in_req_fifo, struct usb_request *);
99 spinlock_t transmit_lock; 99 spinlock_t transmit_lock;
100 unsigned int in_last_port; 100 unsigned int in_last_port;
101 unsigned char free_ref;
101 102
102 struct gmidi_in_port in_ports_array[/* in_ports */]; 103 struct gmidi_in_port in_ports_array[/* in_ports */];
103}; 104};
@@ -108,6 +109,7 @@ static inline struct f_midi *func_to_midi(struct usb_function *f)
108} 109}
109 110
110static void f_midi_transmit(struct f_midi *midi); 111static void f_midi_transmit(struct f_midi *midi);
112static void f_midi_rmidi_free(struct snd_rawmidi *rmidi);
111 113
112DECLARE_UAC_AC_HEADER_DESCRIPTOR(1); 114DECLARE_UAC_AC_HEADER_DESCRIPTOR(1);
113DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); 115DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1);
@@ -163,6 +165,13 @@ static struct usb_endpoint_descriptor bulk_out_desc = {
163 .bmAttributes = USB_ENDPOINT_XFER_BULK, 165 .bmAttributes = USB_ENDPOINT_XFER_BULK,
164}; 166};
165 167
168static struct usb_ss_ep_comp_descriptor bulk_out_ss_comp_desc = {
169 .bLength = sizeof(bulk_out_ss_comp_desc),
170 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
171 /* .bMaxBurst = 0, */
172 /* .bmAttributes = 0, */
173};
174
166/* B.5.2 Class-specific MS Bulk OUT Endpoint Descriptor */ 175/* B.5.2 Class-specific MS Bulk OUT Endpoint Descriptor */
167static struct usb_ms_endpoint_descriptor_16 ms_out_desc = { 176static struct usb_ms_endpoint_descriptor_16 ms_out_desc = {
168 /* .bLength = DYNAMIC */ 177 /* .bLength = DYNAMIC */
@@ -180,6 +189,13 @@ static struct usb_endpoint_descriptor bulk_in_desc = {
180 .bmAttributes = USB_ENDPOINT_XFER_BULK, 189 .bmAttributes = USB_ENDPOINT_XFER_BULK,
181}; 190};
182 191
192static struct usb_ss_ep_comp_descriptor bulk_in_ss_comp_desc = {
193 .bLength = sizeof(bulk_in_ss_comp_desc),
194 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
195 /* .bMaxBurst = 0, */
196 /* .bmAttributes = 0, */
197};
198
183/* B.6.2 Class-specific MS Bulk IN Endpoint Descriptor */ 199/* B.6.2 Class-specific MS Bulk IN Endpoint Descriptor */
184static struct usb_ms_endpoint_descriptor_16 ms_in_desc = { 200static struct usb_ms_endpoint_descriptor_16 ms_in_desc = {
185 /* .bLength = DYNAMIC */ 201 /* .bLength = DYNAMIC */
@@ -755,13 +771,13 @@ static void f_midi_out_trigger(struct snd_rawmidi_substream *substream, int up)
755 clear_bit(substream->number, &midi->out_triggered); 771 clear_bit(substream->number, &midi->out_triggered);
756} 772}
757 773
758static struct snd_rawmidi_ops gmidi_in_ops = { 774static const struct snd_rawmidi_ops gmidi_in_ops = {
759 .open = f_midi_in_open, 775 .open = f_midi_in_open,
760 .close = f_midi_in_close, 776 .close = f_midi_in_close,
761 .trigger = f_midi_in_trigger, 777 .trigger = f_midi_in_trigger,
762}; 778};
763 779
764static struct snd_rawmidi_ops gmidi_out_ops = { 780static const struct snd_rawmidi_ops gmidi_out_ops = {
765 .open = f_midi_out_open, 781 .open = f_midi_out_open,
766 .close = f_midi_out_close, 782 .close = f_midi_out_close,
767 .trigger = f_midi_out_trigger 783 .trigger = f_midi_out_trigger
@@ -818,6 +834,8 @@ static int f_midi_register_card(struct f_midi *midi)
818 SNDRV_RAWMIDI_INFO_INPUT | 834 SNDRV_RAWMIDI_INFO_INPUT |
819 SNDRV_RAWMIDI_INFO_DUPLEX; 835 SNDRV_RAWMIDI_INFO_DUPLEX;
820 rmidi->private_data = midi; 836 rmidi->private_data = midi;
837 rmidi->private_free = f_midi_rmidi_free;
838 midi->free_ref++;
821 839
822 /* 840 /*
823 * Yes, rawmidi OUTPUT = USB IN, and rawmidi INPUT = USB OUT. 841 * Yes, rawmidi OUTPUT = USB IN, and rawmidi INPUT = USB OUT.
@@ -853,7 +871,7 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
853 struct usb_composite_dev *cdev = c->cdev; 871 struct usb_composite_dev *cdev = c->cdev;
854 struct f_midi *midi = func_to_midi(f); 872 struct f_midi *midi = func_to_midi(f);
855 struct usb_string *us; 873 struct usb_string *us;
856 int status, n, jack = 1, i = 0; 874 int status, n, jack = 1, i = 0, endpoint_descriptor_index = 0;
857 875
858 midi->gadget = cdev->gadget; 876 midi->gadget = cdev->gadget;
859 tasklet_init(&midi->tasklet, f_midi_in_tasklet, (unsigned long) midi); 877 tasklet_init(&midi->tasklet, f_midi_in_tasklet, (unsigned long) midi);
@@ -895,7 +913,7 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
895 goto fail; 913 goto fail;
896 914
897 /* allocate temporary function list */ 915 /* allocate temporary function list */
898 midi_function = kcalloc((MAX_PORTS * 4) + 9, sizeof(*midi_function), 916 midi_function = kcalloc((MAX_PORTS * 4) + 11, sizeof(*midi_function),
899 GFP_KERNEL); 917 GFP_KERNEL);
900 if (!midi_function) { 918 if (!midi_function) {
901 status = -ENOMEM; 919 status = -ENOMEM;
@@ -985,6 +1003,7 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
985 ms_in_desc.bNumEmbMIDIJack = midi->out_ports; 1003 ms_in_desc.bNumEmbMIDIJack = midi->out_ports;
986 1004
987 /* ... and add them to the list */ 1005 /* ... and add them to the list */
1006 endpoint_descriptor_index = i;
988 midi_function[i++] = (struct usb_descriptor_header *) &bulk_out_desc; 1007 midi_function[i++] = (struct usb_descriptor_header *) &bulk_out_desc;
989 midi_function[i++] = (struct usb_descriptor_header *) &ms_out_desc; 1008 midi_function[i++] = (struct usb_descriptor_header *) &ms_out_desc;
990 midi_function[i++] = (struct usb_descriptor_header *) &bulk_in_desc; 1009 midi_function[i++] = (struct usb_descriptor_header *) &bulk_in_desc;
@@ -1009,13 +1028,34 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
1009 goto fail_f_midi; 1028 goto fail_f_midi;
1010 } 1029 }
1011 1030
1031 if (gadget_is_superspeed(c->cdev->gadget)) {
1032 bulk_in_desc.wMaxPacketSize = cpu_to_le16(1024);
1033 bulk_out_desc.wMaxPacketSize = cpu_to_le16(1024);
1034 i = endpoint_descriptor_index;
1035 midi_function[i++] = (struct usb_descriptor_header *)
1036 &bulk_out_desc;
1037 midi_function[i++] = (struct usb_descriptor_header *)
1038 &bulk_out_ss_comp_desc;
1039 midi_function[i++] = (struct usb_descriptor_header *)
1040 &ms_out_desc;
1041 midi_function[i++] = (struct usb_descriptor_header *)
1042 &bulk_in_desc;
1043 midi_function[i++] = (struct usb_descriptor_header *)
1044 &bulk_in_ss_comp_desc;
1045 midi_function[i++] = (struct usb_descriptor_header *)
1046 &ms_in_desc;
1047 f->ss_descriptors = usb_copy_descriptors(midi_function);
1048 if (!f->ss_descriptors)
1049 goto fail_f_midi;
1050 }
1051
1012 kfree(midi_function); 1052 kfree(midi_function);
1013 1053
1014 return 0; 1054 return 0;
1015 1055
1016fail_f_midi: 1056fail_f_midi:
1017 kfree(midi_function); 1057 kfree(midi_function);
1018 usb_free_descriptors(f->hs_descriptors); 1058 usb_free_all_descriptors(f);
1019fail: 1059fail:
1020 f_midi_unregister_card(midi); 1060 f_midi_unregister_card(midi);
1021fail_register: 1061fail_register:
@@ -1197,14 +1237,21 @@ static void f_midi_free(struct usb_function *f)
1197 1237
1198 midi = func_to_midi(f); 1238 midi = func_to_midi(f);
1199 opts = container_of(f->fi, struct f_midi_opts, func_inst); 1239 opts = container_of(f->fi, struct f_midi_opts, func_inst);
1200 kfree(midi->id);
1201 mutex_lock(&opts->lock); 1240 mutex_lock(&opts->lock);
1202 kfifo_free(&midi->in_req_fifo); 1241 if (!--midi->free_ref) {
1203 kfree(midi); 1242 kfree(midi->id);
1204 --opts->refcnt; 1243 kfifo_free(&midi->in_req_fifo);
1244 kfree(midi);
1245 --opts->refcnt;
1246 }
1205 mutex_unlock(&opts->lock); 1247 mutex_unlock(&opts->lock);
1206} 1248}
1207 1249
1250static void f_midi_rmidi_free(struct snd_rawmidi *rmidi)
1251{
1252 f_midi_free(rmidi->private_data);
1253}
1254
1208static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f) 1255static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f)
1209{ 1256{
1210 struct usb_composite_dev *cdev = f->config->cdev; 1257 struct usb_composite_dev *cdev = f->config->cdev;
@@ -1219,7 +1266,7 @@ static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f)
1219 card = midi->card; 1266 card = midi->card;
1220 midi->card = NULL; 1267 midi->card = NULL;
1221 if (card) 1268 if (card)
1222 snd_card_free(card); 1269 snd_card_free_when_closed(card);
1223 1270
1224 usb_free_all_descriptors(f); 1271 usb_free_all_descriptors(f);
1225} 1272}
@@ -1263,6 +1310,7 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi)
1263 midi->buflen = opts->buflen; 1310 midi->buflen = opts->buflen;
1264 midi->qlen = opts->qlen; 1311 midi->qlen = opts->qlen;
1265 midi->in_last_port = 0; 1312 midi->in_last_port = 0;
1313 midi->free_ref = 1;
1266 1314
1267 status = kfifo_alloc(&midi->in_req_fifo, midi->qlen, GFP_KERNEL); 1315 status = kfifo_alloc(&midi->in_req_fifo, midi->qlen, GFP_KERNEL);
1268 if (status) 1316 if (status)
diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
index 24e34cfcb4bd..45b334ceaf2e 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -925,8 +925,6 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
925 */ 925 */
926 ncm->port.is_zlp_ok = 926 ncm->port.is_zlp_ok =
927 gadget_is_zlp_supported(cdev->gadget); 927 gadget_is_zlp_supported(cdev->gadget);
928 ncm->port.no_skb_reserve =
929 gadget_avoids_skb_reserve(cdev->gadget);
930 ncm->port.cdc_filter = DEFAULT_FILTER; 928 ncm->port.cdc_filter = DEFAULT_FILTER;
931 DBG(cdev, "activate ncm\n"); 929 DBG(cdev, "activate ncm\n");
932 net = gether_connect(&ncm->port); 930 net = gether_connect(&ncm->port);
diff --git a/drivers/usb/gadget/function/f_rndis.c b/drivers/usb/gadget/function/f_rndis.c
index 16562e461121..e1d5853ef1e4 100644
--- a/drivers/usb/gadget/function/f_rndis.c
+++ b/drivers/usb/gadget/function/f_rndis.c
@@ -691,6 +691,10 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
691 f->os_desc_table[0].os_desc = &rndis_opts->rndis_os_desc; 691 f->os_desc_table[0].os_desc = &rndis_opts->rndis_os_desc;
692 } 692 }
693 693
694 rndis_iad_descriptor.bFunctionClass = rndis_opts->class;
695 rndis_iad_descriptor.bFunctionSubClass = rndis_opts->subclass;
696 rndis_iad_descriptor.bFunctionProtocol = rndis_opts->protocol;
697
694 /* 698 /*
695 * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 699 * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
696 * configurations are bound in sequence with list_for_each_entry, 700 * configurations are bound in sequence with list_for_each_entry,
@@ -866,11 +870,23 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(rndis);
866/* f_rndis_opts_ifname */ 870/* f_rndis_opts_ifname */
867USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(rndis); 871USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(rndis);
868 872
873/* f_rndis_opts_class */
874USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(rndis, class);
875
876/* f_rndis_opts_subclass */
877USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(rndis, subclass);
878
879/* f_rndis_opts_protocol */
880USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(rndis, protocol);
881
869static struct configfs_attribute *rndis_attrs[] = { 882static struct configfs_attribute *rndis_attrs[] = {
870 &rndis_opts_attr_dev_addr, 883 &rndis_opts_attr_dev_addr,
871 &rndis_opts_attr_host_addr, 884 &rndis_opts_attr_host_addr,
872 &rndis_opts_attr_qmult, 885 &rndis_opts_attr_qmult,
873 &rndis_opts_attr_ifname, 886 &rndis_opts_attr_ifname,
887 &rndis_opts_attr_class,
888 &rndis_opts_attr_subclass,
889 &rndis_opts_attr_protocol,
874 NULL, 890 NULL,
875}; 891};
876 892
@@ -916,6 +932,10 @@ static struct usb_function_instance *rndis_alloc_inst(void)
916 } 932 }
917 INIT_LIST_HEAD(&opts->rndis_os_desc.ext_prop); 933 INIT_LIST_HEAD(&opts->rndis_os_desc.ext_prop);
918 934
935 opts->class = rndis_iad_descriptor.bFunctionClass;
936 opts->subclass = rndis_iad_descriptor.bFunctionSubClass;
937 opts->protocol = rndis_iad_descriptor.bFunctionProtocol;
938
919 descs[0] = &opts->rndis_os_desc; 939 descs[0] = &opts->rndis_os_desc;
920 names[0] = "rndis"; 940 names[0] = "rndis";
921 config_group_init_type_name(&opts->func_inst.group, "", 941 config_group_init_type_name(&opts->func_inst.group, "",
diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index a8b40d07e927..bdbc3fdc7c4f 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -1073,7 +1073,7 @@ struct net_device *gether_connect(struct gether *link)
1073 1073
1074 if (result == 0) { 1074 if (result == 0) {
1075 dev->zlp = link->is_zlp_ok; 1075 dev->zlp = link->is_zlp_ok;
1076 dev->no_skb_reserve = link->no_skb_reserve; 1076 dev->no_skb_reserve = gadget_avoids_skb_reserve(dev->gadget);
1077 DBG(dev, "qlen %d\n", qlen(dev->gadget, dev->qmult)); 1077 DBG(dev, "qlen %d\n", qlen(dev->gadget, dev->qmult));
1078 1078
1079 dev->header_len = link->header_len; 1079 dev->header_len = link->header_len;
diff --git a/drivers/usb/gadget/function/u_ether.h b/drivers/usb/gadget/function/u_ether.h
index 81d94a7ae4b4..c77145bd6b5b 100644
--- a/drivers/usb/gadget/function/u_ether.h
+++ b/drivers/usb/gadget/function/u_ether.h
@@ -64,7 +64,6 @@ struct gether {
64 struct usb_ep *out_ep; 64 struct usb_ep *out_ep;
65 65
66 bool is_zlp_ok; 66 bool is_zlp_ok;
67 bool no_skb_reserve;
68 67
69 u16 cdc_filter; 68 u16 cdc_filter;
70 69
diff --git a/drivers/usb/gadget/function/u_ether_configfs.h b/drivers/usb/gadget/function/u_ether_configfs.h
index c71133de17e7..e4c3f84af4c3 100644
--- a/drivers/usb/gadget/function/u_ether_configfs.h
+++ b/drivers/usb/gadget/function/u_ether_configfs.h
@@ -153,4 +153,39 @@ out: \
153 \ 153 \
154 CONFIGFS_ATTR_RO(_f_##_opts_, ifname) 154 CONFIGFS_ATTR_RO(_f_##_opts_, ifname)
155 155
156#define USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(_f_, _n_) \
157 static ssize_t _f_##_opts_##_n_##_show(struct config_item *item,\
158 char *page) \
159 { \
160 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
161 int ret; \
162 \
163 mutex_lock(&opts->lock); \
164 ret = sprintf(page, "%02x\n", opts->_n_); \
165 mutex_unlock(&opts->lock); \
166 \
167 return ret; \
168 } \
169 \
170 static ssize_t _f_##_opts_##_n_##_store(struct config_item *item,\
171 const char *page, \
172 size_t len) \
173 { \
174 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
175 int ret; \
176 u8 val; \
177 \
178 mutex_lock(&opts->lock); \
179 ret = sscanf(page, "%02hhx", &val); \
180 if (ret > 0) { \
181 opts->_n_ = val; \
182 ret = len; \
183 } \
184 mutex_unlock(&opts->lock); \
185 \
186 return ret; \
187 } \
188 \
189 CONFIGFS_ATTR(_f_##_opts_, _n_)
190
156#endif /* __U_ETHER_CONFIGFS_H */ 191#endif /* __U_ETHER_CONFIGFS_H */
diff --git a/drivers/usb/gadget/function/u_rndis.h b/drivers/usb/gadget/function/u_rndis.h
index 4eafd5050545..a35ee3c2545d 100644
--- a/drivers/usb/gadget/function/u_rndis.h
+++ b/drivers/usb/gadget/function/u_rndis.h
@@ -29,6 +29,10 @@ struct f_rndis_opts {
29 struct usb_os_desc rndis_os_desc; 29 struct usb_os_desc rndis_os_desc;
30 char rndis_ext_compat_id[16]; 30 char rndis_ext_compat_id[16];
31 31
32 u8 class;
33 u8 subclass;
34 u8 protocol;
35
32 /* 36 /*
33 * Read/write access to configfs attributes is handled by configfs. 37 * Read/write access to configfs attributes is handled by configfs.
34 * 38 *
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 9b0805f55ad7..4176216d54be 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -537,7 +537,7 @@ static void gs_rx_push(unsigned long _port)
537 } 537 }
538 538
539 /* push data to (open) tty */ 539 /* push data to (open) tty */
540 if (req->actual) { 540 if (req->actual && tty) {
541 char *packet = req->buf; 541 char *packet = req->buf;
542 unsigned size = req->actual; 542 unsigned size = req->actual;
543 unsigned n; 543 unsigned n;
diff --git a/drivers/usb/gadget/udc/bdc/Kconfig b/drivers/usb/gadget/udc/bdc/Kconfig
index eb8b55392360..c74ac25dddcd 100644
--- a/drivers/usb/gadget/udc/bdc/Kconfig
+++ b/drivers/usb/gadget/udc/bdc/Kconfig
@@ -1,6 +1,7 @@
1config USB_BDC_UDC 1config USB_BDC_UDC
2 tristate "Broadcom USB3.0 device controller IP driver(BDC)" 2 tristate "Broadcom USB3.0 device controller IP driver(BDC)"
3 depends on USB_GADGET && HAS_DMA 3 depends on USB_GADGET && HAS_DMA
4 default ARCH_BRCMSTB
4 5
5 help 6 help
6 BDC is Broadcom's USB3.0 device controller IP. If your SOC has a BDC IP 7 BDC is Broadcom's USB3.0 device controller IP. If your SOC has a BDC IP
diff --git a/drivers/usb/gadget/udc/bdc/bdc.h b/drivers/usb/gadget/udc/bdc/bdc.h
index 916d47135cac..6df0352cdc50 100644
--- a/drivers/usb/gadget/udc/bdc/bdc.h
+++ b/drivers/usb/gadget/udc/bdc/bdc.h
@@ -27,8 +27,8 @@
27#include <linux/usb/gadget.h> 27#include <linux/usb/gadget.h>
28#include <asm/unaligned.h> 28#include <asm/unaligned.h>
29 29
30#define BRCM_BDC_NAME "bdc_usb3" 30#define BRCM_BDC_NAME "bdc"
31#define BRCM_BDC_DESC "BDC device controller driver" 31#define BRCM_BDC_DESC "Broadcom USB Device Controller driver"
32 32
33#define DMA_ADDR_INVALID (~(dma_addr_t)0) 33#define DMA_ADDR_INVALID (~(dma_addr_t)0)
34 34
@@ -83,14 +83,14 @@
83 83
84#define BDC_DVCSA 0x50 84#define BDC_DVCSA 0x50
85#define BDC_DVCSB 0x54 85#define BDC_DVCSB 0x54
86#define BDC_EPSTS0(n) (0x60 + (n * 0x10)) 86#define BDC_EPSTS0 0x60
87#define BDC_EPSTS1(n) (0x64 + (n * 0x10)) 87#define BDC_EPSTS1 0x64
88#define BDC_EPSTS2(n) (0x68 + (n * 0x10)) 88#define BDC_EPSTS2 0x68
89#define BDC_EPSTS3(n) (0x6c + (n * 0x10)) 89#define BDC_EPSTS3 0x6c
90#define BDC_EPSTS4(n) (0x70 + (n * 0x10)) 90#define BDC_EPSTS4 0x70
91#define BDC_EPSTS5(n) (0x74 + (n * 0x10)) 91#define BDC_EPSTS5 0x74
92#define BDC_EPSTS6(n) (0x78 + (n * 0x10)) 92#define BDC_EPSTS6 0x78
93#define BDC_EPSTS7(n) (0x7c + (n * 0x10)) 93#define BDC_EPSTS7 0x7c
94#define BDC_SRRBAL(n) (0x200 + (n * 0x10)) 94#define BDC_SRRBAL(n) (0x200 + (n * 0x10))
95#define BDC_SRRBAH(n) (0x204 + (n * 0x10)) 95#define BDC_SRRBAH(n) (0x204 + (n * 0x10))
96#define BDC_SRRINT(n) (0x208 + (n * 0x10)) 96#define BDC_SRRINT(n) (0x208 + (n * 0x10))
@@ -413,6 +413,9 @@ struct bdc {
413 /* device lock */ 413 /* device lock */
414 spinlock_t lock; 414 spinlock_t lock;
415 415
416 /* generic phy */
417 struct phy **phys;
418 int num_phys;
416 /* num of endpoints for a particular instantiation of IP */ 419 /* num of endpoints for a particular instantiation of IP */
417 unsigned int num_eps; 420 unsigned int num_eps;
418 /* 421 /*
@@ -454,6 +457,7 @@ struct bdc {
454 * Func Wake packet every 2.5 secs. Refer to USB3 spec section 8.5.6.4 457 * Func Wake packet every 2.5 secs. Refer to USB3 spec section 8.5.6.4
455 */ 458 */
456 struct delayed_work func_wake_notify; 459 struct delayed_work func_wake_notify;
460 struct clk *clk;
457}; 461};
458 462
459static inline u32 bdc_readl(void __iomem *base, u32 offset) 463static inline u32 bdc_readl(void __iomem *base, u32 offset)
diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c
index e9bd8d4abca0..7a8af4b916cf 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_core.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_core.c
@@ -24,9 +24,11 @@
24#include <linux/dma-mapping.h> 24#include <linux/dma-mapping.h>
25#include <linux/dmapool.h> 25#include <linux/dmapool.h>
26#include <linux/of.h> 26#include <linux/of.h>
27#include <linux/phy/phy.h>
27#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
28#include <linux/usb/ch9.h> 29#include <linux/usb/ch9.h>
29#include <linux/usb/gadget.h> 30#include <linux/usb/gadget.h>
31#include <linux/clk.h>
30 32
31#include "bdc.h" 33#include "bdc.h"
32#include "bdc_dbg.h" 34#include "bdc_dbg.h"
@@ -444,6 +446,43 @@ static int bdc_hw_init(struct bdc *bdc)
444 return 0; 446 return 0;
445} 447}
446 448
449static int bdc_phy_init(struct bdc *bdc)
450{
451 int phy_num;
452 int ret;
453
454 for (phy_num = 0; phy_num < bdc->num_phys; phy_num++) {
455 ret = phy_init(bdc->phys[phy_num]);
456 if (ret)
457 goto err_exit_phy;
458 ret = phy_power_on(bdc->phys[phy_num]);
459 if (ret) {
460 phy_exit(bdc->phys[phy_num]);
461 goto err_exit_phy;
462 }
463 }
464
465 return 0;
466
467err_exit_phy:
468 while (--phy_num >= 0) {
469 phy_power_off(bdc->phys[phy_num]);
470 phy_exit(bdc->phys[phy_num]);
471 }
472
473 return ret;
474}
475
476static void bdc_phy_exit(struct bdc *bdc)
477{
478 int phy_num;
479
480 for (phy_num = 0; phy_num < bdc->num_phys; phy_num++) {
481 phy_power_off(bdc->phys[phy_num]);
482 phy_exit(bdc->phys[phy_num]);
483 }
484}
485
447static int bdc_probe(struct platform_device *pdev) 486static int bdc_probe(struct platform_device *pdev)
448{ 487{
449 struct bdc *bdc; 488 struct bdc *bdc;
@@ -452,12 +491,29 @@ static int bdc_probe(struct platform_device *pdev)
452 int irq; 491 int irq;
453 u32 temp; 492 u32 temp;
454 struct device *dev = &pdev->dev; 493 struct device *dev = &pdev->dev;
494 struct clk *clk;
495 int phy_num;
455 496
456 dev_dbg(dev, "%s()\n", __func__); 497 dev_dbg(dev, "%s()\n", __func__);
498
499 clk = devm_clk_get(dev, "sw_usbd");
500 if (IS_ERR(clk)) {
501 dev_info(dev, "Clock not found in Device Tree\n");
502 clk = NULL;
503 }
504
505 ret = clk_prepare_enable(clk);
506 if (ret) {
507 dev_err(dev, "could not enable clock\n");
508 return ret;
509 }
510
457 bdc = devm_kzalloc(dev, sizeof(*bdc), GFP_KERNEL); 511 bdc = devm_kzalloc(dev, sizeof(*bdc), GFP_KERNEL);
458 if (!bdc) 512 if (!bdc)
459 return -ENOMEM; 513 return -ENOMEM;
460 514
515 bdc->clk = clk;
516
461 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 517 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
462 bdc->regs = devm_ioremap_resource(dev, res); 518 bdc->regs = devm_ioremap_resource(dev, res);
463 if (IS_ERR(bdc->regs)) { 519 if (IS_ERR(bdc->regs)) {
@@ -473,35 +529,66 @@ static int bdc_probe(struct platform_device *pdev)
473 platform_set_drvdata(pdev, bdc); 529 platform_set_drvdata(pdev, bdc);
474 bdc->irq = irq; 530 bdc->irq = irq;
475 bdc->dev = dev; 531 bdc->dev = dev;
476 dev_dbg(bdc->dev, "bdc->regs: %p irq=%d\n", bdc->regs, bdc->irq); 532 dev_dbg(dev, "bdc->regs: %p irq=%d\n", bdc->regs, bdc->irq);
533
534 bdc->num_phys = of_count_phandle_with_args(dev->of_node,
535 "phys", "#phy-cells");
536 if (bdc->num_phys > 0) {
537 bdc->phys = devm_kcalloc(dev, bdc->num_phys,
538 sizeof(struct phy *), GFP_KERNEL);
539 if (!bdc->phys)
540 return -ENOMEM;
541 } else {
542 bdc->num_phys = 0;
543 }
544 dev_info(dev, "Using %d phy(s)\n", bdc->num_phys);
545
546 for (phy_num = 0; phy_num < bdc->num_phys; phy_num++) {
547 bdc->phys[phy_num] = devm_of_phy_get_by_index(
548 dev, dev->of_node, phy_num);
549 if (IS_ERR(bdc->phys[phy_num])) {
550 ret = PTR_ERR(bdc->phys[phy_num]);
551 dev_err(bdc->dev,
552 "BDC phy specified but not found:%d\n", ret);
553 return ret;
554 }
555 }
556
557 ret = bdc_phy_init(bdc);
558 if (ret) {
559 dev_err(bdc->dev, "BDC phy init failure:%d\n", ret);
560 return ret;
561 }
477 562
478 temp = bdc_readl(bdc->regs, BDC_BDCCAP1); 563 temp = bdc_readl(bdc->regs, BDC_BDCCAP1);
479 if ((temp & BDC_P64) && 564 if ((temp & BDC_P64) &&
480 !dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) { 565 !dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) {
481 dev_dbg(bdc->dev, "Using 64-bit address\n"); 566 dev_dbg(dev, "Using 64-bit address\n");
482 } else { 567 } else {
483 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); 568 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
484 if (ret) { 569 if (ret) {
485 dev_err(bdc->dev, "No suitable DMA config available, abort\n"); 570 dev_err(dev,
571 "No suitable DMA config available, abort\n");
486 return -ENOTSUPP; 572 return -ENOTSUPP;
487 } 573 }
488 dev_dbg(bdc->dev, "Using 32-bit address\n"); 574 dev_dbg(dev, "Using 32-bit address\n");
489 } 575 }
490 ret = bdc_hw_init(bdc); 576 ret = bdc_hw_init(bdc);
491 if (ret) { 577 if (ret) {
492 dev_err(bdc->dev, "BDC init failure:%d\n", ret); 578 dev_err(dev, "BDC init failure:%d\n", ret);
493 return ret; 579 goto phycleanup;
494 } 580 }
495 ret = bdc_udc_init(bdc); 581 ret = bdc_udc_init(bdc);
496 if (ret) { 582 if (ret) {
497 dev_err(bdc->dev, "BDC Gadget init failure:%d\n", ret); 583 dev_err(dev, "BDC Gadget init failure:%d\n", ret);
498 goto cleanup; 584 goto cleanup;
499 } 585 }
500 return 0; 586 return 0;
501 587
502cleanup: 588cleanup:
503 bdc_hw_exit(bdc); 589 bdc_hw_exit(bdc);
504 590phycleanup:
591 bdc_phy_exit(bdc);
505 return ret; 592 return ret;
506} 593}
507 594
@@ -513,13 +600,56 @@ static int bdc_remove(struct platform_device *pdev)
513 dev_dbg(bdc->dev, "%s ()\n", __func__); 600 dev_dbg(bdc->dev, "%s ()\n", __func__);
514 bdc_udc_exit(bdc); 601 bdc_udc_exit(bdc);
515 bdc_hw_exit(bdc); 602 bdc_hw_exit(bdc);
603 bdc_phy_exit(bdc);
604 clk_disable_unprepare(bdc->clk);
605 return 0;
606}
607
608#ifdef CONFIG_PM_SLEEP
609static int bdc_suspend(struct device *dev)
610{
611 struct bdc *bdc = dev_get_drvdata(dev);
516 612
613 clk_disable_unprepare(bdc->clk);
517 return 0; 614 return 0;
518} 615}
519 616
617static int bdc_resume(struct device *dev)
618{
619 struct bdc *bdc = dev_get_drvdata(dev);
620 int ret;
621
622 ret = clk_prepare_enable(bdc->clk);
623 if (ret) {
624 dev_err(bdc->dev, "err enabling the clock\n");
625 return ret;
626 }
627 ret = bdc_reinit(bdc);
628 if (ret) {
629 dev_err(bdc->dev, "err in bdc reinit\n");
630 return ret;
631 }
632
633 return 0;
634}
635
636#endif /* CONFIG_PM_SLEEP */
637
638static SIMPLE_DEV_PM_OPS(bdc_pm_ops, bdc_suspend,
639 bdc_resume);
640
641static const struct of_device_id bdc_of_match[] = {
642 { .compatible = "brcm,bdc-v0.16" },
643 { .compatible = "brcm,bdc" },
644 { /* sentinel */ }
645};
646
520static struct platform_driver bdc_driver = { 647static struct platform_driver bdc_driver = {
521 .driver = { 648 .driver = {
522 .name = BRCM_BDC_NAME, 649 .name = BRCM_BDC_NAME,
650 .owner = THIS_MODULE,
651 .pm = &bdc_pm_ops,
652 .of_match_table = bdc_of_match,
523 }, 653 },
524 .probe = bdc_probe, 654 .probe = bdc_probe,
525 .remove = bdc_remove, 655 .remove = bdc_remove,
diff --git a/drivers/usb/gadget/udc/bdc/bdc_dbg.c b/drivers/usb/gadget/udc/bdc/bdc_dbg.c
index 5945dbc47825..ac98f6f681b7 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_dbg.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_dbg.c
@@ -40,28 +40,28 @@ void bdc_dump_epsts(struct bdc *bdc)
40{ 40{
41 u32 temp; 41 u32 temp;
42 42
43 temp = bdc_readl(bdc->regs, BDC_EPSTS0(0)); 43 temp = bdc_readl(bdc->regs, BDC_EPSTS0);
44 dev_vdbg(bdc->dev, "BDC_EPSTS0:0x%08x\n", temp); 44 dev_vdbg(bdc->dev, "BDC_EPSTS0:0x%08x\n", temp);
45 45
46 temp = bdc_readl(bdc->regs, BDC_EPSTS1(0)); 46 temp = bdc_readl(bdc->regs, BDC_EPSTS1);
47 dev_vdbg(bdc->dev, "BDC_EPSTS1:0x%x\n", temp); 47 dev_vdbg(bdc->dev, "BDC_EPSTS1:0x%x\n", temp);
48 48
49 temp = bdc_readl(bdc->regs, BDC_EPSTS2(0)); 49 temp = bdc_readl(bdc->regs, BDC_EPSTS2);
50 dev_vdbg(bdc->dev, "BDC_EPSTS2:0x%08x\n", temp); 50 dev_vdbg(bdc->dev, "BDC_EPSTS2:0x%08x\n", temp);
51 51
52 temp = bdc_readl(bdc->regs, BDC_EPSTS3(0)); 52 temp = bdc_readl(bdc->regs, BDC_EPSTS3);
53 dev_vdbg(bdc->dev, "BDC_EPSTS3:0x%08x\n", temp); 53 dev_vdbg(bdc->dev, "BDC_EPSTS3:0x%08x\n", temp);
54 54
55 temp = bdc_readl(bdc->regs, BDC_EPSTS4(0)); 55 temp = bdc_readl(bdc->regs, BDC_EPSTS4);
56 dev_vdbg(bdc->dev, "BDC_EPSTS4:0x%08x\n", temp); 56 dev_vdbg(bdc->dev, "BDC_EPSTS4:0x%08x\n", temp);
57 57
58 temp = bdc_readl(bdc->regs, BDC_EPSTS5(0)); 58 temp = bdc_readl(bdc->regs, BDC_EPSTS5);
59 dev_vdbg(bdc->dev, "BDC_EPSTS5:0x%08x\n", temp); 59 dev_vdbg(bdc->dev, "BDC_EPSTS5:0x%08x\n", temp);
60 60
61 temp = bdc_readl(bdc->regs, BDC_EPSTS6(0)); 61 temp = bdc_readl(bdc->regs, BDC_EPSTS6);
62 dev_vdbg(bdc->dev, "BDC_EPSTS6:0x%08x\n", temp); 62 dev_vdbg(bdc->dev, "BDC_EPSTS6:0x%08x\n", temp);
63 63
64 temp = bdc_readl(bdc->regs, BDC_EPSTS7(0)); 64 temp = bdc_readl(bdc->regs, BDC_EPSTS7);
65 dev_vdbg(bdc->dev, "BDC_EPSTS7:0x%08x\n", temp); 65 dev_vdbg(bdc->dev, "BDC_EPSTS7:0x%08x\n", temp);
66} 66}
67 67
diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c b/drivers/usb/gadget/udc/bdc/bdc_ep.c
index ff1ef24d1777..bfd8f7ade935 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_ep.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c
@@ -777,9 +777,9 @@ static int ep_dequeue(struct bdc_ep *ep, struct bdc_req *req)
777 */ 777 */
778 778
779 /* The current hw dequeue pointer */ 779 /* The current hw dequeue pointer */
780 tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS0(0)); 780 tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS0);
781 deq_ptr_64 = tmp_32; 781 deq_ptr_64 = tmp_32;
782 tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS1(0)); 782 tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS1);
783 deq_ptr_64 |= ((u64)tmp_32 << 32); 783 deq_ptr_64 |= ((u64)tmp_32 << 32);
784 784
785 /* we have the dma addr of next bd that will be fetched by hardware */ 785 /* we have the dma addr of next bd that will be fetched by hardware */
diff --git a/drivers/usb/gadget/udc/bdc/bdc_udc.c b/drivers/usb/gadget/udc/bdc/bdc_udc.c
index aae7458d8986..c84346146456 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_udc.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_udc.c
@@ -249,6 +249,7 @@ void bdc_sr_uspc(struct bdc *bdc, struct bdc_sr *sreport)
249 disconn = true; 249 disconn = true;
250 else if ((uspc & BDC_PCS) && !BDC_PST(uspc)) 250 else if ((uspc & BDC_PCS) && !BDC_PST(uspc))
251 connected = true; 251 connected = true;
252 clear_flags |= BDC_PCC;
252 } 253 }
253 254
254 /* Change in VBus and VBus is present */ 255 /* Change in VBus and VBus is present */
@@ -259,16 +260,16 @@ void bdc_sr_uspc(struct bdc *bdc, struct bdc_sr *sreport)
259 bdc_softconn(bdc); 260 bdc_softconn(bdc);
260 usb_gadget_set_state(&bdc->gadget, USB_STATE_POWERED); 261 usb_gadget_set_state(&bdc->gadget, USB_STATE_POWERED);
261 } 262 }
262 clear_flags = BDC_VBC; 263 clear_flags |= BDC_VBC;
263 } else if ((uspc & BDC_PRS) || (uspc & BDC_PRC) || disconn) { 264 } else if ((uspc & BDC_PRS) || (uspc & BDC_PRC) || disconn) {
264 /* Hot reset, warm reset, 2.0 bus reset or disconn */ 265 /* Hot reset, warm reset, 2.0 bus reset or disconn */
265 dev_dbg(bdc->dev, "Port reset or disconn\n"); 266 dev_dbg(bdc->dev, "Port reset or disconn\n");
266 bdc_uspc_disconnected(bdc, disconn); 267 bdc_uspc_disconnected(bdc, disconn);
267 clear_flags = BDC_PCC|BDC_PCS|BDC_PRS|BDC_PRC; 268 clear_flags |= BDC_PRC;
268 } else if ((uspc & BDC_PSC) && (uspc & BDC_PCS)) { 269 } else if ((uspc & BDC_PSC) && (uspc & BDC_PCS)) {
269 /* Change in Link state */ 270 /* Change in Link state */
270 handle_link_state_change(bdc, uspc); 271 handle_link_state_change(bdc, uspc);
271 clear_flags = BDC_PSC|BDC_PCS; 272 clear_flags |= BDC_PSC;
272 } 273 }
273 274
274 /* 275 /*
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index e6f04eee95c4..75c51ca4ee0f 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -812,6 +812,8 @@ int usb_gadget_map_request_by_dev(struct device *dev,
812 dev_err(dev, "failed to map buffer\n"); 812 dev_err(dev, "failed to map buffer\n");
813 return -EFAULT; 813 return -EFAULT;
814 } 814 }
815
816 req->dma_mapped = 1;
815 } 817 }
816 818
817 return 0; 819 return 0;
@@ -836,9 +838,10 @@ void usb_gadget_unmap_request_by_dev(struct device *dev,
836 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 838 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
837 839
838 req->num_mapped_sgs = 0; 840 req->num_mapped_sgs = 0;
839 } else { 841 } else if (req->dma_mapped) {
840 dma_unmap_single(dev, req->dma, req->length, 842 dma_unmap_single(dev, req->dma, req->length,
841 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 843 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
844 req->dma_mapped = 0;
842 } 845 }
843} 846}
844EXPORT_SYMBOL_GPL(usb_gadget_unmap_request_by_dev); 847EXPORT_SYMBOL_GPL(usb_gadget_unmap_request_by_dev);
@@ -1130,6 +1133,7 @@ static int check_pending_gadget_drivers(struct usb_udc *udc)
1130 * @release: a gadget release function. 1133 * @release: a gadget release function.
1131 * 1134 *
1132 * Returns zero on success, negative errno otherwise. 1135 * Returns zero on success, negative errno otherwise.
1136 * Calls the gadget release function in the latter case.
1133 */ 1137 */
1134int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, 1138int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
1135 void (*release)(struct device *dev)) 1139 void (*release)(struct device *dev))
@@ -1137,10 +1141,6 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
1137 struct usb_udc *udc; 1141 struct usb_udc *udc;
1138 int ret = -ENOMEM; 1142 int ret = -ENOMEM;
1139 1143
1140 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
1141 if (!udc)
1142 goto err1;
1143
1144 dev_set_name(&gadget->dev, "gadget"); 1144 dev_set_name(&gadget->dev, "gadget");
1145 INIT_WORK(&gadget->work, usb_gadget_state_work); 1145 INIT_WORK(&gadget->work, usb_gadget_state_work);
1146 gadget->dev.parent = parent; 1146 gadget->dev.parent = parent;
@@ -1150,7 +1150,13 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
1150 else 1150 else
1151 gadget->dev.release = usb_udc_nop_release; 1151 gadget->dev.release = usb_udc_nop_release;
1152 1152
1153 ret = device_register(&gadget->dev); 1153 device_initialize(&gadget->dev);
1154
1155 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
1156 if (!udc)
1157 goto err1;
1158
1159 ret = device_add(&gadget->dev);
1154 if (ret) 1160 if (ret)
1155 goto err2; 1161 goto err2;
1156 1162
@@ -1197,10 +1203,10 @@ err3:
1197 device_del(&gadget->dev); 1203 device_del(&gadget->dev);
1198 1204
1199err2: 1205err2:
1200 put_device(&gadget->dev);
1201 kfree(udc); 1206 kfree(udc);
1202 1207
1203err1: 1208err1:
1209 put_device(&gadget->dev);
1204 return ret; 1210 return ret;
1205} 1211}
1206EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); 1212EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release);
diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
index 3c3760315910..a030d7923d7d 100644
--- a/drivers/usb/gadget/udc/dummy_hcd.c
+++ b/drivers/usb/gadget/udc/dummy_hcd.c
@@ -2776,7 +2776,7 @@ static int __init init(void)
2776 if (retval < 0) { 2776 if (retval < 0) {
2777 i--; 2777 i--;
2778 while (i >= 0) 2778 while (i >= 0)
2779 platform_device_del(the_udc_pdev[i]); 2779 platform_device_del(the_udc_pdev[i--]);
2780 goto err_add_udc; 2780 goto err_add_udc;
2781 } 2781 }
2782 } 2782 }
diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c
index e1de8fe599a3..df37c1e6e9d5 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -8,6 +8,7 @@
8 * the Free Software Foundation; version 2 of the License. 8 * the Free Software Foundation; version 2 of the License.
9 */ 9 */
10 10
11#include <linux/debugfs.h>
11#include <linux/delay.h> 12#include <linux/delay.h>
12#include <linux/dma-mapping.h> 13#include <linux/dma-mapping.h>
13#include <linux/err.h> 14#include <linux/err.h>
@@ -20,6 +21,8 @@
20#include <linux/pm_runtime.h> 21#include <linux/pm_runtime.h>
21#include <linux/sizes.h> 22#include <linux/sizes.h>
22#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/sys_soc.h>
25#include <linux/uaccess.h>
23#include <linux/usb/ch9.h> 26#include <linux/usb/ch9.h>
24#include <linux/usb/gadget.h> 27#include <linux/usb/gadget.h>
25 28
@@ -347,6 +350,7 @@ struct renesas_usb3 {
347 bool workaround_for_vbus; 350 bool workaround_for_vbus;
348 bool extcon_host; /* check id and set EXTCON_USB_HOST */ 351 bool extcon_host; /* check id and set EXTCON_USB_HOST */
349 bool extcon_usb; /* check vbus and set EXTCON_USB */ 352 bool extcon_usb; /* check vbus and set EXTCON_USB */
353 bool forced_b_device;
350}; 354};
351 355
352#define gadget_to_renesas_usb3(_gadget) \ 356#define gadget_to_renesas_usb3(_gadget) \
@@ -663,7 +667,9 @@ static void usb3_mode_config(struct renesas_usb3 *usb3, bool host, bool a_dev)
663 spin_lock_irqsave(&usb3->lock, flags); 667 spin_lock_irqsave(&usb3->lock, flags);
664 usb3_set_mode(usb3, host); 668 usb3_set_mode(usb3, host);
665 usb3_vbus_out(usb3, a_dev); 669 usb3_vbus_out(usb3, a_dev);
666 if (!host && a_dev) /* for A-Peripheral */ 670 /* for A-Peripheral or forced B-device mode */
671 if ((!host && a_dev) ||
672 (usb3->workaround_for_vbus && usb3->forced_b_device))
667 usb3_connect(usb3); 673 usb3_connect(usb3);
668 spin_unlock_irqrestore(&usb3->lock, flags); 674 spin_unlock_irqrestore(&usb3->lock, flags);
669} 675}
@@ -677,7 +683,7 @@ static void usb3_check_id(struct renesas_usb3 *usb3)
677{ 683{
678 usb3->extcon_host = usb3_is_a_device(usb3); 684 usb3->extcon_host = usb3_is_a_device(usb3);
679 685
680 if (usb3->extcon_host) 686 if (usb3->extcon_host && !usb3->forced_b_device)
681 usb3_mode_config(usb3, true, true); 687 usb3_mode_config(usb3, true, true);
682 else 688 else
683 usb3_mode_config(usb3, false, false); 689 usb3_mode_config(usb3, false, false);
@@ -2192,7 +2198,7 @@ static void renesas_usb3_ep_fifo_flush(struct usb_ep *_ep)
2192 } 2198 }
2193} 2199}
2194 2200
2195static struct usb_ep_ops renesas_usb3_ep_ops = { 2201static const struct usb_ep_ops renesas_usb3_ep_ops = {
2196 .enable = renesas_usb3_ep_enable, 2202 .enable = renesas_usb3_ep_enable,
2197 .disable = renesas_usb3_ep_disable, 2203 .disable = renesas_usb3_ep_disable,
2198 2204
@@ -2283,6 +2289,9 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,
2283 if (!usb3->driver) 2289 if (!usb3->driver)
2284 return -ENODEV; 2290 return -ENODEV;
2285 2291
2292 if (usb3->forced_b_device)
2293 return -EBUSY;
2294
2286 if (!strncmp(buf, "host", strlen("host"))) 2295 if (!strncmp(buf, "host", strlen("host")))
2287 new_mode_is_host = true; 2296 new_mode_is_host = true;
2288 else if (!strncmp(buf, "peripheral", strlen("peripheral"))) 2297 else if (!strncmp(buf, "peripheral", strlen("peripheral")))
@@ -2310,6 +2319,70 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr,
2310} 2319}
2311static DEVICE_ATTR_RW(role); 2320static DEVICE_ATTR_RW(role);
2312 2321
2322static int renesas_usb3_b_device_show(struct seq_file *s, void *unused)
2323{
2324 struct renesas_usb3 *usb3 = s->private;
2325
2326 seq_printf(s, "%d\n", usb3->forced_b_device);
2327
2328 return 0;
2329}
2330
2331static int renesas_usb3_b_device_open(struct inode *inode, struct file *file)
2332{
2333 return single_open(file, renesas_usb3_b_device_show, inode->i_private);
2334}
2335
2336static ssize_t renesas_usb3_b_device_write(struct file *file,
2337 const char __user *ubuf,
2338 size_t count, loff_t *ppos)
2339{
2340 struct seq_file *s = file->private_data;
2341 struct renesas_usb3 *usb3 = s->private;
2342 char buf[32];
2343
2344 if (!usb3->driver)
2345 return -ENODEV;
2346
2347 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
2348 return -EFAULT;
2349
2350 if (!strncmp(buf, "1", 1))
2351 usb3->forced_b_device = true;
2352 else
2353 usb3->forced_b_device = false;
2354
2355 /* Let this driver call usb3_connect() anyway */
2356 usb3_check_id(usb3);
2357
2358 return count;
2359}
2360
2361static const struct file_operations renesas_usb3_b_device_fops = {
2362 .open = renesas_usb3_b_device_open,
2363 .write = renesas_usb3_b_device_write,
2364 .read = seq_read,
2365 .llseek = seq_lseek,
2366 .release = single_release,
2367};
2368
2369static void renesas_usb3_debugfs_init(struct renesas_usb3 *usb3,
2370 struct device *dev)
2371{
2372 struct dentry *root, *file;
2373
2374 root = debugfs_create_dir(dev_name(dev), NULL);
2375 if (IS_ERR_OR_NULL(root)) {
2376 dev_info(dev, "%s: Can't create the root\n", __func__);
2377 return;
2378 }
2379
2380 file = debugfs_create_file("b_device", 0644, root, usb3,
2381 &renesas_usb3_b_device_fops);
2382 if (!file)
2383 dev_info(dev, "%s: Can't create debugfs mode\n", __func__);
2384}
2385
2313/*------- platform_driver ------------------------------------------------*/ 2386/*------- platform_driver ------------------------------------------------*/
2314static int renesas_usb3_remove(struct platform_device *pdev) 2387static int renesas_usb3_remove(struct platform_device *pdev)
2315{ 2388{
@@ -2432,22 +2505,40 @@ static void renesas_usb3_init_ram(struct renesas_usb3 *usb3, struct device *dev,
2432 } 2505 }
2433} 2506}
2434 2507
2435static const struct renesas_usb3_priv renesas_usb3_priv_r8a7795 = { 2508static const struct renesas_usb3_priv renesas_usb3_priv_r8a7795_es1 = {
2436 .ramsize_per_ramif = SZ_16K, 2509 .ramsize_per_ramif = SZ_16K,
2437 .num_ramif = 2, 2510 .num_ramif = 2,
2438 .ramsize_per_pipe = SZ_4K, 2511 .ramsize_per_pipe = SZ_4K,
2439 .workaround_for_vbus = true, 2512 .workaround_for_vbus = true,
2440}; 2513};
2441 2514
2515static const struct renesas_usb3_priv renesas_usb3_priv_gen3 = {
2516 .ramsize_per_ramif = SZ_16K,
2517 .num_ramif = 4,
2518 .ramsize_per_pipe = SZ_4K,
2519};
2520
2442static const struct of_device_id usb3_of_match[] = { 2521static const struct of_device_id usb3_of_match[] = {
2443 { 2522 {
2444 .compatible = "renesas,r8a7795-usb3-peri", 2523 .compatible = "renesas,r8a7795-usb3-peri",
2445 .data = &renesas_usb3_priv_r8a7795, 2524 .data = &renesas_usb3_priv_gen3,
2525 },
2526 {
2527 .compatible = "renesas,rcar-gen3-usb3-peri",
2528 .data = &renesas_usb3_priv_gen3,
2446 }, 2529 },
2447 { }, 2530 { },
2448}; 2531};
2449MODULE_DEVICE_TABLE(of, usb3_of_match); 2532MODULE_DEVICE_TABLE(of, usb3_of_match);
2450 2533
2534static const struct soc_device_attribute renesas_usb3_quirks_match[] = {
2535 {
2536 .soc_id = "r8a7795", .revision = "ES1.*",
2537 .data = &renesas_usb3_priv_r8a7795_es1,
2538 },
2539 { /* sentinel */ },
2540};
2541
2451static const unsigned int renesas_usb3_cable[] = { 2542static const unsigned int renesas_usb3_cable[] = {
2452 EXTCON_USB, 2543 EXTCON_USB,
2453 EXTCON_USB_HOST, 2544 EXTCON_USB_HOST,
@@ -2461,15 +2552,23 @@ static int renesas_usb3_probe(struct platform_device *pdev)
2461 const struct of_device_id *match; 2552 const struct of_device_id *match;
2462 int irq, ret; 2553 int irq, ret;
2463 const struct renesas_usb3_priv *priv; 2554 const struct renesas_usb3_priv *priv;
2555 const struct soc_device_attribute *attr;
2464 2556
2465 match = of_match_node(usb3_of_match, pdev->dev.of_node); 2557 match = of_match_node(usb3_of_match, pdev->dev.of_node);
2466 if (!match) 2558 if (!match)
2467 return -ENODEV; 2559 return -ENODEV;
2468 priv = match->data; 2560
2561 attr = soc_device_match(renesas_usb3_quirks_match);
2562 if (attr)
2563 priv = attr->data;
2564 else
2565 priv = match->data;
2469 2566
2470 irq = platform_get_irq(pdev, 0); 2567 irq = platform_get_irq(pdev, 0);
2471 if (irq < 0) 2568 if (irq < 0) {
2472 return -ENODEV; 2569 dev_err(&pdev->dev, "Failed to get IRQ: %d\n", irq);
2570 return irq;
2571 }
2473 2572
2474 usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL); 2573 usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL);
2475 if (!usb3) 2574 if (!usb3)
@@ -2527,6 +2626,8 @@ static int renesas_usb3_probe(struct platform_device *pdev)
2527 2626
2528 usb3->workaround_for_vbus = priv->workaround_for_vbus; 2627 usb3->workaround_for_vbus = priv->workaround_for_vbus;
2529 2628
2629 renesas_usb3_debugfs_init(usb3, &pdev->dev);
2630
2530 dev_info(&pdev->dev, "probed\n"); 2631 dev_info(&pdev->dev, "probed\n");
2531 2632
2532 return 0; 2633 return 0;
diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index 0d3ebb353e08..088e3e685c4f 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -500,6 +500,7 @@ static const struct dev_pm_ops mtu3_pm_ops = {
500 500
501static const struct of_device_id mtu3_of_match[] = { 501static const struct of_device_id mtu3_of_match[] = {
502 {.compatible = "mediatek,mt8173-mtu3",}, 502 {.compatible = "mediatek,mt8173-mtu3",},
503 {.compatible = "mediatek,mtu3",},
503 {}, 504 {},
504}; 505};
505 506
diff --git a/drivers/usb/phy/phy-qcom-8x16-usb.c b/drivers/usb/phy/phy-qcom-8x16-usb.c
index b6a83a5cbad3..679afeaaa9a8 100644
--- a/drivers/usb/phy/phy-qcom-8x16-usb.c
+++ b/drivers/usb/phy/phy-qcom-8x16-usb.c
@@ -270,12 +270,9 @@ static int phy_8x16_probe(struct platform_device *pdev)
270 platform_set_drvdata(pdev, qphy); 270 platform_set_drvdata(pdev, qphy);
271 271
272 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 272 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
273 if (!res) 273 qphy->regs = devm_ioremap_resource(&pdev->dev, res);
274 return -EINVAL; 274 if (IS_ERR(qphy->regs))
275 275 return PTR_ERR(qphy->regs);
276 qphy->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res));
277 if (!qphy->regs)
278 return -ENOMEM;
279 276
280 phy = &qphy->phy; 277 phy = &qphy->phy;
281 phy->dev = &pdev->dev; 278 phy->dev = &pdev->dev;
diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c
index 75f3127407af..89f4ac4cd93e 100644
--- a/drivers/usb/phy/phy.c
+++ b/drivers/usb/phy/phy.c
@@ -18,6 +18,18 @@
18 18
19#include <linux/usb/phy.h> 19#include <linux/usb/phy.h>
20 20
21/* Default current range by charger type. */
22#define DEFAULT_SDP_CUR_MIN 2
23#define DEFAULT_SDP_CUR_MAX 500
24#define DEFAULT_SDP_CUR_MIN_SS 150
25#define DEFAULT_SDP_CUR_MAX_SS 900
26#define DEFAULT_DCP_CUR_MIN 500
27#define DEFAULT_DCP_CUR_MAX 5000
28#define DEFAULT_CDP_CUR_MIN 1500
29#define DEFAULT_CDP_CUR_MAX 5000
30#define DEFAULT_ACA_CUR_MIN 1500
31#define DEFAULT_ACA_CUR_MAX 5000
32
21static LIST_HEAD(phy_list); 33static LIST_HEAD(phy_list);
22static LIST_HEAD(phy_bind_list); 34static LIST_HEAD(phy_bind_list);
23static DEFINE_SPINLOCK(phy_lock); 35static DEFINE_SPINLOCK(phy_lock);
@@ -77,6 +89,221 @@ static struct usb_phy *__of_usb_find_phy(struct device_node *node)
77 return ERR_PTR(-EPROBE_DEFER); 89 return ERR_PTR(-EPROBE_DEFER);
78} 90}
79 91
92static void usb_phy_set_default_current(struct usb_phy *usb_phy)
93{
94 usb_phy->chg_cur.sdp_min = DEFAULT_SDP_CUR_MIN;
95 usb_phy->chg_cur.sdp_max = DEFAULT_SDP_CUR_MAX;
96 usb_phy->chg_cur.dcp_min = DEFAULT_DCP_CUR_MIN;
97 usb_phy->chg_cur.dcp_max = DEFAULT_DCP_CUR_MAX;
98 usb_phy->chg_cur.cdp_min = DEFAULT_CDP_CUR_MIN;
99 usb_phy->chg_cur.cdp_max = DEFAULT_CDP_CUR_MAX;
100 usb_phy->chg_cur.aca_min = DEFAULT_ACA_CUR_MIN;
101 usb_phy->chg_cur.aca_max = DEFAULT_ACA_CUR_MAX;
102}
103
104/**
105 * usb_phy_notify_charger_work - notify the USB charger state
106 * @work - the charger work to notify the USB charger state
107 *
108 * This work can be issued when USB charger state has been changed or
109 * USB charger current has been changed, then we can notify the current
110 * what can be drawn to power user and the charger state to userspace.
111 *
112 * If we get the charger type from extcon subsystem, we can notify the
113 * charger state to power user automatically by usb_phy_get_charger_type()
114 * issuing from extcon subsystem.
115 *
116 * If we get the charger type from ->charger_detect() instead of extcon
117 * subsystem, the usb phy driver should issue usb_phy_set_charger_state()
118 * to set charger state when the charger state has been changed.
119 */
120static void usb_phy_notify_charger_work(struct work_struct *work)
121{
122 struct usb_phy *usb_phy = container_of(work, struct usb_phy, chg_work);
123 char uchger_state[50] = { 0 };
124 char *envp[] = { uchger_state, NULL };
125 unsigned int min, max;
126
127 switch (usb_phy->chg_state) {
128 case USB_CHARGER_PRESENT:
129 usb_phy_get_charger_current(usb_phy, &min, &max);
130
131 atomic_notifier_call_chain(&usb_phy->notifier, max, usb_phy);
132 snprintf(uchger_state, ARRAY_SIZE(uchger_state),
133 "USB_CHARGER_STATE=%s", "USB_CHARGER_PRESENT");
134 break;
135 case USB_CHARGER_ABSENT:
136 usb_phy_set_default_current(usb_phy);
137
138 atomic_notifier_call_chain(&usb_phy->notifier, 0, usb_phy);
139 snprintf(uchger_state, ARRAY_SIZE(uchger_state),
140 "USB_CHARGER_STATE=%s", "USB_CHARGER_ABSENT");
141 break;
142 default:
143 dev_warn(usb_phy->dev, "Unknown USB charger state: %d\n",
144 usb_phy->chg_state);
145 return;
146 }
147
148 kobject_uevent_env(&usb_phy->dev->kobj, KOBJ_CHANGE, envp);
149}
150
151static void __usb_phy_get_charger_type(struct usb_phy *usb_phy)
152{
153 if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_SDP) > 0) {
154 usb_phy->chg_type = SDP_TYPE;
155 usb_phy->chg_state = USB_CHARGER_PRESENT;
156 } else if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_CDP) > 0) {
157 usb_phy->chg_type = CDP_TYPE;
158 usb_phy->chg_state = USB_CHARGER_PRESENT;
159 } else if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_DCP) > 0) {
160 usb_phy->chg_type = DCP_TYPE;
161 usb_phy->chg_state = USB_CHARGER_PRESENT;
162 } else if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_ACA) > 0) {
163 usb_phy->chg_type = ACA_TYPE;
164 usb_phy->chg_state = USB_CHARGER_PRESENT;
165 } else {
166 usb_phy->chg_type = UNKNOWN_TYPE;
167 usb_phy->chg_state = USB_CHARGER_ABSENT;
168 }
169
170 schedule_work(&usb_phy->chg_work);
171}
172
173/**
174 * usb_phy_get_charger_type - get charger type from extcon subsystem
175 * @nb -the notifier block to determine charger type
176 * @state - the cable state
177 * @data - private data
178 *
179 * Determin the charger type from extcon subsystem which also means the
180 * charger state has been chaned, then we should notify this event.
181 */
182static int usb_phy_get_charger_type(struct notifier_block *nb,
183 unsigned long state, void *data)
184{
185 struct usb_phy *usb_phy = container_of(nb, struct usb_phy, type_nb);
186
187 __usb_phy_get_charger_type(usb_phy);
188 return NOTIFY_OK;
189}
190
191/**
192 * usb_phy_set_charger_current - set the USB charger current
193 * @usb_phy - the USB phy to be used
194 * @mA - the current need to be set
195 *
196 * Usually we only change the charger default current when USB finished the
197 * enumeration as one SDP charger. As one SDP charger, usb_phy_set_power()
198 * will issue this function to change charger current when after setting USB
199 * configuration, or suspend/resume USB. For other type charger, we should
200 * use the default charger current and we do not suggest to issue this function
201 * to change the charger current.
202 *
203 * When USB charger current has been changed, we need to notify the power users.
204 */
205void usb_phy_set_charger_current(struct usb_phy *usb_phy, unsigned int mA)
206{
207 switch (usb_phy->chg_type) {
208 case SDP_TYPE:
209 if (usb_phy->chg_cur.sdp_max == mA)
210 return;
211
212 usb_phy->chg_cur.sdp_max = (mA > DEFAULT_SDP_CUR_MAX_SS) ?
213 DEFAULT_SDP_CUR_MAX_SS : mA;
214 break;
215 case DCP_TYPE:
216 if (usb_phy->chg_cur.dcp_max == mA)
217 return;
218
219 usb_phy->chg_cur.dcp_max = (mA > DEFAULT_DCP_CUR_MAX) ?
220 DEFAULT_DCP_CUR_MAX : mA;
221 break;
222 case CDP_TYPE:
223 if (usb_phy->chg_cur.cdp_max == mA)
224 return;
225
226 usb_phy->chg_cur.cdp_max = (mA > DEFAULT_CDP_CUR_MAX) ?
227 DEFAULT_CDP_CUR_MAX : mA;
228 break;
229 case ACA_TYPE:
230 if (usb_phy->chg_cur.aca_max == mA)
231 return;
232
233 usb_phy->chg_cur.aca_max = (mA > DEFAULT_ACA_CUR_MAX) ?
234 DEFAULT_ACA_CUR_MAX : mA;
235 break;
236 default:
237 return;
238 }
239
240 schedule_work(&usb_phy->chg_work);
241}
242EXPORT_SYMBOL_GPL(usb_phy_set_charger_current);
243
244/**
245 * usb_phy_get_charger_current - get the USB charger current
246 * @usb_phy - the USB phy to be used
247 * @min - the minimum current
248 * @max - the maximum current
249 *
250 * Usually we will notify the maximum current to power user, but for some
251 * special case, power user also need the minimum current value. Then the
252 * power user can issue this function to get the suitable current.
253 */
254void usb_phy_get_charger_current(struct usb_phy *usb_phy,
255 unsigned int *min, unsigned int *max)
256{
257 switch (usb_phy->chg_type) {
258 case SDP_TYPE:
259 *min = usb_phy->chg_cur.sdp_min;
260 *max = usb_phy->chg_cur.sdp_max;
261 break;
262 case DCP_TYPE:
263 *min = usb_phy->chg_cur.dcp_min;
264 *max = usb_phy->chg_cur.dcp_max;
265 break;
266 case CDP_TYPE:
267 *min = usb_phy->chg_cur.cdp_min;
268 *max = usb_phy->chg_cur.cdp_max;
269 break;
270 case ACA_TYPE:
271 *min = usb_phy->chg_cur.aca_min;
272 *max = usb_phy->chg_cur.aca_max;
273 break;
274 default:
275 *min = 0;
276 *max = 0;
277 break;
278 }
279}
280EXPORT_SYMBOL_GPL(usb_phy_get_charger_current);
281
282/**
283 * usb_phy_set_charger_state - set the USB charger state
284 * @usb_phy - the USB phy to be used
285 * @state - the new state need to be set for charger
286 *
287 * The usb phy driver can issue this function when the usb phy driver
288 * detected the charger state has been changed, in this case the charger
289 * type should be get from ->charger_detect().
290 */
291void usb_phy_set_charger_state(struct usb_phy *usb_phy,
292 enum usb_charger_state state)
293{
294 if (usb_phy->chg_state == state || !usb_phy->charger_detect)
295 return;
296
297 usb_phy->chg_state = state;
298 if (usb_phy->chg_state == USB_CHARGER_PRESENT)
299 usb_phy->chg_type = usb_phy->charger_detect(usb_phy);
300 else
301 usb_phy->chg_type = UNKNOWN_TYPE;
302
303 schedule_work(&usb_phy->chg_work);
304}
305EXPORT_SYMBOL_GPL(usb_phy_set_charger_state);
306
80static void devm_usb_phy_release(struct device *dev, void *res) 307static void devm_usb_phy_release(struct device *dev, void *res)
81{ 308{
82 struct usb_phy *phy = *(struct usb_phy **)res; 309 struct usb_phy *phy = *(struct usb_phy **)res;
@@ -124,6 +351,44 @@ static int usb_add_extcon(struct usb_phy *x)
124 "register VBUS notifier failed\n"); 351 "register VBUS notifier failed\n");
125 return ret; 352 return ret;
126 } 353 }
354 } else {
355 x->type_nb.notifier_call = usb_phy_get_charger_type;
356
357 ret = devm_extcon_register_notifier(x->dev, x->edev,
358 EXTCON_CHG_USB_SDP,
359 &x->type_nb);
360 if (ret) {
361 dev_err(x->dev,
362 "register extcon USB SDP failed.\n");
363 return ret;
364 }
365
366 ret = devm_extcon_register_notifier(x->dev, x->edev,
367 EXTCON_CHG_USB_CDP,
368 &x->type_nb);
369 if (ret) {
370 dev_err(x->dev,
371 "register extcon USB CDP failed.\n");
372 return ret;
373 }
374
375 ret = devm_extcon_register_notifier(x->dev, x->edev,
376 EXTCON_CHG_USB_DCP,
377 &x->type_nb);
378 if (ret) {
379 dev_err(x->dev,
380 "register extcon USB DCP failed.\n");
381 return ret;
382 }
383
384 ret = devm_extcon_register_notifier(x->dev, x->edev,
385 EXTCON_CHG_USB_ACA,
386 &x->type_nb);
387 if (ret) {
388 dev_err(x->dev,
389 "register extcon USB ACA failed.\n");
390 return ret;
391 }
127 } 392 }
128 393
129 if (x->id_nb.notifier_call) { 394 if (x->id_nb.notifier_call) {
@@ -145,6 +410,13 @@ static int usb_add_extcon(struct usb_phy *x)
145 } 410 }
146 } 411 }
147 412
413 usb_phy_set_default_current(x);
414 INIT_WORK(&x->chg_work, usb_phy_notify_charger_work);
415 x->chg_type = UNKNOWN_TYPE;
416 x->chg_state = USB_CHARGER_DEFAULT;
417 if (x->type_nb.notifier_call)
418 __usb_phy_get_charger_type(x);
419
148 return 0; 420 return 0;
149} 421}
150 422
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index 2c8161bcf5b5..c068b673420b 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -764,7 +764,7 @@ static int usbhsg_ep_set_wedge(struct usb_ep *ep)
764 return __usbhsg_ep_set_halt_wedge(ep, 1, 1); 764 return __usbhsg_ep_set_halt_wedge(ep, 1, 1);
765} 765}
766 766
767static struct usb_ep_ops usbhsg_ep_ops = { 767static const struct usb_ep_ops usbhsg_ep_ops = {
768 .enable = usbhsg_ep_enable, 768 .enable = usbhsg_ep_enable,
769 .disable = usbhsg_ep_disable, 769 .disable = usbhsg_ep_disable,
770 770
@@ -1082,7 +1082,6 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1082 ret = -ENOMEM; 1082 ret = -ENOMEM;
1083 goto usbhs_mod_gadget_probe_err_gpriv; 1083 goto usbhs_mod_gadget_probe_err_gpriv;
1084 } 1084 }
1085 spin_lock_init(&uep->lock);
1086 1085
1087 gpriv->transceiver = usb_get_phy(USB_PHY_TYPE_UNDEFINED); 1086 gpriv->transceiver = usb_get_phy(USB_PHY_TYPE_UNDEFINED);
1088 dev_info(dev, "%stransceiver found\n", 1087 dev_info(dev, "%stransceiver found\n",
@@ -1132,6 +1131,7 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1132 uep->ep.name = uep->ep_name; 1131 uep->ep.name = uep->ep_name;
1133 uep->ep.ops = &usbhsg_ep_ops; 1132 uep->ep.ops = &usbhsg_ep_ops;
1134 INIT_LIST_HEAD(&uep->ep.ep_list); 1133 INIT_LIST_HEAD(&uep->ep.ep_list);
1134 spin_lock_init(&uep->lock);
1135 1135
1136 /* init DCP */ 1136 /* init DCP */
1137 if (usbhsg_is_dcp(uep)) { 1137 if (usbhsg_is_dcp(uep)) {
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 5006f9b5d837..6519cdc4c7d3 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -363,6 +363,12 @@ struct hid_item {
363#define HID_GROUP_LOGITECH_DJ_DEVICE 0x0102 363#define HID_GROUP_LOGITECH_DJ_DEVICE 0x0102
364 364
365/* 365/*
366 * HID protocol status
367 */
368#define HID_REPORT_PROTOCOL 1
369#define HID_BOOT_PROTOCOL 0
370
371/*
366 * This is the global environment of the parser. This information is 372 * This is the global environment of the parser. This information is
367 * persistent for main-items. The global environment can be saved and 373 * persistent for main-items. The global environment can be saved and
368 * restored with PUSH/POP statements. 374 * restored with PUSH/POP statements.
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 1a4a4bacfae6..21468a722c4a 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -48,6 +48,7 @@ struct usb_ep;
48 * by adding a zero length packet as needed; 48 * by adding a zero length packet as needed;
49 * @short_not_ok: When reading data, makes short packets be 49 * @short_not_ok: When reading data, makes short packets be
50 * treated as errors (queue stops advancing till cleanup). 50 * treated as errors (queue stops advancing till cleanup).
51 * @dma_mapped: Indicates if request has been mapped to DMA (internal)
51 * @complete: Function called when request completes, so this request and 52 * @complete: Function called when request completes, so this request and
52 * its buffer may be re-used. The function will always be called with 53 * its buffer may be re-used. The function will always be called with
53 * interrupts disabled, and it must not sleep. 54 * interrupts disabled, and it must not sleep.
@@ -103,6 +104,7 @@ struct usb_request {
103 unsigned no_interrupt:1; 104 unsigned no_interrupt:1;
104 unsigned zero:1; 105 unsigned zero:1;
105 unsigned short_not_ok:1; 106 unsigned short_not_ok:1;
107 unsigned dma_mapped:1;
106 108
107 void (*complete)(struct usb_ep *ep, 109 void (*complete)(struct usb_ep *ep,
108 struct usb_request *req); 110 struct usb_request *req);
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index 299245105610..de881b171ba9 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -12,6 +12,7 @@
12#include <linux/extcon.h> 12#include <linux/extcon.h>
13#include <linux/notifier.h> 13#include <linux/notifier.h>
14#include <linux/usb.h> 14#include <linux/usb.h>
15#include <uapi/linux/usb/charger.h>
15 16
16enum usb_phy_interface { 17enum usb_phy_interface {
17 USBPHY_INTERFACE_MODE_UNKNOWN, 18 USBPHY_INTERFACE_MODE_UNKNOWN,
@@ -72,6 +73,17 @@ struct usb_phy_io_ops {
72 int (*write)(struct usb_phy *x, u32 val, u32 reg); 73 int (*write)(struct usb_phy *x, u32 val, u32 reg);
73}; 74};
74 75
76struct usb_charger_current {
77 unsigned int sdp_min;
78 unsigned int sdp_max;
79 unsigned int dcp_min;
80 unsigned int dcp_max;
81 unsigned int cdp_min;
82 unsigned int cdp_max;
83 unsigned int aca_min;
84 unsigned int aca_max;
85};
86
75struct usb_phy { 87struct usb_phy {
76 struct device *dev; 88 struct device *dev;
77 const char *label; 89 const char *label;
@@ -91,6 +103,13 @@ struct usb_phy {
91 struct extcon_dev *id_edev; 103 struct extcon_dev *id_edev;
92 struct notifier_block vbus_nb; 104 struct notifier_block vbus_nb;
93 struct notifier_block id_nb; 105 struct notifier_block id_nb;
106 struct notifier_block type_nb;
107
108 /* Support USB charger */
109 enum usb_charger_type chg_type;
110 enum usb_charger_state chg_state;
111 struct usb_charger_current chg_cur;
112 struct work_struct chg_work;
94 113
95 /* for notification of usb_phy_events */ 114 /* for notification of usb_phy_events */
96 struct atomic_notifier_head notifier; 115 struct atomic_notifier_head notifier;
@@ -129,6 +148,12 @@ struct usb_phy {
129 enum usb_device_speed speed); 148 enum usb_device_speed speed);
130 int (*notify_disconnect)(struct usb_phy *x, 149 int (*notify_disconnect)(struct usb_phy *x,
131 enum usb_device_speed speed); 150 enum usb_device_speed speed);
151
152 /*
153 * Charger detection method can be implemented if you need to
154 * manually detect the charger type.
155 */
156 enum usb_charger_type (*charger_detect)(struct usb_phy *x);
132}; 157};
133 158
134/** 159/**
@@ -219,6 +244,12 @@ extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
219extern int usb_bind_phy(const char *dev_name, u8 index, 244extern int usb_bind_phy(const char *dev_name, u8 index,
220 const char *phy_dev_name); 245 const char *phy_dev_name);
221extern void usb_phy_set_event(struct usb_phy *x, unsigned long event); 246extern void usb_phy_set_event(struct usb_phy *x, unsigned long event);
247extern void usb_phy_set_charger_current(struct usb_phy *usb_phy,
248 unsigned int mA);
249extern void usb_phy_get_charger_current(struct usb_phy *usb_phy,
250 unsigned int *min, unsigned int *max);
251extern void usb_phy_set_charger_state(struct usb_phy *usb_phy,
252 enum usb_charger_state state);
222#else 253#else
223static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) 254static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
224{ 255{
@@ -270,11 +301,29 @@ static inline int usb_bind_phy(const char *dev_name, u8 index,
270static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event) 301static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event)
271{ 302{
272} 303}
304
305static inline void usb_phy_set_charger_current(struct usb_phy *usb_phy,
306 unsigned int mA)
307{
308}
309
310static inline void usb_phy_get_charger_current(struct usb_phy *usb_phy,
311 unsigned int *min,
312 unsigned int *max)
313{
314}
315
316static inline void usb_phy_set_charger_state(struct usb_phy *usb_phy,
317 enum usb_charger_state state)
318{
319}
273#endif 320#endif
274 321
275static inline int 322static inline int
276usb_phy_set_power(struct usb_phy *x, unsigned mA) 323usb_phy_set_power(struct usb_phy *x, unsigned mA)
277{ 324{
325 usb_phy_set_charger_current(x, mA);
326
278 if (x && x->set_power) 327 if (x && x->set_power)
279 return x->set_power(x, mA); 328 return x->set_power(x, mA);
280 return 0; 329 return 0;
diff --git a/include/uapi/linux/usb/charger.h b/include/uapi/linux/usb/charger.h
new file mode 100644
index 000000000000..5f72af35b3ed
--- /dev/null
+++ b/include/uapi/linux/usb/charger.h
@@ -0,0 +1,31 @@
1/*
2 * This file defines the USB charger type and state that are needed for
3 * USB device APIs.
4 */
5
6#ifndef _UAPI__LINUX_USB_CHARGER_H
7#define _UAPI__LINUX_USB_CHARGER_H
8
9/*
10 * USB charger type:
11 * SDP (Standard Downstream Port)
12 * DCP (Dedicated Charging Port)
13 * CDP (Charging Downstream Port)
14 * ACA (Accessory Charger Adapters)
15 */
16enum usb_charger_type {
17 UNKNOWN_TYPE,
18 SDP_TYPE,
19 DCP_TYPE,
20 CDP_TYPE,
21 ACA_TYPE,
22};
23
24/* USB charger state */
25enum usb_charger_state {
26 USB_CHARGER_DEFAULT,
27 USB_CHARGER_PRESENT,
28 USB_CHARGER_ABSENT,
29};
30
31#endif /* _UAPI__LINUX_USB_CHARGER_H */