summaryrefslogtreecommitdiff
path: root/sound/soc/intel/boards/sof_maxim_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/intel/boards/sof_maxim_common.c')
-rw-r--r--sound/soc/intel/boards/sof_maxim_common.c261
1 files changed, 222 insertions, 39 deletions
diff --git a/sound/soc/intel/boards/sof_maxim_common.c b/sound/soc/intel/boards/sof_maxim_common.c
index cf2974718271..c98a67ae5e66 100644
--- a/sound/soc/intel/boards/sof_maxim_common.c
+++ b/sound/soc/intel/boards/sof_maxim_common.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
//
-// Copyright(c) 2020 Intel Corporation. All rights reserved.
+// Copyright(c) 2020 Intel Corporation
#include <linux/module.h>
#include <linux/string.h>
#include <sound/pcm.h>
@@ -9,9 +9,25 @@
#include <sound/soc-acpi.h>
#include <sound/soc-dai.h>
#include <sound/soc-dapm.h>
+#include <sound/sof.h>
#include <uapi/sound/asound.h>
+#include "../common/soc-intel-quirks.h"
#include "sof_maxim_common.h"
+/*
+ * Common structures and functions
+ */
+static const struct snd_kcontrol_new maxim_2spk_kcontrols[] = {
+ SOC_DAPM_PIN_SWITCH("Left Spk"),
+ SOC_DAPM_PIN_SWITCH("Right Spk"),
+
+};
+
+static const struct snd_soc_dapm_widget maxim_2spk_widgets[] = {
+ SND_SOC_DAPM_SPK("Left Spk", NULL),
+ SND_SOC_DAPM_SPK("Right Spk", NULL),
+};
+
/* helper function to get the number of specific codec */
static unsigned int get_num_codecs(const char *hid)
{
@@ -24,14 +40,16 @@ static unsigned int get_num_codecs(const char *hid)
return dev_num;
}
+/*
+ * Maxim MAX98373
+ */
#define MAX_98373_PIN_NAME 16
-const struct snd_soc_dapm_route max_98373_dapm_routes[] = {
+static const struct snd_soc_dapm_route max_98373_dapm_routes[] = {
/* speaker */
{ "Left Spk", NULL, "Left BE_OUT" },
{ "Right Spk", NULL, "Right BE_OUT" },
};
-EXPORT_SYMBOL_NS(max_98373_dapm_routes, SND_SOC_INTEL_SOF_MAXIM_COMMON);
static struct snd_soc_codec_conf max_98373_codec_conf[] = {
{
@@ -44,7 +62,7 @@ static struct snd_soc_codec_conf max_98373_codec_conf[] = {
},
};
-struct snd_soc_dai_link_component max_98373_components[] = {
+static struct snd_soc_dai_link_component max_98373_components[] = {
{ /* For Right */
.name = MAX_98373_DEV0_NAME,
.dai_name = MAX_98373_CODEC_DAI,
@@ -54,34 +72,122 @@ struct snd_soc_dai_link_component max_98373_components[] = {
.dai_name = MAX_98373_CODEC_DAI,
},
};
-EXPORT_SYMBOL_NS(max_98373_components, SND_SOC_INTEL_SOF_MAXIM_COMMON);
+
+/*
+ * According to the definition of 'DAI Sel Mux' mixer in max98373.c, rx mask
+ * should choose two channels from TDM slots, the LSB of rx mask is left channel
+ * and the other one is right channel.
+ */
+static const struct {
+ unsigned int rx;
+} max_98373_tdm_mask[] = {
+ {.rx = 0x3},
+ {.rx = 0x3},
+};
+
+/*
+ * The tx mask indicates which channel(s) contains output IV-sense data and
+ * others should set to Hi-Z. Here we get the channel number from codec's ACPI
+ * device property "maxim,vmon-slot-no" and "maxim,imon-slot-no" to generate the
+ * mask. Refer to the max98373_slot_config() function in max98373.c codec driver.
+ */
+static unsigned int max_98373_get_tx_mask(struct device *dev)
+{
+ int vmon_slot;
+ int imon_slot;
+
+ if (device_property_read_u32(dev, "maxim,vmon-slot-no", &vmon_slot))
+ vmon_slot = 0;
+
+ if (device_property_read_u32(dev, "maxim,imon-slot-no", &imon_slot))
+ imon_slot = 1;
+
+ dev_dbg(dev, "vmon_slot %d imon_slot %d\n", vmon_slot, imon_slot);
+
+ return (0x1 << vmon_slot) | (0x1 << imon_slot);
+}
static int max_98373_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+ struct snd_soc_dai_link *dai_link = rtd->dai_link;
struct snd_soc_dai *codec_dai;
+ int i;
+ int tdm_slots;
+ unsigned int tx_mask;
+ unsigned int tx_mask_used = 0x0;
int ret = 0;
- int j;
- for_each_rtd_codec_dais(rtd, j, codec_dai) {
- if (!strcmp(codec_dai->component->name, MAX_98373_DEV0_NAME)) {
- /* DEV0 tdm slot configuration */
- ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x03, 3, 8, 32);
- } else if (!strcmp(codec_dai->component->name, MAX_98373_DEV1_NAME)) {
- /* DEV1 tdm slot configuration */
- ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0C, 3, 8, 32);
+ for_each_rtd_codec_dais(rtd, i, codec_dai) {
+ if (i >= ARRAY_SIZE(max_98373_tdm_mask)) {
+ dev_err(codec_dai->dev, "only 2 amps are supported\n");
+ return -EINVAL;
}
- if (ret < 0) {
- dev_err(codec_dai->dev, "fail to set tdm slot, ret %d\n",
- ret);
- return ret;
+
+ switch (dai_link->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+ case SND_SOC_DAIFMT_DSP_A:
+ case SND_SOC_DAIFMT_DSP_B:
+ /* get the tplg configured tdm slot number */
+ tdm_slots = sof_dai_get_tdm_slots(rtd);
+ if (tdm_slots <= 0) {
+ dev_err(rtd->dev, "invalid tdm slots %d\n",
+ tdm_slots);
+ return -EINVAL;
+ }
+
+ /* get the tx mask from ACPI device properties */
+ tx_mask = max_98373_get_tx_mask(codec_dai->dev);
+ if (!tx_mask)
+ return -EINVAL;
+
+ if (tx_mask & tx_mask_used) {
+ dev_err(codec_dai->dev, "invalid tx mask 0x%x, used 0x%x\n",
+ tx_mask, tx_mask_used);
+ return -EINVAL;
+ }
+
+ tx_mask_used |= tx_mask;
+
+ /*
+ * check if tdm slot number is too small for channel
+ * allocation
+ */
+ if (fls(tx_mask) > tdm_slots) {
+ dev_err(codec_dai->dev, "slot mismatch, tx %d slots %d\n",
+ fls(tx_mask), tdm_slots);
+ return -EINVAL;
+ }
+
+ if (fls(max_98373_tdm_mask[i].rx) > tdm_slots) {
+ dev_err(codec_dai->dev, "slot mismatch, rx %d slots %d\n",
+ fls(max_98373_tdm_mask[i].rx), tdm_slots);
+ return -EINVAL;
+ }
+
+ dev_dbg(codec_dai->dev, "set tdm slot: tx 0x%x rx 0x%x slots %d width %d\n",
+ tx_mask, max_98373_tdm_mask[i].rx,
+ tdm_slots, params_width(params));
+
+ ret = snd_soc_dai_set_tdm_slot(codec_dai, tx_mask,
+ max_98373_tdm_mask[i].rx,
+ tdm_slots,
+ params_width(params));
+ if (ret < 0) {
+ dev_err(codec_dai->dev, "fail to set tdm slot, ret %d\n",
+ ret);
+ return ret;
+ }
+ break;
+ default:
+ dev_dbg(codec_dai->dev, "codec is in I2S mode\n");
+ break;
}
}
return 0;
}
-int max_98373_trigger(struct snd_pcm_substream *substream, int cmd)
+static int max_98373_trigger(struct snd_pcm_substream *substream, int cmd)
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct snd_soc_dai *codec_dai;
@@ -124,33 +230,67 @@ int max_98373_trigger(struct snd_pcm_substream *substream, int cmd)
return ret;
}
-EXPORT_SYMBOL_NS(max_98373_trigger, SND_SOC_INTEL_SOF_MAXIM_COMMON);
-struct snd_soc_ops max_98373_ops = {
+static const struct snd_soc_ops max_98373_ops = {
.hw_params = max_98373_hw_params,
.trigger = max_98373_trigger,
};
-EXPORT_SYMBOL_NS(max_98373_ops, SND_SOC_INTEL_SOF_MAXIM_COMMON);
-int max_98373_spk_codec_init(struct snd_soc_pcm_runtime *rtd)
+static int max_98373_spk_codec_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_card *card = rtd->card;
+ unsigned int num_codecs = get_num_codecs(MAX_98373_ACPI_HID);
int ret;
- ret = snd_soc_dapm_add_routes(&card->dapm, max_98373_dapm_routes,
- ARRAY_SIZE(max_98373_dapm_routes));
- if (ret)
- dev_err(rtd->dev, "Speaker map addition failed: %d\n", ret);
+ switch (num_codecs) {
+ case 2:
+ ret = snd_soc_dapm_new_controls(&card->dapm, maxim_2spk_widgets,
+ ARRAY_SIZE(maxim_2spk_widgets));
+ if (ret) {
+ dev_err(rtd->dev, "fail to add max98373 widgets, ret %d\n",
+ ret);
+ return ret;
+ }
+
+ ret = snd_soc_add_card_controls(card, maxim_2spk_kcontrols,
+ ARRAY_SIZE(maxim_2spk_kcontrols));
+ if (ret) {
+ dev_err(rtd->dev, "fail to add max98373 kcontrols, ret %d\n",
+ ret);
+ return ret;
+ }
+
+ ret = snd_soc_dapm_add_routes(&card->dapm, max_98373_dapm_routes,
+ ARRAY_SIZE(max_98373_dapm_routes));
+ if (ret) {
+ dev_err(rtd->dev, "fail to add max98373 routes, ret %d\n",
+ ret);
+ return ret;
+ }
+ break;
+ default:
+ dev_err(rtd->dev, "max98373: invalid num_codecs %d\n", num_codecs);
+ return -EINVAL;
+ }
+
return ret;
}
-EXPORT_SYMBOL_NS(max_98373_spk_codec_init, SND_SOC_INTEL_SOF_MAXIM_COMMON);
+
+void max_98373_dai_link(struct device *dev, struct snd_soc_dai_link *link)
+{
+ link->codecs = max_98373_components;
+ link->num_codecs = ARRAY_SIZE(max_98373_components);
+ link->init = max_98373_spk_codec_init;
+ link->ops = &max_98373_ops;
+}
+EXPORT_SYMBOL_NS(max_98373_dai_link, "SND_SOC_INTEL_SOF_MAXIM_COMMON");
void max_98373_set_codec_conf(struct snd_soc_card *card)
{
card->codec_conf = max_98373_codec_conf;
card->num_configs = ARRAY_SIZE(max_98373_codec_conf);
}
-EXPORT_SYMBOL_NS(max_98373_set_codec_conf, SND_SOC_INTEL_SOF_MAXIM_COMMON);
+EXPORT_SYMBOL_NS(max_98373_set_codec_conf, "SND_SOC_INTEL_SOF_MAXIM_COMMON");
/*
* Maxim MAX98390
@@ -177,6 +317,17 @@ static const struct snd_soc_dapm_route max_98390_tt_dapm_routes[] = {
{ "TR Spk", NULL, "Tweeter Right BE_OUT" },
};
+static struct snd_soc_codec_conf max_98390_cml_codec_conf[] = {
+ {
+ .dlc = COMP_CODEC_CONF(MAX_98390_DEV0_NAME),
+ .name_prefix = "Left",
+ },
+ {
+ .dlc = COMP_CODEC_CONF(MAX_98390_DEV1_NAME),
+ .name_prefix = "Right",
+ },
+};
+
static struct snd_soc_codec_conf max_98390_codec_conf[] = {
{
.dlc = COMP_CODEC_CONF(MAX_98390_DEV0_NAME),
@@ -229,6 +380,7 @@ static int max_98390_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+ struct snd_soc_dai_link *dai_link = rtd->dai_link;
struct snd_soc_dai *codec_dai;
int i, ret;
@@ -238,13 +390,24 @@ static int max_98390_hw_params(struct snd_pcm_substream *substream,
return -ENODEV;
}
- ret = snd_soc_dai_set_tdm_slot(codec_dai, max_98390_tdm_mask[i].tx,
- max_98390_tdm_mask[i].rx, 4,
- params_width(params));
- if (ret < 0) {
- dev_err(codec_dai->dev, "fail to set tdm slot, ret %d\n",
- ret);
- return ret;
+ switch (dai_link->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+ case SND_SOC_DAIFMT_DSP_A:
+ case SND_SOC_DAIFMT_DSP_B:
+ /* 4-slot TDM */
+ ret = snd_soc_dai_set_tdm_slot(codec_dai,
+ max_98390_tdm_mask[i].tx,
+ max_98390_tdm_mask[i].rx,
+ 4,
+ params_width(params));
+ if (ret < 0) {
+ dev_err(codec_dai->dev, "fail to set tdm slot, ret %d\n",
+ ret);
+ return ret;
+ }
+ break;
+ default:
+ dev_dbg(codec_dai->dev, "codec is in I2S mode\n");
+ break;
}
}
return 0;
@@ -287,6 +450,22 @@ static int max_98390_init(struct snd_soc_pcm_runtime *rtd)
fallthrough;
case 2:
/* add regular speakers dapm route */
+ ret = snd_soc_dapm_new_controls(&card->dapm, maxim_2spk_widgets,
+ ARRAY_SIZE(maxim_2spk_widgets));
+ if (ret) {
+ dev_err(rtd->dev, "fail to add max98390 woofer widgets, ret %d\n",
+ ret);
+ return ret;
+ }
+
+ ret = snd_soc_add_card_controls(card, maxim_2spk_kcontrols,
+ ARRAY_SIZE(maxim_2spk_kcontrols));
+ if (ret) {
+ dev_err(rtd->dev, "fail to add max98390 woofer kcontrols, ret %d\n",
+ ret);
+ return ret;
+ }
+
ret = snd_soc_dapm_add_routes(&card->dapm, max_98390_dapm_routes,
ARRAY_SIZE(max_98390_dapm_routes));
if (ret) {
@@ -327,7 +506,7 @@ void max_98390_dai_link(struct device *dev, struct snd_soc_dai_link *link)
link->init = max_98390_init;
link->ops = &max_98390_ops;
}
-EXPORT_SYMBOL_NS(max_98390_dai_link, SND_SOC_INTEL_SOF_MAXIM_COMMON);
+EXPORT_SYMBOL_NS(max_98390_dai_link, "SND_SOC_INTEL_SOF_MAXIM_COMMON");
void max_98390_set_codec_conf(struct device *dev, struct snd_soc_card *card)
{
@@ -337,6 +516,10 @@ void max_98390_set_codec_conf(struct device *dev, struct snd_soc_card *card)
switch (num_codecs) {
case 2:
+ if (soc_intel_is_cml())
+ card->codec_conf = max_98390_cml_codec_conf;
+
+ fallthrough;
case 4:
card->num_configs = num_codecs;
break;
@@ -346,7 +529,7 @@ void max_98390_set_codec_conf(struct device *dev, struct snd_soc_card *card)
break;
}
}
-EXPORT_SYMBOL_NS(max_98390_set_codec_conf, SND_SOC_INTEL_SOF_MAXIM_COMMON);
+EXPORT_SYMBOL_NS(max_98390_set_codec_conf, "SND_SOC_INTEL_SOF_MAXIM_COMMON");
/*
* Maxim MAX98357A/MAX98360A
@@ -413,7 +596,7 @@ void max_98357a_dai_link(struct snd_soc_dai_link *link)
link->num_codecs = ARRAY_SIZE(max_98357a_components);
link->init = max_98357a_init;
}
-EXPORT_SYMBOL_NS(max_98357a_dai_link, SND_SOC_INTEL_SOF_MAXIM_COMMON);
+EXPORT_SYMBOL_NS(max_98357a_dai_link, "SND_SOC_INTEL_SOF_MAXIM_COMMON");
void max_98360a_dai_link(struct snd_soc_dai_link *link)
{
@@ -421,7 +604,7 @@ void max_98360a_dai_link(struct snd_soc_dai_link *link)
link->num_codecs = ARRAY_SIZE(max_98360a_components);
link->init = max_98357a_init;
}
-EXPORT_SYMBOL_NS(max_98360a_dai_link, SND_SOC_INTEL_SOF_MAXIM_COMMON);
+EXPORT_SYMBOL_NS(max_98360a_dai_link, "SND_SOC_INTEL_SOF_MAXIM_COMMON");
MODULE_DESCRIPTION("ASoC Intel SOF Maxim helpers");
MODULE_LICENSE("GPL");