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 PPC3_VERSION_TAS5825_BASE 0x114200 38 #define TASDEVICE_DEVICE_SUM 8 39 #define TASDEVICE_CONFIG_SUM 64 40 41 #define TASDEVICE_MAX_CHANNELS 8 42 43 enum tasdevice_dsp_dev_idx { 44 TASDEVICE_DSP_TAS_2555 = 0, 45 TASDEVICE_DSP_TAS_2555_STEREO, 46 TASDEVICE_DSP_TAS_2557_MONO, 47 TASDEVICE_DSP_TAS_2557_DUAL_MONO, 48 TASDEVICE_DSP_TAS_2559, 49 TASDEVICE_DSP_TAS_2563, 50 TASDEVICE_DSP_TAS_2563_DUAL_MONO = 7, 51 TASDEVICE_DSP_TAS_2563_QUAD, 52 TASDEVICE_DSP_TAS_2563_21, 53 TASDEVICE_DSP_TAS_2781, 54 TASDEVICE_DSP_TAS_2781_DUAL_MONO, 55 TASDEVICE_DSP_TAS_2781_21, 56 TASDEVICE_DSP_TAS_2781_QUAD, 57 TASDEVICE_DSP_TAS_5825_MONO, 58 TASDEVICE_DSP_TAS_5825_DUAL, 59 TASDEVICE_DSP_TAS_MAX_DEVICE 60 }; 61 62 struct tasdevice_fw_fixed_hdr { 63 unsigned int fwsize; 64 unsigned int ppcver; 65 unsigned int drv_ver; 66 }; 67 68 struct tasdevice_dspfw_hdr { 69 struct tasdevice_fw_fixed_hdr fixed_hdr; 70 unsigned short device_family; 71 unsigned short device; 72 unsigned char ndev; 73 }; 74 75 struct tasdev_blk { 76 int nr_retry; 77 unsigned int type; 78 unsigned char is_pchksum_present; 79 unsigned char pchksum; 80 unsigned char is_ychksum_present; 81 unsigned char ychksum; 82 unsigned int nr_cmds; 83 unsigned int blk_size; 84 unsigned int nr_subblocks; 85 /* fixed m68k compiling issue, storing the dev_idx as a member of block 86 * can reduce unnecessary timeand system resource comsumption of 87 * dev_idx mapping every time the block data writing to the dsp. 88 */ 89 unsigned char dev_idx; 90 unsigned char *data; 91 }; 92 93 struct tasdevice_data { 94 char name[64]; 95 unsigned int nr_blk; 96 struct tasdev_blk *dev_blks; 97 }; 98 99 struct tasdevice_prog { 100 unsigned int prog_size; 101 struct tasdevice_data dev_data; 102 }; 103 104 struct tasdevice_config { 105 unsigned int cfg_size; 106 char name[64]; 107 struct tasdevice_data dev_data; 108 }; 109 110 struct tasdevice_calibration { 111 struct tasdevice_data dev_data; 112 }; 113 114 struct fct_param_address { 115 /* Thermal data for PG 1.0 device */ 116 unsigned char thr[3]; 117 /* Thermal data for PG 2.0 device */ 118 unsigned char thr2[3]; 119 /* Pilot tone enable flag, usually the sine wave */ 120 unsigned char plt_flg[3]; 121 /* Pilot tone gain for calibration */ 122 unsigned char sin_gn[3]; 123 /* Pilot tone gain for calibration */ 124 unsigned char sin_gn2[3]; 125 /* high 32-bit of real-time spk impedance */ 126 unsigned char r0_reg[3]; 127 /* check spk connection */ 128 unsigned char tf_reg[3]; 129 /* check spk resonant frequency */ 130 unsigned char a1_reg[3]; 131 /* check spk resonant frequency */ 132 unsigned char a2_reg[3]; 133 }; 134 135 struct tasdevice_fw { 136 struct tasdevice_dspfw_hdr fw_hdr; 137 unsigned short nr_programs; 138 struct tasdevice_prog *programs; 139 unsigned short nr_configurations; 140 struct tasdevice_config *configs; 141 unsigned short nr_calibrations; 142 struct tasdevice_calibration *calibrations; 143 struct fct_param_address fct_par_addr; 144 struct device *dev; 145 }; 146 147 enum tasdevice_fw_state { 148 /* Driver in startup mode, not load any firmware. */ 149 TASDEVICE_DSP_FW_PENDING, 150 /* DSP firmware in the system, but parsing error. */ 151 TASDEVICE_DSP_FW_FAIL, 152 /* 153 * Only RCA (Reconfigurable Architecture) firmware load 154 * successfully. 155 */ 156 TASDEVICE_RCA_FW_OK, 157 /* Both RCA and DSP firmware load successfully. */ 158 TASDEVICE_DSP_FW_ALL_OK, 159 }; 160 161 enum tasdevice_bin_blk_type { 162 TASDEVICE_BIN_BLK_COEFF = 1, 163 TASDEVICE_BIN_BLK_POST_POWER_UP, 164 TASDEVICE_BIN_BLK_PRE_SHUTDOWN, 165 TASDEVICE_BIN_BLK_PRE_POWER_UP, 166 TASDEVICE_BIN_BLK_POST_SHUTDOWN 167 }; 168 169 struct tasdevice_rca_hdr { 170 unsigned int img_sz; 171 unsigned int checksum; 172 unsigned int binary_version_num; 173 unsigned int drv_fw_version; 174 unsigned char plat_type; 175 unsigned char dev_family; 176 unsigned char reserve; 177 unsigned char ndev; 178 unsigned char devs[TASDEVICE_DEVICE_SUM]; 179 unsigned int nconfig; 180 unsigned int config_size[TASDEVICE_CONFIG_SUM]; 181 }; 182 183 struct tasdev_blk_data { 184 unsigned char dev_idx; 185 unsigned char block_type; 186 unsigned short yram_checksum; 187 unsigned int block_size; 188 unsigned int n_subblks; 189 unsigned char *regdata; 190 }; 191 192 struct tasdevice_config_info { 193 unsigned int nblocks; 194 unsigned int real_nblocks; 195 unsigned char active_dev; 196 struct tasdev_blk_data **blk_data; 197 }; 198 199 struct tasdevice_rca { 200 struct tasdevice_rca_hdr fw_hdr; 201 int ncfgs; 202 struct tasdevice_config_info **cfg_info; 203 int profile_cfg_id; 204 /* 205 * Since version 0x105, the keyword 'init' was introduced into the 206 * profile, which is used for chip initialization, particularly to 207 * store common settings for other non-initialization profiles. 208 * if (init_profile_id < 0) 209 * No init profile inside the RCA firmware. 210 */ 211 int init_profile_id; 212 }; 213 214 void tasdevice_select_cfg_blk(void *context, int conf_no, 215 unsigned char block_type); 216 void tasdevice_config_info_remove(void *context); 217 void tasdevice_dsp_remove(void *context); 218 int tasdevice_dsp_parser(void *context); 219 int tasdevice_rca_parser(void *context, const struct firmware *fmw); 220 void tasdevice_dsp_remove(void *context); 221 void tasdevice_calbin_remove(void *context); 222 int tasdevice_select_tuningprm_cfg(void *context, int prm, 223 int cfg_no, int rca_conf_no); 224 int tasdevice_prmg_load(void *context, int prm_no); 225 void tasdevice_tuning_switch(void *context, int state); 226 int tas2781_load_calibration(void *context, char *file_name, 227 unsigned short i); 228 229 #endif 230