ASoC: CS4271 codec support
Subsystems (3)
PATCH 2/3 ASoC: CS4271 codec support
From: Alexander Sverdlin <[email protected]>
Added support for CS4271 codec to ASoC.
--- include/sound/cs4271.h | 25 ++ sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/cs4271.c | 607 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 638 insertions(+), 0 deletions(-)
include/sound/cs4271.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Definitions for CS4271 ASoC codec driver +* +* Copyright (c) 2010 Alexander Sverdlin <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef __CS4271_H +#define __CS4271_H + +struct cs4271_platform_data { +int gpio_nreset;/* GPIO driving Reset pin, if any */ +int gpio_disable;/* GPIO that disable serial bus, if any */ +}; + +#endif /* __CS4271_H */
sound/soc/codecs/Kconfig +4 -0
@@ -26,6 +26,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC select SND_SOC_CS42L51 if I2C select SND_SOC_CS4270 if I2C + select SND_SOC_CS4271 if SND_SOC_I2C_AND_SPI select SND_SOC_CX20442 select SND_SOC_DA7210 if I2C select SND_SOC_JZ4740_CODEC if SOC_JZ4740
@@ -154,6 +155,9 @@ config SND_SOC_CS4270_VD33_ERRATA bool depends on SND_SOC_CS4270 +config SND_SOC_CS4271 + tristate + config SND_SOC_CX20442 tristate
sound/soc/codecs/Makefile +2 -0
@@ -12,6 +12,7 @@ snd-soc-ak4671-objs := ak4671.o snd-soc-cq93vc-objs := cq93vc.o snd-soc-cs42l51-objs := cs42l51.o snd-soc-cs4270-objs := cs4270.o +snd-soc-cs4271-objs := cs4271.o snd-soc-cx20442-objs := cx20442.o snd-soc-da7210-objs := da7210.o snd-soc-l3-objs := l3.o
@@ -89,6 +90,7 @@ obj-$(CONFIG_SND_SOC_AK4671) += snd-soc-ak4671.o obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o obj-$(CONFIG_SND_SOC_CS42L51) += snd-soc-cs42l51.o obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o +obj-$(CONFIG_SND_SOC_CS4271) += snd-soc-cs4271.o obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
sound/soc/codecs/cs4271.c new file +607 -0
607 lines not on this page · raw message
Quoted 5 lines · Alexander
From: Alexander Sverdlin <[email protected]>
Added support for CS4271 codec to ASoC.
Signed-off-by Alexander Sverdlin <[email protected]>
Overall this looks very good but a few issues below, mostly coding style/clarity.
Quoted 8 lines
sound/soc/codecs/cs4271.c new file +8
-0+static int cs4271_set_dai_fmt (struct snd_soc_dai *codec_dai, +unsigned int format) +{ +struct snd_soc_codec *codec = codec_dai->codec; +struct cs4271_private *cs4271 =snd_soc_codec_get_drvdata (codec); + + cs4271->mode = format &SND_SOC_DAIFMT_FORMAT_MASK ; +
sound/soc/codecs/cs4271.c line 211
Quoted 10 lines
sound/soc/codecs/cs4271.c new file +10
-0+switch (format &SND_SOC_DAIFMT_MASTER_MASK ) { +default : +dev_err (codec->dev,"Invalid DAI format\n" ); +return -EINVAL ; +case SND_SOC_DAIFMT_CBS_CFS : + cs4271->master =0 ; +break ; +case SND_SOC_DAIFMT_CBM_CFM : + cs4271->master =1 ; + }
Missing break; It's also much more usual to have the default: case be the last one. Similarly for your other switch statements.
sound/soc/codecs/cs4271.c line 261
Quoted 4 lines
sound/soc/codecs/cs4271.c new file +4
-0+/* Configure ADC */ +snd_soc_update_bits (codec,CS4271_ADCCTL ,CS4271_ADCCTL_ADC_DIF_MASK , + (cs4271->mode ==SND_SOC_DAIFMT_I2S ) ? +CS4271_ADCCTL_ADC_DIF_I2S :CS4271_ADCCTL_ADC_DIF_LJ );
Please don't use the ternery operator like this, it's not terribly legible.
sound/soc/codecs/cs4271.c line 288
Quoted 3 lines
sound/soc/codecs/cs4271.c new file +3
-0+static const char *cs4271_de_texts[] = {"None" ,"44.1KHz" ,"48KHz" ,"32KHz" }; +static const struct soc_enum cs4271_de_enum = +SOC_ENUM_SINGLE (CS4271_DACCTL ,4 ,4 , cs4271_de_texts);
Ideally the deemphasis would be managed based on the sample rate.
sound/soc/codecs/cs4271.c line 325
Quoted 9 lines
sound/soc/codecs/cs4271.c new file +9
-0+struct snd_soc_dai_driver cs4271_dai = { + .name ="cs4271-hifi" , + .playback = { + .stream_name ="Playback" , + .channels_min =2 , + .channels_max =2 , + .rates =SNDRV_PCM_RATE_8000_96000 , + .rate_min =8000 , + .rate_max =96000 ,
No need to set rate_min and rate_max if rates is set.
Looking at the code above I suspect you need to set symmetric_rates on the DAI too - it looks like the playback and capture must be at the same rate.
Quoted 5 lines
sound/soc/codecs/cs4271.c new file +5
-0+/* +* This function writes all writeble registers from cache to codec. +* It's used to setup initial config and restore after suspend. +*/ +static int cs4271_write_cache (struct snd_soc_codec *codec)
sound/soc/codecs/cs4271.c line 354
Quoted 10 lines
sound/soc/codecs/cs4271.c new file +10
-0+{ +int i, ret; + +for (i =CS4271_LASTREG ; i >=CS4271_FIRSTREG ; i--) { + ret =snd_soc_write (codec, i,snd_soc_read (codec, i)); +if (ret) { +dev_err (codec->dev,"Cache write failed\n" ); +return ret; + } + }
If you use the standard cache code in soc-cache.c there's a standard cache sync implementation you could use - snd_soc_cache_sync().
Quoted 5 lines
sound/soc/codecs/cs4271.c new file +5
-0+#ifdef CONFIG_PM +static int cs4271_soc_suspend (struct snd_soc_codec *codec,pm_message_t mesg) +{ +/* Set power-down bit */ + snd_soc_update_bits(codec, CS4271_MODE2, CS4271_MODE2_PDN,
sound/soc/codecs/cs4271.c line 373
Quoted 10 lines
sound/soc/codecs/cs4271.c new file +10
-0+ CS4271_MODE2_PDN); + + return 0; +} +#else +#define cs4271_soc_suspend NULL +#endif /* CONFIG_PM */ + +static int cs4271_soc_resume (struct snd_soc_codec *codec) +{
A comment explaining why this isn't in the ifdef above would be useful. I guessed why it was being done before I searched but it'd be good to be clear.
sound/soc/codecs/cs4271.c line 408
Quoted 5 lines
sound/soc/codecs/cs4271.c new file +5
-0+if ((gpio_disable >=0 ) && +gpio_request (gpio_disable,"CS4271 Disable" )) + gpio_disable = -EINVAL ; +if (gpio_disable >=0 ) +gpio_direction_output (gpio_disable,0 );
This is quite hard to read. One issue is that the indentation of the second argument to the && is very confusing as it's lined up with the contents of the if statement, the other is that non-explicit check on the return value of gpio_request() means the expected value is not so clear as it could be.
sound/soc/codecs/cs4271.c line 553
Quoted 3 lines
sound/soc/codecs/cs4271.c new file +3
-0+static struct i2c_driver cs4271_i2c_driver = { + .driver = { + .name ="cs4271-codec" ,
No need for the -codec.
Dear Mark,
Quoted 6 lines · Mark Brown
sound/soc/codecs/cs4271.c line 288
Quoted 3 lines
sound/soc/codecs/cs4271.c new file +3
-0+static const char *cs4271_de_texts[] = {"None" ,"44.1KHz" ,"48KHz" ,"32KHz" }; +static const struct soc_enum cs4271_de_enum = +SOC_ENUM_SINGLE (CS4271_DACCTL ,4 ,4 , cs4271_de_texts);Ideally the deemphasis would be managed based on the sample rate.
I'm not sure if it's necessary feature at all. And the way it should be managed is something unclear to me )
All other issues were corrected, the patch will follow soon...
Best regards,
Alexander A. Sverdlin.
Quoted 6 lines · Alexander
Quoted 1 line · Mark Brown
Ideally the deemphasis would be managed based on the sample rate.
I'm not sure if it's necessary feature at all. And the way it should be managed is something unclear to me )
Provide the user with an on/off switch then if enabled select the deemphasis filter which is closest to the sample rate. It's not essential to provide the control but you may as well.
Hi Alexander,
I can't comment on the codec side of things but a couple of general comments inline. Otherwise looks good to me!
Jamie
Quoted 12 lines · Alexander
From: Alexander Sverdlin <[email protected]>
Added support for CS4271 codec to ASoC.
Signed-off-by Alexander Sverdlin <[email protected]>--- include/sound/cs4271.h | 25 ++ sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/cs4271.c | 607 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 638 insertions(+), 0 deletions(-)
[...]
Quoted 6 lines
sound/soc/codecs/cs4271.c new file +0
-0@@ -0,0 +1,607 @@
[...]
sound/soc/codecs/cs4271.c line 155
Quoted 12 lines
sound/soc/codecs/cs4271.c new file +12
-0+struct cs4271_private { +/* SND_SOC_I2C or SND_SOC_SPI */ +enum snd_soc_control_type bus_type; +void *control_data; +unsigned int mclk; +/* SND_SOC_DAIFMT_I2S or SND_SOC_DAIFMT_LEFT_J */ +unsigned int mode; +unsigned int master; +/* GPIO driving Reset pin, if any */ +int gpio_nreset; +/* GPIO that disable serial bus, if any */ +int gpio_disable;
Align gpio_nreset and gpio_disable with the other fields?
[...]
Quoted 17 lines
sound/soc/codecs/cs4271.c new file +17
-0+#if defined(CONFIG_SPI_MASTER ) +static int __devinit cs4271_spi_probe (struct spi_device *spi) +{ +struct cs4271_private *cs4271; +int ret; + + cs4271 =kzalloc (sizeof (*cs4271),GFP_KERNEL ); +if (!cs4271) +return -ENOMEM ; + +spi_set_drvdata (spi, cs4271); + cs4271->control_data = spi; + cs4271->bus_type =SND_SOC_SPI ; + + ret =snd_soc_register_codec (&spi->dev, &soc_codec_dev_cs4271, + &cs4271_dai,1 ); +if (ret <0 )
sound/soc/codecs/cs4271.c line 504
Quoted 10 lines
sound/soc/codecs/cs4271.c new file +10
-0+kfree (cs4271); +return ret; +} + +static int __devexit cs4271_spi_remove(struct spi_device *spi) +{ +snd_soc_unregister_codec (&spi->dev); +kfree (spi_get_drvdata (spi)); +return 0 ; +}
Is it worth using devm_kzalloc() for the i2c and spi probe functions to simplify the error handling and release functions? Admittedly they are fairly simple functions though.
[...]
Quoted 32 lines
sound/soc/codecs/cs4271.c new file +32
-0+/* +* We only register our serial bus driver here without +* assignment to particular chip. So if any of the below +* fails, there is some problem with I2C or SPI subsystem. +* In most cases this module will be compiled with support +* of only one serial bus. +*/ +static int __init cs4271_modinit (void ) +{ +int ret; + +#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE ) + ret =i2c_add_driver (&cs4271_i2c_driver); +if (ret) { +pr_err ("Failed to register CS4271 I2C driver: %d\n" , ret); +return ret; + } +#endif + +#if defined(CONFIG_SPI_MASTER ) + ret =spi_register_driver (&cs4271_spi_driver); +if (ret) { +pr_err ("Failed to register CS4271 SPI driver: %d\n" , ret); +return ret; + } +#endif + +return 0 ; +} +module_init (cs4271_modinit); + +static void __exit cs4271_modexit(void)
sound/soc/codecs/cs4271.c line 603
Quoted 10 lines
sound/soc/codecs/cs4271.c new file +10
-0+{ +#if defined(CONFIG_SPI_MASTER ) +spi_unregister_driver (&cs4271_spi_driver); +#endif + +#if defined(CONFIG_I2C ) || defined(CONFIG_I2C_MODULE ) +i2c_del_driver (&cs4271_i2c_driver); +#endif +} +module_exit (cs4271_modexit);
Doesn't the dependency on SND_SOC_I2C_AND_SPI mean that you will always have I2C and SPI_MASTER?
Quoted 2 lines · Jamie Iles
Doesn't the dependency on
SND_SOC_I2C_AND_SPImean that you will always have I2C andSPI_MASTER?
It's not a dependency for the CODEC driver at all. It means that when SND_SOC_ALL_CODECS is selecting the module it will ensure that a consistent combination of options is chosen but it is unrelated to use in machine drivers and doesn't force both to be enabled even when it is selected.
Quoted 10 lines · Mark Brown
Quoted 2 lines · Jamie Iles
Doesn't the dependency on
SND_SOC_I2C_AND_SPImean that you will always have I2C andSPI_MASTER?It's not a dependency for the CODEC driver at all. It means that when
SND_SOC_ALL_CODECSis selecting the module it will ensure that a consistent combination of options is chosen but it is unrelated to use in machine drivers and doesn't force both to be enabled even when it is selected.
Ahh, thanks for the explanation, I completely misunderstood the way that the codecs were selected by the arch's in sound/soc/* and assumed that they were user selectable options.
Jamie
Quoted 3 lines · Jamie Iles
Ahh, thanks for the explanation, I completely misunderstood the way that the codecs were selected by the arch's in
sound/soc/*and assumed that they were user selectable options.
They're not user selectable as you have to write explicit code to glue the machine together - that per machine code just selects the CODEC drivers it needs.