]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/media/video/cx18/cx18-io.h
2 * cx18 driver PCI memory mapped IO access routines
4 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
5 * Copyright (C) 2008 Andy Walls <awalls@radix.net>
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.
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.
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
26 #include "cx18-driver.h"
28 static inline void cx18_io_delay(struct cx18
*cx
)
30 if (cx
->options
.mmio_ndelay
)
31 ndelay(cx
->options
.mmio_ndelay
);
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>.
40 /* Statistics gathering */
42 void cx18_log_write_retries(struct cx18
*cx
, int i
, const void __iomem
*addr
)
44 if (i
> CX18_MAX_MMIO_RETRIES
)
45 i
= CX18_MAX_MMIO_RETRIES
;
46 atomic_inc(&cx
->mmio_stats
.retried_write
[i
]);
51 void cx18_log_read_retries(struct cx18
*cx
, int i
, const void __iomem
*addr
)
53 if (i
> CX18_MAX_MMIO_RETRIES
)
54 i
= CX18_MAX_MMIO_RETRIES
;
55 atomic_inc(&cx
->mmio_stats
.retried_read
[i
]);
59 void cx18_log_statistics(struct cx18
*cx
);
61 /* Non byteswapping memory mapped IO */
63 void cx18_raw_writel_noretry(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
65 __raw_writel(val
, addr
);
69 void cx18_raw_writel_retry(struct cx18
*cx
, u32 val
, void __iomem
*addr
);
71 static inline void cx18_raw_writel(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
74 cx18_raw_writel_retry(cx
, val
, addr
);
76 cx18_raw_writel_noretry(cx
, val
, addr
);
81 u32
cx18_raw_readl_noretry(struct cx18
*cx
, const void __iomem
*addr
)
83 u32 ret
= __raw_readl(addr
);
88 u32
cx18_raw_readl_retry(struct cx18
*cx
, const void __iomem
*addr
);
90 static inline u32
cx18_raw_readl(struct cx18
*cx
, const void __iomem
*addr
)
93 return cx18_raw_readl_retry(cx
, addr
);
95 return cx18_raw_readl_noretry(cx
, addr
);
100 u16
cx18_raw_readw_noretry(struct cx18
*cx
, const void __iomem
*addr
)
102 u16 ret
= __raw_readw(addr
);
107 u16
cx18_raw_readw_retry(struct cx18
*cx
, const void __iomem
*addr
);
109 static inline u16
cx18_raw_readw(struct cx18
*cx
, const void __iomem
*addr
)
112 return cx18_raw_readw_retry(cx
, addr
);
114 return cx18_raw_readw_noretry(cx
, addr
);
118 /* Normal memory mapped IO */
120 void cx18_writel_noretry(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
126 void cx18_writel_retry(struct cx18
*cx
, u32 val
, void __iomem
*addr
);
128 static inline void cx18_writel(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
131 cx18_writel_retry(cx
, val
, addr
);
133 cx18_writel_noretry(cx
, val
, addr
);
136 void _cx18_writel_expect(struct cx18
*cx
, u32 val
, void __iomem
*addr
,
140 void cx18_writew_noretry(struct cx18
*cx
, u16 val
, void __iomem
*addr
)
146 void cx18_writew_retry(struct cx18
*cx
, u16 val
, void __iomem
*addr
);
148 static inline void cx18_writew(struct cx18
*cx
, u16 val
, void __iomem
*addr
)
151 cx18_writew_retry(cx
, val
, addr
);
153 cx18_writew_noretry(cx
, val
, addr
);
158 void cx18_writeb_noretry(struct cx18
*cx
, u8 val
, void __iomem
*addr
)
164 void cx18_writeb_retry(struct cx18
*cx
, u8 val
, void __iomem
*addr
);
166 static inline void cx18_writeb(struct cx18
*cx
, u8 val
, void __iomem
*addr
)
169 cx18_writeb_retry(cx
, val
, addr
);
171 cx18_writeb_noretry(cx
, val
, addr
);
175 static inline u32
cx18_readl_noretry(struct cx18
*cx
, const void __iomem
*addr
)
177 u32 ret
= readl(addr
);
182 u32
cx18_readl_retry(struct cx18
*cx
, const void __iomem
*addr
);
184 static inline u32
cx18_readl(struct cx18
*cx
, const void __iomem
*addr
)
187 return cx18_readl_retry(cx
, addr
);
189 return cx18_readl_noretry(cx
, addr
);
193 static inline u16
cx18_readw_noretry(struct cx18
*cx
, const void __iomem
*addr
)
195 u16 ret
= readw(addr
);
200 u16
cx18_readw_retry(struct cx18
*cx
, const void __iomem
*addr
);
202 static inline u16
cx18_readw(struct cx18
*cx
, const void __iomem
*addr
)
205 return cx18_readw_retry(cx
, addr
);
207 return cx18_readw_noretry(cx
, addr
);
211 static inline u8
cx18_readb_noretry(struct cx18
*cx
, const void __iomem
*addr
)
213 u8 ret
= readb(addr
);
218 u8
cx18_readb_retry(struct cx18
*cx
, const void __iomem
*addr
);
220 static inline u8
cx18_readb(struct cx18
*cx
, const void __iomem
*addr
)
223 return cx18_readb_retry(cx
, addr
);
225 return cx18_readb_noretry(cx
, addr
);
230 u32
cx18_write_sync_noretry(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
232 cx18_writel_noretry(cx
, val
, addr
);
233 return cx18_readl_noretry(cx
, addr
);
237 u32
cx18_write_sync_retry(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
239 cx18_writel_retry(cx
, val
, addr
);
240 return cx18_readl_retry(cx
, addr
);
243 static inline u32
cx18_write_sync(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
246 return cx18_write_sync_retry(cx
, val
, addr
);
248 return cx18_write_sync_noretry(cx
, val
, addr
);
252 void cx18_memcpy_fromio(struct cx18
*cx
, void *to
,
253 const void __iomem
*from
, unsigned int len
);
254 void cx18_memset_io(struct cx18
*cx
, void __iomem
*addr
, int val
, size_t count
);
257 /* Access "register" region of CX23418 memory mapped I/O */
258 static inline void cx18_write_reg_noretry(struct cx18
*cx
, u32 val
, u32 reg
)
260 cx18_writel_noretry(cx
, val
, cx
->reg_mem
+ reg
);
263 static inline void cx18_write_reg_retry(struct cx18
*cx
, u32 val
, u32 reg
)
265 cx18_writel_retry(cx
, val
, cx
->reg_mem
+ reg
);
268 static inline void cx18_write_reg(struct cx18
*cx
, u32 val
, u32 reg
)
271 cx18_write_reg_retry(cx
, val
, reg
);
273 cx18_write_reg_noretry(cx
, val
, reg
);
276 static inline void _cx18_write_reg_expect(struct cx18
*cx
, u32 val
, u32 reg
,
279 _cx18_writel_expect(cx
, val
, cx
->reg_mem
+ reg
, eval
, mask
);
282 static inline void cx18_write_reg_expect(struct cx18
*cx
, u32 val
, u32 reg
,
286 _cx18_write_reg_expect(cx
, val
, reg
, eval
, mask
);
288 cx18_write_reg_noretry(cx
, val
, reg
);
292 static inline u32
cx18_read_reg_noretry(struct cx18
*cx
, u32 reg
)
294 return cx18_readl_noretry(cx
, cx
->reg_mem
+ reg
);
297 static inline u32
cx18_read_reg_retry(struct cx18
*cx
, u32 reg
)
299 return cx18_readl_retry(cx
, cx
->reg_mem
+ reg
);
302 static inline u32
cx18_read_reg(struct cx18
*cx
, u32 reg
)
305 return cx18_read_reg_retry(cx
, reg
);
307 return cx18_read_reg_noretry(cx
, reg
);
311 static inline u32
cx18_write_reg_sync_noretry(struct cx18
*cx
, u32 val
, u32 reg
)
313 return cx18_write_sync_noretry(cx
, val
, cx
->reg_mem
+ reg
);
316 static inline u32
cx18_write_reg_sync_retry(struct cx18
*cx
, u32 val
, u32 reg
)
318 return cx18_write_sync_retry(cx
, val
, cx
->reg_mem
+ reg
);
321 static inline u32
cx18_write_reg_sync(struct cx18
*cx
, u32 val
, u32 reg
)
324 return cx18_write_reg_sync_retry(cx
, val
, reg
);
326 return cx18_write_reg_sync_noretry(cx
, val
, reg
);
330 /* Access "encoder memory" region of CX23418 memory mapped I/O */
331 static inline void cx18_write_enc_noretry(struct cx18
*cx
, u32 val
, u32 addr
)
333 cx18_writel_noretry(cx
, val
, cx
->enc_mem
+ addr
);
336 static inline void cx18_write_enc_retry(struct cx18
*cx
, u32 val
, u32 addr
)
338 cx18_writel_retry(cx
, val
, cx
->enc_mem
+ addr
);
341 static inline void cx18_write_enc(struct cx18
*cx
, u32 val
, u32 addr
)
344 cx18_write_enc_retry(cx
, val
, addr
);
346 cx18_write_enc_noretry(cx
, val
, addr
);
350 static inline u32
cx18_read_enc_noretry(struct cx18
*cx
, u32 addr
)
352 return cx18_readl_noretry(cx
, cx
->enc_mem
+ addr
);
355 static inline u32
cx18_read_enc_retry(struct cx18
*cx
, u32 addr
)
357 return cx18_readl_retry(cx
, cx
->enc_mem
+ addr
);
360 static inline u32
cx18_read_enc(struct cx18
*cx
, u32 addr
)
363 return cx18_read_enc_retry(cx
, addr
);
365 return cx18_read_enc_noretry(cx
, addr
);
369 u32
cx18_write_enc_sync_noretry(struct cx18
*cx
, u32 val
, u32 addr
)
371 return cx18_write_sync_noretry(cx
, val
, cx
->enc_mem
+ addr
);
375 u32
cx18_write_enc_sync_retry(struct cx18
*cx
, u32 val
, u32 addr
)
377 return cx18_write_sync_retry(cx
, val
, cx
->enc_mem
+ addr
);
381 u32
cx18_write_enc_sync(struct cx18
*cx
, u32 val
, u32 addr
)
384 return cx18_write_enc_sync_retry(cx
, val
, addr
);
386 return cx18_write_enc_sync_noretry(cx
, val
, addr
);
389 void cx18_sw1_irq_enable(struct cx18
*cx
, u32 val
);
390 void cx18_sw1_irq_disable(struct cx18
*cx
, u32 val
);
391 void cx18_sw2_irq_enable(struct cx18
*cx
, u32 val
);
392 void cx18_sw2_irq_disable(struct cx18
*cx
, u32 val
);
393 void cx18_setup_page(struct cx18
*cx
, u32 addr
);
395 #endif /* CX18_IO_H */