devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Keshava Munegowda <keshava_mgowda@ti.com>
To: linux-omap@vger.kernel.org, devicetree-discuss@lists.ozlabs.org,
	linux-doc@vger.kernel.org, linux-usb@vger.kernel.org
Cc: Keshava Munegowda <keshava_mgowda@ti.com>,
	balbi@ti.com, sameo@linux.intel.com, b-cousson@ti.com
Subject: [RESEND PATCH 06/11] ARM: OMAP: USB: Host: USB TLL Device tree node Adaptation
Date: Wed, 31 Oct 2012 19:56:47 +0530	[thread overview]
Message-ID: <1351693612-23314-7-git-send-email-keshava_mgowda@ti.com> (raw)
In-Reply-To: <1351693612-23314-1-git-send-email-keshava_mgowda@ti.com>

The USB TLL device node is extracted and used in the probe
of the driver to initialize the driver data.
This TLL driver exports an API to usbhs driver to perform
the port configuration. The usb2 hs driver invoke the same
API in its driver probe to initialize the ports.

Signed-off-by: Keshava Munegowda <keshava_mgowda@ti.com>
---
 drivers/mfd/omap-usb-host.c            |    7 ++
 drivers/mfd/omap-usb-tll.c             |  192 +++++++++++++++++++-------------
 include/linux/platform_data/usb-omap.h |    2 +
 3 files changed, 124 insertions(+), 77 deletions(-)

diff --git a/drivers/mfd/omap-usb-host.c b/drivers/mfd/omap-usb-host.c
index 4b3af16..27aa85e 100644
--- a/drivers/mfd/omap-usb-host.c
+++ b/drivers/mfd/omap-usb-host.c
@@ -657,6 +657,11 @@ static int __devinit usbhs_omap_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, omap);
 	dev->platform_data = pdata;
 
+	if (omap_tll_init(pdata->port_mode)) {
+		dev_err(dev, "omap_tll_init failed\n");
+		goto err_tll;
+	}
+
 	omap_usbhs_init(dev);
 	ret = omap_usbhs_alloc_children(pdev);
 	if (ret) {
@@ -668,6 +673,8 @@ static int __devinit usbhs_omap_probe(struct platform_device *pdev)
 
 err_alloc:
 	omap_usbhs_deinit(&pdev->dev);
+
+err_tll:
 	iounmap(omap->uhh_base);
 
 err_init_60m_fclk:
diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
index 0db0dfa..f457883 100644
--- a/drivers/mfd/omap-usb-tll.c
+++ b/drivers/mfd/omap-usb-tll.c
@@ -24,6 +24,7 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/of.h>
 #include <linux/err.h>
 #include <linux/pm_runtime.h>
 #include <linux/platform_data/usb-omap.h>
@@ -98,7 +99,9 @@
 struct usbtll_omap {
 	struct clk				*usbtll_p1_fck;
 	struct clk				*usbtll_p2_fck;
-	struct usbtll_omap_platform_data	platdata;
+	void __iomem				*base;
+	enum usbhs_omap_port_mode		port_mode[OMAP3_HS_USB_PORTS];
+
 	/* secure the register updates */
 	spinlock_t				lock;
 };
@@ -196,17 +199,15 @@ static unsigned ohci_omap3_fslsmode(enum usbhs_omap_port_mode mode)
 }
 
 /**
- * usbtll_omap_probe - initialize TI-based HCDs
+ * usbtll_omap_initports - initialize TI-based HCDs
  *
- * Allocates basic resources for this USB host controller.
+ * initialize the usb tll ports. Maximum 3 ports
  */
