sh-sci.h 24 KB

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