From 932491f75629ab2e3f4acbfd1a7e16d42f8bc351 Mon Sep 17 00:00:00 2001 From: Mark Farrugia Date: Fri, 2 Nov 2018 14:49:24 +1100 Subject: Transform AVIRT into platform driver Like aloop, we need to be able to find AVIRT by-path as platform-snd_avirt.0. The 4a-mixer uses this method to find cards. Signed-off-by: Mark Farrugia --- core.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++------------------- core.h | 1 + 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/core.c b/core.c index 4645f06..41cc555 100644 --- a/core.c +++ b/core.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "core.h" @@ -439,16 +440,63 @@ struct snd_avirt_stream *snd_avirt_stream_find_by_device(unsigned int device) return NULL; } +static int snd_avirt_core_probe(struct platform_device *devptr) +{ + int err; + + // Create the card instance + err = snd_card_new(&devptr->dev, SNDRV_DEFAULT_IDX1, "avirt", + THIS_MODULE, 0, &core.card); + if (err < 0) { + D_ERRORK("Failed to create sound card"); + return err; + } + + strncpy(core.card->driver, "avirt-alsa-dev", 16); + strncpy(core.card->shortname, "avirt", 32); + strncpy(core.card->longname, "A virtual sound card driver for ALSA", + 80); + + return 0; +} + +static int snd_avirt_core_remove(struct platform_device *devptr) +{ + snd_card_free(core.card); + + return 0; +} + +static struct platform_driver snd_avirt_driver = { + .probe = snd_avirt_core_probe, + .remove = snd_avirt_core_remove, + .driver = + { + .name = SND_AVIRT_DRIVER, + }, +}; + /** - * core_init - Initialize the kernel module + * snd_avirt_core_init - Initialize the kernel module */ -static int __init core_init(void) +static int __init snd_avirt_core_init(void) { int err; D_INFOK("Alsa Virtual Sound Driver avirt-%d.%d.%d", core.version[0], core.version[1], core.version[2]); + err = platform_driver_register(&snd_avirt_driver); + if (err < 0) + return err; + + core.plat_dev = + platform_device_register_simple(SND_AVIRT_DRIVER, 0, NULL, 0); + if (IS_ERR(core.plat_dev)) { + err = PTR_ERR(core.plat_dev); + goto exit_platform_device; + } + core.class = class_create(THIS_MODULE, SND_AVIRT_DRIVER); if (IS_ERR(core.class)) { D_ERRORK("No udev support"); @@ -461,54 +509,44 @@ static int __init core_init(void) goto exit_class; } - // Create the card instance - err = snd_card_new(core.dev, SNDRV_DEFAULT_IDX1, "avirt", THIS_MODULE, - 0, &core.card); - if (err < 0) { - D_ERRORK("Failed to create sound card"); - goto exit_class_container; - } - - strncpy(core.card->driver, "avirt-alsa-dev", 16); - strncpy(core.card->shortname, "avirt", 32); - strncpy(core.card->longname, "A virtual sound card driver for ALSA", - 80); - snd_avirt_audiopath_kset = kset_create_and_add("audiopaths", NULL, &core.dev->kobj); if (!snd_avirt_audiopath_kset) { err = -ENOMEM; - goto exit_snd_card; + goto exit_class_container; } err = snd_avirt_configfs_init(&core); if (err < 0) - goto exit_snd_card; + goto exit_kset; return 0; -exit_snd_card: - snd_card_free(core.card); +exit_kset: + kset_unregister(snd_avirt_audiopath_kset); exit_class_container: device_destroy(core.class, 0); exit_class: class_destroy(core.class); +exit_platform_device: + platform_device_unregister(core.plat_dev); + platform_driver_unregister(&snd_avirt_driver); return err; } /** - * core_exit - Destroy the kernel module + * snd_avirt_core_exit - Destroy the kernel module */ -static void __exit core_exit(void) +static void __exit snd_avirt_core_exit(void) { snd_avirt_configfs_exit(&core); - kset_unregister(snd_avirt_audiopath_kset); - snd_card_free(core.card); device_destroy(core.class, 0); class_destroy(core.class); + platform_device_unregister(core.plat_dev); + platform_driver_unregister(&snd_avirt_driver); } -module_init(core_init); -module_exit(core_exit); +module_init(snd_avirt_core_init); +module_exit(snd_avirt_core_exit); diff --git a/core.h b/core.h index 61a78e9..fe2aaab 100644 --- a/core.h +++ b/core.h @@ -21,6 +21,7 @@ struct snd_avirt_core { struct snd_card *card; struct device *dev; struct class *class; + struct platform_device *plat_dev; struct config_group *stream_group; unsigned int stream_count; bool streams_sealed; -- cgit 1.2.3-korg