Commit 95504218 authored by Hans de Goede's avatar Hans de Goede Committed by Mark Brown

ASoC: Intel: bytcr_wm5102: Add BYT_WM5102_SSP2 quirk

Add the standard intel board file quirk mechanism also used in many
other intel board drivers and add a BYT_WM5102_SSP2 quirk setting
for designs using SSP2 instead of SSP0.

And enable the new BYT_WM5102_SSP2 quirk on Cherry Trail devices
since those always use SSP2.

The logging of the quirks uses dev_info_once() because probe() may run
multiple times because of snd_soc_register_card() returning -EPROBE_DEFER.
Acked-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20231025143513.291753-2-hdegoede@redhat.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 109cb216
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/platform_data/x86/soc.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
...@@ -37,6 +38,21 @@ struct byt_wm5102_private { ...@@ -37,6 +38,21 @@ struct byt_wm5102_private {
struct gpio_desc *spkvdd_en_gpio; struct gpio_desc *spkvdd_en_gpio;
}; };
/* Bits 0-15 are reserved for things like an input-map */
#define BYT_WM5102_SSP2 BIT(16)
static unsigned long quirk;
static int quirk_override = -1;
module_param_named(quirk, quirk_override, int, 0444);
MODULE_PARM_DESC(quirk, "Board-specific quirk override");
static void log_quirks(struct device *dev)
{
if (quirk & BYT_WM5102_SSP2)
dev_info_once(dev, "quirk SSP2 enabled");
}
static int byt_wm5102_spkvdd_power_event(struct snd_soc_dapm_widget *w, static int byt_wm5102_spkvdd_power_event(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event) struct snd_kcontrol *kcontrol, int event)
{ {
...@@ -166,14 +182,24 @@ static const struct snd_soc_dapm_route byt_wm5102_audio_map[] = { ...@@ -166,14 +182,24 @@ static const struct snd_soc_dapm_route byt_wm5102_audio_map[] = {
{"Headset Mic", NULL, "MICBIAS1"}, {"Headset Mic", NULL, "MICBIAS1"},
{"Headset Mic", NULL, "MICBIAS2"}, {"Headset Mic", NULL, "MICBIAS2"},
{"IN1L", NULL, "Headset Mic"}, {"IN1L", NULL, "Headset Mic"},
};
static const struct snd_soc_dapm_route bytcr_wm5102_ssp0_map[] = {
{"AIF1 Playback", NULL, "ssp0 Tx"}, {"AIF1 Playback", NULL, "ssp0 Tx"},
{"ssp0 Tx", NULL, "modem_out"}, {"ssp0 Tx", NULL, "modem_out"},
{"modem_in", NULL, "ssp0 Rx"}, {"modem_in", NULL, "ssp0 Rx"},
{"ssp0 Rx", NULL, "AIF1 Capture"}, {"ssp0 Rx", NULL, "AIF1 Capture"},
}; };
static const struct snd_soc_dapm_route bytcr_wm5102_ssp2_map[] = {
{"AIF1 Playback", NULL, "ssp2 Tx"},
{"ssp2 Tx", NULL, "codec_out0"},
{"ssp2 Tx", NULL, "codec_out1"},
{"codec_in0", NULL, "ssp2 Rx"},
{"codec_in1", NULL, "ssp2 Rx"},
{"ssp2 Rx", NULL, "AIF1 Capture"},
};
static const struct snd_kcontrol_new byt_wm5102_controls[] = { static const struct snd_kcontrol_new byt_wm5102_controls[] = {
SOC_DAPM_PIN_SWITCH("Headphone"), SOC_DAPM_PIN_SWITCH("Headphone"),
SOC_DAPM_PIN_SWITCH("Headset Mic"), SOC_DAPM_PIN_SWITCH("Headset Mic"),
...@@ -202,7 +228,8 @@ static int byt_wm5102_init(struct snd_soc_pcm_runtime *runtime) ...@@ -202,7 +228,8 @@ static int byt_wm5102_init(struct snd_soc_pcm_runtime *runtime)
struct snd_soc_card *card = runtime->card; struct snd_soc_card *card = runtime->card;
struct byt_wm5102_private *priv = snd_soc_card_get_drvdata(card); struct byt_wm5102_private *priv = snd_soc_card_get_drvdata(card);
struct snd_soc_component *component = snd_soc_rtd_to_codec(runtime, 0)->component; struct snd_soc_component *component = snd_soc_rtd_to_codec(runtime, 0)->component;
int ret, jack_type; const struct snd_soc_dapm_route *custom_map = NULL;
int ret, jack_type, num_routes = 0;
card->dapm.idle_bias_off = true; card->dapm.idle_bias_off = true;
...@@ -213,6 +240,17 @@ static int byt_wm5102_init(struct snd_soc_pcm_runtime *runtime) ...@@ -213,6 +240,17 @@ static int byt_wm5102_init(struct snd_soc_pcm_runtime *runtime)
return ret; return ret;
} }
if (quirk & BYT_WM5102_SSP2) {
custom_map = bytcr_wm5102_ssp2_map;
num_routes = ARRAY_SIZE(bytcr_wm5102_ssp2_map);
} else {
custom_map = bytcr_wm5102_ssp0_map;
num_routes = ARRAY_SIZE(bytcr_wm5102_ssp0_map);
}
ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
if (ret)
return ret;
/* /*
* The firmware might enable the clock at boot (this information * The firmware might enable the clock at boot (this information
* may or may not be reflected in the enable clock register). * may or may not be reflected in the enable clock register).
...@@ -253,7 +291,7 @@ static int byt_wm5102_codec_fixup(struct snd_soc_pcm_runtime *rtd, ...@@ -253,7 +291,7 @@ static int byt_wm5102_codec_fixup(struct snd_soc_pcm_runtime *rtd,
SNDRV_PCM_HW_PARAM_RATE); SNDRV_PCM_HW_PARAM_RATE);
struct snd_interval *channels = hw_param_interval(params, struct snd_interval *channels = hw_param_interval(params,
SNDRV_PCM_HW_PARAM_CHANNELS); SNDRV_PCM_HW_PARAM_CHANNELS);
int ret; int ret, bits;
/* The DSP will convert the FE rate to 48k, stereo */ /* The DSP will convert the FE rate to 48k, stereo */
rate->min = 48000; rate->min = 48000;
...@@ -261,8 +299,15 @@ static int byt_wm5102_codec_fixup(struct snd_soc_pcm_runtime *rtd, ...@@ -261,8 +299,15 @@ static int byt_wm5102_codec_fixup(struct snd_soc_pcm_runtime *rtd,
channels->min = 2; channels->min = 2;
channels->max = 2; channels->max = 2;
/* set SSP0 to 16-bit */ if (quirk & BYT_WM5102_SSP2) {
params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); /* set SSP2 to 24-bit */
params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
bits = 24;
} else {
/* set SSP0 to 16-bit */
params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
bits = 16;
}
/* /*
* Default mode for SSP configuration is TDM 4 slot, override config * Default mode for SSP configuration is TDM 4 slot, override config
...@@ -278,7 +323,7 @@ static int byt_wm5102_codec_fixup(struct snd_soc_pcm_runtime *rtd, ...@@ -278,7 +323,7 @@ static int byt_wm5102_codec_fixup(struct snd_soc_pcm_runtime *rtd,
return ret; return ret;
} }
ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, 16); ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);
if (ret) { if (ret) {
dev_err(rtd->dev, "Error setting I2S config: %d\n", ret); dev_err(rtd->dev, "Error setting I2S config: %d\n", ret);
return ret; return ret;
...@@ -345,12 +390,9 @@ static struct snd_soc_dai_link byt_wm5102_dais[] = { ...@@ -345,12 +390,9 @@ static struct snd_soc_dai_link byt_wm5102_dais[] = {
/* back ends */ /* back ends */
{ {
/* /*
* This must be named SSP2-Codec even though this machine driver * This dailink is updated dynamically to point to SSP0 or SSP2.
* always uses SSP0. Most machine drivers support both and dynamically * Yet its name is always kept as "SSP2-Codec" because the SOF
* update the dailink to point to SSP0 or SSP2, while keeping the name * tplg files hardcode "SSP2-Codec" even in byt-foo-ssp0.tplg.
* as "SSP2-Codec". The SOF tplg files hardcode the "SSP2-Codec" even
* in the byt-foo-ssp0.tplg versions because the other machine-drivers
* use "SSP2-Codec" even when SSP0 is used.
*/ */
.name = "SSP2-Codec", .name = "SSP2-Codec",
.id = 0, .id = 0,
...@@ -393,8 +435,9 @@ static int snd_byt_wm5102_mc_probe(struct platform_device *pdev) ...@@ -393,8 +435,9 @@ static int snd_byt_wm5102_mc_probe(struct platform_device *pdev)
const char *platform_name; const char *platform_name;
struct acpi_device *adev; struct acpi_device *adev;
struct device *codec_dev; struct device *codec_dev;
int dai_index = 0;
bool sof_parent; bool sof_parent;
int ret; int i, ret;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
...@@ -441,6 +484,26 @@ static int snd_byt_wm5102_mc_probe(struct platform_device *pdev) ...@@ -441,6 +484,26 @@ static int snd_byt_wm5102_mc_probe(struct platform_device *pdev)
return dev_err_probe(dev, ret, "getting spkvdd-GPIO\n"); return dev_err_probe(dev, ret, "getting spkvdd-GPIO\n");
} }
if (soc_intel_is_cht()) {
/* On CHT default to SSP2 */
quirk = BYT_WM5102_SSP2;
}
if (quirk_override != -1) {
dev_info_once(dev, "Overriding quirk 0x%lx => 0x%x\n",
quirk, quirk_override);
quirk = quirk_override;
}
log_quirks(dev);
/* find index of codec dai */
for (i = 0; i < ARRAY_SIZE(byt_wm5102_dais); i++) {
if (!strcmp(byt_wm5102_dais[i].codecs->name,
"wm5102-codec")) {
dai_index = i;
break;
}
}
/* override platform name, if required */ /* override platform name, if required */
byt_wm5102_card.dev = dev; byt_wm5102_card.dev = dev;
platform_name = mach->mach_params.platform; platform_name = mach->mach_params.platform;
...@@ -448,6 +511,10 @@ static int snd_byt_wm5102_mc_probe(struct platform_device *pdev) ...@@ -448,6 +511,10 @@ static int snd_byt_wm5102_mc_probe(struct platform_device *pdev)
if (ret) if (ret)
goto out_put_gpio; goto out_put_gpio;
/* override SSP port, if required */
if (quirk & BYT_WM5102_SSP2)
byt_wm5102_dais[dai_index].cpus->dai_name = "ssp2-port";
/* set card and driver name and pm-ops */ /* set card and driver name and pm-ops */
sof_parent = snd_soc_acpi_sof_parent(dev); sof_parent = snd_soc_acpi_sof_parent(dev);
if (sof_parent) { if (sof_parent) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment