Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp987684ybe; Thu, 19 Sep 2019 07:02:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqw10GTJ+Q/Sy4TAj9SZtGcPttTrQrcBj8Fg/e8XeGe9OdXbRqtRCuAs8WC7IZUwMHTxYOWy X-Received: by 2002:a17:906:1310:: with SMTP id w16mr14022634ejb.73.1568901775495; Thu, 19 Sep 2019 07:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568901775; cv=none; d=google.com; s=arc-20160816; b=NGWn24gWkReorJUVEIgDyR3sBxBqAtVNdpUk9qs59RFcbck63n2FNNwiwb4IMTmcOA OJmla4MjWbg5tdcfZ3gXMNksEiYAn6BjEvFDDCDA6JMX6o6gi6Cx+PZ5dRvKYfTkLvU7 Rn8/hd7F1naQPh80rsJm4mu9ZGmPcR/pXaYEKW7JzhhcLbj6xHfZC/SeJYBt21Odyn1d iGRTcfDOg3e8vEznO3mj44ErBlYI7NOYkT+JuxAsyK1bRm+j3WtsOLQO2MFaleRwNo/J gDeJXRHY5naFtyfY4F2zsjw7/kc+KObbFoDBiV2Ay+tMbJiwq/MlwBPPE6t9DCrc12RB s65A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZIDYLu7ca97k4A/5V7MzuGF5gFCfwb0cYG7NrgVReLI=; b=Cp089EPer/wgZpxzE/peatcnjwFjjPuTueU6MzOwK+I0jFmH4bvZZh6wEgrJ11H8SJ xF+e3mX512tFSzsilwrf/WwFCqsc9J7yDQDZ1GCheqPKTKA6A4hKvE2t1oiGeHkQLWcq dhgIyo6vMmUlU9VPcflRZ6JVeyJV8XRIMwhSvR4PG5kX2Gdtfs6zx+V3EcHRIePZDKFN k9iN82zOQw2hEuqjuOwJjTjxS67c1qQmwzNINkOzGqTYvdVZTH38gmLEC4t2pFXlwiZD tAdcD6aFMx0e3S7u/vPJTQmcWfDHVtfByUobTfxCaQpWqqkA19tOdJwBb9S8s3iMCYYq kiBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BXokyWSE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y50si6151705edd.237.2019.09.19.07.02.30; Thu, 19 Sep 2019 07:02:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BXokyWSE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732371AbfISNzf (ORCPT + 99 others); Thu, 19 Sep 2019 09:55:35 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:34499 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727642AbfISNze (ORCPT ); Thu, 19 Sep 2019 09:55:34 -0400 Received: by mail-pl1-f196.google.com with SMTP id d3so1684282plr.1 for ; Thu, 19 Sep 2019 06:55:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZIDYLu7ca97k4A/5V7MzuGF5gFCfwb0cYG7NrgVReLI=; b=BXokyWSEnoB+eLndxVit4ZfhwMTJl878NpORNWM6vv513KsPPeqI8v+oC4Xbg1+/jg hv56oRBzAHbTEXNnJ3NNjcS4JzFR9+287D41TcTm/hYSISRRerlS2+Bso5eWW1zT0Efz g/8DazqSzzVgfdbnctQLiakvQJCyCK3XIWrhU= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZIDYLu7ca97k4A/5V7MzuGF5gFCfwb0cYG7NrgVReLI=; b=BdncKQeQI/9brN7XRuymqGw9/9+RfY9xmMvhdPtsKJOcf+q87vLf747msCqT79X0Hm 07fnNQbhFvwYalN/Hkq0iJnIdD4+kfuzeWrkfVXkcIcmLvvIniaP2rAZ1z3GMJ8ClHUp lHNRgh6KzrH3WOgfBtxTxAMd7M/9i7UJ5AeVHYeRyNkd/jVdKXY5mG+GpP2fIQs+hy34 a2rH3Z9YIfyf2jKdyAdE1CP/bHiYbf61UYfY7Jwi90ZN9TocFJ5nxZCWhHUMW4TKq759 j/d0QCfkftmaqnYjHooEbvnXBp7gDaSBQ68e7dj0z3YOrxyvnavyLvtIDzZRYF++bC2w QvDg== X-Gm-Message-State: APjAAAWJtezcAUXjFuVi18cKGuu3Td1klM1vYiU0SXtI8dXggYarofEY YkRxX7VpV5PLSBy/t6fWq85HwBNt+oE= X-Received: by 2002:a17:902:7596:: with SMTP id j22mr10208368pll.280.1568901333378; Thu, 19 Sep 2019 06:55:33 -0700 (PDT) Received: from localhost ([2401:fa00:1:10:79b4:bd83:e4a5:a720]) by smtp.gmail.com with ESMTPSA id h9sm7468913pgh.51.2019.09.19.06.55.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Sep 2019 06:55:32 -0700 (PDT) From: Cheng-Yi Chiang To: linux-kernel@vger.kernel.org Cc: Neil Armstrong , Jerome Brunet , Jernej Skrabec , Jonas Karlman , Hans Verkuil , Mark Brown , Liam Girdwood , Takashi Iwai , Jaroslav Kysela , Russell King , Andrzej Hajda , Laurent Pinchart , David Airlie , Daniel Vetter , Heiko Stuebner , dianders@chromium.org, dgreid@chromium.org, tzungbi@chromium.org, alsa-devel@alsa-project.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, Cheng-Yi Chiang Subject: [PATCH v7 3/4] ASoC: rockchip_max98090: Add dai_link for HDMI Date: Thu, 19 Sep 2019 21:54:49 +0800 Message-Id: <20190919135450.62309-4-cychiang@chromium.org> X-Mailer: git-send-email 2.23.0.237.gc6a4ce50a0-goog In-Reply-To: <20190919135450.62309-1-cychiang@chromium.org> References: <20190919135450.62309-1-cychiang@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use two dai_links. One for HDMI and one for max98090. With this setup, audio can play to speaker and HDMI selectively. Signed-off-by: Cheng-Yi Chiang --- .../boot/dts/rk3288-veyron-analog-audio.dtsi | 1 + sound/soc/rockchip/rockchip_max98090.c | 129 ++++++++++++++---- 2 files changed, 103 insertions(+), 27 deletions(-) diff --git a/arch/arm/boot/dts/rk3288-veyron-analog-audio.dtsi b/arch/arm/boot/dts/rk3288-veyron-analog-audio.dtsi index 445270aa136e..51208d161d65 100644 --- a/arch/arm/boot/dts/rk3288-veyron-analog-audio.dtsi +++ b/arch/arm/boot/dts/rk3288-veyron-analog-audio.dtsi @@ -17,6 +17,7 @@ rockchip,hp-det-gpios = <&gpio6 RK_PA5 GPIO_ACTIVE_HIGH>; rockchip,mic-det-gpios = <&gpio6 RK_PB3 GPIO_ACTIVE_LOW>; rockchip,headset-codec = <&headsetcodec>; + rockchip,hdmi-codec = <&hdmi>; }; }; diff --git a/sound/soc/rockchip/rockchip_max98090.c b/sound/soc/rockchip/rockchip_max98090.c index c5fc24675a33..6c217492bb30 100644 --- a/sound/soc/rockchip/rockchip_max98090.c +++ b/sound/soc/rockchip/rockchip_max98090.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ static const struct snd_soc_dapm_widget rk_dapm_widgets[] = { SND_SOC_DAPM_MIC("Headset Mic", NULL), SND_SOC_DAPM_MIC("Int Mic", NULL), SND_SOC_DAPM_SPK("Speaker", NULL), + SND_SOC_DAPM_LINE("HDMI", NULL), }; static const struct snd_soc_dapm_route rk_audio_map[] = { @@ -52,6 +54,7 @@ static const struct snd_soc_dapm_route rk_audio_map[] = { {"Headphone", NULL, "HPR"}, {"Speaker", NULL, "SPKL"}, {"Speaker", NULL, "SPKR"}, + {"HDMI", NULL, "TX"}, }; static const struct snd_kcontrol_new rk_mc_controls[] = { @@ -59,6 +62,7 @@ static const struct snd_kcontrol_new rk_mc_controls[] = { SOC_DAPM_PIN_SWITCH("Headset Mic"), SOC_DAPM_PIN_SWITCH("Int Mic"), SOC_DAPM_PIN_SWITCH("Speaker"), + SOC_DAPM_PIN_SWITCH("HDMI"), }; static int rk_aif1_hw_params(struct snd_pcm_substream *substream, @@ -92,38 +96,63 @@ static int rk_aif1_hw_params(struct snd_pcm_substream *substream, ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT); - if (ret < 0) { - dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret); + if (ret) { + dev_err(cpu_dai->dev, "Can't set cpu dai clock %d\n", ret); return ret; } + /* HDMI codec dai does not need to set sysclk. */ + if (!strcmp(rtd->dai_link->name, "HDMI")) + return 0; + ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, SND_SOC_CLOCK_IN); - if (ret < 0) { - dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret); + if (ret) { + dev_err(codec_dai->dev, "Can't set codec dai clock %d\n", ret); return ret; } - return ret; + return 0; } static const struct snd_soc_ops rk_aif1_ops = { .hw_params = rk_aif1_hw_params, }; -SND_SOC_DAILINK_DEFS(hifi, - DAILINK_COMP_ARRAY(COMP_EMPTY()), - DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "HiFi")), - DAILINK_COMP_ARRAY(COMP_EMPTY())); - -static struct snd_soc_dai_link rk_dailink = { - .name = "max98090", - .stream_name = "Audio", - .ops = &rk_aif1_ops, - /* set max98090 as slave */ - .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | - SND_SOC_DAIFMT_CBS_CFS, - SND_SOC_DAILINK_REG(hifi), +SND_SOC_DAILINK_DEFS(analog, + DAILINK_COMP_ARRAY(COMP_EMPTY()), + DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "HiFi")), + DAILINK_COMP_ARRAY(COMP_EMPTY())); + +SND_SOC_DAILINK_DEFS(hdmi, + DAILINK_COMP_ARRAY(COMP_EMPTY()), + DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")), + DAILINK_COMP_ARRAY(COMP_EMPTY())); + +enum { + DAILINK_MAX98090, + DAILINK_HDMI, +}; + +/* max98090 and HDMI codec dai_link */ +static struct snd_soc_dai_link rk_dailinks[] = { + [DAILINK_MAX98090] = { + .name = "max98090", + .stream_name = "Analog", + .ops = &rk_aif1_ops, + /* set max98090 as slave */ + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, + SND_SOC_DAILINK_REG(analog), + }, + [DAILINK_HDMI] = { + .name = "HDMI", + .stream_name = "HDMI", + .ops = &rk_aif1_ops, + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, + SND_SOC_DAILINK_REG(hdmi), + } }; static int rk_98090_headset_init(struct snd_soc_component *component); @@ -136,8 +165,8 @@ static struct snd_soc_aux_dev rk_98090_headset_dev = { static struct snd_soc_card snd_soc_card_rk = { .name = "ROCKCHIP-I2S", .owner = THIS_MODULE, - .dai_link = &rk_dailink, - .num_links = 1, + .dai_link = rk_dailinks, + .num_links = ARRAY_SIZE(rk_dailinks), .aux_dev = &rk_98090_headset_dev, .num_aux_devs = 1, .dapm_widgets = rk_dapm_widgets, @@ -173,27 +202,73 @@ static int snd_rk_mc_probe(struct platform_device *pdev) int ret = 0; struct snd_soc_card *card = &snd_soc_card_rk; struct device_node *np = pdev->dev.of_node; + struct device_node *np_analog; + struct device_node *np_cpu; + struct device_node *np_hdmi_codec; + struct of_phandle_args args; /* register the soc card */ card->dev = &pdev->dev; - rk_dailink.codecs->of_node = of_parse_phandle(np, - "rockchip,audio-codec", 0); - if (!rk_dailink.codecs->of_node) { + np_analog = of_parse_phandle(np, "rockchip,audio-codec", 0); + if (!np_analog) { dev_err(&pdev->dev, "Property 'rockchip,audio-codec' missing or invalid\n"); return -EINVAL; } + rk_dailinks[DAILINK_MAX98090].codecs->of_node = np_analog; + + ret = of_parse_phandle_with_fixed_args(np, "rockchip,audio-codec", + 0, 0, &args); + if (ret) { + dev_err(&pdev->dev, + "Unable to parse property 'rockchip,audio-codec'\n"); + return ret; + } + + ret = snd_soc_get_dai_name( + &args, &rk_dailinks[DAILINK_MAX98090].codecs->dai_name); + if (ret) { + dev_err(&pdev->dev, "Unable to get codec dai_name\n"); + return ret; + } + + np_cpu = of_parse_phandle(np, "rockchip,i2s-controller", 0); - rk_dailink.cpus->of_node = of_parse_phandle(np, - "rockchip,i2s-controller", 0); - if (!rk_dailink.cpus->of_node) { + if (!np_cpu) { dev_err(&pdev->dev, "Property 'rockchip,i2s-controller' missing or invalid\n"); return -EINVAL; } - rk_dailink.platforms->of_node = rk_dailink.cpus->of_node; + np_hdmi_codec = of_parse_phandle(np, "rockchip,hdmi-codec", 0); + if (!np_hdmi_codec) { + dev_err(&pdev->dev, + "Property 'rockchip,hdmi-codec' missing or invalid\n"); + return -EINVAL; + } + + rk_dailinks[DAILINK_HDMI].codecs->of_node = np_hdmi_codec; + + ret = of_parse_phandle_with_fixed_args(np, "rockchip,hdmi-codec", + 0, 0, &args); + if (ret) { + dev_err(&pdev->dev, + "Unable to parse property 'rockchip,hdmi-codec'\n"); + return ret; + } + + ret = snd_soc_get_dai_name( + &args, &rk_dailinks[DAILINK_HDMI].codecs->dai_name); + if (ret) { + dev_err(&pdev->dev, "Unable to get hdmi codec dai_name\n"); + return ret; + } + + rk_dailinks[DAILINK_MAX98090].cpus->of_node = np_cpu; + rk_dailinks[DAILINK_MAX98090].platforms->of_node = np_cpu; + rk_dailinks[DAILINK_HDMI].cpus->of_node = np_cpu; + rk_dailinks[DAILINK_HDMI].platforms->of_node = np_cpu; rk_98090_headset_dev.codec_of_node = of_parse_phandle(np, "rockchip,headset-codec", 0); -- 2.23.0.237.gc6a4ce50a0-goog