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"
29 * Readback and retry of MMIO access for reliability:
30 * The concept was suggested by Steve Toth <stoth@linuxtv.org>.
31 * The implmentation is the fault of Andy Walls <awalls@radix.net>.
33 * *write* functions are implied to retry the mmio unless suffixed with _noretry
34 * *read* functions never retry the mmio (it never helps to do so)
37 /* Non byteswapping memory mapped IO */
38 static inline u32
cx18_raw_readl(struct cx18
*cx
, const void __iomem
*addr
)
40 return __raw_readl(addr
);
44 void cx18_raw_writel_noretry(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
46 __raw_writel(val
, addr
);
49 static inline void cx18_raw_writel(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
52 for (i
= 0; i
< CX18_MAX_MMIO_WR_RETRIES
; i
++) {
53 cx18_raw_writel_noretry(cx
, val
, addr
);
54 if (val
== cx18_raw_readl(cx
, addr
))
59 /* Normal memory mapped IO */
60 static inline u32
cx18_readl(struct cx18
*cx
, const void __iomem
*addr
)
66 void cx18_writel_noretry(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
71 static inline void cx18_writel(struct cx18
*cx
, u32 val
, void __iomem
*addr
)
74 for (i
= 0; i
< CX18_MAX_MMIO_WR_RETRIES
; i
++) {
75 cx18_writel_noretry(cx
, val
, addr
);
76 if (val
== cx18_readl(cx
, addr
))
82 void cx18_writel_expect(struct cx18
*cx
, u32 val
, void __iomem
*addr
,
88 for (i
= 0; i
< CX18_MAX_MMIO_WR_RETRIES
; i
++) {
89 cx18_writel_noretry(cx
, val
, addr
);
90 r
= cx18_readl(cx
, addr
);
91 if (r
== 0xffffffff && eval
!= 0xffffffff)
93 if (eval
== (r
& mask
))
98 static inline u16
cx18_readw(struct cx18
*cx
, const void __iomem
*addr
)
104 void cx18_writew_noretry(struct cx18
*cx
, u16 val
, void __iomem
*addr
)
109 static inline void cx18_writew(struct cx18
*cx
, u16 val
, void __iomem
*addr
)
112 for (i
= 0; i
< CX18_MAX_MMIO_WR_RETRIES
; i
++) {
113 cx18_writew_noretry(cx
, val
, addr
);
114 if (val
== cx18_readw(cx
, addr
))
119 static inline u8
cx18_readb(struct cx18
*cx
, const void __iomem
*addr
)
125 void cx18_writeb_noretry(struct cx18
*cx
, u8 val
, void __iomem
*addr
)
130 static inline void cx18_writeb(struct cx18
*cx
, u8 val
, void __iomem
*addr
)
133 for (i
= 0; i
< CX18_MAX_MMIO_WR_RETRIES
; i
++) {
134 cx18_writeb_noretry(cx
, val
, addr
);
135 if (val
== cx18_readb(cx
, addr
))
141 void cx18_memcpy_fromio(struct cx18
*cx
, void *to
,
142 const void __iomem
*from
, unsigned int len
)
144 memcpy_fromio(to
, from
, len
);
147 void cx18_memset_io(struct cx18
*cx
, void __iomem
*addr
, int val
, size_t count
);
150 /* Access "register" region of CX23418 memory mapped I/O */
151 static inline void cx18_write_reg_noretry(struct cx18
*cx
, u32 val
, u32 reg
)
153 cx18_writel_noretry(cx
, val
, cx
->reg_mem
+ reg
);
156 static inline void cx18_write_reg(struct cx18
*cx
, u32 val
, u32 reg
)
158 cx18_writel(cx
, val
, cx
->reg_mem
+ reg
);
161 static inline void cx18_write_reg_expect(struct cx18
*cx
, u32 val
, u32 reg
,
164 cx18_writel_expect(cx
, val
, cx
->reg_mem
+ reg
, eval
, mask
);
167 static inline u32
cx18_read_reg(struct cx18
*cx
, u32 reg
)
169 return cx18_readl(cx
, cx
->reg_mem
+ reg
);
173 /* Access "encoder memory" region of CX23418 memory mapped I/O */
174 static inline void cx18_write_enc(struct cx18
*cx
, u32 val
, u32 addr
)
176 cx18_writel(cx
, val
, cx
->enc_mem
+ addr
);
179 static inline u32
cx18_read_enc(struct cx18
*cx
, u32 addr
)
181 return cx18_readl(cx
, cx
->enc_mem
+ addr
);
184 void cx18_sw1_irq_enable(struct cx18
*cx
, u32 val
);
185 void cx18_sw1_irq_disable(struct cx18
*cx
, u32 val
);
186 void cx18_sw2_irq_enable(struct cx18
*cx
, u32 val
);
187 void cx18_sw2_irq_disable(struct cx18
*cx
, u32 val
);
188 void cx18_sw2_irq_disable_cpu(struct cx18
*cx
, u32 val
);
189 void cx18_setup_page(struct cx18
*cx
, u32 addr
);
191 #endif /* CX18_IO_H */