io.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. * linux/arch/sh/kernel/io_hs7751rvoip.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 <asm/io.h>
  16. #include <asm/hs7751rvoip/hs7751rvoip.h>
  17. #include <asm/addrspace.h>
  18. #include <linux/module.h>
  19. #include <linux/pci.h>
  20. #include "../../../drivers/pci/pci-sh7751.h"
  21. extern void *area5_io8_base; /* Area 5 8bit I/O Base address */
  22. extern void *area6_io8_base; /* Area 6 8bit I/O Base address */
  23. extern void *area5_io16_base; /* Area 5 16bit I/O Base address */
  24. extern void *area6_io16_base; /* Area 6 16bit I/O Base address */
  25. /*
  26. * The 7751R HS7751RVoIP uses the built-in PCI controller (PCIC)
  27. * of the 7751R processor, and has a SuperIO accessible via the PCI.
  28. * The board also includes a PCMCIA controller on its memory bus,
  29. * like the other Solution Engine boards.
  30. */
  31. #define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR)
  32. #define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR)
  33. #define PCI_IO_AREA SH7751_PCI_IO_BASE
  34. #define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE
  35. #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
  36. #if defined(CONFIG_HS7751RVOIP_CODEC)
  37. #define CODEC_IO_BASE 0x1000
  38. #endif
  39. #define maybebadio(name,port) \
  40. printk("bad PC-like io %s for port 0x%lx at 0x%08x\n", \
  41. #name, (port), (__u32) __builtin_return_address(0))
  42. static inline void delay(void)
  43. {
  44. ctrl_inw(0xa0000000);
  45. }
  46. static inline unsigned long port2adr(unsigned int port)
  47. {
  48. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  49. if (port == 0x3f6)
  50. return ((unsigned long)area5_io16_base + 0x0c);
  51. else
  52. return ((unsigned long)area5_io16_base + 0x800 + ((port-0x1f0) << 1));
  53. else
  54. maybebadio(port2adr, (unsigned long)port);
  55. return port;
  56. }
  57. /* The 7751R HS7751RVoIP seems to have everything hooked */
  58. /* up pretty normally (nothing on high-bytes only...) so this */
  59. /* shouldn't be needed */
  60. static inline int shifted_port(unsigned long port)
  61. {
  62. /* For IDE registers, value is not shifted */
  63. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  64. return 0;
  65. else
  66. return 1;
  67. }
  68. #if defined(CONFIG_HS7751RVOIP_CODEC)
  69. static inline int
  70. codec_port(unsigned long port)
  71. {
  72. if (CODEC_IO_BASE <= port && port < (CODEC_IO_BASE+0x20))
  73. return 1;
  74. else
  75. return 0;
  76. }
  77. #endif
  78. /* In case someone configures the kernel w/o PCI support: in that */
  79. /* scenario, don't ever bother to check for PCI-window addresses */
  80. /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
  81. #if defined(CONFIG_PCI)
  82. #define CHECK_SH7751_PCIIO(port) \
  83. ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
  84. #else
  85. #define CHECK_SH7751_PCIIO(port) (0)
  86. #endif
  87. /*
  88. * General outline: remap really low stuff [eventually] to SuperIO,
  89. * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
  90. * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
  91. * should be way beyond the window, and is used w/o translation for
  92. * compatibility.
  93. */
  94. unsigned char hs7751rvoip_inb(unsigned long port)
  95. {
  96. if (PXSEG(port))
  97. return *(volatile unsigned char *)port;
  98. #if defined(CONFIG_HS7751RVOIP_CODEC)
  99. else if (codec_port(port))
  100. return *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE));
  101. #endif
  102. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  103. return *(volatile unsigned char *)PCI_IOMAP(port);
  104. else
  105. return (*(volatile unsigned short *)port2adr(port) & 0xff);
  106. }
  107. unsigned char hs7751rvoip_inb_p(unsigned long port)
  108. {
  109. unsigned char v;
  110. if (PXSEG(port))
  111. v = *(volatile unsigned char *)port;
  112. #if defined(CONFIG_HS7751RVOIP_CODEC)
  113. else if (codec_port(port))
  114. v = *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE));
  115. #endif
  116. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  117. v = *(volatile unsigned char *)PCI_IOMAP(port);
  118. else
  119. v = (*(volatile unsigned short *)port2adr(port) & 0xff);
  120. delay();
  121. return v;
  122. }
  123. unsigned short hs7751rvoip_inw(unsigned long port)
  124. {
  125. if (PXSEG(port))
  126. return *(volatile unsigned short *)port;
  127. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  128. return *(volatile unsigned short *)PCI_IOMAP(port);
  129. else
  130. maybebadio(inw, port);
  131. return 0;
  132. }
  133. unsigned int hs7751rvoip_inl(unsigned long port)
  134. {
  135. if (PXSEG(port))
  136. return *(volatile unsigned long *)port;
  137. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  138. return *(volatile unsigned long *)PCI_IOMAP(port);
  139. else
  140. maybebadio(inl, port);
  141. return 0;
  142. }
  143. void hs7751rvoip_outb(unsigned char value, unsigned long port)
  144. {
  145. if (PXSEG(port))
  146. *(volatile unsigned char *)port = value;
  147. #if defined(CONFIG_HS7751RVOIP_CODEC)
  148. else if (codec_port(port))
  149. *(volatile unsigned cjar *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)) = value;
  150. #endif
  151. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  152. *(unsigned char *)PCI_IOMAP(port) = value;
  153. else
  154. *(volatile unsigned short *)port2adr(port) = value;
  155. }
  156. void hs7751rvoip_outb_p(unsigned char value, unsigned long port)
  157. {
  158. if (PXSEG(port))
  159. *(volatile unsigned char *)port = value;
  160. #if defined(CONFIG_HS7751RVOIP_CODEC)
  161. else if (codec_port(port))
  162. *(volatile unsigned cjar *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)) = value;
  163. #endif
  164. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  165. *(unsigned char *)PCI_IOMAP(port) = value;
  166. else
  167. *(volatile unsigned short *)port2adr(port) = value;
  168. delay();
  169. }
  170. void hs7751rvoip_outw(unsigned short value, unsigned long port)
  171. {
  172. if (PXSEG(port))
  173. *(volatile unsigned short *)port = value;
  174. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  175. *(unsigned short *)PCI_IOMAP(port) = value;
  176. else
  177. maybebadio(outw, port);
  178. }
  179. void hs7751rvoip_outl(unsigned int value, unsigned long port)
  180. {
  181. if (PXSEG(port))
  182. *(volatile unsigned long *)port = value;
  183. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  184. *((unsigned long *)PCI_IOMAP(port)) = value;
  185. else
  186. maybebadio(outl, port);
  187. }
  188. void hs7751rvoip_insb(unsigned long port, void *addr, unsigned long count)
  189. {
  190. if (PXSEG(port))
  191. while (count--) *((unsigned char *) addr)++ = *(volatile unsigned char *)port;
  192. #if defined(CONFIG_HS7751RVOIP_CODEC)
  193. else if (codec_port(port))
  194. while (count--) *((unsigned char *) addr)++ = *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE));
  195. #endif
  196. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  197. volatile __u8 *bp = (__u8 *)PCI_IOMAP(port);
  198. while (count--) *((volatile unsigned char *) addr)++ = *bp;
  199. } else {
  200. volatile __u16 *p = (volatile unsigned short *)port2adr(port);
  201. while (count--) *((unsigned char *) addr)++ = *p & 0xff;
  202. }
  203. }
  204. void hs7751rvoip_insw(unsigned long port, void *addr, unsigned long count)
  205. {
  206. volatile __u16 *p;
  207. if (PXSEG(port))
  208. p = (volatile unsigned short *)port;
  209. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  210. p = (volatile unsigned short *)PCI_IOMAP(port);
  211. else
  212. p = (volatile unsigned short *)port2adr(port);
  213. while (count--) *((__u16 *) addr)++ = *p;
  214. }
  215. void hs7751rvoip_insl(unsigned long port, void *addr, unsigned long count)
  216. {
  217. if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  218. volatile __u32 *p = (__u32 *)PCI_IOMAP(port);
  219. while (count--) *((__u32 *) addr)++ = *p;
  220. } else
  221. maybebadio(insl, port);
  222. }
  223. void hs7751rvoip_outsb(unsigned long port, const void *addr, unsigned long count)
  224. {
  225. if (PXSEG(port))
  226. while (count--) *(volatile unsigned char *)port = *((unsigned char *) addr)++;
  227. #if defined(CONFIG_HS7751RVOIP_CODEC)
  228. else if (codec_port(port))
  229. while (count--) *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)) = *((unsigned char *) addr)++;
  230. #endif
  231. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  232. volatile __u8 *bp = (__u8 *)PCI_IOMAP(port);
  233. while (count--) *bp = *((volatile unsigned char *) addr)++;
  234. } else {
  235. volatile __u16 *p = (volatile unsigned short *)port2adr(port);
  236. while (count--) *p = *((unsigned char *) addr)++;
  237. }
  238. }
  239. void hs7751rvoip_outsw(unsigned long port, const void *addr, unsigned long count)
  240. {
  241. volatile __u16 *p;
  242. if (PXSEG(port))
  243. p = (volatile unsigned short *)port;
  244. else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
  245. p = (volatile unsigned short *)PCI_IOMAP(port);
  246. else
  247. p = (volatile unsigned short *)port2adr(port);
  248. while (count--) *p = *((__u16 *) addr)++;
  249. }
  250. void hs7751rvoip_outsl(unsigned long port, const void *addr, unsigned long count)
  251. {
  252. if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
  253. volatile __u32 *p = (__u32 *)PCI_IOMAP(port);
  254. while (count--) *p = *((__u32 *) addr)++;
  255. } else
  256. maybebadio(outsl, port);
  257. }
  258. void *hs7751rvoip_ioremap(unsigned long offset, unsigned long size)
  259. {
  260. if (offset >= 0xfd000000)
  261. return (void *)offset;
  262. else
  263. return (void *)P2SEGADDR(offset);
  264. }
  265. EXPORT_SYMBOL(hs7751rvoip_ioremap);
  266. unsigned long hs7751rvoip_isa_port2addr(unsigned long offset)
  267. {
  268. return port2adr(offset);
  269. }