@@ -47,63 +47,6 @@ static const u16 tlv320aic23_reg[] = {
47
47
0x0000 , 0x0000 , 0x0000 , 0x0000 , /* 12 */
48
48
};
49
49
50
- /*
51
- * read tlv320aic23 register cache
52
- */
53
- static 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
- */
65
- static 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
- */
77
- static 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
-
107
50
static const char * rec_src_text [] = { "Line" , "Mic" };
108
51
static 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
83
val = (val >= 4 ) ? 4 : (3 - val );
141
84
142
- reg = tlv320aic23_read_reg_cache (codec , TLV320AIC23_ANLG ) & (~0x1C0 );
143
- tlv320aic23_write (codec , TLV320AIC23_ANLG , reg | (val << 6 ));
85
+ reg = snd_soc_read (codec , TLV320AIC23_ANLG ) & (~0x1C0 );
86
+ snd_soc_write (codec , TLV320AIC23_ANLG , reg | (val << 6 ));
144
87
145
88
return 0 ;
146
89
}
@@ -151,7 +94,7 @@ static int snd_soc_tlv320aic23_get_volsw(struct snd_kcontrol *kcontrol,
151
94
struct snd_soc_codec * codec = snd_kcontrol_chip (kcontrol );
152
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
98
val = val >> 6 ;
156
99
val = (val >= 4 ) ? 4 : (3 - val );
157
100
ucontrol -> value .integer .value [0 ] = val ;
@@ -232,7 +175,6 @@ static const struct snd_soc_dapm_route tlv320aic23_intercon[] = {
232
175
/* AIC23 driver data */
233
176
struct aic23 {
234
177
enum snd_soc_control_type control_type ;
235
- void * control_data ;
236
178
int mclk ;
237
179
int requested_adc ;
238
180
int requested_dac ;
@@ -344,7 +286,7 @@ static int find_rate(int mclk, u32 need_adc, u32 need_dac)
344
286
static void get_current_sample_rates (struct snd_soc_codec * codec , int mclk ,
345
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
290
int sr = (src >> 2 ) & 0x0f ;
349
291
int val = (mclk / bosr_usb_divisor_table [src & 3 ]);
350
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
310
__func__ , sample_rate_adc , sample_rate_dac );
369
311
return - EINVAL ;
370
312
}
371
- tlv320aic23_write (codec , TLV320AIC23_SRATE , data );
313
+ snd_soc_write (codec , TLV320AIC23_SRATE , data );
372
314
#ifdef DEBUG
373
315
{
374
316
u32 adc , dac ;
@@ -407,9 +349,8 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream,
407
349
if (ret < 0 )
408
350
return ret ;
409
351
410
- iface_reg =
411
- tlv320aic23_read_reg_cache (codec ,
412
- TLV320AIC23_DIGT_FMT ) & ~(0x03 << 2 );
352
+ iface_reg = snd_soc_read (codec , TLV320AIC23_DIGT_FMT ) & ~(0x03 << 2 );
353
+
413
354
switch (params_format (params )) {
414
355
case SNDRV_PCM_FORMAT_S16_LE :
415
356
break ;
@@ -423,7 +364,7 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream,
423
364
iface_reg |= (0x03 << 2 );
424
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
369
return 0 ;
429
370
}
@@ -435,7 +376,7 @@ static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream,
435
376
struct snd_soc_codec * codec = rtd -> codec ;
436
377
437
378
/* set active */
438
- tlv320aic23_write (codec , TLV320AIC23_ACTIVE , 0x0001 );
379
+ snd_soc_write (codec , TLV320AIC23_ACTIVE , 0x0001 );
439
380
440
381
return 0 ;
441
382
}
@@ -450,7 +391,7 @@ static void tlv320aic23_shutdown(struct snd_pcm_substream *substream,
450
391
/* deactivate */
451
392
if (!codec -> active ) {
452
393
udelay (50 );
453
- tlv320aic23_write (codec , TLV320AIC23_ACTIVE , 0x0 );
394
+ snd_soc_write (codec , TLV320AIC23_ACTIVE , 0x0 );
454
395
}
455
396
if (substream -> stream == SNDRV_PCM_STREAM_PLAYBACK )
456
397
aic23 -> requested_dac = 0 ;
@@ -463,14 +404,14 @@ static int tlv320aic23_mute(struct snd_soc_dai *dai, int mute)
463
404
struct snd_soc_codec * codec = dai -> codec ;
464
405
u16 reg ;
465
406
466
- reg = tlv320aic23_read_reg_cache (codec , TLV320AIC23_DIGT );
407
+ reg = snd_soc_read (codec , TLV320AIC23_DIGT );
467
408
if (mute )
468
409
reg |= TLV320AIC23_DACM_MUTE ;
469
410
470
411
else
471
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
416
return 0 ;
476
417
}
@@ -481,8 +422,7 @@ static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai,
481
422
struct snd_soc_codec * codec = codec_dai -> codec ;
482
423
u16 iface_reg ;
483
424
484
- iface_reg =
485
- tlv320aic23_read_reg_cache (codec , TLV320AIC23_DIGT_FMT ) & (~0x03 );
425
+ iface_reg = snd_soc_read (codec , TLV320AIC23_DIGT_FMT ) & (~0x03 );
486
426
487
427
/* set master/slave audio interface */
488
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
461
return 0 ;
522
462
}
@@ -532,26 +472,26 @@ static int tlv320aic23_set_dai_sysclk(struct snd_soc_dai *codec_dai,
532
472
static int tlv320aic23_set_bias_level (struct snd_soc_codec * codec ,
533
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
477
switch (level ) {
538
478
case SND_SOC_BIAS_ON :
539
479
/* vref/mid, osc on, dac unmute */
540
480
reg &= ~(TLV320AIC23_DEVICE_PWR_OFF | TLV320AIC23_OSC_OFF | \
541
481
TLV320AIC23_DAC_OFF );
542
- tlv320aic23_write (codec , TLV320AIC23_PWR , reg );
482
+ snd_soc_write (codec , TLV320AIC23_PWR , reg );
543
483
break ;
544
484
case SND_SOC_BIAS_PREPARE :
545
485
break ;
546
486
case SND_SOC_BIAS_STANDBY :
547
487
/* everything off except vref/vmid, */
548
- tlv320aic23_write (codec , TLV320AIC23_PWR , reg | \
549
- TLV320AIC23_CLK_OFF );
488
+ snd_soc_write (codec , TLV320AIC23_PWR ,
489
+ reg | TLV320AIC23_CLK_OFF );
550
490
break ;
551
491
case SND_SOC_BIAS_OFF :
552
492
/* everything off, dac mute, inactive */
553
- tlv320aic23_write (codec , TLV320AIC23_ACTIVE , 0x0 );
554
- tlv320aic23_write (codec , TLV320AIC23_PWR , 0xffff );
493
+ snd_soc_write (codec , TLV320AIC23_ACTIVE , 0x0 );
494
+ snd_soc_write (codec , TLV320AIC23_PWR , 0xffff );
555
495
break ;
556
496
}
557
497
codec -> dapm .bias_level = level ;
@@ -598,13 +538,7 @@ static int tlv320aic23_suspend(struct snd_soc_codec *codec,
598
538
599
539
static int tlv320aic23_resume (struct snd_soc_codec * codec )
600
540
{
601
- u16 reg ;
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
- }
541
+ snd_soc_cache_sync (codec );
608
542
tlv320aic23_set_bias_level (codec , SND_SOC_BIAS_STANDBY );
609
543
610
544
return 0 ;
@@ -613,46 +547,52 @@ static int tlv320aic23_resume(struct snd_soc_codec *codec)
613
547
static int tlv320aic23_probe (struct snd_soc_codec * codec )
614
548
{
615
549
struct aic23 * aic23 = snd_soc_codec_get_drvdata (codec );
616
- int reg ;
550
+ int ret ;
617
551
618
552
printk (KERN_INFO "AIC23 Audio Codec %s\n" , AIC23_VERSION );
619
- codec -> control_data = aic23 -> control_data ;
620
- codec -> hw_write = (hw_write_t )i2c_master_send ;
621
- codec -> hw_read = NULL ;
553
+
554
+ ret = snd_soc_codec_set_cache_io (codec , 7 , 9 , aic23 -> control_type );
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
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
573
/* power on device */
627
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
578
/* Unmute input */
632
- reg = tlv320aic23_read_reg_cache (codec , TLV320AIC23_LINVOL );
633
- tlv320aic23_write (codec , TLV320AIC23_LINVOL ,
634
- (reg & (~TLV320AIC23_LIM_MUTED )) |
635
- (TLV320AIC23_LRS_ENABLED ));
579
+ snd_soc_update_bits (codec , TLV320AIC23_LINVOL ,
580
+ TLV320AIC23_LIM_MUTED , TLV320AIC23_LRS_ENABLED );
636
581
637
- reg = tlv320aic23_read_reg_cache (codec , TLV320AIC23_RINVOL );
638
- tlv320aic23_write (codec , TLV320AIC23_RINVOL ,
639
- (reg & (~TLV320AIC23_LIM_MUTED )) |
640
- TLV320AIC23_LRS_ENABLED );
582
+ snd_soc_update_bits (codec , TLV320AIC23_RINVOL ,
583
+ TLV320AIC23_LIM_MUTED , TLV320AIC23_LRS_ENABLED );
641
584
642
- reg = tlv320aic23_read_reg_cache (codec , TLV320AIC23_ANLG );
643
- tlv320aic23_write (codec , TLV320AIC23_ANLG ,
644
- (reg ) & (~TLV320AIC23_BYPASS_ON ) &
645
- (~TLV320AIC23_MICM_MUTED ));
585
+ snd_soc_update_bits (codec , TLV320AIC23_ANLG ,
586
+ TLV320AIC23_BYPASS_ON | TLV320AIC23_MICM_MUTED ,
587
+ 0 );
646
588
647
589
/* Default output volume */
648
- tlv320aic23_write (codec , TLV320AIC23_LCHNVOL ,
649
- TLV320AIC23_DEFAULT_OUT_VOL &
650
- TLV320AIC23_OUT_VOL_MASK );
651
- tlv320aic23_write (codec , TLV320AIC23_RCHNVOL ,
652
- TLV320AIC23_DEFAULT_OUT_VOL &
653
- TLV320AIC23_OUT_VOL_MASK );
590
+ snd_soc_write (codec , TLV320AIC23_LCHNVOL ,
591
+ TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK );
592
+ snd_soc_write (codec , TLV320AIC23_RCHNVOL ,
593
+ TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK );
654
594
655
- tlv320aic23_write (codec , TLV320AIC23_ACTIVE , 0x1 );
595
+ snd_soc_write (codec , TLV320AIC23_ACTIVE , 0x1 );
656
596
657
597
snd_soc_add_controls (codec , tlv320aic23_snd_controls ,
658
598
ARRAY_SIZE (tlv320aic23_snd_controls ));
@@ -674,8 +614,6 @@ static struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = {
674
614
.remove = tlv320aic23_remove ,
675
615
.suspend = tlv320aic23_suspend ,
676
616
.resume = tlv320aic23_resume ,
677
- .read = tlv320aic23_read_reg_cache ,
678
- .write = tlv320aic23_write ,
679
617
.set_bias_level = tlv320aic23_set_bias_level ,
680
618
.dapm_widgets = tlv320aic23_dapm_widgets ,
681
619
.num_dapm_widgets = ARRAY_SIZE (tlv320aic23_dapm_widgets ),
@@ -702,7 +640,6 @@ static int tlv320aic23_codec_probe(struct i2c_client *i2c,
702
640
return - ENOMEM ;
703
641
704
642
i2c_set_clientdata (i2c , aic23 );
705
- aic23 -> control_data = i2c ;
706
643
aic23 -> control_type = SND_SOC_I2C ;
707
644
708
645
ret = snd_soc_register_codec (& i2c -> dev ,
0 commit comments