ASoC: intel/sdw_utils: move maxim codec helper functions
authorVijendar Mukunda <Vijendar.Mukunda@amd.com>
Thu, 1 Aug 2024 09:14:35 +0000 (14:44 +0530)
committerMark Brown <broonie@kernel.org>
Thu, 1 Aug 2024 11:44:09 +0000 (12:44 +0100)
Move maxim codec helper functions to common place holder so that
it can be used by other platform machine driver.

Link: https://github.com/thesofproject/linux/pull/5068
Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://patch.msgid.link/20240801091446.10457-21-Vijendar.Mukunda@amd.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/soc_sdw_utils.h
sound/soc/intel/boards/Makefile
sound/soc/intel/boards/sof_sdw_common.h
sound/soc/intel/boards/sof_sdw_maxim.c [deleted file]
sound/soc/sdw_utils/Makefile
sound/soc/sdw_utils/soc_sdw_maxim.c [new file with mode: 0644]

index d5dd887b9d151207c02d82eac0c0d64c86aff942..9e84d1ab6cd03d8bcfa26c982c0c185023da6dbb 100644 (file)
@@ -144,6 +144,12 @@ int asoc_sdw_cs_amp_init(struct snd_soc_card *card,
                         struct asoc_sdw_codec_info *info,
                         bool playback);
 
+/* MAXIM codec support */
+int asoc_sdw_maxim_init(struct snd_soc_card *card,
+                       struct snd_soc_dai_link *dai_links,
+                       struct asoc_sdw_codec_info *info,
+                       bool playback);
+
 /* dai_link init callbacks */
 int asoc_sdw_rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
 int asoc_sdw_rt_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
@@ -158,5 +164,6 @@ int asoc_sdw_cs42l43_hs_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc
 int asoc_sdw_cs42l43_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
 int asoc_sdw_cs42l43_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
 int asoc_sdw_cs_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
+int asoc_sdw_maxim_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
 
 #endif
index 1ee903e1224998e7213fab8b9f5a1c1c522c82b4..5bd8dc2d166a6724fc3c76b70655e2053bc5ac81 100644 (file)
@@ -35,7 +35,6 @@ snd-soc-skl_nau88l25_ssm4567-y := skl_nau88l25_ssm4567.o
 snd-soc-ehl-rt5660-y := ehl_rt5660.o
 snd-soc-sof-ssp-amp-y := sof_ssp_amp.o
 snd-soc-sof-sdw-y += sof_sdw.o                         \
-                       sof_sdw_maxim.o                 \
                        sof_sdw_hdmi.o
 obj-$(CONFIG_SND_SOC_INTEL_SOF_RT5682_MACH) += snd-soc-sof_rt5682.o
 obj-$(CONFIG_SND_SOC_INTEL_SOF_CS42L42_MACH) += snd-soc-sof_cs42l42.o
index b95daa32e343f75e0ffe0d9ecc08a7b8fe5b278a..664c3404eb819a773a7dc784414fab3f388b2781 100644 (file)
@@ -77,14 +77,4 @@ int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd);
 
 int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card);
 
-/* MAXIM codec support */
-int asoc_sdw_maxim_init(struct snd_soc_card *card,
-                       struct snd_soc_dai_link *dai_links,
-                       struct asoc_sdw_codec_info *info,
-                       bool playback);
-
-/* dai_link init callbacks */
-
-int asoc_sdw_maxim_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
-
 #endif
