cx18-io.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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 __iomem *addr)
  38. {
  39. if (i > CX18_MAX_MMIO_WR_RETRIES)
  40. i = CX18_MAX_MMIO_WR_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 __iomem *addr)
  46. {
  47. if (i > CX18_MAX_MMIO_RD_RETRIES)
  48. i = CX18_MAX_MMIO_RD_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. void _cx18_writel_expect(struct cx18 *cx, u32 val, void __iomem *addr,
  112. u32 eval, u32 mask);
  113. static inline
  114. void cx18_writew_noretry(struct cx18 *cx, u16 val, void __iomem *addr)
  115. {
  116. writew(val, addr);
  117. cx18_io_delay(cx);
  118. }
  119. void cx18_writew_retry(struct cx18 *cx, u16 val, void __iomem *addr);
  120. static inline void cx18_writew(struct cx18 *cx, u16 val, void __iomem *addr)
  121. {
  122. if (cx18_retry_mmio)
  123. cx18_writew_retry(cx, val, addr);
  124. else
  125. cx18_writew_noretry(cx, val, addr);
  126. }
  127. static inline
  128. void cx18_writeb_noretry(struct cx18 *cx, u8 val, void __iomem *addr)
  129. {
  130. writeb(val, addr);
  131. cx18_io_delay(cx);
  132. }
  133. void cx18_writeb_retry(struct cx18 *cx, u8 val, void __iomem *addr);
  134. static inline void cx18_writeb(struct cx18 *cx, u8 val, void __iomem *addr)
  135. {
  136. if (cx18_retry_mmio)
  137. cx18_writeb_retry(cx, val, addr);
  138. else
  139. cx18_writeb_noretry(cx, val, addr);
  140. }
  141. static inline u32 cx18_readl_noretry(struct cx18 *cx, const void __iomem *addr)
  142. {
  143. u32 ret = readl(addr);
  144. cx18_io_delay(cx);
  145. return ret;
  146. }
  147. u32 cx18_readl_retry(struct cx18 *cx, const void __iomem *addr);
  148. static inline u32 cx18_readl(struct cx18 *cx, const void __iomem *addr)
  149. {
  150. if (cx18_retry_mmio)
  151. return cx18_readl_retry(cx, addr);
  152. return cx18_readl_noretry(cx, addr);
  153. }
  154. static inline u16 cx18_readw_noretry(struct cx18 *cx, const void __iomem *addr)
  155. {
  156. u16 ret = readw(addr);
  157. cx18_io_delay(cx);
  158. return ret;
  159. }
  160. u16 cx18_readw_retry(struct cx18 *cx, const void __iomem *addr);
  161. static inline u16 cx18_readw(struct cx18 *cx, const void __iomem *addr)
  162. {
  163. if (cx18_retry_mmio)
  164. return cx18_readw_retry(cx, addr);
  165. return cx18_readw_noretry(cx, addr);
  166. }
  167. static inline u8 cx18_readb_noretry(struct cx18 *cx, const void __iomem *addr)
  168. {
  169. u8 ret = readb(addr);
  170. cx18_io_delay(cx);
  171. return ret;
  172. }
  173. u8 cx18_readb_retry(struct cx18 *cx, const void __iomem *addr);
  174. static inline u8 cx18_readb(struct cx18 *cx, const void __iomem *addr)
  175. {
  176. if (cx18_retry_mmio)
  177. return cx18_readb_retry(cx, addr);
  178. return cx18_readb_noretry(cx, addr);
  179. }
  180. static inline
  181. u32 cx18_write_sync_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
  182. {
  183. cx18_writel_noretry(cx, val, addr);
  184. return cx18_readl_noretry(cx, addr);
  185. }
  186. static inline
  187. u32 cx18_write_sync_retry(struct cx18 *cx, u32 val, void __iomem *addr)
  188. {
  189. cx18_writel_retry(cx, val, addr);
  190. return cx18_readl_retry(cx, addr);
  191. }
  192. static inline u32 cx18_write_sync(struct cx18 *cx, u32 val, void __iomem *addr)
  193. {
  194. if (cx18_retry_mmio)
  195. return cx18_write_sync_retry(cx, val, addr);
  196. return cx18_write_sync_noretry(cx, val, addr);
  197. }
  198. void cx18_memcpy_fromio(struct cx18 *cx, void *to,
  199. const void __iomem *from, unsigned int len);
  200. void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count);
  201. /* Access "register" region of CX23418 memory mapped I/O */
  202. static inline void cx18_write_reg_noretry(struct cx18 *cx, u32 val, u32 reg)
  203. {
  204. cx18_writel_noretry(cx, val, cx->reg_mem + reg);
  205. }
  206. static inline void cx18_write_reg_retry(struct cx18 *cx, u32 val, u32 reg)
  207. {
  208. cx18_writel_retry(cx, val, cx->reg_mem + reg);
  209. }
  210. static inline void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg)
  211. {
  212. if (cx18_retry_mmio)
  213. cx18_write_reg_retry(cx, val, reg);
  214. else
  215. cx18_write_reg_noretry(cx, val, reg);
  216. }
  217. static inline void _cx18_write_reg_expect(struct cx18 *cx, u32 val, u32 reg,
  218. u32 eval, u32 mask)
  219. {
  220. _cx18_writel_expect(cx, val, cx->reg_mem + reg, eval, mask);
  221. }
  222. static inline void cx18_write_reg_expect(struct cx18 *cx, u32 val, u32 reg,
  223. u32 eval, u32 mask)
  224. {
  225. if (cx18_retry_mmio)
  226. _cx18_write_reg_expect(cx, val, reg, eval, mask);
  227. else
  228. cx18_write_reg_noretry(cx, val, reg);
  229. }
  230. static inline u32 cx18_read_reg_noretry(struct cx18 *cx, u32 reg)
  231. {
  232. return cx18_readl_noretry(cx, cx->reg_mem + reg);
  233. }
  234. static inline u32 cx18_read_reg_retry(struct cx18 *cx, u32 reg)
  235. {
  236. return cx18_readl_retry(cx, cx->reg_mem + reg);
  237. }
  238. static inline u32 cx18_read_reg(struct cx18 *cx, u32 reg)
  239. {
  240. if (cx18_retry_mmio)
  241. return cx18_read_reg_retry(cx, reg);
  242. return cx18_read_reg_noretry(cx, reg);
  243. }
  244. static inline u32 cx18_write_reg_sync_noretry(struct cx18 *cx, u32 val, u32 reg)
  245. {
  246. return cx18_write_sync_noretry(cx, val, cx->reg_mem + reg);
  247. }
  248. static inline u32 cx18_write_reg_sync_retry(struct cx18 *cx, u32 val, u32 reg)
  249. {
  250. return cx18_write_sync_retry(cx, val, cx->reg_mem + reg);
  251. }
  252. static inline u32 cx18_write_reg_sync(struct cx18 *cx, u32 val, u32 reg)
  253. {
  254. if (cx18_retry_mmio)
  255. return cx18_write_reg_sync_retry(cx, val, reg);
  256. return cx18_write_reg_sync_noretry(cx, val, reg);
  257. }
  258. /* Access "encoder memory" region of CX23418 memory mapped I/O */
  259. static inline void cx18_write_enc_noretry(struct cx18 *cx, u32 val, u32 addr)
  260. {
  261. cx18_writel_noretry(cx, val, cx->enc_mem + addr);
  262. }
  263. static inline void cx18_write_enc_retry(struct cx18 *cx, u32 val, u32 addr)
  264. {
  265. cx18_writel_retry(cx, val, cx->enc_mem + addr);
  266. }
  267. static inline void cx18_write_enc(struct cx18 *cx, u32 val, u32 addr)
  268. {
  269. if (cx18_retry_mmio)
  270. cx18_write_enc_retry(cx, val, addr);
  271. else
  272. cx18_write_enc_noretry(cx, val, addr);
  273. }
  274. static inline u32 cx18_read_enc_noretry(struct cx18 *cx, u32 addr)
  275. {
  276. return cx18_readl_noretry(cx, cx->enc_mem + addr);
  277. }
  278. static inline u32 cx18_read_enc_retry(struct cx18 *cx, u32 addr)
  279. {
  280. return cx18_readl_retry(cx, cx->enc_mem + addr);
  281. }
  282. static inline u32 cx18_read_enc(struct cx18 *cx, u32 addr)
  283. {
  284. if (cx18_retry_mmio)
  285. return cx18_read_enc_retry(cx, addr);
  286. return cx18_read_enc_noretry(cx, addr);
  287. }
  288. static inline
  289. u32 cx18_write_enc_sync_noretry(struct cx18 *cx, u32 val, u32 addr)
  290. {
  291. return cx18_write_sync_noretry(cx, val, cx->enc_mem + addr);
  292. }
  293. static inline
  294. u32 cx18_write_enc_sync_retry(struct cx18 *cx, u32 val, u32 addr)
  295. {
  296. return cx18_write_sync_retry(cx, val, cx->enc_mem + addr);
  297. }
  298. static inline
  299. u32 cx18_write_enc_sync(struct cx18 *cx, u32 val, u32 addr)
  300. {
  301. if (cx18_retry_mmio)
  302. return cx18_write_enc_sync_retry(cx, val, addr);
  303. return cx18_write_enc_sync_noretry(cx, val, addr);
  304. }
  305. void cx18_sw1_irq_enable(struct cx18 *cx, u32 val);
  306. void cx18_sw1_irq_disable(struct cx18 *cx, u32 val);
  307. void cx18_sw2_irq_enable(struct cx18 *cx, u32 val);
  308. void cx18_sw2_irq_disable(struct cx18 *cx, u32 val);
  309. void cx18_setup_page(struct cx18 *cx, u32 addr);
  310. #endif /* CX18_IO_H */