V4L/DVB (9720): cx18: Major rewrite of interrupt handling for incoming mailbox processing
[deliverable/linux.git] / drivers / media / video / cx18 / cx18-io.h
CommitLineData
b1526421
AW
1/*
2 * cx18 driver PCI memory mapped IO access routines
3 *
4 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
5 * Copyright (C) 2008 Andy Walls <awalls@radix.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307 USA
21 */
22
23#ifndef CX18_IO_H
24#define CX18_IO_H
25
26#include "cx18-driver.h"
27
c641d09c
AW
28static inline void cx18_io_delay(struct cx18 *cx)
29{
30 if (cx->options.mmio_ndelay)
31 ndelay(cx->options.mmio_ndelay);
32}
b1526421 33
d267d851
AW
34/*
35 * Readback and retry of MMIO access for reliability:
36 * The concept was suggested by Steve Toth <stoth@linuxtv.org>.
37 * The implmentation is the fault of Andy Walls <awalls@radix.net>.
38 */
39
40/* Statistics gathering */
41static inline
06869713 42void cx18_log_write_retries(struct cx18 *cx, int i, const void __iomem *addr)
d267d851 43{
f7823f8f
AW
44 if (i > CX18_MAX_MMIO_WR_RETRIES)
45 i = CX18_MAX_MMIO_WR_RETRIES;
d267d851
AW
46 atomic_inc(&cx->mmio_stats.retried_write[i]);
47 return;
48}
49
50static inline
06869713 51void cx18_log_read_retries(struct cx18 *cx, int i, const void __iomem *addr)
d267d851 52{
f7823f8f
AW
53 if (i > CX18_MAX_MMIO_RD_RETRIES)
54 i = CX18_MAX_MMIO_RD_RETRIES;
d267d851
AW
55 atomic_inc(&cx->mmio_stats.retried_read[i]);
56 return;
57}
58
59void cx18_log_statistics(struct cx18 *cx);
60
c641d09c 61/* Non byteswapping memory mapped IO */
d267d851
AW
62static inline
63void cx18_raw_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
c641d09c
AW
64{
65 __raw_writel(val, addr);
66 cx18_io_delay(cx);
67}
b1526421 68
d267d851
AW
69void cx18_raw_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr);
70
71static inline void cx18_raw_writel(struct cx18 *cx, u32 val, void __iomem *addr)
72{
73 if (cx18_retry_mmio)
74 cx18_raw_writel_retry(cx, val, addr);
75 else
76 cx18_raw_writel_noretry(cx, val, addr);
77}
78
79
80static inline
81u32 cx18_raw_readl_noretry(struct cx18 *cx, const void __iomem *addr)
c641d09c
AW
82{
83 u32 ret = __raw_readl(addr);
84 cx18_io_delay(cx);
85 return ret;
86}
b1526421 87
d267d851
AW
88u32 cx18_raw_readl_retry(struct cx18 *cx, const void __iomem *addr);
89
90static inline u32 cx18_raw_readl(struct cx18 *cx, const void __iomem *addr)
91{
92 if (cx18_retry_mmio)
93 return cx18_raw_readl_retry(cx, addr);
94
95 return cx18_raw_readl_noretry(cx, addr);
96}
97
98
99static inline
100u16 cx18_raw_readw_noretry(struct cx18 *cx, const void __iomem *addr)
c641d09c
AW
101{
102 u16 ret = __raw_readw(addr);
103 cx18_io_delay(cx);
104 return ret;
105}
b1526421 106
d267d851
AW
107u16 cx18_raw_readw_retry(struct cx18 *cx, const void __iomem *addr);
108
109static inline u16 cx18_raw_readw(struct cx18 *cx, const void __iomem *addr)
110{
111 if (cx18_retry_mmio)
112 return cx18_raw_readw_retry(cx, addr);
113
114 return cx18_raw_readw_noretry(cx, addr);
115}
116
117
c641d09c 118/* Normal memory mapped IO */
d267d851
AW
119static inline
120void cx18_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
c641d09c
AW
121{
122 writel(val, addr);
123 cx18_io_delay(cx);
124}
b1526421 125
d267d851
AW
126void cx18_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr);
127
128static inline void cx18_writel(struct cx18 *cx, u32 val, void __iomem *addr)
129{
130 if (cx18_retry_mmio)
131 cx18_writel_retry(cx, val, addr);
132 else
133 cx18_writel_noretry(cx, val, addr);
134}
135
f056d29e
AW
136void _cx18_writel_expect(struct cx18 *cx, u32 val, void __iomem *addr,
137 u32 eval, u32 mask);
d267d851
AW
138
139static inline
140void cx18_writew_noretry(struct cx18 *cx, u16 val, void __iomem *addr)
c641d09c
AW
141{
142 writew(val, addr);
143 cx18_io_delay(cx);
144}
145
d267d851
AW
146void cx18_writew_retry(struct cx18 *cx, u16 val, void __iomem *addr);
147
148static inline void cx18_writew(struct cx18 *cx, u16 val, void __iomem *addr)
149{
150 if (cx18_retry_mmio)
151 cx18_writew_retry(cx, val, addr);
152 else
153 cx18_writew_noretry(cx, val, addr);
154}
155
156
157static inline
158void cx18_writeb_noretry(struct cx18 *cx, u8 val, void __iomem *addr)
c641d09c
AW
159{
160 writeb(val, addr);
161 cx18_io_delay(cx);
162}
163
d267d851
AW
164void cx18_writeb_retry(struct cx18 *cx, u8 val, void __iomem *addr);
165
166static inline void cx18_writeb(struct cx18 *cx, u8 val, void __iomem *addr)
167{
168 if (cx18_retry_mmio)
169 cx18_writeb_retry(cx, val, addr);
170 else
171 cx18_writeb_noretry(cx, val, addr);
172}
173
174
175static inline u32 cx18_readl_noretry(struct cx18 *cx, const void __iomem *addr)
c641d09c
AW
176{
177 u32 ret = readl(addr);
178 cx18_io_delay(cx);
179 return ret;
180}
181
d267d851
AW
182u32 cx18_readl_retry(struct cx18 *cx, const void __iomem *addr);
183
184static inline u32 cx18_readl(struct cx18 *cx, const void __iomem *addr)
185{
186 if (cx18_retry_mmio)
187 return cx18_readl_retry(cx, addr);
188
189 return cx18_readl_noretry(cx, addr);
190}
191
192
193static inline u16 cx18_readw_noretry(struct cx18 *cx, const void __iomem *addr)
194{
195 u16 ret = readw(addr);
196 cx18_io_delay(cx);
197 return ret;
198}
199
200u16 cx18_readw_retry(struct cx18 *cx, const void __iomem *addr);
201
202static inline u16 cx18_readw(struct cx18 *cx, const void __iomem *addr)
203{
204 if (cx18_retry_mmio)
205 return cx18_readw_retry(cx, addr);
206
207 return cx18_readw_noretry(cx, addr);
208}
209
210
211static inline u8 cx18_readb_noretry(struct cx18 *cx, const void __iomem *addr)
c641d09c
AW
212{
213 u8 ret = readb(addr);
214 cx18_io_delay(cx);
215 return ret;
216}
217
d267d851
AW
218u8 cx18_readb_retry(struct cx18 *cx, const void __iomem *addr);
219
220static inline u8 cx18_readb(struct cx18 *cx, const void __iomem *addr)
221{
222 if (cx18_retry_mmio)
223 return cx18_readb_retry(cx, addr);
224
225 return cx18_readb_noretry(cx, addr);
226}
227
228
229static inline
230u32 cx18_write_sync_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
231{
232 cx18_writel_noretry(cx, val, addr);
233 return cx18_readl_noretry(cx, addr);
234}
235
236static inline
237u32 cx18_write_sync_retry(struct cx18 *cx, u32 val, void __iomem *addr)
238{
239 cx18_writel_retry(cx, val, addr);
240 return cx18_readl_retry(cx, addr);
241}
242
c641d09c
AW
243static inline u32 cx18_write_sync(struct cx18 *cx, u32 val, void __iomem *addr)
244{
d267d851
AW
245 if (cx18_retry_mmio)
246 return cx18_write_sync_retry(cx, val, addr);
247
248 return cx18_write_sync_noretry(cx, val, addr);
c641d09c 249}
b1526421 250
d267d851 251
ee2d64f5 252static inline
b1526421 253void cx18_memcpy_fromio(struct cx18 *cx, void *to,
ee2d64f5
AW
254 const void __iomem *from, unsigned int len)
255{
256 memcpy_fromio(to, from, len);
257}
258
b1526421
AW
259void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count);
260
d267d851 261
c641d09c 262/* Access "register" region of CX23418 memory mapped I/O */
d267d851
AW
263static inline void cx18_write_reg_noretry(struct cx18 *cx, u32 val, u32 reg)
264{
265 cx18_writel_noretry(cx, val, cx->reg_mem + reg);
266}
267
268static inline void cx18_write_reg_retry(struct cx18 *cx, u32 val, u32 reg)
269{
270 cx18_writel_retry(cx, val, cx->reg_mem + reg);
271}
272
c641d09c
AW
273static inline void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg)
274{
d267d851
AW
275 if (cx18_retry_mmio)
276 cx18_write_reg_retry(cx, val, reg);
277 else
278 cx18_write_reg_noretry(cx, val, reg);
279}
280
f056d29e
AW
281static inline void _cx18_write_reg_expect(struct cx18 *cx, u32 val, u32 reg,
282 u32 eval, u32 mask)
283{
284 _cx18_writel_expect(cx, val, cx->reg_mem + reg, eval, mask);
285}
286
287static inline void cx18_write_reg_expect(struct cx18 *cx, u32 val, u32 reg,
288 u32 eval, u32 mask)
289{
290 if (cx18_retry_mmio)
291 _cx18_write_reg_expect(cx, val, reg, eval, mask);
292 else
293 cx18_write_reg_noretry(cx, val, reg);
294}
295
d267d851
AW
296
297static inline u32 cx18_read_reg_noretry(struct cx18 *cx, u32 reg)
298{
299 return cx18_readl_noretry(cx, cx->reg_mem + reg);
300}
301
302static inline u32 cx18_read_reg_retry(struct cx18 *cx, u32 reg)
303{
304 return cx18_readl_retry(cx, cx->reg_mem + reg);
c641d09c
AW
305}
306
307static inline u32 cx18_read_reg(struct cx18 *cx, u32 reg)
308{
d267d851
AW
309 if (cx18_retry_mmio)
310 return cx18_read_reg_retry(cx, reg);
311
312 return cx18_read_reg_noretry(cx, reg);
313}
314
315
316static inline u32 cx18_write_reg_sync_noretry(struct cx18 *cx, u32 val, u32 reg)
317{
318 return cx18_write_sync_noretry(cx, val, cx->reg_mem + reg);
319}
320
321static inline u32 cx18_write_reg_sync_retry(struct cx18 *cx, u32 val, u32 reg)
322{
323 return cx18_write_sync_retry(cx, val, cx->reg_mem + reg);
c641d09c
AW
324}
325
326static inline u32 cx18_write_reg_sync(struct cx18 *cx, u32 val, u32 reg)
327{
d267d851
AW
328 if (cx18_retry_mmio)
329 return cx18_write_reg_sync_retry(cx, val, reg);
330
331 return cx18_write_reg_sync_noretry(cx, val, reg);
c641d09c
AW
332}
333
d267d851 334
c641d09c 335/* Access "encoder memory" region of CX23418 memory mapped I/O */
d267d851
AW
336static inline void cx18_write_enc_noretry(struct cx18 *cx, u32 val, u32 addr)
337{
338 cx18_writel_noretry(cx, val, cx->enc_mem + addr);
339}
340
341static inline void cx18_write_enc_retry(struct cx18 *cx, u32 val, u32 addr)
342{
343 cx18_writel_retry(cx, val, cx->enc_mem + addr);
344}
345
c641d09c
AW
346static inline void cx18_write_enc(struct cx18 *cx, u32 val, u32 addr)
347{
d267d851
AW
348 if (cx18_retry_mmio)
349 cx18_write_enc_retry(cx, val, addr);
350 else
351 cx18_write_enc_noretry(cx, val, addr);
352}
353
354
355static inline u32 cx18_read_enc_noretry(struct cx18 *cx, u32 addr)
356{
357 return cx18_readl_noretry(cx, cx->enc_mem + addr);
358}
359
360static inline u32 cx18_read_enc_retry(struct cx18 *cx, u32 addr)
361{
362 return cx18_readl_retry(cx, cx->enc_mem + addr);
c641d09c
AW
363}
364
365static inline u32 cx18_read_enc(struct cx18 *cx, u32 addr)
366{
d267d851
AW
367 if (cx18_retry_mmio)
368 return cx18_read_enc_retry(cx, addr);
369
370 return cx18_read_enc_noretry(cx, addr);
371}
372
373static inline
374u32 cx18_write_enc_sync_noretry(struct cx18 *cx, u32 val, u32 addr)
375{
376 return cx18_write_sync_noretry(cx, val, cx->enc_mem + addr);
c641d09c
AW
377}
378
d267d851
AW
379static inline
380u32 cx18_write_enc_sync_retry(struct cx18 *cx, u32 val, u32 addr)
c641d09c 381{
d267d851 382 return cx18_write_sync_retry(cx, val, cx->enc_mem + addr);
c641d09c
AW
383}
384
d267d851
AW
385static inline
386u32 cx18_write_enc_sync(struct cx18 *cx, u32 val, u32 addr)
387{
388 if (cx18_retry_mmio)
389 return cx18_write_enc_sync_retry(cx, val, addr);
390
391 return cx18_write_enc_sync_noretry(cx, val, addr);
392}
c641d09c 393
b1526421
AW
394void cx18_sw1_irq_enable(struct cx18 *cx, u32 val);
395void cx18_sw1_irq_disable(struct cx18 *cx, u32 val);
396void cx18_sw2_irq_enable(struct cx18 *cx, u32 val);
397void cx18_sw2_irq_disable(struct cx18 *cx, u32 val);
d20ceecd 398void cx18_sw2_irq_disable_cpu(struct cx18 *cx, u32 val);
b1526421
AW
399void cx18_setup_page(struct cx18 *cx, u32 addr);
400
b1526421 401#endif /* CX18_IO_H */
This page took 0.070807 seconds and 5 git commands to generate.