In addition, having mixer control to switch between DMICs by
using "dmic-gpios" property.
Refer to this one as an example,
commit b7a742cff3f6 ("ASoC: AMD: Use mixer control to switch between DMICs")
Signed-off-by: Ajye Huang <[email protected]>
---
sound/soc/qcom/sc7180.c | 61 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c
index b391f64c3a80..345489d08886 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>
@@ -28,6 +30,8 @@ struct sc7180_snd_data {
u32 pri_mi2s_clk_count;
struct snd_soc_jack hs_jack;
struct snd_soc_jack hdmi_jack;
+ struct gpio_desc *dmic_sel;
+ int dmic_switch;
};
static void sc7180_jack_free(struct snd_jack *jack)
@@ -169,6 +173,27 @@ 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)
+{
+ struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
+ struct sc7180_snd_data *data = snd_soc_card_get_drvdata(dapm->card);
+
+ ucontrol->value.integer.value[0] = data->dmic_switch;
+ return 0;
+}
+
+static int dmic_set(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
+ struct sc7180_snd_data *data = snd_soc_card_get_drvdata(dapm->card);
+
+ data->dmic_switch = ucontrol->value.integer.value[0];
+ gpiod_set_value(data->dmic_sel, data->dmic_switch);
+ return 0;
+}
+
static void sc7180_snd_shutdown(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
@@ -206,6 +231,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 +287,18 @@ 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_property_read_bool(dev->of_node, "dmic-gpios")) {
+ 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),
+ data->dmic_sel = devm_gpiod_get(&pdev->dev, "dmic", GPIOD_OUT_LOW);
+ if (IS_ERR(data->dmic_sel)) {
+ dev_err(&pdev->dev, "DMIC gpio failed err=%d\n", PTR_ERR(data->dmic_sel));
+ return PTR_ERR(data->dmic_sel);
+ }
+ }
+
ret = qcom_snd_parse_of(card);
if (ret)
return ret;
--
2.25.1
On Tue, Nov 3, 2020 at 10:54 AM Ajye Huang <[email protected]> wrote:
>
> In addition, having mixer control to switch between DMICs by
> using "dmic-gpios" property.
>
> Refer to this one as an example,
> commit b7a742cff3f6 ("ASoC: AMD: Use mixer control to switch between DMICs")
>
> Signed-off-by: Ajye Huang <[email protected]>
LGTM.
Reviewed-by: Tzung-Bi Shih <[email protected]>
Hi Ajye,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on asoc/for-next]
[also build test WARNING on next-20201102]
[cannot apply to linus/master linux/master agross-msm/qcom/for-next v5.10-rc2]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Ajye-Huang/Modify-documentation-and-machine-driver-for-SC7180-sound-card/20201103-105632
base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: arm64-randconfig-r016-20201103 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 1fcd5d5655e29f85e12b402e32974f207cfedf32)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/355751174468ab4d64f549b169b6a9fdba0fbe1e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ajye-Huang/Modify-documentation-and-machine-driver-for-SC7180-sound-card/20201103-105632
git checkout 355751174468ab4d64f549b169b6a9fdba0fbe1e
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
All warnings (new ones prefixed by >>):
>> sound/soc/qcom/sc7180.c:297:53: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
dev_err(&pdev->dev, "DMIC gpio failed err=%d\n", PTR_ERR(data->dmic_sel));
~~ ^~~~~~~~~~~~~~~~~~~~~~~
%ld
include/linux/dev_printk.h:112:32: note: expanded from macro 'dev_err'
_dev_err(dev, dev_fmt(fmt), ##__VA_ARGS__)
~~~ ^~~~~~~~~~~
1 warning generated.
vim +297 sound/soc/qcom/sc7180.c
268
269 static int sc7180_snd_platform_probe(struct platform_device *pdev)
270 {
271 struct snd_soc_card *card;
272 struct sc7180_snd_data *data;
273 struct device *dev = &pdev->dev;
274 int ret;
275
276 /* Allocate the private data */
277 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
278 if (!data)
279 return -ENOMEM;
280
281 card = &data->card;
282 snd_soc_card_set_drvdata(card, data);
283
284 card->owner = THIS_MODULE;
285 card->driver_name = DRIVER_NAME;
286 card->dev = dev;
287 card->dapm_widgets = sc7180_snd_widgets;
288 card->num_dapm_widgets = ARRAY_SIZE(sc7180_snd_widgets);
289
290 if (of_property_read_bool(dev->of_node, "dmic-gpios")) {
291 card->dapm_widgets = sc7180_snd_dual_mic_widgets,
292 card->num_dapm_widgets = ARRAY_SIZE(sc7180_snd_dual_mic_widgets),
293 card->dapm_routes = sc7180_snd_dual_mic_audio_route,
294 card->num_dapm_routes = ARRAY_SIZE(sc7180_snd_dual_mic_audio_route),
295 data->dmic_sel = devm_gpiod_get(&pdev->dev, "dmic", GPIOD_OUT_LOW);
296 if (IS_ERR(data->dmic_sel)) {
> 297 dev_err(&pdev->dev, "DMIC gpio failed err=%d\n", PTR_ERR(data->dmic_sel));
298 return PTR_ERR(data->dmic_sel);
299 }
300 }
301
302 ret = qcom_snd_parse_of(card);
303 if (ret)
304 return ret;
305
306 sc7180_add_ops(card);
307
308 return devm_snd_soc_register_card(dev, card);
309 }
310
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]