Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/serial/sh-sci.c |
| 3 | * |
| 4 | * SuperH on-chip serial module support. (SCI with no FIFO / with FIFO) |
| 5 | * |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 6 | * Copyright (C) 2002 - 2008 Paul Mundt |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 7 | * Modified to support SH7720 SCIF. Markus Brunner, Mark Jonas (Jul 2007). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 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 Damm | d89ddd1 | 2007-07-25 11:42:56 +0900 | [diff] [blame] | 16 | * Removed SH7300 support (Jul 2007). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * |
| 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 Mundt | 0b3d4ef | 2007-03-14 13:22:37 +0900 | [diff] [blame] | 22 | #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 23 | #define SUPPORT_SYSRQ |
| 24 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #undef DEBUG |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/ioport.h> |
| 39 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/init.h> |
| 41 | #include <linux/delay.h> |
| 42 | #include <linux/console.h> |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 43 | #include <linux/platform_device.h> |
Paul Mundt | 96de1a8 | 2008-02-26 14:52:45 +0900 | [diff] [blame] | 44 | #include <linux/serial_sci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/notifier.h> |
| 46 | #include <linux/cpufreq.h> |
Paul Mundt | 85f094e | 2008-04-25 16:04:20 +0900 | [diff] [blame] | 47 | #include <linux/clk.h> |
Paul Mundt | fa5da2f | 2007-03-08 17:27:37 +0900 | [diff] [blame] | 48 | #include <linux/ctype.h> |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 49 | #include <linux/err.h> |
Paul Mundt | 85f094e | 2008-04-25 16:04:20 +0900 | [diff] [blame] | 50 | |
| 51 | #ifdef CONFIG_SUPERH |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 52 | #include <asm/clock.h> |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 53 | #include <asm/sh_bios.h> |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 54 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include "sh-sci.h" |
| 57 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 58 | struct sci_port { |
| 59 | struct uart_port port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 61 | /* Port type */ |
| 62 | unsigned int type; |
| 63 | |
| 64 | /* Port IRQs: ERI, RXI, TXI, BRI (optional) */ |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 65 | unsigned int irqs[SCIx_NR_IRQS]; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 66 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 67 | /* Port enable callback */ |
| 68 | void (*enable)(struct uart_port *port); |
| 69 | |
| 70 | /* Port disable callback */ |
| 71 | void (*disable)(struct uart_port *port); |
| 72 | |
| 73 | /* Break timer */ |
| 74 | struct timer_list break_timer; |
| 75 | int break_flag; |
dmitry pervushin | 1534a3b | 2007-04-24 13:41:12 +0900 | [diff] [blame] | 76 | |
Paul Mundt | a2159b5 | 2008-10-02 19:09:13 +0900 | [diff] [blame] | 77 | #ifdef CONFIG_HAVE_CLK |
dmitry pervushin | 1534a3b | 2007-04-24 13:41:12 +0900 | [diff] [blame] | 78 | /* Port clock */ |
| 79 | struct clk *clk; |
Paul Mundt | 005a336 | 2007-04-26 11:45:32 +0900 | [diff] [blame] | 80 | #endif |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 81 | }; |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 84 | static struct sci_port *serial_console_port; |
| 85 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | /* Function prototypes */ |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 88 | static void sci_stop_tx(struct uart_port *port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 90 | #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS |
| 91 | |
| 92 | static struct sci_port sci_ports[SCI_NPORTS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | static struct uart_driver sci_uart_driver; |
| 94 | |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 95 | static inline struct sci_port * |
| 96 | to_sci_port(struct uart_port *uart) |
| 97 | { |
| 98 | return container_of(uart, struct sci_port, port); |
| 99 | } |
| 100 | |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 101 | #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_SH_SCI_CONSOLE) |
Paul Mundt | 1f6fd5c | 2008-12-17 14:53:24 +0900 | [diff] [blame] | 102 | |
| 103 | #ifdef CONFIG_CONSOLE_POLL |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 104 | static inline void handle_error(struct uart_port *port) |
| 105 | { |
| 106 | /* Clear error flags */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port)); |
| 108 | } |
| 109 | |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 110 | static int sci_poll_get_char(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | unsigned short status; |
| 113 | int c; |
| 114 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 115 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | status = sci_in(port, SCxSR); |
| 117 | if (status & SCxSR_ERRORS(port)) { |
| 118 | handle_error(port); |
| 119 | continue; |
| 120 | } |
| 121 | } while (!(status & SCxSR_RDxF(port))); |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | c = sci_in(port, SCxRDR); |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 124 | |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 125 | /* Dummy read */ |
| 126 | sci_in(port, SCxSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | return c; |
| 130 | } |
Paul Mundt | 1f6fd5c | 2008-12-17 14:53:24 +0900 | [diff] [blame] | 131 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 133 | static void sci_poll_put_char(struct uart_port *port, unsigned char c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | unsigned short status; |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | do { |
| 138 | status = sci_in(port, SCxSR); |
| 139 | } while (!(status & SCxSR_TDxE(port))); |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | sci_in(port, SCxSR); /* Dummy read */ |
Magnus Damm | 973e5d5 | 2009-02-24 15:57:12 +0900 | [diff] [blame^] | 142 | sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port)); |
Paul Mundt | 272966c | 2008-11-13 17:46:06 +0900 | [diff] [blame] | 143 | sci_out(port, SCxTDR, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 145 | #endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | #if defined(__H8300S__) |
| 148 | enum { sci_disable, sci_enable }; |
| 149 | |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 150 | static void h8300_sci_config(struct uart_port *port, unsigned int ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 152 | volatile unsigned char *mstpcrl = (volatile unsigned char *)MSTPCRL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | int ch = (port->mapbase - SMR0) >> 3; |
| 154 | unsigned char mask = 1 << (ch+1); |
| 155 | |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 156 | if (ctrl == sci_disable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | *mstpcrl |= mask; |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 158 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | *mstpcrl &= ~mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 161 | |
| 162 | static inline void h8300_sci_enable(struct uart_port *port) |
| 163 | { |
| 164 | h8300_sci_config(port, sci_enable); |
| 165 | } |
| 166 | |
| 167 | static inline void h8300_sci_disable(struct uart_port *port) |
| 168 | { |
| 169 | h8300_sci_config(port, sci_disable); |
| 170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | #endif |
| 172 | |
Paul Mundt | 15c73aa | 2008-10-02 19:47:12 +0900 | [diff] [blame] | 173 | #if defined(__H8300H__) || defined(__H8300S__) |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 174 | static void sci_init_pins(struct uart_port *port, unsigned int cflag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
| 176 | int ch = (port->mapbase - SMR0) >> 3; |
| 177 | |
| 178 | /* set DDR regs */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 179 | H8300_GPIO_DDR(h8300_sci_pins[ch].port, |
| 180 | h8300_sci_pins[ch].rx, |
| 181 | H8300_GPIO_INPUT); |
| 182 | H8300_GPIO_DDR(h8300_sci_pins[ch].port, |
| 183 | h8300_sci_pins[ch].tx, |
| 184 | H8300_GPIO_OUTPUT); |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | /* tx mark output*/ |
| 187 | H8300_SCI_DR(ch) |= h8300_sci_pins[ch].tx; |
| 188 | } |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 189 | #elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712) |
| 190 | static inline void sci_init_pins(struct uart_port *port, unsigned int cflag) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 191 | { |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 192 | if (port->mapbase == 0xA4400000) { |
| 193 | __raw_writew(__raw_readw(PACR) & 0xffc0, PACR); |
| 194 | __raw_writew(__raw_readw(PBCR) & 0x0fff, PBCR); |
| 195 | } else if (port->mapbase == 0xA4410000) |
| 196 | __raw_writew(__raw_readw(PBCR) & 0xf003, PBCR); |
Nobuhiro Iwamatsu | 9465a54 | 2007-03-27 18:13:51 +0900 | [diff] [blame] | 197 | } |
Yoshihiro Shimoda | 31a49c4 | 2007-12-26 11:45:06 +0900 | [diff] [blame] | 198 | #elif defined(CONFIG_CPU_SUBTYPE_SH7720) || defined(CONFIG_CPU_SUBTYPE_SH7721) |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 199 | static inline void sci_init_pins(struct uart_port *port, unsigned int cflag) |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 200 | { |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 201 | unsigned short data; |
| 202 | |
| 203 | if (cflag & CRTSCTS) { |
| 204 | /* enable RTS/CTS */ |
| 205 | if (port->mapbase == 0xa4430000) { /* SCIF0 */ |
| 206 | /* Clear PTCR bit 9-2; enable all scif pins but sck */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 207 | data = __raw_readw(PORT_PTCR); |
| 208 | __raw_writew((data & 0xfc03), PORT_PTCR); |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 209 | } else if (port->mapbase == 0xa4438000) { /* SCIF1 */ |
| 210 | /* Clear PVCR bit 9-2 */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 211 | data = __raw_readw(PORT_PVCR); |
| 212 | __raw_writew((data & 0xfc03), PORT_PVCR); |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 213 | } |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 214 | } else { |
| 215 | if (port->mapbase == 0xa4430000) { /* SCIF0 */ |
| 216 | /* Clear PTCR bit 5-2; enable only tx and rx */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 217 | data = __raw_readw(PORT_PTCR); |
| 218 | __raw_writew((data & 0xffc3), PORT_PTCR); |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 219 | } else if (port->mapbase == 0xa4438000) { /* SCIF1 */ |
| 220 | /* Clear PVCR bit 5-2 */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 221 | data = __raw_readw(PORT_PVCR); |
| 222 | __raw_writew((data & 0xffc3), PORT_PVCR); |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 223 | } |
| 224 | } |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 225 | } |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 226 | #elif defined(CONFIG_CPU_SH3) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 227 | /* For SH7705, SH7706, SH7707, SH7709, SH7709A, SH7729 */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 228 | static inline void sci_init_pins(struct uart_port *port, unsigned int cflag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 230 | unsigned short data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 232 | /* We need to set SCPCR to enable RTS/CTS */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 233 | data = __raw_readw(SCPCR); |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 234 | /* Clear out SCP7MD1,0, SCP6MD1,0, SCP4MD1,0*/ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 235 | __raw_writew(data & 0x0fcf, SCPCR); |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 236 | |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 237 | if (!(cflag & CRTSCTS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | /* We need to set SCPCR to enable RTS/CTS */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 239 | data = __raw_readw(SCPCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | /* Clear out SCP7MD1,0, SCP4MD1,0, |
| 241 | Set SCP6MD1,0 = {01} (output) */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 242 | __raw_writew((data & 0x0fcf) | 0x1000, SCPCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | data = ctrl_inb(SCPDR); |
| 245 | /* Set /RTS2 (bit6) = 0 */ |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 246 | ctrl_outb(data & 0xbf, SCPDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 249 | #elif defined(CONFIG_CPU_SUBTYPE_SH7722) |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 250 | static inline void sci_init_pins(struct uart_port *port, unsigned int cflag) |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 251 | { |
Magnus Damm | 346b746 | 2008-04-23 21:25:29 +0900 | [diff] [blame] | 252 | unsigned short data; |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 253 | |
Magnus Damm | 346b746 | 2008-04-23 21:25:29 +0900 | [diff] [blame] | 254 | if (port->mapbase == 0xffe00000) { |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 255 | data = __raw_readw(PSCR); |
Magnus Damm | 346b746 | 2008-04-23 21:25:29 +0900 | [diff] [blame] | 256 | data &= ~0x03cf; |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 257 | if (!(cflag & CRTSCTS)) |
Magnus Damm | 346b746 | 2008-04-23 21:25:29 +0900 | [diff] [blame] | 258 | data |= 0x0340; |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 259 | |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 260 | __raw_writew(data, PSCR); |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 261 | } |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 262 | } |
Yoshihiro Shimoda | 7d740a0 | 2008-01-07 14:40:07 +0900 | [diff] [blame] | 263 | #elif defined(CONFIG_CPU_SUBTYPE_SH7763) || \ |
| 264 | defined(CONFIG_CPU_SUBTYPE_SH7780) || \ |
Paul Mundt | 2b1bd1a | 2007-06-20 18:27:10 +0900 | [diff] [blame] | 265 | defined(CONFIG_CPU_SUBTYPE_SH7785) || \ |
| 266 | defined(CONFIG_CPU_SUBTYPE_SHX3) |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 267 | static inline void sci_init_pins(struct uart_port *port, unsigned int cflag) |
| 268 | { |
| 269 | if (!(cflag & CRTSCTS)) |
| 270 | __raw_writew(0x0080, SCSPTR0); /* Set RTS = 1 */ |
| 271 | } |
Paul Mundt | b0c50ad | 2008-12-22 03:40:10 +0900 | [diff] [blame] | 272 | #elif defined(CONFIG_CPU_SH4) && !defined(CONFIG_CPU_SH4A) |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 273 | static inline void sci_init_pins(struct uart_port *port, unsigned int cflag) |
| 274 | { |
| 275 | if (!(cflag & CRTSCTS)) |
| 276 | __raw_writew(0x0080, SCSPTR2); /* Set RTS = 1 */ |
| 277 | } |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 278 | #else |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 279 | static inline void sci_init_pins(struct uart_port *port, unsigned int cflag) |
| 280 | { |
| 281 | /* Nothing to do */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 283 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 285 | #if defined(CONFIG_CPU_SUBTYPE_SH7760) || \ |
| 286 | defined(CONFIG_CPU_SUBTYPE_SH7780) || \ |
| 287 | defined(CONFIG_CPU_SUBTYPE_SH7785) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 288 | static inline int scif_txroom(struct uart_port *port) |
| 289 | { |
Yutaro Ebihara | cae167d | 2008-03-11 13:58:50 +0900 | [diff] [blame] | 290 | return SCIF_TXROOM_MAX - (sci_in(port, SCTFDR) & 0xff); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static inline int scif_rxroom(struct uart_port *port) |
| 294 | { |
Yutaro Ebihara | cae167d | 2008-03-11 13:58:50 +0900 | [diff] [blame] | 295 | return sci_in(port, SCRFDR) & 0xff; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 296 | } |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 297 | #elif defined(CONFIG_CPU_SUBTYPE_SH7763) |
| 298 | static inline int scif_txroom(struct uart_port *port) |
| 299 | { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 300 | if ((port->mapbase == 0xffe00000) || |
| 301 | (port->mapbase == 0xffe08000)) { |
| 302 | /* SCIF0/1*/ |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 303 | return SCIF_TXROOM_MAX - (sci_in(port, SCTFDR) & 0xff); |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 304 | } else { |
| 305 | /* SCIF2 */ |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 306 | return SCIF2_TXROOM_MAX - (sci_in(port, SCFDR) >> 8); |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 307 | } |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static inline int scif_rxroom(struct uart_port *port) |
| 311 | { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 312 | if ((port->mapbase == 0xffe00000) || |
| 313 | (port->mapbase == 0xffe08000)) { |
| 314 | /* SCIF0/1*/ |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 315 | return sci_in(port, SCRFDR) & 0xff; |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 316 | } else { |
| 317 | /* SCIF2 */ |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 318 | return sci_in(port, SCFDR) & SCIF2_RFDC_MASK; |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 319 | } |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 320 | } |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 321 | #else |
| 322 | static inline int scif_txroom(struct uart_port *port) |
| 323 | { |
| 324 | return SCIF_TXROOM_MAX - (sci_in(port, SCFDR) >> 8); |
| 325 | } |
| 326 | |
| 327 | static inline int scif_rxroom(struct uart_port *port) |
| 328 | { |
| 329 | return sci_in(port, SCFDR) & SCIF_RFDC_MASK; |
| 330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 333 | static inline int sci_txroom(struct uart_port *port) |
| 334 | { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 335 | return (sci_in(port, SCxSR) & SCI_TDRE) != 0; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static inline int sci_rxroom(struct uart_port *port) |
| 339 | { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 340 | return (sci_in(port, SCxSR) & SCxSR_RDxF(port)) != 0; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 341 | } |
| 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | /* ********************************************************************** * |
| 344 | * the interrupt related routines * |
| 345 | * ********************************************************************** */ |
| 346 | |
| 347 | static void sci_transmit_chars(struct uart_port *port) |
| 348 | { |
| 349 | struct circ_buf *xmit = &port->info->xmit; |
| 350 | unsigned int stopped = uart_tx_stopped(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | unsigned short status; |
| 352 | unsigned short ctrl; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 353 | int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | status = sci_in(port, SCxSR); |
| 356 | if (!(status & SCxSR_TDxE(port))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | ctrl = sci_in(port, SCSCR); |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 358 | if (uart_circ_empty(xmit)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | ctrl &= ~SCI_CTRL_FLAGS_TIE; |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 360 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | ctrl |= SCI_CTRL_FLAGS_TIE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | sci_out(port, SCSCR, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | return; |
| 364 | } |
| 365 | |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 366 | if (port->type == PORT_SCI) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 367 | count = sci_txroom(port); |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 368 | else |
| 369 | count = scif_txroom(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
| 371 | do { |
| 372 | unsigned char c; |
| 373 | |
| 374 | if (port->x_char) { |
| 375 | c = port->x_char; |
| 376 | port->x_char = 0; |
| 377 | } else if (!uart_circ_empty(xmit) && !stopped) { |
| 378 | c = xmit->buf[xmit->tail]; |
| 379 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 380 | } else { |
| 381 | break; |
| 382 | } |
| 383 | |
| 384 | sci_out(port, SCxTDR, c); |
| 385 | |
| 386 | port->icount.tx++; |
| 387 | } while (--count > 0); |
| 388 | |
| 389 | sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port)); |
| 390 | |
| 391 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 392 | uart_write_wakeup(port); |
| 393 | if (uart_circ_empty(xmit)) { |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 394 | sci_stop_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | ctrl = sci_in(port, SCSCR); |
| 397 | |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 398 | if (port->type != PORT_SCI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | sci_in(port, SCxSR); /* Dummy read */ |
| 400 | sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port)); |
| 401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
| 403 | ctrl |= SCI_CTRL_FLAGS_TIE; |
| 404 | sci_out(port, SCSCR, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
| 408 | /* On SH3, SCIF may read end-of-break as a space->mark char */ |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 409 | #define STEPFN(c) ({int __c = (c); (((__c-1)|(__c)) == -1); }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 411 | static inline void sci_receive_chars(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 413 | struct sci_port *sci_port = to_sci_port(port); |
Takashi Iwai | a88487c | 2008-07-16 21:54:42 +0100 | [diff] [blame] | 414 | struct tty_struct *tty = port->info->port.tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | int i, count, copied = 0; |
| 416 | unsigned short status; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 417 | unsigned char flag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | status = sci_in(port, SCxSR); |
| 420 | if (!(status & SCxSR_RDxF(port))) |
| 421 | return; |
| 422 | |
| 423 | while (1) { |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 424 | if (port->type == PORT_SCI) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 425 | count = sci_rxroom(port); |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 426 | else |
| 427 | count = scif_rxroom(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
| 429 | /* Don't copy more bytes than there is room for in the buffer */ |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 430 | count = tty_buffer_request_room(tty, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | /* If for any reason we can't copy more data, we're done! */ |
| 433 | if (count == 0) |
| 434 | break; |
| 435 | |
| 436 | if (port->type == PORT_SCI) { |
| 437 | char c = sci_in(port, SCxRDR); |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 438 | if (uart_handle_sysrq_char(port, c) || |
| 439 | sci_port->break_flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | count = 0; |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 441 | else |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 442 | tty_insert_flip_char(tty, c, TTY_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } else { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 444 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | char c = sci_in(port, SCxRDR); |
| 446 | status = sci_in(port, SCxSR); |
| 447 | #if defined(CONFIG_CPU_SH3) |
| 448 | /* Skip "chars" during break */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 449 | if (sci_port->break_flag) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | if ((c == 0) && |
| 451 | (status & SCxSR_FER(port))) { |
| 452 | count--; i--; |
| 453 | continue; |
| 454 | } |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | /* Nonzero => end-of-break */ |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 457 | dev_dbg(port->dev, "debounce<%02x>\n", c); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 458 | sci_port->break_flag = 0; |
| 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | if (STEPFN(c)) { |
| 461 | count--; i--; |
| 462 | continue; |
| 463 | } |
| 464 | } |
| 465 | #endif /* CONFIG_CPU_SH3 */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 466 | if (uart_handle_sysrq_char(port, c)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | count--; i--; |
| 468 | continue; |
| 469 | } |
| 470 | |
| 471 | /* Store data and status */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | if (status&SCxSR_FER(port)) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 473 | flag = TTY_FRAME; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 474 | dev_notice(port->dev, "frame error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | } else if (status&SCxSR_PER(port)) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 476 | flag = TTY_PARITY; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 477 | dev_notice(port->dev, "parity error\n"); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 478 | } else |
| 479 | flag = TTY_NORMAL; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 480 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 481 | tty_insert_flip_char(tty, c, flag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | |
| 485 | sci_in(port, SCxSR); /* dummy read */ |
| 486 | sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); |
| 487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | copied += count; |
| 489 | port->icount.rx += count; |
| 490 | } |
| 491 | |
| 492 | if (copied) { |
| 493 | /* Tell the rest of the system the news. New characters! */ |
| 494 | tty_flip_buffer_push(tty); |
| 495 | } else { |
| 496 | sci_in(port, SCxSR); /* dummy read */ |
| 497 | sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | #define SCI_BREAK_JIFFIES (HZ/20) |
| 502 | /* The sci generates interrupts during the break, |
| 503 | * 1 per millisecond or so during the break period, for 9600 baud. |
| 504 | * So dont bother disabling interrupts. |
| 505 | * But dont want more than 1 break event. |
| 506 | * Use a kernel timer to periodically poll the rx line until |
| 507 | * the break is finished. |
| 508 | */ |
| 509 | static void sci_schedule_break_timer(struct sci_port *port) |
| 510 | { |
| 511 | port->break_timer.expires = jiffies + SCI_BREAK_JIFFIES; |
| 512 | add_timer(&port->break_timer); |
| 513 | } |
| 514 | /* Ensure that two consecutive samples find the break over. */ |
| 515 | static void sci_break_timer(unsigned long data) |
| 516 | { |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 517 | struct sci_port *port = (struct sci_port *)data; |
| 518 | |
| 519 | if (sci_rxd_in(&port->port) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | port->break_flag = 1; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 521 | sci_schedule_break_timer(port); |
| 522 | } else if (port->break_flag == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | /* break is over. */ |
| 524 | port->break_flag = 2; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 525 | sci_schedule_break_timer(port); |
| 526 | } else |
| 527 | port->break_flag = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | static inline int sci_handle_errors(struct uart_port *port) |
| 531 | { |
| 532 | int copied = 0; |
| 533 | unsigned short status = sci_in(port, SCxSR); |
Takashi Iwai | a88487c | 2008-07-16 21:54:42 +0100 | [diff] [blame] | 534 | struct tty_struct *tty = port->info->port.tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 536 | if (status & SCxSR_ORER(port)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* overrun error */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 538 | if (tty_insert_flip_char(tty, 0, TTY_OVERRUN)) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 539 | copied++; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 540 | |
| 541 | dev_notice(port->dev, "overrun error"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 544 | if (status & SCxSR_FER(port)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | if (sci_rxd_in(port) == 0) { |
| 546 | /* Notify of BREAK */ |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 547 | struct sci_port *sci_port = to_sci_port(port); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 548 | |
| 549 | if (!sci_port->break_flag) { |
| 550 | sci_port->break_flag = 1; |
| 551 | sci_schedule_break_timer(sci_port); |
| 552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | /* Do sysrq handling. */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 554 | if (uart_handle_break(port)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | return 0; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 556 | |
| 557 | dev_dbg(port->dev, "BREAK detected\n"); |
| 558 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 559 | if (tty_insert_flip_char(tty, 0, TTY_BREAK)) |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 560 | copied++; |
| 561 | } |
| 562 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 563 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | /* frame error */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 565 | if (tty_insert_flip_char(tty, 0, TTY_FRAME)) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 566 | copied++; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 567 | |
| 568 | dev_notice(port->dev, "frame error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 572 | if (status & SCxSR_PER(port)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | /* parity error */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 574 | if (tty_insert_flip_char(tty, 0, TTY_PARITY)) |
| 575 | copied++; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 576 | |
| 577 | dev_notice(port->dev, "parity error"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 580 | if (copied) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | tty_flip_buffer_push(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
| 583 | return copied; |
| 584 | } |
| 585 | |
Paul Mundt | d830fa4 | 2008-12-16 19:29:38 +0900 | [diff] [blame] | 586 | static inline int sci_handle_fifo_overrun(struct uart_port *port) |
| 587 | { |
| 588 | struct tty_struct *tty = port->info->port.tty; |
| 589 | int copied = 0; |
| 590 | |
| 591 | if (port->type != PORT_SCIF) |
| 592 | return 0; |
| 593 | |
| 594 | if ((sci_in(port, SCLSR) & SCIF_ORER) != 0) { |
| 595 | sci_out(port, SCLSR, 0); |
| 596 | |
| 597 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); |
| 598 | tty_flip_buffer_push(tty); |
| 599 | |
| 600 | dev_notice(port->dev, "overrun error\n"); |
| 601 | copied++; |
| 602 | } |
| 603 | |
| 604 | return copied; |
| 605 | } |
| 606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | static inline int sci_handle_breaks(struct uart_port *port) |
| 608 | { |
| 609 | int copied = 0; |
| 610 | unsigned short status = sci_in(port, SCxSR); |
Takashi Iwai | a88487c | 2008-07-16 21:54:42 +0100 | [diff] [blame] | 611 | struct tty_struct *tty = port->info->port.tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | struct sci_port *s = &sci_ports[port->line]; |
| 613 | |
Paul Mundt | 0b3d4ef | 2007-03-14 13:22:37 +0900 | [diff] [blame] | 614 | if (uart_handle_break(port)) |
| 615 | return 0; |
| 616 | |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 617 | if (!s->break_flag && status & SCxSR_BRK(port)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | #if defined(CONFIG_CPU_SH3) |
| 619 | /* Debounce break */ |
| 620 | s->break_flag = 1; |
| 621 | #endif |
| 622 | /* Notify of BREAK */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 623 | if (tty_insert_flip_char(tty, 0, TTY_BREAK)) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 624 | copied++; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 625 | |
| 626 | dev_dbg(port->dev, "BREAK detected\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 629 | if (copied) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | tty_flip_buffer_push(tty); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 631 | |
Paul Mundt | d830fa4 | 2008-12-16 19:29:38 +0900 | [diff] [blame] | 632 | copied += sci_handle_fifo_overrun(port); |
| 633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | return copied; |
| 635 | } |
| 636 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 637 | static irqreturn_t sci_rx_interrupt(int irq, void *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | /* I think sci_receive_chars has to be called irrespective |
| 640 | * of whether the I_IXOFF is set, otherwise, how is the interrupt |
| 641 | * to be disabled? |
| 642 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 643 | sci_receive_chars(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | return IRQ_HANDLED; |
| 646 | } |
| 647 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 648 | static irqreturn_t sci_tx_interrupt(int irq, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | { |
| 650 | struct uart_port *port = ptr; |
| 651 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 652 | spin_lock_irq(&port->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | sci_transmit_chars(port); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 654 | spin_unlock_irq(&port->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
| 656 | return IRQ_HANDLED; |
| 657 | } |
| 658 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 659 | static irqreturn_t sci_er_interrupt(int irq, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | { |
| 661 | struct uart_port *port = ptr; |
| 662 | |
| 663 | /* Handle errors */ |
| 664 | if (port->type == PORT_SCI) { |
| 665 | if (sci_handle_errors(port)) { |
| 666 | /* discard character in rx buffer */ |
| 667 | sci_in(port, SCxSR); |
| 668 | sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); |
| 669 | } |
| 670 | } else { |
Paul Mundt | d830fa4 | 2008-12-16 19:29:38 +0900 | [diff] [blame] | 671 | sci_handle_fifo_overrun(port); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 672 | sci_rx_interrupt(irq, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port)); |
| 676 | |
| 677 | /* Kick the transmission */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 678 | sci_tx_interrupt(irq, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
| 680 | return IRQ_HANDLED; |
| 681 | } |
| 682 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 683 | static irqreturn_t sci_br_interrupt(int irq, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | { |
| 685 | struct uart_port *port = ptr; |
| 686 | |
| 687 | /* Handle BREAKs */ |
| 688 | sci_handle_breaks(port); |
| 689 | sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port)); |
| 690 | |
| 691 | return IRQ_HANDLED; |
| 692 | } |
| 693 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 694 | static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | { |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 696 | unsigned short ssr_status, scr_status; |
| 697 | struct uart_port *port = ptr; |
| 698 | irqreturn_t ret = IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 700 | ssr_status = sci_in(port, SCxSR); |
| 701 | scr_status = sci_in(port, SCSCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
| 703 | /* Tx Interrupt */ |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 704 | if ((ssr_status & 0x0020) && (scr_status & SCI_CTRL_FLAGS_TIE)) |
| 705 | ret = sci_tx_interrupt(irq, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | /* Rx Interrupt */ |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 707 | if ((ssr_status & 0x0002) && (scr_status & SCI_CTRL_FLAGS_RIE)) |
| 708 | ret = sci_rx_interrupt(irq, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | /* Error Interrupt */ |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 710 | if ((ssr_status & 0x0080) && (scr_status & SCI_CTRL_FLAGS_REIE)) |
| 711 | ret = sci_er_interrupt(irq, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | /* Break Interrupt */ |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 713 | if ((ssr_status & 0x0010) && (scr_status & SCI_CTRL_FLAGS_REIE)) |
| 714 | ret = sci_br_interrupt(irq, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 716 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Paul Mundt | 027e687 | 2008-12-16 18:36:16 +0900 | [diff] [blame] | 719 | #ifdef CONFIG_HAVE_CLK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | /* |
| 721 | * Here we define a transistion notifier so that we can update all of our |
| 722 | * ports' baud rate when the peripheral clock changes. |
| 723 | */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 724 | static int sci_notifier(struct notifier_block *self, |
| 725 | unsigned long phase, void *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | int i; |
| 728 | |
| 729 | if ((phase == CPUFREQ_POSTCHANGE) || |
Paul Mundt | 027e687 | 2008-12-16 18:36:16 +0900 | [diff] [blame] | 730 | (phase == CPUFREQ_RESUMECHANGE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | for (i = 0; i < SCI_NPORTS; i++) { |
Paul Mundt | 027e687 | 2008-12-16 18:36:16 +0900 | [diff] [blame] | 732 | struct sci_port *s = &sci_ports[i]; |
| 733 | s->port.uartclk = clk_get_rate(s->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | return NOTIFY_OK; |
| 737 | } |
| 738 | |
| 739 | static struct notifier_block sci_nb = { &sci_notifier, NULL, 0 }; |
Paul Mundt | 027e687 | 2008-12-16 18:36:16 +0900 | [diff] [blame] | 740 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | |
| 742 | static int sci_request_irq(struct sci_port *port) |
| 743 | { |
| 744 | int i; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 745 | irqreturn_t (*handlers[4])(int irq, void *ptr) = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | sci_er_interrupt, sci_rx_interrupt, sci_tx_interrupt, |
| 747 | sci_br_interrupt, |
| 748 | }; |
| 749 | const char *desc[] = { "SCI Receive Error", "SCI Receive Data Full", |
| 750 | "SCI Transmit Data Empty", "SCI Break" }; |
| 751 | |
| 752 | if (port->irqs[0] == port->irqs[1]) { |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 753 | if (unlikely(!port->irqs[0])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | return -ENODEV; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 755 | |
| 756 | if (request_irq(port->irqs[0], sci_mpxed_interrupt, |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 757 | IRQF_DISABLED, "sci", port)) { |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 758 | dev_err(port->port.dev, "Can't allocate IRQ\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | return -ENODEV; |
| 760 | } |
| 761 | } else { |
| 762 | for (i = 0; i < ARRAY_SIZE(handlers); i++) { |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 763 | if (unlikely(!port->irqs[i])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | continue; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 765 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 766 | if (request_irq(port->irqs[i], handlers[i], |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 767 | IRQF_DISABLED, desc[i], port)) { |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 768 | dev_err(port->port.dev, "Can't allocate IRQ\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | return -ENODEV; |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | static void sci_free_irq(struct sci_port *port) |
| 778 | { |
| 779 | int i; |
| 780 | |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 781 | if (port->irqs[0] == port->irqs[1]) |
| 782 | free_irq(port->irqs[0], port); |
| 783 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | for (i = 0; i < ARRAY_SIZE(port->irqs); i++) { |
| 785 | if (!port->irqs[i]) |
| 786 | continue; |
| 787 | |
| 788 | free_irq(port->irqs[i], port); |
| 789 | } |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | static unsigned int sci_tx_empty(struct uart_port *port) |
| 794 | { |
| 795 | /* Can't detect */ |
| 796 | return TIOCSER_TEMT; |
| 797 | } |
| 798 | |
| 799 | static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 800 | { |
| 801 | /* This routine is used for seting signals of: DTR, DCD, CTS/RTS */ |
| 802 | /* We use SCIF's hardware for CTS/RTS, so don't need any for that. */ |
| 803 | /* If you have signals for DTR and DCD, please implement here. */ |
| 804 | } |
| 805 | |
| 806 | static unsigned int sci_get_mctrl(struct uart_port *port) |
| 807 | { |
| 808 | /* This routine is used for geting signals of: DTR, DCD, DSR, RI, |
| 809 | and CTS/RTS */ |
| 810 | |
| 811 | return TIOCM_DTR | TIOCM_RTS | TIOCM_DSR; |
| 812 | } |
| 813 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 814 | static void sci_start_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 816 | unsigned short ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 818 | /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */ |
| 819 | ctrl = sci_in(port, SCSCR); |
| 820 | ctrl |= SCI_CTRL_FLAGS_TIE; |
| 821 | sci_out(port, SCSCR, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 824 | static void sci_stop_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | unsigned short ctrl; |
| 827 | |
| 828 | /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | ctrl = sci_in(port, SCSCR); |
| 830 | ctrl &= ~SCI_CTRL_FLAGS_TIE; |
| 831 | sci_out(port, SCSCR, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | static void sci_start_rx(struct uart_port *port, unsigned int tty_start) |
| 835 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | unsigned short ctrl; |
| 837 | |
| 838 | /* Set RIE (Receive Interrupt Enable) bit in SCSCR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | ctrl = sci_in(port, SCSCR); |
| 840 | ctrl |= SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE; |
| 841 | sci_out(port, SCSCR, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | static void sci_stop_rx(struct uart_port *port) |
| 845 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | unsigned short ctrl; |
| 847 | |
| 848 | /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | ctrl = sci_in(port, SCSCR); |
| 850 | ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE); |
| 851 | sci_out(port, SCSCR, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | static void sci_enable_ms(struct uart_port *port) |
| 855 | { |
| 856 | /* Nothing here yet .. */ |
| 857 | } |
| 858 | |
| 859 | static void sci_break_ctl(struct uart_port *port, int break_state) |
| 860 | { |
| 861 | /* Nothing here yet .. */ |
| 862 | } |
| 863 | |
| 864 | static int sci_startup(struct uart_port *port) |
| 865 | { |
| 866 | struct sci_port *s = &sci_ports[port->line]; |
| 867 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 868 | if (s->enable) |
| 869 | s->enable(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
Paul Mundt | a2159b5 | 2008-10-02 19:09:13 +0900 | [diff] [blame] | 871 | #ifdef CONFIG_HAVE_CLK |
dmitry pervushin | 1534a3b | 2007-04-24 13:41:12 +0900 | [diff] [blame] | 872 | s->clk = clk_get(NULL, "module_clk"); |
Paul Mundt | 005a336 | 2007-04-26 11:45:32 +0900 | [diff] [blame] | 873 | #endif |
dmitry pervushin | 1534a3b | 2007-04-24 13:41:12 +0900 | [diff] [blame] | 874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | sci_request_irq(s); |
Yoshinori Sato | d656901 | 2005-10-14 15:59:12 -0700 | [diff] [blame] | 876 | sci_start_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | sci_start_rx(port, 1); |
| 878 | |
| 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | static void sci_shutdown(struct uart_port *port) |
| 883 | { |
| 884 | struct sci_port *s = &sci_ports[port->line]; |
| 885 | |
| 886 | sci_stop_rx(port); |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 887 | sci_stop_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | sci_free_irq(s); |
| 889 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 890 | if (s->disable) |
| 891 | s->disable(port); |
dmitry pervushin | 1534a3b | 2007-04-24 13:41:12 +0900 | [diff] [blame] | 892 | |
Paul Mundt | a2159b5 | 2008-10-02 19:09:13 +0900 | [diff] [blame] | 893 | #ifdef CONFIG_HAVE_CLK |
dmitry pervushin | 1534a3b | 2007-04-24 13:41:12 +0900 | [diff] [blame] | 894 | clk_put(s->clk); |
| 895 | s->clk = NULL; |
Paul Mundt | 005a336 | 2007-04-26 11:45:32 +0900 | [diff] [blame] | 896 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 899 | static void sci_set_termios(struct uart_port *port, struct ktermios *termios, |
| 900 | struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | unsigned int status, baud, smr_val; |
Paul Mundt | a2159b5 | 2008-10-02 19:09:13 +0900 | [diff] [blame] | 903 | int t = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
| 905 | baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); |
Paul Mundt | a2159b5 | 2008-10-02 19:09:13 +0900 | [diff] [blame] | 906 | if (likely(baud)) |
| 907 | t = SCBRR_VALUE(baud, port->uartclk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 909 | do { |
| 910 | status = sci_in(port, SCxSR); |
| 911 | } while (!(status & SCxSR_TEND(port))); |
| 912 | |
| 913 | sci_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */ |
| 914 | |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 915 | if (port->type != PORT_SCI) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 916 | sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 917 | |
| 918 | smr_val = sci_in(port, SCSMR) & 3; |
| 919 | if ((termios->c_cflag & CSIZE) == CS7) |
| 920 | smr_val |= 0x40; |
| 921 | if (termios->c_cflag & PARENB) |
| 922 | smr_val |= 0x20; |
| 923 | if (termios->c_cflag & PARODD) |
| 924 | smr_val |= 0x30; |
| 925 | if (termios->c_cflag & CSTOPB) |
| 926 | smr_val |= 0x08; |
| 927 | |
| 928 | uart_update_timeout(port, termios->c_cflag, baud); |
| 929 | |
| 930 | sci_out(port, SCSMR, smr_val); |
| 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | if (t > 0) { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 933 | if (t >= 256) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1); |
| 935 | t >>= 2; |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 936 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3); |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | sci_out(port, SCBRR, t); |
| 940 | udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */ |
| 941 | } |
| 942 | |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 943 | sci_init_pins(port, termios->c_cflag); |
| 944 | sci_out(port, SCFCR, (termios->c_cflag & CRTSCTS) ? SCFCR_MCE : 0); |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | sci_out(port, SCSCR, SCSCR_INIT(port)); |
| 947 | |
| 948 | if ((termios->c_cflag & CREAD) != 0) |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 949 | sci_start_rx(port, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | static const char *sci_type(struct uart_port *port) |
| 953 | { |
| 954 | switch (port->type) { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 955 | case PORT_IRDA: |
| 956 | return "irda"; |
| 957 | case PORT_SCI: |
| 958 | return "sci"; |
| 959 | case PORT_SCIF: |
| 960 | return "scif"; |
| 961 | case PORT_SCIFA: |
| 962 | return "scifa"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 965 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | static void sci_release_port(struct uart_port *port) |
| 969 | { |
| 970 | /* Nothing here yet .. */ |
| 971 | } |
| 972 | |
| 973 | static int sci_request_port(struct uart_port *port) |
| 974 | { |
| 975 | /* Nothing here yet .. */ |
| 976 | return 0; |
| 977 | } |
| 978 | |
| 979 | static void sci_config_port(struct uart_port *port, int flags) |
| 980 | { |
| 981 | struct sci_port *s = &sci_ports[port->line]; |
| 982 | |
| 983 | port->type = s->type; |
| 984 | |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 985 | if (port->flags & UPF_IOREMAP && !port->membase) { |
| 986 | #if defined(CONFIG_SUPERH64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | port->mapbase = onchip_remap(SCIF_ADDR_SH5, 1024, "SCIF"); |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 988 | port->membase = (void __iomem *)port->mapbase; |
| 989 | #else |
| 990 | port->membase = ioremap_nocache(port->mapbase, 0x40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | #endif |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 992 | |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 993 | dev_err(port->dev, "can't remap port#%d\n", port->line); |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 994 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | static int sci_verify_port(struct uart_port *port, struct serial_struct *ser) |
| 998 | { |
| 999 | struct sci_port *s = &sci_ports[port->line]; |
| 1000 | |
Yinghai Lu | a62c413 | 2008-08-19 20:49:55 -0700 | [diff] [blame] | 1001 | if (ser->irq != s->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | return -EINVAL; |
| 1003 | if (ser->baud_base < 2400) |
| 1004 | /* No paper tape reader for Mitch.. */ |
| 1005 | return -EINVAL; |
| 1006 | |
| 1007 | return 0; |
| 1008 | } |
| 1009 | |
| 1010 | static struct uart_ops sci_uart_ops = { |
| 1011 | .tx_empty = sci_tx_empty, |
| 1012 | .set_mctrl = sci_set_mctrl, |
| 1013 | .get_mctrl = sci_get_mctrl, |
| 1014 | .start_tx = sci_start_tx, |
| 1015 | .stop_tx = sci_stop_tx, |
| 1016 | .stop_rx = sci_stop_rx, |
| 1017 | .enable_ms = sci_enable_ms, |
| 1018 | .break_ctl = sci_break_ctl, |
| 1019 | .startup = sci_startup, |
| 1020 | .shutdown = sci_shutdown, |
| 1021 | .set_termios = sci_set_termios, |
| 1022 | .type = sci_type, |
| 1023 | .release_port = sci_release_port, |
| 1024 | .request_port = sci_request_port, |
| 1025 | .config_port = sci_config_port, |
| 1026 | .verify_port = sci_verify_port, |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 1027 | #ifdef CONFIG_CONSOLE_POLL |
| 1028 | .poll_get_char = sci_poll_get_char, |
| 1029 | .poll_put_char = sci_poll_put_char, |
| 1030 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | }; |
| 1032 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1033 | static void __init sci_init_ports(void) |
| 1034 | { |
| 1035 | static int first = 1; |
| 1036 | int i; |
| 1037 | |
| 1038 | if (!first) |
| 1039 | return; |
| 1040 | |
| 1041 | first = 0; |
| 1042 | |
| 1043 | for (i = 0; i < SCI_NPORTS; i++) { |
| 1044 | sci_ports[i].port.ops = &sci_uart_ops; |
| 1045 | sci_ports[i].port.iotype = UPIO_MEM; |
| 1046 | sci_ports[i].port.line = i; |
| 1047 | sci_ports[i].port.fifosize = 1; |
| 1048 | |
| 1049 | #if defined(__H8300H__) || defined(__H8300S__) |
| 1050 | #ifdef __H8300S__ |
| 1051 | sci_ports[i].enable = h8300_sci_enable; |
| 1052 | sci_ports[i].disable = h8300_sci_disable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | #endif |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1054 | sci_ports[i].port.uartclk = CONFIG_CPU_CLOCK; |
Paul Mundt | a2159b5 | 2008-10-02 19:09:13 +0900 | [diff] [blame] | 1055 | #elif defined(CONFIG_HAVE_CLK) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1056 | /* |
| 1057 | * XXX: We should use a proper SCI/SCIF clock |
| 1058 | */ |
| 1059 | { |
Paul Mundt | 1d11856 | 2006-12-01 13:15:14 +0900 | [diff] [blame] | 1060 | struct clk *clk = clk_get(NULL, "module_clk"); |
Paul Mundt | a2159b5 | 2008-10-02 19:09:13 +0900 | [diff] [blame] | 1061 | sci_ports[i].port.uartclk = clk_get_rate(clk); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1062 | clk_put(clk); |
| 1063 | } |
Paul Mundt | a2159b5 | 2008-10-02 19:09:13 +0900 | [diff] [blame] | 1064 | #else |
| 1065 | #error "Need a valid uartclk" |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1066 | #endif |
| 1067 | |
| 1068 | sci_ports[i].break_timer.data = (unsigned long)&sci_ports[i]; |
| 1069 | sci_ports[i].break_timer.function = sci_break_timer; |
| 1070 | |
| 1071 | init_timer(&sci_ports[i].break_timer); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | int __init early_sci_setup(struct uart_port *port) |
| 1076 | { |
| 1077 | if (unlikely(port->line > SCI_NPORTS)) |
| 1078 | return -ENODEV; |
| 1079 | |
| 1080 | sci_init_ports(); |
| 1081 | |
| 1082 | sci_ports[port->line].port.membase = port->membase; |
| 1083 | sci_ports[port->line].port.mapbase = port->mapbase; |
| 1084 | sci_ports[port->line].port.type = port->type; |
| 1085 | |
| 1086 | return 0; |
| 1087 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
| 1089 | #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE |
| 1090 | /* |
| 1091 | * Print a string to the serial port trying not to disturb |
| 1092 | * any possible real use of the port... |
| 1093 | */ |
| 1094 | static void serial_console_write(struct console *co, const char *s, |
| 1095 | unsigned count) |
| 1096 | { |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 1097 | struct uart_port *port = &serial_console_port->port; |
Magnus Damm | 973e5d5 | 2009-02-24 15:57:12 +0900 | [diff] [blame^] | 1098 | unsigned short bits; |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 1099 | int i; |
| 1100 | |
| 1101 | for (i = 0; i < count; i++) { |
| 1102 | if (*s == 10) |
| 1103 | sci_poll_put_char(port, '\r'); |
| 1104 | |
| 1105 | sci_poll_put_char(port, *s++); |
| 1106 | } |
Magnus Damm | 973e5d5 | 2009-02-24 15:57:12 +0900 | [diff] [blame^] | 1107 | |
| 1108 | /* wait until fifo is empty and last bit has been transmitted */ |
| 1109 | bits = SCxSR_TDxE(port) | SCxSR_TEND(port); |
| 1110 | while ((sci_in(port, SCxSR) & bits) != bits) |
| 1111 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | static int __init serial_console_setup(struct console *co, char *options) |
| 1115 | { |
| 1116 | struct uart_port *port; |
| 1117 | int baud = 115200; |
| 1118 | int bits = 8; |
| 1119 | int parity = 'n'; |
| 1120 | int flow = 'n'; |
| 1121 | int ret; |
| 1122 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1123 | /* |
| 1124 | * Check whether an invalid uart number has been specified, and |
| 1125 | * if so, search for the first available port that does have |
| 1126 | * console support. |
| 1127 | */ |
| 1128 | if (co->index >= SCI_NPORTS) |
| 1129 | co->index = 0; |
| 1130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | serial_console_port = &sci_ports[co->index]; |
| 1132 | port = &serial_console_port->port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
| 1134 | /* |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1135 | * Also need to check port->type, we don't actually have any |
| 1136 | * UPIO_PORT ports, but uart_report_port() handily misreports |
| 1137 | * it anyways if we don't have a port available by the time this is |
| 1138 | * called. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1140 | if (!port->type) |
| 1141 | return -ENODEV; |
| 1142 | if (!port->membase || !port->mapbase) |
| 1143 | return -ENODEV; |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 1144 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1145 | port->type = serial_console_port->type; |
| 1146 | |
Paul Mundt | a2159b5 | 2008-10-02 19:09:13 +0900 | [diff] [blame] | 1147 | #ifdef CONFIG_HAVE_CLK |
Paul Mundt | 005a336 | 2007-04-26 11:45:32 +0900 | [diff] [blame] | 1148 | if (!serial_console_port->clk) |
| 1149 | serial_console_port->clk = clk_get(NULL, "module_clk"); |
| 1150 | #endif |
| 1151 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1152 | if (port->flags & UPF_IOREMAP) |
| 1153 | sci_config_port(port, 0); |
| 1154 | |
| 1155 | if (serial_console_port->enable) |
| 1156 | serial_console_port->enable(port); |
| 1157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | if (options) |
| 1159 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 1160 | |
| 1161 | ret = uart_set_options(port, co, baud, parity, bits, flow); |
| 1162 | #if defined(__H8300H__) || defined(__H8300S__) |
| 1163 | /* disable rx interrupt */ |
| 1164 | if (ret == 0) |
| 1165 | sci_stop_rx(port); |
| 1166 | #endif |
| 1167 | return ret; |
| 1168 | } |
| 1169 | |
| 1170 | static struct console serial_console = { |
| 1171 | .name = "ttySC", |
| 1172 | .device = uart_console_device, |
| 1173 | .write = serial_console_write, |
| 1174 | .setup = serial_console_setup, |
Paul Mundt | fa5da2f | 2007-03-08 17:27:37 +0900 | [diff] [blame] | 1175 | .flags = CON_PRINTBUFFER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | .index = -1, |
| 1177 | .data = &sci_uart_driver, |
| 1178 | }; |
| 1179 | |
| 1180 | static int __init sci_console_init(void) |
| 1181 | { |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1182 | sci_init_ports(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | register_console(&serial_console); |
| 1184 | return 0; |
| 1185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | console_initcall(sci_console_init); |
| 1187 | #endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */ |
| 1188 | |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 1189 | #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 1190 | #define SCI_CONSOLE (&serial_console) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | #else |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 1192 | #define SCI_CONSOLE 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | #endif |
| 1194 | |
| 1195 | static char banner[] __initdata = |
| 1196 | KERN_INFO "SuperH SCI(F) driver initialized\n"; |
| 1197 | |
| 1198 | static struct uart_driver sci_uart_driver = { |
| 1199 | .owner = THIS_MODULE, |
| 1200 | .driver_name = "sci", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | .dev_name = "ttySC", |
| 1202 | .major = SCI_MAJOR, |
| 1203 | .minor = SCI_MINOR_START, |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1204 | .nr = SCI_NPORTS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | .cons = SCI_CONSOLE, |
| 1206 | }; |
| 1207 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1208 | /* |
| 1209 | * Register a set of serial devices attached to a platform device. The |
| 1210 | * list is terminated with a zero flags entry, which means we expect |
| 1211 | * all entries to have at least UPF_BOOT_AUTOCONF set. Platforms that need |
| 1212 | * remapping (such as sh64) should also set UPF_IOREMAP. |
| 1213 | */ |
| 1214 | static int __devinit sci_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | { |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1216 | struct plat_sci_port *p = dev->dev.platform_data; |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 1217 | int i, ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 1219 | for (i = 0; p && p->flags != 0; p++, i++) { |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1220 | struct sci_port *sciport = &sci_ports[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 1222 | /* Sanity check */ |
| 1223 | if (unlikely(i == SCI_NPORTS)) { |
| 1224 | dev_notice(&dev->dev, "Attempting to register port " |
| 1225 | "%d when only %d are available.\n", |
| 1226 | i+1, SCI_NPORTS); |
| 1227 | dev_notice(&dev->dev, "Consider bumping " |
| 1228 | "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n"); |
| 1229 | break; |
| 1230 | } |
| 1231 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1232 | sciport->port.mapbase = p->mapbase; |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 1233 | |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 1234 | if (p->mapbase && !p->membase) { |
| 1235 | if (p->flags & UPF_IOREMAP) { |
| 1236 | p->membase = ioremap_nocache(p->mapbase, 0x40); |
| 1237 | if (IS_ERR(p->membase)) { |
| 1238 | ret = PTR_ERR(p->membase); |
| 1239 | goto err_unreg; |
| 1240 | } |
| 1241 | } else { |
| 1242 | /* |
| 1243 | * For the simple (and majority of) cases |
| 1244 | * where we don't need to do any remapping, |
| 1245 | * just cast the cookie directly. |
| 1246 | */ |
| 1247 | p->membase = (void __iomem *)p->mapbase; |
| 1248 | } |
| 1249 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1251 | sciport->port.membase = p->membase; |
| 1252 | |
| 1253 | sciport->port.irq = p->irqs[SCIx_TXI_IRQ]; |
| 1254 | sciport->port.flags = p->flags; |
| 1255 | sciport->port.dev = &dev->dev; |
| 1256 | |
| 1257 | sciport->type = sciport->port.type = p->type; |
| 1258 | |
| 1259 | memcpy(&sciport->irqs, &p->irqs, sizeof(p->irqs)); |
| 1260 | |
| 1261 | uart_add_one_port(&sci_uart_driver, &sciport->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Paul Mundt | 027e687 | 2008-12-16 18:36:16 +0900 | [diff] [blame] | 1264 | #ifdef CONFIG_HAVE_CLK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | cpufreq_register_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | #endif |
| 1267 | |
| 1268 | #ifdef CONFIG_SH_STANDARD_BIOS |
| 1269 | sh_bios_gdb_detach(); |
| 1270 | #endif |
| 1271 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1272 | return 0; |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 1273 | |
| 1274 | err_unreg: |
| 1275 | for (i = i - 1; i >= 0; i--) |
| 1276 | uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port); |
| 1277 | |
| 1278 | return ret; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | static int __devexit sci_remove(struct platform_device *dev) |
| 1282 | { |
| 1283 | int i; |
| 1284 | |
Paul Mundt | 027e687 | 2008-12-16 18:36:16 +0900 | [diff] [blame] | 1285 | #ifdef CONFIG_HAVE_CLK |
| 1286 | cpufreq_unregister_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER); |
| 1287 | #endif |
| 1288 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1289 | for (i = 0; i < SCI_NPORTS; i++) |
| 1290 | uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port); |
| 1291 | |
| 1292 | return 0; |
| 1293 | } |
| 1294 | |
| 1295 | static int sci_suspend(struct platform_device *dev, pm_message_t state) |
| 1296 | { |
| 1297 | int i; |
| 1298 | |
| 1299 | for (i = 0; i < SCI_NPORTS; i++) { |
| 1300 | struct sci_port *p = &sci_ports[i]; |
| 1301 | |
| 1302 | if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev) |
| 1303 | uart_suspend_port(&sci_uart_driver, &p->port); |
| 1304 | } |
| 1305 | |
| 1306 | return 0; |
| 1307 | } |
| 1308 | |
| 1309 | static int sci_resume(struct platform_device *dev) |
| 1310 | { |
| 1311 | int i; |
| 1312 | |
| 1313 | for (i = 0; i < SCI_NPORTS; i++) { |
| 1314 | struct sci_port *p = &sci_ports[i]; |
| 1315 | |
| 1316 | if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev) |
| 1317 | uart_resume_port(&sci_uart_driver, &p->port); |
| 1318 | } |
| 1319 | |
| 1320 | return 0; |
| 1321 | } |
| 1322 | |
| 1323 | static struct platform_driver sci_driver = { |
| 1324 | .probe = sci_probe, |
| 1325 | .remove = __devexit_p(sci_remove), |
| 1326 | .suspend = sci_suspend, |
| 1327 | .resume = sci_resume, |
| 1328 | .driver = { |
| 1329 | .name = "sh-sci", |
| 1330 | .owner = THIS_MODULE, |
| 1331 | }, |
| 1332 | }; |
| 1333 | |
| 1334 | static int __init sci_init(void) |
| 1335 | { |
| 1336 | int ret; |
| 1337 | |
| 1338 | printk(banner); |
| 1339 | |
| 1340 | sci_init_ports(); |
| 1341 | |
| 1342 | ret = uart_register_driver(&sci_uart_driver); |
| 1343 | if (likely(ret == 0)) { |
| 1344 | ret = platform_driver_register(&sci_driver); |
| 1345 | if (unlikely(ret)) |
| 1346 | uart_unregister_driver(&sci_uart_driver); |
| 1347 | } |
| 1348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | return ret; |
| 1350 | } |
| 1351 | |
| 1352 | static void __exit sci_exit(void) |
| 1353 | { |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1354 | platform_driver_unregister(&sci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | uart_unregister_driver(&sci_uart_driver); |
| 1356 | } |
| 1357 | |
| 1358 | module_init(sci_init); |
| 1359 | module_exit(sci_exit); |
| 1360 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1361 | MODULE_LICENSE("GPL"); |
Kay Sievers | e169c13 | 2008-04-15 14:34:35 -0700 | [diff] [blame] | 1362 | MODULE_ALIAS("platform:sh-sci"); |