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 *
6*293ad281SPierre-Louis Bossart * Copyright(c) 2018 Intel Corporation
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
sof_ops_init(struct snd_sof_dev * sdev)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
sof_ops_free(struct snd_sof_dev * sdev)32bc433fd7SRanjani Sridharan static inline void sof_ops_free(struct snd_sof_dev *sdev)
33bc433fd7SRanjani Sridharan {
34bc433fd7SRanjani Sridharan if (sdev->pdata->desc->ops_free)
35bc433fd7SRanjani Sridharan sdev->pdata->desc->ops_free(sdev);
36bc433fd7SRanjani Sridharan }
37bc433fd7SRanjani Sridharan
38d1d95fcbSLiam Girdwood /* Mandatory operations are verified during probing */
39d1d95fcbSLiam Girdwood
40d1d95fcbSLiam Girdwood /* init */
snd_sof_probe_early(struct snd_sof_dev * sdev)4117baaa1fSPierre-Louis Bossart static inline int snd_sof_probe_early(struct snd_sof_dev *sdev)
4217baaa1fSPierre-Louis Bossart {
4317baaa1fSPierre-Louis Bossart if (sof_ops(sdev)->probe_early)
4417baaa1fSPierre-Louis Bossart return sof_ops(sdev)->probe_early(sdev);
4517baaa1fSPierre-Louis Bossart
4617baaa1fSPierre-Louis Bossart return 0;
4717baaa1fSPierre-Louis Bossart }
4817baaa1fSPierre-Louis Bossart
snd_sof_probe(struct snd_sof_dev * sdev)49d1d95fcbSLiam Girdwood static inline int snd_sof_probe(struct snd_sof_dev *sdev)
50d1d95fcbSLiam Girdwood {
51d1d95fcbSLiam Girdwood return sof_ops(sdev)->probe(sdev);
52d1d95fcbSLiam Girdwood }
53d1d95fcbSLiam Girdwood
snd_sof_remove(struct snd_sof_dev * sdev)54e4d09de3SPierre-Louis Bossart static inline void snd_sof_remove(struct snd_sof_dev *sdev)
55d1d95fcbSLiam Girdwood {
56d1d95fcbSLiam Girdwood if (sof_ops(sdev)->remove)
57e4d09de3SPierre-Louis Bossart sof_ops(sdev)->remove(sdev);
58d1d95fcbSLiam Girdwood }
59d1d95fcbSLiam Girdwood
snd_sof_remove_late(struct snd_sof_dev * sdev)60264aeb99STakashi Iwai static inline void snd_sof_remove_late(struct snd_sof_dev *sdev)
6117baaa1fSPierre-Louis Bossart {
6217baaa1fSPierre-Louis Bossart if (sof_ops(sdev)->remove_late)
63264aeb99STakashi Iwai sof_ops(sdev)->remove_late(sdev);
6417baaa1fSPierre-Louis Bossart }
6517baaa1fSPierre-Louis Bossart
snd_sof_shutdown(struct snd_sof_dev * sdev)667edb3051SKeyon Jie static inline int snd_sof_shutdown(struct snd_sof_dev *sdev)
677edb3051SKeyon Jie {
687edb3051SKeyon Jie if (sof_ops(sdev)->shutdown)
697edb3051SKeyon Jie return sof_ops(sdev)->shutdown(sdev);
707edb3051SKeyon Jie
717edb3051SKeyon Jie return 0;
727edb3051SKeyon Jie }
737edb3051SKeyon Jie
74d1d95fcbSLiam Girdwood /* control */
75d1d95fcbSLiam Girdwood
76d1d95fcbSLiam Girdwood /*
77d1d95fcbSLiam Girdwood * snd_sof_dsp_run returns the core mask of the cores that are available
78d1d95fcbSLiam Girdwood * after successful fw boot
79d1d95fcbSLiam Girdwood */
snd_sof_dsp_run(struct snd_sof_dev * sdev)80d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_run(struct snd_sof_dev *sdev)
81d1d95fcbSLiam Girdwood {
82d1d95fcbSLiam Girdwood return sof_ops(sdev)->run(sdev);
83d1d95fcbSLiam Girdwood }
84d1d95fcbSLiam Girdwood
snd_sof_dsp_stall(struct snd_sof_dev * sdev,unsigned int core_mask)85a70eb708SFred Oh static inline int snd_sof_dsp_stall(struct snd_sof_dev *sdev, unsigned int core_mask)
86d1d95fcbSLiam Girdwood {
87d1d95fcbSLiam Girdwood if (sof_ops(sdev)->stall)
88a70eb708SFred Oh return sof_ops(sdev)->stall(sdev, core_mask);
89d1d95fcbSLiam Girdwood
90d1d95fcbSLiam Girdwood return 0;
91d1d95fcbSLiam Girdwood }
92d1d95fcbSLiam Girdwood
snd_sof_dsp_reset(struct snd_sof_dev * sdev)93d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_reset(struct snd_sof_dev *sdev)
94d1d95fcbSLiam Girdwood {
95d1d95fcbSLiam Girdwood if (sof_ops(sdev)->reset)
96d1d95fcbSLiam Girdwood return sof_ops(sdev)->reset(sdev);
97d1d95fcbSLiam Girdwood
98d1d95fcbSLiam Girdwood return 0;
99d1d95fcbSLiam Girdwood }
100d1d95fcbSLiam Girdwood
1019ea80748SRanjani Sridharan /* dsp core get/put */
snd_sof_dsp_core_get(struct snd_sof_dev * sdev,int core)102c414d5dfSRanjani Sridharan static inline int snd_sof_dsp_core_get(struct snd_sof_dev *sdev, int core)
103c414d5dfSRanjani Sridharan {
104c414d5dfSRanjani Sridharan if (core > sdev->num_cores - 1) {
105c414d5dfSRanjani Sridharan dev_err(sdev->dev, "invalid core id: %d for num_cores: %d\n", core,
106c414d5dfSRanjani Sridharan sdev->num_cores);
107c414d5dfSRanjani Sridharan return -EINVAL;
108c414d5dfSRanjani Sridharan }
109c414d5dfSRanjani Sridharan
110c414d5dfSRanjani Sridharan if (sof_ops(sdev)->core_get) {
111c414d5dfSRanjani Sridharan int ret;
112c414d5dfSRanjani Sridharan
113c414d5dfSRanjani Sridharan /* if current ref_count is > 0, increment it and return */
114c414d5dfSRanjani Sridharan if (sdev->dsp_core_ref_count[core] > 0) {
115c414d5dfSRanjani Sridharan sdev->dsp_core_ref_count[core]++;
116c414d5dfSRanjani Sridharan return 0;
117c414d5dfSRanjani Sridharan }
118c414d5dfSRanjani Sridharan
119c414d5dfSRanjani Sridharan /* power up the core */
120c414d5dfSRanjani Sridharan ret = sof_ops(sdev)->core_get(sdev, core);
121c414d5dfSRanjani Sridharan if (ret < 0)
122c414d5dfSRanjani Sridharan return ret;
123c414d5dfSRanjani Sridharan
124c414d5dfSRanjani Sridharan /* increment ref_count */
125c414d5dfSRanjani Sridharan sdev->dsp_core_ref_count[core]++;
126c414d5dfSRanjani Sridharan
127c414d5dfSRanjani Sridharan /* and update enabled_cores_mask */
128c414d5dfSRanjani Sridharan sdev->enabled_cores_mask |= BIT(core);
129c414d5dfSRanjani Sridharan
130c414d5dfSRanjani Sridharan dev_dbg(sdev->dev, "Core %d powered up\n", core);
131c414d5dfSRanjani Sridharan }
132c414d5dfSRanjani Sridharan
133c414d5dfSRanjani Sridharan return 0;
134c414d5dfSRanjani Sridharan }
135c414d5dfSRanjani Sridharan
snd_sof_dsp_core_put(struct snd_sof_dev * sdev,int core)136c414d5dfSRanjani Sridharan static inline int snd_sof_dsp_core_put(struct snd_sof_dev *sdev, int core)
137c414d5dfSRanjani Sridharan {
138c414d5dfSRanjani Sridharan if (core > sdev->num_cores - 1) {
139c414d5dfSRanjani Sridharan dev_err(sdev->dev, "invalid core id: %d for num_cores: %d\n", core,
140c414d5dfSRanjani Sridharan sdev->num_cores);
141c414d5dfSRanjani Sridharan return -EINVAL;
142c414d5dfSRanjani Sridharan }
143c414d5dfSRanjani Sridharan
144c414d5dfSRanjani Sridharan if (sof_ops(sdev)->core_put) {
145c414d5dfSRanjani Sridharan int ret;
146c414d5dfSRanjani Sridharan
147c414d5dfSRanjani Sridharan /* decrement ref_count and return if it is > 0 */
148c414d5dfSRanjani Sridharan if (--(sdev->dsp_core_ref_count[core]) > 0)
149c414d5dfSRanjani Sridharan return 0;
150c414d5dfSRanjani Sridharan
151c414d5dfSRanjani Sridharan /* power down the core */
152c414d5dfSRanjani Sridharan ret = sof_ops(sdev)->core_put(sdev, core);
153c414d5dfSRanjani Sridharan if (ret < 0)
154c414d5dfSRanjani Sridharan return ret;
155c414d5dfSRanjani Sridharan
156c414d5dfSRanjani Sridharan /* and update enabled_cores_mask */
157c414d5dfSRanjani Sridharan sdev->enabled_cores_mask &= ~BIT(core);
158c414d5dfSRanjani Sridharan
159c414d5dfSRanjani Sridharan dev_dbg(sdev->dev, "Core %d powered down\n", core);
160c414d5dfSRanjani Sridharan }
161c414d5dfSRanjani Sridharan
162c414d5dfSRanjani Sridharan return 0;
163c414d5dfSRanjani Sridharan }
164c414d5dfSRanjani Sridharan
165d1d95fcbSLiam Girdwood /* pre/post fw load */
snd_sof_dsp_pre_fw_run(struct snd_sof_dev * sdev)166d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_pre_fw_run(struct snd_sof_dev *sdev)
167d1d95fcbSLiam Girdwood {
168d1d95fcbSLiam Girdwood if (sof_ops(sdev)->pre_fw_run)
169d1d95fcbSLiam Girdwood return sof_ops(sdev)->pre_fw_run(sdev);
170d1d95fcbSLiam Girdwood
171d1d95fcbSLiam Girdwood return 0;
172d1d95fcbSLiam Girdwood }
173d1d95fcbSLiam Girdwood
snd_sof_dsp_post_fw_run(struct snd_sof_dev * sdev)174d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_post_fw_run(struct snd_sof_dev *sdev)
175d1d95fcbSLiam Girdwood {
176d1d95fcbSLiam Girdwood if (sof_ops(sdev)->post_fw_run)
177d1d95fcbSLiam Girdwood return sof_ops(sdev)->post_fw_run(sdev);
178d1d95fcbSLiam Girdwood
179d1d95fcbSLiam Girdwood return 0;
180d1d95fcbSLiam Girdwood }
181d1d95fcbSLiam Girdwood
182e984f3efSFred Oh /* parse platform specific extended manifest */
snd_sof_dsp_parse_platform_ext_manifest(struct snd_sof_dev * sdev,const struct sof_ext_man_elem_header * hdr)183e984f3efSFred Oh static inline int snd_sof_dsp_parse_platform_ext_manifest(struct snd_sof_dev *sdev,
184e984f3efSFred Oh const struct sof_ext_man_elem_header *hdr)
185e984f3efSFred Oh {
186e984f3efSFred Oh if (sof_ops(sdev)->parse_platform_ext_manifest)
187e984f3efSFred Oh return sof_ops(sdev)->parse_platform_ext_manifest(sdev, hdr);
188e984f3efSFred Oh
189e984f3efSFred Oh return 0;
190e984f3efSFred Oh }
191e984f3efSFred Oh
192ce8234a6SDaniel Baluta /* misc */
193ce8234a6SDaniel Baluta
194ce8234a6SDaniel Baluta /**
195ce8234a6SDaniel Baluta * snd_sof_dsp_get_bar_index - Maps a section type with a BAR index
196ce8234a6SDaniel Baluta *
197ce8234a6SDaniel Baluta * @sdev: sof device
198ce8234a6SDaniel Baluta * @type: section type as described by snd_sof_fw_blk_type
199ce8234a6SDaniel Baluta *
200ce8234a6SDaniel Baluta * Returns the corresponding BAR index (a positive integer) or -EINVAL
201ce8234a6SDaniel Baluta * in case there is no mapping
202ce8234a6SDaniel Baluta */
snd_sof_dsp_get_bar_index(struct snd_sof_dev * sdev,u32 type)203ce8234a6SDaniel Baluta static inline int snd_sof_dsp_get_bar_index(struct snd_sof_dev *sdev, u32 type)
204ce8234a6SDaniel Baluta {
205ce8234a6SDaniel Baluta if (sof_ops(sdev)->get_bar_index)
206ce8234a6SDaniel Baluta return sof_ops(sdev)->get_bar_index(sdev, type);
207ce8234a6SDaniel Baluta
208ce8234a6SDaniel Baluta return sdev->mmio_bar;
209ce8234a6SDaniel Baluta }
210ce8234a6SDaniel Baluta
snd_sof_dsp_get_mailbox_offset(struct snd_sof_dev * sdev)211bb9c93f5SDaniel Baluta static inline int snd_sof_dsp_get_mailbox_offset(struct snd_sof_dev *sdev)
212bb9c93f5SDaniel Baluta {
213bb9c93f5SDaniel Baluta if (sof_ops(sdev)->get_mailbox_offset)
214bb9c93f5SDaniel Baluta return sof_ops(sdev)->get_mailbox_offset(sdev);
215bb9c93f5SDaniel Baluta
216bb9c93f5SDaniel Baluta dev_err(sdev->dev, "error: %s not defined\n", __func__);
217353bc992SPeter Ujfalusi return -EOPNOTSUPP;
218bb9c93f5SDaniel Baluta }
219bb9c93f5SDaniel Baluta
snd_sof_dsp_get_window_offset(struct snd_sof_dev * sdev,u32 id)220e17422cdSDaniel Baluta static inline int snd_sof_dsp_get_window_offset(struct snd_sof_dev *sdev,
221e17422cdSDaniel Baluta u32 id)
222e17422cdSDaniel Baluta {
223e17422cdSDaniel Baluta if (sof_ops(sdev)->get_window_offset)
224e17422cdSDaniel Baluta return sof_ops(sdev)->get_window_offset(sdev, id);
225e17422cdSDaniel Baluta
226e17422cdSDaniel Baluta dev_err(sdev->dev, "error: %s not defined\n", __func__);
227353bc992SPeter Ujfalusi return -EOPNOTSUPP;
228e17422cdSDaniel Baluta }
229d1d95fcbSLiam Girdwood /* power management */
snd_sof_dsp_resume(struct snd_sof_dev * sdev)230d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_resume(struct snd_sof_dev *sdev)
231d1d95fcbSLiam Girdwood {
232d1d95fcbSLiam Girdwood if (sof_ops(sdev)->resume)
233d1d95fcbSLiam Girdwood return sof_ops(sdev)->resume(sdev);
234d1d95fcbSLiam Girdwood
235d1d95fcbSLiam Girdwood return 0;
236d1d95fcbSLiam Girdwood }
237d1d95fcbSLiam Girdwood
snd_sof_dsp_suspend(struct snd_sof_dev * sdev,u32 target_state)23861e285caSRanjani Sridharan static inline int snd_sof_dsp_suspend(struct snd_sof_dev *sdev,
23961e285caSRanjani Sridharan u32 target_state)
240d1d95fcbSLiam Girdwood {
241d1d95fcbSLiam Girdwood if (sof_ops(sdev)->suspend)
24261e285caSRanjani Sridharan return sof_ops(sdev)->suspend(sdev, target_state);
243d1d95fcbSLiam Girdwood
244d1d95fcbSLiam Girdwood return 0;
245d1d95fcbSLiam Girdwood }
246d1d95fcbSLiam Girdwood
snd_sof_dsp_runtime_resume(struct snd_sof_dev * sdev)247d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_runtime_resume(struct snd_sof_dev *sdev)
248d1d95fcbSLiam Girdwood {
249d1d95fcbSLiam Girdwood if (sof_ops(sdev)->runtime_resume)
250d1d95fcbSLiam Girdwood return sof_ops(sdev)->runtime_resume(sdev);
251d1d95fcbSLiam Girdwood
252d1d95fcbSLiam Girdwood return 0;
253d1d95fcbSLiam Girdwood }
254d1d95fcbSLiam Girdwood
snd_sof_dsp_runtime_suspend(struct snd_sof_dev * sdev)2551c38c922SFred Oh static inline int snd_sof_dsp_runtime_suspend(struct snd_sof_dev *sdev)
256d1d95fcbSLiam Girdwood {
257d1d95fcbSLiam Girdwood if (sof_ops(sdev)->runtime_suspend)
2581c38c922SFred Oh return sof_ops(sdev)->runtime_suspend(sdev);
259d1d95fcbSLiam Girdwood
260d1d95fcbSLiam Girdwood return 0;
261d1d95fcbSLiam Girdwood }
262d1d95fcbSLiam Girdwood
snd_sof_dsp_runtime_idle(struct snd_sof_dev * sdev)26362fde977SKai Vehmanen static inline int snd_sof_dsp_runtime_idle(struct snd_sof_dev *sdev)
26462fde977SKai Vehmanen {
26562fde977SKai Vehmanen if (sof_ops(sdev)->runtime_idle)
26662fde977SKai Vehmanen return sof_ops(sdev)->runtime_idle(sdev);
26762fde977SKai Vehmanen
26862fde977SKai Vehmanen return 0;
26962fde977SKai Vehmanen }
27062fde977SKai Vehmanen
snd_sof_dsp_hw_params_upon_resume(struct snd_sof_dev * sdev)2717077a07aSRanjani Sridharan static inline int snd_sof_dsp_hw_params_upon_resume(struct snd_sof_dev *sdev)
272ed3baacdSRanjani Sridharan {
273ed3baacdSRanjani Sridharan if (sof_ops(sdev)->set_hw_params_upon_resume)
2747077a07aSRanjani Sridharan return sof_ops(sdev)->set_hw_params_upon_resume(sdev);
2757077a07aSRanjani Sridharan return 0;
276ed3baacdSRanjani Sridharan }
277ed3baacdSRanjani Sridharan
snd_sof_dsp_set_clk(struct snd_sof_dev * sdev,u32 freq)278d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_set_clk(struct snd_sof_dev *sdev, u32 freq)
279d1d95fcbSLiam Girdwood {
280d1d95fcbSLiam Girdwood if (sof_ops(sdev)->set_clk)
281d1d95fcbSLiam Girdwood return sof_ops(sdev)->set_clk(sdev, freq);
282d1d95fcbSLiam Girdwood
283d1d95fcbSLiam Girdwood return 0;
284d1d95fcbSLiam Girdwood }
285d1d95fcbSLiam Girdwood
28661e285caSRanjani Sridharan static inline int
snd_sof_dsp_set_power_state(struct snd_sof_dev * sdev,const struct sof_dsp_power_state * target_state)28761e285caSRanjani Sridharan snd_sof_dsp_set_power_state(struct snd_sof_dev *sdev,
28861e285caSRanjani Sridharan const struct sof_dsp_power_state *target_state)
289e8f112d8SKeyon Jie {
2908b66d7c5SKeyon Jie int ret = 0;
291e8f112d8SKeyon Jie
2928b66d7c5SKeyon Jie mutex_lock(&sdev->power_state_access);
2938b66d7c5SKeyon Jie
2948b66d7c5SKeyon Jie if (sof_ops(sdev)->set_power_state)
2958b66d7c5SKeyon Jie ret = sof_ops(sdev)->set_power_state(sdev, target_state);
2968b66d7c5SKeyon Jie
2978b66d7c5SKeyon Jie mutex_unlock(&sdev->power_state_access);
2988b66d7c5SKeyon Jie
2998b66d7c5SKeyon Jie return ret;
300e8f112d8SKeyon Jie }
301e8f112d8SKeyon Jie
302d1d95fcbSLiam Girdwood /* debug */
3032f148430SPeter Ujfalusi void snd_sof_dsp_dbg_dump(struct snd_sof_dev *sdev, const char *msg, u32 flags);
3045e4a27fdSPan Xiuli
snd_sof_debugfs_add_region_item(struct snd_sof_dev * sdev,enum snd_sof_fw_blk_type blk_type,u32 offset,size_t size,const char * name,enum sof_debugfs_access_type access_type)30507e833b4SPeter Ujfalusi static inline int snd_sof_debugfs_add_region_item(struct snd_sof_dev *sdev,
30607e833b4SPeter Ujfalusi enum snd_sof_fw_blk_type blk_type, u32 offset, size_t size,
30707e833b4SPeter Ujfalusi const char *name, enum sof_debugfs_access_type access_type)
30807e833b4SPeter Ujfalusi {
30907e833b4SPeter Ujfalusi if (sof_ops(sdev) && sof_ops(sdev)->debugfs_add_region_item)
31007e833b4SPeter Ujfalusi return sof_ops(sdev)->debugfs_add_region_item(sdev, blk_type, offset,
31107e833b4SPeter Ujfalusi size, name, access_type);
31207e833b4SPeter Ujfalusi
31307e833b4SPeter Ujfalusi return 0;
31407e833b4SPeter Ujfalusi }
31507e833b4SPeter Ujfalusi
316d1d95fcbSLiam Girdwood /* register IO */
snd_sof_dsp_write8(struct snd_sof_dev * sdev,u32 bar,u32 offset,u8 value)317f8fbf0dcSPierre-Louis Bossart static inline void snd_sof_dsp_write8(struct snd_sof_dev *sdev, u32 bar,
31874fe0c4dSPierre-Louis Bossart u32 offset, u8 value)
31974fe0c4dSPierre-Louis Bossart {
320f8fbf0dcSPierre-Louis Bossart if (sof_ops(sdev)->write8)
321f8fbf0dcSPierre-Louis Bossart sof_ops(sdev)->write8(sdev, sdev->bar[bar] + offset, value);
32274fe0c4dSPierre-Louis Bossart else
32374fe0c4dSPierre-Louis Bossart writeb(value, sdev->bar[bar] + offset);
32474fe0c4dSPierre-Louis Bossart }
32574fe0c4dSPierre-Louis Bossart
snd_sof_dsp_write(struct snd_sof_dev * sdev,u32 bar,u32 offset,u32 value)326d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write(struct snd_sof_dev *sdev, u32 bar,
327d1d95fcbSLiam Girdwood u32 offset, u32 value)
328d1d95fcbSLiam Girdwood {
32901278cb6SPierre-Louis Bossart if (sof_ops(sdev)->write)
330d1d95fcbSLiam Girdwood sof_ops(sdev)->write(sdev, sdev->bar[bar] + offset, value);
33101278cb6SPierre-Louis Bossart else
33201278cb6SPierre-Louis Bossart writel(value, sdev->bar[bar] + offset);
333d1d95fcbSLiam Girdwood }
334d1d95fcbSLiam Girdwood
snd_sof_dsp_write64(struct snd_sof_dev * sdev,u32 bar,u32 offset,u64 value)335d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write64(struct snd_sof_dev *sdev, u32 bar,
336d1d95fcbSLiam Girdwood u32 offset, u64 value)
337d1d95fcbSLiam Girdwood {
33801278cb6SPierre-Louis Bossart if (sof_ops(sdev)->write64)
339d1d95fcbSLiam Girdwood sof_ops(sdev)->write64(sdev, sdev->bar[bar] + offset, value);
34001278cb6SPierre-Louis Bossart else
34101278cb6SPierre-Louis Bossart writeq(value, sdev->bar[bar] + offset);
342d1d95fcbSLiam Girdwood }
343d1d95fcbSLiam Girdwood
snd_sof_dsp_read8(struct snd_sof_dev * sdev,u32 bar,u32 offset)344f8fbf0dcSPierre-Louis Bossart static inline u8 snd_sof_dsp_read8(struct snd_sof_dev *sdev, u32 bar,
34574fe0c4dSPierre-Louis Bossart u32 offset)
34674fe0c4dSPierre-Louis Bossart {
347f8fbf0dcSPierre-Louis Bossart if (sof_ops(sdev)->read8)
348f8fbf0dcSPierre-Louis Bossart return sof_ops(sdev)->read8(sdev, sdev->bar[bar] + offset);
34974fe0c4dSPierre-Louis Bossart else
35074fe0c4dSPierre-Louis Bossart return readb(sdev->bar[bar] + offset);
35174fe0c4dSPierre-Louis Bossart }
35274fe0c4dSPierre-Louis Bossart
snd_sof_dsp_read(struct snd_sof_dev * sdev,u32 bar,u32 offset)353d1d95fcbSLiam Girdwood static inline u32 snd_sof_dsp_read(struct snd_sof_dev *sdev, u32 bar,
354d1d95fcbSLiam Girdwood u32 offset)
355d1d95fcbSLiam Girdwood {
356d1d95fcbSLiam Girdwood if (sof_ops(sdev)->read)
357d1d95fcbSLiam Girdwood return sof_ops(sdev)->read(sdev, sdev->bar[bar] + offset);
35801278cb6SPierre-Louis Bossart else
35901278cb6SPierre-Louis Bossart return readl(sdev->bar[bar] + offset);
360d1d95fcbSLiam Girdwood }
361d1d95fcbSLiam Girdwood
snd_sof_dsp_read64(struct snd_sof_dev * sdev,u32 bar,u32 offset)362d1d95fcbSLiam Girdwood static inline u64 snd_sof_dsp_read64(struct snd_sof_dev *sdev, u32 bar,
363d1d95fcbSLiam Girdwood u32 offset)
364d1d95fcbSLiam Girdwood {
365d1d95fcbSLiam Girdwood if (sof_ops(sdev)->read64)
366d1d95fcbSLiam Girdwood return sof_ops(sdev)->read64(sdev, sdev->bar[bar] + offset);
36701278cb6SPierre-Louis Bossart else
36801278cb6SPierre-Louis Bossart return readq(sdev->bar[bar] + offset);
369d1d95fcbSLiam Girdwood }
370d1d95fcbSLiam Girdwood
snd_sof_dsp_update8(struct snd_sof_dev * sdev,u32 bar,u32 offset,u8 mask,u8 value)371f8fbf0dcSPierre-Louis Bossart static inline void snd_sof_dsp_update8(struct snd_sof_dev *sdev, u32 bar,
3725afc7eefSRander Wang u32 offset, u8 mask, u8 value)
373c28a36b0SPierre-Louis Bossart {
374c28a36b0SPierre-Louis Bossart u8 reg;
375c28a36b0SPierre-Louis Bossart
376f8fbf0dcSPierre-Louis Bossart reg = snd_sof_dsp_read8(sdev, bar, offset);
377c28a36b0SPierre-Louis Bossart reg &= ~mask;
378c28a36b0SPierre-Louis Bossart reg |= value;
379f8fbf0dcSPierre-Louis Bossart snd_sof_dsp_write8(sdev, bar, offset, reg);
380c28a36b0SPierre-Louis Bossart }
381c28a36b0SPierre-Louis Bossart
382d1d95fcbSLiam Girdwood /* block IO */
snd_sof_dsp_block_read(struct snd_sof_dev * sdev,enum snd_sof_fw_blk_type blk_type,u32 offset,void * dest,size_t bytes)3834624bb2fSPeter Ujfalusi static inline int snd_sof_dsp_block_read(struct snd_sof_dev *sdev,
3844624bb2fSPeter Ujfalusi enum snd_sof_fw_blk_type blk_type,
385d1d95fcbSLiam Girdwood u32 offset, void *dest, size_t bytes)
386d1d95fcbSLiam Girdwood {
3874624bb2fSPeter Ujfalusi return sof_ops(sdev)->block_read(sdev, blk_type, offset, dest, bytes);
388d1d95fcbSLiam Girdwood }
389d1d95fcbSLiam Girdwood
snd_sof_dsp_block_write(struct snd_sof_dev * sdev,enum snd_sof_fw_blk_type blk_type,u32 offset,void * src,size_t bytes)3904624bb2fSPeter Ujfalusi static inline int snd_sof_dsp_block_write(struct snd_sof_dev *sdev,
3914624bb2fSPeter Ujfalusi enum snd_sof_fw_blk_type blk_type,
392d1d95fcbSLiam Girdwood u32 offset, void *src, size_t bytes)
393d1d95fcbSLiam Girdwood {
3944624bb2fSPeter Ujfalusi return sof_ops(sdev)->block_write(sdev, blk_type, offset, src, bytes);
395d1d95fcbSLiam Girdwood }
396d1d95fcbSLiam Girdwood
397f71f59ddSDaniel Baluta /* mailbox IO */
snd_sof_dsp_mailbox_read(struct snd_sof_dev * sdev,u32 offset,void * dest,size_t bytes)398f71f59ddSDaniel Baluta static inline void snd_sof_dsp_mailbox_read(struct snd_sof_dev *sdev,
399f71f59ddSDaniel Baluta u32 offset, void *dest, size_t bytes)
400f71f59ddSDaniel Baluta {
401f71f59ddSDaniel Baluta if (sof_ops(sdev)->mailbox_read)
402f71f59ddSDaniel Baluta sof_ops(sdev)->mailbox_read(sdev, offset, dest, bytes);
403f71f59ddSDaniel Baluta }
404f71f59ddSDaniel Baluta
snd_sof_dsp_mailbox_write(struct snd_sof_dev * sdev,u32 offset,void * src,size_t bytes)405f71f59ddSDaniel Baluta static inline void snd_sof_dsp_mailbox_write(struct snd_sof_dev *sdev,
406f71f59ddSDaniel Baluta u32 offset, void *src, size_t bytes)
407f71f59ddSDaniel Baluta {
408f71f59ddSDaniel Baluta if (sof_ops(sdev)->mailbox_write)
409f71f59ddSDaniel Baluta sof_ops(sdev)->mailbox_write(sdev, offset, src, bytes);
410f71f59ddSDaniel Baluta }
411f71f59ddSDaniel Baluta
412d1d95fcbSLiam Girdwood /* ipc */
snd_sof_dsp_send_msg(struct snd_sof_dev * sdev,struct snd_sof_ipc_msg * msg)413d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_send_msg(struct snd_sof_dev *sdev,
414d1d95fcbSLiam Girdwood struct snd_sof_ipc_msg *msg)
415d1d95fcbSLiam Girdwood {
416d1d95fcbSLiam Girdwood return sof_ops(sdev)->send_msg(sdev, msg);
417d1d95fcbSLiam Girdwood }
418d1d95fcbSLiam Girdwood
419d1d95fcbSLiam Girdwood /* host PCM ops */
420d1d95fcbSLiam Girdwood static inline int
snd_sof_pcm_platform_open(struct snd_sof_dev * sdev,struct snd_pcm_substream * substream)421d1d95fcbSLiam Girdwood snd_sof_pcm_platform_open(struct snd_sof_dev *sdev,
422d1d95fcbSLiam Girdwood struct snd_pcm_substream *substream)
423d1d95fcbSLiam Girdwood {
424d1d95fcbSLiam Girdwood if (sof_ops(sdev) && sof_ops(sdev)->pcm_open)
425d1d95fcbSLiam Girdwood return sof_ops(sdev)->pcm_open(sdev, substream);
426d1d95fcbSLiam Girdwood
427d1d95fcbSLiam Girdwood return 0;
428d1d95fcbSLiam Girdwood }
429d1d95fcbSLiam Girdwood
430d1d95fcbSLiam Girdwood /* disconnect pcm substream to a host stream */
431d1d95fcbSLiam Girdwood static inline int
snd_sof_pcm_platform_close(struct snd_sof_dev * sdev,struct snd_pcm_substream * substream)432d1d95fcbSLiam Girdwood snd_sof_pcm_platform_close(struct snd_sof_dev *sdev,
433d1d95fcbSLiam Girdwood struct snd_pcm_substream *substream)
434d1d95fcbSLiam Girdwood {
435d1d95fcbSLiam Girdwood if (sof_ops(sdev) && sof_ops(sdev)->pcm_close)
436d1d95fcbSLiam Girdwood return sof_ops(sdev)->pcm_close(sdev, substream);
437d1d95fcbSLiam Girdwood
438d1d95fcbSLiam Girdwood return 0;
439d1d95fcbSLiam Girdwood }
440d1d95fcbSLiam Girdwood
441d1d95fcbSLiam Girdwood /* host stream hw params */
442d1d95fcbSLiam Girdwood static inline int
snd_sof_pcm_platform_hw_params(struct snd_sof_dev * sdev,struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_sof_platform_stream_params * platform_params)443d1d95fcbSLiam Girdwood snd_sof_pcm_platform_hw_params(struct snd_sof_dev *sdev,
444d1d95fcbSLiam Girdwood struct snd_pcm_substream *substream,
445d1d95fcbSLiam Girdwood struct snd_pcm_hw_params *params,
44631f60a0cSPeter Ujfalusi struct snd_sof_platform_stream_params *platform_params)
447d1d95fcbSLiam Girdwood {
448d1d95fcbSLiam Girdwood if (sof_ops(sdev) && sof_ops(sdev)->pcm_hw_params)
44931f60a0cSPeter Ujfalusi return sof_ops(sdev)->pcm_hw_params(sdev, substream, params,
45031f60a0cSPeter Ujfalusi platform_params);
451d1d95fcbSLiam Girdwood
452d1d95fcbSLiam Girdwood return 0;
453d1d95fcbSLiam Girdwood }
454d1d95fcbSLiam Girdwood
45593146bc2SRanjani Sridharan /* host stream hw free */
45693146bc2SRanjani Sridharan static inline int
snd_sof_pcm_platform_hw_free(struct snd_sof_dev * sdev,struct snd_pcm_substream * substream)45793146bc2SRanjani Sridharan snd_sof_pcm_platform_hw_free(struct snd_sof_dev *sdev,
45893146bc2SRanjani Sridharan struct snd_pcm_substream *substream)
45993146bc2SRanjani Sridharan {
46093146bc2SRanjani Sridharan if (sof_ops(sdev) && sof_ops(sdev)->pcm_hw_free)
46193146bc2SRanjani Sridharan return sof_ops(sdev)->pcm_hw_free(sdev, substream);
46293146bc2SRanjani Sridharan
46393146bc2SRanjani Sridharan return 0;
46493146bc2SRanjani Sridharan }
46593146bc2SRanjani Sridharan
466d1d95fcbSLiam Girdwood /* host stream trigger */
467d1d95fcbSLiam Girdwood static inline int
snd_sof_pcm_platform_trigger(struct snd_sof_dev * sdev,struct snd_pcm_substream * substream,int cmd)468d1d95fcbSLiam Girdwood snd_sof_pcm_platform_trigger(struct snd_sof_dev *sdev,
469d1d95fcbSLiam Girdwood struct snd_pcm_substream *substream, int cmd)
470d1d95fcbSLiam Girdwood {
471d1d95fcbSLiam Girdwood if (sof_ops(sdev) && sof_ops(sdev)->pcm_trigger)
472d1d95fcbSLiam Girdwood return sof_ops(sdev)->pcm_trigger(sdev, substream, cmd);
473d1d95fcbSLiam Girdwood
474d1d95fcbSLiam Girdwood return 0;
475d1d95fcbSLiam Girdwood }
476d1d95fcbSLiam Girdwood
47796ec1741SPeter Ujfalusi /* Firmware loading */
snd_sof_load_firmware(struct snd_sof_dev * sdev)47896ec1741SPeter Ujfalusi static inline int snd_sof_load_firmware(struct snd_sof_dev *sdev)
47996ec1741SPeter Ujfalusi {
48096ec1741SPeter Ujfalusi dev_dbg(sdev->dev, "loading firmware\n");
48196ec1741SPeter Ujfalusi
48296ec1741SPeter Ujfalusi return sof_ops(sdev)->load_firmware(sdev);
48396ec1741SPeter Ujfalusi }
48496ec1741SPeter Ujfalusi
485d1d95fcbSLiam Girdwood /* host DSP message data */
snd_sof_ipc_msg_data(struct snd_sof_dev * sdev,struct snd_sof_pcm_stream * sps,void * p,size_t sz)4866a0ba071SGuennadi Liakhovetski static inline int snd_sof_ipc_msg_data(struct snd_sof_dev *sdev,
4871b905942SDaniel Baluta struct snd_sof_pcm_stream *sps,
488d1d95fcbSLiam Girdwood void *p, size_t sz)
489d1d95fcbSLiam Girdwood {
4901b905942SDaniel Baluta return sof_ops(sdev)->ipc_msg_data(sdev, sps, p, sz);
491d1d95fcbSLiam Girdwood }
492757ce810SPeter Ujfalusi /* host side configuration of the stream's data offset in stream mailbox area */
493757ce810SPeter Ujfalusi static inline int
snd_sof_set_stream_data_offset(struct snd_sof_dev * sdev,struct snd_sof_pcm_stream * sps,size_t posn_offset)494757ce810SPeter Ujfalusi snd_sof_set_stream_data_offset(struct snd_sof_dev *sdev,
495249f186dSDaniel Baluta struct snd_sof_pcm_stream *sps,
496757ce810SPeter Ujfalusi size_t posn_offset)
497757ce810SPeter Ujfalusi {
498757ce810SPeter Ujfalusi if (sof_ops(sdev) && sof_ops(sdev)->set_stream_data_offset)
499249f186dSDaniel Baluta return sof_ops(sdev)->set_stream_data_offset(sdev, sps,
500757ce810SPeter Ujfalusi posn_offset);
501757ce810SPeter Ujfalusi
502757ce810SPeter Ujfalusi return 0;
503757ce810SPeter Ujfalusi }
504757ce810SPeter Ujfalusi
505d1d95fcbSLiam Girdwood /* host stream pointer */
506d1d95fcbSLiam Girdwood static inline snd_pcm_uframes_t
snd_sof_pcm_platform_pointer(struct snd_sof_dev * sdev,struct snd_pcm_substream * substream)507d1d95fcbSLiam Girdwood snd_sof_pcm_platform_pointer(struct snd_sof_dev *sdev,
508d1d95fcbSLiam Girdwood struct snd_pcm_substream *substream)
509d1d95fcbSLiam Girdwood {
510d1d95fcbSLiam Girdwood if (sof_ops(sdev) && sof_ops(sdev)->pcm_pointer)
511d1d95fcbSLiam Girdwood return sof_ops(sdev)->pcm_pointer(sdev, substream);
512d1d95fcbSLiam Girdwood
513d1d95fcbSLiam Girdwood return 0;
514d1d95fcbSLiam Girdwood }
515d1d95fcbSLiam Girdwood
5164a39ea3fSRanjani Sridharan /* pcm ack */
snd_sof_pcm_platform_ack(struct snd_sof_dev * sdev,struct snd_pcm_substream * substream)5174a39ea3fSRanjani Sridharan static inline int snd_sof_pcm_platform_ack(struct snd_sof_dev *sdev,
5184a39ea3fSRanjani Sridharan struct snd_pcm_substream *substream)
5194a39ea3fSRanjani Sridharan {
5204a39ea3fSRanjani Sridharan if (sof_ops(sdev) && sof_ops(sdev)->pcm_ack)
5214a39ea3fSRanjani Sridharan return sof_ops(sdev)->pcm_ack(sdev, substream);
5224a39ea3fSRanjani Sridharan
5234a39ea3fSRanjani Sridharan return 0;
5244a39ea3fSRanjani Sridharan }
5254a39ea3fSRanjani Sridharan
526ce2faa9aSPeter Ujfalusi static inline u64
snd_sof_pcm_get_dai_frame_counter(struct snd_sof_dev * sdev,struct snd_soc_component * component,struct snd_pcm_substream * substream)527ce2faa9aSPeter Ujfalusi snd_sof_pcm_get_dai_frame_counter(struct snd_sof_dev *sdev,
528ce2faa9aSPeter Ujfalusi struct snd_soc_component *component,
529ce2faa9aSPeter Ujfalusi struct snd_pcm_substream *substream)
530ce2faa9aSPeter Ujfalusi {
531ce2faa9aSPeter Ujfalusi if (sof_ops(sdev) && sof_ops(sdev)->get_dai_frame_counter)
532ce2faa9aSPeter Ujfalusi return sof_ops(sdev)->get_dai_frame_counter(sdev, component,
533ce2faa9aSPeter Ujfalusi substream);
534ce2faa9aSPeter Ujfalusi
535ce2faa9aSPeter Ujfalusi return 0;
536ce2faa9aSPeter Ujfalusi }
537ce2faa9aSPeter Ujfalusi
538ce2faa9aSPeter Ujfalusi static inline u64
snd_sof_pcm_get_host_byte_counter(struct snd_sof_dev * sdev,struct snd_soc_component * component,struct snd_pcm_substream * substream)539ce2faa9aSPeter Ujfalusi snd_sof_pcm_get_host_byte_counter(struct snd_sof_dev *sdev,
540ce2faa9aSPeter Ujfalusi struct snd_soc_component *component,
541ce2faa9aSPeter Ujfalusi struct snd_pcm_substream *substream)
542ce2faa9aSPeter Ujfalusi {
543ce2faa9aSPeter Ujfalusi if (sof_ops(sdev) && sof_ops(sdev)->get_host_byte_counter)
544ce2faa9aSPeter Ujfalusi return sof_ops(sdev)->get_host_byte_counter(sdev, component,
545ce2faa9aSPeter Ujfalusi substream);
546ce2faa9aSPeter Ujfalusi
547ce2faa9aSPeter Ujfalusi return 0;
548ce2faa9aSPeter Ujfalusi }
549ce2faa9aSPeter Ujfalusi
550285880a2SDaniel Baluta /* machine driver */
551285880a2SDaniel Baluta static inline int
snd_sof_machine_register(struct snd_sof_dev * sdev,void * pdata)552285880a2SDaniel Baluta snd_sof_machine_register(struct snd_sof_dev *sdev, void *pdata)
553285880a2SDaniel Baluta {
554285880a2SDaniel Baluta if (sof_ops(sdev) && sof_ops(sdev)->machine_register)
555285880a2SDaniel Baluta return sof_ops(sdev)->machine_register(sdev, pdata);
556285880a2SDaniel Baluta
557285880a2SDaniel Baluta return 0;
558285880a2SDaniel Baluta }
559285880a2SDaniel Baluta
560285880a2SDaniel Baluta static inline void
snd_sof_machine_unregister(struct snd_sof_dev * sdev,void * pdata)561285880a2SDaniel Baluta snd_sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata)
562285880a2SDaniel Baluta {
563285880a2SDaniel Baluta if (sof_ops(sdev) && sof_ops(sdev)->machine_unregister)
564285880a2SDaniel Baluta sof_ops(sdev)->machine_unregister(sdev, pdata);
565285880a2SDaniel Baluta }
566285880a2SDaniel Baluta
567cb515f10SGuennadi Liakhovetski static inline struct snd_soc_acpi_mach *
snd_sof_machine_select(struct snd_sof_dev * sdev)568285880a2SDaniel Baluta snd_sof_machine_select(struct snd_sof_dev *sdev)
569285880a2SDaniel Baluta {
570285880a2SDaniel Baluta if (sof_ops(sdev) && sof_ops(sdev)->machine_select)
571cb515f10SGuennadi Liakhovetski return sof_ops(sdev)->machine_select(sdev);
572cb515f10SGuennadi Liakhovetski
573cb515f10SGuennadi Liakhovetski return NULL;
574285880a2SDaniel Baluta }
575285880a2SDaniel Baluta
576285880a2SDaniel Baluta static inline void
snd_sof_set_mach_params(struct snd_soc_acpi_mach * mach,struct snd_sof_dev * sdev)577cb515f10SGuennadi Liakhovetski snd_sof_set_mach_params(struct snd_soc_acpi_mach *mach,
57817e9d6b0SPierre-Louis Bossart struct snd_sof_dev *sdev)
579285880a2SDaniel Baluta {
580285880a2SDaniel Baluta if (sof_ops(sdev) && sof_ops(sdev)->set_mach_params)
58117e9d6b0SPierre-Louis Bossart sof_ops(sdev)->set_mach_params(mach, sdev);
582285880a2SDaniel Baluta }
583285880a2SDaniel Baluta
584ba91d091SPierre-Louis Bossart static inline bool
snd_sof_is_chain_dma_supported(struct snd_sof_dev * sdev,u32 dai_type)585ba91d091SPierre-Louis Bossart snd_sof_is_chain_dma_supported(struct snd_sof_dev *sdev, u32 dai_type)
586ba91d091SPierre-Louis Bossart {
587ba91d091SPierre-Louis Bossart if (sof_ops(sdev) && sof_ops(sdev)->is_chain_dma_supported)
588ba91d091SPierre-Louis Bossart return sof_ops(sdev)->is_chain_dma_supported(sdev, dai_type);
589ba91d091SPierre-Louis Bossart
590ba91d091SPierre-Louis Bossart return false;
591ba91d091SPierre-Louis Bossart }
592ba91d091SPierre-Louis Bossart
593d1d95fcbSLiam Girdwood /**
594d1d95fcbSLiam Girdwood * snd_sof_dsp_register_poll_timeout - Periodically poll an address
595d1d95fcbSLiam Girdwood * until a condition is met or a timeout occurs
596d1d95fcbSLiam Girdwood * @op: accessor function (takes @addr as its only argument)
597d1d95fcbSLiam Girdwood * @addr: Address to poll
598d1d95fcbSLiam Girdwood * @val: Variable to read the value into
599d1d95fcbSLiam Girdwood * @cond: Break condition (usually involving @val)
600d1d95fcbSLiam Girdwood * @sleep_us: Maximum time to sleep between reads in us (0
601d1d95fcbSLiam Girdwood * tight-loops). Should be less than ~20ms since usleep_range
602458f69efSMauro Carvalho Chehab * is used (see Documentation/timers/timers-howto.rst).
603d1d95fcbSLiam Girdwood * @timeout_us: Timeout in us, 0 means never timeout
604d1d95fcbSLiam Girdwood *
605d1d95fcbSLiam Girdwood * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
606d1d95fcbSLiam Girdwood * case, the last read value at @addr is stored in @val. Must not
607d1d95fcbSLiam Girdwood * be called from atomic context if sleep_us or timeout_us are used.
608d1d95fcbSLiam Girdwood *
609d1d95fcbSLiam Girdwood * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
610d1d95fcbSLiam Girdwood */
611d1d95fcbSLiam Girdwood #define snd_sof_dsp_read_poll_timeout(sdev, bar, offset, val, cond, sleep_us, timeout_us) \
612d1d95fcbSLiam Girdwood ({ \
613d1d95fcbSLiam Girdwood u64 __timeout_us = (timeout_us); \
614d1d95fcbSLiam Girdwood unsigned long __sleep_us = (sleep_us); \
615d1d95fcbSLiam Girdwood ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
616d1d95fcbSLiam Girdwood might_sleep_if((__sleep_us) != 0); \
617d1d95fcbSLiam Girdwood for (;;) { \
618d1d95fcbSLiam Girdwood (val) = snd_sof_dsp_read(sdev, bar, offset); \
619d1d95fcbSLiam Girdwood if (cond) { \
620d1d95fcbSLiam Girdwood dev_dbg(sdev->dev, \
6213b2e93edSKeyon Jie "FW Poll Status: reg[%#x]=%#x successful\n", \
6223b2e93edSKeyon Jie (offset), (val)); \
623d1d95fcbSLiam Girdwood break; \
624d1d95fcbSLiam Girdwood } \
625d1d95fcbSLiam Girdwood if (__timeout_us && \
626d1d95fcbSLiam Girdwood ktime_compare(ktime_get(), __timeout) > 0) { \
627d1d95fcbSLiam Girdwood (val) = snd_sof_dsp_read(sdev, bar, offset); \
628d1d95fcbSLiam Girdwood dev_dbg(sdev->dev, \
6293b2e93edSKeyon Jie "FW Poll Status: reg[%#x]=%#x timedout\n", \
6303b2e93edSKeyon Jie (offset), (val)); \
631d1d95fcbSLiam Girdwood break; \
632d1d95fcbSLiam Girdwood } \
633d1d95fcbSLiam Girdwood if (__sleep_us) \
634d1d95fcbSLiam Girdwood usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
635d1d95fcbSLiam Girdwood } \
636d1d95fcbSLiam Girdwood (cond) ? 0 : -ETIMEDOUT; \
637d1d95fcbSLiam Girdwood })
638d1d95fcbSLiam Girdwood
639d1d95fcbSLiam Girdwood /* This is for registers bits with attribute RWC */
640d1d95fcbSLiam Girdwood bool snd_sof_pci_update_bits(struct snd_sof_dev *sdev, u32 offset,
641d1d95fcbSLiam Girdwood u32 mask, u32 value);
642d1d95fcbSLiam Girdwood
643d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits_unlocked(struct snd_sof_dev *sdev, u32 bar,
644d1d95fcbSLiam Girdwood u32 offset, u32 mask, u32 value);
645d1d95fcbSLiam Girdwood
646d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64_unlocked(struct snd_sof_dev *sdev, u32 bar,
647d1d95fcbSLiam Girdwood u32 offset, u64 mask, u64 value);
648d1d95fcbSLiam Girdwood
649d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits(struct snd_sof_dev *sdev, u32 bar, u32 offset,
650d1d95fcbSLiam Girdwood u32 mask, u32 value);
651d1d95fcbSLiam Girdwood
652d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64(struct snd_sof_dev *sdev, u32 bar,
653d1d95fcbSLiam Girdwood u32 offset, u64 mask, u64 value);
654d1d95fcbSLiam Girdwood
655d1d95fcbSLiam Girdwood void snd_sof_dsp_update_bits_forced(struct snd_sof_dev *sdev, u32 bar,
656d1d95fcbSLiam Girdwood u32 offset, u32 mask, u32 value);
657d1d95fcbSLiam Girdwood
658d1d95fcbSLiam Girdwood int snd_sof_dsp_register_poll(struct snd_sof_dev *sdev, u32 bar, u32 offset,
659d1d95fcbSLiam Girdwood u32 mask, u32 target, u32 timeout_ms,
660d1d95fcbSLiam Girdwood u32 interval_us);
661d1d95fcbSLiam Girdwood
662b2b10aa7SPeter Ujfalusi void snd_sof_dsp_panic(struct snd_sof_dev *sdev, u32 offset, bool non_recoverable);
663d1d95fcbSLiam Girdwood #endif
664