blob: 56472c5419f444d04511e4cfe0178b1792976cd1 [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 Vasut10e91cf2019-05-07 22:31:23 +0200109#elif defined(CONFIG_CPU_SH7203) || \
Phil Edworthy7fbeb642011-06-01 07:35:13 +0100110 defined(CONFIG_CPU_SH7264)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900111# define SCSPTR0 0xfffe8020 /* 16 bit SCIF */
112# define SCSPTR1 0xfffe8820 /* 16 bit SCIF */
113# define SCSPTR2 0xfffe9020 /* 16 bit SCIF */
114# define SCSPTR3 0xfffe9820 /* 16 bit SCIF */
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900115# define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
Marek Vasut67180fe2019-05-01 18:20:00 +0200116#elif defined(CONFIG_CPU_SH7269) || defined(CONFIG_RZA1)
Phil Edworthy99744b72012-05-15 22:15:51 +0000117# define SCSPTR0 0xe8007020 /* 16 bit SCIF */
118# define SCSPTR1 0xe8007820 /* 16 bit SCIF */
119# define SCSPTR2 0xe8008020 /* 16 bit SCIF */
120# define SCSPTR3 0xe8008820 /* 16 bit SCIF */
121# define SCSPTR4 0xe8009020 /* 16 bit SCIF */
122# define SCSPTR5 0xe8009820 /* 16 bit SCIF */
123# define SCSPTR6 0xe800a020 /* 16 bit SCIF */
124# define SCSPTR7 0xe800a820 /* 16 bit SCIF */
125# define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
Marek Vasut67180fe2019-05-01 18:20:00 +0200126# define SCIF_ORER 0x0001 /* overrun error bit */
Chris Brandt8591ac82018-01-16 20:52:18 -0500127#elif defined(CONFIG_RCAR_GEN2) || defined(CONFIG_RCAR_GEN3) || \
128 defined(CONFIG_R7S72100)
Vladimir Barinov53be7bf2015-07-20 20:49:39 +0300129# if defined(CONFIG_SCIF_A)
130# define SCIF_ORER 0x0200
131# else
132# define SCIF_ORER 0x0001
133# endif
Vladimir Barinov2cbb17c2015-02-14 01:05:18 +0300134# define SCSCR_INIT(port) (port->clk_mode == EXT_CLK ? 0x32 : 0x30)
135 /* TIE=0,RIE=0,TE=1,RE=1,REIE=0, */
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900136#else
137# error CPU subtype not defined
138#endif
139
140/* SCSCR */
141#define SCI_CTRL_FLAGS_TIE 0x80 /* all */
142#define SCI_CTRL_FLAGS_RIE 0x40 /* all */
143#define SCI_CTRL_FLAGS_TE 0x20 /* all */
144#define SCI_CTRL_FLAGS_RE 0x10 /* all */
145#if defined(CONFIG_CPU_SH7750) || \
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900146 defined(CONFIG_CPU_SH7750R) || \
147 defined(CONFIG_CPU_SH7722) || \
Nobuhiro Iwamatsu2a57e7e2012-01-11 10:45:01 +0900148 defined(CONFIG_CPU_SH7734) || \
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900149 defined(CONFIG_CPU_SH7750S) || \
150 defined(CONFIG_CPU_SH7751) || \
151 defined(CONFIG_CPU_SH7751R) || \
152 defined(CONFIG_CPU_SH7763) || \
Marek Vasut10e91cf2019-05-07 22:31:23 +0200153 defined(CONFIG_CPU_SH7780)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900154#define SCI_CTRL_FLAGS_REIE 0x08 /* 7750 SCIF */
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900155#else
156#define SCI_CTRL_FLAGS_REIE 0
157#endif
158/* SCI_CTRL_FLAGS_MPIE 0x08 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
159/* SCI_CTRL_FLAGS_TEIE 0x04 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
160/* SCI_CTRL_FLAGS_CKE1 0x02 * all */
161/* SCI_CTRL_FLAGS_CKE0 0x01 * 7707 SCI/SCIF, 7708 SCI, 7709 SCI/SCIF, 7750 SCI */
162
163/* SCxSR SCI */
164#define SCI_TDRE 0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
165#define SCI_RDRF 0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
166#define SCI_ORER 0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
167#define SCI_FER 0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
168#define SCI_PER 0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
169#define SCI_TEND 0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
170/* SCI_MPB 0x02 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
171/* SCI_MPBT 0x01 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
172
173#define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
174
175/* SCxSR SCIF */
176#define SCIF_ER 0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
177#define SCIF_TEND 0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
178#define SCIF_TDFE 0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
179#define SCIF_BRK 0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
180#define SCIF_FER 0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
181#define SCIF_PER 0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
182#define SCIF_RDF 0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
183#define SCIF_DR 0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
184
185#if defined(CONFIG_CPU_SH7705) || \
186 defined(CONFIG_CPU_SH7720) || \
187 defined(CONFIG_CPU_SH7721) || \
Hideyuki Sanod61678e2012-06-25 10:29:56 +0900188 defined(CONFIG_SH73A0) || \
189 defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900190# define SCIF_ORER 0x0200
191# define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
192# define SCIF_RFDC_MASK 0x007f
193# define SCIF_TXROOM_MAX 64
194#elif defined(CONFIG_CPU_SH7763)
195# define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
196# define SCIF_RFDC_MASK 0x007f
197# define SCIF_TXROOM_MAX 64
198/* SH7763 SCIF2 support */
199# define SCIF2_RFDC_MASK 0x001f
200# define SCIF2_TXROOM_MAX 16
Marek Vasuta6e25b22018-01-22 01:43:25 +0100201#elif defined(CONFIG_RCAR_GEN2)
Nobuhiro Iwamatsu48ca8822013-07-23 13:58:20 +0900202# define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
Vladimir Barinov53be7bf2015-07-20 20:49:39 +0300203# if defined(CONFIG_SCIF_A)
204# define SCIF_RFDC_MASK 0x007f
205# else
206# define SCIF_RFDC_MASK 0x001f
207# endif
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900208#else
209# define SCIF_ERRORS (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
210# define SCIF_RFDC_MASK 0x001f
211# define SCIF_TXROOM_MAX 16
212#endif
213
214#ifndef SCIF_ORER
215#define SCIF_ORER 0x0000
216#endif
217
218#define SCxSR_TEND(port)\
219 (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
220#define SCxSR_ERRORS(port)\
221 (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
222#define SCxSR_RDxF(port)\
223 (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
224#define SCxSR_TDxE(port)\
225 (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
226#define SCxSR_FER(port)\
227 (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
228#define SCxSR_PER(port)\
229 (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
230#define SCxSR_BRK(port)\
231 ((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
232#define SCxSR_ORER(port)\
233 (((port)->type == PORT_SCI) ? SCI_ORER : SCIF_ORER)
234
235#if defined(CONFIG_CPU_SH7705) || \
236 defined(CONFIG_CPU_SH7720) || \
237 defined(CONFIG_CPU_SH7721) || \
Hideyuki Sanod61678e2012-06-25 10:29:56 +0900238 defined(CONFIG_SH73A0) || \
239 defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900240# define SCxSR_RDxF_CLEAR(port) (sci_in(port, SCxSR) & 0xfffc)
241# define SCxSR_ERROR_CLEAR(port) (sci_in(port, SCxSR) & 0xfd73)
242# define SCxSR_TDxE_CLEAR(port) (sci_in(port, SCxSR) & 0xffdf)
243# define SCxSR_BREAK_CLEAR(port) (sci_in(port, SCxSR) & 0xffe3)
244#else
245# define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
246# define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
247# define SCxSR_TDxE_CLEAR(port) (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
248# define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
249#endif
250
251/* SCFCR */
252#define SCFCR_RFRST 0x0002
253#define SCFCR_TFRST 0x0004
254#define SCFCR_TCRST 0x4000
255#define SCFCR_MCE 0x0008
256
257#define SCI_MAJOR 204
258#define SCI_MINOR_START 8
259
260/* Generic serial flags */
261#define SCI_RX_THROTTLE 0x0000001
262
263#define SCI_MAGIC 0xbabeface
264
265/*
266 * Events are used to schedule things to happen at timer-interrupt
267 * time, instead of at rs interrupt time.
268 */
269#define SCI_EVENT_WRITE_WAKEUP 0
270
271#define SCI_IN(size, offset)\
272 if ((size) == 8) {\
273 return readb(port->membase + (offset));\
274 } else {\
275 return readw(port->membase + (offset));\
276 }
277#define SCI_OUT(size, offset, value)\
278 if ((size) == 8) {\
279 writeb(value, port->membase + (offset));\
280 } else if ((size) == 16) {\
281 writew(value, port->membase + (offset));\
282 }
283
284#define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
285 static inline unsigned int sci_##name##_in(struct uart_port *port) {\
286 if (port->type == PORT_SCIF || port->type == PORT_SCIFB) {\
287 SCI_IN(scif_size, scif_offset)\
288 } else { /* PORT_SCI or PORT_SCIFA */\
289 SCI_IN(sci_size, sci_offset);\
290 }\
291 }\
292static inline void sci_##name##_out(struct uart_port *port,\
293 unsigned int value) {\
294 if (port->type == PORT_SCIF || port->type == PORT_SCIFB) {\
295 SCI_OUT(scif_size, scif_offset, value)\
296 } else { /* PORT_SCI or PORT_SCIFA */\
297 SCI_OUT(sci_size, sci_offset, value);\
298 }\
299}
300
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900301#define CPU_SCIF_FNS(name, scif_offset, scif_size) \
302 static inline unsigned int sci_##name##_in(struct uart_port *port) {\
303 SCI_IN(scif_size, scif_offset);\
304 }\
305 static inline void sci_##name##_out(struct uart_port *port,\
306 unsigned int value) {\
307 SCI_OUT(scif_size, scif_offset, value);\
308 }
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900309
310#define CPU_SCI_FNS(name, sci_offset, sci_size)\
311 static inline unsigned int sci_##name##_in(struct uart_port *port) {\
312 SCI_IN(sci_size, sci_offset);\
313 }\
314 static inline void sci_##name##_out(struct uart_port *port,\
315 unsigned int value) {\
316 SCI_OUT(sci_size, sci_offset, value);\
317 }
318
Masahiro Yamada7d236662014-11-06 15:55:21 +0900319#if defined(CONFIG_CPU_SH3) || \
Hideyuki Sanod61678e2012-06-25 10:29:56 +0900320 defined(CONFIG_SH73A0) || \
321 defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900322#if defined(CONFIG_CPU_SH7710) || defined(CONFIG_CPU_SH7712)
323#define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
324 sh4_sci_offset, sh4_sci_size, \
325 sh3_scif_offset, sh3_scif_size, \
326 sh4_scif_offset, sh4_scif_size, \
327 h8_sci_offset, h8_sci_size) \
328 CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size,\
329 sh4_scif_offset, sh4_scif_size)
330#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
331 sh4_scif_offset, sh4_scif_size) \
332 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
333#elif defined(CONFIG_CPU_SH7705) || \
334 defined(CONFIG_CPU_SH7720) || \
335 defined(CONFIG_CPU_SH7721) || \
Nobuhiro Iwamatsuc3d6a352012-06-21 13:21:32 +0900336 defined(CONFIG_SH73A0)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900337#define SCIF_FNS(name, scif_offset, scif_size) \
338 CPU_SCIF_FNS(name, scif_offset, scif_size)
Marek Vasut10e91cf2019-05-07 22:31:23 +0200339#elif defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900340#define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
341 sh4_scifb_offset, sh4_scifb_size) \
342 CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
343 sh4_scifb_offset, sh4_scifb_size)
344#define SCIF_FNS(name, scif_offset, scif_size) \
345 CPU_SCIF_FNS(name, scif_offset, scif_size)
346#else
347#define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
348 sh4_sci_offset, sh4_sci_size, \
349 sh3_scif_offset, sh3_scif_size,\
350 sh4_scif_offset, sh4_scif_size, \
351 h8_sci_offset, h8_sci_size) \
352 CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
353 sh3_scif_offset, sh3_scif_size)
354#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size,\
355 sh4_scif_offset, sh4_scif_size) \
356 CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
357#endif
Marek Vasutd13a6142019-05-04 13:31:06 +0200358#elif defined(CONFIG_CPU_SH7723)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900359 #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
360 sh4_scif_offset, sh4_scif_size) \
361 CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size,\
362 sh4_scif_offset, sh4_scif_size)
363 #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \
364 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
365#else
366#define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size,\
367 sh4_sci_offset, sh4_sci_size, \
368 sh3_scif_offset, sh3_scif_size,\
369 sh4_scif_offset, sh4_scif_size, \
370 h8_sci_offset, h8_sci_size) \
371 CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size,\
372 sh4_scif_offset, sh4_scif_size)
373#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, \
374 sh4_scif_offset, sh4_scif_size) \
375 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
376#endif
377
378#if defined(CONFIG_CPU_SH7705) || \
379 defined(CONFIG_CPU_SH7720) || \
380 defined(CONFIG_CPU_SH7721) || \
Nobuhiro Iwamatsuc3d6a352012-06-21 13:21:32 +0900381 defined(CONFIG_SH73A0)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900382
383SCIF_FNS(SCSMR, 0x00, 16)
384SCIF_FNS(SCBRR, 0x04, 8)
385SCIF_FNS(SCSCR, 0x08, 16)
386SCIF_FNS(SCTDSR, 0x0c, 8)
387SCIF_FNS(SCFER, 0x10, 16)
388SCIF_FNS(SCxSR, 0x14, 16)
389SCIF_FNS(SCFCR, 0x18, 16)
390SCIF_FNS(SCFDR, 0x1c, 16)
391SCIF_FNS(SCxTDR, 0x20, 8)
392SCIF_FNS(SCxRDR, 0x24, 8)
393SCIF_FNS(SCLSR, 0x00, 0)
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900394SCIF_FNS(DL, 0x00, 0) /* dummy */
Marek Vasut10e91cf2019-05-07 22:31:23 +0200395#elif defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900396SCIF_FNS(SCSMR, 0x00, 16)
397SCIF_FNS(SCBRR, 0x04, 8)
398SCIF_FNS(SCSCR, 0x08, 16)
399SCIF_FNS(SCTDSR, 0x0c, 16)
400SCIF_FNS(SCFER, 0x10, 16)
401SCIF_FNS(SCxSR, 0x14, 16)
402SCIF_FNS(SCFCR, 0x18, 16)
403SCIF_FNS(SCFDR, 0x1c, 16)
404SCIF_FNS(SCTFDR, 0x38, 16)
405SCIF_FNS(SCRFDR, 0x3c, 16)
406SCIx_FNS(SCxTDR, 0x20, 8, 0x40, 8)
407SCIx_FNS(SCxRDR, 0x24, 8, 0x60, 8)
408SCIF_FNS(SCLSR, 0x00, 0)
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900409SCIF_FNS(DL, 0x00, 0) /* dummy */
Marek Vasutd13a6142019-05-04 13:31:06 +0200410#elif defined(CONFIG_CPU_SH7723)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900411SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16)
412SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8)
413SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16)
414SCIx_FNS(SCxTDR, 0x20, 8, 0x0c, 8)
415SCIx_FNS(SCxSR, 0x14, 16, 0x10, 16)
416SCIx_FNS(SCxRDR, 0x24, 8, 0x14, 8)
417SCIx_FNS(SCSPTR, 0, 0, 0, 0)
418SCIF_FNS(SCTDSR, 0x0c, 8)
419SCIF_FNS(SCFER, 0x10, 16)
420SCIF_FNS(SCFCR, 0x18, 16)
421SCIF_FNS(SCFDR, 0x1c, 16)
422SCIF_FNS(SCLSR, 0x24, 16)
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900423SCIF_FNS(DL, 0x00, 0) /* dummy */
Marek Vasuta6e25b22018-01-22 01:43:25 +0100424#elif defined(CONFIG_RCAR_GEN2)
Vladimir Barinov53be7bf2015-07-20 20:49:39 +0300425/* SCIFA and SCIF register offsets and size */
426SCIx_FNS(SCSMR, 0, 0, 0x00, 16, 0, 0, 0x00, 16, 0, 0)
427SCIx_FNS(SCBRR, 0, 0, 0x04, 8, 0, 0, 0x04, 8, 0, 0)
428SCIx_FNS(SCSCR, 0, 0, 0x08, 16, 0, 0, 0x08, 16, 0, 0)
429SCIx_FNS(SCxTDR, 0, 0, 0x20, 8, 0, 0, 0x0C, 8, 0, 0)
430SCIx_FNS(SCxSR, 0, 0, 0x14, 16, 0, 0, 0x10, 16, 0, 0)
431SCIx_FNS(SCxRDR, 0, 0, 0x24, 8, 0, 0, 0x14, 8, 0, 0)
432SCIF_FNS(SCFCR, 0, 0, 0x18, 16)
433SCIF_FNS(SCFDR, 0, 0, 0x1C, 16)
434SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
435SCIF_FNS(DL, 0, 0, 0x30, 16)
436SCIF_FNS(CKS, 0, 0, 0x34, 16)
437#if defined(CONFIG_SCIF_A)
438SCIF_FNS(SCLSR, 0, 0, 0x14, 16)
439#else
440SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
441#endif
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900442#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*/
445SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16, 0x00, 8)
446SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8, 0x01, 8)
447SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16, 0x02, 8)
448SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8, 0x03, 8)
449SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16, 0x04, 8)
450SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
451SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
Marek Vasut10e91cf2019-05-07 22:31:23 +0200452#if defined(CONFIG_CPU_SH7780)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900453SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
454SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
455SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
456SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
457SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
458#elif defined(CONFIG_CPU_SH7763)
459SCIF_FNS(SCFDR, 0, 0, 0x1C, 16)
460SCIF_FNS(SCSPTR2, 0, 0, 0x20, 16)
461SCIF_FNS(SCLSR2, 0, 0, 0x24, 16)
462SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
463SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
464SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
465SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
466#else
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900467
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900468SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
469#if defined(CONFIG_CPU_SH7722)
470SCIF_FNS(SCSPTR, 0, 0, 0, 0)
471#else
472SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
473#endif
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900474SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
475#endif
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900476SCIF_FNS(DL, 0, 0, 0x0, 0) /* dummy */
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900477#endif
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900478#define sci_in(port, reg) sci_##reg##_in(port)
479#define sci_out(port, reg, value) sci_##reg##_out(port, value)
480
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900481#if defined(CONFIG_CPU_SH7706) || \
482 defined(CONFIG_CPU_SH7707) || \
483 defined(CONFIG_CPU_SH7708) || \
484 defined(CONFIG_CPU_SH7709)
485static inline int sci_rxd_in(struct uart_port *port)
486{
487 if (port->mapbase == 0xfffffe80)
488 return __raw_readb(SCPDR)&0x01 ? 1 : 0; /* SCI */
489 return 1;
490}
491#elif defined(CONFIG_CPU_SH7750) || \
492 defined(CONFIG_CPU_SH7751) || \
493 defined(CONFIG_CPU_SH7751R) || \
494 defined(CONFIG_CPU_SH7750R) || \
Marek Vasut10e91cf2019-05-07 22:31:23 +0200495 defined(CONFIG_CPU_SH7750S)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900496static inline int sci_rxd_in(struct uart_port *port)
497{
498 if (port->mapbase == 0xffe00000)
499 return __raw_readb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
500 return 1;
501}
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900502#else /* default case for non-SCI processors */
503static inline int sci_rxd_in(struct uart_port *port)
504{
505 return 1;
506}
507#endif
508
509/*
510 * Values for the BitRate Register (SCBRR)
511 *
512 * The values are actually divisors for a frequency which can
513 * be internal to the SH3 (14.7456MHz) or derived from an external
514 * clock source. This driver assumes the internal clock is used;
515 * to support using an external clock source, config options or
516 * possibly command-line options would need to be added.
517 *
518 * Also, to support speeds below 2400 (why?) the lower 2 bits of
519 * the SCSMR register would also need to be set to non-zero values.
520 *
521 * -- Greg Banks 27Feb2000
522 *
523 * Answer: The SCBRR register is only eight bits, and the value in
524 * it gets larger with lower baud rates. At around 2400 (depending on
525 * the peripherial module clock) you run out of bits. However the
526 * lower two bits of SCSMR allow the module clock to be divided down,
527 * scaling the value which is needed in SCBRR.
528 *
529 * -- Stuart Menefy - 23 May 2000
530 *
531 * I meant, why would anyone bother with bitrates below 2400.
532 *
533 * -- Greg Banks - 7Jul2000
534 *
535 * You "speedist"! How will I use my 110bps ASR-33 teletype with paper
536 * tape reader as a console!
537 *
538 * -- Mitch Davis - 15 Jul 2000
539 */
540
Marek Vasut10e91cf2019-05-07 22:31:23 +0200541#if defined(CONFIG_CPU_SH7780)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900542#define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1)
543#elif defined(CONFIG_CPU_SH7705) || \
544 defined(CONFIG_CPU_SH7720) || \
545 defined(CONFIG_CPU_SH7721) || \
Hideyuki Sanod61678e2012-06-25 10:29:56 +0900546 defined(CONFIG_SH73A0) || \
547 defined(CONFIG_R8A7740)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900548#define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1)
Marek Vasutd13a6142019-05-04 13:31:06 +0200549#elif defined(CONFIG_CPU_SH7723)
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900550static inline int scbrr_calc(struct uart_port *port, int bps, int clk)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900551{
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900552 if (port->type == PORT_SCIF)
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900553 return (clk+16*bps)/(32*bps)-1;
554 else
555 return ((clk*2)+16*bps)/(16*bps)-1;
556}
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900557#define SCBRR_VALUE(bps, clk) scbrr_calc(port, bps, clk)
Marek Vasuta6e25b22018-01-22 01:43:25 +0100558#elif defined(CONFIG_RCAR_GEN2)
Nobuhiro Iwamatsu53022c32014-07-28 15:07:44 +0900559#define DL_VALUE(bps, clk) (clk / bps / 16) /* External Clock */
Vladimir Barinov53be7bf2015-07-20 20:49:39 +0300560 #if defined(CONFIG_SCIF_A)
561 #define SCBRR_VALUE(bps, clk) (clk / bps / 16 - 1) /* Internal Clock */
562 #else
563 #define SCBRR_VALUE(bps, clk) (clk / bps / 32 - 1) /* Internal Clock */
564 #endif
Nobuhiro Iwamatsu3f6c8e32010-10-26 03:55:15 +0900565#else /* Generic SH */
566#define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1)
567#endif
Nobuhiro Iwamatsu59088e42015-02-12 13:48:04 +0900568
569#ifndef DL_VALUE
570#define DL_VALUE(bps, clk) 0
571#endif