xref: /openbmc/linux/sound/soc/codecs/tda7419.c (revision 6c33a6f4)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * TDA7419 audio processor driver
4  *
5  * Copyright 2018 Konsulko Group
6  *
7  * Author: Matt Porter <mporter@konsulko.com>
8  */
9 
10 #include <linux/i2c.h>
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/regmap.h>
14 #include <sound/core.h>
15 #include <sound/control.h>
16 #include <sound/soc.h>
17 #include <sound/tlv.h>
18 
19 #define TDA7419_MAIN_SRC_REG		0x00
20 #define TDA7419_LOUDNESS_REG		0x01
21 #define TDA7419_MUTE_CLK_REG		0x02
22 #define TDA7419_VOLUME_REG		0x03
23 #define TDA7419_TREBLE_REG		0x04
24 #define TDA7419_MIDDLE_REG		0x05
25 #define TDA7419_BASS_REG		0x06
26 #define TDA7419_SECOND_SRC_REG		0x07
27 #define TDA7419_SUB_MID_BASS_REG	0x08
28 #define TDA7419_MIXING_GAIN_REG		0x09
29 #define TDA7419_ATTENUATOR_LF_REG	0x0a
30 #define TDA7419_ATTENUATOR_RF_REG	0x0b
31 #define TDA7419_ATTENUATOR_LR_REG	0x0c
32 #define TDA7419_ATTENUATOR_RR_REG	0x0d
33 #define TDA7419_MIXING_LEVEL_REG	0x0e
34 #define TDA7419_ATTENUATOR_SUB_REG	0x0f
35 #define TDA7419_SA_CLK_AC_REG		0x10
36 #define TDA7419_TESTING_REG		0x11
37 
38 #define TDA7419_MAIN_SRC_SEL		0
39 #define TDA7419_MAIN_SRC_GAIN		3
40 #define TDA7419_MAIN_SRC_AUTOZERO	7
41 
42 #define TDA7419_LOUDNESS_ATTEN		0
43 #define TDA7419_LOUDNESS_CENTER_FREQ	4
44 #define TDA7419_LOUDNESS_BOOST		6
45 #define TDA7419_LOUDNESS_SOFT_STEP	7
46 
47 #define TDA7419_VOLUME_SOFT_STEP	7
48 
49 #define TDA7419_SOFT_MUTE		0
50 #define TDA7419_MUTE_INFLUENCE		1
51 #define TDA7419_SOFT_MUTE_TIME		2
52 #define TDA7419_SOFT_STEP_TIME		4
53 #define TDA7419_CLK_FAST_MODE		7
54 
55 #define TDA7419_TREBLE_CENTER_FREQ	5
56 #define TDA7419_REF_OUT_SELECT		7
57 
58 #define TDA7419_MIDDLE_Q_FACTOR		5
59 #define TDA7419_MIDDLE_SOFT_STEP	7
60 
61 #define TDA7419_BASS_Q_FACTOR		5
62 #define TDA7419_BASS_SOFT_STEP		7
63 
64 #define TDA7419_SECOND_SRC_SEL		0
65 #define TDA7419_SECOND_SRC_GAIN		3
66 #define TDA7419_REAR_SPKR_SRC		7
67 
68 #define TDA7419_SUB_CUT_OFF_FREQ	0
69 #define TDA7419_MIDDLE_CENTER_FREQ	2
70 #define TDA7419_BASS_CENTER_FREQ	4
71 #define TDA7419_BASS_DC_MODE		6
72 #define TDA7419_SMOOTHING_FILTER	7
73 
74 #define TDA7419_MIX_LF			0
75 #define TDA7419_MIX_RF			1
76 #define TDA7419_MIX_ENABLE		2
77 #define TDA7419_SUB_ENABLE		3
78 #define TDA7419_HPF_GAIN		4
79 
80 #define TDA7419_SA_Q_FACTOR		0
81 #define TDA7419_RESET_MODE		1
82 #define TDA7419_SA_SOURCE		2
83 #define TDA7419_SA_RUN			3
84 #define TDA7419_RESET			4
85 #define TDA7419_CLK_SOURCE		5
86 #define TDA7419_COUPLING_MODE		6
87 
88 struct tda7419_data {
89 	struct regmap *regmap;
90 };
91 
92 static bool tda7419_readable_reg(struct device *dev, unsigned int reg)
93 {
94 	return false;
95 }
96 
97 static const struct reg_default tda7419_regmap_defaults[] = {
98 	{ TDA7419_MAIN_SRC_REG,	0xfe },
99 	{ TDA7419_LOUDNESS_REG, 0xfe },
100 	{ TDA7419_MUTE_CLK_REG, 0xfe },
101 	{ TDA7419_VOLUME_REG, 0xfe },
102 	{ TDA7419_TREBLE_REG, 0xfe },
103 	{ TDA7419_MIDDLE_REG, 0xfe },
104 	{ TDA7419_BASS_REG, 0xfe },
105 	{ TDA7419_SECOND_SRC_REG, 0xfe },
106 	{ TDA7419_SUB_MID_BASS_REG, 0xfe },
107 	{ TDA7419_MIXING_GAIN_REG, 0xfe },
108 	{ TDA7419_ATTENUATOR_LF_REG, 0xfe },
109 	{ TDA7419_ATTENUATOR_RF_REG, 0xfe },
110 	{ TDA7419_ATTENUATOR_LR_REG, 0xfe },
111 	{ TDA7419_ATTENUATOR_RR_REG, 0xfe },
112 	{ TDA7419_MIXING_LEVEL_REG, 0xfe },
113 	{ TDA7419_ATTENUATOR_SUB_REG, 0xfe },
114 	{ TDA7419_SA_CLK_AC_REG, 0xfe },
115 	{ TDA7419_TESTING_REG, 0xfe },
116 };
117 
118 static const struct regmap_config tda7419_regmap_config = {
119 	.reg_bits = 8,
120 	.val_bits = 8,
121 	.max_register = TDA7419_TESTING_REG,
122 	.cache_type = REGCACHE_RBTREE,
123 	.readable_reg = tda7419_readable_reg,
124 	.reg_defaults = tda7419_regmap_defaults,
125 	.num_reg_defaults = ARRAY_SIZE(tda7419_regmap_defaults),
126 };
127 
128 struct tda7419_vol_control {
129 	int min, max;
130 	unsigned int reg, rreg, mask, thresh;
131 	unsigned int invert:1;
132 };
133 
134 static inline bool tda7419_vol_is_stereo(struct tda7419_vol_control *tvc)
135 {
136 	if (tvc->reg == tvc->rreg)
137 		return false;
138 
139 	return true;
140 }
141 
142 static int tda7419_vol_info(struct snd_kcontrol *kcontrol,
143 	struct snd_ctl_elem_info *uinfo)
144 {
145 	struct tda7419_vol_control *tvc =
146 		(struct tda7419_vol_control *)kcontrol->private_value;
147 
148 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
149 	uinfo->count = tda7419_vol_is_stereo(tvc) ? 2 : 1;
150 	uinfo->value.integer.min = tvc->min;
151 	uinfo->value.integer.max = tvc->max;
152 
153 	return 0;
154 }
155 
156 static inline int tda7419_vol_get_value(int val, unsigned int mask,
157 					int min, int thresh,
158 					unsigned int invert)
159 {
160 	val &= mask;
161 	if (val < thresh) {
162 		if (invert)
163 			val = 0 - val;
164 	} else if (val > thresh) {
165 		if (invert)
166 			val = val - thresh;
167 		else
168 			val = thresh - val;
169 	}
170 
171 	if (val < min)
172 		val = min;
173 
174 	return val;
175 }
176 
177 static int tda7419_vol_get(struct snd_kcontrol *kcontrol,
178 			   struct snd_ctl_elem_value *ucontrol)
179 {
180 	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
181 	struct tda7419_vol_control *tvc =
182 		(struct tda7419_vol_control *)kcontrol->private_value;
183 	unsigned int reg = tvc->reg;
184 	unsigned int rreg = tvc->rreg;
185 	unsigned int mask = tvc->mask;
186 	int min = tvc->min;
187 	int thresh = tvc->thresh;
188 	unsigned int invert = tvc->invert;
189 	int val;
190 	int ret;
191 
192 	ret = snd_soc_component_read(component, reg, &val);
193 	if (ret < 0)
194 		return ret;
195 	ucontrol->value.integer.value[0] =
196 		tda7419_vol_get_value(val, mask, min, thresh, invert);
197 
198 	if (tda7419_vol_is_stereo(tvc)) {
199 		ret = snd_soc_component_read(component, rreg, &val);
200 		if (ret < 0)
201 			return ret;
202 		ucontrol->value.integer.value[1] =
203 			tda7419_vol_get_value(val, mask, min, thresh, invert);
204 	}
205 
206 	return 0;
207 }
208 
209 static inline int tda7419_vol_put_value(int val, int thresh,
210 					unsigned int invert)
211 {
212 	if (val < 0) {
213 		if (invert)
214 			val = abs(val);
215 		else
216 			val = thresh - val;
217 	} else if ((val > 0) && invert) {
218 		val += thresh;
219 	}
220 
221 	return val;
222 }
223 
224 static int tda7419_vol_put(struct snd_kcontrol *kcontrol,
225 			   struct snd_ctl_elem_value *ucontrol)
226 {
227 	struct snd_soc_component *component =
228 		snd_kcontrol_chip(kcontrol);
229 	struct tda7419_vol_control *tvc =
230 		(struct tda7419_vol_control *)kcontrol->private_value;
231 	unsigned int reg = tvc->reg;
232 	unsigned int rreg = tvc->rreg;
233 	unsigned int mask = tvc->mask;
234 	int thresh = tvc->thresh;
235 	unsigned int invert = tvc->invert;
236 	int val;
237 	int ret;
238 
239 	val = tda7419_vol_put_value(ucontrol->value.integer.value[0],
240 				    thresh, invert);
241 	ret = snd_soc_component_update_bits(component, reg,
242 					    mask, val);
243 	if (ret < 0)
244 		return ret;
245 
246 	if (tda7419_vol_is_stereo(tvc)) {
247 		val = tda7419_vol_put_value(ucontrol->value.integer.value[1],
248 					    thresh, invert);
249 		ret = snd_soc_component_update_bits(component, rreg,
250 						    mask, val);
251 	}
252 
253 	return ret;
254 }
255 
256 #define TDA7419_SINGLE_VALUE(xreg, xmask, xmin, xmax, xthresh, xinvert) \
257 	((unsigned long)&(struct tda7419_vol_control) \
258 	{.reg = xreg, .rreg = xreg, .mask = xmask, .min = xmin, \
259 	 .max = xmax, .thresh = xthresh, .invert = xinvert})
260 
261 #define TDA7419_DOUBLE_R_VALUE(xregl, xregr, xmask, xmin, xmax, xthresh, \
262 			       xinvert) \
263 	((unsigned long)&(struct tda7419_vol_control) \
264 	{.reg = xregl, .rreg = xregr, .mask = xmask, .min = xmin, \
265 	 .max = xmax, .thresh = xthresh, .invert = xinvert})
266 
267 #define TDA7419_SINGLE_TLV(xname, xreg, xmask, xmin, xmax, xthresh, \
268 			   xinvert, xtlv_array) \
269 {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
270 	.name = xname, \
271 	.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
272 		SNDRV_CTL_ELEM_ACCESS_READWRITE, \
273 	.tlv.p = (xtlv_array), \
274 	.info = tda7419_vol_info, \
275 	.get = tda7419_vol_get, \
276 	.put = tda7419_vol_put, \
277 	.private_value = TDA7419_SINGLE_VALUE(xreg, xmask, xmin, \
278 					      xmax, xthresh, xinvert), \
279 }
280 
281 #define TDA7419_DOUBLE_R_TLV(xname, xregl, xregr, xmask, xmin, xmax, \
282 			     xthresh, xinvert, xtlv_array) \
283 {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
284 	.name = xname, \
285 	.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
286 		SNDRV_CTL_ELEM_ACCESS_READWRITE, \
287 	.tlv.p = (xtlv_array), \
288 	.info = tda7419_vol_info, \
289 	.get = tda7419_vol_get, \
290 	.put = tda7419_vol_put, \
291 	.private_value = TDA7419_DOUBLE_R_VALUE(xregl, xregr, xmask, \
292 						xmin, xmax, xthresh, \
293 						xinvert), \
294 }
295 
296 static const char * const enum_src_sel[] = {
297 	"QD", "SE1", "SE2", "SE3", "SE", "Mute", "Mute", "Mute"};
298 static SOC_ENUM_SINGLE_DECL(soc_enum_main_src_sel,
299 	TDA7419_MAIN_SRC_REG, TDA7419_MAIN_SRC_SEL, enum_src_sel);
300 static const struct snd_kcontrol_new soc_mux_main_src_sel =
301 	SOC_DAPM_ENUM("Main Source Select", soc_enum_main_src_sel);
302 static DECLARE_TLV_DB_SCALE(tlv_src_gain, 0, 100, 0);
303 static DECLARE_TLV_DB_SCALE(tlv_loudness_atten, -1500, 100, 0);
304 static const char * const enum_loudness_center_freq[] = {
305 	"Flat", "400 Hz", "800 Hz", "2400 Hz"};
306 static SOC_ENUM_SINGLE_DECL(soc_enum_loudness_center_freq,
307 	TDA7419_LOUDNESS_REG, TDA7419_LOUDNESS_CENTER_FREQ,
308 	enum_loudness_center_freq);
309 static const char * const enum_mute_influence[] = {
310 	"Pin and IIC", "IIC"};
311 static SOC_ENUM_SINGLE_DECL(soc_enum_mute_influence,
312 	TDA7419_MUTE_CLK_REG, TDA7419_MUTE_INFLUENCE, enum_mute_influence);
313 static const char * const enum_soft_mute_time[] = {
314 	"0.48 ms", "0.96 ms", "123 ms", "123 ms"};
315 static SOC_ENUM_SINGLE_DECL(soc_enum_soft_mute_time,
316 	TDA7419_MUTE_CLK_REG, TDA7419_SOFT_MUTE_TIME, enum_soft_mute_time);
317 static const char * const enum_soft_step_time[] = {
318 	"0.160 ms", "0.321 ms", "0.642 ms", "1.28 ms",
319 	"2.56 ms", "5.12 ms", "10.24 ms", "20.48 ms"};
320 static SOC_ENUM_SINGLE_DECL(soc_enum_soft_step_time,
321 	TDA7419_MUTE_CLK_REG, TDA7419_SOFT_STEP_TIME, enum_soft_step_time);
322 static DECLARE_TLV_DB_SCALE(tlv_volume, -8000, 100, 1);
323 static const char * const enum_treble_center_freq[] = {
324 	"10.0 kHz", "12.5 kHz", "15.0 kHz", "17.5 kHz"};
325 static DECLARE_TLV_DB_SCALE(tlv_filter, -1500, 100, 0);
326 static SOC_ENUM_SINGLE_DECL(soc_enum_treble_center_freq,
327 	TDA7419_TREBLE_REG, TDA7419_TREBLE_CENTER_FREQ,
328 	enum_treble_center_freq);
329 static const char * const enum_ref_out_select[] = {
330 	"External Vref (4 V)", "Internal Vref (3.3 V)"};
331 static SOC_ENUM_SINGLE_DECL(soc_enum_ref_out_select,
332 	TDA7419_TREBLE_REG, TDA7419_REF_OUT_SELECT, enum_ref_out_select);
333 static const char * const enum_middle_q_factor[] = {
334 	"0.5", "0.75", "1.0", "1.25"};
335 static SOC_ENUM_SINGLE_DECL(soc_enum_middle_q_factor,
336 	TDA7419_MIDDLE_REG, TDA7419_MIDDLE_Q_FACTOR, enum_middle_q_factor);
337 static const char * const enum_bass_q_factor[] = {
338 	"1.0", "1.25", "1.5", "2.0"};
339 static SOC_ENUM_SINGLE_DECL(soc_enum_bass_q_factor,
340 	TDA7419_BASS_REG, TDA7419_BASS_Q_FACTOR, enum_bass_q_factor);
341 static SOC_ENUM_SINGLE_DECL(soc_enum_second_src_sel,
342 	TDA7419_SECOND_SRC_REG, TDA7419_SECOND_SRC_SEL, enum_src_sel);
343 static const struct snd_kcontrol_new soc_mux_second_src_sel =
344 	SOC_DAPM_ENUM("Second Source Select", soc_enum_second_src_sel);
345 static const char * const enum_rear_spkr_src[] = {
346 	"Main", "Second"};
347 static SOC_ENUM_SINGLE_DECL(soc_enum_rear_spkr_src,
348 	TDA7419_SECOND_SRC_REG, TDA7419_REAR_SPKR_SRC, enum_rear_spkr_src);
349 static const struct snd_kcontrol_new soc_mux_rear_spkr_src =
350 	SOC_DAPM_ENUM("Rear Speaker Source", soc_enum_rear_spkr_src);
351 static const char * const enum_sub_cut_off_freq[] = {
352 	"Flat", "80 Hz", "120 Hz", "160 Hz"};
353 static SOC_ENUM_SINGLE_DECL(soc_enum_sub_cut_off_freq,
354 	TDA7419_SUB_MID_BASS_REG, TDA7419_SUB_CUT_OFF_FREQ,
355 	enum_sub_cut_off_freq);
356 static const char * const enum_middle_center_freq[] = {
357 	"500 Hz", "1000 Hz", "1500 Hz", "2500 Hz"};
358 static SOC_ENUM_SINGLE_DECL(soc_enum_middle_center_freq,
359 	TDA7419_SUB_MID_BASS_REG, TDA7419_MIDDLE_CENTER_FREQ,
360 	enum_middle_center_freq);
361 static const char * const enum_bass_center_freq[] = {
362 	"60 Hz", "80 Hz", "100 Hz", "200 Hz"};
363 static SOC_ENUM_SINGLE_DECL(soc_enum_bass_center_freq,
364 	TDA7419_SUB_MID_BASS_REG, TDA7419_BASS_CENTER_FREQ,
365 	enum_bass_center_freq);
366 static const char * const enum_sa_q_factor[] = {
367 	"3.5", "1.75" };
368 static SOC_ENUM_SINGLE_DECL(soc_enum_sa_q_factor,
369 	TDA7419_SA_CLK_AC_REG, TDA7419_SA_Q_FACTOR, enum_sa_q_factor);
370 static const char * const enum_reset_mode[] = {
371 	"IIC", "Auto" };
372 static SOC_ENUM_SINGLE_DECL(soc_enum_reset_mode,
373 	TDA7419_SA_CLK_AC_REG, TDA7419_RESET_MODE, enum_reset_mode);
374 static const char * const enum_sa_src[] = {
375 	"Bass", "In Gain" };
376 static SOC_ENUM_SINGLE_DECL(soc_enum_sa_src,
377 	TDA7419_SA_CLK_AC_REG, TDA7419_SA_SOURCE, enum_sa_src);
378 static const char * const enum_clk_src[] = {
379 	"Internal", "External" };
380 static SOC_ENUM_SINGLE_DECL(soc_enum_clk_src,
381 	TDA7419_SA_CLK_AC_REG, TDA7419_CLK_SOURCE, enum_clk_src);
382 static const char * const enum_coupling_mode[] = {
383 	"DC Coupling (without HPF)", "AC Coupling after In Gain",
384 	"DC Coupling (with HPF)", "AC Coupling after Bass" };
385 static SOC_ENUM_SINGLE_DECL(soc_enum_coupling_mode,
386 	TDA7419_SA_CLK_AC_REG, TDA7419_COUPLING_MODE, enum_coupling_mode);
387 
388 /* ASoC Controls */
389 static struct snd_kcontrol_new tda7419_controls[] = {
390 SOC_SINGLE_TLV("Main Source Capture Volume", TDA7419_MAIN_SRC_REG,
391 	       TDA7419_MAIN_SRC_GAIN, 15, 0, tlv_src_gain),
392 SOC_SINGLE("Main Source AutoZero Switch", TDA7419_MAIN_SRC_REG,
393 	   TDA7419_MAIN_SRC_AUTOZERO, 1, 1),
394 SOC_SINGLE_TLV("Loudness Playback Volume", TDA7419_LOUDNESS_REG,
395 	       TDA7419_LOUDNESS_ATTEN, 15, 1, tlv_loudness_atten),
396 SOC_ENUM("Loudness Center Frequency", soc_enum_loudness_center_freq),
397 SOC_SINGLE("Loudness High Boost Switch", TDA7419_LOUDNESS_REG,
398 	   TDA7419_LOUDNESS_BOOST, 1, 1),
399 SOC_SINGLE("Loudness Soft Step Switch", TDA7419_LOUDNESS_REG,
400 	   TDA7419_LOUDNESS_SOFT_STEP, 1, 1),
401 SOC_SINGLE("Soft Mute Switch", TDA7419_MUTE_CLK_REG, TDA7419_SOFT_MUTE, 1, 1),
402 SOC_ENUM("Mute Influence", soc_enum_mute_influence),
403 SOC_ENUM("Soft Mute Time", soc_enum_soft_mute_time),
404 SOC_ENUM("Soft Step Time", soc_enum_soft_step_time),
405 SOC_SINGLE("Clock Fast Mode Switch", TDA7419_MUTE_CLK_REG,
406 	   TDA7419_CLK_FAST_MODE, 1, 1),
407 TDA7419_SINGLE_TLV("Master Playback Volume", TDA7419_VOLUME_REG,
408 		   0x7f, -80, 15, 0x10, 0, tlv_volume),
409 SOC_SINGLE("Volume Soft Step Switch", TDA7419_VOLUME_REG,
410 	   TDA7419_VOLUME_SOFT_STEP, 1, 1),
411 TDA7419_SINGLE_TLV("Treble Playback Volume", TDA7419_TREBLE_REG,
412 		   0x1f, -15, 15, 0x10, 1, tlv_filter),
413 SOC_ENUM("Treble Center Frequency", soc_enum_treble_center_freq),
414 SOC_ENUM("Reference Output Select", soc_enum_ref_out_select),
415 TDA7419_SINGLE_TLV("Middle Playback Volume", TDA7419_MIDDLE_REG,
416 		   0x1f, -15, 15, 0x10, 1, tlv_filter),
417 SOC_ENUM("Middle Q Factor", soc_enum_middle_q_factor),
418 SOC_SINGLE("Middle Soft Step Switch", TDA7419_MIDDLE_REG,
419 	   TDA7419_MIDDLE_SOFT_STEP, 1, 1),
420 TDA7419_SINGLE_TLV("Bass Playback Volume", TDA7419_BASS_REG,
421 		   0x1f, -15, 15, 0x10, 1, tlv_filter),
422 SOC_ENUM("Bass Q Factor", soc_enum_bass_q_factor),
423 SOC_SINGLE("Bass Soft Step Switch", TDA7419_BASS_REG,
424 	   TDA7419_BASS_SOFT_STEP, 1, 1),
425 SOC_SINGLE_TLV("Second Source Capture Volume", TDA7419_SECOND_SRC_REG,
426 	       TDA7419_SECOND_SRC_GAIN, 15, 0, tlv_src_gain),
427 SOC_ENUM("Subwoofer Cut-off Frequency", soc_enum_sub_cut_off_freq),
428 SOC_ENUM("Middle Center Frequency", soc_enum_middle_center_freq),
429 SOC_ENUM("Bass Center Frequency", soc_enum_bass_center_freq),
430 SOC_SINGLE("Bass DC Mode Switch", TDA7419_SUB_MID_BASS_REG,
431 	   TDA7419_BASS_DC_MODE, 1, 1),
432 SOC_SINGLE("Smoothing Filter Switch", TDA7419_SUB_MID_BASS_REG,
433 	   TDA7419_SMOOTHING_FILTER, 1, 1),
434 TDA7419_DOUBLE_R_TLV("Front Speaker Playback Volume", TDA7419_ATTENUATOR_LF_REG,
435 		     TDA7419_ATTENUATOR_RF_REG, 0x7f, -80, 15, 0x10, 0,
436 		     tlv_volume),
437 SOC_SINGLE("Left Front Soft Step Switch", TDA7419_ATTENUATOR_LF_REG,
438 	   TDA7419_VOLUME_SOFT_STEP, 1, 1),
439 SOC_SINGLE("Right Front Soft Step Switch", TDA7419_ATTENUATOR_RF_REG,
440 	   TDA7419_VOLUME_SOFT_STEP, 1, 1),
441 TDA7419_DOUBLE_R_TLV("Rear Speaker Playback Volume", TDA7419_ATTENUATOR_LR_REG,
442 		     TDA7419_ATTENUATOR_RR_REG, 0x7f, -80, 15, 0x10, 0,
443 		     tlv_volume),
444 SOC_SINGLE("Left Rear Soft Step Switch", TDA7419_ATTENUATOR_LR_REG,
445 	   TDA7419_VOLUME_SOFT_STEP, 1, 1),
446 SOC_SINGLE("Right Rear Soft Step Switch", TDA7419_ATTENUATOR_RR_REG,
447 	   TDA7419_VOLUME_SOFT_STEP, 1, 1),
448 TDA7419_SINGLE_TLV("Mixing Capture Volume", TDA7419_MIXING_LEVEL_REG,
449 		   0x7f, -80, 15, 0x10, 0, tlv_volume),
450 SOC_SINGLE("Mixing Level Soft Step Switch", TDA7419_MIXING_LEVEL_REG,
451 	   TDA7419_VOLUME_SOFT_STEP, 1, 1),
452 TDA7419_SINGLE_TLV("Subwoofer Playback Volume", TDA7419_ATTENUATOR_SUB_REG,
453 		   0x7f, -80, 15, 0x10, 0, tlv_volume),
454 SOC_SINGLE("Subwoofer Soft Step Switch", TDA7419_ATTENUATOR_SUB_REG,
455 	   TDA7419_VOLUME_SOFT_STEP, 1, 1),
456 SOC_ENUM("Spectrum Analyzer Q Factor", soc_enum_sa_q_factor),
457 SOC_ENUM("Spectrum Analyzer Reset Mode", soc_enum_reset_mode),
458 SOC_ENUM("Spectrum Analyzer Source", soc_enum_sa_src),
459 SOC_SINGLE("Spectrum Analyzer Run Switch", TDA7419_SA_CLK_AC_REG,
460 	   TDA7419_SA_RUN, 1, 1),
461 SOC_SINGLE("Spectrum Analyzer Reset Switch", TDA7419_SA_CLK_AC_REG,
462 	   TDA7419_RESET, 1, 1),
463 SOC_ENUM("Clock Source", soc_enum_clk_src),
464 SOC_ENUM("Coupling Mode", soc_enum_coupling_mode),
465 };
466 
467 static const struct snd_kcontrol_new soc_mixer_lf_output_controls[] = {
468 	SOC_DAPM_SINGLE("Mix to LF Speaker Switch",
469 			TDA7419_MIXING_GAIN_REG,
470 			TDA7419_MIX_LF, 1, 1),
471 };
472 
473 static const struct snd_kcontrol_new soc_mixer_rf_output_controls[] = {
474 	SOC_DAPM_SINGLE("Mix to RF Speaker Switch",
475 			TDA7419_MIXING_GAIN_REG,
476 			TDA7419_MIX_RF, 1, 1),
477 };
478 
479 static const struct snd_kcontrol_new soc_mix_enable_switch_controls[] = {
480 	SOC_DAPM_SINGLE("Switch", TDA7419_MIXING_GAIN_REG,
481 			TDA7419_MIX_ENABLE, 1, 1),
482 };
483 
484 static const struct snd_kcontrol_new soc_sub_enable_switch_controls[] = {
485 	SOC_DAPM_SINGLE("Switch", TDA7419_MIXING_GAIN_REG,
486 			TDA7419_MIX_ENABLE, 1, 1),
487 };
488 
489 static const struct snd_soc_dapm_widget tda7419_dapm_widgets[] = {
490 	SND_SOC_DAPM_INPUT("SE3L"),
491 	SND_SOC_DAPM_INPUT("SE3R"),
492 	SND_SOC_DAPM_INPUT("SE2L"),
493 	SND_SOC_DAPM_INPUT("SE2R"),
494 	SND_SOC_DAPM_INPUT("SE1L"),
495 	SND_SOC_DAPM_INPUT("SE1R"),
496 	SND_SOC_DAPM_INPUT("DIFFL"),
497 	SND_SOC_DAPM_INPUT("DIFFR"),
498 	SND_SOC_DAPM_INPUT("MIX"),
499 
500 	SND_SOC_DAPM_MUX("Main Source Select", SND_SOC_NOPM,
501 			 0, 0, &soc_mux_main_src_sel),
502 	SND_SOC_DAPM_MUX("Second Source Select", SND_SOC_NOPM,
503 			 0, 0, &soc_mux_second_src_sel),
504 	SND_SOC_DAPM_MUX("Rear Speaker Source", SND_SOC_NOPM,
505 			 0, 0, &soc_mux_rear_spkr_src),
506 
507 	SND_SOC_DAPM_SWITCH("Mix Enable", SND_SOC_NOPM,
508 			0, 0, &soc_mix_enable_switch_controls[0]),
509 	SND_SOC_DAPM_MIXER_NAMED_CTL("LF Output Mixer", SND_SOC_NOPM,
510 			0, 0, &soc_mixer_lf_output_controls[0],
511 			ARRAY_SIZE(soc_mixer_lf_output_controls)),
512 	SND_SOC_DAPM_MIXER_NAMED_CTL("RF Output Mixer", SND_SOC_NOPM,
513 			0, 0, &soc_mixer_rf_output_controls[0],
514 			ARRAY_SIZE(soc_mixer_rf_output_controls)),
515 
516 	SND_SOC_DAPM_SWITCH("Subwoofer Enable",
517 			SND_SOC_NOPM, 0, 0,
518 			&soc_sub_enable_switch_controls[0]),
519 
520 	SND_SOC_DAPM_OUTPUT("OUTLF"),
521 	SND_SOC_DAPM_OUTPUT("OUTRF"),
522 	SND_SOC_DAPM_OUTPUT("OUTLR"),
523 	SND_SOC_DAPM_OUTPUT("OUTRR"),
524 	SND_SOC_DAPM_OUTPUT("OUTSW"),
525 };
526 
527 static const struct snd_soc_dapm_route tda7419_dapm_routes[] = {
528 	{"Main Source Select", "SE3", "SE3L"},
529 	{"Main Source Select", "SE3", "SE3R"},
530 	{"Main Source Select", "SE2", "SE2L"},
531 	{"Main Source Select", "SE2", "SE2R"},
532 	{"Main Source Select", "SE1", "SE1L"},
533 	{"Main Source Select", "SE1", "SE1R"},
534 	{"Main Source Select", "SE", "DIFFL"},
535 	{"Main Source Select", "SE", "DIFFR"},
536 	{"Main Source Select", "QD", "DIFFL"},
537 	{"Main Source Select", "QD", "DIFFR"},
538 
539 	{"Second Source Select", "SE3", "SE3L"},
540 	{"Second Source Select", "SE3", "SE3R"},
541 	{"Second Source Select", "SE2", "SE2L"},
542 	{"Second Source Select", "SE2", "SE2R"},
543 	{"Second Source Select", "SE1", "SE1L"},
544 	{"Second Source Select", "SE1", "SE1R"},
545 	{"Second Source Select", "SE", "DIFFL"},
546 	{"Second Source Select", "SE", "DIFFR"},
547 	{"Second Source Select", "QD", "DIFFL"},
548 	{"Second Source Select", "QD", "DIFFR"},
549 
550 	{"Rear Speaker Source", "Main", "Main Source Select"},
551 	{"Rear Speaker Source", "Second", "Second Source Select"},
552 
553 	{"Subwoofer Enable", "Switch", "Main Source Select"},
554 
555 	{"Mix Enable", "Switch", "MIX"},
556 
557 	{"LF Output Mixer", NULL, "Main Source Select"},
558 	{"LF Output Mixer", "Mix to LF Speaker Switch", "Mix Enable"},
559 	{"RF Output Mixer", NULL, "Main Source Select"},
560 	{"RF Output Mixer", "Mix to RF Speaker Switch", "Mix Enable"},
561 
562 	{"OUTLF", NULL, "LF Output Mixer"},
563 	{"OUTRF", NULL, "RF Output Mixer"},
564 	{"OUTLR", NULL, "Rear Speaker Source"},
565 	{"OUTRR", NULL, "Rear Speaker Source"},
566 	{"OUTSW", NULL, "Subwoofer Enable"},
567 };
568 
569 static const struct snd_soc_component_driver tda7419_component_driver = {
570 	.name			= "tda7419",
571 	.controls		= tda7419_controls,
572 	.num_controls		= ARRAY_SIZE(tda7419_controls),
573 	.dapm_widgets		= tda7419_dapm_widgets,
574 	.num_dapm_widgets	= ARRAY_SIZE(tda7419_dapm_widgets),
575 	.dapm_routes		= tda7419_dapm_routes,
576 	.num_dapm_routes	= ARRAY_SIZE(tda7419_dapm_routes),
577 };
578 
579 static int tda7419_probe(struct i2c_client *i2c,
580 			 const struct i2c_device_id *id)
581 {
582 	struct tda7419_data *tda7419;
583 	int i, ret;
584 
585 	tda7419 = devm_kzalloc(&i2c->dev,
586 			       sizeof(struct tda7419_data),
587 			       GFP_KERNEL);
588 	if (tda7419 == NULL)
589 		return -ENOMEM;
590 
591 	i2c_set_clientdata(i2c, tda7419);
592 
593 	tda7419->regmap = devm_regmap_init_i2c(i2c, &tda7419_regmap_config);
594 	if (IS_ERR(tda7419->regmap)) {
595 		ret = PTR_ERR(tda7419->regmap);
596 		dev_err(&i2c->dev, "error initializing regmap: %d\n",
597 				ret);
598 		return ret;
599 	}
600 
601 	/*
602 	 * Reset registers to power-on defaults. The part does not provide a
603 	 * soft-reset function and the registers are not readable. This ensures
604 	 * that the cache matches register contents even if the registers have
605 	 * been previously initialized and not power cycled before probe.
606 	 */
607 	for (i = 0; i < ARRAY_SIZE(tda7419_regmap_defaults); i++)
608 		regmap_write(tda7419->regmap,
609 			     tda7419_regmap_defaults[i].reg,
610 			     tda7419_regmap_defaults[i].def);
611 
612 	ret = devm_snd_soc_register_component(&i2c->dev,
613 		&tda7419_component_driver, NULL, 0);
614 	if (ret < 0) {
615 		dev_err(&i2c->dev, "error registering component: %d\n",
616 				ret);
617 	}
618 
619 	return ret;
620 }
621 
622 static const struct i2c_device_id tda7419_i2c_id[] = {
623 	{ "tda7419", 0 },
624 	{ }
625 };
626 MODULE_DEVICE_TABLE(i2c, tda7419_i2c_id);
627 
628 static const struct of_device_id tda7419_of_match[] = {
629 	{ .compatible = "st,tda7419" },
630 	{ },
631 };
632 
633 static struct i2c_driver tda7419_driver = {
634 	.driver = {
635 		.name   = "tda7419",
636 		.of_match_table = tda7419_of_match,
637 	},
638 	.probe          = tda7419_probe,
639 	.id_table       = tda7419_i2c_id,
640 };
641 
642 module_i2c_driver(tda7419_driver);
643 
644 MODULE_AUTHOR("Matt Porter <mporter@konsulko.com>");
645 MODULE_DESCRIPTION("TDA7419 audio processor driver");
646 MODULE_LICENSE("GPL");
647