]>
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 *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 *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
);
138 void cx18_writew_noretry(struct cx18
*cx
, u16 val
, void __iomem
*addr
)
144 void cx18_writew_retry(struct cx18
*cx
, u16 val
, void __iomem
*addr
);
146 static inline void cx18_writew(struct cx18
*cx
, u16 val
, void __iomem
*addr
)
149 cx18_writew_retry(cx
, val
, addr
);
151 cx18_writew_noretry(cx
, val
, addr
);
156 void cx18_writeb_noretry(struct cx18
*cx
, u8 val
, void __iomem
*addr
)
162 void cx18_writeb_retry(struct cx18
*cx
, u8 val
, void __iomem
*addr
);
164 static inline void cx18_writeb(struct cx18
*cx
, u8 val
, void __iomem
*addr
)
167 cx18_writeb_retry(cx
, val
, addr
);
169 cx18_writeb_noretry(cx
, val
, addr
);
173 static inline u32
cx18_readl_noretry(struct cx18
*cx
, const void __iomem
*addr
)
175 u32 ret
= readl(addr
);
180 u32
cx18_readl_retry(struct cx18
*cx
, const void __iomem
*addr
);
182 static inline u32
cx18_readl(struct cx18
*cx
, const void __iomem
*addr
)
185 return cx18_readl_retry(cx
, addr
);
187 return cx18_readl_noretry(cx
, addr
);
191 static inline u16
cx18_readw_noretry(struct cx18
*cx
, const void __iomem
*addr
)
193 u16 ret
= readw(addr
);
198 u16
cx18_readw_retry(struct cx18
*cx
, const void __iomem
*addr
);
200 static inline u16
cx18_readw(struct cx18
*cx
, const void __iomem
*addr
)
203 return cx18_readw_retry(cx
, addr
);
205 return cx18_readw_noretry(cx
, addr
);
209 static inline u8
cx18_readb_noretry(struct cx18
*cx
, const void __iomem
*addr
)
211 u8 ret
= readb(addr
);
216 u8
cx18_readb_retry(struct cx18
*cx
, const void __iomem
*addr
);
218 static inline u8
cx18_readb(struct cx18
*cx
, const void __iomem
*addr
)
221 return cx18_readb_retry(cx
, addr
);
223 return cx18_readb_noretry(cx
, addr
);
228 u32
cx18_write_sync_noretry(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
230 cx18_writel_noretry(cx
, val
, addr
);
231 return cx18_readl_noretry(cx
, addr
);
235 u32
cx18_write_sync_retry(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
237 cx18_writel_retry(cx
, val
, addr
);
238 return cx18_readl_retry(cx
, addr
);
241 static inline u32
cx18_write_sync(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
244 return cx18_write_sync_retry(cx
, val
, addr
);
246 return cx18_write_sync_noretry(cx
, val
, addr
);
250 void cx18_memcpy_fromio(struct cx18
*cx
, void *to
,
251 const void __iomem
*from
, unsigned int len
);
252 void cx18_memset_io(struct cx18
*cx
, void __iomem
*addr
, int val
, size_t count
);
255 /* Access "register" region of CX23418 memory mapped I/O */
256 static inline void cx18_write_reg_noretry(struct cx18
*cx
, u32 val
, u32 reg
)
258 cx18_writel_noretry(cx
, val
, cx
->reg_mem
+ reg
);
261 static inline void cx18_write_reg_retry(struct cx18
*cx
, u32 val
, u32 reg
)
263 cx18_writel_retry(cx
, val
, cx
->reg_mem
+ reg
);
266 static inline void cx18_write_reg(struct cx18
*cx
, u32 val
, u32 reg
)
269 cx18_write_reg_retry(cx
, val
, reg
);
271 cx18_write_reg_noretry(cx
, val
, reg
);
275 static inline u32
cx18_read_reg_noretry(struct cx18
*cx
, u32 reg
)
277 return cx18_readl_noretry(cx
, cx
->reg_mem
+ reg
);
280 static inline u32
cx18_read_reg_retry(struct cx18
*cx
, u32 reg
)
282 return cx18_readl_retry(cx
, cx
->reg_mem
+ reg
);
285 static inline u32
cx18_read_reg(struct cx18
*cx
, u32 reg
)
288 return cx18_read_reg_retry(cx
, reg
);
290 return cx18_read_reg_noretry(cx
, reg
);
294 static inline u32
cx18_write_reg_sync_noretry(struct cx18
*cx
, u32 val
, u32 reg
)
296 return cx18_write_sync_noretry(cx
, val
, cx
->reg_mem
+ reg
);
299 static inline u32
cx18_write_reg_sync_retry(struct cx18
*cx
, u32 val
, u32 reg
)
301 return cx18_write_sync_retry(cx
, val
, cx
->reg_mem
+ reg
);
304 static inline u32
cx18_write_reg_sync(struct cx18
*cx
, u32 val
, u32 reg
)
307 return cx18_write_reg_sync_retry(cx
, val
, reg
);
309 return cx18_write_reg_sync_noretry(cx
, val
, reg
);
313 /* Access "encoder memory" region of CX23418 memory mapped I/O */
314 static inline void cx18_write_enc_noretry(struct cx18
*cx
, u32 val
, u32 addr
)
316 cx18_writel_noretry(cx
, val
, cx
->enc_mem
+ addr
);
319 static inline void cx18_write_enc_retry(struct cx18
*cx
, u32 val
, u32 addr
)
321 cx18_writel_retry(cx
, val
, cx
->enc_mem
+ addr
);
324 static inline void cx18_write_enc(struct cx18
*cx
, u32 val
, u32 addr
)
327 cx18_write_enc_retry(cx
, val
, addr
);
329 cx18_write_enc_noretry(cx
, val
, addr
);
333 static inline u32
cx18_read_enc_noretry(struct cx18
*cx
, u32 addr
)
335 return cx18_readl_noretry(cx
, cx
->enc_mem
+ addr
);
338 static inline u32
cx18_read_enc_retry(struct cx18
*cx
, u32 addr
)
340 return cx18_readl_retry(cx
, cx
->enc_mem
+ addr
);
343 static inline u32
cx18_read_enc(struct cx18
*cx
, u32 addr
)
346 return cx18_read_enc_retry(cx
, addr
);
348 return cx18_read_enc_noretry(cx
, addr
);
352 u32
cx18_write_enc_sync_noretry(struct cx18
*cx
, u32 val
, u32 addr
)
354 return cx18_write_sync_noretry(cx
, val
, cx
->enc_mem
+ addr
);
358 u32
cx18_write_enc_sync_retry(struct cx18
*cx
, u32 val
, u32 addr
)
360 return cx18_write_sync_retry(cx
, val
, cx
->enc_mem
+ addr
);
364 u32
cx18_write_enc_sync(struct cx18
*cx
, u32 val
, u32 addr
)
367 return cx18_write_enc_sync_retry(cx
, val
, addr
);
369 return cx18_write_enc_sync_noretry(cx
, val
, addr
);
372 void cx18_sw1_irq_enable(struct cx18
*cx
, u32 val
);
373 void cx18_sw1_irq_disable(struct cx18
*cx
, u32 val
);
374 void cx18_sw2_irq_enable(struct cx18
*cx
, u32 val
);
375 void cx18_sw2_irq_disable(struct cx18
*cx
, u32 val
);
376 void cx18_setup_page(struct cx18
*cx
, u32 addr
);
378 #endif /* CX18_IO_H */