serial_sh.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /*
  2. * Copy and modify from linux/drivers/serial/sh-sci.h
  3. */
  4. struct uart_port {
  5. unsigned long iobase; /* in/out[bwl] */
  6. unsigned char *membase; /* read/write[bwl] */
  7. unsigned long mapbase; /* for ioremap */
  8. unsigned int type; /* port type */
  9. };
  10. #define PORT_SCI 52
  11. #define PORT_SCIF 53
  12. #define PORT_SCIFA 83
  13. #define PORT_SCIFB 93
  14. #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
  15. #include <asm/regs306x.h>
  16. #endif
  17. #if defined(CONFIG_H8S2678)
  18. #include <asm/regs267x.h>
  19. #endif
  20. #if defined(CONFIG_CPU_SH7706) || \
  21. defined(CONFIG_CPU_SH7707) || \
  22. defined(CONFIG_CPU_SH7708) || \
  23. defined(CONFIG_CPU_SH7709)
  24. # define SCPCR 0xA4000116 /* 16 bit SCI and SCIF */
  25. # define SCPDR 0xA4000136 /* 8 bit SCI and SCIF */
  26. # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
  27. #elif defined(CONFIG_CPU_SH7705)
  28. # define SCIF0 0xA4400000
  29. # define SCIF2 0xA4410000
  30. # define SCSMR_Ir 0xA44A0000
  31. # define IRDA_SCIF SCIF0
  32. # define SCPCR 0xA4000116
  33. # define SCPDR 0xA4000136
  34. /* Set the clock source,
  35. * SCIF2 (0xA4410000) -> External clock, SCK pin used as clock input
  36. * SCIF0 (0xA4400000) -> Internal clock, SCK pin as serial clock output
  37. */
  38. # define SCSCR_INIT(port) (port->mapbase == SCIF2) ? 0xF3 : 0xF0
  39. #elif defined(CONFIG_CPU_SH7720) || \
  40. defined(CONFIG_CPU_SH7721) || \
  41. defined(CONFIG_ARCH_SH7367) || \
  42. defined(CONFIG_ARCH_SH7377) || \
  43. defined(CONFIG_ARCH_SH7372) || \
  44. defined(CONFIG_SH73A0) || \
  45. defined(CONFIG_R8A7740)
  46. # define SCSCR_INIT(port) 0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
  47. # define PORT_PTCR 0xA405011EUL
  48. # define PORT_PVCR 0xA4050122UL
  49. # define SCIF_ORER 0x0200 /* overrun error bit */
  50. #elif defined(CONFIG_SH_RTS7751R2D)
  51. # define SCSPTR1 0xFFE0001C /* 8 bit SCIF */
  52. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  53. # define SCIF_ORER 0x0001 /* overrun error bit */
  54. # define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  55. #elif defined(CONFIG_CPU_SH7750) || \
  56. defined(CONFIG_CPU_SH7750R) || \
  57. defined(CONFIG_CPU_SH7750S) || \
  58. defined(CONFIG_CPU_SH7091) || \
  59. defined(CONFIG_CPU_SH7751) || \
  60. defined(CONFIG_CPU_SH7751R)
  61. # define SCSPTR1 0xffe0001c /* 8 bit SCI */
  62. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  63. # define SCIF_ORER 0x0001 /* overrun error bit */
  64. # define SCSCR_INIT(port) (((port)->type == PORT_SCI) ? \
  65. 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
  66. 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */)
  67. #elif defined(CONFIG_CPU_SH7760)
  68. # define SCSPTR0 0xfe600024 /* 16 bit SCIF */
  69. # define SCSPTR1 0xfe610024 /* 16 bit SCIF */
  70. # define SCSPTR2 0xfe620024 /* 16 bit SCIF */
  71. # define SCIF_ORER 0x0001 /* overrun error bit */
  72. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  73. #elif defined(CONFIG_CPU_SH7710) || defined(CONFIG_CPU_SH7712)
  74. # define SCSPTR0 0xA4400000 /* 16 bit SCIF */
  75. # define SCIF_ORER 0x0001 /* overrun error bit */
  76. # define PACR 0xa4050100
  77. # define PBCR 0xa4050102
  78. # define SCSCR_INIT(port) 0x3B
  79. #elif defined(CONFIG_CPU_SH7343)
  80. # define SCSPTR0 0xffe00010 /* 16 bit SCIF */
  81. # define SCSPTR1 0xffe10010 /* 16 bit SCIF */
  82. # define SCSPTR2 0xffe20010 /* 16 bit SCIF */
  83. # define SCSPTR3 0xffe30010 /* 16 bit SCIF */
  84. # define SCSCR_INIT(port) 0x32 /* TIE=0,RIE=0,TE=1,RE=1,REIE=0,CKE=1 */
  85. #elif defined(CONFIG_CPU_SH7722)
  86. # define PADR 0xA4050120
  87. # undef PSDR
  88. # define PSDR 0xA405013e
  89. # define PWDR 0xA4050166
  90. # define PSCR 0xA405011E
  91. # define SCIF_ORER 0x0001 /* overrun error bit */
  92. # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  93. #elif defined(CONFIG_CPU_SH7366)
  94. # define SCPDR0 0xA405013E /* 16 bit SCIF0 PSDR */
  95. # define SCSPTR0 SCPDR0
  96. # define SCIF_ORER 0x0001 /* overrun error bit */
  97. # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  98. #elif defined(CONFIG_CPU_SH7723)
  99. # define SCSPTR0 0xa4050160
  100. # define SCSPTR1 0xa405013e
  101. # define SCSPTR2 0xa4050160
  102. # define SCSPTR3 0xa405013e
  103. # define SCSPTR4 0xa4050128
  104. # define SCSPTR5 0xa4050128
  105. # define SCIF_ORER 0x0001 /* overrun error bit */
  106. # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  107. #elif defined(CONFIG_CPU_SH7724)
  108. # define SCIF_ORER 0x0001 /* overrun error bit */
  109. # define SCSCR_INIT(port) ((port)->type == PORT_SCIFA ? \
  110. 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
  111. 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */)
  112. #elif defined(CONFIG_CPU_SH7734)
  113. # define SCSPTR0 0xFFE40020
  114. # define SCSPTR1 0xFFE41020
  115. # define SCSPTR2 0xFFE42020
  116. # define SCSPTR3 0xFFE43020
  117. # define SCSPTR4 0xFFE44020
  118. # define SCSPTR5 0xFFE45020
  119. # define SCIF_ORER 0x0001 /* overrun error bit */
  120. # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  121. #elif defined(CONFIG_CPU_SH4_202)
  122. # define SCSPTR2 0xffe80020 /* 16 bit SCIF */
  123. # define SCIF_ORER 0x0001 /* overrun error bit */
  124. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  125. #elif defined(CONFIG_CPU_SH5_101) || defined(CONFIG_CPU_SH5_103)
  126. # define SCIF_BASE_ADDR 0x01030000
  127. # define SCIF_ADDR_SH5 (PHYS_PERIPHERAL_BLOCK+SCIF_BASE_ADDR)
  128. # define SCIF_PTR2_OFFS 0x0000020
  129. # define SCIF_LSR2_OFFS 0x0000024
  130. # define SCSPTR\
  131. ((port->mapbase)+SCIF_PTR2_OFFS) /* 16 bit SCIF */
  132. # define SCLSR2\
  133. ((port->mapbase)+SCIF_LSR2_OFFS) /* 16 bit SCIF */
  134. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0, TE=1,RE=1,REIE=1 */
  135. #elif defined(CONFIG_H83007) || defined(CONFIG_H83068)
  136. # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
  137. # define H8300_SCI_DR(ch) (*(volatile char *)(P1DR + h8300_sci_pins[ch].port))
  138. #elif defined(CONFIG_H8S2678)
  139. # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
  140. # define H8300_SCI_DR(ch) (*(volatile char *)(P1DR + h8300_sci_pins[ch].port))
  141. #elif defined(CONFIG_CPU_SH7757) || \
  142. defined(CONFIG_CPU_SH7752) || \
  143. defined(CONFIG_CPU_SH7753)
  144. # define SCSPTR0 0xfe4b0020
  145. # define SCSPTR1 0xfe4b0020
  146. # define SCSPTR2 0xfe4b0020
  147. # define SCIF_ORER 0x0001
  148. # define SCSCR_INIT(port) 0x38
  149. # define SCIF_ONLY
  150. #elif defined(CONFIG_CPU_SH7763)
  151. # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
  152. # define SCSPTR1 0xffe08024 /* 16 bit SCIF */
  153. # define SCSPTR2 0xffe10020 /* 16 bit SCIF/IRDA */
  154. # define SCIF_ORER 0x0001 /* overrun error bit */
  155. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  156. #elif defined(CONFIG_CPU_SH7770)
  157. # define SCSPTR0 0xff923020 /* 16 bit SCIF */
  158. # define SCSPTR1 0xff924020 /* 16 bit SCIF */
  159. # define SCSPTR2 0xff925020 /* 16 bit SCIF */
  160. # define SCIF_ORER 0x0001 /* overrun error bit */
  161. # define SCSCR_INIT(port) 0x3c /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,cke=2 */
  162. #elif defined(CONFIG_CPU_SH7780)
  163. # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
  164. # define SCSPTR1 0xffe10024 /* 16 bit SCIF */
  165. # define SCIF_ORER 0x0001 /* Overrun error bit */
  166. #if defined(CONFIG_SH_SH2007)
  167. /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,CKE1=0 */
  168. # define SCSCR_INIT(port) 0x38
  169. #else
  170. /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,CKE1=1 */
  171. # define SCSCR_INIT(port) 0x3a
  172. #endif
  173. #elif defined(CONFIG_CPU_SH7785) || \
  174. defined(CONFIG_CPU_SH7786)
  175. # define SCSPTR0 0xffea0024 /* 16 bit SCIF */
  176. # define SCSPTR1 0xffeb0024 /* 16 bit SCIF */
  177. # define SCSPTR2 0xffec0024 /* 16 bit SCIF */
  178. # define SCSPTR3 0xffed0024 /* 16 bit SCIF */
  179. # define SCSPTR4 0xffee0024 /* 16 bit SCIF */
  180. # define SCSPTR5 0xffef0024 /* 16 bit SCIF */
  181. # define SCIF_ORER 0x0001 /* Overrun error bit */
  182. # define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  183. #elif defined(CONFIG_CPU_SH7201) || \
  184. defined(CONFIG_CPU_SH7203) || \
  185. defined(CONFIG_CPU_SH7206) || \
  186. defined(CONFIG_CPU_SH7263) || \
  187. defined(CONFIG_CPU_SH7264)
  188. # define SCSPTR0 0xfffe8020 /* 16 bit SCIF */
  189. # define SCSPTR1 0xfffe8820 /* 16 bit SCIF */
  190. # define SCSPTR2 0xfffe9020 /* 16 bit SCIF */
  191. # define SCSPTR3 0xfffe9820 /* 16 bit SCIF */
  192. # if defined(CONFIG_CPU_SH7201)
  193. # define SCSPTR4 0xfffeA020 /* 16 bit SCIF */
  194. # define SCSPTR5 0xfffeA820 /* 16 bit SCIF */
  195. # define SCSPTR6 0xfffeB020 /* 16 bit SCIF */
  196. # define SCSPTR7 0xfffeB820 /* 16 bit SCIF */
  197. # endif
  198. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  199. #elif defined(CONFIG_CPU_SH7269)
  200. # define SCSPTR0 0xe8007020 /* 16 bit SCIF */
  201. # define SCSPTR1 0xe8007820 /* 16 bit SCIF */
  202. # define SCSPTR2 0xe8008020 /* 16 bit SCIF */
  203. # define SCSPTR3 0xe8008820 /* 16 bit SCIF */
  204. # define SCSPTR4 0xe8009020 /* 16 bit SCIF */
  205. # define SCSPTR5 0xe8009820 /* 16 bit SCIF */
  206. # define SCSPTR6 0xe800a020 /* 16 bit SCIF */
  207. # define SCSPTR7 0xe800a820 /* 16 bit SCIF */
  208. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  209. #elif defined(CONFIG_CPU_SH7619)
  210. # define SCSPTR0 0xf8400020 /* 16 bit SCIF */
  211. # define SCSPTR1 0xf8410020 /* 16 bit SCIF */
  212. # define SCSPTR2 0xf8420020 /* 16 bit SCIF */
  213. # define SCIF_ORER 0x0001 /* overrun error bit */
  214. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  215. #elif defined(CONFIG_CPU_SHX3)
  216. # define SCSPTR0 0xffc30020 /* 16 bit SCIF */
  217. # define SCSPTR1 0xffc40020 /* 16 bit SCIF */
  218. # define SCSPTR2 0xffc50020 /* 16 bit SCIF */
  219. # define SCSPTR3 0xffc60020 /* 16 bit SCIF */
  220. # define SCIF_ORER 0x0001 /* Overrun error bit */
  221. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  222. #elif defined(CONFIG_R8A7790) || defined(CONFIG_R8A7791) || \
  223. defined(CONFIG_R8A7793) || defined(CONFIG_R8A7794)
  224. # define SCIF_ORER 0x0001
  225. # define SCSCR_INIT(port) 0x32 /* TIE=0,RIE=0,TE=1,RE=1,REIE=0, */
  226. #else
  227. # error CPU subtype not defined
  228. #endif
  229. /* SCSCR */
  230. #define SCI_CTRL_FLAGS_TIE 0x80 /* all */
  231. #define SCI_CTRL_FLAGS_RIE 0x40 /* all */
  232. #define SCI_CTRL_FLAGS_TE 0x20 /* all */
  233. #define SCI_CTRL_FLAGS_RE 0x10 /* all */
  234. #if defined(CONFIG_CPU_SH7750) || \
  235. defined(CONFIG_CPU_SH7091) || \
  236. defined(CONFIG_CPU_SH7750R) || \
  237. defined(CONFIG_CPU_SH7722) || \
  238. defined(CONFIG_CPU_SH7734) || \
  239. defined(CONFIG_CPU_SH7750S) || \
  240. defined(CONFIG_CPU_SH7751) || \
  241. defined(CONFIG_CPU_SH7751R) || \
  242. defined(CONFIG_CPU_SH7763) || \
  243. defined(CONFIG_CPU_SH7780) || \
  244. defined(CONFIG_CPU_SH7785) || \
  245. defined(CONFIG_CPU_SH7786) || \
  246. defined(CONFIG_CPU_SHX3)
  247. #define SCI_CTRL_FLAGS_REIE 0x08 /* 7750 SCIF */
  248. #elif defined(CONFIG_CPU_SH7724)
  249. #define SCI_CTRL_FLAGS_REIE ((port)->type == PORT_SCIFA ? 0 : 8)
  250. #else
  251. #define SCI_CTRL_FLAGS_REIE 0
  252. #endif
  253. /* SCI_CTRL_FLAGS_MPIE 0x08 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  254. /* SCI_CTRL_FLAGS_TEIE 0x04 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  255. /* SCI_CTRL_FLAGS_CKE1 0x02 * all */
  256. /* SCI_CTRL_FLAGS_CKE0 0x01 * 7707 SCI/SCIF, 7708 SCI, 7709 SCI/SCIF, 7750 SCI */
  257. /* SCxSR SCI */
  258. #define SCI_TDRE 0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  259. #define SCI_RDRF 0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  260. #define SCI_ORER 0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  261. #define SCI_FER 0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  262. #define SCI_PER 0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  263. #define SCI_TEND 0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  264. /* SCI_MPB 0x02 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  265. /* SCI_MPBT 0x01 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  266. #define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
  267. /* SCxSR SCIF */
  268. #define SCIF_ER 0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  269. #define SCIF_TEND 0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  270. #define SCIF_TDFE 0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  271. #define SCIF_BRK 0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  272. #define SCIF_FER 0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  273. #define SCIF_PER 0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  274. #define SCIF_RDF 0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  275. #define SCIF_DR 0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  276. #if defined(CONFIG_CPU_SH7705) || \
  277. defined(CONFIG_CPU_SH7720) || \
  278. defined(CONFIG_CPU_SH7721) || \
  279. defined(CONFIG_ARCH_SH7367) || \
  280. defined(CONFIG_ARCH_SH7377) || \
  281. defined(CONFIG_ARCH_SH7372) || \
  282. defined(CONFIG_SH73A0) || \
  283. defined(CONFIG_R8A7740)
  284. # define SCIF_ORER 0x0200
  285. # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
  286. # define SCIF_RFDC_MASK 0x007f
  287. # define SCIF_TXROOM_MAX 64
  288. #elif defined(CONFIG_CPU_SH7763)
  289. # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
  290. # define SCIF_RFDC_MASK 0x007f
  291. # define SCIF_TXROOM_MAX 64
  292. /* SH7763 SCIF2 support */
  293. # define SCIF2_RFDC_MASK 0x001f
  294. # define SCIF2_TXROOM_MAX 16
  295. #elif defined(CONFIG_R8A7790) || defined(CONFIG_R8A7791) || \
  296. defined(CONFIG_R8A7793) || defined(CONFIG_R8A7794)
  297. # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
  298. # define SCIF_RFDC_MASK 0x003f
  299. #else
  300. # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
  301. # define SCIF_RFDC_MASK 0x001f
  302. # define SCIF_TXROOM_MAX 16
  303. #endif
  304. #ifndef SCIF_ORER
  305. #define SCIF_ORER 0x0000
  306. #endif
  307. #define SCxSR_TEND(port)\
  308. (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
  309. #define SCxSR_ERRORS(port)\
  310. (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
  311. #define SCxSR_RDxF(port)\
  312. (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
  313. #define SCxSR_TDxE(port)\
  314. (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
  315. #define SCxSR_FER(port)\
  316. (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
  317. #define SCxSR_PER(port)\
  318. (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
  319. #define SCxSR_BRK(port)\
  320. ((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
  321. #define SCxSR_ORER(port)\
  322. (((port)->type == PORT_SCI) ? SCI_ORER : SCIF_ORER)
  323. #if defined(CONFIG_CPU_SH7705) || \
  324. defined(CONFIG_CPU_SH7720) || \
  325. defined(CONFIG_CPU_SH7721) || \
  326. defined(CONFIG_ARCH_SH7367) || \
  327. defined(CONFIG_ARCH_SH7377) || \
  328. defined(CONFIG_ARCH_SH7372) || \
  329. defined(CONFIG_SH73A0) || \
  330. defined(CONFIG_R8A7740)
  331. # define SCxSR_RDxF_CLEAR(port) (sci_in(port, SCxSR) & 0xfffc)
  332. # define SCxSR_ERROR_CLEAR(port) (sci_in(port, SCxSR) & 0xfd73)
  333. # define SCxSR_TDxE_CLEAR(port) (sci_in(port, SCxSR) & 0xffdf)
  334. # define SCxSR_BREAK_CLEAR(port) (sci_in(port, SCxSR) & 0xffe3)
  335. #else
  336. # define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
  337. # define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
  338. # define SCxSR_TDxE_CLEAR(port) (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
  339. # define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
  340. #endif
  341. /* SCFCR */
  342. #define SCFCR_RFRST 0x0002
  343. #define SCFCR_TFRST 0x0004
  344. #define SCFCR_TCRST 0x4000
  345. #define SCFCR_MCE 0x0008
  346. #define SCI_MAJOR 204
  347. #define SCI_MINOR_START 8
  348. /* Generic serial flags */
  349. #define SCI_RX_THROTTLE 0x0000001
  350. #define SCI_MAGIC 0xbabeface
  351. /*
  352. * Events are used to schedule things to happen at timer-interrupt
  353. * time, instead of at rs interrupt time.
  354. */
  355. #define SCI_EVENT_WRITE_WAKEUP 0
  356. #define SCI_IN(size, offset)\
  357. if ((size) == 8) {\
  358. return readb(port->membase + (offset));\
  359. } else {\
  360. return readw(port->membase + (offset));\
  361. }
  362. #define SCI_OUT(size, offset, value)\
  363. if ((size) == 8) {\
  364. writeb(value, port->membase + (offset));\
  365. } else if ((size) == 16) {\
  366. writew(value, port->membase + (offset));\
  367. }
  368. #define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
  369. static inline unsigned int sci_##name##_in(struct uart_port *port) {\
  370. if (port->type == PORT_SCIF || port->type == PORT_SCIFB) {\
  371. SCI_IN(scif_size, scif_offset)\
  372. } else { /* PORT_SCI or PORT_SCIFA */\
  373. SCI_IN(sci_size, sci_offset);\
  374. }\
  375. }\
  376. static inline void sci_##name##_out(struct uart_port *port,\
  377. unsigned int value) {\
  378. if (port->type == PORT_SCIF || port->type == PORT_SCIFB) {\
  379. SCI_OUT(scif_size, scif_offset, value)\
  380. } else { /* PORT_SCI or PORT_SCIFA */\
  381. SCI_OUT(sci_size, sci_offset, value);\
  382. }\
  383. }
  384. #ifdef CONFIG_H8300
  385. /* h8300 don't have SCIF */
  386. #define CPU_SCIF_FNS(name) \
  387. static inline unsigned int sci_##name##_in(struct uart_port *port) {\
  388. return 0;\
  389. }\
  390. static inline void sci_##name##_out(struct uart_port *port,\
  391. unsigned int value) {\
  392. }
  393. #else
  394. #define CPU_SCIF_FNS(name, scif_offset, scif_size) \
  395. static inline unsigned int sci_##name##_in(struct uart_port *port) {\
  396. SCI_IN(scif_size, scif_offset);\
  397. }\
  398. static inline void sci_##name##_out(struct uart_port *port,\
  399. unsigned int value) {\
  400. SCI_OUT(scif_size, scif_offset, value);\
  401. }
  402. #endif
  403. #define CPU_SCI_FNS(name, sci_offset, sci_size)\
  404. static inline unsigned int sci_##name##_in(struct uart_port *port) {\
  405. SCI_IN(sci_size, sci_offset);\
  406. }\
  407. static inline void sci_##name##_out(struct uart_port *port,\
  408. unsigned int value) {\
  409. SCI_OUT(sci_size, sci_offset, value);\
  410. }
  411. #if defined(CONFIG_CPU_SH3) || \
  412. defined(CONFIG_ARCH_SH7367) || \
  413. defined(CONFIG_ARCH_SH7377) || \
  414. defined(CONFIG_ARCH_SH7372) || \
  415. defined(CONFIG_SH73A0) || \
  416. defined(CONFIG_R8A7740)
  417. #if defined(CONFIG_CPU_SH7710) || defined(CONFIG_CPU_SH7712)
  418. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
  419. sh4_sci_offset, sh4_sci_size, \
  420. sh3_scif_offset, sh3_scif_size, \
  421. sh4_scif_offset, sh4_scif_size, \
  422. h8_sci_offset, h8_sci_size) \
  423. CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size,\
  424. sh4_scif_offset, sh4_scif_size)
  425. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
  426. sh4_scif_offset, sh4_scif_size) \
  427. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  428. #elif defined(CONFIG_CPU_SH7705) || \
  429. defined(CONFIG_CPU_SH7720) || \
  430. defined(CONFIG_CPU_SH7721) || \
  431. defined(CONFIG_ARCH_SH7367) || \
  432. defined(CONFIG_ARCH_SH7377) || \
  433. defined(CONFIG_SH73A0)
  434. #define SCIF_FNS(name, scif_offset, scif_size) \
  435. CPU_SCIF_FNS(name, scif_offset, scif_size)
  436. #elif defined(CONFIG_ARCH_SH7372) || \
  437. defined(CONFIG_R8A7740)
  438. #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
  439. sh4_scifb_offset, sh4_scifb_size) \
  440. CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
  441. sh4_scifb_offset, sh4_scifb_size)
  442. #define SCIF_FNS(name, scif_offset, scif_size) \
  443. CPU_SCIF_FNS(name, scif_offset, scif_size)
  444. #else
  445. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
  446. sh4_sci_offset, sh4_sci_size, \
  447. sh3_scif_offset, sh3_scif_size,\
  448. sh4_scif_offset, sh4_scif_size, \
  449. h8_sci_offset, h8_sci_size) \
  450. CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
  451. sh3_scif_offset, sh3_scif_size)
  452. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
  453. sh4_scif_offset, sh4_scif_size) \
  454. CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
  455. #endif
  456. #elif defined(__H8300H__) || defined(__H8300S__)
  457. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
  458. sh4_sci_offset, sh4_sci_size, \
  459. sh3_scif_offset, sh3_scif_size,\
  460. sh4_scif_offset, sh4_scif_size, \
  461. h8_sci_offset, h8_sci_size) \
  462. CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size)
  463. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
  464. sh4_scif_offset, sh4_scif_size) \
  465. CPU_SCIF_FNS(name)
  466. #elif defined(CONFIG_CPU_SH7723) || defined(CONFIG_CPU_SH7724)
  467. #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
  468. sh4_scif_offset, sh4_scif_size) \
  469. CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
  470. sh4_scif_offset, sh4_scif_size)
  471. #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \
  472. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  473. #else
  474. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
  475. sh4_sci_offset, sh4_sci_size, \
  476. sh3_scif_offset, sh3_scif_size,\
  477. sh4_scif_offset, sh4_scif_size, \
  478. h8_sci_offset, h8_sci_size) \
  479. CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size,\
  480. sh4_scif_offset, sh4_scif_size)
  481. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, \
  482. sh4_scif_offset, sh4_scif_size) \
  483. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  484. #endif
  485. #if defined(CONFIG_CPU_SH7705) || \
  486. defined(CONFIG_CPU_SH7720) || \
  487. defined(CONFIG_CPU_SH7721) || \
  488. defined(CONFIG_ARCH_SH7367) || \
  489. defined(CONFIG_ARCH_SH7377) || \
  490. defined(CONFIG_SH73A0)
  491. SCIF_FNS(SCSMR, 0x00, 16)
  492. SCIF_FNS(SCBRR, 0x04, 8)
  493. SCIF_FNS(SCSCR, 0x08, 16)
  494. SCIF_FNS(SCTDSR, 0x0c, 8)
  495. SCIF_FNS(SCFER, 0x10, 16)
  496. SCIF_FNS(SCxSR, 0x14, 16)
  497. SCIF_FNS(SCFCR, 0x18, 16)
  498. SCIF_FNS(SCFDR, 0x1c, 16)
  499. SCIF_FNS(SCxTDR, 0x20, 8)
  500. SCIF_FNS(SCxRDR, 0x24, 8)
  501. SCIF_FNS(SCLSR, 0x00, 0)
  502. #elif defined(CONFIG_ARCH_SH7372) || \
  503. defined(CONFIG_R8A7740)
  504. SCIF_FNS(SCSMR, 0x00, 16)
  505. SCIF_FNS(SCBRR, 0x04, 8)
  506. SCIF_FNS(SCSCR, 0x08, 16)
  507. SCIF_FNS(SCTDSR, 0x0c, 16)
  508. SCIF_FNS(SCFER, 0x10, 16)
  509. SCIF_FNS(SCxSR, 0x14, 16)
  510. SCIF_FNS(SCFCR, 0x18, 16)
  511. SCIF_FNS(SCFDR, 0x1c, 16)
  512. SCIF_FNS(SCTFDR, 0x38, 16)
  513. SCIF_FNS(SCRFDR, 0x3c, 16)
  514. SCIx_FNS(SCxTDR, 0x20, 8, 0x40, 8)
  515. SCIx_FNS(SCxRDR, 0x24, 8, 0x60, 8)
  516. SCIF_FNS(SCLSR, 0x00, 0)
  517. #elif defined(CONFIG_CPU_SH7723) ||\
  518. defined(CONFIG_CPU_SH7724)
  519. SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16)
  520. SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8)
  521. SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16)
  522. SCIx_FNS(SCxTDR, 0x20, 8, 0x0c, 8)
  523. SCIx_FNS(SCxSR, 0x14, 16, 0x10, 16)
  524. SCIx_FNS(SCxRDR, 0x24, 8, 0x14, 8)
  525. SCIx_FNS(SCSPTR, 0, 0, 0, 0)
  526. SCIF_FNS(SCTDSR, 0x0c, 8)
  527. SCIF_FNS(SCFER, 0x10, 16)
  528. SCIF_FNS(SCFCR, 0x18, 16)
  529. SCIF_FNS(SCFDR, 0x1c, 16)
  530. SCIF_FNS(SCLSR, 0x24, 16)
  531. #else
  532. /* reg SCI/SH3 SCI/SH4 SCIF/SH3 SCIF/SH4 SCI/H8*/
  533. /* name off sz off sz off sz off sz off sz*/
  534. SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16, 0x00, 8)
  535. SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8, 0x01, 8)
  536. SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16, 0x02, 8)
  537. SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8, 0x03, 8)
  538. SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16, 0x04, 8)
  539. SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
  540. SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
  541. #if defined(CONFIG_CPU_SH7760) || \
  542. defined(CONFIG_CPU_SH7780) || \
  543. defined(CONFIG_CPU_SH7785) || \
  544. defined(CONFIG_CPU_SH7786)
  545. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  546. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  547. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  548. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  549. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  550. #elif defined(CONFIG_CPU_SH7763)
  551. SCIF_FNS(SCFDR, 0, 0, 0x1C, 16)
  552. SCIF_FNS(SCSPTR2, 0, 0, 0x20, 16)
  553. SCIF_FNS(SCLSR2, 0, 0, 0x24, 16)
  554. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  555. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  556. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  557. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  558. #else
  559. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  560. #if defined(CONFIG_CPU_SH7722)
  561. SCIF_FNS(SCSPTR, 0, 0, 0, 0)
  562. #else
  563. SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
  564. #endif
  565. #if defined(CONFIG_R8A7790) || defined(CONFIG_R8A7791) || \
  566. defined(CONFIG_R8A7793) || defined(CONFIG_R8A7794)
  567. SCIF_FNS(DL, 0, 0, 0x30, 16)
  568. SCIF_FNS(CKS, 0, 0, 0x34, 16)
  569. #endif
  570. SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
  571. #endif
  572. #endif
  573. #define sci_in(port, reg) sci_##reg##_in(port)
  574. #define sci_out(port, reg, value) sci_##reg##_out(port, value)
  575. /* H8/300 series SCI pins assignment */
  576. #if defined(__H8300H__) || defined(__H8300S__)
  577. static const struct __attribute__((packed)) {
  578. int port; /* GPIO port no */
  579. unsigned short rx, tx; /* GPIO bit no */
  580. } h8300_sci_pins[] = {
  581. #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
  582. { /* SCI0 */
  583. .port = H8300_GPIO_P9,
  584. .rx = H8300_GPIO_B2,
  585. .tx = H8300_GPIO_B0,
  586. },
  587. { /* SCI1 */
  588. .port = H8300_GPIO_P9,
  589. .rx = H8300_GPIO_B3,
  590. .tx = H8300_GPIO_B1,
  591. },
  592. { /* SCI2 */
  593. .port = H8300_GPIO_PB,
  594. .rx = H8300_GPIO_B7,
  595. .tx = H8300_GPIO_B6,
  596. }
  597. #elif defined(CONFIG_H8S2678)
  598. { /* SCI0 */
  599. .port = H8300_GPIO_P3,
  600. .rx = H8300_GPIO_B2,
  601. .tx = H8300_GPIO_B0,
  602. },
  603. { /* SCI1 */
  604. .port = H8300_GPIO_P3,
  605. .rx = H8300_GPIO_B3,
  606. .tx = H8300_GPIO_B1,
  607. },
  608. { /* SCI2 */
  609. .port = H8300_GPIO_P5,
  610. .rx = H8300_GPIO_B1,
  611. .tx = H8300_GPIO_B0,
  612. }
  613. #endif
  614. };
  615. #endif
  616. #if defined(CONFIG_CPU_SH7706) || \
  617. defined(CONFIG_CPU_SH7707) || \
  618. defined(CONFIG_CPU_SH7708) || \
  619. defined(CONFIG_CPU_SH7709)
  620. static inline int sci_rxd_in(struct uart_port *port)
  621. {
  622. if (port->mapbase == 0xfffffe80)
  623. return __raw_readb(SCPDR)&0x01 ? 1 : 0; /* SCI */
  624. return 1;
  625. }
  626. #elif defined(CONFIG_CPU_SH7750) || \
  627. defined(CONFIG_CPU_SH7751) || \
  628. defined(CONFIG_CPU_SH7751R) || \
  629. defined(CONFIG_CPU_SH7750R) || \
  630. defined(CONFIG_CPU_SH7750S) || \
  631. defined(CONFIG_CPU_SH7091)
  632. static inline int sci_rxd_in(struct uart_port *port)
  633. {
  634. if (port->mapbase == 0xffe00000)
  635. return __raw_readb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
  636. return 1;
  637. }
  638. #elif defined(__H8300H__) || defined(__H8300S__)
  639. static inline int sci_rxd_in(struct uart_port *port)
  640. {
  641. int ch = (port->mapbase - SMR0) >> 3;
  642. return (H8300_SCI_DR(ch) & h8300_sci_pins[ch].rx) ? 1 : 0;
  643. }
  644. #else /* default case for non-SCI processors */
  645. static inline int sci_rxd_in(struct uart_port *port)
  646. {
  647. return 1;
  648. }
  649. #endif
  650. /*
  651. * Values for the BitRate Register (SCBRR)
  652. *
  653. * The values are actually divisors for a frequency which can
  654. * be internal to the SH3 (14.7456MHz) or derived from an external
  655. * clock source. This driver assumes the internal clock is used;
  656. * to support using an external clock source, config options or
  657. * possibly command-line options would need to be added.
  658. *
  659. * Also, to support speeds below 2400 (why?) the lower 2 bits of
  660. * the SCSMR register would also need to be set to non-zero values.
  661. *
  662. * -- Greg Banks 27Feb2000
  663. *
  664. * Answer: The SCBRR register is only eight bits, and the value in
  665. * it gets larger with lower baud rates. At around 2400 (depending on
  666. * the peripherial module clock) you run out of bits. However the
  667. * lower two bits of SCSMR allow the module clock to be divided down,
  668. * scaling the value which is needed in SCBRR.
  669. *
  670. * -- Stuart Menefy - 23 May 2000
  671. *
  672. * I meant, why would anyone bother with bitrates below 2400.
  673. *
  674. * -- Greg Banks - 7Jul2000
  675. *
  676. * You "speedist"! How will I use my 110bps ASR-33 teletype with paper
  677. * tape reader as a console!
  678. *
  679. * -- Mitch Davis - 15 Jul 2000
  680. */
  681. #if (defined(CONFIG_CPU_SH7780) || \
  682. defined(CONFIG_CPU_SH7785) || \
  683. defined(CONFIG_CPU_SH7786)) && \
  684. !defined(CONFIG_SH_SH2007)
  685. #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1)
  686. #elif defined(CONFIG_CPU_SH7705) || \
  687. defined(CONFIG_CPU_SH7720) || \
  688. defined(CONFIG_CPU_SH7721) || \
  689. defined(CONFIG_ARCH_SH7367) || \
  690. defined(CONFIG_ARCH_SH7377) || \
  691. defined(CONFIG_ARCH_SH7372) || \
  692. defined(CONFIG_SH73A0) || \
  693. defined(CONFIG_R8A7740)
  694. #define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1)
  695. #elif defined(CONFIG_CPU_SH7723) ||\
  696. defined(CONFIG_CPU_SH7724)
  697. static inline int scbrr_calc(struct uart_port port, int bps, int clk)
  698. {
  699. if (port.type == PORT_SCIF)
  700. return (clk+16*bps)/(32*bps)-1;
  701. else
  702. return ((clk*2)+16*bps)/(16*bps)-1;
  703. }
  704. #define SCBRR_VALUE(bps, clk) scbrr_calc(sh_sci, bps, clk)
  705. #elif defined(__H8300H__) || defined(__H8300S__)
  706. #define SCBRR_VALUE(bps, clk) (((clk*1000/32)/bps)-1)
  707. #elif defined(CONFIG_R8A7790) || defined(CONFIG_R8A7791) || \
  708. defined(CONFIG_R8A7793) || defined(CONFIG_R8A7794)
  709. #define DL_VALUE(bps, clk) (clk / bps / 16) /* External Clock */
  710. #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1) /* Internal Clock */
  711. #else /* Generic SH */
  712. #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1)
  713. #endif