Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 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 | |
Andy Walls | c641d09 | 2008-09-01 00:40:41 -0300 | [diff] [blame^] | 28 | static inline void cx18_io_delay(struct cx18 *cx) |
| 29 | { |
| 30 | if (cx->options.mmio_ndelay) |
| 31 | ndelay(cx->options.mmio_ndelay); |
| 32 | } |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 33 | |
Andy Walls | c641d09 | 2008-09-01 00:40:41 -0300 | [diff] [blame^] | 34 | /* Non byteswapping memory mapped IO */ |
| 35 | static 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 Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 40 | |
Andy Walls | c641d09 | 2008-09-01 00:40:41 -0300 | [diff] [blame^] | 41 | static 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 Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 47 | |
Andy Walls | c641d09 | 2008-09-01 00:40:41 -0300 | [diff] [blame^] | 48 | static 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 Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 54 | |
Andy Walls | c641d09 | 2008-09-01 00:40:41 -0300 | [diff] [blame^] | 55 | /* Normal memory mapped IO */ |
| 56 | static inline void cx18_writel(struct cx18 *cx, u32 val, void __iomem *addr) |
| 57 | { |
| 58 | writel(val, addr); |
| 59 | cx18_io_delay(cx); |
| 60 | } |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 61 | |
Andy Walls | c641d09 | 2008-09-01 00:40:41 -0300 | [diff] [blame^] | 62 | static inline void cx18_writew(struct cx18 *cx, u16 val, void __iomem *addr) |
| 63 | { |
| 64 | writew(val, addr); |
| 65 | cx18_io_delay(cx); |
| 66 | } |
| 67 | |
| 68 | static inline void cx18_writeb(struct cx18 *cx, u8 val, void __iomem *addr) |
| 69 | { |
| 70 | writeb(val, addr); |
| 71 | cx18_io_delay(cx); |
| 72 | } |
| 73 | |
| 74 | static 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 | |
| 81 | static 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 | |
| 88 | static 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 Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 93 | |
| 94 | void cx18_memcpy_fromio(struct cx18 *cx, void *to, |
| 95 | const void __iomem *from, unsigned int len); |
| 96 | void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count); |
| 97 | |
Andy Walls | c641d09 | 2008-09-01 00:40:41 -0300 | [diff] [blame^] | 98 | /* Access "register" region of CX23418 memory mapped I/O */ |
| 99 | static inline void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg) |
| 100 | { |
| 101 | cx18_writel(cx, val, cx->reg_mem + reg); |
| 102 | } |
| 103 | |
| 104 | static inline u32 cx18_read_reg(struct cx18 *cx, u32 reg) |
| 105 | { |
| 106 | return cx18_readl(cx, cx->reg_mem + reg); |
| 107 | } |
| 108 | |
| 109 | static 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 */ |
| 115 | static inline void cx18_write_enc(struct cx18 *cx, u32 val, u32 addr) |
| 116 | { |
| 117 | cx18_writel(cx, val, cx->enc_mem + addr); |
| 118 | } |
| 119 | |
| 120 | static inline u32 cx18_read_enc(struct cx18 *cx, u32 addr) |
| 121 | { |
| 122 | return cx18_readl(cx, cx->enc_mem + addr); |
| 123 | } |
| 124 | |
| 125 | static 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 Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 131 | void cx18_sw1_irq_enable(struct cx18 *cx, u32 val); |
| 132 | void cx18_sw1_irq_disable(struct cx18 *cx, u32 val); |
| 133 | void cx18_sw2_irq_enable(struct cx18 *cx, u32 val); |
| 134 | void cx18_sw2_irq_disable(struct cx18 *cx, u32 val); |
| 135 | void cx18_setup_page(struct cx18 *cx, u32 addr); |
| 136 | |
| 137 | /* Tries to recover from the CX23418 responding improperly on the PCI bus */ |
| 138 | int cx18_pci_try_recover(struct cx18 *cx); |
| 139 | |
| 140 | #endif /* CX18_IO_H */ |