io_adx.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:4k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /* 
  2.  * linux/arch/sh/kernel/io_adx.c
  3.  *
  4.  * Copyright (C) 2001 A&D Co., Ltd.
  5.  *
  6.  * I/O routine and setup routines for A&D ADX Board
  7.  *
  8.  * This file is subject to the terms and conditions of the GNU General Public
  9.  * License.  See the file "COPYING" in the main directory of this archive
  10.  * for more details.
  11.  *
  12.  */
  13. #include <asm/io.h>
  14. #include <asm/machvec.h>
  15. #include <linux/module.h>
  16. #define PORT2ADDR(x) (adx_isa_port2addr(x))
  17. static inline void delay(void)
  18. {
  19. ctrl_inw(0xa0000000);
  20. }
  21. unsigned char adx_inb(unsigned long port)
  22. {
  23. return *(volatile unsigned char*)PORT2ADDR(port);
  24. }
  25. unsigned short adx_inw(unsigned long port)
  26. {
  27. return *(volatile unsigned short*)PORT2ADDR(port);
  28. }
  29. unsigned int adx_inl(unsigned long port)
  30. {
  31. return *(volatile unsigned long*)PORT2ADDR(port);
  32. }
  33. unsigned char adx_inb_p(unsigned long port)
  34. {
  35. unsigned long v = *(volatile unsigned char*)PORT2ADDR(port);
  36. delay();
  37. return v;
  38. }
  39. unsigned short adx_inw_p(unsigned long port)
  40. {
  41. unsigned long v = *(volatile unsigned short*)PORT2ADDR(port);
  42. delay();
  43. return v;
  44. }
  45. unsigned int adx_inl_p(unsigned long port)
  46. {
  47. unsigned long v = *(volatile unsigned long*)PORT2ADDR(port);
  48. delay();
  49. return v;
  50. }
  51. void adx_insb(unsigned long port, void *buffer, unsigned long count)
  52. {
  53. unsigned char *buf = buffer;
  54. while(count--) *buf++ = inb(port);
  55. }
  56. void adx_insw(unsigned long port, void *buffer, unsigned long count)
  57. {
  58. unsigned short *buf = buffer;
  59. while(count--) *buf++ = inw(port);
  60. }
  61. void adx_insl(unsigned long port, void *buffer, unsigned long count)
  62. {
  63. unsigned long *buf = buffer;
  64. while(count--) *buf++ = inl(port);
  65. }
  66. void adx_outb(unsigned char b, unsigned long port)
  67. {
  68. *(volatile unsigned char*)PORT2ADDR(port) = b;
  69. }
  70. void adx_outw(unsigned short b, unsigned long port)
  71. {
  72. *(volatile unsigned short*)PORT2ADDR(port) = b;
  73. }
  74. void adx_outl(unsigned int b, unsigned long port)
  75. {
  76. *(volatile unsigned long*)PORT2ADDR(port) = b;
  77. }
  78. void adx_outb_p(unsigned char b, unsigned long port)
  79. {
  80. *(volatile unsigned char*)PORT2ADDR(port) = b;
  81. delay();
  82. }
  83. void adx_outw_p(unsigned short b, unsigned long port)
  84. {
  85. *(volatile unsigned short*)PORT2ADDR(port) = b;
  86. delay();
  87. }
  88. void adx_outl_p(unsigned int b, unsigned long port)
  89. {
  90. *(volatile unsigned long*)PORT2ADDR(port) = b;
  91. delay();
  92. }
  93. void adx_outsb(unsigned long port, const void *buffer, unsigned long count)
  94. {
  95. const unsigned char *buf = buffer;
  96. while(count--) outb(*buf++, port);
  97. }
  98. void adx_outsw(unsigned long port, const void *buffer, unsigned long count)
  99. {
  100. const unsigned short *buf = buffer;
  101. while(count--) outw(*buf++, port);
  102. }
  103. void adx_outsl(unsigned long port, const void *buffer, unsigned long count)
  104. {
  105. const unsigned long *buf = buffer;
  106. while(count--) outl(*buf++, port);
  107. }
  108. unsigned char adx_readb(unsigned long addr)
  109. {
  110. return *(volatile unsigned char*)addr;
  111. }
  112. unsigned short adx_readw(unsigned long addr)
  113. {
  114. return *(volatile unsigned short*)addr;
  115. }
  116. unsigned int adx_readl(unsigned long addr)
  117. {
  118. return *(volatile unsigned long*)addr;
  119. }
  120. void adx_writeb(unsigned char b, unsigned long addr)
  121. {
  122. *(volatile unsigned char*)addr = b;
  123. }
  124. void adx_writew(unsigned short b, unsigned long addr)
  125. {
  126. *(volatile unsigned short*)addr = b;
  127. }
  128. void adx_writel(unsigned int b, unsigned long addr)
  129. {
  130. *(volatile unsigned long*)addr = b;
  131. }
  132. void *adx_ioremap(unsigned long offset, unsigned long size)
  133. {
  134. return (void *)P2SEGADDR(offset);
  135. }
  136. EXPORT_SYMBOL (adx_ioremap);
  137. void adx_iounmap(void *addr)
  138. {
  139. }
  140. EXPORT_SYMBOL(adx_iounmap);
  141. #include <linux/vmalloc.h>
  142. extern void *cf_io_base;
  143. unsigned long adx_isa_port2addr(unsigned long offset)
  144. {
  145.   /* CompactFlash (IDE) */
  146. if (((offset >= 0x1f0) && (offset <= 0x1f7)) || (offset == 0x3f6)) {
  147. return (unsigned long)cf_io_base + offset;
  148. }
  149.   /* eth0 */
  150. if ((offset >= 0x300) && (offset <= 0x30f)) {
  151. return 0xa5000000 + offset; /* COMM BOARD (AREA1) */
  152. }
  153. return offset + 0xb0000000; /* IOBUS (AREA 4)*/
  154. }