xref: /openbmc/linux/sound/soc/sof/ops.h (revision e17422cda9d60339d71e117d3fdfd444e83669a4)
1d1d95fcbSLiam Girdwood /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2d1d95fcbSLiam Girdwood /*
3d1d95fcbSLiam Girdwood  * This file is provided under a dual BSD/GPLv2 license.  When using or
4d1d95fcbSLiam Girdwood  * redistributing this file, you may do so under either license.
5d1d95fcbSLiam Girdwood  *
6d1d95fcbSLiam Girdwood  * Copyright(c) 2018 Intel Corporation. All rights reserved.
7d1d95fcbSLiam Girdwood  *
8d1d95fcbSLiam Girdwood  * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9d1d95fcbSLiam Girdwood  */
10d1d95fcbSLiam Girdwood 
11d1d95fcbSLiam Girdwood #ifndef __SOUND_SOC_SOF_IO_H
12d1d95fcbSLiam Girdwood #define __SOUND_SOC_SOF_IO_H
13d1d95fcbSLiam Girdwood 
14d1d95fcbSLiam Girdwood #include <linux/device.h>
15d1d95fcbSLiam Girdwood #include <linux/interrupt.h>
16d1d95fcbSLiam Girdwood #include <linux/kernel.h>
17d1d95fcbSLiam Girdwood #include <linux/types.h>
18d1d95fcbSLiam Girdwood #include <sound/pcm.h>
19d1d95fcbSLiam Girdwood #include "sof-priv.h"
20d1d95fcbSLiam Girdwood 
21d1d95fcbSLiam Girdwood #define sof_ops(sdev) \
22d1d95fcbSLiam Girdwood 	((sdev)->pdata->desc->ops)
23d1d95fcbSLiam Girdwood 
24d1d95fcbSLiam Girdwood /* Mandatory operations are verified during probing */
25d1d95fcbSLiam Girdwood 
26d1d95fcbSLiam Girdwood /* init */
27d1d95fcbSLiam Girdwood static inline int snd_sof_probe(struct snd_sof_dev *sdev)
28d1d95fcbSLiam Girdwood {
29d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->probe(sdev);
30d1d95fcbSLiam Girdwood }
31d1d95fcbSLiam Girdwood 
32d1d95fcbSLiam Girdwood static inline int snd_sof_remove(struct snd_sof_dev *sdev)
33d1d95fcbSLiam Girdwood {
34d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->remove)
35d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->remove(sdev);
36d1d95fcbSLiam Girdwood 
37d1d95fcbSLiam Girdwood 	return 0;
38d1d95fcbSLiam Girdwood }
39d1d95fcbSLiam Girdwood 
40d1d95fcbSLiam Girdwood /* control */
41d1d95fcbSLiam Girdwood 
42d1d95fcbSLiam Girdwood /*
43d1d95fcbSLiam Girdwood  * snd_sof_dsp_run returns the core mask of the cores that are available
44d1d95fcbSLiam Girdwood  * after successful fw boot
45d1d95fcbSLiam Girdwood  */
46d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_run(struct snd_sof_dev *sdev)
47d1d95fcbSLiam Girdwood {
48d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->run(sdev);
49d1d95fcbSLiam Girdwood }
50d1d95fcbSLiam Girdwood 
51d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_stall(struct snd_sof_dev *sdev)
52d1d95fcbSLiam Girdwood {
53d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->stall)
54d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->stall(sdev);
55d1d95fcbSLiam Girdwood 
56d1d95fcbSLiam Girdwood 	return 0;
57d1d95fcbSLiam Girdwood }
58d1d95fcbSLiam Girdwood 
59d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_reset(struct snd_sof_dev *sdev)
60d1d95fcbSLiam Girdwood {
61d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->reset)
62d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->reset(sdev);
63d1d95fcbSLiam Girdwood 
64d1d95fcbSLiam Girdwood 	return 0;
65d1d95fcbSLiam Girdwood }
66d1d95fcbSLiam Girdwood 
67d1d95fcbSLiam Girdwood /* dsp core power up/power down */
68d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_core_power_up(struct snd_sof_dev *sdev,
69d1d95fcbSLiam Girdwood 					    unsigned int core_mask)
70d1d95fcbSLiam Girdwood {
71d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->core_power_up)
72d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->core_power_up(sdev, core_mask);
73d1d95fcbSLiam Girdwood 
74d1d95fcbSLiam Girdwood 	return 0;
75d1d95fcbSLiam Girdwood }
76d1d95fcbSLiam Girdwood 
77d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_core_power_down(struct snd_sof_dev *sdev,
78d1d95fcbSLiam Girdwood 					      unsigned int core_mask)
79d1d95fcbSLiam Girdwood {
80d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->core_power_down)
81d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->core_power_down(sdev, core_mask);
82d1d95fcbSLiam Girdwood 
83d1d95fcbSLiam Girdwood 	return 0;
84d1d95fcbSLiam Girdwood }
85d1d95fcbSLiam Girdwood 
86d1d95fcbSLiam Girdwood /* pre/post fw load */
87d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_pre_fw_run(struct snd_sof_dev *sdev)
88d1d95fcbSLiam Girdwood {
89d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->pre_fw_run)
90d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pre_fw_run(sdev);
91d1d95fcbSLiam Girdwood 
92d1d95fcbSLiam Girdwood 	return 0;
93d1d95fcbSLiam Girdwood }
94d1d95fcbSLiam Girdwood 
95d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_post_fw_run(struct snd_sof_dev *sdev)
96d1d95fcbSLiam Girdwood {
97d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->post_fw_run)
98d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->post_fw_run(sdev);
99d1d95fcbSLiam Girdwood 
100d1d95fcbSLiam Girdwood 	return 0;
101d1d95fcbSLiam Girdwood }
102d1d95fcbSLiam Girdwood 
103ce8234a6SDaniel Baluta /* misc */
104ce8234a6SDaniel Baluta 
105ce8234a6SDaniel Baluta /**
106ce8234a6SDaniel Baluta  * snd_sof_dsp_get_bar_index - Maps a section type with a BAR index
107ce8234a6SDaniel Baluta  *
108ce8234a6SDaniel Baluta  * @sdev: sof device
109ce8234a6SDaniel Baluta  * @type: section type as described by snd_sof_fw_blk_type
110ce8234a6SDaniel Baluta  *
111ce8234a6SDaniel Baluta  * Returns the corresponding BAR index (a positive integer) or -EINVAL
112ce8234a6SDaniel Baluta  * in case there is no mapping
113ce8234a6SDaniel Baluta  */
114ce8234a6SDaniel Baluta static inline int snd_sof_dsp_get_bar_index(struct snd_sof_dev *sdev, u32 type)
115ce8234a6SDaniel Baluta {
116ce8234a6SDaniel Baluta 	if (sof_ops(sdev)->get_bar_index)
117ce8234a6SDaniel Baluta 		return sof_ops(sdev)->get_bar_index(sdev, type);
118ce8234a6SDaniel Baluta 
119ce8234a6SDaniel Baluta 	return sdev->mmio_bar;
120ce8234a6SDaniel Baluta }
121ce8234a6SDaniel Baluta 
122bb9c93f5SDaniel Baluta static inline int snd_sof_dsp_get_mailbox_offset(struct snd_sof_dev *sdev)
123bb9c93f5SDaniel Baluta {
124bb9c93f5SDaniel Baluta 	if (sof_ops(sdev)->get_mailbox_offset)
125bb9c93f5SDaniel Baluta 		return sof_ops(sdev)->get_mailbox_offset(sdev);
126bb9c93f5SDaniel Baluta 
127bb9c93f5SDaniel Baluta 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
128bb9c93f5SDaniel Baluta 	return -ENOTSUPP;
129bb9c93f5SDaniel Baluta }
130bb9c93f5SDaniel Baluta 
131*e17422cdSDaniel Baluta static inline int snd_sof_dsp_get_window_offset(struct snd_sof_dev *sdev,
132*e17422cdSDaniel Baluta 						u32 id)
133*e17422cdSDaniel Baluta {
134*e17422cdSDaniel Baluta 	if (sof_ops(sdev)->get_window_offset)
135*e17422cdSDaniel Baluta 		return sof_ops(sdev)->get_window_offset(sdev, id);
136*e17422cdSDaniel Baluta 
137*e17422cdSDaniel Baluta 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
138*e17422cdSDaniel Baluta 	return -ENOTSUPP;
139*e17422cdSDaniel Baluta }
140d1d95fcbSLiam Girdwood /* power management */
141d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_resume(struct snd_sof_dev *sdev)
142d1d95fcbSLiam Girdwood {
143d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->resume)
144d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->resume(sdev);
145d1d95fcbSLiam Girdwood 
146d1d95fcbSLiam Girdwood 	return 0;
147d1d95fcbSLiam Girdwood }
148d1d95fcbSLiam Girdwood 
1491c38c922SFred Oh static inline int snd_sof_dsp_suspend(struct snd_sof_dev *sdev)
150d1d95fcbSLiam Girdwood {
151d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->suspend)
1521c38c922SFred Oh 		return sof_ops(sdev)->suspend(sdev);
153d1d95fcbSLiam Girdwood 
154d1d95fcbSLiam Girdwood 	return 0;
155d1d95fcbSLiam Girdwood }
156d1d95fcbSLiam Girdwood 
157d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_runtime_resume(struct snd_sof_dev *sdev)
158d1d95fcbSLiam Girdwood {
159d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->runtime_resume)
160d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->runtime_resume(sdev);
161d1d95fcbSLiam Girdwood 
162d1d95fcbSLiam Girdwood 	return 0;
163d1d95fcbSLiam Girdwood }
164d1d95fcbSLiam Girdwood 
1651c38c922SFred Oh static inline int snd_sof_dsp_runtime_suspend(struct snd_sof_dev *sdev)
166d1d95fcbSLiam Girdwood {
167d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->runtime_suspend)
1681c38c922SFred Oh 		return sof_ops(sdev)->runtime_suspend(sdev);
169d1d95fcbSLiam Girdwood 
170d1d95fcbSLiam Girdwood 	return 0;
171d1d95fcbSLiam Girdwood }
172d1d95fcbSLiam Girdwood 
17362fde977SKai Vehmanen static inline int snd_sof_dsp_runtime_idle(struct snd_sof_dev *sdev)
17462fde977SKai Vehmanen {
17562fde977SKai Vehmanen 	if (sof_ops(sdev)->runtime_idle)
17662fde977SKai Vehmanen 		return sof_ops(sdev)->runtime_idle(sdev);
17762fde977SKai Vehmanen 
17862fde977SKai Vehmanen 	return 0;
17962fde977SKai Vehmanen }
18062fde977SKai Vehmanen 
1817077a07aSRanjani Sridharan static inline int snd_sof_dsp_hw_params_upon_resume(struct snd_sof_dev *sdev)
182ed3baacdSRanjani Sridharan {
183ed3baacdSRanjani Sridharan 	if (sof_ops(sdev)->set_hw_params_upon_resume)
1847077a07aSRanjani Sridharan 		return sof_ops(sdev)->set_hw_params_upon_resume(sdev);
1857077a07aSRanjani Sridharan 	return 0;
186ed3baacdSRanjani Sridharan }
187ed3baacdSRanjani Sridharan 
188d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_set_clk(struct snd_sof_dev *sdev, u32 freq)
189d1d95fcbSLiam Girdwood {
190d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->set_clk)
191d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->set_clk(sdev, freq);
192d1d95fcbSLiam Girdwood 
193d1d95fcbSLiam Girdwood 	return 0;
194d1d95fcbSLiam Girdwood }
195d1d95fcbSLiam Girdwood 
196d1d95fcbSLiam Girdwood /* debug */
197d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_dbg_dump(struct snd_sof_dev *sdev, u32 flags)
198d1d95fcbSLiam Girdwood {
199d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->dbg_dump)
200d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->dbg_dump(sdev, flags);
201d1d95fcbSLiam Girdwood }
202d1d95fcbSLiam Girdwood 
2035e4a27fdSPan Xiuli static inline void snd_sof_ipc_dump(struct snd_sof_dev *sdev)
2045e4a27fdSPan Xiuli {
2055e4a27fdSPan Xiuli 	if (sof_ops(sdev)->ipc_dump)
2065e4a27fdSPan Xiuli 		return sof_ops(sdev)->ipc_dump(sdev);
2075e4a27fdSPan Xiuli }
2085e4a27fdSPan Xiuli 
209d1d95fcbSLiam Girdwood /* register IO */
210d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write(struct snd_sof_dev *sdev, u32 bar,
211d1d95fcbSLiam Girdwood 				     u32 offset, u32 value)
212d1d95fcbSLiam Girdwood {
213d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->write) {
214d1d95fcbSLiam Girdwood 		sof_ops(sdev)->write(sdev, sdev->bar[bar] + offset, value);
215d1d95fcbSLiam Girdwood 		return;
216d1d95fcbSLiam Girdwood 	}
217d1d95fcbSLiam Girdwood 
218d1d95fcbSLiam Girdwood 	dev_err_ratelimited(sdev->dev, "error: %s not defined\n", __func__);
219d1d95fcbSLiam Girdwood }
220d1d95fcbSLiam Girdwood 
221d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write64(struct snd_sof_dev *sdev, u32 bar,
222d1d95fcbSLiam Girdwood 				       u32 offset, u64 value)
223d1d95fcbSLiam Girdwood {
224d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->write64) {
225d1d95fcbSLiam Girdwood 		sof_ops(sdev)->write64(sdev, sdev->bar[bar] + offset, value);
226d1d95fcbSLiam Girdwood 		return;
227d1d95fcbSLiam Girdwood 	}
228d1d95fcbSLiam Girdwood 
229d1d95fcbSLiam Girdwood 	dev_err_ratelimited(sdev->dev, "error: %s not defined\n", __func__);
230d1d95fcbSLiam Girdwood }
231d1d95fcbSLiam Girdwood 
232d1d95fcbSLiam Girdwood static inline u32 snd_sof_dsp_read(struct snd_sof_dev *sdev, u32 bar,
233d1d95fcbSLiam Girdwood 				   u32 offset)
234d1d95fcbSLiam Girdwood {
235d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->read)
236d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->read(sdev, sdev->bar[bar] + offset);
237d1d95fcbSLiam Girdwood 
238d1d95fcbSLiam Girdwood 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
239d1d95fcbSLiam Girdwood 	return -ENOTSUPP;
240d1d95fcbSLiam Girdwood }
241d1d95fcbSLiam Girdwood 
242d1d95fcbSLiam Girdwood static inline u64 snd_sof_dsp_read64(struct snd_sof_dev *sdev, u32 bar,
243d1d95fcbSLiam Girdwood 				     u32 offset)
244d1d95fcbSLiam Girdwood {
245d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->read64)
246d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->read64(sdev, sdev->bar[bar] + offset);
247d1d95fcbSLiam Girdwood 
248d1d95fcbSLiam Girdwood 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
249d1d95fcbSLiam Girdwood 	return -ENOTSUPP;
250d1d95fcbSLiam Girdwood }
251d1d95fcbSLiam Girdwood 
252d1d95fcbSLiam Girdwood /* block IO */
253d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_block_read(struct snd_sof_dev *sdev, u32 bar,
254d1d95fcbSLiam Girdwood 					  u32 offset, void *dest, size_t bytes)
255d1d95fcbSLiam Girdwood {
256d1d95fcbSLiam Girdwood 	sof_ops(sdev)->block_read(sdev, bar, offset, dest, bytes);
257d1d95fcbSLiam Girdwood }
258d1d95fcbSLiam Girdwood 
259d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_block_write(struct snd_sof_dev *sdev, u32 bar,
260d1d95fcbSLiam Girdwood 					   u32 offset, void *src, size_t bytes)
261d1d95fcbSLiam Girdwood {
262d1d95fcbSLiam Girdwood 	sof_ops(sdev)->block_write(sdev, bar, offset, src, bytes);
263d1d95fcbSLiam Girdwood }
264d1d95fcbSLiam Girdwood 
265d1d95fcbSLiam Girdwood /* ipc */
266d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_send_msg(struct snd_sof_dev *sdev,
267d1d95fcbSLiam Girdwood 				       struct snd_sof_ipc_msg *msg)
268d1d95fcbSLiam Girdwood {
269d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->send_msg(sdev, msg);
270d1d95fcbSLiam Girdwood }
271d1d95fcbSLiam Girdwood 
272d1d95fcbSLiam Girdwood /* host DMA trace */
273d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_init(struct snd_sof_dev *sdev,
274d1d95fcbSLiam Girdwood 					 u32 *stream_tag)
275d1d95fcbSLiam Girdwood {
276d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_init)
277d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_init(sdev, stream_tag);
278d1d95fcbSLiam Girdwood 
279d1d95fcbSLiam Girdwood 	return 0;
280d1d95fcbSLiam Girdwood }
281d1d95fcbSLiam Girdwood 
282d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_release(struct snd_sof_dev *sdev)
283d1d95fcbSLiam Girdwood {
284d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_release)
285d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_release(sdev);
286d1d95fcbSLiam Girdwood 
287d1d95fcbSLiam Girdwood 	return 0;
288d1d95fcbSLiam Girdwood }
289d1d95fcbSLiam Girdwood 
290d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_trigger(struct snd_sof_dev *sdev, int cmd)
291d1d95fcbSLiam Girdwood {
292d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_trigger)
293d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_trigger(sdev, cmd);
294d1d95fcbSLiam Girdwood 
295d1d95fcbSLiam Girdwood 	return 0;
296d1d95fcbSLiam Girdwood }
297d1d95fcbSLiam Girdwood 
298d1d95fcbSLiam Girdwood /* host PCM ops */
299d1d95fcbSLiam Girdwood static inline int
300d1d95fcbSLiam Girdwood snd_sof_pcm_platform_open(struct snd_sof_dev *sdev,
301d1d95fcbSLiam Girdwood 			  struct snd_pcm_substream *substream)
302d1d95fcbSLiam Girdwood {
303d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_open)
304d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_open(sdev, substream);
305d1d95fcbSLiam Girdwood 
306d1d95fcbSLiam Girdwood 	return 0;
307d1d95fcbSLiam Girdwood }
308d1d95fcbSLiam Girdwood 
309d1d95fcbSLiam Girdwood /* disconnect pcm substream to a host stream */
310d1d95fcbSLiam Girdwood static inline int
311d1d95fcbSLiam Girdwood snd_sof_pcm_platform_close(struct snd_sof_dev *sdev,
312d1d95fcbSLiam Girdwood 			   struct snd_pcm_substream *substream)
313d1d95fcbSLiam Girdwood {
314d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_close)
315d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_close(sdev, substream);
316d1d95fcbSLiam Girdwood 
317d1d95fcbSLiam Girdwood 	return 0;
318d1d95fcbSLiam Girdwood }
319d1d95fcbSLiam Girdwood 
320d1d95fcbSLiam Girdwood /* host stream hw params */
321d1d95fcbSLiam Girdwood static inline int
322d1d95fcbSLiam Girdwood snd_sof_pcm_platform_hw_params(struct snd_sof_dev *sdev,
323d1d95fcbSLiam Girdwood 			       struct snd_pcm_substream *substream,
324d1d95fcbSLiam Girdwood 			       struct snd_pcm_hw_params *params,
325d1d95fcbSLiam Girdwood 			       struct sof_ipc_stream_params *ipc_params)
326d1d95fcbSLiam Girdwood {
327d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_hw_params)
328d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_hw_params(sdev, substream,
329d1d95fcbSLiam Girdwood 						    params, ipc_params);
330d1d95fcbSLiam Girdwood 
331d1d95fcbSLiam Girdwood 	return 0;
332d1d95fcbSLiam Girdwood }
333d1d95fcbSLiam Girdwood 
33493146bc2SRanjani Sridharan /* host stream hw free */
33593146bc2SRanjani Sridharan static inline int
33693146bc2SRanjani Sridharan snd_sof_pcm_platform_hw_free(struct snd_sof_dev *sdev,
33793146bc2SRanjani Sridharan 			     struct snd_pcm_substream *substream)
33893146bc2SRanjani Sridharan {
33993146bc2SRanjani Sridharan 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_hw_free)
34093146bc2SRanjani Sridharan 		return sof_ops(sdev)->pcm_hw_free(sdev, substream);
34193146bc2SRanjani Sridharan 
34293146bc2SRanjani Sridharan 	return 0;
34393146bc2SRanjani Sridharan }
34493146bc2SRanjani Sridharan 
345d1d95fcbSLiam Girdwood /* host stream trigger */
346d1d95fcbSLiam Girdwood static inline int
347d1d95fcbSLiam Girdwood snd_sof_pcm_platform_trigger(struct snd_sof_dev *sdev,
348d1d95fcbSLiam Girdwood 			     struct snd_pcm_substream *substream, int cmd)
349d1d95fcbSLiam Girdwood {
350d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_trigger)
351d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_trigger(sdev, substream, cmd);
352d1d95fcbSLiam Girdwood 
353d1d95fcbSLiam Girdwood 	return 0;
354d1d95fcbSLiam Girdwood }
355d1d95fcbSLiam Girdwood 
356d1d95fcbSLiam Girdwood /* host DSP message data */
357d1d95fcbSLiam Girdwood static inline void snd_sof_ipc_msg_data(struct snd_sof_dev *sdev,
358d1d95fcbSLiam Girdwood 					struct snd_pcm_substream *substream,
359d1d95fcbSLiam Girdwood 					void *p, size_t sz)
360d1d95fcbSLiam Girdwood {
361d1d95fcbSLiam Girdwood 	sof_ops(sdev)->ipc_msg_data(sdev, substream, p, sz);
362d1d95fcbSLiam Girdwood }
363d1d95fcbSLiam Girdwood 
364d1d95fcbSLiam Girdwood /* host configure DSP HW parameters */
365d1d95fcbSLiam Girdwood static inline int
366d1d95fcbSLiam Girdwood snd_sof_ipc_pcm_params(struct snd_sof_dev *sdev,
367d1d95fcbSLiam Girdwood 		       struct snd_pcm_substream *substream,
368d1d95fcbSLiam Girdwood 		       const struct sof_ipc_pcm_params_reply *reply)
369d1d95fcbSLiam Girdwood {
370d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->ipc_pcm_params(sdev, substream, reply);
371d1d95fcbSLiam Girdwood }
372d1d95fcbSLiam Girdwood 
373d1d95fcbSLiam Girdwood /* host stream pointer */
374d1d95fcbSLiam Girdwood static inline snd_pcm_uframes_t
375d1d95fcbSLiam Girdwood snd_sof_pcm_platform_pointer(struct snd_sof_dev *sdev,
376d1d95fcbSLiam Girdwood 			     struct snd_pcm_substream *substream)
377d1d95fcbSLiam Girdwood {
378d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_pointer)
379d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_pointer(sdev, substream);
380d1d95fcbSLiam Girdwood 
381d1d95fcbSLiam Girdwood 	return 0;
382d1d95fcbSLiam Girdwood }
383d1d95fcbSLiam Girdwood 
384d1d95fcbSLiam Girdwood static inline const struct snd_sof_dsp_ops
385d1d95fcbSLiam Girdwood *sof_get_ops(const struct sof_dev_desc *d,
386d1d95fcbSLiam Girdwood 	     const struct sof_ops_table mach_ops[], int asize)
387d1d95fcbSLiam Girdwood {
388d1d95fcbSLiam Girdwood 	int i;
389d1d95fcbSLiam Girdwood 
390d1d95fcbSLiam Girdwood 	for (i = 0; i < asize; i++) {
391d1d95fcbSLiam Girdwood 		if (d == mach_ops[i].desc)
392d1d95fcbSLiam Girdwood 			return mach_ops[i].ops;
393d1d95fcbSLiam Girdwood 	}
394d1d95fcbSLiam Girdwood 
395d1d95fcbSLiam Girdwood 	/* not found */
396d1d95fcbSLiam Girdwood 	return NULL;
397d1d95fcbSLiam Girdwood }
398d1d95fcbSLiam Girdwood 
399d1d95fcbSLiam Girdwood /**
400d1d95fcbSLiam Girdwood  * snd_sof_dsp_register_poll_timeout - Periodically poll an address
401d1d95fcbSLiam Girdwood  * until a condition is met or a timeout occurs
402d1d95fcbSLiam Girdwood  * @op: accessor function (takes @addr as its only argument)
403d1d95fcbSLiam Girdwood  * @addr: Address to poll
404d1d95fcbSLiam Girdwood  * @val: Variable to read the value into
405d1d95fcbSLiam Girdwood  * @cond: Break condition (usually involving @val)
406d1d95fcbSLiam Girdwood  * @sleep_us: Maximum time to sleep between reads in us (0
407d1d95fcbSLiam Girdwood  *            tight-loops).  Should be less than ~20ms since usleep_range
408458f69efSMauro Carvalho Chehab  *            is used (see Documentation/timers/timers-howto.rst).
409d1d95fcbSLiam Girdwood  * @timeout_us: Timeout in us, 0 means never timeout
410d1d95fcbSLiam Girdwood  *
411d1d95fcbSLiam Girdwood  * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
412d1d95fcbSLiam Girdwood  * case, the last read value at @addr is stored in @val. Must not
413d1d95fcbSLiam Girdwood  * be called from atomic context if sleep_us or timeout_us are used.
414d1d95fcbSLiam Girdwood  *
415d1d95fcbSLiam Girdwood  * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
416d1d95fcbSLiam Girdwood  */
417d1d95fcbSLiam Girdwood #define snd_sof_dsp_read_poll_timeout(sdev, bar, offset, val, cond, sleep_us, timeout_us) \
418d1d95fcbSLiam Girdwood ({ \
419d1d95fcbSLiam Girdwood 	u64 __timeout_us = (timeout_us); \
420d1d95fcbSLiam Girdwood 	unsigned long __sleep_us = (sleep_us); \
421d1d95fcbSLiam Girdwood 	ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
422d1d95fcbSLiam Girdwood 	might_sleep_if((__sleep_us) != 0); \
423d1d95fcbSLiam Girdwood 	for (;;) {							\
424d1d95fcbSLiam Girdwood 		(val) = snd_sof_dsp_read(sdev, bar, offset);		\
425d1d95fcbSLiam Girdwood 		if (cond) { \
426d1d95fcbSLiam Girdwood 			dev_dbg(sdev->dev, \
427d1d95fcbSLiam Girdwood 				"FW Poll Status: reg=%#x successful\n", (val)); \
428d1d95fcbSLiam Girdwood 			break; \
429d1d95fcbSLiam Girdwood 		} \
430d1d95fcbSLiam Girdwood 		if (__timeout_us && \
431d1d95fcbSLiam Girdwood 		    ktime_compare(ktime_get(), __timeout) > 0) { \
432d1d95fcbSLiam Girdwood 			(val) = snd_sof_dsp_read(sdev, bar, offset); \
433d1d95fcbSLiam Girdwood 			dev_dbg(sdev->dev, \
434d1d95fcbSLiam Girdwood 				"FW Poll Status: reg=%#x timedout\n", (val)); \
435d1d95fcbSLiam Girdwood 			break; \
436d1d95fcbSLiam Girdwood 		} \
437d1d95fcbSLiam Girdwood 		if (__sleep_us) \
438d1d95fcbSLiam Girdwood 			usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
439d1d95fcbSLiam Girdwood 	} \
440d1d95fcbSLiam Girdwood 	(cond) ? 0 : -ETIMEDOUT; \
441d1d95fcbSLiam Girdwood })
442d1d95fcbSLiam Girdwood 
443d1d95fcbSLiam Girdwood /* This is for registers bits with attribute RWC */
444d1d95fcbSLiam Girdwood bool snd_sof_pci_update_bits(struct snd_sof_dev *sdev, u32 offset,
445d1d95fcbSLiam Girdwood 			     u32 mask, u32 value);
446d1d95fcbSLiam Girdwood 
447d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits_unlocked(struct snd_sof_dev *sdev, u32 bar,
448d1d95fcbSLiam Girdwood 				      u32 offset, u32 mask, u32 value);
449d1d95fcbSLiam Girdwood 
450d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64_unlocked(struct snd_sof_dev *sdev, u32 bar,
451d1d95fcbSLiam Girdwood 					u32 offset, u64 mask, u64 value);
452d1d95fcbSLiam Girdwood 
453d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits(struct snd_sof_dev *sdev, u32 bar, u32 offset,
454d1d95fcbSLiam Girdwood 			     u32 mask, u32 value);
455d1d95fcbSLiam Girdwood 
456d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64(struct snd_sof_dev *sdev, u32 bar,
457d1d95fcbSLiam Girdwood 			       u32 offset, u64 mask, u64 value);
458d1d95fcbSLiam Girdwood 
459d1d95fcbSLiam Girdwood void snd_sof_dsp_update_bits_forced(struct snd_sof_dev *sdev, u32 bar,
460d1d95fcbSLiam Girdwood 				    u32 offset, u32 mask, u32 value);
461d1d95fcbSLiam Girdwood 
462d1d95fcbSLiam Girdwood int snd_sof_dsp_register_poll(struct snd_sof_dev *sdev, u32 bar, u32 offset,
463d1d95fcbSLiam Girdwood 			      u32 mask, u32 target, u32 timeout_ms,
464d1d95fcbSLiam Girdwood 			      u32 interval_us);
465d1d95fcbSLiam Girdwood 
466d1d95fcbSLiam Girdwood void snd_sof_dsp_panic(struct snd_sof_dev *sdev, u32 offset);
467d1d95fcbSLiam Girdwood #endif
468