io_generic.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. #ifdef CONFIG_CPU_SH3
  18. /* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
  19. * workaround. */
  20. /* I'm not sure SH7709 has this kind of bug */
  21. #define dummy_read() ctrl_inb(0xba000000)
  22. #else
  23. #define dummy_read()
  24. #endif
  25. unsigned long generic_io_base;
  26. static inline void delay(void)
  27. {
  28. ctrl_inw(0xa0000000);
  29. }
  30. u8 generic_inb(unsigned long port)
  31. {
  32. return ctrl_inb((unsigned long __force)__ioport_map(port, 1));
  33. }
  34. u16 generic_inw(unsigned long port)
  35. {
  36. return ctrl_inw((unsigned long __force)__ioport_map(port, 2));
  37. }
  38. u32 generic_inl(unsigned long port)
  39. {
  40. return ctrl_inl((unsigned long __force)__ioport_map(port, 4));
  41. }
  42. u8 generic_inb_p(unsigned long port)
  43. {
  44. unsigned long v = generic_inb(port);
  45. delay();
  46. return v;
  47. }
  48. u16 generic_inw_p(unsigned long port)
  49. {
  50. unsigned long v = generic_inw(port);
  51. delay();
  52. return v;
  53. }
  54. u32 generic_inl_p(unsigned long port)
  55. {
  56. unsigned long v = generic_inl(port);
  57. delay();
  58. return v;
  59. }
  60. /*
  61. * insb/w/l all read a series of bytes/words/longs from a fixed port
  62. * address. However as the port address doesn't change we only need to
  63. * convert the port address to real address once.
  64. */
  65. void generic_insb(unsigned long port, void *dst, unsigned long count)
  66. {
  67. volatile u8 *port_addr;
  68. u8 *buf = dst;
  69. port_addr = (volatile u8 *)__ioport_map(port, 1);
  70. while (count--)
  71. *buf++ = *port_addr;
  72. }
  73. void generic_insw(unsigned long port, void *dst, unsigned long count)
  74. {
  75. volatile u16 *port_addr;
  76. u16 *buf = dst;
  77. port_addr = (volatile u16 *)__ioport_map(port, 2);
  78. while (count--)
  79. *buf++ = *port_addr;
  80. dummy_read();
  81. }
  82. void generic_insl(unsigned long port, void *dst, unsigned long count)
  83. {
  84. volatile u32 *port_addr;
  85. u32 *buf = dst;
  86. port_addr = (volatile u32 *)__ioport_map(port, 4);
  87. while (count--)
  88. *buf++ = *port_addr;
  89. dummy_read();
  90. }
  91. void generic_outb(u8 b, unsigned long port)
  92. {
  93. ctrl_outb(b, (unsigned long __force)__ioport_map(port, 1));
  94. }
  95. void generic_outw(u16 b, unsigned long port)
  96. {
  97. ctrl_outw(b, (unsigned long __force)__ioport_map(port, 2));
  98. }
  99. void generic_outl(u32 b, unsigned long port)
  100. {
  101. ctrl_outl(b, (unsigned long __force)__ioport_map(port, 4));
  102. }
  103. void generic_outb_p(u8 b, unsigned long port)
  104. {
  105. generic_outb(b, port);
  106. delay();
  107. }
  108. void generic_outw_p(u16 b, unsigned long port)
  109. {
  110. generic_outw(b, port);
  111. delay();
  112. }
  113. void generic_outl_p(u32 b, unsigned long port)
  114. {
  115. generic_outl(b, port);
  116. delay();
  117. }
  118. /*
  119. * outsb/w/l all write a series of bytes/words/longs to a fixed port
  120. * address. However as the port address doesn't change we only need to
  121. * convert the port address to real address once.
  122. */
  123. void generic_outsb(unsigned long port, const void *src, unsigned long count)
  124. {
  125. volatile u8 *port_addr;
  126. const u8 *buf = src;
  127. port_addr = (volatile u8 __force *)__ioport_map(port, 1);
  128. while (count--)
  129. *port_addr = *buf++;
  130. }
  131. void generic_outsw(unsigned long port, const void *src, unsigned long count)
  132. {
  133. volatile u16 *port_addr;
  134. const u16 *buf = src;
  135. port_addr = (volatile u16 __force *)__ioport_map(port, 2);
  136. while (count--)
  137. *port_addr = *buf++;
  138. dummy_read();
  139. }
  140. void generic_outsl(unsigned long port, const void *src, unsigned long count)
  141. {
  142. volatile u32 *port_addr;
  143. const u32 *buf = src;
  144. port_addr = (volatile u32 __force *)__ioport_map(port, 4);
  145. while (count--)
  146. *port_addr = *buf++;
  147. dummy_read();
  148. }
  149. u8 generic_readb(void __iomem *addr)
  150. {
  151. return ctrl_inb((unsigned long __force)addr);
  152. }
  153. u16 generic_readw(void __iomem *addr)
  154. {
  155. return ctrl_inw((unsigned long __force)addr);
  156. }
  157. u32 generic_readl(void __iomem *addr)
  158. {
  159. return ctrl_inl((unsigned long __force)addr);
  160. }
  161. void generic_writeb(u8 b, void __iomem *addr)
  162. {
  163. ctrl_outb(b, (unsigned long __force)addr);
  164. }
  165. void generic_writew(u16 b, void __iomem *addr)
  166. {
  167. ctrl_outw(b, (unsigned long __force)addr);
  168. }
  169. void generic_writel(u32 b, void __iomem *addr)
  170. {
  171. ctrl_outl(b, (unsigned long __force)addr);
  172. }
  173. void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
  174. {
  175. return (void __iomem *)(addr + generic_io_base);
  176. }
  177. void generic_ioport_unmap(void __iomem *addr)
  178. {
  179. }