sunxi: initial 4.4 support
[openwrt/openwrt.git] / target / linux / sunxi / patches-4.4 / 144-usb-ehci-plat-support-multiple-reset-ctrllines.patch
1 From 957e8f96c67052ca843ea9ffc5223662b973e5de Mon Sep 17 00:00:00 2001
2 From: Reinder de Haan <patchesrdh@mveas.com>
3 Date: Sun, 15 Nov 2015 14:24:46 +0100
4 Subject: [PATCH] ehci-platform: Add support for controllers with multiple
5 reset lines
6
7 At least the EHCI/OHCI found on the Allwinnner H3 SoC needs multiple
8 reset lines, the controller will not initialize while the reset for
9 its companion is still asserted, which means we need to de-assert
10 2 resets for the controller to work.
11
12 Signed-off-by: Reinder de Haan <patchesrdh@mveas.com>
13 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
14 ---
15 Changes in v2:
16 -Use the new reset_control_[de]assert_shared reset-controller functions
17 ---
18 Documentation/devicetree/bindings/usb/usb-ehci.txt | 2 +-
19 drivers/usb/host/ehci-platform.c | 47 +++++++++++++---------
20 2 files changed, 30 insertions(+), 19 deletions(-)
21
22 diff --git a/Documentation/devicetree/bindings/usb/usb-ehci.txt b/Documentation/devicetree/bindings/usb/usb-ehci.txt
23 index a12d601..0701812 100644
24 --- a/Documentation/devicetree/bindings/usb/usb-ehci.txt
25 +++ b/Documentation/devicetree/bindings/usb/usb-ehci.txt
26 @@ -18,7 +18,7 @@ Optional properties:
27 - clocks : a list of phandle + clock specifier pairs
28 - phys : phandle + phy specifier pair
29 - phy-names : "usb"
30 - - resets : phandle + reset specifier pair
31 + - resets : a list of phandle + reset specifier pairs
32
33 Example (Sequoia 440EPx):
34 ehci@e0000300 {
35 diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
36 index bd7082f2..6fbf32a 100644
37 --- a/drivers/usb/host/ehci-platform.c
38 +++ b/drivers/usb/host/ehci-platform.c
39 @@ -39,11 +39,12 @@
40
41 #define DRIVER_DESC "EHCI generic platform driver"
42 #define EHCI_MAX_CLKS 3
43 +#define EHCI_MAX_RESETS 2
44 #define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv)
45
46 struct ehci_platform_priv {
47 struct clk *clks[EHCI_MAX_CLKS];
48 - struct reset_control *rst;
49 + struct reset_control *resets[EHCI_MAX_RESETS];
50 struct phy **phys;
51 int num_phys;
52 bool reset_on_resume;
53 @@ -149,7 +150,7 @@ static int ehci_platform_probe(struct platform_device *dev)
54 struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
55 struct ehci_platform_priv *priv;
56 struct ehci_hcd *ehci;
57 - int err, irq, phy_num, clk = 0;
58 + int err, irq, phy_num, clk = 0, rst = 0;
59
60 if (usb_disabled())
61 return -ENODEV;
62 @@ -232,18 +233,24 @@ static int ehci_platform_probe(struct platform_device *dev)
63 break;
64 }
65 }
66 - }
67
68 - priv->rst = devm_reset_control_get_optional(&dev->dev, NULL);
69 - if (IS_ERR(priv->rst)) {
70 - err = PTR_ERR(priv->rst);
71 - if (err == -EPROBE_DEFER)
72 - goto err_put_clks;
73 - priv->rst = NULL;
74 - } else {
75 - err = reset_control_deassert(priv->rst);
76 - if (err)
77 - goto err_put_clks;
78 + for (rst = 0; rst < EHCI_MAX_RESETS; rst++) {
79 + priv->resets[rst] =
80 + of_reset_control_get_by_index(dev->dev.of_node,
81 + rst);
82 + if (IS_ERR(priv->resets[rst])) {
83 + err = PTR_ERR(priv->resets[rst]);
84 + if (err == -EPROBE_DEFER)
85 + goto err_reset;
86 + priv->resets[rst] = NULL;
87 + break;
88 + }
89 + err = reset_control_deassert_shared(priv->resets[rst]);
90 + if (err) {
91 + reset_control_put(priv->resets[rst]);
92 + goto err_reset;
93 + }
94 + }
95 }
96
97 if (pdata->big_endian_desc)
98 @@ -300,8 +307,10 @@ static int ehci_platform_probe(struct platform_device *dev)
99 if (pdata->power_off)
100 pdata->power_off(dev);
101 err_reset:
102 - if (priv->rst)
103 - reset_control_assert(priv->rst);
104 + while (--rst >= 0) {
105 + reset_control_assert_shared(priv->resets[rst]);
106 + reset_control_put(priv->resets[rst]);
107 + }
108 err_put_clks:
109 while (--clk >= 0)
110 clk_put(priv->clks[clk]);
111 @@ -319,15 +328,17 @@ static int ehci_platform_remove(struct platform_device *dev)
112 struct usb_hcd *hcd = platform_get_drvdata(dev);
113 struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
114 struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
115 - int clk;
116 + int clk, rst;
117
118 usb_remove_hcd(hcd);
119
120 if (pdata->power_off)
121 pdata->power_off(dev);
122
123 - if (priv->rst)
124 - reset_control_assert(priv->rst);
125 + for (rst = 0; rst < EHCI_MAX_RESETS && priv->resets[rst]; rst++) {
126 + reset_control_assert_shared(priv->resets[rst]);
127 + reset_control_put(priv->resets[rst]);
128 + }
129
130 for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++)
131 clk_put(priv->clks[clk]);