io.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * I/O routines for Titan
  3. */
  4. #include <linux/pci.h>
  5. #include <asm/machvec.h>
  6. #include <asm/addrspace.h>
  7. #include <asm/titan.h>
  8. #include <asm/io.h>
  9. #include "../../drivers/pci/pci-sh7751.h"
  10. #define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR)
  11. #define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR)
  12. #define PCI_IO_AREA SH7751_PCI_IO_BASE
  13. #define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE
  14. #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
  15. #if defined(CONFIG_PCI)
  16. #define CHECK_SH7751_PCIIO(port) \
  17. ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
  18. #define CHECK_SH7751_PCIMEMIO(port) \
  19. ((port >= PCIBIOS_MIN_MEM) && (port < (PCIBIOS_MIN_MEM + SH7751_PCI_MEM_SIZE)))
  20. #else
  21. #define CHECK_SH7751_PCIIO(port) (0)
  22. #endif
  23. static inline void delay(void)
  24. {
  25. ctrl_inw(0xa0000000);
  26. }
  27. static inline unsigned int port2adr(unsigned int port)
  28. {
  29. maybebadio((unsigned long)port);
  30. return port;
  31. }
  32. u8 titan_inb(unsigned long port)
  33. {
  34. if (PXSEG(port))
  35. return ctrl_inb(port);
  36. else if (CHECK_SH7751_PCIIO(port))
  37. return ctrl_inb(PCI_IOMAP(port));
  38. return ctrl_inw(port2adr(port)) & 0xff;
  39. }
  40. u8 titan_inb_p(unsigned long port)
  41. {
  42. u8 v;
  43. if (PXSEG(port))
  44. v = ctrl_inb(port);
  45. else if (CHECK_SH7751_PCIIO(port))
  46. v = ctrl_inb(PCI_IOMAP(port));
  47. else
  48. v = ctrl_inw(port2adr(port)) & 0xff;
  49. delay();
  50. return v;
  51. }
  52. u16 titan_inw(unsigned long port)
  53. {
  54. if (PXSEG(port))
  55. return ctrl_inw(port);
  56. else if (CHECK_SH7751_PCIIO(port))
  57. return ctrl_inw(PCI_IOMAP(port));
  58. else if (port >= 0x2000)
  59. return ctrl_inw(port2adr(port));
  60. else
  61. maybebadio(port);
  62. return 0;
  63. }
  64. u32 titan_inl(unsigned long port)
  65. {
  66. if (PXSEG(port))
  67. return ctrl_inl(port);
  68. else if (CHECK_SH7751_PCIIO(port))
  69. return ctrl_inl(PCI_IOMAP(port));
  70. else if (port >= 0x2000)
  71. return ctrl_inw(port2adr(port));
  72. else
  73. maybebadio(port);
  74. return 0;
  75. }
  76. void titan_outb(u8 value, unsigned long port)
  77. {
  78. if (PXSEG(port))
  79. ctrl_outb(value, port);
  80. else if (CHECK_SH7751_PCIIO(port))
  81. ctrl_outb(value, PCI_IOMAP(port));
  82. else
  83. ctrl_outw(value, port2adr(port));
  84. }
  85. void titan_outb_p(u8 value, unsigned long port)
  86. {
  87. if (PXSEG(port))
  88. ctrl_outb(value, port);
  89. else if (CHECK_SH7751_PCIIO(port))
  90. ctrl_outb(value, PCI_IOMAP(port));
  91. else
  92. ctrl_outw(value, port2adr(port));
  93. delay();
  94. }
  95. void titan_outw(u16 value, unsigned long port)
  96. {
  97. if (PXSEG(port))
  98. ctrl_outw(value, port);
  99. else if (CHECK_SH7751_PCIIO(port))
  100. ctrl_outw(value, PCI_IOMAP(port));
  101. else if (port >= 0x2000)
  102. ctrl_outw(value, port2adr(port));
  103. else
  104. maybebadio(port);
  105. }
  106. void titan_outl(u32 value, unsigned long port)
  107. {
  108. if (PXSEG(port))
  109. ctrl_outl(value, port);
  110. else if (CHECK_SH7751_PCIIO(port))
  111. ctrl_outl(value, PCI_IOMAP(port));
  112. else
  113. maybebadio(port);
  114. }
  115. void titan_insl(unsigned long port, void *dst, unsigned long count)
  116. {
  117. maybebadio(port);
  118. }
  119. void titan_outsl(unsigned long port, const void *src, unsigned long count)
  120. {
  121. maybebadio(port);
  122. }
  123. void __iomem *titan_ioport_map(unsigned long port, unsigned int size)
  124. {
  125. if (PXSEG(port) || CHECK_SH7751_PCIMEMIO(port))
  126. return (void __iomem *)port;
  127. else if (CHECK_SH7751_PCIIO(port))
  128. return (void __iomem *)PCI_IOMAP(port);
  129. return (void __iomem *)port2adr(port);
  130. }