devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] usb: musb: add driver for control module
@ 2013-01-18  9:40 Kishon Vijay Abraham I
  2013-01-18  9:40 ` [PATCH 1/4] drivers: usb: phy: add a new driver for usb part of " Kishon Vijay Abraham I
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-18  9:40 UTC (permalink / raw)
  To: rob.herring-bsGFqQB8/DxBDgjK7y7TUQ, rob-VoJi6FS/r0vR7s880joybQ,
	tony-4v6yS6AI5VpBDgjK7y7TUQ, balbi-l0cyMroinI0,
	b-cousson-l0cyMroinI0, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-doc-u79uwXL29TY76Z2rM5mHXA,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-lFZ/pmaqli7XmaaqVzeoHQ, kishon-l0cyMroinI0

Added a new driver for the usb part of control module. This has an API
to power on the USB2 phy and an API to write to the mailbox depending on
whether MUSB has to act in host mode or in device mode.

Writing to control module registers for doing the above task which was
previously done in omap glue and in omap-usb2 phy is removed.

Changes from RFC:
* Used "#if IS_ENABLED(CONFIG_OMAP_CONTROL_USB)" instead of 
  "#if (defined(CONFIG_OMAP_CONTROL_USB) || \
				defined(CONFIG_OMAP_CONTROL_USB_MODULE))"

* return "-EADDRNOTAVAIL" if devm_request_and_ioremap fails.

* Removed the dt data from this patch series (I'll send that as a separate
series).

* added "ctrl_module" binding to usb otg glue and usb phy in the Documentaion.
  This binding is not planned to be used until an actual requirement for
  it arises.

This series was developed on
git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git xceiv

Did basic enumeration testing in omap4 panda, omap4 sdp and omap3 beagle.

Kishon Vijay Abraham I (4):
  drivers: usb: phy: add a new driver for usb part of control module
  ARM: OMAP: devices: create device for usb part of control module
  ARM: OMAP2: MUSB: Specify omap4 has mailbox
  drivers: usb: start using the control module driver

 Documentation/devicetree/bindings/usb/omap-usb.txt |   30 ++-
 Documentation/devicetree/bindings/usb/usb-phy.txt  |   12 +-
 arch/arm/mach-omap2/devices.c                      |   48 +++++
 arch/arm/mach-omap2/omap_hwmod_44xx_data.c         |   13 --
 arch/arm/mach-omap2/usb-musb.c                     |    3 +
 drivers/usb/musb/Kconfig                           |    1 +
 drivers/usb/musb/omap2430.c                        |   64 +++---
 drivers/usb/musb/omap2430.h                        |    9 -
 drivers/usb/phy/Kconfig                            |   10 +
 drivers/usb/phy/Makefile                           |    1 +
 drivers/usb/phy/omap-control-usb.c                 |  204 ++++++++++++++++++++
 drivers/usb/phy/omap-usb2.c                        |   38 +---
 include/linux/usb/musb.h                           |    2 +
 include/linux/usb/omap_control_usb.h               |   72 +++++++
 include/linux/usb/omap_usb.h                       |    4 +-
 15 files changed, 411 insertions(+), 100 deletions(-)
 create mode 100644 drivers/usb/phy/omap-control-usb.c
 create mode 100644 include/linux/usb/omap_control_usb.h

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/4] drivers: usb: phy: add a new driver for usb part of control module
  2013-01-18  9:40 [PATCH 0/4] usb: musb: add driver for control module Kishon Vijay Abraham I
@ 2013-01-18  9:40 ` Kishon Vijay Abraham I
       [not found]   ` <1358502045-27008-2-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
       [not found] ` <1358502045-27008-1-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
  2013-01-18  9:40 ` [PATCH 3/4] ARM: OMAP2: MUSB: Specify omap4 has mailbox Kishon Vijay Abraham I
  2 siblings, 1 reply; 11+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-18  9:40 UTC (permalink / raw)
  To: rob.herring, rob, tony, balbi, b-cousson, linux-usb,
	linux-arm-kernel, linux-omap, linux-kernel, linux-doc,
	devicetree-discuss
  Cc: grant.likely, linux, gregkh, kishon

Added a new driver for the usb part of control module. This has an API
to power on the USB2 phy and an API to write to the mailbox depending on
whether MUSB has to act in host mode or in device mode.

Writing to control module registers for doing the above task which was
previously done in omap glue and in omap-usb2 phy will be removed.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 Documentation/devicetree/bindings/usb/omap-usb.txt |   26 ++-
 Documentation/devicetree/bindings/usb/usb-phy.txt  |    5 +
 drivers/usb/phy/Kconfig                            |    9 +
 drivers/usb/phy/Makefile                           |    1 +
 drivers/usb/phy/omap-control-usb.c                 |  204 ++++++++++++++++++++
 include/linux/usb/omap_control_usb.h               |   72 +++++++
 6 files changed, 316 insertions(+), 1 deletion(-)
 create mode 100644 drivers/usb/phy/omap-control-usb.c
 create mode 100644 include/linux/usb/omap_control_usb.h

diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
index 29a043e..ead6ba9 100644
--- a/Documentation/devicetree/bindings/usb/omap-usb.txt
+++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
@@ -1,4 +1,4 @@
-OMAP GLUE
+OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS
 
 OMAP MUSB GLUE
  - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"
@@ -16,6 +16,10 @@ OMAP MUSB GLUE
  - power : Should be "50". This signifies the controller can supply upto
    100mA when operating in host mode.
 
+Optional properties:
+ - ctrl_module : phandle of the control module this glue uses to write to
+   mailbox
+
 SOC specific device node entry
 usb_otg_hs: usb_otg_hs@4a0ab000 {
 	compatible = "ti,omap4-musb";
@@ -23,6 +27,7 @@ usb_otg_hs: usb_otg_hs@4a0ab000 {
 	multipoint = <1>;
 	num_eps = <16>;
 	ram_bits = <12>;
+	ctrl_module = <&omap_control_usb>;
 };
 
 Board specific device node entry
@@ -31,3 +36,22 @@ Board specific device node entry
 	mode = <3>;
 	power = <50>;
 };
+
+OMAP CONTROL USB
+
+Required properties:
+ - compatible: Should be "ti,omap-control-usb"
+ - reg : Address and length of the register set for the device. It contains
+   the address of "control_dev_conf" and "otghs_control".
+ - reg-names: The names of the register addresses corresponding to the registers
+   filled in "reg".
+ - ti,has_mailbox: This is used to specify if the platform has mailbox in
+   control module.
+
+omap_control_usb: omap-control-usb@4a002300 {
+	compatible = "ti,omap-control-usb";
+	reg = <0x4a002300 0x4>,
+	      <0x4a00233c 0x4>;
+	reg-names = "control_dev_conf", "otghs_control";
+	ti,has_mailbox;
+};
diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
index 80d4148..2466b6f 100644
--- a/Documentation/devicetree/bindings/usb/usb-phy.txt
+++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
@@ -8,10 +8,15 @@ Required properties:
 add the address of control module dev conf register until a driver for
 control module is added
 
+Optional properties:
+ - ctrl_module : phandle of the control module used by PHY driver to power on
+   the PHY.
+
 This is usually a subnode of ocp2scp to which it is connected.
 
 usb2phy@4a0ad080 {
 	compatible = "ti,omap-usb2";
 	reg = <0x4a0ad080 0x58>,
 	      <0x4a002300 0x4>;
+	ctrl_module = <&omap_control_usb>;
 };
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index 5de6e7f..a7277ee 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -14,6 +14,15 @@ config OMAP_USB2
 	  The USB OTG controller communicates with the comparator using this
 	  driver.
 
+config OMAP_CONTROL_USB
+	tristate "OMAP CONTROL USB Driver"
+	depends on ARCH_OMAP2PLUS
+	help
+	  Enable this to add support for the USB part present in the control
+	  module. This driver has API to power on the PHY and to write to the
+	  mailbox. The mailbox is present only in omap4 and the register to
+	  power on the PHY is present in omap4 and omap5.
+
 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 1a579a8..0dea4d2 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -5,6 +5,7 @@
 ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
 
 obj-$(CONFIG_OMAP_USB2)			+= omap-usb2.o
+obj-$(CONFIG_OMAP_CONTROL_USB)		+= omap-control-usb.o
 obj-$(CONFIG_USB_ISP1301)		+= isp1301.o
 obj-$(CONFIG_MV_U3D_PHY)		+= mv_u3d_phy.o
 obj-$(CONFIG_USB_EHCI_TEGRA)	+= tegra_usb_phy.o
diff --git a/drivers/usb/phy/omap-control-usb.c b/drivers/usb/phy/omap-control-usb.c
new file mode 100644
index 0000000..7edeb41
--- /dev/null
+++ b/drivers/usb/phy/omap-control-usb.c
@@ -0,0 +1,204 @@
+/*
+ * omap-control-usb.c - The USB part of control module.
+ *
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
+ * 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.
+ *
+ * Author: Kishon Vijay Abraham I <kishon@ti.com>
+ *
+ * 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/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/usb/omap_control_usb.h>
+
+static struct omap_control_usb *control_usb;
+
+/**
+ * get_omap_control_dev - returns the device pointer for this control device
+ *
+ * This API should be called to get the device pointer for this control
+ * module device. This device pointer should be passed to all other API's
+ * in this driver.
+ *
+ * To be used by PHY driver and glue driver
+ */
+struct device *get_omap_control_dev(void)
+{
+	if (!control_usb)
+		return ERR_PTR(-ENODEV);
+
+	return control_usb->dev;
+}
+EXPORT_SYMBOL_GPL(get_omap_control_dev);
+
+/**
+ * omap_control_usb_phy_power - power on/off the phy using control module reg
+ * @dev: the control module device
+ * @on: 0 or 1, based on powering on or off the PHY
+ */
+void omap_control_usb_phy_power(struct device *dev, int on)
+{
+	u32 val;
+	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
+
+	if (on) {
+		val = readl(control_usb->dev_conf);
+		if (val & PHY_PD)
+			writel(~PHY_PD, control_usb->dev_conf);
+	} else {
+		writel(PHY_PD, control_usb->dev_conf);
+	}
+}
+EXPORT_SYMBOL_GPL(omap_control_usb_phy_power);
+
+/**
+ * omap_control_usb_host_mode - set AVALID, VBUSVALID and ID pin in grounded
+ * @dev: struct device *
+ *
+ * This is an API to write to the mailbox register to notify the usb core that
+ * a usb device has been connected.
+ */
+void omap_control_usb_host_mode(struct device *dev)
+{
+	u32 val;
+	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
+
+	val = AVALID | VBUSVALID;
+
+	writel(val, control_usb->otghs_control);
+}
+EXPORT_SYMBOL_GPL(omap_control_usb_host_mode);
+
+/**
+ * omap_control_usb_device_mode - set AVALID, VBUSVALID and ID pin in high
+ * impedance
+ * @dev: struct device *
+ *
+ * This is an API to write to the mailbox register to notify the usb core that
+ * it has been connected to a usb host.
+ */
+void omap_control_usb_device_mode(struct device *dev)
+{
+	u32 val;
+	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
+
+	val = IDDIG | AVALID | VBUSVALID;
+
+	writel(val, control_usb->otghs_control);
+}
+EXPORT_SYMBOL_GPL(omap_control_usb_device_mode);
+
+/**
+ * omap_control_usb_set_sessionend - Enable SESSIONEND and IDIG to high
+ * impedance
+ * @dev: struct device *
+ *
+ * This is an API to write to the mailbox register to notify the usb core
+ * it's now in disconnected state.
+ */
+void omap_control_usb_set_sessionend(struct device *dev)
+{
+	u32 val;
+	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
+
+	val = SESSEND | IDDIG;
+
+	writel(val, control_usb->otghs_control);
+}
+EXPORT_SYMBOL_GPL(omap_control_usb_set_sessionend);
+
+static int omap_control_usb_probe(struct platform_device *pdev)
+{
+	struct resource	*res;
+	struct device_node *np = pdev->dev.of_node;
+	struct omap_control_usb_platform_data *pdata = pdev->dev.platform_data;
+
+	control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb),
+	    GFP_KERNEL);
+	if (!control_usb) {
+		dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
+		return -ENOMEM;
+	}
+
+	if (np) {
+		control_usb->has_mailbox = of_property_read_bool(np,
+		    "ti,has_mailbox");
+	} else if (pdata) {
+		control_usb->has_mailbox = pdata->has_mailbox;
+	} else {
+		dev_err(&pdev->dev, "no pdata present\n");
+		return -EINVAL;
+	}
+
+	control_usb->dev	= &pdev->dev;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+	    "control_dev_conf");
+	control_usb->dev_conf = devm_request_and_ioremap(&pdev->dev, res);
+	if (control_usb->dev_conf == NULL) {
+		dev_err(&pdev->dev, "Failed to obtain io memory\n");
+		return -EADDRNOTAVAIL;
+	}
+
+	if (control_usb->has_mailbox) {
+		res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+		    "otghs_control");
+		control_usb->otghs_control = devm_request_and_ioremap(
+		    &pdev->dev, res);
+		if (control_usb->otghs_control == NULL) {
+			dev_err(&pdev->dev, "Failed to obtain io memory\n");
+			return -EADDRNOTAVAIL;
+		}
+	}
+
+	dev_set_drvdata(control_usb->dev, control_usb);
+
+	return 0;
+}
+
+#ifdef CONFIG_OF
+static const struct of_device_id omap_control_usb_id_table[] = {
+	{ .compatible = "ti,omap-control-usb" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
+#endif
+
+static struct platform_driver omap_control_usb_driver = {
+	.probe		= omap_control_usb_probe,
+	.driver		= {
+		.name	= "omap-control-usb",
+		.owner	= THIS_MODULE,
+		.of_match_table = of_match_ptr(omap_control_usb_id_table),
+	},
+};
+
+static int __init omap_control_usb_init(void)
+{
+	return platform_driver_register(&omap_control_usb_driver);
+}
+subsys_initcall(omap_control_usb_init);
+
+static void __exit omap_control_usb_exit(void)
+{
+	platform_driver_unregister(&omap_control_usb_driver);
+}
+module_exit(omap_control_usb_exit);
+
+MODULE_ALIAS("platform: omap_control_usb");
+MODULE_AUTHOR("Texas Instruments Inc.");
+MODULE_DESCRIPTION("OMAP CONTROL USB DRIVER");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/usb/omap_control_usb.h b/include/linux/usb/omap_control_usb.h
new file mode 100644
index 0000000..a16f993
--- /dev/null
+++ b/include/linux/usb/omap_control_usb.h
@@ -0,0 +1,72 @@
+/*
+ * omap_control_usb.h - Header file for the USB part of control module.
+ *
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
+ * 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.
+ *
+ * Author: Kishon Vijay Abraham I <kishon@ti.com>
+ *
+ * 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.
+ *
+ */
+
+#ifndef __OMAP_CONTROL_USB_H__
+#define __OMAP_CONTROL_USB_H__
+
+struct omap_control_usb {
+	struct device *dev;
+
+	u32 __iomem *dev_conf;
+	u32 __iomem *otghs_control;
+
+	u8 has_mailbox:1;
+};
+
+struct omap_control_usb_platform_data {
+	u8 has_mailbox:1;
+};
+
+#define	PHY_PD		BIT(0)
+
+#define	AVALID		BIT(0)
+#define	BVALID		BIT(1)
+#define	VBUSVALID	BIT(2)
+#define	SESSEND		BIT(3)
+#define	IDDIG		BIT(4)
+
+#if IS_ENABLED(CONFIG_OMAP_CONTROL_USB)
+extern struct device *get_omap_control_dev(void);
+extern void omap_control_usb_phy_power(struct device *dev, int on);
+extern void omap_control_usb_host_mode(struct device *dev);
+extern void omap_control_usb_device_mode(struct device *dev);
+extern void omap_control_usb_set_sessionend(struct device *dev);
+#else
+static inline struct device *get_omap_control_dev()
+{
+	return ERR_PTR(-ENODEV);
+}
+
+static inline void omap_control_usb_phy_power(struct device *dev, int on)
+{
+}
+
+static inline void omap_control_usb_host_mode(struct device *dev)
+{
+}
+
+static inline void omap_control_usb_device_mode(struct device *dev)
+{
+}
+
+static inline void omap_control_usb_set_sessionend(struct device *dev)
+{
+}
+#endif
+
+#endif	/* __OMAP_CONTROL_USB_H__ */
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/4] ARM: OMAP: devices: create device for usb part of control module
       [not found] ` <1358502045-27008-1-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
