Blame src/hwdep/hwdep.c

Packit 4a16fb
/**
Packit 4a16fb
 * \file hwdep/hwdep.c
Packit 4a16fb
 * \brief HwDep Interface (hardware dependent)
Packit 4a16fb
 * \author Jaroslav Kysela <perex@perex.cz>
Packit 4a16fb
 * \date 2000-2001
Packit 4a16fb
 *
Packit 4a16fb
 * HwDep (hardware dependent) Interface is designed for individual hardware
Packit 4a16fb
 * access. This interface does not cover any API specification.
Packit 4a16fb
 */
Packit 4a16fb
/*
Packit 4a16fb
 *  Hardware dependent Interface - main file
Packit 4a16fb
 *  Copyright (c) 2000 by Jaroslav Kysela <perex@perex.cz>
Packit 4a16fb
 *
Packit 4a16fb
 *
Packit 4a16fb
 *   This library is free software; you can redistribute it and/or modify
Packit 4a16fb
 *   it under the terms of the GNU Lesser General Public License as
Packit 4a16fb
 *   published by the Free Software Foundation; either version 2.1 of
Packit 4a16fb
 *   the License, or (at your option) any later version.
Packit 4a16fb
 *
Packit 4a16fb
 *   This program is distributed in the hope that it will be useful,
Packit 4a16fb
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 4a16fb
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 4a16fb
 *   GNU Lesser General Public License for more details.
Packit 4a16fb
 *
Packit 4a16fb
 *   You should have received a copy of the GNU Lesser General Public
Packit 4a16fb
 *   License along with this library; if not, write to the Free Software
Packit 4a16fb
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit 4a16fb
 *
Packit 4a16fb
 */
Packit 4a16fb
Packit 4a16fb
#include <stdio.h>
Packit 4a16fb
#include <stdlib.h>
Packit 4a16fb
#include <unistd.h>
Packit 4a16fb
#include <string.h>
Packit 4a16fb
#include <fcntl.h>
Packit 4a16fb
#include <sys/ioctl.h>
Packit 4a16fb
#include "hwdep_local.h"
Packit 4a16fb
Packit 4a16fb
static int snd_hwdep_open_conf(snd_hwdep_t **hwdep,
Packit 4a16fb
			       const char *name, snd_config_t *hwdep_root,
Packit 4a16fb
			       snd_config_t *hwdep_conf, int mode)
