linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Konstantin Baydarov <kbaidarov@dev.rtsoft.ru>
To: b-cousson@ti.com, kishon@ti.com, kbaidarov@dev.rtsoft.ru,
	santosh.shilimkar@ti.com, tony@atomide.com, paul@pwsan.com
Cc: balbi@ti.com, amit.kucheria@linaro.org,
	linux-pm@lists.linux-foundation.org,
	linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org,
	amit.kachhap@linaro.org,
	Eduardo Valentin <eduardo.valentin@ti.com>
Subject: [RFC PATCH v2 05/11] mfd: omap: control: usb-phy: introduce the ctrl-module usb driver
Date: Mon, 18 Jun 2012 15:32:26 +0400	[thread overview]
Message-ID: <4FDF11CA.4040009@dev.rtsoft.ru> (raw)
In-Reply-To: <1337934361-1606-1-git-send-email-eduardo.valentin@ti.com>

Created a new platform driver for the platform device created by the
control module mfd core, wrt usb. This driver has API's to power on/off
the phy and the API's to write to musb mailbox.

Changes since previous version:
- Bandgap and usb phy: drivers are now independent from control module driver, they use their own API functions.
Dependency was removed from Kconfig.
- Bandgap and usb phy: Added private spinlocks for bandgap and usb drivers.

(p.s. the mailbox for musb in omap4 is present in system control
module)

[kishon@ti.com: wrote the original API's related to USB functions]
Signed-off-by: Konstantin Baydarov <kbaidarov@dev.rtsoft.ru>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>
---
 drivers/usb/otg/Kconfig           |   12 ++
 drivers/usb/otg/Makefile          |    1 
 drivers/usb/otg/omap4-usb-phy.c   |  167 ++++++++++++++++++++++++++++++++++++++
 include/linux/usb/omap4_usb_phy.h |   53 ++++++++++++
 4 files changed, 233 insertions(+)

Index: linux-2.6/drivers/usb/otg/Kconfig
===================================================================
--- linux-2.6.orig/drivers/usb/otg/Kconfig
+++ linux-2.6/drivers/usb/otg/Kconfig
@@ -78,6 +78,18 @@ config TWL6030_USB
 	  are hooked to this driver through platform_data structure.
 	  The definition of internal PHY APIs are in the mach-omap2 layer.
 
+config OMAP4_USB_PHY
+	tristate "Texas Instruments OMAP4+ USB pin control driver"
+	help
+	  If you say yes here you get support for the Texas Instruments
+	  OMAP4+ USB pin control driver. The register set is part of system
+	  control module.
+
+	  USB phy in OMAP configures control module register for powering on
+	  the phy, configuring VBUSVALID, AVALID, IDDIG and SESSEND. For
+	  performing the above mentioned configuration, API's are added in
+	  by this children of the control module driver.
+
 config NOP_USB_XCEIV
 	tristate "NOP USB Transceiver Driver"
 	select USB_OTG_UTILS
Index: linux-2.6/drivers/usb/otg/Makefile
===================================================================
--- linux-2.6.orig/drivers/usb/otg/Makefile
+++ linux-2.6/drivers/usb/otg/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_USB_GPIO_VBUS)	+= gpio_vbus
 obj-$(CONFIG_ISP1301_OMAP)	+= isp1301_omap.o
 obj-$(CONFIG_TWL4030_USB)	+= twl4030-usb.o
 obj-$(CONFIG_TWL6030_USB)	+= twl6030-usb.o
+obj-$(CONFIG_OMAP4_USB_PHY)	+= omap4-usb-phy.o
 obj-$(CONFIG_NOP_USB_XCEIV)	+= nop-usb-xceiv.o
 obj-$(CONFIG_USB_ULPI)		+= ulpi.o
 obj-$(CONFIG_USB_ULPI_VIEWPORT)	+= ulpi_viewport.o
