Linux-OMAP Archive on lore.kernel.org
 help / color / Atom feed
From: Aaro Koskinen <aaro.koskinen@iki.fi>
To: linux-usb@vger.kernel.org, linux-omap@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, Felipe Balbi <balbi@ti.com>,
	Tony Lindgren <tony@atomide.com>
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>
Subject: [PATCH 2/3] USB: OMAP: add omap-otg
Date: Mon, 10 Jun 2013 01:40:05 +0300
Message-ID: <1370817606-1008-3-git-send-email-aaro.koskinen@iki.fi> (raw)
In-Reply-To: <1370817606-1008-1-git-send-email-aaro.koskinen@iki.fi>

Transceivers need to manage OTG controller state on OMAP1 to enable
switching between peripheral and host modes. Provide a driver for that.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
---
 drivers/usb/phy/Kconfig        |   10 ++++
 drivers/usb/phy/Makefile       |    1 +
 drivers/usb/phy/phy-omap-otg.c |  126 ++++++++++++++++++++++++++++++++++++++++
 include/linux/usb/omap-otg.h   |   19 ++++++
 4 files changed, 156 insertions(+)
 create mode 100644 drivers/usb/phy/phy-omap-otg.c
 create mode 100644 include/linux/usb/omap-otg.h

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index 7ef3eb8..2d2cd5f 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -135,6 +135,16 @@ config USB_GPIO_VBUS
 	  optionally control of a D+ pullup GPIO as well as a VBUS
 	  current limit regulator.
 
+config OMAP_OTG
+	tristate "OMAP USB OTG controller driver"
+	depends on ARCH_OMAP_OTG
+	help
+	  Enable this to support some transceivers on OMAP1 platforms. OTG
+	  controller is needed to switch between host and peripheral modes.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called omap-otg.
+
 config USB_ISP1301
 	tristate "NXP ISP1301 USB transceiver support"
 	depends on USB || USB_GADGET
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index a9169cb..c7f391b 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_ISP1301_OMAP)		+= phy-isp1301-omap.o
 obj-$(CONFIG_MV_U3D_PHY)		+= phy-mv-u3d-usb.o
 obj-$(CONFIG_NOP_USB_XCEIV)		+= phy-nop.o
 obj-$(CONFIG_OMAP_CONTROL_USB)		+= phy-omap-control.o
+obj-$(CONFIG_OMAP_OTG)			+= phy-omap-otg.o
 obj-$(CONFIG_OMAP_USB2)			+= phy-omap-usb2.o
 obj-$(CONFIG_OMAP_USB3)			+= phy-omap-usb3.o
 obj-$(CONFIG_SAMSUNG_USBPHY)		+= phy-samsung-usb.o
