@@ -36,6 +36,7 @@ struct dsp_code {
36
36
37
37
struct glb_pool {
38
38
struct mutex lock ;
39
+ unsigned int dual_mode ;
39
40
unsigned int set_lowpass ;
40
41
unsigned int set_mode ;
41
42
unsigned int set_rate ;
@@ -47,8 +48,8 @@ bool glb_mclk;
47
48
48
49
static struct gpio_desc * mute_gpio [2 ];
49
50
50
-
51
51
static const char * const allo_piano_mode_texts [] = {
52
+ "None" ,
52
53
"2.0" ,
53
54
"2.1" ,
54
55
"2.2" ,
@@ -57,6 +58,15 @@ static const char * const allo_piano_mode_texts[] = {
57
58
static const SOC_ENUM_SINGLE_DECL (allo_piano_mode_enum ,
58
59
0 , 0 , allo_piano_mode_texts ) ;
59
60
61
+ static const char * const allo_piano_dual_mode_texts [] = {
62
+ "None" ,
63
+ "Dual-Mono" ,
64
+ "Dual-Stereo" ,
65
+ };
66
+
67
+ static const SOC_ENUM_SINGLE_DECL (allo_piano_dual_mode_enum ,
68
+ 0 , 0 , allo_piano_dual_mode_texts ) ;
69
+
60
70
static const char * const allo_piano_dsp_low_pass_texts [] = {
61
71
"60" ,
62
72
"70" ,
@@ -82,10 +92,10 @@ static int __snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
82
92
unsigned int mode , unsigned int rate , unsigned int lowpass )
83
93
{
84
94
const struct firmware * fw ;
85
- char firmware_name [60 ];
86
- int ret = 0 , dac = 0 ;
87
95
struct snd_soc_card * card = rtd -> card ;
88
96
struct glb_pool * glb_ptr = card -> drvdata ;
97
+ char firmware_name [60 ];
98
+ int ret = 0 , dac = 0 ;
89
99
90
100
if (rate <= 46000 )
91
101
rate = 44100 ;
@@ -100,26 +110,35 @@ static int __snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
100
110
else
101
111
rate = 192000 ;
102
112
103
- if ((lowpass > 14 ) || (lowpass < 0 ))
104
- lowpass = 3 ;
105
- if ((mode > 2 ) || (mode < 0 ))
106
- mode = 0 ;
113
+ if (lowpass > 14 )
114
+ glb_ptr -> set_lowpass = lowpass = 3 ;
115
+
116
+ if (mode > 3 )
117
+ glb_ptr -> set_mode = mode = 0 ;
118
+
119
+ if (mode > 0 )
120
+ glb_ptr -> dual_mode = 0 ;
107
121
108
122
/* same configuration loaded */
109
123
if ((rate == glb_ptr -> set_rate ) && (lowpass == glb_ptr -> set_lowpass )
110
124
&& (mode == glb_ptr -> set_mode ))
111
125
return 0 ;
112
126
113
- if (mode == 0 ) { /* 2.0 */
114
- snd_soc_write (rtd -> codec_dais [1 ]-> codec ,
115
- PCM512x_MUTE , 0x11 );
127
+ switch (mode ) {
128
+ case 0 : /* None */
129
+ return 1 ;
130
+
131
+ case 1 : /* 2.0 */
132
+ snd_soc_write (rtd -> codec_dais [0 ]-> codec , PCM512x_MUTE , 0x00 );
133
+ snd_soc_write (rtd -> codec_dais [1 ]-> codec , PCM512x_MUTE , 0x11 );
116
134
glb_ptr -> set_rate = rate ;
117
135
glb_ptr -> set_mode = mode ;
118
136
glb_ptr -> set_lowpass = lowpass ;
119
137
return 1 ;
120
- } else {
121
- snd_soc_write (rtd -> codec_dais [1 ]-> codec ,
122
- PCM512x_MUTE , 0x00 );
138
+
139
+ default :
140
+ snd_soc_write (rtd -> codec_dais [0 ]-> codec , PCM512x_MUTE , 0x00 );
141
+ snd_soc_write (rtd -> codec_dais [1 ]-> codec , PCM512x_MUTE , 0x00 );
123
142
}
124
143
125
144
for (dac = 0 ; dac < rtd -> num_codecs ; dac ++ ) {
@@ -128,13 +147,13 @@ static int __snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
128
147
int i = 1 ;
129
148
130
149
if (dac == 0 ) { /* high */
131
- sprintf (firmware_name ,
150
+ snprintf (firmware_name , sizeof ( firmware_name ) ,
132
151
"allo/piano/2.2/allo-piano-dsp-%d-%d-%d.bin" ,
133
152
rate , ((lowpass * 10 ) + 60 ), dac );
134
153
} else { /* low */
135
- sprintf (firmware_name ,
154
+ snprintf (firmware_name , sizeof ( firmware_name ) ,
136
155
"allo/piano/2.%d/allo-piano-dsp-%d-%d-%d.bin" ,
137
- mode , rate , ((lowpass * 10 ) + 60 ), dac );
156
+ ( mode - 1 ) , rate , ((lowpass * 10 ) + 60 ), dac );
138
157
}
139
158
140
159
dev_info (codec -> dev , "Dsp Firmware File Name: %s\n" ,
@@ -199,6 +218,80 @@ static int snd_allo_piano_dsp_program(struct snd_soc_pcm_runtime *rtd,
199
218
return ret ;
200
219
}
201
220
221
+ static int snd_allo_piano_dual_mode_get (struct snd_kcontrol * kcontrol ,
222
+ struct snd_ctl_elem_value * ucontrol )
223
+ {
224
+ struct snd_soc_card * card = snd_kcontrol_chip (kcontrol );
225
+ struct glb_pool * glb_ptr = card -> drvdata ;
226
+
227
+ ucontrol -> value .integer .value [0 ] = glb_ptr -> dual_mode ;
228
+
229
+ return 0 ;
230
+ }
231
+
232
+ static int snd_allo_piano_dual_mode_put (struct snd_kcontrol * kcontrol ,
233
+ struct snd_ctl_elem_value * ucontrol )
234
+ {
235
+ struct snd_soc_card * card = snd_kcontrol_chip (kcontrol );
236
+ struct glb_pool * glb_ptr = card -> drvdata ;
237
+ struct snd_soc_pcm_runtime * rtd ;
238
+ struct snd_card * snd_card_ptr = card -> snd_card ;
239
+ struct snd_kcontrol * kctl ;
240
+ struct soc_mixer_control * mc ;
241
+ unsigned int left_val = 0 ;
242
+
243
+ rtd = snd_soc_get_pcm_runtime (card , card -> dai_link [0 ].name );
244
+
245
+ if (ucontrol -> value .integer .value [0 ] > 0 ) {
246
+ glb_ptr -> dual_mode = ucontrol -> value .integer .value [0 ];
247
+ glb_ptr -> set_mode = 0 ;
248
+ } else if (ucontrol -> value .integer .value [0 ] <= 0 ) {
249
+ if (glb_ptr -> set_mode <= 0 ) {
250
+ glb_ptr -> dual_mode = 1 ;
251
+ glb_ptr -> set_mode = 0 ;
252
+ }
253
+ } else {
254
+ glb_ptr -> dual_mode = 0 ;
255
+ return 0 ;
256
+ }
257
+
258
+ if (glb_ptr -> dual_mode == 1 ) {
259
+ snd_soc_write (rtd -> codec_dais [0 ]-> codec , PCM512x_MUTE , 0x01 );
260
+ snd_soc_write (rtd -> codec_dais [1 ]-> codec , PCM512x_MUTE , 0x10 );
261
+ snd_soc_write (rtd -> codec_dais [0 ]-> codec ,
262
+ PCM512x_DIGITAL_VOLUME_3 , 0xff );
263
+
264
+ list_for_each_entry (kctl , & snd_card_ptr -> controls , list ) {
265
+ if (!strncmp (kctl -> id .name , "Digital Playback Volume" ,
266
+ sizeof (kctl -> id .name ))) {
267
+ mc = (struct soc_mixer_control * )
268
+ kctl -> private_value ;
269
+ mc -> rreg = mc -> reg ;
270
+ break ;
271
+ }
272
+ }
273
+ } else {
274
+ left_val = snd_soc_read (rtd -> codec_dais [0 ]-> codec ,
275
+ PCM512x_DIGITAL_VOLUME_2 );
276
+ list_for_each_entry (kctl , & snd_card_ptr -> controls , list ) {
277
+ if (!strncmp (kctl -> id .name , "Digital Playback Volume" ,
278
+ sizeof (kctl -> id .name ))) {
279
+ mc = (struct soc_mixer_control * )
280
+ kctl -> private_value ;
281
+ mc -> rreg = PCM512x_DIGITAL_VOLUME_3 ;
282
+ break ;
283
+ }
284
+ }
285
+
286
+ snd_soc_write (rtd -> codec_dais [0 ]-> codec ,
287
+ PCM512x_DIGITAL_VOLUME_3 , left_val );
288
+ snd_soc_write (rtd -> codec_dais [0 ]-> codec , PCM512x_MUTE , 0x00 );
289
+ snd_soc_write (rtd -> codec_dais [1 ]-> codec , PCM512x_MUTE , 0x00 );
290
+ }
291
+
292
+ return 0 ;
293
+ }
294
+
202
295
static int snd_allo_piano_mode_get (struct snd_kcontrol * kcontrol ,
203
296
struct snd_ctl_elem_value * ucontrol )
204
297
{
@@ -215,8 +308,30 @@ static int snd_allo_piano_mode_put(struct snd_kcontrol *kcontrol,
215
308
struct snd_soc_card * card = snd_kcontrol_chip (kcontrol );
216
309
struct snd_soc_pcm_runtime * rtd ;
217
310
struct glb_pool * glb_ptr = card -> drvdata ;
311
+ struct snd_card * snd_card_ptr = card -> snd_card ;
312
+ struct snd_kcontrol * kctl ;
313
+ struct soc_mixer_control * mc ;
314
+ unsigned int left_val = 0 ;
218
315
219
316
rtd = snd_soc_get_pcm_runtime (card , card -> dai_link [0 ].name );
317
+
318
+ if ((glb_ptr -> dual_mode == 1 ) &&
319
+ (ucontrol -> value .integer .value [0 ] > 0 )) {
320
+ left_val = snd_soc_read (rtd -> codec_dais [0 ]-> codec ,
321
+ PCM512x_DIGITAL_VOLUME_2 );
322
+ list_for_each_entry (kctl , & snd_card_ptr -> controls , list ) {
323
+ if (!strncmp (kctl -> id .name , "Digital Playback Volume" ,
324
+ sizeof (kctl -> id .name ))) {
325
+ mc = (struct soc_mixer_control * )
326
+ kctl -> private_value ;
327
+ mc -> rreg = PCM512x_DIGITAL_VOLUME_3 ;
328
+ break ;
329
+ }
330
+ }
331
+ snd_soc_write (rtd -> codec_dais [0 ]-> codec ,
332
+ PCM512x_DIGITAL_VOLUME_3 , left_val );
333
+ }
334
+
220
335
return (snd_allo_piano_dsp_program (rtd ,
221
336
ucontrol -> value .integer .value [0 ],
222
337
glb_ptr -> set_rate , glb_ptr -> set_lowpass ));
@@ -344,6 +459,11 @@ static const struct snd_kcontrol_new allo_piano_controls[] = {
344
459
snd_allo_piano_mode_get ,
345
460
snd_allo_piano_mode_put ),
346
461
462
+ SOC_ENUM_EXT ("Dual Mode Route" ,
463
+ allo_piano_dual_mode_enum ,
464
+ snd_allo_piano_dual_mode_get ,
465
+ snd_allo_piano_dual_mode_put ),
466
+
347
467
SOC_ENUM_EXT ("Lowpass Route" , allo_piano_enum ,
348
468
snd_allo_piano_lowpass_get ,
349
469
snd_allo_piano_lowpass_put ),
@@ -472,7 +592,7 @@ static int snd_allo_piano_dac_hw_params(
472
592
PCM512x_RATE_DET_4 );
473
593
if (val < 0 ) {
474
594
dev_err (rtd -> codec_dais [dac ]-> codec -> dev ,
475
- "Failed to read register PCM512x_RATE_DET_4\n" );
595
+ "Failed to read register PCM512x_RATE_DET_4\n" );
476
596
return val ;
477
597
}
478
598
@@ -482,7 +602,7 @@ static int snd_allo_piano_dac_hw_params(
482
602
PCM512x_SREF_BCK );
483
603
484
604
dev_info (rtd -> codec_dais [dac ]-> codec -> dev ,
485
- "Setting BCLK as input clock & Enable PLL\n" );
605
+ "Setting BCLK as input clock & Enable PLL\n" );
486
606
} else {
487
607
snd_soc_write (rtd -> codec_dais [dac ]-> codec ,
488
608
PCM512x_PLL_EN ,
@@ -493,7 +613,7 @@ static int snd_allo_piano_dac_hw_params(
493
613
PCM512x_SREF_SCK );
494
614
495
615
dev_info (rtd -> codec_dais [dac ]-> codec -> dev ,
496
- "Setting SCLK as input clock & disabled PLL\n" );
616
+ "Setting SCLK as input clock & disabled PLL\n" );
497
617
}
498
618
}
499
619
@@ -504,6 +624,7 @@ static int snd_allo_piano_dac_hw_params(
504
624
dev_warn (card -> dev , "Failed to set volume limit: %d\n" ,
505
625
ret );
506
626
}
627
+
507
628
ret = snd_allo_piano_dsp_program (rtd , glb_ptr -> set_mode , rate ,
508
629
glb_ptr -> set_lowpass );
509
630
if (ret < 0 )
@@ -521,6 +642,7 @@ static int snd_allo_piano_dac_prepare(
521
642
struct snd_soc_card * card = rtd -> card ;
522
643
523
644
snd_allo_piano_gpio_unmute (card );
645
+
524
646
return 0 ;
525
647
}
526
648
0 commit comments