serial_sh.h 24 KB

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