linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Green <andy.green@linaro.org>
To: stern@rowland.harvard.edu
Cc: linux-omap@vger.kernel.org, keshava_mgowda@ti.com,
	linux-usb@vger.kernel.org, balbi@ti.com, rogerq@ti.com
Subject: [RFC PATCH 3/5] usb: hub: add device_path regulator control to generic hub
Date: Mon, 26 Nov 2012 12:45:45 +0000	[thread overview]
Message-ID: <20121126124544.18106.60130.stgit@build.warmcat.com> (raw)
In-Reply-To: <20121126123427.18106.4112.stgit@build.warmcat.com>

This adds the config option to associate a regulator with each hub,
when the hub on a specific, interesting device path appears, then
the regular is powered while the logical hub exists.

Signed-off-by: Andy Green <andy.green@linaro.org>
---
 drivers/usb/core/Kconfig |   10 ++++++++++
 drivers/usb/core/hub.c   |   26 +++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index f70c1a1..4a91eb1 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -95,3 +95,13 @@ config USB_OTG_BLACKLIST_HUB
 	  and software costs by not supporting external hubs.  So
 	  are "Embedded Hosts" that don't offer OTG support.
 
+config USB_HUB_DEVICE_PATH_REGULATOR
+	bool "Support generic regulators at hubs"
+	select DEVICEPATH
+	depends on USB
+	default n
+	help
+	  Allows you to use the device_path APIs to associate kernel regulators
+	  with dynamically probed USB hubs, so the regulators are enabled
+	  as the appropriate hub instance gets created and disabled as it
+	  is destroyed.
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index a815fd2..49ebb5e 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -26,6 +26,7 @@
 #include <linux/mutex.h>
 #include <linux/freezer.h>
 #include <linux/random.h>
+#include <linux/regulator/consumer.h>
 
 #include <asm/uaccess.h>
 #include <asm/byteorder.h>
