io.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 (is_pci_ioaddr(port))
  37. return *(volatile unsigned char *)pci_ioaddr(port);
  38. else if (port <= 0x3F1)
  39. return *(volatile unsigned char *)ETHER_IOMAP(port);
  40. else
  41. return (*port2adr(port))&0xff;
  42. }
  43. unsigned char sh7751systemh_inb_p(unsigned long port)
  44. {
  45. unsigned char v;
  46. if (PXSEG(port))
  47. v = *(volatile unsigned char *)port;
  48. else if (is_pci_ioaddr(port))
  49. v = *(volatile unsigned char *)pci_ioaddr(port);
  50. else if (port <= 0x3F1)
  51. v = *(volatile unsigned char *)ETHER_IOMAP(port);
  52. else
  53. v = (*port2adr(port))&0xff;
  54. ctrl_delay();
  55. return v;
  56. }
  57. unsigned short sh7751systemh_inw(unsigned long port)
  58. {
  59. if (PXSEG(port))
  60. return *(volatile unsigned short *)port;
  61. else if (is_pci_ioaddr(port))
  62. return *(volatile unsigned short *)pci_ioaddr(port);
  63. else if (port >= 0x2000)
  64. return *port2adr(port);
  65. else if (port <= 0x3F1)
  66. return *(volatile unsigned int *)ETHER_IOMAP(port);
  67. else
  68. maybebadio(port);
  69. return 0;
  70. }
  71. unsigned int sh7751systemh_inl(unsigned long port)
  72. {
  73. if (PXSEG(port))
  74. return *(volatile unsigned long *)port;
  75. else if (is_pci_ioaddr(port))
  76. return *(volatile unsigned int *)pci_ioaddr(port);
  77. else if (port >= 0x2000)
  78. return *port2adr(port);
  79. else if (port <= 0x3F1)
  80. return *(volatile unsigned int *)ETHER_IOMAP(port);
  81. else
  82. maybebadio(port);
  83. return 0;
  84. }
  85. void sh7751systemh_outb(unsigned char value, unsigned long port)
  86. {
  87. if (PXSEG(port))
  88. *(volatile unsigned char *)port = value;
  89. else if (is_pci_ioaddr(port))
  90. *((unsigned char*)pci_ioaddr(port)) = value;
  91. else if (port <= 0x3F1)
  92. *(volatile unsigned char *)ETHER_IOMAP(port) = value;
  93. else
  94. *(port2adr(port)) = value;
  95. }
  96. void sh7751systemh_outb_p(unsigned char value, unsigned long port)
  97. {
  98. if (PXSEG(port))
  99. *(volatile unsigned char *)port = value;
  100. else if (is_pci_ioaddr(port))
  101. *((unsigned char*)pci_ioaddr(port)) = value;
  102. else if (port <= 0x3F1)
  103. *(volatile unsigned char *)ETHER_IOMAP(port) = value;
  104. else
  105. *(port2adr(port)) = value;
  106. ctrl_delay();
  107. }
  108. void sh7751systemh_outw(unsigned short value, unsigned long port)
  109. {
  110. if (PXSEG(port))
  111. *(volatile unsigned short *)port = value;
  112. else if (is_pci_ioaddr(port))
  113. *((unsigned short *)pci_ioaddr(port)) = value;
  114. else if (port >= 0x2000)
  115. *port2adr(port) = value;
  116. else if (port <= 0x3F1)
  117. *(volatile unsigned short *)ETHER_IOMAP(port) = value;
  118. else
  119. maybebadio(port);
  120. }
  121. void sh7751systemh_outl(unsigned int value, unsigned long port)
  122. {
  123. if (PXSEG(port))
  124. *(volatile unsigned long *)port = value;
  125. else if (is_pci_ioaddr(port))
  126. *((unsigned long*)pci_ioaddr(port)) = value;
  127. else
  128. maybebadio(port);
  129. }
  130. void sh7751systemh_insb(unsigned long port, void *addr, unsigned long count)
  131. {
  132. unsigned char *p = addr;
  133. while (count--) *p++ = sh7751systemh_inb(port);
  134. }
  135. void sh7751systemh_insw(unsigned long port, void *addr, unsigned long count)
  136. {
  137. unsigned short *p = addr;
  138. while (count--) *p++ = sh7751systemh_inw(port);
  139. }
  140. void sh7751systemh_insl(unsigned long port, void *addr, unsigned long count)
  141. {
  142. maybebadio(port);
  143. }
  144. void sh7751systemh_outsb(unsigned long port, const void *addr, unsigned long count)
  145. {
  146. unsigned char *p = (unsigned char*)addr;
  147. while (count--) sh7751systemh_outb(*p++, port);
  148. }
  149. void sh7751systemh_outsw(unsigned long port, const void *addr, unsigned long count)
  150. {
  151. unsigned short *p = (unsigned short*)addr;
  152. while (count--) sh7751systemh_outw(*p++, port);
  153. }
  154. void sh7751systemh_outsl(unsigned long port, const void *addr, unsigned long count)
  155. {
  156. maybebadio(port);
  157. }