sunxi: backport sunxi-mmc controller driver from 4.13
[openwrt/openwrt.git] / target / linux / sunxi / patches-4.4 / 145-usb-ohci-plat-support-multiple-reset-ctrllines.patch
1 From 5f0c864c1f207dba1db587747a58ec6b362dadf8 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Sun, 29 Nov 2015 18:44:14 +0100
4 Subject: [PATCH] ohci-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: Hans de Goede <hdegoede@redhat.com>
13 ---
14 Changes in v2:
15 -New patch in v2 of this patch-set, to complement the identical patch for
16 the ehci-platform code
17 ---
18 Documentation/devicetree/bindings/usb/usb-ohci.txt | 2 +-
19 drivers/usb/host/ohci-platform.c | 49 +++++++++++++---------
20 2 files changed, 30 insertions(+), 21 deletions(-)
21
22 --- a/Documentation/devicetree/bindings/usb/usb-ohci.txt
23 +++ b/Documentation/devicetree/bindings/usb/usb-ohci.txt
24 @@ -14,7 +14,7 @@ Optional properties:
25 - clocks : a list of phandle + clock specifier pairs
26 - phys : phandle + phy specifier pair
27 - phy-names : "usb"
28 -- resets : phandle + reset specifier pair
29 +- resets : a list of phandle + reset specifier pairs
30
31 Example:
32
33 --- a/drivers/usb/host/ohci-platform.c
34 +++ b/drivers/usb/host/ohci-platform.c
35 @@ -33,11 +33,12 @@
36
37 #define DRIVER_DESC "OHCI generic platform driver"
38 #define OHCI_MAX_CLKS 3
39 +#define OHCI_MAX_RESETS 2
40 #define hcd_to_ohci_priv(h) ((struct ohci_platform_priv *)hcd_to_ohci(h)->priv)
41
42 struct ohci_platform_priv {
43 struct clk *clks[OHCI_MAX_CLKS];
44 - struct reset_control *rst;
45 + struct reset_control *resets[OHCI_MAX_RESETS];
46 struct phy **phys;
47 int num_phys;
48 };
49 @@ -117,7 +118,7 @@ static int ohci_platform_probe(struct pl
50 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
51 struct ohci_platform_priv *priv;
52 struct ohci_hcd *ohci;
53 - int err, irq, phy_num, clk = 0;
54 + int err, irq, phy_num, clk = 0, rst = 0;
55
56 if (usb_disabled())
57 return -ENODEV;
58 @@ -195,19 +196,23 @@ static int ohci_platform_probe(struct pl
59 break;
60 }
61 }
62 -
63 - }
64 -
65 - priv->rst = devm_reset_control_get_optional(&dev->dev, NULL);
66 - if (IS_ERR(priv->rst)) {
67 - err = PTR_ERR(priv->rst);
68 - if (err == -EPROBE_DEFER)
69 - goto err_put_clks;
70 - priv->rst = NULL;
71 - } else {
72 - err = reset_control_deassert(priv->rst);
73 - if (err)
74 - goto err_put_clks;
75 + for (rst = 0; rst < OHCI_MAX_RESETS; rst++) {
76 + priv->resets[rst] =
77 + of_reset_control_get_by_index(dev->dev.of_node,
78 + rst);
79 + if (IS_ERR(priv->resets[rst])) {
80 + err = PTR_ERR(priv->resets[rst]);
81 + if (err == -EPROBE_DEFER)
82 + goto err_reset;
83 + priv->resets[rst] = NULL;
84 + break;
85 + }
86 + err = reset_control_deassert_shared(priv->resets[rst]);
87 + if (err) {
88 + reset_control_put(priv->resets[rst]);
89 + goto err_reset;
90 + }
91 + }
92 }
93
94 if (pdata->big_endian_desc)
95 @@ -265,8 +270,10 @@ err_power:
96 if (pdata->power_off)
97 pdata->power_off(dev);
98 err_reset:
99 - if (priv->rst)
100 - reset_control_assert(priv->rst);
101 + while (--rst >= 0) {
102 + reset_control_assert_shared(priv->resets[rst]);
103 + reset_control_put(priv->resets[rst]);
104 + }
105 err_put_clks:
106 while (--clk >= 0)
107 clk_put(priv->clks[clk]);
108 @@ -284,15 +291,17 @@ static int ohci_platform_remove(struct p
109 struct usb_hcd *hcd = platform_get_drvdata(dev);
110 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
111 struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
112 - int clk;
113 + int clk, rst;
114
115 usb_remove_hcd(hcd);
116
117 if (pdata->power_off)
118 pdata->power_off(dev);
119
120 - if (priv->rst)
121 - reset_control_assert(priv->rst);
122 + for (rst = 0; rst < OHCI_MAX_RESETS && priv->resets[rst]; rst++) {
123 + reset_control_assert_shared(priv->resets[rst]);
124 + reset_control_put(priv->resets[rst]);
125 + }
126
127 for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++)
128 clk_put(priv->clks[clk]);