io_generic.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* $Id: io_generic.c,v 1.2 2003/05/04 19:29:53 lethal Exp $
  2. *
  3. * linux/arch/sh/kernel/io_generic.c
  4. *
  5. * Copyright (C) 2000 Niibe Yutaka
  6. * Copyright (C) 2005 Paul Mundt
  7. *
  8. * Generic I/O routine. These can be used where a machine specific version
  9. * is not required.
  10. *
  11. * This file is subject to the terms and conditions of the GNU General Public
  12. * License. See the file "COPYING" in the main directory of this archive
  13. * for more details.
  14. */
  15. #include <linux/module.h>
  16. #include <asm/io.h>
  17. #include <asm/machvec.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. dummy_read();
  82. }
  83. void generic_insl(unsigned long port, void *dst, unsigned long count)
  84. {
  85. volatile u32 *port_addr;
  86. u32 *buf = dst;
  87. port_addr = (volatile u32 *)ioport_map(port, 4);
  88. while (count--)
  89. *buf++ = *port_addr;
  90. dummy_read();
  91. }
  92. void generic_outb(u8 b, unsigned long port)
  93. {
  94. ctrl_outb(b, (unsigned long __force)ioport_map(port, 1));
  95. }
  96. void generic_outw(u16 b, unsigned long port)
  97. {
  98. ctrl_outw(b, (unsigned long __force)ioport_map(port, 2));
  99. }
  100. void generic_outl(u32 b, unsigned long port)
  101. {
  102. ctrl_outl(b, (unsigned long __force)ioport_map(port, 4));
  103. }
  104. void generic_outb_p(u8 b, unsigned long port)
  105. {
  106. generic_outb(b, port);
  107. delay();
  108. }
  109. void generic_outw_p(u16 b, unsigned long port)
  110. {
  111. generic_outw(b, port);
  112. delay();
  113. }
  114. void generic_outl_p(u32 b, unsigned long port)
  115. {
  116. generic_outl(b, port);
  117. delay();
  118. }
  119. /*
  120. * outsb/w/l all write a series of bytes/words/longs to a fixed port
  121. * address. However as the port address doesn't change we only need to
  122. * convert the port address to real address once.
  123. */
  124. void generic_outsb(unsigned long port, const void *src, unsigned long count)
  125. {
  126. volatile u8 *port_addr;
  127. const u8 *buf = src;
  128. port_addr = (volatile u8 __force *)ioport_map(port, 1);
  129. while (count--)
  130. *port_addr = *buf++;
  131. }
  132. void generic_outsw(unsigned long port, const void *src, unsigned long count)
  133. {
  134. volatile u16 *port_addr;
  135. const u16 *buf = src;
  136. port_addr = (volatile u16 __force *)ioport_map(port, 2);
  137. while (count--)
  138. *port_addr = *buf++;
  139. dummy_read();
  140. }
  141. void generic_outsl(unsigned long port, const void *src, unsigned long count)
  142. {
  143. volatile u32 *port_addr;
  144. const u32 *buf = src;
  145. port_addr = (volatile u32 __force *)ioport_map(port, 4);
  146. while (count--)
  147. *port_addr = *buf++;
  148. dummy_read();
  149. }
  150. u8 generic_readb(void __iomem *addr)
  151. {
  152. return ctrl_inb((unsigned long __force)addr);
  153. }
  154. u16 generic_readw(void __iomem *addr)
  155. {
  156. return ctrl_inw((unsigned long __force)addr);
  157. }
  158. u32 generic_readl(void __iomem *addr)
  159. {
  160. return ctrl_inl((unsigned long __force)addr);
  161. }
  162. void generic_writeb(u8 b, void __iomem *addr)
  163. {
  164. ctrl_outb(b, (unsigned long __force)addr);
  165. }
  166. void generic_writew(u16 b, void __iomem *addr)
  167. {
  168. ctrl_outw(b, (unsigned long __force)addr);
  169. }
  170. void generic_writel(u32 b, void __iomem *addr)
  171. {
  172. ctrl_outl(b, (unsigned long __force)addr);
  173. }
  174. void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
  175. {
  176. return (void __iomem *)(addr + generic_io_base);
  177. }
  178. void generic_ioport_unmap(void __iomem *addr)
  179. {
  180. }