sunxi: initial 4.4 support
[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 diff --git a/Documentation/devicetree/bindings/usb/usb-ohci.txt b/Documentation/devicetree/bindings/usb/usb-ohci.txt
23 index 19233b7..9df4569 100644
24 --- a/Documentation/devicetree/bindings/usb/usb-ohci.txt
25 +++ b/Documentation/devicetree/bindings/usb/usb-ohci.txt
26 @@ -14,7 +14,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:
34  
35 diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
36 index c2669f18..7d8bbc4 100644
37 --- a/drivers/usb/host/ohci-platform.c
38 +++ b/drivers/usb/host/ohci-platform.c
39 @@ -33,11 +33,12 @@
40  
41  #define DRIVER_DESC "OHCI generic platform driver"
42  #define OHCI_MAX_CLKS 3
43 +#define OHCI_MAX_RESETS 2
44  #define hcd_to_ohci_priv(h) ((struct ohci_platform_priv *)hcd_to_ohci(h)->priv)
45  
46  struct ohci_platform_priv {
47         struct clk *clks[OHCI_MAX_CLKS];
48 -       struct reset_control *rst;
49 +       struct reset_control *resets[OHCI_MAX_RESETS];
50         struct phy **phys;
51         int num_phys;
52  };
53 @@ -117,7 +118,7 @@ static int ohci_platform_probe(struct platform_device *dev)
54         struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
55         struct ohci_platform_priv *priv;
56         struct ohci_hcd *ohci;
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 @@ -195,19 +196,23 @@ static int ohci_platform_probe(struct platform_device *dev)
63                                 break;
64                         }
65                 }
66 -
67 -       }
68 -
69 -       priv->rst = devm_reset_control_get_optional(&dev->dev, NULL);
70 -       if (IS_ERR(priv->rst)) {
71 -               err = PTR_ERR(priv->rst);
72 -               if (err == -EPROBE_DEFER)
73 -                       goto err_put_clks;
74 -               priv->rst = NULL;
75 -       } else {
76 -               err = reset_control_deassert(priv->rst);
77 -               if (err)
78 -                       goto err_put_clks;
79 +               for (rst = 0; rst < OHCI_MAX_RESETS; rst++) {
80 +                       priv->resets[rst] =
81 +                               of_reset_control_get_by_index(dev->dev.of_node,
82 +                                                             rst);
83 +                       if (IS_ERR(priv->resets[rst])) {
84 +                               err = PTR_ERR(priv->resets[rst]);
85 +                               if (err == -EPROBE_DEFER)
86 +                                       goto err_reset;
87 +                               priv->resets[rst] = NULL;
88 +                               break;
89 +                       }
90 +                       err = reset_control_deassert_shared(priv->resets[rst]);
91 +                       if (err) {
92 +                               reset_control_put(priv->resets[rst]);
93 +                               goto err_reset;
94 +                       }
95 +               }
96         }
97  
98         if (pdata->big_endian_desc)
99 @@ -265,8 +270,10 @@ static int ohci_platform_probe(struct platform_device *dev)
100         if (pdata->power_off)
101                 pdata->power_off(dev);
102  err_reset:
103 -       if (priv->rst)
104 -               reset_control_assert(priv->rst);
105 +       while (--rst >= 0) {
106 +               reset_control_assert_shared(priv->resets[rst]);
107 +               reset_control_put(priv->resets[rst]);
108 +       }
109  err_put_clks:
110         while (--clk >= 0)
111                 clk_put(priv->clks[clk]);
112 @@ -284,15 +291,17 @@ static int ohci_platform_remove(struct platform_device *dev)
113         struct usb_hcd *hcd = platform_get_drvdata(dev);
114         struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
115         struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
116 -       int clk;
117 +       int clk, rst;
118  
119         usb_remove_hcd(hcd);
120  
121         if (pdata->power_off)
122                 pdata->power_off(dev);
123  
124 -       if (priv->rst)
125 -               reset_control_assert(priv->rst);
126 +       for (rst = 0; rst < OHCI_MAX_RESETS && priv->resets[rst]; rst++) {
127 +               reset_control_assert_shared(priv->resets[rst]);
128 +               reset_control_put(priv->resets[rst]);
129 +       }
130  
131         for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++)
132                 clk_put(priv->clks[clk]);