Skip to content

Commit 8e34f1e

Browse files
committed
Merge series "ASoC: core: Two step component registration" from Cezary Rojewski <[email protected]>:
Provide a mechanism for true two-step component registration. This mimics device registration flow where initialization is the first step while addition goes as second in line. Drivers may choose to modify component's fields before registering component to ASoC subsystem via snd_soc_add_component. Patchset achieves status quo - behavior of snd_soc_register_component remains unchanged. Cezary Rojewski (3): ASoC: core: Relocate and expose snd_soc_component_initialize ASoC: core: Simplify snd_soc_component_initialize declaration ASoC: core: Two step component registration include/sound/soc-component.h | 3 -- include/sound/soc.h | 11 +++--- sound/soc/soc-component.c | 16 --------- sound/soc/soc-core.c | 52 +++++++++++++++++---------- sound/soc/soc-generic-dmaengine-pcm.c | 14 +++++--- sound/soc/stm/stm32_adfsdm.c | 9 +++-- 6 files changed, 55 insertions(+), 50 deletions(-) -- 2.17.1
2 parents 2dbf11e + ea029dd commit 8e34f1e

File tree

6 files changed

+55
-50
lines changed

6 files changed

+55
-50
lines changed

include/sound/soc-component.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,6 @@ static inline int snd_soc_component_cache_sync(
325325
return regcache_sync(component->regmap);
326326
}
327327

328-
int snd_soc_component_initialize(struct snd_soc_component *component,
329-
const struct snd_soc_component_driver *driver,
330-
struct device *dev, const char *name);
331328
void snd_soc_component_set_aux(struct snd_soc_component *component,
332329
struct snd_soc_aux_dev *aux);
333330
int snd_soc_component_init(struct snd_soc_component *component);

include/sound/soc.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,12 @@ static inline int snd_soc_resume(struct device *dev)
414414
}
415415
#endif
416416
int snd_soc_poweroff(struct device *dev);
417-
int snd_soc_add_component(struct device *dev,
418-
struct snd_soc_component *component,
419-
const struct snd_soc_component_driver *component_driver,
420-
struct snd_soc_dai_driver *dai_drv,
421-
int num_dai);
417+
int snd_soc_component_initialize(struct snd_soc_component *component,
418+
const struct snd_soc_component_driver *driver,
419+
struct device *dev);
420+
int snd_soc_add_component(struct snd_soc_component *component,
421+
struct snd_soc_dai_driver *dai_drv,
422+
int num_dai);
422423
int snd_soc_register_component(struct device *dev,
423424
const struct snd_soc_component_driver *component_driver,
424425
struct snd_soc_dai_driver *dai_drv, int num_dai);

sound/soc/soc-component.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,6 @@ static inline int _soc_component_ret(struct snd_soc_component *component,
3333
return ret;
3434
}
3535

36-
int snd_soc_component_initialize(struct snd_soc_component *component,
37-
const struct snd_soc_component_driver *driver,
38-
struct device *dev, const char *name)
39-
{
40-
INIT_LIST_HEAD(&component->dai_list);
41-
INIT_LIST_HEAD(&component->dobj_list);
42-
INIT_LIST_HEAD(&component->card_list);
43-
mutex_init(&component->io_mutex);
44-
45-
component->name = name;
46-
component->dev = dev;
47-
component->driver = driver;
48-
49-
return 0;
50-
}
51-
5236
void snd_soc_component_set_aux(struct snd_soc_component *component,
5337
struct snd_soc_aux_dev *aux)
5438
{

sound/soc/soc-core.c

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,29 +2438,38 @@ static void snd_soc_del_component_unlocked(struct snd_soc_component *component)
24382438
list_del(&component->list);
24392439
}
24402440

2441-
int snd_soc_add_component(struct device *dev,
2442-
struct snd_soc_component *component,
2443-
const struct snd_soc_component_driver *component_driver,
2444-
struct snd_soc_dai_driver *dai_drv,
2445-
int num_dai)
2441+
int snd_soc_component_initialize(struct snd_soc_component *component,
2442+
const struct snd_soc_component_driver *driver,
2443+
struct device *dev)
24462444
{
2447-
const char *name = fmt_single_name(dev, &component->id);
2448-
int ret;
2449-
int i;
2445+
INIT_LIST_HEAD(&component->dai_list);
2446+
INIT_LIST_HEAD(&component->dobj_list);
2447+
INIT_LIST_HEAD(&component->card_list);
2448+
mutex_init(&component->io_mutex);
24502449

2451-
if (!name) {
2450+
component->name = fmt_single_name(dev, &component->id);
2451+
if (!component->name) {
24522452
dev_err(dev, "ASoC: Failed to allocate name\n");
24532453
return -ENOMEM;
24542454
}
24552455

2456-
mutex_lock(&client_mutex);
2456+
component->dev = dev;
2457+
component->driver = driver;
24572458

2458-
ret = snd_soc_component_initialize(component, component_driver,
2459-
dev, name);
2460-
if (ret)
2461-
goto err_free;
2459+
return 0;
2460+
}
2461+
EXPORT_SYMBOL_GPL(snd_soc_component_initialize);
2462+
2463+
int snd_soc_add_component(struct snd_soc_component *component,
2464+
struct snd_soc_dai_driver *dai_drv,
2465+
int num_dai)
2466+
{
2467+
int ret;
2468+
int i;
2469+
2470+
mutex_lock(&client_mutex);
24622471

2463-
if (component_driver->endianness) {
2472+
if (component->driver->endianness) {
24642473
for (i = 0; i < num_dai; i++) {
24652474
convert_endianness_formats(&dai_drv[i].playback);
24662475
convert_endianness_formats(&dai_drv[i].capture);
@@ -2469,7 +2478,8 @@ int snd_soc_add_component(struct device *dev,
24692478

24702479
ret = snd_soc_register_dais(component, dai_drv, num_dai);
24712480
if (ret < 0) {
2472-
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);
24732483
goto err_cleanup;
24742484
}
24752485

@@ -2487,7 +2497,7 @@ int snd_soc_add_component(struct device *dev,
24872497
err_cleanup:
24882498
if (ret < 0)
24892499
snd_soc_del_component_unlocked(component);
2490-
err_free:
2500+
24912501
mutex_unlock(&client_mutex);
24922502

24932503
if (ret == 0)
@@ -2503,13 +2513,17 @@ int snd_soc_register_component(struct device *dev,
25032513
int num_dai)
25042514
{
25052515
struct snd_soc_component *component;
2516+
int ret;
25062517

25072518
component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
25082519
if (!component)
25092520
return -ENOMEM;
25102521

2511-
return snd_soc_add_component(dev, component, component_driver,
2512-
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);
25132527
}
25142528
EXPORT_SYMBOL_GPL(snd_soc_register_component);
25152529

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)