usb: chipidea: otg: add otg file used to access otgsc
[deliverable/linux.git] / drivers / usb / chipidea / core.c
index a5df24c578fc8b65b8945781a0cacb6e6bb33977..2f70080023ae25353a0ac8653b13363b9bc449bb 100644 (file)
 #include <linux/usb/chipidea.h>
 #include <linux/usb/of.h>
 #include <linux/phy.h>
+#include <linux/regulator/consumer.h>
 
 #include "ci.h"
 #include "udc.h"
 #include "bits.h"
 #include "host.h"
 #include "debug.h"
+#include "otg.h"
 
 /* Controller register map */
 static uintptr_t ci_regs_nolpm[] = {
@@ -264,8 +266,6 @@ int hw_device_reset(struct ci_hdrc *ci, u32 mode)
        while (hw_read(ci, OP_USBCMD, USBCMD_RST))
                udelay(10);             /* not RTOS friendly */
 
-       hw_phymode_configure(ci);
-
        if (ci->platdata->notify_event)
                ci->platdata->notify_event(ci,
                        CI_HDRC_CONTROLLER_RESET_EVENT);
@@ -344,6 +344,24 @@ static irqreturn_t ci_irq(int irq, void *data)
        return ret;
 }
 
+static int ci_get_platdata(struct device *dev,
+               struct ci_hdrc_platform_data *platdata)
+{
+       /* Get the vbus regulator */
+       platdata->reg_vbus = devm_regulator_get(dev, "vbus");
+       if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) {
+               return -EPROBE_DEFER;
+       } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) {
+               platdata->reg_vbus = NULL; /* no vbus regualator is needed */
+       } else if (IS_ERR(platdata->reg_vbus)) {
+               dev_err(dev, "Getting regulator error: %ld\n",
+                       PTR_ERR(platdata->reg_vbus));
+               return PTR_ERR(platdata->reg_vbus);
+       }
+
+       return 0;
+}
+
 static DEFINE_IDA(ci_ida);
 
 struct platform_device *ci_hdrc_add_device(struct device *dev,
@@ -353,6 +371,10 @@ struct platform_device *ci_hdrc_add_device(struct device *dev,
        struct platform_device *pdev;
        int id, ret;
 
+       ret = ci_get_platdata(dev, platdata);
+       if (ret)
+               return ERR_PTR(ret);
+
        id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL);
        if (id < 0)
                return ERR_PTR(id);
@@ -406,15 +428,13 @@ static int ci_hdrc_probe(struct platform_device *pdev)
        void __iomem    *base;
        int             ret;
        enum usb_dr_mode dr_mode;
+       struct device_node *of_node = dev->of_node ?: dev->parent->of_node;
 
        if (!dev->platform_data) {
                dev_err(dev, "platform data missing\n");
                return -ENODEV;
        }
 
-       if (!dev->of_node && dev->parent)
-               dev->of_node = dev->parent->of_node;
-
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        base = devm_ioremap_resource(dev, res);
        if (IS_ERR(base))
@@ -455,10 +475,12 @@ static int ci_hdrc_probe(struct platform_device *pdev)
        }
 
        if (!ci->platdata->phy_mode)
-               ci->platdata->phy_mode = of_usb_get_phy_mode(dev->of_node);
+               ci->platdata->phy_mode = of_usb_get_phy_mode(of_node);
+
+       hw_phymode_configure(ci);
 
        if (!ci->platdata->dr_mode)
-               ci->platdata->dr_mode = of_usb_get_dr_mode(dev->of_node);
+               ci->platdata->dr_mode = of_usb_get_dr_mode(of_node);
 
        if (ci->platdata->dr_mode == USB_DR_MODE_UNKNOWN)
                ci->platdata->dr_mode = USB_DR_MODE_OTG;
@@ -497,7 +519,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)
        ret = ci_role_start(ci, ci->role);
        if (ret) {
                dev_err(dev, "can't start %s role\n", ci_role(ci)->name);
-               ret = -ENODEV;
                goto rm_wq;
        }
 
@@ -508,7 +529,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
                goto stop;
 
        if (ci->is_otg)
-               hw_write(ci, OP_OTGSC, OTGSC_IDIE, OTGSC_IDIE);
+               ci_hdrc_otg_init(ci);
 
        ret = dbg_create_files(ci);
        if (!ret)
@@ -548,7 +569,6 @@ static struct platform_driver ci_hdrc_driver = {
 module_platform_driver(ci_hdrc_driver);
 
 MODULE_ALIAS("platform:ci_hdrc");
-MODULE_ALIAS("platform:ci13xxx");
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("David Lopo <dlopo@chipidea.mips.com>");
 MODULE_DESCRIPTION("ChipIdea HDRC Driver");
This page took 0.030916 seconds and 5 git commands to generate.