1 /* SPDX-License-Identifier: GPL-2.0 */ 2 // 3 // ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier 4 // 5 // Copyright (C) 2022 - 2025 Texas Instruments Incorporated 6 // https://www.ti.com 7 // 8 // The TAS2781 driver implements a flexible and configurable 9 // algo coefficient setting for one, two, or even multiple 10 // TAS2781 chips. 11 // 12 // Author: Shenghao Ding <shenghao-ding@ti.com> 13 // Author: Kevin Lu <kevin-lu@ti.com> 14 // 15 16 #ifndef __TAS2781_DSP_H__ 17 #define __TAS2781_DSP_H__ 18 19 #define MAIN_ALL_DEVICES 0x0d 20 #define MAIN_DEVICE_A 0x01 21 #define MAIN_DEVICE_B 0x08 22 #define MAIN_DEVICE_C 0x10 23 #define MAIN_DEVICE_D 0x14 24 #define COEFF_DEVICE_A 0x03 25 #define COEFF_DEVICE_B 0x0a 26 #define COEFF_DEVICE_C 0x11 27 #define COEFF_DEVICE_D 0x15 28 #define PRE_DEVICE_A 0x04 29 #define PRE_DEVICE_B 0x0b 30 #define PRE_DEVICE_C 0x12 31 #define PRE_DEVICE_D 0x16 32 33 #define PPC3_VERSION_BASE 0x4100 34 #define PPC3_VERSION_TAS2781_BASIC_MIN 0x14600 35 #define PPC3_VERSION_TAS2781_ALPHA_MIN 0x4a00 36 #define PPC3_VERSION_TAS2781_BETA_MIN 0x19400 37 #define TASDEVICE_DEVICE_SUM 8 38 #define TASDEVICE_CONFIG_SUM 64 39 40 #define TASDEVICE_MAX_CHANNELS 8 41 42 enum tasdevice_dsp_dev_idx { 43 TASDEVICE_DSP_TAS_2555 = 0, 44 TASDEVICE_DSP_TAS_2555_STEREO, 45 TASDEVICE_DSP_TAS_2557_MONO, 46 TASDEVICE_DSP_TAS_2557_DUAL_MONO, 47 TASDEVICE_DSP_TAS_2559, 48 TASDEVICE_DSP_TAS_2563, 49 TASDEVICE_DSP_TAS_2563_DUAL_MONO = 7, 50 TASDEVICE_DSP_TAS_2563_QUAD, 51 TASDEVICE_DSP_TAS_2563_21, 52 TASDEVICE_DSP_TAS_2781, 53 TASDEVICE_DSP_TAS_2781_DUAL_MONO, 54 TASDEVICE_DSP_TAS_2781_21, 55 TASDEVICE_DSP_TAS_2781_QUAD, 56 TASDEVICE_DSP_TAS_MAX_DEVICE 57 }; 58 59 struct tasdevice_fw_fixed_hdr { 60 unsigned int fwsize; 61 unsigned int ppcver; 62 unsigned int drv_ver; 63 }; 64 65 struct tasdevice_dspfw_hdr { 66 struct tasdevice_fw_fixed_hdr fixed_hdr; 67 unsigned short device_family; 68 unsigned short device; 69 unsigned char ndev; 70 }; 71 72 struct tasdev_blk { 73 int nr_retry; 74 unsigned int type; 75 unsigned char is_pchksum_present; 76 unsigned char pchksum; 77 unsigned char is_ychksum_present; 78 unsigned char ychksum; 79 unsigned int nr_cmds; 80 unsigned int blk_size; 81 unsigned int nr_subblocks; 82 /* fixed m68k compiling issue, storing the dev_idx as a member of block 83 * can reduce unnecessary timeand system resource comsumption of 84 * dev_idx mapping every time the block data writing to the dsp. 85 */ 86 unsigned char dev_idx; 87 unsigned char *data; 88 }; 89 90 struct tasdevice_data { 91 char name[64]; 92 unsigned int nr_blk; 93 struct tasdev_blk *dev_blks; 94 }; 95 96 struct tasdevice_prog { 97 unsigned int prog_size; 98 struct tasdevice_data dev_data; 99 }; 100 101 struct tasdevice_config { 102 unsigned int cfg_size; 103 char name[64]; 104 struct tasdevice_data dev_data; 105 }; 106 107 struct tasdevice_calibration { 108 struct tasdevice_data dev_data; 109 }; 110 111 struct fct_param_address { 112 /* Thermal data for PG 1.0 device */ 113 unsigned char thr[3]; 114 /* Thermal data for PG 2.0 device */ 115 unsigned char thr2[3]; 116 /* Pilot tone enable flag, usually the sine wave */ 117 unsigned char plt_flg[3]; 118 /* Pilot tone gain for calibration */ 119 unsigned char sin_gn[3]; 120 /* Pilot tone gain for calibration */ 121 unsigned char sin_gn2[3]; 122 /* high 32-bit of real-time spk impedance */ 123 unsigned char r0_reg[3]; 124 /* check spk connection */ 125 unsigned char tf_reg[3]; 126 /* check spk resonant frequency */ 127 unsigned char a1_reg[3]; 128 /* check spk resonant frequency */ 129 unsigned char a2_reg[3]; 130 }; 131 132 struct tasdevice_fw { 133 struct tasdevice_dspfw_hdr fw_hdr; 134 unsigned short nr_programs; 135 struct tasdevice_prog *programs; 136 unsigned short nr_configurations; 137 struct tasdevice_config *configs; 138 unsigned short nr_calibrations; 139 struct tasdevice_calibration *calibrations; 140 struct fct_param_address fct_par_addr; 141 struct device *dev; 142 }; 143 144 enum tasdevice_fw_state { 145 /* Driver in startup mode, not load any firmware. */ 146 TASDEVICE_DSP_FW_PENDING, 147 /* DSP firmware in the system, but parsing error. */ 148 TASDEVICE_DSP_FW_FAIL, 149 /* 150 * Only RCA (Reconfigurable Architecture) firmware load 151 * successfully. 152 */ 153 TASDEVICE_RCA_FW_OK, 154 /* Both RCA and DSP firmware load successfully. */ 155 TASDEVICE_DSP_FW_ALL_OK, 156 }; 157 158 enum tasdevice_bin_blk_type { 159 TASDEVICE_BIN_BLK_COEFF = 1, 160 TASDEVICE_BIN_BLK_POST_POWER_UP, 161 TASDEVICE_BIN_BLK_PRE_SHUTDOWN, 162 TASDEVICE_BIN_BLK_PRE_POWER_UP, 163 TASDEVICE_BIN_BLK_POST_SHUTDOWN 164 }; 165 166 struct tasdevice_rca_hdr { 167 unsigned int img_sz; 168 unsigned int checksum; 169 unsigned int binary_version_num; 170 unsigned int drv_fw_version; 171 unsigned char plat_type; 172 unsigned char dev_family; 173 unsigned char reserve; 174 unsigned char ndev; 175 unsigned char devs[TASDEVICE_DEVICE_SUM]; 176 unsigned int nconfig; 177 unsigned int config_size[TASDEVICE_CONFIG_SUM]; 178 }; 179 180 struct tasdev_blk_data { 181 unsigned char dev_idx; 182 unsigned char block_type; 183 unsigned short yram_checksum; 184 unsigned int block_size; 185 unsigned int n_subblks; 186 unsigned char *regdata; 187 }; 188 189 struct tasdevice_config_info { 190 unsigned int nblocks; 191 unsigned int real_nblocks; 192 unsigned char active_dev; 193 struct tasdev_blk_data **blk_data; 194 }; 195 196 struct tasdevice_rca { 197 struct tasdevice_rca_hdr fw_hdr; 198 int ncfgs; 199 struct tasdevice_config_info **cfg_info; 200 int profile_cfg_id; 201 }; 202 203 void tasdevice_select_cfg_blk(void *context, int conf_no, 204 unsigned char block_type); 205 void tasdevice_config_info_remove(void *context); 206 void tasdevice_dsp_remove(void *context); 207 int tasdevice_dsp_parser(void *context); 208 int tasdevice_rca_parser(void *context, const struct firmware *fmw); 209 void tasdevice_dsp_remove(void *context); 210 void tasdevice_calbin_remove(void *context); 211 int tasdevice_select_tuningprm_cfg(void *context, int prm, 212 int cfg_no, int rca_conf_no); 213 int tasdevice_prmg_load(void *context, int prm_no); 214 void tasdevice_tuning_switch(void *context, int state); 215 int tas2781_load_calibration(void *context, char *file_name, 216 unsigned short i); 217 218 #endif 219