Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8839270ybi; Wed, 10 Jul 2019 00:10:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzohL29sQ0LyWG8VvSm11XeqGnRoFFNkALmhlEOGb3GKIcIe04R6FB26HivauH7g1AIsj7z X-Received: by 2002:a17:90b:f0e:: with SMTP id br14mr5062881pjb.117.1562742653499; Wed, 10 Jul 2019 00:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562742653; cv=none; d=google.com; s=arc-20160816; b=YExPIldG2E8N2LmobCF9afSrfY7WzcRUMW4sXyhZZPeQWWvZCNHa8koNAaHhkNO1Jy dkbW90YJAwbb57368JmSBCa/2Fi3e2fcZRmXidqQqZ6tYl4aD+nkcuAJ/qxPy32+KP4q YFzCZLcyN+ktwsj6RW6NNSdFOJL76r8ApPTYwk9inTVBdqxluKd55Uru1vUObTZMrfPx dCgMZFYBgWnCMtP9plhce+SobJr01nIGDMEuiDzKu3gjtWsf+MeA8m64q+RYVfWJhT9U zB+URWgVjOqWkvP6XQcN8Z5qcGNylQUYRJ6aMbg4GZq1ZFzqF05TTmOEu4ACA8qyb8uV 0xlg== 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=L+eKwrZa/F89dB8NfDOZ+87/z4L5EP9Qja22HRzGycY=; b=uiUK6pdrzWa8BaNeokH9BUnSlZXRuR/laXWGR0+WS4OdjmLDxalqQ1Cmvf5w6Hen+B 4uGvVrPPWHDmZ/HM1k9VIJ55k3Nr5Yex1PEHbAYVfj1kJWqZTcnAKAfSJYu8A1NK0VCU /TJT1c6Ff5MtSS2YZLJ7LAV/lOKDinXkJgC8EJXhu7Ld6XwZLp3gOm/+Y3pAaVnqIyw0 jCWXZWzwx5Vw/LfNOd5yZjoNiHzq4WR4hp73LILixkrsBtcTyw4yFOSDIRQmCCcgP1xa aw8qm3EiF93wyZKvoXNZaSl/BUvK/adgwm5WmRk9VnGhXvZlvy7JT5Jmbgspd5rtnWHq hTYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XFTjyNCf; 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 h127si1383496pgc.176.2019.07.10.00.10.37; Wed, 10 Jul 2019 00:10:53 -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=XFTjyNCf; 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 S1727057AbfGJHIn (ORCPT + 99 others); Wed, 10 Jul 2019 03:08:43 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37350 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbfGJHIn (ORCPT ); Wed, 10 Jul 2019 03:08:43 -0400 Received: by mail-pg1-f196.google.com with SMTP id g15so769116pgi.4 for ; Wed, 10 Jul 2019 00:08:43 -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=L+eKwrZa/F89dB8NfDOZ+87/z4L5EP9Qja22HRzGycY=; b=XFTjyNCfLxVVIdDsJKJTxrbqVs0USy8TBcD29bfpp9mVPErgv4JI65f8wjNoJ1d6Fp zy1R0cXBmn3mc2Iqdrnt9zXwcELjWa86VdCg0OlTymIOHeaCjha9Y9EJu++SFCHa8ynh GOsnfmZZzgKWbwups7Zqxws4e4nhIo/XsylBE= 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=L+eKwrZa/F89dB8NfDOZ+87/z4L5EP9Qja22HRzGycY=; b=CBDgBrwsSZVleksn2F5/EIGVOYqpeIgihz87l4fd/wRjVcmaOoWouc/C45U36DDwPf PB+z2OEZjIbf2N0q+5LiwqZYWh2t5DiTRt9pK0DJFcq5WhsbxGsEZf2zRZQVZFD3Hg87 WYiKjgH2igOSCV8ysSfSnJ0jxopvD/R5Ah7noH0II0o2p426CRzEZ5N1JRMQ3kc1EiBO ewX+LllOTfuox6pyW9IVRknv70RhEvGAzHacQAqR/KW4njIx/dNIg8IEdZhqVweLxmqL HuGTqUvGjRqsyYiG+kpmEGjAxABg3sP+p66di+w16nu1ArNXNjgjYG87SJsPsev2yPnf CKDw== X-Gm-Message-State: APjAAAVxdiCRB66UGiVmIyu1Rk/GVXLqv39+btpYYEHfiy8Ou7739qu7 7681Bo+RpVV1NAx1IHrJzlUAxd6Ycrg= X-Received: by 2002:a63:2148:: with SMTP id s8mr34672466pgm.336.1562742522299; Wed, 10 Jul 2019 00:08:42 -0700 (PDT) Received: from localhost ([2401:fa00:1:b:e688:dfd2:a1a7:2956]) by smtp.gmail.com with ESMTPSA id v12sm1029001pgr.86.2019.07.10.00.08.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jul 2019 00:08:41 -0700 (PDT) From: Cheng-Yi Chiang To: linux-kernel@vger.kernel.org Cc: 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 v2 3/4] ASoC: rockchip_max98090: Add dai_link for HDMI Date: Wed, 10 Jul 2019 15:07:50 +0800 Message-Id: <20190710070751.260061-4-cychiang@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190710070751.260061-1-cychiang@chromium.org> References: <20190710070751.260061-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 --- sound/soc/rockchip/rockchip_max98090.c | 95 +++++++++++++++++++------- 1 file changed, 72 insertions(+), 23 deletions(-) diff --git a/sound/soc/rockchip/rockchip_max98090.c b/sound/soc/rockchip/rockchip_max98090.c index c5fc24675a33..3617012692ea 100644 --- a/sound/soc/rockchip/rockchip_max98090.c +++ b/sound/soc/rockchip/rockchip_max98090.c @@ -41,6 +41,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 +53,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 +61,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 +95,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, +SND_SOC_DAILINK_DEFS(analog, 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(hdmi, + DAILINK_COMP_ARRAY(COMP_EMPTY()), + DAILINK_COMP_ARRAY(COMP_CODEC("hdmi-audio-codec.3.auto", "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 +164,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 +201,48 @@ 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 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; + 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.22.0.410.gd8fdbe21b5-goog