162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci *
362306a36Sopenharmony_ci * linux/sound/soc-topology.h -- ALSA SoC Firmware Controls and DAPM
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2012 Texas Instruments Inc.
662306a36Sopenharmony_ci * Copyright (C) 2015 Intel Corporation.
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Simple file API to load FW that includes mixers, coefficients, DAPM graphs,
962306a36Sopenharmony_ci * algorithms, equalisers, DAIs, widgets, FE caps, BE caps, codec link caps etc.
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#ifndef __LINUX_SND_SOC_TPLG_H
1362306a36Sopenharmony_ci#define __LINUX_SND_SOC_TPLG_H
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#include <sound/asoc.h>
1662306a36Sopenharmony_ci#include <linux/list.h>
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct firmware;
1962306a36Sopenharmony_cistruct snd_kcontrol;
2062306a36Sopenharmony_cistruct snd_soc_tplg_pcm_be;
2162306a36Sopenharmony_cistruct snd_ctl_elem_value;
2262306a36Sopenharmony_cistruct snd_ctl_elem_info;
2362306a36Sopenharmony_cistruct snd_soc_dapm_widget;
2462306a36Sopenharmony_cistruct snd_soc_component;
2562306a36Sopenharmony_cistruct snd_soc_tplg_pcm_fe;
2662306a36Sopenharmony_cistruct snd_soc_dapm_context;
2762306a36Sopenharmony_cistruct snd_soc_card;
2862306a36Sopenharmony_cistruct snd_kcontrol_new;
2962306a36Sopenharmony_cistruct snd_soc_dai_link;
3062306a36Sopenharmony_cistruct snd_soc_dai_driver;
3162306a36Sopenharmony_cistruct snd_soc_dai;
3262306a36Sopenharmony_cistruct snd_soc_dapm_route;
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/* dynamic object type */
3562306a36Sopenharmony_cienum snd_soc_dobj_type {
3662306a36Sopenharmony_ci	SND_SOC_DOBJ_NONE		= 0,	/* object is not dynamic */
3762306a36Sopenharmony_ci	SND_SOC_DOBJ_MIXER,
3862306a36Sopenharmony_ci	SND_SOC_DOBJ_BYTES,
3962306a36Sopenharmony_ci	SND_SOC_DOBJ_ENUM,
4062306a36Sopenharmony_ci	SND_SOC_DOBJ_GRAPH,
4162306a36Sopenharmony_ci	SND_SOC_DOBJ_WIDGET,
4262306a36Sopenharmony_ci	SND_SOC_DOBJ_DAI_LINK,
4362306a36Sopenharmony_ci	SND_SOC_DOBJ_PCM,
4462306a36Sopenharmony_ci	SND_SOC_DOBJ_CODEC_LINK,
4562306a36Sopenharmony_ci	SND_SOC_DOBJ_BACKEND_LINK,
4662306a36Sopenharmony_ci};
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci/* dynamic control object */
4962306a36Sopenharmony_cistruct snd_soc_dobj_control {
5062306a36Sopenharmony_ci	struct snd_kcontrol *kcontrol;
5162306a36Sopenharmony_ci	char **dtexts;
5262306a36Sopenharmony_ci	unsigned long *dvalues;
5362306a36Sopenharmony_ci};
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/* dynamic widget object */
5662306a36Sopenharmony_cistruct snd_soc_dobj_widget {
5762306a36Sopenharmony_ci	unsigned int *kcontrol_type;	/* kcontrol type: mixer, enum, bytes */
5862306a36Sopenharmony_ci};
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci/* generic dynamic object - all dynamic objects belong to this struct */
6162306a36Sopenharmony_cistruct snd_soc_dobj {
6262306a36Sopenharmony_ci	enum snd_soc_dobj_type type;
6362306a36Sopenharmony_ci	unsigned int index;	/* objects can belong in different groups */
6462306a36Sopenharmony_ci	struct list_head list;
6562306a36Sopenharmony_ci	int (*unload)(struct snd_soc_component *comp, struct snd_soc_dobj *dobj);
6662306a36Sopenharmony_ci	union {
6762306a36Sopenharmony_ci		struct snd_soc_dobj_control control;
6862306a36Sopenharmony_ci		struct snd_soc_dobj_widget widget;
6962306a36Sopenharmony_ci	};
7062306a36Sopenharmony_ci	void *private; /* core does not touch this */
7162306a36Sopenharmony_ci};
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci/*
7462306a36Sopenharmony_ci * Kcontrol operations - used to map handlers onto firmware based controls.
7562306a36Sopenharmony_ci */
7662306a36Sopenharmony_cistruct snd_soc_tplg_kcontrol_ops {
7762306a36Sopenharmony_ci	u32 id;
7862306a36Sopenharmony_ci	int (*get)(struct snd_kcontrol *kcontrol,
7962306a36Sopenharmony_ci			struct snd_ctl_elem_value *ucontrol);
8062306a36Sopenharmony_ci	int (*put)(struct snd_kcontrol *kcontrol,
8162306a36Sopenharmony_ci			struct snd_ctl_elem_value *ucontrol);
8262306a36Sopenharmony_ci	int (*info)(struct snd_kcontrol *kcontrol,
8362306a36Sopenharmony_ci		struct snd_ctl_elem_info *uinfo);
8462306a36Sopenharmony_ci};
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/* Bytes ext operations, for TLV byte controls */
8762306a36Sopenharmony_cistruct snd_soc_tplg_bytes_ext_ops {
8862306a36Sopenharmony_ci	u32 id;
8962306a36Sopenharmony_ci	int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
9062306a36Sopenharmony_ci							unsigned int size);
9162306a36Sopenharmony_ci	int (*put)(struct snd_kcontrol *kcontrol,
9262306a36Sopenharmony_ci			const unsigned int __user *bytes, unsigned int size);
9362306a36Sopenharmony_ci};
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci/*
9662306a36Sopenharmony_ci * DAPM widget event handlers - used to map handlers onto widgets.
9762306a36Sopenharmony_ci */
9862306a36Sopenharmony_cistruct snd_soc_tplg_widget_events {
9962306a36Sopenharmony_ci	u16 type;
10062306a36Sopenharmony_ci	int (*event_handler)(struct snd_soc_dapm_widget *w,
10162306a36Sopenharmony_ci			struct snd_kcontrol *k, int event);
10262306a36Sopenharmony_ci};
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci/*
10562306a36Sopenharmony_ci * Public API - Used by component drivers to load and unload dynamic objects
10662306a36Sopenharmony_ci * and their resources.
10762306a36Sopenharmony_ci */
10862306a36Sopenharmony_cistruct snd_soc_tplg_ops {
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci	/* external kcontrol init - used for any driver specific init */
11162306a36Sopenharmony_ci	int (*control_load)(struct snd_soc_component *, int index,
11262306a36Sopenharmony_ci		struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
11362306a36Sopenharmony_ci	int (*control_unload)(struct snd_soc_component *,
11462306a36Sopenharmony_ci		struct snd_soc_dobj *);
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci	/* DAPM graph route element loading and unloading */
11762306a36Sopenharmony_ci	int (*dapm_route_load)(struct snd_soc_component *, int index,
11862306a36Sopenharmony_ci		struct snd_soc_dapm_route *route);
11962306a36Sopenharmony_ci	int (*dapm_route_unload)(struct snd_soc_component *,
12062306a36Sopenharmony_ci		struct snd_soc_dobj *);
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci	/* external widget init - used for any driver specific init */
12362306a36Sopenharmony_ci	int (*widget_load)(struct snd_soc_component *, int index,
12462306a36Sopenharmony_ci		struct snd_soc_dapm_widget *,
12562306a36Sopenharmony_ci		struct snd_soc_tplg_dapm_widget *);
12662306a36Sopenharmony_ci	int (*widget_ready)(struct snd_soc_component *, int index,
12762306a36Sopenharmony_ci		struct snd_soc_dapm_widget *,
12862306a36Sopenharmony_ci		struct snd_soc_tplg_dapm_widget *);
12962306a36Sopenharmony_ci	int (*widget_unload)(struct snd_soc_component *,
13062306a36Sopenharmony_ci		struct snd_soc_dobj *);
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci	/* FE DAI - used for any driver specific init */
13362306a36Sopenharmony_ci	int (*dai_load)(struct snd_soc_component *, int index,
13462306a36Sopenharmony_ci		struct snd_soc_dai_driver *dai_drv,
13562306a36Sopenharmony_ci		struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai);
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci	int (*dai_unload)(struct snd_soc_component *,
13862306a36Sopenharmony_ci		struct snd_soc_dobj *);
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci	/* DAI link - used for any driver specific init */
14162306a36Sopenharmony_ci	int (*link_load)(struct snd_soc_component *, int index,
14262306a36Sopenharmony_ci		struct snd_soc_dai_link *link,
14362306a36Sopenharmony_ci		struct snd_soc_tplg_link_config *cfg);
14462306a36Sopenharmony_ci	int (*link_unload)(struct snd_soc_component *,
14562306a36Sopenharmony_ci		struct snd_soc_dobj *);
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci	/* callback to handle vendor bespoke data */
14862306a36Sopenharmony_ci	int (*vendor_load)(struct snd_soc_component *, int index,
14962306a36Sopenharmony_ci		struct snd_soc_tplg_hdr *);
15062306a36Sopenharmony_ci	int (*vendor_unload)(struct snd_soc_component *,
15162306a36Sopenharmony_ci		struct snd_soc_tplg_hdr *);
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci	/* completion - called at completion of firmware loading */
15462306a36Sopenharmony_ci	int (*complete)(struct snd_soc_component *comp);
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci	/* manifest - optional to inform component of manifest */
15762306a36Sopenharmony_ci	int (*manifest)(struct snd_soc_component *, int index,
15862306a36Sopenharmony_ci		struct snd_soc_tplg_manifest *);
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci	/* vendor specific kcontrol handlers available for binding */
16162306a36Sopenharmony_ci	const struct snd_soc_tplg_kcontrol_ops *io_ops;
16262306a36Sopenharmony_ci	int io_ops_count;
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci	/* vendor specific bytes ext handlers available for binding */
16562306a36Sopenharmony_ci	const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
16662306a36Sopenharmony_ci	int bytes_ext_ops_count;
16762306a36Sopenharmony_ci};
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci#ifdef CONFIG_SND_SOC_TOPOLOGY
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ci/* gets a pointer to data from the firmware block header */
17262306a36Sopenharmony_cistatic inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
17362306a36Sopenharmony_ci{
17462306a36Sopenharmony_ci	const void *ptr = hdr;
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci	return ptr + sizeof(*hdr);
17762306a36Sopenharmony_ci}
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci/* Dynamic Object loading and removal for component drivers */
18062306a36Sopenharmony_ciint snd_soc_tplg_component_load(struct snd_soc_component *comp,
18162306a36Sopenharmony_ci	struct snd_soc_tplg_ops *ops, const struct firmware *fw);
18262306a36Sopenharmony_ciint snd_soc_tplg_component_remove(struct snd_soc_component *comp);
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci/* Binds event handlers to dynamic widgets */
18562306a36Sopenharmony_ciint snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
18662306a36Sopenharmony_ci	const struct snd_soc_tplg_widget_events *events, int num_events,
18762306a36Sopenharmony_ci	u16 event_type);
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci#else
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_cistatic inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp)
19262306a36Sopenharmony_ci{
19362306a36Sopenharmony_ci	return 0;
19462306a36Sopenharmony_ci}
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci#endif
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci#endif
199