18
18
19
19
#include <linux/module.h>
20
20
#include <linux/platform_device.h>
21
-
21
+ #include <linux/gpio/consumer.h>
22
22
#include <sound/core.h>
23
23
#include <sound/pcm.h>
24
24
#include <sound/pcm_params.h>
@@ -43,7 +43,10 @@ struct glb_pool {
43
43
};
44
44
45
45
static bool digital_gain_0db_limit = true;
46
- unsigned int set_lowpass , set_mode , set_rate , dsp_page_number ;
46
+ bool glb_mclk ;
47
+
48
+ static struct gpio_desc * mute_gpio [2 ];
49
+
47
50
48
51
static const char * const allo_piano_mode_texts [] = {
49
52
"2.0" ,
@@ -387,7 +390,71 @@ static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
387
390
return 0 ;
388
391
}
389
392
390
- static int snd_allo_piano_dac_hw_params (struct snd_pcm_substream * substream ,
393
+ static void snd_allo_piano_gpio_mute (struct snd_soc_card * card )
394
+ {
395
+ if (mute_gpio [0 ])
396
+ gpiod_set_value_cansleep (mute_gpio [0 ], 1 );
397
+
398
+ if (mute_gpio [1 ])
399
+ gpiod_set_value_cansleep (mute_gpio [1 ], 1 );
400
+ }
401
+
402
+ static void snd_allo_piano_gpio_unmute (struct snd_soc_card * card )
403
+ {
404
+ if (mute_gpio [0 ])
405
+ gpiod_set_value_cansleep (mute_gpio [0 ], 0 );
406
+
407
+ if (mute_gpio [1 ])
408
+ gpiod_set_value_cansleep (mute_gpio [1 ], 0 );
409
+ }
410
+
411
+ static int snd_allo_piano_set_bias_level (struct snd_soc_card * card ,
412
+ struct snd_soc_dapm_context * dapm , enum snd_soc_bias_level level )
413
+ {
414
+ struct snd_soc_pcm_runtime * rtd ;
415
+ struct snd_soc_dai * codec_dai ;
416
+
417
+ rtd = snd_soc_get_pcm_runtime (card , card -> dai_link [0 ].name );
418
+ codec_dai = rtd -> codec_dai ;
419
+
420
+ if (dapm -> dev != codec_dai -> dev )
421
+ return 0 ;
422
+
423
+ switch (level ) {
424
+ case SND_SOC_BIAS_PREPARE :
425
+ if (dapm -> bias_level != SND_SOC_BIAS_STANDBY )
426
+ break ;
427
+ /* UNMUTE DAC */
428
+ snd_allo_piano_gpio_unmute (card );
429
+ break ;
430
+
431
+ case SND_SOC_BIAS_STANDBY :
432
+ if (dapm -> bias_level != SND_SOC_BIAS_PREPARE )
433
+ break ;
434
+ /* MUTE DAC */
435
+ snd_allo_piano_gpio_mute (card );
436
+ break ;
437
+
438
+ default :
439
+ break ;
440
+ }
441
+
442
+ return 0 ;
443
+ }
444
+
445
+ static int snd_allo_piano_dac_startup (
446
+ struct snd_pcm_substream * substream )
447
+ {
448
+ struct snd_soc_pcm_runtime * rtd = substream -> private_data ;
449
+ struct snd_soc_card * card = rtd -> card ;
450
+
451
+ snd_allo_piano_gpio_mute (card );
452
+
453
+ return 0 ;
454
+ }
455
+
456
+ static int snd_allo_piano_dac_hw_params (
457
+ struct snd_pcm_substream * substream ,
391
458
struct snd_pcm_hw_params * params )
392
459
{
393
460
struct snd_soc_pcm_runtime * rtd = substream -> private_data ;
@@ -397,7 +464,38 @@ static int snd_allo_piano_dac_hw_params(struct snd_pcm_substream *substream,
397
464
unsigned int rate = params_rate (params );
398
465
struct snd_soc_card * card = rtd -> card ;
399
466
struct glb_pool * glb_ptr = card -> drvdata ;
400
- int ret = 0 ;
467
+ int ret = 0 , val = 0 , dac ;
468
+
469
+ for (dac = 0 ; (glb_mclk && dac < 2 ); dac ++ ) {
470
+ /* Configure the PLL clock reference for both the Codecs */
471
+ val = snd_soc_read (rtd -> codec_dais [dac ]-> codec ,
472
+ PCM512x_RATE_DET_4 );
473
+ if (val < 0 ) {
474
+ dev_err (rtd -> codec_dais [dac ]-> codec -> dev ,
475
+ "Failed to read register PCM512x_RATE_DET_4\n" );
476
+ return val ;
477
+ }
478
+
479
+ if (val & 0x40 ) {
480
+ snd_soc_write (rtd -> codec_dais [dac ]-> codec ,
481
+ PCM512x_PLL_REF ,
482
+ PCM512x_SREF_BCK );
483
+
484
+ dev_info (rtd -> codec_dais [dac ]-> codec -> dev ,
485
+ "Setting BCLK as input clock & Enable PLL\n" );
486
+ } else {
487
+ snd_soc_write (rtd -> codec_dais [dac ]-> codec ,
488
+ PCM512x_PLL_EN ,
489
+ 0x00 );
490
+
491
+ snd_soc_write (rtd -> codec_dais [dac ]-> codec ,
492
+ PCM512x_PLL_REF ,
493
+ PCM512x_SREF_SCK );
494
+
495
+ dev_info (rtd -> codec_dais [dac ]-> codec -> dev ,
496
+ "Setting SCLK as input clock & disabled PLL\n" );
497
+ }
498
+ }
401
499
402
500
if (digital_gain_0db_limit ) {
403
501
ret = snd_soc_limit_volume (card ,
@@ -416,9 +514,21 @@ static int snd_allo_piano_dac_hw_params(struct snd_pcm_substream *substream,
416
514
return ret ;
417
515
}
418
516
517
+ static int snd_allo_piano_dac_prepare (
518
+ struct snd_pcm_substream * substream )
519
+ {
520
+ struct snd_soc_pcm_runtime * rtd = substream -> private_data ;
521
+ struct snd_soc_card * card = rtd -> card ;
522
+
523
+ snd_allo_piano_gpio_unmute (card );
524
+ return 0 ;
525
+ }
526
+
419
527
/* machine stream operations */
420
528
static struct snd_soc_ops snd_allo_piano_dac_ops = {
529
+ .startup = snd_allo_piano_dac_startup ,
421
530
.hw_params = snd_allo_piano_dac_hw_params ,
531
+ .prepare = snd_allo_piano_dac_prepare ,
422
532
};
423
533
424
534
static struct snd_soc_dai_link_component allo_piano_2_1_codecs [] = {
@@ -483,6 +593,9 @@ static int snd_allo_piano_dac_probe(struct platform_device *pdev)
483
593
!of_property_read_bool (pdev -> dev .of_node ,
484
594
"allo,24db_digital_gain" );
485
595
596
+ glb_mclk = of_property_read_bool (pdev -> dev .of_node ,
597
+ "allo,glb_mclk" );
598
+
486
599
allo_piano_2_1_codecs [0 ].of_node =
487
600
of_parse_phandle (pdev -> dev .of_node , "audio-codec" , 0 );
488
601
if (!allo_piano_2_1_codecs [0 ].of_node ) {
@@ -498,22 +611,51 @@ static int snd_allo_piano_dac_probe(struct platform_device *pdev)
498
611
"Property 'audio-codec' missing or invalid\n" );
499
612
return - EINVAL ;
500
613
}
501
- }
502
614
503
- ret = snd_soc_register_card (& snd_allo_piano_dac );
504
- if (ret < 0 )
505
- dev_err (& pdev -> dev , "snd_soc_register_card() failed: %d\n" ,
506
- ret );
615
+ mute_gpio [0 ] = devm_gpiod_get_optional (& pdev -> dev , "mute1" ,
616
+ GPIOD_OUT_LOW );
617
+ if (IS_ERR (mute_gpio [0 ])) {
618
+ ret = PTR_ERR (mute_gpio [0 ]);
619
+ dev_err (& pdev -> dev ,
620
+ "failed to get mute1 gpio6: %d\n" , ret );
621
+ return ret ;
622
+ }
507
623
508
- return ret ;
624
+ mute_gpio [1 ] = devm_gpiod_get_optional (& pdev -> dev , "mute2" ,
625
+ GPIOD_OUT_LOW );
626
+ if (IS_ERR (mute_gpio [1 ])) {
627
+ ret = PTR_ERR (mute_gpio [1 ]);
628
+ dev_err (& pdev -> dev ,
629
+ "failed to get mute2 gpio25: %d\n" , ret );
630
+ return ret ;
631
+ }
632
+
633
+ if (mute_gpio [0 ] && mute_gpio [1 ])
634
+ snd_allo_piano_dac .set_bias_level =
635
+ snd_allo_piano_set_bias_level ;
636
+
637
+ ret = snd_soc_register_card (& snd_allo_piano_dac );
638
+ if (ret < 0 ) {
639
+ dev_err (& pdev -> dev ,
640
+ "snd_soc_register_card() failed: %d\n" , ret );
641
+ return ret ;
642
+ }
643
+
644
+ if ((mute_gpio [0 ]) && (mute_gpio [1 ]))
645
+ snd_allo_piano_gpio_mute (& snd_allo_piano_dac );
646
+
647
+ return 0 ;
648
+ }
649
+
650
+ return - EINVAL ;
509
651
}
510
652
511
653
static int snd_allo_piano_dac_remove (struct platform_device * pdev )
512
654
{
513
655
struct snd_soc_card * card = platform_get_drvdata (pdev );
514
656
515
657
kfree (& card -> drvdata );
516
-
658
+ snd_allo_piano_gpio_mute ( & snd_allo_piano_dac );
517
659
return snd_soc_unregister_card (& snd_allo_piano_dac );
518
660
}
519
661
0 commit comments