Generic drivers like this need to control arbitrary numbers of reset
lines.  Instead of hard-coding the maximum number of resets, use the
reset array API.  It can manage a bunch of resets behind the scene.

Signed-off-by: Masahiro Yamada <yamada.masah...@socionext.com>
---

 drivers/usb/host/ohci-platform.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
index 61fe2b9..cb7e190 100644
--- a/drivers/usb/host/ohci-platform.c
+++ b/drivers/usb/host/ohci-platform.c
@@ -34,12 +34,11 @@
 
 #define DRIVER_DESC "OHCI generic platform driver"
 #define OHCI_MAX_CLKS 3
-#define OHCI_MAX_RESETS 2
 #define hcd_to_ohci_priv(h) ((struct ohci_platform_priv *)hcd_to_ohci(h)->priv)
 
 struct ohci_platform_priv {
        struct clk *clks[OHCI_MAX_CLKS];
-       struct reset_control *resets[OHCI_MAX_RESETS];
+       struct reset_control *resets;
        struct phy **phys;
        int num_phys;
 };
@@ -119,7 +118,7 @@ static int ohci_platform_probe(struct platform_device *dev)
        struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
        struct ohci_platform_priv *priv;
        struct ohci_hcd *ohci;
-       int err, irq, phy_num, clk = 0, rst = 0;
+       int err, irq, phy_num, clk = 0;
 
        if (usb_disabled())
                return -ENODEV;
@@ -204,21 +203,15 @@ static int ohci_platform_probe(struct platform_device 
*dev)
                                break;
                        }
                }
-               for (rst = 0; rst < OHCI_MAX_RESETS; rst++) {
-                       priv->resets[rst] =
-                               devm_reset_control_get_shared_by_index(
-                                                               &dev->dev, rst);
-                       if (IS_ERR(priv->resets[rst])) {
-                               err = PTR_ERR(priv->resets[rst]);
-                               if (err == -EPROBE_DEFER)
-                                       goto err_reset;
-                               priv->resets[rst] = NULL;
-                               break;
-                       }
-                       err = reset_control_deassert(priv->resets[rst]);
-                       if (err)
-                               goto err_reset;
-               }
+
+               priv->resets = devm_reset_control_array_get_optional_shared(
+                                                               &dev->dev);
+               if (IS_ERR(priv->resets))
+                       return PTR_ERR(priv->resets);
+
+               err = reset_control_deassert(priv->resets);
+               if (err)
+                       goto err_put_clks;
        }
 
        if (pdata->big_endian_desc)
@@ -279,8 +272,7 @@ static int ohci_platform_probe(struct platform_device *dev)
                pdata->power_off(dev);
 err_reset:
        pm_runtime_disable(&dev->dev);
-       while (--rst >= 0)
-               reset_control_assert(priv->resets[rst]);
+       reset_control_assert(priv->resets);
 err_put_clks:
        while (--clk >= 0)
                clk_put(priv->clks[clk]);
@@ -298,7 +290,7 @@ static int ohci_platform_remove(struct platform_device *dev)
        struct usb_hcd *hcd = platform_get_drvdata(dev);
        struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
        struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
-       int clk, rst;
+       int clk;
 
        pm_runtime_get_sync(&dev->dev);
        usb_remove_hcd(hcd);
@@ -306,8 +298,7 @@ static int ohci_platform_remove(struct platform_device *dev)
        if (pdata->power_off)
                pdata->power_off(dev);
 
-       for (rst = 0; rst < OHCI_MAX_RESETS && priv->resets[rst]; rst++)
-               reset_control_assert(priv->resets[rst]);
+       reset_control_assert(priv->resets);
 
        for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++)
                clk_put(priv->clks[clk]);
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to