io_generic.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. *
  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. */
  15. #include <asm/io.h>
  16. #include <asm/machvec.h>
  17. #include <linux/module.h>
  18. #if defined(CONFIG_CPU_SH3)
  19. /* I'm not sure SH7709 has this kind of bug */
  20. #define SH3_PCMCIA_BUG_WORKAROUND 1
  21. #define DUMMY_READ_AREA6 0xba000000
  22. #endif
  23. #define PORT2ADDR(x) (sh_mv.mv_isa_port2addr(x))
  24. unsigned long generic_io_base;
  25. static inline void delay(void)
  26. {
  27. ctrl_inw(0xa0000000);
  28. }
  29. unsigned char generic_inb(unsigned long port)
  30. {
  31. return *(volatile unsigned char*)PORT2ADDR(port);
  32. }
  33. unsigned short generic_inw(unsigned long port)
  34. {
  35. return *(volatile unsigned short*)PORT2ADDR(port);
  36. }
  37. unsigned int generic_inl(unsigned long port)
  38. {
  39. return *(volatile unsigned long*)PORT2ADDR(port);
  40. }
  41. unsigned char generic_inb_p(unsigned long port)
  42. {
  43. unsigned long v = *(volatile unsigned char*)PORT2ADDR(port);
  44. delay();
  45. return v;
  46. }
  47. unsigned short generic_inw_p(unsigned long port)
  48. {
  49. unsigned long v = *(volatile unsigned short*)PORT2ADDR(port);
  50. delay();
  51. return v;
  52. }
  53. unsigned int generic_inl_p(unsigned long port)
  54. {
  55. unsigned long v = *(volatile unsigned long*)PORT2ADDR(port);
  56. delay();
  57. return v;
  58. }
  59. /*
  60. * insb/w/l all read a series of bytes/words/longs from a fixed port
  61. * address. However as the port address doesn't change we only need to
  62. * convert the port address to real address once.
  63. */
  64. void generic_insb(unsigned long port, void *buffer, unsigned long count)
  65. {
  66. volatile unsigned char *port_addr;
  67. unsigned char *buf=buffer;
  68. port_addr = (volatile unsigned char *)PORT2ADDR(port);
  69. while(count--)
  70. *buf++ = *port_addr;
  71. }
  72. void generic_insw(unsigned long port, void *buffer, unsigned long count)
  73. {
  74. volatile unsigned short *port_addr;
  75. unsigned short *buf=buffer;
  76. port_addr = (volatile unsigned short *)PORT2ADDR(port);
  77. while(count--)
  78. *buf++ = *port_addr;
  79. #ifdef SH3_PCMCIA_BUG_WORKAROUND
  80. ctrl_inb (DUMMY_READ_AREA6);
  81. #endif
  82. }
  83. void generic_insl(unsigned long port, void *buffer, unsigned long count)
  84. {
  85. volatile unsigned long *port_addr;
  86. unsigned long *buf=buffer;
  87. port_addr = (volatile unsigned long *)PORT2ADDR(port);
  88. while(count--)
  89. *buf++ = *port_addr;
  90. #ifdef SH3_PCMCIA_BUG_WORKAROUND
  91. ctrl_inb (DUMMY_READ_AREA6);
  92. #endif
  93. }
  94. void generic_outb(unsigned char b, unsigned long port)
  95. {
  96. *(volatile unsigned char*)PORT2ADDR(port) = b;
  97. }
  98. void generic_outw(unsigned short b, unsigned long port)
  99. {
  100. *(volatile unsigned short*)PORT2ADDR(port) = b;
  101. }
  102. void generic_outl(unsigned int b, unsigned long port)
  103. {
  104. *(volatile unsigned long*)PORT2ADDR(port) = b;
  105. }
  106. void generic_outb_p(unsigned char b, unsigned long port)
  107. {
  108. *(volatile unsigned char*)PORT2ADDR(port) = b;
  109. delay();
  110. }
  111. void generic_outw_p(unsigned short b, unsigned long port)
  112. {
  113. *(volatile unsigned short*)PORT2ADDR(port) = b;
  114. delay();
  115. }
  116. void generic_outl_p(unsigned int b, unsigned long port)
  117. {
  118. *(volatile unsigned long*)PORT2ADDR(port) = b;
  119. delay();
  120. }
  121. /*
  122. * outsb/w/l all write a series of bytes/words/longs to a fixed port
  123. * address. However as the port address doesn't change we only need to
  124. * convert the port address to real address once.
  125. */
  126. void generic_outsb(unsigned long port, const void *buffer, unsigned long count)
  127. {
  128. volatile unsigned char *port_addr;
  129. const unsigned char *buf=buffer;
  130. port_addr = (volatile unsigned char *)PORT2ADDR(port);
  131. while(count--)
  132. *port_addr = *buf++;
  133. }
  134. void generic_outsw(unsigned long port, const void *buffer, unsigned long count)
  135. {
  136. volatile unsigned short *port_addr;
  137. const unsigned short *buf=buffer;
  138. port_addr = (volatile unsigned short *)PORT2ADDR(port);
  139. while(count--)
  140. *port_addr = *buf++;
  141. #ifdef SH3_PCMCIA_BUG_WORKAROUND
  142. ctrl_inb (DUMMY_READ_AREA6);
  143. #endif
  144. }
  145. void generic_outsl(unsigned long port, const void *buffer, unsigned long count)
  146. {
  147. volatile unsigned long *port_addr;
  148. const unsigned long *buf=buffer;
  149. port_addr = (volatile unsigned long *)PORT2ADDR(port);
  150. while(count--)
  151. *port_addr = *buf++;
  152. #ifdef SH3_PCMCIA_BUG_WORKAROUND
  153. ctrl_inb (DUMMY_READ_AREA6);
  154. #endif
  155. }
  156. unsigned char generic_readb(unsigned long addr)
  157. {
  158. return *(volatile unsigned char*)addr;
  159. }
  160. unsigned short generic_readw(unsigned long addr)
  161. {
  162. return *(volatile unsigned short*)addr;
  163. }
  164. unsigned int generic_readl(unsigned long addr)
  165. {
  166. return *(volatile unsigned long*)addr;
  167. }
  168. void generic_writeb(unsigned char b, unsigned long addr)
  169. {
  170. *(volatile unsigned char*)addr = b;
  171. }
  172. void generic_writew(unsigned short b, unsigned long addr)
  173. {
  174. *(volatile unsigned short*)addr = b;
  175. }
  176. void generic_writel(unsigned int b, unsigned long addr)
  177. {
  178. *(volatile unsigned long*)addr = b;
  179. }
  180. void * generic_ioremap(unsigned long offset, unsigned long size)
  181. {
  182. return (void *) P2SEGADDR(offset);
  183. }
  184. EXPORT_SYMBOL(generic_ioremap);
  185. void generic_iounmap(void *addr)
  186. {
  187. }
  188. EXPORT_SYMBOL(generic_iounmap);
  189. unsigned long generic_isa_port2addr(unsigned long offset)
  190. {
  191. return offset + generic_io_base;
  192. }