From patchwork Thu Sep 22 10:10:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Yushchenko X-Patchwork-Id: 9349807 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 08BC36077A for ; Sun, 25 Sep 2016 15:45:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED07128BE5 for ; Sun, 25 Sep 2016 15:45:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD5FF28C6E; Sun, 25 Sep 2016 15:45:38 +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_SIGNED, 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 0A0AD28BE5 for ; Sun, 25 Sep 2016 15:45:37 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 8AEA0266B50; Sun, 25 Sep 2016 17:45:36 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id AB1D626155E; Sun, 25 Sep 2016 17:43:17 +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 9B6BC2670C1; Thu, 22 Sep 2016 12:11:09 +0200 (CEST) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by alsa0.perex.cz (Postfix) with ESMTP id 500B5266BF8 for ; Thu, 22 Sep 2016 12:11:03 +0200 (CEST) Received: by mail-lf0-f49.google.com with SMTP id g62so62821785lfe.3 for ; Thu, 22 Sep 2016 03:11:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=T7Iwkq7Y5wCMU8bWb8gwkrMyCPV6Why9pRrj3NarjdQ=; b=qpsW5S5S2VLs23gAP3sDhU8gHbTBzV+tCtJEp536cWba/tSdvFLzo8I32Y+pudkxm+ 6TfaPTx1jrfWokGXuRYWbKMxCwKhNjcQ44YSGerJI+JHt13m39efU8NoU/nzK1h6Z36s iW14yjnB9TySYZm/CJ4B61rtuqFCgX5ZSRV+EZbTkGb39+MkiXOaNxujJFLLFpdZjlzL UhUXtfnXh5LKkT9YQ2ejGxji3hEC6qIy95JE5oCwwHyaUCHUlkKRoaaX+R1PUNJ0Qe0I 8UEIuZqKBZbZJPEiIzecuSVB2pg3mSb6imJdZ/blp86xBIB72G/eRxfDEAqmKHtWkCHh oeMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=T7Iwkq7Y5wCMU8bWb8gwkrMyCPV6Why9pRrj3NarjdQ=; b=Zn3g61zcJFK8J9Os0LIga/8Ehvsm4KB7G6t+YbIQ55BiV9MqFIRgbFG0ys0UHlm3Zo 2tQ3jVcsAE1g1NhJHnxg/MDqTjqFnFuylZet7+mYL1ylDSIeVJHoDUM1u7wuVP9ZGyI+ gpHeUSvhDemvo1x0sthI6ca7f1noQKJ3/VsWoJ4V+38+OAO4K7KL5/gZBllC/1KExJCK yyycinyEVT+SsTl14EkyczZF9vQBGE/FgHr3TP9+EyDTKk4QISeWmEDqde1/zhXpOaGd NpO7nuCoxvvMd8A1KHJ8auvpepRIjOsugbJX4Gmxsqy0RyL16exhKCXJ4n85HynudUse zgCQ== X-Gm-Message-State: AE9vXwNL0H8G3ZKIZRA5eY8DuowjeUCpUnk9r1/ymwGmjGeeZUarHPuvVOR2ECd6hkyuPQ== X-Received: by 10.25.217.146 with SMTP id s18mr424640lfi.46.1474539063324; Thu, 22 Sep 2016 03:11:03 -0700 (PDT) Received: from hugenb.home (nikaet.starlink.ru. [94.141.168.29]) by smtp.gmail.com with ESMTPSA id c125sm221931lfe.10.2016.09.22.03.11.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Sep 2016 03:11:02 -0700 (PDT) From: Nikita Yushchenko To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Helen Koike , Lars-Peter Clausen , Sebastian Reichel , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Date: Thu, 22 Sep 2016 13:10:40 +0300 Message-Id: <1474539040-25347-1-git-send-email-nikita.yoush@cogentembedded.com> X-Mailer: git-send-email 2.1.4 X-Mailman-Approved-At: Sun, 25 Sep 2016 09:54:12 +0200 Cc: Nikita Yushchenko , Chris Healy Subject: [alsa-devel] [PATCH] ASoC: tpa6130a2: fix volume setting when no stream is running 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP After moving tpa6130a2 power management to DAPM, if chip can be physically powered off (either reset_gpio is defined, or regulator indeed removes power), then volume change no longer works unless chip is on due to a running stream. Fix that by entering regcache cache_only mode while chip is off. Move regcache calls to tpa6130a2_power() to get them at driver init time as well. Signed-off-by: Nikita Yushchenko --- sound/soc/codecs/tpa6130a2.c | 49 +++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c index f1ea052..3b6faed 100644 --- a/sound/soc/codecs/tpa6130a2.c +++ b/sound/soc/codecs/tpa6130a2.c @@ -52,7 +52,7 @@ struct tpa6130a2_data { static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable) { - int ret; + int ret = 0, ret2; if (enable) { ret = regulator_enable(data->supply); @@ -64,20 +64,34 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable) /* Power on */ if (data->power_gpio >= 0) gpio_set_value(data->power_gpio, 1); + + /* Sync registers */ + regcache_cache_only(data->regmap, false); + ret = regcache_sync(data->regmap); + if (ret != 0) { + dev_err(data->dev, + "Failed to sync registers: %d\n", ret); + goto regcache_sync_failed; + } } else { + /* Powered off device does not retain registers. While device + * is off, any register updates (i.e. volume changes) should + * happen in cache only. + */ + regcache_mark_dirty(data->regmap); +regcache_sync_failed: + regcache_cache_only(data->regmap, true); + /* Power off */ if (data->power_gpio >= 0) gpio_set_value(data->power_gpio, 0); - ret = regulator_disable(data->supply); - if (ret != 0) { + ret2 = regulator_disable(data->supply); + if (ret2 != 0) { dev_err(data->dev, - "Failed to disable supply: %d\n", ret); - return ret; + "Failed to disable supply: %d\n", ret2); + return ret ? ret : ret2; } - - /* device regs does not match the cache state anymore */ - regcache_mark_dirty(data->regmap); } return ret; @@ -88,25 +102,14 @@ static int tpa6130a2_power_event(struct snd_soc_dapm_widget *w, { struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm); struct tpa6130a2_data *data = snd_soc_component_get_drvdata(c); - int ret; - /* before widget power up */ if (SND_SOC_DAPM_EVENT_ON(event)) { - /* Turn on the chip */ - tpa6130a2_power(data, true); - /* Sync the registers */ - ret = regcache_sync(data->regmap); - if (ret < 0) { - dev_err(c->dev, "Failed to initialize chip\n"); - tpa6130a2_power(data, false); - return ret; - } - /* after widget power down */ + /* Before widget power up: turn chip on, sync registers */ + return tpa6130a2_power(data, true); } else { - tpa6130a2_power(data, false); + /* After widget power down: turn chip off */ + return tpa6130a2_power(data, false); } - - return 0; } /*