Skip to content

Commit ea029dd

Browse files
crojewsk-intelbroonie
authored andcommitted
ASoC: core: Two step component registration
Modify snd_soc_add_component so it calls snd_soc_component_initialize no longer and thus providing true two-step registration. Drivers may choose to change component's fields before actually adding it to ASoC subsystem. Signed-off-by: Cezary Rojewski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 7274d4c commit ea029dd

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

include/sound/soc.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,9 @@ int snd_soc_poweroff(struct device *dev);
417417
int snd_soc_component_initialize(struct snd_soc_component *component,
418418
const struct snd_soc_component_driver *driver,
419419
struct device *dev);
420-
int snd_soc_add_component(struct device *dev,
421-
struct snd_soc_component *component,
422-
const struct snd_soc_component_driver *component_driver,
423-
struct snd_soc_dai_driver *dai_drv,
424-
int num_dai);
420+
int snd_soc_add_component(struct snd_soc_component *component,
421+
struct snd_soc_dai_driver *dai_drv,
422+
int num_dai);
425423
int snd_soc_register_component(struct device *dev,
426424
const struct snd_soc_component_driver *component_driver,
427425
struct snd_soc_dai_driver *dai_drv, int num_dai);

sound/soc/soc-core.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,22 +2460,16 @@ int snd_soc_component_initialize(struct snd_soc_component *component,
24602460
}
24612461
EXPORT_SYMBOL_GPL(snd_soc_component_initialize);
24622462

2463-
int snd_soc_add_component(struct device *dev,
2464-
struct snd_soc_component *component,
2465-
const struct snd_soc_component_driver *component_driver,
2466-
struct snd_soc_dai_driver *dai_drv,
2467-
int num_dai)
2463+
int snd_soc_add_component(struct snd_soc_component *component,
2464+
struct snd_soc_dai_driver *dai_drv,
2465+
int num_dai)
24682466
{
24692467
int ret;
24702468
int i;
24712469

24722470
mutex_lock(&client_mutex);
24732471

2474-
ret = snd_soc_component_initialize(component, component_driver, dev);
2475-
if (ret)
2476-
goto err_free;
2477-
2478-
if (component_driver->endianness) {
2472+
if (component->driver->endianness) {
24792473
for (i = 0; i < num_dai; i++) {
24802474
convert_endianness_formats(&dai_drv[i].playback);
24812475
convert_endianness_formats(&dai_drv[i].capture);
@@ -2484,7 +2478,8 @@ int snd_soc_add_component(struct device *dev,
24842478

24852479
ret = snd_soc_register_dais(component, dai_drv, num_dai);
24862480
if (ret < 0) {
2487-
dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
2481+
dev_err(component->dev, "ASoC: Failed to register DAIs: %d\n",
2482+
ret);
24882483
goto err_cleanup;
24892484
}
24902485

@@ -2502,7 +2497,7 @@ int snd_soc_add_component(struct device *dev,
25022497
err_cleanup:
25032498
if (ret < 0)
25042499
snd_soc_del_component_unlocked(component);
2505-
err_free:
2500+
25062501
mutex_unlock(&client_mutex);
25072502

25082503
if (ret == 0)
@@ -2518,13 +2513,17 @@ int snd_soc_register_component(struct device *dev,
25182513
int num_dai)
25192514
{
25202515
struct snd_soc_component *component;
2516+
int ret;
25212517

25222518
component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
25232519
if (!component)
25242520
return -ENOMEM;
25252521

2526-
return snd_soc_add_component(dev, component, component_driver,
2527-
dai_drv, num_dai);
2522+
ret = snd_soc_component_initialize(component, component_driver, dev);
2523+
if (ret < 0)
2524+
return ret;
2525+
2526+
return snd_soc_add_component(component, dai_drv, num_dai);
25282527
}
25292528
EXPORT_SYMBOL_GPL(snd_soc_register_component);
25302529

sound/soc/soc-generic-dmaengine-pcm.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ static void dmaengine_pcm_release_chan(struct dmaengine_pcm *pcm)
424424
int snd_dmaengine_pcm_register(struct device *dev,
425425
const struct snd_dmaengine_pcm_config *config, unsigned int flags)
426426
{
427+
const struct snd_soc_component_driver *driver;
427428
struct dmaengine_pcm *pcm;
428429
int ret;
429430

@@ -442,12 +443,15 @@ int snd_dmaengine_pcm_register(struct device *dev,
442443
goto err_free_dma;
443444

444445
if (config && config->process)
445-
ret = snd_soc_add_component(dev, &pcm->component,
446-
&dmaengine_pcm_component_process,
447-
NULL, 0);
446+
driver = &dmaengine_pcm_component_process;
448447
else
449-
ret = snd_soc_add_component(dev, &pcm->component,
450-
&dmaengine_pcm_component, NULL, 0);
448+
driver = &dmaengine_pcm_component;
449+
450+
ret = snd_soc_component_initialize(&pcm->component, driver, dev);
451+
if (ret)
452+
goto err_free_dma;
453+
454+
ret = snd_soc_add_component(&pcm->component, NULL, 0);
451455
if (ret)
452456
goto err_free_dma;
453457

sound/soc/stm/stm32_adfsdm.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,17 @@ static int stm32_adfsdm_probe(struct platform_device *pdev)
344344
component = devm_kzalloc(&pdev->dev, sizeof(*component), GFP_KERNEL);
345345
if (!component)
346346
return -ENOMEM;
347+
348+
ret = snd_soc_component_initialize(component,
349+
&stm32_adfsdm_soc_platform,
350+
&pdev->dev);
351+
if (ret < 0)
352+
return ret;
347353
#ifdef CONFIG_DEBUG_FS
348354
component->debugfs_prefix = "pcm";
349355
#endif
350356

351-
ret = snd_soc_add_component(&pdev->dev, component,
352-
&stm32_adfsdm_soc_platform, NULL, 0);
357+
ret = snd_soc_add_component(component, NULL, 0);
353358
if (ret < 0)
354359
dev_err(&pdev->dev, "%s: Failed to register PCM platform\n",
355360
__func__);

0 commit comments

Comments
 (0)