From patchwork Fri Mar 24 19:20:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9645401 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 8D72F602BF for ; Mon, 27 Mar 2017 07:07:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E1CE2832D for ; Mon, 27 Mar 2017 07:07:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7032628356; Mon, 27 Mar 2017 07:07:59 +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.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=unavailable 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 4672E2832D for ; Mon, 27 Mar 2017 07:07:57 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id AFF6E2664EB; Mon, 27 Mar 2017 09:07:55 +0200 (CEST) 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 933A226754A; Fri, 24 Mar 2017 20:21:59 +0100 (CET) Received: from mail-pf0-f181.google.com (mail-pf0-f181.google.com [209.85.192.181]) by alsa0.perex.cz (Postfix) with ESMTP id 58A39267550 for ; Fri, 24 Mar 2017 20:20:28 +0100 (CET) Received: by mail-pf0-f181.google.com with SMTP id o126so4801237pfb.3 for ; Fri, 24 Mar 2017 12:20:28 -0700 (PDT) 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=OGVksCSYa2rmFg6Xuv5W8pV3hKKk0RVKvTTgv7xoQWE=; b=CMauDoRs/qS3MNPFmBUucsvUDYdATu97862XzWrLR08ofIZDudk44Op/MdJ+HpjOzG lmlSGyOoEE5P/r4dclXltKSwRwL2a9zDXz0/pQhVvwUoUZg+bw+V4DzErRJDENC1AVlE i19HgJgsxwJDfr+tnek0j+VCFygrEBDN9eRBwTBYku4NsYcA7TqdBjwtFRN5zN5hRUn/ vq3NwXWZ1iWdJaRm9j03uUEE00+IcNWAaUVDGlitLfL7/6TvHjIlkS9cltiKbPfss/Zr /taEhGnR48r94zgoCcbOF9jUFefYqLA62E266G1IERtYvOV73CKvmqzoKj/rFygWoGjh WcOw== X-Gm-Message-State: AFeK/H3xTWDzQxE0theEUV+m9/CbS9vyd7oe/8DXwpEf0zPeMhn+ELUKKBEXFDK4DuL5hKji X-Received: by 10.84.217.2 with SMTP id o2mr12990114pli.51.1490383227179; Fri, 24 Mar 2017 12:20:27 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1311:a5d8:4e25:3282:18d4]) by smtp.gmail.com with ESMTPSA id x65sm6154382pfb.111.2017.03.24.12.20.26 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 24 Mar 2017 12:20:26 -0700 (PDT) Date: Fri, 24 Mar 2017 12:20:24 -0700 From: Dmitry Torokhov To: Mark Brown Message-ID: <20170324192024.GA13029@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Mailman-Approved-At: Mon, 27 Mar 2017 09:07:53 +0200 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 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 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);