cx18-io.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. static inline void cx18_io_delay(struct cx18 *cx)
  26. {
  27. if (cx->options.mmio_ndelay)
  28. ndelay(cx->options.mmio_ndelay);
  29. }
  30. /*
  31. * Readback and retry of MMIO access for reliability:
  32. * The concept was suggested by Steve Toth <stoth@linuxtv.org>.
  33. * The implmentation is the fault of Andy Walls <awalls@radix.net>.
  34. */
  35. /* Statistics gathering */
  36. static inline
  37. void cx18_log_write_retries(struct cx18 *cx, int i, const void *addr)
  38. {
  39. if (i > CX18_MAX_MMIO_RETRIES)
  40. i = CX18_MAX_MMIO_RETRIES;
  41. atomic_inc(&cx->mmio_stats.retried_write[i]);
  42. return;
  43. }
  44. static inline
  45. void cx18_log_read_retries(struct cx18 *cx, int i, const void *addr)
  46. {
  47. if (i > CX18_MAX_MMIO_RETRIES)
  48. i = CX18_MAX_MMIO_RETRIES;
  49. atomic_inc(&cx->mmio_stats.retried_read[i]);
  50. return;
  51. }
  52. void cx18_log_statistics(struct cx18 *cx);
  53. /* Non byteswapping memory mapped IO */
  54. static inline
  55. void cx18_raw_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
  56. {
  57. __raw_writel(val, addr);
  58. cx18_io_delay(cx);
  59. }
  60. void cx18_raw_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr);
  61. static inline void cx18_raw_writel(struct cx18 *cx, u32 val, void __iomem *addr)
  62. {
  63. if (cx18_retry_mmio)
  64. cx18_raw_writel_retry(cx, val, addr);
  65. else
  66. cx18_raw_writel_noretry(cx, val, addr);
  67. }
  68. static inline
  69. u32 cx18_raw_readl_noretry(struct cx18 *cx, const void __iomem *addr)
  70. {
  71. u32 ret = __raw_readl(addr);
  72. cx18_io_delay(cx);
  73. return ret;
  74. }
  75. u32 cx18_raw_readl_retry(struct cx18 *cx, const void __iomem *addr);
  76. static inline u32 cx18_raw_readl(struct cx18 *cx, const void __iomem *addr)
  77. {
  78. if (cx18_retry_mmio)
  79. return cx18_raw_readl_retry(cx, addr);
  80. return cx18_raw_readl_noretry(cx, addr);
  81. }
  82. static inline
  83. u16 cx18_raw_readw_noretry(struct cx18 *cx, const void __iomem *addr)
  84. {
  85. u16 ret = __raw_readw(addr);
  86. cx18_io_delay(cx);
  87. return ret;
  88. }
  89. u16 cx18_raw_readw_retry(struct cx18 *cx, const void __iomem *addr);
  90. static inline u16 cx18_raw_readw(struct cx18 *cx, const void __iomem *addr)
  91. {
  92. if (cx18_retry_mmio)
  93. return cx18_raw_readw_retry(cx, addr);
  94. return cx18_raw_readw_noretry(cx, addr);
  95. }
  96. /* Normal memory mapped IO */
  97. static inline
  98. void cx18_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
  99. {
  100. writel(val, addr);
  101. cx18_io_delay(cx);
  102. }
  103. void cx18_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr);
  104. static inline void cx18_writel(struct cx18 *cx, u32 val, void __iomem *addr)
  105. {
  106. if (cx18_retry_mmio)
  107. cx18_writel_retry(cx, val, addr);
  108. else
  109. cx18_writel_noretry(cx, val, addr);
  110. }
  111. static inline
  112. void cx18_writew_noretry(struct cx18 *cx, u16 val, void __iomem *addr)
  113. {
  114. writew(val, addr);
  115. cx18_io_delay(cx);
  116. }
  117. void cx18_writew_retry(struct cx18 *cx, u16 val, void __iomem *addr);
  118. static inline void cx18_writew(struct cx18 *cx, u16 val, void __iomem *addr)
  119. {
  120. if (cx18_retry_mmio)
  121. cx18_writew_retry(cx, val, addr);
  122. else
  123. cx18_writew_noretry(cx, val, addr);
  124. }
  125. static inline
  126. void cx18_writeb_noretry(struct cx18 *cx, u8 val, void __iomem *addr)
  127. {
  128. writeb(val, addr);
  129. cx18_io_delay(cx);
  130. }
  131. void cx18_writeb_retry(struct cx18 *cx, u8 val, void __iomem *addr);
  132. static inline void cx18_writeb(struct cx18 *cx, u8 val, void __iomem *addr)
  133. {
  134. if (cx18_retry_mmio)
  135. cx18_writeb_retry(cx, val, addr);
  136. else
  137. cx18_writeb_noretry(cx, val, addr);
  138. }
  139. static inline u32 cx18_readl_noretry(struct cx18 *cx, const void __iomem *addr)
  140. {
  141. u32 ret = readl(addr);
  142. cx18_io_delay(cx);
  143. return ret;
  144. }
  145. u32 cx18_readl_retry(struct cx18 *cx, const void __iomem *addr);
  146. static inline u32 cx18_readl(struct cx18 *cx, const void __iomem *addr)
  147. {
  148. if (cx18_retry_mmio)
  149. return cx18_readl_retry(cx, addr);
  150. return cx18_readl_noretry(cx, addr);
  151. }
  152. static inline u16 cx18_readw_noretry(struct cx18 *cx, const void __iomem *addr)
  153. {
  154. u16 ret = readw(addr);
  155. cx18_io_delay(cx);
  156. return ret;
  157. }
  158. u16 cx18_readw_retry(struct cx18 *cx, const void __iomem *addr);
  159. static inline u16 cx18_readw(struct cx18 *cx, const void __iomem *addr)
  160. {
  161. if (cx18_retry_mmio)
  162. return cx18_readw_retry(cx, addr);
  163. return cx18_readw_noretry(cx, addr);
  164. }
  165. static inline u8 cx18_readb_noretry(struct cx18 *cx, const void __iomem *addr)
  166. {
  167. u8 ret = readb(addr);
  168. cx18_io_delay(cx);
  169. return ret;
  170. }
  171. u8 cx18_readb_retry(struct cx18 *cx, const void __iomem *addr);
  172. static inline u8 cx18_readb(struct cx18 *cx, const void __iomem *addr)
  173. {
  174. if (cx18_retry_mmio)
  175. return cx18_readb_retry(cx, addr);
  176. return cx18_readb_noretry(cx, addr);
  177. }
  178. static inline
  179. u32 cx18_write_sync_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
  180. {
  181. cx18_writel_noretry(cx, val, addr);
  182. return cx18_readl_noretry(cx, addr);
  183. }
  184. static inline
  185. u32 cx18_write_sync_retry(struct cx18 *cx, u32 val, void __iomem *addr)
  186. {
  187. cx18_writel_retry(cx, val, addr);
  188. return cx18_readl_retry(cx, addr);
  189. }
  190. static inline u32 cx18_write_sync(struct cx18 *cx, u32 val, void __iomem *addr)
  191. {
  192. if (cx18_retry_mmio)
  193. return cx18_write_sync_retry(cx, val, addr);
  194. return cx18_write_sync_noretry(cx, val, addr);
  195. }
  196. void cx18_memcpy_fromio(struct cx18 *cx, void *to,
  197. const void __iomem *from, unsigned int len);
  198. void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count);
  199. /* Access "register" region of CX23418 memory mapped I/O */
  200. static inline void cx18_write_reg_noretry(struct cx18 *cx, u32 val, u32 reg)
  201. {
  202. cx18_writel_noretry(cx, val, cx->reg_mem + reg);
  203. }
  204. static inline void cx18_write_reg_retry(struct cx18 *cx, u32 val, u32 reg)
  205. {
  206. cx18_writel_retry(cx, val, cx->reg_mem + reg);
  207. }
  208. static inline void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg)
  209. {
  210. if (cx18_retry_mmio)
  211. cx18_write_reg_retry(cx, val, reg);
  212. else
  213. cx18_write_reg_noretry(cx, val, reg);
  214. }
  215. static inline u32 cx18_read_reg_noretry(struct cx18 *cx, u32 reg)
  216. {
  217. return cx18_readl_noretry(cx, cx->reg_mem + reg);
  218. }
  219. static inline u32 cx18_read_reg_retry(struct cx18 *cx, u32 reg)
  220. {
  221. return cx18_readl_retry(cx, cx->reg_mem + reg);
  222. }
  223. static inline u32 cx18_read_reg(struct cx18 *cx, u32 reg)
  224. {
  225. if (cx18_retry_mmio)
  226. return cx18_read_reg_retry(cx, reg);
  227. return cx18_read_reg_noretry(cx, reg);
  228. }
  229. static inline u32 cx18_write_reg_sync_noretry(struct cx18 *cx, u32 val, u32 reg)
  230. {
  231. return cx18_write_sync_noretry(cx, val, cx->reg_mem + reg);
  232. }
  233. static inline u32 cx18_write_reg_sync_retry(struct cx18 *cx, u32 val, u32 reg)
  234. {
  235. return cx18_write_sync_retry(cx, val, cx->reg_mem + reg);
  236. }
  237. static inline u32 cx18_write_reg_sync(struct cx18 *cx, u32 val, u32 reg)
  238. {
  239. if (cx18_retry_mmio)
  240. return cx18_write_reg_sync_retry(cx, val, reg);
  241. return cx18_write_reg_sync_noretry(cx, val, reg);
  242. }
  243. /* Access "encoder memory" region of CX23418 memory mapped I/O */
  244. static inline void cx18_write_enc_noretry(struct cx18 *cx, u32 val, u32 addr)
  245. {
  246. cx18_writel_noretry(cx, val, cx->enc_mem + addr);
  247. }
  248. static inline void cx18_write_enc_retry(struct cx18 *cx, u32 val, u32 addr)
  249. {
  250. cx18_writel_retry(cx, val, cx->enc_mem + addr);
  251. }
  252. static inline void cx18_write_enc(struct cx18 *cx, u32 val, u32 addr)
  253. {
  254. if (cx18_retry_mmio)
  255. cx18_write_enc_retry(cx, val, addr);
  256. else
  257. cx18_write_enc_noretry(cx, val, addr);
  258. }
  259. static inline u32 cx18_read_enc_noretry(struct cx18 *cx, u32 addr)
  260. {
  261. return cx18_readl_noretry(cx, cx->enc_mem + addr);
  262. }
  263. static inline u32 cx18_read_enc_retry(struct cx18 *cx, u32 addr)
  264. {
  265. return cx18_readl_retry(cx, cx->enc_mem + addr);
  266. }
  267. static inline u32 cx18_read_enc(struct cx18 *cx, u32 addr)
  268. {
  269. if (cx18_retry_mmio)
  270. return cx18_read_enc_retry(cx, addr);
  271. return cx18_read_enc_noretry(cx, addr);
  272. }
  273. static inline
  274. u32 cx18_write_enc_sync_noretry(struct cx18 *cx, u32 val, u32 addr)
  275. {
  276. return cx18_write_sync_noretry(cx, val, cx->enc_mem + addr);
  277. }
  278. static inline
  279. u32 cx18_write_enc_sync_retry(struct cx18 *cx, u32 val, u32 addr)
  280. {
  281. return cx18_write_sync_retry(cx, val, cx->enc_mem + addr);
  282. }
  283. static inline
  284. u32 cx18_write_enc_sync(struct cx18 *cx, u32 val, u32 addr)
  285. {
  286. if (cx18_retry_mmio)
  287. return cx18_write_enc_sync_retry(cx, val, addr);
  288. return cx18_write_enc_sync_noretry(cx, val, addr);
  289. }
  290. void cx18_sw1_irq_enable(struct cx18 *cx, u32 val);
  291. void cx18_sw1_irq_disable(struct cx18 *cx, u32 val);
  292. void cx18_sw2_irq_enable(struct cx18 *cx, u32 val);
  293. void cx18_sw2_irq_disable(struct cx18 *cx, u32 val);
  294. void cx18_setup_page(struct cx18 *cx, u32 addr);
  295. #endif /* CX18_IO_H */