Packit 4a16fb
{
Packit 4a16fb
	const char *str;
Packit 4a16fb
	char buf[256], errbuf[256];
Packit 4a16fb
	int err;
Packit 4a16fb
	snd_config_t *conf, *type_conf = NULL;
Packit 4a16fb
	snd_config_iterator_t i, next;
Packit 4a16fb
	const char *id;
Packit 4a16fb
	const char *lib = NULL, *open_name = NULL;
Packit 4a16fb
	int (*open_func)(snd_hwdep_t **, const char *, snd_config_t *, snd_config_t *, int) = NULL;
Packit 4a16fb
#ifndef PIC
Packit 4a16fb
	extern void *snd_hwdep_open_symbols(void);
Packit 4a16fb
#endif
Packit 4a16fb
	void *h = NULL;
Packit 4a16fb
	if (snd_config_get_type(hwdep_conf) != SND_CONFIG_TYPE_COMPOUND) {
Packit 4a16fb
		if (name)
Packit 4a16fb
			SNDERR("Invalid type for HWDEP %s definition", name);
Packit 4a16fb
		else
Packit 4a16fb
			SNDERR("Invalid type for HWDEP definition");
Packit 4a16fb
		return -EINVAL;
Packit 4a16fb
	}
Packit 4a16fb
	err = snd_config_search(hwdep_conf, "type", &conf;;
Packit 4a16fb
	if (err < 0) {
Packit 4a16fb
		SNDERR("type is not defined");
Packit 4a16fb
		return err;
Packit 4a16fb
	}
Packit 4a16fb
	err = snd_config_get_id(conf, &id;;
Packit 4a16fb
	if (err < 0) {
Packit 4a16fb
		SNDERR("unable to get id");
Packit 4a16fb
		return err;
Packit 4a16fb
	}
Packit 4a16fb
	err = snd_config_get_string(conf, &str);
Packit 4a16fb
	if (err < 0) {
Packit 4a16fb
		SNDERR("Invalid type for %s", id);
Packit 4a16fb
		return err;
Packit 4a16fb
	}
Packit 4a16fb
	err = snd_config_search_definition(hwdep_root, "hwdep_type", str, &type_conf);
Packit 4a16fb
	if (err >= 0) {
Packit 4a16fb
		if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
Packit 4a16fb
			SNDERR("Invalid type for HWDEP type %s definition", str);
Packit 4a16fb
			err = -EINVAL;
Packit 4a16fb
			goto _err;
Packit 4a16fb
		}
Packit 4a16fb
		snd_config_for_each(i, next, type_conf) {
Packit 4a16fb
			snd_config_t *n = snd_config_iterator_entry(i);
Packit 4a16fb
			const char *id;
Packit 4a16fb
			if (snd_config_get_id(n, &id) < 0)
Packit 4a16fb
				continue;
Packit 4a16fb
			if (strcmp(id, "comment") == 0)
Packit 4a16fb
				continue;
Packit 4a16fb
			if (strcmp(id, "lib") == 0) {
Packit 4a16fb
				err = snd_config_get_string(n, &lib);
Packit 4a16fb
				if (err < 0) {
Packit 4a16fb
					SNDERR("Invalid type for %s", id);
Packit 4a16fb
					goto _err;
Packit 4a16fb
				}
Packit 4a16fb
				continue;
Packit 4a16fb
			}
Packit 4a16fb
			if (strcmp(id, "open") == 0) {
Packit 4a16fb
				err = snd_config_get_string(n, &open_name);
Packit 4a16fb
				if (err < 0) {
Packit 4a16fb
					SNDERR("Invalid type for %s", id);
Packit 4a16fb
					goto _err;
Packit 4a16fb
				}
Packit 4a16fb
				continue;
Packit 4a16fb
			}
Packit 4a16fb
			SNDERR("Unknown field %s", id);
Packit 4a16fb
			err = -EINVAL;
Packit 4a16fb
			goto _err;
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
	if (!open_name) {
Packit 4a16fb
		open_name = buf;
Packit 4a16fb
		snprintf(buf, sizeof(buf), "_snd_hwdep_%s_open", str);
Packit 4a16fb
	}
Packit 4a16fb
#ifndef PIC
Packit 4a16fb
	snd_hwdep_open_symbols();
Packit 4a16fb
#endif
Packit 4a16fb
	h = INTERNAL(snd_dlopen)(lib, RTLD_NOW, errbuf, sizeof(errbuf));
Packit 4a16fb
	if (h)
Packit 4a16fb
		open_func = snd_dlsym(h, open_name, SND_DLSYM_VERSION(SND_HWDEP_DLSYM_VERSION));
Packit 4a16fb
	err = 0;
Packit 4a16fb
	if (!h) {
Packit 4a16fb
		SNDERR("Cannot open shared library %s (%s)", lib, errbuf);
Packit 4a16fb
		err = -ENOENT;
Packit 4a16fb
	} else if (!open_func) {
Packit 4a16fb
		SNDERR("symbol %s is not defined inside %s", open_name, lib);
Packit 4a16fb
		snd_dlclose(h);
Packit 4a16fb
		err = -ENXIO;
Packit 4a16fb
	}
Packit 4a16fb
       _err:
Packit 4a16fb
	if (type_conf)
Packit 4a16fb
		snd_config_delete(type_conf);
Packit 4a16fb
	if (err >= 0) {
Packit 4a16fb
		err = open_func(hwdep, name, hwdep_root, hwdep_conf, mode);
Packit 4a16fb
		if (err >= 0) {
Packit 4a16fb
			(*hwdep)->dl_handle = h;
Packit 4a16fb
		} else {
Packit 4a16fb
			snd_dlclose(h);
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
	return err;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_hwdep_open_noupdate(snd_hwdep_t **hwdep, snd_config_t *root, const char *name, int mode)
Packit 4a16fb
{
Packit 4a16fb
	int err;
Packit 4a16fb
	snd_config_t *hwdep_conf;
Packit 4a16fb
	err = snd_config_search_definition(root, "hwdep", name, &hwdep_conf);
Packit 4a16fb
	if (err < 0) {
Packit 4a16fb
		SNDERR("Unknown HwDep %s", name);
Packit 4a16fb
		return err;
Packit 4a16fb
	}
Packit 4a16fb
	err = snd_hwdep_open_conf(hwdep, name, root, hwdep_conf, mode);
Packit 4a16fb
	snd_config_delete(hwdep_conf);
Packit 4a16fb
	return err;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief Opens a new connection to the HwDep interface.
Packit 4a16fb
 * \param hwdep Returned handle (NULL if not wanted)
Packit 4a16fb
 * \param name ASCII identifier of the HwDep handle
Packit 4a16fb
 * \param mode Open mode
Packit 4a16fb
 * \return 0 on success otherwise a negative error code
Packit 4a16fb
 *
Packit 4a16fb
 * Opens a new connection to the HwDep interface specified with
Packit 4a16fb
 * an ASCII identifier and mode.
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_open(snd_hwdep_t **hwdep, const char *name, int mode)
Packit 4a16fb
{
Packit 4a16fb
	snd_config_t *top;
Packit 4a16fb
	int err;
Packit 4a16fb
Packit 4a16fb
	assert(hwdep && name);
Packit 4a16fb
	err = snd_config_update_ref(&top);
Packit 4a16fb
	if (err < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	err = snd_hwdep_open_noupdate(hwdep, top, name, mode);
Packit 4a16fb
	snd_config_unref(top);
Packit 4a16fb
	return err;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief Opens a new connection to the HwDep interface using local configuration
Packit 4a16fb
 * \param hwdep Returned handle (NULL if not wanted)
Packit 4a16fb
 * \param name ASCII identifier of the HwDep handle
Packit 4a16fb
 * \param mode Open mode
Packit 4a16fb
 * \param lconf The local configuration tree
Packit 4a16fb
 * \return 0 on success otherwise a negative error code
Packit 4a16fb
 *
Packit 4a16fb
 * Opens a new connection to the HwDep interface specified with
Packit 4a16fb
 * an ASCII identifier and mode.
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_open_lconf(snd_hwdep_t **hwdep, const char *name,
Packit 4a16fb
			 int mode, snd_config_t *lconf)
Packit 4a16fb
{
Packit 4a16fb
	assert(hwdep && name && lconf);
Packit 4a16fb
	return snd_hwdep_open_noupdate(hwdep, lconf, name, mode);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief close HwDep handle
Packit 4a16fb
 * \param hwdep HwDep handle
Packit 4a16fb
 * \return 0 on success otherwise a negative error code
Packit 4a16fb
 *
Packit 4a16fb
 * Closes the specified HwDep handle and frees all associated
Packit 4a16fb
 * resources.
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_close(snd_hwdep_t *hwdep)
Packit 4a16fb
{
Packit 4a16fb
	int err;
Packit 4a16fb
  	assert(hwdep);
Packit 4a16fb
	err = hwdep->ops->close(hwdep);
Packit 4a16fb
	if (hwdep->dl_handle)
Packit 4a16fb
		snd_dlclose(hwdep->dl_handle);
Packit 4a16fb
	free(hwdep->name);
Packit 4a16fb
	free(hwdep);
Packit 4a16fb
	return err;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get identifier of HwDep handle
Packit 4a16fb
 * \param hwdep a Hwdep handle
Packit 4a16fb
 * \return ascii identifier of HwDep handle
Packit 4a16fb
 *
Packit 4a16fb
 * Returns the ASCII identifier of given HwDep handle. It's the same
Packit 4a16fb
 * identifier specified in snd_hwdep_open().
Packit 4a16fb
 */
Packit 4a16fb
const char *snd_hwdep_name(snd_hwdep_t *hwdep)
Packit 4a16fb
{
Packit 4a16fb
	assert(hwdep);
Packit 4a16fb
	return hwdep->name;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get type of HwDep handle
Packit 4a16fb
 * \param hwdep a HwDep handle
Packit 4a16fb
 * \return type of HwDep handle
Packit 4a16fb
 *
Packit 4a16fb
 * Returns the type #snd_hwdep_type_t of given HwDep handle.
Packit 4a16fb
 */
Packit 4a16fb
snd_hwdep_type_t snd_hwdep_type(snd_hwdep_t *hwdep)
Packit 4a16fb
{
Packit 4a16fb
	assert(hwdep);
Packit 4a16fb
	return hwdep->type;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get count of poll descriptors for HwDep handle
Packit 4a16fb
 * \param hwdep HwDep handle
Packit 4a16fb
 * \return count of poll descriptors
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_poll_descriptors_count(snd_hwdep_t *hwdep)
Packit 4a16fb
{
Packit 4a16fb
	assert(hwdep);
Packit 4a16fb
	return 1;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get poll descriptors
Packit 4a16fb
 * \param hwdep HwDep handle
Packit 4a16fb
 * \param pfds array of poll descriptors
Packit 4a16fb
 * \param space space in the poll descriptor array
Packit 4a16fb
 * \return count of filled descriptors
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_poll_descriptors(snd_hwdep_t *hwdep, struct pollfd *pfds, unsigned int space)
Packit 4a16fb
{
Packit 4a16fb
	assert(hwdep);
Packit 4a16fb
	if (space >= 1) {
Packit 4a16fb
		pfds->fd = hwdep->poll_fd;
Packit 4a16fb
		switch (hwdep->mode & O_ACCMODE) {
Packit 4a16fb
		case O_WRONLY:
Packit 4a16fb
			pfds->events = POLLOUT|POLLERR|POLLNVAL;
Packit 4a16fb
			break;
Packit 4a16fb
		case O_RDONLY:
Packit 4a16fb
			pfds->events = POLLIN|POLLERR|POLLNVAL;
Packit 4a16fb
			break;
Packit 4a16fb
		case O_RDWR:
Packit 4a16fb
			pfds->events = POLLOUT|POLLIN|POLLERR|POLLNVAL;
Packit 4a16fb
			break;
Packit 4a16fb
		default:
Packit 4a16fb
			return -EIO;
Packit 4a16fb
		}
Packit 4a16fb
		return 1;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get returned events from poll descriptors
Packit 4a16fb
 * \param hwdep HwDep  handle
Packit 4a16fb
 * \param pfds array of poll descriptors
Packit 4a16fb
 * \param nfds count of poll descriptors
Packit 4a16fb
 * \param revents returned events
Packit 4a16fb
 * \return zero if success, otherwise a negative error code
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_poll_descriptors_revents(snd_hwdep_t *hwdep, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
Packit 4a16fb
{
Packit 4a16fb
        assert(hwdep && pfds && revents);
Packit 4a16fb
        if (nfds == 1) {
Packit 4a16fb
                *revents = pfds->revents;
Packit 4a16fb
                return 0;
Packit 4a16fb
        }
Packit 4a16fb
        return -EINVAL;
Packit 4a16fb
}                                                                       
Packit 4a16fb
                                                                       
Packit 4a16fb
/**
Packit 4a16fb
 * \brief set nonblock mode
Packit 4a16fb
 * \param hwdep HwDep handle
Packit 4a16fb
 * \param nonblock 0 = block, 1 = nonblock mode
Packit 4a16fb
 * \return 0 on success otherwise a negative error code
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_nonblock(snd_hwdep_t *hwdep, int nonblock)
Packit 4a16fb
{
Packit 4a16fb
	int err;
Packit 4a16fb
	assert(hwdep);
Packit 4a16fb
	if ((err = hwdep->ops->nonblock(hwdep, nonblock)) < 0)
Packit 4a16fb
		return err;
Packit 4a16fb
	if (nonblock)
Packit 4a16fb
		hwdep->mode |= SND_HWDEP_OPEN_NONBLOCK;
Packit 4a16fb
	else
Packit 4a16fb
		hwdep->mode &= ~SND_HWDEP_OPEN_NONBLOCK;
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get size of the snd_hwdep_info_t structure in bytes
Packit 4a16fb
 * \return size of the snd_hwdep_info_t structure in bytes
Packit 4a16fb
 */
Packit 4a16fb
size_t snd_hwdep_info_sizeof()
Packit 4a16fb
{
Packit 4a16fb
	return sizeof(snd_hwdep_info_t);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief allocate a new snd_hwdep_info_t structure
Packit 4a16fb
 * \param info returned pointer
Packit 4a16fb
 * \return 0 on success otherwise a negative error code if fails
Packit 4a16fb
 *
Packit 4a16fb
 * Allocates a new snd_hwdep_info_t structure using the standard
Packit 4a16fb
 * malloc C library function.
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_info_malloc(snd_hwdep_info_t **info)
Packit 4a16fb
{
Packit 4a16fb
	assert(info);
Packit 4a16fb
	*info = calloc(1, sizeof(snd_hwdep_info_t));
Packit 4a16fb
	if (!*info)
Packit 4a16fb
		return -ENOMEM;
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief frees the snd_hwdep_info_t structure
Packit 4a16fb
 * \param info pointer to the snd_hwdep_info_t structure to free
Packit 4a16fb
 *
Packit 4a16fb
 * Frees the given snd_hwdep_info_t structure using the standard
Packit 4a16fb
 * free C library function.
Packit 4a16fb
 */
Packit 4a16fb
void snd_hwdep_info_free(snd_hwdep_info_t *info)
Packit 4a16fb
{
Packit 4a16fb
	assert(info);
Packit 4a16fb
	free(info);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief copy one snd_hwdep_info_t structure to another
Packit 4a16fb
 * \param dst destination snd_hwdep_info_t structure
Packit 4a16fb
 * \param src source snd_hwdep_info_t structure
Packit 4a16fb
 */
Packit 4a16fb
void snd_hwdep_info_copy(snd_hwdep_info_t *dst, const snd_hwdep_info_t *src)
Packit 4a16fb
{
Packit 4a16fb
	assert(dst && src);
Packit 4a16fb
	*dst = *src;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get hwdep card number
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_info_t structure
Packit 4a16fb
 * \return hwdep card number
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_info_get_card(const snd_hwdep_info_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return obj->card;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get hwdep device number
Packit 4a16fb
 * \param info pointer to a snd_hwdep_info_t structure
Packit 4a16fb
 * \return hwdep device number
Packit 4a16fb
 */
Packit 4a16fb
unsigned int snd_hwdep_info_get_device(const snd_hwdep_info_t *info)
Packit 4a16fb
{
Packit 4a16fb
	assert(info);
Packit 4a16fb
	return info->device;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get hwdep driver identifier
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_info_t structure
Packit 4a16fb
 * \return hwdep driver identifier
Packit 4a16fb
 */
Packit 4a16fb
const char *snd_hwdep_info_get_id(const snd_hwdep_info_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return (const char *)obj->id;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get hwdep driver name
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_info_t structure
Packit 4a16fb
 * \return hwdep driver name
Packit 4a16fb
 */
Packit 4a16fb
const char *snd_hwdep_info_get_name(const snd_hwdep_info_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return (const char *)obj->name;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get hwdep protocol interface
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_info_t structure
Packit 4a16fb
 * \return hwdep protocol interface
Packit 4a16fb
 */
Packit 4a16fb
snd_hwdep_iface_t snd_hwdep_info_get_iface(const snd_hwdep_info_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return obj->iface;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief set hwdep device number
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_info_t structure
Packit 4a16fb
 * \param val hwdep device
Packit 4a16fb
 */
Packit 4a16fb
void snd_hwdep_info_set_device(snd_hwdep_info_t *obj, unsigned int val)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	obj->device = val;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get information about HwDep handle
Packit 4a16fb
 * \param hwdep HwDep handle
Packit 4a16fb
 * \param info pointer to a snd_hwdep_info_t structure to be filled
Packit 4a16fb
 * \return 0 on success otherwise a negative error code
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_info(snd_hwdep_t *hwdep, snd_hwdep_info_t * info)
Packit 4a16fb
{
Packit 4a16fb
	assert(hwdep);
Packit 4a16fb
	assert(info);
Packit 4a16fb
	return hwdep->ops->info(hwdep, info);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief do hardware dependent ioctl
Packit 4a16fb
 * \param hwdep HwDep handle
Packit 4a16fb
 * \param request ioctl command
Packit 4a16fb
 * \param arg ioctl argument
Packit 4a16fb
 * \return 0 on success otherwise a negative error code
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_ioctl(snd_hwdep_t *hwdep, unsigned int request, void * arg)
Packit 4a16fb
{
Packit 4a16fb
	assert(hwdep);
Packit 4a16fb
	return hwdep->ops->ioctl(hwdep, request, arg);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief write bytes using HwDep handle
Packit 4a16fb
 * \param hwdep HwDep handle
Packit 4a16fb
 * \param buffer buffer containing bytes to write
Packit 4a16fb
 * \param size output buffer size in bytes
Packit 4a16fb
 */
Packit 4a16fb
ssize_t snd_hwdep_write(snd_hwdep_t *hwdep, const void *buffer, size_t size)
Packit 4a16fb
{
Packit 4a16fb
	assert(hwdep);
Packit 4a16fb
	assert(((hwdep->mode & O_ACCMODE) == O_WRONLY) || ((hwdep->mode & O_ACCMODE) == O_RDWR));
Packit 4a16fb
	assert(buffer || size == 0);
Packit 4a16fb
	return hwdep->ops->write(hwdep, buffer, size);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief read bytes using HwDep handle
Packit 4a16fb
 * \param hwdep HwDep handle
Packit 4a16fb
 * \param buffer buffer to store the input bytes
Packit 4a16fb
 * \param size input buffer size in bytes
Packit 4a16fb
 */
Packit 4a16fb
ssize_t snd_hwdep_read(snd_hwdep_t *hwdep, void *buffer, size_t size)
Packit 4a16fb
{
Packit 4a16fb
	assert(hwdep);
Packit 4a16fb
	assert(((hwdep->mode & O_ACCMODE) == O_RDONLY) || ((hwdep->mode & O_ACCMODE) == O_RDWR));
Packit 4a16fb
	assert(buffer || size == 0);
Packit 4a16fb
	return (hwdep->ops->read)(hwdep, buffer, size);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get the DSP status information
Packit 4a16fb
 * \param hwdep HwDep handle
Packit 4a16fb
 * \param info pointer to a snd_hwdep_dsp_status_t structure to be filled
Packit 4a16fb
 * \return 0 on success otherwise a negative error code
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_dsp_status(snd_hwdep_t *hwdep, snd_hwdep_dsp_status_t *info)
Packit 4a16fb
{
Packit 4a16fb
	assert(hwdep);
Packit 4a16fb
	assert(info);
Packit 4a16fb
	return hwdep->ops->ioctl(hwdep, SNDRV_HWDEP_IOCTL_DSP_STATUS, (void*)info);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief load the DSP block
Packit 4a16fb
 * \param hwdep HwDep handle
Packit 4a16fb
 * \param block pointer to a snd_hwdep_dsp_image_t structure to transfer
Packit 4a16fb
 * \return 0 on success otherwise a negative error code
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_dsp_load(snd_hwdep_t *hwdep, snd_hwdep_dsp_image_t *block)
Packit 4a16fb
{
Packit 4a16fb
	assert(hwdep);
Packit 4a16fb
	assert(block);
Packit 4a16fb
	return hwdep->ops->ioctl(hwdep, SNDRV_HWDEP_IOCTL_DSP_LOAD, (void*)block);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get size of the snd_hwdep_dsp_status_t structure in bytes
Packit 4a16fb
 * \return size of the snd_hwdep_dsp_status_t structure in bytes
Packit 4a16fb
 */
Packit 4a16fb
size_t snd_hwdep_dsp_status_sizeof()
Packit 4a16fb
{
Packit 4a16fb
	return sizeof(snd_hwdep_dsp_status_t);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief allocate a new snd_hwdep_dsp_status_t structure
Packit 4a16fb
 * \param info returned pointer
Packit 4a16fb
 * \return 0 on success otherwise a negative error code if fails
Packit 4a16fb
 *
Packit 4a16fb
 * Allocates a new snd_hwdep_dsp_status_t structure using the standard
Packit 4a16fb
 * malloc C library function.
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_dsp_status_malloc(snd_hwdep_dsp_status_t **info)
Packit 4a16fb
{
Packit 4a16fb
	assert(info);
Packit 4a16fb
	*info = calloc(1, sizeof(snd_hwdep_dsp_status_t));
Packit 4a16fb
	if (!*info)
Packit 4a16fb
		return -ENOMEM;
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief frees the snd_hwdep_dsp_status_t structure
Packit 4a16fb
 * \param info pointer to the snd_hwdep_dsp_status_t structure to free
Packit 4a16fb
 *
Packit 4a16fb
 * Frees the given snd_hwdep_dsp_status_t structure using the standard
Packit 4a16fb
 * free C library function.
Packit 4a16fb
 */
Packit 4a16fb
void snd_hwdep_dsp_status_free(snd_hwdep_dsp_status_t *info)
Packit 4a16fb
{
Packit 4a16fb
	assert(info);
Packit 4a16fb
	free(info);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief copy one snd_hwdep_dsp_status_t structure to another
Packit 4a16fb
 * \param dst destination snd_hwdep_dsp_status_t structure
Packit 4a16fb
 * \param src source snd_hwdep_dsp_status_t structure
Packit 4a16fb
 */
Packit 4a16fb
void snd_hwdep_dsp_status_copy(snd_hwdep_dsp_status_t *dst, const snd_hwdep_dsp_status_t *src)
Packit 4a16fb
{
Packit 4a16fb
	assert(dst && src);
Packit 4a16fb
	*dst = *src;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get the driver version of dsp loader
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_status_t structure
Packit 4a16fb
 * \return the driver version
Packit 4a16fb
 */
Packit 4a16fb
unsigned int snd_hwdep_dsp_status_get_version(const snd_hwdep_dsp_status_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return obj->version;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get the driver id of dsp loader
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_status_t structure
Packit 4a16fb
 * \return the driver id string
Packit 4a16fb
 */
Packit 4a16fb
const char *snd_hwdep_dsp_status_get_id(const snd_hwdep_dsp_status_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return (const char *)obj->id;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get number of dsp blocks
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_status_t structure
Packit 4a16fb
 * \return number of dsp blocks
Packit 4a16fb
 */
Packit 4a16fb
unsigned int snd_hwdep_dsp_status_get_num_dsps(const snd_hwdep_dsp_status_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return obj->num_dsps;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get the bit flags of the loaded dsp blocks
Packit 4a16fb
 * \param info pointer to a snd_hwdep_dsp_status_t structure
Packit 4a16fb
 * \return the big flags of the loaded dsp blocks
Packit 4a16fb
 */
Packit 4a16fb
unsigned int snd_hwdep_dsp_status_get_dsp_loaded(const snd_hwdep_dsp_status_t *info)
Packit 4a16fb
{
Packit 4a16fb
	assert(info);
Packit 4a16fb
	return info->dsp_loaded;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get the chip status of dsp loader
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_status_t structure
Packit 4a16fb
 * \return non-zero if all DSP blocks are loaded and the chip is ready
Packit 4a16fb
 */
Packit 4a16fb
unsigned int snd_hwdep_dsp_status_get_chip_ready(const snd_hwdep_dsp_status_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return obj->chip_ready;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get size of the snd_hwdep_dsp_image_t structure in bytes
Packit 4a16fb
 * \return size of the snd_hwdep_dsp_image_t structure in bytes
Packit 4a16fb
 */
Packit 4a16fb
size_t snd_hwdep_dsp_image_sizeof()
Packit 4a16fb
{
Packit 4a16fb
	return sizeof(snd_hwdep_dsp_image_t);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief allocate a new snd_hwdep_dsp_image_t structure
Packit 4a16fb
 * \param info returned pointer
Packit 4a16fb
 * \return 0 on success otherwise a negative error code if fails
Packit 4a16fb
 *
Packit 4a16fb
 * Allocates a new snd_hwdep_dsp_image_t structure using the standard
Packit 4a16fb
 * malloc C library function.
Packit 4a16fb
 */
Packit 4a16fb
int snd_hwdep_dsp_image_malloc(snd_hwdep_dsp_image_t **info)
Packit 4a16fb
{
Packit 4a16fb
	assert(info);
Packit 4a16fb
	*info = calloc(1, sizeof(snd_hwdep_dsp_image_t));
Packit 4a16fb
	if (!*info)
Packit 4a16fb
		return -ENOMEM;
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief frees the snd_hwdep_dsp_image_t structure
Packit 4a16fb
 * \param info pointer to the snd_hwdep_dsp_image_t structure to free
Packit 4a16fb
 *
Packit 4a16fb
 * Frees the given snd_hwdep_dsp_image_t structure using the standard
Packit 4a16fb
 * free C library function.
Packit 4a16fb
 */
Packit 4a16fb
void snd_hwdep_dsp_image_free(snd_hwdep_dsp_image_t *info)
Packit 4a16fb
{
Packit 4a16fb
	assert(info);
Packit 4a16fb
	free(info);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief copy one snd_hwdep_dsp_image_t structure to another
Packit 4a16fb
 * \param dst destination snd_hwdep_dsp_image_t structure
Packit 4a16fb
 * \param src source snd_hwdep_dsp_image_t structure
Packit 4a16fb
 */
Packit 4a16fb
void snd_hwdep_dsp_image_copy(snd_hwdep_dsp_image_t *dst, const snd_hwdep_dsp_image_t *src)
Packit 4a16fb
{
Packit 4a16fb
	assert(dst && src);
Packit 4a16fb
	*dst = *src;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get the DSP block index
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_image_t structure
Packit 4a16fb
 * \return the index of the DSP block
Packit 4a16fb
 */
Packit 4a16fb
unsigned int snd_hwdep_dsp_image_get_index(const snd_hwdep_dsp_image_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return obj->index;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get the name of the DSP block
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_image_t structure
Packit 4a16fb
 * \return the name string of the DSP block
Packit 4a16fb
 */
Packit 4a16fb
const char *snd_hwdep_dsp_image_get_name(const snd_hwdep_dsp_image_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return (const char *)obj->name;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get the length of the DSP block
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_image_t structure
Packit 4a16fb
 * \return the length of the DSP block in bytes
Packit 4a16fb
 */
Packit 4a16fb
size_t snd_hwdep_dsp_image_get_length(const snd_hwdep_dsp_image_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return obj->length;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief get the image pointer of the DSP block
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_image_t structure
Packit 4a16fb
 * \return the image pointer of the DSP block
Packit 4a16fb
 */
Packit 4a16fb
const void *snd_hwdep_dsp_image_get_image(const snd_hwdep_dsp_image_t *obj)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	return obj->image;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief set the DSP block index
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_image_t structure
Packit 4a16fb
 * \param index the index value to set
Packit 4a16fb
 */
Packit 4a16fb
void snd_hwdep_dsp_image_set_index(snd_hwdep_dsp_image_t *obj, unsigned int index)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	obj->index = index;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief set the name of the DSP block
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_image_t structure
Packit 4a16fb
 * \param name the name string
Packit 4a16fb
 */
Packit 4a16fb
void snd_hwdep_dsp_image_set_name(snd_hwdep_dsp_image_t *obj, const char *name)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj && name);
Packit 4a16fb
	strncpy((char *)obj->name, name, sizeof(obj->name));
Packit 4a16fb
	obj->name[sizeof(obj->name)-1] = 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief set the DSP block length
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_image_t structure
Packit 4a16fb
 * \param length the length of the DSP block
Packit 4a16fb
 */
Packit 4a16fb
void snd_hwdep_dsp_image_set_length(snd_hwdep_dsp_image_t *obj, size_t length)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	obj->length = length;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/**
Packit 4a16fb
 * \brief set the DSP block image pointer
Packit 4a16fb
 * \param obj pointer to a snd_hwdep_dsp_image_t structure
Packit 4a16fb
 * \param image the DSP image pointer
Packit 4a16fb
 */
Packit 4a16fb
void snd_hwdep_dsp_image_set_image(snd_hwdep_dsp_image_t *obj, void *image)
Packit 4a16fb
{
Packit 4a16fb
	assert(obj);
Packit 4a16fb
	obj->image = image;
Packit 4a16fb
}
Packit 4a16fb