io.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * linux/arch/sh/kernel/io_7751se.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 SolutionEngine.
  8. *
  9. * Initial version only to support LAN access; some
  10. * placeholder code from io_se.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/se7751/se7751.h>
  17. #include <asm/addrspace.h>
  18. #include <linux/pci.h>
  19. #include "../../../drivers/pci/pci-sh7751.h"
  20. #if 0
  21. /******************************************************************
  22. * Variables from io_se.c, related to PCMCIA (not PCI); we're not
  23. * compiling them in, and have removed references from functions
  24. * which follow. [Many checked for IO ports in the range bounded
  25. * by sh_pcic_io_start/stop, and used sh_pcic_io_wbase as offset.
  26. * As start/stop are uninitialized, only port 0x0 would match?]
  27. * When used, remember to adjust names to avoid clash with io_se?
  28. *****************************************************************/
  29. /* SH pcmcia io window base, start and end. */
  30. int sh_pcic_io_wbase = 0xb8400000;
  31. int sh_pcic_io_start;
  32. int sh_pcic_io_stop;
  33. int sh_pcic_io_type;
  34. int sh_pcic_io_dummy;
  35. /*************************************************************/
  36. #endif
  37. /*
  38. * The 7751 Solution Engine uses the built-in PCI controller (PCIC)
  39. * of the 7751 processor, and has a SuperIO accessible via the PCI.
  40. * The board also includes a PCMCIA controller on its memory bus,
  41. * like the other Solution Engine boards.
  42. */
  43. #define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR)
  44. #define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR)
  45. #define PCI_IO_AREA SH7751_PCI_IO_BASE
  46. #define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE
  47. #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
  48. #define maybebadio(name,port) \
  49. printk("bad PC-like io %s for port 0x%lx at 0x%08x\n", \
  50. #name, (port), (__u32) __builtin_return_address(0))
  51. static inline void delay(void)
  52. {
  53. ctrl_inw(0xa0000000);
  54. }
  55. static inline volatile __u16 *
  56. port2adr(unsigned int port)
  57. {
  58. if (port >= 0x2000)
  59. return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
  60. #if 0
  61. else
  62. return (volatile __u16 *) (PA_SUPERIO + (port << 1));
  63. #endif
  64. maybebadio(name,(unsigned long)port);
  65. return (volatile __u16*)port;
  66. }
  67. #if 0
  68. /* The 7751 Solution Engine seems to have everything hooked */
  69. /* up pretty normally (nothing on high-bytes only...) so this */
  70. /* shouldn't be needed */
  71. static inline int
  72. shifted_port(unsigned long port)
  73. {
  74. /* For IDE registers, value is not shifted */
  75. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  76. return 0;
  77. else
  78. return 1;
  79. }
  80. #endif
  81. /* In case someone configures the kernel w/o PCI support: in that */
  82. /* scenario, don't ever bother to check for PCI-window addresses */
  83. /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
  84. #if defined(CONFIG_PCI)
  85. #define CHECK_SH7751_PCIIO(port) \
  86. ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
  87. #else
  88. #define CHECK_SH7751_PCIIO(port) (0)
  89. #endif
  90. /*
  91. * General outline: remap really low stuff [eventually] to SuperIO,
  92. * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
  93. * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
  94. * should be way beyond the window, and is used w/o translation for
  95. * compatibility.
  96. */
  97. unsigned char sh7751se_inb(unsigned long port)
  98. {
  99. if (PXSEG(port))
  100. return *(volatile unsigned char *)port;
  101. else if (CHECK_SH7751_PCIIO(port))
  102. return *(volatile unsigned char *)PCI_IOMAP(port);
  103. else
  104. return (*port2adr(port))&0xff;
  105. }
  106. unsigned char sh7751se_inb_p(unsigned long port)
  107. {
  108. unsigned char v;
  109. if (PXSEG(port))
  110. v = *(volatile unsigned char *)port;
  111. else if (CHECK_SH7751_PCIIO(port))
  112. v = *(volatile unsigned char *)PCI_IOMAP(port);
  113. else
  114. v = (*port2adr(port))&0xff;
  115. delay();
  116. return v;
  117. }
  118. unsigned short sh7751se_inw(unsigned long port)
  119. {
  120. if (PXSEG(port))
  121. return *(volatile unsigned short *)port;
  122. else if (CHECK_SH7751_PCIIO(port))
  123. return *(volatile unsigned short *)PCI_IOMAP(port);
  124. else if (port >= 0x2000)
  125. return *port2adr(port);
  126. else
  127. maybebadio(inw, port);
  128. return 0;
  129. }
  130. unsigned int sh7751se_inl(unsigned long port)
  131. {
  132. if (PXSEG(port))
  133. return *(volatile unsigned long *)port;
  134. else if (CHECK_SH7751_PCIIO(port))
  135. return *(volatile unsigned int *)PCI_IOMAP(port);
  136. else if (port >= 0x2000)
  137. return *port2adr(port);
  138. else
  139. maybebadio(inl, port);
  140. return 0;
  141. }
  142. void sh7751se_outb(unsigned char value, unsigned long port)
  143. {
  144. if (PXSEG(port))
  145. *(volatile unsigned char *)port = value;
  146. else if (CHECK_SH7751_PCIIO(port))
  147. *((unsigned char*)PCI_IOMAP(port)) = value;
  148. else
  149. *(port2adr(port)) = value;
  150. }
  151. void sh7751se_outb_p(unsigned char value, unsigned long port)
  152. {
  153. if (PXSEG(port))
  154. *(volatile unsigned char *)port = value;
  155. else if (CHECK_SH7751_PCIIO(port))
  156. *((unsigned char*)PCI_IOMAP(port)) = value;
  157. else
  158. *(port2adr(port)) = value;
  159. delay();
  160. }
  161. void sh7751se_outw(unsigned short value, unsigned long port)
  162. {
  163. if (PXSEG(port))
  164. *(volatile unsigned short *)port = value;
  165. else if (CHECK_SH7751_PCIIO(port))
  166. *((unsigned short *)PCI_IOMAP(port)) = value;
  167. else if (port >= 0x2000)
  168. *port2adr(port) = value;
  169. else
  170. maybebadio(outw, port);
  171. }
  172. void sh7751se_outl(unsigned int value, unsigned long port)
  173. {
  174. if (PXSEG(port))
  175. *(volatile unsigned long *)port = value;
  176. else if (CHECK_SH7751_PCIIO(port))
  177. *((unsigned long*)PCI_IOMAP(port)) = value;
  178. else
  179. maybebadio(outl, port);
  180. }
  181. void sh7751se_insl(unsigned long port, void *addr, unsigned long count)
  182. {
  183. maybebadio(insl, port);
  184. }
  185. void sh7751se_outsl(unsigned long port, const void *addr, unsigned long count)
  186. {
  187. maybebadio(outsw, port);
  188. }
  189. /* Map ISA bus address to the real address. Only for PCMCIA. */
  190. /* ISA page descriptor. */
  191. static __u32 sh_isa_memmap[256];
  192. #if 0
  193. static int
  194. sh_isa_mmap(__u32 start, __u32 length, __u32 offset)
  195. {
  196. int idx;
  197. if (start >= 0x100000 || (start & 0xfff) || (length != 0x1000))
  198. return -1;
  199. idx = start >> 12;
  200. sh_isa_memmap[idx] = 0xb8000000 + (offset &~ 0xfff);
  201. printk("sh_isa_mmap: start %x len %x offset %x (idx %x paddr %x)\n",
  202. start, length, offset, idx, sh_isa_memmap[idx]);
  203. return 0;
  204. }
  205. #endif
  206. unsigned long
  207. sh7751se_isa_port2addr(unsigned long offset)
  208. {
  209. int idx;
  210. idx = (offset >> 12) & 0xff;
  211. offset &= 0xfff;
  212. return sh_isa_memmap[idx] + offset;
  213. }