io.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/kernel.h>
  11. #include <linux/types.h>
  12. #include <linux/delay.h>
  13. #include <asm/system.h>
  14. #include <asm/processor.h>
  15. #include <asm/io.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. /* This is horrible at the moment - needs more work to do something sensible */
  23. #define IO_DELAY()
  24. #define OUT_DELAY(x,type) \
  25. void out##x##_p(unsigned type value,unsigned long port){out##x(value,port);IO_DELAY();}
  26. #define IN_DELAY(x,type) \
  27. unsigned type in##x##_p(unsigned long port) {unsigned type tmp=in##x(port);IO_DELAY();return tmp;}
  28. #if 1
  29. OUT_DELAY(b, long) OUT_DELAY(w, long) OUT_DELAY(l, long)
  30. IN_DELAY(b, long) IN_DELAY(w, long) IN_DELAY(l, long)
  31. #endif
  32. /* Now for the string version of these functions */
  33. void outsb(unsigned long port, const void *addr, unsigned long count)
  34. {
  35. int i;
  36. unsigned char *p = (unsigned char *) addr;
  37. for (i = 0; i < count; i++, p++) {
  38. outb(*p, port);
  39. }
  40. }
  41. void insb(unsigned long port, void *addr, unsigned long count)
  42. {
  43. int i;
  44. unsigned char *p = (unsigned char *) addr;
  45. for (i = 0; i < count; i++, p++) {
  46. *p = inb(port);
  47. }
  48. }
  49. /* For the 16 and 32 bit string functions, we have to worry about alignment.
  50. * The SH does not do unaligned accesses, so we have to read as bytes and
  51. * then write as a word or dword.
  52. * This can be optimised a lot more, especially in the case where the data
  53. * is aligned
  54. */
  55. void outsw(unsigned long port, const void *addr, unsigned long count)
  56. {
  57. int i;
  58. unsigned short tmp;
  59. unsigned char *p = (unsigned char *) addr;
  60. for (i = 0; i < count; i++, p += 2) {
  61. tmp = (*p) | ((*(p + 1)) << 8);
  62. outw(tmp, port);
  63. }
  64. }
  65. void insw(unsigned long port, void *addr, unsigned long count)
  66. {
  67. int i;
  68. unsigned short tmp;
  69. unsigned char *p = (unsigned char *) addr;
  70. for (i = 0; i < count; i++, p += 2) {
  71. tmp = inw(port);
  72. p[0] = tmp & 0xff;
  73. p[1] = (tmp >> 8) & 0xff;
  74. }
  75. }
  76. void outsl(unsigned long port, const void *addr, unsigned long count)
  77. {
  78. int i;
  79. unsigned tmp;
  80. unsigned char *p = (unsigned char *) addr;
  81. for (i = 0; i < count; i++, p += 4) {
  82. tmp = (*p) | ((*(p + 1)) << 8) | ((*(p + 2)) << 16) |
  83. ((*(p + 3)) << 24);
  84. outl(tmp, port);
  85. }
  86. }
  87. void insl(unsigned long port, void *addr, unsigned long count)
  88. {
  89. int i;
  90. unsigned tmp;
  91. unsigned char *p = (unsigned char *) addr;
  92. for (i = 0; i < count; i++, p += 4) {
  93. tmp = inl(port);
  94. p[0] = tmp & 0xff;
  95. p[1] = (tmp >> 8) & 0xff;
  96. p[2] = (tmp >> 16) & 0xff;
  97. p[3] = (tmp >> 24) & 0xff;
  98. }
  99. }
  100. void memcpy_toio(void __iomem *to, const void *from, long count)
  101. {
  102. unsigned char *p = (unsigned char *) from;
  103. while (count) {
  104. count--;
  105. writeb(*p++, to++);
  106. }
  107. }
  108. void memcpy_fromio(void *to, void __iomem *from, long count)
  109. {
  110. int i;
  111. unsigned char *p = (unsigned char *) to;
  112. for (i = 0; i < count; i++) {
  113. p[i] = readb(from);
  114. from++;
  115. }
  116. }