sh-sci.h 25 KB

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