diff --git a/sound/soc/intel/boards/sof_sdw_maxim.c b/sound/soc/intel/boards/sof_sdw_maxim.c
deleted file mode 100644 (file)
index 9933224..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-// Copyright (c) 2020 Intel Corporation
-//
-// sof_sdw_maxim - Helpers to handle maxim codecs
-// codec devices from generic machine driver
-
-#include <linux/device.h>
-#include <linux/errno.h>
-#include <sound/control.h>
-#include <sound/soc.h>
-#include <sound/soc-acpi.h>
-#include <sound/soc-dapm.h>
-#include "sof_sdw_common.h"
-
-static int maxim_part_id;
-#define SOC_SDW_PART_ID_MAX98363 0x8363
-#define SOC_SDW_PART_ID_MAX98373 0x8373
-
-static const struct snd_soc_dapm_route max_98373_dapm_routes[] = {
-       { "Left Spk", NULL, "Left BE_OUT" },
-       { "Right Spk", NULL, "Right BE_OUT" },
-};
-
-int asoc_sdw_maxim_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
-{
-       struct snd_soc_card *card = rtd->card;
-       int ret;
-
-       card->components = devm_kasprintf(card->dev, GFP_KERNEL,
-                                         "%s spk:mx%04x",
-                                         card->components, maxim_part_id);
-       if (!card->components)
-               return -ENOMEM;
-
-       dev_dbg(card->dev, "soundwire maxim card components assigned : %s\n",
-               card->components);
-
-       ret = snd_soc_dapm_add_routes(&card->dapm, max_98373_dapm_routes, 2);
-       if (ret)
-               dev_err(rtd->dev, "failed to add first SPK map: %d\n", ret);
-
-       return ret;
-}
-
-static int mx8373_enable_spk_pin(struct snd_pcm_substream *substream, bool enable)
-{
-       struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
-       struct snd_soc_dai *codec_dai;
-       struct snd_soc_dai *cpu_dai;
-       int ret;
-       int j;
-
-       /* set spk pin by playback only */
-       if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
-               return 0;
-
-       cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
-       for_each_rtd_codec_dais(rtd, j, codec_dai) {
-               struct snd_soc_dapm_context *dapm =
-                               snd_soc_component_get_dapm(cpu_dai->component);
-               char pin_name[16];
-
-               snprintf(pin_name, ARRAY_SIZE(pin_name), "%s Spk",
-                        codec_dai->component->name_prefix);
-
-               if (enable)
-                       ret = snd_soc_dapm_enable_pin(dapm, pin_name);
-               else
-                       ret = snd_soc_dapm_disable_pin(dapm, pin_name);
-
-               if (!ret)
-                       snd_soc_dapm_sync(dapm);
-       }
-
-       return 0;
-}
-
-static int asoc_sdw_mx8373_prepare(struct snd_pcm_substream *substream)
-{
-       int ret;
-
-       /* according to soc_pcm_prepare dai link prepare is called first */
-       ret = asoc_sdw_prepare(substream);
-       if (ret < 0)
-               return ret;
-
-       return mx8373_enable_spk_pin(substream, true);
-}
-
-static int asoc_sdw_mx8373_hw_free(struct snd_pcm_substream *substream)
-{
-       int ret;
-
-       /* according to soc_pcm_hw_free dai link free is called first */
-       ret = asoc_sdw_hw_free(substream);
-       if (ret < 0)
-               return ret;
-
-       return mx8373_enable_spk_pin(substream, false);
-}
-
-static const struct snd_soc_ops max_98373_sdw_ops = {
-       .startup = asoc_sdw_startup,
-       .prepare = asoc_sdw_mx8373_prepare,
-       .trigger = asoc_sdw_trigger,
-       .hw_params = asoc_sdw_hw_params,
-       .hw_free = asoc_sdw_mx8373_hw_free,
-       .shutdown = asoc_sdw_shutdown,
-};
-
-static int asoc_sdw_mx8373_sdw_late_probe(struct snd_soc_card *card)
-{
-       struct snd_soc_dapm_context *dapm = &card->dapm;
-
-       /* Disable Left and Right Spk pin after boot */
-       snd_soc_dapm_disable_pin(dapm, "Left Spk");
-       snd_soc_dapm_disable_pin(dapm, "Right Spk");
-       return snd_soc_dapm_sync(dapm);
-}
-
-int asoc_sdw_maxim_init(struct snd_soc_card *card,
-                       struct snd_soc_dai_link *dai_links,
-                       struct asoc_sdw_codec_info *info,
-                       bool playback)
-{
-       info->amp_num++;
-
-       maxim_part_id = info->part_id;
-       switch (maxim_part_id) {
-       case SOC_SDW_PART_ID_MAX98363:
-               /* Default ops are set in function init_dai_link.
-                * called as part of function create_sdw_dailink
-                */
-               break;
-       case SOC_SDW_PART_ID_MAX98373:
-               info->codec_card_late_probe = asoc_sdw_mx8373_sdw_late_probe;
-               dai_links->ops = &max_98373_sdw_ops;
-               break;
-       default:
-               dev_err(card->dev, "Invalid maxim_part_id %#x\n", maxim_part_id);
-               return -EINVAL;
-       }
-       return 0;
-}
index c15b08f3ab0b479af8c1513c71ed64e448b5b6ee..28229ed96ffb5e7695b7a46d6ece7251a80c9473 100644 (file)
@@ -6,5 +6,6 @@ snd-soc-sdw-utils-y := soc_sdw_utils.o soc_sdw_dmic.o soc_sdw_rt_dmic.o \
                       soc_sdw_rt_amp.o                                 \
                       soc_sdw_bridge_cs35l56.o                         \
                       soc_sdw_cs42l42.o soc_sdw_cs42l43.o              \
-                      soc_sdw_cs_amp.o
+                      soc_sdw_cs_amp.o                                 \
+                      soc_sdw_maxim.o
 obj-$(CONFIG_SND_SOC_SDW_UTILS) += snd-soc-sdw-utils.o
