^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/sound/soc-topology.h -- ALSA SoC Firmware Controls and DAPM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2012 Texas Instruments Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2015 Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Simple file API to load FW that includes mixers, coefficients, DAPM graphs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * algorithms, equalisers, DAIs, widgets, FE caps, BE caps, codec link caps etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifndef __LINUX_SND_SOC_TPLG_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define __LINUX_SND_SOC_TPLG_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <sound/asoc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct snd_kcontrol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct snd_soc_tplg_pcm_be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct snd_ctl_elem_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct snd_ctl_elem_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct snd_soc_dapm_widget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct snd_soc_component;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct snd_soc_tplg_pcm_fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct snd_soc_dapm_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct snd_soc_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct snd_kcontrol_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct snd_soc_dai_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct snd_soc_dai_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct snd_soc_dai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct snd_soc_dapm_route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* object scan be loaded and unloaded in groups with identfying indexes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define SND_SOC_TPLG_INDEX_ALL 0 /* ID that matches all FW objects */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* dynamic object type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) enum snd_soc_dobj_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) SND_SOC_DOBJ_NONE = 0, /* object is not dynamic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) SND_SOC_DOBJ_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) SND_SOC_DOBJ_BYTES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) SND_SOC_DOBJ_ENUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) SND_SOC_DOBJ_GRAPH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) SND_SOC_DOBJ_WIDGET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) SND_SOC_DOBJ_DAI_LINK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) SND_SOC_DOBJ_PCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) SND_SOC_DOBJ_CODEC_LINK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) SND_SOC_DOBJ_BACKEND_LINK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* dynamic control object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct snd_soc_dobj_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct snd_kcontrol *kcontrol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) char **dtexts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) unsigned long *dvalues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* dynamic widget object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct snd_soc_dobj_widget {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) unsigned int kcontrol_type; /* kcontrol type: mixer, enum, bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* generic dynamic object - all dynamic objects belong to this struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct snd_soc_dobj {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) enum snd_soc_dobj_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) unsigned int index; /* objects can belong in different groups */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct snd_soc_tplg_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct snd_soc_dobj_control control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct snd_soc_dobj_widget widget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) void *private; /* core does not touch this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * Kcontrol operations - used to map handlers onto firmware based controls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct snd_soc_tplg_kcontrol_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int (*get)(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int (*put)(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int (*info)(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct snd_ctl_elem_info *uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* Bytes ext operations, for TLV byte controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct snd_soc_tplg_bytes_ext_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) unsigned int size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int (*put)(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) const unsigned int __user *bytes, unsigned int size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * DAPM widget event handlers - used to map handlers onto widgets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct snd_soc_tplg_widget_events {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) u16 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int (*event_handler)(struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct snd_kcontrol *k, int event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * Public API - Used by component drivers to load and unload dynamic objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * and their resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct snd_soc_tplg_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* external kcontrol init - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int (*control_load)(struct snd_soc_component *, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int (*control_unload)(struct snd_soc_component *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct snd_soc_dobj *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* DAPM graph route element loading and unloading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int (*dapm_route_load)(struct snd_soc_component *, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct snd_soc_dapm_route *route);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int (*dapm_route_unload)(struct snd_soc_component *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct snd_soc_dobj *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* external widget init - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int (*widget_load)(struct snd_soc_component *, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct snd_soc_dapm_widget *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct snd_soc_tplg_dapm_widget *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int (*widget_ready)(struct snd_soc_component *, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct snd_soc_dapm_widget *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct snd_soc_tplg_dapm_widget *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int (*widget_unload)(struct snd_soc_component *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct snd_soc_dobj *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* FE DAI - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int (*dai_load)(struct snd_soc_component *, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct snd_soc_dai_driver *dai_drv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int (*dai_unload)(struct snd_soc_component *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct snd_soc_dobj *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* DAI link - used for any driver specific init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int (*link_load)(struct snd_soc_component *, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct snd_soc_dai_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct snd_soc_tplg_link_config *cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) int (*link_unload)(struct snd_soc_component *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct snd_soc_dobj *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* callback to handle vendor bespoke data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int (*vendor_load)(struct snd_soc_component *, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct snd_soc_tplg_hdr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) int (*vendor_unload)(struct snd_soc_component *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct snd_soc_tplg_hdr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* completion - called at completion of firmware loading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) void (*complete)(struct snd_soc_component *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* manifest - optional to inform component of manifest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int (*manifest)(struct snd_soc_component *, int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct snd_soc_tplg_manifest *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* vendor specific kcontrol handlers available for binding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) const struct snd_soc_tplg_kcontrol_ops *io_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int io_ops_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* vendor specific bytes ext handlers available for binding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int bytes_ext_ops_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #ifdef CONFIG_SND_SOC_TOPOLOGY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* gets a pointer to data from the firmware block header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) const void *ptr = hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return ptr + sizeof(*hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Dynamic Object loading and removal for component drivers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int snd_soc_tplg_component_load(struct snd_soc_component *comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct snd_soc_tplg_ops *ops, const struct firmware *fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) u32 index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* Widget removal - widgets also removed wth component API */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) u32 index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* Binds event handlers to dynamic widgets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) const struct snd_soc_tplg_widget_events *events, int num_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) u16 event_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) u32 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #endif