sh-sci.h 22 KB

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