usb: ohci-platform: use reset array API

Generic drivers like this need to control arbitrary number 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.masahiro@socionext.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Masahiro Yamada 2017-11-02 01:01:59 +09:00 committed by Greg Kroah-Hartman
parent 8e84f8aa53
commit 20a7f3ad62
1 changed files with 15 additions and 22 deletions

View File

@ -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,17 @@ 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)) {
err = PTR_ERR(priv->resets);
goto err_put_clks;
}
err = reset_control_deassert(priv->resets);
if (err)
goto err_put_clks;
}
if (pdata->big_endian_desc)
@ -279,8 +274,7 @@ err_power:
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 +292,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 +300,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]);