summaryrefslogtreecommitdiffstats
path: root/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'core.c')
-rw-r--r--core.c197
1 files changed, 99 insertions, 98 deletions
diff --git a/core.c b/core.c
index 08381e5..aacc0a1 100644
--- a/core.c
+++ b/core.c
@@ -3,7 +3,7 @@
* AVIRT - ALSA Virtual Soundcard
*
* Copyright (c) 2010-2018 Fiberdyne Systems Pty Ltd
- *
+ *
* core.c - AVIRT core internals
*/
@@ -27,44 +27,43 @@ MODULE_LICENSE("GPL v2");
#define SND_AVIRTUAL_DRIVER "snd_avirt"
-extern struct snd_pcm_ops pcm_ops;
-
-static struct avirt_core core = {
+static struct snd_avirt_core core = {
.stream_count = 0,
.streams_sealed = false,
};
-struct avirt_coreinfo coreinfo = {
- .version = {0, 0, 1},
+struct snd_avirt_coreinfo coreinfo = {
+ .version = { 0, 0, 1 },
};
static LIST_HEAD(audiopath_list);
-struct avirt_audiopath_obj {
+struct snd_avirt_audiopath_obj {
struct kobject kobj;
struct list_head list;
- struct avirt_audiopath *path;
+ struct snd_avirt_audiopath *path;
};
-static struct kset *avirt_audiopath_kset;
+static struct kset *snd_avirt_audiopath_kset;
static struct kobject *kobj;
-#define to_audiopath_obj(d) container_of(d, struct avirt_audiopath_obj, kobj)
-#define to_audiopath_attr(a) \
- container_of(a, struct avirt_audiopath_attribute, attr)
+#define to_audiopath_obj(d) \
+ container_of(d, struct snd_avirt_audiopath_obj, kobj)
+#define to_audiopath_attr(a) \
+ container_of(a, struct snd_avirt_audiopath_attribute, attr)
/**
- * struct avirt_audiopath_attribute - access the attributes of Audio Path
+ * struct snd_avirt_audiopath_attribute - access the attributes of Audio Path
* @attr: attributes of an Audio Path
* @show: pointer to the show function
* @store: pointer to the store function
*/
-struct avirt_audiopath_attribute {
+struct snd_avirt_audiopath_attribute {
struct attribute attr;
- ssize_t (*show)(struct avirt_audiopath_obj *d,
- struct avirt_audiopath_attribute *attr, char *buf);
- ssize_t (*store)(struct avirt_audiopath_obj *d,
- struct avirt_audiopath_attribute *attr,
+ ssize_t (*show)(struct snd_avirt_audiopath_obj *d,
+ struct snd_avirt_audiopath_attribute *attr, char *buf);
+ ssize_t (*store)(struct snd_avirt_audiopath_obj *d,
+ struct snd_avirt_audiopath_attribute *attr,
const char *buf, size_t count);
};
@@ -77,8 +76,8 @@ struct avirt_audiopath_attribute {
static ssize_t audiopath_attr_show(struct kobject *kobj, struct attribute *attr,
char *buf)
{
- struct avirt_audiopath_attribute *audiopath_attr;
- struct avirt_audiopath_obj *audiopath_obj;
+ struct snd_avirt_audiopath_attribute *audiopath_attr;
+ struct snd_avirt_audiopath_obj *audiopath_obj;
audiopath_attr = to_audiopath_attr(attr);
audiopath_obj = to_audiopath_obj(kobj);
@@ -100,8 +99,8 @@ static ssize_t audiopath_attr_store(struct kobject *kobj,
struct attribute *attr, const char *buf,
size_t len)
{
- struct avirt_audiopath_attribute *audiopath_attr;
- struct avirt_audiopath_obj *audiopath_obj;
+ struct snd_avirt_audiopath_attribute *audiopath_attr;
+ struct snd_avirt_audiopath_obj *audiopath_obj;
audiopath_attr = to_audiopath_attr(attr);
audiopath_obj = to_audiopath_obj(kobj);
@@ -111,84 +110,88 @@ static ssize_t audiopath_attr_store(struct kobject *kobj,
return audiopath_attr->store(audiopath_obj, audiopath_attr, buf, len);
}
-static const struct sysfs_ops avirt_audiopath_sysfs_ops = {
+static const struct sysfs_ops snd_avirt_audiopath_sysfs_ops = {
.show = audiopath_attr_show,
.store = audiopath_attr_store,
};
/**
- * avirt_audiopath_release - Audio Path release function
+ * snd_avirt_audiopath_release - Audio Path release function
* @kobj: pointer to Audio Paths's kobject
*/
-static void avirt_audiopath_release(struct kobject *kobj)
+static void snd_avirt_audiopath_release(struct kobject *kobj)
{
- struct avirt_audiopath_obj *audiopath_obj = to_audiopath_obj(kobj);
+ struct snd_avirt_audiopath_obj *audiopath_obj = to_audiopath_obj(kobj);
kfree(audiopath_obj);
}
-static ssize_t audiopath_name_show(struct avirt_audiopath_obj *audiopath_obj,
- struct avirt_audiopath_attribute *attr,
- char *buf)
+static ssize_t
+ audiopath_name_show(struct snd_avirt_audiopath_obj *audiopath_obj,
+ struct snd_avirt_audiopath_attribute *attr,
+ char *buf)
{
return sprintf(buf, "%s\n", audiopath_obj->path->name);
}
-static ssize_t audiopath_version_show(struct avirt_audiopath_obj *audiopath_obj,
- struct avirt_audiopath_attribute *attr,
- char *buf)
+static ssize_t
+ audiopath_version_show(struct snd_avirt_audiopath_obj *audiopath_obj,
+ struct snd_avirt_audiopath_attribute *attr,
+ char *buf)
{
- struct avirt_audiopath *audiopath = audiopath_obj->path;
+ struct snd_avirt_audiopath *audiopath = audiopath_obj->path;
return sprintf(buf, "%d.%d.%d\n", audiopath->version[0],
audiopath->version[1], audiopath->version[2]);
}
-static struct avirt_audiopath_attribute avirt_audiopath_attrs[] = {
+static struct snd_avirt_audiopath_attribute snd_avirt_audiopath_attrs[] = {
__ATTR_RO(audiopath_name),
__ATTR_RO(audiopath_version),
};
-static struct attribute *avirt_audiopath_def_attrs[] = {
- &avirt_audiopath_attrs[0].attr,
- &avirt_audiopath_attrs[1].attr,
+static struct attribute *snd_avirt_audiopath_def_attrs[] = {
+ &snd_avirt_audiopath_attrs[0].attr,
+ &snd_avirt_audiopath_attrs[1].attr,
NULL,
};
-static struct kobj_type avirt_audiopath_ktype = {
- .sysfs_ops = &avirt_audiopath_sysfs_ops,
- .release = avirt_audiopath_release,
- .default_attrs = avirt_audiopath_def_attrs,
+static struct kobj_type snd_avirt_audiopath_ktype = {
+ .sysfs_ops = &snd_avirt_audiopath_sysfs_ops,
+ .release = snd_avirt_audiopath_release,
+ .default_attrs = snd_avirt_audiopath_def_attrs,
};
/**
- * create_avirt_audiopath_obj - creates an Audio Path object
+ * create_snd_avirt_audiopath_obj - creates an Audio Path object
* @uid: Unique ID of the Audio Path
*
* This creates an Audio Path object and assigns the kset and registers
* it with sysfs.
* @return: Pointer to the Audio Path object or NULL if it failed.
*/
-static struct avirt_audiopath_obj *create_avirt_audiopath_obj(const char *uid)
+static struct snd_avirt_audiopath_obj *
+ create_snd_avirt_audiopath_obj(const char *uid)
{
- struct avirt_audiopath_obj *avirt_audiopath;
+ struct snd_avirt_audiopath_obj *snd_avirt_audiopath;
int retval;
- avirt_audiopath = kzalloc(sizeof(*avirt_audiopath), GFP_KERNEL);
- if (!avirt_audiopath)
+ snd_avirt_audiopath = kzalloc(sizeof(*snd_avirt_audiopath), GFP_KERNEL);
+ if (!snd_avirt_audiopath)
return NULL;
- avirt_audiopath->kobj.kset = avirt_audiopath_kset;
- retval = kobject_init_and_add(&avirt_audiopath->kobj,
- &avirt_audiopath_ktype, kobj, "%s", uid);
+ snd_avirt_audiopath->kobj.kset = snd_avirt_audiopath_kset;
+ retval = kobject_init_and_add(&snd_avirt_audiopath->kobj,
+ &snd_avirt_audiopath_ktype, kobj, "%s",
+ uid);
if (retval) {
- kobject_put(&avirt_audiopath->kobj);
+ kobject_put(&snd_avirt_audiopath->kobj);
return NULL;
}
- kobject_uevent(&avirt_audiopath->kobj, KOBJ_ADD);
- return avirt_audiopath;
+ kobject_uevent(&snd_avirt_audiopath->kobj, KOBJ_ADD);
+ return snd_avirt_audiopath;
}
-static struct snd_pcm *pcm_create(struct avirt_stream *stream)
+static struct snd_pcm *pcm_create(struct snd_avirt_stream *stream)
{
bool playback = false, capture = false;
struct snd_pcm *pcm;
@@ -224,25 +227,24 @@ static struct snd_pcm *pcm_create(struct avirt_stream *stream)
}
/**
- * destroy_avirt_audiopath_obj - destroys an Audio Path object
+ * destroy_snd_avirt_audiopath_obj - destroys an Audio Path object
* @name: the Audio Path object
*/
-static void destroy_avirt_audiopath_obj(struct avirt_audiopath_obj *p)
+static void destroy_snd_avirt_audiopath_obj(struct snd_avirt_audiopath_obj *p)
{
kobject_put(&p->kobj);
}
/**
- * avirt_audiopath_get - retrieves the Audio Path by its UID
+ * snd_avirt_audiopath_get - retrieves the Audio Path by its UID
* @uid: Unique ID for the Audio Path
* @return: Corresponding Audio Path
*/
-struct avirt_audiopath *avirt_audiopath_get(const char *uid)
+struct snd_avirt_audiopath *snd_avirt_audiopath_get(const char *uid)
{
- struct avirt_audiopath_obj *ap_obj;
+ struct snd_avirt_audiopath_obj *ap_obj;
- list_for_each_entry(ap_obj, &audiopath_list, list)
- {
+ list_for_each_entry(ap_obj, &audiopath_list, list) {
// pr_info("get_ap %s\n", ap_obj->path->uid);
if (!strcmp(ap_obj->path->uid, uid))
return ap_obj->path;
@@ -252,22 +254,22 @@ struct avirt_audiopath *avirt_audiopath_get(const char *uid)
}
/**
- * avirt_audiopath_register - register Audio Path with ALSA virtual driver
+ * snd_avirt_audiopath_register - register Audio Path with AVIRT
* @audiopath: Audio Path to be registered
* @core: ALSA virtual driver core info
* @return: 0 on success or error code otherwise
*/
-int avirt_audiopath_register(struct avirt_audiopath *audiopath,
- struct avirt_coreinfo **info)
+int snd_avirt_audiopath_register(struct snd_avirt_audiopath *audiopath,
+ struct snd_avirt_coreinfo **info)
{
- struct avirt_audiopath_obj *audiopath_obj;
+ struct snd_avirt_audiopath_obj *audiopath_obj;
if (!audiopath) {
D_ERRORK("Audio Path is NULL!");
return -EINVAL;
}
- audiopath_obj = create_avirt_audiopath_obj(audiopath->uid);
+ audiopath_obj = create_snd_avirt_audiopath_obj(audiopath->uid);
if (!audiopath_obj) {
D_INFOK("Failed to alloc driver object");
return -ENOMEM;
@@ -288,16 +290,16 @@ int avirt_audiopath_register(struct avirt_audiopath *audiopath,
return 0;
}
-EXPORT_SYMBOL_GPL(avirt_audiopath_register);
+EXPORT_SYMBOL_GPL(snd_avirt_audiopath_register);
/**
- * avirt_audiopath_deregister - deregister Audio Path with ALSA virtual driver
+ * snd_avirt_audiopath_deregister - deregister Audio Path with AVIRT
* @audiopath: Audio Path to be deregistered
* @return: 0 on success or error code otherwise
*/
-int avirt_audiopath_deregister(struct avirt_audiopath *audiopath)
+int snd_avirt_audiopath_deregister(struct snd_avirt_audiopath *audiopath)
{
- struct avirt_audiopath_obj *audiopath_obj;
+ struct snd_avirt_audiopath_obj *audiopath_obj;
// Check if audio path is registered
if (!audiopath) {
@@ -312,32 +314,31 @@ int avirt_audiopath_deregister(struct avirt_audiopath *audiopath)
}
list_del(&audiopath_obj->list);
- destroy_avirt_audiopath_obj(audiopath_obj);
+ destroy_snd_avirt_audiopath_obj(audiopath_obj);
D_INFOK("Deregistered Audio Path %s", audiopath->uid);
return 0;
}
-EXPORT_SYMBOL_GPL(avirt_audiopath_deregister);
+EXPORT_SYMBOL_GPL(snd_avirt_audiopath_deregister);
/**
- * avirt_stream_count - get the stream count for the given direction
+ * snd_avirt_stream_count - get the stream count for the given direction
* @direction: The direction to get the stream count for
* @return: The stream count
*/
-int avirt_stream_count(unsigned int direction)
+int snd_avirt_stream_count(unsigned int direction)
{
struct list_head *entry;
struct config_item *item;
- struct avirt_stream *stream;
+ struct snd_avirt_stream *stream;
unsigned int count = 0;
if (direction > 1)
return -ERANGE;
- list_for_each(entry, &core.stream_group->cg_children)
- {
+ list_for_each(entry, &core.stream_group->cg_children) {
item = container_of(entry, struct config_item, ci_entry);
- stream = avirt_stream_from_config_item(item);
+ stream = snd_avirt_stream_from_config_item(item);
if (!stream)
return -EFAULT;
if (stream->direction == direction)
@@ -346,18 +347,19 @@ int avirt_stream_count(unsigned int direction)
return count;
}
-EXPORT_SYMBOL_GPL(avirt_stream_count);
+EXPORT_SYMBOL_GPL(snd_avirt_stream_count);
/**
- * __avirt_stream_create - Create audio stream, including it's ALSA PCM device
+ * snd_avirt_stream_create - Create audio stream, including it's ALSA PCM device
* @name: The name designated to the audio stream
* @direction: The PCM direction (SNDRV_PCM_STREAM_PLAYBACK or
* SNDRV_PCM_STREAM_CAPTURE)
* @return: The newly created audio stream if successful, or an error pointer
*/
-struct avirt_stream *__avirt_stream_create(const char *name, int direction)
+struct snd_avirt_stream *snd_avirt_stream_create(const char *name,
+ int direction)
{
- struct avirt_stream *stream;
+ struct snd_avirt_stream *stream;
stream = kzalloc(sizeof(*stream), GFP_KERNEL);
if (!stream)
@@ -374,11 +376,11 @@ struct avirt_stream *__avirt_stream_create(const char *name, int direction)
return stream;
}
-int __avirt_streams_seal(void)
+int snd_avirt_streams_seal(void)
{
int err = 0;
- struct avirt_audiopath_obj *ap_obj;
- struct avirt_stream *stream;
+ struct snd_avirt_audiopath_obj *ap_obj;
+ struct snd_avirt_stream *stream;
struct config_item *item;
struct list_head *entry;
@@ -387,9 +389,9 @@ int __avirt_streams_seal(void)
return -1;
}
- list_for_each (entry, &core.stream_group->cg_children) {
+ list_for_each(entry, &core.stream_group->cg_children) {
item = container_of(entry, struct config_item, ci_entry);
- stream = avirt_stream_from_config_item(item);
+ stream = snd_avirt_stream_from_config_item(item);
if (!stream)
return -EFAULT;
stream->pcm = pcm_create(stream);
@@ -397,7 +399,7 @@ int __avirt_streams_seal(void)
return (PTR_ERR(stream->pcm));
}
- list_for_each_entry (ap_obj, &audiopath_list, list) {
+ list_for_each_entry(ap_obj, &audiopath_list, list) {
D_INFOK("configure() AP uid: %s", ap_obj->path->uid);
ap_obj->path->configure(core.card, core.stream_group,
core.stream_count);
@@ -414,14 +416,14 @@ int __avirt_streams_seal(void)
return err;
}
-bool __avirt_streams_sealed(void)
+bool snd_avirt_streams_sealed(void)
{
return core.streams_sealed;
}
-struct avirt_stream *__avirt_stream_find_by_device(unsigned int device)
+struct snd_avirt_stream *snd_avirt_stream_find_by_device(unsigned int device)
{
- struct avirt_stream *stream;
+ struct snd_avirt_stream *stream;
struct config_item *item;
struct list_head *entry;
@@ -430,10 +432,9 @@ struct avirt_stream *__avirt_stream_find_by_device(unsigned int device)
return ERR_PTR(-EINVAL);
}
- list_for_each(entry, &core.stream_group->cg_children)
- {
+ list_for_each(entry, &core.stream_group->cg_children) {
item = container_of(entry, struct config_item, ci_entry);
- stream = avirt_stream_from_config_item(item);
+ stream = snd_avirt_stream_from_config_item(item);
if (!stream)
return ERR_PTR(-EFAULT);
if (stream->device == device)
@@ -478,14 +479,14 @@ static int __init core_init(void)
strncpy(core.card->longname, "A virtual sound card driver for ALSA",
80);
- avirt_audiopath_kset =
+ snd_avirt_audiopath_kset =
kset_create_and_add("audiopaths", NULL, &core.dev->kobj);
- if (!avirt_audiopath_kset) {
+ if (!snd_avirt_audiopath_kset) {
err = -ENOMEM;
goto exit_snd_card;
}
- err = __avirt_configfs_init(&core);
+ err = snd_avirt_configfs_init(&core);
if (err < 0)
goto exit_snd_card;
@@ -506,9 +507,9 @@ exit_class:
*/
static void __exit core_exit(void)
{
- __avirt_configfs_exit(&core);
+ snd_avirt_configfs_exit(&core);
- kset_unregister(avirt_audiopath_kset);
+ kset_unregister(snd_avirt_audiopath_kset);
snd_card_free(core.card);
device_destroy(core.avirt_class, 0);
class_destroy(core.avirt_class);