soc-topology.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. /* object scan be loaded and unloaded in groups with identfying indexes */
  29. #define SND_SOC_TPLG_INDEX_ALL 0 /* ID that matches all FW objects */
  30. /* dynamic object type */
  31. enum snd_soc_dobj_type {
  32. SND_SOC_DOBJ_NONE = 0, /* object is not dynamic */
  33. SND_SOC_DOBJ_MIXER,
  34. SND_SOC_DOBJ_ENUM,
  35. SND_SOC_DOBJ_BYTES,
  36. SND_SOC_DOBJ_PCM,
  37. SND_SOC_DOBJ_DAI_LINK,
  38. SND_SOC_DOBJ_CODEC_LINK,
  39. SND_SOC_DOBJ_WIDGET,
  40. };
  41. /* dynamic control object */
  42. struct snd_soc_dobj_control {
  43. struct snd_kcontrol *kcontrol;
  44. char **dtexts;
  45. unsigned long *dvalues;
  46. };
  47. /* dynamic widget object */
  48. struct snd_soc_dobj_widget {
  49. unsigned int kcontrol_enum:1; /* this widget is an enum kcontrol */
  50. };
  51. /* generic dynamic object - all dynamic objects belong to this struct */
  52. struct snd_soc_dobj {
  53. enum snd_soc_dobj_type type;
  54. unsigned int index; /* objects can belong in different groups */
  55. struct list_head list;
  56. struct snd_soc_tplg_ops *ops;
  57. union {
  58. struct snd_soc_dobj_control control;
  59. struct snd_soc_dobj_widget widget;
  60. };
  61. void *private; /* core does not touch this */
  62. };
  63. /*
  64. * Kcontrol operations - used to map handlers onto firmware based controls.
  65. */
  66. struct snd_soc_tplg_kcontrol_ops {
  67. u32 id;
  68. int (*get)(struct snd_kcontrol *kcontrol,
  69. struct snd_ctl_elem_value *ucontrol);
  70. int (*put)(struct snd_kcontrol *kcontrol,
  71. struct snd_ctl_elem_value *ucontrol);
  72. int (*info)(struct snd_kcontrol *kcontrol,
  73. struct snd_ctl_elem_info *uinfo);
  74. };
  75. /* Bytes ext operations, for TLV byte controls */
  76. struct snd_soc_tplg_bytes_ext_ops {
  77. u32 id;
  78. int (*get)(struct snd_kcontrol *kcontrol, unsigned int __user *bytes,
  79. unsigned int size);
  80. int (*put)(struct snd_kcontrol *kcontrol,
  81. const unsigned int __user *bytes, unsigned int size);
  82. };
  83. /*
  84. * DAPM widget event handlers - used to map handlers onto widgets.
  85. */
  86. struct snd_soc_tplg_widget_events {
  87. u16 type;
  88. int (*event_handler)(struct snd_soc_dapm_widget *w,
  89. struct snd_kcontrol *k, int event);
  90. };
  91. /*
  92. * Public API - Used by component drivers to load and unload dynamic objects
  93. * and their resources.
  94. */
  95. struct snd_soc_tplg_ops {
  96. /* external kcontrol init - used for any driver specific init */
  97. int (*control_load)(struct snd_soc_component *,
  98. struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
  99. int (*control_unload)(struct snd_soc_component *,
  100. struct snd_soc_dobj *);
  101. /* external widget init - used for any driver specific init */
  102. int (*widget_load)(struct snd_soc_component *,
  103. struct snd_soc_dapm_widget *,
  104. struct snd_soc_tplg_dapm_widget *);
  105. int (*widget_unload)(struct snd_soc_component *,
  106. struct snd_soc_dobj *);
  107. /* FE DAI - used for any driver specific init */
  108. int (*dai_load)(struct snd_soc_component *,
  109. struct snd_soc_dai_driver *dai_drv);
  110. int (*dai_unload)(struct snd_soc_component *,
  111. struct snd_soc_dobj *);
  112. /* DAI link - used for any driver specific init */
  113. int (*link_load)(struct snd_soc_component *,
  114. struct snd_soc_dai_link *link);
  115. int (*link_unload)(struct snd_soc_component *,
  116. struct snd_soc_dobj *);
  117. /* callback to handle vendor bespoke data */
  118. int (*vendor_load)(struct snd_soc_component *,
  119. struct snd_soc_tplg_hdr *);
  120. int (*vendor_unload)(struct snd_soc_component *,
  121. struct snd_soc_tplg_hdr *);
  122. /* completion - called at completion of firmware loading */
  123. void (*complete)(struct snd_soc_component *);
  124. /* manifest - optional to inform component of manifest */
  125. int (*manifest)(struct snd_soc_component *,
  126. struct snd_soc_tplg_manifest *);
  127. /* vendor specific kcontrol handlers available for binding */
  128. const struct snd_soc_tplg_kcontrol_ops *io_ops;
  129. int io_ops_count;
  130. /* vendor specific bytes ext handlers available for binding */
  131. const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
  132. int bytes_ext_ops_count;
  133. };
  134. #ifdef CONFIG_SND_SOC_TOPOLOGY
  135. /* gets a pointer to data from the firmware block header */
  136. static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
  137. {
  138. const void *ptr = hdr;
  139. return ptr + sizeof(*hdr);
  140. }
  141. /* Dynamic Object loading and removal for component drivers */
  142. int snd_soc_tplg_component_load(struct snd_soc_component *comp,
  143. struct snd_soc_tplg_ops *ops, const struct firmware *fw,
  144. u32 index);
  145. int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);
  146. /* Widget removal - widgets also removed wth component API */
  147. void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
  148. void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
  149. u32 index);
  150. /* Binds event handlers to dynamic widgets */
  151. int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
  152. const struct snd_soc_tplg_widget_events *events, int num_events,
  153. u16 event_type);
  154. #else
  155. static inline int snd_soc_tplg_component_remove(struct snd_soc_component *comp,
  156. u32 index)
  157. {
  158. return 0;
  159. }
  160. #endif
  161. #endif