Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0
0002  *
0003  * linux/sound/soc-topology.h -- ALSA SoC Firmware Controls and DAPM
0004  *
0005  * Copyright (C) 2012 Texas Instruments Inc.
0006  * Copyright (C) 2015 Intel Corporation.
0007  *
0008  * Simple file API to load FW that includes mixers, coefficients, DAPM graphs,
0009  * algorithms, equalisers, DAIs, widgets, FE caps, BE caps, codec link caps etc.
0010  */
0011 
0012 #ifndef __LINUX_SND_SOC_TPLG_H
0013 #define __LINUX_SND_SOC_TPLG_H
0014 
0015 #include <sound/asoc.h>
0016 #include <linux/list.h>
0017 
0018 struct firmware;
0019 struct snd_kcontrol;
0020 struct snd_soc_tplg_pcm_be;
0021 struct snd_ctl_elem_value;
0022 struct snd_ctl_elem_info;
0023 struct snd_soc_dapm_widget;
0024 struct snd_soc_component;
0025 struct snd_soc_tplg_pcm_fe;
0026 struct snd_soc_dapm_context;
0027 struct snd_soc_card;
0028 struct snd_kcontrol_new;
0029 struct snd_soc_dai_link;
0030 struct snd_soc_dai_driver;
0031 struct snd_soc_dai;
0032 struct snd_soc_dapm_route;
0033 
0034 /* dynamic object type */
0035 enum snd_soc_dobj_type {
0036     SND_SOC_DOBJ_NONE       = 0,    /* object is not dynamic */
0037     SND_SOC_DOBJ_MIXER,
0038     SND_SOC_DOBJ_BYTES,
0039     SND_SOC_DOBJ_ENUM,
0040     SND_SOC_DOBJ_GRAPH,
0041     SND_SOC_DOBJ_WIDGET,
0042     SND_SOC_DOBJ_DAI_LINK,
0043     SND_SOC_DOBJ_PCM,
0044     SND_SOC_DOBJ_CODEC_LINK,
0045     SND_SOC_DOBJ_BACKEND_LINK,
0046 };
0047 
0048 /* dynamic control object */
0049 struct snd_soc_dobj_control {
0050     struct snd_kcontrol *kcontrol;
0051     char **dtexts;
0052     unsigned long *dvalues;
0053 };
0054 
0055 /* dynamic widget object */
0056 struct snd_soc_dobj_widget {
0057     unsigned int *kcontrol_type;    /* kcontrol type: mixer, enum, bytes */
0058 };
0059 
0060 /* generic dynamic object - all dynamic objects belong to this struct */
0061 struct snd_soc_dobj {
0062     enum snd_soc_dobj_type type;
0063     unsigned int index; /* objects can belong in different groups */
0064     struct list_head list;
0065     struct snd_soc_tplg_ops *ops;
0066     union {
0067         struct snd_soc_dobj_control control;
0068         struct snd_soc_dobj_widget widget;
0069     };
0070     void *private; /* core does not touch this */
0071 };
0072 
0073 /*
0074  * Kcontrol operations - used to map handlers onto firmware based controls.
0075  */
0076 struct snd_soc_tplg_kcontrol_ops {
0077     u32 id;
0078     int (*get)(struct snd_kcontrol *kcontrol,
0079             struct snd_ctl_elem_value *ucontrol);
0080     int (*put)(struct snd_kcontrol *kcontrol,
0081             struct snd_ctl_elem_value *ucontrol);
0082     int (*info)(struct snd_kcontrol *kcontrol,
0083         struct snd_ctl_elem_info *uinfo);
0084 };
0085 
0086 /* Bytes ext operations, for TLV byte controls */
0087 struct snd_soc_tplg_bytes_ext_ops {
0088     u32 id;
0089     int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
0090                             unsigned int size);
0091     int (*put)(struct snd_kcontrol *kcontrol,
0092             const unsigned int __user *bytes, unsigned int size);
0093 };
0094 
0095 /*
0096  * DAPM widget event handlers - used to map handlers onto widgets.
0097  */
0098 struct snd_soc_tplg_widget_events {
0099     u16 type;
0100     int (*event_handler)(struct snd_soc_dapm_widget *w,
0101             struct snd_kcontrol *k, int event);
0102 };
0103 
0104 /*
0105  * Public API - Used by component drivers to load and unload dynamic objects
0106  * and their resources.
0107  */
0108 struct snd_soc_tplg_ops {
0109 
0110     /* external kcontrol init - used for any driver specific init */
0111     int (*control_load)(struct snd_soc_component *, int index,
0112         struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
0113     int (*control_unload)(struct snd_soc_component *,
0114         struct snd_soc_dobj *);
0115 
0116     /* DAPM graph route element loading and unloading */
0117     int (*dapm_route_load)(struct snd_soc_component *, int index,
0118         struct snd_soc_dapm_route *route);
0119     int (*dapm_route_unload)(struct snd_soc_component *,
0120         struct snd_soc_dobj *);
0121 
0122     /* external widget init - used for any driver specific init */
0123     int (*widget_load)(struct snd_soc_component *, int index,
0124         struct snd_soc_dapm_widget *,
0125         struct snd_soc_tplg_dapm_widget *);
0126     int (*widget_ready)(struct snd_soc_component *, int index,
0127         struct snd_soc_dapm_widget *,
0128         struct snd_soc_tplg_dapm_widget *);
0129     int (*widget_unload)(struct snd_soc_component *,
0130         struct snd_soc_dobj *);
0131 
0132     /* FE DAI - used for any driver specific init */
0133     int (*dai_load)(struct snd_soc_component *, int index,
0134         struct snd_soc_dai_driver *dai_drv,
0135         struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai);
0136 
0137     int (*dai_unload)(struct snd_soc_component *,
0138         struct snd_soc_dobj *);
0139 
0140     /* DAI link - used for any driver specific init */
0141     int (*link_load)(struct snd_soc_component *, int index,
0142         struct snd_soc_dai_link *link,
0143         struct snd_soc_tplg_link_config *cfg);
0144     int (*link_unload)(struct snd_soc_component *,
0145         struct snd_soc_dobj *);
0146 
0147     /* callback to handle vendor bespoke data */
0148     int (*vendor_load)(struct snd_soc_component *, int index,
0149         struct snd_soc_tplg_hdr *);
0150     int (*vendor_unload)(struct snd_soc_component *,
0151         struct snd_soc_tplg_hdr *);
0152 
0153     /* completion - called at completion of firmware loading */
0154     int (*complete)(struct snd_soc_component *comp);
0155 
0156     /* manifest - optional to inform component of manifest */
0157     int (*manifest)(struct snd_soc_component *, int index,
0158         struct snd_soc_tplg_manifest *);
0159 
0160     /* vendor specific kcontrol handlers available for binding */
0161     const struct snd_soc_tplg_kcontrol_ops *io_ops;
0162     int io_ops_count;
0163 
0164     /* vendor specific bytes ext handlers available for binding */
0165     const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
0166     int bytes_ext_ops_count;
0167 };
0168 
0169 #ifdef CONFIG_SND_SOC_TOPOLOGY
0170 
0171 /* gets a pointer to data from the firmware block header */
0172 static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
0173 {
0174     const void *ptr = hdr;
0175 
0176     return ptr + sizeof(*hdr);
0177 }
0178 
0179 /* Dynamic Object loading and removal for component drivers */
0180 int snd_soc_tplg_component_load(struct snd_soc_component *comp,
0181     struct snd_soc_tplg_ops *ops, const struct firmware *fw);
0182 int snd_soc_tplg_component_remove(struct snd_soc_component *comp);
0183 
0184 /* Binds event handlers to dynamic widgets */
0185 int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
0186     const struct snd_soc_tplg_widget_events *events, int num_events,
0187     u16 event_type);
0188 
0189 #else
0190 
0191 static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp)
0192 {
0193     return 0;
0194 }
0195 
0196 #endif
0197 
0198 #endif