io_usrv.c 6.2 KB

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