io_usrv.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * linux/arch/m32r/kernel/io_usrv.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 <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 v = _inb(port);
  80. delay();
  81. return v;
  82. }
  83. unsigned short _inw_p(unsigned long port)
  84. {
  85. unsigned short v = _inw(port);
  86. delay();
  87. return v;
  88. }
  89. unsigned long _inl_p(unsigned long port)
  90. {
  91. unsigned long v = _inl(port);
  92. delay();
  93. return v;
  94. }
  95. void _outb(unsigned char b, unsigned long port)
  96. {
  97. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  98. pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
  99. else
  100. *(volatile unsigned char *)PORT2ADDR(port) = b;
  101. }
  102. void _outw(unsigned short w, unsigned long port)
  103. {
  104. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  105. pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
  106. else
  107. *(volatile unsigned short *)PORT2ADDR(port) = w;
  108. }
  109. void _outl(unsigned long l, unsigned long port)
  110. {
  111. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  112. pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
  113. else
  114. *(volatile unsigned long *)PORT2ADDR(port) = l;
  115. }
  116. void _outb_p(unsigned char b, unsigned long port)
  117. {
  118. _outb(b, port);
  119. delay();
  120. }
  121. void _outw_p(unsigned short w, unsigned long port)
  122. {
  123. _outw(w, port);
  124. delay();
  125. }
  126. void _outl_p(unsigned long l, unsigned long port)
  127. {
  128. _outl(l, port);
  129. delay();
  130. }
  131. void _insb(unsigned int port, void * addr, unsigned long count)
  132. {
  133. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  134. pcc_ioread_byte(0, port, addr, sizeof(unsigned char), count, 1);
  135. else {
  136. unsigned char *buf = addr;
  137. unsigned char *portp = PORT2ADDR(port);
  138. while (count--)
  139. *buf++ = *(volatile unsigned char *)portp;
  140. }
  141. }
  142. void _insw(unsigned int port, void * addr, unsigned long count)
  143. {
  144. unsigned short *buf = addr;
  145. unsigned short *portp;
  146. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  147. pcc_ioread_word(0, port, addr, sizeof(unsigned short), count,
  148. 1);
  149. else {
  150. portp = PORT2ADDR(port);
  151. while (count--)
  152. *buf++ = *(volatile unsigned short *)portp;
  153. }
  154. }
  155. void _insl(unsigned int port, void * addr, unsigned long count)
  156. {
  157. unsigned long *buf = addr;
  158. unsigned long *portp;
  159. portp = PORT2ADDR(port);
  160. while (count--)
  161. *buf++ = *(volatile unsigned long *)portp;
  162. }
  163. void _outsb(unsigned int port, const void * addr, unsigned long count)
  164. {
  165. const unsigned char *buf = addr;
  166. unsigned char *portp;
  167. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  168. pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
  169. count, 1);
  170. else {
  171. portp = PORT2ADDR(port);
  172. while (count--)
  173. *(volatile unsigned char *)portp = *buf++;
  174. }
  175. }
  176. void _outsw(unsigned int port, const void * addr, unsigned long count)
  177. {
  178. const unsigned short *buf = addr;
  179. unsigned short *portp;
  180. if (port >= CFC_IOSTART && port <= CFC_IOEND)
  181. pcc_iowrite_word(0, port, (void *)addr, sizeof(unsigned short),
  182. count, 1);
  183. else {
  184. portp = PORT2ADDR(port);
  185. while (count--)
  186. *(volatile unsigned short *)portp = *buf++;
  187. }
  188. }
  189. void _outsl(unsigned int port, const void * addr, unsigned long count)
  190. {
  191. const unsigned long *buf = addr;
  192. unsigned char *portp;
  193. portp = PORT2ADDR(port);
  194. while (count--)
  195. *(volatile unsigned long *)portp = *buf++;
  196. }