Skip to content

Commit

Permalink
USB: Add DT probing support to ehci-spear and ohci-spear
Browse files Browse the repository at this point in the history
This patch adds support to configure the SPEAr EHCI & OHCI driver via
device-tree instead of platform_data.

Signed-off-by: Stefan Roese <sr@denx.de>
Acked-by: Viresh Kumar <viresh.kumar@st.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Stefan Roese authored and Greg Kroah-Hartman committed Apr 18, 2012
1 parent 8b4fc8c commit 56fafb9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 12 deletions.
39 changes: 39 additions & 0 deletions Documentation/devicetree/bindings/usb/spear-usb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ST SPEAr SoC USB controllers:
-----------------------------

EHCI:
-----

Required properties:
- compatible: "st,spear600-ehci"
- interrupt-parent: Should be the phandle for the interrupt controller
that services interrupts for this device
- interrupts: Should contain the EHCI interrupt

Example:

ehci@e1800000 {
compatible = "st,spear600-ehci", "usb-ehci";
reg = <0xe1800000 0x1000>;
interrupt-parent = <&vic1>;
interrupts = <27>;
};


OHCI:
-----

Required properties:
- compatible: "st,spear600-ohci"
- interrupt-parent: Should be the phandle for the interrupt controller
that services interrupts for this device
- interrupts: Should contain the OHCI interrupt

Example:

ohci@e1900000 {
compatible = "st,spear600-ohci", "usb-ohci";
reg = <0xe1800000 0x1000>;
interrupt-parent = <&vic1>;
interrupts = <26>;
};
32 changes: 26 additions & 6 deletions drivers/usb/host/ehci-spear.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <linux/clk.h>
#include <linux/jiffies.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm.h>

Expand Down Expand Up @@ -168,19 +169,18 @@ static int ehci_spear_drv_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend,
ehci_spear_drv_resume);

static u64 spear_ehci_dma_mask = DMA_BIT_MASK(32);

static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
{
struct usb_hcd *hcd ;
struct spear_ehci *ehci;
struct resource *res;
struct clk *usbh_clk;
const struct hc_driver *driver = &ehci_spear_hc_driver;
int *pdata = pdev->dev.platform_data;
int irq, retval;
char clk_name[20] = "usbh_clk";

if (pdata == NULL)
return -EFAULT;
static int instance = -1;

if (usb_disabled())
return -ENODEV;
Expand All @@ -191,8 +191,22 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
goto fail_irq_get;
}

if (*pdata >= 0)
sprintf(clk_name, "usbh.%01d_clk", *pdata);
/*
* Right now device-tree probed devices don't get dma_mask set.
* Since shared usb code relies on it, set it here for now.
* Once we have dma capability bindings this can go away.
*/
if (!pdev->dev.dma_mask)
pdev->dev.dma_mask = &spear_ehci_dma_mask;

/*
* Increment the device instance, when probing via device-tree
*/
if (pdev->id < 0)
instance++;
else
instance = pdev->id;
sprintf(clk_name, "usbh.%01d_clk", instance);

usbh_clk = clk_get(NULL, clk_name);
if (IS_ERR(usbh_clk)) {
Expand Down Expand Up @@ -277,6 +291,11 @@ static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
return 0;
}

static struct of_device_id spear_ehci_id_table[] __devinitdata = {
{ .compatible = "st,spear600-ehci", },
{ },
};

static struct platform_driver spear_ehci_hcd_driver = {
.probe = spear_ehci_hcd_drv_probe,
.remove = spear_ehci_hcd_drv_remove,
Expand All @@ -285,6 +304,7 @@ static struct platform_driver spear_ehci_hcd_driver = {
.name = "spear-ehci",
.bus = &platform_bus_type,
.pm = &ehci_spear_pm_ops,
.of_match_table = of_match_ptr(spear_ehci_id_table),
}
};

Expand Down
32 changes: 26 additions & 6 deletions drivers/usb/host/ohci-spear.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/signal.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/of.h>

struct spear_ohci {
struct ohci_hcd ohci;
Expand Down Expand Up @@ -90,6 +91,8 @@ static const struct hc_driver ohci_spear_hc_driver = {
.start_port_reset = ohci_start_port_reset,
};

static u64 spear_ohci_dma_mask = DMA_BIT_MASK(32);

static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
{
const struct hc_driver *driver = &ohci_spear_hc_driver;
Expand All @@ -98,20 +101,31 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
struct spear_ohci *ohci_p;
struct resource *res;
int retval, irq;
int *pdata = pdev->dev.platform_data;
char clk_name[20] = "usbh_clk";

if (pdata == NULL)
return -EFAULT;
static int instance = -1;

irq = platform_get_irq(pdev, 0);
if (irq < 0) {
retval = irq;
goto fail_irq_get;
}

if (*pdata >= 0)
sprintf(clk_name, "usbh.%01d_clk", *pdata);
/*
* Right now device-tree probed devices don't get dma_mask set.
* Since shared usb code relies on it, set it here for now.
* Once we have dma capability bindings this can go away.
*/
if (!pdev->dev.dma_mask)
pdev->dev.dma_mask = &spear_ohci_dma_mask;

/*
* Increment the device instance, when probing via device-tree
*/
if (pdev->id < 0)
instance++;
else
instance = pdev->id;
sprintf(clk_name, "usbh.%01d_clk", instance);

usbh_clk = clk_get(NULL, clk_name);
if (IS_ERR(usbh_clk)) {
Expand Down Expand Up @@ -222,6 +236,11 @@ static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
}
#endif

static struct of_device_id spear_ohci_id_table[] __devinitdata = {
{ .compatible = "st,spear600-ohci", },
{ },
};

/* Driver definition to register with the platform bus */
static struct platform_driver spear_ohci_hcd_driver = {
.probe = spear_ohci_hcd_drv_probe,
Expand All @@ -233,6 +252,7 @@ static struct platform_driver spear_ohci_hcd_driver = {
.driver = {
.owner = THIS_MODULE,
.name = "spear-ohci",
.of_match_table = of_match_ptr(spear_ohci_id_table),
},
};

Expand Down

0 comments on commit 56fafb9

Please sign in to comment.