Path: blob/master/drivers/media/video/cx18/cx18-io.h
17782 views
/*1* cx18 driver PCI memory mapped IO access routines2*3* Copyright (C) 2007 Hans Verkuil <[email protected]>4* Copyright (C) 2008 Andy Walls <[email protected]>5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2 of the License, or9* (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA19* 02111-1307 USA20*/2122#ifndef CX18_IO_H23#define CX18_IO_H2425#include "cx18-driver.h"2627/*28* Readback and retry of MMIO access for reliability:29* The concept was suggested by Steve Toth <[email protected]>.30* The implmentation is the fault of Andy Walls <[email protected]>.31*32* *write* functions are implied to retry the mmio unless suffixed with _noretry33* *read* functions never retry the mmio (it never helps to do so)34*/3536/* Non byteswapping memory mapped IO */37static inline u32 cx18_raw_readl(struct cx18 *cx, const void __iomem *addr)38{39return __raw_readl(addr);40}4142static inline43void cx18_raw_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)44{45__raw_writel(val, addr);46}4748static inline void cx18_raw_writel(struct cx18 *cx, u32 val, void __iomem *addr)49{50int i;51for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {52cx18_raw_writel_noretry(cx, val, addr);53if (val == cx18_raw_readl(cx, addr))54break;55}56}5758/* Normal memory mapped IO */59static inline u32 cx18_readl(struct cx18 *cx, const void __iomem *addr)60{61return readl(addr);62}6364static inline65void cx18_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)66{67writel(val, addr);68}6970static inline void cx18_writel(struct cx18 *cx, u32 val, void __iomem *addr)71{72int i;73for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {74cx18_writel_noretry(cx, val, addr);75if (val == cx18_readl(cx, addr))76break;77}78}7980static inline81void cx18_writel_expect(struct cx18 *cx, u32 val, void __iomem *addr,82u32 eval, u32 mask)83{84int i;85u32 r;86eval &= mask;87for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {88cx18_writel_noretry(cx, val, addr);89r = cx18_readl(cx, addr);90if (r == 0xffffffff && eval != 0xffffffff)91continue;92if (eval == (r & mask))93break;94}95}9697static inline u16 cx18_readw(struct cx18 *cx, const void __iomem *addr)98{99return readw(addr);100}101102static inline103void cx18_writew_noretry(struct cx18 *cx, u16 val, void __iomem *addr)104{105writew(val, addr);106}107108static inline void cx18_writew(struct cx18 *cx, u16 val, void __iomem *addr)109{110int i;111for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {112cx18_writew_noretry(cx, val, addr);113if (val == cx18_readw(cx, addr))114break;115}116}117118static inline u8 cx18_readb(struct cx18 *cx, const void __iomem *addr)119{120return readb(addr);121}122123static inline124void cx18_writeb_noretry(struct cx18 *cx, u8 val, void __iomem *addr)125{126writeb(val, addr);127}128129static inline void cx18_writeb(struct cx18 *cx, u8 val, void __iomem *addr)130{131int i;132for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {133cx18_writeb_noretry(cx, val, addr);134if (val == cx18_readb(cx, addr))135break;136}137}138139static inline140void cx18_memcpy_fromio(struct cx18 *cx, void *to,141const void __iomem *from, unsigned int len)142{143memcpy_fromio(to, from, len);144}145146void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count);147148149/* Access "register" region of CX23418 memory mapped I/O */150static inline void cx18_write_reg_noretry(struct cx18 *cx, u32 val, u32 reg)151{152cx18_writel_noretry(cx, val, cx->reg_mem + reg);153}154155static inline void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg)156{157cx18_writel(cx, val, cx->reg_mem + reg);158}159160static inline void cx18_write_reg_expect(struct cx18 *cx, u32 val, u32 reg,161u32 eval, u32 mask)162{163cx18_writel_expect(cx, val, cx->reg_mem + reg, eval, mask);164}165166static inline u32 cx18_read_reg(struct cx18 *cx, u32 reg)167{168return cx18_readl(cx, cx->reg_mem + reg);169}170171172/* Access "encoder memory" region of CX23418 memory mapped I/O */173static inline void cx18_write_enc(struct cx18 *cx, u32 val, u32 addr)174{175cx18_writel(cx, val, cx->enc_mem + addr);176}177178static inline u32 cx18_read_enc(struct cx18 *cx, u32 addr)179{180return cx18_readl(cx, cx->enc_mem + addr);181}182183void cx18_sw1_irq_enable(struct cx18 *cx, u32 val);184void cx18_sw1_irq_disable(struct cx18 *cx, u32 val);185void cx18_sw2_irq_enable(struct cx18 *cx, u32 val);186void cx18_sw2_irq_disable(struct cx18 *cx, u32 val);187void cx18_sw2_irq_disable_cpu(struct cx18 *cx, u32 val);188void cx18_setup_page(struct cx18 *cx, u32 addr);189190#endif /* CX18_IO_H */191192193