1 // SPDX-License-Identifier: GPL-2.0
3 // Driver for the Texas Instruments TAS2562 CODEC
4 // Copyright (C) 2019 Texas Instruments Inc.
7 #include <linux/module.h>
8 #include <linux/errno.h>
9 #include <linux/device.h>
10 #include <linux/i2c.h>
11 #include <linux/regmap.h>
12 #include <linux/slab.h>
13 #include <linux/gpio/consumer.h>
14 #include <linux/regulator/consumer.h>
15 #include <linux/delay.h>
17 #include <sound/pcm.h>
18 #include <sound/pcm_params.h>
19 #include <sound/soc.h>
20 #include <sound/soc-dapm.h>
21 #include <sound/tlv.h>
25 #define TAS2562_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |\
26 SNDRV_PCM_FORMAT_S32_LE)
28 /* DVC equation involves floating point math
29 * round(10^(volume in dB/20)*2^30)
30 * so create a lookup table for 2dB step
32 static const unsigned int float_vol_db_lookup
[] = {
33 0x00000d43, 0x000010b2, 0x00001505, 0x00001a67, 0x00002151,
34 0x000029f1, 0x000034cd, 0x00004279, 0x000053af, 0x0000695b,
35 0x0000695b, 0x0000a6fa, 0x0000d236, 0x000108a4, 0x00014d2a,
36 0x0001a36e, 0x00021008, 0x000298c0, 0x000344df, 0x00041d8f,
37 0x00052e5a, 0x000685c8, 0x00083621, 0x000a566d, 0x000d03a7,
38 0x0010624d, 0x0014a050, 0x0019f786, 0x0020b0bc, 0x0029279d,
39 0x0033cf8d, 0x004139d3, 0x00521d50, 0x00676044, 0x0082248a,
40 0x00a3d70a, 0x00ce4328, 0x0103ab3d, 0x0146e75d, 0x019b8c27,
41 0x02061b89, 0x028c423f, 0x03352529, 0x0409c2b0, 0x05156d68,
42 0x080e9f96, 0x0a24b062, 0x0cc509ab, 0x10137987, 0x143d1362,
43 0x197a967f, 0x2013739e, 0x28619ae9, 0x32d64617, 0x40000000
47 struct snd_soc_component
*component
;
48 struct gpio_desc
*sdz_gpio
;
49 struct regmap
*regmap
;
51 struct i2c_client
*client
;
66 static int tas2562_set_samplerate(struct tas2562_data
*tas2562
, int samplerate
)
73 ramp_rate
= TAS2562_TDM_CFG0_RAMPRATE_44_1
;
74 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_7305_8KHZ
;
78 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_7305_8KHZ
;
81 ramp_rate
= TAS2562_TDM_CFG0_RAMPRATE_44_1
;
82 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_14_7_16KHZ
;
86 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_14_7_16KHZ
;
89 ramp_rate
= TAS2562_TDM_CFG0_RAMPRATE_44_1
;
90 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_22_05_24KHZ
;
94 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_22_05_24KHZ
;
97 ramp_rate
= TAS2562_TDM_CFG0_RAMPRATE_44_1
;
98 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_29_4_32KHZ
;
102 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_29_4_32KHZ
;
105 ramp_rate
= TAS2562_TDM_CFG0_RAMPRATE_44_1
;
106 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_44_1_48KHZ
;
110 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_44_1_48KHZ
;
113 ramp_rate
= TAS2562_TDM_CFG0_RAMPRATE_44_1
;
114 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_88_2_96KHZ
;
118 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_88_2_96KHZ
;
121 ramp_rate
= TAS2562_TDM_CFG0_RAMPRATE_44_1
;
122 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_176_4_192KHZ
;
126 samp_rate
= TAS2562_TDM_CFG0_SAMPRATE_176_4_192KHZ
;
129 dev_info(tas2562
->dev
, "%s, unsupported sample rate, %d\n",
130 __func__
, samplerate
);
134 snd_soc_component_update_bits(tas2562
->component
, TAS2562_TDM_CFG0
,
135 TAS2562_TDM_CFG0_RAMPRATE_MASK
, ramp_rate
);
136 snd_soc_component_update_bits(tas2562
->component
, TAS2562_TDM_CFG0
,
137 TAS2562_TDM_CFG0_SAMPRATE_MASK
, samp_rate
);
142 static int tas2562_set_dai_tdm_slot(struct snd_soc_dai
*dai
,
143 unsigned int tx_mask
, unsigned int rx_mask
,
144 int slots
, int slot_width
)
146 struct snd_soc_component
*component
= dai
->component
;
147 struct tas2562_data
*tas2562
= snd_soc_component_get_drvdata(component
);
148 int left_slot
, right_slot
;
153 dev_err(component
->dev
, "tx masks must not be 0\n");
164 left_slot
= __ffs(tx_mask
);
165 tx_mask
&= ~(1 << left_slot
);
167 right_slot
= left_slot
;
169 right_slot
= __ffs(tx_mask
);
173 slots_cfg
= (right_slot
<< TAS2562_RIGHT_SLOT_SHIFT
) | left_slot
;
175 ret
= snd_soc_component_write(component
, TAS2562_TDM_CFG3
, slots_cfg
);
179 switch (slot_width
) {
181 ret
= snd_soc_component_update_bits(component
,
183 TAS2562_TDM_CFG2_RXLEN_MASK
,
184 TAS2562_TDM_CFG2_RXLEN_16B
);
187 ret
= snd_soc_component_update_bits(component
,
189 TAS2562_TDM_CFG2_RXLEN_MASK
,
190 TAS2562_TDM_CFG2_RXLEN_24B
);
193 ret
= snd_soc_component_update_bits(component
,
195 TAS2562_TDM_CFG2_RXLEN_MASK
,
196 TAS2562_TDM_CFG2_RXLEN_32B
);
200 /* Do not change slot width */
203 dev_err(tas2562
->dev
, "slot width not supported");
210 ret
= snd_soc_component_update_bits(component
, TAS2562_TDM_CFG5
,
211 TAS2562_TDM_CFG5_VSNS_SLOT_MASK
,
212 tas2562
->v_sense_slot
);
216 ret
= snd_soc_component_update_bits(component
, TAS2562_TDM_CFG6
,
217 TAS2562_TDM_CFG6_ISNS_SLOT_MASK
,
218 tas2562
->i_sense_slot
);
225 static int tas2562_set_bitwidth(struct tas2562_data
*tas2562
, int bitwidth
)
232 case SNDRV_PCM_FORMAT_S16_LE
:
233 snd_soc_component_update_bits(tas2562
->component
,
235 TAS2562_TDM_CFG2_RXWLEN_MASK
,
236 TAS2562_TDM_CFG2_RXWLEN_16B
);
238 case SNDRV_PCM_FORMAT_S24_LE
:
239 snd_soc_component_update_bits(tas2562
->component
,
241 TAS2562_TDM_CFG2_RXWLEN_MASK
,
242 TAS2562_TDM_CFG2_RXWLEN_24B
);
244 case SNDRV_PCM_FORMAT_S32_LE
:
245 snd_soc_component_update_bits(tas2562
->component
,
247 TAS2562_TDM_CFG2_RXWLEN_MASK
,
248 TAS2562_TDM_CFG2_RXWLEN_32B
);
252 dev_info(tas2562
->dev
, "Unsupported bitwidth format\n");
256 val
= snd_soc_component_read(tas2562
->component
, TAS2562_PWR_CTRL
);
260 if (val
& (1 << TAS2562_VSENSE_POWER_EN
))
263 sense_en
= TAS2562_TDM_CFG5_VSNS_EN
;
265 ret
= snd_soc_component_update_bits(tas2562
->component
, TAS2562_TDM_CFG5
,
266 TAS2562_TDM_CFG5_VSNS_EN
, sense_en
);
270 if (val
& (1 << TAS2562_ISENSE_POWER_EN
))
273 sense_en
= TAS2562_TDM_CFG6_ISNS_EN
;
275 ret
= snd_soc_component_update_bits(tas2562
->component
, TAS2562_TDM_CFG6
,
276 TAS2562_TDM_CFG6_ISNS_EN
, sense_en
);
283 static int tas2562_hw_params(struct snd_pcm_substream
*substream
,
284 struct snd_pcm_hw_params
*params
,
285 struct snd_soc_dai
*dai
)
287 struct snd_soc_component
*component
= dai
->component
;
288 struct tas2562_data
*tas2562
= snd_soc_component_get_drvdata(component
);
291 ret
= tas2562_set_bitwidth(tas2562
, params_format(params
));
293 dev_err(tas2562
->dev
, "set bitwidth failed, %d\n", ret
);
297 ret
= tas2562_set_samplerate(tas2562
, params_rate(params
));
299 dev_err(tas2562
->dev
, "set sample rate failed, %d\n", ret
);
304 static int tas2562_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
306 struct snd_soc_component
*component
= dai
->component
;
307 struct tas2562_data
*tas2562
= snd_soc_component_get_drvdata(component
);
309 u8 tdm_rx_start_slot
= 0;
312 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
313 case SND_SOC_DAIFMT_NB_NF
:
316 case SND_SOC_DAIFMT_IB_NF
:
317 asi_cfg_1
|= TAS2562_TDM_CFG1_RX_FALLING
;
320 dev_err(tas2562
->dev
, "ASI format Inverse is not found\n");
324 ret
= snd_soc_component_update_bits(component
, TAS2562_TDM_CFG1
,
325 TAS2562_TDM_CFG1_RX_EDGE_MASK
,
328 dev_err(tas2562
->dev
, "Failed to set RX edge\n");
331 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
332 case SND_SOC_DAIFMT_LEFT_J
:
333 case SND_SOC_DAIFMT_DSP_B
:
334 tdm_rx_start_slot
= 0;
336 case SND_SOC_DAIFMT_I2S
:
337 case SND_SOC_DAIFMT_DSP_A
:
338 tdm_rx_start_slot
= 1;
341 dev_err(tas2562
->dev
,
342 "DAI Format is not found, fmt=0x%x\n", fmt
);
346 ret
= snd_soc_component_update_bits(component
, TAS2562_TDM_CFG1
,
347 TAS2562_RX_OFF_MASK
, (tdm_rx_start_slot
<< 1));
354 static int tas2562_update_pwr_ctrl(struct tas2562_data
*tas2562
)
356 struct snd_soc_component
*component
= tas2562
->component
;
360 if (tas2562
->dac_powered
)
361 val
= tas2562
->unmuted
?
362 TAS2562_ACTIVE
: TAS2562_MUTE
;
364 val
= TAS2562_SHUTDOWN
;
366 ret
= snd_soc_component_update_bits(component
, TAS2562_PWR_CTRL
,
367 TAS2562_MODE_MASK
, val
);
374 static int tas2562_mute(struct snd_soc_dai
*dai
, int mute
, int direction
)
376 struct tas2562_data
*tas2562
= snd_soc_component_get_drvdata(dai
->component
);
378 tas2562
->unmuted
= !mute
;
379 return tas2562_update_pwr_ctrl(tas2562
);
382 static int tas2562_codec_probe(struct snd_soc_component
*component
)
384 struct tas2562_data
*tas2562
= snd_soc_component_get_drvdata(component
);
386 tas2562
->component
= component
;
388 if (tas2562
->sdz_gpio
)
389 gpiod_set_value_cansleep(tas2562
->sdz_gpio
, 1);
395 static int tas2562_suspend(struct snd_soc_component
*component
)
397 struct tas2562_data
*tas2562
= snd_soc_component_get_drvdata(component
);
399 regcache_cache_only(tas2562
->regmap
, true);
400 regcache_mark_dirty(tas2562
->regmap
);
402 if (tas2562
->sdz_gpio
)
403 gpiod_set_value_cansleep(tas2562
->sdz_gpio
, 0);
408 static int tas2562_resume(struct snd_soc_component
*component
)
410 struct tas2562_data
*tas2562
= snd_soc_component_get_drvdata(component
);
412 if (tas2562
->sdz_gpio
)
413 gpiod_set_value_cansleep(tas2562
->sdz_gpio
, 1);
415 regcache_cache_only(tas2562
->regmap
, false);
417 return regcache_sync(tas2562
->regmap
);
420 #define tas2562_suspend NULL
421 #define tas2562_resume NULL
424 static const char * const tas2562_ASI1_src
[] = {
425 "I2C offset", "Left", "Right", "LeftRightDiv2",
428 static SOC_ENUM_SINGLE_DECL(tas2562_ASI1_src_enum
, TAS2562_TDM_CFG2
, 4,
431 static const struct snd_kcontrol_new tas2562_asi1_mux
=
432 SOC_DAPM_ENUM("ASI1 Source", tas2562_ASI1_src_enum
);
434 static int tas2562_dac_event(struct snd_soc_dapm_widget
*w
,
435 struct snd_kcontrol
*kcontrol
, int event
)
437 struct snd_soc_component
*component
=
438 snd_soc_dapm_to_component(w
->dapm
);
439 struct tas2562_data
*tas2562
= snd_soc_component_get_drvdata(component
);
443 case SND_SOC_DAPM_POST_PMU
:
444 tas2562
->dac_powered
= true;
445 ret
= tas2562_update_pwr_ctrl(tas2562
);
447 case SND_SOC_DAPM_PRE_PMD
:
448 tas2562
->dac_powered
= false;
449 ret
= tas2562_update_pwr_ctrl(tas2562
);
452 dev_err(tas2562
->dev
, "Not supported evevt\n");
459 static int tas2562_volume_control_get(struct snd_kcontrol
*kcontrol
,
460 struct snd_ctl_elem_value
*ucontrol
)
462 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
463 struct tas2562_data
*tas2562
= snd_soc_component_get_drvdata(component
);
465 ucontrol
->value
.integer
.value
[0] = tas2562
->volume_lvl
;
469 static int tas2562_volume_control_put(struct snd_kcontrol
*kcontrol
,
470 struct snd_ctl_elem_value
*ucontrol
)
472 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
473 struct tas2562_data
*tas2562
= snd_soc_component_get_drvdata(component
);
477 reg_val
= float_vol_db_lookup
[ucontrol
->value
.integer
.value
[0]/2];
478 ret
= snd_soc_component_write(component
, TAS2562_DVC_CFG4
,
482 ret
= snd_soc_component_write(component
, TAS2562_DVC_CFG3
,
483 ((reg_val
>> 8) & 0xff));
486 ret
= snd_soc_component_write(component
, TAS2562_DVC_CFG2
,
487 ((reg_val
>> 16) & 0xff));
490 ret
= snd_soc_component_write(component
, TAS2562_DVC_CFG1
,
491 ((reg_val
>> 24) & 0xff));
495 tas2562
->volume_lvl
= ucontrol
->value
.integer
.value
[0];
500 /* Digital Volume Control. From 0 dB to -110 dB in 1 dB steps */
501 static const DECLARE_TLV_DB_SCALE(dvc_tlv
, -11000, 100, 0);
503 static DECLARE_TLV_DB_SCALE(tas2562_dac_tlv
, 850, 50, 0);
505 static const struct snd_kcontrol_new isense_switch
=
506 SOC_DAPM_SINGLE("Switch", TAS2562_PWR_CTRL
, TAS2562_ISENSE_POWER_EN
,
509 static const struct snd_kcontrol_new vsense_switch
=
510 SOC_DAPM_SINGLE("Switch", TAS2562_PWR_CTRL
, TAS2562_VSENSE_POWER_EN
,
513 static const struct snd_kcontrol_new tas2562_snd_controls
[] = {
514 SOC_SINGLE_TLV("Amp Gain Volume", TAS2562_PB_CFG1
, 1, 0x1c, 0,
517 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
518 .name
= "Digital Volume Control",
521 .access
= SNDRV_CTL_ELEM_ACCESS_TLV_READ
| SNDRV_CTL_ELEM_ACCESS_READWRITE
,
522 .info
= snd_soc_info_volsw
,
523 .get
= tas2562_volume_control_get
,
524 .put
= tas2562_volume_control_put
,
525 .private_value
= SOC_SINGLE_VALUE(TAS2562_DVC_CFG1
, 0, 110, 0, 0),
529 static const struct snd_soc_dapm_widget tas2110_dapm_widgets
[] = {
530 SND_SOC_DAPM_AIF_IN("ASI1", "ASI1 Playback", 0, SND_SOC_NOPM
, 0, 0),
531 SND_SOC_DAPM_MUX("ASI1 Sel", SND_SOC_NOPM
, 0, 0, &tas2562_asi1_mux
),
532 SND_SOC_DAPM_DAC_E("DAC", NULL
, SND_SOC_NOPM
, 0, 0, tas2562_dac_event
,
533 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
534 SND_SOC_DAPM_OUTPUT("OUT"),
537 static const struct snd_soc_dapm_route tas2110_audio_map
[] = {
538 {"ASI1 Sel", "I2C offset", "ASI1"},
539 {"ASI1 Sel", "Left", "ASI1"},
540 {"ASI1 Sel", "Right", "ASI1"},
541 {"ASI1 Sel", "LeftRightDiv2", "ASI1"},
542 { "DAC", NULL
, "ASI1 Sel" },
543 { "OUT", NULL
, "DAC" },
546 static const struct snd_soc_component_driver soc_component_dev_tas2110
= {
547 .probe
= tas2562_codec_probe
,
548 .suspend
= tas2562_suspend
,
549 .resume
= tas2562_resume
,
550 .controls
= tas2562_snd_controls
,
551 .num_controls
= ARRAY_SIZE(tas2562_snd_controls
),
552 .dapm_widgets
= tas2110_dapm_widgets
,
553 .num_dapm_widgets
= ARRAY_SIZE(tas2110_dapm_widgets
),
554 .dapm_routes
= tas2110_audio_map
,
555 .num_dapm_routes
= ARRAY_SIZE(tas2110_audio_map
),
557 .use_pmdown_time
= 1,
561 static const struct snd_soc_dapm_widget tas2562_dapm_widgets
[] = {
562 SND_SOC_DAPM_AIF_IN("ASI1", "ASI1 Playback", 0, SND_SOC_NOPM
, 0, 0),
563 SND_SOC_DAPM_MUX("ASI1 Sel", SND_SOC_NOPM
, 0, 0, &tas2562_asi1_mux
),
564 SND_SOC_DAPM_DAC_E("DAC", NULL
, SND_SOC_NOPM
, 0, 0, tas2562_dac_event
,
565 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
566 SND_SOC_DAPM_SWITCH("ISENSE", TAS2562_PWR_CTRL
, 3, 1, &isense_switch
),
567 SND_SOC_DAPM_SWITCH("VSENSE", TAS2562_PWR_CTRL
, 2, 1, &vsense_switch
),
568 SND_SOC_DAPM_SIGGEN("VMON"),
569 SND_SOC_DAPM_SIGGEN("IMON"),
570 SND_SOC_DAPM_OUTPUT("OUT"),
573 static const struct snd_soc_dapm_route tas2562_audio_map
[] = {
574 {"ASI1 Sel", "I2C offset", "ASI1"},
575 {"ASI1 Sel", "Left", "ASI1"},
576 {"ASI1 Sel", "Right", "ASI1"},
577 {"ASI1 Sel", "LeftRightDiv2", "ASI1"},
578 { "DAC", NULL
, "ASI1 Sel" },
579 { "OUT", NULL
, "DAC" },
580 {"ISENSE", "Switch", "IMON"},
581 {"VSENSE", "Switch", "VMON"},
584 static const struct snd_soc_component_driver soc_component_dev_tas2562
= {
585 .probe
= tas2562_codec_probe
,
586 .suspend
= tas2562_suspend
,
587 .resume
= tas2562_resume
,
588 .controls
= tas2562_snd_controls
,
589 .num_controls
= ARRAY_SIZE(tas2562_snd_controls
),
590 .dapm_widgets
= tas2562_dapm_widgets
,
591 .num_dapm_widgets
= ARRAY_SIZE(tas2562_dapm_widgets
),
592 .dapm_routes
= tas2562_audio_map
,
593 .num_dapm_routes
= ARRAY_SIZE(tas2562_audio_map
),
595 .use_pmdown_time
= 1,
599 static const struct snd_soc_dai_ops tas2562_speaker_dai_ops
= {
600 .hw_params
= tas2562_hw_params
,
601 .set_fmt
= tas2562_set_dai_fmt
,
602 .set_tdm_slot
= tas2562_set_dai_tdm_slot
,
603 .mute_stream
= tas2562_mute
,
604 .no_capture_mute
= 1,
607 static struct snd_soc_dai_driver tas2562_dai
[] = {
609 .name
= "tas2562-amplifier",
612 .stream_name
= "ASI1 Playback",
615 .rates
= SNDRV_PCM_RATE_8000_192000
,
616 .formats
= TAS2562_FORMATS
,
619 .stream_name
= "ASI1 Capture",
622 .rates
= SNDRV_PCM_RATE_8000_192000
,
623 .formats
= TAS2562_FORMATS
,
625 .ops
= &tas2562_speaker_dai_ops
,
629 static const struct regmap_range_cfg tas2562_ranges
[] = {
632 .range_max
= 5 * 128,
633 .selector_reg
= TAS2562_PAGE_CTRL
,
634 .selector_mask
= 0xff,
641 static const struct reg_default tas2562_reg_defaults
[] = {
642 { TAS2562_PAGE_CTRL
, 0x00 },
643 { TAS2562_SW_RESET
, 0x00 },
644 { TAS2562_PWR_CTRL
, 0x0e },
645 { TAS2562_PB_CFG1
, 0x20 },
646 { TAS2562_TDM_CFG0
, 0x09 },
647 { TAS2562_TDM_CFG1
, 0x02 },
648 { TAS2562_DVC_CFG1
, 0x40 },
649 { TAS2562_DVC_CFG2
, 0x40 },
650 { TAS2562_DVC_CFG3
, 0x00 },
651 { TAS2562_DVC_CFG4
, 0x00 },
654 static const struct regmap_config tas2562_regmap_config
= {
658 .max_register
= 5 * 128,
659 .cache_type
= REGCACHE_RBTREE
,
660 .reg_defaults
= tas2562_reg_defaults
,
661 .num_reg_defaults
= ARRAY_SIZE(tas2562_reg_defaults
),
662 .ranges
= tas2562_ranges
,
663 .num_ranges
= ARRAY_SIZE(tas2562_ranges
),
666 static int tas2562_parse_dt(struct tas2562_data
*tas2562
)
668 struct device
*dev
= tas2562
->dev
;
671 tas2562
->sdz_gpio
= devm_gpiod_get_optional(dev
, "shutdown", GPIOD_OUT_HIGH
);
672 if (IS_ERR(tas2562
->sdz_gpio
)) {
673 if (PTR_ERR(tas2562
->sdz_gpio
) == -EPROBE_DEFER
)
674 return -EPROBE_DEFER
;
676 tas2562
->sdz_gpio
= NULL
;
680 * The shut-down property is deprecated but needs to be checked for
681 * backwards compatibility.
683 if (tas2562
->sdz_gpio
== NULL
) {
684 tas2562
->sdz_gpio
= devm_gpiod_get_optional(dev
, "shut-down",
686 if (IS_ERR(tas2562
->sdz_gpio
))
687 if (PTR_ERR(tas2562
->sdz_gpio
) == -EPROBE_DEFER
)
688 return -EPROBE_DEFER
;
690 tas2562
->sdz_gpio
= NULL
;
693 if (tas2562
->model_id
== TAS2110
)
696 ret
= fwnode_property_read_u32(dev
->fwnode
, "ti,imon-slot-no",
697 &tas2562
->i_sense_slot
);
699 dev_err(dev
, "Property %s is missing setting default slot\n",
701 tas2562
->i_sense_slot
= 0;
705 ret
= fwnode_property_read_u32(dev
->fwnode
, "ti,vmon-slot-no",
706 &tas2562
->v_sense_slot
);
708 dev_info(dev
, "Property %s is missing setting default slot\n",
710 tas2562
->v_sense_slot
= 2;
713 if (tas2562
->v_sense_slot
< tas2562
->i_sense_slot
) {
714 dev_err(dev
, "Vsense slot must be greater than Isense slot\n");
721 static const struct i2c_device_id tas2562_id
[] = {
722 { "tas2562", TAS2562
},
723 { "tas2564", TAS2564
},
724 { "tas2110", TAS2110
},
727 MODULE_DEVICE_TABLE(i2c
, tas2562_id
);
729 static int tas2562_probe(struct i2c_client
*client
)
731 struct device
*dev
= &client
->dev
;
732 struct tas2562_data
*data
;
734 const struct i2c_device_id
*id
;
736 data
= devm_kzalloc(dev
, sizeof(*data
), GFP_KERNEL
);
740 id
= i2c_match_id(tas2562_id
, client
);
741 data
->client
= client
;
742 data
->dev
= &client
->dev
;
743 data
->model_id
= id
->driver_data
;
745 tas2562_parse_dt(data
);
747 data
->regmap
= devm_regmap_init_i2c(client
, &tas2562_regmap_config
);
748 if (IS_ERR(data
->regmap
)) {
749 ret
= PTR_ERR(data
->regmap
);
750 dev_err(dev
, "failed to allocate register map: %d\n", ret
);
754 dev_set_drvdata(&client
->dev
, data
);
756 if (data
->model_id
== TAS2110
)
757 return devm_snd_soc_register_component(dev
,
758 &soc_component_dev_tas2110
,
760 ARRAY_SIZE(tas2562_dai
));
762 return devm_snd_soc_register_component(dev
, &soc_component_dev_tas2562
,
764 ARRAY_SIZE(tas2562_dai
));
769 static const struct of_device_id tas2562_of_match
[] = {
770 { .compatible
= "ti,tas2562", },
771 { .compatible
= "ti,tas2564", },
772 { .compatible
= "ti,tas2110", },
775 MODULE_DEVICE_TABLE(of
, tas2562_of_match
);
778 static struct i2c_driver tas2562_i2c_driver
= {
781 .of_match_table
= of_match_ptr(tas2562_of_match
),
783 .probe
= tas2562_probe
,
784 .id_table
= tas2562_id
,
787 module_i2c_driver(tas2562_i2c_driver
);
789 MODULE_AUTHOR("Dan Murphy <dmurphy@ti.com>");
790 MODULE_DESCRIPTION("TAS2562 Audio amplifier driver");
791 MODULE_LICENSE("GPL");