1678f38ebSShenghao Ding /* SPDX-License-Identifier: GPL-2.0 */ 2678f38ebSShenghao Ding // 3678f38ebSShenghao Ding // ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier 4678f38ebSShenghao Ding // 5b195acf5SShenghao Ding // Copyright (C) 2022 - 2024 Texas Instruments Incorporated 6678f38ebSShenghao Ding // https://www.ti.com 7678f38ebSShenghao Ding // 8678f38ebSShenghao Ding // The TAS2781 driver implements a flexible and configurable 9678f38ebSShenghao Ding // algo coefficient setting for one, two, or even multiple 10678f38ebSShenghao Ding // TAS2781 chips. 11678f38ebSShenghao Ding // 12678f38ebSShenghao Ding // Author: Shenghao Ding <shenghao-ding@ti.com> 13678f38ebSShenghao Ding // Author: Kevin Lu <kevin-lu@ti.com> 14678f38ebSShenghao Ding // 15678f38ebSShenghao Ding 16b195acf5SShenghao Ding #ifndef __TAS2781_DSP_H__ 17b195acf5SShenghao Ding #define __TAS2781_DSP_H__ 18678f38ebSShenghao Ding 19678f38ebSShenghao Ding #define MAIN_ALL_DEVICES 0x0d 20678f38ebSShenghao Ding #define MAIN_DEVICE_A 0x01 21678f38ebSShenghao Ding #define MAIN_DEVICE_B 0x08 22678f38ebSShenghao Ding #define MAIN_DEVICE_C 0x10 23678f38ebSShenghao Ding #define MAIN_DEVICE_D 0x14 24678f38ebSShenghao Ding #define COEFF_DEVICE_A 0x03 25678f38ebSShenghao Ding #define COEFF_DEVICE_B 0x0a 26678f38ebSShenghao Ding #define COEFF_DEVICE_C 0x11 27678f38ebSShenghao Ding #define COEFF_DEVICE_D 0x15 28678f38ebSShenghao Ding #define PRE_DEVICE_A 0x04 29678f38ebSShenghao Ding #define PRE_DEVICE_B 0x0b 30678f38ebSShenghao Ding #define PRE_DEVICE_C 0x12 31678f38ebSShenghao Ding #define PRE_DEVICE_D 0x16 32678f38ebSShenghao Ding 33678f38ebSShenghao Ding #define PPC3_VERSION 0x4100 34678f38ebSShenghao Ding #define PPC3_VERSION_TAS2781 0x14600 35678f38ebSShenghao Ding #define TASDEVICE_DEVICE_SUM 8 36678f38ebSShenghao Ding #define TASDEVICE_CONFIG_SUM 64 37678f38ebSShenghao Ding 38678f38ebSShenghao Ding #define TASDEVICE_MAX_CHANNELS 8 39678f38ebSShenghao Ding 40678f38ebSShenghao Ding enum tasdevice_dsp_dev_idx { 41678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2555 = 0, 42678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2555_STEREO, 43678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2557_MONO, 44678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2557_DUAL_MONO, 45678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2559, 46678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2563, 47678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2563_DUAL_MONO = 7, 48678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2563_QUAD, 49678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2563_21, 50678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2781, 51678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2781_DUAL_MONO, 52678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2781_21, 53678f38ebSShenghao Ding TASDEVICE_DSP_TAS_2781_QUAD, 54678f38ebSShenghao Ding TASDEVICE_DSP_TAS_MAX_DEVICE 55678f38ebSShenghao Ding }; 56678f38ebSShenghao Ding 57678f38ebSShenghao Ding struct tasdevice_fw_fixed_hdr { 58678f38ebSShenghao Ding unsigned int fwsize; 59678f38ebSShenghao Ding unsigned int ppcver; 60678f38ebSShenghao Ding unsigned int drv_ver; 61678f38ebSShenghao Ding }; 62678f38ebSShenghao Ding 63678f38ebSShenghao Ding struct tasdevice_dspfw_hdr { 64678f38ebSShenghao Ding struct tasdevice_fw_fixed_hdr fixed_hdr; 65678f38ebSShenghao Ding unsigned short device_family; 66678f38ebSShenghao Ding unsigned short device; 67678f38ebSShenghao Ding unsigned char ndev; 68678f38ebSShenghao Ding }; 69678f38ebSShenghao Ding 70678f38ebSShenghao Ding struct tasdev_blk { 71678f38ebSShenghao Ding int nr_retry; 72678f38ebSShenghao Ding unsigned int type; 73678f38ebSShenghao Ding unsigned char is_pchksum_present; 74678f38ebSShenghao Ding unsigned char pchksum; 75678f38ebSShenghao Ding unsigned char is_ychksum_present; 76678f38ebSShenghao Ding unsigned char ychksum; 77678f38ebSShenghao Ding unsigned int nr_cmds; 78678f38ebSShenghao Ding unsigned int blk_size; 79678f38ebSShenghao Ding unsigned int nr_subblocks; 804c556d1eSShenghao Ding /* fixed m68k compiling issue, storing the dev_idx as a member of block 814c556d1eSShenghao Ding * can reduce unnecessary timeand system resource comsumption of 824c556d1eSShenghao Ding * dev_idx mapping every time the block data writing to the dsp. 834c556d1eSShenghao Ding */ 844c556d1eSShenghao Ding unsigned char dev_idx; 85678f38ebSShenghao Ding unsigned char *data; 86678f38ebSShenghao Ding }; 87678f38ebSShenghao Ding 88678f38ebSShenghao Ding struct tasdevice_data { 89678f38ebSShenghao Ding char name[64]; 90678f38ebSShenghao Ding unsigned int nr_blk; 91678f38ebSShenghao Ding struct tasdev_blk *dev_blks; 92678f38ebSShenghao Ding }; 93678f38ebSShenghao Ding 94678f38ebSShenghao Ding struct tasdevice_prog { 95678f38ebSShenghao Ding unsigned int prog_size; 96678f38ebSShenghao Ding struct tasdevice_data dev_data; 97678f38ebSShenghao Ding }; 98678f38ebSShenghao Ding 99678f38ebSShenghao Ding struct tasdevice_config { 100678f38ebSShenghao Ding unsigned int cfg_size; 101678f38ebSShenghao Ding char name[64]; 102678f38ebSShenghao Ding struct tasdevice_data dev_data; 103678f38ebSShenghao Ding }; 104678f38ebSShenghao Ding 105678f38ebSShenghao Ding struct tasdevice_calibration { 106678f38ebSShenghao Ding struct tasdevice_data dev_data; 107678f38ebSShenghao Ding }; 108678f38ebSShenghao Ding 109678f38ebSShenghao Ding struct tasdevice_fw { 110678f38ebSShenghao Ding struct tasdevice_dspfw_hdr fw_hdr; 111678f38ebSShenghao Ding unsigned short nr_programs; 112678f38ebSShenghao Ding struct tasdevice_prog *programs; 113678f38ebSShenghao Ding unsigned short nr_configurations; 114678f38ebSShenghao Ding struct tasdevice_config *configs; 115678f38ebSShenghao Ding unsigned short nr_calibrations; 116678f38ebSShenghao Ding struct tasdevice_calibration *calibrations; 117678f38ebSShenghao Ding struct device *dev; 118678f38ebSShenghao Ding }; 119678f38ebSShenghao Ding 120*9f774c75SShenghao Ding enum tasdevice_fw_state { 121*9f774c75SShenghao Ding /* Driver in startup mode, not load any firmware. */ 122678f38ebSShenghao Ding TASDEVICE_DSP_FW_PENDING, 123*9f774c75SShenghao Ding /* DSP firmware in the system, but parsing error. */ 124678f38ebSShenghao Ding TASDEVICE_DSP_FW_FAIL, 125*9f774c75SShenghao Ding /* 126*9f774c75SShenghao Ding * Only RCA (Reconfigurable Architecture) firmware load 127*9f774c75SShenghao Ding * successfully. 128*9f774c75SShenghao Ding */ 129*9f774c75SShenghao Ding TASDEVICE_RCA_FW_OK, 130*9f774c75SShenghao Ding /* Both RCA and DSP firmware load successfully. */ 131678f38ebSShenghao Ding TASDEVICE_DSP_FW_ALL_OK, 132678f38ebSShenghao Ding }; 133678f38ebSShenghao Ding 134678f38ebSShenghao Ding enum tasdevice_bin_blk_type { 135678f38ebSShenghao Ding TASDEVICE_BIN_BLK_COEFF = 1, 136678f38ebSShenghao Ding TASDEVICE_BIN_BLK_POST_POWER_UP, 137678f38ebSShenghao Ding TASDEVICE_BIN_BLK_PRE_SHUTDOWN, 138678f38ebSShenghao Ding TASDEVICE_BIN_BLK_PRE_POWER_UP, 139678f38ebSShenghao Ding TASDEVICE_BIN_BLK_POST_SHUTDOWN 140678f38ebSShenghao Ding }; 141678f38ebSShenghao Ding 142678f38ebSShenghao Ding struct tasdevice_rca_hdr { 143678f38ebSShenghao Ding unsigned int img_sz; 144678f38ebSShenghao Ding unsigned int checksum; 145678f38ebSShenghao Ding unsigned int binary_version_num; 146678f38ebSShenghao Ding unsigned int drv_fw_version; 147678f38ebSShenghao Ding unsigned char plat_type; 148678f38ebSShenghao Ding unsigned char dev_family; 149678f38ebSShenghao Ding unsigned char reserve; 150678f38ebSShenghao Ding unsigned char ndev; 151678f38ebSShenghao Ding unsigned char devs[TASDEVICE_DEVICE_SUM]; 152678f38ebSShenghao Ding unsigned int nconfig; 153678f38ebSShenghao Ding unsigned int config_size[TASDEVICE_CONFIG_SUM]; 154678f38ebSShenghao Ding }; 155678f38ebSShenghao Ding 156678f38ebSShenghao Ding struct tasdev_blk_data { 157678f38ebSShenghao Ding unsigned char dev_idx; 158678f38ebSShenghao Ding unsigned char block_type; 159678f38ebSShenghao Ding unsigned short yram_checksum; 160678f38ebSShenghao Ding unsigned int block_size; 161678f38ebSShenghao Ding unsigned int n_subblks; 162678f38ebSShenghao Ding unsigned char *regdata; 163678f38ebSShenghao Ding }; 164678f38ebSShenghao Ding 165678f38ebSShenghao Ding struct tasdevice_config_info { 166678f38ebSShenghao Ding unsigned int nblocks; 167678f38ebSShenghao Ding unsigned int real_nblocks; 168678f38ebSShenghao Ding unsigned char active_dev; 169678f38ebSShenghao Ding struct tasdev_blk_data **blk_data; 170678f38ebSShenghao Ding }; 171678f38ebSShenghao Ding 172678f38ebSShenghao Ding struct tasdevice_rca { 173678f38ebSShenghao Ding struct tasdevice_rca_hdr fw_hdr; 174678f38ebSShenghao Ding int ncfgs; 175678f38ebSShenghao Ding struct tasdevice_config_info **cfg_info; 176678f38ebSShenghao Ding int profile_cfg_id; 177678f38ebSShenghao Ding }; 178678f38ebSShenghao Ding 179678f38ebSShenghao Ding void tasdevice_select_cfg_blk(void *context, int conf_no, 180678f38ebSShenghao Ding unsigned char block_type); 181678f38ebSShenghao Ding void tasdevice_config_info_remove(void *context); 182678f38ebSShenghao Ding void tasdevice_dsp_remove(void *context); 183678f38ebSShenghao Ding int tasdevice_dsp_parser(void *context); 184678f38ebSShenghao Ding int tasdevice_rca_parser(void *context, const struct firmware *fmw); 185678f38ebSShenghao Ding void tasdevice_dsp_remove(void *context); 186678f38ebSShenghao Ding void tasdevice_calbin_remove(void *context); 187678f38ebSShenghao Ding int tasdevice_select_tuningprm_cfg(void *context, int prm, 188678f38ebSShenghao Ding int cfg_no, int rca_conf_no); 189678f38ebSShenghao Ding int tasdevice_prmg_load(void *context, int prm_no); 190678f38ebSShenghao Ding void tasdevice_tuning_switch(void *context, int state); 191678f38ebSShenghao Ding int tas2781_load_calibration(void *context, char *file_name, 192678f38ebSShenghao Ding unsigned short i); 193678f38ebSShenghao Ding 194678f38ebSShenghao Ding #endif 195