@ 2013-01-18  9:40   ` Kishon Vijay Abraham I
       [not found]     ` <1358502045-27008-3-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
  2013-01-18  9:40   ` [PATCH 4/4] drivers: usb: start using the control module driver Kishon Vijay Abraham I
  1 sibling, 1 reply; 11+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-18  9:40 UTC (permalink / raw)
  To: rob.herring-bsGFqQB8/DxBDgjK7y7TUQ, rob-VoJi6FS/r0vR7s880joybQ,
	tony-4v6yS6AI5VpBDgjK7y7TUQ, balbi-l0cyMroinI0,
	b-cousson-l0cyMroinI0, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-doc-u79uwXL29TY76Z2rM5mHXA,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-lFZ/pmaqli7XmaaqVzeoHQ, kishon-l0cyMroinI0

A seperate driver has been added to handle the usb part of control
module. A device for the above driver is created here, using the register
address information to be used by the driver for powering on the PHY and
for writing to the mailbox.

Signed-off-by: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
---
 arch/arm/mach-omap2/devices.c |   48 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 5e304d0..a58b0ce 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -20,6 +20,7 @@
 #include <linux/pinctrl/machine.h>
 #include <linux/platform_data/omap4-keypad.h>
 #include <linux/platform_data/omap_ocp2scp.h>
+#include <linux/usb/omap_control_usb.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/map.h>
@@ -254,6 +255,52 @@ static inline void omap_init_camera(void)
 #endif
 }
 
+#if IS_ENABLED(CONFIG_OMAP_CONTROL_USB)
+static struct omap_control_usb_platform_data omap4_control_usb_pdata = {
+	.has_mailbox = true,
+};
+
+struct resource omap4_control_usb_res[] = {
+	{
+		.name	= "control_dev_conf",
+		.start	= 0x4a002300,
+		.end	= 0x4a002303,
+		.flags	= IORESOURCE_MEM,
+	},
+	{
+		.name	= "otghs_control",
+		.start	= 0x4a00233c,
+		.end	= 0x4a00233f,
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct platform_device omap4_control_usb = {
+	.name		= "omap-control-usb",
+	.id		= -1,
+	.dev = {
+		.platform_data = &omap4_control_usb_pdata,
+	},
+	.num_resources = 2,
+	.resource = omap4_control_usb_res,
+};
+
+static inline void __init omap_init_control_usb(void)
+{
+	int ret = 0;
+
+	if (cpu_is_omap44xx()) {
+		ret = platform_device_register(&omap4_control_usb);
+		if (ret)
+			pr_err("Error registering omap_control_usb device:%d\n",
+			    ret);
+	}
+}
+
+#else
+static inline void omap_init_control_usb(void) { }
+#endif /* CONFIG_OMAP_CONTROL_USB */
+
 int __init omap4_keyboard_init(struct omap4_keypad_platform_data
 			*sdp4430_keypad_data, struct omap_board_data *bdata)
 {
@@ -721,6 +768,7 @@ static int __init omap2_init_devices(void)
 	omap_init_mbox();
 	/* If dtb is there, the devices will be created dynamically */
 	if (!of_have_populated_dt()) {
+		omap_init_control_usb();
 		omap_init_dmic();
 		omap_init_mcpdm();
 		omap_init_mcspi();
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/4] ARM: OMAP2: MUSB: Specify omap4 has mailbox
  2013-01-18  9:40 [PATCH 0/4] usb: musb: add driver for control module Kishon Vijay Abraham I
  2013-01-18  9:40 ` [PATCH 1/4] drivers: usb: phy: add a new driver for usb part of " Kishon Vijay Abraham I
       [not found] ` <1358502045-27008-1-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
@ 2013-01-18  9:40 ` Kishon Vijay Abraham I
  2 siblings, 0 replies; 11+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-18  9:40 UTC (permalink / raw)
  To: rob.herring, rob, tony, balbi, b-cousson, linux-usb,
	linux-arm-kernel, linux-omap, linux-kernel, linux-doc,
	devicetree-discuss
  Cc: grant.likely, linux, gregkh, kishon

Added has_mailbox to the musb platform data to specify that omap uses
an external mailbox (in control module) to communicate with the musb
core during device connect and disconnect.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 arch/arm/mach-omap2/usb-musb.c |    3 +++
 include/linux/usb/musb.h       |    2 ++
 2 files changed, 5 insertions(+)

diff --git a/arch/arm/mach-omap2/usb-musb.c b/arch/arm/mach-omap2/usb-musb.c
index 7b33b37..9d27e3f 100644
--- a/arch/arm/mach-omap2/usb-musb.c
+++ b/arch/arm/mach-omap2/usb-musb.c
@@ -85,6 +85,9 @@ void __init usb_musb_init(struct omap_musb_board_data *musb_board_data)
 	musb_plat.mode = board_data->mode;
 	musb_plat.extvbus = board_data->extvbus;
 
