io.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * linux/include/asm-arm/arch-s3c2410/io.h
  3. * from linux/include/asm-arm/arch-rpc/io.h
  4. *
  5. * Copyright (C) 1997 Russell King
  6. * (C) 2003 Simtec Electronics
  7. *
  8. * Modifications:
  9. * 06-Dec-1997 RMK Created.
  10. * 02-Sep-2003 BJD Modified for S3C2410
  11. * 10-Mar-2005 LCVR Changed S3C2410_VA to S3C24XX_VA
  12. *
  13. */
  14. #ifndef __ASM_ARM_ARCH_IO_H
  15. #define __ASM_ARM_ARCH_IO_H
  16. #define IO_SPACE_LIMIT 0xffffffff
  17. /*
  18. * We use two different types of addressing - PC style addresses, and ARM
  19. * addresses. PC style accesses the PC hardware with the normal PC IO
  20. * addresses, eg 0x3f8 for serial#1. ARM addresses are above A28
  21. * and are translated to the start of IO. Note that all addresses are
  22. * not shifted left!
  23. */
  24. #define __PORT_PCIO(x) ((x) < (1<<28))
  25. #define PCIO_BASE (S3C24XX_VA_ISA_WORD)
  26. #define PCIO_BASE_b (S3C24XX_VA_ISA_BYTE)
  27. #define PCIO_BASE_w (S3C24XX_VA_ISA_WORD)
  28. #define PCIO_BASE_l (S3C24XX_VA_ISA_WORD)
  29. /*
  30. * Dynamic IO functions - let the compiler
  31. * optimize the expressions
  32. */
  33. #define DECLARE_DYN_OUT(sz,fnsuffix,instr) \
  34. static inline void __out##fnsuffix (unsigned int val, unsigned int port) \
  35. { \
  36. unsigned long temp; \
  37. __asm__ __volatile__( \
  38. "cmp %2, #(1<<28)\n\t" \
  39. "mov %0, %2\n\t" \
  40. "addcc %0, %0, %3\n\t" \
  41. "str" instr " %1, [%0, #0 ] @ out" #fnsuffix \
  42. : "=&r" (temp) \
  43. : "r" (val), "r" (port), "Ir" (PCIO_BASE_##fnsuffix) \
  44. : "cc"); \
  45. }
  46. #define DECLARE_DYN_IN(sz,fnsuffix,instr) \
  47. static inline unsigned sz __in##fnsuffix (unsigned int port) \
  48. { \
  49. unsigned long temp, value; \
  50. __asm__ __volatile__( \
  51. "cmp %2, #(1<<28)\n\t" \
  52. "mov %0, %2\n\t" \
  53. "addcc %0, %0, %3\n\t" \
  54. "ldr" instr " %1, [%0, #0 ] @ in" #fnsuffix \
  55. : "=&r" (temp), "=r" (value) \
  56. : "r" (port), "Ir" (PCIO_BASE_##fnsuffix) \
  57. : "cc"); \
  58. return (unsigned sz)value; \
  59. }
  60. static inline void __iomem *__ioaddr (unsigned long port)
  61. {
  62. return __PORT_PCIO(port) ? (PCIO_BASE + port) : (void __iomem *)port;
  63. }
  64. #define DECLARE_IO(sz,fnsuffix,instr) \
  65. DECLARE_DYN_IN(sz,fnsuffix,instr) \
  66. DECLARE_DYN_OUT(sz,fnsuffix,instr)
  67. DECLARE_IO(char,b,"b")
  68. DECLARE_IO(short,w,"h")
  69. DECLARE_IO(int,l,"")
  70. #undef DECLARE_IO
  71. #undef DECLARE_DYN_IN
  72. /*
  73. * Constant address IO functions
  74. *
  75. * These have to be macros for the 'J' constraint to work -
  76. * +/-4096 immediate operand.
  77. */
  78. #define __outbc(value,port) \
  79. ({ \
  80. if (__PORT_PCIO((port))) \
  81. __asm__ __volatile__( \
  82. "strb %0, [%1, %2] @ outbc" \
  83. : : "r" (value), "r" (PCIO_BASE), "Jr" ((port))); \
  84. else \
  85. __asm__ __volatile__( \
  86. "strb %0, [%1, #0] @ outbc" \
  87. : : "r" (value), "r" ((port))); \
  88. })
  89. #define __inbc(port) \
  90. ({ \
  91. unsigned char result; \
  92. if (__PORT_PCIO((port))) \
  93. __asm__ __volatile__( \
  94. "ldrb %0, [%1, %2] @ inbc" \
  95. : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port))); \
  96. else \
  97. __asm__ __volatile__( \
  98. "ldrb %0, [%1, #0] @ inbc" \
  99. : "=r" (result) : "r" ((port))); \
  100. result; \
  101. })
  102. #define __outwc(value,port) \
  103. ({ \
  104. unsigned long v = value; \
  105. if (__PORT_PCIO((port))) \
  106. __asm__ __volatile__( \
  107. "strh %0, [%1, %2] @ outwc" \
  108. : : "r" (v), "r" (PCIO_BASE), "Jr" ((port))); \
  109. else \
  110. __asm__ __volatile__( \
  111. "strh %0, [%1, #0] @ outwc" \
  112. : : "r" (v), "r" ((port))); \
  113. })
  114. #define __inwc(port) \
  115. ({ \
  116. unsigned short result; \
  117. if (__PORT_PCIO((port))) \
  118. __asm__ __volatile__( \
  119. "ldrh %0, [%1, %2] @ inwc" \
  120. : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port))); \
  121. else \
  122. __asm__ __volatile__( \
  123. "ldrh %0, [%1, #0] @ inwc" \
  124. : "=r" (result) : "r" ((port))); \
  125. result; \
  126. })
  127. #define __outlc(value,port) \
  128. ({ \
  129. unsigned long v = value; \
  130. if (__PORT_PCIO((port))) \
  131. __asm__ __volatile__( \
  132. "str %0, [%1, %2] @ outlc" \
  133. : : "r" (v), "r" (PCIO_BASE), "Jr" ((port))); \
  134. else \
  135. __asm__ __volatile__( \
  136. "str %0, [%1, #0] @ outlc" \
  137. : : "r" (v), "r" ((port))); \
  138. })
  139. #define __inlc(port) \
  140. ({ \
  141. unsigned long result; \
  142. if (__PORT_PCIO((port))) \
  143. __asm__ __volatile__( \
  144. "ldr %0, [%1, %2] @ inlc" \
  145. : "=r" (result) : "r" (PCIO_BASE), "Jr" ((port))); \
  146. else \
  147. __asm__ __volatile__( \
  148. "ldr %0, [%1, #0] @ inlc" \
  149. : "=r" (result) : "r" ((port))); \
  150. result; \
  151. })
  152. #define __ioaddrc(port) ((__PORT_PCIO(port) ? PCIO_BASE + (port) : (void __iomem *)(port)))
  153. #define inb(p) (__builtin_constant_p((p)) ? __inbc(p) : __inb(p))
  154. #define inw(p) (__builtin_constant_p((p)) ? __inwc(p) : __inw(p))
  155. #define inl(p) (__builtin_constant_p((p)) ? __inlc(p) : __inl(p))
  156. #define outb(v,p) (__builtin_constant_p((p)) ? __outbc(v,p) : __outb(v,p))
  157. #define outw(v,p) (__builtin_constant_p((p)) ? __outwc(v,p) : __outw(v,p))
  158. #define outl(v,p) (__builtin_constant_p((p)) ? __outlc(v,p) : __outl(v,p))
  159. #define __ioaddr(p) (__builtin_constant_p((p)) ? __ioaddr(p) : __ioaddrc(p))
  160. /* the following macro is deprecated */
  161. #define ioaddr(port) __ioaddr((port))
  162. #define insb(p,d,l) __raw_readsb(__ioaddr(p),d,l)
  163. #define insw(p,d,l) __raw_readsw(__ioaddr(p),d,l)
  164. #define insl(p,d,l) __raw_readsl(__ioaddr(p),d,l)
  165. #define outsb(p,d,l) __raw_writesb(__ioaddr(p),d,l)
  166. #define outsw(p,d,l) __raw_writesw(__ioaddr(p),d,l)
  167. #define outsl(p,d,l) __raw_writesl(__ioaddr(p),d,l)
  168. /*
  169. * 1:1 mapping for ioremapped regions.
  170. */
  171. #define __mem_pci(x) (x)
  172. #endif