diff --git a/sound/soc/sdw_utils/soc_sdw_maxim.c b/sound/soc/sdw_utils/soc_sdw_maxim.c
new file mode 100644 (file)
index 0000000..cdcd8df
--- /dev/null
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// This file incorporates work covered by the following copyright notice:
+// Copyright (c) 2020 Intel Corporation
+// Copyright (c) 2024 Advanced Micro Devices, Inc.
+//
+// soc_sdw_maxim - Helpers to handle maxim codecs
+// codec devices from generic machine driver
+
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <sound/control.h>
+#include <sound/soc.h>
+#include <sound/soc-acpi.h>
+#include <sound/soc-dapm.h>
+#include <sound/soc_sdw_utils.h>
+
+static int maxim_part_id;
+#define SOC_SDW_PART_ID_MAX98363 0x8363
+#define SOC_SDW_PART_ID_MAX98373 0x8373
+
+static const struct snd_soc_dapm_route max_98373_dapm_routes[] = {
+       { "Left Spk", NULL, "Left BE_OUT" },
+       { "Right Spk", NULL, "Right BE_OUT" },
+};
+
+int asoc_sdw_maxim_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
+{
+       struct snd_soc_card *card = rtd->card;
+       int ret;
+
+       card->components = devm_kasprintf(card->dev, GFP_KERNEL,
+                                         "%s spk:mx%04x",
+                                         card->components, maxim_part_id);
+       if (!card->components)
+               return -ENOMEM;
+
+       dev_dbg(card->dev, "soundwire maxim card components assigned : %s\n",
+               card->components);
+
+       ret = snd_soc_dapm_add_routes(&card->dapm, max_98373_dapm_routes, 2);
+       if (ret)
+               dev_err(rtd->dev, "failed to add first SPK map: %d\n", ret);
+
+       return ret;
+}
+EXPORT_SYMBOL_NS(asoc_sdw_maxim_spk_rtd_init, SND_SOC_SDW_UTILS);
+
+static int asoc_sdw_mx8373_enable_spk_pin(struct snd_pcm_substream *substream, bool enable)
+{
+       struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+       struct snd_soc_dai *codec_dai;
+       struct snd_soc_dai *cpu_dai;
+       int ret;
+       int j;
+
+       /* set spk pin by playback only */
+       if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+               return 0;
+
+       cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+       for_each_rtd_codec_dais(rtd, j, codec_dai) {
+               struct snd_soc_dapm_context *dapm =
+                               snd_soc_component_get_dapm(cpu_dai->component);
+               char pin_name[16];
+
+               snprintf(pin_name, ARRAY_SIZE(pin_name), "%s Spk",
+                        codec_dai->component->name_prefix);
+
+               if (enable)
+                       ret = snd_soc_dapm_enable_pin(dapm, pin_name);
+               else
+                       ret = snd_soc_dapm_disable_pin(dapm, pin_name);
+
+               if (!ret)
+                       snd_soc_dapm_sync(dapm);
+       }
+
+       return 0;
+}
+
+static int asoc_sdw_mx8373_prepare(struct snd_pcm_substream *substream)
+{
+       int ret;
+
+       /* according to soc_pcm_prepare dai link prepare is called first */
+       ret = asoc_sdw_prepare(substream);
+       if (ret < 0)
+               return ret;
+
+       return asoc_sdw_mx8373_enable_spk_pin(substream, true);
+}
+
+static int asoc_sdw_mx8373_hw_free(struct snd_pcm_substream *substream)
+{
+       int ret;
+
+       /* according to soc_pcm_hw_free dai link free is called first */
+       ret = asoc_sdw_hw_free(substream);
+       if (ret < 0)
+               return ret;
+
+       return asoc_sdw_mx8373_enable_spk_pin(substream, false);
+}
+
+static const struct snd_soc_ops max_98373_sdw_ops = {
+       .startup = asoc_sdw_startup,
+       .prepare = asoc_sdw_mx8373_prepare,
+       .trigger = asoc_sdw_trigger,
+       .hw_params = asoc_sdw_hw_params,
+       .hw_free = asoc_sdw_mx8373_hw_free,
+       .shutdown = asoc_sdw_shutdown,
+};
+
+static int asoc_sdw_mx8373_sdw_late_probe(struct snd_soc_card *card)
+{
+       struct snd_soc_dapm_context *dapm = &card->dapm;
+
+       /* Disable Left and Right Spk pin after boot */
+       snd_soc_dapm_disable_pin(dapm, "Left Spk");
+       snd_soc_dapm_disable_pin(dapm, "Right Spk");
+       return snd_soc_dapm_sync(dapm);
+}
+
+int asoc_sdw_maxim_init(struct snd_soc_card *card,
+                       struct snd_soc_dai_link *dai_links,
+                       struct asoc_sdw_codec_info *info,
+                       bool playback)
+{
+       info->amp_num++;
+
+       maxim_part_id = info->part_id;
+       switch (maxim_part_id) {
+       case SOC_SDW_PART_ID_MAX98363:
+               /* Default ops are set in function init_dai_link.
+                * called as part of function create_sdw_dailink
+                */
+               break;
+       case SOC_SDW_PART_ID_MAX98373:
+               info->codec_card_late_probe = asoc_sdw_mx8373_sdw_late_probe;
+               dai_links->ops = &max_98373_sdw_ops;
+               break;
+       default:
+               dev_err(card->dev, "Invalid maxim_part_id %#x\n", maxim_part_id);
+               return -EINVAL;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_NS(asoc_sdw_maxim_init, SND_SOC_SDW_UTILS);