1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
From df85dac9b4a0855ba40c14fdf7ba93b33fd1db35 Mon Sep 17 00:00:00 2001
From: paul-1 <6473457+paul-1@users.noreply.github.com>
Date: Fri, 2 Apr 2021 10:56:19 -0400
Subject: [PATCH] Update Allo Piano Dac Driver
Add unique names to the individual dac coded drivers
Remove some of the codec controls that are not used.
Signed-off-by: Paul Hermann <paul@picoreplayer.org>
# Conflicts:
# sound/soc/bcm/allo-piano-dac-plus.c
---
sound/soc/bcm/allo-piano-dac-plus.c | 152 +++++++++++++++++++++-------
1 file changed, 114 insertions(+), 38 deletions(-)
--- a/sound/soc/bcm/allo-piano-dac-plus.c
+++ b/sound/soc/bcm/allo-piano-dac-plus.c
@@ -2,7 +2,8 @@
* ALSA ASoC Machine Driver for Allo Piano DAC Plus Subwoofer
*
* Author: Baswaraj K <jaikumar@cem-solutions.net>
- * Copyright 2016
+ * Copyright 2020
+ * based on code by David Knell <david.knell@gmail.com)
* based on code by Daniel Matuschek <info@crazy-audio.com>
* based on code by Florian Meier <florian.meier@koalo.de>
*
@@ -276,8 +277,15 @@ static int snd_allo_piano_dual_mode_put(
PCM512x_DIGITAL_VOLUME_2, 0xff);
list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
- if (!strncmp(kctl->id.name, "Digital Playback Volume",
- sizeof(kctl->id.name))) {
+ if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
+ sizeof(kctl->id.name))) {
+ mc = (struct soc_mixer_control *)
+ kctl->private_value;
+ mc->rreg = mc->reg;
+ break;
+ }
+ if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
+ sizeof(kctl->id.name))) {
mc = (struct soc_mixer_control *)
kctl->private_value;
mc->rreg = mc->reg;
@@ -291,13 +299,20 @@ static int snd_allo_piano_dual_mode_put(
PCM512x_DIGITAL_VOLUME_3);
list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
- if (!strncmp(kctl->id.name, "Digital Playback Volume",
- sizeof(kctl->id.name))) {
+ if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
+ sizeof(kctl->id.name))) {
mc = (struct soc_mixer_control *)
kctl->private_value;
mc->rreg = PCM512x_DIGITAL_VOLUME_3;
break;
}
+ if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
+ sizeof(kctl->id.name))) {
+ mc = (struct soc_mixer_control *)
+ kctl->private_value;
+ mc->rreg = PCM512x_DIGITAL_VOLUME_2;
+ break;
+ }
}
snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
@@ -344,13 +359,20 @@ static int snd_allo_piano_mode_put(struc
PCM512x_DIGITAL_VOLUME_2);
list_for_each_entry(kctl, &snd_card_ptr->controls, list) {
- if (!strncmp(kctl->id.name, "Digital Playback Volume",
- sizeof(kctl->id.name))) {
+ if (!strncmp(kctl->id.name, "Main Digital Playback Volume",
+ sizeof(kctl->id.name))) {
mc = (struct soc_mixer_control *)
kctl->private_value;
mc->rreg = PCM512x_DIGITAL_VOLUME_3;
break;
}
+ if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
+ sizeof(kctl->id.name))) {
+ mc = (struct soc_mixer_control *)
+ kctl->private_value;
+ mc->rreg = PCM512x_DIGITAL_VOLUME_2;
+ break;
+ }
}
snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
PCM512x_DIGITAL_VOLUME_3, left_val);
@@ -397,6 +419,7 @@ static int pcm512x_get_reg_sub(struct sn
unsigned int left_val = 0;
unsigned int right_val = 0;
rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
+
right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
PCM512x_DIGITAL_VOLUME_3);
if (glb_ptr->dual_mode != 1) {
@@ -428,12 +451,6 @@ static int pcm512x_set_reg_sub(struct sn
int ret = 0;
rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
- if (glb_ptr->dual_mode != 1) {
- ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
- PCM512x_DIGITAL_VOLUME_2, (~left_val));
- if (ret < 0)
- return ret;
- }
if (digital_gain_0db_limit) {
ret = snd_soc_limit_volume(card, "Subwoofer Playback Volume",
@@ -443,10 +460,20 @@ static int pcm512x_set_reg_sub(struct sn
ret);
}
- ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
- PCM512x_DIGITAL_VOLUME_3, (~right_val));
- if (ret < 0)
- return ret;
+ // When in Dual Mono, Sub vol control should not set anything.
+ if (glb_ptr->dual_mode != 1) { //Not in Dual Mono mode
+
+ ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
+ PCM512x_DIGITAL_VOLUME_2, (~left_val));
+ if (ret < 0)
+ return ret;
+
+ ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
+ PCM512x_DIGITAL_VOLUME_3, (~right_val));
+ if (ret < 0)
+ return ret;
+
+ }
return 1;
}
@@ -505,7 +532,7 @@ static int pcm512x_get_reg_master(struct
left_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 0)->component,
PCM512x_DIGITAL_VOLUME_2);
- if (glb_ptr->dual_mode == 1) {
+ if (glb_ptr->dual_mode == 1) { // in Dual Mono mode
right_val = snd_soc_component_read(asoc_rtd_to_codec(rtd, 1)->component,
PCM512x_DIGITAL_VOLUME_3);
} else {
@@ -543,8 +570,21 @@ static int pcm512x_set_reg_master(struct
ret);
}
- if (glb_ptr->dual_mode != 1) {
+ if (glb_ptr->dual_mode == 1) { //in Dual Mono Mode
+
+ ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
+ PCM512x_DIGITAL_VOLUME_2, (~left_val));
+ if (ret < 0)
+ return ret;
+
ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
+ PCM512x_DIGITAL_VOLUME_3, (~right_val));
+ if (ret < 0)
+ return ret;
+
+ } else {
+
+ ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
PCM512x_DIGITAL_VOLUME_2, (~left_val));
if (ret < 0)
return ret;
@@ -555,16 +595,6 @@ static int pcm512x_set_reg_master(struct
return ret;
}
-
- ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
- PCM512x_DIGITAL_VOLUME_3, (~right_val));
- if (ret < 0)
- return ret;
-
- ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
- PCM512x_DIGITAL_VOLUME_2, (~left_val));
- if (ret < 0)
- return ret;
return 1;
}
@@ -680,10 +710,32 @@ static const struct snd_kcontrol_new all
pcm512x_set_reg_master_switch),
};
+static const char * const codec_ctl_pfx[] = { "Main", "Sub" };
+static const char * const codec_ctl_name[] = {
+ "Digital Playback Volume",
+ "Digital Playback Switch",
+ "Auto Mute Mono Switch",
+ "Auto Mute Switch",
+ "Auto Mute Time Left",
+ "Auto Mute Time Right",
+ "Clock Missing Period",
+ "Max Overclock DAC",
+ "Max Overclock DSP",
+ "Max Overclock PLL",
+ "Volume Ramp Down Emergency Rate",
+ "Volume Ramp Down Emergency Step",
+ "Volume Ramp Up Rate",
+ "Volume Ramp Down Rate",
+ "Volume Ramp Up Step",
+ "Volume Ramp Down Step"
+};
+
static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_card *card = rtd->card;
struct glb_pool *glb_ptr;
+ struct snd_kcontrol *kctl;
+ int i, j;
glb_ptr = kzalloc(sizeof(struct glb_pool), GFP_KERNEL);
if (!glb_ptr)
@@ -698,12 +750,36 @@ static int snd_allo_piano_dac_init(struc
if (digital_gain_0db_limit) {
int ret;
- ret = snd_soc_limit_volume(card, "Digital Playback Volume",
- 207);
- if (ret < 0)
- dev_warn(card->dev, "Failed to set volume limit: %d\n",
- ret);
+ //Set volume limit on both dacs
+ for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
+ char cname[256];
+
+ sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[0]);
+ ret = snd_soc_limit_volume(card, cname, 207);
+ if (ret < 0)
+ dev_warn(card->dev, "Failed to set volume limit: %d\n",
+ ret);
+ }
+ }
+
+ // Remove codec controls
+ for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
+ for (j = 0; j < ARRAY_SIZE(codec_ctl_name); j++) {
+ char cname[256];
+
+ sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[j]);
+ kctl = snd_soc_card_get_kcontrol(card, cname);
+ if (!kctl) {
+ dev_err(rtd->card->dev, "Control %s not found\n",
+ cname);
+ } else {
+ kctl->vd[0].access =
+ SNDRV_CTL_ELEM_ACCESS_READWRITE;
+ snd_ctl_remove(card->snd_card, kctl);
+ }
+ }
}
+
return 0;
}
@@ -842,10 +918,10 @@ static struct snd_soc_dai_link_component
};
SND_SOC_DAILINK_DEFS(allo_piano_dai_plus,
- DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
- DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "pcm512x-hifi"),
- COMP_CODEC(NULL, "pcm512x-hifi")),
- DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
+ DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004c", "pcm512x-hifi"),
+ COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi")),
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
{
|