sh-sci.h 27 KB

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