1 From df85dac9b4a0855ba40c14fdf7ba93b33fd1db35 Mon Sep 17 00:00:00 2001
2 From: paul-1 <6473457+paul-1@users.noreply.github.com>
3 Date: Fri, 2 Apr 2021 10:56:19 -0400
4 Subject: [PATCH] Update Allo Piano Dac Driver
6 Add unique names to the individual dac coded drivers
7 Remove some of the codec controls that are not used.
9 Signed-off-by: Paul Hermann <paul@picoreplayer.org>
12 # sound/soc/bcm/allo-piano-dac-plus.c
14 sound/soc/bcm/allo-piano-dac-plus.c | 152 +++++++++++++++++++++-------
15 1 file changed, 114 insertions(+), 38 deletions(-)
17 --- a/sound/soc/bcm/allo-piano-dac-plus.c
18 +++ b/sound/soc/bcm/allo-piano-dac-plus.c
20 * ALSA ASoC Machine Driver for Allo Piano DAC Plus Subwoofer
22 * Author: Baswaraj K <jaikumar@cem-solutions.net>
25 + * based on code by David Knell <david.knell@gmail.com)
26 * based on code by Daniel Matuschek <info@crazy-audio.com>
27 * based on code by Florian Meier <florian.meier@koalo.de>
29 @@ -276,8 +277,15 @@ static int snd_allo_piano_dual_mode_put(
30 PCM512x_DIGITAL_VOLUME_2, 0xff);
32 list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
33 - if (!strncmp(kctl->id.name, "Digital Playback Volume",
34 - sizeof(kctl->id.name))) {
35 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
36 + sizeof(kctl->id.name))) {
37 + mc = (struct soc_mixer_control *)
38 + kctl->private_value;
42 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
43 + sizeof(kctl->id.name))) {
44 mc = (struct soc_mixer_control *)
47 @@ -291,13 +299,20 @@ static int snd_allo_piano_dual_mode_put(
48 PCM512x_DIGITAL_VOLUME_3);
50 list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
51 - if (!strncmp(kctl->id.name, "Digital Playback Volume",
52 - sizeof(kctl->id.name))) {
53 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
54 + sizeof(kctl->id.name))) {
55 mc = (struct soc_mixer_control *)
57 mc->rreg = PCM512x_DIGITAL_VOLUME_3;
60 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
61 + sizeof(kctl->id.name))) {
62 + mc = (struct soc_mixer_control *)
63 + kctl->private_value;
64 + mc->rreg = PCM512x_DIGITAL_VOLUME_2;
69 snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
70 @@ -344,13 +359,20 @@ static int snd_allo_piano_mode_put(struc
71 PCM512x_DIGITAL_VOLUME_2);
73 list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
74 - if (!strncmp(kctl->id.name, "Digital Playback Volume",
75 - sizeof(kctl->id.name))) {
76 + if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
77 + sizeof(kctl->id.name))) {
78 mc = (struct soc_mixer_control *)
80 mc->rreg = PCM512x_DIGITAL_VOLUME_3;
83 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
84 + sizeof(kctl->id.name))) {
85 + mc = (struct soc_mixer_control *)
86 + kctl->private_value;
87 + mc->rreg = PCM512x_DIGITAL_VOLUME_2;
91 snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
92 PCM512x_DIGITAL_VOLUME_3, left_val);
93 @@ -397,6 +419,7 @@ static int pcm512x_get_reg_sub(struct sn
94 unsigned int left_val = 0;
95 unsigned int right_val = 0;
96 rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
98 right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
99 PCM512x_DIGITAL_VOLUME_3);
100 if (glb_ptr->dual_mode != 1) {
101 @@ -428,12 +451,6 @@ static int pcm512x_set_reg_sub(struct sn
104 rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
105 - if (glb_ptr->dual_mode != 1) {
106 - ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
107 - PCM512x_DIGITAL_VOLUME_2, (~left_val));
112 if (digital_gain_0db_limit) {
113 ret = snd_soc_limit_volume(card, "Subwoofer Playback Volume",
114 @@ -443,10 +460,20 @@ static int pcm512x_set_reg_sub(struct sn
118 - ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
119 - PCM512x_DIGITAL_VOLUME_3, (~right_val));
122 + // When in Dual Mono, Sub vol control should not set anything.
123 + if (glb_ptr->dual_mode != 1) { //Not in Dual Mono mode
125 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
126 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
130 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
131 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
139 @@ -505,7 +532,7 @@ static int pcm512x_get_reg_master(struct
140 left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
141 PCM512x_DIGITAL_VOLUME_2);
143 - if (glb_ptr->dual_mode == 1) {
144 + if (glb_ptr->dual_mode == 1) { // in Dual Mono mode
145 right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
146 PCM512x_DIGITAL_VOLUME_3);
148 @@ -543,8 +570,21 @@ static int pcm512x_set_reg_master(struct
152 - if (glb_ptr->dual_mode != 1) {
153 + if (glb_ptr->dual_mode == 1) { //in Dual Mono Mode
155 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
156 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
160 ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
161 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
167 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
168 PCM512x_DIGITAL_VOLUME_2, (~left_val));
171 @@ -555,16 +595,6 @@ static int pcm512x_set_reg_master(struct
176 - ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
177 - PCM512x_DIGITAL_VOLUME_3, (~right_val));
181 - ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
182 - PCM512x_DIGITAL_VOLUME_2, (~left_val));
188 @@ -680,10 +710,32 @@ static const struct snd_kcontrol_new all
189 pcm512x_set_reg_master_switch),
192 +static const char * const codec_ctl_pfx[] = { "Main", "Sub" };
193 +static const char * const codec_ctl_name[] = {
194 + "Digital Playback Volume",
195 + "Digital Playback Switch",
196 + "Auto Mute Mono Switch",
197 + "Auto Mute Switch",
198 + "Auto Mute Time Left",
199 + "Auto Mute Time Right",
200 + "Clock Missing Period",
201 + "Max Overclock DAC",
202 + "Max Overclock DSP",
203 + "Max Overclock PLL",
204 + "Volume Ramp Down Emergency Rate",
205 + "Volume Ramp Down Emergency Step",
206 + "Volume Ramp Up Rate",
207 + "Volume Ramp Down Rate",
208 + "Volume Ramp Up Step",
209 + "Volume Ramp Down Step"
212 static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
214 struct snd_soc_card *card = rtd->card;
215 struct glb_pool *glb_ptr;
216 + struct snd_kcontrol *kctl;
219 glb_ptr = kzalloc(sizeof(struct glb_pool), GFP_KERNEL);
221 @@ -698,12 +750,36 @@ static int snd_allo_piano_dac_init(struc
222 if (digital_gain_0db_limit) {
225 - ret = snd_soc_limit_volume(card, "Digital Playback Volume",
228 - dev_warn(card->dev, "Failed to set volume limit: %d\n",
230 + //Set volume limit on both dacs
231 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
234 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[0]);
235 + ret = snd_soc_limit_volume(card, cname, 207);
237 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
242 + // Remove codec controls
243 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
244 + for (j = 0; j < ARRAY_SIZE(codec_ctl_name); j++) {
247 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[j]);
248 + kctl = snd_soc_card_get_kcontrol(card, cname);
250 + dev_err(rtd->card->dev, "Control %s not found\n",
253 + kctl->vd[0].access =
254 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
255 + snd_ctl_remove(card->snd_card, kctl);
263 @@ -842,10 +918,10 @@ static struct snd_soc_dai_link_component
266 SND_SOC_DAILINK_DEFS(allo_piano_dai_plus,
267 - DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
268 - DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "pcm512x-hifi"),
269 - COMP_CODEC(NULL, "pcm512x-hifi")),
270 - DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
271 + DAILINK_COMP_ARRAY(COMP_EMPTY()),
272 + DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi"),
273 + COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
274 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
276 static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {