io.c 3.2 KB

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