cx18-io.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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@md.metrocast.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. #ifndef CX18_IO_H
  23. #define CX18_IO_H
  24. #include "cx18-driver.h"
  25. /*
  26. * Readback and retry of MMIO access for reliability:
  27. * The concept was suggested by Steve Toth <stoth@linuxtv.org>.
  28. * The implmentation is the fault of Andy Walls <awalls@md.metrocast.net>.
  29. *
  30. * *write* functions are implied to retry the mmio unless suffixed with _noretry
  31. * *read* functions never retry the mmio (it never helps to do so)
  32. */
  33. /* Non byteswapping memory mapped IO */
  34. static inline u32 cx18_raw_readl(struct cx18 *cx, const void __iomem *addr)
  35. {
  36. return __raw_readl(addr);
  37. }
  38. static inline
  39. void cx18_raw_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
  40. {
  41. __raw_writel(val, addr);
  42. }
  43. static inline void cx18_raw_writel(struct cx18 *cx, u32 val, void __iomem *addr)
  44. {
  45. int i;
  46. for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {
  47. cx18_raw_writel_noretry(cx, val, addr);
  48. if (val == cx18_raw_readl(cx, addr))
  49. break;
  50. }
  51. }
  52. /* Normal memory mapped IO */
  53. static inline u32 cx18_readl(struct cx18 *cx, const void __iomem *addr)
  54. {
  55. return readl(addr);
  56. }
  57. static inline
  58. void cx18_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
  59. {
  60. writel(val, addr);
  61. }
  62. static inline void cx18_writel(struct cx18 *cx, u32 val, void __iomem *addr)
  63. {
  64. int i;
  65. for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {
  66. cx18_writel_noretry(cx, val, addr);
  67. if (val == cx18_readl(cx, addr))
  68. break;
  69. }
  70. }
  71. static inline
  72. void cx18_writel_expect(struct cx18 *cx, u32 val, void __iomem *addr,
  73. u32 eval, u32 mask)
  74. {
  75. int i;
  76. u32 r;
  77. eval &= mask;
  78. for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {
  79. cx18_writel_noretry(cx, val, addr);
  80. r = cx18_readl(cx, addr);
  81. if (r == 0xffffffff && eval != 0xffffffff)
  82. continue;
  83. if (eval == (r & mask))
  84. break;
  85. }
  86. }
  87. static inline u16 cx18_readw(struct cx18 *cx, const void __iomem *addr)
  88. {
  89. return readw(addr);
  90. }
  91. static inline
  92. void cx18_writew_noretry(struct cx18 *cx, u16 val, void __iomem *addr)
  93. {
  94. writew(val, addr);
  95. }
  96. static inline void cx18_writew(struct cx18 *cx, u16 val, void __iomem *addr)
  97. {
  98. int i;
  99. for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {
  100. cx18_writew_noretry(cx, val, addr);
  101. if (val == cx18_readw(cx, addr))
  102. break;
  103. }
  104. }
  105. static inline u8 cx18_readb(struct cx18 *cx, const void __iomem *addr)
  106. {
  107. return readb(addr);
  108. }
  109. static inline
  110. void cx18_writeb_noretry(struct cx18 *cx, u8 val, void __iomem *addr)
  111. {
  112. writeb(val, addr);
  113. }
  114. static inline void cx18_writeb(struct cx18 *cx, u8 val, void __iomem *addr)
  115. {
  116. int i;
  117. for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {
  118. cx18_writeb_noretry(cx, val, addr);
  119. if (val == cx18_readb(cx, addr))
  120. break;
  121. }
  122. }
  123. static inline
  124. void cx18_memcpy_fromio(struct cx18 *cx, void *to,
  125. const void __iomem *from, unsigned int len)
  126. {
  127. memcpy_fromio(to, from, len);
  128. }
  129. void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count);
  130. /* Access "register" region of CX23418 memory mapped I/O */
  131. static inline void cx18_write_reg_noretry(struct cx18 *cx, u32 val, u32 reg)
  132. {
  133. cx18_writel_noretry(cx, val, cx->reg_mem + reg);
  134. }
  135. static inline void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg)
  136. {
  137. cx18_writel(cx, val, cx->reg_mem + reg);
  138. }
  139. static inline void cx18_write_reg_expect(struct cx18 *cx, u32 val, u32 reg,
  140. u32 eval, u32 mask)
  141. {
  142. cx18_writel_expect(cx, val, cx->reg_mem + reg, eval, mask);
  143. }
  144. static inline u32 cx18_read_reg(struct cx18 *cx, u32 reg)
  145. {
  146. return cx18_readl(cx, cx->reg_mem + reg);
  147. }
  148. /* Access "encoder memory" region of CX23418 memory mapped I/O */
  149. static inline void cx18_write_enc(struct cx18 *cx, u32 val, u32 addr)
  150. {
  151. cx18_writel(cx, val, cx->enc_mem + addr);
  152. }
  153. static inline u32 cx18_read_enc(struct cx18 *cx, u32 addr)
  154. {
  155. return cx18_readl(cx, cx->enc_mem + addr);
  156. }
  157. void cx18_sw1_irq_enable(struct cx18 *cx, u32 val);
  158. void cx18_sw1_irq_disable(struct cx18 *cx, u32 val);
  159. void cx18_sw2_irq_enable(struct cx18 *cx, u32 val);
  160. void cx18_sw2_irq_disable(struct cx18 *cx, u32 val);
  161. void cx18_sw2_irq_disable_cpu(struct cx18 *cx, u32 val);
  162. void cx18_setup_page(struct cx18 *cx, u32 addr);
  163. #endif /* CX18_IO_H */