io.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * linux/arch/sh/boards/renesas/systemh/io.c
  3. *
  4. * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
  5. * Based largely on io_se.c.
  6. *
  7. * I/O routine for Hitachi 7751 Systemh.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/types.h>
  11. #include <linux/pci.h>
  12. #include <mach/systemh7751.h>
  13. #include <asm/addrspace.h>
  14. #include <asm/io.h>
  15. #define ETHER_IOMAP(adr) (0xB3000000 + (adr)) /*map to 16bits access area
  16. of smc lan chip*/
  17. static inline volatile __u16 *
  18. port2adr(unsigned int port)
  19. {
  20. if (port >= 0x2000)
  21. return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
  22. maybebadio((unsigned long)port);
  23. return (volatile __u16*)port;
  24. }
  25. /*
  26. * General outline: remap really low stuff [eventually] to SuperIO,
  27. * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
  28. * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
  29. * should be way beyond the window, and is used w/o translation for
  30. * compatibility.
  31. */
  32. unsigned char sh7751systemh_inb(unsigned long port)
  33. {
  34. if (PXSEG(port))
  35. return *(volatile unsigned char *)port;
  36. else if (port <= 0x3F1)
  37. return *(volatile unsigned char *)ETHER_IOMAP(port);
  38. else
  39. return (*port2adr(port))&0xff;
  40. }
  41. unsigned char sh7751systemh_inb_p(unsigned long port)
  42. {
  43. unsigned char v;
  44. if (PXSEG(port))
  45. v = *(volatile unsigned char *)port;
  46. else if (port <= 0x3F1)
  47. v = *(volatile unsigned char *)ETHER_IOMAP(port);
  48. else
  49. v = (*port2adr(port))&0xff;
  50. ctrl_delay();
  51. return v;
  52. }
  53. unsigned short sh7751systemh_inw(unsigned long port)
  54. {
  55. if (PXSEG(port))
  56. return *(volatile unsigned short *)port;
  57. else if (port >= 0x2000)
  58. return *port2adr(port);
  59. else if (port <= 0x3F1)
  60. return *(volatile unsigned int *)ETHER_IOMAP(port);
  61. else
  62. maybebadio(port);
  63. return 0;
  64. }
  65. unsigned int sh7751systemh_inl(unsigned long port)
  66. {
  67. if (PXSEG(port))
  68. return *(volatile unsigned long *)port;
  69. else if (port >= 0x2000)
  70. return *port2adr(port);
  71. else if (port <= 0x3F1)
  72. return *(volatile unsigned int *)ETHER_IOMAP(port);
  73. else
  74. maybebadio(port);
  75. return 0;
  76. }
  77. void sh7751systemh_outb(unsigned char value, unsigned long port)
  78. {
  79. if (PXSEG(port))
  80. *(volatile unsigned char *)port = value;
  81. else if (port <= 0x3F1)
  82. *(volatile unsigned char *)ETHER_IOMAP(port) = value;
  83. else
  84. *(port2adr(port)) = value;
  85. }
  86. void sh7751systemh_outb_p(unsigned char value, unsigned long port)
  87. {
  88. if (PXSEG(port))
  89. *(volatile unsigned char *)port = value;
  90. else if (port <= 0x3F1)
  91. *(volatile unsigned char *)ETHER_IOMAP(port) = value;
  92. else
  93. *(port2adr(port)) = value;
  94. ctrl_delay();
  95. }
  96. void sh7751systemh_outw(unsigned short value, unsigned long port)
  97. {
  98. if (PXSEG(port))
  99. *(volatile unsigned short *)port = value;
  100. else if (port >= 0x2000)
  101. *port2adr(port) = value;
  102. else if (port <= 0x3F1)
  103. *(volatile unsigned short *)ETHER_IOMAP(port) = value;
  104. else
  105. maybebadio(port);
  106. }
  107. void sh7751systemh_outl(unsigned int value, unsigned long port)
  108. {
  109. if (PXSEG(port))
  110. *(volatile unsigned long *)port = value;
  111. else
  112. maybebadio(port);
  113. }
  114. void sh7751systemh_insb(unsigned long port, void *addr, unsigned long count)
  115. {
  116. unsigned char *p = addr;
  117. while (count--) *p++ = sh7751systemh_inb(port);
  118. }
  119. void sh7751systemh_insw(unsigned long port, void *addr, unsigned long count)
  120. {
  121. unsigned short *p = addr;
  122. while (count--) *p++ = sh7751systemh_inw(port);
  123. }
  124. void sh7751systemh_insl(unsigned long port, void *addr, unsigned long count)
  125. {
  126. maybebadio(port);
  127. }
  128. void sh7751systemh_outsb(unsigned long port, const void *addr, unsigned long count)
  129. {
  130. unsigned char *p = (unsigned char*)addr;
  131. while (count--) sh7751systemh_outb(*p++, port);
  132. }
  133. void sh7751systemh_outsw(unsigned long port, const void *addr, unsigned long count)
  134. {
  135. unsigned short *p = (unsigned short*)addr;
  136. while (count--) sh7751systemh_outw(*p++, port);
  137. }
  138. void sh7751systemh_outsl(unsigned long port, const void *addr, unsigned long count)
  139. {
  140. maybebadio(port);
  141. }