sh-sci.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. #include <linux/serial_core.h>
  2. #include <linux/io.h>
  3. #include <linux/gpio.h>
  4. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  5. defined(CONFIG_CPU_SUBTYPE_SH7706) || \
  6. defined(CONFIG_CPU_SUBTYPE_SH7707) || \
  7. defined(CONFIG_CPU_SUBTYPE_SH7708) || \
  8. defined(CONFIG_CPU_SUBTYPE_SH7709)
  9. # define SCPCR 0xA4000116 /* 16 bit SCI and SCIF */
  10. # define SCPDR 0xA4000136 /* 8 bit SCI and SCIF */
  11. #elif defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  12. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  13. defined(CONFIG_ARCH_SH73A0) || \
  14. defined(CONFIG_ARCH_SH7367) || \
  15. defined(CONFIG_ARCH_SH7377) || \
  16. defined(CONFIG_ARCH_SH7372)
  17. # define PORT_PTCR 0xA405011EUL
  18. # define PORT_PVCR 0xA4050122UL
  19. #elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  20. defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  21. defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
  22. defined(CONFIG_CPU_SUBTYPE_SH7091) || \
  23. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  24. defined(CONFIG_CPU_SUBTYPE_SH7751R) || \
  25. defined(CONFIG_CPU_SUBTYPE_SH4_202)
  26. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  27. #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
  28. # define SCSPTR0 0xfe600024 /* 16 bit SCIF */
  29. # define SCSPTR2 0xfe620024 /* 16 bit SCIF */
  30. #elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
  31. # define SCSPTR0 0xA4400000 /* 16 bit SCIF */
  32. # define PACR 0xa4050100
  33. # define PBCR 0xa4050102
  34. #elif defined(CONFIG_CPU_SUBTYPE_SH7343)
  35. # define SCSPTR0 0xffe00010 /* 16 bit SCIF */
  36. #elif defined(CONFIG_CPU_SUBTYPE_SH7722)
  37. # define PWDR 0xA4050166
  38. # define PSCR 0xA405011E
  39. #elif defined(CONFIG_CPU_SUBTYPE_SH7366)
  40. # define SCPDR0 0xA405013E /* 16 bit SCIF0 PSDR */
  41. # define SCSPTR0 SCPDR0
  42. #elif defined(CONFIG_CPU_SUBTYPE_SH7723)
  43. # define SCSPTR0 0xa4050160
  44. #elif defined(CONFIG_CPU_SUBTYPE_SH7757)
  45. # define SCSPTR0 0xfe4b0020
  46. #elif defined(CONFIG_CPU_SUBTYPE_SH7763) || \
  47. defined(CONFIG_CPU_SUBTYPE_SH7780)
  48. # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
  49. #elif defined(CONFIG_CPU_SUBTYPE_SH7770)
  50. # define SCSPTR0 0xff923020 /* 16 bit SCIF */
  51. #elif defined(CONFIG_CPU_SUBTYPE_SH7785) || \
  52. defined(CONFIG_CPU_SUBTYPE_SH7786)
  53. # define SCSPTR0 0xffea0024 /* 16 bit SCIF */
  54. #elif defined(CONFIG_CPU_SUBTYPE_SH7201) || \
  55. defined(CONFIG_CPU_SUBTYPE_SH7203) || \
  56. defined(CONFIG_CPU_SUBTYPE_SH7206) || \
  57. defined(CONFIG_CPU_SUBTYPE_SH7263)
  58. # define SCSPTR0 0xfffe8020 /* 16 bit SCIF */
  59. #elif defined(CONFIG_CPU_SUBTYPE_SH7619)
  60. # define SCSPTR0 0xf8400020 /* 16 bit SCIF */
  61. #elif defined(CONFIG_CPU_SUBTYPE_SHX3)
  62. # define SCSPTR0 0xffc30020 /* 16 bit SCIF */
  63. #else
  64. # error CPU subtype not defined
  65. #endif
  66. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  67. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  68. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  69. defined(CONFIG_ARCH_SH73A0) || \
  70. defined(CONFIG_ARCH_SH7367) || \
  71. defined(CONFIG_ARCH_SH7377) || \
  72. defined(CONFIG_ARCH_SH7372)
  73. # define SCIF_RFDC_MASK 0x007f
  74. # define SCIF_TXROOM_MAX 64
  75. #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
  76. # define SCIF_RFDC_MASK 0x007f
  77. # define SCIF_TXROOM_MAX 64
  78. /* SH7763 SCIF2 support */
  79. # define SCIF2_RFDC_MASK 0x001f
  80. # define SCIF2_TXROOM_MAX 16
  81. #else
  82. # define SCIF_RFDC_MASK 0x001f
  83. # define SCIF_TXROOM_MAX 16
  84. #endif
  85. #define SCxSR_TEND(port) (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
  86. #define SCxSR_RDxF(port) (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
  87. #define SCxSR_TDxE(port) (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
  88. #define SCxSR_FER(port) (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
  89. #define SCxSR_PER(port) (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
  90. #define SCxSR_BRK(port) (((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
  91. #define SCxSR_ERRORS(port) (to_sci_port(port)->cfg->error_mask)
  92. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  93. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  94. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  95. defined(CONFIG_ARCH_SH73A0) || \
  96. defined(CONFIG_ARCH_SH7367) || \
  97. defined(CONFIG_ARCH_SH7377) || \
  98. defined(CONFIG_ARCH_SH7372)
  99. # define SCxSR_RDxF_CLEAR(port) (sci_in(port, SCxSR) & 0xfffc)
  100. # define SCxSR_ERROR_CLEAR(port) (sci_in(port, SCxSR) & 0xfd73)
  101. # define SCxSR_TDxE_CLEAR(port) (sci_in(port, SCxSR) & 0xffdf)
  102. # define SCxSR_BREAK_CLEAR(port) (sci_in(port, SCxSR) & 0xffe3)
  103. #else
  104. # define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
  105. # define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
  106. # define SCxSR_TDxE_CLEAR(port) (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
  107. # define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
  108. #endif
  109. /* SCFCR */
  110. #define SCFCR_RFRST 0x0002
  111. #define SCFCR_TFRST 0x0004
  112. #define SCFCR_MCE 0x0008
  113. #define SCI_MAJOR 204
  114. #define SCI_MINOR_START 8
  115. #define SCI_IN(size, offset) \
  116. ioread##size(port->membase + (offset))
  117. #define SCI_OUT(size, offset, value) \
  118. iowrite##size(value, port->membase + (offset))
  119. #define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
  120. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  121. { \
  122. if (port->type == PORT_SCIF || port->type == PORT_SCIFB) { \
  123. return SCI_IN(scif_size, scif_offset); \
  124. } else { /* PORT_SCI or PORT_SCIFA */ \
  125. return SCI_IN(sci_size, sci_offset); \
  126. } \
  127. } \
  128. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  129. { \
  130. if (port->type == PORT_SCIF || port->type == PORT_SCIFB) { \
  131. SCI_OUT(scif_size, scif_offset, value); \
  132. } else { /* PORT_SCI or PORT_SCIFA */ \
  133. SCI_OUT(sci_size, sci_offset, value); \
  134. } \
  135. }
  136. #define CPU_SCIF_FNS(name, scif_offset, scif_size) \
  137. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  138. { \
  139. return SCI_IN(scif_size, scif_offset); \
  140. } \
  141. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  142. { \
  143. SCI_OUT(scif_size, scif_offset, value); \
  144. }
  145. #if defined(CONFIG_CPU_SH3) || \
  146. defined(CONFIG_ARCH_SH73A0) || \
  147. defined(CONFIG_ARCH_SH7367) || \
  148. defined(CONFIG_ARCH_SH7377) || \
  149. defined(CONFIG_ARCH_SH7372)
  150. #if defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
  151. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  152. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  153. CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
  154. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  155. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  156. #elif defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  157. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  158. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  159. defined(CONFIG_ARCH_SH7367)
  160. #define SCIF_FNS(name, scif_offset, scif_size) \
  161. CPU_SCIF_FNS(name, scif_offset, scif_size)
  162. #elif defined(CONFIG_ARCH_SH7377) || \
  163. defined(CONFIG_ARCH_SH7372) || \
  164. defined(CONFIG_ARCH_SH73A0)
  165. #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scifb_offset, sh4_scifb_size) \
  166. CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scifb_offset, sh4_scifb_size)
  167. #define SCIF_FNS(name, scif_offset, scif_size) \
  168. CPU_SCIF_FNS(name, scif_offset, scif_size)
  169. #else
  170. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  171. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  172. CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh3_scif_offset, sh3_scif_size)
  173. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  174. CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
  175. #endif
  176. #elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\
  177. defined(CONFIG_CPU_SUBTYPE_SH7724)
  178. #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size) \
  179. CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size)
  180. #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \
  181. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  182. #else
  183. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  184. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  185. CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
  186. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  187. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  188. #endif
  189. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  190. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  191. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  192. defined(CONFIG_ARCH_SH7367)
  193. SCIF_FNS(SCSMR, 0x00, 16)
  194. SCIF_FNS(SCBRR, 0x04, 8)
  195. SCIF_FNS(SCSCR, 0x08, 16)
  196. SCIF_FNS(SCxSR, 0x14, 16)
  197. SCIF_FNS(SCFCR, 0x18, 16)
  198. SCIF_FNS(SCFDR, 0x1c, 16)
  199. SCIF_FNS(SCxTDR, 0x20, 8)
  200. SCIF_FNS(SCxRDR, 0x24, 8)
  201. SCIF_FNS(SCLSR, 0x00, 0)
  202. #elif defined(CONFIG_ARCH_SH7377) || \
  203. defined(CONFIG_ARCH_SH7372) || \
  204. defined(CONFIG_ARCH_SH73A0)
  205. SCIF_FNS(SCSMR, 0x00, 16)
  206. SCIF_FNS(SCBRR, 0x04, 8)
  207. SCIF_FNS(SCSCR, 0x08, 16)
  208. SCIF_FNS(SCTDSR, 0x0c, 16)
  209. SCIF_FNS(SCFER, 0x10, 16)
  210. SCIF_FNS(SCxSR, 0x14, 16)
  211. SCIF_FNS(SCFCR, 0x18, 16)
  212. SCIF_FNS(SCFDR, 0x1c, 16)
  213. SCIF_FNS(SCTFDR, 0x38, 16)
  214. SCIF_FNS(SCRFDR, 0x3c, 16)
  215. SCIx_FNS(SCxTDR, 0x20, 8, 0x40, 8)
  216. SCIx_FNS(SCxRDR, 0x24, 8, 0x60, 8)
  217. SCIF_FNS(SCLSR, 0x00, 0)
  218. #elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\
  219. defined(CONFIG_CPU_SUBTYPE_SH7724)
  220. SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16)
  221. SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8)
  222. SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16)
  223. SCIx_FNS(SCxTDR, 0x20, 8, 0x0c, 8)
  224. SCIx_FNS(SCxSR, 0x14, 16, 0x10, 16)
  225. SCIx_FNS(SCxRDR, 0x24, 8, 0x14, 8)
  226. SCIx_FNS(SCSPTR, 0, 0, 0, 0)
  227. SCIF_FNS(SCFCR, 0x18, 16)
  228. SCIF_FNS(SCFDR, 0x1c, 16)
  229. SCIF_FNS(SCLSR, 0x24, 16)
  230. #else
  231. /* reg SCI/SH3 SCI/SH4 SCIF/SH3 SCIF/SH4 */
  232. /* name off sz off sz off sz off sz */
  233. SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16)
  234. SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8)
  235. SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16)
  236. SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8)
  237. SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16)
  238. SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8)
  239. SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
  240. #if defined(CONFIG_CPU_SUBTYPE_SH7760) || \
  241. defined(CONFIG_CPU_SUBTYPE_SH7780) || \
  242. defined(CONFIG_CPU_SUBTYPE_SH7785) || \
  243. defined(CONFIG_CPU_SUBTYPE_SH7786)
  244. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  245. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  246. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  247. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  248. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  249. #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
  250. SCIF_FNS(SCFDR, 0, 0, 0x1C, 16)
  251. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  252. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  253. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  254. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  255. #else
  256. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  257. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  258. SCIF_FNS(SCSPTR, 0, 0, 0, 0)
  259. #else
  260. SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
  261. #endif
  262. SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
  263. #endif
  264. #endif
  265. #define sci_in(port, reg) sci_##reg##_in(port)
  266. #define sci_out(port, reg, value) sci_##reg##_out(port, value)