sh-sci.h 24 KB

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