sh-sci.h 22 KB

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