From ff637d38ea6b9c54f708a2b9edabc1b0c73c6d0a Mon Sep 17 00:00:00 2001 From: Timur Tabi Date: Thu, 22 Jan 2009 18:23:39 -0600 Subject: ASoC: remove stand-alone mode support from CS4270 codec driver The CS4270 supports stand-alone mode, where the codec is not connect to the I2C or SPI buses. Instead, input voltages configure the codec at power-on. The CS4270 ASoC device driver has partial support for this mode, but the code was never tested, and partial support doesn't help anyone. It also made the rest of the code more complicated than necessary. [Removed redundant CS4270 dependency on I2C -- broonie] Signed-off-by: Timur Tabi Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 92 ++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 65 deletions(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index f1aa0c34421..2e4ce04925e 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -12,11 +12,7 @@ * * Current features/limitations: * - * 1) Software mode is supported. Stand-alone mode is automatically - * selected if I2C is disabled or if a CS4270 is not found on the I2C - * bus. However, stand-alone mode is only partially implemented because - * there is no mechanism yet for this driver and the machine driver to - * communicate the values of the M0, M1, MCLK1, and MCLK2 pins. + * 1) Software mode is supported. Stand-alone mode is not supported. * 2) Only I2C is supported, not SPI * 3) Only Master mode is supported, not Slave. * 4) The machine driver's 'startup' function must call @@ -33,14 +29,6 @@ #include #include -#include "cs4270.h" - -/* If I2C is defined, then we support software mode. However, if we're - not compiled as module but I2C is, then we can't use I2C calls. */ -#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) -#define USE_I2C -#endif - /* Private data for the CS4270 */ struct cs4270_private { unsigned int mclk; /* Input frequency of the MCLK pin */ @@ -60,8 +48,6 @@ struct cs4270_private { SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \ SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) -#ifdef USE_I2C - /* CS4270 registers addresses */ #define CS4270_CHIPID 0x01 /* Chip ID */ #define CS4270_PWRCTL 0x02 /* Power Control */ @@ -271,17 +257,6 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai, return ret; } -/* - * A list of addresses on which this CS4270 could use. I2C addresses are - * 7 bits. For the CS4270, the upper four bits are always 1001, and the - * lower three bits are determined via the AD2, AD1, and AD0 pins - * (respectively). - */ -static const unsigned short normal_i2c[] = { - 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, I2C_CLIENT_END -}; -I2C_CLIENT_INSMOD; - /* * Pre-fill the CS4270 register cache. * @@ -476,7 +451,6 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, } #ifdef CONFIG_SND_SOC_CS4270_HWMUTE - /* * Set the CS4270 external mute * @@ -501,32 +475,16 @@ static int cs4270_mute(struct snd_soc_dai *dai, int mute) return snd_soc_write(codec, CS4270_MUTE, reg6); } - +#else +#define cs4270_mute NULL #endif -static int cs4270_i2c_probe(struct i2c_client *, const struct i2c_device_id *); - /* A list of non-DAPM controls that the CS4270 supports */ static const struct snd_kcontrol_new cs4270_snd_controls[] = { SOC_DOUBLE_R("Master Playback Volume", CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1) }; -static const struct i2c_device_id cs4270_id[] = { - {"cs4270", 0}, - {} -}; -MODULE_DEVICE_TABLE(i2c, cs4270_id); - -static struct i2c_driver cs4270_i2c_driver = { - .driver = { - .name = "CS4270 I2C", - .owner = THIS_MODULE, - }, - .id_table = cs4270_id, - .probe = cs4270_i2c_probe, -}; - /* * Global variable to store socdev for i2c probe function. * @@ -633,7 +591,20 @@ error: return ret; } -#endif /* USE_I2C*/ +static const struct i2c_device_id cs4270_id[] = { + {"cs4270", 0}, + {} +}; +MODULE_DEVICE_TABLE(i2c, cs4270_id); + +static struct i2c_driver cs4270_i2c_driver = { + .driver = { + .name = "cs4270", + .owner = THIS_MODULE, + }, + .id_table = cs4270_id, + .probe = cs4270_i2c_probe, +}; struct snd_soc_dai cs4270_dai = { .name = "CS4270", @@ -698,7 +669,6 @@ static int cs4270_probe(struct platform_device *pdev) goto error_free_codec; } -#ifdef USE_I2C cs4270_socdev = socdev; ret = i2c_add_driver(&cs4270_i2c_driver); @@ -708,20 +678,16 @@ static int cs4270_probe(struct platform_device *pdev) } /* Did we find a CS4270 on the I2C bus? */ - if (codec->control_data) { - /* Initialize codec ops */ - cs4270_dai.ops.hw_params = cs4270_hw_params; - cs4270_dai.ops.set_sysclk = cs4270_set_dai_sysclk; - cs4270_dai.ops.set_fmt = cs4270_set_dai_fmt; -#ifdef CONFIG_SND_SOC_CS4270_HWMUTE - cs4270_dai.ops.digital_mute = cs4270_mute; -#endif - } else - printk(KERN_INFO "cs4270: no I2C device found, " - "using stand-alone mode\n"); -#else - printk(KERN_INFO "cs4270: I2C disabled, using stand-alone mode\n"); -#endif + if (!codec->control_data) { + printk(KERN_ERR "cs4270: failed to attach driver"); + goto error_del_driver; + } + + /* Initialize codec ops */ + cs4270_dai.ops.hw_params = cs4270_hw_params; + cs4270_dai.ops.set_sysclk = cs4270_set_dai_sysclk; + cs4270_dai.ops.set_fmt = cs4270_set_dai_fmt; + cs4270_dai.ops.digital_mute = cs4270_mute; ret = snd_soc_init_card(socdev); if (ret < 0) { @@ -732,11 +698,9 @@ static int cs4270_probe(struct platform_device *pdev) return 0; error_del_driver: -#ifdef USE_I2C i2c_del_driver(&cs4270_i2c_driver); error_free_pcms: -#endif snd_soc_free_pcms(socdev); error_free_codec: @@ -752,9 +716,7 @@ static int cs4270_remove(struct platform_device *pdev) snd_soc_free_pcms(socdev); -#ifdef USE_I2C i2c_del_driver(&cs4270_i2c_driver); -#endif kfree(socdev->codec); socdev->codec = NULL; -- cgit v1.2.3 From 01e097d6c409a6eb64758dce9fcde0c70073fe36 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 23 Jan 2009 15:07:45 +0000 Subject: ASoC: Include header file in cs4270 and wm9705 Ensures that the DAI and socdev exported by the codec match up with their exported prototype. Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 2e4ce04925e..e2130d7b1e4 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -29,6 +29,8 @@ #include #include +#include "cs4270.h" + /* Private data for the CS4270 */ struct cs4270_private { unsigned int mclk; /* Input frequency of the MCLK pin */ -- cgit v1.2.3 From 0db4d0705260dd4bddf1e5a5441c58bdf08bdc9f Mon Sep 17 00:00:00 2001 From: Timur Tabi Date: Fri, 23 Jan 2009 16:31:19 -0600 Subject: ASoC: improve I2C initialization code in CS4270 driver Further improvements in the I2C initialization sequence of the CS4270 driver. All ASoC initialization is now done in the I2C probe function. Signed-off-by: Timur Tabi Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 252 +++++++++++++++++++++------------------------- 1 file changed, 113 insertions(+), 139 deletions(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index e2130d7b1e4..2aa12fdbd2c 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -31,12 +31,6 @@ #include "cs4270.h" -/* Private data for the CS4270 */ -struct cs4270_private { - unsigned int mclk; /* Input frequency of the MCLK pin */ - unsigned int mode; /* The mode (I2S or left-justified) */ -}; - /* * The codec isn't really big-endian or little-endian, since the I2S * interface requires data to be sent serially with the MSbit first. @@ -109,6 +103,14 @@ struct cs4270_private { #define CS4270_MUTE_DAC_A 0x01 #define CS4270_MUTE_DAC_B 0x02 +/* Private data for the CS4270 */ +struct cs4270_private { + struct snd_soc_codec codec; + u8 reg_cache[CS4270_NUMREGS]; + unsigned int mclk; /* Input frequency of the MCLK pin */ + unsigned int mode; /* The mode (I2S or left-justified) */ +}; + /* * Clock Ratio Selection for Master Mode with I2C enabled * @@ -504,6 +506,31 @@ static const struct snd_kcontrol_new cs4270_snd_controls[] = { */ static struct snd_soc_device *cs4270_socdev; +struct snd_soc_dai cs4270_dai = { + .name = "cs4270", + .playback = { + .stream_name = "Playback", + .channels_min = 1, + .channels_max = 2, + .rates = 0, + .formats = CS4270_FORMATS, + }, + .capture = { + .stream_name = "Capture", + .channels_min = 1, + .channels_max = 2, + .rates = 0, + .formats = CS4270_FORMATS, + }, + .ops = { + .hw_params = cs4270_hw_params, + .set_sysclk = cs4270_set_dai_sysclk, + .set_fmt = cs4270_set_dai_fmt, + .digital_mute = cs4270_mute, + }, +}; +EXPORT_SYMBOL_GPL(cs4270_dai); + /* * Initialize the I2C interface of the CS4270 * @@ -517,47 +544,52 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, const struct i2c_device_id *id) { struct snd_soc_device *socdev = cs4270_socdev; - struct snd_soc_codec *codec = socdev->codec; + struct snd_soc_codec *codec; + struct cs4270_private *cs4270; int i; int ret = 0; - /* Probing all possible addresses has one drawback: if there are - multiple CS4270s on the bus, then you cannot specify which - socdev is matched with which CS4270. For now, we just reject - this I2C device if the socdev already has one attached. */ - if (codec->control_data) - return -ENODEV; - - /* Note: codec_dai->codec is NULL here */ - - codec->reg_cache = kzalloc(CS4270_NUMREGS, GFP_KERNEL); - if (!codec->reg_cache) { - printk(KERN_ERR "cs4270: could not allocate register cache\n"); - ret = -ENOMEM; - goto error; - } - /* Verify that we have a CS4270 */ ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID); if (ret < 0) { printk(KERN_ERR "cs4270: failed to read I2C\n"); - goto error; + return ret; } /* The top four bits of the chip ID should be 1100. */ if ((ret & 0xF0) != 0xC0) { - /* The device at this address is not a CS4270 codec */ - ret = -ENODEV; - goto error; + printk(KERN_ERR "cs4270: device at addr %X is not a CS4270\n", + i2c_client->addr); + return -ENODEV; } printk(KERN_INFO "cs4270: found device at I2C address %X\n", i2c_client->addr); printk(KERN_INFO "cs4270: hardware revision %X\n", ret & 0xF); + /* Allocate enough space for the snd_soc_codec structure + and our private data together. */ + cs4270 = kzalloc(sizeof(struct cs4270_private), GFP_KERNEL); + if (!cs4270) { + printk(KERN_ERR "cs4270: Could not allocate codec structure\n"); + return -ENOMEM; + } + codec = &cs4270->codec; + socdev->codec = codec; + + mutex_init(&codec->mutex); + INIT_LIST_HEAD(&codec->dapm_widgets); + INIT_LIST_HEAD(&codec->dapm_paths); + + codec->name = "CS4270"; + codec->owner = THIS_MODULE; + codec->dai = &cs4270_dai; + codec->num_dai = 1; + codec->private_data = cs4270; codec->control_data = i2c_client; codec->read = cs4270_read_reg_cache; codec->write = cs4270_i2c_write; + codec->reg_cache = cs4270->reg_cache; codec->reg_cache_size = CS4270_NUMREGS; /* The I2C interface is set up, so pre-fill our register cache */ @@ -565,35 +597,72 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, ret = cs4270_fill_cache(codec); if (ret < 0) { printk(KERN_ERR "cs4270: failed to fill register cache\n"); - goto error; + goto error_free_codec; + } + + /* Register PCMs */ + + ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); + if (ret < 0) { + printk(KERN_ERR "cs4270: failed to create PCMs\n"); + goto error_free_codec; } /* Add the non-DAPM controls */ for (i = 0; i < ARRAY_SIZE(cs4270_snd_controls); i++) { - struct snd_kcontrol *kctrl = - snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL); + struct snd_kcontrol *kctrl; + + kctrl = snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL); + if (!kctrl) { + printk(KERN_ERR "cs4270: error creating control '%s'\n", + cs4270_snd_controls[i].name); + ret = -ENOMEM; + goto error_free_pcms; + } ret = snd_ctl_add(codec->card, kctrl); - if (ret < 0) - goto error; + if (ret < 0) { + printk(KERN_ERR "cs4270: error adding control '%s'\n", + cs4270_snd_controls[i].name); + goto error_free_pcms; + } } - i2c_set_clientdata(i2c_client, codec); + /* Initialize the SOC device */ + + ret = snd_soc_init_card(socdev); + if (ret < 0) { + printk(KERN_ERR "cs4270: failed to register card\n"); + goto error_free_pcms;; + } + + i2c_set_clientdata(i2c_client, socdev); return 0; -error: - codec->control_data = NULL; +error_free_pcms: + snd_soc_free_pcms(socdev); - kfree(codec->reg_cache); - codec->reg_cache = NULL; - codec->reg_cache_size = 0; +error_free_codec: + kfree(cs4270); return ret; } -static const struct i2c_device_id cs4270_id[] = { +static int cs4270_i2c_remove(struct i2c_client *i2c_client) +{ + struct snd_soc_device *socdev = i2c_get_clientdata(i2c_client); + struct snd_soc_codec *codec = socdev->codec; + struct cs4270_private *cs4270 = codec->private_data; + + snd_soc_free_pcms(socdev); + kfree(cs4270); + + return 0; +} + +static struct i2c_device_id cs4270_id[] = { {"cs4270", 0}, {} }; @@ -606,27 +675,9 @@ static struct i2c_driver cs4270_i2c_driver = { }, .id_table = cs4270_id, .probe = cs4270_i2c_probe, + .remove = cs4270_i2c_remove, }; -struct snd_soc_dai cs4270_dai = { - .name = "CS4270", - .playback = { - .stream_name = "Playback", - .channels_min = 1, - .channels_max = 2, - .rates = 0, - .formats = CS4270_FORMATS, - }, - .capture = { - .stream_name = "Capture", - .channels_min = 1, - .channels_max = 2, - .rates = 0, - .formats = CS4270_FORMATS, - }, -}; -EXPORT_SYMBOL_GPL(cs4270_dai); - /* * ASoC probe function * @@ -635,94 +686,15 @@ EXPORT_SYMBOL_GPL(cs4270_dai); */ static int cs4270_probe(struct platform_device *pdev) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - printk(KERN_INFO "CS4270 ALSA SoC Codec\n"); - - /* Allocate enough space for the snd_soc_codec structure - and our private data together. */ - codec = kzalloc(ALIGN(sizeof(struct snd_soc_codec), 4) + - sizeof(struct cs4270_private), GFP_KERNEL); - if (!codec) { - printk(KERN_ERR "cs4270: Could not allocate codec structure\n"); - return -ENOMEM; - } - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->name = "CS4270"; - codec->owner = THIS_MODULE; - codec->dai = &cs4270_dai; - codec->num_dai = 1; - codec->private_data = (void *) codec + - ALIGN(sizeof(struct snd_soc_codec), 4); - - socdev->codec = codec; - - /* Register PCMs */ - - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "cs4270: failed to create PCMs\n"); - goto error_free_codec; - } - - cs4270_socdev = socdev; - - ret = i2c_add_driver(&cs4270_i2c_driver); - if (ret) { - printk(KERN_ERR "cs4270: failed to attach driver"); - goto error_free_pcms; - } - - /* Did we find a CS4270 on the I2C bus? */ - if (!codec->control_data) { - printk(KERN_ERR "cs4270: failed to attach driver"); - goto error_del_driver; - } + cs4270_socdev = platform_get_drvdata(pdev);; - /* Initialize codec ops */ - cs4270_dai.ops.hw_params = cs4270_hw_params; - cs4270_dai.ops.set_sysclk = cs4270_set_dai_sysclk; - cs4270_dai.ops.set_fmt = cs4270_set_dai_fmt; - cs4270_dai.ops.digital_mute = cs4270_mute; - - ret = snd_soc_init_card(socdev); - if (ret < 0) { - printk(KERN_ERR "cs4270: failed to register card\n"); - goto error_del_driver; - } - - return 0; - -error_del_driver: - i2c_del_driver(&cs4270_i2c_driver); - -error_free_pcms: - snd_soc_free_pcms(socdev); - -error_free_codec: - kfree(socdev->codec); - socdev->codec = NULL; - - return ret; + return i2c_add_driver(&cs4270_i2c_driver); } static int cs4270_remove(struct platform_device *pdev) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - i2c_del_driver(&cs4270_i2c_driver); - kfree(socdev->codec); - socdev->codec = NULL; - return 0; } @@ -740,6 +712,8 @@ EXPORT_SYMBOL_GPL(soc_codec_device_cs4270); static int __init cs4270_init(void) { + printk(KERN_INFO "Cirrus Logic CS4270 ALSA SoC Codec Driver\n"); + return snd_soc_register_dai(&cs4270_dai); } module_init(cs4270_init); -- cgit v1.2.3 From 6627a653bceb3a54e55e5cdc478ec5b8d5c9cc44 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 23 Jan 2009 22:55:23 +0000 Subject: ASoC: Push the codec runtime storage into the card structure This is a further stage on the road to refactoring away the ASoC platform device. Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 2aa12fdbd2c..21253b48289 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -350,7 +350,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, { struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_device *socdev = rtd->socdev; - struct snd_soc_codec *codec = socdev->codec; + struct snd_soc_codec *codec = socdev->card->codec; struct cs4270_private *cs4270 = codec->private_data; int ret; unsigned int i; @@ -575,7 +575,7 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, return -ENOMEM; } codec = &cs4270->codec; - socdev->codec = codec; + socdev->card->codec = codec; mutex_init(&codec->mutex); INIT_LIST_HEAD(&codec->dapm_widgets); @@ -653,7 +653,7 @@ error_free_codec: static int cs4270_i2c_remove(struct i2c_client *i2c_client) { struct snd_soc_device *socdev = i2c_get_clientdata(i2c_client); - struct snd_soc_codec *codec = socdev->codec; + struct snd_soc_codec *codec = socdev->card->codec; struct cs4270_private *cs4270 = codec->private_data; snd_soc_free_pcms(socdev); -- cgit v1.2.3 From 04eb093c7c81d118efeb96228f69bc0179f71897 Mon Sep 17 00:00:00 2001 From: Timur Tabi Date: Thu, 29 Jan 2009 14:28:37 -0600 Subject: ASoC: fix initialization order of the CS4270 codec driver ASoC codec drivers typically serve two masters: the I2C bus and ASoC itself. When a codec driver registers with ASoC, a probe function is called. Most codec drivers call ASoC first, and then register with the I2C bus in the ASoC probe function. However, in order to support multiple codecs on one board, it's easier if the codec driver is probed via the I2C bus first. This is because the call to i2c_add_driver() can result in the I2C probe function being called multiple times - once for each codec. In the current design, the driver registers once with ASoC, and in the ASoC probe function, it calls i2c_add_driver(). The results in the I2C probe function being called multiple times before the driver can register with ASoC again. The new design has the driver call i2c_add_driver() first. In the I2C probe function, the driver registers with ASoC. This allows the ASoC probe function to be called once per I2C device. Also add code to check if the I2C probe function is called more than once, since that is not supported with the current ASoC design. Signed-off-by: Timur Tabi Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 177 +++++++++++++++++++++++++--------------------- 1 file changed, 97 insertions(+), 80 deletions(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 21253b48289..adc1150ddb0 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -490,21 +490,17 @@ static const struct snd_kcontrol_new cs4270_snd_controls[] = { }; /* - * Global variable to store socdev for i2c probe function. + * Global variable to store codec for the ASoC probe function. * * If struct i2c_driver had a private_data field, we wouldn't need to use - * cs4270_socdec. This is the only way to pass the socdev structure to - * cs4270_i2c_probe(). - * - * The real solution to cs4270_socdev is to create a mechanism - * that maps I2C addresses to snd_soc_device structures. Perhaps the - * creation of the snd_soc_device object should be moved out of - * cs4270_probe() and into cs4270_i2c_probe(), but that would make this - * driver dependent on I2C. The CS4270 supports "stand-alone" mode, whereby - * the chip is *not* connected to the I2C bus, but is instead configured via - * input pins. + * cs4270_codec. This is the only way to pass the codec structure from + * cs4270_i2c_probe() to cs4270_probe(). Unfortunately, there is no good + * way to synchronize these two functions. cs4270_i2c_probe() can be called + * multiple times before cs4270_probe() is called even once. So for now, we + * also only allow cs4270_i2c_probe() to be run once. That means that we do + * not support more than one cs4270 device in the system, at least for now. */ -static struct snd_soc_device *cs4270_socdev; +static struct snd_soc_codec *cs4270_codec; struct snd_soc_dai cs4270_dai = { .name = "cs4270", @@ -531,6 +527,70 @@ struct snd_soc_dai cs4270_dai = { }; EXPORT_SYMBOL_GPL(cs4270_dai); +/* + * ASoC probe function + */ +static int cs4270_probe(struct platform_device *pdev) +{ + struct snd_soc_device *socdev = platform_get_drvdata(pdev); + struct snd_soc_codec *codec = cs4270_codec; + unsigned int i; + int ret; + + /* Connect the codec to the socdev. snd_soc_new_pcms() needs this. */ + socdev->card->codec = codec; + + /* Register PCMs */ + ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); + if (ret < 0) { + printk(KERN_ERR "cs4270: failed to create PCMs\n"); + return ret; + } + + /* Add the non-DAPM controls */ + for (i = 0; i < ARRAY_SIZE(cs4270_snd_controls); i++) { + struct snd_kcontrol *kctrl; + + kctrl = snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL); + if (!kctrl) { + printk(KERN_ERR "cs4270: error creating control '%s'\n", + cs4270_snd_controls[i].name); + ret = -ENOMEM; + goto error_free_pcms; + } + + ret = snd_ctl_add(codec->card, kctrl); + if (ret < 0) { + printk(KERN_ERR "cs4270: error adding control '%s'\n", + cs4270_snd_controls[i].name); + goto error_free_pcms; + } + } + + /* And finally, register the socdev */ + ret = snd_soc_init_card(socdev); + if (ret < 0) { + printk(KERN_ERR "cs4270: failed to register card\n"); + goto error_free_pcms; + } + + return 0; + +error_free_pcms: + snd_soc_free_pcms(socdev); + + return ret; +} + +static int cs4270_remove(struct platform_device *pdev) +{ + struct snd_soc_device *socdev = platform_get_drvdata(pdev); + + snd_soc_free_pcms(socdev); + + return 0; +}; + /* * Initialize the I2C interface of the CS4270 * @@ -543,17 +603,27 @@ EXPORT_SYMBOL_GPL(cs4270_dai); static int cs4270_i2c_probe(struct i2c_client *i2c_client, const struct i2c_device_id *id) { - struct snd_soc_device *socdev = cs4270_socdev; struct snd_soc_codec *codec; struct cs4270_private *cs4270; - int i; - int ret = 0; + int ret; + + /* For now, we only support one cs4270 device in the system. See the + * comment for cs4270_codec. + */ + if (cs4270_codec) { + printk(KERN_ERR "cs4270: ignoring CS4270 at addr %X\n", + i2c_client->addr); + printk(KERN_ERR "cs4270: only one CS4270 per board allowed\n"); + /* Should we return something other than ENODEV here? */ + return -ENODEV; + } /* Verify that we have a CS4270 */ ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID); if (ret < 0) { - printk(KERN_ERR "cs4270: failed to read I2C\n"); + printk(KERN_ERR "cs4270: failed to read I2C at addr %X\n", + i2c_client->addr); return ret; } /* The top four bits of the chip ID should be 1100. */ @@ -575,7 +645,7 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, return -ENOMEM; } codec = &cs4270->codec; - socdev->card->codec = codec; + cs4270_codec = codec; mutex_init(&codec->mutex); INIT_LIST_HEAD(&codec->dapm_widgets); @@ -600,50 +670,20 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, goto error_free_codec; } - /* Register PCMs */ - - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); + /* Register the DAI. If all the other ASoC driver have already + * registered, then this will call our probe function, so + * cs4270_codec needs to be ready. + */ + ret = snd_soc_register_dai(&cs4270_dai); if (ret < 0) { - printk(KERN_ERR "cs4270: failed to create PCMs\n"); + printk(KERN_ERR "cs4270: failed to register DAIe\n"); goto error_free_codec; } - /* Add the non-DAPM controls */ - - for (i = 0; i < ARRAY_SIZE(cs4270_snd_controls); i++) { - struct snd_kcontrol *kctrl; - - kctrl = snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL); - if (!kctrl) { - printk(KERN_ERR "cs4270: error creating control '%s'\n", - cs4270_snd_controls[i].name); - ret = -ENOMEM; - goto error_free_pcms; - } - - ret = snd_ctl_add(codec->card, kctrl); - if (ret < 0) { - printk(KERN_ERR "cs4270: error adding control '%s'\n", - cs4270_snd_controls[i].name); - goto error_free_pcms; - } - } - - /* Initialize the SOC device */ - - ret = snd_soc_init_card(socdev); - if (ret < 0) { - printk(KERN_ERR "cs4270: failed to register card\n"); - goto error_free_pcms;; - } - - i2c_set_clientdata(i2c_client, socdev); + i2c_set_clientdata(i2c_client, cs4270); return 0; -error_free_pcms: - snd_soc_free_pcms(socdev); - error_free_codec: kfree(cs4270); @@ -652,11 +692,8 @@ error_free_codec: static int cs4270_i2c_remove(struct i2c_client *i2c_client) { - struct snd_soc_device *socdev = i2c_get_clientdata(i2c_client); - struct snd_soc_codec *codec = socdev->card->codec; - struct cs4270_private *cs4270 = codec->private_data; + struct cs4270_private *cs4270 = i2c_get_clientdata(i2c_client); - snd_soc_free_pcms(socdev); kfree(cs4270); return 0; @@ -678,26 +715,6 @@ static struct i2c_driver cs4270_i2c_driver = { .remove = cs4270_i2c_remove, }; -/* - * ASoC probe function - * - * This function is called when the machine driver calls - * platform_device_add(). - */ -static int cs4270_probe(struct platform_device *pdev) -{ - cs4270_socdev = platform_get_drvdata(pdev);; - - return i2c_add_driver(&cs4270_i2c_driver); -} - -static int cs4270_remove(struct platform_device *pdev) -{ - i2c_del_driver(&cs4270_i2c_driver); - - return 0; -} - /* * ASoC codec device structure * @@ -714,13 +731,13 @@ static int __init cs4270_init(void) { printk(KERN_INFO "Cirrus Logic CS4270 ALSA SoC Codec Driver\n"); - return snd_soc_register_dai(&cs4270_dai); + return i2c_add_driver(&cs4270_i2c_driver); } module_init(cs4270_init); static void __exit cs4270_exit(void) { - snd_soc_unregister_dai(&cs4270_dai); + i2c_del_driver(&cs4270_i2c_driver); } module_exit(cs4270_exit); -- cgit v1.2.3 From ff7bf02f630ae93cad4feda0f6a5a19b25a5019a Mon Sep 17 00:00:00 2001 From: Timur Tabi Date: Fri, 30 Jan 2009 11:14:49 -0600 Subject: ASoC: fix documentation in CS4270 codec driver Spruce up the documentation in the CS4270 codec. Use kerneldoc where appropriate. Fix incorrect comments. Signed-off-by: Timur Tabi Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 163 +++++++++++++++++++++++++++++----------------- 1 file changed, 105 insertions(+), 58 deletions(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index adc1150ddb0..e5f5afdd342 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -3,10 +3,10 @@ * * Author: Timur Tabi * - * Copyright 2007 Freescale Semiconductor, Inc. This file is licensed under - * the terms of the GNU General Public License version 2. This program - * is licensed "as is" without any warranty of any kind, whether express - * or implied. + * Copyright 2007-2009 Freescale Semiconductor, Inc. This file is licensed + * under the terms of the GNU General Public License version 2. This + * program is licensed "as is" without any warranty of any kind, whether + * express or implied. * * This is an ASoC device driver for the Cirrus Logic CS4270 codec. * @@ -111,8 +111,13 @@ struct cs4270_private { unsigned int mode; /* The mode (I2S or left-justified) */ }; -/* - * Clock Ratio Selection for Master Mode with I2C enabled +/** + * struct cs4270_mode_ratios - clock ratio tables + * @ratio: the ratio of MCLK to the sample rate + * @speed_mode: the Speed Mode bits to set in the Mode Control register for + * this ratio + * @mclk: the Ratio Select bits to set in the Mode Control register for this + * ratio * * The data for this chart is taken from Table 5 of the CS4270 reference * manual. @@ -121,31 +126,30 @@ struct cs4270_private { * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling * rates the CS4270 currently supports. * - * Each element in this array corresponds to the ratios in mclk_ratios[]. - * These two arrays need to be in sync. - * - * 'speed_mode' is the corresponding bit pattern to be written to the + * @speed_mode is the corresponding bit pattern to be written to the * MODE bits of the Mode Control Register * - * 'mclk' is the corresponding bit pattern to be wirten to the MCLK bits of + * @mclk is the corresponding bit pattern to be wirten to the MCLK bits of * the Mode Control Register. * * In situations where a single ratio is represented by multiple speed * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick * double-speed instead of quad-speed. However, the CS4270 errata states - * that Divide-By-1.5 can cause failures, so we avoid that mode where + * that divide-By-1.5 can cause failures, so we avoid that mode where * possible. * - * ERRATA: There is an errata for the CS4270 where divide-by-1.5 does not - * work if VD = 3.3V. If this effects you, select the + * Errata: There is an errata for the CS4270 where divide-by-1.5 does not + * work if Vd is 3.3V. If this effects you, select the * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will * never select any sample rates that require divide-by-1.5. */ -static struct { +struct cs4270_mode_ratios { unsigned int ratio; u8 speed_mode; u8 mclk; -} cs4270_mode_ratios[] = { +}; + +static struct cs4270_mode_ratios[] = { {64, CS4270_MODE_4X, CS4270_MODE_DIV1}, #ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA {96, CS4270_MODE_4X, CS4270_MODE_DIV15}, @@ -162,34 +166,27 @@ static struct { /* The number of MCLK/LRCK ratios supported by the CS4270 */ #define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios) -/* - * Determine the CS4270 samples rates. +/** + * cs4270_set_dai_sysclk - determine the CS4270 samples rates. + * @codec_dai: the codec DAI + * @clk_id: the clock ID (ignored) + * @freq: the MCLK input frequency + * @dir: the clock direction (ignored) * - * 'freq' is the input frequency to MCLK. The other parameters are ignored. + * This function is used to tell the codec driver what the input MCLK + * frequency is. * * The value of MCLK is used to determine which sample rates are supported * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine - * support values: 64, 96, 128, 192, 256, 384, 512, 768, and 1024. + * supported values - 64, 96, 128, 192, 256, 384, 512, 768, and 1024. * * This function calculates the nine ratios and determines which ones match * a standard sample rate. If there's a match, then it is added to the list - * of support sample rates. + * of supported sample rates. * * This function must be called by the machine driver's 'startup' function, * otherwise the list of supported sample rates will not be available in * time for ALSA. - * - * Note that in stand-alone mode, the sample rate is determined by input - * pins M0, M1, MDIV1, and MDIV2. Also in stand-alone mode, divide-by-3 - * is not a programmable option. However, divide-by-3 is not an available - * option in stand-alone mode. This cases two problems: a ratio of 768 is - * not available (it requires divide-by-3) and B) ratios 192 and 384 can - * only be selected with divide-by-1.5, but there is an errate that make - * this selection difficult. - * - * In addition, there is no mechanism for communicating with the machine - * driver what the input settings can be. This would need to be implemented - * for stand-alone mode to work. */ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, int clk_id, unsigned int freq, int dir) @@ -230,8 +227,10 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, return 0; } -/* - * Configure the codec for the selected audio format +/** + * cs4270_set_dai_fmt - configure the codec for the selected audio format + * @codec_dai: the codec DAI + * @format: a SND_SOC_DAIFMT_x value indicating the data format * * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the * codec accordingly. @@ -261,8 +260,16 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai, return ret; } -/* - * Pre-fill the CS4270 register cache. +/** + * cs4270_fill_cache - pre-fill the CS4270 register cache. + * @codec: the codec for this CS4270 + * + * This function fills in the CS4270 register cache by reading the register + * values from the hardware. + * + * This CS4270 registers are cached to avoid excessive I2C I/O operations. + * After the initial read to pre-fill the cache, the CS4270 never updates + * the register values, so we won't have a cache coherency problem. * * We use the auto-increment feature of the CS4270 to read all registers in * one shot. @@ -285,12 +292,17 @@ static int cs4270_fill_cache(struct snd_soc_codec *codec) return 0; } -/* - * Read from the CS4270 register cache. +/** + * cs4270_read_reg_cache - read from the CS4270 register cache. + * @codec: the codec for this CS4270 + * @reg: the register to read + * + * This function returns the value for a given register. It reads only from + * the register cache, not the hardware itself. * * This CS4270 registers are cached to avoid excessive I2C I/O operations. * After the initial read to pre-fill the cache, the CS4270 never updates - * the register values, so we won't have a cache coherncy problem. + * the register values, so we won't have a cache coherency problem. */ static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec, unsigned int reg) @@ -303,8 +315,11 @@ static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec, return cache[reg - CS4270_FIRSTREG]; } -/* - * Write to a CS4270 register via the I2C bus. +/** + * cs4270_i2c_write - write to a CS4270 register via the I2C bus. + * @codec: the codec for this CS4270 + * @reg: the register to write + * @value: the value to write to the register * * This function writes the given value to the given CS4270 register, and * also updates the register cache. @@ -336,11 +351,17 @@ static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg, return 0; } -/* - * Program the CS4270 with the given hardware parameters. +/** + * cs4270_hw_params - program the CS4270 with the given hardware parameters. + * @substream: the audio stream + * @params: the hardware parameters to set + * @dai: the SOC DAI (ignored) * - * The .ops functions are used to provide board-specific data, like - * input frequencies, to this driver. This function takes that information, + * This function programs the hardware with the values provided. + * Specifically, the sample rate and the data format. + * + * The .ops functions are used to provide board-specific data, like input + * frequencies, to this driver. This function takes that information, * combines it with the hardware parameters provided, and programs the * hardware accordingly. */ @@ -455,8 +476,10 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, } #ifdef CONFIG_SND_SOC_CS4270_HWMUTE -/* - * Set the CS4270 external mute +/** + * cs4270_mute - enable/disable the CS4270 external mute + * @dai: the SOC DAI + * @mute: 0 = disable mute, 1 = enable mute * * This function toggles the mute bits in the MUTE register. The CS4270's * mute capability is intended for external muting circuitry, so if the @@ -490,7 +513,7 @@ static const struct snd_kcontrol_new cs4270_snd_controls[] = { }; /* - * Global variable to store codec for the ASoC probe function. + * cs4270_codec - global variable to store codec for the ASoC probe function * * If struct i2c_driver had a private_data field, we wouldn't need to use * cs4270_codec. This is the only way to pass the codec structure from @@ -527,8 +550,12 @@ struct snd_soc_dai cs4270_dai = { }; EXPORT_SYMBOL_GPL(cs4270_dai); -/* - * ASoC probe function +/** + * cs4270_probe - ASoC probe function + * @pdev: platform device + * + * This function is called when ASoC has all the pieces it needs to + * instantiate a sound driver. */ static int cs4270_probe(struct platform_device *pdev) { @@ -582,6 +609,12 @@ error_free_pcms: return ret; } +/** + * cs4270_remove - ASoC remove function + * @pdev: platform device + * + * This function is the counterpart to cs4270_probe(). + */ static int cs4270_remove(struct platform_device *pdev) { struct snd_soc_device *socdev = platform_get_drvdata(pdev); @@ -591,14 +624,13 @@ static int cs4270_remove(struct platform_device *pdev) return 0; }; -/* - * Initialize the I2C interface of the CS4270 - * - * This function is called for whenever the I2C subsystem finds a device - * at a particular address. +/** + * cs4270_i2c_probe - initialize the I2C interface of the CS4270 + * @i2c_client: the I2C client object + * @id: the I2C device ID (ignored) * - * Note: snd_soc_new_pcms() must be called before this function can be called, - * because of snd_ctl_add(). + * This function is called whenever the I2C subsystem finds a device that + * matches the device ID given via a prior call to i2c_add_driver(). */ static int cs4270_i2c_probe(struct i2c_client *i2c_client, const struct i2c_device_id *id) @@ -690,6 +722,12 @@ error_free_codec: return ret; } +/** + * cs4270_i2c_remove - remove an I2C device + * @i2c_client: the I2C client object + * + * This function is the counterpart to cs4270_i2c_probe(). + */ static int cs4270_i2c_remove(struct i2c_client *i2c_client) { struct cs4270_private *cs4270 = i2c_get_clientdata(i2c_client); @@ -699,12 +737,21 @@ static int cs4270_i2c_remove(struct i2c_client *i2c_client) return 0; } +/* + * cs4270_id - I2C device IDs supported by this driver + */ static struct i2c_device_id cs4270_id[] = { {"cs4270", 0}, {} }; MODULE_DEVICE_TABLE(i2c, cs4270_id); +/* + * cs4270_i2c_driver - I2C device identification + * + * This structure tells the I2C subsystem how to identify and support a + * given I2C device type. + */ static struct i2c_driver cs4270_i2c_driver = { .driver = { .name = "cs4270", -- cgit v1.2.3 From d9fb7fbddc9a14569aad517984c1a5b0b07002ea Mon Sep 17 00:00:00 2001 From: Timur Tabi Date: Mon, 2 Feb 2009 14:50:45 -0600 Subject: ASoC: fix build break in CS4270 codec driver Fix a oversight in the CS4270 codec driver that caused a build break. Signed-off-by: Timur Tabi Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index e5f5afdd342..7962874258f 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -149,7 +149,7 @@ struct cs4270_mode_ratios { u8 mclk; }; -static struct cs4270_mode_ratios[] = { +static struct cs4270_mode_ratios cs4270_mode_ratios[] = { {64, CS4270_MODE_4X, CS4270_MODE_DIV1}, #ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA {96, CS4270_MODE_4X, CS4270_MODE_DIV15}, -- cgit v1.2.3 From a6c255e0945160b76eabe983f59e2129e0c66246 Mon Sep 17 00:00:00 2001 From: Timur Tabi Date: Mon, 2 Feb 2009 15:08:29 -0600 Subject: ASoC: fix message display in CS4270 codec driver Replace printk calls with dev_xxx calls. Set the 'dev' field of the codec and codec_dai structures so that these calls work. Signed-off-by: Timur Tabi Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 66 ++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 27 deletions(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 7962874258f..2c79a24186f 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -212,7 +212,7 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, rates &= ~SNDRV_PCM_RATE_KNOT; if (!rates) { - printk(KERN_ERR "cs4270: could not find a valid sample rate\n"); + dev_err(codec->dev, "could not find a valid sample rate\n"); return -EINVAL; } @@ -253,7 +253,7 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai, cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK; break; default: - printk(KERN_ERR "cs4270: invalid DAI format\n"); + dev_err(codec->dev, "invalid dai format\n"); ret = -EINVAL; } @@ -284,7 +284,7 @@ static int cs4270_fill_cache(struct snd_soc_codec *codec) CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache); if (length != CS4270_NUMREGS) { - printk(KERN_ERR "cs4270: I2C read failure, addr=0x%x\n", + dev_err(codec->dev, "i2c read failure, addr=0x%x\n", i2c_client->addr); return -EIO; } @@ -340,7 +340,7 @@ static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg, if (cache[reg - CS4270_FIRSTREG] != value) { struct i2c_client *client = codec->control_data; if (i2c_smbus_write_byte_data(client, reg, value)) { - printk(KERN_ERR "cs4270: I2C write failed\n"); + dev_err(codec->dev, "i2c write failed\n"); return -EIO; } @@ -391,7 +391,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, if (i == NUM_MCLK_RATIOS) { /* We did not find a matching ratio */ - printk(KERN_ERR "cs4270: could not find matching ratio\n"); + dev_err(codec->dev, "could not find matching ratio\n"); return -EINVAL; } @@ -401,7 +401,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC | CS4270_PWRCTL_PDN); if (ret < 0) { - printk(KERN_ERR "cs4270: I2C write failed\n"); + dev_err(codec->dev, "i2c write failed\n"); return ret; } @@ -413,7 +413,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, ret = snd_soc_write(codec, CS4270_MODE, reg); if (ret < 0) { - printk(KERN_ERR "cs4270: I2C write failed\n"); + dev_err(codec->dev, "i2c write failed\n"); return ret; } @@ -430,13 +430,13 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ; break; default: - printk(KERN_ERR "cs4270: unknown format\n"); + dev_err(codec->dev, "unknown dai format\n"); return -EINVAL; } ret = snd_soc_write(codec, CS4270_FORMAT, reg); if (ret < 0) { - printk(KERN_ERR "cs4270: I2C write failed\n"); + dev_err(codec->dev, "i2c write failed\n"); return ret; } @@ -447,7 +447,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, reg &= ~CS4270_MUTE_AUTO; ret = snd_soc_write(codec, CS4270_MUTE, reg); if (ret < 0) { - printk(KERN_ERR "cs4270: I2C write failed\n"); + dev_err(codec->dev, "i2c write failed\n"); return ret; } @@ -460,7 +460,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO); ret = cs4270_i2c_write(codec, CS4270_TRANS, reg); if (ret < 0) { - printk(KERN_ERR "I2C write failed\n"); + dev_err(codec->dev, "i2c write failed\n"); return ret; } @@ -468,7 +468,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, ret = snd_soc_write(codec, CS4270_PWRCTL, 0); if (ret < 0) { - printk(KERN_ERR "cs4270: I2C write failed\n"); + dev_err(codec->dev, "i2c write failed\n"); return ret; } @@ -570,7 +570,7 @@ static int cs4270_probe(struct platform_device *pdev) /* Register PCMs */ ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); if (ret < 0) { - printk(KERN_ERR "cs4270: failed to create PCMs\n"); + dev_err(codec->dev, "failed to create pcms\n"); return ret; } @@ -580,7 +580,7 @@ static int cs4270_probe(struct platform_device *pdev) kctrl = snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL); if (!kctrl) { - printk(KERN_ERR "cs4270: error creating control '%s'\n", + dev_err(codec->dev, "error creating control '%s'\n", cs4270_snd_controls[i].name); ret = -ENOMEM; goto error_free_pcms; @@ -588,7 +588,7 @@ static int cs4270_probe(struct platform_device *pdev) ret = snd_ctl_add(codec->card, kctrl); if (ret < 0) { - printk(KERN_ERR "cs4270: error adding control '%s'\n", + dev_err(codec->dev, "error adding control '%s'\n", cs4270_snd_controls[i].name); goto error_free_pcms; } @@ -597,7 +597,7 @@ static int cs4270_probe(struct platform_device *pdev) /* And finally, register the socdev */ ret = snd_soc_init_card(socdev); if (ret < 0) { - printk(KERN_ERR "cs4270: failed to register card\n"); + dev_err(codec->dev, "failed to register card\n"); goto error_free_pcms; } @@ -643,9 +643,9 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, * comment for cs4270_codec. */ if (cs4270_codec) { - printk(KERN_ERR "cs4270: ignoring CS4270 at addr %X\n", + dev_err(&i2c_client->dev, "ignoring CS4270 at addr %X\n", i2c_client->addr); - printk(KERN_ERR "cs4270: only one CS4270 per board allowed\n"); + dev_err(&i2c_client->dev, "only one per board allowed\n"); /* Should we return something other than ENODEV here? */ return -ENODEV; } @@ -654,35 +654,35 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID); if (ret < 0) { - printk(KERN_ERR "cs4270: failed to read I2C at addr %X\n", + dev_err(&i2c_client->dev, "failed to read i2c at addr %X\n", i2c_client->addr); return ret; } /* The top four bits of the chip ID should be 1100. */ if ((ret & 0xF0) != 0xC0) { - printk(KERN_ERR "cs4270: device at addr %X is not a CS4270\n", + dev_err(&i2c_client->dev, "device at addr %X is not a CS4270\n", i2c_client->addr); return -ENODEV; } - printk(KERN_INFO "cs4270: found device at I2C address %X\n", + dev_info(&i2c_client->dev, "found device at i2c address %X\n", i2c_client->addr); - printk(KERN_INFO "cs4270: hardware revision %X\n", ret & 0xF); + dev_info(&i2c_client->dev, "hardware revision %X\n", ret & 0xF); /* Allocate enough space for the snd_soc_codec structure and our private data together. */ cs4270 = kzalloc(sizeof(struct cs4270_private), GFP_KERNEL); if (!cs4270) { - printk(KERN_ERR "cs4270: Could not allocate codec structure\n"); + dev_err(&i2c_client->dev, "could not allocate codec\n"); return -ENOMEM; } codec = &cs4270->codec; - cs4270_codec = codec; mutex_init(&codec->mutex); INIT_LIST_HEAD(&codec->dapm_widgets); INIT_LIST_HEAD(&codec->dapm_paths); + codec->dev = &i2c_client->dev; codec->name = "CS4270"; codec->owner = THIS_MODULE; codec->dai = &cs4270_dai; @@ -698,17 +698,25 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, ret = cs4270_fill_cache(codec); if (ret < 0) { - printk(KERN_ERR "cs4270: failed to fill register cache\n"); + dev_err(&i2c_client->dev, "failed to fill register cache\n"); goto error_free_codec; } + /* Initialize the DAI. Normally, we'd prefer to have a kmalloc'd DAI + * structure for each CS4270 device, but the machine driver needs to + * have a pointer to the DAI structure, so for now it must be a global + * variable. + */ + cs4270_dai.dev = &i2c_client->dev; + /* Register the DAI. If all the other ASoC driver have already * registered, then this will call our probe function, so * cs4270_codec needs to be ready. */ + cs4270_codec = codec; ret = snd_soc_register_dai(&cs4270_dai); if (ret < 0) { - printk(KERN_ERR "cs4270: failed to register DAIe\n"); + dev_err(&i2c_client->dev, "failed to register DAIe\n"); goto error_free_codec; } @@ -718,6 +726,8 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, error_free_codec: kfree(cs4270); + cs4270_codec = NULL; + cs4270_dai.dev = NULL; return ret; } @@ -733,6 +743,8 @@ static int cs4270_i2c_remove(struct i2c_client *i2c_client) struct cs4270_private *cs4270 = i2c_get_clientdata(i2c_client); kfree(cs4270); + cs4270_codec = NULL; + cs4270_dai.dev = NULL; return 0; } @@ -776,7 +788,7 @@ EXPORT_SYMBOL_GPL(soc_codec_device_cs4270); static int __init cs4270_init(void) { - printk(KERN_INFO "Cirrus Logic CS4270 ALSA SoC Codec Driver\n"); + pr_info("Cirrus Logic CS4270 ALSA SoC Codec Driver\n"); return i2c_add_driver(&cs4270_i2c_driver); } -- cgit v1.2.3 From d5e9ba1d58b6da1c58a91113fc350ece97ec5a0b Mon Sep 17 00:00:00 2001 From: Timur Tabi Date: Tue, 3 Feb 2009 11:09:32 -0600 Subject: ASoC: add additional controls to the CS4270 codec driver Update the CS4270 codec driver to allow applications to use the mixer to control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute. Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first initializes the hardware, but these features either don't work or interfere with normal ALSA behavior. However, they can now be re-enabled by an application if desired. Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute bits. The driver previously and erroneously assumed that these bits control only external muting circuitry, but they also control internal muting circuitry, so they should always be used. Signed-off-by: Timur Tabi Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 93 ++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 53 deletions(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 2c79a24186f..cd4a9ee38e4 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -395,17 +395,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - /* Freeze and power-down the codec */ - - ret = snd_soc_write(codec, CS4270_PWRCTL, CS4270_PWRCTL_FREEZE | - CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC | - CS4270_PWRCTL_PDN); - if (ret < 0) { - dev_err(codec->dev, "i2c write failed\n"); - return ret; - } - - /* Program the mode control register */ + /* Set the sample rate */ reg = snd_soc_read(codec, CS4270_MODE); reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK); @@ -417,7 +407,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, return ret; } - /* Program the format register */ + /* Set the DAI format */ reg = snd_soc_read(codec, CS4270_FORMAT); reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK); @@ -440,42 +430,9 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, return ret; } - /* Disable auto-mute. This feature appears to be buggy, because in - some situations, auto-mute will not deactivate when it should. */ - - reg = snd_soc_read(codec, CS4270_MUTE); - reg &= ~CS4270_MUTE_AUTO; - ret = snd_soc_write(codec, CS4270_MUTE, reg); - if (ret < 0) { - dev_err(codec->dev, "i2c write failed\n"); - return ret; - } - - /* Disable automatic volume control. It's enabled by default, and - * it causes volume change commands to be delayed, sometimes until - * after playback has started. - */ - - reg = cs4270_read_reg_cache(codec, CS4270_TRANS); - reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO); - ret = cs4270_i2c_write(codec, CS4270_TRANS, reg); - if (ret < 0) { - dev_err(codec->dev, "i2c write failed\n"); - return ret; - } - - /* Thaw and power-up the codec */ - - ret = snd_soc_write(codec, CS4270_PWRCTL, 0); - if (ret < 0) { - dev_err(codec->dev, "i2c write failed\n"); - return ret; - } - return ret; } -#ifdef CONFIG_SND_SOC_CS4270_HWMUTE /** * cs4270_mute - enable/disable the CS4270 external mute * @dai: the SOC DAI @@ -494,22 +451,23 @@ static int cs4270_mute(struct snd_soc_dai *dai, int mute) reg6 = snd_soc_read(codec, CS4270_MUTE); if (mute) - reg6 |= CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B | - CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B; + reg6 |= CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B; else - reg6 &= ~(CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B | - CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B); + reg6 &= ~(CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B); return snd_soc_write(codec, CS4270_MUTE, reg6); } -#else -#define cs4270_mute NULL -#endif /* A list of non-DAPM controls that the CS4270 supports */ static const struct snd_kcontrol_new cs4270_snd_controls[] = { SOC_DOUBLE_R("Master Playback Volume", - CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1) + CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1), + SOC_SINGLE("Digital Sidetone Switch", CS4270_FORMAT, 5, 1, 0), + SOC_SINGLE("Soft Ramp Switch", CS4270_TRANS, 6, 1, 0), + SOC_SINGLE("Zero Cross Switch", CS4270_TRANS, 5, 1, 0), + SOC_SINGLE("Popguard Switch", CS4270_MODE, 0, 1, 1), + SOC_SINGLE("Auto-Mute Switch", CS4270_MUTE, 5, 1, 0), + SOC_DOUBLE("Master Capture Switch", CS4270_MUTE, 3, 4, 1, 0) }; /* @@ -637,6 +595,7 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, { struct snd_soc_codec *codec; struct cs4270_private *cs4270; + unsigned int reg; int ret; /* For now, we only support one cs4270 device in the system. See the @@ -702,6 +661,34 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, goto error_free_codec; } + /* Disable auto-mute. This feature appears to be buggy. In some + * situations, auto-mute will not deactivate when it should, so we want + * this feature disabled by default. An application (e.g. alsactl) can + * re-enabled it by using the controls. + */ + + reg = cs4270_read_reg_cache(codec, CS4270_MUTE); + reg &= ~CS4270_MUTE_AUTO; + ret = cs4270_i2c_write(codec, CS4270_MUTE, reg); + if (ret < 0) { + dev_err(&i2c_client->dev, "i2c write failed\n"); + return ret; + } + + /* Disable automatic volume control. The hardware enables, and it + * causes volume change commands to be delayed, sometimes until after + * playback has started. An application (e.g. alsactl) can + * re-enabled it by using the controls. + */ + + reg = cs4270_read_reg_cache(codec, CS4270_TRANS); + reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO); + ret = cs4270_i2c_write(codec, CS4270_TRANS, reg); + if (ret < 0) { + dev_err(&i2c_client->dev, "i2c write failed\n"); + return ret; + } + /* Initialize the DAI. Normally, we'd prefer to have a kmalloc'd DAI * structure for each CS4270 device, but the machine driver needs to * have a pointer to the DAI structure, so for now it must be a global -- cgit v1.2.3 From 4eae080dda3a563160be2f642cfbda27ffc42178 Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Wed, 25 Feb 2009 14:37:21 +0100 Subject: ASoC: Add cs4270 support for slave mode configurations Added support for scenarios where the Cirrus CS4270 audio codec is slave to the bitclk and lrclk. Mixed setups are unsupported. Signed-off-by: Daniel Mack Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index cd4a9ee38e4..339e0f6b0fe 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -109,6 +109,7 @@ struct cs4270_private { u8 reg_cache[CS4270_NUMREGS]; unsigned int mclk; /* Input frequency of the MCLK pin */ unsigned int mode; /* The mode (I2S or left-justified) */ + unsigned int slave_mode; }; /** @@ -247,6 +248,7 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai, struct cs4270_private *cs4270 = codec->private_data; int ret = 0; + /* set DAI format */ switch (format & SND_SOC_DAIFMT_FORMAT_MASK) { case SND_SOC_DAIFMT_I2S: case SND_SOC_DAIFMT_LEFT_J: @@ -257,6 +259,21 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai, ret = -EINVAL; } + /* set master/slave audio interface */ + switch (format & SND_SOC_DAIFMT_MASTER_MASK) { + case SND_SOC_DAIFMT_CBS_CFS: + cs4270->slave_mode = 1; + break; + case SND_SOC_DAIFMT_CBM_CFM: + cs4270->slave_mode = 0; + break; + case SND_SOC_DAIFMT_CBM_CFS: + /* unsupported - cs4270 can eigther be slave or master to + * both the bitclk and the lrclk. */ + default: + ret = -EINVAL; + } + return ret; } @@ -399,7 +416,12 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, reg = snd_soc_read(codec, CS4270_MODE); reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK); - reg |= cs4270_mode_ratios[i].speed_mode | cs4270_mode_ratios[i].mclk; + reg |= cs4270_mode_ratios[i].mclk; + + if (cs4270->slave_mode) + reg |= CS4270_MODE_SLAVE; + else + reg |= cs4270_mode_ratios[i].speed_mode; ret = snd_soc_write(codec, CS4270_MODE, reg); if (ret < 0) { -- cgit v1.2.3 From ff09d49ad0176a5f52a398c137a7ff5f669d6be4 Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Sat, 28 Feb 2009 13:21:03 +0100 Subject: ASoC: fix typo and removed unneeded switch case for cs4270 This removes a misspelled comment and got rid of superfluous switch case. Signed-off-by: Daniel Mack Acked-by: Timur Tabi Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 339e0f6b0fe..f86f33cc179 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -267,10 +267,8 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai, case SND_SOC_DAIFMT_CBM_CFM: cs4270->slave_mode = 0; break; - case SND_SOC_DAIFMT_CBM_CFS: - /* unsupported - cs4270 can eigther be slave or master to - * both the bitclk and the lrclk. */ default: + /* all other modes are unsupported by the hardware */ ret = -EINVAL; } -- cgit v1.2.3 From 6335d05548eece40092000aa91b64a50310d69d5 Mon Sep 17 00:00:00 2001 From: Eric Miao Date: Tue, 3 Mar 2009 09:41:00 +0800 Subject: ASoC: make ops a pointer in 'struct snd_soc_dai' Considering the fact that most cpu_dai or codec_dai are using a same 'snd_soc_dai_ops' for several similar interfaces, 'ops' would be better made a pointer instead, to make sharing easier and code a bit cleaner. The patch below is rather preliminary since the asoc tree is being actively developed, and this touches almost every piece of code, (and possibly many others in development need to be changed as well). Building of all codecs are OK, yet to every SoC, I didn't test that. Signed-off-by: Eric Miao Acked-by: Timur Tabi Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index f86f33cc179..7ae3d6520e3 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -503,6 +503,13 @@ static const struct snd_kcontrol_new cs4270_snd_controls[] = { */ static struct snd_soc_codec *cs4270_codec; +static struct snd_soc_dai_ops cs4270_dai_ops = { + .hw_params = cs4270_hw_params, + .set_sysclk = cs4270_set_dai_sysclk, + .set_fmt = cs4270_set_dai_fmt, + .digital_mute = cs4270_mute, +}; + struct snd_soc_dai cs4270_dai = { .name = "cs4270", .playback = { @@ -519,12 +526,7 @@ struct snd_soc_dai cs4270_dai = { .rates = 0, .formats = CS4270_FORMATS, }, - .ops = { - .hw_params = cs4270_hw_params, - .set_sysclk = cs4270_set_dai_sysclk, - .set_fmt = cs4270_set_dai_fmt, - .digital_mute = cs4270_mute, - }, + .ops = &cs4270_dai_ops, }; EXPORT_SYMBOL_GPL(cs4270_dai); -- cgit v1.2.3 From b191f63c4fe9fbcfe583180228080d02b8dcdebc Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Sun, 8 Mar 2009 17:51:52 +0100 Subject: ASoC: bring cs4270 feature/limitations list in sync Removes numbers from the list of features/limitations and makes it reflect recent changes to the code. Signed-off-by: Daniel Mack Acked-by: Timur Tabi Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index f86f33cc179..0e0c23ee6af 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -12,14 +12,13 @@ * * Current features/limitations: * - * 1) Software mode is supported. Stand-alone mode is not supported. - * 2) Only I2C is supported, not SPI - * 3) Only Master mode is supported, not Slave. - * 4) The machine driver's 'startup' function must call - * cs4270_set_dai_sysclk() with the value of MCLK. - * 5) Only I2S and left-justified modes are supported - * 6) Power management is not supported - * 7) The only supported control is volume and hardware mute (if enabled) + * - Software mode is supported. Stand-alone mode is not supported. + * - Only I2C is supported, not SPI + * - Support for master and slave mode + * - The machine driver's 'startup' function must call + * cs4270_set_dai_sysclk() with the value of MCLK. + * - Only I2S and left-justified modes are supported + * - Power management is not supported */ #include -- cgit v1.2.3 From eb5f6d753e337834c7ceb07824ee472e43d9a7a2 Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Thu, 12 Mar 2009 11:07:54 +0100 Subject: ASoC: Replace remaining uses of snd_soc_cnew with snd_soc_add_controls. The drivers are basically duplicating the same code over and over. As snd_soc_cnew is going to be made static some time after the next merge window, we might as well convert them now. Signed-off-by: Philipp Zabel Signed-off-by: Mark Brown --- sound/soc/codecs/cs4270.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'sound/soc/codecs/cs4270.c') diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 2137670c9b7..7fa09a38762 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -540,7 +540,6 @@ static int cs4270_probe(struct platform_device *pdev) { struct snd_soc_device *socdev = platform_get_drvdata(pdev); struct snd_soc_codec *codec = cs4270_codec; - unsigned int i; int ret; /* Connect the codec to the socdev. snd_soc_new_pcms() needs this. */ @@ -554,23 +553,11 @@ static int cs4270_probe(struct platform_device *pdev) } /* Add the non-DAPM controls */ - for (i = 0; i < ARRAY_SIZE(cs4270_snd_controls); i++) { - struct snd_kcontrol *kctrl; - - kctrl = snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL); - if (!kctrl) { - dev_err(codec->dev, "error creating control '%s'\n", - cs4270_snd_controls[i].name); - ret = -ENOMEM; - goto error_free_pcms; - } - - ret = snd_ctl_add(codec->card, kctrl); - if (ret < 0) { - dev_err(codec->dev, "error adding control '%s'\n", - cs4270_snd_controls[i].name); - goto error_free_pcms; - } + ret = snd_soc_add_controls(codec, cs4270_snd_controls, + ARRAY_SIZE(cs4270_snd_controls)); + if (ret < 0) { + dev_err(codec->dev, "failed to add controls\n"); + goto error_free_pcms; } /* And finally, register the socdev */ -- cgit v1.2.3