io.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright (C) 2000 David J. Mckay (david.mckay@st.com)
  3. *
  4. * May be copied or modified under the terms of the GNU General Public
  5. * License. See linux/COPYING for more information.
  6. *
  7. * This file contains the I/O routines for use on the overdrive board
  8. *
  9. */
  10. #include <linux/config.h>
  11. #include <linux/types.h>
  12. #include <linux/delay.h>
  13. #include <asm/processor.h>
  14. #include <asm/io.h>
  15. #include <asm/addrspace.h>
  16. #include <asm/overdrive/overdrive.h>
  17. /*
  18. * readX/writeX() are used to access memory mapped devices. On some
  19. * architectures the memory mapped IO stuff needs to be accessed
  20. * differently. On the SuperH architecture, we just read/write the
  21. * memory location directly.
  22. */
  23. #define dprintk(x...)
  24. /* Translates an IO address to where it is mapped in memory */
  25. #define io_addr(x) (((unsigned)(x))|PCI_GTIO_BASE)
  26. unsigned char od_inb(unsigned long port)
  27. {
  28. dprintk("od_inb(%x)\n", port);
  29. return readb(io_addr(port)) & 0xff;
  30. }
  31. unsigned short od_inw(unsigned long port)
  32. {
  33. dprintk("od_inw(%x)\n", port);
  34. return readw(io_addr(port)) & 0xffff;
  35. }
  36. unsigned int od_inl(unsigned long port)
  37. {
  38. dprintk("od_inl(%x)\n", port);
  39. return readl(io_addr(port));
  40. }
  41. void od_outb(unsigned char value, unsigned long port)
  42. {
  43. dprintk("od_outb(%x, %x)\n", value, port);
  44. writeb(value, io_addr(port));
  45. }
  46. void od_outw(unsigned short value, unsigned long port)
  47. {
  48. dprintk("od_outw(%x, %x)\n", value, port);
  49. writew(value, io_addr(port));
  50. }
  51. void od_outl(unsigned int value, unsigned long port)
  52. {
  53. dprintk("od_outl(%x, %x)\n", value, port);
  54. writel(value, io_addr(port));
  55. }
  56. /* This is horrible at the moment - needs more work to do something sensible */
  57. #define IO_DELAY() udelay(10)
  58. #define OUT_DELAY(x,type) \
  59. void od_out##x##_p(unsigned type value,unsigned long port){out##x(value,port);IO_DELAY();}
  60. #define IN_DELAY(x,type) \
  61. unsigned type od_in##x##_p(unsigned long port) {unsigned type tmp=in##x(port);IO_DELAY();return tmp;}
  62. OUT_DELAY(b,char)
  63. OUT_DELAY(w,short)
  64. OUT_DELAY(l,int)
  65. IN_DELAY(b,char)
  66. IN_DELAY(w,short)
  67. IN_DELAY(l,int)
  68. /* Now for the string version of these functions */
  69. void od_outsb(unsigned long port, const void *addr, unsigned long count)
  70. {
  71. int i;
  72. unsigned char *p = (unsigned char *) addr;
  73. for (i = 0; i < count; i++, p++) {
  74. outb(*p, port);
  75. }
  76. }
  77. void od_insb(unsigned long port, void *addr, unsigned long count)
  78. {
  79. int i;
  80. unsigned char *p = (unsigned char *) addr;
  81. for (i = 0; i < count; i++, p++) {
  82. *p = inb(port);
  83. }
  84. }
  85. /* For the 16 and 32 bit string functions, we have to worry about alignment.
  86. * The SH does not do unaligned accesses, so we have to read as bytes and
  87. * then write as a word or dword.
  88. * This can be optimised a lot more, especially in the case where the data
  89. * is aligned
  90. */
  91. void od_outsw(unsigned long port, const void *addr, unsigned long count)
  92. {
  93. int i;
  94. unsigned short tmp;
  95. unsigned char *p = (unsigned char *) addr;
  96. for (i = 0; i < count; i++, p += 2) {
  97. tmp = (*p) | ((*(p + 1)) << 8);
  98. outw(tmp, port);
  99. }
  100. }
  101. void od_insw(unsigned long port, void *addr, unsigned long count)
  102. {
  103. int i;
  104. unsigned short tmp;
  105. unsigned char *p = (unsigned char *) addr;
  106. for (i = 0; i < count; i++, p += 2) {
  107. tmp = inw(port);
  108. p[0] = tmp & 0xff;
  109. p[1] = (tmp >> 8) & 0xff;
  110. }
  111. }
  112. void od_outsl(unsigned long port, const void *addr, unsigned long count)
  113. {
  114. int i;
  115. unsigned tmp;
  116. unsigned char *p = (unsigned char *) addr;
  117. for (i = 0; i < count; i++, p += 4) {
  118. tmp = (*p) | ((*(p + 1)) << 8) | ((*(p + 2)) << 16) |
  119. ((*(p + 3)) << 24);
  120. outl(tmp, port);
  121. }
  122. }
  123. void od_insl(unsigned long port, void *addr, unsigned long count)
  124. {
  125. int i;
  126. unsigned tmp;
  127. unsigned char *p = (unsigned char *) addr;
  128. for (i = 0; i < count; i++, p += 4) {
  129. tmp = inl(port);
  130. p[0] = tmp & 0xff;
  131. p[1] = (tmp >> 8) & 0xff;
  132. p[2] = (tmp >> 16) & 0xff;
  133. p[3] = (tmp >> 24) & 0xff;
  134. }
  135. }