ASoC: ops: improve snd_soc_get_volsw
PATCH v5 1/5 ASoC: ops: improve snd_soc_get_volsw
* add error handling in case register read fails
* clamp the values if the register value read is
out of range
--
v5:
- remove clamp parameter
- move the boundary check after sign-bit extension
--- sound/soc/soc-ops.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
sound/soc/soc-ops.c +15 -2
@@ -118,6 +118,7 @@ static int soc_mixer_reg_to_ctl(struct soc_mixer_control *mc, unsigned int reg_vif (mc->sign_bit) val =sign_extend32 (val, mc->sign_bit); + val =clamp (val, mc->min, mc->max); val -= mc->min;if (mc->invert)
@@ -249,9 +250,15 @@ static int soc_get_volsw(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);unsigned int reg_val; -int val; +int val, ret =0 ; reg_val =snd_soc_component_read (component, mc->reg); + val = reg_val; +if (val <0 ) { + ret = val; + goto get_volsw_done; + } + val =soc_mixer_reg_to_ctl (mc, reg_val, mask, mc->shift, max); ucontrol->value.integer.value[0 ] = val;
@@ -261,13 +268,19 @@ static int soc_get_volsw(struct snd_kcontrol *kcontrol, val =soc_mixer_reg_to_ctl (mc, reg_val, mask, mc->rshift, max); }else { reg_val =snd_soc_component_read (component, mc->rreg); + val = reg_val; +if (val <0 ) { + ret = val; + goto get_volsw_done; + } val =soc_mixer_reg_to_ctl (mc, reg_val, mask, mc->shift, max); } ucontrol->value.integer.value[1 ] = val; } -return 0 ; +get_volsw_done: +return ret; }/**
Signature · 1 line
2.45.2
PATCH v5 2/5 ASoc: tas2783A: Add soundwire based codec driver
TAS2783 is mono digital input class-D Smart Amplifier based on MIPI Alliance Soundwire interface. The driver supports loading the algorithm coefficients for one or more tas2783 chips.
---
v5:
- update to use the originial api snd_soc_get_volsw for get mixer control
v4:
- Dropped tas_clamp and use snd_soc_put_volsw and snd_soc_get_volsw_clamped for volume handling.
- move the stub implementation to header file.
v3:
- fix compilation issue for ARCH=hexagon clang compiler
- Kconfig - use depends on for SOUNDWIRE and EFI instead of select
- add REGMAP_SOUNDWIRE_MBQ
v2:
- append Volume to amp gain mixer control
- remove unwanted debug log
--- sound/soc/codecs/Kconfig | 14 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/tas2783-sdw.c | 1331 ++++++++++++++++++++++++++++++++ sound/soc/codecs/tas2783.h | 110 +++ 4 files changed, 1457 insertions(+) create mode 100644 sound/soc/codecs/tas2783-sdw.c create mode 100644 sound/soc/codecs/tas2783.h
sound/soc/codecs/Kconfig +14 -0
@@ -266,6 +266,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_TAS2770 imply SND_SOC_TAS2780 imply SND_SOC_TAS2781_I2C + imply SND_SOC_TAS2783_SDW imply SND_SOC_TAS5086 imply SND_SOC_TAS571X imply SND_SOC_TAS5720
@@ -2074,6 +2075,19 @@ config SND_SOC_TAS2781_I2C algo coefficient setting, for one, two or even multiple TAS2781 chips. +config SND_SOC_TAS2783_SDW + tristate "Texas Instruments TAS2783 speaker amplifier (sdw)" + depends on SOUNDWIRE + depends on EFI + select REGMAP_SOUNDWIRE + select REGMAP_SOUNDWIRE_MBQ + select CRC32 + help + Enable support for Texas Instruments TAS2783A Digital input + mono Class-D and DSP-inside audio power amplifiers. TAS2783 + driver implements a flexible and configurable algorithm + cofficient setting, for one, two or multiple TAS2783 chips. + config SND_SOC_TAS5086 tristate "Texas Instruments TAS5086 speaker amplifier" depends on I2C
sound/soc/codecs/Makefile +2 -0
@@ -316,6 +316,7 @@ snd-soc-tas2781-comlib-y := tas2781-comlib.o snd-soc-tas2781-comlib-i2c-y := tas2781-comlib-i2c.o snd-soc-tas2781-fmwlib-y := tas2781-fmwlib.o snd-soc-tas2781-i2c-y := tas2781-i2c.o +snd-soc-tas2783-sdw-y := tas2783-sdw.o snd-soc-tfa9879-y := tfa9879.o snd-soc-tfa989x-y := tfa989x.o snd-soc-tlv320adc3xxx-y := tlv320adc3xxx.o
@@ -732,6 +733,7 @@ obj-$(CONFIG_SND_SOC_TAS2781_COMLIB) += snd-soc-tas2781-comlib.o obj-$(CONFIG_SND_SOC_TAS2781_COMLIB_I2C) += snd-soc-tas2781-comlib-i2c.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_SDW) += snd-soc-tas2783-sdw.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 +1331 -0
1,331 lines not on this page · raw message
sound/soc/codecs/tas2783.h new file +110 -0
110 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v5 3/5 ASoc: tas2783A: machine driver amp utility for TI devices
In reply to Niranjan H Y Machine driver amp utility file to initialize and support
multiple tas2783a devices are added.
--
v5:
- removed empty line in soc_sdw_ti_amp.c
--- include/sound/soc_sdw_utils.h | 8 +++ sound/soc/sdw_utils/Makefile | 3 +- sound/soc/sdw_utils/soc_sdw_ti_amp.c | 92 ++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 sound/soc/sdw_utils/soc_sdw_ti_amp.c
include/sound/soc_sdw_utils.h +8 -0
@@ -248,5 +248,13 @@ int asoc_sdw_cs42l43_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soint asoc_sdw_cs42l43_dmic_rtd_init (struct snd_soc_pcm_runtime *rtd,struct snd_soc_dai *dai);int asoc_sdw_cs_spk_rtd_init (struct snd_soc_pcm_runtime *rtd,struct snd_soc_dai *dai);int asoc_sdw_maxim_spk_rtd_init (struct snd_soc_pcm_runtime *rtd,struct snd_soc_dai *dai); +/* TI */ +int asoc_sdw_ti_amp_init (struct snd_soc_card *card, +struct snd_soc_dai_link *dai_links, +struct asoc_sdw_codec_info *info, +bool playback); +int asoc_sdw_ti_spk_rtd_init (struct snd_soc_pcm_runtime *rtd,struct snd_soc_dai *dai); +int asoc_sdw_ti_amp_initial_settings (struct snd_soc_card *card, +const char *name_prefix);#endif
sound/soc/sdw_utils/Makefile +2 -1
@@ -6,5 +6,6 @@ snd-soc-sdw-utils-y := soc_sdw_utils.o soc_sdw_dmic.o soc_sdw_rt_dmic.o \ soc_sdw_bridge_cs35l56.o \ soc_sdw_cs42l42.o soc_sdw_cs42l43.o \ soc_sdw_cs_amp.o \ - soc_sdw_maxim.o + soc_sdw_maxim.o \ + soc_sdw_ti_amp.o obj-$(CONFIG_SND_SOC_SDW_UTILS) += snd-soc-sdw-utils.o
sound/soc/sdw_utils/soc_sdw_ti_amp.c new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v5 4/5 ASoc: tas2783A: add machine driver changes
In reply to Niranjan H YAdd tas2783-codec for codec_info
--- sound/soc/sdw_utils/soc_sdw_utils.c | 38 +++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 10 deletions(-)
sound/soc/sdw_utils/soc_sdw_utils.c +28 -10
@@ -35,12 +35,12 @@ static const struct snd_kcontrol_new generic_spk_controls[] = { SOC_DAPM_PIN_SWITCH("Speaker"), }; -static const struct snd_soc_dapm_widget maxim_widgets[] = { +static const struct snd_soc_dapm_widget lr_spk_widgets[] = {SND_SOC_DAPM_SPK ("Left Spk" ,NULL ),SND_SOC_DAPM_SPK ("Right Spk" ,NULL ), }; -static const struct snd_kcontrol_new maxim_controls[] = { +static const struct snd_kcontrol_new lr_spk_controls[] = {SOC_DAPM_PIN_SWITCH ("Left Spk" ),SOC_DAPM_PIN_SWITCH ("Right Spk" ), };
@@ -58,6 +58,24 @@ static const struct snd_kcontrol_new rt700_controls[] = { };struct asoc_sdw_codec_info codec_info_list[] = { + { + .part_id =0x0000 ,/* TAS2783A */ + .dais = { + { + .direction = {true, true}, + .dai_name ="tas2783-codec" , + .dai_type =SOC_SDW_DAI_TYPE_AMP , + .dailink = {SOC_SDW_AMP_OUT_DAI_ID ,SOC_SDW_AMP_IN_DAI_ID }, + .init = asoc_sdw_ti_amp_init, + .rtd_init = asoc_sdw_ti_spk_rtd_init, + .controls = lr_spk_controls, + .num_controls =ARRAY_SIZE (lr_spk_controls), + .widgets = lr_spk_widgets, + .num_widgets =ARRAY_SIZE (lr_spk_widgets), + }, + }, + .dai_num =1 , + }, { .part_id =0x700 , .dais = {
@@ -450,10 +468,10 @@ struct asoc_sdw_codec_info codec_info_list[] = { .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_AMP_IN_DAI_ID}, .init = asoc_sdw_maxim_init, .rtd_init = asoc_sdw_maxim_spk_rtd_init, - .controls = maxim_controls, - .num_controls = ARRAY_SIZE(maxim_controls), - .widgets = maxim_widgets, - .num_widgets = ARRAY_SIZE(maxim_widgets), + .controls = lr_spk_controls, + .num_controls = ARRAY_SIZE(lr_spk_controls), + .widgets = lr_spk_widgets, + .num_widgets = ARRAY_SIZE(lr_spk_widgets), }, }, .dai_num = 1,
@@ -469,10 +487,10 @@ struct asoc_sdw_codec_info codec_info_list[] = { .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_UNUSED_DAI_ID}, .init = asoc_sdw_maxim_init, .rtd_init = asoc_sdw_maxim_spk_rtd_init, - .controls = maxim_controls, - .num_controls = ARRAY_SIZE(maxim_controls), - .widgets = maxim_widgets, - .num_widgets = ARRAY_SIZE(maxim_widgets), + .controls = lr_spk_controls, + .num_controls = ARRAY_SIZE(lr_spk_controls), + .widgets = lr_spk_widgets, + .num_widgets = ARRAY_SIZE(lr_spk_widgets), }, }, .dai_num = 1,
Signature · 1 line
2.45.2
PATCH v5 5/5 tas2783A: Add acpi match changes for Intel MTL
In reply to Niranjan H Yacpi match changes to support tas2783a on mtl
on link 0 for 2 devices
--- .../intel/common/soc-acpi-intel-mtl-match.c | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+)
sound/soc/intel/common/soc-acpi-intel-mtl-match.c +30 -0
@@ -948,6 +948,30 @@ static const struct snd_soc_acpi_adr_device cs42l42_0_adr[] = { } }; +static const struct snd_soc_acpi_adr_device tas2783_0_adr[] = { + { + .adr =0x0000380102000001ull , + .num_endpoints =1 , + .endpoints = &spk_l_endpoint, + .name_prefix ="tas2783-1" + }, + { + .adr =0x0000390102000001ull , + .num_endpoints =1 , + .endpoints = &spk_r_endpoint, + .name_prefix ="tas2783-2" + } +}; + +static const struct snd_soc_acpi_link_adr tas2783_link0[] = { + { + .mask =BIT (0 ), + .num_adr =ARRAY_SIZE (tas2783_0_adr), + .adr_d = tas2783_0_adr, + }, + {} +}; +static const struct snd_soc_acpi_link_adr cs42l42_link0_max98363_link2[] = {/* Expected order: jack -> amp */ {
@@ -1080,6 +1104,12 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_mtl_sdw_machines[] = { .drv_name = "sof_sdw", .sof_tplg_filename = "sof-mtl-rt715-rt711-rt1308-mono.tplg", }, + { + .link_mask = BIT(0), + .links = tas2783_link0, + .drv_name = "sof_sdw", + .sof_tplg_filename = "sof-mtl-tas2783.tplg", + }, { .link_mask = GENMASK(3, 0), .links = mtl_rt713_l0_rt1316_l12_rt1713_l3,
Signature · 1 line
2.45.2
Mark Brown
maintainerQuoted 3 lines · Niranjan H Y
* add error handling in case register read fails
* clamp the values if the register value read is
out of range
This is really two changes, they don't even overlap code wise - see submitting-patches.rst.
sound/soc/soc-ops.c static int soc_get_volsw(struct snd_kcontrol *kcontrol, · line 257
Quoted 10 lines
sound/soc/soc-ops.c +3
-1@@ -249,9 +250,15 @@ static int soc_get_volsw(struct snd_kcontrol *kcontrol, {struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);unsigned int reg_val; -int val; +int val, ret =0 ; reg_val =snd_soc_component_read (component, mc->reg); + val = reg_val; +if (val <0 ) {
Here reg_val is an unsigned int, but then we assign that to an int check if it's less than 0. I don't see how that can work sensibly, and indeed when I test it on some amlogic platforms it blows up:
https://lava.sirena.org.uk/scheduler/job/1862694#L1927
that normaly succeds:
https://lava.sirena.org.uk/scheduler/job/1863246#L1931
It's obviously not a bad idea to have error checking, we should really do that, but it's a bigger rework than this.
Mark Brown
maintainerQuoted 10 lines · Niranjan H Y
* add error handling in case register read fails
* clamp the values if the register value read is
out of range--
v5:
- remove clamp parameter
- move the boundary check after sign-bit extension[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/5] ASoC: ops: improve snd_soc_get_volsw
commit: a0ce874cfaaab9792d657440b9d050e2112f6e4d
[2/5] ASoc: tas2783A: Add soundwire based codec driver
commit: 4cc9bd8d7b32d59b86cb489a96aa8a7b9dd6a21b
[3/5] ASoc: tas2783A: machine driver amp utility for TI devices
commit: 96384a34dd15b0e7357a34af5c848d1115a35e62
[4/5] ASoc: tas2783A: add machine driver changes
commit: b41949a2109e49cb96a1dc292efa249933e5232e
[5/5] tas2783A: Add acpi match changes for Intel MTL
commit: 63b4c34635cf32af023796b64c855dd1ed0f0a4fAll being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 18 lines · Niranjan H Y
* add error handling in case register read fails
* clamp the values if the register value read is
out of rangeSigned-off-by Niranjan H Y <[email protected]>--
v5:
- remove clamp parameter
- move the boundary check after sign-bit extension--- sound/soc/soc-ops.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)sound/soc/soc-ops.c +0
-0
sound/soc/soc-ops.c static int soc_mixer_reg_to_ctl(struct soc_mixer_control *mc, unsigned int reg_v · line 121
Quoted 4 lines
sound/soc/soc-ops.c +1
-0@@ -118,6 +118,7 @@ static int soc_mixer_reg_to_ctl(struct soc_mixer_control *mc, unsigned int reg_vif (mc->sign_bit) val =sign_extend32 (val, mc->sign_bit); + val =clamp (val, mc->min, mc->max);
This code path is shared with SX controls, when the maximum would be mc->min + mc->max. The max parameter to the function can be used to get a more sensible maximum (otherwise there could be cases where min > max):
mc->min + max
Also, the Digital PCM Volume in CS35L36 has some trouble with this. It maps -102dB to 0x4D0 and -0.125dB to 0x7FF (mask 0x7FF). At +0dB, it's supposed to wrap around to 0x000, then go up to +12dB at 0x060. This clamping reads +0dB and above (0x000 to 0x060) as -102dB, since it doesn't account for signed values.