soc-topology.h 5.4 KB

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