io.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * linux/arch/sh/kernel/io_rts7751r2d.c
  3. *
  4. * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
  5. * Based largely on io_se.c.
  6. *
  7. * I/O routine for Renesas Technology sales RTS7751R2D.
  8. *
  9. * Initial version only to support LAN access; some
  10. * placeholder code from io_rts7751r2d.c left in with the
  11. * expectation of later SuperIO and PCMCIA access.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <asm/io.h>
  16. #include <asm/rts7751r2d/rts7751r2d.h>
  17. #include <asm/addrspace.h>
  18. #include <linux/module.h>
  19. #include <linux/pci.h>
  20. #include "../../../drivers/pci/pci-sh7751.h"
  21. /*
  22. * The 7751R RTS7751R2D uses the built-in PCI controller (PCIC)
  23. * of the 7751R processor, and has a SuperIO accessible via the PCI.
  24. * The board also includes a PCMCIA controller on its memory bus,
  25. * like the other Solution Engine boards.
  26. */
  27. #define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR)
  28. #define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR)
  29. #define PCI_IO_AREA SH7751_PCI_IO_BASE
  30. #define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE
  31. #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
  32. #define maybebadio(name,port) \
  33. printk("bad PC-like io %s for port 0x%lx at 0x%08x\n", \
  34. #name, (port), (__u32) __builtin_return_address(0))
  35. static inline void delay(void)
  36. {
  37. ctrl_inw(0xa0000000);
  38. }
  39. static inline unsigned long port2adr(unsigned int port)
  40. {
  41. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  42. if (port == 0x3f6)
  43. return (PA_AREA5_IO + 0x80c);
  44. else
  45. return (PA_AREA5_IO + 0x1000 + ((port-0x1f0) << 1));
  46. else
  47. maybebadio(port2adr, (unsigned long)port);
  48. return port;
  49. }
  50. static inline unsigned long port88796l(unsigned int port, int flag)
  51. {
  52. unsigned long addr;
  53. if (flag)
  54. addr = PA_AX88796L + ((port - AX88796L_IO_BASE) << 1);
  55. else
  56. addr = PA_AX88796L + ((port - AX88796L_IO_BASE) << 1) + 0x1000;
  57. return addr;
  58. }
  59. /* The 7751R RTS7751R2D seems to have everything hooked */
  60. /* up pretty normally (nothing on high-bytes only...) so this */
  61. /* shouldn't be needed */
  62. static inline int shifted_port(unsigned long port)
  63. {
  64. /* For IDE registers, value is not shifted */
  65. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  66. return 0;
  67. else
  68. return 1;
  69. }
  70. /* In case someone configures the kernel w/o PCI support: in that */
  71. /* scenario, don't ever bother to check for PCI-window addresses */
  72. /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
  73. #if defined(CONFIG_PCI)
  74. #define CHECK_SH7751_PCIIO(port) \
  75. ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
  76. #else
  77. #define CHECK_SH7751_PCIIO(port) (0)
  78. #endif
  79. #if defined(CONFIG_NE2000) || defined(CONFIG_NE2000_MODULE)
  80. #define CHECK_AX88796L_PORT(port) \
  81. ((port >= AX88796L_IO_BASE) && (port < (AX88796L_IO_BASE+0x20)))
  82. #else
  83. #define CHECK_AX88796L_PORT(port) (0)
  84. #endif
  85. /*
  86. * General outline: remap really low stuff [eventually] to SuperIO,
  87. * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
  88. * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
  89. * should be way beyond the window, and is used w/o translation for
  90. * compatibility.
  91. */
  92. unsigned char rts7751r2d_inb(unsigned long port)
  93. {
  94. if (CHECK_AX88796L_PORT(port))
  95. return (*(volatile unsigned short *)port88796l(port, 0)) & 0xff;
  96. else if (PXSEG(port))
  97. return *(volatile unsigned char *)port;
  98. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  99. return *(volatile unsigned char *)PCI_IOMAP(port);
  100. else
  101. return (*(volatile unsigned short *)port2adr(port) & 0xff);
  102. }
  103. unsigned char rts7751r2d_inb_p(unsigned long port)
  104. {
  105. unsigned char v;
  106. if (CHECK_AX88796L_PORT(port))
  107. v = (*(volatile unsigned short *)port88796l(port, 0)) & 0xff;
  108. else if (PXSEG(port))
  109. v = *(volatile unsigned char *)port;
  110. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  111. v = *(volatile unsigned char *)PCI_IOMAP(port);
  112. else
  113. v = (*(volatile unsigned short *)port2adr(port) & 0xff);
  114. delay();
  115. return v;
  116. }
  117. unsigned short rts7751r2d_inw(unsigned long port)
  118. {
  119. if (CHECK_AX88796L_PORT(port))
  120. maybebadio(inw, port);
  121. else if (PXSEG(port))
  122. return *(volatile unsigned short *)port;
  123. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  124. return *(volatile unsigned short *)PCI_IOMAP(port);
  125. else
  126. maybebadio(inw, port);
  127. return 0;
  128. }
  129. unsigned int rts7751r2d_inl(unsigned long port)
  130. {
  131. if (CHECK_AX88796L_PORT(port))
  132. maybebadio(inl, port);
  133. else if (PXSEG(port))
  134. return *(volatile unsigned long *)port;
  135. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  136. return *(volatile unsigned long *)PCI_IOMAP(port);
  137. else
  138. maybebadio(inl, port);
  139. return 0;
  140. }
  141. void rts7751r2d_outb(unsigned char value, unsigned long port)
  142. {
  143. if (CHECK_AX88796L_PORT(port))
  144. *((volatile unsigned short *)port88796l(port, 0)) = value;
  145. else if (PXSEG(port))
  146. *(volatile unsigned char *)port = value;
  147. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  148. *(volatile unsigned char *)PCI_IOMAP(port) = value;
  149. else
  150. *(volatile unsigned short *)port2adr(port) = value;
  151. }
  152. void rts7751r2d_outb_p(unsigned char value, unsigned long port)
  153. {
  154. if (CHECK_AX88796L_PORT(port))
  155. *((volatile unsigned short *)port88796l(port, 0)) = value;
  156. else if (PXSEG(port))
  157. *(volatile unsigned char *)port = value;
  158. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  159. *(volatile unsigned char *)PCI_IOMAP(port) = value;
  160. else
  161. *(volatile unsigned short *)port2adr(port) = value;
  162. delay();
  163. }
  164. void rts7751r2d_outw(unsigned short value, unsigned long port)
  165. {
  166. if (CHECK_AX88796L_PORT(port))
  167. maybebadio(outw, port);
  168. else if (PXSEG(port))
  169. *(volatile unsigned short *)port = value;
  170. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  171. *(volatile unsigned short *)PCI_IOMAP(port) = value;
  172. else
  173. maybebadio(outw, port);
  174. }
  175. void rts7751r2d_outl(unsigned int value, unsigned long port)
  176. {
  177. if (CHECK_AX88796L_PORT(port))
  178. maybebadio(outl, port);
  179. else if (PXSEG(port))
  180. *(volatile unsigned long *)port = value;
  181. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  182. *(volatile unsigned long *)PCI_IOMAP(port) = value;
  183. else
  184. maybebadio(outl, port);
  185. }
  186. void rts7751r2d_insb(unsigned long port, void *addr, unsigned long count)
  187. {
  188. volatile __u8 *bp;
  189. volatile __u16 *p;
  190. if (CHECK_AX88796L_PORT(port)) {
  191. p = (volatile unsigned short *)port88796l(port, 0);
  192. while (count--) *((unsigned char *) addr)++ = *p & 0xff;
  193. } else if (PXSEG(port))
  194. while (count--) *((unsigned char *) addr)++ = *(volatile unsigned char *)port;
  195. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  196. bp = (__u8 *)PCI_IOMAP(port);
  197. while (count--) *((volatile unsigned char *) addr)++ = *bp;
  198. } else {
  199. p = (volatile unsigned short *)port2adr(port);
  200. while (count--) *((unsigned char *) addr)++ = *p & 0xff;
  201. }
  202. }
  203. void rts7751r2d_insw(unsigned long port, void *addr, unsigned long count)
  204. {
  205. volatile __u16 *p;
  206. if (CHECK_AX88796L_PORT(port))
  207. p = (volatile unsigned short *)port88796l(port, 1);
  208. else if (PXSEG(port))
  209. p = (volatile unsigned short *)port;
  210. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  211. p = (volatile unsigned short *)PCI_IOMAP(port);
  212. else
  213. p = (volatile unsigned short *)port2adr(port);
  214. while (count--) *((__u16 *) addr)++ = *p;
  215. }
  216. void rts7751r2d_insl(unsigned long port, void *addr, unsigned long count)
  217. {
  218. if (CHECK_AX88796L_PORT(port))
  219. maybebadio(insl, port);
  220. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  221. volatile __u32 *p = (__u32 *)PCI_IOMAP(port);
  222. while (count--) *((__u32 *) addr)++ = *p;
  223. } else
  224. maybebadio(insl, port);
  225. }
  226. void rts7751r2d_outsb(unsigned long port, const void *addr, unsigned long count)
  227. {
  228. volatile __u8 *bp;
  229. volatile __u16 *p;
  230. if (CHECK_AX88796L_PORT(port)) {
  231. p = (volatile unsigned short *)port88796l(port, 0);
  232. while (count--) *p = *((unsigned char *) addr)++;
  233. } else if (PXSEG(port))
  234. while (count--) *(volatile unsigned char *)port = *((unsigned char *) addr)++;
  235. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  236. bp = (__u8 *)PCI_IOMAP(port);
  237. while (count--) *bp = *((volatile unsigned char *) addr)++;
  238. } else {
  239. p = (volatile unsigned short *)port2adr(port);
  240. while (count--) *p = *((unsigned char *) addr)++;
  241. }
  242. }
  243. void rts7751r2d_outsw(unsigned long port, const void *addr, unsigned long count)
  244. {
  245. volatile __u16 *p;
  246. if (CHECK_AX88796L_PORT(port))
  247. p = (volatile unsigned short *)port88796l(port, 1);
  248. else if (PXSEG(port))
  249. p = (volatile unsigned short *)port;
  250. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  251. p = (volatile unsigned short *)PCI_IOMAP(port);
  252. else
  253. p = (volatile unsigned short *)port2adr(port);
  254. while (count--) *p = *((__u16 *) addr)++;
  255. }
  256. void rts7751r2d_outsl(unsigned long port, const void *addr, unsigned long count)
  257. {
  258. if (CHECK_AX88796L_PORT(port))
  259. maybebadio(outsl, port);
  260. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  261. volatile __u32 *p = (__u32 *)PCI_IOMAP(port);
  262. while (count--) *p = *((__u32 *) addr)++;
  263. } else
  264. maybebadio(outsl, port);
  265. }
  266. void *rts7751r2d_ioremap(unsigned long offset, unsigned long size)
  267. {
  268. if (offset >= 0xfd000000)
  269. return (void *)offset;
  270. else
  271. return (void *)P2SEGADDR(offset);
  272. }
  273. EXPORT_SYMBOL(rts7751r2d_ioremap);
  274. unsigned long rts7751r2d_isa_port2addr(unsigned long offset)
  275. {
  276. return port2adr(offset);
  277. }