usb: ohci-platform: add support for multiple phys per controller

Added support for cases where one controller is connected
to multiple phys

Signed-off-by: Arun Ramamurthy <arunrama@broadcom.com>
Reviewed-by: Ray Jui <rjui@broadcom.com>
Reviewed-by: Scott Branden <sbranden@broadcom.com>
Tested-by: Scott Branden <sbranden@broadcom.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Arun Ramamurthy 2015-01-19 16:05:30 -08:00 committed by Greg Kroah-Hartman
parent 6d2a566329
commit 85cd690d7e
1 changed files with 60 additions and 22 deletions

View File

@ -38,7 +38,8 @@
struct ohci_platform_priv { struct ohci_platform_priv {
struct clk *clks[OHCI_MAX_CLKS]; struct clk *clks[OHCI_MAX_CLKS];
struct reset_control *rst; struct reset_control *rst;
struct phy *phy; struct phy **phys;
int num_phys;
}; };
static const char hcd_name[] = "ohci-platform"; static const char hcd_name[] = "ohci-platform";
@ -47,7 +48,7 @@ static int ohci_platform_power_on(struct platform_device *dev)
{ {
struct usb_hcd *hcd = platform_get_drvdata(dev); struct usb_hcd *hcd = platform_get_drvdata(dev);
struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd); struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
int clk, ret; int clk, ret, phy_num;
for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) { for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) {
ret = clk_prepare_enable(priv->clks[clk]); ret = clk_prepare_enable(priv->clks[clk]);
@ -55,20 +56,28 @@ static int ohci_platform_power_on(struct platform_device *dev)
goto err_disable_clks; goto err_disable_clks;
} }
if (priv->phy) { for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
ret = phy_init(priv->phy); if (priv->phys[phy_num]) {
if (ret) ret = phy_init(priv->phys[phy_num]);
goto err_disable_clks;
ret = phy_power_on(priv->phy);
if (ret) if (ret)
goto err_exit_phy; goto err_exit_phy;
ret = phy_power_on(priv->phys[phy_num]);
if (ret) {
phy_exit(priv->phys[phy_num]);
goto err_exit_phy;
}
}
} }
return 0; return 0;
err_exit_phy: err_exit_phy:
phy_exit(priv->phy); while (--phy_num >= 0) {
if (priv->phys[phy_num]) {
phy_power_off(priv->phys[phy_num]);
phy_exit(priv->phys[phy_num]);
}
}
err_disable_clks: err_disable_clks:
while (--clk >= 0) while (--clk >= 0)
clk_disable_unprepare(priv->clks[clk]); clk_disable_unprepare(priv->clks[clk]);
@ -80,11 +89,13 @@ static void ohci_platform_power_off(struct platform_device *dev)
{ {
struct usb_hcd *hcd = platform_get_drvdata(dev); struct usb_hcd *hcd = platform_get_drvdata(dev);
struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd); struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
int clk; int clk, phy_num;
if (priv->phy) { for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
phy_power_off(priv->phy); if (priv->phys[phy_num]) {
phy_exit(priv->phy); phy_power_off(priv->phys[phy_num]);
phy_exit(priv->phys[phy_num]);
}
} }
for (clk = OHCI_MAX_CLKS - 1; clk >= 0; clk--) for (clk = OHCI_MAX_CLKS - 1; clk >= 0; clk--)
@ -112,7 +123,8 @@ static int ohci_platform_probe(struct platform_device *dev)
struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev); struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
struct ohci_platform_priv *priv; struct ohci_platform_priv *priv;
struct ohci_hcd *ohci; struct ohci_hcd *ohci;
int err, irq, clk = 0; const char *phy_name;
int err, irq, phy_num, clk = 0;
if (usb_disabled()) if (usb_disabled())
return -ENODEV; return -ENODEV;
@ -160,12 +172,38 @@ static int ohci_platform_probe(struct platform_device *dev)
of_property_read_u32(dev->dev.of_node, "num-ports", of_property_read_u32(dev->dev.of_node, "num-ports",
&ohci->num_ports); &ohci->num_ports);
priv->phy = devm_phy_get(&dev->dev, "usb"); priv->num_phys = of_count_phandle_with_args(dev->dev.of_node,
if (IS_ERR(priv->phy)) { "phys", "#phy-cells");
err = PTR_ERR(priv->phy); priv->num_phys = priv->num_phys > 0 ? priv->num_phys : 1;
if (err == -EPROBE_DEFER)
priv->phys = devm_kcalloc(&dev->dev, priv->num_phys,
sizeof(struct phy *), GFP_KERNEL);
if (!priv->phys)
return -ENOMEM;
for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
err = of_property_read_string_index(
dev->dev.of_node,
"phy-names", phy_num,
&phy_name);
if (err < 0) {
if (priv->num_phys > 1) {
dev_err(&dev->dev, "phy-names not provided");
goto err_put_hcd; goto err_put_hcd;
priv->phy = NULL; } else
phy_name = "usb";
}
priv->phys[phy_num] = devm_phy_get(&dev->dev,
phy_name);
if (IS_ERR(priv->phys[phy_num])) {
err = PTR_ERR(priv->phys[phy_num]);
if ((priv->num_phys > 1) ||
(err == -EPROBE_DEFER))
goto err_put_hcd;
priv->phys[phy_num] = NULL;
}
} }
for (clk = 0; clk < OHCI_MAX_CLKS; clk++) { for (clk = 0; clk < OHCI_MAX_CLKS; clk++) {