Skip to contentSkip to conversation

ASoc: tas2783: Add tas2783 codec driver

PATCH Superseded Shenghao Ding 2 participants 4 messages Mar 19, 2024 – Mar 26, 2024

Subsystems (3)

v11 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Shenghao Ding

author maintainer
#0 lore raw

PATCH v11 1/1 ASoc: tas2783: Add tas2783 codec driver

The tas2783 is a smart audio amplifier with integrated MIPI SoundWire interface (Version 1.2.1 compliant), I2C, and I2S/TDM interfaces designed for portable applications. An on-chip DSP supports Texas Instruments SmartAmp speaker protection algorithm. The integrated speaker voltage and current sense provides for real-time monitoring of loudspeakers.

The ASoC component provides the majority of the functionality of the device, all the audio functions.

---
Change in v11:
- simplify tasdevice_set_sdw_stream
- fixed some Linux coding style
- fixed the spelling mistakes
- Select left/right channel based on unique id
- a longer description has been added
- remove unused crc8 in KCONFIG
- Invert of RE here means reciprocal of RE
- correct indentation
- correct the wrong pow calibrated register
- correct comment on RESET register
- fixed usually lines don't end with an open parenthesis
- fixed tasdevice_sdw_shutdown
- use defines for function, entity, etc. for readable
- remove unnecessary codec_lock in component_probe()
- remove struct sdw_stream_data
- remove unused macro definitions
- use BIT(2) and BIT(1) instead of 0x2 and 0x1
- implement pm_runtime
- reg_start is u8, reg_start + i only adds i byte, it should be reg_start + i * 4, because the calibration values
- fixed total_sz in tas2783_calibration
- add a define for TASDEVICE_REG(0, 0, 0x0a)
- rework macro style in header file
- Add select CRC32
- rewrite the mute and the return value handling
- Add comments on bin file
- Add link_id into the fw name to distinguish the same sdw id on different sdw id.
- remove unnecessary mutex_lock
- use set_active() in tasdevice_io_init and move all other parts in the probe.
- move pm_runtime_get_noresume to the probe
- fix the return value of putvol function
- add put_noidle in tasdevice_sdw_remove
- remove unused header file(of.h)
- correct the style of the multi-line comment
- Set the readable registers in tas2783_readable_register for debugfs
- Use new PM macros
- Use default put and get inline SOC_SINGLE_RANGE_TLV and SOC_SINGLE_SX_TLV
- Use respective %pt to log the calibrated time
- Remove unnecessary struct tm
- Add trailing comma tasdevice_dapm_widgets and tasdevice_audio_map
- Rewrite the return value handling in tasdevice_sdw_probe
- use dev_num instead of id.unique_id
- rework the log
- Add code to check the size of calibrated data in UEFI
- Add description of Layout of calibrated Data in UEFI
- switch back link_id and unique_id to identify the devcie
- unique_id offset as the device index of the calibrated data
- update calibrated data layout stored in UEFI, add link_id and unique_id into the calibrated data in case of tas2783 sitting in different SDQW buses.
- correct the wrong unique_id
- set the unique_id as hex style in dsp bin file name
- use __func__ in the dev_err message in two identical logs intas2783_apply_calibv1/v2.
- In tas2783_apply_calibv2, the very least move initializations to a different line.
- No need for separate j variable, reuse i in tasdevice_read_prop.
- remove unused "struct sdw_bus_params params", unsigned char dev_name[32] pstream, and chip_id
- define dspfw_binaryname as a local variable in tasdevice_comp_probe.
- reduce a lot of indentation in tasdevice_mute and spilte tasdevice_mute into tasdevice_enable_echo_ref and tasdevice_playback
- remove tas2783_reg_defaults
- use REGCACHE_MAPLE instead of REGCACHE_RBTREE
- define fw_node_sz to store the node size

---
 sound/soc/codecs/Kconfig       |  16 +
 sound/soc/codecs/Makefile      |   2 +
 sound/soc/codecs/tas2783-sdw.c | 893 +++++++++++++++++++++++++++++++++
 sound/soc/codecs/tas2783.h     | 107 ++++
 4 files changed, 1018 insertions(+)
 create mode 100644 sound/soc/codecs/tas2783-sdw.c
 create mode 100644 sound/soc/codecs/tas2783.h
sound/soc/codecs/Kconfig +16 -0
index f78ea2f86fa6..939384837d5e 100644
@@ -248,6 +248,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_TAS2781_COMLIB
 	imply SND_SOC_TAS2781_FMWLIB
 	imply SND_SOC_TAS2781_I2C
