serial_sh.h 25 KB

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