io.c 3.8 KB

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