usb: dwc3: omap: Remove explicit writes to SYSCONFIG register
[cascardo/linux.git] / drivers / usb / dwc3 / dwc3-omap.c
index f31867f..f85ae5e 100644 (file)
 #include <linux/spinlock.h>
 #include <linux/platform_device.h>
 #include <linux/platform_data/dwc3-omap.h>
+#include <linux/pm_runtime.h>
 #include <linux/dma-mapping.h>
 #include <linux/ioport.h>
 #include <linux/io.h>
 #include <linux/of.h>
+#include <linux/of_platform.h>
 
 #include <linux/usb/otg.h>
 #include <linux/usb/nop-usb-xceiv.h>
 
 /* SYSCONFIG REGISTER */
 #define USBOTGSS_SYSCONFIG_DMADISABLE          (1 << 16)
-#define USBOTGSS_SYSCONFIG_STANDBYMODE(x)      ((x) << 4)
-
-#define USBOTGSS_STANDBYMODE_FORCE_STANDBY     0
-#define USBOTGSS_STANDBYMODE_NO_STANDBY                1
-#define USBOTGSS_STANDBYMODE_SMART_STANDBY     2
-#define USBOTGSS_STANDBYMODE_SMART_WAKEUP      3
-
-#define USBOTGSS_STANDBYMODE_MASK              (0x03 << 4)
-
-#define USBOTGSS_SYSCONFIG_IDLEMODE(x)         ((x) << 2)
-
-#define USBOTGSS_IDLEMODE_FORCE_IDLE           0
-#define USBOTGSS_IDLEMODE_NO_IDLE              1
-#define USBOTGSS_IDLEMODE_SMART_IDLE           2
-#define USBOTGSS_IDLEMODE_SMART_WAKEUP         3
-
-#define USBOTGSS_IDLEMODE_MASK                 (0x03 << 2)
 
 /* IRQ_EOI REGISTER */
 #define USBOTGSS_IRQ_EOI_LINE_NUMBER           (1 << 0)
@@ -133,7 +118,6 @@ struct dwc3_omap {
        /* device lock */
        spinlock_t              lock;
 
-       struct platform_device  *dwc3;
        struct platform_device  *usb2_phy;
        struct platform_device  *usb3_phy;
        struct device           *dev;
@@ -262,12 +246,20 @@ static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
        return IRQ_HANDLED;
 }
 
+static int dwc3_omap_remove_core(struct device *dev, void *c)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+
+       platform_device_unregister(pdev);
+
+       return 0;
+}
+
 static int dwc3_omap_probe(struct platform_device *pdev)
 {
        struct dwc3_omap_data   *pdata = pdev->dev.platform_data;
        struct device_node      *node = pdev->dev.of_node;
 
-       struct platform_device  *dwc3;
        struct dwc3_omap        *omap;
        struct resource         *res;
        struct device           *dev = &pdev->dev;
@@ -314,30 +306,26 @@ static int dwc3_omap_probe(struct platform_device *pdev)
                return ret;
        }
 
-       dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
-       if (!dwc3) {
-               dev_err(dev, "couldn't allocate dwc3 device\n");
-               return -ENOMEM;
-       }
-
        context = devm_kzalloc(dev, resource_size(res), GFP_KERNEL);
        if (!context) {
                dev_err(dev, "couldn't allocate dwc3 context memory\n");
-               goto err2;
+               return -ENOMEM;
        }
 
        spin_lock_init(&omap->lock);
-       dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask);
 
-       dwc3->dev.parent = dev;
-       dwc3->dev.dma_mask = dev->dma_mask;
-       dwc3->dev.dma_parms = dev->dma_parms;
        omap->resource_size = resource_size(res);
        omap->context   = context;
        omap->dev       = dev;
        omap->irq       = irq;
        omap->base      = base;
-       omap->dwc3      = dwc3;
+
+       pm_runtime_enable(dev);
+       ret = pm_runtime_get_sync(dev);
+       if (ret < 0) {
+               dev_err(dev, "get_sync failed with err %d\n", ret);
+               return ret;
+       }
 
        reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
 
@@ -368,21 +356,12 @@ static int dwc3_omap_probe(struct platform_device *pdev)
        reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG);
        omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE);
 
-       /* Set No-Idle and No-Standby */
-       reg &= ~(USBOTGSS_STANDBYMODE_MASK
-                       | USBOTGSS_IDLEMODE_MASK);
-
-       reg |= (USBOTGSS_SYSCONFIG_STANDBYMODE(USBOTGSS_STANDBYMODE_NO_STANDBY)
-               | USBOTGSS_SYSCONFIG_IDLEMODE(USBOTGSS_IDLEMODE_NO_IDLE));
-
-       dwc3_omap_writel(omap->base, USBOTGSS_SYSCONFIG, reg);
-
        ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0,
                        "dwc3-omap", omap);
        if (ret) {
                dev_err(dev, "failed to request IRQ #%d --> %d\n",
                                omap->irq, ret);
-               goto err2;
+               return ret;
        }
 
        /* enable all IRQs */
@@ -401,33 +380,28 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 
        dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg);
 
-       ret = platform_device_add_resources(dwc3, pdev->resource,
-                       pdev->num_resources);
-       if (ret) {
-               dev_err(dev, "couldn't add resources to dwc3 device\n");
-               goto err2;
-       }
-
-       ret = platform_device_add(dwc3);
-       if (ret) {
-               dev_err(dev, "failed to register dwc3 device\n");
-               goto err2;
+       if (node) {
+               ret = of_platform_populate(node, NULL, NULL, dev);
+               if (ret) {
+                       dev_err(&pdev->dev,
+                               "failed to add create dwc3 core\n");
+                       return ret;
+               }
        }
 
        return 0;
-
-err2:
-       platform_device_put(dwc3);
-       return ret;
 }
 
 static int dwc3_omap_remove(struct platform_device *pdev)
 {
        struct dwc3_omap        *omap = platform_get_drvdata(pdev);
 
-       platform_device_unregister(omap->dwc3);
        platform_device_unregister(omap->usb2_phy);
        platform_device_unregister(omap->usb3_phy);
+       pm_runtime_put_sync(&pdev->dev);
+       pm_runtime_disable(&pdev->dev);
+       device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
+
        return 0;
 }