Provide small fixes and refactor the code for easier insertion of a new
platform using the same acp5x machine driver.
Changes since V1:
- Don't use smaller variable names
- Don't use 100 limit for all lines
- Use component prefixes to avoid collisions
- Improved commit messages
Lucas Tanure (9):
ASoC: amd: vangogh: Remove unnecessary init function
ASoC: amd: vangogh: Small code refactor
ASoC: amd: vangogh: use sizeof of variable instead of struct type
ASoC: amd: vangogh: remove unnecessarily included headers
ASoC: amd: vangogh: use for_each_rtd_components instead of for
ASoC: amd: vangogh: Check Bit Clock rate before snd_soc_dai_set_pll
ASoC: amd: vangogh: Move nau8821 and CPU side code up for future
platform
ASoC: amd: vangogh: Centralize strings definition
ASoC: amd: vangogh: Add components prefix in structs and function
names
sound/soc/amd/vangogh/acp5x-mach.c | 297 ++++++++++++++---------------
1 file changed, 144 insertions(+), 153 deletions(-)
--
2.39.2
Remove empty acp5x_cs35l41_init function
Signed-off-by: Lucas Tanure <[email protected]>
---
sound/soc/amd/vangogh/acp5x-mach.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/sound/soc/amd/vangogh/acp5x-mach.c b/sound/soc/amd/vangogh/acp5x-mach.c
index eebf2650ad27..5bd9418919a0 100644
--- a/sound/soc/amd/vangogh/acp5x-mach.c
+++ b/sound/soc/amd/vangogh/acp5x-mach.c
@@ -73,11 +73,6 @@ static int acp5x_8821_init(struct snd_soc_pcm_runtime *rtd)
return ret;
}
-static int acp5x_cs35l41_init(struct snd_soc_pcm_runtime *rtd)
-{
- return 0;
-}
-
static const unsigned int rates[] = {
48000,
};
@@ -258,7 +253,6 @@ static struct snd_soc_dai_link acp5x_dai[] = {
.dpcm_playback = 1,
.playback_only = 1,
.ops = &acp5x_cs35l41_play_ops,
- .init = acp5x_cs35l41_init,
SND_SOC_DAILINK_REG(acp5x_bt, cs35l41, platform),
},
};
--
2.39.2
Small refactor of the code:
- sort includes in alphabetical order
- sort variables declarations by line length
- remove unnecessary "struct snd_soc_card *card" lines
- insert blank lines before return
- break/unbreak some lines for better read
- align defines
Signed-off-by: Lucas Tanure <[email protected]>
---
sound/soc/amd/vangogh/acp5x-mach.c | 145 +++++++++++++----------------
1 file changed, 64 insertions(+), 81 deletions(-)
diff --git a/sound/soc/amd/vangogh/acp5x-mach.c b/sound/soc/amd/vangogh/acp5x-mach.c
index 5bd9418919a0..f914f6327cda 100644
--- a/sound/soc/amd/vangogh/acp5x-mach.c
+++ b/sound/soc/amd/vangogh/acp5x-mach.c
@@ -5,34 +5,31 @@
*
* Copyright 2021 Advanced Micro Devices, Inc.
*/
-
-#include <sound/soc.h>
-#include <sound/soc-dapm.h>
-#include <linux/module.h>
-#include <linux/io.h>
-#include <sound/pcm.h>
-#include <sound/pcm_params.h>
-
-#include <sound/jack.h>
+#include <linux/acpi.h>
#include <linux/clk.h>
+#include <linux/dmi.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
+#include <linux/io.h>
#include <linux/i2c.h>
#include <linux/input.h>
-#include <linux/acpi.h>
-#include <linux/dmi.h>
+#include <linux/module.h>
+#include <sound/jack.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
#include "../../codecs/nau8821.h"
#include "../../codecs/cs35l41.h"
-
#include "acp5x.h"
-#define DRV_NAME "acp5x_mach"
-#define DUAL_CHANNEL 2
-#define ACP5X_NUVOTON_CODEC_DAI "nau8821-hifi"
-#define VG_JUPITER 1
-#define ACP5X_NUVOTON_BCLK 3072000
-#define ACP5X_NAU8821_FREQ_OUT 12288000
+#define DRV_NAME "acp5x_mach"
+#define DUAL_CHANNEL 2
+#define ACP5X_NUVOTON_CODEC_DAI "nau8821-hifi"
+#define VG_JUPITER 1
+#define ACP5X_NUVOTON_BCLK 3072000
+#define ACP5X_NAU8821_FREQ_OUT 12288000
static unsigned long acp5x_machine_id;
static struct snd_soc_jack vg_headset;
@@ -50,16 +47,14 @@ static struct snd_soc_jack_pin acp5x_nau8821_jack_pins[] = {
static int acp5x_8821_init(struct snd_soc_pcm_runtime *rtd)
{
+ struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
int ret;
- struct snd_soc_card *card = rtd->card;
- struct snd_soc_component *component =
- asoc_rtd_to_codec(rtd, 0)->component;
/*
* Headset buttons map to the google Reference headset.
* These can be configured by userspace.
*/
- ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
+ ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
SND_JACK_HEADSET | SND_JACK_BTN_0,
&vg_headset, acp5x_nau8821_jack_pins,
ARRAY_SIZE(acp5x_nau8821_jack_pins));
@@ -70,6 +65,7 @@ static int acp5x_8821_init(struct snd_soc_pcm_runtime *rtd)
snd_jack_set_key(vg_headset.jack, SND_JACK_BTN_0, KEY_MEDIA);
nau8821_enable_jack_detect(component, &vg_headset);
+
return ret;
}
@@ -104,8 +100,7 @@ static int acp5x_8821_startup(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
- struct snd_soc_card *card = rtd->card;
- struct acp5x_platform_info *machine = snd_soc_card_get_drvdata(card);
+ struct acp5x_platform_info *machine = snd_soc_card_get_drvdata(rtd->card);
machine->play_i2s_instance = I2S_SP_INSTANCE;
machine->cap_i2s_instance = I2S_SP_INSTANCE;
@@ -118,6 +113,7 @@ static int acp5x_8821_startup(struct snd_pcm_substream *substream)
snd_pcm_hw_constraint_list(substream->runtime, 0,
SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
&constraints_sample_bits);
+
return 0;
}
@@ -126,16 +122,13 @@ static int acp5x_nau8821_hw_params(struct snd_pcm_substream *substream,
{
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct snd_soc_card *card = rtd->card;
- struct snd_soc_dai *codec_dai =
- snd_soc_card_get_codec_dai(card,
- ACP5X_NUVOTON_CODEC_DAI);
+ struct snd_soc_dai *dai = snd_soc_card_get_codec_dai(card, ACP5X_NUVOTON_CODEC_DAI);
int ret;
- ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_FLL_BLK, 0,
- SND_SOC_CLOCK_IN);
+ ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_FLL_BLK, 0, SND_SOC_CLOCK_IN);
if (ret < 0)
dev_err(card->dev, "can't set FS clock %d\n", ret);
- ret = snd_soc_dai_set_pll(codec_dai, 0, 0, snd_soc_params_to_bclk(params),
+ ret = snd_soc_dai_set_pll(dai, 0, 0, snd_soc_params_to_bclk(params),
params_rate(params) * 256);
if (ret < 0)
dev_err(card->dev, "can't set FLL: %d\n", ret);
@@ -145,10 +138,9 @@ static int acp5x_nau8821_hw_params(struct snd_pcm_substream *substream,
static int acp5x_cs35l41_startup(struct snd_pcm_substream *substream)
{
- struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
- struct snd_soc_card *card = rtd->card;
- struct acp5x_platform_info *machine = snd_soc_card_get_drvdata(card);
+ struct acp5x_platform_info *machine = snd_soc_card_get_drvdata(rtd->card);
+ struct snd_pcm_runtime *runtime = substream->runtime;
machine->play_i2s_instance = I2S_HS_INSTANCE;
@@ -157,6 +149,7 @@ static int acp5x_cs35l41_startup(struct snd_pcm_substream *substream)
&constraints_channels);
snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
&constraints_rates);
+
return 0;
}
@@ -164,16 +157,16 @@ static int acp5x_cs35l41_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = asoc_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;
+ struct snd_soc_card *card = rtd->card;
+ struct snd_soc_dai *dai;
unsigned int bclk_val;
+ int ret, i;
ret = 0;
for (i = 0; i < num_codecs; i++) {
- codec_dai = asoc_rtd_to_codec(rtd, i);
- if (strcmp(codec_dai->name, "cs35l41-pcm") == 0) {
+ dai = asoc_rtd_to_codec(rtd, i);
+ if (strcmp(dai->name, "cs35l41-pcm") == 0) {
switch (params_rate(params)) {
case 48000:
bclk_val = 1536000;
@@ -183,8 +176,8 @@ static int acp5x_cs35l41_hw_params(struct snd_pcm_substream *substream,
params_rate(params));
return -EINVAL;
}
- ret = snd_soc_component_set_sysclk(codec_dai->component,
- 0, 0, bclk_val, SND_SOC_CLOCK_IN);
+ ret = snd_soc_component_set_sysclk(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;
@@ -216,28 +209,19 @@ static struct snd_soc_codec_conf cs35l41_conf[] = {
},
};
-SND_SOC_DAILINK_DEF(acp5x_i2s,
- DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.0")));
-
-SND_SOC_DAILINK_DEF(acp5x_bt,
- DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.1")));
-
-SND_SOC_DAILINK_DEF(nau8821,
- DAILINK_COMP_ARRAY(COMP_CODEC("i2c-NVTN2020:00",
- "nau8821-hifi")));
-
-SND_SOC_DAILINK_DEF(cs35l41,
- DAILINK_COMP_ARRAY(COMP_CODEC("spi-VLV1776:00", "cs35l41-pcm"),
- COMP_CODEC("spi-VLV1776:01", "cs35l41-pcm")));
-
-SND_SOC_DAILINK_DEF(platform,
- DAILINK_COMP_ARRAY(COMP_PLATFORM("acp5x_i2s_dma.0")));
+SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("acp5x_i2s_dma.0")));
+SND_SOC_DAILINK_DEF(acp5x_i2s, DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.0")));
+SND_SOC_DAILINK_DEF(acp5x_bt, DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.1")));
+SND_SOC_DAILINK_DEF(nau8821, DAILINK_COMP_ARRAY(COMP_CODEC("i2c-NVTN2020:00", "nau8821-hifi")));
+SND_SOC_DAILINK_DEF(cs35l41, DAILINK_COMP_ARRAY(COMP_CODEC("spi-VLV1776:00", "cs35l41-pcm"),
+ COMP_CODEC("spi-VLV1776:01", "cs35l41-pcm")));
static struct snd_soc_dai_link acp5x_dai[] = {
{
.name = "acp5x-8821-play",
.stream_name = "Playback/Capture",
- .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+ .dai_fmt = SND_SOC_DAIFMT_I2S |
+ SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBC_CFC,
.dpcm_playback = 1,
.dpcm_capture = 1,
@@ -248,7 +232,8 @@ static struct snd_soc_dai_link acp5x_dai[] = {
{
.name = "acp5x-CS35L41-Stereo",
.stream_name = "CS35L41 Stereo Playback",
- .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+ .dai_fmt = SND_SOC_DAIFMT_I2S |
+ SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBC_CFC,
.dpcm_playback = 1,
.playback_only = 1,
@@ -258,36 +243,34 @@ static struct snd_soc_dai_link acp5x_dai[] = {
};
static int platform_clock_control(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *k, int event)
+ struct snd_kcontrol *k, int event)
{
struct snd_soc_dapm_context *dapm = w->dapm;
struct snd_soc_card *card = dapm->card;
- struct snd_soc_dai *codec_dai;
+ struct snd_soc_dai *dai;
int ret = 0;
- codec_dai = snd_soc_card_get_codec_dai(card, ACP5X_NUVOTON_CODEC_DAI);
- if (!codec_dai) {
+ dai = snd_soc_card_get_codec_dai(card, ACP5X_NUVOTON_CODEC_DAI);
+ if (!dai) {
dev_err(card->dev, "Codec dai not found\n");
return -EIO;
}
if (SND_SOC_DAPM_EVENT_OFF(event)) {
- ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_INTERNAL,
- 0, SND_SOC_CLOCK_IN);
+ ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN);
if (ret < 0) {
dev_err(card->dev, "set sysclk err = %d\n", ret);
return -EIO;
}
} else {
- ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_FLL_BLK, 0,
- SND_SOC_CLOCK_IN);
+ ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_FLL_BLK, 0, SND_SOC_CLOCK_IN);
if (ret < 0)
- dev_err(codec_dai->dev, "can't set BLK clock %d\n", ret);
- ret = snd_soc_dai_set_pll(codec_dai, 0, 0, ACP5X_NUVOTON_BCLK,
- ACP5X_NAU8821_FREQ_OUT);
+ dev_err(dai->dev, "can't set BLK clock %d\n", ret);
+ ret = snd_soc_dai_set_pll(dai, 0, 0, ACP5X_NUVOTON_BCLK, ACP5X_NAU8821_FREQ_OUT);
if (ret < 0)
- dev_err(codec_dai->dev, "can't set FLL: %d\n", ret);
+ dev_err(dai->dev, "can't set FLL: %d\n", ret);
}
+
return ret;
}
@@ -302,7 +285,8 @@ static const struct snd_soc_dapm_widget acp5x_8821_widgets[] = {
SND_SOC_DAPM_MIC("Headset Mic", NULL),
SND_SOC_DAPM_MIC("Int Mic", NULL),
SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
- platform_clock_control, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
+ platform_clock_control,
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
};
static const struct snd_soc_dapm_route acp5x_8821_audio_route[] = {
@@ -336,6 +320,7 @@ static struct snd_soc_card acp5x_card = {
static int acp5x_vg_quirk_cb(const struct dmi_system_id *id)
{
acp5x_machine_id = VG_JUPITER;
+
return 1;
}
@@ -352,12 +337,12 @@ static const struct dmi_system_id acp5x_vg_quirk_table[] = {
static int acp5x_probe(struct platform_device *pdev)
{
- int ret;
struct acp5x_platform_info *machine;
+ struct device *dev = &pdev->dev;
struct snd_soc_card *card;
+ int ret;
- machine = devm_kzalloc(&pdev->dev, sizeof(struct acp5x_platform_info),
- GFP_KERNEL);
+ machine = devm_kzalloc(dev, sizeof(struct acp5x_platform_info), GFP_KERNEL);
if (!machine)
return -ENOMEM;
@@ -365,20 +350,18 @@ static int acp5x_probe(struct platform_device *pdev)
switch (acp5x_machine_id) {
case VG_JUPITER:
card = &acp5x_card;
- acp5x_card.dev = &pdev->dev;
break;
default:
return -ENODEV;
}
+ card->dev = dev;
platform_set_drvdata(pdev, card);
snd_soc_card_set_drvdata(card, machine);
- ret = devm_snd_soc_register_card(&pdev->dev, card);
- if (ret) {
- return dev_err_probe(&pdev->dev, ret,
- "snd_soc_register_card(%s) failed\n",
- acp5x_card.name);
- }
+ ret = devm_snd_soc_register_card(dev, card);
+ if (ret)
+ return dev_err_probe(dev, ret, "Register card (%s) failed\n", card->name);
+
return 0;
}
--
2.39.2
Use sizeof(*machine) instead of sizeof(struct acp5x_platform_info)
There is a possibility of bug when variable type has changed but
corresponding struct passed to the sizeof has not.
Signed-off-by: Lucas Tanure <[email protected]>
---
sound/soc/amd/vangogh/acp5x-mach.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/amd/vangogh/acp5x-mach.c b/sound/soc/amd/vangogh/acp5x-mach.c
index f914f6327cda..43c80103d138 100644
--- a/sound/soc/amd/vangogh/acp5x-mach.c
+++ b/sound/soc/amd/vangogh/acp5x-mach.c
@@ -342,7 +342,7 @@ static int acp5x_probe(struct platform_device *pdev)
struct snd_soc_card *card;
int ret;
- machine = devm_kzalloc(dev, sizeof(struct acp5x_platform_info), GFP_KERNEL);
+ machine = devm_kzalloc(dev, sizeof(*machine), GFP_KERNEL);
if (!machine)
return -ENOMEM;
--
2.39.2
Remove unused includes and replace <linux/input.h> by
<linux/input-event-codes.h>
Signed-off-by: Lucas Tanure <[email protected]>
---
sound/soc/amd/vangogh/acp5x-mach.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/sound/soc/amd/vangogh/acp5x-mach.c b/sound/soc/amd/vangogh/acp5x-mach.c
index 43c80103d138..a1cd52e58574 100644
--- a/sound/soc/amd/vangogh/acp5x-mach.c
+++ b/sound/soc/amd/vangogh/acp5x-mach.c
@@ -5,23 +5,19 @@
*
* Copyright 2021 Advanced Micro Devices, Inc.
*/
+
#include <linux/acpi.h>
-#include <linux/clk.h>
#include <linux/dmi.h>
-#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
-#include <linux/io.h>
#include <linux/i2c.h>
-#include <linux/input.h>
+#include <linux/input-event-codes.h>
#include <linux/module.h>
#include <sound/jack.h>
-#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include "../../codecs/nau8821.h"
-#include "../../codecs/cs35l41.h"
#include "acp5x.h"
#define DRV_NAME "acp5x_mach"
--
2.39.2
To iterate over components use for_each_rtd_components
And compare to component name, so asoc_rtd_to_codec and the dai code can
be removed
Signed-off-by: Lucas Tanure <[email protected]>
---
sound/soc/amd/vangogh/acp5x-mach.c | 42 ++++++++++++++++--------------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/sound/soc/amd/vangogh/acp5x-mach.c b/sound/soc/amd/vangogh/acp5x-mach.c
index a1cd52e58574..e7183d8ac3a2 100644
--- a/sound/soc/amd/vangogh/acp5x-mach.c
+++ b/sound/soc/amd/vangogh/acp5x-mach.c
@@ -153,35 +153,37 @@ static int acp5x_cs35l41_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
- unsigned int num_codecs = rtd->dai_link->num_codecs;
- struct snd_soc_card *card = rtd->card;
- struct snd_soc_dai *dai;
- unsigned int bclk_val;
+ unsigned int bclk, rate = params_rate(params);
+ struct snd_soc_component *comp;
int ret, i;
- ret = 0;
- for (i = 0; i < num_codecs; i++) {
- dai = asoc_rtd_to_codec(rtd, i);
- if (strcmp(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));
+ switch (rate) {
+ case 48000:
+ bclk = 1536000;
+ break;
+ default:
+ bclk = 0;
+ break;
+ }
+
+ for_each_rtd_components(rtd, i, comp) {
+ if (!(strcmp(comp->name, "spi-VLV1776:00")) ||
+ !(strcmp(comp->name, "spi-VLV1776:01"))) {
+ if (!bclk) {
+ dev_err(comp->dev, "Invalid sample rate: 0x%x\n", rate);
return -EINVAL;
}
- ret = snd_soc_component_set_sysclk(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");
+
+ ret = snd_soc_component_set_sysclk(comp, 0, 0, bclk, SND_SOC_CLOCK_IN);
+ if (ret) {
+ dev_err(comp->dev, "failed to set SYSCLK: %d\n", ret);
return ret;
}
}
}
- return ret;
+ return 0;
+
}
static const struct snd_soc_ops acp5x_8821_ops = {
--
2.39.2
Move nau8821 and CPU side code up in the source so future platforms can
be added.
Signed-off-by: Lucas Tanure <[email protected]>
---
sound/soc/amd/vangogh/acp5x-mach.c | 97 +++++++++++++++---------------
1 file changed, 50 insertions(+), 47 deletions(-)
diff --git a/sound/soc/amd/vangogh/acp5x-mach.c b/sound/soc/amd/vangogh/acp5x-mach.c
index c746605b63a1..153ce9e84a23 100644
--- a/sound/soc/amd/vangogh/acp5x-mach.c
+++ b/sound/soc/amd/vangogh/acp5x-mach.c
@@ -30,6 +30,11 @@
static unsigned long acp5x_machine_id;
static struct snd_soc_jack vg_headset;
+SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("acp5x_i2s_dma.0")));
+SND_SOC_DAILINK_DEF(acp5x_i2s, DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.0")));
+SND_SOC_DAILINK_DEF(acp5x_bt, DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.1")));
+SND_SOC_DAILINK_DEF(nau8821, DAILINK_COMP_ARRAY(COMP_CODEC("i2c-NVTN2020:00", "nau8821-hifi")));
+
static struct snd_soc_jack_pin acp5x_nau8821_jack_pins[] = {
{
.pin = "Headphone",
@@ -41,6 +46,44 @@ static struct snd_soc_jack_pin acp5x_nau8821_jack_pins[] = {
},
};
+static const struct snd_kcontrol_new acp5x_8821_controls[] = {
+ SOC_DAPM_PIN_SWITCH("Headphone"),
+ SOC_DAPM_PIN_SWITCH("Headset Mic"),
+ SOC_DAPM_PIN_SWITCH("Int Mic"),
+};
+
+static int platform_clock_control(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *k, int event)
+{
+ struct snd_soc_dapm_context *dapm = w->dapm;
+ struct snd_soc_card *card = dapm->card;
+ struct snd_soc_dai *dai;
+ int ret = 0;
+
+ dai = snd_soc_card_get_codec_dai(card, ACP5X_NUVOTON_CODEC_DAI);
+ if (!dai) {
+ dev_err(card->dev, "Codec dai not found\n");
+ return -EIO;
+ }
+
+ if (SND_SOC_DAPM_EVENT_OFF(event)) {
+ ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN);
+ if (ret < 0) {
+ dev_err(card->dev, "set sysclk err = %d\n", ret);
+ return -EIO;
+ }
+ } else {
+ ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_FLL_BLK, 0, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(dai->dev, "can't set BLK clock %d\n", ret);
+ ret = snd_soc_dai_set_pll(dai, 0, 0, ACP5X_NUVOTON_BCLK, ACP5X_NAU8821_FREQ_OUT);
+ if (ret < 0)
+ dev_err(dai->dev, "can't set FLL: %d\n", ret);
+ }
+
+ return ret;
+}
+
static int acp5x_8821_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
@@ -138,6 +181,11 @@ static int acp5x_nau8821_hw_params(struct snd_pcm_substream *substream,
return ret;
}
+static const struct snd_soc_ops acp5x_8821_ops = {
+ .startup = acp5x_8821_startup,
+ .hw_params = acp5x_nau8821_hw_params,
+};
+
static int acp5x_cs35l41_startup(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
@@ -192,11 +240,6 @@ static int acp5x_cs35l41_hw_params(struct snd_pcm_substream *substream,
}
-static const struct snd_soc_ops acp5x_8821_ops = {
- .startup = acp5x_8821_startup,
- .hw_params = acp5x_nau8821_hw_params,
-};
-
static const struct snd_soc_ops acp5x_cs35l41_play_ops = {
.startup = acp5x_cs35l41_startup,
.hw_params = acp5x_cs35l41_hw_params,
@@ -213,12 +256,8 @@ static struct snd_soc_codec_conf cs35l41_conf[] = {
},
};
-SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("acp5x_i2s_dma.0")));
-SND_SOC_DAILINK_DEF(acp5x_i2s, DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.0")));
-SND_SOC_DAILINK_DEF(acp5x_bt, DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.1")));
-SND_SOC_DAILINK_DEF(nau8821, DAILINK_COMP_ARRAY(COMP_CODEC("i2c-NVTN2020:00", "nau8821-hifi")));
-SND_SOC_DAILINK_DEF(cs35l41, DAILINK_COMP_ARRAY(COMP_CODEC("spi-VLV1776:00", "cs35l41-pcm"),
- COMP_CODEC("spi-VLV1776:01", "cs35l41-pcm")));
+SND_SOC_DAILINK_DEF(cs35l41, DAILINK_COMP_ARRAY(COMP_CODEC("spi-VLV1776:00", "cs35l41-pcm"),
+ COMP_CODEC("spi-VLV1776:01", "cs35l41-pcm")));
static struct snd_soc_dai_link acp5x_dai[] = {
{
@@ -246,43 +285,7 @@ static struct snd_soc_dai_link acp5x_dai[] = {
},
};
-static int platform_clock_control(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *k, int event)
-{
- struct snd_soc_dapm_context *dapm = w->dapm;
- struct snd_soc_card *card = dapm->card;
- struct snd_soc_dai *dai;
- int ret = 0;
-
- dai = snd_soc_card_get_codec_dai(card, ACP5X_NUVOTON_CODEC_DAI);
- if (!dai) {
- dev_err(card->dev, "Codec dai not found\n");
- return -EIO;
- }
-
- if (SND_SOC_DAPM_EVENT_OFF(event)) {
- ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN);
- if (ret < 0) {
- dev_err(card->dev, "set sysclk err = %d\n", ret);
- return -EIO;
- }
- } else {
- ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_FLL_BLK, 0, SND_SOC_CLOCK_IN);
- if (ret < 0)
- dev_err(dai->dev, "can't set BLK clock %d\n", ret);
- ret = snd_soc_dai_set_pll(dai, 0, 0, ACP5X_NUVOTON_BCLK, ACP5X_NAU8821_FREQ_OUT);
- if (ret < 0)
- dev_err(dai->dev, "can't set FLL: %d\n", ret);
- }
-
- return ret;
-}
-static const struct snd_kcontrol_new acp5x_8821_controls[] = {
- SOC_DAPM_PIN_SWITCH("Headphone"),
- SOC_DAPM_PIN_SWITCH("Headset Mic"),
- SOC_DAPM_PIN_SWITCH("Int Mic"),
-};
static const struct snd_soc_dapm_widget acp5x_8821_widgets[] = {
SND_SOC_DAPM_HP("Headphone", NULL),
--
2.39.2
Check bit clock is valid before setting it with snd_soc_dai_set_pll
Signed-off-by: Lucas Tanure <[email protected]>
---
sound/soc/amd/vangogh/acp5x-mach.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/sound/soc/amd/vangogh/acp5x-mach.c b/sound/soc/amd/vangogh/acp5x-mach.c
index e7183d8ac3a2..c746605b63a1 100644
--- a/sound/soc/amd/vangogh/acp5x-mach.c
+++ b/sound/soc/amd/vangogh/acp5x-mach.c
@@ -119,13 +119,19 @@ static int acp5x_nau8821_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct snd_soc_card *card = rtd->card;
struct snd_soc_dai *dai = snd_soc_card_get_codec_dai(card, ACP5X_NUVOTON_CODEC_DAI);
- int ret;
+ int ret, bclk;
ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_FLL_BLK, 0, SND_SOC_CLOCK_IN);
if (ret < 0)
dev_err(card->dev, "can't set FS clock %d\n", ret);
- ret = snd_soc_dai_set_pll(dai, 0, 0, snd_soc_params_to_bclk(params),
- params_rate(params) * 256);
+
+ bclk = snd_soc_params_to_bclk(params);
+ if (bclk < 0) {
+ dev_err(dai->dev, "Fail to get BCLK rate: %d\n", bclk);
+ return bclk;
+ }
+
+ ret = snd_soc_dai_set_pll(dai, 0, 0, bclk, params_rate(params) * 256);
if (ret < 0)
dev_err(card->dev, "can't set FLL: %d\n", ret);
--
2.39.2
Add prefixes 8821/35l41 in structs and function names so future platforms
can be added and reference the correct sound card.
Also include acp5x prefix to cs35l41_conf.
Signed-off-by: Lucas Tanure <[email protected]>
---
sound/soc/amd/vangogh/acp5x-mach.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/sound/soc/amd/vangogh/acp5x-mach.c b/sound/soc/amd/vangogh/acp5x-mach.c
index 367570e5c60f..e5bcd1e6eb73 100644
--- a/sound/soc/amd/vangogh/acp5x-mach.c
+++ b/sound/soc/amd/vangogh/acp5x-mach.c
@@ -250,7 +250,7 @@ static const struct snd_soc_ops acp5x_cs35l41_play_ops = {
.hw_params = acp5x_cs35l41_hw_params,
};
-static struct snd_soc_codec_conf cs35l41_conf[] = {
+static struct snd_soc_codec_conf acp5x_cs35l41_conf[] = {
{
.dlc = COMP_CODEC_CONF(ACP5X_CS35L41_COMP_LNAME),
.name_prefix = "Left",
@@ -266,7 +266,7 @@ SND_SOC_DAILINK_DEF(cs35l41, DAILINK_COMP_ARRAY(COMP_CODEC(ACP5X_CS35L41_COMP_LN
COMP_CODEC(ACP5X_CS35L41_COMP_RNAME,
ACP5X_CS35L41_DAI_NAME)));
-static struct snd_soc_dai_link acp5x_dai[] = {
+static struct snd_soc_dai_link acp5x_8821_35l41_dai[] = {
{
.name = "acp5x-8821-play",
.stream_name = "Playback/Capture",
@@ -294,7 +294,7 @@ static struct snd_soc_dai_link acp5x_dai[] = {
-static const struct snd_soc_dapm_widget acp5x_8821_widgets[] = {
+static const struct snd_soc_dapm_widget acp5x_8821_35l41_widgets[] = {
SND_SOC_DAPM_HP("Headphone", NULL),
SND_SOC_DAPM_MIC("Headset Mic", NULL),
SND_SOC_DAPM_MIC("Int Mic", NULL),
@@ -303,7 +303,7 @@ static const struct snd_soc_dapm_widget acp5x_8821_widgets[] = {
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
};
-static const struct snd_soc_dapm_route acp5x_8821_audio_route[] = {
+static const struct snd_soc_dapm_route acp5x_8821_35l41_audio_route[] = {
/* HP jack connectors - unknown if we have jack detection */
{ "Headphone", NULL, "HPOL" },
{ "Headphone", NULL, "HPOR" },
@@ -316,17 +316,17 @@ static const struct snd_soc_dapm_route acp5x_8821_audio_route[] = {
{ "Int Mic", NULL, "Platform Clock" },
};
-static struct snd_soc_card acp5x_card = {
+static struct snd_soc_card acp5x_8821_35l41_card = {
.name = "acp5x",
.owner = THIS_MODULE,
- .dai_link = acp5x_dai,
- .num_links = ARRAY_SIZE(acp5x_dai),
- .dapm_widgets = acp5x_8821_widgets,
- .num_dapm_widgets = ARRAY_SIZE(acp5x_8821_widgets),
- .dapm_routes = acp5x_8821_audio_route,
- .num_dapm_routes = ARRAY_SIZE(acp5x_8821_audio_route),
- .codec_conf = cs35l41_conf,
- .num_configs = ARRAY_SIZE(cs35l41_conf),
+ .dai_link = acp5x_8821_35l41_dai,
+ .num_links = ARRAY_SIZE(acp5x_8821_35l41_dai),
+ .dapm_widgets = acp5x_8821_35l41_widgets,
+ .num_dapm_widgets = ARRAY_SIZE(acp5x_8821_35l41_widgets),
+ .dapm_routes = acp5x_8821_35l41_audio_route,
+ .num_dapm_routes = ARRAY_SIZE(acp5x_8821_35l41_audio_route),
+ .codec_conf = acp5x_cs35l41_conf,
+ .num_configs = ARRAY_SIZE(acp5x_cs35l41_conf),
.controls = acp5x_8821_controls,
.num_controls = ARRAY_SIZE(acp5x_8821_controls),
};
@@ -363,7 +363,7 @@ static int acp5x_probe(struct platform_device *pdev)
dmi_check_system(acp5x_vg_quirk_table);
switch (acp5x_machine_id) {
case VG_JUPITER:
- card = &acp5x_card;
+ card = &acp5x_8821_35l41_card;
break;
default:
return -ENODEV;
--
2.39.2
Replace occurrences of strings by their definition, avoiding
bugs where the string changed, but not all places have been modified.
While at it rename defines to use NAU8821 codec name instead of NUVOTON
and align with the other defines.
Signed-off-by: Lucas Tanure <[email protected]>
---
sound/soc/amd/vangogh/acp5x-mach.c | 31 ++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/sound/soc/amd/vangogh/acp5x-mach.c b/sound/soc/amd/vangogh/acp5x-mach.c
index 153ce9e84a23..367570e5c60f 100644
--- a/sound/soc/amd/vangogh/acp5x-mach.c
+++ b/sound/soc/amd/vangogh/acp5x-mach.c
@@ -22,10 +22,14 @@
#define DRV_NAME "acp5x_mach"
#define DUAL_CHANNEL 2
-#define ACP5X_NUVOTON_CODEC_DAI "nau8821-hifi"
#define VG_JUPITER 1
-#define ACP5X_NUVOTON_BCLK 3072000
+#define ACP5X_NAU8821_BCLK 3072000
#define ACP5X_NAU8821_FREQ_OUT 12288000
+#define ACP5X_NAU8821_COMP_NAME "i2c-NVTN2020:00"
+#define ACP5X_NAU8821_DAI_NAME "nau8821-hifi"
+#define ACP5X_CS35L41_COMP_LNAME "spi-VLV1776:00"
+#define ACP5X_CS35L41_COMP_RNAME "spi-VLV1776:01"
+#define ACP5X_CS35L41_DAI_NAME "cs35l41-pcm"
static unsigned long acp5x_machine_id;
static struct snd_soc_jack vg_headset;
@@ -33,7 +37,8 @@ static struct snd_soc_jack vg_headset;
SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("acp5x_i2s_dma.0")));
SND_SOC_DAILINK_DEF(acp5x_i2s, DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.0")));
SND_SOC_DAILINK_DEF(acp5x_bt, DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.1")));
-SND_SOC_DAILINK_DEF(nau8821, DAILINK_COMP_ARRAY(COMP_CODEC("i2c-NVTN2020:00", "nau8821-hifi")));
+SND_SOC_DAILINK_DEF(nau8821, DAILINK_COMP_ARRAY(COMP_CODEC(ACP5X_NAU8821_COMP_NAME,
+ ACP5X_NAU8821_DAI_NAME)));
static struct snd_soc_jack_pin acp5x_nau8821_jack_pins[] = {
{
@@ -60,7 +65,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
struct snd_soc_dai *dai;
int ret = 0;
- dai = snd_soc_card_get_codec_dai(card, ACP5X_NUVOTON_CODEC_DAI);
+ dai = snd_soc_card_get_codec_dai(card, ACP5X_NAU8821_DAI_NAME);
if (!dai) {
dev_err(card->dev, "Codec dai not found\n");
return -EIO;
@@ -76,7 +81,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_FLL_BLK, 0, SND_SOC_CLOCK_IN);
if (ret < 0)
dev_err(dai->dev, "can't set BLK clock %d\n", ret);
- ret = snd_soc_dai_set_pll(dai, 0, 0, ACP5X_NUVOTON_BCLK, ACP5X_NAU8821_FREQ_OUT);
+ ret = snd_soc_dai_set_pll(dai, 0, 0, ACP5X_NAU8821_BCLK, ACP5X_NAU8821_FREQ_OUT);
if (ret < 0)
dev_err(dai->dev, "can't set FLL: %d\n", ret);
}
@@ -161,7 +166,7 @@ static int acp5x_nau8821_hw_params(struct snd_pcm_substream *substream,
{
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct snd_soc_card *card = rtd->card;
- struct snd_soc_dai *dai = snd_soc_card_get_codec_dai(card, ACP5X_NUVOTON_CODEC_DAI);
+ struct snd_soc_dai *dai = snd_soc_card_get_codec_dai(card, ACP5X_NAU8821_DAI_NAME);
int ret, bclk;
ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_FLL_BLK, 0, SND_SOC_CLOCK_IN);
@@ -221,8 +226,8 @@ static int acp5x_cs35l41_hw_params(struct snd_pcm_substream *substream,
}
for_each_rtd_components(rtd, i, comp) {
- if (!(strcmp(comp->name, "spi-VLV1776:00")) ||
- !(strcmp(comp->name, "spi-VLV1776:01"))) {
+ if (!(strcmp(comp->name, ACP5X_CS35L41_COMP_LNAME)) ||
+ !(strcmp(comp->name, ACP5X_CS35L41_COMP_RNAME))) {
if (!bclk) {
dev_err(comp->dev, "Invalid sample rate: 0x%x\n", rate);
return -EINVAL;
@@ -247,17 +252,19 @@ static const struct snd_soc_ops acp5x_cs35l41_play_ops = {
static struct snd_soc_codec_conf cs35l41_conf[] = {
{
- .dlc = COMP_CODEC_CONF("spi-VLV1776:00"),
+ .dlc = COMP_CODEC_CONF(ACP5X_CS35L41_COMP_LNAME),
.name_prefix = "Left",
},
{
- .dlc = COMP_CODEC_CONF("spi-VLV1776:01"),
+ .dlc = COMP_CODEC_CONF(ACP5X_CS35L41_COMP_RNAME),
.name_prefix = "Right",
},
};
-SND_SOC_DAILINK_DEF(cs35l41, DAILINK_COMP_ARRAY(COMP_CODEC("spi-VLV1776:00", "cs35l41-pcm"),
- COMP_CODEC("spi-VLV1776:01", "cs35l41-pcm")));
+SND_SOC_DAILINK_DEF(cs35l41, DAILINK_COMP_ARRAY(COMP_CODEC(ACP5X_CS35L41_COMP_LNAME,
+ ACP5X_CS35L41_DAI_NAME),
+ COMP_CODEC(ACP5X_CS35L41_COMP_RNAME,
+ ACP5X_CS35L41_DAI_NAME)));
static struct snd_soc_dai_link acp5x_dai[] = {
{
--
2.39.2