io.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. unsigned char *s = addr;
  191. if (CHECK_AX88796L_PORT(port)) {
  192. p = (volatile unsigned short *)port88796l(port, 0);
  193. while (count--) *s++ = *p & 0xff;
  194. } else if (PXSEG(port))
  195. while (count--) *s++ = *(volatile unsigned char *)port;
  196. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  197. bp = (__u8 *)PCI_IOMAP(port);
  198. while (count--) *s++ = *bp;
  199. } else {
  200. p = (volatile unsigned short *)port2adr(port);
  201. while (count--) *s++ = *p & 0xff;
  202. }
  203. }
  204. void rts7751r2d_insw(unsigned long port, void *addr, unsigned long count)
  205. {
  206. volatile __u16 *p;
  207. __u16 *s = addr;
  208. if (CHECK_AX88796L_PORT(port))
  209. p = (volatile unsigned short *)port88796l(port, 1);
  210. else if (PXSEG(port))
  211. p = (volatile unsigned short *)port;
  212. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  213. p = (volatile unsigned short *)PCI_IOMAP(port);
  214. else
  215. p = (volatile unsigned short *)port2adr(port);
  216. while (count--) *s++ = *p;
  217. }
  218. void rts7751r2d_insl(unsigned long port, void *addr, unsigned long count)
  219. {
  220. if (CHECK_AX88796L_PORT(port))
  221. maybebadio(insl, port);
  222. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  223. volatile __u32 *p = (__u32 *)PCI_IOMAP(port);
  224. __u32 *s = addr;
  225. while (count--) *s++ = *p;
  226. } else
  227. maybebadio(insl, port);
  228. }
  229. void rts7751r2d_outsb(unsigned long port, const void *addr, unsigned long count)
  230. {
  231. volatile __u8 *bp;
  232. volatile __u16 *p;
  233. const __u8 *s = addr;
  234. if (CHECK_AX88796L_PORT(port)) {
  235. p = (volatile unsigned short *)port88796l(port, 0);
  236. while (count--) *p = *s++;
  237. } else if (PXSEG(port))
  238. while (count--) *(volatile unsigned char *)port = *s++;
  239. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  240. bp = (__u8 *)PCI_IOMAP(port);
  241. while (count--) *bp = *s++;
  242. } else {
  243. p = (volatile unsigned short *)port2adr(port);
  244. while (count--) *p = *s++;
  245. }
  246. }
  247. void rts7751r2d_outsw(unsigned long port, const void *addr, unsigned long count)
  248. {
  249. volatile __u16 *p;
  250. const __u16 *s = addr;
  251. if (CHECK_AX88796L_PORT(port))
  252. p = (volatile unsigned short *)port88796l(port, 1);
  253. else if (PXSEG(port))
  254. p = (volatile unsigned short *)port;
  255. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  256. p = (volatile unsigned short *)PCI_IOMAP(port);
  257. else
  258. p = (volatile unsigned short *)port2adr(port);
  259. while (count--) *p = *s++;
  260. }
  261. void rts7751r2d_outsl(unsigned long port, const void *addr, unsigned long count)
  262. {
  263. if (CHECK_AX88796L_PORT(port))
  264. maybebadio(outsl, port);
  265. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  266. volatile __u32 *p = (__u32 *)PCI_IOMAP(port);
  267. const __u32 *s = addr;
  268. while (count--) *p = *s++;
  269. } else
  270. maybebadio(outsl, port);
  271. }
  272. void *rts7751r2d_ioremap(unsigned long offset, unsigned long size)
  273. {
  274. if (offset >= 0xfd000000)
  275. return (void *)offset;
  276. else
  277. return (void *)P2SEGADDR(offset);
  278. }
  279. EXPORT_SYMBOL(rts7751r2d_ioremap);
  280. unsigned long rts7751r2d_isa_port2addr(unsigned long offset)
  281. {
  282. return port2adr(offset);
  283. }