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@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. #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@radix.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. /* Statistics gathering */
  34. void cx18_log_statistics(struct cx18 *cx);
  35. /* Non byteswapping memory mapped IO */
  36. static inline u32 cx18_raw_readl(struct cx18 *cx, const void __iomem *addr)
  37. {
  38. return __raw_readl(addr);
  39. }
  40. static inline
  41. void cx18_raw_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
  42. {
  43. __raw_writel(val, addr);
  44. }
  45. static inline void cx18_raw_writel(struct cx18 *cx, u32 val, void __iomem *addr)
  46. {
  47. int i;
  48. for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {
  49. cx18_raw_writel_noretry(cx, val, addr);
  50. if (val == cx18_raw_readl(cx, addr))
  51. break;
  52. }
  53. }
  54. /* Normal memory mapped IO */
  55. static inline u32 cx18_readl(struct cx18 *cx, const void __iomem *addr)
  56. {
  57. return readl(addr);
  58. }
  59. static inline
  60. void cx18_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
  61. {
  62. writel(val, addr);
  63. }
  64. static inline void cx18_writel(struct cx18 *cx, u32 val, void __iomem *addr)
  65. {
  66. int i;
  67. for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {
  68. cx18_writel_noretry(cx, val, addr);
  69. if (val == cx18_readl(cx, addr))
  70. break;
  71. }
  72. }
  73. static inline
  74. void cx18_writel_expect(struct cx18 *cx, u32 val, void __iomem *addr,
  75. u32 eval, u32 mask)
  76. {
  77. int i;
  78. eval &= mask;
  79. for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {
  80. cx18_writel_noretry(cx, val, addr);
  81. if (eval == (cx18_readl(cx, addr) & mask))
  82. break;
  83. }
  84. }
  85. static inline u16 cx18_readw(struct cx18 *cx, const void __iomem *addr)
  86. {
  87. return readw(addr);
  88. }
  89. static inline
  90. void cx18_writew_noretry(struct cx18 *cx, u16 val, void __iomem *addr)
  91. {
  92. writew(val, addr);
  93. }
  94. static inline void cx18_writew(struct cx18 *cx, u16 val, void __iomem *addr)
  95. {
  96. int i;
  97. for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {
  98. cx18_writew_noretry(cx, val, addr);
  99. if (val == cx18_readw(cx, addr))
  100. break;
  101. }
  102. }
  103. static inline u8 cx18_readb(struct cx18 *cx, const void __iomem *addr)
  104. {
  105. return readb(addr);
  106. }
  107. static inline
  108. void cx18_writeb_noretry(struct cx18 *cx, u8 val, void __iomem *addr)
  109. {
  110. writeb(val, addr);
  111. }
  112. static inline void cx18_writeb(struct cx18 *cx, u8 val, void __iomem *addr)
  113. {
  114. int i;
  115. for (i = 0; i < CX18_MAX_MMIO_WR_RETRIES; i++) {
  116. cx18_writeb_noretry(cx, val, addr);
  117. if (val == cx18_readb(cx, addr))
  118. break;
  119. }
  120. }
  121. static inline
  122. void cx18_memcpy_fromio(struct cx18 *cx, void *to,
  123. const void __iomem *from, unsigned int len)
  124. {
  125. memcpy_fromio(to, from, len);
  126. }
  127. void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count);
  128. /* Access "register" region of CX23418 memory mapped I/O */
  129. static inline void cx18_write_reg_noretry(struct cx18 *cx, u32 val, u32 reg)
  130. {
  131. cx18_writel_noretry(cx, val, cx->reg_mem + reg);
  132. }
  133. static inline void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg)
  134. {
  135. cx18_writel(cx, val, cx->reg_mem + reg);
  136. }
  137. static inline void cx18_write_reg_expect(struct cx18 *cx, u32 val, u32 reg,
  138. u32 eval, u32 mask)
  139. {
  140. cx18_writel_expect(cx, val, cx->reg_mem + reg, eval, mask);
  141. }
  142. static inline u32 cx18_read_reg(struct cx18 *cx, u32 reg)
  143. {
  144. return cx18_readl(cx, cx->reg_mem + reg);
  145. }
  146. /* Access "encoder memory" region of CX23418 memory mapped I/O */
  147. static inline void cx18_write_enc(struct cx18 *cx, u32 val, u32 addr)
  148. {
  149. cx18_writel(cx, val, cx->enc_mem + addr);
  150. }
  151. static inline u32 cx18_read_enc(struct cx18 *cx, u32 addr)
  152. {
  153. return cx18_readl(cx, cx->enc_mem + addr);
  154. }
  155. void cx18_sw1_irq_enable(struct cx18 *cx, u32 val);
  156. void cx18_sw1_irq_disable(struct cx18 *cx, u32 val);
  157. void cx18_sw2_irq_enable(struct cx18 *cx, u32 val);
  158. void cx18_sw2_irq_disable(struct cx18 *cx, u32 val);
  159. void cx18_sw2_irq_disable_cpu(struct cx18 *cx, u32 val);
  160. void cx18_setup_page(struct cx18 *cx, u32 addr);
  161. #endif /* CX18_IO_H */