+	imply SND_SOC_TAS2783
 	imply SND_SOC_TAS5086
 	imply SND_SOC_TAS571X
 	imply SND_SOC_TAS5720
@@ -1880,6 +1881,21 @@ config SND_SOC_TAS2781_I2C
 	  algo coefficient setting, for one, two or even multiple TAS2781
 	  chips.
 
+config SND_SOC_TAS2783
+	tristate "Texas Instruments TAS2783 speaker amplifier (sdw)"
+	depends on SOUNDWIRE
+	depends on EFI
+	select REGMAP
+	select REGMAP_SOUNDWIRE
+	select CRC32
+	select CRC32_SARWATE
+	help
+	  Enable support for Texas Instruments TAS2783 Smart Amplifier
+	  Digital input mono Class-D and DSP-inside audio power amplifiers.
+	  TAS2783 supports the MIPI SoundWire v1.2 compatible interface
+	  for audio and control data. At the end of calibrated data appends
+	  the crc data with crc32_sarwate for error detection.
+
 config SND_SOC_TAS5086
 	tristate "Texas Instruments TAS5086 speaker amplifier"
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index 7c075539dc47..6f27f810affc 100644
@@ -287,6 +287,7 @@ snd-soc-tas2770-objs := tas2770.o
 snd-soc-tas2781-comlib-objs := tas2781-comlib.o
 snd-soc-tas2781-fmwlib-objs := tas2781-fmwlib.o
 snd-soc-tas2781-i2c-objs := tas2781-i2c.o
+snd-soc-tas2783-objs := tas2783-sdw.o
 snd-soc-tfa9879-objs := tfa9879.o
 snd-soc-tfa989x-objs := tfa989x.o
 snd-soc-tlv320adc3xxx-objs := tlv320adc3xxx.o
@@ -672,6 +673,7 @@ obj-$(CONFIG_SND_SOC_TAS2780)	+= snd-soc-tas2780.o
 obj-$(CONFIG_SND_SOC_TAS2781_COMLIB)	+= snd-soc-tas2781-comlib.o
 obj-$(CONFIG_SND_SOC_TAS2781_FMWLIB)	+= snd-soc-tas2781-fmwlib.o
 obj-$(CONFIG_SND_SOC_TAS2781_I2C)	+= snd-soc-tas2781-i2c.o
+obj-$(CONFIG_SND_SOC_TAS2783)	+= snd-soc-tas2783.o
 obj-$(CONFIG_SND_SOC_TAS5086)	+= snd-soc-tas5086.o
 obj-$(CONFIG_SND_SOC_TAS571X)	+= snd-soc-tas571x.o
 obj-$(CONFIG_SND_SOC_TAS5720)	+= snd-soc-tas5720.o
sound/soc/codecs/tas2783-sdw.c new file +893 -0

893 lines not on this page · raw message

sound/soc/codecs/tas2783.h new file +107 -0

107 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw

sound/soc/codecs/tas2783-sdw.c line 58

