io_generic.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. volatile u8 *port_addr;
  64. u8 *buf = dst;
  65. port_addr = (volatile u8 __force *)__ioport_map(port, 1);
  66. while (count--)
  67. *buf++ = *port_addr;
  68. }
  69. void generic_insw(unsigned long port, void *dst, unsigned long count)
  70. {
  71. volatile u16 *port_addr;
  72. u16 *buf = dst;
  73. port_addr = (volatile u16 __force *)__ioport_map(port, 2);
  74. while (count--)
  75. *buf++ = *port_addr;
  76. dummy_read();
  77. }
  78. void generic_insl(unsigned long port, void *dst, unsigned long count)
  79. {
  80. volatile u32 *port_addr;
  81. u32 *buf = dst;
  82. port_addr = (volatile u32 __force *)__ioport_map(port, 4);
  83. while (count--)
  84. *buf++ = *port_addr;
  85. dummy_read();
  86. }
  87. void generic_outb(u8 b, unsigned long port)
  88. {
  89. __raw_writeb(b, __ioport_map(port, 1));
  90. }
  91. void generic_outw(u16 b, unsigned long port)
  92. {
  93. __raw_writew(b, __ioport_map(port, 2));
  94. }
  95. void generic_outl(u32 b, unsigned long port)
  96. {
  97. __raw_writel(b, __ioport_map(port, 4));
  98. }
  99. void generic_outb_p(u8 b, unsigned long port)
  100. {
  101. generic_outb(b, port);
  102. ctrl_delay();
  103. }
  104. void generic_outw_p(u16 b, unsigned long port)
  105. {
  106. generic_outw(b, port);
  107. ctrl_delay();
  108. }
  109. void generic_outl_p(u32 b, unsigned long port)
  110. {
  111. generic_outl(b, port);
  112. ctrl_delay();
  113. }
  114. /*
  115. * outsb/w/l all write a series of bytes/words/longs to a fixed port
  116. * address. However as the port address doesn't change we only need to
  117. * convert the port address to real address once.
  118. */
  119. void generic_outsb(unsigned long port, const void *src, unsigned long count)
  120. {
  121. volatile u8 *port_addr;
  122. const u8 *buf = src;
  123. port_addr = (volatile u8 __force *)__ioport_map(port, 1);
  124. while (count--)
  125. *port_addr = *buf++;
  126. }
  127. void generic_outsw(unsigned long port, const void *src, unsigned long count)
  128. {
  129. volatile u16 *port_addr;
  130. const u16 *buf = src;
  131. port_addr = (volatile u16 __force *)__ioport_map(port, 2);
  132. while (count--)
  133. *port_addr = *buf++;
  134. dummy_read();
  135. }
  136. void generic_outsl(unsigned long port, const void *src, unsigned long count)
  137. {
  138. volatile u32 *port_addr;
  139. const u32 *buf = src;
  140. port_addr = (volatile u32 __force *)__ioport_map(port, 4);
  141. while (count--)
  142. *port_addr = *buf++;
  143. dummy_read();
  144. }
  145. void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
  146. {
  147. return (void __iomem *)(addr + generic_io_base);
  148. }
  149. void generic_ioport_unmap(void __iomem *addr)
  150. {
  151. }