ASoC: tas2781: Add tas2781 driver
Subsystems (3)
PATCH v10 1/1 ASoC: tas2781: Add tas2781 driver
Create tas2781 driver.
---
Changes in v10:
- using be16_to_cpu and be32_to_cpu instead of SMS_HTONS and SMS_HTONL
- optimize and reduce the boundary checks
- Add comments on some kmemdup instead of kzalloc+memcpy Changes to be committed:
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 | 1822 ++++++++++++++++++++++++++++++++ sound/soc/codecs/tas2781-dsp.h | 181 ++++ sound/soc/codecs/tas2781-i2c.c | 1609 ++++++++++++++++++++++++++++ sound/soc/codecs/tas2781.h | 156 +++ 6 files changed, 3783 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 +1822 -0
1,822 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 +1609 -0
958 lines not on this page · raw message
sound/soc/codecs/tas2781.h new file +156 -0
156 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 17 lines · Shenghao Ding
Create tas2781 driver.
Signed-off-by Shenghao Ding <[email protected]>---
Changes in v10:
- usingbe16_to_cpuandbe32_to_cpuinstead ofSMS_HTONSandSMS_HTONL
- optimize and reduce the boundary checks
- Add comments on some kmemdup instead of kzalloc+memcpy Changes to be committed: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/tas2781-dsp.c line 89
Quoted 12 lines
sound/soc/codecs/tas2781-dsp.c new file +12
-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 +16 > fmw->size) { +dev_err (tas_fmw->dev,"%s: File Size error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->type =be32_to_cpup ((__be32 *)&data[offset]);
Wouldn't just be32_to_cpu(data[offset]) work instead of be32_to_cpup? Same in other cases.
Ding, Shenghao
maintainerHi Amadeusz Sławiński
Thanks for your comment.
Answer inline.
-----Original Message-----
From: Amadeusz Sławiński <[email protected]>
Sent: Thursday, March 30, 2023 7:54 PM
To: Shenghao Ding <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Lu, Kevin <[email protected]>; Ding, Shenghao <[email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; Gupta, Peeyush <[email protected]>; Navada Kanyana, Mukund <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v10] ASoC: tas2781: Add tas2781 driver
Quoted 17 lines · Shenghao Ding
Create tas2781 driver.
Signed-off-by Shenghao Ding <[email protected]>---
Changes in v10:
- usingbe16_to_cpuandbe32_to_cpuinstead ofSMS_HTONSandSMS_HTONL
- optimize and reduce the boundary checks
- Add comments on some kmemdup instead of kzalloc+memcpy Changes to be committed: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/tas2781-dsp.c line 89
Quoted 11 lines
sound/soc/codecs/tas2781-dsp.c new file +11
-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 +16 > fmw->size) { +dev_err (tas_fmw->dev,"%s: File Size error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->type =be32_to_cpup ((__be32 *)&data[offset]);
Wouldn't just be32_to_cpu(data[offset]) work instead of be32_to_cpup? Same in other cases.
[DING] data[] is a char array, the code will convert data[offset], data[offset + 1], data[offset + 2] and data[offset + 3] into host instead of data[offset] only.
Le 31/03/2023 à 04:19, Ding, Shenghao a écrit :
Quoted 32 lines
Hi Amadeusz Sławiński
Thanks for your comment.
Answer inline.-----Original Message-----
From: Amadeusz Sławiński <[email protected]>
Sent: Thursday, March 30, 2023 7:54 PM
To: Shenghao Ding <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Lu, Kevin <[email protected]>; Ding, Shenghao <[email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; Gupta, Peeyush <[email protected]>; Navada Kanyana, Mukund <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v10] ASoC: tas2781: Add tas2781 driverQuoted 17 lines · Shenghao Ding
Create tas2781 driver.
Signed-off-by Shenghao Ding <[email protected]>---
Changes in v10:
- usingbe16_to_cpuandbe32_to_cpuinstead ofSMS_HTONSandSMS_HTONL
- optimize and reduce the boundary checks
- Add comments on some kmemdup instead of kzalloc+memcpy Changes to be committed: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 17 lines
sound/soc/codecs/tas2781-dsp.c line 89
Quoted 11 lines
sound/soc/codecs/tas2781-dsp.c new file +11
-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 +16 > fmw->size) { +dev_err (tas_fmw->dev,"%s: File Size error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->type =be32_to_cpup ((__be32 *)&data[offset]);Wouldn't just
be32_to_cpu(data[offset])work instead ofbe32_to_cpup? Same in other cases.
[DING] data[] is a char array, the code will convert data[offset], data[offset + 1], data[offset + 2] and data[offset + 3] into host instead of data[offset] only.
Not sure to follow you.
Isn't it the purpose of be32_to_cpu() to take a 32 bits word, in other words 4 x 8 bits char, and swap what if needed (little endian arch)?
It ends to __swab32() ([1] for the "constant" implementation)
be32_to_cpup(&p) ends to __swab32(*p), which really looks to the same as be32_to_cpu(p).
Can you elaborate more?
CJ
[1]: https://elixir.bootlin.com/linux/v6.3-rc3/source/include/uapi/linux/swab.h#L18
Ding, Shenghao
maintainerHi Both
I wrote a test code to verify the be32_to_cpu & be32_to_cpup, static int __init lkm_init(void)
{
char test_buf[]={0x12, 0x34, 0xab, 0xbc, 0x56, 0x78, 0xef};
unsigned int *k, p, q;
int i;
printk("Hello, Shanghai!\n");
for (i = 0; i < 4; i ++) {
k = (unsigned int *)&test_buf[i];
p = be32_to_cpup((__be32 *)k);
q = be32_to_cpu(test_buf[i]);
printk("%d: *k = 0x%08x p = 0x%08x q = 0x%08x %ld\n",
i, *k, p, q, sizeof(unsigned int));
}
return 0;
}
The output is:
[ 9109.722548] Hello, Shanghai!
[ 9109.726287] 0: *k = 0xbcab3412 p = 0x1234abbc q = 0x12000000 4
[ 9109.727665] 1: *k = 0x56bcab34 p = 0x34abbc56 q = 0x34000000 4
[ 9109.728553] 2: *k = 0x7856bcab p = 0xabbc5678 q = 0xabffffff 4
[ 9109.729308] 3: *k = 0xef7856bc p = 0xbc5678ef q = 0xbcffffff 4Apparently, be32_to_cpup's output is what I expected. Looking forward to your comments. Thanks.
BR
Shenghao Ding
-----Original Message-----
From: Christophe JAILLET <[email protected]>
Sent: Saturday, April 1, 2023 4:41 AM
To: Ding, Shenghao <[email protected]>; Amadeusz Slawinski <[email protected]>; Shenghao Ding <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Lu, Kevin <[email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; Gupta, Peeyush <[email protected]>; Navada Kanyana, Mukund <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v10] ASoC: tas2781: Add tas2781 driver
Le 31/03/2023 à 04:19, Ding, Shenghao a écrit :
Quoted 37 lines
Hi Amadeusz Sławiński
Thanks for your comment.
Answer inline.-----Original Message-----
From: Amadeusz Sławiński <[email protected]>
Sent: Thursday, March 30, 2023 7:54 PM
To: Shenghao Ding <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Lu, Kevin <[email protected]>; Ding, Shenghao <[email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; Gupta, Peeyush <[email protected]>; Navada Kanyana, Mukund <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v10] ASoC: tas2781: Add tas2781 driverQuoted 17 lines · Shenghao Ding
Create tas2781 driver.
Signed-off-by Shenghao Ding <[email protected]>---
Changes in v10:
- usingbe16_to_cpuandbe32_to_cpuinstead ofSMS_HTONSandSMS_HTONL
- optimize and reduce the boundary checks
- Add comments on some kmemdup instead of kzalloc+memcpy Changes to be committed: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 17 lines
sound/soc/codecs/tas2781-dsp.c line 89
Quoted 11 lines
sound/soc/codecs/tas2781-dsp.c new file +11
-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 +16 > fmw->size) { +dev_err (tas_fmw->dev,"%s: File Size error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->type =be32_to_cpup ((__be32 *)&data[offset]);Wouldn't just
be32_to_cpu(data[offset])work instead ofbe32_to_cpup?
Same in other cases.
[DING] data[] is a char array, the code will convert data[offset],
data[offset + 1], data[offset + 2] and data[offset + 3] into host instead of data[offset] only.
Not sure to follow you.
Isn't it the purpose of be32_to_cpu() to take a 32 bits word, in other words 4 x 8 bits char, and swap what if needed (little endian arch)?
It ends to __swab32() ([1] for the "constant" implementation)
be32_to_cpup(&p) ends to __swab32(*p), which really looks to the same as be32_to_cpu(p).
Can you elaborate more?
CJ
[1]:
https://elixir.bootlin.com/linux/v6.3-rc3/source/include/uapi/linux/swab.h#L18
Quoted 25 lines · Shenghao
Hi Both
I wrote a test code to verify thebe32_to_cpu&be32_to_cpup, static int__initlkm_init(void){ char test_buf[]={0x12, 0x34, 0xab, 0xbc, 0x56, 0x78, 0xef}; unsigned int *k, p, q; int i; printk("Hello, Shanghai!\n"); for (i = 0; i < 4; i ++) { k = (unsigned int *)&test_buf[i]; p = be32_to_cpup((__be32 *)k); q = be32_to_cpu(test_buf[i]); printk("%d: *k = 0x%08x p = 0x%08x q = 0x%08x %ld\n", i, *k, p, q, sizeof(unsigned int)); } return 0; } The output is: [ 9109.722548] Hello, Shanghai! [ 9109.726287] 0: *k = 0xbcab3412 p = 0x1234abbc q = 0x12000000 4 [ 9109.727665] 1: *k = 0x56bcab34 p = 0x34abbc56 q = 0x34000000 4 [ 9109.728553] 2: *k = 0x7856bcab p = 0xabbc5678 q = 0xabffffff 4 [ 9109.729308] 3: *k = 0xef7856bc p = 0xbc5678ef q = 0xbcffffff 4
Quoted 3 lines
Apparently, be32_to_cpup's output is what I expected. Looking forward to your comments. Thanks.
It makes sense, as array access reads 8 bit value, you would need to access value using pointer instead. So instead of doing be32_to_cpu(test_buf[i]) you would need to do be32_to_cpu(*(test_buf + i)) if I didn't mess the pointer magic ;)
And then I'm not sure which is better, be32_to_cpup or be32_to_cpu.
Quoted 81 lines
BR
Shenghao Ding
-----Original Message-----
From: Christophe JAILLET <[email protected]>
Sent: Saturday, April 1, 2023 4:41 AM
To: Ding, Shenghao <[email protected]>; Amadeusz Slawinski <[email protected]>; Shenghao Ding <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Lu, Kevin <[email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; Gupta, Peeyush <[email protected]>; Navada Kanyana, Mukund <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v10] ASoC: tas2781: Add tas2781 driverLe 31/03/2023 à 04:19, Ding, Shenghao a écrit :
Quoted 37 lines
Hi Amadeusz Sławiński
Thanks for your comment.
Answer inline.-----Original Message-----
From: Amadeusz Sławiński <[email protected]>
Sent: Thursday, March 30, 2023 7:54 PM
To: Shenghao Ding <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Lu, Kevin <[email protected]>; Ding, Shenghao <[email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; Gupta, Peeyush <[email protected]>; Navada Kanyana, Mukund <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v10] ASoC: tas2781: Add tas2781 driverQuoted 17 lines · Shenghao Ding
Create tas2781 driver.
Signed-off-by Shenghao Ding <[email protected]>---
Changes in v10:
- usingbe16_to_cpuandbe32_to_cpuinstead ofSMS_HTONSandSMS_HTONL
- optimize and reduce the boundary checks
- Add comments on some kmemdup instead of kzalloc+memcpy Changes to be committed:
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 17 lines
sound/soc/codecs/tas2781-dsp.c line 89
Quoted 11 lines
sound/soc/codecs/tas2781-dsp.c new file +11
-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 +16 > fmw->size) { +dev_err (tas_fmw->dev,"%s: File Size error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->type =be32_to_cpup ((__be32 *)&data[offset]);Wouldn't just
be32_to_cpu(data[offset])work instead ofbe32_to_cpup?
Same in other cases.
[DING] data[] is a char array, the code will convert data[offset],
data[offset + 1], data[offset + 2] and data[offset + 3] into host instead of data[offset] only.Not sure to follow you.
Isn't it the purpose ofbe32_to_cpu()to take a 32 bits word, in other words 4 x 8 bits char, and swap what if needed (little endian arch)?It ends to
__swab32()([1] for the "constant" implementation)
be32_to_cpup(&p)ends to__swab32(*p), which really looks to the same asbe32_to_cpu(p).Can you elaborate more?
CJ
[1]:
https://elixir.bootlin.com/linux/v6.3-rc3/source/include/uapi/linux/swab.h#L18
Mark Brown
maintainerQuoted 6 lines · Amadeusz Sławiński
It makes sense, as array access reads 8 bit value, you would need to access value using pointer instead. So instead of doing
be32_to_cpu(test_buf[i])you would need to dobe32_to_cpu(*(test_buf + i))if I didn't mess the pointer magic ;)And then I'm not sure which is better,
be32_to_cpuporbe32_to_cpu.
The p variant works with unaligned pointers but might be slower if the architecture doesn't support unaligned access. For this application it probably doesn't matter either way.
Le 05/04/2023 à 13:21, Ding, Shenghao a écrit :
Quoted 25 lines
Hi Both
I wrote a test code to verify thebe32_to_cpu&be32_to_cpup, static int__initlkm_init(void){ char test_buf[]={0x12, 0x34, 0xab, 0xbc, 0x56, 0x78, 0xef}; unsigned int *k, p, q; int i; printk("Hello, Shanghai!\n"); for (i = 0; i < 4; i ++) { k = (unsigned int *)&test_buf[i]; p = be32_to_cpup((__be32 *)k); q = be32_to_cpu(test_buf[i]); printk("%d: *k = 0x%08x p = 0x%08x q = 0x%08x %ld\n", i, *k, p, q, sizeof(unsigned int)); } return 0; } The output is: [ 9109.722548] Hello, Shanghai! [ 9109.726287] 0: *k = 0xbcab3412 p = 0x1234abbc q = 0x12000000 4 [ 9109.727665] 1: *k = 0x56bcab34 p = 0x34abbc56 q = 0x34000000 4 [ 9109.728553] 2: *k = 0x7856bcab p = 0xabbc5678 q = 0xabffffff 4 [ 9109.729308] 3: *k = 0xef7856bc p = 0xbc5678ef q = 0xbcffffff 4
Quoted 2 lines
Apparently, be32_to_cpup's output is what I expected. Looking forward to your comments. Thanks.
Hi,
thanks for the clarification and code sample.
You are right.
I had in mind that something like: be32_to_cpu((__be32 *)data); would make it. (thanks to the cast)
But because of the need of "&" and "[offset]", it would just make the code unnecessarily complex.
I think that your approach is better.
CJ
Hi Both
I wrote a test code to verify the be32_to_cpu & be32_to_cpup, static int __init lkm_init(void)
{
char test_buf[]={0x12, 0x34, 0xab, 0xbc, 0x56, 0x78, 0xef};
unsigned int *k, p, q;
int i;
printk("Hello, Shanghai!\n");
for (i = 0; i < 4; i ++) {
k = (unsigned int *)&test_buf[i];
p = be32_to_cpup((__be32 *)k);
q = be32_to_cpu(test_buf[i]);
printk("%d: *k = 0x%08x p = 0x%08x q = 0x%08x %ld\n",
i, *k, p, q, sizeof(unsigned int));
}
return 0;
}
The output is:
[ 9109.722548] Hello, Shanghai!
[ 9109.726287] 0: *k = 0xbcab3412 p = 0x1234abbc q = 0x12000000 4
[ 9109.727665] 1: *k = 0x56bcab34 p = 0x34abbc56 q = 0x34000000 4
[ 9109.728553] 2: *k = 0x7856bcab p = 0xabbc5678 q = 0xabffffff 4
[ 9109.729308] 3: *k = 0xef7856bc p = 0xbc5678ef q = 0xbcffffff 4Apparently, be32_to_cpup's output is what I expected. Looking forward to your comments. Thanks.
BR
Shenghao Ding
-----Original Message-----
From: Christophe JAILLET <[email protected]>
Sent: Saturday, April 1, 2023 4:41 AM
To: Ding, Shenghao <[email protected]>; Amadeusz Slawinski <[email protected]>; Shenghao Ding <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Lu, Kevin <[email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; Gupta, Peeyush <[email protected]>; Navada Kanyana, Mukund <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v10] ASoC: tas2781: Add tas2781 driver
Le 31/03/2023 à 04:19, Ding, Shenghao a écrit :
Quoted 37 lines
Hi Amadeusz Sławiński
Thanks for your comment.
Answer inline.-----Original Message-----
From: Amadeusz Sławiński <[email protected]>
Sent: Thursday, March 30, 2023 7:54 PM
To: Shenghao Ding <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Lu, Kevin <[email protected]>; Ding, Shenghao <[email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; Gupta, Peeyush <[email protected]>; Navada Kanyana, Mukund <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v10] ASoC: tas2781: Add tas2781 driverQuoted 17 lines · Shenghao Ding
Create tas2781 driver.
Signed-off-by Shenghao Ding <[email protected]>---
Changes in v10:
- usingbe16_to_cpuandbe32_to_cpuinstead ofSMS_HTONSandSMS_HTONL
- optimize and reduce the boundary checks
- Add comments on some kmemdup instead of kzalloc+memcpy Changes to be committed: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 17 lines
sound/soc/codecs/tas2781-dsp.c line 89
Quoted 11 lines
sound/soc/codecs/tas2781-dsp.c new file +11
-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 +16 > fmw->size) { +dev_err (tas_fmw->dev,"%s: File Size error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->type =be32_to_cpup ((__be32 *)&data[offset]);Wouldn't just
be32_to_cpu(data[offset])work instead ofbe32_to_cpup?
Same in other cases.
[DING] data[] is a char array, the code will convert data[offset],
data[offset + 1], data[offset + 2] and data[offset + 3] into host instead of data[offset] only.
Not sure to follow you.
Isn't it the purpose of be32_to_cpu() to take a 32 bits word, in other words 4 x 8 bits char, and swap what if needed (little endian arch)?
It ends to __swab32() ([1] for the "constant" implementation)
be32_to_cpup(&p) ends to __swab32(*p), which really looks to the same as be32_to_cpu(p).
Can you elaborate more?
CJ
[1]:
https://elixir.bootlin.com/linux/v6.3-rc3/source/include/uapi/linux/swab.h#L18
Hi Amadeusz Sławiński
Thanks for your comment.
Answer inline.
-----Original Message-----
From: Amadeusz Sławiński <[email protected]>
Sent: Thursday, March 30, 2023 7:54 PM
To: Shenghao Ding <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Lu, Kevin <[email protected]>; Ding, Shenghao <[email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; Gupta, Peeyush <[email protected]>; Navada Kanyana, Mukund <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v10] ASoC: tas2781: Add tas2781 driver
Quoted 17 lines · Shenghao Ding
Create tas2781 driver.
Signed-off-by Shenghao Ding <[email protected]>---
Changes in v10:
- usingbe16_to_cpuandbe32_to_cpuinstead ofSMS_HTONSandSMS_HTONL
- optimize and reduce the boundary checks
- Add comments on some kmemdup instead of kzalloc+memcpy Changes to be committed: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/tas2781-dsp.c line 89
Quoted 11 lines
sound/soc/codecs/tas2781-dsp.c new file +11
-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 +16 > fmw->size) { +dev_err (tas_fmw->dev,"%s: File Size error\n" , __func__); + offset = -EINVAL ; + goto out; + } + block->type =be32_to_cpup ((__be32 *)&data[offset]);
Wouldn't just be32_to_cpu(data[offset]) work instead of be32_to_cpup? Same in other cases.
[DING] data[] is a char array, the code will convert data[offset], data[offset + 1], data[offset + 2] and data[offset + 3] into host instead of data[offset] only.
Le 29/03/2023 à 12:01, Shenghao Ding a écrit :
Quoted 6 lines
Create tas2781 driver.
Signed-off-by Shenghao Ding <[email protected]>---
Changes in v10:
[...]
Hi,
Quoted 19 lines
sound/soc/codecs/tas2781-i2c.c new file +19
-0+static void tasdevice_select_cfg_blk (void *pContext,int conf_no, +unsigned char block_type) +{ +struct tasdevice_priv *tas_dev = (struct tasdevice_priv *) pContext; +struct tasdevice_rca *rca = &(tas_dev->rcabin); +struct tasdevice_config_info **cfg_info = rca->cfg_info; +struct tasdev_blk_data **blk_data; +int j, k, chn, chnend; + +if (conf_no >= rca->ncfgs || conf_no <0 || !cfg_info) { +dev_err (tas_dev->dev,"conf_no should be not more than %u\n" , + rca->ncfgs); +return ; + } + blk_data = cfg_info[conf_no]->blk_data; + +for (j =0 ; j < (int )cfg_info[conf_no]->real_nblocks; j++) { +unsigned int length =0 , rc =0 ; +
sound/soc/codecs/tas2781-i2c.c line 252
Quoted 10 lines
sound/soc/codecs/tas2781-i2c.c new file +10
-0+if (block_type >5 || block_type <2 ) { +dev_err (tas_dev->dev, +"block_type should be in range from 2 to 5\n" ); +break ; + } +if (block_type != blk_data[j]->block_type) +continue ; + +for (k =0 ; k < (int )blk_data[j]->n_subblks; k++) { +if (cfg_info[conf_no]->blk_data[j]->dev_idx) {
Just use "blk_data[j]->dev_idx"?
Quoted 6 lines
sound/soc/codecs/tas2781-i2c.c new file +6
-0+ chn = blk_data[j]->dev_idx -1 ; + chnend = blk_data[j]->dev_idx; + }else { + chn =0 ; + chnend = tas_dev->ndev; + }
[...]
sound/soc/codecs/tas2781-i2c.c line 324
Quoted 3 lines
sound/soc/codecs/tas2781-i2c.c new file +3
-0+/* Several kinds of dsp/algorithm firmwares can run on tas2781, +* the number and size of blk are not fixed and different among +* thest firmwares.
these?
CJ