blob: 5b3e9769ca2101fc8645a4ef6c1e5835412f0594 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/serial/sh-sci.c
3 *
4 * SuperH on-chip serial module support. (SCI with no FIFO / with FIFO)
5 *
Paul Mundtf43dc232011-01-13 15:06:28 +09006 * Copyright (C) 2002 - 2011 Paul Mundt
Markus Brunner3ea6bc32007-08-20 08:59:33 +09007 * Modified to support SH7720 SCIF. Markus Brunner, Mark Jonas (Jul 2007).
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * based off of the old drivers/char/sh-sci.c by:
10 *
11 * Copyright (C) 1999, 2000 Niibe Yutaka
12 * Copyright (C) 2000 Sugioka Toshinobu
13 * Modified to support multiple serial ports. Stuart Menefy (May 2000).
14 * Modified to support SecureEdge. David McCullough (2002)
15 * Modified to support SH7300 SCIF. Takashi Kusuda (Jun 2003).
Magnus Dammd89ddd12007-07-25 11:42:56 +090016 * Removed SH7300 support (Jul 2007).
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 *
18 * This file is subject to the terms and conditions of the GNU General Public
19 * License. See the file "COPYING" in the main directory of this archive
20 * for more details.
21 */
Paul Mundt0b3d4ef2007-03-14 13:22:37 +090022#if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
23#define SUPPORT_SYSRQ
24#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#undef DEBUG
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/module.h>
29#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/timer.h>
31#include <linux/interrupt.h>
32#include <linux/tty.h>
33#include <linux/tty_flip.h>
34#include <linux/serial.h>
35#include <linux/major.h>
36#include <linux/string.h>
37#include <linux/sysrq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/ioport.h>
39#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/init.h>
41#include <linux/delay.h>
42#include <linux/console.h>
Paul Mundte108b2c2006-09-27 16:32:13 +090043#include <linux/platform_device.h>
Paul Mundt96de1a82008-02-26 14:52:45 +090044#include <linux/serial_sci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/notifier.h>
46#include <linux/cpufreq.h>
Paul Mundt85f094e2008-04-25 16:04:20 +090047#include <linux/clk.h>
Paul Mundtfa5da2f2007-03-08 17:27:37 +090048#include <linux/ctype.h>
Paul Mundt7ff731a2008-10-01 15:46:58 +090049#include <linux/err.h>
Magnus Damme552de22009-01-21 15:13:42 +000050#include <linux/list.h>
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +090051#include <linux/dmaengine.h>
52#include <linux/scatterlist.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090053#include <linux/slab.h>
Paul Mundt85f094e2008-04-25 16:04:20 +090054
55#ifdef CONFIG_SUPERH
Paul Mundte108b2c2006-09-27 16:32:13 +090056#include <asm/sh_bios.h>
Paul Mundtb7a76e42006-02-01 03:06:06 -080057#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Yoshinori Sato168f3622009-04-28 04:40:15 +000059#ifdef CONFIG_H8300
60#include <asm/gpio.h>
61#endif
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include "sh-sci.h"
64
Paul Mundte108b2c2006-09-27 16:32:13 +090065struct sci_port {
66 struct uart_port port;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Paul Mundtce6738b2011-01-19 15:24:40 +090068 /* Platform configuration */
69 struct plat_sci_port *cfg;
Paul Mundte108b2c2006-09-27 16:32:13 +090070
Paul Mundte108b2c2006-09-27 16:32:13 +090071 /* Port enable callback */
72 void (*enable)(struct uart_port *port);
73
74 /* Port disable callback */
75 void (*disable)(struct uart_port *port);
76
77 /* Break timer */
78 struct timer_list break_timer;
79 int break_flag;
dmitry pervushin1534a3b2007-04-24 13:41:12 +090080
Magnus Damm501b8252009-01-21 15:14:30 +000081 /* Interface clock */
82 struct clk *iclk;
Paul Mundtc7ed1ab2010-03-10 18:35:14 +090083 /* Function clock */
84 struct clk *fclk;
Paul Mundtedad1f22009-11-25 16:23:35 +090085
Magnus Damme552de22009-01-21 15:13:42 +000086 struct list_head node;
Paul Mundtf43dc232011-01-13 15:06:28 +090087
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +090088 struct dma_chan *chan_tx;
89 struct dma_chan *chan_rx;
Paul Mundtf43dc232011-01-13 15:06:28 +090090
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +090091#ifdef CONFIG_SERIAL_SH_SCI_DMA
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +090092 struct dma_async_tx_descriptor *desc_tx;
93 struct dma_async_tx_descriptor *desc_rx[2];
94 dma_cookie_t cookie_tx;
95 dma_cookie_t cookie_rx[2];
96 dma_cookie_t active_rx;
97 struct scatterlist sg_tx;
98 unsigned int sg_len_tx;
99 struct scatterlist sg_rx[2];
100 size_t buf_len_rx;
101 struct sh_dmae_slave param_tx;
102 struct sh_dmae_slave param_rx;
103 struct work_struct work_tx;
104 struct work_struct work_rx;
105 struct timer_list rx_timer;
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +0000106 unsigned int rx_timeout;
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900107#endif
Magnus Damme552de22009-01-21 15:13:42 +0000108};
109
110struct sh_sci_priv {
111 spinlock_t lock;
112 struct list_head ports;
Magnus Damme552de22009-01-21 15:13:42 +0000113 struct notifier_block clk_nb;
Paul Mundte108b2c2006-09-27 16:32:13 +0900114};
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116/* Function prototypes */
Russell Kingb129a8c2005-08-31 10:12:14 +0100117static void sci_stop_tx(struct uart_port *port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Paul Mundte108b2c2006-09-27 16:32:13 +0900119#define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS
120
121static struct sci_port sci_ports[SCI_NPORTS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static struct uart_driver sci_uart_driver;
123
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900124static inline struct sci_port *
125to_sci_port(struct uart_port *uart)
126{
127 return container_of(uart, struct sci_port, port);
128}
129
Paul Mundt07d2a1a2008-12-11 19:06:43 +0900130#if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
Paul Mundt1f6fd5c2008-12-17 14:53:24 +0900131
132#ifdef CONFIG_CONSOLE_POLL
Paul Mundte108b2c2006-09-27 16:32:13 +0900133static inline void handle_error(struct uart_port *port)
134{
135 /* Clear error flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
137}
138
Paul Mundt07d2a1a2008-12-11 19:06:43 +0900139static int sci_poll_get_char(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 unsigned short status;
142 int c;
143
Paul Mundte108b2c2006-09-27 16:32:13 +0900144 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 status = sci_in(port, SCxSR);
146 if (status & SCxSR_ERRORS(port)) {
147 handle_error(port);
148 continue;
149 }
Jason Wessel3f255eb2010-05-20 21:04:23 -0500150 break;
151 } while (1);
152
153 if (!(status & SCxSR_RDxF(port)))
154 return NO_POLL_CHAR;
Paul Mundt07d2a1a2008-12-11 19:06:43 +0900155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 c = sci_in(port, SCxRDR);
Paul Mundt07d2a1a2008-12-11 19:06:43 +0900157
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900158 /* Dummy read */
159 sci_in(port, SCxSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 return c;
163}
Paul Mundt1f6fd5c2008-12-17 14:53:24 +0900164#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Paul Mundt07d2a1a2008-12-11 19:06:43 +0900166static void sci_poll_put_char(struct uart_port *port, unsigned char c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 unsigned short status;
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 do {
171 status = sci_in(port, SCxSR);
172 } while (!(status & SCxSR_TDxE(port)));
173
Paul Mundt272966c2008-11-13 17:46:06 +0900174 sci_out(port, SCxTDR, c);
SUGIOKA Toshinobudd0a3e72009-06-01 03:53:41 +0000175 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
Paul Mundt07d2a1a2008-12-11 19:06:43 +0900177#endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Paul Mundt15c73aa2008-10-02 19:47:12 +0900179#if defined(__H8300H__) || defined(__H8300S__)
Paul Mundtd5701642008-12-16 20:07:27 +0900180static void sci_init_pins(struct uart_port *port, unsigned int cflag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
182 int ch = (port->mapbase - SMR0) >> 3;
183
184 /* set DDR regs */
Paul Mundte108b2c2006-09-27 16:32:13 +0900185 H8300_GPIO_DDR(h8300_sci_pins[ch].port,
186 h8300_sci_pins[ch].rx,
187 H8300_GPIO_INPUT);
188 H8300_GPIO_DDR(h8300_sci_pins[ch].port,
189 h8300_sci_pins[ch].tx,
190 H8300_GPIO_OUTPUT);
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 /* tx mark output*/
193 H8300_SCI_DR(ch) |= h8300_sci_pins[ch].tx;
194}
Paul Mundtd5701642008-12-16 20:07:27 +0900195#elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
196static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
Paul Mundte108b2c2006-09-27 16:32:13 +0900197{
Paul Mundtd5701642008-12-16 20:07:27 +0900198 if (port->mapbase == 0xA4400000) {
199 __raw_writew(__raw_readw(PACR) & 0xffc0, PACR);
200 __raw_writew(__raw_readw(PBCR) & 0x0fff, PBCR);
201 } else if (port->mapbase == 0xA4410000)
202 __raw_writew(__raw_readw(PBCR) & 0xf003, PBCR);
Nobuhiro Iwamatsu9465a542007-03-27 18:13:51 +0900203}
Yoshihiro Shimoda31a49c42007-12-26 11:45:06 +0900204#elif defined(CONFIG_CPU_SUBTYPE_SH7720) || defined(CONFIG_CPU_SUBTYPE_SH7721)
Paul Mundtd5701642008-12-16 20:07:27 +0900205static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900206{
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900207 unsigned short data;
208
209 if (cflag & CRTSCTS) {
210 /* enable RTS/CTS */
211 if (port->mapbase == 0xa4430000) { /* SCIF0 */
212 /* Clear PTCR bit 9-2; enable all scif pins but sck */
Paul Mundtd5701642008-12-16 20:07:27 +0900213 data = __raw_readw(PORT_PTCR);
214 __raw_writew((data & 0xfc03), PORT_PTCR);
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900215 } else if (port->mapbase == 0xa4438000) { /* SCIF1 */
216 /* Clear PVCR bit 9-2 */
Paul Mundtd5701642008-12-16 20:07:27 +0900217 data = __raw_readw(PORT_PVCR);
218 __raw_writew((data & 0xfc03), PORT_PVCR);
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900219 }
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900220 } else {
221 if (port->mapbase == 0xa4430000) { /* SCIF0 */
222 /* Clear PTCR bit 5-2; enable only tx and rx */
Paul Mundtd5701642008-12-16 20:07:27 +0900223 data = __raw_readw(PORT_PTCR);
224 __raw_writew((data & 0xffc3), PORT_PTCR);
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900225 } else if (port->mapbase == 0xa4438000) { /* SCIF1 */
226 /* Clear PVCR bit 5-2 */
Paul Mundtd5701642008-12-16 20:07:27 +0900227 data = __raw_readw(PORT_PVCR);
228 __raw_writew((data & 0xffc3), PORT_PVCR);
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900229 }
230 }
Markus Brunner3ea6bc32007-08-20 08:59:33 +0900231}
Paul Mundtb7a76e42006-02-01 03:06:06 -0800232#elif defined(CONFIG_CPU_SH3)
Paul Mundte108b2c2006-09-27 16:32:13 +0900233/* For SH7705, SH7706, SH7707, SH7709, SH7709A, SH7729 */
Paul Mundtd5701642008-12-16 20:07:27 +0900234static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
Paul Mundtb7a76e42006-02-01 03:06:06 -0800236 unsigned short data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Paul Mundtb7a76e42006-02-01 03:06:06 -0800238 /* We need to set SCPCR to enable RTS/CTS */
Paul Mundtd5701642008-12-16 20:07:27 +0900239 data = __raw_readw(SCPCR);
Paul Mundtb7a76e42006-02-01 03:06:06 -0800240 /* Clear out SCP7MD1,0, SCP6MD1,0, SCP4MD1,0*/
Paul Mundtd5701642008-12-16 20:07:27 +0900241 __raw_writew(data & 0x0fcf, SCPCR);
Paul Mundtb7a76e42006-02-01 03:06:06 -0800242
Paul Mundtd5701642008-12-16 20:07:27 +0900243 if (!(cflag & CRTSCTS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 /* We need to set SCPCR to enable RTS/CTS */
Paul Mundtd5701642008-12-16 20:07:27 +0900245 data = __raw_readw(SCPCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 /* Clear out SCP7MD1,0, SCP4MD1,0,
247 Set SCP6MD1,0 = {01} (output) */
Paul Mundtd5701642008-12-16 20:07:27 +0900248 __raw_writew((data & 0x0fcf) | 0x1000, SCPCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Paul Mundt32b53072009-12-24 14:52:43 +0900250 data = __raw_readb(SCPDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 /* Set /RTS2 (bit6) = 0 */
Paul Mundt32b53072009-12-24 14:52:43 +0900252 __raw_writeb(data & 0xbf, SCPDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
Paul Mundt41504c32006-12-11 20:28:03 +0900255#elif defined(CONFIG_CPU_SUBTYPE_SH7722)
Paul Mundtd5701642008-12-16 20:07:27 +0900256static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
Paul Mundt41504c32006-12-11 20:28:03 +0900257{
Magnus Damm346b7462008-04-23 21:25:29 +0900258 unsigned short data;
Paul Mundt41504c32006-12-11 20:28:03 +0900259
Magnus Damm346b7462008-04-23 21:25:29 +0900260 if (port->mapbase == 0xffe00000) {
Paul Mundtd5701642008-12-16 20:07:27 +0900261 data = __raw_readw(PSCR);
Magnus Damm346b7462008-04-23 21:25:29 +0900262 data &= ~0x03cf;
Paul Mundtd5701642008-12-16 20:07:27 +0900263 if (!(cflag & CRTSCTS))
Magnus Damm346b7462008-04-23 21:25:29 +0900264 data |= 0x0340;
Paul Mundt41504c32006-12-11 20:28:03 +0900265
Paul Mundtd5701642008-12-16 20:07:27 +0900266 __raw_writew(data, PSCR);
Paul Mundt41504c32006-12-11 20:28:03 +0900267 }
Paul Mundt41504c32006-12-11 20:28:03 +0900268}
Yoshihiro Shimodac01f0f12009-08-21 16:30:28 +0900269#elif defined(CONFIG_CPU_SUBTYPE_SH7757) || \
270 defined(CONFIG_CPU_SUBTYPE_SH7763) || \
Yoshihiro Shimoda7d740a02008-01-07 14:40:07 +0900271 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
Paul Mundt2b1bd1a2007-06-20 18:27:10 +0900272 defined(CONFIG_CPU_SUBTYPE_SH7785) || \
Kuninori Morimoto55ba99e2009-03-03 15:40:25 +0900273 defined(CONFIG_CPU_SUBTYPE_SH7786) || \
Paul Mundt2b1bd1a2007-06-20 18:27:10 +0900274 defined(CONFIG_CPU_SUBTYPE_SHX3)
Paul Mundtd5701642008-12-16 20:07:27 +0900275static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
276{
277 if (!(cflag & CRTSCTS))
278 __raw_writew(0x0080, SCSPTR0); /* Set RTS = 1 */
279}
Paul Mundtb0c50ad2008-12-22 03:40:10 +0900280#elif defined(CONFIG_CPU_SH4) && !defined(CONFIG_CPU_SH4A)
Paul Mundtd5701642008-12-16 20:07:27 +0900281static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
282{
283 if (!(cflag & CRTSCTS))
284 __raw_writew(0x0080, SCSPTR2); /* Set RTS = 1 */
285}
Paul Mundtb7a76e42006-02-01 03:06:06 -0800286#else
Paul Mundtd5701642008-12-16 20:07:27 +0900287static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
288{
289 /* Nothing to do */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
Paul Mundte108b2c2006-09-27 16:32:13 +0900291#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Paul Mundt32351a22007-03-12 14:38:59 +0900293#if defined(CONFIG_CPU_SUBTYPE_SH7760) || \
294 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
Kuninori Morimoto55ba99e2009-03-03 15:40:25 +0900295 defined(CONFIG_CPU_SUBTYPE_SH7785) || \
296 defined(CONFIG_CPU_SUBTYPE_SH7786)
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900297static int scif_txfill(struct uart_port *port)
Paul Mundte108b2c2006-09-27 16:32:13 +0900298{
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900299 return sci_in(port, SCTFDR) & 0xff;
Paul Mundte108b2c2006-09-27 16:32:13 +0900300}
301
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900302static int scif_txroom(struct uart_port *port)
303{
304 return SCIF_TXROOM_MAX - scif_txfill(port);
305}
306
307static int scif_rxfill(struct uart_port *port)
Paul Mundte108b2c2006-09-27 16:32:13 +0900308{
Yutaro Ebiharacae167d2008-03-11 13:58:50 +0900309 return sci_in(port, SCRFDR) & 0xff;
Paul Mundte108b2c2006-09-27 16:32:13 +0900310}
Nobuhiro Iwamatsuc63847a2008-06-06 17:04:08 +0900311#elif defined(CONFIG_CPU_SUBTYPE_SH7763)
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900312static int scif_txfill(struct uart_port *port)
Nobuhiro Iwamatsuc63847a2008-06-06 17:04:08 +0900313{
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900314 if (port->mapbase == 0xffe00000 ||
315 port->mapbase == 0xffe08000)
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900316 /* SCIF0/1*/
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900317 return sci_in(port, SCTFDR) & 0xff;
318 else
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900319 /* SCIF2 */
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900320 return sci_in(port, SCFDR) >> 8;
Nobuhiro Iwamatsuc63847a2008-06-06 17:04:08 +0900321}
322
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900323static int scif_txroom(struct uart_port *port)
324{
325 if (port->mapbase == 0xffe00000 ||
326 port->mapbase == 0xffe08000)
327 /* SCIF0/1*/
328 return SCIF_TXROOM_MAX - scif_txfill(port);
329 else
330 /* SCIF2 */
331 return SCIF2_TXROOM_MAX - scif_txfill(port);
332}
333
334static int scif_rxfill(struct uart_port *port)
Nobuhiro Iwamatsuc63847a2008-06-06 17:04:08 +0900335{
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900336 if ((port->mapbase == 0xffe00000) ||
337 (port->mapbase == 0xffe08000)) {
338 /* SCIF0/1*/
Nobuhiro Iwamatsuc63847a2008-06-06 17:04:08 +0900339 return sci_in(port, SCRFDR) & 0xff;
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900340 } else {
341 /* SCIF2 */
Nobuhiro Iwamatsuc63847a2008-06-06 17:04:08 +0900342 return sci_in(port, SCFDR) & SCIF2_RFDC_MASK;
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900343 }
Nobuhiro Iwamatsuc63847a2008-06-06 17:04:08 +0900344}
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +0000345#elif defined(CONFIG_ARCH_SH7372)
346static int scif_txfill(struct uart_port *port)
Paul Mundte108b2c2006-09-27 16:32:13 +0900347{
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +0000348 if (port->type == PORT_SCIFA)
349 return sci_in(port, SCFDR) >> 8;
350 else
351 return sci_in(port, SCTFDR);
Paul Mundte108b2c2006-09-27 16:32:13 +0900352}
353
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +0000354static int scif_txroom(struct uart_port *port)
355{
356 return port->fifosize - scif_txfill(port);
357}
358
359static int scif_rxfill(struct uart_port *port)
360{
361 if (port->type == PORT_SCIFA)
362 return sci_in(port, SCFDR) & SCIF_RFDC_MASK;
363 else
364 return sci_in(port, SCRFDR);
365}
Paul Mundte108b2c2006-09-27 16:32:13 +0900366#else
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900367static int scif_txfill(struct uart_port *port)
Paul Mundte108b2c2006-09-27 16:32:13 +0900368{
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900369 return sci_in(port, SCFDR) >> 8;
Paul Mundte108b2c2006-09-27 16:32:13 +0900370}
371
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900372static int scif_txroom(struct uart_port *port)
373{
374 return SCIF_TXROOM_MAX - scif_txfill(port);
375}
376
377static int scif_rxfill(struct uart_port *port)
Paul Mundte108b2c2006-09-27 16:32:13 +0900378{
379 return sci_in(port, SCFDR) & SCIF_RFDC_MASK;
380}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900383static int sci_txfill(struct uart_port *port)
Paul Mundte108b2c2006-09-27 16:32:13 +0900384{
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900385 return !(sci_in(port, SCxSR) & SCI_TDRE);
Paul Mundte108b2c2006-09-27 16:32:13 +0900386}
387
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900388static int sci_txroom(struct uart_port *port)
389{
390 return !sci_txfill(port);
391}
392
393static int sci_rxfill(struct uart_port *port)
Paul Mundte108b2c2006-09-27 16:32:13 +0900394{
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900395 return (sci_in(port, SCxSR) & SCxSR_RDxF(port)) != 0;
Paul Mundte108b2c2006-09-27 16:32:13 +0900396}
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398/* ********************************************************************** *
399 * the interrupt related routines *
400 * ********************************************************************** */
401
402static void sci_transmit_chars(struct uart_port *port)
403{
Alan Coxebd2c8f2009-09-19 13:13:28 -0700404 struct circ_buf *xmit = &port->state->xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 unsigned int stopped = uart_tx_stopped(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 unsigned short status;
407 unsigned short ctrl;
Paul Mundte108b2c2006-09-27 16:32:13 +0900408 int count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 status = sci_in(port, SCxSR);
411 if (!(status & SCxSR_TDxE(port))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 ctrl = sci_in(port, SCSCR);
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900413 if (uart_circ_empty(xmit))
Paul Mundt8e698612009-06-24 19:44:32 +0900414 ctrl &= ~SCSCR_TIE;
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900415 else
Paul Mundt8e698612009-06-24 19:44:32 +0900416 ctrl |= SCSCR_TIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 sci_out(port, SCSCR, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return;
419 }
420
Yoshihiro Shimoda1a22f082008-11-11 12:19:05 +0900421 if (port->type == PORT_SCI)
Paul Mundte108b2c2006-09-27 16:32:13 +0900422 count = sci_txroom(port);
Yoshihiro Shimoda1a22f082008-11-11 12:19:05 +0900423 else
424 count = scif_txroom(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 do {
427 unsigned char c;
428
429 if (port->x_char) {
430 c = port->x_char;
431 port->x_char = 0;
432 } else if (!uart_circ_empty(xmit) && !stopped) {
433 c = xmit->buf[xmit->tail];
434 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
435 } else {
436 break;
437 }
438
439 sci_out(port, SCxTDR, c);
440
441 port->icount.tx++;
442 } while (--count > 0);
443
444 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
445
446 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
447 uart_write_wakeup(port);
448 if (uart_circ_empty(xmit)) {
Russell Kingb129a8c2005-08-31 10:12:14 +0100449 sci_stop_tx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 ctrl = sci_in(port, SCSCR);
452
Yoshihiro Shimoda1a22f082008-11-11 12:19:05 +0900453 if (port->type != PORT_SCI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 sci_in(port, SCxSR); /* Dummy read */
455 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Paul Mundt8e698612009-06-24 19:44:32 +0900458 ctrl |= SCSCR_TIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 sci_out(port, SCSCR, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 }
461}
462
463/* On SH3, SCIF may read end-of-break as a space->mark char */
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900464#define STEPFN(c) ({int __c = (c); (((__c-1)|(__c)) == -1); })
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
David Howells7d12e782006-10-05 14:55:46 +0100466static inline void sci_receive_chars(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900468 struct sci_port *sci_port = to_sci_port(port);
Alan Coxebd2c8f2009-09-19 13:13:28 -0700469 struct tty_struct *tty = port->state->port.tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 int i, count, copied = 0;
471 unsigned short status;
Alan Cox33f0f882006-01-09 20:54:13 -0800472 unsigned char flag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 status = sci_in(port, SCxSR);
475 if (!(status & SCxSR_RDxF(port)))
476 return;
477
478 while (1) {
Yoshihiro Shimoda1a22f082008-11-11 12:19:05 +0900479 if (port->type == PORT_SCI)
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900480 count = sci_rxfill(port);
Yoshihiro Shimoda1a22f082008-11-11 12:19:05 +0900481 else
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900482 count = scif_rxfill(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 /* Don't copy more bytes than there is room for in the buffer */
Alan Cox33f0f882006-01-09 20:54:13 -0800485 count = tty_buffer_request_room(tty, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 /* If for any reason we can't copy more data, we're done! */
488 if (count == 0)
489 break;
490
491 if (port->type == PORT_SCI) {
492 char c = sci_in(port, SCxRDR);
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900493 if (uart_handle_sysrq_char(port, c) ||
494 sci_port->break_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 count = 0;
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900496 else
Paul Mundte108b2c2006-09-27 16:32:13 +0900497 tty_insert_flip_char(tty, c, TTY_NORMAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 } else {
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900499 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 char c = sci_in(port, SCxRDR);
501 status = sci_in(port, SCxSR);
502#if defined(CONFIG_CPU_SH3)
503 /* Skip "chars" during break */
Paul Mundte108b2c2006-09-27 16:32:13 +0900504 if (sci_port->break_flag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if ((c == 0) &&
506 (status & SCxSR_FER(port))) {
507 count--; i--;
508 continue;
509 }
Paul Mundte108b2c2006-09-27 16:32:13 +0900510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 /* Nonzero => end-of-break */
Paul Mundt762c69e2008-12-16 18:55:26 +0900512 dev_dbg(port->dev, "debounce<%02x>\n", c);
Paul Mundte108b2c2006-09-27 16:32:13 +0900513 sci_port->break_flag = 0;
514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (STEPFN(c)) {
516 count--; i--;
517 continue;
518 }
519 }
520#endif /* CONFIG_CPU_SH3 */
David Howells7d12e782006-10-05 14:55:46 +0100521 if (uart_handle_sysrq_char(port, c)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 count--; i--;
523 continue;
524 }
525
526 /* Store data and status */
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900527 if (status & SCxSR_FER(port)) {
Alan Cox33f0f882006-01-09 20:54:13 -0800528 flag = TTY_FRAME;
Paul Mundt762c69e2008-12-16 18:55:26 +0900529 dev_notice(port->dev, "frame error\n");
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900530 } else if (status & SCxSR_PER(port)) {
Alan Cox33f0f882006-01-09 20:54:13 -0800531 flag = TTY_PARITY;
Paul Mundt762c69e2008-12-16 18:55:26 +0900532 dev_notice(port->dev, "parity error\n");
Alan Cox33f0f882006-01-09 20:54:13 -0800533 } else
534 flag = TTY_NORMAL;
Paul Mundt762c69e2008-12-16 18:55:26 +0900535
Alan Cox33f0f882006-01-09 20:54:13 -0800536 tty_insert_flip_char(tty, c, flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 }
538 }
539
540 sci_in(port, SCxSR); /* dummy read */
541 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 copied += count;
544 port->icount.rx += count;
545 }
546
547 if (copied) {
548 /* Tell the rest of the system the news. New characters! */
549 tty_flip_buffer_push(tty);
550 } else {
551 sci_in(port, SCxSR); /* dummy read */
552 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
553 }
554}
555
556#define SCI_BREAK_JIFFIES (HZ/20)
557/* The sci generates interrupts during the break,
558 * 1 per millisecond or so during the break period, for 9600 baud.
559 * So dont bother disabling interrupts.
560 * But dont want more than 1 break event.
561 * Use a kernel timer to periodically poll the rx line until
562 * the break is finished.
563 */
564static void sci_schedule_break_timer(struct sci_port *port)
565{
566 port->break_timer.expires = jiffies + SCI_BREAK_JIFFIES;
567 add_timer(&port->break_timer);
568}
569/* Ensure that two consecutive samples find the break over. */
570static void sci_break_timer(unsigned long data)
571{
Paul Mundte108b2c2006-09-27 16:32:13 +0900572 struct sci_port *port = (struct sci_port *)data;
573
574 if (sci_rxd_in(&port->port) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 port->break_flag = 1;
Paul Mundte108b2c2006-09-27 16:32:13 +0900576 sci_schedule_break_timer(port);
577 } else if (port->break_flag == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 /* break is over. */
579 port->break_flag = 2;
Paul Mundte108b2c2006-09-27 16:32:13 +0900580 sci_schedule_break_timer(port);
581 } else
582 port->break_flag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583}
584
585static inline int sci_handle_errors(struct uart_port *port)
586{
587 int copied = 0;
588 unsigned short status = sci_in(port, SCxSR);
Alan Coxebd2c8f2009-09-19 13:13:28 -0700589 struct tty_struct *tty = port->state->port.tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Paul Mundte108b2c2006-09-27 16:32:13 +0900591 if (status & SCxSR_ORER(port)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 /* overrun error */
Paul Mundte108b2c2006-09-27 16:32:13 +0900593 if (tty_insert_flip_char(tty, 0, TTY_OVERRUN))
Alan Cox33f0f882006-01-09 20:54:13 -0800594 copied++;
Paul Mundt762c69e2008-12-16 18:55:26 +0900595
596 dev_notice(port->dev, "overrun error");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
598
Paul Mundte108b2c2006-09-27 16:32:13 +0900599 if (status & SCxSR_FER(port)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 if (sci_rxd_in(port) == 0) {
601 /* Notify of BREAK */
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900602 struct sci_port *sci_port = to_sci_port(port);
Paul Mundte108b2c2006-09-27 16:32:13 +0900603
604 if (!sci_port->break_flag) {
605 sci_port->break_flag = 1;
606 sci_schedule_break_timer(sci_port);
607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 /* Do sysrq handling. */
Paul Mundte108b2c2006-09-27 16:32:13 +0900609 if (uart_handle_break(port))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 return 0;
Paul Mundt762c69e2008-12-16 18:55:26 +0900611
612 dev_dbg(port->dev, "BREAK detected\n");
613
Paul Mundte108b2c2006-09-27 16:32:13 +0900614 if (tty_insert_flip_char(tty, 0, TTY_BREAK))
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900615 copied++;
616 }
617
Paul Mundte108b2c2006-09-27 16:32:13 +0900618 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 /* frame error */
Paul Mundte108b2c2006-09-27 16:32:13 +0900620 if (tty_insert_flip_char(tty, 0, TTY_FRAME))
Alan Cox33f0f882006-01-09 20:54:13 -0800621 copied++;
Paul Mundt762c69e2008-12-16 18:55:26 +0900622
623 dev_notice(port->dev, "frame error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 }
625 }
626
Paul Mundte108b2c2006-09-27 16:32:13 +0900627 if (status & SCxSR_PER(port)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 /* parity error */
Paul Mundte108b2c2006-09-27 16:32:13 +0900629 if (tty_insert_flip_char(tty, 0, TTY_PARITY))
630 copied++;
Paul Mundt762c69e2008-12-16 18:55:26 +0900631
632 dev_notice(port->dev, "parity error");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 }
634
Alan Cox33f0f882006-01-09 20:54:13 -0800635 if (copied)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 tty_flip_buffer_push(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
638 return copied;
639}
640
Paul Mundtd830fa42008-12-16 19:29:38 +0900641static inline int sci_handle_fifo_overrun(struct uart_port *port)
642{
Alan Coxebd2c8f2009-09-19 13:13:28 -0700643 struct tty_struct *tty = port->state->port.tty;
Paul Mundtd830fa42008-12-16 19:29:38 +0900644 int copied = 0;
645
646 if (port->type != PORT_SCIF)
647 return 0;
648
649 if ((sci_in(port, SCLSR) & SCIF_ORER) != 0) {
650 sci_out(port, SCLSR, 0);
651
652 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
653 tty_flip_buffer_push(tty);
654
655 dev_notice(port->dev, "overrun error\n");
656 copied++;
657 }
658
659 return copied;
660}
661
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662static inline int sci_handle_breaks(struct uart_port *port)
663{
664 int copied = 0;
665 unsigned short status = sci_in(port, SCxSR);
Alan Coxebd2c8f2009-09-19 13:13:28 -0700666 struct tty_struct *tty = port->state->port.tty;
Magnus Damma5660ad2009-01-21 15:14:38 +0000667 struct sci_port *s = to_sci_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Paul Mundt0b3d4ef2007-03-14 13:22:37 +0900669 if (uart_handle_break(port))
670 return 0;
671
Paul Mundtb7a76e42006-02-01 03:06:06 -0800672 if (!s->break_flag && status & SCxSR_BRK(port)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673#if defined(CONFIG_CPU_SH3)
674 /* Debounce break */
675 s->break_flag = 1;
676#endif
677 /* Notify of BREAK */
Paul Mundte108b2c2006-09-27 16:32:13 +0900678 if (tty_insert_flip_char(tty, 0, TTY_BREAK))
Alan Cox33f0f882006-01-09 20:54:13 -0800679 copied++;
Paul Mundt762c69e2008-12-16 18:55:26 +0900680
681 dev_dbg(port->dev, "BREAK detected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 }
683
Alan Cox33f0f882006-01-09 20:54:13 -0800684 if (copied)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 tty_flip_buffer_push(tty);
Paul Mundte108b2c2006-09-27 16:32:13 +0900686
Paul Mundtd830fa42008-12-16 19:29:38 +0900687 copied += sci_handle_fifo_overrun(port);
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 return copied;
690}
691
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900692static irqreturn_t sci_rx_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900694#ifdef CONFIG_SERIAL_SH_SCI_DMA
695 struct uart_port *port = ptr;
696 struct sci_port *s = to_sci_port(port);
697
698 if (s->chan_rx) {
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900699 u16 scr = sci_in(port, SCSCR);
700 u16 ssr = sci_in(port, SCxSR);
701
702 /* Disable future Rx interrupts */
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +0000703 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +0000704 disable_irq_nosync(irq);
705 scr |= 0x4000;
706 } else {
Paul Mundtf43dc232011-01-13 15:06:28 +0900707 scr &= ~SCSCR_RIE;
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +0000708 }
709 sci_out(port, SCSCR, scr);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900710 /* Clear current interrupt */
711 sci_out(port, SCxSR, ssr & ~(1 | SCxSR_RDxF(port)));
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +0000712 dev_dbg(port->dev, "Rx IRQ %lu: setup t-out in %u jiffies\n",
713 jiffies, s->rx_timeout);
714 mod_timer(&s->rx_timer, jiffies + s->rx_timeout);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900715
716 return IRQ_HANDLED;
717 }
718#endif
719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 /* I think sci_receive_chars has to be called irrespective
721 * of whether the I_IXOFF is set, otherwise, how is the interrupt
722 * to be disabled?
723 */
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900724 sci_receive_chars(ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
726 return IRQ_HANDLED;
727}
728
David Howells7d12e782006-10-05 14:55:46 +0100729static irqreturn_t sci_tx_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
731 struct uart_port *port = ptr;
Stuart Menefyfd78a762009-07-29 23:01:24 +0900732 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Stuart Menefyfd78a762009-07-29 23:01:24 +0900734 spin_lock_irqsave(&port->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 sci_transmit_chars(port);
Stuart Menefyfd78a762009-07-29 23:01:24 +0900736 spin_unlock_irqrestore(&port->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 return IRQ_HANDLED;
739}
740
David Howells7d12e782006-10-05 14:55:46 +0100741static irqreturn_t sci_er_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
743 struct uart_port *port = ptr;
744
745 /* Handle errors */
746 if (port->type == PORT_SCI) {
747 if (sci_handle_errors(port)) {
748 /* discard character in rx buffer */
749 sci_in(port, SCxSR);
750 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
751 }
752 } else {
Paul Mundtd830fa42008-12-16 19:29:38 +0900753 sci_handle_fifo_overrun(port);
David Howells7d12e782006-10-05 14:55:46 +0100754 sci_rx_interrupt(irq, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
756
757 sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
758
759 /* Kick the transmission */
David Howells7d12e782006-10-05 14:55:46 +0100760 sci_tx_interrupt(irq, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 return IRQ_HANDLED;
763}
764
David Howells7d12e782006-10-05 14:55:46 +0100765static irqreturn_t sci_br_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
767 struct uart_port *port = ptr;
768
769 /* Handle BREAKs */
770 sci_handle_breaks(port);
771 sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port));
772
773 return IRQ_HANDLED;
774}
775
Paul Mundtf43dc232011-01-13 15:06:28 +0900776static inline unsigned long port_rx_irq_mask(struct uart_port *port)
777{
778 /*
779 * Not all ports (such as SCIFA) will support REIE. Rather than
780 * special-casing the port type, we check the port initialization
781 * IRQ enable mask to see whether the IRQ is desired at all. If
782 * it's unset, it's logically inferred that there's no point in
783 * testing for it.
784 */
Paul Mundtce6738b2011-01-19 15:24:40 +0900785 return SCSCR_RIE | (to_sci_port(port)->cfg->scscr & SCSCR_REIE);
Paul Mundtf43dc232011-01-13 15:06:28 +0900786}
787
David Howells7d12e782006-10-05 14:55:46 +0100788static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Magnus Damm44e18e92009-07-03 08:39:34 +0000790 unsigned short ssr_status, scr_status, err_enabled;
Michael Trimarchia8884e32008-10-31 16:10:23 +0900791 struct uart_port *port = ptr;
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900792 struct sci_port *s = to_sci_port(port);
Michael Trimarchia8884e32008-10-31 16:10:23 +0900793 irqreturn_t ret = IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Michael Trimarchie7c98dc2008-11-13 18:18:35 +0900795 ssr_status = sci_in(port, SCxSR);
796 scr_status = sci_in(port, SCSCR);
Paul Mundtf43dc232011-01-13 15:06:28 +0900797 err_enabled = scr_status & port_rx_irq_mask(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 /* Tx Interrupt */
Paul Mundtf43dc232011-01-13 15:06:28 +0900800 if ((ssr_status & SCxSR_TDxE(port)) && (scr_status & SCSCR_TIE) &&
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900801 !s->chan_tx)
Michael Trimarchia8884e32008-10-31 16:10:23 +0900802 ret = sci_tx_interrupt(irq, ptr);
Paul Mundtf43dc232011-01-13 15:06:28 +0900803
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900804 /*
805 * Rx Interrupt: if we're using DMA, the DMA controller clears RDF /
806 * DR flags
807 */
808 if (((ssr_status & SCxSR_RDxF(port)) || s->chan_rx) &&
Paul Mundtf43dc232011-01-13 15:06:28 +0900809 (scr_status & SCSCR_RIE))
Michael Trimarchia8884e32008-10-31 16:10:23 +0900810 ret = sci_rx_interrupt(irq, ptr);
Paul Mundtf43dc232011-01-13 15:06:28 +0900811
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 /* Error Interrupt */
SUGIOKA Toshinobudd4da3a2009-07-07 05:32:07 +0000813 if ((ssr_status & SCxSR_ERRORS(port)) && err_enabled)
Michael Trimarchia8884e32008-10-31 16:10:23 +0900814 ret = sci_er_interrupt(irq, ptr);
Paul Mundtf43dc232011-01-13 15:06:28 +0900815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 /* Break Interrupt */
SUGIOKA Toshinobudd4da3a2009-07-07 05:32:07 +0000817 if ((ssr_status & SCxSR_BRK(port)) && err_enabled)
Michael Trimarchia8884e32008-10-31 16:10:23 +0900818 ret = sci_br_interrupt(irq, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Michael Trimarchia8884e32008-10-31 16:10:23 +0900820 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821}
822
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823/*
824 * Here we define a transistion notifier so that we can update all of our
825 * ports' baud rate when the peripheral clock changes.
826 */
Paul Mundte108b2c2006-09-27 16:32:13 +0900827static int sci_notifier(struct notifier_block *self,
828 unsigned long phase, void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
Magnus Damme552de22009-01-21 15:13:42 +0000830 struct sh_sci_priv *priv = container_of(self,
831 struct sh_sci_priv, clk_nb);
832 struct sci_port *sci_port;
833 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835 if ((phase == CPUFREQ_POSTCHANGE) ||
Magnus Damme552de22009-01-21 15:13:42 +0000836 (phase == CPUFREQ_RESUMECHANGE)) {
837 spin_lock_irqsave(&priv->lock, flags);
838 list_for_each_entry(sci_port, &priv->ports, node)
Paul Mundtc7ed1ab2010-03-10 18:35:14 +0900839 sci_port->port.uartclk = clk_get_rate(sci_port->iclk);
Magnus Damme552de22009-01-21 15:13:42 +0000840 spin_unlock_irqrestore(&priv->lock, flags);
841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 return NOTIFY_OK;
844}
Magnus Damm501b8252009-01-21 15:14:30 +0000845
846static void sci_clk_enable(struct uart_port *port)
847{
848 struct sci_port *sci_port = to_sci_port(port);
849
Paul Mundtc7ed1ab2010-03-10 18:35:14 +0900850 clk_enable(sci_port->iclk);
851 sci_port->port.uartclk = clk_get_rate(sci_port->iclk);
852 clk_enable(sci_port->fclk);
Magnus Damm501b8252009-01-21 15:14:30 +0000853}
854
855static void sci_clk_disable(struct uart_port *port)
856{
857 struct sci_port *sci_port = to_sci_port(port);
858
Paul Mundtc7ed1ab2010-03-10 18:35:14 +0900859 clk_disable(sci_port->fclk);
860 clk_disable(sci_port->iclk);
Magnus Damm501b8252009-01-21 15:14:30 +0000861}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
863static int sci_request_irq(struct sci_port *port)
864{
865 int i;
David Howells7d12e782006-10-05 14:55:46 +0100866 irqreturn_t (*handlers[4])(int irq, void *ptr) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 sci_er_interrupt, sci_rx_interrupt, sci_tx_interrupt,
868 sci_br_interrupt,
869 };
870 const char *desc[] = { "SCI Receive Error", "SCI Receive Data Full",
871 "SCI Transmit Data Empty", "SCI Break" };
872
Paul Mundtce6738b2011-01-19 15:24:40 +0900873 if (port->cfg->irqs[0] == port->cfg->irqs[1]) {
874 if (unlikely(!port->cfg->irqs[0]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 return -ENODEV;
Paul Mundte108b2c2006-09-27 16:32:13 +0900876
Paul Mundtce6738b2011-01-19 15:24:40 +0900877 if (request_irq(port->cfg->irqs[0], sci_mpxed_interrupt,
Paul Mundt35f3c512006-10-06 15:31:16 +0900878 IRQF_DISABLED, "sci", port)) {
Paul Mundt762c69e2008-12-16 18:55:26 +0900879 dev_err(port->port.dev, "Can't allocate IRQ\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 return -ENODEV;
881 }
882 } else {
883 for (i = 0; i < ARRAY_SIZE(handlers); i++) {
Paul Mundtce6738b2011-01-19 15:24:40 +0900884 if (unlikely(!port->cfg->irqs[i]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 continue;
Paul Mundt762c69e2008-12-16 18:55:26 +0900886
Paul Mundtce6738b2011-01-19 15:24:40 +0900887 if (request_irq(port->cfg->irqs[i], handlers[i],
Paul Mundt35f3c512006-10-06 15:31:16 +0900888 IRQF_DISABLED, desc[i], port)) {
Paul Mundt762c69e2008-12-16 18:55:26 +0900889 dev_err(port->port.dev, "Can't allocate IRQ\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 return -ENODEV;
891 }
892 }
893 }
894
895 return 0;
896}
897
898static void sci_free_irq(struct sci_port *port)
899{
900 int i;
901
Paul Mundtce6738b2011-01-19 15:24:40 +0900902 if (port->cfg->irqs[0] == port->cfg->irqs[1])
903 free_irq(port->cfg->irqs[0], port);
Paul Mundt762c69e2008-12-16 18:55:26 +0900904 else {
Paul Mundtce6738b2011-01-19 15:24:40 +0900905 for (i = 0; i < ARRAY_SIZE(port->cfg->irqs); i++) {
906 if (!port->cfg->irqs[i])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 continue;
908
Paul Mundtce6738b2011-01-19 15:24:40 +0900909 free_irq(port->cfg->irqs[i], port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 }
911 }
912}
913
914static unsigned int sci_tx_empty(struct uart_port *port)
915{
Guennadi Liakhovetskib1516802009-12-01 09:54:46 +0000916 unsigned short status = sci_in(port, SCxSR);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900917 unsigned short in_tx_fifo = scif_txfill(port);
918
919 return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920}
921
922static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl)
923{
924 /* This routine is used for seting signals of: DTR, DCD, CTS/RTS */
925 /* We use SCIF's hardware for CTS/RTS, so don't need any for that. */
926 /* If you have signals for DTR and DCD, please implement here. */
927}
928
929static unsigned int sci_get_mctrl(struct uart_port *port)
930{
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900931 /* This routine is used for getting signals of: DTR, DCD, DSR, RI,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 and CTS/RTS */
933
934 return TIOCM_DTR | TIOCM_RTS | TIOCM_DSR;
935}
936
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900937#ifdef CONFIG_SERIAL_SH_SCI_DMA
938static void sci_dma_tx_complete(void *arg)
939{
940 struct sci_port *s = arg;
941 struct uart_port *port = &s->port;
942 struct circ_buf *xmit = &port->state->xmit;
943 unsigned long flags;
944
945 dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
946
947 spin_lock_irqsave(&port->lock, flags);
948
Magnus Dammf354a382010-03-19 04:47:01 +0000949 xmit->tail += sg_dma_len(&s->sg_tx);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900950 xmit->tail &= UART_XMIT_SIZE - 1;
951
Magnus Dammf354a382010-03-19 04:47:01 +0000952 port->icount.tx += sg_dma_len(&s->sg_tx);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900953
954 async_tx_ack(s->desc_tx);
955 s->cookie_tx = -EINVAL;
956 s->desc_tx = NULL;
957
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900958 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
959 uart_write_wakeup(port);
960
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +0000961 if (!uart_circ_empty(xmit)) {
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900962 schedule_work(&s->work_tx);
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +0000963 } else if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +0000964 u16 ctrl = sci_in(port, SCSCR);
Paul Mundtf43dc232011-01-13 15:06:28 +0900965 sci_out(port, SCSCR, ctrl & ~SCSCR_TIE);
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +0000966 }
967
968 spin_unlock_irqrestore(&port->lock, flags);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +0900969}
970
971/* Locking: called with port lock held */
972static int sci_dma_rx_push(struct sci_port *s, struct tty_struct *tty,
973 size_t count)
974{
975 struct uart_port *port = &s->port;
976 int i, active, room;
977
978 room = tty_buffer_request_room(tty, count);
979
980 if (s->active_rx == s->cookie_rx[0]) {
981 active = 0;
982 } else if (s->active_rx == s->cookie_rx[1]) {
983 active = 1;
984 } else {
985 dev_err(port->dev, "cookie %d not found!\n", s->active_rx);
986 return 0;
987 }
988
989 if (room < count)
990 dev_warn(port->dev, "Rx overrun: dropping %u bytes\n",
991 count - room);
992 if (!room)
993 return room;
994
995 for (i = 0; i < room; i++)
996 tty_insert_flip_char(tty, ((u8 *)sg_virt(&s->sg_rx[active]))[i],
997 TTY_NORMAL);
998
999 port->icount.rx += room;
1000
1001 return room;
1002}
1003
1004static void sci_dma_rx_complete(void *arg)
1005{
1006 struct sci_port *s = arg;
1007 struct uart_port *port = &s->port;
1008 struct tty_struct *tty = port->state->port.tty;
1009 unsigned long flags;
1010 int count;
1011
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001012 dev_dbg(port->dev, "%s(%d) active #%d\n", __func__, port->line, s->active_rx);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001013
1014 spin_lock_irqsave(&port->lock, flags);
1015
1016 count = sci_dma_rx_push(s, tty, s->buf_len_rx);
1017
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001018 mod_timer(&s->rx_timer, jiffies + s->rx_timeout);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001019
1020 spin_unlock_irqrestore(&port->lock, flags);
1021
1022 if (count)
1023 tty_flip_buffer_push(tty);
1024
1025 schedule_work(&s->work_rx);
1026}
1027
1028static void sci_start_rx(struct uart_port *port);
1029static void sci_start_tx(struct uart_port *port);
1030
1031static void sci_rx_dma_release(struct sci_port *s, bool enable_pio)
1032{
1033 struct dma_chan *chan = s->chan_rx;
1034 struct uart_port *port = &s->port;
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001035
1036 s->chan_rx = NULL;
1037 s->cookie_rx[0] = s->cookie_rx[1] = -EINVAL;
1038 dma_release_channel(chan);
Guennadi Liakhovetski85b8e3f2010-05-21 15:22:40 +00001039 if (sg_dma_address(&s->sg_rx[0]))
1040 dma_free_coherent(port->dev, s->buf_len_rx * 2,
1041 sg_virt(&s->sg_rx[0]), sg_dma_address(&s->sg_rx[0]));
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001042 if (enable_pio)
1043 sci_start_rx(port);
1044}
1045
1046static void sci_tx_dma_release(struct sci_port *s, bool enable_pio)
1047{
1048 struct dma_chan *chan = s->chan_tx;
1049 struct uart_port *port = &s->port;
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001050
1051 s->chan_tx = NULL;
1052 s->cookie_tx = -EINVAL;
1053 dma_release_channel(chan);
1054 if (enable_pio)
1055 sci_start_tx(port);
1056}
1057
1058static void sci_submit_rx(struct sci_port *s)
1059{
1060 struct dma_chan *chan = s->chan_rx;
1061 int i;
1062
1063 for (i = 0; i < 2; i++) {
1064 struct scatterlist *sg = &s->sg_rx[i];
1065 struct dma_async_tx_descriptor *desc;
1066
1067 desc = chan->device->device_prep_slave_sg(chan,
1068 sg, 1, DMA_FROM_DEVICE, DMA_PREP_INTERRUPT);
1069
1070 if (desc) {
1071 s->desc_rx[i] = desc;
1072 desc->callback = sci_dma_rx_complete;
1073 desc->callback_param = s;
1074 s->cookie_rx[i] = desc->tx_submit(desc);
1075 }
1076
1077 if (!desc || s->cookie_rx[i] < 0) {
1078 if (i) {
1079 async_tx_ack(s->desc_rx[0]);
1080 s->cookie_rx[0] = -EINVAL;
1081 }
1082 if (desc) {
1083 async_tx_ack(desc);
1084 s->cookie_rx[i] = -EINVAL;
1085 }
1086 dev_warn(s->port.dev,
1087 "failed to re-start DMA, using PIO\n");
1088 sci_rx_dma_release(s, true);
1089 return;
1090 }
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001091 dev_dbg(s->port.dev, "%s(): cookie %d to #%d\n", __func__,
1092 s->cookie_rx[i], i);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001093 }
1094
1095 s->active_rx = s->cookie_rx[0];
1096
1097 dma_async_issue_pending(chan);
1098}
1099
1100static void work_fn_rx(struct work_struct *work)
1101{
1102 struct sci_port *s = container_of(work, struct sci_port, work_rx);
1103 struct uart_port *port = &s->port;
1104 struct dma_async_tx_descriptor *desc;
1105 int new;
1106
1107 if (s->active_rx == s->cookie_rx[0]) {
1108 new = 0;
1109 } else if (s->active_rx == s->cookie_rx[1]) {
1110 new = 1;
1111 } else {
1112 dev_err(port->dev, "cookie %d not found!\n", s->active_rx);
1113 return;
1114 }
1115 desc = s->desc_rx[new];
1116
1117 if (dma_async_is_tx_complete(s->chan_rx, s->active_rx, NULL, NULL) !=
1118 DMA_SUCCESS) {
1119 /* Handle incomplete DMA receive */
1120 struct tty_struct *tty = port->state->port.tty;
1121 struct dma_chan *chan = s->chan_rx;
1122 struct sh_desc *sh_desc = container_of(desc, struct sh_desc,
1123 async_tx);
1124 unsigned long flags;
1125 int count;
1126
Linus Walleij05827632010-05-17 16:30:42 -07001127 chan->device->device_control(chan, DMA_TERMINATE_ALL, 0);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001128 dev_dbg(port->dev, "Read %u bytes with cookie %d\n",
1129 sh_desc->partial, sh_desc->cookie);
1130
1131 spin_lock_irqsave(&port->lock, flags);
1132 count = sci_dma_rx_push(s, tty, sh_desc->partial);
1133 spin_unlock_irqrestore(&port->lock, flags);
1134
1135 if (count)
1136 tty_flip_buffer_push(tty);
1137
1138 sci_submit_rx(s);
1139
1140 return;
1141 }
1142
1143 s->cookie_rx[new] = desc->tx_submit(desc);
1144 if (s->cookie_rx[new] < 0) {
1145 dev_warn(port->dev, "Failed submitting Rx DMA descriptor\n");
1146 sci_rx_dma_release(s, true);
1147 return;
1148 }
1149
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001150 s->active_rx = s->cookie_rx[!new];
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001151
1152 dev_dbg(port->dev, "%s: cookie %d #%d, new active #%d\n", __func__,
1153 s->cookie_rx[new], new, s->active_rx);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001154}
1155
1156static void work_fn_tx(struct work_struct *work)
1157{
1158 struct sci_port *s = container_of(work, struct sci_port, work_tx);
1159 struct dma_async_tx_descriptor *desc;
1160 struct dma_chan *chan = s->chan_tx;
1161 struct uart_port *port = &s->port;
1162 struct circ_buf *xmit = &port->state->xmit;
1163 struct scatterlist *sg = &s->sg_tx;
1164
1165 /*
1166 * DMA is idle now.
1167 * Port xmit buffer is already mapped, and it is one page... Just adjust
1168 * offsets and lengths. Since it is a circular buffer, we have to
1169 * transmit till the end, and then the rest. Take the port lock to get a
1170 * consistent xmit buffer state.
1171 */
1172 spin_lock_irq(&port->lock);
1173 sg->offset = xmit->tail & (UART_XMIT_SIZE - 1);
Magnus Dammf354a382010-03-19 04:47:01 +00001174 sg_dma_address(sg) = (sg_dma_address(sg) & ~(UART_XMIT_SIZE - 1)) +
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001175 sg->offset;
Magnus Dammf354a382010-03-19 04:47:01 +00001176 sg_dma_len(sg) = min((int)CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE),
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001177 CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE));
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001178 spin_unlock_irq(&port->lock);
1179
Magnus Dammf354a382010-03-19 04:47:01 +00001180 BUG_ON(!sg_dma_len(sg));
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001181
1182 desc = chan->device->device_prep_slave_sg(chan,
1183 sg, s->sg_len_tx, DMA_TO_DEVICE,
1184 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
1185 if (!desc) {
1186 /* switch to PIO */
1187 sci_tx_dma_release(s, true);
1188 return;
1189 }
1190
1191 dma_sync_sg_for_device(port->dev, sg, 1, DMA_TO_DEVICE);
1192
1193 spin_lock_irq(&port->lock);
1194 s->desc_tx = desc;
1195 desc->callback = sci_dma_tx_complete;
1196 desc->callback_param = s;
1197 spin_unlock_irq(&port->lock);
1198 s->cookie_tx = desc->tx_submit(desc);
1199 if (s->cookie_tx < 0) {
1200 dev_warn(port->dev, "Failed submitting Tx DMA descriptor\n");
1201 /* switch to PIO */
1202 sci_tx_dma_release(s, true);
1203 return;
1204 }
1205
1206 dev_dbg(port->dev, "%s: %p: %d...%d, cookie %d\n", __func__,
1207 xmit->buf, xmit->tail, xmit->head, s->cookie_tx);
1208
1209 dma_async_issue_pending(chan);
1210}
1211#endif
1212
Russell Kingb129a8c2005-08-31 10:12:14 +01001213static void sci_start_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214{
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001215 struct sci_port *s = to_sci_port(port);
Paul Mundte108b2c2006-09-27 16:32:13 +09001216 unsigned short ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001218#ifdef CONFIG_SERIAL_SH_SCI_DMA
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +00001219 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001220 u16 new, scr = sci_in(port, SCSCR);
1221 if (s->chan_tx)
1222 new = scr | 0x8000;
1223 else
1224 new = scr & ~0x8000;
1225 if (new != scr)
1226 sci_out(port, SCSCR, new);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001227 }
Paul Mundtf43dc232011-01-13 15:06:28 +09001228
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001229 if (s->chan_tx && !uart_circ_empty(&s->port.state->xmit) &&
1230 s->cookie_tx < 0)
1231 schedule_work(&s->work_tx);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001232#endif
Paul Mundtf43dc232011-01-13 15:06:28 +09001233
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +00001234 if (!s->chan_tx || port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001235 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
1236 ctrl = sci_in(port, SCSCR);
Paul Mundtf43dc232011-01-13 15:06:28 +09001237 sci_out(port, SCSCR, ctrl | SCSCR_TIE);
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239}
1240
Russell Kingb129a8c2005-08-31 10:12:14 +01001241static void sci_stop_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 unsigned short ctrl;
1244
1245 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 ctrl = sci_in(port, SCSCR);
Paul Mundtf43dc232011-01-13 15:06:28 +09001247
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +00001248 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001249 ctrl &= ~0x8000;
Paul Mundtf43dc232011-01-13 15:06:28 +09001250
Paul Mundt8e698612009-06-24 19:44:32 +09001251 ctrl &= ~SCSCR_TIE;
Paul Mundtf43dc232011-01-13 15:06:28 +09001252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 sci_out(port, SCSCR, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254}
1255
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001256static void sci_start_rx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 unsigned short ctrl;
1259
Paul Mundtf43dc232011-01-13 15:06:28 +09001260 ctrl = sci_in(port, SCSCR) | port_rx_irq_mask(port);
1261
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +00001262 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001263 ctrl &= ~0x4000;
Paul Mundtf43dc232011-01-13 15:06:28 +09001264
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 sci_out(port, SCSCR, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266}
1267
1268static void sci_stop_rx(struct uart_port *port)
1269{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 unsigned short ctrl;
1271
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 ctrl = sci_in(port, SCSCR);
Paul Mundtf43dc232011-01-13 15:06:28 +09001273
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +00001274 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001275 ctrl &= ~0x4000;
Paul Mundtf43dc232011-01-13 15:06:28 +09001276
1277 ctrl &= ~port_rx_irq_mask(port);
1278
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 sci_out(port, SCSCR, ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280}
1281
1282static void sci_enable_ms(struct uart_port *port)
1283{
1284 /* Nothing here yet .. */
1285}
1286
1287static void sci_break_ctl(struct uart_port *port, int break_state)
1288{
1289 /* Nothing here yet .. */
1290}
1291
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001292#ifdef CONFIG_SERIAL_SH_SCI_DMA
1293static bool filter(struct dma_chan *chan, void *slave)
1294{
1295 struct sh_dmae_slave *param = slave;
1296
1297 dev_dbg(chan->device->dev, "%s: slave ID %d\n", __func__,
1298 param->slave_id);
1299
1300 if (param->dma_dev == chan->device->dev) {
1301 chan->private = param;
1302 return true;
1303 } else {
1304 return false;
1305 }
1306}
1307
1308static void rx_timer_fn(unsigned long arg)
1309{
1310 struct sci_port *s = (struct sci_port *)arg;
1311 struct uart_port *port = &s->port;
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001312 u16 scr = sci_in(port, SCSCR);
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001313
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +00001314 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001315 scr &= ~0x4000;
Paul Mundtce6738b2011-01-19 15:24:40 +09001316 enable_irq(s->cfg->irqs[1]);
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001317 }
Paul Mundtf43dc232011-01-13 15:06:28 +09001318 sci_out(port, SCSCR, scr | SCSCR_RIE);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001319 dev_dbg(port->dev, "DMA Rx timed out\n");
1320 schedule_work(&s->work_rx);
1321}
1322
1323static void sci_request_dma(struct uart_port *port)
1324{
1325 struct sci_port *s = to_sci_port(port);
1326 struct sh_dmae_slave *param;
1327 struct dma_chan *chan;
1328 dma_cap_mask_t mask;
1329 int nent;
1330
1331 dev_dbg(port->dev, "%s: port %d DMA %p\n", __func__,
Paul Mundtce6738b2011-01-19 15:24:40 +09001332 port->line, s->cfg->dma_dev);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001333
Paul Mundtce6738b2011-01-19 15:24:40 +09001334 if (!s->cfg->dma_dev)
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001335 return;
1336
1337 dma_cap_zero(mask);
1338 dma_cap_set(DMA_SLAVE, mask);
1339
1340 param = &s->param_tx;
1341
1342 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_TX */
Paul Mundtce6738b2011-01-19 15:24:40 +09001343 param->slave_id = s->cfg->dma_slave_tx;
1344 param->dma_dev = s->cfg->dma_dev;
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001345
1346 s->cookie_tx = -EINVAL;
1347 chan = dma_request_channel(mask, filter, param);
1348 dev_dbg(port->dev, "%s: TX: got channel %p\n", __func__, chan);
1349 if (chan) {
1350 s->chan_tx = chan;
1351 sg_init_table(&s->sg_tx, 1);
1352 /* UART circular tx buffer is an aligned page. */
1353 BUG_ON((int)port->state->xmit.buf & ~PAGE_MASK);
1354 sg_set_page(&s->sg_tx, virt_to_page(port->state->xmit.buf),
1355 UART_XMIT_SIZE, (int)port->state->xmit.buf & ~PAGE_MASK);
1356 nent = dma_map_sg(port->dev, &s->sg_tx, 1, DMA_TO_DEVICE);
1357 if (!nent)
1358 sci_tx_dma_release(s, false);
1359 else
1360 dev_dbg(port->dev, "%s: mapped %d@%p to %x\n", __func__,
1361 sg_dma_len(&s->sg_tx),
1362 port->state->xmit.buf, sg_dma_address(&s->sg_tx));
1363
1364 s->sg_len_tx = nent;
1365
1366 INIT_WORK(&s->work_tx, work_fn_tx);
1367 }
1368
1369 param = &s->param_rx;
1370
1371 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_RX */
Paul Mundtce6738b2011-01-19 15:24:40 +09001372 param->slave_id = s->cfg->dma_slave_rx;
1373 param->dma_dev = s->cfg->dma_dev;
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001374
1375 chan = dma_request_channel(mask, filter, param);
1376 dev_dbg(port->dev, "%s: RX: got channel %p\n", __func__, chan);
1377 if (chan) {
1378 dma_addr_t dma[2];
1379 void *buf[2];
1380 int i;
1381
1382 s->chan_rx = chan;
1383
1384 s->buf_len_rx = 2 * max(16, (int)port->fifosize);
1385 buf[0] = dma_alloc_coherent(port->dev, s->buf_len_rx * 2,
1386 &dma[0], GFP_KERNEL);
1387
1388 if (!buf[0]) {
1389 dev_warn(port->dev,
1390 "failed to allocate dma buffer, using PIO\n");
1391 sci_rx_dma_release(s, true);
1392 return;
1393 }
1394
1395 buf[1] = buf[0] + s->buf_len_rx;
1396 dma[1] = dma[0] + s->buf_len_rx;
1397
1398 for (i = 0; i < 2; i++) {
1399 struct scatterlist *sg = &s->sg_rx[i];
1400
1401 sg_init_table(sg, 1);
1402 sg_set_page(sg, virt_to_page(buf[i]), s->buf_len_rx,
1403 (int)buf[i] & ~PAGE_MASK);
Magnus Dammf354a382010-03-19 04:47:01 +00001404 sg_dma_address(sg) = dma[i];
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001405 }
1406
1407 INIT_WORK(&s->work_rx, work_fn_rx);
1408 setup_timer(&s->rx_timer, rx_timer_fn, (unsigned long)s);
1409
1410 sci_submit_rx(s);
1411 }
1412}
1413
1414static void sci_free_dma(struct uart_port *port)
1415{
1416 struct sci_port *s = to_sci_port(port);
1417
Paul Mundtce6738b2011-01-19 15:24:40 +09001418 if (!s->cfg->dma_dev)
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001419 return;
1420
1421 if (s->chan_tx)
1422 sci_tx_dma_release(s, false);
1423 if (s->chan_rx)
1424 sci_rx_dma_release(s, false);
1425}
Paul Mundt27bd1072011-01-19 15:37:31 +09001426#else
1427static inline void sci_request_dma(struct uart_port *port)
1428{
1429}
1430
1431static inline void sci_free_dma(struct uart_port *port)
1432{
1433}
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001434#endif
1435
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436static int sci_startup(struct uart_port *port)
1437{
Magnus Damma5660ad2009-01-21 15:14:38 +00001438 struct sci_port *s = to_sci_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001440 dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
1441
Paul Mundte108b2c2006-09-27 16:32:13 +09001442 if (s->enable)
1443 s->enable(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
1445 sci_request_irq(s);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001446 sci_request_dma(port);
Yoshinori Satod6569012005-10-14 15:59:12 -07001447 sci_start_tx(port);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001448 sci_start_rx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
1450 return 0;
1451}
1452
1453static void sci_shutdown(struct uart_port *port)
1454{
Magnus Damma5660ad2009-01-21 15:14:38 +00001455 struct sci_port *s = to_sci_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001457 dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
1458
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 sci_stop_rx(port);
Russell Kingb129a8c2005-08-31 10:12:14 +01001460 sci_stop_tx(port);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001461 sci_free_dma(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 sci_free_irq(s);
1463
Paul Mundte108b2c2006-09-27 16:32:13 +09001464 if (s->disable)
1465 s->disable(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466}
1467
Paul Mundt26c92f32009-06-24 18:23:52 +09001468static unsigned int sci_scbrr_calc(unsigned int algo_id, unsigned int bps,
1469 unsigned long freq)
1470{
1471 switch (algo_id) {
1472 case SCBRR_ALGO_1:
1473 return ((freq + 16 * bps) / (16 * bps) - 1);
1474 case SCBRR_ALGO_2:
1475 return ((freq + 16 * bps) / (32 * bps) - 1);
1476 case SCBRR_ALGO_3:
1477 return (((freq * 2) + 16 * bps) / (16 * bps) - 1);
1478 case SCBRR_ALGO_4:
1479 return (((freq * 2) + 16 * bps) / (32 * bps) - 1);
1480 case SCBRR_ALGO_5:
1481 return (((freq * 1000 / 32) / bps) - 1);
1482 }
1483
1484 /* Warn, but use a safe default */
1485 WARN_ON(1);
1486 return ((freq + 16 * bps) / (32 * bps) - 1);
1487}
1488
Alan Cox606d0992006-12-08 02:38:45 -08001489static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
1490 struct ktermios *old)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Paul Mundt00b9de92009-06-24 17:53:33 +09001492 struct sci_port *s = to_sci_port(port);
Magnus Damm154280f2009-12-22 03:37:28 +00001493 unsigned int status, baud, smr_val, max_baud;
Paul Mundta2159b52008-10-02 19:09:13 +09001494 int t = -1;
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001495 u16 scfcr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Magnus Damm154280f2009-12-22 03:37:28 +00001497 /*
1498 * earlyprintk comes here early on with port->uartclk set to zero.
1499 * the clock framework is not up and running at this point so here
1500 * we assume that 115200 is the maximum baud rate. please note that
1501 * the baud rate is not programmed during earlyprintk - it is assumed
1502 * that the previous boot loader has enabled required clocks and
1503 * setup the baud rate generator hardware for us already.
1504 */
1505 max_baud = port->uartclk ? port->uartclk / 16 : 115200;
1506
1507 baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
1508 if (likely(baud && port->uartclk))
Paul Mundtce6738b2011-01-19 15:24:40 +09001509 t = sci_scbrr_calc(s->cfg->scbrr_algo_id, baud, port->uartclk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Paul Mundte108b2c2006-09-27 16:32:13 +09001511 do {
1512 status = sci_in(port, SCxSR);
1513 } while (!(status & SCxSR_TEND(port)));
1514
1515 sci_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */
1516
Yoshihiro Shimoda1a22f082008-11-11 12:19:05 +09001517 if (port->type != PORT_SCI)
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001518 sci_out(port, SCFCR, scfcr | SCFCR_RFRST | SCFCR_TFRST);
Paul Mundte108b2c2006-09-27 16:32:13 +09001519
1520 smr_val = sci_in(port, SCSMR) & 3;
1521 if ((termios->c_cflag & CSIZE) == CS7)
1522 smr_val |= 0x40;
1523 if (termios->c_cflag & PARENB)
1524 smr_val |= 0x20;
1525 if (termios->c_cflag & PARODD)
1526 smr_val |= 0x30;
1527 if (termios->c_cflag & CSTOPB)
1528 smr_val |= 0x08;
1529
1530 uart_update_timeout(port, termios->c_cflag, baud);
1531
1532 sci_out(port, SCSMR, smr_val);
1533
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001534 dev_dbg(port->dev, "%s: SMR %x, t %x, SCSCR %x\n", __func__, smr_val, t,
Paul Mundtce6738b2011-01-19 15:24:40 +09001535 s->cfg->scscr);
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001536
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 if (t > 0) {
Michael Trimarchie7c98dc2008-11-13 18:18:35 +09001538 if (t >= 256) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1);
1540 t >>= 2;
Michael Trimarchie7c98dc2008-11-13 18:18:35 +09001541 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3);
Michael Trimarchie7c98dc2008-11-13 18:18:35 +09001543
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 sci_out(port, SCBRR, t);
1545 udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
1546 }
1547
Paul Mundtd5701642008-12-16 20:07:27 +09001548 sci_init_pins(port, termios->c_cflag);
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001549 sci_out(port, SCFCR, scfcr | ((termios->c_cflag & CRTSCTS) ? SCFCR_MCE : 0));
Paul Mundtb7a76e42006-02-01 03:06:06 -08001550
Paul Mundtce6738b2011-01-19 15:24:40 +09001551 sci_out(port, SCSCR, s->cfg->scscr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Guennadi Liakhovetski3089f382010-03-19 13:53:04 +00001553#ifdef CONFIG_SERIAL_SH_SCI_DMA
1554 /*
1555 * Calculate delay for 1.5 DMA buffers: see
1556 * drivers/serial/serial_core.c::uart_update_timeout(). With 10 bits
1557 * (CS8), 250Hz, 115200 baud and 64 bytes FIFO, the above function
1558 * calculates 1 jiffie for the data plus 5 jiffies for the "slop(e)."
1559 * Then below we calculate 3 jiffies (12ms) for 1.5 DMA buffers (3 FIFO
1560 * sizes), but it has been found out experimentally, that this is not
1561 * enough: the driver too often needlessly runs on a DMA timeout. 20ms
1562 * as a minimum seem to work perfectly.
1563 */
1564 if (s->chan_rx) {
1565 s->rx_timeout = (port->timeout - HZ / 50) * s->buf_len_rx * 3 /
1566 port->fifosize / 2;
1567 dev_dbg(port->dev,
1568 "DMA Rx t-out %ums, tty t-out %u jiffies\n",
1569 s->rx_timeout * 1000 / HZ, port->timeout);
1570 if (s->rx_timeout < msecs_to_jiffies(20))
1571 s->rx_timeout = msecs_to_jiffies(20);
1572 }
1573#endif
1574
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 if ((termios->c_cflag & CREAD) != 0)
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001576 sci_start_rx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
1579static const char *sci_type(struct uart_port *port)
1580{
1581 switch (port->type) {
Michael Trimarchie7c98dc2008-11-13 18:18:35 +09001582 case PORT_IRDA:
1583 return "irda";
1584 case PORT_SCI:
1585 return "sci";
1586 case PORT_SCIF:
1587 return "scif";
1588 case PORT_SCIFA:
1589 return "scifa";
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +00001590 case PORT_SCIFB:
1591 return "scifb";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 }
1593
Paul Mundtfa439722008-09-04 18:53:58 +09001594 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595}
1596
1597static void sci_release_port(struct uart_port *port)
1598{
1599 /* Nothing here yet .. */
1600}
1601
1602static int sci_request_port(struct uart_port *port)
1603{
1604 /* Nothing here yet .. */
1605 return 0;
1606}
1607
1608static void sci_config_port(struct uart_port *port, int flags)
1609{
Magnus Damma5660ad2009-01-21 15:14:38 +00001610 struct sci_port *s = to_sci_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
Paul Mundtce6738b2011-01-19 15:24:40 +09001612 port->type = s->cfg->type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Magnus Damm08f8cb32009-01-21 15:14:22 +00001614 if (port->flags & UPF_IOREMAP) {
Paul Mundt7ff731a2008-10-01 15:46:58 +09001615 port->membase = ioremap_nocache(port->mapbase, 0x40);
Magnus Damm08f8cb32009-01-21 15:14:22 +00001616
1617 if (IS_ERR(port->membase))
1618 dev_err(port->dev, "can't remap port#%d\n", port->line);
1619 } else {
1620 /*
1621 * For the simple (and majority of) cases where we don't
1622 * need to do any remapping, just cast the cookie
1623 * directly.
1624 */
1625 port->membase = (void __iomem *)port->mapbase;
Paul Mundt7ff731a2008-10-01 15:46:58 +09001626 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
1629static int sci_verify_port(struct uart_port *port, struct serial_struct *ser)
1630{
Magnus Damma5660ad2009-01-21 15:14:38 +00001631 struct sci_port *s = to_sci_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
Paul Mundtce6738b2011-01-19 15:24:40 +09001633 if (ser->irq != s->cfg->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 return -EINVAL;
1635 if (ser->baud_base < 2400)
1636 /* No paper tape reader for Mitch.. */
1637 return -EINVAL;
1638
1639 return 0;
1640}
1641
1642static struct uart_ops sci_uart_ops = {
1643 .tx_empty = sci_tx_empty,
1644 .set_mctrl = sci_set_mctrl,
1645 .get_mctrl = sci_get_mctrl,
1646 .start_tx = sci_start_tx,
1647 .stop_tx = sci_stop_tx,
1648 .stop_rx = sci_stop_rx,
1649 .enable_ms = sci_enable_ms,
1650 .break_ctl = sci_break_ctl,
1651 .startup = sci_startup,
1652 .shutdown = sci_shutdown,
1653 .set_termios = sci_set_termios,
1654 .type = sci_type,
1655 .release_port = sci_release_port,
1656 .request_port = sci_request_port,
1657 .config_port = sci_config_port,
1658 .verify_port = sci_verify_port,
Paul Mundt07d2a1a2008-12-11 19:06:43 +09001659#ifdef CONFIG_CONSOLE_POLL
1660 .poll_get_char = sci_poll_get_char,
1661 .poll_put_char = sci_poll_put_char,
1662#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663};
1664
Paul Mundtc7ed1ab2010-03-10 18:35:14 +09001665static int __devinit sci_init_single(struct platform_device *dev,
1666 struct sci_port *sci_port,
1667 unsigned int index,
1668 struct plat_sci_port *p)
Paul Mundte108b2c2006-09-27 16:32:13 +09001669{
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001670 struct uart_port *port = &sci_port->port;
Paul Mundte108b2c2006-09-27 16:32:13 +09001671
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001672 port->ops = &sci_uart_ops;
1673 port->iotype = UPIO_MEM;
1674 port->line = index;
Markus Pietrek75136d42010-01-15 08:33:20 +09001675
1676 switch (p->type) {
Guennadi Liakhovetskid1d4b102010-05-23 16:39:09 +00001677 case PORT_SCIFB:
1678 port->fifosize = 256;
1679 break;
Markus Pietrek75136d42010-01-15 08:33:20 +09001680 case PORT_SCIFA:
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001681 port->fifosize = 64;
Markus Pietrek75136d42010-01-15 08:33:20 +09001682 break;
1683 case PORT_SCIF:
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001684 port->fifosize = 16;
Markus Pietrek75136d42010-01-15 08:33:20 +09001685 break;
1686 default:
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001687 port->fifosize = 1;
Markus Pietrek75136d42010-01-15 08:33:20 +09001688 break;
1689 }
Magnus Damm7b6fd3b2009-12-14 10:24:42 +00001690
1691 if (dev) {
Paul Mundtc7ed1ab2010-03-10 18:35:14 +09001692 sci_port->iclk = clk_get(&dev->dev, "sci_ick");
1693 if (IS_ERR(sci_port->iclk)) {
1694 sci_port->iclk = clk_get(&dev->dev, "peripheral_clk");
1695 if (IS_ERR(sci_port->iclk)) {
1696 dev_err(&dev->dev, "can't get iclk\n");
1697 return PTR_ERR(sci_port->iclk);
1698 }
1699 }
1700
1701 /*
1702 * The function clock is optional, ignore it if we can't
1703 * find it.
1704 */
1705 sci_port->fclk = clk_get(&dev->dev, "sci_fck");
1706 if (IS_ERR(sci_port->fclk))
1707 sci_port->fclk = NULL;
1708
Magnus Damm7b6fd3b2009-12-14 10:24:42 +00001709 sci_port->enable = sci_clk_enable;
1710 sci_port->disable = sci_clk_disable;
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001711 port->dev = &dev->dev;
Magnus Damm7b6fd3b2009-12-14 10:24:42 +00001712 }
Paul Mundte108b2c2006-09-27 16:32:13 +09001713
Magnus Damm7ed7e072009-01-21 15:14:14 +00001714 sci_port->break_timer.data = (unsigned long)sci_port;
1715 sci_port->break_timer.function = sci_break_timer;
1716 init_timer(&sci_port->break_timer);
Paul Mundte108b2c2006-09-27 16:32:13 +09001717
Paul Mundtce6738b2011-01-19 15:24:40 +09001718 sci_port->cfg = p;
Magnus Damm7ed7e072009-01-21 15:14:14 +00001719
Paul Mundtce6738b2011-01-19 15:24:40 +09001720 port->mapbase = p->mapbase;
1721 port->type = p->type;
Paul Mundtf43dc232011-01-13 15:06:28 +09001722 port->flags = p->flags;
Paul Mundtce6738b2011-01-19 15:24:40 +09001723
1724 /*
1725 * The UART port needs an IRQ value, so we peg this to the TX IRQ
1726 * for the multi-IRQ ports, which is where we are primarily
1727 * concerned with the shutdown path synchronization.
1728 *
1729 * For the muxed case there's nothing more to do.
1730 */
1731 port->irq = p->irqs[SCIx_TXI_IRQ];
Guennadi Liakhovetski73a19e42010-03-02 11:39:15 +09001732
Paul Mundtce6738b2011-01-19 15:24:40 +09001733 if (p->dma_dev)
1734 dev_dbg(port->dev, "DMA device %p, tx %d, rx %d\n",
1735 p->dma_dev, p->dma_slave_tx, p->dma_slave_rx);
Magnus Damm7ed7e072009-01-21 15:14:14 +00001736
Paul Mundtc7ed1ab2010-03-10 18:35:14 +09001737 return 0;
Paul Mundte108b2c2006-09-27 16:32:13 +09001738}
1739
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
Magnus Dammdc8e6f52009-01-21 15:14:06 +00001741static struct tty_driver *serial_console_device(struct console *co, int *index)
1742{
1743 struct uart_driver *p = &sci_uart_driver;
1744 *index = co->index;
1745 return p->tty_driver;
1746}
1747
1748static void serial_console_putchar(struct uart_port *port, int ch)
1749{
1750 sci_poll_put_char(port, ch);
1751}
1752
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753/*
1754 * Print a string to the serial port trying not to disturb
1755 * any possible real use of the port...
1756 */
1757static void serial_console_write(struct console *co, const char *s,
1758 unsigned count)
1759{
Magnus Dammdc8e6f52009-01-21 15:14:06 +00001760 struct uart_port *port = co->data;
Magnus Damm501b8252009-01-21 15:14:30 +00001761 struct sci_port *sci_port = to_sci_port(port);
Magnus Damm973e5d52009-02-24 15:57:12 +09001762 unsigned short bits;
Paul Mundt07d2a1a2008-12-11 19:06:43 +09001763
Magnus Damm501b8252009-01-21 15:14:30 +00001764 if (sci_port->enable)
1765 sci_port->enable(port);
1766
1767 uart_console_write(port, s, count, serial_console_putchar);
Magnus Damm973e5d52009-02-24 15:57:12 +09001768
1769 /* wait until fifo is empty and last bit has been transmitted */
1770 bits = SCxSR_TDxE(port) | SCxSR_TEND(port);
1771 while ((sci_in(port, SCxSR) & bits) != bits)
1772 cpu_relax();
Magnus Damm501b8252009-01-21 15:14:30 +00001773
Magnus Damm345e5a72009-11-05 14:34:57 +00001774 if (sci_port->disable)
Magnus Damm501b8252009-01-21 15:14:30 +00001775 sci_port->disable(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776}
1777
Magnus Damm7b6fd3b2009-12-14 10:24:42 +00001778static int __devinit serial_console_setup(struct console *co, char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779{
Magnus Dammdc8e6f52009-01-21 15:14:06 +00001780 struct sci_port *sci_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 struct uart_port *port;
1782 int baud = 115200;
1783 int bits = 8;
1784 int parity = 'n';
1785 int flow = 'n';
1786 int ret;
1787
Paul Mundte108b2c2006-09-27 16:32:13 +09001788 /*
1789 * Check whether an invalid uart number has been specified, and
1790 * if so, search for the first available port that does have
1791 * console support.
1792 */
1793 if (co->index >= SCI_NPORTS)
1794 co->index = 0;
1795
Magnus Damm7b6fd3b2009-12-14 10:24:42 +00001796 if (co->data) {
1797 port = co->data;
1798 sci_port = to_sci_port(port);
1799 } else {
1800 sci_port = &sci_ports[co->index];
1801 port = &sci_port->port;
1802 co->data = port;
1803 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805 /*
Paul Mundte108b2c2006-09-27 16:32:13 +09001806 * Also need to check port->type, we don't actually have any
1807 * UPIO_PORT ports, but uart_report_port() handily misreports
1808 * it anyways if we don't have a port available by the time this is
1809 * called.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 */
Paul Mundte108b2c2006-09-27 16:32:13 +09001811 if (!port->type)
1812 return -ENODEV;
Paul Mundte108b2c2006-09-27 16:32:13 +09001813
Magnus Damm08f8cb32009-01-21 15:14:22 +00001814 sci_config_port(port, 0);
Paul Mundte108b2c2006-09-27 16:32:13 +09001815
Magnus Dammdc8e6f52009-01-21 15:14:06 +00001816 if (sci_port->enable)
1817 sci_port->enable(port);
Paul Mundte108b2c2006-09-27 16:32:13 +09001818
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 if (options)
1820 uart_parse_options(options, &baud, &parity, &bits, &flow);
1821
1822 ret = uart_set_options(port, co, baud, parity, bits, flow);
1823#if defined(__H8300H__) || defined(__H8300S__)
1824 /* disable rx interrupt */
1825 if (ret == 0)
1826 sci_stop_rx(port);
1827#endif
Magnus Damm501b8252009-01-21 15:14:30 +00001828 /* TODO: disable clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 return ret;
1830}
1831
1832static struct console serial_console = {
1833 .name = "ttySC",
Magnus Dammdc8e6f52009-01-21 15:14:06 +00001834 .device = serial_console_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 .write = serial_console_write,
1836 .setup = serial_console_setup,
Paul Mundtfa5da2f2007-03-08 17:27:37 +09001837 .flags = CON_PRINTBUFFER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 .index = -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839};
1840
1841static int __init sci_console_init(void)
1842{
1843 register_console(&serial_console);
1844 return 0;
1845}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846console_initcall(sci_console_init);
Magnus Damm7b6fd3b2009-12-14 10:24:42 +00001847
1848static struct sci_port early_serial_port;
1849static struct console early_serial_console = {
1850 .name = "early_ttySC",
1851 .write = serial_console_write,
1852 .flags = CON_PRINTBUFFER,
1853};
1854static char early_serial_buf[32];
1855
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856#endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
1857
Paul Mundt07d2a1a2008-12-11 19:06:43 +09001858#if defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
Michael Trimarchie7c98dc2008-11-13 18:18:35 +09001859#define SCI_CONSOLE (&serial_console)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860#else
Paul Mundtb7a76e42006-02-01 03:06:06 -08001861#define SCI_CONSOLE 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862#endif
1863
1864static char banner[] __initdata =
1865 KERN_INFO "SuperH SCI(F) driver initialized\n";
1866
1867static struct uart_driver sci_uart_driver = {
1868 .owner = THIS_MODULE,
1869 .driver_name = "sci",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 .dev_name = "ttySC",
1871 .major = SCI_MAJOR,
1872 .minor = SCI_MINOR_START,
Paul Mundte108b2c2006-09-27 16:32:13 +09001873 .nr = SCI_NPORTS,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 .cons = SCI_CONSOLE,
1875};
1876
Magnus Damme552de22009-01-21 15:13:42 +00001877
Paul Mundt54507f62009-05-08 23:48:33 +09001878static int sci_remove(struct platform_device *dev)
Magnus Damme552de22009-01-21 15:13:42 +00001879{
1880 struct sh_sci_priv *priv = platform_get_drvdata(dev);
1881 struct sci_port *p;
1882 unsigned long flags;
1883
Magnus Damme552de22009-01-21 15:13:42 +00001884 cpufreq_unregister_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
Magnus Damme552de22009-01-21 15:13:42 +00001885
1886 spin_lock_irqsave(&priv->lock, flags);
Paul Mundtc7ed1ab2010-03-10 18:35:14 +09001887 list_for_each_entry(p, &priv->ports, node) {
Magnus Damme552de22009-01-21 15:13:42 +00001888 uart_remove_one_port(&sci_uart_driver, &p->port);
Paul Mundtc7ed1ab2010-03-10 18:35:14 +09001889 clk_put(p->iclk);
1890 clk_put(p->fclk);
1891 }
Magnus Damme552de22009-01-21 15:13:42 +00001892 spin_unlock_irqrestore(&priv->lock, flags);
1893
1894 kfree(priv);
1895 return 0;
1896}
1897
Magnus Damm0ee70712009-01-21 15:13:50 +00001898static int __devinit sci_probe_single(struct platform_device *dev,
1899 unsigned int index,
1900 struct plat_sci_port *p,
1901 struct sci_port *sciport)
1902{
1903 struct sh_sci_priv *priv = platform_get_drvdata(dev);
1904 unsigned long flags;
1905 int ret;
1906
1907 /* Sanity check */
1908 if (unlikely(index >= SCI_NPORTS)) {
1909 dev_notice(&dev->dev, "Attempting to register port "
1910 "%d when only %d are available.\n",
1911 index+1, SCI_NPORTS);
1912 dev_notice(&dev->dev, "Consider bumping "
1913 "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n");
1914 return 0;
1915 }
1916
Paul Mundtc7ed1ab2010-03-10 18:35:14 +09001917 ret = sci_init_single(dev, sciport, index, p);
1918 if (ret)
1919 return ret;
Magnus Damm0ee70712009-01-21 15:13:50 +00001920
1921 ret = uart_add_one_port(&sci_uart_driver, &sciport->port);
Magnus Damm08f8cb32009-01-21 15:14:22 +00001922 if (ret)
Magnus Damm0ee70712009-01-21 15:13:50 +00001923 return ret;
Magnus Damm0ee70712009-01-21 15:13:50 +00001924
1925 INIT_LIST_HEAD(&sciport->node);
1926
1927 spin_lock_irqsave(&priv->lock, flags);
1928 list_add(&sciport->node, &priv->ports);
1929 spin_unlock_irqrestore(&priv->lock, flags);
1930
1931 return 0;
1932}
1933
Paul Mundte108b2c2006-09-27 16:32:13 +09001934/*
1935 * Register a set of serial devices attached to a platform device. The
1936 * list is terminated with a zero flags entry, which means we expect
1937 * all entries to have at least UPF_BOOT_AUTOCONF set. Platforms that need
1938 * remapping (such as sh64) should also set UPF_IOREMAP.
1939 */
1940static int __devinit sci_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941{
Paul Mundte108b2c2006-09-27 16:32:13 +09001942 struct plat_sci_port *p = dev->dev.platform_data;
Magnus Damme552de22009-01-21 15:13:42 +00001943 struct sh_sci_priv *priv;
Paul Mundt7ff731a2008-10-01 15:46:58 +09001944 int i, ret = -EINVAL;
Magnus Damme552de22009-01-21 15:13:42 +00001945
Magnus Damm7b6fd3b2009-12-14 10:24:42 +00001946#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
1947 if (is_early_platform_device(dev)) {
1948 if (dev->id == -1)
1949 return -ENOTSUPP;
1950 early_serial_console.index = dev->id;
1951 early_serial_console.data = &early_serial_port.port;
1952 sci_init_single(NULL, &early_serial_port, dev->id, p);
1953 serial_console_setup(&early_serial_console, early_serial_buf);
1954 if (!strstr(early_serial_buf, "keep"))
1955 early_serial_console.flags |= CON_BOOT;
1956 register_console(&early_serial_console);
1957 return 0;
1958 }
1959#endif
1960
Magnus Damme552de22009-01-21 15:13:42 +00001961 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1962 if (!priv)
1963 return -ENOMEM;
1964
1965 INIT_LIST_HEAD(&priv->ports);
1966 spin_lock_init(&priv->lock);
1967 platform_set_drvdata(dev, priv);
1968
Magnus Damme552de22009-01-21 15:13:42 +00001969 priv->clk_nb.notifier_call = sci_notifier;
1970 cpufreq_register_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971
Magnus Damm0ee70712009-01-21 15:13:50 +00001972 if (dev->id != -1) {
1973 ret = sci_probe_single(dev, dev->id, p, &sci_ports[dev->id]);
1974 if (ret)
Magnus Damme552de22009-01-21 15:13:42 +00001975 goto err_unreg;
Magnus Damm0ee70712009-01-21 15:13:50 +00001976 } else {
1977 for (i = 0; p && p->flags != 0; p++, i++) {
1978 ret = sci_probe_single(dev, i, p, &sci_ports[i]);
1979 if (ret)
1980 goto err_unreg;
Magnus Damme552de22009-01-21 15:13:42 +00001981 }
Magnus Damme552de22009-01-21 15:13:42 +00001982 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
1984#ifdef CONFIG_SH_STANDARD_BIOS
1985 sh_bios_gdb_detach();
1986#endif
1987
Paul Mundte108b2c2006-09-27 16:32:13 +09001988 return 0;
Paul Mundt7ff731a2008-10-01 15:46:58 +09001989
1990err_unreg:
Magnus Damme552de22009-01-21 15:13:42 +00001991 sci_remove(dev);
Paul Mundt7ff731a2008-10-01 15:46:58 +09001992 return ret;
Paul Mundte108b2c2006-09-27 16:32:13 +09001993}
1994
Paul Mundt6daa79b2009-06-15 07:07:38 +09001995static int sci_suspend(struct device *dev)
Paul Mundte108b2c2006-09-27 16:32:13 +09001996{
Paul Mundt6daa79b2009-06-15 07:07:38 +09001997 struct sh_sci_priv *priv = dev_get_drvdata(dev);
Magnus Damme552de22009-01-21 15:13:42 +00001998 struct sci_port *p;
1999 unsigned long flags;
Paul Mundte108b2c2006-09-27 16:32:13 +09002000
Magnus Damme552de22009-01-21 15:13:42 +00002001 spin_lock_irqsave(&priv->lock, flags);
2002 list_for_each_entry(p, &priv->ports, node)
2003 uart_suspend_port(&sci_uart_driver, &p->port);
Magnus Damme552de22009-01-21 15:13:42 +00002004 spin_unlock_irqrestore(&priv->lock, flags);
Paul Mundte108b2c2006-09-27 16:32:13 +09002005
2006 return 0;
2007}
2008
Paul Mundt6daa79b2009-06-15 07:07:38 +09002009static int sci_resume(struct device *dev)
Paul Mundte108b2c2006-09-27 16:32:13 +09002010{
Paul Mundt6daa79b2009-06-15 07:07:38 +09002011 struct sh_sci_priv *priv = dev_get_drvdata(dev);
Magnus Damme552de22009-01-21 15:13:42 +00002012 struct sci_port *p;
2013 unsigned long flags;
Paul Mundte108b2c2006-09-27 16:32:13 +09002014
Magnus Damme552de22009-01-21 15:13:42 +00002015 spin_lock_irqsave(&priv->lock, flags);
2016 list_for_each_entry(p, &priv->ports, node)
2017 uart_resume_port(&sci_uart_driver, &p->port);
Magnus Damme552de22009-01-21 15:13:42 +00002018 spin_unlock_irqrestore(&priv->lock, flags);
Paul Mundte108b2c2006-09-27 16:32:13 +09002019
2020 return 0;
2021}
2022
Alexey Dobriyan47145212009-12-14 18:00:08 -08002023static const struct dev_pm_ops sci_dev_pm_ops = {
Paul Mundt6daa79b2009-06-15 07:07:38 +09002024 .suspend = sci_suspend,
2025 .resume = sci_resume,
2026};
2027
Paul Mundte108b2c2006-09-27 16:32:13 +09002028static struct platform_driver sci_driver = {
2029 .probe = sci_probe,
Uwe Kleine-Königb9e39c82009-11-24 22:07:32 +01002030 .remove = sci_remove,
Paul Mundte108b2c2006-09-27 16:32:13 +09002031 .driver = {
2032 .name = "sh-sci",
2033 .owner = THIS_MODULE,
Paul Mundt6daa79b2009-06-15 07:07:38 +09002034 .pm = &sci_dev_pm_ops,
Paul Mundte108b2c2006-09-27 16:32:13 +09002035 },
2036};
2037
2038static int __init sci_init(void)
2039{
2040 int ret;
2041
2042 printk(banner);
2043
Paul Mundte108b2c2006-09-27 16:32:13 +09002044 ret = uart_register_driver(&sci_uart_driver);
2045 if (likely(ret == 0)) {
2046 ret = platform_driver_register(&sci_driver);
2047 if (unlikely(ret))
2048 uart_unregister_driver(&sci_uart_driver);
2049 }
2050
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 return ret;
2052}
2053
2054static void __exit sci_exit(void)
2055{
Paul Mundte108b2c2006-09-27 16:32:13 +09002056 platform_driver_unregister(&sci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 uart_unregister_driver(&sci_uart_driver);
2058}
2059
Magnus Damm7b6fd3b2009-12-14 10:24:42 +00002060#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
2061early_platform_init_buffer("earlyprintk", &sci_driver,
2062 early_serial_buf, ARRAY_SIZE(early_serial_buf));
2063#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064module_init(sci_init);
2065module_exit(sci_exit);
2066
Paul Mundte108b2c2006-09-27 16:32:13 +09002067MODULE_LICENSE("GPL");
Kay Sieverse169c132008-04-15 14:34:35 -07002068MODULE_ALIAS("platform:sh-sci");