io_generic.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * arch/sh/kernel/io_generic.c
  3. *
  4. * Copyright (C) 2000 Niibe Yutaka
  5. * Copyright (C) 2005 - 2007 Paul Mundt
  6. *
  7. * Generic I/O routine. These can be used where a machine specific version
  8. * is not required.
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file "COPYING" in the main directory of this archive
  12. * for more details.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/io.h>
  16. #include <asm/machvec.h>
  17. #ifdef CONFIG_CPU_SH3
  18. /* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
  19. * workaround. */
  20. /* I'm not sure SH7709 has this kind of bug */
  21. #define dummy_read() __raw_readb(0xba000000)
  22. #else
  23. #define dummy_read()
  24. #endif
  25. unsigned long generic_io_base;
  26. u8 generic_inb(unsigned long port)
  27. {
  28. return __raw_readb(__ioport_map(port, 1));
  29. }
  30. u16 generic_inw(unsigned long port)
  31. {
  32. return __raw_readw(__ioport_map(port, 2));
  33. }
  34. u32 generic_inl(unsigned long port)
  35. {
  36. return __raw_readl(__ioport_map(port, 4));
  37. }
  38. u8 generic_inb_p(unsigned long port)
  39. {
  40. unsigned long v = generic_inb(port);
  41. ctrl_delay();
  42. return v;
  43. }
  44. u16 generic_inw_p(unsigned long port)
  45. {
  46. unsigned long v = generic_inw(port);
  47. ctrl_delay();
  48. return v;
  49. }
  50. u32 generic_inl_p(unsigned long port)
  51. {
  52. unsigned long v = generic_inl(port);
  53. ctrl_delay();
  54. return v;
  55. }
  56. /*
  57. * insb/w/l all read a series of bytes/words/longs from a fixed port
  58. * address. However as the port address doesn't change we only need to
  59. * convert the port address to real address once.
  60. */
  61. void generic_insb(unsigned long port, void *dst, unsigned long count)
  62. {
  63. __raw_readsb(__ioport_map(port, 1), dst, count);
  64. dummy_read();
  65. }
  66. void generic_insw(unsigned long port, void *dst, unsigned long count)
  67. {
  68. __raw_readsw(__ioport_map(port, 2), dst, count);
  69. dummy_read();
  70. }
  71. void generic_insl(unsigned long port, void *dst, unsigned long count)
  72. {
  73. __raw_readsl(__ioport_map(port, 4), dst, count);
  74. dummy_read();
  75. }
  76. void generic_outb(u8 b, unsigned long port)
  77. {
  78. __raw_writeb(b, __ioport_map(port, 1));
  79. }
  80. void generic_outw(u16 b, unsigned long port)
  81. {
  82. __raw_writew(b, __ioport_map(port, 2));
  83. }
  84. void generic_outl(u32 b, unsigned long port)
  85. {
  86. __raw_writel(b, __ioport_map(port, 4));
  87. }
  88. void generic_outb_p(u8 b, unsigned long port)
  89. {
  90. generic_outb(b, port);
  91. ctrl_delay();
  92. }
  93. void generic_outw_p(u16 b, unsigned long port)
  94. {
  95. generic_outw(b, port);
  96. ctrl_delay();
  97. }
  98. void generic_outl_p(u32 b, unsigned long port)
  99. {
  100. generic_outl(b, port);
  101. ctrl_delay();
  102. }
  103. /*
  104. * outsb/w/l all write a series of bytes/words/longs to a fixed port
  105. * address. However as the port address doesn't change we only need to
  106. * convert the port address to real address once.
  107. */
  108. void generic_outsb(unsigned long port, const void *src, unsigned long count)
  109. {
  110. __raw_writesb(__ioport_map(port, 1), src, count);
  111. dummy_read();
  112. }
  113. void generic_outsw(unsigned long port, const void *src, unsigned long count)
  114. {
  115. __raw_writesw(__ioport_map(port, 2), src, count);
  116. dummy_read();
  117. }
  118. void generic_outsl(unsigned long port, const void *src, unsigned long count)
  119. {
  120. __raw_writesl(__ioport_map(port, 4), src, count);
  121. dummy_read();
  122. }
  123. void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
  124. {
  125. if (PXSEG(addr) >= P1SEG)
  126. return (void __iomem *)addr;
  127. return (void __iomem *)(addr + generic_io_base);
  128. }
  129. void generic_ioport_unmap(void __iomem *addr)
  130. {
  131. }