summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--alsa-pcm.c19
-rwxr-xr-xalsa.c79
-rwxr-xr-xalsa.h43
-rw-r--r--core.c13
-rw-r--r--core.h38
5 files changed, 69 insertions, 123 deletions
diff --git a/alsa-pcm.c b/alsa-pcm.c
index faa7a83..17255df 100644
--- a/alsa-pcm.c
+++ b/alsa-pcm.c
@@ -7,7 +7,6 @@
* Copyright (C) 2010-2018 Fiberdyne Systems Pty Ltd
*/
-#include "core.h"
#include "alsa.h"
#define AP_LOGNAME "CORE"
@@ -30,9 +29,9 @@
*/
static int configure_pcm(struct snd_pcm_substream *substream)
{
- struct avirt_alsa_dev_config *config;
+ struct avirt_alsa_devconfig *config;
struct avirt_audiopath *audiopath;
- struct avirt_alsa_dev_group *group;
+ struct avirt_alsa_group *group;
struct snd_pcm_hardware *hw;
unsigned bytes_per_sample = 0, blocksize = 0;
@@ -55,7 +54,7 @@ static int configure_pcm(struct snd_pcm_substream *substream)
}
// Get device group (playback/capture)
- group = avirt_alsa_get_dev_group(substream->stream);
+ group = avirt_alsa_get_group(substream->stream);
CHK_NULL(group);
// Check if substream id is valid
@@ -135,11 +134,9 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
int channels, err;
size_t bufsz;
struct avirt_audiopath *audiopath;
- struct avirt_alsa_dev_group *group;
+ struct avirt_alsa_group *group;
- DINFO(AP_LOGNAME, "");
-
- group = avirt_alsa_get_dev_group(substream->stream);
+ group = avirt_alsa_get_group(substream->stream);
CHK_NULL(group);
channels = group->config[substream->pcm->device].channels;
@@ -270,11 +267,9 @@ static int pcm_get_time_info(
struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
struct snd_pcm_audio_tstamp_report *audio_tstamp_report)
{
- struct avirt_alsa_dev_group *group;
-
- DINFO(AP_LOGNAME, "");
+ struct avirt_alsa_group *group;
- group = avirt_alsa_get_dev_group(substream->stream);
+ group = avirt_alsa_get_group(substream->stream);
CHK_NULL(group);
DO_AUDIOPATH_CB(get_time_info, substream, system_ts, audio_ts,
diff --git a/alsa.c b/alsa.c
index 045624b..dd00ddb 100755
--- a/alsa.c
+++ b/alsa.c
@@ -12,10 +12,10 @@
#include <sound/initval.h>
#include "alsa.h"
-#include "core.h"
-static struct avirt_alsa_driver *_driver = NULL;
+extern struct avirt_coreinfo coreinfo;
+static struct snd_card *card = NULL;
extern struct snd_pcm_ops pcm_ops;
/**
@@ -29,29 +29,29 @@ static int pcm_constructor(struct snd_card *card)
int i;
// Allocate Playback PCM instances
- for (i = 0; i < _driver->playback.devices; i++) {
+ for (i = 0; i < coreinfo.playback.devices; i++) {
CHK_ERR(snd_pcm_new(card,
- _driver->playback.config[i].devicename, i,
- 1, 1, &pcm));
+ coreinfo.playback.config[i].devicename, i,
+ 1, 0, &pcm));
/** Register driver callbacks */
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &pcm_ops);
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pcm_ops);
pcm->info_flags = 0;
- strcpy(pcm->name, _driver->playback.config[i].devicename);
+ strcpy(pcm->name, coreinfo.playback.config[i].devicename);
}
// Allocate Capture PCM instances
- for (i = 0; i < _driver->capture.devices; i++) {
- CHK_ERR(snd_pcm_new(card, _driver->capture.config[i].devicename,
+ for (i = 0; i < coreinfo.capture.devices; i++) {
+ CHK_ERR(snd_pcm_new(card, coreinfo.capture.config[i].devicename,
i, 0, 1, &pcm));
/** Register driver callbacks */
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pcm_ops);
pcm->info_flags = 0;
- strcpy(pcm->name, _driver->capture.config[i].devicename);
+ strcpy(pcm->name, coreinfo.capture.config[i].devicename);
}
return 0;
@@ -61,35 +61,31 @@ static int pcm_constructor(struct snd_card *card)
* alloc_dev_config - Allocates memory for ALSA device configuration
* @return: 0 on success or error code otherwise
*/
-static int alloc_dev_config(struct avirt_alsa_dev_config **devconfig,
- struct avirt_alsa_dev_config *userconfig,
+static int alloc_dev_config(struct avirt_alsa_devconfig **devconfig,
+ struct avirt_alsa_devconfig *userconfig,
unsigned numdevices)
{
if (numdevices == 0)
return 0;
- *devconfig = kzalloc(sizeof(struct avirt_alsa_dev_config) * numdevices,
+ *devconfig = kzalloc(sizeof(struct avirt_alsa_devconfig) * numdevices,
GFP_KERNEL);
if (!(*devconfig))
return -ENOMEM;
memcpy(*devconfig, userconfig,
- sizeof(struct avirt_alsa_dev_config) * numdevices);
+ sizeof(struct avirt_alsa_devconfig) * numdevices);
return 0;
}
-struct avirt_alsa_dev_group *avirt_alsa_get_dev_group(int direction)
+struct avirt_alsa_group *avirt_alsa_get_group(int direction)
{
- if (!_driver) {
- pr_err("[%s] _driver is NULL", __func__);
- return NULL;
- }
-
switch (direction) {
case SNDRV_PCM_STREAM_PLAYBACK:
+ return &coreinfo.playback;
case SNDRV_PCM_STREAM_CAPTURE:
- return &_driver->playback;
+ return &coreinfo.capture;
default:
pr_err("[%s] Direction must be SNDRV_PCM_STREAM_XXX!",
__func__);
@@ -98,32 +94,18 @@ struct avirt_alsa_dev_group *avirt_alsa_get_dev_group(int direction)
}
/**
- * avirt_alsa_init - Initializes the ALSA driver
- * @return: 0 on success or error code otherwise
- */
-int avirt_alsa_init()
-{
- // Allocate memory for the driver
- _driver = kzalloc(sizeof(struct avirt_alsa_driver), GFP_KERNEL);
- if (!_driver)
- return -ENOMEM;
-
- return 0;
-}
-
-/**
* avirt_alsa_configure_pcm- Configure the PCM device
* @config: Device configuration structure array
* @direction: Direction of PCM (SNDRV_PCM_STREAM_XXX)
* @numdevices: Number of devices (array length)
* @return: 0 on success or error code otherwise
*/
-int avirt_alsa_configure_pcm(struct avirt_alsa_dev_config *config,
- int direction, unsigned numdevices)
+int avirt_alsa_configure_pcm(struct avirt_alsa_devconfig *config, int direction,
+ unsigned numdevices)
{
- struct avirt_alsa_dev_group *group;
+ struct avirt_alsa_group *group;
- group = avirt_alsa_get_dev_group(direction);
+ group = avirt_alsa_get_group(direction);
CHK_NULL(group);
CHK_ERR(alloc_dev_config(&group->config, config, numdevices));
@@ -140,12 +122,8 @@ int avirt_alsa_configure_pcm(struct avirt_alsa_dev_config *config,
*/
int avirt_alsa_register(struct platform_device *devptr)
{
- struct snd_card *card;
static struct snd_device_ops device_ops;
- if (!_driver)
- return -EFAULT;
-
// Create the card instance
CHK_ERR_V(snd_card_new(&devptr->dev, SNDRV_DEFAULT_IDX1, "avirt",
THIS_MODULE, 0, &card),
@@ -154,10 +132,9 @@ int avirt_alsa_register(struct platform_device *devptr)
strcpy(card->driver, "avirt-alsa-device");
strcpy(card->shortname, "avirt");
strcpy(card->longname, "A virtual sound card driver for ALSA");
- _driver->card = card;
// Create new sound device
- CHK_ERR_V((snd_device_new(card, SNDRV_DEV_LOWLEVEL, _driver,
+ CHK_ERR_V((snd_device_new(card, SNDRV_DEV_LOWLEVEL, &coreinfo,
&device_ops)),
"Failed to create sound device");
@@ -176,14 +153,12 @@ int avirt_alsa_register(struct platform_device *devptr)
*/
int avirt_alsa_deregister(void)
{
- CHK_NULL(_driver->card);
- snd_card_free(_driver->card);
- CHK_NULL(_driver->playback.config);
- kfree(_driver->playback.config);
- CHK_NULL(_driver->capture.config);
- kfree(_driver->capture.config);
- CHK_NULL(_driver);
- kfree(_driver);
+ CHK_NULL(card);
+ snd_card_free(card);
+ CHK_NULL(coreinfo.playback.config);
+ kfree(coreinfo.playback.config);
+ CHK_NULL(coreinfo.capture.config);
+ kfree(coreinfo.capture.config);
return 0;
}
diff --git a/alsa.h b/alsa.h
index 2e79d33..815dd65 100755
--- a/alsa.h
+++ b/alsa.h
@@ -10,11 +10,11 @@
#ifndef __AVIRT_ALSA_H__
#define __AVIRT_ALSA_H__
+#include "core.h"
+
#include <linux/platform_device.h>
#include <sound/pcm.h>
-#define MAX_NAME_LEN 32
-
#define PRINT_ERR(errno, errmsg, ...) \
pr_err("[%s()] %s [ERRNO:%d]", __func__, errmsg, ##__VA_ARGS__, errno);
@@ -46,37 +46,6 @@
} \
} while (0)
-/*
- * Substream device configuration
- */
-struct avirt_alsa_dev_config {
- const char devicename[MAX_NAME_LEN];
- int channels;
-};
-
-/**
- * Collection of devices
- */
-struct avirt_alsa_dev_group {
- struct avirt_alsa_dev_config *config;
- int devices;
-};
-
-/**
- * ALSA driver data
- */
-struct avirt_alsa_driver {
- struct snd_card *card;
- struct avirt_alsa_dev_group playback;
- struct avirt_alsa_dev_group capture;
-};
-
-/**
- * avirt_alsa_init - Initializes the ALSA driver
- * @return: 0 on success or error code otherwise
- */
-int avirt_alsa_init(void);
-
/**
* avirt_alsa_configure_pcm- Configure the PCM device
* @config: Device configuration structure array
@@ -84,8 +53,8 @@ int avirt_alsa_init(void);
* @numdevices: Number of devices (array length)
* @return: 0 on success or error code otherwise
*/
-int avirt_alsa_configure_pcm(struct avirt_alsa_dev_config *config,
- int direction, unsigned numdevices);
+int avirt_alsa_configure_pcm(struct avirt_alsa_devconfig *config, int direction,
+ unsigned numdevices);
/**
* avirt_alsa_register - Registers the ALSA driver
@@ -102,12 +71,12 @@ int avirt_alsa_register(struct platform_device *devptr);
int avirt_alsa_deregister(void);
/**
- * avirt_alsa_get_dev_group - Gets the device group for the specified direction
+ * avirt_alsa_get_group - Gets the device group for the specified direction
* @direction: SNDRV_PCM_STREAM_PLAYBACK or SNDRV_PCM_STREAM_CAPTURE
* @return: Either the playback or capture device group on success,
* or NULL otherwise
*/
-struct avirt_alsa_dev_group *avirt_alsa_get_dev_group(int direction);
+struct avirt_alsa_group *avirt_alsa_get_group(int direction);
/**
* pcm_buff_complete_cb - PCM buffer complete callback
diff --git a/core.c b/core.c
index 996a452..4b6b5af 100644
--- a/core.c
+++ b/core.c
@@ -65,7 +65,7 @@ static struct avirt_core {
struct platform_device *platform_dev;
} core;
-static struct avirt_coreinfo coreinfo = {
+struct avirt_coreinfo coreinfo = {
.version = { 0, 0, 1 },
.pcm_buff_complete = pcm_buff_complete_cb,
};
@@ -79,8 +79,8 @@ static LIST_HEAD(audiopath_list);
*/
static int avirt_probe(struct platform_device *devptr)
{
- // struct avirt_alsa_dev_config capture_config[MAX_PCM_DEVS];
- struct avirt_alsa_dev_config playback_config[MAX_PCM_DEVS];
+ // struct avirt_alsa_devconfig capture_config[MAX_PCM_DEVS];
+ struct avirt_alsa_devconfig playback_config[MAX_PCM_DEVS];
int err = 0, i = 0;
if (playback_num == 0 && capture_num == 0) {
@@ -88,13 +88,6 @@ static int avirt_probe(struct platform_device *devptr)
return -EINVAL;
}
- coreinfo.playback_num = playback_num;
- coreinfo.capture_num = capture_num;
-
- err = avirt_alsa_init();
- if (err < 0)
- return err;
-
// Set up playback
for (i = 0; i < playback_num; i++) {
if (!playback_names[i]) {
diff --git a/core.h b/core.h
index a31c916..de428c2 100644
--- a/core.h
+++ b/core.h
@@ -12,16 +12,7 @@
#include <sound/pcm.h>
-#define DINFO(ap, fmt, args...) \
- printk(KERN_INFO "[%s]: %d:%s " fmt "\n", ap, __LINE__, __func__, \
- ##args)
-
-#define DERROR(ap, fmt, args...) \
- printk(KERN_ERR "[%s]: %d:%s " fmt "\n", ap, __LINE__, __func__, ##args)
-
-#define DPRINT(ap, fmt, args...) \
- printk(KERN_DEBUG "[%s]: %d:%s " fmt "\n", ap, __LINE__, __func__, \
- ##args)
+#define MAX_NAME_LEN 32
/**
* PCM buffer complete callback
@@ -31,6 +22,9 @@
*/
typedef int (*avirt_buff_complete)(struct snd_pcm_substream *substream);
+/**
+ * AVIRT Audio Path info
+ */
struct avirt_audiopath {
const char *name;
unsigned version[3];
@@ -41,10 +35,30 @@ struct avirt_audiopath {
void *context;
};
+/*
+ * ALSA Substream device configuration
+ */
+struct avirt_alsa_devconfig {
+ const char devicename[MAX_NAME_LEN];
+ int channels;
+};
+
+/**
+ * Collection of ALSA devices
+ */
+struct avirt_alsa_group {
+ struct avirt_alsa_devconfig *config;
+ int devices;
+};
+
+/**
+ * AVIRT core info
+ */
struct avirt_coreinfo {
unsigned version[3];
- unsigned playback_num;
- unsigned capture_num;
+
+ struct avirt_alsa_group playback;
+ struct avirt_alsa_group capture;
avirt_buff_complete pcm_buff_complete;
};