sof-audio.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
  2. /*
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * Copyright(c) 2019 Intel Corporation. All rights reserved.
  7. *
  8. * Author: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
  9. */
  10. #ifndef __SOUND_SOC_SOF_AUDIO_H
  11. #define __SOUND_SOC_SOF_AUDIO_H
  12. #include <linux/workqueue.h>
  13. #include <sound/soc.h>
  14. #include <sound/control.h>
  15. #include <sound/sof/stream.h> /* needs to be included before control.h */
  16. #include <sound/sof/control.h>
  17. #include <sound/sof/dai.h>
  18. #include <sound/sof/topology.h>
  19. #include "sof-priv.h"
  20. #define SOF_AUDIO_PCM_DRV_NAME "sof-audio-component"
  21. /* max number of FE PCMs before BEs */
  22. #define SOF_BE_PCM_BASE 16
  23. #define DMA_CHAN_INVALID 0xFFFFFFFF
  24. /* PCM stream, mapped to FW component */
  25. struct snd_sof_pcm_stream {
  26. u32 comp_id;
  27. struct snd_dma_buffer page_table;
  28. struct sof_ipc_stream_posn posn;
  29. struct snd_pcm_substream *substream;
  30. struct work_struct period_elapsed_work;
  31. bool d0i3_compatible; /* DSP can be in D0I3 when this pcm is opened */
  32. /*
  33. * flag to indicate that the DSP pipelines should be kept
  34. * active or not while suspending the stream
  35. */
  36. bool suspend_ignored;
  37. };
  38. /* ALSA SOF PCM device */
  39. struct snd_sof_pcm {
  40. struct snd_soc_component *scomp;
  41. struct snd_soc_tplg_pcm pcm;
  42. struct snd_sof_pcm_stream stream[2];
  43. struct list_head list; /* list in sdev pcm list */
  44. struct snd_pcm_hw_params params[2];
  45. bool prepared[2]; /* PCM_PARAMS set successfully */
  46. };
  47. struct snd_sof_led_control {
  48. unsigned int use_led;
  49. unsigned int direction;
  50. int led_value;
  51. };
  52. /* ALSA SOF Kcontrol device */
  53. struct snd_sof_control {
  54. struct snd_soc_component *scomp;
  55. int comp_id;
  56. int min_volume_step; /* min volume step for volume_table */
  57. int max_volume_step; /* max volume step for volume_table */
  58. int num_channels;
  59. u32 readback_offset; /* offset to mmapped data if used */
  60. struct sof_ipc_ctrl_data *control_data;
  61. u32 size; /* cdata size */
  62. enum sof_ipc_ctrl_cmd cmd;
  63. u32 *volume_table; /* volume table computed from tlv data*/
  64. struct list_head list; /* list in sdev control list */
  65. struct snd_sof_led_control led_ctl;
  66. };
  67. /* ASoC SOF DAPM widget */
  68. struct snd_sof_widget {
  69. struct snd_soc_component *scomp;
  70. int comp_id;
  71. int pipeline_id;
  72. int complete;
  73. int core;
  74. int id;
  75. struct snd_soc_dapm_widget *widget;
  76. struct list_head list; /* list in sdev widget list */
  77. /* extended data for UUID components */
  78. struct sof_ipc_comp_ext comp_ext;
  79. void *private; /* core does not touch this */
  80. };
  81. /* ASoC SOF DAPM route */
  82. struct snd_sof_route {
  83. struct snd_soc_component *scomp;
  84. struct snd_soc_dapm_route *route;
  85. struct list_head list; /* list in sdev route list */
  86. void *private;
  87. };
  88. /* ASoC DAI device */
  89. struct snd_sof_dai {
  90. struct snd_soc_component *scomp;
  91. const char *name;
  92. const char *cpu_dai_name;
  93. struct sof_ipc_comp_dai comp_dai;
  94. struct sof_ipc_dai_config *dai_config;
  95. struct list_head list; /* list in sdev dai list */
  96. };
  97. /*
  98. * Kcontrols.
  99. */
  100. int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
  101. struct snd_ctl_elem_value *ucontrol);
  102. int snd_sof_volume_put(struct snd_kcontrol *kcontrol,
  103. struct snd_ctl_elem_value *ucontrol);
  104. int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
  105. struct snd_ctl_elem_value *ucontrol);
  106. int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
  107. struct snd_ctl_elem_value *ucontrol);
  108. int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
  109. struct snd_ctl_elem_value *ucontrol);
  110. int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
  111. struct snd_ctl_elem_value *ucontrol);
  112. int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
  113. struct snd_ctl_elem_value *ucontrol);
  114. int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
  115. struct snd_ctl_elem_value *ucontrol);
  116. int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
  117. const unsigned int __user *binary_data,
  118. unsigned int size);
  119. int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
  120. unsigned int __user *binary_data,
  121. unsigned int size);
  122. int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int __user *binary_data,
  123. unsigned int size);
  124. /*
  125. * Topology.
  126. * There is no snd_sof_free_topology since topology components will
  127. * be freed by snd_soc_unregister_component,
  128. */
  129. int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file);
  130. int snd_sof_complete_pipeline(struct device *dev,
  131. struct snd_sof_widget *swidget);
  132. int sof_load_pipeline_ipc(struct device *dev,
  133. struct sof_ipc_pipe_new *pipeline,
  134. struct sof_ipc_comp_reply *r);
  135. int sof_pipeline_core_enable(struct snd_sof_dev *sdev,
  136. const struct snd_sof_widget *swidget);
  137. /*
  138. * Stream IPC
  139. */
  140. int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp,
  141. struct snd_sof_pcm *spcm, int direction,
  142. struct sof_ipc_stream_posn *posn);
  143. struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
  144. const char *name);
  145. struct snd_sof_widget *
  146. snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
  147. const char *pcm_name, int dir);
  148. struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
  149. const char *name);
  150. static inline
  151. struct snd_sof_pcm *snd_sof_find_spcm_dai(struct snd_soc_component *scomp,
  152. struct snd_soc_pcm_runtime *rtd)
  153. {
  154. struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
  155. struct snd_sof_pcm *spcm = NULL;
  156. list_for_each_entry(spcm, &sdev->pcm_list, list) {
  157. if (le32_to_cpu(spcm->pcm.dai_id) == rtd->dai_link->id)
  158. return spcm;
  159. }
  160. return NULL;
  161. }
  162. struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
  163. const char *name);
  164. struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
  165. unsigned int comp_id,
  166. int *direction);
  167. struct snd_sof_pcm *snd_sof_find_spcm_pcm_id(struct snd_soc_component *scomp,
  168. unsigned int pcm_id);
  169. const struct sof_ipc_pipe_new *snd_sof_pipeline_find(struct snd_sof_dev *sdev,
  170. int pipeline_id);
  171. void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream);
  172. void snd_sof_pcm_period_elapsed_work(struct work_struct *work);
  173. /*
  174. * Mixer IPC
  175. */
  176. int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol,
  177. u32 ipc_cmd,
  178. enum sof_ipc_ctrl_type ctrl_type,
  179. enum sof_ipc_ctrl_cmd ctrl_cmd,
  180. bool send);
  181. /* PM */
  182. int sof_restore_pipelines(struct device *dev);
  183. int sof_set_hw_params_upon_resume(struct device *dev);
  184. bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev);
  185. bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev);
  186. /* Machine driver enumeration */
  187. int sof_machine_register(struct snd_sof_dev *sdev, void *pdata);
  188. void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata);
  189. #endif