linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: rogerq@ti.com (Roger Quadros)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 02/21] ARM: OMAP2+: omap-usb-host: Add usbhs_init_phys()
Date: Wed, 20 Mar 2013 17:44:41 +0200	[thread overview]
Message-ID: <1363794300-31526-3-git-send-email-rogerq@ti.com> (raw)
In-Reply-To: <1363794300-31526-1-git-send-email-rogerq@ti.com>

This helper allows board support code to add the PHY's
VCC and RESET regulators which are GPIO controlled as well
as the NOP PHY device.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 arch/arm/mach-omap2/usb-host.c |  160 +++++++++++++++++++++++++++++++++++++++-
 arch/arm/mach-omap2/usb.h      |    9 ++
 2 files changed, 167 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-omap2/usb-host.c b/arch/arm/mach-omap2/usb-host.c
index 5706bdc..aa27d7f 100644
--- a/arch/arm/mach-omap2/usb-host.c
+++ b/arch/arm/mach-omap2/usb-host.c
@@ -22,8 +22,12 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/dma-mapping.h>
-
-#include <asm/io.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/fixed.h>
+#include <linux/string.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/usb/phy.h>
 
 #include "soc.h"
 #include "omap_device.h"
@@ -526,3 +530,155 @@ void __init usbhs_init(struct usbhs_omap_platform_data *pdata)
 }
 
 #endif
+
+/* Template for PHY regulators */
+static struct fixed_voltage_config hsusb_reg_config = {
+	/* .supply_name filled later */
+	.microvolts = 3300000,
+	.gpio = -1,		/* updated later */
+	.startup_delay = 70000, /* 70msec */
+	.enable_high = 1,	/* updated later */
+	.enabled_at_boot = 0,	/* keep in RESET */
+	/* .init_data filled later */
+};
+
+static const char *nop_name = "nop_usb_xceiv"; /* NOP PHY driver */
+static const char *reg_name = "reg-fixed-voltage"; /* Regulator driver */
+
+/**
+ * usbhs_add_regulator - Add a gpio based fixed voltage regulator device
+ * @name: name for the regulator
+ * @dev_id: device id of the device this regulator supplies power to
+ * @dev_supply: supply name that the device expects
+ * @gpio: GPIO number
+ * @polarity: 1 - Active high, 0 - Active low
+ */
+static int usbhs_add_regulator(char *name, char *dev_id, char *dev_supply,
+						int gpio, int polarity)
+{
+	struct regulator_consumer_supply *supplies;
+	struct regulator_init_data *reg_data;
+	struct fixed_voltage_config *config;
+	struct platform_device *pdev;
+	int ret;
+
+	supplies = kzalloc(sizeof(*supplies), GFP_KERNEL);
+	if (!supplies)
+		return -ENOMEM;
+
+	supplies->supply = dev_supply;
+	supplies->dev_name = dev_id;
+
+	reg_data = kzalloc(sizeof(*reg_data), GFP_KERNEL);
+	if (!reg_data)
+		return -ENOMEM;
+
+	reg_data->constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS;
+	reg_data->consumer_supplies = supplies;
+	reg_data->num_consumer_supplies = 1;
+
+	config = kmemdup(&hsusb_reg_config, sizeof(hsusb_reg_config),
+			GFP_KERNEL);
+	if (!config)
+		return -ENOMEM;
+
+	config->supply_name = name;
+	config->gpio = gpio;
+	config->enable_high = polarity;
+	config->init_data = reg_data;
+
+	/* create a regulator device */
+	pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
+	if (!pdev)
+		return -ENOMEM;
+
+	pdev->id = PLATFORM_DEVID_AUTO;
+	pdev->name = reg_name;
+	pdev->dev.platform_data = config;
+
+	ret = platform_device_register(pdev);
+	if (ret)
+		pr_err("%s: Failed registering regulator %s for %s\n",
+				__func__, name, dev_id);
+
+	return ret;
+}
+
+int usbhs_init_phys(struct usbhs_phy_data *phy, int num_phys)
+{
+	char *rail_name;
+	int i, len;
+	struct platform_device *pdev;
+	char *phy_id;
+
+	/* the phy_id will be something like "nop_usb_xceiv.1" */
+	len = strlen(nop_name) + 3; /* 3 -> ".1" and NULL terminator */
+
+	for (i = 0; i < num_phys; i++) {
+
+		if (!phy->port) {
+			pr_err("%s: Invalid port 0. Must start from 1\n",
+						__func__);
+			continue;
+		}
+
+		/* do we need a NOP PHY device ? */
+		if (!gpio_is_valid(phy->reset_gpio) &&
+			!gpio_is_valid(phy->vcc_gpio))
+			continue;
+
+		/* create a NOP PHY device */
+		pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
+		if (!pdev)
+			return -ENOMEM;
+
+		pdev->id = phy->port;
+		pdev->name = nop_name;
+		pdev->dev.platform_data = phy->platform_data;
+
+		phy_id = kmalloc(len, GFP_KERNEL);
+		if (!phy_id)
+			return -ENOMEM;
+
+		scnprintf(phy_id, len, "nop_usb_xceiv.%d\n",
+					pdev->id);
+
+		if (platform_device_register(pdev)) {
+			pr_err("%s: Failed to register device %s\n",
+				__func__,  phy_id);
+			continue;
+		}
+
+		usb_bind_phy("ehci-omap.0", phy->port - 1, phy_id);
+
+		/* Do we need RESET regulator ? */
+		if (gpio_is_valid(phy->reset_gpio)) {
+
+			rail_name = kmalloc(13, GFP_KERNEL);
+			if (!rail_name)
+				return -ENOMEM;
+
+			scnprintf(rail_name, 13, "hsusb%d_reset", phy->port);
+
+			usbhs_add_regulator(rail_name, phy_id, "reset",
+						phy->reset_gpio, 1);
+		}
+
+		/* Do we need VCC regulator ? */
+		if (gpio_is_valid(phy->vcc_gpio)) {
+
+			rail_name = kmalloc(13, GFP_KERNEL);
+			if (!rail_name)
+				return -ENOMEM;
+
+			scnprintf(rail_name, 13, "hsusb%d_vcc", phy->port);
+
+			usbhs_add_regulator(rail_name, phy_id, "vcc",
+					phy->vcc_gpio, phy->vcc_polarity);
+		}
+
+		phy++;
+	}
+
+	return 0;
+}
diff --git a/arch/arm/mach-omap2/usb.h b/arch/arm/mach-omap2/usb.h
index 3319f5c..e7261eb 100644
--- a/arch/arm/mach-omap2/usb.h
+++ b/arch/arm/mach-omap2/usb.h
@@ -53,8 +53,17 @@
 #define USBPHY_OTGSESSEND_EN	(1 << 20)
 #define USBPHY_DATA_POLARITY	(1 << 23)
 
