Commit d233c196 authored by Vivek Gautam's avatar Vivek Gautam Committed by Felipe Balbi

USB: ehci-s5p: Add phy driver support

Adding the phy driver to ehci-s5p. Keeping the platform data
for continuing the smooth operation for boards which still uses it
Signed-off-by: default avatarVivek Gautam <gautam.vivek@samsung.com>
Acked-by: default avatarJingoo Han <jg1.han@samsung.com>
Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Acked-by: default avatarKukjin Kim <kgene.kim@samsung.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 8c1b3e16
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
#include <linux/platform_data/usb-ehci-s5p.h> #include <linux/platform_data/usb-ehci-s5p.h>
#include <linux/usb/phy.h>
#include <linux/usb/samsung_usb_phy.h> #include <linux/usb/samsung_usb_phy.h>
#include <plat/usb-phy.h> #include <plat/usb-phy.h>
...@@ -33,6 +34,9 @@ struct s5p_ehci_hcd { ...@@ -33,6 +34,9 @@ struct s5p_ehci_hcd {
struct device *dev; struct device *dev;
struct usb_hcd *hcd; struct usb_hcd *hcd;
struct clk *clk; struct clk *clk;
struct usb_phy *phy;
struct usb_otg *otg;
struct s5p_ehci_platdata *pdata;
}; };
static const struct hc_driver s5p_ehci_hc_driver = { static const struct hc_driver s5p_ehci_hc_driver = {
...@@ -66,6 +70,26 @@ static const struct hc_driver s5p_ehci_hc_driver = { ...@@ -66,6 +70,26 @@ static const struct hc_driver s5p_ehci_hc_driver = {
.clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
}; };
static void s5p_ehci_phy_enable(struct s5p_ehci_hcd *s5p_ehci)
{
struct platform_device *pdev = to_platform_device(s5p_ehci->dev);
if (s5p_ehci->phy)
usb_phy_init(s5p_ehci->phy);
else if (s5p_ehci->pdata->phy_init)
s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
}
static void s5p_ehci_phy_disable(struct s5p_ehci_hcd *s5p_ehci)
{
struct platform_device *pdev = to_platform_device(s5p_ehci->dev);
if (s5p_ehci->phy)
usb_phy_shutdown(s5p_ehci->phy);
else if (s5p_ehci->pdata->phy_exit)
s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
}
static void s5p_setup_vbus_gpio(struct platform_device *pdev) static void s5p_setup_vbus_gpio(struct platform_device *pdev)
{ {
int err; int err;
...@@ -88,20 +112,15 @@ static u64 ehci_s5p_dma_mask = DMA_BIT_MASK(32); ...@@ -88,20 +112,15 @@ static u64 ehci_s5p_dma_mask = DMA_BIT_MASK(32);
static int s5p_ehci_probe(struct platform_device *pdev) static int s5p_ehci_probe(struct platform_device *pdev)
{ {
struct s5p_ehci_platdata *pdata; struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
struct s5p_ehci_hcd *s5p_ehci; struct s5p_ehci_hcd *s5p_ehci;
struct usb_hcd *hcd; struct usb_hcd *hcd;
struct ehci_hcd *ehci; struct ehci_hcd *ehci;
struct resource *res; struct resource *res;
struct usb_phy *phy;
int irq; int irq;
int err; int err;
pdata = pdev->dev.platform_data;
if (!pdata) {
dev_err(&pdev->dev, "No platform data defined\n");
return -EINVAL;
}
/* /*
* Right now device-tree probed devices don't get dma_mask set. * Right now device-tree probed devices don't get dma_mask set.
* Since shared usb code relies on it, set it here for now. * Since shared usb code relies on it, set it here for now.
...@@ -119,6 +138,20 @@ static int s5p_ehci_probe(struct platform_device *pdev) ...@@ -119,6 +138,20 @@ static int s5p_ehci_probe(struct platform_device *pdev)
if (!s5p_ehci) if (!s5p_ehci)
return -ENOMEM; return -ENOMEM;
phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
if (IS_ERR_OR_NULL(phy)) {
/* Fallback to pdata */
if (!pdata) {
dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
return -EPROBE_DEFER;
} else {
s5p_ehci->pdata = pdata;
}
} else {
s5p_ehci->phy = phy;
s5p_ehci->otg = phy->otg;
}
s5p_ehci->dev = &pdev->dev; s5p_ehci->dev = &pdev->dev;
hcd = usb_create_hcd(&s5p_ehci_hc_driver, &pdev->dev, hcd = usb_create_hcd(&s5p_ehci_hc_driver, &pdev->dev,
...@@ -164,8 +197,10 @@ static int s5p_ehci_probe(struct platform_device *pdev) ...@@ -164,8 +197,10 @@ static int s5p_ehci_probe(struct platform_device *pdev)
goto fail_io; goto fail_io;
} }
if (pdata->phy_init) if (s5p_ehci->otg)
pdata->phy_init(pdev, USB_PHY_TYPE_HOST); s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self);
s5p_ehci_phy_enable(s5p_ehci);
ehci = hcd_to_ehci(hcd); ehci = hcd_to_ehci(hcd);
ehci->caps = hcd->regs; ehci->caps = hcd->regs;
...@@ -176,13 +211,15 @@ static int s5p_ehci_probe(struct platform_device *pdev) ...@@ -176,13 +211,15 @@ static int s5p_ehci_probe(struct platform_device *pdev)
err = usb_add_hcd(hcd, irq, IRQF_SHARED); err = usb_add_hcd(hcd, irq, IRQF_SHARED);
if (err) { if (err) {
dev_err(&pdev->dev, "Failed to add USB HCD\n"); dev_err(&pdev->dev, "Failed to add USB HCD\n");
goto fail_io; goto fail_add_hcd;
} }
platform_set_drvdata(pdev, s5p_ehci); platform_set_drvdata(pdev, s5p_ehci);
return 0; return 0;
fail_add_hcd:
s5p_ehci_phy_disable(s5p_ehci);
fail_io: fail_io:
clk_disable_unprepare(s5p_ehci->clk); clk_disable_unprepare(s5p_ehci->clk);
fail_clk: fail_clk:
...@@ -192,14 +229,15 @@ static int s5p_ehci_probe(struct platform_device *pdev) ...@@ -192,14 +229,15 @@ static int s5p_ehci_probe(struct platform_device *pdev)
static int s5p_ehci_remove(struct platform_device *pdev) static int s5p_ehci_remove(struct platform_device *pdev)
{ {
struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev);
struct usb_hcd *hcd = s5p_ehci->hcd; struct usb_hcd *hcd = s5p_ehci->hcd;
usb_remove_hcd(hcd); usb_remove_hcd(hcd);
if (pdata && pdata->phy_exit) if (s5p_ehci->otg)
pdata->phy_exit(pdev, USB_PHY_TYPE_HOST); s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self);
s5p_ehci_phy_disable(s5p_ehci);
clk_disable_unprepare(s5p_ehci->clk); clk_disable_unprepare(s5p_ehci->clk);
...@@ -223,14 +261,14 @@ static int s5p_ehci_suspend(struct device *dev) ...@@ -223,14 +261,14 @@ static int s5p_ehci_suspend(struct device *dev)
struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev); struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
struct usb_hcd *hcd = s5p_ehci->hcd; struct usb_hcd *hcd = s5p_ehci->hcd;
bool do_wakeup = device_may_wakeup(dev); bool do_wakeup = device_may_wakeup(dev);
struct platform_device *pdev = to_platform_device(dev);
struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
int rc; int rc;
rc = ehci_suspend(hcd, do_wakeup); rc = ehci_suspend(hcd, do_wakeup);
if (pdata && pdata->phy_exit) if (s5p_ehci->otg)
pdata->phy_exit(pdev, USB_PHY_TYPE_HOST); s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self);
s5p_ehci_phy_disable(s5p_ehci);
clk_disable_unprepare(s5p_ehci->clk); clk_disable_unprepare(s5p_ehci->clk);
...@@ -241,13 +279,13 @@ static int s5p_ehci_resume(struct device *dev) ...@@ -241,13 +279,13 @@ static int s5p_ehci_resume(struct device *dev)
{ {
struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev); struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
struct usb_hcd *hcd = s5p_ehci->hcd; struct usb_hcd *hcd = s5p_ehci->hcd;
struct platform_device *pdev = to_platform_device(dev);
struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
clk_prepare_enable(s5p_ehci->clk); clk_prepare_enable(s5p_ehci->clk);
if (pdata && pdata->phy_init) if (s5p_ehci->otg)
pdata->phy_init(pdev, USB_PHY_TYPE_HOST); s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self);
s5p_ehci_phy_enable(s5p_ehci);
/* DMA burst Enable */ /* DMA burst Enable */
writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment