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