aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/codecs/cs4270.c163
1 files changed, 105 insertions, 58 deletions
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index adc1150ddb00..e5f5afdd3427 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -3,10 +3,10 @@
3 * 3 *
4 * Author: Timur Tabi <timur@freescale.com> 4 * Author: Timur Tabi <timur@freescale.com>
5 * 5 *
6 * Copyright 2007 Freescale Semiconductor, Inc. This file is licensed under 6 * Copyright 2007-2009 Freescale Semiconductor, Inc. This file is licensed
7 * the terms of the GNU General Public License version 2. This program 7 * under the terms of the GNU General Public License version 2. This
8 * is licensed "as is" without any warranty of any kind, whether express 8 * program is licensed "as is" without any warranty of any kind, whether
9 * or implied. 9 * express or implied.
10 * 10 *
11 * This is an ASoC device driver for the Cirrus Logic CS4270 codec. 11 * This is an ASoC device driver for the Cirrus Logic CS4270 codec.
12 * 12 *
@@ -111,8 +111,13 @@ struct cs4270_private {
111 unsigned int mode; /* The mode (I2S or left-justified) */ 111 unsigned int mode; /* The mode (I2S or left-justified) */
112}; 112};
113 113
114/* 114/**
115 * Clock Ratio Selection for Master Mode with I2C enabled 115 * struct cs4270_mode_ratios - clock ratio tables
116 * @ratio: the ratio of MCLK to the sample rate
117 * @speed_mode: the Speed Mode bits to set in the Mode Control register for
118 * this ratio
119 * @mclk: the Ratio Select bits to set in the Mode Control register for this
120 * ratio
116 * 121 *
117 * The data for this chart is taken from Table 5 of the CS4270 reference 122 * The data for this chart is taken from Table 5 of the CS4270 reference
118 * manual. 123 * manual.
@@ -121,31 +126,30 @@ struct cs4270_private {
121 * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling 126 * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling
122 * rates the CS4270 currently supports. 127 * rates the CS4270 currently supports.
123 * 128 *
124 * Each element in this array corresponds to the ratios in mclk_ratios[]. 129 * @speed_mode is the corresponding bit pattern to be written to the
125 * These two arrays need to be in sync.
126 *
127 * 'speed_mode' is the corresponding bit pattern to be written to the
128 * MODE bits of the Mode Control Register 130 * MODE bits of the Mode Control Register
129 * 131 *
130 * 'mclk' is the corresponding bit pattern to be wirten to the MCLK bits of 132 * @mclk is the corresponding bit pattern to be wirten to the MCLK bits of
131 * the Mode Control Register. 133 * the Mode Control Register.
132 * 134 *
133 * In situations where a single ratio is represented by multiple speed 135 * In situations where a single ratio is represented by multiple speed
134 * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick 136 * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick
135 * double-speed instead of quad-speed. However, the CS4270 errata states 137 * double-speed instead of quad-speed. However, the CS4270 errata states
136 * that Divide-By-1.5 can cause failures, so we avoid that mode where 138 * that divide-By-1.5 can cause failures, so we avoid that mode where
137 * possible. 139 * possible.
138 * 140 *
139 * ERRATA: There is an errata for the CS4270 where divide-by-1.5 does not 141 * Errata: There is an errata for the CS4270 where divide-by-1.5 does not
140 * work if VD = 3.3V. If this effects you, select the 142 * work if Vd is 3.3V. If this effects you, select the
141 * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will 143 * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will
142 * never select any sample rates that require divide-by-1.5. 144 * never select any sample rates that require divide-by-1.5.
143 */ 145 */
144static struct { 146struct cs4270_mode_ratios {
145 unsigned int ratio; 147 unsigned int ratio;
146 u8 speed_mode; 148 u8 speed_mode;
147 u8 mclk; 149 u8 mclk;
148} cs4270_mode_ratios[] = { 150};
151
152static struct cs4270_mode_ratios[] = {
149 {64, CS4270_MODE_4X, CS4270_MODE_DIV1}, 153 {64, CS4270_MODE_4X, CS4270_MODE_DIV1},
150#ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA 154#ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA
151 {96, CS4270_MODE_4X, CS4270_MODE_DIV15}, 155 {96, CS4270_MODE_4X, CS4270_MODE_DIV15},
@@ -162,34 +166,27 @@ static struct {
162/* The number of MCLK/LRCK ratios supported by the CS4270 */ 166/* The number of MCLK/LRCK ratios supported by the CS4270 */
163#define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios) 167#define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios)
164 168
165/* 169/**
166 * Determine the CS4270 samples rates. 170 * cs4270_set_dai_sysclk - determine the CS4270 samples rates.
171 * @codec_dai: the codec DAI
172 * @clk_id: the clock ID (ignored)
173 * @freq: the MCLK input frequency
174 * @dir: the clock direction (ignored)
167 * 175 *
168 * 'freq' is the input frequency to MCLK. The other parameters are ignored. 176 * This function is used to tell the codec driver what the input MCLK
177 * frequency is.
169 * 178 *
170 * The value of MCLK is used to determine which sample rates are supported 179 * The value of MCLK is used to determine which sample rates are supported
171 * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine 180 * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine
172 * support values: 64, 96, 128, 192, 256, 384, 512, 768, and 1024. 181 * supported values - 64, 96, 128, 192, 256, 384, 512, 768, and 1024.
173 * 182 *
174 * This function calculates the nine ratios and determines which ones match 183 * This function calculates the nine ratios and determines which ones match
175 * a standard sample rate. If there's a match, then it is added to the list 184 * a standard sample rate. If there's a match, then it is added to the list
176 * of support sample rates. 185 * of supported sample rates.
177 * 186 *
178 * This function must be called by the machine driver's 'startup' function, 187 * This function must be called by the machine driver's 'startup' function,
179 * otherwise the list of supported sample rates will not be available in 188 * otherwise the list of supported sample rates will not be available in
180 * time for ALSA. 189 * time for ALSA.
181 *
182 * Note that in stand-alone mode, the sample rate is determined by input
183 * pins M0, M1, MDIV1, and MDIV2. Also in stand-alone mode, divide-by-3
184 * is not a programmable option. However, divide-by-3 is not an available
185 * option in stand-alone mode. This cases two problems: a ratio of 768 is
186 * not available (it requires divide-by-3) and B) ratios 192 and 384 can
187 * only be selected with divide-by-1.5, but there is an errate that make
188 * this selection difficult.
189 *
190 * In addition, there is no mechanism for communicating with the machine
191 * driver what the input settings can be. This would need to be implemented
192 * for stand-alone mode to work.
193 */ 190 */
194static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, 191static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
195 int clk_id, unsigned int freq, int dir) 192 int clk_id, unsigned int freq, int dir)
@@ -230,8 +227,10 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
230 return 0; 227 return 0;
231} 228}
232 229
233/* 230/**
234 * Configure the codec for the selected audio format 231 * cs4270_set_dai_fmt - configure the codec for the selected audio format
232 * @codec_dai: the codec DAI
233 * @format: a SND_SOC_DAIFMT_x value indicating the data format
235 * 234 *
236 * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the 235 * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the
237 * codec accordingly. 236 * codec accordingly.
@@ -261,8 +260,16 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai,
261 return ret; 260 return ret;
262} 261}
263 262
264/* 263/**
265 * Pre-fill the CS4270 register cache. 264 * cs4270_fill_cache - pre-fill the CS4270 register cache.
265 * @codec: the codec for this CS4270
266 *
267 * This function fills in the CS4270 register cache by reading the register
268 * values from the hardware.
269 *
270 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
271 * After the initial read to pre-fill the cache, the CS4270 never updates
272 * the register values, so we won't have a cache coherency problem.
266 * 273 *
267 * We use the auto-increment feature of the CS4270 to read all registers in 274 * We use the auto-increment feature of the CS4270 to read all registers in
268 * one shot. 275 * one shot.
@@ -285,12 +292,17 @@ static int cs4270_fill_cache(struct snd_soc_codec *codec)
285 return 0; 292 return 0;
286} 293}
287 294
288/* 295/**
289 * Read from the CS4270 register cache. 296 * cs4270_read_reg_cache - read from the CS4270 register cache.
297 * @codec: the codec for this CS4270
298 * @reg: the register to read
299 *
300 * This function returns the value for a given register. It reads only from
301 * the register cache, not the hardware itself.
290 * 302 *
291 * This CS4270 registers are cached to avoid excessive I2C I/O operations. 303 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
292 * After the initial read to pre-fill the cache, the CS4270 never updates 304 * After the initial read to pre-fill the cache, the CS4270 never updates
293 * the register values, so we won't have a cache coherncy problem. 305 * the register values, so we won't have a cache coherency problem.
294 */ 306 */
295static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec, 307static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
296 unsigned int reg) 308 unsigned int reg)
@@ -303,8 +315,11 @@ static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
303 return cache[reg - CS4270_FIRSTREG]; 315 return cache[reg - CS4270_FIRSTREG];
304} 316}
305 317
306/* 318/**
307 * Write to a CS4270 register via the I2C bus. 319 * cs4270_i2c_write - write to a CS4270 register via the I2C bus.
320 * @codec: the codec for this CS4270
321 * @reg: the register to write
322 * @value: the value to write to the register
308 * 323 *
309 * This function writes the given value to the given CS4270 register, and 324 * This function writes the given value to the given CS4270 register, and
310 * also updates the register cache. 325 * also updates the register cache.
@@ -336,11 +351,17 @@ static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
336 return 0; 351 return 0;
337} 352}
338 353
339/* 354/**
340 * Program the CS4270 with the given hardware parameters. 355 * cs4270_hw_params - program the CS4270 with the given hardware parameters.
356 * @substream: the audio stream
357 * @params: the hardware parameters to set
358 * @dai: the SOC DAI (ignored)
341 * 359 *
342 * The .ops functions are used to provide board-specific data, like 360 * This function programs the hardware with the values provided.
343 * input frequencies, to this driver. This function takes that information, 361 * Specifically, the sample rate and the data format.
362 *
363 * The .ops functions are used to provide board-specific data, like input
364 * frequencies, to this driver. This function takes that information,
344 * combines it with the hardware parameters provided, and programs the 365 * combines it with the hardware parameters provided, and programs the
345 * hardware accordingly. 366 * hardware accordingly.
346 */ 367 */
@@ -455,8 +476,10 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
455} 476}
456 477
457#ifdef CONFIG_SND_SOC_CS4270_HWMUTE 478#ifdef CONFIG_SND_SOC_CS4270_HWMUTE
458/* 479/**
459 * Set the CS4270 external mute 480 * cs4270_mute - enable/disable the CS4270 external mute
481 * @dai: the SOC DAI
482 * @mute: 0 = disable mute, 1 = enable mute
460 * 483 *
461 * This function toggles the mute bits in the MUTE register. The CS4270's 484 * This function toggles the mute bits in the MUTE register. The CS4270's
462 * mute capability is intended for external muting circuitry, so if the 485 * mute capability is intended for external muting circuitry, so if the
@@ -490,7 +513,7 @@ static const struct snd_kcontrol_new cs4270_snd_controls[] = {
490}; 513};
491 514
492/* 515/*
493 * Global variable to store codec for the ASoC probe function. 516 * cs4270_codec - global variable to store codec for the ASoC probe function
494 * 517 *
495 * If struct i2c_driver had a private_data field, we wouldn't need to use 518 * If struct i2c_driver had a private_data field, we wouldn't need to use
496 * cs4270_codec. This is the only way to pass the codec structure from 519 * cs4270_codec. This is the only way to pass the codec structure from
@@ -527,8 +550,12 @@ struct snd_soc_dai cs4270_dai = {
527}; 550};
528EXPORT_SYMBOL_GPL(cs4270_dai); 551EXPORT_SYMBOL_GPL(cs4270_dai);
529 552
530/* 553/**
531 * ASoC probe function 554 * cs4270_probe - ASoC probe function
555 * @pdev: platform device
556 *
557 * This function is called when ASoC has all the pieces it needs to
558 * instantiate a sound driver.
532 */ 559 */
533static int cs4270_probe(struct platform_device *pdev) 560static int cs4270_probe(struct platform_device *pdev)
534{ 561{
@@ -582,6 +609,12 @@ error_free_pcms:
582 return ret; 609 return ret;
583} 610}
584 611
612/**
613 * cs4270_remove - ASoC remove function
614 * @pdev: platform device
615 *
616 * This function is the counterpart to cs4270_probe().
617 */
585static int cs4270_remove(struct platform_device *pdev) 618static int cs4270_remove(struct platform_device *pdev)
586{ 619{
587 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 620 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
@@ -591,14 +624,13 @@ static int cs4270_remove(struct platform_device *pdev)
591 return 0; 624 return 0;
592}; 625};
593 626
594/* 627/**
595 * Initialize the I2C interface of the CS4270 628 * cs4270_i2c_probe - initialize the I2C interface of the CS4270
596 * 629 * @i2c_client: the I2C client object
597 * This function is called for whenever the I2C subsystem finds a device 630 * @id: the I2C device ID (ignored)
598 * at a particular address.
599 * 631 *
600 * Note: snd_soc_new_pcms() must be called before this function can be called, 632 * This function is called whenever the I2C subsystem finds a device that
601 * because of snd_ctl_add(). 633 * matches the device ID given via a prior call to i2c_add_driver().
602 */ 634 */
603static int cs4270_i2c_probe(struct i2c_client *i2c_client, 635static int cs4270_i2c_probe(struct i2c_client *i2c_client,
604 const struct i2c_device_id *id) 636 const struct i2c_device_id *id)
@@ -690,6 +722,12 @@ error_free_codec:
690 return ret; 722 return ret;
691} 723}
692 724
725/**
726 * cs4270_i2c_remove - remove an I2C device
727 * @i2c_client: the I2C client object
728 *
729 * This function is the counterpart to cs4270_i2c_probe().
730 */
693static int cs4270_i2c_remove(struct i2c_client *i2c_client) 731static int cs4270_i2c_remove(struct i2c_client *i2c_client)
694{ 732{
695 struct cs4270_private *cs4270 = i2c_get_clientdata(i2c_client); 733 struct cs4270_private *cs4270 = i2c_get_clientdata(i2c_client);
@@ -699,12 +737,21 @@ static int cs4270_i2c_remove(struct i2c_client *i2c_client)
699 return 0; 737 return 0;
700} 738}
701 739
740/*
741 * cs4270_id - I2C device IDs supported by this driver
742 */
702static struct i2c_device_id cs4270_id[] = { 743static struct i2c_device_id cs4270_id[] = {
703 {"cs4270", 0}, 744 {"cs4270", 0},
704 {} 745 {}
705}; 746};
706MODULE_DEVICE_TABLE(i2c, cs4270_id); 747MODULE_DEVICE_TABLE(i2c, cs4270_id);
707 748
749/*
750 * cs4270_i2c_driver - I2C device identification
751 *
752 * This structure tells the I2C subsystem how to identify and support a
753 * given I2C device type.
754 */
708static struct i2c_driver cs4270_i2c_driver = { 755static struct i2c_driver cs4270_i2c_driver = {
709 .driver = { 756 .driver = {
710 .name = "cs4270", 757 .name = "cs4270",