xref: /openbmc/linux/sound/soc/sof/ops.h (revision d1d95fcb63e3b83245ad06484b6905ab6c21afc3)
1*d1d95fcbSLiam Girdwood /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2*d1d95fcbSLiam Girdwood /*
3*d1d95fcbSLiam Girdwood  * This file is provided under a dual BSD/GPLv2 license.  When using or
4*d1d95fcbSLiam Girdwood  * redistributing this file, you may do so under either license.
5*d1d95fcbSLiam Girdwood  *
6*d1d95fcbSLiam Girdwood  * Copyright(c) 2018 Intel Corporation. All rights reserved.
7*d1d95fcbSLiam Girdwood  *
8*d1d95fcbSLiam Girdwood  * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9*d1d95fcbSLiam Girdwood  */
10*d1d95fcbSLiam Girdwood 
11*d1d95fcbSLiam Girdwood #ifndef __SOUND_SOC_SOF_IO_H
12*d1d95fcbSLiam Girdwood #define __SOUND_SOC_SOF_IO_H
13*d1d95fcbSLiam Girdwood 
14*d1d95fcbSLiam Girdwood #include <linux/device.h>
15*d1d95fcbSLiam Girdwood #include <linux/interrupt.h>
16*d1d95fcbSLiam Girdwood #include <linux/kernel.h>
17*d1d95fcbSLiam Girdwood #include <linux/types.h>
18*d1d95fcbSLiam Girdwood #include <sound/pcm.h>
19*d1d95fcbSLiam Girdwood #include "sof-priv.h"
20*d1d95fcbSLiam Girdwood 
21*d1d95fcbSLiam Girdwood #define sof_ops(sdev) \
22*d1d95fcbSLiam Girdwood 	((sdev)->pdata->desc->ops)
23*d1d95fcbSLiam Girdwood 
24*d1d95fcbSLiam Girdwood /* Mandatory operations are verified during probing */
25*d1d95fcbSLiam Girdwood 
26*d1d95fcbSLiam Girdwood /* init */
27*d1d95fcbSLiam Girdwood static inline int snd_sof_probe(struct snd_sof_dev *sdev)
28*d1d95fcbSLiam Girdwood {
29*d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->probe(sdev);
30*d1d95fcbSLiam Girdwood }
31*d1d95fcbSLiam Girdwood 
32*d1d95fcbSLiam Girdwood static inline int snd_sof_remove(struct snd_sof_dev *sdev)
33*d1d95fcbSLiam Girdwood {
34*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->remove)
35*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->remove(sdev);
36*d1d95fcbSLiam Girdwood 
37*d1d95fcbSLiam Girdwood 	return 0;
38*d1d95fcbSLiam Girdwood }
39*d1d95fcbSLiam Girdwood 
40*d1d95fcbSLiam Girdwood /* control */
41*d1d95fcbSLiam Girdwood 
42*d1d95fcbSLiam Girdwood /*
43*d1d95fcbSLiam Girdwood  * snd_sof_dsp_run returns the core mask of the cores that are available
44*d1d95fcbSLiam Girdwood  * after successful fw boot
45*d1d95fcbSLiam Girdwood  */
46*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_run(struct snd_sof_dev *sdev)
47*d1d95fcbSLiam Girdwood {
48*d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->run(sdev);
49*d1d95fcbSLiam Girdwood }
50*d1d95fcbSLiam Girdwood 
51*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_stall(struct snd_sof_dev *sdev)
52*d1d95fcbSLiam Girdwood {
53*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->stall)
54*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->stall(sdev);
55*d1d95fcbSLiam Girdwood 
56*d1d95fcbSLiam Girdwood 	return 0;
57*d1d95fcbSLiam Girdwood }
58*d1d95fcbSLiam Girdwood 
59*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_reset(struct snd_sof_dev *sdev)
60*d1d95fcbSLiam Girdwood {
61*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->reset)
62*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->reset(sdev);
63*d1d95fcbSLiam Girdwood 
64*d1d95fcbSLiam Girdwood 	return 0;
65*d1d95fcbSLiam Girdwood }
66*d1d95fcbSLiam Girdwood 
67*d1d95fcbSLiam Girdwood /* dsp core power up/power down */
68*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_core_power_up(struct snd_sof_dev *sdev,
69*d1d95fcbSLiam Girdwood 					    unsigned int core_mask)
70*d1d95fcbSLiam Girdwood {
71*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->core_power_up)
72*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->core_power_up(sdev, core_mask);
73*d1d95fcbSLiam Girdwood 
74*d1d95fcbSLiam Girdwood 	return 0;
75*d1d95fcbSLiam Girdwood }
76*d1d95fcbSLiam Girdwood 
77*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_core_power_down(struct snd_sof_dev *sdev,
78*d1d95fcbSLiam Girdwood 					      unsigned int core_mask)
79*d1d95fcbSLiam Girdwood {
80*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->core_power_down)
81*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->core_power_down(sdev, core_mask);
82*d1d95fcbSLiam Girdwood 
83*d1d95fcbSLiam Girdwood 	return 0;
84*d1d95fcbSLiam Girdwood }
85*d1d95fcbSLiam Girdwood 
86*d1d95fcbSLiam Girdwood /* pre/post fw load */
87*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_pre_fw_run(struct snd_sof_dev *sdev)
88*d1d95fcbSLiam Girdwood {
89*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->pre_fw_run)
90*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pre_fw_run(sdev);
91*d1d95fcbSLiam Girdwood 
92*d1d95fcbSLiam Girdwood 	return 0;
93*d1d95fcbSLiam Girdwood }
94*d1d95fcbSLiam Girdwood 
95*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_post_fw_run(struct snd_sof_dev *sdev)
96*d1d95fcbSLiam Girdwood {
97*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->post_fw_run)
98*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->post_fw_run(sdev);
99*d1d95fcbSLiam Girdwood 
100*d1d95fcbSLiam Girdwood 	return 0;
101*d1d95fcbSLiam Girdwood }
102*d1d95fcbSLiam Girdwood 
103*d1d95fcbSLiam Girdwood /* power management */
104*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_resume(struct snd_sof_dev *sdev)
105*d1d95fcbSLiam Girdwood {
106*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->resume)
107*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->resume(sdev);
108*d1d95fcbSLiam Girdwood 
109*d1d95fcbSLiam Girdwood 	return 0;
110*d1d95fcbSLiam Girdwood }
111*d1d95fcbSLiam Girdwood 
112*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_suspend(struct snd_sof_dev *sdev, int state)
113*d1d95fcbSLiam Girdwood {
114*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->suspend)
115*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->suspend(sdev, state);
116*d1d95fcbSLiam Girdwood 
117*d1d95fcbSLiam Girdwood 	return 0;
118*d1d95fcbSLiam Girdwood }
119*d1d95fcbSLiam Girdwood 
120*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_runtime_resume(struct snd_sof_dev *sdev)
121*d1d95fcbSLiam Girdwood {
122*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->runtime_resume)
123*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->runtime_resume(sdev);
124*d1d95fcbSLiam Girdwood 
125*d1d95fcbSLiam Girdwood 	return 0;
126*d1d95fcbSLiam Girdwood }
127*d1d95fcbSLiam Girdwood 
128*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_runtime_suspend(struct snd_sof_dev *sdev,
129*d1d95fcbSLiam Girdwood 					      int state)
130*d1d95fcbSLiam Girdwood {
131*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->runtime_suspend)
132*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->runtime_suspend(sdev, state);
133*d1d95fcbSLiam Girdwood 
134*d1d95fcbSLiam Girdwood 	return 0;
135*d1d95fcbSLiam Girdwood }
136*d1d95fcbSLiam Girdwood 
137*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_set_clk(struct snd_sof_dev *sdev, u32 freq)
138*d1d95fcbSLiam Girdwood {
139*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->set_clk)
140*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->set_clk(sdev, freq);
141*d1d95fcbSLiam Girdwood 
142*d1d95fcbSLiam Girdwood 	return 0;
143*d1d95fcbSLiam Girdwood }
144*d1d95fcbSLiam Girdwood 
145*d1d95fcbSLiam Girdwood /* debug */
146*d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_dbg_dump(struct snd_sof_dev *sdev, u32 flags)
147*d1d95fcbSLiam Girdwood {
148*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->dbg_dump)
149*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->dbg_dump(sdev, flags);
150*d1d95fcbSLiam Girdwood }
151*d1d95fcbSLiam Girdwood 
152*d1d95fcbSLiam Girdwood /* register IO */
153*d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write(struct snd_sof_dev *sdev, u32 bar,
154*d1d95fcbSLiam Girdwood 				     u32 offset, u32 value)
155*d1d95fcbSLiam Girdwood {
156*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->write) {
157*d1d95fcbSLiam Girdwood 		sof_ops(sdev)->write(sdev, sdev->bar[bar] + offset, value);
158*d1d95fcbSLiam Girdwood 		return;
159*d1d95fcbSLiam Girdwood 	}
160*d1d95fcbSLiam Girdwood 
161*d1d95fcbSLiam Girdwood 	dev_err_ratelimited(sdev->dev, "error: %s not defined\n", __func__);
162*d1d95fcbSLiam Girdwood }
163*d1d95fcbSLiam Girdwood 
164*d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_write64(struct snd_sof_dev *sdev, u32 bar,
165*d1d95fcbSLiam Girdwood 				       u32 offset, u64 value)
166*d1d95fcbSLiam Girdwood {
167*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->write64) {
168*d1d95fcbSLiam Girdwood 		sof_ops(sdev)->write64(sdev, sdev->bar[bar] + offset, value);
169*d1d95fcbSLiam Girdwood 		return;
170*d1d95fcbSLiam Girdwood 	}
171*d1d95fcbSLiam Girdwood 
172*d1d95fcbSLiam Girdwood 	dev_err_ratelimited(sdev->dev, "error: %s not defined\n", __func__);
173*d1d95fcbSLiam Girdwood }
174*d1d95fcbSLiam Girdwood 
175*d1d95fcbSLiam Girdwood static inline u32 snd_sof_dsp_read(struct snd_sof_dev *sdev, u32 bar,
176*d1d95fcbSLiam Girdwood 				   u32 offset)
177*d1d95fcbSLiam Girdwood {
178*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->read)
179*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->read(sdev, sdev->bar[bar] + offset);
180*d1d95fcbSLiam Girdwood 
181*d1d95fcbSLiam Girdwood 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
182*d1d95fcbSLiam Girdwood 	return -ENOTSUPP;
183*d1d95fcbSLiam Girdwood }
184*d1d95fcbSLiam Girdwood 
185*d1d95fcbSLiam Girdwood static inline u64 snd_sof_dsp_read64(struct snd_sof_dev *sdev, u32 bar,
186*d1d95fcbSLiam Girdwood 				     u32 offset)
187*d1d95fcbSLiam Girdwood {
188*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->read64)
189*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->read64(sdev, sdev->bar[bar] + offset);
190*d1d95fcbSLiam Girdwood 
191*d1d95fcbSLiam Girdwood 	dev_err(sdev->dev, "error: %s not defined\n", __func__);
192*d1d95fcbSLiam Girdwood 	return -ENOTSUPP;
193*d1d95fcbSLiam Girdwood }
194*d1d95fcbSLiam Girdwood 
195*d1d95fcbSLiam Girdwood /* block IO */
196*d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_block_read(struct snd_sof_dev *sdev, u32 bar,
197*d1d95fcbSLiam Girdwood 					  u32 offset, void *dest, size_t bytes)
198*d1d95fcbSLiam Girdwood {
199*d1d95fcbSLiam Girdwood 	sof_ops(sdev)->block_read(sdev, bar, offset, dest, bytes);
200*d1d95fcbSLiam Girdwood }
201*d1d95fcbSLiam Girdwood 
202*d1d95fcbSLiam Girdwood static inline void snd_sof_dsp_block_write(struct snd_sof_dev *sdev, u32 bar,
203*d1d95fcbSLiam Girdwood 					   u32 offset, void *src, size_t bytes)
204*d1d95fcbSLiam Girdwood {
205*d1d95fcbSLiam Girdwood 	sof_ops(sdev)->block_write(sdev, bar, offset, src, bytes);
206*d1d95fcbSLiam Girdwood }
207*d1d95fcbSLiam Girdwood 
208*d1d95fcbSLiam Girdwood /* ipc */
209*d1d95fcbSLiam Girdwood static inline int snd_sof_dsp_send_msg(struct snd_sof_dev *sdev,
210*d1d95fcbSLiam Girdwood 				       struct snd_sof_ipc_msg *msg)
211*d1d95fcbSLiam Girdwood {
212*d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->send_msg(sdev, msg);
213*d1d95fcbSLiam Girdwood }
214*d1d95fcbSLiam Girdwood 
215*d1d95fcbSLiam Girdwood /* host DMA trace */
216*d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_init(struct snd_sof_dev *sdev,
217*d1d95fcbSLiam Girdwood 					 u32 *stream_tag)
218*d1d95fcbSLiam Girdwood {
219*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_init)
220*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_init(sdev, stream_tag);
221*d1d95fcbSLiam Girdwood 
222*d1d95fcbSLiam Girdwood 	return 0;
223*d1d95fcbSLiam Girdwood }
224*d1d95fcbSLiam Girdwood 
225*d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_release(struct snd_sof_dev *sdev)
226*d1d95fcbSLiam Girdwood {
227*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_release)
228*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_release(sdev);
229*d1d95fcbSLiam Girdwood 
230*d1d95fcbSLiam Girdwood 	return 0;
231*d1d95fcbSLiam Girdwood }
232*d1d95fcbSLiam Girdwood 
233*d1d95fcbSLiam Girdwood static inline int snd_sof_dma_trace_trigger(struct snd_sof_dev *sdev, int cmd)
234*d1d95fcbSLiam Girdwood {
235*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev)->trace_trigger)
236*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->trace_trigger(sdev, cmd);
237*d1d95fcbSLiam Girdwood 
238*d1d95fcbSLiam Girdwood 	return 0;
239*d1d95fcbSLiam Girdwood }
240*d1d95fcbSLiam Girdwood 
241*d1d95fcbSLiam Girdwood /* host PCM ops */
242*d1d95fcbSLiam Girdwood static inline int
243*d1d95fcbSLiam Girdwood snd_sof_pcm_platform_open(struct snd_sof_dev *sdev,
244*d1d95fcbSLiam Girdwood 			  struct snd_pcm_substream *substream)
245*d1d95fcbSLiam Girdwood {
246*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_open)
247*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_open(sdev, substream);
248*d1d95fcbSLiam Girdwood 
249*d1d95fcbSLiam Girdwood 	return 0;
250*d1d95fcbSLiam Girdwood }
251*d1d95fcbSLiam Girdwood 
252*d1d95fcbSLiam Girdwood /* disconnect pcm substream to a host stream */
253*d1d95fcbSLiam Girdwood static inline int
254*d1d95fcbSLiam Girdwood snd_sof_pcm_platform_close(struct snd_sof_dev *sdev,
255*d1d95fcbSLiam Girdwood 			   struct snd_pcm_substream *substream)
256*d1d95fcbSLiam Girdwood {
257*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_close)
258*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_close(sdev, substream);
259*d1d95fcbSLiam Girdwood 
260*d1d95fcbSLiam Girdwood 	return 0;
261*d1d95fcbSLiam Girdwood }
262*d1d95fcbSLiam Girdwood 
263*d1d95fcbSLiam Girdwood /* host stream hw params */
264*d1d95fcbSLiam Girdwood static inline int
265*d1d95fcbSLiam Girdwood snd_sof_pcm_platform_hw_params(struct snd_sof_dev *sdev,
266*d1d95fcbSLiam Girdwood 			       struct snd_pcm_substream *substream,
267*d1d95fcbSLiam Girdwood 			       struct snd_pcm_hw_params *params,
268*d1d95fcbSLiam Girdwood 			       struct sof_ipc_stream_params *ipc_params)
269*d1d95fcbSLiam Girdwood {
270*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_hw_params)
271*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_hw_params(sdev, substream,
272*d1d95fcbSLiam Girdwood 						    params, ipc_params);
273*d1d95fcbSLiam Girdwood 
274*d1d95fcbSLiam Girdwood 	return 0;
275*d1d95fcbSLiam Girdwood }
276*d1d95fcbSLiam Girdwood 
277*d1d95fcbSLiam Girdwood /* host stream trigger */
278*d1d95fcbSLiam Girdwood static inline int
279*d1d95fcbSLiam Girdwood snd_sof_pcm_platform_trigger(struct snd_sof_dev *sdev,
280*d1d95fcbSLiam Girdwood 			     struct snd_pcm_substream *substream, int cmd)
281*d1d95fcbSLiam Girdwood {
282*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_trigger)
283*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_trigger(sdev, substream, cmd);
284*d1d95fcbSLiam Girdwood 
285*d1d95fcbSLiam Girdwood 	return 0;
286*d1d95fcbSLiam Girdwood }
287*d1d95fcbSLiam Girdwood 
288*d1d95fcbSLiam Girdwood /* host DSP message data */
289*d1d95fcbSLiam Girdwood static inline void snd_sof_ipc_msg_data(struct snd_sof_dev *sdev,
290*d1d95fcbSLiam Girdwood 					struct snd_pcm_substream *substream,
291*d1d95fcbSLiam Girdwood 					void *p, size_t sz)
292*d1d95fcbSLiam Girdwood {
293*d1d95fcbSLiam Girdwood 	sof_ops(sdev)->ipc_msg_data(sdev, substream, p, sz);
294*d1d95fcbSLiam Girdwood }
295*d1d95fcbSLiam Girdwood 
296*d1d95fcbSLiam Girdwood /* host configure DSP HW parameters */
297*d1d95fcbSLiam Girdwood static inline int
298*d1d95fcbSLiam Girdwood snd_sof_ipc_pcm_params(struct snd_sof_dev *sdev,
299*d1d95fcbSLiam Girdwood 		       struct snd_pcm_substream *substream,
300*d1d95fcbSLiam Girdwood 		       const struct sof_ipc_pcm_params_reply *reply)
301*d1d95fcbSLiam Girdwood {
302*d1d95fcbSLiam Girdwood 	return sof_ops(sdev)->ipc_pcm_params(sdev, substream, reply);
303*d1d95fcbSLiam Girdwood }
304*d1d95fcbSLiam Girdwood 
305*d1d95fcbSLiam Girdwood /* host stream pointer */
306*d1d95fcbSLiam Girdwood static inline snd_pcm_uframes_t
307*d1d95fcbSLiam Girdwood snd_sof_pcm_platform_pointer(struct snd_sof_dev *sdev,
308*d1d95fcbSLiam Girdwood 			     struct snd_pcm_substream *substream)
309*d1d95fcbSLiam Girdwood {
310*d1d95fcbSLiam Girdwood 	if (sof_ops(sdev) && sof_ops(sdev)->pcm_pointer)
311*d1d95fcbSLiam Girdwood 		return sof_ops(sdev)->pcm_pointer(sdev, substream);
312*d1d95fcbSLiam Girdwood 
313*d1d95fcbSLiam Girdwood 	return 0;
314*d1d95fcbSLiam Girdwood }
315*d1d95fcbSLiam Girdwood 
316*d1d95fcbSLiam Girdwood static inline const struct snd_sof_dsp_ops
317*d1d95fcbSLiam Girdwood *sof_get_ops(const struct sof_dev_desc *d,
318*d1d95fcbSLiam Girdwood 	     const struct sof_ops_table mach_ops[], int asize)
319*d1d95fcbSLiam Girdwood {
320*d1d95fcbSLiam Girdwood 	int i;
321*d1d95fcbSLiam Girdwood 
322*d1d95fcbSLiam Girdwood 	for (i = 0; i < asize; i++) {
323*d1d95fcbSLiam Girdwood 		if (d == mach_ops[i].desc)
324*d1d95fcbSLiam Girdwood 			return mach_ops[i].ops;
325*d1d95fcbSLiam Girdwood 	}
326*d1d95fcbSLiam Girdwood 
327*d1d95fcbSLiam Girdwood 	/* not found */
328*d1d95fcbSLiam Girdwood 	return NULL;
329*d1d95fcbSLiam Girdwood }
330*d1d95fcbSLiam Girdwood 
331*d1d95fcbSLiam Girdwood /**
332*d1d95fcbSLiam Girdwood  * snd_sof_dsp_register_poll_timeout - Periodically poll an address
333*d1d95fcbSLiam Girdwood  * until a condition is met or a timeout occurs
334*d1d95fcbSLiam Girdwood  * @op: accessor function (takes @addr as its only argument)
335*d1d95fcbSLiam Girdwood  * @addr: Address to poll
336*d1d95fcbSLiam Girdwood  * @val: Variable to read the value into
337*d1d95fcbSLiam Girdwood  * @cond: Break condition (usually involving @val)
338*d1d95fcbSLiam Girdwood  * @sleep_us: Maximum time to sleep between reads in us (0
339*d1d95fcbSLiam Girdwood  *            tight-loops).  Should be less than ~20ms since usleep_range
340*d1d95fcbSLiam Girdwood  *            is used (see Documentation/timers/timers-howto.txt).
341*d1d95fcbSLiam Girdwood  * @timeout_us: Timeout in us, 0 means never timeout
342*d1d95fcbSLiam Girdwood  *
343*d1d95fcbSLiam Girdwood  * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
344*d1d95fcbSLiam Girdwood  * case, the last read value at @addr is stored in @val. Must not
345*d1d95fcbSLiam Girdwood  * be called from atomic context if sleep_us or timeout_us are used.
346*d1d95fcbSLiam Girdwood  *
347*d1d95fcbSLiam Girdwood  * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
348*d1d95fcbSLiam Girdwood  */
349*d1d95fcbSLiam Girdwood #define snd_sof_dsp_read_poll_timeout(sdev, bar, offset, val, cond, sleep_us, timeout_us) \
350*d1d95fcbSLiam Girdwood ({ \
351*d1d95fcbSLiam Girdwood 	u64 __timeout_us = (timeout_us); \
352*d1d95fcbSLiam Girdwood 	unsigned long __sleep_us = (sleep_us); \
353*d1d95fcbSLiam Girdwood 	ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
354*d1d95fcbSLiam Girdwood 	might_sleep_if((__sleep_us) != 0); \
355*d1d95fcbSLiam Girdwood 	for (;;) {							\
356*d1d95fcbSLiam Girdwood 		(val) = snd_sof_dsp_read(sdev, bar, offset);		\
357*d1d95fcbSLiam Girdwood 		if (cond) { \
358*d1d95fcbSLiam Girdwood 			dev_dbg(sdev->dev, \
359*d1d95fcbSLiam Girdwood 				"FW Poll Status: reg=%#x successful\n", (val)); \
360*d1d95fcbSLiam Girdwood 			break; \
361*d1d95fcbSLiam Girdwood 		} \
362*d1d95fcbSLiam Girdwood 		if (__timeout_us && \
363*d1d95fcbSLiam Girdwood 		    ktime_compare(ktime_get(), __timeout) > 0) { \
364*d1d95fcbSLiam Girdwood 			(val) = snd_sof_dsp_read(sdev, bar, offset); \
365*d1d95fcbSLiam Girdwood 			dev_dbg(sdev->dev, \
366*d1d95fcbSLiam Girdwood 				"FW Poll Status: reg=%#x timedout\n", (val)); \
367*d1d95fcbSLiam Girdwood 			break; \
368*d1d95fcbSLiam Girdwood 		} \
369*d1d95fcbSLiam Girdwood 		if (__sleep_us) \
370*d1d95fcbSLiam Girdwood 			usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
371*d1d95fcbSLiam Girdwood 	} \
372*d1d95fcbSLiam Girdwood 	(cond) ? 0 : -ETIMEDOUT; \
373*d1d95fcbSLiam Girdwood })
374*d1d95fcbSLiam Girdwood 
375*d1d95fcbSLiam Girdwood /* This is for registers bits with attribute RWC */
376*d1d95fcbSLiam Girdwood bool snd_sof_pci_update_bits(struct snd_sof_dev *sdev, u32 offset,
377*d1d95fcbSLiam Girdwood 			     u32 mask, u32 value);
378*d1d95fcbSLiam Girdwood 
379*d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits_unlocked(struct snd_sof_dev *sdev, u32 bar,
380*d1d95fcbSLiam Girdwood 				      u32 offset, u32 mask, u32 value);
381*d1d95fcbSLiam Girdwood 
382*d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64_unlocked(struct snd_sof_dev *sdev, u32 bar,
383*d1d95fcbSLiam Girdwood 					u32 offset, u64 mask, u64 value);
384*d1d95fcbSLiam Girdwood 
385*d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits(struct snd_sof_dev *sdev, u32 bar, u32 offset,
386*d1d95fcbSLiam Girdwood 			     u32 mask, u32 value);
387*d1d95fcbSLiam Girdwood 
388*d1d95fcbSLiam Girdwood bool snd_sof_dsp_update_bits64(struct snd_sof_dev *sdev, u32 bar,
389*d1d95fcbSLiam Girdwood 			       u32 offset, u64 mask, u64 value);
390*d1d95fcbSLiam Girdwood 
391*d1d95fcbSLiam Girdwood void snd_sof_dsp_update_bits_forced(struct snd_sof_dev *sdev, u32 bar,
392*d1d95fcbSLiam Girdwood 				    u32 offset, u32 mask, u32 value);
393*d1d95fcbSLiam Girdwood 
394*d1d95fcbSLiam Girdwood int snd_sof_dsp_register_poll(struct snd_sof_dev *sdev, u32 bar, u32 offset,
395*d1d95fcbSLiam Girdwood 			      u32 mask, u32 target, u32 timeout_ms,
396*d1d95fcbSLiam Girdwood 			      u32 interval_us);
397*d1d95fcbSLiam Girdwood 
398*d1d95fcbSLiam Girdwood void snd_sof_dsp_panic(struct snd_sof_dev *sdev, u32 offset);
399*d1d95fcbSLiam Girdwood #endif
400