ASoC: SDCA: Export Q7.8 volume control helpers
Subsystems (4)
PATCH v3 1/4 ASoC: SDCA: Export Q7.8 volume control helpers
Export the Q7.8 volume control helpers to allow reuse by other ASoC drivers. These functions handle 16-bit signed Q7.8 fixed-point format values for volume controls.
Changes include:
- Rename q78_get_volsw to sdca_asoc_q78_get_volsw
- Rename q78_put_volsw to sdca_asoc_q78_put_volsw
- Add a convenience macro SDCA_SINGLE_Q78_TLV() for creating mixer controls
This allows other ASoC drivers to easily implement controls using the Q7.8 fixed-point format without duplicating code.
---
v3:
- prepend apis with sdca_asoc_
- add macro SDCA_SINGLE_Q78_TLV
- updated the commit message based on the latest changes
v2:
- newly added patch
--- include/sound/sdca_asoc.h | 25 ++++++++++++++++++++++++- sound/soc/sdca/sdca_asoc.c | 14 ++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-)
include/sound/sdca_asoc.h +24 -1
@@ -13,6 +13,8 @@struct device ;struct regmap ;struct sdca_function_data ; +struct snd_ctl_elem_value ; +struct snd_kcontrol ;struct snd_kcontrol_new ;struct snd_pcm_hw_params ;struct snd_pcm_substream ;
@@ -23,6 +25,24 @@ struct snd_soc_dai_ops;struct snd_soc_dapm_route ;struct snd_soc_dapm_widget ; +/* convenient macro to handle the volume in 7.8 fixed format representation */ +#define SDCA_SINGLE_Q78_TLV (xname, xreg, xmin, xmax, xstep, tlv_array) \ +{ \ + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ + .name = xname, \ + .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE, \ + .tlv.p = (tlv_array), \ + .info = snd_soc_info_volsw, \ + .get = sdca_asoc_q78_get_volsw, \ + .put = sdca_asoc_q78_put_volsw, \ + .private_value = (unsigned long)&(struct soc_mixer_control) { \ + .reg = (xreg), .rreg = (xreg), \ + .min = (xmin), .max = (xmax), \ + .shift = (xstep), .rshift = (xstep), \ + .sign_bit = 15 \ + } \ +} +int sdca_asoc_count_component (struct device *dev,struct sdca_function_data *function,int *num_widgets,int *num_routes,int *num_controls,int *num_dais);
@@ -57,5 +77,8 @@ int sdca_asoc_hw_params(struct device *dev, struct regmap *regmap,struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai); - +int sdca_asoc_q78_put_volsw (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol); +int sdca_asoc_q78_get_volsw (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol);#endif // __SDCA_ASOC_H__
sound/soc/sdca/sdca_asoc.c +8 -6
@@ -820,8 +820,8 @@ static int q78_write(struct snd_soc_component *component,return snd_soc_component_update_bits (component, reg, mask, reg_val); } -static int q78_put_volsw (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +int sdca_asoc_q78_put_volsw (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) {struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);
@@ -841,6 +841,7 @@ static int q78_put_volsw(struct snd_kcontrol *kcontrol,return ret; } +EXPORT_SYMBOL_NS (sdca_asoc_q78_put_volsw,"SND_SOC_SDCA" );static int q78_read (struct snd_soc_component *component,struct soc_mixer_control *mc,unsigned int reg)
@@ -855,8 +856,8 @@ static int q78_read(struct snd_soc_component *component,return val &GENMASK (mc->sign_bit,0 ); } -static int q78_get_volsw (struct snd_kcontrol *kcontrol, -struct snd_ctl_elem_value *ucontrol) +int sdca_asoc_q78_get_volsw (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) {struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;struct snd_soc_component *component =snd_kcontrol_chip (kcontrol);
@@ -868,6 +869,7 @@ static int q78_get_volsw(struct snd_kcontrol *kcontrol,return 0 ; } +EXPORT_SYMBOL_NS (sdca_asoc_q78_get_volsw,"SND_SOC_SDCA" ); static int control_limit_kctl(struct device *dev, struct sdca_entity *entity,
@@ -912,8 +914,8 @@ static int control_limit_kctl(struct device *dev, kctl->tlv.p = tlv; kctl->access |=SNDRV_CTL_ELEM_ACCESS_TLV_READ ; - kctl->get = q78_get_volsw; - kctl->put = q78_put_volsw; + kctl->get = sdca_asoc_q78_get_volsw; + kctl->put = sdca_asoc_q78_put_volsw;return 0 ; }
Signature · 1 line
2.34.1
PATCH v3 2/4 ASoC: tac5xx2-sdw: add soundwire based codec driver
Add codec driver for tac5xx2 family of devices. This includes the support for
1. tac5572 - DAC, PDM, UAJ and HID
2. tas2883 - Amplifier with DSP
3. tac5672 - Similar to tac5572 with feedback
4. tac5682 - Similar to tac5672 with Amplifier DSP.
---
v3:
- use macro SDCA_SINGLE_Q78_TLV for the volume mixer controls
- replace magic number with macro for current owner
- fix debug log message about the current owner for hid event
v2:
- Define and use consistent macros for register access to improve code readability and maintainability
- Replace complex event handlers with simpler DAPM widget implementations using direct register control for muting/unmuting and enabling/disabling components
- Replace custom volume controls with standard Q7.8 controls from the SDCA framework
- Fix PDE power state transitions with proper verification of actual power state
- Combine separate locks into a single ops\_lock to protect both firmware operations and power state transitions
- Clean up interrupt handling by removing unnecessary register accesses
- Fix headset microphone control by using the correct mono channel value
- Add comments to clarify firmware handling and critical sections
--- sound/soc/codecs/Kconfig | 11 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/tac5xx2-sdw.c | 2130 ++++++++++++++++++++++++++++++++ sound/soc/codecs/tac5xx2.h | 259 ++++ 4 files changed, 2402 insertions(+) create mode 100644 sound/soc/codecs/tac5xx2-sdw.c create mode 100644 sound/soc/codecs/tac5xx2.h
sound/soc/codecs/Kconfig +11 -0
@@ -264,6 +264,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_STA529 imply SND_SOC_STAC9766 imply SND_SOC_STI_SAS + imply SND_SOC_TAC5XX2_SDW imply SND_SOC_TAS2552 imply SND_SOC_TAS2562 imply SND_SOC_TAS2764
@@ -2139,6 +2140,16 @@ config SND_SOC_STAC9766 config SND_SOC_STI_SAS tristate "codec Audio support for STI SAS codec" +config SND_SOC_TAC5XX2_SDW + tristate "Texas Instruments TAC5XX2 SoundWire Smart Amplifier" + depends on SOUNDWIRE + depends on SND_SOC_SDCA + help + This option enables support for Texas Instruments TAC5XX2 family + of SoundWire Smart Amplifiers. This includes TAC5572, TAC5672, + TAC568 and TAS2883. To compile this driver as a module, choose + M here: the module will be called snd-soc-tac5xx2. + config SND_SOC_TAS2552 tristate "Texas Instruments TAS2552 Mono Audio amplifier" depends on I2C
sound/soc/codecs/Makefile +2 -0
@@ -313,6 +313,7 @@ snd-soc-sta350-y := sta350.o snd-soc-sta529-y := sta529.o snd-soc-stac9766-y := stac9766.o snd-soc-sti-sas-y := sti-sas.o +snd-soc-tac5xx2-sdw-y := tac5xx2-sdw.o snd-soc-tas5086-y := tas5086.o snd-soc-tas571x-y := tas571x.o snd-soc-tas5720-y := tas5720.o
@@ -746,6 +747,7 @@ obj-$(CONFIG_SND_SOC_STA350) += snd-soc-sta350.o obj-$(CONFIG_SND_SOC_STA529) += snd-soc-sta529.o obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o obj-$(CONFIG_SND_SOC_STI_SAS) += snd-soc-sti-sas.o +obj-$(CONFIG_SND_SOC_TAC5XX2_SDW) += snd-soc-tac5xx2-sdw.o 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
sound/soc/codecs/tac5xx2-sdw.c new file +2130 -0
2,130 lines not on this page · raw message
sound/soc/codecs/tac5xx2.h new file +259 -0
259 lines not on this page · raw message
Signature · 1 line
2.34.1
Mark Brown
maintainerRe: [PATCH v3 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver
Quoted 11 lines · Niranjan H Y
Add codec driver for tac5xx2 family of devices.
sound/soc/codecs/tac5xx2-sdw.c new file +8
-0+static int tac_cx11_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_component *component; +struct tac5xx2_prv *tac_dev; + + ucontrol->value.enumerated.item[0 ] =1 ;/* Default to DC:1 */ +
sound/soc/codecs/tac5xx2-sdw.c line 551
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+if (!kcontrol || !kcontrol->private_data) +return 0 ; + + component =snd_kcontrol_chip (kcontrol); +if (!component) +return 0 ; + + tac_dev =snd_soc_component_get_drvdata (component); +if (!tac_dev) +return 0 ;
Shouldn't these be errors?
sound/soc/codecs/tac5xx2-sdw.c line 595
Quoted 13 lines
sound/soc/codecs/tac5xx2-sdw.c new file +12
-0+ +static int tac_cx11_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ + ret =regmap_write (tac_dev->regmap, +SDW_SDCA_CTL (TAC_FUNCTION_ID_SM ,TAC_SDCA_ENT_CX11 , +TAC_SDCA_CTL_CX_CLK_SEL ,0 ), + val); +if (ret) { +dev_dbg (tac_dev->dev,"cx put failed" ); +return -EIO ; + }
Probably nicer to return the error code you got here, and also include it in the log message - that'll help people figure out what's going on if things do go wrong.
sound/soc/codecs/tac5xx2-sdw.c line 605
Quoted 6 lines
sound/soc/codecs/tac5xx2-sdw.c new file +6
-0+/* Volume controls for mic, hp and mic cap */ +static const struct snd_kcontrol_new tac5xx2_snd_controls[] = { +SOC_SINGLE_RANGE_TLV ("Left Amp Volume" ,TAC_AMP_LVL_CFG0 ,2 ,0 ,44 ,1 , + tac5xx2_amp_tlv), +SOC_SINGLE_RANGE_TLV ("Right Amp Volume" ,TAC_AMP_LVL_CFG1 ,2 ,0 ,44 ,1 , + tac5xx2_amp_tlv),
What's the logic behind two mono controls rather than stereo controls? There's a bunch of these in the driver.
sound/soc/codecs/tac5xx2-sdw.c line 842
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +9
-0+static int tac_sdw_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai) +{ +if (dai->id ==TAC5XX2_DMIC ) { + }else if (dai->id ==TAC5XX2_UAJ ) { + }else if (dai->id ==TAC5XX2_SPK ) { + }else { + }
This should be a switch statement for clarity and scalability.
Quoted 8 lines
sound/soc/codecs/tac5xx2-sdw.c new file +8
-0+switch (params_rate (params)) { +case 48000 : + sample_rate_idx =0x01 ; +break ; +case 44100 : + sample_rate_idx =0x02 ; +break ; +case 96000 :
sound/soc/codecs/tac5xx2-sdw.c line 873
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+ sample_rate_idx =0x03 ; +break ; +case 88200 : + sample_rate_idx =0x04 ; +break ; +default : +dev_err (tac_dev->dev,"Unsupported sample rate: %d Hz" , +params_rate (params)); +return -EINVAL ; + }
This allows userspace to spam the logs doesn't it?
sound/soc/codecs/tac5xx2-sdw.c line 910
Quoted 2 lines
sound/soc/codecs/tac5xx2-sdw.c new file +2
-0+if (function_id ==TAC_FUNCTION_ID_SM ) { + }else if (function_id ==TAC_FUNCTION_ID_UAJ ) {
Again, switch statement. There's a bunch of these in teh driver.
Quoted 7 lines
sound/soc/codecs/tac5xx2-sdw.c new file +6
-0+static s32 tac_fw_read_hdr (const u8 *data,struct tac_fw_hdr *hdr) +{ + hdr->size =get_unaligned_le32 (data); + +return TAC_FW_HDR_SIZE ; +}
sound/soc/codecs/tac5xx2-sdw.c line 1679
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +9
-0+static s32 tac_download_fw_to_hw (struct tac5xx2_prv *tac_dev) +{ + buf = tac_dev->fw_data; + img_sz = tac_dev->fw_size; + +dev_dbg (tac_dev->dev,"Downloading cached firmware to HW, size=%zu\n" , img_sz); + + offset +=tac_fw_read_hdr (buf, hdr); +if (hdr->size != img_sz) {
We don't validate that the file has enough data to read here, there's a check after the request_firmware() that the file is non-zero but it might just be a single byte.
sound/soc/codecs/tac5xx2-sdw.c line 1700
Quoted 9 lines
sound/soc/codecs/tac5xx2-sdw.c new file +9
-0+while (offset < img_sz && num_files <TAC_MAX_FW_CHUNKS ) { +if (offset +20 > img_sz) { +dev_warn (tac_dev->dev,"Incomplete block header at offset %d\n" , + offset); +break ; + } + offset +=tac_fw_get_next_file (&buf[offset], &files[num_files]); + num_files++; + }
I can't see anything that validates that we stay within the buffer here, we're checking if the header is in the buffer but not the payload and if we do overflow we just exit the loop and...
sound/soc/codecs/tac5xx2-sdw.c line 1706
Quoted 6 lines
sound/soc/codecs/tac5xx2-sdw.c new file +6
-0+ +if (num_files ==0 ) { +dev_err (tac_dev->dev,"firmware with no files\n" ); + ret = -EINVAL ; + goto out; + }
...so long as we found at least one block we'll just carry on.
PATCH v3 3/4 ASoC: sdw_utils: TI amp utility for tac5xx2 family
In reply to Niranjan H Y Add TI amp utility for supporting the tac5xx2 family
of devices to support tac5572, tac5672, tac5682 and tas2883
---
v3:
- no change
v2:
- no change
--- include/sound/soc_sdw_utils.h | 4 + sound/soc/sdw_utils/soc_sdw_ti_amp.c | 144 ++++++++++++++++++++++++- sound/soc/sdw_utils/soc_sdw_utils.c | 151 +++++++++++++++++++++++++++ 3 files changed, 298 insertions(+), 1 deletion(-)
include/sound/soc_sdw_utils.h +4 -0
@@ -272,7 +272,11 @@ int asoc_sdw_ti_amp_init(struct snd_soc_card *card,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_tac5xx2_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); +int asoc_sdw_ti_dmic_rtd_init (struct snd_soc_pcm_runtime *rtd,struct snd_soc_dai *dai); +int asoc_sdw_ti_sdca_jack_rtd_init (struct snd_soc_pcm_runtime *rtd,struct snd_soc_dai *dai);#endif
sound/soc/sdw_utils/soc_sdw_ti_amp.c +143 -1
158 lines not on this page · raw message
sound/soc/sdw_utils/soc_sdw_utils.c +151 -0
157 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 4/4 ASoC: tac5xx2-sdw: ACPI match for intel mtl platform
In reply to Niranjan H Y Add acpi match entries to support TI's tac5572,
tas2883, tac5672 and tac5682 on link 0 on MTL machine.
---
v3:
- no change
v2:
- no change
--- .../intel/common/soc-acpi-intel-mtl-match.c | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+)
sound/soc/intel/common/soc-acpi-intel-mtl-match.c +132 -0
@@ -122,6 +122,42 @@ static const struct snd_soc_acpi_endpoint spk_r_endpoint = { .group_id = 1, }; +static const struct snd_soc_acpi_endpoint tac5xx2_endpoints[] = { + {/* Playback Endpoint */ + .num =0 , + .aggregated =0 , + .group_position =0 , + .group_id =0 , + }, + {/* Mic Capture Endpoint */ + .num =1 , + .aggregated =0 , + .group_position =0 , + .group_id =0 , + }, + {/* UAJ-HP with Mic Endpoint */ + .num =2 , + .aggregated =0 , + .group_position =0 , + .group_id =0 , + }, +}; + +static const struct snd_soc_acpi_endpoint tas2883_endpoints[] = { + {/* Playback Endpoint */ + .num =0 , + .aggregated =0 , + .group_position =0 , + .group_id =0 , + }, + {/* Mic Capture Endpoint */ + .num =1 , + .aggregated =0 , + .group_position =0 , + .group_id =0 , + }, +}; +static const struct snd_soc_acpi_endpoint rt712_endpoints[] = { { .num =0 ,
@@ -1011,6 +1047,33 @@ static const struct snd_soc_acpi_adr_device cs42l42_0_adr[] = { } }; +static const struct snd_soc_acpi_adr_device tac5572_0_adr[] = { + { + .adr =0x0000300102557201ull , + .num_endpoints =ARRAY_SIZE (tac5xx2_endpoints), + .endpoints = tac5xx2_endpoints, + .name_prefix ="tac5572" + } +}; + +static const struct snd_soc_acpi_adr_device tac5672_0_adr[] = { + { + .adr =0x0000300102567201ull , + .num_endpoints =ARRAY_SIZE (tac5xx2_endpoints), + .endpoints = tac5xx2_endpoints, + .name_prefix ="tac5672" + } +}; + +static const struct snd_soc_acpi_adr_device tac5682_0_adr[] = { + { + .adr =0x0000300102568201ull , + .num_endpoints =ARRAY_SIZE (tac5xx2_endpoints), + .endpoints = tac5xx2_endpoints, + .name_prefix ="tac5682" + } +}; +static const struct snd_soc_acpi_adr_device tas2783_0_adr[] = { { .adr =0x00003c0102000001ull ,
@@ -1035,9 +1098,45 @@ static const struct snd_soc_acpi_adr_device tas2783_0_adr[] = { .num_endpoints = 1, .endpoints = &spk_r_endpoint, .name_prefix ="tas2783-4" + }, +}; + +static const struct snd_soc_acpi_adr_device tas2883_0_adr[] = { + { + .adr =0x0000300102288301ull , + .num_endpoints =ARRAY_SIZE (tas2883_endpoints), + .endpoints = tas2883_endpoints, + .name_prefix ="tas2883" } }; +static const struct snd_soc_acpi_link_adr tac5572_l0[] = { + { + .mask =BIT (0 ), + .num_adr =ARRAY_SIZE (tac5572_0_adr), + .adr_d = tac5572_0_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr tac5672_l0[] = { + { + .mask =BIT (0 ), + .num_adr =ARRAY_SIZE (tac5672_0_adr), + .adr_d = tac5672_0_adr, + }, + {} +}; + +static const struct snd_soc_acpi_link_adr tac5682_l0[] = { + { + .mask =BIT (0 ), + .num_adr =ARRAY_SIZE (tac5682_0_adr), + .adr_d = tac5682_0_adr, + }, + {} +}; +static const struct snd_soc_acpi_link_adr tas2783_link0[] = { { .mask =BIT (0 ),
@@ -1047,6 +1146,15 @@ static const struct snd_soc_acpi_link_adr tas2783_link0[] = { {} }; +static const struct snd_soc_acpi_link_adr tas2883_l0[] = { + { + .mask =BIT (0 ), + .num_adr =ARRAY_SIZE (tas2883_0_adr), + .adr_d = tas2883_0_adr, + }, + {} +}; +static const struct snd_soc_acpi_link_adr cs42l42_link0_max98363_link2[] = {/* Expected order: jack -> amp */ {
@@ -1208,12 +1316,36 @@ 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 = tac5572_l0, + .drv_name = "sof_sdw", + .sof_tplg_filename = "sof-mtl-tac5572.tplg", + }, + { + .link_mask = BIT(0), + .links = tac5672_l0, + .drv_name = "sof_sdw", + .sof_tplg_filename = "sof-mtl-tac5672.tplg", + }, + { + .link_mask = BIT(0), + .links = tac5682_l0, + .drv_name = "sof_sdw", + .sof_tplg_filename = "sof-mtl-tac5682.tplg", + }, { .link_mask = BIT(0), .links = tas2783_link0, .drv_name = "sof_sdw", .sof_tplg_filename = "sof-mtl-tas2783.tplg", }, + { + .link_mask = BIT(0), + .links = tas2883_l0, + .drv_name = "sof_sdw", + .sof_tplg_filename = "sof-mtl-tas2883.tplg", + }, { .link_mask = GENMASK(3, 0), .links = mtl_rt713_l0_rt1316_l12_rt1713_l3,
Signature · 1 line
2.34.1
Quoted 10 lines · Niranjan H Y
Export the Q7.8 volume control helpers to allow reuse by other ASoC drivers. These functions handle 16-bit signed Q7.8 fixed-point format values for volume controls.
Changes include:
- Renameq78_get_volswtosdca_asoc_q78_get_volsw
- Renameq78_put_volswtosdca_asoc_q78_put_volsw
- Add a convenience macroSDCA_SINGLE_Q78_TLV()for creating mixer controls
Quoted 5 lines
This allows other ASoC drivers to easily implement controls using the Q7.8 fixed-point format without duplicating code.
Signed-off-by Niranjan H Y <[email protected]>---
Thanks,
Charles