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