io.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
  3. * Based largely on io_se.c.
  4. *
  5. * I/O routine for Renesas Solutions Highlander R7780RP-1
  6. *
  7. * Initial version only to support LAN access; some
  8. * placeholder code from io_r7780rp.c left in with the
  9. * expectation of later SuperIO and PCMCIA access.
  10. */
  11. #include <linux/pci.h>
  12. #include <linux/kernel.h>
  13. #include <linux/types.h>
  14. #include <asm/r7780rp.h>
  15. #include <asm/addrspace.h>
  16. #include <asm/io.h>
  17. static inline unsigned long port2adr(unsigned int port)
  18. {
  19. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  20. if (port == 0x3f6)
  21. return (PA_AREA5_IO + 0x80c);
  22. else
  23. return (PA_AREA5_IO + 0x1000 + ((port-0x1f0) << 1));
  24. else
  25. maybebadio((unsigned long)port);
  26. return port;
  27. }
  28. static inline unsigned long port88796l(unsigned int port, int flag)
  29. {
  30. unsigned long addr;
  31. if (flag)
  32. addr = PA_AX88796L + ((port - AX88796L_IO_BASE) << 1);
  33. else
  34. addr = PA_AX88796L + ((port - AX88796L_IO_BASE) << 1) + 0x1000;
  35. return addr;
  36. }
  37. /* The 7780 R7780RP-1 seems to have everything hooked */
  38. /* up pretty normally (nothing on high-bytes only...) so this */
  39. /* shouldn't be needed */
  40. static inline int shifted_port(unsigned long port)
  41. {
  42. /* For IDE registers, value is not shifted */
  43. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  44. return 0;
  45. else
  46. return 1;
  47. }
  48. #if defined(CONFIG_NE2000) || defined(CONFIG_NE2000_MODULE)
  49. #define CHECK_AX88796L_PORT(port) \
  50. ((port >= AX88796L_IO_BASE) && (port < (AX88796L_IO_BASE+0x20)))
  51. #else
  52. #define CHECK_AX88796L_PORT(port) (0)
  53. #endif
  54. /*
  55. * General outline: remap really low stuff [eventually] to SuperIO,
  56. * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
  57. * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
  58. * should be way beyond the window, and is used w/o translation for
  59. * compatibility.
  60. */
  61. u8 r7780rp_inb(unsigned long port)
  62. {
  63. if (CHECK_AX88796L_PORT(port))
  64. return ctrl_inw(port88796l(port, 0)) & 0xff;
  65. else if (PXSEG(port))
  66. return ctrl_inb(port);
  67. else if (is_pci_ioaddr(port) || shifted_port(port))
  68. return ctrl_inb(pci_ioaddr(port));
  69. return ctrl_inw(port2adr(port)) & 0xff;
  70. }
  71. u8 r7780rp_inb_p(unsigned long port)
  72. {
  73. u8 v;
  74. if (CHECK_AX88796L_PORT(port))
  75. v = ctrl_inw(port88796l(port, 0)) & 0xff;
  76. else if (PXSEG(port))
  77. v = ctrl_inb(port);
  78. else if (is_pci_ioaddr(port) || shifted_port(port))
  79. v = ctrl_inb(pci_ioaddr(port));
  80. else
  81. v = ctrl_inw(port2adr(port)) & 0xff;
  82. ctrl_delay();
  83. return v;
  84. }
  85. u16 r7780rp_inw(unsigned long port)
  86. {
  87. if (CHECK_AX88796L_PORT(port))
  88. maybebadio(port);
  89. else if (PXSEG(port))
  90. return ctrl_inw(port);
  91. else if (is_pci_ioaddr(port) || shifted_port(port))
  92. return ctrl_inw(pci_ioaddr(port));
  93. else
  94. maybebadio(port);
  95. return 0;
  96. }
  97. u32 r7780rp_inl(unsigned long port)
  98. {
  99. if (CHECK_AX88796L_PORT(port))
  100. maybebadio(port);
  101. else if (PXSEG(port))
  102. return ctrl_inl(port);
  103. else if (is_pci_ioaddr(port) || shifted_port(port))
  104. return ctrl_inl(pci_ioaddr(port));
  105. else
  106. maybebadio(port);
  107. return 0;
  108. }
  109. void r7780rp_outb(u8 value, unsigned long port)
  110. {
  111. if (CHECK_AX88796L_PORT(port))
  112. ctrl_outw(value, port88796l(port, 0));
  113. else if (PXSEG(port))
  114. ctrl_outb(value, port);
  115. else if (is_pci_ioaddr(port) || shifted_port(port))
  116. ctrl_outb(value, pci_ioaddr(port));
  117. else
  118. ctrl_outw(value, port2adr(port));
  119. }
  120. void r7780rp_outb_p(u8 value, unsigned long port)
  121. {
  122. if (CHECK_AX88796L_PORT(port))
  123. ctrl_outw(value, port88796l(port, 0));
  124. else if (PXSEG(port))
  125. ctrl_outb(value, port);
  126. else if (is_pci_ioaddr(port) || shifted_port(port))
  127. ctrl_outb(value, pci_ioaddr(port));
  128. else
  129. ctrl_outw(value, port2adr(port));
  130. ctrl_delay();
  131. }
  132. void r7780rp_outw(u16 value, unsigned long port)
  133. {
  134. if (CHECK_AX88796L_PORT(port))
  135. maybebadio(port);
  136. else if (PXSEG(port))
  137. ctrl_outw(value, port);
  138. else if (is_pci_ioaddr(port) || shifted_port(port))
  139. ctrl_outw(value, pci_ioaddr(port));
  140. else
  141. maybebadio(port);
  142. }
  143. void r7780rp_outl(u32 value, unsigned long port)
  144. {
  145. if (CHECK_AX88796L_PORT(port))
  146. maybebadio(port);
  147. else if (PXSEG(port))
  148. ctrl_outl(value, port);
  149. else if (is_pci_ioaddr(port) || shifted_port(port))
  150. ctrl_outl(value, pci_ioaddr(port));
  151. else
  152. maybebadio(port);
  153. }
  154. void r7780rp_insb(unsigned long port, void *dst, unsigned long count)
  155. {
  156. volatile u16 *p;
  157. u8 *buf = dst;
  158. if (CHECK_AX88796L_PORT(port)) {
  159. p = (volatile u16 *)port88796l(port, 0);
  160. while (count--)
  161. *buf++ = *p & 0xff;
  162. } else if (PXSEG(port)) {
  163. while (count--)
  164. *buf++ = *(volatile u8 *)port;
  165. } else if (is_pci_ioaddr(port) || shifted_port(port)) {
  166. volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
  167. while (count--)
  168. *buf++ = *bp;
  169. } else {
  170. p = (volatile u16 *)port2adr(port);
  171. while (count--)
  172. *buf++ = *p & 0xff;
  173. }
  174. }
  175. void r7780rp_insw(unsigned long port, void *dst, unsigned long count)
  176. {
  177. volatile u16 *p;
  178. u16 *buf = dst;
  179. if (CHECK_AX88796L_PORT(port))
  180. p = (volatile u16 *)port88796l(port, 1);
  181. else if (PXSEG(port))
  182. p = (volatile u16 *)port;
  183. else if (is_pci_ioaddr(port) || shifted_port(port))
  184. p = (volatile u16 *)pci_ioaddr(port);
  185. else
  186. p = (volatile u16 *)port2adr(port);
  187. while (count--)
  188. *buf++ = *p;
  189. }
  190. void r7780rp_insl(unsigned long port, void *dst, unsigned long count)
  191. {
  192. u32 *buf = dst;
  193. if (CHECK_AX88796L_PORT(port))
  194. maybebadio(port);
  195. else if (is_pci_ioaddr(port) || shifted_port(port)) {
  196. volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
  197. while (count--)
  198. *buf++ = *p;
  199. } else
  200. maybebadio(port);
  201. }
  202. void r7780rp_outsb(unsigned long port, const void *src, unsigned long count)
  203. {
  204. volatile u16 *p;
  205. const u8 *buf = src;
  206. if (CHECK_AX88796L_PORT(port)) {
  207. p = (volatile u16 *)port88796l(port, 0);
  208. while (count--)
  209. *p = *buf++;
  210. } else if (PXSEG(port))
  211. while (count--)
  212. ctrl_outb(*buf++, port);
  213. else if (is_pci_ioaddr(port) || shifted_port(port)) {
  214. volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
  215. while (count--)
  216. *bp = *buf++;
  217. } else {
  218. p = (volatile u16 *)port2adr(port);
  219. while (count--)
  220. *p = *buf++;
  221. }
  222. }
  223. void r7780rp_outsw(unsigned long port, const void *src, unsigned long count)
  224. {
  225. volatile u16 *p;
  226. const u16 *buf = src;
  227. if (CHECK_AX88796L_PORT(port))
  228. p = (volatile u16 *)port88796l(port, 1);
  229. else if (PXSEG(port))
  230. p = (volatile u16 *)port;
  231. else if (is_pci_ioaddr(port) || shifted_port(port))
  232. p = (volatile u16 *)pci_ioaddr(port);
  233. else
  234. p = (volatile u16 *)port2adr(port);
  235. while (count--)
  236. *p = *buf++;
  237. }
  238. void r7780rp_outsl(unsigned long port, const void *src, unsigned long count)
  239. {
  240. const u32 *buf = src;
  241. if (CHECK_AX88796L_PORT(port))
  242. maybebadio(port);
  243. else if (is_pci_ioaddr(port) || shifted_port(port)) {
  244. volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
  245. while (count--)
  246. *p = *buf++;
  247. } else
  248. maybebadio(port);
  249. }
  250. void __iomem *r7780rp_ioport_map(unsigned long port, unsigned int size)
  251. {
  252. if (CHECK_AX88796L_PORT(port))
  253. return (void __iomem *)port88796l(port, size > 1);
  254. else if (PXSEG(port))
  255. return (void __iomem *)port;
  256. else if (is_pci_ioaddr(port) || shifted_port(port))
  257. return (void __iomem *)pci_ioaddr(port);
  258. return (void __iomem *)port2adr(port);
  259. }