From patchwork Sat Mar 10 02:37:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 131281 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1698125lja; Fri, 9 Mar 2018 18:39:48 -0800 (PST) X-Google-Smtp-Source: AG47ELvY8OG1NswYglVf+MFIj1J3jj3eG3Bx6FLx9QFAzMMi3lbOtyg/6Vie6EQezYUoJyF1tMGX X-Received: by 10.28.106.19 with SMTP id f19mr90951wmc.84.1520649587962; Fri, 09 Mar 2018 18:39:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520649587; cv=none; d=google.com; s=arc-20160816; b=jGKWR2PtmXHQHc81ij1gsGKC8KXrQ6DG0sO7tuRZG13BC/IVcli2jYVnqCtkn4lv9M eSG77nwtC2tSpmuQUC06yPjPrqGvrzNIbcCHInjg/GgLzYq8K1Ma7qt5V2cMytx2w+Mo 8JA9jYrbxCExcqbjJ2l+tSogtC2FA56mS0jvkpwb5/oo6ZOCtNRy1Wu6eTWXwdNHWzBP YblNXwsbZUmodFX6UXCRtqybM5oMyCbMGTtAOd0DL5JZTFhXtiDnE0jntteXbetpHQlF e1sUxtrHWdoz39VyV43mUVKiM+jqIHwxzjI+UtDRgusNnU+eBu4Rjn5s4oEFsbJJ9/RA rR3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=Kozae3Sji7S/jVPUOdsAf2saisq1pSf9n3JABVzeppM=; b=mwxqf0Cb8h4EZY0GQqG/XfA/ZMvAs2jeUxFSGS0P8gJzO0mWj4Qx1HNVPXeEmKEHXQ Raozr82CSx6xrhrqkJTPwzK5Bex8xQ82BdoWujLt1SMSTgo7eCkFd+fLMbZzV0RUSlM9 O7uqCSlKjXUappmr/4y8aIEQ3BW4+LRNZ5sZ2YkY7MoW8wniF1Q/mXuVO3jp+jLj76WB k/f5O5IGYuHXb7C0tD93hNTvYiBVcDqfLO5UOj8q3JsSvk+a1TemLVTXn3VizRW0OGdt /1MILVSoKgMja2zaYXpKjc5SlVfhFFgRCYy5yT3/bpt0pZFPLu+mW42XmIAM1haXXYKA vUeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FfUXkps8; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id z70si1706056wrb.532.2018.03.09.18.39.47; Fri, 09 Mar 2018 18:39:47 -0800 (PST) Received-SPF: pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) client-ip=77.48.224.243; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FfUXkps8; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 59D93267661; Sat, 10 Mar 2018 03:39:46 +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 EDB25267665; Sat, 10 Mar 2018 03:39:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS autolearn=disabled version=3.4.0 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by alsa0.perex.cz (Postfix) with ESMTP id BFED426765C for ; Sat, 10 Mar 2018 03:39:41 +0100 (CET) Received: by mail-wm0-f65.google.com with SMTP id z81so7062252wmb.4 for ; Fri, 09 Mar 2018 18:39:41 -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=xuaHIcsMO/ur/uUnJG1ElWtmtziXYzycJ09RDV8XetM=; b=FfUXkps80yd3oFWvaFQ1PwEq/Nf37h8iENQmZEsgiWzYzFFu/v7wP8JOuJiWlMqqcx CdfpkvYTSQQuGAIGV4qWtuOeTvsmxndC3EbCQ+sredJnYjaIXvZ+nmq+lod6Fx6tMD/h KMAV7OF2ulJ5fLkyUQZvyIBrkz/wQMvk9ER9c= 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=xuaHIcsMO/ur/uUnJG1ElWtmtziXYzycJ09RDV8XetM=; b=afGr7DiGZeuPpf9YgJn4s4pwxve544QpbbOryA0LvqYw6bM8h++qmYKgJgffEbIBez GapcoZqrpu5wHygXQ/mu5U91M4c65pHgRKgvLFxrG3cS7/YF9GM6c2P+0xtyHwCIZQPn 1DmozW7exzGA/ziFYbzii9v8rPI0dqIy0ColArGpnF5vJI731VxI6ECXeM6zfOohZrhD Qd0y13qtz6vtz6sL0aoRk4vnOqJS995g6NUzfXpCvT5/qLdgKFqqBU3FK/Q8zikUUn7v qVpzD/UPykVgWDRz6LrSUP0hSai1ntaSZg/GaqN+Ghi6eqOpo62jHaMYcNAHj5GjVVCB dSmw== X-Gm-Message-State: AElRT7H9ehAdgckH/4QXAoZtEqXwRhVY427ZqNWD5/K8VcilbKGuLb0A P5i9RUTMyx6cG0CtVGq6oHe9Vg== X-Received: by 10.28.170.5 with SMTP id t5mr79606wme.116.1520649581377; Fri, 09 Mar 2018 18:39:41 -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 d17sm2976373wrc.69.2018.03.09.18.39.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Mar 2018 18:39:40 -0800 (PST) From: srinivas.kandagatla@linaro.org To: Mark Brown , Liam Girdwood , Takashi Iwai Date: Sat, 10 Mar 2018 02:37:27 +0000 Message-Id: <20180310023727.27077-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] [PATCH v2] 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 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. Signed-off-by: Srinivas Kandagatla --- Changes since v1: - removed synchronize with the DAPM async queue include/sound/soc-dapm.h | 16 ++++++++++++++++ sound/soc/soc-dapm.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) -- 2.15.1 _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel 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..ac4f13230faf 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,31 @@ 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; + + 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 +1928,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 +2342,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 +3492,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 +3582,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;