[PATCH 3/3] usb: phy: hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor usb: phy: hold wakeupsource when USB is enumerated in peripheral mode Some systems require a mechanism to prevent system to enter into suspend state when USB is connected and enumerated in peripheral mode. This patch provides an interface to hold a wakeupsource to prevent suspend. PHY drivers can use this interface when USB is connected and enumerated in peripheral mode. A timed wakeupsource is temporarily held on USB disconnect events, to allow the rest of the system to react to the USB disconnection (dropping host sessions, updating charger status, etc.) prior to re-allowing suspend. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Cc: Arve Hj�nnev�g Cc: Benoit Goby Signed-off-by: Todd Poynor [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy --- drivers/usb/phy/phy.c | 29 +++-- include/linux/usb/phy.h | 5 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 2b1039e..b8a2d56 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -329,6 +329,7 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) int ret = 0; unsigned long flags; struct usb_phy *phy; + char wsource_name[40]; if (x->type != USB_PHY_TYPE_UNDEFINED) { dev_err(x->dev, "not accepting initialized PHY %s\n", x->label); @@ -351,6 +352,10 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) x->type = type; list_add_tail(>head, _list); + snprintf(wsource_name, sizeof(wsource_name), "vbus-%s", + dev_name(x->dev)); + wakeup_source_init(>wsource, wsource_name); + out: spin_unlock_irqrestore(_lock, flags); return ret; @@ -402,6 +407,7 @@ void usb_remove_phy(struct usb_phy *x) spin_lock_irqsave(_lock, flags); if (x) { + wakeup_source_trash(>wsource); list_for_each_entry(phy_bind, _bind_list, list) if (phy_bind->phy == x) phy_bind->phy = NULL; @@ -446,13 +452,32 @@ int usb_bind_phy(const char *dev_name, u8 index, EXPORT_SYMBOL_GPL(usb_bind_phy); /** - * usb_phy_set_event - set event to phy event + * usb_phy_set_event - set event to phy event and + * hold/temporarily hold wakeupsource * @x: the phy returned by usb_get_phy(); * - * This sets event to phy event + * This holds per-PHY wakeupsource/timed wakeupsource */ void usb_phy_set_event(struct usb_phy *x, unsigned long event) { + x->last_event = event; + + switch (event) { + case USB_EVENT_ENUMERATED: + __pm_stay_awake(>wsource); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_VBUS: + case USB_EVENT_CHARGER: + __pm_wakeup_event(>wsource, + USB_PHY_DEFAULT_WAKEUP_SRC_TIMEOUT); + break; + + default: + break; + } } EXPORT_SYMBOL_GPL(usb_phy_set_event); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 3c713ff..c593fc6 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -12,6 +12,8 @@ #include #include +#define USB_PHY_DEFAULT_WAKEUP_SRC_TIMEOUT msecs_to_jiffies(2000) + enum usb_phy_interface { USBPHY_INTERFACE_MODE_UNKNOWN, USBPHY_INTERFACE_MODE_UTMI, @@ -89,6 +91,9 @@ struct usb_phy { /* for notification of usb_phy_events */ struct atomic_notifier_head notifier; + /* wakeup source */ + struct wakeup_sourcewsource; + /* to pass extra port status to the root hub */ u16 port_status; u16 port_change; -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 2/3] usb: phy: Handle per-PHY event for connect and disconnect events
From: Todd Poynor usb: phy: Handle per-PHY event for connnect and disconnect events When usb is connected and enumerated in device mode or when usb is disconnected,call usb_phy_set_event from phy drivers to handle per-PHY event. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Cc: Arve Hj�nnev�g Cc: Benoit Goby Signed-off-by: Todd Poynor [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy --- drivers/usb/phy/phy-ab8500-usb.c| 15 +++ drivers/usb/phy/phy-gpio-vbus-usb.c | 2 ++ drivers/usb/phy/phy-mv-usb.c| 2 ++ drivers/usb/phy/phy-tahvo.c | 2 ++ 4 files changed, 21 insertions(+) diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c index 11ab2c4..d79fa3e 100644 --- a/drivers/usb/phy/phy-ab8500-usb.c +++ b/drivers/usb/phy/phy-ab8500-usb.c @@ -447,6 +447,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_NONE; /* Fallback to default B_IDLE as nothing is connected. */ ab->phy.state = OTG_STATE_B_IDLE; + usb_phy_set_event(>phy, USB_EVENT_NONE); break; case USB_LINK_ACA_RID_C_NM_9540: @@ -461,12 +462,14 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(>phy.notifier, UX500_MUSB_PREPARE, >vbus_draw); + usb_phy_set_event(>phy, USB_EVENT_ENUMERATED); } if (ab->mode == USB_IDLE) { ab->mode = USB_PERIPHERAL; ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(>phy.notifier, UX500_MUSB_PREPARE, >vbus_draw); + usb_phy_set_event(>phy, USB_EVENT_ENUMERATED); } if (event != UX500_MUSB_RIDC) event = UX500_MUSB_VBUS; @@ -502,6 +505,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_CHARGER; atomic_notifier_call_chain(>phy.notifier, event, >vbus_draw); + usb_phy_set_event(>phy, USB_EVENT_CHARGER); break; case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540: @@ -526,6 +530,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, ab->mode = USB_IDLE; ab->phy.otg->default_a = false; ab->vbus_draw = 0; + usb_phy_set_event(>phy, USB_EVENT_NONE); } } break; @@ -585,6 +590,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, * is connected */ ab->phy.state = OTG_STATE_B_IDLE; + usb_phy_set_event(>phy, USB_EVENT_NONE); break; case USB_LINK_ACA_RID_C_NM_8540: @@ -598,6 +604,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(>phy.notifier, UX500_MUSB_PREPARE, >vbus_draw); + usb_phy_set_event(>phy, USB_EVENT_ENUMERATED); } if (event != UX500_MUSB_RIDC) event = UX500_MUSB_VBUS; @@ -626,6 +633,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_CHARGER; atomic_notifier_call_chain(>phy.notifier, event, >vbus_draw); + usb_phy_set_event(>phy, USB_EVENT_CHARGER); break; case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540: @@ -648,6 +656,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, ab->mode = USB_IDLE; ab->phy.otg->default_a = false; ab->vbus_draw = 0; + usb_phy_set_event(>phy, USB_EVENT_NONE); } break; @@ -694,6 +703,7 @@ static int ab8505_usb_link_status_update(struct ab8500_usb *ab, * is connected */ ab->phy.state = OTG_STATE_B_IDLE; + usb_phy_set_event(>phy, USB_EVENT_NONE); break; case USB_LINK_ACA_RID_C_NM_8505: @@ -707,6 +717,7 @@ static int ab8505_usb_link_status_update(struct
[PATCH 1/3] usb: phy: introduce usb_phy_set_event interface
From: Todd Poynor usb: phy: introduce usb_phy_set_event interface PHY drivers require a generic interface to handle per-PHY events. usb_phy_set_event interface sets event to phy event. PHY drivers call this interface for each phy event. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Cc: Arve Hj�nnev�g Cc: Benoit Goby Signed-off-by: Todd Poynor [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy --- drivers/usb/phy/phy.c | 12 include/linux/usb/phy.h | 5 + 2 files changed, 17 insertions(+) diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 045cd30..2b1039e 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -444,3 +444,15 @@ int usb_bind_phy(const char *dev_name, u8 index, return 0; } EXPORT_SYMBOL_GPL(usb_bind_phy); + +/** + * usb_phy_set_event - set event to phy event + * @x: the phy returned by usb_get_phy(); + * + * This sets event to phy event + */ +void usb_phy_set_event(struct usb_phy *x, unsigned long event) +{ + x->last_event = event; +} +EXPORT_SYMBOL_GPL(usb_phy_set_event); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 353053a..3c713ff 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -210,6 +210,7 @@ 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); +extern void usb_phy_set_event(struct usb_phy *x, unsigned long event); #else static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) { @@ -251,6 +252,10 @@ static inline int usb_bind_phy(const char *dev_name, u8 index, { return -EOPNOTSUPP; } + +static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event) +{ +} #endif static inline int -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 0/3] usb: phy: hold wakeupsource on usb phy events.
This patch set aims to hold wakeupsource per-PHY on usb connect/disconnect events. First patch introduces usb_phy_set_event which just sets event to phy event. In second patch, phy drivers call usb_phy_set_event for each phy event. In third patch, wakeupsource is held when usb is enumerated in peripheral mode and wakeupsource held temporarily on disconnect event(to allow other parts of the system react to disconnect event). latest patch-set: * use USB_PHY_DEFAULT_WAKEUP_SRC_TIMEOUT instead of TEMPORARY_HOLD_TIME v6: * Break the patch into three sub patches patch 1: Introduce usb_phy_set_event patch 2: Call usb_phy_set_event from phy drivers patch 3: Hold wakeupsource for connect events and temporarily hold wakeupsource for disconnect events. * Include usb_phy_wsource_init and usb_phy_wource_trash functionality in usb_add_phy and usb_remove_phy respectively. v5: * with the new approach,i was able to chnage only 5 phy drivers as mentioned below to use the wakeupsource funtionality. drivers/phy/phy-omap-control.c drivers/usb/phy/phy-ab8500-usb.c drivers/usb/phy/phy-tahvo.c drivers/usb/phy/phy-mv-usb.c drivers/usb/phy/phy-gpio-vbus-usb.c * Notification method not used any more. * introduced usb_phy_set_event in phy.c to hold wakeupsource * introduced usb_phy_wsource_init/usb_phy_wsource_trash in phy.c to initialize/relese per-PHY wakeupsource.These interfaces called from probe/remove functions of phy drivers. * usb_phy_set_event called from phy drivers where usb enumeration event is handled. * usb_phy_set_event expects usb_phy handle where as phy-omap-control.c provides its own type(omap_control_phy), so directly called __pm_stay_awake and __pm_awake_event from phy-omap-control.c instead of calling usb_phy_set_event. v4: * Temporarily hold wakeupsource patch integrated into main patch. * As per feedback,dropped "enabled" module parameter. * Introduced otgws_otg_usb3_notifications function to handle event notifications from usb3 phy. * Handled wakeupsource initialization,spinlock,registration of notifier block per-PHY. * Updated usb_phy structure. v3: * As per the feedback,no global phy pointer used. * called the one-liner wakeupsource handling calls directly instead of indirect functions implemented in v2. * Removed indirect function get_phy_hook and used usb_get_phy to get the phy handle.. v2: * wakeupsource handling implemeted per-PHY * Implemented wakeupsource handling calls in phy * included Todd's refactoring logic. v1: * changed to "disabled by default" from "enable by default". * Kconfig help text modified * Included better commit text * otgws_nb moved to otg_wakeupsource_init function * Introduced get_phy_hook to handle otgws_xceiv per-PHY Initial RFC: * 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). Todd Poynor (3): usb: phy: introduce usb_phy_set_event interface usb: phy: Handle per-PHY event for connect and disconnect events usb: phy: hold wakeupsource when USB is enumerated in peripheral mode drivers/usb/phy/phy-ab8500-usb.c| 15 +++ drivers/usb/phy/phy-gpio-vbus-usb.c | 2 ++ drivers/usb/phy/phy-mv-usb.c| 2 ++ drivers/usb/phy/phy-tahvo.c | 2 ++ drivers/usb/phy/phy.c | 37 + include/linux/usb/phy.h | 10 ++ 6 files changed, 68 insertions(+) -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 0/3] usb: phy: hold wakeupsource on usb phy events.
This patch set aims to hold wakeupsource per-PHY on usb connect/disconnect events. First patch introduces usb_phy_set_event which just sets event to phy event. In second patch, phy drivers call usb_phy_set_event for each phy event. In third patch, wakeupsource is held when usb is enumerated in peripheral mode and wakeupsource held temporarily on disconnect event(to allow other parts of the system react to disconnect event). latest patch-set: * use USB_PHY_DEFAULT_WAKEUP_SRC_TIMEOUT instead of TEMPORARY_HOLD_TIME v6: * Break the patch into three sub patches patch 1: Introduce usb_phy_set_event patch 2: Call usb_phy_set_event from phy drivers patch 3: Hold wakeupsource for connect events and temporarily hold wakeupsource for disconnect events. * Include usb_phy_wsource_init and usb_phy_wource_trash functionality in usb_add_phy and usb_remove_phy respectively. v5: * with the new approach,i was able to chnage only 5 phy drivers as mentioned below to use the wakeupsource funtionality. drivers/phy/phy-omap-control.c drivers/usb/phy/phy-ab8500-usb.c drivers/usb/phy/phy-tahvo.c drivers/usb/phy/phy-mv-usb.c drivers/usb/phy/phy-gpio-vbus-usb.c * Notification method not used any more. * introduced usb_phy_set_event in phy.c to hold wakeupsource * introduced usb_phy_wsource_init/usb_phy_wsource_trash in phy.c to initialize/relese per-PHY wakeupsource.These interfaces called from probe/remove functions of phy drivers. * usb_phy_set_event called from phy drivers where usb enumeration event is handled. * usb_phy_set_event expects usb_phy handle where as phy-omap-control.c provides its own type(omap_control_phy), so directly called __pm_stay_awake and __pm_awake_event from phy-omap-control.c instead of calling usb_phy_set_event. v4: * Temporarily hold wakeupsource patch integrated into main patch. * As per feedback,dropped enabled module parameter. * Introduced otgws_otg_usb3_notifications function to handle event notifications from usb3 phy. * Handled wakeupsource initialization,spinlock,registration of notifier block per-PHY. * Updated usb_phy structure. v3: * As per the feedback,no global phy pointer used. * called the one-liner wakeupsource handling calls directly instead of indirect functions implemented in v2. * Removed indirect function get_phy_hook and used usb_get_phy to get the phy handle.. v2: * wakeupsource handling implemeted per-PHY * Implemented wakeupsource handling calls in phy * included Todd's refactoring logic. v1: * changed to disabled by default from enable by default. * Kconfig help text modified * Included better commit text * otgws_nb moved to otg_wakeupsource_init function * Introduced get_phy_hook to handle otgws_xceiv per-PHY Initial RFC: * 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). Todd Poynor (3): usb: phy: introduce usb_phy_set_event interface usb: phy: Handle per-PHY event for connect and disconnect events usb: phy: hold wakeupsource when USB is enumerated in peripheral mode drivers/usb/phy/phy-ab8500-usb.c| 15 +++ drivers/usb/phy/phy-gpio-vbus-usb.c | 2 ++ drivers/usb/phy/phy-mv-usb.c| 2 ++ drivers/usb/phy/phy-tahvo.c | 2 ++ drivers/usb/phy/phy.c | 37 + include/linux/usb/phy.h | 10 ++ 6 files changed, 68 insertions(+) -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 2/3] usb: phy: Handle per-PHY event for connect and disconnect events
From: Todd Poynor toddpoy...@google.com usb: phy: Handle per-PHY event for connnect and disconnect events When usb is connected and enumerated in device mode or when usb is disconnected,call usb_phy_set_event from phy drivers to handle per-PHY event. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Cc: Arve Hj�nnev�g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- drivers/usb/phy/phy-ab8500-usb.c| 15 +++ drivers/usb/phy/phy-gpio-vbus-usb.c | 2 ++ drivers/usb/phy/phy-mv-usb.c| 2 ++ drivers/usb/phy/phy-tahvo.c | 2 ++ 4 files changed, 21 insertions(+) diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c index 11ab2c4..d79fa3e 100644 --- a/drivers/usb/phy/phy-ab8500-usb.c +++ b/drivers/usb/phy/phy-ab8500-usb.c @@ -447,6 +447,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_NONE; /* Fallback to default B_IDLE as nothing is connected. */ ab-phy.state = OTG_STATE_B_IDLE; + usb_phy_set_event(ab-phy, USB_EVENT_NONE); break; case USB_LINK_ACA_RID_C_NM_9540: @@ -461,12 +462,14 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(ab-phy.notifier, UX500_MUSB_PREPARE, ab-vbus_draw); + usb_phy_set_event(ab-phy, USB_EVENT_ENUMERATED); } if (ab-mode == USB_IDLE) { ab-mode = USB_PERIPHERAL; ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(ab-phy.notifier, UX500_MUSB_PREPARE, ab-vbus_draw); + usb_phy_set_event(ab-phy, USB_EVENT_ENUMERATED); } if (event != UX500_MUSB_RIDC) event = UX500_MUSB_VBUS; @@ -502,6 +505,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_CHARGER; atomic_notifier_call_chain(ab-phy.notifier, event, ab-vbus_draw); + usb_phy_set_event(ab-phy, USB_EVENT_CHARGER); break; case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540: @@ -526,6 +530,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, ab-mode = USB_IDLE; ab-phy.otg-default_a = false; ab-vbus_draw = 0; + usb_phy_set_event(ab-phy, USB_EVENT_NONE); } } break; @@ -585,6 +590,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, * is connected */ ab-phy.state = OTG_STATE_B_IDLE; + usb_phy_set_event(ab-phy, USB_EVENT_NONE); break; case USB_LINK_ACA_RID_C_NM_8540: @@ -598,6 +604,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(ab-phy.notifier, UX500_MUSB_PREPARE, ab-vbus_draw); + usb_phy_set_event(ab-phy, USB_EVENT_ENUMERATED); } if (event != UX500_MUSB_RIDC) event = UX500_MUSB_VBUS; @@ -626,6 +633,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_CHARGER; atomic_notifier_call_chain(ab-phy.notifier, event, ab-vbus_draw); + usb_phy_set_event(ab-phy, USB_EVENT_CHARGER); break; case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540: @@ -648,6 +656,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, ab-mode = USB_IDLE; ab-phy.otg-default_a = false; ab-vbus_draw = 0; + usb_phy_set_event(ab-phy, USB_EVENT_NONE); } break; @@ -694,6 +703,7 @@ static int ab8505_usb_link_status_update(struct ab8500_usb *ab, * is connected */
[PATCH 1/3] usb: phy: introduce usb_phy_set_event interface
From: Todd Poynor toddpoy...@google.com usb: phy: introduce usb_phy_set_event interface PHY drivers require a generic interface to handle per-PHY events. usb_phy_set_event interface sets event to phy event. PHY drivers call this interface for each phy event. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Cc: Arve Hj�nnev�g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- drivers/usb/phy/phy.c | 12 include/linux/usb/phy.h | 5 + 2 files changed, 17 insertions(+) diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 045cd30..2b1039e 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -444,3 +444,15 @@ int usb_bind_phy(const char *dev_name, u8 index, return 0; } EXPORT_SYMBOL_GPL(usb_bind_phy); + +/** + * usb_phy_set_event - set event to phy event + * @x: the phy returned by usb_get_phy(); + * + * This sets event to phy event + */ +void usb_phy_set_event(struct usb_phy *x, unsigned long event) +{ + x-last_event = event; +} +EXPORT_SYMBOL_GPL(usb_phy_set_event); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 353053a..3c713ff 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -210,6 +210,7 @@ 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); +extern void usb_phy_set_event(struct usb_phy *x, unsigned long event); #else static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) { @@ -251,6 +252,10 @@ static inline int usb_bind_phy(const char *dev_name, u8 index, { return -EOPNOTSUPP; } + +static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event) +{ +} #endif static inline int -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 3/3] usb: phy: hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor toddpoy...@google.com usb: phy: hold wakeupsource when USB is enumerated in peripheral mode Some systems require a mechanism to prevent system to enter into suspend state when USB is connected and enumerated in peripheral mode. This patch provides an interface to hold a wakeupsource to prevent suspend. PHY drivers can use this interface when USB is connected and enumerated in peripheral mode. A timed wakeupsource is temporarily held on USB disconnect events, to allow the rest of the system to react to the USB disconnection (dropping host sessions, updating charger status, etc.) prior to re-allowing suspend. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Cc: Arve Hj�nnev�g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- drivers/usb/phy/phy.c | 29 +++-- include/linux/usb/phy.h | 5 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 2b1039e..b8a2d56 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -329,6 +329,7 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) int ret = 0; unsigned long flags; struct usb_phy *phy; + char wsource_name[40]; if (x-type != USB_PHY_TYPE_UNDEFINED) { dev_err(x-dev, not accepting initialized PHY %s\n, x-label); @@ -351,6 +352,10 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) x-type = type; list_add_tail(x-head, phy_list); + snprintf(wsource_name, sizeof(wsource_name), vbus-%s, + dev_name(x-dev)); + wakeup_source_init(x-wsource, wsource_name); + out: spin_unlock_irqrestore(phy_lock, flags); return ret; @@ -402,6 +407,7 @@ void usb_remove_phy(struct usb_phy *x) spin_lock_irqsave(phy_lock, flags); if (x) { + wakeup_source_trash(x-wsource); list_for_each_entry(phy_bind, phy_bind_list, list) if (phy_bind-phy == x) phy_bind-phy = NULL; @@ -446,13 +452,32 @@ int usb_bind_phy(const char *dev_name, u8 index, EXPORT_SYMBOL_GPL(usb_bind_phy); /** - * usb_phy_set_event - set event to phy event + * usb_phy_set_event - set event to phy event and + * hold/temporarily hold wakeupsource * @x: the phy returned by usb_get_phy(); * - * This sets event to phy event + * This holds per-PHY wakeupsource/timed wakeupsource */ void usb_phy_set_event(struct usb_phy *x, unsigned long event) { + x-last_event = event; + + switch (event) { + case USB_EVENT_ENUMERATED: + __pm_stay_awake(x-wsource); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_VBUS: + case USB_EVENT_CHARGER: + __pm_wakeup_event(x-wsource, + USB_PHY_DEFAULT_WAKEUP_SRC_TIMEOUT); + break; + + default: + break; + } } EXPORT_SYMBOL_GPL(usb_phy_set_event); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 3c713ff..c593fc6 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -12,6 +12,8 @@ #include linux/notifier.h #include linux/usb.h +#define USB_PHY_DEFAULT_WAKEUP_SRC_TIMEOUT msecs_to_jiffies(2000) + enum usb_phy_interface { USBPHY_INTERFACE_MODE_UNKNOWN, USBPHY_INTERFACE_MODE_UTMI, @@ -89,6 +91,9 @@ struct usb_phy { /* for notification of usb_phy_events */ struct atomic_notifier_head notifier; + /* wakeup source */ + struct wakeup_sourcewsource; + /* to pass extra port status to the root hub */ u16 port_status; u16 port_change; -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC] debug: add parameters to prevent entering debug mode on errors
From: Colin Cross debug: add parameters to prevent entering debug mode on errors On non-developer devices kgdb prevents CONFIG_PANIC_TIMEOUT from rebooting the device after a panic. Add module parameters debug_core.break_on_exception and debug_core.break_on_panic to allow skipping debug on panics and exceptions respectively. Both default to true to preserve existing behavior. Cc: Jason Wessel Cc: kgdb-bugrep...@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Signed-off-by: Colin Cross [Kiran: Added context to commit message] Signed-off-by: Kiran Raparthy --- This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. I wanted to submit it for review to see if it should go upstream. kernel/debug/debug_core.c | 12 1 file changed, 12 insertions(+) diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index 1adf62b..af06122 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -87,6 +87,10 @@ static int kgdb_use_con; bool dbg_is_early = true; /* Next cpu to become the master debug core */ int dbg_switch_cpu; +/* Flag for entering kdb when a panic occurs */ +static bool break_on_panic = true; +/* Flag for entering kdb when an exception occurs */ +static bool break_on_exception = true; /* Use kdb or gdbserver mode */ int dbg_kdb_mode = 1; @@ -101,6 +105,8 @@ early_param("kgdbcon", opt_kgdb_con); module_param(kgdb_use_con, int, 0644); module_param(kgdbreboot, int, 0644); +module_param(break_on_panic, bool, 0644); +module_param(break_on_exception, bool, 0644); /* * Holds information about breakpoints in a kernel. These breakpoints are @@ -690,6 +696,9 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs) if (arch_kgdb_ops.enable_nmi) arch_kgdb_ops.enable_nmi(0); + if (unlikely(signo != SIGTRAP && !break_on_exception)) + return 1; + memset(ks, 0, sizeof(struct kgdb_state)); ks->cpu = raw_smp_processor_id(); ks->ex_vector = evector; @@ -821,6 +830,9 @@ static int kgdb_panic_event(struct notifier_block *self, unsigned long val, void *data) { + if (!break_on_panic) + return NOTIFY_DONE; + if (dbg_kdb_mode) kdb_printf("PANIC: %s\n", (char *)data); kgdb_breakpoint(); -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC] debug: add parameters to prevent entering debug mode on errors
From: Colin Cross ccr...@android.com debug: add parameters to prevent entering debug mode on errors On non-developer devices kgdb prevents CONFIG_PANIC_TIMEOUT from rebooting the device after a panic. Add module parameters debug_core.break_on_exception and debug_core.break_on_panic to allow skipping debug on panics and exceptions respectively. Both default to true to preserve existing behavior. Cc: Jason Wessel jason.wes...@windriver.com Cc: kgdb-bugrep...@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Signed-off-by: Colin Cross ccr...@android.com [Kiran: Added context to commit message] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. I wanted to submit it for review to see if it should go upstream. kernel/debug/debug_core.c | 12 1 file changed, 12 insertions(+) diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index 1adf62b..af06122 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -87,6 +87,10 @@ static int kgdb_use_con; bool dbg_is_early = true; /* Next cpu to become the master debug core */ int dbg_switch_cpu; +/* Flag for entering kdb when a panic occurs */ +static bool break_on_panic = true; +/* Flag for entering kdb when an exception occurs */ +static bool break_on_exception = true; /* Use kdb or gdbserver mode */ int dbg_kdb_mode = 1; @@ -101,6 +105,8 @@ early_param(kgdbcon, opt_kgdb_con); module_param(kgdb_use_con, int, 0644); module_param(kgdbreboot, int, 0644); +module_param(break_on_panic, bool, 0644); +module_param(break_on_exception, bool, 0644); /* * Holds information about breakpoints in a kernel. These breakpoints are @@ -690,6 +696,9 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs) if (arch_kgdb_ops.enable_nmi) arch_kgdb_ops.enable_nmi(0); + if (unlikely(signo != SIGTRAP !break_on_exception)) + return 1; + memset(ks, 0, sizeof(struct kgdb_state)); ks-cpu = raw_smp_processor_id(); ks-ex_vector = evector; @@ -821,6 +830,9 @@ static int kgdb_panic_event(struct notifier_block *self, unsigned long val, void *data) { + if (!break_on_panic) + return NOTIFY_DONE; + if (dbg_kdb_mode) kdb_printf(PANIC: %s\n, (char *)data); kgdb_breakpoint(); -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC] serial_core: Add wake_peer uart operation
From: San Mehat serial_core: Add wake_peer uart operation Add wake_peer which is called before starting UART TX. The idea here is to provide a mechanism where we can wakeup our peer before sending data. Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: linux-ser...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Signed-off-by: San Mehat [Kiran: Added context to commit message] Signed-off-by: Kiran Raparthy --- This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. I wanted to submit it for review to see if it should go upstream. drivers/tty/serial/serial_core.c | 3 +++ include/linux/serial_core.h | 1 + 2 files changed, 4 insertions(+) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index df3a8c7..dc45c4b 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -95,6 +95,9 @@ static void __uart_start(struct tty_struct *tty) struct uart_state *state = tty->driver_data; struct uart_port *port = state->uart_port; + if (port->ops->wake_peer) + port->ops->wake_peer(port); + if (!uart_tx_stopped(port)) port->ops->start_tx(port); } diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 21c2e05..219b6a3 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -66,6 +66,7 @@ struct uart_ops { void(*set_ldisc)(struct uart_port *, int new); void(*pm)(struct uart_port *, unsigned int state, unsigned int oldstate); + void(*wake_peer)(struct uart_port *); /* * Return a string describing the type of the port -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC] serial_core: Add wake_peer uart operation
From: San Mehat s...@google.com serial_core: Add wake_peer uart operation Add wake_peer which is called before starting UART TX. The idea here is to provide a mechanism where we can wakeup our peer before sending data. Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: Jiri Slaby jsl...@suse.cz Cc: linux-ser...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Signed-off-by: San Mehat s...@google.com [Kiran: Added context to commit message] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. I wanted to submit it for review to see if it should go upstream. drivers/tty/serial/serial_core.c | 3 +++ include/linux/serial_core.h | 1 + 2 files changed, 4 insertions(+) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index df3a8c7..dc45c4b 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -95,6 +95,9 @@ static void __uart_start(struct tty_struct *tty) struct uart_state *state = tty-driver_data; struct uart_port *port = state-uart_port; + if (port-ops-wake_peer) + port-ops-wake_peer(port); + if (!uart_tx_stopped(port)) port-ops-start_tx(port); } diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 21c2e05..219b6a3 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -66,6 +66,7 @@ struct uart_ops { void(*set_ldisc)(struct uart_port *, int new); void(*pm)(struct uart_port *, unsigned int state, unsigned int oldstate); + void(*wake_peer)(struct uart_port *); /* * Return a string describing the type of the port -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v6 3/3] usb: phy: hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor usb: phy: hold wakeupsource when USB is enumerated in peripheral mode Some systems require a mechanism to prevent system to enter into suspend state when USB is connected and enumerated in peripheral mode. This patch provides an interface to hold a wakeupsource to prevent suspend. PHY drivers can use this interface when USB is connected and enumerated in peripheral mode. A timed wakeupsource is temporarily held on USB disconnect events, to allow the rest of the system to react to the USB disconnection (dropping host sessions, updating charger status, etc.) prior to re-allowing suspend. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Cc: Arve Hj�nnev�g Cc: Benoit Goby Signed-off-by: Todd Poynor [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hjønnevåg, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy --- drivers/usb/phy/phy.c | 29 +++-- include/linux/usb/phy.h | 5 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 2b1039e..b5c5fd3 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -329,6 +329,7 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) int ret = 0; unsigned long flags; struct usb_phy *phy; + char wsource_name[40]; if (x->type != USB_PHY_TYPE_UNDEFINED) { dev_err(x->dev, "not accepting initialized PHY %s\n", x->label); @@ -351,6 +352,10 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) x->type = type; list_add_tail(>head, _list); + snprintf(wsource_name, sizeof(wsource_name), "vbus-%s", + dev_name(x->dev)); + wakeup_source_init(>wsource, wsource_name); + out: spin_unlock_irqrestore(_lock, flags); return ret; @@ -402,6 +407,7 @@ void usb_remove_phy(struct usb_phy *x) spin_lock_irqsave(_lock, flags); if (x) { + wakeup_source_trash(>wsource); list_for_each_entry(phy_bind, _bind_list, list) if (phy_bind->phy == x) phy_bind->phy = NULL; @@ -446,13 +452,32 @@ int usb_bind_phy(const char *dev_name, u8 index, EXPORT_SYMBOL_GPL(usb_bind_phy); /** - * usb_phy_set_event - set event to phy event + * usb_phy_set_event - set event to phy event and + * hold/temporarily hold wakeupsource * @x: the phy returned by usb_get_phy(); * - * This sets event to phy event + * This holds per-PHY wakeupsource/timed wakeupsource */ void usb_phy_set_event(struct usb_phy *x, unsigned long event) { + x->last_event = event; + + switch (event) { + case USB_EVENT_ENUMERATED: + __pm_stay_awake(>wsource); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_VBUS: + case USB_EVENT_CHARGER: + __pm_wakeup_event(>wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); + break; + + default: + break; + } } EXPORT_SYMBOL_GPL(usb_phy_set_event); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 3c713ff..bc58fb8 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -12,6 +12,8 @@ #include #include +#define TEMPORARY_HOLD_TIME2000 + enum usb_phy_interface { USBPHY_INTERFACE_MODE_UNKNOWN, USBPHY_INTERFACE_MODE_UTMI, @@ -89,6 +91,9 @@ struct usb_phy { /* for notification of usb_phy_events */ struct atomic_notifier_head notifier; + /* wakeup source */ + struct wakeup_sourcewsource; + /* to pass extra port status to the root hub */ u16 port_status; u16 port_change; -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v6 2/3] usb: phy: handle per-PHY connect and disconnect events
From: Todd Poynor usb: phy: handle per-PHY connect and disconnect events When usb is connected and enumerated in device mode or when usb is disconnected,call usb_phy_set_event from phy drivers to handle per-PHY event. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Cc: Arve Hj�nnev�g Cc: Benoit Goby Signed-off-by: Todd Poynor [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy --- drivers/usb/phy/phy-ab8500-usb.c| 15 +++ drivers/usb/phy/phy-gpio-vbus-usb.c | 2 ++ drivers/usb/phy/phy-mv-usb.c| 2 ++ drivers/usb/phy/phy-tahvo.c | 2 ++ 4 files changed, 21 insertions(+) diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c index 11ab2c4..d79fa3e 100644 --- a/drivers/usb/phy/phy-ab8500-usb.c +++ b/drivers/usb/phy/phy-ab8500-usb.c @@ -447,6 +447,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_NONE; /* Fallback to default B_IDLE as nothing is connected. */ ab->phy.state = OTG_STATE_B_IDLE; + usb_phy_set_event(>phy, USB_EVENT_NONE); break; case USB_LINK_ACA_RID_C_NM_9540: @@ -461,12 +462,14 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(>phy.notifier, UX500_MUSB_PREPARE, >vbus_draw); + usb_phy_set_event(>phy, USB_EVENT_ENUMERATED); } if (ab->mode == USB_IDLE) { ab->mode = USB_PERIPHERAL; ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(>phy.notifier, UX500_MUSB_PREPARE, >vbus_draw); + usb_phy_set_event(>phy, USB_EVENT_ENUMERATED); } if (event != UX500_MUSB_RIDC) event = UX500_MUSB_VBUS; @@ -502,6 +505,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_CHARGER; atomic_notifier_call_chain(>phy.notifier, event, >vbus_draw); + usb_phy_set_event(>phy, USB_EVENT_CHARGER); break; case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540: @@ -526,6 +530,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, ab->mode = USB_IDLE; ab->phy.otg->default_a = false; ab->vbus_draw = 0; + usb_phy_set_event(>phy, USB_EVENT_NONE); } } break; @@ -585,6 +590,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, * is connected */ ab->phy.state = OTG_STATE_B_IDLE; + usb_phy_set_event(>phy, USB_EVENT_NONE); break; case USB_LINK_ACA_RID_C_NM_8540: @@ -598,6 +604,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(>phy.notifier, UX500_MUSB_PREPARE, >vbus_draw); + usb_phy_set_event(>phy, USB_EVENT_ENUMERATED); } if (event != UX500_MUSB_RIDC) event = UX500_MUSB_VBUS; @@ -626,6 +633,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_CHARGER; atomic_notifier_call_chain(>phy.notifier, event, >vbus_draw); + usb_phy_set_event(>phy, USB_EVENT_CHARGER); break; case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540: @@ -648,6 +656,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, ab->mode = USB_IDLE; ab->phy.otg->default_a = false; ab->vbus_draw = 0; + usb_phy_set_event(>phy, USB_EVENT_NONE); } break; @@ -694,6 +703,7 @@ static int ab8505_usb_link_status_update(struct ab8500_usb *ab, * is connected */ ab->phy.state = OTG_STATE_B_IDLE; + usb_phy_set_event(>phy, USB_EVENT_NONE); break; case USB_LINK_ACA_RID_C_NM_8505: @@ -707,6 +717,7 @@ static int ab8505_usb_link_status_update(struct ab8500_usb
[RFC v6 1/3] usb: phy: introduce usb_phy_set_event interface
From: Todd Poynor usb: phy: introduce usb_phy_set_event interface PHY drivers require a generic interface to handle per-PHY events. usb_phy_set_event interface sets event to phy event. PHY drivers call this interface for each phy event. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Cc: Arve Hj�nnev�g Cc: Benoit Goby Signed-off-by: Todd Poynor [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy --- drivers/usb/phy/phy.c | 12 include/linux/usb/phy.h | 5 + 2 files changed, 17 insertions(+) diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 045cd30..2b1039e 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -444,3 +444,15 @@ int usb_bind_phy(const char *dev_name, u8 index, return 0; } EXPORT_SYMBOL_GPL(usb_bind_phy); + +/** + * usb_phy_set_event - set event to phy event + * @x: the phy returned by usb_get_phy(); + * + * This sets event to phy event + */ +void usb_phy_set_event(struct usb_phy *x, unsigned long event) +{ + x->last_event = event; +} +EXPORT_SYMBOL_GPL(usb_phy_set_event); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 353053a..3c713ff 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -210,6 +210,7 @@ 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); +extern void usb_phy_set_event(struct usb_phy *x, unsigned long event); #else static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) { @@ -251,6 +252,10 @@ static inline int usb_bind_phy(const char *dev_name, u8 index, { return -EOPNOTSUPP; } + +static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event) +{ +} #endif static inline int -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v6 0/3] usb: phy: hold wakeupsource on usb phy events.
This patch set aims to hold wakeupsource per-PHY on usb connect/disconnect events. First patch introduces usb_phy_set_event which just sets event to phy event. In second patch, phy drivers call usb_phy_set_event for each phy event. In third patch, wakeupsource is held when usb is enumerated in peripheral mode and wakeupsource held temporarily on disconnect event(to allow other parts of the system react to disconnect event). v6: * Break the patch into three sub patches patch 1: Introduce usb_phy_set_event patch 2: Call usb_phy_set_event from phy drivers patch 3: Hold wakeupsource for connect events and temporarily hold wakeupsource for disconnect events. * Include usb_phy_wsource_init and usb_phy_wource_trash functionality in usb_add_phy and usb_remove_phy respectively. v5: * with the new approach,i was able to chnage only 5 phy drivers as mentioned below to use the wakeupsource funtionality. drivers/phy/phy-omap-control.c drivers/usb/phy/phy-ab8500-usb.c drivers/usb/phy/phy-tahvo.c drivers/usb/phy/phy-mv-usb.c drivers/usb/phy/phy-gpio-vbus-usb.c * Notification method not used any more. * introduced usb_phy_set_event in phy.c to hold wakeupsource * introduced usb_phy_wsource_init/usb_phy_wsource_trash in phy.c to initialize/relese per-PHY wakeupsource.These interfaces called from probe/remove functions of phy drivers. * usb_phy_set_event called from phy drivers where usb enumeration event is handled. * usb_phy_set_event expects usb_phy handle where as phy-omap-control.c provides its own type(omap_control_phy), so directly called __pm_stay_awake and� __pm_awake_event from phy-omap-control.c instead of calling usb_phy_set_event. v4: * Temporarily hold wakeupsource patch integrated into main patch. * As per feedback,dropped "enabled" module parameter. * Introduced otgws_otg_usb3_notifications function to handle event notifications from usb3 phy. * Handled wakeupsource initialization,spinlock,registration of notifier block per-PHY. * Updated usb_phy structure. v3: * As per the feedback,no global phy pointer used. * called the one-liner wakeupsource handling calls directly instead of indirect functions implemented in v2. * Removed indirect function get_phy_hook and used usb_get_phy to get the phy handle.. v2: * wakeupsource handling implemeted per-PHY * Implemented wakeupsource handling calls in phy * included Todd's refactoring logic. v1: * changed to "disabled by default" from "enable by default". * Kconfig help text modified * Included better commit text * otgws_nb moved to otg_wakeupsource_init function * Introduced get_phy_hook to handle otgws_xceiv per-PHY Initial RFC: * 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). Todd Poynor (3): usb: phy: introduce usb_phy_set_event interface usb: phy: Handle per-PHY event for connect and disconnect events usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode drivers/usb/phy/phy-ab8500-usb.c| 15 +++ drivers/usb/phy/phy-gpio-vbus-usb.c | 2 ++ drivers/usb/phy/phy-mv-usb.c| 2 ++ drivers/usb/phy/phy-tahvo.c | 2 ++ drivers/usb/phy/phy.c | 37 + include/linux/usb/phy.h | 10 ++ 6 files changed, 68 insertions(+) -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v6 0/3] usb: phy: hold wakeupsource on usb phy events.
This patch set aims to hold wakeupsource per-PHY on usb connect/disconnect events. First patch introduces usb_phy_set_event which just sets event to phy event. In second patch, phy drivers call usb_phy_set_event for each phy event. In third patch, wakeupsource is held when usb is enumerated in peripheral mode and wakeupsource held temporarily on disconnect event(to allow other parts of the system react to disconnect event). v6: * Break the patch into three sub patches patch 1: Introduce usb_phy_set_event patch 2: Call usb_phy_set_event from phy drivers patch 3: Hold wakeupsource for connect events and temporarily hold wakeupsource for disconnect events. * Include usb_phy_wsource_init and usb_phy_wource_trash functionality in usb_add_phy and usb_remove_phy respectively. v5: * with the new approach,i was able to chnage only 5 phy drivers as mentioned below to use the wakeupsource funtionality. drivers/phy/phy-omap-control.c drivers/usb/phy/phy-ab8500-usb.c drivers/usb/phy/phy-tahvo.c drivers/usb/phy/phy-mv-usb.c drivers/usb/phy/phy-gpio-vbus-usb.c * Notification method not used any more. * introduced usb_phy_set_event in phy.c to hold wakeupsource * introduced usb_phy_wsource_init/usb_phy_wsource_trash in phy.c to initialize/relese per-PHY wakeupsource.These interfaces called from probe/remove functions of phy drivers. * usb_phy_set_event called from phy drivers where usb enumeration event is handled. * usb_phy_set_event expects usb_phy handle where as phy-omap-control.c provides its own type(omap_control_phy), so directly called __pm_stay_awake and� __pm_awake_event from phy-omap-control.c instead of calling usb_phy_set_event. v4: * Temporarily hold wakeupsource patch integrated into main patch. * As per feedback,dropped enabled module parameter. * Introduced otgws_otg_usb3_notifications function to handle event notifications from usb3 phy. * Handled wakeupsource initialization,spinlock,registration of notifier block per-PHY. * Updated usb_phy structure. v3: * As per the feedback,no global phy pointer used. * called the one-liner wakeupsource handling calls directly instead of indirect functions implemented in v2. * Removed indirect function get_phy_hook and used usb_get_phy to get the phy handle.. v2: * wakeupsource handling implemeted per-PHY * Implemented wakeupsource handling calls in phy * included Todd's refactoring logic. v1: * changed to disabled by default from enable by default. * Kconfig help text modified * Included better commit text * otgws_nb moved to otg_wakeupsource_init function * Introduced get_phy_hook to handle otgws_xceiv per-PHY Initial RFC: * 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). Todd Poynor (3): usb: phy: introduce usb_phy_set_event interface usb: phy: Handle per-PHY event for connect and disconnect events usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode drivers/usb/phy/phy-ab8500-usb.c| 15 +++ drivers/usb/phy/phy-gpio-vbus-usb.c | 2 ++ drivers/usb/phy/phy-mv-usb.c| 2 ++ drivers/usb/phy/phy-tahvo.c | 2 ++ drivers/usb/phy/phy.c | 37 + include/linux/usb/phy.h | 10 ++ 6 files changed, 68 insertions(+) -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v6 2/3] usb: phy: handle per-PHY connect and disconnect events
From: Todd Poynor toddpoy...@google.com usb: phy: handle per-PHY connect and disconnect events When usb is connected and enumerated in device mode or when usb is disconnected,call usb_phy_set_event from phy drivers to handle per-PHY event. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Cc: Arve Hj�nnev�g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- drivers/usb/phy/phy-ab8500-usb.c| 15 +++ drivers/usb/phy/phy-gpio-vbus-usb.c | 2 ++ drivers/usb/phy/phy-mv-usb.c| 2 ++ drivers/usb/phy/phy-tahvo.c | 2 ++ 4 files changed, 21 insertions(+) diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c index 11ab2c4..d79fa3e 100644 --- a/drivers/usb/phy/phy-ab8500-usb.c +++ b/drivers/usb/phy/phy-ab8500-usb.c @@ -447,6 +447,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_NONE; /* Fallback to default B_IDLE as nothing is connected. */ ab-phy.state = OTG_STATE_B_IDLE; + usb_phy_set_event(ab-phy, USB_EVENT_NONE); break; case USB_LINK_ACA_RID_C_NM_9540: @@ -461,12 +462,14 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(ab-phy.notifier, UX500_MUSB_PREPARE, ab-vbus_draw); + usb_phy_set_event(ab-phy, USB_EVENT_ENUMERATED); } if (ab-mode == USB_IDLE) { ab-mode = USB_PERIPHERAL; ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(ab-phy.notifier, UX500_MUSB_PREPARE, ab-vbus_draw); + usb_phy_set_event(ab-phy, USB_EVENT_ENUMERATED); } if (event != UX500_MUSB_RIDC) event = UX500_MUSB_VBUS; @@ -502,6 +505,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_CHARGER; atomic_notifier_call_chain(ab-phy.notifier, event, ab-vbus_draw); + usb_phy_set_event(ab-phy, USB_EVENT_CHARGER); break; case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_9540: @@ -526,6 +530,7 @@ static int ab9540_usb_link_status_update(struct ab8500_usb *ab, ab-mode = USB_IDLE; ab-phy.otg-default_a = false; ab-vbus_draw = 0; + usb_phy_set_event(ab-phy, USB_EVENT_NONE); } } break; @@ -585,6 +590,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, * is connected */ ab-phy.state = OTG_STATE_B_IDLE; + usb_phy_set_event(ab-phy, USB_EVENT_NONE); break; case USB_LINK_ACA_RID_C_NM_8540: @@ -598,6 +604,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, ab8500_usb_peri_phy_en(ab); atomic_notifier_call_chain(ab-phy.notifier, UX500_MUSB_PREPARE, ab-vbus_draw); + usb_phy_set_event(ab-phy, USB_EVENT_ENUMERATED); } if (event != UX500_MUSB_RIDC) event = UX500_MUSB_VBUS; @@ -626,6 +633,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, event = UX500_MUSB_CHARGER; atomic_notifier_call_chain(ab-phy.notifier, event, ab-vbus_draw); + usb_phy_set_event(ab-phy, USB_EVENT_CHARGER); break; case USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8540: @@ -648,6 +656,7 @@ static int ab8540_usb_link_status_update(struct ab8500_usb *ab, ab-mode = USB_IDLE; ab-phy.otg-default_a = false; ab-vbus_draw = 0; + usb_phy_set_event(ab-phy, USB_EVENT_NONE); } break; @@ -694,6 +703,7 @@ static int ab8505_usb_link_status_update(struct ab8500_usb *ab, * is connected */
[RFC v6 1/3] usb: phy: introduce usb_phy_set_event interface
From: Todd Poynor toddpoy...@google.com usb: phy: introduce usb_phy_set_event interface PHY drivers require a generic interface to handle per-PHY events. usb_phy_set_event interface sets event to phy event. PHY drivers call this interface for each phy event. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Cc: Arve Hj�nnev�g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- drivers/usb/phy/phy.c | 12 include/linux/usb/phy.h | 5 + 2 files changed, 17 insertions(+) diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 045cd30..2b1039e 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -444,3 +444,15 @@ int usb_bind_phy(const char *dev_name, u8 index, return 0; } EXPORT_SYMBOL_GPL(usb_bind_phy); + +/** + * usb_phy_set_event - set event to phy event + * @x: the phy returned by usb_get_phy(); + * + * This sets event to phy event + */ +void usb_phy_set_event(struct usb_phy *x, unsigned long event) +{ + x-last_event = event; +} +EXPORT_SYMBOL_GPL(usb_phy_set_event); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 353053a..3c713ff 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -210,6 +210,7 @@ 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); +extern void usb_phy_set_event(struct usb_phy *x, unsigned long event); #else static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) { @@ -251,6 +252,10 @@ static inline int usb_bind_phy(const char *dev_name, u8 index, { return -EOPNOTSUPP; } + +static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event) +{ +} #endif static inline int -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v6 3/3] usb: phy: hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor toddpoy...@google.com usb: phy: hold wakeupsource when USB is enumerated in peripheral mode Some systems require a mechanism to prevent system to enter into suspend state when USB is connected and enumerated in peripheral mode. This patch provides an interface to hold a wakeupsource to prevent suspend. PHY drivers can use this interface when USB is connected and enumerated in peripheral mode. A timed wakeupsource is temporarily held on USB disconnect events, to allow the rest of the system to react to the USB disconnection (dropping host sessions, updating charger status, etc.) prior to re-allowing suspend. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Cc: Arve Hj�nnev�g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hjønnevåg, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- drivers/usb/phy/phy.c | 29 +++-- include/linux/usb/phy.h | 5 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 2b1039e..b5c5fd3 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -329,6 +329,7 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) int ret = 0; unsigned long flags; struct usb_phy *phy; + char wsource_name[40]; if (x-type != USB_PHY_TYPE_UNDEFINED) { dev_err(x-dev, not accepting initialized PHY %s\n, x-label); @@ -351,6 +352,10 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) x-type = type; list_add_tail(x-head, phy_list); + snprintf(wsource_name, sizeof(wsource_name), vbus-%s, + dev_name(x-dev)); + wakeup_source_init(x-wsource, wsource_name); + out: spin_unlock_irqrestore(phy_lock, flags); return ret; @@ -402,6 +407,7 @@ void usb_remove_phy(struct usb_phy *x) spin_lock_irqsave(phy_lock, flags); if (x) { + wakeup_source_trash(x-wsource); list_for_each_entry(phy_bind, phy_bind_list, list) if (phy_bind-phy == x) phy_bind-phy = NULL; @@ -446,13 +452,32 @@ int usb_bind_phy(const char *dev_name, u8 index, EXPORT_SYMBOL_GPL(usb_bind_phy); /** - * usb_phy_set_event - set event to phy event + * usb_phy_set_event - set event to phy event and + * hold/temporarily hold wakeupsource * @x: the phy returned by usb_get_phy(); * - * This sets event to phy event + * This holds per-PHY wakeupsource/timed wakeupsource */ void usb_phy_set_event(struct usb_phy *x, unsigned long event) { + x-last_event = event; + + switch (event) { + case USB_EVENT_ENUMERATED: + __pm_stay_awake(x-wsource); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_VBUS: + case USB_EVENT_CHARGER: + __pm_wakeup_event(x-wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); + break; + + default: + break; + } } EXPORT_SYMBOL_GPL(usb_phy_set_event); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 3c713ff..bc58fb8 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -12,6 +12,8 @@ #include linux/notifier.h #include linux/usb.h +#define TEMPORARY_HOLD_TIME2000 + enum usb_phy_interface { USBPHY_INTERFACE_MODE_UNKNOWN, USBPHY_INTERFACE_MODE_UTMI, @@ -89,6 +91,9 @@ struct usb_phy { /* for notification of usb_phy_events */ struct atomic_notifier_head notifier; + /* wakeup source */ + struct wakeup_sourcewsource; + /* to pass extra port status to the root hub */ u16 port_status; u16 port_change; -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v5] usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode Some systems require a mechanism to prevent system to enter into suspend state when USB is connected and enumerated in peripheral mode. This patch provides an interface to hold a wakeupsource to prevent suspend. PHY drivers can use this interface when USB is connected and enumerated in peripheral mode. A timed wakeupsource is temporarily held on USB disconnect events, to allow the rest of the system to react to the USB disconnection (dropping host sessions, updating charger status, etc.) prior to re-allowing suspend. Cc: Kishon Vijay Abraham I Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Cc: Arve Hj?nnev?g Cc: Benoit Goby Signed-off-by: Todd Poynor [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj?nnev?g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy --- v5: * with the new approach,i was able to chnage only 5 phy drivers as mentioned below to use the wakeupsource funtionality. drivers/phy/phy-omap-control.c drivers/usb/phy/phy-ab8500-usb.c drivers/usb/phy/phy-tahvo.c drivers/usb/phy/phy-mv-usb.c drivers/usb/phy/phy-gpio-vbus-usb.c * Notification method not used any more. * introduced usb_phy_set_event in phy.c to hold wakeupsource * introduced usb_phy_wsource_init/usb_phy_wsource_trash in phy.c to initialize/relese per-PHY wakeupsource.These interfaces called from probe/remove functions of phy drivers. * usb_phy_set_event called from phy drivers where usb enumeration event is handled. * usb_phy_set_event expects usb_phy handle where as phy-omap-control.c provides its own type(omap_control_phy), so directly called __pm_stay_awake and __pm_awake_event from phy-omap-control.c instead of calling usb_phy_set_event. v4: * Temporarily hold wakeupsource patch integrated into main patch. * As per feedback,dropped "enabled" module parameter. * Introduced otgws_otg_usb3_notifications function to handle event notifications from usb3 phy. * Handled wakeupsource initialization,spinlock,registration of notifier block per-PHY. * Updated usb_phy structure. v3: * As per the feedback,no global phy pointer used. * called the one-liner wakeupsource handling calls directly instead of indirect functions implemented in v2. * Removed indirect function get_phy_hook and used usb_get_phy to get the phy handle.. v2: * wakeupsource handling implemeted per-PHY * Implemented wakeupsource handling calls in phy * included Todd's refactoring logic. v1: * changed to "disabled by default" from "enable by default". * Kconfig help text modified * Included better commit text * otgws_nb moved to otg_wakeupsource_init function * Introduced get_phy_hook to handle otgws_xceiv per-PHY Initial RFC: * 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). drivers/phy/phy-omap-control.c | 9 ++ drivers/usb/phy/phy-ab8500-usb.c | 17 +++ drivers/usb/phy/phy-gpio-vbus-usb.c | 4 +++ drivers/usb/phy/phy-mv-usb.c | 4 +++ drivers/usb/phy/phy-tahvo.c | 5 drivers/usb/phy/phy.c| 56 include/linux/phy/omap_control_phy.h | 4 +++ include/linux/usb/phy.h | 8 ++ 8 files changed, 107 insertions(+) diff --git a/drivers/phy/phy-omap-control.c b/drivers/phy/phy-omap-control.c index 311b4f9..efc629f 100644 --- a/drivers/phy/phy-omap-control.c +++ b/drivers/phy/phy-omap-control.c @@ -24,6 +24,7 @@ #include #include #include +#include #include /** @@ -196,9 +197,12 @@ void omap_control_usb_set_mode(struct device *dev, break; case USB_MODE_DEVICE: omap_control_usb_device_mode(ctrl_phy); + __pm_stay_awake(_phy->wsource); break; case USB_MODE_DISCONNECT: omap_control_usb_set_sessionend(ctrl_phy); + __pm_wakeup_event(_phy->wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: dev_vdbg(dev, "invalid omap control usb mode\n"); @@ -246,6 +250,7 @@ static int omap_control_phy_probe(struct platform_device *pdev) struct resource *res; const struct of_device_id *of_id; struct omap_control_phy *control_phy; + char wsource_name[40]; of_id = of_match_device(of_match_ptr(omap_control_phy_id_table), >dev); @@ -290,6 +295,10 @@ static int omap_control_phy_probe(struct platform_device *pdev) dev_set_drvdata(control_phy->dev,
[RFC v5] usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor toddpoy...@google.com usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode Some systems require a mechanism to prevent system to enter into suspend state when USB is connected and enumerated in peripheral mode. This patch provides an interface to hold a wakeupsource to prevent suspend. PHY drivers can use this interface when USB is connected and enumerated in peripheral mode. A timed wakeupsource is temporarily held on USB disconnect events, to allow the rest of the system to react to the USB disconnection (dropping host sessions, updating charger status, etc.) prior to re-allowing suspend. Cc: Kishon Vijay Abraham I kis...@ti.com Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Cc: Arve Hj?nnev?g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj?nnev?g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- v5: * with the new approach,i was able to chnage only 5 phy drivers as mentioned below to use the wakeupsource funtionality. drivers/phy/phy-omap-control.c drivers/usb/phy/phy-ab8500-usb.c drivers/usb/phy/phy-tahvo.c drivers/usb/phy/phy-mv-usb.c drivers/usb/phy/phy-gpio-vbus-usb.c * Notification method not used any more. * introduced usb_phy_set_event in phy.c to hold wakeupsource * introduced usb_phy_wsource_init/usb_phy_wsource_trash in phy.c to initialize/relese per-PHY wakeupsource.These interfaces called from probe/remove functions of phy drivers. * usb_phy_set_event called from phy drivers where usb enumeration event is handled. * usb_phy_set_event expects usb_phy handle where as phy-omap-control.c provides its own type(omap_control_phy), so directly called __pm_stay_awake and __pm_awake_event from phy-omap-control.c instead of calling usb_phy_set_event. v4: * Temporarily hold wakeupsource patch integrated into main patch. * As per feedback,dropped enabled module parameter. * Introduced otgws_otg_usb3_notifications function to handle event notifications from usb3 phy. * Handled wakeupsource initialization,spinlock,registration of notifier block per-PHY. * Updated usb_phy structure. v3: * As per the feedback,no global phy pointer used. * called the one-liner wakeupsource handling calls directly instead of indirect functions implemented in v2. * Removed indirect function get_phy_hook and used usb_get_phy to get the phy handle.. v2: * wakeupsource handling implemeted per-PHY * Implemented wakeupsource handling calls in phy * included Todd's refactoring logic. v1: * changed to disabled by default from enable by default. * Kconfig help text modified * Included better commit text * otgws_nb moved to otg_wakeupsource_init function * Introduced get_phy_hook to handle otgws_xceiv per-PHY Initial RFC: * 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). drivers/phy/phy-omap-control.c | 9 ++ drivers/usb/phy/phy-ab8500-usb.c | 17 +++ drivers/usb/phy/phy-gpio-vbus-usb.c | 4 +++ drivers/usb/phy/phy-mv-usb.c | 4 +++ drivers/usb/phy/phy-tahvo.c | 5 drivers/usb/phy/phy.c| 56 include/linux/phy/omap_control_phy.h | 4 +++ include/linux/usb/phy.h | 8 ++ 8 files changed, 107 insertions(+) diff --git a/drivers/phy/phy-omap-control.c b/drivers/phy/phy-omap-control.c index 311b4f9..efc629f 100644 --- a/drivers/phy/phy-omap-control.c +++ b/drivers/phy/phy-omap-control.c @@ -24,6 +24,7 @@ #include linux/err.h #include linux/io.h #include linux/clk.h +#include linux/usb/phy.h #include linux/phy/omap_control_phy.h /** @@ -196,9 +197,12 @@ void omap_control_usb_set_mode(struct device *dev, break; case USB_MODE_DEVICE: omap_control_usb_device_mode(ctrl_phy); + __pm_stay_awake(ctrl_phy-wsource); break; case USB_MODE_DISCONNECT: omap_control_usb_set_sessionend(ctrl_phy); + __pm_wakeup_event(ctrl_phy-wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: dev_vdbg(dev, invalid omap control usb mode\n); @@ -246,6 +250,7 @@ static int omap_control_phy_probe(struct platform_device *pdev) struct resource *res; const struct of_device_id *of_id; struct omap_control_phy
[RFC v4] usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor 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). Temporarily hold a timed wakeup source on USB disconnect events, to allow the rest of the system to react to the USB disconnection (dropping host sessions, updating charger status, etc.) prior to re-allowing suspend. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Cc: Arve Hj�nnev�g Cc: Benoit Goby Signed-off-by: Todd Poynor [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy --- v4: * Temporarily hold wakeupsource patch integrated into main patch. * As per feedback,dropped "enabled" module parameter. * Introduced otgws_otg_usb3_notifications function to handle event notifications from usb3 phy. * Handled wakeupsource initialization,spinlock,registration of notifier block per-PHY. * Updated usb_phy structure. v3: * As per the feedback,no global phy pointer used. * called the one-liner wakeupsource handling calls directly instead of indirect functions implemented in v2. * Removed indirect function get_phy_hook and used usb_get_phy to get the phy handle.. v2: * wakeupsource handling implemeted per-PHY * Implemented wakeupsource handling calls in phy * included Todd's refactoring logic. v1: * changed to "disabled by default" from "enable by default". * Kconfig help text modified * Included better commit text * otgws_nb moved to otg_wakeupsource_init function * Introduced get_phy_hook to handle otgws_xceiv per-PHY RFC: * 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). drivers/usb/phy/Kconfig| 8 +++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/otg-wakeupsource.c | 134 + include/linux/usb/phy.h| 8 +++ 4 files changed, 151 insertions(+) create mode 100644 drivers/usb/phy/otg-wakeupsource.c diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index e253fa0..d9ddd85 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -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 # diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 24a9133..ca2fbaf 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -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 diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c new file mode 100644 index 000..00d3359 --- /dev/null +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -0,0 +1,134 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +static void otgws_handle_event(struct usb_phy *otgws_xceiv, unsigned long event) +{ + unsigned long irqflags; + + spin_lock_irqsave(_xceiv->otgws_slock, irqflags); + + switch (event) { + case USB_EVENT_VBUS: + case USB_EVENT_ENUMERATED: + __pm_stay_awake(_xceiv->wsource); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_CHARGER: + __pm_wakeup_event(_xceiv->wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); + break; + + default: + break; + } + + spin_unlock_irqrestore(_xceiv->otgws_slock, irqflags); +} +
[RFC v4] usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor toddpoy...@google.com 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). Temporarily hold a timed wakeup source on USB disconnect events, to allow the rest of the system to react to the USB disconnection (dropping host sessions, updating charger status, etc.) prior to re-allowing suspend. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Cc: Arve Hj�nnev�g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- v4: * Temporarily hold wakeupsource patch integrated into main patch. * As per feedback,dropped enabled module parameter. * Introduced otgws_otg_usb3_notifications function to handle event notifications from usb3 phy. * Handled wakeupsource initialization,spinlock,registration of notifier block per-PHY. * Updated usb_phy structure. v3: * As per the feedback,no global phy pointer used. * called the one-liner wakeupsource handling calls directly instead of indirect functions implemented in v2. * Removed indirect function get_phy_hook and used usb_get_phy to get the phy handle.. v2: * wakeupsource handling implemeted per-PHY * Implemented wakeupsource handling calls in phy * included Todd's refactoring logic. v1: * changed to disabled by default from enable by default. * Kconfig help text modified * Included better commit text * otgws_nb moved to otg_wakeupsource_init function * Introduced get_phy_hook to handle otgws_xceiv per-PHY RFC: * 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). drivers/usb/phy/Kconfig| 8 +++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/otg-wakeupsource.c | 134 + include/linux/usb/phy.h| 8 +++ 4 files changed, 151 insertions(+) create mode 100644 drivers/usb/phy/otg-wakeupsource.c diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index e253fa0..d9ddd85 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -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 # diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 24a9133..ca2fbaf 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -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 diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c new file mode 100644 index 000..00d3359 --- /dev/null +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -0,0 +1,134 @@ +/* + * 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 +#include linux/module.h +#include linux/notifier.h +#include linux/pm_wakeup.h +#include linux/spinlock.h +#include linux/usb/otg.h + +static void otgws_handle_event(struct usb_phy *otgws_xceiv, unsigned long event) +{ + unsigned long irqflags; + + spin_lock_irqsave(otgws_xceiv-otgws_slock, irqflags); + + switch (event) { + case USB_EVENT_VBUS: + case USB_EVENT_ENUMERATED: + __pm_stay_awake(otgws_xceiv-wsource); + break; + + case USB_EVENT_NONE: + case
[RFC v3 2/2] usb: phy: Temporarily hold timed wakeup source on charger and disconnect events
From: Todd Poynor usb: phy: Temporarily hold timed wakeup source on charger and disconnect events It temporarily holds a timed wakeup source on USB disconnect events, to allow the rest of the system time to react to the USB disconnection (dropping host sessions, updating charger status, etc.) prior to re-allowing suspend Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Signed-off-by: Todd Poynor [kiran: Added context to commit message and addressed community feedback] Signed-off-by: Kiran Raparthy --- v3: * Modified the commit log. * Remove indirect function usb_temporary_hold_wsource and call __pm_wakeup_even directly. v2: * Implement usb_temporary_hold_wsource function in phy. v1: * Removed the refactoring logic from this integrated into main driver code. RFC: * Integrated the refactoring logic and logic to hold wakeupsource temporarily. drivers/usb/phy/otg-wakeupsource.c | 3 ++- include/linux/usb/phy.h| 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index d9a1720..7bc9657 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -47,7 +47,8 @@ static void otgws_handle_event(struct usb_phy *otgws_xceiv, unsigned long event) case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - __pm_relax(_xceiv->wsource); + __pm_wakeup_event(_xceiv->wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index c71cf15..f8f9f1f 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -12,6 +12,8 @@ #include #include +#define TEMPORARY_HOLD_TIME2000 + enum usb_phy_interface { USBPHY_INTERFACE_MODE_UNKNOWN, USBPHY_INTERFACE_MODE_UTMI, -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v3 1/2] usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor 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 Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Sumit Semwal Cc: Arve Hj�nnev�g Cc: Benoit Goby Signed-off-by: Todd Poynor [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy --- v3: * As per the feedback,no global phy pointer used. * called the one-liner wakeupsource handling calls directly instead of indirect functions implemented in v2. * Removed indirect function get_phy_hook and used usb_get_phy to get the phy handle.. v2: * wakeupsource handling implemeted per-PHY * Implemented wakeupsource handling calls in phy * included Todd's refactoring logic. v1: * changed to "disabled by default" from "enable by default". * Kconfig help text modified * Included better commit text * otgws_nb moved to otg_wakeupsource_init function * Introduced get_phy_hook to handle otgws_xceiv per-PHY RFC: * 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). drivers/usb/phy/Kconfig| 8 +++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/otg-wakeupsource.c | 136 + include/linux/usb/phy.h| 4 ++ 4 files changed, 149 insertions(+) create mode 100644 drivers/usb/phy/otg-wakeupsource.c diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index e253fa0..d9ddd85 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -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 # diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 24a9133..ca2fbaf 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -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 diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c new file mode 100644 index 000..d9a1720 --- /dev/null +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -0,0 +1,136 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +bool enabled = false; + +static DEFINE_SPINLOCK(otgws_spinlock); + +static void otgws_handle_event(struct usb_phy *otgws_xceiv, unsigned long event) +{ + unsigned long irqflags; + + spin_lock_irqsave(_spinlock, irqflags); + + if (!enabled) { + __pm_relax(_xceiv->wsource); + spin_unlock_irqrestore(_spinlock, irqflags); + return; + } + + switch (event) { + case USB_EVENT_VBUS: + case USB_EVENT_ENUMERATED: + __pm_stay_awake(_xceiv->wsource); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_CHARGER: + __pm_relax(_xceiv->wsource); + break; + + default: + break; + } + + spin_unlock_irqrestore(_spinlock, irqflags); +} + +static int otgws_otg_notifications(struct notifier_block *nb, + unsigned long event, void *unused) +{ + static struct usb_phy *otgws_xceiv; + + otgws_xceiv = usb_get_phy(USB_PHY_TYPE_USB2); + + if (IS_ERR(otgws_xceiv)) { + pr_err("%s: No OTG transceiver found\n",
[RFC v3 1/2] usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor toddpoy...@google.com 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 ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Cc: Arve Hj�nnev�g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message, squished build fixes from Benoit Goby and Arve Hj�nnev�g, changed wakelocks usage to wakeupsource, merged Todd's refactoring logic and simplified the structures and code and addressed community feedback] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- v3: * As per the feedback,no global phy pointer used. * called the one-liner wakeupsource handling calls directly instead of indirect functions implemented in v2. * Removed indirect function get_phy_hook and used usb_get_phy to get the phy handle.. v2: * wakeupsource handling implemeted per-PHY * Implemented wakeupsource handling calls in phy * included Todd's refactoring logic. v1: * changed to disabled by default from enable by default. * Kconfig help text modified * Included better commit text * otgws_nb moved to otg_wakeupsource_init function * Introduced get_phy_hook to handle otgws_xceiv per-PHY RFC: * 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). drivers/usb/phy/Kconfig| 8 +++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/otg-wakeupsource.c | 136 + include/linux/usb/phy.h| 4 ++ 4 files changed, 149 insertions(+) create mode 100644 drivers/usb/phy/otg-wakeupsource.c diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index e253fa0..d9ddd85 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -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 # diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 24a9133..ca2fbaf 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -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 diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c new file mode 100644 index 000..d9a1720 --- /dev/null +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -0,0 +1,136 @@ +/* + * 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 +#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 void otgws_handle_event(struct usb_phy *otgws_xceiv, unsigned long event) +{ + unsigned long irqflags; + + spin_lock_irqsave(otgws_spinlock, irqflags); + + if (!enabled) { + __pm_relax(otgws_xceiv-wsource); + spin_unlock_irqrestore(otgws_spinlock, irqflags); + return; + } + + switch (event) { + case USB_EVENT_VBUS: + case USB_EVENT_ENUMERATED: + __pm_stay_awake(otgws_xceiv-wsource); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_CHARGER: + __pm_relax(otgws_xceiv-wsource); + break; + + default: + break; + } + + spin_unlock_irqrestore(otgws_spinlock, irqflags); +} +
[RFC v3 2/2] usb: phy: Temporarily hold timed wakeup source on charger and disconnect events
From: Todd Poynor toddpoy...@google.com usb: phy: Temporarily hold timed wakeup source on charger and disconnect events It temporarily holds a timed wakeup source on USB disconnect events, to allow the rest of the system time to react to the USB disconnection (dropping host sessions, updating charger status, etc.) prior to re-allowing suspend Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Sumit Semwal sumit.sem...@linaro.org Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message and addressed community feedback] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- v3: * Modified the commit log. * Remove indirect function usb_temporary_hold_wsource and call __pm_wakeup_even directly. v2: * Implement usb_temporary_hold_wsource function in phy. v1: * Removed the refactoring logic from this integrated into main driver code. RFC: * Integrated the refactoring logic and logic to hold wakeupsource temporarily. drivers/usb/phy/otg-wakeupsource.c | 3 ++- include/linux/usb/phy.h| 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index d9a1720..7bc9657 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -47,7 +47,8 @@ static void otgws_handle_event(struct usb_phy *otgws_xceiv, unsigned long event) case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - __pm_relax(otgws_xceiv-wsource); + __pm_wakeup_event(otgws_xceiv-wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index c71cf15..f8f9f1f 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -12,6 +12,8 @@ #include linux/notifier.h #include linux/usb.h +#define TEMPORARY_HOLD_TIME2000 + enum usb_phy_interface { USBPHY_INTERFACE_MODE_UNKNOWN, USBPHY_INTERFACE_MODE_UTMI, -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v2 2/2] usb: phy: Temporarily hold wakeupsource on charger connect and disconnect events
From: Todd Poynor usb: phy: Temporarily hold wakeupsource on charger connect and disconnect events Allow other parts of the system to react to the charger connect/disconnect event without allowing the system to suspend before the other parts can process the event. This wakeup_source times out after 2 seconds; if nobody else holds a wakeup_source by that time then the device can sleep. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Signed-off-by: Todd Poynor [kiran: Added context to commit message wakeupsource handling implemented per PHY in phy core] Signed-off-by: Kiran Raparthy --- drivers/usb/phy/otg-wakeupsource.c | 2 +- drivers/usb/phy/phy.c | 10 ++ include/linux/usb/phy.h| 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index fca2010..70fa05e 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -48,7 +48,7 @@ static void otgws_handle_event(struct usb_phy *otgws_xceiv, unsigned long event) case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - usb_drop_wsource(otgws_xceiv); + usb_temporary_hold_wsource(otgws_xceiv); break; default: diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 659b1e8..c488716 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -483,3 +483,13 @@ void usb_drop_wsource(struct usb_phy *x) __pm_relax(>wsource); } EXPORT_SYMBOL_GPL(usb_drop_wsource); + +/** + * usb_temporary_hold_wsource - temporarily hold wakeupsource + * @usb_phy: the phy returned by usb_get_phy() + */ +void usb_temporary_hold_wsource(struct usb_phy *x) +{ + __pm_wakeup_event(>wsource, msecs_to_jiffies(TEMPORARY_HOLD_TIME)); +} +EXPORT_SYMBOL_GPL(usb_temporary_hold_wsource); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 6c680e6..5f9b70e 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -13,6 +13,8 @@ #include #include +#define TEMPORARY_HOLD_TIME2000 + enum usb_phy_interface { USBPHY_INTERFACE_MODE_UNKNOWN, USBPHY_INTERFACE_MODE_UTMI, @@ -218,6 +220,7 @@ 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); +void usb_temporary_hold_wsource(struct usb_phy *x); #else static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) { -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v2 1/2] usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor 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 Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Arve Hj�nnev�g Cc: Benoit Goby Signed-off-by: Todd Poynor [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] Signed-off-by: Kiran Raparthy --- 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 diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index e253fa0..d9ddd85 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -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 # diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 24a9133..ca2fbaf 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -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 diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c new file mode 100644 index 000..fca2010 --- /dev/null +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -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 +#include +#include +#include +#include +#include +#include + +bool enabled = false; + +static DEFINE_SPINLOCK(otgws_spinlock); +static struct usb_phy *get_phy_hook(void); + +static void otgws_handle_event(struct usb_phy *otgws_xceiv, unsigned long event) +{ + unsigned long irqflags; + + spin_lock_irqsave(_spinlock, irqflags); + + if (!enabled) { + usb_drop_wsource(otgws_xceiv); + spin_unlock_irqrestore(_spinlock, irqflags); + return; + } + + switch (event) { + case USB_EVENT_VBUS: + case USB_EVENT_ENUMERATED: + usb_grab_wsource(otgws_xceiv); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_CHARGER: + usb_drop_wsource(otgws_xceiv); + break; + + default: + break; + } + + spin_unlock_irqrestore(_spinlock, irqflags); +} +static struct usb_phy *get_phy_hook(void) +{ + struct usb_phy *phy; + + phy = usb_get_phy(USB_PHY_TYPE_USB2); + + if (IS_ERR(phy)) { + pr_err("%s: No OTG transceiver found\n", __func__); + return NULL; + } + + return phy; +} +static int otgws_otg_notifications(struct notifier_block *nb, + unsigned long event, void *unused) +{ + static struct usb_phy *otgws_xceiv; + + otgws_xceiv = get_phy_hook(); + + if (otgws_xceiv) + otgws_handle_event(otgws_xceiv, event); + + return NOTIFY_OK; +} + +static int set_enabled(const char *val,
[RFC v2 1/2] usb: phy: Hold wakeupsource when USB is enumerated in peripheral mode
From: Todd Poynor toddpoy...@google.com 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 ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Arve Hj�nnev�g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com [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] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- 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 diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index e253fa0..d9ddd85 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -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 # diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 24a9133..ca2fbaf 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -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 diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c new file mode 100644 index 000..fca2010 --- /dev/null +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -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 +#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); + +static void otgws_handle_event(struct usb_phy *otgws_xceiv, unsigned long event) +{ + unsigned long irqflags; + + spin_lock_irqsave(otgws_spinlock, irqflags); + + if (!enabled) { + usb_drop_wsource(otgws_xceiv); + spin_unlock_irqrestore(otgws_spinlock, irqflags); + return; + } + + switch (event) { + case USB_EVENT_VBUS: + case USB_EVENT_ENUMERATED: + usb_grab_wsource(otgws_xceiv); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_CHARGER: + usb_drop_wsource(otgws_xceiv); + break; + + default: + break; + } + + spin_unlock_irqrestore(otgws_spinlock, irqflags); +} +static struct usb_phy *get_phy_hook(void) +{ + struct usb_phy *phy; + + phy = usb_get_phy(USB_PHY_TYPE_USB2); + + if (IS_ERR(phy)) { + pr_err(%s: No OTG transceiver found\n, __func__); + return NULL; + } + + return phy; +} +static int otgws_otg_notifications(struct notifier_block *nb, +
[RFC v2 2/2] usb: phy: Temporarily hold wakeupsource on charger connect and disconnect events
From: Todd Poynor toddpoy...@google.com usb: phy: Temporarily hold wakeupsource on charger connect and disconnect events Allow other parts of the system to react to the charger connect/disconnect event without allowing the system to suspend before the other parts can process the event. This wakeup_source times out after 2 seconds; if nobody else holds a wakeup_source by that time then the device can sleep. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message wakeupsource handling implemented per PHY in phy core] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- drivers/usb/phy/otg-wakeupsource.c | 2 +- drivers/usb/phy/phy.c | 10 ++ include/linux/usb/phy.h| 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index fca2010..70fa05e 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -48,7 +48,7 @@ static void otgws_handle_event(struct usb_phy *otgws_xceiv, unsigned long event) case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - usb_drop_wsource(otgws_xceiv); + usb_temporary_hold_wsource(otgws_xceiv); break; default: diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 659b1e8..c488716 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -483,3 +483,13 @@ void usb_drop_wsource(struct usb_phy *x) __pm_relax(x-wsource); } EXPORT_SYMBOL_GPL(usb_drop_wsource); + +/** + * usb_temporary_hold_wsource - temporarily hold wakeupsource + * @usb_phy: the phy returned by usb_get_phy() + */ +void usb_temporary_hold_wsource(struct usb_phy *x) +{ + __pm_wakeup_event(x-wsource, msecs_to_jiffies(TEMPORARY_HOLD_TIME)); +} +EXPORT_SYMBOL_GPL(usb_temporary_hold_wsource); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 6c680e6..5f9b70e 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -13,6 +13,8 @@ #include linux/usb.h #include linux/pm_wakeup.h +#define TEMPORARY_HOLD_TIME2000 + enum usb_phy_interface { USBPHY_INTERFACE_MODE_UNKNOWN, USBPHY_INTERFACE_MODE_UTMI, @@ -218,6 +220,7 @@ 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); +void usb_temporary_hold_wsource(struct usb_phy *x); #else static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) { -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v1 2/2] usb: otg: Temporarily hold wakeupsource on charger
From: Todd Poynor usb: otg: Temporarily hold wakeupsource on charger connect and disconnect events Allow other parts of the system to react to the charger connect/disconnect event without allowing the system to suspend before the other parts can process the event. This wakeup_source times out after 2 seconds; if nobody else holds a wakeup_source by that time then the device can sleep. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Signed-off-by: Todd Poynor [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy --- drivers/usb/phy/otg-wakeupsource.c | 10 +++--- include/linux/usb/otg.h| 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index 7c838d1..9f3c5c1 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -34,8 +34,11 @@ struct otgws_lock { struct wakeup_source wsource; }; -/* VBUS present lock */ - +/* + * VBUS present lock. Also used as a timed lock on charger + * connect/disconnect and USB host disconnect, to allow the system + * to react to the change in power. + */ static struct otgws_lock vbus_lock; static void otgws_handle_event(unsigned long event) @@ -59,7 +62,8 @@ static void otgws_handle_event(unsigned long event) case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - __pm_relax(_lock.wsource); + __pm_wakeup_event(_lock.wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 154332b..4243747 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h @@ -11,6 +11,8 @@ #include +#define TEMPORARY_HOLD_TIME2000 + struct usb_otg { u8 default_a; -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v1 2/2] usb: otg: Temporarily hold wakeupsource on charger and disconnect events
From: Todd Poynor usb: otg: Temporarily hold wakeupsource on charger and disconnect events Allow other parts of the system to react to the charger connect/disconnect event without allowing the system to suspend before the other parts can process the event. This wakeup_source times out after 2 seconds; if nobody else holds a wakeup_source by that time then the device can sleep. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Signed-off-by: Todd Poynor [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy --- drivers/usb/phy/otg-wakeupsource.c | 10 +++--- include/linux/usb/otg.h| 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index 7c838d1..9f3c5c1 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -34,8 +34,11 @@ struct otgws_lock { struct wakeup_source wsource; }; -/* VBUS present lock */ - +/* + * VBUS present lock. Also used as a timed lock on charger + * connect/disconnect and USB host disconnect, to allow the system + * to react to the change in power. + */ static struct otgws_lock vbus_lock; static void otgws_handle_event(unsigned long event) @@ -59,7 +62,8 @@ static void otgws_handle_event(unsigned long event) case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - __pm_relax(_lock.wsource); + __pm_wakeup_event(_lock.wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 154332b..4243747 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h @@ -11,6 +11,8 @@ #include +#define TEMPORARY_HOLD_TIME2000 + struct usb_otg { u8 default_a; -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v1 2/2] usb: otg: Temporarily hold wakeupsource on charger and disconnect events
From: Todd Poynor usb: otg: Temporarily hold wakeupsource on charger and disconnect events Allow other parts of the system to react to the charger connect/disconnect event without allowing the system to suspend before the other parts can process the event. This wakeup_source times out after 2 seconds; if nobody else holds a wakeup_source by that time then the device can sleep. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Signed-off-by: Todd Poynor [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy --- drivers/usb/phy/otg-wakeupsource.c | 10 +++--- include/linux/usb/otg.h| 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index 7c838d1..9f3c5c1 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -34,8 +34,11 @@ struct otgws_lock { struct wakeup_source wsource; }; -/* VBUS present lock */ - +/* + * VBUS present lock. Also used as a timed lock on charger + * connect/disconnect and USB host disconnect, to allow the system + * to react to the change in power. + */ static struct otgws_lock vbus_lock; static void otgws_handle_event(unsigned long event) @@ -59,7 +62,8 @@ static void otgws_handle_event(unsigned long event) case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - __pm_relax(_lock.wsource); + __pm_wakeup_event(_lock.wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 154332b..4243747 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h @@ -11,6 +11,8 @@ #include +#define TEMPORARY_HOLD_TIME2000 + struct usb_otg { u8 default_a; -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v1 1/2] USB: OTG: Hold wakeupsource when VBUS present
From: Todd Poynor USB: OTG: Hold wakeupsource when VBUS present Purpose of this is to prevent the system to enter into suspend state from USB peripheral traffic by hodling a wakeupsource when USB(otg) 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 Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Arve Hj�nnev�g Cc: Benoit Goby Signed-off-by: Todd Poynor [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. __pm_stay_awake and __pm_relax called directly from the main. code instead of calling them via otgws_grab,otgws_drop. modified Kconfig help text] Signed-off-by: Kiran Raparthy --- drivers/usb/phy/Kconfig| 8 +++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/otg-wakeupsource.c | 144 + 3 files changed, 153 insertions(+) create mode 100644 drivers/usb/phy/otg-wakeupsource.c diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index e253fa0..d9ddd85 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -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 # diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 24a9133..ca2fbaf 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -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 diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c new file mode 100644 index 000..7c838d1 --- /dev/null +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -0,0 +1,144 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +bool enabled = false; + +static DEFINE_SPINLOCK(otgws_spinlock); +static struct usb_phy *get_phy_hook(void); + +/* Only one lock, but since these 2 fields are associated with each other... */ + +struct otgws_lock { + char name[40]; + struct wakeup_source wsource; +}; + +/* VBUS present lock */ + +static struct otgws_lock vbus_lock; + +static void otgws_handle_event(unsigned long event) +{ + unsigned long irqflags; + + spin_lock_irqsave(_spinlock, irqflags); + + if (!enabled) { + __pm_relax(_lock.wsource); + spin_unlock_irqrestore(_spinlock, irqflags); + return; + } + + switch (event) { + case USB_EVENT_VBUS: + case USB_EVENT_ENUMERATED: + __pm_stay_awake(_lock.wsource); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_CHARGER: + __pm_relax(_lock.wsource); + break; + + default: + break; + } + + spin_unlock_irqrestore(_spinlock, irqflags); +} +static struct usb_phy *get_phy_hook(void) +{ + struct usb_phy *phy; + + phy = usb_get_phy(USB_PHY_TYPE_USB2); + + if (IS_ERR(phy)) { + pr_err("%s: No OTG transceiver found\n", __func__); + return NULL; + } + + return phy; +} +static int otgws_otg_notifications(struct notifier_block *nb, + unsigned long event, void *unused) +{ + otgws_handle_event(event); + return NOTIFY_OK; +} + +static int
[RFC v1 1/2] USB: OTG: Hold wakeupsource when VBUS present
From: Todd Poynor toddpoy...@google.com USB: OTG: Hold wakeupsource when VBUS present Purpose of this is to prevent the system to enter into suspend state from USB peripheral traffic by hodling a wakeupsource when USB(otg) 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 ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Arve Hj�nnev�g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com [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. __pm_stay_awake and __pm_relax called directly from the main. code instead of calling them via otgws_grab,otgws_drop. modified Kconfig help text] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- drivers/usb/phy/Kconfig| 8 +++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/otg-wakeupsource.c | 144 + 3 files changed, 153 insertions(+) create mode 100644 drivers/usb/phy/otg-wakeupsource.c diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index e253fa0..d9ddd85 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -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 # diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 24a9133..ca2fbaf 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -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 diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c new file mode 100644 index 000..7c838d1 --- /dev/null +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -0,0 +1,144 @@ +/* + * 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 +#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); + +/* Only one lock, but since these 2 fields are associated with each other... */ + +struct otgws_lock { + char name[40]; + struct wakeup_source wsource; +}; + +/* VBUS present lock */ + +static struct otgws_lock vbus_lock; + +static void otgws_handle_event(unsigned long event) +{ + unsigned long irqflags; + + spin_lock_irqsave(otgws_spinlock, irqflags); + + if (!enabled) { + __pm_relax(vbus_lock.wsource); + spin_unlock_irqrestore(otgws_spinlock, irqflags); + return; + } + + switch (event) { + case USB_EVENT_VBUS: + case USB_EVENT_ENUMERATED: + __pm_stay_awake(vbus_lock.wsource); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_CHARGER: + __pm_relax(vbus_lock.wsource); + break; + + default: + break; + } + + spin_unlock_irqrestore(otgws_spinlock, irqflags); +} +static struct usb_phy *get_phy_hook(void) +{ + struct usb_phy *phy; + + phy = usb_get_phy(USB_PHY_TYPE_USB2); + + if (IS_ERR(phy)) { + pr_err(%s: No OTG transceiver
[RFC v1 2/2] usb: otg: Temporarily hold wakeupsource on charger and disconnect events
From: Todd Poynor toddpoy...@google.com usb: otg: Temporarily hold wakeupsource on charger and disconnect events Allow other parts of the system to react to the charger connect/disconnect event without allowing the system to suspend before the other parts can process the event. This wakeup_source times out after 2 seconds; if nobody else holds a wakeup_source by that time then the device can sleep. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- drivers/usb/phy/otg-wakeupsource.c | 10 +++--- include/linux/usb/otg.h| 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index 7c838d1..9f3c5c1 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -34,8 +34,11 @@ struct otgws_lock { struct wakeup_source wsource; }; -/* VBUS present lock */ - +/* + * VBUS present lock. Also used as a timed lock on charger + * connect/disconnect and USB host disconnect, to allow the system + * to react to the change in power. + */ static struct otgws_lock vbus_lock; static void otgws_handle_event(unsigned long event) @@ -59,7 +62,8 @@ static void otgws_handle_event(unsigned long event) case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - __pm_relax(vbus_lock.wsource); + __pm_wakeup_event(vbus_lock.wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 154332b..4243747 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h @@ -11,6 +11,8 @@ #include linux/usb/phy.h +#define TEMPORARY_HOLD_TIME2000 + struct usb_otg { u8 default_a; -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v1 2/2] usb: otg: Temporarily hold wakeupsource on charger and disconnect events
From: Todd Poynor toddpoy...@google.com usb: otg: Temporarily hold wakeupsource on charger and disconnect events Allow other parts of the system to react to the charger connect/disconnect event without allowing the system to suspend before the other parts can process the event. This wakeup_source times out after 2 seconds; if nobody else holds a wakeup_source by that time then the device can sleep. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- drivers/usb/phy/otg-wakeupsource.c | 10 +++--- include/linux/usb/otg.h| 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index 7c838d1..9f3c5c1 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -34,8 +34,11 @@ struct otgws_lock { struct wakeup_source wsource; }; -/* VBUS present lock */ - +/* + * VBUS present lock. Also used as a timed lock on charger + * connect/disconnect and USB host disconnect, to allow the system + * to react to the change in power. + */ static struct otgws_lock vbus_lock; static void otgws_handle_event(unsigned long event) @@ -59,7 +62,8 @@ static void otgws_handle_event(unsigned long event) case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - __pm_relax(vbus_lock.wsource); + __pm_wakeup_event(vbus_lock.wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 154332b..4243747 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h @@ -11,6 +11,8 @@ #include linux/usb/phy.h +#define TEMPORARY_HOLD_TIME2000 + struct usb_otg { u8 default_a; -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v1 2/2] usb: otg: Temporarily hold wakeupsource on charger
From: Todd Poynor toddpoy...@google.com usb: otg: Temporarily hold wakeupsource on charger connect and disconnect events Allow other parts of the system to react to the charger connect/disconnect event without allowing the system to suspend before the other parts can process the event. This wakeup_source times out after 2 seconds; if nobody else holds a wakeup_source by that time then the device can sleep. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Signed-off-by: Todd Poynor toddpoy...@google.com [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- drivers/usb/phy/otg-wakeupsource.c | 10 +++--- include/linux/usb/otg.h| 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index 7c838d1..9f3c5c1 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -34,8 +34,11 @@ struct otgws_lock { struct wakeup_source wsource; }; -/* VBUS present lock */ - +/* + * VBUS present lock. Also used as a timed lock on charger + * connect/disconnect and USB host disconnect, to allow the system + * to react to the change in power. + */ static struct otgws_lock vbus_lock; static void otgws_handle_event(unsigned long event) @@ -59,7 +62,8 @@ static void otgws_handle_event(unsigned long event) case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - __pm_relax(vbus_lock.wsource); + __pm_wakeup_event(vbus_lock.wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 154332b..4243747 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h @@ -11,6 +11,8 @@ #include linux/usb/phy.h +#define TEMPORARY_HOLD_TIME2000 + struct usb_otg { u8 default_a; -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC 2/2] usb: otg: Temporarily hold wakeupsource on charger and disconnect events
From: Todd Poynor usb: otg: Temporarily hold wakeupsource on charger and disconnect events Allow other parts of the system to react to the charger connect/disconnect event without allowing the system to suspend before the other parts can process the event. This wakeup_source times out after 2 seconds; if nobody else holds a wakeup_source by that time then the device can sleep. This patch also refactoras the logic of wakeupsource_init,otg_notifications and handle event funtions This is one of the number of patches from the Android AOSP tegra.git tree, which is used on Android devices. so I wanted to submit it for review to see if it should go upstream. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Signed-off-by: Todd Poynor Signed-off-by: Kiran Raparthy [kiran: Added context to commit message] --- drivers/usb/phy/otg-wakeupsource.c | 108 ++--- include/linux/usb/otg.h| 2 + 2 files changed, 41 insertions(+), 69 deletions(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index fa44e11..d2c16b8 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -39,21 +39,25 @@ struct otgws_lock { }; /* - * VBUS present lock. ++ * VBUS present lock. Also used as a timed lock on charger ++ * connect/disconnect and USB host disconnect, to allow the system ++ * to react to the change in power. */ static struct otgws_lock vbus_lock; -static int otgws_otg_notifications(struct notifier_block *nb, - unsigned long event, void *unused) +static void otgws_handle_event(unsigned long event) { unsigned long irqflags; - if (!enabled) - return NOTIFY_OK; - spin_lock_irqsave(_spinlock, irqflags); + if (!enabled) { + __pm_relax(_lock.wsource); + spin_unlock_irqrestore(_spinlock, irqflags); + return; + } + switch (event) { case USB_EVENT_VBUS: case USB_EVENT_ENUMERATED: @@ -63,7 +67,8 @@ static int otgws_otg_notifications(struct notifier_block *nb, case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - __pm_relax(_lock.wsource); + __pm_wakeup_event(_lock.wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: @@ -71,72 +76,25 @@ static int otgws_otg_notifications(struct notifier_block *nb, } spin_unlock_irqrestore(_spinlock, irqflags); - return NOTIFY_OK; -} - -static void sync_with_xceiv_state(void) -{ - if ((otgws_xceiv->last_event == USB_EVENT_VBUS) || - (otgws_xceiv->last_event == USB_EVENT_ENUMERATED)) - __pm_stay_awake(_lock.wsource); - else - __pm_relax(_lock.wsource); } -static int init_for_xceiv(void) +static int otgws_otg_notifications(struct notifier_block *nb, + unsigned long event, void *unused) { - int rv; - struct usb_phy *phy; - - if (!otgws_xceiv) { - phy = usb_get_phy(USB_PHY_TYPE_USB2); - - if (IS_ERR(phy)) { - pr_err("%s: No USB transceiver found\n", __func__); - return PTR_ERR(phy); - } - otgws_xceiv = phy; - - snprintf(vbus_lock.name, sizeof(vbus_lock.name), "vbus-%s", -dev_name(otgws_xceiv->dev)); - wakeup_source_init(_lock.wsource, vbus_lock.name); - - rv = usb_register_notifier(otgws_xceiv, _nb); - - if (rv) { - pr_err("%s: usb_register_notifier on transceiver %s - failed\n", __func__, - dev_name(otgws_xceiv->dev)); - otgws_xceiv = NULL; - wakeup_source_trash(_lock.wsource); - return rv; - } - } - - return 0; + otgws_handle_event(event); + return NOTIFY_OK; } static int set_enabled(const char *val, const struct kernel_param *kp) { - unsigned long irqflags; int rv = param_set_bool(val, kp); if (rv) return rv; - rv = init_for_xceiv(); - - if (rv) - return rv; - - spin_lock_irqsave(_spinlock, irqflags); - - if (enabled) - sync_with_xceiv_state(); - else - __pm_relax(_lock.wsource); + if (otgws_xceiv) + otgws_handle_event(otgws_xceiv->last_event); - spin_unlock_irqrestore(_spinlock, irqflags); return 0; } @@ -150,19 +108,31 @@ MODULE_PARM_DESC(enabled, "enable wakelock when VBUS present"); static int __init otg_wakeupsource_init(void) { - unsigned long irqflags; + int
[RFC 1/2] USB: OTG: Hold wakeupsource when VBUS present
From: Todd Poynor USB: OTG: Hold wakeupsource when VBUS present Enabled by default, can disable with: echo N > /sys/module/otg_wakeupsource/parameters/enabled This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. so I wanted to submit it for review to see if it should go upstream. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Cc: Arve Hj�nnev�g Cc: Benoit Goby Signed-off-by: Todd Poynor Signed-off-by: Kiran Raparthy [kiran: Added context to commit message Included build fix from Benoit Goby and Arve Arve Hj�nnev�g Removed lock->held field in driver as this mechanism is provided in wakeup.c wakelock(wl) terminology replaced with wakeup_source(ws) sys entry(module param) field modified to otg_wakeupsource __pm_stay_awake and __pm_relax called directly from the main code instead of calling them via otgws_grab,otgws_drop] --- drivers/usb/phy/Kconfig| 8 ++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/otg-wakeupsource.c | 171 + 3 files changed, 180 insertions(+) create mode 100644 drivers/usb/phy/otg-wakeupsource.c diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index e253fa0..9c747b2 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -6,6 +6,14 @@ menu "USB Physical Layer drivers" config USB_PHY def_bool n +config USB_OTG_WAKEUPSOURCE + bool "Hold a wakeupsource when USB connected" + depends on PM_SLEEP + select USB_PHY + help + Select this to automatically hold a wakeupsource when USB is + connected, preventing suspend. + # # USB Transceiver Drivers # diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 24a9133..ca2fbaf 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -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 diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c new file mode 100644 index 000..fa44e11 --- /dev/null +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -0,0 +1,171 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +static bool enabled = true; +static struct usb_phy *otgws_xceiv; +static struct notifier_block otgws_nb; + + +static DEFINE_SPINLOCK(otgws_spinlock); + +/* + * Only one lock, but since these 2 fields are associated with each other... + */ + +struct otgws_lock { + char name[40]; + struct wakeup_source wsource; +}; + +/* + * VBUS present lock. + */ + +static struct otgws_lock vbus_lock; + +static int otgws_otg_notifications(struct notifier_block *nb, + unsigned long event, void *unused) +{ + unsigned long irqflags; + + if (!enabled) + return NOTIFY_OK; + + spin_lock_irqsave(_spinlock, irqflags); + + switch (event) { + case USB_EVENT_VBUS: + case USB_EVENT_ENUMERATED: + __pm_stay_awake(_lock.wsource); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_CHARGER: + __pm_relax(_lock.wsource); + break; + + default: + break; + } + + spin_unlock_irqrestore(_spinlock, irqflags); + return NOTIFY_OK; +} + +static void sync_with_xceiv_state(void) +{ + if ((otgws_xceiv->last_event == USB_EVENT_VBUS) || + (otgws_xceiv->last_event == USB_EVENT_ENUMERATED)) + __pm_stay_awake(_lock.wsource); + else + __pm_relax(_lock.wsource); +} + +static int init_for_xceiv(void) +{ + int rv; + struct usb_phy *phy; + + if (!otgws_xceiv) { + phy = usb_get_phy(USB_PHY_TYPE_USB2); + + if (IS_ERR(phy)) { + pr_err("%s: No USB transceiver found\n", __func__); + return PTR_ERR(phy); + } + otgws_xceiv = phy; + + snprintf(vbus_lock.name, sizeof(vbus_lock.name), "vbus-%s", +dev_name(otgws_xceiv->dev)); +
[RFC 1/2] USB: OTG: Hold wakeupsource when VBUS present
From: Todd Poynor toddpoy...@google.com USB: OTG: Hold wakeupsource when VBUS present Enabled by default, can disable with: echo N /sys/module/otg_wakeupsource/parameters/enabled This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. so I wanted to submit it for review to see if it should go upstream. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Cc: Arve Hj�nnev�g a...@android.com Cc: Benoit Goby ben...@android.com Signed-off-by: Todd Poynor toddpoy...@google.com Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org [kiran: Added context to commit message Included build fix from Benoit Goby and Arve Arve Hj�nnev�g Removed lock-held field in driver as this mechanism is provided in wakeup.c wakelock(wl) terminology replaced with wakeup_source(ws) sys entry(module param) field modified to otg_wakeupsource __pm_stay_awake and __pm_relax called directly from the main code instead of calling them via otgws_grab,otgws_drop] --- drivers/usb/phy/Kconfig| 8 ++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/otg-wakeupsource.c | 171 + 3 files changed, 180 insertions(+) create mode 100644 drivers/usb/phy/otg-wakeupsource.c diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index e253fa0..9c747b2 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -6,6 +6,14 @@ menu USB Physical Layer drivers config USB_PHY def_bool n +config USB_OTG_WAKEUPSOURCE + bool Hold a wakeupsource when USB connected + depends on PM_SLEEP + select USB_PHY + help + Select this to automatically hold a wakeupsource when USB is + connected, preventing suspend. + # # USB Transceiver Drivers # diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 24a9133..ca2fbaf 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -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 diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c new file mode 100644 index 000..fa44e11 --- /dev/null +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -0,0 +1,171 @@ +/* + * 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 +#include linux/module.h +#include linux/notifier.h +#include linux/pm_wakeup.h +#include linux/spinlock.h +#include linux/usb/otg.h + +static bool enabled = true; +static struct usb_phy *otgws_xceiv; +static struct notifier_block otgws_nb; + + +static DEFINE_SPINLOCK(otgws_spinlock); + +/* + * Only one lock, but since these 2 fields are associated with each other... + */ + +struct otgws_lock { + char name[40]; + struct wakeup_source wsource; +}; + +/* + * VBUS present lock. + */ + +static struct otgws_lock vbus_lock; + +static int otgws_otg_notifications(struct notifier_block *nb, + unsigned long event, void *unused) +{ + unsigned long irqflags; + + if (!enabled) + return NOTIFY_OK; + + spin_lock_irqsave(otgws_spinlock, irqflags); + + switch (event) { + case USB_EVENT_VBUS: + case USB_EVENT_ENUMERATED: + __pm_stay_awake(vbus_lock.wsource); + break; + + case USB_EVENT_NONE: + case USB_EVENT_ID: + case USB_EVENT_CHARGER: + __pm_relax(vbus_lock.wsource); + break; + + default: + break; + } + + spin_unlock_irqrestore(otgws_spinlock, irqflags); + return NOTIFY_OK; +} + +static void sync_with_xceiv_state(void) +{ + if ((otgws_xceiv-last_event == USB_EVENT_VBUS) || + (otgws_xceiv-last_event == USB_EVENT_ENUMERATED)) + __pm_stay_awake(vbus_lock.wsource); + else + __pm_relax(vbus_lock.wsource); +} + +static int init_for_xceiv(void) +{ + int rv; + struct usb_phy *phy; + + if (!otgws_xceiv) { + phy = usb_get_phy(USB_PHY_TYPE_USB2); + + if (IS_ERR(phy)) { +
[RFC 2/2] usb: otg: Temporarily hold wakeupsource on charger and disconnect events
From: Todd Poynor toddpoy...@google.com usb: otg: Temporarily hold wakeupsource on charger and disconnect events Allow other parts of the system to react to the charger connect/disconnect event without allowing the system to suspend before the other parts can process the event. This wakeup_source times out after 2 seconds; if nobody else holds a wakeup_source by that time then the device can sleep. This patch also refactoras the logic of wakeupsource_init,otg_notifications and handle event funtions This is one of the number of patches from the Android AOSP tegra.git tree, which is used on Android devices. so I wanted to submit it for review to see if it should go upstream. Cc: Felipe Balbi ba...@ti.com Cc: Greg Kroah-Hartman gre...@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Cc: linux-...@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Signed-off-by: Todd Poynor toddpoy...@google.com Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org [kiran: Added context to commit message] --- drivers/usb/phy/otg-wakeupsource.c | 108 ++--- include/linux/usb/otg.h| 2 + 2 files changed, 41 insertions(+), 69 deletions(-) diff --git a/drivers/usb/phy/otg-wakeupsource.c b/drivers/usb/phy/otg-wakeupsource.c index fa44e11..d2c16b8 100644 --- a/drivers/usb/phy/otg-wakeupsource.c +++ b/drivers/usb/phy/otg-wakeupsource.c @@ -39,21 +39,25 @@ struct otgws_lock { }; /* - * VBUS present lock. ++ * VBUS present lock. Also used as a timed lock on charger ++ * connect/disconnect and USB host disconnect, to allow the system ++ * to react to the change in power. */ static struct otgws_lock vbus_lock; -static int otgws_otg_notifications(struct notifier_block *nb, - unsigned long event, void *unused) +static void otgws_handle_event(unsigned long event) { unsigned long irqflags; - if (!enabled) - return NOTIFY_OK; - spin_lock_irqsave(otgws_spinlock, irqflags); + if (!enabled) { + __pm_relax(vbus_lock.wsource); + spin_unlock_irqrestore(otgws_spinlock, irqflags); + return; + } + switch (event) { case USB_EVENT_VBUS: case USB_EVENT_ENUMERATED: @@ -63,7 +67,8 @@ static int otgws_otg_notifications(struct notifier_block *nb, case USB_EVENT_NONE: case USB_EVENT_ID: case USB_EVENT_CHARGER: - __pm_relax(vbus_lock.wsource); + __pm_wakeup_event(vbus_lock.wsource, + msecs_to_jiffies(TEMPORARY_HOLD_TIME)); break; default: @@ -71,72 +76,25 @@ static int otgws_otg_notifications(struct notifier_block *nb, } spin_unlock_irqrestore(otgws_spinlock, irqflags); - return NOTIFY_OK; -} - -static void sync_with_xceiv_state(void) -{ - if ((otgws_xceiv-last_event == USB_EVENT_VBUS) || - (otgws_xceiv-last_event == USB_EVENT_ENUMERATED)) - __pm_stay_awake(vbus_lock.wsource); - else - __pm_relax(vbus_lock.wsource); } -static int init_for_xceiv(void) +static int otgws_otg_notifications(struct notifier_block *nb, + unsigned long event, void *unused) { - int rv; - struct usb_phy *phy; - - if (!otgws_xceiv) { - phy = usb_get_phy(USB_PHY_TYPE_USB2); - - if (IS_ERR(phy)) { - pr_err(%s: No USB transceiver found\n, __func__); - return PTR_ERR(phy); - } - otgws_xceiv = phy; - - snprintf(vbus_lock.name, sizeof(vbus_lock.name), vbus-%s, -dev_name(otgws_xceiv-dev)); - wakeup_source_init(vbus_lock.wsource, vbus_lock.name); - - rv = usb_register_notifier(otgws_xceiv, otgws_nb); - - if (rv) { - pr_err(%s: usb_register_notifier on transceiver %s - failed\n, __func__, - dev_name(otgws_xceiv-dev)); - otgws_xceiv = NULL; - wakeup_source_trash(vbus_lock.wsource); - return rv; - } - } - - return 0; + otgws_handle_event(event); + return NOTIFY_OK; } static int set_enabled(const char *val, const struct kernel_param *kp) { - unsigned long irqflags; int rv = param_set_bool(val, kp); if (rv) return rv; - rv = init_for_xceiv(); - - if (rv) - return rv; - - spin_lock_irqsave(otgws_spinlock, irqflags); - - if (enabled) - sync_with_xceiv_state(); - else - __pm_relax(vbus_lock.wsource); + if (otgws_xceiv) + otgws_handle_event(otgws_xceiv-last_event); - spin_unlock_irqrestore(otgws_spinlock, irqflags);
[PATCH - RESEND] Bluetooth: Keep master role when SCO or eSCO is active
From: "hyungseoung.yoo" Preserve the master role when SCO or eSCO is active as this improves compatability with lots of headset and chipset combinations. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. It looks like it would improve support for compatibility with lot of headset,so I wanted to submit it for review to see if it should go upstream. v3: Fixed formatting issues pointed by Sergei Cc: Marcel Holtmann Cc: Gustavo Padovan Cc: Johan Hedberg Cc: "David S. Miller" Cc: linux-blueto...@vger.kernel.org Cc: net...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Signed-off-by: hyungseoung.yoo Signed-off-by: Jaikumar Ganesh [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy --- net/bluetooth/hci_event.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 15010a2..cfb1355 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1915,6 +1915,14 @@ unlock: hci_conn_check_pending(hdev); } +static inline bool is_sco_active(struct hci_dev *hdev) +{ + if (hci_conn_hash_lookup_state(hdev, SCO_LINK, BT_CONNECTED) || + hci_conn_hash_lookup_state(hdev, ESCO_LINK, BT_CONNECTED)) + return true; + return false; +} + static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_ev_conn_request *ev = (void *) skb->data; @@ -1961,7 +1969,9 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) bacpy(, >bdaddr); - if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER)) + if (lmp_rswitch_capable(hdev) && + ((mask & HCI_LM_MASTER) || + is_sco_active(hdev))) cp.role = 0x00; /* Become master */ else cp.role = 0x01; /* Remain slave */ -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH - RESEND] Bluetooth: Keep master role when SCO or eSCO is active
From: hyungseoung.yoo hyungseoung@samsung.com Preserve the master role when SCO or eSCO is active as this improves compatability with lots of headset and chipset combinations. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. It looks like it would improve support for compatibility with lot of headset,so I wanted to submit it for review to see if it should go upstream. v3: Fixed formatting issues pointed by Sergei Cc: Marcel Holtmann mar...@holtmann.org Cc: Gustavo Padovan gust...@padovan.org Cc: Johan Hedberg johan.hedb...@gmail.com Cc: David S. Miller da...@davemloft.net Cc: linux-blueto...@vger.kernel.org Cc: net...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Signed-off-by: hyungseoung.yoo hyungseoung@samsung.com Signed-off-by: Jaikumar Ganesh jaikum...@android.com [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- net/bluetooth/hci_event.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 15010a2..cfb1355 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1915,6 +1915,14 @@ unlock: hci_conn_check_pending(hdev); } +static inline bool is_sco_active(struct hci_dev *hdev) +{ + if (hci_conn_hash_lookup_state(hdev, SCO_LINK, BT_CONNECTED) || + hci_conn_hash_lookup_state(hdev, ESCO_LINK, BT_CONNECTED)) + return true; + return false; +} + static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_ev_conn_request *ev = (void *) skb-data; @@ -1961,7 +1969,9 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) bacpy(cp.bdaddr, ev-bdaddr); - if (lmp_rswitch_capable(hdev) (mask HCI_LM_MASTER)) + if (lmp_rswitch_capable(hdev) + ((mask HCI_LM_MASTER) || + is_sco_active(hdev))) cp.role = 0x00; /* Become master */ else cp.role = 0x01; /* Remain slave */ -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC] Bluetooth: Do not attempt to send dlci disconnect when in BT_CONFIG.
From: Nick Pelly Do not attempt to send dlci disconnect when in BT_CONFIG. This fixes a bug where shutdown() and close() on a rfcomm socket during ACL connection would not cause HCI Create Connection Cancel. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. so I wanted to submit it for review to see if it should go upstream. Cc: Marcel Holtmann Cc: Gustavo Padovan Cc: Johan Hedberg Cc: David S. Miller Cc: Peter Hurley Cc: Seung-Woo Kim Cc: Nick Pelly Cc: linux-blueto...@vger.kernel.org Cc: net...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Signed-off-by: Nick Pelly [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy --- net/bluetooth/rfcomm/core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c index cf62026..6a531e7 100644 --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c @@ -456,7 +456,6 @@ static int __rfcomm_dlc_close(struct rfcomm_dlc *d, int err) switch (d->state) { case BT_CONNECT: - case BT_CONFIG: case BT_OPEN: case BT_CONNECT2: if (test_and_clear_bit(RFCOMM_DEFER_SETUP, >flags)) { -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC] Bluetooth: Add ACL MTU, available buffers and total buffers to hci_conn_info.
From: Nick Pelly Add ACL MTU, available buffers and total buffers to hci_conn_info. This provides userspace debugging tools access to ACL flow control state. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. so I wanted to submit it for review to see if it should go upstream. Cc: Marcel Holtmann Cc: Gustavo Padovan Cc: Johan Hedberg Cc: David S. Miller Cc: linux-blueto...@vger.kernel.org Cc: net...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Signed-off-by: Nick Pelly [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy --- include/net/bluetooth/hci.h | 3 +++ net/bluetooth/hci_conn.c| 18 ++ 2 files changed, 21 insertions(+) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index be150cf..67dc0fb 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -1830,6 +1830,9 @@ struct hci_conn_info { __u8 out; __u16state; __u32link_mode; + __u32mtu; + __u32cnt; + __u32pkts; }; struct hci_dev_req { diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 521fd4f..c2ba0fe 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1064,6 +1064,15 @@ int hci_get_conn_list(void __user *arg) (ci + n)->out = c->out; (ci + n)->state = c->state; (ci + n)->link_mode = c->link_mode; + if (c->type == SCO_LINK) { + (ci + n)->mtu = hdev->sco_mtu; + (ci + n)->cnt = hdev->sco_cnt; + (ci + n)->pkts = hdev->sco_pkts; + } else { + (ci + n)->mtu = hdev->acl_mtu; + (ci + n)->cnt = hdev->acl_cnt; + (ci + n)->pkts = hdev->acl_pkts; + } if (++n >= req.conn_num) break; } @@ -1100,6 +1109,15 @@ int hci_get_conn_info(struct hci_dev *hdev, void __user *arg) ci.out = conn->out; ci.state = conn->state; ci.link_mode = conn->link_mode; + if (req.type == SCO_LINK) { + ci.mtu = hdev->sco_mtu; + ci.cnt = hdev->sco_cnt; + ci.pkts = hdev->sco_pkts; + } else { + ci.mtu = hdev->acl_mtu; + ci.cnt = hdev->acl_cnt; + ci.pkts = hdev->acl_pkts; + } } hci_dev_unlock(hdev); -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC] Bluetooth: Add ACL MTU, available buffers and total buffers to hci_conn_info.
From: Nick Pelly npe...@google.com Add ACL MTU, available buffers and total buffers to hci_conn_info. This provides userspace debugging tools access to ACL flow control state. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. so I wanted to submit it for review to see if it should go upstream. Cc: Marcel Holtmann mar...@holtmann.org Cc: Gustavo Padovan gust...@padovan.org Cc: Johan Hedberg johan.hedb...@gmail.com Cc: David S. Miller da...@davemloft.net Cc: linux-blueto...@vger.kernel.org Cc: net...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Signed-off-by: Nick Pelly npe...@google.com [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- include/net/bluetooth/hci.h | 3 +++ net/bluetooth/hci_conn.c| 18 ++ 2 files changed, 21 insertions(+) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index be150cf..67dc0fb 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -1830,6 +1830,9 @@ struct hci_conn_info { __u8 out; __u16state; __u32link_mode; + __u32mtu; + __u32cnt; + __u32pkts; }; struct hci_dev_req { diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 521fd4f..c2ba0fe 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1064,6 +1064,15 @@ int hci_get_conn_list(void __user *arg) (ci + n)-out = c-out; (ci + n)-state = c-state; (ci + n)-link_mode = c-link_mode; + if (c-type == SCO_LINK) { + (ci + n)-mtu = hdev-sco_mtu; + (ci + n)-cnt = hdev-sco_cnt; + (ci + n)-pkts = hdev-sco_pkts; + } else { + (ci + n)-mtu = hdev-acl_mtu; + (ci + n)-cnt = hdev-acl_cnt; + (ci + n)-pkts = hdev-acl_pkts; + } if (++n = req.conn_num) break; } @@ -1100,6 +1109,15 @@ int hci_get_conn_info(struct hci_dev *hdev, void __user *arg) ci.out = conn-out; ci.state = conn-state; ci.link_mode = conn-link_mode; + if (req.type == SCO_LINK) { + ci.mtu = hdev-sco_mtu; + ci.cnt = hdev-sco_cnt; + ci.pkts = hdev-sco_pkts; + } else { + ci.mtu = hdev-acl_mtu; + ci.cnt = hdev-acl_cnt; + ci.pkts = hdev-acl_pkts; + } } hci_dev_unlock(hdev); -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC] Bluetooth: Do not attempt to send dlci disconnect when in BT_CONFIG.
From: Nick Pelly npe...@google.com Do not attempt to send dlci disconnect when in BT_CONFIG. This fixes a bug where shutdown() and close() on a rfcomm socket during ACL connection would not cause HCI Create Connection Cancel. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. so I wanted to submit it for review to see if it should go upstream. Cc: Marcel Holtmann mar...@holtmann.org Cc: Gustavo Padovan gust...@padovan.org Cc: Johan Hedberg johan.hedb...@gmail.com Cc: David S. Miller da...@davemloft.net Cc: Peter Hurley pe...@hurleysoftware.com Cc: Seung-Woo Kim sw0312@samsung.com Cc: Nick Pelly npe...@google.com Cc: linux-blueto...@vger.kernel.org Cc: net...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Signed-off-by: Nick Pelly npe...@google.com [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- net/bluetooth/rfcomm/core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c index cf62026..6a531e7 100644 --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c @@ -456,7 +456,6 @@ static int __rfcomm_dlc_close(struct rfcomm_dlc *d, int err) switch (d-state) { case BT_CONNECT: - case BT_CONFIG: case BT_OPEN: case BT_CONNECT2: if (test_and_clear_bit(RFCOMM_DEFER_SETUP, d-flags)) { -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v3] Bluetooth: Keep master role when SCO or eSCO is active
From: "hyungseoung.yoo" Preserve the master role when SCO or eSCO is active as this improves compatability with lots of headset and chipset combinations. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. It looks like it would improve support for compatibility with lot of headset,so I wanted to submit it for review to see if it should go upstream. v3: Fixed formatting issues pointed by Sergei Cc: Marcel Holtmann Cc: Gustavo Padovan Cc: Johan Hedberg Cc: "David S. Miller" Cc: linux-blueto...@vger.kernel.org Cc: net...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Signed-off-by: hyungseoung.yoo Signed-off-by: Jaikumar Ganesh [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy --- net/bluetooth/hci_event.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 15010a2..cfb1355 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1915,6 +1915,14 @@ unlock: hci_conn_check_pending(hdev); } +static inline bool is_sco_active(struct hci_dev *hdev) +{ + if (hci_conn_hash_lookup_state(hdev, SCO_LINK, BT_CONNECTED) || + hci_conn_hash_lookup_state(hdev, ESCO_LINK, BT_CONNECTED)) + return true; + return false; +} + static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_ev_conn_request *ev = (void *) skb->data; @@ -1961,7 +1969,9 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) bacpy(, >bdaddr); - if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER)) + if (lmp_rswitch_capable(hdev) && + ((mask & HCI_LM_MASTER) || + is_sco_active(hdev))) cp.role = 0x00; /* Become master */ else cp.role = 0x01; /* Remain slave */ -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v3] Bluetooth: Keep master role when SCO or eSCO is active
From: hyungseoung.yoo hyungseoung@samsung.com Preserve the master role when SCO or eSCO is active as this improves compatability with lots of headset and chipset combinations. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. It looks like it would improve support for compatibility with lot of headset,so I wanted to submit it for review to see if it should go upstream. v3: Fixed formatting issues pointed by Sergei Cc: Marcel Holtmann mar...@holtmann.org Cc: Gustavo Padovan gust...@padovan.org Cc: Johan Hedberg johan.hedb...@gmail.com Cc: David S. Miller da...@davemloft.net Cc: linux-blueto...@vger.kernel.org Cc: net...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Signed-off-by: hyungseoung.yoo hyungseoung@samsung.com Signed-off-by: Jaikumar Ganesh jaikum...@android.com [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- net/bluetooth/hci_event.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 15010a2..cfb1355 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1915,6 +1915,14 @@ unlock: hci_conn_check_pending(hdev); } +static inline bool is_sco_active(struct hci_dev *hdev) +{ + if (hci_conn_hash_lookup_state(hdev, SCO_LINK, BT_CONNECTED) || + hci_conn_hash_lookup_state(hdev, ESCO_LINK, BT_CONNECTED)) + return true; + return false; +} + static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_ev_conn_request *ev = (void *) skb-data; @@ -1961,7 +1969,9 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) bacpy(cp.bdaddr, ev-bdaddr); - if (lmp_rswitch_capable(hdev) (mask HCI_LM_MASTER)) + if (lmp_rswitch_capable(hdev) + ((mask HCI_LM_MASTER) || + is_sco_active(hdev))) cp.role = 0x00; /* Become master */ else cp.role = 0x01; /* Remain slave */ -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v2] Bluetooth: Keep master role when SCO or eSCO is active
From: "hyungseoung.yoo" Preserve the master role when SCO or eSCO is active as this improves compatability with lots of headset and chipset combinations. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. It looks like it would improve support for compatibility with lot of headset,so I wanted to submit it for review to see if it should go upstream. v2: Fixed formatting issues pointed by Sergei Cc: Marcel Holtmann Cc: Gustavo Padovan Cc: Johan Hedberg Cc: "David S. Miller" Cc: linux-blueto...@vger.kernel.org Cc: net...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team Cc: John Stultz Signed-off-by: hyungseoung.yoo Signed-off-by: Jaikumar Ganesh [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy --- net/bluetooth/hci_event.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 15010a2..48bc772 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1915,6 +1915,14 @@ unlock: hci_conn_check_pending(hdev); } +static inline bool is_sco_active(struct hci_dev *hdev) +{ + if (hci_conn_hash_lookup_state(hdev, SCO_LINK, BT_CONNECTED) || + hci_conn_hash_lookup_state(hdev, ESCO_LINK, BT_CONNECTED)) + return true; + return false; +} + static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_ev_conn_request *ev = (void *) skb->data; @@ -1961,7 +1969,9 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) bacpy(, >bdaddr); - if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER)) + if (lmp_rswitch_capable(hdev) && + ((mask & HCI_LM_MASTER) || + is_sco_active(hdev))) cp.role = 0x00; /* Become master */ else cp.role = 0x01; /* Remain slave */ -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC v2] Bluetooth: Keep master role when SCO or eSCO is active
From: hyungseoung.yoo hyungseoung@samsung.com Preserve the master role when SCO or eSCO is active as this improves compatability with lots of headset and chipset combinations. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. It looks like it would improve support for compatibility with lot of headset,so I wanted to submit it for review to see if it should go upstream. v2: Fixed formatting issues pointed by Sergei Cc: Marcel Holtmann mar...@holtmann.org Cc: Gustavo Padovan gust...@padovan.org Cc: Johan Hedberg johan.hedb...@gmail.com Cc: David S. Miller da...@davemloft.net Cc: linux-blueto...@vger.kernel.org Cc: net...@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Signed-off-by: hyungseoung.yoo hyungseoung@samsung.com Signed-off-by: Jaikumar Ganesh jaikum...@android.com [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- net/bluetooth/hci_event.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 15010a2..48bc772 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1915,6 +1915,14 @@ unlock: hci_conn_check_pending(hdev); } +static inline bool is_sco_active(struct hci_dev *hdev) +{ + if (hci_conn_hash_lookup_state(hdev, SCO_LINK, BT_CONNECTED) || + hci_conn_hash_lookup_state(hdev, ESCO_LINK, BT_CONNECTED)) + return true; + return false; +} + static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_ev_conn_request *ev = (void *) skb-data; @@ -1961,7 +1969,9 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) bacpy(cp.bdaddr, ev-bdaddr); - if (lmp_rswitch_capable(hdev) (mask HCI_LM_MASTER)) + if (lmp_rswitch_capable(hdev) + ((mask HCI_LM_MASTER) || + is_sco_active(hdev))) cp.role = 0x00; /* Become master */ else cp.role = 0x01; /* Remain slave */ -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC] Bluetooth: Keep master role when SCO or eSCO is active
From: "hyungseoung.yoo" Preserve the master role when SCO or eSCO is active as this improves compatability with lots of headset and chipset combinations. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. It looks like it would improve support for compatibility with lot of headset,so I wanted to submit it for review to see if it should go upstream. Cc: Marcel Holtmann (maintainer:BLUETOOTH SUBSYSTEM) Cc: Gustavo Padovan (maintainer:BLUETOOTH SUBSYSTEM) Cc: Johan Hedberg (maintainer:BLUETOOTH SUBSYSTEM) Cc: "David S. Miller" (maintainer:NETWORKING [GENERAL]) Cc: linux-blueto...@vger.kernel.org (open list:BLUETOOTH SUBSYSTEM) Cc: net...@vger.kernel.org (open list:NETWORKING [GENERAL]) Cc: linux-kernel@vger.kernel.org (open list) Cc: Android Kernel Team Cc: John Stultz Signed-off-by: hyungseoung.yoo Signed-off-by: Jaikumar Ganesh [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy --- net/bluetooth/hci_event.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 15010a2..6f944d5 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1915,6 +1915,15 @@ unlock: hci_conn_check_pending(hdev); } +static inline bool is_sco_active(struct hci_dev *hdev) +{ + if (hci_conn_hash_lookup_state(hdev, SCO_LINK, BT_CONNECTED) || + (hci_conn_hash_lookup_state(hdev, ESCO_LINK, + BT_CONNECTED))) + return true; + return false; +} + static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_ev_conn_request *ev = (void *) skb->data; @@ -1961,7 +1970,8 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) bacpy(, >bdaddr); - if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER)) + if (lmp_rswitch_capable(hdev) && ((mask & HCI_LM_MASTER) + || is_sco_active(hdev))) cp.role = 0x00; /* Become master */ else cp.role = 0x01; /* Remain slave */ -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC] Bluetooth: Keep master role when SCO or eSCO is active
From: hyungseoung.yoo hyungseoung@samsung.com Preserve the master role when SCO or eSCO is active as this improves compatability with lots of headset and chipset combinations. This is one of the number of patches from the Android AOSP common.git tree, which is used on almost all Android devices. It looks like it would improve support for compatibility with lot of headset,so I wanted to submit it for review to see if it should go upstream. Cc: Marcel Holtmann mar...@holtmann.org (maintainer:BLUETOOTH SUBSYSTEM) Cc: Gustavo Padovan gust...@padovan.org (maintainer:BLUETOOTH SUBSYSTEM) Cc: Johan Hedberg johan.hedb...@gmail.com (maintainer:BLUETOOTH SUBSYSTEM) Cc: David S. Miller da...@davemloft.net (maintainer:NETWORKING [GENERAL]) Cc: linux-blueto...@vger.kernel.org (open list:BLUETOOTH SUBSYSTEM) Cc: net...@vger.kernel.org (open list:NETWORKING [GENERAL]) Cc: linux-kernel@vger.kernel.org (open list) Cc: Android Kernel Team kernel-t...@android.com Cc: John Stultz john.stu...@linaro.org Signed-off-by: hyungseoung.yoo hyungseoung@samsung.com Signed-off-by: Jaikumar Ganesh jaikum...@android.com [kiran: Added context to commit message] Signed-off-by: Kiran Raparthy kiran.ku...@linaro.org --- net/bluetooth/hci_event.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 15010a2..6f944d5 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1915,6 +1915,15 @@ unlock: hci_conn_check_pending(hdev); } +static inline bool is_sco_active(struct hci_dev *hdev) +{ + if (hci_conn_hash_lookup_state(hdev, SCO_LINK, BT_CONNECTED) || + (hci_conn_hash_lookup_state(hdev, ESCO_LINK, + BT_CONNECTED))) + return true; + return false; +} + static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_ev_conn_request *ev = (void *) skb-data; @@ -1961,7 +1970,8 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) bacpy(cp.bdaddr, ev-bdaddr); - if (lmp_rswitch_capable(hdev) (mask HCI_LM_MASTER)) + if (lmp_rswitch_capable(hdev) ((mask HCI_LM_MASTER) + || is_sco_active(hdev))) cp.role = 0x00; /* Become master */ else cp.role = 0x01; /* Remain slave */ -- 1.8.2.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/