ASoc: tas2783: Add tas2783 codec driver
Subsystems (3)
Shenghao Ding
maintainerPATCH v7 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 lodspeakers.
The ASoC component provides the majority of the functionality of the device, all the audio functions.
---
Change in v7:
- 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
--- sound/soc/codecs/Kconfig | 14 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/tas2783-sdw.c | 937 +++++++++++++++++++++++++++++++++ sound/soc/codecs/tas2783.h | 108 ++++ 4 files changed, 1061 insertions(+) create mode 100644 sound/soc/codecs/tas2783-sdw.c create mode 100644 sound/soc/codecs/tas2783.h
sound/soc/codecs/Kconfig +14 -0
@@ -247,6 +247,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
@@ -1847,6 +1848,19 @@ 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_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. + config SND_SOC_TAS5086 tristate "Texas Instruments TAS5086 speaker amplifier" depends on I2C
sound/soc/codecs/Makefile +2 -0
@@ -284,6 +284,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
@@ -664,6 +665,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 +937 -0
937 lines not on this page · raw message
sound/soc/codecs/tas2783.h new file +108 -0
108 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 8 lines · Shenghao Ding
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 lodspeakers.
The ASoC component provides the majority of the functionality of the device, all the audio functions.
...
sound/soc/codecs/tas2783-sdw.c line 19
Quoted 8 lines
sound/soc/codecs/tas2783-sdw.c new file +7
-0+#include <linux/crc32.h> +#include <linux/efi.h> +#include <linux/err.h> +#include <linux/firmware.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/of.h>
Unused header. Maybe you use it as a "proxy"? Don't do this, include what you use directly (with some exceptions when we know that one header guarantees to include another).
sound/soc/codecs/tas2783-sdw.c line 29
Quoted 10 lines
sound/soc/codecs/tas2783-sdw.c new file +10
-0+#include <linux/pm.h> +#include <linux/pm_runtime.h> +#include <linux/regmap.h> +#include <linux/soundwire/sdw.h> +#include <linux/soundwire/sdw_registers.h> +#include <linux/soundwire/sdw_type.h> +#include <sound/pcm_params.h> +#include <sound/sdw.h> +#include <sound/soc.h> +#include <sound/tlv.h>
+ Blank line?
Quoted 3 lines
sound/soc/codecs/tas2783-sdw.c new file +3
-0+#include <sound/tas2781-tlv.h> + +#include "tas2783.h"
...
sound/soc/codecs/tas2783-sdw.c line 103
Quoted 5 lines
sound/soc/codecs/tas2783-sdw.c new file +5
-0+/* Only reset register was volatiled. +* Software reset. Bit is self clearing. +* 0b = Don't reset +* 1b = reset +*/
/*
* The above style of the multi-line comment is used
* solely by net subsystem. Please, fix all comments
* in your driver accordingly.
*/
...
sound/soc/codecs/tas2783-sdw.c line 115
Quoted 7 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 ,
I'm always wondering how this can work in debugfs when one tries to dump all registers...
Quoted 6 lines
sound/soc/codecs/tas2783-sdw.c new file +6
-0+ .reg_defaults = tas2783_reg_defaults, + .num_reg_defaults = ARRAY_SIZE(tas2783_reg_defaults), + .cache_type = REGCACHE_RBTREE, + .use_single_read = true, + .use_single_write = true, +};
...
sound/soc/codecs/tas2783-sdw.c line 132
Quoted 10 lines
sound/soc/codecs/tas2783-sdw.c new file +10
-0+static int tasdevice_clamp (int val,int max,unsigned int invert) +{ +/* Keep in valid area, out of range value don't care. */ +if (val > max) + val = max; +if (invert) + val = max - val; +if (val <0 ) + val =0 ; +return val;
Can it be as simple as
val = clamp(val, 0, max); if (invert) return max - val; return val;
?
Quoted 1 line
+}
...
Review
Quoted 1 line
(quoted diff) +1
-0+ dev_err(tas_dev->dev, "%s, wrong parameter.\n", __func__);
Usually using __func__ in error messages signals about them being poorly written.
...
sound/soc/codecs/tas2783-sdw.c line 155
Quoted 2 lines
sound/soc/codecs/tas2783-sdw.c new file +2
-0+dev_err (tas_dev->dev,"%s, get digital vol error %x.\n" , + __func__, ret);
Like here, you repeat __func__ contents in the message itself.
...
Review
Quoted 1 line
(quoted diff) +1
-0+ mask = (1 << fls(mc->max)) - 1;
Wouldn't roundup_pow_of_two() or roundown_pow_of_two() abe more explicit?
...
Review
Quoted 1 line
(quoted diff) +1
-0+ mask = (1 << fls(mc->max)) - 1;
Ditto.
...
sound/soc/codecs/tas2783-sdw.c line 287
Quoted 2 lines
sound/soc/codecs/tas2783-sdw.c new file +2
-0+ reg_start = (u8 *)(cali_data + (tas_dev->sdw_peripheral->id.unique_id + -TAS2783_ID_MIN ) *sizeof (tas2783_cali_reg));
Strange indentation.
sound/soc/codecs/tas2783-sdw.c line 290
Quoted 3 lines
sound/soc/codecs/tas2783-sdw.c new file +3
-0+for (int i =0 ; i <ARRAY_SIZE (tas2783_cali_reg); i++) { + ret =regmap_bulk_write (map, tas2783_cali_reg[i], + ®_start[4 * i],4 );
Ditto.
Quoted 6 lines
sound/soc/codecs/tas2783-sdw.c new file +6
-0+if (ret) { +dev_err (tas_dev->dev,"Cali failed %x:%d\n" , + tas2783_cali_reg[i], ret); +break ; + } + }
...
sound/soc/codecs/tas2783-sdw.c line 327
Quoted 1 line
sound/soc/codecs/tas2783-sdw.c new file +1
-0+if (status !=0 ) {
if (status)
Quoted 4 lines
sound/soc/codecs/tas2783-sdw.c new file +4
-0+/* Failed got calibration data from EFI. */ +dev_dbg (tas_dev->dev,"No calibration data in UEFI." ); +return 0 ; + }
...
sound/soc/codecs/tas2783-sdw.c line 342
Quoted 5 lines
sound/soc/codecs/tas2783-sdw.c new file +5
-0+/* Date and time of calibration was done. */ +time64_to_tm (tmp_val[20 ],0 , tm); +dev_dbg (tas_dev->dev,"%4ld-%2d-%2d, %2d:%2d:%2d\n" , + tm->tm_year, tm->tm_mon, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec);
Use respective %pt
...
sound/soc/codecs/tas2783-sdw.c line 374
Quoted 1 line
sound/soc/codecs/tas2783-sdw.c new file +1
-0+ img_sz =le32_to_cpup ((__le32 *)&buf[offset]);
Potentially broken alignment. In any case this code is bad. Use get_unaligned_le32() instead.
...
sound/soc/codecs/tas2783-sdw.c line 378
Quoted 2 lines
sound/soc/codecs/tas2783-sdw.c new file +2
-0+dev_err (tas_dev->dev,"Size not matching, %d %u" , + (int )fmw->size, img_sz);
No castings in printf(). It's rarely when you need one. Here is just an indication of mistype.
...
sound/soc/codecs/tas2783-sdw.c line 392
Quoted 1 line
sound/soc/codecs/tas2783-sdw.c new file +1
-0+if (ret !=0 ) {
if (ret)
sound/soc/codecs/tas2783-sdw.c line 396
Quoted 4 lines
sound/soc/codecs/tas2783-sdw.c new file +4
-0+dev_dbg (tas_dev->dev,"Load FW fail: %d.\n" , ret); + goto out; + } + offset +=sizeof (unsigned int )*5 + p->length;
Missing spaces around '*'. And why magic number? What is it meaning?
...
sound/soc/codecs/tas2783-sdw.c line 400
Quoted 1 line
sound/soc/codecs/tas2783-sdw.c new file +1
-0+ value_sdw |= ((tas_dev->sdw_peripheral->dev_num &1 ) <<4 );
Outer parentheses are not needed, perhaps BIT(0) instead of 1 will be better to understand?
sound/soc/codecs/tas2783-sdw.c line 417
Quoted 6 lines
sound/soc/codecs/tas2783-sdw.c new file +6
-0+static const struct snd_soc_dapm_widget tasdevice_dapm_widgets[] = { +SND_SOC_DAPM_AIF_IN ("ASI" ,"ASI Playback" ,0 ,SND_SOC_NOPM ,0 ,0 ), +SND_SOC_DAPM_AIF_OUT ("ASI OUT" ,"ASI Capture" ,0 ,SND_SOC_NOPM , +0 ,0 ), +SND_SOC_DAPM_OUTPUT ("OUT" ), +SND_SOC_DAPM_INPUT ("DMIC" )
Leave trailing comma as it's not a terminator.
sound/soc/codecs/tas2783-sdw.c line 422
Quoted 5 lines
sound/soc/codecs/tas2783-sdw.c new file +5
-0+}; + +static const struct snd_soc_dapm_route tasdevice_audio_map[] = { + {"OUT" ,NULL ,"ASI" }, + {"ASI OUT" ,NULL ,"DMIC" }
Ditto.
Quoted 1 line
+};
...
sound/soc/codecs/tas2783-sdw.c line 450
Quoted 1 line
sound/soc/codecs/tas2783-sdw.c new file +1
-0+dev_dbg (dai->dev,"%s %s" , __func__, dai->name);
__func__ in dev_dbg() makes a little sense as we may enable it dynamically (when Dynamic Debug is on). Generally speaking no debug messages should use __LINE__, __FILE__, or __func__ in the modern kernel code.
...
sound/soc/codecs/tas2783-sdw.c line 666
Quoted 1 line
sound/soc/codecs/tas2783-sdw.c new file +1
-0+ scnprintf(tas_dev->rca_binaryname, 64, "tas2783-%d-%x.bin",
sizeof() ?
Quoted 2 lines
sound/soc/codecs/tas2783-sdw.c new file +2
-0+ tas_dev->sdw_peripheral->bus->link_id, + tas_dev->sdw_peripheral->id.unique_id);
...
Quoted 1 line
+out:
Useless label, you can return directly.
Quoted 1 line
(quoted diff) +1
-0+ return ret;
...
Review
Quoted 2 lines
(quoted diff) +2
-0+out: + return ret;
Ditto.
...
sound/soc/codecs/tas2783-sdw.c line 792
Quoted 1 line
sound/soc/codecs/tas2783-sdw.c new file +1
-0+struct tasdevice_priv *tas_priv =dev_get_drvdata (&slave->dev);
Too many spaces.
...
sound/soc/codecs/tas2783-sdw.c line 843
Quoted 2 lines
sound/soc/codecs/tas2783-sdw.c new file +2
-0+ tas_dev->regmap =devm_regmap_init_sdw (peripheral, + &tasdevice_regmap);
One line?
sound/soc/codecs/tas2783-sdw.c line 850
Quoted 7 lines
sound/soc/codecs/tas2783-sdw.c new file +7
-0+if (IS_ERR (tas_dev->regmap)) { + ret =PTR_ERR (tas_dev->regmap); +dev_err (dev,"Failed %d of devm_regmap_init_sdw." , ret); + }else + ret =tasdevice_init (tas_dev); + +return ret;
if (IS_ERR(tas_dev->regmap)) return dev_err_probe(dev, PTR_ERR(tas_dev->regmap), "Failed devm_regmap_init_sdw."); return tasdevice_init(tas_dev);
...
sound/soc/codecs/tas2783-sdw.c line 861
Quoted 9 lines
sound/soc/codecs/tas2783-sdw.c new file +9
-0+static int tasdevice_sdw_remove (struct sdw_slave *peripheral) +{ +struct tasdevice_priv *tas_dev =dev_get_drvdata (&peripheral->dev); + +if (tas_dev->first_hw_init) +pm_runtime_disable (tas_dev->dev); + +pm_runtime_put_noidle (tas_dev->dev); +return 0 ;
Are you sure this is correct order of calls as we have a lot of cleaning up happening here?
Quoted 1 line
+}
...
sound/soc/codecs/tas2783-sdw.c line 866
Quoted 3 lines
sound/soc/codecs/tas2783-sdw.c new file +3
-0+static const struct sdw_device_id tasdevice_sdw_id[] = { +SDW_SLAVE_ENTRY (0x0102 ,0x0000 ,0 ), + {},
No comma for the terminator line.
sound/soc/codecs/tas2783-sdw.c line 41
Quoted 3 lines
sound/soc/codecs/tas2783-sdw.c new file +2
-0+}; +
Unneeded blank line.
Quoted 1 line
+MODULE_DEVICE_TABLE(sdw,
tasdevice_sdw_id);
...
Quoted 1 line
+#define
TAS2783_PROBE_TIMEOUT5000
Missing units suffix (_US? _MS?)
Quoted 1 line
+static int
__maybe_unusedtas2783_sdca_dev_resume(struct device *dev)
No new code should use __maybe_unused for PM callbacks. Use pm_ptr() and respective new PM macros.
...
sound/soc/codecs/tas2783-sdw.c line 919
Quoted 6 lines
sound/soc/codecs/tas2783-sdw.c new file +6
-0+static const struct dev_pm_ops tas2783_sdca_pm = { + SET_SYSTEM_SLEEP_PM_OPS(tas2783_sdca_dev_suspend, + tas2783_sdca_dev_resume) +SET_RUNTIME_PM_OPS (tas2783_sdca_dev_suspend, + tas2783_sdca_dev_resume,NULL ) +};
Use new PM macros.
sound/soc/codecs/tas2783-sdw.c line 931
Quoted 12 lines
sound/soc/codecs/tas2783-sdw.c new file +11
-0+static struct sdw_driver tasdevice_sdw_driver = { + .driver = { + .name ="slave-tas2783" , + .pm = &tas2783_sdca_pm, + }, + .probe = tasdevice_sdw_probe, + .remove = tasdevice_sdw_remove, + .ops = &tasdevice_sdw_ops, + .id_table = tasdevice_sdw_id, +}; +
Unneeded blank line.
Quoted 1 line
+module_sdw_driver(tasdevice_sdw_driver);
...
sound/soc/codecs/tas2783.h line 13
Quoted 2 lines
sound/soc/codecs/tas2783.h new file +2
-0+#ifndef __TAS2783_H__ +#define __TAS2783_H__
+ linux/bits.h
+ linux/time.h
+ linux/types.h
+ sound/pcm.h
and so on, use IWYU (include what you use) principle.
Note, for the pointers you may use forward declarations, like
struct device;
struct regmap;
struct snd_soc_component;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Mark Brown
maintainerQuoted 8 lines · Andy Shevchenko
Quoted 5 lines · Shenghao Ding
sound/soc/codecs/tas2783-sdw.c new file +5
-0+static const struct regmap_config tasdevice_regmap = { + .reg_bits =32 , + .val_bits =8 , + .readable_reg = tas2783_readable_register, + .volatile_reg = tas2783_volatile_register,
Quoted 4 lines
sound/soc/codecs/tas2783-sdw.c line 115
Quoted 1 line
sound/soc/codecs/tas2783-sdw.c new file +1
-0+ .max_register = 0x44ffffff,I'm always wondering how this can work in debugfs when one tries to dump all registers...
regmap will filter out non-readable registers from what it shows in debugfs so sparse regmaps will end up much smaller than they might look. The debugfs code also has support for seeking into the output (since each register is a fixed size) so we'll only actually render whatever is being read in an individual read().
Quoted 8 lines
sound/soc/codecs/tas2783-sdw.c line 919
Quoted 6 lines
sound/soc/codecs/tas2783-sdw.c new file +6
-0+static const struct dev_pm_ops tas2783_sdca_pm = { + SET_SYSTEM_SLEEP_PM_OPS(tas2783_sdca_dev_suspend, + tas2783_sdca_dev_resume) +SET_RUNTIME_PM_OPS (tas2783_sdca_dev_suspend, + tas2783_sdca_dev_resume,NULL ) +};Use new PM macros.
...which are?
Quoted 2 lines · Mark Brown
Quoted 1 line · Andy Shevchenko
On Wed, Feb 07, 2024 at 01:47:42PM +0800, Shenghao Ding wrote:
...
Quoted 10 lines
Quoted 4 lines
sound/soc/codecs/tas2783-sdw.c line 115
Quoted 1 line
sound/soc/codecs/tas2783-sdw.c new file +1
-0+ .max_register = 0x44ffffff,I'm always wondering how this can work in debugfs when one tries to dump all registers...
regmap will filter out non-readable registers from what it shows in debugfs so sparse regmaps will end up much smaller than they might look. The debugfs code also has support for seeking into the output (since each register is a fixed size) so we'll only actually render whatever is being read in an individual
read().
Thanks, good to know.
...
Quoted 10 lines
Quoted 8 lines
sound/soc/codecs/tas2783-sdw.c line 919
Quoted 6 lines
sound/soc/codecs/tas2783-sdw.c new file +6
-0+static const struct dev_pm_ops tas2783_sdca_pm = { + SET_SYSTEM_SLEEP_PM_OPS(tas2783_sdca_dev_suspend, + tas2783_sdca_dev_resume) +SET_RUNTIME_PM_OPS (tas2783_sdca_dev_suspend, + tas2783_sdca_dev_resume,NULL ) +};Use new PM macros.
...which are?
SYSTEM_SLEEP_PM_OPS()RUNTIME_PM_OPS()
and pm_ptr() in the .driver.pm assignment.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Much better than previous versions but still questions on pm_runtime and a big undocumented part on the unique_id use. see comments below -Pierre
sound/soc/codecs/Kconfig config SND_SOC_TAS2781_I2C · line 1856
Quoted 6 lines
sound/soc/codecs/Kconfig +6
-0+config SND_SOC_TAS2783 + tristate "Texas Instruments TAS2783 speaker amplifier (sdw)" + depends on SOUNDWIRE + depends on EFI + select REGMAP + select REGMAP_SOUNDWIRE
nit-pick: should have 'select CRC32'...
sound/soc/codecs/Kconfig config SND_SOC_TAS2781_I2C · line 1857
Quoted 1 line
sound/soc/codecs/Kconfig +1
-0+ select CRC32_SARWATE
before selecting the CRC32 implementation. It's also not clear if this is needed, the help says
"Only choose this option if you know what you are doing."
sound/soc/codecs/tas2783-sdw.c line 275
Quoted 9 lines
sound/soc/codecs/tas2783-sdw.c new file +9
-0+static void tas2783_apply_calib (struct tasdevice_priv *tas_dev, +unsigned int *cali_data) +{ +struct regmap *map = tas_dev->regmap; +u8 *reg_start; +int ret; + +if (!tas_dev->sdw_peripheral) { + dev_err(tas_dev->dev, "%s, slaver doesn't exist.\n",
"peripheral does not exist"
sound/soc/codecs/tas2783-sdw.c line 280
Quoted 5 lines
sound/soc/codecs/tas2783-sdw.c new file +5
-0+ __func__); +return ; + } +if ((tas_dev->sdw_peripheral->id.unique_id <TAS2783_ID_MIN ) || + (tas_dev->sdw_peripheral->id.unique_id >TAS2783_ID_MAX )) {
Where does this unique_id requirement come from?
I see this in the header files, and that means only half of the bits are supported?
+/* Unique id start */
+#define TAS2783_ID_MIN 0x08
+/* Unique id end */
+#define TAS2783_ID_MAX 0x0f
the unique_id is only meant to allow identical devices to work concurrently on the same link, specifically it enables the enumeration of identical devices with the hardware arbitration. The device with the highest unique_id is enumerated first in case of conflicts.
The unique_id is usually set at the board level. I don't know how the codec driver can enforce a specific value.
This needs more explanations....
Quoted 25 lines
sound/soc/codecs/tas2783-sdw.c new file +24
-0+dev_err (tas_dev->dev,"%s, error unique_id.\n" , + __func__); +return ; + } + + reg_start = (u8 *)(cali_data + (tas_dev->sdw_peripheral->id.unique_id + -TAS2783_ID_MIN ) *sizeof (tas2783_cali_reg)); +for (int i =0 ; i <ARRAY_SIZE (tas2783_cali_reg); i++) { + ret =regmap_bulk_write (map, tas2783_cali_reg[i], + ®_start[4 * i],4 ); +if (ret) { +dev_err (tas_dev->dev,"Cali failed %x:%d\n" , + tas2783_cali_reg[i], ret); +break ; + } + } +} +static void tasdevice_rca_ready (const struct firmware *fmw, +void *context) +{ +struct tasdevice_priv *tas_dev = + (struct tasdevice_priv *) context; +struct tas2783_firmware_node *p; +struct regmap *map = tas_dev->regmap;
sound/soc/codecs/tas2783-sdw.c line 369
Quoted 10 lines
sound/soc/codecs/tas2783-sdw.c new file +10
-0+unsigned char *buf =NULL ; +int offset =0 , img_sz; +int ret, value_sdw; + +if (!fmw || !fmw->data) { +/* No firmware binary, devices will work in ROM mode. */ +dev_err (tas_dev->dev, +"Failed to read %s, no side-effect on driver\n" , + tas_dev->rca_binaryname); + ret = -EINVAL ;
If this is not an error, it should be dev_info or dev_warn?
Quoted 21 lines
sound/soc/codecs/tas2783-sdw.c new file +21
-0+ goto out; + } + buf = (unsigned char *)fmw->data; + + img_sz =le32_to_cpup ((__le32 *)&buf[offset]); + offset +=sizeof (img_sz); +if (img_sz != fmw->size) { +dev_err (tas_dev->dev,"Size not matching, %d %u" , + (int )fmw->size, img_sz); + ret = -EINVAL ; + goto out; + } + +while (offset < img_sz) { + p = (struct tas2783_firmware_node *)(buf + offset); +if (p->length >1 ) { + ret =regmap_bulk_write (map, p->download_addr, + buf + offset +sizeof (unsigned int )*5 , p->length); + }else + ret =regmap_write (map, p->download_addr, + *(buf + offset +sizeof (unsigned int ) *5 ));
sound/soc/codecs/tas2783-sdw.c line 400
Quoted 10 lines
sound/soc/codecs/tas2783-sdw.c new file +10
-0+ +if (ret !=0 ) { +dev_dbg (tas_dev->dev,"Load FW fail: %d.\n" , ret); + goto out; + } + offset +=sizeof (unsigned int )*5 + p->length; + } +/* Select left/right channel based on unique id. */ + value_sdw =0x1a ; + value_sdw |= ((tas_dev->sdw_peripheral->dev_num &1 ) <<4 );
This is a very odd sequence, please add commments on what those bits mean. It looks like this is confusing unique id and device number. Not the same thing at all! The unique_id is set at the board level and used during enumeration only, the dev_num is used as a logical value for command/control. The dev_num is assigned in drivers/soundwire/bus.c and depends on multiple things (order of attachment, allocation policy on this host, etc). The codec driver cannot assume any specific value for dev_num.
Quoted 24 lines
sound/soc/codecs/tas2783-sdw.c new file +23
-0+dev_dbg (tas_dev->dev,"%s dev_num = %u" , __func__, + tas_dev->sdw_peripheral->dev_num); +regmap_write (map,TAS2783_REG_TDM_RX_CFG , value_sdw); + +tas2783_calibration (tas_dev); + +out: +if (fmw) +release_firmware (fmw); +} +static int tasdevice_init (struct tasdevice_priv *tas_dev) +{ +int ret; + +dev_set_drvdata (tas_dev->dev, tas_dev); + + ret =devm_snd_soc_register_component (tas_dev->dev, + &soc_codec_driver_tasdevice, + tasdevice_dai_driver,ARRAY_SIZE (tasdevice_dai_driver)); +if (ret) { +dev_err (tas_dev->dev,"%s: codec register error:%d.\n" , + __func__, ret); + goto out;
sound/soc/codecs/tas2783-sdw.c
Quoted 10 lines
sound/soc/codecs/tas2783-sdw.c new file +10
-0+ } + +/* tas2783-link_id[0,1,...,N]-unique_id[8,9,...,f].bin stores the dsp +* firmware including speaker protection algorithm, audio acoustic +* algorithm, speaker characters and algorithm params, it must be +* copied into firmware folder. Each tas2783 has its own bin file. +*/ +scnprintf (tas_dev->rca_binaryname,64 ,"tas2783-%d-%x.bin" , + tas_dev->sdw_peripheral->bus->link_id, + tas_dev->sdw_peripheral->id.unique_id);
Goodness, again this unique_id usage.
This is really problematic, how would this work for a Linux distribution? Fetching the firmware ONLY on the basis of a unique_id means possible collisions between platformA from OEM_X and platformB from OEM_Y.
Quoted 8 lines
sound/soc/codecs/tas2783-sdw.c new file +8
-0+ + ret =request_firmware_nowait (THIS_MODULE ,FW_ACTION_UEVENT , + tas_dev->rca_binaryname, tas_dev->dev,GFP_KERNEL , + tas_dev, tasdevice_rca_ready); +if (ret) { +dev_err (tas_dev->dev, +"%s: request_firmware %x open status: %d.\n" , + __func__, tas_dev->sdw_peripheral->id.unique_id, ret);
sound/soc/codecs/tas2783-sdw.c line 686
Quoted 10 lines
sound/soc/codecs/tas2783-sdw.c new file +10
-0+ goto out; + } + +/* set autosuspend parameters */ +pm_runtime_set_autosuspend_delay (tas_dev->dev,3000 ); +pm_runtime_use_autosuspend (tas_dev->dev); + +/* make sure the device does not suspend immediately */ +pm_runtime_mark_last_busy (tas_dev->dev); +pm_runtime_get_noresume (tas_dev->dev);
why are you increasing the refcount here? No other SoundWire codec driver does this.
Quoted 4 lines
sound/soc/codecs/tas2783-sdw.c new file +4
-0+pm_runtime_enable (tas_dev->dev); + +out: +return ret;
sound/soc/codecs/tas2783-sdw.c line 860
Quoted 10 lines
sound/soc/codecs/tas2783-sdw.c new file +9
-0+} +static int tasdevice_sdw_remove (struct sdw_slave *peripheral) +{ +struct tasdevice_priv *tas_dev =dev_get_drvdata (&peripheral->dev); + +if (tas_dev->first_hw_init) +pm_runtime_disable (tas_dev->dev); + +pm_runtime_put_noidle (tas_dev->dev);
that should be removed as well, this and the previous get_no_resume() guarantee that pm_runtime suspend *NEVER* happens...
sound/soc/codecs/tas2783.h line 58
Quoted 7 lines
sound/soc/codecs/tas2783.h new file +6
-0+return 0 ; +} +/* Unique id start */ +#define TAS2783_ID_MIN 0x08 +/* Unique id end */ +#define TAS2783_ID_MAX 0x0f
this needs a lot more documentation, there's really nothing in the SoundWire spec that allows for the unique_id to be restricted...