sh-sci.h 12 KB

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