soc-topology.h 6.0 KB

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