Move core device initialization to a central location in order to share
it with the device mode implementation.

Signed-off-by: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
---
 drivers/usb/host/Makefile       |  2 +-
 drivers/usb/host/isp1760-core.c | 65 +++++++++++++++++++++++++++++++++++++++++
 drivers/usb/host/isp1760-core.h | 33 +++++++++++++++++++++
 drivers/usb/host/isp1760-hcd.c  | 42 +++++++-------------------
 drivers/usb/host/isp1760-hcd.h  |  8 ++---
 drivers/usb/host/isp1760-if.c   |  2 +-
 6 files changed, 114 insertions(+), 38 deletions(-)
 create mode 100644 drivers/usb/host/isp1760-core.c
 create mode 100644 drivers/usb/host/isp1760-core.h

diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index d6216a4..4dea9b1 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -5,7 +5,7 @@
 # tell define_trace.h where to find the xhci trace header
 CFLAGS_xhci-trace.o := -I$(src)
 
-isp1760-y := isp1760-hcd.o isp1760-if.o
+isp1760-y := isp1760-core.o isp1760-hcd.o isp1760-if.o
 
 fhci-y := fhci-hcd.o fhci-hub.o fhci-q.o
 fhci-y += fhci-mem.o fhci-tds.o fhci-sched.o
diff --git a/drivers/usb/host/isp1760-core.c b/drivers/usb/host/isp1760-core.c
new file mode 100644
index 0000000..d38efa0
--- /dev/null
+++ b/drivers/usb/host/isp1760-core.c
@@ -0,0 +1,65 @@
+/*
+ * Driver for the NXP ISP1760 chip
+ *
+ * Copyright 2014 Laurent Pinchart
+ * Copyright 2007 Sebastian Siewior
+ *
+ * Contacts:
+ *     Sebastian Siewior <bige...@linutronix.de>
+ *     Laurent Pinchart <laurent.pinch...@ideasonboard.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+#include <linux/gpio.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+
+#include "isp1760-core.h"
+#include "isp1760-hcd.h"
+
+int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
+                    struct device *dev, unsigned int devflags)
+{
+       struct isp1760_device *isp;
+       int ret;
+
+       if (usb_disabled())
+               return -ENODEV;
+
+       /* prevent usb-core allocating DMA pages */
+       dev->dma_mask = NULL;
+
+       isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL);
+       if (!isp)
+               return -ENOMEM;
+
+       isp->regs = devm_ioremap_resource(dev, mem);
+       if (IS_ERR(isp->regs))
+               return PTR_ERR(isp->regs);
+
+       ret = isp1760_hcd_register(&isp->hcd, isp->regs, mem, irq, irqflags,
+                                  dev, devflags);
+       if (ret < 0)
+               return ret;
+
+       dev_set_drvdata(dev, isp);
+
+       return 0;
+}
+
+void isp1760_unregister(struct device *dev)
+{
+       struct isp1760_device *isp = dev_get_drvdata(dev);
+
+       isp1760_hcd_unregister(&isp->hcd);
+}
+
+MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP");
+MODULE_AUTHOR("Sebastian Siewior <bige...@linuxtronix.de>");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/isp1760-core.h b/drivers/usb/host/isp1760-core.h
new file mode 100644
index 0000000..0caeb11
--- /dev/null
+++ b/drivers/usb/host/isp1760-core.h
@@ -0,0 +1,33 @@
+/*
+ * Driver for the NXP ISP1760 chip
+ *
+ * Copyright 2014 Laurent Pinchart
+ * Copyright 2007 Sebastian Siewior
+ *
+ * Contacts:
+ *     Sebastian Siewior <bige...@linutronix.de>
+ *     Laurent Pinchart <laurent.pinch...@ideasonboard.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+#ifndef _ISP1760_CORE_H_
+#define _ISP1760_CORE_H_
+
+#include <linux/ioport.h>
+
+#include "isp1760-hcd.h"
+
+struct isp1760_device {
+       void __iomem *regs;
+
+       struct isp1760_hcd hcd;
+};
+
+int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
+                    struct device *dev, unsigned int devflags);
+void isp1760_unregister(struct device *dev);
+
+#endif
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index 50434cc..0cf620b 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -2232,30 +2232,20 @@ void isp1760_deinit_kmem_cache(void)
        kmem_cache_destroy(urb_listitem_cachep);
 }
 
-int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
-                    struct device *dev, unsigned int devflags)
+int isp1760_hcd_register(struct isp1760_hcd *priv, void __iomem *regs,
+                        struct resource *mem, int irq, unsigned long irqflags,
+                        struct device *dev, unsigned int devflags)
 {
-       struct usb_hcd *hcd = NULL;
-       struct isp1760_hcd *priv;
+       struct usb_hcd *hcd;
        int ret;
 
-       if (usb_disabled())
-               return -ENODEV;
-
-       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-       if (!priv)
-               return -ENOMEM;
-
-       /* prevent usb-core allocating DMA pages */
-       dev->dma_mask = NULL;
-
        hcd = usb_create_hcd(&isp1760_hc_driver, dev, dev_name(dev));
        if (!hcd)
                return -ENOMEM;
 
