soc-topology.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. /*
  82. * DAPM widget event handlers - used to map handlers onto widgets.
  83. */
  84. struct snd_soc_tplg_widget_events {
  85. u16 type;
  86. int (*event_handler)(struct snd_soc_dapm_widget *w,
  87. struct snd_kcontrol *k, int event);
  88. };
  89. /*
  90. * Public API - Used by component drivers to load and unload dynamic objects
  91. * and their resources.
  92. */
  93. struct snd_soc_tplg_ops {
  94. /* external kcontrol init - used for any driver specific init */
  95. int (*control_load)(struct snd_soc_component *,
  96. struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *);
  97. int (*control_unload)(struct snd_soc_component *,
  98. struct snd_soc_dobj *);
  99. /* external widget init - used for any driver specific init */
  100. int (*widget_load)(struct snd_soc_component *,
  101. struct snd_soc_dapm_widget *,
  102. struct snd_soc_tplg_dapm_widget *);
  103. int (*widget_unload)(struct snd_soc_component *,
  104. struct snd_soc_dobj *);
  105. /* FE - used for any driver specific init */
  106. int (*pcm_dai_load)(struct snd_soc_component *,
  107. struct snd_soc_tplg_pcm_dai *pcm_dai, int num_fe);
  108. int (*pcm_dai_unload)(struct snd_soc_component *,
  109. struct snd_soc_dobj *);
  110. /* callback to handle vendor bespoke data */
  111. int (*vendor_load)(struct snd_soc_component *,
  112. struct snd_soc_tplg_hdr *);
  113. int (*vendor_unload)(struct snd_soc_component *,
  114. struct snd_soc_tplg_hdr *);
  115. /* completion - called at completion of firmware loading */
  116. void (*complete)(struct snd_soc_component *);
  117. /* manifest - optional to inform component of manifest */
  118. int (*manifest)(struct snd_soc_component *,
  119. struct snd_soc_tplg_manifest *);
  120. /* bespoke kcontrol handlers available for binding */
  121. const struct snd_soc_tplg_kcontrol_ops *io_ops;
  122. int io_ops_count;
  123. };
  124. /* gets a pointer to data from the firmware block header */
  125. static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr)
  126. {
  127. const void *ptr = hdr;
  128. return ptr + sizeof(*hdr);
  129. }
  130. /* Dynamic Object loading and removal for component drivers */
  131. int snd_soc_tplg_component_load(struct snd_soc_component *comp,
  132. struct snd_soc_tplg_ops *ops, const struct firmware *fw,
  133. u32 index);
  134. int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index);
  135. /* Widget removal - widgets also removed wth component API */
  136. void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w);
  137. void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
  138. u32 index);
  139. /* Binds event handlers to dynamic widgets */
  140. int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
  141. const struct snd_soc_tplg_widget_events *events, int num_events,
  142. u16 event_type);
  143. #endif