Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3706980ybi; Sun, 2 Jun 2019 21:35:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwyKS9kwQdYwENZBgUwFbmlOssR+HTlK4oR1e520AyYpefFq1aHokVpCtRMjuNEglYezY/B X-Received: by 2002:a17:90a:c481:: with SMTP id j1mr27544573pjt.96.1559536534985; Sun, 02 Jun 2019 21:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559536534; cv=none; d=google.com; s=arc-20160816; b=gNZON+pRNI6JzmpLL4mpjlsO9i+Tzh3E20ztbsQonsQpIt3Wwsq9HF/ckDHjmT+vKG Qwz7wdmUXF96KOHcbhvnOJl7nlZfGSzEXUezOIfXx6xPmon2w6hDxtjhcFQl+eJmI8OQ z1ik8Elq5yaf5VcamsE01kjm++/vvOHkFDbXLIaFFayQ1DL1v8dHrjh5wXDVuVT+Jqei Ny7mD1aEmDm9fhXOOjuukxKCwK4p6f47xJnWddonvb/bstrLvJSM36Dryw0npgkIc3dV tre7DsxU7aovID7U1jCn6besVnzDkWkUQ13aYoCQBSJdjhGsyQIgN1zDJ1VrXbbMx1Ke YslA== 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=VNhIPfCzhvP16fqORSEWqfVMPdXyoyqEWF63uuLSDrk=; b=m1JybXXjpRL3QGyTs49Dj2FXmv9rPYiKV7qxGOFqSxF6EtI3EfTVL4/yNV9V/HDSeh +Zy+o/ZfYoF6RqI5lZG0zGcPwdbe80dJ1JSwQesuta6Fbk9bU6YDEQ/fyEiEtOTezb/l dc3F2KqN5+uVYy3fKCc4ilCKukeI0Si//94HaAEAo8W5xfYdwQzxUtabl8eZ2J+eBMpA gKtPIxuh3jXEAP6qPo29AD5lXUUzJsfyuYH948kIZDCGWa9pLmEWlt1cLgTXdIMtf728 FMdW7GIDrglUV6ZLfPQAtlDY1S8pM2b2VO6cSIG7H3ywize5gD4yY+x+6+CHj7DWRElg MCnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aS63RSB2; 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 k2si17127300pje.26.2019.06.02.21.35.19; Sun, 02 Jun 2019 21:35:34 -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=aS63RSB2; 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 S1726808AbfFCEdy (ORCPT + 99 others); Mon, 3 Jun 2019 00:33:54 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:43858 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726939AbfFCEdw (ORCPT ); Mon, 3 Jun 2019 00:33:52 -0400 Received: by mail-pg1-f193.google.com with SMTP id f25so7509643pgv.10 for ; Sun, 02 Jun 2019 21:33:51 -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=VNhIPfCzhvP16fqORSEWqfVMPdXyoyqEWF63uuLSDrk=; b=aS63RSB2MNke62PjJpoyae9QYgwadmzCHxyo/akbQ6j0njb7Qvs1M42x05Nl+STv4N aT36WXdgX14k/02Uu5lOtg0gDcVzgC82+oI2MDXRTP2djZfNlQBgktFTbm0TIYz9LeEM UQxXP76qGTfkBpPvYmVsorx3tFk+XkOps4S8Q= 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=VNhIPfCzhvP16fqORSEWqfVMPdXyoyqEWF63uuLSDrk=; b=TlNAUUUng1wWirHLmbTlD2/AB5Ggd0L0NQamWr9FB20MHEhCe4WTddWYIIOhCMksHL GP89TGHpx/tJsfeTaKO+E+ozZJS3K1rEBMq9WWq53GOLj3VicN28VPvDPiBTcf3Fkr8u D5CayngYto46BDLLba3Sg0P9n8Sn0BCU15N6jhh9u/ykpvS1knrMUJOfGKbnF4C18lb2 SFa8BjE3+JBqQ81/ULZUMP3N4p+cE74cVSRuhw/nlOrljNQUAQtkBdOPpSNFEbpzrGUp yL79rK7JEy2T4jSlnIfbtA+VtKcMl7CS3MAXz3yMlM+bhyJ+evff+Bdg+YOKRU6n7zT6 VP7g== X-Gm-Message-State: APjAAAUUA4eCzaYoIujcSVGnyxsznaRSgbJKz4FSGJrXwLNffzpqcyKI sMZe2mnbX65GAfvEQ0Mk19ipkXwZG4Y= X-Received: by 2002:a65:5302:: with SMTP id m2mr15280720pgq.266.1559536431198; Sun, 02 Jun 2019 21:33:51 -0700 (PDT) Received: from localhost ([2401:fa00:1:b:e688:dfd2:a1a7:2956]) by smtp.gmail.com with ESMTPSA id g22sm13550306pfo.28.2019.06.02.21.33.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Jun 2019 21:33:50 -0700 (PDT) From: Cheng-Yi Chiang To: linux-kernel@vger.kernel.org Cc: Hans Verkuil , Bartlomiej Zolnierkiewicz , Greg Kroah-Hartman , Philipp Zabel , Mark Brown , Liam Girdwood , Takashi Iwai , Jaroslav Kysela , Russell King , Andrzej Hajda , Laurent Pinchart , David Airlie , Daniel Vetter , Rob Herring , Heiko Stuebner , dianders@chromium.org, dgreid@chromium.org, tzungbi@chromium.org, linux-media@vger.kernel.org, alsa-devel@alsa-project.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, Cheng-Yi Chiang Subject: [PATCH 4/7] ASoC: rockchip_max98090: Add dai_link for HDMI Date: Mon, 3 Jun 2019 12:32:48 +0800 Message-Id: <20190603043251.226549-5-cychiang@chromium.org> X-Mailer: git-send-email 2.22.0.rc1.257.g3120a18244-goog In-Reply-To: <20190603043251.226549-1-cychiang@chromium.org> References: <20190603043251.226549-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 | 82 +++++++++++++++++++------- 1 file changed, 60 insertions(+), 22 deletions(-) diff --git a/sound/soc/rockchip/rockchip_max98090.c b/sound/soc/rockchip/rockchip_max98090.c index 789d6f1e2b5f..2dd247670c7a 100644 --- a/sound/soc/rockchip/rockchip_max98090.c +++ b/sound/soc/rockchip/rockchip_max98090.c @@ -53,6 +53,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[] = { @@ -64,6 +65,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[] = { @@ -71,6 +73,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, @@ -104,33 +107,48 @@ 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 && ret != -ENOTSUPP) { + dev_err(cpu_dai->dev, "Can't set cpu dai clock %d\n", ret); return ret; } 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 && ret != -ENOTSUPP) { + 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, }; -static struct snd_soc_dai_link rk_dailink = { - .name = "max98090", - .stream_name = "Audio", - .codec_dai_name = "HiFi", - .ops = &rk_aif1_ops, - /* set max98090 as slave */ - .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | - SND_SOC_DAIFMT_CBS_CFS, +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, + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, + }, + [DAILINK_HDMI] = { + .name = "HDMI", + .stream_name = "HDMI", + .codec_name = "hdmi-audio-codec.3.auto", + .codec_dai_name = "i2s-hifi", + .ops = &rk_aif1_ops, + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, + } }; static int rk_98090_headset_init(struct snd_soc_component *component); @@ -143,8 +161,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, @@ -180,27 +198,47 @@ 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_cpu; + struct of_phandle_args args; /* register the soc card */ card->dev = &pdev->dev; - rk_dailink.codec_of_node = of_parse_phandle(np, - "rockchip,audio-codec", 0); - if (!rk_dailink.codec_of_node) { + rk_dailinks[DAILINK_MAX98090].codec_of_node = + of_parse_phandle(np, "rockchip,audio-codec", 0); + if (!rk_dailinks[DAILINK_MAX98090].codec_of_node) { dev_err(&pdev->dev, "Property 'rockchip,audio-codec' missing or invalid\n"); return -EINVAL; } - rk_dailink.cpu_of_node = of_parse_phandle(np, - "rockchip,i2s-controller", 0); - if (!rk_dailink.cpu_of_node) { + 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].codec_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); + + if (!np_cpu) { dev_err(&pdev->dev, "Property 'rockchip,i2s-controller' missing or invalid\n"); return -EINVAL; } - rk_dailink.platform_of_node = rk_dailink.cpu_of_node; + rk_dailinks[DAILINK_MAX98090].cpu_of_node = np_cpu; + rk_dailinks[DAILINK_MAX98090].platform_of_node = np_cpu; + rk_dailinks[DAILINK_HDMI].cpu_of_node = np_cpu; + rk_dailinks[DAILINK_HDMI].platform_of_node = np_cpu; rk_98090_headset_dev.codec_of_node = of_parse_phandle(np, "rockchip,headset-codec", 0); -- 2.22.0.rc1.257.g3120a18244-goog