1 /* SPDX-License-Identifier: GPL-2.0 */
3 // ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier
5 // Copyright (C) 2022 - 2023 Texas Instruments Incorporated
8 // The TAS2781 driver implements a flexible and configurable
9 // algo coefficient setting for one, two, or even multiple
12 // Author: Shenghao Ding <shenghao-ding@ti.com>
13 // Author: Kevin Lu <kevin-lu@ti.com>
19 #include "tas2781-dsp.h"
22 #define TAS2781_DRV_VER 1
23 #define SMARTAMP_MODULE_NAME "tas2781"
24 #define TAS2781_GLOBAL_ADDR 0x40
25 #define TASDEVICE_RATES (SNDRV_PCM_RATE_44100 |\
26 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\
29 #define TASDEVICE_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
30 SNDRV_PCM_FMTBIT_S24_LE | \
31 SNDRV_PCM_FMTBIT_S32_LE)
33 /*PAGE Control Register (available in page0 of each book) */
34 #define TASDEVICE_PAGE_SELECT 0x00
35 #define TASDEVICE_BOOKCTL_PAGE 0x00
36 #define TASDEVICE_BOOKCTL_REG 127
37 #define TASDEVICE_BOOK_ID(reg) (reg / (256 * 128))
38 #define TASDEVICE_PAGE_ID(reg) ((reg % (256 * 128)) / 128)
39 #define TASDEVICE_PAGE_REG(reg) ((reg % (256 * 128)) % 128)
40 #define TASDEVICE_PGRG(reg) (reg % (256 * 128))
41 #define TASDEVICE_REG(book, page, reg) (((book * 256 * 128) + \
45 #define TAS2781_REG_SWRESET TASDEVICE_REG(0x0, 0X0, 0x01)
46 #define TAS2781_REG_SWRESET_RESET BIT(0)
49 #define TASDEVICE_I2CChecksum TASDEVICE_REG(0x0, 0x0, 0x7E)
52 #define TAS2781_DVC_LVL TASDEVICE_REG(0x0, 0x0, 0x1A)
53 #define TAS2781_AMP_LEVEL TASDEVICE_REG(0x0, 0x0, 0x03)
54 #define TAS2781_AMP_LEVEL_MASK GENMASK(5, 1)
56 #define TASDEVICE_CMD_SING_W 0x1
57 #define TASDEVICE_CMD_BURST 0x2
58 #define TASDEVICE_CMD_DELAY 0x3
59 #define TASDEVICE_CMD_FIELD_W 0x4
65 enum device_catlog_id {
71 struct tasdevice_fw *cali_data_fmw;
72 unsigned int dev_addr;
73 unsigned int err_code;
74 unsigned char cur_book;
81 struct tasdevice_irqinfo {
88 unsigned long total_sz;
91 struct tasdevice_priv {
92 struct tasdevice tasdevice[TASDEVICE_MAX_CHANNELS];
93 struct tasdevice_irqinfo irq_info;
94 struct tasdevice_rca rcabin;
95 struct calidata cali_data;
96 struct tasdevice_fw *fmw;
97 struct gpio_desc *reset;
98 struct mutex codec_lock;
99 struct regmap *regmap;
103 enum device_catlog_id catlog_id;
104 const char *acpi_subsystem_id;
105 unsigned char cal_binaryname[TASDEVICE_MAX_CHANNELS][64];
106 unsigned char crc8_lkp_tbl[CRC8_TABLE_SIZE];
107 unsigned char coef_binaryname[64];
108 unsigned char rca_binaryname[64];
109 unsigned char dev_name[32];
111 unsigned int magic_num;
112 unsigned int chip_id;
121 bool force_fwload_status;
122 bool playback_started;
124 int (*fw_parse_variable_header)(struct tasdevice_priv *tas_priv,
125 const struct firmware *fmw, int offset);
126 int (*fw_parse_program_data)(struct tasdevice_priv *tas_priv,
127 struct tasdevice_fw *tas_fmw,
128 const struct firmware *fmw, int offset);
129 int (*fw_parse_configuration_data)(struct tasdevice_priv *tas_priv,
130 struct tasdevice_fw *tas_fmw,
131 const struct firmware *fmw, int offset);
132 int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv,
133 struct tasdev_blk *block);
136 void tas2781_reset(struct tasdevice_priv *tas_dev);
137 int tascodec_init(struct tasdevice_priv *tas_priv, void *codec,
138 void (*cont)(const struct firmware *fw, void *context));
139 struct tasdevice_priv *tasdevice_kzalloc(struct i2c_client *i2c);
140 int tasdevice_init(struct tasdevice_priv *tas_priv);
141 void tasdevice_remove(struct tasdevice_priv *tas_priv);
142 int tasdevice_dev_read(struct tasdevice_priv *tas_priv,
143 unsigned short chn, unsigned int reg, unsigned int *value);
144 int tasdevice_dev_write(struct tasdevice_priv *tas_priv,
145 unsigned short chn, unsigned int reg, unsigned int value);
146 int tasdevice_dev_bulk_write(
147 struct tasdevice_priv *tas_priv, unsigned short chn,
148 unsigned int reg, unsigned char *p_data, unsigned int n_length);
149 int tasdevice_dev_bulk_read(struct tasdevice_priv *tas_priv,
150 unsigned short chn, unsigned int reg, unsigned char *p_data,
151 unsigned int n_length);
152 int tasdevice_dev_update_bits(
153 struct tasdevice_priv *tasdevice, unsigned short chn,
154 unsigned int reg, unsigned int mask, unsigned int value);
155 int tasdevice_amp_putvol(struct tasdevice_priv *tas_priv,
156 struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
157 int tasdevice_amp_getvol(struct tasdevice_priv *tas_priv,
158 struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
159 int tasdevice_digital_putvol(struct tasdevice_priv *tas_priv,
160 struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
161 int tasdevice_digital_getvol(struct tasdevice_priv *tas_priv,
162 struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
164 #endif /* __TAS2781_H__ */