[PATCH 1/1] usb: chipidea: imx: include usbmisc_imx.c in ci_hdrc_imx.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At former design, both ci_hdrc_imx and usbmisc_imx are individual
module, ci_hdrc_imx is glue layer for imx usb driver. usbmisc_imx
handles non-core registers which has different register layout
for imx SoC serials, it usually supplies interface for wakeup
setting, PHY setting, etc.

usbmisc_imx uses symbols from ci_hdrc_imx, So, when we combile both
of drivers as loadable module, usbmisc is needed to be unload first.
However at ci_hdrc_imx, it needs to call usbmisc_imx's interface
at its removal function once we enable wakeup/runtime pm function, so
keeping two drivers can't work well at loadable module use case.

To fix loadable module use case, we need to build usbmisc_imx into
ci_hdrc_imx. The usbmisc_imx still handles misc setting for controllers,
and will be included at ci_hdrc_imx.

There is a short discussion for it:
http://marc.info/?l=linux-usb&m=136861599423172&w=2

Besides, we update dts and binding doc for at this commit

Signed-off-by: Peter Chen <peter.chen@xxxxxxxxxxxxx>
---
 .../devicetree/bindings/usb/ci13xxx-imx.txt        |   10 +-
 .../devicetree/bindings/usb/usbmisc-imx.txt        |   14 --
 arch/arm/boot/dts/imx23.dtsi                       |    1 +
 arch/arm/boot/dts/imx25.dtsi                       |   14 +-
 arch/arm/boot/dts/imx28.dtsi                       |    2 +
 arch/arm/boot/dts/imx51.dtsi                       |   13 +
 arch/arm/boot/dts/imx53.dtsi                       |   13 +
 arch/arm/boot/dts/imx6qdl.dtsi                     |   20 +-
 drivers/usb/chipidea/Makefile                      |    2 +-
 drivers/usb/chipidea/ci_hdrc_imx.c                 |  125 ++++++-----
 drivers/usb/chipidea/ci_hdrc_imx.h                 |   32 ++--
 drivers/usb/chipidea/usbmisc_imx.c                 |  237 +++++---------------
 12 files changed, 192 insertions(+), 291 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/usb/usbmisc-imx.txt

diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
index b4b5b79..13720a2 100644
--- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
+++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
@@ -13,8 +13,8 @@ Recommended properies:
 
 Optional properties:
 - fsl,usbphy: phandler of usb phy that connects to the only one port
-- fsl,usbmisc: phandler of non-core register device, with one argument
-  that indicate usb controller index
+- ci,noncore: phandler of non-core register device, the user must enable
+syscon driver to use it
 - vbus-supply: regulator for vbus
 - disable-over-current: disable over current detect
 - external-vbus-divider: enables off-chip resistor divider for Vbus
@@ -25,7 +25,11 @@ usb@02184000 { /* USB OTG */
 	reg = <0x02184000 0x200>;
 	interrupts = <0 43 0x04>;
 	fsl,usbphy = <&usbphy1>;
-	fsl,usbmisc = <&usbmisc 0>;
+	ci,noncore = <&noncore>;
 	disable-over-current;
 	external-vbus-divider;
 };
+noncore: usb-non-core@02184800 {
+	 compatible = "fsl,imx-usb-non-core", "syscon";
+	 reg = <0x02184800 0x200>;
+};
diff --git a/Documentation/devicetree/bindings/usb/usbmisc-imx.txt b/Documentation/devicetree/bindings/usb/usbmisc-imx.txt
deleted file mode 100644
index 97ce94e..0000000
--- a/Documentation/devicetree/bindings/usb/usbmisc-imx.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-* Freescale i.MX non-core registers
-
-Required properties:
-- #index-cells: Cells used to descibe usb controller index. Should be <1>
-- compatible: Should be one of below:
-	"fsl,imx6q-usbmisc" for imx6q
-- reg: Should contain registers location and length
-
-Examples:
-usbmisc@02184800 {
-	#index-cells = <1>;
-	compatible = "fsl,imx6q-usbmisc";
-	reg = <0x02184800 0x200>;
-};
diff --git a/arch/arm/boot/dts/imx23.dtsi b/arch/arm/boot/dts/imx23.dtsi
index 587ceef..a0d8471 100644
--- a/arch/arm/boot/dts/imx23.dtsi
+++ b/arch/arm/boot/dts/imx23.dtsi
@@ -20,6 +20,7 @@
 		gpio2 = &gpio2;
 		serial0 = &auart0;
 		serial1 = &auart1;
