serial_sh.h 24 KB

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