Fix races on creation of SDCA jack detection
Subsystems (3)
Charles Keepax
maintainercover Fix races on creation of SDCA jack detection
Currently there exists a couple races that can result in the DAPM graph coming up in a state that doesn't match the hardware with respect to SDCA jack detection. This series fixes these up by adding a component level fixup_controls helper into the asoc core and shuffling around the IRQ requests from the SDCA side.
Thanks,
Charles
Charles Keepax (3):
ASoC: Add a component fixup_controls callback
ASoC: SDCA: Populate IRQ data earlier
ASoC: SDCA: Switch to fixup_controls callback for IRQ registration
include/sound/sdca_interrupts.h | 2 + include/sound/soc-component.h | 2 + sound/soc/sdca/sdca_class_function.c | 4 +- sound/soc/sdca/sdca_interrupts.c | 94 +++++++++++----------------- sound/soc/sdca/sdca_jack.c | 44 ++++++------- sound/soc/soc-component.c | 10 +++ sound/soc/soc-core.c | 5 ++ 7 files changed, 75 insertions(+), 86 deletions(-)
Signature · 1 line
2.47.3
Charles Keepax
maintainerPATCH 3/3 ASoC: SDCA: Switch to fixup_controls callback for IRQ registration
Currently there are some race conditions around the boot of SDCA jack detection. The core creates DAPM widgets/routes quite a long time before it creates the associated ALSA control, and the jack detection IRQ is currently registered in component probe. At the time of component probe, the DAPM widgets exist, shortly after this the DAPM routes are added. At the time the DAPM routes are added the register value for the control is checked and the appropriate path is connected. The existing handling in the SDCA jack IRQ handles the case the control doesn't exist and updates the registers directly, which works until the DAPM routes are added. After the routes are added the DAPM graph has already set connected on a particular DAPM path, which will not be updated until an IRQ is received when the control is present. Thus those updates are usually not reflected in the resulting DAPM graph which can lead to the audio path being erroneously powered on/off.
Switch to the new fixup_controls callback to register the IRQs, this is guaranteed to run after all the controls have been created. Which means we can avoid the aforementioned race condition and as a bonus no longer need to concern ourselves with a case where the IRQ handler runs and the ALSA control is unavailable.
--- sound/soc/sdca/sdca_class_function.c | 4 +-- sound/soc/sdca/sdca_jack.c | 44 ++++++++++++---------------- 2 files changed, 21 insertions(+), 27 deletions(-)
sound/soc/sdca/sdca_class_function.c +2 -2
@@ -191,7 +191,7 @@ static const struct snd_soc_dai_ops class_function_sdw_ops = { .hw_free = class_function_sdw_remove_peripheral, }; -static int class_function_component_probe (struct snd_soc_component *component) +static int class_function_component_fixup_controls (struct snd_soc_component *component) {struct class_function_drv *drv =snd_soc_component_get_drvdata (component);struct sdca_class_drv *core = drv->core;
@@ -217,7 +217,7 @@ static int class_function_set_jack(struct snd_soc_component *component, }static const struct snd_soc_component_driver class_function_component_drv = { - .probe = class_function_component_probe, + .fixup_controls = class_function_component_fixup_controls, .remove = class_function_component_remove, .endianness =1 , };
sound/soc/sdca/sdca_jack.c +19 -25
72 lines not on this page · raw message
Signature · 1 line
2.47.3
Charles Keepax
maintainerPATCH 1/3 ASoC: Add a component fixup_controls callback
In reply to Charles KeepaxA card level fixup_controls callback was added in:
commit df4d27b19b89 ("ASoC: Introduce 'fixup_controls' card method")
This allowed the machine driver to take actions after all the card controls have been added. However, there are times when a codec driver would also want to do things like obtain references to controls for later use, which requires all the controls to be present. Add a component level fixup_controls callback, echoing the card level option.
--- include/sound/soc-component.h | 2 ++ sound/soc/soc-component.c | 10 ++++++++++ sound/soc/soc-core.c | 5 +++++ 3 files changed, 17 insertions(+)
include/sound/soc-component.h +2 -0
@@ -78,6 +78,7 @@ struct snd_soc_component_driver {unsigned int num_dapm_routes;int (*probe)(struct snd_soc_component *component); +int (*fixup_controls)(struct snd_soc_component *component);void (*remove)(struct snd_soc_component *component);int (*suspend)(struct snd_soc_component *component);int (*resume)(struct snd_soc_component *component);
@@ -380,6 +381,7 @@ void snd_soc_component_suspend(struct snd_soc_component *component);void snd_soc_component_resume (struct snd_soc_component *component);int snd_soc_component_is_suspended (struct snd_soc_component *component);int snd_soc_component_probe (struct snd_soc_component *component); +int snd_soc_component_fixup_controls (struct snd_soc_component *component);void snd_soc_component_remove (struct snd_soc_component *component);int snd_soc_component_of_xlate_dai_id (struct snd_soc_component *component,struct device_node *ep);
sound/soc/soc-component.c +10 -0
@@ -310,6 +310,16 @@ int snd_soc_component_probe(struct snd_soc_component *component)return soc_component_ret (component, ret); } +int snd_soc_component_fixup_controls (struct snd_soc_component *component) +{ +int ret =0 ; + +if (component->driver->fixup_controls) + ret = component->driver->fixup_controls (component); + +return soc_component_ret (component, ret); +} +void snd_soc_component_remove (struct snd_soc_component *component) {if (component->driver->remove)
sound/soc/soc-core.c +5 -0
@@ -2162,6 +2162,11 @@ static int snd_soc_bind_card(struct snd_soc_card *card) goto probe_end;snd_soc_dapm_new_widgets (card); +for_each_card_components (card, component) { + ret =snd_soc_component_fixup_controls (component); +if (ret <0 ) + goto probe_end; + }snd_soc_card_fixup_controls (card); ret =snd_card_register (card->snd_card);
Signature · 1 line
2.47.3
Charles Keepax
maintainerPATCH 2/3 ASoC: SDCA: Populate IRQ data earlier
In reply to Charles KeepaxCurrently, the IRQ data (attached Entity/Control/etc) is populated as the IRQ is requested. However, this can cause issues as occasionally the setup process wants to access specifics of an IRQ before the IRQ is actually enabled. To facilitate this cache all the IRQ data during sdca_irq_populate_early() and make sdca_irq_populate() simply request the outstanding IRQs. This also has the advantage that sdca_irq_populate() can now just iterate through the IRQ array which is much smaller/faster than going through every Entity in the Function for Controls.
--- include/sound/sdca_interrupts.h | 2 + sound/soc/sdca/sdca_interrupts.c | 94 ++++++++++++-------------------- 2 files changed, 37 insertions(+), 59 deletions(-)
include/sound/sdca_interrupts.h +2 -0
@@ -30,6 +30,7 @@ struct sdca_function_data;* @function: Pointer to the Function that the interrupt is associated with. * @entity: Pointer to the Entity that the interrupt is associated with. * @control: Pointer to the Control that the interrupt is associated with. +* @handler: Handler function to be called for the IRQ. * @priv: Pointer to private data for use by the handler. * @irq: IRQ number allocated to this interrupt, also used internally to track * the IRQ being assigned.
@@ -44,6 +45,7 @@ struct sdca_interrupt {struct sdca_function_data *function;struct sdca_entity *entity;struct sdca_control *control; +irq_handler_t handler;void *priv;
sound/soc/sdca/sdca_interrupts.c +35 -59
128 lines not on this page · raw message
Signature · 1 line
2.47.3