linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: richard.zhao@freescale.com (Richard Zhao)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 05/12] usb: chipidea: add imx platform driver
Date: Fri, 25 May 2012 10:24:18 +0800	[thread overview]
Message-ID: <1337912665-16615-6-git-send-email-richard.zhao@freescale.com> (raw)
In-Reply-To: <1337912665-16615-1-git-send-email-richard.zhao@freescale.com>

This patch supports only the host-mode functionality so far.

Signed-off-by: Richard Zhao <richard.zhao@freescale.com>
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Peter Chen <peter.chen@freescale.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 .../devicetree/bindings/usb/ci13xxx-imx.txt        |   20 ++
 drivers/usb/chipidea/Makefile                      |    3 +
 drivers/usb/chipidea/ci13xxx_imx.c                 |  189 ++++++++++++++++++++
 3 files changed, 212 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
 create mode 100644 drivers/usb/chipidea/ci13xxx_imx.c

diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
new file mode 100644
index 0000000..beb75d6
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
@@ -0,0 +1,20 @@
+* Freescale i.MX ci13xxx usb controllers
+
+Required properties:
+- compatible: Should be "fsl,imx31-usb"
+- reg: Should contain registers location and length
+- interrupts: Should contain controller interrupt
+
+Optional properties:
+- fsl,usbphy: phandler of usb phy that connects to the only one port
+- fsl,hub-reset-gpios: gpio used to reset on-board usb hub
+- fsl,vbus-power-gpios: gpio used to set vbus power of the only one port
+
+Examples:
+usb at 02184000 { /* USB OTG */
+	compatible = "fsl,imx6q-usb", "fsl,imx31-usb";
+	reg = <0x02184000 0x200>;
+	interrupts = <0 43 0x04>;
+	fsl,usbphy = <&usbphy1>;
+	fsl,vbus-power-gpios = <&gpio3 22 0>;
+};
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index b69900a..5c66d9c 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -14,3 +14,6 @@ ifneq ($(CONFIG_PCI),)
 	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_pci.o
 endif
 
