sh-sci.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /* $Id: sh-sci.h,v 1.4 2004/02/19 16:43:56 lethal Exp $
  2. *
  3. * linux/drivers/serial/sh-sci.h
  4. *
  5. * SuperH on-chip serial module support. (SCI with no FIFO / with FIFO)
  6. * Copyright (C) 1999, 2000 Niibe Yutaka
  7. * Copyright (C) 2000 Greg Banks
  8. * Copyright (C) 2002, 2003 Paul Mundt
  9. * Modified to support multiple serial ports. Stuart Menefy (May 2000).
  10. * Modified to support SH7300(SH-Mobile) SCIF. Takashi Kusuda (Jun 2003).
  11. * Modified to support H8/300 Series Yoshinori Sato (Feb 2004).
  12. */
  13. #include <linux/serial_core.h>
  14. #include <asm/io.h>
  15. #if defined(__H8300H__) || defined(__H8300S__)
  16. #include <asm/gpio.h>
  17. #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
  18. #include <asm/regs306x.h>
  19. #endif
  20. #if defined(CONFIG_H8S2678)
  21. #include <asm/regs267x.h>
  22. #endif
  23. #endif
  24. #if defined(CONFIG_CPU_SUBTYPE_SH7708)
  25. # define SCSPTR 0xffffff7c /* 8 bit */
  26. # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
  27. # define SCI_ONLY
  28. #elif defined(CONFIG_CPU_SUBTYPE_SH7707) || \
  29. defined(CONFIG_CPU_SUBTYPE_SH7709) || \
  30. defined(CONFIG_CPU_SUBTYPE_SH7706)
  31. # define SCPCR 0xA4000116 /* 16 bit SCI and SCIF */
  32. # define SCPDR 0xA4000136 /* 8 bit SCI and SCIF */
  33. # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
  34. # define SCI_AND_SCIF
  35. #elif defined(CONFIG_CPU_SUBTYPE_SH7705)
  36. # define SCIF0 0xA4400000
  37. # define SCIF2 0xA4410000
  38. # define SCSMR_Ir 0xA44A0000
  39. # define IRDA_SCIF SCIF0
  40. # define SCPCR 0xA4000116
  41. # define SCPDR 0xA4000136
  42. /* Set the clock source,
  43. * SCIF2 (0xA4410000) -> External clock, SCK pin used as clock input
  44. * SCIF0 (0xA4400000) -> Internal clock, SCK pin as serial clock output
  45. */
  46. # define SCSCR_INIT(port) (port->mapbase == SCIF2) ? 0xF3 : 0xF0
  47. # define SCIF_ONLY
  48. #elif defined(CONFIG_SH_RTS7751R2D)
  49. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  50. # define SCIF_ORER 0x0001 /* overrun error bit */
  51. # define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  52. # define SCIF_ONLY
  53. #elif defined(CONFIG_CPU_SUBTYPE_SH7750) || defined(CONFIG_CPU_SUBTYPE_SH7751)
  54. # define SCSPTR1 0xffe0001c /* 8 bit SCI */
  55. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  56. # define SCIF_ORER 0x0001 /* overrun error bit */
  57. # define SCSCR_INIT(port) (((port)->type == PORT_SCI) ? \
  58. 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
  59. 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */ )
  60. # define SCI_AND_SCIF
  61. #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
  62. # define SCSPTR0 0xfe600024 /* 16 bit SCIF */
  63. # define SCSPTR1 0xfe610024 /* 16 bit SCIF */
  64. # define SCSPTR2 0xfe620024 /* 16 bit SCIF */
  65. # define SCIF_ORER 0x0001 /* overrun error bit */
  66. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  67. # define SCIF_ONLY
  68. #elif defined(CONFIG_CPU_SUBTYPE_SH7300)
  69. # define SCPCR 0xA4050116 /* 16 bit SCIF */
  70. # define SCPDR 0xA4050136 /* 16 bit SCIF */
  71. # define SCSCR_INIT(port) 0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
  72. # define SCIF_ONLY
  73. #elif defined(CONFIG_CPU_SUBTYPE_SH7710)
  74. # define SCSPTR0 0xA4400000 /* 16 bit SCIF */
  75. # define SCSCR_INIT(port) 0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
  76. # define SCIF_ONLY
  77. #elif defined(CONFIG_CPU_SUBTYPE_SH73180)
  78. # define SCPDR 0xA4050138 /* 16 bit SCIF */
  79. # define SCSPTR2 SCPDR
  80. # define SCIF_ORER 0x0001 /* overrun error bit */
  81. # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1 */
  82. # define SCIF_ONLY
  83. #elif defined(CONFIG_CPU_SUBTYPE_SH7343)
  84. # define SCSPTR0 0xffe00010 /* 16 bit SCIF */
  85. # define SCSPTR1 0xffe10010 /* 16 bit SCIF */
  86. # define SCSPTR2 0xffe20010 /* 16 bit SCIF */
  87. # define SCSPTR3 0xffe30010 /* 16 bit SCIF */
  88. # define SCSCR_INIT(port) 0x32 /* TIE=0,RIE=0,TE=1,RE=1,REIE=0,CKE=1 */
  89. # define SCIF_ONLY
  90. #elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
  91. # define SCSPTR2 0xffe80020 /* 16 bit SCIF */
  92. # define SCIF_ORER 0x0001 /* overrun error bit */
  93. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  94. # define SCIF_ONLY
  95. #elif defined(CONFIG_CPU_SUBTYPE_ST40STB1)
  96. # define SCSPTR1 0xffe00020 /* 16 bit SCIF */
  97. # define SCSPTR2 0xffe80020 /* 16 bit SCIF */
  98. # define SCIF_ORER 0x0001 /* overrun error bit */
  99. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  100. # define SCIF_ONLY
  101. #elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
  102. # include <asm/hardware.h>
  103. # define SCIF_BASE_ADDR 0x01030000
  104. # define SCIF_ADDR_SH5 PHYS_PERIPHERAL_BLOCK+SCIF_BASE_ADDR
  105. # define SCIF_PTR2_OFFS 0x0000020
  106. # define SCIF_LSR2_OFFS 0x0000024
  107. # define SCSPTR2 ((port->mapbase)+SCIF_PTR2_OFFS) /* 16 bit SCIF */
  108. # define SCLSR2 ((port->mapbase)+SCIF_LSR2_OFFS) /* 16 bit SCIF */
  109. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,
  110. TE=1,RE=1,REIE=1 */
  111. # define SCIF_ONLY
  112. #elif defined(CONFIG_H83007) || defined(CONFIG_H83068)
  113. # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
  114. # define SCI_ONLY
  115. # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
  116. #elif defined(CONFIG_H8S2678)
  117. # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
  118. # define SCI_ONLY
  119. # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
  120. #elif defined(CONFIG_CPU_SUBTYPE_SH7770)
  121. # define SCSPTR0 0xff923020 /* 16 bit SCIF */
  122. # define SCSPTR1 0xff924020 /* 16 bit SCIF */
  123. # define SCSPTR2 0xff925020 /* 16 bit SCIF */
  124. # define SCIF_ORER 0x0001 /* overrun error bit */
  125. # define SCSCR_INIT(port) 0x3c /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,cke=2 */
  126. # define SCIF_ONLY
  127. #elif defined(CONFIG_CPU_SUBTYPE_SH7780)
  128. # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
  129. # define SCSPTR1 0xffe10024 /* 16 bit SCIF */
  130. # define SCIF_ORER 0x0001 /* Overrun error bit */
  131. # define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  132. # define SCIF_ONLY
  133. #elif defined(CONFIG_CPU_SUBTYPE_SH7206)
  134. # define SCSPTR0 0xfffe8020 /* 16 bit SCIF */
  135. # define SCSPTR1 0xfffe8820 /* 16 bit SCIF */
  136. # define SCSPTR2 0xfffe9020 /* 16 bit SCIF */
  137. # define SCSPTR3 0xfffe9820 /* 16 bit SCIF */
  138. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  139. # define SCIF_ONLY
  140. #elif defined(CONFIG_CPU_SUBTYPE_SH7619)
  141. # define SCSPTR0 0xf8400020 /* 16 bit SCIF */
  142. # define SCSPTR1 0xf8410020 /* 16 bit SCIF */
  143. # define SCSPTR2 0xf8420020 /* 16 bit SCIF */
  144. # define SCIF_ORER 0x0001 /* overrun error bit */
  145. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  146. # define SCIF_ONLY
  147. #else
  148. # error CPU subtype not defined
  149. #endif
  150. /* SCSCR */
  151. #define SCI_CTRL_FLAGS_TIE 0x80 /* all */
  152. #define SCI_CTRL_FLAGS_RIE 0x40 /* all */
  153. #define SCI_CTRL_FLAGS_TE 0x20 /* all */
  154. #define SCI_CTRL_FLAGS_RE 0x10 /* all */
  155. #if defined(CONFIG_CPU_SUBTYPE_SH7750) || defined(CONFIG_CPU_SUBTYPE_SH7751) || defined(CONFIG_CPU_SUBTYPE_SH7780)
  156. #define SCI_CTRL_FLAGS_REIE 0x08 /* 7750 SCIF */
  157. #else
  158. #define SCI_CTRL_FLAGS_REIE 0
  159. #endif
  160. /* SCI_CTRL_FLAGS_MPIE 0x08 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  161. /* SCI_CTRL_FLAGS_TEIE 0x04 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  162. /* SCI_CTRL_FLAGS_CKE1 0x02 * all */
  163. /* SCI_CTRL_FLAGS_CKE0 0x01 * 7707 SCI/SCIF, 7708 SCI, 7709 SCI/SCIF, 7750 SCI */
  164. /* SCxSR SCI */
  165. #define SCI_TDRE 0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  166. #define SCI_RDRF 0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  167. #define SCI_ORER 0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  168. #define SCI_FER 0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  169. #define SCI_PER 0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  170. #define SCI_TEND 0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  171. /* SCI_MPB 0x02 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  172. /* SCI_MPBT 0x01 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
  173. #define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
  174. /* SCxSR SCIF */
  175. #define SCIF_ER 0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  176. #define SCIF_TEND 0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  177. #define SCIF_TDFE 0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  178. #define SCIF_BRK 0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  179. #define SCIF_FER 0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  180. #define SCIF_PER 0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  181. #define SCIF_RDF 0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  182. #define SCIF_DR 0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
  183. #if defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7705)
  184. #define SCIF_ORER 0x0200
  185. #define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
  186. #define SCIF_RFDC_MASK 0x007f
  187. #define SCIF_TXROOM_MAX 64
  188. #else
  189. #define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
  190. #define SCIF_RFDC_MASK 0x001f
  191. #define SCIF_TXROOM_MAX 16
  192. #endif
  193. #if defined(SCI_ONLY)
  194. # define SCxSR_TEND(port) SCI_TEND
  195. # define SCxSR_ERRORS(port) SCI_ERRORS
  196. # define SCxSR_RDxF(port) SCI_RDRF
  197. # define SCxSR_TDxE(port) SCI_TDRE
  198. # define SCxSR_ORER(port) SCI_ORER
  199. # define SCxSR_FER(port) SCI_FER
  200. # define SCxSR_PER(port) SCI_PER
  201. # define SCxSR_BRK(port) 0x00
  202. # define SCxSR_RDxF_CLEAR(port) 0xbc
  203. # define SCxSR_ERROR_CLEAR(port) 0xc4
  204. # define SCxSR_TDxE_CLEAR(port) 0x78
  205. # define SCxSR_BREAK_CLEAR(port) 0xc4
  206. #elif defined(SCIF_ONLY)
  207. # define SCxSR_TEND(port) SCIF_TEND
  208. # define SCxSR_ERRORS(port) SCIF_ERRORS
  209. # define SCxSR_RDxF(port) SCIF_RDF
  210. # define SCxSR_TDxE(port) SCIF_TDFE
  211. #if defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7705)
  212. # define SCxSR_ORER(port) SCIF_ORER
  213. #else
  214. # define SCxSR_ORER(port) 0x0000
  215. #endif
  216. # define SCxSR_FER(port) SCIF_FER
  217. # define SCxSR_PER(port) SCIF_PER
  218. # define SCxSR_BRK(port) SCIF_BRK
  219. #if defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7705)
  220. # define SCxSR_RDxF_CLEAR(port) (sci_in(port,SCxSR)&0xfffc)
  221. # define SCxSR_ERROR_CLEAR(port) (sci_in(port,SCxSR)&0xfd73)
  222. # define SCxSR_TDxE_CLEAR(port) (sci_in(port,SCxSR)&0xffdf)
  223. # define SCxSR_BREAK_CLEAR(port) (sci_in(port,SCxSR)&0xffe3)
  224. #else
  225. /* SH7705 can also use this, clearing is same between 7705 and 7709 and 7300 */
  226. # define SCxSR_RDxF_CLEAR(port) 0x00fc
  227. # define SCxSR_ERROR_CLEAR(port) 0x0073
  228. # define SCxSR_TDxE_CLEAR(port) 0x00df
  229. # define SCxSR_BREAK_CLEAR(port) 0x00e3
  230. #endif
  231. #else
  232. # define SCxSR_TEND(port) (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
  233. # define SCxSR_ERRORS(port) (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
  234. # define SCxSR_RDxF(port) (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
  235. # define SCxSR_TDxE(port) (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
  236. # define SCxSR_ORER(port) (((port)->type == PORT_SCI) ? SCI_ORER : 0x0000)
  237. # define SCxSR_FER(port) (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
  238. # define SCxSR_PER(port) (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
  239. # define SCxSR_BRK(port) (((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
  240. # define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
  241. # define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
  242. # define SCxSR_TDxE_CLEAR(port) (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
  243. # define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
  244. #endif
  245. /* SCFCR */
  246. #define SCFCR_RFRST 0x0002
  247. #define SCFCR_TFRST 0x0004
  248. #define SCFCR_TCRST 0x4000
  249. #define SCFCR_MCE 0x0008
  250. #define SCI_MAJOR 204
  251. #define SCI_MINOR_START 8
  252. /* Generic serial flags */
  253. #define SCI_RX_THROTTLE 0x0000001
  254. #define SCI_MAGIC 0xbabeface
  255. /*
  256. * Events are used to schedule things to happen at timer-interrupt
  257. * time, instead of at rs interrupt time.
  258. */
  259. #define SCI_EVENT_WRITE_WAKEUP 0
  260. #define SCI_IN(size, offset) \
  261. unsigned int addr = port->mapbase + (offset); \
  262. if ((size) == 8) { \
  263. return ctrl_inb(addr); \
  264. } else { \
  265. return ctrl_inw(addr); \
  266. }
  267. #define SCI_OUT(size, offset, value) \
  268. unsigned int addr = port->mapbase + (offset); \
  269. if ((size) == 8) { \
  270. ctrl_outb(value, addr); \
  271. } else { \
  272. ctrl_outw(value, addr); \
  273. }
  274. #define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
  275. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  276. { \
  277. if (port->type == PORT_SCI) { \
  278. SCI_IN(sci_size, sci_offset) \
  279. } else { \
  280. SCI_IN(scif_size, scif_offset); \
  281. } \
  282. } \
  283. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  284. { \
  285. if (port->type == PORT_SCI) { \
  286. SCI_OUT(sci_size, sci_offset, value) \
  287. } else { \
  288. SCI_OUT(scif_size, scif_offset, value); \
  289. } \
  290. }
  291. #define CPU_SCIF_FNS(name, scif_offset, scif_size) \
  292. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  293. { \
  294. SCI_IN(scif_size, scif_offset); \
  295. } \
  296. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  297. { \
  298. SCI_OUT(scif_size, scif_offset, value); \
  299. }
  300. #define CPU_SCI_FNS(name, sci_offset, sci_size) \
  301. static inline unsigned int sci_##name##_in(struct uart_port* port) \
  302. { \
  303. SCI_IN(sci_size, sci_offset); \
  304. } \
  305. static inline void sci_##name##_out(struct uart_port* port, unsigned int value) \
  306. { \
  307. SCI_OUT(sci_size, sci_offset, value); \
  308. }
  309. #ifdef CONFIG_CPU_SH3
  310. #if defined(CONFIG_CPU_SUBTYPE_SH7300) || \
  311. defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  312. defined(CONFIG_CPU_SUBTYPE_SH7710)
  313. #define SCIF_FNS(name, scif_offset, scif_size) \
  314. CPU_SCIF_FNS(name, scif_offset, scif_size)
  315. #else
  316. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  317. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  318. h8_sci_offset, h8_sci_size) \
  319. CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh3_scif_offset, sh3_scif_size)
  320. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  321. CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
  322. #endif
  323. #elif defined(__H8300H__) || defined(__H8300S__)
  324. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  325. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  326. h8_sci_offset, h8_sci_size) \
  327. CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size)
  328. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size)
  329. #else
  330. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  331. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  332. h8_sci_offset, h8_sci_size) \
  333. CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
  334. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  335. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  336. #endif
  337. #if defined(CONFIG_CPU_SUBTYPE_SH7300) || \
  338. defined(CONFIG_CPU_SUBTYPE_SH7705) || \
  339. defined(CONFIG_CPU_SUBTYPE_SH7710)
  340. SCIF_FNS(SCSMR, 0x00, 16)
  341. SCIF_FNS(SCBRR, 0x04, 8)
  342. SCIF_FNS(SCSCR, 0x08, 16)
  343. SCIF_FNS(SCTDSR, 0x0c, 8)
  344. SCIF_FNS(SCFER, 0x10, 16)
  345. SCIF_FNS(SCxSR, 0x14, 16)
  346. SCIF_FNS(SCFCR, 0x18, 16)
  347. SCIF_FNS(SCFDR, 0x1c, 16)
  348. SCIF_FNS(SCxTDR, 0x20, 8)
  349. SCIF_FNS(SCxRDR, 0x24, 8)
  350. SCIF_FNS(SCLSR, 0x24, 16)
  351. #else
  352. /* reg SCI/SH3 SCI/SH4 SCIF/SH3 SCIF/SH4 SCI/H8*/
  353. /* name off sz off sz off sz off sz off sz*/
  354. SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16, 0x00, 8)
  355. SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8, 0x01, 8)
  356. SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16, 0x02, 8)
  357. SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8, 0x03, 8)
  358. SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16, 0x04, 8)
  359. SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
  360. SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
  361. #if defined(CONFIG_CPU_SUBTYPE_SH7760) || defined(CONFIG_CPU_SUBTYPE_SH7780)
  362. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  363. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  364. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  365. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  366. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  367. #else
  368. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  369. SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
  370. SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
  371. #endif
  372. #endif
  373. #define sci_in(port, reg) sci_##reg##_in(port)
  374. #define sci_out(port, reg, value) sci_##reg##_out(port, value)
  375. /* H8/300 series SCI pins assignment */
  376. #if defined(__H8300H__) || defined(__H8300S__)
  377. static const struct __attribute__((packed)) {
  378. int port; /* GPIO port no */
  379. unsigned short rx,tx; /* GPIO bit no */
  380. } h8300_sci_pins[] = {
  381. #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
  382. { /* SCI0 */
  383. .port = H8300_GPIO_P9,
  384. .rx = H8300_GPIO_B2,
  385. .tx = H8300_GPIO_B0,
  386. },
  387. { /* SCI1 */
  388. .port = H8300_GPIO_P9,
  389. .rx = H8300_GPIO_B3,
  390. .tx = H8300_GPIO_B1,
  391. },
  392. { /* SCI2 */
  393. .port = H8300_GPIO_PB,
  394. .rx = H8300_GPIO_B7,
  395. .tx = H8300_GPIO_B6,
  396. }
  397. #elif defined(CONFIG_H8S2678)
  398. { /* SCI0 */
  399. .port = H8300_GPIO_P3,
  400. .rx = H8300_GPIO_B2,
  401. .tx = H8300_GPIO_B0,
  402. },
  403. { /* SCI1 */
  404. .port = H8300_GPIO_P3,
  405. .rx = H8300_GPIO_B3,
  406. .tx = H8300_GPIO_B1,
  407. },
  408. { /* SCI2 */
  409. .port = H8300_GPIO_P5,
  410. .rx = H8300_GPIO_B1,
  411. .tx = H8300_GPIO_B0,
  412. }
  413. #endif
  414. };
  415. #endif
  416. #if defined(CONFIG_CPU_SUBTYPE_SH7708)
  417. static inline int sci_rxd_in(struct uart_port *port)
  418. {
  419. if (port->mapbase == 0xfffffe80)
  420. return ctrl_inb(SCSPTR)&0x01 ? 1 : 0; /* SCI */
  421. return 1;
  422. }
  423. #elif defined(CONFIG_CPU_SUBTYPE_SH7707) || \
  424. defined(CONFIG_CPU_SUBTYPE_SH7709) || \
  425. defined(CONFIG_CPU_SUBTYPE_SH7706)
  426. static inline int sci_rxd_in(struct uart_port *port)
  427. {
  428. if (port->mapbase == 0xfffffe80)
  429. return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCI */
  430. if (port->mapbase == 0xa4000150)
  431. return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
  432. if (port->mapbase == 0xa4000140)
  433. return ctrl_inb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
  434. return 1;
  435. }
  436. #elif defined(CONFIG_CPU_SUBTYPE_SH7705)
  437. static inline int sci_rxd_in(struct uart_port *port)
  438. {
  439. if (port->mapbase == SCIF0)
  440. return ctrl_inb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
  441. if (port->mapbase == SCIF2)
  442. return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
  443. return 1;
  444. }
  445. #elif defined(CONFIG_CPU_SUBTYPE_SH7710)
  446. static inline int sci_rxd_in(struct uart_port *port)
  447. {
  448. if (port->mapbase == SCSPTR0)
  449. return ctrl_inw(SCSPTR0 + 0x10) & 0x01 ? 1 : 0;
  450. return 1;
  451. }
  452. #elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  453. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  454. defined(CONFIG_CPU_SUBTYPE_SH4_202)
  455. static inline int sci_rxd_in(struct uart_port *port)
  456. {
  457. #ifndef SCIF_ONLY
  458. if (port->mapbase == 0xffe00000)
  459. return ctrl_inb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
  460. #endif
  461. #ifndef SCI_ONLY
  462. if (port->mapbase == 0xffe80000)
  463. return ctrl_inw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
  464. #endif
  465. return 1;
  466. }
  467. #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
  468. static inline int sci_rxd_in(struct uart_port *port)
  469. {
  470. if (port->mapbase == 0xfe600000)
  471. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  472. if (port->mapbase == 0xfe610000)
  473. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  474. if (port->mapbase == 0xfe620000)
  475. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  476. return 1;
  477. }
  478. #elif defined(CONFIG_CPU_SUBTYPE_SH7300)
  479. static inline int sci_rxd_in(struct uart_port *port)
  480. {
  481. if (port->mapbase == 0xa4430000)
  482. return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCIF0 */
  483. return 1;
  484. }
  485. #elif defined(CONFIG_CPU_SUBTYPE_SH73180)
  486. static inline int sci_rxd_in(struct uart_port *port)
  487. {
  488. return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCIF0 */
  489. }
  490. #elif defined(CONFIG_CPU_SUBTYPE_SH7343)
  491. static inline int sci_rxd_in(struct uart_port *port)
  492. {
  493. if (port->mapbase == 0xffe00000)
  494. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  495. if (port->mapbase == 0xffe10000)
  496. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  497. if (port->mapbase == 0xffe20000)
  498. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  499. if (port->mapbase == 0xffe30000)
  500. return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
  501. return 1;
  502. }
  503. #elif defined(CONFIG_CPU_SUBTYPE_ST40STB1)
  504. static inline int sci_rxd_in(struct uart_port *port)
  505. {
  506. if (port->mapbase == 0xffe00000)
  507. return ctrl_inw(SCSPTR1)&0x0001 ? 1 : 0; /* SCIF */
  508. else
  509. return ctrl_inw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
  510. }
  511. #elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
  512. static inline int sci_rxd_in(struct uart_port *port)
  513. {
  514. return sci_in(port, SCSPTR)&0x0001 ? 1 : 0; /* SCIF */
  515. }
  516. #elif defined(__H8300H__) || defined(__H8300S__)
  517. static inline int sci_rxd_in(struct uart_port *port)
  518. {
  519. int ch = (port->mapbase - SMR0) >> 3;
  520. return (H8300_SCI_DR(ch) & h8300_sci_pins[ch].rx) ? 1 : 0;
  521. }
  522. #elif defined(CONFIG_CPU_SUBTYPE_SH7770)
  523. static inline int sci_rxd_in(struct uart_port *port)
  524. {
  525. if (port->mapbase == 0xff923000)
  526. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  527. if (port->mapbase == 0xff924000)
  528. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  529. if (port->mapbase == 0xff925000)
  530. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  531. return 1;
  532. }
  533. #elif defined(CONFIG_CPU_SUBTYPE_SH7780)
  534. static inline int sci_rxd_in(struct uart_port *port)
  535. {
  536. if (port->mapbase == 0xffe00000)
  537. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  538. if (port->mapbase == 0xffe10000)
  539. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  540. return 1;
  541. }
  542. #elif defined(CONFIG_CPU_SUBTYPE_SH7206)
  543. static inline int sci_rxd_in(struct uart_port *port)
  544. {
  545. if (port->mapbase == 0xfffe8000)
  546. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  547. if (port->mapbase == 0xfffe8800)
  548. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  549. if (port->mapbase == 0xfffe9000)
  550. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  551. if (port->mapbase == 0xfffe9800)
  552. return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
  553. return 1;
  554. }
  555. #elif defined(CONFIG_CPU_SUBTYPE_SH7619)
  556. static inline int sci_rxd_in(struct uart_port *port)
  557. {
  558. if (port->mapbase == 0xf8400000)
  559. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  560. if (port->mapbase == 0xf8410000)
  561. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  562. if (port->mapbase == 0xf8420000)
  563. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  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_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7780)
  599. #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1)
  600. #elif defined(CONFIG_CPU_SUBTYPE_SH7705)
  601. #define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1)
  602. #elif defined(__H8300H__) || defined(__H8300S__)
  603. #define SCBRR_VALUE(bps) (((CONFIG_CPU_CLOCK*1000/32)/bps)-1)
  604. #elif defined(CONFIG_SUPERH64)
  605. #define SCBRR_VALUE(bps) ((current_cpu_data.module_clock+16*bps)/(32*bps)-1)
  606. #else /* Generic SH */
  607. #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1)
  608. #endif