diff --git a/drivers/usb/phy/phy-omap-otg.c b/drivers/usb/phy/phy-omap-otg.c
new file mode 100644
index 0000000..cb00ffe
--- /dev/null
+++ b/drivers/usb/phy/phy-omap-otg.c
@@ -0,0 +1,126 @@
+/*
+ * OMAP OTG controller driver
+ *
+ * Based on code from tahvo-usb.c and isp1301_omap.c drivers.
+ *
+ * Copyright (C) 2005-2006 Nokia Corporation
+ * Copyright (C) 2004 Texas Instruments
+ * Copyright (C) 2004 David Brownell
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/io.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/usb/omap-otg.h>
+#include <linux/platform_device.h>
+
+struct otg_device {
+	void __iomem	*base;
+	struct mutex	serialize;
+};
+static struct otg_device *otg_dev;
+
+#define OMAP_OTG_CTRL		(otg_dev->base + 0x0c)
+#define OMAP_OTG_ASESSVLD	(1 << 20)
+#define OMAP_OTG_BSESSEND	(1 << 19)
+#define OMAP_OTG_BSESSVLD	(1 << 18)
+#define OMAP_OTG_VBUSVLD	(1 << 17)
+#define OMAP_OTG_ID		(1 << 16)
+#define OMAP_OTG_XCEIV_OUTPUTS \
+	(OMAP_OTG_ASESSVLD | OMAP_OTG_BSESSEND | OMAP_OTG_BSESSVLD | \
+	 OMAP_OTG_VBUSVLD  | OMAP_OTG_ID)
+
+static void omap_otg_ctrl(u32 outputs)
+{
+	u32 l;
+
+	l = readl(OMAP_OTG_CTRL);
+	l &= ~OMAP_OTG_XCEIV_OUTPUTS;
+	l |= outputs;
+	writel(l, OMAP_OTG_CTRL);
+}
+
+void omap_otg_set_mode(enum omap_otg_mode mode)
+{
+	if (!otg_dev) {
+		WARN(1, "%s: controller not present\n", __func__);
+		return;
+	}
+	mutex_lock(&otg_dev->serialize);
+	switch (mode) {
+	case OMAP_OTG_MODE_DEVICE:
+		/*
+		 * Set B-session valid.
+		 */
+		omap_otg_ctrl(OMAP_OTG_ID | OMAP_OTG_BSESSVLD);
+		break;
+	case OMAP_OTG_MODE_HOST:
+		/*
+		 * Set A-session valid.
+		 */
+		omap_otg_ctrl(OMAP_OTG_ASESSVLD);
+		break;
+	case OMAP_OTG_MODE_DISCONNECT:
+		/*
+		 * Set B-session end to indicate no VBUS.
+		 */
+		omap_otg_ctrl(OMAP_OTG_ID | OMAP_OTG_BSESSEND);
+		break;
+	default:
+		WARN(1, "%s: unknown mode: %d\n", __func__, mode);
+	}
+	mutex_unlock(&otg_dev->serialize);
+}
+EXPORT_SYMBOL_GPL(omap_otg_set_mode);
+
+static int omap_otg_probe(struct platform_device *dev)
+{
+	struct otg_device *odev;
+	u32 rev;
+
+	if (otg_dev)
+		return -EBUSY;
+
+	odev = devm_kzalloc(&dev->dev, sizeof(*odev), GFP_KERNEL);
+	if (!odev)
+		return -ENOMEM;
+
+	odev->base = devm_ioremap_resource(&dev->dev, &dev->resource[0]);
+	if (IS_ERR(odev->base))
+		return PTR_ERR(odev->base);
+
+	rev = readl(odev->base);
+	dev_info(&dev->dev, "OMAP USB OTG controller rev %d.%d\n",
+		 (rev >> 4) & 0xf, rev & 0xf);
+
+	mutex_init(&odev->serialize);
+
+	otg_dev = odev;
+
+	return 0;
+}
+
+static struct platform_driver omap_otg_driver = {
+	.probe		= omap_otg_probe,
+	.driver		= {
+		.owner	= THIS_MODULE,
+		.name	= "omap_otg",
+	},
+};
+module_platform_driver(omap_otg_driver);
+
+MODULE_DESCRIPTION("OMAP USB OTG controller driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
diff --git a/include/linux/usb/omap-otg.h b/include/linux/usb/omap-otg.h
new file mode 100644
index 0000000..fb3d7ab
--- /dev/null
+++ b/include/linux/usb/omap-otg.h
@@ -0,0 +1,19 @@
+/*
+ * OMAP OTG driver
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive for
+ * more details.
+ */
+#ifndef __LINUX_OMAP_OTG_H
+#define __LINUX_OMAP_OTG_H
+
+enum omap_otg_mode {
+	OMAP_OTG_MODE_DEVICE,
+	OMAP_OTG_MODE_HOST,
+	OMAP_OTG_MODE_DISCONNECT,
+};
+
+void omap_otg_set_mode(enum omap_otg_mode mode);
+
+#endif /* __LINUX_OMAP_OTG_H */
-- 
1.7.10.4


  parent reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-09 22:40 [PATCH 0/3] USB: OMAP: Tahvo USB support for 770 Aaro Koskinen
2013-06-09 22:40 ` [PATCH 1/3] ARM: OMAP1: nokia770: enable Tahvo Aaro Koskinen
2013-06-09 22:40 ` Aaro Koskinen [this message]
     [not found]   ` <1370817606-1008-3-git-send-email-aaro.koskinen-X3B1VOXEql0@public.gmane.org>
2013-06-12 15:13     ` [PATCH 2/3] USB: OMAP: add omap-otg Felipe Balbi
2013-06-13 22:37       ` Aaro Koskinen
     [not found]         ` <20130613223711.GD18360-R3WNPi76c83LsdW6vOPryG4HOFkwEHDbMR2xtNvyitY@public.gmane.org>
2013-06-14  1:27           ` Felipe Balbi
2013-06-09 22:40 ` [PATCH 3/3] USB: OMAP: Tahvo USB transceiver driver Aaro Koskinen

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=1370817606-1008-3-git-send-email-aaro.koskinen@iki.fi \
    --to=aaro.koskinen@iki.fi \
    --cc=balbi@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=tony@atomide.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

Linux-OMAP Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-omap/0 linux-omap/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-omap linux-omap/ https://lore.kernel.org/linux-omap \
		linux-omap@vger.kernel.org
	public-inbox-index linux-omap

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-omap


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git