ASoC: Intel: nuvoton-common: support nau8318 amplifier
authorBrent Lu <brent.lu@intel.com>
Fri, 15 Sep 2023 12:48:46 +0000 (20:48 +0800)
committerMark Brown <broonie@kernel.org>
Fri, 15 Sep 2023 13:44:43 +0000 (14:44 +0100)
Implement nau8318 support code in this common module so it could be
shared between multiple SOF machine drivers.

Signed-off-by: Brent Lu <brent.lu@intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20230915124852.1696857-14-yung-chuan.liao@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/boards/Kconfig
sound/soc/intel/boards/Makefile
sound/soc/intel/boards/sof_nuvoton_common.c [new file with mode: 0644]
sound/soc/intel/boards/sof_nuvoton_common.h [new file with mode: 0644]

index 70f8fa939426ef3f8e4cc64faf64d764862897d3..88521bdf59289f5347d77df78b64aef128d36cb0 100644 (file)
@@ -38,6 +38,9 @@ config SND_SOC_INTEL_SOF_REALTEK_COMMON
 config SND_SOC_INTEL_SOF_CIRRUS_COMMON
        tristate
 
+config SND_SOC_INTEL_SOF_NUVOTON_COMMON
+       tristate
+
 config SND_SOC_INTEL_SOF_SSP_COMMON
        tristate
 
index d8a78d7c7a51479ea6746df7d8cb076417d422ef..a7a80d22d66779c7e9690b3e13825603f81e814f 100644 (file)
@@ -96,5 +96,8 @@ obj-$(CONFIG_SND_SOC_INTEL_SOF_REALTEK_COMMON) += snd-soc-intel-sof-realtek-comm
 snd-soc-intel-sof-cirrus-common-objs += sof_cirrus_common.o
 obj-$(CONFIG_SND_SOC_INTEL_SOF_CIRRUS_COMMON) += snd-soc-intel-sof-cirrus-common.o
 
+snd-soc-intel-sof-nuvoton-common-objs += sof_nuvoton_common.o
+obj-$(CONFIG_SND_SOC_INTEL_SOF_NUVOTON_COMMON) += snd-soc-intel-sof-nuvoton-common.o
+
 snd-soc-intel-sof-ssp-common-objs += sof_ssp_common.o
 obj-$(CONFIG_SND_SOC_INTEL_SOF_SSP_COMMON) += snd-soc-intel-sof-ssp-common.o
diff --git a/sound/soc/intel/boards/sof_nuvoton_common.c b/sound/soc/intel/boards/sof_nuvoton_common.c
new file mode 100644 (file)
index 0000000..549a412
--- /dev/null
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * This file defines data structures and functions used in Machine
+ * Driver for Intel platforms with Nuvoton Codecs.
+ *
+ * Copyright 2023 Intel Corporation.
+ */
+#include <linux/module.h>
+#include <sound/sof.h>
+#include "sof_nuvoton_common.h"
+
+/*
+ * Nuvoton NAU8318
+ */
+static const struct snd_kcontrol_new nau8318_kcontrols[] = {
+       SOC_DAPM_PIN_SWITCH("Spk"),
+};
+
+static const struct snd_soc_dapm_widget nau8318_widgets[] = {
+       SND_SOC_DAPM_SPK("Spk", NULL),
+};
+
+static const struct snd_soc_dapm_route nau8318_routes[] = {
+       { "Spk", NULL, "Speaker" },
+};
+
+static struct snd_soc_dai_link_component nau8318_components[] = {
+       {
+               .name = NAU8318_DEV0_NAME,
+               .dai_name = NAU8318_CODEC_DAI,
+       }
+};
+
+static int nau8318_init(struct snd_soc_pcm_runtime *rtd)
+{
+       struct snd_soc_card *card = rtd->card;
+       int ret;
+
+       ret = snd_soc_dapm_new_controls(&card->dapm, nau8318_widgets,
+                                       ARRAY_SIZE(nau8318_widgets));
+       if (ret) {
+               dev_err(rtd->dev, "fail to add nau8318 widgets, ret %d\n", ret);
+               return ret;
+       }
+
+       ret = snd_soc_add_card_controls(card, nau8318_kcontrols,
+                                       ARRAY_SIZE(nau8318_kcontrols));
+       if (ret) {
+               dev_err(rtd->dev, "fail to add nau8318 kcontrols, ret %d\n", ret);
+               return ret;
+       }
+
+       ret = snd_soc_dapm_add_routes(&card->dapm, nau8318_routes,
+                                     ARRAY_SIZE(nau8318_routes));
+
+       if (ret) {
+               dev_err(rtd->dev, "fail to add nau8318 routes, ret %d\n", ret);
+               return ret;
+       }
+
+       return ret;
+}
+
+void nau8318_set_dai_link(struct snd_soc_dai_link *link)
+{
+       link->codecs = nau8318_components;
+       link->num_codecs = ARRAY_SIZE(nau8318_components);
+       link->init = nau8318_init;
+}
+EXPORT_SYMBOL_NS(nau8318_set_dai_link, SND_SOC_INTEL_SOF_NUVOTON_COMMON);
+
+MODULE_DESCRIPTION("ASoC Intel SOF Nuvoton helpers");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/intel/boards/sof_nuvoton_common.h b/sound/soc/intel/boards/sof_nuvoton_common.h
new file mode 100644 (file)
index 0000000..53a84f9
--- /dev/null
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * This file defines data structures used in Machine Driver for Intel
+ * platforms with Nuvoton Codecs.
+ *
+ * Copyright 2023 Intel Corporation.
+ */
+#ifndef __SOF_NUVOTON_COMMON_H
+#define __SOF_NUVOTON_COMMON_H
+
+#include <sound/soc.h>
+#include "sof_ssp_common.h"
+
+/*
+ * Nuvoton NAU8318
+ */
+#define NAU8318_CODEC_DAI      "nau8315-hifi"
+#define NAU8318_DEV0_NAME      "i2c-" NAU8318_ACPI_HID ":00"
+
+void nau8318_set_dai_link(struct snd_soc_dai_link *link);
+
+#endif /* __SOF_NUVOTON_COMMON_H */