1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ASoC Driver for Infineon Merus(TM) ma120x0p multi-level class-D amplifier
5 * Authors: Ariel Muszkat <ariel.muszkat@gmail.com>
6 * Jorgen Kragh Jakobsen <jorgen.kraghjakobsen@infineon.com>
8 * Copyright (C) 2019 Infineon Technologies AG
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/init.h>
14 #include <linux/delay.h>
15 #include <linux/pm_runtime.h>
16 #include <linux/i2c.h>
17 #include <linux/of_device.h>
18 #include <linux/spi/spi.h>
19 #include <linux/regmap.h>
20 #include <linux/regulator/consumer.h>
21 #include <linux/slab.h>
22 #include <linux/gpio/consumer.h>
23 #include <linux/gpio.h>
24 #include <sound/core.h>
25 #include <sound/pcm.h>
26 #include <sound/pcm_params.h>
27 #include <sound/soc.h>
28 #include <sound/soc-dapm.h>
29 #include <sound/initval.h>
30 #include <sound/tlv.h>
31 #include <linux/interrupt.h>
33 #include <linux/kernel.h>
34 #include <linux/string.h>
36 #include <linux/uaccess.h>
40 //------------------------------------------------------------------manualPM---
41 // Select Manual PowerMode control
42 #define ma_manualpm__a 0
43 #define ma_manualpm__len 1
44 #define ma_manualpm__mask 0x40
45 #define ma_manualpm__shift 0x06
46 #define ma_manualpm__reset 0x00
47 //--------------------------------------------------------------------pm_man---
48 // manual selected power mode
49 #define ma_pm_man__a 0
50 #define ma_pm_man__len 2
51 #define ma_pm_man__mask 0x30
52 #define ma_pm_man__shift 0x04
53 #define ma_pm_man__reset 0x03
54 //------------------------------------------ ----------------------mthr_1to2---
55 // mod. index threshold value for pm1=>pm2 change.
56 #define ma_mthr_1to2__a 1
57 #define ma_mthr_1to2__len 8
58 #define ma_mthr_1to2__mask 0xff
59 #define ma_mthr_1to2__shift 0x00
60 #define ma_mthr_1to2__reset 0x3c
61 //-----------------------------------------------------------------mthr_2to1---
62 // mod. index threshold value for pm2=>pm1 change.
63 #define ma_mthr_2to1__a 2
64 #define ma_mthr_2to1__len 8
65 #define ma_mthr_2to1__mask 0xff
66 #define ma_mthr_2to1__shift 0x00
67 #define ma_mthr_2to1__reset 0x32
68 //-----------------------------------------------------------------mthr_2to3---
69 // mod. index threshold value for pm2=>pm3 change.
70 #define ma_mthr_2to3__a 3
71 #define ma_mthr_2to3__len 8
72 #define ma_mthr_2to3__mask 0xff
73 #define ma_mthr_2to3__shift 0x00
74 #define ma_mthr_2to3__reset 0x5a
75 //-----------------------------------------------------------------mthr_3to2---
76 // mod. index threshold value for pm3=>pm2 change.
77 #define ma_mthr_3to2__a 4
78 #define ma_mthr_3to2__len 8
79 #define ma_mthr_3to2__mask 0xff
80 #define ma_mthr_3to2__shift 0x00
81 #define ma_mthr_3to2__reset 0x50
82 //-------------------------------------------------------------pwmclkdiv_nom---
83 // pwm default clock divider value
84 #define ma_pwmclkdiv_nom__a 8
85 #define ma_pwmclkdiv_nom__len 8
86 #define ma_pwmclkdiv_nom__mask 0xff
87 #define ma_pwmclkdiv_nom__shift 0x00
88 #define ma_pwmclkdiv_nom__reset 0x26
89 //--------- ----------------------------------------------------ocp_latch_en---
90 // high to use permanently latching level-2 ocp
91 #define ma_ocp_latch_en__a 10
92 #define ma_ocp_latch_en__len 1
93 #define ma_ocp_latch_en__mask 0x02
94 #define ma_ocp_latch_en__shift 0x01
95 #define ma_ocp_latch_en__reset 0x00
96 //---------------------------------------------------------------lf_clamp_en---
97 // high (default) to enable lf int2+3 clamping on clip
98 #define ma_lf_clamp_en__a 10
99 #define ma_lf_clamp_en__len 1
100 #define ma_lf_clamp_en__mask 0x80
101 #define ma_lf_clamp_en__shift 0x07
102 #define ma_lf_clamp_en__reset 0x00
103 //-------------------------------------------------------pmcfg_btl_b.modtype---
105 #define ma_pmcfg_btl_b__modtype__a 18
106 #define ma_pmcfg_btl_b__modtype__len 2
107 #define ma_pmcfg_btl_b__modtype__mask 0x18
108 #define ma_pmcfg_btl_b__modtype__shift 0x03
109 #define ma_pmcfg_btl_b__modtype__reset 0x02
110 //-------------------------------------------------------pmcfg_btl_b.freqdiv---
111 #define ma_pmcfg_btl_b__freqdiv__a 18
112 #define ma_pmcfg_btl_b__freqdiv__len 2
113 #define ma_pmcfg_btl_b__freqdiv__mask 0x06
114 #define ma_pmcfg_btl_b__freqdiv__shift 0x01
115 #define ma_pmcfg_btl_b__freqdiv__reset 0x01
116 //----------------------------------------------------pmcfg_btl_b.lf_gain_ol---
118 #define ma_pmcfg_btl_b__lf_gain_ol__a 18
119 #define ma_pmcfg_btl_b__lf_gain_ol__len 1
120 #define ma_pmcfg_btl_b__lf_gain_ol__mask 0x01
121 #define ma_pmcfg_btl_b__lf_gain_ol__shift 0x00
122 #define ma_pmcfg_btl_b__lf_gain_ol__reset 0x01
123 //-------------------------------------------------------pmcfg_btl_c.freqdiv---
125 #define ma_pmcfg_btl_c__freqdiv__a 19
126 #define ma_pmcfg_btl_c__freqdiv__len 2
127 #define ma_pmcfg_btl_c__freqdiv__mask 0x06
128 #define ma_pmcfg_btl_c__freqdiv__shift 0x01
129 #define ma_pmcfg_btl_c__freqdiv__reset 0x01
130 //-------------------------------------------------------pmcfg_btl_c.modtype---
132 #define ma_pmcfg_btl_c__modtype__a 19
133 #define ma_pmcfg_btl_c__modtype__len 2
134 #define ma_pmcfg_btl_c__modtype__mask 0x18
135 #define ma_pmcfg_btl_c__modtype__shift 0x03
136 #define ma_pmcfg_btl_c__modtype__reset 0x01
137 //----------------------------------------------------pmcfg_btl_c.lf_gain_ol---
139 #define ma_pmcfg_btl_c__lf_gain_ol__a 19
140 #define ma_pmcfg_btl_c__lf_gain_ol__len 1
141 #define ma_pmcfg_btl_c__lf_gain_ol__mask 0x01
142 #define ma_pmcfg_btl_c__lf_gain_ol__shift 0x00
143 #define ma_pmcfg_btl_c__lf_gain_ol__reset 0x00
144 //-------------------------------------------------------pmcfg_btl_d.modtype---
146 #define ma_pmcfg_btl_d__modtype__a 20
147 #define ma_pmcfg_btl_d__modtype__len 2
148 #define ma_pmcfg_btl_d__modtype__mask 0x18
149 #define ma_pmcfg_btl_d__modtype__shift 0x03
150 #define ma_pmcfg_btl_d__modtype__reset 0x02
151 //-------------------------------------------------------pmcfg_btl_d.freqdiv---
153 #define ma_pmcfg_btl_d__freqdiv__a 20
154 #define ma_pmcfg_btl_d__freqdiv__len 2
155 #define ma_pmcfg_btl_d__freqdiv__mask 0x06
156 #define ma_pmcfg_btl_d__freqdiv__shift 0x01
157 #define ma_pmcfg_btl_d__freqdiv__reset 0x02
158 //----------------------------------------------------pmcfg_btl_d.lf_gain_ol---
160 #define ma_pmcfg_btl_d__lf_gain_ol__a 20
161 #define ma_pmcfg_btl_d__lf_gain_ol__len 1
162 #define ma_pmcfg_btl_d__lf_gain_ol__mask 0x01
163 #define ma_pmcfg_btl_d__lf_gain_ol__shift 0x00
164 #define ma_pmcfg_btl_d__lf_gain_ol__reset 0x00
165 //------------ -------------------------------------------pmcfg_se_a.modtype---
167 #define ma_pmcfg_se_a__modtype__a 21
168 #define ma_pmcfg_se_a__modtype__len 2
169 #define ma_pmcfg_se_a__modtype__mask 0x18
170 #define ma_pmcfg_se_a__modtype__shift 0x03
171 #define ma_pmcfg_se_a__modtype__reset 0x01
172 //--------------------------------------------------------pmcfg_se_a.freqdiv---
174 #define ma_pmcfg_se_a__freqdiv__a 21
175 #define ma_pmcfg_se_a__freqdiv__len 2
176 #define ma_pmcfg_se_a__freqdiv__mask 0x06
177 #define ma_pmcfg_se_a__freqdiv__shift 0x01
178 #define ma_pmcfg_se_a__freqdiv__reset 0x00
179 //-----------------------------------------------------pmcfg_se_a.lf_gain_ol---
181 #define ma_pmcfg_se_a__lf_gain_ol__a 21
182 #define ma_pmcfg_se_a__lf_gain_ol__len 1
183 #define ma_pmcfg_se_a__lf_gain_ol__mask 0x01
184 #define ma_pmcfg_se_a__lf_gain_ol__shift 0x00
185 #define ma_pmcfg_se_a__lf_gain_ol__reset 0x01
186 //-----------------------------------------------------pmcfg_se_b.lf_gain_ol---
188 #define ma_pmcfg_se_b__lf_gain_ol__a 22
189 #define ma_pmcfg_se_b__lf_gain_ol__len 1
190 #define ma_pmcfg_se_b__lf_gain_ol__mask 0x01
191 #define ma_pmcfg_se_b__lf_gain_ol__shift 0x00
192 #define ma_pmcfg_se_b__lf_gain_ol__reset 0x00
193 //--------------------------------------------------------pmcfg_se_b.freqdiv---
195 #define ma_pmcfg_se_b__freqdiv__a 22
196 #define ma_pmcfg_se_b__freqdiv__len 2
197 #define ma_pmcfg_se_b__freqdiv__mask 0x06
198 #define ma_pmcfg_se_b__freqdiv__shift 0x01
199 #define ma_pmcfg_se_b__freqdiv__reset 0x01
200 //--------------------------------------------------------pmcfg_se_b.modtype---
202 #define ma_pmcfg_se_b__modtype__a 22
203 #define ma_pmcfg_se_b__modtype__len 2
204 #define ma_pmcfg_se_b__modtype__mask 0x18
205 #define ma_pmcfg_se_b__modtype__shift 0x03
206 #define ma_pmcfg_se_b__modtype__reset 0x01
207 //----------------------------------------------------------balwaitcount_pm1---
208 // pm1 balancing period.
209 #define ma_balwaitcount_pm1__a 23
210 #define ma_balwaitcount_pm1__len 8
211 #define ma_balwaitcount_pm1__mask 0xff
212 #define ma_balwaitcount_pm1__shift 0x00
213 #define ma_balwaitcount_pm1__reset 0x14
214 //----------------------------------------------------------balwaitcount_pm2---
215 // pm2 balancing period.
216 #define ma_balwaitcount_pm2__a 24
217 #define ma_balwaitcount_pm2__len 8
218 #define ma_balwaitcount_pm2__mask 0xff
219 #define ma_balwaitcount_pm2__shift 0x00
220 #define ma_balwaitcount_pm2__reset 0x14
221 //----------------------------------------------------------balwaitcount_pm3---
222 // pm3 balancing period.
223 #define ma_balwaitcount_pm3__a 25
224 #define ma_balwaitcount_pm3__len 8
225 #define ma_balwaitcount_pm3__mask 0xff
226 #define ma_balwaitcount_pm3__shift 0x00
227 #define ma_balwaitcount_pm3__reset 0x1a
228 //-------------------------------------------------------------usespread_pm1---
229 // pm1 pwm spread-spectrum mode on/off.
230 #define ma_usespread_pm1__a 26
231 #define ma_usespread_pm1__len 1
232 #define ma_usespread_pm1__mask 0x40
233 #define ma_usespread_pm1__shift 0x06
234 #define ma_usespread_pm1__reset 0x00
235 //---------------------------------------------------------------dtsteps_pm1---
236 // pm1 dead time setting [10ns steps].
237 #define ma_dtsteps_pm1__a 26
238 #define ma_dtsteps_pm1__len 3
239 #define ma_dtsteps_pm1__mask 0x38
240 #define ma_dtsteps_pm1__shift 0x03
241 #define ma_dtsteps_pm1__reset 0x04
242 //---------------------------------------------------------------baltype_pm1---
243 // pm1 balancing sensor scheme.
244 #define ma_baltype_pm1__a 26
245 #define ma_baltype_pm1__len 3
246 #define ma_baltype_pm1__mask 0x07
247 #define ma_baltype_pm1__shift 0x00
248 #define ma_baltype_pm1__reset 0x00
249 //-------------------------------------------------------------usespread_pm2---
250 // pm2 pwm spread-spectrum mode on/off.
251 #define ma_usespread_pm2__a 27
252 #define ma_usespread_pm2__len 1
253 #define ma_usespread_pm2__mask 0x40
254 #define ma_usespread_pm2__shift 0x06
255 #define ma_usespread_pm2__reset 0x00
256 //---------------------------------------------------------------dtsteps_pm2---
257 // pm2 dead time setting [10ns steps].
258 #define ma_dtsteps_pm2__a 27
259 #define ma_dtsteps_pm2__len 3
260 #define ma_dtsteps_pm2__mask 0x38
261 #define ma_dtsteps_pm2__shift 0x03
262 #define ma_dtsteps_pm2__reset 0x03
263 //---------------------------------------------------------------baltype_pm2---
264 // pm2 balancing sensor scheme.
265 #define ma_baltype_pm2__a 27
266 #define ma_baltype_pm2__len 3
267 #define ma_baltype_pm2__mask 0x07
268 #define ma_baltype_pm2__shift 0x00
269 #define ma_baltype_pm2__reset 0x01
270 //-------------------------------------------------------------usespread_pm3---
271 // pm3 pwm spread-spectrum mode on/off.
272 #define ma_usespread_pm3__a 28
273 #define ma_usespread_pm3__len 1
274 #define ma_usespread_pm3__mask 0x40
275 #define ma_usespread_pm3__shift 0x06
276 #define ma_usespread_pm3__reset 0x00
277 //---------------------------------------------------------------dtsteps_pm3---
278 // pm3 dead time setting [10ns steps].
279 #define ma_dtsteps_pm3__a 28
280 #define ma_dtsteps_pm3__len 3
281 #define ma_dtsteps_pm3__mask 0x38
282 #define ma_dtsteps_pm3__shift 0x03
283 #define ma_dtsteps_pm3__reset 0x01
284 //---------------------------------------------------------------baltype_pm3---
285 // pm3 balancing sensor scheme.
286 #define ma_baltype_pm3__a 28
287 #define ma_baltype_pm3__len 3
288 #define ma_baltype_pm3__mask 0x07
289 #define ma_baltype_pm3__shift 0x00
290 #define ma_baltype_pm3__reset 0x03
291 //-----------------------------------------------------------------pmprofile---
292 // pm profile select. valid presets: 0-1-2-3-4. 5=> custom profile.
293 #define ma_pmprofile__a 29
294 #define ma_pmprofile__len 3
295 #define ma_pmprofile__mask 0x07
296 #define ma_pmprofile__shift 0x00
297 #define ma_pmprofile__reset 0x00
298 //-------------------------------------------------------------------pm3_man---
299 // custom profile pm3 contents. 0=>a, 1=>b, 2=>c, 3=>d
300 #define ma_pm3_man__a 30
301 #define ma_pm3_man__len 2
302 #define ma_pm3_man__mask 0x30
303 #define ma_pm3_man__shift 0x04
304 #define ma_pm3_man__reset 0x02
305 //-------------------------------------------------------------------pm2_man---
306 // custom profile pm2 contents. 0=>a, 1=>b, 2=>c, 3=>d
307 #define ma_pm2_man__a 30
308 #define ma_pm2_man__len 2
309 #define ma_pm2_man__mask 0x0c
310 #define ma_pm2_man__shift 0x02
311 #define ma_pm2_man__reset 0x03
312 //-------------------------------------------------------------------pm1_man---
313 // custom profile pm1 contents. 0=>a, 1=>b, 2=>c, 3=>d
314 #define ma_pm1_man__a 30
315 #define ma_pm1_man__len 2
316 #define ma_pm1_man__mask 0x03
317 #define ma_pm1_man__shift 0x00
318 #define ma_pm1_man__reset 0x03
319 //-----------------------------------------------------------ocp_latch_clear---
320 // low-high clears current ocp latched condition.
321 #define ma_ocp_latch_clear__a 32
322 #define ma_ocp_latch_clear__len 1
323 #define ma_ocp_latch_clear__mask 0x80
324 #define ma_ocp_latch_clear__shift 0x07
325 #define ma_ocp_latch_clear__reset 0x00
326 //-------------------------------------------------------------audio_in_mode---
327 // audio input mode; 0-1-2-3-4-5
328 #define ma_audio_in_mode__a 37
329 #define ma_audio_in_mode__len 3
330 #define ma_audio_in_mode__mask 0xe0
331 #define ma_audio_in_mode__shift 0x05
332 #define ma_audio_in_mode__reset 0x00
333 //-----------------------------------------------------------------eh_dcshdn---
334 // high to enable dc protection
335 #define ma_eh_dcshdn__a 38
336 #define ma_eh_dcshdn__len 1
337 #define ma_eh_dcshdn__mask 0x04
338 #define ma_eh_dcshdn__shift 0x02
339 #define ma_eh_dcshdn__reset 0x01
340 //---------------------------------------------------------audio_in_mode_ext---
341 // if set, audio_in_mode is controlled from audio_in_mode register. if not set
342 //audio_in_mode is set from fuse bank setting
343 #define ma_audio_in_mode_ext__a 39
344 #define ma_audio_in_mode_ext__len 1
345 #define ma_audio_in_mode_ext__mask 0x20
346 #define ma_audio_in_mode_ext__shift 0x05
347 #define ma_audio_in_mode_ext__reset 0x00
348 //------------------------------------------------------------------eh_clear---
349 // flip to clear error registers
350 #define ma_eh_clear__a 45
351 #define ma_eh_clear__len 1
352 #define ma_eh_clear__mask 0x04
353 #define ma_eh_clear__shift 0x02
354 #define ma_eh_clear__reset 0x00
355 //----------------------------------------------------------thermal_compr_en---
356 // enable otw-contr. input compression?
357 #define ma_thermal_compr_en__a 45
358 #define ma_thermal_compr_en__len 1
359 #define ma_thermal_compr_en__mask 0x20
360 #define ma_thermal_compr_en__shift 0x05
361 #define ma_thermal_compr_en__reset 0x01
362 //---------------------------------------------------------------system_mute---
363 // 1 = mute system, 0 = normal operation
364 #define ma_system_mute__a 45
365 #define ma_system_mute__len 1
366 #define ma_system_mute__mask 0x40
367 #define ma_system_mute__shift 0x06
368 #define ma_system_mute__reset 0x00
369 //------------------------------------------------------thermal_compr_max_db---
370 // audio limiter max thermal reduction
371 #define ma_thermal_compr_max_db__a 46
372 #define ma_thermal_compr_max_db__len 3
373 #define ma_thermal_compr_max_db__mask 0x07
374 #define ma_thermal_compr_max_db__shift 0x00
375 #define ma_thermal_compr_max_db__reset 0x04
376 //---------------------------------------------------------audio_proc_enable---
377 // enable audio proc, bypass if not enabled
378 #define ma_audio_proc_enable__a 53
379 #define ma_audio_proc_enable__len 1
380 #define ma_audio_proc_enable__mask 0x08
381 #define ma_audio_proc_enable__shift 0x03
382 #define ma_audio_proc_enable__reset 0x00
383 //--------------------------------------------------------audio_proc_release---
384 // 00:slow, 01:normal, 10:fast
385 #define ma_audio_proc_release__a 53
386 #define ma_audio_proc_release__len 2
387 #define ma_audio_proc_release__mask 0x30
388 #define ma_audio_proc_release__shift 0x04
389 #define ma_audio_proc_release__reset 0x00
390 //---------------------------------------------------------audio_proc_attack---
391 // 00:slow, 01:normal, 10:fast
392 #define ma_audio_proc_attack__a 53
393 #define ma_audio_proc_attack__len 2
394 #define ma_audio_proc_attack__mask 0xc0
395 #define ma_audio_proc_attack__shift 0x06
396 #define ma_audio_proc_attack__reset 0x00
397 //----------------------------------------------------------------i2s_format---
398 // i2s basic data format, 000 = std. i2s, 001 = left justified (default)
399 #define ma_i2s_format__a 53
400 #define ma_i2s_format__len 3
401 #define ma_i2s_format__mask 0x07
402 #define ma_i2s_format__shift 0x00
403 #define ma_i2s_format__reset 0x01
404 //--------------------------------------------------audio_proc_limiterenable---
405 // 1: enable limiter, 0: disable limiter
406 #define ma_audio_proc_limiterenable__a 54
407 #define ma_audio_proc_limiterenable__len 1
408 #define ma_audio_proc_limiterenable__mask 0x40
409 #define ma_audio_proc_limiterenable__shift 0x06
410 #define ma_audio_proc_limiterenable__reset 0x00
411 //-----------------------------------------------------------audio_proc_mute---
412 // 1: mute, 0: unmute
413 #define ma_audio_proc_mute__a 54
414 #define ma_audio_proc_mute__len 1
415 #define ma_audio_proc_mute__mask 0x80
416 #define ma_audio_proc_mute__shift 0x07
417 #define ma_audio_proc_mute__reset 0x00
418 //---------------------------------------------------------------i2s_sck_pol---
419 // i2s sck polarity cfg. 0 = rising edge data change
420 #define ma_i2s_sck_pol__a 54
421 #define ma_i2s_sck_pol__len 1
422 #define ma_i2s_sck_pol__mask 0x01
423 #define ma_i2s_sck_pol__shift 0x00
424 #define ma_i2s_sck_pol__reset 0x01
425 //-------------------------------------------------------------i2s_framesize---
426 // i2s word length. 00 = 32bit, 01 = 24bit
427 #define ma_i2s_framesize__a 54
428 #define ma_i2s_framesize__len 2
429 #define ma_i2s_framesize__mask 0x18
430 #define ma_i2s_framesize__shift 0x03
431 #define ma_i2s_framesize__reset 0x00
432 //----------------------------------------------------------------i2s_ws_pol---
433 // i2s ws polarity. 0 = low first
434 #define ma_i2s_ws_pol__a 54
435 #define ma_i2s_ws_pol__len 1
436 #define ma_i2s_ws_pol__mask 0x02
437 #define ma_i2s_ws_pol__shift 0x01
438 #define ma_i2s_ws_pol__reset 0x00
439 //-----------------------------------------------------------------i2s_order---
440 // i2s word bit order. 0 = msb first
441 #define ma_i2s_order__a 54
442 #define ma_i2s_order__len 1
443 #define ma_i2s_order__mask 0x04
444 #define ma_i2s_order__shift 0x02
445 #define ma_i2s_order__reset 0x00
446 //------------------------------------------------------------i2s_rightfirst---
447 // i2s l/r word order; 0 = left first
448 #define ma_i2s_rightfirst__a 54
449 #define ma_i2s_rightfirst__len 1
450 #define ma_i2s_rightfirst__mask 0x20
451 #define ma_i2s_rightfirst__shift 0x05
452 #define ma_i2s_rightfirst__reset 0x00
453 //-------------------------------------------------------------vol_db_master---
455 #define ma_vol_db_master__a 64
456 #define ma_vol_db_master__len 8
457 #define ma_vol_db_master__mask 0xff
458 #define ma_vol_db_master__shift 0x00
459 #define ma_vol_db_master__reset 0x18
460 //------------------------------------------------------------vol_lsb_master---
461 // master volume lsb 1/4 steps
462 #define ma_vol_lsb_master__a 65
463 #define ma_vol_lsb_master__len 2
464 #define ma_vol_lsb_master__mask 0x03
465 #define ma_vol_lsb_master__shift 0x00
466 #define ma_vol_lsb_master__reset 0x00
467 //----------------------------------------------------------------vol_db_ch0---
469 #define ma_vol_db_ch0__a 66
470 #define ma_vol_db_ch0__len 8
471 #define ma_vol_db_ch0__mask 0xff
472 #define ma_vol_db_ch0__shift 0x00
473 #define ma_vol_db_ch0__reset 0x18
474 //----------------------------------------------------------------vol_db_ch1---
476 #define ma_vol_db_ch1__a 67
477 #define ma_vol_db_ch1__len 8
478 #define ma_vol_db_ch1__mask 0xff
479 #define ma_vol_db_ch1__shift 0x00
480 #define ma_vol_db_ch1__reset 0x18
481 //----------------------------------------------------------------vol_db_ch2---
483 #define ma_vol_db_ch2__a 68
484 #define ma_vol_db_ch2__len 8
485 #define ma_vol_db_ch2__mask 0xff
486 #define ma_vol_db_ch2__shift 0x00
487 #define ma_vol_db_ch2__reset 0x18
488 //----------------------------------------------------------------vol_db_ch3---
490 #define ma_vol_db_ch3__a 69
491 #define ma_vol_db_ch3__len 8
492 #define ma_vol_db_ch3__mask 0xff
493 #define ma_vol_db_ch3__shift 0x00
494 #define ma_vol_db_ch3__reset 0x18
495 //---------------------------------------------------------------vol_lsb_ch0---
496 // volume channel 1 - 1/4 steps
497 #define ma_vol_lsb_ch0__a 70
498 #define ma_vol_lsb_ch0__len 2
499 #define ma_vol_lsb_ch0__mask 0x03
500 #define ma_vol_lsb_ch0__shift 0x00
501 #define ma_vol_lsb_ch0__reset 0x00
502 //---------------------------------------------------------------vol_lsb_ch1---
503 // volume channel 3 - 1/4 steps
504 #define ma_vol_lsb_ch1__a 70
505 #define ma_vol_lsb_ch1__len 2
506 #define ma_vol_lsb_ch1__mask 0x0c
507 #define ma_vol_lsb_ch1__shift 0x02
508 #define ma_vol_lsb_ch1__reset 0x00
509 //---------------------------------------------------------------vol_lsb_ch2---
510 // volume channel 2 - 1/4 steps
511 #define ma_vol_lsb_ch2__a 70
512 #define ma_vol_lsb_ch2__len 2
513 #define ma_vol_lsb_ch2__mask 0x30
514 #define ma_vol_lsb_ch2__shift 0x04
515 #define ma_vol_lsb_ch2__reset 0x00
516 //---------------------------------------------------------------vol_lsb_ch3---
517 // volume channel 3 - 1/4 steps
518 #define ma_vol_lsb_ch3__a 70
519 #define ma_vol_lsb_ch3__len 2
520 #define ma_vol_lsb_ch3__mask 0xc0
521 #define ma_vol_lsb_ch3__shift 0x06
522 #define ma_vol_lsb_ch3__reset 0x00
523 //----------------------------------------------------------------thr_db_ch0---
525 #define ma_thr_db_ch0__a 71
526 #define ma_thr_db_ch0__len 8
527 #define ma_thr_db_ch0__mask 0xff
528 #define ma_thr_db_ch0__shift 0x00
529 #define ma_thr_db_ch0__reset 0x18
530 //----------------------------------------------------------------thr_db_ch1---
532 #define ma_thr_db_ch1__a 72
533 #define ma_thr_db_ch1__len 8
534 #define ma_thr_db_ch1__mask 0xff
535 #define ma_thr_db_ch1__shift 0x00
536 #define ma_thr_db_ch1__reset 0x18
537 //----------------------------------------------------------------thr_db_ch2---
539 #define ma_thr_db_ch2__a 73
540 #define ma_thr_db_ch2__len 8
541 #define ma_thr_db_ch2__mask 0xff
542 #define ma_thr_db_ch2__shift 0x00
543 #define ma_thr_db_ch2__reset 0x18
544 //----------------------------------------------------------------thr_db_ch3---
546 #define ma_thr_db_ch3__a 74
547 #define ma_thr_db_ch3__len 8
548 #define ma_thr_db_ch3__mask 0xff
549 #define ma_thr_db_ch3__shift 0x00
550 #define ma_thr_db_ch3__reset 0x18
551 //---------------------------------------------------------------thr_lsb_ch0---
553 #define ma_thr_lsb_ch0__a 75
554 #define ma_thr_lsb_ch0__len 2
555 #define ma_thr_lsb_ch0__mask 0x03
556 #define ma_thr_lsb_ch0__shift 0x00
557 #define ma_thr_lsb_ch0__reset 0x00
558 //---------------------------------------------------------------thr_lsb_ch1---
560 #define ma_thr_lsb_ch1__a 75
561 #define ma_thr_lsb_ch1__len 2
562 #define ma_thr_lsb_ch1__mask 0x0c
563 #define ma_thr_lsb_ch1__shift 0x02
564 #define ma_thr_lsb_ch1__reset 0x00
565 //---------------------------------------------------------------thr_lsb_ch2---
566 // thr lsb ch2 1/4 db step
567 #define ma_thr_lsb_ch2__a 75
568 #define ma_thr_lsb_ch2__len 2
569 #define ma_thr_lsb_ch2__mask 0x30
570 #define ma_thr_lsb_ch2__shift 0x04
571 #define ma_thr_lsb_ch2__reset 0x00
572 //---------------------------------------------------------------thr_lsb_ch3---
574 #define ma_thr_lsb_ch3__a 75
575 #define ma_thr_lsb_ch3__len 2
576 #define ma_thr_lsb_ch3__mask 0xc0
577 #define ma_thr_lsb_ch3__shift 0x06
578 #define ma_thr_lsb_ch3__reset 0x00
579 //-----------------------------------------------------------dcu_mon0.pm_mon---
580 // power mode monitor channel 0
581 #define ma_dcu_mon0__pm_mon__a 96
582 #define ma_dcu_mon0__pm_mon__len 2
583 #define ma_dcu_mon0__pm_mon__mask 0x03
584 #define ma_dcu_mon0__pm_mon__shift 0x00
585 #define ma_dcu_mon0__pm_mon__reset 0x00
586 //-----------------------------------------------------dcu_mon0.freqmode_mon---
587 // frequence mode monitor channel 0
588 #define ma_dcu_mon0__freqmode_mon__a 96
589 #define ma_dcu_mon0__freqmode_mon__len 3
590 #define ma_dcu_mon0__freqmode_mon__mask 0x70
591 #define ma_dcu_mon0__freqmode_mon__shift 0x04
592 #define ma_dcu_mon0__freqmode_mon__reset 0x00
593 //-------------------------------------------------------dcu_mon0.pps_passed---
594 // dcu0 pps completion indicator
595 #define ma_dcu_mon0__pps_passed__a 96
596 #define ma_dcu_mon0__pps_passed__len 1
597 #define ma_dcu_mon0__pps_passed__mask 0x80
598 #define ma_dcu_mon0__pps_passed__shift 0x07
599 #define ma_dcu_mon0__pps_passed__reset 0x00
600 //----------------------------------------------------------dcu_mon0.ocp_mon---
601 // ocp monitor channel 0
602 #define ma_dcu_mon0__ocp_mon__a 97
603 #define ma_dcu_mon0__ocp_mon__len 1
604 #define ma_dcu_mon0__ocp_mon__mask 0x01
605 #define ma_dcu_mon0__ocp_mon__shift 0x00
606 #define ma_dcu_mon0__ocp_mon__reset 0x00
607 //--------------------------------------------------------dcu_mon0.vcfly1_ok---
608 // cfly1 protection monitor channel 0.
609 #define ma_dcu_mon0__vcfly1_ok__a 97
610 #define ma_dcu_mon0__vcfly1_ok__len 1
611 #define ma_dcu_mon0__vcfly1_ok__mask 0x02
612 #define ma_dcu_mon0__vcfly1_ok__shift 0x01
613 #define ma_dcu_mon0__vcfly1_ok__reset 0x00
614 //--------------------------------------------------------dcu_mon0.vcfly2_ok---
615 // cfly2 protection monitor channel 0.
616 #define ma_dcu_mon0__vcfly2_ok__a 97
617 #define ma_dcu_mon0__vcfly2_ok__len 1
618 #define ma_dcu_mon0__vcfly2_ok__mask 0x04
619 #define ma_dcu_mon0__vcfly2_ok__shift 0x02
620 #define ma_dcu_mon0__vcfly2_ok__reset 0x00
621 //----------------------------------------------------------dcu_mon0.pvdd_ok---
623 #define ma_dcu_mon0__pvdd_ok__a 97
624 #define ma_dcu_mon0__pvdd_ok__len 1
625 #define ma_dcu_mon0__pvdd_ok__mask 0x08
626 #define ma_dcu_mon0__pvdd_ok__shift 0x03
627 #define ma_dcu_mon0__pvdd_ok__reset 0x00
628 //-----------------------------------------------------------dcu_mon0.vdd_ok---
630 #define ma_dcu_mon0__vdd_ok__a 97
631 #define ma_dcu_mon0__vdd_ok__len 1
632 #define ma_dcu_mon0__vdd_ok__mask 0x10
633 #define ma_dcu_mon0__vdd_ok__shift 0x04
634 #define ma_dcu_mon0__vdd_ok__reset 0x00
635 //-------------------------------------------------------------dcu_mon0.mute---
637 #define ma_dcu_mon0__mute__a 97
638 #define ma_dcu_mon0__mute__len 1
639 #define ma_dcu_mon0__mute__mask 0x20
640 #define ma_dcu_mon0__mute__shift 0x05
641 #define ma_dcu_mon0__mute__reset 0x00
642 //------------------------------------------------------------dcu_mon0.m_mon---
643 // m sense monitor channel 0
644 #define ma_dcu_mon0__m_mon__a 98
645 #define ma_dcu_mon0__m_mon__len 8
646 #define ma_dcu_mon0__m_mon__mask 0xff
647 #define ma_dcu_mon0__m_mon__shift 0x00
648 #define ma_dcu_mon0__m_mon__reset 0x00
649 //-----------------------------------------------------------dcu_mon1.pm_mon---
650 // power mode monitor channel 1
651 #define ma_dcu_mon1__pm_mon__a 100
652 #define ma_dcu_mon1__pm_mon__len 2
653 #define ma_dcu_mon1__pm_mon__mask 0x03
654 #define ma_dcu_mon1__pm_mon__shift 0x00
655 #define ma_dcu_mon1__pm_mon__reset 0x00
656 //-----------------------------------------------------dcu_mon1.freqmode_mon---
657 // frequence mode monitor channel 1
658 #define ma_dcu_mon1__freqmode_mon__a 100
659 #define ma_dcu_mon1__freqmode_mon__len 3
660 #define ma_dcu_mon1__freqmode_mon__mask 0x70
661 #define ma_dcu_mon1__freqmode_mon__shift 0x04
662 #define ma_dcu_mon1__freqmode_mon__reset 0x00
663 //-------------------------------------------------------dcu_mon1.pps_passed---
664 // dcu1 pps completion indicator
665 #define ma_dcu_mon1__pps_passed__a 100
666 #define ma_dcu_mon1__pps_passed__len 1
667 #define ma_dcu_mon1__pps_passed__mask 0x80
668 #define ma_dcu_mon1__pps_passed__shift 0x07
669 #define ma_dcu_mon1__pps_passed__reset 0x00
670 //----------------------------------------------------------dcu_mon1.ocp_mon---
671 // ocp monitor channel 1
672 #define ma_dcu_mon1__ocp_mon__a 101
673 #define ma_dcu_mon1__ocp_mon__len 1
674 #define ma_dcu_mon1__ocp_mon__mask 0x01
675 #define ma_dcu_mon1__ocp_mon__shift 0x00
676 #define ma_dcu_mon1__ocp_mon__reset 0x00
677 //--------------------------------------------------------dcu_mon1.vcfly1_ok---
678 // cfly1 protcetion monitor channel 1
679 #define ma_dcu_mon1__vcfly1_ok__a 101
680 #define ma_dcu_mon1__vcfly1_ok__len 1
681 #define ma_dcu_mon1__vcfly1_ok__mask 0x02
682 #define ma_dcu_mon1__vcfly1_ok__shift 0x01
683 #define ma_dcu_mon1__vcfly1_ok__reset 0x00
684 //--------------------------------------------------------dcu_mon1.vcfly2_ok---
685 // cfly2 protection monitor channel 1
686 #define ma_dcu_mon1__vcfly2_ok__a 101
687 #define ma_dcu_mon1__vcfly2_ok__len 1
688 #define ma_dcu_mon1__vcfly2_ok__mask 0x04
689 #define ma_dcu_mon1__vcfly2_ok__shift 0x02
690 #define ma_dcu_mon1__vcfly2_ok__reset 0x00
691 //----------------------------------------------------------dcu_mon1.pvdd_ok---
693 #define ma_dcu_mon1__pvdd_ok__a 101
694 #define ma_dcu_mon1__pvdd_ok__len 1
695 #define ma_dcu_mon1__pvdd_ok__mask 0x08
696 #define ma_dcu_mon1__pvdd_ok__shift 0x03
697 #define ma_dcu_mon1__pvdd_ok__reset 0x00
698 //-----------------------------------------------------------dcu_mon1.vdd_ok---
700 #define ma_dcu_mon1__vdd_ok__a 101
701 #define ma_dcu_mon1__vdd_ok__len 1
702 #define ma_dcu_mon1__vdd_ok__mask 0x10
703 #define ma_dcu_mon1__vdd_ok__shift 0x04
704 #define ma_dcu_mon1__vdd_ok__reset 0x00
705 //-------------------------------------------------------------dcu_mon1.mute---
707 #define ma_dcu_mon1__mute__a 101
708 #define ma_dcu_mon1__mute__len 1
709 #define ma_dcu_mon1__mute__mask 0x20
710 #define ma_dcu_mon1__mute__shift 0x05
711 #define ma_dcu_mon1__mute__reset 0x00
712 //------------------------------------------------------------dcu_mon1.m_mon---
713 // m sense monitor channel 1
714 #define ma_dcu_mon1__m_mon__a 102
715 #define ma_dcu_mon1__m_mon__len 8
716 #define ma_dcu_mon1__m_mon__mask 0xff
717 #define ma_dcu_mon1__m_mon__shift 0x00
718 #define ma_dcu_mon1__m_mon__reset 0x00
719 //--------------------------------------------------------dcu_mon0.sw_enable---
720 // dcu0 switch enable monitor
721 #define ma_dcu_mon0__sw_enable__a 104
722 #define ma_dcu_mon0__sw_enable__len 1
723 #define ma_dcu_mon0__sw_enable__mask 0x40
724 #define ma_dcu_mon0__sw_enable__shift 0x06
725 #define ma_dcu_mon0__sw_enable__reset 0x00
726 //--------------------------------------------------------dcu_mon1.sw_enable---
727 // dcu1 switch enable monitor
728 #define ma_dcu_mon1__sw_enable__a 104
729 #define ma_dcu_mon1__sw_enable__len 1
730 #define ma_dcu_mon1__sw_enable__mask 0x80
731 #define ma_dcu_mon1__sw_enable__shift 0x07
732 #define ma_dcu_mon1__sw_enable__reset 0x00
733 //------------------------------------------------------------hvboot0_ok_mon---
734 // hvboot0_ok for test/debug
735 #define ma_hvboot0_ok_mon__a 105
736 #define ma_hvboot0_ok_mon__len 1
737 #define ma_hvboot0_ok_mon__mask 0x40
738 #define ma_hvboot0_ok_mon__shift 0x06
739 #define ma_hvboot0_ok_mon__reset 0x00
740 //------------------------------------------------------------hvboot1_ok_mon---
741 // hvboot1_ok for test/debug
742 #define ma_hvboot1_ok_mon__a 105
743 #define ma_hvboot1_ok_mon__len 1
744 #define ma_hvboot1_ok_mon__mask 0x80
745 #define ma_hvboot1_ok_mon__shift 0x07
746 #define ma_hvboot1_ok_mon__reset 0x00
747 //-----------------------------------------------------------------error_acc---
748 // accumulated errors, at and after triggering
749 #define ma_error_acc__a 109
750 #define ma_error_acc__len 8
751 #define ma_error_acc__mask 0xff
752 #define ma_error_acc__shift 0x00
753 #define ma_error_acc__reset 0x00
754 //-------------------------------------------------------------i2s_data_rate---
755 // detected i2s data rate: 00/01/10 = x1/x2/x4
756 #define ma_i2s_data_rate__a 116
757 #define ma_i2s_data_rate__len 2
758 #define ma_i2s_data_rate__mask 0x03
759 #define ma_i2s_data_rate__shift 0x00
760 #define ma_i2s_data_rate__reset 0x00
761 //---------------------------------------------------------audio_in_mode_mon---
762 // audio input mode monitor
763 #define ma_audio_in_mode_mon__a 116
764 #define ma_audio_in_mode_mon__len 3
765 #define ma_audio_in_mode_mon__mask 0x1c
766 #define ma_audio_in_mode_mon__shift 0x02
767 #define ma_audio_in_mode_mon__reset 0x00
768 //------------------------------------------------------------------msel_mon---
769 // msel[2:0] monitor register
770 #define ma_msel_mon__a 117
771 #define ma_msel_mon__len 3
772 #define ma_msel_mon__mask 0x07
773 #define ma_msel_mon__shift 0x00
774 #define ma_msel_mon__reset 0x00
775 //---------------------------------------------------------------------error---
776 // current error flag monitor reg - for app. ctrl.
777 #define ma_error__a 124
778 #define ma_error__len 8
779 #define ma_error__mask 0xff
780 #define ma_error__shift 0x00
781 #define ma_error__reset 0x00
782 //----------------------------------------------------audio_proc_limiter_mon---
783 // b7-b4: channel 3-0 limiter active
784 #define ma_audio_proc_limiter_mon__a 126
785 #define ma_audio_proc_limiter_mon__len 4
786 #define ma_audio_proc_limiter_mon__mask 0xf0
787 #define ma_audio_proc_limiter_mon__shift 0x04
788 #define ma_audio_proc_limiter_mon__reset 0x00
789 //-------------------------------------------------------audio_proc_clip_mon---
790 // b3-b0: channel 3-0 clipping monitor
791 #define ma_audio_proc_clip_mon__a 126
792 #define ma_audio_proc_clip_mon__len 4
793 #define ma_audio_proc_clip_mon__mask 0x0f
794 #define ma_audio_proc_clip_mon__shift 0x00
795 #define ma_audio_proc_clip_mon__reset 0x00
798 #define SOC_ENUM_ERR(xname, xenum)\
799 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
800 .access = SNDRV_CTL_ELEM_ACCESS_READ,\
801 .info = snd_soc_info_enum_double,\
802 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double,\
803 .private_value = (unsigned long)&(xenum) }
805 static struct i2c_client *i2c;
807 struct ma120x0p_priv {
808 struct regmap *regmap;
810 struct snd_soc_component *component;
811 struct gpio_desc *enable_gpio;
812 struct gpio_desc *mute_gpio;
813 struct gpio_desc *booster_gpio;
814 struct gpio_desc *error_gpio;
817 static struct ma120x0p_priv *priv_data;
819 //Used to share the IRQ number within this file
820 static unsigned int irqNumber;
822 // Function prototype for the custom IRQ handler function
823 static irqreturn_t ma120x0p_irq_handler(int irq, void *data);
826 static const char * const limenable_text[] = {"Bypassed", "Enabled"};
827 static const char * const limatack_text[] = {"Slow", "Normal", "Fast"};
828 static const char * const limrelease_text[] = {"Slow", "Normal", "Fast"};
830 static const char * const err_flycap_text[] = {"Ok", "Error"};
831 static const char * const err_overcurr_text[] = {"Ok", "Error"};
832 static const char * const err_pllerr_text[] = {"Ok", "Error"};
833 static const char * const err_pvddunder_text[] = {"Ok", "Error"};
834 static const char * const err_overtempw_text[] = {"Ok", "Error"};
835 static const char * const err_overtempe_text[] = {"Ok", "Error"};
836 static const char * const err_pinlowimp_text[] = {"Ok", "Error"};
837 static const char * const err_dcprot_text[] = {"Ok", "Error"};
839 static const char * const pwr_mode_prof_text[] = {"PMF0", "PMF1", "PMF2",
842 static const struct soc_enum lim_enable_ctrl =
843 SOC_ENUM_SINGLE(ma_audio_proc_limiterenable__a,
844 ma_audio_proc_limiterenable__shift,
845 ma_audio_proc_limiterenable__len + 1,
847 static const struct soc_enum limatack_ctrl =
848 SOC_ENUM_SINGLE(ma_audio_proc_attack__a,
849 ma_audio_proc_attack__shift,
850 ma_audio_proc_attack__len + 1,
852 static const struct soc_enum limrelease_ctrl =
853 SOC_ENUM_SINGLE(ma_audio_proc_release__a,
854 ma_audio_proc_release__shift,
855 ma_audio_proc_release__len + 1,
857 static const struct soc_enum err_flycap_ctrl =
858 SOC_ENUM_SINGLE(ma_error__a, 0, 3, err_flycap_text);
859 static const struct soc_enum err_overcurr_ctrl =
860 SOC_ENUM_SINGLE(ma_error__a, 1, 3, err_overcurr_text);
861 static const struct soc_enum err_pllerr_ctrl =
862 SOC_ENUM_SINGLE(ma_error__a, 2, 3, err_pllerr_text);
863 static const struct soc_enum err_pvddunder_ctrl =
864 SOC_ENUM_SINGLE(ma_error__a, 3, 3, err_pvddunder_text);
865 static const struct soc_enum err_overtempw_ctrl =
866 SOC_ENUM_SINGLE(ma_error__a, 4, 3, err_overtempw_text);
867 static const struct soc_enum err_overtempe_ctrl =
868 SOC_ENUM_SINGLE(ma_error__a, 5, 3, err_overtempe_text);
869 static const struct soc_enum err_pinlowimp_ctrl =
870 SOC_ENUM_SINGLE(ma_error__a, 6, 3, err_pinlowimp_text);
871 static const struct soc_enum err_dcprot_ctrl =
872 SOC_ENUM_SINGLE(ma_error__a, 7, 3, err_dcprot_text);
873 static const struct soc_enum pwr_mode_prof_ctrl =
874 SOC_ENUM_SINGLE(ma_pmprofile__a, ma_pmprofile__shift, 5,
877 static const char * const pwr_mode_texts[] = {
878 "Dynamic power mode",
884 static const int pwr_mode_values[] = {
891 static SOC_VALUE_ENUM_SINGLE_DECL(pwr_mode_ctrl,
892 ma_pm_man__a, 0, 0x70,
896 static const DECLARE_TLV_DB_SCALE(ma120x0p_vol_tlv, -14400, 100, 0);
897 static const DECLARE_TLV_DB_SCALE(ma120x0p_lim_tlv, -5000, 100, 0);
898 static const DECLARE_TLV_DB_SCALE(ma120x0p_lr_tlv, -5000, 100, 0);
900 static const struct snd_kcontrol_new ma120x0p_snd_controls[] = {
902 SOC_SINGLE_RANGE_TLV("A.Mstr Vol Volume",
903 ma_vol_db_master__a, 0, 0x18, 0xa8, 1, ma120x0p_vol_tlv),
906 SOC_SINGLE_RANGE_TLV("B.L Vol Volume",
907 ma_vol_db_ch0__a, 0, 0x18, 0x4a, 1, ma120x0p_lr_tlv),
908 SOC_SINGLE_RANGE_TLV("C.R Vol Volume",
909 ma_vol_db_ch1__a, 0, 0x18, 0x4a, 1, ma120x0p_lr_tlv),
911 //L-R Limiter Threshold ch0-ch1
912 SOC_DOUBLE_R_RANGE_TLV("D.Lim thresh Volume",
913 ma_thr_db_ch0__a, ma_thr_db_ch1__a, 0, 0x0e, 0x4a, 1,
916 //Enum Switches/Selectors
917 //SOC_ENUM("E.AudioProc Mute", audioproc_mute_ctrl),
918 SOC_ENUM("F.Limiter Enable", lim_enable_ctrl),
919 SOC_ENUM("G.Limiter Attck", limatack_ctrl),
920 SOC_ENUM("H.Limiter Rls", limrelease_ctrl),
922 //Enum Error Monitor (read-only)
923 SOC_ENUM_ERR("I.Err flycap", err_flycap_ctrl),
924 SOC_ENUM_ERR("J.Err overcurr", err_overcurr_ctrl),
925 SOC_ENUM_ERR("K.Err pllerr", err_pllerr_ctrl),
926 SOC_ENUM_ERR("L.Err pvddunder", err_pvddunder_ctrl),
927 SOC_ENUM_ERR("M.Err overtempw", err_overtempw_ctrl),
928 SOC_ENUM_ERR("N.Err overtempe", err_overtempe_ctrl),
929 SOC_ENUM_ERR("O.Err pinlowimp", err_pinlowimp_ctrl),
930 SOC_ENUM_ERR("P.Err dcprot", err_dcprot_ctrl),
932 //Power modes profiles
933 SOC_ENUM("Q.PM Prof", pwr_mode_prof_ctrl),
935 // Power mode selection (Dynamic,1,2,3)
936 SOC_ENUM("R.Power Mode", pwr_mode_ctrl),
940 static int ma120x0p_hw_params(struct snd_pcm_substream *substream,
941 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
945 struct snd_soc_component *component = dai->component;
947 priv_data->component = component;
949 switch (params_format(params)) {
950 case SNDRV_PCM_FORMAT_S16_LE:
953 case SNDRV_PCM_FORMAT_S24_LE:
956 case SNDRV_PCM_FORMAT_S32_LE:
960 dev_err(dai->dev, "Unsupported word length: %u\n",
961 params_format(params));
966 snd_soc_component_update_bits(component, ma_i2s_framesize__a,
967 ma_i2s_framesize__mask, blen);
972 static int ma120x0p_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
976 struct ma120x0p_priv *ma120x0p;
978 struct snd_soc_component *component = dai->component;
980 ma120x0p = snd_soc_component_get_drvdata(component);
987 gpiod_set_value_cansleep(priv_data->mute_gpio, val);
992 static const struct snd_soc_dai_ops ma120x0p_dai_ops = {
993 .hw_params = ma120x0p_hw_params,
994 .mute_stream = ma120x0p_mute_stream,
997 static struct snd_soc_dai_driver ma120x0p_dai = {
998 .name = "ma120x0p-amp",
1000 .stream_name = "Playback",
1003 .rates = SNDRV_PCM_RATE_CONTINUOUS,
1006 .formats = SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE
1008 .ops = &ma120x0p_dai_ops,
1012 static int ma120x0p_clear_err(struct snd_soc_component *component)
1016 struct ma120x0p_priv *ma120x0p;
1018 ma120x0p = snd_soc_component_get_drvdata(component);
1020 ret = snd_soc_component_update_bits(component,
1021 ma_eh_clear__a, ma_eh_clear__mask, 0x00);
1025 ret = snd_soc_component_update_bits(component,
1026 ma_eh_clear__a, ma_eh_clear__mask, 0x04);
1030 ret = snd_soc_component_update_bits(component,
1031 ma_eh_clear__a, ma_eh_clear__mask, 0x00);
1038 static void ma120x0p_remove(struct snd_soc_component *component)
1040 struct ma120x0p_priv *ma120x0p;
1042 ma120x0p = snd_soc_component_get_drvdata(component);
1045 static int ma120x0p_probe(struct snd_soc_component *component)
1047 struct ma120x0p_priv *ma120x0p;
1051 i2c = container_of(component->dev, struct i2c_client, dev);
1053 ma120x0p = snd_soc_component_get_drvdata(component);
1056 ma120x0p_clear_err(component);
1060 // set serial audio format I2S and enable audio processor
1061 ret = snd_soc_component_write(component, ma_i2s_format__a, 0x08);
1065 // Enable audio limiter
1066 ret = snd_soc_component_update_bits(component,
1067 ma_audio_proc_limiterenable__a,
1068 ma_audio_proc_limiterenable__mask, 0x40);
1072 // Set lim attack to fast
1073 ret = snd_soc_component_update_bits(component,
1074 ma_audio_proc_attack__a, ma_audio_proc_attack__mask, 0x80);
1078 // Set lim attack to low
1079 ret = snd_soc_component_update_bits(component,
1080 ma_audio_proc_release__a, ma_audio_proc_release__mask, 0x00);
1084 // set volume to 0dB
1085 ret = snd_soc_component_write(component, ma_vol_db_master__a, 0x18);
1089 // set ch0 lim thresh to -15dB
1090 ret = snd_soc_component_write(component, ma_thr_db_ch0__a, 0x27);
1094 // set ch1 lim thresh to -15dB
1095 ret = snd_soc_component_write(component, ma_thr_db_ch1__a, 0x27);
1100 ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x00, 0);
1103 ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x01, 0);
1106 ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x02, 0);
1109 ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x08, 0);
1112 ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x10, 0);
1115 ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x20, 0);
1118 ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x40, 0);
1121 ret = snd_soc_component_test_bits(component, ma_error_acc__a, 0x80, 0);
1128 static int ma120x0p_set_bias_level(struct snd_soc_component *component,
1129 enum snd_soc_bias_level level)
1133 struct ma120x0p_priv *ma120x0p;
1135 ma120x0p = snd_soc_component_get_drvdata(component);
1138 case SND_SOC_BIAS_ON:
1141 case SND_SOC_BIAS_PREPARE:
1144 case SND_SOC_BIAS_STANDBY:
1145 ret = gpiod_get_value_cansleep(priv_data->enable_gpio);
1147 dev_err(component->dev, "Device ma120x0p disabled in STANDBY BIAS: %d\n",
1153 case SND_SOC_BIAS_OFF:
1160 static const struct snd_soc_dapm_widget ma120x0p_dapm_widgets[] = {
1161 SND_SOC_DAPM_OUTPUT("OUT_A"),
1162 SND_SOC_DAPM_OUTPUT("OUT_B"),
1165 static const struct snd_soc_dapm_route ma120x0p_dapm_routes[] = {
1166 { "OUT_B", NULL, "Playback" },
1167 { "OUT_A", NULL, "Playback" },
1170 static const struct snd_soc_component_driver ma120x0p_component_driver = {
1171 .probe = ma120x0p_probe,
1172 .remove = ma120x0p_remove,
1173 .set_bias_level = ma120x0p_set_bias_level,
1174 .dapm_widgets = ma120x0p_dapm_widgets,
1175 .num_dapm_widgets = ARRAY_SIZE(ma120x0p_dapm_widgets),
1176 .dapm_routes = ma120x0p_dapm_routes,
1177 .num_dapm_routes = ARRAY_SIZE(ma120x0p_dapm_routes),
1178 .controls = ma120x0p_snd_controls,
1179 .num_controls = ARRAY_SIZE(ma120x0p_snd_controls),
1180 .use_pmdown_time = 1,
1182 .non_legacy_dai_naming = 1,
1186 static const struct reg_default ma120x0p_reg_defaults[] = {
1190 static bool ma120x0p_reg_volatile(struct device *dev, unsigned int reg)
1200 static const struct of_device_id ma120x0p_of_match[] = {
1201 { .compatible = "ma,ma120x0p", },
1205 MODULE_DEVICE_TABLE(of, ma120x0p_of_match);
1207 static struct regmap_config ma120x0p_regmap_config = {
1211 .max_register = 255,
1212 .volatile_reg = ma120x0p_reg_volatile,
1214 .cache_type = REGCACHE_RBTREE,
1215 .reg_defaults = ma120x0p_reg_defaults,
1216 .num_reg_defaults = ARRAY_SIZE(ma120x0p_reg_defaults),
1219 static int ma120x0p_i2c_probe(struct i2c_client *i2c,
1220 const struct i2c_device_id *id)
1224 priv_data = devm_kzalloc(&i2c->dev, sizeof(*priv_data), GFP_KERNEL);
1227 i2c_set_clientdata(i2c, priv_data);
1229 priv_data->regmap = devm_regmap_init_i2c(i2c, &ma120x0p_regmap_config);
1230 if (IS_ERR(priv_data->regmap)) {
1231 ret = PTR_ERR(priv_data->regmap);
1237 //Make sure the device is muted
1238 priv_data->mute_gpio = devm_gpiod_get_optional(&i2c->dev, "mute_gp",
1240 if (IS_ERR(priv_data->mute_gpio)) {
1241 ret = PTR_ERR(priv_data->mute_gpio);
1242 dev_err(&i2c->dev, "Failed to get mute gpio line: %d\n", ret);
1247 // MA120xx0P devices are usually powered by an integrated boost converter.
1248 // An option GPIO control line is provided to enable the booster properly and
1249 // in sync with the enable and mute GPIO lines.
1250 priv_data->booster_gpio = devm_gpiod_get_optional(&i2c->dev,
1251 "booster_gp", GPIOD_OUT_LOW);
1252 if (IS_ERR(priv_data->booster_gpio)) {
1253 ret = PTR_ERR(priv_data->booster_gpio);
1255 "Failed to get booster enable gpio line: %d\n", ret);
1260 //Enable booster and wait 200ms until stable PVDD
1261 gpiod_set_value_cansleep(priv_data->booster_gpio, 1);
1265 priv_data->enable_gpio = devm_gpiod_get_optional(&i2c->dev,
1266 "enable_gp", GPIOD_OUT_LOW);
1267 if (IS_ERR(priv_data->enable_gpio)) {
1268 ret = PTR_ERR(priv_data->enable_gpio);
1270 "Failed to get ma120x0p enable gpio line: %d\n", ret);
1275 //Optional use of ma120x0pp error line as an interrupt trigger to
1277 //Get error input gpio ma120x0p
1278 priv_data->error_gpio = devm_gpiod_get_optional(&i2c->dev,
1279 "error_gp", GPIOD_IN);
1280 if (IS_ERR(priv_data->error_gpio)) {
1281 ret = PTR_ERR(priv_data->error_gpio);
1283 "Failed to get ma120x0p error gpio line: %d\n", ret);
1287 if (priv_data->error_gpio != NULL) {
1288 irqNumber = gpiod_to_irq(priv_data->error_gpio);
1290 ret = devm_request_threaded_irq(&i2c->dev,
1291 irqNumber, ma120x0p_irq_handler,
1292 NULL, IRQF_TRIGGER_FALLING,
1293 "ma120x0p", priv_data);
1295 dev_warn(&i2c->dev, "Failed to request IRQ: %d\n",
1299 ret = devm_snd_soc_register_component(&i2c->dev,
1300 &ma120x0p_component_driver, &ma120x0p_dai, 1);
1305 static irqreturn_t ma120x0p_irq_handler(int irq, void *data)
1307 gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
1308 gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
1312 static int ma120x0p_i2c_remove(struct i2c_client *i2c)
1314 snd_soc_unregister_component(&i2c->dev);
1315 i2c_set_clientdata(i2c, NULL);
1317 gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
1319 gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
1321 gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
1329 static void ma120x0p_i2c_shutdown(struct i2c_client *i2c)
1331 snd_soc_unregister_component(&i2c->dev);
1332 i2c_set_clientdata(i2c, NULL);
1334 gpiod_set_value_cansleep(priv_data->mute_gpio, 0);
1336 gpiod_set_value_cansleep(priv_data->enable_gpio, 1);
1338 gpiod_set_value_cansleep(priv_data->booster_gpio, 0);
1344 static const struct i2c_device_id ma120x0p_i2c_id[] = {
1349 MODULE_DEVICE_TABLE(i2c, ma120x0p_i2c_id);
1351 static struct i2c_driver ma120x0p_i2c_driver = {
1354 .owner = THIS_MODULE,
1355 .of_match_table = ma120x0p_of_match,
1357 .probe = ma120x0p_i2c_probe,
1358 .remove = ma120x0p_i2c_remove,
1359 .shutdown = ma120x0p_i2c_shutdown,
1360 .id_table = ma120x0p_i2c_id
1363 static int __init ma120x0p_modinit(void)
1367 ret = i2c_add_driver(&ma120x0p_i2c_driver);
1369 pr_err("Failed to register MA120X0P I2C driver: %d\n", ret);
1374 module_init(ma120x0p_modinit);
1376 static void __exit ma120x0p_exit(void)
1378 i2c_del_driver(&ma120x0p_i2c_driver);
1380 module_exit(ma120x0p_exit);
1382 MODULE_AUTHOR("Ariel Muszkat ariel.muszkat@gmail.com>");
1383 MODULE_DESCRIPTION("ASoC driver for ma120x0p");
1384 MODULE_LICENSE("GPL v2");