aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Dannenberg <dannenberg@ti.com>2017-12-05 10:54:12 -0500
committerMark Brown <broonie@kernel.org>2017-12-06 07:39:50 -0500
commit157b68babe3281222e08c9c58456ca22544f06bc (patch)
tree7e4af158775ca9826353324e0c86e6bd6e60b25b
parent2e662342962863bb6044ad581d7cc03795da4e9d (diff)
ASoC: tas6424: Add support for TAS6424 digital amplifier
The Texas Instruments TAS6424 device is a high-efficiency quad-channel Class-D audio power amplifier. Its digital time division multiplexed (TDM) interface enables up to 2 devices to share the same bus, supporting a total of eight channels from one audio serial port. Signed-off-by: Andreas Dannenberg <dannenberg@ti.com> Signed-off-by: Michael Stecklein <m-stecklein@ti.com> Signed-off-by: Andrew F. Davis <afd@ti.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/codecs/Kconfig8
-rw-r--r--sound/soc/codecs/Makefile2
-rw-r--r--sound/soc/codecs/tas6424.c707
-rw-r--r--sound/soc/codecs/tas6424.h144
4 files changed, 861 insertions, 0 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index a42ddbc93f3d..6c2e0d5426f7 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -148,6 +148,7 @@ config SND_SOC_ALL_CODECS
148 select SND_SOC_TAS5086 if I2C 148 select SND_SOC_TAS5086 if I2C
149 select SND_SOC_TAS571X if I2C 149 select SND_SOC_TAS571X if I2C
150 select SND_SOC_TAS5720 if I2C 150 select SND_SOC_TAS5720 if I2C
151 select SND_SOC_TAS6424 if I2C
151 select SND_SOC_TFA9879 if I2C 152 select SND_SOC_TFA9879 if I2C
152 select SND_SOC_TLV320AIC23_I2C if I2C 153 select SND_SOC_TLV320AIC23_I2C if I2C
153 select SND_SOC_TLV320AIC23_SPI if SPI_MASTER 154 select SND_SOC_TLV320AIC23_SPI if SPI_MASTER
@@ -883,6 +884,13 @@ config SND_SOC_TAS5720
883 Enable support for Texas Instruments TAS5720L/M high-efficiency mono 884 Enable support for Texas Instruments TAS5720L/M high-efficiency mono
884 Class-D audio power amplifiers. 885 Class-D audio power amplifiers.
885 886
887config SND_SOC_TAS6424
888 tristate "Texas Instruments TAS6424 Quad-Channel Audio amplifier"
889 depends on I2C
890 help
891 Enable support for Texas Instruments TAS6424 high-efficiency
892 digital input quad-channel Class-D audio power amplifiers.
893
886config SND_SOC_TFA9879 894config SND_SOC_TFA9879
887 tristate "NXP Semiconductors TFA9879 amplifier" 895 tristate "NXP Semiconductors TFA9879 amplifier"
888 depends on I2C 896 depends on I2C
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 0001069ce2a7..154abd758c30 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -156,6 +156,7 @@ snd-soc-sti-sas-objs := sti-sas.o
156snd-soc-tas5086-objs := tas5086.o 156snd-soc-tas5086-objs := tas5086.o
157snd-soc-tas571x-objs := tas571x.o 157snd-soc-tas571x-objs := tas571x.o
158snd-soc-tas5720-objs := tas5720.o 158snd-soc-tas5720-objs := tas5720.o
159snd-soc-tas6424-objs := tas6424.o
159snd-soc-tfa9879-objs := tfa9879.o 160snd-soc-tfa9879-objs := tfa9879.o
160snd-soc-tlv320aic23-objs := tlv320aic23.o 161snd-soc-tlv320aic23-objs := tlv320aic23.o
161snd-soc-tlv320aic23-i2c-objs := tlv320aic23-i2c.o 162snd-soc-tlv320aic23-i2c-objs := tlv320aic23-i2c.o
@@ -395,6 +396,7 @@ obj-$(CONFIG_SND_SOC_TAS2552) += snd-soc-tas2552.o
395obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o 396obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o
396obj-$(CONFIG_SND_SOC_TAS571X) += snd-soc-tas571x.o 397obj-$(CONFIG_SND_SOC_TAS571X) += snd-soc-tas571x.o
397obj-$(CONFIG_SND_SOC_TAS5720) += snd-soc-tas5720.o 398obj-$(CONFIG_SND_SOC_TAS5720) += snd-soc-tas5720.o
399obj-$(CONFIG_SND_SOC_TAS6424) += snd-soc-tas6424.o
398obj-$(CONFIG_SND_SOC_TFA9879) += snd-soc-tfa9879.o 400obj-$(CONFIG_SND_SOC_TFA9879) += snd-soc-tfa9879.o
399obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o 401obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o
400obj-$(CONFIG_SND_SOC_TLV320AIC23_I2C) += snd-soc-tlv320aic23-i2c.o 402obj-$(CONFIG_SND_SOC_TLV320AIC23_I2C) += snd-soc-tlv320aic23-i2c.o
diff --git a/sound/soc/codecs/tas6424.c b/sound/soc/codecs/tas6424.c
new file mode 100644
index 000000000000..49b87f6e85bf
--- /dev/null
+++ b/sound/soc/codecs/tas6424.c
@@ -0,0 +1,707 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * ALSA SoC Texas Instruments TAS6424 Quad-Channel Audio Amplifier
4 *
5 * Copyright (C) 2016-2017 Texas Instruments Incorporated - http://www.ti.com/
6 * Author: Andreas Dannenberg <dannenberg@ti.com>
7 * Andrew F. Davis <afd@ti.com>
8 */
9
10#include <linux/module.h>
11#include <linux/errno.h>
12#include <linux/device.h>
13#include <linux/i2c.h>
14#include <linux/pm_runtime.h>
15#include <linux/regmap.h>
16#include <linux/slab.h>
17#include <linux/regulator/consumer.h>
18#include <linux/delay.h>
19
20#include <sound/pcm.h>
21#include <sound/pcm_params.h>
22#include <sound/soc.h>
23#include <sound/soc-dapm.h>
24#include <sound/tlv.h>
25
26#include "tas6424.h"
27
28/* Define how often to check (and clear) the fault status register (in ms) */
29#define TAS6424_FAULT_CHECK_INTERVAL 200
30
31static const char * const tas6424_supply_names[] = {
32 "dvdd", /* Digital power supply. Connect to 3.3-V supply. */
33 "vbat", /* Supply used for higher voltage analog circuits. */
34 "pvdd", /* Class-D amp output FETs supply. */
35};
36#define TAS6424_NUM_SUPPLIES ARRAY_SIZE(tas6424_supply_names)
37
38struct tas6424_data {
39 struct device *dev;
40 struct regmap *regmap;
41 struct regulator_bulk_data supplies[TAS6424_NUM_SUPPLIES];
42 struct delayed_work fault_check_work;
43 unsigned int last_fault1;
44 unsigned int last_fault2;
45 unsigned int last_warn;
46};
47
48/*
49 * DAC digital volumes. From -103.5 to 24 dB in 0.5 dB steps. Note that
50 * setting the gain below -100 dB (register value <0x7) is effectively a MUTE
51 * as per device datasheet.
52 */
53static DECLARE_TLV_DB_SCALE(dac_tlv, -10350, 50, 0);
54
55static const struct snd_kcontrol_new tas6424_snd_controls[] = {
56 SOC_SINGLE_TLV("Speaker Driver CH1 Playback Volume",
57 TAS6424_CH1_VOL_CTRL, 0, 0xff, 0, dac_tlv),
58 SOC_SINGLE_TLV("Speaker Driver CH2 Playback Volume",
59 TAS6424_CH2_VOL_CTRL, 0, 0xff, 0, dac_tlv),
60 SOC_SINGLE_TLV("Speaker Driver CH3 Playback Volume",
61 TAS6424_CH3_VOL_CTRL, 0, 0xff, 0, dac_tlv),
62 SOC_SINGLE_TLV("Speaker Driver CH4 Playback Volume",
63 TAS6424_CH4_VOL_CTRL, 0, 0xff, 0, dac_tlv),
64};
65
66static int tas6424_dac_event(struct snd_soc_dapm_widget *w,
67 struct snd_kcontrol *kcontrol, int event)
68{
69 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
70 struct tas6424_data *tas6424 = snd_soc_codec_get_drvdata(codec);
71
72 dev_dbg(codec->dev, "%s() event=0x%0x\n", __func__, event);
73
74 if (event & SND_SOC_DAPM_POST_PMU) {
75 /* Observe codec shutdown-to-active time */
76 msleep(12);
77
78 /* Turn on TAS6424 periodic fault checking/handling */
79 tas6424->last_fault1 = 0;
80 tas6424->last_fault2 = 0;
81 tas6424->last_warn = 0;
82 schedule_delayed_work(&tas6424->fault_check_work,
83 msecs_to_jiffies(TAS6424_FAULT_CHECK_INTERVAL));
84 } else if (event & SND_SOC_DAPM_PRE_PMD) {
85 /* Disable TAS6424 periodic fault checking/handling */
86 cancel_delayed_work_sync(&tas6424->fault_check_work);
87 }
88
89 return 0;
90}
91
92static const struct snd_soc_dapm_widget tas6424_dapm_widgets[] = {
93 SND_SOC_DAPM_AIF_IN("DAC IN", "Playback", 0, SND_SOC_NOPM, 0, 0),
94 SND_SOC_DAPM_DAC_E("DAC", NULL, SND_SOC_NOPM, 0, 0, tas6424_dac_event,
95 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
96 SND_SOC_DAPM_OUTPUT("OUT")
97};
98
99static const struct snd_soc_dapm_route tas6424_audio_map[] = {
100 { "DAC", NULL, "DAC IN" },
101 { "OUT", NULL, "DAC" },
102};
103
104static int tas6424_hw_params(struct snd_pcm_substream *substream,
105 struct snd_pcm_hw_params *params,
106 struct snd_soc_dai *dai)
107{
108 struct snd_soc_codec *codec = dai->codec;
109 unsigned int rate = params_rate(params);
110 unsigned int width = params_width(params);
111 u8 sap_ctrl = 0;
112
113 dev_dbg(codec->dev, "%s() rate=%u width=%u\n", __func__, rate, width);
114
115 switch (rate) {
116 case 44100:
117 sap_ctrl |= TAS6424_SAP_RATE_44100;
118 break;
119 case 48000:
120 sap_ctrl |= TAS6424_SAP_RATE_48000;
121 break;
122 case 96000:
123 sap_ctrl |= TAS6424_SAP_RATE_96000;
124 break;
125 default:
126 dev_err(codec->dev, "unsupported sample rate: %u\n", rate);
127 return -EINVAL;
128 }
129
130 switch (width) {
131 case 16:
132 sap_ctrl |= TAS6424_SAP_TDM_SLOT_SZ_16;
133 break;
134 case 24:
135 break;
136 default:
137 dev_err(codec->dev, "unsupported sample width: %u\n", width);
138 return -EINVAL;
139 }
140
141 snd_soc_update_bits(codec, TAS6424_SAP_CTRL,
142 TAS6424_SAP_RATE_MASK |
143 TAS6424_SAP_TDM_SLOT_SZ_16,
144 sap_ctrl);
145
146 return 0;
147}
148
149static int tas6424_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
150{
151 struct snd_soc_codec *codec = dai->codec;
152 u8 serial_format = 0;
153
154 dev_dbg(codec->dev, "%s() fmt=0x%0x\n", __func__, fmt);
155
156 /* clock masters */
157 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
158 case SND_SOC_DAIFMT_CBS_CFS:
159 break;
160 default:
161 dev_err(codec->dev, "Invalid DAI master/slave interface\n");
162 return -EINVAL;
163 }
164
165 /* signal polarity */
166 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
167 case SND_SOC_DAIFMT_NB_NF:
168 break;
169 default:
170 dev_err(codec->dev, "Invalid DAI clock signal polarity\n");
171 return -EINVAL;
172 }
173
174 /* interface format */
175 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
176 case SND_SOC_DAIFMT_I2S:
177 serial_format |= TAS6424_SAP_I2S;
178 break;
179 case SND_SOC_DAIFMT_DSP_A:
180 serial_format |= TAS6424_SAP_DSP;
181 break;
182 case SND_SOC_DAIFMT_DSP_B:
183 /*
184 * We can use the fact that the TAS6424 does not care about the
185 * LRCLK duty cycle during TDM to receive DSP_B formatted data
186 * in LEFTJ mode (no delaying of the 1st data bit).
187 */
188 serial_format |= TAS6424_SAP_LEFTJ;
189 break;
190 case SND_SOC_DAIFMT_LEFT_J:
191 serial_format |= TAS6424_SAP_LEFTJ;
192 break;
193 default:
194 dev_err(codec->dev, "Invalid DAI interface format\n");
195 return -EINVAL;
196 }
197
198 snd_soc_update_bits(codec, TAS6424_SAP_CTRL,
199 TAS6424_SAP_FMT_MASK, serial_format);
200
201 return 0;
202}
203
204static int tas6424_set_dai_tdm_slot(struct snd_soc_dai *dai,
205 unsigned int tx_mask, unsigned int rx_mask,
206 int slots, int slot_width)
207{
208 struct snd_soc_codec *codec = dai->codec;
209 unsigned int first_slot, last_slot;
210 bool sap_tdm_slot_last;
211
212 dev_dbg(codec->dev, "%s() tx_mask=%d rx_mask=%d\n", __func__,
213 tx_mask, rx_mask);
214
215 if (!tx_mask || !rx_mask)
216 return 0; /* nothing needed to disable TDM mode */
217
218 /*
219 * Determine the first slot and last slot that is being requested so
220 * we'll be able to more easily enforce certain constraints as the
221 * TAS6424's TDM interface is not fully configurable.
222 */
223 first_slot = __ffs(tx_mask);
224 last_slot = __fls(rx_mask);
225
226 if (last_slot - first_slot != 4) {
227 dev_err(codec->dev, "tdm mask must cover 4 contiguous slots\n");
228 return -EINVAL;
229 }
230
231 switch (first_slot) {
232 case 0:
233 sap_tdm_slot_last = false;
234 break;
235 case 4:
236 sap_tdm_slot_last = true;
237 break;
238 default:
239 dev_err(codec->dev, "tdm mask must start at slot 0 or 4\n");
240 return -EINVAL;
241 }
242
243 snd_soc_update_bits(codec, TAS6424_SAP_CTRL, TAS6424_SAP_TDM_SLOT_LAST,
244 sap_tdm_slot_last ? TAS6424_SAP_TDM_SLOT_LAST : 0);
245
246 return 0;
247}
248
249static int tas6424_mute(struct snd_soc_dai *dai, int mute)
250{
251 struct snd_soc_codec *codec = dai->codec;
252 unsigned int val;
253
254 dev_dbg(codec->dev, "%s() mute=%d\n", __func__, mute);
255
256 if (mute)
257 val = TAS6424_ALL_STATE_MUTE;
258 else
259 val = TAS6424_ALL_STATE_PLAY;
260
261 snd_soc_write(codec, TAS6424_CH_STATE_CTRL, val);
262
263 return 0;
264}
265
266static int tas6424_power_off(struct snd_soc_codec *codec)
267{
268 struct tas6424_data *tas6424 = snd_soc_codec_get_drvdata(codec);
269 int ret;
270
271 snd_soc_write(codec, TAS6424_CH_STATE_CTRL, TAS6424_ALL_STATE_HIZ);
272
273 regcache_cache_only(tas6424->regmap, true);
274 regcache_mark_dirty(tas6424->regmap);
275
276 ret = regulator_bulk_disable(ARRAY_SIZE(tas6424->supplies),
277 tas6424->supplies);
278 if (ret < 0) {
279 dev_err(codec->dev, "failed to disable supplies: %d\n", ret);
280 return ret;
281 }
282
283 return 0;
284}
285
286static int tas6424_power_on(struct snd_soc_codec *codec)
287{
288 struct tas6424_data *tas6424 = snd_soc_codec_get_drvdata(codec);
289 int ret;
290
291 ret = regulator_bulk_enable(ARRAY_SIZE(tas6424->supplies),
292 tas6424->supplies);
293 if (ret < 0) {
294 dev_err(codec->dev, "failed to enable supplies: %d\n", ret);
295 return ret;
296 }
297
298 regcache_cache_only(tas6424->regmap, false);
299
300 ret = regcache_sync(tas6424->regmap);
301 if (ret < 0) {
302 dev_err(codec->dev, "failed to sync regcache: %d\n", ret);
303 return ret;
304 }
305
306 snd_soc_write(codec, TAS6424_CH_STATE_CTRL, TAS6424_ALL_STATE_MUTE);
307
308 /* any time we come out of HIZ, the output channels automatically run DC
309 * load diagnostics, wait here until this completes
310 */
311 msleep(230);
312
313 return 0;
314}
315
316static int tas6424_set_bias_level(struct snd_soc_codec *codec,
317 enum snd_soc_bias_level level)
318{
319 dev_dbg(codec->dev, "%s() level=%d\n", __func__, level);
320
321 switch (level) {
322 case SND_SOC_BIAS_ON:
323 case SND_SOC_BIAS_PREPARE:
324 break;
325 case SND_SOC_BIAS_STANDBY:
326 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
327 tas6424_power_on(codec);
328 break;
329 case SND_SOC_BIAS_OFF:
330 tas6424_power_off(codec);
331 break;
332 }
333
334 return 0;
335}
336
337static struct snd_soc_codec_driver soc_codec_dev_tas6424 = {
338 .set_bias_level = tas6424_set_bias_level,
339 .idle_bias_off = true,
340
341 .component_driver = {
342 .controls = tas6424_snd_controls,
343 .num_controls = ARRAY_SIZE(tas6424_snd_controls),
344 .dapm_widgets = tas6424_dapm_widgets,
345 .num_dapm_widgets = ARRAY_SIZE(tas6424_dapm_widgets),
346 .dapm_routes = tas6424_audio_map,
347 .num_dapm_routes = ARRAY_SIZE(tas6424_audio_map),
348 },
349};
350
351static struct snd_soc_dai_ops tas6424_speaker_dai_ops = {
352 .hw_params = tas6424_hw_params,
353 .set_fmt = tas6424_set_dai_fmt,
354 .set_tdm_slot = tas6424_set_dai_tdm_slot,
355 .digital_mute = tas6424_mute,
356};
357
358static struct snd_soc_dai_driver tas6424_dai[] = {
359 {
360 .name = "tas6424-amplifier",
361 .playback = {
362 .stream_name = "Playback",
363 .channels_min = 1,
364 .channels_max = 4,
365 .rates = TAS6424_RATES,
366 .formats = TAS6424_FORMATS,
367 },
368 .ops = &tas6424_speaker_dai_ops,
369 },
370};
371
372static void tas6424_fault_check_work(struct work_struct *work)
373{
374 struct tas6424_data *tas6424 = container_of(work, struct tas6424_data,
375 fault_check_work.work);
376 struct device *dev = tas6424->dev;
377 unsigned int reg;
378 int ret;
379
380 ret = regmap_read(tas6424->regmap, TAS6424_GLOB_FAULT1, &reg);
381 if (ret < 0) {
382 dev_err(dev, "failed to read FAULT1 register: %d\n", ret);
383 goto out;
384 }
385
386 /*
387 * Ignore any clock faults as there is no clean way to check for them.
388 * We would need to start checking for those faults *after* the SAIF
389 * stream has been setup, and stop checking *before* the stream is
390 * stopped to avoid any false-positives. However there are no
391 * appropriate hooks to monitor these events.
392 */
393 reg &= TAS6424_FAULT_PVDD_OV |
394 TAS6424_FAULT_VBAT_OV |
395 TAS6424_FAULT_PVDD_UV |
396 TAS6424_FAULT_VBAT_UV;
397
398 if (reg)
399 goto check_global_fault2_reg;
400
401 /*
402 * Only flag errors once for a given occurrence. This is needed as
403 * the TAS6424 will take time clearing the fault condition internally
404 * during which we don't want to bombard the system with the same
405 * error message over and over.
406 */
407 if ((reg & TAS6424_FAULT_PVDD_OV) && !(tas6424->last_fault1 & TAS6424_FAULT_PVDD_OV))
408 dev_crit(dev, "experienced a PVDD overvoltage fault\n");
409
410 if ((reg & TAS6424_FAULT_VBAT_OV) && !(tas6424->last_fault1 & TAS6424_FAULT_VBAT_OV))
411 dev_crit(dev, "experienced a VBAT overvoltage fault\n");
412
413 if ((reg & TAS6424_FAULT_PVDD_UV) && !(tas6424->last_fault1 & TAS6424_FAULT_PVDD_UV))
414 dev_crit(dev, "experienced a PVDD undervoltage fault\n");
415
416 if ((reg & TAS6424_FAULT_VBAT_UV) && !(tas6424->last_fault1 & TAS6424_FAULT_VBAT_UV))
417 dev_crit(dev, "experienced a VBAT undervoltage fault\n");
418
419 /* Store current fault1 value so we can detect any changes next time */
420 tas6424->last_fault1 = reg;
421
422check_global_fault2_reg:
423 ret = regmap_read(tas6424->regmap, TAS6424_GLOB_FAULT2, &reg);
424 if (ret < 0) {
425 dev_err(dev, "failed to read FAULT2 register: %d\n", ret);
426 goto out;
427 }
428
429 reg &= TAS6424_FAULT_OTSD |
430 TAS6424_FAULT_OTSD_CH1 |
431 TAS6424_FAULT_OTSD_CH2 |
432 TAS6424_FAULT_OTSD_CH3 |
433 TAS6424_FAULT_OTSD_CH4;
434
435 if (!reg)
436 goto check_warn_reg;
437
438 if ((reg & TAS6424_FAULT_OTSD) && !(tas6424->last_fault2 & TAS6424_FAULT_OTSD))
439 dev_crit(dev, "experienced a global overtemp shutdown\n");
440
441 if ((reg & TAS6424_FAULT_OTSD_CH1) && !(tas6424->last_fault2 & TAS6424_FAULT_OTSD_CH1))
442 dev_crit(dev, "experienced an overtemp shutdown on CH1\n");
443
444 if ((reg & TAS6424_FAULT_OTSD_CH2) && !(tas6424->last_fault2 & TAS6424_FAULT_OTSD_CH2))
445 dev_crit(dev, "experienced an overtemp shutdown on CH2\n");
446
447 if ((reg & TAS6424_FAULT_OTSD_CH3) && !(tas6424->last_fault2 & TAS6424_FAULT_OTSD_CH3))
448 dev_crit(dev, "experienced an overtemp shutdown on CH3\n");
449
450 if ((reg & TAS6424_FAULT_OTSD_CH4) && !(tas6424->last_fault2 & TAS6424_FAULT_OTSD_CH4))
451 dev_crit(dev, "experienced an overtemp shutdown on CH4\n");
452
453 /* Store current fault2 value so we can detect any changes next time */
454 tas6424->last_fault2 = reg;
455
456check_warn_reg:
457 ret = regmap_read(tas6424->regmap, TAS6424_WARN, &reg);
458 if (ret < 0) {
459 dev_err(dev, "failed to read WARN register: %d\n", ret);
460 goto out;
461 }
462
463 reg &= TAS6424_WARN_VDD_UV |
464 TAS6424_WARN_VDD_POR |
465 TAS6424_WARN_VDD_OTW |
466 TAS6424_WARN_VDD_OTW_CH1 |
467 TAS6424_WARN_VDD_OTW_CH2 |
468 TAS6424_WARN_VDD_OTW_CH3 |
469 TAS6424_WARN_VDD_OTW_CH4;
470
471 if (!reg)
472 goto out;
473
474 if ((reg & TAS6424_WARN_VDD_UV) && !(tas6424->last_warn & TAS6424_WARN_VDD_UV))
475 dev_warn(dev, "experienced a VDD under voltage condition\n");
476
477 if ((reg & TAS6424_WARN_VDD_POR) && !(tas6424->last_warn & TAS6424_WARN_VDD_POR))
478 dev_warn(dev, "experienced a VDD POR condition\n");
479
480 if ((reg & TAS6424_WARN_VDD_OTW) && !(tas6424->last_warn & TAS6424_WARN_VDD_OTW))
481 dev_warn(dev, "experienced a global overtemp warning\n");
482
483 if ((reg & TAS6424_WARN_VDD_OTW_CH1) && !(tas6424->last_warn & TAS6424_WARN_VDD_OTW_CH1))
484 dev_warn(dev, "experienced an overtemp warning on CH1\n");
485
486 if ((reg & TAS6424_WARN_VDD_OTW_CH2) && !(tas6424->last_warn & TAS6424_WARN_VDD_OTW_CH2))
487 dev_warn(dev, "experienced an overtemp warning on CH2\n");
488
489 if ((reg & TAS6424_WARN_VDD_OTW_CH3) && !(tas6424->last_warn & TAS6424_WARN_VDD_OTW_CH3))
490 dev_warn(dev, "experienced an overtemp warning on CH3\n");
491
492 if ((reg & TAS6424_WARN_VDD_OTW_CH4) && !(tas6424->last_warn & TAS6424_WARN_VDD_OTW_CH4))
493 dev_warn(dev, "experienced an overtemp warning on CH4\n");
494
495 /* Store current warn value so we can detect any changes next time */
496 tas6424->last_warn = reg;
497
498 /* Clear any faults by toggling the CLEAR_FAULT control bit */
499 ret = regmap_write_bits(tas6424->regmap, TAS6424_MISC_CTRL3,
500 TAS6424_CLEAR_FAULT, TAS6424_CLEAR_FAULT);
501 if (ret < 0)
502 dev_err(dev, "failed to write MISC_CTRL3 register: %d\n", ret);
503
504 ret = regmap_write_bits(tas6424->regmap, TAS6424_MISC_CTRL3,
505 TAS6424_CLEAR_FAULT, 0);
506 if (ret < 0)
507 dev_err(dev, "failed to write MISC_CTRL3 register: %d\n", ret);
508
509out:
510 /* Schedule the next fault check at the specified interval */
511 schedule_delayed_work(&tas6424->fault_check_work,
512 msecs_to_jiffies(TAS6424_FAULT_CHECK_INTERVAL));
513}
514
515static const struct reg_default tas6424_reg_defaults[] = {
516 { TAS6424_MODE_CTRL, 0x00 },
517 { TAS6424_MISC_CTRL1, 0x32 },
518 { TAS6424_MISC_CTRL2, 0x62 },
519 { TAS6424_SAP_CTRL, 0x04 },
520 { TAS6424_CH_STATE_CTRL, 0x55 },
521 { TAS6424_CH1_VOL_CTRL, 0xcf },
522 { TAS6424_CH2_VOL_CTRL, 0xcf },
523 { TAS6424_CH3_VOL_CTRL, 0xcf },
524 { TAS6424_CH4_VOL_CTRL, 0xcf },
525 { TAS6424_DC_DIAG_CTRL1, 0x00 },
526 { TAS6424_DC_DIAG_CTRL2, 0x11 },
527 { TAS6424_DC_DIAG_CTRL3, 0x11 },
528 { TAS6424_PIN_CTRL, 0xff },
529 { TAS6424_AC_DIAG_CTRL1, 0x00 },
530 { TAS6424_MISC_CTRL3, 0x00 },
531 { TAS6424_CLIP_CTRL, 0x01 },
532 { TAS6424_CLIP_WINDOW, 0x14 },
533 { TAS6424_CLIP_WARN, 0x00 },
534 { TAS6424_CBC_STAT, 0x00 },
535 { TAS6424_MISC_CTRL4, 0x40 },
536};
537
538static bool tas6424_is_writable_reg(struct device *dev, unsigned int reg)
539{
540 switch (reg) {
541 case TAS6424_MODE_CTRL:
542 case TAS6424_MISC_CTRL1:
543 case TAS6424_MISC_CTRL2:
544 case TAS6424_SAP_CTRL:
545 case TAS6424_CH_STATE_CTRL:
546 case TAS6424_CH1_VOL_CTRL:
547 case TAS6424_CH2_VOL_CTRL:
548 case TAS6424_CH3_VOL_CTRL:
549 case TAS6424_CH4_VOL_CTRL:
550 case TAS6424_DC_DIAG_CTRL1:
551 case TAS6424_DC_DIAG_CTRL2:
552 case TAS6424_DC_DIAG_CTRL3:
553 case TAS6424_PIN_CTRL:
554 case TAS6424_AC_DIAG_CTRL1:
555 case TAS6424_MISC_CTRL3:
556 case TAS6424_CLIP_CTRL:
557 case TAS6424_CLIP_WINDOW:
558 case TAS6424_CLIP_WARN:
559 case TAS6424_CBC_STAT:
560 case TAS6424_MISC_CTRL4:
561 return true;
562 default:
563 return false;
564 }
565}
566
567static bool tas6424_is_volatile_reg(struct device *dev, unsigned int reg)
568{
569 switch (reg) {
570 case TAS6424_DC_LOAD_DIAG_REP12:
571 case TAS6424_DC_LOAD_DIAG_REP34:
572 case TAS6424_DC_LOAD_DIAG_REPLO:
573 case TAS6424_CHANNEL_STATE:
574 case TAS6424_CHANNEL_FAULT:
575 case TAS6424_GLOB_FAULT1:
576 case TAS6424_GLOB_FAULT2:
577 case TAS6424_WARN:
578 case TAS6424_AC_LOAD_DIAG_REP1:
579 case TAS6424_AC_LOAD_DIAG_REP2:
580 case TAS6424_AC_LOAD_DIAG_REP3:
581 case TAS6424_AC_LOAD_DIAG_REP4:
582 return true;
583 default:
584 return false;
585 }
586}
587
588static const struct regmap_config tas6424_regmap_config = {
589 .reg_bits = 8,
590 .val_bits = 8,
591
592 .writeable_reg = tas6424_is_writable_reg,
593 .volatile_reg = tas6424_is_volatile_reg,
594
595 .max_register = TAS6424_MAX,
596 .reg_defaults = tas6424_reg_defaults,
597 .num_reg_defaults = ARRAY_SIZE(tas6424_reg_defaults),
598 .cache_type = REGCACHE_RBTREE,
599};
600
601#if IS_ENABLED(CONFIG_OF)
602static const struct of_device_id tas6424_of_ids[] = {
603 { .compatible = "ti,tas6424", },
604 { },
605};
606MODULE_DEVICE_TABLE(of, tas6424_of_ids);
607#endif
608
609static int tas6424_i2c_probe(struct i2c_client *client,
610 const struct i2c_device_id *id)
611{
612 struct device *dev = &client->dev;
613 struct tas6424_data *tas6424;
614 int ret;
615 int i;
616
617 tas6424 = devm_kzalloc(dev, sizeof(*tas6424), GFP_KERNEL);
618 if (!tas6424)
619 return -ENOMEM;
620 dev_set_drvdata(dev, tas6424);
621
622 tas6424->dev = dev;
623
624 tas6424->regmap = devm_regmap_init_i2c(client, &tas6424_regmap_config);
625 if (IS_ERR(tas6424->regmap)) {
626 ret = PTR_ERR(tas6424->regmap);
627 dev_err(dev, "unable to allocate register map: %d\n", ret);
628 return ret;
629 }
630
631 for (i = 0; i < ARRAY_SIZE(tas6424->supplies); i++)
632 tas6424->supplies[i].supply = tas6424_supply_names[i];
633 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(tas6424->supplies),
634 tas6424->supplies);
635 if (ret) {
636 dev_err(dev, "unable to request supplies: %d\n", ret);
637 return ret;
638 }
639
640 ret = regulator_bulk_enable(ARRAY_SIZE(tas6424->supplies),
641 tas6424->supplies);
642 if (ret) {
643 dev_err(dev, "unable to enable supplies: %d\n", ret);
644 return ret;
645 }
646
647 /* Reset device to establish well-defined startup state */
648 ret = regmap_update_bits(tas6424->regmap, TAS6424_MODE_CTRL,
649 TAS6424_RESET, TAS6424_RESET);
650 if (ret) {
651 dev_err(dev, "unable to reset device: %d\n", ret);
652 return ret;
653 }
654
655 INIT_DELAYED_WORK(&tas6424->fault_check_work, tas6424_fault_check_work);
656
657 ret = snd_soc_register_codec(dev, &soc_codec_dev_tas6424,
658 tas6424_dai, ARRAY_SIZE(tas6424_dai));
659 if (ret < 0) {
660 dev_err(dev, "unable to register codec: %d\n", ret);
661 return ret;
662 }
663
664 return 0;
665}
666
667static int tas6424_i2c_remove(struct i2c_client *client)
668{
669 struct device *dev = &client->dev;
670 struct tas6424_data *tas6424 = dev_get_drvdata(dev);
671 int ret;
672
673 snd_soc_unregister_codec(dev);
674
675 cancel_delayed_work_sync(&tas6424->fault_check_work);
676
677 ret = regulator_bulk_disable(ARRAY_SIZE(tas6424->supplies),
678 tas6424->supplies);
679 if (ret < 0) {
680 dev_err(dev, "unable to disable supplies: %d\n", ret);
681 return ret;
682 }
683
684 return 0;
685}
686
687static const struct i2c_device_id tas6424_i2c_ids[] = {
688 { "tas6424", 0 },
689 { }
690};
691MODULE_DEVICE_TABLE(i2c, tas6424_i2c_ids);
692
693static struct i2c_driver tas6424_i2c_driver = {
694 .driver = {
695 .name = "tas6424",
696 .of_match_table = of_match_ptr(tas6424_of_ids),
697 },
698 .probe = tas6424_i2c_probe,
699 .remove = tas6424_i2c_remove,
700 .id_table = tas6424_i2c_ids,
701};
702module_i2c_driver(tas6424_i2c_driver);
703
704MODULE_AUTHOR("Andreas Dannenberg <dannenberg@ti.com>");
705MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
706MODULE_DESCRIPTION("TAS6424 Audio amplifier driver");
707MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/tas6424.h b/sound/soc/codecs/tas6424.h
new file mode 100644
index 000000000000..430588328a06
--- /dev/null
+++ b/sound/soc/codecs/tas6424.h
@@ -0,0 +1,144 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * ALSA SoC Texas Instruments TAS6424 Quad-Channel Audio Amplifier
4 *
5 * Copyright (C) 2016-2017 Texas Instruments Incorporated - http://www.ti.com/
6 * Author: Andreas Dannenberg <dannenberg@ti.com>
7 * Andrew F. Davis <afd@ti.com>
8 */
9
10#ifndef __TAS6424_H__
11#define __TAS6424_H__
12
13#define TAS6424_RATES (SNDRV_PCM_RATE_44100 | \
14 SNDRV_PCM_RATE_48000 | \
15 SNDRV_PCM_RATE_96000)
16
17#define TAS6424_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
18 SNDRV_PCM_FMTBIT_S24_LE)
19
20/* Register Address Map */
21#define TAS6424_MODE_CTRL 0x00
22#define TAS6424_MISC_CTRL1 0x01
23#define TAS6424_MISC_CTRL2 0x02
24#define TAS6424_SAP_CTRL 0x03
25#define TAS6424_CH_STATE_CTRL 0x04
26#define TAS6424_CH1_VOL_CTRL 0x05
27#define TAS6424_CH2_VOL_CTRL 0x06
28#define TAS6424_CH3_VOL_CTRL 0x07
29#define TAS6424_CH4_VOL_CTRL 0x08
30#define TAS6424_DC_DIAG_CTRL1 0x09
31#define TAS6424_DC_DIAG_CTRL2 0x0a
32#define TAS6424_DC_DIAG_CTRL3 0x0b
33#define TAS6424_DC_LOAD_DIAG_REP12 0x0c
34#define TAS6424_DC_LOAD_DIAG_REP34 0x0d
35#define TAS6424_DC_LOAD_DIAG_REPLO 0x0e
36#define TAS6424_CHANNEL_STATE 0x0f
37#define TAS6424_CHANNEL_FAULT 0x10
38#define TAS6424_GLOB_FAULT1 0x11
39#define TAS6424_GLOB_FAULT2 0x12
40#define TAS6424_WARN 0x13
41#define TAS6424_PIN_CTRL 0x14
42#define TAS6424_AC_DIAG_CTRL1 0x15
43#define TAS6424_AC_DIAG_CTRL2 0x16
44#define TAS6424_AC_LOAD_DIAG_REP1 0x17
45#define TAS6424_AC_LOAD_DIAG_REP2 0x18
46#define TAS6424_AC_LOAD_DIAG_REP3 0x19
47#define TAS6424_AC_LOAD_DIAG_REP4 0x1a
48#define TAS6424_MISC_CTRL3 0x21
49#define TAS6424_CLIP_CTRL 0x22
50#define TAS6424_CLIP_WINDOW 0x23
51#define TAS6424_CLIP_WARN 0x24
52#define TAS6424_CBC_STAT 0x25
53#define TAS6424_MISC_CTRL4 0x26
54#define TAS6424_MAX TAS6424_MISC_CTRL4
55
56/* TAS6424_MODE_CTRL_REG */
57#define TAS6424_RESET BIT(7)
58
59/* TAS6424_SAP_CTRL_REG */
60#define TAS6424_SAP_RATE_MASK GENMASK(7, 6)
61#define TAS6424_SAP_RATE_44100 (0x00 << 6)
62#define TAS6424_SAP_RATE_48000 (0x01 << 6)
63#define TAS6424_SAP_RATE_96000 (0x02 << 6)
64#define TAS6424_SAP_TDM_SLOT_LAST BIT(5)
65#define TAS6424_SAP_TDM_SLOT_SZ_16 BIT(4)
66#define TAS6424_SAP_TDM_SLOT_SWAP BIT(3)
67#define TAS6424_SAP_FMT_MASK GENMASK(2, 0)
68#define TAS6424_SAP_RIGHTJ_24 (0x00 << 0)
69#define TAS6424_SAP_RIGHTJ_20 (0x01 << 0)
70#define TAS6424_SAP_RIGHTJ_18 (0x02 << 0)
71#define TAS6424_SAP_RIGHTJ_16 (0x03 << 0)
72#define TAS6424_SAP_I2S (0x04 << 0)
73#define TAS6424_SAP_LEFTJ (0x05 << 0)
74#define TAS6424_SAP_DSP (0x06 << 0)
75
76/* TAS6424_CH_STATE_CTRL_REG */
77#define TAS6424_CH1_STATE_MASK GENMASK(7, 6)
78#define TAS6424_CH1_STATE_PLAY (0x00 << 6)
79#define TAS6424_CH1_STATE_HIZ (0x01 << 6)
80#define TAS6424_CH1_STATE_MUTE (0x02 << 6)
81#define TAS6424_CH1_STATE_DIAG (0x03 << 6)
82#define TAS6424_CH2_STATE_MASK GENMASK(5, 4)
83#define TAS6424_CH2_STATE_PLAY (0x00 << 4)
84#define TAS6424_CH2_STATE_HIZ (0x01 << 4)
85#define TAS6424_CH2_STATE_MUTE (0x02 << 4)
86#define TAS6424_CH2_STATE_DIAG (0x03 << 4)
87#define TAS6424_CH3_STATE_MASK GENMASK(3, 2)
88#define TAS6424_CH3_STATE_PLAY (0x00 << 2)
89#define TAS6424_CH3_STATE_HIZ (0x01 << 2)
90#define TAS6424_CH3_STATE_MUTE (0x02 << 2)
91#define TAS6424_CH3_STATE_DIAG (0x03 << 2)
92#define TAS6424_CH4_STATE_MASK GENMASK(1, 0)
93#define TAS6424_CH4_STATE_PLAY (0x00 << 0)
94#define TAS6424_CH4_STATE_HIZ (0x01 << 0)
95#define TAS6424_CH4_STATE_MUTE (0x02 << 0)
96#define TAS6424_CH4_STATE_DIAG (0x03 << 0)
97#define TAS6424_ALL_STATE_PLAY (TAS6424_CH1_STATE_PLAY | \
98 TAS6424_CH2_STATE_PLAY | \
99 TAS6424_CH3_STATE_PLAY | \
100 TAS6424_CH4_STATE_PLAY)
101#define TAS6424_ALL_STATE_HIZ (TAS6424_CH1_STATE_HIZ | \
102 TAS6424_CH2_STATE_HIZ | \
103 TAS6424_CH3_STATE_HIZ | \
104 TAS6424_CH4_STATE_HIZ)
105#define TAS6424_ALL_STATE_MUTE (TAS6424_CH1_STATE_MUTE | \
106 TAS6424_CH2_STATE_MUTE | \
107 TAS6424_CH3_STATE_MUTE | \
108 TAS6424_CH4_STATE_MUTE)
109#define TAS6424_ALL_STATE_DIAG (TAS6424_CH1_STATE_DIAG | \
110 TAS6424_CH2_STATE_DIAG | \
111 TAS6424_CH3_STATE_DIAG | \
112 TAS6424_CH4_STATE_DIAG)
113
114/* TAS6424_GLOB_FAULT1_REG */
115#define TAS6424_FAULT_CLOCK BIT(4)
116#define TAS6424_FAULT_PVDD_OV BIT(3)
117#define TAS6424_FAULT_VBAT_OV BIT(2)
118#define TAS6424_FAULT_PVDD_UV BIT(1)
119#define TAS6424_FAULT_VBAT_UV BIT(0)
120
121/* TAS6424_GLOB_FAULT2_REG */
122#define TAS6424_FAULT_OTSD BIT(4)
123#define TAS6424_FAULT_OTSD_CH1 BIT(3)
124#define TAS6424_FAULT_OTSD_CH2 BIT(2)
125#define TAS6424_FAULT_OTSD_CH3 BIT(1)
126#define TAS6424_FAULT_OTSD_CH4 BIT(0)
127
128/* TAS6424_WARN_REG */
129#define TAS6424_WARN_VDD_UV BIT(6)
130#define TAS6424_WARN_VDD_POR BIT(5)
131#define TAS6424_WARN_VDD_OTW BIT(4)
132#define TAS6424_WARN_VDD_OTW_CH1 BIT(3)
133#define TAS6424_WARN_VDD_OTW_CH2 BIT(2)
134#define TAS6424_WARN_VDD_OTW_CH3 BIT(1)
135#define TAS6424_WARN_VDD_OTW_CH4 BIT(0)
136
137/* TAS6424_MISC_CTRL3_REG */
138#define TAS6424_CLEAR_FAULT BIT(7)
139#define TAS6424_PBTL_CH_SEL BIT(6)
140#define TAS6424_MASK_CBC_WARN BIT(5)
141#define TAS6424_MASK_VDD_UV BIT(4)
142#define TAS6424_OTSD_AUTO_RECOVERY BIT(3)
143
144#endif /* __TAS6424_H__ */