From patchwork Tue Sep 19 12:57:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffy Chen X-Patchwork-Id: 9958951 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 4F18F60568 for ; Tue, 19 Sep 2017 13:00:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72AEF28ED8 for ; Tue, 19 Sep 2017 13:00:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70EC428F07; Tue, 19 Sep 2017 13:00:46 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8686B28ED8 for ; Tue, 19 Sep 2017 13:00:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=UmShGDCAscg5vk9pP1qjFfv+6aLqLy5RLucD9LC6e9o=; b=auq7S2Hy6AVtZDKKFU18auD6dE qW1mubpuGhuy04JMd+tDgu3picGtsG/MZ/Gg+FRqKRNPbQzYLuZAhjdOlQZjCYVEdTpsrxZCDZaLH qmjoo39rnI0lnipEdrsY2ZMgobtOZaTyq3U59gXOEGf6Ug0AkgqQU/opQuWBCQcgH55hknI9ggEsT lhpsb74+coOAswKD/znz8tueFl/unq/wRCYlNAtZi3ZFtqdHS6P5OtFGxhl6lPeGea2Q+e6+seQsG yUPRWSZlAuHLEBf4PKxY5LeSWly4JdLnmcbqKxIM9GX0K3EPPHW7E8ccHA5htl0daY1VR/EptLxLT JnkQzB+A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1duI8f-00068o-CQ; Tue, 19 Sep 2017 13:00:33 +0000 Received: from regular1.263xmail.com ([211.150.99.135]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1duI7O-0003gD-7v; Tue, 19 Sep 2017 12:59:25 +0000 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.183]) by regular1.263xmail.com (Postfix) with ESMTP id A5CAD1DED4; Tue, 19 Sep 2017 20:58:48 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id F390E394; Tue, 19 Sep 2017 20:58:40 +0800 (CST) X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from localhost (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 24583KWIEK5; Tue, 19 Sep 2017 20:58:50 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org Subject: [PATCH v3 3/5] ASoC: rockchip: Init dapm routes dynamically Date: Tue, 19 Sep 2017 20:57:58 +0800 Message-Id: <20170919125800.336-4-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170919125800.336-1-jeffy.chen@rock-chips.com> References: <20170919125800.336-1-jeffy.chen@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170919_055915_500434_87B806A7 X-CRM114-Status: GOOD ( 10.56 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, briannorris@chromium.org, Heiko Stuebner , Liam Girdwood , Mark Brown , Jeffy Chen , dianders@chromium.org, Jaroslav Kysela , linux-rockchip@lists.infradead.org, mka@chromium.org, Takashi Iwai , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently we are using a fixed list of dapm routes. Init dapm routes dynamically when parsing dailinks, since we are supporting optional codecs. Signed-off-by: Jeffy Chen Reviewed-by: Matthias Kaehlcke Tested-by: Matthias Kaehlcke --- Changes in v3: None Changes in v2: Fix DMic typo. sound/soc/rockchip/rk3399_gru_sound.c | 88 ++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 16 deletions(-) diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c index ad19e391c4a6..fab868850d3a 100644 --- a/sound/soc/rockchip/rk3399_gru_sound.c +++ b/sound/soc/rockchip/rk3399_gru_sound.c @@ -50,20 +50,6 @@ static const struct snd_soc_dapm_widget rockchip_dapm_widgets[] = { SND_SOC_DAPM_LINE("HDMI", NULL), }; -static const struct snd_soc_dapm_route rockchip_dapm_routes[] = { - /* Input Lines */ - {"MIC", NULL, "Headset Mic"}, - {"DMIC1L", NULL, "Int Mic"}, - {"DMIC1R", NULL, "Int Mic"}, - {"DMic", NULL, "Int Mic"}, - - /* Output Lines */ - {"Headphones", NULL, "HPL"}, - {"Headphones", NULL, "HPR"}, - {"Speakers", NULL, "Speaker"}, - {"HDMI", NULL, "TX"}, -}; - static const struct snd_kcontrol_new rockchip_controls[] = { SOC_DAPM_PIN_SWITCH("Headphones"), SOC_DAPM_PIN_SWITCH("Speakers"), @@ -318,8 +304,6 @@ static struct snd_soc_card rockchip_sound_card = { .owner = THIS_MODULE, .dapm_widgets = rockchip_dapm_widgets, .num_dapm_widgets = ARRAY_SIZE(rockchip_dapm_widgets), - .dapm_routes = rockchip_dapm_routes, - .num_dapm_routes = ARRAY_SIZE(rockchip_dapm_routes), .controls = rockchip_controls, .num_controls = ARRAY_SIZE(rockchip_controls), }; @@ -395,6 +379,65 @@ static const struct snd_soc_dai_link rockchip_dais[] = { }, }; +static const struct snd_soc_dapm_route rockchip_sound_cdndp_routes[] = { + /* Output */ + {"HDMI", NULL, "TX"}, +}; + +static const struct snd_soc_dapm_route rockchip_sound_da7219_routes[] = { + /* Output */ + {"Headphones", NULL, "HPL"}, + {"Headphones", NULL, "HPR"}, + + /* Input */ + {"MIC", NULL, "Headset Mic"}, +}; + +static const struct snd_soc_dapm_route rockchip_sound_dmic_routes[] = { + /* Input */ + {"DMic", NULL, "Int Mic"}, +}; + +static const struct snd_soc_dapm_route rockchip_sound_max98357a_routes[] = { + /* Output */ + {"Speakers", NULL, "Speaker"}, +}; + +static const struct snd_soc_dapm_route rockchip_sound_rt5514_routes[] = { + /* Input */ + {"DMIC1L", NULL, "Int Mic"}, + {"DMIC1R", NULL, "Int Mic"}, +}; + +struct rockchip_sound_route { + const struct snd_soc_dapm_route *routes; + int num_routes; +}; + +static const struct rockchip_sound_route rockchip_routes[] = { + [DAILINK_CDNDP] = { + .routes = rockchip_sound_cdndp_routes, + .num_routes = ARRAY_SIZE(rockchip_sound_cdndp_routes), + }, + [DAILINK_DA7219] = { + .routes = rockchip_sound_da7219_routes, + .num_routes = ARRAY_SIZE(rockchip_sound_da7219_routes), + }, + [DAILINK_DMIC] = { + .routes = rockchip_sound_dmic_routes, + .num_routes = ARRAY_SIZE(rockchip_sound_dmic_routes), + }, + [DAILINK_MAX98357A] = { + .routes = rockchip_sound_max98357a_routes, + .num_routes = ARRAY_SIZE(rockchip_sound_max98357a_routes), + }, + [DAILINK_RT5514] = { + .routes = rockchip_sound_rt5514_routes, + .num_routes = ARRAY_SIZE(rockchip_sound_rt5514_routes), + }, + [DAILINK_RT5514_DSP] = {}, +}; + static int rockchip_sound_codec_node_match(struct device_node *np_codec) { int i; @@ -412,6 +455,7 @@ static int rockchip_sound_of_parse_dais(struct device *dev, struct device_node *np_cpu, *np_cpu0, *np_cpu1; struct device_node *np_codec; struct snd_soc_dai_link *dai; + struct snd_soc_dapm_route *routes; int i, index; card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais), @@ -419,9 +463,16 @@ static int rockchip_sound_of_parse_dais(struct device *dev, if (!card->dai_link) return -ENOMEM; + routes = devm_kzalloc(dev, sizeof(rockchip_routes), + GFP_KERNEL); + if (!routes) + return -ENOMEM; + card->dapm_routes = routes; + np_cpu0 = of_parse_phandle(dev->of_node, "rockchip,cpu", 0); np_cpu1 = of_parse_phandle(dev->of_node, "rockchip,cpu", 1); + card->num_dapm_routes = 0; card->num_links = 0; for (i = 0; i < ARRAY_SIZE(rockchip_dais); i++) { np_codec = of_parse_phandle(dev->of_node, @@ -449,6 +500,11 @@ static int rockchip_sound_of_parse_dais(struct device *dev, dai->codec_of_node = np_codec; dai->platform_of_node = np_cpu; dai->cpu_of_node = np_cpu; + + memcpy(routes + card->num_dapm_routes, + rockchip_routes[index].routes, + rockchip_routes[index].num_routes * sizeof(*routes)); + card->num_dapm_routes += rockchip_routes[index].num_routes; } return 0;