ASoC: tas2781: Add tas2781 driver
Subsystems (3)
PATCH v9 1/1 ASoC: tas2781: Add tas2781 driver
Create tas2781 driver.
---
Changes in v9:
- rewording some commets
- Add comments on fimware parsing error handling -- all the memory resources will be released in the end of tasdevice_rca_ready (fw_parse_data, fw_parse_program_data & fw_parse_configuration_data).
- Add comments on fw_parse_calibration_data -- DSP can still work with default calibrated data, memory resource related to calibrated data will be released in the tasdevice_codec_remove.
modified: sound/soc/codecs/Kconfig
modified: sound/soc/codecs/Makefile
new file: sound/soc/codecs/tas2781-dsp.c
new file: sound/soc/codecs/tas2781-dsp.h
new file: sound/soc/codecs/tas2781-i2c.c
new file: sound/soc/codecs/tas2781.h
--- sound/soc/codecs/Kconfig | 13 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/tas2781-dsp.c | 2154 ++++++++++++++++++++++++++++++++ sound/soc/codecs/tas2781-dsp.h | 181 +++ sound/soc/codecs/tas2781-i2c.c | 1622 ++++++++++++++++++++++++ sound/soc/codecs/tas2781.h | 159 +++ 6 files changed, 4131 insertions(+) create mode 100644 sound/soc/codecs/tas2781-dsp.c create mode 100644 sound/soc/codecs/tas2781-dsp.h create mode 100644 sound/soc/codecs/tas2781-i2c.c create mode 100644 sound/soc/codecs/tas2781.h
sound/soc/codecs/Kconfig +13 -0
@@ -229,6 +229,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_TAS2764 imply SND_SOC_TAS2770 imply SND_SOC_TAS2780 + imply SND_SOC_TAS2781 imply SND_SOC_TAS5086 imply SND_SOC_TAS571X imply SND_SOC_TAS5720
@@ -1637,6 +1638,18 @@ config SND_SOC_TAS2780 Enable support for Texas Instruments TAS2780 high-efficiency digital input mono Class-D audio power amplifiers. +config SND_SOC_TAS2781 + tristate "Texas Instruments TAS2781 speaker amplifier" + depends on I2C + select REGMAP_I2C + select CRC8 + help + Enable support for Texas Instruments TAS2781 Smart Amplifier + Digital input mono Class-D and DSP-inside audio power amplifiers. + Note the TAS2781 driver implements a flexible and configurable + algo coefficient setting, for one, two or even multiple TAS2781 + chips. + config SND_SOC_TAS5086 tristate "Texas Instruments TAS5086 speaker amplifier" depends on I2C
sound/soc/codecs/Makefile +2 -0
@@ -262,6 +262,7 @@ snd-soc-tas5805m-objs := tas5805m.o snd-soc-tas6424-objs := tas6424.o snd-soc-tda7419-objs := tda7419.o snd-soc-tas2770-objs := tas2770.o +snd-soc-tas2781-objs := tas2781-i2c.o tas2781-dsp.o snd-soc-tfa9879-objs := tfa9879.o snd-soc-tfa989x-objs := tfa989x.o snd-soc-tlv320adc3xxx-objs := tlv320adc3xxx.o
@@ -619,6 +620,7 @@ obj-$(CONFIG_SND_SOC_TAS2552) += snd-soc-tas2552.o obj-$(CONFIG_SND_SOC_TAS2562) += snd-soc-tas2562.o obj-$(CONFIG_SND_SOC_TAS2764) += snd-soc-tas2764.o obj-$(CONFIG_SND_SOC_TAS2780) += snd-soc-tas2780.o +obj-$(CONFIG_SND_SOC_TAS2781) += snd-soc-tas2781.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/tas2781-dsp.c new file +2154 -0
2,154 lines not on this page · raw message
sound/soc/codecs/tas2781-dsp.h new file +181 -0
181 lines not on this page · raw message
sound/soc/codecs/tas2781-i2c.c new file +1622 -0
626 lines not on this page · raw message
sound/soc/codecs/tas2781.h new file +159 -0
159 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
Quoted 20 lines · Shenghao Ding
Create tas2781 driver.
Signed-off-by Shenghao Ding <[email protected]>---
Changes in v9:
- rewording some commets
- Add comments on fimware parsing error handling -- all the memory resources will be released in the end oftasdevice_rca_ready(fw_parse_data,fw_parse_program_data&fw_parse_configuration_data).
- Add comments onfw_parse_calibration_data-- DSP can still work with default calibrated data, memory resource related to calibrated data will be released in thetasdevice_codec_remove.
modified:sound/soc/codecs/Kconfig
modified:sound/soc/codecs/Makefile
new file:sound/soc/codecs/tas2781-dsp.c
new file:sound/soc/codecs/tas2781-dsp.h
new file:sound/soc/codecs/tas2781-i2c.c
new file:sound/soc/codecs/tas2781.h
---
...
Quoted 71 lines
sound/soc/codecs/tas2781-dsp.c new file +71
-0+ +static int fw_parse_block_data_kernel (struct tasdevice_fw *tas_fmw, +struct tasdev_blk *block,const struct firmware *fmw,int offset) +{ +const unsigned char *data = fmw->data; + +if (offset +4 > fmw->size) { +dev_err (tas_fmw->dev,"%s: File Size error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->type =SMS_HTONL (data[offset], data[offset +1 ], + data[offset +2 ], data[offset +3 ]); + offset +=4 ; + +if (offset +1 > fmw->size) { +dev_err (tas_fmw->dev,"%s: PChkSumPresent error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->is_pchksum_present = data[offset]; + offset++; + +if (offset +1 > fmw->size) { +dev_err (tas_fmw->dev,"%s: mnPChkSum error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->pchksum = data[offset]; + offset++; + +if (offset +1 > fmw->size) { +dev_err (tas_fmw->dev,"%s: YChkSumPresent error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->is_ychksum_present = data[offset]; + offset++; + +if (offset +1 > fmw->size) { +dev_err (tas_fmw->dev,"%s: mnYChkSum error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->ychksum = data[offset]; + offset++; + +if (offset +4 > fmw->size) { +dev_err (tas_fmw->dev,"%s: blk_size error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->blk_size =SMS_HTONL (data[offset], data[offset +1 ], + data[offset +2 ], data[offset +3 ]); + offset +=4 ; + +if (offset +4 > fmw->size) { +dev_err (tas_fmw->dev,"%s: nSublocks error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->nr_subblocks =SMS_HTONL (data[offset], data[offset +1 ], + data[offset +2 ], data[offset +3 ]); + offset +=4 ; + +if (offset + block->blk_size > fmw->size) { +dev_err (tas_fmw->dev,"%s: nSublocks error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->data =kmemdup (&data[offset], block->blk_size,GFP_KERNEL );
sound/soc/codecs/tas2781-dsp.c line 158
Quoted 10 lines
sound/soc/codecs/tas2781-dsp.c new file +10
-0+if (!block->data) { + offset = -ENOMEM ; + goto out; + } + offset += block->blk_size; + +out: +return offset; +} +
I have a question regarding those
if (offset + x > fmw->size) {
do error
}
offset += x;
Can you instead of doing check before every assignment, just check once if you have enough data to parse, before parsing whole piece of data instead?
For above function it would be something like:
static int fw_parse_block_data_kernel(struct tasdevice_fw *tas_fmw,
struct tasdev_blk *block, const struct firmware *fmw, int offset)
{
const unsigned char *data = fmw->data;
if (offset + 16 + block->blk_size > fmw->size) {
dev_err(tas_fmw->dev, "%s: File Size error\n", __func__);
offset = -EINVAL;
goto out;
}
block->type = SMS_HTONL(data[offset], data[offset + 1],
data[offset + 2], data[offset + 3]);
block->is_pchksum_present = data[offset + 4];
block->pchksum = data[offset + 5];
block->is_ychksum_present = data[offset + 6];
block->ychksum = data[offset + 7];
block->blk_size = SMS_HTONL(data[offset + 8], data[offset + 9],
data[offset + 10], data[offset + 11]);
block->nr_subblocks = SMS_HTONL(data[offset + 12], data[offset + 13],
data[offset + 14], data[offset + 15]);
offset += 16;
block->data = kmemdup(&data[offset], block->blk_size, GFP_KERNEL);
if (!block->data) {
offset = -ENOMEM;
goto out;
}
offset += block->blk_size;out:
return offset; }
Additionally if you defined 'struct tasdev_blk' to reflect data which you copy here it can probably be simplified further to simple memcpy, instead of doing field by field assignments, which would reduce amount of code significantly and make it easier to read.
Above applies to all similar parsing in the patch.
Quoted 8 lines
sound/soc/codecs/tas2781-dsp.c new file +8
-0+static int fw_parse_data_kernel (struct tasdevice_fw *tas_fmw, +struct tasdevice_data *img_data,const struct firmware *fmw, +int offset) +{ +const unsigned char *data = fmw->data; +struct tasdev_blk *blk; +unsigned int i; +
...
sound/soc/codecs/tas2781.h line 73
Quoted 6 lines
sound/soc/codecs/tas2781.h new file +6
-0+ +#define SMS_HTONS (a, b) ((((a)&0x00FF)<<8) | ((b)&0x00FF)) +#define SMS_HTONL (a, b, c, d) ((((a)&0x000000FF)<<24) | \ + (((b)&0x000000FF)<<16) | (((c)&0x000000FF)<<8) | \ + ((d)&0x000000FF)) +
Kernel has htons and htonl (in source/include/linux/byteorder/generic.h), but I assume that this means that your FW may use different endianness than host cpu (big endian?), so I would suggest using be16_to_cpu and be32_to_cpu macros instead, as this should be more understandable in this case.