cx18-io.h 4.6 KB

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