Quoted 10 lines
sound/soc/codecs/tas2783-sdw.c new file +9 -0
+static bool tas2783_readable_register(struct device *dev,
+	unsigned int reg)
+{
+	switch (reg) {
+	/* Page 0 */
+	case 0x8000 ... 0x807F:
+		return true;
+	default:
+		return false;

so only the registers in 0x8000..807F are readable. That's the usual non-SDCA vendor-specific areas ...

sound/soc/codecs/tas2783-sdw.c line 84

Quoted 6 lines
sound/soc/codecs/tas2783-sdw.c new file +6 -0
+static const struct regmap_config tasdevice_regmap = {
+	.reg_bits = 32,
+	.val_bits = 8,
+	.readable_reg = tas2783_readable_register,
+	.volatile_reg = tas2783_volatile_register,
+	.max_register = 0x44ffffff,

.... but here you show support for a much larger register set in SDCA space.

I am having a hard-time believing that none of these SDCA registers are readable?

Quoted 26 lines
sound/soc/codecs/tas2783-sdw.c new file +26 -0
+static void tas2783_calibration(struct tasdevice_priv *tas_dev)
+{
+	efi_guid_t efi_guid = EFI_GUID(0x1f52d2a1, 0xbb3a, 0x457d, 0xbc,
+			0x09, 0x43, 0xa3, 0xf4, 0x31, 0x0a, 0x92);
+	static efi_char16_t efi_name[] = L"CALI_DATA";
+	struct calibration_data cali_data;
+	unsigned int *tmp_val;
+	unsigned int crc;
+	efi_status_t status;
+
+	cali_data.total_sz = 0;
+
+	status = efi.get_variable(efi_name, &efi_guid, NULL,
+		&cali_data.total_sz, NULL);
+	if (status == EFI_BUFFER_TOO_SMALL
+		&& cali_data.total_sz < TAS2783_MAX_CALIDATA_SIZE) {
+		status = efi.get_variable(efi_name, &efi_guid, NULL,
+			&cali_data.total_sz,
+			cali_data.data);
+		dev_dbg(tas_dev->dev, "%s: cali get %lx bytes result:%ld\n",
+			__func__, cali_data.total_sz, status);
+	}
+	if (status != 0) {
+		/* Failed got calibration data from EFI. */
+		dev_dbg(tas_dev->dev, "No calibration data in UEFI.");
+		return;

sound/soc/codecs/tas2783-sdw.c line 253

Quoted 10 lines
sound/soc/codecs/tas2783-sdw.c new file +10 -0
+	}
+
+	tmp_val = (unsigned int *)cali_data.data;
+
+	/* Check Calibrated Data V1 */
+	crc = crc32(~0, cali_data.data, TAS2783_CALIDATAV1_BYTE_SIZE) ^ ~0;
+	if (crc == tmp_val[TAS2783_CALIDATAV1_CRC32_INDX]) {
+		/* Date and time of when calibration was done. */
+		tas2783_apply_calibv1(tas_dev, tmp_val);
+		dev_dbg(tas_dev->dev, "V1: %ptTs",

Is this really needed/helpful?

Quoted 6 lines
sound/soc/codecs/tas2783-sdw.c new file +6 -0
+			&tmp_val[TAS2783_CALIDATAV1_TIMESTAMP_INDX]);
+		return;
+	}
+
+	/* Check Calibrated Data V2 */
+	if (tmp_val[0] == 2783) {

sound/soc/codecs/tas2783-sdw.c line 269

Quoted 10 lines
sound/soc/codecs/tas2783-sdw.c new file +10 -0
+		const struct calibdatav2_info calib_info = {
+			.number_of_devices = tmp_val[1],
+			.crc32_indx = 3 + tmp_val[1] * 6,
+			.byt_sz = 12 + tmp_val[1] * 24,
+			.cali_data = &tmp_val[3]
+		};
+
+		if (calib_info.number_of_devices > TAS2783_MAX_DEV_NUM ||
+			calib_info.number_of_devices == 0) {
+			dev_dbg(tas_dev->dev, "No dev in calibrated data V2.");

the log is not aligned with the first condition where you have too many devices.

It's not clear why it's not an error.

sound/soc/codecs/tas2783-sdw.c line 276

Quoted 7 lines
sound/soc/codecs/tas2783-sdw.c new file +7 -0
+			return;
+		}
+		crc = crc32(~0, cali_data.data, calib_info.byt_sz)
+			^ ~0;
+		if (crc == tmp_val[calib_info.crc32_indx]) {
+			tas2783_apply_calibv2(tas_dev, &calib_info);
+			dev_dbg(tas_dev->dev, "V2: %ptTs",

same, is this needed?

sound/soc/codecs/tas2783-sdw.c line 281

Quoted 5 lines
sound/soc/codecs/tas2783-sdw.c new file +5 -0
+				&tmp_val[TAS2783_CALIDATAV2_TIMESTAMP_INDX]);
+		} else {
+			dev_dbg(tas_dev->dev,
+				"V2: CRC 0x%08x not match 0x%08x\n",
+				crc, tmp_val[calib_info.crc32_indx]);

is this not an error?

sound/soc/codecs/tas2783-sdw.c line 286

Quoted 5 lines
sound/soc/codecs/tas2783-sdw.c new file +5 -0
+		}
+	} else {
+		dev_err(tas_dev->dev, "Non-2783 chip\n");
+	}
+}

the error level seem inconsistent and it's not clear why errors are ignored?

author maintainer
#2 lore raw

Hi Guy
Thanks for your comments. Feedback inline

Quoted 26 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Tuesday, March 19, 2024 11:35 PM
To: Ding, Shenghao <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; yung- [email protected]; Lu, Kevin <[email protected]>; [email protected]; Xu, Baojun <[email protected]>; [email protected]; [email protected]; Navada Kanyana, Mukund <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v11] ASoc: tas2783: Add tas2783 codec driver

Review

Quoted 4 lines
(quoted diff) +4 -0
+static bool tas2783_readable_register(struct device *dev, > +
+unsigned int reg) > +{ > + switch (reg) { > + /* Page 0 */ > + case
+0x8000 .. . 0x807F: > + return true; > + default: > + return false;
+so only the registers

ZjQcmQRYFpfptBannerStart
This message was sent from outside of Texas Instruments.
Do not click links or open attachments unless you recognize the source of this email and know the content is safe.

ZjQcmQRYFpfptBannerEnd

Quoted 1 line

+static bool tas2783_readable_register(struct device *dev,

................................................

Quoted 12 lines

sound/soc/codecs/tas2783-sdw.c

Quoted 11 lines
sound/soc/codecs/tas2783-sdw.c new file +11 -0
+
+	/* Check Calibrated Data V2 */
+	if (tmp_val[0] == 2783) {
+		const struct calibdatav2_info calib_info = {
+			.number_of_devices = tmp_val[1],
+			.crc32_indx = 3 + tmp_val[1] * 6,
+			.byt_sz = 12 + tmp_val[1] * 24,
+			.cali_data = &tmp_val[3]
+		};
+
+		if (calib_info.number_of_devices >

TAS2783_MAX_DEV_NUM ||

Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+			calib_info.number_of_devices == 0) {
+			dev_dbg(tas_dev->dev, "No dev in calibrated data

V2.");

the log is not aligned with the first condition where you have too many devices.

It's not clear why it's not an error.

playback still work without calibrated data stored in UEFI, for example bypass mode. Even if in case of bypass mode, algo can still work with default calibrated data. So, not an error.

Quoted 10 lines

sound/soc/codecs/tas2783-sdw.c line 276

Quoted 8 lines
sound/soc/codecs/tas2783-sdw.c new file +7 -0
+			return;
+		}
+		crc = crc32(~0, cali_data.data, calib_info.byt_sz)
+			^ ~0;
+		if (crc == tmp_val[calib_info.crc32_indx]) {
+			tas2783_apply_calibv2(tas_dev, &calib_info);
+			dev_dbg(tas_dev->dev, "V2: %ptTs",

same, is this needed?

Accepted.

Quoted 9 lines
Quoted 1 line

+

	&tmp_val[TAS2783_CALIDATAV2_TIMESTAMP_INDX]);

sound/soc/codecs/tas2783-sdw.c line 281

Quoted 4 lines
sound/soc/codecs/tas2783-sdw.c new file +4 -0
+		} else {
+			dev_dbg(tas_dev->dev,
+				"V2: CRC 0x%08x not match 0x%08x\n",
+				crc, tmp_val[calib_info.crc32_indx]);

is this not an error?

Quoted 7 lines

sound/soc/codecs/tas2783-sdw.c line 286

Quoted 5 lines
sound/soc/codecs/tas2783-sdw.c new file +5 -0
+		}
+	} else {
+		dev_err(tas_dev->dev, "Non-2783 chip\n");
+	}
+}

the error level seem inconsistent and it's not clear why errors are ignored?

Maybe set them as dev_warn?

#3 lore raw
Quoted 17 lines
Quoted 17 lines

sound/soc/codecs/tas2783-sdw.c

Quoted 12 lines
sound/soc/codecs/tas2783-sdw.c new file +11 -0
+
+	/* Check Calibrated Data V2 */
+	if (tmp_val[0] == 2783) {
+		const struct calibdatav2_info calib_info = {
+			.number_of_devices = tmp_val[1],
+			.crc32_indx = 3 + tmp_val[1] * 6,
+			.byt_sz = 12 + tmp_val[1] * 24,
+			.cali_data = &tmp_val[3]
+		};
+
+		if (calib_info.number_of_devices >

TAS2783_MAX_DEV_NUM ||

Review

Quoted 2 lines
(quoted diff) +2 -0
+			calib_info.number_of_devices == 0) {
+			dev_dbg(tas_dev->dev, "No dev in calibrated data

V2.");

Quoted 7 lines
Quoted 4 lines

the log is not aligned with the first condition where you have too many devices.

It's not clear why it's not an error.

playback still work without calibrated data stored in UEFI, for example bypass mode. Even if in case of bypass mode, algo can still work with default calibrated data. So, not an error.

I would use a dev_info with a clearer message that defaults are used, e.g. along the lines of

dev_info(tas_dev->dev, "using default calibration data, no device found in EFI data v2").

dev_warn would work as well if this is really not expected.