Commit ea029dd8d0124fcd5db1c7003e87a7bd4ddb3bad

Authored by Cezary Rojewski
Committed by Mark Brown
1 parent 7274d4cd85

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 <cezary.rojewski@intel.com>
Link: https://lore.kernel.org/r/20200731144146.6678-4-cezary.rojewski@intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>

Showing 4 changed files with 32 additions and 26 deletions Side-by-side Diff

... ... @@ -417,11 +417,9 @@
417 417 int snd_soc_component_initialize(struct snd_soc_component *component,
418 418 const struct snd_soc_component_driver *driver,
419 419 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);
425 423 int snd_soc_register_component(struct device *dev,
426 424 const struct snd_soc_component_driver *component_driver,
427 425 struct snd_soc_dai_driver *dai_drv, int num_dai);
sound/soc/soc-core.c
... ... @@ -2460,22 +2460,16 @@
2460 2460 }
2461 2461 EXPORT_SYMBOL_GPL(snd_soc_component_initialize);
2462 2462  
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)
2468 2466 {
2469 2467 int ret;
2470 2468 int i;
2471 2469  
2472 2470 mutex_lock(&client_mutex);
2473 2471  
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) {
2479 2473 for (i = 0; i < num_dai; i++) {
2480 2474 convert_endianness_formats(&dai_drv[i].playback);
2481 2475 convert_endianness_formats(&dai_drv[i].capture);
... ... @@ -2484,7 +2478,8 @@
2484 2478  
2485 2479 ret = snd_soc_register_dais(component, dai_drv, num_dai);
2486 2480 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);
2488 2483 goto err_cleanup;
2489 2484 }
2490 2485  
... ... @@ -2502,7 +2497,7 @@
2502 2497 err_cleanup:
2503 2498 if (ret < 0)
2504 2499 snd_soc_del_component_unlocked(component);
2505   -err_free:
  2500 +
2506 2501 mutex_unlock(&client_mutex);
2507 2502  
2508 2503 if (ret == 0)
2509 2504  
... ... @@ -2518,13 +2513,17 @@
2518 2513 int num_dai)
2519 2514 {
2520 2515 struct snd_soc_component *component;
  2516 + int ret;
2521 2517  
2522 2518 component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
2523 2519 if (!component)
2524 2520 return -ENOMEM;
2525 2521  
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);
2528 2527 }
2529 2528 EXPORT_SYMBOL_GPL(snd_soc_register_component);
2530 2529  
sound/soc/soc-generic-dmaengine-pcm.c
... ... @@ -424,6 +424,7 @@
424 424 int snd_dmaengine_pcm_register(struct device *dev,
425 425 const struct snd_dmaengine_pcm_config *config, unsigned int flags)
426 426 {
  427 + const struct snd_soc_component_driver *driver;
427 428 struct dmaengine_pcm *pcm;
428 429 int ret;
429 430  
430 431  
... ... @@ -442,12 +443,15 @@
442 443 goto err_free_dma;
443 444  
444 445 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;
448 447 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);
451 455 if (ret)
452 456 goto err_free_dma;
453 457  
sound/soc/stm/stm32_adfsdm.c
... ... @@ -344,12 +344,17 @@
344 344 component = devm_kzalloc(&pdev->dev, sizeof(*component), GFP_KERNEL);
345 345 if (!component)
346 346 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;
347 353 #ifdef CONFIG_DEBUG_FS
348 354 component->debugfs_prefix = "pcm";
349 355 #endif
350 356  
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);
353 358 if (ret < 0)
354 359 dev_err(&pdev->dev, "%s: Failed to register PCM platform\n",
355 360 __func__);