xref: /openbmc/linux/sound/soc/sof/ops.h (revision bc433fd76faefb8484f5bc653d846043822a2d35)
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 
2437e809d5SPierre-Louis Bossart static inline int sof_ops_init(struct snd_sof_dev *sdev)
25856601e5SPierre-Louis Bossart {
26856601e5SPierre-Louis Bossart 	if (sdev->pdata->desc->ops_init)
2737e809d5SPierre-Louis Bossart 		return sdev->pdata->desc->ops_init(sdev);
2837e809d5SPierre-Louis Bossart 
2937e809d5SPierre-Louis Bossart 	return 0;
30856601e5SPierre-Louis Bossart }
31856601e5SPierre-Louis Bossart 
32*bc433fd7SRanjani Sridharan static inline void sof_ops_free(struct snd_sof_dev *sdev)
33*bc433fd7SRanjani Sridharan {
34*bc433fd7SRanjani Sridharan 	if (sdev->pdata->desc->ops_free)
35*bc433fd7SRanjani Sridharan 		sdev->pdata->desc->ops_free(sdev);
36*bc433fd7SRanjani Sridharan }
37*bc433fd7SRanjani Sridharan 
38d1d95fcbSLiam Girdwood /* Mandatory operations are verified during probing */
39d1d95fcbSLiam Girdwood 
40d1d95fcbSLiam Girdwood /* init */
41d1d95fcbSLiam Girdwood static inline int snd_sof_probe(struct snd_sof_dev *sdev)
42d1d95fcbSLiam Girdwood {
43d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->probe(sdev);
44d1d95fcbSLiam Girdwood }
45d1d95fcbSLiam Girdwood 
46d1d95fcbSLiam Girdwood static inline int snd_sof_remove(struct snd_sof_dev *sdev)
47d1d95fcbSLiam Girdwood {
48d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->remove)
49d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->remove(sdev);
50d1d95fcbSLiam Girdwood 
51d1d95fcbSLiam Girdwood 	return 0;
52d1d95fcbSLiam Girdwood }
53d1d95fcbSLiam Girdwood 
547edb3051SKeyon Jie static inline int snd_sof_shutdown(struct snd_sof_dev *sdev)
557edb3051SKeyon Jie {
567edb3051SKeyon Jie 	if (sof_ops(sdev)->shutdown)
577edb3051SKeyon Jie 		return sof_ops(sdev)->shutdown(sdev);
587edb3051SKeyon Jie 
597edb3051SKeyon Jie 	return 0;
607edb3051SKeyon Jie }
617edb3051SKeyon Jie 
62d1d95fcbSLiam Girdwood /* control */
63d1d95fcbSLiam Girdwood 
64d1d95fcbSLiam Girdwood /*
65d1d95fcbSLiam Girdwood  * snd_sof_dsp_run returns the core mask of the cores that are available
66d1d95fcbSLiam Girdwood  * after successful fw boot
67d1d95fcbSLiam Girdwood  */
68d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_run(struct snd_sof_dev *sdev)
69d1d95fcbSLiam Girdwood {
70d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->run(sdev);
71d1d95fcbSLiam Girdwood }
72d1d95fcbSLiam Girdwood 
73a70eb708SFred Oh static inline int snd_sof_dsp_stall(struct snd_sof_dev *sdev, unsigned int core_mask)
74d1d95fcbSLiam Girdwood {
75d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->stall)
76a70eb708SFred Oh 		return sof_ops(sdev)->stall(sdev, core_mask);
77d1d95fcbSLiam Girdwood 
78d1d95fcbSLiam Girdwood 	return 0;
79d1d95fcbSLiam Girdwood }
80d1d95fcbSLiam Girdwood 
81d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_reset(struct snd_sof_dev *sdev)
82d1d95fcbSLiam Girdwood {
83d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->reset)
84d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->reset(sdev);
85d1d95fcbSLiam Girdwood 
86d1d95fcbSLiam Girdwood 	return 0;
87d1d95fcbSLiam Girdwood }
88d1d95fcbSLiam Girdwood 
899ea80748SRanjani Sridharan /* dsp core get/put */
90c414d5dfSRanjani Sridharan static inline int snd_sof_dsp_core_get(struct snd_sof_dev *sdev, int core)
91c414d5dfSRanjani Sridharan {
92c414d5dfSRanjani Sridharan 	if (core > sdev->num_cores - 1) {
93c414d5dfSRanjani Sridharan 		dev_err(sdev->dev, "invalid core id: %d for num_cores: %d\n", core,
94c414d5dfSRanjani Sridharan 			sdev->num_cores);
95c414d5dfSRanjani Sridharan 		return -EINVAL;
96c414d5dfSRanjani Sridharan 	}
97c414d5dfSRanjani Sridharan 
98c414d5dfSRanjani Sridharan 	if (sof_ops(sdev)->core_get) {
99c414d5dfSRanjani Sridharan 		int ret;
100c414d5dfSRanjani Sridharan 
101c414d5dfSRanjani Sridharan 		/* if current ref_count is > 0, increment it and return */
102c414d5dfSRanjani Sridharan 		if (sdev->dsp_core_ref_count[core] > 0) {
103c414d5dfSRanjani Sridharan 			sdev->dsp_core_ref_count[core]++;
104c414d5dfSRanjani Sridharan 			return 0;
105c414d5dfSRanjani Sridharan 		}
106c414d5dfSRanjani Sridharan 
107c414d5dfSRanjani Sridharan 		/* power up the core */
108c414d5dfSRanjani Sridharan 		ret = sof_ops(sdev)->core_get(sdev, core);
109c414d5dfSRanjani Sridharan 		if (ret < 0)
110c414d5dfSRanjani Sridharan 			return ret;
111c414d5dfSRanjani Sridharan 
112c414d5dfSRanjani Sridharan 		/* increment ref_count */
113c414d5dfSRanjani Sridharan 		sdev->dsp_core_ref_count[core]++;
114c414d5dfSRanjani Sridharan 
115c414d5dfSRanjani Sridharan 		/* and update enabled_cores_mask */
116c414d5dfSRanjani Sridharan 		sdev->enabled_cores_mask |= BIT(core);
117c414d5dfSRanjani Sridharan 
118c414d5dfSRanjani Sridharan 		dev_dbg(sdev->dev, "Core %d powered up\n", core);
119c414d5dfSRanjani Sridharan 	}
120c414d5dfSRanjani Sridharan 
121c414d5dfSRanjani Sridharan 	return 0;
122c414d5dfSRanjani Sridharan }
123c414d5dfSRanjani Sridharan 
124c414d5dfSRanjani Sridharan static inline int snd_sof_dsp_core_put(struct snd_sof_dev *sdev, int core)
125c414d5dfSRanjani Sridharan {
126c414d5dfSRanjani Sridharan 	if (core > sdev->num_cores - 1) {
127c414d5dfSRanjani Sridharan 		dev_err(sdev->dev, "invalid core id: %d for num_cores: %d\n", core,
128c414d5dfSRanjani Sridharan 			sdev->num_cores);
129c414d5dfSRanjani Sridharan 		return -EINVAL;
130c414d5dfSRanjani Sridharan 	}
131c414d5dfSRanjani Sridharan 
132c414d5dfSRanjani Sridharan 	if (sof_ops(sdev)->core_put) {
133c414d5dfSRanjani Sridharan 		int ret;
134c414d5dfSRanjani Sridharan 
135c414d5dfSRanjani Sridharan 		/* decrement ref_count and return if it is > 0 */
136c414d5dfSRanjani Sridharan 		if (--(sdev->dsp_core_ref_count[core]) > 0)
137c414d5dfSRanjani Sridharan 			return 0;
138c414d5dfSRanjani Sridharan 
139c414d5dfSRanjani Sridharan 		/* power down the core */
140c414d5dfSRanjani Sridharan 		ret = sof_ops(sdev)->core_put(sdev, core);
141c414d5dfSRanjani Sridharan 		if (ret < 0)
142c414d5dfSRanjani Sridharan 			return ret;
143c414d5dfSRanjani Sridharan 
144c414d5dfSRanjani Sridharan 		/* and update enabled_cores_mask */
145c414d5dfSRanjani Sridharan 		sdev->enabled_cores_mask &= ~BIT(core);
146c414d5dfSRanjani Sridharan 
147c414d5dfSRanjani Sridharan 		dev_dbg(sdev->dev, "Core %d powered down\n", core);
148c414d5dfSRanjani Sridharan 	}
149c414d5dfSRanjani Sridharan 
150c414d5dfSRanjani Sridharan 	return 0;
151c414d5dfSRanjani Sridharan }
152c414d5dfSRanjani Sridharan 
153d1d95fcbSLiam Girdwood /* pre/post fw load */
154d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_pre_fw_run(struct snd_sof_dev *sdev)
155d1d95fcbSLiam Girdwood {
156d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->pre_fw_run)
157d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pre_fw_run(sdev);
158d1d95fcbSLiam Girdwood 
159d1d95fcbSLiam Girdwood 	return 0;
160d1d95fcbSLiam Girdwood }
161d1d95fcbSLiam Girdwood 
162d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_post_fw_run(struct snd_sof_dev *sdev)
163d1d95fcbSLiam Girdwood {
164d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->post_fw_run)
165d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->post_fw_run(sdev);
166d1d95fcbSLiam Girdwood 
167d1d95fcbSLiam Girdwood 	return 0;
168d1d95fcbSLiam Girdwood }
169d1d95fcbSLiam Girdwood 
170e984f3efSFred Oh /* parse platform specific extended manifest */
171e984f3efSFred Oh static inline int snd_sof_dsp_parse_platform_ext_manifest(struct snd_sof_dev *sdev,
172e984f3efSFred Oh 							  const struct sof_ext_man_elem_header *hdr)
173e984f3efSFred Oh {
174e984f3efSFred Oh 	if (sof_ops(sdev)->parse_platform_ext_manifest)
175e984f3efSFred Oh 		return sof_ops(sdev)->parse_platform_ext_manifest(sdev, hdr);
176e984f3efSFred Oh 
177e984f3efSFred Oh 	return 0;
178e984f3efSFred Oh }
179e984f3efSFred Oh 
180ce8234a6SDaniel Baluta /* misc */
181ce8234a6SDaniel Baluta 
182ce8234a6SDaniel Baluta /**
183ce8234a6SDaniel Baluta  * snd_sof_dsp_get_bar_index - Maps a section type with a BAR index
184ce8234a6SDaniel Baluta  *
185ce8234a6SDaniel Baluta  * @sdev: sof device
186ce8234a6SDaniel Baluta  * @type: section type as described by snd_sof_fw_blk_type
187ce8234a6SDaniel Baluta  *
188ce8234a6SDaniel Baluta  * Returns the corresponding BAR index (a positive integer) or -EINVAL
189ce8234a6SDaniel Baluta  * in case there is no mapping
190ce8234a6SDaniel Baluta  */
191ce8234a6SDaniel Baluta static inline int snd_sof_dsp_get_bar_index(struct snd_sof_dev *sdev, u32 type)
192ce8234a6SDaniel Baluta {
193ce8234a6SDaniel Baluta 	if (sof_ops(sdev)->get_bar_index)
194ce8234a6SDaniel Baluta 		return sof_ops(sdev)->get_bar_index(sdev, type);
195ce8234a6SDaniel Baluta 
196ce8234a6SDaniel Baluta 	return sdev->mmio_bar;
197ce8234a6SDaniel Baluta }
198ce8234a6SDaniel Baluta 
199bb9c93f5SDaniel Baluta static inline int snd_sof_dsp_get_mailbox_offset(struct snd_sof_dev *sdev)
200bb9c93f5SDaniel Baluta {
201bb9c93f5SDaniel Baluta 	if (sof_ops(sdev)->get_mailbox_offset)
202bb9c93f5SDaniel Baluta 		return sof_ops(sdev)->get_mailbox_offset(sdev);
203bb9c93f5SDaniel Baluta 
204bb9c93f5SDaniel Baluta 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
205bb9c93f5SDaniel Baluta 	return -ENOTSUPP;
206bb9c93f5SDaniel Baluta }
207bb9c93f5SDaniel Baluta 
208e17422cdSDaniel Baluta static inline int snd_sof_dsp_get_window_offset(struct snd_sof_dev *sdev,
209e17422cdSDaniel Baluta 						u32 id)
210e17422cdSDaniel Baluta {
211e17422cdSDaniel Baluta 	if (sof_ops(sdev)->get_window_offset)
212e17422cdSDaniel Baluta 		return sof_ops(sdev)->get_window_offset(sdev, id);
213e17422cdSDaniel Baluta 
214e17422cdSDaniel Baluta 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
215e17422cdSDaniel Baluta 	return -ENOTSUPP;
216e17422cdSDaniel Baluta }
217d1d95fcbSLiam Girdwood /* power management */
218d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_resume(struct snd_sof_dev *sdev)
219d1d95fcbSLiam Girdwood {
220d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->resume)
221d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->resume(sdev);
222d1d95fcbSLiam Girdwood 
223d1d95fcbSLiam Girdwood 	return 0;
224d1d95fcbSLiam Girdwood }
225d1d95fcbSLiam Girdwood 
22661e285caSRanjani Sridharan static inline int snd_sof_dsp_suspend(struct snd_sof_dev *sdev,
22761e285caSRanjani Sridharan 				      u32 target_state)
228d1d95fcbSLiam Girdwood {
229d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->suspend)
23061e285caSRanjani Sridharan 		return sof_ops(sdev)->suspend(sdev, target_state);
231d1d95fcbSLiam Girdwood 
232d1d95fcbSLiam Girdwood 	return 0;
233d1d95fcbSLiam Girdwood }
234d1d95fcbSLiam Girdwood 
235d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_runtime_resume(struct snd_sof_dev *sdev)
236d1d95fcbSLiam Girdwood {
237d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->runtime_resume)
238d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->runtime_resume(sdev);
239d1d95fcbSLiam Girdwood 
240d1d95fcbSLiam Girdwood 	return 0;
241d1d95fcbSLiam Girdwood }
242d1d95fcbSLiam Girdwood 
2431c38c922SFred Oh static inline int snd_sof_dsp_runtime_suspend(struct snd_sof_dev *sdev)
244d1d95fcbSLiam Girdwood {
245d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->runtime_suspend)
2461c38c922SFred Oh 		return sof_ops(sdev)->runtime_suspend(sdev);
247d1d95fcbSLiam Girdwood 
248d1d95fcbSLiam Girdwood 	return 0;
249d1d95fcbSLiam Girdwood }
250d1d95fcbSLiam Girdwood 
25162fde977SKai Vehmanen static inline int snd_sof_dsp_runtime_idle(struct snd_sof_dev *sdev)
25262fde977SKai Vehmanen {
25362fde977SKai Vehmanen 	if (sof_ops(sdev)->runtime_idle)
25462fde977SKai Vehmanen 		return sof_ops(sdev)->runtime_idle(sdev);
25562fde977SKai Vehmanen 
25662fde977SKai Vehmanen 	return 0;
25762fde977SKai Vehmanen }
25862fde977SKai Vehmanen 
2597077a07aSRanjani Sridharan static inline int snd_sof_dsp_hw_params_upon_resume(struct snd_sof_dev *sdev)
260ed3baacdSRanjani Sridharan {
261ed3baacdSRanjani Sridharan 	if (sof_ops(sdev)->set_hw_params_upon_resume)
2627077a07aSRanjani Sridharan 		return sof_ops(sdev)->set_hw_params_upon_resume(sdev);
2637077a07aSRanjani Sridharan 	return 0;
264ed3baacdSRanjani Sridharan }
265ed3baacdSRanjani Sridharan 
266d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_set_clk(struct snd_sof_dev *sdev, u32 freq)
267d1d95fcbSLiam Girdwood {
268d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->set_clk)
269d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->set_clk(sdev, freq);
270d1d95fcbSLiam Girdwood 
271d1d95fcbSLiam Girdwood 	return 0;
272d1d95fcbSLiam Girdwood }
273d1d95fcbSLiam Girdwood 
27461e285caSRanjani Sridharan static inline int
27561e285caSRanjani Sridharan snd_sof_dsp_set_power_state(struct snd_sof_dev *sdev,
27661e285caSRanjani Sridharan 			    const struct sof_dsp_power_state *target_state)
277e8f112d8SKeyon Jie {
2788b66d7c5SKeyon Jie 	int ret = 0;
279e8f112d8SKeyon Jie 
2808b66d7c5SKeyon Jie 	mutex_lock(&sdev->power_state_access);
2818b66d7c5SKeyon Jie 
2828b66d7c5SKeyon Jie 	if (sof_ops(sdev)->set_power_state)
2838b66d7c5SKeyon Jie 		ret = sof_ops(sdev)->set_power_state(sdev, target_state);
2848b66d7c5SKeyon Jie 
2858b66d7c5SKeyon Jie 	mutex_unlock(&sdev->power_state_access);
2868b66d7c5SKeyon Jie 
2878b66d7c5SKeyon Jie 	return ret;
288e8f112d8SKeyon Jie }
289e8f112d8SKeyon Jie 
290d1d95fcbSLiam Girdwood /* debug */
2912f148430SPeter Ujfalusi void snd_sof_dsp_dbg_dump(struct snd_sof_dev *sdev, const char *msg, u32 flags);
2925e4a27fdSPan Xiuli 
29307e833b4SPeter Ujfalusi static inline int snd_sof_debugfs_add_region_item(struct snd_sof_dev *sdev,
29407e833b4SPeter Ujfalusi 		enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
29507e833b4SPeter Ujfalusi 		const char *name, enum sof_debugfs_access_type access_type)
29607e833b4SPeter Ujfalusi {
29707e833b4SPeter Ujfalusi 	if (sof_ops(sdev) && sof_ops(sdev)->debugfs_add_region_item)
29807e833b4SPeter Ujfalusi 		return sof_ops(sdev)->debugfs_add_region_item(sdev, blk_type, offset,
29907e833b4SPeter Ujfalusi 							      size, name, access_type);
30007e833b4SPeter Ujfalusi 
30107e833b4SPeter Ujfalusi 	return 0;
30207e833b4SPeter Ujfalusi }
30307e833b4SPeter Ujfalusi 
304d1d95fcbSLiam Girdwood /* register IO */
305d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write(struct snd_sof_dev *sdev, u32 bar,
306d1d95fcbSLiam Girdwood 				     u32 offset, u32 value)
307d1d95fcbSLiam Girdwood {
308d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->write) {
309d1d95fcbSLiam Girdwood 		sof_ops(sdev)->write(sdev, sdev->bar[bar] + offset, value);
310d1d95fcbSLiam Girdwood 		return;
311d1d95fcbSLiam Girdwood 	}
312d1d95fcbSLiam Girdwood 
313d1d95fcbSLiam Girdwood 	dev_err_ratelimited(sdev->dev, "error: %s not defined\n", __func__);
314d1d95fcbSLiam Girdwood }
315d1d95fcbSLiam Girdwood 
316d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write64(struct snd_sof_dev *sdev, u32 bar,
317d1d95fcbSLiam Girdwood 				       u32 offset, u64 value)
318d1d95fcbSLiam Girdwood {
319d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->write64) {
320d1d95fcbSLiam Girdwood 		sof_ops(sdev)->write64(sdev, sdev->bar[bar] + offset, value);
321d1d95fcbSLiam Girdwood 		return;
322d1d95fcbSLiam Girdwood 	}
323d1d95fcbSLiam Girdwood 
324d1d95fcbSLiam Girdwood 	dev_err_ratelimited(sdev->dev, "error: %s not defined\n", __func__);
325d1d95fcbSLiam Girdwood }
326d1d95fcbSLiam Girdwood 
327d1d95fcbSLiam Girdwood static inline u32 snd_sof_dsp_read(struct snd_sof_dev *sdev, u32 bar,
328d1d95fcbSLiam Girdwood 				   u32 offset)
329d1d95fcbSLiam Girdwood {
330d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->read)
331d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->read(sdev, sdev->bar[bar] + offset);
332d1d95fcbSLiam Girdwood 
333d1d95fcbSLiam Girdwood 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
334d1d95fcbSLiam Girdwood 	return -ENOTSUPP;
335d1d95fcbSLiam Girdwood }
336d1d95fcbSLiam Girdwood 
337d1d95fcbSLiam Girdwood static inline u64 snd_sof_dsp_read64(struct snd_sof_dev *sdev, u32 bar,
338d1d95fcbSLiam Girdwood 				     u32 offset)
339d1d95fcbSLiam Girdwood {
340d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->read64)
341d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->read64(sdev, sdev->bar[bar] + offset);
342d1d95fcbSLiam Girdwood 
343d1d95fcbSLiam Girdwood 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
344d1d95fcbSLiam Girdwood 	return -ENOTSUPP;
345d1d95fcbSLiam Girdwood }
346d1d95fcbSLiam Girdwood 
347d1d95fcbSLiam Girdwood /* block IO */
3484624bb2fSPeter Ujfalusi static inline int snd_sof_dsp_block_read(struct snd_sof_dev *sdev,
3494624bb2fSPeter Ujfalusi 					 enum snd_sof_fw_blk_type blk_type,
350d1d95fcbSLiam Girdwood 					 u32 offset, void *dest, size_t bytes)
351d1d95fcbSLiam Girdwood {
3524624bb2fSPeter Ujfalusi 	return sof_ops(sdev)->block_read(sdev, blk_type, offset, dest, bytes);
353d1d95fcbSLiam Girdwood }
354d1d95fcbSLiam Girdwood 
3554624bb2fSPeter Ujfalusi static inline int snd_sof_dsp_block_write(struct snd_sof_dev *sdev,
3564624bb2fSPeter Ujfalusi 					  enum snd_sof_fw_blk_type blk_type,
357d1d95fcbSLiam Girdwood 					  u32 offset, void *src, size_t bytes)
358d1d95fcbSLiam Girdwood {
3594624bb2fSPeter Ujfalusi 	return sof_ops(sdev)->block_write(sdev, blk_type, offset, src, bytes);
360d1d95fcbSLiam Girdwood }
361d1d95fcbSLiam Girdwood 
362f71f59ddSDaniel Baluta /* mailbox IO */
363f71f59ddSDaniel Baluta static inline void snd_sof_dsp_mailbox_read(struct snd_sof_dev *sdev,
364f71f59ddSDaniel Baluta 					    u32 offset, void *dest, size_t bytes)
365f71f59ddSDaniel Baluta {
366f71f59ddSDaniel Baluta 	if (sof_ops(sdev)->mailbox_read)
367f71f59ddSDaniel Baluta 		sof_ops(sdev)->mailbox_read(sdev, offset, dest, bytes);
368f71f59ddSDaniel Baluta }
369f71f59ddSDaniel Baluta 
370f71f59ddSDaniel Baluta static inline void snd_sof_dsp_mailbox_write(struct snd_sof_dev *sdev,
371f71f59ddSDaniel Baluta 					     u32 offset, void *src, size_t bytes)
372f71f59ddSDaniel Baluta {
373f71f59ddSDaniel Baluta 	if (sof_ops(sdev)->mailbox_write)
374f71f59ddSDaniel Baluta 		sof_ops(sdev)->mailbox_write(sdev, offset, src, bytes);
375f71f59ddSDaniel Baluta }
376f71f59ddSDaniel Baluta 
377d1d95fcbSLiam Girdwood /* ipc */
378d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_send_msg(struct snd_sof_dev *sdev,
379d1d95fcbSLiam Girdwood 				       struct snd_sof_ipc_msg *msg)
380d1d95fcbSLiam Girdwood {
381d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->send_msg(sdev, msg);
382d1d95fcbSLiam Girdwood }
383d1d95fcbSLiam Girdwood 
384d1d95fcbSLiam Girdwood /* host PCM ops */
385d1d95fcbSLiam Girdwood static inline int
386d1d95fcbSLiam Girdwood snd_sof_pcm_platform_open(struct snd_sof_dev *sdev,
387d1d95fcbSLiam Girdwood 			  struct snd_pcm_substream *substream)
388d1d95fcbSLiam Girdwood {
389d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_open)
390d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_open(sdev, substream);
391d1d95fcbSLiam Girdwood 
392d1d95fcbSLiam Girdwood 	return 0;
393d1d95fcbSLiam Girdwood }
394d1d95fcbSLiam Girdwood 
395d1d95fcbSLiam Girdwood /* disconnect pcm substream to a host stream */
396d1d95fcbSLiam Girdwood static inline int
397d1d95fcbSLiam Girdwood snd_sof_pcm_platform_close(struct snd_sof_dev *sdev,
398d1d95fcbSLiam Girdwood 			   struct snd_pcm_substream *substream)
399d1d95fcbSLiam Girdwood {
400d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_close)
401d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_close(sdev, substream);
402d1d95fcbSLiam Girdwood 
403d1d95fcbSLiam Girdwood 	return 0;
404d1d95fcbSLiam Girdwood }
405d1d95fcbSLiam Girdwood 
406d1d95fcbSLiam Girdwood /* host stream hw params */
407d1d95fcbSLiam Girdwood static inline int
408d1d95fcbSLiam Girdwood snd_sof_pcm_platform_hw_params(struct snd_sof_dev *sdev,
409d1d95fcbSLiam Girdwood 			       struct snd_pcm_substream *substream,
410d1d95fcbSLiam Girdwood 			       struct snd_pcm_hw_params *params,
41131f60a0cSPeter Ujfalusi 			       struct snd_sof_platform_stream_params *platform_params)
412d1d95fcbSLiam Girdwood {
413d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_hw_params)
41431f60a0cSPeter Ujfalusi 		return sof_ops(sdev)->pcm_hw_params(sdev, substream, params,
41531f60a0cSPeter Ujfalusi 						    platform_params);
416d1d95fcbSLiam Girdwood 
417d1d95fcbSLiam Girdwood 	return 0;
418d1d95fcbSLiam Girdwood }
419d1d95fcbSLiam Girdwood 
42093146bc2SRanjani Sridharan /* host stream hw free */
42193146bc2SRanjani Sridharan static inline int
42293146bc2SRanjani Sridharan snd_sof_pcm_platform_hw_free(struct snd_sof_dev *sdev,
42393146bc2SRanjani Sridharan 			     struct snd_pcm_substream *substream)
42493146bc2SRanjani Sridharan {
42593146bc2SRanjani Sridharan 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_hw_free)
42693146bc2SRanjani Sridharan 		return sof_ops(sdev)->pcm_hw_free(sdev, substream);
42793146bc2SRanjani Sridharan 
42893146bc2SRanjani Sridharan 	return 0;
42993146bc2SRanjani Sridharan }
43093146bc2SRanjani Sridharan 
431d1d95fcbSLiam Girdwood /* host stream trigger */
432d1d95fcbSLiam Girdwood static inline int
433d1d95fcbSLiam Girdwood snd_sof_pcm_platform_trigger(struct snd_sof_dev *sdev,
434d1d95fcbSLiam Girdwood 			     struct snd_pcm_substream *substream, int cmd)
435d1d95fcbSLiam Girdwood {
436d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_trigger)
437d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_trigger(sdev, substream, cmd);
438d1d95fcbSLiam Girdwood 
439d1d95fcbSLiam Girdwood 	return 0;
440d1d95fcbSLiam Girdwood }
441d1d95fcbSLiam Girdwood 
44296ec1741SPeter Ujfalusi /* Firmware loading */
44396ec1741SPeter Ujfalusi static inline int snd_sof_load_firmware(struct snd_sof_dev *sdev)
44496ec1741SPeter Ujfalusi {
44596ec1741SPeter Ujfalusi 	dev_dbg(sdev->dev, "loading firmware\n");
44696ec1741SPeter Ujfalusi 
44796ec1741SPeter Ujfalusi 	return sof_ops(sdev)->load_firmware(sdev);
44896ec1741SPeter Ujfalusi }
44996ec1741SPeter Ujfalusi 
450d1d95fcbSLiam Girdwood /* host DSP message data */
4516a0ba071SGuennadi Liakhovetski static inline int snd_sof_ipc_msg_data(struct snd_sof_dev *sdev,
452d1d95fcbSLiam Girdwood 				       struct snd_pcm_substream *substream,
453d1d95fcbSLiam Girdwood 				       void *p, size_t sz)
454d1d95fcbSLiam Girdwood {
4556a0ba071SGuennadi Liakhovetski 	return sof_ops(sdev)->ipc_msg_data(sdev, substream, p, sz);
456d1d95fcbSLiam Girdwood }
457757ce810SPeter Ujfalusi /* host side configuration of the stream's data offset in stream mailbox area */
458757ce810SPeter Ujfalusi static inline int
459757ce810SPeter Ujfalusi snd_sof_set_stream_data_offset(struct snd_sof_dev *sdev,
460757ce810SPeter Ujfalusi 			       struct snd_pcm_substream *substream,
461757ce810SPeter Ujfalusi 			       size_t posn_offset)
462757ce810SPeter Ujfalusi {
463757ce810SPeter Ujfalusi 	if (sof_ops(sdev) && sof_ops(sdev)->set_stream_data_offset)
464757ce810SPeter Ujfalusi 		return sof_ops(sdev)->set_stream_data_offset(sdev, substream,
465757ce810SPeter Ujfalusi 							     posn_offset);
466757ce810SPeter Ujfalusi 
467757ce810SPeter Ujfalusi 	return 0;
468757ce810SPeter Ujfalusi }
469757ce810SPeter Ujfalusi 
470d1d95fcbSLiam Girdwood /* host stream pointer */
471d1d95fcbSLiam Girdwood static inline snd_pcm_uframes_t
472d1d95fcbSLiam Girdwood snd_sof_pcm_platform_pointer(struct snd_sof_dev *sdev,
473d1d95fcbSLiam Girdwood 			     struct snd_pcm_substream *substream)
474d1d95fcbSLiam Girdwood {
475d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_pointer)
476d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_pointer(sdev, substream);
477d1d95fcbSLiam Girdwood 
478d1d95fcbSLiam Girdwood 	return 0;
479d1d95fcbSLiam Girdwood }
480d1d95fcbSLiam Girdwood 
4814a39ea3fSRanjani Sridharan /* pcm ack */
4824a39ea3fSRanjani Sridharan static inline int snd_sof_pcm_platform_ack(struct snd_sof_dev *sdev,
4834a39ea3fSRanjani Sridharan 					   struct snd_pcm_substream *substream)
4844a39ea3fSRanjani Sridharan {
4854a39ea3fSRanjani Sridharan 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_ack)
4864a39ea3fSRanjani Sridharan 		return sof_ops(sdev)->pcm_ack(sdev, substream);
4874a39ea3fSRanjani Sridharan 
4884a39ea3fSRanjani Sridharan 	return 0;
4894a39ea3fSRanjani Sridharan }
4904a39ea3fSRanjani Sridharan 
491285880a2SDaniel Baluta /* machine driver */
492285880a2SDaniel Baluta static inline int
493285880a2SDaniel Baluta snd_sof_machine_register(struct snd_sof_dev *sdev, void *pdata)
494285880a2SDaniel Baluta {
495285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->machine_register)
496285880a2SDaniel Baluta 		return sof_ops(sdev)->machine_register(sdev, pdata);
497285880a2SDaniel Baluta 
498285880a2SDaniel Baluta 	return 0;
499285880a2SDaniel Baluta }
500285880a2SDaniel Baluta 
501285880a2SDaniel Baluta static inline void
502285880a2SDaniel Baluta snd_sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata)
503285880a2SDaniel Baluta {
504285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->machine_unregister)
505285880a2SDaniel Baluta 		sof_ops(sdev)->machine_unregister(sdev, pdata);
506285880a2SDaniel Baluta }
507285880a2SDaniel Baluta 
508cb515f10SGuennadi Liakhovetski static inline struct snd_soc_acpi_mach *
509285880a2SDaniel Baluta snd_sof_machine_select(struct snd_sof_dev *sdev)
510285880a2SDaniel Baluta {
511285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->machine_select)
512cb515f10SGuennadi Liakhovetski 		return sof_ops(sdev)->machine_select(sdev);
513cb515f10SGuennadi Liakhovetski 
514cb515f10SGuennadi Liakhovetski 	return NULL;
515285880a2SDaniel Baluta }
516285880a2SDaniel Baluta 
517285880a2SDaniel Baluta static inline void
518cb515f10SGuennadi Liakhovetski snd_sof_set_mach_params(struct snd_soc_acpi_mach *mach,
51917e9d6b0SPierre-Louis Bossart 			struct snd_sof_dev *sdev)
520285880a2SDaniel Baluta {
521285880a2SDaniel Baluta 	if (sof_ops(sdev) && sof_ops(sdev)->set_mach_params)
52217e9d6b0SPierre-Louis Bossart 		sof_ops(sdev)->set_mach_params(mach, sdev);
523285880a2SDaniel Baluta }
524285880a2SDaniel Baluta 
525d1d95fcbSLiam Girdwood /**
526d1d95fcbSLiam Girdwood  * snd_sof_dsp_register_poll_timeout - Periodically poll an address
527d1d95fcbSLiam Girdwood  * until a condition is met or a timeout occurs
528d1d95fcbSLiam Girdwood  * @op: accessor function (takes @addr as its only argument)
529d1d95fcbSLiam Girdwood  * @addr: Address to poll
530d1d95fcbSLiam Girdwood  * @val: Variable to read the value into
531d1d95fcbSLiam Girdwood  * @cond: Break condition (usually involving @val)
532d1d95fcbSLiam Girdwood  * @sleep_us: Maximum time to sleep between reads in us (0
533d1d95fcbSLiam Girdwood  *            tight-loops).  Should be less than ~20ms since usleep_range
534458f69efSMauro Carvalho Chehab  *            is used (see Documentation/timers/timers-howto.rst).
535d1d95fcbSLiam Girdwood  * @timeout_us: Timeout in us, 0 means never timeout
536d1d95fcbSLiam Girdwood  *
537d1d95fcbSLiam Girdwood  * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
538d1d95fcbSLiam Girdwood  * case, the last read value at @addr is stored in @val. Must not
539d1d95fcbSLiam Girdwood  * be called from atomic context if sleep_us or timeout_us are used.
540d1d95fcbSLiam Girdwood  *
541d1d95fcbSLiam Girdwood  * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
542d1d95fcbSLiam Girdwood  */
543d1d95fcbSLiam Girdwood #define snd_sof_dsp_read_poll_timeout(sdev, bar, offset, val, cond, sleep_us, timeout_us) \
544d1d95fcbSLiam Girdwood ({ \
545d1d95fcbSLiam Girdwood 	u64 __timeout_us = (timeout_us); \
546d1d95fcbSLiam Girdwood 	unsigned long __sleep_us = (sleep_us); \
547d1d95fcbSLiam Girdwood 	ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
548d1d95fcbSLiam Girdwood 	might_sleep_if((__sleep_us) != 0); \
549d1d95fcbSLiam Girdwood 	for (;;) {							\
550d1d95fcbSLiam Girdwood 		(val) = snd_sof_dsp_read(sdev, bar, offset);		\
551d1d95fcbSLiam Girdwood 		if (cond) { \
552d1d95fcbSLiam Girdwood 			dev_dbg(sdev->dev, \
5533b2e93edSKeyon Jie 				"FW Poll Status: reg[%#x]=%#x successful\n", \
5543b2e93edSKeyon Jie 				(offset), (val)); \
555d1d95fcbSLiam Girdwood 			break; \
556d1d95fcbSLiam Girdwood 		} \
557d1d95fcbSLiam Girdwood 		if (__timeout_us && \
558d1d95fcbSLiam Girdwood 		    ktime_compare(ktime_get(), __timeout) > 0) { \
559d1d95fcbSLiam Girdwood 			(val) = snd_sof_dsp_read(sdev, bar, offset); \
560d1d95fcbSLiam Girdwood 			dev_dbg(sdev->dev, \
5613b2e93edSKeyon Jie 				"FW Poll Status: reg[%#x]=%#x timedout\n", \
5623b2e93edSKeyon Jie 				(offset), (val)); \
563d1d95fcbSLiam Girdwood 			break; \
564d1d95fcbSLiam Girdwood 		} \
565d1d95fcbSLiam Girdwood 		if (__sleep_us) \
566d1d95fcbSLiam Girdwood 			usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
567d1d95fcbSLiam Girdwood 	} \
568d1d95fcbSLiam Girdwood 	(cond) ? 0 : -ETIMEDOUT; \
569d1d95fcbSLiam Girdwood })
570d1d95fcbSLiam Girdwood 
571d1d95fcbSLiam Girdwood /* This is for registers bits with attribute RWC */
572d1d95fcbSLiam Girdwood bool snd_sof_pci_update_bits(struct snd_sof_dev *sdev, u32 offset,
573d1d95fcbSLiam Girdwood 			     u32 mask, u32 value);
574d1d95fcbSLiam Girdwood 
575d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits_unlocked(struct snd_sof_dev *sdev, u32 bar,
576d1d95fcbSLiam Girdwood 				      u32 offset, u32 mask, u32 value);
577d1d95fcbSLiam Girdwood 
578d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64_unlocked(struct snd_sof_dev *sdev, u32 bar,
579d1d95fcbSLiam Girdwood 					u32 offset, u64 mask, u64 value);
580d1d95fcbSLiam Girdwood 
581d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits(struct snd_sof_dev *sdev, u32 bar, u32 offset,
582d1d95fcbSLiam Girdwood 			     u32 mask, u32 value);
583d1d95fcbSLiam Girdwood 
584d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64(struct snd_sof_dev *sdev, u32 bar,
585d1d95fcbSLiam Girdwood 			       u32 offset, u64 mask, u64 value);
586d1d95fcbSLiam Girdwood 
587d1d95fcbSLiam Girdwood void snd_sof_dsp_update_bits_forced(struct snd_sof_dev *sdev, u32 bar,
588d1d95fcbSLiam Girdwood 				    u32 offset, u32 mask, u32 value);
589d1d95fcbSLiam Girdwood 
590d1d95fcbSLiam Girdwood int snd_sof_dsp_register_poll(struct snd_sof_dev *sdev, u32 bar, u32 offset,
591d1d95fcbSLiam Girdwood 			      u32 mask, u32 target, u32 timeout_ms,
592d1d95fcbSLiam Girdwood 			      u32 interval_us);
593d1d95fcbSLiam Girdwood 
594b2b10aa7SPeter Ujfalusi void snd_sof_dsp_panic(struct snd_sof_dev *sdev, u32 offset, bool non_recoverable);
595d1d95fcbSLiam Girdwood #endif
596