From patchwork Tue Mar 21 23:50:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9637849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C75D2601E9 for ; Wed, 22 Mar 2017 00:00:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9E9E23201 for ; Wed, 22 Mar 2017 00:00:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE18D28306; Wed, 22 Mar 2017 00:00:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D09A123201 for ; Wed, 22 Mar 2017 00:00:55 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 85A9F2671FF; Wed, 22 Mar 2017 00:50:54 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id E5BA126720A; Wed, 22 Mar 2017 00:50:52 +0100 (CET) Received: from mail-pg0-f68.google.com (mail-pg0-f68.google.com [74.125.83.68]) by alsa0.perex.cz (Postfix) with ESMTP id 182142671FB for ; Wed, 22 Mar 2017 00:50:46 +0100 (CET) Received: by mail-pg0-f68.google.com with SMTP id w20so2636818pgc.1 for ; Tue, 21 Mar 2017 16:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=qMdSSzxhoFXsh5Nj/z2TUOtanEUVi084G0w1XdLsk44=; b=fCf48i9I2KVC2C5wa0ggt9iap3m6eTvlULDanJj0nLeDGgroFNqkk5BpZOnXgQNzpe rCcR9LnTDg0inPqhxy4dylq071qw3lTyiVHgzbQ0L8uBbLN3n3t9KqgJfh5By3s+u+Lm LHMFl7WE/lTcyWpXCKoCf8+YWNAX//DSoMT1TVo/uu5QG8f1TIuZDQPJp9PNRtD5Jhsl BgygAcHtpFqR3r2oftllWF0pC7Ew8DoL9fVqvm8jXe77P95FFjps+is5YB75QLpjd9Ar Da+mo2hIjrnjLh15I9RsPLooqP5qF9NIKEd2KR5qk2FysSh6wxugrnAY05fkmLOxuCoz QGkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=qMdSSzxhoFXsh5Nj/z2TUOtanEUVi084G0w1XdLsk44=; b=Tb/MRoQrYjyRauBV3Le4QAX2ttlVL0zavy5npI+VqHCwTRPoMoGlWpbulPh4PLak5M nrE/npRAsB/CJl0LptLxqh02i/k5A6xCIKc+sFH/ckp2bW4HB+3fB2keNv5zNT0RuDeV nJ2GDlNEfq53n+d+55cvy2YSPelXh8tD4fcC5n4D/enDhZMie05KiUqeQW20CW33NOQ0 UtYT1jEPQOXVOB/b7hRGqAhumASZfw3vW3N86IyQKlnAwrWxOudSB6yXknWBuEHZ1Vky yFbbkyTi5FfWmXEDqGezqi6NClBKEwrSwrcySqp1Okh5l892JEYGySguUOs/Uq/2Cbwk BXcg== X-Gm-Message-State: AFeK/H0PROw7U7daXa1FXx/2+Nmje2N9/RK4/H0Bfe3RizKaOssj3/ciLsCV1aybLZU9+Q== X-Received: by 10.98.82.216 with SMTP id g207mr42665980pfb.139.1490140246058; Tue, 21 Mar 2017 16:50:46 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1311:c16b:6044:29b2:a709]) by smtp.gmail.com with ESMTPSA id t12sm41624169pfg.14.2017.03.21.16.50.45 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 21 Mar 2017 16:50:45 -0700 (PDT) Date: Tue, 21 Mar 2017 16:50:43 -0700 From: Dmitry Torokhov To: Mark Brown Message-ID: <20170321235043.GA9831@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Takashi Iwai , Liam Girdwood Subject: [alsa-devel] [PATCH] ASoC: jack - check status of GPIO-based pins on resume X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Torokhov 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 --- 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 #include #include +#include #include /** @@ -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);