1 // SPDX-License-Identifier: GPL-2.0-only
3 * cs42l73.c -- CS42L73 ALSA Soc Audio driver
5 * Copyright 2011 Cirrus Logic, Inc.
7 * Authors: Georgi Vlaev, Nucleus Systems Ltd, <joe@nucleusys.com>
8 * Brian Austin, Cirrus Logic Inc, <brian.austin@cirrus.com>
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/delay.h>
16 #include <linux/of_gpio.h>
18 #include <linux/i2c.h>
19 #include <linux/regmap.h>
20 #include <linux/slab.h>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/pcm_params.h>
24 #include <sound/soc.h>
25 #include <sound/soc-dapm.h>
26 #include <sound/initval.h>
27 #include <sound/tlv.h>
28 #include <sound/cs42l73.h>
35 struct cs42l73_private {
36 struct cs42l73_platform_data pdata;
37 struct sp_config config[3];
38 struct regmap *regmap;
45 static const struct reg_default cs42l73_reg_defaults[] = {
46 { 6, 0xF1 }, /* r06 - Power Ctl 1 */
47 { 7, 0xDF }, /* r07 - Power Ctl 2 */
48 { 8, 0x3F }, /* r08 - Power Ctl 3 */
49 { 9, 0x50 }, /* r09 - Charge Pump Freq */
50 { 10, 0x53 }, /* r0A - Output Load MicBias Short Detect */
51 { 11, 0x00 }, /* r0B - DMIC Master Clock Ctl */
52 { 12, 0x00 }, /* r0C - Aux PCM Ctl */
53 { 13, 0x15 }, /* r0D - Aux PCM Master Clock Ctl */
54 { 14, 0x00 }, /* r0E - Audio PCM Ctl */
55 { 15, 0x15 }, /* r0F - Audio PCM Master Clock Ctl */
56 { 16, 0x00 }, /* r10 - Voice PCM Ctl */
57 { 17, 0x15 }, /* r11 - Voice PCM Master Clock Ctl */
58 { 18, 0x00 }, /* r12 - Voice/Aux Sample Rate */
59 { 19, 0x06 }, /* r13 - Misc I/O Path Ctl */
60 { 20, 0x00 }, /* r14 - ADC Input Path Ctl */
61 { 21, 0x00 }, /* r15 - MICA Preamp, PGA Volume */
62 { 22, 0x00 }, /* r16 - MICB Preamp, PGA Volume */
63 { 23, 0x00 }, /* r17 - Input Path A Digital Volume */
64 { 24, 0x00 }, /* r18 - Input Path B Digital Volume */
65 { 25, 0x00 }, /* r19 - Playback Digital Ctl */
66 { 26, 0x00 }, /* r1A - HP/LO Left Digital Volume */
67 { 27, 0x00 }, /* r1B - HP/LO Right Digital Volume */
68 { 28, 0x00 }, /* r1C - Speakerphone Digital Volume */
69 { 29, 0x00 }, /* r1D - Ear/SPKLO Digital Volume */
70 { 30, 0x00 }, /* r1E - HP Left Analog Volume */
71 { 31, 0x00 }, /* r1F - HP Right Analog Volume */
72 { 32, 0x00 }, /* r20 - LO Left Analog Volume */
73 { 33, 0x00 }, /* r21 - LO Right Analog Volume */
74 { 34, 0x00 }, /* r22 - Stereo Input Path Advisory Volume */
75 { 35, 0x00 }, /* r23 - Aux PCM Input Advisory Volume */
76 { 36, 0x00 }, /* r24 - Audio PCM Input Advisory Volume */
77 { 37, 0x00 }, /* r25 - Voice PCM Input Advisory Volume */
78 { 38, 0x00 }, /* r26 - Limiter Attack Rate HP/LO */
79 { 39, 0x7F }, /* r27 - Limter Ctl, Release Rate HP/LO */
80 { 40, 0x00 }, /* r28 - Limter Threshold HP/LO */
81 { 41, 0x00 }, /* r29 - Limiter Attack Rate Speakerphone */
82 { 42, 0x3F }, /* r2A - Limter Ctl, Release Rate Speakerphone */
83 { 43, 0x00 }, /* r2B - Limter Threshold Speakerphone */
84 { 44, 0x00 }, /* r2C - Limiter Attack Rate Ear/SPKLO */
85 { 45, 0x3F }, /* r2D - Limter Ctl, Release Rate Ear/SPKLO */
86 { 46, 0x00 }, /* r2E - Limter Threshold Ear/SPKLO */
87 { 47, 0x00 }, /* r2F - ALC Enable, Attack Rate Left/Right */
88 { 48, 0x3F }, /* r30 - ALC Release Rate Left/Right */
89 { 49, 0x00 }, /* r31 - ALC Threshold Left/Right */
90 { 50, 0x00 }, /* r32 - Noise Gate Ctl Left/Right */
91 { 51, 0x00 }, /* r33 - ALC/NG Misc Ctl */
92 { 52, 0x18 }, /* r34 - Mixer Ctl */
93 { 53, 0x3F }, /* r35 - HP/LO Left Mixer Input Path Volume */
94 { 54, 0x3F }, /* r36 - HP/LO Right Mixer Input Path Volume */
95 { 55, 0x3F }, /* r37 - HP/LO Left Mixer Aux PCM Volume */
96 { 56, 0x3F }, /* r38 - HP/LO Right Mixer Aux PCM Volume */
97 { 57, 0x3F }, /* r39 - HP/LO Left Mixer Audio PCM Volume */
98 { 58, 0x3F }, /* r3A - HP/LO Right Mixer Audio PCM Volume */
99 { 59, 0x3F }, /* r3B - HP/LO Left Mixer Voice PCM Mono Volume */
100 { 60, 0x3F }, /* r3C - HP/LO Right Mixer Voice PCM Mono Volume */
101 { 61, 0x3F }, /* r3D - Aux PCM Left Mixer Input Path Volume */
102 { 62, 0x3F }, /* r3E - Aux PCM Right Mixer Input Path Volume */
103 { 63, 0x3F }, /* r3F - Aux PCM Left Mixer Volume */
104 { 64, 0x3F }, /* r40 - Aux PCM Left Mixer Volume */
105 { 65, 0x3F }, /* r41 - Aux PCM Left Mixer Audio PCM L Volume */
106 { 66, 0x3F }, /* r42 - Aux PCM Right Mixer Audio PCM R Volume */
107 { 67, 0x3F }, /* r43 - Aux PCM Left Mixer Voice PCM Volume */
108 { 68, 0x3F }, /* r44 - Aux PCM Right Mixer Voice PCM Volume */
109 { 69, 0x3F }, /* r45 - Audio PCM Left Input Path Volume */
110 { 70, 0x3F }, /* r46 - Audio PCM Right Input Path Volume */
111 { 71, 0x3F }, /* r47 - Audio PCM Left Mixer Aux PCM L Volume */
112 { 72, 0x3F }, /* r48 - Audio PCM Right Mixer Aux PCM R Volume */
113 { 73, 0x3F }, /* r49 - Audio PCM Left Mixer Volume */
114 { 74, 0x3F }, /* r4A - Audio PCM Right Mixer Volume */
115 { 75, 0x3F }, /* r4B - Audio PCM Left Mixer Voice PCM Volume */
116 { 76, 0x3F }, /* r4C - Audio PCM Right Mixer Voice PCM Volume */
117 { 77, 0x3F }, /* r4D - Voice PCM Left Input Path Volume */
118 { 78, 0x3F }, /* r4E - Voice PCM Right Input Path Volume */
119 { 79, 0x3F }, /* r4F - Voice PCM Left Mixer Aux PCM L Volume */
120 { 80, 0x3F }, /* r50 - Voice PCM Right Mixer Aux PCM R Volume */
121 { 81, 0x3F }, /* r51 - Voice PCM Left Mixer Audio PCM L Volume */
122 { 82, 0x3F }, /* r52 - Voice PCM Right Mixer Audio PCM R Volume */
123 { 83, 0x3F }, /* r53 - Voice PCM Left Mixer Voice PCM Volume */
124 { 84, 0x3F }, /* r54 - Voice PCM Right Mixer Voice PCM Volume */
125 { 85, 0xAA }, /* r55 - Mono Mixer Ctl */
126 { 86, 0x3F }, /* r56 - SPK Mono Mixer Input Path Volume */
127 { 87, 0x3F }, /* r57 - SPK Mono Mixer Aux PCM Mono/L/R Volume */
128 { 88, 0x3F }, /* r58 - SPK Mono Mixer Audio PCM Mono/L/R Volume */
129 { 89, 0x3F }, /* r59 - SPK Mono Mixer Voice PCM Mono Volume */
130 { 90, 0x3F }, /* r5A - SPKLO Mono Mixer Input Path Mono Volume */
131 { 91, 0x3F }, /* r5B - SPKLO Mono Mixer Aux Mono/L/R Volume */
132 { 92, 0x3F }, /* r5C - SPKLO Mono Mixer Audio Mono/L/R Volume */
133 { 93, 0x3F }, /* r5D - SPKLO Mono Mixer Voice Mono Volume */
134 { 94, 0x00 }, /* r5E - Interrupt Mask 1 */
135 { 95, 0x00 }, /* r5F - Interrupt Mask 2 */
138 static bool cs42l73_volatile_register(struct device *dev, unsigned int reg)
149 static bool cs42l73_readable_register(struct device *dev, unsigned int reg)
152 case CS42L73_DEVID_AB ... CS42L73_DEVID_E:
153 case CS42L73_REVID ... CS42L73_IM2:
160 static const DECLARE_TLV_DB_RANGE(hpaloa_tlv,
161 0, 13, TLV_DB_SCALE_ITEM(-7600, 200, 0),
162 14, 75, TLV_DB_SCALE_ITEM(-4900, 100, 0)
165 static DECLARE_TLV_DB_SCALE(adc_boost_tlv, 0, 2500, 0);
167 static DECLARE_TLV_DB_SCALE(hl_tlv, -10200, 50, 0);
169 static DECLARE_TLV_DB_SCALE(ipd_tlv, -9600, 100, 0);
171 static DECLARE_TLV_DB_SCALE(micpga_tlv, -600, 50, 0);
173 static const DECLARE_TLV_DB_RANGE(limiter_tlv,
174 0, 2, TLV_DB_SCALE_ITEM(-3000, 600, 0),
175 3, 7, TLV_DB_SCALE_ITEM(-1200, 300, 0)
178 static const DECLARE_TLV_DB_SCALE(attn_tlv, -6300, 100, 1);
180 static const char * const cs42l73_pgaa_text[] = { "Line A", "Mic 1" };
181 static const char * const cs42l73_pgab_text[] = { "Line B", "Mic 2" };
183 static SOC_ENUM_SINGLE_DECL(pgaa_enum,
187 static SOC_ENUM_SINGLE_DECL(pgab_enum,
191 static const struct snd_kcontrol_new pgaa_mux =
192 SOC_DAPM_ENUM("Left Analog Input Capture Mux", pgaa_enum);
194 static const struct snd_kcontrol_new pgab_mux =
195 SOC_DAPM_ENUM("Right Analog Input Capture Mux", pgab_enum);
197 static const struct snd_kcontrol_new input_left_mixer[] = {
198 SOC_DAPM_SINGLE("ADC Left Input", CS42L73_PWRCTL1,
200 SOC_DAPM_SINGLE("DMIC Left Input", CS42L73_PWRCTL1,
204 static const struct snd_kcontrol_new input_right_mixer[] = {
205 SOC_DAPM_SINGLE("ADC Right Input", CS42L73_PWRCTL1,
207 SOC_DAPM_SINGLE("DMIC Right Input", CS42L73_PWRCTL1,
211 static const char * const cs42l73_ng_delay_text[] = {
212 "50ms", "100ms", "150ms", "200ms" };
214 static SOC_ENUM_SINGLE_DECL(ng_delay_enum,
216 cs42l73_ng_delay_text);
218 static const char * const cs42l73_mono_mix_texts[] = {
219 "Left", "Right", "Mono Mix"};
221 static const unsigned int cs42l73_mono_mix_values[] = { 0, 1, 2 };
223 static const struct soc_enum spk_asp_enum =
224 SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 6, 3,
225 ARRAY_SIZE(cs42l73_mono_mix_texts),
226 cs42l73_mono_mix_texts,
227 cs42l73_mono_mix_values);
229 static const struct snd_kcontrol_new spk_asp_mixer =
230 SOC_DAPM_ENUM("Route", spk_asp_enum);
232 static const struct soc_enum spk_xsp_enum =
233 SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 4, 3,
234 ARRAY_SIZE(cs42l73_mono_mix_texts),
235 cs42l73_mono_mix_texts,
236 cs42l73_mono_mix_values);
238 static const struct snd_kcontrol_new spk_xsp_mixer =
239 SOC_DAPM_ENUM("Route", spk_xsp_enum);
241 static const struct soc_enum esl_asp_enum =
242 SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 2, 3,
243 ARRAY_SIZE(cs42l73_mono_mix_texts),
244 cs42l73_mono_mix_texts,
245 cs42l73_mono_mix_values);
247 static const struct snd_kcontrol_new esl_asp_mixer =
248 SOC_DAPM_ENUM("Route", esl_asp_enum);
250 static const struct soc_enum esl_xsp_enum =
251 SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 0, 3,
252 ARRAY_SIZE(cs42l73_mono_mix_texts),
253 cs42l73_mono_mix_texts,
254 cs42l73_mono_mix_values);
256 static const struct snd_kcontrol_new esl_xsp_mixer =
257 SOC_DAPM_ENUM("Route", esl_xsp_enum);
259 static const char * const cs42l73_ip_swap_text[] = {
260 "Stereo", "Mono A", "Mono B", "Swap A-B"};
262 static SOC_ENUM_SINGLE_DECL(ip_swap_enum,
264 cs42l73_ip_swap_text);
266 static const char * const cs42l73_spo_mixer_text[] = {"Mono", "Stereo"};
268 static SOC_ENUM_SINGLE_DECL(vsp_output_mux_enum,
270 cs42l73_spo_mixer_text);
272 static SOC_ENUM_SINGLE_DECL(xsp_output_mux_enum,
274 cs42l73_spo_mixer_text);
276 static const struct snd_kcontrol_new hp_amp_ctl =
277 SOC_DAPM_SINGLE("Switch", CS42L73_PWRCTL3, 0, 1, 1);
279 static const struct snd_kcontrol_new lo_amp_ctl =
280 SOC_DAPM_SINGLE("Switch", CS42L73_PWRCTL3, 1, 1, 1);
282 static const struct snd_kcontrol_new spk_amp_ctl =
283 SOC_DAPM_SINGLE("Switch", CS42L73_PWRCTL3, 2, 1, 1);
285 static const struct snd_kcontrol_new spklo_amp_ctl =
286 SOC_DAPM_SINGLE("Switch", CS42L73_PWRCTL3, 4, 1, 1);
288 static const struct snd_kcontrol_new ear_amp_ctl =
289 SOC_DAPM_SINGLE("Switch", CS42L73_PWRCTL3, 3, 1, 1);
291 static const struct snd_kcontrol_new cs42l73_snd_controls[] = {
292 SOC_DOUBLE_R_SX_TLV("Headphone Analog Playback Volume",
293 CS42L73_HPAAVOL, CS42L73_HPBAVOL, 0,
294 0x41, 0x4B, hpaloa_tlv),
296 SOC_DOUBLE_R_SX_TLV("LineOut Analog Playback Volume", CS42L73_LOAAVOL,
297 CS42L73_LOBAVOL, 0, 0x41, 0x4B, hpaloa_tlv),
299 SOC_DOUBLE_R_SX_TLV("Input PGA Analog Volume", CS42L73_MICAPREPGAAVOL,
300 CS42L73_MICBPREPGABVOL, 0, 0x34,
303 SOC_DOUBLE_R("MIC Preamp Switch", CS42L73_MICAPREPGAAVOL,
304 CS42L73_MICBPREPGABVOL, 6, 1, 1),
306 SOC_DOUBLE_R_SX_TLV("Input Path Digital Volume", CS42L73_IPADVOL,
307 CS42L73_IPBDVOL, 0, 0xA0, 0x6C, ipd_tlv),
309 SOC_DOUBLE_R_SX_TLV("HL Digital Playback Volume",
310 CS42L73_HLADVOL, CS42L73_HLBDVOL,
311 0, 0x34, 0xE4, hl_tlv),
313 SOC_SINGLE_TLV("ADC A Boost Volume",
314 CS42L73_ADCIPC, 2, 0x01, 1, adc_boost_tlv),
316 SOC_SINGLE_TLV("ADC B Boost Volume",
317 CS42L73_ADCIPC, 6, 0x01, 1, adc_boost_tlv),
319 SOC_SINGLE_SX_TLV("Speakerphone Digital Volume",
320 CS42L73_SPKDVOL, 0, 0x34, 0xE4, hl_tlv),
322 SOC_SINGLE_SX_TLV("Ear Speaker Digital Volume",
323 CS42L73_ESLDVOL, 0, 0x34, 0xE4, hl_tlv),
325 SOC_DOUBLE_R("Headphone Analog Playback Switch", CS42L73_HPAAVOL,
326 CS42L73_HPBAVOL, 7, 1, 1),
328 SOC_DOUBLE_R("LineOut Analog Playback Switch", CS42L73_LOAAVOL,
329 CS42L73_LOBAVOL, 7, 1, 1),
330 SOC_DOUBLE("Input Path Digital Switch", CS42L73_ADCIPC, 0, 4, 1, 1),
331 SOC_DOUBLE("HL Digital Playback Switch", CS42L73_PBDC, 0,
333 SOC_SINGLE("Speakerphone Digital Playback Switch", CS42L73_PBDC, 2, 1,
335 SOC_SINGLE("Ear Speaker Digital Playback Switch", CS42L73_PBDC, 3, 1,
338 SOC_SINGLE("PGA Soft-Ramp Switch", CS42L73_MIOPC, 3, 1, 0),
339 SOC_SINGLE("Analog Zero Cross Switch", CS42L73_MIOPC, 2, 1, 0),
340 SOC_SINGLE("Digital Soft-Ramp Switch", CS42L73_MIOPC, 1, 1, 0),
341 SOC_SINGLE("Analog Output Soft-Ramp Switch", CS42L73_MIOPC, 0, 1, 0),
343 SOC_DOUBLE("ADC Signal Polarity Switch", CS42L73_ADCIPC, 1, 5, 1,
346 SOC_SINGLE("HL Limiter Attack Rate", CS42L73_LIMARATEHL, 0, 0x3F,
348 SOC_SINGLE("HL Limiter Release Rate", CS42L73_LIMRRATEHL, 0,
352 SOC_SINGLE("HL Limiter Switch", CS42L73_LIMRRATEHL, 7, 1, 0),
353 SOC_SINGLE("HL Limiter All Channels Switch", CS42L73_LIMRRATEHL, 6, 1,
356 SOC_SINGLE_TLV("HL Limiter Max Threshold Volume", CS42L73_LMAXHL, 5, 7,
359 SOC_SINGLE_TLV("HL Limiter Cushion Volume", CS42L73_LMAXHL, 2, 7, 1,
362 SOC_SINGLE("SPK Limiter Attack Rate Volume", CS42L73_LIMARATESPK, 0,
364 SOC_SINGLE("SPK Limiter Release Rate Volume", CS42L73_LIMRRATESPK, 0,
366 SOC_SINGLE("SPK Limiter Switch", CS42L73_LIMRRATESPK, 7, 1, 0),
367 SOC_SINGLE("SPK Limiter All Channels Switch", CS42L73_LIMRRATESPK,
369 SOC_SINGLE_TLV("SPK Limiter Max Threshold Volume", CS42L73_LMAXSPK, 5,
372 SOC_SINGLE_TLV("SPK Limiter Cushion Volume", CS42L73_LMAXSPK, 2, 7, 1,
375 SOC_SINGLE("ESL Limiter Attack Rate Volume", CS42L73_LIMARATEESL, 0,
377 SOC_SINGLE("ESL Limiter Release Rate Volume", CS42L73_LIMRRATEESL, 0,
379 SOC_SINGLE("ESL Limiter Switch", CS42L73_LIMRRATEESL, 7, 1, 0),
380 SOC_SINGLE_TLV("ESL Limiter Max Threshold Volume", CS42L73_LMAXESL, 5,
383 SOC_SINGLE_TLV("ESL Limiter Cushion Volume", CS42L73_LMAXESL, 2, 7, 1,
386 SOC_SINGLE("ALC Attack Rate Volume", CS42L73_ALCARATE, 0, 0x3F, 0),
387 SOC_SINGLE("ALC Release Rate Volume", CS42L73_ALCRRATE, 0, 0x3F, 0),
388 SOC_DOUBLE("ALC Switch", CS42L73_ALCARATE, 6, 7, 1, 0),
389 SOC_SINGLE_TLV("ALC Max Threshold Volume", CS42L73_ALCMINMAX, 5, 7, 0,
391 SOC_SINGLE_TLV("ALC Min Threshold Volume", CS42L73_ALCMINMAX, 2, 7, 0,
394 SOC_DOUBLE("NG Enable Switch", CS42L73_NGCAB, 6, 7, 1, 0),
395 SOC_SINGLE("NG Boost Switch", CS42L73_NGCAB, 5, 1, 0),
397 NG Threshold depends on NG_BOOTSAB, which selects
398 between two threshold scales in decibels.
399 Set linear values for now ..
401 SOC_SINGLE("NG Threshold", CS42L73_NGCAB, 2, 7, 0),
402 SOC_ENUM("NG Delay", ng_delay_enum),
404 SOC_DOUBLE_R_TLV("XSP-IP Volume",
405 CS42L73_XSPAIPAA, CS42L73_XSPBIPBA, 0, 0x3F, 1,
407 SOC_DOUBLE_R_TLV("XSP-XSP Volume",
408 CS42L73_XSPAXSPAA, CS42L73_XSPBXSPBA, 0, 0x3F, 1,
410 SOC_DOUBLE_R_TLV("XSP-ASP Volume",
411 CS42L73_XSPAASPAA, CS42L73_XSPAASPBA, 0, 0x3F, 1,
413 SOC_DOUBLE_R_TLV("XSP-VSP Volume",
414 CS42L73_XSPAVSPMA, CS42L73_XSPBVSPMA, 0, 0x3F, 1,
417 SOC_DOUBLE_R_TLV("ASP-IP Volume",
418 CS42L73_ASPAIPAA, CS42L73_ASPBIPBA, 0, 0x3F, 1,
420 SOC_DOUBLE_R_TLV("ASP-XSP Volume",
421 CS42L73_ASPAXSPAA, CS42L73_ASPBXSPBA, 0, 0x3F, 1,
423 SOC_DOUBLE_R_TLV("ASP-ASP Volume",
424 CS42L73_ASPAASPAA, CS42L73_ASPBASPBA, 0, 0x3F, 1,
426 SOC_DOUBLE_R_TLV("ASP-VSP Volume",
427 CS42L73_ASPAVSPMA, CS42L73_ASPBVSPMA, 0, 0x3F, 1,
430 SOC_DOUBLE_R_TLV("VSP-IP Volume",
431 CS42L73_VSPAIPAA, CS42L73_VSPBIPBA, 0, 0x3F, 1,
433 SOC_DOUBLE_R_TLV("VSP-XSP Volume",
434 CS42L73_VSPAXSPAA, CS42L73_VSPBXSPBA, 0, 0x3F, 1,
436 SOC_DOUBLE_R_TLV("VSP-ASP Volume",
437 CS42L73_VSPAASPAA, CS42L73_VSPBASPBA, 0, 0x3F, 1,
439 SOC_DOUBLE_R_TLV("VSP-VSP Volume",
440 CS42L73_VSPAVSPMA, CS42L73_VSPBVSPMA, 0, 0x3F, 1,
443 SOC_DOUBLE_R_TLV("HL-IP Volume",
444 CS42L73_HLAIPAA, CS42L73_HLBIPBA, 0, 0x3F, 1,
446 SOC_DOUBLE_R_TLV("HL-XSP Volume",
447 CS42L73_HLAXSPAA, CS42L73_HLBXSPBA, 0, 0x3F, 1,
449 SOC_DOUBLE_R_TLV("HL-ASP Volume",
450 CS42L73_HLAASPAA, CS42L73_HLBASPBA, 0, 0x3F, 1,
452 SOC_DOUBLE_R_TLV("HL-VSP Volume",
453 CS42L73_HLAVSPMA, CS42L73_HLBVSPMA, 0, 0x3F, 1,
456 SOC_SINGLE_TLV("SPK-IP Mono Volume",
457 CS42L73_SPKMIPMA, 0, 0x3F, 1, attn_tlv),
458 SOC_SINGLE_TLV("SPK-XSP Mono Volume",
459 CS42L73_SPKMXSPA, 0, 0x3F, 1, attn_tlv),
460 SOC_SINGLE_TLV("SPK-ASP Mono Volume",
461 CS42L73_SPKMASPA, 0, 0x3F, 1, attn_tlv),
462 SOC_SINGLE_TLV("SPK-VSP Mono Volume",
463 CS42L73_SPKMVSPMA, 0, 0x3F, 1, attn_tlv),
465 SOC_SINGLE_TLV("ESL-IP Mono Volume",
466 CS42L73_ESLMIPMA, 0, 0x3F, 1, attn_tlv),
467 SOC_SINGLE_TLV("ESL-XSP Mono Volume",
468 CS42L73_ESLMXSPA, 0, 0x3F, 1, attn_tlv),
469 SOC_SINGLE_TLV("ESL-ASP Mono Volume",
470 CS42L73_ESLMASPA, 0, 0x3F, 1, attn_tlv),
471 SOC_SINGLE_TLV("ESL-VSP Mono Volume",
472 CS42L73_ESLMVSPMA, 0, 0x3F, 1, attn_tlv),
474 SOC_ENUM("IP Digital Swap/Mono Select", ip_swap_enum),
476 SOC_ENUM("VSPOUT Mono/Stereo Select", vsp_output_mux_enum),
477 SOC_ENUM("XSPOUT Mono/Stereo Select", xsp_output_mux_enum),
480 static int cs42l73_spklo_spk_amp_event(struct snd_soc_dapm_widget *w,
481 struct snd_kcontrol *kcontrol, int event)
483 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
484 struct cs42l73_private *priv = snd_soc_component_get_drvdata(component);
486 case SND_SOC_DAPM_POST_PMD:
487 /* 150 ms delay between setting PDN and MCLKDIS */
488 priv->shutdwn_delay = 150;
491 pr_err("Invalid event = 0x%x\n", event);
496 static int cs42l73_ear_amp_event(struct snd_soc_dapm_widget *w,
497 struct snd_kcontrol *kcontrol, int event)
499 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
500 struct cs42l73_private *priv = snd_soc_component_get_drvdata(component);
502 case SND_SOC_DAPM_POST_PMD:
503 /* 50 ms delay between setting PDN and MCLKDIS */
504 if (priv->shutdwn_delay < 50)
505 priv->shutdwn_delay = 50;
508 pr_err("Invalid event = 0x%x\n", event);
514 static int cs42l73_hp_amp_event(struct snd_soc_dapm_widget *w,
515 struct snd_kcontrol *kcontrol, int event)
517 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
518 struct cs42l73_private *priv = snd_soc_component_get_drvdata(component);
520 case SND_SOC_DAPM_POST_PMD:
521 /* 30 ms delay between setting PDN and MCLKDIS */
522 if (priv->shutdwn_delay < 30)
523 priv->shutdwn_delay = 30;
526 pr_err("Invalid event = 0x%x\n", event);
531 static const struct snd_soc_dapm_widget cs42l73_dapm_widgets[] = {
532 SND_SOC_DAPM_INPUT("DMICA"),
533 SND_SOC_DAPM_INPUT("DMICB"),
534 SND_SOC_DAPM_INPUT("LINEINA"),
535 SND_SOC_DAPM_INPUT("LINEINB"),
536 SND_SOC_DAPM_INPUT("MIC1"),
537 SND_SOC_DAPM_SUPPLY("MIC1 Bias", CS42L73_PWRCTL2, 6, 1, NULL, 0),
538 SND_SOC_DAPM_INPUT("MIC2"),
539 SND_SOC_DAPM_SUPPLY("MIC2 Bias", CS42L73_PWRCTL2, 7, 1, NULL, 0),
541 SND_SOC_DAPM_AIF_OUT("XSPOUTL", NULL, 0,
542 CS42L73_PWRCTL2, 1, 1),
543 SND_SOC_DAPM_AIF_OUT("XSPOUTR", NULL, 0,
544 CS42L73_PWRCTL2, 1, 1),
545 SND_SOC_DAPM_AIF_OUT("ASPOUTL", NULL, 0,
546 CS42L73_PWRCTL2, 3, 1),
547 SND_SOC_DAPM_AIF_OUT("ASPOUTR", NULL, 0,
548 CS42L73_PWRCTL2, 3, 1),
549 SND_SOC_DAPM_AIF_OUT("VSPINOUT", NULL, 0,
550 CS42L73_PWRCTL2, 4, 1),
552 SND_SOC_DAPM_PGA("PGA Left", SND_SOC_NOPM, 0, 0, NULL, 0),
553 SND_SOC_DAPM_PGA("PGA Right", SND_SOC_NOPM, 0, 0, NULL, 0),
555 SND_SOC_DAPM_MUX("PGA Left Mux", SND_SOC_NOPM, 0, 0, &pgaa_mux),
556 SND_SOC_DAPM_MUX("PGA Right Mux", SND_SOC_NOPM, 0, 0, &pgab_mux),
558 SND_SOC_DAPM_ADC("ADC Left", NULL, CS42L73_PWRCTL1, 7, 1),
559 SND_SOC_DAPM_ADC("ADC Right", NULL, CS42L73_PWRCTL1, 5, 1),
560 SND_SOC_DAPM_ADC("DMIC Left", NULL, CS42L73_PWRCTL1, 6, 1),
561 SND_SOC_DAPM_ADC("DMIC Right", NULL, CS42L73_PWRCTL1, 4, 1),
563 SND_SOC_DAPM_MIXER_NAMED_CTL("Input Left Capture", SND_SOC_NOPM,
564 0, 0, input_left_mixer,
565 ARRAY_SIZE(input_left_mixer)),
567 SND_SOC_DAPM_MIXER_NAMED_CTL("Input Right Capture", SND_SOC_NOPM,
568 0, 0, input_right_mixer,
569 ARRAY_SIZE(input_right_mixer)),
571 SND_SOC_DAPM_MIXER("ASPL Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
572 SND_SOC_DAPM_MIXER("ASPR Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
573 SND_SOC_DAPM_MIXER("XSPL Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
574 SND_SOC_DAPM_MIXER("XSPR Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
575 SND_SOC_DAPM_MIXER("VSP Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
577 SND_SOC_DAPM_AIF_IN("XSPINL", NULL, 0,
578 CS42L73_PWRCTL2, 0, 1),
579 SND_SOC_DAPM_AIF_IN("XSPINR", NULL, 0,
580 CS42L73_PWRCTL2, 0, 1),
581 SND_SOC_DAPM_AIF_IN("XSPINM", NULL, 0,
582 CS42L73_PWRCTL2, 0, 1),
584 SND_SOC_DAPM_AIF_IN("ASPINL", NULL, 0,
585 CS42L73_PWRCTL2, 2, 1),
586 SND_SOC_DAPM_AIF_IN("ASPINR", NULL, 0,
587 CS42L73_PWRCTL2, 2, 1),
588 SND_SOC_DAPM_AIF_IN("ASPINM", NULL, 0,
589 CS42L73_PWRCTL2, 2, 1),
591 SND_SOC_DAPM_AIF_IN("VSPINOUT", NULL, 0,
592 CS42L73_PWRCTL2, 4, 1),
594 SND_SOC_DAPM_MIXER("HL Left Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
595 SND_SOC_DAPM_MIXER("HL Right Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
596 SND_SOC_DAPM_MIXER("SPK Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
597 SND_SOC_DAPM_MIXER("ESL Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
599 SND_SOC_DAPM_MUX("ESL-XSP Mux", SND_SOC_NOPM,
600 0, 0, &esl_xsp_mixer),
602 SND_SOC_DAPM_MUX("ESL-ASP Mux", SND_SOC_NOPM,
603 0, 0, &esl_asp_mixer),
605 SND_SOC_DAPM_MUX("SPK-ASP Mux", SND_SOC_NOPM,
606 0, 0, &spk_asp_mixer),
608 SND_SOC_DAPM_MUX("SPK-XSP Mux", SND_SOC_NOPM,
609 0, 0, &spk_xsp_mixer),
611 SND_SOC_DAPM_PGA("HL Left DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
612 SND_SOC_DAPM_PGA("HL Right DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
613 SND_SOC_DAPM_PGA("SPK DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
614 SND_SOC_DAPM_PGA("ESL DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
616 SND_SOC_DAPM_SWITCH_E("HP Amp", CS42L73_PWRCTL3, 0, 1,
617 &hp_amp_ctl, cs42l73_hp_amp_event,
618 SND_SOC_DAPM_POST_PMD),
619 SND_SOC_DAPM_SWITCH("LO Amp", CS42L73_PWRCTL3, 1, 1,
621 SND_SOC_DAPM_SWITCH_E("SPK Amp", CS42L73_PWRCTL3, 2, 1,
622 &spk_amp_ctl, cs42l73_spklo_spk_amp_event,
623 SND_SOC_DAPM_POST_PMD),
624 SND_SOC_DAPM_SWITCH_E("EAR Amp", CS42L73_PWRCTL3, 3, 1,
625 &ear_amp_ctl, cs42l73_ear_amp_event,
626 SND_SOC_DAPM_POST_PMD),
627 SND_SOC_DAPM_SWITCH_E("SPKLO Amp", CS42L73_PWRCTL3, 4, 1,
628 &spklo_amp_ctl, cs42l73_spklo_spk_amp_event,
629 SND_SOC_DAPM_POST_PMD),
631 SND_SOC_DAPM_OUTPUT("HPOUTA"),
632 SND_SOC_DAPM_OUTPUT("HPOUTB"),
633 SND_SOC_DAPM_OUTPUT("LINEOUTA"),
634 SND_SOC_DAPM_OUTPUT("LINEOUTB"),
635 SND_SOC_DAPM_OUTPUT("EAROUT"),
636 SND_SOC_DAPM_OUTPUT("SPKOUT"),
637 SND_SOC_DAPM_OUTPUT("SPKLINEOUT"),
640 static const struct snd_soc_dapm_route cs42l73_audio_map[] = {
642 /* SPKLO EARSPK Paths */
643 {"EAROUT", NULL, "EAR Amp"},
644 {"SPKLINEOUT", NULL, "SPKLO Amp"},
646 {"EAR Amp", "Switch", "ESL DAC"},
647 {"SPKLO Amp", "Switch", "ESL DAC"},
649 {"ESL DAC", "ESL-ASP Mono Volume", "ESL Mixer"},
650 {"ESL DAC", "ESL-XSP Mono Volume", "ESL Mixer"},
651 {"ESL DAC", "ESL-VSP Mono Volume", "VSPINOUT"},
653 {"ESL DAC", "ESL-IP Mono Volume", "Input Left Capture"},
654 {"ESL DAC", "ESL-IP Mono Volume", "Input Right Capture"},
656 {"ESL Mixer", NULL, "ESL-ASP Mux"},
657 {"ESL Mixer", NULL, "ESL-XSP Mux"},
659 {"ESL-ASP Mux", "Left", "ASPINL"},
660 {"ESL-ASP Mux", "Right", "ASPINR"},
661 {"ESL-ASP Mux", "Mono Mix", "ASPINM"},
663 {"ESL-XSP Mux", "Left", "XSPINL"},
664 {"ESL-XSP Mux", "Right", "XSPINR"},
665 {"ESL-XSP Mux", "Mono Mix", "XSPINM"},
667 /* Speakerphone Paths */
668 {"SPKOUT", NULL, "SPK Amp"},
669 {"SPK Amp", "Switch", "SPK DAC"},
671 {"SPK DAC", "SPK-ASP Mono Volume", "SPK Mixer"},
672 {"SPK DAC", "SPK-XSP Mono Volume", "SPK Mixer"},
673 {"SPK DAC", "SPK-VSP Mono Volume", "VSPINOUT"},
675 {"SPK DAC", "SPK-IP Mono Volume", "Input Left Capture"},
676 {"SPK DAC", "SPK-IP Mono Volume", "Input Right Capture"},
678 {"SPK Mixer", NULL, "SPK-ASP Mux"},
679 {"SPK Mixer", NULL, "SPK-XSP Mux"},
681 {"SPK-ASP Mux", "Left", "ASPINL"},
682 {"SPK-ASP Mux", "Mono Mix", "ASPINM"},
683 {"SPK-ASP Mux", "Right", "ASPINR"},
685 {"SPK-XSP Mux", "Left", "XSPINL"},
686 {"SPK-XSP Mux", "Mono Mix", "XSPINM"},
687 {"SPK-XSP Mux", "Right", "XSPINR"},
689 /* HP LineOUT Paths */
690 {"HPOUTA", NULL, "HP Amp"},
691 {"HPOUTB", NULL, "HP Amp"},
692 {"LINEOUTA", NULL, "LO Amp"},
693 {"LINEOUTB", NULL, "LO Amp"},
695 {"HP Amp", "Switch", "HL Left DAC"},
696 {"HP Amp", "Switch", "HL Right DAC"},
697 {"LO Amp", "Switch", "HL Left DAC"},
698 {"LO Amp", "Switch", "HL Right DAC"},
700 {"HL Left DAC", "HL-XSP Volume", "HL Left Mixer"},
701 {"HL Right DAC", "HL-XSP Volume", "HL Right Mixer"},
702 {"HL Left DAC", "HL-ASP Volume", "HL Left Mixer"},
703 {"HL Right DAC", "HL-ASP Volume", "HL Right Mixer"},
704 {"HL Left DAC", "HL-VSP Volume", "HL Left Mixer"},
705 {"HL Right DAC", "HL-VSP Volume", "HL Right Mixer"},
707 {"HL Left DAC", "HL-IP Volume", "HL Left Mixer"},
708 {"HL Right DAC", "HL-IP Volume", "HL Right Mixer"},
709 {"HL Left Mixer", NULL, "Input Left Capture"},
710 {"HL Right Mixer", NULL, "Input Right Capture"},
712 {"HL Left Mixer", NULL, "ASPINL"},
713 {"HL Right Mixer", NULL, "ASPINR"},
714 {"HL Left Mixer", NULL, "XSPINL"},
715 {"HL Right Mixer", NULL, "XSPINR"},
716 {"HL Left Mixer", NULL, "VSPINOUT"},
717 {"HL Right Mixer", NULL, "VSPINOUT"},
719 {"ASPINL", NULL, "ASP Playback"},
720 {"ASPINM", NULL, "ASP Playback"},
721 {"ASPINR", NULL, "ASP Playback"},
722 {"XSPINL", NULL, "XSP Playback"},
723 {"XSPINM", NULL, "XSP Playback"},
724 {"XSPINR", NULL, "XSP Playback"},
725 {"VSPINOUT", NULL, "VSP Playback"},
728 {"MIC1", NULL, "MIC1 Bias"},
729 {"PGA Left Mux", "Mic 1", "MIC1"},
730 {"MIC2", NULL, "MIC2 Bias"},
731 {"PGA Right Mux", "Mic 2", "MIC2"},
733 {"PGA Left Mux", "Line A", "LINEINA"},
734 {"PGA Right Mux", "Line B", "LINEINB"},
736 {"PGA Left", NULL, "PGA Left Mux"},
737 {"PGA Right", NULL, "PGA Right Mux"},
739 {"ADC Left", NULL, "PGA Left"},
740 {"ADC Right", NULL, "PGA Right"},
741 {"DMIC Left", NULL, "DMICA"},
742 {"DMIC Right", NULL, "DMICB"},
744 {"Input Left Capture", "ADC Left Input", "ADC Left"},
745 {"Input Right Capture", "ADC Right Input", "ADC Right"},
746 {"Input Left Capture", "DMIC Left Input", "DMIC Left"},
747 {"Input Right Capture", "DMIC Right Input", "DMIC Right"},
750 {"ASPL Output Mixer", NULL, "Input Left Capture"},
751 {"ASPR Output Mixer", NULL, "Input Right Capture"},
753 {"ASPOUTL", "ASP-IP Volume", "ASPL Output Mixer"},
754 {"ASPOUTR", "ASP-IP Volume", "ASPR Output Mixer"},
756 /* Auxillary Capture */
757 {"XSPL Output Mixer", NULL, "Input Left Capture"},
758 {"XSPR Output Mixer", NULL, "Input Right Capture"},
760 {"XSPOUTL", "XSP-IP Volume", "XSPL Output Mixer"},
761 {"XSPOUTR", "XSP-IP Volume", "XSPR Output Mixer"},
763 {"XSPOUTL", NULL, "XSPL Output Mixer"},
764 {"XSPOUTR", NULL, "XSPR Output Mixer"},
767 {"VSP Output Mixer", NULL, "Input Left Capture"},
768 {"VSP Output Mixer", NULL, "Input Right Capture"},
770 {"VSPINOUT", "VSP-IP Volume", "VSP Output Mixer"},
772 {"VSPINOUT", NULL, "VSP Output Mixer"},
774 {"ASP Capture", NULL, "ASPOUTL"},
775 {"ASP Capture", NULL, "ASPOUTR"},
776 {"XSP Capture", NULL, "XSPOUTL"},
777 {"XSP Capture", NULL, "XSPOUTR"},
778 {"VSP Capture", NULL, "VSPINOUT"},
781 struct cs42l73_mclk_div {
787 static const struct cs42l73_mclk_div cs42l73_mclk_coeffs[] = {
788 /* MCLK, Sample Rate, xMMCC[5:0] */
789 {5644800, 11025, 0x30},
790 {5644800, 22050, 0x20},
791 {5644800, 44100, 0x10},
793 {6000000, 8000, 0x39},
794 {6000000, 11025, 0x33},
795 {6000000, 12000, 0x31},
796 {6000000, 16000, 0x29},
797 {6000000, 22050, 0x23},
798 {6000000, 24000, 0x21},
799 {6000000, 32000, 0x19},
800 {6000000, 44100, 0x13},
801 {6000000, 48000, 0x11},
803 {6144000, 8000, 0x38},
804 {6144000, 12000, 0x30},
805 {6144000, 16000, 0x28},
806 {6144000, 24000, 0x20},
807 {6144000, 32000, 0x18},
808 {6144000, 48000, 0x10},
810 {6500000, 8000, 0x3C},
811 {6500000, 11025, 0x35},
812 {6500000, 12000, 0x34},
813 {6500000, 16000, 0x2C},
814 {6500000, 22050, 0x25},
815 {6500000, 24000, 0x24},
816 {6500000, 32000, 0x1C},
817 {6500000, 44100, 0x15},
818 {6500000, 48000, 0x14},
820 {6400000, 8000, 0x3E},
821 {6400000, 11025, 0x37},
822 {6400000, 12000, 0x36},
823 {6400000, 16000, 0x2E},
824 {6400000, 22050, 0x27},
825 {6400000, 24000, 0x26},
826 {6400000, 32000, 0x1E},
827 {6400000, 44100, 0x17},
828 {6400000, 48000, 0x16},
831 struct cs42l73_mclkx_div {
837 static const struct cs42l73_mclkx_div cs42l73_mclkx_coeffs[] = {
838 {5644800, 1, 0}, /* 5644800 */
839 {6000000, 1, 0}, /* 6000000 */
840 {6144000, 1, 0}, /* 6144000 */
841 {11289600, 2, 2}, /* 5644800 */
842 {12288000, 2, 2}, /* 6144000 */
843 {12000000, 2, 2}, /* 6000000 */
844 {13000000, 2, 2}, /* 6500000 */
845 {19200000, 3, 3}, /* 6400000 */
846 {24000000, 4, 4}, /* 6000000 */
847 {26000000, 4, 4}, /* 6500000 */
848 {38400000, 6, 5} /* 6400000 */
851 static int cs42l73_get_mclkx_coeff(int mclkx)
855 for (i = 0; i < ARRAY_SIZE(cs42l73_mclkx_coeffs); i++) {
856 if (cs42l73_mclkx_coeffs[i].mclkx == mclkx)
862 static int cs42l73_get_mclk_coeff(int mclk, int srate)
866 for (i = 0; i < ARRAY_SIZE(cs42l73_mclk_coeffs); i++) {
867 if (cs42l73_mclk_coeffs[i].mclk == mclk &&
868 cs42l73_mclk_coeffs[i].srate == srate)
875 static int cs42l73_set_mclk(struct snd_soc_dai *dai, unsigned int freq)
877 struct snd_soc_component *component = dai->component;
878 struct cs42l73_private *priv = snd_soc_component_get_drvdata(component);
885 mclkx_coeff = cs42l73_get_mclkx_coeff(freq);
889 mclk = cs42l73_mclkx_coeffs[mclkx_coeff].mclkx /
890 cs42l73_mclkx_coeffs[mclkx_coeff].ratio;
892 dev_dbg(component->dev, "MCLK%u %u <-> internal MCLK %u\n",
893 priv->mclksel + 1, cs42l73_mclkx_coeffs[mclkx_coeff].mclkx,
896 dmmcc = (priv->mclksel << 4) |
897 (cs42l73_mclkx_coeffs[mclkx_coeff].mclkdiv << 1);
899 snd_soc_component_write(component, CS42L73_DMMCC, dmmcc);
901 priv->sysclk = mclkx_coeff;
907 static int cs42l73_set_sysclk(struct snd_soc_dai *dai,
908 int clk_id, unsigned int freq, int dir)
910 struct snd_soc_component *component = dai->component;
911 struct cs42l73_private *priv = snd_soc_component_get_drvdata(component);
914 case CS42L73_CLKID_MCLK1:
916 case CS42L73_CLKID_MCLK2:
922 if ((cs42l73_set_mclk(dai, freq)) < 0) {
923 dev_err(component->dev, "Unable to set MCLK for dai %s\n",
928 priv->mclksel = clk_id;
933 static int cs42l73_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
935 struct snd_soc_component *component = codec_dai->component;
936 struct cs42l73_private *priv = snd_soc_component_get_drvdata(component);
937 u8 id = codec_dai->id;
938 unsigned int inv, format;
941 spc = snd_soc_component_read(component, CS42L73_SPC(id));
942 mmcc = snd_soc_component_read(component, CS42L73_MMCC(id));
944 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
945 case SND_SOC_DAIFMT_CBM_CFM:
946 mmcc |= CS42L73_MS_MASTER;
949 case SND_SOC_DAIFMT_CBS_CFS:
950 mmcc &= ~CS42L73_MS_MASTER;
957 format = (fmt & SND_SOC_DAIFMT_FORMAT_MASK);
958 inv = (fmt & SND_SOC_DAIFMT_INV_MASK);
961 case SND_SOC_DAIFMT_I2S:
962 spc &= ~CS42L73_SPDIF_PCM;
964 case SND_SOC_DAIFMT_DSP_A:
965 case SND_SOC_DAIFMT_DSP_B:
966 if (mmcc & CS42L73_MS_MASTER) {
967 dev_err(component->dev,
968 "PCM format in slave mode only\n");
971 if (id == CS42L73_ASP) {
972 dev_err(component->dev,
973 "PCM format is not supported on ASP port\n");
976 spc |= CS42L73_SPDIF_PCM;
982 if (spc & CS42L73_SPDIF_PCM) {
983 /* Clear PCM mode, clear PCM_BIT_ORDER bit for MSB->LSB */
984 spc &= ~(CS42L73_PCM_MODE_MASK | CS42L73_PCM_BIT_ORDER);
986 case SND_SOC_DAIFMT_DSP_B:
987 if (inv == SND_SOC_DAIFMT_IB_IF)
988 spc |= CS42L73_PCM_MODE0;
989 if (inv == SND_SOC_DAIFMT_IB_NF)
990 spc |= CS42L73_PCM_MODE1;
992 case SND_SOC_DAIFMT_DSP_A:
993 if (inv == SND_SOC_DAIFMT_IB_IF)
994 spc |= CS42L73_PCM_MODE1;
1001 priv->config[id].spc = spc;
1002 priv->config[id].mmcc = mmcc;
1007 static const unsigned int cs42l73_asrc_rates[] = {
1008 8000, 11025, 12000, 16000, 22050,
1009 24000, 32000, 44100, 48000
1012 static unsigned int cs42l73_get_xspfs_coeff(u32 rate)
1015 for (i = 0; i < ARRAY_SIZE(cs42l73_asrc_rates); i++) {
1016 if (cs42l73_asrc_rates[i] == rate)
1019 return 0; /* 0 = Don't know */
1022 static void cs42l73_update_asrc(struct snd_soc_component *component, int id, int srate)
1027 spfs = cs42l73_get_xspfs_coeff(srate);
1031 snd_soc_component_update_bits(component, CS42L73_VXSPFS, 0x0f, spfs);
1034 snd_soc_component_update_bits(component, CS42L73_ASPC, 0x3c, spfs << 2);
1037 snd_soc_component_update_bits(component, CS42L73_VXSPFS, 0xf0, spfs << 4);
1044 static int cs42l73_pcm_hw_params(struct snd_pcm_substream *substream,
1045 struct snd_pcm_hw_params *params,
1046 struct snd_soc_dai *dai)
1048 struct snd_soc_component *component = dai->component;
1049 struct cs42l73_private *priv = snd_soc_component_get_drvdata(component);
1052 int srate = params_rate(params);
1054 if (priv->config[id].mmcc & CS42L73_MS_MASTER) {
1055 /* CS42L73 Master */
1058 cs42l73_get_mclk_coeff(priv->mclk, srate);
1063 dev_dbg(component->dev,
1064 "DAI[%d]: MCLK %u, srate %u, MMCC[5:0] = %x\n",
1065 id, priv->mclk, srate,
1066 cs42l73_mclk_coeffs[mclk_coeff].mmcc);
1068 priv->config[id].mmcc &= 0xC0;
1069 priv->config[id].mmcc |= cs42l73_mclk_coeffs[mclk_coeff].mmcc;
1070 priv->config[id].spc &= 0xFC;
1071 /* Use SCLK=64*Fs if internal MCLK >= 6.4MHz */
1072 if (priv->mclk >= 6400000)
1073 priv->config[id].spc |= CS42L73_MCK_SCLK_64FS;
1075 priv->config[id].spc |= CS42L73_MCK_SCLK_MCLK;
1078 priv->config[id].spc &= 0xFC;
1079 priv->config[id].spc |= CS42L73_MCK_SCLK_64FS;
1082 priv->config[id].srate = srate;
1084 snd_soc_component_write(component, CS42L73_SPC(id), priv->config[id].spc);
1085 snd_soc_component_write(component, CS42L73_MMCC(id), priv->config[id].mmcc);
1087 cs42l73_update_asrc(component, id, srate);
1092 static int cs42l73_set_bias_level(struct snd_soc_component *component,
1093 enum snd_soc_bias_level level)
1095 struct cs42l73_private *cs42l73 = snd_soc_component_get_drvdata(component);
1098 case SND_SOC_BIAS_ON:
1099 snd_soc_component_update_bits(component, CS42L73_DMMCC, CS42L73_MCLKDIS, 0);
1100 snd_soc_component_update_bits(component, CS42L73_PWRCTL1, CS42L73_PDN, 0);
1103 case SND_SOC_BIAS_PREPARE:
1106 case SND_SOC_BIAS_STANDBY:
1107 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
1108 regcache_cache_only(cs42l73->regmap, false);
1109 regcache_sync(cs42l73->regmap);
1111 snd_soc_component_update_bits(component, CS42L73_PWRCTL1, CS42L73_PDN, 1);
1114 case SND_SOC_BIAS_OFF:
1115 snd_soc_component_update_bits(component, CS42L73_PWRCTL1, CS42L73_PDN, 1);
1116 if (cs42l73->shutdwn_delay > 0) {
1117 mdelay(cs42l73->shutdwn_delay);
1118 cs42l73->shutdwn_delay = 0;
1120 mdelay(15); /* Min amount of time requred to power
1124 snd_soc_component_update_bits(component, CS42L73_DMMCC, CS42L73_MCLKDIS, 1);
1130 static int cs42l73_set_tristate(struct snd_soc_dai *dai, int tristate)
1132 struct snd_soc_component *component = dai->component;
1135 return snd_soc_component_update_bits(component, CS42L73_SPC(id), CS42L73_SP_3ST,
1139 static const struct snd_pcm_hw_constraint_list constraints_12_24 = {
1140 .count = ARRAY_SIZE(cs42l73_asrc_rates),
1141 .list = cs42l73_asrc_rates,
1144 static int cs42l73_pcm_startup(struct snd_pcm_substream *substream,
1145 struct snd_soc_dai *dai)
1147 snd_pcm_hw_constraint_list(substream->runtime, 0,
1148 SNDRV_PCM_HW_PARAM_RATE,
1149 &constraints_12_24);
1154 #define CS42L73_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1155 SNDRV_PCM_FMTBIT_S24_LE)
1157 static const struct snd_soc_dai_ops cs42l73_ops = {
1158 .startup = cs42l73_pcm_startup,
1159 .hw_params = cs42l73_pcm_hw_params,
1160 .set_fmt = cs42l73_set_dai_fmt,
1161 .set_sysclk = cs42l73_set_sysclk,
1162 .set_tristate = cs42l73_set_tristate,
1165 static struct snd_soc_dai_driver cs42l73_dai[] = {
1167 .name = "cs42l73-xsp",
1170 .stream_name = "XSP Playback",
1173 .rates = SNDRV_PCM_RATE_KNOT,
1174 .formats = CS42L73_FORMATS,
1177 .stream_name = "XSP Capture",
1180 .rates = SNDRV_PCM_RATE_KNOT,
1181 .formats = CS42L73_FORMATS,
1183 .ops = &cs42l73_ops,
1184 .symmetric_rates = 1,
1187 .name = "cs42l73-asp",
1190 .stream_name = "ASP Playback",
1193 .rates = SNDRV_PCM_RATE_KNOT,
1194 .formats = CS42L73_FORMATS,
1197 .stream_name = "ASP Capture",
1200 .rates = SNDRV_PCM_RATE_KNOT,
1201 .formats = CS42L73_FORMATS,
1203 .ops = &cs42l73_ops,
1204 .symmetric_rates = 1,
1207 .name = "cs42l73-vsp",
1210 .stream_name = "VSP Playback",
1213 .rates = SNDRV_PCM_RATE_KNOT,
1214 .formats = CS42L73_FORMATS,
1217 .stream_name = "VSP Capture",
1220 .rates = SNDRV_PCM_RATE_KNOT,
1221 .formats = CS42L73_FORMATS,
1223 .ops = &cs42l73_ops,
1224 .symmetric_rates = 1,
1228 static int cs42l73_probe(struct snd_soc_component *component)
1230 struct cs42l73_private *cs42l73 = snd_soc_component_get_drvdata(component);
1232 /* Set Charge Pump Frequency */
1233 if (cs42l73->pdata.chgfreq)
1234 snd_soc_component_update_bits(component, CS42L73_CPFCHC,
1235 CS42L73_CHARGEPUMP_MASK,
1236 cs42l73->pdata.chgfreq << 4);
1238 /* MCLK1 as master clk */
1239 cs42l73->mclksel = CS42L73_CLKID_MCLK1;
1245 static const struct snd_soc_component_driver soc_component_dev_cs42l73 = {
1246 .probe = cs42l73_probe,
1247 .set_bias_level = cs42l73_set_bias_level,
1248 .controls = cs42l73_snd_controls,
1249 .num_controls = ARRAY_SIZE(cs42l73_snd_controls),
1250 .dapm_widgets = cs42l73_dapm_widgets,
1251 .num_dapm_widgets = ARRAY_SIZE(cs42l73_dapm_widgets),
1252 .dapm_routes = cs42l73_audio_map,
1253 .num_dapm_routes = ARRAY_SIZE(cs42l73_audio_map),
1254 .suspend_bias_off = 1,
1256 .use_pmdown_time = 1,
1258 .non_legacy_dai_naming = 1,
1261 static const struct regmap_config cs42l73_regmap = {
1265 .max_register = CS42L73_MAX_REGISTER,
1266 .reg_defaults = cs42l73_reg_defaults,
1267 .num_reg_defaults = ARRAY_SIZE(cs42l73_reg_defaults),
1268 .volatile_reg = cs42l73_volatile_register,
1269 .readable_reg = cs42l73_readable_register,
1270 .cache_type = REGCACHE_RBTREE,
1273 static int cs42l73_i2c_probe(struct i2c_client *i2c_client,
1274 const struct i2c_device_id *id)
1276 struct cs42l73_private *cs42l73;
1277 struct cs42l73_platform_data *pdata = dev_get_platdata(&i2c_client->dev);
1279 unsigned int devid = 0;
1283 cs42l73 = devm_kzalloc(&i2c_client->dev, sizeof(*cs42l73), GFP_KERNEL);
1287 cs42l73->regmap = devm_regmap_init_i2c(i2c_client, &cs42l73_regmap);
1288 if (IS_ERR(cs42l73->regmap)) {
1289 ret = PTR_ERR(cs42l73->regmap);
1290 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret);
1295 cs42l73->pdata = *pdata;
1297 pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata),
1302 if (i2c_client->dev.of_node) {
1303 if (of_property_read_u32(i2c_client->dev.of_node,
1304 "chgfreq", &val32) >= 0)
1305 pdata->chgfreq = val32;
1307 pdata->reset_gpio = of_get_named_gpio(i2c_client->dev.of_node,
1309 cs42l73->pdata = *pdata;
1312 i2c_set_clientdata(i2c_client, cs42l73);
1314 if (cs42l73->pdata.reset_gpio) {
1315 ret = devm_gpio_request_one(&i2c_client->dev,
1316 cs42l73->pdata.reset_gpio,
1317 GPIOF_OUT_INIT_HIGH,
1320 dev_err(&i2c_client->dev, "Failed to request /RST %d: %d\n",
1321 cs42l73->pdata.reset_gpio, ret);
1324 gpio_set_value_cansleep(cs42l73->pdata.reset_gpio, 0);
1325 gpio_set_value_cansleep(cs42l73->pdata.reset_gpio, 1);
1328 /* initialize codec */
1329 ret = regmap_read(cs42l73->regmap, CS42L73_DEVID_AB, ®);
1330 devid = (reg & 0xFF) << 12;
1332 ret = regmap_read(cs42l73->regmap, CS42L73_DEVID_CD, ®);
1333 devid |= (reg & 0xFF) << 4;
1335 ret = regmap_read(cs42l73->regmap, CS42L73_DEVID_E, ®);
1336 devid |= (reg & 0xF0) >> 4;
1338 if (devid != CS42L73_DEVID) {
1340 dev_err(&i2c_client->dev,
1341 "CS42L73 Device ID (%X). Expected %X\n",
1342 devid, CS42L73_DEVID);
1346 ret = regmap_read(cs42l73->regmap, CS42L73_REVID, ®);
1348 dev_err(&i2c_client->dev, "Get Revision ID failed\n");
1352 dev_info(&i2c_client->dev,
1353 "Cirrus Logic CS42L73, Revision: %02X\n", reg & 0xFF);
1355 ret = devm_snd_soc_register_component(&i2c_client->dev,
1356 &soc_component_dev_cs42l73, cs42l73_dai,
1357 ARRAY_SIZE(cs42l73_dai));
1363 static const struct of_device_id cs42l73_of_match[] = {
1364 { .compatible = "cirrus,cs42l73", },
1367 MODULE_DEVICE_TABLE(of, cs42l73_of_match);
1369 static const struct i2c_device_id cs42l73_id[] = {
1374 MODULE_DEVICE_TABLE(i2c, cs42l73_id);
1376 static struct i2c_driver cs42l73_i2c_driver = {
1379 .of_match_table = cs42l73_of_match,
1381 .id_table = cs42l73_id,
1382 .probe = cs42l73_i2c_probe,
1386 module_i2c_driver(cs42l73_i2c_driver);
1388 MODULE_DESCRIPTION("ASoC CS42L73 driver");
1389 MODULE_AUTHOR("Georgi Vlaev, Nucleus Systems Ltd, <joe@nucleusys.com>");
1390 MODULE_AUTHOR("Brian Austin, Cirrus Logic Inc, <brian.austin@cirrus.com>");
1391 MODULE_LICENSE("GPL");