From patchwork Mon Mar 5 12:32:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 10258849 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 7846C60365 for ; Mon, 5 Mar 2018 12:34:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65E83289FF for ; Mon, 5 Mar 2018 12:34:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 592B428A0B; Mon, 5 Mar 2018 12:34:30 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,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 3B721289FF for ; Mon, 5 Mar 2018 12:34:28 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id EDDE72670F9; Mon, 5 Mar 2018 13:34:26 +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 2B4C42671D2; Mon, 5 Mar 2018 13:34:23 +0100 (CET) Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by alsa0.perex.cz (Postfix) with ESMTP id B7B7C266F68 for ; Mon, 5 Mar 2018 13:34:19 +0100 (CET) Received: by mail-wr0-f194.google.com with SMTP id v111so17071008wrb.3 for ; Mon, 05 Mar 2018 04:34:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=42jOa4efiGbeEFQ7rQXtrXcDiBzNC9QAHlkRC4sgMqo=; b=MRdDG/vlQ/WBxhIbmkt3G2TJJ1Nbdpwc2TC3CctqjLy38bIwlDi5wh/G6mXN5HhCFC WUBpwCxSzlRWavZT15E5B9spSqWcvOZf/1sFAnX4i9dABa1IVuRVyL0nisUZkT4nMjQi prEBqb1VCJNYxWO/nh5cZF8cEqo9Lnt9G5yMk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=42jOa4efiGbeEFQ7rQXtrXcDiBzNC9QAHlkRC4sgMqo=; b=tMJQKr6yEe5Ae+1C9++P77Ff4XenY3BjDNWk/eq6dA2G/fn22GSEjPKQ0DlDYYq4Nr xMtXUjTGMYo5uOHS8Upjhaz//It3kfLk+ZO75DC4qNij359G6wVaVogb3lxuvjNa3pDl +nRwaZ25zt+nAkzzA23IYeKPnb0RNaEgkFH2LYHKtPaB2UxVdW6FG7Ja11ZICeMeph7n wkZu0ylxUfZc0hiBJIz3t1sR10DwbsDvbi8XgJ+6f83H/08O49uc61jWuxCc7+nTNvqK yOBKI1tCo4jkOnupZuyrW8qls6XDryF7/gjWEZprhy0tJzo5aRRcvVZZu3OLXsxGaQou hcuw== X-Gm-Message-State: APf1xPBSHCZTrRwqn4oRvsChGOG5MdPKyVGzPxJHUC2FMDw+rbcia8Af DUmRNZ85DS/rpKAyma5bBrhVEw== X-Google-Smtp-Source: AG47ELsiROYT8FuhgHyH790JIVqPy4O6Bt3nL3ECfUaT8fHHAFMVlliDJaQNsfAE8V9/XBubotwipg== X-Received: by 10.223.168.46 with SMTP id l43mr13503242wrc.118.1520253258942; Mon, 05 Mar 2018 04:34:18 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id o12sm20486080wrb.15.2018.03.05.04.34.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Mar 2018 04:34:18 -0800 (PST) From: srinivas.kandagatla@linaro.org To: Mark Brown , Liam Girdwood , Takashi Iwai Date: Mon, 5 Mar 2018 12:32:13 +0000 Message-Id: <20180305123213.2045-1-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.1 Cc: alsa-devel@alsa-project.org, Srinivas Kandagatla , linux-kernel@vger.kernel.org Subject: [alsa-devel] [RFC PATCH] ASoC: dapm: add support to pinctrl dapm 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 From: Srinivas Kandagatla Purpose of having pinctrl dapm is to dynamically put the pins in low power state when they are not actively used by the audio and saving power. Without this each driver has to set the pinctrl states, either during probe or dynamically depending on the callbacks received from ASoC core. This patch adds a single macro SND_SOC_DAPM_PINCTRL which takes, widget, active and sleep state names, and the dapm would use active and sleep state pinctrl names to put the pins in active and sleep state respectively. Signed-off-by: Srinivas Kandagatla --- Hi All, Purpose of this patch is to discuss the idea of having pinctrl part of dapm. As an example on Qualcomm SoCs there are multiple I2S Interfaces, each of these interfaces have there own pinctrls setting, It does not make sense for the machine/platform/componet driver to put them in default/active state durning probe/init as it would waste power. If we make these pinctrl part of the dapm sequence, these would only become active when the stream is active which would save power. This patch adds a single macro SND_SOC_DAPM_PINCTRL which takes, widget, active and sleep state names, and the dapm would use active and sleep state pinctrl names to put the pins in active and sleep state respectively. Thanks, Srini include/sound/soc-dapm.h | 16 ++++++++++++++++ sound/soc/soc-dapm.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 344b96c206a3..a6ce2de4e20a 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -269,6 +269,13 @@ struct device; .reg = SND_SOC_NOPM, .shift = wdelay, .event = dapm_regulator_event, \ .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD, \ .on_val = wflags} +#define SND_SOC_DAPM_PINCTRL(wname, active, sleep) \ +{ .id = snd_soc_dapm_pinctrl, .name = wname, \ + .priv = (&(struct snd_soc_dapm_pinctrl_priv) \ + { .active_state = active, .sleep_state = sleep,}), \ + .reg = SND_SOC_NOPM, .event = dapm_pinctrl_event, \ + .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD } + /* dapm kcontrol types */ @@ -374,6 +381,8 @@ int dapm_regulator_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event); int dapm_clock_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event); +int dapm_pinctrl_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event); /* dapm controls */ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, @@ -500,6 +509,7 @@ enum snd_soc_dapm_type { snd_soc_dapm_pre, /* machine specific pre widget - exec first */ snd_soc_dapm_post, /* machine specific post widget - exec last */ snd_soc_dapm_supply, /* power/clock supply */ + snd_soc_dapm_pinctrl, /* pinctrl */ snd_soc_dapm_regulator_supply, /* external regulator */ snd_soc_dapm_clock_supply, /* external clock */ snd_soc_dapm_aif_in, /* audio interface input */ @@ -581,6 +591,7 @@ struct snd_soc_dapm_widget { void *priv; /* widget specific data */ struct regulator *regulator; /* attached regulator */ + struct pinctrl *pinctrl; /* attached pinctrl */ const struct snd_soc_pcm_stream *params; /* params for dai links */ unsigned int num_params; /* number of params for dai links */ unsigned int params_select; /* currently selected param for dai link */ @@ -683,6 +694,11 @@ struct snd_soc_dapm_stats { int neighbour_checks; }; +struct snd_soc_dapm_pinctrl_priv { + const char *active_state; + const char *sleep_state; +}; + /** * snd_soc_dapm_init_bias_level() - Initialize DAPM bias level * @dapm: The DAPM context to initialize diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 40085a4c8f92..babff1cd2849 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,7 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, static int dapm_up_seq[] = { [snd_soc_dapm_pre] = 0, [snd_soc_dapm_regulator_supply] = 1, + [snd_soc_dapm_pinctrl] = 1, [snd_soc_dapm_clock_supply] = 1, [snd_soc_dapm_supply] = 2, [snd_soc_dapm_micbias] = 3, @@ -119,6 +121,7 @@ static int dapm_down_seq[] = { [snd_soc_dapm_dai_link] = 11, [snd_soc_dapm_supply] = 12, [snd_soc_dapm_clock_supply] = 13, + [snd_soc_dapm_pinctrl] = 13, [snd_soc_dapm_regulator_supply] = 13, [snd_soc_dapm_post] = 14, }; @@ -1287,6 +1290,33 @@ int dapm_regulator_event(struct snd_soc_dapm_widget *w, } EXPORT_SYMBOL_GPL(dapm_regulator_event); +/* + * Handler for pinctrl widget. + */ +int dapm_pinctrl_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_dapm_pinctrl_priv *priv = w->priv; + struct pinctrl *p = w->pinctrl; + struct pinctrl_state *s; + + if (!p || !priv) + return -EIO; + + soc_dapm_async_complete(w->dapm); + + if (SND_SOC_DAPM_EVENT_ON(event)) + s = pinctrl_lookup_state(p, priv->active_state); + else + s = pinctrl_lookup_state(p, priv->sleep_state); + + if (IS_ERR(s)) + return PTR_ERR(s); + + return pinctrl_select_state(p, s); +} +EXPORT_SYMBOL_GPL(dapm_pinctrl_event); + /* * Handler for clock supply widget. */ @@ -1900,6 +1930,7 @@ static int dapm_power_widgets(struct snd_soc_card *card, int event) break; case snd_soc_dapm_supply: case snd_soc_dapm_regulator_supply: + case snd_soc_dapm_pinctrl: case snd_soc_dapm_clock_supply: case snd_soc_dapm_micbias: if (d->target_bias_level < SND_SOC_BIAS_STANDBY) @@ -2313,6 +2344,7 @@ static ssize_t dapm_widget_show_component(struct snd_soc_component *cmpnt, case snd_soc_dapm_mixer_named_ctl: case snd_soc_dapm_supply: case snd_soc_dapm_regulator_supply: + case snd_soc_dapm_pinctrl: case snd_soc_dapm_clock_supply: if (w->name) count += sprintf(buf + count, "%s: %s\n", @@ -3462,6 +3494,17 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, w->name, ret); } break; + case snd_soc_dapm_pinctrl: + w->pinctrl = devm_pinctrl_get(dapm->dev); + if (IS_ERR_OR_NULL(w->pinctrl)) { + ret = PTR_ERR(w->pinctrl); + if (ret == -EPROBE_DEFER) + return ERR_PTR(ret); + dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n", + w->name, ret); + return NULL; + } + break; case snd_soc_dapm_clock_supply: #ifdef CONFIG_CLKDEV_LOOKUP w->clk = devm_clk_get(dapm->dev, w->name); @@ -3541,6 +3584,7 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, break; case snd_soc_dapm_supply: case snd_soc_dapm_regulator_supply: + case snd_soc_dapm_pinctrl: case snd_soc_dapm_clock_supply: case snd_soc_dapm_kcontrol: w->is_supply = 1;