ASoC: tac5xx2-sdw: add soundwire based codec driver
Subsystems (3)
PATCH v5 1/3 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.
---
v5:
- add missing pde_lock while accessing the current power state.
- add uaj_lock to serialize uaj detection update
- return error, if any, returned by sdw_stream_add_slave in hw_parms
- drop snd_soc_unregister_component as we are using devm_snd_soc_register_component
- fix issue in error handling for invalid firmware
- remove unsupported line in/out detection in jack detection
- refactor the jack and button detection logic to be based on their respective interrupt
v4:
- make volume controls as stereo controls for amp gain, playback, dmic and uaj playback.
- better error handling for "CX11 CS Select" mixer control.
- use switch statement for scalability in hw_params and hw_free
- remove unnecessary else in tac_io_init
- change error log for unsupported sample rates to debug logs
- make firmware binary parsing robust by checking the fw size during caching and parsing
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 | 2174 ++++++++++++++++++++++++++++++++ sound/soc/codecs/tac5xx2.h | 259 ++++ 4 files changed, 2446 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 +2174 -0
2,174 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
PATCH v5 2/3 ASoC: sdw_utils: TI amp utility for tac5xx2 family
Add TI amp utility for supporting the tac5xx2 family
of devices to support tac5572, tac5672, tac5682 and tas2883
---
v5:
- no change
v4:
- 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 v5 3/3 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.
---
v5:
- no change
v4:
- 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
Mark Brown
maintainersound/soc/codecs/tac5xx2-sdw.c line 1604
Quoted 10 lines · Niranjan H Y
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+static s32 tac_load_and_cache_firmware (struct tac5xx2_prv *tac_dev) +{ +const struct firmware *fmw =NULL ; +const char *fw_name_used =NULL ; +s32 ret =0 ; +u8 *cached_data =NULL ; +u32 fw_hdr_size; + +mutex_lock (&tac_dev->pde_lock); + ret =request_firmware (&fmw, tac_dev->fw_binaryname, tac_dev->dev);
This is happening in the SoundWire bus callback - if request_firmware() ends up being slow (eg, a userspace helper faffing) we might block other things on the bus.
Quoted 7 lines
sound/soc/codecs/tac5xx2-sdw.c new file +5
-0+static s32 tac_download_fw_to_hw (struct tac5xx2_prv *tac_dev) +{ +while (offset < img_sz && num_files <TAC_MAX_FW_CHUNKS ) { +if (file_length > img_sz || offset > img_sz -TAC_FW_FILE_HDR || + file_length > img_sz - offset -TAC_FW_FILE_HDR ) {
sound/soc/codecs/tac5xx2-sdw.c line 1759
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +9
-0+dev_warn (tac_dev->dev,"File at offset %d exceeds buffer: length=%u, available=%zu\n" , + offset, file_length, img_sz - offset -TAC_FW_FILE_HDR ); +break ; + } +if (num_files ==0 ) { +dev_err (tac_dev->dev,"firmware with no files\n" ); + ret = -EINVAL ; + goto out; + }
If we've parsed any files then an oversized file will just break out of the loop and download what we got already, is that desirable?
Quoted 7 lines
sound/soc/codecs/tac5xx2-sdw.c new file +7
-0+if (tac_dev->sm_func_data) { + ret =sdca_regmap_write_init (dev, tac_dev->regmap, + tac_dev->sm_func_data); +if (ret) { +dev_err (dev,"smartmic init table update failed\n" ); + goto io_init_err; + }
sound/soc/codecs/tac5xx2-sdw.c line 1875
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+dev_dbg (dev,"smartmic init done\n" ); + +if (first) { +/* Set default value to CS:11 */ + tac_dev->cx11_value =1 ; +regmap_write (tac_dev->regmap, +SDW_SDCA_CTL (TAC_FUNCTION_ID_SM , +TAC_SDCA_ENT_CX11 , +TAC_SDCA_CTL_CX_CLK_SEL ,0 ), + tac_dev->cx11_value);
This looks like it could race with tac_cx11_put() - they both write cx11_value but the control could be modifying it. I can imagine that happening if userspace starts and is setting config while the SoundWire bus is coming on line.
Quoted 7 lines · Mark Brown
Subject: Re: [PATCH v5 1/3] ASoC: tac5xx2-sdw: add soundwire based codec driver
Quoted 2 lines · Niranjan H Y
sound/soc/codecs/tac5xx2-sdw.c new file +2
-0+static s32 tac_load_and_cache_firmware (struct tac5xx2_prv *tac_dev) +{
...
Quoted 6 lines
Quoted 2 lines
(quoted diff) +1
-0+ ret = request_firmware(&fmw, tac_dev->fw_binaryname, tac_dev-dev);
This is happening in the SoundWire bus callback - if
request_firmware()ends up being slow (eg, a userspace helper faffing) we might block other things on the bus.
I'll move this to probe and use request_firmware_nowait() to prepare the firmware in background.
Quoted 9 lines
sound/soc/codecs/tac5xx2-sdw.c line 1876
Quoted 8 lines
sound/soc/codecs/tac5xx2-sdw.c new file +8
-0+ +if (first) { +/* Set default value to CS:11 */ + tac_dev->cx11_value =1 ; + regmap_write(tac_dev->regmap, + SDW_SDCA_CTL(TAC_FUNCTION_ID_SM, + TAC_SDCA_ENT_CX11, +TAC_SDCA_CTL_CX_CLK_SEL, 0),
Quoted 6 lines
sound/soc/codecs/tac5xx2-sdw.c line 1875
Quoted 1 line
sound/soc/codecs/tac5xx2-sdw.c new file +1
-0+ tac_dev->cx11_value);This looks like it could race with
tac_cx11_put()- they both writecx11_valuebut the control could be modifying it. I can imagine that happening if userspace starts and is setting config while the SoundWire bus is coming on line.
I will drop the userspace control as Pierre suggested. The CX11 clock selector will be set to the default value (CS:11) during initialization, eliminating the race condition. The device functions correctly with this fixed configuration for smart mic based on my testing.
Regards
Niranjan
Pierre-Louis Bossart
reviewerQuoted 5 lines
sound/soc/codecs/tac5xx2-sdw.c new file +4
-0+struct tac5xx2_prv { +struct snd_soc_component *component; +struct sdw_slave *sdw_peripheral; +struct sdca_function_data *sa_func_data;
sound/soc/codecs/tac5xx2-sdw.c line 139
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+struct sdca_function_data *sm_func_data; +struct sdca_function_data *uaj_func_data; +struct sdca_function_data *hid_func_data; +enum sdw_slave_status status; +/* Lock for firmware download and PDE state transitions. +* Serializes FW caching/download and DAPM-driven power +* state changes to prevent PDE operations during firmware load. +*/ +struct mutex pde_lock; +/* serialize potential concurrnet uaj detection in .hw_params
concurrent
Quoted 43 lines
(quoted diff) +42
-0+ * during playback session and .interrupt_callback. + */ + struct mutex uaj_lock; + struct regmap *regmap; + struct device *dev; + bool hw_init; + bool first_hw_init; + u32 part_id; + unsigned int cx11_value; + struct snd_soc_jack *hs_jack; + int jack_type; + /* Custom fw binary. UMP File Download is not used. */ + const u8 *fw_data; + size_t fw_size; + bool fw_cached; + bool fw_dl_success; + u8 fw_binaryname[64]; +}; +static int tac_cx11_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component; + struct tac5xx2_prv *tac_dev; + unsigned int val; + int ret; + + val = ucontrol->value.enumerated.item[0]; + + if (val >= ARRAY_SIZE(tac_cx11_mux_texts)) + return -EINVAL; + + component = snd_kcontrol_chip(kcontrol); + if (!component) + return -ENODEV; + + tac_dev = snd_soc_component_get_drvdata(component); + if (!tac_dev || !tac_dev->sdw_peripheral || !tac_dev->hw_init) { + dev_err(component->dev, "failed to get driver data for cx put"); + return -ENODEV; + } + + if (tac_dev->cx11_value == val) {
Review
Quoted 10 lines
(quoted diff) +10
-0+ dev_dbg(tac_dev->dev, "cx put, same value"); + return 0; /* No change */ + } + + tac_dev->cx11_value = val; + + 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);
do you really want to let userspace control the clock sources?
In most cases the clock sources should only be changed to let the SDCA device operate on its own while the bus is stopped. userspace has no concept of SoundWire bus stop, nor is it aware of when playback actually starts.
This deserves more explanations/discussions.
Quoted 394 lines
sound/soc/codecs/tac5xx2-sdw.c new file +394
-0+if (ret) { +dev_err (tac_dev->dev,"cx put failed: %d" , ret); +return ret; + } + +return 1 ; +} + +/* Volume controls for mic, hp and mic cap */ +static const struct snd_kcontrol_new tac5xx2_snd_controls[] = { +SOC_DOUBLE_R_RANGE_TLV ("Amp Volume" ,TAC_AMP_LVL_CFG0 ,TAC_AMP_LVL_CFG1 , +2 ,0 ,44 ,1 , tac5xx2_amp_tlv), +TAC_DOUBLE_Q78_TLV ("DMIC Capture Volume" ,SM ,FU113 ), +TAC_DOUBLE_Q78_TLV ("Speaker Volume" ,SA ,FU21 ), +SOC_DAPM_ENUM_EXT ("CX11 CS Select" , tac_cx11_mux_enum, tac_cx11_get, + tac_cx11_put), +}; + +static const struct snd_kcontrol_new tac_uaj_controls[] = { +TAC_DOUBLE_Q78_TLV ("UAJ Playback Volume" ,UAJ ,FU41 ), +SDCA_SINGLE_Q78_TLV ("UAJ Capture Volume" , +SDW_SDCA_CTL (TAC_FUNCTION_ID_UAJ ,TAC_SDCA_ENT_FU36 , +TAC_SDCA_CHANNEL_GAIN ,TAC_JACK_MONO_CS ), +TAC_DVC_MIN ,TAC_DVC_MAX ,TAC_DVC_STEP , tac5xx2_dvc_tlv), +}; + +static const struct snd_soc_dapm_widget tac5xx2_common_widgets[] = { +/* Port 1: Speaker Playback Path */ +SND_SOC_DAPM_AIF_IN ("AIF1 Playback" ,"DP1 Speaker Playback" ,0 , +SND_SOC_NOPM ,0 ,0 ), +SND_SOC_DAPM_PGA ("FU21_L" ,FU21_L_MUTE_REG ,0 ,1 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("FU21_R" ,FU21_R_MUTE_REG ,0 ,1 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("FU23_L" ,FU23_L_MUTE_REG ,0 ,1 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("FU23_R" ,FU23_R_MUTE_REG ,0 ,1 ,NULL ,0 ), +SND_SOC_DAPM_OUTPUT ("SPK_L" ), +SND_SOC_DAPM_OUTPUT ("SPK_R" ), + +/* Port 3: Smart Mic (DMIC) Capture Path */ +SND_SOC_DAPM_AIF_OUT ("AIF3 Capture" ,"DP3 Mic Capture" ,0 ,SND_SOC_NOPM ,0 ,0 ), +SND_SOC_DAPM_INPUT ("DMIC_L" ), +SND_SOC_DAPM_INPUT ("DMIC_R" ), +SND_SOC_DAPM_PGA ("IT11" ,IT11_USAGE_REG ,0 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY ("CS11" ,SND_SOC_NOPM ,0 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY ("CS18" ,SND_SOC_NOPM ,0 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY ("CS113" ,SND_SOC_NOPM ,0 ,0 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("FU11_L" ,FU11_L_MUTE_REG ,0 ,1 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("FU11_R" ,FU11_R_MUTE_REG ,0 ,1 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("PPU11" ,SND_SOC_NOPM ,0 ,0 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("XU12" ,XU12_BYPASS_REG ,0 ,0 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("FU113_L" ,FU113_L_MUTE_REG ,0 ,1 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("FU113_R" ,FU113_R_MUTE_REG ,0 ,1 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("OT113" ,OT113_USAGE_REG ,0 ,0 ,NULL ,0 ), +}; + +static const struct snd_soc_dapm_widget tac_uaj_widgets[] = { +/* Port 4: UAJ (Headphone) Playback Path */ +SND_SOC_DAPM_AIF_IN ("AIF4 Playback" ,"DP4 UAJ Speaker Playback" ,0 , +SND_SOC_NOPM ,0 ,0 ), +SND_SOC_DAPM_PGA ("IT41" ,IT41_USAGE_REG ,0 ,0 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("FU41_L" ,FU41_L_MUTE_REG ,0 ,1 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("FU41_R" ,FU41_R_MUTE_REG ,0 ,1 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("XU42" ,XU42_BYPASS_REG ,0 ,0 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY ("CS41" ,SND_SOC_NOPM ,0 ,0 ,NULL ,0 ), +SND_SOC_DAPM_DAC ("OT45" ,"DP4 UAJ Speaker Playback" ,OT45_USAGE_REG ,0 ,0 ), +SND_SOC_DAPM_OUTPUT ("HP_L" ), +SND_SOC_DAPM_OUTPUT ("HP_R" ), + +/* Port 7: UAJ (Headset Mic) Capture Path */ +SND_SOC_DAPM_AIF_OUT ("AIF7 Capture" ,"DP7 UAJ Mic Capture" ,0 , +SND_SOC_NOPM ,0 ,0 ), +SND_SOC_DAPM_INPUT ("UAJ_MIC" ), +SND_SOC_DAPM_ADC ("IT33" ,"DP7 UAJ Mic Capture" ,IT33_USAGE_REG ,0 ,0 ), +SND_SOC_DAPM_PGA ("FU36" ,FU36_MUTE_REG ,0 ,1 ,NULL ,0 ), +SND_SOC_DAPM_SUPPLY ("CS36" ,SND_SOC_NOPM ,0 ,0 ,NULL ,0 ), +SND_SOC_DAPM_PGA ("OT36" ,OT36_USAGE_REG ,0 ,0 ,NULL ,0 ), +}; + +static const struct snd_soc_dapm_route tac5xx2_common_routes[] = { +/* Speaker Playback Path */ + {"FU21_L" ,NULL ,"AIF1 Playback" }, + {"FU21_R" ,NULL ,"AIF1 Playback" }, + + {"FU23_L" ,NULL ,"FU21_L" }, + {"FU23_R" ,NULL ,"FU21_R" }, + + {"SPK_L" ,NULL ,"FU23_L" }, + {"SPK_R" ,NULL ,"FU23_R" }, + +/* Smart Mic DAPM Routes */ + {"IT11" ,NULL ,"DMIC_L" }, + {"IT11" ,NULL ,"DMIC_R" }, + {"IT11" ,NULL ,"CS11" }, + {"IT11" ,NULL ,"CS18" }, + {"FU11_L" ,NULL ,"IT11" }, + {"FU11_R" ,NULL ,"IT11" }, + {"PPU11" ,NULL ,"FU11_L" }, + {"PPU11" ,NULL ,"FU11_R" }, + {"XU12" ,NULL ,"PPU11" }, + {"FU113_L" ,NULL ,"XU12" }, + {"FU113_R" ,NULL ,"XU12" }, + {"FU113_L" ,NULL ,"CS113" }, + {"FU113_R" ,NULL ,"CS113" }, + {"OT113" ,NULL ,"FU113_L" }, + {"OT113" ,NULL ,"FU113_R" }, + {"OT113" ,NULL ,"CS113" }, + {"AIF3 Capture" ,NULL ,"OT113" }, +}; + +static const struct snd_soc_dapm_route tac_uaj_routes[] = { +/* UAJ Playback routes */ + {"IT41" ,NULL ,"AIF4 Playback" }, + {"IT41" ,NULL ,"CS41" }, + {"FU41_L" ,NULL ,"IT41" }, + {"FU41_R" ,NULL ,"IT41" }, + {"XU42" ,NULL ,"FU41_L" }, + {"XU42" ,NULL ,"FU41_R" }, + {"OT45" ,NULL ,"XU42" }, + {"OT45" ,NULL ,"CS41" }, + {"HP_L" ,NULL ,"OT45" }, + {"HP_R" ,NULL ,"OT45" }, + +/* UAJ Capture routes */ + {"IT33" ,NULL ,"UAJ_MIC" }, + {"IT33" ,NULL ,"CS36" }, + {"FU36" ,NULL ,"IT33" }, + {"OT36" ,NULL ,"FU36" }, + {"OT36" ,NULL ,"CS36" }, + {"AIF7 Capture" ,NULL ,"OT36" }, +}; + +static s32 tac_set_sdw_stream (struct snd_soc_dai *dai, +void *sdw_stream,s32 direction) +{ +if (sdw_stream) +snd_soc_dai_dma_data_set (dai, direction, sdw_stream); + +return 0 ; +} + +static void tac_sdw_shutdown (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +snd_soc_dai_set_dma_data (dai, substream,NULL ); +} + +static int tac_clear_latch (struct tac5xx2_prv *priv) +{ +int ret; + + ret =regmap_write (priv->regmap,TAC_INT_CFG ,0X00 ); +if (ret) +return ret; + + ret =regmap_update_bits (priv->regmap,TAC_INT_CFG , +TAC_INT_CFG_CLR_REG ,TAC_INT_CFG_CLR_REG ); +if (ret) +return ret; + + ret =regmap_write (priv->regmap,TAC_INT_CFG ,0X00 ); +return ret; +} + +static int tac_sdw_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai) +{ +struct snd_soc_component *component = dai->component; +struct tac5xx2_prv *tac_dev =snd_soc_component_get_drvdata (component); +struct sdw_stream_config stream_config = {0 }; +struct sdw_port_config port_config = {0 }; +struct sdw_stream_runtime *sdw_stream; +struct sdw_slave *sdw_peripheral = tac_dev->sdw_peripheral; +unsigned long time; +int ret, retry; +int function_id; +int pde_entity; +int port_num; +unsigned int actual_ps =3 ;/* off */ +u8 sample_rate_idx =0 ; + + time =wait_for_completion_timeout (&sdw_peripheral->initialization_complete, +msecs_to_jiffies (TAC5XX2_PROBE_TIMEOUT_MS )); +if (!time) { +dev_warn (tac_dev->dev,"%s: hw initialization timeout\n" , __func__); +return -ETIMEDOUT ; + } +if (!tac_dev->hw_init) { +dev_err (tac_dev->dev, +"error: operation without hw initialization" ); +return -EINVAL ; + } + + sdw_stream =snd_soc_dai_get_dma_data (dai, substream); +if (!sdw_stream) { +dev_err (tac_dev->dev,"failed to get dma data" ); +return -EINVAL ; + } + + ret =tac_clear_latch (tac_dev); +if (ret) +dev_warn (tac_dev->dev,"clear latch failed, err=%d" , ret); + +switch (dai->id) { +case TAC5XX2_DMIC : + function_id =TAC_FUNCTION_ID_SM ; + pde_entity =TAC_SDCA_ENT_PDE11 ; + port_num =TAC_SDW_PORT_NUM_DMIC ; +break ; +case TAC5XX2_UAJ : + function_id =TAC_FUNCTION_ID_UAJ ; + pde_entity = substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ? +TAC_SDCA_ENT_PDE47 :TAC_SDCA_ENT_PDE34 ; + port_num = substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ? +TAC_SDW_PORT_NUM_UAJ_PLAYBACK : +TAC_SDW_PORT_NUM_UAJ_CAPTURE ; +/* Detect and set jack type for UAJ path before playback. +* This is required as jack is not triggering interrupt +* when the device is in suspended mode. +*/ +mutex_lock (&tac_dev->uaj_lock); +tac5xx2_sdca_headset_detect (tac_dev); +mutex_unlock (&tac_dev->uaj_lock); +break ; +case TAC5XX2_SPK : + function_id =TAC_FUNCTION_ID_SA ; + pde_entity =TAC_SDCA_ENT_PDE23 ; + port_num = substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ? +TAC_SDW_PORT_NUM_SPK_PLAYBACK : +TAC_SDW_PORT_NUM_SPK_CAPTURE ; +break ; +default : +dev_err (tac_dev->dev,"Invalid dai id: %d" , dai->id); +return -EINVAL ; + } + +mutex_lock (&tac_dev->pde_lock); +regmap_write (tac_dev->regmap,SDW_SDCA_CTL (function_id, pde_entity, +TAC_SDCA_REQUESTED_PS ,0 ), +0x03 ); +mutex_unlock (&tac_dev->pde_lock); + +snd_sdw_params_to_config (substream, params, &stream_config, &port_config); + port_config.num = port_num; + ret =sdw_stream_add_slave (sdw_peripheral, &stream_config, + &port_config,1 , sdw_stream); +if (ret) { +dev_err (dai->dev, +"Unable to configure port %d: %d\n" , port_num, ret); +return ret; + } + +switch (params_rate (params)) { +case 48000 : + sample_rate_idx =0x01 ; +break ; +case 44100 : + sample_rate_idx =0x02 ; +break ; +case 96000 : + sample_rate_idx =0x03 ; +break ; +case 88200 : + sample_rate_idx =0x04 ; +break ; +default : +dev_dbg (tac_dev->dev,"Unsupported sample rate: %d Hz" , +params_rate (params)); +return -EINVAL ; + } + +switch (function_id) { +case TAC_FUNCTION_ID_SM : + ret =regmap_write (tac_dev->regmap, +SDW_SDCA_CTL (function_id,TAC_SDCA_ENT_PPU11 , +TAC_SDCA_CTL_PPU_POSTURE_NUM ,0 ), +0 ); +if (ret) { +dev_err (tac_dev->dev,"Failed to set PPU11: %d" , ret); +return ret; + } + + ret =regmap_write (tac_dev->regmap, +SDW_SDCA_CTL (function_id,TAC_SDCA_ENT_CS113 , +TAC_SDCA_CTL_CS_SAMP_RATE_IDX ,0 ), + sample_rate_idx); +if (ret) { +dev_err (tac_dev->dev,"Failed to set CS113 sample rate: %d" , ret); +return ret; + } + +if (tac_dev->cx11_value) { + ret =regmap_write (tac_dev->regmap, +SDW_SDCA_CTL (function_id,TAC_SDCA_ENT_CS11 , +TAC_SDCA_CTL_CS_SAMP_RATE_IDX ,0 ), + sample_rate_idx); + }else { + ret =regmap_write (tac_dev->regmap, +SDW_SDCA_CTL (function_id,TAC_SDCA_ENT_CS18 , +TAC_SDCA_CTL_CS_SAMP_RATE_IDX ,0 ), + sample_rate_idx); + } +if (ret) { +dev_err (tac_dev->dev,"Failed to set %s sample rate: %d" , + tac_dev->cx11_value ?"CS11" :"CS18" , ret); +return ret; + } +break ; +case TAC_FUNCTION_ID_UAJ : +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { + ret =regmap_write (tac_dev->regmap, +SDW_SDCA_CTL (function_id,TAC_SDCA_ENT_CS41 , +TAC_SDCA_CTL_CS_SAMP_RATE_IDX ,0 ), + sample_rate_idx); +if (ret) { +dev_err (tac_dev->dev,"Failed to set CS41 sample rate: %d" , ret); +return ret; + } + }else { + ret =regmap_write (tac_dev->regmap, +SDW_SDCA_CTL (function_id,TAC_SDCA_ENT_CS36 , +TAC_SDCA_CTL_CS_SAMP_RATE_IDX ,0 ), + sample_rate_idx); +if (ret) { +dev_err (tac_dev->dev,"Failed to set CS36 sample rate: %d" , ret); +return ret; + } + } +break ; +case TAC_FUNCTION_ID_SA : +/* SmartAmp: no additional sample rate configuration needed */ +break ; + } + +mutex_lock (&tac_dev->pde_lock); + retry =3 ; +/* make sure that power transition write is successful, before checking atual ps */ +do { + ret =regmap_write (tac_dev->regmap,SDW_SDCA_CTL (function_id, pde_entity, +TAC_SDCA_REQUESTED_PS ,0 ), +0x00 ); +if (!ret) +break ; + +dev_err (tac_dev->dev,"requested PS write err=%d, retry=%d" , ret, retry); +usleep_range (1000 ,1200 ); + }while (retry--); + + retry =3 ; +do { + ret =regmap_read (tac_dev->regmap,SDW_SDCA_CTL (function_id, pde_entity, +TAC_SDCA_ACTUAL_PS ,0 ), + &actual_ps); +if (ret) { +dev_err (tac_dev->dev,"read actual PS err=%d: retry=%d" , ret, retry); +continue ; + } + +if (!actual_ps) +break ; + +if (retry) +usleep_range (1000 ,1200 ); + }while (retry--); + +if (actual_ps !=0x00 ) +dev_warn (tac_dev->dev,"err PDE transition to D0: PS=0x%x\n" , + actual_ps); +mutex_unlock (&tac_dev->pde_lock); + +return 0 ; +} + +static s32 tac_sdw_pcm_hw_free (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +s32 ret; +struct snd_soc_component *component = dai->component; +struct tac5xx2_prv *tac_dev = +snd_soc_component_get_drvdata (component); +struct sdw_stream_runtime *sdw_stream = +snd_soc_dai_get_dma_data (dai, substream); +int pde_entity, function_id; + +sdw_stream_remove_slave (tac_dev->sdw_peripheral, sdw_stream); + +switch (dai->id) { +case TAC5XX2_DMIC : + pde_entity =TAC_SDCA_ENT_PDE11 ; + function_id =TAC_FUNCTION_ID_SM ; +break ; +case TAC5XX2_UAJ : + function_id =TAC_FUNCTION_ID_UAJ ; + pde_entity = substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ? +TAC_SDCA_ENT_PDE47 :TAC_SDCA_ENT_PDE34 ;
sound/soc/codecs/tac5xx2-sdw.c line 1006
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+break ; +default : + function_id =TAC_FUNCTION_ID_SA ; + pde_entity =TAC_SDCA_ENT_PDE23 ; +break ; + } +mutex_lock (&tac_dev->pde_lock); + ret =regmap_write (tac_dev->regmap, +SDW_SDCA_CTL (function_id, pde_entity,0x01 ,0 ), +0x03 );
you need to check the ACTUAL_PS as well, same as for PS3->PS0, otherwise you risk unlocking the PDE too early while it's transitioning state.
Quoted 8 lines
sound/soc/codecs/tac5xx2-sdw.c new file +7
-0+mutex_unlock (&tac_dev->pde_lock); + +return ret; +} +#if IS_ENABLED (CONFIG_PCI ) +static struct pci_dev *tac_get_pci_dev (struct sdw_slave *peripheral) +{
sound/soc/codecs/tac5xx2-sdw.c line 1789
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+struct device *dev = &peripheral->dev; + +for (; dev; dev = dev->parent) { +if (dev->bus == &pci_bus_type) +return to_pci_dev (dev); + } + + return NULL; +} +#endif
CONFIG_PCI makes no sense to me in a soundwire context. The parent is not a PCI bus, is it?
Quoted 5 lines
sound/soc/codecs/tac5xx2-sdw.c new file +5
-0+ +static void tac_generate_fw_name (struct sdw_slave *slave,char *name,size_t size) +{ +struct sdw_bus *bus = slave->bus; +u16 part_id = slave->id.part_id;
sound/soc/codecs/tac5xx2-sdw.c line 1804
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+u8 unique_id = slave->id.unique_id; +#if IS_ENABLED (CONFIG_PCI ) +struct pci_dev *pci =tac_get_pci_dev (slave); + +if (pci) { +scnprintf (name, size,"%04X-%1X-%1X.bin" , + pci->subsystem_device, bus->link_id, unique_id); +return ; + } +#endif
same here
Quoted 5 lines
sound/soc/codecs/tac5xx2-sdw.c new file +5
-0+/* Default firmware name based on part ID */ +scnprintf (name, size,"%s%04x-%1X-%1X.bin" , + part_id ==0x2883 ?"tas" :"tac" , + part_id, bus->link_id, unique_id); +}