io.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 <linux/io.h>
  15. #include <asm/r7780rp.h>
  16. #include <asm/addrspace.h>
  17. static inline unsigned long port88796l(unsigned int port, int flag)
  18. {
  19. unsigned long addr;
  20. if (flag)
  21. addr = PA_AX88796L + ((port - AX88796L_IO_BASE) << 1);
  22. else
  23. addr = PA_AX88796L + ((port - AX88796L_IO_BASE) << 1) + 0x1000;
  24. return addr;
  25. }
  26. #if defined(CONFIG_NE2000) || defined(CONFIG_NE2000_MODULE)
  27. #define CHECK_AX88796L_PORT(port) \
  28. ((port >= AX88796L_IO_BASE) && (port < (AX88796L_IO_BASE+0x20)))
  29. #else
  30. #define CHECK_AX88796L_PORT(port) (0)
  31. #endif
  32. /*
  33. * General outline: remap really low stuff [eventually] to SuperIO,
  34. * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
  35. * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
  36. * should be way beyond the window, and is used w/o translation for
  37. * compatibility.
  38. */
  39. u8 r7780rp_inb(unsigned long port)
  40. {
  41. if (CHECK_AX88796L_PORT(port))
  42. return ctrl_inw(port88796l(port, 0)) & 0xff;
  43. else if (is_pci_ioaddr(port))
  44. return ctrl_inb(pci_ioaddr(port));
  45. return ctrl_inw(port) & 0xff;
  46. }
  47. u8 r7780rp_inb_p(unsigned long port)
  48. {
  49. u8 v;
  50. if (CHECK_AX88796L_PORT(port))
  51. v = ctrl_inw(port88796l(port, 0)) & 0xff;
  52. else if (is_pci_ioaddr(port))
  53. v = ctrl_inb(pci_ioaddr(port));
  54. else
  55. v = ctrl_inw(port) & 0xff;
  56. ctrl_delay();
  57. return v;
  58. }
  59. u16 r7780rp_inw(unsigned long port)
  60. {
  61. if (is_pci_ioaddr(port))
  62. return ctrl_inw(pci_ioaddr(port));
  63. return ctrl_inw(port);
  64. }
  65. u32 r7780rp_inl(unsigned long port)
  66. {
  67. if (is_pci_ioaddr(port))
  68. return ctrl_inl(pci_ioaddr(port));
  69. return ctrl_inl(port);
  70. }
  71. void r7780rp_outb(u8 value, unsigned long port)
  72. {
  73. if (CHECK_AX88796L_PORT(port))
  74. ctrl_outw(value, port88796l(port, 0));
  75. else if (is_pci_ioaddr(port))
  76. ctrl_outb(value, pci_ioaddr(port));
  77. else
  78. ctrl_outb(value, port);
  79. }
  80. void r7780rp_outb_p(u8 value, unsigned long port)
  81. {
  82. if (CHECK_AX88796L_PORT(port))
  83. ctrl_outw(value, port88796l(port, 0));
  84. else if (is_pci_ioaddr(port))
  85. ctrl_outb(value, pci_ioaddr(port));
  86. else
  87. ctrl_outb(value, port);
  88. ctrl_delay();
  89. }
  90. void r7780rp_outw(u16 value, unsigned long port)
  91. {
  92. if (is_pci_ioaddr(port))
  93. ctrl_outw(value, pci_ioaddr(port));
  94. else
  95. ctrl_outw(value, port);
  96. }
  97. void r7780rp_outl(u32 value, unsigned long port)
  98. {
  99. if (is_pci_ioaddr(port))
  100. ctrl_outl(value, pci_ioaddr(port));
  101. else
  102. ctrl_outl(value, port);
  103. }
  104. void r7780rp_insb(unsigned long port, void *dst, unsigned long count)
  105. {
  106. volatile u16 *p;
  107. u8 *buf = dst;
  108. if (CHECK_AX88796L_PORT(port)) {
  109. p = (volatile u16 *)port88796l(port, 0);
  110. while (count--)
  111. *buf++ = *p & 0xff;
  112. } else if (is_pci_ioaddr(port)) {
  113. volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
  114. while (count--)
  115. *buf++ = *bp;
  116. } else {
  117. p = (volatile u16 *)port;
  118. while (count--)
  119. *buf++ = *p & 0xff;
  120. }
  121. }
  122. void r7780rp_insw(unsigned long port, void *dst, unsigned long count)
  123. {
  124. volatile u16 *p;
  125. u16 *buf = dst;
  126. if (CHECK_AX88796L_PORT(port))
  127. p = (volatile u16 *)port88796l(port, 1);
  128. else if (is_pci_ioaddr(port))
  129. p = (volatile u16 *)pci_ioaddr(port);
  130. else
  131. p = (volatile u16 *)port;
  132. while (count--)
  133. *buf++ = *p;
  134. flush_dcache_all();
  135. }
  136. void r7780rp_insl(unsigned long port, void *dst, unsigned long count)
  137. {
  138. if (is_pci_ioaddr(port)) {
  139. volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
  140. u32 *buf = dst;
  141. while (count--)
  142. *buf++ = *p;
  143. }
  144. }
  145. void r7780rp_outsb(unsigned long port, const void *src, unsigned long count)
  146. {
  147. volatile u16 *p;
  148. const u8 *buf = src;
  149. if (CHECK_AX88796L_PORT(port)) {
  150. p = (volatile u16 *)port88796l(port, 0);
  151. while (count--)
  152. *p = *buf++;
  153. } else if (is_pci_ioaddr(port)) {
  154. volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
  155. while (count--)
  156. *bp = *buf++;
  157. } else
  158. while (count--)
  159. ctrl_outb(*buf++, port);
  160. }
  161. void r7780rp_outsw(unsigned long port, const void *src, unsigned long count)
  162. {
  163. volatile u16 *p;
  164. const u16 *buf = src;
  165. if (CHECK_AX88796L_PORT(port))
  166. p = (volatile u16 *)port88796l(port, 1);
  167. else if (is_pci_ioaddr(port))
  168. p = (volatile u16 *)pci_ioaddr(port);
  169. else
  170. p = (volatile u16 *)port;
  171. while (count--)
  172. *p = *buf++;
  173. flush_dcache_all();
  174. }
  175. void r7780rp_outsl(unsigned long port, const void *src, unsigned long count)
  176. {
  177. const u32 *buf = src;
  178. u32 *p;
  179. if (is_pci_ioaddr(port))
  180. p = (u32 *)pci_ioaddr(port);
  181. else
  182. p = (u32 *)port;
  183. while (count--)
  184. ctrl_outl(*buf++, (unsigned long)p);
  185. }
  186. void __iomem *r7780rp_ioport_map(unsigned long port, unsigned int size)
  187. {
  188. if (CHECK_AX88796L_PORT(port))
  189. return (void __iomem *)port88796l(port, size > 1);
  190. else if (is_pci_ioaddr(port))
  191. return (void __iomem *)pci_ioaddr(port);
  192. return (void __iomem *)port;
  193. }