serial: sh: Drop RTS7751R2D support
[platform/kernel/u-boot.git] / drivers / serial / serial_sh.h
1 /*
2  * Copy and modify from linux/drivers/serial/sh-sci.h
3  */
4
5 #include <dm/platform_data/serial_sh.h>
6
7 struct uart_port {
8         unsigned long   iobase;         /* in/out[bwl] */
9         unsigned char   *membase;       /* read/write[bwl] */
10         unsigned long   mapbase;        /* for ioremap */
11         enum sh_serial_type type;       /* port type */
12         enum sh_clk_mode clk_mode;      /* clock mode */
13 };
14
15 #if defined(CONFIG_CPU_SH7706) || \
16         defined(CONFIG_CPU_SH7707) || \
17         defined(CONFIG_CPU_SH7708) || \
18         defined(CONFIG_CPU_SH7709)
19 # define SCPCR  0xA4000116 /* 16 bit SCI and SCIF */
20 # define SCPDR  0xA4000136 /* 8  bit SCI and SCIF */
21 # define SCSCR_INIT(port)          0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
22 #elif defined(CONFIG_CPU_SH7705)
23 # define SCIF0          0xA4400000
24 # define SCIF2          0xA4410000
25 # define SCSMR_Ir       0xA44A0000
26 # define IRDA_SCIF      SCIF0
27 # define SCPCR 0xA4000116
28 # define SCPDR 0xA4000136
29
30 /* Set the clock source,
31  * SCIF2 (0xA4410000) -> External clock, SCK pin used as clock input
32  * SCIF0 (0xA4400000) -> Internal clock, SCK pin as serial clock output
33  */
34 # define SCSCR_INIT(port) (port->mapbase == SCIF2) ? 0xF3 : 0xF0
35 #elif defined(CONFIG_CPU_SH7720) || \
36         defined(CONFIG_CPU_SH7721) || \
37         defined(CONFIG_ARCH_SH7367) || \
38         defined(CONFIG_ARCH_SH7377) || \
39         defined(CONFIG_ARCH_SH7372) || \
40         defined(CONFIG_SH73A0) || \
41         defined(CONFIG_R8A7740)
42 # define SCSCR_INIT(port)  0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
43 # define PORT_PTCR         0xA405011EUL
44 # define PORT_PVCR         0xA4050122UL
45 # define SCIF_ORER         0x0200   /* overrun error bit */
46 #elif defined(CONFIG_CPU_SH7750)  || \
47         defined(CONFIG_CPU_SH7750R) || \
48         defined(CONFIG_CPU_SH7750S) || \
49         defined(CONFIG_CPU_SH7091)  || \
50         defined(CONFIG_CPU_SH7751)  || \
51         defined(CONFIG_CPU_SH7751R)
52 # define SCSPTR1 0xffe0001c /* 8  bit SCI */
53 # define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
54 # define SCIF_ORER 0x0001   /* overrun error bit */
55 # define SCSCR_INIT(port) (((port)->type == PORT_SCI) ? \
56         0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
57         0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */)
58 #elif defined(CONFIG_CPU_SH7760)
59 # define SCSPTR0 0xfe600024 /* 16 bit SCIF */
60 # define SCSPTR1 0xfe610024 /* 16 bit SCIF */
61 # define SCSPTR2 0xfe620024 /* 16 bit SCIF */
62 # define SCIF_ORER 0x0001  /* overrun error bit */
63 # define SCSCR_INIT(port)          0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
64 #elif defined(CONFIG_CPU_SH7710) || defined(CONFIG_CPU_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 #elif defined(CONFIG_CPU_SH7343)
71 # define SCSPTR0 0xffe00010     /* 16 bit SCIF */
72 # define SCSPTR1 0xffe10010     /* 16 bit SCIF */
73 # define SCSPTR2 0xffe20010     /* 16 bit SCIF */
74 # define SCSPTR3 0xffe30010     /* 16 bit SCIF */
75 # define SCSCR_INIT(port) 0x32  /* TIE=0,RIE=0,TE=1,RE=1,REIE=0,CKE=1 */
76 #elif defined(CONFIG_CPU_SH7722)
77 # define PADR                   0xA4050120
78 # undef PSDR
79 # define PSDR                   0xA405013e
80 # define PWDR                   0xA4050166
81 # define PSCR                   0xA405011E
82 # define SCIF_ORER              0x0001  /* overrun error bit */
83 # define SCSCR_INIT(port)       0x0038  /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
84 #elif defined(CONFIG_CPU_SH7366)
85 # define SCPDR0                 0xA405013E      /* 16 bit SCIF0 PSDR */
86 # define SCSPTR0                SCPDR0
87 # define SCIF_ORER              0x0001  /* overrun error bit */
88 # define SCSCR_INIT(port)       0x0038  /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
89 #elif defined(CONFIG_CPU_SH7723)
90 # define SCSPTR0                0xa4050160
91 # define SCSPTR1                0xa405013e
92 # define SCSPTR2                0xa4050160
93 # define SCSPTR3                0xa405013e
94 # define SCSPTR4                0xa4050128
95 # define SCSPTR5                0xa4050128
96 # define SCIF_ORER              0x0001  /* overrun error bit */
97 # define SCSCR_INIT(port)       0x0038  /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
98 #elif defined(CONFIG_CPU_SH7734)
99 # define SCSPTR0 0xFFE40020
100 # define SCSPTR1 0xFFE41020
101 # define SCSPTR2 0xFFE42020
102 # define SCSPTR3 0xFFE43020
103 # define SCSPTR4 0xFFE44020
104 # define SCSPTR5 0xFFE45020
105 # define SCIF_ORER 0x0001  /* overrun error bit */
106 # define SCSCR_INIT(port) 0x0038  /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
107 #elif defined(CONFIG_CPU_SH4_202)
108 # define SCSPTR2 0xffe80020 /* 16 bit SCIF */
109 # define SCIF_ORER 0x0001   /* overrun error bit */
110 # define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
111 #elif defined(CONFIG_CPU_SH5_101) || defined(CONFIG_CPU_SH5_103)
112 # define SCIF_BASE_ADDR    0x01030000
113 # define SCIF_ADDR_SH5     (PHYS_PERIPHERAL_BLOCK+SCIF_BASE_ADDR)
114 # define SCIF_PTR2_OFFS    0x0000020
115 # define SCIF_LSR2_OFFS    0x0000024
116 # define SCSPTR\
117                 ((port->mapbase)+SCIF_PTR2_OFFS) /* 16 bit SCIF */
118 # define SCLSR2\
119                 ((port->mapbase)+SCIF_LSR2_OFFS) /* 16 bit SCIF */
120 # define SCSCR_INIT(port)  0x38         /* TIE=0,RIE=0, TE=1,RE=1,REIE=1 */
121 #elif defined(CONFIG_CPU_SH7757) || \
122         defined(CONFIG_CPU_SH7752) || \
123         defined(CONFIG_CPU_SH7753)
124 # define SCSPTR0 0xfe4b0020
125 # define SCSPTR1 0xfe4b0020
126 # define SCSPTR2 0xfe4b0020
127 # define SCIF_ORER 0x0001
128 # define SCSCR_INIT(port)       0x38
129 # define SCIF_ONLY
130 #elif defined(CONFIG_CPU_SH7763)
131 # define SCSPTR0 0xffe00024 /* 16 bit SCIF */
132 # define SCSPTR1 0xffe08024 /* 16 bit SCIF */
133 # define SCSPTR2 0xffe10020 /* 16 bit SCIF/IRDA */
134 # define SCIF_ORER 0x0001  /* overrun error bit */
135 # define SCSCR_INIT(port)       0x38    /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
136 #elif defined(CONFIG_CPU_SH7770)
137 # define SCSPTR0 0xff923020 /* 16 bit SCIF */
138 # define SCSPTR1 0xff924020 /* 16 bit SCIF */
139 # define SCSPTR2 0xff925020 /* 16 bit SCIF */
140 # define SCIF_ORER 0x0001  /* overrun error bit */
141 # define SCSCR_INIT(port)       0x3c /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,cke=2 */
142 #elif defined(CONFIG_CPU_SH7780)
143 # define SCSPTR0        0xffe00024      /* 16 bit SCIF */
144 # define SCSPTR1        0xffe10024      /* 16 bit SCIF */
145 # define SCIF_ORER      0x0001          /* Overrun error bit */
146
147 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,CKE1=1 */
148 # define SCSCR_INIT(port)       0x3a
149
150 #elif defined(CONFIG_CPU_SH7786)
151 # define SCSPTR0        0xffea0024      /* 16 bit SCIF */
152 # define SCSPTR1        0xffeb0024      /* 16 bit SCIF */
153 # define SCSPTR2        0xffec0024      /* 16 bit SCIF */
154 # define SCSPTR3        0xffed0024      /* 16 bit SCIF */
155 # define SCSPTR4        0xffee0024      /* 16 bit SCIF */
156 # define SCSPTR5        0xffef0024      /* 16 bit SCIF */
157 # define SCIF_ORER      0x0001          /* Overrun error bit */
158 # define SCSCR_INIT(port)       0x3a    /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
159 #elif defined(CONFIG_CPU_SH7201) || \
160         defined(CONFIG_CPU_SH7203) || \
161         defined(CONFIG_CPU_SH7206) || \
162         defined(CONFIG_CPU_SH7263) || \
163         defined(CONFIG_CPU_SH7264)
164 # define SCSPTR0 0xfffe8020 /* 16 bit SCIF */
165 # define SCSPTR1 0xfffe8820 /* 16 bit SCIF */
166 # define SCSPTR2 0xfffe9020 /* 16 bit SCIF */
167 # define SCSPTR3 0xfffe9820 /* 16 bit SCIF */
168 # if defined(CONFIG_CPU_SH7201)
169 #  define SCSPTR4 0xfffeA020 /* 16 bit SCIF */
170 #  define SCSPTR5 0xfffeA820 /* 16 bit SCIF */
171 #  define SCSPTR6 0xfffeB020 /* 16 bit SCIF */
172 #  define SCSPTR7 0xfffeB820 /* 16 bit SCIF */
173 # endif
174 # define SCSCR_INIT(port)       0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
175 #elif defined(CONFIG_CPU_SH7269) || defined(CONFIG_RZA1)
176 # define SCSPTR0 0xe8007020 /* 16 bit SCIF */
177 # define SCSPTR1 0xe8007820 /* 16 bit SCIF */
178 # define SCSPTR2 0xe8008020 /* 16 bit SCIF */
179 # define SCSPTR3 0xe8008820 /* 16 bit SCIF */
180 # define SCSPTR4 0xe8009020 /* 16 bit SCIF */
181 # define SCSPTR5 0xe8009820 /* 16 bit SCIF */
182 # define SCSPTR6 0xe800a020 /* 16 bit SCIF */
183 # define SCSPTR7 0xe800a820 /* 16 bit SCIF */
184 # define SCSCR_INIT(port)       0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
185 # define SCIF_ORER 0x0001  /* overrun error bit */
186 #elif defined(CONFIG_CPU_SH7619)
187 # define SCSPTR0 0xf8400020 /* 16 bit SCIF */
188 # define SCSPTR1 0xf8410020 /* 16 bit SCIF */
189 # define SCSPTR2 0xf8420020 /* 16 bit SCIF */
190 # define SCIF_ORER 0x0001  /* overrun error bit */
191 # define SCSCR_INIT(port)       0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
192 #elif defined(CONFIG_CPU_SHX3)
193 # define SCSPTR0 0xffc30020             /* 16 bit SCIF */
194 # define SCSPTR1 0xffc40020             /* 16 bit SCIF */
195 # define SCSPTR2 0xffc50020             /* 16 bit SCIF */
196 # define SCSPTR3 0xffc60020             /* 16 bit SCIF */
197 # define SCIF_ORER 0x0001               /* Overrun error bit */
198 # define SCSCR_INIT(port)       0x38    /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
199 #elif defined(CONFIG_RCAR_GEN2) || defined(CONFIG_RCAR_GEN3) || \
200       defined(CONFIG_R7S72100)
201 # if defined(CONFIG_SCIF_A)
202 #  define SCIF_ORER     0x0200
203 # else
204 #  define SCIF_ORER     0x0001
205 # endif
206 # define SCSCR_INIT(port)       (port->clk_mode == EXT_CLK ? 0x32 : 0x30)
207                                 /* TIE=0,RIE=0,TE=1,RE=1,REIE=0, */
208 #else
209 # error CPU subtype not defined
210 #endif
211
212 /* SCSCR */
213 #define SCI_CTRL_FLAGS_TIE  0x80 /* all */
214 #define SCI_CTRL_FLAGS_RIE  0x40 /* all */
215 #define SCI_CTRL_FLAGS_TE   0x20 /* all */
216 #define SCI_CTRL_FLAGS_RE   0x10 /* all */
217 #if defined(CONFIG_CPU_SH7750)  || \
218         defined(CONFIG_CPU_SH7091)  || \
219         defined(CONFIG_CPU_SH7750R) || \
220         defined(CONFIG_CPU_SH7722)  || \
221         defined(CONFIG_CPU_SH7734)  || \
222         defined(CONFIG_CPU_SH7750S) || \
223         defined(CONFIG_CPU_SH7751)  || \
224         defined(CONFIG_CPU_SH7751R) || \
225         defined(CONFIG_CPU_SH7763)  || \
226         defined(CONFIG_CPU_SH7780)  || \
227         defined(CONFIG_CPU_SH7786)  || \
228         defined(CONFIG_CPU_SHX3)
229 #define SCI_CTRL_FLAGS_REIE 0x08 /* 7750 SCIF */
230 #else
231 #define SCI_CTRL_FLAGS_REIE 0
232 #endif
233 /*              SCI_CTRL_FLAGS_MPIE 0x08  * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
234 /*              SCI_CTRL_FLAGS_TEIE 0x04  * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
235 /*              SCI_CTRL_FLAGS_CKE1 0x02  * all */
236 /*              SCI_CTRL_FLAGS_CKE0 0x01  * 7707 SCI/SCIF, 7708 SCI, 7709 SCI/SCIF, 7750 SCI */
237
238 /* SCxSR SCI */
239 #define SCI_TDRE  0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
240 #define SCI_RDRF  0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
241 #define SCI_ORER  0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
242 #define SCI_FER   0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
243 #define SCI_PER   0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
244 #define SCI_TEND  0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
245 /*      SCI_MPB   0x02  * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
246 /*      SCI_MPBT  0x01  * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
247
248 #define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
249
250 /* SCxSR SCIF */
251 #define SCIF_ER    0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
252 #define SCIF_TEND  0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
253 #define SCIF_TDFE  0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
254 #define SCIF_BRK   0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
255 #define SCIF_FER   0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
256 #define SCIF_PER   0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
257 #define SCIF_RDF   0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
258 #define SCIF_DR    0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
259
260 #if defined(CONFIG_CPU_SH7705) || \
261         defined(CONFIG_CPU_SH7720) || \
262         defined(CONFIG_CPU_SH7721) || \
263         defined(CONFIG_ARCH_SH7367) || \
264         defined(CONFIG_ARCH_SH7377) || \
265         defined(CONFIG_ARCH_SH7372) || \
266         defined(CONFIG_SH73A0) || \
267         defined(CONFIG_R8A7740)
268 # define SCIF_ORER    0x0200
269 # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
270 # define SCIF_RFDC_MASK 0x007f
271 # define SCIF_TXROOM_MAX 64
272 #elif defined(CONFIG_CPU_SH7763)
273 # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
274 # define SCIF_RFDC_MASK 0x007f
275 # define SCIF_TXROOM_MAX 64
276 /* SH7763 SCIF2 support */
277 # define SCIF2_RFDC_MASK 0x001f
278 # define SCIF2_TXROOM_MAX 16
279 #elif defined(CONFIG_RCAR_GEN2)
280 # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
281 # if defined(CONFIG_SCIF_A)
282 #  define SCIF_RFDC_MASK        0x007f
283 # else
284 #  define SCIF_RFDC_MASK        0x001f
285 # endif
286 #else
287 # define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
288 # define SCIF_RFDC_MASK 0x001f
289 # define SCIF_TXROOM_MAX 16
290 #endif
291
292 #ifndef SCIF_ORER
293 #define SCIF_ORER       0x0000
294 #endif
295
296 #define SCxSR_TEND(port)\
297                 (((port)->type == PORT_SCI) ? SCI_TEND  : SCIF_TEND)
298 #define SCxSR_ERRORS(port)\
299                 (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
300 #define SCxSR_RDxF(port)\
301                 (((port)->type == PORT_SCI) ? SCI_RDRF  : SCIF_RDF)
302 #define SCxSR_TDxE(port)\
303                 (((port)->type == PORT_SCI) ? SCI_TDRE  : SCIF_TDFE)
304 #define SCxSR_FER(port)\
305                 (((port)->type == PORT_SCI) ? SCI_FER   : SCIF_FER)
306 #define SCxSR_PER(port)\
307                 (((port)->type == PORT_SCI) ? SCI_PER   : SCIF_PER)
308 #define SCxSR_BRK(port)\
309                 ((port)->type == PORT_SCI) ? 0x00               : SCIF_BRK)
310 #define SCxSR_ORER(port)\
311                 (((port)->type == PORT_SCI) ? SCI_ORER  : SCIF_ORER)
312
313 #if defined(CONFIG_CPU_SH7705) || \
314         defined(CONFIG_CPU_SH7720) || \
315         defined(CONFIG_CPU_SH7721) || \
316         defined(CONFIG_ARCH_SH7367) || \
317         defined(CONFIG_ARCH_SH7377) || \
318         defined(CONFIG_ARCH_SH7372) || \
319         defined(CONFIG_SH73A0) || \
320         defined(CONFIG_R8A7740)
321 # define SCxSR_RDxF_CLEAR(port)  (sci_in(port, SCxSR) & 0xfffc)
322 # define SCxSR_ERROR_CLEAR(port) (sci_in(port, SCxSR) & 0xfd73)
323 # define SCxSR_TDxE_CLEAR(port)  (sci_in(port, SCxSR) & 0xffdf)
324 # define SCxSR_BREAK_CLEAR(port) (sci_in(port, SCxSR) & 0xffe3)
325 #else
326 # define SCxSR_RDxF_CLEAR(port)  (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
327 # define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
328 # define SCxSR_TDxE_CLEAR(port)  (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
329 # define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
330 #endif
331
332 /* SCFCR */
333 #define SCFCR_RFRST 0x0002
334 #define SCFCR_TFRST 0x0004
335 #define SCFCR_TCRST 0x4000
336 #define SCFCR_MCE   0x0008
337
338 #define SCI_MAJOR               204
339 #define SCI_MINOR_START         8
340
341 /* Generic serial flags */
342 #define SCI_RX_THROTTLE         0x0000001
343
344 #define SCI_MAGIC 0xbabeface
345
346 /*
347  * Events are used to schedule things to happen at timer-interrupt
348  * time, instead of at rs interrupt time.
349  */
350 #define SCI_EVENT_WRITE_WAKEUP  0
351
352 #define SCI_IN(size, offset)\
353         if ((size) == 8) {\
354                 return readb(port->membase + (offset));\
355         } else {\
356                 return readw(port->membase + (offset));\
357         }
358 #define SCI_OUT(size, offset, value)\
359         if ((size) == 8) {\
360                 writeb(value, port->membase + (offset));\
361         } else if ((size) == 16) {\
362                 writew(value, port->membase + (offset));\
363         }
364
365 #define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
366         static inline unsigned int sci_##name##_in(struct uart_port *port) {\
367                 if (port->type == PORT_SCIF || port->type == PORT_SCIFB) {\
368                         SCI_IN(scif_size, scif_offset)\
369                 } else { /* PORT_SCI or PORT_SCIFA */\
370                         SCI_IN(sci_size, sci_offset);\
371                 }\
372         }\
373 static inline void sci_##name##_out(struct uart_port *port,\
374                                 unsigned int value) {\
375         if (port->type == PORT_SCIF || port->type == PORT_SCIFB) {\
376                 SCI_OUT(scif_size, scif_offset, value)\
377         } else {        /* PORT_SCI or PORT_SCIFA */\
378                 SCI_OUT(sci_size, sci_offset, value);\
379         }\
380 }
381
382 #define CPU_SCIF_FNS(name, scif_offset, scif_size)                      \
383         static inline unsigned int sci_##name##_in(struct uart_port *port) {\
384                 SCI_IN(scif_size, scif_offset);\
385         }\
386         static inline void sci_##name##_out(struct uart_port *port,\
387                                         unsigned int value) {\
388                 SCI_OUT(scif_size, scif_offset, value);\
389         }
390
391 #define CPU_SCI_FNS(name, sci_offset, sci_size)\
392         static inline unsigned int sci_##name##_in(struct uart_port *port) {\
393                 SCI_IN(sci_size, sci_offset);\
394         }\
395         static inline void sci_##name##_out(struct uart_port *port,\
396                                         unsigned int value) {\
397                 SCI_OUT(sci_size, sci_offset, value);\
398         }
399
400 #if defined(CONFIG_CPU_SH3) || \
401         defined(CONFIG_ARCH_SH7367) || \
402         defined(CONFIG_ARCH_SH7377) || \
403         defined(CONFIG_ARCH_SH7372) || \
404         defined(CONFIG_SH73A0) || \
405         defined(CONFIG_R8A7740)
406 #if defined(CONFIG_CPU_SH7710) || defined(CONFIG_CPU_SH7712)
407 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
408                                 sh4_sci_offset, sh4_sci_size, \
409                                 sh3_scif_offset, sh3_scif_size, \
410                                 sh4_scif_offset, sh4_scif_size, \
411                                 h8_sci_offset, h8_sci_size) \
412         CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size,\
413                                 sh4_scif_offset, sh4_scif_size)
414 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
415                                 sh4_scif_offset, sh4_scif_size) \
416         CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
417 #elif defined(CONFIG_CPU_SH7705) || \
418         defined(CONFIG_CPU_SH7720) || \
419         defined(CONFIG_CPU_SH7721) || \
420         defined(CONFIG_ARCH_SH7367) || \
421         defined(CONFIG_ARCH_SH7377) || \
422         defined(CONFIG_SH73A0)
423 #define SCIF_FNS(name, scif_offset, scif_size) \
424         CPU_SCIF_FNS(name, scif_offset, scif_size)
425 #elif defined(CONFIG_ARCH_SH7372) || \
426         defined(CONFIG_R8A7740)
427 #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
428                                 sh4_scifb_offset, sh4_scifb_size) \
429         CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
430                                 sh4_scifb_offset, sh4_scifb_size)
431 #define SCIF_FNS(name, scif_offset, scif_size) \
432         CPU_SCIF_FNS(name, scif_offset, scif_size)
433 #else
434 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
435                                 sh4_sci_offset, sh4_sci_size, \
436                                 sh3_scif_offset, sh3_scif_size,\
437                                 sh4_scif_offset, sh4_scif_size, \
438                                 h8_sci_offset, h8_sci_size) \
439         CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
440                                 sh3_scif_offset, sh3_scif_size)
441 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
442                                 sh4_scif_offset, sh4_scif_size) \
443         CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
444 #endif
445 #elif defined(CONFIG_CPU_SH7723)
446                 #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
447                                         sh4_scif_offset, sh4_scif_size) \
448                         CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
449                                         sh4_scif_offset, sh4_scif_size)
450                 #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \
451                         CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
452 #else
453 #define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
454                                 sh4_sci_offset, sh4_sci_size, \
455                                 sh3_scif_offset, sh3_scif_size,\
456                                 sh4_scif_offset, sh4_scif_size, \
457                                 h8_sci_offset, h8_sci_size) \
458         CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size,\
459                                         sh4_scif_offset, sh4_scif_size)
460 #define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, \
461                                 sh4_scif_offset, sh4_scif_size) \
462         CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
463 #endif
464
465 #if defined(CONFIG_CPU_SH7705) || \
466         defined(CONFIG_CPU_SH7720) || \
467         defined(CONFIG_CPU_SH7721) || \
468         defined(CONFIG_ARCH_SH7367) || \
469         defined(CONFIG_ARCH_SH7377) || \
470         defined(CONFIG_SH73A0)
471
472 SCIF_FNS(SCSMR,  0x00, 16)
473 SCIF_FNS(SCBRR,  0x04,  8)
474 SCIF_FNS(SCSCR,  0x08, 16)
475 SCIF_FNS(SCTDSR, 0x0c,  8)
476 SCIF_FNS(SCFER,  0x10, 16)
477 SCIF_FNS(SCxSR,  0x14, 16)
478 SCIF_FNS(SCFCR,  0x18, 16)
479 SCIF_FNS(SCFDR,  0x1c, 16)
480 SCIF_FNS(SCxTDR, 0x20,  8)
481 SCIF_FNS(SCxRDR, 0x24,  8)
482 SCIF_FNS(SCLSR,  0x00,  0)
483 SCIF_FNS(DL,     0x00,  0) /* dummy */
484 #elif defined(CONFIG_ARCH_SH7372) || \
485         defined(CONFIG_R8A7740)
486 SCIF_FNS(SCSMR,  0x00, 16)
487 SCIF_FNS(SCBRR,  0x04,  8)
488 SCIF_FNS(SCSCR,  0x08, 16)
489 SCIF_FNS(SCTDSR, 0x0c, 16)
490 SCIF_FNS(SCFER,  0x10, 16)
491 SCIF_FNS(SCxSR,  0x14, 16)
492 SCIF_FNS(SCFCR,  0x18, 16)
493 SCIF_FNS(SCFDR,  0x1c, 16)
494 SCIF_FNS(SCTFDR, 0x38, 16)
495 SCIF_FNS(SCRFDR, 0x3c, 16)
496 SCIx_FNS(SCxTDR, 0x20,  8, 0x40,  8)
497 SCIx_FNS(SCxRDR, 0x24,  8, 0x60,  8)
498 SCIF_FNS(SCLSR,  0x00,  0)
499 SCIF_FNS(DL,     0x00,  0) /* dummy */
500 #elif defined(CONFIG_CPU_SH7723)
501 SCIx_FNS(SCSMR,  0x00, 16, 0x00, 16)
502 SCIx_FNS(SCBRR,  0x04,  8, 0x04,  8)
503 SCIx_FNS(SCSCR,  0x08, 16, 0x08, 16)
504 SCIx_FNS(SCxTDR, 0x20,  8, 0x0c,  8)
505 SCIx_FNS(SCxSR,  0x14, 16, 0x10, 16)
506 SCIx_FNS(SCxRDR, 0x24,  8, 0x14,  8)
507 SCIx_FNS(SCSPTR, 0,     0,    0,  0)
508 SCIF_FNS(SCTDSR, 0x0c,  8)
509 SCIF_FNS(SCFER,  0x10, 16)
510 SCIF_FNS(SCFCR,  0x18, 16)
511 SCIF_FNS(SCFDR,  0x1c, 16)
512 SCIF_FNS(SCLSR,  0x24, 16)
513 SCIF_FNS(DL,     0x00,  0) /* dummy */
514 #elif defined(CONFIG_RCAR_GEN2)
515 /* SCIFA and SCIF register offsets and size */
516 SCIx_FNS(SCSMR,  0,  0, 0x00, 16, 0,  0, 0x00, 16, 0,  0)
517 SCIx_FNS(SCBRR,  0,  0, 0x04,  8, 0,  0, 0x04,  8, 0,  0)
518 SCIx_FNS(SCSCR,  0,  0, 0x08, 16, 0,  0, 0x08, 16, 0,  0)
519 SCIx_FNS(SCxTDR, 0,  0, 0x20,  8, 0,  0, 0x0C,  8, 0,  0)
520 SCIx_FNS(SCxSR,  0,  0, 0x14, 16, 0,  0, 0x10, 16, 0,  0)
521 SCIx_FNS(SCxRDR, 0,  0, 0x24,  8, 0,  0, 0x14,  8, 0,  0)
522 SCIF_FNS(SCFCR,  0,  0, 0x18, 16)
523 SCIF_FNS(SCFDR,  0,  0, 0x1C, 16)
524 SCIF_FNS(SCSPTR, 0,  0, 0x20, 16)
525 SCIF_FNS(DL,     0,  0, 0x30, 16)
526 SCIF_FNS(CKS,    0,  0, 0x34, 16)
527 #if defined(CONFIG_SCIF_A)
528 SCIF_FNS(SCLSR,  0,  0, 0x14, 16)
529 #else
530 SCIF_FNS(SCLSR,  0,  0, 0x24, 16)
531 #endif
532 #else
533 /*      reg      SCI/SH3   SCI/SH4  SCIF/SH3   SCIF/SH4  SCI/H8*/
534 /*      name     off  sz   off  sz   off  sz   off  sz   off  sz*/
535 SCIx_FNS(SCSMR,  0x00,  8, 0x00,  8, 0x00,  8, 0x00, 16, 0x00,  8)
536 SCIx_FNS(SCBRR,  0x02,  8, 0x04,  8, 0x02,  8, 0x04,  8, 0x01,  8)
537 SCIx_FNS(SCSCR,  0x04,  8, 0x08,  8, 0x04,  8, 0x08, 16, 0x02,  8)
538 SCIx_FNS(SCxTDR, 0x06,  8, 0x0c,  8, 0x06,  8, 0x0C,  8, 0x03,  8)
539 SCIx_FNS(SCxSR,  0x08,  8, 0x10,  8, 0x08, 16, 0x10, 16, 0x04,  8)
540 SCIx_FNS(SCxRDR, 0x0a,  8, 0x14,  8, 0x0A,  8, 0x14,  8, 0x05,  8)
541 SCIF_FNS(SCFCR,                      0x0c,  8, 0x18, 16)
542 #if defined(CONFIG_CPU_SH7760) || \
543         defined(CONFIG_CPU_SH7780) || \
544         defined(CONFIG_CPU_SH7786)
545 SCIF_FNS(SCFDR,                      0x0e, 16, 0x1C, 16)
546 SCIF_FNS(SCTFDR,                     0x0e, 16, 0x1C, 16)
547 SCIF_FNS(SCRFDR,                     0x0e, 16, 0x20, 16)
548 SCIF_FNS(SCSPTR,                        0,  0, 0x24, 16)
549 SCIF_FNS(SCLSR,                         0,  0, 0x28, 16)
550 #elif defined(CONFIG_CPU_SH7763)
551 SCIF_FNS(SCFDR,                         0,  0, 0x1C, 16)
552 SCIF_FNS(SCSPTR2,                       0,  0, 0x20, 16)
553 SCIF_FNS(SCLSR2,                        0,  0, 0x24, 16)
554 SCIF_FNS(SCTFDR,                     0x0e, 16, 0x1C, 16)
555 SCIF_FNS(SCRFDR,                     0x0e, 16, 0x20, 16)
556 SCIF_FNS(SCSPTR,                        0,  0, 0x24, 16)
557 SCIF_FNS(SCLSR,                         0,  0, 0x28, 16)
558 #else
559
560 SCIF_FNS(SCFDR,                      0x0e, 16, 0x1C, 16)
561 #if defined(CONFIG_CPU_SH7722)
562 SCIF_FNS(SCSPTR,                        0,  0, 0, 0)
563 #else
564 SCIF_FNS(SCSPTR,                        0,  0, 0x20, 16)
565 #endif
566 SCIF_FNS(SCLSR,                         0,  0, 0x24, 16)
567 #endif
568 SCIF_FNS(DL,                            0,  0, 0x0,  0) /* dummy */
569 #endif
570 #define sci_in(port, reg) sci_##reg##_in(port)
571 #define sci_out(port, reg, value) sci_##reg##_out(port, value)
572
573 #if defined(CONFIG_CPU_SH7706) || \
574         defined(CONFIG_CPU_SH7707) || \
575         defined(CONFIG_CPU_SH7708) || \
576         defined(CONFIG_CPU_SH7709)
577 static inline int sci_rxd_in(struct uart_port *port)
578 {
579         if (port->mapbase == 0xfffffe80)
580                 return __raw_readb(SCPDR)&0x01 ? 1 : 0; /* SCI */
581         return 1;
582 }
583 #elif defined(CONFIG_CPU_SH7750)  || \
584         defined(CONFIG_CPU_SH7751)  || \
585         defined(CONFIG_CPU_SH7751R) || \
586         defined(CONFIG_CPU_SH7750R) || \
587         defined(CONFIG_CPU_SH7750S) || \
588         defined(CONFIG_CPU_SH7091)
589 static inline int sci_rxd_in(struct uart_port *port)
590 {
591         if (port->mapbase == 0xffe00000)
592                 return __raw_readb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
593         return 1;
594 }
595 #else /* default case for non-SCI processors */
596 static inline int sci_rxd_in(struct uart_port *port)
597 {
598         return 1;
599 }
600 #endif
601
602 /*
603  * Values for the BitRate Register (SCBRR)
604  *
605  * The values are actually divisors for a frequency which can
606  * be internal to the SH3 (14.7456MHz) or derived from an external
607  * clock source.  This driver assumes the internal clock is used;
608  * to support using an external clock source, config options or
609  * possibly command-line options would need to be added.
610  *
611  * Also, to support speeds below 2400 (why?) the lower 2 bits of
612  * the SCSMR register would also need to be set to non-zero values.
613  *
614  * -- Greg Banks 27Feb2000
615  *
616  * Answer: The SCBRR register is only eight bits, and the value in
617  * it gets larger with lower baud rates. At around 2400 (depending on
618  * the peripherial module clock) you run out of bits. However the
619  * lower two bits of SCSMR allow the module clock to be divided down,
620  * scaling the value which is needed in SCBRR.
621  *
622  * -- Stuart Menefy - 23 May 2000
623  *
624  * I meant, why would anyone bother with bitrates below 2400.
625  *
626  * -- Greg Banks - 7Jul2000
627  *
628  * You "speedist"!  How will I use my 110bps ASR-33 teletype with paper
629  * tape reader as a console!
630  *
631  * -- Mitch Davis - 15 Jul 2000
632  */
633
634 #if defined(CONFIG_CPU_SH7780) || \
635         defined(CONFIG_CPU_SH7786)
636 #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1)
637 #elif defined(CONFIG_CPU_SH7705) || \
638         defined(CONFIG_CPU_SH7720) || \
639         defined(CONFIG_CPU_SH7721) || \
640         defined(CONFIG_ARCH_SH7367) || \
641         defined(CONFIG_ARCH_SH7377) || \
642         defined(CONFIG_ARCH_SH7372) || \
643         defined(CONFIG_SH73A0) || \
644         defined(CONFIG_R8A7740)
645 #define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1)
646 #elif defined(CONFIG_CPU_SH7723)
647 static inline int scbrr_calc(struct uart_port *port, int bps, int clk)
648 {
649         if (port->type == PORT_SCIF)
650                 return (clk+16*bps)/(32*bps)-1;
651         else
652                 return ((clk*2)+16*bps)/(16*bps)-1;
653 }
654 #define SCBRR_VALUE(bps, clk) scbrr_calc(port, bps, clk)
655 #elif defined(CONFIG_RCAR_GEN2)
656 #define DL_VALUE(bps, clk) (clk / bps / 16) /* External Clock */
657  #if defined(CONFIG_SCIF_A)
658   #define SCBRR_VALUE(bps, clk) (clk / bps / 16 - 1) /* Internal Clock */
659  #else
660   #define SCBRR_VALUE(bps, clk) (clk / bps / 32 - 1) /* Internal Clock */
661  #endif
662 #else /* Generic SH */
663 #define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1)
664 #endif
665
666 #ifndef DL_VALUE
667 #define DL_VALUE(bps, clk) 0
668 #endif