Skip to content

Commit b69a975

Browse files
committed
ASoC: Make creation of machine device from SOF core optional
Currently, SOF probes machine drivers by creating a platform device and passing the machine description as private data. This is driven by the ACPI restrictions. Ideally, ACPI tables should contain the description for the machine driver. This is not possible because ACPI tables are frozen and used on multiple OS-es (e.g Windows). In the case, of Device Tree we don't have this restrictions, so we choose to probe the machine drivers by creating a DT node as is the standard ALSA way. This patch makes the probing of machine drivers from SOF core optional allowing for arm platforms to decouple the SOF core from machine driver probing. Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
1 parent 872e5e8 commit b69a975

File tree

7 files changed

+106
-22
lines changed

7 files changed

+106
-22
lines changed

sound/soc/sof/core.c

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ int snd_sof_create_page_table(struct snd_sof_dev *sdev,
261261
/*
262262
* SOF Driver enumeration.
263263
*/
264-
static int sof_machine_check(struct snd_sof_dev *sdev)
264+
int sof_machine_check(struct snd_sof_dev *sdev)
265265
{
266266
struct snd_sof_pdata *plat_data = sdev->pdata;
267267
#if IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC)
@@ -292,13 +292,45 @@ static int sof_machine_check(struct snd_sof_dev *sdev)
292292
return 0;
293293
#endif
294294
}
295+
EXPORT_SYMBOL(sof_machine_check);
295296

296-
static int sof_probe_continue(struct snd_sof_dev *sdev)
297+
int sof_machine_register(struct snd_sof_dev *sdev, void *pdata)
297298
{
298-
struct snd_sof_pdata *plat_data = sdev->pdata;
299+
struct snd_sof_pdata *plat_data = (struct snd_sof_pdata *)pdata;
299300
const char *drv_name;
300301
const void *mach;
301302
int size;
303+
304+
drv_name = plat_data->machine->drv_name;
305+
mach = (const void *)plat_data->machine;
306+
size = sizeof(*plat_data->machine);
307+
308+
/* register machine driver, pass machine info as pdata */
309+
plat_data->pdev_mach =
310+
platform_device_register_data(sdev->dev, drv_name,
311+
PLATFORM_DEVID_NONE, mach, size);
312+
if (IS_ERR(plat_data->pdev_mach))
313+
return PTR_ERR(plat_data->pdev_mach);
314+
315+
dev_dbg(sdev->dev, "created machine %s\n",
316+
dev_name(&plat_data->pdev_mach->dev));
317+
318+
return 0;
319+
}
320+
EXPORT_SYMBOL(sof_machine_register);
321+
322+
void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata)
323+
{
324+
struct snd_sof_pdata *plat_data = (struct snd_sof_pdata *)pdata;
325+
326+
if (!IS_ERR_OR_NULL(plat_data->pdev_mach))
327+
platform_device_unregister(plat_data->pdev_mach);
328+
}
329+
EXPORT_SYMBOL(sof_machine_unregister);
330+
331+
static int sof_probe_continue(struct snd_sof_dev *sdev)
332+
{
333+
struct snd_sof_pdata *plat_data = sdev->pdata;
302334
int ret;
303335

304336
/* probe the DSP hardware */
@@ -309,7 +341,7 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
309341
}
310342

311343
/* check machine info */
312-
ret = sof_machine_check(sdev);
344+
ret = snd_sof_machine_check(sdev);
313345
if (ret < 0) {
314346
dev_err(sdev->dev, "error: failed to get machine info %d\n",
315347
ret);
@@ -384,22 +416,9 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
384416
goto fw_run_err;
385417
}
386418

387-
drv_name = plat_data->machine->drv_name;
388-
mach = (const void *)plat_data->machine;
389-
size = sizeof(*plat_data->machine);
390-
391-
/* register machine driver, pass machine info as pdata */
392-
plat_data->pdev_mach =
393-
platform_device_register_data(sdev->dev, drv_name,
394-
PLATFORM_DEVID_NONE, mach, size);
395-
396-
if (IS_ERR(plat_data->pdev_mach)) {
397-
ret = PTR_ERR(plat_data->pdev_mach);
419+
ret = snd_sof_machine_register(sdev, plat_data);
420+
if (ret < 0)
398421
goto fw_run_err;
399-
}
400-
401-
dev_dbg(sdev->dev, "created machine %s\n",
402-
dev_name(&plat_data->pdev_mach->dev));
403422

404423
if (plat_data->sof_probe_complete)
405424
plat_data->sof_probe_complete(sdev->dev);
@@ -521,9 +540,7 @@ int snd_sof_device_remove(struct device *dev)
521540
* will remove the component driver and unload the topology
522541
* before freeing the snd_card.
523542
*/
524-
if (!IS_ERR_OR_NULL(pdata->pdev_mach))
525-
platform_device_unregister(pdata->pdev_mach);
526-
543+
snd_sof_machine_unregister(sdev, pdata);
527544
/*
528545
* Unregistering the machine driver results in unloading the topology.
529546
* Some widgets, ex: scheduler, attempt to power down the core they are

sound/soc/sof/intel/apl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ const struct snd_sof_dsp_ops sof_apl_ops = {
5353
.ipc_msg_data = hda_ipc_msg_data,
5454
.ipc_pcm_params = hda_ipc_pcm_params,
5555

56+
/* machine driver */
57+
.machine_check = sof_machine_check,
58+
.machine_register = sof_machine_register,
59+
.machine_unregister = sof_machine_unregister,
60+
5661
/* debug */
5762
.debug_map = apl_dsp_debugfs,
5863
.debug_map_count = ARRAY_SIZE(apl_dsp_debugfs),

