soc-topology.h 6.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * linux/sound/soc-topology.h -- ALSA SoC Firmware Controls and DAPM
 *
 * Copyright (C) 2012 Texas Instruments Inc.
 * Copyright (C) 2015 Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * Simple file API to load FW that includes mixers, coefficients, DAPM graphs,
 * algorithms, equalisers, DAIs, widgets, FE caps, BE caps, codec link caps etc.
 */

#ifndef __LINUX_SND_SOC_TPLG_H
#define __LINUX_SND_SOC_TPLG_H

#include <sound/asoc.h>
#include <linux/list.h>

struct firmware;
struct snd_kcontrol;
struct snd_soc_tplg_pcm_be;
struct snd_ctl_elem_value;
struct snd_ctl_elem_info;
struct snd_soc_dapm_widget;
struct snd_soc_component;
struct snd_soc_tplg_pcm_fe;
struct snd_soc_dapm_context;
struct snd_soc_card;
31 32
struct snd_kcontrol_new;
struct snd_soc_dai_link;
33 34
struct snd_soc_dai_driver;
struct snd_soc_dai;
35
struct snd_soc_dapm_route;
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

/* object scan be loaded and unloaded in groups with identfying indexes */
#define SND_SOC_TPLG_INDEX_ALL	0	/* ID that matches all FW objects */

/* dynamic object type */
enum snd_soc_dobj_type {
	SND_SOC_DOBJ_NONE		= 0,	/* object is not dynamic */
	SND_SOC_DOBJ_MIXER,
	SND_SOC_DOBJ_ENUM,
	SND_SOC_DOBJ_BYTES,
	SND_SOC_DOBJ_PCM,
	SND_SOC_DOBJ_DAI_LINK,
	SND_SOC_DOBJ_CODEC_LINK,
	SND_SOC_DOBJ_WIDGET,
};

/* dynamic control object */
struct snd_soc_dobj_control {
	struct snd_kcontrol *kcontrol;
	char **dtexts;
	unsigned long *dvalues;
};

/* dynamic widget object */
struct snd_soc_dobj_widget {
61
	unsigned int kcontrol_type;	/* kcontrol type: mixer, enum, bytes */
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
};

/* generic dynamic object - all dynamic objects belong to this struct */
struct snd_soc_dobj {
	enum snd_soc_dobj_type type;
	unsigned int index;	/* objects can belong in different groups */
	struct list_head list;
	struct snd_soc_tplg_ops *ops;
	union {
		struct snd_soc_dobj_control control;
		struct snd_soc_dobj_widget widget;
	};
	void *private; /* core does not touch this */
};

/*
 * Kcontrol operations - used to map handlers onto firmware based controls.
 */
struct snd_soc_tplg_kcontrol_ops {
	u32 id;
	int (*get)(struct snd_kcontrol *kcontrol,
			struct snd_ctl_elem_value *ucontrol);
	int (*put)(struct snd_kcontrol *kcontrol,
			struct snd_ctl_elem_value *ucontrol);
	int (*info)(struct snd_kcontrol *kcontrol,
		struct snd_ctl_elem_info *uinfo);
};

90 91 92
/* Bytes ext operations, for TLV byte controls */
struct snd_soc_tplg_bytes_ext_ops {
	u32 id;
93 94 95 96
	int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
							unsigned int size);
	int (*put)(struct snd_kcontrol *kcontrol,
			const unsigned int __user *bytes, unsigned int size);
97 98
};

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
/*
 * DAPM widget event handlers - used to map handlers onto widgets.
 */
struct snd_soc_tplg_widget_events {
	u16 type;
	int (*event_handler)(struct snd_soc_dapm_widget *w,
			struct snd_kcontrol *k, int event);
};

/*
 * Public API - Used by component drivers to load and unload dynamic objects
 * and their resources.
 */
struct snd_soc_tplg_ops {

	/* external kcontrol init - used for any driver specific init */
115
	int (*control_load)(struct snd_soc_component *, int index,
116 117 118 119
		struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
	int (*control_unload)(struct snd_soc_component *,
		struct snd_soc_dobj *);

120 121 122 123 124 125
	/* DAPM graph route element loading and unloading */
	int (*dapm_route_load)(struct snd_soc_component *, int index,
		struct snd_soc_dapm_route *route);
	int (*dapm_route_unload)(struct snd_soc_component *,
		struct snd_soc_dobj *);

126
	/* external widget init - used for any driver specific init */
127
	int (*widget_load)(struct snd_soc_component *, int index,
128 129
		struct snd_soc_dapm_widget *,
		struct snd_soc_tplg_dapm_widget *);
130
	int (*widget_ready)(struct snd_soc_component *, int index,
131 132
		struct snd_soc_dapm_widget *,
		struct snd_soc_tplg_dapm_widget *);
133 134 135
	int (*widget_unload)(struct snd_soc_component *,
		struct snd_soc_dobj *);

136
	/* FE DAI - used for any driver specific init */
137 138 139 140
	int (*dai_load)(struct snd_soc_component *, int index,
		struct snd_soc_dai_driver *dai_drv,
		struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai);

141
	int (*dai_unload)(struct snd_soc_component *,
142 143
		struct snd_soc_dobj *);

144
	/* DAI link - used for any driver specific init */
145 146 147
	int (*link_load)(struct snd_soc_component *, int index,
		struct snd_soc_dai_link *link,
		struct snd_soc_tplg_link_config *cfg);
148 149 150
	int (*link_unload)(struct snd_soc_component *,
		struct snd_soc_dobj *);

151
	/* callback to handle vendor bespoke data */
152
	int (*vendor_load)(struct snd_soc_component *, int index,
153 154 155 156 157 158 159 160
		struct snd_soc_tplg_hdr *);
	int (*vendor_unload)(struct snd_soc_component *,
		struct snd_soc_tplg_hdr *);

	/* completion - called at completion of firmware loading */
	void (*complete)(struct snd_soc_component *);

	/* manifest - optional to inform component of manifest */
161
	int (*manifest)(struct snd_soc_component *, int index,
162 163
		struct snd_soc_tplg_manifest *);

164
	/* vendor specific kcontrol handlers available for binding */
165 166
	const struct snd_soc_tplg_kcontrol_ops *io_ops;
	int io_ops_count;
167 168 169 170

	/* vendor specific bytes ext handlers available for binding */
	const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
	int bytes_ext_ops_count;
171 172
};

173 174
#ifdef CONFIG_SND_SOC_TOPOLOGY

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
/* gets a pointer to data from the firmware block header */
static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
{
	const void *ptr = hdr;

	return ptr + sizeof(*hdr);
}

/* Dynamic Object loading and removal for component drivers */
int snd_soc_tplg_component_load(struct snd_soc_component *comp,
	struct snd_soc_tplg_ops *ops, const struct firmware *fw,
	u32 index);
int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);

/* Widget removal - widgets also removed wth component API */
void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
	u32 index);

/* Binds event handlers to dynamic widgets */
int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
	const struct snd_soc_tplg_widget_events *events, int num_events,
	u16 event_type);

199 200 201 202 203 204 205 206 207 208
#else

static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp,
						u32 index)
{
	return 0;
}

#endif

209
#endif