io.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * linux/arch/m32r/platforms/usrv/io.c
  3. *
  4. * Typical I/O routines for uServer board.
  5. *
  6. * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
  7. * Hitoshi Yamamoto, Takeo Takahashi
  8. *
  9. * This file is subject to the terms and conditions of the GNU General
  10. * Public License. See the file "COPYING" in the main directory of this
  11. * archive for more details.
  12. *
  13. */
  14. #include <asm/m32r.h>
  15. #include <asm/page.h>
  16. #include <asm/io.h>
  17. #include <linux/types.h>
  18. #include "../../../../drivers/pcmcia/m32r_cfc.h"
  19. extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
  20. extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
  21. extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
  22. extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
  23. #define CFC_IOSTART CFC_IOPORT_BASE
  24. #define CFC_IOEND (CFC_IOSTART + (M32R_PCC_MAPSIZE * M32R_MAX_PCC) - 1)
  25. #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
  26. #define UART0_REGSTART 0x04c20000
  27. #define UART1_REGSTART 0x04c20100
  28. #define UART_IOMAP_SIZE 8
  29. #define UART0_IOSTART 0x3f8
  30. #define UART0_IOEND (UART0_IOSTART + UART_IOMAP_SIZE - 1)
  31. #define UART1_IOSTART 0x2f8
  32. #define UART1_IOEND (UART1_IOSTART + UART_IOMAP_SIZE - 1)
  33. #endif /* CONFIG_SERIAL_8250 || CONFIG_SERIAL_8250_MODULE */
  34. #define PORT2ADDR(port) _port2addr(port)
  35. static inline void *_port2addr(unsigned long port)
  36. {
  37. #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
  38. if (port >= UART0_IOSTART && port <= UART0_IOEND)
  39. port = ((port - UART0_IOSTART) << 1) + UART0_REGSTART;
  40. else if (port >= UART1_IOSTART && port <= UART1_IOEND)
  41. port = ((port - UART1_IOSTART) << 1) + UART1_REGSTART;
  42. #endif /* CONFIG_SERIAL_8250 || CONFIG_SERIAL_8250_MODULE */
  43. return (void *)(port | (NONCACHE_OFFSET));
  44. }
  45. static inline void delay(void)
  46. {
  47. __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
  48. }
  49. unsigned char _inb(unsigned long port)
  50. {
  51. if (port >= CFC_IOSTART && port <= CFC_IOEND) {
  52. unsigned char b;
  53. pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
  54. return b;
  55. } else
  56. return *(volatile unsigned char *)PORT2ADDR(port);
  57. }
  58. unsigned short _inw(unsigned long port)
  59. {
  60. if (port >= CFC_IOSTART && port <= CFC_IOEND) {
  61. unsigned short w;
  62. pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
  63. return w;
  64. } else
  65. return *(volatile unsigned short *)PORT2ADDR(port);
  66. }
  67. unsigned long _inl(unsigned long port)
  68. {
  69. if (port >= CFC_IOSTART && port <= CFC_IOEND) {
  70. unsigned long l;
  71. pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
  72. return l;
  73. } else
  74. return *(volatile unsigned long *)PORT2ADDR(port);
  75. }
  76. unsigned char _inb_p(unsigned long port)
  77. {
  78. unsigned char v = _inb(port);
  79. delay();
  80. return v;
  81. }
  82. unsigned short _inw_p(unsigned long port)
  83. {
  84. unsigned short v = _inw(port);
  85. delay();
  86. return v;
  87. }
  88. unsigned long _inl_p(unsigned long port)
  89. {
  90. unsigned long v = _inl(port);
  91. delay();
  92. return v;
  93. }
  94. void _outb(unsigned char b, unsigned long port)
  95. {
  96. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  97. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  98. else
  99. *(volatile unsigned char *)PORT2ADDR(port) = b;
  100. }
  101. void _outw(unsigned short w, unsigned long port)
  102. {
  103. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  104. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  105. else
  106. *(volatile unsigned short *)PORT2ADDR(port) = w;
  107. }
  108. void _outl(unsigned long l, unsigned long port)
  109. {
  110. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  111. pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
  112. else
  113. *(volatile unsigned long *)PORT2ADDR(port) = l;
  114. }
  115. void _outb_p(unsigned char b, unsigned long port)
  116. {
  117. _outb(b, port);
  118. delay();
  119. }
  120. void _outw_p(unsigned short w, unsigned long port)
  121. {
  122. _outw(w, port);
  123. delay();
  124. }
  125. void _outl_p(unsigned long l, unsigned long port)
  126. {
  127. _outl(l, port);
  128. delay();
  129. }
  130. void _insb(unsigned int port, void * addr, unsigned long count)
  131. {
  132. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  133. pcc_ioread_byte(0, port, addr, sizeof(unsigned char), count, 1);
  134. else {
  135. unsigned char *buf = addr;
  136. unsigned char *portp = PORT2ADDR(port);
  137. while (count--)
  138. *buf++ = *(volatile unsigned char *)portp;
  139. }
  140. }
  141. void _insw(unsigned int port, void * addr, unsigned long count)
  142. {
  143. unsigned short *buf = addr;
  144. unsigned short *portp;
  145. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  146. pcc_ioread_word(0, port, addr, sizeof(unsigned short), count,
  147. 1);
  148. else {
  149. portp = PORT2ADDR(port);
  150. while (count--)
  151. *buf++ = *(volatile unsigned short *)portp;
  152. }
  153. }
  154. void _insl(unsigned int port, void * addr, unsigned long count)
  155. {
  156. unsigned long *buf = addr;
  157. unsigned long *portp;
  158. portp = PORT2ADDR(port);
  159. while (count--)
  160. *buf++ = *(volatile unsigned long *)portp;
  161. }
  162. void _outsb(unsigned int port, const void * addr, unsigned long count)
  163. {
  164. const unsigned char *buf = addr;
  165. unsigned char *portp;
  166. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  167. pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
  168. count, 1);
  169. else {
  170. portp = PORT2ADDR(port);
  171. while (count--)
  172. *(volatile unsigned char *)portp = *buf++;
  173. }
  174. }
  175. void _outsw(unsigned int port, const void * addr, unsigned long count)
  176. {
  177. const unsigned short *buf = addr;
  178. unsigned short *portp;
  179. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  180. pcc_iowrite_word(0, port, (void *)addr, sizeof(unsigned short),
  181. count, 1);
  182. else {
  183. portp = PORT2ADDR(port);
  184. while (count--)
  185. *(volatile unsigned short *)portp = *buf++;
  186. }
  187. }
  188. void _outsl(unsigned int port, const void * addr, unsigned long count)
  189. {
  190. const unsigned long *buf = addr;
  191. unsigned char *portp;
  192. portp = PORT2ADDR(port);
  193. while (count--)
  194. *(volatile unsigned long *)portp = *buf++;
  195. }