xref: /openbmc/linux/sound/soc/sof/ops.h (revision 7edb3051f11683640c38b93e183ef1676090a79b)
1e149ca29SPierre-Louis Bossart /* SPDX-License-Identifier: (GPL-2.0-only 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 
40*7edb3051SKeyon Jie static inline int snd_sof_shutdown(struct snd_sof_dev *sdev)
41*7edb3051SKeyon Jie {
42*7edb3051SKeyon Jie 	if (sof_ops(sdev)->shutdown)
43*7edb3051SKeyon Jie 		return sof_ops(sdev)->shutdown(sdev);
44*7edb3051SKeyon Jie 
45*7edb3051SKeyon Jie 	return 0;
46*7edb3051SKeyon Jie }
47*7edb3051SKeyon Jie 
48d1d95fcbSLiam Girdwood /* control */
49d1d95fcbSLiam Girdwood 
50d1d95fcbSLiam Girdwood /*
51d1d95fcbSLiam Girdwood  * snd_sof_dsp_run returns the core mask of the cores that are available
52d1d95fcbSLiam Girdwood  * after successful fw boot
53d1d95fcbSLiam Girdwood  */
54d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_run(struct snd_sof_dev *sdev)
55d1d95fcbSLiam Girdwood {
56d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->run(sdev);
57d1d95fcbSLiam Girdwood }
58d1d95fcbSLiam Girdwood 
59a70eb708SFred Oh static inline int snd_sof_dsp_stall(struct snd_sof_dev *sdev, unsigned int core_mask)
60d1d95fcbSLiam Girdwood {
61d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->stall)
62a70eb708SFred Oh 		return sof_ops(sdev)->stall(sdev, core_mask);
63d1d95fcbSLiam Girdwood 
64d1d95fcbSLiam Girdwood 	return 0;
65d1d95fcbSLiam Girdwood }
66d1d95fcbSLiam Girdwood 
67d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_reset(struct snd_sof_dev *sdev)
68d1d95fcbSLiam Girdwood {
69d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->reset)
70d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->reset(sdev);
71d1d95fcbSLiam Girdwood 
72d1d95fcbSLiam Girdwood 	return 0;
73d1d95fcbSLiam Girdwood }
74d1d95fcbSLiam Girdwood 
75d1d95fcbSLiam Girdwood /* dsp core power up/power down */
76d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_core_power_up(struct snd_sof_dev *sdev,
77d1d95fcbSLiam Girdwood 					    unsigned int core_mask)
78d1d95fcbSLiam Girdwood {
79d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->core_power_up)
80d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->core_power_up(sdev, core_mask);
81d1d95fcbSLiam Girdwood 
82d1d95fcbSLiam Girdwood 	return 0;
83d1d95fcbSLiam Girdwood }
84d1d95fcbSLiam Girdwood 
85d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_core_power_down(struct snd_sof_dev *sdev,
86d1d95fcbSLiam Girdwood 					      unsigned int core_mask)
87d1d95fcbSLiam Girdwood {
88d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->core_power_down)
89d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->core_power_down(sdev, core_mask);
90d1d95fcbSLiam Girdwood 
91d1d95fcbSLiam Girdwood 	return 0;
92d1d95fcbSLiam Girdwood }
93d1d95fcbSLiam Girdwood 
94d1d95fcbSLiam Girdwood /* pre/post fw load */
95d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_pre_fw_run(struct snd_sof_dev *sdev)
96d1d95fcbSLiam Girdwood {
97d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->pre_fw_run)
98d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pre_fw_run(sdev);
99d1d95fcbSLiam Girdwood 
100d1d95fcbSLiam Girdwood 	return 0;
101d1d95fcbSLiam Girdwood }
102d1d95fcbSLiam Girdwood 
103d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_post_fw_run(struct snd_sof_dev *sdev)
104d1d95fcbSLiam Girdwood {
105d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->post_fw_run)
106d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->post_fw_run(sdev);
107d1d95fcbSLiam Girdwood 
108d1d95fcbSLiam Girdwood 	return 0;
109d1d95fcbSLiam Girdwood }
110d1d95fcbSLiam Girdwood 
111e984f3efSFred Oh /* parse platform specific extended manifest */
112e984f3efSFred Oh static inline int snd_sof_dsp_parse_platform_ext_manifest(struct snd_sof_dev *sdev,
113e984f3efSFred Oh 							  const struct sof_ext_man_elem_header *hdr)
114e984f3efSFred Oh {
115e984f3efSFred Oh 	if (sof_ops(sdev)->parse_platform_ext_manifest)
116e984f3efSFred Oh 		return sof_ops(sdev)->parse_platform_ext_manifest(sdev, hdr);
117e984f3efSFred Oh 
118e984f3efSFred Oh 	return 0;
119e984f3efSFred Oh }
120e984f3efSFred Oh 
121ce8234a6SDaniel Baluta /* misc */
122ce8234a6SDaniel Baluta 
123ce8234a6SDaniel Baluta /**
124ce8234a6SDaniel Baluta  * snd_sof_dsp_get_bar_index - Maps a section type with a BAR index
125ce8234a6SDaniel Baluta  *
126ce8234a6SDaniel Baluta  * @sdev: sof device
127ce8234a6SDaniel Baluta  * @type: section type as described by snd_sof_fw_blk_type
128ce8234a6SDaniel Baluta  *
129ce8234a6SDaniel Baluta  * Returns the corresponding BAR index (a positive integer) or -EINVAL
130ce8234a6SDaniel Baluta  * in case there is no mapping
131ce8234a6SDaniel Baluta  */
132ce8234a6SDaniel Baluta static inline int snd_sof_dsp_get_bar_index(struct snd_sof_dev *sdev, u32 type)
133ce8234a6SDaniel Baluta {
134ce8234a6SDaniel Baluta 	if (sof_ops(sdev)->get_bar_index)
135ce8234a6SDaniel Baluta 		return sof_ops(sdev)->get_bar_index(sdev, type);
136ce8234a6SDaniel Baluta 
137ce8234a6SDaniel Baluta 	return sdev->mmio_bar;
138ce8234a6SDaniel Baluta }
139ce8234a6SDaniel Baluta 
140bb9c93f5SDaniel Baluta static inline int snd_sof_dsp_get_mailbox_offset(struct snd_sof_dev *sdev)
141bb9c93f5SDaniel Baluta {
142bb9c93f5SDaniel Baluta 	if (sof_ops(sdev)->get_mailbox_offset)
143bb9c93f5SDaniel Baluta 		return sof_ops(sdev)->get_mailbox_offset(sdev);
144bb9c93f5SDaniel Baluta 
145bb9c93f5SDaniel Baluta 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
146bb9c93f5SDaniel Baluta 	return -ENOTSUPP;
147bb9c93f5SDaniel Baluta }
148bb9c93f5SDaniel Baluta 
149e17422cdSDaniel Baluta static inline int snd_sof_dsp_get_window_offset(struct snd_sof_dev *sdev,
150e17422cdSDaniel Baluta 						u32 id)
151e17422cdSDaniel Baluta {
152e17422cdSDaniel Baluta 	if (sof_ops(sdev)->get_window_offset)
153e17422cdSDaniel Baluta 		return sof_ops(sdev)->get_window_offset(sdev, id);
154e17422cdSDaniel Baluta 
155e17422cdSDaniel Baluta 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
156e17422cdSDaniel Baluta 	return -ENOTSUPP;
157e17422cdSDaniel Baluta }
158d1d95fcbSLiam Girdwood /* power management */
159d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_resume(struct snd_sof_dev *sdev)
160d1d95fcbSLiam Girdwood {
161d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->resume)
162d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->resume(sdev);
163d1d95fcbSLiam Girdwood 
164d1d95fcbSLiam Girdwood 	return 0;
165d1d95fcbSLiam Girdwood }
166d1d95fcbSLiam Girdwood 
16761e285caSRanjani Sridharan static inline int snd_sof_dsp_suspend(struct snd_sof_dev *sdev,
16861e285caSRanjani Sridharan 				      u32 target_state)
169d1d95fcbSLiam Girdwood {
170d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->suspend)
17161e285caSRanjani Sridharan 		return sof_ops(sdev)->suspend(sdev, target_state);
172d1d95fcbSLiam Girdwood 
173d1d95fcbSLiam Girdwood 	return 0;
174d1d95fcbSLiam Girdwood }
175d1d95fcbSLiam Girdwood 
176d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_runtime_resume(struct snd_sof_dev *sdev)
177d1d95fcbSLiam Girdwood {
178d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->runtime_resume)
179d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->runtime_resume(sdev);
180d1d95fcbSLiam Girdwood 
181d1d95fcbSLiam Girdwood 	return 0;
182d1d95fcbSLiam Girdwood }
183d1d95fcbSLiam Girdwood 
1841c38c922SFred Oh static inline int snd_sof_dsp_runtime_suspend(struct snd_sof_dev *sdev)
185d1d95fcbSLiam Girdwood {
186d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->runtime_suspend)
1871c38c922SFred Oh 		return sof_ops(sdev)->runtime_suspend(sdev);
188d1d95fcbSLiam Girdwood 
189d1d95fcbSLiam Girdwood 	return 0;
190d1d95fcbSLiam Girdwood }
191d1d95fcbSLiam Girdwood 
19262fde977SKai Vehmanen static inline int snd_sof_dsp_runtime_idle(struct snd_sof_dev *sdev)
19362fde977SKai Vehmanen {
19462fde977SKai Vehmanen 	if (sof_ops(sdev)->runtime_idle)
19562fde977SKai Vehmanen 		return sof_ops(sdev)->runtime_idle(sdev);
19662fde977SKai Vehmanen 
19762fde977SKai Vehmanen 	return 0;
19862fde977SKai Vehmanen }
19962fde977SKai Vehmanen 
2007077a07aSRanjani Sridharan static inline int snd_sof_dsp_hw_params_upon_resume(struct snd_sof_dev *sdev)
201ed3baacdSRanjani Sridharan {
202ed3baacdSRanjani Sridharan 	if (sof_ops(sdev)->set_hw_params_upon_resume)
2037077a07aSRanjani Sridharan 		return sof_ops(sdev)->set_hw_params_upon_resume(sdev);
2047077a07aSRanjani Sridharan 	return 0;
205ed3baacdSRanjani Sridharan }
206ed3baacdSRanjani Sridharan 
207d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_set_clk(struct snd_sof_dev *sdev, u32 freq)
208d1d95fcbSLiam Girdwood {
209d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->set_clk)
210d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->set_clk(sdev, freq);
211d1d95fcbSLiam Girdwood 
212d1d95fcbSLiam Girdwood 	return 0;
213d1d95fcbSLiam Girdwood }
214d1d95fcbSLiam Girdwood 
21561e285caSRanjani Sridharan static inline int
21661e285caSRanjani Sridharan snd_sof_dsp_set_power_state(struct snd_sof_dev *sdev,
21761e285caSRanjani Sridharan 			    const struct sof_dsp_power_state *target_state)
218e8f112d8SKeyon Jie {
2198b66d7c5SKeyon Jie 	int ret = 0;
220e8f112d8SKeyon Jie 
2218b66d7c5SKeyon Jie 	mutex_lock(&sdev->power_state_access);
2228b66d7c5SKeyon Jie 
2238b66d7c5SKeyon Jie 	if (sof_ops(sdev)->set_power_state)
2248b66d7c5SKeyon Jie 		ret = sof_ops(sdev)->set_power_state(sdev, target_state);
2258b66d7c5SKeyon Jie 
2268b66d7c5SKeyon Jie 	mutex_unlock(&sdev->power_state_access);
2278b66d7c5SKeyon Jie 
2288b66d7c5SKeyon Jie 	return ret;
229e8f112d8SKeyon Jie }
230e8f112d8SKeyon Jie 
231d1d95fcbSLiam Girdwood /* debug */
232d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_dbg_dump(struct snd_sof_dev *sdev, u32 flags)
233d1d95fcbSLiam Girdwood {
234d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->dbg_dump)
235d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->dbg_dump(sdev, flags);
236d1d95fcbSLiam Girdwood }
237d1d95fcbSLiam Girdwood 
2385e4a27fdSPan Xiuli static inline void snd_sof_ipc_dump(struct snd_sof_dev *sdev)
2395e4a27fdSPan Xiuli {
2405e4a27fdSPan Xiuli 	if (sof_ops(sdev)->ipc_dump)
2415e4a27fdSPan Xiuli 		return sof_ops(sdev)->ipc_dump(sdev);
2425e4a27fdSPan Xiuli }
2435e4a27fdSPan Xiuli 
244d1d95fcbSLiam Girdwood /* register IO */
245d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write(struct snd_sof_dev *sdev, u32 bar,
246d1d95fcbSLiam Girdwood 				     u32 offset, u32 value)
247d1d95fcbSLiam Girdwood {
248d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->write) {
249d1d95fcbSLiam Girdwood 		sof_ops(sdev)->write(sdev, sdev->bar[bar] + offset, value);
250d1d95fcbSLiam Girdwood 		return;
251d1d95fcbSLiam Girdwood 	}
252d1d95fcbSLiam Girdwood 
253d1d95fcbSLiam Girdwood 	dev_err_ratelimited(sdev->dev, "error: %s not defined\n", __func__);
254d1d95fcbSLiam Girdwood }
255d1d95fcbSLiam Girdwood 
256d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write64(struct snd_sof_dev *sdev, u32 bar,
257d1d95fcbSLiam Girdwood 				       u32 offset, u64 value)
258d1d95fcbSLiam Girdwood {
259d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->write64) {
260d1d95fcbSLiam Girdwood 		sof_ops(sdev)->write64(sdev, sdev->bar[bar] + offset, value);
261d1d95fcbSLiam Girdwood 		return;
262d1d95fcbSLiam Girdwood 	}
263d1d95fcbSLiam Girdwood 
264d1d95fcbSLiam Girdwood 	dev_err_ratelimited(sdev->dev, "error: %s not defined\n", __func__);
265d1d95fcbSLiam Girdwood }
266d1d95fcbSLiam Girdwood 
267d1d95fcbSLiam Girdwood static inline u32 snd_sof_dsp_read(struct snd_sof_dev *sdev, u32 bar,
268d1d95fcbSLiam Girdwood 				   u32 offset)
269d1d95fcbSLiam Girdwood {
270d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->read)
271d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->read(sdev, sdev->bar[bar] + offset);
272d1d95fcbSLiam Girdwood 
273d1d95fcbSLiam Girdwood 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
274d1d95fcbSLiam Girdwood 	return -ENOTSUPP;
275d1d95fcbSLiam Girdwood }
276d1d95fcbSLiam Girdwood 
277d1d95fcbSLiam Girdwood static inline u64 snd_sof_dsp_read64(struct snd_sof_dev *sdev, u32 bar,
278d1d95fcbSLiam Girdwood 				     u32 offset)
279d1d95fcbSLiam Girdwood {
280d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->read64)
281d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->read64(sdev, sdev->bar[bar] + offset);
282d1d95fcbSLiam Girdwood 
283d1d95fcbSLiam Girdwood 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
284d1d95fcbSLiam Girdwood 	return -ENOTSUPP;
285d1d95fcbSLiam Girdwood }
286d1d95fcbSLiam Girdwood 
287d1d95fcbSLiam Girdwood /* block IO */
288d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_block_read(struct snd_sof_dev *sdev, u32 bar,
289d1d95fcbSLiam Girdwood 					  u32 offset, void *dest, size_t bytes)
290d1d95fcbSLiam Girdwood {
291d1d95fcbSLiam Girdwood 	sof_ops(sdev)->block_read(sdev, bar, offset, dest, bytes);
292d1d95fcbSLiam Girdwood }
293d1d95fcbSLiam Girdwood 
294d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_block_write(struct snd_sof_dev *sdev, u32 bar,
295d1d95fcbSLiam Girdwood 					   u32 offset, void *src, size_t bytes)
296d1d95fcbSLiam Girdwood {
297d1d95fcbSLiam Girdwood 	sof_ops(sdev)->block_write(sdev, bar, offset, src, bytes);
298d1d95fcbSLiam Girdwood }
299d1d95fcbSLiam Girdwood 
300d1d95fcbSLiam Girdwood /* ipc */
301d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_send_msg(struct snd_sof_dev *sdev,
302d1d95fcbSLiam Girdwood 				       struct snd_sof_ipc_msg *msg)
303d1d95fcbSLiam Girdwood {
304d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->send_msg(sdev, msg);
305d1d95fcbSLiam Girdwood }
306d1d95fcbSLiam Girdwood 
307d1d95fcbSLiam Girdwood /* host DMA trace */
308d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_init(struct snd_sof_dev *sdev,
309d1d95fcbSLiam Girdwood 					 u32 *stream_tag)
310d1d95fcbSLiam Girdwood {
311d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_init)
312d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_init(sdev, stream_tag);
313d1d95fcbSLiam Girdwood 
314d1d95fcbSLiam Girdwood 	return 0;
315d1d95fcbSLiam Girdwood }
316d1d95fcbSLiam Girdwood 
317d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_release(struct snd_sof_dev *sdev)
318d1d95fcbSLiam Girdwood {
319d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_release)
320d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_release(sdev);
321d1d95fcbSLiam Girdwood 
322d1d95fcbSLiam Girdwood 	return 0;
323d1d95fcbSLiam Girdwood }
324d1d95fcbSLiam Girdwood 
325d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_trigger(struct snd_sof_dev *sdev, int cmd)
326d1d95fcbSLiam Girdwood {
327d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_trigger)
328d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_trigger(sdev, cmd);
329d1d95fcbSLiam Girdwood 
330d1d95fcbSLiam Girdwood 	return 0;
331d1d95fcbSLiam Girdwood }
332d1d95fcbSLiam Girdwood 
333d1d95fcbSLiam Girdwood /* host PCM ops */
334d1d95fcbSLiam Girdwood static inline int
335d1d95fcbSLiam Girdwood snd_sof_pcm_platform_open(struct snd_sof_dev *sdev,
336d1d95fcbSLiam Girdwood 			  struct snd_pcm_substream *substream)
337d1d95fcbSLiam Girdwood {
338d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_open)
339d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_open(sdev, substream);
340d1d95fcbSLiam Girdwood 
341d1d95fcbSLiam Girdwood 	return 0;
342d1d95fcbSLiam Girdwood }
343d1d95fcbSLiam Girdwood 
344d1d95fcbSLiam Girdwood /* disconnect pcm substream to a host stream */
345d1d95fcbSLiam Girdwood static inline int
346d1d95fcbSLiam Girdwood snd_sof_pcm_platform_close(struct snd_sof_dev *sdev,
347d1d95fcbSLiam Girdwood 			   struct snd_pcm_substream *substream)
348d1d95fcbSLiam Girdwood {
349d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_close)
350d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_close(sdev, substream);
351d1d95fcbSLiam Girdwood 
352d1d95fcbSLiam Girdwood 	return 0;
353d1d95fcbSLiam Girdwood }
354d1d95fcbSLiam Girdwood 
355d1d95fcbSLiam Girdwood /* host stream hw params */
356d1d95fcbSLiam Girdwood static inline int
357d1d95fcbSLiam Girdwood snd_sof_pcm_platform_hw_params(struct snd_sof_dev *sdev,
358d1d95fcbSLiam Girdwood 			       struct snd_pcm_substream *substream,
359d1d95fcbSLiam Girdwood 			       struct snd_pcm_hw_params *params,
360d1d95fcbSLiam Girdwood 			       struct sof_ipc_stream_params *ipc_params)
361d1d95fcbSLiam Girdwood {
362d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_hw_params)
363d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_hw_params(sdev, substream,
364d1d95fcbSLiam Girdwood 						    params, ipc_params);
365d1d95fcbSLiam Girdwood 
366d1d95fcbSLiam Girdwood 	return 0;
367d1d95fcbSLiam Girdwood }
368d1d95fcbSLiam Girdwood 
36993146bc2SRanjani Sridharan /* host stream hw free */
37093146bc2SRanjani Sridharan static inline int
37193146bc2SRanjani Sridharan snd_sof_pcm_platform_hw_free(struct snd_sof_dev *sdev,
37293146bc2SRanjani Sridharan 			     struct snd_pcm_substream *substream)
37393146bc2SRanjani Sridharan {
37493146bc2SRanjani Sridharan 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_hw_free)
37593146bc2SRanjani Sridharan 		return sof_ops(sdev)->pcm_hw_free(sdev, substream);
37693146bc2SRanjani Sridharan 
37793146bc2SRanjani Sridharan 	return 0;
37893146bc2SRanjani Sridharan }
37993146bc2SRanjani Sridharan 
380d1d95fcbSLiam Girdwood /* host stream trigger */
381d1d95fcbSLiam Girdwood static inline int
382d1d95fcbSLiam Girdwood snd_sof_pcm_platform_trigger(struct snd_sof_dev *sdev,
383d1d95fcbSLiam Girdwood 			     struct snd_pcm_substream *substream, int cmd)
384d1d95fcbSLiam Girdwood {
385d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_trigger)
386d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_trigger(sdev, substream, cmd);
387d1d95fcbSLiam Girdwood 
388d1d95fcbSLiam Girdwood 	return 0;
389d1d95fcbSLiam Girdwood }
390d1d95fcbSLiam Girdwood 
391d1d95fcbSLiam Girdwood /* host DSP message data */
392d1d95fcbSLiam Girdwood static inline void snd_sof_ipc_msg_data(struct snd_sof_dev *sdev,
393d1d95fcbSLiam Girdwood 					struct snd_pcm_substream *substream,
394d1d95fcbSLiam Girdwood 					void *p, size_t sz)
395d1d95fcbSLiam Girdwood {
396d1d95fcbSLiam Girdwood 	sof_ops(sdev)->ipc_msg_data(sdev, substream, p, sz);
397d1d95fcbSLiam Girdwood }
398d1d95fcbSLiam Girdwood 
399d1d95fcbSLiam Girdwood /* host configure DSP HW parameters */
400d1d95fcbSLiam Girdwood static inline int
401d1d95fcbSLiam Girdwood snd_sof_ipc_pcm_params(struct snd_sof_dev *sdev,
402d1d95fcbSLiam Girdwood 		       struct snd_pcm_substream *substream,
403d1d95fcbSLiam Girdwood 		       const struct sof_ipc_pcm_params_reply *reply)
404d1d95fcbSLiam Girdwood {
405d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->ipc_pcm_params(sdev, substream, reply);
406d1d95fcbSLiam Girdwood }
407d1d95fcbSLiam Girdwood 
408d1d95fcbSLiam Girdwood /* host stream pointer */
409d1d95fcbSLiam Girdwood static inline snd_pcm_uframes_t
410d1d95fcbSLiam Girdwood snd_sof_pcm_platform_pointer(struct snd_sof_dev *sdev,
411d1d95fcbSLiam Girdwood 			     struct snd_pcm_substream *substream)
412d1d95fcbSLiam Girdwood {
413d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_pointer)
414d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_pointer(sdev, substream);
415d1d95fcbSLiam Girdwood 
416d1d95fcbSLiam Girdwood 	return 0;
417d1d95fcbSLiam Girdwood }
418d1d95fcbSLiam Girdwood 
419e145e9afSCezary Rojewski #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
420e145e9afSCezary Rojewski static inline int
421e145e9afSCezary Rojewski snd_sof_probe_compr_assign(struct snd_sof_dev *sdev,
422e145e9afSCezary Rojewski 		struct snd_compr_stream *cstream, struct snd_soc_dai *dai)
423e145e9afSCezary Rojewski {
424e145e9afSCezary Rojewski 	return sof_ops(sdev)->probe_assign(sdev, cstream, dai);
425e145e9afSCezary Rojewski }
426e145e9afSCezary Rojewski 
427e145e9afSCezary Rojewski static inline int
428e145e9afSCezary Rojewski snd_sof_probe_compr_free(struct snd_sof_dev *sdev,
429e145e9afSCezary Rojewski 		struct snd_compr_stream *cstream, struct snd_soc_dai *dai)
430e145e9afSCezary Rojewski {
431e145e9afSCezary Rojewski 	return sof_ops(sdev)->probe_free(sdev, cstream, dai);
432e145e9afSCezary Rojewski }
433e145e9afSCezary Rojewski 
434e145e9afSCezary Rojewski static inline int
435e145e9afSCezary Rojewski snd_sof_probe_compr_set_params(struct snd_sof_dev *sdev,
436e145e9afSCezary Rojewski 		struct snd_compr_stream *cstream,
437e145e9afSCezary Rojewski 		struct snd_compr_params *params, struct snd_soc_dai *dai)
438e145e9afSCezary Rojewski {
439e145e9afSCezary Rojewski 	return sof_ops(sdev)->probe_set_params(sdev, cstream, params, dai);
440e145e9afSCezary Rojewski }
441e145e9afSCezary Rojewski 
442e145e9afSCezary Rojewski static inline int
443e145e9afSCezary Rojewski snd_sof_probe_compr_trigger(struct snd_sof_dev *sdev,
444e145e9afSCezary Rojewski 		struct snd_compr_stream *cstream, int cmd,
445e145e9afSCezary Rojewski 		struct snd_soc_dai *dai)
446e145e9afSCezary Rojewski {
447e145e9afSCezary Rojewski 	return sof_ops(sdev)->probe_trigger(sdev, cstream, cmd, dai);
448e145e9afSCezary Rojewski }
449e145e9afSCezary Rojewski 
450e145e9afSCezary Rojewski static inline int
451e145e9afSCezary Rojewski snd_sof_probe_compr_pointer(struct snd_sof_dev *sdev,
452e145e9afSCezary Rojewski 		struct snd_compr_stream *cstream,
453e145e9afSCezary Rojewski 		struct snd_compr_tstamp *tstamp, struct snd_soc_dai *dai)
454e145e9afSCezary Rojewski {
455e145e9afSCezary Rojewski 	if (sof_ops(sdev) && sof_ops(sdev)->probe_pointer)
456e145e9afSCezary Rojewski 		return sof_ops(sdev)->probe_pointer(sdev, cstream, tstamp, dai);
457e145e9afSCezary Rojewski 
458e145e9afSCezary Rojewski 	return 0;
459e145e9afSCezary Rojewski }
460e145e9afSCezary Rojewski #endif
461e145e9afSCezary Rojewski 
462285880a2SDaniel Baluta /* machine driver */
463285880a2SDaniel Baluta static inline int
464285880a2SDaniel Baluta snd_sof_machine_register(struct snd_sof_dev *sdev, void *pdata)
465285880a2SDaniel Baluta {
466285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->machine_register)
467285880a2SDaniel Baluta 		return sof_ops(sdev)->machine_register(sdev, pdata);
468285880a2SDaniel Baluta 
469285880a2SDaniel Baluta 	return 0;
470285880a2SDaniel Baluta }
471285880a2SDaniel Baluta 
472285880a2SDaniel Baluta static inline void
473285880a2SDaniel Baluta snd_sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata)
474285880a2SDaniel Baluta {
475285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->machine_unregister)
476285880a2SDaniel Baluta 		sof_ops(sdev)->machine_unregister(sdev, pdata);
477285880a2SDaniel Baluta }
478285880a2SDaniel Baluta 
479285880a2SDaniel Baluta static inline void
480285880a2SDaniel Baluta snd_sof_machine_select(struct snd_sof_dev *sdev)
481285880a2SDaniel Baluta {
482285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->machine_select)
483285880a2SDaniel Baluta 		sof_ops(sdev)->machine_select(sdev);
484285880a2SDaniel Baluta }
485285880a2SDaniel Baluta 
486285880a2SDaniel Baluta static inline void
487285880a2SDaniel Baluta snd_sof_set_mach_params(const struct snd_soc_acpi_mach *mach,
488285880a2SDaniel Baluta 			struct device *dev)
489285880a2SDaniel Baluta {
490285880a2SDaniel Baluta 	struct snd_sof_dev *sdev = dev_get_drvdata(dev);
491285880a2SDaniel Baluta 
492285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->set_mach_params)
493285880a2SDaniel Baluta 		sof_ops(sdev)->set_mach_params(mach, dev);
494285880a2SDaniel Baluta }
495285880a2SDaniel Baluta 
496d1d95fcbSLiam Girdwood static inline const struct snd_sof_dsp_ops
497d1d95fcbSLiam Girdwood *sof_get_ops(const struct sof_dev_desc *d,
498d1d95fcbSLiam Girdwood 	     const struct sof_ops_table mach_ops[], int asize)
499d1d95fcbSLiam Girdwood {
500d1d95fcbSLiam Girdwood 	int i;
501d1d95fcbSLiam Girdwood 
502d1d95fcbSLiam Girdwood 	for (i = 0; i < asize; i++) {
503d1d95fcbSLiam Girdwood 		if (d == mach_ops[i].desc)
504d1d95fcbSLiam Girdwood 			return mach_ops[i].ops;
505d1d95fcbSLiam Girdwood 	}
506d1d95fcbSLiam Girdwood 
507d1d95fcbSLiam Girdwood 	/* not found */
508d1d95fcbSLiam Girdwood 	return NULL;
509d1d95fcbSLiam Girdwood }
510d1d95fcbSLiam Girdwood 
511d1d95fcbSLiam Girdwood /**
512d1d95fcbSLiam Girdwood  * snd_sof_dsp_register_poll_timeout - Periodically poll an address
513d1d95fcbSLiam Girdwood  * until a condition is met or a timeout occurs
514d1d95fcbSLiam Girdwood  * @op: accessor function (takes @addr as its only argument)
515d1d95fcbSLiam Girdwood  * @addr: Address to poll
516d1d95fcbSLiam Girdwood  * @val: Variable to read the value into
517d1d95fcbSLiam Girdwood  * @cond: Break condition (usually involving @val)
518d1d95fcbSLiam Girdwood  * @sleep_us: Maximum time to sleep between reads in us (0
519d1d95fcbSLiam Girdwood  *            tight-loops).  Should be less than ~20ms since usleep_range
520458f69efSMauro Carvalho Chehab  *            is used (see Documentation/timers/timers-howto.rst).
521d1d95fcbSLiam Girdwood  * @timeout_us: Timeout in us, 0 means never timeout
522d1d95fcbSLiam Girdwood  *
523d1d95fcbSLiam Girdwood  * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
524d1d95fcbSLiam Girdwood  * case, the last read value at @addr is stored in @val. Must not
525d1d95fcbSLiam Girdwood  * be called from atomic context if sleep_us or timeout_us are used.
526d1d95fcbSLiam Girdwood  *
527d1d95fcbSLiam Girdwood  * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
528d1d95fcbSLiam Girdwood  */
529d1d95fcbSLiam Girdwood #define snd_sof_dsp_read_poll_timeout(sdev, bar, offset, val, cond, sleep_us, timeout_us) \
530d1d95fcbSLiam Girdwood ({ \
531d1d95fcbSLiam Girdwood 	u64 __timeout_us = (timeout_us); \
532d1d95fcbSLiam Girdwood 	unsigned long __sleep_us = (sleep_us); \
533d1d95fcbSLiam Girdwood 	ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
534d1d95fcbSLiam Girdwood 	might_sleep_if((__sleep_us) != 0); \
535d1d95fcbSLiam Girdwood 	for (;;) {							\
536d1d95fcbSLiam Girdwood 		(val) = snd_sof_dsp_read(sdev, bar, offset);		\
537d1d95fcbSLiam Girdwood 		if (cond) { \
538d1d95fcbSLiam Girdwood 			dev_dbg(sdev->dev, \
539d1d95fcbSLiam Girdwood 				"FW Poll Status: reg=%#x successful\n", (val)); \
540d1d95fcbSLiam Girdwood 			break; \
541d1d95fcbSLiam Girdwood 		} \
542d1d95fcbSLiam Girdwood 		if (__timeout_us && \
543d1d95fcbSLiam Girdwood 		    ktime_compare(ktime_get(), __timeout) > 0) { \
544d1d95fcbSLiam Girdwood 			(val) = snd_sof_dsp_read(sdev, bar, offset); \
545d1d95fcbSLiam Girdwood 			dev_dbg(sdev->dev, \
546d1d95fcbSLiam Girdwood 				"FW Poll Status: reg=%#x timedout\n", (val)); \
547d1d95fcbSLiam Girdwood 			break; \
548d1d95fcbSLiam Girdwood 		} \
549d1d95fcbSLiam Girdwood 		if (__sleep_us) \
550d1d95fcbSLiam Girdwood 			usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
551d1d95fcbSLiam Girdwood 	} \
552d1d95fcbSLiam Girdwood 	(cond) ? 0 : -ETIMEDOUT; \
553d1d95fcbSLiam Girdwood })
554d1d95fcbSLiam Girdwood 
555d1d95fcbSLiam Girdwood /* This is for registers bits with attribute RWC */
556d1d95fcbSLiam Girdwood bool snd_sof_pci_update_bits(struct snd_sof_dev *sdev, u32 offset,
557d1d95fcbSLiam Girdwood 			     u32 mask, u32 value);
558d1d95fcbSLiam Girdwood 
559d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits_unlocked(struct snd_sof_dev *sdev, u32 bar,
560d1d95fcbSLiam Girdwood 				      u32 offset, u32 mask, u32 value);
561d1d95fcbSLiam Girdwood 
562d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64_unlocked(struct snd_sof_dev *sdev, u32 bar,
563d1d95fcbSLiam Girdwood 					u32 offset, u64 mask, u64 value);
564d1d95fcbSLiam Girdwood 
565d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits(struct snd_sof_dev *sdev, u32 bar, u32 offset,
566d1d95fcbSLiam Girdwood 			     u32 mask, u32 value);
567d1d95fcbSLiam Girdwood 
568d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64(struct snd_sof_dev *sdev, u32 bar,
569d1d95fcbSLiam Girdwood 			       u32 offset, u64 mask, u64 value);
570d1d95fcbSLiam Girdwood 
571d1d95fcbSLiam Girdwood void snd_sof_dsp_update_bits_forced(struct snd_sof_dev *sdev, u32 bar,
572d1d95fcbSLiam Girdwood 				    u32 offset, u32 mask, u32 value);
573d1d95fcbSLiam Girdwood 
574d1d95fcbSLiam Girdwood int snd_sof_dsp_register_poll(struct snd_sof_dev *sdev, u32 bar, u32 offset,
575d1d95fcbSLiam Girdwood 			      u32 mask, u32 target, u32 timeout_ms,
576d1d95fcbSLiam Girdwood 			      u32 interval_us);
577d1d95fcbSLiam Girdwood 
578d1d95fcbSLiam Girdwood void snd_sof_dsp_panic(struct snd_sof_dev *sdev, u32 offset);
579d1d95fcbSLiam Girdwood #endif
580