sound/soc/sof/intel/bdw.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ const struct snd_sof_dsp_ops sof_bdw_ops = {
574574
.ipc_msg_data = intel_ipc_msg_data,
575575
.ipc_pcm_params = intel_ipc_pcm_params,
576576

577+
/* machine driver */
578+
.machine_check = sof_machine_check,
579+
.machine_register = sof_machine_register,
580+
.machine_unregister = sof_machine_unregister,
581+
577582
/* debug */
578583
.debug_map = bdw_debugfs,
579584
.debug_map_count = ARRAY_SIZE(bdw_debugfs),

sound/soc/sof/intel/byt.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@ const struct snd_sof_dsp_ops sof_tng_ops = {
514514
.ipc_msg_data = intel_ipc_msg_data,
515515
.ipc_pcm_params = intel_ipc_pcm_params,
516516

517+
/* machine driver */
518+
.machine_check = sof_machine_check,
519+
.machine_register = sof_machine_register,
520+
.machine_unregister = sof_machine_unregister,
521+
517522
/* debug */
518523
.debug_map = byt_debugfs,
519524
.debug_map_count = ARRAY_SIZE(byt_debugfs),
@@ -682,6 +687,11 @@ const struct snd_sof_dsp_ops sof_byt_ops = {
682687
.ipc_msg_data = intel_ipc_msg_data,
683688
.ipc_pcm_params = intel_ipc_pcm_params,
684689

690+
/* machine driver */
691+
.machine_check = sof_machine_check,
692+
.machine_register = sof_machine_register,
693+
.machine_unregister = sof_machine_unregister,
694+
685695
/* debug */
686696
.debug_map = byt_debugfs,
687697
.debug_map_count = ARRAY_SIZE(byt_debugfs),
@@ -748,6 +758,11 @@ const struct snd_sof_dsp_ops sof_cht_ops = {
748758
.ipc_msg_data = intel_ipc_msg_data,
749759
.ipc_pcm_params = intel_ipc_pcm_params,
750760

761+
/* machine driver */
762+
.machine_check = sof_machine_check,
763+
.machine_register = sof_machine_register,
764+
.machine_unregister = sof_machine_unregister,
765+
751766
/* debug */
752767
.debug_map = cht_debugfs,
753768
.debug_map_count = ARRAY_SIZE(cht_debugfs),

sound/soc/sof/intel/cnl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ const struct snd_sof_dsp_ops sof_cnl_ops = {
243243
.ipc_msg_data = hda_ipc_msg_data,
244244
.ipc_pcm_params = hda_ipc_pcm_params,
245245

246+
/* machine driver */
247+
.machine_check = sof_machine_check,
248+
.machine_register = sof_machine_register,
249+
.machine_unregister = sof_machine_unregister,
250+
246251
/* debug */
247252
.debug_map = cnl_dsp_debugfs,
248253
.debug_map_count = ARRAY_SIZE(cnl_dsp_debugfs),

sound/soc/sof/ops.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,32 @@ snd_sof_pcm_platform_pointer(struct snd_sof_dev *sdev,
391391
return 0;
392392
}
393393

394+
/* machine driver */
395+
static inline int
396+
snd_sof_machine_register(struct snd_sof_dev *sdev, void *pdata)
397+
{
398+
if (sof_ops(sdev) && sof_ops(sdev)->machine_register)
399+
return sof_ops(sdev)->machine_register(sdev, pdata);
400+
401+
return 0;
402+
}
403+
404+
static inline void
405+
snd_sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata)
406+
{
407+
if (sof_ops(sdev) && sof_ops(sdev)->machine_unregister)
408+
sof_ops(sdev)->machine_unregister(sdev, pdata);
409+
}
410+
411+
static inline int
412+
snd_sof_machine_check(struct snd_sof_dev *sdev)
413+
{
414+
if (sof_ops(sdev) && sof_ops(sdev)->machine_check)
415+
return sof_ops(sdev)->machine_check(sdev);
416+
417+
return 0;
418+
}
419+
394420
static inline const struct snd_sof_dsp_ops
395421
*sof_get_ops(const struct sof_dev_desc *d,
396422
const struct sof_ops_table mach_ops[], int asize)

sound/soc/sof/sof-priv.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ struct snd_sof_dsp_ops {
216216
int (*get_window_offset)(struct snd_sof_dev *sdev,
217217
u32 id);/* mandatory for common loader code */
218218

219+
/* machine driver ops */
220+
int (*machine_register)(struct snd_sof_dev *sdev,
221+
void *pdata); /* optional */
222+
void (*machine_unregister)(struct snd_sof_dev *sdev,
223+
void *pdata); /* optional */
224+
int (*machine_check)(struct snd_sof_dev *sdev); /* optional */
225+
219226
/* DAI ops */
220227
struct snd_soc_dai_driver *drv;
221228
int num_drv;
@@ -503,6 +510,10 @@ int snd_sof_create_page_table(struct snd_sof_dev *sdev,
503510
struct snd_dma_buffer *dmab,
504511
unsigned char *page_table, size_t size);
505512

513+
int sof_machine_register(struct snd_sof_dev *sdev, void *pdata);
514+
void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata);
515+
int sof_machine_check(struct snd_sof_dev *sdev);
516+
506517
/*
507518
* Firmware loading.
508519
*/

0 commit comments

Comments
 (0)