From ba5fcc25b726559cb36d61196c58c865190a8a7b Mon Sep 17 00:00:00 2001 From c0c65da7ca4b0a4f93272f5e932dd7eed90703c8 Mon Sep 17 00:00:00 2001 From: Ethan Geller Date: Thu, 16 Nov 2023 21:31:48 +0000 Subject: [PATCH] Fix for Max98388 issue where speakers would not be powered on when we resume from S3. The issue was that when we flush the regmap to the amp on resume, we were also flushing a value of 1 to the SW_RESET pin. Theoretically, this is fixed by marking the SW_RESET register volatile. However, we did not observe a fix after marking the register volatile, so we opted for a more complete fix of ensuring SW_RESET is zero in our regmap after we have waited for the reset loop to be complete. --- sound/soc/codecs/max98388.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/max98388.c b/sound/soc/codecs/max98388.c index 293ec172e0a71..4c495e0e33f90 100644 --- a/sound/soc/codecs/max98388.c +++ b/sound/soc/codecs/max98388.c @@ -391,27 +391,43 @@ void max98388_reset(struct max98388_priv *max98388, struct device *dev) { int ret, reg, count; + /* Software Reset */ ret = regmap_update_bits(max98388->regmap, MAX98388_R2000_SW_RESET, MAX98388_SOFT_RESET, MAX98388_SOFT_RESET); - if (ret) + + if (ret) { dev_err(dev, "Reset command failed. (ret:%d)\n", ret); + goto exit; + } + count = 0; while (count < 3) { usleep_range(10000, 11000); + /* Software Reset Verification */ ret = regmap_read(max98388->regmap, MAX98388_R22FF_REV_ID, ®); + if (!ret) { dev_info(dev, "Reset completed (retry:%d)\n", count); - return; + goto exit; } count++; } + dev_err(dev, "Reset failed. (ret:%d)\n", ret); + + +exit: + regcache_cache_only(max98388->regmap, true); + ret = regmap_update_bits(max98388->regmap, + MAX98388_R2000_SW_RESET, + MAX98388_SOFT_RESET, 0); + regcache_cache_only(max98388->regmap, false); } static int max98388_probe(struct snd_soc_component *component) @@ -420,6 +436,7 @@ static int max98388_probe(struct snd_soc_component *component) /* Software Reset */ max98388_reset(max98388, component->dev); + usleep_range(400, 1000); /* General channel source configuration */ regmap_write(max98388->regmap, @@ -812,6 +829,7 @@ static bool max98388_readable_register(struct device *dev, case MAX98388_R210E_AUTO_RESTART: case MAX98388_R210F_GLOBAL_EN: case MAX98388_R22FF_REV_ID: + case MAX98388_R2000_SW_RESET: return true; default: return false; @@ -824,6 +842,7 @@ static bool max98388_volatile_reg(struct device *dev, unsigned int reg) case MAX98388_R2001_INT_RAW1 ... MAX98388_R2005_INT_STATE2: case MAX98388_R210F_GLOBAL_EN: case MAX98388_R22FF_REV_ID: + case MAX98388_R2000_SW_RESET: return true; default: return false; @@ -868,6 +887,7 @@ static int max98388_resume(struct device *dev) regcache_cache_only(max98388->regmap, false); max98388_reset(max98388, dev); + usleep_range(400, 1000); regcache_sync(max98388->regmap); return 0; -- GitLab diff --git a/sound/soc/amd/acp/acp-mach-common.c b/sound/soc/amd/acp/acp-mach-common.c index 504d1b8c4..3411e8d9a 100644 --- a/sound/soc/amd/acp/acp-mach-common.c +++ b/sound/soc/amd/acp/acp-mach-common.c @@ -26,6 +26,7 @@ #include "../../codecs/rt5682s.h" #include "../../codecs/nau8825.h" #include "../../codecs/nau8821.h" +#include "../../codecs/cs35l41.h" #include "acp-mach.h" #define PCO_PLAT_CLK 48000000 @@ -1282,6 +1283,78 @@ SND_SOC_DAILINK_DEF(nau8821, DAILINK_COMP_ARRAY(COMP_CODEC("i2c-NVTN2020:00", "nau8821-hifi"))); +static int acp_cs35l41_init(struct snd_soc_pcm_runtime *rtd) +{ + return 0; +} + +static int acp_cs35l41_startup(struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + + runtime->hw.channels_max = DUAL_CHANNEL; + snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, + &constraints_channels); + snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, + &constraints_rates); + return 0; +} + +static int acp_cs35l41_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_card *card = rtd->card; + struct snd_soc_dai *codec_dai; + int ret, i; + unsigned int num_codecs = rtd->dai_link->num_codecs; + unsigned int bclk_val; + + ret = 0; + for (i = 0; i < num_codecs; i++) { + codec_dai = snd_soc_rtd_to_codec(rtd, i); + if (strcmp(codec_dai->name, "cs35l41-pcm") == 0) { + switch (params_rate(params)) { + case 48000: + bclk_val = 1536000; + break; + default: + dev_err(card->dev, "Invalid Samplerate:0x%x\n", + params_rate(params)); + return -EINVAL; + } + ret = snd_soc_component_set_sysclk(codec_dai->component, + 0, 0, bclk_val, SND_SOC_CLOCK_IN); + if (ret < 0) { + dev_err(card->dev, "failed to set sysclk for CS35l41 dai\n"); + return ret; + } + } + } + + return ret; +} + +static struct snd_soc_codec_conf cs35l41_conf[] = { + { + .dlc = COMP_CODEC_CONF("spi-VLV1776:00"), + .name_prefix = "Left", + }, + { + .dlc = COMP_CODEC_CONF("spi-VLV1776:01"), + .name_prefix = "Right", + }, +}; + +static const struct snd_soc_ops acp_cs35l41_ops = { + .startup = acp_cs35l41_startup, + .hw_params = acp_cs35l41_hw_params, +}; + +SND_SOC_DAILINK_DEF(cs35l41, + DAILINK_COMP_ARRAY(COMP_CODEC("spi-VLV1776:00", "cs35l41-pcm"), + COMP_CODEC("spi-VLV1776:01", "cs35l41-pcm"))); + /* Declare DMIC codec components */ SND_SOC_DAILINK_DEF(dmic_codec, DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi"))); @@ -1481,6 +1554,7 @@ int acp_sofdsp_dai_links_create(struct snd_soc_card *card) links[i].platforms = sof_component; links[i].num_platforms = ARRAY_SIZE(sof_component); links[i].dpcm_playback = 1; + links[i].dpcm_capture = 1; links[i].nonatomic = true; links[i].no_pcm = 1; if (!drv_data->amp_codec_id) { @@ -1513,6 +1587,7 @@ int acp_sofdsp_dai_links_create(struct snd_soc_card *card) links[i].platforms = sof_component; links[i].num_platforms = ARRAY_SIZE(sof_component); links[i].dpcm_playback = 1; + links[i].dpcm_capture = 1; links[i].nonatomic = true; links[i].no_pcm = 1; if (!drv_data->amp_codec_id) { @@ -1597,6 +1672,8 @@ int acp_legacy_dai_links_create(struct snd_soc_card *card) if (drv_data->hs_cpu_id) num_links++; + if (drv_data->bt_cpu_id) + num_links++; if (drv_data->amp_cpu_id) num_links++; if (drv_data->dmic_cpu_id) @@ -1744,6 +1821,33 @@ int acp_legacy_dai_links_create(struct snd_soc_card *card) card->codec_conf = rt1019_conf; card->num_configs = ARRAY_SIZE(rt1019_conf); } + if (drv_data->amp_codec_id == CS35L41) { + links[i].codecs = cs35l41; + links[i].num_codecs = ARRAY_SIZE(cs35l41); + links[i].init = acp_cs35l41_init; + card->codec_conf = cs35l41_conf; + card->num_configs = ARRAY_SIZE(cs35l41_conf); + links[i].ops = &acp_cs35l41_ops; + } + i++; + } + + if (drv_data->bt_cpu_id == I2S_BT) { + links[i].name = "acp-bt-codec"; + links[i].id = BT_BE_ID; + links[i].cpus = sof_bt; + links[i].num_cpus = ARRAY_SIZE(sof_bt); + links[i].platforms = sof_component; + links[i].num_platforms = ARRAY_SIZE(sof_component); + links[i].dpcm_playback = 1; + links[i].dpcm_capture = 1; + links[i].nonatomic = true; + links[i].no_pcm = 1; + if (!drv_data->bt_codec_id) { + /* Use dummy codec if codec id not specified */ + links[i].codecs = &snd_soc_dummy_dlc; + links[i].num_codecs = 1; + } i++; } diff --git a/sound/soc/amd/acp/acp-mach.h b/sound/soc/amd/acp/acp-mach.h index a48546d8d..3b69dfa80 100644 --- a/sound/soc/amd/acp/acp-mach.h +++ b/sound/soc/amd/acp/acp-mach.h @@ -46,6 +46,7 @@ enum codec_endpoints { MAX98360A, RT5682S, NAU8825, + CS35L41, NAU8821, MAX98388, ES83XX, -- 2.43.0 diff --git a/sound/soc/amd/acp/acp-mach.h b/sound/soc/amd/acp/acp-mach.h index a48546d8d407..0c18ccd29305 100644 --- a/sound/soc/amd/acp/acp-mach.h +++ b/sound/soc/amd/acp/acp-mach.h @@ -27,8 +27,8 @@ enum be_id { HEADSET_BE_ID = 0, AMP_BE_ID, - DMIC_BE_ID, BT_BE_ID, + DMIC_BE_ID, }; enum cpu_endpoints {