sh-sci.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. #include <linux/serial_core.h>
  2. #include <asm/io.h>
  3. #include <linux/gpio.h>
  4. #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
  5. #include <asm/regs306x.h>
  6. #endif
  7. #if defined(CONFIG_H8S2678)
  8. #include <asm/regs267x.h>
  9. #endif
  10. #if defined(CONFIG_CPU_SUBTYPE_SH7706) || \
  11. defined(CONFIG_CPU_SUBTYPE_SH7707) || \
  12. defined(CONFIG_CPU_SUBTYPE_SH7708) || \
  13. defined(CONFIG_CPU_SUBTYPE_SH7709)
  14. # define SCPCR 0xA4000116 /* 16 bit SCI and SCIF */
  15. # define SCPDR 0xA4000136 /* 8 bit SCI and SCIF */
  16. #elif defined(CONFIG_CPU_SUBTYPE_SH7705)
  17. # define SCIF0 0xA4400000
  18. # define SCIF2 0xA4410000
  19. # define SCPCR 0xA4000116
  20. # define SCPDR 0xA4000136
  21. #elif defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  22. defined(CONFIG_CPU_SUBTYPE_SH7721)
  23. # define PORT_PTCR 0xA405011EUL
  24. # define PORT_PVCR 0xA4050122UL
  25. # define SCIF_ORER 0x0200 /* overrun error bit */
  26. #elif defined(CONFIG_SH_RTS7751R2D)
  27. # define SCSPTR1 0xFFE0001C /* 8 bit SCIF */
  28. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  29. # define SCIF_ORER 0x0001 /* overrun error bit */
  30. #elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  31. defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  32. defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
  33. defined(CONFIG_CPU_SUBTYPE_SH7091) || \
  34. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  35. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  36. # define SCSPTR1 0xffe0001c /* 8 bit SCI */
  37. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  38. # define SCIF_ORER 0x0001 /* overrun error bit */
  39. #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
  40. # define SCSPTR0 0xfe600024 /* 16 bit SCIF */
  41. # define SCSPTR1 0xfe610024 /* 16 bit SCIF */
  42. # define SCSPTR2 0xfe620024 /* 16 bit SCIF */
  43. # define SCIF_ORER 0x0001 /* overrun error bit */
  44. #elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
  45. # define SCSPTR0 0xA4400000 /* 16 bit SCIF */
  46. # define SCIF_ORER 0x0001 /* overrun error bit */
  47. # define PACR 0xa4050100
  48. # define PBCR 0xa4050102
  49. #elif defined(CONFIG_CPU_SUBTYPE_SH7343)
  50. # define SCSPTR0 0xffe00010 /* 16 bit SCIF */
  51. # define SCSPTR1 0xffe10010 /* 16 bit SCIF */
  52. # define SCSPTR2 0xffe20010 /* 16 bit SCIF */
  53. # define SCSPTR3 0xffe30010 /* 16 bit SCIF */
  54. #elif defined(CONFIG_CPU_SUBTYPE_SH7722)
  55. # define PADR 0xA4050120
  56. # define PSDR 0xA405013e
  57. # define PWDR 0xA4050166
  58. # define PSCR 0xA405011E
  59. # define SCIF_ORER 0x0001 /* overrun error bit */
  60. #elif defined(CONFIG_CPU_SUBTYPE_SH7366)
  61. # define SCPDR0 0xA405013E /* 16 bit SCIF0 PSDR */
  62. # define SCSPTR0 SCPDR0
  63. # define SCIF_ORER 0x0001 /* overrun error bit */
  64. #elif defined(CONFIG_CPU_SUBTYPE_SH7723)
  65. # define SCSPTR0 0xa4050160
  66. # define SCSPTR1 0xa405013e
  67. # define SCSPTR2 0xa4050160
  68. # define SCSPTR3 0xa405013e
  69. # define SCSPTR4 0xa4050128
  70. # define SCSPTR5 0xa4050128
  71. # define SCIF_ORER 0x0001 /* overrun error bit */
  72. #elif defined(CONFIG_CPU_SUBTYPE_SH7724)
  73. # define SCIF_ORER 0x0001 /* overrun error bit */
  74. #elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
  75. # define SCSPTR2 0xffe80020 /* 16 bit SCIF */
  76. # define SCIF_ORER 0x0001 /* overrun error bit */
  77. #elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
  78. # define SCIF_PTR2_OFFS 0x0000020
  79. # define SCSPTR2 ((port->mapbase)+SCIF_PTR2_OFFS) /* 16 bit SCIF */
  80. #elif defined(CONFIG_H83007) || defined(CONFIG_H83068)
  81. # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
  82. #elif defined(CONFIG_H8S2678)
  83. # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
  84. #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
  85. # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
  86. # define SCSPTR1 0xffe08024 /* 16 bit SCIF */
  87. # define SCSPTR2 0xffe10020 /* 16 bit SCIF/IRDA */
  88. # define SCIF_ORER 0x0001 /* overrun error bit */
  89. #elif defined(CONFIG_CPU_SUBTYPE_SH7770)
  90. # define SCSPTR0 0xff923020 /* 16 bit SCIF */
  91. # define SCSPTR1 0xff924020 /* 16 bit SCIF */
  92. # define SCSPTR2 0xff925020 /* 16 bit SCIF */
  93. # define SCIF_ORER 0x0001 /* overrun error bit */
  94. #elif defined(CONFIG_CPU_SUBTYPE_SH7780)
  95. # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
  96. # define SCSPTR1 0xffe10024 /* 16 bit SCIF */
  97. # define SCIF_ORER 0x0001 /* Overrun error bit */
  98. #elif defined(CONFIG_CPU_SUBTYPE_SH7785) || \
  99. defined(CONFIG_CPU_SUBTYPE_SH7786)
  100. # define SCSPTR0 0xffea0024 /* 16 bit SCIF */
  101. # define SCSPTR1 0xffeb0024 /* 16 bit SCIF */
  102. # define SCSPTR2 0xffec0024 /* 16 bit SCIF */
  103. # define SCSPTR3 0xffed0024 /* 16 bit SCIF */
  104. # define SCSPTR4 0xffee0024 /* 16 bit SCIF */
  105. # define SCSPTR5 0xffef0024 /* 16 bit SCIF */
  106. # define SCIF_ORER 0x0001 /* Overrun error bit */
  107. #elif defined(CONFIG_CPU_SUBTYPE_SH7201) || \
  108. defined(CONFIG_CPU_SUBTYPE_SH7203) || \
  109. defined(CONFIG_CPU_SUBTYPE_SH7206) || \
  110. defined(CONFIG_CPU_SUBTYPE_SH7263)
  111. # define SCSPTR0 0xfffe8020 /* 16 bit SCIF */
  112. # define SCSPTR1 0xfffe8820 /* 16 bit SCIF */
  113. # define SCSPTR2 0xfffe9020 /* 16 bit SCIF */
  114. # define SCSPTR3 0xfffe9820 /* 16 bit SCIF */
  115. # if defined(CONFIG_CPU_SUBTYPE_SH7201)
  116. # define SCSPTR4 0xfffeA020 /* 16 bit SCIF */
  117. # define SCSPTR5 0xfffeA820 /* 16 bit SCIF */
  118. # define SCSPTR6 0xfffeB020 /* 16 bit SCIF */
  119. # define SCSPTR7 0xfffeB820 /* 16 bit SCIF */
  120. # endif
  121. #elif defined(CONFIG_CPU_SUBTYPE_SH7619)
  122. # define SCSPTR0 0xf8400020 /* 16 bit SCIF */
  123. # define SCSPTR1 0xf8410020 /* 16 bit SCIF */
  124. # define SCSPTR2 0xf8420020 /* 16 bit SCIF */
  125. # define SCIF_ORER 0x0001 /* overrun error bit */
  126. #elif defined(CONFIG_CPU_SUBTYPE_SHX3)
  127. # define SCSPTR0 0xffc30020 /* 16 bit SCIF */
  128. # define SCSPTR1 0xffc40020 /* 16 bit SCIF */
  129. # define SCSPTR2 0xffc50020 /* 16 bit SCIF */
  130. # define SCSPTR3 0xffc60020 /* 16 bit SCIF */
  131. # define SCIF_ORER 0x0001 /* Overrun error bit */
  132. #else
  133. # error CPU subtype not defined
  134. #endif
  135. /* SCxSR SCI */
  136. #define SCI_TDRE 0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  137. #define SCI_RDRF 0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  138. #define SCI_ORER 0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  139. #define SCI_FER 0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  140. #define SCI_PER 0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  141. #define SCI_TEND 0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  142. /* SCI_MPB 0x02 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  143. /* SCI_MPBT 0x01 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  144. #define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
  145. /* SCxSR SCIF */
  146. #define SCIF_ER 0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  147. #define SCIF_TEND 0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  148. #define SCIF_TDFE 0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  149. #define SCIF_BRK 0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  150. #define SCIF_FER 0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  151. #define SCIF_PER 0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  152. #define SCIF_RDF 0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  153. #define SCIF_DR 0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  154. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  155. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  156. defined(CONFIG_CPU_SUBTYPE_SH7721)
  157. # define SCIF_ORER 0x0200
  158. # define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
  159. # define SCIF_RFDC_MASK 0x007f
  160. # define SCIF_TXROOM_MAX 64
  161. #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
  162. # define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK )
  163. # define SCIF_RFDC_MASK 0x007f
  164. # define SCIF_TXROOM_MAX 64
  165. /* SH7763 SCIF2 support */
  166. # define SCIF2_RFDC_MASK 0x001f
  167. # define SCIF2_TXROOM_MAX 16
  168. #else
  169. # define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
  170. # define SCIF_RFDC_MASK 0x001f
  171. # define SCIF_TXROOM_MAX 16
  172. #endif
  173. #ifndef SCIF_ORER
  174. #define SCIF_ORER 0x0000
  175. #endif
  176. #define SCxSR_TEND(port) (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
  177. #define SCxSR_ERRORS(port) (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
  178. #define SCxSR_RDxF(port) (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
  179. #define SCxSR_TDxE(port) (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
  180. #define SCxSR_FER(port) (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
  181. #define SCxSR_PER(port) (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
  182. #define SCxSR_BRK(port) (((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
  183. #define SCxSR_ORER(port) (((port)->type == PORT_SCI) ? SCI_ORER : SCIF_ORER)
  184. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  185. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  186. defined(CONFIG_CPU_SUBTYPE_SH7721)
  187. # define SCxSR_RDxF_CLEAR(port) (sci_in(port, SCxSR) & 0xfffc)
  188. # define SCxSR_ERROR_CLEAR(port) (sci_in(port, SCxSR) & 0xfd73)
  189. # define SCxSR_TDxE_CLEAR(port) (sci_in(port, SCxSR) & 0xffdf)
  190. # define SCxSR_BREAK_CLEAR(port) (sci_in(port, SCxSR) & 0xffe3)
  191. #else
  192. # define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
  193. # define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
  194. # define SCxSR_TDxE_CLEAR(port) (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
  195. # define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
  196. #endif
  197. /* SCFCR */
  198. #define SCFCR_RFRST 0x0002
  199. #define SCFCR_TFRST 0x0004
  200. #define SCFCR_MCE 0x0008
  201. #define SCI_MAJOR 204
  202. #define SCI_MINOR_START 8
  203. #define SCI_IN(size, offset) \
  204. if ((size) == 8) { \
  205. return ioread8(port->membase + (offset)); \
  206. } else { \
  207. return ioread16(port->membase + (offset)); \
  208. }
  209. #define SCI_OUT(size, offset, value) \
  210. if ((size) == 8) { \
  211. iowrite8(value, port->membase + (offset)); \
  212. } else if ((size) == 16) { \
  213. iowrite16(value, port->membase + (offset)); \
  214. }
  215. #define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
  216. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  217. { \
  218. if (port->type == PORT_SCIF) { \
  219. SCI_IN(scif_size, scif_offset) \
  220. } else { /* PORT_SCI or PORT_SCIFA */ \
  221. SCI_IN(sci_size, sci_offset); \
  222. } \
  223. } \
  224. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  225. { \
  226. if (port->type == PORT_SCIF) { \
  227. SCI_OUT(scif_size, scif_offset, value) \
  228. } else { /* PORT_SCI or PORT_SCIFA */ \
  229. SCI_OUT(sci_size, sci_offset, value); \
  230. } \
  231. }
  232. #ifdef CONFIG_H8300
  233. /* h8300 don't have SCIF */
  234. #define CPU_SCIF_FNS(name) \
  235. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  236. { \
  237. return 0; \
  238. } \
  239. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  240. { \
  241. }
  242. #else
  243. #define CPU_SCIF_FNS(name, scif_offset, scif_size) \
  244. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  245. { \
  246. SCI_IN(scif_size, scif_offset); \
  247. } \
  248. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  249. { \
  250. SCI_OUT(scif_size, scif_offset, value); \
  251. }
  252. #endif
  253. #define CPU_SCI_FNS(name, sci_offset, sci_size) \
  254. static inline unsigned int sci_##name##_in(struct uart_port* port) \
  255. { \
  256. SCI_IN(sci_size, sci_offset); \
  257. } \
  258. static inline void sci_##name##_out(struct uart_port* port, unsigned int value) \
  259. { \
  260. SCI_OUT(sci_size, sci_offset, value); \
  261. }
  262. #ifdef CONFIG_CPU_SH3
  263. #if defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
  264. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  265. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  266. h8_sci_offset, h8_sci_size) \
  267. CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
  268. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  269. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  270. #elif defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  271. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  272. defined(CONFIG_CPU_SUBTYPE_SH7721)
  273. #define SCIF_FNS(name, scif_offset, scif_size) \
  274. CPU_SCIF_FNS(name, scif_offset, scif_size)
  275. #else
  276. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  277. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  278. h8_sci_offset, h8_sci_size) \
  279. CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh3_scif_offset, sh3_scif_size)
  280. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  281. CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
  282. #endif
  283. #elif defined(__H8300H__) || defined(__H8300S__)
  284. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  285. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  286. h8_sci_offset, h8_sci_size) \
  287. CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size)
  288. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  289. CPU_SCIF_FNS(name)
  290. #elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\
  291. defined(CONFIG_CPU_SUBTYPE_SH7724)
  292. #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size) \
  293. CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size)
  294. #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \
  295. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  296. #else
  297. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  298. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  299. h8_sci_offset, h8_sci_size) \
  300. CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
  301. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  302. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  303. #endif
  304. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  305. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  306. defined(CONFIG_CPU_SUBTYPE_SH7721)
  307. SCIF_FNS(SCSMR, 0x00, 16)
  308. SCIF_FNS(SCBRR, 0x04, 8)
  309. SCIF_FNS(SCSCR, 0x08, 16)
  310. SCIF_FNS(SCxSR, 0x14, 16)
  311. SCIF_FNS(SCFCR, 0x18, 16)
  312. SCIF_FNS(SCFDR, 0x1c, 16)
  313. SCIF_FNS(SCxTDR, 0x20, 8)
  314. SCIF_FNS(SCxRDR, 0x24, 8)
  315. SCIF_FNS(SCLSR, 0x24, 16)
  316. #elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\
  317. defined(CONFIG_CPU_SUBTYPE_SH7724)
  318. SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16)
  319. SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8)
  320. SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16)
  321. SCIx_FNS(SCxTDR, 0x20, 8, 0x0c, 8)
  322. SCIx_FNS(SCxSR, 0x14, 16, 0x10, 16)
  323. SCIx_FNS(SCxRDR, 0x24, 8, 0x14, 8)
  324. SCIx_FNS(SCSPTR, 0, 0, 0, 0)
  325. SCIF_FNS(SCFCR, 0x18, 16)
  326. SCIF_FNS(SCFDR, 0x1c, 16)
  327. SCIF_FNS(SCLSR, 0x24, 16)
  328. #else
  329. /* reg SCI/SH3 SCI/SH4 SCIF/SH3 SCIF/SH4 SCI/H8*/
  330. /* name off sz off sz off sz off sz off sz*/
  331. SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16, 0x00, 8)
  332. SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8, 0x01, 8)
  333. SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16, 0x02, 8)
  334. SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8, 0x03, 8)
  335. SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16, 0x04, 8)
  336. SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
  337. SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
  338. #if defined(CONFIG_CPU_SUBTYPE_SH7760) || \
  339. defined(CONFIG_CPU_SUBTYPE_SH7780) || \
  340. defined(CONFIG_CPU_SUBTYPE_SH7785) || \
  341. defined(CONFIG_CPU_SUBTYPE_SH7786)
  342. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  343. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  344. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  345. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  346. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  347. #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
  348. SCIF_FNS(SCFDR, 0, 0, 0x1C, 16)
  349. SCIF_FNS(SCSPTR2, 0, 0, 0x20, 16)
  350. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  351. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  352. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  353. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  354. #else
  355. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  356. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  357. SCIF_FNS(SCSPTR, 0, 0, 0, 0)
  358. #else
  359. SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
  360. #endif
  361. SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
  362. #endif
  363. #endif
  364. #define sci_in(port, reg) sci_##reg##_in(port)
  365. #define sci_out(port, reg, value) sci_##reg##_out(port, value)
  366. /* H8/300 series SCI pins assignment */
  367. #if defined(__H8300H__) || defined(__H8300S__)
  368. static const struct __attribute__((packed)) {
  369. int port; /* GPIO port no */
  370. unsigned short rx,tx; /* GPIO bit no */
  371. } h8300_sci_pins[] = {
  372. #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
  373. { /* SCI0 */
  374. .port = H8300_GPIO_P9,
  375. .rx = H8300_GPIO_B2,
  376. .tx = H8300_GPIO_B0,
  377. },
  378. { /* SCI1 */
  379. .port = H8300_GPIO_P9,
  380. .rx = H8300_GPIO_B3,
  381. .tx = H8300_GPIO_B1,
  382. },
  383. { /* SCI2 */
  384. .port = H8300_GPIO_PB,
  385. .rx = H8300_GPIO_B7,
  386. .tx = H8300_GPIO_B6,
  387. }
  388. #elif defined(CONFIG_H8S2678)
  389. { /* SCI0 */
  390. .port = H8300_GPIO_P3,
  391. .rx = H8300_GPIO_B2,
  392. .tx = H8300_GPIO_B0,
  393. },
  394. { /* SCI1 */
  395. .port = H8300_GPIO_P3,
  396. .rx = H8300_GPIO_B3,
  397. .tx = H8300_GPIO_B1,
  398. },
  399. { /* SCI2 */
  400. .port = H8300_GPIO_P5,
  401. .rx = H8300_GPIO_B1,
  402. .tx = H8300_GPIO_B0,
  403. }
  404. #endif
  405. };
  406. #endif
  407. #if defined(CONFIG_CPU_SUBTYPE_SH7706) || \
  408. defined(CONFIG_CPU_SUBTYPE_SH7707) || \
  409. defined(CONFIG_CPU_SUBTYPE_SH7708) || \
  410. defined(CONFIG_CPU_SUBTYPE_SH7709)
  411. static inline int sci_rxd_in(struct uart_port *port)
  412. {
  413. if (port->mapbase == 0xfffffe80)
  414. return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCI */
  415. if (port->mapbase == 0xa4000150)
  416. return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
  417. if (port->mapbase == 0xa4000140)
  418. return ctrl_inb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
  419. return 1;
  420. }
  421. #elif defined(CONFIG_CPU_SUBTYPE_SH7705)
  422. static inline int sci_rxd_in(struct uart_port *port)
  423. {
  424. if (port->mapbase == SCIF0)
  425. return ctrl_inb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
  426. if (port->mapbase == SCIF2)
  427. return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
  428. return 1;
  429. }
  430. #elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
  431. static inline int sci_rxd_in(struct uart_port *port)
  432. {
  433. return sci_in(port,SCxSR)&0x0010 ? 1 : 0;
  434. }
  435. #elif defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  436. defined(CONFIG_CPU_SUBTYPE_SH7721)
  437. static inline int sci_rxd_in(struct uart_port *port)
  438. {
  439. if (port->mapbase == 0xa4430000)
  440. return sci_in(port, SCxSR) & 0x0003 ? 1 : 0;
  441. else if (port->mapbase == 0xa4438000)
  442. return sci_in(port, SCxSR) & 0x0003 ? 1 : 0;
  443. return 1;
  444. }
  445. #elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  446. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  447. defined(CONFIG_CPU_SUBTYPE_SH7751R) || \
  448. defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  449. defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
  450. defined(CONFIG_CPU_SUBTYPE_SH7091)
  451. static inline int sci_rxd_in(struct uart_port *port)
  452. {
  453. if (port->mapbase == 0xffe00000)
  454. return ctrl_inb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
  455. if (port->mapbase == 0xffe80000)
  456. return ctrl_inw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
  457. return 1;
  458. }
  459. #elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
  460. static inline int sci_rxd_in(struct uart_port *port)
  461. {
  462. if (port->mapbase == 0xffe80000)
  463. return ctrl_inw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
  464. return 1;
  465. }
  466. #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
  467. static inline int sci_rxd_in(struct uart_port *port)
  468. {
  469. if (port->mapbase == 0xfe600000)
  470. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  471. if (port->mapbase == 0xfe610000)
  472. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  473. if (port->mapbase == 0xfe620000)
  474. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  475. return 1;
  476. }
  477. #elif defined(CONFIG_CPU_SUBTYPE_SH7343)
  478. static inline int sci_rxd_in(struct uart_port *port)
  479. {
  480. if (port->mapbase == 0xffe00000)
  481. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  482. if (port->mapbase == 0xffe10000)
  483. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  484. if (port->mapbase == 0xffe20000)
  485. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  486. if (port->mapbase == 0xffe30000)
  487. return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
  488. return 1;
  489. }
  490. #elif defined(CONFIG_CPU_SUBTYPE_SH7366)
  491. static inline int sci_rxd_in(struct uart_port *port)
  492. {
  493. if (port->mapbase == 0xffe00000)
  494. return ctrl_inb(SCPDR0) & 0x0001 ? 1 : 0; /* SCIF0 */
  495. return 1;
  496. }
  497. #elif defined(CONFIG_CPU_SUBTYPE_SH7722)
  498. static inline int sci_rxd_in(struct uart_port *port)
  499. {
  500. if (port->mapbase == 0xffe00000)
  501. return ctrl_inb(PSDR) & 0x02 ? 1 : 0; /* SCIF0 */
  502. if (port->mapbase == 0xffe10000)
  503. return ctrl_inb(PADR) & 0x40 ? 1 : 0; /* SCIF1 */
  504. if (port->mapbase == 0xffe20000)
  505. return ctrl_inb(PWDR) & 0x04 ? 1 : 0; /* SCIF2 */
  506. return 1;
  507. }
  508. #elif defined(CONFIG_CPU_SUBTYPE_SH7723)
  509. static inline int sci_rxd_in(struct uart_port *port)
  510. {
  511. if (port->mapbase == 0xffe00000)
  512. return ctrl_inb(SCSPTR0) & 0x0008 ? 1 : 0; /* SCIF0 */
  513. if (port->mapbase == 0xffe10000)
  514. return ctrl_inb(SCSPTR1) & 0x0020 ? 1 : 0; /* SCIF1 */
  515. if (port->mapbase == 0xffe20000)
  516. return ctrl_inb(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF2 */
  517. if (port->mapbase == 0xa4e30000)
  518. return ctrl_inb(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF3 */
  519. if (port->mapbase == 0xa4e40000)
  520. return ctrl_inb(SCSPTR4) & 0x0001 ? 1 : 0; /* SCIF4 */
  521. if (port->mapbase == 0xa4e50000)
  522. return ctrl_inb(SCSPTR5) & 0x0008 ? 1 : 0; /* SCIF5 */
  523. return 1;
  524. }
  525. #elif defined(CONFIG_CPU_SUBTYPE_SH7724)
  526. # define SCFSR 0x0010
  527. # define SCASSR 0x0014
  528. static inline int sci_rxd_in(struct uart_port *port)
  529. {
  530. if (port->type == PORT_SCIF)
  531. return ctrl_inw((port->mapbase + SCFSR)) & SCIF_BRK ? 1 : 0;
  532. if (port->type == PORT_SCIFA)
  533. return ctrl_inw((port->mapbase + SCASSR)) & SCIF_BRK ? 1 : 0;
  534. return 1;
  535. }
  536. #elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
  537. static inline int sci_rxd_in(struct uart_port *port)
  538. {
  539. return sci_in(port, SCSPTR)&0x0001 ? 1 : 0; /* SCIF */
  540. }
  541. #elif defined(__H8300H__) || defined(__H8300S__)
  542. static inline int sci_rxd_in(struct uart_port *port)
  543. {
  544. int ch = (port->mapbase - SMR0) >> 3;
  545. return (H8300_SCI_DR(ch) & h8300_sci_pins[ch].rx) ? 1 : 0;
  546. }
  547. #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
  548. static inline int sci_rxd_in(struct uart_port *port)
  549. {
  550. if (port->mapbase == 0xffe00000)
  551. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  552. if (port->mapbase == 0xffe08000)
  553. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  554. if (port->mapbase == 0xffe10000)
  555. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF/IRDA */
  556. return 1;
  557. }
  558. #elif defined(CONFIG_CPU_SUBTYPE_SH7770)
  559. static inline int sci_rxd_in(struct uart_port *port)
  560. {
  561. if (port->mapbase == 0xff923000)
  562. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  563. if (port->mapbase == 0xff924000)
  564. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  565. if (port->mapbase == 0xff925000)
  566. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  567. return 1;
  568. }
  569. #elif defined(CONFIG_CPU_SUBTYPE_SH7780)
  570. static inline int sci_rxd_in(struct uart_port *port)
  571. {
  572. if (port->mapbase == 0xffe00000)
  573. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  574. if (port->mapbase == 0xffe10000)
  575. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  576. return 1;
  577. }
  578. #elif defined(CONFIG_CPU_SUBTYPE_SH7785) || \
  579. defined(CONFIG_CPU_SUBTYPE_SH7786)
  580. static inline int sci_rxd_in(struct uart_port *port)
  581. {
  582. if (port->mapbase == 0xffea0000)
  583. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  584. if (port->mapbase == 0xffeb0000)
  585. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  586. if (port->mapbase == 0xffec0000)
  587. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  588. if (port->mapbase == 0xffed0000)
  589. return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
  590. if (port->mapbase == 0xffee0000)
  591. return ctrl_inw(SCSPTR4) & 0x0001 ? 1 : 0; /* SCIF */
  592. if (port->mapbase == 0xffef0000)
  593. return ctrl_inw(SCSPTR5) & 0x0001 ? 1 : 0; /* SCIF */
  594. return 1;
  595. }
  596. #elif defined(CONFIG_CPU_SUBTYPE_SH7201) || \
  597. defined(CONFIG_CPU_SUBTYPE_SH7203) || \
  598. defined(CONFIG_CPU_SUBTYPE_SH7206) || \
  599. defined(CONFIG_CPU_SUBTYPE_SH7263)
  600. static inline int sci_rxd_in(struct uart_port *port)
  601. {
  602. if (port->mapbase == 0xfffe8000)
  603. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  604. if (port->mapbase == 0xfffe8800)
  605. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  606. if (port->mapbase == 0xfffe9000)
  607. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  608. if (port->mapbase == 0xfffe9800)
  609. return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
  610. #if defined(CONFIG_CPU_SUBTYPE_SH7201)
  611. if (port->mapbase == 0xfffeA000)
  612. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  613. if (port->mapbase == 0xfffeA800)
  614. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  615. if (port->mapbase == 0xfffeB000)
  616. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  617. if (port->mapbase == 0xfffeB800)
  618. return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
  619. #endif
  620. return 1;
  621. }
  622. #elif defined(CONFIG_CPU_SUBTYPE_SH7619)
  623. static inline int sci_rxd_in(struct uart_port *port)
  624. {
  625. if (port->mapbase == 0xf8400000)
  626. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  627. if (port->mapbase == 0xf8410000)
  628. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  629. if (port->mapbase == 0xf8420000)
  630. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  631. return 1;
  632. }
  633. #elif defined(CONFIG_CPU_SUBTYPE_SHX3)
  634. static inline int sci_rxd_in(struct uart_port *port)
  635. {
  636. if (port->mapbase == 0xffc30000)
  637. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  638. if (port->mapbase == 0xffc40000)
  639. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  640. if (port->mapbase == 0xffc50000)
  641. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  642. if (port->mapbase == 0xffc60000)
  643. return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
  644. return 1;
  645. }
  646. #endif