linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: jack - check status of GPIO-based pins on resume
@ 2017-03-21 23:50 Dmitry Torokhov
  2017-03-24 18:51 ` Mark Brown
  2017-03-24 19:16 ` Applied "ASoC: jack - check status of GPIO-based pins on resume" to the asoc tree Mark Brown
  0 siblings, 2 replies; 7+ messages in thread
From: Dmitry Torokhov @ 2017-03-21 23:50 UTC (permalink / raw)
  To: Mark Brown
  Cc: Jaroslav Kysela, Liam Girdwood, Takashi Iwai, alsa-devel, linux-kernel

From: Dmitry Torokhov <dtor@chromium.org>

For GPIO-backed pins that are not configured as wakeup sources, we may
miss change in their state that happens while system is suspended. Let's
use PM notifier to refresh their state upon resume.

Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
---
 include/sound/soc.h  |  1 +
 sound/soc/soc-jack.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index b86168a21d56..c0b8bf463940 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -722,6 +722,7 @@ struct snd_soc_jack_gpio {
 	/* private: */
 	struct snd_soc_jack *jack;
 	struct delayed_work work;
+	struct notifier_block pm_notifier;
 	struct gpio_desc *desc;
 
 	void *data;
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index fbaa1bb41102..d90af94ec1be 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -19,6 +19,7 @@
 #include <linux/workqueue.h>
 #include <linux/delay.h>
 #include <linux/export.h>
+#include <linux/suspend.h>
 #include <trace/events/asoc.h>
 
 /**
@@ -293,6 +294,27 @@ static void gpio_work(struct work_struct *work)
 	snd_soc_jack_gpio_detect(gpio);
 }
 
+static int snd_soc_jack_pm_notifier(struct notifier_block *nb,
+				    unsigned long action, void *data)
+{
+	struct snd_soc_jack_gpio *gpio =
+			container_of(nb, struct snd_soc_jack_gpio, pm_notifier);
+
+	switch (action) {
+	case PM_POST_SUSPEND:
+	case PM_POST_HIBERNATION:
+	case PM_POST_RESTORE:
+		/*
+		 * Use workqueue so we do not have to care about running
+		 * concurrently with work triggered by the interrupt handler.
+		 */
+		queue_delayed_work(system_power_efficient_wq, &gpio->work, 0);
+		break;
+	}
+
+	return NOTIFY_DONE;
+}
+
 /**
  * snd_soc_jack_add_gpios - Associate GPIO pins with an ASoC jack
  *
@@ -369,6 +391,13 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
 					i, ret);
 		}
 
+		/*
+		 * Register PM notifier so we do not miss state transitions
+		 * happening while system is asleep.
+		 */
+		gpios[i].pm_notifier.notifier_call = snd_soc_jack_pm_notifier;
+		register_pm_notifier(&gpios[i].pm_notifier);
+
 		/* Expose GPIO value over sysfs for diagnostic purposes */
 		gpiod_export(gpios[i].desc, false);
 