-       priv->hcd = hcd;
        *(struct isp1760_hcd **)hcd->hcd_priv = priv;
 
+       priv->hcd = hcd;
        priv->devflags = devflags;
 
        priv->rst_gpio = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH);
@@ -2265,22 +2255,17 @@ int isp1760_register(struct resource *mem, int irq, 
unsigned long irqflags,
        }
 
        init_memory(priv);
-       hcd->regs = devm_ioremap_resource(dev, mem);
-       if (IS_ERR(hcd->regs)) {
-               ret = PTR_ERR(hcd->regs);
-               goto error;
-       }
 
        hcd->irq = irq;
+       hcd->regs = regs;
        hcd->rsrc_start = mem->start;
        hcd->rsrc_len = resource_size(mem);
 
        ret = usb_add_hcd(hcd, irq, irqflags);
        if (ret)
                goto error;
-       device_wakeup_enable(hcd->self.controller);
 
-       dev_set_drvdata(dev, priv);
+       device_wakeup_enable(hcd->self.controller);
 
        return 0;
 
@@ -2289,15 +2274,8 @@ error:
        return ret;
 }
 
-void isp1760_unregister(struct device *dev)
+void isp1760_hcd_unregister(struct isp1760_hcd *priv)
 {
-       struct isp1760_hcd *priv = dev_get_drvdata(dev);
-       struct usb_hcd *hcd = priv->hcd;
-
-       usb_remove_hcd(hcd);
-       usb_put_hcd(hcd);
+       usb_remove_hcd(priv->hcd);
+       usb_put_hcd(priv->hcd);
 }
-
-MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP");
-MODULE_AUTHOR("Sebastian Siewior <bige...@linuxtronix.de>");
-MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h
index 44486c8..dcd2232 100644
--- a/drivers/usb/host/isp1760-hcd.h
+++ b/drivers/usb/host/isp1760-hcd.h
@@ -84,10 +84,10 @@ struct isp1760_hcd {
        struct gpio_desc        *rst_gpio;
 };
 
-/* exports for if */
-int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
-                    struct device *dev, unsigned int devflags);
-void isp1760_unregister(struct device *dev);
+int isp1760_hcd_register(struct isp1760_hcd *priv, void __iomem *regs,
+                        struct resource *mem, int irq, unsigned long irqflags,
+                        struct device *dev, unsigned int devflags);
+void isp1760_hcd_unregister(struct isp1760_hcd *priv);
 
 int isp1760_init_kmem_once(void);
 void isp1760_deinit_kmem_cache(void);
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index b1591c6c..f2a3990 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -18,7 +18,7 @@
 #include <linux/usb/isp1760.h>
 #include <linux/usb/hcd.h>
 
-#include "isp1760-hcd.h"
+#include "isp1760-core.h"
 #include "isp1760-regs.h"
 
 #ifdef CONFIG_PCI
-- 
2.0.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to