Skip to content

Commit 678f38e

Browse files
Shenghao Dingbroonie
authored andcommitted
ASoC: tas2781: Add Header file for tas2781 driver
Create Header file for tas2781 driver. Signed-off-by: Shenghao Ding <13916275206@139.com> Link: https://lore.kernel.org/r/20230618122819.23143-1-13916275206@139.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 8fba13f commit 678f38e

3 files changed

Lines changed: 368 additions & 0 deletions

File tree

include/sound/tas2781-dsp.h

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
//
3+
// ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier
4+
//
5+
// Copyright (C) 2022 - 2023 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 __TASDEVICE_DSP_H__
17+
#define __TASDEVICE_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 0x4100
34+
#define PPC3_VERSION_TAS2781 0x14600
35+
#define TASDEVICE_DEVICE_SUM 8
36+
#define TASDEVICE_CONFIG_SUM 64
37+
38+
#define TASDEVICE_MAX_CHANNELS 8
39+
40+
enum tasdevice_dsp_dev_idx {
41+
TASDEVICE_DSP_TAS_2555 = 0,
42+
TASDEVICE_DSP_TAS_2555_STEREO,
43+
TASDEVICE_DSP_TAS_2557_MONO,
44+
TASDEVICE_DSP_TAS_2557_DUAL_MONO,
45+
TASDEVICE_DSP_TAS_2559,
46+
TASDEVICE_DSP_TAS_2563,
47+
TASDEVICE_DSP_TAS_2563_DUAL_MONO = 7,
48+
TASDEVICE_DSP_TAS_2563_QUAD,
49+
TASDEVICE_DSP_TAS_2563_21,
50+
TASDEVICE_DSP_TAS_2781,
51+
TASDEVICE_DSP_TAS_2781_DUAL_MONO,
52+
TASDEVICE_DSP_TAS_2781_21,
53+
TASDEVICE_DSP_TAS_2781_QUAD,
54+
TASDEVICE_DSP_TAS_MAX_DEVICE
55+
};
56+
57+
struct tasdevice_fw_fixed_hdr {
58+
unsigned int fwsize;
59+
unsigned int ppcver;
60+
unsigned int drv_ver;
61+
};
62+
63+
struct tasdevice_dspfw_hdr {
64+
struct tasdevice_fw_fixed_hdr fixed_hdr;
65+
unsigned short device_family;
66+
unsigned short device;
67+
unsigned char ndev;
68+
};
69+
70+
struct tasdev_blk {
71+
int nr_retry;
72+
unsigned int type;
73+
unsigned char is_pchksum_present;
74+
unsigned char pchksum;
75+
unsigned char is_ychksum_present;
76+
unsigned char ychksum;
77+
unsigned int nr_cmds;
78+
unsigned int blk_size;
79+
unsigned int nr_subblocks;
80+
unsigned char *data;
81+
};
82+
83+
struct tasdevice_data {
84+
char name[64];
85+
unsigned int nr_blk;
86+
struct tasdev_blk *dev_blks;
87+
};
88+
89+
struct tasdevice_prog {
90+
unsigned int prog_size;
91+
struct tasdevice_data dev_data;
92+
};
93+
94+
struct tasdevice_config {
95+
unsigned int cfg_size;
96+
char name[64];
97+
struct tasdevice_data dev_data;
98+
};
99+
100+
struct tasdevice_calibration {
101+
struct tasdevice_data dev_data;
102+
};
103+
104+
struct tasdevice_fw {
105+
struct tasdevice_dspfw_hdr fw_hdr;
106+
unsigned short nr_programs;
107+
struct tasdevice_prog *programs;
108+
unsigned short nr_configurations;
109+
struct tasdevice_config *configs;
110+
unsigned short nr_calibrations;
111+
struct tasdevice_calibration *calibrations;
112+
struct device *dev;
113+
};
114+
115+
enum tasdevice_dsp_fw_state {
116+
TASDEVICE_DSP_FW_NONE = 0,
117+
TASDEVICE_DSP_FW_PENDING,
118+
TASDEVICE_DSP_FW_FAIL,
119+
TASDEVICE_DSP_FW_ALL_OK,
120+
};
121+
122+
enum tasdevice_bin_blk_type {
123+
TASDEVICE_BIN_BLK_COEFF = 1,
124+
TASDEVICE_BIN_BLK_POST_POWER_UP,
125+
TASDEVICE_BIN_BLK_PRE_SHUTDOWN,
126+
TASDEVICE_BIN_BLK_PRE_POWER_UP,
127+
TASDEVICE_BIN_BLK_POST_SHUTDOWN
128+
};
129+
130+
struct tasdevice_rca_hdr {
131+
unsigned int img_sz;
132+
unsigned int checksum;
133+
unsigned int binary_version_num;
134+
unsigned int drv_fw_version;
135+
unsigned char plat_type;
136+
unsigned char dev_family;
137+
unsigned char reserve;
138+
unsigned char ndev;
139+
unsigned char devs[TASDEVICE_DEVICE_SUM];
140+
unsigned int nconfig;
141+
unsigned int config_size[TASDEVICE_CONFIG_SUM];
142+
};
143+
144+
struct tasdev_blk_data {
145+
unsigned char dev_idx;
146+
unsigned char block_type;
147+
unsigned short yram_checksum;
148+
unsigned int block_size;
149+
unsigned int n_subblks;
150+
unsigned char *regdata;
151+
};
152+
153+
struct tasdevice_config_info {
154+
unsigned int nblocks;
155+
unsigned int real_nblocks;
156+
unsigned char active_dev;
157+
struct tasdev_blk_data **blk_data;
158+
};
159+
160+
struct tasdevice_rca {
161+
struct tasdevice_rca_hdr fw_hdr;
162+
int ncfgs;
163+
struct tasdevice_config_info **cfg_info;
164+
int profile_cfg_id;
165+
};
166+
167+
void tasdevice_select_cfg_blk(void *context, int conf_no,
168+
unsigned char block_type);
169+
void tasdevice_config_info_remove(void *context);
170+
void tasdevice_dsp_remove(void *context);
171+
int tasdevice_dsp_parser(void *context);
172+
int tasdevice_rca_parser(void *context, const struct firmware *fmw);
173+
void tasdevice_dsp_remove(void *context);
174+
void tasdevice_calbin_remove(void *context);
175+
int tasdevice_select_tuningprm_cfg(void *context, int prm,
176+
int cfg_no, int rca_conf_no);
177+
int tasdevice_prmg_load(void *context, int prm_no);
178+
int tasdevice_prmg_calibdata_load(void *context, int prm_no);
179+
void tasdevice_tuning_switch(void *context, int state);
180+
int tas2781_load_calibration(void *context, char *file_name,
181+
unsigned short i);
182+
183+
#endif