+		usb0 = &usb0;
 	};
 
 	cpus {
diff --git a/arch/arm/boot/dts/imx25.dtsi b/arch/arm/boot/dts/imx25.dtsi
index 1f72862..7bb94ce 100644
--- a/arch/arm/boot/dts/imx25.dtsi
+++ b/arch/arm/boot/dts/imx25.dtsi
@@ -461,7 +461,7 @@
 				interrupts = <37>;
 				clocks = <&clks 9>, <&clks 70>, <&clks 8>;
 				clock-names = "ipg", "ahb", "per";
-				fsl,usbmisc = <&usbmisc 0>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
@@ -471,17 +471,13 @@
 				interrupts = <35>;
 				clocks = <&clks 9>, <&clks 70>, <&clks 8>;
 				clock-names = "ipg", "ahb", "per";
-				fsl,usbmisc = <&usbmisc 1>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
-			usbmisc: usbmisc@53ff4600 {
-				#index-cells = <1>;
-				compatible = "fsl,imx25-usbmisc";
-				clocks = <&clks 9>, <&clks 70>, <&clks 8>;
-				clock-names = "ipg", "ahb", "per";
-				reg = <0x53ff4600 0x00f>;
-				status = "disabled";
+			noncore: usb-non-core@0x53ff4600 {
+				 compatible = "fsl,imx-usb-non-core", "syscon";
+				 reg = <0x53ff4600 0x200>;
 			};
 
 			dryice@53ffc000 {
diff --git a/arch/arm/boot/dts/imx28.dtsi b/arch/arm/boot/dts/imx28.dtsi
index 4c10a19..a1ff0d1 100644
--- a/arch/arm/boot/dts/imx28.dtsi
+++ b/arch/arm/boot/dts/imx28.dtsi
@@ -29,6 +29,8 @@
 		serial4 = &auart4;
 		ethernet0 = &mac0;
 		ethernet1 = &mac1;
+		usb0 = &usb0;
+		usb1 = &usb1;
 	};
 
 	cpus {
diff --git a/arch/arm/boot/dts/imx51.dtsi b/arch/arm/boot/dts/imx51.dtsi
index 0cd89c9..1aa46e4 100644
--- a/arch/arm/boot/dts/imx51.dtsi
+++ b/arch/arm/boot/dts/imx51.dtsi
@@ -22,6 +22,10 @@
 		gpio1 = &gpio2;
 		gpio2 = &gpio3;
 		gpio3 = &gpio4;
+		usb0 = &usbotg;
+		usb1 = &usbh1;
+		usb2 = &usbh2;
+		usb3 = &usbh3;
 	};
 
 	tzic: tz-interrupt-controller@e0000000 {
@@ -181,6 +185,7 @@
 				compatible = "fsl,imx51-usb", "fsl,imx27-usb";
 				reg = <0x73f80000 0x0200>;
 				interrupts = <18>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
@@ -188,6 +193,7 @@
 				compatible = "fsl,imx51-usb", "fsl,imx27-usb";
 				reg = <0x73f80200 0x0200>;
 				interrupts = <14>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
@@ -195,6 +201,7 @@
 				compatible = "fsl,imx51-usb", "fsl,imx27-usb";
 				reg = <0x73f80400 0x0200>;
 				interrupts = <16>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
@@ -202,9 +209,15 @@
 				compatible = "fsl,imx51-usb", "fsl,imx27-usb";
 				reg = <0x73f80600 0x0200>;
 				interrupts = <17>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
+			noncore: usb-non-core@0x73f80800 {
+				 compatible = "fsl,imx-usb-non-core", "syscon";
+				 reg = <0x73f80800 0x200>;
+			};
+
 			gpio1: gpio@73f84000 {
 				compatible = "fsl,imx51-gpio", "fsl,imx35-gpio";
 				reg = <0x73f84000 0x4000>;
diff --git a/arch/arm/boot/dts/imx53.dtsi b/arch/arm/boot/dts/imx53.dtsi
index 28707f0..1a12c51 100644
--- a/arch/arm/boot/dts/imx53.dtsi
+++ b/arch/arm/boot/dts/imx53.dtsi
@@ -27,6 +27,10 @@
 		gpio4 = &gpio5;
 		gpio5 = &gpio6;
 		gpio6 = &gpio7;
+		usb0 = &usbotg;
+		usb1 = &usbh1;
+		usb2 = &usbh2;
+		usb3 = &usbh3;
 	};
 
 	tzic: tz-interrupt-controller@0fffc000 {
@@ -169,6 +173,7 @@
 				compatible = "fsl,imx53-usb", "fsl,imx27-usb";
 				reg = <0x53f80000 0x0200>;
 				interrupts = <18>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
@@ -176,6 +181,7 @@
 				compatible = "fsl,imx53-usb", "fsl,imx27-usb";
 				reg = <0x53f80200 0x0200>;
 				interrupts = <14>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
@@ -183,6 +189,7 @@
 				compatible = "fsl,imx53-usb", "fsl,imx27-usb";
 				reg = <0x53f80400 0x0200>;
 				interrupts = <16>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
@@ -190,9 +197,15 @@
 				compatible = "fsl,imx53-usb", "fsl,imx27-usb";
 				reg = <0x53f80600 0x0200>;
 				interrupts = <17>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
+			noncore: usb-non-core@0x53f80800 {
+				 compatible = "fsl,imx-usb-non-core", "syscon";
+				 reg = <0x53f80800 0x200>;
+			};
+
 			gpio1: gpio@53f84000 {
 				compatible = "fsl,imx53-gpio", "fsl,imx35-gpio";
 				reg = <0x53f84000 0x4000>;
diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index 7b4fb96..c308e63 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -28,6 +28,10 @@
 		serial2 = &uart3;
 		serial3 = &uart4;
 		serial4 = &uart5;
+		usb0 = &usbotg;
+		usb1 = &usbh1;
+		usb2 = &usbh2;
+		usb3 = &usbh3;
 	};
 
 	intc: interrupt-controller@00a01000 {
@@ -1286,7 +1290,7 @@
 				interrupts = <0 43 0x04>;
 				clocks = <&clks 162>;
 				fsl,usbphy = <&usbphy1>;
-				fsl,usbmisc = <&usbmisc 0>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
@@ -1296,7 +1300,7 @@
 				interrupts = <0 40 0x04>;
 				clocks = <&clks 162>;
 				fsl,usbphy = <&usbphy2>;
-				fsl,usbmisc = <&usbmisc 1>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
@@ -1305,7 +1309,7 @@
 				reg = <0x02184400 0x200>;
 				interrupts = <0 41 0x04>;
 				clocks = <&clks 162>;
-				fsl,usbmisc = <&usbmisc 2>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
@@ -1314,15 +1318,13 @@
 				reg = <0x02184600 0x200>;
 				interrupts = <0 42 0x04>;
 				clocks = <&clks 162>;
-				fsl,usbmisc = <&usbmisc 3>;
+				ci,noncore = <&noncore>;
 				status = "disabled";
 			};
 
-			usbmisc: usbmisc: usbmisc@02184800 {
-				#index-cells = <1>;
-				compatible = "fsl,imx6q-usbmisc";
-				reg = <0x02184800 0x200>;
-				clocks = <&clks 162>;
+			noncore: usb-non-core@02184800 {
+				 compatible = "fsl,imx-usb-non-core", "syscon";
+				 reg = <0x02184800 0x200>;
 			};
 
 			fec: ethernet@02188000 {
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index a99d980..2f0b309 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -17,5 +17,5 @@ ifneq ($(CONFIG_PCI),)
 endif
 
 ifneq ($(CONFIG_OF),)
-	obj-$(CONFIG_USB_CHIPIDEA)	+= ci_hdrc_imx.o usbmisc_imx.o
+	obj-$(CONFIG_USB_CHIPIDEA)	+= ci_hdrc_imx.o
 endif
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
index bd1fe25..d660734 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -19,68 +19,78 @@
 #include <linux/dma-mapping.h>
 #include <linux/usb/chipidea.h>
 #include <linux/clk.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>
 
 #include "ci.h"
 #include "ci_hdrc_imx.h"
+#include "usbmisc_imx.c"
 
-#define pdev_to_phy(pdev) \
-	((struct usb_phy *)platform_get_drvdata(pdev))
-
-struct ci_hdrc_imx_data {
-	struct usb_phy *phy;
-	struct platform_device *ci_pdev;
-	struct clk *clk;
+static const struct of_device_id ci_hdrc_imx_dt_ids[] = {
+	{
+		.compatible = "fsl,imx23-usb",
+		.data = &imx23_usbmisc_data,
+	},
+	{
+		.compatible = "fsl,imx25-usb",
+		.data = &imx25_usbmisc_data,
+	},
+	{
+		.compatible = "fsl,imx28-usb",
+		.data = &imx28_usbmisc_data,
+	},
+	{
+		.compatible = "fsl,imx53-usb",
+		.data = &imx53_usbmisc_data,
+	},
+	{
+		.compatible = "fsl,imx6q-usb",
+		.data = &imx6q_usbmisc_data,
+	},
+	{ /* sentinel */ }
 };
+MODULE_DEVICE_TABLE(of, ci_hdrc_imx_dt_ids);
 
-static const struct usbmisc_ops *usbmisc_ops;
-
-/* Common functions shared by usbmisc drivers */
-
-int usbmisc_set_ops(const struct usbmisc_ops *ops)
-{
-	if (usbmisc_ops)
-		return -EBUSY;
-
-	usbmisc_ops = ops;
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(usbmisc_set_ops);
-
-void usbmisc_unset_ops(const struct usbmisc_ops *ops)
-{
-	usbmisc_ops = NULL;
-}
-EXPORT_SYMBOL_GPL(usbmisc_unset_ops);
-
-int usbmisc_get_init_data(struct device *dev, struct usbmisc_usb_device *usbdev)
+static int usbmisc_init(struct device *dev)
 {
 	struct device_node *np = dev->of_node;
-	struct of_phandle_args args;
+	struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
 	int ret;
+	const struct of_device_id *of_id =
+			of_match_device(ci_hdrc_imx_dt_ids, dev);
 
-	usbdev->dev = dev;
+	if (of_id->data)
+		data->misc_data = (struct usbmisc_data *)of_id->data;
+	else
+		dev_dbg(dev, "no usbmisc data\n");
 
-	ret = of_parse_phandle_with_args(np, "fsl,usbmisc", "#index-cells",
-					0, &args);
-	if (ret) {
-		dev_err(dev, "Failed to parse property fsl,usbmisc, errno %d\n",
-			ret);
-		memset(usbdev, 0, sizeof(*usbdev));
+	ret = of_alias_get_id(np, "usb");
+	if (ret < 0) {
+		dev_err(dev, "failed to get alias id, errno %d\n", ret);
 		return ret;
 	}
-	usbdev->index = args.args[0];
-	of_node_put(args.np);
 
 	if (of_find_property(np, "disable-over-current", NULL))
-		usbdev->disable_oc = 1;
+		data->disable_oc = 1;
 
 	if (of_find_property(np, "external-vbus-divider", NULL))
-		usbdev->evdo = 1;
+		data->evdo = 1;
+
+	/* mx23 and mx28 doesn't have non core registers */
+	if (data->misc_data && (!strcmp(data->misc_data->name, "imx23-usb") ||
+			!strcmp(data->misc_data->name, "imx28-usb")))
+		return 0;
+
+	data->non_core_base_addr = syscon_regmap_lookup_by_phandle
+		(np, "ci,noncore");
+	if (IS_ERR(data->non_core_base_addr)) {
+		dev_err(dev, "can't find non-core regmap: %ld\n",
+				PTR_ERR(data->non_core_base_addr));
+		return PTR_ERR(data->non_core_base_addr);
+	}
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
 
 /* End of common functions shared by usbmisc drivers*/
 
@@ -96,10 +106,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 	};
 	int ret;
 
-	if (of_find_property(pdev->dev.of_node, "fsl,usbmisc", NULL)
-		&& !usbmisc_ops)
-		return -EPROBE_DEFER;
-
 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
 	if (!data) {
 		dev_err(&pdev->dev, "Failed to allocate ci_hdrc-imx data!\n");
@@ -139,8 +145,19 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 	if (!pdev->dev.coherent_dma_mask)
 		pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
 
-	if (usbmisc_ops && usbmisc_ops->init) {
-		ret = usbmisc_ops->init(&pdev->dev);
+	spin_lock_init(&data->lock);
+
+	platform_set_drvdata(pdev, data);
+
+	/* Some platform specific initializations */
+	ret = usbmisc_init(&pdev->dev);
+	if (ret) {
+		dev_err(&pdev->dev, "usbmisc_init failed, ret=%d\n", ret);
+		goto err_clk;
+	}
+
+	if (data->misc_data && data->misc_data->init) {
+		ret = data->misc_data->init(data);
 		if (ret) {
 			dev_err(&pdev->dev,
 				"usbmisc init failed, ret=%d\n", ret);
@@ -159,8 +176,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 		goto err_clk;
 	}
 
-	if (usbmisc_ops && usbmisc_ops->post) {
-		ret = usbmisc_ops->post(&pdev->dev);
+	if (data->misc_data && data->misc_data->post) {
+		ret = data->misc_data->post(data);
 		if (ret) {
 			dev_err(&pdev->dev,
 				"usbmisc post failed, ret=%d\n", ret);
@@ -168,8 +185,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 		}
 	}
 
-	platform_set_drvdata(pdev, data);
-
 	pm_runtime_no_callbacks(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
 
@@ -199,12 +214,6 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev)
 	return 0;
 }
 
-static const struct of_device_id ci_hdrc_imx_dt_ids[] = {
-	{ .compatible = "fsl,imx27-usb", },
-	{ /* sentinel */ }
-};
-MODULE_DEVICE_TABLE(of, ci_hdrc_imx_dt_ids);
-
 static struct platform_driver ci_hdrc_imx_driver = {
 	.probe = ci_hdrc_imx_probe,
 	.remove = ci_hdrc_imx_remove,
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.h b/drivers/usb/chipidea/ci_hdrc_imx.h
index 550bfa4..14731c4 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.h
+++ b/drivers/usb/chipidea/ci_hdrc_imx.h
@@ -10,22 +10,26 @@
  */
 
 /* Used to set SoC specific callbacks */
-struct usbmisc_ops {
+#define SOC_NAME_SIZE 20
+struct ci_hdrc_imx_data;
+
+struct usbmisc_data {
+	char name[SOC_NAME_SIZE];
 	/* It's called once when probe a usb device */
-	int (*init)(struct device *dev);
+	int (*init)(struct ci_hdrc_imx_data *data);
 	/* It's called once after adding a usb device */
-	int (*post)(struct device *dev);
+	int (*post)(struct ci_hdrc_imx_data *data);
 };
 
-struct usbmisc_usb_device {
-	struct device *dev; /* usb controller device */
-	int index;
-
-	unsigned int disable_oc:1; /* over current detect disabled */
-	unsigned int evdo:1; /* set external vbus divider option */
+struct ci_hdrc_imx_data {
+	struct usb_phy *phy;
+	struct platform_device *ci_pdev;
+	struct clk *clk;
+	struct usbmisc_data *misc_data;
+	/* non core register address, mx23/mx28 has no non core register */
+	struct regmap *non_core_base_addr;
+	int index; /* controller's index */
+	spinlock_t lock;
+	int disable_oc:1; /* over current detect disabled */
+	int evdo:1; /* set external vbus divider option */
 };
-
-int usbmisc_set_ops(const struct usbmisc_ops *ops);
-void usbmisc_unset_ops(const struct usbmisc_ops *ops);
-int
-usbmisc_get_init_data(struct device *dev, struct usbmisc_usb_device *usbdev);
diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
index ac5a461..af472e6 100644
--- a/drivers/usb/chipidea/usbmisc_imx.c
+++ b/drivers/usb/chipidea/usbmisc_imx.c
@@ -9,15 +9,6 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
-#include <linux/module.h>
-#include <linux/of_platform.h>
-#include <linux/clk.h>
-#include <linux/err.h>
-#include <linux/io.h>
-#include <linux/delay.h>
-
-#include "ci_hdrc_imx.h"
-
 #define USB_DEV_MAX 4
 
 #define MX25_USB_PHY_CTRL_OFFSET	0x08
@@ -32,221 +23,101 @@
 
 #define MX6_BM_OVER_CUR_DIS		BIT(7)
 
-struct imx_usbmisc {
-	void __iomem *base;
-	spinlock_t lock;
-	struct clk *clk;
-	struct usbmisc_usb_device usbdev[USB_DEV_MAX];
-	const struct usbmisc_ops *ops;
-};
-
-static struct imx_usbmisc *usbmisc;
-
-static struct usbmisc_usb_device *get_usbdev(struct device *dev)
+static int usbmisc_imx25_post(struct ci_hdrc_imx_data *data)
 {
-	int i, ret;
-
-	for (i = 0; i < USB_DEV_MAX; i++) {
-		if (usbmisc->usbdev[i].dev == dev)
-			return &usbmisc->usbdev[i];
-		else if (!usbmisc->usbdev[i].dev)
-			break;
-	}
-
-	if (i >= USB_DEV_MAX)
-		return ERR_PTR(-EBUSY);
-
-	ret = usbmisc_get_init_data(dev, &usbmisc->usbdev[i]);
-	if (ret)
-		return ERR_PTR(ret);
-
-	return &usbmisc->usbdev[i];
-}
-
-static int usbmisc_imx25_post(struct device *dev)
-{
-	struct usbmisc_usb_device *usbdev;
-	void __iomem *reg;
 	unsigned long flags;
 	u32 val;
 
-	usbdev = get_usbdev(dev);
-	if (IS_ERR(usbdev))
-		return PTR_ERR(usbdev);
-
-	reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET;
-
-	if (usbdev->evdo) {
-		spin_lock_irqsave(&usbmisc->lock, flags);
-		val = readl(reg);
-		writel(val | MX25_BM_EXTERNAL_VBUS_DIVIDER, reg);
-		spin_unlock_irqrestore(&usbmisc->lock, flags);
+	if (data->evdo) {
+		spin_lock_irqsave(&data->lock, flags);
+		regmap_read(data->non_core_base_addr,
+				MX25_USB_PHY_CTRL_OFFSET, &val);
+		regmap_write(data->non_core_base_addr,
+				MX25_USB_PHY_CTRL_OFFSET,
+					val | MX25_BM_EXTERNAL_VBUS_DIVIDER);
+		spin_unlock_irqrestore(&data->lock, flags);
 		usleep_range(5000, 10000); /* needed to stabilize voltage */
 	}
 
 	return 0;
 }
 
-static int usbmisc_imx53_init(struct device *dev)
+static int usbmisc_imx53_init(struct ci_hdrc_imx_data *data)
 {
-	struct usbmisc_usb_device *usbdev;
-	void __iomem *reg = NULL;
 	unsigned long flags;
-	u32 val = 0;
+	u32 reg = 0, val = 0;
 
-	usbdev = get_usbdev(dev);
-	if (IS_ERR(usbdev))
-		return PTR_ERR(usbdev);
-
-	if (usbdev->disable_oc) {
-		spin_lock_irqsave(&usbmisc->lock, flags);
-		switch (usbdev->index) {
+	if (data->disable_oc) {
+		spin_lock_irqsave(&data->lock, flags);
+		switch (data->index) {
 		case 0:
-			reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET;
-			val = readl(reg) | MX53_BM_OVER_CUR_DIS_OTG;
+			reg = MX53_USB_OTG_PHY_CTRL_0_OFFSET;
+			regmap_read(data->non_core_base_addr,
+				reg, &val);
+			val |= MX53_BM_OVER_CUR_DIS_OTG;
 			break;
 		case 1:
-			reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET;
-			val = readl(reg) | MX53_BM_OVER_CUR_DIS_H1;
+			reg = MX53_USB_OTG_PHY_CTRL_0_OFFSET;
+			regmap_read(data->non_core_base_addr,
+				reg, &val);
+			val |= MX53_BM_OVER_CUR_DIS_H1;
 			break;
 		case 2:
-			reg = usbmisc->base + MX53_USB_UH2_CTRL_OFFSET;
-			val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx;
+			reg = MX53_USB_UH2_CTRL_OFFSET;
+			regmap_read(data->non_core_base_addr,
+				reg, &val);
+			val |= MX53_BM_OVER_CUR_DIS_UHx;
 			break;
 		case 3:
-			reg = usbmisc->base + MX53_USB_UH3_CTRL_OFFSET;
-			val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx;
+			reg = MX53_USB_UH3_CTRL_OFFSET;
+			regmap_read(data->non_core_base_addr,
+				reg, &val);
+			val |= MX53_BM_OVER_CUR_DIS_UHx;
 			break;
 		}
 		if (reg && val)
-			writel(val, reg);
-		spin_unlock_irqrestore(&usbmisc->lock, flags);
+			regmap_write(data->non_core_base_addr, reg, val);
+		spin_unlock_irqrestore(&data->lock, flags);
 	}
 
 	return 0;
 }
 
-static int usbmisc_imx6q_init(struct device *dev)
+static int usbmisc_imx6q_init(struct ci_hdrc_imx_data *data)
 {
-
-	struct usbmisc_usb_device *usbdev;
 	unsigned long flags;
-	u32 reg;
-
-	usbdev = get_usbdev(dev);
-	if (IS_ERR(usbdev))
-		return PTR_ERR(usbdev);
-
-	if (usbdev->disable_oc) {
-		spin_lock_irqsave(&usbmisc->lock, flags);
-		reg = readl(usbmisc->base + usbdev->index * 4);
-		writel(reg | MX6_BM_OVER_CUR_DIS,
-			usbmisc->base + usbdev->index * 4);
-		spin_unlock_irqrestore(&usbmisc->lock, flags);
+	u32 val;
+
+	if (data->disable_oc) {
+		spin_lock_irqsave(&data->lock, flags);
+		regmap_read(data->non_core_base_addr, data->index * 4, &val);
+		regmap_write(data->non_core_base_addr, data->index * 4,
+			val | MX6_BM_OVER_CUR_DIS);
+		spin_unlock_irqrestore(&data->lock, flags);
 	}
 
 	return 0;
 }
 
-static const struct usbmisc_ops imx25_usbmisc_ops = {
-	.post = usbmisc_imx25_post,
+static const struct usbmisc_data imx23_usbmisc_data = {
+	.name = "imx23-usb",
 };
 
-static const struct usbmisc_ops imx53_usbmisc_ops = {
-	.init = usbmisc_imx53_init,
+static const struct usbmisc_data imx25_usbmisc_data = {
+	.name = "imx25-usb",
+	.post = usbmisc_imx25_post,
 };
 
-static const struct usbmisc_ops imx6q_usbmisc_ops = {
-	.init = usbmisc_imx6q_init,
+static const struct usbmisc_data imx28_usbmisc_data = {
+	.name = "imx28-usb",
 };
 
-static const struct of_device_id usbmisc_imx_dt_ids[] = {
-	{
-		.compatible = "fsl,imx25-usbmisc",
-		.data = &imx25_usbmisc_ops,
-	},
-	{
-		.compatible = "fsl,imx53-usbmisc",
-		.data = &imx53_usbmisc_ops,
-	},
-	{
-		.compatible = "fsl,imx6q-usbmisc",
-		.data = &imx6q_usbmisc_ops,
-	},
-	{ /* sentinel */ }
+static const struct usbmisc_data imx53_usbmisc_data = {
+	.name = "imx53-usb",
+	.init = usbmisc_imx53_init,
 };
-MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids);
-
-static int usbmisc_imx_probe(struct platform_device *pdev)
-{
-	struct resource	*res;
-	struct imx_usbmisc *data;
-	int ret;
-	struct of_device_id *tmp_dev;
-
-	if (usbmisc)
-		return -EBUSY;
-
-	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
-	spin_lock_init(&data->lock);
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	data->base = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(data->base))
-		return PTR_ERR(data->base);
-
-	data->clk = devm_clk_get(&pdev->dev, NULL);
-	if (IS_ERR(data->clk)) {
-		dev_err(&pdev->dev,
-			"failed to get clock, err=%ld\n", PTR_ERR(data->clk));
-		return PTR_ERR(data->clk);
-	}
-
-	ret = clk_prepare_enable(data->clk);
-	if (ret) {
-		dev_err(&pdev->dev,
-			"clk_prepare_enable failed, err=%d\n", ret);
-		return ret;
-	}
-
-	tmp_dev = (struct of_device_id *)
-		of_match_device(usbmisc_imx_dt_ids, &pdev->dev);
-	data->ops = (const struct usbmisc_ops *)tmp_dev->data;
-	usbmisc = data;
-	ret = usbmisc_set_ops(data->ops);
-	if (ret) {
-		usbmisc = NULL;
-		clk_disable_unprepare(data->clk);
-		return ret;
-	}
 
-	return 0;
-}
-
-static int usbmisc_imx_remove(struct platform_device *pdev)
-{
-	usbmisc_unset_ops(usbmisc->ops);
-	clk_disable_unprepare(usbmisc->clk);
-	usbmisc = NULL;
-	return 0;
-}
-
-static struct platform_driver usbmisc_imx_driver = {
-	.probe = usbmisc_imx_probe,
-	.remove = usbmisc_imx_remove,
-	.driver = {
-		.name = "usbmisc_imx",
-		.owner = THIS_MODULE,
-		.of_match_table = usbmisc_imx_dt_ids,
-	 },
+static const struct usbmisc_data imx6q_usbmisc_data = {
+	.name = "imx6q-usb",
+	.init = usbmisc_imx6q_init,
 };
-
-module_platform_driver(usbmisc_imx_driver);
-
-MODULE_ALIAS("platform:usbmisc-imx");
-MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("driver for imx usb non-core registers");
-MODULE_AUTHOR("Richard Zhao <richard.zhao@xxxxxxxxxxxxx>");
-- 
1.7.1


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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux