sof-audio.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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
  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. /*
  22. * The ipc4 firmware only supports up to 8 sink or source pins
  23. * per widget, because only 3 bits are used for queue(pin) ID
  24. * in ipc4 protocol.
  25. */
  26. #define SOF_WIDGET_MAX_NUM_PINS 8
  27. /* Widget pin type */
  28. #define SOF_PIN_TYPE_INPUT 0
  29. #define SOF_PIN_TYPE_OUTPUT 1
  30. /* max number of FE PCMs before BEs */
  31. #define SOF_BE_PCM_BASE 16
  32. #define DMA_CHAN_INVALID 0xFFFFFFFF
  33. #define WIDGET_IS_DAI(id) ((id) == snd_soc_dapm_dai_in || (id) == snd_soc_dapm_dai_out)
  34. #define WIDGET_IS_AIF(id) ((id) == snd_soc_dapm_aif_in || (id) == snd_soc_dapm_aif_out)
  35. #define WIDGET_IS_AIF_OR_DAI(id) (WIDGET_IS_DAI(id) || WIDGET_IS_AIF(id))
  36. #define WIDGET_IS_COPIER(id) (WIDGET_IS_AIF_OR_DAI(id) || (id) == snd_soc_dapm_buffer)
  37. #define SOF_DAI_PARAM_INTEL_SSP_MCLK 0
  38. #define SOF_DAI_PARAM_INTEL_SSP_BCLK 1
  39. #define SOF_DAI_PARAM_INTEL_SSP_TDM_SLOTS 2
  40. enum sof_widget_op {
  41. SOF_WIDGET_PREPARE,
  42. SOF_WIDGET_SETUP,
  43. SOF_WIDGET_FREE,
  44. SOF_WIDGET_UNPREPARE,
  45. };
  46. /*
  47. * Volume fractional word length define to 16 sets
  48. * the volume linear gain value to use Qx.16 format
  49. */
  50. #define VOLUME_FWL 16
  51. #define SOF_TLV_ITEMS 3
  52. static inline u32 mixer_to_ipc(unsigned int value, u32 *volume_map, int size)
  53. {
  54. if (value >= size)
  55. return volume_map[size - 1];
  56. return volume_map[value];
  57. }
  58. static inline u32 ipc_to_mixer(u32 value, u32 *volume_map, int size)
  59. {
  60. int i;
  61. for (i = 0; i < size; i++) {
  62. if (volume_map[i] >= value)
  63. return i;
  64. }
  65. return i - 1;
  66. }
  67. struct snd_sof_widget;
  68. struct snd_sof_route;
  69. struct snd_sof_control;
  70. struct snd_sof_dai;
  71. struct snd_sof_pcm;
  72. struct snd_sof_dai_config_data {
  73. int dai_index;
  74. int dai_data; /* contains DAI-specific information */
  75. int dai_node_id; /* contains DAI-specific information for Gateway configuration */
  76. };
  77. /**
  78. * struct sof_ipc_pcm_ops - IPC-specific PCM ops
  79. * @hw_params: Function pointer for hw_params
  80. * @hw_free: Function pointer for hw_free
  81. * @trigger: Function pointer for trigger
  82. * @dai_link_fixup: Function pointer for DAI link fixup
  83. * @pcm_setup: Function pointer for IPC-specific PCM set up that can be used for allocating
  84. * additional memory in the SOF PCM stream structure
  85. * @pcm_free: Function pointer for PCM free that can be used for freeing any
  86. * additional memory in the SOF PCM stream structure
  87. * @pointer: Function pointer for pcm pointer
  88. * Note: the @pointer callback may return -EOPNOTSUPP which should be
  89. * handled in a same way as if the callback is not provided
  90. * @delay: Function pointer for pcm delay reporting
  91. * @reset_hw_params_during_stop: Flag indicating whether the hw_params should be reset during the
  92. * STOP pcm trigger
  93. * @ipc_first_on_start: Send IPC before invoking platform trigger during
  94. * START/PAUSE_RELEASE triggers
  95. * @platform_stop_during_hw_free: Invoke the platform trigger during hw_free. This is needed for
  96. * IPC4 where a pipeline is only paused during stop/pause/suspend
  97. * triggers. The FW keeps the host DMA running in this case and
  98. * therefore the host must do the same and should stop the DMA during
  99. * hw_free.
  100. * @d0i3_supported_in_s0ix: Allow DSP D0I3 during S0iX
  101. */
  102. struct sof_ipc_pcm_ops {
  103. int (*hw_params)(struct snd_soc_component *component, struct snd_pcm_substream *substream,
  104. struct snd_pcm_hw_params *params,
  105. struct snd_sof_platform_stream_params *platform_params);
  106. int (*hw_free)(struct snd_soc_component *component, struct snd_pcm_substream *substream);
  107. int (*trigger)(struct snd_soc_component *component, struct snd_pcm_substream *substream,
  108. int cmd);
  109. int (*dai_link_fixup)(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
  110. int (*pcm_setup)(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm);
  111. void (*pcm_free)(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm);
  112. int (*pointer)(struct snd_soc_component *component,
  113. struct snd_pcm_substream *substream,
  114. snd_pcm_uframes_t *pointer);
  115. snd_pcm_sframes_t (*delay)(struct snd_soc_component *component,
  116. struct snd_pcm_substream *substream);
  117. bool reset_hw_params_during_stop;
  118. bool ipc_first_on_start;
  119. bool platform_stop_during_hw_free;
  120. bool d0i3_supported_in_s0ix;
  121. };
  122. /**
  123. * struct sof_ipc_tplg_control_ops - IPC-specific ops for topology kcontrol IO
  124. */
  125. struct sof_ipc_tplg_control_ops {
  126. bool (*volume_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
  127. int (*volume_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
  128. bool (*switch_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
  129. int (*switch_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
  130. bool (*enum_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
  131. int (*enum_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
  132. int (*bytes_put)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
  133. int (*bytes_get)(struct snd_sof_control *scontrol, struct snd_ctl_elem_value *ucontrol);
  134. int (*bytes_ext_get)(struct snd_sof_control *scontrol,
  135. const unsigned int __user *binary_data, unsigned int size);
  136. int (*bytes_ext_volatile_get)(struct snd_sof_control *scontrol,
  137. const unsigned int __user *binary_data, unsigned int size);
  138. int (*bytes_ext_put)(struct snd_sof_control *scontrol,
  139. const unsigned int __user *binary_data, unsigned int size);
  140. /* update control data based on notification from the DSP */
  141. void (*update)(struct snd_sof_dev *sdev, void *ipc_control_message);
  142. /* Optional callback to setup kcontrols associated with an swidget */
  143. int (*widget_kcontrol_setup)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
  144. /* mandatory callback to set up volume table for volume kcontrols */
  145. int (*set_up_volume_table)(struct snd_sof_control *scontrol, int tlv[SOF_TLV_ITEMS],
  146. int size);
  147. };
  148. /**
  149. * struct sof_ipc_tplg_widget_ops - IPC-specific ops for topology widgets
  150. * @ipc_setup: Function pointer for setting up widget IPC params
  151. * @ipc_free: Function pointer for freeing widget IPC params
  152. * @token_list: List of token ID's that should be parsed for the widget
  153. * @token_list_size: number of elements in token_list
  154. * @bind_event: Function pointer for binding events to the widget
  155. * @ipc_prepare: Optional op for preparing a widget for set up
  156. * @ipc_unprepare: Optional op for unpreparing a widget
  157. */
  158. struct sof_ipc_tplg_widget_ops {
  159. int (*ipc_setup)(struct snd_sof_widget *swidget);
  160. void (*ipc_free)(struct snd_sof_widget *swidget);
  161. enum sof_tokens *token_list;
  162. int token_list_size;
  163. int (*bind_event)(struct snd_soc_component *scomp, struct snd_sof_widget *swidget,
  164. u16 event_type);
  165. int (*ipc_prepare)(struct snd_sof_widget *swidget,
  166. struct snd_pcm_hw_params *fe_params,
  167. struct snd_sof_platform_stream_params *platform_params,
  168. struct snd_pcm_hw_params *source_params, int dir);
  169. void (*ipc_unprepare)(struct snd_sof_widget *swidget);
  170. };
  171. /**
  172. * struct sof_ipc_tplg_ops - IPC-specific topology ops
  173. * @widget: Array of pointers to IPC-specific ops for widgets. This should always be of size
  174. * SND_SOF_DAPM_TYPE_COUNT i.e one per widget type. Unsupported widget types will be
  175. * initialized to 0.
  176. * @control: Pointer to the IPC-specific ops for topology kcontrol IO
  177. * @route_setup: Function pointer for setting up pipeline connections
  178. * @route_free: Function pointer for freeing pipeline connections.
  179. * @token_list: List of all tokens supported by the IPC version. The size of the token_list
  180. * array should be SOF_TOKEN_COUNT. The unused elements in the array will be
  181. * initialized to 0.
  182. * @control_setup: Function pointer for setting up kcontrol IPC-specific data
  183. * @control_free: Function pointer for freeing kcontrol IPC-specific data
  184. * @pipeline_complete: Function pointer for pipeline complete IPC
  185. * @widget_setup: Function pointer for setting up setup in the DSP
  186. * @widget_free: Function pointer for freeing widget in the DSP
  187. * @dai_config: Function pointer for sending DAI config IPC to the DSP
  188. * @dai_get_param: Function pointer for getting the DAI parameter
  189. * @set_up_all_pipelines: Function pointer for setting up all topology pipelines
  190. * @tear_down_all_pipelines: Function pointer for tearing down all topology pipelines
  191. * @parse_manifest: Function pointer for ipc4 specific parsing of topology manifest
  192. * @link_setup: Function pointer for IPC-specific DAI link set up
  193. *
  194. * Note: function pointers (ops) are optional
  195. */
  196. struct sof_ipc_tplg_ops {
  197. const struct sof_ipc_tplg_widget_ops *widget;
  198. const struct sof_ipc_tplg_control_ops *control;
  199. int (*route_setup)(struct snd_sof_dev *sdev, struct snd_sof_route *sroute);
  200. int (*route_free)(struct snd_sof_dev *sdev, struct snd_sof_route *sroute);
  201. const struct sof_token_info *token_list;
  202. int (*control_setup)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
  203. int (*control_free)(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol);
  204. int (*pipeline_complete)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
  205. int (*widget_setup)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
  206. int (*widget_free)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
  207. int (*dai_config)(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
  208. unsigned int flags, struct snd_sof_dai_config_data *data);
  209. int (*dai_get_param)(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int param_type);
  210. int (*set_up_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
  211. int (*tear_down_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
  212. int (*parse_manifest)(struct snd_soc_component *scomp, int index,
  213. struct snd_soc_tplg_manifest *man);
  214. int (*link_setup)(struct snd_sof_dev *sdev, struct snd_soc_dai_link *link);
  215. };
  216. /** struct snd_sof_tuple - Tuple info
  217. * @token: Token ID
  218. * @value: union of a string or a u32 values
  219. */
  220. struct snd_sof_tuple {
  221. u32 token;
  222. union {
  223. u32 v;
  224. const char *s;
  225. } value;
  226. };
  227. /*
  228. * List of SOF token ID's. The order of ID's does not matter as token arrays are looked up based on
  229. * the ID.
  230. */
  231. enum sof_tokens {
  232. SOF_PCM_TOKENS,
  233. SOF_PIPELINE_TOKENS,
  234. SOF_SCHED_TOKENS,
  235. SOF_ASRC_TOKENS,
  236. SOF_SRC_TOKENS,
  237. SOF_COMP_TOKENS,
  238. SOF_BUFFER_TOKENS,
  239. SOF_VOLUME_TOKENS,
  240. SOF_PROCESS_TOKENS,
  241. SOF_DAI_TOKENS,
  242. SOF_DAI_LINK_TOKENS,
  243. SOF_HDA_TOKENS,
  244. SOF_SSP_TOKENS,
  245. SOF_ALH_TOKENS,
  246. SOF_DMIC_TOKENS,
  247. SOF_DMIC_PDM_TOKENS,
  248. SOF_ESAI_TOKENS,
  249. SOF_SAI_TOKENS,
  250. SOF_AFE_TOKENS,
  251. SOF_CORE_TOKENS,
  252. SOF_COMP_EXT_TOKENS,
  253. SOF_IN_AUDIO_FORMAT_TOKENS,
  254. SOF_OUT_AUDIO_FORMAT_TOKENS,
  255. SOF_COPIER_DEEP_BUFFER_TOKENS,
  256. SOF_COPIER_TOKENS,
  257. SOF_AUDIO_FMT_NUM_TOKENS,
  258. SOF_COPIER_FORMAT_TOKENS,
  259. SOF_GAIN_TOKENS,
  260. SOF_ACPDMIC_TOKENS,
  261. SOF_ACPI2S_TOKENS,
  262. SOF_MICFIL_TOKENS,
  263. SOF_ACP_SDW_TOKENS,
  264. /* this should be the last */
  265. SOF_TOKEN_COUNT,
  266. };
  267. /**
  268. * struct sof_topology_token - SOF topology token definition
  269. * @token: Token number
  270. * @type: Token type
  271. * @get_token: Function pointer to parse the token value and save it in a object
  272. * @offset: Offset within an object to save the token value into
  273. */
  274. struct sof_topology_token {
  275. u32 token;
  276. u32 type;
  277. int (*get_token)(void *elem, void *object, u32 offset);
  278. u32 offset;
  279. };
  280. struct sof_token_info {
  281. const char *name;
  282. const struct sof_topology_token *tokens;
  283. int count;
  284. };
  285. /**
  286. * struct snd_sof_pcm_stream_pipeline_list - List of pipelines associated with a PCM stream
  287. * @pipelines: array of pipelines
  288. * @count: number of pipeline widgets in the @pipe_widgets array
  289. */
  290. struct snd_sof_pcm_stream_pipeline_list {
  291. struct snd_sof_pipeline **pipelines;
  292. u32 count;
  293. };
  294. /* PCM stream, mapped to FW component */
  295. struct snd_sof_pcm_stream {
  296. u32 comp_id;
  297. struct snd_dma_buffer page_table;
  298. struct sof_ipc_stream_posn posn;
  299. struct snd_pcm_substream *substream;
  300. struct snd_compr_stream *cstream;
  301. struct work_struct period_elapsed_work;
  302. struct snd_soc_dapm_widget_list *list; /* list of connected DAPM widgets */
  303. bool d0i3_compatible; /* DSP can be in D0I3 when this pcm is opened */
  304. unsigned int dsp_max_burst_size_in_ms; /* The maximum size of the host DMA burst in ms */
  305. /*
  306. * flag to indicate that the DSP pipelines should be kept
  307. * active or not while suspending the stream
  308. */
  309. bool suspend_ignored;
  310. struct snd_sof_pcm_stream_pipeline_list pipeline_list;
  311. /* used by IPC implementation and core does not touch it */
  312. void *private;
  313. };
  314. /* ALSA SOF PCM device */
  315. struct snd_sof_pcm {
  316. struct snd_soc_component *scomp;
  317. struct snd_sof_pcm_stream stream[2];
  318. struct list_head list; /* list in sdev pcm list */
  319. struct snd_pcm_hw_params params[2];
  320. bool prepared[2]; /* PCM_PARAMS set successfully */
  321. bool pending_stop[2]; /* only used if (!pcm_ops->platform_stop_during_hw_free) */
  322. /* Must be last - ends in a flex-array member. */
  323. struct snd_soc_tplg_pcm pcm;
  324. };
  325. struct snd_sof_led_control {
  326. unsigned int use_led;
  327. unsigned int direction;
  328. int led_value;
  329. };
  330. /* ALSA SOF Kcontrol device */
  331. struct snd_sof_control {
  332. struct snd_soc_component *scomp;
  333. const char *name;
  334. int comp_id;
  335. int min_volume_step; /* min volume step for volume_table */
  336. int max_volume_step; /* max volume step for volume_table */
  337. int num_channels;
  338. unsigned int access;
  339. int info_type;
  340. int index; /* pipeline ID */
  341. void *priv; /* private data copied from topology */
  342. size_t priv_size; /* size of private data */
  343. size_t max_size;
  344. void *ipc_control_data;
  345. void *old_ipc_control_data;
  346. int max; /* applicable to volume controls */
  347. u32 size; /* cdata size */
  348. u32 *volume_table; /* volume table computed from tlv data*/
  349. struct list_head list; /* list in sdev control list */
  350. struct snd_sof_led_control led_ctl;
  351. /* if true, the control's data needs to be updated from Firmware */
  352. bool comp_data_dirty;
  353. };
  354. /** struct snd_sof_dai_link - DAI link info
  355. * @tuples: array of parsed tuples
  356. * @num_tuples: number of tuples in the tuples array
  357. * @link: Pointer to snd_soc_dai_link
  358. * @hw_configs: Pointer to hw configs in topology
  359. * @num_hw_configs: Number of hw configs in topology
  360. * @default_hw_cfg_id: Default hw config ID
  361. * @type: DAI type
  362. * @list: item in snd_sof_dev dai_link list
  363. */
  364. struct snd_sof_dai_link {
  365. struct snd_sof_tuple *tuples;
  366. int num_tuples;
  367. struct snd_soc_dai_link *link;
  368. struct snd_soc_tplg_hw_config *hw_configs;
  369. int num_hw_configs;
  370. int default_hw_cfg_id;
  371. int type;
  372. struct list_head list;
  373. };
  374. /* ASoC SOF DAPM widget */
  375. struct snd_sof_widget {
  376. struct snd_soc_component *scomp;
  377. int comp_id;
  378. int pipeline_id;
  379. /*
  380. * the prepared flag is used to indicate that a widget has been prepared for getting set
  381. * up in the DSP.
  382. */
  383. bool prepared;
  384. struct mutex setup_mutex; /* to protect the swidget setup and free operations */
  385. /*
  386. * use_count is protected by the PCM mutex held by the core and the
  387. * setup_mutex against non stream domain races (kcontrol access for
  388. * example)
  389. */
  390. int use_count;
  391. int core;
  392. int id; /* id is the DAPM widget type */
  393. /*
  394. * Instance ID is set dynamically when the widget gets set up in the FW. It should be
  395. * unique for each module type across all pipelines. This will not be used in SOF_IPC.
  396. */
  397. int instance_id;
  398. /*
  399. * Flag indicating if the widget should be set up dynamically when a PCM is opened.
  400. * This flag is only set for the scheduler type widget in topology. During topology
  401. * loading, this flag is propagated to all the widgets belonging to the same pipeline.
  402. * When this flag is not set, a widget is set up at the time of topology loading
  403. * and retained until the DSP enters D3. It will need to be set up again when resuming
  404. * from D3.
  405. */
  406. bool dynamic_pipeline_widget;
  407. struct snd_soc_dapm_widget *widget;
  408. struct list_head list; /* list in sdev widget list */
  409. struct snd_sof_pipeline *spipe;
  410. void *module_info;
  411. const guid_t uuid;
  412. int num_tuples;
  413. struct snd_sof_tuple *tuples;
  414. /*
  415. * The allowed range for num_input/output_pins is [0, SOF_WIDGET_MAX_NUM_PINS].
  416. * Widgets may have zero input or output pins, for example the tone widget has
  417. * zero input pins.
  418. */
  419. u32 num_input_pins;
  420. u32 num_output_pins;
  421. /*
  422. * The input/output pin binding array, it takes the form of
  423. * [widget_name_connected_to_pin0, widget_name_connected_to_pin1, ...],
  424. * with the index as the queue ID.
  425. *
  426. * The array is used for special pin binding. Note that even if there
  427. * is only one input/output pin requires special pin binding, pin binding
  428. * should be defined for all input/output pins in topology, for pin(s) that
  429. * are not used, give the value "NotConnected".
  430. *
  431. * If pin binding is not defined in topology, nothing to parse in the kernel,
  432. * input_pin_binding and output_pin_binding shall be NULL.
  433. */
  434. char **input_pin_binding;
  435. char **output_pin_binding;
  436. struct ida output_queue_ida;
  437. struct ida input_queue_ida;
  438. void *private; /* core does not touch this */
  439. };
  440. /** struct snd_sof_pipeline - ASoC SOF pipeline
  441. * @pipe_widget: Pointer to the pipeline widget
  442. * @started_count: Count of number of PCM's that have started this pipeline
  443. * @paused_count: Count of number of PCM's that have started and have currently paused this
  444. pipeline
  445. * @complete: flag used to indicate that pipeline set up is complete.
  446. * @core_mask: Mask containing target cores for all modules in the pipeline
  447. * @list: List item in sdev pipeline_list
  448. */
  449. struct snd_sof_pipeline {
  450. struct snd_sof_widget *pipe_widget;
  451. int started_count;
  452. int paused_count;
  453. int complete;
  454. unsigned long core_mask;
  455. struct list_head list;
  456. };
  457. /* ASoC SOF DAPM route */
  458. struct snd_sof_route {
  459. struct snd_soc_component *scomp;
  460. struct snd_soc_dapm_route *route;
  461. struct list_head list; /* list in sdev route list */
  462. struct snd_sof_widget *src_widget;
  463. struct snd_sof_widget *sink_widget;
  464. bool setup;
  465. int src_queue_id;
  466. int dst_queue_id;
  467. void *private;
  468. };
  469. /* ASoC DAI device */
  470. struct snd_sof_dai {
  471. struct snd_soc_component *scomp;
  472. const char *name;
  473. u32 type;
  474. int number_configs;
  475. int current_config;
  476. struct list_head list; /* list in sdev dai list */
  477. /* core should not touch this */
  478. const void *platform_private;
  479. void *private;
  480. };
  481. /*
  482. * Kcontrols.
  483. */
  484. int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
  485. struct snd_ctl_elem_value *ucontrol);
  486. int snd_sof_volume_put(struct snd_kcontrol *kcontrol,
  487. struct snd_ctl_elem_value *ucontrol);
  488. int snd_sof_volume_info(struct snd_kcontrol *kcontrol,
  489. struct snd_ctl_elem_info *uinfo);
  490. int snd_sof_switch_get(struct snd_kcontrol *kcontrol,
  491. struct snd_ctl_elem_value *ucontrol);
  492. int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
  493. struct snd_ctl_elem_value *ucontrol);
  494. int snd_sof_enum_get(struct snd_kcontrol *kcontrol,
  495. struct snd_ctl_elem_value *ucontrol);
  496. int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
  497. struct snd_ctl_elem_value *ucontrol);
  498. int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
  499. struct snd_ctl_elem_value *ucontrol);
  500. int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
  501. struct snd_ctl_elem_value *ucontrol);
  502. int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
  503. const unsigned int __user *binary_data,
  504. unsigned int size);
  505. int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
  506. unsigned int __user *binary_data,
  507. unsigned int size);
  508. int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int __user *binary_data,
  509. unsigned int size);
  510. void snd_sof_control_notify(struct snd_sof_dev *sdev,
  511. struct sof_ipc_ctrl_data *cdata);
  512. /*
  513. * Topology.
  514. * There is no snd_sof_free_topology since topology components will
  515. * be freed by snd_soc_unregister_component,
  516. */
  517. int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file);
  518. /*
  519. * Stream IPC
  520. */
  521. int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp,
  522. struct snd_sof_pcm *spcm, int direction,
  523. struct sof_ipc_stream_posn *posn);
  524. struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
  525. const char *name);
  526. struct snd_sof_widget *
  527. snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
  528. const char *pcm_name, int dir);
  529. struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
  530. const char *name);
  531. static inline
  532. struct snd_sof_pcm *snd_sof_find_spcm_dai(struct snd_soc_component *scomp,
  533. struct snd_soc_pcm_runtime *rtd)
  534. {
  535. struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
  536. struct snd_sof_pcm *spcm;
  537. list_for_each_entry(spcm, &sdev->pcm_list, list) {
  538. if (le32_to_cpu(spcm->pcm.dai_id) == rtd->dai_link->id)
  539. return spcm;
  540. }
  541. return NULL;
  542. }
  543. struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
  544. const char *name);
  545. struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
  546. unsigned int comp_id,
  547. int *direction);
  548. void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream);
  549. void snd_sof_pcm_init_elapsed_work(struct work_struct *work);
  550. #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
  551. void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream);
  552. void snd_sof_compr_init_elapsed_work(struct work_struct *work);
  553. #else
  554. static inline void snd_sof_compr_fragment_elapsed(struct snd_compr_stream *cstream) { }
  555. static inline void snd_sof_compr_init_elapsed_work(struct work_struct *work) { }
  556. #endif
  557. /* DAI link fixup */
  558. int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params);
  559. /* PM */
  560. bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev);
  561. bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev);
  562. /* Machine driver enumeration */
  563. int sof_machine_register(struct snd_sof_dev *sdev, void *pdata);
  564. void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata);
  565. int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
  566. int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
  567. int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
  568. struct snd_soc_dapm_widget *wsink);
  569. /* PCM */
  570. int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
  571. struct snd_pcm_hw_params *fe_params,
  572. struct snd_sof_platform_stream_params *platform_params,
  573. int dir);
  574. int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir);
  575. int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev *sdev,
  576. struct snd_sof_pcm *spcm);
  577. int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
  578. struct snd_sof_pcm *spcm, int dir, bool free_widget_list);
  579. int get_token_u32(void *elem, void *object, u32 offset);
  580. int get_token_u16(void *elem, void *object, u32 offset);
  581. int get_token_comp_format(void *elem, void *object, u32 offset);
  582. int get_token_dai_type(void *elem, void *object, u32 offset);
  583. int get_token_uuid(void *elem, void *object, u32 offset);
  584. int get_token_string(void *elem, void *object, u32 offset);
  585. int sof_update_ipc_object(struct snd_soc_component *scomp, void *object, enum sof_tokens token_id,
  586. struct snd_sof_tuple *tuples, int num_tuples,
  587. size_t object_size, int token_instance_num);
  588. u32 vol_compute_gain(u32 value, int *tlv);
  589. #endif