sh: Simplify and lock down the ISA tuning.
[pandora-kernel.git] / drivers / serial / sh-sci.h
1 #include <linux/serial_core.h>
2 #include <asm/io.h>
3 #include <asm/gpio.h>
4
5 #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
6 #include <asm/regs306x.h>
7 #endif
8 #if defined(CONFIG_H8S2678)
9 #include <asm/regs267x.h>
10 #endif
11
12 #if defined(CONFIG_CPU_SUBTYPE_SH7706) || \
13     defined(CONFIG_CPU_SUBTYPE_SH7707) || \
14     defined(CONFIG_CPU_SUBTYPE_SH7708) || \
15     defined(CONFIG_CPU_SUBTYPE_SH7709)
16 # define SCPCR  0xA4000116 /* 16 bit SCI and SCIF */
17 # define SCPDR  0xA4000136 /* 8  bit SCI and SCIF */
18 # define SCSCR_INIT(port)          0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
19 # define SCI_AND_SCIF
20 #elif defined(CONFIG_CPU_SUBTYPE_SH7705)
21 # define SCIF0          0xA4400000
22 # define SCIF2          0xA4410000
23 # define SCSMR_Ir       0xA44A0000
24 # define IRDA_SCIF      SCIF0
25 # define SCPCR 0xA4000116
26 # define SCPDR 0xA4000136
27
28 /* Set the clock source,
29  * SCIF2 (0xA4410000) -> External clock, SCK pin used as clock input
30  * SCIF0 (0xA4400000) -> Internal clock, SCK pin as serial clock output
31  */
32 # define SCSCR_INIT(port) (port->mapbase == SCIF2) ? 0xF3 : 0xF0
33 # define SCIF_ONLY
34 #elif defined(CONFIG_CPU_SUBTYPE_SH7720) || \
35       defined(CONFIG_CPU_SUBTYPE_SH7721)
36 # define SCSCR_INIT(port)  0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
37 # define SCIF_ONLY
38 #define SCIF_ORER    0x0200   /* overrun error bit */
39 #elif defined(CONFIG_SH_RTS7751R2D)
40 # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
41 # define SCIF_ORER 0x0001   /* overrun error bit */
42 # define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
43 # define SCIF_ONLY
44 #elif defined(CONFIG_CPU_SUBTYPE_SH7750)  || \
45       defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
46       defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
47       defined(CONFIG_CPU_SUBTYPE_SH7091)  || \
48       defined(CONFIG_CPU_SUBTYPE_SH7751)  || \
49       defined(CONFIG_CPU_SUBTYPE_SH7751R)
50 # define SCSPTR1 0xffe0001c /* 8  bit SCI */
51 # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
52 # define SCIF_ORER 0x0001   /* overrun error bit */
53 # define SCSCR_INIT(port) (((port)->type == PORT_SCI) ? \
54         0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
55         0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */ )
56 # define SCI_AND_SCIF
57 #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
58 # define SCSPTR0 0xfe600024 /* 16 bit SCIF */
59 # define SCSPTR1 0xfe610024 /* 16 bit SCIF */
60 # define SCSPTR2 0xfe620024 /* 16 bit SCIF */
61 # define SCIF_ORER 0x0001  /* overrun error bit */
62 # define SCSCR_INIT(port)          0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
63 # define SCIF_ONLY
64 #elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
65 # define SCSPTR0 0xA4400000       /* 16 bit SCIF */
66 # define SCIF_ORER 0x0001   /* overrun error bit */
67 # define PACR 0xa4050100
68 # define PBCR 0xa4050102
69 # define SCSCR_INIT(port)          0x3B
70 # define SCIF_ONLY
71 #elif defined(CONFIG_CPU_SUBTYPE_SH7343)
72 # define SCSPTR0 0xffe00010     /* 16 bit SCIF */
73 # define SCSPTR1 0xffe10010     /* 16 bit SCIF */
74 # define SCSPTR2 0xffe20010     /* 16 bit SCIF */
75 # define SCSPTR3 0xffe30010     /* 16 bit SCIF */
76 # define SCSCR_INIT(port) 0x32  /* TIE=0,RIE=0,TE=1,RE=1,REIE=0,CKE=1 */
77 # define SCIF_ONLY
78 #elif defined(CONFIG_CPU_SUBTYPE_SH7722)
79 # define PADR                   0xA4050120
80 # define PSDR                   0xA405013e
81 # define PWDR                   0xA4050166
82 # define PSCR                   0xA405011E
83 # define SCIF_ORER              0x0001  /* overrun error bit */
84 # define SCSCR_INIT(port)       0x0038  /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
85 # define SCIF_ONLY
86 #elif defined(CONFIG_CPU_SUBTYPE_SH7366)
87 # define SCPDR0                 0xA405013E      /* 16 bit SCIF0 PSDR */
88 # define SCSPTR0                SCPDR0
89 # define SCIF_ORER              0x0001  /* overrun error bit */
90 # define SCSCR_INIT(port)       0x0038  /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
91 # define SCIF_ONLY
92 #elif defined(CONFIG_CPU_SUBTYPE_SH7723)
93 # define SCSPTR0                0xa4050160
94 # define SCSPTR1                0xa405013e
95 # define SCSPTR2                0xa4050160
96 # define SCSPTR3                0xa405013e
97 # define SCSPTR4                0xa4050128
98 # define SCSPTR5                0xa4050128
99 # define SCIF_ORER              0x0001  /* overrun error bit */
100 # define SCSCR_INIT(port)       0x0038  /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
101 # define SCIF_ONLY
102 #elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
103 # define SCSPTR2 0xffe80020 /* 16 bit SCIF */
104 # define SCIF_ORER 0x0001   /* overrun error bit */
105 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
106 # define SCIF_ONLY
107 #elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
108 # define SCIF_BASE_ADDR    0x01030000
109 # define SCIF_ADDR_SH5     PHYS_PERIPHERAL_BLOCK+SCIF_BASE_ADDR
110 # define SCIF_PTR2_OFFS    0x0000020
111 # define SCIF_LSR2_OFFS    0x0000024
112 # define SCSPTR2           ((port->mapbase)+SCIF_PTR2_OFFS) /* 16 bit SCIF */
113 # define SCLSR2            ((port->mapbase)+SCIF_LSR2_OFFS) /* 16 bit SCIF */
114 # define SCSCR_INIT(port)  0x38         /* TIE=0,RIE=0, TE=1,RE=1,REIE=1 */
115 # define SCIF_ONLY
116 #elif defined(CONFIG_H83007) || defined(CONFIG_H83068)
117 # define SCSCR_INIT(port)          0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
118 # define SCI_ONLY
119 # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
120 #elif defined(CONFIG_H8S2678)
121 # define SCSCR_INIT(port)          0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
122 # define SCI_ONLY
123 # define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
124 #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
125 # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
126 # define SCSPTR1 0xffe08024 /* 16 bit SCIF */
127 # define SCSPTR2 0xffe10020 /* 16 bit SCIF/IRDA */
128 # define SCIF_ORER 0x0001  /* overrun error bit */
129 # define SCSCR_INIT(port)       0x38    /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
130 # define SCIF_ONLY
131 #elif defined(CONFIG_CPU_SUBTYPE_SH7770)
132 # define SCSPTR0 0xff923020 /* 16 bit SCIF */
133 # define SCSPTR1 0xff924020 /* 16 bit SCIF */
134 # define SCSPTR2 0xff925020 /* 16 bit SCIF */
135 # define SCIF_ORER 0x0001  /* overrun error bit */
136 # define SCSCR_INIT(port)       0x3c /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,cke=2 */
137 # define SCIF_ONLY
138 #elif defined(CONFIG_CPU_SUBTYPE_SH7780)
139 # define SCSPTR0        0xffe00024      /* 16 bit SCIF */
140 # define SCSPTR1        0xffe10024      /* 16 bit SCIF */
141 # define SCIF_ORER      0x0001          /* Overrun error bit */
142 # define SCSCR_INIT(port)       0x3a    /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
143 # define SCIF_ONLY
144 #elif defined(CONFIG_CPU_SUBTYPE_SH7785)
145 # define SCSPTR0        0xffea0024      /* 16 bit SCIF */
146 # define SCSPTR1        0xffeb0024      /* 16 bit SCIF */
147 # define SCSPTR2        0xffec0024      /* 16 bit SCIF */
148 # define SCSPTR3        0xffed0024      /* 16 bit SCIF */
149 # define SCSPTR4        0xffee0024      /* 16 bit SCIF */
150 # define SCSPTR5        0xffef0024      /* 16 bit SCIF */
151 # define SCIF_OPER      0x0001          /* Overrun error bit */
152 # define SCSCR_INIT(port)       0x3a    /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
153 # define SCIF_ONLY
154 #elif defined(CONFIG_CPU_SUBTYPE_SH7203) || \
155       defined(CONFIG_CPU_SUBTYPE_SH7206) || \
156       defined(CONFIG_CPU_SUBTYPE_SH7263)
157 # define SCSPTR0 0xfffe8020 /* 16 bit SCIF */
158 # define SCSPTR1 0xfffe8820 /* 16 bit SCIF */
159 # define SCSPTR2 0xfffe9020 /* 16 bit SCIF */
160 # define SCSPTR3 0xfffe9820 /* 16 bit SCIF */
161 # define SCSCR_INIT(port)       0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
162 # define SCIF_ONLY
163 #elif defined(CONFIG_CPU_SUBTYPE_SH7619)
164 # define SCSPTR0 0xf8400020 /* 16 bit SCIF */
165 # define SCSPTR1 0xf8410020 /* 16 bit SCIF */
166 # define SCSPTR2 0xf8420020 /* 16 bit SCIF */
167 # define SCIF_ORER 0x0001  /* overrun error bit */
168 # define SCSCR_INIT(port)       0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
169 # define SCIF_ONLY
170 #elif defined(CONFIG_CPU_SUBTYPE_SHX3)
171 # define SCSPTR0 0xffc30020             /* 16 bit SCIF */
172 # define SCSPTR1 0xffc40020             /* 16 bit SCIF */
173 # define SCSPTR2 0xffc50020             /* 16 bit SCIF */
174 # define SCSPTR3 0xffc60020             /* 16 bit SCIF */
175 # define SCIF_ORER 0x0001               /* Overrun error bit */
176 # define SCSCR_INIT(port)       0x38    /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
177 # define SCIF_ONLY
178 #else
179 # error CPU subtype not defined
180 #endif
181
182 /* SCSCR */
183 #define SCI_CTRL_FLAGS_TIE  0x80 /* all */
184 #define SCI_CTRL_FLAGS_RIE  0x40 /* all */
185 #define SCI_CTRL_FLAGS_TE   0x20 /* all */
186 #define SCI_CTRL_FLAGS_RE   0x10 /* all */
187 #if defined(CONFIG_CPU_SUBTYPE_SH7750)  || \
188     defined(CONFIG_CPU_SUBTYPE_SH7091)  || \
189     defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
190     defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
191     defined(CONFIG_CPU_SUBTYPE_SH7751)  || \
192     defined(CONFIG_CPU_SUBTYPE_SH7751R) || \
193     defined(CONFIG_CPU_SUBTYPE_SH7763)  || \
194     defined(CONFIG_CPU_SUBTYPE_SH7780)  || \
195     defined(CONFIG_CPU_SUBTYPE_SH7785)  || \
196     defined(CONFIG_CPU_SUBTYPE_SHX3)
197 #define SCI_CTRL_FLAGS_REIE 0x08 /* 7750 SCIF */
198 #else
199 #define SCI_CTRL_FLAGS_REIE 0
200 #endif
201 /*      SCI_CTRL_FLAGS_MPIE 0x08  * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
202 /*      SCI_CTRL_FLAGS_TEIE 0x04  * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
203 /*      SCI_CTRL_FLAGS_CKE1 0x02  * all */
204 /*      SCI_CTRL_FLAGS_CKE0 0x01  * 7707 SCI/SCIF, 7708 SCI, 7709 SCI/SCIF, 7750 SCI */
205
206 /* SCxSR SCI */
207 #define SCI_TDRE  0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
208 #define SCI_RDRF  0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
209 #define SCI_ORER  0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
210 #define SCI_FER   0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
211 #define SCI_PER   0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
212 #define SCI_TEND  0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
213 /*      SCI_MPB   0x02  * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
214 /*      SCI_MPBT  0x01  * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
215
216 #define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
217
218 /* SCxSR SCIF */
219 #define SCIF_ER    0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
220 #define SCIF_TEND  0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
221 #define SCIF_TDFE  0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
222 #define SCIF_BRK   0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
223 #define SCIF_FER   0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
224 #define SCIF_PER   0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
225 #define SCIF_RDF   0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
226 #define SCIF_DR    0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
227
228 #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
229     defined(CONFIG_CPU_SUBTYPE_SH7720) || \
230     defined(CONFIG_CPU_SUBTYPE_SH7721)
231 # define SCIF_ORER    0x0200
232 # define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
233 # define SCIF_RFDC_MASK 0x007f
234 # define SCIF_TXROOM_MAX 64
235 #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
236 # define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK )
237 # define SCIF_RFDC_MASK 0x007f
238 # define SCIF_TXROOM_MAX 64
239 /* SH7763 SCIF2 support */
240 # define SCIF2_RFDC_MASK 0x001f
241 # define SCIF2_TXROOM_MAX 16
242 #else
243 # define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
244 # define SCIF_RFDC_MASK 0x001f
245 # define SCIF_TXROOM_MAX 16
246 #endif
247
248 #if defined(SCI_ONLY)
249 # define SCxSR_TEND(port)               SCI_TEND
250 # define SCxSR_ERRORS(port)             SCI_ERRORS
251 # define SCxSR_RDxF(port)               SCI_RDRF
252 # define SCxSR_TDxE(port)               SCI_TDRE
253 # define SCxSR_ORER(port)               SCI_ORER
254 # define SCxSR_FER(port)                SCI_FER
255 # define SCxSR_PER(port)                SCI_PER
256 # define SCxSR_BRK(port)                0x00
257 # define SCxSR_RDxF_CLEAR(port)         0xbc
258 # define SCxSR_ERROR_CLEAR(port)        0xc4
259 # define SCxSR_TDxE_CLEAR(port)         0x78
260 # define SCxSR_BREAK_CLEAR(port)        0xc4
261 #elif defined(SCIF_ONLY)
262 # define SCxSR_TEND(port)               SCIF_TEND
263 # define SCxSR_ERRORS(port)             SCIF_ERRORS
264 # define SCxSR_RDxF(port)               SCIF_RDF
265 # define SCxSR_TDxE(port)               SCIF_TDFE
266 #if defined(CONFIG_CPU_SUBTYPE_SH7705)
267 # define SCxSR_ORER(port)               SCIF_ORER
268 #else
269 # define SCxSR_ORER(port)               0x0000
270 #endif
271 # define SCxSR_FER(port)                SCIF_FER
272 # define SCxSR_PER(port)                SCIF_PER
273 # define SCxSR_BRK(port)                SCIF_BRK
274 #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
275     defined(CONFIG_CPU_SUBTYPE_SH7720) || \
276     defined(CONFIG_CPU_SUBTYPE_SH7721)
277 # define SCxSR_RDxF_CLEAR(port)         (sci_in(port,SCxSR)&0xfffc)
278 # define SCxSR_ERROR_CLEAR(port)        (sci_in(port,SCxSR)&0xfd73)
279 # define SCxSR_TDxE_CLEAR(port)         (sci_in(port,SCxSR)&0xffdf)
280 # define SCxSR_BREAK_CLEAR(port)        (sci_in(port,SCxSR)&0xffe3)
281 #else
282 /* SH7705 can also use this, clearing is same between 7705 and 7709 */
283 # define SCxSR_RDxF_CLEAR(port)         0x00fc
284 # define SCxSR_ERROR_CLEAR(port)        0x0073
285 # define SCxSR_TDxE_CLEAR(port)         0x00df
286 # define SCxSR_BREAK_CLEAR(port)        0x00e3
287 #endif
288 #else
289 # define SCxSR_TEND(port)        (((port)->type == PORT_SCI) ? SCI_TEND   : SCIF_TEND)
290 # define SCxSR_ERRORS(port)      (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
291 # define SCxSR_RDxF(port)        (((port)->type == PORT_SCI) ? SCI_RDRF   : SCIF_RDF)
292 # define SCxSR_TDxE(port)        (((port)->type == PORT_SCI) ? SCI_TDRE   : SCIF_TDFE)
293 # define SCxSR_ORER(port)        (((port)->type == PORT_SCI) ? SCI_ORER   : 0x0000)
294 # define SCxSR_FER(port)         (((port)->type == PORT_SCI) ? SCI_FER    : SCIF_FER)
295 # define SCxSR_PER(port)         (((port)->type == PORT_SCI) ? SCI_PER    : SCIF_PER)
296 # define SCxSR_BRK(port)         (((port)->type == PORT_SCI) ? 0x00       : SCIF_BRK)
297 # define SCxSR_RDxF_CLEAR(port)  (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
298 # define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
299 # define SCxSR_TDxE_CLEAR(port)  (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
300 # define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
301 #endif
302
303 /* SCFCR */
304 #define SCFCR_RFRST 0x0002
305 #define SCFCR_TFRST 0x0004
306 #define SCFCR_TCRST 0x4000
307 #define SCFCR_MCE   0x0008
308
309 #define SCI_MAJOR               204
310 #define SCI_MINOR_START         8
311
312 /* Generic serial flags */
313 #define SCI_RX_THROTTLE         0x0000001
314
315 #define SCI_MAGIC 0xbabeface
316
317 /*
318  * Events are used to schedule things to happen at timer-interrupt
319  * time, instead of at rs interrupt time.
320  */
321 #define SCI_EVENT_WRITE_WAKEUP  0
322
323 #define SCI_IN(size, offset)                                    \
324   if ((size) == 8) {                                            \
325     return ioread8(port->membase + (offset));                   \
326   } else {                                                      \
327     return ioread16(port->membase + (offset));                  \
328   }
329 #define SCI_OUT(size, offset, value)                            \
330   if ((size) == 8) {                                            \
331     iowrite8(value, port->membase + (offset));                  \
332   } else if ((size) == 16) {                                    \
333     iowrite16(value, port->membase + (offset));                 \
334   }
335
336 #define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
337   static inline unsigned int sci_##name##_in(struct uart_port *port)    \
338   {                                                                     \
339     if (port->type == PORT_SCI) {                                       \
340       SCI_IN(sci_size, sci_offset)                                      \
341     } else {                                                            \
342       SCI_IN(scif_size, scif_offset);                                   \
343     }                                                                   \
344   }                                                                     \
345   static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
346   {                                                                     \
347     if (port->type == PORT_SCI) {                                       \
348       SCI_OUT(sci_size, sci_offset, value)                              \
349     } else {                                                            \
350       SCI_OUT(scif_size, scif_offset, value);                           \
351     }                                                                   \
352   }
353
354 #define CPU_SCIF_FNS(name, scif_offset, scif_size)                              \
355   static inline unsigned int sci_##name##_in(struct uart_port *port)    \
356   {                                                                     \
357     SCI_IN(scif_size, scif_offset);                                     \
358   }                                                                     \
359   static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
360   {                                                                     \
361     SCI_OUT(scif_size, scif_offset, value);                             \
362   }
363
364 #define CPU_SCI_FNS(name, sci_offset, sci_size)                         \
365   static inline unsigned int sci_##name##_in(struct uart_port* port)    \
366   {                                                                     \
367     SCI_IN(sci_size, sci_offset);                                       \
368   }                                                                     \
369   static inline void sci_##name##_out(struct uart_port* port, unsigned int value) \
370   {                                                                     \
371     SCI_OUT(sci_size, sci_offset, value);                               \
372   }
373
374 #ifdef CONFIG_CPU_SH3
375 #if defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
376 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
377                                 sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
378                                  h8_sci_offset, h8_sci_size) \
379   CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
380 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
381           CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
382 #elif defined(CONFIG_CPU_SUBTYPE_SH7705) || \
383       defined(CONFIG_CPU_SUBTYPE_SH7720) || \
384       defined(CONFIG_CPU_SUBTYPE_SH7721)
385 #define SCIF_FNS(name, scif_offset, scif_size) \
386   CPU_SCIF_FNS(name, scif_offset, scif_size)
387 #else
388 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
389                  sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
390                  h8_sci_offset, h8_sci_size) \
391   CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh3_scif_offset, sh3_scif_size)
392 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
393   CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
394 #endif
395 #elif defined(__H8300H__) || defined(__H8300S__)
396 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
397                  sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
398                  h8_sci_offset, h8_sci_size) \
399   CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size)
400 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size)
401 #elif defined(CONFIG_CPU_SUBTYPE_SH7723)
402         #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size) \
403                 CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size)
404         #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \
405                 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
406 #else
407 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
408                  sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
409                  h8_sci_offset, h8_sci_size) \
410   CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
411 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
412   CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
413 #endif
414
415 #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
416     defined(CONFIG_CPU_SUBTYPE_SH7720) || \
417     defined(CONFIG_CPU_SUBTYPE_SH7721)
418
419 SCIF_FNS(SCSMR,  0x00, 16)
420 SCIF_FNS(SCBRR,  0x04,  8)
421 SCIF_FNS(SCSCR,  0x08, 16)
422 SCIF_FNS(SCTDSR, 0x0c,  8)
423 SCIF_FNS(SCFER,  0x10, 16)
424 SCIF_FNS(SCxSR,  0x14, 16)
425 SCIF_FNS(SCFCR,  0x18, 16)
426 SCIF_FNS(SCFDR,  0x1c, 16)
427 SCIF_FNS(SCxTDR, 0x20,  8)
428 SCIF_FNS(SCxRDR, 0x24,  8)
429 SCIF_FNS(SCLSR,  0x24, 16)
430 #elif defined(CONFIG_CPU_SUBTYPE_SH7723)
431 SCIx_FNS(SCSMR,  0x00, 16, 0x00, 16)
432 SCIx_FNS(SCBRR,  0x04,  8, 0x04,  8)
433 SCIx_FNS(SCSCR,  0x08, 16, 0x08, 16)
434 SCIx_FNS(SCxTDR, 0x20,  8, 0x0c,  8)
435 SCIx_FNS(SCxSR,  0x14, 16, 0x10, 16)
436 SCIx_FNS(SCxRDR, 0x24,  8, 0x14,  8)
437 SCIF_FNS(SCTDSR, 0x0c,  8)
438 SCIF_FNS(SCFER,  0x10, 16)
439 SCIF_FNS(SCFCR,  0x18, 16)
440 SCIF_FNS(SCFDR,  0x1c, 16)
441 SCIF_FNS(SCLSR,  0x24, 16)
442 #else
443 /*      reg      SCI/SH3   SCI/SH4  SCIF/SH3   SCIF/SH4  SCI/H8*/
444 /*      name     off  sz   off  sz   off  sz   off  sz   off  sz*/
445 SCIx_FNS(SCSMR,  0x00,  8, 0x00,  8, 0x00,  8, 0x00, 16, 0x00,  8)
446 SCIx_FNS(SCBRR,  0x02,  8, 0x04,  8, 0x02,  8, 0x04,  8, 0x01,  8)
447 SCIx_FNS(SCSCR,  0x04,  8, 0x08,  8, 0x04,  8, 0x08, 16, 0x02,  8)
448 SCIx_FNS(SCxTDR, 0x06,  8, 0x0c,  8, 0x06,  8, 0x0C,  8, 0x03,  8)
449 SCIx_FNS(SCxSR,  0x08,  8, 0x10,  8, 0x08, 16, 0x10, 16, 0x04,  8)
450 SCIx_FNS(SCxRDR, 0x0a,  8, 0x14,  8, 0x0A,  8, 0x14,  8, 0x05,  8)
451 SCIF_FNS(SCFCR,                      0x0c,  8, 0x18, 16)
452 #if defined(CONFIG_CPU_SUBTYPE_SH7760) || \
453     defined(CONFIG_CPU_SUBTYPE_SH7780) || \
454     defined(CONFIG_CPU_SUBTYPE_SH7785)
455 SCIF_FNS(SCFDR,                      0x0e, 16, 0x1C, 16)
456 SCIF_FNS(SCTFDR,                     0x0e, 16, 0x1C, 16)
457 SCIF_FNS(SCRFDR,                     0x0e, 16, 0x20, 16)
458 SCIF_FNS(SCSPTR,                        0,  0, 0x24, 16)
459 SCIF_FNS(SCLSR,                         0,  0, 0x28, 16)
460 #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
461 SCIF_FNS(SCFDR,                         0,  0, 0x1C, 16)
462 SCIF_FNS(SCSPTR2,                       0,  0, 0x20, 16)
463 SCIF_FNS(SCLSR2,                        0,  0, 0x24, 16)
464 SCIF_FNS(SCTFDR,                     0x0e, 16, 0x1C, 16)
465 SCIF_FNS(SCRFDR,                     0x0e, 16, 0x20, 16)
466 SCIF_FNS(SCSPTR,                        0,  0, 0x24, 16)
467 SCIF_FNS(SCLSR,                         0,  0, 0x28, 16)
468 #else
469 SCIF_FNS(SCFDR,                      0x0e, 16, 0x1C, 16)
470 #if defined(CONFIG_CPU_SUBTYPE_SH7722)
471 SCIF_FNS(SCSPTR,                        0,  0, 0, 0)
472 #else
473 SCIF_FNS(SCSPTR,                        0,  0, 0x20, 16)
474 #endif
475 SCIF_FNS(SCLSR,                         0,  0, 0x24, 16)
476 #endif
477 #endif
478 #define sci_in(port, reg) sci_##reg##_in(port)
479 #define sci_out(port, reg, value) sci_##reg##_out(port, value)
480
481 /* H8/300 series SCI pins assignment */
482 #if defined(__H8300H__) || defined(__H8300S__)
483 static const struct __attribute__((packed)) {
484         int port;             /* GPIO port no */
485         unsigned short rx,tx; /* GPIO bit no */
486 } h8300_sci_pins[] = {
487 #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
488         {    /* SCI0 */
489                 .port = H8300_GPIO_P9,
490                 .rx   = H8300_GPIO_B2,
491                 .tx   = H8300_GPIO_B0,
492         },
493         {    /* SCI1 */
494                 .port = H8300_GPIO_P9,
495                 .rx   = H8300_GPIO_B3,
496                 .tx   = H8300_GPIO_B1,
497         },
498         {    /* SCI2 */
499                 .port = H8300_GPIO_PB,
500                 .rx   = H8300_GPIO_B7,
501                 .tx   = H8300_GPIO_B6,
502         }
503 #elif defined(CONFIG_H8S2678)
504         {    /* SCI0 */
505                 .port = H8300_GPIO_P3,
506                 .rx   = H8300_GPIO_B2,
507                 .tx   = H8300_GPIO_B0,
508         },
509         {    /* SCI1 */
510                 .port = H8300_GPIO_P3,
511                 .rx   = H8300_GPIO_B3,
512                 .tx   = H8300_GPIO_B1,
513         },
514         {    /* SCI2 */
515                 .port = H8300_GPIO_P5,
516                 .rx   = H8300_GPIO_B1,
517                 .tx   = H8300_GPIO_B0,
518         }
519 #endif
520 };
521 #endif
522
523 #if defined(CONFIG_CPU_SUBTYPE_SH7706) || \
524     defined(CONFIG_CPU_SUBTYPE_SH7707) || \
525     defined(CONFIG_CPU_SUBTYPE_SH7708) || \
526     defined(CONFIG_CPU_SUBTYPE_SH7709)
527 static inline int sci_rxd_in(struct uart_port *port)
528 {
529         if (port->mapbase == 0xfffffe80)
530                 return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCI */
531         if (port->mapbase == 0xa4000150)
532                 return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
533         if (port->mapbase == 0xa4000140)
534                 return ctrl_inb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
535         return 1;
536 }
537 #elif defined(CONFIG_CPU_SUBTYPE_SH7705)
538 static inline int sci_rxd_in(struct uart_port *port)
539 {
540         if (port->mapbase == SCIF0)
541                 return ctrl_inb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
542         if (port->mapbase == SCIF2)
543                 return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
544         return 1;
545 }
546 #elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
547 static inline int sci_rxd_in(struct uart_port *port)
548 {
549           return sci_in(port,SCxSR)&0x0010 ? 1 : 0;
550 }
551 static inline void set_sh771x_scif_pfc(struct uart_port *port)
552 {
553         if (port->mapbase == 0xA4400000){
554                 ctrl_outw(ctrl_inw(PACR)&0xffc0,PACR);
555                 ctrl_outw(ctrl_inw(PBCR)&0x0fff,PBCR);
556                 return;
557         }
558         if (port->mapbase == 0xA4410000){
559                 ctrl_outw(ctrl_inw(PBCR)&0xf003,PBCR);
560                 return;
561         }
562 }
563 #elif defined(CONFIG_CPU_SUBTYPE_SH7720) || \
564       defined(CONFIG_CPU_SUBTYPE_SH7721)
565 static inline int sci_rxd_in(struct uart_port *port)
566 {
567         if (port->mapbase == 0xa4430000)
568                 return sci_in(port, SCxSR) & 0x0003 ? 1 : 0;
569         else if (port->mapbase == 0xa4438000)
570                 return sci_in(port, SCxSR) & 0x0003 ? 1 : 0;
571         return 1;
572 }
573 #elif defined(CONFIG_CPU_SUBTYPE_SH7750)  || \
574       defined(CONFIG_CPU_SUBTYPE_SH7751)  || \
575       defined(CONFIG_CPU_SUBTYPE_SH7751R) || \
576       defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
577       defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
578       defined(CONFIG_CPU_SUBTYPE_SH7091)  || \
579       defined(CONFIG_CPU_SUBTYPE_SH4_202)
580 static inline int sci_rxd_in(struct uart_port *port)
581 {
582 #ifndef SCIF_ONLY
583         if (port->mapbase == 0xffe00000)
584                 return ctrl_inb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
585 #endif
586 #ifndef SCI_ONLY
587         if (port->mapbase == 0xffe80000)
588                 return ctrl_inw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
589 #endif
590         return 1;
591 }
592 #elif defined(CONFIG_CPU_SUBTYPE_SH7760)
593 static inline int sci_rxd_in(struct uart_port *port)
594 {
595         if (port->mapbase == 0xfe600000)
596                 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
597         if (port->mapbase == 0xfe610000)
598                 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
599         if (port->mapbase == 0xfe620000)
600                 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
601         return 1;
602 }
603 #elif defined(CONFIG_CPU_SUBTYPE_SH7343)
604 static inline int sci_rxd_in(struct uart_port *port)
605 {
606         if (port->mapbase == 0xffe00000)
607                 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
608         if (port->mapbase == 0xffe10000)
609                 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
610         if (port->mapbase == 0xffe20000)
611                 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
612         if (port->mapbase == 0xffe30000)
613                 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
614         return 1;
615 }
616 #elif defined(CONFIG_CPU_SUBTYPE_SH7366)
617 static inline int sci_rxd_in(struct uart_port *port)
618 {
619         if (port->mapbase == 0xffe00000)
620                 return ctrl_inb(SCPDR0) & 0x0001 ? 1 : 0; /* SCIF0 */
621         return 1;
622 }
623 #elif defined(CONFIG_CPU_SUBTYPE_SH7722)
624 static inline int sci_rxd_in(struct uart_port *port)
625 {
626         if (port->mapbase == 0xffe00000)
627                 return ctrl_inb(PSDR) & 0x02 ? 1 : 0; /* SCIF0 */
628         if (port->mapbase == 0xffe10000)
629                 return ctrl_inb(PADR) & 0x40 ? 1 : 0; /* SCIF1 */
630         if (port->mapbase == 0xffe20000)
631                 return ctrl_inb(PWDR) & 0x04 ? 1 : 0; /* SCIF2 */
632
633         return 1;
634 }
635 #elif defined(CONFIG_CPU_SUBTYPE_SH7723)
636 static inline int sci_rxd_in(struct uart_port *port)
637 {
638         if (port->mapbase == 0xffe00000)
639                 return ctrl_inb(SCSPTR0) & 0x0008 ? 1 : 0; /* SCIF0 */
640         if (port->mapbase == 0xffe10000)
641                 return ctrl_inb(SCSPTR1) & 0x0020 ? 1 : 0; /* SCIF1 */
642         if (port->mapbase == 0xffe20000)
643                 return ctrl_inb(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF2 */
644         if (port->mapbase == 0xa4e30000)
645                 return ctrl_inb(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF3 */
646         if (port->mapbase == 0xa4e40000)
647                 return ctrl_inb(SCSPTR4) & 0x0001 ? 1 : 0; /* SCIF4 */
648         if (port->mapbase == 0xa4e50000)
649                 return ctrl_inb(SCSPTR5) & 0x0008 ? 1 : 0; /* SCIF5 */
650         return 1;
651 }
652 #elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
653 static inline int sci_rxd_in(struct uart_port *port)
654 {
655          return sci_in(port, SCSPTR)&0x0001 ? 1 : 0; /* SCIF */
656 }
657 #elif defined(__H8300H__) || defined(__H8300S__)
658 static inline int sci_rxd_in(struct uart_port *port)
659 {
660         int ch = (port->mapbase - SMR0) >> 3;
661         return (H8300_SCI_DR(ch) & h8300_sci_pins[ch].rx) ? 1 : 0;
662 }
663 #elif defined(CONFIG_CPU_SUBTYPE_SH7763)
664 static inline int sci_rxd_in(struct uart_port *port)
665 {
666         if (port->mapbase == 0xffe00000)
667                 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
668         if (port->mapbase == 0xffe08000)
669                 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
670         if (port->mapbase == 0xffe10000)
671                 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF/IRDA */
672
673         return 1;
674 }
675 #elif defined(CONFIG_CPU_SUBTYPE_SH7770)
676 static inline int sci_rxd_in(struct uart_port *port)
677 {
678         if (port->mapbase == 0xff923000)
679                 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
680         if (port->mapbase == 0xff924000)
681                 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
682         if (port->mapbase == 0xff925000)
683                 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
684         return 1;
685 }
686 #elif defined(CONFIG_CPU_SUBTYPE_SH7780)
687 static inline int sci_rxd_in(struct uart_port *port)
688 {
689         if (port->mapbase == 0xffe00000)
690                 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
691         if (port->mapbase == 0xffe10000)
692                 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
693         return 1;
694 }
695 #elif defined(CONFIG_CPU_SUBTYPE_SH7785)
696 static inline int sci_rxd_in(struct uart_port *port)
697 {
698         if (port->mapbase == 0xffea0000)
699                 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
700         if (port->mapbase == 0xffeb0000)
701                 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
702         if (port->mapbase == 0xffec0000)
703                 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
704         if (port->mapbase == 0xffed0000)
705                 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
706         if (port->mapbase == 0xffee0000)
707                 return ctrl_inw(SCSPTR4) & 0x0001 ? 1 : 0; /* SCIF */
708         if (port->mapbase == 0xffef0000)
709                 return ctrl_inw(SCSPTR5) & 0x0001 ? 1 : 0; /* SCIF */
710         return 1;
711 }
712 #elif defined(CONFIG_CPU_SUBTYPE_SH7203) || \
713       defined(CONFIG_CPU_SUBTYPE_SH7206) || \
714       defined(CONFIG_CPU_SUBTYPE_SH7263)
715 static inline int sci_rxd_in(struct uart_port *port)
716 {
717         if (port->mapbase == 0xfffe8000)
718                 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
719         if (port->mapbase == 0xfffe8800)
720                 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
721         if (port->mapbase == 0xfffe9000)
722                 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
723         if (port->mapbase == 0xfffe9800)
724                 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
725         return 1;
726 }
727 #elif defined(CONFIG_CPU_SUBTYPE_SH7619)
728 static inline int sci_rxd_in(struct uart_port *port)
729 {
730         if (port->mapbase == 0xf8400000)
731                 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
732         if (port->mapbase == 0xf8410000)
733                 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
734         if (port->mapbase == 0xf8420000)
735                 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
736         return 1;
737 }
738 #elif defined(CONFIG_CPU_SUBTYPE_SHX3)
739 static inline int sci_rxd_in(struct uart_port *port)
740 {
741         if (port->mapbase == 0xffc30000)
742                 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
743         if (port->mapbase == 0xffc40000)
744                 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
745         if (port->mapbase == 0xffc50000)
746                 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
747         if (port->mapbase == 0xffc60000)
748                 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
749         return 1;
750 }
751 #endif
752
753 /*
754  * Values for the BitRate Register (SCBRR)
755  *
756  * The values are actually divisors for a frequency which can
757  * be internal to the SH3 (14.7456MHz) or derived from an external
758  * clock source.  This driver assumes the internal clock is used;
759  * to support using an external clock source, config options or
760  * possibly command-line options would need to be added.
761  *
762  * Also, to support speeds below 2400 (why?) the lower 2 bits of
763  * the SCSMR register would also need to be set to non-zero values.
764  *
765  * -- Greg Banks 27Feb2000
766  *
767  * Answer: The SCBRR register is only eight bits, and the value in
768  * it gets larger with lower baud rates. At around 2400 (depending on
769  * the peripherial module clock) you run out of bits. However the
770  * lower two bits of SCSMR allow the module clock to be divided down,
771  * scaling the value which is needed in SCBRR.
772  *
773  * -- Stuart Menefy - 23 May 2000
774  *
775  * I meant, why would anyone bother with bitrates below 2400.
776  *
777  * -- Greg Banks - 7Jul2000
778  *
779  * You "speedist"!  How will I use my 110bps ASR-33 teletype with paper
780  * tape reader as a console!
781  *
782  * -- Mitch Davis - 15 Jul 2000
783  */
784
785 #if defined(CONFIG_CPU_SUBTYPE_SH7780) || \
786     defined(CONFIG_CPU_SUBTYPE_SH7785)
787 #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1)
788 #elif defined(CONFIG_CPU_SUBTYPE_SH7705) || \
789       defined(CONFIG_CPU_SUBTYPE_SH7720) || \
790       defined(CONFIG_CPU_SUBTYPE_SH7721)
791 #define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1)
792 #elif defined(CONFIG_CPU_SUBTYPE_SH7723)
793 static inline int scbrr_calc(struct uart_port *port, int bps, int clk)
794 {
795         if (port->type == PORT_SCIF)
796                 return (clk+16*bps)/(32*bps)-1;
797         else
798                 return ((clk*2)+16*bps)/(16*bps)-1;
799 }
800 #define SCBRR_VALUE(bps, clk) scbrr_calc(port, bps, clk)
801 #elif defined(__H8300H__) || defined(__H8300S__)
802 #define SCBRR_VALUE(bps, clk) (((clk*1000/32)/bps)-1)
803 #else /* Generic SH */
804 #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1)
805 #endif