soc-topology.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * linux/sound/soc-topology.h -- ALSA SoC Firmware Controls and DAPM
  3. *
  4. * Copyright (C) 2012 Texas Instruments Inc.
  5. * Copyright (C) 2015 Intel Corporation.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Simple file API to load FW that includes mixers, coefficients, DAPM graphs,
  12. * algorithms, equalisers, DAIs, widgets, FE caps, BE caps, codec link caps etc.
  13. */
  14. #ifndef __LINUX_SND_SOC_TPLG_H
  15. #define __LINUX_SND_SOC_TPLG_H
  16. #include <sound/asoc.h>
  17. #include <linux/list.h>
  18. struct firmware;
  19. struct snd_kcontrol;
  20. struct snd_soc_tplg_pcm_be;
  21. struct snd_ctl_elem_value;
  22. struct snd_ctl_elem_info;
  23. struct snd_soc_dapm_widget;
  24. struct snd_soc_component;
  25. struct snd_soc_tplg_pcm_fe;
  26. struct snd_soc_dapm_context;
  27. struct snd_soc_card;
  28. struct snd_kcontrol_new;
  29. struct snd_soc_dai_link;
  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 *,
  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. /* external widget init - used for any driver specific init */
  104. int (*widget_load)(struct snd_soc_component *,
  105. struct snd_soc_dapm_widget *,
  106. struct snd_soc_tplg_dapm_widget *);
  107. int (*widget_ready)(struct snd_soc_component *,
  108. struct snd_soc_dapm_widget *,
  109. struct snd_soc_tplg_dapm_widget *);
  110. int (*widget_unload)(struct snd_soc_component *,
  111. struct snd_soc_dobj *);
  112. /* FE DAI - used for any driver specific init */
  113. int (*dai_load)(struct snd_soc_component *,
  114. struct snd_soc_dai_driver *dai_drv);
  115. int (*dai_unload)(struct snd_soc_component *,
  116. struct snd_soc_dobj *);
  117. /* DAI link - used for any driver specific init */
  118. int (*link_load)(struct snd_soc_component *,
  119. struct snd_soc_dai_link *link);
  120. int (*link_unload)(struct snd_soc_component *,
  121. struct snd_soc_dobj *);
  122. /* callback to handle vendor bespoke data */
  123. int (*vendor_load)(struct snd_soc_component *,
  124. struct snd_soc_tplg_hdr *);
  125. int (*vendor_unload)(struct snd_soc_component *,
  126. struct snd_soc_tplg_hdr *);
  127. /* completion - called at completion of firmware loading */
  128. void (*complete)(struct snd_soc_component *);
  129. /* manifest - optional to inform component of manifest */
  130. int (*manifest)(struct snd_soc_component *,
  131. struct snd_soc_tplg_manifest *);
  132. /* vendor specific kcontrol handlers available for binding */
  133. const struct snd_soc_tplg_kcontrol_ops *io_ops;
  134. int io_ops_count;
  135. /* vendor specific bytes ext handlers available for binding */
  136. const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
  137. int bytes_ext_ops_count;
  138. };
  139. #ifdef CONFIG_SND_SOC_TOPOLOGY
  140. /* gets a pointer to data from the firmware block header */
  141. static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
  142. {
  143. const void *ptr = hdr;
  144. return ptr + sizeof(*hdr);
  145. }
  146. /* Dynamic Object loading and removal for component drivers */
  147. int snd_soc_tplg_component_load(struct snd_soc_component *comp,
  148. struct snd_soc_tplg_ops *ops, const struct firmware *fw,
  149. u32 index);
  150. int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);
  151. /* Widget removal - widgets also removed wth component API */
  152. void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
  153. void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
  154. u32 index);
  155. /* Binds event handlers to dynamic widgets */
  156. int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
  157. const struct snd_soc_tplg_widget_events *events, int num_events,
  158. u16 event_type);
  159. #else
  160. static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp,
  161. u32 index)
  162. {
  163. return 0;
  164. }
  165. #endif
  166. #endif