@@ -428,6 +457,7 @@ void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
 
 	for (i = 0; i < count; i++) {
 		gpiod_unexport(gpios[i].desc);
+		unregister_pm_notifier(&gpios[i].pm_notifier);
 		free_irq(gpiod_to_irq(gpios[i].desc), &gpios[i]);
 		cancel_delayed_work_sync(&gpios[i].work);
 		gpiod_put(gpios[i].desc);
-- 
2.12.1.500.gab5fba24ee-goog


-- 
Dmitry

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

* Re: [PATCH] ASoC: jack - check status of GPIO-based pins on resume
  2017-03-21 23:50 [PATCH] ASoC: jack - check status of GPIO-based pins on resume Dmitry Torokhov
@ 2017-03-24 18:51 ` Mark Brown
  2017-03-24 19:22   ` Dmitry Torokhov
  2017-03-24 19:16 ` Applied "ASoC: jack - check status of GPIO-based pins on resume" to the asoc tree Mark Brown
  1 sibling, 1 reply; 7+ messages in thread
From: Mark Brown @ 2017-03-24 18:51 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Jaroslav Kysela, Liam Girdwood, Takashi Iwai, alsa-devel, linux-kernel

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

On Tue, Mar 21, 2017 at 04:50:43PM -0700, Dmitry Torokhov wrote:
> From: Dmitry Torokhov <dtor@chromium.org>
> 
> For GPIO-backed pins that are not configured as wakeup sources, we may
> miss change in their state that happens while system is suspended. Let's
> use PM notifier to refresh their state upon resume.
> 
> Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
> ---

Please send patches from the mail account corresponding to the signoff,
not doing that makes the patch look like it's missing a signoff (as it's
got the From line so more than one signoff is expected but there's only
one) which slows down review.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Applied "ASoC: jack - check status of GPIO-based pins on resume" to the asoc tree
  2017-03-21 23:50 [PATCH] ASoC: jack - check status of GPIO-based pins on resume Dmitry Torokhov
  2017-03-24 18:51 ` Mark Brown
@ 2017-03-24 19:16 ` Mark Brown
  1 sibling, 0 replies; 7+ messages in thread
From: Mark Brown @ 2017-03-24 19:16 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Mark Brown, Mark Brown, linux-kernel, alsa-devel, Takashi Iwai,
	Liam Girdwood, alsa-devel

The patch

   ASoC: jack - check status of GPIO-based pins on resume

has been applied to the asoc tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 73548dd316adec41172c31d63a0c35a97bf9577f Mon Sep 17 00:00:00 2001
From: Dmitry Torokhov <dtor@chromium.org>
Date: Tue, 21 Mar 2017 16:50:43 -0700
Subject: [PATCH] ASoC: jack - check status of GPIO-based pins on resume

For GPIO-backed pins that are not configured as wakeup sources, we may
miss change in their state that happens while system is suspended. Let's
use PM notifier to refresh their state upon resume.

Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 include/sound/soc.h  |  1 +
 sound/soc/soc-jack.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 2b502f6cc6d0..1d20abec4995 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -722,6 +722,7 @@ struct snd_soc_jack_gpio {
 	/* private: */
 	struct snd_soc_jack *jack;
 	struct delayed_work work;
+	struct notifier_block pm_notifier;
 	struct gpio_desc *desc;
 
 	void *data;
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index fbaa1bb41102..a03dcbb94baf 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -19,6 +19,7 @@
 #include <linux/workqueue.h>
 #include <linux/delay.h>
 #include <linux/export.h>
+#include <linux/suspend.h>
 #include <trace/events/asoc.h>
 
 /**
@@ -293,6 +294,27 @@ static void gpio_work(struct work_struct *work)
 	snd_soc_jack_gpio_detect(gpio);
 }
 
+static int snd_soc_jack_pm_notifier(struct notifier_block *nb,
+				    unsigned long action, void *data)
+{
+	struct snd_soc_jack_gpio *gpio =
+			container_of(nb, struct snd_soc_jack_gpio, pm_notifier);
+
+	switch (action) {
+	case PM_POST_SUSPEND:
+	case PM_POST_HIBERNATION:
+	case PM_POST_RESTORE:
+		/*
+		 * Use workqueue so we do not have to care about running
+		 * concurrently with work triggered by the interrupt handler.
+		 */
+		queue_delayed_work(system_power_efficient_wq, &gpio->work, 0);
+		break;
+	}
+
+	return NOTIFY_DONE;
+}
+
 /**
  * snd_soc_jack_add_gpios - Associate GPIO pins with an ASoC jack
  *
@@ -369,6 +391,13 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
 					i, ret);
 		}
 
+		/*
+		 * Register PM notifier so we do not miss state transitions
+		 * happening while system is asleep.
+		 */
+		gpios[i].pm_notifier.notifier_call = snd_soc_jack_pm_notifier;
+		register_pm_notifier(&gpios[i].pm_notifier);
+
 		/* Expose GPIO value over sysfs for diagnostic purposes */
 		gpiod_export(gpios[i].desc, false);
 
@@ -428,6 +457,7 @@ void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
 
 	for (i = 0; i < count; i++) {
 		gpiod_unexport(gpios[i].desc);
+		unregister_pm_notifier(&gpios[i].pm_notifier);
 		free_irq(gpiod_to_irq(gpios[i].desc), &gpios[i]);
 		cancel_delayed_work_sync(&gpios[i].work);
 		gpiod_put(gpios[i].desc);
-- 
2.11.0

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

* Re: [PATCH] ASoC: jack - check status of GPIO-based pins on resume
  2017-03-24 18:51 ` Mark Brown
@ 2017-03-24 19:22   ` Dmitry Torokhov
  2017-03-24 19:26     ` Mark Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2017-03-24 19:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: Jaroslav Kysela, Liam Girdwood, Takashi Iwai, alsa-devel, linux-kernel

On Fri, Mar 24, 2017 at 06:51:47PM +0000, Mark Brown wrote:
> On Tue, Mar 21, 2017 at 04:50:43PM -0700, Dmitry Torokhov wrote:
> > From: Dmitry Torokhov <dtor@chromium.org>
> > 
> > For GPIO-backed pins that are not configured as wakeup sources, we may
> > miss change in their state that happens while system is suspended. Let's
> > use PM notifier to refresh their state upon resume.
> > 
> > Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
> > ---
> 
> Please send patches from the mail account corresponding to the signoff,
> not doing that makes the patch look like it's missing a signoff (as it's
> got the From line so more than one signoff is expected but there's only
> one) which slows down review.