+ifneq ($(CONFIG_OF_DEVICE),)
+	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_imx.o
+endif
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c
new file mode 100644
index 0000000..de570a2
--- /dev/null
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/dma-mapping.h>
+#include <linux/usb/chipidea.h>
+#include <linux/clk.h>
+#include <linux/regulator/consumer.h>
+
+#include "ci.h"
+
+#define pdev_to_phy(pdev) \
+	((struct usb_phy *)platform_get_drvdata(pdev))
+
+struct ci13xxx_imx_data {
+	struct device_node *phy_np;
+	struct usb_phy *phy;
+	struct platform_device *ci_pdev;
+	struct clk *clk;
+	struct regulator *reg_vbus;
+};
+
+static struct ci13xxx_platform_data ci13xxx_imx_platdata __devinitdata  = {
+	.name			= "ci13xxx_imx",
+	.flags			= CI13XXX_REQUIRE_TRANSCEIVER |
+				  CI13XXX_PULLUP_ON_VBUS |
+				  CI13XXX_DISABLE_STREAMING,
+	.capoffset		= DEF_CAPOFFSET,
+};
+
+static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
+{
+	struct ci13xxx_imx_data *data;
+	struct platform_device *plat_ci, *phy_pdev;
+	struct device_node *phy_np;
+	struct resource *res;
+	struct regulator *reg_vbus;
+	int ret;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data) {
+		dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n");
+		return -ENOMEM;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "Can't get device resources!\n");
+		return -ENOENT;
+	}
+
+	data->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(data->clk)) {
+		dev_err(&pdev->dev, "Failed to get clock!\n");
+		return PTR_ERR(data->clk);
+	}
+
+	ret = clk_prepare_enable(data->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to prepare or enable clock!\n");
+		return ret;
+	}
+
+	phy_np = of_parse_phandle(pdev->dev.of_node, "fsl,usbphy", 0);
+	if (phy_np) {
+		data->phy_np = phy_np;
+		phy_pdev = of_find_device_by_node(phy_np);
+		if (phy_pdev) {
+			struct usb_phy *phy;
+			phy = pdev_to_phy(phy_pdev);
+			if (phy &&
+			    try_module_get(phy_pdev->dev.driver->owner)) {
+				usb_phy_init(phy);
+				data->phy = phy;
+			}
+		}
+	}
+
+	/* we only support host now, so enable vbus here */
+	reg_vbus = devm_regulator_get(&pdev->dev, "vbus");
+	if (!IS_ERR(reg_vbus)) {
+		ret = regulator_enable(reg_vbus);
+		if (ret) {
+			dev_err(&pdev->dev,
+				"Failed to enable vbus regulator!\n");
+			goto put_np;
+		}
+		data->reg_vbus = reg_vbus;
+	} else
+		reg_vbus = NULL;
+
+	ci13xxx_imx_platdata.phy = data->phy;
+
+	if (!pdev->dev.dma_mask) {
+		pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
+				      sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
+		if (!pdev->dev.dma_mask) {
+			ret = -ENOMEM;
+			dev_err(&pdev->dev, "Failed to alloc dma_mask!\n");
+			goto err;
+		}
+		*pdev->dev.dma_mask = DMA_BIT_MASK(32);
+		dma_set_coherent_mask(&pdev->dev, *pdev->dev.dma_mask);
+	}
+	plat_ci = ci13xxx_add_device(&pdev->dev,
+				pdev->resource, pdev->num_resources,
+				&ci13xxx_imx_platdata);
+	if (IS_ERR(plat_ci)) {
+		dev_err(&pdev->dev, "Can't register ci_hdrc platform device\n");
+		ret = PTR_ERR(plat_ci);
+		goto err;
+	}
+
+	data->ci_pdev = plat_ci;
+	platform_set_drvdata(pdev, data);
+
+	pm_runtime_no_callbacks(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+
+	return 0;
+
+err:
+	if (reg_vbus)
+		regulator_disable(reg_vbus);
+put_np:
+	if (phy_np)
+		of_node_put(phy_np);
+	return ret;
+}
+
+static int __devexit ci13xxx_imx_remove(struct platform_device *pdev)
+{
+	struct ci13xxx_imx_data *data = platform_get_drvdata(pdev);
+
+	ci13xxx_remove_device(data->ci_pdev);
+
+	if (data->reg_vbus)
+		regulator_disable(data->reg_vbus);
+
+	if (data->phy) {
+		usb_phy_shutdown(data->phy);
+		module_put(data->phy->dev->driver->owner);
+	}
+
+	of_node_put(data->phy_np);
+
+	clk_disable_unprepare(data->clk);
+
+	platform_set_drvdata(pdev, NULL);
+
+	return 0;
+}
+
+static const struct of_device_id ci13xxx_imx_dt_ids[] = {
+	{ .compatible = "fsl,imx31-usb", },
+	{ /* sentinel */ }
+};
+
+static struct platform_driver ci13xxx_imx_driver = {
+	.probe = ci13xxx_imx_probe,
+	.remove = __devexit_p(ci13xxx_imx_remove),
+	.driver = {
+		.name = "imx_usb",
+		.owner = THIS_MODULE,
+		.of_match_table = ci13xxx_imx_dt_ids,
+	 },
+};
+
+module_platform_driver(ci13xxx_imx_driver);
+
+MODULE_ALIAS("platform:imx-usb");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("CI13xxx i.MX USB binding");
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
+MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
-- 
1.7.5.4

  parent reply	other threads:[~2012-05-25  2:24 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-25  2:24 [PATCH v3 00/12] add imx usb driver for mx28/6x Richard Zhao
2012-05-25  2:24 ` [PATCH v3 01/12] usb: otg: add notify_connect/notify_disconnect callback Richard Zhao
2012-06-06  8:49   ` Felipe Balbi
2012-05-25  2:24 ` [PATCH v3 02/12] usb: chipidea: permit driver bindings pass phy pointer Richard Zhao
2012-06-06  8:50   ` Felipe Balbi
2012-06-08 12:37   ` [PATCH v4] " Richard Zhao
2012-06-12 23:14     ` Greg KH
2012-06-13  6:23       ` Richard Zhao
2012-06-14  7:52       ` Alexander Shishkin
2012-06-14 15:46         ` Greg KH
2012-06-15  2:46           ` Richard Zhao
2012-06-21  5:50             ` Richard Zhao
2012-06-21  6:44               ` Alexander Shishkin
2012-05-25  2:24 ` [PATCH v3 03/12] usb: ehci-hcd: notify phy when connect change Richard Zhao
2012-06-05 14:00   ` Alexander Shishkin
2012-06-05 14:28     ` Alan Stern
2012-06-05 15:03       ` Marek Vasut
2012-06-05 16:56         ` Alan Stern
2012-06-05 17:23           ` Marek Vasut
2012-06-05 17:30             ` Alan Stern
2012-06-06  1:27               ` Richard Zhao
2012-06-06  8:28         ` Alexander Shishkin
2012-06-06  1:29   ` [PATCH v4] " Richard Zhao
2012-06-06  9:39     ` Alexander Shishkin
2012-06-06 11:05       ` Richard Zhao
2012-06-06 11:27         ` Alexander Shishkin
2012-06-06 14:19     ` Alan Stern
2012-06-07  2:04       ` Chen Peter-B29397
2012-06-07  2:43         ` Richard Zhao
2012-06-07  3:14           ` Chen Peter-B29397
2012-06-08 12:32     ` [PATCH 1/2] USB: move transceiver from ehci_hcd and ohci_hcd to hcd and rename it as phy Richard Zhao
2012-06-08 12:32       ` [PATCH v5 2/2] USB: notify phy when root hub port connect change Richard Zhao
2012-05-25  2:24 ` [PATCH v3 04/12] usb: otg: add basic mxs phy driver support Richard Zhao
2012-06-06  8:51   ` Felipe Balbi
2012-05-25  2:24 ` Richard Zhao [this message]
2012-05-25  8:37   ` [PATCH v3 05/12] usb: chipidea: add imx platform driver Alexander Shishkin
2012-05-25  8:51     ` Richard Zhao
2012-05-25  9:49       ` Alexander Shishkin
2012-05-29  3:05         ` Richard Zhao
2012-06-05 14:25           ` Alexander Shishkin
2012-05-25  2:24 ` [PATCH v3 06/12] ARM: imx6q: correct device name of usbphy and usb controller clock export Richard Zhao
2012-05-25  2:24 ` [PATCH v3 07/12] ARM: imx6q: add config-on-boot gpios Richard Zhao
2012-05-25  2:24 ` [PATCH v3 08/12] ARM: imx6q: add usbphy clocks Richard Zhao
2012-05-25  2:24 ` [PATCH v3 09/12] ARM: imx6q: disable usb charger detector Richard Zhao
2012-05-25  2:24 ` [PATCH v3 10/12] ARM: dts: imx6q-sabrelite: add usb devices Richard Zhao
2012-05-25  2:24 ` [PATCH v3 11/12] ARM: mxs: clk_register_clkdev mx28 usb clocks Richard Zhao
2012-05-25  2:24 ` [PATCH v3 12/12] ARM: dts: imx28-evk: add usb devices Richard Zhao
2012-05-26 11:37 ` [PATCH v3 00/12] add imx usb driver for mx28/6x Marek Vasut
2012-05-26 12:50   ` Richard Zhao
2012-06-04  0:46 ` Richard Zhao
2012-06-04 15:00   ` Felipe Balbi
2012-06-04 17:16     ` Marek Vasut
2012-06-04 18:58   ` Alexander Shishkin
2012-06-05 15:02 ` Felipe Balbi
2012-06-06  2:27   ` Shawn Guo
2012-06-06  6:03     ` Felipe Balbi
2012-06-06  6:27       ` Shawn Guo
2012-06-06  6:30       ` Richard Zhao
2012-06-06  8:39         ` Alexander Shishkin
2012-06-06 13:20         ` Alexander Shishkin

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=1337912665-16615-6-git-send-email-richard.zhao@freescale.com \
    --to=richard.zhao@freescale.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).