+	if (cpu_is_omap44xx())
+		musb_plat.has_mailbox = true;
+
 	if (soc_is_am35xx()) {
 		oh_name = "am35x_otg_hs";
 		name = "musb-am35x";
diff --git a/include/linux/usb/musb.h b/include/linux/usb/musb.h
index eb50525..053c268 100644
--- a/include/linux/usb/musb.h
+++ b/include/linux/usb/musb.h
@@ -99,6 +99,8 @@ struct musb_hdrc_platform_data {
 	/* MUSB_HOST, MUSB_PERIPHERAL, or MUSB_OTG */
 	u8		mode;
 
+	u8		has_mailbox:1;
+
 	/* for clk_get() */
 	const char	*clock;
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/4] drivers: usb: start using the control module driver
       [not found] ` <1358502045-27008-1-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
  2013-01-18  9:40   ` [PATCH 2/4] ARM: OMAP: devices: create device " Kishon Vijay Abraham I
@ 2013-01-18  9:40   ` Kishon Vijay Abraham I
       [not found]     ` <1358502045-27008-5-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
  1 sibling, 1 reply; 11+ messages in thread
From: Kishon Vijay Abraham I @ 2013-01-18  9:40 UTC (permalink / raw)
  To: rob.herring-bsGFqQB8/DxBDgjK7y7TUQ, rob-VoJi6FS/r0vR7s880joybQ,
	tony-4v6yS6AI5VpBDgjK7y7TUQ, balbi-l0cyMroinI0,
	b-cousson-l0cyMroinI0, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-doc-u79uwXL29TY76Z2rM5mHXA,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-lFZ/pmaqli7XmaaqVzeoHQ, kishon-l0cyMroinI0

Start using the control module driver for powering on the PHY and for
writing to the mailbox instead of writing to the control module
registers on their own.

Signed-off-by: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
---
 Documentation/devicetree/bindings/usb/omap-usb.txt |    4 ++
 Documentation/devicetree/bindings/usb/usb-phy.txt  |    7 +--
 arch/arm/mach-omap2/omap_hwmod_44xx_data.c         |   13 ----
 drivers/usb/musb/Kconfig                           |    1 +
 drivers/usb/musb/omap2430.c                        |   64 ++++++++------------
 drivers/usb/musb/omap2430.h                        |    9 ---
 drivers/usb/phy/Kconfig                            |    1 +
 drivers/usb/phy/omap-usb2.c                        |   38 +++---------
 include/linux/usb/omap_usb.h                       |    4 +-
 9 files changed, 42 insertions(+), 99 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
index ead6ba9..8bedbba 100644
--- a/Documentation/devicetree/bindings/usb/omap-usb.txt
+++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
@@ -3,6 +3,9 @@ OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS
 OMAP MUSB GLUE
  - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"
  - ti,hwmods : must be "usb_otg_hs"
+ - ti,has_mailbox : to specify that omap uses an external mailbox
+   (in control module) to communicate with the musb core during device connect
+   and disconnect.
  - multipoint : Should be "1" indicating the musb controller supports
    multipoint. This is a MUSB configuration-specific setting.
  - num_eps : Specifies the number of endpoints. This is also a
@@ -24,6 +27,7 @@ SOC specific device node entry
 usb_otg_hs: usb_otg_hs@4a0ab000 {
 	compatible = "ti,omap4-musb";
 	ti,hwmods = "usb_otg_hs";
+	ti,has_mailbox;
 	multipoint = <1>;
 	num_eps = <16>;
 	ram_bits = <12>;
diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
index 2466b6f..48761a2 100644
--- a/Documentation/devicetree/bindings/usb/usb-phy.txt
+++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
@@ -4,9 +4,7 @@ OMAP USB2 PHY
 
 Required properties:
  - compatible: Should be "ti,omap-usb2"
- - reg : Address and length of the register set for the device. Also
-add the address of control module dev conf register until a driver for
-control module is added
+ - reg : Address and length of the register set for the device.
 
 Optional properties:
  - ctrl_module : phandle of the control module used by PHY driver to power on
@@ -16,7 +14,6 @@ This is usually a subnode of ocp2scp to which it is connected.
 
 usb2phy@4a0ad080 {
 	compatible = "ti,omap-usb2";
-	reg = <0x4a0ad080 0x58>,
-	      <0x4a002300 0x4>;
+	reg = <0x4a0ad080 0x58>;
 	ctrl_module = <&omap_control_usb>;
 };
diff --git a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
index 129d508..103f4ba 100644
--- a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
@@ -2698,13 +2698,6 @@ static struct resource omap44xx_usb_phy_and_pll_addrs[] = {
 		.end		= 0x4a0ae000,
 		.flags		= IORESOURCE_MEM,
 	},
-	{
-		/* XXX: Remove this once control module driver is in place */
-		.name		= "ctrl_dev",
-		.start		= 0x4a002300,
-		.end		= 0x4a002303,
-		.flags		= IORESOURCE_MEM,
-	},
 	{ }
 };
 
@@ -6152,12 +6145,6 @@ static struct omap_hwmod_addr_space omap44xx_usb_otg_hs_addrs[] = {
 		.pa_end		= 0x4a0ab7ff,
 		.flags		= ADDR_TYPE_RT
 	},
-	{
-		/* XXX: Remove this once control module driver is in place */
-		.pa_start	= 0x4a00233c,
-		.pa_end		= 0x4a00233f,
-		.flags		= ADDR_TYPE_RT
-	},
 	{ }
 };
 
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 23a0b7f..de6e5ce 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -11,6 +11,7 @@ config USB_MUSB_HDRC
 	select NOP_USB_XCEIV if (SOC_TI81XX || SOC_AM33XX)
 	select TWL4030_USB if MACH_OMAP_3430SDP
 	select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
+	select OMAP_CONTROL_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
 	select USB_OTG_UTILS
 	help
 	  Say Y here if your system has a dual role high speed USB
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index da00af4..3e7ceef 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -37,6 +37,7 @@
 #include <linux/err.h>
 #include <linux/delay.h>
 #include <linux/usb/musb-omap.h>
+#include <linux/usb/omap_control_usb.h>
 
 #include "musb_core.h"
 #include "omap2430.h"
@@ -46,7 +47,7 @@ struct omap2430_glue {
 	struct platform_device	*musb;
 	enum omap_musb_vbus_id_status status;
 	struct work_struct	omap_musb_mailbox_work;
-	u32 __iomem		*control_otghs;
+	struct device		*control_otghs;
 };
 #define glue_to_musb(g)		platform_get_drvdata(g->musb)
 
@@ -54,26 +55,6 @@ struct omap2430_glue		*_glue;
 
 static struct timer_list musb_idle_timer;
 
