ASoC: cs4341: Add driver for CS4341 CODEC
Subsystems (3)
PATCH 1/2 ASoC: cs4341: Add driver for CS4341 CODEC
Initial commit of the Cirrus Logic CS4341.
This is a very simple, playback only, stereo DAC.
--- sound/soc/codecs/Kconfig | 7 ++ sound/soc/codecs/Makefile | 1 + sound/soc/codecs/cs4341.c | 281 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 289 insertions(+) create mode 100644 sound/soc/codecs/cs4341.c
sound/soc/codecs/Kconfig +7 -0
@@ -458,6 +458,13 @@ config SND_SOC_CS42XX8_I2C select SND_SOC_CS42XX8 select REGMAP_I2C +config SND_SOC_CS4341 + tristate "Cirrus Logic CS4341 CODEC" + depends on SPI_MASTER + select REGMAP_SPI + help + Enable support for Cirrus Logic (Crystal) CS4341 CODEC. + # Cirrus Logic CS4349 HiFi DAC config SND_SOC_CS4349 tristate "Cirrus Logic CS4349 CODEC"
sound/soc/codecs/Makefile +1 -0
@@ -50,6 +50,7 @@ snd-soc-cs4271-i2c-objs := cs4271-i2c.o snd-soc-cs4271-spi-objs := cs4271-spi.o snd-soc-cs42xx8-objs := cs42xx8.o snd-soc-cs42xx8-i2c-objs := cs42xx8-i2c.o +snd-soc-cs4341-objs := cs4341.o snd-soc-cs4349-objs := cs4349.o snd-soc-cs47l24-objs := cs47l24.o snd-soc-cs53l30-objs := cs53l30.o
sound/soc/codecs/cs4341.c new file +281 -0
281 lines not on this page · raw message
Signature · 1 line
2.7.3
Quoted 5 lines · Alexander Shiyan
sound/soc/codecs/Kconfig +0
-0
sound/soc/codecs/Kconfig config SND_SOC_CS42XX8_I2C · line 467
Quoted 10 lines
sound/soc/codecs/Kconfig +7
-0@@ -458,6 +458,13 @@ config SND_SOC_CS42XX8_I2C select SND_SOC_CS42XX8 select REGMAP_I2C +config SND_SOC_CS4341 + tristate "Cirrus Logic CS4341 CODEC" + depends on SPI_MASTER + select REGMAP_SPI + help + Enable support for Cirrus Logic (Crystal) CS4341 CODEC. +
This devices primary interface is I2C. That should be added as well since i2c is read/write and spi is write only.
Quoted 9 lines
sound/soc/codecs/Kconfig +0
-0# Cirrus Logic CS4349 HiFi DACconfig
SND_SOC_CS4349
tristate "Cirrus Logic CS4349 CODEC"sound/soc/codecs/Kconfig +4
-0+#define CS4341_REG_MODE1 0x00 +#define CS4341_REG_MODE2 0x01 +#define CS4341_REG_MIX 0x02 +#define CS4341_REG_VOLA 0x03
sound/soc/codecs/Kconfig
Quoted 10 lines
sound/soc/codecs/Kconfig +10
-0+#define CS4341_REG_VOLB 0x04 + +#define CS4341_MODE2_DIF (7 << 4) +#define CS4341_MODE2_DIF_I2S_24 (0 << 4) +#define CS4341_MODE2_DIF_I2S_16 (1 << 4) +#define CS4341_MODE2_DIF_LJ_24 (2 << 4) +#define CS4341_MODE2_DIF_RJ_24 (3 << 4) +#define CS4341_MODE2_DIF_RJ_16 (5 << 4) + +#define CS4341_VOLX_MUTE (1 << 7)
It would be a good idea to clean up the indentation here.
Quoted 9 lines
sound/soc/codecs/Kconfig +9
-0+ switch (cs4341->fmt) { + case SND_SOC_DAIFMT_I2S: + snd_soc_update_bits(codec, CS4341_REG_MODE2, CS4341_MODE2_DIF, + bits24 ? CS4341_MODE2_DIF_I2S_24 : + CS4341_MODE2_DIF_I2S_16); + break; + case SND_SOC_DAIFMT_LEFT_J: + snd_soc_update_bits(codec, CS4341_REG_MODE2, CS4341_MODE2_DIF, + CS4341_MODE2_DIF_LJ_24);
sound/soc/codecs/Kconfig
Quoted 10 lines
sound/soc/codecs/Kconfig +10
-0+ break; + case SND_SOC_DAIFMT_RIGHT_J: + snd_soc_update_bits(codec, CS4341_REG_MODE2, CS4341_MODE2_DIF, + bits24 ? CS4341_MODE2_DIF_RJ_24 : + CS4341_MODE2_DIF_RJ_16); + break; + default: + dev_err(codec->dev, "Unsupported DAI format\n"); + return -EINVAL; + }
Can we use regmap_update_bits where we can?
Quoted 6 lines
sound/soc/codecs/Kconfig +6
-0+ + return 0; +} + +static int cs4341_digital_mute(struct snd_soc_dai *dai, int mute) +{
sound/soc/codecs/Kconfig
Quoted 10 lines
sound/soc/codecs/Kconfig +10
-0+ struct snd_soc_codec *codec = dai->codec; + int ret; + + ret = snd_soc_update_bits(codec, CS4341_REG_VOLA, CS4341_VOLX_MUTE, + mute ? CS4341_VOLX_MUTE : 0); + if (ret < 0) + return ret; + + return snd_soc_update_bits(codec, CS4341_REG_VOLB, CS4341_VOLX_MUTE, + mute ? CS4341_VOLX_MUTE : 0);
regmap_update_bits
Quoted 5 lines
sound/soc/codecs/Kconfig +2
-0+} +
Quoted 2 lines · Alexander Shiyan
...
Quoted 9 lines
sound/soc/codecs/Kconfig config SND_SOC_CS42XX8_I2C · line 467
Quoted 7 lines
sound/soc/codecs/Kconfig +7
-0+config SND_SOC_CS4341 +tristate "Cirrus Logic CS4341 CODEC" +depends on SPI_MASTER +select REGMAP_SPI +help + Enable support for Cirrus Logic (Crystal) CS4341 CODEC. +This devices primary interface is I2C. That should be added as well since i2c is read/write and spi is write only.
I can add I2C support, but can not test this.
...
Quoted 10 lines
sound/soc/codecs/cs4341.c line 133
Quoted 8 lines
sound/soc/codecs/cs4341.c new file +8
-0+snd_soc_update_bits (codec,CS4341_REG_MODE2 ,CS4341_MODE2_DIF , + bits24 ?CS4341_MODE2_DIF_RJ_24 : +CS4341_MODE2_DIF_RJ_16 ); +break ; +default : +dev_err (codec->dev,"Unsupported DAI format\n" ); +return -EINVAL ; +}Can we use
regmap_update_bitswhere we can?
So you say that regmap_update_bits() is prefferred than snd_soc_update_bits() ?
---
Mark Brown
maintainerQuoted 5 lines · Alexander Shiyan
Quoted 3 lines · Alexander Shiyan
Can we use
regmap_update_bitswhere we can?So you say that
regmap_update_bits()is prefferred thansnd_soc_update_bits()?
It's a bit better, yes.
Quoted 14 lines · Alexander Shiyan
Quoted 2 lines · Alexander Shiyan
...
Quoted 10 lines
sound/soc/codecs/Kconfig config SND_SOC_CS42XX8_I2C · line 467
Quoted 7 lines
sound/soc/codecs/Kconfig +7
-0+config SND_SOC_CS4341 +tristate "Cirrus Logic CS4341 CODEC" +depends on SPI_MASTER +select REGMAP_SPI +help + Enable support for Cirrus Logic (Crystal) CS4341 CODEC. +This devices primary interface is I2C. That should be added as well since
i2c is read/write and spi is write only.
Quoted 1 line
I can add I2C support, but can not test this.
OK, that is fine. We can add a patch to support I2C after that.
Quoted 13 lines
...
Quoted 10 lines
sound/soc/codecs/cs4341.c line 133
Quoted 8 lines
sound/soc/codecs/cs4341.c new file +8
-0+snd_soc_update_bits (codec,CS4341_REG_MODE2 ,CS4341_MODE2_DIF , + bits24 ?CS4341_MODE2_DIF_RJ_24 : +CS4341_MODE2_DIF_RJ_16 ); +break ; +default : +dev_err (codec->dev,"Unsupported DAI format\n" ); +return -EINVAL ; +}Can we use
regmap_update_bitswhere we can?
Quoted 2 lines
So you say that
regmap_update_bits()is prefferred thansnd_soc_update_bits()?
Yes.
Quoted 10 lines
---
_______________________________________________
Alsa-devel mailing list
[email protected]
https://urldefense.proofpoint.com/v2/url?u=http-3A__mailman.alsa-2Dproject
.org_mailman_listinfo_alsa-2Ddevel&d=DQICAg&c=O3LcjD-V2Iepl5V0N1424A&r=NJt NI3T_InLOY17xIGk4jdUC7XljFdoy6miaxhGHOOI&m=D9AVC8o2an1rQHYC1xfoGKGHyAfKmCk 0R0ahr8l8n3Q&s=EaM-NwVFymokJtsVOM7graacnT_2n68TY32zeMkDSbw&e=
Mark Brown
maintainersound/soc/codecs/cs4341.c line 78
Quoted 6 lines · Alexander Shiyan
sound/soc/codecs/cs4341.c new file +6
-0+switch (format &SND_SOC_DAIFMT_INV_MASK ) { +case SND_SOC_DAIFMT_NB_NF : +break ; +default : + goto fmt_err; + }
Why the goto? Just put the error handling code in here directly.
sound/soc/codecs/cs4341.c line 87
Quoted 8 lines
sound/soc/codecs/cs4341.c new file +8
-0+switch (format &SND_SOC_DAIFMT_FORMAT_MASK ) { +case SND_SOC_DAIFMT_I2S : +case SND_SOC_DAIFMT_LEFT_J : +case SND_SOC_DAIFMT_RIGHT_J : + cs4341->fmt = format &SND_SOC_DAIFMT_FORMAT_MASK ; +return 0 ; +default : +break ;
We silently ignore invalid formats here...
sound/soc/codecs/cs4341.c line 188
Quoted 1 line
sound/soc/codecs/cs4341.c new file +1
-0+ SOC_SINGLE("Popguard Transient Control", CS4341_REG_MODE2, 1, 1, 0),
Popguard Transient Switch so that userspace tools know how to handle this.
sound/soc/codecs/cs4341.c line 230
Quoted 2 lines
sound/soc/codecs/cs4341.c new file +2
-0+ spi->bits_per_word = spi->bits_per_word ? :8 ; + spi->max_speed_hz = spi->max_speed_hz ? :6000000 ;
Please write normal if statements, it's easier to read..