@@ -54,7 +55,9 @@ struct usb_hub {
 	struct usb_device	*hdev;
 	struct kref		kref;
 	struct urb		*urb;		/* for interrupt polling pipe */
-
+#ifdef CONFIG_USB_HUB_DEVICE_PATH_REGULATOR
+	struct regulator	*regulator;	/* optional power control */
+#endif
 	/* buffer for urb ... with extra space in case of babble */
 	char			(*buffer)[8];
 	union {
@@ -1594,6 +1597,12 @@ static void hub_disconnect(struct usb_interface *intf)
 	if (hub->hdev->speed == USB_SPEED_HIGH)
 		highspeed_hubs--;
 
+#ifdef CONFIG_USB_HUB_DEVICE_PATH_REGULATOR
+	if (hub->regulator && !IS_ERR(hub->regulator)) {
+		regulator_disable(hub->regulator);
+		regulator_put(hub->regulator);
+	}
+#endif
 	usb_free_urb(hub->urb);
 	kfree(hub->ports);
 	kfree(hub->descriptor);
@@ -1609,6 +1618,9 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
 	struct usb_endpoint_descriptor *endpoint;
 	struct usb_device *hdev;
 	struct usb_hub *hub;
+#ifdef CONFIG_USB_HUB_DEVICE_PATH_REGULATOR
+	char *dev_path;
+#endif
 
 	desc = intf->cur_altsetting;
 	hdev = interface_to_usbdev(intf);
@@ -1692,6 +1704,18 @@ descriptor_error:
 		return -ENOMEM;
 	}
 
+#ifdef CONFIG_USB_HUB_DEVICE_PATH_REGULATOR
+	/* if a regulator is associated on our device_path, use it */
+	dev_path = kmalloc(MAX_DEV_PATH_SIZE, GFP_KERNEL);
+	if (!device_path_generate(&hdev->dev, dev_path, MAX_DEV_PATH_SIZE)) {
+		dev_info(&hdev->dev, "device_path: %s\n", dev_path);
+		hub->regulator = regulator_get(&hdev->dev, dev_path);
+		if (!IS_ERR(hub->regulator))
+			regulator_enable(hub->regulator);
+	}
+	kfree(dev_path);
+#endif
+
 	kref_init(&hub->kref);
 	INIT_LIST_HEAD(&hub->event_list);
 	hub->intfdev = &intf->dev;


  parent reply	other threads:[~2012-11-26 12:45 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-26 12:45 [RFC PATCH 0/5] Device Paths introduced and applied to generic hub and panda Andy Green
2012-11-26 12:45 ` [RFC PATCH 1/5] drivers : introduce device_path api Andy Green
2012-11-26 19:12   ` Alan Stern
     [not found]     ` <Pine.LNX.4.44L0.1211261348310.2168-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-26 23:26       ` Andy Green
     [not found]   ` <20121126124534.18106.44137.stgit-Ak/hGR4SqtBG2qbu2SEcwgC/G2K4zDHf@public.gmane.org>
2012-11-26 19:16     ` Greg KH
     [not found]       ` <20121126191612.GA11239-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2012-11-26 23:28         ` Andy Green
2012-11-26 19:22   ` Greg KH
2012-11-26 19:27     ` Greg KH
2012-11-26 21:07     ` Alan Stern
2012-11-26 22:50       ` Greg KH
     [not found]       ` <Pine.LNX.4.44L0.1211261555400.2168-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-27  0:02         ` Andy Green
     [not found]           ` <50B40320.2020206-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-27 16:37             ` Alan Stern
2012-11-27 17:44               ` Andy Green
     [not found]                 ` <50B4FBE9.5080301-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-27 18:09                   ` Alan Stern
     [not found]                     ` <Pine.LNX.4.44L0.1211271253230.1489-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-27 19:22                       ` Andy Green
2012-11-27 20:10                         ` Alan Stern
     [not found]                           ` <Pine.LNX.4.44L0.1211271446430.1489-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-28  2:30                             ` Andy Green
     [not found]                         ` <50B51313.2060003-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-28 11:13                           ` Roger Quadros
2012-11-28 11:47                             ` Andy Green
2012-11-28 12:45                               ` Roger Quadros
2012-11-28 16:43                             ` Alan Stern
2012-11-29  2:05                               ` Ming Lei
2012-11-29 17:05                                 ` Alan Stern
2012-11-27  3:41       ` Ming Lei
2012-11-27 16:30         ` Alan Stern
     [not found]           ` <Pine.LNX.4.44L0.1211271119380.1489-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-27 17:02             ` Greg KH
2012-12-01  7:49               ` Jassi Brar
2012-12-01  8:37                 ` Andy Green
     [not found]                   ` <50B9C1B0.3080605-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-12-01 18:08                     ` Jassi Brar
     [not found]                 ` <CABb+yY3TC3z+jRU91KGX+FKLtJ3ZXUp55-wM_KjxiYuVZ+LL+Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-12-05 14:09                   ` Roger Quadros
     [not found]                     ` <50BF55B3.1030205-l0cyMroinI0@public.gmane.org>
2012-12-06 14:34                       ` Jassi Brar
2012-12-10  9:48                         ` Roger Quadros
     [not found]                           ` <50C5B003.9060904-l0cyMroinI0@public.gmane.org>
2012-12-10 14:36                             ` Felipe Balbi
2012-12-11  9:12                           ` Jassi Brar
     [not found]                             ` <CABb+yY3u2QB0JqXrznDGHXqH3crkYk54whC0GTwkBHqjdEzhbg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-12-11 10:01                               ` Roger Quadros
     [not found]                                 ` <50C70495.40500-l0cyMroinI0@public.gmane.org>
2012-12-11 10:09                                   ` Felipe Balbi
2012-11-27 17:22           ` Ming Lei
2012-11-27 17:55             ` Andy Green
     [not found]               ` <50B4FE7D.9030505-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-27 23:06                 ` Ming Lei
2012-11-28  1:16                   ` Ming Lei
2012-11-26 23:47     ` Andy Green
     [not found] ` <20121126123427.18106.4112.stgit-Ak/hGR4SqtBG2qbu2SEcwgC/G2K4zDHf@public.gmane.org>
2012-11-26 12:45   ` [RFC PATCH 2/5] usb: omap ehci: remove all regulator control from ehci omap Andy Green
2012-11-26 12:45 ` Andy Green [this message]
2012-11-26 19:23   ` [RFC PATCH 3/5] usb: hub: add device_path regulator control to generic hub Greg KH
2012-11-26 12:45 ` [RFC PATCH 4/5] omap4: panda: add smsc95xx regulator and reset dependent on root hub Andy Green
2012-11-26 16:20   ` Roger Quadros
2012-11-27  0:17     ` Andy Green
2012-11-26 12:45 ` [RFC PATCH 5/5] config omap2plus add ehci bits Andy Green

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=20121126124544.18106.60130.stgit@build.warmcat.com \
    --to=andy.green@linaro.org \
    --cc=balbi@ti.com \
    --cc=keshava_mgowda@ti.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=rogerq@ti.com \
    --cc=stern@rowland.harvard.edu \
    /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).