Skip to content

Commit 0ffa5a0

Browse files
author
BabuSubashChandar C
committed
Add clock changes and mute gpios.
Signed-off-by: Baswaraj K <[email protected]> Reviewed-by: Vijay Kumar B. <[email protected]> Reviewed-by: Raashid Muhammed <[email protected]>
1 parent e591aa7 commit 0ffa5a0

File tree

3 files changed

+160
-11
lines changed

3 files changed

+160
-11
lines changed

arch/arm/boot/dts/overlays/README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
323323
responsibility of the user to ensure that
324324
the Digital volume control is set to a value
325325
that does not result in clipping/distortion!)
326+
glb_mclk This option is only with Kali board. If enabled,
327+
MCLK for Kali is used and PLL is disabled for
328+
better voice quality. (default Off)
326329

327330

328331
Name: at86rf233

arch/arm/boot/dts/overlays/allo-piano-dac-plus-pcm512x-audio-overlay.dts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@
4040
compatible = "allo,piano-dac-plus";
4141
audio-codec = <&allo_pcm5122_4c &allo_pcm5122_4d>;
4242
i2s-controller = <&i2s>;
43+
mute1-gpios = <&gpio 6 1>;
44+
mute2-gpios = <&gpio 25 1>;
4345
status = "okay";
4446
};
4547
};
4648

4749
__overrides__ {
4850
24db_digital_gain =
4951
<&piano_dac>,"allo,24db_digital_gain?";
52+
glb_mclk =
53+
<&piano_dac>,"allo,glb_mclk?";
5054
};
5155
};

sound/soc/bcm/allo-piano-dac-plus.c

Lines changed: 153 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include <linux/module.h>
2020
#include <linux/platform_device.h>
21-
21+
#include <linux/gpio/consumer.h>
2222
#include <sound/core.h>
2323
#include <sound/pcm.h>
2424
#include <sound/pcm_params.h>
@@ -43,7 +43,10 @@ struct glb_pool {
4343
};
4444

4545
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+
4750

4851
static const char * const allo_piano_mode_texts[] = {
4952
"2.0",
@@ -387,7 +390,71 @@ static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
387390
return 0;
388391
}
389392

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,
391458
struct snd_pcm_hw_params *params)
392459
{
393460
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,
397464
unsigned int rate = params_rate(params);
398465
struct snd_soc_card *card = rtd->card;
399466
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+
}
401499

402500
if (digital_gain_0db_limit) {
403501
ret = snd_soc_limit_volume(card,
@@ -416,9 +514,21 @@ static int snd_allo_piano_dac_hw_params(struct snd_pcm_substream *substream,
416514
return ret;
417515
}
418516

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+
419527
/* machine stream operations */
420528
static struct snd_soc_ops snd_allo_piano_dac_ops = {
529+
.startup = snd_allo_piano_dac_startup,
421530
.hw_params = snd_allo_piano_dac_hw_params,
531+
.prepare = snd_allo_piano_dac_prepare,
422532
};
423533

424534
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)
483593
!of_property_read_bool(pdev->dev.of_node,
484594
"allo,24db_digital_gain");
485595

596+
glb_mclk = of_property_read_bool(pdev->dev.of_node,
597+
"allo,glb_mclk");
598+
486599
allo_piano_2_1_codecs[0].of_node =
487600
of_parse_phandle(pdev->dev.of_node, "audio-codec", 0);
488601
if (!allo_piano_2_1_codecs[0].of_node) {
@@ -498,22 +611,51 @@ static int snd_allo_piano_dac_probe(struct platform_device *pdev)
498611
"Property 'audio-codec' missing or invalid\n");
499612
return -EINVAL;
500613
}
501-
}
502614

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+
}
507623

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;
509651
}
510652

511653
static int snd_allo_piano_dac_remove(struct platform_device *pdev)
512654
{
513655
struct snd_soc_card *card = platform_get_drvdata(pdev);
514656

515657
kfree(&card->drvdata);
516-
658+
snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
517659
return snd_soc_unregister_card(&snd_allo_piano_dac);
518660
}
519661

0 commit comments

Comments
 (0)