io.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * linux/arch/sh/boards/renesas/hs7751rvoip/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 Renesas Technology sales HS7751RVoIP
  8. *
  9. * Initial version only to support LAN access; some
  10. * placeholder code from io_hs7751rvoip.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/module.h>
  16. #include <linux/pci.h>
  17. #include <asm/io.h>
  18. #include <asm/hs7751rvoip.h>
  19. #include <asm/addrspace.h>
  20. extern void *area6_io8_base; /* Area 6 8bit I/O Base address */
  21. extern void *area5_io16_base; /* Area 5 16bit I/O Base address */
  22. /*
  23. * The 7751R HS7751RVoIP uses the built-in PCI controller (PCIC)
  24. * of the 7751R processor, and has a SuperIO accessible via the PCI.
  25. * The board also includes a PCMCIA controller on its memory bus,
  26. * like the other Solution Engine boards.
  27. */
  28. #define CODEC_IO_BASE 0x1000
  29. #define CODEC_IOMAP(a) ((unsigned long)area6_io8_base + ((a) - CODEC_IO_BASE))
  30. static inline unsigned long port2adr(unsigned int port)
  31. {
  32. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  33. if (port == 0x3f6)
  34. return ((unsigned long)area5_io16_base + 0x0c);
  35. else
  36. return ((unsigned long)area5_io16_base + 0x800 +
  37. ((port-0x1f0) << 1));
  38. else
  39. maybebadio((unsigned long)port);
  40. return port;
  41. }
  42. /* The 7751R HS7751RVoIP seems to have everything hooked */
  43. /* up pretty normally (nothing on high-bytes only...) so this */
  44. /* shouldn't be needed */
  45. static inline int shifted_port(unsigned long port)
  46. {
  47. /* For IDE registers, value is not shifted */
  48. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  49. return 0;
  50. else
  51. return 1;
  52. }
  53. #if defined(CONFIG_HS7751RVOIP_CODEC)
  54. #define codec_port(port) \
  55. ((CODEC_IO_BASE <= (port)) && ((port) < (CODEC_IO_BASE + 0x20)))
  56. #else
  57. #define codec_port(port) (0)
  58. #endif
  59. /*
  60. * General outline: remap really low stuff [eventually] to SuperIO,
  61. * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
  62. * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
  63. * should be way beyond the window, and is used w/o translation for
  64. * compatibility.
  65. */
  66. unsigned char hs7751rvoip_inb(unsigned long port)
  67. {
  68. if (PXSEG(port))
  69. return ctrl_inb(port);
  70. else if (codec_port(port))
  71. return ctrl_inb(CODEC_IOMAP(port));
  72. else if (is_pci_ioaddr(port) || shifted_port(port))
  73. return ctrl_inb(pci_ioaddr(port));
  74. else
  75. return ctrl_inw(port2adr(port)) & 0xff;
  76. }
  77. unsigned char hs7751rvoip_inb_p(unsigned long port)
  78. {
  79. unsigned char v;
  80. if (PXSEG(port))
  81. v = ctrl_inb(port);
  82. else if (codec_port(port))
  83. v = ctrl_inb(CODEC_IOMAP(port));
  84. else if (is_pci_ioaddr(port) || shifted_port(port))
  85. v = ctrl_inb(pci_ioaddr(port));
  86. else
  87. v = ctrl_inw(port2adr(port)) & 0xff;
  88. ctrl_delay();
  89. return v;
  90. }
  91. unsigned short hs7751rvoip_inw(unsigned long port)
  92. {
  93. if (PXSEG(port))
  94. return ctrl_inw(port);
  95. else if (is_pci_ioaddr(port) || shifted_port(port))
  96. return ctrl_inw(pci_ioaddr(port));
  97. else
  98. maybebadio(port);
  99. return 0;
  100. }
  101. unsigned int hs7751rvoip_inl(unsigned long port)
  102. {
  103. if (PXSEG(port))
  104. return ctrl_inl(port);
  105. else if (is_pci_ioaddr(port) || shifted_port(port))
  106. return ctrl_inl(pci_ioaddr(port));
  107. else
  108. maybebadio(port);
  109. return 0;
  110. }
  111. void hs7751rvoip_outb(unsigned char value, unsigned long port)
  112. {
  113. if (PXSEG(port))
  114. ctrl_outb(value, port);
  115. else if (codec_port(port))
  116. ctrl_outb(value, CODEC_IOMAP(port));
  117. else if (is_pci_ioaddr(port) || shifted_port(port))
  118. ctrl_outb(value, pci_ioaddr(port));
  119. else
  120. ctrl_outb(value, port2adr(port));
  121. }
  122. void hs7751rvoip_outb_p(unsigned char value, unsigned long port)
  123. {
  124. if (PXSEG(port))
  125. ctrl_outb(value, port);
  126. else if (codec_port(port))
  127. ctrl_outb(value, CODEC_IOMAP(port));
  128. else if (is_pci_ioaddr(port) || shifted_port(port))
  129. ctrl_outb(value, pci_ioaddr(port));
  130. else
  131. ctrl_outw(value, port2adr(port));
  132. ctrl_delay();
  133. }
  134. void hs7751rvoip_outw(unsigned short value, unsigned long port)
  135. {
  136. if (PXSEG(port))
  137. ctrl_outw(value, port);
  138. else if (is_pci_ioaddr(port) || shifted_port(port))
  139. ctrl_outw(value, pci_ioaddr(port));
  140. else
  141. maybebadio(port);
  142. }
  143. void hs7751rvoip_outl(unsigned int value, unsigned long port)
  144. {
  145. if (PXSEG(port))
  146. ctrl_outl(value, port);
  147. else if (is_pci_ioaddr(port) || shifted_port(port))
  148. ctrl_outl(value, pci_ioaddr(port));
  149. else
  150. maybebadio(port);
  151. }
  152. void hs7751rvoip_insb(unsigned long port, void *addr, unsigned long count)
  153. {
  154. u8 *buf = addr;
  155. if (PXSEG(port))
  156. while (count--)
  157. *buf++ = ctrl_inb(port);
  158. else if (codec_port(port))
  159. while (count--)
  160. *buf++ = ctrl_inb(CODEC_IOMAP(port));
  161. else if (is_pci_ioaddr(port) || shifted_port(port)) {
  162. volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
  163. while (count--)
  164. *buf++ = *bp;
  165. } else {
  166. volatile u16 *p = (volatile u16 *)port2adr(port);
  167. while (count--)
  168. *buf++ = *p & 0xff;
  169. }
  170. }
  171. void hs7751rvoip_insw(unsigned long port, void *addr, unsigned long count)
  172. {
  173. volatile u16 *p;
  174. u16 *buf = addr;
  175. if (PXSEG(port))
  176. p = (volatile u16 *)port;
  177. else if (is_pci_ioaddr(port) || shifted_port(port))
  178. p = (volatile u16 *)pci_ioaddr(port);
  179. else
  180. p = (volatile u16 *)port2adr(port);
  181. while (count--)
  182. *buf++ = *p;
  183. }
  184. void hs7751rvoip_insl(unsigned long port, void *addr, unsigned long count)
  185. {
  186. if (is_pci_ioaddr(port) || shifted_port(port)) {
  187. volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
  188. u32 *buf = addr;
  189. while (count--)
  190. *buf++ = *p;
  191. } else
  192. maybebadio(port);
  193. }
  194. void hs7751rvoip_outsb(unsigned long port, const void *addr, unsigned long count)
  195. {
  196. const u8 *buf = addr;
  197. if (PXSEG(port))
  198. while (count--)
  199. ctrl_outb(*buf++, port);
  200. else if (codec_port(port))
  201. while (count--)
  202. ctrl_outb(*buf++, CODEC_IOMAP(port));
  203. else if (is_pci_ioaddr(port) || shifted_port(port)) {
  204. volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
  205. while (count--)
  206. *bp = *buf++;
  207. } else {
  208. volatile u16 *p = (volatile u16 *)port2adr(port);
  209. while (count--)
  210. *p = *buf++;
  211. }
  212. }
  213. void hs7751rvoip_outsw(unsigned long port, const void *addr, unsigned long count)
  214. {
  215. volatile u16 *p;
  216. const u16 *buf = addr;
  217. if (PXSEG(port))
  218. p = (volatile u16 *)port;
  219. else if (is_pci_ioaddr(port) || shifted_port(port))
  220. p = (volatile u16 *)pci_ioaddr(port);
  221. else
  222. p = (volatile u16 *)port2adr(port);
  223. while (count--)
  224. *p = *buf++;
  225. }
  226. void hs7751rvoip_outsl(unsigned long port, const void *addr, unsigned long count)
  227. {
  228. const u32 *buf = addr;
  229. if (is_pci_ioaddr(port) || shifted_port(port)) {
  230. volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
  231. while (count--)
  232. *p = *buf++;
  233. } else
  234. maybebadio(port);
  235. }
  236. void __iomem *hs7751rvoip_ioport_map(unsigned long port, unsigned int size)
  237. {
  238. if (PXSEG(port))
  239. return (void __iomem *)port;
  240. else if (unlikely(codec_port(port) && (size == 1)))
  241. return (void __iomem *)CODEC_IOMAP(port);
  242. else if (is_pci_ioaddr(port))
  243. return (void __iomem *)pci_ioaddr(port);
  244. return (void __iomem *)port2adr(port);
  245. }