sh-sci.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. #elif defined(CONFIG_CPU_SUBTYPE_SH7705)
  17. # define SCIF0 0xA4400000
  18. # define SCIF2 0xA4410000
  19. # define SCPCR 0xA4000116
  20. # define SCPDR 0xA4000136
  21. #elif defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  22. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  23. defined(CONFIG_ARCH_SH73A0) || \
  24. defined(CONFIG_ARCH_SH7367) || \
  25. defined(CONFIG_ARCH_SH7377) || \
  26. defined(CONFIG_ARCH_SH7372)
  27. # define PORT_PTCR 0xA405011EUL
  28. # define PORT_PVCR 0xA4050122UL
  29. # define SCIF_ORER 0x0200 /* overrun error bit */
  30. #elif defined(CONFIG_SH_RTS7751R2D)
  31. # define SCSPTR1 0xFFE0001C /* 8 bit SCIF */
  32. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  33. # define SCIF_ORER 0x0001 /* overrun error bit */
  34. #elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  35. defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  36. defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
  37. defined(CONFIG_CPU_SUBTYPE_SH7091) || \
  38. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  39. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  40. # define SCSPTR1 0xffe0001c /* 8 bit SCI */
  41. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  42. # define SCIF_ORER 0x0001 /* overrun error bit */
  43. #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
  44. # define SCSPTR0 0xfe600024 /* 16 bit SCIF */
  45. # define SCSPTR1 0xfe610024 /* 16 bit SCIF */
  46. # define SCSPTR2 0xfe620024 /* 16 bit SCIF */
  47. # define SCIF_ORER 0x0001 /* overrun error bit */
  48. #elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
  49. # define SCSPTR0 0xA4400000 /* 16 bit SCIF */
  50. # define SCIF_ORER 0x0001 /* overrun error bit */
  51. # define PACR 0xa4050100
  52. # define PBCR 0xa4050102
  53. #elif defined(CONFIG_CPU_SUBTYPE_SH7343)
  54. # define SCSPTR0 0xffe00010 /* 16 bit SCIF */
  55. # define SCSPTR1 0xffe10010 /* 16 bit SCIF */
  56. # define SCSPTR2 0xffe20010 /* 16 bit SCIF */
  57. # define SCSPTR3 0xffe30010 /* 16 bit SCIF */
  58. #elif defined(CONFIG_CPU_SUBTYPE_SH7722)
  59. # define PADR 0xA4050120
  60. # define PSDR 0xA405013e
  61. # define PWDR 0xA4050166
  62. # define PSCR 0xA405011E
  63. # define SCIF_ORER 0x0001 /* overrun error bit */
  64. #elif defined(CONFIG_CPU_SUBTYPE_SH7366)
  65. # define SCPDR0 0xA405013E /* 16 bit SCIF0 PSDR */
  66. # define SCSPTR0 SCPDR0
  67. # define SCIF_ORER 0x0001 /* overrun error bit */
  68. #elif defined(CONFIG_CPU_SUBTYPE_SH7723)
  69. # define SCSPTR0 0xa4050160
  70. # define SCSPTR1 0xa405013e
  71. # define SCSPTR2 0xa4050160
  72. # define SCSPTR3 0xa405013e
  73. # define SCSPTR4 0xa4050128
  74. # define SCSPTR5 0xa4050128
  75. # define SCIF_ORER 0x0001 /* overrun error bit */
  76. #elif defined(CONFIG_CPU_SUBTYPE_SH7724)
  77. # define SCIF_ORER 0x0001 /* overrun error bit */
  78. #elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
  79. # define SCSPTR2 0xffe80020 /* 16 bit SCIF */
  80. # define SCIF_ORER 0x0001 /* overrun error bit */
  81. #elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
  82. # define SCIF_PTR2_OFFS 0x0000020
  83. # define SCSPTR2 ((port->mapbase)+SCIF_PTR2_OFFS) /* 16 bit SCIF */
  84. #elif defined(CONFIG_H83007) || defined(CONFIG_H83068)
  85. # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
  86. #elif defined(CONFIG_H8S2678)
  87. # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
  88. #elif defined(CONFIG_CPU_SUBTYPE_SH7757)
  89. # define SCSPTR0 0xfe4b0020
  90. # define SCSPTR1 0xfe4b0020
  91. # define SCSPTR2 0xfe4b0020
  92. # define SCIF_ORER 0x0001
  93. # define SCIF_ONLY
  94. #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
  95. # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
  96. # define SCSPTR1 0xffe08024 /* 16 bit SCIF */
  97. # define SCSPTR2 0xffe10020 /* 16 bit SCIF/IRDA */
  98. # define SCIF_ORER 0x0001 /* overrun error bit */
  99. #elif defined(CONFIG_CPU_SUBTYPE_SH7770)
  100. # define SCSPTR0 0xff923020 /* 16 bit SCIF */
  101. # define SCSPTR1 0xff924020 /* 16 bit SCIF */
  102. # define SCSPTR2 0xff925020 /* 16 bit SCIF */
  103. # define SCIF_ORER 0x0001 /* overrun error bit */
  104. #elif defined(CONFIG_CPU_SUBTYPE_SH7780)
  105. # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
  106. # define SCSPTR1 0xffe10024 /* 16 bit SCIF */
  107. # define SCIF_ORER 0x0001 /* Overrun error bit */
  108. #elif defined(CONFIG_CPU_SUBTYPE_SH7785) || \
  109. defined(CONFIG_CPU_SUBTYPE_SH7786)
  110. # define SCSPTR0 0xffea0024 /* 16 bit SCIF */
  111. # define SCSPTR1 0xffeb0024 /* 16 bit SCIF */
  112. # define SCSPTR2 0xffec0024 /* 16 bit SCIF */
  113. # define SCSPTR3 0xffed0024 /* 16 bit SCIF */
  114. # define SCSPTR4 0xffee0024 /* 16 bit SCIF */
  115. # define SCSPTR5 0xffef0024 /* 16 bit SCIF */
  116. # define SCIF_ORER 0x0001 /* Overrun error bit */
  117. #elif defined(CONFIG_CPU_SUBTYPE_SH7201) || \
  118. defined(CONFIG_CPU_SUBTYPE_SH7203) || \
  119. defined(CONFIG_CPU_SUBTYPE_SH7206) || \
  120. defined(CONFIG_CPU_SUBTYPE_SH7263)
  121. # define SCSPTR0 0xfffe8020 /* 16 bit SCIF */
  122. # define SCSPTR1 0xfffe8820 /* 16 bit SCIF */
  123. # define SCSPTR2 0xfffe9020 /* 16 bit SCIF */
  124. # define SCSPTR3 0xfffe9820 /* 16 bit SCIF */
  125. # if defined(CONFIG_CPU_SUBTYPE_SH7201)
  126. # define SCSPTR4 0xfffeA020 /* 16 bit SCIF */
  127. # define SCSPTR5 0xfffeA820 /* 16 bit SCIF */
  128. # define SCSPTR6 0xfffeB020 /* 16 bit SCIF */
  129. # define SCSPTR7 0xfffeB820 /* 16 bit SCIF */
  130. # endif
  131. #elif defined(CONFIG_CPU_SUBTYPE_SH7619)
  132. # define SCSPTR0 0xf8400020 /* 16 bit SCIF */
  133. # define SCSPTR1 0xf8410020 /* 16 bit SCIF */
  134. # define SCSPTR2 0xf8420020 /* 16 bit SCIF */
  135. # define SCIF_ORER 0x0001 /* overrun error bit */
  136. #elif defined(CONFIG_CPU_SUBTYPE_SHX3)
  137. # define SCSPTR0 0xffc30020 /* 16 bit SCIF */
  138. # define SCSPTR1 0xffc40020 /* 16 bit SCIF */
  139. # define SCSPTR2 0xffc50020 /* 16 bit SCIF */
  140. # define SCSPTR3 0xffc60020 /* 16 bit SCIF */
  141. # define SCIF_ORER 0x0001 /* Overrun error bit */
  142. #else
  143. # error CPU subtype not defined
  144. #endif
  145. /* SCxSR SCI */
  146. #define SCI_TDRE 0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  147. #define SCI_RDRF 0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  148. #define SCI_ORER 0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  149. #define SCI_FER 0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  150. #define SCI_PER 0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  151. #define SCI_TEND 0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  152. /* SCI_MPB 0x02 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  153. /* SCI_MPBT 0x01 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  154. #define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
  155. /* SCxSR SCIF */
  156. #define SCIF_ER 0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  157. #define SCIF_TEND 0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  158. #define SCIF_TDFE 0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  159. #define SCIF_BRK 0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  160. #define SCIF_FER 0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  161. #define SCIF_PER 0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  162. #define SCIF_RDF 0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  163. #define SCIF_DR 0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  164. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  165. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  166. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  167. defined(CONFIG_ARCH_SH73A0) || \
  168. defined(CONFIG_ARCH_SH7367) || \
  169. defined(CONFIG_ARCH_SH7377) || \
  170. defined(CONFIG_ARCH_SH7372)
  171. # define SCIF_ORER 0x0200
  172. # define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
  173. # define SCIF_RFDC_MASK 0x007f
  174. # define SCIF_TXROOM_MAX 64
  175. #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
  176. # define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK )
  177. # define SCIF_RFDC_MASK 0x007f
  178. # define SCIF_TXROOM_MAX 64
  179. /* SH7763 SCIF2 support */
  180. # define SCIF2_RFDC_MASK 0x001f
  181. # define SCIF2_TXROOM_MAX 16
  182. #else
  183. # define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
  184. # define SCIF_RFDC_MASK 0x001f
  185. # define SCIF_TXROOM_MAX 16
  186. #endif
  187. #ifndef SCIF_ORER
  188. #define SCIF_ORER 0x0000
  189. #endif
  190. #define SCxSR_TEND(port) (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
  191. #define SCxSR_ERRORS(port) (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
  192. #define SCxSR_RDxF(port) (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
  193. #define SCxSR_TDxE(port) (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
  194. #define SCxSR_FER(port) (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
  195. #define SCxSR_PER(port) (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
  196. #define SCxSR_BRK(port) (((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
  197. #define SCxSR_ORER(port) (((port)->type == PORT_SCI) ? SCI_ORER : SCIF_ORER)
  198. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  199. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  200. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  201. defined(CONFIG_ARCH_SH73A0) || \
  202. defined(CONFIG_ARCH_SH7367) || \
  203. defined(CONFIG_ARCH_SH7377) || \
  204. defined(CONFIG_ARCH_SH7372)
  205. # define SCxSR_RDxF_CLEAR(port) (sci_in(port, SCxSR) & 0xfffc)
  206. # define SCxSR_ERROR_CLEAR(port) (sci_in(port, SCxSR) & 0xfd73)
  207. # define SCxSR_TDxE_CLEAR(port) (sci_in(port, SCxSR) & 0xffdf)
  208. # define SCxSR_BREAK_CLEAR(port) (sci_in(port, SCxSR) & 0xffe3)
  209. #else
  210. # define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
  211. # define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
  212. # define SCxSR_TDxE_CLEAR(port) (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
  213. # define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
  214. #endif
  215. /* SCFCR */
  216. #define SCFCR_RFRST 0x0002
  217. #define SCFCR_TFRST 0x0004
  218. #define SCFCR_MCE 0x0008
  219. #define SCI_MAJOR 204
  220. #define SCI_MINOR_START 8
  221. #define SCI_IN(size, offset) \
  222. if ((size) == 8) { \
  223. return ioread8(port->membase + (offset)); \
  224. } else { \
  225. return ioread16(port->membase + (offset)); \
  226. }
  227. #define SCI_OUT(size, offset, value) \
  228. if ((size) == 8) { \
  229. iowrite8(value, port->membase + (offset)); \
  230. } else if ((size) == 16) { \
  231. iowrite16(value, port->membase + (offset)); \
  232. }
  233. #define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
  234. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  235. { \
  236. if (port->type == PORT_SCIF || port->type == PORT_SCIFB) { \
  237. SCI_IN(scif_size, scif_offset) \
  238. } else { /* PORT_SCI or PORT_SCIFA */ \
  239. SCI_IN(sci_size, sci_offset); \
  240. } \
  241. } \
  242. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  243. { \
  244. if (port->type == PORT_SCIF || port->type == PORT_SCIFB) { \
  245. SCI_OUT(scif_size, scif_offset, value) \
  246. } else { /* PORT_SCI or PORT_SCIFA */ \
  247. SCI_OUT(sci_size, sci_offset, value); \
  248. } \
  249. }
  250. #ifdef CONFIG_H8300
  251. /* h8300 don't have SCIF */
  252. #define CPU_SCIF_FNS(name) \
  253. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  254. { \
  255. return 0; \
  256. } \
  257. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  258. { \
  259. }
  260. #else
  261. #define CPU_SCIF_FNS(name, scif_offset, scif_size) \
  262. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  263. { \
  264. SCI_IN(scif_size, scif_offset); \
  265. } \
  266. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  267. { \
  268. SCI_OUT(scif_size, scif_offset, value); \
  269. }
  270. #endif
  271. #define CPU_SCI_FNS(name, sci_offset, sci_size) \
  272. static inline unsigned int sci_##name##_in(struct uart_port* port) \
  273. { \
  274. SCI_IN(sci_size, sci_offset); \
  275. } \
  276. static inline void sci_##name##_out(struct uart_port* port, unsigned int value) \
  277. { \
  278. SCI_OUT(sci_size, sci_offset, value); \
  279. }
  280. #if defined(CONFIG_CPU_SH3) || \
  281. defined(CONFIG_ARCH_SH73A0) || \
  282. defined(CONFIG_ARCH_SH7367) || \
  283. defined(CONFIG_ARCH_SH7377) || \
  284. defined(CONFIG_ARCH_SH7372)
  285. #if defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
  286. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  287. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  288. h8_sci_offset, h8_sci_size) \
  289. CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
  290. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  291. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  292. #elif defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  293. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  294. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  295. defined(CONFIG_ARCH_SH73A0) || \
  296. defined(CONFIG_ARCH_SH7367) || \
  297. defined(CONFIG_ARCH_SH7377)
  298. #define SCIF_FNS(name, scif_offset, scif_size) \
  299. CPU_SCIF_FNS(name, scif_offset, scif_size)
  300. #elif defined(CONFIG_ARCH_SH7372)
  301. #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scifb_offset, sh4_scifb_size) \
  302. CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scifb_offset, sh4_scifb_size)
  303. #define SCIF_FNS(name, scif_offset, scif_size) \
  304. CPU_SCIF_FNS(name, scif_offset, scif_size)
  305. #else
  306. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  307. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  308. h8_sci_offset, h8_sci_size) \
  309. CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh3_scif_offset, sh3_scif_size)
  310. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  311. CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
  312. #endif
  313. #elif defined(__H8300H__) || defined(__H8300S__)
  314. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  315. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  316. h8_sci_offset, h8_sci_size) \
  317. CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size)
  318. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  319. CPU_SCIF_FNS(name)
  320. #elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\
  321. defined(CONFIG_CPU_SUBTYPE_SH7724)
  322. #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size) \
  323. CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size)
  324. #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \
  325. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  326. #else
  327. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  328. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  329. h8_sci_offset, h8_sci_size) \
  330. CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
  331. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  332. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  333. #endif
  334. #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  335. defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  336. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  337. defined(CONFIG_ARCH_SH73A0) || \
  338. defined(CONFIG_ARCH_SH7367) || \
  339. defined(CONFIG_ARCH_SH7377)
  340. SCIF_FNS(SCSMR, 0x00, 16)
  341. SCIF_FNS(SCBRR, 0x04, 8)
  342. SCIF_FNS(SCSCR, 0x08, 16)
  343. SCIF_FNS(SCxSR, 0x14, 16)
  344. SCIF_FNS(SCFCR, 0x18, 16)
  345. SCIF_FNS(SCFDR, 0x1c, 16)
  346. SCIF_FNS(SCxTDR, 0x20, 8)
  347. SCIF_FNS(SCxRDR, 0x24, 8)
  348. SCIF_FNS(SCLSR, 0x00, 0)
  349. #elif defined(CONFIG_ARCH_SH7372)
  350. SCIF_FNS(SCSMR, 0x00, 16)
  351. SCIF_FNS(SCBRR, 0x04, 8)
  352. SCIF_FNS(SCSCR, 0x08, 16)
  353. SCIF_FNS(SCTDSR, 0x0c, 16)
  354. SCIF_FNS(SCFER, 0x10, 16)
  355. SCIF_FNS(SCxSR, 0x14, 16)
  356. SCIF_FNS(SCFCR, 0x18, 16)
  357. SCIF_FNS(SCFDR, 0x1c, 16)
  358. SCIF_FNS(SCTFDR, 0x38, 16)
  359. SCIF_FNS(SCRFDR, 0x3c, 16)
  360. SCIx_FNS(SCxTDR, 0x20, 8, 0x40, 8)
  361. SCIx_FNS(SCxRDR, 0x24, 8, 0x60, 8)
  362. SCIF_FNS(SCLSR, 0x00, 0)
  363. #elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\
  364. defined(CONFIG_CPU_SUBTYPE_SH7724)
  365. SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16)
  366. SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8)
  367. SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16)
  368. SCIx_FNS(SCxTDR, 0x20, 8, 0x0c, 8)
  369. SCIx_FNS(SCxSR, 0x14, 16, 0x10, 16)
  370. SCIx_FNS(SCxRDR, 0x24, 8, 0x14, 8)
  371. SCIx_FNS(SCSPTR, 0, 0, 0, 0)
  372. SCIF_FNS(SCFCR, 0x18, 16)
  373. SCIF_FNS(SCFDR, 0x1c, 16)
  374. SCIF_FNS(SCLSR, 0x24, 16)
  375. #else
  376. /* reg SCI/SH3 SCI/SH4 SCIF/SH3 SCIF/SH4 SCI/H8*/
  377. /* name off sz off sz off sz off sz off sz*/
  378. SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16, 0x00, 8)
  379. SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8, 0x01, 8)
  380. SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16, 0x02, 8)
  381. SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8, 0x03, 8)
  382. SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16, 0x04, 8)
  383. SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
  384. SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
  385. #if defined(CONFIG_CPU_SUBTYPE_SH7760) || \
  386. defined(CONFIG_CPU_SUBTYPE_SH7780) || \
  387. defined(CONFIG_CPU_SUBTYPE_SH7785) || \
  388. defined(CONFIG_CPU_SUBTYPE_SH7786)
  389. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  390. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  391. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  392. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  393. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  394. #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
  395. SCIF_FNS(SCFDR, 0, 0, 0x1C, 16)
  396. SCIF_FNS(SCSPTR2, 0, 0, 0x20, 16)
  397. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  398. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  399. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  400. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  401. #else
  402. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  403. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  404. SCIF_FNS(SCSPTR, 0, 0, 0, 0)
  405. #else
  406. SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
  407. #endif
  408. SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
  409. #endif
  410. #endif
  411. #define sci_in(port, reg) sci_##reg##_in(port)
  412. #define sci_out(port, reg, value) sci_##reg##_out(port, value)
  413. /* H8/300 series SCI pins assignment */
  414. #if defined(__H8300H__) || defined(__H8300S__)
  415. static const struct __attribute__((packed)) {
  416. int port; /* GPIO port no */
  417. unsigned short rx,tx; /* GPIO bit no */
  418. } h8300_sci_pins[] = {
  419. #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
  420. { /* SCI0 */
  421. .port = H8300_GPIO_P9,
  422. .rx = H8300_GPIO_B2,
  423. .tx = H8300_GPIO_B0,
  424. },
  425. { /* SCI1 */
  426. .port = H8300_GPIO_P9,
  427. .rx = H8300_GPIO_B3,
  428. .tx = H8300_GPIO_B1,
  429. },
  430. { /* SCI2 */
  431. .port = H8300_GPIO_PB,
  432. .rx = H8300_GPIO_B7,
  433. .tx = H8300_GPIO_B6,
  434. }
  435. #elif defined(CONFIG_H8S2678)
  436. { /* SCI0 */
  437. .port = H8300_GPIO_P3,
  438. .rx = H8300_GPIO_B2,
  439. .tx = H8300_GPIO_B0,
  440. },
  441. { /* SCI1 */
  442. .port = H8300_GPIO_P3,
  443. .rx = H8300_GPIO_B3,
  444. .tx = H8300_GPIO_B1,
  445. },
  446. { /* SCI2 */
  447. .port = H8300_GPIO_P5,
  448. .rx = H8300_GPIO_B1,
  449. .tx = H8300_GPIO_B0,
  450. }
  451. #endif
  452. };
  453. #endif
  454. #if defined(CONFIG_CPU_SUBTYPE_SH7706) || \
  455. defined(CONFIG_CPU_SUBTYPE_SH7707) || \
  456. defined(CONFIG_CPU_SUBTYPE_SH7708) || \
  457. defined(CONFIG_CPU_SUBTYPE_SH7709)
  458. static inline int sci_rxd_in(struct uart_port *port)
  459. {
  460. if (port->mapbase == 0xfffffe80)
  461. return __raw_readb(SCPDR)&0x01 ? 1 : 0; /* SCI */
  462. return 1;
  463. }
  464. #elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  465. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  466. defined(CONFIG_CPU_SUBTYPE_SH7751R) || \
  467. defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  468. defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
  469. defined(CONFIG_CPU_SUBTYPE_SH7091)
  470. static inline int sci_rxd_in(struct uart_port *port)
  471. {
  472. if (port->mapbase == 0xffe00000)
  473. return __raw_readb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
  474. return 1;
  475. }
  476. #elif defined(__H8300H__) || defined(__H8300S__)
  477. static inline int sci_rxd_in(struct uart_port *port)
  478. {
  479. int ch = (port->mapbase - SMR0) >> 3;
  480. return (H8300_SCI_DR(ch) & h8300_sci_pins[ch].rx) ? 1 : 0;
  481. }
  482. #else /* default case for non-SCI processors */
  483. static inline int sci_rxd_in(struct uart_port *port)
  484. {
  485. return 1;
  486. }
  487. #endif