io.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * linux/arch/sh/boards/systemh/io.c
  3. *
  4. * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
  5. * Based largely on io_se.c.
  6. *
  7. * I/O routine for Hitachi 7751 Systemh.
  8. *
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/types.h>
  12. #include <asm/systemh/7751systemh.h>
  13. #include <asm/addrspace.h>
  14. #include <asm/io.h>
  15. #include <linux/pci.h>
  16. #include "../../drivers/pci/pci-sh7751.h"
  17. /*
  18. * The 7751 SystemH Engine uses the built-in PCI controller (PCIC)
  19. * of the 7751 processor, and has a SuperIO accessible on its memory
  20. * bus.
  21. */
  22. #define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR)
  23. #define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR)
  24. #define PCI_IO_AREA SH7751_PCI_IO_BASE
  25. #define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE
  26. #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
  27. #define ETHER_IOMAP(adr) (0xB3000000 + (adr)) /*map to 16bits access area
  28. of smc lan chip*/
  29. #define maybebadio(name,port) \
  30. printk("bad PC-like io %s for port 0x%lx at 0x%08x\n", \
  31. #name, (port), (__u32) __builtin_return_address(0))
  32. static inline void delay(void)
  33. {
  34. ctrl_inw(0xa0000000);
  35. }
  36. static inline volatile __u16 *
  37. port2adr(unsigned int port)
  38. {
  39. if (port >= 0x2000)
  40. return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
  41. #if 0
  42. else
  43. return (volatile __u16 *) (PA_SUPERIO + (port << 1));
  44. #endif
  45. maybebadio(name,(unsigned long)port);
  46. return (volatile __u16*)port;
  47. }
  48. /* In case someone configures the kernel w/o PCI support: in that */
  49. /* scenario, don't ever bother to check for PCI-window addresses */
  50. /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
  51. #if defined(CONFIG_PCI)
  52. #define CHECK_SH7751_PCIIO(port) \
  53. ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
  54. #else
  55. #define CHECK_SH7751_PCIIO(port) (0)
  56. #endif
  57. /*
  58. * General outline: remap really low stuff [eventually] to SuperIO,
  59. * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
  60. * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
  61. * should be way beyond the window, and is used w/o translation for
  62. * compatibility.
  63. */
  64. unsigned char sh7751systemh_inb(unsigned long port)
  65. {
  66. if (PXSEG(port))
  67. return *(volatile unsigned char *)port;
  68. else if (CHECK_SH7751_PCIIO(port))
  69. return *(volatile unsigned char *)PCI_IOMAP(port);
  70. else if (port <= 0x3F1)
  71. return *(volatile unsigned char *)ETHER_IOMAP(port);
  72. else
  73. return (*port2adr(port))&0xff;
  74. }
  75. unsigned char sh7751systemh_inb_p(unsigned long port)
  76. {
  77. unsigned char v;
  78. if (PXSEG(port))
  79. v = *(volatile unsigned char *)port;
  80. else if (CHECK_SH7751_PCIIO(port))
  81. v = *(volatile unsigned char *)PCI_IOMAP(port);
  82. else if (port <= 0x3F1)
  83. v = *(volatile unsigned char *)ETHER_IOMAP(port);
  84. else
  85. v = (*port2adr(port))&0xff;
  86. delay();
  87. return v;
  88. }
  89. unsigned short sh7751systemh_inw(unsigned long port)
  90. {
  91. if (PXSEG(port))
  92. return *(volatile unsigned short *)port;
  93. else if (CHECK_SH7751_PCIIO(port))
  94. return *(volatile unsigned short *)PCI_IOMAP(port);
  95. else if (port >= 0x2000)
  96. return *port2adr(port);
  97. else if (port <= 0x3F1)
  98. return *(volatile unsigned int *)ETHER_IOMAP(port);
  99. else
  100. maybebadio(inw, port);
  101. return 0;
  102. }
  103. unsigned int sh7751systemh_inl(unsigned long port)
  104. {
  105. if (PXSEG(port))
  106. return *(volatile unsigned long *)port;
  107. else if (CHECK_SH7751_PCIIO(port))
  108. return *(volatile unsigned int *)PCI_IOMAP(port);
  109. else if (port >= 0x2000)
  110. return *port2adr(port);
  111. else if (port <= 0x3F1)
  112. return *(volatile unsigned int *)ETHER_IOMAP(port);
  113. else
  114. maybebadio(inl, port);
  115. return 0;
  116. }
  117. void sh7751systemh_outb(unsigned char value, unsigned long port)
  118. {
  119. if (PXSEG(port))
  120. *(volatile unsigned char *)port = value;
  121. else if (CHECK_SH7751_PCIIO(port))
  122. *((unsigned char*)PCI_IOMAP(port)) = value;
  123. else if (port <= 0x3F1)
  124. *(volatile unsigned char *)ETHER_IOMAP(port) = value;
  125. else
  126. *(port2adr(port)) = value;
  127. }
  128. void sh7751systemh_outb_p(unsigned char value, unsigned long port)
  129. {
  130. if (PXSEG(port))
  131. *(volatile unsigned char *)port = value;
  132. else if (CHECK_SH7751_PCIIO(port))
  133. *((unsigned char*)PCI_IOMAP(port)) = value;
  134. else if (port <= 0x3F1)
  135. *(volatile unsigned char *)ETHER_IOMAP(port) = value;
  136. else
  137. *(port2adr(port)) = value;
  138. delay();
  139. }
  140. void sh7751systemh_outw(unsigned short value, unsigned long port)
  141. {
  142. if (PXSEG(port))
  143. *(volatile unsigned short *)port = value;
  144. else if (CHECK_SH7751_PCIIO(port))
  145. *((unsigned short *)PCI_IOMAP(port)) = value;
  146. else if (port >= 0x2000)
  147. *port2adr(port) = value;
  148. else if (port <= 0x3F1)
  149. *(volatile unsigned short *)ETHER_IOMAP(port) = value;
  150. else
  151. maybebadio(outw, port);
  152. }
  153. void sh7751systemh_outl(unsigned int value, unsigned long port)
  154. {
  155. if (PXSEG(port))
  156. *(volatile unsigned long *)port = value;
  157. else if (CHECK_SH7751_PCIIO(port))
  158. *((unsigned long*)PCI_IOMAP(port)) = value;
  159. else
  160. maybebadio(outl, port);
  161. }
  162. void sh7751systemh_insb(unsigned long port, void *addr, unsigned long count)
  163. {
  164. unsigned char *p = addr;
  165. while (count--) *p++ = sh7751systemh_inb(port);
  166. }
  167. void sh7751systemh_insw(unsigned long port, void *addr, unsigned long count)
  168. {
  169. unsigned short *p = addr;
  170. while (count--) *p++ = sh7751systemh_inw(port);
  171. }
  172. void sh7751systemh_insl(unsigned long port, void *addr, unsigned long count)
  173. {
  174. maybebadio(insl, port);
  175. }
  176. void sh7751systemh_outsb(unsigned long port, const void *addr, unsigned long count)
  177. {
  178. unsigned char *p = (unsigned char*)addr;
  179. while (count--) sh7751systemh_outb(*p++, port);
  180. }
  181. void sh7751systemh_outsw(unsigned long port, const void *addr, unsigned long count)
  182. {
  183. unsigned short *p = (unsigned short*)addr;
  184. while (count--) sh7751systemh_outw(*p++, port);
  185. }
  186. void sh7751systemh_outsl(unsigned long port, const void *addr, unsigned long count)
  187. {
  188. maybebadio(outsw, port);
  189. }
  190. /* For read/write calls, just copy generic (pass-thru); PCIMBR is */
  191. /* already set up. For a larger memory space, these would need to */
  192. /* reset PCIMBR as needed on a per-call basis... */
  193. unsigned char sh7751systemh_readb(unsigned long addr)
  194. {
  195. return *(volatile unsigned char*)addr;
  196. }
  197. unsigned short sh7751systemh_readw(unsigned long addr)
  198. {
  199. return *(volatile unsigned short*)addr;
  200. }
  201. unsigned int sh7751systemh_readl(unsigned long addr)
  202. {
  203. return *(volatile unsigned long*)addr;
  204. }
  205. void sh7751systemh_writeb(unsigned char b, unsigned long addr)
  206. {
  207. *(volatile unsigned char*)addr = b;
  208. }
  209. void sh7751systemh_writew(unsigned short b, unsigned long addr)
  210. {
  211. *(volatile unsigned short*)addr = b;
  212. }
  213. void sh7751systemh_writel(unsigned int b, unsigned long addr)
  214. {
  215. *(volatile unsigned long*)addr = b;
  216. }
  217. /* Map ISA bus address to the real address. Only for PCMCIA. */
  218. /* ISA page descriptor. */
  219. static __u32 sh_isa_memmap[256];
  220. #if 0
  221. static int
  222. sh_isa_mmap(__u32 start, __u32 length, __u32 offset)
  223. {
  224. int idx;
  225. if (start >= 0x100000 || (start & 0xfff) || (length != 0x1000))
  226. return -1;
  227. idx = start >> 12;
  228. sh_isa_memmap[idx] = 0xb8000000 + (offset &~ 0xfff);
  229. printk("sh_isa_mmap: start %x len %x offset %x (idx %x paddr %x)\n",
  230. start, length, offset, idx, sh_isa_memmap[idx]);
  231. return 0;
  232. }
  233. #endif
  234. unsigned long
  235. sh7751systemh_isa_port2addr(unsigned long offset)
  236. {
  237. int idx;
  238. idx = (offset >> 12) & 0xff;
  239. offset &= 0xfff;
  240. return sh_isa_memmap[idx] + offset;
  241. }