Skip to contentSkip to conversation

usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode

RFC Superseded Kiran Kumar Raparthy 2 participants 2 messages Sep 2, 2014 USB

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

RFC v2 1/2 usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode

From: Todd Poynor <[email protected]>

usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode

Purpose of this is to prevent the system to enter into suspend state from USB peripheral traffic by hodling a wakeupsource when USB is connected and enumerated in peripheral mode(say adb).

Disabled by default, can enable with:
echo Y > /sys/module/otg_wakeupsource/parameters/enabled

Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Android Kernel Team <[email protected]>
Cc John Stultz <[email protected]>
Cc Arve Hj�nnev�g <[email protected]>
Cc Benoit Goby <[email protected]>

[kiran: Added context to commit message.
Included build fix from Benoit Goby and Arve Hj�nnev�g. Removed lock->held field in driver as this mechanism is provided in wakeupsource driver.
wakelock(wl) terminology replaced with wakeup_source(ws). changed to "disabled by default" from "enable by default". sys entry(module param) field modified to otg_wakeupsource. included Todd's refactoring logic.
Introduced get_phy_hook to handle otgws_xceiv per-PHY. otgws_nb moved to otg_wakeupsource_init function. wakeupsource handling implemeted per-PHY(in phy core). modified Kconfig help text]

---
 drivers/usb/phy/Kconfig            |   8 +++
 drivers/usb/phy/Makefile           |   1 +
 drivers/usb/phy/otg-wakeupsource.c | 140 +++++++++++++++++++++++++++++++++++++
 drivers/usb/phy/phy.c              |  42 +++++++++++
 include/linux/usb/phy.h            |   8 +++
 5 files changed, 199 insertions(+)
 create mode 100644 drivers/usb/phy/otg-wakeupsource.c
drivers/usb/phy/Kconfig +8 -0
index e253fa0..d9ddd85 100644
@@ -6,6 +6,14 @@ menu "USB Physical Layer drivers"
 config USB_PHY
 	def_bool n
 
+config USB_OTG_WAKEUPSOURCE
+	bool "Hold wakeupsource when USB is enumerated in peripheral mode"
+	depends on PM_SLEEP
+	select USB_PHY
+	help
+	  Prevent the system going into automatic suspend while
+	  it is attached as a USB peripheral by holding a wakeupsource.
+
 #
 # USB Transceiver Drivers
 #
drivers/usb/phy/Makefile +1 -0
index 24a9133..ca2fbaf 100644
@@ -3,6 +3,7 @@
 #
 obj-$(CONFIG_USB_PHY)			+= phy.o
 obj-$(CONFIG_OF)			+= of.o
+obj-$(CONFIG_USB_OTG_WAKEUPSOURCE)		+= otg-wakeupsource.o
 
 # transceiver drivers, keep the list sorted
 
drivers/usb/phy/otg-wakeupsource.c new file +140 -0

140 lines not on this page · raw message

drivers/usb/phy/phy.c +42 -0

45 lines not on this page · raw message

include/linux/usb/phy.h +8 -0
index 353053a..6c680e6 100644
@@ -11,6 +11,7 @@
 
 #include <linux/notifier.h>
 #include <linux/usb.h>
