io.c 8.9 KB

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