+struct usbhs_phy_data {
+	int port;		/* 1 indexed port number */
+	int reset_gpio;
+	int vcc_gpio;
+	bool vcc_polarity;	/* 1 active high, 0 active low */
+	void *platform_data;
+};
+
 extern void usb_musb_init(struct omap_musb_board_data *board_data);
 extern void usbhs_init(struct usbhs_omap_platform_data *pdata);
+extern int usbhs_init_phys(struct usbhs_phy_data *phy, int num_phys);
 
 extern void am35x_musb_reset(void);
 extern void am35x_musb_phy_power(u8 on);
-- 
1.7.4.1

  parent reply	other threads:[~2013-03-20 15:44 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-20 15:44 [PATCH v4 00/21] ARM: OMAP2+: Adapt to ehci-omap changes for 3.10 Roger Quadros
2013-03-20 15:44 ` [PATCH v4 01/21] usb: phy: nop: Add some parameters to platform data Roger Quadros
2013-03-20 15:55   ` Felipe Balbi
2013-03-20 16:13     ` Tony Lindgren
2013-03-20 16:19       ` Felipe Balbi
2013-04-02 17:21         ` Tony Lindgren
2013-04-03 14:53           ` Roger Quadros
2013-03-20 15:44 ` Roger Quadros [this message]
2013-03-20 15:44 ` [PATCH v4 03/21] ARM: OMAP2+: omap4panda: Adapt to ehci-omap changes Roger Quadros
2013-03-20 15:44 ` [PATCH v4 04/21] ARM: OMAP3: Beagle: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 05/21] ARM: OMAP3: 3430SDP: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 06/21] ARM: OMAP3: 3630SDP: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 07/21] ARM: OMAP: AM3517crane: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 08/21] ARM: OMAP: AM3517evm: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 09/21] ARM: OMAP3: cm-t35: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 10/21] ARM: OMAP3: cm-t3517: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 11/21] ARM: OMAP: devkit8000: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 12/21] ARM: OMAP3: igep0020: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 13/21] ARM: OMAP3: omap3evm: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 14/21] ARM: OMAP3: omap3pandora: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 15/21] ARM: OMAP3: omap3stalker: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 16/21] ARM: OMAP3: omap3touchbook: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 17/21] ARM: OMAP3: overo: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 18/21] ARM: OMAP: zoom: " Roger Quadros
2013-03-20 15:44 ` [PATCH v4 19/21] ARM: dts: OMAP4: Add HS USB Host IP nodes Roger Quadros
2013-03-20 15:44 ` [PATCH v4 20/21] ARM: dts: OMAP3: " Roger Quadros
2013-03-20 15:45 ` [PATCH v4 21/21] ARM: dts: omap3-beagle: Add USB Host support Roger Quadros
2013-04-05  8:30 ` [PATCH v4 00/21] ARM: OMAP2+: Adapt to ehci-omap changes for 3.10 Benoit Cousson
2013-04-05  9:56   ` Benoit Cousson
2013-04-05 15:43     ` Tony Lindgren
2013-04-08 12:06       ` Benoit Cousson
2013-04-08 17:09         ` Tony Lindgren

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=1363794300-31526-3-git-send-email-rogerq@ti.com \
    --to=rogerq@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

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

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