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/config.h>
  14. #include <linux/serial_core.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. /* Offsets into the sci_port->irqs array */
  25. #define SCIx_ERI_IRQ 0
  26. #define SCIx_RXI_IRQ 1
  27. #define SCIx_TXI_IRQ 2
  28. /* ERI, RXI, TXI, BRI */
  29. #define SCI_IRQS { 23, 24, 25, 0 }
  30. #define SH3_SCIF_IRQS { 56, 57, 59, 58 }
  31. #define SH3_IRDA_IRQS { 52, 53, 55, 54 }
  32. #define SH4_SCIF_IRQS { 40, 41, 43, 42 }
  33. #define STB1_SCIF1_IRQS {23, 24, 26, 25 }
  34. #define SH7760_SCIF0_IRQS { 52, 53, 55, 54 }
  35. #define SH7760_SCIF1_IRQS { 72, 73, 75, 74 }
  36. #define SH7760_SCIF2_IRQS { 76, 77, 79, 78 }
  37. #define SH7300_SCIF0_IRQS {80, 80, 80, 80 }
  38. #define SH73180_SCIF_IRQS {80, 81, 83, 82 }
  39. #define H8300H_SCI_IRQS0 {52, 53, 54, 0 }
  40. #define H8300H_SCI_IRQS1 {56, 57, 58, 0 }
  41. #define H8300H_SCI_IRQS2 {60, 61, 62, 0 }
  42. #define H8S_SCI_IRQS0 {88, 89, 90, 0 }
  43. #define H8S_SCI_IRQS1 {92, 93, 94, 0 }
  44. #define H8S_SCI_IRQS2 {96, 97, 98, 0 }
  45. #define SH5_SCIF_IRQS {39, 40, 42, 0 }
  46. #define SH7770_SCIF0_IRQS {61, 61, 61, 61 }
  47. #define SH7770_SCIF1_IRQS {62, 62, 62, 62 }
  48. #define SH7770_SCIF2_IRQS {63, 63, 63, 63 }
  49. #define SH7780_SCIF0_IRQS {40, 41, 43, 42 }
  50. #define SH7780_SCIF1_IRQS {76, 77, 79, 78 }
  51. #if defined(CONFIG_CPU_SUBTYPE_SH7708)
  52. # define SCSPTR 0xffffff7c /* 8 bit */
  53. # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
  54. # define SCI_ONLY
  55. #elif defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709)
  56. # define SCPCR 0xA4000116 /* 16 bit SCI and SCIF */
  57. # define SCPDR 0xA4000136 /* 8 bit SCI and SCIF */
  58. # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
  59. # define SCI_AND_SCIF
  60. #elif defined(CONFIG_CPU_SUBTYPE_SH7705)
  61. # define SCIF0 0xA4400000
  62. # define SCIF2 0xA4410000
  63. # define SCSMR_Ir 0xA44A0000
  64. # define IRDA_SCIF SCIF0
  65. # define SCPCR 0xA4000116
  66. # define SCPDR 0xA4000136
  67. /* Set the clock source,
  68. * SCIF2 (0xA4410000) -> External clock, SCK pin used as clock input
  69. * SCIF0 (0xA4400000) -> Internal clock, SCK pin as serial clock output
  70. */
  71. # define SCSCR_INIT(port) (port->mapbase == SCIF2) ? 0xF3 : 0xF0
  72. # define SCIF_ONLY
  73. #elif defined(CONFIG_SH_RTS7751R2D)
  74. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  75. # define SCIF_ORER 0x0001 /* overrun error bit */
  76. # define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  77. # define SCIF_ONLY
  78. #elif defined(CONFIG_CPU_SUBTYPE_SH7750) || defined(CONFIG_CPU_SUBTYPE_SH7751)
  79. # define SCSPTR1 0xffe0001c /* 8 bit SCI */
  80. # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
  81. # define SCIF_ORER 0x0001 /* overrun error bit */
  82. # define SCSCR_INIT(port) (((port)->type == PORT_SCI) ? \
  83. 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
  84. 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */ )
  85. # define SCI_AND_SCIF
  86. #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
  87. # define SCSPTR0 0xfe600024 /* 16 bit SCIF */
  88. # define SCSPTR1 0xfe610024 /* 16 bit SCIF */
  89. # define SCSPTR2 0xfe620024 /* 16 bit SCIF */
  90. # define SCIF_ORER 0x0001 /* overrun error bit */
  91. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  92. # define SCIF_ONLY
  93. #elif defined(CONFIG_CPU_SUBTYPE_SH7300)
  94. # define SCPCR 0xA4050116 /* 16 bit SCIF */
  95. # define SCPDR 0xA4050136 /* 16 bit SCIF */
  96. # define SCSCR_INIT(port) 0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
  97. # define SCIF_ONLY
  98. #elif defined(CONFIG_CPU_SUBTYPE_SH73180)
  99. # define SCPDR 0xA4050138 /* 16 bit SCIF */
  100. # define SCSPTR2 SCPDR
  101. # define SCIF_ORER 0x0001 /* overrun error bit */
  102. # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1 */
  103. # define SCIF_ONLY
  104. #elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
  105. # define SCSPTR2 0xffe80020 /* 16 bit SCIF */
  106. # define SCIF_ORER 0x0001 /* overrun error bit */
  107. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  108. # define SCIF_ONLY
  109. #elif defined(CONFIG_CPU_SUBTYPE_ST40STB1)
  110. # define SCSPTR1 0xffe00020 /* 16 bit SCIF */
  111. # define SCSPTR2 0xffe80020 /* 16 bit SCIF */
  112. # define SCIF_ORER 0x0001 /* overrun error bit */
  113. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
  114. # define SCIF_ONLY
  115. #elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
  116. # include <asm/hardware.h>
  117. # define SCIF_BASE_ADDR 0x01030000
  118. # define SCIF_ADDR_SH5 PHYS_PERIPHERAL_BLOCK+SCIF_BASE_ADDR
  119. # define SCIF_PTR2_OFFS 0x0000020
  120. # define SCIF_LSR2_OFFS 0x0000024
  121. # define SCSPTR2 ((port->mapbase)+SCIF_PTR2_OFFS) /* 16 bit SCIF */
  122. # define SCLSR2 ((port->mapbase)+SCIF_LSR2_OFFS) /* 16 bit SCIF */
  123. # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,
  124. TE=1,RE=1,REIE=1 */
  125. # define SCIF_ONLY
  126. #elif defined(CONFIG_H83007) || defined(CONFIG_H83068)
  127. # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
  128. # define SCI_ONLY
  129. # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
  130. #elif defined(CONFIG_H8S2678)
  131. # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
  132. # define SCI_ONLY
  133. # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
  134. #elif defined(CONFIG_CPU_SUBTYPE_SH7770)
  135. # define SCSPTR0 0xff923020 /* 16 bit SCIF */
  136. # define SCSPTR1 0xff924020 /* 16 bit SCIF */
  137. # define SCSPTR2 0xff925020 /* 16 bit SCIF */
  138. # define SCIF_ORER 0x0001 /* overrun error bit */
  139. # define SCSCR_INIT(port) 0x3c /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,cke=2 */
  140. # define SCIF_ONLY
  141. #elif defined(CONFIG_CPU_SUBTYPE_SH7780)
  142. # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
  143. # define SCSPTR1 0xffe10024 /* 16 bit SCIF */
  144. # define SCIF_OPER 0x0001 /* Overrun error bit */
  145. # define SCSCR_INIT(port) 0x3a /* 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. struct sci_port {
  261. struct uart_port port;
  262. int type;
  263. unsigned char irqs[4]; /* ERI, RXI, TXI, BRI */
  264. void (*init_pins)(struct uart_port *port, unsigned int cflag);
  265. int break_flag;
  266. struct timer_list break_timer;
  267. };
  268. #define SCI_IN(size, offset) \
  269. unsigned int addr = port->mapbase + (offset); \
  270. if ((size) == 8) { \
  271. return ctrl_inb(addr); \
  272. } else { \
  273. return ctrl_inw(addr); \
  274. }
  275. #define SCI_OUT(size, offset, value) \
  276. unsigned int addr = port->mapbase + (offset); \
  277. if ((size) == 8) { \
  278. ctrl_outb(value, addr); \
  279. } else { \
  280. ctrl_outw(value, addr); \
  281. }
  282. #define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
  283. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  284. { \
  285. if (port->type == PORT_SCI) { \
  286. SCI_IN(sci_size, sci_offset) \
  287. } else { \
  288. SCI_IN(scif_size, scif_offset); \
  289. } \
  290. } \
  291. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  292. { \
  293. if (port->type == PORT_SCI) { \
  294. SCI_OUT(sci_size, sci_offset, value) \
  295. } else { \
  296. SCI_OUT(scif_size, scif_offset, value); \
  297. } \
  298. }
  299. #define CPU_SCIF_FNS(name, scif_offset, scif_size) \
  300. static inline unsigned int sci_##name##_in(struct uart_port *port) \
  301. { \
  302. SCI_IN(scif_size, scif_offset); \
  303. } \
  304. static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
  305. { \
  306. SCI_OUT(scif_size, scif_offset, value); \
  307. }
  308. #define CPU_SCI_FNS(name, sci_offset, sci_size) \
  309. static inline unsigned int sci_##name##_in(struct uart_port* port) \
  310. { \
  311. SCI_IN(sci_size, sci_offset); \
  312. } \
  313. static inline void sci_##name##_out(struct uart_port* port, unsigned int value) \
  314. { \
  315. SCI_OUT(sci_size, sci_offset, value); \
  316. }
  317. #ifdef CONFIG_CPU_SH3
  318. #if defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7705)
  319. #define SCIF_FNS(name, scif_offset, scif_size) \
  320. CPU_SCIF_FNS(name, scif_offset, scif_size)
  321. #else
  322. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  323. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  324. h8_sci_offset, h8_sci_size) \
  325. CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh3_scif_offset, sh3_scif_size)
  326. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  327. CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
  328. #endif
  329. #elif defined(__H8300H__) || defined(__H8300S__)
  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_SCI_FNS(name, h8_sci_offset, h8_sci_size)
  334. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size)
  335. #else
  336. #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
  337. sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
  338. h8_sci_offset, h8_sci_size) \
  339. CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
  340. #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
  341. CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
  342. #endif
  343. #if defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7705)
  344. SCIF_FNS(SCSMR, 0x00, 16)
  345. SCIF_FNS(SCBRR, 0x04, 8)
  346. SCIF_FNS(SCSCR, 0x08, 16)
  347. SCIF_FNS(SCTDSR, 0x0c, 8)
  348. SCIF_FNS(SCFER, 0x10, 16)
  349. SCIF_FNS(SCxSR, 0x14, 16)
  350. SCIF_FNS(SCFCR, 0x18, 16)
  351. SCIF_FNS(SCFDR, 0x1c, 16)
  352. SCIF_FNS(SCxTDR, 0x20, 8)
  353. SCIF_FNS(SCxRDR, 0x24, 8)
  354. SCIF_FNS(SCLSR, 0x24, 16)
  355. #else
  356. /* reg SCI/SH3 SCI/SH4 SCIF/SH3 SCIF/SH4 SCI/H8*/
  357. /* name off sz off sz off sz off sz off sz*/
  358. SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16, 0x00, 8)
  359. SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8, 0x01, 8)
  360. SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16, 0x02, 8)
  361. SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8, 0x03, 8)
  362. SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16, 0x04, 8)
  363. SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
  364. SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
  365. #if defined(CONFIG_CPU_SUBTYPE_SH7760) || defined(CONFIG_CPU_SUBTYPE_SH7780)
  366. SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
  367. SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
  368. SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
  369. SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
  370. #else
  371. SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
  372. SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
  373. SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
  374. #endif
  375. #endif
  376. #define sci_in(port, reg) sci_##reg##_in(port)
  377. #define sci_out(port, reg, value) sci_##reg##_out(port, value)
  378. /* H8/300 series SCI pins assignment */
  379. #if defined(__H8300H__) || defined(__H8300S__)
  380. static const struct __attribute__((packed)) {
  381. int port; /* GPIO port no */
  382. unsigned short rx,tx; /* GPIO bit no */
  383. } h8300_sci_pins[] = {
  384. #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
  385. { /* SCI0 */
  386. .port = H8300_GPIO_P9,
  387. .rx = H8300_GPIO_B2,
  388. .tx = H8300_GPIO_B0,
  389. },
  390. { /* SCI1 */
  391. .port = H8300_GPIO_P9,
  392. .rx = H8300_GPIO_B3,
  393. .tx = H8300_GPIO_B1,
  394. },
  395. { /* SCI2 */
  396. .port = H8300_GPIO_PB,
  397. .rx = H8300_GPIO_B7,
  398. .tx = H8300_GPIO_B6,
  399. }
  400. #elif defined(CONFIG_H8S2678)
  401. { /* SCI0 */
  402. .port = H8300_GPIO_P3,
  403. .rx = H8300_GPIO_B2,
  404. .tx = H8300_GPIO_B0,
  405. },
  406. { /* SCI1 */
  407. .port = H8300_GPIO_P3,
  408. .rx = H8300_GPIO_B3,
  409. .tx = H8300_GPIO_B1,
  410. },
  411. { /* SCI2 */
  412. .port = H8300_GPIO_P5,
  413. .rx = H8300_GPIO_B1,
  414. .tx = H8300_GPIO_B0,
  415. }
  416. #endif
  417. };
  418. #endif
  419. #if defined(CONFIG_CPU_SUBTYPE_SH7708)
  420. static inline int sci_rxd_in(struct uart_port *port)
  421. {
  422. if (port->mapbase == 0xfffffe80)
  423. return ctrl_inb(SCSPTR)&0x01 ? 1 : 0; /* SCI */
  424. return 1;
  425. }
  426. #elif defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709)
  427. static inline int sci_rxd_in(struct uart_port *port)
  428. {
  429. if (port->mapbase == 0xfffffe80)
  430. return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCI */
  431. if (port->mapbase == 0xa4000150)
  432. return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
  433. if (port->mapbase == 0xa4000140)
  434. return ctrl_inb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
  435. return 1;
  436. }
  437. #elif defined(CONFIG_CPU_SUBTYPE_SH7705)
  438. static inline int sci_rxd_in(struct uart_port *port)
  439. {
  440. if (port->mapbase == SCIF0)
  441. return ctrl_inb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
  442. if (port->mapbase == SCIF2)
  443. return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
  444. return 1;
  445. }
  446. #elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  447. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  448. defined(CONFIG_CPU_SUBTYPE_SH4_202)
  449. static inline int sci_rxd_in(struct uart_port *port)
  450. {
  451. #ifndef SCIF_ONLY
  452. if (port->mapbase == 0xffe00000)
  453. return ctrl_inb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
  454. #endif
  455. #ifndef SCI_ONLY
  456. if (port->mapbase == 0xffe80000)
  457. return ctrl_inw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
  458. #endif
  459. return 1;
  460. }
  461. #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
  462. static inline int sci_rxd_in(struct uart_port *port)
  463. {
  464. if (port->mapbase == 0xfe600000)
  465. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  466. if (port->mapbase == 0xfe610000)
  467. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  468. if (port->mapbase == 0xfe620000)
  469. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  470. }
  471. #elif defined(CONFIG_CPU_SUBTYPE_SH7300)
  472. static inline int sci_rxd_in(struct uart_port *port)
  473. {
  474. if (port->mapbase == 0xa4430000)
  475. return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCIF0 */
  476. return 1;
  477. }
  478. #elif defined(CONFIG_CPU_SUBTYPE_SH73180)
  479. static inline int sci_rxd_in(struct uart_port *port)
  480. {
  481. return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCIF0 */
  482. }
  483. #elif defined(CONFIG_CPU_SUBTYPE_ST40STB1)
  484. static inline int sci_rxd_in(struct uart_port *port)
  485. {
  486. if (port->mapbase == 0xffe00000)
  487. return ctrl_inw(SCSPTR1)&0x0001 ? 1 : 0; /* SCIF */
  488. else
  489. return ctrl_inw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
  490. }
  491. #elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
  492. static inline int sci_rxd_in(struct uart_port *port)
  493. {
  494. return sci_in(port, SCSPTR)&0x0001 ? 1 : 0; /* SCIF */
  495. }
  496. #elif defined(__H8300H__) || defined(__H8300S__)
  497. static inline int sci_rxd_in(struct uart_port *port)
  498. {
  499. int ch = (port->mapbase - SMR0) >> 3;
  500. return (H8300_SCI_DR(ch) & h8300_sci_pins[ch].rx) ? 1 : 0;
  501. }
  502. #elif defined(CONFIG_CPU_SUBTYPE_SH7770)
  503. static inline int sci_rxd_in(struct uart_port *port)
  504. {
  505. if (port->mapbase == 0xff923000)
  506. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  507. if (port->mapbase == 0xff924000)
  508. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  509. if (port->mapbase == 0xff925000)
  510. return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
  511. }
  512. #elif defined(CONFIG_CPU_SUBTYPE_SH7780)
  513. static inline int sci_rxd_in(struct uart_port *port)
  514. {
  515. if (port->mapbase == 0xffe00000)
  516. return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
  517. if (port->mapbase == 0xffe10000)
  518. return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
  519. }
  520. #endif
  521. /*
  522. * Values for the BitRate Register (SCBRR)
  523. *
  524. * The values are actually divisors for a frequency which can
  525. * be internal to the SH3 (14.7456MHz) or derived from an external
  526. * clock source. This driver assumes the internal clock is used;
  527. * to support using an external clock source, config options or
  528. * possibly command-line options would need to be added.
  529. *
  530. * Also, to support speeds below 2400 (why?) the lower 2 bits of
  531. * the SCSMR register would also need to be set to non-zero values.
  532. *
  533. * -- Greg Banks 27Feb2000
  534. *
  535. * Answer: The SCBRR register is only eight bits, and the value in
  536. * it gets larger with lower baud rates. At around 2400 (depending on
  537. * the peripherial module clock) you run out of bits. However the
  538. * lower two bits of SCSMR allow the module clock to be divided down,
  539. * scaling the value which is needed in SCBRR.
  540. *
  541. * -- Stuart Menefy - 23 May 2000
  542. *
  543. * I meant, why would anyone bother with bitrates below 2400.
  544. *
  545. * -- Greg Banks - 7Jul2000
  546. *
  547. * You "speedist"! How will I use my 110bps ASR-33 teletype with paper
  548. * tape reader as a console!
  549. *
  550. * -- Mitch Davis - 15 Jul 2000
  551. */
  552. #if defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7780)
  553. #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1)
  554. #elif defined(CONFIG_CPU_SUBTYPE_SH7705)
  555. #define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1)
  556. #elif defined(__H8300H__) || defined(__H8300S__)
  557. #define SCBRR_VALUE(bps) (((CONFIG_CPU_CLOCK*1000/32)/bps)-1)
  558. #elif defined(CONFIG_SUPERH64)
  559. #define SCBRR_VALUE(bps) ((current_cpu_data.module_clock+16*bps)/(32*bps)-1)
  560. #else /* Generic SH */
  561. #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1)
  562. #endif