Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4099672ybg; Fri, 25 Oct 2019 13:19:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyuLLlZnj7eEMJ7V+dTpANvvj+cm2PUfT8vyvDIvBYsnAFjtemdJGvxu8q4Knb1YdZMvalL X-Received: by 2002:a17:906:4c97:: with SMTP id q23mr5150352eju.78.1572034746455; Fri, 25 Oct 2019 13:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572034746; cv=none; d=google.com; s=arc-20160816; b=Ug1Oby8RrmmX/Nz7UKUIPTVv0AJmACP1DevJcXqStktcKoiPI8/l+qEMUMOChoBi6g COmRPnU/+ilW541SFSwYZKc0MNCI5dqn8E0S2i5MjbUfTEjcuAdDOmpGsxJ6N+L2QNP1 +hgv5I4JCn7igmLNMtndWRyg3tx9VShCamhuawsFcUNB6HHzUALhRWd1aa8Wpg3a2WHx POFqQEQISdiX5K2/MaoCNZRi0vsKpckMb7+/G7fLhtUaGzzbHF5xhgiQlYi1hpgOKfpQ LqQOazsDv2NgkaC/7TvFpVPcng5rpwI4CSNTlNYZKkgik82E25gbjdQMg39bEQeHJPR1 zmvQ== 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=ve3UtPvtc/xYkzxdt2g2jT6KC14vNaRw1VSiMrx2k+M=; b=I137AMJC0TFOasAu/C2g22MPgrB9S9BuKyjN8dm/S1n8cpX2IXz7zwSOxcTgjqLBhp aGXR123H3pGPn3qMwZpWSyqeG6XhRXwnZH+Y2crBkqbWJLzmDiJnRL+7Df9XEiuZlFa/ 2ImK1Yt4MDcHln1klTVhPhv62/U6ES+iJERjhfJslP1/OH4YESRVyH+7HOTUlJVQk0Aa hXBEdRgJK5omyTwug7Nx+A1jSLAwZzoOpecx5nI+azv/bNch2rpZkzwfxXGSUUTm7GOx uCAX7qXnAVRvlJs/In0seWJJb6UBjQ+C2gnfTO6mMsFi0x2hMS4up+ZgeHp+RcvBhoqE pOBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DK2nUf+F; 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 63si2347884edp.302.2019.10.25.13.18.43; Fri, 25 Oct 2019 13:19:06 -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=DK2nUf+F; 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 S2504735AbfJYNbD (ORCPT + 99 others); Fri, 25 Oct 2019 09:31:03 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:36443 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2504727AbfJYNbB (ORCPT ); Fri, 25 Oct 2019 09:31:01 -0400 Received: by mail-pf1-f195.google.com with SMTP id v19so1601869pfm.3 for ; Fri, 25 Oct 2019 06:31:00 -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=ve3UtPvtc/xYkzxdt2g2jT6KC14vNaRw1VSiMrx2k+M=; b=DK2nUf+FP8kZb9OOpfloe4MHcvJFz2/rv7k5yAQK83PBDj4jh15Z+fI3qR98PHrYgw BWhr0pj65MZmG/uTpX+k5yiYagE4bTizChAfOggclPZjhzHVoe/rDN4fZg+p+XFiCzTe ZF3c6QKMJ387PjbCa+kDDAiCkRSPcs8Vp2Xt4= 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=ve3UtPvtc/xYkzxdt2g2jT6KC14vNaRw1VSiMrx2k+M=; b=nx5k2wkt0catz31ksgM5O0+o8LUhrpXG5/v48W+Qor0urWpvWG/+ly0bZgSZuzyl9B osePqDLT9sk6m1XJCWEK6yJ/s4q2t+C5qpy2J97c8ks4LkJns3Ty2KnrZXGNkZyhq/Xt Mf7R0OaY6UMbd68ayn4KtVUcouerQD4iaq6WZxMy/VndJF82Asuj3RAnZgmsQodwSh8B Egu1LAPuZIogf+99PJKHznKYfpku8FmoOz20we9Ws7N/pB55bmkCsUnpFEQOG+qDld24 UxXZG71yk87TqGvS3ZldARxefgA75UaDgY63m+UI0xaMG+WLVjEZxQvFwXcmDC646gMG IZBA== X-Gm-Message-State: APjAAAXFDdQB0Fu7/olY/0R5FREOzkRAOtOt2D2nFazLJoBqbDmio36n 18+DrJvzSlW3IeWeBJ8gL3B8ebEce7GS2w== X-Received: by 2002:a17:90a:730a:: with SMTP id m10mr4184984pjk.80.1572010259258; Fri, 25 Oct 2019 06:30:59 -0700 (PDT) Received: from localhost ([2401:fa00:1:10:79b4:bd83:e4a5:a720]) by smtp.gmail.com with ESMTPSA id e23sm2677354pgh.84.2019.10.25.06.30.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Oct 2019 06:30:58 -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 , Rob Herring , Mark Rutland , 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, devicetree@vger.kernel.org, Cheng-Yi Chiang Subject: [PATCH v8 3/6] ASoC: rockchip_max98090: Optionally support HDMI use case Date: Fri, 25 Oct 2019 21:30:04 +0800 Message-Id: <20191025133007.11190-4-cychiang@chromium.org> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog In-Reply-To: <20191025133007.11190-1-cychiang@chromium.org> References: <20191025133007.11190-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 Support three different use cases with rockchip_max98090 driver: - max98090 only: Current usage, where HDMI link is missing. - HDMI only: Needed use case for veyron_mickey board. - max98090 + HDMI: Ideal use case for veyron_jerry, veyron_minnie..etc. Note that we keep max98090 only usage for backward compatibility. From devicetree, different compatible string can be passed to configure the usage. Signed-off-by: Cheng-Yi Chiang --- The checkpatch error "Macros with complex values should be enclosed in parentheses" seems not suitable for the macro usage for DAPM widget, route, and controls. sound/soc/rockchip/rockchip_max98090.c | 371 ++++++++++++++++++++----- 1 file changed, 303 insertions(+), 68 deletions(-) diff --git a/sound/soc/rockchip/rockchip_max98090.c b/sound/soc/rockchip/rockchip_max98090.c index 0097df1fae66..550e57789719 100644 --- a/sound/soc/rockchip/rockchip_max98090.c +++ b/sound/soc/rockchip/rockchip_max98090.c @@ -6,11 +6,13 @@ */ #include +#include #include #include #include #include #include +#include #include #include #include @@ -21,6 +23,17 @@ #define DRV_NAME "rockchip-snd-max98090" +enum rk_snd_usage { + RK_USE_MAX98090, /* Only use max98090. */ + RK_USE_HDMI, /* Only use HDMI. */ + RK_USE_MAX98090_HDMI, /* Use both max98090 and HDMI. */ +}; + +struct rk_card_config { + enum rk_snd_usage usage; + struct snd_soc_card *card; +}; + static struct snd_soc_jack headset_jack; /* Headset jack detection DAPM pins */ @@ -36,28 +49,73 @@ static struct snd_soc_jack_pin headset_jack_pins[] = { }; -static const struct snd_soc_dapm_widget rk_dapm_widgets[] = { - SND_SOC_DAPM_HP("Headphone", NULL), - SND_SOC_DAPM_MIC("Headset Mic", NULL), - SND_SOC_DAPM_MIC("Int Mic", NULL), - SND_SOC_DAPM_SPK("Speaker", NULL), +#define RK_MAX98090_WIDGETS \ + SND_SOC_DAPM_HP("Headphone", NULL), \ + SND_SOC_DAPM_MIC("Headset Mic", NULL), \ + SND_SOC_DAPM_MIC("Int Mic", NULL), \ + SND_SOC_DAPM_SPK("Speaker", NULL) + +#define RK_HDMI_WIDGETS \ + SND_SOC_DAPM_LINE("HDMI", NULL) + +static const struct snd_soc_dapm_widget rk_max98090_dapm_widgets[] = { + RK_MAX98090_WIDGETS, +}; + +static const struct snd_soc_dapm_widget rk_hdmi_dapm_widgets[] = { + RK_HDMI_WIDGETS, +}; + +static const struct snd_soc_dapm_widget rk_max98090_hdmi_dapm_widgets[] = { + RK_MAX98090_WIDGETS, + RK_HDMI_WIDGETS, +}; + +#define RK_MAX98090_AUDIO_MAP \ + {"IN34", NULL, "Headset Mic"}, \ + {"Headset Mic", NULL, "MICBIAS"}, \ + {"DMICL", NULL, "Int Mic"}, \ + {"Headphone", NULL, "HPL"}, \ + {"Headphone", NULL, "HPR"}, \ + {"Speaker", NULL, "SPKL"}, \ + {"Speaker", NULL, "SPKR"} + +#define RK_HDMI_AUDIO_MAP \ + {"HDMI", NULL, "TX"} + +static const struct snd_soc_dapm_route rk_max98090_audio_map[] = { + RK_MAX98090_AUDIO_MAP, +}; + +static const struct snd_soc_dapm_route rk_hdmi_audio_map[] = { + RK_HDMI_AUDIO_MAP, +}; + +static const struct snd_soc_dapm_route rk_max98090_hdmi_audio_map[] = { + RK_MAX98090_AUDIO_MAP, + RK_HDMI_AUDIO_MAP, +}; + +#define RK_MAX98090_CONTROLS \ + SOC_DAPM_PIN_SWITCH("Headphone"), \ + SOC_DAPM_PIN_SWITCH("Headset Mic"), \ + SOC_DAPM_PIN_SWITCH("Int Mic"), \ + SOC_DAPM_PIN_SWITCH("Speaker") + +#define RK_HDMI_CONTROLS \ + SOC_DAPM_PIN_SWITCH("HDMI") + +static const struct snd_kcontrol_new rk_max98090_controls[] = { + RK_MAX98090_CONTROLS, }; -static const struct snd_soc_dapm_route rk_audio_map[] = { - {"IN34", NULL, "Headset Mic"}, - {"Headset Mic", NULL, "MICBIAS"}, - {"DMICL", NULL, "Int Mic"}, - {"Headphone", NULL, "HPL"}, - {"Headphone", NULL, "HPR"}, - {"Speaker", NULL, "SPKL"}, - {"Speaker", NULL, "SPKR"}, +static const struct snd_kcontrol_new rk_hdmi_controls[] = { + RK_HDMI_CONTROLS, }; -static const struct snd_kcontrol_new rk_mc_controls[] = { - SOC_DAPM_PIN_SWITCH("Headphone"), - SOC_DAPM_PIN_SWITCH("Headset Mic"), - SOC_DAPM_PIN_SWITCH("Int Mic"), - SOC_DAPM_PIN_SWITCH("Speaker"), +static const struct snd_kcontrol_new rk_max98090_hdmi_controls[] = { + RK_MAX98090_CONTROLS, + RK_HDMI_CONTROLS, }; static int rk_jack_event(struct notifier_block *nb, unsigned long event, @@ -122,15 +180,20 @@ 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; } 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); + + /* HDMI codec dai does not need to set sysclk. */ + if (!strcmp(rtd->dai_link->name, "HDMI")) + return 0; + + if (ret) { + dev_err(codec_dai->dev, "Can't set codec dai clock %d\n", ret); return ret; } @@ -152,20 +215,67 @@ static const struct snd_soc_ops rk_aif1_ops = { .startup = rk_aif1_startup, }; -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", - .init = rk_init, - .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 dai_link */ +static struct snd_soc_dai_link rk_max98090_dailinks[] = { + { + .name = "max98090", + .stream_name = "Analog", + .init = rk_init, + .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), + }, +}; + +/* HDMI codec dai_link */ +static struct snd_soc_dai_link rk_hdmi_dailinks[] = { + { + .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), + } +}; + +/* max98090 and HDMI codec dai_link */ +static struct snd_soc_dai_link rk_max98090_hdmi_dailinks[] = { + [DAILINK_MAX98090] = { + .name = "max98090", + .stream_name = "Analog", + .init = rk_init, + .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); @@ -175,19 +285,47 @@ static struct snd_soc_aux_dev rk_98090_headset_dev = { .init = rk_98090_headset_init, }; -static struct snd_soc_card snd_soc_card_rk = { +static struct snd_soc_card rockchip_max98090_card = { .name = "ROCKCHIP-I2S", .owner = THIS_MODULE, - .dai_link = &rk_dailink, - .num_links = 1, + .dai_link = rk_max98090_dailinks, + .num_links = ARRAY_SIZE(rk_max98090_dailinks), + .aux_dev = &rk_98090_headset_dev, + .num_aux_devs = 1, + .dapm_widgets = rk_max98090_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(rk_max98090_dapm_widgets), + .dapm_routes = rk_max98090_audio_map, + .num_dapm_routes = ARRAY_SIZE(rk_max98090_audio_map), + .controls = rk_max98090_controls, + .num_controls = ARRAY_SIZE(rk_max98090_controls), +}; + +static struct snd_soc_card rockchip_hdmi_card = { + .name = "ROCKCHIP-HDMI", + .owner = THIS_MODULE, + .dai_link = rk_hdmi_dailinks, + .num_links = ARRAY_SIZE(rk_hdmi_dailinks), + .dapm_widgets = rk_hdmi_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(rk_hdmi_dapm_widgets), + .dapm_routes = rk_hdmi_audio_map, + .num_dapm_routes = ARRAY_SIZE(rk_hdmi_audio_map), + .controls = rk_hdmi_controls, + .num_controls = ARRAY_SIZE(rk_hdmi_controls), +}; + +static struct snd_soc_card rockchip_max98090_hdmi_card = { + .name = "ROCKCHIP-MAX98090-HDMI", + .owner = THIS_MODULE, + .dai_link = rk_max98090_hdmi_dailinks, + .num_links = ARRAY_SIZE(rk_max98090_hdmi_dailinks), .aux_dev = &rk_98090_headset_dev, .num_aux_devs = 1, - .dapm_widgets = rk_dapm_widgets, - .num_dapm_widgets = ARRAY_SIZE(rk_dapm_widgets), - .dapm_routes = rk_audio_map, - .num_dapm_routes = ARRAY_SIZE(rk_audio_map), - .controls = rk_mc_controls, - .num_controls = ARRAY_SIZE(rk_mc_controls), + .dapm_widgets = rk_max98090_hdmi_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(rk_max98090_hdmi_dapm_widgets), + .dapm_routes = rk_max98090_hdmi_audio_map, + .num_dapm_routes = ARRAY_SIZE(rk_max98090_hdmi_audio_map), + .controls = rk_max98090_hdmi_controls, + .num_controls = ARRAY_SIZE(rk_max98090_hdmi_controls), }; static int rk_98090_headset_init(struct snd_soc_component *component) @@ -195,7 +333,7 @@ static int rk_98090_headset_init(struct snd_soc_component *component) int ret; /* Enable Headset and 4 Buttons Jack detection */ - ret = snd_soc_card_jack_new(&snd_soc_card_rk, "Headset Jack", + ret = snd_soc_card_jack_new(component->card, "Headset Jack", SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 | SND_JACK_BTN_3, @@ -210,41 +348,112 @@ static int rk_98090_headset_init(struct snd_soc_component *component) return ret; } +static int rk_parse_codec_from_of(struct device *dev, struct device_node *np, + const char *codec_property_name, + struct snd_soc_dai_link_component *codecs) +{ + struct device_node *np_codec; + + np_codec = of_parse_phandle(np, codec_property_name, 0); + if (!np_codec) { + dev_err(dev, + "Property %s missing or invalid\n", + codec_property_name); + return -EINVAL; + } + + codecs->of_node = np_codec; + return 0; +} + +static int rk_parse_headset_from_of(struct device *dev, struct device_node *np) +{ + rk_98090_headset_dev.dlc.of_node = of_parse_phandle( + np, "rockchip,headset-codec", 0); + if (!rk_98090_headset_dev.dlc.of_node) { + dev_err(dev, + "Property 'rockchip,headset-codec' missing/invalid\n"); + return -EINVAL; + } + return 0; +} + static int snd_rk_mc_probe(struct platform_device *pdev) { int ret = 0; - struct snd_soc_card *card = &snd_soc_card_rk; + struct snd_soc_card *card; + struct device *dev = &pdev->dev; struct device_node *np = pdev->dev.of_node; + struct device_node *np_cpu; + const struct of_device_id *match; + struct rk_card_config *config; + enum rk_snd_usage usage; + + /* Find the config and card to use based on match table. */ + match = of_match_device(dev->driver->of_match_table, dev); + if (!match || !match->data) + return -EINVAL; - /* register the soc card */ - card->dev = &pdev->dev; + config = (struct rk_card_config *)match->data; + card = config->card; + usage = config->usage; + card->dev = dev; - rk_dailink.codecs->of_node = of_parse_phandle(np, - "rockchip,audio-codec", 0); - if (!rk_dailink.codecs->of_node) { + /* Parse DTS for I2S controller. */ + np_cpu = of_parse_phandle(np, "rockchip,i2s-controller", 0); + + if (!np_cpu) { dev_err(&pdev->dev, - "Property 'rockchip,audio-codec' missing or invalid\n"); + "Property 'rockchip,i2s-controller missing or invalid\n"); return -EINVAL; } - rk_dailink.cpus->of_node = of_parse_phandle(np, - "rockchip,i2s-controller", 0); - if (!rk_dailink.cpus->of_node) { - dev_err(&pdev->dev, - "Property 'rockchip,i2s-controller' missing or invalid\n"); - return -EINVAL; + /* Parse DTS for max98090-only card. */ + if (usage == RK_USE_MAX98090) { + ret = rk_parse_codec_from_of(dev, np, "rockchip,audio-codec", + card->dai_link[0].codecs); + if (ret) + return ret; + card->dai_link[0].cpus->of_node = np_cpu; + card->dai_link[0].platforms->of_node = np_cpu; } - rk_dailink.platforms->of_node = rk_dailink.cpus->of_node; + /* Parse DTS for HDMI-only card. */ + if (usage == RK_USE_HDMI) { + ret = rk_parse_codec_from_of(dev, np, "rockchip,hdmi-codec", + card->dai_link[0].codecs); + if (ret) + return ret; + card->dai_link[0].cpus->of_node = np_cpu; + card->dai_link[0].platforms->of_node = np_cpu; + } - rk_98090_headset_dev.dlc.of_node = of_parse_phandle(np, - "rockchip,headset-codec", 0); - if (!rk_98090_headset_dev.dlc.of_node) { - dev_err(&pdev->dev, - "Property 'rockchip,headset-codec' missing/invalid\n"); - return -EINVAL; + /* Parse DTS for max98090 plus HDMI card. */ + if (usage == RK_USE_MAX98090_HDMI) { + ret = rk_parse_codec_from_of( + dev, np, "rockchip,audio-codec", + card->dai_link[DAILINK_MAX98090].codecs); + if (ret) + return ret; + ret = rk_parse_codec_from_of( + dev, np, "rockchip,hdmi-codec", + card->dai_link[DAILINK_HDMI].codecs); + if (ret) + return ret; + card->dai_link[DAILINK_MAX98090].cpus->of_node = np_cpu; + card->dai_link[DAILINK_MAX98090].platforms->of_node = np_cpu; + card->dai_link[DAILINK_HDMI].cpus->of_node = np_cpu; + card->dai_link[DAILINK_HDMI].platforms->of_node = np_cpu; } + /* Parse headset detection codec. */ + if (usage == RK_USE_MAX98090 || usage == RK_USE_MAX98090_HDMI) { + ret = rk_parse_headset_from_of(dev, np); + if (ret) + return ret; + } + + /* Parse card name. */ ret = snd_soc_of_parse_card_name(card, "rockchip,model"); if (ret) { dev_err(&pdev->dev, @@ -252,6 +461,7 @@ static int snd_rk_mc_probe(struct platform_device *pdev) return ret; } + /* register the soc card */ ret = devm_snd_soc_register_card(&pdev->dev, card); if (ret) { dev_err(&pdev->dev, @@ -262,9 +472,34 @@ static int snd_rk_mc_probe(struct platform_device *pdev) return ret; } +struct rk_card_config rk_card_configs[] = { + [RK_USE_MAX98090] = { + .usage = RK_USE_MAX98090, + .card = &rockchip_max98090_card, + }, + [RK_USE_HDMI] = { + .usage = RK_USE_HDMI, + .card = &rockchip_hdmi_card, + }, + [RK_USE_MAX98090_HDMI] = { + .usage = RK_USE_MAX98090_HDMI, + .card = &rockchip_max98090_hdmi_card, + }, +}; + static const struct of_device_id rockchip_max98090_of_match[] = { - { .compatible = "rockchip,rockchip-audio-max98090", }, - {}, + { + .compatible = "rockchip,rockchip-audio-max98090", + .data = &rk_card_configs[RK_USE_MAX98090], + }, + { + .compatible = "rockchip,rockchip-audio-hdmi", + .data = &rk_card_configs[RK_USE_HDMI], + }, + { + .compatible = "rockchip,rockchip-audio-max98090-hdmi", + .data = &rk_card_configs[RK_USE_MAX98090_HDMI], + }, }; MODULE_DEVICE_TABLE(of, rockchip_max98090_of_match); -- 2.24.0.rc0.303.g954a862665-goog