From: Ajye Huang <ajye.huang@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: dianders@chromium.org, devicetree@vger.kernel.org,
alsa-devel@alsa-project.org,
Banajit Goswami <bgoswami@codeaurora.org>,
Srinivasa Rao Mandadapu <srivasam@codeaurora.org>,
Liam Girdwood <lgirdwood@gmail.com>,
linux-arm-msm@vger.kernel.org, Patrick Lai <plai@codeaurora.org>,
Ajye Huang <ajye_huang@compal.corp-partner.google.com>,
Andy Gross <agross@kernel.org>, Rob Herring <robh+dt@kernel.org>,
Bjorn Andersson <bjorn.andersson@linaro.org>,
Mark Brown <broonie@kernel.org>,
Rohit kumar <rohitkr@codeaurora.org>,
tzungbi@chromium.org, linux-arm-kernel@lists.infradead.org,
cychiang@chromium.org
Subject: [PATCH v1 2/2] ASoC: qcom: sc7180: Modify machine driver for 2mic
Date: Mon, 28 Sep 2020 14:37:44 +0800 [thread overview]
Message-ID: <20200928063744.525700-3-ajye_huang@compal.corp-partner.google.com> (raw)
In-Reply-To: <20200928063744.525700-1-ajye_huang@compal.corp-partner.google.com>
In addition, having mixer control to switch between DMICs for
"qcom,sc7180-sndcard-rt5682-m98357-2mic" 2mic case.
Refer to this one as an example,
commit b7a742cff3f6 ("ASoC: AMD: Use mixer control to switch between DMICs")
Signed-off-by: Ajye Huang <ajye_huang@compal.corp-partner.google.com>
---
This patch depends on this patch series
https://patchwork.kernel.org/patch/11773223/ .
sound/soc/qcom/sc7180.c | 60 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
index 0e90448523b0..c8751fb9f9bf 100644
--- a/sound/soc/qcom/sc7180.c
+++ b/sound/soc/qcom/sc7180.c
@@ -5,6 +5,8 @@
// sc7180.c -- ALSA SoC Machine driver for SC7180
#include <dt-bindings/sound/sc7180-lpass.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
@@ -24,6 +26,9 @@
// This will be defined in include/dt-bindings/sound/sc7180-lpass.h
#define LPASS_DP_RX 2
+static struct gpio_desc *dmic_sel;
+static int dmic_switch;
+
struct sc7180_snd_data {
struct snd_soc_card card;
u32 pri_mi2s_clk_count;
@@ -170,6 +175,23 @@ static int sc7180_snd_startup(struct snd_pcm_substream *substream)
return 0;
}
+static int dmic_get(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = dmic_switch;
+ return 0;
+}
+
+static int dmic_set(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ if (dmic_sel) {
+ dmic_switch = ucontrol->value.integer.value[0];
+ gpiod_set_value(dmic_sel, dmic_switch);
+ }
+ return 0;
+}
+
static void sc7180_snd_shutdown(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
@@ -207,6 +229,30 @@ static const struct snd_soc_dapm_widget sc7180_snd_widgets[] = {
SND_SOC_DAPM_MIC("Headset Mic", NULL),
};
+static const char * const dmic_mux_text[] = {
+ "Front Mic",
+ "Rear Mic",
+};
+
+static SOC_ENUM_SINGLE_DECL(sc7180_dmic_enum,
+ SND_SOC_NOPM, 0, dmic_mux_text);
+
+static const struct snd_kcontrol_new sc7180_dmic_mux_control =
+ SOC_DAPM_ENUM_EXT("DMIC Select Mux", sc7180_dmic_enum,
+ dmic_get, dmic_set);
+
+static const struct snd_soc_dapm_widget sc7180_snd_dual_mic_widgets[] = {
+ SND_SOC_DAPM_HP("Headphone Jack", NULL),
+ SND_SOC_DAPM_MIC("Headset Mic", NULL),
+ SND_SOC_DAPM_MIC("DMIC", NULL),
+ SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0, &sc7180_dmic_mux_control),
+};
+
+static const struct snd_soc_dapm_route sc7180_snd_dual_mic_audio_route[] = {
+ {"Dmic Mux", "Front Mic", "DMIC"},
+ {"Dmic Mux", "Rear Mic", "DMIC"},
+};
+
static void sc7180_add_ops(struct snd_soc_card *card)
{
struct snd_soc_dai_link *link;
@@ -238,6 +284,19 @@ static int sc7180_snd_platform_probe(struct platform_device *pdev)
card->dapm_widgets = sc7180_snd_widgets;
card->num_dapm_widgets = ARRAY_SIZE(sc7180_snd_widgets);
+ if (of_device_is_compatible(dev->of_node, "qcom,sc7180-sndcard-rt5682-m98357-2mic")) {
+ card->dapm_widgets = sc7180_snd_dual_mic_widgets,
+ card->num_dapm_widgets = ARRAY_SIZE(sc7180_snd_dual_mic_widgets),
+ card->dapm_routes = sc7180_snd_dual_mic_audio_route,
+ card->num_dapm_routes = ARRAY_SIZE(sc7180_snd_dual_mic_audio_route),
+ dmic_sel = devm_gpiod_get(&pdev->dev, "dmic", GPIOD_OUT_LOW);
+ if (IS_ERR(dmic_sel)) {
+ dev_err(&pdev->dev, "DMIC gpio failed err=%d\n",
+ PTR_ERR(dmic_sel));
+ return PTR_ERR(dmic_sel);
+ }
+ }
+
ret = qcom_snd_parse_of(card);
if (ret)
return ret;
@@ -249,6 +308,7 @@ static int sc7180_snd_platform_probe(struct platform_device *pdev)
static const struct of_device_id sc7180_snd_device_id[] = {
{ .compatible = "qcom,sc7180-sndcard-rt5682-m98357-1mic" },
+ { .compatible = "qcom,sc7180-sndcard-rt5682-m98357-2mic" },
{},
};
MODULE_DEVICE_TABLE(of, sc7180_snd_device_id);
--
2.25.1
next prev parent reply other threads:[~2020-10-01 13:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-28 6:37 [PATCH v1 0/2] Modify documentation and machine driver for SC7180 sound card Ajye Huang
2020-09-28 6:37 ` [PATCH v1 1/2] ASoC: qcom: dt-bindings: Modify sc7180 machine bindings Ajye Huang
2020-09-29 19:41 ` Rob Herring
2020-10-09 13:52 ` Mark Brown
2020-10-09 16:07 ` Ajye Huang
2020-10-12 13:50 ` Mark Brown
2020-10-15 13:46 ` Ajye Huang
2020-09-28 6:37 ` Ajye Huang [this message]
2020-11-10 16:02 ` [PATCH v1 0/2] Modify documentation and machine driver for SC7180 sound card Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200928063744.525700-3-ajye_huang@compal.corp-partner.google.com \
--to=ajye.huang@gmail.com \
--cc=agross@kernel.org \
--cc=ajye_huang@compal.corp-partner.google.com \
--cc=alsa-devel@alsa-project.org \
--cc=bgoswami@codeaurora.org \
--cc=bjorn.andersson@linaro.org \
--cc=broonie@kernel.org \
--cc=cychiang@chromium.org \
--cc=devicetree@vger.kernel.org \
--cc=dianders@chromium.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=plai@codeaurora.org \
--cc=robh+dt@kernel.org \
--cc=rohitkr@codeaurora.org \
--cc=srivasam@codeaurora.org \
--cc=tzungbi@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).