bcm27xx: switch to 5.15
[openwrt/staging/noltari.git] / target / linux / bcm27xx / patches-5.10 / 950-0526-Update-Allo-Piano-Dac-Driver.patch
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
5
6 Add unique names to the individual dac coded drivers
7 Remove some of the codec controls that are not used.
8
9 Signed-off-by: Paul Hermann <paul@picoreplayer.org>
10
11 # Conflicts:
12 # sound/soc/bcm/allo-piano-dac-plus.c
13 ---
14 sound/soc/bcm/allo-piano-dac-plus.c | 152 +++++++++++++++++++++-------
15 1 file changed, 114 insertions(+), 38 deletions(-)
16
17 --- a/sound/soc/bcm/allo-piano-dac-plus.c
18 +++ b/sound/soc/bcm/allo-piano-dac-plus.c
19 @@ -2,7 +2,8 @@
20 * ALSA ASoC Machine Driver for Allo Piano DAC Plus Subwoofer
21 *
22 * Author: Baswaraj K <jaikumar@cem-solutions.net>
23 - * Copyright 2016
24 + * Copyright 2020
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>
28 *
29 @@ -276,8 +277,15 @@ static int snd_allo_piano_dual_mode_put(
30 PCM512x_DIGITAL_VOLUME_2, 0xff);
31
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;
39 + mc->rreg = mc->reg;
40 + break;
41 + }
42 + if (!strncmp(kctl->id.name, "Sub Digital Playback Volume",
43 + sizeof(kctl->id.name))) {
44 mc = (struct soc_mixer_control *)
45 kctl->private_value;
46 mc->rreg = mc->reg;
47 @@ -291,13 +299,20 @@ static int snd_allo_piano_dual_mode_put(
48 PCM512x_DIGITAL_VOLUME_3);
49
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 *)
56 kctl->private_value;
57 mc->rreg = PCM512x_DIGITAL_VOLUME_3;
58 break;
59 }
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;
65 + break;
66 + }
67 }
68
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);
72
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 *)
79 kctl->private_value;
80 mc->rreg = PCM512x_DIGITAL_VOLUME_3;
81 break;
82 }
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;
88 + break;
89 + }
90 }
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]);
97 +
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
102 int ret = 0;
103
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));
108 - if (ret < 0)
109 - return ret;
110 - }
111
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
115 ret);
116 }
117
118 - ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
119 - PCM512x_DIGITAL_VOLUME_3, (~right_val));
120 - if (ret < 0)
121 - return ret;
122 + // When in Dual Mono, Sub vol control should not set anything.
123 + if (glb_ptr->dual_mode != 1) { //Not in Dual Mono mode
124 +
125 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
126 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
127 + if (ret < 0)
128 + return ret;
129 +
130 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
131 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
132 + if (ret < 0)
133 + return ret;
134 +
135 + }
136
137 return 1;
138 }
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);
142
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);
147 } else {
148 @@ -543,8 +570,21 @@ static int pcm512x_set_reg_master(struct
149 ret);
150 }
151
152 - if (glb_ptr->dual_mode != 1) {
153 + if (glb_ptr->dual_mode == 1) { //in Dual Mono Mode
154 +
155 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
156 + PCM512x_DIGITAL_VOLUME_2, (~left_val));
157 + if (ret < 0)
158 + return ret;
159 +
160 ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
161 + PCM512x_DIGITAL_VOLUME_3, (~right_val));
162 + if (ret < 0)
163 + return ret;
164 +
165 + } else {
166 +
167 + ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
168 PCM512x_DIGITAL_VOLUME_2, (~left_val));
169 if (ret < 0)
170 return ret;
171 @@ -555,16 +595,6 @@ static int pcm512x_set_reg_master(struct
172 return ret;
173
174 }
175 -
176 - ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 1)->component,
177 - PCM512x_DIGITAL_VOLUME_3, (~right_val));
178 - if (ret < 0)
179 - return ret;
180 -
181 - ret = snd_soc_component_write(asoc_rtd_to_codec(rtd, 0)->component,
182 - PCM512x_DIGITAL_VOLUME_2, (~left_val));
183 - if (ret < 0)
184 - return ret;
185 return 1;
186 }
187
188 @@ -680,10 +710,32 @@ static const struct snd_kcontrol_new all
189 pcm512x_set_reg_master_switch),
190 };
191
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"
210 +};
211 +
212 static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
213 {
214 struct snd_soc_card *card = rtd->card;
215 struct glb_pool *glb_ptr;
216 + struct snd_kcontrol *kctl;
217 + int i, j;
218
219 glb_ptr = kzalloc(sizeof(struct glb_pool), GFP_KERNEL);
220 if (!glb_ptr)
221 @@ -698,12 +750,36 @@ static int snd_allo_piano_dac_init(struc
222 if (digital_gain_0db_limit) {
223 int ret;
224
225 - ret = snd_soc_limit_volume(card, "Digital Playback Volume",
226 - 207);
227 - if (ret < 0)
228 - dev_warn(card->dev, "Failed to set volume limit: %d\n",
229 - ret);
230 + //Set volume limit on both dacs
231 + for (i = 0; i < ARRAY_SIZE(codec_ctl_pfx); i++) {
232 + char cname[256];
233 +
234 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[0]);
235 + ret = snd_soc_limit_volume(card, cname, 207);
236 + if (ret < 0)
237 + dev_warn(card->dev, "Failed to set volume limit: %d\n",
238 + ret);
239 + }
240 + }
241 +
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++) {
245 + char cname[256];
246 +
247 + sprintf(cname, "%s %s", codec_ctl_pfx[i], codec_ctl_name[j]);
248 + kctl = snd_soc_card_get_kcontrol(card, cname);
249 + if (!kctl) {
250 + dev_err(rtd->card->dev, "Control %s not found\n",
251 + cname);
252 + } else {
253 + kctl->vd[0].access =
254 + SNDRV_CTL_ELEM_ACCESS_READWRITE;
255 + snd_ctl_remove(card->snd_card, kctl);
256 + }
257 + }
258 }
259 +
260 return 0;
261 }
262
263 @@ -842,10 +918,10 @@ static struct snd_soc_dai_link_component
264 };
265
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()));
275
276 static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
277 {