sh-sci.h 25 KB

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