Index: linux-2.6/drivers/usb/otg/omap4-usb-phy.c
===================================================================
--- /dev/null
+++ linux-2.6/drivers/usb/otg/omap4-usb-phy.c
@@ -0,0 +1,167 @@
+/*
+ * OMAP4 system control module driver, USB control children
+ *
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Contact:
+ *    Kishon Vijay Abraham I <kishon@ti.com>
+ *    Eduardo Valentin <eduardo.valentin@ti.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.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/usb/omap4_usb_phy.h>
+
+void __iomem *omap_usb_phy_base;
+spinlock_t omap_usb_phy_lock;
+
+static int omap_usb_phy_readl(u32 reg, u32 *val)
+{
+	if (!omap_usb_phy_base)
+		return -EINVAL;
+
+	*val = __raw_readl(omap_usb_phy_base + reg);
+	return 0;
+}
+
+/*
+ * TODO: Get rid from omap_usb_phy_writel() return value -
+ * It's useless.
+ */
+static int omap_usb_phy_writel(u32 val, u32 reg)
+{
+	unsigned long flags;
+
+	if (!omap_usb_phy_base)
+		return -EINVAL;
+
+	spin_lock_irqsave(&omap_usb_phy_lock, flags);
+	__raw_writel(val, omap_usb_phy_base + reg);
+	spin_unlock_irqrestore(&omap_usb_phy_lock, flags);
+	return 0;
+}
+
+/**
+ * omap4_usb_phy_power - power on/off the phy using control module reg
+ * @dev: struct device *
+ * @on: 0 or 1, based on powering on or off the PHY
+ *
+ * omap_usb2 can call this API to power on or off the PHY.
+ */
+int omap4_usb_phy_power(struct device *dev, int on)
+{
+	u32 val;
+	int ret;
+
+	if (on) {
+		ret = omap_usb_phy_readl(CONTROL_DEV_CONF, &val);
+		if (!ret && (val & PHY_PD)) {
+			ret = omap_usb_phy_writel(~PHY_PD,
+						  CONTROL_DEV_CONF);
+			/* XXX: add proper documentation for this delay */
+			mdelay(200);
+		}
+	} else
+		ret = omap_usb_phy_writel(PHY_PD, CONTROL_DEV_CONF);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(omap4_usb_phy_power);
+
+/**
+ * omap4_usb_phy_mailbox - write to usb otg mailbox
+ * @dev: struct device *
+ * @val: the value to be written to the mailbox
+ *
+ * On detection of a device (ID pin is grounded), the phy should call this API
+ * to set AVALID, VBUSVALID and ID pin is grounded.
+ *
+ * When OMAP is connected to a host (OMAP in device mode), the phy should call
+ * this API to set AVALID, VBUSVALID and ID pin in high impedance.
+ *
+ * The phy should call this API, if OMAP is disconnected from host or device.
+ */
+int omap4_usb_phy_mailbox(struct device *dev, u32 val)
+{
+	return omap_usb_phy_writel(val, CONTROL_USBOTGHS_CONTROL);
+}
+EXPORT_SYMBOL_GPL(omap4_usb_phy_mailbox);
+
+static int __devinit omap_usb_phy_probe(struct platform_device *pdev)
+{
+	struct resource *io_res;
+
+//	printk("\n\t\t **** omap_usb_phy_probe(): enter ");
+
+	io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!io_res)
+		return -ENOENT;
+
+//	printk("\n\t\t **** omap_usb_phy_probe(): start %x ", io_res->start);
+//	printk("\n\t\t **** omap_usb_phy_probe(): size %x ", resource_size(io_res));
+	omap_usb_phy_base = ioremap(io_res->start, resource_size(io_res));
+//	printk("\n\t\t **** omap_usb_phy_probe(): omap_usb_phy_base %x ", omap_usb_phy_base);
+	if (!omap_usb_phy_base)
+		return -ENOMEM;
+
+	/* Initialize register lock */
+	spin_lock_init(&omap_usb_phy_lock);
+
+	return 0;
+}
+
+static int __devexit omap_usb_phy_remove(struct platform_device *pdev)
+{
+	return 0;
+}
+
+static const struct of_device_id of_omap_usb_phy_match[] = {
+	{ .compatible = "ti,omap4-usb-phy", },
+	{ },
+};
+
+static struct platform_driver omap_usb_phy_driver = {
+	.probe = omap_usb_phy_probe,
+	.remove = __devexit_p(omap_usb_phy_remove),
+	.driver = {
+			.name	= "omap4-usb-phy",
+			.owner	= THIS_MODULE,
+			.of_match_table	= of_omap_usb_phy_match,
+	},
+};
+
+static int __init omap_usb_phy_init(void)
+{
+	return platform_driver_register(&omap_usb_phy_driver);
+}
+postcore_initcall(omap_usb_phy_init);
+
+static void __exit omap_usb_phy_exit(void)
+{
+	platform_driver_unregister(&omap_usb_phy_driver);
+}
+module_exit(omap_usb_phy_exit);
+
+MODULE_DESCRIPTION("OMAP4+ USB-phy driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform: omap4-usb-phy");
+MODULE_AUTHOR("Texas Instrument Inc.");
Index: linux-2.6/include/linux/usb/omap4_usb_phy.h
===================================================================
--- /dev/null
+++ linux-2.6/include/linux/usb/omap4_usb_phy.h
@@ -0,0 +1,53 @@
+/*
+ * OMAP4 USB-phy
+ *
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Contact:
+ *    Kishon Vijay Abraham I <kishon@ti.com>
+ *    Eduardo Valentin <eduardo.valentin@ti.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.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __OMAP4_USB_PHY_H
+#define __OMAP4_USB_PHY_H
+
+#define	PHY_PD				0x1
+#define	AVALID				BIT(0)
+#define	BVALID				BIT(1)
+#define	VBUSVALID			BIT(2)
+#define	SESSEND				BIT(3)
+#define	IDDIG				BIT(4)
+#define	CONTROL_DEV_CONF		0x00000300
+#define	CONTROL_USBOTGHS_CONTROL	0x0000033C
+
+/* USB-PHY helpers */
+#if (defined(CONFIG_OMAP4_USB_PHY)) || (defined(CONFIG_OMAP4_USB_PHY_MODULE))
+extern int omap4_usb_phy_mailbox(struct device *dev, u32 val);
+extern int omap4_usb_phy_power(struct device *dev, int on);
+#else
+static inline int omap4_usb_phy_mailbox(struct device *dev, u32 val)
+{
+	return 0;
+}
+static inline int omap4_usb_phy_power(struct device *dev, int on)
+{
+	return 0;
+}
+#endif
+
+#endif

  parent reply	other threads:[~2012-06-18 11:32 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-25  8:25 [RFC PATCH 00/11] OMAP System Control Module Eduardo Valentin
2012-05-25  8:25 ` [RFC PATCH 01/11] ARM: OMAP4: Remove un-used control module headers and defines Eduardo Valentin
2012-05-28  9:12   ` Shilimkar, Santosh
2012-05-25  8:25 ` [RFC PATCH 02/11] ARM: OMAP: expose control.h to mach area Eduardo Valentin
2012-05-28  9:25   ` Shilimkar, Santosh
2012-05-28 10:30     ` Valentin, Eduardo
2012-06-01 11:19       ` Tony Lindgren
2012-05-25  8:25 ` [RFC PATCH 03/11] arm: omap: device: create a device for system control module Eduardo Valentin
2012-05-25 12:30   ` Cousson, Benoit
2012-05-29  9:44     ` Eduardo Valentin
2012-06-14 13:50       ` Konstantin Baydarov
2012-06-15  9:22         ` Valentin, Eduardo
2012-05-29 13:39   ` Konstantin Baydarov
2012-05-25  8:25 ` [RFC PATCH 04/11] OMAP: Add early " Eduardo Valentin
2012-05-25 11:32   ` Konstantin Baydarov
2012-05-25 11:44     ` Valentin, Eduardo
2012-05-25 11:54   ` Konstantin Baydarov
2012-05-25 12:32   ` Cousson, Benoit
2012-05-28  9:58   ` Shilimkar, Santosh
2012-05-25  8:25 ` [RFC PATCH 05/11] mfd: omap: control: core system control driver Eduardo Valentin
2012-05-25 12:52   ` Cousson, Benoit
2012-05-28 11:35     ` Eduardo Valentin
2012-05-29 13:25       ` Cousson, Benoit
2012-06-01 11:29         ` Tony Lindgren
2012-06-01 12:30           ` Shilimkar, Santosh
2012-06-01 12:43             ` Cousson, Benoit
2012-06-01 17:19               ` Eduardo Valentin
2012-06-01 13:40           ` Konstantin Baydarov
2012-06-01 14:13             ` Tony Lindgren
2012-06-01 14:26               ` Konstantin Baydarov
2012-05-28  9:54   ` Shilimkar, Santosh
2012-05-28 11:42     ` Eduardo Valentin
2012-05-28 13:15       ` Shilimkar, Santosh
2012-05-29 13:31         ` Cousson, Benoit
2012-05-25  8:25 ` [RFC PATCH 06/11] OMAP2+: use control module mfd driver in omap_type Eduardo Valentin
2012-05-25 12:53   ` Cousson, Benoit
2012-05-28 10:02     ` Shilimkar, Santosh
2012-05-28 11:24       ` Eduardo Valentin
2012-06-01 11:35         ` Tony Lindgren
2012-05-25  8:25 ` [RFC PATCH 07/11] mfd: omap: control: usb-phy: introduce the ctrl-module usb driver Eduardo Valentin
2012-05-25 13:35   ` Shubhrajyoti Datta
2012-05-25 15:06   ` Cousson, Benoit
2012-06-01 11:38   ` Tony Lindgren
2012-06-01 13:20     ` [linux-pm] " Tony Lindgren
2012-06-01 14:07       ` Kevin Hilman
2012-06-01 14:15         ` Tony Lindgren
2012-05-25  8:25 ` [RFC PATCH 08/11] ARM: OMAP4+: Adding the temperature sensor register set bit fields Eduardo Valentin
2012-05-25 15:13   ` Cousson, Benoit
2012-05-28 11:17     ` Eduardo Valentin
2012-05-28 10:04   ` Shilimkar, Santosh
2012-05-28 11:18     ` Eduardo Valentin
2012-05-25  8:25 ` [RFC PATCH 09/11] ARM: OMAP4+: thermal: introduce bandgap temperature sensor Eduardo Valentin
2012-05-25 15:49   ` Cousson, Benoit
2012-05-28 11:06     ` Eduardo Valentin
2012-05-28 11:16     ` Eduardo Valentin
2012-05-29 13:14       ` Cousson, Benoit
2012-05-29 17:51         ` Mike Turquette
2012-05-25 16:39   ` Konstantin Baydarov
2012-05-28 10:55     ` Eduardo Valentin
2012-06-01 11:42   ` Tony Lindgren
2012-05-25  8:26 ` [RFC PATCH 10/11] omap4: thermal: add basic CPU thermal zone Eduardo Valentin
2012-05-28  9:33   ` Shilimkar, Santosh
2012-05-28  9:48     ` Felipe Balbi
2012-05-28 10:26       ` Valentin, Eduardo
2012-05-29 12:54         ` Cousson, Benoit
2012-05-25  8:26 ` [RFC PATCH 11/11] ARM: DT: Add support to system control module for OMAP4 Eduardo Valentin
2012-05-29  9:49   ` Konstantin Baydarov
2012-05-30  8:38     ` Cousson, Benoit
2012-05-30  9:05       ` Konstantin Baydarov
2012-05-30  9:26         ` Cousson, Benoit
2012-05-30 10:17           ` Konstantin Baydarov
2012-05-30 10:22             ` Cousson, Benoit
2012-05-30 10:42               ` Eduardo Valentin
2012-05-30 12:16                 ` Cousson, Benoit
2012-05-31 12:06           ` Konstantin Baydarov
2012-05-31 12:49             ` Eduardo Valentin
2012-05-31 12:52               ` Cousson, Benoit
2012-05-31 14:51                 ` Konstantin Baydarov
2012-05-25  8:35 ` [RFC PATCH 00/11] OMAP System Control Module Eduardo Valentin
2012-05-25 10:50 ` Konstantin Baydarov
2012-05-25 11:11   ` Valentin, Eduardo
2012-05-25 12:21     ` Konstantin Baydarov
2012-06-01  0:12 ` [linux-pm] " Kevin Hilman
2012-06-18 11:32 ` [RFC PATCH v2 01/11] ARM: OMAP4: Remove un-used control module headers and defines Konstantin Baydarov
2012-06-18 11:32 ` [RFC PATCH v2 02/11] ARM: OMAP: expose control.h to mach area Konstantin Baydarov
2012-06-20 10:17   ` Tony Lindgren
2012-06-18 11:32 ` [RFC PATCH v2 03/11] mfd: omap: control: core system control driver Konstantin Baydarov
2012-06-20 10:22   ` Tony Lindgren
2012-06-20 14:13     ` Konstantin Baydarov
2012-06-26 11:17       ` Tony Lindgren
2012-06-18 11:32 ` [RFC PATCH v2 04/11] OMAP2+: use control module mfd driver in omap_type Konstantin Baydarov
2012-06-20 10:24   ` Tony Lindgren
2012-06-18 11:32 ` Konstantin Baydarov [this message]
2012-06-18 11:32 ` [RFC PATCH v2 06/11] ARM: OMAP4+: Adding the temperature sensor register set bit fields Konstantin Baydarov
2012-06-20 10:25   ` Tony Lindgren
2012-06-18 11:32 ` [RFC PATCH v2 07/11] ARM: OMAP4+: thermal: introduce bandgap temperature sensor Konstantin Baydarov
2012-06-18 11:32 ` [RFC PATCH v2 08/11] omap4: thermal: add basic CPU thermal zone Konstantin Baydarov
2012-06-18 11:32 ` [RFC PATCH v2 09/11] ARM: DT: Add support to system control module for OMAP4 Konstantin Baydarov
2012-06-18 12:13   ` Sergei Shtylyov

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=4FDF11CA.4040009@dev.rtsoft.ru \
    --to=kbaidarov@dev.rtsoft.ru \
    --cc=amit.kachhap@linaro.org \
    --cc=amit.kucheria@linaro.org \
    --cc=b-cousson@ti.com \
    --cc=balbi@ti.com \
    --cc=eduardo.valentin@ti.com \
    --cc=kishon@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=paul@pwsan.com \
    --cc=santosh.shilimkar@ti.com \
    --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
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).