io_generic.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * arch/sh/kernel/io_generic.c
  3. *
  4. * Copyright (C) 2000 Niibe Yutaka
  5. * Copyright (C) 2005 - 2007 Paul Mundt
  6. *
  7. * Generic I/O routine. These can be used where a machine specific version
  8. * is not required.
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file "COPYING" in the main directory of this archive
  12. * for more details.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/io.h>
  16. #include <asm/machvec.h>
  17. #include <asm/cacheflush.h>
  18. #ifdef CONFIG_CPU_SH3
  19. /* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
  20. * workaround. */
  21. /* I'm not sure SH7709 has this kind of bug */
  22. #define dummy_read() ctrl_inb(0xba000000)
  23. #else
  24. #define dummy_read()
  25. #endif
  26. unsigned long generic_io_base;
  27. static inline void delay(void)
  28. {
  29. ctrl_inw(0xa0000000);
  30. }
  31. u8 generic_inb(unsigned long port)
  32. {
  33. return ctrl_inb((unsigned long __force)ioport_map(port, 1));
  34. }
  35. u16 generic_inw(unsigned long port)
  36. {
  37. return ctrl_inw((unsigned long __force)ioport_map(port, 2));
  38. }
  39. u32 generic_inl(unsigned long port)
  40. {
  41. return ctrl_inl((unsigned long __force)ioport_map(port, 4));
  42. }
  43. u8 generic_inb_p(unsigned long port)
  44. {
  45. unsigned long v = generic_inb(port);
  46. delay();
  47. return v;
  48. }
  49. u16 generic_inw_p(unsigned long port)
  50. {
  51. unsigned long v = generic_inw(port);
  52. delay();
  53. return v;
  54. }
  55. u32 generic_inl_p(unsigned long port)
  56. {
  57. unsigned long v = generic_inl(port);
  58. delay();
  59. return v;
  60. }
  61. /*
  62. * insb/w/l all read a series of bytes/words/longs from a fixed port
  63. * address. However as the port address doesn't change we only need to
  64. * convert the port address to real address once.
  65. */
  66. void generic_insb(unsigned long port, void *dst, unsigned long count)
  67. {
  68. volatile u8 *port_addr;
  69. u8 *buf = dst;
  70. port_addr = (volatile u8 *)ioport_map(port, 1);
  71. while (count--)
  72. *buf++ = *port_addr;
  73. }
  74. void generic_insw(unsigned long port, void *dst, unsigned long count)
  75. {
  76. volatile u16 *port_addr;
  77. u16 *buf = dst;
  78. port_addr = (volatile u16 *)ioport_map(port, 2);
  79. while (count--)
  80. *buf++ = *port_addr;
  81. flush_dcache_all();
  82. dummy_read();
  83. }
  84. void generic_insl(unsigned long port, void *dst, unsigned long count)
  85. {
  86. volatile u32 *port_addr;
  87. u32 *buf = dst;
  88. port_addr = (volatile u32 *)ioport_map(port, 4);
  89. while (count--)
  90. *buf++ = *port_addr;
  91. dummy_read();
  92. }
  93. void generic_outb(u8 b, unsigned long port)
  94. {
  95. ctrl_outb(b, (unsigned long __force)ioport_map(port, 1));
  96. }
  97. void generic_outw(u16 b, unsigned long port)
  98. {
  99. ctrl_outw(b, (unsigned long __force)ioport_map(port, 2));
  100. }
  101. void generic_outl(u32 b, unsigned long port)
  102. {
  103. ctrl_outl(b, (unsigned long __force)ioport_map(port, 4));
  104. }
  105. void generic_outb_p(u8 b, unsigned long port)
  106. {
  107. generic_outb(b, port);
  108. delay();
  109. }
  110. void generic_outw_p(u16 b, unsigned long port)
  111. {
  112. generic_outw(b, port);
  113. delay();
  114. }
  115. void generic_outl_p(u32 b, unsigned long port)
  116. {
  117. generic_outl(b, port);
  118. delay();
  119. }
  120. /*
  121. * outsb/w/l all write a series of bytes/words/longs to a fixed port
  122. * address. However as the port address doesn't change we only need to
  123. * convert the port address to real address once.
  124. */
  125. void generic_outsb(unsigned long port, const void *src, unsigned long count)
  126. {
  127. volatile u8 *port_addr;
  128. const u8 *buf = src;
  129. port_addr = (volatile u8 __force *)ioport_map(port, 1);
  130. while (count--)
  131. *port_addr = *buf++;
  132. }
  133. void generic_outsw(unsigned long port, const void *src, unsigned long count)
  134. {
  135. volatile u16 *port_addr;
  136. const u16 *buf = src;
  137. port_addr = (volatile u16 __force *)ioport_map(port, 2);
  138. while (count--)
  139. *port_addr = *buf++;
  140. flush_dcache_all();
  141. dummy_read();
  142. }
  143. void generic_outsl(unsigned long port, const void *src, unsigned long count)
  144. {
  145. volatile u32 *port_addr;
  146. const u32 *buf = src;
  147. port_addr = (volatile u32 __force *)ioport_map(port, 4);
  148. while (count--)
  149. *port_addr = *buf++;
  150. dummy_read();
  151. }
  152. u8 generic_readb(void __iomem *addr)
  153. {
  154. return ctrl_inb((unsigned long __force)addr);
  155. }
  156. u16 generic_readw(void __iomem *addr)
  157. {
  158. return ctrl_inw((unsigned long __force)addr);
  159. }
  160. u32 generic_readl(void __iomem *addr)
  161. {
  162. return ctrl_inl((unsigned long __force)addr);
  163. }
  164. void generic_writeb(u8 b, void __iomem *addr)
  165. {
  166. ctrl_outb(b, (unsigned long __force)addr);
  167. }
  168. void generic_writew(u16 b, void __iomem *addr)
  169. {
  170. ctrl_outw(b, (unsigned long __force)addr);
  171. }
  172. void generic_writel(u32 b, void __iomem *addr)
  173. {
  174. ctrl_outl(b, (unsigned long __force)addr);
  175. }
  176. void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
  177. {
  178. return (void __iomem *)(addr + generic_io_base);
  179. }
  180. void generic_ioport_unmap(void __iomem *addr)
  181. {
  182. }