1 /* $Id: sh-sci.h,v 1.4 2004/02/19 16:43:56 lethal Exp $
3 * linux/drivers/serial/sh-sci.h
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 H8/300 Series Yoshinori Sato (Feb 2004).
12 #include <linux/config.h>
13 #include <linux/serial_core.h>
15 #if defined(__H8300H__) || defined(__H8300S__)
17 #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
18 #include <asm/regs306x.h>
20 #if defined(CONFIG_H8S2678)
21 #include <asm/regs267x.h>
25 /* Offsets into the sci_port->irqs array */
26 #define SCIx_ERI_IRQ 0
27 #define SCIx_RXI_IRQ 1
28 #define SCIx_TXI_IRQ 2
30 /* ERI, RXI, TXI, BRI */
31 #define SCI_IRQS { 23, 24, 25, 0 }
32 #define SH3_SCIF_IRQS { 56, 57, 59, 58 }
33 #define SH3_IRDA_IRQS { 52, 53, 55, 54 }
34 #define SH4_SCIF_IRQS { 40, 41, 43, 42 }
35 #define STB1_SCIF1_IRQS {23, 24, 26, 25 }
36 #define SH7760_SCIF0_IRQS { 52, 53, 55, 54 }
37 #define SH7760_SCIF1_IRQS { 72, 73, 75, 74 }
38 #define SH7760_SCIF2_IRQS { 76, 77, 79, 78 }
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 }
46 #if defined(CONFIG_CPU_SUBTYPE_SH7708)
48 # define SCSPTR 0xffffff7c /* 8 bit */
49 # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
51 #elif defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709)
53 # define SCPCR 0xA4000116 /* 16 bit SCI and SCIF */
54 # define SCPDR 0xA4000136 /* 8 bit SCI and SCIF */
55 # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
57 #elif defined(CONFIG_CPU_SUBTYPE_SH7750) || defined(CONFIG_CPU_SUBTYPE_SH7751)
59 # define SCSPTR1 0xffe0001c /* 8 bit SCI */
60 # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
61 # define SCIF_ORER 0x0001 /* overrun error bit */
62 # define SCSCR_INIT(port) (((port)->type == PORT_SCI) ? \
63 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
64 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */ )
66 #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
68 # define SCSPTR0 0xfe600000 /* 16 bit SCIF */
69 # define SCSPTR1 0xfe610000 /* 16 bit SCIF */
70 # define SCSPTR2 0xfe620000 /* 16 bit SCIF */
71 # define SCIF_ORDER 0x0001 /* overrun error bit */
72 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
74 #elif defined(CONFIG_CPU_SUBTYPE_ST40STB1)
76 # define SCSPTR1 0xffe00020 /* 16 bit SCIF */
77 # define SCSPTR2 0xffe80020 /* 16 bit SCIF */
78 # define SCIF_ORER 0x0001 /* overrun error bit */
79 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
81 #elif defined(CONFIG_H83007) || defined(CONFIG_H83068)
83 # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
85 # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
86 #elif defined(CONFIG_H8S2678)
88 # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
90 # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
92 # error CPU subtype not defined
96 #define SCI_CTRL_FLAGS_TIE 0x80 /* all */
97 #define SCI_CTRL_FLAGS_RIE 0x40 /* all */
98 #define SCI_CTRL_FLAGS_TE 0x20 /* all */
99 #define SCI_CTRL_FLAGS_RE 0x10 /* all */
100 /* SCI_CTRL_FLAGS_REIE 0x08 * 7750 SCIF */
101 /* SCI_CTRL_FLAGS_MPIE 0x08 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
102 /* SCI_CTRL_FLAGS_TEIE 0x04 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
103 /* SCI_CTRL_FLAGS_CKE1 0x02 * all */
104 /* SCI_CTRL_FLAGS_CKE0 0x01 * 7707 SCI/SCIF, 7708 SCI, 7709 SCI/SCIF, 7750 SCI */
107 #define SCI_TDRE 0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
108 #define SCI_RDRF 0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
109 #define SCI_ORER 0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
110 #define SCI_FER 0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
111 #define SCI_PER 0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
112 #define SCI_TEND 0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
113 /* SCI_MPB 0x02 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
114 /* SCI_MPBT 0x01 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
116 #define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
119 #define SCIF_ER 0x0080 /* 7707 SCIF, 7709 SCIF, 7750 SCIF */
120 #define SCIF_TEND 0x0040 /* 7707 SCIF, 7709 SCIF, 7750 SCIF */
121 #define SCIF_TDFE 0x0020 /* 7707 SCIF, 7709 SCIF, 7750 SCIF */
122 #define SCIF_BRK 0x0010 /* 7707 SCIF, 7709 SCIF, 7750 SCIF */
123 #define SCIF_FER 0x0008 /* 7707 SCIF, 7709 SCIF, 7750 SCIF */
124 #define SCIF_PER 0x0004 /* 7707 SCIF, 7709 SCIF, 7750 SCIF */
125 #define SCIF_RDF 0x0002 /* 7707 SCIF, 7709 SCIF, 7750 SCIF */
126 #define SCIF_DR 0x0001 /* 7707 SCIF, 7709 SCIF, 7750 SCIF */
128 #define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
130 #if defined(SCI_ONLY)
131 # define SCxSR_TEND(port) SCI_TEND
132 # define SCxSR_ERRORS(port) SCI_ERRORS
133 # define SCxSR_RDxF(port) SCI_RDRF
134 # define SCxSR_TDxE(port) SCI_TDRE
135 # define SCxSR_ORER(port) SCI_ORER
136 # define SCxSR_FER(port) SCI_FER
137 # define SCxSR_PER(port) SCI_PER
138 # define SCxSR_BRK(port) 0x00
139 # define SCxSR_RDxF_CLEAR(port) 0xbc
140 # define SCxSR_ERROR_CLEAR(port) 0xc4
141 # define SCxSR_TDxE_CLEAR(port) 0x78
142 # define SCxSR_BREAK_CLEAR(port) 0xc4
143 #elif defined(SCIF_ONLY)
144 # define SCxSR_TEND(port) SCIF_TEND
145 # define SCxSR_ERRORS(port) SCIF_ERRORS
146 # define SCxSR_RDxF(port) SCIF_RDF
147 # define SCxSR_TDxE(port) SCIF_TDFE
148 # define SCxSR_ORER(port) 0x0000
149 # define SCxSR_FER(port) SCIF_FER
150 # define SCxSR_PER(port) SCIF_PER
151 # define SCxSR_BRK(port) SCIF_BRK
152 # define SCxSR_RDxF_CLEAR(port) 0x00fc
153 # define SCxSR_ERROR_CLEAR(port) 0x0073
154 # define SCxSR_TDxE_CLEAR(port) 0x00df
155 # define SCxSR_BREAK_CLEAR(port) 0x00e3
157 # define SCxSR_TEND(port) (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
158 # define SCxSR_ERRORS(port) (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
159 # define SCxSR_RDxF(port) (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
160 # define SCxSR_TDxE(port) (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
161 # define SCxSR_ORER(port) (((port)->type == PORT_SCI) ? SCI_ORER : 0x0000)
162 # define SCxSR_FER(port) (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
163 # define SCxSR_PER(port) (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
164 # define SCxSR_BRK(port) (((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
165 # define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
166 # define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
167 # define SCxSR_TDxE_CLEAR(port) (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
168 # define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
172 #define SCFCR_RFRST 0x0002
173 #define SCFCR_TFRST 0x0004
174 #define SCFCR_MCE 0x0008
176 #define SCI_MAJOR 204
177 #define SCI_MINOR_START 8
179 /* Generic serial flags */
180 #define SCI_RX_THROTTLE 0x0000001
182 #define SCI_MAGIC 0xbabeface
185 * Events are used to schedule things to happen at timer-interrupt
186 * time, instead of at rs interrupt time.
188 #define SCI_EVENT_WRITE_WAKEUP 0
191 struct uart_port port;
193 unsigned char irqs[4]; /* ERI, RXI, TXI, BRI */
194 void (*init_pins)(struct uart_port *port, unsigned int cflag);
196 struct timer_list break_timer;
199 #define SCI_IN(size, offset) \
200 unsigned int addr = port->mapbase + (offset); \
202 return ctrl_inb(addr); \
204 return ctrl_inw(addr); \
206 #define SCI_OUT(size, offset, value) \
207 unsigned int addr = port->mapbase + (offset); \
209 ctrl_outb(value, addr); \
211 ctrl_outw(value, addr); \
214 #define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
215 static inline unsigned int sci_##name##_in(struct uart_port *port) \
217 if (port->type == PORT_SCI) { \
218 SCI_IN(sci_size, sci_offset) \
220 SCI_IN(scif_size, scif_offset); \
223 static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
225 if (port->type == PORT_SCI) { \
226 SCI_OUT(sci_size, sci_offset, value) \
228 SCI_OUT(scif_size, scif_offset, value); \
232 #define CPU_SCIF_FNS(name, scif_offset, scif_size) \
233 static inline unsigned int sci_##name##_in(struct uart_port *port) \
235 SCI_IN(scif_size, scif_offset); \
237 static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
239 SCI_OUT(scif_size, scif_offset, value); \
242 #define CPU_SCI_FNS(name, sci_offset, sci_size) \
243 static inline unsigned int sci_##name##_in(struct uart_port* port) \
245 SCI_IN(sci_size, sci_offset); \
247 static inline void sci_##name##_out(struct uart_port* port, unsigned int value) \
249 SCI_OUT(sci_size, sci_offset, value); \
252 #ifdef CONFIG_CPU_SH3
253 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
254 sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
255 h8_sci_offset, h8_sci_size) \
256 CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh3_scif_offset, sh3_scif_size)
257 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
258 CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
259 #elif defined(__H8300H__) || defined(__H8300S__)
260 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
261 sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
262 h8_sci_offset, h8_sci_size) \
263 CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size)
264 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size)
266 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
267 sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
268 h8_sci_offset, h8_sci_size) \
269 CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
270 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
271 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
274 /* reg SCI/SH3 SCI/SH4 SCIF/SH3 SCIF/SH4 SCI/H8*/
275 /* name off sz off sz off sz off sz off sz*/
276 SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16, 0x00, 8)
277 SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8, 0x01, 8)
278 SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16, 0x02, 8)
279 SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8, 0x03, 8)
280 SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16, 0x04, 8)
281 SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
282 SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
283 SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
284 SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
286 #define sci_in(port, reg) sci_##reg##_in(port)
287 #define sci_out(port, reg, value) sci_##reg##_out(port, value)
289 /* H8/300 series SCI pins assignment */
290 #if defined(__H8300H__) || defined(__H8300S__)
291 static const struct __attribute__((packed)) {
292 int port; /* GPIO port no */
293 unsigned short rx,tx; /* GPIO bit no */
294 } h8300_sci_pins[] = {
295 #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
297 .port = H8300_GPIO_P9,
302 .port = H8300_GPIO_P9,
307 .port = H8300_GPIO_PB,
311 #elif defined(CONFIG_H8S2678)
313 .port = H8300_GPIO_P3,
318 .port = H8300_GPIO_P3,
323 .port = H8300_GPIO_P5,
331 #if defined(CONFIG_CPU_SUBTYPE_SH7708)
332 static inline int sci_rxd_in(struct uart_port *port)
334 if (port->mapbase == 0xfffffe80)
335 return ctrl_inb(SCSPTR)&0x01 ? 1 : 0; /* SCI */
338 #elif defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709)
339 static inline int sci_rxd_in(struct uart_port *port)
341 if (port->mapbase == 0xfffffe80)
342 return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCI */
343 if (port->mapbase == 0xa4000150)
344 return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
345 if (port->mapbase == 0xa4000140)
346 return ctrl_inb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
349 #elif defined(CONFIG_CPU_SUBTYPE_SH7750) || defined(CONFIG_CPU_SUBTYPE_SH7751)
350 static inline int sci_rxd_in(struct uart_port *port)
353 if (port->mapbase == 0xffe00000)
354 return ctrl_inb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
357 if (port->mapbase == 0xffe80000)
358 return ctrl_inw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
362 #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
363 static inline int sci_rxd_in(struct uart_port *port)
365 if (port->mapbase == 0xfe600000)
366 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
367 if (port->mapbase == 0xfe610000)
368 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
369 if (port->mapbase == 0xfe620000)
370 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
372 #elif defined(CONFIG_CPU_SUBTYPE_ST40STB1)
373 static inline int sci_rxd_in(struct uart_port *port)
375 if (port->mapbase == 0xffe00000)
376 return ctrl_inw(SCSPTR1)&0x0001 ? 1 : 0; /* SCIF */
378 return ctrl_inw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
381 #elif defined(__H8300H__) || defined(__H8300S__)
382 static inline int sci_rxd_in(struct uart_port *port)
384 int ch = (port->mapbase - SMR0) >> 3;
385 return (H8300_SCI_DR(ch) & h8300_sci_pins[ch].rx) ? 1 : 0;
390 * Values for the BitRate Register (SCBRR)
392 * The values are actually divisors for a frequency which can
393 * be internal to the SH3 (14.7456MHz) or derived from an external
394 * clock source. This driver assumes the internal clock is used;
395 * to support using an external clock source, config options or
396 * possibly command-line options would need to be added.
398 * Also, to support speeds below 2400 (why?) the lower 2 bits of
399 * the SCSMR register would also need to be set to non-zero values.
401 * -- Greg Banks 27Feb2000
403 * Answer: The SCBRR register is only eight bits, and the value in
404 * it gets larger with lower baud rates. At around 2400 (depending on
405 * the peripherial module clock) you run out of bits. However the
406 * lower two bits of SCSMR allow the module clock to be divided down,
407 * scaling the value which is needed in SCBRR.
409 * -- Stuart Menefy - 23 May 2000
411 * I meant, why would anyone bother with bitrates below 2400.
413 * -- Greg Banks - 7Jul2000
415 * You "speedist"! How will I use my 110bps ASR-33 teletype with paper
416 * tape reader as a console!
418 * -- Mitch Davis - 15 Jul 2000
421 #define PCLK (current_cpu_data.module_clock)
423 #if !defined(__H8300H__) && !defined(__H8300S__)
424 #define SCBRR_VALUE(bps) ((PCLK+16*bps)/(32*bps)-1)
426 #define SCBRR_VALUE(bps) (((CONFIG_CPU_CLOCK*1000/32)/bps)-1)
428 #define BPS_2400 SCBRR_VALUE(2400)
429 #define BPS_4800 SCBRR_VALUE(4800)
430 #define BPS_9600 SCBRR_VALUE(9600)
431 #define BPS_19200 SCBRR_VALUE(19200)
432 #define BPS_38400 SCBRR_VALUE(38400)
433 #define BPS_57600 SCBRR_VALUE(57600)
434 #define BPS_115200 SCBRR_VALUE(115200)