~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/codecs/tda7419.c

Version: ~ [ linux-5.7-rc7 ] ~ [ linux-5.6.14 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.42 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.124 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.181 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.224 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.224 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.84 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp