Linux Audio

Check our new training course

Loading...
v6.8
  1/* SPDX-License-Identifier: GPL-2.0 */
  2//
  3// ALSA SoC Texas Instruments TAS2563/TAS2781 Audio Smart Amplifier
  4//
  5// Copyright (C) 2022 - 2023 Texas Instruments Incorporated
  6// https://www.ti.com
  7//
  8// The TAS2563/TAS2781 driver implements a flexible and configurable
  9// algo coefficient setting for one, two, or even multiple
 10// TAS2563/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 TAS2563_GLOBAL_ADDR	0x48
 26#define TASDEVICE_RATES			(SNDRV_PCM_RATE_44100 |\
 27	SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\
 28	SNDRV_PCM_RATE_88200)
 29
 30#define TASDEVICE_FORMATS		(SNDRV_PCM_FMTBIT_S16_LE | \
 31	SNDRV_PCM_FMTBIT_S24_LE | \
 32	SNDRV_PCM_FMTBIT_S32_LE)
 33
 34/*PAGE Control Register (available in page0 of each book) */
 35#define TASDEVICE_PAGE_SELECT		0x00
 36#define TASDEVICE_BOOKCTL_PAGE		0x00
 37#define TASDEVICE_BOOKCTL_REG		127
 38#define TASDEVICE_BOOK_ID(reg)		(reg / (256 * 128))
 39#define TASDEVICE_PAGE_ID(reg)		((reg % (256 * 128)) / 128)
 40#define TASDEVICE_PAGE_REG(reg)		((reg % (256 * 128)) % 128)
 41#define TASDEVICE_PGRG(reg)		(reg % (256 * 128))
 42#define TASDEVICE_REG(book, page, reg)	(((book * 256 * 128) + \
 43					(page * 128)) + reg)
 44
 45/*Software Reset */
 46#define TAS2781_REG_SWRESET		TASDEVICE_REG(0x0, 0X0, 0x01)
 47#define TAS2781_REG_SWRESET_RESET	BIT(0)
 48
 49/*I2C Checksum */
 50#define TASDEVICE_I2CChecksum		TASDEVICE_REG(0x0, 0x0, 0x7E)
 51
 
 
 
 
 
 52/* Volume control */
 
 53#define TAS2781_DVC_LVL			TASDEVICE_REG(0x0, 0x0, 0x1A)
 54#define TAS2781_AMP_LEVEL		TASDEVICE_REG(0x0, 0x0, 0x03)
 55#define TAS2781_AMP_LEVEL_MASK		GENMASK(5, 1)
 56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 57#define TASDEVICE_CMD_SING_W		0x1
 58#define TASDEVICE_CMD_BURST		0x2
 59#define TASDEVICE_CMD_DELAY		0x3
 60#define TASDEVICE_CMD_FIELD_W		0x4
 61
 62enum audio_device {
 63	TAS2563,
 64	TAS2781,
 65};
 66
 67enum device_catlog_id {
 68	LENOVO = 0,
 69	OTHERS
 70};
 71
 
 
 
 
 
 
 
 72struct tasdevice {
 
 73	struct tasdevice_fw *cali_data_fmw;
 74	unsigned int dev_addr;
 75	unsigned int err_code;
 76	unsigned char cur_book;
 77	short cur_prog;
 78	short cur_conf;
 79	bool is_loading;
 80	bool is_loaderr;
 81};
 82
 83struct tasdevice_irqinfo {
 84	int irq_gpio;
 85	int irq;
 
 
 
 86};
 87
 88struct calidata {
 89	unsigned char *data;
 90	unsigned long total_sz;
 
 
 91};
 92
 93struct tasdevice_priv {
 94	struct tasdevice tasdevice[TASDEVICE_MAX_CHANNELS];
 95	struct tasdevice_irqinfo irq_info;
 96	struct tasdevice_rca rcabin;
 97	struct calidata cali_data;
 98	struct tasdevice_fw *fmw;
 
 99	struct gpio_desc *reset;
100	struct mutex codec_lock;
101	struct regmap *regmap;
102	struct device *dev;
103	struct tm tm;
104
105	enum device_catlog_id catlog_id;
106	const char *acpi_subsystem_id;
107	unsigned char cal_binaryname[TASDEVICE_MAX_CHANNELS][64];
108	unsigned char crc8_lkp_tbl[CRC8_TABLE_SIZE];
109	unsigned char coef_binaryname[64];
110	unsigned char rca_binaryname[64];
111	unsigned char dev_name[32];
 
112	unsigned char ndev;
113	unsigned int magic_num;
114	unsigned int chip_id;
115	unsigned int sysclk;
116
 
117	int cur_prog;
118	int cur_conf;
119	int fw_state;
120	int index;
121	void *client;
122	void *codec;
123	bool force_fwload_status;
124	bool playback_started;
125	bool isacpi;
 
126	unsigned int global_addr;
127
128	int (*fw_parse_variable_header)(struct tasdevice_priv *tas_priv,
129		const struct firmware *fmw, int offset);
130	int (*fw_parse_program_data)(struct tasdevice_priv *tas_priv,
131		struct tasdevice_fw *tas_fmw,
132		const struct firmware *fmw, int offset);
133	int (*fw_parse_configuration_data)(struct tasdevice_priv *tas_priv,
134		struct tasdevice_fw *tas_fmw,
135		const struct firmware *fmw, int offset);
136	int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv,
137		struct tasdev_blk *block);
138
139	int (*save_calibration)(struct tasdevice_priv *tas_priv);
140	void (*apply_calibration)(struct tasdevice_priv *tas_priv);
141};
142
143void tas2781_reset(struct tasdevice_priv *tas_dev);
144int tascodec_init(struct tasdevice_priv *tas_priv, void *codec,
145	struct module *module,
146	void (*cont)(const struct firmware *fw, void *context));
147struct tasdevice_priv *tasdevice_kzalloc(struct i2c_client *i2c);
148int tasdevice_init(struct tasdevice_priv *tas_priv);
149void tasdevice_remove(struct tasdevice_priv *tas_priv);
150int tasdevice_save_calibration(struct tasdevice_priv *tas_priv);
151void tasdevice_apply_calibration(struct tasdevice_priv *tas_priv);
 
 
152int tasdevice_dev_read(struct tasdevice_priv *tas_priv,
153	unsigned short chn, unsigned int reg, unsigned int *value);
154int tasdevice_dev_write(struct tasdevice_priv *tas_priv,
155	unsigned short chn, unsigned int reg, unsigned int value);
156int tasdevice_dev_bulk_write(
157	struct tasdevice_priv *tas_priv, unsigned short chn,
158	unsigned int reg, unsigned char *p_data, unsigned int n_length);
159int tasdevice_dev_bulk_read(struct tasdevice_priv *tas_priv,
160	unsigned short chn, unsigned int reg, unsigned char *p_data,
161	unsigned int n_length);
162int tasdevice_dev_update_bits(
163	struct tasdevice_priv *tasdevice, unsigned short chn,
164	unsigned int reg, unsigned int mask, unsigned int value);
165int tasdevice_amp_putvol(struct tasdevice_priv *tas_priv,
166	struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
167int tasdevice_amp_getvol(struct tasdevice_priv *tas_priv,
168	struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
169int tasdevice_digital_putvol(struct tasdevice_priv *tas_priv,
170	struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
171int tasdevice_digital_getvol(struct tasdevice_priv *tas_priv,
172	struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
173
174#endif /* __TAS2781_H__ */
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0 */
  2//
  3// ALSA SoC Texas Instruments TAS2563/TAS2781 Audio Smart Amplifier
  4//
  5// Copyright (C) 2022 - 2024 Texas Instruments Incorporated
  6// https://www.ti.com
  7//
  8// The TAS2563/TAS2781 driver implements a flexible and configurable
  9// algo coefficient setting for one, two, or even multiple
 10// TAS2563/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 TAS2563_GLOBAL_ADDR	0x48
 26#define TASDEVICE_RATES			(SNDRV_PCM_RATE_44100 |\
 27	SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\
 28	SNDRV_PCM_RATE_88200)
 29
 30#define TASDEVICE_FORMATS		(SNDRV_PCM_FMTBIT_S16_LE | \
 31	SNDRV_PCM_FMTBIT_S24_LE | \
 32	SNDRV_PCM_FMTBIT_S32_LE)
 33
 34/*PAGE Control Register (available in page0 of each book) */
 35#define TASDEVICE_PAGE_SELECT		0x00
 36#define TASDEVICE_BOOKCTL_PAGE		0x00
 37#define TASDEVICE_BOOKCTL_REG		127
 38#define TASDEVICE_BOOK_ID(reg)		(reg / (256 * 128))
 39#define TASDEVICE_PAGE_ID(reg)		((reg % (256 * 128)) / 128)
 40#define TASDEVICE_PAGE_REG(reg)		((reg % (256 * 128)) % 128)
 41#define TASDEVICE_PGRG(reg)		(reg % (256 * 128))
 42#define TASDEVICE_REG(book, page, reg)	(((book * 256 * 128) + \
 43					(page * 128)) + reg)
 44
 45/*Software Reset */
 46#define TASDEVICE_REG_SWRESET		TASDEVICE_REG(0x0, 0X0, 0x01)
 47#define TASDEVICE_REG_SWRESET_RESET	BIT(0)
 48
 49/*I2C Checksum */
 50#define TASDEVICE_I2CChecksum		TASDEVICE_REG(0x0, 0x0, 0x7E)
 51
 52/* XM_340 */
 53#define	TASDEVICE_XM_A1_REG	TASDEVICE_REG(0x64, 0x63, 0x3c)
 54/* XM_341 */
 55#define	TASDEVICE_XM_A2_REG	TASDEVICE_REG(0x64, 0x63, 0x38)
 56
 57/* Volume control */
 58#define TAS2563_DVC_LVL			TASDEVICE_REG(0x00, 0x02, 0x0C)
 59#define TAS2781_DVC_LVL			TASDEVICE_REG(0x0, 0x0, 0x1A)
 60#define TAS2781_AMP_LEVEL		TASDEVICE_REG(0x0, 0x0, 0x03)
 61#define TAS2781_AMP_LEVEL_MASK		GENMASK(5, 1)
 62
 63#define TAS2563_IDLE		TASDEVICE_REG(0x00, 0x00, 0x3e)
 64#define TAS2563_PRM_R0_REG		TASDEVICE_REG(0x00, 0x0f, 0x34)
 65
 66#define TAS2563_RUNTIME_RE_REG_TF	TASDEVICE_REG(0x64, 0x02, 0x70)
 67#define TAS2563_RUNTIME_RE_REG		TASDEVICE_REG(0x64, 0x02, 0x48)
 68
 69#define TAS2563_PRM_ENFF_REG		TASDEVICE_REG(0x00, 0x0d, 0x54)
 70#define TAS2563_PRM_DISTCK_REG		TASDEVICE_REG(0x00, 0x0d, 0x58)
 71#define TAS2563_PRM_TE_SCTHR_REG	TASDEVICE_REG(0x00, 0x0f, 0x60)
 72#define TAS2563_PRM_PLT_FLAG_REG	TASDEVICE_REG(0x00, 0x0d, 0x74)
 73#define TAS2563_PRM_SINEGAIN_REG	TASDEVICE_REG(0x00, 0x0d, 0x7c)
 74/* prm_Int_B0 */
 75#define TAS2563_TE_TA1_REG		TASDEVICE_REG(0x00, 0x10, 0x0c)
 76/* prm_Int_A1 */
 77#define TAS2563_TE_TA1_AT_REG		TASDEVICE_REG(0x00, 0x10, 0x10)
 78/* prm_TE_Beta */
 79#define TAS2563_TE_TA2_REG		TASDEVICE_REG(0x00, 0x0f, 0x64)
 80/* prm_TE_Beta1 */
 81#define TAS2563_TE_AT_REG		TASDEVICE_REG(0x00, 0x0f, 0x68)
 82/* prm_TE_1_Beta1 */
 83#define TAS2563_TE_DT_REG		TASDEVICE_REG(0x00, 0x0f, 0x70)
 84
 85#define TAS2781_PRM_INT_MASK_REG	TASDEVICE_REG(0x00, 0x00, 0x3b)
 86#define TAS2781_PRM_CLK_CFG_REG		TASDEVICE_REG(0x00, 0x00, 0x5c)
 87#define TAS2781_PRM_RSVD_REG		TASDEVICE_REG(0x00, 0x01, 0x19)
 88#define TAS2781_PRM_TEST_57_REG		TASDEVICE_REG(0x00, 0xfd, 0x39)
 89#define TAS2781_PRM_TEST_62_REG		TASDEVICE_REG(0x00, 0xfd, 0x3e)
 90#define TAS2781_PRM_PVDD_UVLO_REG	TASDEVICE_REG(0x00, 0x00, 0x71)
 91#define TAS2781_PRM_CHNL_0_REG		TASDEVICE_REG(0x00, 0x00, 0x03)
 92#define TAS2781_PRM_NG_CFG0_REG		TASDEVICE_REG(0x00, 0x00, 0x35)
 93#define TAS2781_PRM_IDLE_CH_DET_REG	TASDEVICE_REG(0x00, 0x00, 0x66)
 94#define TAS2781_PRM_PLT_FLAG_REG	TASDEVICE_REG(0x00, 0x14, 0x38)
 95#define TAS2781_PRM_SINEGAIN_REG	TASDEVICE_REG(0x00, 0x14, 0x40)
 96#define TAS2781_PRM_SINEGAIN2_REG	TASDEVICE_REG(0x00, 0x14, 0x44)
 97
 98#define TAS2781_TEST_UNLOCK_REG		TASDEVICE_REG(0x00, 0xFD, 0x0D)
 99#define TAS2781_TEST_PAGE_UNLOCK	0x0D
100
101#define TAS2781_RUNTIME_LATCH_RE_REG	TASDEVICE_REG(0x00, 0x00, 0x49)
102#define TAS2781_RUNTIME_RE_REG_TF	TASDEVICE_REG(0x64, 0x62, 0x48)
103#define TAS2781_RUNTIME_RE_REG		TASDEVICE_REG(0x64, 0x63, 0x44)
104
105#define TASDEVICE_CMD_SING_W		0x1
106#define TASDEVICE_CMD_BURST		0x2
107#define TASDEVICE_CMD_DELAY		0x3
108#define TASDEVICE_CMD_FIELD_W		0x4
109
110enum audio_device {
111	TAS2563,
112	TAS2781,
113};
114
115enum device_catlog_id {
116	LENOVO = 0,
117	OTHERS
118};
119
120struct bulk_reg_val {
121	int reg;
122	unsigned char val[4];
123	unsigned char val_len;
124	bool is_locked;
125};
126
127struct tasdevice {
128	struct bulk_reg_val *cali_data_backup;
129	struct tasdevice_fw *cali_data_fmw;
130	unsigned int dev_addr;
131	unsigned int err_code;
132	unsigned char cur_book;
133	short cur_prog;
134	short cur_conf;
135	bool is_loading;
136	bool is_loaderr;
137};
138
139struct cali_reg {
140	unsigned int r0_reg;
141	unsigned int r0_low_reg;
142	unsigned int invr0_reg;
143	unsigned int pow_reg;
144	unsigned int tlimit_reg;
145};
146
147struct calidata {
148	unsigned char *data;
149	unsigned long total_sz;
150	struct cali_reg cali_reg_array;
151	unsigned int cali_dat_sz_per_dev;
152};
153
154struct tasdevice_priv {
155	struct tasdevice tasdevice[TASDEVICE_MAX_CHANNELS];
 
156	struct tasdevice_rca rcabin;
157	struct calidata cali_data;
158	struct tasdevice_fw *fmw;
159	struct gpio_desc *speaker_id;
160	struct gpio_desc *reset;
161	struct mutex codec_lock;
162	struct regmap *regmap;
163	struct device *dev;
164	struct tm tm;
165
166	enum device_catlog_id catlog_id;
 
167	unsigned char cal_binaryname[TASDEVICE_MAX_CHANNELS][64];
168	unsigned char crc8_lkp_tbl[CRC8_TABLE_SIZE];
169	unsigned char coef_binaryname[64];
170	unsigned char rca_binaryname[64];
171	unsigned char dev_name[32];
172	const char *name_prefix;
173	unsigned char ndev;
174	unsigned int magic_num;
175	unsigned int chip_id;
176	unsigned int sysclk;
177
178	int irq;
179	int cur_prog;
180	int cur_conf;
181	int fw_state;
182	int index;
183	void *client;
184	void *codec;
185	bool force_fwload_status;
186	bool playback_started;
187	bool isacpi;
188	bool is_user_space_calidata;
189	unsigned int global_addr;
190
191	int (*fw_parse_variable_header)(struct tasdevice_priv *tas_priv,
192		const struct firmware *fmw, int offset);
193	int (*fw_parse_program_data)(struct tasdevice_priv *tas_priv,
194		struct tasdevice_fw *tas_fmw,
195		const struct firmware *fmw, int offset);
196	int (*fw_parse_configuration_data)(struct tasdevice_priv *tas_priv,
197		struct tasdevice_fw *tas_fmw,
198		const struct firmware *fmw, int offset);
199	int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv,
200		struct tasdev_blk *block);
201
202	int (*save_calibration)(struct tasdevice_priv *tas_priv);
203	void (*apply_calibration)(struct tasdevice_priv *tas_priv);
204};
205
206void tasdevice_reset(struct tasdevice_priv *tas_dev);
207int tascodec_init(struct tasdevice_priv *tas_priv, void *codec,
208	struct module *module,
209	void (*cont)(const struct firmware *fw, void *context));
210struct tasdevice_priv *tasdevice_kzalloc(struct i2c_client *i2c);
211int tasdevice_init(struct tasdevice_priv *tas_priv);
212void tasdevice_remove(struct tasdevice_priv *tas_priv);
213int tasdevice_save_calibration(struct tasdevice_priv *tas_priv);
214void tasdevice_apply_calibration(struct tasdevice_priv *tas_priv);
215int tasdev_chn_switch(struct tasdevice_priv *tas_priv,
216	unsigned short chn);
217int tasdevice_dev_read(struct tasdevice_priv *tas_priv,
218	unsigned short chn, unsigned int reg, unsigned int *value);
219int tasdevice_dev_write(struct tasdevice_priv *tas_priv,
220	unsigned short chn, unsigned int reg, unsigned int value);
221int tasdevice_dev_bulk_write(
222	struct tasdevice_priv *tas_priv, unsigned short chn,
223	unsigned int reg, unsigned char *p_data, unsigned int n_length);
224int tasdevice_dev_bulk_read(struct tasdevice_priv *tas_priv,
225	unsigned short chn, unsigned int reg, unsigned char *p_data,
226	unsigned int n_length);
227int tasdevice_dev_update_bits(
228	struct tasdevice_priv *tasdevice, unsigned short chn,
229	unsigned int reg, unsigned int mask, unsigned int value);
230int tasdevice_amp_putvol(struct tasdevice_priv *tas_priv,
231	struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
232int tasdevice_amp_getvol(struct tasdevice_priv *tas_priv,
233	struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
234int tasdevice_digital_putvol(struct tasdevice_priv *tas_priv,
235	struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
236int tasdevice_digital_getvol(struct tasdevice_priv *tas_priv,
237	struct snd_ctl_elem_value *ucontrol, struct soc_mixer_control *mc);
238
239#endif /* __TAS2781_H__ */