sh-sci.h 22 KB

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