+#include <linux/pm_wakeup.h>
 
 enum usb_phy_interface {
 	USBPHY_INTERFACE_MODE_UNKNOWN,
@@ -89,6 +90,9 @@ struct usb_phy {
 	/* for notification of usb_phy_events */
 	struct atomic_notifier_head	notifier;
 
+	/* wakeup source */
+	struct wakeup_source wsource;
+
 	/* to pass extra port status to the root hub */
 	u16			port_status;
 	u16			port_change;
@@ -210,6 +214,10 @@ extern void usb_put_phy(struct usb_phy *);
 extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
 extern int usb_bind_phy(const char *dev_name, u8 index,
 				const char *phy_dev_name);
+void usb_wsource_init(struct usb_phy *x, char *phy_dev_name);
+void usb_wsource_trash(struct usb_phy *x);
+void usb_grab_wsource(struct usb_phy *x);
+void usb_drop_wsource(struct usb_phy *x);
 #else
 static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
 {
Signature · 1 line
1.8.2.1
#1 lore raw
Quoted 97 lines · Kiran Kumar Raparthy

From: Todd Poynor <[email protected]>

usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode

Purpose of this is to prevent the system to enter into suspend state from USB peripheral traffic by hodling a wakeupsource when USB is connected and enumerated in peripheral mode(say adb).

Disabled by default, can enable with:
echo Y > /sys/module/otg_wakeupsource/parameters/enabled

Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Android Kernel Team <[email protected]>
Cc John Stultz <[email protected]>
Cc Arve Hj�nnev�g <[email protected]>
Cc Benoit Goby <[email protected]>

[kiran: Added context to commit message.
Included build fix from Benoit Goby and Arve Hj�nnev�g. Removed lock->held field in driver as this mechanism is provided in wakeupsource driver.
wakelock(wl) terminology replaced with wakeup_source(ws). changed to "disabled by default" from "enable by default". sys entry(module param) field modified to otg_wakeupsource. included Todd's refactoring logic.
Introduced get_phy_hook to handle otgws_xceiv per-PHY. otgws_nb moved to otg_wakeupsource_init function. wakeupsource handling implemeted per-PHY(in phy core). modified Kconfig help text]

---
 drivers/usb/phy/Kconfig            |   8 +++
 drivers/usb/phy/Makefile           |   1 +
 drivers/usb/phy/otg-wakeupsource.c | 140 +++++++++++++++++++++++++++++++++++++
 drivers/usb/phy/phy.c              |  42 +++++++++++
 include/linux/usb/phy.h            |   8 +++
 5 files changed, 199 insertions(+)
 create mode 100644 drivers/usb/phy/otg-wakeupsource.c
drivers/usb/phy/Kconfig +8 -0
index e253fa0..d9ddd85 100644
@@ -6,6 +6,14 @@ menu "USB Physical Layer drivers"
 config USB_PHY
 	def_bool n
 
+config USB_OTG_WAKEUPSOURCE
+	bool "Hold wakeupsource when USB is enumerated in peripheral mode"
+	depends on PM_SLEEP
+	select USB_PHY
+	help
+	  Prevent the system going into automatic suspend while
+	  it is attached as a USB peripheral by holding a wakeupsource.
+
 #
 # USB Transceiver Drivers
 #
drivers/usb/phy/Makefile +1 -0
index 24a9133..ca2fbaf 100644
@@ -3,6 +3,7 @@
 #
 obj-$(CONFIG_USB_PHY)			+= phy.o
 obj-$(CONFIG_OF)			+= of.o
+obj-$(CONFIG_USB_OTG_WAKEUPSOURCE)		+= otg-wakeupsource.o
 
 # transceiver drivers, keep the list sorted
 
drivers/usb/phy/otg-wakeupsource.c new file +18 -0
new file mode 100644
index 0000000..fca2010
@@ -0,0 +1,140 @@
+/*
+ * otg-wakeupsource.c
+ *
+ * Copyright (C) 2011 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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/kernel.h>
+#include <linux/device.h>

drivers/usb/phy/otg-wakeupsource.c line 28

Quoted 10 lines
drivers/usb/phy/otg-wakeupsource.c new file +10 -0
+#include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/pm_wakeup.h>
+#include <linux/spinlock.h>
+#include <linux/usb/otg.h>
+
+bool enabled = false;
+
+static DEFINE_SPINLOCK(otgws_spinlock);
+static struct usb_phy *get_phy_hook(void);

how many times do I have to say that this needs to be per-PHY ? This means that you shouldn't have a global PHY pointer. Embed this directly into struct usb_phy and have phy-core handle this.

Signature · 1 line
balbi