From patchwork Fri Apr 26 02:25:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 10918055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 551B5933 for ; Fri, 26 Apr 2019 04:53:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 436EF289B1 for ; Fri, 26 Apr 2019 04:53:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3787128D7F; Fri, 26 Apr 2019 04:53:25 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 29E68289B1 for ; Fri, 26 Apr 2019 04:53:23 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id C5921853; Fri, 26 Apr 2019 04:26:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C5921853 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1556245619; bh=4mQCznt02YYsHGnF+4AUTmwob6dvvcCKyfIEoLZSdKM=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=j/kbHFyjx8UeKmx1Lf8VpFxKxDrrJ6QKF6jKpZob7fwW4nV9smzSw5f/wmXGOe6OW Wrphir5xn20Hmt06qx7K8TUyfwXVha7jOaHp7aiauOF8oNZLOmiX1IF9+XVRajDjab f0WfdBYXpucbPWqR7AQB7nyGVhWCB1Wjy2ARZNUc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3154FF896CC; Fri, 26 Apr 2019 04:26:09 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id AFDA2F896E0; Fri, 26 Apr 2019 04:26:06 +0200 (CEST) Received: from crapouillou.net (outils.crapouillou.net [89.234.176.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 7D17EF8961C for ; Fri, 26 Apr 2019 04:26:03 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 7D17EF8961C Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="WuQV9dkG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1556245560; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=XpPFglC39Lepd2C8rXS0wGjtZOwr35DRBGQT+aRjR8o=; b=WuQV9dkGg1BIOQqYR3H699slUZkovPSu8EtmvmKnRlS2lIPsBC3EM2y/jUzF+zKpaNleaj v3N2iDTun0r4+TaH3rUKgfMWZircsJ9n2CYZGsubp8vUIGQauuB/OBJV9Qqv+VDjxWgkbK FF383Q4Mhnu1o6BYAfOwN9Y+lyweYpM= From: Paul Cercueil To: Mark Brown , Liam Girdwood Date: Fri, 26 Apr 2019 04:25:49 +0200 Message-Id: <20190426022550.31359-1-paul@crapouillou.net> MIME-Version: 1.0 Cc: Paul Cercueil , alsa-devel@alsa-project.org, od@zcrc.me, linux-kernel@vger.kernel.org, Kuninori Morimoto Subject: [alsa-devel] [PATCH v2 1/2] ASoC: simple-card-utils: add asoc_simple_parse_pin_switches() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" X-Virus-Scanned: ClamAV using ClamSMTP This function is a helper that permits to create pin switch controls for a list of widgets whose names are listed in the PREFIX "pin-switches" devicetree property. Signed-off-by: Paul Cercueil --- Notes: v2: - Rebase on top of for-next - Rename to asoc_simple_parse_pin_switches() include/sound/simple_card_utils.h | 2 + sound/soc/generic/simple-card-utils.c | 57 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h index 67dc3ee6ed01..3429888347e7 100644 --- a/include/sound/simple_card_utils.h +++ b/include/sound/simple_card_utils.h @@ -133,6 +133,8 @@ int asoc_simple_parse_routing(struct snd_soc_card *card, char *prefix); int asoc_simple_parse_widgets(struct snd_soc_card *card, char *prefix); +int asoc_simple_parse_pin_switches(struct snd_soc_card *card, + char *prefix); int asoc_simple_init_jack(struct snd_soc_card *card, struct asoc_simple_jack *sjack, diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c index db1458a19985..f4c6375d11c7 100644 --- a/sound/soc/generic/simple-card-utils.c +++ b/sound/soc/generic/simple-card-utils.c @@ -430,6 +430,63 @@ int asoc_simple_parse_widgets(struct snd_soc_card *card, } EXPORT_SYMBOL_GPL(asoc_simple_parse_widgets); +int asoc_simple_parse_pin_switches(struct snd_soc_card *card, + char *prefix) +{ + const unsigned int nb_controls_max = 16; + const char **strings, *control_name; + struct snd_kcontrol_new *controls; + struct device *dev = card->dev; + unsigned int i, nb_controls; + char prop[128]; + int ret; + + if (!prefix) + prefix = ""; + + snprintf(prop, sizeof(prop), "%s%s", prefix, "pin-switches"); + + if (!of_property_read_bool(dev->of_node, prop)) + return 0; + + strings = devm_kcalloc(dev, nb_controls_max, + sizeof(*strings), GFP_KERNEL); + if (!strings) + return -ENOMEM; + + ret = of_property_read_string_array(dev->of_node, prop, + strings, nb_controls_max); + if (ret < 0) + return ret; + + nb_controls = (unsigned int)ret; + + controls = devm_kcalloc(dev, nb_controls, + sizeof(*controls), GFP_KERNEL); + if (!controls) + return -ENOMEM; + + for (i = 0; i < nb_controls; i++) { + control_name = devm_kasprintf(dev, GFP_KERNEL, + "%s Switch", strings[i]); + if (!control_name) + return -ENOMEM; + + controls[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; + controls[i].name = control_name; + controls[i].info = snd_soc_dapm_info_pin_switch; + controls[i].get = snd_soc_dapm_get_pin_switch; + controls[i].put = snd_soc_dapm_put_pin_switch; + controls[i].private_value = (unsigned long)strings[i]; + } + + card->controls = controls; + card->num_controls = nb_controls; + + return 0; +} +EXPORT_SYMBOL_GPL(asoc_simple_parse_pin_switches); + int asoc_simple_init_jack(struct snd_soc_card *card, struct asoc_simple_jack *sjack, int is_hp, char *prefix) From patchwork Fri Apr 26 02:25:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 10918001 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83BFD912 for ; Fri, 26 Apr 2019 03:23:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71C7328D82 for ; Fri, 26 Apr 2019 03:23:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 660ED28D87; Fri, 26 Apr 2019 03:23:21 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 91ACB28D82 for ; Fri, 26 Apr 2019 03:23:20 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id CD6D8867; Fri, 26 Apr 2019 04:27:05 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz CD6D8867 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1556245675; bh=gMOsF+/v8/pIjE1gBRExnKNYQxDNf1whvlsBRieHcAs=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=cM3/sP21k6Hd6N33xdwiTSH+HH0zRnzjOcQX89O/BimgQCYVWKVUvzHr9+WRoPQyE XjielN8mYsMPpnrQPj38p/+XToOohqY2TDyhrjr8qQl9QyZH5/iPdMExEAv2+5oFsO A8FK3YIQfWrn/iQ1SWJ4gNLdnfWm961Y0jIFNWiQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 1C893F89703; Fri, 26 Apr 2019 04:26:11 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3C828F896DF; Fri, 26 Apr 2019 04:26:07 +0200 (CEST) Received: from crapouillou.net (outils.crapouillou.net [89.234.176.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 2180DF896CC for ; Fri, 26 Apr 2019 04:26:03 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2180DF896CC Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="OyvOvzrp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1556245563; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o9aYnbBBsG31bu06WPoCmxnU2t+15WTo2eoyBq5LG9I=; b=OyvOvzrpfHxh8GZ2KmKTM1H0N1hi8tw3nYnoi6v61UMPcPwQFa3mJWb83E/hXxsXnJWqkl p0W1QC9wC4+HEuWTm79MDoBlQ/3MTTGohKQWxDY8bdNHeGRcQQVPQUiVKbErvmyYdAB/xA Z6oYoNZm4X0d8XxtPfekXYjuw+tG7jg= From: Paul Cercueil To: Mark Brown , Liam Girdwood Date: Fri, 26 Apr 2019 04:25:50 +0200 Message-Id: <20190426022550.31359-2-paul@crapouillou.net> In-Reply-To: <20190426022550.31359-1-paul@crapouillou.net> References: <20190426022550.31359-1-paul@crapouillou.net> MIME-Version: 1.0 Cc: Paul Cercueil , alsa-devel@alsa-project.org, od@zcrc.me, linux-kernel@vger.kernel.org, Kuninori Morimoto Subject: [alsa-devel] [PATCH v2 2/2] ASoC: simple-card: Read pin switches conf from devicetree X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" X-Virus-Scanned: ClamAV using ClamSMTP When the routing path between a widget (e.g. "Speaker") and the codec goes through an external amplifier, having a pin switch for this widget allows the amplifier to be disabled when the widget is not to be used (e.g. when using headphones). Signed-off-by: Paul Cercueil --- Notes: v2: - Rebase on top of for-next - Rename to asoc_simple_parse_pin_switches() sound/soc/generic/simple-card.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 335ead0cbb8a..9b568f578bcd 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -464,6 +464,10 @@ static int simple_parse_of(struct asoc_simple_priv *priv) if (ret < 0) return ret; + ret = asoc_simple_parse_pin_switches(card, PREFIX); + if (ret < 0) + return ret; + /* Single/Muti DAI link(s) & New style of DT node */ memset(&li, 0, sizeof(li)); for (li.cpu = 1; li.cpu >= 0; li.cpu--) {