-static int __devinit usbtll_omap_probe(struct platform_device *pdev)
+
+static int usbtll_initports(struct device *dev,
+			    enum usbhs_omap_port_mode port_mode[])
 {
-	struct device				*dev =  &pdev->dev;
-	struct usbtll_omap_platform_data	*pdata = dev->platform_data;
-	void __iomem				*base;
-	struct resource				*res;
-	struct usbtll_omap			*tll;
+	struct usbtll_omap			*tll = dev_get_drvdata(dev);
 	unsigned				reg;
 	unsigned long				flags;
 	int					ret = 0;
@@ -214,53 +215,19 @@ static int __devinit usbtll_omap_probe(struct platform_device *pdev)
 
 	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
 
-	tll = kzalloc(sizeof(struct usbtll_omap), GFP_KERNEL);
 	if (!tll) {
-		dev_err(dev, "Memory allocation failed\n");
-		ret = -ENOMEM;
-		goto end;
+		dev_err(dev, "%s: missing TLL Driver data\n", __func__);
+		return -ENOMEM;
 	}
 
-	spin_lock_init(&tll->lock);
-
 	for (i = 0; i < OMAP3_HS_USB_PORTS; i++)
-		tll->platdata.port_mode[i] = pdata->port_mode[i];
+		tll->port_mode[i] = port_mode[i];
 
-	tll->usbtll_p1_fck = clk_get(dev, "usb_tll_hs_usb_ch0_clk");
-	if (IS_ERR(tll->usbtll_p1_fck)) {
-		ret = PTR_ERR(tll->usbtll_p1_fck);
-		dev_err(dev, "usbtll_p1_fck failed error:%d\n", ret);
-		goto err_tll;
-	}
-
-	tll->usbtll_p2_fck = clk_get(dev, "usb_tll_hs_usb_ch1_clk");
-	if (IS_ERR(tll->usbtll_p2_fck)) {
-		ret = PTR_ERR(tll->usbtll_p2_fck);
-		dev_err(dev, "usbtll_p2_fck failed error:%d\n", ret);
-		goto err_usbtll_p1_fck;
-	}
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(dev, "usb tll get resource failed\n");
-		ret = -ENODEV;
-		goto err_usbtll_p2_fck;
-	}
-
-	base = ioremap(res->start, resource_size(res));
-	if (!base) {
-		dev_err(dev, "TLL ioremap failed\n");
-		ret = -ENOMEM;
-		goto err_usbtll_p2_fck;
-	}
-
-	platform_set_drvdata(pdev, tll);
-	pm_runtime_enable(dev);
 	pm_runtime_get_sync(dev);
 
 	spin_lock_irqsave(&tll->lock, flags);
 
-	ver =  usbtll_read(base, OMAP_USBTLL_REVISION);
+	ver =  usbtll_read(tll->base, OMAP_USBTLL_REVISION);
 	switch (ver) {
 	case OMAP_USBTLL_REV1:
 	case OMAP_USBTLL_REV2:
@@ -272,34 +239,34 @@ static int __devinit usbtll_omap_probe(struct platform_device *pdev)
 	default:
 		dev_err(dev, "TLL version failed\n");
 		ret = -ENODEV;
-		goto err_ioremap;
+		goto end;
 	}
 
