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",
346 case SND_SOC_BIAS_OFF
:
347 if (!IS_ERR(priv
->mclk
))
348 clk_disable_unprepare(priv
->mclk
);
355 static const struct snd_soc_dai_ops tas571x_dai_ops
= {
356 .set_fmt
= tas571x_set_dai_fmt
,
357 .hw_params
= tas571x_hw_params
,
358 .digital_mute
= tas571x_mute
,
362 #define BIQUAD_COEFS(xname, reg) \
363 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
364 .info = tas571x_coefficient_info, \
365 .get = tas571x_coefficient_get,\
366 .put = tas571x_coefficient_put, \
367 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
368 .private_value = reg | (5 << 16) }
370 static const char *const tas5711_supply_names
[] = {
379 static const DECLARE_TLV_DB_SCALE(tas5711_volume_tlv
, -10350, 50, 1);
381 static const struct snd_kcontrol_new tas5711_controls
[] = {
382 SOC_SINGLE_TLV("Master Volume",
384 0, 0xff, 1, tas5711_volume_tlv
),
385 SOC_DOUBLE_R_TLV("Speaker Volume",
388 0, 0xff, 1, tas5711_volume_tlv
),
389 SOC_DOUBLE("Speaker Switch",
390 TAS571X_SOFT_MUTE_REG
,
391 TAS571X_SOFT_MUTE_CH1_SHIFT
, TAS571X_SOFT_MUTE_CH2_SHIFT
,
395 static const struct regmap_range tas571x_readonly_regs_range
[] = {
396 regmap_reg_range(TAS571X_CLK_CTRL_REG
, TAS571X_DEV_ID_REG
),
399 static const struct regmap_range tas571x_volatile_regs_range
[] = {
400 regmap_reg_range(TAS571X_CLK_CTRL_REG
, TAS571X_ERR_STATUS_REG
),
401 regmap_reg_range(TAS571X_OSC_TRIM_REG
, TAS571X_OSC_TRIM_REG
),
404 static const struct regmap_access_table tas571x_write_regs
= {
405 .no_ranges
= tas571x_readonly_regs_range
,
406 .n_no_ranges
= ARRAY_SIZE(tas571x_readonly_regs_range
),
409 static const struct regmap_access_table tas571x_volatile_regs
= {
410 .yes_ranges
= tas571x_volatile_regs_range
,
411 .n_yes_ranges
= ARRAY_SIZE(tas571x_volatile_regs_range
),
415 static const struct reg_default tas5711_reg_defaults
[] = {
425 static const struct regmap_config tas5711_regmap_config
= {
428 .max_register
= 0xff,
429 .reg_read
= tas571x_reg_read
,
430 .reg_write
= tas571x_reg_write
,
431 .reg_defaults
= tas5711_reg_defaults
,
432 .num_reg_defaults
= ARRAY_SIZE(tas5711_reg_defaults
),
433 .cache_type
= REGCACHE_RBTREE
,
434 .wr_table
= &tas571x_write_regs
,
435 .volatile_table
= &tas571x_volatile_regs
,
438 static const struct tas571x_chip tas5711_chip
= {
439 .supply_names
= tas5711_supply_names
,
440 .num_supply_names
= ARRAY_SIZE(tas5711_supply_names
),
441 .controls
= tas5711_controls
,
442 .num_controls
= ARRAY_SIZE(tas5711_controls
),
443 .regmap_config
= &tas5711_regmap_config
,
447 static const char *const tas5717_supply_names
[] = {
455 static const DECLARE_TLV_DB_SCALE(tas5717_volume_tlv
, -10375, 25, 0);
457 static const struct snd_kcontrol_new tas5717_controls
[] = {
458 /* MVOL LSB is ignored - see comments in tas571x_i2c_probe() */
459 SOC_SINGLE_TLV("Master Volume",
460 TAS571X_MVOL_REG
, 1, 0x1ff, 1,
462 SOC_DOUBLE_R_TLV("Speaker Volume",
463 TAS571X_CH1_VOL_REG
, TAS571X_CH2_VOL_REG
,
464 1, 0x1ff, 1, tas5717_volume_tlv
),
465 SOC_DOUBLE("Speaker Switch",
466 TAS571X_SOFT_MUTE_REG
,
467 TAS571X_SOFT_MUTE_CH1_SHIFT
, TAS571X_SOFT_MUTE_CH2_SHIFT
,
470 SOC_DOUBLE_R_RANGE("CH1 Mixer Volume",
471 TAS5717_CH1_LEFT_CH_MIX_REG
,
472 TAS5717_CH1_RIGHT_CH_MIX_REG
,
475 SOC_DOUBLE_R_RANGE("CH2 Mixer Volume",
476 TAS5717_CH2_LEFT_CH_MIX_REG
,
477 TAS5717_CH2_RIGHT_CH_MIX_REG
,
481 * The biquads are named according to the register names.
482 * Please note that TI's TAS57xx Graphical Development Environment
483 * tool names them different.
485 BIQUAD_COEFS("CH1 - Biquad 0", TAS5717_CH1_BQ0_REG
),
486 BIQUAD_COEFS("CH1 - Biquad 1", TAS5717_CH1_BQ1_REG
),
487 BIQUAD_COEFS("CH1 - Biquad 2", TAS5717_CH1_BQ2_REG
),
488 BIQUAD_COEFS("CH1 - Biquad 3", TAS5717_CH1_BQ3_REG
),
489 BIQUAD_COEFS("CH1 - Biquad 4", TAS5717_CH1_BQ4_REG
),
490 BIQUAD_COEFS("CH1 - Biquad 5", TAS5717_CH1_BQ5_REG
),
491 BIQUAD_COEFS("CH1 - Biquad 6", TAS5717_CH1_BQ6_REG
),
492 BIQUAD_COEFS("CH1 - Biquad 7", TAS5717_CH1_BQ7_REG
),
493 BIQUAD_COEFS("CH1 - Biquad 8", TAS5717_CH1_BQ8_REG
),
494 BIQUAD_COEFS("CH1 - Biquad 9", TAS5717_CH1_BQ9_REG
),
495 BIQUAD_COEFS("CH1 - Biquad 10", TAS5717_CH1_BQ10_REG
),
496 BIQUAD_COEFS("CH1 - Biquad 11", TAS5717_CH1_BQ11_REG
),
498 BIQUAD_COEFS("CH2 - Biquad 0", TAS5717_CH2_BQ0_REG
),
499 BIQUAD_COEFS("CH2 - Biquad 1", TAS5717_CH2_BQ1_REG
),
500 BIQUAD_COEFS("CH2 - Biquad 2", TAS5717_CH2_BQ2_REG
),
501 BIQUAD_COEFS("CH2 - Biquad 3", TAS5717_CH2_BQ3_REG
),
502 BIQUAD_COEFS("CH2 - Biquad 4", TAS5717_CH2_BQ4_REG
),
503 BIQUAD_COEFS("CH2 - Biquad 5", TAS5717_CH2_BQ5_REG
),
504 BIQUAD_COEFS("CH2 - Biquad 6", TAS5717_CH2_BQ6_REG
),
505 BIQUAD_COEFS("CH2 - Biquad 7", TAS5717_CH2_BQ7_REG
),
506 BIQUAD_COEFS("CH2 - Biquad 8", TAS5717_CH2_BQ8_REG
),
507 BIQUAD_COEFS("CH2 - Biquad 9", TAS5717_CH2_BQ9_REG
),
508 BIQUAD_COEFS("CH2 - Biquad 10", TAS5717_CH2_BQ10_REG
),
509 BIQUAD_COEFS("CH2 - Biquad 11", TAS5717_CH2_BQ11_REG
),
511 BIQUAD_COEFS("CH3 - Biquad 0", TAS5717_CH3_BQ0_REG
),
512 BIQUAD_COEFS("CH3 - Biquad 1", TAS5717_CH3_BQ1_REG
),
514 BIQUAD_COEFS("CH4 - Biquad 0", TAS5717_CH4_BQ0_REG
),
515 BIQUAD_COEFS("CH4 - Biquad 1", TAS5717_CH4_BQ1_REG
),
518 static const struct reg_default tas5717_reg_defaults
[] = {
526 { TAS5717_CH1_RIGHT_CH_MIX_REG
, 0x0 },
527 { TAS5717_CH1_LEFT_CH_MIX_REG
, 0x800000},
528 { TAS5717_CH2_LEFT_CH_MIX_REG
, 0x0 },
529 { TAS5717_CH2_RIGHT_CH_MIX_REG
, 0x800000},
532 static const struct regmap_config tas5717_regmap_config
= {
535 .max_register
= 0xff,
536 .reg_read
= tas571x_reg_read
,
537 .reg_write
= tas571x_reg_write
,
538 .reg_defaults
= tas5717_reg_defaults
,
539 .num_reg_defaults
= ARRAY_SIZE(tas5717_reg_defaults
),
540 .cache_type
= REGCACHE_RBTREE
,
541 .wr_table
= &tas571x_write_regs
,
542 .volatile_table
= &tas571x_volatile_regs
,
545 /* This entry is reused for tas5719 as the software interface is identical. */
546 static const struct tas571x_chip tas5717_chip
= {
547 .supply_names
= tas5717_supply_names
,
548 .num_supply_names
= ARRAY_SIZE(tas5717_supply_names
),
549 .controls
= tas5717_controls
,
550 .num_controls
= ARRAY_SIZE(tas5717_controls
),
551 .regmap_config
= &tas5717_regmap_config
,
555 static const char *const tas5721_supply_names
[] = {
562 static const struct snd_kcontrol_new tas5721_controls
[] = {
563 SOC_SINGLE_TLV("Master Volume",
565 0, 0xff, 1, tas5711_volume_tlv
),
566 SOC_DOUBLE_R_TLV("Speaker Volume",
569 0, 0xff, 1, tas5711_volume_tlv
),
570 SOC_DOUBLE("Speaker Switch",
571 TAS571X_SOFT_MUTE_REG
,
572 TAS571X_SOFT_MUTE_CH1_SHIFT
, TAS571X_SOFT_MUTE_CH2_SHIFT
,
576 static const struct reg_default tas5721_reg_defaults
[] = {
577 {TAS571X_CLK_CTRL_REG
, 0x6c},
578 {TAS571X_DEV_ID_REG
, 0x00},
579 {TAS571X_ERR_STATUS_REG
, 0x00},
580 {TAS571X_SYS_CTRL_1_REG
, 0xa0},
581 {TAS571X_SDI_REG
, 0x05},
582 {TAS571X_SYS_CTRL_2_REG
, 0x40},
583 {TAS571X_SOFT_MUTE_REG
, 0x00},
584 {TAS571X_MVOL_REG
, 0xff},
585 {TAS571X_CH1_VOL_REG
, 0x30},
586 {TAS571X_CH2_VOL_REG
, 0x30},
587 {TAS571X_CH3_VOL_REG
, 0x30},
588 {TAS571X_VOL_CFG_REG
, 0x91},
589 {TAS571X_MODULATION_LIMIT_REG
, 0x02},
590 {TAS571X_IC_DELAY_CH1_REG
, 0xac},
591 {TAS571X_IC_DELAY_CH2_REG
, 0x54},
592 {TAS571X_IC_DELAY_CH3_REG
, 0xac},
593 {TAS571X_IC_DELAY_CH4_REG
, 0x54},
594 {TAS571X_PWM_CH_SDN_GROUP_REG
, 0x30},
595 {TAS571X_START_STOP_PERIOD_REG
, 0x0f},
596 {TAS571X_OSC_TRIM_REG
, 0x82},
597 {TAS571X_BKND_ERR_REG
, 0x02},
598 {TAS571X_INPUT_MUX_REG
, 0x17772},
599 {TAS571X_CH4_SRC_SELECT_REG
, 0x4303},
600 {TAS571X_PWM_MUX_REG
, 0x1021345},
603 static const struct regmap_config tas5721_regmap_config
= {
606 .max_register
= 0xff,
607 .reg_read
= tas571x_reg_read
,
608 .reg_write
= tas571x_reg_write
,
609 .reg_defaults
= tas5721_reg_defaults
,
610 .num_reg_defaults
= ARRAY_SIZE(tas5721_reg_defaults
),
611 .cache_type
= REGCACHE_RBTREE
,
612 .wr_table
= &tas571x_write_regs
,
613 .volatile_table
= &tas571x_volatile_regs
,
617 static const struct tas571x_chip tas5721_chip
= {
618 .supply_names
= tas5721_supply_names
,
619 .num_supply_names
= ARRAY_SIZE(tas5721_supply_names
),
620 .controls
= tas5711_controls
,
621 .num_controls
= ARRAY_SIZE(tas5711_controls
),
622 .regmap_config
= &tas5721_regmap_config
,
626 static const struct snd_soc_dapm_widget tas571x_dapm_widgets
[] = {
627 SND_SOC_DAPM_DAC("DACL", NULL
, SND_SOC_NOPM
, 0, 0),
628 SND_SOC_DAPM_DAC("DACR", NULL
, SND_SOC_NOPM
, 0, 0),
630 SND_SOC_DAPM_OUTPUT("OUT_A"),
631 SND_SOC_DAPM_OUTPUT("OUT_B"),
632 SND_SOC_DAPM_OUTPUT("OUT_C"),
633 SND_SOC_DAPM_OUTPUT("OUT_D"),
636 static const struct snd_soc_dapm_route tas571x_dapm_routes
[] = {
637 { "DACL", NULL
, "Playback" },
638 { "DACR", NULL
, "Playback" },
640 { "OUT_A", NULL
, "DACL" },
641 { "OUT_B", NULL
, "DACL" },
642 { "OUT_C", NULL
, "DACR" },
643 { "OUT_D", NULL
, "DACR" },
646 static const struct snd_soc_codec_driver tas571x_codec
= {
647 .set_bias_level
= tas571x_set_bias_level
,
648 .idle_bias_off
= true,
650 .component_driver
= {
651 .dapm_widgets
= tas571x_dapm_widgets
,
652 .num_dapm_widgets
= ARRAY_SIZE(tas571x_dapm_widgets
),
653 .dapm_routes
= tas571x_dapm_routes
,
654 .num_dapm_routes
= ARRAY_SIZE(tas571x_dapm_routes
),
658 static struct snd_soc_dai_driver tas571x_dai
= {
659 .name
= "tas571x-hifi",
661 .stream_name
= "Playback",
664 .rates
= SNDRV_PCM_RATE_8000_48000
,
665 .formats
= SNDRV_PCM_FMTBIT_S32_LE
|
666 SNDRV_PCM_FMTBIT_S24_LE
|
667 SNDRV_PCM_FMTBIT_S16_LE
,
669 .ops
= &tas571x_dai_ops
,
672 static const struct of_device_id tas571x_of_match
[];
674 static int tas571x_i2c_probe(struct i2c_client
*client
,
675 const struct i2c_device_id
*id
)
677 struct tas571x_private
*priv
;
678 struct device
*dev
= &client
->dev
;
679 const struct of_device_id
*of_id
;
682 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
685 i2c_set_clientdata(client
, priv
);
687 of_id
= of_match_device(tas571x_of_match
, dev
);
689 priv
->chip
= of_id
->data
;
691 priv
->chip
= (void *) id
->driver_data
;
693 priv
->mclk
= devm_clk_get(dev
, "mclk");
694 if (IS_ERR(priv
->mclk
) && PTR_ERR(priv
->mclk
) != -ENOENT
) {
695 dev_err(dev
, "Failed to request mclk: %ld\n",
696 PTR_ERR(priv
->mclk
));
697 return PTR_ERR(priv
->mclk
);
700 if (WARN_ON(priv
->chip
->num_supply_names
> TAS571X_MAX_SUPPLIES
))
702 for (i
= 0; i
< priv
->chip
->num_supply_names
; i
++)
703 priv
->supplies
[i
].supply
= priv
->chip
->supply_names
[i
];
705 ret
= devm_regulator_bulk_get(dev
, priv
->chip
->num_supply_names
,
708 dev_err(dev
, "Failed to get supplies: %d\n", ret
);
711 ret
= regulator_bulk_enable(priv
->chip
->num_supply_names
,
714 dev_err(dev
, "Failed to enable supplies: %d\n", ret
);
718 priv
->regmap
= devm_regmap_init(dev
, NULL
, client
,
719 priv
->chip
->regmap_config
);
720 if (IS_ERR(priv
->regmap
))
721 return PTR_ERR(priv
->regmap
);
723 priv
->pdn_gpio
= devm_gpiod_get_optional(dev
, "pdn", GPIOD_OUT_LOW
);
724 if (IS_ERR(priv
->pdn_gpio
)) {
725 dev_err(dev
, "error requesting pdn_gpio: %ld\n",
726 PTR_ERR(priv
->pdn_gpio
));
727 return PTR_ERR(priv
->pdn_gpio
);
730 priv
->reset_gpio
= devm_gpiod_get_optional(dev
, "reset",
732 if (IS_ERR(priv
->reset_gpio
)) {
733 dev_err(dev
, "error requesting reset_gpio: %ld\n",
734 PTR_ERR(priv
->reset_gpio
));
735 return PTR_ERR(priv
->reset_gpio
);
736 } else if (priv
->reset_gpio
) {
737 /* pulse the active low reset line for ~100us */
738 usleep_range(100, 200);
739 gpiod_set_value(priv
->reset_gpio
, 0);
740 usleep_range(13500, 20000);
743 ret
= regmap_write(priv
->regmap
, TAS571X_OSC_TRIM_REG
, 0);
747 usleep_range(50000, 60000);
749 memcpy(&priv
->codec_driver
, &tas571x_codec
, sizeof(priv
->codec_driver
));
750 priv
->codec_driver
.component_driver
.controls
= priv
->chip
->controls
;
751 priv
->codec_driver
.component_driver
.num_controls
= priv
->chip
->num_controls
;
753 if (priv
->chip
->vol_reg_size
== 2) {
755 * The master volume defaults to 0x3ff (mute), but we ignore
756 * (zero) the LSB because the hardware step size is 0.125 dB
757 * and TLV_DB_SCALE_ITEM has a resolution of 0.01 dB.
759 ret
= regmap_update_bits(priv
->regmap
, TAS571X_MVOL_REG
, 1, 0);
764 return snd_soc_register_codec(&client
->dev
, &priv
->codec_driver
,
768 static int tas571x_i2c_remove(struct i2c_client
*client
)
770 struct tas571x_private
*priv
= i2c_get_clientdata(client
);
772 snd_soc_unregister_codec(&client
->dev
);
773 regulator_bulk_disable(priv
->chip
->num_supply_names
, priv
->supplies
);
778 static const struct of_device_id tas571x_of_match
[] = {
779 { .compatible
= "ti,tas5711", .data
= &tas5711_chip
, },
780 { .compatible
= "ti,tas5717", .data
= &tas5717_chip
, },
781 { .compatible
= "ti,tas5719", .data
= &tas5717_chip
, },
782 { .compatible
= "ti,tas5721", .data
= &tas5721_chip
, },
785 MODULE_DEVICE_TABLE(of
, tas571x_of_match
);
787 static const struct i2c_device_id tas571x_i2c_id
[] = {
788 { "tas5711", (kernel_ulong_t
) &tas5711_chip
},
789 { "tas5717", (kernel_ulong_t
) &tas5717_chip
},
790 { "tas5719", (kernel_ulong_t
) &tas5717_chip
},
791 { "tas5721", (kernel_ulong_t
) &tas5721_chip
},
794 MODULE_DEVICE_TABLE(i2c
, tas571x_i2c_id
);
796 static struct i2c_driver tas571x_i2c_driver
= {
799 .of_match_table
= of_match_ptr(tas571x_of_match
),
801 .probe
= tas571x_i2c_probe
,
802 .remove
= tas571x_i2c_remove
,
803 .id_table
= tas571x_i2c_id
,
805 module_i2c_driver(tas571x_i2c_driver
);
807 MODULE_DESCRIPTION("ASoC TAS571x driver");
808 MODULE_AUTHOR("Kevin Cernekee <cernekee@chromium.org>");
809 MODULE_LICENSE("GPL");