1 // SPDX-License-Identifier: GPL-2.0
3 // ALSA SoC Texas Instruments TAS2770 20-W Digital Input Mono Class-D
4 // Audio Amplifier with Speaker I/V Sense
6 // Copyright (C) 2016-2017 Texas Instruments Incorporated - http://www.ti.com/
7 // Author: Tracy Yi <tracy-yi@ti.com>
8 // Frank Shi <shifu0704@thundersoft.com>
10 #include <linux/module.h>
11 #include <linux/moduleparam.h>
12 #include <linux/err.h>
13 #include <linux/init.h>
14 #include <linux/delay.h>
16 #include <linux/i2c.h>
17 #include <linux/gpio.h>
18 #include <linux/gpio/consumer.h>
19 #include <linux/pm_runtime.h>
20 #include <linux/regulator/consumer.h>
21 #include <linux/firmware.h>
22 #include <linux/regmap.h>
24 #include <linux/of_gpio.h>
25 #include <linux/slab.h>
26 #include <sound/soc.h>
27 #include <sound/pcm.h>
28 #include <sound/pcm_params.h>
29 #include <sound/initval.h>
30 #include <sound/tlv.h>
34 #define TAS2770_MDELAY 0xFFFFFFFE
36 static void tas2770_reset(struct tas2770_priv
*tas2770
)
38 if (tas2770
->reset_gpio
) {
39 gpiod_set_value_cansleep(tas2770
->reset_gpio
, 0);
41 gpiod_set_value_cansleep(tas2770
->reset_gpio
, 1);
43 snd_soc_component_write(tas2770
->component
, TAS2770_SW_RST
,
47 static int tas2770_set_bias_level(struct snd_soc_component
*component
,
48 enum snd_soc_bias_level level
)
50 struct tas2770_priv
*tas2770
=
51 snd_soc_component_get_drvdata(component
);
55 snd_soc_component_update_bits(component
,
57 TAS2770_PWR_CTRL_MASK
,
58 TAS2770_PWR_CTRL_ACTIVE
);
61 case SND_SOC_BIAS_OFF
:
62 snd_soc_component_update_bits(component
,
64 TAS2770_PWR_CTRL_MASK
,
65 TAS2770_PWR_CTRL_SHUTDOWN
);
70 "wrong power level setting %d\n", level
);
78 static int tas2770_codec_suspend(struct snd_soc_component
*component
)
82 ret
= snd_soc_component_update_bits(component
,
84 TAS2770_PWR_CTRL_MASK
,
85 TAS2770_PWR_CTRL_SHUTDOWN
);
93 static int tas2770_codec_resume(struct snd_soc_component
*component
)
97 ret
= snd_soc_component_update_bits(component
,
99 TAS2770_PWR_CTRL_MASK
,
100 TAS2770_PWR_CTRL_ACTIVE
);
108 #define tas2770_codec_suspend NULL
109 #define tas2770_codec_resume NULL
112 static const char * const tas2770_ASI1_src
[] = {
113 "I2C offset", "Left", "Right", "LeftRightDiv2",
116 static SOC_ENUM_SINGLE_DECL(
117 tas2770_ASI1_src_enum
, TAS2770_TDM_CFG_REG2
,
118 4, tas2770_ASI1_src
);
120 static const struct snd_kcontrol_new tas2770_asi1_mux
=
121 SOC_DAPM_ENUM("ASI1 Source", tas2770_ASI1_src_enum
);
123 static int tas2770_dac_event(struct snd_soc_dapm_widget
*w
,
124 struct snd_kcontrol
*kcontrol
, int event
)
126 struct snd_soc_component
*component
=
127 snd_soc_dapm_to_component(w
->dapm
);
128 struct tas2770_priv
*tas2770
=
129 snd_soc_component_get_drvdata(component
);
133 case SND_SOC_DAPM_POST_PMU
:
134 ret
= snd_soc_component_update_bits(component
,
136 TAS2770_PWR_CTRL_MASK
,
137 TAS2770_PWR_CTRL_MUTE
);
141 case SND_SOC_DAPM_PRE_PMD
:
142 ret
= snd_soc_component_update_bits(component
,
144 TAS2770_PWR_CTRL_MASK
,
145 TAS2770_PWR_CTRL_SHUTDOWN
);
150 dev_err(tas2770
->dev
, "Not supported evevt\n");
161 static const struct snd_kcontrol_new isense_switch
=
162 SOC_DAPM_SINGLE("Switch", TAS2770_PWR_CTRL
, 3, 1, 1);
163 static const struct snd_kcontrol_new vsense_switch
=
164 SOC_DAPM_SINGLE("Switch", TAS2770_PWR_CTRL
, 2, 1, 1);
166 static const struct snd_soc_dapm_widget tas2770_dapm_widgets
[] = {
167 SND_SOC_DAPM_AIF_IN("ASI1", "ASI1 Playback", 0, SND_SOC_NOPM
, 0, 0),
168 SND_SOC_DAPM_MUX("ASI1 Sel", SND_SOC_NOPM
, 0, 0,
170 SND_SOC_DAPM_SWITCH("ISENSE", TAS2770_PWR_CTRL
, 3, 1,
172 SND_SOC_DAPM_SWITCH("VSENSE", TAS2770_PWR_CTRL
, 2, 1,
174 SND_SOC_DAPM_DAC_E("DAC", NULL
, SND_SOC_NOPM
, 0, 0, tas2770_dac_event
,
175 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
),
176 SND_SOC_DAPM_OUTPUT("OUT"),
177 SND_SOC_DAPM_SIGGEN("VMON"),
178 SND_SOC_DAPM_SIGGEN("IMON")
181 static const struct snd_soc_dapm_route tas2770_audio_map
[] = {
182 {"ASI1 Sel", "I2C offset", "ASI1"},
183 {"ASI1 Sel", "Left", "ASI1"},
184 {"ASI1 Sel", "Right", "ASI1"},
185 {"ASI1 Sel", "LeftRightDiv2", "ASI1"},
186 {"DAC", NULL
, "ASI1 Sel"},
187 {"OUT", NULL
, "DAC"},
188 {"ISENSE", "Switch", "IMON"},
189 {"VSENSE", "Switch", "VMON"},
192 static int tas2770_mute(struct snd_soc_dai
*dai
, int mute
)
194 struct snd_soc_component
*component
= dai
->component
;
198 ret
= snd_soc_component_update_bits(component
,
200 TAS2770_PWR_CTRL_MASK
,
201 TAS2770_PWR_CTRL_MUTE
);
203 ret
= snd_soc_component_update_bits(component
,
205 TAS2770_PWR_CTRL_MASK
,
206 TAS2770_PWR_CTRL_ACTIVE
);
214 static int tas2770_set_bitwidth(struct tas2770_priv
*tas2770
, int bitwidth
)
217 struct snd_soc_component
*component
= tas2770
->component
;
220 case SNDRV_PCM_FORMAT_S16_LE
:
221 ret
= snd_soc_component_update_bits(component
,
222 TAS2770_TDM_CFG_REG2
,
223 TAS2770_TDM_CFG_REG2_RXW_MASK
,
224 TAS2770_TDM_CFG_REG2_RXW_16BITS
);
225 tas2770
->v_sense_slot
= tas2770
->i_sense_slot
+ 2;
227 case SNDRV_PCM_FORMAT_S24_LE
:
228 ret
= snd_soc_component_update_bits(component
,
229 TAS2770_TDM_CFG_REG2
,
230 TAS2770_TDM_CFG_REG2_RXW_MASK
,
231 TAS2770_TDM_CFG_REG2_RXW_24BITS
);
232 tas2770
->v_sense_slot
= tas2770
->i_sense_slot
+ 4;
234 case SNDRV_PCM_FORMAT_S32_LE
:
235 ret
= snd_soc_component_update_bits(component
,
236 TAS2770_TDM_CFG_REG2
,
237 TAS2770_TDM_CFG_REG2_RXW_MASK
,
238 TAS2770_TDM_CFG_REG2_RXW_32BITS
);
239 tas2770
->v_sense_slot
= tas2770
->i_sense_slot
+ 4;
246 tas2770
->channel_size
= bitwidth
;
248 ret
= snd_soc_component_update_bits(component
,
249 TAS2770_TDM_CFG_REG5
,
250 TAS2770_TDM_CFG_REG5_VSNS_MASK
|
251 TAS2770_TDM_CFG_REG5_50_MASK
,
252 TAS2770_TDM_CFG_REG5_VSNS_ENABLE
|
253 tas2770
->v_sense_slot
);
256 ret
= snd_soc_component_update_bits(component
,
257 TAS2770_TDM_CFG_REG6
,
258 TAS2770_TDM_CFG_REG6_ISNS_MASK
|
259 TAS2770_TDM_CFG_REG6_50_MASK
,
260 TAS2770_TDM_CFG_REG6_ISNS_ENABLE
|
261 tas2770
->i_sense_slot
);
270 static int tas2770_set_samplerate(struct tas2770_priv
*tas2770
, int samplerate
)
273 struct snd_soc_component
*component
= tas2770
->component
;
275 switch (samplerate
) {
277 ret
= snd_soc_component_update_bits(component
,
278 TAS2770_TDM_CFG_REG0
,
279 TAS2770_TDM_CFG_REG0_SMP_MASK
,
280 TAS2770_TDM_CFG_REG0_SMP_48KHZ
);
283 ret
= snd_soc_component_update_bits(component
,
284 TAS2770_TDM_CFG_REG0
,
285 TAS2770_TDM_CFG_REG0_31_MASK
,
286 TAS2770_TDM_CFG_REG0_31_44_1_48KHZ
);
291 ret
= snd_soc_component_update_bits(component
,
292 TAS2770_TDM_CFG_REG0
,
293 TAS2770_TDM_CFG_REG0_SMP_MASK
,
294 TAS2770_TDM_CFG_REG0_SMP_44_1KHZ
);
297 ret
= snd_soc_component_update_bits(component
,
298 TAS2770_TDM_CFG_REG0
,
299 TAS2770_TDM_CFG_REG0_31_MASK
,
300 TAS2770_TDM_CFG_REG0_31_44_1_48KHZ
);
305 ret
= snd_soc_component_update_bits(component
,
306 TAS2770_TDM_CFG_REG0
,
307 TAS2770_TDM_CFG_REG0_SMP_MASK
,
308 TAS2770_TDM_CFG_REG0_SMP_48KHZ
);
311 ret
= snd_soc_component_update_bits(component
,
312 TAS2770_TDM_CFG_REG0
,
313 TAS2770_TDM_CFG_REG0_31_MASK
,
314 TAS2770_TDM_CFG_REG0_31_88_2_96KHZ
);
317 ret
= snd_soc_component_update_bits(component
,
318 TAS2770_TDM_CFG_REG0
,
319 TAS2770_TDM_CFG_REG0_SMP_MASK
,
320 TAS2770_TDM_CFG_REG0_SMP_44_1KHZ
);
323 ret
= snd_soc_component_update_bits(component
,
324 TAS2770_TDM_CFG_REG0
,
325 TAS2770_TDM_CFG_REG0_31_MASK
,
326 TAS2770_TDM_CFG_REG0_31_88_2_96KHZ
);
329 ret
= snd_soc_component_update_bits(component
,
330 TAS2770_TDM_CFG_REG0
,
331 TAS2770_TDM_CFG_REG0_SMP_MASK
,
332 TAS2770_TDM_CFG_REG0_SMP_48KHZ
);
335 ret
= snd_soc_component_update_bits(component
,
336 TAS2770_TDM_CFG_REG0
,
337 TAS2770_TDM_CFG_REG0_31_MASK
,
338 TAS2770_TDM_CFG_REG0_31_176_4_192KHZ
);
343 ret
= snd_soc_component_update_bits(component
,
344 TAS2770_TDM_CFG_REG0
,
345 TAS2770_TDM_CFG_REG0_SMP_MASK
,
346 TAS2770_TDM_CFG_REG0_SMP_44_1KHZ
);
349 ret
= snd_soc_component_update_bits(component
,
350 TAS2770_TDM_CFG_REG0
,
351 TAS2770_TDM_CFG_REG0_31_MASK
,
352 TAS2770_TDM_CFG_REG0_31_176_4_192KHZ
);
362 tas2770
->sampling_rate
= samplerate
;
366 static int tas2770_hw_params(struct snd_pcm_substream
*substream
,
367 struct snd_pcm_hw_params
*params
,
368 struct snd_soc_dai
*dai
)
370 struct snd_soc_component
*component
= dai
->component
;
371 struct tas2770_priv
*tas2770
=
372 snd_soc_component_get_drvdata(component
);
375 ret
= tas2770_set_bitwidth(tas2770
, params_format(params
));
380 ret
= tas2770_set_samplerate(tas2770
, params_rate(params
));
386 static int tas2770_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
388 u8 tdm_rx_start_slot
= 0, asi_cfg_1
= 0;
390 struct snd_soc_component
*component
= dai
->component
;
391 struct tas2770_priv
*tas2770
=
392 snd_soc_component_get_drvdata(component
);
394 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
395 case SND_SOC_DAIFMT_CBS_CFS
:
398 dev_err(tas2770
->dev
, "ASI format master is not found\n");
402 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
403 case SND_SOC_DAIFMT_NB_NF
:
404 asi_cfg_1
|= TAS2770_TDM_CFG_REG1_RX_RSING
;
406 case SND_SOC_DAIFMT_IB_NF
:
407 asi_cfg_1
|= TAS2770_TDM_CFG_REG1_RX_FALING
;
410 dev_err(tas2770
->dev
, "ASI format Inverse is not found\n");
414 ret
= snd_soc_component_update_bits(component
, TAS2770_TDM_CFG_REG1
,
415 TAS2770_TDM_CFG_REG1_RX_MASK
,
420 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
421 case SND_SOC_DAIFMT_I2S
:
422 tdm_rx_start_slot
= 1;
424 case SND_SOC_DAIFMT_DSP_A
:
425 tdm_rx_start_slot
= 0;
427 case SND_SOC_DAIFMT_DSP_B
:
428 tdm_rx_start_slot
= 1;
430 case SND_SOC_DAIFMT_LEFT_J
:
431 tdm_rx_start_slot
= 0;
434 dev_err(tas2770
->dev
,
435 "DAI Format is not found, fmt=0x%x\n", fmt
);
439 ret
= snd_soc_component_update_bits(component
, TAS2770_TDM_CFG_REG1
,
440 TAS2770_TDM_CFG_REG1_MASK
,
441 (tdm_rx_start_slot
<< TAS2770_TDM_CFG_REG1_51_SHIFT
));
445 tas2770
->asi_format
= fmt
;
450 static int tas2770_set_dai_tdm_slot(struct snd_soc_dai
*dai
,
451 unsigned int tx_mask
,
452 unsigned int rx_mask
,
453 int slots
, int slot_width
)
455 struct snd_soc_component
*component
= dai
->component
;
456 struct tas2770_priv
*tas2770
=
457 snd_soc_component_get_drvdata(component
);
458 int left_slot
, right_slot
;
461 if (tx_mask
== 0 || rx_mask
!= 0)
470 left_slot
= __ffs(tx_mask
);
471 tx_mask
&= ~(1 << left_slot
);
473 right_slot
= left_slot
;
475 right_slot
= __ffs(tx_mask
);
476 tx_mask
&= ~(1 << right_slot
);
480 if (tx_mask
!= 0 || left_slot
>= slots
|| right_slot
>= slots
)
483 ret
= snd_soc_component_update_bits(component
, TAS2770_TDM_CFG_REG3
,
484 TAS2770_TDM_CFG_REG3_30_MASK
,
485 (left_slot
<< TAS2770_TDM_CFG_REG3_30_SHIFT
));
488 ret
= snd_soc_component_update_bits(component
, TAS2770_TDM_CFG_REG3
,
489 TAS2770_TDM_CFG_REG3_RXS_MASK
,
490 (right_slot
<< TAS2770_TDM_CFG_REG3_RXS_SHIFT
));
494 switch (slot_width
) {
496 ret
= snd_soc_component_update_bits(component
,
497 TAS2770_TDM_CFG_REG2
,
498 TAS2770_TDM_CFG_REG2_RXS_MASK
,
499 TAS2770_TDM_CFG_REG2_RXS_16BITS
);
503 ret
= snd_soc_component_update_bits(component
,
504 TAS2770_TDM_CFG_REG2
,
505 TAS2770_TDM_CFG_REG2_RXS_MASK
,
506 TAS2770_TDM_CFG_REG2_RXS_24BITS
);
510 ret
= snd_soc_component_update_bits(component
,
511 TAS2770_TDM_CFG_REG2
,
512 TAS2770_TDM_CFG_REG2_RXS_MASK
,
513 TAS2770_TDM_CFG_REG2_RXS_32BITS
);
517 /* Do not change slot width */
528 tas2770
->slot_width
= slot_width
;
532 static struct snd_soc_dai_ops tas2770_dai_ops
= {
533 .digital_mute
= tas2770_mute
,
534 .hw_params
= tas2770_hw_params
,
535 .set_fmt
= tas2770_set_fmt
,
536 .set_tdm_slot
= tas2770_set_dai_tdm_slot
,
539 #define TAS2770_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
540 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
542 #define TAS2770_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
543 SNDRV_PCM_RATE_96000 |\
544 SNDRV_PCM_RATE_192000\
547 static struct snd_soc_dai_driver tas2770_dai_driver
[] = {
549 .name
= "tas2770 ASI1",
552 .stream_name
= "ASI1 Playback",
555 .rates
= TAS2770_RATES
,
556 .formats
= TAS2770_FORMATS
,
559 .stream_name
= "ASI1 Capture",
562 .rates
= TAS2770_RATES
,
563 .formats
= TAS2770_FORMATS
,
565 .ops
= &tas2770_dai_ops
,
566 .symmetric_rates
= 1,
570 static int tas2770_codec_probe(struct snd_soc_component
*component
)
572 struct tas2770_priv
*tas2770
=
573 snd_soc_component_get_drvdata(component
);
575 tas2770
->component
= component
;
580 static DECLARE_TLV_DB_SCALE(tas2770_digital_tlv
, 1100, 50, 0);
581 static DECLARE_TLV_DB_SCALE(tas2770_playback_volume
, -12750, 50, 0);
583 static const struct snd_kcontrol_new tas2770_snd_controls
[] = {
584 SOC_SINGLE_TLV("Speaker Playback Volume", TAS2770_PLAY_CFG_REG2
,
585 0, TAS2770_PLAY_CFG_REG2_VMAX
, 1,
586 tas2770_playback_volume
),
587 SOC_SINGLE_TLV("Amp Gain Volume", TAS2770_PLAY_CFG_REG0
,
589 tas2770_digital_tlv
),
592 static const struct snd_soc_component_driver soc_component_driver_tas2770
= {
593 .probe
= tas2770_codec_probe
,
594 .suspend
= tas2770_codec_suspend
,
595 .resume
= tas2770_codec_resume
,
596 .set_bias_level
= tas2770_set_bias_level
,
597 .controls
= tas2770_snd_controls
,
598 .num_controls
= ARRAY_SIZE(tas2770_snd_controls
),
599 .dapm_widgets
= tas2770_dapm_widgets
,
600 .num_dapm_widgets
= ARRAY_SIZE(tas2770_dapm_widgets
),
601 .dapm_routes
= tas2770_audio_map
,
602 .num_dapm_routes
= ARRAY_SIZE(tas2770_audio_map
),
605 .non_legacy_dai_naming
= 1,
608 static int tas2770_register_codec(struct tas2770_priv
*tas2770
)
610 return devm_snd_soc_register_component(tas2770
->dev
,
611 &soc_component_driver_tas2770
,
612 tas2770_dai_driver
, ARRAY_SIZE(tas2770_dai_driver
));
615 static const struct reg_default tas2770_reg_defaults
[] = {
616 { TAS2770_PAGE
, 0x00 },
617 { TAS2770_SW_RST
, 0x00 },
618 { TAS2770_PWR_CTRL
, 0x0e },
619 { TAS2770_PLAY_CFG_REG0
, 0x10 },
620 { TAS2770_PLAY_CFG_REG1
, 0x01 },
621 { TAS2770_PLAY_CFG_REG2
, 0x00 },
622 { TAS2770_MSC_CFG_REG0
, 0x07 },
623 { TAS2770_TDM_CFG_REG1
, 0x02 },
624 { TAS2770_TDM_CFG_REG2
, 0x0a },
625 { TAS2770_TDM_CFG_REG3
, 0x10 },
626 { TAS2770_INT_MASK_REG0
, 0xfc },
627 { TAS2770_INT_MASK_REG1
, 0xb1 },
628 { TAS2770_INT_CFG
, 0x05 },
629 { TAS2770_MISC_IRQ
, 0x81 },
630 { TAS2770_CLK_CGF
, 0x0c },
634 static bool tas2770_volatile(struct device
*dev
, unsigned int reg
)
637 case TAS2770_PAGE
: /* regmap implementation requires this */
638 case TAS2770_SW_RST
: /* always clears after write */
639 case TAS2770_BO_PRV_REG0
:/* has a self clearing bit */
640 case TAS2770_LVE_INT_REG0
:
641 case TAS2770_LVE_INT_REG1
:
642 case TAS2770_LAT_INT_REG0
:/* Sticky interrupt flags */
643 case TAS2770_LAT_INT_REG1
:/* Sticky interrupt flags */
644 case TAS2770_VBAT_MSB
:
645 case TAS2770_VBAT_LSB
:
646 case TAS2770_TEMP_MSB
:
647 case TAS2770_TEMP_LSB
:
653 static bool tas2770_writeable(struct device
*dev
, unsigned int reg
)
656 case TAS2770_LVE_INT_REG0
:
657 case TAS2770_LVE_INT_REG1
:
658 case TAS2770_LAT_INT_REG0
:
659 case TAS2770_LAT_INT_REG1
:
660 case TAS2770_VBAT_MSB
:
661 case TAS2770_VBAT_LSB
:
662 case TAS2770_TEMP_MSB
:
663 case TAS2770_TEMP_LSB
:
664 case TAS2770_TDM_CLK_DETC
:
665 case TAS2770_REV_AND_GPID
:
671 static const struct regmap_range_cfg tas2770_regmap_ranges
[] = {
674 .range_max
= 1 * 128,
675 .selector_reg
= TAS2770_PAGE
,
676 .selector_mask
= 0xff,
683 static const struct regmap_config tas2770_i2c_regmap
= {
686 .writeable_reg
= tas2770_writeable
,
687 .volatile_reg
= tas2770_volatile
,
688 .reg_defaults
= tas2770_reg_defaults
,
689 .num_reg_defaults
= ARRAY_SIZE(tas2770_reg_defaults
),
690 .cache_type
= REGCACHE_RBTREE
,
691 .ranges
= tas2770_regmap_ranges
,
692 .num_ranges
= ARRAY_SIZE(tas2770_regmap_ranges
),
693 .max_register
= 1 * 128,
696 static int tas2770_parse_dt(struct device
*dev
, struct tas2770_priv
*tas2770
)
700 rc
= fwnode_property_read_u32(dev
->fwnode
, "ti,asi-format",
701 &tas2770
->asi_format
);
703 dev_err(tas2770
->dev
, "Looking up %s property failed %d\n",
704 "ti,asi-format", rc
);
708 rc
= fwnode_property_read_u32(dev
->fwnode
, "ti,imon-slot-no",
709 &tas2770
->i_sense_slot
);
711 dev_err(tas2770
->dev
, "Looking up %s property failed %d\n",
712 "ti,imon-slot-no", rc
);
716 rc
= fwnode_property_read_u32(dev
->fwnode
, "ti,vmon-slot-no",
717 &tas2770
->v_sense_slot
);
719 dev_err(tas2770
->dev
, "Looking up %s property failed %d\n",
720 "ti,vmon-slot-no", rc
);
728 static int tas2770_i2c_probe(struct i2c_client
*client
,
729 const struct i2c_device_id
*id
)
731 struct tas2770_priv
*tas2770
;
734 tas2770
= devm_kzalloc(&client
->dev
,
735 sizeof(struct tas2770_priv
), GFP_KERNEL
);
738 tas2770
->dev
= &client
->dev
;
740 i2c_set_clientdata(client
, tas2770
);
741 dev_set_drvdata(&client
->dev
, tas2770
);
742 tas2770
->power_state
= TAS2770_POWER_SHUTDOWN
;
744 tas2770
->regmap
= devm_regmap_init_i2c(client
, &tas2770_i2c_regmap
);
745 if (IS_ERR(tas2770
->regmap
)) {
746 result
= PTR_ERR(tas2770
->regmap
);
747 dev_err(&client
->dev
, "Failed to allocate register map: %d\n",
752 if (client
->dev
.of_node
) {
753 result
= tas2770_parse_dt(&client
->dev
, tas2770
);
755 dev_err(tas2770
->dev
, "%s: Failed to parse devicetree\n",
761 tas2770
->reset_gpio
= devm_gpiod_get_optional(tas2770
->dev
,
764 if (IS_ERR(tas2770
->reset_gpio
)) {
765 if (PTR_ERR(tas2770
->reset_gpio
) == -EPROBE_DEFER
) {
766 tas2770
->reset_gpio
= NULL
;
767 return -EPROBE_DEFER
;
771 tas2770
->channel_size
= 0;
772 tas2770
->slot_width
= 0;
774 tas2770_reset(tas2770
);
776 result
= tas2770_register_codec(tas2770
);
778 dev_err(tas2770
->dev
, "Register codec failed.\n");
784 static int tas2770_i2c_remove(struct i2c_client
*client
)
786 pm_runtime_disable(&client
->dev
);
791 static const struct i2c_device_id tas2770_i2c_id
[] = {
795 MODULE_DEVICE_TABLE(i2c
, tas2770_i2c_id
);
797 #if defined(CONFIG_OF)
798 static const struct of_device_id tas2770_of_match
[] = {
799 { .compatible
= "ti,tas2770" },
802 MODULE_DEVICE_TABLE(of
, tas2770_of_match
);
805 static struct i2c_driver tas2770_i2c_driver
= {
808 .of_match_table
= of_match_ptr(tas2770_of_match
),
810 .probe
= tas2770_i2c_probe
,
811 .remove
= tas2770_i2c_remove
,
812 .id_table
= tas2770_i2c_id
,
815 module_i2c_driver(tas2770_i2c_driver
);
817 MODULE_AUTHOR("Shi Fu <shifu0704@thundersoft.com>");
818 MODULE_DESCRIPTION("TAS2770 I2C Smart Amplifier driver");
819 MODULE_LICENSE("GPL v2");