io.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * arch/sh/boards/landisk/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 I-O Data Device, Inc. LANDISK.
  8. *
  9. * Initial version only to support LAN access; some
  10. * placeholder code from io_landisk.c left in with the
  11. * expectation of later SuperIO and PCMCIA access.
  12. */
  13. /*
  14. * modifed by kogiidena
  15. * 2005.03.03
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/types.h>
  19. #include <linux/pci.h>
  20. #include <asm/landisk/iodata_landisk.h>
  21. #include <asm/addrspace.h>
  22. #include <asm/io.h>
  23. extern void *area5_io_base; /* Area 5 I/O Base address */
  24. extern void *area6_io_base; /* Area 6 I/O Base address */
  25. static inline unsigned long port2adr(unsigned int port)
  26. {
  27. if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
  28. if (port == 0x3f6)
  29. return ((unsigned long)area5_io_base + 0x2c);
  30. else
  31. return ((unsigned long)area5_io_base + PA_PIDE_OFFSET +
  32. ((port - 0x1f0) << 1));
  33. else if ((0x170 <= port && port < 0x178) || port == 0x376)
  34. if (port == 0x376)
  35. return ((unsigned long)area6_io_base + 0x2c);
  36. else
  37. return ((unsigned long)area6_io_base + PA_SIDE_OFFSET +
  38. ((port - 0x170) << 1));
  39. else
  40. maybebadio((unsigned long)port);
  41. return port;
  42. }
  43. /*
  44. * General outline: remap really low stuff [eventually] to SuperIO,
  45. * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
  46. * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
  47. * should be way beyond the window, and is used w/o translation for
  48. * compatibility.
  49. */
  50. u8 landisk_inb(unsigned long port)
  51. {
  52. if (PXSEG(port))
  53. return ctrl_inb(port);
  54. else if (is_pci_ioaddr(port))
  55. return ctrl_inb(pci_ioaddr(port));
  56. return ctrl_inw(port2adr(port)) & 0xff;
  57. }
  58. u8 landisk_inb_p(unsigned long port)
  59. {
  60. u8 v;
  61. if (PXSEG(port))
  62. v = ctrl_inb(port);
  63. else if (is_pci_ioaddr(port))
  64. v = ctrl_inb(pci_ioaddr(port));
  65. else
  66. v = ctrl_inw(port2adr(port)) & 0xff;
  67. ctrl_delay();
  68. return v;
  69. }
  70. u16 landisk_inw(unsigned long port)
  71. {
  72. if (PXSEG(port))
  73. return ctrl_inw(port);
  74. else if (is_pci_ioaddr(port))
  75. return ctrl_inw(pci_ioaddr(port));
  76. else
  77. maybebadio(port);
  78. return 0;
  79. }
  80. u32 landisk_inl(unsigned long port)
  81. {
  82. if (PXSEG(port))
  83. return ctrl_inl(port);
  84. else if (is_pci_ioaddr(port))
  85. return ctrl_inl(pci_ioaddr(port));
  86. else
  87. maybebadio(port);
  88. return 0;
  89. }
  90. void landisk_outb(u8 value, unsigned long port)
  91. {
  92. if (PXSEG(port))
  93. ctrl_outb(value, port);
  94. else if (is_pci_ioaddr(port))
  95. ctrl_outb(value, pci_ioaddr(port));
  96. else
  97. ctrl_outw(value, port2adr(port));
  98. }
  99. void landisk_outb_p(u8 value, unsigned long port)
  100. {
  101. if (PXSEG(port))
  102. ctrl_outb(value, port);
  103. else if (is_pci_ioaddr(port))
  104. ctrl_outb(value, pci_ioaddr(port));
  105. else
  106. ctrl_outw(value, port2adr(port));
  107. ctrl_delay();
  108. }
  109. void landisk_outw(u16 value, unsigned long port)
  110. {
  111. if (PXSEG(port))
  112. ctrl_outw(value, port);
  113. else if (is_pci_ioaddr(port))
  114. ctrl_outw(value, pci_ioaddr(port));
  115. else
  116. maybebadio(port);
  117. }
  118. void landisk_outl(u32 value, unsigned long port)
  119. {
  120. if (PXSEG(port))
  121. ctrl_outl(value, port);
  122. else if (is_pci_ioaddr(port))
  123. ctrl_outl(value, pci_ioaddr(port));
  124. else
  125. maybebadio(port);
  126. }
  127. void landisk_insb(unsigned long port, void *dst, unsigned long count)
  128. {
  129. volatile u16 *p;
  130. u8 *buf = dst;
  131. if (PXSEG(port)) {
  132. while (count--)
  133. *buf++ = *(volatile u8 *)port;
  134. } else if (is_pci_ioaddr(port)) {
  135. volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
  136. while (count--)
  137. *buf++ = *bp;
  138. } else {
  139. p = (volatile u16 *)port2adr(port);
  140. while (count--)
  141. *buf++ = *p & 0xff;
  142. }
  143. }
  144. void landisk_insw(unsigned long port, void *dst, unsigned long count)
  145. {
  146. volatile u16 *p;
  147. u16 *buf = dst;
  148. if (PXSEG(port))
  149. p = (volatile u16 *)port;
  150. else if (is_pci_ioaddr(port))
  151. p = (volatile u16 *)pci_ioaddr(port);
  152. else
  153. p = (volatile u16 *)port2adr(port);
  154. while (count--)
  155. *buf++ = *p;
  156. }
  157. void landisk_insl(unsigned long port, void *dst, unsigned long count)
  158. {
  159. u32 *buf = dst;
  160. if (is_pci_ioaddr(port)) {
  161. volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
  162. while (count--)
  163. *buf++ = *p;
  164. } else
  165. maybebadio(port);
  166. }
  167. void landisk_outsb(unsigned long port, const void *src, unsigned long count)
  168. {
  169. volatile u16 *p;
  170. const u8 *buf = src;
  171. if (PXSEG(port))
  172. while (count--)
  173. ctrl_outb(*buf++, port);
  174. else if (is_pci_ioaddr(port)) {
  175. volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
  176. while (count--)
  177. *bp = *buf++;
  178. } else {
  179. p = (volatile u16 *)port2adr(port);
  180. while (count--)
  181. *p = *buf++;
  182. }
  183. }
  184. void landisk_outsw(unsigned long port, const void *src, unsigned long count)
  185. {
  186. volatile u16 *p;
  187. const u16 *buf = src;
  188. if (PXSEG(port))
  189. p = (volatile u16 *)port;
  190. else if (is_pci_ioaddr(port))
  191. p = (volatile u16 *)pci_ioaddr(port);
  192. else
  193. p = (volatile u16 *)port2adr(port);
  194. while (count--)
  195. *p = *buf++;
  196. }
  197. void landisk_outsl(unsigned long port, const void *src, unsigned long count)
  198. {
  199. const u32 *buf = src;
  200. if (is_pci_ioaddr(port)) {
  201. volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
  202. while (count--)
  203. *p = *buf++;
  204. } else
  205. maybebadio(port);
  206. }
  207. void __iomem *landisk_ioport_map(unsigned long port, unsigned int size)
  208. {
  209. if (PXSEG(port))
  210. return (void __iomem *)port;
  211. else if (is_pci_ioaddr(port))
  212. return (void __iomem *)pci_ioaddr(port);
  213. return (void __iomem *)port2adr(port);
  214. }