include/sound/tas2781-tlv.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
//
3+
// ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier
4+
//
5+
// Copyright (C) 2022 - 2023 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+
//
14+
15+
#ifndef __TAS2781_TLV_H__
16+
#define __TAS2781_TLV_H__
17+
18+
static const DECLARE_TLV_DB_SCALE(dvc_tlv, -10000, 100, 0);
19+
static const DECLARE_TLV_DB_SCALE(amp_vol_tlv, 1100, 50, 0);
20+
21+
#endif

include/sound/tas2781.h

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
//
3+
// ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier
4+
//
5+
// Copyright (C) 2022 - 2023 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_H__
17+
#define __TAS2781_H__
18+
19+
#include "tas2781-dsp.h"
20+
21+
/* version number */
22+
#define TAS2781_DRV_VER 1
23+
#define SMARTAMP_MODULE_NAME "tas2781"
24+
#define TAS2781_GLOBAL_ADDR 0x40
25+
#define TASDEVICE_RATES (SNDRV_PCM_RATE_44100 |\
26+
SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\
27+
SNDRV_PCM_RATE_88200)
28+
29+
#define TASDEVICE_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
30+
SNDRV_PCM_FMTBIT_S24_LE | \
31+
SNDRV_PCM_FMTBIT_S32_LE)
32+
33+
/*PAGE Control Register (available in page0 of each book) */
34+
#define TASDEVICE_PAGE_SELECT 0x00
35+
#define TASDEVICE_BOOKCTL_PAGE 0x00
36+
#define TASDEVICE_BOOKCTL_REG 127
37+
#define TASDEVICE_BOOK_ID(reg) (reg / (256 * 128))
38+
#define TASDEVICE_PAGE_ID(reg) ((reg % (256 * 128)) / 128)
39+
#define TASDEVICE_PAGE_REG(reg) ((reg % (256 * 128)) % 128)
40+
#define TASDEVICE_PGRG(reg) (reg % (256 * 128))
41+
#define TASDEVICE_REG(book, page, reg) (((book * 256 * 128) + \
42+
(page * 128)) + reg)
43+
44+
/*Software Reset */
45+
#define TAS2781_REG_SWRESET TASDEVICE_REG(0x0, 0X0, 0x01)
46+
#define TAS2781_REG_SWRESET_RESET BIT(0)
47+
48+
/*I2C Checksum */
49+
#define TASDEVICE_I2CChecksum TASDEVICE_REG(0x0, 0x0, 0x7E)
50+
51+
/* Volume control */
52+
#define TAS2781_DVC_LVL TASDEVICE_REG(0x0, 0x0, 0x1A)
53+
#define TAS2781_AMP_LEVEL TASDEVICE_REG(0x0, 0x0, 0x03)
54+
#define TAS2781_AMP_LEVEL_MASK GENMASK(5, 1)
55+
56+
#define TASDEVICE_CMD_SING_W 0x1
57+
#define TASDEVICE_CMD_BURST 0x2
58+
#define TASDEVICE_CMD_DELAY 0x3
59+
#define TASDEVICE_CMD_FIELD_W 0x4
60+
61+
enum audio_device {
62+
TAS2781 = 0,
63+
};
64+
65+
enum device_catlog_id {
66+
LENOVO = 0,
67+
OTHERS
68+
};
69+
70+
struct tasdevice {
71+
struct tasdevice_fw *cali_data_fmw;
72+
unsigned int dev_addr;
73+
unsigned int err_code;
74+
unsigned char cur_book;
75+
short cur_prog;
76+
short cur_conf;
77+
bool is_loading;
78+
bool is_loaderr;
79+
};
80+
81+
struct tasdevice_irqinfo {
82+
int irq_gpio;
83+
int irq;
84+
};
85+
86+
struct calidata {
87+
unsigned char *data;
88+
unsigned long total_sz;
89+
};
90+
91+
struct tasdevice_priv {
92+
struct tasdevice tasdevice[TASDEVICE_MAX_CHANNELS];
93+
struct tasdevice_irqinfo irq_info;
94+
struct tasdevice_rca rcabin;
95+
struct calidata cali_data;
96+
struct tasdevice_fw *fmw;
97+
struct gpio_desc *reset;
98+
struct mutex codec_lock;
99+
struct regmap *regmap;
100+
struct device *dev;
101+
struct tm tm;
102+
103+
enum device_catlog_id catlog_id;
104+
const char *acpi_subsystem_id;
105+
unsigned char cal_binaryname[TASDEVICE_MAX_CHANNELS][64];
106+
unsigned char crc8_lkp_tbl[CRC8_TABLE_SIZE];
107+
unsigned char coef_binaryname[64];
108+
unsigned char rca_binaryname[64];
109+
unsigned char dev_name[32];
110+
unsigned char ndev;
111+
unsigned int magic_num;
112+
unsigned int chip_id;
113+
unsigned int sysclk;
114+
115+
int cur_prog;
116+
int cur_conf;
117+
int fw_state;
118+
int index;
119+
void *client;
120+
void *codec;
121+
bool force_fwload_status;
122+
bool playback_started;
123+
bool isacpi;
124+
int (*fw_parse_variable_header)(struct tasdevice_priv *tas_priv,
125+
const struct firmware *fmw, int offset);
126+
int (*fw_parse_program_data)(struct tasdevice_priv *tas_priv,
127+
struct tasdevice_fw *tas_fmw,
128+
const struct firmware *fmw, int offset);
129+
int (*fw_parse_configuration_data)(struct tasdevice_priv *tas_priv,
130+
struct tasdevice_fw *tas_fmw,
131+
const struct firmware *fmw, int offset);
132+
int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv,
133+
struct tasdev_blk *block);
134+
};
135+
136+
void tas2781_reset(struct tasdevice_priv *tas_dev);
137+
int tascodec_init(struct tasdevice_priv *tas_priv, void *codec,
138+
void (*cont)(const struct firmware *fw, void *context));
139+
struct tasdevice_priv *tasdevice_kzalloc(struct i2c_client *i2c);
140+
int tasdevice_init(struct tasdevice_priv *tas_priv);
141+
void tasdevice_remove(struct tasdevice_priv *tas_priv);
142+
int tasdevice_dev_read(struct tasdevice_priv *tas_priv,
143+
unsigned short chn, unsigned int reg, unsigned int *value);
144+
int tasdevice_dev_write(struct tasdevice_priv *tas_priv,
145+
unsigned short chn, unsigned int reg, unsigned int value);
146+
int tasdevice_dev_bulk_write(
147+
struct tasdevice_priv *tas_priv, unsigned short chn,
148+
unsigned int reg, unsigned char *p_data, unsigned int n_length);
149+
int tasdevice_dev_bulk_read(struct tasdevice_priv *tas_priv,
150+
unsigned short chn, unsigned int reg, unsigned char *p_data,
151+
unsigned int n_length);
152+
int tasdevice_dev_update_bits(
153+
struct tasdevice_priv *tasdevice, unsigned short chn,
154+
unsigned int reg, unsigned int mask, unsigned int value);
155+
int tasdevice_amp_putvol(struct tasdevice_priv *tas_priv,
156+
struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
157+
int tasdevice_amp_getvol(struct tasdevice_priv *tas_priv,
158+
struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
159+
int tasdevice_digital_putvol(struct tasdevice_priv *tas_priv,
160+
struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
161+
int tasdevice_digital_getvol(struct tasdevice_priv *tas_priv,
162+
struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
163+
164+
#endif /* __TAS2781_H__ */

0 commit comments

Comments
 (0)