Resent from @chromium.

-- 
Dmitry

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

* Re: [PATCH] ASoC: jack - check status of GPIO-based pins on resume
  2017-03-24 19:22   ` Dmitry Torokhov
@ 2017-03-24 19:26     ` Mark Brown
  2017-03-24 19:28       ` Dmitry Torokhov
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2017-03-24 19:26 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Jaroslav Kysela, Liam Girdwood, Takashi Iwai, alsa-devel, linux-kernel

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

On Fri, Mar 24, 2017 at 12:22:09PM -0700, Dmitry Torokhov wrote:
> On Fri, Mar 24, 2017 at 06:51:47PM +0000, Mark Brown wrote:

> > Please send patches from the mail account corresponding to the signoff,
> > not doing that makes the patch look like it's missing a signoff (as it's
> > got the From line so more than one signoff is expected but there's only
> > one) which slows down review.

> Resent from @chromium.

Sorry, that was a note for future submissions - I'd already applied when
I sent.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] ASoC: jack - check status of GPIO-based pins on resume
  2017-03-24 19:26     ` Mark Brown
@ 2017-03-24 19:28       ` Dmitry Torokhov
  0 siblings, 0 replies; 7+ messages in thread
From: Dmitry Torokhov @ 2017-03-24 19:28 UTC (permalink / raw)
  To: Mark Brown
  Cc: Jaroslav Kysela, Liam Girdwood, Takashi Iwai, alsa-devel, linux-kernel

On Fri, Mar 24, 2017 at 07:26:29PM +0000, Mark Brown wrote:
> On Fri, Mar 24, 2017 at 12:22:09PM -0700, Dmitry Torokhov wrote:
> > On Fri, Mar 24, 2017 at 06:51:47PM +0000, Mark Brown wrote:
> 
> > > Please send patches from the mail account corresponding to the signoff,
> > > not doing that makes the patch look like it's missing a signoff (as it's
> > > got the From line so more than one signoff is expected but there's only
> > > one) which slows down review.
> 
> > Resent from @chromium.
> 
> Sorry, that was a note for future submissions - I'd already applied when
> I sent.

Ah, sorry, well, it was a test for my updated script then ;)

-- 
Dmitry

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

* [PATCH] ASoC: jack - check status of GPIO-based pins on resume
@ 2017-03-24 19:20 Dmitry Torokhov
  0 siblings, 0 replies; 7+ messages in thread
From: Dmitry Torokhov @ 2017-03-24 19:20 UTC (permalink / raw)
  To: Mark Brown
  Cc: Jaroslav Kysela, Liam Girdwood, Takashi Iwai, alsa-devel, linux-kernel

For GPIO-backed pins that are not configured as wakeup sources, we may
miss change in their state that happens while system is suspended. Let's
use PM notifier to refresh their state upon resume.

Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
---
 include/sound/soc.h  |  1 +
 sound/soc/soc-jack.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index b86168a21d56..c0b8bf463940 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -722,6 +722,7 @@ struct snd_soc_jack_gpio {
 	/* private: */
 	struct snd_soc_jack *jack;
 	struct delayed_work work;
+	struct notifier_block pm_notifier;
 	struct gpio_desc *desc;
 
 	void *data;
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index fbaa1bb41102..d90af94ec1be 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -19,6 +19,7 @@
 #include <linux/workqueue.h>
 #include <linux/delay.h>
 #include <linux/export.h>
+#include <linux/suspend.h>
 #include <trace/events/asoc.h>
 
 /**
@@ -293,6 +294,27 @@ static void gpio_work(struct work_struct *work)
 	snd_soc_jack_gpio_detect(gpio);
 }
 
+static int snd_soc_jack_pm_notifier(struct notifier_block *nb,
+				    unsigned long action, void *data)
+{
+	struct snd_soc_jack_gpio *gpio =
+			container_of(nb, struct snd_soc_jack_gpio, pm_notifier);
+
+	switch (action) {
+	case PM_POST_SUSPEND:
+	case PM_POST_HIBERNATION:
+	case PM_POST_RESTORE:
+		/*
+		 * Use workqueue so we do not have to care about running
+		 * concurrently with work triggered by interrupt handler.
+		 */
+		queue_delayed_work(system_power_efficient_wq, &gpio->work, 0);
+		break;
+	}
+
+	return NOTIFY_DONE;
+}
+
 /**
  * snd_soc_jack_add_gpios - Associate GPIO pins with an ASoC jack
  *
@@ -369,6 +391,13 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
 					i, ret);
 		}
 
+		/*
+		 * Register PM notifier so we do not miss state transitions
+		 * happening while system is asleep.
+		 */
+		gpios[i].pm_notifier.notifier_call = snd_soc_jack_pm_notifier;
+		register_pm_notifier(&gpios[i].pm_notifier);
+
 		/* Expose GPIO value over sysfs for diagnostic purposes */
 		gpiod_export(gpios[i].desc, false);
 
@@ -428,6 +457,7 @@ void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
 
 	for (i = 0; i < count; i++) {
 		gpiod_unexport(gpios[i].desc);
+		unregister_pm_notifier(&gpios[i].pm_notifier);
 		free_irq(gpiod_to_irq(gpios[i].desc), &gpios[i]);
 		cancel_delayed_work_sync(&gpios[i].work);
 		gpiod_put(gpios[i].desc);
-- 
2.12.1.578.ge9c3154ca4-goog


-- 
Dmitry

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

end of thread, other threads:[~2017-03-24 19:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-21 23:50 [PATCH] ASoC: jack - check status of GPIO-based pins on resume Dmitry Torokhov
2017-03-24 18:51 ` Mark Brown
2017-03-24 19:22   ` Dmitry Torokhov
2017-03-24 19:26     ` Mark Brown
2017-03-24 19:28       ` Dmitry Torokhov
2017-03-24 19:16 ` Applied "ASoC: jack - check status of GPIO-based pins on resume" to the asoc tree Mark Brown
2017-03-24 19:20 [PATCH] ASoC: jack - check status of GPIO-based pins on resume Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).