2 * TAS571x amplifier audio driver
4 * Copyright (C) 2015 Google, Inc.
5 * Copyright (c) 2013 Daniel Mack <zonque@gmail.com>
8 * Copyright (C) 2016 Petr Kulhavy, Barix AG <petr@barix.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
16 #include <linux/clk.h>
17 #include <linux/delay.h>
18 #include <linux/device.h>
19 #include <linux/gpio/consumer.h>
20 #include <linux/i2c.h>
21 #include <linux/init.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/of_device.h>
25 #include <linux/regmap.h>
26 #include <linux/regulator/consumer.h>
27 #include <linux/stddef.h>
28 #include <sound/pcm_params.h>
29 #include <sound/soc.h>
30 #include <sound/tlv.h>
31 #include <asm/unaligned.h>
35 #define TAS571X_MAX_SUPPLIES 6
38 const char *const *supply_names
;
40 const struct snd_kcontrol_new
*controls
;
42 const struct regmap_config
*regmap_config
;
46 struct tas571x_private
{
47 const struct tas571x_chip
*chip
;
48 struct regmap
*regmap
;
49 struct regulator_bulk_data supplies
[TAS571X_MAX_SUPPLIES
];
52 struct gpio_desc
*reset_gpio
;
53 struct gpio_desc
*pdn_gpio
;
54 struct snd_soc_codec_driver codec_driver
;
57 static int tas571x_register_size(struct tas571x_private
*priv
, unsigned int reg
)
60 case TAS571X_MVOL_REG
:
61 case TAS571X_CH1_VOL_REG
:
62 case TAS571X_CH2_VOL_REG
:
63 return priv
->chip
->vol_reg_size
;
64 case TAS571X_INPUT_MUX_REG
:
65 case TAS571X_CH4_SRC_SELECT_REG
:
66 case TAS571X_PWM_MUX_REG
:
67 case TAS5717_CH1_RIGHT_CH_MIX_REG
:
68 case TAS5717_CH1_LEFT_CH_MIX_REG
:
69 case TAS5717_CH2_LEFT_CH_MIX_REG
:
70 case TAS5717_CH2_RIGHT_CH_MIX_REG
:
77 static int tas571x_reg_write(void *context
, unsigned int reg
,
80 struct i2c_client
*client
= context
;
81 struct tas571x_private
*priv
= i2c_get_clientdata(client
);
86 size
= tas571x_register_size(priv
, reg
);
89 for (i
= size
; i
>= 1; --i
) {
94 ret
= i2c_master_send(client
, buf
, size
+ 1);
103 static int tas571x_reg_read(void *context
, unsigned int reg
,
106 struct i2c_client
*client
= context
;
107 struct tas571x_private
*priv
= i2c_get_clientdata(client
);
108 uint8_t send_buf
, recv_buf
[4];
109 struct i2c_msg msgs
[2];
114 size
= tas571x_register_size(priv
, reg
);
117 msgs
[0].addr
= client
->addr
;
118 msgs
[0].len
= sizeof(send_buf
);
119 msgs
[0].buf
= &send_buf
;
122 msgs
[1].addr
= client
->addr
;
124 msgs
[1].buf
= recv_buf
;
125 msgs
[1].flags
= I2C_M_RD
;
127 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
130 else if (ret
!= ARRAY_SIZE(msgs
))
135 for (i
= 0; i
< size
; i
++) {
137 *value
|= recv_buf
[i
];
144 * register write for 8- and 20-byte registers
146 static int tas571x_reg_write_multiword(struct i2c_client
*client
,
147 unsigned int reg
, const long values
[], size_t len
)
152 size_t send_size
= 1 + len
* sizeof(uint32_t);
154 buf
= kzalloc(send_size
, GFP_KERNEL
| GFP_DMA
);
159 for (i
= 0, p
= buf
+ 1; i
< len
; i
++, p
+= sizeof(uint32_t))
160 put_unaligned_be32(values
[i
], p
);
162 ret
= i2c_master_send(client
, buf
, send_size
);
166 if (ret
== send_size
)
175 * register read for 8- and 20-byte registers
177 static int tas571x_reg_read_multiword(struct i2c_client
*client
,
178 unsigned int reg
, long values
[], size_t len
)
182 uint8_t *recv_buf
, *p
;
183 struct i2c_msg msgs
[2];
184 unsigned int recv_size
= len
* sizeof(uint32_t);
187 recv_buf
= kzalloc(recv_size
, GFP_KERNEL
| GFP_DMA
);
193 msgs
[0].addr
= client
->addr
;
194 msgs
[0].len
= sizeof(send_buf
);
195 msgs
[0].buf
= &send_buf
;
198 msgs
[1].addr
= client
->addr
;
199 msgs
[1].len
= recv_size
;
200 msgs
[1].buf
= recv_buf
;
201 msgs
[1].flags
= I2C_M_RD
;
203 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
206 else if (ret
!= ARRAY_SIZE(msgs
)) {
211 for (i
= 0, p
= recv_buf
; i
< len
; i
++, p
+= sizeof(uint32_t))
212 values
[i
] = get_unaligned_be32(p
);
220 * Integer array controls for setting biquad, mixer, DRC coefficients.
221 * According to the datasheet each coefficient is effectively 26bits,
222 * i.e. stored as 32bits, where bits [31:26] are ignored.
223 * TI's TAS57xx Graphical Development Environment tool however produces
224 * coefficients with more than 26 bits. For this reason we allow values
225 * in the full 32-bits reange.
226 * The coefficients are ordered as given in the TAS571x data sheet:
230 static int tas571x_coefficient_info(struct snd_kcontrol
*kcontrol
,
231 struct snd_ctl_elem_info
*uinfo
)
233 int numcoef
= kcontrol
->private_value
>> 16;
235 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
236 uinfo
->count
= numcoef
;
237 uinfo
->value
.integer
.min
= 0;
238 uinfo
->value
.integer
.max
= 0xffffffff;
242 static int tas571x_coefficient_get(struct snd_kcontrol
*kcontrol
,
243 struct snd_ctl_elem_value
*ucontrol
)
245 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
246 struct i2c_client
*i2c
= to_i2c_client(codec
->dev
);
247 int numcoef
= kcontrol
->private_value
>> 16;
248 int index
= kcontrol
->private_value
& 0xffff;
250 return tas571x_reg_read_multiword(i2c
, index
,
251 ucontrol
->value
.integer
.value
, numcoef
);
254 static int tas571x_coefficient_put(struct snd_kcontrol
*kcontrol
,
255 struct snd_ctl_elem_value
*ucontrol
)
257 struct snd_soc_codec
*codec
= snd_soc_kcontrol_codec(kcontrol
);
258 struct i2c_client
*i2c
= to_i2c_client(codec
->dev
);
259 int numcoef
= kcontrol
->private_value
>> 16;
260 int index
= kcontrol
->private_value
& 0xffff;
262 return tas571x_reg_write_multiword(i2c
, index
,
263 ucontrol
->value
.integer
.value
, numcoef
);
266 static int tas571x_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int format
)
268 struct tas571x_private
*priv
= snd_soc_codec_get_drvdata(dai
->codec
);
270 priv
->format
= format
;
275 static int tas571x_hw_params(struct snd_pcm_substream
*substream
,
276 struct snd_pcm_hw_params
*params
,
277 struct snd_soc_dai
*dai
)
279 struct tas571x_private
*priv
= snd_soc_codec_get_drvdata(dai
->codec
);
282 switch (priv
->format
& SND_SOC_DAIFMT_FORMAT_MASK
) {
283 case SND_SOC_DAIFMT_RIGHT_J
:
286 case SND_SOC_DAIFMT_I2S
:
289 case SND_SOC_DAIFMT_LEFT_J
:
296 if (params_width(params
) >= 24)
298 else if (params_width(params
) >= 20)
301 return regmap_update_bits(priv
->regmap
, TAS571X_SDI_REG
,
302 TAS571X_SDI_FMT_MASK
, val
);
305 static int tas571x_mute(struct snd_soc_dai
*dai
, int mute
)
307 struct snd_soc_codec
*codec
= dai
->codec
;
311 sysctl2
= mute
? TAS571X_SYS_CTRL_2_SDN_MASK
: 0;
313 ret
= snd_soc_update_bits(codec
,
314 TAS571X_SYS_CTRL_2_REG
,
315 TAS571X_SYS_CTRL_2_SDN_MASK
,
317 usleep_range(1000, 2000);
322 static int tas571x_set_bias_level(struct snd_soc_codec
*codec
,
323 enum snd_soc_bias_level level
)
325 struct tas571x_private
*priv
= snd_soc_codec_get_drvdata(codec
);
329 case SND_SOC_BIAS_ON
:
331 case SND_SOC_BIAS_PREPARE
:
333 case SND_SOC_BIAS_STANDBY
:
334 if (snd_soc_codec_get_bias_level(codec
) == SND_SOC_BIAS_OFF
) {
335 if (!IS_ERR(priv
->mclk
)) {
336 ret
= clk_prepare_enable(priv
->mclk
);
339 "Failed to enable master clock: %d\n",
345 gpiod_set_value(priv
->pdn_gpio
, 0);
346 usleep_range(5000, 6000);
348 regcache_cache_only(priv
->regmap
, false);
349 ret
= regcache_sync(priv
->regmap
);
354 case SND_SOC_BIAS_OFF
:
355 regcache_cache_only(priv
->regmap
, true);
356 gpiod_set_value(priv
->pdn_gpio
, 1);
358 if (!IS_ERR(priv
->mclk
))
359 clk_disable_unprepare(priv
->mclk
);
366 static const struct snd_soc_dai_ops tas571x_dai_ops
= {
367 .set_fmt
= tas571x_set_dai_fmt
,
368 .hw_params
= tas571x_hw_params
,
369 .digital_mute
= tas571x_mute
,
373 #define BIQUAD_COEFS(xname, reg) \
374 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
375 .info = tas571x_coefficient_info, \
376 .get = tas571x_coefficient_get,\
377 .put = tas571x_coefficient_put, \
378 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
379 .private_value = reg | (5 << 16) }
381 static const char *const tas5711_supply_names
[] = {
390 static const DECLARE_TLV_DB_SCALE(tas5711_volume_tlv
, -10350, 50, 1);
392 static const struct snd_kcontrol_new tas5711_controls
[] = {
393 SOC_SINGLE_TLV("Master Volume",
395 0, 0xff, 1, tas5711_volume_tlv
),
396 SOC_DOUBLE_R_TLV("Speaker Volume",
399 0, 0xff, 1, tas5711_volume_tlv
),
400 SOC_DOUBLE("Speaker Switch",
401 TAS571X_SOFT_MUTE_REG
,
402 TAS571X_SOFT_MUTE_CH1_SHIFT
, TAS571X_SOFT_MUTE_CH2_SHIFT
,
405 SOC_DOUBLE_R_RANGE("CH1 Mixer Volume",
406 TAS5717_CH1_LEFT_CH_MIX_REG
,
407 TAS5717_CH1_RIGHT_CH_MIX_REG
,
410 SOC_DOUBLE_R_RANGE("CH2 Mixer Volume",
411 TAS5717_CH2_LEFT_CH_MIX_REG
,
412 TAS5717_CH2_RIGHT_CH_MIX_REG
,
416 static const struct regmap_range tas571x_readonly_regs_range
[] = {
417 regmap_reg_range(TAS571X_CLK_CTRL_REG
, TAS571X_DEV_ID_REG
),
420 static const struct regmap_range tas571x_volatile_regs_range
[] = {
421 regmap_reg_range(TAS571X_CLK_CTRL_REG
, TAS571X_ERR_STATUS_REG
),
422 regmap_reg_range(TAS571X_OSC_TRIM_REG
, TAS571X_OSC_TRIM_REG
),
425 static const struct regmap_access_table tas571x_write_regs
= {
426 .no_ranges
= tas571x_readonly_regs_range
,
427 .n_no_ranges
= ARRAY_SIZE(tas571x_readonly_regs_range
),
430 static const struct regmap_access_table tas571x_volatile_regs
= {
431 .yes_ranges
= tas571x_volatile_regs_range
,
432 .n_yes_ranges
= ARRAY_SIZE(tas571x_volatile_regs_range
),
436 static const struct reg_default tas5711_reg_defaults
[] = {
446 static const struct regmap_config tas5711_regmap_config
= {
449 .max_register
= 0xff,
450 .reg_read
= tas571x_reg_read
,
451 .reg_write
= tas571x_reg_write
,
452 .reg_defaults
= tas5711_reg_defaults
,
453 .num_reg_defaults
= ARRAY_SIZE(tas5711_reg_defaults
),
454 .cache_type
= REGCACHE_RBTREE
,
455 .wr_table
= &tas571x_write_regs
,
456 .volatile_table
= &tas571x_volatile_regs
,
459 static const struct tas571x_chip tas5711_chip
= {
460 .supply_names
= tas5711_supply_names
,
461 .num_supply_names
= ARRAY_SIZE(tas5711_supply_names
),
462 .controls
= tas5711_controls
,
463 .num_controls
= ARRAY_SIZE(tas5711_controls
),
464 .regmap_config
= &tas5711_regmap_config
,
468 static const char *const tas5717_supply_names
[] = {
476 static const DECLARE_TLV_DB_SCALE(tas5717_volume_tlv
, -10375, 25, 0);
478 static const struct snd_kcontrol_new tas5717_controls
[] = {
479 /* MVOL LSB is ignored - see comments in tas571x_i2c_probe() */
480 SOC_SINGLE_TLV("Master Volume",
481 TAS571X_MVOL_REG
, 1, 0x1ff, 1,
483 SOC_DOUBLE_R_TLV("Speaker Volume",
484 TAS571X_CH1_VOL_REG
, TAS571X_CH2_VOL_REG
,
485 1, 0x1ff, 1, tas5717_volume_tlv
),
486 SOC_DOUBLE("Speaker Switch",
487 TAS571X_SOFT_MUTE_REG
,
488 TAS571X_SOFT_MUTE_CH1_SHIFT
, TAS571X_SOFT_MUTE_CH2_SHIFT
,
492 * The biquads are named according to the register names.
493 * Please note that TI's TAS57xx Graphical Development Environment
494 * tool names them different.
496 BIQUAD_COEFS("CH1 - Biquad 0", TAS5717_CH1_BQ0_REG
),
497 BIQUAD_COEFS("CH1 - Biquad 1", TAS5717_CH1_BQ1_REG
),
498 BIQUAD_COEFS("CH1 - Biquad 2", TAS5717_CH1_BQ2_REG
),
499 BIQUAD_COEFS("CH1 - Biquad 3", TAS5717_CH1_BQ3_REG
),
500 BIQUAD_COEFS("CH1 - Biquad 4", TAS5717_CH1_BQ4_REG
),
501 BIQUAD_COEFS("CH1 - Biquad 5", TAS5717_CH1_BQ5_REG
),
502 BIQUAD_COEFS("CH1 - Biquad 6", TAS5717_CH1_BQ6_REG
),
503 BIQUAD_COEFS("CH1 - Biquad 7", TAS5717_CH1_BQ7_REG
),
504 BIQUAD_COEFS("CH1 - Biquad 8", TAS5717_CH1_BQ8_REG
),
505 BIQUAD_COEFS("CH1 - Biquad 9", TAS5717_CH1_BQ9_REG
),
506 BIQUAD_COEFS("CH1 - Biquad 10", TAS5717_CH1_BQ10_REG
),
507 BIQUAD_COEFS("CH1 - Biquad 11", TAS5717_CH1_BQ11_REG
),
509 BIQUAD_COEFS("CH2 - Biquad 0", TAS5717_CH2_BQ0_REG
),
510 BIQUAD_COEFS("CH2 - Biquad 1", TAS5717_CH2_BQ1_REG
),
511 BIQUAD_COEFS("CH2 - Biquad 2", TAS5717_CH2_BQ2_REG
),
512 BIQUAD_COEFS("CH2 - Biquad 3", TAS5717_CH2_BQ3_REG
),
513 BIQUAD_COEFS("CH2 - Biquad 4", TAS5717_CH2_BQ4_REG
),
514 BIQUAD_COEFS("CH2 - Biquad 5", TAS5717_CH2_BQ5_REG
),
515 BIQUAD_COEFS("CH2 - Biquad 6", TAS5717_CH2_BQ6_REG
),
516 BIQUAD_COEFS("CH2 - Biquad 7", TAS5717_CH2_BQ7_REG
),
517 BIQUAD_COEFS("CH2 - Biquad 8", TAS5717_CH2_BQ8_REG
),
518 BIQUAD_COEFS("CH2 - Biquad 9", TAS5717_CH2_BQ9_REG
),
519 BIQUAD_COEFS("CH2 - Biquad 10", TAS5717_CH2_BQ10_REG
),
520 BIQUAD_COEFS("CH2 - Biquad 11", TAS5717_CH2_BQ11_REG
),
522 BIQUAD_COEFS("CH3 - Biquad 0", TAS5717_CH3_BQ0_REG
),
523 BIQUAD_COEFS("CH3 - Biquad 1", TAS5717_CH3_BQ1_REG
),
525 BIQUAD_COEFS("CH4 - Biquad 0", TAS5717_CH4_BQ0_REG
),
526 BIQUAD_COEFS("CH4 - Biquad 1", TAS5717_CH4_BQ1_REG
),
529 static const struct reg_default tas5717_reg_defaults
[] = {
537 { TAS5717_CH1_RIGHT_CH_MIX_REG
, 0x0 },
538 { TAS5717_CH1_LEFT_CH_MIX_REG
, 0x800000},
539 { TAS5717_CH2_LEFT_CH_MIX_REG
, 0x0 },
540 { TAS5717_CH2_RIGHT_CH_MIX_REG
, 0x800000},
543 static const struct regmap_config tas5717_regmap_config
= {
546 .max_register
= 0xff,
547 .reg_read
= tas571x_reg_read
,
548 .reg_write
= tas571x_reg_write
,
549 .reg_defaults
= tas5717_reg_defaults
,
550 .num_reg_defaults
= ARRAY_SIZE(tas5717_reg_defaults
),
551 .cache_type
= REGCACHE_RBTREE
,
552 .wr_table
= &tas571x_write_regs
,
553 .volatile_table
= &tas571x_volatile_regs
,
556 /* This entry is reused for tas5719 as the software interface is identical. */
557 static const struct tas571x_chip tas5717_chip
= {
558 .supply_names
= tas5717_supply_names
,
559 .num_supply_names
= ARRAY_SIZE(tas5717_supply_names
),
560 .controls
= tas5717_controls
,
561 .num_controls
= ARRAY_SIZE(tas5717_controls
),
562 .regmap_config
= &tas5717_regmap_config
,
566 static const char *const tas5721_supply_names
[] = {
573 static const struct snd_kcontrol_new tas5721_controls
[] = {
574 SOC_SINGLE_TLV("Master Volume",
576 0, 0xff, 1, tas5711_volume_tlv
),
577 SOC_DOUBLE_R_TLV("Speaker Volume",
580 0, 0xff, 1, tas5711_volume_tlv
),
581 SOC_DOUBLE("Speaker Switch",
582 TAS571X_SOFT_MUTE_REG
,
583 TAS571X_SOFT_MUTE_CH1_SHIFT
, TAS571X_SOFT_MUTE_CH2_SHIFT
,
587 static const struct reg_default tas5721_reg_defaults
[] = {
588 {TAS571X_CLK_CTRL_REG
, 0x6c},
589 {TAS571X_DEV_ID_REG
, 0x00},
590 {TAS571X_ERR_STATUS_REG
, 0x00},
591 {TAS571X_SYS_CTRL_1_REG
, 0xa0},
592 {TAS571X_SDI_REG
, 0x05},
593 {TAS571X_SYS_CTRL_2_REG
, 0x40},
594 {TAS571X_SOFT_MUTE_REG
, 0x00},
595 {TAS571X_MVOL_REG
, 0xff},
596 {TAS571X_CH1_VOL_REG
, 0x30},
597 {TAS571X_CH2_VOL_REG
, 0x30},
598 {TAS571X_CH3_VOL_REG
, 0x30},
599 {TAS571X_VOL_CFG_REG
, 0x91},
600 {TAS571X_MODULATION_LIMIT_REG
, 0x02},
601 {TAS571X_IC_DELAY_CH1_REG
, 0xac},
602 {TAS571X_IC_DELAY_CH2_REG
, 0x54},
603 {TAS571X_IC_DELAY_CH3_REG
, 0xac},
604 {TAS571X_IC_DELAY_CH4_REG
, 0x54},
605 {TAS571X_PWM_CH_SDN_GROUP_REG
, 0x30},
606 {TAS571X_START_STOP_PERIOD_REG
, 0x0f},
607 {TAS571X_OSC_TRIM_REG
, 0x82},
608 {TAS571X_BKND_ERR_REG
, 0x02},
609 {TAS571X_INPUT_MUX_REG
, 0x17772},
610 {TAS571X_CH4_SRC_SELECT_REG
, 0x4303},
611 {TAS571X_PWM_MUX_REG
, 0x1021345},
614 static const struct regmap_config tas5721_regmap_config
= {
617 .max_register
= 0xff,
618 .reg_read
= tas571x_reg_read
,
619 .reg_write
= tas571x_reg_write
,
620 .reg_defaults
= tas5721_reg_defaults
,
621 .num_reg_defaults
= ARRAY_SIZE(tas5721_reg_defaults
),
622 .cache_type
= REGCACHE_RBTREE
,
623 .wr_table
= &tas571x_write_regs
,
624 .volatile_table
= &tas571x_volatile_regs
,
628 static const struct tas571x_chip tas5721_chip
= {
629 .supply_names
= tas5721_supply_names
,
630 .num_supply_names
= ARRAY_SIZE(tas5721_supply_names
),
631 .controls
= tas5711_controls
,
632 .num_controls
= ARRAY_SIZE(tas5711_controls
),
633 .regmap_config
= &tas5721_regmap_config
,
637 static const struct snd_soc_dapm_widget tas571x_dapm_widgets
[] = {
638 SND_SOC_DAPM_DAC("DACL", NULL
, SND_SOC_NOPM
, 0, 0),
639 SND_SOC_DAPM_DAC("DACR", NULL
, SND_SOC_NOPM
, 0, 0),
641 SND_SOC_DAPM_OUTPUT("OUT_A"),
642 SND_SOC_DAPM_OUTPUT("OUT_B"),
643 SND_SOC_DAPM_OUTPUT("OUT_C"),
644 SND_SOC_DAPM_OUTPUT("OUT_D"),
647 static const struct snd_soc_dapm_route tas571x_dapm_routes
[] = {
648 { "DACL", NULL
, "Playback" },
649 { "DACR", NULL
, "Playback" },
651 { "OUT_A", NULL
, "DACL" },
652 { "OUT_B", NULL
, "DACL" },
653 { "OUT_C", NULL
, "DACR" },
654 { "OUT_D", NULL
, "DACR" },
657 static const struct snd_soc_codec_driver tas571x_codec
= {
658 .set_bias_level
= tas571x_set_bias_level
,
659 .idle_bias_off
= true,
661 .dapm_widgets
= tas571x_dapm_widgets
,
662 .num_dapm_widgets
= ARRAY_SIZE(tas571x_dapm_widgets
),
663 .dapm_routes
= tas571x_dapm_routes
,
664 .num_dapm_routes
= ARRAY_SIZE(tas571x_dapm_routes
),
667 static struct snd_soc_dai_driver tas571x_dai
= {
668 .name
= "tas571x-hifi",
670 .stream_name
= "Playback",
673 .rates
= SNDRV_PCM_RATE_8000_48000
,
674 .formats
= SNDRV_PCM_FMTBIT_S32_LE
|
675 SNDRV_PCM_FMTBIT_S24_LE
|
676 SNDRV_PCM_FMTBIT_S16_LE
,
678 .ops
= &tas571x_dai_ops
,
681 static const struct of_device_id tas571x_of_match
[];
683 static int tas571x_i2c_probe(struct i2c_client
*client
,
684 const struct i2c_device_id
*id
)
686 struct tas571x_private
*priv
;
687 struct device
*dev
= &client
->dev
;
688 const struct of_device_id
*of_id
;
691 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
694 i2c_set_clientdata(client
, priv
);
696 of_id
= of_match_device(tas571x_of_match
, dev
);
698 priv
->chip
= of_id
->data
;
700 priv
->chip
= (void *) id
->driver_data
;
702 priv
->mclk
= devm_clk_get(dev
, "mclk");
703 if (IS_ERR(priv
->mclk
) && PTR_ERR(priv
->mclk
) != -ENOENT
) {
704 dev_err(dev
, "Failed to request mclk: %ld\n",
705 PTR_ERR(priv
->mclk
));
706 return PTR_ERR(priv
->mclk
);
709 BUG_ON(priv
->chip
->num_supply_names
> TAS571X_MAX_SUPPLIES
);
710 for (i
= 0; i
< priv
->chip
->num_supply_names
; i
++)
711 priv
->supplies
[i
].supply
= priv
->chip
->supply_names
[i
];
713 ret
= devm_regulator_bulk_get(dev
, priv
->chip
->num_supply_names
,
716 dev_err(dev
, "Failed to get supplies: %d\n", ret
);
719 ret
= regulator_bulk_enable(priv
->chip
->num_supply_names
,
722 dev_err(dev
, "Failed to enable supplies: %d\n", ret
);
726 priv
->regmap
= devm_regmap_init(dev
, NULL
, client
,
727 priv
->chip
->regmap_config
);
728 if (IS_ERR(priv
->regmap
))
729 return PTR_ERR(priv
->regmap
);
731 priv
->pdn_gpio
= devm_gpiod_get_optional(dev
, "pdn", GPIOD_OUT_LOW
);
732 if (IS_ERR(priv
->pdn_gpio
)) {
733 dev_err(dev
, "error requesting pdn_gpio: %ld\n",
734 PTR_ERR(priv
->pdn_gpio
));
735 return PTR_ERR(priv
->pdn_gpio
);
738 priv
->reset_gpio
= devm_gpiod_get_optional(dev
, "reset",
740 if (IS_ERR(priv
->reset_gpio
)) {
741 dev_err(dev
, "error requesting reset_gpio: %ld\n",
742 PTR_ERR(priv
->reset_gpio
));
743 return PTR_ERR(priv
->reset_gpio
);
744 } else if (priv
->reset_gpio
) {
745 /* pulse the active low reset line for ~100us */
746 usleep_range(100, 200);
747 gpiod_set_value(priv
->reset_gpio
, 0);
748 usleep_range(12000, 20000);
751 ret
= regmap_write(priv
->regmap
, TAS571X_OSC_TRIM_REG
, 0);
756 memcpy(&priv
->codec_driver
, &tas571x_codec
, sizeof(priv
->codec_driver
));
757 priv
->codec_driver
.controls
= priv
->chip
->controls
;
758 priv
->codec_driver
.num_controls
= priv
->chip
->num_controls
;
760 if (priv
->chip
->vol_reg_size
== 2) {
762 * The master volume defaults to 0x3ff (mute), but we ignore
763 * (zero) the LSB because the hardware step size is 0.125 dB
764 * and TLV_DB_SCALE_ITEM has a resolution of 0.01 dB.
766 ret
= regmap_update_bits(priv
->regmap
, TAS571X_MVOL_REG
, 1, 0);
771 regcache_cache_only(priv
->regmap
, true);
772 gpiod_set_value(priv
->pdn_gpio
, 1);
774 return snd_soc_register_codec(&client
->dev
, &priv
->codec_driver
,
778 static int tas571x_i2c_remove(struct i2c_client
*client
)
780 struct tas571x_private
*priv
= i2c_get_clientdata(client
);
782 snd_soc_unregister_codec(&client
->dev
);
783 regulator_bulk_disable(priv
->chip
->num_supply_names
, priv
->supplies
);
788 static const struct of_device_id tas571x_of_match
[] = {
789 { .compatible
= "ti,tas5711", .data
= &tas5711_chip
, },
790 { .compatible
= "ti,tas5717", .data
= &tas5717_chip
, },
791 { .compatible
= "ti,tas5719", .data
= &tas5717_chip
, },
792 { .compatible
= "ti,tas5721", .data
= &tas5721_chip
, },
795 MODULE_DEVICE_TABLE(of
, tas571x_of_match
);
797 static const struct i2c_device_id tas571x_i2c_id
[] = {
798 { "tas5711", (kernel_ulong_t
) &tas5711_chip
},
799 { "tas5717", (kernel_ulong_t
) &tas5717_chip
},
800 { "tas5719", (kernel_ulong_t
) &tas5717_chip
},
801 { "tas5721", (kernel_ulong_t
) &tas5721_chip
},
804 MODULE_DEVICE_TABLE(i2c
, tas571x_i2c_id
);
806 static struct i2c_driver tas571x_i2c_driver
= {
809 .of_match_table
= of_match_ptr(tas571x_of_match
),
811 .probe
= tas571x_i2c_probe
,
812 .remove
= tas571x_i2c_remove
,
813 .id_table
= tas571x_i2c_id
,
815 module_i2c_driver(tas571x_i2c_driver
);
817 MODULE_DESCRIPTION("ASoC TAS571x driver");
818 MODULE_AUTHOR("Kevin Cernekee <cernekee@chromium.org>");
819 MODULE_LICENSE("GPL");