blob: 7ab7be2531cacbe60f1aca4ab304566468f90fa0 [file] [log] [blame]
Andy Wallsb1526422008-08-30 16:03:44 -03001/*
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
Andy Wallsc641d092008-09-01 00:40:41 -030028static inline void cx18_io_delay(struct cx18 *cx)
29{
30 if (cx->options.mmio_ndelay)
31 ndelay(cx->options.mmio_ndelay);
32}
Andy Wallsb1526422008-08-30 16:03:44 -030033
Andy Wallsc641d092008-09-01 00:40:41 -030034/* Non byteswapping memory mapped IO */
35static inline void cx18_raw_writel(struct cx18 *cx, u32 val, void __iomem *addr)
36{
37 __raw_writel(val, addr);
38 cx18_io_delay(cx);
39}
Andy Wallsb1526422008-08-30 16:03:44 -030040
Andy Wallsc641d092008-09-01 00:40:41 -030041static inline u32 cx18_raw_readl(struct cx18 *cx, const void __iomem *addr)
42{
43 u32 ret = __raw_readl(addr);
44 cx18_io_delay(cx);
45 return ret;
46}
Andy Wallsb1526422008-08-30 16:03:44 -030047
Andy Wallsc641d092008-09-01 00:40:41 -030048static inline u16 cx18_raw_readw(struct cx18 *cx, const void __iomem *addr)
49{
50 u16 ret = __raw_readw(addr);
51 cx18_io_delay(cx);
52 return ret;
53}
Andy Wallsb1526422008-08-30 16:03:44 -030054
Andy Wallsc641d092008-09-01 00:40:41 -030055/* Normal memory mapped IO */
56static inline void cx18_writel(struct cx18 *cx, u32 val, void __iomem *addr)
57{
58 writel(val, addr);
59 cx18_io_delay(cx);
60}
Andy Wallsb1526422008-08-30 16:03:44 -030061
Andy Wallsc641d092008-09-01 00:40:41 -030062static inline void cx18_writew(struct cx18 *cx, u16 val, void __iomem *addr)
63{
64 writew(val, addr);
65 cx18_io_delay(cx);
66}
67
68static inline void cx18_writeb(struct cx18 *cx, u8 val, void __iomem *addr)
69{
70 writeb(val, addr);
71 cx18_io_delay(cx);
72}
73
74static inline u32 cx18_readl(struct cx18 *cx, const void __iomem *addr)
75{
76 u32 ret = readl(addr);
77 cx18_io_delay(cx);
78 return ret;
79}
80
81static inline u8 cx18_readb(struct cx18 *cx, const void __iomem *addr)
82{
83 u8 ret = readb(addr);
84 cx18_io_delay(cx);
85 return ret;
86}
87
88static inline u32 cx18_write_sync(struct cx18 *cx, u32 val, void __iomem *addr)
89{
90 cx18_writel(cx, val, addr);
91 return cx18_readl(cx, addr);
92}
Andy Wallsb1526422008-08-30 16:03:44 -030093
94void cx18_memcpy_fromio(struct cx18 *cx, void *to,
95 const void __iomem *from, unsigned int len);
96void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count);
97
Andy Wallsc641d092008-09-01 00:40:41 -030098/* Access "register" region of CX23418 memory mapped I/O */
99static inline void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg)
100{
101 cx18_writel(cx, val, cx->reg_mem + reg);
102}
103
104static inline u32 cx18_read_reg(struct cx18 *cx, u32 reg)
105{
106 return cx18_readl(cx, cx->reg_mem + reg);
107}
108
109static inline u32 cx18_write_reg_sync(struct cx18 *cx, u32 val, u32 reg)
110{
111 return cx18_write_sync(cx, val, cx->reg_mem + reg);
112}
113
114/* Access "encoder memory" region of CX23418 memory mapped I/O */
115static inline void cx18_write_enc(struct cx18 *cx, u32 val, u32 addr)
116{
117 cx18_writel(cx, val, cx->enc_mem + addr);
118}
119
120static inline u32 cx18_read_enc(struct cx18 *cx, u32 addr)
121{
122 return cx18_readl(cx, cx->enc_mem + addr);
123}
124
125static inline u32 cx18_write_enc_sync(struct cx18 *cx, u32 val, u32 addr)
126{
127 return cx18_write_sync(cx, val, cx->enc_mem + addr);
128}
129
130
Andy Wallsb1526422008-08-30 16:03:44 -0300131void cx18_sw1_irq_enable(struct cx18 *cx, u32 val);
132void cx18_sw1_irq_disable(struct cx18 *cx, u32 val);
133void cx18_sw2_irq_enable(struct cx18 *cx, u32 val);
134void cx18_sw2_irq_disable(struct cx18 *cx, u32 val);
135void cx18_setup_page(struct cx18 *cx, u32 addr);
136
137/* Tries to recover from the CX23418 responding improperly on the PCI bus */
138int cx18_pci_try_recover(struct cx18 *cx);
139
140#endif /* CX18_IO_H */