-	if (is_ehci_tll_mode(pdata->port_mode[0]) ||
-	    is_ehci_tll_mode(pdata->port_mode[1]) ||
-	    is_ehci_tll_mode(pdata->port_mode[2]) ||
-	    is_ohci_port(pdata->port_mode[0]) ||
-	    is_ohci_port(pdata->port_mode[1]) ||
-	    is_ohci_port(pdata->port_mode[2])) {
+	if (is_ehci_tll_mode(tll->port_mode[0]) ||
+	    is_ehci_tll_mode(tll->port_mode[1]) ||
+	    is_ehci_tll_mode(tll->port_mode[2]) ||
+	    is_ohci_port(tll->port_mode[0]) ||
+	    is_ohci_port(tll->port_mode[1]) ||
+	    is_ohci_port(tll->port_mode[2])) {
 
 		/* Program Common TLL register */
-		reg = usbtll_read(base, OMAP_TLL_SHARED_CONF);
+		reg = usbtll_read(tll->base, OMAP_TLL_SHARED_CONF);
 		reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
 			| OMAP_TLL_SHARED_CONF_USB_DIVRATION);
 		reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
 		reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN;
 
-		usbtll_write(base, OMAP_TLL_SHARED_CONF, reg);
+		usbtll_write(tll->base, OMAP_TLL_SHARED_CONF, reg);
 
 		/* Enable channels now */
 		for (i = 0; i < count; i++) {
-			reg = usbtll_read(base,	OMAP_TLL_CHANNEL_CONF(i));
+			reg = usbtll_read(tll->base, OMAP_TLL_CHANNEL_CONF(i));
 
-			if (is_ohci_port(pdata->port_mode[i])) {
-				reg |= ohci_omap3_fslsmode(pdata->port_mode[i])
+			if (is_ohci_port(tll->port_mode[i])) {
+				reg |= ohci_omap3_fslsmode(tll->port_mode[i])
 				<< OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT;
 				reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS;
-			} else if (pdata->port_mode[i] ==
+			} else if (tll->port_mode[i] ==
 					OMAP_EHCI_PORT_MODE_TLL) {
 				/*
 				 * Disable AutoIdle, BitStuffing
@@ -312,22 +279,75 @@ static int __devinit usbtll_omap_probe(struct platform_device *pdev)
 				continue;
 			}
 			reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
-			usbtll_write(base, OMAP_TLL_CHANNEL_CONF(i), reg);
+			usbtll_write(tll->base, OMAP_TLL_CHANNEL_CONF(i), reg);
 
-			usbtll_writeb(base,
+			usbtll_writeb(tll->base,
 				      OMAP_TLL_ULPI_SCRATCH_REGISTER(i),
 				      0xbe);
 		}
 	}
 
-err_ioremap:
+end:
 	spin_unlock_irqrestore(&tll->lock, flags);
-	iounmap(base);
 	pm_runtime_put_sync(dev);
+	return ret;
+}
+
+/**
+ * usbtll_omap_probe - initialize TI-based HCDs
+ *
+ * Allocates basic resources for this USB host controller.
+ */
+static int __devinit usbtll_omap_probe(struct platform_device *pdev)
+{
+	struct device				*dev =  &pdev->dev;
+	struct resource				*res;
+	struct usbtll_omap			*tll;
+	int					ret = 0;
+
+	dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
+
+	tll = kzalloc(sizeof(struct usbtll_omap), GFP_KERNEL);
+	if (!tll) {
+		dev_err(dev, "Memory allocation failed\n");
+		ret = -ENOMEM;
+		goto err_tll;
+	}
+
+	spin_lock_init(&tll->lock);
+
+	tll->usbtll_p1_fck = clk_get(dev, "usb_tll_hs_usb_ch0_clk");
+	if (IS_ERR(tll->usbtll_p1_fck)) {
+		ret = PTR_ERR(tll->usbtll_p1_fck);
+		dev_err(dev, "usbtll_p1_fck failed error:%d\n", ret);
+		goto err_tll;
+	}
+
+	tll->usbtll_p2_fck = clk_get(dev, "usb_tll_hs_usb_ch1_clk");
+	if (IS_ERR(tll->usbtll_p2_fck)) {
+		ret = PTR_ERR(tll->usbtll_p2_fck);
+		dev_err(dev, "usbtll_p2_fck failed error:%d\n", ret);
+		goto err_usbtll_p1_fck;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "usb tll get resource failed\n");
+		ret = -ENODEV;
+		goto err_usbtll_p2_fck;
+	}
+
+	tll->base = ioremap(res->start, resource_size(res));
+	if (!tll->base) {
+		dev_err(dev, "TLL ioremap failed\n");
+		ret = -ENOMEM;
+		goto err_usbtll_p2_fck;
+	}
+
+	platform_set_drvdata(pdev, tll);
+	pm_runtime_enable(dev);
 	tll_pdev = pdev;
-	if (!ret)
-		goto end;
-	pm_runtime_disable(dev);
+	return 0;
 
 err_usbtll_p2_fck:
 	clk_put(tll->usbtll_p2_fck);
@@ -337,8 +357,6 @@ err_usbtll_p1_fck:
 
 err_tll:
 	kfree(tll);
-
-end:
 	return ret;
 }
 
@@ -362,22 +380,21 @@ static int __devexit usbtll_omap_remove(struct platform_device *pdev)
 static int usbtll_runtime_resume(struct device *dev)
 {
 	struct usbtll_omap			*tll = dev_get_drvdata(dev);
-	struct usbtll_omap_platform_data	*pdata = &tll->platdata;
 	unsigned long				flags;
 
 	dev_dbg(dev, "usbtll_runtime_resume\n");
 
-	if (!pdata) {
+	if (!tll) {
 		dev_dbg(dev, "missing platform_data\n");
 		return  -ENODEV;
 	}
 
 	spin_lock_irqsave(&tll->lock, flags);
 
-	if (is_ehci_tll_mode(pdata->port_mode[0]))
+	if (is_ehci_tll_mode(tll->port_mode[0]))
 		clk_enable(tll->usbtll_p1_fck);
 
-	if (is_ehci_tll_mode(pdata->port_mode[1]))
+	if (is_ehci_tll_mode(tll->port_mode[1]))
 		clk_enable(tll->usbtll_p2_fck);
 
 	spin_unlock_irqrestore(&tll->lock, flags);
@@ -388,22 +405,21 @@ static int usbtll_runtime_resume(struct device *dev)
 static int usbtll_runtime_suspend(struct device *dev)
 {
 	struct usbtll_omap			*tll = dev_get_drvdata(dev);
-	struct usbtll_omap_platform_data	*pdata = &tll->platdata;
 	unsigned long				flags;
 
 	dev_dbg(dev, "usbtll_runtime_suspend\n");
 
-	if (!pdata) {
+	if (!tll) {
 		dev_dbg(dev, "missing platform_data\n");
 		return  -ENODEV;
 	}
 
 	spin_lock_irqsave(&tll->lock, flags);
 
-	if (is_ehci_tll_mode(pdata->port_mode[0]))
+	if (is_ehci_tll_mode(tll->port_mode[0]))
 		clk_disable(tll->usbtll_p1_fck);
 
-	if (is_ehci_tll_mode(pdata->port_mode[1]))
+	if (is_ehci_tll_mode(tll->port_mode[1]))
 		clk_disable(tll->usbtll_p2_fck);
 
 	spin_unlock_irqrestore(&tll->lock, flags);
@@ -417,16 +433,38 @@ static const struct dev_pm_ops usbtllomap_dev_pm_ops = {
 			   NULL)
 };
 
+#ifdef CONFIG_OF
+static const struct of_device_id omap_tll_of_match[] = {
+	{
+		.compatible = "ti,usbtll",
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, omap_tll_of_match);
+
+#endif
+
 static struct platform_driver usbtll_omap_driver = {
 	.driver = {
 		.name		= (char *)usbtll_driver_name,
 		.owner		= THIS_MODULE,
 		.pm		= &usbtllomap_dev_pm_ops,
+		.of_match_table = of_match_ptr(omap_tll_of_match),
 	},
 	.probe		= usbtll_omap_probe,
 	.remove		= __devexit_p(usbtll_omap_remove),
 };
 
+int omap_tll_init(enum usbhs_omap_port_mode port_mode[])
+{
+	if (!tll_pdev) {
+		pr_err("missing omap usbhs tll platform_data\n");
+		return  -ENODEV;
+	}
+	return usbtll_initports(&tll_pdev->dev, port_mode);
+}
+EXPORT_SYMBOL_GPL(omap_tll_init);
+
 int omap_tll_enable(void)
 {
 	if (!tll_pdev) {
diff --git a/include/linux/platform_data/usb-omap.h b/include/linux/platform_data/usb-omap.h
index 04dcf67..3ad2d8a 100644
--- a/include/linux/platform_data/usb-omap.h
+++ b/include/linux/platform_data/usb-omap.h
@@ -91,3 +91,5 @@ enum musb_interface {
 	MUSB_INTERFACE_ULPI,
 	MUSB_INTERFACE_UTMI
 };
+
+extern int omap_tll_init(enum usbhs_omap_port_mode port_mode[]);
-- 
1.7.9.5


  parent reply	other threads:[~2012-10-31 14:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-31 14:26 [RESEND PATCH 00/11] ARM: OMAP: USB: Host: Device tree Adaptation Keshava Munegowda
2012-10-31 14:26 ` [RESEND PATCH 01/11] ARM: OMAP4: USB: Host: Add USB2 Host Device Tree Node Keshava Munegowda
2012-10-31 14:26 ` [RESEND PATCH 02/11] ARM: OMAP4: USB: Host: Panda board specific device tree node Keshava Munegowda
2012-10-31 14:26 ` [RESEND PATCH 05/11] ARM: OMAP: USB: Host: usb host Device tree node Adaptation Keshava Munegowda
     [not found]   ` <1351693612-23314-6-git-send-email-keshava_mgowda-l0cyMroinI0@public.gmane.org>
2012-10-31 18:29     ` Tony Lindgren
     [not found]       ` <20121031182903.GN12739-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2012-11-01  8:19         ` Munegowda, Keshava
2012-11-01 10:21           ` Felipe Balbi
2012-11-01 15:12             ` Munegowda, Keshava
2012-10-31 14:26 ` Keshava Munegowda [this message]
2012-10-31 14:26 ` [RESEND PATCH 07/11] ARM: OMAP: USB: Host: Ehci driver uses the usbhs port data Keshava Munegowda
2012-10-31 14:26 ` [RESEND PATCH 08/11] ARM: OMAP: USB: Change the TLL clock names Keshava Munegowda
2012-10-31 14:26 ` [RESEND PATCH 09/11] ARM: OMAP: USB: Remove the device name for TLL channel clocks for OMAP3 Keshava Munegowda
     [not found] ` <1351693612-23314-1-git-send-email-keshava_mgowda-l0cyMroinI0@public.gmane.org>
2012-10-31 14:26   ` [RESEND PATCH 03/11] ARM: OMAP3: USB: Add USB2 Host Device Tree Node Keshava Munegowda
2012-10-31 14:26   ` [RESEND PATCH 04/11] ARM: OMAP3: USB: Host: Beagle-XM board specific device tree node Keshava Munegowda
2012-10-31 14:26   ` [RESEND PATCH 10/11] ARM: OMAP4: USB: Add pin mux configuration for panda board Keshava Munegowda
2012-10-31 14:26   ` [RESEND PATCH 11/11] ARM: OMAP3: USB: Add pin mux configuration for beagle-xm board Keshava Munegowda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1351693612-23314-7-git-send-email-keshava_mgowda@ti.com \
    --to=keshava_mgowda@ti.com \
    --cc=b-cousson@ti.com \
    --cc=balbi@ti.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sameo@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).