serial_sh.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. /*
  2. * Copy and modify from linux/drivers/serial/sh-sci.h
  3. */
  4. #include <dm/platform_data/serial_sh.h>
  5. struct uart_port {
  6. unsigned long iobase; /* in/out[bwl] */
  7. unsigned char *membase; /* read/write[bwl] */
  8. unsigned long mapbase; /* for ioremap */
  9. enum sh_serial_type type; /* port type */
  10. enum sh_clk_mode clk_mode; /* clock mode */
  11. };
  12. #if defined(CONFIG_CPU_SH7721) || \
  13. defined(CONFIG_R8A7740)
  14. # define SCSCR_INIT(port) 0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
  15. # define PORT_PTCR 0xA405011EUL
  16. # define PORT_PVCR 0xA4050122UL
  17. # define SCIF_ORER 0x0200 /* overrun error bit */
  18. #elif defined(CONFIG_CPU_SH7750) || \
  19. defined(CONFIG_CPU_SH7750R) || \
  20. defined(CONFIG_CPU_SH7750S) || \
  21. defined(CONFIG_CPU_SH7751) || \
  22. defined(CONFIG_CPU_SH7751R)
  23. # define SCSPTR1 0xffe0001c /* 8 bit SCI */
  24. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  25. # define SCIF_ORER 0x0001 /* overrun error bit */
  26. # define SCSCR_INIT(port) (((port)->type == PORT_SCI) ? \
  27. 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
  28. 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */)
  29. #elif defined(CONFIG_CPU_SH7722)
  30. # define PADR 0xA4050120
  31. # undef PSDR
  32. # define PSDR 0xA405013e
  33. # define PWDR 0xA4050166
  34. # define PSCR 0xA405011E
  35. # define SCIF_ORER 0x0001 /* overrun error bit */
  36. # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  37. #elif defined(CONFIG_CPU_SH7723)
  38. # define SCSPTR0 0xa4050160
  39. # define SCSPTR1 0xa405013e
  40. # define SCSPTR2 0xa4050160
  41. # define SCSPTR3 0xa405013e
  42. # define SCSPTR4 0xa4050128
  43. # define SCSPTR5 0xa4050128
  44. # define SCIF_ORER 0x0001 /* overrun error bit */
  45. # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  46. #elif defined(CONFIG_CPU_SH7734)
  47. # define SCSPTR0 0xFFE40020
  48. # define SCSPTR1 0xFFE41020
  49. # define SCSPTR2 0xFFE42020
  50. # define SCSPTR3 0xFFE43020
  51. # define SCSPTR4 0xFFE44020
  52. # define SCSPTR5 0xFFE45020
  53. # define SCIF_ORER 0x0001 /* overrun error bit */
  54. # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  55. #elif defined(CONFIG_CPU_SH7757) || \
  56. defined(CONFIG_CPU_SH7752) || \
  57. defined(CONFIG_CPU_SH7753)
  58. # define SCSPTR0 0xfe4b0020
  59. # define SCSPTR1 0xfe4b0020
  60. # define SCSPTR2 0xfe4b0020
  61. # define SCIF_ORER 0x0001
  62. # define SCSCR_INIT(port) 0x38
  63. # define SCIF_ONLY
  64. #elif defined(CONFIG_CPU_SH7763)
  65. # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
  66. # define SCSPTR1 0xffe08024 /* 16 bit SCIF */
  67. # define SCSPTR2 0xffe10020 /* 16 bit SCIF/IRDA */
  68. # define SCIF_ORER 0x0001 /* overrun error bit */
  69. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  70. #elif defined(CONFIG_CPU_SH7780)
  71. # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
  72. # define SCSPTR1 0xffe10024 /* 16 bit SCIF */
  73. # define SCIF_ORER 0x0001 /* Overrun error bit */
  74. /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,CKE1=1 */
  75. # define SCSCR_INIT(port) 0x3a
  76. #elif defined(CONFIG_RZA1)
  77. # define SCSPTR0 0xe8007020 /* 16 bit SCIF */
  78. # define SCSPTR1 0xe8007820 /* 16 bit SCIF */
  79. # define SCSPTR2 0xe8008020 /* 16 bit SCIF */
  80. # define SCSPTR3 0xe8008820 /* 16 bit SCIF */
  81. # define SCSPTR4 0xe8009020 /* 16 bit SCIF */
  82. # define SCSPTR5 0xe8009820 /* 16 bit SCIF */
  83. # define SCSPTR6 0xe800a020 /* 16 bit SCIF */
  84. # define SCSPTR7 0xe800a820 /* 16 bit SCIF */
  85. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  86. # define SCIF_ORER 0x0001 /* overrun error bit */
  87. #elif defined(CONFIG_RCAR_GEN2) || defined(CONFIG_RCAR_64) || \
  88. defined(CONFIG_R7S72100)
  89. # if defined(CFG_SCIF_A)
  90. # define SCIF_ORER 0x0200
  91. # else
  92. # define SCIF_ORER 0x0001
  93. # endif
  94. # define SCSCR_INIT(port) (port->clk_mode == EXT_CLK ? 0x32 : 0x30)
  95. /* TIE=0,RIE=0,TE=1,RE=1,REIE=0, */
  96. #else
  97. # error CPU subtype not defined
  98. #endif
  99. /* SCSCR */
  100. #define SCI_CTRL_FLAGS_TIE 0x80 /* all */
  101. #define SCI_CTRL_FLAGS_RIE 0x40 /* all */
  102. #define SCI_CTRL_FLAGS_TE 0x20 /* all */
  103. #define SCI_CTRL_FLAGS_RE 0x10 /* all */
  104. #if defined(CONFIG_CPU_SH7750) || \
  105. defined(CONFIG_CPU_SH7750R) || \
  106. defined(CONFIG_CPU_SH7722) || \
  107. defined(CONFIG_CPU_SH7734) || \
  108. defined(CONFIG_CPU_SH7750S) || \
  109. defined(CONFIG_CPU_SH7751) || \
  110. defined(CONFIG_CPU_SH7751R) || \
  111. defined(CONFIG_CPU_SH7763) || \
  112. defined(CONFIG_CPU_SH7780)
  113. #define SCI_CTRL_FLAGS_REIE 0x08 /* 7750 SCIF */
  114. #else
  115. #define SCI_CTRL_FLAGS_REIE 0
  116. #endif
  117. /* SCI_CTRL_FLAGS_MPIE 0x08 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  118. /* SCI_CTRL_FLAGS_TEIE 0x04 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  119. /* SCI_CTRL_FLAGS_CKE1 0x02 * all */
  120. /* SCI_CTRL_FLAGS_CKE0 0x01 * 7707 SCI/SCIF, 7708 SCI, 7709 SCI/SCIF, 7750 SCI */
  121. /* SCxSR SCI */
  122. #define SCI_TDRE 0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  123. #define SCI_RDRF 0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  124. #define SCI_ORER 0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  125. #define SCI_FER 0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  126. #define SCI_PER 0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  127. #define SCI_TEND 0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  128. /* SCI_MPB 0x02 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  129. /* SCI_MPBT 0x01 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  130. #define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
  131. /* SCxSR SCIF */
  132. #define SCIF_ER 0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  133. #define SCIF_TEND 0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  134. #define SCIF_TDFE 0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  135. #define SCIF_BRK 0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  136. #define SCIF_FER 0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  137. #define SCIF_PER 0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  138. #define SCIF_RDF 0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  139. #define SCIF_DR 0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  140. #if defined(CONFIG_CPU_SH7721) || \
  141. defined(CONFIG_R8A7740)
  142. # define SCIF_ORER 0x0200
  143. # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
  144. # define SCIF_RFDC_MASK 0x007f
  145. # define SCIF_TXROOM_MAX 64
  146. #elif defined(CONFIG_CPU_SH7763)
  147. # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
  148. # define SCIF_RFDC_MASK 0x007f
  149. # define SCIF_TXROOM_MAX 64
  150. /* SH7763 SCIF2 support */
  151. # define SCIF2_RFDC_MASK 0x001f
  152. # define SCIF2_TXROOM_MAX 16
  153. #elif defined(CONFIG_RCAR_GEN2)
  154. # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
  155. # if defined(CFG_SCIF_A)
  156. # define SCIF_RFDC_MASK 0x007f
  157. # else
  158. # define SCIF_RFDC_MASK 0x001f
  159. # endif
  160. #else
  161. # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
  162. # define SCIF_RFDC_MASK 0x001f
  163. # define SCIF_TXROOM_MAX 16
  164. #endif
  165. #ifndef SCIF_ORER
  166. #define SCIF_ORER 0x0000
  167. #endif
  168. #define SCxSR_TEND(port)\
  169. (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
  170. #define SCxSR_ERRORS(port)\
  171. (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
  172. #define SCxSR_RDxF(port)\
  173. (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
  174. #define SCxSR_TDxE(port)\
  175. (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
  176. #define SCxSR_FER(port)\
  177. (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
  178. #define SCxSR_PER(port)\
  179. (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
  180. #define SCxSR_BRK(port)\
  181. ((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
  182. #define SCxSR_ORER(port)\
  183. (((port)->type == PORT_SCI) ? SCI_ORER : SCIF_ORER)
  184. #if defined(CONFIG_CPU_SH7721) || \
  185. defined(CONFIG_R8A7740)
  186. # define SCxSR_RDxF_CLEAR(port) (sci_in(port, SCxSR) & 0xfffc)
  187. # define SCxSR_ERROR_CLEAR(port) (sci_in(port, SCxSR) & 0xfd73)
  188. # define SCxSR_TDxE_CLEAR(port) (sci_in(port, SCxSR) & 0xffdf)
  189. # define SCxSR_BREAK_CLEAR(port) (sci_in(port, SCxSR) & 0xffe3)
  190. #else
  191. # define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
  192. # define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
  193. # define SCxSR_TDxE_CLEAR(port) (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
  194. # define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
  195. #endif
  196. /* SCFCR */
  197. #define SCFCR_RFRST 0x0002
  198. #define SCFCR_TFRST 0x0004
  199. #define SCFCR_TCRST 0x4000
  200. #define SCFCR_MCE 0x0008
  201. /* HSSRR */
  202. #define HSSRR_SRE BIT(15)
  203. #define HSSRR_SRCYC8 0x0007
  204. #define SCI_MAJOR 204
  205. #define SCI_MINOR_START 8
  206. /* Generic serial flags */
  207. #define SCI_RX_THROTTLE 0x0000001
  208. #define SCI_MAGIC 0xbabeface
  209. /*
  210. * Events are used to schedule things to happen at timer-interrupt
  211. * time, instead of at rs interrupt time.
  212. */
  213. #define SCI_EVENT_WRITE_WAKEUP 0
  214. #define SCI_IN(size, offset)\
  215. if ((size) == 8) {\
  216. return readb(port->membase + (offset));\
  217. } else {\
  218. return readw(port->membase + (offset));\
  219. }
  220. #define SCI_OUT(size, offset, value)\
  221. if ((size) == 8) {\
  222. writeb(value, port->membase + (offset));\
  223. } else if ((size) == 16) {\
  224. writew(value, port->membase + (offset));\
  225. }
  226. #define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
  227. static inline unsigned int sci_##name##_in(struct uart_port *port) {\
  228. if (port->type == PORT_SCIF || port->type == PORT_SCIFB ||\
  229. port->type == PORT_HSCIF) {\
  230. SCI_IN(scif_size, scif_offset)\
  231. } else { /* PORT_SCI or PORT_SCIFA */\
  232. SCI_IN(sci_size, sci_offset);\
  233. }\
  234. }\
  235. static inline void sci_##name##_out(struct uart_port *port,\
  236. unsigned int value) {\
  237. if (port->type == PORT_SCIF || port->type == PORT_SCIFB ||\
  238. port->type == PORT_HSCIF) {\
  239. SCI_OUT(scif_size, scif_offset, value)\
  240. } else { /* PORT_SCI or PORT_SCIFA */\
  241. SCI_OUT(sci_size, sci_offset, value);\
  242. }\
  243. }
  244. #define CPU_SCIF_FNS(name, scif_offset, scif_size) \
  245. static inline unsigned int sci_##name##_in(struct uart_port *port) {\
  246. SCI_IN(scif_size, scif_offset);\
  247. }\
  248. static inline void sci_##name##_out(struct uart_port *port,\
  249. unsigned int value) {\
  250. SCI_OUT(scif_size, scif_offset, value);\
  251. }
  252. #define CPU_SCI_FNS(name, sci_offset, sci_size)\
  253. static inline unsigned int sci_##name##_in(struct uart_port *port) {\
  254. SCI_IN(sci_size, sci_offset);\
  255. }\
  256. static inline void sci_##name##_out(struct uart_port *port,\
  257. unsigned int value) {\
  258. SCI_OUT(sci_size, sci_offset, value);\
  259. }
  260. #if defined(CONFIG_R8A7740)
  261. #if defined(CONFIG_CPU_SH7721) || \
  262. defined(CONFIG_SH73A0)
  263. #define SCIF_FNS(name, scif_offset, scif_size) \
  264. CPU_SCIF_FNS(name, scif_offset, scif_size)
  265. #elif defined(CONFIG_R8A7740)
  266. #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
  267. sh4_scifb_offset, sh4_scifb_size) \
  268. CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
  269. sh4_scifb_offset, sh4_scifb_size)
  270. #define SCIF_FNS(name, scif_offset, scif_size) \
  271. CPU_SCIF_FNS(name, scif_offset, scif_size)
  272. #else
  273. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
  274. sh4_sci_offset, sh4_sci_size, \
  275. sh3_scif_offset, sh3_scif_size,\
  276. sh4_scif_offset, sh4_scif_size, \
  277. h8_sci_offset, h8_sci_size) \
  278. CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
  279. sh3_scif_offset, sh3_scif_size)
  280. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
  281. sh4_scif_offset, sh4_scif_size) \
  282. CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
  283. #endif
  284. #elif defined(CONFIG_CPU_SH7723)
  285. #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
  286. sh4_scif_offset, sh4_scif_size) \
  287. CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
  288. sh4_scif_offset, sh4_scif_size)
  289. #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \
  290. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  291. #else
  292. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
  293. sh4_sci_offset, sh4_sci_size, \
  294. sh3_scif_offset, sh3_scif_size,\
  295. sh4_scif_offset, sh4_scif_size, \
  296. h8_sci_offset, h8_sci_size) \
  297. CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size,\
  298. sh4_scif_offset, sh4_scif_size)
  299. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, \
  300. sh4_scif_offset, sh4_scif_size) \
  301. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  302. #endif
  303. #if defined(CONFIG_CPU_SH7721)
  304. SCIF_FNS(SCSMR, 0x00, 16)
  305. SCIF_FNS(SCBRR, 0x04, 8)
  306. SCIF_FNS(SCSCR, 0x08, 16)
  307. SCIF_FNS(SCTDSR, 0x0c, 8)
  308. SCIF_FNS(SCFER, 0x10, 16)
  309. SCIF_FNS(SCxSR, 0x14, 16)
  310. SCIF_FNS(SCFCR, 0x18, 16)
  311. SCIF_FNS(SCFDR, 0x1c, 16)
  312. SCIF_FNS(SCxTDR, 0x20, 8)
  313. SCIF_FNS(SCxRDR, 0x24, 8)
  314. SCIF_FNS(SCLSR, 0x00, 0)
  315. SCIF_FNS(DL, 0x00, 0) /* dummy */
  316. #elif defined(CONFIG_R8A7740)
  317. SCIF_FNS(SCSMR, 0x00, 16)
  318. SCIF_FNS(SCBRR, 0x04, 8)
  319. SCIF_FNS(SCSCR, 0x08, 16)
  320. SCIF_FNS(SCTDSR, 0x0c, 16)
  321. SCIF_FNS(SCFER, 0x10, 16)
  322. SCIF_FNS(SCxSR, 0x14, 16)
  323. SCIF_FNS(SCFCR, 0x18, 16)
  324. SCIF_FNS(SCFDR, 0x1c, 16)
  325. SCIF_FNS(SCTFDR, 0x38, 16)
  326. SCIF_FNS(SCRFDR, 0x3c, 16)
  327. SCIx_FNS(SCxTDR, 0x20, 8, 0x40, 8)
  328. SCIx_FNS(SCxRDR, 0x24, 8, 0x60, 8)
  329. SCIF_FNS(SCLSR, 0x00, 0)
  330. SCIF_FNS(DL, 0x00, 0) /* dummy */
  331. #elif defined(CONFIG_CPU_SH7723)
  332. SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16)
  333. SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8)
  334. SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16)
  335. SCIx_FNS(SCxTDR, 0x20, 8, 0x0c, 8)
  336. SCIx_FNS(SCxSR, 0x14, 16, 0x10, 16)
  337. SCIx_FNS(SCxRDR, 0x24, 8, 0x14, 8)
  338. SCIx_FNS(SCSPTR, 0, 0, 0, 0)
  339. SCIF_FNS(SCTDSR, 0x0c, 8)
  340. SCIF_FNS(SCFER, 0x10, 16)
  341. SCIF_FNS(SCFCR, 0x18, 16)
  342. SCIF_FNS(SCFDR, 0x1c, 16)
  343. SCIF_FNS(SCLSR, 0x24, 16)
  344. SCIF_FNS(DL, 0x00, 0) /* dummy */
  345. #elif defined(CONFIG_RCAR_GEN2)
  346. /* SCIFA and SCIF register offsets and size */
  347. SCIx_FNS(SCSMR, 0, 0, 0x00, 16, 0, 0, 0x00, 16, 0, 0)
  348. SCIx_FNS(SCBRR, 0, 0, 0x04, 8, 0, 0, 0x04, 8, 0, 0)
  349. SCIx_FNS(SCSCR, 0, 0, 0x08, 16, 0, 0, 0x08, 16, 0, 0)
  350. SCIx_FNS(SCxTDR, 0, 0, 0x20, 8, 0, 0, 0x0C, 8, 0, 0)
  351. SCIx_FNS(SCxSR, 0, 0, 0x14, 16, 0, 0, 0x10, 16, 0, 0)
  352. SCIx_FNS(SCxRDR, 0, 0, 0x24, 8, 0, 0, 0x14, 8, 0, 0)
  353. SCIF_FNS(SCFCR, 0, 0, 0x18, 16)
  354. SCIF_FNS(SCFDR, 0, 0, 0x1C, 16)
  355. SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
  356. SCIF_FNS(DL, 0, 0, 0x30, 16)
  357. SCIF_FNS(CKS, 0, 0, 0x34, 16)
  358. SCIF_FNS(HSSRR, 0, 0, 0x40, 16) /* HSCIF only */
  359. #if defined(CFG_SCIF_A)
  360. SCIF_FNS(SCLSR, 0, 0, 0x14, 16)
  361. #else
  362. SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
  363. #endif
  364. #else
  365. /* reg SCI/SH3 SCI/SH4 SCIF/SH3 SCIF/SH4 SCI/H8*/
  366. /* name off sz off sz off sz off sz off sz*/
  367. SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16, 0x00, 8)
  368. SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8, 0x01, 8)
  369. SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16, 0x02, 8)
  370. SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8, 0x03, 8)
  371. SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16, 0x04, 8)
  372. SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
  373. SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
  374. #if defined(CONFIG_CPU_SH7780)
  375. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  376. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  377. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  378. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  379. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  380. #elif defined(CONFIG_CPU_SH7763)
  381. SCIF_FNS(SCFDR, 0, 0, 0x1C, 16)
  382. SCIF_FNS(SCSPTR2, 0, 0, 0x20, 16)
  383. SCIF_FNS(SCLSR2, 0, 0, 0x24, 16)
  384. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  385. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  386. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  387. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  388. #else
  389. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  390. #if defined(CONFIG_CPU_SH7722)
  391. SCIF_FNS(SCSPTR, 0, 0, 0, 0)
  392. #else
  393. SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
  394. #endif
  395. SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
  396. #endif
  397. SCIF_FNS(DL, 0, 0, 0x30, 16)
  398. SCIF_FNS(CKS, 0, 0, 0x34, 16)
  399. SCIF_FNS(HSSRR, 0, 0, 0x40, 16) /* HSCIF only */
  400. #endif
  401. #define sci_in(port, reg) sci_##reg##_in(port)
  402. #define sci_out(port, reg, value) sci_##reg##_out(port, value)
  403. #if defined(CONFIG_CPU_SH7750) || \
  404. defined(CONFIG_CPU_SH7751) || \
  405. defined(CONFIG_CPU_SH7751R) || \
  406. defined(CONFIG_CPU_SH7750R) || \
  407. defined(CONFIG_CPU_SH7750S)
  408. static inline int sci_rxd_in(struct uart_port *port)
  409. {
  410. if (port->mapbase == 0xffe00000)
  411. return __raw_readb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
  412. return 1;
  413. }
  414. #else /* default case for non-SCI processors */
  415. static inline int sci_rxd_in(struct uart_port *port)
  416. {
  417. return 1;
  418. }
  419. #endif
  420. /*
  421. * Values for the BitRate Register (SCBRR)
  422. *
  423. * The values are actually divisors for a frequency which can
  424. * be internal to the SH3 (14.7456MHz) or derived from an external
  425. * clock source. This driver assumes the internal clock is used;
  426. * to support using an external clock source, config options or
  427. * possibly command-line options would need to be added.
  428. *
  429. * Also, to support speeds below 2400 (why?) the lower 2 bits of
  430. * the SCSMR register would also need to be set to non-zero values.
  431. *
  432. * -- Greg Banks 27Feb2000
  433. *
  434. * Answer: The SCBRR register is only eight bits, and the value in
  435. * it gets larger with lower baud rates. At around 2400 (depending on
  436. * the peripherial module clock) you run out of bits. However the
  437. * lower two bits of SCSMR allow the module clock to be divided down,
  438. * scaling the value which is needed in SCBRR.
  439. *
  440. * -- Stuart Menefy - 23 May 2000
  441. *
  442. * I meant, why would anyone bother with bitrates below 2400.
  443. *
  444. * -- Greg Banks - 7Jul2000
  445. *
  446. * You "speedist"! How will I use my 110bps ASR-33 teletype with paper
  447. * tape reader as a console!
  448. *
  449. * -- Mitch Davis - 15 Jul 2000
  450. */
  451. #if defined(CONFIG_CPU_SH7780)
  452. #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1)
  453. #elif defined(CONFIG_CPU_SH7721) || \
  454. defined(CONFIG_R8A7740)
  455. #define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1)
  456. #elif defined(CONFIG_CPU_SH7723)
  457. static inline int scbrr_calc(struct uart_port *port, int bps, int clk)
  458. {
  459. if (port->type == PORT_SCIF)
  460. return (clk+16*bps)/(32*bps)-1;
  461. else
  462. return ((clk*2)+16*bps)/(16*bps)-1;
  463. }
  464. #define SCBRR_VALUE(bps, clk) scbrr_calc(port, bps, clk)
  465. #elif defined(CONFIG_RCAR_GEN2)
  466. #define DL_VALUE(bps, clk) (clk / bps / 16) /* External Clock */
  467. #if defined(CFG_SCIF_A) || defined(CFG_HSCIF)
  468. #define SCBRR_VALUE(bps, clk) (clk / bps / 16 - 1) /* Internal Clock */
  469. #else
  470. #define SCBRR_VALUE(bps, clk) (clk / bps / 32 - 1) /* Internal Clock */
  471. #endif
  472. #elif defined(CONFIG_RCAR_64)
  473. static inline int scbrr_calc(struct uart_port *port, int bps, int clk)
  474. {
  475. if (port->type == PORT_SCIF)
  476. return (clk + 16 * bps) / (32 * bps) - 1;
  477. else /* PORT_HSCIF */
  478. return clk / bps / 8 / 2 - 1; /* Internal Clock, Sampling rate = 8 */
  479. }
  480. #define SCBRR_VALUE(bps, clk) scbrr_calc(port, bps, clk)
  481. #else /* Generic SH */
  482. #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1)
  483. #endif
  484. #ifndef DL_VALUE
  485. #define DL_VALUE(bps, clk) 0
  486. #endif