aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/tlv320aic23.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2011-10-13 03:06:43 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-10-14 15:29:04 -0400
commitf9dfbf91cbf9a8875e955350c957f84e13557634 (patch)
treece07e97cc4bdc41c300d6bff0f1db8f693f5b22d /sound/soc/codecs/tlv320aic23.c
parenta6f096f3b6effff9edc0f34a20eb0593406cc00a (diff)
ASoC: tlv320aic23: convert to soc-cache
Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/tlv320aic23.c')
-rw-r--r--sound/soc/codecs/tlv320aic23.c167
1 files changed, 52 insertions, 115 deletions
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c
index c3a4bb207d7b..ab27dbcd1262 100644
--- a/sound/soc/codecs/tlv320aic23.c
+++ b/sound/soc/codecs/tlv320aic23.c
@@ -47,63 +47,6 @@ static const u16 tlv320aic23_reg[] = {
47 0x0000, 0x0000, 0x0000, 0x0000, /* 12 */ 47 0x0000, 0x0000, 0x0000, 0x0000, /* 12 */
48}; 48};
49 49
50/*
51 * read tlv320aic23 register cache
52 */
53static inline unsigned int tlv320aic23_read_reg_cache(struct snd_soc_codec
54 *codec, unsigned int reg)
55{
56 u16 *cache = codec->reg_cache;
57 if (reg >= ARRAY_SIZE(tlv320aic23_reg))
58 return -1;
59 return cache[reg];
60}
61
62/*
63 * write tlv320aic23 register cache
64 */
65static inline void tlv320aic23_write_reg_cache(struct snd_soc_codec *codec,
66 u8 reg, u16 value)
67{
68 u16 *cache = codec->reg_cache;
69 if (reg >= ARRAY_SIZE(tlv320aic23_reg))
70 return;
71 cache[reg] = value;
72}
73
74/*
75 * write to the tlv320aic23 register space
76 */
77static int tlv320aic23_write(struct snd_soc_codec *codec, unsigned int reg,
78 unsigned int value)
79{
80
81 u8 data[2];
82
83 /* TLV320AIC23 has 7 bit address and 9 bits of data
84 * so we need to switch one data bit into reg and rest
85 * of data into val
86 */
87
88 if (reg > 9 && reg != 15) {
89 printk(KERN_WARNING "%s Invalid register R%u\n", __func__, reg);
90 return -1;
91 }
92
93 data[0] = (reg << 1) | (value >> 8 & 0x01);
94 data[1] = value & 0xff;
95
96 tlv320aic23_write_reg_cache(codec, reg, value);
97
98 if (codec->hw_write(codec->control_data, data, 2) == 2)
99 return 0;
100
101 printk(KERN_ERR "%s cannot write %03x to register R%u\n", __func__,
102 value, reg);
103
104 return -EIO;
105}
106
107static const char *rec_src_text[] = { "Line", "Mic" }; 50static const char *rec_src_text[] = { "Line", "Mic" };
108static const char *deemph_text[] = {"None", "32Khz", "44.1Khz", "48Khz"}; 51static const char *deemph_text[] = {"None", "32Khz", "44.1Khz", "48Khz"};
109 52
@@ -139,8 +82,8 @@ static int snd_soc_tlv320aic23_put_volsw(struct snd_kcontrol *kcontrol,
139 */ 82 */
140 val = (val >= 4) ? 4 : (3 - val); 83 val = (val >= 4) ? 4 : (3 - val);
141 84
142 reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_ANLG) & (~0x1C0); 85 reg = snd_soc_read(codec, TLV320AIC23_ANLG) & (~0x1C0);
143 tlv320aic23_write(codec, TLV320AIC23_ANLG, reg | (val << 6)); 86 snd_soc_write(codec, TLV320AIC23_ANLG, reg | (val << 6));
144 87
145 return 0; 88 return 0;
146} 89}
@@ -151,7 +94,7 @@ static int snd_soc_tlv320aic23_get_volsw(struct snd_kcontrol *kcontrol,
151 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 94 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
152 u16 val; 95 u16 val;
153 96
154 val = tlv320aic23_read_reg_cache(codec, TLV320AIC23_ANLG) & (0x1C0); 97 val = snd_soc_read(codec, TLV320AIC23_ANLG) & (0x1C0);
155 val = val >> 6; 98 val = val >> 6;
156 val = (val >= 4) ? 4 : (3 - val); 99 val = (val >= 4) ? 4 : (3 - val);
157 ucontrol->value.integer.value[0] = val; 100 ucontrol->value.integer.value[0] = val;
@@ -232,7 +175,6 @@ static const struct snd_soc_dapm_route tlv320aic23_intercon[] = {
232/* AIC23 driver data */ 175/* AIC23 driver data */
233struct aic23 { 176struct aic23 {
234 enum snd_soc_control_type control_type; 177 enum snd_soc_control_type control_type;
235 void *control_data;
236 int mclk; 178 int mclk;
237 int requested_adc; 179 int requested_adc;
238 int requested_dac; 180 int requested_dac;
@@ -344,7 +286,7 @@ static int find_rate(int mclk, u32 need_adc, u32 need_dac)
344static void get_current_sample_rates(struct snd_soc_codec *codec, int mclk, 286static void get_current_sample_rates(struct snd_soc_codec *codec, int mclk,
345 u32 *sample_rate_adc, u32 *sample_rate_dac) 287 u32 *sample_rate_adc, u32 *sample_rate_dac)
346{ 288{
347 int src = tlv320aic23_read_reg_cache(codec, TLV320AIC23_SRATE); 289 int src = snd_soc_read(codec, TLV320AIC23_SRATE);
348 int sr = (src >> 2) & 0x0f; 290 int sr = (src >> 2) & 0x0f;
349 int val = (mclk / bosr_usb_divisor_table[src & 3]); 291 int val = (mclk / bosr_usb_divisor_table[src & 3]);
350 int adc = (val * sr_adc_mult_table[sr]) / SR_MULT; 292 int adc = (val * sr_adc_mult_table[sr]) / SR_MULT;
@@ -368,7 +310,7 @@ static int set_sample_rate_control(struct snd_soc_codec *codec, int mclk,
368 __func__, sample_rate_adc, sample_rate_dac); 310 __func__, sample_rate_adc, sample_rate_dac);
369 return -EINVAL; 311 return -EINVAL;
370 } 312 }
371 tlv320aic23_write(codec, TLV320AIC23_SRATE, data); 313 snd_soc_write(codec, TLV320AIC23_SRATE, data);
372#ifdef DEBUG 314#ifdef DEBUG
373 { 315 {
374 u32 adc, dac; 316 u32 adc, dac;
@@ -407,9 +349,8 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream,
407 if (ret < 0) 349 if (ret < 0)
408 return ret; 350 return ret;
409 351
410 iface_reg = 352 iface_reg = snd_soc_read(codec, TLV320AIC23_DIGT_FMT) & ~(0x03 << 2);
411 tlv320aic23_read_reg_cache(codec, 353
412 TLV320AIC23_DIGT_FMT) & ~(0x03 << 2);
413 switch (params_format(params)) { 354 switch (params_format(params)) {
414 case SNDRV_PCM_FORMAT_S16_LE: 355 case SNDRV_PCM_FORMAT_S16_LE:
415 break; 356 break;
@@ -423,7 +364,7 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream,
423 iface_reg |= (0x03 << 2); 364 iface_reg |= (0x03 << 2);
424 break; 365 break;
425 } 366 }
426 tlv320aic23_write(codec, TLV320AIC23_DIGT_FMT, iface_reg); 367 snd_soc_write(codec, TLV320AIC23_DIGT_FMT, iface_reg);
427 368
428 return 0; 369 return 0;
429} 370}
@@ -435,7 +376,7 @@ static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream,
435 struct snd_soc_codec *codec = rtd->codec; 376 struct snd_soc_codec *codec = rtd->codec;
436 377
437 /* set active */ 378 /* set active */
438 tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0001); 379 snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0001);
439 380
440 return 0; 381 return 0;
441} 382}
@@ -450,7 +391,7 @@ static void tlv320aic23_shutdown(struct snd_pcm_substream *substream,
450 /* deactivate */ 391 /* deactivate */
451 if (!codec->active) { 392 if (!codec->active) {
452 udelay(50); 393 udelay(50);
453 tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0); 394 snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0);
454 } 395 }
455 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 396 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
456 aic23->requested_dac = 0; 397 aic23->requested_dac = 0;
@@ -463,14 +404,14 @@ static int tlv320aic23_mute(struct snd_soc_dai *dai, int mute)
463 struct snd_soc_codec *codec = dai->codec; 404 struct snd_soc_codec *codec = dai->codec;
464 u16 reg; 405 u16 reg;
465 406
466 reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_DIGT); 407 reg = snd_soc_read(codec, TLV320AIC23_DIGT);
467 if (mute) 408 if (mute)
468 reg |= TLV320AIC23_DACM_MUTE; 409 reg |= TLV320AIC23_DACM_MUTE;
469 410
470 else 411 else
471 reg &= ~TLV320AIC23_DACM_MUTE; 412 reg &= ~TLV320AIC23_DACM_MUTE;
472 413
473 tlv320aic23_write(codec, TLV320AIC23_DIGT, reg); 414 snd_soc_write(codec, TLV320AIC23_DIGT, reg);
474 415
475 return 0; 416 return 0;
476} 417}
@@ -481,8 +422,7 @@ static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai,
481 struct snd_soc_codec *codec = codec_dai->codec; 422 struct snd_soc_codec *codec = codec_dai->codec;
482 u16 iface_reg; 423 u16 iface_reg;
483 424
484 iface_reg = 425 iface_reg = snd_soc_read(codec, TLV320AIC23_DIGT_FMT) & (~0x03);
485 tlv320aic23_read_reg_cache(codec, TLV320AIC23_DIGT_FMT) & (~0x03);
486 426
487 /* set master/slave audio interface */ 427 /* set master/slave audio interface */
488 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 428 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -516,7 +456,7 @@ static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai,
516 456
517 } 457 }
518 458
519 tlv320aic23_write(codec, TLV320AIC23_DIGT_FMT, iface_reg); 459 snd_soc_write(codec, TLV320AIC23_DIGT_FMT, iface_reg);
520 460
521 return 0; 461 return 0;
522} 462}
@@ -532,26 +472,26 @@ static int tlv320aic23_set_dai_sysclk(struct snd_soc_dai *codec_dai,
532static int tlv320aic23_set_bias_level(struct snd_soc_codec *codec, 472static int tlv320aic23_set_bias_level(struct snd_soc_codec *codec,
533 enum snd_soc_bias_level level) 473 enum snd_soc_bias_level level)
534{ 474{
535 u16 reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_PWR) & 0xff7f; 475 u16 reg = snd_soc_read(codec, TLV320AIC23_PWR) & 0xff7f;
536 476
537 switch (level) { 477 switch (level) {
538 case SND_SOC_BIAS_ON: 478 case SND_SOC_BIAS_ON:
539 /* vref/mid, osc on, dac unmute */ 479 /* vref/mid, osc on, dac unmute */
540 reg &= ~(TLV320AIC23_DEVICE_PWR_OFF | TLV320AIC23_OSC_OFF | \ 480 reg &= ~(TLV320AIC23_DEVICE_PWR_OFF | TLV320AIC23_OSC_OFF | \
541 TLV320AIC23_DAC_OFF); 481 TLV320AIC23_DAC_OFF);
542 tlv320aic23_write(codec, TLV320AIC23_PWR, reg); 482 snd_soc_write(codec, TLV320AIC23_PWR, reg);
543 break; 483 break;
544 case SND_SOC_BIAS_PREPARE: 484 case SND_SOC_BIAS_PREPARE:
545 break; 485 break;
546 case SND_SOC_BIAS_STANDBY: 486 case SND_SOC_BIAS_STANDBY:
547 /* everything off except vref/vmid, */ 487 /* everything off except vref/vmid, */
548 tlv320aic23_write(codec, TLV320AIC23_PWR, reg | \ 488 snd_soc_write(codec, TLV320AIC23_PWR,
549 TLV320AIC23_CLK_OFF); 489 reg | TLV320AIC23_CLK_OFF);
550 break; 490 break;
551 case SND_SOC_BIAS_OFF: 491 case SND_SOC_BIAS_OFF:
552 /* everything off, dac mute, inactive */ 492 /* everything off, dac mute, inactive */
553 tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0); 493 snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0);
554 tlv320aic23_write(codec, TLV320AIC23_PWR, 0xffff); 494 snd_soc_write(codec, TLV320AIC23_PWR, 0xffff);
555 break; 495 break;
556 } 496 }
557 codec->dapm.bias_level = level; 497 codec->dapm.bias_level = level;
@@ -598,13 +538,7 @@ static int tlv320aic23_suspend(struct snd_soc_codec *codec,
598 538
599static int tlv320aic23_resume(struct snd_soc_codec *codec) 539static int tlv320aic23_resume(struct snd_soc_codec *codec)
600{ 540{
601 u16 reg; 541 snd_soc_cache_sync(codec);
602
603 /* Sync reg_cache with the hardware */
604 for (reg = 0; reg <= TLV320AIC23_ACTIVE; reg++) {
605 u16 val = tlv320aic23_read_reg_cache(codec, reg);
606 tlv320aic23_write(codec, reg, val);
607 }
608 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 542 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
609 543
610 return 0; 544 return 0;
@@ -613,46 +547,52 @@ static int tlv320aic23_resume(struct snd_soc_codec *codec)
613static int tlv320aic23_probe(struct snd_soc_codec *codec) 547static int tlv320aic23_probe(struct snd_soc_codec *codec)
614{ 548{
615 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); 549 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
616 int reg; 550 int ret;
617 551
618 printk(KERN_INFO "AIC23 Audio Codec %s\n", AIC23_VERSION); 552 printk(KERN_INFO "AIC23 Audio Codec %s\n", AIC23_VERSION);
619 codec->control_data = aic23->control_data; 553
620 codec->hw_write = (hw_write_t)i2c_master_send; 554 ret = snd_soc_codec_set_cache_io(codec, 7, 9, aic23->control_type);
621 codec->hw_read = NULL; 555 if (ret < 0) {
556 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
557 return ret;
558 }
622 559
623 /* Reset codec */ 560 /* Reset codec */
624 tlv320aic23_write(codec, TLV320AIC23_RESET, 0); 561 snd_soc_write(codec, TLV320AIC23_RESET, 0);
562
563 /* Write the register default value to cache for reserved registers,
564 * so the write to the these registers are suppressed by the cache
565 * restore code when it skips writes of default registers.
566 */
567 snd_soc_cache_write(codec, 0x0A, 0);
568 snd_soc_cache_write(codec, 0x0B, 0);
569 snd_soc_cache_write(codec, 0x0C, 0);
570 snd_soc_cache_write(codec, 0x0D, 0);
571 snd_soc_cache_write(codec, 0x0E, 0);
625 572
626 /* power on device */ 573 /* power on device */
627 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 574 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
628 575
629 tlv320aic23_write(codec, TLV320AIC23_DIGT, TLV320AIC23_DEEMP_44K); 576 snd_soc_write(codec, TLV320AIC23_DIGT, TLV320AIC23_DEEMP_44K);
630 577
631 /* Unmute input */ 578 /* Unmute input */
632 reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_LINVOL); 579 snd_soc_update_bits(codec, TLV320AIC23_LINVOL,
633 tlv320aic23_write(codec, TLV320AIC23_LINVOL, 580 TLV320AIC23_LIM_MUTED, TLV320AIC23_LRS_ENABLED);
634 (reg & (~TLV320AIC23_LIM_MUTED)) |
635 (TLV320AIC23_LRS_ENABLED));
636 581
637 reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_RINVOL); 582 snd_soc_update_bits(codec, TLV320AIC23_RINVOL,
638 tlv320aic23_write(codec, TLV320AIC23_RINVOL, 583 TLV320AIC23_LIM_MUTED, TLV320AIC23_LRS_ENABLED);
639 (reg & (~TLV320AIC23_LIM_MUTED)) |
640 TLV320AIC23_LRS_ENABLED);
641 584
642 reg = tlv320aic23_read_reg_cache(codec, TLV320AIC23_ANLG); 585 snd_soc_update_bits(codec, TLV320AIC23_ANLG,
643 tlv320aic23_write(codec, TLV320AIC23_ANLG, 586 TLV320AIC23_BYPASS_ON | TLV320AIC23_MICM_MUTED,
644 (reg) & (~TLV320AIC23_BYPASS_ON) & 587 0);
645 (~TLV320AIC23_MICM_MUTED));
646 588
647 /* Default output volume */ 589 /* Default output volume */
648 tlv320aic23_write(codec, TLV320AIC23_LCHNVOL, 590 snd_soc_write(codec, TLV320AIC23_LCHNVOL,
649 TLV320AIC23_DEFAULT_OUT_VOL & 591 TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK);
650 TLV320AIC23_OUT_VOL_MASK); 592 snd_soc_write(codec, TLV320AIC23_RCHNVOL,
651 tlv320aic23_write(codec, TLV320AIC23_RCHNVOL, 593 TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK);
652 TLV320AIC23_DEFAULT_OUT_VOL &
653 TLV320AIC23_OUT_VOL_MASK);
654 594
655 tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x1); 595 snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x1);
656 596
657 snd_soc_add_controls(codec, tlv320aic23_snd_controls, 597 snd_soc_add_controls(codec, tlv320aic23_snd_controls,
658 ARRAY_SIZE(tlv320aic23_snd_controls)); 598 ARRAY_SIZE(tlv320aic23_snd_controls));
@@ -674,8 +614,6 @@ static struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = {
674 .remove = tlv320aic23_remove, 614 .remove = tlv320aic23_remove,
675 .suspend = tlv320aic23_suspend, 615 .suspend = tlv320aic23_suspend,
676 .resume = tlv320aic23_resume, 616 .resume = tlv320aic23_resume,
677 .read = tlv320aic23_read_reg_cache,
678 .write = tlv320aic23_write,
679 .set_bias_level = tlv320aic23_set_bias_level, 617 .set_bias_level = tlv320aic23_set_bias_level,
680 .dapm_widgets = tlv320aic23_dapm_widgets, 618 .dapm_widgets = tlv320aic23_dapm_widgets,
681 .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets), 619 .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
@@ -702,7 +640,6 @@ static int tlv320aic23_codec_probe(struct i2c_client *i2c,
702 return -ENOMEM; 640 return -ENOMEM;
703 641
704 i2c_set_clientdata(i2c, aic23); 642 i2c_set_clientdata(i2c, aic23);
705 aic23->control_data = i2c;
706 aic23->control_type = SND_SOC_I2C; 643 aic23->control_type = SND_SOC_I2C;
707 644
708 ret = snd_soc_register_codec(&i2c->dev, 645 ret = snd_soc_register_codec(&i2c->dev,