Blame src/ucm/ucm_local.h

Packit 4a16fb
/*
Packit 4a16fb
 *  This library is free software; you can redistribute it and/or
Packit 4a16fb
 *  modify it under the terms of the GNU Lesser General Public
Packit 4a16fb
 *  License as published by the Free Software Foundation; either
Packit 4a16fb
 *  version 2 of the License, or (at your option) any later version.
Packit 4a16fb
 *
Packit 4a16fb
 *  This library 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 GNU
Packit 4a16fb
 *  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
 *  Support for the verb/device/modifier core logic and API,
Packit 4a16fb
 *  command line tool and file parser was kindly sponsored by
Packit 4a16fb
 *  Texas Instruments Inc.
Packit 4a16fb
 *  Support for multiple active modifiers and devices,
Packit 4a16fb
 *  transition sequences, multiple client access and user defined use
Packit 4a16fb
 *  cases was kindly sponsored by Wolfson Microelectronics PLC.
Packit 4a16fb
 *
Packit 4a16fb
 *  Copyright (C) 2008-2010 SlimLogic Ltd
Packit 4a16fb
 *  Copyright (C) 2010 Wolfson Microelectronics PLC
Packit 4a16fb
 *  Copyright (C) 2010 Texas Instruments Inc.
Packit 4a16fb
 *  Copyright (C) 2010 Red Hat Inc.
Packit 4a16fb
 *  Authors: Liam Girdwood <lrg@slimlogic.co.uk>
Packit 4a16fb
 *	         Stefan Schmidt <stefan@slimlogic.co.uk>
Packit 4a16fb
 *	         Justin Xu <justinx@slimlogic.co.uk>
Packit 4a16fb
 *               Jaroslav Kysela <perex@perex.cz>
Packit 4a16fb
 */
