summaryrefslogtreecommitdiffstats
path: root/core.c
diff options
context:
space:
mode:
authorMark Farrugia <mark.farrugia@fiberdyne.com.au>2018-11-02 14:49:24 +1100
committerMark Farrugia <mark.farrugia@fiberdyne.com.au>2018-11-02 14:49:24 +1100
commit932491f75629ab2e3f4acbfd1a7e16d42f8bc351 (patch)
tree3027780d7a263c4e7c29d61d443ff6da1fd8b112 /core.c
parentae62015391dded62bf60ac0cc8b3e19fef50dbbc (diff)
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 <mark.farrugia@fiberdyne.com.au>
Diffstat (limited to 'core.c')
-rw-r--r--core.c88
1 files changed, 63 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 <linux/string.h>
#include <linux/slab.h>
#include <sound/initval.h>
+#include <linux/platform_device.h>
#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);