blob: 57aaa09811eadf88564448b4285072dbe25a3bc6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: sh-sci.h,v 1.4 2004/02/19 16:43:56 lethal Exp $
2 *
3 * linux/drivers/serial/sh-sci.h
4 *
5 * SuperH on-chip serial module support. (SCI with no FIFO / with FIFO)
6 * Copyright (C) 1999, 2000 Niibe Yutaka
7 * Copyright (C) 2000 Greg Banks
8 * Copyright (C) 2002, 2003 Paul Mundt
9 * Modified to support multiple serial ports. Stuart Menefy (May 2000).
10 * Modified to support SH7300(SH-Mobile) SCIF. Takashi Kusuda (Jun 2003).
11 * Modified to support H8/300 Series Yoshinori Sato (Feb 2004).
Magnus Dammd89ddd12007-07-25 11:42:56 +090012 * Removed SH7300 support (Jul 2007).
Markus Brunner3ea6bc32007-08-20 08:59:33 +090013 * Modified to support SH7720 SCIF. Markus Brunner, Mark Jonas (Aug 2007).
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/serial_core.h>
Paul Mundte108b2c2006-09-27 16:32:13 +090016#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/gpio.h>
Markus Brunner3ea6bc32007-08-20 08:59:33 +090019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#if defined(CONFIG_H83007) || defined(CONFIG_H83068)
21#include <asm/regs306x.h>
22#endif
23#if defined(CONFIG_H8S2678)
24#include <asm/regs267x.h>
25#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Magnus Damm0fbde952007-07-26 10:14:16 +090027#if defined(CONFIG_CPU_SUBTYPE_SH7706) || \
28 defined(CONFIG_CPU_SUBTYPE_SH7707) || \
29 defined(CONFIG_CPU_SUBTYPE_SH7708) || \
30 defined(CONFIG_CPU_SUBTYPE_SH7709)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031# define SCPCR 0xA4000116 /* 16 bit SCI and SCIF */
32# define SCPDR 0xA4000136 /* 8 bit SCI and SCIF */
33# define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
34# define SCI_AND_SCIF
35#elif defined(CONFIG_CPU_SUBTYPE_SH7705)
36# define SCIF0 0xA4400000
37# define SCIF2 0xA4410000
Paul Mundtb7a76e42006-02-01 03:06:06 -080038# define SCSMR_Ir 0xA44A0000
39# define IRDA_SCIF SCIF0
Linus Torvalds1da177e2005-04-16 15:20:36 -070040# define SCPCR 0xA4000116
41# define SCPDR 0xA4000136
42
43/* Set the clock source,
44 * SCIF2 (0xA4410000) -> External clock, SCK pin used as clock input
45 * SCIF0 (0xA4400000) -> Internal clock, SCK pin as serial clock output
46 */
47# define SCSCR_INIT(port) (port->mapbase == SCIF2) ? 0xF3 : 0xF0
48# define SCIF_ONLY
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +090049#elif defined(CONFIG_CPU_SUBTYPE_SH7720) || \
50 defined(CONFIG_CPU_SUBTYPE_SH7721)
Markus Brunner3ea6bc32007-08-20 08:59:33 +090051# define SCSCR_INIT(port) 0x0030 /* TIE=0,RIE=0,TE=1,RE=1 */
52# define SCIF_ONLY
53#define SCIF_ORER 0x0200 /* overrun error bit */
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#elif defined(CONFIG_SH_RTS7751R2D)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055# define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
56# define SCIF_ORER 0x0001 /* overrun error bit */
57# define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
58# define SCIF_ONLY
Paul Mundt05627482007-05-15 16:25:47 +090059#elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
60 defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
61 defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
62 defined(CONFIG_CPU_SUBTYPE_SH7091) || \
63 defined(CONFIG_CPU_SUBTYPE_SH7751) || \
64 defined(CONFIG_CPU_SUBTYPE_SH7751R)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065# define SCSPTR1 0xffe0001c /* 8 bit SCI */
66# define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
67# define SCIF_ORER 0x0001 /* overrun error bit */
68# define SCSCR_INIT(port) (((port)->type == PORT_SCI) ? \
69 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */ : \
70 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */ )
71# define SCI_AND_SCIF
72#elif defined(CONFIG_CPU_SUBTYPE_SH7760)
Paul Mundtb7a76e42006-02-01 03:06:06 -080073# define SCSPTR0 0xfe600024 /* 16 bit SCIF */
74# define SCSPTR1 0xfe610024 /* 16 bit SCIF */
75# define SCSPTR2 0xfe620024 /* 16 bit SCIF */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076# define SCIF_ORER 0x0001 /* overrun error bit */
77# define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
78# define SCIF_ONLY
Paul Mundt2b1bd1a2007-06-20 18:27:10 +090079#elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
Paul Mundte108b2c2006-09-27 16:32:13 +090080# define SCSPTR0 0xA4400000 /* 16 bit SCIF */
Nobuhiro Iwamatsu9465a542007-03-27 18:13:51 +090081# define SCIF_ORER 0x0001 /* overrun error bit */
82# define PACR 0xa4050100
83# define PBCR 0xa4050102
84# define SCSCR_INIT(port) 0x3B
Paul Mundte108b2c2006-09-27 16:32:13 +090085# define SCIF_ONLY
Paul Mundte108b2c2006-09-27 16:32:13 +090086#elif defined(CONFIG_CPU_SUBTYPE_SH7343)
87# define SCSPTR0 0xffe00010 /* 16 bit SCIF */
88# define SCSPTR1 0xffe10010 /* 16 bit SCIF */
89# define SCSPTR2 0xffe20010 /* 16 bit SCIF */
90# define SCSPTR3 0xffe30010 /* 16 bit SCIF */
91# define SCSCR_INIT(port) 0x32 /* TIE=0,RIE=0,TE=1,RE=1,REIE=0,CKE=1 */
92# define SCIF_ONLY
Paul Mundt41504c32006-12-11 20:28:03 +090093#elif defined(CONFIG_CPU_SUBTYPE_SH7722)
94# define SCPDR0 0xA405013E /* 16 bit SCIF0 PSDR */
95# define SCSPTR0 SCPDR0
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# define SCIF_ONLY
99# define PORT_PSCR 0xA405011E
Magnus Damm9109a302008-02-08 17:31:24 +0900100#elif defined(CONFIG_CPU_SUBTYPE_SH7366)
101# define SCPDR0 0xA405013E /* 16 bit SCIF0 PSDR */
102# define SCSPTR0 SCPDR0
103# define SCIF_ORER 0x0001 /* overrun error bit */
104# define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
105# define SCIF_ONLY
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107# define SCSPTR2 0xffe80020 /* 16 bit SCIF */
108# define SCIF_ORER 0x0001 /* overrun error bit */
109# define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
110# define SCIF_ONLY
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
112# include <asm/hardware.h>
113# define SCIF_BASE_ADDR 0x01030000
114# define SCIF_ADDR_SH5 PHYS_PERIPHERAL_BLOCK+SCIF_BASE_ADDR
115# define SCIF_PTR2_OFFS 0x0000020
116# define SCIF_LSR2_OFFS 0x0000024
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117# define SCSPTR2 ((port->mapbase)+SCIF_PTR2_OFFS) /* 16 bit SCIF */
118# define SCLSR2 ((port->mapbase)+SCIF_LSR2_OFFS) /* 16 bit SCIF */
Paul Mundtf9669182007-11-07 11:05:32 +0900119# define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0, TE=1,RE=1,REIE=1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120# define SCIF_ONLY
121#elif defined(CONFIG_H83007) || defined(CONFIG_H83068)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122# define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
123# define SCI_ONLY
124# define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
125#elif defined(CONFIG_H8S2678)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126# define SCSCR_INIT(port) 0x30 /* TIE=0,RIE=0,TE=1,RE=1 */
127# define SCI_ONLY
128# define H8300_SCI_DR(ch) *(volatile char *)(P1DR + h8300_sci_pins[ch].port)
Yoshihiro Shimoda7d740a02008-01-07 14:40:07 +0900129#elif defined(CONFIG_CPU_SUBTYPE_SH7763)
130# define SCSPTR0 0xffe00024 /* 16 bit SCIF */
131# define SCSPTR1 0xffe08024 /* 16 bit SCIF */
132# define SCIF_ORER 0x0001 /* overrun error bit */
133# define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
134# define SCIF_ONLY
Paul Mundtb7a76e42006-02-01 03:06:06 -0800135#elif defined(CONFIG_CPU_SUBTYPE_SH7770)
136# define SCSPTR0 0xff923020 /* 16 bit SCIF */
137# define SCSPTR1 0xff924020 /* 16 bit SCIF */
138# define SCSPTR2 0xff925020 /* 16 bit SCIF */
139# define SCIF_ORER 0x0001 /* overrun error bit */
140# define SCSCR_INIT(port) 0x3c /* TIE=0,RIE=0,TE=1,RE=1,REIE=1,cke=2 */
141# define SCIF_ONLY
142#elif defined(CONFIG_CPU_SUBTYPE_SH7780)
143# define SCSPTR0 0xffe00024 /* 16 bit SCIF */
144# define SCSPTR1 0xffe10024 /* 16 bit SCIF */
Paul Mundte108b2c2006-09-27 16:32:13 +0900145# define SCIF_ORER 0x0001 /* Overrun error bit */
Paul Mundtb7a76e42006-02-01 03:06:06 -0800146# define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
147# define SCIF_ONLY
Paul Mundt32351a22007-03-12 14:38:59 +0900148#elif defined(CONFIG_CPU_SUBTYPE_SH7785)
149# define SCSPTR0 0xffea0024 /* 16 bit SCIF */
150# define SCSPTR1 0xffeb0024 /* 16 bit SCIF */
151# define SCSPTR2 0xffec0024 /* 16 bit SCIF */
152# define SCSPTR3 0xffed0024 /* 16 bit SCIF */
153# define SCSPTR4 0xffee0024 /* 16 bit SCIF */
154# define SCSPTR5 0xffef0024 /* 16 bit SCIF */
155# define SCIF_OPER 0x0001 /* Overrun error bit */
156# define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
157# define SCIF_ONLY
Paul Mundt6d01f512007-11-26 18:17:21 +0900158#elif defined(CONFIG_CPU_SUBTYPE_SH7203) || \
Paul Mundta8f67f42007-11-26 19:54:02 +0900159 defined(CONFIG_CPU_SUBTYPE_SH7206) || \
160 defined(CONFIG_CPU_SUBTYPE_SH7263)
Yoshinori Sato9d4436a2006-11-05 15:40:13 +0900161# define SCSPTR0 0xfffe8020 /* 16 bit SCIF */
162# define SCSPTR1 0xfffe8820 /* 16 bit SCIF */
163# define SCSPTR2 0xfffe9020 /* 16 bit SCIF */
164# define SCSPTR3 0xfffe9820 /* 16 bit SCIF */
165# define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
166# define SCIF_ONLY
167#elif defined(CONFIG_CPU_SUBTYPE_SH7619)
168# define SCSPTR0 0xf8400020 /* 16 bit SCIF */
169# define SCSPTR1 0xf8410020 /* 16 bit SCIF */
170# define SCSPTR2 0xf8420020 /* 16 bit SCIF */
171# define SCIF_ORER 0x0001 /* overrun error bit */
172# define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
173# define SCIF_ONLY
Paul Mundt2b1bd1a2007-06-20 18:27:10 +0900174#elif defined(CONFIG_CPU_SUBTYPE_SHX3)
175# define SCSPTR0 0xffc30020 /* 16 bit SCIF */
176# define SCSPTR1 0xffc40020 /* 16 bit SCIF */
177# define SCSPTR2 0xffc50020 /* 16 bit SCIF */
178# define SCSPTR3 0xffc60020 /* 16 bit SCIF */
179# define SCIF_ORER 0x0001 /* Overrun error bit */
180# define SCSCR_INIT(port) 0x38 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
181# define SCIF_ONLY
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#else
183# error CPU subtype not defined
184#endif
185
186/* SCSCR */
187#define SCI_CTRL_FLAGS_TIE 0x80 /* all */
188#define SCI_CTRL_FLAGS_RIE 0x40 /* all */
189#define SCI_CTRL_FLAGS_TE 0x20 /* all */
190#define SCI_CTRL_FLAGS_RE 0x10 /* all */
Paul Mundt05627482007-05-15 16:25:47 +0900191#if defined(CONFIG_CPU_SUBTYPE_SH7750) || \
192 defined(CONFIG_CPU_SUBTYPE_SH7091) || \
193 defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
194 defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
195 defined(CONFIG_CPU_SUBTYPE_SH7751) || \
196 defined(CONFIG_CPU_SUBTYPE_SH7751R) || \
197 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
Paul Mundt2b1bd1a2007-06-20 18:27:10 +0900198 defined(CONFIG_CPU_SUBTYPE_SH7785) || \
199 defined(CONFIG_CPU_SUBTYPE_SHX3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#define SCI_CTRL_FLAGS_REIE 0x08 /* 7750 SCIF */
201#else
202#define SCI_CTRL_FLAGS_REIE 0
203#endif
204/* SCI_CTRL_FLAGS_MPIE 0x08 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
205/* SCI_CTRL_FLAGS_TEIE 0x04 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
206/* SCI_CTRL_FLAGS_CKE1 0x02 * all */
207/* SCI_CTRL_FLAGS_CKE0 0x01 * 7707 SCI/SCIF, 7708 SCI, 7709 SCI/SCIF, 7750 SCI */
208
209/* SCxSR SCI */
210#define SCI_TDRE 0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
211#define SCI_RDRF 0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
212#define SCI_ORER 0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
213#define SCI_FER 0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
214#define SCI_PER 0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
215#define SCI_TEND 0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
216/* SCI_MPB 0x02 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
217/* SCI_MPBT 0x01 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
218
219#define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
220
221/* SCxSR SCIF */
222#define SCIF_ER 0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
223#define SCIF_TEND 0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
224#define SCIF_TDFE 0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
225#define SCIF_BRK 0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
226#define SCIF_FER 0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
227#define SCIF_PER 0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
228#define SCIF_RDF 0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
229#define SCIF_DR 0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
230
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900231#if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +0900232 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
233 defined(CONFIG_CPU_SUBTYPE_SH7721)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234#define SCIF_ORER 0x0200
235#define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
236#define SCIF_RFDC_MASK 0x007f
237#define SCIF_TXROOM_MAX 64
238#else
239#define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
240#define SCIF_RFDC_MASK 0x001f
241#define SCIF_TXROOM_MAX 16
242#endif
243
244#if defined(SCI_ONLY)
245# define SCxSR_TEND(port) SCI_TEND
246# define SCxSR_ERRORS(port) SCI_ERRORS
247# define SCxSR_RDxF(port) SCI_RDRF
248# define SCxSR_TDxE(port) SCI_TDRE
249# define SCxSR_ORER(port) SCI_ORER
250# define SCxSR_FER(port) SCI_FER
251# define SCxSR_PER(port) SCI_PER
252# define SCxSR_BRK(port) 0x00
253# define SCxSR_RDxF_CLEAR(port) 0xbc
254# define SCxSR_ERROR_CLEAR(port) 0xc4
255# define SCxSR_TDxE_CLEAR(port) 0x78
Paul Mundtb7a76e42006-02-01 03:06:06 -0800256# define SCxSR_BREAK_CLEAR(port) 0xc4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#elif defined(SCIF_ONLY)
258# define SCxSR_TEND(port) SCIF_TEND
259# define SCxSR_ERRORS(port) SCIF_ERRORS
260# define SCxSR_RDxF(port) SCIF_RDF
261# define SCxSR_TDxE(port) SCIF_TDFE
Magnus Dammd89ddd12007-07-25 11:42:56 +0900262#if defined(CONFIG_CPU_SUBTYPE_SH7705)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263# define SCxSR_ORER(port) SCIF_ORER
264#else
265# define SCxSR_ORER(port) 0x0000
266#endif
267# define SCxSR_FER(port) SCIF_FER
268# define SCxSR_PER(port) SCIF_PER
269# define SCxSR_BRK(port) SCIF_BRK
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900270#if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +0900271 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
272 defined(CONFIG_CPU_SUBTYPE_SH7721)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273# define SCxSR_RDxF_CLEAR(port) (sci_in(port,SCxSR)&0xfffc)
274# define SCxSR_ERROR_CLEAR(port) (sci_in(port,SCxSR)&0xfd73)
275# define SCxSR_TDxE_CLEAR(port) (sci_in(port,SCxSR)&0xffdf)
276# define SCxSR_BREAK_CLEAR(port) (sci_in(port,SCxSR)&0xffe3)
277#else
Magnus Dammd89ddd12007-07-25 11:42:56 +0900278/* SH7705 can also use this, clearing is same between 7705 and 7709 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279# define SCxSR_RDxF_CLEAR(port) 0x00fc
280# define SCxSR_ERROR_CLEAR(port) 0x0073
281# define SCxSR_TDxE_CLEAR(port) 0x00df
Paul Mundtb7a76e42006-02-01 03:06:06 -0800282# define SCxSR_BREAK_CLEAR(port) 0x00e3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283#endif
284#else
285# define SCxSR_TEND(port) (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
286# define SCxSR_ERRORS(port) (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
287# define SCxSR_RDxF(port) (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
288# define SCxSR_TDxE(port) (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
289# define SCxSR_ORER(port) (((port)->type == PORT_SCI) ? SCI_ORER : 0x0000)
290# define SCxSR_FER(port) (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
291# define SCxSR_PER(port) (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
292# define SCxSR_BRK(port) (((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
293# define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
294# define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
295# define SCxSR_TDxE_CLEAR(port) (((port)->type == PORT_SCI) ? 0x78 : 0x00df)
296# define SCxSR_BREAK_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x00e3)
297#endif
298
299/* SCFCR */
300#define SCFCR_RFRST 0x0002
301#define SCFCR_TFRST 0x0004
302#define SCFCR_TCRST 0x4000
303#define SCFCR_MCE 0x0008
304
305#define SCI_MAJOR 204
306#define SCI_MINOR_START 8
307
308/* Generic serial flags */
309#define SCI_RX_THROTTLE 0x0000001
310
311#define SCI_MAGIC 0xbabeface
312
313/*
314 * Events are used to schedule things to happen at timer-interrupt
315 * time, instead of at rs interrupt time.
316 */
317#define SCI_EVENT_WRITE_WAKEUP 0
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#define SCI_IN(size, offset) \
320 unsigned int addr = port->mapbase + (offset); \
Paul Mundtb7a76e42006-02-01 03:06:06 -0800321 if ((size) == 8) { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 return ctrl_inb(addr); \
Paul Mundtb7a76e42006-02-01 03:06:06 -0800323 } else { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 return ctrl_inw(addr); \
325 }
326#define SCI_OUT(size, offset, value) \
327 unsigned int addr = port->mapbase + (offset); \
Paul Mundtb7a76e42006-02-01 03:06:06 -0800328 if ((size) == 8) { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 ctrl_outb(value, addr); \
330 } else { \
331 ctrl_outw(value, addr); \
332 }
333
334#define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
335 static inline unsigned int sci_##name##_in(struct uart_port *port) \
336 { \
Paul Mundtb7a76e42006-02-01 03:06:06 -0800337 if (port->type == PORT_SCI) { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 SCI_IN(sci_size, sci_offset) \
339 } else { \
Paul Mundtb7a76e42006-02-01 03:06:06 -0800340 SCI_IN(scif_size, scif_offset); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 } \
342 } \
343 static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
344 { \
345 if (port->type == PORT_SCI) { \
346 SCI_OUT(sci_size, sci_offset, value) \
347 } else { \
348 SCI_OUT(scif_size, scif_offset, value); \
349 } \
350 }
351
352#define CPU_SCIF_FNS(name, scif_offset, scif_size) \
353 static inline unsigned int sci_##name##_in(struct uart_port *port) \
354 { \
Paul Mundtb7a76e42006-02-01 03:06:06 -0800355 SCI_IN(scif_size, scif_offset); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 } \
357 static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
358 { \
359 SCI_OUT(scif_size, scif_offset, value); \
360 }
361
362#define CPU_SCI_FNS(name, sci_offset, sci_size) \
363 static inline unsigned int sci_##name##_in(struct uart_port* port) \
364 { \
Paul Mundtb7a76e42006-02-01 03:06:06 -0800365 SCI_IN(sci_size, sci_offset); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 } \
367 static inline void sci_##name##_out(struct uart_port* port, unsigned int value) \
368 { \
369 SCI_OUT(sci_size, sci_offset, value); \
370 }
371
372#ifdef CONFIG_CPU_SH3
Nobuhiro Iwamatsu9465a542007-03-27 18:13:51 +0900373#if defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
374#define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
375 sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
376 h8_sci_offset, h8_sci_size) \
377 CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
378#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
379 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900380#elif defined(CONFIG_CPU_SUBTYPE_SH7705) || \
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +0900381 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
382 defined(CONFIG_CPU_SUBTYPE_SH7721)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#define SCIF_FNS(name, scif_offset, scif_size) \
384 CPU_SCIF_FNS(name, scif_offset, scif_size)
385#else
386#define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
387 sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
388 h8_sci_offset, h8_sci_size) \
389 CPU_SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh3_scif_offset, sh3_scif_size)
390#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
391 CPU_SCIF_FNS(name, sh3_scif_offset, sh3_scif_size)
392#endif
393#elif defined(__H8300H__) || defined(__H8300S__)
394#define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
395 sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
396 h8_sci_offset, h8_sci_size) \
397 CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size)
398#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size)
399#else
400#define SCIx_FNS(name, sh3_sci_offset, sh3_sci_size, sh4_sci_offset, sh4_sci_size, \
401 sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
402 h8_sci_offset, h8_sci_size) \
403 CPU_SCIx_FNS(name, sh4_sci_offset, sh4_sci_size, sh4_scif_offset, sh4_scif_size)
404#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
405 CPU_SCIF_FNS(name, sh4_scif_offset, sh4_scif_size)
406#endif
407
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900408#if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +0900409 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
410 defined(CONFIG_CPU_SUBTYPE_SH7721)
Nobuhiro Iwamatsu9465a542007-03-27 18:13:51 +0900411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412SCIF_FNS(SCSMR, 0x00, 16)
413SCIF_FNS(SCBRR, 0x04, 8)
414SCIF_FNS(SCSCR, 0x08, 16)
415SCIF_FNS(SCTDSR, 0x0c, 8)
416SCIF_FNS(SCFER, 0x10, 16)
417SCIF_FNS(SCxSR, 0x14, 16)
418SCIF_FNS(SCFCR, 0x18, 16)
419SCIF_FNS(SCFDR, 0x1c, 16)
420SCIF_FNS(SCxTDR, 0x20, 8)
421SCIF_FNS(SCxRDR, 0x24, 8)
422SCIF_FNS(SCLSR, 0x24, 16)
423#else
424/* reg SCI/SH3 SCI/SH4 SCIF/SH3 SCIF/SH4 SCI/H8*/
425/* name off sz off sz off sz off sz off sz*/
426SCIx_FNS(SCSMR, 0x00, 8, 0x00, 8, 0x00, 8, 0x00, 16, 0x00, 8)
427SCIx_FNS(SCBRR, 0x02, 8, 0x04, 8, 0x02, 8, 0x04, 8, 0x01, 8)
428SCIx_FNS(SCSCR, 0x04, 8, 0x08, 8, 0x04, 8, 0x08, 16, 0x02, 8)
429SCIx_FNS(SCxTDR, 0x06, 8, 0x0c, 8, 0x06, 8, 0x0C, 8, 0x03, 8)
430SCIx_FNS(SCxSR, 0x08, 8, 0x10, 8, 0x08, 16, 0x10, 16, 0x04, 8)
431SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
432SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
Paul Mundt32351a22007-03-12 14:38:59 +0900433#if defined(CONFIG_CPU_SUBTYPE_SH7760) || \
Yoshihiro Shimoda7d740a02008-01-07 14:40:07 +0900434 defined(CONFIG_CPU_SUBTYPE_SH7763) || \
Paul Mundt32351a22007-03-12 14:38:59 +0900435 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
436 defined(CONFIG_CPU_SUBTYPE_SH7785)
Paul Mundt6fc21b82006-11-27 12:10:23 +0900437SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
Paul Mundtb7a76e42006-02-01 03:06:06 -0800438SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
439SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
440SCIF_FNS(SCSPTR, 0, 0, 0x24, 16)
441SCIF_FNS(SCLSR, 0, 0, 0x28, 16)
442#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
444SCIF_FNS(SCSPTR, 0, 0, 0x20, 16)
445SCIF_FNS(SCLSR, 0, 0, 0x24, 16)
446#endif
Paul Mundtb7a76e42006-02-01 03:06:06 -0800447#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448#define sci_in(port, reg) sci_##reg##_in(port)
449#define sci_out(port, reg, value) sci_##reg##_out(port, value)
450
451/* H8/300 series SCI pins assignment */
452#if defined(__H8300H__) || defined(__H8300S__)
453static const struct __attribute__((packed)) {
454 int port; /* GPIO port no */
455 unsigned short rx,tx; /* GPIO bit no */
456} h8300_sci_pins[] = {
457#if defined(CONFIG_H83007) || defined(CONFIG_H83068)
458 { /* SCI0 */
459 .port = H8300_GPIO_P9,
460 .rx = H8300_GPIO_B2,
461 .tx = H8300_GPIO_B0,
462 },
463 { /* SCI1 */
464 .port = H8300_GPIO_P9,
465 .rx = H8300_GPIO_B3,
466 .tx = H8300_GPIO_B1,
467 },
468 { /* SCI2 */
469 .port = H8300_GPIO_PB,
470 .rx = H8300_GPIO_B7,
471 .tx = H8300_GPIO_B6,
472 }
473#elif defined(CONFIG_H8S2678)
474 { /* SCI0 */
475 .port = H8300_GPIO_P3,
476 .rx = H8300_GPIO_B2,
477 .tx = H8300_GPIO_B0,
478 },
479 { /* SCI1 */
480 .port = H8300_GPIO_P3,
481 .rx = H8300_GPIO_B3,
482 .tx = H8300_GPIO_B1,
483 },
484 { /* SCI2 */
485 .port = H8300_GPIO_P5,
486 .rx = H8300_GPIO_B1,
487 .tx = H8300_GPIO_B0,
488 }
489#endif
490};
491#endif
492
Magnus Damm0fbde952007-07-26 10:14:16 +0900493#if defined(CONFIG_CPU_SUBTYPE_SH7706) || \
494 defined(CONFIG_CPU_SUBTYPE_SH7707) || \
495 defined(CONFIG_CPU_SUBTYPE_SH7708) || \
496 defined(CONFIG_CPU_SUBTYPE_SH7709)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497static inline int sci_rxd_in(struct uart_port *port)
498{
499 if (port->mapbase == 0xfffffe80)
500 return ctrl_inb(SCPDR)&0x01 ? 1 : 0; /* SCI */
501 if (port->mapbase == 0xa4000150)
502 return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
503 if (port->mapbase == 0xa4000140)
504 return ctrl_inb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
505 return 1;
506}
507#elif defined(CONFIG_CPU_SUBTYPE_SH7705)
508static inline int sci_rxd_in(struct uart_port *port)
509{
510 if (port->mapbase == SCIF0)
511 return ctrl_inb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
512 if (port->mapbase == SCIF2)
513 return ctrl_inb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
514 return 1;
515}
Nobuhiro Iwamatsu9465a542007-03-27 18:13:51 +0900516#elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
Paul Mundte108b2c2006-09-27 16:32:13 +0900517static inline int sci_rxd_in(struct uart_port *port)
518{
Nobuhiro Iwamatsu9465a542007-03-27 18:13:51 +0900519 return sci_in(port,SCxSR)&0x0010 ? 1 : 0;
Paul Mundte108b2c2006-09-27 16:32:13 +0900520}
Nobuhiro Iwamatsu9465a542007-03-27 18:13:51 +0900521static inline void set_sh771x_scif_pfc(struct uart_port *port)
522{
523 if (port->mapbase == 0xA4400000){
524 ctrl_outw(ctrl_inw(PACR)&0xffc0,PACR);
525 ctrl_outw(ctrl_inw(PBCR)&0x0fff,PBCR);
526 return;
527 }
528 if (port->mapbase == 0xA4410000){
529 ctrl_outw(ctrl_inw(PBCR)&0xf003,PBCR);
530 return;
531 }
532}
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +0900533#elif defined(CONFIG_CPU_SUBTYPE_SH7720) || \
534 defined(CONFIG_CPU_SUBTYPE_SH7721)
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900535static inline int sci_rxd_in(struct uart_port *port)
536{
537 if (port->mapbase == 0xa4430000)
538 return sci_in(port, SCxSR) & 0x0003 ? 1 : 0;
539 else if (port->mapbase == 0xa4438000)
540 return sci_in(port, SCxSR) & 0x0003 ? 1 : 0;
541 return 1;
542}
Paul Mundt05627482007-05-15 16:25:47 +0900543#elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
544 defined(CONFIG_CPU_SUBTYPE_SH7751) || \
545 defined(CONFIG_CPU_SUBTYPE_SH7751R) || \
546 defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
547 defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
548 defined(CONFIG_CPU_SUBTYPE_SH7091) || \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 defined(CONFIG_CPU_SUBTYPE_SH4_202)
550static inline int sci_rxd_in(struct uart_port *port)
551{
552#ifndef SCIF_ONLY
553 if (port->mapbase == 0xffe00000)
554 return ctrl_inb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
555#endif
556#ifndef SCI_ONLY
557 if (port->mapbase == 0xffe80000)
558 return ctrl_inw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
559#endif
560 return 1;
561}
562#elif defined(CONFIG_CPU_SUBTYPE_SH7760)
563static inline int sci_rxd_in(struct uart_port *port)
564{
565 if (port->mapbase == 0xfe600000)
566 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
567 if (port->mapbase == 0xfe610000)
568 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
569 if (port->mapbase == 0xfe620000)
570 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
Paul Mundt31388752006-12-08 14:26:19 +0900571 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572}
Paul Mundte108b2c2006-09-27 16:32:13 +0900573#elif defined(CONFIG_CPU_SUBTYPE_SH7343)
574static inline int sci_rxd_in(struct uart_port *port)
575{
576 if (port->mapbase == 0xffe00000)
577 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
578 if (port->mapbase == 0xffe10000)
579 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
580 if (port->mapbase == 0xffe20000)
581 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
582 if (port->mapbase == 0xffe30000)
583 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
584 return 1;
585}
Magnus Damm9109a302008-02-08 17:31:24 +0900586#elif defined(CONFIG_CPU_SUBTYPE_SH7722) || defined(CONFIG_CPU_SUBTYPE_SH7366)
Paul Mundt41504c32006-12-11 20:28:03 +0900587static inline int sci_rxd_in(struct uart_port *port)
588{
589 if (port->mapbase == 0xffe00000)
590 return ctrl_inb(SCPDR0) & 0x0001 ? 1 : 0; /* SCIF0 */
591 return 1;
592}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
594static inline int sci_rxd_in(struct uart_port *port)
595{
596 return sci_in(port, SCSPTR)&0x0001 ? 1 : 0; /* SCIF */
597}
598#elif defined(__H8300H__) || defined(__H8300S__)
599static inline int sci_rxd_in(struct uart_port *port)
600{
601 int ch = (port->mapbase - SMR0) >> 3;
602 return (H8300_SCI_DR(ch) & h8300_sci_pins[ch].rx) ? 1 : 0;
603}
Yoshihiro Shimoda7d740a02008-01-07 14:40:07 +0900604#elif defined(CONFIG_CPU_SUBTYPE_SH7763)
605static inline int sci_rxd_in(struct uart_port *port)
606{
607 if (port->mapbase == 0xffe00000)
608 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
609 if (port->mapbase == 0xffe08000)
610 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
611 return 1;
612}
Paul Mundtb7a76e42006-02-01 03:06:06 -0800613#elif defined(CONFIG_CPU_SUBTYPE_SH7770)
614static inline int sci_rxd_in(struct uart_port *port)
615{
616 if (port->mapbase == 0xff923000)
617 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
618 if (port->mapbase == 0xff924000)
619 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
620 if (port->mapbase == 0xff925000)
621 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
Paul Mundt31388752006-12-08 14:26:19 +0900622 return 1;
Paul Mundtb7a76e42006-02-01 03:06:06 -0800623}
624#elif defined(CONFIG_CPU_SUBTYPE_SH7780)
625static inline int sci_rxd_in(struct uart_port *port)
626{
627 if (port->mapbase == 0xffe00000)
628 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
629 if (port->mapbase == 0xffe10000)
630 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
Paul Mundt31388752006-12-08 14:26:19 +0900631 return 1;
Paul Mundtb7a76e42006-02-01 03:06:06 -0800632}
Paul Mundt32351a22007-03-12 14:38:59 +0900633#elif defined(CONFIG_CPU_SUBTYPE_SH7785)
634static inline int sci_rxd_in(struct uart_port *port)
635{
636 if (port->mapbase == 0xffea0000)
637 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
638 if (port->mapbase == 0xffeb0000)
639 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
640 if (port->mapbase == 0xffec0000)
641 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
642 if (port->mapbase == 0xffed0000)
643 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
644 if (port->mapbase == 0xffee0000)
645 return ctrl_inw(SCSPTR4) & 0x0001 ? 1 : 0; /* SCIF */
646 if (port->mapbase == 0xffef0000)
647 return ctrl_inw(SCSPTR5) & 0x0001 ? 1 : 0; /* SCIF */
648 return 1;
649}
Paul Mundt6d01f512007-11-26 18:17:21 +0900650#elif defined(CONFIG_CPU_SUBTYPE_SH7203) || \
Paul Mundta8f67f42007-11-26 19:54:02 +0900651 defined(CONFIG_CPU_SUBTYPE_SH7206) || \
652 defined(CONFIG_CPU_SUBTYPE_SH7263)
Yoshinori Sato9d4436a2006-11-05 15:40:13 +0900653static inline int sci_rxd_in(struct uart_port *port)
654{
655 if (port->mapbase == 0xfffe8000)
656 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
657 if (port->mapbase == 0xfffe8800)
658 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
659 if (port->mapbase == 0xfffe9000)
660 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
661 if (port->mapbase == 0xfffe9800)
662 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
Paul Mundt31388752006-12-08 14:26:19 +0900663 return 1;
Yoshinori Sato9d4436a2006-11-05 15:40:13 +0900664}
665#elif defined(CONFIG_CPU_SUBTYPE_SH7619)
666static inline int sci_rxd_in(struct uart_port *port)
667{
668 if (port->mapbase == 0xf8400000)
669 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
670 if (port->mapbase == 0xf8410000)
671 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
672 if (port->mapbase == 0xf8420000)
673 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
Paul Mundt31388752006-12-08 14:26:19 +0900674 return 1;
Yoshinori Sato9d4436a2006-11-05 15:40:13 +0900675}
Paul Mundt2b1bd1a2007-06-20 18:27:10 +0900676#elif defined(CONFIG_CPU_SUBTYPE_SHX3)
677static inline int sci_rxd_in(struct uart_port *port)
678{
679 if (port->mapbase == 0xffc30000)
680 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
681 if (port->mapbase == 0xffc40000)
682 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
683 if (port->mapbase == 0xffc50000)
684 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
685 if (port->mapbase == 0xffc60000)
686 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
Paul Mundt1760b7d72007-08-08 16:57:05 +0900687 return 1;
Paul Mundt2b1bd1a2007-06-20 18:27:10 +0900688}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689#endif
690
691/*
692 * Values for the BitRate Register (SCBRR)
693 *
694 * The values are actually divisors for a frequency which can
695 * be internal to the SH3 (14.7456MHz) or derived from an external
696 * clock source. This driver assumes the internal clock is used;
697 * to support using an external clock source, config options or
698 * possibly command-line options would need to be added.
699 *
700 * Also, to support speeds below 2400 (why?) the lower 2 bits of
701 * the SCSMR register would also need to be set to non-zero values.
702 *
703 * -- Greg Banks 27Feb2000
704 *
705 * Answer: The SCBRR register is only eight bits, and the value in
706 * it gets larger with lower baud rates. At around 2400 (depending on
707 * the peripherial module clock) you run out of bits. However the
708 * lower two bits of SCSMR allow the module clock to be divided down,
709 * scaling the value which is needed in SCBRR.
710 *
711 * -- Stuart Menefy - 23 May 2000
712 *
713 * I meant, why would anyone bother with bitrates below 2400.
714 *
715 * -- Greg Banks - 7Jul2000
716 *
717 * You "speedist"! How will I use my 110bps ASR-33 teletype with paper
718 * tape reader as a console!
719 *
720 * -- Mitch Davis - 15 Jul 2000
721 */
722
Yoshihiro Shimoda7d740a02008-01-07 14:40:07 +0900723#if defined(CONFIG_CPU_SUBTYPE_SH7763) || \
724 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
Paul Mundt32351a22007-03-12 14:38:59 +0900725 defined(CONFIG_CPU_SUBTYPE_SH7785)
Paul Mundtb7a76e42006-02-01 03:06:06 -0800726#define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1)
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900727#elif defined(CONFIG_CPU_SUBTYPE_SH7705) || \
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +0900728 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
729 defined(CONFIG_CPU_SUBTYPE_SH7721)
Paul Mundtb7a76e42006-02-01 03:06:06 -0800730#define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1)
731#elif defined(__H8300H__) || defined(__H8300S__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732#define SCBRR_VALUE(bps) (((CONFIG_CPU_CLOCK*1000/32)/bps)-1)
Paul Mundtb7a76e42006-02-01 03:06:06 -0800733#elif defined(CONFIG_SUPERH64)
734#define SCBRR_VALUE(bps) ((current_cpu_data.module_clock+16*bps)/(32*bps)-1)
735#else /* Generic SH */
736#define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(32*bps)-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737#endif