ASoC: SDCA: Add PDE verification reusable helper
Subsystems (4)
PATCH v11 1/4 ASoC: SDCA: Add PDE verification reusable helper
Implement sdca_asoc_pde_ensure_ps() helper function to poll for PDE
power state transitions. Per SDCA specification, after writing REQUESTED_PS, drivers must poll ACTUAL_PS until the target power state is reached.
Changes include:
- Add sdca_asoc_pde_ensure_ps() to handle ACTUAL_PS polling with support for device-specific delay tables or default intervals
- Export function via sdca_asoc.h for use by SDCA-compliant drivers
- Refactor entity_pde_event() in sdca_asoc.c to use the helper
---
v11:
- revert v10 changes
- API is renamed from sdca_asoc_pde_ensure_ps to
sdca_asoc_pde_poll_actual_ps
v10:
- write REQUESTED_PS before checking the target state.
- change the API name sdca_asoc_pde_ensure_ps to sdca_asoc_set_pde_poll_sync
v9:
- newly added interface
--- include/sound/sdca_asoc.h | 6 +++ sound/soc/sdca/sdca_asoc.c | 105 ++++++++++++++++++++++++++----------- 2 files changed, 79 insertions(+), 32 deletions(-)
include/sound/sdca_asoc.h +6 -0
@@ -13,6 +13,7 @@struct device ;struct regmap ;struct sdca_function_data ; +struct sdca_pde_delay ;struct snd_ctl_elem_value ;struct snd_kcontrol ;struct snd_kcontrol_new ;
@@ -99,4 +100,9 @@ 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); +int sdca_asoc_pde_poll_actual_ps (struct device *dev,struct regmap *regmap, +int function_id,int entity_id, +int from_ps,int to_ps, +const struct sdca_pde_delay *pde_delays, +int num_delays);#endif // __SDCA_ASOC_H__
sound/soc/sdca/sdca_asoc.c +73 -32
122 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v11 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.
---
v11:
- refactor code for resume to wait for the initialisation to complete and then proceed.
- replace the sdca_asoc_set_pde_pool_sync with sdca_asoc_pde_poll_actual_ps
v10:
- use sdca helper sdca_asoc_set_pde_poll_sync for
changing the power states.
- register .set_jack callback only for if uaj is
available.
v9:
- Update tac5xx2-sdw.c hw_params() and hw_free() to use new SDCA helper sdca_asoc_pde_ensure_ps
- Remove redundant PPU11 initialization as it is there as part of the initialisation table.
- remove unnecessary default value writes for latch clear as the register.
- Improve jack detection and PDE power state transition comments
v8:
- disable interrupts in .set_jack if jack is set to NULL
- hold uaj_lock in .set_jack
- remove unwanted interrupt enable in initialisation
v7:
- refactor remove the cx11, cs18 and cs11 they are not required to be configured for mic
- fix error handling and interrupt cleanup in .set_jack
- fix typo in Kconfig
v6:
- move firmware caching trigger from soundwire bus callback to soundwire probe and make it asynchronous
- validate the firmware fully before starting firmware.
- drop mixer control for cx11 configuration
- check the actual power state in .hw_free after requesting power state transition to power off
- use dev_is_pci() and remove CONFIG_PCI
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 | 2018 ++++++++++++++++++++++++++++++++ sound/soc/codecs/tac5xx2.h | 259 ++++ 4 files changed, 2290 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, + TAC5682 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 +2018 -0
2,018 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 v11 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver
Quoted 7 lines · Niranjan H Y
Add codec driver for tac5xx2 family of devices.
sound/soc/codecs/tac5xx2-sdw.c new file +5
-0+switch (dai->id) { +case TAC5XX2_DMIC : + pde_entity =TAC_SDCA_ENT_PDE11 ; + function_id =TAC_FUNCTION_ID_SM ; +break ;
sound/soc/codecs/tac5xx2-sdw.c line 839
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+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 ; +break ; +default : + function_id =TAC_FUNCTION_ID_SA ; + pde_entity =TAC_SDCA_ENT_PDE23 ; +break ; + }
Shouldn't the default case be to print a warning or something and have an explicit case for what's there now? It seems weird that we just silently handle one ID by mapping any old number that gets passed in to it.
sound/soc/codecs/tac5xx2-sdw.c line 995
Quoted 9 lines
sound/soc/codecs/tac5xx2-sdw.c new file +8
-0+static int tac5xx2_set_jack (struct snd_soc_component *component, +struct snd_soc_jack *hs_jack,void *data) +{ + tac_dev->hs_jack = hs_jack; +if (!tac_dev->hw_init) { +dev_err (tac_dev->dev,"jack init failed, hw not initialized" ); +return 0 ; + }
I'm not seeing anything that does the jack setup when the hw_init happens?
sound/soc/codecs/tac5xx2-sdw.c line 1792
Quoted 13 lines
sound/soc/codecs/tac5xx2-sdw.c new file +12
-0+static int tac_update_status (struct sdw_slave *slave, +enum sdw_slave_status status) +{ +if (!tac_dev->first_hw_init) { +pm_runtime_set_autosuspend_delay (tac_dev->dev,3000 ); +pm_runtime_use_autosuspend (tac_dev->dev); +pm_runtime_mark_last_busy (tac_dev->dev); +pm_runtime_set_active (tac_dev->dev); +pm_runtime_enable (tac_dev->dev); + tac_dev->first_hw_init = true; + first = true; + }
Does anything ever actually undo this pm_runtime_enable()?
Pierre-Louis Bossart
reviewerRe: [PATCH v11 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver
In reply to Niranjan H Ysound/soc/codecs/tac5xx2-sdw.c line 138
Quoted 13 lines
sound/soc/codecs/tac5xx2-sdw.c new file +12
-0+struct tac5xx2_prv { +struct snd_soc_component *component; +struct sdw_slave *sdw_peripheral; +struct sdca_function_data *sa_func_data; +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; +/* serialize potential concurrent uaj detection in .hw_params +* during playback session and .interrupt_callback. +*/ +struct mutex uaj_lock;
is this uaj_lock really needed, if you look below at hw_params there's nothing that looks even remotely tied to jack detection...
Quoted 143 lines
(quoted diff) +142
-0+ struct regmap *regmap; + struct device *dev; + bool hw_init; + bool first_hw_init; + u32 part_id; + struct snd_soc_jack *hs_jack; + int jack_type; + /* Custom fw binary. UMP File Download is not used. */ + unsigned int fw_file_cnt; + struct tac_fw_file *fw_files; + struct completion fw_caching_complete; + bool fw_dl_success; + u8 fw_binaryname[64]; +}; +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; + int ret; + int function_id; + int pde_entity; + int port_num; + u8 sample_rate_idx = 0; + + 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; + 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; + } + + 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_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; + } + + 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; + } + + ret = regmap_write(tac_dev->regmap, SDW_SDCA_CTL(function_id, pde_entity, + TAC_SDCA_REQUESTED_PS, 0), 0); + if (ret) {
Review
Quoted 10 lines
(quoted diff) +10
-0+ dev_err(tac_dev->dev, "failed to set PS to 0: %d\n", ret); + return ret; + } + + ret = sdca_asoc_pde_poll_actual_ps(tac_dev->dev, tac_dev->regmap, function_id, pde_entity, + SDCA_PDE_PS3, SDCA_PDE_PS0, NULL, 0); + if (ret) + dev_err(tac_dev->dev, + "failed to transition to PS0, err= %d\n", ret); + return ret;
so as I said above there's nothing here that might conflict with the interrupt callback? What am I missing?
sound/soc/codecs/tac5xx2-sdw.c line 815
Quoted 6 lines
sound/soc/codecs/tac5xx2-sdw.c new file +6
-0+} + +static s32 tac_sdw_pcm_hw_free (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +s32 ret;
style nit-pick: reverse xmas-tree
Quoted 33 lines
sound/soc/codecs/tac5xx2-sdw.c new file +33
-0+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 ; +break ; +default : + function_id =TAC_FUNCTION_ID_SA ; + pde_entity =TAC_SDCA_ENT_PDE23 ; +break ; + } + + ret =regmap_write (tac_dev->regmap,SDW_SDCA_CTL (function_id, pde_entity, +TAC_SDCA_REQUESTED_PS ,0 ), +SDCA_PDE_PS3 ); +if (ret) +return ret; + + ret = sdca_asoc_pde_poll_actual_ps(tac_dev->dev, tac_dev->regmap, function_id, + pde_entity, SDCA_PDE_PS0, SDCA_PDE_PS3,
sound/soc/codecs/tac5xx2-sdw.c line 858
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+ NULL, 0); + +return ret; +} + +static const struct snd_soc_dai_ops tac_dai_ops = { + .hw_params = tac_sdw_hw_params, + .hw_free = tac_sdw_pcm_hw_free, + .set_stream = tac_set_sdw_stream, + .shutdown = tac_sdw_shutdown,
so set_jack is now dynamically added...
sound/soc/codecs/tac5xx2-sdw.c line 940
Quoted 9 lines
sound/soc/codecs/tac5xx2-sdw.c new file +8
-0+}; + +static int tac5xx2_sdca_headset_detect (struct tac5xx2_prv *tac_dev) +{ +int val, ret; + +if (!tac_has_uaj_support (tac_dev)) +return 0 ;
... but here the test for uaj_support is still there? Is this needed?
Quoted 45 lines
sound/soc/codecs/tac5xx2-sdw.c new file +45
-0+ + ret =regmap_read (tac_dev->regmap, +SDW_SDCA_CTL (TAC_FUNCTION_ID_UAJ ,TAC_SDCA_ENT_GE35 , +TAC_SDCA_CTL_DET_MODE ,0 ), &val); +if (ret) { +dev_err (tac_dev->dev,"Failed to read the detect mode" ); +return ret; + } + +switch (val) { +case 4 : + tac_dev->jack_type =SND_JACK_MICROPHONE ; +break ; +case 5 : + tac_dev->jack_type =SND_JACK_HEADPHONE ; +break ; +case 6 : + tac_dev->jack_type =SND_JACK_HEADSET ; +break ; +case 0 : +default : + tac_dev->jack_type =0 ; +break ; + } + + ret =regmap_write (tac_dev->regmap, +SDW_SDCA_CTL (TAC_FUNCTION_ID_UAJ ,TAC_SDCA_ENT_GE35 , +TAC_SDCA_CTL_SEL_MODE ,0 ), val); +if (ret) +dev_err (tac_dev->dev,"Failed to update the jack type to device" ); + +return 0 ; +} + +static int tac5xx2_set_jack (struct snd_soc_component *component, +struct snd_soc_jack *hs_jack,void *data) +{ +struct tac5xx2_prv *tac_dev =snd_soc_component_get_drvdata (component); +int ret; + +guard (mutex)(&tac_dev->uaj_lock); +if (!hs_jack) { +if (tac_dev->hs_jack) { + tac_dev->hs_jack =NULL ; + ret =0 ;
sound/soc/codecs/tac5xx2-sdw.c line 995
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+ goto disable_interrupts; + } +return 0 ; + } + + tac_dev->hs_jack = hs_jack; +if (!tac_dev->hw_init) { +dev_err (tac_dev->dev,"jack init failed, hw not initialized" ); +return 0 ; + }
should this test go up to the start of the function?
And isn't there a case where .set_jack can be invoked before the device is fully initialized?
I have a vague memory this was the case with other codecs, please double-check.
Quoted 27 lines
sound/soc/codecs/tac5xx2-sdw.c new file +27
-0+ + ret =regmap_write (tac_dev->regmap,SDW_SCP_SDCA_INTMASK2 , +SDW_SCP_SDCA_INTMASK_SDCA_11 ); +if (ret) { +dev_warn (tac_dev->dev, +"Failed to register jack detection interrupt" ); + goto disable_interrupts; + } + + ret =regmap_write (tac_dev->regmap,SDW_SCP_SDCA_INTMASK3 , +SDW_SCP_SDCA_INTMASK_SDCA_16 ); +if (ret) { +dev_warn (tac_dev->dev, +"Failed to register for button detect interrupt" ); + goto disable_interrupts; + } + +return 0 ; + +disable_interrupts: +/* ignore errors while disabling interrupts */ +regmap_write (tac_dev->regmap,SDW_SCP_SDCA_INTMASK2 ,0 ); +regmap_write (tac_dev->regmap,SDW_SCP_SDCA_INTMASK3 ,0 ); + +return ret; +} +
sound/soc/codecs/tac5xx2-sdw.c line 1032
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+static int tac_interrupt_callback (struct sdw_slave *slave, +struct sdw_slave_intr_status *status) +{ +struct tac5xx2_prv *tac_dev =dev_get_drvdata (&slave->dev); +struct device *dev = &slave->dev; +int ret =0 ; +int btn_type =0 ; +unsigned int sdca_int2, sdca_int3, jack_report_mask =0 ; + +guard (mutex)(&tac_dev->uaj_lock);
again what does this uaj_lock protect?
Quoted 226 lines
sound/soc/codecs/tac5xx2-sdw.c new file +225
-0+if (status->control_port) { +if (status->control_port &SDW_SCP_INT1_PARITY ) +dev_warn (dev,"SCP: Parity error interrupt" ); +if (status->control_port &SDW_SCP_INT1_BUS_CLASH ) +dev_warn (dev,"SCP: Bus clash interrupt" ); + } + + ret =regmap_read (tac_dev->regmap,SDW_SCP_SDCA_INT2 , &sdca_int2); +if (ret) { +dev_err (dev,"Failed to read UAJ Interrupt, reg:%#x err=%d\n" , +SDW_SCP_SDCA_INT2 , ret); +return ret; + } + + ret =regmap_read (tac_dev->regmap,SDW_SCP_SDCA_INT3 , &sdca_int3); +if (ret) { +dev_err (dev,"Failed to read HID interrupt reg=%#x: err=%d" , +SDW_SCP_SDCA_INT3 , ret); +return ret; + } + +dev_dbg (dev,"SDCA_INT2: 0x%02x, SDCA_INT3: 0x%02x\n" , + sdca_int2, sdca_int3); + +if (sdca_int2 &SDW_SCP_SDCA_INT_SDCA_11 ) { + ret =tac5xx2_sdca_headset_detect (tac_dev); +if (ret <0 ) + goto clear; + jack_report_mask |=SND_JACK_HEADSET ; + } + +if (sdca_int3 &SDW_SCP_SDCA_INT_SDCA_16 ) { + btn_type =tac5xx2_sdca_button_detect (tac_dev); +if (btn_type <0 ) + btn_type =0 ; + jack_report_mask |=SND_JACK_BTN_0 |SND_JACK_BTN_1 | +SND_JACK_BTN_2 |SND_JACK_BTN_3 |SND_JACK_BTN_4 ; + } + +if (tac_dev->jack_type ==0 ) + btn_type =0 ; + +dev_dbg (tac_dev->dev,"in %s, jack_type=%d\n" , __func__, tac_dev->jack_type); +dev_dbg (tac_dev->dev,"in %s, btn_type=0x%x\n" , __func__, btn_type); + +if (!tac_dev->hs_jack) + goto clear; + +snd_soc_jack_report (tac_dev->hs_jack, tac_dev->jack_type | btn_type, + jack_report_mask); + +clear: +if (sdca_int2) { + ret =regmap_write (tac_dev->regmap,SDW_SCP_SDCA_INT2 , sdca_int2); +if (ret) +dev_dbg (tac_dev->dev,"Failed to clear jack interrupt\n" ); + } + +if (sdca_int3) { + ret =regmap_write (tac_dev->regmap,SDW_SCP_SDCA_INT3 , sdca_int3); +if (ret) +dev_dbg (tac_dev->dev,"failed to clear hid interrupt\n" ); + } + +return 0 ; +} +static s32 tac_component_probe (struct snd_soc_component *component) +{ +struct tac5xx2_prv *tac_dev = +snd_soc_component_get_drvdata (component); +struct device *dev = tac_dev->dev; +struct sdw_slave *slave = tac_dev->sdw_peripheral; +unsigned long time; +int ret; + +/* Wait for SoundWire hw initialization to complete */ + time =wait_for_completion_timeout (&slave->initialization_complete, +msecs_to_jiffies (TAC5XX2_PROBE_TIMEOUT_MS )); +if (!time) { +dev_warn (dev,"%s: hw initialization timeout\n" , __func__); +return -ETIMEDOUT ; + } + +if (!tac_has_uaj_support (tac_dev)) + goto done_comp_probe; + + ret =snd_soc_dapm_new_controls (snd_soc_component_to_dapm (component), + tac_uaj_widgets, +ARRAY_SIZE (tac_uaj_widgets)); +if (ret) { +dev_err (component->dev,"Failed to add UAJ widgets: %d\n" , ret); +return ret; + } + + ret =snd_soc_dapm_add_routes (snd_soc_component_to_dapm (component), + tac_uaj_routes,ARRAY_SIZE (tac_uaj_routes)); +if (ret) { +dev_err (component->dev,"Failed to add UAJ routes: %d\n" , ret); +return ret; + } + + ret =snd_soc_add_component_controls (component, tac_uaj_controls, +ARRAY_SIZE (tac_uaj_controls)); +if (ret) { +dev_err (dev,"Failed to add UAJ controls: %d\n" , ret); +return ret; + } + +done_comp_probe: + tac_dev->component = component; +return 0 ; +} + +static void tac_component_remove (struct snd_soc_component *codec) +{ +struct tac5xx2_prv *tac_dev =snd_soc_component_get_drvdata (codec); + + tac_dev->component =NULL ; +} + +static const struct snd_soc_component_driver soc_codec_driver_tacdevice = { + .probe = tac_component_probe, + .remove = tac_component_remove, + .controls = tac5xx2_snd_controls, + .num_controls =ARRAY_SIZE (tac5xx2_snd_controls), + .dapm_widgets = tac5xx2_common_widgets, + .num_dapm_widgets =ARRAY_SIZE (tac5xx2_common_widgets), + .dapm_routes = tac5xx2_common_routes, + .num_dapm_routes =ARRAY_SIZE (tac5xx2_common_routes), + .idle_bias_on =0 , + .endianness =1 , +}; + +static s32 tac_init (struct tac5xx2_prv *tac_dev) +{ +s32 ret; +struct snd_soc_dai_driver *dai_drv; +struct snd_soc_component_driver *component_driver; +int num_dais; + +dev_set_drvdata (tac_dev->dev, tac_dev); + +switch (tac_dev->part_id) { +case 0x5572 : + dai_drv = tac5572_dai_driver; + num_dais =ARRAY_SIZE (tac5572_dai_driver); +break ; +case 0x5672 : + dai_drv = tac5672_dai_driver; + num_dais =ARRAY_SIZE (tac5672_dai_driver); +break ; +case 0x5682 : + dai_drv = tac5682_dai_driver; + num_dais =ARRAY_SIZE (tac5682_dai_driver); +break ; +case 0x2883 : + dai_drv = tas2883_dai_driver; + num_dais =ARRAY_SIZE (tas2883_dai_driver); +break ; +default : +dev_err (tac_dev->dev,"Unsupported device: 0x%x\n" , + tac_dev->part_id); +return -EINVAL ; + } + + component_driver =devm_kzalloc (tac_dev->dev,sizeof (*component_driver), +GFP_KERNEL ); +if (!component_driver) +return -ENOMEM ; + +memcpy (component_driver, &soc_codec_driver_tacdevice,sizeof (*component_driver)); +if (tac_has_uaj_support (tac_dev)) + component_driver->set_jack = tac5xx2_set_jack; + + ret =devm_snd_soc_register_component (tac_dev->dev, component_driver, + dai_drv, num_dais); +if (ret) { +dev_err (tac_dev->dev,"%s: codec register error:%d.\n" , + __func__, ret); +return ret; + } + +return 0 ; +} + +static s32 tac5xx2_sdca_dev_suspend (struct device *dev) +{ +struct tac5xx2_prv *tac_dev =dev_get_drvdata (dev); + +if (!tac_dev->hw_init) +return 0 ; + +regcache_cache_only (tac_dev->regmap, true); +return 0 ; +} + +static s32 tac5xx2_sdca_dev_system_suspend (struct device *dev) +{ +return tac5xx2_sdca_dev_suspend (dev); +} + +static s32 tac5xx2_sdca_dev_resume (struct device *dev) +{ +struct sdw_slave *slave =dev_to_sdw_dev (dev); +struct tac5xx2_prv *tac_dev =dev_get_drvdata (dev); +unsigned long t; +int ret; +bool had_unattached = false; + +if (!tac_dev->first_hw_init) { +dev_dbg (dev,"Device not initialized yet, skipping resume sync\n" ); +return 0 ; + } + +if (!slave->unattach_request) + goto regmap_sync; + + had_unattached = true; + t =wait_for_completion_timeout (&slave->initialization_complete, +msecs_to_jiffies (TAC5XX2_PROBE_TIMEOUT_MS )); +if (!t) { +dev_err (&slave->dev,"resume: initialization timed out\n" ); +sdw_show_ping_status (slave->bus, true); +return -ETIMEDOUT ; + }
sound/soc/codecs/tac5xx2-sdw.c line 1450
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+ slave->unattach_request =0 ; +dev_dbg (tac_dev->dev,"%s wait for resume complete, starting writes\n" , __func__); + +/* Detect and set jack type for UAJ path before playback. +* This is required as jack detection does not trigger interrupt +* when device is in runtime_pm suspend with bus in clock stop mode. +*/ +mutex_lock (&tac_dev->uaj_lock); +tac5xx2_sdca_headset_detect (tac_dev); +mutex_unlock (&tac_dev->uaj_lock);
again what does this mutex protect? there is no interrupt so there cannot be any conflict/race with the interrupt callback and even less with hw_params.
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+ +regmap_sync: +regcache_cache_only (tac_dev->regmap, false); +if (!had_unattached) { +regcache_mark_dirty (tac_dev->regmap); + ret =regcache_sync (tac_dev->regmap); +if (ret <0 ) +dev_warn (dev,"Failed to sync regcache: %d\n" , ret); + } +
sound/soc/codecs/tac5xx2-sdw.c
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +9
-0+return 0 ; +} +static struct pci_dev *tac_get_pci_dev (struct sdw_slave *peripheral) +{ +struct device *dev = &peripheral->dev; + +for (; dev; dev = dev->parent) { +if (dev_is_pci (dev)) +return to_pci_dev (dev);
I find this surprising, what is the purpose of going up in the device hierarchy to find a PCI device? Why would this driver care?
Quoted 20 lines
sound/soc/codecs/tac5xx2-sdw.c new file +20
-0+ } + +return NULL ; +} +static int tac_update_status (struct sdw_slave *slave, +enum sdw_slave_status status) +{ +int ret; +bool first = false; +struct tac5xx2_prv *tac_dev =dev_get_drvdata (&slave->dev); +struct device *dev = &slave->dev; + + tac_dev->status = status; +if (status ==SDW_SLAVE_UNATTACHED ) { + tac_dev->hw_init = false; + tac_dev->fw_dl_success = false; + } + +if (tac_dev->hw_init || tac_dev->status !=SDW_SLAVE_ATTACHED ) { + dev_dbg(dev, "%s: early return, hw_init=%d, status=%d",
sound/soc/codecs/tac5xx2-sdw.c line 1789
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+ __func__, tac_dev->hw_init, tac_dev->status); +return 0 ; + } + +if (!tac_dev->first_hw_init) { +pm_runtime_set_autosuspend_delay (tac_dev->dev,3000 ); +pm_runtime_use_autosuspend (tac_dev->dev); +pm_runtime_mark_last_busy (tac_dev->dev); +pm_runtime_set_active (tac_dev->dev); +pm_runtime_enable (tac_dev->dev);
I suggest you look at other codec drivers, all the pm_runtime configuration is done in the .probe callback and only set_active done upon a change in status.
Quoted 23 lines
sound/soc/codecs/tac5xx2-sdw.c new file +23
-0+ tac_dev->first_hw_init = true; + first = true; + } + +pm_runtime_get_noresume (tac_dev->dev); + +regcache_mark_dirty (tac_dev->regmap); +regcache_cache_only (tac_dev->regmap, false); + ret =tac_io_init (&slave->dev, slave, first); +if (ret) { +dev_err (dev,"Device initialization failed: %d\n" , ret); + goto err_out; + } + + ret =regcache_sync (tac_dev->regmap); +if (ret) +dev_warn (dev,"Failed to sync regcache after init: %d\n" , ret); + +err_out: +pm_runtime_mark_last_busy (tac_dev->dev); +pm_runtime_put_autosuspend (tac_dev->dev); + +return ret;
sound/soc/codecs/tac5xx2-sdw.c line 1822
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+} + +static int tac5xx2_sdw_clk_stop (struct sdw_slave *peripheral, +enum sdw_clk_stop_mode mode, +enum sdw_clk_stop_type type) +{ +struct tac5xx2_prv *tac_dev =dev_get_drvdata (&peripheral->dev); + +dev_dbg (tac_dev->dev,"%s: mode:%d type:%d" , __func__, mode, type); +return 0 ;
this looks rather useless, no?
Quoted 118 lines
sound/soc/codecs/tac5xx2-sdw.c new file +117
-0+} + +static int tac5xx2_sdw_read_prop (struct sdw_slave *peripheral) +{ +struct device *dev = &peripheral->dev; +int ret; + + ret =sdw_slave_read_prop (peripheral); +if (ret) { +dev_err (dev,"sdw_slave_read_prop failed: %d" , ret); +return ret; + } + +return 0 ; +} +static s32 tac_sdw_probe (struct sdw_slave *peripheral, +const struct sdw_device_id *id) +{ +struct regmap *regmap; +struct device *dev = &peripheral->dev; +struct tac5xx2_prv *tac_dev; +struct sdca_function_data *function_data =NULL ; +int ret, i; + + tac_dev =devm_kzalloc (dev,sizeof (*tac_dev),GFP_KERNEL ); +if (!tac_dev) +return dev_err_probe (dev, -ENOMEM , +"Failed devm_kzalloc" ); + +if (peripheral->sdca_data.num_functions >0 ) { +dev_dbg (dev,"SDCA functions found: %d" , + peripheral->sdca_data.num_functions); + +for (i =0 ; i < peripheral->sdca_data.num_functions; i++) { +struct sdca_function_data **func_ptr; +const char *func_name; + +switch (peripheral->sdca_data.function[i].type) { +case SDCA_FUNCTION_TYPE_SMART_AMP : + func_ptr = &tac_dev->sa_func_data; + func_name ="smartamp" ; +break ; +case SDCA_FUNCTION_TYPE_SMART_MIC : + func_ptr = &tac_dev->sm_func_data; + func_name ="smartmic" ; +break ; +case SDCA_FUNCTION_TYPE_UAJ : + func_ptr = &tac_dev->uaj_func_data; + func_name ="uaj" ; +break ; +case SDCA_FUNCTION_TYPE_HID : + func_ptr = &tac_dev->hid_func_data; + func_name ="hid" ; +break ; +default : +continue ; + } + + function_data =devm_kzalloc (dev,sizeof (*function_data), +GFP_KERNEL ); +if (!function_data) +return dev_err_probe (dev, -ENOMEM , +"failed to allocate %s function data" , + func_name); + + ret =sdca_parse_function (dev, peripheral, + &peripheral->sdca_data.function[i], + function_data); +if (!ret) + *func_ptr = function_data; +else +devm_kfree (dev, function_data); + } + } + +dev_dbg (dev,"SDCA functions enabled: SA=%s SM=%s UAJ=%s HID=%s" , + tac_dev->sa_func_data ?"yes" :"no" , + tac_dev->sm_func_data ?"yes" :"no" , + tac_dev->uaj_func_data ?"yes" :"no" , + tac_dev->hid_func_data ?"yes" :"no" ); + + tac_dev->dev = dev; + tac_dev->sdw_peripheral = peripheral; + tac_dev->hw_init = false; + tac_dev->first_hw_init = false; +mutex_init (&tac_dev->uaj_lock); + tac_dev->part_id = id->part_id; +dev_set_drvdata (dev, tac_dev); + + regmap =devm_regmap_init_sdw_mbq_cfg (&peripheral->dev, peripheral, + &tac_regmap, &tac_mbq_cfg); +if (IS_ERR (regmap)) +return dev_err_probe (dev,PTR_ERR (regmap), +"Failed devm_regmap_init_sdw\n" ); + +regcache_cache_only (regmap, true); + tac_dev->regmap = regmap; + tac_dev->jack_type =0 ; +init_completion (&tac_dev->fw_caching_complete); + +if (tac_has_dsp_algo (tac_dev)) { +tac_generate_fw_name (peripheral, tac_dev->fw_binaryname, +sizeof (tac_dev->fw_binaryname)); + + ret =tac_load_and_cache_firmware_async (tac_dev); +if (ret) { +complete_all (&tac_dev->fw_caching_complete); +dev_dbg (dev,"failed to load fw: %d, use rom mode\n" , ret); + } + }else { +complete_all (&tac_dev->fw_caching_complete); + } + + ret =tac_init (tac_dev); +if (ret) +return dev_err_probe (dev, ret, +"failed to initialize tac device\n" );
sound/soc/codecs/tac5xx2-sdw.c line 1991
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+ +return 0 ; +} + +static void tac_sdw_remove (struct sdw_slave *peripheral) +{ +struct tac5xx2_prv *tac_dev =dev_get_drvdata (&peripheral->dev); + +mutex_destroy (&tac_dev->uaj_lock); +dev_set_drvdata (&peripheral->dev,NULL );
if you move all the runtime_pm stuff to the probe above, this remove() would also need to be modified to add a pm_runtime_disable()
Quoted 1 line
+}
Re: [PATCH v11 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver
Quoted 18 lines · Pierre-Louis Bossart
Subject: Re: [PATCH v11 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver
sound/soc/codecs/tac5xx2-sdw.c line 138
Quoted 12 lines
sound/soc/codecs/tac5xx2-sdw.c new file +12
-0+struct tac5xx2_prv { +struct snd_soc_component *component; +struct sdw_slave *sdw_peripheral; +struct sdca_function_data *sa_func_data; +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; +/* serialize potential concurrent uaj detection in .hw_params +* during playback session and .interrupt_callback. +*/ +struct mutex uaj_lock;is this
uaj_lockreally needed, if you look below athw_paramsthere's nothing that looks even remotely tied to jack detection...
I think comment needs update to remove the hw_params related description here. ...
Quoted 11 lines
sound/soc/codecs/tac5xx2-sdw.c line 737
Quoted 7 lines
sound/soc/codecs/tac5xx2-sdw.c new file +7
-0+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 = + return ret;so as I said above there's nothing here that might conflict with the interrupt callback?
What am I missing?
... uaj_lock is still needed to handle potential race condition in case .set_jack is called with jack as NULL (potentially to disable the jack functionality ) when the interrupt is being handled.
This was suggested in earlier review comment and it made sense to me as well
Quoted 11 lines
sound/soc/codecs/tac5xx2-sdw.c line 858
Quoted 5 lines
sound/soc/codecs/tac5xx2-sdw.c new file +5
-0+static const struct snd_soc_dai_ops tac_dai_ops = { + .hw_params = tac_sdw_hw_params, + .hw_free = tac_sdw_pcm_hw_free, + .set_stream = tac_set_sdw_stream, + .shutdown = tac_sdw_shutdown,so
set_jackis now dynamically added...Quoted 2 lines
(quoted diff) +2
-0+}; +
Quoted 8 lines
sound/soc/codecs/tac5xx2-sdw.c line 940
Quoted 6 lines
sound/soc/codecs/tac5xx2-sdw.c new file +6
-0+static int tac5xx2_sdca_headset_detect (struct tac5xx2_prv *tac_dev) +{ +int val, ret; + +if (!tac_has_uaj_support (tac_dev)) +return 0 ;... but here the test for
uaj_supportis still there? Is this needed?
I will drop this.
Quoted 27 lines
sound/soc/codecs/tac5xx2-sdw.c
Quoted 4 lines
sound/soc/codecs/tac5xx2-sdw.c new file +4
-0+static int tac5xx2_set_jack (struct snd_soc_component *component, +struct snd_soc_jack *hs_jack,void *data) +{ + struct tac5xx2_prv *tac_dev =
snd_soc_component_get_drvdata(component);Quoted 7 lines
sound/soc/codecs/tac5xx2-sdw.c new file +7
-0+int ret; + +guard (mutex)(&tac_dev->uaj_lock); +if (!hs_jack) { +if (tac_dev->hs_jack) { + tac_dev->hs_jack =NULL ; + ret =0 ;sound/soc/codecs/tac5xx2-sdw.c line 995
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c new file +10
-0+ goto disable_interrupts; + } +return 0 ; + } + + tac_dev->hs_jack = hs_jack; +if (!tac_dev->hw_init) { +dev_err (tac_dev->dev,"jack init failed, hw not initialized" ); +return 0 ; + }should this test go up to the start of the function?
And isn't there a case where .set_jack can be invoked before the device is fully initialized?
Quoted 2 lines
I have a vague memory this was the case with other codecs, please double- check.
I have already dropped this in v12 patch to remove the hw_init check and let regcache handle this.
Quoted 5 lines
Quoted 5 lines
sound/soc/codecs/tac5xx2-sdw.c new file +5
-0+ +static int tac_interrupt_callback (struct sdw_slave *slave, +struct sdw_slave_intr_status *status) +{ +struct tac5xx2_prv *tac_dev =dev_get_drvdata (&slave->dev);
Quoted 8 lines
sound/soc/codecs/tac5xx2-sdw.c line 1032
Quoted 6 lines
sound/soc/codecs/tac5xx2-sdw.c new file +6
-0+struct device *dev = &slave->dev; +int ret =0 ; +int btn_type =0 ; +unsigned int sdca_int2, sdca_int3, jack_report_mask =0 ; + +guard (mutex)(&tac_dev->uaj_lock);again what does this
uaj_lockprotect?
commented above.
Quoted 30 lines
sound/soc/codecs/tac5xx2-sdw.c
Quoted 11 lines
sound/soc/codecs/tac5xx2-sdw.c new file +11
-0+ +static s32 tac5xx2_sdca_dev_resume (struct device *dev) +{ +struct sdw_slave *slave =dev_to_sdw_dev (dev); +struct tac5xx2_prv *tac_dev =dev_get_drvdata (dev); +unsigned long t; +int ret; +bool had_unattached = false; + +if (!tac_dev->first_hw_init) { + dev_dbg(dev, "Device not initialized yet, skipping resumesync\n");
sound/soc/codecs/tac5xx2-sdw.c line 1443
Quoted 9 lines
sound/soc/codecs/tac5xx2-sdw.c new file +9
-0+return 0 ; + } + +if (!slave->unattach_request) + goto regmap_sync; + + had_unattached = true; + t = wait_for_completion_timeout(&slave->initialization_complete, +msecs_to_jiffies(TAC5XX2_PROBE_TIMEOUT_MS));sound/soc/codecs/tac5xx2-sdw.c
Quoted 7 lines
sound/soc/codecs/tac5xx2-sdw.c new file +7
-0+if (!t) { +dev_err (&slave->dev,"resume: initialization timed out\n" ); +sdw_show_ping_status (slave->bus, true); +return -ETIMEDOUT ; + } + slave->unattach_request =0 ; + dev_dbg(tac_dev->dev, "%s wait for resume complete, startingwrites\n",
__func__);
Quoted 11 lines
sound/soc/codecs/tac5xx2-sdw.c line 1450
Quoted 8 lines
sound/soc/codecs/tac5xx2-sdw.c new file +8
-0+ +/* Detect and set jack type for UAJ path before playback. +* This is required as jack detection does not trigger interrupt +* when device is in runtime_pm suspend with bus in clock stop mode. +*/ +mutex_lock (&tac_dev->uaj_lock); +tac5xx2_sdca_headset_detect (tac_dev); +mutex_unlock (&tac_dev->uaj_lock);again what does this mutex protect? there is no interrupt so there cannot be any conflict/race with the interrupt callback and even less with
hw_params.
commented above
Quoted 12 lines
sound/soc/codecs/tac5xx2-sdw.c line 1636
Quoted 8 lines
sound/soc/codecs/tac5xx2-sdw.c new file +7
-0+static struct pci_dev *tac_get_pci_dev (struct sdw_slave *peripheral) +{ +struct device *dev = &peripheral->dev; + +for (; dev; dev = dev->parent) { +if (dev_is_pci (dev)) +return to_pci_dev (dev);I find this surprising, what is the purpose of going up in the device hierarchy to find a PCI device?
Why would this driver care?
For Speaker protection modules running on the firmware based devices, we need to have different firmware for different projects as there are firmware differences. We need a way to uniquely identify firmware for each of these projects. Currently this is done through the "subsystem id" which is part of the pci device. So we find the pci bus and then identify the subsystem id.
I see similar changes in class driver as well sound/soc/sdca/sdca_fdl.c.
Quoted 21 lines
Quoted 21 lines
sound/soc/codecs/tac5xx2-sdw.c new file +21
-0+static int tac_update_status (struct sdw_slave *slave, +enum sdw_slave_status status) +{ +int ret; +bool first = false; +struct tac5xx2_prv *tac_dev =dev_get_drvdata (&slave->dev); +struct device *dev = &slave->dev; + + tac_dev->status = status; +if (status ==SDW_SLAVE_UNATTACHED ) { + tac_dev->hw_init = false; + tac_dev->fw_dl_success = false; + } + +if (tac_dev->hw_init || tac_dev->status !=SDW_SLAVE_ATTACHED ) { +dev_dbg (dev,"%s: early return, hw_init=%d, status=%d" , + __func__, tac_dev->hw_init, tac_dev->status); +return 0 ; + } + +if (!tac_dev->first_hw_init) {
Quoted 8 lines
sound/soc/codecs/tac5xx2-sdw.c line 1789
Quoted 5 lines
sound/soc/codecs/tac5xx2-sdw.c new file +5
-0+pm_runtime_set_autosuspend_delay (tac_dev->dev,3000 ); +pm_runtime_use_autosuspend (tac_dev->dev); +pm_runtime_mark_last_busy (tac_dev->dev); +pm_runtime_set_active (tac_dev->dev); +pm_runtime_enable (tac_dev->dev);I suggest you look at other codec drivers, all the
pm_runtimeconfiguration is done in the .probe callback and onlyset_activedone upon a change in status.
I thought I will keep it here so that all pm_runtime_* initializations are in one place.
Quoted 9 lines
sound/soc/codecs/tac5xx2-sdw.c
Quoted 8 lines
sound/soc/codecs/tac5xx2-sdw.c new file +8
-0+ +static int tac5xx2_sdw_clk_stop (struct sdw_slave *peripheral, +enum sdw_clk_stop_mode mode, +enum sdw_clk_stop_type type) +{ +struct tac5xx2_prv *tac_dev =dev_get_drvdata (&peripheral->dev); + + dev_dbg(tac_dev->dev, "%s: mode:%d type:%d", __func__, mode,type);
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;this looks rather useless, no?
Yes, currently only required in case of debugging.
Quoted 9 lines
sound/soc/codecs/tac5xx2-sdw.c line 1991
Quoted 6 lines
sound/soc/codecs/tac5xx2-sdw.c new file +6
-0+static void tac_sdw_remove (struct sdw_slave *peripheral) +{ +struct tac5xx2_prv *tac_dev =dev_get_drvdata (&peripheral->dev); + +mutex_destroy (&tac_dev->uaj_lock); +dev_set_drvdata (&peripheral->dev,NULL );if you move all the
runtime_pmstuff to the probe above, thisremove()would also need to be modified to add apm_runtime_disable()
Already taken care in v12.
Thanks
Regards
Niranjan
Pierre-Louis Bossart
reviewerRe: [PATCH v11 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver
Quoted 19 lines · Niranjan
Quoted 18 lines · Pierre-Louis Bossart
Subject: Re: [PATCH v11 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver
sound/soc/codecs/tac5xx2-sdw.c line 138
Quoted 12 lines
sound/soc/codecs/tac5xx2-sdw.c new file +12
-0+struct tac5xx2_prv { +struct snd_soc_component *component; +struct sdw_slave *sdw_peripheral; +struct sdca_function_data *sa_func_data; +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; +/* serialize potential concurrent uaj detection in .hw_params +* during playback session and .interrupt_callback. +*/ +struct mutex uaj_lock;is this
uaj_lockreally needed, if you look below athw_paramsthere's nothing that looks even remotely tied to jack detection...
Quoted 1 line
I think comment needs update to remove the
hw_paramsrelated description here. ...
ok, but still see below...
Quoted 12 lines
Quoted 11 lines
sound/soc/codecs/tac5xx2-sdw.c line 737
Quoted 7 lines
sound/soc/codecs/tac5xx2-sdw.c new file +7
-0+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 = + return ret;so as I said above there's nothing here that might conflict with the interrupt callback?
What am I missing?
Quoted 3 lines
...
uaj_lockis still needed to handle potential race condition in case .set_jack is called with jack as NULL (potentially to disable the jack functionality ) when the interrupt is being handled.
This was suggested in earlier review comment and it made sense to me as well
This isn't the first jack codec we've reviewed, and so far none of them have such a lock.
There is in some cases a lock to make sure the calibration is only done once, but that's different to your explanation. So either everyone was wrong or this is unnecessary. Please double-check.
And in addition this driver is missing the pm_resume_and_get() that's present in most implementations to avoid races between set_jack and resume.
see e.g. commit e02b99e "ASoC: codecs: rt700/rt711/rt711-sdca: resume bus/codec in .set_jack_detect"
Quoted 12 lines
Quoted 11 lines
sound/soc/codecs/tac5xx2-sdw.c line 1636
Quoted 7 lines
sound/soc/codecs/tac5xx2-sdw.c new file +7
-0+static struct pci_dev *tac_get_pci_dev (struct sdw_slave *peripheral) +{ +struct device *dev = &peripheral->dev; + +for (; dev; dev = dev->parent) { +if (dev_is_pci (dev)) +return to_pci_dev (dev);I find this surprising, what is the purpose of going up in the device hierarchy to find a PCI device?
Why would this driver care?
Quoted 7 lines
For Speaker protection modules running on the firmware based devices, we need to have different firmware for different projects as there are firmware differences. We need a way to uniquely identify firmware for each of these projects. Currently this is done through the "subsystem id" which is part of the pci device. So we find the pci bus and then identify the subsystem id.
I see similar changes in class driver as well
sound/soc/sdca/sdca_fdl.c.
ok, now I get it.
Quoted 30 lines
Quoted 21 lines
Quoted 21 lines
sound/soc/codecs/tac5xx2-sdw.c new file +21
-0+static int tac_update_status (struct sdw_slave *slave, +enum sdw_slave_status status) +{ +int ret; +bool first = false; +struct tac5xx2_prv *tac_dev =dev_get_drvdata (&slave->dev); +struct device *dev = &slave->dev; + + tac_dev->status = status; +if (status ==SDW_SLAVE_UNATTACHED ) { + tac_dev->hw_init = false; + tac_dev->fw_dl_success = false; + } + +if (tac_dev->hw_init || tac_dev->status !=SDW_SLAVE_ATTACHED ) { +dev_dbg (dev,"%s: early return, hw_init=%d, status=%d" , + __func__, tac_dev->hw_init, tac_dev->status); +return 0 ; + } + +if (!tac_dev->first_hw_init) {Quoted 8 lines
sound/soc/codecs/tac5xx2-sdw.c line 1789
Quoted 5 lines
sound/soc/codecs/tac5xx2-sdw.c new file +5
-0+pm_runtime_set_autosuspend_delay (tac_dev->dev,3000 ); +pm_runtime_use_autosuspend (tac_dev->dev); +pm_runtime_mark_last_busy (tac_dev->dev); +pm_runtime_set_active (tac_dev->dev); +pm_runtime_enable (tac_dev->dev);I suggest you look at other codec drivers, all the
pm_runtimeconfiguration is done in the .probe callback and onlyset_activedone upon a change in status.
Quoted 1 line
I thought I will keep it here so that all pm_runtime_* initializations are in one place.
well that's well intended but not so good.
You want to have a symmetric handling of pm_runtime_enable() and pm_runtime_disable() in .probe and .remove driver callbacks. With your implementation the pm_runtime_enable() is only done if/when the device attaches.
And then you do want to take a look at other drivers where there's this big fat comment..
/* set autosuspend parameters */ pm_runtime_set_autosuspend_delay(dev, 3000); pm_runtime_use_autosuspend(dev); /* make sure the device does not suspend immediately */ pm_runtime_mark_last_busy(dev); pm_runtime_enable(dev); /* important note: the device is NOT tagged as 'active' and will remain * 'suspended' until the hardware is enumerated/initialized. This is required * to make sure the ASoC framework use of pm_runtime_get_sync() does not silently * fail with -EACCESS because of race conditions between card creation and enumeration */
Quoted 10 lines
Quoted 10 lines
sound/soc/codecs/tac5xx2-sdw.c
Quoted 9 lines
sound/soc/codecs/tac5xx2-sdw.c new file +8
-0+ +static int tac5xx2_sdw_clk_stop (struct sdw_slave *peripheral, +enum sdw_clk_stop_mode mode, +enum sdw_clk_stop_type type) +{ +struct tac5xx2_prv *tac_dev =dev_get_drvdata (&peripheral->dev); + + dev_dbg(tac_dev->dev, "%s: mode:%d type:%d", __func__, mode,type);
Quoted 5 lines
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;this looks rather useless, no?
Yes, currently only required in case of debugging.
the clock stop is logged at the host level, this seems useless to me, even for debugging.
PATCH v11 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
---
v11:
- no change
v10:
- 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 v11 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.
---
v11:
- no change
v10:
- 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 5 lines · Niranjan H Y
Implement
sdca_asoc_pde_ensure_ps()helper function to poll for PDE
power state transitions. Per SDCA specification, after writingREQUESTED_PS, drivers must pollACTUAL_PSuntil the target power state is reached.
Quoted 8 lines
Changes include:
- Addsdca_asoc_pde_ensure_ps()to handleACTUAL_PSpolling with support for device-specific delay tables or default intervals
- Export function viasdca_asoc.hfor use by SDCA-compliant drivers
- Refactorentity_pde_event()insdca_asoc.cto use the helperSigned-off-by Niranjan H Y <[email protected]>---
Thanks,
Charles
Mark Brown
maintainersound/soc/sdca/sdca_asoc.c static int entity_parse_ot(struct device *dev, · line 423
Quoted 1 line · Niranjan H Y
sound/soc/sdca/sdca_asoc.c +1
-0+dev_err (dev,"PDE power transition failed: expected 0x%x, got 0x%x\n" , to_ps, val);
The old code included entity->label, I guess for disambiguation?
sound/soc/sdca/sdca_asoc.c static int entity_parse_ot(struct device *dev, · line 426
Quoted 3 lines
sound/soc/sdca/sdca_asoc.c +3
-0+return -ETIMEDOUT ; +} +EXPORT_SYMBOL (sdca_asoc_pde_poll_actual_ps);
All the other SDCA stuff seems to use EXPORT_SYMBOL_NS() or EXPORT_SYMBOL_NS_GPL()?
Charles Keepax
maintainerQuoted 5 lines · Mark Brown
sound/soc/sdca/sdca_asoc.c static int entity_parse_ot(struct device *dev, · line 423
Quoted 1 line · Niranjan H Y
sound/soc/sdca/sdca_asoc.c +1
-0+dev_err (dev,"PDE power transition failed: expected 0x%x, got 0x%x\n" , to_ps, val);The old code included
entity->label, I guess for disambiguation?
Hmm... yeah I think perhaps we should push the error message up to the caller here as it will have better context to print the message.
Quoted 7 lines
sound/soc/sdca/sdca_asoc.c static int entity_parse_ot(struct device *dev, · line 426
Quoted 4 lines
sound/soc/sdca/sdca_asoc.c +3
-0+return -ETIMEDOUT ; +} +EXPORT_SYMBOL (sdca_asoc_pde_poll_actual_ps);All the other SDCA stuff seems to use
EXPORT_SYMBOL_NS()orEXPORT_SYMBOL_NS_GPL()?
Oh thanks yeah that is a good spot, we should fix that up.
Thanks,
Charles