162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci// 362306a36Sopenharmony_ci// ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier 462306a36Sopenharmony_ci// 562306a36Sopenharmony_ci// Copyright (C) 2022 - 2023 Texas Instruments Incorporated 662306a36Sopenharmony_ci// https://www.ti.com 762306a36Sopenharmony_ci// 862306a36Sopenharmony_ci// The TAS2781 driver implements a flexible and configurable 962306a36Sopenharmony_ci// algo coefficient setting for one, two, or even multiple 1062306a36Sopenharmony_ci// TAS2781 chips. 1162306a36Sopenharmony_ci// 1262306a36Sopenharmony_ci// Author: Shenghao Ding <shenghao-ding@ti.com> 1362306a36Sopenharmony_ci// Author: Kevin Lu <kevin-lu@ti.com> 1462306a36Sopenharmony_ci// 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#ifndef __TASDEVICE_DSP_H__ 1762306a36Sopenharmony_ci#define __TASDEVICE_DSP_H__ 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#define MAIN_ALL_DEVICES 0x0d 2062306a36Sopenharmony_ci#define MAIN_DEVICE_A 0x01 2162306a36Sopenharmony_ci#define MAIN_DEVICE_B 0x08 2262306a36Sopenharmony_ci#define MAIN_DEVICE_C 0x10 2362306a36Sopenharmony_ci#define MAIN_DEVICE_D 0x14 2462306a36Sopenharmony_ci#define COEFF_DEVICE_A 0x03 2562306a36Sopenharmony_ci#define COEFF_DEVICE_B 0x0a 2662306a36Sopenharmony_ci#define COEFF_DEVICE_C 0x11 2762306a36Sopenharmony_ci#define COEFF_DEVICE_D 0x15 2862306a36Sopenharmony_ci#define PRE_DEVICE_A 0x04 2962306a36Sopenharmony_ci#define PRE_DEVICE_B 0x0b 3062306a36Sopenharmony_ci#define PRE_DEVICE_C 0x12 3162306a36Sopenharmony_ci#define PRE_DEVICE_D 0x16 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci#define PPC3_VERSION 0x4100 3462306a36Sopenharmony_ci#define PPC3_VERSION_TAS2781 0x14600 3562306a36Sopenharmony_ci#define TASDEVICE_DEVICE_SUM 8 3662306a36Sopenharmony_ci#define TASDEVICE_CONFIG_SUM 64 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#define TASDEVICE_MAX_CHANNELS 8 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_cienum tasdevice_dsp_dev_idx { 4162306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2555 = 0, 4262306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2555_STEREO, 4362306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2557_MONO, 4462306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2557_DUAL_MONO, 4562306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2559, 4662306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2563, 4762306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2563_DUAL_MONO = 7, 4862306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2563_QUAD, 4962306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2563_21, 5062306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2781, 5162306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2781_DUAL_MONO, 5262306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2781_21, 5362306a36Sopenharmony_ci TASDEVICE_DSP_TAS_2781_QUAD, 5462306a36Sopenharmony_ci TASDEVICE_DSP_TAS_MAX_DEVICE 5562306a36Sopenharmony_ci}; 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_cistruct tasdevice_fw_fixed_hdr { 5862306a36Sopenharmony_ci unsigned int fwsize; 5962306a36Sopenharmony_ci unsigned int ppcver; 6062306a36Sopenharmony_ci unsigned int drv_ver; 6162306a36Sopenharmony_ci}; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cistruct tasdevice_dspfw_hdr { 6462306a36Sopenharmony_ci struct tasdevice_fw_fixed_hdr fixed_hdr; 6562306a36Sopenharmony_ci unsigned short device_family; 6662306a36Sopenharmony_ci unsigned short device; 6762306a36Sopenharmony_ci unsigned char ndev; 6862306a36Sopenharmony_ci}; 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_cistruct tasdev_blk { 7162306a36Sopenharmony_ci int nr_retry; 7262306a36Sopenharmony_ci unsigned int type; 7362306a36Sopenharmony_ci unsigned char is_pchksum_present; 7462306a36Sopenharmony_ci unsigned char pchksum; 7562306a36Sopenharmony_ci unsigned char is_ychksum_present; 7662306a36Sopenharmony_ci unsigned char ychksum; 7762306a36Sopenharmony_ci unsigned int nr_cmds; 7862306a36Sopenharmony_ci unsigned int blk_size; 7962306a36Sopenharmony_ci unsigned int nr_subblocks; 8062306a36Sopenharmony_ci unsigned char *data; 8162306a36Sopenharmony_ci}; 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_cistruct tasdevice_data { 8462306a36Sopenharmony_ci char name[64]; 8562306a36Sopenharmony_ci unsigned int nr_blk; 8662306a36Sopenharmony_ci struct tasdev_blk *dev_blks; 8762306a36Sopenharmony_ci}; 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_cistruct tasdevice_prog { 9062306a36Sopenharmony_ci unsigned int prog_size; 9162306a36Sopenharmony_ci struct tasdevice_data dev_data; 9262306a36Sopenharmony_ci}; 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_cistruct tasdevice_config { 9562306a36Sopenharmony_ci unsigned int cfg_size; 9662306a36Sopenharmony_ci char name[64]; 9762306a36Sopenharmony_ci struct tasdevice_data dev_data; 9862306a36Sopenharmony_ci}; 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_cistruct tasdevice_calibration { 10162306a36Sopenharmony_ci struct tasdevice_data dev_data; 10262306a36Sopenharmony_ci}; 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_cistruct tasdevice_fw { 10562306a36Sopenharmony_ci struct tasdevice_dspfw_hdr fw_hdr; 10662306a36Sopenharmony_ci unsigned short nr_programs; 10762306a36Sopenharmony_ci struct tasdevice_prog *programs; 10862306a36Sopenharmony_ci unsigned short nr_configurations; 10962306a36Sopenharmony_ci struct tasdevice_config *configs; 11062306a36Sopenharmony_ci unsigned short nr_calibrations; 11162306a36Sopenharmony_ci struct tasdevice_calibration *calibrations; 11262306a36Sopenharmony_ci struct device *dev; 11362306a36Sopenharmony_ci}; 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_cienum tasdevice_dsp_fw_state { 11662306a36Sopenharmony_ci TASDEVICE_DSP_FW_NONE = 0, 11762306a36Sopenharmony_ci TASDEVICE_DSP_FW_PENDING, 11862306a36Sopenharmony_ci TASDEVICE_DSP_FW_FAIL, 11962306a36Sopenharmony_ci TASDEVICE_DSP_FW_ALL_OK, 12062306a36Sopenharmony_ci}; 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_cienum tasdevice_bin_blk_type { 12362306a36Sopenharmony_ci TASDEVICE_BIN_BLK_COEFF = 1, 12462306a36Sopenharmony_ci TASDEVICE_BIN_BLK_POST_POWER_UP, 12562306a36Sopenharmony_ci TASDEVICE_BIN_BLK_PRE_SHUTDOWN, 12662306a36Sopenharmony_ci TASDEVICE_BIN_BLK_PRE_POWER_UP, 12762306a36Sopenharmony_ci TASDEVICE_BIN_BLK_POST_SHUTDOWN 12862306a36Sopenharmony_ci}; 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_cistruct tasdevice_rca_hdr { 13162306a36Sopenharmony_ci unsigned int img_sz; 13262306a36Sopenharmony_ci unsigned int checksum; 13362306a36Sopenharmony_ci unsigned int binary_version_num; 13462306a36Sopenharmony_ci unsigned int drv_fw_version; 13562306a36Sopenharmony_ci unsigned char plat_type; 13662306a36Sopenharmony_ci unsigned char dev_family; 13762306a36Sopenharmony_ci unsigned char reserve; 13862306a36Sopenharmony_ci unsigned char ndev; 13962306a36Sopenharmony_ci unsigned char devs[TASDEVICE_DEVICE_SUM]; 14062306a36Sopenharmony_ci unsigned int nconfig; 14162306a36Sopenharmony_ci unsigned int config_size[TASDEVICE_CONFIG_SUM]; 14262306a36Sopenharmony_ci}; 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_cistruct tasdev_blk_data { 14562306a36Sopenharmony_ci unsigned char dev_idx; 14662306a36Sopenharmony_ci unsigned char block_type; 14762306a36Sopenharmony_ci unsigned short yram_checksum; 14862306a36Sopenharmony_ci unsigned int block_size; 14962306a36Sopenharmony_ci unsigned int n_subblks; 15062306a36Sopenharmony_ci unsigned char *regdata; 15162306a36Sopenharmony_ci}; 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_cistruct tasdevice_config_info { 15462306a36Sopenharmony_ci unsigned int nblocks; 15562306a36Sopenharmony_ci unsigned int real_nblocks; 15662306a36Sopenharmony_ci unsigned char active_dev; 15762306a36Sopenharmony_ci struct tasdev_blk_data **blk_data; 15862306a36Sopenharmony_ci}; 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_cistruct tasdevice_rca { 16162306a36Sopenharmony_ci struct tasdevice_rca_hdr fw_hdr; 16262306a36Sopenharmony_ci int ncfgs; 16362306a36Sopenharmony_ci struct tasdevice_config_info **cfg_info; 16462306a36Sopenharmony_ci int profile_cfg_id; 16562306a36Sopenharmony_ci}; 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_civoid tasdevice_select_cfg_blk(void *context, int conf_no, 16862306a36Sopenharmony_ci unsigned char block_type); 16962306a36Sopenharmony_civoid tasdevice_config_info_remove(void *context); 17062306a36Sopenharmony_civoid tasdevice_dsp_remove(void *context); 17162306a36Sopenharmony_ciint tasdevice_dsp_parser(void *context); 17262306a36Sopenharmony_ciint tasdevice_rca_parser(void *context, const struct firmware *fmw); 17362306a36Sopenharmony_civoid tasdevice_dsp_remove(void *context); 17462306a36Sopenharmony_civoid tasdevice_calbin_remove(void *context); 17562306a36Sopenharmony_ciint tasdevice_select_tuningprm_cfg(void *context, int prm, 17662306a36Sopenharmony_ci int cfg_no, int rca_conf_no); 17762306a36Sopenharmony_ciint tasdevice_prmg_load(void *context, int prm_no); 17862306a36Sopenharmony_ciint tasdevice_prmg_calibdata_load(void *context, int prm_no); 17962306a36Sopenharmony_civoid tasdevice_tuning_switch(void *context, int state); 18062306a36Sopenharmony_ciint tas2781_load_calibration(void *context, char *file_name, 18162306a36Sopenharmony_ci unsigned short i); 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci#endif 184