1 /* SPDX-License-Identifier: GPL-2.0 */ 2 // 3 // ALSA SoC Texas Instruments TAS2563/TAS2781 Audio Smart Amplifier 4 // 5 // Copyright (C) 2022 - 2026 Texas Instruments Incorporated 6 // https://www.ti.com 7 // 8 // The TAS2563/TAS2781 driver implements a flexible and configurable 9 // algo coefficient setting for one, two, or even multiple 10 // TAS2563/TAS2781 chips. 11 // 12 // Author: Shenghao Ding <shenghao-ding@ti.com> 13 // Author: Kevin Lu <kevin-lu@ti.com> 14 // Author: Baojun Xu <baojun.xu@ti.com> 15 // 16 17 #ifndef __TAS2781_H__ 18 #define __TAS2781_H__ 19 20 #ifdef CONFIG_SND_SOC_TAS2781_ACOUST_I2C 21 #include <linux/debugfs.h> 22 #endif 23 24 #include "tas2781-dsp.h" 25 26 /* version number */ 27 #define TAS2781_DRV_VER 1 28 #define SMARTAMP_MODULE_NAME "tas2781" 29 #define TAS2781_GLOBAL_ADDR 0x40 30 #define TAS2563_GLOBAL_ADDR 0x48 31 #define TASDEVICE_RATES (SNDRV_PCM_RATE_44100 |\ 32 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\ 33 SNDRV_PCM_RATE_88200) 34 35 #define TASDEVICE_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \ 36 SNDRV_PCM_FMTBIT_S24_LE | \ 37 SNDRV_PCM_FMTBIT_S32_LE) 38 39 #define TASDEVICE_CRC8_POLYNOMIAL 0x4d 40 41 /* PAGE Control Register (available in page0 of each book) */ 42 #define TASDEVICE_PAGE_SELECT 0x00 43 #define TASDEVICE_BOOKCTL_PAGE 0x00 44 #define TASDEVICE_BOOKCTL_REG 127 45 #define TASDEVICE_BOOK_ID(reg) (reg / (256 * 128)) 46 #define TASDEVICE_PAGE_ID(reg) ((reg % (256 * 128)) / 128) 47 #define TASDEVICE_PAGE_REG(reg) ((reg % (256 * 128)) % 128) 48 #define TASDEVICE_PGRG(reg) (reg % (256 * 128)) 49 #define TASDEVICE_REG(book, page, reg) (((book * 256 * 128) + \ 50 (page * 128)) + reg) 51 52 /* Software Reset, compatble with new device (TAS5825). */ 53 #define TASDEVICE_REG_SWRESET TASDEVICE_REG(0x0, 0x0, 0x01) 54 #define TASDEVICE_REG_SWRESET_RESET BIT(0) 55 56 #define TAS5825_REG_SWRESET_RESET (BIT(0) | BIT(4)) 57 58 /* Checksum */ 59 #define TASDEVICE_CHECKSUM_REG TASDEVICE_REG(0x0, 0x0, 0x7e) 60 61 /* XM_340 */ 62 #define TASDEVICE_XM_A1_REG TASDEVICE_REG(0x64, 0x63, 0x3c) 63 /* XM_341 */ 64 #define TASDEVICE_XM_A2_REG TASDEVICE_REG(0x64, 0x63, 0x38) 65 66 /* Volume control */ 67 #define TAS2563_DVC_LVL TASDEVICE_REG(0x00, 0x02, 0x0c) 68 #define TAS2781_DVC_LVL TASDEVICE_REG(0x0, 0x0, 0x1a) 69 #define TAS2781_AMP_LEVEL TASDEVICE_REG(0x0, 0x0, 0x03) 70 #define TAS2781_AMP_LEVEL_MASK GENMASK(5, 1) 71 72 #define TAS2563_IDLE TASDEVICE_REG(0x00, 0x00, 0x3e) 73 #define TAS2563_PRM_R0_REG TASDEVICE_REG(0x00, 0x0f, 0x34) 74 75 #define TAS2563_RUNTIME_RE_REG_TF TASDEVICE_REG(0x64, 0x02, 0x70) 76 #define TAS2563_RUNTIME_RE_REG TASDEVICE_REG(0x64, 0x02, 0x48) 77 78 #define TAS2563_PRM_ENFF_REG TASDEVICE_REG(0x00, 0x0d, 0x54) 79 #define TAS2563_PRM_DISTCK_REG TASDEVICE_REG(0x00, 0x0d, 0x58) 80 #define TAS2563_PRM_TE_SCTHR_REG TASDEVICE_REG(0x00, 0x0f, 0x60) 81 #define TAS2563_PRM_PLT_FLAG_REG TASDEVICE_REG(0x00, 0x0d, 0x74) 82 #define TAS2563_PRM_SINEGAIN_REG TASDEVICE_REG(0x00, 0x0d, 0x7c) 83 /* prm_Int_B0 */ 84 #define TAS2563_TE_TA1_REG TASDEVICE_REG(0x00, 0x10, 0x0c) 85 /* prm_Int_A1 */ 86 #define TAS2563_TE_TA1_AT_REG TASDEVICE_REG(0x00, 0x10, 0x10) 87 /* prm_TE_Beta */ 88 #define TAS2563_TE_TA2_REG TASDEVICE_REG(0x00, 0x0f, 0x64) 89 /* prm_TE_Beta1 */ 90 #define TAS2563_TE_AT_REG TASDEVICE_REG(0x00, 0x0f, 0x68) 91 /* prm_TE_1_Beta1 */ 92 #define TAS2563_TE_DT_REG TASDEVICE_REG(0x00, 0x0f, 0x70) 93 94 #define TAS2781_PRM_INT_MASK_REG TASDEVICE_REG(0x00, 0x00, 0x3b) 95 #define TAS2781_PRM_CLK_CFG_REG TASDEVICE_REG(0x00, 0x00, 0x5c) 96 #define TAS2781_PRM_RSVD_REG TASDEVICE_REG(0x00, 0x01, 0x19) 97 #define TAS2781_PRM_TEST_57_REG TASDEVICE_REG(0x00, 0xfd, 0x39) 98 #define TAS2781_PRM_TEST_62_REG TASDEVICE_REG(0x00, 0xfd, 0x3e) 99 #define TAS2781_PRM_PVDD_UVLO_REG TASDEVICE_REG(0x00, 0x00, 0x71) 100 #define TAS2781_PRM_CHNL_0_REG TASDEVICE_REG(0x00, 0x00, 0x03) 101 #define TAS2781_PRM_NG_CFG0_REG TASDEVICE_REG(0x00, 0x00, 0x35) 102 #define TAS2781_PRM_IDLE_CH_DET_REG TASDEVICE_REG(0x00, 0x00, 0x66) 103 #define TAS2781_PRM_PLT_FLAG_REG TASDEVICE_REG(0x00, 0x14, 0x38) 104 #define TAS2781_PRM_SINEGAIN_REG TASDEVICE_REG(0x00, 0x14, 0x40) 105 #define TAS2781_PRM_SINEGAIN2_REG TASDEVICE_REG(0x00, 0x14, 0x44) 106 107 #define TAS2781_TEST_UNLOCK_REG TASDEVICE_REG(0x00, 0xfd, 0x0d) 108 #define TAS2781_TEST_PAGE_UNLOCK 0x0d 109 110 #define TAS2781_RUNTIME_LATCH_RE_REG TASDEVICE_REG(0x00, 0x00, 0x49) 111 #define TAS2781_RUNTIME_RE_REG_TF TASDEVICE_REG(0x64, 0x62, 0x48) 112 #define TAS2781_RUNTIME_RE_REG TASDEVICE_REG(0x64, 0x63, 0x44) 113 114 enum audio_device { 115 TAS2020, 116 TAS2118, 117 TAS2120, 118 TAS2320, 119 TAS2563, 120 TAS2568, 121 TAS2570, 122 TAS2572, 123 TAS2574, 124 TAS2781, 125 TAS5802, 126 TAS5806M, 127 TAS5806MD, 128 TAS5815, 129 TAS5822, 130 TAS5825, 131 TAS5827, 132 TAS5828, 133 TAS5830, 134 TAS5832, 135 TAS_OTHERS, 136 }; 137 138 enum dspbin_type { 139 TASDEV_BASIC, 140 TASDEV_ALPHA, 141 TASDEV_BETA, 142 }; 143 144 struct bulk_reg_val { 145 int reg; 146 unsigned char val[4]; 147 unsigned char val_len; 148 bool is_locked; 149 }; 150 151 struct tasdevice { 152 struct bulk_reg_val *cali_data_backup; 153 struct bulk_reg_val alp_cali_bckp; 154 struct tasdevice_fw *cali_data_fmw; 155 void *cali_specific; 156 unsigned int dev_addr; 157 unsigned int err_code; 158 unsigned char cur_book; 159 short cur_prog; 160 short cur_conf; 161 bool is_loading; 162 bool is_loaderr; 163 }; 164 165 struct cali_reg { 166 unsigned int r0_reg; 167 unsigned int r0_low_reg; 168 unsigned int invr0_reg; 169 unsigned int pow_reg; 170 unsigned int tlimit_reg; 171 }; 172 173 struct calidata { 174 unsigned char *data; 175 unsigned long total_sz; 176 struct cali_reg cali_reg_array; 177 unsigned int cali_dat_sz_per_dev; 178 }; 179 180 /* 181 * To enable CONFIG_SND_SOC_TAS2781_ACOUST_I2C will create a bridge to the 182 * acoustic tuning tool which can tune the chips' acoustic effect. Due to the 183 * whole directly exposing the registers, there exist some potential risks. So 184 * this define is invisible in Kconfig, anyone who wants to use acoustic tool 185 * have to edit the source manually. 186 */ 187 #ifdef CONFIG_SND_SOC_TAS2781_ACOUST_I2C 188 #define TASDEV_DATA_PAYLOAD_SIZE 128 189 struct acoustic_data { 190 unsigned char len; 191 unsigned char id; 192 unsigned char addr; 193 unsigned char book; 194 unsigned char page; 195 unsigned char reg; 196 unsigned char data[TASDEV_DATA_PAYLOAD_SIZE]; 197 }; 198 #endif 199 200 struct tasdevice_priv { 201 struct tasdevice tasdevice[TASDEVICE_MAX_CHANNELS]; 202 struct tasdevice_rca rcabin; 203 struct calidata cali_data; 204 #ifdef CONFIG_SND_SOC_TAS2781_ACOUST_I2C 205 struct acoustic_data acou_data; 206 #endif 207 struct tasdevice_fw *fmw; 208 struct gpio_desc *reset; 209 struct mutex codec_lock; 210 struct regmap *regmap; 211 struct device *dev; 212 213 unsigned char cal_binaryname[TASDEVICE_MAX_CHANNELS][64]; 214 unsigned char crc8_lkp_tbl[CRC8_TABLE_SIZE]; 215 unsigned char coef_binaryname[64]; 216 unsigned char rca_binaryname[64]; 217 unsigned char dev_name[32]; 218 const unsigned char (*dvc_tlv_table)[4]; 219 const char *name_prefix; 220 unsigned char ndev; 221 unsigned int dspbin_typ; 222 unsigned int magic_num; 223 unsigned int chip_id; 224 unsigned int sysclk; 225 int speaker_id; 226 227 int irq; 228 int cur_prog; 229 int cur_conf; 230 int fw_state; 231 int index; 232 void *client; 233 void *codec; 234 bool force_fwload_status; 235 bool playback_started; 236 bool isacpi; 237 bool isspi; 238 unsigned int global_addr; 239 240 int (*fw_parse_variable_header)(struct tasdevice_priv *tas_priv, 241 const struct firmware *fmw, int offset); 242 int (*fw_parse_program_data)(struct tasdevice_priv *tas_priv, 243 struct tasdevice_fw *tas_fmw, 244 const struct firmware *fmw, int offset); 245 int (*fw_parse_configuration_data)(struct tasdevice_priv *tas_priv, 246 struct tasdevice_fw *tas_fmw, 247 const struct firmware *fmw, int offset); 248 int (*fw_parse_fct_param_address)(struct tasdevice_priv *tas_priv, 249 struct tasdevice_fw *tas_fmw, 250 const struct firmware *fmw, int offset); 251 int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv, 252 struct tasdev_blk *block); 253 254 int (*change_chn_book)(struct tasdevice_priv *tas_priv, 255 unsigned short chn, int book); 256 int (*update_bits)(struct tasdevice_priv *tas_priv, 257 unsigned short chn, unsigned int reg, unsigned int mask, 258 unsigned int value); 259 int (*dev_read)(struct tasdevice_priv *tas_priv, 260 unsigned short chn, unsigned int reg, unsigned int *value); 261 int (*dev_bulk_read)(struct tasdevice_priv *tas_priv, 262 unsigned short chn, unsigned int reg, unsigned char *p_data, 263 unsigned int n_length); 264 }; 265 266 int tasdevice_dev_read(struct tasdevice_priv *tas_priv, 267 unsigned short chn, unsigned int reg, unsigned int *value); 268 int tasdevice_dev_bulk_read(struct tasdevice_priv *tas_priv, 269 unsigned short chn, unsigned int reg, unsigned char *p_data, 270 unsigned int n_length); 271 int tasdevice_dev_write(struct tasdevice_priv *tas_priv, 272 unsigned short chn, unsigned int reg, unsigned int value); 273 int tasdevice_dev_bulk_write( 274 struct tasdevice_priv *tas_priv, unsigned short chn, 275 unsigned int reg, unsigned char *p_data, unsigned int n_length); 276 void tasdevice_remove(struct tasdevice_priv *tas_priv); 277 #endif /* __TAS2781_H__ */ 278