io.c 9.1 KB

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