Packit 4a16fb
Packit 4a16fb
Packit 4a16fb
Packit 4a16fb
#if 0
Packit 4a16fb
#define UC_MGR_DEBUG
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
#include "local.h"
Packit 4a16fb
#include <pthread.h>
Packit 4a16fb
#include "use-case.h"
Packit 4a16fb
Packit 4a16fb
#define SYNTAX_VERSION_MAX	2
Packit 4a16fb
Packit 4a16fb
#define MAX_FILE		256
Packit 4a16fb
#define MAX_CARD_SHORT_NAME	32
Packit 4a16fb
#define MAX_CARD_LONG_NAME	80
Packit 4a16fb
Packit 4a16fb
#define SEQUENCE_ELEMENT_TYPE_CDEV	1
Packit 4a16fb
#define SEQUENCE_ELEMENT_TYPE_CSET	2
Packit 4a16fb
#define SEQUENCE_ELEMENT_TYPE_SLEEP	3
Packit 4a16fb
#define SEQUENCE_ELEMENT_TYPE_EXEC	4
Packit 4a16fb
#define SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE	5
Packit 4a16fb
#define SEQUENCE_ELEMENT_TYPE_CSET_TLV	6
Packit 4a16fb
#define SEQUENCE_ELEMENT_TYPE_CMPT_SEQ	7
Packit 4a16fb
Packit 4a16fb
struct ucm_value {
Packit 4a16fb
        struct list_head list;
Packit 4a16fb
        char *name;
Packit 4a16fb
        char *data;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
/* sequence of a component device */
Packit 4a16fb
struct component_sequence {
Packit 4a16fb
	struct use_case_device *device; /* component device */
Packit 4a16fb
	int enable; /* flag to choose enable or disable list of the device */
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
struct sequence_element {
Packit 4a16fb
	struct list_head list;
Packit 4a16fb
	unsigned int type;
Packit 4a16fb
	union {
Packit 4a16fb
		long sleep; /* Sleep time in microseconds if sleep element, else 0 */
Packit 4a16fb
		char *cdev;
Packit 4a16fb
		char *cset;
Packit 4a16fb
		char *exec;
Packit 4a16fb
		struct component_sequence cmpt_seq; /* component sequence */
Packit 4a16fb
	} data;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
/*
Packit 4a16fb
 * Transition sequences. i.e. transition between one verb, device, mod to another
Packit 4a16fb
 */
Packit 4a16fb
struct transition_sequence {
Packit 4a16fb
	struct list_head list;
Packit 4a16fb
	char *name;
Packit 4a16fb
	struct list_head transition_list;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
/*
Packit 4a16fb
 * Modifier Supported Devices.
Packit 4a16fb
 */
Packit 4a16fb
enum dev_list_type {
Packit 4a16fb
	DEVLIST_NONE,
Packit 4a16fb
	DEVLIST_SUPPORTED,
Packit 4a16fb
	DEVLIST_CONFLICTING
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
struct dev_list_node {
Packit 4a16fb
	struct list_head list;
Packit 4a16fb
	char *name;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
struct dev_list {
Packit 4a16fb
	enum dev_list_type type;
Packit 4a16fb
	struct list_head list;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
struct ctl_dev {
Packit 4a16fb
	struct list_head list;
Packit 4a16fb
	char *device;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
struct ctl_list {
Packit 4a16fb
	struct list_head list;
Packit 4a16fb
	struct list_head dev_list;
Packit 4a16fb
	snd_ctl_t *ctl;
Packit 4a16fb
	snd_ctl_card_info_t *ctl_info;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
/*
Packit 4a16fb
 * Describes a Use Case Modifier and it's enable and disable sequences.
Packit 4a16fb
 * A use case verb can have N modifiers.
Packit 4a16fb
 */
Packit 4a16fb
struct use_case_modifier {
Packit 4a16fb
	struct list_head list;
Packit 4a16fb
	struct list_head active_list;
Packit 4a16fb
Packit 4a16fb
	char *name;
Packit 4a16fb
	char *comment;
Packit 4a16fb
Packit 4a16fb
	/* modifier enable and disable sequences */
Packit 4a16fb
	struct list_head enable_list;
Packit 4a16fb
	struct list_head disable_list;
Packit 4a16fb
Packit 4a16fb
	/* modifier transition list */
Packit 4a16fb
	struct list_head transition_list;
Packit 4a16fb
Packit 4a16fb
	/* list of devices supported or conflicting */
Packit 4a16fb
	struct dev_list dev_list;
Packit 4a16fb
Packit 4a16fb
	/* values */
Packit 4a16fb
	struct list_head value_list;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
/*
Packit 4a16fb
 * Describes a Use Case Device and it's enable and disable sequences.
Packit 4a16fb
 * A use case verb can have N devices.
Packit 4a16fb
 */
Packit 4a16fb
struct use_case_device {
Packit 4a16fb
	struct list_head list;
Packit 4a16fb
	struct list_head active_list;
Packit 4a16fb
Packit 4a16fb
	char *name;
Packit 4a16fb
	char *comment;
Packit 4a16fb
Packit 4a16fb
	/* device enable and disable sequences */
Packit 4a16fb
	struct list_head enable_list;
Packit 4a16fb
	struct list_head disable_list;
Packit 4a16fb
Packit 4a16fb
	/* device transition list */
Packit 4a16fb
	struct list_head transition_list;
Packit 4a16fb
Packit 4a16fb
	/* list of devices supported or conflicting */
Packit 4a16fb
	struct dev_list dev_list;
Packit 4a16fb
Packit 4a16fb
	/* value list */
Packit 4a16fb
	struct list_head value_list;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
/*
Packit 4a16fb
 * Describes a Use Case Verb and it's enable and disable sequences.
Packit 4a16fb
 * A use case verb can have N devices and N modifiers.
Packit 4a16fb
 */
Packit 4a16fb
struct use_case_verb {
Packit 4a16fb
	struct list_head list;
Packit 4a16fb
Packit 4a16fb
	unsigned int active: 1;
Packit 4a16fb
Packit 4a16fb
	char *name;
Packit 4a16fb
	char *comment;
Packit 4a16fb
Packit 4a16fb
	/* verb enable and disable sequences */
Packit 4a16fb
	struct list_head enable_list;
Packit 4a16fb
	struct list_head disable_list;
Packit 4a16fb
Packit 4a16fb
	/* verb transition list */
Packit 4a16fb
	struct list_head transition_list;
Packit 4a16fb
Packit 4a16fb
	/* hardware devices that can be used with this use case */
Packit 4a16fb
	struct list_head device_list;
Packit 4a16fb
Packit 4a16fb
	/* component device list */
Packit 4a16fb
	struct list_head cmpt_device_list;
Packit 4a16fb
Packit 4a16fb
	/* modifiers that can be used with this use case */
Packit 4a16fb
	struct list_head modifier_list;
Packit 4a16fb
Packit 4a16fb
	/* value list */
Packit 4a16fb
	struct list_head value_list;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
/*
Packit 4a16fb
 *  Manages a sound card and all its use cases.
Packit 4a16fb
 */
Packit 4a16fb
struct snd_use_case_mgr {
Packit 4a16fb
	char *card_name;
Packit 4a16fb
	char conf_file_name[MAX_CARD_LONG_NAME];
Packit 4a16fb
	char *comment;
Packit 4a16fb
	int conf_format;
Packit 4a16fb
Packit 4a16fb
	/* use case verb, devices and modifier configs parsed from files */
Packit 4a16fb
	struct list_head verb_list;
Packit 4a16fb
Packit 4a16fb
	/* default settings - sequence */
Packit 4a16fb
	struct list_head default_list;
Packit 4a16fb
Packit 4a16fb
	/* default settings - value list */
Packit 4a16fb
	struct list_head value_list;
Packit 4a16fb
Packit 4a16fb
	/* current status */
Packit 4a16fb
	struct use_case_verb *active_verb;
Packit 4a16fb
	struct list_head active_devices;
Packit 4a16fb
	struct list_head active_modifiers;
Packit 4a16fb
Packit 4a16fb
	/* locking */
Packit 4a16fb
	pthread_mutex_t mutex;
Packit 4a16fb
Packit 4a16fb
	/* list of opened control devices */
Packit 4a16fb
	struct list_head ctl_list;
Packit 4a16fb
Packit 4a16fb
	/* Components don't define cdev, the card device. When executing
Packit 4a16fb
	 * a sequence of a component device, ucm manager enters component
Packit 4a16fb
	 * domain and needs to provide cdev to the component. This cdev
Packit 4a16fb
	 * should be defined by the machine, parent of the component.
Packit 4a16fb
	 */
Packit 4a16fb
	int in_component_domain;
Packit 4a16fb
	char *cdev;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
#define uc_error SNDERR
Packit 4a16fb
Packit 4a16fb
#ifdef UC_MGR_DEBUG
Packit 4a16fb
#define uc_dbg SNDERR
Packit 4a16fb
#else
Packit 4a16fb
#define uc_dbg(fmt, arg...) do { } while (0)
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
void uc_mgr_error(const char *fmt, ...);
Packit 4a16fb
void uc_mgr_stdout(const char *fmt, ...);
Packit 4a16fb
Packit 4a16fb
int uc_mgr_config_load(int format, const char *file, snd_config_t **cfg);
Packit 4a16fb
int uc_mgr_import_master_config(snd_use_case_mgr_t *uc_mgr);
Packit 4a16fb
int uc_mgr_scan_master_configs(const char **_list[]);
Packit 4a16fb
Packit 4a16fb
void uc_mgr_free_sequence_element(struct sequence_element *seq);
Packit 4a16fb
void uc_mgr_free_transition_element(struct transition_sequence *seq);
Packit 4a16fb
void uc_mgr_free_verb(snd_use_case_mgr_t *uc_mgr);
Packit 4a16fb
void uc_mgr_free(snd_use_case_mgr_t *uc_mgr);
Packit 4a16fb
Packit 4a16fb
int uc_mgr_open_ctl(snd_use_case_mgr_t *uc_mgr,
Packit 4a16fb
                    snd_ctl_t **ctl,
Packit 4a16fb
                    const char *device);
Packit 4a16fb
Packit 4a16fb
struct ctl_list *uc_mgr_get_one_ctl(snd_use_case_mgr_t *uc_mgr);
Packit 4a16fb
snd_ctl_t *uc_mgr_get_ctl(snd_use_case_mgr_t *uc_mgr);
Packit 4a16fb
void uc_mgr_free_ctl_list(snd_use_case_mgr_t *uc_mgr);
Packit 4a16fb
Packit 4a16fb
int uc_mgr_add_value(struct list_head *base, const char *key, char *val);
Packit 4a16fb
Packit 4a16fb
int uc_mgr_get_substituted_value(snd_use_case_mgr_t *uc_mgr,
Packit 4a16fb
				 char **_rvalue,
Packit 4a16fb
				 const char *value);
Packit 4a16fb
Packit 4a16fb
int uc_mgr_evaluate_condition(snd_use_case_mgr_t *uc_mgr,
Packit 4a16fb
			      snd_config_t *parent,
Packit 4a16fb
			      snd_config_t *cond);
Packit 4a16fb
Packit 4a16fb
/** The name of the environment variable containing the UCM directory */
Packit 4a16fb
#define ALSA_CONFIG_UCM_VAR "ALSA_CONFIG_UCM"
Packit 4a16fb
Packit 4a16fb
/** The name of the environment variable containing the UCM directory (new syntax) */
Packit 4a16fb
#define ALSA_CONFIG_UCM2_VAR "ALSA_CONFIG_UCM2"