io_7751se.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:8k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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/hitachi_7751se.h>
  17. #include <asm/addrspace.h>
  18. #include <linux/pci.h>
  19. #include <asm/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%08xn", 
  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_SH_7751_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_insb(unsigned long port, void *addr, unsigned long count)
  182. {
  183. unsigned char *p = addr;
  184. while (count--) *p++ = sh7751se_inb(port);
  185. }
  186. void sh7751se_insw(unsigned long port, void *addr, unsigned long count)
  187. {
  188. unsigned short *p = addr;
  189. while (count--) *p++ = sh7751se_inw(port);
  190. }
  191. void sh7751se_insl(unsigned long port, void *addr, unsigned long count)
  192. {
  193. maybebadio(insl, port);
  194. }
  195. void sh7751se_outsb(unsigned long port, const void *addr, unsigned long count)
  196. {
  197. unsigned char *p = (unsigned char*)addr;
  198. while (count--) sh7751se_outb(*p++, port);
  199. }
  200. void sh7751se_outsw(unsigned long port, const void *addr, unsigned long count)
  201. {
  202. unsigned short *p = (unsigned short*)addr;
  203. while (count--) sh7751se_outw(*p++, port);
  204. }
  205. void sh7751se_outsl(unsigned long port, const void *addr, unsigned long count)
  206. {
  207. maybebadio(outsw, port);
  208. }
  209. /* For read/write calls, just copy generic (pass-thru); PCIMBR is  */
  210. /* already set up.  For a larger memory space, these would need to */
  211. /* reset PCIMBR as needed on a per-call basis...                   */
  212. unsigned char sh7751se_readb(unsigned long addr)
  213. {
  214. return *(volatile unsigned char*)addr;
  215. }
  216. unsigned short sh7751se_readw(unsigned long addr)
  217. {
  218. return *(volatile unsigned short*)addr;
  219. }
  220. unsigned int sh7751se_readl(unsigned long addr)
  221. {
  222. return *(volatile unsigned long*)addr;
  223. }
  224. void sh7751se_writeb(unsigned char b, unsigned long addr)
  225. {
  226. *(volatile unsigned char*)addr = b;
  227. }
  228. void sh7751se_writew(unsigned short b, unsigned long addr)
  229. {
  230. *(volatile unsigned short*)addr = b;
  231. }
  232. void sh7751se_writel(unsigned int b, unsigned long addr)
  233. {
  234.         *(volatile unsigned long*)addr = b;
  235. }
  236. /* Map ISA bus address to the real address. Only for PCMCIA.  */
  237. /* ISA page descriptor.  */
  238. static __u32 sh_isa_memmap[256];
  239. #if 0
  240. static int
  241. sh_isa_mmap(__u32 start, __u32 length, __u32 offset)
  242. {
  243. int idx;
  244. if (start >= 0x100000 || (start & 0xfff) || (length != 0x1000))
  245. return -1;
  246. idx = start >> 12;
  247. sh_isa_memmap[idx] = 0xb8000000 + (offset &~ 0xfff);
  248. printk("sh_isa_mmap: start %x len %x offset %x (idx %x paddr %x)n",
  249.        start, length, offset, idx, sh_isa_memmap[idx]);
  250. return 0;
  251. }
  252. #endif
  253. unsigned long
  254. sh7751se_isa_port2addr(unsigned long offset)
  255. {
  256. int idx;
  257. idx = (offset >> 12) & 0xff;
  258. offset &= 0xfff;
  259. return sh_isa_memmap[idx] + offset;
  260. }