2 * Copy and modify from linux/drivers/serial/sh-sci.h
6 unsigned long iobase; /* in/out[bwl] */
7 unsigned char *membase; /* read/write[bwl] */
8 unsigned long mapbase; /* for ioremap */
9 unsigned int type; /* port type */
17 #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
18 #include <asm/regs306x.h>
20 #if defined(CONFIG_H8S2678)
21 #include <asm/regs267x.h>
24 #if defined(CONFIG_CPU_SH7706) || \
25 defined(CONFIG_CPU_SH7707) || \
26 defined(CONFIG_CPU_SH7708) || \
27 defined(CONFIG_CPU_SH7709)
28 # define SCPCR 0xA4000116 /* 16 bit SCI and SCIF */
29 # define SCPDR 0xA4000136 /* 8 bit SCI and SCIF */
30 # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
31 #elif defined(CONFIG_CPU_SH7705)
32 # define SCIF0 0xA4400000
33 # define SCIF2 0xA4410000
34 # define SCSMR_Ir 0xA44A0000
35 # define IRDA_SCIF SCIF0
36 # define SCPCR 0xA4000116
37 # define SCPDR 0xA4000136
39 /* Set the clock source,
40 * SCIF2 (0xA4410000) -> External clock, SCK pin used as clock input
41 * SCIF0 (0xA4400000) -> Internal clock, SCK pin as serial clock output
43 # define SCSCR_INIT(port) (port->mapbase == SCIF2) ? 0xF3 : 0xF0
44 #elif defined(CONFIG_CPU_SH7720) || \
45 defined(CONFIG_CPU_SH7721) || \
46 defined(CONFIG_ARCH_SH7367) || \
47 defined(CONFIG_ARCH_SH7377) || \
48 defined(CONFIG_ARCH_SH7372) || \
49 defined(CONFIG_SH73A0)
50 # define SCSCR_INIT(port) 0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
51 # define PORT_PTCR 0xA405011EUL
52 # define PORT_PVCR 0xA4050122UL
53 # define SCIF_ORER 0x0200 /* overrun error bit */
54 #elif defined(CONFIG_SH_RTS7751R2D)
55 # define SCSPTR1 0xFFE0001C /* 8 bit SCIF */
56 # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
57 # define SCIF_ORER 0x0001 /* overrun error bit */
58 # define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
59 #elif defined(CONFIG_CPU_SH7750) || \
60 defined(CONFIG_CPU_SH7750R) || \
61 defined(CONFIG_CPU_SH7750S) || \
62 defined(CONFIG_CPU_SH7091) || \
63 defined(CONFIG_CPU_SH7751) || \
64 defined(CONFIG_CPU_SH7751R)
65 # define SCSPTR1 0xffe0001c /* 8 bit SCI */
66 # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
67 # define SCIF_ORER 0x0001 /* overrun error bit */
68 # define SCSCR_INIT(port) (((port)->type == PORT_SCI) ? \
69 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
70 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */)
71 #elif defined(CONFIG_CPU_SH7760)
72 # define SCSPTR0 0xfe600024 /* 16 bit SCIF */
73 # define SCSPTR1 0xfe610024 /* 16 bit SCIF */
74 # define SCSPTR2 0xfe620024 /* 16 bit SCIF */
75 # define SCIF_ORER 0x0001 /* overrun error bit */
76 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
77 #elif defined(CONFIG_CPU_SH7710) || defined(CONFIG_CPU_SH7712)
78 # define SCSPTR0 0xA4400000 /* 16 bit SCIF */
79 # define SCIF_ORER 0x0001 /* overrun error bit */
80 # define PACR 0xa4050100
81 # define PBCR 0xa4050102
82 # define SCSCR_INIT(port) 0x3B
83 #elif defined(CONFIG_CPU_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 #elif defined(CONFIG_CPU_SH7722)
90 # define PADR 0xA4050120
92 # define PSDR 0xA405013e
93 # define PWDR 0xA4050166
94 # define PSCR 0xA405011E
95 # define SCIF_ORER 0x0001 /* overrun error bit */
96 # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
97 #elif defined(CONFIG_CPU_SH7366)
98 # define SCPDR0 0xA405013E /* 16 bit SCIF0 PSDR */
99 # define SCSPTR0 SCPDR0
100 # define SCIF_ORER 0x0001 /* overrun error bit */
101 # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
102 #elif defined(CONFIG_CPU_SH7723)
103 # define SCSPTR0 0xa4050160
104 # define SCSPTR1 0xa405013e
105 # define SCSPTR2 0xa4050160
106 # define SCSPTR3 0xa405013e
107 # define SCSPTR4 0xa4050128
108 # define SCSPTR5 0xa4050128
109 # define SCIF_ORER 0x0001 /* overrun error bit */
110 # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
111 #elif defined(CONFIG_CPU_SH7724)
112 # define SCIF_ORER 0x0001 /* overrun error bit */
113 # define SCSCR_INIT(port) ((port)->type == PORT_SCIFA ? \
114 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
115 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */)
116 #elif defined(CONFIG_CPU_SH7734)
117 # define SCSPTR0 0xFFE40020
118 # define SCSPTR1 0xFFE41020
119 # define SCSPTR2 0xFFE42020
120 # define SCSPTR3 0xFFE43020
121 # define SCSPTR4 0xFFE44020
122 # define SCSPTR5 0xFFE45020
123 # define SCIF_ORER 0x0001 /* overrun error bit */
124 # define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
125 #elif defined(CONFIG_CPU_SH4_202)
126 # define SCSPTR2 0xffe80020 /* 16 bit SCIF */
127 # define SCIF_ORER 0x0001 /* overrun error bit */
128 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
129 #elif defined(CONFIG_CPU_SH5_101) || defined(CONFIG_CPU_SH5_103)
130 # define SCIF_BASE_ADDR 0x01030000
131 # define SCIF_ADDR_SH5 (PHYS_PERIPHERAL_BLOCK+SCIF_BASE_ADDR)
132 # define SCIF_PTR2_OFFS 0x0000020
133 # define SCIF_LSR2_OFFS 0x0000024
135 ((port->mapbase)+SCIF_PTR2_OFFS) /* 16 bit SCIF */
137 ((port->mapbase)+SCIF_LSR2_OFFS) /* 16 bit SCIF */
138 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0, TE=1,RE=1,REIE=1 */
139 #elif defined(CONFIG_H83007) || defined(CONFIG_H83068)
140 # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
141 # define H8300_SCI_DR(ch) (*(volatile char *)(P1DR + h8300_sci_pins[ch].port))
142 #elif defined(CONFIG_H8S2678)
143 # define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
144 # define H8300_SCI_DR(ch) (*(volatile char *)(P1DR + h8300_sci_pins[ch].port))
145 #elif defined(CONFIG_CPU_SH7757)
146 # define SCSPTR0 0xfe4b0020
147 # define SCSPTR1 0xfe4b0020
148 # define SCSPTR2 0xfe4b0020
149 # define SCIF_ORER 0x0001
150 # define SCSCR_INIT(port) 0x38
152 #elif defined(CONFIG_CPU_SH7763)
153 # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
154 # define SCSPTR1 0xffe08024 /* 16 bit SCIF */
155 # define SCSPTR2 0xffe10020 /* 16 bit SCIF/IRDA */
156 # define SCIF_ORER 0x0001 /* overrun error bit */
157 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
158 #elif defined(CONFIG_CPU_SH7770)
159 # define SCSPTR0 0xff923020 /* 16 bit SCIF */
160 # define SCSPTR1 0xff924020 /* 16 bit SCIF */
161 # define SCSPTR2 0xff925020 /* 16 bit SCIF */
162 # define SCIF_ORER 0x0001 /* overrun error bit */
163 # define SCSCR_INIT(port) 0x3c /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,cke=2 */
164 #elif defined(CONFIG_CPU_SH7780)
165 # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
166 # define SCSPTR1 0xffe10024 /* 16 bit SCIF */
167 # define SCIF_ORER 0x0001 /* Overrun error bit */
169 #if defined(CONFIG_SH_SH2007)
170 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,CKE1=0 */
171 # define SCSCR_INIT(port) 0x38
173 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,CKE1=1 */
174 # define SCSCR_INIT(port) 0x3a
177 #elif defined(CONFIG_CPU_SH7785) || \
178 defined(CONFIG_CPU_SH7786)
179 # define SCSPTR0 0xffea0024 /* 16 bit SCIF */
180 # define SCSPTR1 0xffeb0024 /* 16 bit SCIF */
181 # define SCSPTR2 0xffec0024 /* 16 bit SCIF */
182 # define SCSPTR3 0xffed0024 /* 16 bit SCIF */
183 # define SCSPTR4 0xffee0024 /* 16 bit SCIF */
184 # define SCSPTR5 0xffef0024 /* 16 bit SCIF */
185 # define SCIF_ORER 0x0001 /* Overrun error bit */
186 # define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
187 #elif defined(CONFIG_CPU_SH7201) || \
188 defined(CONFIG_CPU_SH7203) || \
189 defined(CONFIG_CPU_SH7206) || \
190 defined(CONFIG_CPU_SH7263) || \
191 defined(CONFIG_CPU_SH7264)
192 # define SCSPTR0 0xfffe8020 /* 16 bit SCIF */
193 # define SCSPTR1 0xfffe8820 /* 16 bit SCIF */
194 # define SCSPTR2 0xfffe9020 /* 16 bit SCIF */
195 # define SCSPTR3 0xfffe9820 /* 16 bit SCIF */
196 # if defined(CONFIG_CPU_SH7201)
197 # define SCSPTR4 0xfffeA020 /* 16 bit SCIF */
198 # define SCSPTR5 0xfffeA820 /* 16 bit SCIF */
199 # define SCSPTR6 0xfffeB020 /* 16 bit SCIF */
200 # define SCSPTR7 0xfffeB820 /* 16 bit SCIF */
202 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
203 #elif defined(CONFIG_CPU_SH7269)
204 # define SCSPTR0 0xe8007020 /* 16 bit SCIF */
205 # define SCSPTR1 0xe8007820 /* 16 bit SCIF */
206 # define SCSPTR2 0xe8008020 /* 16 bit SCIF */
207 # define SCSPTR3 0xe8008820 /* 16 bit SCIF */
208 # define SCSPTR4 0xe8009020 /* 16 bit SCIF */
209 # define SCSPTR5 0xe8009820 /* 16 bit SCIF */
210 # define SCSPTR6 0xe800a020 /* 16 bit SCIF */
211 # define SCSPTR7 0xe800a820 /* 16 bit SCIF */
212 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
213 #elif defined(CONFIG_CPU_SH7619)
214 # define SCSPTR0 0xf8400020 /* 16 bit SCIF */
215 # define SCSPTR1 0xf8410020 /* 16 bit SCIF */
216 # define SCSPTR2 0xf8420020 /* 16 bit SCIF */
217 # define SCIF_ORER 0x0001 /* overrun error bit */
218 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
219 #elif defined(CONFIG_CPU_SHX3)
220 # define SCSPTR0 0xffc30020 /* 16 bit SCIF */
221 # define SCSPTR1 0xffc40020 /* 16 bit SCIF */
222 # define SCSPTR2 0xffc50020 /* 16 bit SCIF */
223 # define SCSPTR3 0xffc60020 /* 16 bit SCIF */
224 # define SCIF_ORER 0x0001 /* Overrun error bit */
225 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
227 # error CPU subtype not defined
231 #define SCI_CTRL_FLAGS_TIE 0x80 /* all */
232 #define SCI_CTRL_FLAGS_RIE 0x40 /* all */
233 #define SCI_CTRL_FLAGS_TE 0x20 /* all */
234 #define SCI_CTRL_FLAGS_RE 0x10 /* all */
235 #if defined(CONFIG_CPU_SH7750) || \
236 defined(CONFIG_CPU_SH7091) || \
237 defined(CONFIG_CPU_SH7750R) || \
238 defined(CONFIG_CPU_SH7722) || \
239 defined(CONFIG_CPU_SH7734) || \
240 defined(CONFIG_CPU_SH7750S) || \
241 defined(CONFIG_CPU_SH7751) || \
242 defined(CONFIG_CPU_SH7751R) || \
243 defined(CONFIG_CPU_SH7763) || \
244 defined(CONFIG_CPU_SH7780) || \
245 defined(CONFIG_CPU_SH7785) || \
246 defined(CONFIG_CPU_SH7786) || \
247 defined(CONFIG_CPU_SHX3)
248 #define SCI_CTRL_FLAGS_REIE 0x08 /* 7750 SCIF */
249 #elif defined(CONFIG_CPU_SH7724)
250 #define SCI_CTRL_FLAGS_REIE ((port)->type == PORT_SCIFA ? 0 : 8)
252 #define SCI_CTRL_FLAGS_REIE 0
254 /* SCI_CTRL_FLAGS_MPIE 0x08 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
255 /* SCI_CTRL_FLAGS_TEIE 0x04 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
256 /* SCI_CTRL_FLAGS_CKE1 0x02 * all */
257 /* SCI_CTRL_FLAGS_CKE0 0x01 * 7707 SCI/SCIF, 7708 SCI, 7709 SCI/SCIF, 7750 SCI */
260 #define SCI_TDRE 0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
261 #define SCI_RDRF 0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
262 #define SCI_ORER 0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
263 #define SCI_FER 0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
264 #define SCI_PER 0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
265 #define SCI_TEND 0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
266 /* SCI_MPB 0x02 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
267 /* SCI_MPBT 0x01 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
269 #define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
272 #define SCIF_ER 0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
273 #define SCIF_TEND 0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
274 #define SCIF_TDFE 0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
275 #define SCIF_BRK 0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
276 #define SCIF_FER 0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
277 #define SCIF_PER 0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
278 #define SCIF_RDF 0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
279 #define SCIF_DR 0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
281 #if defined(CONFIG_CPU_SH7705) || \
282 defined(CONFIG_CPU_SH7720) || \
283 defined(CONFIG_CPU_SH7721) || \
284 defined(CONFIG_ARCH_SH7367) || \
285 defined(CONFIG_ARCH_SH7377) || \
286 defined(CONFIG_ARCH_SH7372) || \
287 defined(CONFIG_SH73A0)
288 # define SCIF_ORER 0x0200
289 # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
290 # define SCIF_RFDC_MASK 0x007f
291 # define SCIF_TXROOM_MAX 64
292 #elif defined(CONFIG_CPU_SH7763)
293 # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
294 # define SCIF_RFDC_MASK 0x007f
295 # define SCIF_TXROOM_MAX 64
296 /* SH7763 SCIF2 support */
297 # define SCIF2_RFDC_MASK 0x001f
298 # define SCIF2_TXROOM_MAX 16
300 # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
301 # define SCIF_RFDC_MASK 0x001f
302 # define SCIF_TXROOM_MAX 16
306 #define SCIF_ORER 0x0000
309 #define SCxSR_TEND(port)\
310 (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
311 #define SCxSR_ERRORS(port)\
312 (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
313 #define SCxSR_RDxF(port)\
314 (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
315 #define SCxSR_TDxE(port)\
316 (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
317 #define SCxSR_FER(port)\
318 (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
319 #define SCxSR_PER(port)\
320 (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
321 #define SCxSR_BRK(port)\
322 ((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
323 #define SCxSR_ORER(port)\
324 (((port)->type == PORT_SCI) ? SCI_ORER : SCIF_ORER)
326 #if defined(CONFIG_CPU_SH7705) || \
327 defined(CONFIG_CPU_SH7720) || \
328 defined(CONFIG_CPU_SH7721) || \
329 defined(CONFIG_ARCH_SH7367) || \
330 defined(CONFIG_ARCH_SH7377) || \
331 defined(CONFIG_ARCH_SH7372) || \
332 defined(CONFIG_SH73A0)
333 # define SCxSR_RDxF_CLEAR(port) (sci_in(port, SCxSR) & 0xfffc)
334 # define SCxSR_ERROR_CLEAR(port) (sci_in(port, SCxSR) & 0xfd73)
335 # define SCxSR_TDxE_CLEAR(port) (sci_in(port, SCxSR) & 0xffdf)
336 # define SCxSR_BREAK_CLEAR(port) (sci_in(port, SCxSR) & 0xffe3)
338 # define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
339 # define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
340 # define SCxSR_TDxE_CLEAR(port) (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
341 # define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
345 #define SCFCR_RFRST 0x0002
346 #define SCFCR_TFRST 0x0004
347 #define SCFCR_TCRST 0x4000
348 #define SCFCR_MCE 0x0008
350 #define SCI_MAJOR 204
351 #define SCI_MINOR_START 8
353 /* Generic serial flags */
354 #define SCI_RX_THROTTLE 0x0000001
356 #define SCI_MAGIC 0xbabeface
359 * Events are used to schedule things to happen at timer-interrupt
360 * time, instead of at rs interrupt time.
362 #define SCI_EVENT_WRITE_WAKEUP 0
364 #define SCI_IN(size, offset)\
366 return readb(port->membase + (offset));\
368 return readw(port->membase + (offset));\
370 #define SCI_OUT(size, offset, value)\
372 writeb(value, port->membase + (offset));\
373 } else if ((size) == 16) {\
374 writew(value, port->membase + (offset));\
377 #define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
378 static inline unsigned int sci_##name##_in(struct uart_port *port) {\
379 if (port->type == PORT_SCIF || port->type == PORT_SCIFB) {\
380 SCI_IN(scif_size, scif_offset)\
381 } else { /* PORT_SCI or PORT_SCIFA */\
382 SCI_IN(sci_size, sci_offset);\
385 static inline void sci_##name##_out(struct uart_port *port,\
386 unsigned int value) {\
387 if (port->type == PORT_SCIF || port->type == PORT_SCIFB) {\
388 SCI_OUT(scif_size, scif_offset, value)\
389 } else { /* PORT_SCI or PORT_SCIFA */\
390 SCI_OUT(sci_size, sci_offset, value);\
395 /* h8300 don't have SCIF */
396 #define CPU_SCIF_FNS(name) \
397 static inline unsigned int sci_##name##_in(struct uart_port *port) {\
400 static inline void sci_##name##_out(struct uart_port *port,\
401 unsigned int value) {\
404 #define CPU_SCIF_FNS(name, scif_offset, scif_size) \
405 static inline unsigned int sci_##name##_in(struct uart_port *port) {\
406 SCI_IN(scif_size, scif_offset);\
408 static inline void sci_##name##_out(struct uart_port *port,\
409 unsigned int value) {\
410 SCI_OUT(scif_size, scif_offset, value);\
414 #define CPU_SCI_FNS(name, sci_offset, sci_size)\
415 static inline unsigned int sci_##name##_in(struct uart_port *port) {\
416 SCI_IN(sci_size, sci_offset);\
418 static inline void sci_##name##_out(struct uart_port *port,\
419 unsigned int value) {\
420 SCI_OUT(sci_size, sci_offset, value);\
423 #if defined(CONFIG_SH3) || \
424 defined(CONFIG_ARCH_SH7367) || \
425 defined(CONFIG_ARCH_SH7377) || \
426 defined(CONFIG_ARCH_SH7372) || \
427 defined(CONFIG_SH73A0)
428 #if defined(CONFIG_CPU_SH7710) || defined(CONFIG_CPU_SH7712)
429 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
430 sh4_sci_offset, sh4_sci_size, \
431 sh3_scif_offset, sh3_scif_size, \
432 sh4_scif_offset, sh4_scif_size, \
433 h8_sci_offset, h8_sci_size) \
434 CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size,\
435 sh4_scif_offset, sh4_scif_size)
436 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
437 sh4_scif_offset, sh4_scif_size) \
438 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
439 #elif defined(CONFIG_CPU_SH7705) || \
440 defined(CONFIG_CPU_SH7720) || \
441 defined(CONFIG_CPU_SH7721) || \
442 defined(CONFIG_ARCH_SH7367) || \
443 defined(CONFIG_ARCH_SH7377) || \
444 defined(CONFIG_SH73A0)
445 #define SCIF_FNS(name, scif_offset, scif_size) \
446 CPU_SCIF_FNS(name, scif_offset, scif_size)
447 #elif defined(CONFIG_ARCH_SH7372)
448 #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
449 sh4_scifb_offset, sh4_scifb_size) \
450 CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
451 sh4_scifb_offset, sh4_scifb_size)
452 #define SCIF_FNS(name, scif_offset, scif_size) \
453 CPU_SCIF_FNS(name, scif_offset, scif_size)
455 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
456 sh4_sci_offset, sh4_sci_size, \
457 sh3_scif_offset, sh3_scif_size,\
458 sh4_scif_offset, sh4_scif_size, \
459 h8_sci_offset, h8_sci_size) \
460 CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
461 sh3_scif_offset, sh3_scif_size)
462 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
463 sh4_scif_offset, sh4_scif_size) \
464 CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
466 #elif defined(__H8300H__) || defined(__H8300S__)
467 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
468 sh4_sci_offset, sh4_sci_size, \
469 sh3_scif_offset, sh3_scif_size,\
470 sh4_scif_offset, sh4_scif_size, \
471 h8_sci_offset, h8_sci_size) \
472 CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size)
473 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
474 sh4_scif_offset, sh4_scif_size) \
476 #elif defined(CONFIG_CPU_SH7723) || defined(CONFIG_CPU_SH7724)
477 #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
478 sh4_scif_offset, sh4_scif_size) \
479 CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
480 sh4_scif_offset, sh4_scif_size)
481 #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \
482 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
484 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
485 sh4_sci_offset, sh4_sci_size, \
486 sh3_scif_offset, sh3_scif_size,\
487 sh4_scif_offset, sh4_scif_size, \
488 h8_sci_offset, h8_sci_size) \
489 CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size,\
490 sh4_scif_offset, sh4_scif_size)
491 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, \
492 sh4_scif_offset, sh4_scif_size) \
493 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
496 #if defined(CONFIG_CPU_SH7705) || \
497 defined(CONFIG_CPU_SH7720) || \
498 defined(CONFIG_CPU_SH7721) || \
499 defined(CONFIG_ARCH_SH7367) || \
500 defined(CONFIG_ARCH_SH7377) || \
501 defined(CONFIG_SH73A0)
503 SCIF_FNS(SCSMR, 0x00, 16)
504 SCIF_FNS(SCBRR, 0x04, 8)
505 SCIF_FNS(SCSCR, 0x08, 16)
506 SCIF_FNS(SCTDSR, 0x0c, 8)
507 SCIF_FNS(SCFER, 0x10, 16)
508 SCIF_FNS(SCxSR, 0x14, 16)
509 SCIF_FNS(SCFCR, 0x18, 16)
510 SCIF_FNS(SCFDR, 0x1c, 16)
511 SCIF_FNS(SCxTDR, 0x20, 8)
512 SCIF_FNS(SCxRDR, 0x24, 8)
513 SCIF_FNS(SCLSR, 0x00, 0)
514 #elif defined(CONFIG_ARCH_SH7372)
515 SCIF_FNS(SCSMR, 0x00, 16)
516 SCIF_FNS(SCBRR, 0x04, 8)
517 SCIF_FNS(SCSCR, 0x08, 16)
518 SCIF_FNS(SCTDSR, 0x0c, 16)
519 SCIF_FNS(SCFER, 0x10, 16)
520 SCIF_FNS(SCxSR, 0x14, 16)
521 SCIF_FNS(SCFCR, 0x18, 16)
522 SCIF_FNS(SCFDR, 0x1c, 16)
523 SCIF_FNS(SCTFDR, 0x38, 16)
524 SCIF_FNS(SCRFDR, 0x3c, 16)
525 SCIx_FNS(SCxTDR, 0x20, 8, 0x40, 8)
526 SCIx_FNS(SCxRDR, 0x24, 8, 0x60, 8)
527 SCIF_FNS(SCLSR, 0x00, 0)
528 #elif defined(CONFIG_CPU_SH7723) ||\
529 defined(CONFIG_CPU_SH7724)
530 SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16)
531 SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8)
532 SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16)
533 SCIx_FNS(SCxTDR, 0x20, 8, 0x0c, 8)
534 SCIx_FNS(SCxSR, 0x14, 16, 0x10, 16)
535 SCIx_FNS(SCxRDR, 0x24, 8, 0x14, 8)
536 SCIx_FNS(SCSPTR, 0, 0, 0, 0)
537 SCIF_FNS(SCTDSR, 0x0c, 8)
538 SCIF_FNS(SCFER, 0x10, 16)
539 SCIF_FNS(SCFCR, 0x18, 16)
540 SCIF_FNS(SCFDR, 0x1c, 16)
541 SCIF_FNS(SCLSR, 0x24, 16)
543 /* reg SCI/SH3 SCI/SH4 SCIF/SH3 SCIF/SH4 SCI/H8*/
544 /* name off sz off sz off sz off sz off sz*/
545 SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16, 0x00, 8)
546 SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8, 0x01, 8)
547 SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16, 0x02, 8)
548 SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8, 0x03, 8)
549 SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16, 0x04, 8)
550 SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
551 SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
552 #if defined(CONFIG_CPU_SH7760) || \
553 defined(CONFIG_CPU_SH7780) || \
554 defined(CONFIG_CPU_SH7785) || \
555 defined(CONFIG_CPU_SH7786)
556 SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
557 SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
558 SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
559 SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
560 SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
561 #elif defined(CONFIG_CPU_SH7763)
562 SCIF_FNS(SCFDR, 0, 0, 0x1C, 16)
563 SCIF_FNS(SCSPTR2, 0, 0, 0x20, 16)
564 SCIF_FNS(SCLSR2, 0, 0, 0x24, 16)
565 SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
566 SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
567 SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
568 SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
570 SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
571 #if defined(CONFIG_CPU_SH7722)
572 SCIF_FNS(SCSPTR, 0, 0, 0, 0)
574 SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
576 SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
579 #define sci_in(port, reg) sci_##reg##_in(port)
580 #define sci_out(port, reg, value) sci_##reg##_out(port, value)
582 /* H8/300 series SCI pins assignment */
583 #if defined(__H8300H__) || defined(__H8300S__)
584 static const struct __attribute__((packed)) {
585 int port; /* GPIO port no */
586 unsigned short rx, tx; /* GPIO bit no */
587 } h8300_sci_pins[] = {
588 #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
590 .port = H8300_GPIO_P9,
595 .port = H8300_GPIO_P9,
600 .port = H8300_GPIO_PB,
604 #elif defined(CONFIG_H8S2678)
606 .port = H8300_GPIO_P3,
611 .port = H8300_GPIO_P3,
616 .port = H8300_GPIO_P5,
624 #if defined(CONFIG_CPU_SH7706) || \
625 defined(CONFIG_CPU_SH7707) || \
626 defined(CONFIG_CPU_SH7708) || \
627 defined(CONFIG_CPU_SH7709)
628 static inline int sci_rxd_in(struct uart_port *port)
630 if (port->mapbase == 0xfffffe80)
631 return __raw_readb(SCPDR)&0x01 ? 1 : 0; /* SCI */
634 #elif defined(CONFIG_CPU_SH7750) || \
635 defined(CONFIG_CPU_SH7751) || \
636 defined(CONFIG_CPU_SH7751R) || \
637 defined(CONFIG_CPU_SH7750R) || \
638 defined(CONFIG_CPU_SH7750S) || \
639 defined(CONFIG_CPU_SH7091)
640 static inline int sci_rxd_in(struct uart_port *port)
642 if (port->mapbase == 0xffe00000)
643 return __raw_readb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
646 #elif defined(__H8300H__) || defined(__H8300S__)
647 static inline int sci_rxd_in(struct uart_port *port)
649 int ch = (port->mapbase - SMR0) >> 3;
650 return (H8300_SCI_DR(ch) & h8300_sci_pins[ch].rx) ? 1 : 0;
652 #else /* default case for non-SCI processors */
653 static inline int sci_rxd_in(struct uart_port *port)
660 * Values for the BitRate Register (SCBRR)
662 * The values are actually divisors for a frequency which can
663 * be internal to the SH3 (14.7456MHz) or derived from an external
664 * clock source. This driver assumes the internal clock is used;
665 * to support using an external clock source, config options or
666 * possibly command-line options would need to be added.
668 * Also, to support speeds below 2400 (why?) the lower 2 bits of
669 * the SCSMR register would also need to be set to non-zero values.
671 * -- Greg Banks 27Feb2000
673 * Answer: The SCBRR register is only eight bits, and the value in
674 * it gets larger with lower baud rates. At around 2400 (depending on
675 * the peripherial module clock) you run out of bits. However the
676 * lower two bits of SCSMR allow the module clock to be divided down,
677 * scaling the value which is needed in SCBRR.
679 * -- Stuart Menefy - 23 May 2000
681 * I meant, why would anyone bother with bitrates below 2400.
683 * -- Greg Banks - 7Jul2000
685 * You "speedist"! How will I use my 110bps ASR-33 teletype with paper
686 * tape reader as a console!
688 * -- Mitch Davis - 15 Jul 2000
691 #if (defined(CONFIG_CPU_SH7780) || \
692 defined(CONFIG_CPU_SH7785) || \
693 defined(CONFIG_CPU_SH7786)) && \
694 !defined(CONFIG_SH_SH2007)
695 #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1)
696 #elif defined(CONFIG_CPU_SH7705) || \
697 defined(CONFIG_CPU_SH7720) || \
698 defined(CONFIG_CPU_SH7721) || \
699 defined(CONFIG_ARCH_SH7367) || \
700 defined(CONFIG_ARCH_SH7377) || \
701 defined(CONFIG_ARCH_SH7372) || \
702 defined(CONFIG_SH73A0)
703 #define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1)
704 #elif defined(CONFIG_CPU_SH7723) ||\
705 defined(CONFIG_CPU_SH7724)
706 static inline int scbrr_calc(struct uart_port port, int bps, int clk)
708 if (port.type == PORT_SCIF)
709 return (clk+16*bps)/(32*bps)-1;
711 return ((clk*2)+16*bps)/(16*bps)-1;
713 #define SCBRR_VALUE(bps, clk) scbrr_calc(sh_sci, bps, clk)
714 #elif defined(__H8300H__) || defined(__H8300S__)
715 #define SCBRR_VALUE(bps, clk) (((clk*1000/32)/bps)-1)
716 #else /* Generic SH */
717 #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1)