-/**
- * omap4_usb_phy_mailbox - write to usb otg mailbox
- * @glue: struct omap2430_glue *
- * @val: the value to be written to the mailbox
- *
- * On detection of a device (ID pin is grounded), this API should be called
- * to set AVALID, VBUSVALID and ID pin is grounded.
- *
- * When OMAP is connected to a host (OMAP in device mode), this API
- * is called to set AVALID, VBUSVALID and ID pin in high impedance.
- *
- * XXX: This function will be removed once we have a seperate driver for
- * control module
- */
-static void omap4_usb_phy_mailbox(struct omap2430_glue *glue, u32 val)
-{
-	if (glue->control_otghs)
-		writel(val, glue->control_otghs);
-}
-
 static void musb_do_idle(unsigned long _musb)
 {
 	struct musb	*musb = (void *)_musb;
@@ -269,7 +250,6 @@ EXPORT_SYMBOL_GPL(omap_musb_mailbox);
 
 static void omap_musb_set_mailbox(struct omap2430_glue *glue)
 {
-	u32 val;
 	struct musb *musb = glue_to_musb(glue);
 	struct device *dev = musb->controller;
 	struct musb_hdrc_platform_data *pdata = dev->platform_data;
@@ -285,8 +265,8 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
 		musb->xceiv->last_event = USB_EVENT_ID;
 		if (musb->gadget_driver) {
 			pm_runtime_get_sync(dev);
-			val = AVALID | VBUSVALID;
-			omap4_usb_phy_mailbox(glue, val);
+			if (!IS_ERR(glue->control_otghs))
+				omap_control_usb_host_mode(glue->control_otghs);
 			omap2430_musb_set_vbus(musb, 1);
 		}
 		break;
@@ -299,8 +279,8 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
 		musb->xceiv->last_event = USB_EVENT_VBUS;
 		if (musb->gadget_driver)
 			pm_runtime_get_sync(dev);
-		val = IDDIG | AVALID | VBUSVALID;
-		omap4_usb_phy_mailbox(glue, val);
+		if (!IS_ERR(glue->control_otghs))
+			omap_control_usb_device_mode(glue->control_otghs);
 		break;
 
 	case OMAP_MUSB_ID_FLOAT:
@@ -317,8 +297,8 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
 			if (musb->xceiv->otg->set_vbus)
 				otg_set_vbus(musb->xceiv->otg, 0);
 		}
-		val = SESSEND | IDDIG;
-		omap4_usb_phy_mailbox(glue, val);
+		if (!IS_ERR(glue->control_otghs))
+			omap_control_usb_set_sessionend(glue->control_otghs);
 		break;
 	default:
 		dev_dbg(dev, "ID float\n");
@@ -415,7 +395,6 @@ err1:
 static void omap2430_musb_enable(struct musb *musb)
 {
 	u8		devctl;
-	u32		val;
 	unsigned long timeout = jiffies + msecs_to_jiffies(1000);
 	struct device *dev = musb->controller;
 	struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
@@ -425,8 +404,8 @@ static void omap2430_musb_enable(struct musb *musb)
 	switch (glue->status) {
 
 	case OMAP_MUSB_ID_GROUND:
-		val = AVALID | VBUSVALID;
-		omap4_usb_phy_mailbox(glue, val);
+		if (!IS_ERR(glue->control_otghs))
+			omap_control_usb_host_mode(glue->control_otghs);
 		if (data->interface_type != MUSB_INTERFACE_UTMI)
 			break;
 		devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
@@ -445,8 +424,8 @@ static void omap2430_musb_enable(struct musb *musb)
 		break;
 
 	case OMAP_MUSB_VBUS_VALID:
-		val = IDDIG | AVALID | VBUSVALID;
-		omap4_usb_phy_mailbox(glue, val);
+		if (!IS_ERR(glue->control_otghs))
+			omap_control_usb_device_mode(glue->control_otghs);
 		break;
 
 	default:
@@ -456,13 +435,12 @@ static void omap2430_musb_enable(struct musb *musb)
 
 static void omap2430_musb_disable(struct musb *musb)
 {
-	u32 val;
 	struct device *dev = musb->controller;
 	struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
 
 	if (glue->status != OMAP_MUSB_UNKNOWN) {
-		val = SESSEND | IDDIG;
-		omap4_usb_phy_mailbox(glue, val);
+		if (!IS_ERR(glue->control_otghs))
+			omap_control_usb_set_sessionend(glue->control_otghs);
 	}
 }
 
@@ -523,9 +501,6 @@ static int omap2430_probe(struct platform_device *pdev)
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 
-	glue->control_otghs = devm_request_and_ioremap(&pdev->dev, res);
-	if (glue->control_otghs == NULL)
-		dev_dbg(&pdev->dev, "Failed to obtain control memory\n");
 
 	if (np) {
 		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
@@ -558,11 +533,22 @@ static int omap2430_probe(struct platform_device *pdev)
 		of_property_read_u32(np, "ram_bits", (u32 *)&config->ram_bits);
 		of_property_read_u32(np, "power", (u32 *)&pdata->power);
 		config->multipoint = of_property_read_bool(np, "multipoint");
+		pdata->has_mailbox = of_property_read_bool(np,
+		    "ti,has_mailbox");
 
 		pdata->board_data	= data;
 		pdata->config		= config;
 	}
 
+	if (pdata->has_mailbox) {
+		glue->control_otghs = get_omap_control_dev();
+		if (IS_ERR(glue->control_otghs)) {
+			dev_vdbg(&pdev->dev, "Failed to get control device\n");
+			return -ENODEV;
+		}
+	} else {
+		glue->control_otghs = ERR_PTR(-ENODEV);
+	}
 	pdata->platform_ops		= &omap2430_ops;
 
 	platform_set_drvdata(pdev, glue);
diff --git a/drivers/usb/musb/omap2430.h b/drivers/usb/musb/omap2430.h
index 8ef6566..1b5e83a 100644
--- a/drivers/usb/musb/omap2430.h
+++ b/drivers/usb/musb/omap2430.h
@@ -49,13 +49,4 @@
 #define OTG_FORCESTDBY		0x414
 #	define	ENABLEFORCE		(1 << 0)
 
-/*
- * Control Module bit definitions
- * XXX: Will be removed once we have a driver for control module.
- */
-#define	AVALID				BIT(0)
-#define	BVALID				BIT(1)
-#define	VBUSVALID			BIT(2)
-#define	SESSEND				BIT(3)
-#define	IDDIG				BIT(4)
 #endif	/* __MUSB_OMAP243X_H__ */
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index a7277ee..16bdaca 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -8,6 +8,7 @@ config OMAP_USB2
 	tristate "OMAP USB2 PHY Driver"
 	depends on ARCH_OMAP2PLUS
 	select USB_OTG_UTILS
+	select OMAP_CONTROL_USB
 	help
 	  Enable this to support the transceiver that is part of SOC. This
 	  driver takes care of all the PHY functionality apart from comparator.
diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/omap-usb2.c
index 26ae8f4..2152ce4 100644
--- a/drivers/usb/phy/omap-usb2.c
+++ b/drivers/usb/phy/omap-usb2.c
@@ -27,6 +27,7 @@
 #include <linux/err.h>
 #include <linux/pm_runtime.h>
 #include <linux/delay.h>
+#include <linux/usb/omap_control_usb.h>
 
 /**
  * omap_usb2_set_comparator - links the comparator present in the sytem with
@@ -52,29 +53,6 @@ int omap_usb2_set_comparator(struct phy_companion *comparator)
 }
 EXPORT_SYMBOL_GPL(omap_usb2_set_comparator);
 
-/**
- * omap_usb_phy_power - power on/off the phy using control module reg
- * @phy: struct omap_usb *
- * @on: 0 or 1, based on powering on or off the PHY
- *
- * XXX: Remove this function once control module driver gets merged
- */
-static void omap_usb_phy_power(struct omap_usb *phy, int on)
-{
-	u32 val;
-
-	if (on) {
-		val = readl(phy->control_dev);
-		if (val & PHY_PD) {
-			writel(~PHY_PD, phy->control_dev);
-			/* XXX: add proper documentation for this delay */
-			mdelay(200);
-		}
-	} else {
-		writel(PHY_PD, phy->control_dev);
-	}
-}
-
 static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled)
 {
 	struct omap_usb *phy = phy_to_omapusb(otg->phy);
@@ -124,7 +102,7 @@ static int omap_usb2_suspend(struct usb_phy *x, int suspend)
 	struct omap_usb *phy = phy_to_omapusb(x);
 
 	if (suspend && !phy->is_suspended) {
-		omap_usb_phy_power(phy, 0);
+		omap_control_usb_phy_power(phy->control_dev, 0);
 		pm_runtime_put_sync(phy->dev);
 		phy->is_suspended = 1;
 	} else if (!suspend && phy->is_suspended) {
@@ -134,7 +112,7 @@ static int omap_usb2_suspend(struct usb_phy *x, int suspend)
 									ret);
 			return ret;
 		}
-		omap_usb_phy_power(phy, 1);
+		omap_control_usb_phy_power(phy->control_dev, 1);
 		phy->is_suspended = 0;
 	}
 
@@ -168,14 +146,14 @@ static int omap_usb2_probe(struct platform_device *pdev)
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 
-	phy->control_dev = devm_request_and_ioremap(&pdev->dev, res);
-	if (phy->control_dev == NULL) {
-		dev_err(&pdev->dev, "Failed to obtain io memory\n");
-		return -ENXIO;
+	phy->control_dev = get_omap_control_dev();
+	if (IS_ERR(phy->control_dev)) {
+		dev_dbg(&pdev->dev, "Failed to get control device\n");
+		return -ENODEV;
 	}
 
 	phy->is_suspended	= 1;
-	omap_usb_phy_power(phy, 0);
+	omap_control_usb_phy_power(phy->control_dev, 0);
 
 	otg->set_host		= omap_usb_set_host;
 	otg->set_peripheral	= omap_usb_set_peripheral;
diff --git a/include/linux/usb/omap_usb.h b/include/linux/usb/omap_usb.h
index 0ea17f8..3db9b53 100644
--- a/include/linux/usb/omap_usb.h
+++ b/include/linux/usb/omap_usb.h
@@ -25,13 +25,11 @@ struct omap_usb {
 	struct usb_phy		phy;
 	struct phy_companion	*comparator;
 	struct device		*dev;
-	u32 __iomem		*control_dev;
+	struct device		*control_dev;
 	struct clk		*wkupclk;
 	u8			is_suspended:1;
 };
 
-#define	PHY_PD	0x1
-
 #define	phy_to_omapusb(x)	container_of((x), struct omap_usb, phy)
 
 #if defined(CONFIG_OMAP_USB2) || defined(CONFIG_OMAP_USB2_MODULE)
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] drivers: usb: phy: add a new driver for usb part of control module
       [not found]   ` <1358502045-27008-2-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
@ 2013-01-18 11:59     ` Felipe Balbi
       [not found]       ` <20130118115909.GA4672-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Felipe Balbi @ 2013-01-18 11:59 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: rob.herring-bsGFqQB8/DxBDgjK7y7TUQ, rob-VoJi6FS/r0vR7s880joybQ,
	tony-4v6yS6AI5VpBDgjK7y7TUQ, balbi-l0cyMroinI0,
	b-cousson-l0cyMroinI0, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-doc-u79uwXL29TY76Z2rM5mHXA,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	grant.likely-s3s/WqlpOiPyB63q8FvJNQ, linux-lFZ/pmaqli7XmaaqVzeoHQ,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r

[-- Attachment #1: Type: text/plain, Size: 14200 bytes --]

Hi,

On Fri, Jan 18, 2013 at 03:10:42PM +0530, Kishon Vijay Abraham I wrote:
> Added a new driver for the usb part of control module. This has an API
> to power on the USB2 phy and an API to write to the mailbox depending on
> whether MUSB has to act in host mode or in device mode.
> 
> Writing to control module registers for doing the above task which was
> previously done in omap glue and in omap-usb2 phy will be removed.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
> ---
>  Documentation/devicetree/bindings/usb/omap-usb.txt |   26 ++-
>  Documentation/devicetree/bindings/usb/usb-phy.txt  |    5 +
>  drivers/usb/phy/Kconfig                            |    9 +
>  drivers/usb/phy/Makefile                           |    1 +
>  drivers/usb/phy/omap-control-usb.c                 |  204 ++++++++++++++++++++
>  include/linux/usb/omap_control_usb.h               |   72 +++++++
>  6 files changed, 316 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/usb/phy/omap-control-usb.c
>  create mode 100644 include/linux/usb/omap_control_usb.h
> 
> diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
> index 29a043e..ead6ba9 100644
> --- a/Documentation/devicetree/bindings/usb/omap-usb.txt
> +++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
> @@ -1,4 +1,4 @@
> -OMAP GLUE
> +OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS
>  
>  OMAP MUSB GLUE
>   - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"
> @@ -16,6 +16,10 @@ OMAP MUSB GLUE
>   - power : Should be "50". This signifies the controller can supply upto
>     100mA when operating in host mode.
>  
> +Optional properties:
> + - ctrl_module : phandle of the control module this glue uses to write to
> +   mailbox
> +
>  SOC specific device node entry
>  usb_otg_hs: usb_otg_hs@4a0ab000 {
>  	compatible = "ti,omap4-musb";
> @@ -23,6 +27,7 @@ usb_otg_hs: usb_otg_hs@4a0ab000 {
>  	multipoint = <1>;
>  	num_eps = <16>;
>  	ram_bits = <12>;
> +	ctrl_module = <&omap_control_usb>;
>  };
>  
>  Board specific device node entry
> @@ -31,3 +36,22 @@ Board specific device node entry
>  	mode = <3>;
>  	power = <50>;
>  };
> +
> +OMAP CONTROL USB
> +
> +Required properties:
> + - compatible: Should be "ti,omap-control-usb"
> + - reg : Address and length of the register set for the device. It contains
> +   the address of "control_dev_conf" and "otghs_control".
> + - reg-names: The names of the register addresses corresponding to the registers
> +   filled in "reg".
> + - ti,has_mailbox: This is used to specify if the platform has mailbox in
> +   control module.
> +
> +omap_control_usb: omap-control-usb@4a002300 {
> +	compatible = "ti,omap-control-usb";
> +	reg = <0x4a002300 0x4>,
> +	      <0x4a00233c 0x4>;
> +	reg-names = "control_dev_conf", "otghs_control";
> +	ti,has_mailbox;
> +};
> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
> index 80d4148..2466b6f 100644
> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
> @@ -8,10 +8,15 @@ Required properties:
>  add the address of control module dev conf register until a driver for
>  control module is added
>  
> +Optional properties:
> + - ctrl_module : phandle of the control module used by PHY driver to power on
> +   the PHY.
> +
>  This is usually a subnode of ocp2scp to which it is connected.
>  
>  usb2phy@4a0ad080 {
>  	compatible = "ti,omap-usb2";
>  	reg = <0x4a0ad080 0x58>,
>  	      <0x4a002300 0x4>;
> +	ctrl_module = <&omap_control_usb>;
>  };
> diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
> index 5de6e7f..a7277ee 100644
> --- a/drivers/usb/phy/Kconfig
> +++ b/drivers/usb/phy/Kconfig
> @@ -14,6 +14,15 @@ config OMAP_USB2
>  	  The USB OTG controller communicates with the comparator using this
>  	  driver.
>  
> +config OMAP_CONTROL_USB
> +	tristate "OMAP CONTROL USB Driver"
> +	depends on ARCH_OMAP2PLUS
> +	help
> +	  Enable this to add support for the USB part present in the control
> +	  module. This driver has API to power on the PHY and to write to the
> +	  mailbox. The mailbox is present only in omap4 and the register to
> +	  power on the PHY is present in omap4 and omap5.
> +
>  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 1a579a8..0dea4d2 100644
> --- a/drivers/usb/phy/Makefile
> +++ b/drivers/usb/phy/Makefile
> @@ -5,6 +5,7 @@
>  ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
>  
>  obj-$(CONFIG_OMAP_USB2)			+= omap-usb2.o
> +obj-$(CONFIG_OMAP_CONTROL_USB)		+= omap-control-usb.o
>  obj-$(CONFIG_USB_ISP1301)		+= isp1301.o
>  obj-$(CONFIG_MV_U3D_PHY)		+= mv_u3d_phy.o
>  obj-$(CONFIG_USB_EHCI_TEGRA)	+= tegra_usb_phy.o
> diff --git a/drivers/usb/phy/omap-control-usb.c b/drivers/usb/phy/omap-control-usb.c
> new file mode 100644
> index 0000000..7edeb41
> --- /dev/null
> +++ b/drivers/usb/phy/omap-control-usb.c
> @@ -0,0 +1,204 @@
> +/*
> + * omap-control-usb.c - The USB part of control module.
> + *
> + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
> + * 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.
> + *
> + * Author: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
> + *
> + * 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/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +#include <linux/of.h>
> +#include <linux/err.h>
> +#include <linux/io.h>
> +#include <linux/usb/omap_control_usb.h>
> +
> +static struct omap_control_usb *control_usb;
> +
> +/**
> + * get_omap_control_dev - returns the device pointer for this control device
> + *
> + * This API should be called to get the device pointer for this control
> + * module device. This device pointer should be passed to all other API's
> + * in this driver.
> + *
> + * To be used by PHY driver and glue driver
> + */
> +struct device *get_omap_control_dev(void)

let's do a small rename here and call it:

omap_get_control_dev(), just to keep consistency with rest of the file.

> +{
> +	if (!control_usb)
> +		return ERR_PTR(-ENODEV);
> +
> +	return control_usb->dev;
> +}
> +EXPORT_SYMBOL_GPL(get_omap_control_dev);
> +
> +/**
> + * omap_control_usb_phy_power - power on/off the phy using control module reg
> + * @dev: the control module device
> + * @on: 0 or 1, based on powering on or off the PHY
> + */
> +void omap_control_usb_phy_power(struct device *dev, int on)
> +{
> +	u32 val;
> +	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
> +
> +	if (on) {
> +		val = readl(control_usb->dev_conf);
> +		if (val & PHY_PD)
> +			writel(~PHY_PD, control_usb->dev_conf);
> +	} else {
> +		writel(PHY_PD, control_usb->dev_conf);
> +	}

this can be better. I would rather have this:

struct omap_control_usb *ctrl = dev_get_drvdata(dev);
u32 val;

val = readl(ctrl->dev_conf);

if (on)
	val &= ~OMAP_CTRL_DEV_PHY_PD;
else
	val |= OMAP_CTRL_DEV_PHY_PD;

writel(val, ctrl->dev_conf);



> +}
> +EXPORT_SYMBOL_GPL(omap_control_usb_phy_power);
> +
> +/**
> + * omap_control_usb_host_mode - set AVALID, VBUSVALID and ID pin in grounded
> + * @dev: struct device *
> + *
> + * This is an API to write to the mailbox register to notify the usb core that
> + * a usb device has been connected.
> + */
> +void omap_control_usb_host_mode(struct device *dev)
> +{
> +	u32 val;
> +	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
> +
> +	val = AVALID | VBUSVALID;
> +
> +	writel(val, control_usb->otghs_control);

I would like to make this future proof too:

val = readl(ctrl->otghs_control);
val |= OMAP_CTRL_DEV_AVALID | OMAP_CTRL_DEV_VBUSVALID;
writel(val, ctrl->otghs_control);

> +void omap_control_usb_device_mode(struct device *dev)
> +{
> +	u32 val;
> +	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
> +
> +	val = IDDIG | AVALID | VBUSVALID;

ditto. Read it before changing it. (the idea is that in future the other
bits might be used for something else, so you risk breaking future
functionality).

> +
> +	writel(val, control_usb->otghs_control);
> +}
> +EXPORT_SYMBOL_GPL(omap_control_usb_device_mode);
> +
> +/**
> + * omap_control_usb_set_sessionend - Enable SESSIONEND and IDIG to high
> + * impedance
> + * @dev: struct device *
> + *
> + * This is an API to write to the mailbox register to notify the usb core
> + * it's now in disconnected state.
> + */
> +void omap_control_usb_set_sessionend(struct device *dev)
> +{
> +	u32 val;
> +	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
> +
> +	val = SESSEND | IDDIG;

ditto

> +
> +	writel(val, control_usb->otghs_control);
> +}
> +EXPORT_SYMBOL_GPL(omap_control_usb_set_sessionend);
> +
> +static int omap_control_usb_probe(struct platform_device *pdev)
> +{
> +	struct resource	*res;
> +	struct device_node *np = pdev->dev.of_node;
> +	struct omap_control_usb_platform_data *pdata = pdev->dev.platform_data;
> +
> +	control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb),
> +	    GFP_KERNEL);

you're using space indentation here.

> +	if (!control_usb) {
> +		dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
> +		return -ENOMEM;
> +	}
> +
> +	if (np) {
> +		control_usb->has_mailbox = of_property_read_bool(np,
> +		    "ti,has_mailbox");
> +	} else if (pdata) {
> +		control_usb->has_mailbox = pdata->has_mailbox;
> +	} else {
> +		dev_err(&pdev->dev, "no pdata present\n");
> +		return -EINVAL;

does it make sense to default to has_mailbox as true ? I mean, seems
like this is how it's going to be in future devices looking at the
current trend.

Another idea is to try to get the extra resource below, if it fails you
try to continue without it ;-)

> +	}
> +
> +	control_usb->dev	= &pdev->dev;
> +
> +	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
> +	    "control_dev_conf");

using space indentation here again.

> +	control_usb->dev_conf = devm_request_and_ioremap(&pdev->dev, res);
> +	if (control_usb->dev_conf == NULL) {
> +		dev_err(&pdev->dev, "Failed to obtain io memory\n");
> +		return -EADDRNOTAVAIL;
> +	}
> +
> +	if (control_usb->has_mailbox) {
> +		res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
> +		    "otghs_control");
> +		control_usb->otghs_control = devm_request_and_ioremap(
> +		    &pdev->dev, res);
> +		if (control_usb->otghs_control == NULL) {
> +			dev_err(&pdev->dev, "Failed to obtain io memory\n");
> +			return -EADDRNOTAVAIL;
> +		}
> +	}
> +
> +	dev_set_drvdata(control_usb->dev, control_usb);
> +
> +	return 0;
> +}
> +
> +#ifdef CONFIG_OF
> +static const struct of_device_id omap_control_usb_id_table[] = {
> +	{ .compatible = "ti,omap-control-usb" },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
> +#endif
> +
> +static struct platform_driver omap_control_usb_driver = {
> +	.probe		= omap_control_usb_probe,
> +	.driver		= {
> +		.name	= "omap-control-usb",
> +		.owner	= THIS_MODULE,

no need to set owner here. When you register the platform_driver, it
will be set for you.

> +		.of_match_table = of_match_ptr(omap_control_usb_id_table),
> +	},
> +};
> +
> +static int __init omap_control_usb_init(void)
> +{
> +	return platform_driver_register(&omap_control_usb_driver);
> +}
> +subsys_initcall(omap_control_usb_init);
> +
> +static void __exit omap_control_usb_exit(void)
> +{
> +	platform_driver_unregister(&omap_control_usb_driver);
> +}
> +module_exit(omap_control_usb_exit);
> +
> +MODULE_ALIAS("platform: omap_control_usb");
> +MODULE_AUTHOR("Texas Instruments Inc.");
> +MODULE_DESCRIPTION("OMAP CONTROL USB DRIVER");

don't scream to your users like that ;-)

MODULE_DESCRIPTION("OMAP Control Module USB Driver");

> +MODULE_LICENSE("GPL v2");
> diff --git a/include/linux/usb/omap_control_usb.h b/include/linux/usb/omap_control_usb.h
> new file mode 100644
> index 0000000..a16f993
> --- /dev/null
> +++ b/include/linux/usb/omap_control_usb.h
> @@ -0,0 +1,72 @@
> +/*
> + * omap_control_usb.h - Header file for the USB part of control module.
> + *
> + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
> + * 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.
> + *
> + * Author: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
> + *
> + * 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.
> + *
> + */
> +
> +#ifndef __OMAP_CONTROL_USB_H__
> +#define __OMAP_CONTROL_USB_H__
> +
> +struct omap_control_usb {
> +	struct device *dev;
> +
> +	u32 __iomem *dev_conf;
> +	u32 __iomem *otghs_control;
> +
> +	u8 has_mailbox:1;
> +};
> +
> +struct omap_control_usb_platform_data {
> +	u8 has_mailbox:1;
> +};
> +
> +#define	PHY_PD		BIT(0)
> +
> +#define	AVALID		BIT(0)
> +#define	BVALID		BIT(1)
> +#define	VBUSVALID	BIT(2)
> +#define	SESSEND		BIT(3)
> +#define	IDDIG		BIT(4)

please prepend with OMAP_CTRL_ or something similar.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/4] ARM: OMAP: devices: create device for usb part of control module
       [not found]     ` <1358502045-27008-3-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
@ 2013-01-18 12:00       ` Felipe Balbi
  0 siblings, 0 replies; 11+ messages in thread
From: Felipe Balbi @ 2013-01-18 12:00 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: rob.herring-bsGFqQB8/DxBDgjK7y7TUQ, rob-VoJi6FS/r0vR7s880joybQ,
	tony-4v6yS6AI5VpBDgjK7y7TUQ, balbi-l0cyMroinI0,
	b-cousson-l0cyMroinI0, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-doc-u79uwXL29TY76Z2rM5mHXA,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	grant.likely-s3s/WqlpOiPyB63q8FvJNQ, linux-lFZ/pmaqli7XmaaqVzeoHQ,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r

[-- Attachment #1: Type: text/plain, Size: 2246 bytes --]

On Fri, Jan 18, 2013 at 03:10:43PM +0530, Kishon Vijay Abraham I wrote:
> A seperate driver has been added to handle the usb part of control
> module. A device for the above driver is created here, using the register
> address information to be used by the driver for powering on the PHY and
> for writing to the mailbox.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
> ---
>  arch/arm/mach-omap2/devices.c |   48 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 48 insertions(+)
> 
> diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
> index 5e304d0..a58b0ce 100644
> --- a/arch/arm/mach-omap2/devices.c
> +++ b/arch/arm/mach-omap2/devices.c
> @@ -20,6 +20,7 @@
>  #include <linux/pinctrl/machine.h>
>  #include <linux/platform_data/omap4-keypad.h>
>  #include <linux/platform_data/omap_ocp2scp.h>
> +#include <linux/usb/omap_control_usb.h>
>  
>  #include <asm/mach-types.h>
>  #include <asm/mach/map.h>
> @@ -254,6 +255,52 @@ static inline void omap_init_camera(void)
>  #endif
>  }
>  
> +#if IS_ENABLED(CONFIG_OMAP_CONTROL_USB)
> +static struct omap_control_usb_platform_data omap4_control_usb_pdata = {
> +	.has_mailbox = true,
> +};
> +
> +struct resource omap4_control_usb_res[] = {
> +	{
> +		.name	= "control_dev_conf",
> +		.start	= 0x4a002300,
> +		.end	= 0x4a002303,
> +		.flags	= IORESOURCE_MEM,
> +	},
> +	{
> +		.name	= "otghs_control",
> +		.start	= 0x4a00233c,
> +		.end	= 0x4a00233f,
> +		.flags	= IORESOURCE_MEM,
> +	},
> +};
> +
> +static struct platform_device omap4_control_usb = {
> +	.name		= "omap-control-usb",
> +	.id		= -1,
> +	.dev = {
> +		.platform_data = &omap4_control_usb_pdata,
> +	},
> +	.num_resources = 2,
> +	.resource = omap4_control_usb_res,
> +};
> +
> +static inline void __init omap_init_control_usb(void)
> +{
> +	int ret = 0;
> +
> +	if (cpu_is_omap44xx()) {
> +		ret = platform_device_register(&omap4_control_usb);
> +		if (ret)
> +			pr_err("Error registering omap_control_usb device:%d\n",
> +			    ret);
> +	}

you can decrease indentation if you invert the check:

if (!cpu_is_omap44xx())
	return;

if (platform_device_register(.....)
-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4] drivers: usb: start using the control module driver
       [not found]     ` <1358502045-27008-5-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
@ 2013-01-18 12:02       ` Felipe Balbi
  2013-01-18 12:11         ` kishon
  0 siblings, 1 reply; 11+ messages in thread
From: Felipe Balbi @ 2013-01-18 12:02 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-lFZ/pmaqli7XmaaqVzeoHQ, linux-doc-u79uwXL29TY76Z2rM5mHXA,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, balbi-l0cyMroinI0,
	rob.herring-bsGFqQB8/DxBDgjK7y7TUQ,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r


[-- Attachment #1.1: Type: text/plain, Size: 7326 bytes --]

Hi,

On Fri, Jan 18, 2013 at 03:10:45PM +0530, Kishon Vijay Abraham I wrote:
> Start using the control module driver for powering on the PHY and for
> writing to the mailbox instead of writing to the control module
> registers on their own.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
> ---
>  Documentation/devicetree/bindings/usb/omap-usb.txt |    4 ++
>  Documentation/devicetree/bindings/usb/usb-phy.txt  |    7 +--
>  arch/arm/mach-omap2/omap_hwmod_44xx_data.c         |   13 ----
>  drivers/usb/musb/Kconfig                           |    1 +
>  drivers/usb/musb/omap2430.c                        |   64 ++++++++------------
>  drivers/usb/musb/omap2430.h                        |    9 ---
>  drivers/usb/phy/Kconfig                            |    1 +
>  drivers/usb/phy/omap-usb2.c                        |   38 +++---------
>  include/linux/usb/omap_usb.h                       |    4 +-
>  9 files changed, 42 insertions(+), 99 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
> index ead6ba9..8bedbba 100644
> --- a/Documentation/devicetree/bindings/usb/omap-usb.txt
> +++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
> @@ -3,6 +3,9 @@ OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS
>  OMAP MUSB GLUE
>   - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"
>   - ti,hwmods : must be "usb_otg_hs"
> + - ti,has_mailbox : to specify that omap uses an external mailbox
> +   (in control module) to communicate with the musb core during device connect
> +   and disconnect.
>   - multipoint : Should be "1" indicating the musb controller supports
>     multipoint. This is a MUSB configuration-specific setting.
>   - num_eps : Specifies the number of endpoints. This is also a
> @@ -24,6 +27,7 @@ SOC specific device node entry
>  usb_otg_hs: usb_otg_hs@4a0ab000 {
>  	compatible = "ti,omap4-musb";
>  	ti,hwmods = "usb_otg_hs";
> +	ti,has_mailbox;
>  	multipoint = <1>;
>  	num_eps = <16>;
>  	ram_bits = <12>;
> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
> index 2466b6f..48761a2 100644
> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
> @@ -4,9 +4,7 @@ OMAP USB2 PHY
>  
>  Required properties:
>   - compatible: Should be "ti,omap-usb2"
> - - reg : Address and length of the register set for the device. Also
> -add the address of control module dev conf register until a driver for
> -control module is added
> + - reg : Address and length of the register set for the device.
>  
>  Optional properties:
>   - ctrl_module : phandle of the control module used by PHY driver to power on
> @@ -16,7 +14,6 @@ This is usually a subnode of ocp2scp to which it is connected.
>  
>  usb2phy@4a0ad080 {
>  	compatible = "ti,omap-usb2";
> -	reg = <0x4a0ad080 0x58>,
> -	      <0x4a002300 0x4>;
> +	reg = <0x4a0ad080 0x58>;
>  	ctrl_module = <&omap_control_usb>;
>  };
> diff --git a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
> index 129d508..103f4ba 100644
> --- a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
> +++ b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
> @@ -2698,13 +2698,6 @@ static struct resource omap44xx_usb_phy_and_pll_addrs[] = {
>  		.end		= 0x4a0ae000,
>  		.flags		= IORESOURCE_MEM,
>  	},
> -	{
> -		/* XXX: Remove this once control module driver is in place */
> -		.name		= "ctrl_dev",
> -		.start		= 0x4a002300,
> -		.end		= 0x4a002303,
> -		.flags		= IORESOURCE_MEM,
> -	},
>  	{ }
>  };
>  
> @@ -6152,12 +6145,6 @@ static struct omap_hwmod_addr_space omap44xx_usb_otg_hs_addrs[] = {
>  		.pa_end		= 0x4a0ab7ff,
>  		.flags		= ADDR_TYPE_RT
>  	},
> -	{
> -		/* XXX: Remove this once control module driver is in place */
> -		.pa_start	= 0x4a00233c,
> -		.pa_end		= 0x4a00233f,
> -		.flags		= ADDR_TYPE_RT
> -	},
>  	{ }
>  };
>  
> diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
> index 23a0b7f..de6e5ce 100644
> --- a/drivers/usb/musb/Kconfig
> +++ b/drivers/usb/musb/Kconfig
> @@ -11,6 +11,7 @@ config USB_MUSB_HDRC
>  	select NOP_USB_XCEIV if (SOC_TI81XX || SOC_AM33XX)
>  	select TWL4030_USB if MACH_OMAP_3430SDP
>  	select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
> +	select OMAP_CONTROL_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
>  	select USB_OTG_UTILS
>  	help
>  	  Say Y here if your system has a dual role high speed USB
> diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
> index da00af4..3e7ceef 100644
> --- a/drivers/usb/musb/omap2430.c
> +++ b/drivers/usb/musb/omap2430.c
> @@ -37,6 +37,7 @@
>  #include <linux/err.h>
>  #include <linux/delay.h>
>  #include <linux/usb/musb-omap.h>
> +#include <linux/usb/omap_control_usb.h>
>  
>  #include "musb_core.h"
>  #include "omap2430.h"
> @@ -46,7 +47,7 @@ struct omap2430_glue {
>  	struct platform_device	*musb;
>  	enum omap_musb_vbus_id_status status;
>  	struct work_struct	omap_musb_mailbox_work;
> -	u32 __iomem		*control_otghs;
> +	struct device		*control_otghs;
>  };
>  #define glue_to_musb(g)		platform_get_drvdata(g->musb)
>  
> @@ -54,26 +55,6 @@ struct omap2430_glue		*_glue;
>  
>  static struct timer_list musb_idle_timer;
>  
> -/**
> - * omap4_usb_phy_mailbox - write to usb otg mailbox
> - * @glue: struct omap2430_glue *
> - * @val: the value to be written to the mailbox
> - *
> - * On detection of a device (ID pin is grounded), this API should be called
> - * to set AVALID, VBUSVALID and ID pin is grounded.
> - *
> - * When OMAP is connected to a host (OMAP in device mode), this API
> - * is called to set AVALID, VBUSVALID and ID pin in high impedance.
> - *
> - * XXX: This function will be removed once we have a seperate driver for
> - * control module
> - */
> -static void omap4_usb_phy_mailbox(struct omap2430_glue *glue, u32 val)
> -{
> -	if (glue->control_otghs)
> -		writel(val, glue->control_otghs);
> -}
> -
>  static void musb_do_idle(unsigned long _musb)
>  {
>  	struct musb	*musb = (void *)_musb;
> @@ -269,7 +250,6 @@ EXPORT_SYMBOL_GPL(omap_musb_mailbox);
>  
>  static void omap_musb_set_mailbox(struct omap2430_glue *glue)
>  {
> -	u32 val;
>  	struct musb *musb = glue_to_musb(glue);
>  	struct device *dev = musb->controller;
>  	struct musb_hdrc_platform_data *pdata = dev->platform_data;
> @@ -285,8 +265,8 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
>  		musb->xceiv->last_event = USB_EVENT_ID;
>  		if (musb->gadget_driver) {
>  			pm_runtime_get_sync(dev);
> -			val = AVALID | VBUSVALID;
> -			omap4_usb_phy_mailbox(glue, val);
> +			if (!IS_ERR(glue->control_otghs))
> +				omap_control_usb_host_mode(glue->control_otghs);

you could introduce a helper to do the checks for you. something like:

static inline void omap_control_set_mode(*ctrl, int mode)
{
	if (IS_ERR(glue->control_otghs))
		return;

	switch (mode) {
	case HOST:
		omap_control_usb_host_mode(ctrl);
		break;
	case DEVICE:
		omap_control_usb_device(ctrl)
		break;
	default:
		meh();
	}
}

likewise for power() method

-- 
balbi

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 192 bytes --]

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] drivers: usb: phy: add a new driver for usb part of control module
       [not found]       ` <20130118115909.GA4672-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
@ 2013-01-18 12:10         ` kishon
       [not found]           ` <50F93B9C.108-l0cyMroinI0@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: kishon @ 2013-01-18 12:10 UTC (permalink / raw)
  To: balbi-l0cyMroinI0
  Cc: linux-lFZ/pmaqli7XmaaqVzeoHQ, linux-doc-u79uwXL29TY76Z2rM5mHXA,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	rob.herring-bsGFqQB8/DxBDgjK7y7TUQ,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

Hi,

On Friday 18 January 2013 05:29 PM, Felipe Balbi wrote:
> Hi,
>
> On Fri, Jan 18, 2013 at 03:10:42PM +0530, Kishon Vijay Abraham I wrote:
>> Added a new driver for the usb part of control module. This has an API
>> to power on the USB2 phy and an API to write to the mailbox depending on
>> whether MUSB has to act in host mode or in device mode.
>>
>> Writing to control module registers for doing the above task which was
>> previously done in omap glue and in omap-usb2 phy will be removed.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
>> ---
>>   Documentation/devicetree/bindings/usb/omap-usb.txt |   26 ++-
>>   Documentation/devicetree/bindings/usb/usb-phy.txt  |    5 +
>>   drivers/usb/phy/Kconfig                            |    9 +
>>   drivers/usb/phy/Makefile                           |    1 +
>>   drivers/usb/phy/omap-control-usb.c                 |  204 ++++++++++++++++++++
>>   include/linux/usb/omap_control_usb.h               |   72 +++++++
>>   6 files changed, 316 insertions(+), 1 deletion(-)
>>   create mode 100644 drivers/usb/phy/omap-control-usb.c
>>   create mode 100644 include/linux/usb/omap_control_usb.h
>>
>> diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
>> index 29a043e..ead6ba9 100644
>> --- a/Documentation/devicetree/bindings/usb/omap-usb.txt
>> +++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
>> @@ -1,4 +1,4 @@
>> -OMAP GLUE
>> +OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS
>>
>>   OMAP MUSB GLUE
>>    - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"
>> @@ -16,6 +16,10 @@ OMAP MUSB GLUE
>>    - power : Should be "50". This signifies the controller can supply upto
>>      100mA when operating in host mode.
>>
>> +Optional properties:
>> + - ctrl_module : phandle of the control module this glue uses to write to
>> +   mailbox
>> +
>>   SOC specific device node entry
>>   usb_otg_hs: usb_otg_hs@4a0ab000 {
>>   	compatible = "ti,omap4-musb";
>> @@ -23,6 +27,7 @@ usb_otg_hs: usb_otg_hs@4a0ab000 {
>>   	multipoint = <1>;
>>   	num_eps = <16>;
>>   	ram_bits = <12>;
>> +	ctrl_module = <&omap_control_usb>;
>>   };
>>
>>   Board specific device node entry
>> @@ -31,3 +36,22 @@ Board specific device node entry
>>   	mode = <3>;
>>   	power = <50>;
>>   };
>> +
>> +OMAP CONTROL USB
>> +
>> +Required properties:
>> + - compatible: Should be "ti,omap-control-usb"
>> + - reg : Address and length of the register set for the device. It contains
>> +   the address of "control_dev_conf" and "otghs_control".
>> + - reg-names: The names of the register addresses corresponding to the registers
>> +   filled in "reg".
>> + - ti,has_mailbox: This is used to specify if the platform has mailbox in
>> +   control module.
>> +
>> +omap_control_usb: omap-control-usb@4a002300 {
>> +	compatible = "ti,omap-control-usb";
>> +	reg = <0x4a002300 0x4>,
>> +	      <0x4a00233c 0x4>;
>> +	reg-names = "control_dev_conf", "otghs_control";
>> +	ti,has_mailbox;
>> +};
>> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
>> index 80d4148..2466b6f 100644
>> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
>> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
>> @@ -8,10 +8,15 @@ Required properties:
>>   add the address of control module dev conf register until a driver for
>>   control module is added
>>
>> +Optional properties:
>> + - ctrl_module : phandle of the control module used by PHY driver to power on
>> +   the PHY.
>> +
>>   This is usually a subnode of ocp2scp to which it is connected.
>>
>>   usb2phy@4a0ad080 {
>>   	compatible = "ti,omap-usb2";
>>   	reg = <0x4a0ad080 0x58>,
>>   	      <0x4a002300 0x4>;
>> +	ctrl_module = <&omap_control_usb>;
>>   };
>> diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
>> index 5de6e7f..a7277ee 100644
>> --- a/drivers/usb/phy/Kconfig
>> +++ b/drivers/usb/phy/Kconfig
>> @@ -14,6 +14,15 @@ config OMAP_USB2
>>   	  The USB OTG controller communicates with the comparator using this
>>   	  driver.
>>
>> +config OMAP_CONTROL_USB
>> +	tristate "OMAP CONTROL USB Driver"
>> +	depends on ARCH_OMAP2PLUS
>> +	help
>> +	  Enable this to add support for the USB part present in the control
>> +	  module. This driver has API to power on the PHY and to write to the
>> +	  mailbox. The mailbox is present only in omap4 and the register to
>> +	  power on the PHY is present in omap4 and omap5.
>> +
>>   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 1a579a8..0dea4d2 100644
>> --- a/drivers/usb/phy/Makefile
>> +++ b/drivers/usb/phy/Makefile
>> @@ -5,6 +5,7 @@
>>   ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
>>
>>   obj-$(CONFIG_OMAP_USB2)			+= omap-usb2.o
>> +obj-$(CONFIG_OMAP_CONTROL_USB)		+= omap-control-usb.o
>>   obj-$(CONFIG_USB_ISP1301)		+= isp1301.o
>>   obj-$(CONFIG_MV_U3D_PHY)		+= mv_u3d_phy.o
>>   obj-$(CONFIG_USB_EHCI_TEGRA)	+= tegra_usb_phy.o
>> diff --git a/drivers/usb/phy/omap-control-usb.c b/drivers/usb/phy/omap-control-usb.c
>> new file mode 100644
>> index 0000000..7edeb41
>> --- /dev/null
>> +++ b/drivers/usb/phy/omap-control-usb.c
>> @@ -0,0 +1,204 @@
>> +/*
>> + * omap-control-usb.c - The USB part of control module.
>> + *
>> + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
>> + * 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.
>> + *
>> + * Author: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
>> + *
>> + * 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/module.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/slab.h>
>> +#include <linux/of.h>
>> +#include <linux/err.h>
>> +#include <linux/io.h>
>> +#include <linux/usb/omap_control_usb.h>
>> +
>> +static struct omap_control_usb *control_usb;
>> +
>> +/**
>> + * get_omap_control_dev - returns the device pointer for this control device
>> + *
>> + * This API should be called to get the device pointer for this control
>> + * module device. This device pointer should be passed to all other API's
>> + * in this driver.
>> + *
>> + * To be used by PHY driver and glue driver
>> + */
>> +struct device *get_omap_control_dev(void)
>
> let's do a small rename here and call it:
>
> omap_get_control_dev(), just to keep consistency with rest of the file.

Ok.
>
>> +{
>> +	if (!control_usb)
>> +		return ERR_PTR(-ENODEV);
>> +
>> +	return control_usb->dev;
>> +}
>> +EXPORT_SYMBOL_GPL(get_omap_control_dev);
>> +
>> +/**
>> + * omap_control_usb_phy_power - power on/off the phy using control module reg
>> + * @dev: the control module device
>> + * @on: 0 or 1, based on powering on or off the PHY
>> + */
>> +void omap_control_usb_phy_power(struct device *dev, int on)
>> +{
>> +	u32 val;
>> +	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
>> +
>> +	if (on) {
>> +		val = readl(control_usb->dev_conf);
>> +		if (val & PHY_PD)
>> +			writel(~PHY_PD, control_usb->dev_conf);
>> +	} else {
>> +		writel(PHY_PD, control_usb->dev_conf);
>> +	}
>
> this can be better. I would rather have this:
>
> struct omap_control_usb *ctrl = dev_get_drvdata(dev);
> u32 val;
>
> val = readl(ctrl->dev_conf);
>
> if (on)
> 	val &= ~OMAP_CTRL_DEV_PHY_PD;
> else
> 	val |= OMAP_CTRL_DEV_PHY_PD;
>
> writel(val, ctrl->dev_conf);
>
>
>
>> +}
>> +EXPORT_SYMBOL_GPL(omap_control_usb_phy_power);
>> +
>> +/**
>> + * omap_control_usb_host_mode - set AVALID, VBUSVALID and ID pin in grounded
>> + * @dev: struct device *
>> + *
>> + * This is an API to write to the mailbox register to notify the usb core that
>> + * a usb device has been connected.
>> + */
>> +void omap_control_usb_host_mode(struct device *dev)
>> +{
>> +	u32 val;
>> +	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
>> +
>> +	val = AVALID | VBUSVALID;
>> +
>> +	writel(val, control_usb->otghs_control);
>
> I would like to make this future proof too:
>
> val = readl(ctrl->otghs_control);
> val |= OMAP_CTRL_DEV_AVALID | OMAP_CTRL_DEV_VBUSVALID;
> writel(val, ctrl->otghs_control);

I think we might then have to add
val &= ~(IDDIG | SESSEND) right?

Similar things should be done for below API's also so that we don't 
inadvertently carry forward the settings.
>
>> +void omap_control_usb_device_mode(struct device *dev)
>> +{
>> +	u32 val;
>> +	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
>> +
>> +	val = IDDIG | AVALID | VBUSVALID;
>
> ditto. Read it before changing it. (the idea is that in future the other
> bits might be used for something else, so you risk breaking future
> functionality).
>
>> +
>> +	writel(val, control_usb->otghs_control);
>> +}
>> +EXPORT_SYMBOL_GPL(omap_control_usb_device_mode);
>> +
>> +/**
>> + * omap_control_usb_set_sessionend - Enable SESSIONEND and IDIG to high
>> + * impedance
>> + * @dev: struct device *
>> + *
>> + * This is an API to write to the mailbox register to notify the usb core
>> + * it's now in disconnected state.
>> + */
>> +void omap_control_usb_set_sessionend(struct device *dev)
>> +{
>> +	u32 val;
>> +	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
>> +
>> +	val = SESSEND | IDDIG;
>
> ditto
>
>> +
>> +	writel(val, control_usb->otghs_control);
>> +}
>> +EXPORT_SYMBOL_GPL(omap_control_usb_set_sessionend);
>> +
>> +static int omap_control_usb_probe(struct platform_device *pdev)
>> +{
>> +	struct resource	*res;
>> +	struct device_node *np = pdev->dev.of_node;
>> +	struct omap_control_usb_platform_data *pdata = pdev->dev.platform_data;
>> +
>> +	control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb),
>> +	    GFP_KERNEL);
>
> you're using space indentation here.
>
>> +	if (!control_usb) {
>> +		dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
>> +		return -ENOMEM;
>> +	}
>> +
>> +	if (np) {
>> +		control_usb->has_mailbox = of_property_read_bool(np,
>> +		    "ti,has_mailbox");
>> +	} else if (pdata) {
>> +		control_usb->has_mailbox = pdata->has_mailbox;
>> +	} else {
>> +		dev_err(&pdev->dev, "no pdata present\n");
>> +		return -EINVAL;
>
> does it make sense to default to has_mailbox as true ? I mean, seems
> like this is how it's going to be in future devices looking at the
> current trend.

No actually. omap5 doesn't have mailbox in control module ;-)
>
> Another idea is to try to get the extra resource below, if it fails you
> try to continue without it ;-)

I prefer the way it is now because mailbox is needed for MUSB to be 
functional in OMAP4 and we should fail if we don't have it. No?
>
>> +	}
>> +
>> +	control_usb->dev	= &pdev->dev;
>> +
>> +	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
>> +	    "control_dev_conf");
>
> using space indentation here again.
>
>> +	control_usb->dev_conf = devm_request_and_ioremap(&pdev->dev, res);
>> +	if (control_usb->dev_conf == NULL) {
>> +		dev_err(&pdev->dev, "Failed to obtain io memory\n");
>> +		return -EADDRNOTAVAIL;
>> +	}
>> +
>> +	if (control_usb->has_mailbox) {
>> +		res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
>> +		    "otghs_control");
>> +		control_usb->otghs_control = devm_request_and_ioremap(
>> +		    &pdev->dev, res);
>> +		if (control_usb->otghs_control == NULL) {
>> +			dev_err(&pdev->dev, "Failed to obtain io memory\n");
>> +			return -EADDRNOTAVAIL;
>> +		}
>> +	}
>> +
>> +	dev_set_drvdata(control_usb->dev, control_usb);
>> +
>> +	return 0;
>> +}
>> +
>> +#ifdef CONFIG_OF
>> +static const struct of_device_id omap_control_usb_id_table[] = {
>> +	{ .compatible = "ti,omap-control-usb" },
>> +	{}
>> +};
>> +MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
>> +#endif
>> +
>> +static struct platform_driver omap_control_usb_driver = {
>> +	.probe		= omap_control_usb_probe,
>> +	.driver		= {
>> +		.name	= "omap-control-usb",
>> +		.owner	= THIS_MODULE,
>
> no need to set owner here. When you register the platform_driver, it
> will be set for you.

Ok.
>
>> +		.of_match_table = of_match_ptr(omap_control_usb_id_table),
>> +	},
>> +};
>> +
>> +static int __init omap_control_usb_init(void)
>> +{
>> +	return platform_driver_register(&omap_control_usb_driver);
>> +}
>> +subsys_initcall(omap_control_usb_init);
>> +
>> +static void __exit omap_control_usb_exit(void)
>> +{
>> +	platform_driver_unregister(&omap_control_usb_driver);
>> +}
>> +module_exit(omap_control_usb_exit);
>> +
>> +MODULE_ALIAS("platform: omap_control_usb");
>> +MODULE_AUTHOR("Texas Instruments Inc.");
>> +MODULE_DESCRIPTION("OMAP CONTROL USB DRIVER");
>
> don't scream to your users like that ;-)
>
> MODULE_DESCRIPTION("OMAP Control Module USB Driver");

Ok.
>
>> +MODULE_LICENSE("GPL v2");
>> diff --git a/include/linux/usb/omap_control_usb.h b/include/linux/usb/omap_control_usb.h
>> new file mode 100644
>> index 0000000..a16f993
>> --- /dev/null
>> +++ b/include/linux/usb/omap_control_usb.h
>> @@ -0,0 +1,72 @@
>> +/*
>> + * omap_control_usb.h - Header file for the USB part of control module.
>> + *
>> + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
>> + * 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.
>> + *
>> + * Author: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
>> + *
>> + * 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.
>> + *
>> + */
>> +
>> +#ifndef __OMAP_CONTROL_USB_H__
>> +#define __OMAP_CONTROL_USB_H__
>> +
>> +struct omap_control_usb {
>> +	struct device *dev;
>> +
>> +	u32 __iomem *dev_conf;
>> +	u32 __iomem *otghs_control;
>> +
>> +	u8 has_mailbox:1;
>> +};
>> +
>> +struct omap_control_usb_platform_data {
>> +	u8 has_mailbox:1;
>> +};
>> +
>> +#define	PHY_PD		BIT(0)
>> +
>> +#define	AVALID		BIT(0)
>> +#define	BVALID		BIT(1)
>> +#define	VBUSVALID	BIT(2)
>> +#define	SESSEND		BIT(3)
>> +#define	IDDIG		BIT(4)
>
> please prepend with OMAP_CTRL_ or something similar.

Sure.

Thanks
Kishon

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4] drivers: usb: start using the control module driver
  2013-01-18 12:02       ` Felipe Balbi
@ 2013-01-18 12:11         ` kishon
  0 siblings, 0 replies; 11+ messages in thread
From: kishon @ 2013-01-18 12:11 UTC (permalink / raw)
  To: balbi
  Cc: rob.herring, rob, tony, b-cousson, linux-usb, linux-arm-kernel,
	linux-omap, linux-kernel, linux-doc, devicetree-discuss,
	grant.likely, linux, gregkh

On Friday 18 January 2013 05:32 PM, Felipe Balbi wrote:
> Hi,
>
> On Fri, Jan 18, 2013 at 03:10:45PM +0530, Kishon Vijay Abraham I wrote:
>> Start using the control module driver for powering on the PHY and for
>> writing to the mailbox instead of writing to the control module
>> registers on their own.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>>   Documentation/devicetree/bindings/usb/omap-usb.txt |    4 ++
>>   Documentation/devicetree/bindings/usb/usb-phy.txt  |    7 +--
>>   arch/arm/mach-omap2/omap_hwmod_44xx_data.c         |   13 ----
>>   drivers/usb/musb/Kconfig                           |    1 +
>>   drivers/usb/musb/omap2430.c                        |   64 ++++++++------------
>>   drivers/usb/musb/omap2430.h                        |    9 ---
>>   drivers/usb/phy/Kconfig                            |    1 +
>>   drivers/usb/phy/omap-usb2.c                        |   38 +++---------
>>   include/linux/usb/omap_usb.h                       |    4 +-
>>   9 files changed, 42 insertions(+), 99 deletions(-)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
>> index ead6ba9..8bedbba 100644
>> --- a/Documentation/devicetree/bindings/usb/omap-usb.txt
>> +++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
>> @@ -3,6 +3,9 @@ OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS
>>   OMAP MUSB GLUE
>>    - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"
>>    - ti,hwmods : must be "usb_otg_hs"
>> + - ti,has_mailbox : to specify that omap uses an external mailbox
>> +   (in control module) to communicate with the musb core during device connect
>> +   and disconnect.
>>    - multipoint : Should be "1" indicating the musb controller supports
>>      multipoint. This is a MUSB configuration-specific setting.
>>    - num_eps : Specifies the number of endpoints. This is also a
>> @@ -24,6 +27,7 @@ SOC specific device node entry
>>   usb_otg_hs: usb_otg_hs@4a0ab000 {
>>   	compatible = "ti,omap4-musb";
>>   	ti,hwmods = "usb_otg_hs";
>> +	ti,has_mailbox;
>>   	multipoint = <1>;
>>   	num_eps = <16>;
>>   	ram_bits = <12>;
>> diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
>> index 2466b6f..48761a2 100644
>> --- a/Documentation/devicetree/bindings/usb/usb-phy.txt
>> +++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
>> @@ -4,9 +4,7 @@ OMAP USB2 PHY
>>
>>   Required properties:
>>    - compatible: Should be "ti,omap-usb2"
>> - - reg : Address and length of the register set for the device. Also
>> -add the address of control module dev conf register until a driver for
>> -control module is added
>> + - reg : Address and length of the register set for the device.
>>
>>   Optional properties:
>>    - ctrl_module : phandle of the control module used by PHY driver to power on
>> @@ -16,7 +14,6 @@ This is usually a subnode of ocp2scp to which it is connected.
>>
>>   usb2phy@4a0ad080 {
>>   	compatible = "ti,omap-usb2";
>> -	reg = <0x4a0ad080 0x58>,
>> -	      <0x4a002300 0x4>;
>> +	reg = <0x4a0ad080 0x58>;
>>   	ctrl_module = <&omap_control_usb>;
>>   };
>> diff --git a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
>> index 129d508..103f4ba 100644
>> --- a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
>> +++ b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
>> @@ -2698,13 +2698,6 @@ static struct resource omap44xx_usb_phy_and_pll_addrs[] = {
>>   		.end		= 0x4a0ae000,
>>   		.flags		= IORESOURCE_MEM,
>>   	},
>> -	{
>> -		/* XXX: Remove this once control module driver is in place */
>> -		.name		= "ctrl_dev",
>> -		.start		= 0x4a002300,
>> -		.end		= 0x4a002303,
>> -		.flags		= IORESOURCE_MEM,
>> -	},
>>   	{ }
>>   };
>>
>> @@ -6152,12 +6145,6 @@ static struct omap_hwmod_addr_space omap44xx_usb_otg_hs_addrs[] = {
>>   		.pa_end		= 0x4a0ab7ff,
>>   		.flags		= ADDR_TYPE_RT
>>   	},
>> -	{
>> -		/* XXX: Remove this once control module driver is in place */
>> -		.pa_start	= 0x4a00233c,
>> -		.pa_end		= 0x4a00233f,
>> -		.flags		= ADDR_TYPE_RT
>> -	},
>>   	{ }
>>   };
>>
>> diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
>> index 23a0b7f..de6e5ce 100644
>> --- a/drivers/usb/musb/Kconfig
>> +++ b/drivers/usb/musb/Kconfig
>> @@ -11,6 +11,7 @@ config USB_MUSB_HDRC
>>   	select NOP_USB_XCEIV if (SOC_TI81XX || SOC_AM33XX)
>>   	select TWL4030_USB if MACH_OMAP_3430SDP
>>   	select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
>> +	select OMAP_CONTROL_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
>>   	select USB_OTG_UTILS
>>   	help
>>   	  Say Y here if your system has a dual role high speed USB
>> diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
>> index da00af4..3e7ceef 100644
>> --- a/drivers/usb/musb/omap2430.c
>> +++ b/drivers/usb/musb/omap2430.c
>> @@ -37,6 +37,7 @@
>>   #include <linux/err.h>
>>   #include <linux/delay.h>
>>   #include <linux/usb/musb-omap.h>
>> +#include <linux/usb/omap_control_usb.h>
>>
>>   #include "musb_core.h"
>>   #include "omap2430.h"
>> @@ -46,7 +47,7 @@ struct omap2430_glue {
>>   	struct platform_device	*musb;
>>   	enum omap_musb_vbus_id_status status;
>>   	struct work_struct	omap_musb_mailbox_work;
>> -	u32 __iomem		*control_otghs;
>> +	struct device		*control_otghs;
>>   };
>>   #define glue_to_musb(g)		platform_get_drvdata(g->musb)
>>
>> @@ -54,26 +55,6 @@ struct omap2430_glue		*_glue;
>>
>>   static struct timer_list musb_idle_timer;
>>
>> -/**
>> - * omap4_usb_phy_mailbox - write to usb otg mailbox
>> - * @glue: struct omap2430_glue *
>> - * @val: the value to be written to the mailbox
>> - *
>> - * On detection of a device (ID pin is grounded), this API should be called
>> - * to set AVALID, VBUSVALID and ID pin is grounded.
>> - *
>> - * When OMAP is connected to a host (OMAP in device mode), this API
>> - * is called to set AVALID, VBUSVALID and ID pin in high impedance.
>> - *
>> - * XXX: This function will be removed once we have a seperate driver for
>> - * control module
>> - */
>> -static void omap4_usb_phy_mailbox(struct omap2430_glue *glue, u32 val)
>> -{
>> -	if (glue->control_otghs)
>> -		writel(val, glue->control_otghs);
>> -}
>> -
>>   static void musb_do_idle(unsigned long _musb)
>>   {
>>   	struct musb	*musb = (void *)_musb;
>> @@ -269,7 +250,6 @@ EXPORT_SYMBOL_GPL(omap_musb_mailbox);
>>
>>   static void omap_musb_set_mailbox(struct omap2430_glue *glue)
>>   {
>> -	u32 val;
>>   	struct musb *musb = glue_to_musb(glue);
>>   	struct device *dev = musb->controller;
>>   	struct musb_hdrc_platform_data *pdata = dev->platform_data;
>> @@ -285,8 +265,8 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
>>   		musb->xceiv->last_event = USB_EVENT_ID;
>>   		if (musb->gadget_driver) {
>>   			pm_runtime_get_sync(dev);
>> -			val = AVALID | VBUSVALID;
>> -			omap4_usb_phy_mailbox(glue, val);
>> +			if (!IS_ERR(glue->control_otghs))
>> +				omap_control_usb_host_mode(glue->control_otghs);
>
> you could introduce a helper to do the checks for you. something like:
>
> static inline void omap_control_set_mode(*ctrl, int mode)
> {
> 	if (IS_ERR(glue->control_otghs))
> 		return;
>
> 	switch (mode) {
> 	case HOST:
> 		omap_control_usb_host_mode(ctrl);
> 		break;
> 	case DEVICE:
> 		omap_control_usb_device(ctrl)
> 		break;
> 	default:
> 		meh();
> 	}
> }
>
> likewise for power() method

Ok.

Thanks
Kishon

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] drivers: usb: phy: add a new driver for usb part of control module
       [not found]           ` <50F93B9C.108-l0cyMroinI0@public.gmane.org>
@ 2013-01-18 12:13             ` Felipe Balbi
  0 siblings, 0 replies; 11+ messages in thread
From: Felipe Balbi @ 2013-01-18 12:13 UTC (permalink / raw)
  To: kishon
  Cc: linux-lFZ/pmaqli7XmaaqVzeoHQ, linux-doc-u79uwXL29TY76Z2rM5mHXA,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	rob.herring-bsGFqQB8/DxBDgjK7y7TUQ, balbi-l0cyMroinI0,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r


[-- Attachment #1.1: Type: text/plain, Size: 926 bytes --]

Hi,

On Fri, Jan 18, 2013 at 05:40:04PM +0530, kishon wrote:
> >>+void omap_control_usb_host_mode(struct device *dev)
> >>+{
> >>+	u32 val;
> >>+	struct omap_control_usb	*control_usb = dev_get_drvdata(dev);
> >>+
> >>+	val = AVALID | VBUSVALID;
> >>+
> >>+	writel(val, control_usb->otghs_control);
> >
> >I would like to make this future proof too:
> >
> >val = readl(ctrl->otghs_control);
> >val |= OMAP_CTRL_DEV_AVALID | OMAP_CTRL_DEV_VBUSVALID;
> >writel(val, ctrl->otghs_control);
> 
> I think we might then have to add
> val &= ~(IDDIG | SESSEND) right?

right, my bad ;-)

> >Another idea is to try to get the extra resource below, if it fails you
> >try to continue without it ;-)
> 
> I prefer the way it is now because mailbox is needed for MUSB to be
> functional in OMAP4 and we should fail if we don't have it. No?

could be, that would mean an error on DT data though.

-- 
balbi

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 192 bytes --]

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-01-18 12:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-18  9:40 [PATCH 0/4] usb: musb: add driver for control module Kishon Vijay Abraham I
2013-01-18  9:40 ` [PATCH 1/4] drivers: usb: phy: add a new driver for usb part of " Kishon Vijay Abraham I
     [not found]   ` <1358502045-27008-2-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2013-01-18 11:59     ` Felipe Balbi
     [not found]       ` <20130118115909.GA4672-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2013-01-18 12:10         ` kishon
     [not found]           ` <50F93B9C.108-l0cyMroinI0@public.gmane.org>
2013-01-18 12:13             ` Felipe Balbi
     [not found] ` <1358502045-27008-1-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2013-01-18  9:40   ` [PATCH 2/4] ARM: OMAP: devices: create device " Kishon Vijay Abraham I
     [not found]     ` <1358502045-27008-3-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2013-01-18 12:00       ` Felipe Balbi
2013-01-18  9:40   ` [PATCH 4/4] drivers: usb: start using the control module driver Kishon Vijay Abraham I
     [not found]     ` <1358502045-27008-5-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2013-01-18 12:02       ` Felipe Balbi
2013-01-18 12:11         ` kishon
2013-01-18  9:40 ` [PATCH 3/4] ARM: OMAP2: MUSB: Specify omap4 has mailbox Kishon Vijay Abraham I

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).