io.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * linux/arch/sh/kernel/io_7751se.c
  3. *
  4. * Copyright (C) 2002 David McCullough <davidm@snapgear.com>
  5. * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
  6. * Based largely on io_se.c.
  7. *
  8. * I/O routine for Hitachi 7751 SolutionEngine.
  9. *
  10. * Initial version only to support LAN access; some
  11. * placeholder code from io_se.c left in with the
  12. * expectation of later SuperIO and PCMCIA access.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/types.h>
  16. #include <linux/pci.h>
  17. #include <asm/io.h>
  18. #include <asm/addrspace.h>
  19. #include <asm/pci.h>
  20. #include "../../drivers/pci/pci-sh7751.h"
  21. #ifdef CONFIG_SH_SECUREEDGE5410
  22. unsigned short secureedge5410_ioport;
  23. #endif
  24. /*
  25. * The SnapGear uses the built-in PCI controller (PCIC)
  26. * of the 7751 processor
  27. */
  28. #define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR)
  29. #define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR)
  30. #define PCI_IO_AREA SH7751_PCI_IO_BASE
  31. #define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE
  32. #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
  33. #define maybebadio(name,port) \
  34. printk("bad PC-like io %s for port 0x%lx at 0x%08x\n", \
  35. #name, (port), (__u32) __builtin_return_address(0))
  36. static inline void delay(void)
  37. {
  38. ctrl_inw(0xa0000000);
  39. }
  40. static inline volatile __u16 *port2adr(unsigned int port)
  41. {
  42. #if 0
  43. if (port >= 0x2000)
  44. return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
  45. #endif
  46. maybebadio(name,(unsigned long)port);
  47. return (volatile __u16*)port;
  48. }
  49. /* In case someone configures the kernel w/o PCI support: in that */
  50. /* scenario, don't ever bother to check for PCI-window addresses */
  51. /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
  52. #if defined(CONFIG_PCI)
  53. #define CHECK_SH7751_PCIIO(port) \
  54. ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
  55. #else
  56. #define CHECK_SH7751_PCIIO(port) (0)
  57. #endif
  58. /*
  59. * General outline: remap really low stuff [eventually] to SuperIO,
  60. * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
  61. * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
  62. * should be way beyond the window, and is used w/o translation for
  63. * compatibility.
  64. */
  65. unsigned char snapgear_inb(unsigned long port)
  66. {
  67. if (PXSEG(port))
  68. return *(volatile unsigned char *)port;
  69. else if (CHECK_SH7751_PCIIO(port))
  70. return *(volatile unsigned char *)PCI_IOMAP(port);
  71. else
  72. return (*port2adr(port))&0xff;
  73. }
  74. unsigned char snapgear_inb_p(unsigned long port)
  75. {
  76. unsigned char v;
  77. if (PXSEG(port))
  78. v = *(volatile unsigned char *)port;
  79. else if (CHECK_SH7751_PCIIO(port))
  80. v = *(volatile unsigned char *)PCI_IOMAP(port);
  81. else
  82. v = (*port2adr(port))&0xff;
  83. delay();
  84. return v;
  85. }
  86. unsigned short snapgear_inw(unsigned long port)
  87. {
  88. if (PXSEG(port))
  89. return *(volatile unsigned short *)port;
  90. else if (CHECK_SH7751_PCIIO(port))
  91. return *(volatile unsigned short *)PCI_IOMAP(port);
  92. else if (port >= 0x2000)
  93. return *port2adr(port);
  94. else
  95. maybebadio(inw, port);
  96. return 0;
  97. }
  98. unsigned int snapgear_inl(unsigned long port)
  99. {
  100. if (PXSEG(port))
  101. return *(volatile unsigned long *)port;
  102. else if (CHECK_SH7751_PCIIO(port))
  103. return *(volatile unsigned int *)PCI_IOMAP(port);
  104. else if (port >= 0x2000)
  105. return *port2adr(port);
  106. else
  107. maybebadio(inl, port);
  108. return 0;
  109. }
  110. void snapgear_outb(unsigned char value, unsigned long port)
  111. {
  112. if (PXSEG(port))
  113. *(volatile unsigned char *)port = value;
  114. else if (CHECK_SH7751_PCIIO(port))
  115. *((unsigned char*)PCI_IOMAP(port)) = value;
  116. else
  117. *(port2adr(port)) = value;
  118. }
  119. void snapgear_outb_p(unsigned char value, unsigned long port)
  120. {
  121. if (PXSEG(port))
  122. *(volatile unsigned char *)port = value;
  123. else if (CHECK_SH7751_PCIIO(port))
  124. *((unsigned char*)PCI_IOMAP(port)) = value;
  125. else
  126. *(port2adr(port)) = value;
  127. delay();
  128. }
  129. void snapgear_outw(unsigned short value, unsigned long port)
  130. {
  131. if (PXSEG(port))
  132. *(volatile unsigned short *)port = value;
  133. else if (CHECK_SH7751_PCIIO(port))
  134. *((unsigned short *)PCI_IOMAP(port)) = value;
  135. else if (port >= 0x2000)
  136. *port2adr(port) = value;
  137. else
  138. maybebadio(outw, port);
  139. }
  140. void snapgear_outl(unsigned int value, unsigned long port)
  141. {
  142. if (PXSEG(port))
  143. *(volatile unsigned long *)port = value;
  144. else if (CHECK_SH7751_PCIIO(port))
  145. *((unsigned long*)PCI_IOMAP(port)) = value;
  146. else
  147. maybebadio(outl, port);
  148. }
  149. void snapgear_insl(unsigned long port, void *addr, unsigned long count)
  150. {
  151. maybebadio(insl, port);
  152. }
  153. void snapgear_outsl(unsigned long port, const void *addr, unsigned long count)
  154. {
  155. maybebadio(outsw, port);
  156. }
  157. /* Map ISA bus address to the real address. Only for PCMCIA. */
  158. /* ISA page descriptor. */
  159. static __u32 sh_isa_memmap[256];
  160. #if 0
  161. static int sh_isa_mmap(__u32 start, __u32 length, __u32 offset)
  162. {
  163. int idx;
  164. if (start >= 0x100000 || (start & 0xfff) || (length != 0x1000))
  165. return -1;
  166. idx = start >> 12;
  167. sh_isa_memmap[idx] = 0xb8000000 + (offset &~ 0xfff);
  168. #if 0
  169. printk("sh_isa_mmap: start %x len %x offset %x (idx %x paddr %x)\n",
  170. start, length, offset, idx, sh_isa_memmap[idx]);
  171. #endif
  172. return 0;
  173. }
  174. #endif
  175. unsigned long snapgear_isa_port2addr(unsigned long offset)
  176. {
  177. int idx;
  178. idx = (offset >> 12) & 0xff;
  179. offset &= 0xfff;
  180. return sh_isa_memmap[idx] + offset;
  181. }