blob: f13deec72a47763b7561dbc51c52bbc2bca085fc [file] [log] [blame]
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +09001/*
2 * Copy and modify from linux/drivers/serial/sh-sci.h
3 */
4
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +09005#include <dm/platform_data/serial_sh.h>
6
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +09007struct uart_port {
8 unsigned long iobase; /* in/out[bwl] */
9 unsigned char *membase; /* read/write[bwl] */
10 unsigned long mapbase; /* for ioremap */
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +090011 enum sh_serial_type type; /* port type */
12 enum sh_clk_mode clk_mode; /* clock mode */
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +090013};
14
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +090015#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) || \
Hideyuki Sanod61678e2012-06-25 10:29:56 +090037 defined(CONFIG_SH73A0) || \
38 defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +090039# define SCSCR_INIT(port) 0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
40# define PORT_PTCR 0xA405011EUL
41# define PORT_PVCR 0xA4050122UL
42# define SCIF_ORER 0x0200 /* overrun error bit */
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +090043#elif defined(CONFIG_CPU_SH7750) || \
44 defined(CONFIG_CPU_SH7750R) || \
45 defined(CONFIG_CPU_SH7750S) || \
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +090046 defined(CONFIG_CPU_SH7751) || \
47 defined(CONFIG_CPU_SH7751R)
48# define SCSPTR1 0xffe0001c /* 8 bit SCI */
49# define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
50# define SCIF_ORER 0x0001 /* overrun error bit */
51# define SCSCR_INIT(port) (((port)->type == PORT_SCI) ? \
52 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
53 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +090054#elif defined(CONFIG_CPU_SH7710) || defined(CONFIG_CPU_SH7712)
55# define SCSPTR0 0xA4400000 /* 16 bit SCIF */
56# define SCIF_ORER 0x0001 /* overrun error bit */
57# define PACR 0xa4050100
58# define PBCR 0xa4050102
59# define SCSCR_INIT(port) 0x3B
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +090060#elif defined(CONFIG_CPU_SH7722)
61# define PADR 0xA4050120
Nobuhiro Iwamatsu99057062010-11-24 13:24:33 +090062# undef PSDR
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +090063# define PSDR 0xA405013e
64# define PWDR 0xA4050166
65# define PSCR 0xA405011E
66# define SCIF_ORER 0x0001 /* overrun error bit */
67# define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +090068#elif defined(CONFIG_CPU_SH7723)
69# define SCSPTR0 0xa4050160
70# define SCSPTR1 0xa405013e
71# define SCSPTR2 0xa4050160
72# define SCSPTR3 0xa405013e
73# define SCSPTR4 0xa4050128
74# define SCSPTR5 0xa4050128
75# define SCIF_ORER 0x0001 /* overrun error bit */
76# define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
Nobuhiro Iwamatsu2a57e7e2012-01-11 10:45:01 +090077#elif defined(CONFIG_CPU_SH7734)
78# define SCSPTR0 0xFFE40020
79# define SCSPTR1 0xFFE41020
80# define SCSPTR2 0xFFE42020
81# define SCSPTR3 0xFFE43020
82# define SCSPTR4 0xFFE44020
83# define SCSPTR5 0xFFE45020
84# define SCIF_ORER 0x0001 /* overrun error bit */
85# define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
Yoshihiro Shimodaf3bf2122013-12-18 16:04:20 +090086#elif defined(CONFIG_CPU_SH7757) || \
87 defined(CONFIG_CPU_SH7752) || \
88 defined(CONFIG_CPU_SH7753)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +090089# define SCSPTR0 0xfe4b0020
90# define SCSPTR1 0xfe4b0020
91# define SCSPTR2 0xfe4b0020
92# define SCIF_ORER 0x0001
93# define SCSCR_INIT(port) 0x38
94# define SCIF_ONLY
95#elif defined(CONFIG_CPU_SH7763)
96# define SCSPTR0 0xffe00024 /* 16 bit SCIF */
97# define SCSPTR1 0xffe08024 /* 16 bit SCIF */
98# define SCSPTR2 0xffe10020 /* 16 bit SCIF/IRDA */
99# define SCIF_ORER 0x0001 /* overrun error bit */
100# define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900101#elif defined(CONFIG_CPU_SH7780)
102# define SCSPTR0 0xffe00024 /* 16 bit SCIF */
103# define SCSPTR1 0xffe10024 /* 16 bit SCIF */
104# define SCIF_ORER 0x0001 /* Overrun error bit */
105
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900106/* TIE=0,RIE=0,TE=1,RE=1,REIE=1,CKE1=1 */
107# define SCSCR_INIT(port) 0x3a
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900108
Marek Vasut7de3ea82019-05-07 21:52:47 +0200109#elif defined(CONFIG_RZA1)
Phil Edworthy99744b72012-05-15 22:15:51 +0000110# define SCSPTR0 0xe8007020 /* 16 bit SCIF */
111# define SCSPTR1 0xe8007820 /* 16 bit SCIF */
112# define SCSPTR2 0xe8008020 /* 16 bit SCIF */
113# define SCSPTR3 0xe8008820 /* 16 bit SCIF */
114# define SCSPTR4 0xe8009020 /* 16 bit SCIF */
115# define SCSPTR5 0xe8009820 /* 16 bit SCIF */
116# define SCSPTR6 0xe800a020 /* 16 bit SCIF */
117# define SCSPTR7 0xe800a820 /* 16 bit SCIF */
118# define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
Marek Vasut67180fe2019-05-01 18:20:00 +0200119# define SCIF_ORER 0x0001 /* overrun error bit */
Chris Brandt8591ac82018-01-16 20:52:18 -0500120#elif defined(CONFIG_RCAR_GEN2) || defined(CONFIG_RCAR_GEN3) || \
121 defined(CONFIG_R7S72100)
Vladimir Barinov53be7bf2015-07-20 20:49:39 +0300122# if defined(CONFIG_SCIF_A)
123# define SCIF_ORER 0x0200
124# else
125# define SCIF_ORER 0x0001
126# endif
Vladimir Barinov2cbb17c2015-02-14 01:05:18 +0300127# define SCSCR_INIT(port) (port->clk_mode == EXT_CLK ? 0x32 : 0x30)
128 /* TIE=0,RIE=0,TE=1,RE=1,REIE=0, */
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900129#else
130# error CPU subtype not defined
131#endif
132
133/* SCSCR */
134#define SCI_CTRL_FLAGS_TIE 0x80 /* all */
135#define SCI_CTRL_FLAGS_RIE 0x40 /* all */
136#define SCI_CTRL_FLAGS_TE 0x20 /* all */
137#define SCI_CTRL_FLAGS_RE 0x10 /* all */
138#if defined(CONFIG_CPU_SH7750) || \
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900139 defined(CONFIG_CPU_SH7750R) || \
140 defined(CONFIG_CPU_SH7722) || \
Nobuhiro Iwamatsu2a57e7e2012-01-11 10:45:01 +0900141 defined(CONFIG_CPU_SH7734) || \
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900142 defined(CONFIG_CPU_SH7750S) || \
143 defined(CONFIG_CPU_SH7751) || \
144 defined(CONFIG_CPU_SH7751R) || \
145 defined(CONFIG_CPU_SH7763) || \
Marek Vasut10e91cf2019-05-07 22:31:23 +0200146 defined(CONFIG_CPU_SH7780)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900147#define SCI_CTRL_FLAGS_REIE 0x08 /* 7750 SCIF */
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900148#else
149#define SCI_CTRL_FLAGS_REIE 0
150#endif
151/* SCI_CTRL_FLAGS_MPIE 0x08 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
152/* SCI_CTRL_FLAGS_TEIE 0x04 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
153/* SCI_CTRL_FLAGS_CKE1 0x02 * all */
154/* SCI_CTRL_FLAGS_CKE0 0x01 * 7707 SCI/SCIF, 7708 SCI, 7709 SCI/SCIF, 7750 SCI */
155
156/* SCxSR SCI */
157#define SCI_TDRE 0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
158#define SCI_RDRF 0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
159#define SCI_ORER 0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
160#define SCI_FER 0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
161#define SCI_PER 0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
162#define SCI_TEND 0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
163/* SCI_MPB 0x02 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
164/* SCI_MPBT 0x01 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
165
166#define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
167
168/* SCxSR SCIF */
169#define SCIF_ER 0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
170#define SCIF_TEND 0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
171#define SCIF_TDFE 0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
172#define SCIF_BRK 0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
173#define SCIF_FER 0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
174#define SCIF_PER 0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
175#define SCIF_RDF 0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
176#define SCIF_DR 0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
177
178#if defined(CONFIG_CPU_SH7705) || \
179 defined(CONFIG_CPU_SH7720) || \
180 defined(CONFIG_CPU_SH7721) || \
Hideyuki Sanod61678e2012-06-25 10:29:56 +0900181 defined(CONFIG_SH73A0) || \
182 defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900183# define SCIF_ORER 0x0200
184# define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
185# define SCIF_RFDC_MASK 0x007f
186# define SCIF_TXROOM_MAX 64
187#elif defined(CONFIG_CPU_SH7763)
188# define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
189# define SCIF_RFDC_MASK 0x007f
190# define SCIF_TXROOM_MAX 64
191/* SH7763 SCIF2 support */
192# define SCIF2_RFDC_MASK 0x001f
193# define SCIF2_TXROOM_MAX 16
Marek Vasuta6e25b22018-01-22 01:43:25 +0100194#elif defined(CONFIG_RCAR_GEN2)
Nobuhiro Iwamatsu48ca8822013-07-23 13:58:20 +0900195# define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
Vladimir Barinov53be7bf2015-07-20 20:49:39 +0300196# if defined(CONFIG_SCIF_A)
197# define SCIF_RFDC_MASK 0x007f
198# else
199# define SCIF_RFDC_MASK 0x001f
200# endif
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900201#else
202# define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
203# define SCIF_RFDC_MASK 0x001f
204# define SCIF_TXROOM_MAX 16
205#endif
206
207#ifndef SCIF_ORER
208#define SCIF_ORER 0x0000
209#endif
210
211#define SCxSR_TEND(port)\
212 (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
213#define SCxSR_ERRORS(port)\
214 (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
215#define SCxSR_RDxF(port)\
216 (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
217#define SCxSR_TDxE(port)\
218 (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
219#define SCxSR_FER(port)\
220 (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
221#define SCxSR_PER(port)\
222 (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
223#define SCxSR_BRK(port)\
224 ((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
225#define SCxSR_ORER(port)\
226 (((port)->type == PORT_SCI) ? SCI_ORER : SCIF_ORER)
227
228#if defined(CONFIG_CPU_SH7705) || \
229 defined(CONFIG_CPU_SH7720) || \
230 defined(CONFIG_CPU_SH7721) || \
Hideyuki Sanod61678e2012-06-25 10:29:56 +0900231 defined(CONFIG_SH73A0) || \
232 defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900233# define SCxSR_RDxF_CLEAR(port) (sci_in(port, SCxSR) & 0xfffc)
234# define SCxSR_ERROR_CLEAR(port) (sci_in(port, SCxSR) & 0xfd73)
235# define SCxSR_TDxE_CLEAR(port) (sci_in(port, SCxSR) & 0xffdf)
236# define SCxSR_BREAK_CLEAR(port) (sci_in(port, SCxSR) & 0xffe3)
237#else
238# define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
239# define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
240# define SCxSR_TDxE_CLEAR(port) (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
241# define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
242#endif
243
244/* SCFCR */
245#define SCFCR_RFRST 0x0002
246#define SCFCR_TFRST 0x0004
247#define SCFCR_TCRST 0x4000
248#define SCFCR_MCE 0x0008
249
250#define SCI_MAJOR 204
251#define SCI_MINOR_START 8
252
253/* Generic serial flags */
254#define SCI_RX_THROTTLE 0x0000001
255
256#define SCI_MAGIC 0xbabeface
257
258/*
259 * Events are used to schedule things to happen at timer-interrupt
260 * time, instead of at rs interrupt time.
261 */
262#define SCI_EVENT_WRITE_WAKEUP 0
263
264#define SCI_IN(size, offset)\
265 if ((size) == 8) {\
266 return readb(port->membase + (offset));\
267 } else {\
268 return readw(port->membase + (offset));\
269 }
270#define SCI_OUT(size, offset, value)\
271 if ((size) == 8) {\
272 writeb(value, port->membase + (offset));\
273 } else if ((size) == 16) {\
274 writew(value, port->membase + (offset));\
275 }
276
277#define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
278 static inline unsigned int sci_##name##_in(struct uart_port *port) {\
279 if (port->type == PORT_SCIF || port->type == PORT_SCIFB) {\
280 SCI_IN(scif_size, scif_offset)\
281 } else { /* PORT_SCI or PORT_SCIFA */\
282 SCI_IN(sci_size, sci_offset);\
283 }\
284 }\
285static inline void sci_##name##_out(struct uart_port *port,\
286 unsigned int value) {\
287 if (port->type == PORT_SCIF || port->type == PORT_SCIFB) {\
288 SCI_OUT(scif_size, scif_offset, value)\
289 } else { /* PORT_SCI or PORT_SCIFA */\
290 SCI_OUT(sci_size, sci_offset, value);\
291 }\
292}
293
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900294#define CPU_SCIF_FNS(name, scif_offset, scif_size) \
295 static inline unsigned int sci_##name##_in(struct uart_port *port) {\
296 SCI_IN(scif_size, scif_offset);\
297 }\
298 static inline void sci_##name##_out(struct uart_port *port,\
299 unsigned int value) {\
300 SCI_OUT(scif_size, scif_offset, value);\
301 }
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900302
303#define CPU_SCI_FNS(name, sci_offset, sci_size)\
304 static inline unsigned int sci_##name##_in(struct uart_port *port) {\
305 SCI_IN(sci_size, sci_offset);\
306 }\
307 static inline void sci_##name##_out(struct uart_port *port,\
308 unsigned int value) {\
309 SCI_OUT(sci_size, sci_offset, value);\
310 }
311
Masahiro Yamada7d236662014-11-06 15:55:21 +0900312#if defined(CONFIG_CPU_SH3) || \
Hideyuki Sanod61678e2012-06-25 10:29:56 +0900313 defined(CONFIG_SH73A0) || \
314 defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900315#if defined(CONFIG_CPU_SH7710) || defined(CONFIG_CPU_SH7712)
316#define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
317 sh4_sci_offset, sh4_sci_size, \
318 sh3_scif_offset, sh3_scif_size, \
319 sh4_scif_offset, sh4_scif_size, \
320 h8_sci_offset, h8_sci_size) \
321 CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size,\
322 sh4_scif_offset, sh4_scif_size)
323#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
324 sh4_scif_offset, sh4_scif_size) \
325 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
326#elif defined(CONFIG_CPU_SH7705) || \
327 defined(CONFIG_CPU_SH7720) || \
328 defined(CONFIG_CPU_SH7721) || \
Nobuhiro Iwamatsuc3d6a352012-06-21 13:21:32 +0900329 defined(CONFIG_SH73A0)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900330#define SCIF_FNS(name, scif_offset, scif_size) \
331 CPU_SCIF_FNS(name, scif_offset, scif_size)
Marek Vasut10e91cf2019-05-07 22:31:23 +0200332#elif defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900333#define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
334 sh4_scifb_offset, sh4_scifb_size) \
335 CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
336 sh4_scifb_offset, sh4_scifb_size)
337#define SCIF_FNS(name, scif_offset, scif_size) \
338 CPU_SCIF_FNS(name, scif_offset, scif_size)
339#else
340#define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
341 sh4_sci_offset, sh4_sci_size, \
342 sh3_scif_offset, sh3_scif_size,\
343 sh4_scif_offset, sh4_scif_size, \
344 h8_sci_offset, h8_sci_size) \
345 CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
346 sh3_scif_offset, sh3_scif_size)
347#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
348 sh4_scif_offset, sh4_scif_size) \
349 CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
350#endif
Marek Vasutd13a6142019-05-04 13:31:06 +0200351#elif defined(CONFIG_CPU_SH7723)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900352 #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
353 sh4_scif_offset, sh4_scif_size) \
354 CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
355 sh4_scif_offset, sh4_scif_size)
356 #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \
357 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
358#else
359#define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
360 sh4_sci_offset, sh4_sci_size, \
361 sh3_scif_offset, sh3_scif_size,\
362 sh4_scif_offset, sh4_scif_size, \
363 h8_sci_offset, h8_sci_size) \
364 CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size,\
365 sh4_scif_offset, sh4_scif_size)
366#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, \
367 sh4_scif_offset, sh4_scif_size) \
368 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
369#endif
370
371#if defined(CONFIG_CPU_SH7705) || \
372 defined(CONFIG_CPU_SH7720) || \
373 defined(CONFIG_CPU_SH7721) || \
Nobuhiro Iwamatsuc3d6a352012-06-21 13:21:32 +0900374 defined(CONFIG_SH73A0)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900375
376SCIF_FNS(SCSMR, 0x00, 16)
377SCIF_FNS(SCBRR, 0x04, 8)
378SCIF_FNS(SCSCR, 0x08, 16)
379SCIF_FNS(SCTDSR, 0x0c, 8)
380SCIF_FNS(SCFER, 0x10, 16)
381SCIF_FNS(SCxSR, 0x14, 16)
382SCIF_FNS(SCFCR, 0x18, 16)
383SCIF_FNS(SCFDR, 0x1c, 16)
384SCIF_FNS(SCxTDR, 0x20, 8)
385SCIF_FNS(SCxRDR, 0x24, 8)
386SCIF_FNS(SCLSR, 0x00, 0)
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900387SCIF_FNS(DL, 0x00, 0) /* dummy */
Marek Vasut10e91cf2019-05-07 22:31:23 +0200388#elif defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900389SCIF_FNS(SCSMR, 0x00, 16)
390SCIF_FNS(SCBRR, 0x04, 8)
391SCIF_FNS(SCSCR, 0x08, 16)
392SCIF_FNS(SCTDSR, 0x0c, 16)
393SCIF_FNS(SCFER, 0x10, 16)
394SCIF_FNS(SCxSR, 0x14, 16)
395SCIF_FNS(SCFCR, 0x18, 16)
396SCIF_FNS(SCFDR, 0x1c, 16)
397SCIF_FNS(SCTFDR, 0x38, 16)
398SCIF_FNS(SCRFDR, 0x3c, 16)
399SCIx_FNS(SCxTDR, 0x20, 8, 0x40, 8)
400SCIx_FNS(SCxRDR, 0x24, 8, 0x60, 8)
401SCIF_FNS(SCLSR, 0x00, 0)
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900402SCIF_FNS(DL, 0x00, 0) /* dummy */
Marek Vasutd13a6142019-05-04 13:31:06 +0200403#elif defined(CONFIG_CPU_SH7723)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900404SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16)
405SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8)
406SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16)
407SCIx_FNS(SCxTDR, 0x20, 8, 0x0c, 8)
408SCIx_FNS(SCxSR, 0x14, 16, 0x10, 16)
409SCIx_FNS(SCxRDR, 0x24, 8, 0x14, 8)
410SCIx_FNS(SCSPTR, 0, 0, 0, 0)
411SCIF_FNS(SCTDSR, 0x0c, 8)
412SCIF_FNS(SCFER, 0x10, 16)
413SCIF_FNS(SCFCR, 0x18, 16)
414SCIF_FNS(SCFDR, 0x1c, 16)
415SCIF_FNS(SCLSR, 0x24, 16)
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900416SCIF_FNS(DL, 0x00, 0) /* dummy */
Marek Vasuta6e25b22018-01-22 01:43:25 +0100417#elif defined(CONFIG_RCAR_GEN2)
Vladimir Barinov53be7bf2015-07-20 20:49:39 +0300418/* SCIFA and SCIF register offsets and size */
419SCIx_FNS(SCSMR, 0, 0, 0x00, 16, 0, 0, 0x00, 16, 0, 0)
420SCIx_FNS(SCBRR, 0, 0, 0x04, 8, 0, 0, 0x04, 8, 0, 0)
421SCIx_FNS(SCSCR, 0, 0, 0x08, 16, 0, 0, 0x08, 16, 0, 0)
422SCIx_FNS(SCxTDR, 0, 0, 0x20, 8, 0, 0, 0x0C, 8, 0, 0)
423SCIx_FNS(SCxSR, 0, 0, 0x14, 16, 0, 0, 0x10, 16, 0, 0)
424SCIx_FNS(SCxRDR, 0, 0, 0x24, 8, 0, 0, 0x14, 8, 0, 0)
425SCIF_FNS(SCFCR, 0, 0, 0x18, 16)
426SCIF_FNS(SCFDR, 0, 0, 0x1C, 16)
427SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
428SCIF_FNS(DL, 0, 0, 0x30, 16)
429SCIF_FNS(CKS, 0, 0, 0x34, 16)
430#if defined(CONFIG_SCIF_A)
431SCIF_FNS(SCLSR, 0, 0, 0x14, 16)
432#else
433SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
434#endif
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900435#else
436/* reg SCI/SH3 SCI/SH4 SCIF/SH3 SCIF/SH4 SCI/H8*/
437/* name off sz off sz off sz off sz off sz*/
438SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16, 0x00, 8)
439SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8, 0x01, 8)
440SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16, 0x02, 8)
441SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8, 0x03, 8)
442SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16, 0x04, 8)
443SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
444SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
Marek Vasut10e91cf2019-05-07 22:31:23 +0200445#if defined(CONFIG_CPU_SH7780)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900446SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
447SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
448SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
449SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
450SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
451#elif defined(CONFIG_CPU_SH7763)
452SCIF_FNS(SCFDR, 0, 0, 0x1C, 16)
453SCIF_FNS(SCSPTR2, 0, 0, 0x20, 16)
454SCIF_FNS(SCLSR2, 0, 0, 0x24, 16)
455SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
456SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
457SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
458SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
459#else
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900460
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900461SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
462#if defined(CONFIG_CPU_SH7722)
463SCIF_FNS(SCSPTR, 0, 0, 0, 0)
464#else
465SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
466#endif
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900467SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
468#endif
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900469SCIF_FNS(DL, 0, 0, 0x0, 0) /* dummy */
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900470#endif
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900471#define sci_in(port, reg) sci_##reg##_in(port)
472#define sci_out(port, reg, value) sci_##reg##_out(port, value)
473
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900474#if defined(CONFIG_CPU_SH7706) || \
475 defined(CONFIG_CPU_SH7707) || \
476 defined(CONFIG_CPU_SH7708) || \
477 defined(CONFIG_CPU_SH7709)
478static inline int sci_rxd_in(struct uart_port *port)
479{
480 if (port->mapbase == 0xfffffe80)
481 return __raw_readb(SCPDR)&0x01 ? 1 : 0; /* SCI */
482 return 1;
483}
484#elif defined(CONFIG_CPU_SH7750) || \
485 defined(CONFIG_CPU_SH7751) || \
486 defined(CONFIG_CPU_SH7751R) || \
487 defined(CONFIG_CPU_SH7750R) || \
Marek Vasut10e91cf2019-05-07 22:31:23 +0200488 defined(CONFIG_CPU_SH7750S)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900489static inline int sci_rxd_in(struct uart_port *port)
490{
491 if (port->mapbase == 0xffe00000)
492 return __raw_readb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
493 return 1;
494}
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900495#else /* default case for non-SCI processors */
496static inline int sci_rxd_in(struct uart_port *port)
497{
498 return 1;
499}
500#endif
501
502/*
503 * Values for the BitRate Register (SCBRR)
504 *
505 * The values are actually divisors for a frequency which can
506 * be internal to the SH3 (14.7456MHz) or derived from an external
507 * clock source. This driver assumes the internal clock is used;
508 * to support using an external clock source, config options or
509 * possibly command-line options would need to be added.
510 *
511 * Also, to support speeds below 2400 (why?) the lower 2 bits of
512 * the SCSMR register would also need to be set to non-zero values.
513 *
514 * -- Greg Banks 27Feb2000
515 *
516 * Answer: The SCBRR register is only eight bits, and the value in
517 * it gets larger with lower baud rates. At around 2400 (depending on
518 * the peripherial module clock) you run out of bits. However the
519 * lower two bits of SCSMR allow the module clock to be divided down,
520 * scaling the value which is needed in SCBRR.
521 *
522 * -- Stuart Menefy - 23 May 2000
523 *
524 * I meant, why would anyone bother with bitrates below 2400.
525 *
526 * -- Greg Banks - 7Jul2000
527 *
528 * You "speedist"! How will I use my 110bps ASR-33 teletype with paper
529 * tape reader as a console!
530 *
531 * -- Mitch Davis - 15 Jul 2000
532 */
533
Marek Vasut10e91cf2019-05-07 22:31:23 +0200534#if defined(CONFIG_CPU_SH7780)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900535#define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1)
536#elif defined(CONFIG_CPU_SH7705) || \
537 defined(CONFIG_CPU_SH7720) || \
538 defined(CONFIG_CPU_SH7721) || \
Hideyuki Sanod61678e2012-06-25 10:29:56 +0900539 defined(CONFIG_SH73A0) || \
540 defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900541#define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1)
Marek Vasutd13a6142019-05-04 13:31:06 +0200542#elif defined(CONFIG_CPU_SH7723)
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900543static inline int scbrr_calc(struct uart_port *port, int bps, int clk)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900544{
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900545 if (port->type == PORT_SCIF)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900546 return (clk+16*bps)/(32*bps)-1;
547 else
548 return ((clk*2)+16*bps)/(16*bps)-1;
549}
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900550#define SCBRR_VALUE(bps, clk) scbrr_calc(port, bps, clk)
Marek Vasuta6e25b22018-01-22 01:43:25 +0100551#elif defined(CONFIG_RCAR_GEN2)
Nobuhiro Iwamatsu53022c32014-07-28 15:07:44 +0900552#define DL_VALUE(bps, clk) (clk / bps / 16) /* External Clock */
Vladimir Barinov53be7bf2015-07-20 20:49:39 +0300553 #if defined(CONFIG_SCIF_A)
554 #define SCBRR_VALUE(bps, clk) (clk / bps / 16 - 1) /* Internal Clock */
555 #else
556 #define SCBRR_VALUE(bps, clk) (clk / bps / 32 - 1) /* Internal Clock */
557 #endif
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900558#else /* Generic SH */
559#define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1)
560#endif
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900561
562#ifndef DL_VALUE
563#define DL_VALUE(bps, clk) 0
564#endif