Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: sound/soc/codecs/cs4270.c

Issue 6577007: CHROMIUM: ASoC: Import entire upstream ASoC tree (Closed)
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sound/soc/codecs/cq93vc.c ('k') | sound/soc/codecs/cs4271.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * CS4270 ALSA SoC (ASoC) codec driver 2 * CS4270 ALSA SoC (ASoC) codec driver
3 * 3 *
4 * Author: Timur Tabi <timur@freescale.com> 4 * Author: Timur Tabi <timur@freescale.com>
5 * 5 *
6 * Copyright 2007-2009 Freescale Semiconductor, Inc. This file is licensed 6 * Copyright 2007-2009 Freescale Semiconductor, Inc. This file is licensed
7 * under the terms of the GNU General Public License version 2. This 7 * under the terms of the GNU General Public License version 2. This
8 * program is licensed "as is" without any warranty of any kind, whether 8 * program is licensed "as is" without any warranty of any kind, whether
9 * express or implied. 9 * express or implied.
10 * 10 *
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 #define CS4270_TRANS_INV_DAC_A 0x02 99 #define CS4270_TRANS_INV_DAC_A 0x02
100 #define CS4270_TRANS_INV_DAC_B 0x04 100 #define CS4270_TRANS_INV_DAC_B 0x04
101 #define CS4270_TRANS_DEEMPH 0x01 101 #define CS4270_TRANS_DEEMPH 0x01
102 #define CS4270_MUTE_AUTO 0x20 102 #define CS4270_MUTE_AUTO 0x20
103 #define CS4270_MUTE_ADC_A 0x08 103 #define CS4270_MUTE_ADC_A 0x08
104 #define CS4270_MUTE_ADC_B 0x10 104 #define CS4270_MUTE_ADC_B 0x10
105 #define CS4270_MUTE_POLARITY 0x04 105 #define CS4270_MUTE_POLARITY 0x04
106 #define CS4270_MUTE_DAC_A 0x01 106 #define CS4270_MUTE_DAC_A 0x01
107 #define CS4270_MUTE_DAC_B 0x02 107 #define CS4270_MUTE_DAC_B 0x02
108 108
109 /* Power-on default values for the registers
110 *
111 * This array contains the power-on default values of the registers, with the
112 * exception of the "CHIPID" register (01h). The lower four bits of that
113 * register contain the hardware revision, so it is treated as volatile.
114 *
115 * Also note that on the CS4270, the first readable register is 1, but ASoC
116 * assumes the first register is 0. Therfore, the array must have an entry for
117 * register 0, but we use cs4270_reg_is_readable() to tell ASoC that it can't
118 * be read.
119 */
120 static const u8 cs4270_default_reg_cache[CS4270_LASTREG + 1] = {
121 0x00, 0x00, 0x00, 0x30, 0x00, 0x60, 0x20, 0x00, 0x00
122 };
123
109 static const char *supply_names[] = { 124 static const char *supply_names[] = {
110 "va", "vd", "vlc" 125 "va", "vd", "vlc"
111 }; 126 };
112 127
113 /* Private data for the CS4270 */ 128 /* Private data for the CS4270 */
114 struct cs4270_private { 129 struct cs4270_private {
115 enum snd_soc_control_type control_type; 130 enum snd_soc_control_type control_type;
116 void *control_data; 131 void *control_data;
117 u8 reg_cache[CS4270_NUMREGS];
118 unsigned int mclk; /* Input frequency of the MCLK pin */ 132 unsigned int mclk; /* Input frequency of the MCLK pin */
119 unsigned int mode; /* The mode (I2S or left-justified) */ 133 unsigned int mode; /* The mode (I2S or left-justified) */
120 unsigned int slave_mode; 134 unsigned int slave_mode;
121 unsigned int manual_mute; 135 unsigned int manual_mute;
122 136
123 /* power domain regulators */ 137 /* power domain regulators */
124 struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; 138 struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
125 }; 139 };
126 140
127 /** 141 /**
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 {256, CS4270_MODE_1X, CS4270_MODE_DIV1}, 186 {256, CS4270_MODE_1X, CS4270_MODE_DIV1},
173 {384, CS4270_MODE_2X, CS4270_MODE_DIV3}, 187 {384, CS4270_MODE_2X, CS4270_MODE_DIV3},
174 {512, CS4270_MODE_1X, CS4270_MODE_DIV2}, 188 {512, CS4270_MODE_1X, CS4270_MODE_DIV2},
175 {768, CS4270_MODE_1X, CS4270_MODE_DIV3}, 189 {768, CS4270_MODE_1X, CS4270_MODE_DIV3},
176 {1024, CS4270_MODE_1X, CS4270_MODE_DIV4} 190 {1024, CS4270_MODE_1X, CS4270_MODE_DIV4}
177 }; 191 };
178 192
179 /* The number of MCLK/LRCK ratios supported by the CS4270 */ 193 /* The number of MCLK/LRCK ratios supported by the CS4270 */
180 #define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios) 194 #define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios)
181 195
196 static int cs4270_reg_is_readable(struct snd_soc_codec *codec, unsigned int reg)
197 {
198 return (reg >= CS4270_FIRSTREG) && (reg <= CS4270_LASTREG);
199 }
200
201 static int cs4270_reg_is_volatile(struct snd_soc_codec *codec, unsigned int reg)
202 {
203 /* Unreadable registers are considered volatile */
204 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
205 return 1;
206
207 return reg == CS4270_CHIPID;
208 }
209
182 /** 210 /**
183 * cs4270_set_dai_sysclk - determine the CS4270 samples rates. 211 * cs4270_set_dai_sysclk - determine the CS4270 samples rates.
184 * @codec_dai: the codec DAI 212 * @codec_dai: the codec DAI
185 * @clk_id: the clock ID (ignored) 213 * @clk_id: the clock ID (ignored)
186 * @freq: the MCLK input frequency 214 * @freq: the MCLK input frequency
187 * @dir: the clock direction (ignored) 215 * @dir: the clock direction (ignored)
188 * 216 *
189 * This function is used to tell the codec driver what the input MCLK 217 * This function is used to tell the codec driver what the input MCLK
190 * frequency is. 218 * frequency is.
191 * 219 *
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 break; 285 break;
258 default: 286 default:
259 /* all other modes are unsupported by the hardware */ 287 /* all other modes are unsupported by the hardware */
260 ret = -EINVAL; 288 ret = -EINVAL;
261 } 289 }
262 290
263 return ret; 291 return ret;
264 } 292 }
265 293
266 /** 294 /**
267 * cs4270_fill_cache - pre-fill the CS4270 register cache.
268 * @codec: the codec for this CS4270
269 *
270 * This function fills in the CS4270 register cache by reading the register
271 * values from the hardware.
272 *
273 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
274 * After the initial read to pre-fill the cache, the CS4270 never updates
275 * the register values, so we won't have a cache coherency problem.
276 *
277 * We use the auto-increment feature of the CS4270 to read all registers in
278 * one shot.
279 */
280 static int cs4270_fill_cache(struct snd_soc_codec *codec)
281 {
282 u8 *cache = codec->reg_cache;
283 struct i2c_client *i2c_client = codec->control_data;
284 s32 length;
285
286 length = i2c_smbus_read_i2c_block_data(i2c_client,
287 CS4270_FIRSTREG | CS4270_I2C_INCR, CS4270_NUMREGS, cache);
288
289 if (length != CS4270_NUMREGS) {
290 dev_err(codec->dev, "i2c read failure, addr=0x%x\n",
291 i2c_client->addr);
292 return -EIO;
293 }
294
295 return 0;
296 }
297
298 /**
299 * cs4270_read_reg_cache - read from the CS4270 register cache.
300 * @codec: the codec for this CS4270
301 * @reg: the register to read
302 *
303 * This function returns the value for a given register. It reads only from
304 * the register cache, not the hardware itself.
305 *
306 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
307 * After the initial read to pre-fill the cache, the CS4270 never updates
308 * the register values, so we won't have a cache coherency problem.
309 */
310 static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
311 unsigned int reg)
312 {
313 u8 *cache = codec->reg_cache;
314
315 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
316 return -EIO;
317
318 return cache[reg - CS4270_FIRSTREG];
319 }
320
321 /**
322 * cs4270_i2c_write - write to a CS4270 register via the I2C bus.
323 * @codec: the codec for this CS4270
324 * @reg: the register to write
325 * @value: the value to write to the register
326 *
327 * This function writes the given value to the given CS4270 register, and
328 * also updates the register cache.
329 *
330 * Note that we don't use the hw_write function pointer of snd_soc_codec.
331 * That's because it's too clunky: the hw_write_t prototype does not match
332 * i2c_smbus_write_byte_data(), and it's just another layer of overhead.
333 */
334 static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
335 unsigned int value)
336 {
337 u8 *cache = codec->reg_cache;
338
339 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
340 return -EIO;
341
342 /* Only perform an I2C operation if the new value is different */
343 if (cache[reg - CS4270_FIRSTREG] != value) {
344 struct i2c_client *client = codec->control_data;
345 if (i2c_smbus_write_byte_data(client, reg, value)) {
346 dev_err(codec->dev, "i2c write failed\n");
347 return -EIO;
348 }
349
350 /* We've written to the hardware, so update the cache */
351 cache[reg - CS4270_FIRSTREG] = value;
352 }
353
354 return 0;
355 }
356
357 /**
358 * cs4270_hw_params - program the CS4270 with the given hardware parameters. 295 * cs4270_hw_params - program the CS4270 with the given hardware parameters.
359 * @substream: the audio stream 296 * @substream: the audio stream
360 * @params: the hardware parameters to set 297 * @params: the hardware parameters to set
361 * @dai: the SOC DAI (ignored) 298 * @dai: the SOC DAI (ignored)
362 * 299 *
363 * This function programs the hardware with the values provided. 300 * This function programs the hardware with the values provided.
364 * Specifically, the sample rate and the data format. 301 * Specifically, the sample rate and the data format.
365 * 302 *
366 * The .ops functions are used to provide board-specific data, like input 303 * The .ops functions are used to provide board-specific data, like input
367 * frequencies, to this driver. This function takes that information, 304 * frequencies, to this driver. This function takes that information,
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 /** 481 /**
545 * cs4270_probe - ASoC probe function 482 * cs4270_probe - ASoC probe function
546 * @pdev: platform device 483 * @pdev: platform device
547 * 484 *
548 * This function is called when ASoC has all the pieces it needs to 485 * This function is called when ASoC has all the pieces it needs to
549 * instantiate a sound driver. 486 * instantiate a sound driver.
550 */ 487 */
551 static int cs4270_probe(struct snd_soc_codec *codec) 488 static int cs4270_probe(struct snd_soc_codec *codec)
552 { 489 {
553 struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); 490 struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
554 » int i, ret, reg; 491 » int i, ret;
555 492
556 codec->control_data = cs4270->control_data; 493 codec->control_data = cs4270->control_data;
557 494
558 » /* The I2C interface is set up, so pre-fill our register cache */ 495 » /* Tell ASoC what kind of I/O to use to read the registers. ASoC will
559 496 » * then do the I2C transactions itself.
560 » ret = cs4270_fill_cache(codec); 497 » */
498 » ret = snd_soc_codec_set_cache_io(codec, 8, 8, cs4270->control_type);
561 if (ret < 0) { 499 if (ret < 0) {
562 » » dev_err(codec->dev, "failed to fill register cache\n"); 500 » » dev_err(codec->dev, "failed to set cache I/O (ret=%i)\n", ret);
563 return ret; 501 return ret;
564 } 502 }
565 503
566 /* Disable auto-mute. This feature appears to be buggy. In some 504 /* Disable auto-mute. This feature appears to be buggy. In some
567 * situations, auto-mute will not deactivate when it should, so we want 505 * situations, auto-mute will not deactivate when it should, so we want
568 * this feature disabled by default. An application (e.g. alsactl) can 506 * this feature disabled by default. An application (e.g. alsactl) can
569 * re-enabled it by using the controls. 507 * re-enabled it by using the controls.
570 */ 508 */
571 509 » ret = snd_soc_update_bits(codec, CS4270_MUTE, CS4270_MUTE_AUTO, 0);
572 » reg = cs4270_read_reg_cache(codec, CS4270_MUTE);
573 » reg &= ~CS4270_MUTE_AUTO;
574 » ret = cs4270_i2c_write(codec, CS4270_MUTE, reg);
575 if (ret < 0) { 510 if (ret < 0) {
576 dev_err(codec->dev, "i2c write failed\n"); 511 dev_err(codec->dev, "i2c write failed\n");
577 return ret; 512 return ret;
578 } 513 }
579 514
580 /* Disable automatic volume control. The hardware enables, and it 515 /* Disable automatic volume control. The hardware enables, and it
581 * causes volume change commands to be delayed, sometimes until after 516 * causes volume change commands to be delayed, sometimes until after
582 * playback has started. An application (e.g. alsactl) can 517 * playback has started. An application (e.g. alsactl) can
583 * re-enabled it by using the controls. 518 * re-enabled it by using the controls.
584 */ 519 */
585 520 » ret = snd_soc_update_bits(codec, CS4270_TRANS,
586 » reg = cs4270_read_reg_cache(codec, CS4270_TRANS); 521 » » CS4270_TRANS_SOFT | CS4270_TRANS_ZERO, 0);
587 » reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO);
588 » ret = cs4270_i2c_write(codec, CS4270_TRANS, reg);
589 if (ret < 0) { 522 if (ret < 0) {
590 dev_err(codec->dev, "i2c write failed\n"); 523 dev_err(codec->dev, "i2c write failed\n");
591 return ret; 524 return ret;
592 } 525 }
593 526
594 /* Add the non-DAPM controls */ 527 /* Add the non-DAPM controls */
595 ret = snd_soc_add_controls(codec, cs4270_snd_controls, 528 ret = snd_soc_add_controls(codec, cs4270_snd_controls,
596 ARRAY_SIZE(cs4270_snd_controls)); 529 ARRAY_SIZE(cs4270_snd_controls));
597 if (ret < 0) { 530 if (ret < 0) {
598 dev_err(codec->dev, "failed to add controls\n"); 531 dev_err(codec->dev, "failed to add controls\n");
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 #define cs4270_soc_suspend NULL 634 #define cs4270_soc_suspend NULL
702 #define cs4270_soc_resume NULL 635 #define cs4270_soc_resume NULL
703 #endif /* CONFIG_PM */ 636 #endif /* CONFIG_PM */
704 637
705 /* 638 /*
706 * ASoC codec device structure 639 * ASoC codec device structure
707 * 640 *
708 * Assign this variable to the codec_dev field of the machine driver's 641 * Assign this variable to the codec_dev field of the machine driver's
709 * snd_soc_device structure. 642 * snd_soc_device structure.
710 */ 643 */
711 static struct snd_soc_codec_driver soc_codec_device_cs4270 = { 644 static const struct snd_soc_codec_driver soc_codec_device_cs4270 = {
712 » .probe =» cs4270_probe, 645 » .probe =» » cs4270_probe,
713 » .remove =» cs4270_remove, 646 » .remove =» » cs4270_remove,
714 » .suspend =» cs4270_soc_suspend, 647 » .suspend =» » cs4270_soc_suspend,
715 » .resume =» cs4270_soc_resume, 648 » .resume =» » cs4270_soc_resume,
716 » .read = cs4270_read_reg_cache, 649 » .volatile_register =» cs4270_reg_is_volatile,
717 » .write = cs4270_i2c_write, 650 » .readable_register =» cs4270_reg_is_readable,
718 » .reg_cache_size = CS4270_NUMREGS, 651 » .reg_cache_size =» CS4270_LASTREG + 1,
719 » .reg_word_size = sizeof(u8), 652 » .reg_word_size =» sizeof(u8),
653 » .reg_cache_default =» cs4270_default_reg_cache,
720 }; 654 };
721 655
722 /** 656 /**
723 * cs4270_i2c_probe - initialize the I2C interface of the CS4270 657 * cs4270_i2c_probe - initialize the I2C interface of the CS4270
724 * @i2c_client: the I2C client object 658 * @i2c_client: the I2C client object
725 * @id: the I2C device ID (ignored) 659 * @id: the I2C device ID (ignored)
726 * 660 *
727 * This function is called whenever the I2C subsystem finds a device that 661 * This function is called whenever the I2C subsystem finds a device that
728 * matches the device ID given via a prior call to i2c_add_driver(). 662 * matches the device ID given via a prior call to i2c_add_driver().
729 */ 663 */
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 751
818 static void __exit cs4270_exit(void) 752 static void __exit cs4270_exit(void)
819 { 753 {
820 i2c_del_driver(&cs4270_i2c_driver); 754 i2c_del_driver(&cs4270_i2c_driver);
821 } 755 }
822 module_exit(cs4270_exit); 756 module_exit(cs4270_exit);
823 757
824 MODULE_AUTHOR("Timur Tabi <timur@freescale.com>"); 758 MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
825 MODULE_DESCRIPTION("Cirrus Logic CS4270 ALSA SoC Codec Driver"); 759 MODULE_DESCRIPTION("Cirrus Logic CS4270 ALSA SoC Codec Driver");
826 MODULE_LICENSE("GPL"); 760 MODULE_LICENSE("GPL");
OLDNEW
« no previous file with comments | « sound/soc/codecs/cq93vc.c ('k') | sound/soc/codecs/cs4271.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698