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 | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 6 | * Copyright (C) 2002 - 2011 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> |
Magnus Damm | 5e50d2d | 2011-04-19 10:38:25 +0000 | [diff] [blame] | 46 | #include <linux/pm_runtime.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/cpufreq.h> |
Paul Mundt | 85f094e | 2008-04-25 16:04:20 +0900 | [diff] [blame] | 48 | #include <linux/clk.h> |
Paul Mundt | fa5da2f | 2007-03-08 17:27:37 +0900 | [diff] [blame] | 49 | #include <linux/ctype.h> |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 50 | #include <linux/err.h> |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 51 | #include <linux/dmaengine.h> |
| 52 | #include <linux/scatterlist.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 53 | #include <linux/slab.h> |
Paul Mundt | 85f094e | 2008-04-25 16:04:20 +0900 | [diff] [blame] | 54 | |
| 55 | #ifdef CONFIG_SUPERH |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 56 | #include <asm/sh_bios.h> |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 57 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Yoshinori Sato | 168f362 | 2009-04-28 04:40:15 +0000 | [diff] [blame] | 59 | #ifdef CONFIG_H8300 |
| 60 | #include <asm/gpio.h> |
| 61 | #endif |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #include "sh-sci.h" |
| 64 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 65 | struct sci_port { |
| 66 | struct uart_port port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 68 | /* Platform configuration */ |
| 69 | struct plat_sci_port *cfg; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 70 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 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 | |
Magnus Damm | 501b825 | 2009-01-21 15:14:30 +0000 | [diff] [blame] | 81 | /* Interface clock */ |
| 82 | struct clk *iclk; |
Paul Mundt | c7ed1ab | 2010-03-10 18:35:14 +0900 | [diff] [blame] | 83 | /* Function clock */ |
| 84 | struct clk *fclk; |
Paul Mundt | edad1f2 | 2009-11-25 16:23:35 +0900 | [diff] [blame] | 85 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 86 | struct dma_chan *chan_tx; |
| 87 | struct dma_chan *chan_rx; |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 88 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 89 | #ifdef CONFIG_SERIAL_SH_SCI_DMA |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 90 | struct dma_async_tx_descriptor *desc_tx; |
| 91 | struct dma_async_tx_descriptor *desc_rx[2]; |
| 92 | dma_cookie_t cookie_tx; |
| 93 | dma_cookie_t cookie_rx[2]; |
| 94 | dma_cookie_t active_rx; |
| 95 | struct scatterlist sg_tx; |
| 96 | unsigned int sg_len_tx; |
| 97 | struct scatterlist sg_rx[2]; |
| 98 | size_t buf_len_rx; |
| 99 | struct sh_dmae_slave param_tx; |
| 100 | struct sh_dmae_slave param_rx; |
| 101 | struct work_struct work_tx; |
| 102 | struct work_struct work_rx; |
| 103 | struct timer_list rx_timer; |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 104 | unsigned int rx_timeout; |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 105 | #endif |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 106 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 107 | struct notifier_block freq_transition; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 108 | }; |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* Function prototypes */ |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 111 | static void sci_start_tx(struct uart_port *port); |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 112 | static void sci_stop_tx(struct uart_port *port); |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 113 | static void sci_start_rx(struct uart_port *port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 115 | #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS |
| 116 | |
| 117 | static struct sci_port sci_ports[SCI_NPORTS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | static struct uart_driver sci_uart_driver; |
| 119 | |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 120 | static inline struct sci_port * |
| 121 | to_sci_port(struct uart_port *uart) |
| 122 | { |
| 123 | return container_of(uart, struct sci_port, port); |
| 124 | } |
| 125 | |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 126 | #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_SH_SCI_CONSOLE) |
Paul Mundt | 1f6fd5c | 2008-12-17 14:53:24 +0900 | [diff] [blame] | 127 | |
| 128 | #ifdef CONFIG_CONSOLE_POLL |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 129 | static int sci_poll_get_char(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | unsigned short status; |
| 132 | int c; |
| 133 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 134 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | status = sci_in(port, SCxSR); |
| 136 | if (status & SCxSR_ERRORS(port)) { |
Paul Mundt | 94c8b6d | 2011-01-20 23:26:18 +0900 | [diff] [blame] | 137 | sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | continue; |
| 139 | } |
Jason Wessel | 3f255eb | 2010-05-20 21:04:23 -0500 | [diff] [blame] | 140 | break; |
| 141 | } while (1); |
| 142 | |
| 143 | if (!(status & SCxSR_RDxF(port))) |
| 144 | return NO_POLL_CHAR; |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | c = sci_in(port, SCxRDR); |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 147 | |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 148 | /* Dummy read */ |
| 149 | sci_in(port, SCxSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | return c; |
| 153 | } |
Paul Mundt | 1f6fd5c | 2008-12-17 14:53:24 +0900 | [diff] [blame] | 154 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 156 | 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] | 157 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | unsigned short status; |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | do { |
| 161 | status = sci_in(port, SCxSR); |
| 162 | } while (!(status & SCxSR_TDxE(port))); |
| 163 | |
Paul Mundt | 272966c | 2008-11-13 17:46:06 +0900 | [diff] [blame] | 164 | sci_out(port, SCxTDR, c); |
SUGIOKA Toshinobu | dd0a3e7 | 2009-06-01 03:53:41 +0000 | [diff] [blame] | 165 | sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 167 | #endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Paul Mundt | 15c73aa | 2008-10-02 19:47:12 +0900 | [diff] [blame] | 169 | #if defined(__H8300H__) || defined(__H8300S__) |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 170 | static void sci_init_pins(struct uart_port *port, unsigned int cflag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
| 172 | int ch = (port->mapbase - SMR0) >> 3; |
| 173 | |
| 174 | /* set DDR regs */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 175 | H8300_GPIO_DDR(h8300_sci_pins[ch].port, |
| 176 | h8300_sci_pins[ch].rx, |
| 177 | H8300_GPIO_INPUT); |
| 178 | H8300_GPIO_DDR(h8300_sci_pins[ch].port, |
| 179 | h8300_sci_pins[ch].tx, |
| 180 | H8300_GPIO_OUTPUT); |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | /* tx mark output*/ |
| 183 | H8300_SCI_DR(ch) |= h8300_sci_pins[ch].tx; |
| 184 | } |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 185 | #elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712) |
| 186 | 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] | 187 | { |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 188 | if (port->mapbase == 0xA4400000) { |
| 189 | __raw_writew(__raw_readw(PACR) & 0xffc0, PACR); |
| 190 | __raw_writew(__raw_readw(PBCR) & 0x0fff, PBCR); |
| 191 | } else if (port->mapbase == 0xA4410000) |
| 192 | __raw_writew(__raw_readw(PBCR) & 0xf003, PBCR); |
Nobuhiro Iwamatsu | 9465a54 | 2007-03-27 18:13:51 +0900 | [diff] [blame] | 193 | } |
Yoshihiro Shimoda | 31a49c4 | 2007-12-26 11:45:06 +0900 | [diff] [blame] | 194 | #elif defined(CONFIG_CPU_SUBTYPE_SH7720) || defined(CONFIG_CPU_SUBTYPE_SH7721) |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 195 | 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] | 196 | { |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 197 | unsigned short data; |
| 198 | |
| 199 | if (cflag & CRTSCTS) { |
| 200 | /* enable RTS/CTS */ |
| 201 | if (port->mapbase == 0xa4430000) { /* SCIF0 */ |
| 202 | /* Clear PTCR bit 9-2; enable all scif pins but sck */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 203 | data = __raw_readw(PORT_PTCR); |
| 204 | __raw_writew((data & 0xfc03), PORT_PTCR); |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 205 | } else if (port->mapbase == 0xa4438000) { /* SCIF1 */ |
| 206 | /* Clear PVCR bit 9-2 */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 207 | data = __raw_readw(PORT_PVCR); |
| 208 | __raw_writew((data & 0xfc03), PORT_PVCR); |
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 | } else { |
| 211 | if (port->mapbase == 0xa4430000) { /* SCIF0 */ |
| 212 | /* Clear PTCR bit 5-2; enable only tx and rx */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 213 | data = __raw_readw(PORT_PTCR); |
| 214 | __raw_writew((data & 0xffc3), PORT_PTCR); |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 215 | } else if (port->mapbase == 0xa4438000) { /* SCIF1 */ |
| 216 | /* Clear PVCR bit 5-2 */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 217 | data = __raw_readw(PORT_PVCR); |
| 218 | __raw_writew((data & 0xffc3), PORT_PVCR); |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 219 | } |
| 220 | } |
Markus Brunner | 3ea6bc3 | 2007-08-20 08:59:33 +0900 | [diff] [blame] | 221 | } |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 222 | #elif defined(CONFIG_CPU_SH3) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 223 | /* For SH7705, SH7706, SH7707, SH7709, SH7709A, SH7729 */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 224 | 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] | 225 | { |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 226 | unsigned short data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 228 | /* We need to set SCPCR to enable RTS/CTS */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 229 | data = __raw_readw(SCPCR); |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 230 | /* Clear out SCP7MD1,0, SCP6MD1,0, SCP4MD1,0*/ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 231 | __raw_writew(data & 0x0fcf, SCPCR); |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 232 | |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 233 | if (!(cflag & CRTSCTS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | /* We need to set SCPCR to enable RTS/CTS */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 235 | data = __raw_readw(SCPCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | /* Clear out SCP7MD1,0, SCP4MD1,0, |
| 237 | Set SCP6MD1,0 = {01} (output) */ |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 238 | __raw_writew((data & 0x0fcf) | 0x1000, SCPCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Paul Mundt | 32b5307 | 2009-12-24 14:52:43 +0900 | [diff] [blame] | 240 | data = __raw_readb(SCPDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | /* Set /RTS2 (bit6) = 0 */ |
Paul Mundt | 32b5307 | 2009-12-24 14:52:43 +0900 | [diff] [blame] | 242 | __raw_writeb(data & 0xbf, SCPDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 245 | #elif defined(CONFIG_CPU_SUBTYPE_SH7722) |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 246 | 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] | 247 | { |
Magnus Damm | 346b746 | 2008-04-23 21:25:29 +0900 | [diff] [blame] | 248 | unsigned short data; |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 249 | |
Magnus Damm | 346b746 | 2008-04-23 21:25:29 +0900 | [diff] [blame] | 250 | if (port->mapbase == 0xffe00000) { |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 251 | data = __raw_readw(PSCR); |
Magnus Damm | 346b746 | 2008-04-23 21:25:29 +0900 | [diff] [blame] | 252 | data &= ~0x03cf; |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 253 | if (!(cflag & CRTSCTS)) |
Magnus Damm | 346b746 | 2008-04-23 21:25:29 +0900 | [diff] [blame] | 254 | data |= 0x0340; |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 255 | |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 256 | __raw_writew(data, PSCR); |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 257 | } |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 258 | } |
Yoshihiro Shimoda | c01f0f1 | 2009-08-21 16:30:28 +0900 | [diff] [blame] | 259 | #elif defined(CONFIG_CPU_SUBTYPE_SH7757) || \ |
| 260 | defined(CONFIG_CPU_SUBTYPE_SH7763) || \ |
Yoshihiro Shimoda | 7d740a0 | 2008-01-07 14:40:07 +0900 | [diff] [blame] | 261 | defined(CONFIG_CPU_SUBTYPE_SH7780) || \ |
Paul Mundt | 2b1bd1a | 2007-06-20 18:27:10 +0900 | [diff] [blame] | 262 | defined(CONFIG_CPU_SUBTYPE_SH7785) || \ |
Kuninori Morimoto | 55ba99e | 2009-03-03 15:40:25 +0900 | [diff] [blame] | 263 | defined(CONFIG_CPU_SUBTYPE_SH7786) || \ |
Paul Mundt | 2b1bd1a | 2007-06-20 18:27:10 +0900 | [diff] [blame] | 264 | defined(CONFIG_CPU_SUBTYPE_SHX3) |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 265 | static inline void sci_init_pins(struct uart_port *port, unsigned int cflag) |
| 266 | { |
| 267 | if (!(cflag & CRTSCTS)) |
| 268 | __raw_writew(0x0080, SCSPTR0); /* Set RTS = 1 */ |
| 269 | } |
Paul Mundt | b0c50ad | 2008-12-22 03:40:10 +0900 | [diff] [blame] | 270 | #elif defined(CONFIG_CPU_SH4) && !defined(CONFIG_CPU_SH4A) |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 271 | static inline void sci_init_pins(struct uart_port *port, unsigned int cflag) |
| 272 | { |
| 273 | if (!(cflag & CRTSCTS)) |
| 274 | __raw_writew(0x0080, SCSPTR2); /* Set RTS = 1 */ |
| 275 | } |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 276 | #else |
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 | /* Nothing to do */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 281 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Paul Mundt | 32351a2 | 2007-03-12 14:38:59 +0900 | [diff] [blame] | 283 | #if defined(CONFIG_CPU_SUBTYPE_SH7760) || \ |
| 284 | defined(CONFIG_CPU_SUBTYPE_SH7780) || \ |
Kuninori Morimoto | 55ba99e | 2009-03-03 15:40:25 +0900 | [diff] [blame] | 285 | defined(CONFIG_CPU_SUBTYPE_SH7785) || \ |
| 286 | defined(CONFIG_CPU_SUBTYPE_SH7786) |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 287 | static int scif_txfill(struct uart_port *port) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 288 | { |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 289 | return sci_in(port, SCTFDR) & 0xff; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 290 | } |
| 291 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 292 | static int scif_txroom(struct uart_port *port) |
| 293 | { |
| 294 | return SCIF_TXROOM_MAX - scif_txfill(port); |
| 295 | } |
| 296 | |
| 297 | static int scif_rxfill(struct uart_port *port) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 298 | { |
Yutaro Ebihara | cae167d | 2008-03-11 13:58:50 +0900 | [diff] [blame] | 299 | return sci_in(port, SCRFDR) & 0xff; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 300 | } |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 301 | #elif defined(CONFIG_CPU_SUBTYPE_SH7763) |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 302 | static int scif_txfill(struct uart_port *port) |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 303 | { |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 304 | if (port->mapbase == 0xffe00000 || |
| 305 | port->mapbase == 0xffe08000) |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 306 | /* SCIF0/1*/ |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 307 | return sci_in(port, SCTFDR) & 0xff; |
| 308 | else |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 309 | /* SCIF2 */ |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 310 | return sci_in(port, SCFDR) >> 8; |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 311 | } |
| 312 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 313 | static int scif_txroom(struct uart_port *port) |
| 314 | { |
| 315 | if (port->mapbase == 0xffe00000 || |
| 316 | port->mapbase == 0xffe08000) |
| 317 | /* SCIF0/1*/ |
| 318 | return SCIF_TXROOM_MAX - scif_txfill(port); |
| 319 | else |
| 320 | /* SCIF2 */ |
| 321 | return SCIF2_TXROOM_MAX - scif_txfill(port); |
| 322 | } |
| 323 | |
| 324 | static int scif_rxfill(struct uart_port *port) |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 325 | { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 326 | if ((port->mapbase == 0xffe00000) || |
| 327 | (port->mapbase == 0xffe08000)) { |
| 328 | /* SCIF0/1*/ |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 329 | return sci_in(port, SCRFDR) & 0xff; |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 330 | } else { |
| 331 | /* SCIF2 */ |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 332 | return sci_in(port, SCFDR) & SCIF2_RFDC_MASK; |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 333 | } |
Nobuhiro Iwamatsu | c63847a | 2008-06-06 17:04:08 +0900 | [diff] [blame] | 334 | } |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 335 | #elif defined(CONFIG_ARCH_SH7372) |
| 336 | static int scif_txfill(struct uart_port *port) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 337 | { |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 338 | if (port->type == PORT_SCIFA) |
| 339 | return sci_in(port, SCFDR) >> 8; |
| 340 | else |
| 341 | return sci_in(port, SCTFDR); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 342 | } |
| 343 | |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 344 | static int scif_txroom(struct uart_port *port) |
| 345 | { |
| 346 | return port->fifosize - scif_txfill(port); |
| 347 | } |
| 348 | |
| 349 | static int scif_rxfill(struct uart_port *port) |
| 350 | { |
| 351 | if (port->type == PORT_SCIFA) |
| 352 | return sci_in(port, SCFDR) & SCIF_RFDC_MASK; |
| 353 | else |
| 354 | return sci_in(port, SCRFDR); |
| 355 | } |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 356 | #else |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 357 | static int scif_txfill(struct uart_port *port) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 358 | { |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 359 | return sci_in(port, SCFDR) >> 8; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 360 | } |
| 361 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 362 | static int scif_txroom(struct uart_port *port) |
| 363 | { |
| 364 | return SCIF_TXROOM_MAX - scif_txfill(port); |
| 365 | } |
| 366 | |
| 367 | static int scif_rxfill(struct uart_port *port) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 368 | { |
| 369 | return sci_in(port, SCFDR) & SCIF_RFDC_MASK; |
| 370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 373 | static int sci_txfill(struct uart_port *port) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 374 | { |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 375 | return !(sci_in(port, SCxSR) & SCI_TDRE); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 376 | } |
| 377 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 378 | static int sci_txroom(struct uart_port *port) |
| 379 | { |
| 380 | return !sci_txfill(port); |
| 381 | } |
| 382 | |
| 383 | static int sci_rxfill(struct uart_port *port) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 384 | { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 385 | return (sci_in(port, SCxSR) & SCxSR_RDxF(port)) != 0; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 386 | } |
| 387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | /* ********************************************************************** * |
| 389 | * the interrupt related routines * |
| 390 | * ********************************************************************** */ |
| 391 | |
| 392 | static void sci_transmit_chars(struct uart_port *port) |
| 393 | { |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 394 | struct circ_buf *xmit = &port->state->xmit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | unsigned int stopped = uart_tx_stopped(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | unsigned short status; |
| 397 | unsigned short ctrl; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 398 | int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | status = sci_in(port, SCxSR); |
| 401 | if (!(status & SCxSR_TDxE(port))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | ctrl = sci_in(port, SCSCR); |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 403 | if (uart_circ_empty(xmit)) |
Paul Mundt | 8e69861 | 2009-06-24 19:44:32 +0900 | [diff] [blame] | 404 | ctrl &= ~SCSCR_TIE; |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 405 | else |
Paul Mundt | 8e69861 | 2009-06-24 19:44:32 +0900 | [diff] [blame] | 406 | ctrl |= SCSCR_TIE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | sci_out(port, SCSCR, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | return; |
| 409 | } |
| 410 | |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 411 | if (port->type == PORT_SCI) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 412 | count = sci_txroom(port); |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 413 | else |
| 414 | count = scif_txroom(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
| 416 | do { |
| 417 | unsigned char c; |
| 418 | |
| 419 | if (port->x_char) { |
| 420 | c = port->x_char; |
| 421 | port->x_char = 0; |
| 422 | } else if (!uart_circ_empty(xmit) && !stopped) { |
| 423 | c = xmit->buf[xmit->tail]; |
| 424 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 425 | } else { |
| 426 | break; |
| 427 | } |
| 428 | |
| 429 | sci_out(port, SCxTDR, c); |
| 430 | |
| 431 | port->icount.tx++; |
| 432 | } while (--count > 0); |
| 433 | |
| 434 | sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port)); |
| 435 | |
| 436 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 437 | uart_write_wakeup(port); |
| 438 | if (uart_circ_empty(xmit)) { |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 439 | sci_stop_tx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | ctrl = sci_in(port, SCSCR); |
| 442 | |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 443 | if (port->type != PORT_SCI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | sci_in(port, SCxSR); /* Dummy read */ |
| 445 | sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port)); |
| 446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Paul Mundt | 8e69861 | 2009-06-24 19:44:32 +0900 | [diff] [blame] | 448 | ctrl |= SCSCR_TIE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | sci_out(port, SCSCR, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
| 453 | /* 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] | 454 | #define STEPFN(c) ({int __c = (c); (((__c-1)|(__c)) == -1); }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Paul Mundt | 94c8b6d | 2011-01-20 23:26:18 +0900 | [diff] [blame] | 456 | static void sci_receive_chars(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 458 | struct sci_port *sci_port = to_sci_port(port); |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 459 | struct tty_struct *tty = port->state->port.tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | int i, count, copied = 0; |
| 461 | unsigned short status; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 462 | unsigned char flag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
| 464 | status = sci_in(port, SCxSR); |
| 465 | if (!(status & SCxSR_RDxF(port))) |
| 466 | return; |
| 467 | |
| 468 | while (1) { |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 469 | if (port->type == PORT_SCI) |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 470 | count = sci_rxfill(port); |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 471 | else |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 472 | count = scif_rxfill(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | /* 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] | 475 | count = tty_buffer_request_room(tty, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
| 477 | /* If for any reason we can't copy more data, we're done! */ |
| 478 | if (count == 0) |
| 479 | break; |
| 480 | |
| 481 | if (port->type == PORT_SCI) { |
| 482 | char c = sci_in(port, SCxRDR); |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 483 | if (uart_handle_sysrq_char(port, c) || |
| 484 | sci_port->break_flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | count = 0; |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 486 | else |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 487 | tty_insert_flip_char(tty, c, TTY_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } else { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 489 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | char c = sci_in(port, SCxRDR); |
| 491 | status = sci_in(port, SCxSR); |
| 492 | #if defined(CONFIG_CPU_SH3) |
| 493 | /* Skip "chars" during break */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 494 | if (sci_port->break_flag) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | if ((c == 0) && |
| 496 | (status & SCxSR_FER(port))) { |
| 497 | count--; i--; |
| 498 | continue; |
| 499 | } |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | /* Nonzero => end-of-break */ |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 502 | dev_dbg(port->dev, "debounce<%02x>\n", c); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 503 | sci_port->break_flag = 0; |
| 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | if (STEPFN(c)) { |
| 506 | count--; i--; |
| 507 | continue; |
| 508 | } |
| 509 | } |
| 510 | #endif /* CONFIG_CPU_SH3 */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 511 | if (uart_handle_sysrq_char(port, c)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | count--; i--; |
| 513 | continue; |
| 514 | } |
| 515 | |
| 516 | /* Store data and status */ |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 517 | if (status & SCxSR_FER(port)) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 518 | flag = TTY_FRAME; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 519 | dev_notice(port->dev, "frame error\n"); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 520 | } else if (status & SCxSR_PER(port)) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 521 | flag = TTY_PARITY; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 522 | dev_notice(port->dev, "parity error\n"); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 523 | } else |
| 524 | flag = TTY_NORMAL; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 525 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 526 | tty_insert_flip_char(tty, c, flag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | |
| 530 | sci_in(port, SCxSR); /* dummy read */ |
| 531 | sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | copied += count; |
| 534 | port->icount.rx += count; |
| 535 | } |
| 536 | |
| 537 | if (copied) { |
| 538 | /* Tell the rest of the system the news. New characters! */ |
| 539 | tty_flip_buffer_push(tty); |
| 540 | } else { |
| 541 | sci_in(port, SCxSR); /* dummy read */ |
| 542 | sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | #define SCI_BREAK_JIFFIES (HZ/20) |
Paul Mundt | 94c8b6d | 2011-01-20 23:26:18 +0900 | [diff] [blame] | 547 | |
| 548 | /* |
| 549 | * The sci generates interrupts during the break, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | * 1 per millisecond or so during the break period, for 9600 baud. |
| 551 | * So dont bother disabling interrupts. |
| 552 | * But dont want more than 1 break event. |
| 553 | * Use a kernel timer to periodically poll the rx line until |
| 554 | * the break is finished. |
| 555 | */ |
Paul Mundt | 94c8b6d | 2011-01-20 23:26:18 +0900 | [diff] [blame] | 556 | static inline void sci_schedule_break_timer(struct sci_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | { |
Paul Mundt | bc9b3f5 | 2011-01-20 23:30:19 +0900 | [diff] [blame] | 558 | mod_timer(&port->break_timer, jiffies + SCI_BREAK_JIFFIES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
Paul Mundt | 94c8b6d | 2011-01-20 23:26:18 +0900 | [diff] [blame] | 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | /* Ensure that two consecutive samples find the break over. */ |
| 562 | static void sci_break_timer(unsigned long data) |
| 563 | { |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 564 | struct sci_port *port = (struct sci_port *)data; |
| 565 | |
Magnus Damm | 5e50d2d | 2011-04-19 10:38:25 +0000 | [diff] [blame] | 566 | if (port->enable) |
| 567 | port->enable(&port->port); |
| 568 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 569 | if (sci_rxd_in(&port->port) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | port->break_flag = 1; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 571 | sci_schedule_break_timer(port); |
| 572 | } else if (port->break_flag == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | /* break is over. */ |
| 574 | port->break_flag = 2; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 575 | sci_schedule_break_timer(port); |
| 576 | } else |
| 577 | port->break_flag = 0; |
Magnus Damm | 5e50d2d | 2011-04-19 10:38:25 +0000 | [diff] [blame] | 578 | |
| 579 | if (port->disable) |
| 580 | port->disable(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Paul Mundt | 94c8b6d | 2011-01-20 23:26:18 +0900 | [diff] [blame] | 583 | static int sci_handle_errors(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | { |
| 585 | int copied = 0; |
| 586 | unsigned short status = sci_in(port, SCxSR); |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 587 | struct tty_struct *tty = port->state->port.tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 589 | if (status & SCxSR_ORER(port)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | /* overrun error */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 591 | if (tty_insert_flip_char(tty, 0, TTY_OVERRUN)) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 592 | copied++; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 593 | |
| 594 | dev_notice(port->dev, "overrun error"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 597 | if (status & SCxSR_FER(port)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | if (sci_rxd_in(port) == 0) { |
| 599 | /* Notify of BREAK */ |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 600 | struct sci_port *sci_port = to_sci_port(port); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 601 | |
| 602 | if (!sci_port->break_flag) { |
| 603 | sci_port->break_flag = 1; |
| 604 | sci_schedule_break_timer(sci_port); |
| 605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | /* Do sysrq handling. */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 607 | if (uart_handle_break(port)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | return 0; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 609 | |
| 610 | dev_dbg(port->dev, "BREAK detected\n"); |
| 611 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 612 | if (tty_insert_flip_char(tty, 0, TTY_BREAK)) |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 613 | copied++; |
| 614 | } |
| 615 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 616 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | /* frame error */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 618 | if (tty_insert_flip_char(tty, 0, TTY_FRAME)) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 619 | copied++; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 620 | |
| 621 | dev_notice(port->dev, "frame error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 625 | if (status & SCxSR_PER(port)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | /* parity error */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 627 | if (tty_insert_flip_char(tty, 0, TTY_PARITY)) |
| 628 | copied++; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 629 | |
| 630 | dev_notice(port->dev, "parity error"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 633 | if (copied) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | tty_flip_buffer_push(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
| 636 | return copied; |
| 637 | } |
| 638 | |
Paul Mundt | 94c8b6d | 2011-01-20 23:26:18 +0900 | [diff] [blame] | 639 | static int sci_handle_fifo_overrun(struct uart_port *port) |
Paul Mundt | d830fa4 | 2008-12-16 19:29:38 +0900 | [diff] [blame] | 640 | { |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 641 | struct tty_struct *tty = port->state->port.tty; |
Paul Mundt | d830fa4 | 2008-12-16 19:29:38 +0900 | [diff] [blame] | 642 | int copied = 0; |
| 643 | |
| 644 | if (port->type != PORT_SCIF) |
| 645 | return 0; |
| 646 | |
| 647 | if ((sci_in(port, SCLSR) & SCIF_ORER) != 0) { |
| 648 | sci_out(port, SCLSR, 0); |
| 649 | |
| 650 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); |
| 651 | tty_flip_buffer_push(tty); |
| 652 | |
| 653 | dev_notice(port->dev, "overrun error\n"); |
| 654 | copied++; |
| 655 | } |
| 656 | |
| 657 | return copied; |
| 658 | } |
| 659 | |
Paul Mundt | 94c8b6d | 2011-01-20 23:26:18 +0900 | [diff] [blame] | 660 | static int sci_handle_breaks(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | { |
| 662 | int copied = 0; |
| 663 | unsigned short status = sci_in(port, SCxSR); |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 664 | struct tty_struct *tty = port->state->port.tty; |
Magnus Damm | a5660ad | 2009-01-21 15:14:38 +0000 | [diff] [blame] | 665 | struct sci_port *s = to_sci_port(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
Paul Mundt | 0b3d4ef | 2007-03-14 13:22:37 +0900 | [diff] [blame] | 667 | if (uart_handle_break(port)) |
| 668 | return 0; |
| 669 | |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 670 | if (!s->break_flag && status & SCxSR_BRK(port)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | #if defined(CONFIG_CPU_SH3) |
| 672 | /* Debounce break */ |
| 673 | s->break_flag = 1; |
| 674 | #endif |
| 675 | /* Notify of BREAK */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 676 | if (tty_insert_flip_char(tty, 0, TTY_BREAK)) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 677 | copied++; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 678 | |
| 679 | dev_dbg(port->dev, "BREAK detected\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 682 | if (copied) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | tty_flip_buffer_push(tty); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 684 | |
Paul Mundt | d830fa4 | 2008-12-16 19:29:38 +0900 | [diff] [blame] | 685 | copied += sci_handle_fifo_overrun(port); |
| 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | return copied; |
| 688 | } |
| 689 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 690 | static irqreturn_t sci_rx_interrupt(int irq, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | { |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 692 | #ifdef CONFIG_SERIAL_SH_SCI_DMA |
| 693 | struct uart_port *port = ptr; |
| 694 | struct sci_port *s = to_sci_port(port); |
| 695 | |
| 696 | if (s->chan_rx) { |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 697 | u16 scr = sci_in(port, SCSCR); |
| 698 | u16 ssr = sci_in(port, SCxSR); |
| 699 | |
| 700 | /* Disable future Rx interrupts */ |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 701 | if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 702 | disable_irq_nosync(irq); |
| 703 | scr |= 0x4000; |
| 704 | } else { |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 705 | scr &= ~SCSCR_RIE; |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 706 | } |
| 707 | sci_out(port, SCSCR, scr); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 708 | /* Clear current interrupt */ |
| 709 | sci_out(port, SCxSR, ssr & ~(1 | SCxSR_RDxF(port))); |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 710 | dev_dbg(port->dev, "Rx IRQ %lu: setup t-out in %u jiffies\n", |
| 711 | jiffies, s->rx_timeout); |
| 712 | mod_timer(&s->rx_timer, jiffies + s->rx_timeout); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 713 | |
| 714 | return IRQ_HANDLED; |
| 715 | } |
| 716 | #endif |
| 717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | /* I think sci_receive_chars has to be called irrespective |
| 719 | * of whether the I_IXOFF is set, otherwise, how is the interrupt |
| 720 | * to be disabled? |
| 721 | */ |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 722 | sci_receive_chars(ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
| 724 | return IRQ_HANDLED; |
| 725 | } |
| 726 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 727 | static irqreturn_t sci_tx_interrupt(int irq, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
| 729 | struct uart_port *port = ptr; |
Stuart Menefy | fd78a76 | 2009-07-29 23:01:24 +0900 | [diff] [blame] | 730 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Stuart Menefy | fd78a76 | 2009-07-29 23:01:24 +0900 | [diff] [blame] | 732 | spin_lock_irqsave(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | sci_transmit_chars(port); |
Stuart Menefy | fd78a76 | 2009-07-29 23:01:24 +0900 | [diff] [blame] | 734 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
| 736 | return IRQ_HANDLED; |
| 737 | } |
| 738 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 739 | static irqreturn_t sci_er_interrupt(int irq, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | { |
| 741 | struct uart_port *port = ptr; |
| 742 | |
| 743 | /* Handle errors */ |
| 744 | if (port->type == PORT_SCI) { |
| 745 | if (sci_handle_errors(port)) { |
| 746 | /* discard character in rx buffer */ |
| 747 | sci_in(port, SCxSR); |
| 748 | sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); |
| 749 | } |
| 750 | } else { |
Paul Mundt | d830fa4 | 2008-12-16 19:29:38 +0900 | [diff] [blame] | 751 | sci_handle_fifo_overrun(port); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 752 | sci_rx_interrupt(irq, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port)); |
| 756 | |
| 757 | /* Kick the transmission */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 758 | sci_tx_interrupt(irq, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
| 760 | return IRQ_HANDLED; |
| 761 | } |
| 762 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 763 | static irqreturn_t sci_br_interrupt(int irq, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | { |
| 765 | struct uart_port *port = ptr; |
| 766 | |
| 767 | /* Handle BREAKs */ |
| 768 | sci_handle_breaks(port); |
| 769 | sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port)); |
| 770 | |
| 771 | return IRQ_HANDLED; |
| 772 | } |
| 773 | |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 774 | static inline unsigned long port_rx_irq_mask(struct uart_port *port) |
| 775 | { |
| 776 | /* |
| 777 | * Not all ports (such as SCIFA) will support REIE. Rather than |
| 778 | * special-casing the port type, we check the port initialization |
| 779 | * IRQ enable mask to see whether the IRQ is desired at all. If |
| 780 | * it's unset, it's logically inferred that there's no point in |
| 781 | * testing for it. |
| 782 | */ |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 783 | return SCSCR_RIE | (to_sci_port(port)->cfg->scscr & SCSCR_REIE); |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 784 | } |
| 785 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 786 | static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | { |
Magnus Damm | 44e18e9 | 2009-07-03 08:39:34 +0000 | [diff] [blame] | 788 | unsigned short ssr_status, scr_status, err_enabled; |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 789 | struct uart_port *port = ptr; |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 790 | struct sci_port *s = to_sci_port(port); |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 791 | irqreturn_t ret = IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 793 | ssr_status = sci_in(port, SCxSR); |
| 794 | scr_status = sci_in(port, SCSCR); |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 795 | err_enabled = scr_status & port_rx_irq_mask(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
| 797 | /* Tx Interrupt */ |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 798 | if ((ssr_status & SCxSR_TDxE(port)) && (scr_status & SCSCR_TIE) && |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 799 | !s->chan_tx) |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 800 | ret = sci_tx_interrupt(irq, ptr); |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 801 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 802 | /* |
| 803 | * Rx Interrupt: if we're using DMA, the DMA controller clears RDF / |
| 804 | * DR flags |
| 805 | */ |
| 806 | if (((ssr_status & SCxSR_RDxF(port)) || s->chan_rx) && |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 807 | (scr_status & SCSCR_RIE)) |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 808 | ret = sci_rx_interrupt(irq, ptr); |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | /* Error Interrupt */ |
SUGIOKA Toshinobu | dd4da3a | 2009-07-07 05:32:07 +0000 | [diff] [blame] | 811 | if ((ssr_status & SCxSR_ERRORS(port)) && err_enabled) |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 812 | ret = sci_er_interrupt(irq, ptr); |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | /* Break Interrupt */ |
SUGIOKA Toshinobu | dd4da3a | 2009-07-07 05:32:07 +0000 | [diff] [blame] | 815 | if ((ssr_status & SCxSR_BRK(port)) && err_enabled) |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 816 | ret = sci_br_interrupt(irq, ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Michael Trimarchi | a8884e3 | 2008-10-31 16:10:23 +0900 | [diff] [blame] | 818 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 822 | * Here we define a transition notifier so that we can update all of our |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | * ports' baud rate when the peripheral clock changes. |
| 824 | */ |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 825 | static int sci_notifier(struct notifier_block *self, |
| 826 | unsigned long phase, void *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | { |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 828 | struct sci_port *sci_port; |
| 829 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 831 | sci_port = container_of(self, struct sci_port, freq_transition); |
| 832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | if ((phase == CPUFREQ_POSTCHANGE) || |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 834 | (phase == CPUFREQ_RESUMECHANGE)) { |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 835 | struct uart_port *port = &sci_port->port; |
Paul Mundt | 073e84c | 2011-01-19 17:30:53 +0900 | [diff] [blame] | 836 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 837 | spin_lock_irqsave(&port->lock, flags); |
| 838 | port->uartclk = clk_get_rate(sci_port->iclk); |
| 839 | spin_unlock_irqrestore(&port->lock, flags); |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 840 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | return NOTIFY_OK; |
| 843 | } |
Magnus Damm | 501b825 | 2009-01-21 15:14:30 +0000 | [diff] [blame] | 844 | |
| 845 | static void sci_clk_enable(struct uart_port *port) |
| 846 | { |
| 847 | struct sci_port *sci_port = to_sci_port(port); |
| 848 | |
Magnus Damm | 5e50d2d | 2011-04-19 10:38:25 +0000 | [diff] [blame] | 849 | pm_runtime_get_sync(port->dev); |
| 850 | |
Paul Mundt | c7ed1ab | 2010-03-10 18:35:14 +0900 | [diff] [blame] | 851 | clk_enable(sci_port->iclk); |
| 852 | sci_port->port.uartclk = clk_get_rate(sci_port->iclk); |
| 853 | clk_enable(sci_port->fclk); |
Magnus Damm | 501b825 | 2009-01-21 15:14:30 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | static void sci_clk_disable(struct uart_port *port) |
| 857 | { |
| 858 | struct sci_port *sci_port = to_sci_port(port); |
| 859 | |
Paul Mundt | c7ed1ab | 2010-03-10 18:35:14 +0900 | [diff] [blame] | 860 | clk_disable(sci_port->fclk); |
| 861 | clk_disable(sci_port->iclk); |
Magnus Damm | 5e50d2d | 2011-04-19 10:38:25 +0000 | [diff] [blame] | 862 | |
| 863 | pm_runtime_put_sync(port->dev); |
Magnus Damm | 501b825 | 2009-01-21 15:14:30 +0000 | [diff] [blame] | 864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | static int sci_request_irq(struct sci_port *port) |
| 867 | { |
| 868 | int i; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 869 | irqreturn_t (*handlers[4])(int irq, void *ptr) = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | sci_er_interrupt, sci_rx_interrupt, sci_tx_interrupt, |
| 871 | sci_br_interrupt, |
| 872 | }; |
| 873 | const char *desc[] = { "SCI Receive Error", "SCI Receive Data Full", |
| 874 | "SCI Transmit Data Empty", "SCI Break" }; |
| 875 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 876 | if (port->cfg->irqs[0] == port->cfg->irqs[1]) { |
| 877 | if (unlikely(!port->cfg->irqs[0])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | return -ENODEV; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 879 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 880 | if (request_irq(port->cfg->irqs[0], sci_mpxed_interrupt, |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 881 | IRQF_DISABLED, "sci", port)) { |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 882 | dev_err(port->port.dev, "Can't allocate IRQ\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | return -ENODEV; |
| 884 | } |
| 885 | } else { |
| 886 | for (i = 0; i < ARRAY_SIZE(handlers); i++) { |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 887 | if (unlikely(!port->cfg->irqs[i])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | continue; |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 889 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 890 | if (request_irq(port->cfg->irqs[i], handlers[i], |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 891 | IRQF_DISABLED, desc[i], port)) { |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 892 | dev_err(port->port.dev, "Can't allocate IRQ\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | return -ENODEV; |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | static void sci_free_irq(struct sci_port *port) |
| 902 | { |
| 903 | int i; |
| 904 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 905 | if (port->cfg->irqs[0] == port->cfg->irqs[1]) |
| 906 | free_irq(port->cfg->irqs[0], port); |
Paul Mundt | 762c69e | 2008-12-16 18:55:26 +0900 | [diff] [blame] | 907 | else { |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 908 | for (i = 0; i < ARRAY_SIZE(port->cfg->irqs); i++) { |
| 909 | if (!port->cfg->irqs[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | continue; |
| 911 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 912 | free_irq(port->cfg->irqs[i], port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | static unsigned int sci_tx_empty(struct uart_port *port) |
| 918 | { |
Guennadi Liakhovetski | b151680 | 2009-12-01 09:54:46 +0000 | [diff] [blame] | 919 | unsigned short status = sci_in(port, SCxSR); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 920 | unsigned short in_tx_fifo = scif_txfill(port); |
| 921 | |
| 922 | return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 926 | { |
| 927 | /* This routine is used for seting signals of: DTR, DCD, CTS/RTS */ |
| 928 | /* We use SCIF's hardware for CTS/RTS, so don't need any for that. */ |
| 929 | /* If you have signals for DTR and DCD, please implement here. */ |
| 930 | } |
| 931 | |
| 932 | static unsigned int sci_get_mctrl(struct uart_port *port) |
| 933 | { |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 934 | /* This routine is used for getting signals of: DTR, DCD, DSR, RI, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | and CTS/RTS */ |
| 936 | |
| 937 | return TIOCM_DTR | TIOCM_RTS | TIOCM_DSR; |
| 938 | } |
| 939 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 940 | #ifdef CONFIG_SERIAL_SH_SCI_DMA |
| 941 | static void sci_dma_tx_complete(void *arg) |
| 942 | { |
| 943 | struct sci_port *s = arg; |
| 944 | struct uart_port *port = &s->port; |
| 945 | struct circ_buf *xmit = &port->state->xmit; |
| 946 | unsigned long flags; |
| 947 | |
| 948 | dev_dbg(port->dev, "%s(%d)\n", __func__, port->line); |
| 949 | |
| 950 | spin_lock_irqsave(&port->lock, flags); |
| 951 | |
Magnus Damm | f354a38 | 2010-03-19 04:47:01 +0000 | [diff] [blame] | 952 | xmit->tail += sg_dma_len(&s->sg_tx); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 953 | xmit->tail &= UART_XMIT_SIZE - 1; |
| 954 | |
Magnus Damm | f354a38 | 2010-03-19 04:47:01 +0000 | [diff] [blame] | 955 | port->icount.tx += sg_dma_len(&s->sg_tx); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 956 | |
| 957 | async_tx_ack(s->desc_tx); |
| 958 | s->cookie_tx = -EINVAL; |
| 959 | s->desc_tx = NULL; |
| 960 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 961 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 962 | uart_write_wakeup(port); |
| 963 | |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 964 | if (!uart_circ_empty(xmit)) { |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 965 | schedule_work(&s->work_tx); |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 966 | } else if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 967 | u16 ctrl = sci_in(port, SCSCR); |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 968 | sci_out(port, SCSCR, ctrl & ~SCSCR_TIE); |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | spin_unlock_irqrestore(&port->lock, flags); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | /* Locking: called with port lock held */ |
| 975 | static int sci_dma_rx_push(struct sci_port *s, struct tty_struct *tty, |
| 976 | size_t count) |
| 977 | { |
| 978 | struct uart_port *port = &s->port; |
| 979 | int i, active, room; |
| 980 | |
| 981 | room = tty_buffer_request_room(tty, count); |
| 982 | |
| 983 | if (s->active_rx == s->cookie_rx[0]) { |
| 984 | active = 0; |
| 985 | } else if (s->active_rx == s->cookie_rx[1]) { |
| 986 | active = 1; |
| 987 | } else { |
| 988 | dev_err(port->dev, "cookie %d not found!\n", s->active_rx); |
| 989 | return 0; |
| 990 | } |
| 991 | |
| 992 | if (room < count) |
| 993 | dev_warn(port->dev, "Rx overrun: dropping %u bytes\n", |
| 994 | count - room); |
| 995 | if (!room) |
| 996 | return room; |
| 997 | |
| 998 | for (i = 0; i < room; i++) |
| 999 | tty_insert_flip_char(tty, ((u8 *)sg_virt(&s->sg_rx[active]))[i], |
| 1000 | TTY_NORMAL); |
| 1001 | |
| 1002 | port->icount.rx += room; |
| 1003 | |
| 1004 | return room; |
| 1005 | } |
| 1006 | |
| 1007 | static void sci_dma_rx_complete(void *arg) |
| 1008 | { |
| 1009 | struct sci_port *s = arg; |
| 1010 | struct uart_port *port = &s->port; |
| 1011 | struct tty_struct *tty = port->state->port.tty; |
| 1012 | unsigned long flags; |
| 1013 | int count; |
| 1014 | |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1015 | dev_dbg(port->dev, "%s(%d) active #%d\n", __func__, port->line, s->active_rx); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1016 | |
| 1017 | spin_lock_irqsave(&port->lock, flags); |
| 1018 | |
| 1019 | count = sci_dma_rx_push(s, tty, s->buf_len_rx); |
| 1020 | |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1021 | mod_timer(&s->rx_timer, jiffies + s->rx_timeout); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1022 | |
| 1023 | spin_unlock_irqrestore(&port->lock, flags); |
| 1024 | |
| 1025 | if (count) |
| 1026 | tty_flip_buffer_push(tty); |
| 1027 | |
| 1028 | schedule_work(&s->work_rx); |
| 1029 | } |
| 1030 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1031 | static void sci_rx_dma_release(struct sci_port *s, bool enable_pio) |
| 1032 | { |
| 1033 | struct dma_chan *chan = s->chan_rx; |
| 1034 | struct uart_port *port = &s->port; |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1035 | |
| 1036 | s->chan_rx = NULL; |
| 1037 | s->cookie_rx[0] = s->cookie_rx[1] = -EINVAL; |
| 1038 | dma_release_channel(chan); |
Guennadi Liakhovetski | 85b8e3f | 2010-05-21 15:22:40 +0000 | [diff] [blame] | 1039 | if (sg_dma_address(&s->sg_rx[0])) |
| 1040 | dma_free_coherent(port->dev, s->buf_len_rx * 2, |
| 1041 | sg_virt(&s->sg_rx[0]), sg_dma_address(&s->sg_rx[0])); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1042 | if (enable_pio) |
| 1043 | sci_start_rx(port); |
| 1044 | } |
| 1045 | |
| 1046 | static void sci_tx_dma_release(struct sci_port *s, bool enable_pio) |
| 1047 | { |
| 1048 | struct dma_chan *chan = s->chan_tx; |
| 1049 | struct uart_port *port = &s->port; |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1050 | |
| 1051 | s->chan_tx = NULL; |
| 1052 | s->cookie_tx = -EINVAL; |
| 1053 | dma_release_channel(chan); |
| 1054 | if (enable_pio) |
| 1055 | sci_start_tx(port); |
| 1056 | } |
| 1057 | |
| 1058 | static void sci_submit_rx(struct sci_port *s) |
| 1059 | { |
| 1060 | struct dma_chan *chan = s->chan_rx; |
| 1061 | int i; |
| 1062 | |
| 1063 | for (i = 0; i < 2; i++) { |
| 1064 | struct scatterlist *sg = &s->sg_rx[i]; |
| 1065 | struct dma_async_tx_descriptor *desc; |
| 1066 | |
| 1067 | desc = chan->device->device_prep_slave_sg(chan, |
| 1068 | sg, 1, DMA_FROM_DEVICE, DMA_PREP_INTERRUPT); |
| 1069 | |
| 1070 | if (desc) { |
| 1071 | s->desc_rx[i] = desc; |
| 1072 | desc->callback = sci_dma_rx_complete; |
| 1073 | desc->callback_param = s; |
| 1074 | s->cookie_rx[i] = desc->tx_submit(desc); |
| 1075 | } |
| 1076 | |
| 1077 | if (!desc || s->cookie_rx[i] < 0) { |
| 1078 | if (i) { |
| 1079 | async_tx_ack(s->desc_rx[0]); |
| 1080 | s->cookie_rx[0] = -EINVAL; |
| 1081 | } |
| 1082 | if (desc) { |
| 1083 | async_tx_ack(desc); |
| 1084 | s->cookie_rx[i] = -EINVAL; |
| 1085 | } |
| 1086 | dev_warn(s->port.dev, |
| 1087 | "failed to re-start DMA, using PIO\n"); |
| 1088 | sci_rx_dma_release(s, true); |
| 1089 | return; |
| 1090 | } |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1091 | dev_dbg(s->port.dev, "%s(): cookie %d to #%d\n", __func__, |
| 1092 | s->cookie_rx[i], i); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | s->active_rx = s->cookie_rx[0]; |
| 1096 | |
| 1097 | dma_async_issue_pending(chan); |
| 1098 | } |
| 1099 | |
| 1100 | static void work_fn_rx(struct work_struct *work) |
| 1101 | { |
| 1102 | struct sci_port *s = container_of(work, struct sci_port, work_rx); |
| 1103 | struct uart_port *port = &s->port; |
| 1104 | struct dma_async_tx_descriptor *desc; |
| 1105 | int new; |
| 1106 | |
| 1107 | if (s->active_rx == s->cookie_rx[0]) { |
| 1108 | new = 0; |
| 1109 | } else if (s->active_rx == s->cookie_rx[1]) { |
| 1110 | new = 1; |
| 1111 | } else { |
| 1112 | dev_err(port->dev, "cookie %d not found!\n", s->active_rx); |
| 1113 | return; |
| 1114 | } |
| 1115 | desc = s->desc_rx[new]; |
| 1116 | |
| 1117 | if (dma_async_is_tx_complete(s->chan_rx, s->active_rx, NULL, NULL) != |
| 1118 | DMA_SUCCESS) { |
| 1119 | /* Handle incomplete DMA receive */ |
| 1120 | struct tty_struct *tty = port->state->port.tty; |
| 1121 | struct dma_chan *chan = s->chan_rx; |
| 1122 | struct sh_desc *sh_desc = container_of(desc, struct sh_desc, |
| 1123 | async_tx); |
| 1124 | unsigned long flags; |
| 1125 | int count; |
| 1126 | |
Linus Walleij | 0582763 | 2010-05-17 16:30:42 -0700 | [diff] [blame] | 1127 | chan->device->device_control(chan, DMA_TERMINATE_ALL, 0); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1128 | dev_dbg(port->dev, "Read %u bytes with cookie %d\n", |
| 1129 | sh_desc->partial, sh_desc->cookie); |
| 1130 | |
| 1131 | spin_lock_irqsave(&port->lock, flags); |
| 1132 | count = sci_dma_rx_push(s, tty, sh_desc->partial); |
| 1133 | spin_unlock_irqrestore(&port->lock, flags); |
| 1134 | |
| 1135 | if (count) |
| 1136 | tty_flip_buffer_push(tty); |
| 1137 | |
| 1138 | sci_submit_rx(s); |
| 1139 | |
| 1140 | return; |
| 1141 | } |
| 1142 | |
| 1143 | s->cookie_rx[new] = desc->tx_submit(desc); |
| 1144 | if (s->cookie_rx[new] < 0) { |
| 1145 | dev_warn(port->dev, "Failed submitting Rx DMA descriptor\n"); |
| 1146 | sci_rx_dma_release(s, true); |
| 1147 | return; |
| 1148 | } |
| 1149 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1150 | s->active_rx = s->cookie_rx[!new]; |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1151 | |
| 1152 | dev_dbg(port->dev, "%s: cookie %d #%d, new active #%d\n", __func__, |
| 1153 | s->cookie_rx[new], new, s->active_rx); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | static void work_fn_tx(struct work_struct *work) |
| 1157 | { |
| 1158 | struct sci_port *s = container_of(work, struct sci_port, work_tx); |
| 1159 | struct dma_async_tx_descriptor *desc; |
| 1160 | struct dma_chan *chan = s->chan_tx; |
| 1161 | struct uart_port *port = &s->port; |
| 1162 | struct circ_buf *xmit = &port->state->xmit; |
| 1163 | struct scatterlist *sg = &s->sg_tx; |
| 1164 | |
| 1165 | /* |
| 1166 | * DMA is idle now. |
| 1167 | * Port xmit buffer is already mapped, and it is one page... Just adjust |
| 1168 | * offsets and lengths. Since it is a circular buffer, we have to |
| 1169 | * transmit till the end, and then the rest. Take the port lock to get a |
| 1170 | * consistent xmit buffer state. |
| 1171 | */ |
| 1172 | spin_lock_irq(&port->lock); |
| 1173 | sg->offset = xmit->tail & (UART_XMIT_SIZE - 1); |
Magnus Damm | f354a38 | 2010-03-19 04:47:01 +0000 | [diff] [blame] | 1174 | sg_dma_address(sg) = (sg_dma_address(sg) & ~(UART_XMIT_SIZE - 1)) + |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1175 | sg->offset; |
Magnus Damm | f354a38 | 2010-03-19 04:47:01 +0000 | [diff] [blame] | 1176 | sg_dma_len(sg) = min((int)CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE), |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1177 | CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE)); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1178 | spin_unlock_irq(&port->lock); |
| 1179 | |
Magnus Damm | f354a38 | 2010-03-19 04:47:01 +0000 | [diff] [blame] | 1180 | BUG_ON(!sg_dma_len(sg)); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1181 | |
| 1182 | desc = chan->device->device_prep_slave_sg(chan, |
| 1183 | sg, s->sg_len_tx, DMA_TO_DEVICE, |
| 1184 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 1185 | if (!desc) { |
| 1186 | /* switch to PIO */ |
| 1187 | sci_tx_dma_release(s, true); |
| 1188 | return; |
| 1189 | } |
| 1190 | |
| 1191 | dma_sync_sg_for_device(port->dev, sg, 1, DMA_TO_DEVICE); |
| 1192 | |
| 1193 | spin_lock_irq(&port->lock); |
| 1194 | s->desc_tx = desc; |
| 1195 | desc->callback = sci_dma_tx_complete; |
| 1196 | desc->callback_param = s; |
| 1197 | spin_unlock_irq(&port->lock); |
| 1198 | s->cookie_tx = desc->tx_submit(desc); |
| 1199 | if (s->cookie_tx < 0) { |
| 1200 | dev_warn(port->dev, "Failed submitting Tx DMA descriptor\n"); |
| 1201 | /* switch to PIO */ |
| 1202 | sci_tx_dma_release(s, true); |
| 1203 | return; |
| 1204 | } |
| 1205 | |
| 1206 | dev_dbg(port->dev, "%s: %p: %d...%d, cookie %d\n", __func__, |
| 1207 | xmit->buf, xmit->tail, xmit->head, s->cookie_tx); |
| 1208 | |
| 1209 | dma_async_issue_pending(chan); |
| 1210 | } |
| 1211 | #endif |
| 1212 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1213 | static void sci_start_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | { |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1215 | struct sci_port *s = to_sci_port(port); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1216 | unsigned short ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1218 | #ifdef CONFIG_SERIAL_SH_SCI_DMA |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 1219 | if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1220 | u16 new, scr = sci_in(port, SCSCR); |
| 1221 | if (s->chan_tx) |
| 1222 | new = scr | 0x8000; |
| 1223 | else |
| 1224 | new = scr & ~0x8000; |
| 1225 | if (new != scr) |
| 1226 | sci_out(port, SCSCR, new); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1227 | } |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1228 | |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1229 | if (s->chan_tx && !uart_circ_empty(&s->port.state->xmit) && |
| 1230 | s->cookie_tx < 0) |
| 1231 | schedule_work(&s->work_tx); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1232 | #endif |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1233 | |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 1234 | if (!s->chan_tx || port->type == PORT_SCIFA || port->type == PORT_SCIFB) { |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1235 | /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */ |
| 1236 | ctrl = sci_in(port, SCSCR); |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1237 | sci_out(port, SCSCR, ctrl | SCSCR_TIE); |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1241 | static void sci_stop_tx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | unsigned short ctrl; |
| 1244 | |
| 1245 | /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | ctrl = sci_in(port, SCSCR); |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1247 | |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 1248 | if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1249 | ctrl &= ~0x8000; |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1250 | |
Paul Mundt | 8e69861 | 2009-06-24 19:44:32 +0900 | [diff] [blame] | 1251 | ctrl &= ~SCSCR_TIE; |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | sci_out(port, SCSCR, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1256 | static void sci_start_rx(struct uart_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | unsigned short ctrl; |
| 1259 | |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1260 | ctrl = sci_in(port, SCSCR) | port_rx_irq_mask(port); |
| 1261 | |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 1262 | if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1263 | ctrl &= ~0x4000; |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | sci_out(port, SCSCR, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | static void sci_stop_rx(struct uart_port *port) |
| 1269 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | unsigned short ctrl; |
| 1271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | ctrl = sci_in(port, SCSCR); |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1273 | |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 1274 | if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1275 | ctrl &= ~0x4000; |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1276 | |
| 1277 | ctrl &= ~port_rx_irq_mask(port); |
| 1278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | sci_out(port, SCSCR, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | static void sci_enable_ms(struct uart_port *port) |
| 1283 | { |
| 1284 | /* Nothing here yet .. */ |
| 1285 | } |
| 1286 | |
| 1287 | static void sci_break_ctl(struct uart_port *port, int break_state) |
| 1288 | { |
| 1289 | /* Nothing here yet .. */ |
| 1290 | } |
| 1291 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1292 | #ifdef CONFIG_SERIAL_SH_SCI_DMA |
| 1293 | static bool filter(struct dma_chan *chan, void *slave) |
| 1294 | { |
| 1295 | struct sh_dmae_slave *param = slave; |
| 1296 | |
| 1297 | dev_dbg(chan->device->dev, "%s: slave ID %d\n", __func__, |
| 1298 | param->slave_id); |
| 1299 | |
| 1300 | if (param->dma_dev == chan->device->dev) { |
| 1301 | chan->private = param; |
| 1302 | return true; |
| 1303 | } else { |
| 1304 | return false; |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | static void rx_timer_fn(unsigned long arg) |
| 1309 | { |
| 1310 | struct sci_port *s = (struct sci_port *)arg; |
| 1311 | struct uart_port *port = &s->port; |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1312 | u16 scr = sci_in(port, SCSCR); |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1313 | |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 1314 | if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1315 | scr &= ~0x4000; |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1316 | enable_irq(s->cfg->irqs[1]); |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1317 | } |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1318 | sci_out(port, SCSCR, scr | SCSCR_RIE); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1319 | dev_dbg(port->dev, "DMA Rx timed out\n"); |
| 1320 | schedule_work(&s->work_rx); |
| 1321 | } |
| 1322 | |
| 1323 | static void sci_request_dma(struct uart_port *port) |
| 1324 | { |
| 1325 | struct sci_port *s = to_sci_port(port); |
| 1326 | struct sh_dmae_slave *param; |
| 1327 | struct dma_chan *chan; |
| 1328 | dma_cap_mask_t mask; |
| 1329 | int nent; |
| 1330 | |
| 1331 | dev_dbg(port->dev, "%s: port %d DMA %p\n", __func__, |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1332 | port->line, s->cfg->dma_dev); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1333 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1334 | if (!s->cfg->dma_dev) |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1335 | return; |
| 1336 | |
| 1337 | dma_cap_zero(mask); |
| 1338 | dma_cap_set(DMA_SLAVE, mask); |
| 1339 | |
| 1340 | param = &s->param_tx; |
| 1341 | |
| 1342 | /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_TX */ |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1343 | param->slave_id = s->cfg->dma_slave_tx; |
| 1344 | param->dma_dev = s->cfg->dma_dev; |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1345 | |
| 1346 | s->cookie_tx = -EINVAL; |
| 1347 | chan = dma_request_channel(mask, filter, param); |
| 1348 | dev_dbg(port->dev, "%s: TX: got channel %p\n", __func__, chan); |
| 1349 | if (chan) { |
| 1350 | s->chan_tx = chan; |
| 1351 | sg_init_table(&s->sg_tx, 1); |
| 1352 | /* UART circular tx buffer is an aligned page. */ |
| 1353 | BUG_ON((int)port->state->xmit.buf & ~PAGE_MASK); |
| 1354 | sg_set_page(&s->sg_tx, virt_to_page(port->state->xmit.buf), |
| 1355 | UART_XMIT_SIZE, (int)port->state->xmit.buf & ~PAGE_MASK); |
| 1356 | nent = dma_map_sg(port->dev, &s->sg_tx, 1, DMA_TO_DEVICE); |
| 1357 | if (!nent) |
| 1358 | sci_tx_dma_release(s, false); |
| 1359 | else |
| 1360 | dev_dbg(port->dev, "%s: mapped %d@%p to %x\n", __func__, |
| 1361 | sg_dma_len(&s->sg_tx), |
| 1362 | port->state->xmit.buf, sg_dma_address(&s->sg_tx)); |
| 1363 | |
| 1364 | s->sg_len_tx = nent; |
| 1365 | |
| 1366 | INIT_WORK(&s->work_tx, work_fn_tx); |
| 1367 | } |
| 1368 | |
| 1369 | param = &s->param_rx; |
| 1370 | |
| 1371 | /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_RX */ |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1372 | param->slave_id = s->cfg->dma_slave_rx; |
| 1373 | param->dma_dev = s->cfg->dma_dev; |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1374 | |
| 1375 | chan = dma_request_channel(mask, filter, param); |
| 1376 | dev_dbg(port->dev, "%s: RX: got channel %p\n", __func__, chan); |
| 1377 | if (chan) { |
| 1378 | dma_addr_t dma[2]; |
| 1379 | void *buf[2]; |
| 1380 | int i; |
| 1381 | |
| 1382 | s->chan_rx = chan; |
| 1383 | |
| 1384 | s->buf_len_rx = 2 * max(16, (int)port->fifosize); |
| 1385 | buf[0] = dma_alloc_coherent(port->dev, s->buf_len_rx * 2, |
| 1386 | &dma[0], GFP_KERNEL); |
| 1387 | |
| 1388 | if (!buf[0]) { |
| 1389 | dev_warn(port->dev, |
| 1390 | "failed to allocate dma buffer, using PIO\n"); |
| 1391 | sci_rx_dma_release(s, true); |
| 1392 | return; |
| 1393 | } |
| 1394 | |
| 1395 | buf[1] = buf[0] + s->buf_len_rx; |
| 1396 | dma[1] = dma[0] + s->buf_len_rx; |
| 1397 | |
| 1398 | for (i = 0; i < 2; i++) { |
| 1399 | struct scatterlist *sg = &s->sg_rx[i]; |
| 1400 | |
| 1401 | sg_init_table(sg, 1); |
| 1402 | sg_set_page(sg, virt_to_page(buf[i]), s->buf_len_rx, |
| 1403 | (int)buf[i] & ~PAGE_MASK); |
Magnus Damm | f354a38 | 2010-03-19 04:47:01 +0000 | [diff] [blame] | 1404 | sg_dma_address(sg) = dma[i]; |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | INIT_WORK(&s->work_rx, work_fn_rx); |
| 1408 | setup_timer(&s->rx_timer, rx_timer_fn, (unsigned long)s); |
| 1409 | |
| 1410 | sci_submit_rx(s); |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | static void sci_free_dma(struct uart_port *port) |
| 1415 | { |
| 1416 | struct sci_port *s = to_sci_port(port); |
| 1417 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1418 | if (!s->cfg->dma_dev) |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1419 | return; |
| 1420 | |
| 1421 | if (s->chan_tx) |
| 1422 | sci_tx_dma_release(s, false); |
| 1423 | if (s->chan_rx) |
| 1424 | sci_rx_dma_release(s, false); |
| 1425 | } |
Paul Mundt | 27bd107 | 2011-01-19 15:37:31 +0900 | [diff] [blame] | 1426 | #else |
| 1427 | static inline void sci_request_dma(struct uart_port *port) |
| 1428 | { |
| 1429 | } |
| 1430 | |
| 1431 | static inline void sci_free_dma(struct uart_port *port) |
| 1432 | { |
| 1433 | } |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1434 | #endif |
| 1435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | static int sci_startup(struct uart_port *port) |
| 1437 | { |
Magnus Damm | a5660ad | 2009-01-21 15:14:38 +0000 | [diff] [blame] | 1438 | struct sci_port *s = to_sci_port(port); |
Paul Mundt | 073e84c | 2011-01-19 17:30:53 +0900 | [diff] [blame] | 1439 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1441 | dev_dbg(port->dev, "%s(%d)\n", __func__, port->line); |
| 1442 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1443 | if (s->enable) |
| 1444 | s->enable(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | |
Paul Mundt | 073e84c | 2011-01-19 17:30:53 +0900 | [diff] [blame] | 1446 | ret = sci_request_irq(s); |
| 1447 | if (unlikely(ret < 0)) |
| 1448 | return ret; |
| 1449 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1450 | sci_request_dma(port); |
Paul Mundt | 073e84c | 2011-01-19 17:30:53 +0900 | [diff] [blame] | 1451 | |
Yoshinori Sato | d656901 | 2005-10-14 15:59:12 -0700 | [diff] [blame] | 1452 | sci_start_tx(port); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1453 | sci_start_rx(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | |
| 1455 | return 0; |
| 1456 | } |
| 1457 | |
| 1458 | static void sci_shutdown(struct uart_port *port) |
| 1459 | { |
Magnus Damm | a5660ad | 2009-01-21 15:14:38 +0000 | [diff] [blame] | 1460 | struct sci_port *s = to_sci_port(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1462 | dev_dbg(port->dev, "%s(%d)\n", __func__, port->line); |
| 1463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | sci_stop_rx(port); |
Russell King | b129a8c | 2005-08-31 10:12:14 +0100 | [diff] [blame] | 1465 | sci_stop_tx(port); |
Paul Mundt | 073e84c | 2011-01-19 17:30:53 +0900 | [diff] [blame] | 1466 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1467 | sci_free_dma(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | sci_free_irq(s); |
| 1469 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1470 | if (s->disable) |
| 1471 | s->disable(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Paul Mundt | 26c92f3 | 2009-06-24 18:23:52 +0900 | [diff] [blame] | 1474 | static unsigned int sci_scbrr_calc(unsigned int algo_id, unsigned int bps, |
| 1475 | unsigned long freq) |
| 1476 | { |
| 1477 | switch (algo_id) { |
| 1478 | case SCBRR_ALGO_1: |
| 1479 | return ((freq + 16 * bps) / (16 * bps) - 1); |
| 1480 | case SCBRR_ALGO_2: |
| 1481 | return ((freq + 16 * bps) / (32 * bps) - 1); |
| 1482 | case SCBRR_ALGO_3: |
| 1483 | return (((freq * 2) + 16 * bps) / (16 * bps) - 1); |
| 1484 | case SCBRR_ALGO_4: |
| 1485 | return (((freq * 2) + 16 * bps) / (32 * bps) - 1); |
| 1486 | case SCBRR_ALGO_5: |
| 1487 | return (((freq * 1000 / 32) / bps) - 1); |
| 1488 | } |
| 1489 | |
| 1490 | /* Warn, but use a safe default */ |
| 1491 | WARN_ON(1); |
Paul Mundt | e8183a6 | 2011-01-19 17:51:37 +0900 | [diff] [blame] | 1492 | |
Paul Mundt | 26c92f3 | 2009-06-24 18:23:52 +0900 | [diff] [blame] | 1493 | return ((freq + 16 * bps) / (32 * bps) - 1); |
| 1494 | } |
| 1495 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1496 | static void sci_set_termios(struct uart_port *port, struct ktermios *termios, |
| 1497 | struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | { |
Paul Mundt | 00b9de9 | 2009-06-24 17:53:33 +0900 | [diff] [blame] | 1499 | struct sci_port *s = to_sci_port(port); |
Magnus Damm | 154280f | 2009-12-22 03:37:28 +0000 | [diff] [blame] | 1500 | unsigned int status, baud, smr_val, max_baud; |
Paul Mundt | a2159b5 | 2008-10-02 19:09:13 +0900 | [diff] [blame] | 1501 | int t = -1; |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1502 | u16 scfcr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | |
Magnus Damm | 154280f | 2009-12-22 03:37:28 +0000 | [diff] [blame] | 1504 | /* |
| 1505 | * earlyprintk comes here early on with port->uartclk set to zero. |
| 1506 | * the clock framework is not up and running at this point so here |
| 1507 | * we assume that 115200 is the maximum baud rate. please note that |
| 1508 | * the baud rate is not programmed during earlyprintk - it is assumed |
| 1509 | * that the previous boot loader has enabled required clocks and |
| 1510 | * setup the baud rate generator hardware for us already. |
| 1511 | */ |
| 1512 | max_baud = port->uartclk ? port->uartclk / 16 : 115200; |
| 1513 | |
| 1514 | baud = uart_get_baud_rate(port, termios, old, 0, max_baud); |
| 1515 | if (likely(baud && port->uartclk)) |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1516 | t = sci_scbrr_calc(s->cfg->scbrr_algo_id, baud, port->uartclk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
Alexandre Courbot | 3600338 | 2011-03-03 08:04:42 +0000 | [diff] [blame] | 1518 | if (s->enable) |
| 1519 | s->enable(port); |
| 1520 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1521 | do { |
| 1522 | status = sci_in(port, SCxSR); |
| 1523 | } while (!(status & SCxSR_TEND(port))); |
| 1524 | |
| 1525 | sci_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */ |
| 1526 | |
Yoshihiro Shimoda | 1a22f08 | 2008-11-11 12:19:05 +0900 | [diff] [blame] | 1527 | if (port->type != PORT_SCI) |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1528 | sci_out(port, SCFCR, scfcr | SCFCR_RFRST | SCFCR_TFRST); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1529 | |
| 1530 | smr_val = sci_in(port, SCSMR) & 3; |
Paul Mundt | e8183a6 | 2011-01-19 17:51:37 +0900 | [diff] [blame] | 1531 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1532 | if ((termios->c_cflag & CSIZE) == CS7) |
| 1533 | smr_val |= 0x40; |
| 1534 | if (termios->c_cflag & PARENB) |
| 1535 | smr_val |= 0x20; |
| 1536 | if (termios->c_cflag & PARODD) |
| 1537 | smr_val |= 0x30; |
| 1538 | if (termios->c_cflag & CSTOPB) |
| 1539 | smr_val |= 0x08; |
| 1540 | |
| 1541 | uart_update_timeout(port, termios->c_cflag, baud); |
| 1542 | |
| 1543 | sci_out(port, SCSMR, smr_val); |
| 1544 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1545 | dev_dbg(port->dev, "%s: SMR %x, t %x, SCSCR %x\n", __func__, smr_val, t, |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1546 | s->cfg->scscr); |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | if (t > 0) { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 1549 | if (t >= 256) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1); |
| 1551 | t >>= 2; |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 1552 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3); |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 1554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | sci_out(port, SCBRR, t); |
| 1556 | udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */ |
| 1557 | } |
| 1558 | |
Paul Mundt | d570164 | 2008-12-16 20:07:27 +0900 | [diff] [blame] | 1559 | sci_init_pins(port, termios->c_cflag); |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1560 | sci_out(port, SCFCR, scfcr | ((termios->c_cflag & CRTSCTS) ? SCFCR_MCE : 0)); |
Paul Mundt | b7a76e4 | 2006-02-01 03:06:06 -0800 | [diff] [blame] | 1561 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1562 | sci_out(port, SCSCR, s->cfg->scscr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | |
Guennadi Liakhovetski | 3089f38 | 2010-03-19 13:53:04 +0000 | [diff] [blame] | 1564 | #ifdef CONFIG_SERIAL_SH_SCI_DMA |
| 1565 | /* |
| 1566 | * Calculate delay for 1.5 DMA buffers: see |
| 1567 | * drivers/serial/serial_core.c::uart_update_timeout(). With 10 bits |
| 1568 | * (CS8), 250Hz, 115200 baud and 64 bytes FIFO, the above function |
| 1569 | * calculates 1 jiffie for the data plus 5 jiffies for the "slop(e)." |
| 1570 | * Then below we calculate 3 jiffies (12ms) for 1.5 DMA buffers (3 FIFO |
| 1571 | * sizes), but it has been found out experimentally, that this is not |
| 1572 | * enough: the driver too often needlessly runs on a DMA timeout. 20ms |
| 1573 | * as a minimum seem to work perfectly. |
| 1574 | */ |
| 1575 | if (s->chan_rx) { |
| 1576 | s->rx_timeout = (port->timeout - HZ / 50) * s->buf_len_rx * 3 / |
| 1577 | port->fifosize / 2; |
| 1578 | dev_dbg(port->dev, |
| 1579 | "DMA Rx t-out %ums, tty t-out %u jiffies\n", |
| 1580 | s->rx_timeout * 1000 / HZ, port->timeout); |
| 1581 | if (s->rx_timeout < msecs_to_jiffies(20)) |
| 1582 | s->rx_timeout = msecs_to_jiffies(20); |
| 1583 | } |
| 1584 | #endif |
| 1585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | if ((termios->c_cflag & CREAD) != 0) |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1587 | sci_start_rx(port); |
Alexandre Courbot | 3600338 | 2011-03-03 08:04:42 +0000 | [diff] [blame] | 1588 | |
| 1589 | if (s->disable) |
| 1590 | s->disable(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | static const char *sci_type(struct uart_port *port) |
| 1594 | { |
| 1595 | switch (port->type) { |
Michael Trimarchi | e7c98dc | 2008-11-13 18:18:35 +0900 | [diff] [blame] | 1596 | case PORT_IRDA: |
| 1597 | return "irda"; |
| 1598 | case PORT_SCI: |
| 1599 | return "sci"; |
| 1600 | case PORT_SCIF: |
| 1601 | return "scif"; |
| 1602 | case PORT_SCIFA: |
| 1603 | return "scifa"; |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 1604 | case PORT_SCIFB: |
| 1605 | return "scifb"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 1608 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
Paul Mundt | e265164 | 2011-01-20 21:24:03 +0900 | [diff] [blame] | 1611 | static inline unsigned long sci_port_size(struct uart_port *port) |
| 1612 | { |
| 1613 | /* |
| 1614 | * Pick an arbitrary size that encapsulates all of the base |
| 1615 | * registers by default. This can be optimized later, or derived |
| 1616 | * from platform resource data at such a time that ports begin to |
| 1617 | * behave more erratically. |
| 1618 | */ |
| 1619 | return 64; |
| 1620 | } |
| 1621 | |
Paul Mundt | f6e9495 | 2011-01-21 15:25:36 +0900 | [diff] [blame] | 1622 | static int sci_remap_port(struct uart_port *port) |
| 1623 | { |
| 1624 | unsigned long size = sci_port_size(port); |
| 1625 | |
| 1626 | /* |
| 1627 | * Nothing to do if there's already an established membase. |
| 1628 | */ |
| 1629 | if (port->membase) |
| 1630 | return 0; |
| 1631 | |
| 1632 | if (port->flags & UPF_IOREMAP) { |
| 1633 | port->membase = ioremap_nocache(port->mapbase, size); |
| 1634 | if (unlikely(!port->membase)) { |
| 1635 | dev_err(port->dev, "can't remap port#%d\n", port->line); |
| 1636 | return -ENXIO; |
| 1637 | } |
| 1638 | } else { |
| 1639 | /* |
| 1640 | * For the simple (and majority of) cases where we don't |
| 1641 | * need to do any remapping, just cast the cookie |
| 1642 | * directly. |
| 1643 | */ |
| 1644 | port->membase = (void __iomem *)port->mapbase; |
| 1645 | } |
| 1646 | |
| 1647 | return 0; |
| 1648 | } |
| 1649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | static void sci_release_port(struct uart_port *port) |
| 1651 | { |
Paul Mundt | e265164 | 2011-01-20 21:24:03 +0900 | [diff] [blame] | 1652 | if (port->flags & UPF_IOREMAP) { |
| 1653 | iounmap(port->membase); |
| 1654 | port->membase = NULL; |
| 1655 | } |
| 1656 | |
| 1657 | release_mem_region(port->mapbase, sci_port_size(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | static int sci_request_port(struct uart_port *port) |
| 1661 | { |
Paul Mundt | e265164 | 2011-01-20 21:24:03 +0900 | [diff] [blame] | 1662 | unsigned long size = sci_port_size(port); |
| 1663 | struct resource *res; |
Paul Mundt | f6e9495 | 2011-01-21 15:25:36 +0900 | [diff] [blame] | 1664 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | |
Paul Mundt | 1020520 | 2011-01-21 16:00:31 +0900 | [diff] [blame] | 1666 | res = request_mem_region(port->mapbase, size, dev_name(port->dev)); |
Paul Mundt | e265164 | 2011-01-20 21:24:03 +0900 | [diff] [blame] | 1667 | if (unlikely(res == NULL)) |
| 1668 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | |
Paul Mundt | f6e9495 | 2011-01-21 15:25:36 +0900 | [diff] [blame] | 1670 | ret = sci_remap_port(port); |
| 1671 | if (unlikely(ret != 0)) { |
| 1672 | release_resource(res); |
| 1673 | return ret; |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 1674 | } |
Paul Mundt | e265164 | 2011-01-20 21:24:03 +0900 | [diff] [blame] | 1675 | |
| 1676 | return 0; |
| 1677 | } |
| 1678 | |
| 1679 | static void sci_config_port(struct uart_port *port, int flags) |
| 1680 | { |
| 1681 | if (flags & UART_CONFIG_TYPE) { |
| 1682 | struct sci_port *sport = to_sci_port(port); |
| 1683 | |
| 1684 | port->type = sport->cfg->type; |
| 1685 | sci_request_port(port); |
| 1686 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | static int sci_verify_port(struct uart_port *port, struct serial_struct *ser) |
| 1690 | { |
Magnus Damm | a5660ad | 2009-01-21 15:14:38 +0000 | [diff] [blame] | 1691 | struct sci_port *s = to_sci_port(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1693 | if (ser->irq != s->cfg->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | return -EINVAL; |
| 1695 | if (ser->baud_base < 2400) |
| 1696 | /* No paper tape reader for Mitch.. */ |
| 1697 | return -EINVAL; |
| 1698 | |
| 1699 | return 0; |
| 1700 | } |
| 1701 | |
| 1702 | static struct uart_ops sci_uart_ops = { |
| 1703 | .tx_empty = sci_tx_empty, |
| 1704 | .set_mctrl = sci_set_mctrl, |
| 1705 | .get_mctrl = sci_get_mctrl, |
| 1706 | .start_tx = sci_start_tx, |
| 1707 | .stop_tx = sci_stop_tx, |
| 1708 | .stop_rx = sci_stop_rx, |
| 1709 | .enable_ms = sci_enable_ms, |
| 1710 | .break_ctl = sci_break_ctl, |
| 1711 | .startup = sci_startup, |
| 1712 | .shutdown = sci_shutdown, |
| 1713 | .set_termios = sci_set_termios, |
| 1714 | .type = sci_type, |
| 1715 | .release_port = sci_release_port, |
| 1716 | .request_port = sci_request_port, |
| 1717 | .config_port = sci_config_port, |
| 1718 | .verify_port = sci_verify_port, |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 1719 | #ifdef CONFIG_CONSOLE_POLL |
| 1720 | .poll_get_char = sci_poll_get_char, |
| 1721 | .poll_put_char = sci_poll_put_char, |
| 1722 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | }; |
| 1724 | |
Paul Mundt | c7ed1ab | 2010-03-10 18:35:14 +0900 | [diff] [blame] | 1725 | static int __devinit sci_init_single(struct platform_device *dev, |
| 1726 | struct sci_port *sci_port, |
| 1727 | unsigned int index, |
| 1728 | struct plat_sci_port *p) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1729 | { |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1730 | struct uart_port *port = &sci_port->port; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1731 | |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1732 | port->ops = &sci_uart_ops; |
| 1733 | port->iotype = UPIO_MEM; |
| 1734 | port->line = index; |
Markus Pietrek | 75136d4 | 2010-01-15 08:33:20 +0900 | [diff] [blame] | 1735 | |
| 1736 | switch (p->type) { |
Guennadi Liakhovetski | d1d4b10 | 2010-05-23 16:39:09 +0000 | [diff] [blame] | 1737 | case PORT_SCIFB: |
| 1738 | port->fifosize = 256; |
| 1739 | break; |
Markus Pietrek | 75136d4 | 2010-01-15 08:33:20 +0900 | [diff] [blame] | 1740 | case PORT_SCIFA: |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1741 | port->fifosize = 64; |
Markus Pietrek | 75136d4 | 2010-01-15 08:33:20 +0900 | [diff] [blame] | 1742 | break; |
| 1743 | case PORT_SCIF: |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1744 | port->fifosize = 16; |
Markus Pietrek | 75136d4 | 2010-01-15 08:33:20 +0900 | [diff] [blame] | 1745 | break; |
| 1746 | default: |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1747 | port->fifosize = 1; |
Markus Pietrek | 75136d4 | 2010-01-15 08:33:20 +0900 | [diff] [blame] | 1748 | break; |
| 1749 | } |
Magnus Damm | 7b6fd3b | 2009-12-14 10:24:42 +0000 | [diff] [blame] | 1750 | |
| 1751 | if (dev) { |
Paul Mundt | c7ed1ab | 2010-03-10 18:35:14 +0900 | [diff] [blame] | 1752 | sci_port->iclk = clk_get(&dev->dev, "sci_ick"); |
| 1753 | if (IS_ERR(sci_port->iclk)) { |
| 1754 | sci_port->iclk = clk_get(&dev->dev, "peripheral_clk"); |
| 1755 | if (IS_ERR(sci_port->iclk)) { |
| 1756 | dev_err(&dev->dev, "can't get iclk\n"); |
| 1757 | return PTR_ERR(sci_port->iclk); |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | /* |
| 1762 | * The function clock is optional, ignore it if we can't |
| 1763 | * find it. |
| 1764 | */ |
| 1765 | sci_port->fclk = clk_get(&dev->dev, "sci_fck"); |
| 1766 | if (IS_ERR(sci_port->fclk)) |
| 1767 | sci_port->fclk = NULL; |
| 1768 | |
Magnus Damm | 7b6fd3b | 2009-12-14 10:24:42 +0000 | [diff] [blame] | 1769 | sci_port->enable = sci_clk_enable; |
| 1770 | sci_port->disable = sci_clk_disable; |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1771 | port->dev = &dev->dev; |
Magnus Damm | 5e50d2d | 2011-04-19 10:38:25 +0000 | [diff] [blame] | 1772 | |
| 1773 | pm_runtime_enable(&dev->dev); |
Magnus Damm | 7b6fd3b | 2009-12-14 10:24:42 +0000 | [diff] [blame] | 1774 | } |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1775 | |
Magnus Damm | 7ed7e07 | 2009-01-21 15:14:14 +0000 | [diff] [blame] | 1776 | sci_port->break_timer.data = (unsigned long)sci_port; |
| 1777 | sci_port->break_timer.function = sci_break_timer; |
| 1778 | init_timer(&sci_port->break_timer); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1779 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1780 | sci_port->cfg = p; |
Magnus Damm | 7ed7e07 | 2009-01-21 15:14:14 +0000 | [diff] [blame] | 1781 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1782 | port->mapbase = p->mapbase; |
| 1783 | port->type = p->type; |
Paul Mundt | f43dc23 | 2011-01-13 15:06:28 +0900 | [diff] [blame] | 1784 | port->flags = p->flags; |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1785 | |
| 1786 | /* |
| 1787 | * The UART port needs an IRQ value, so we peg this to the TX IRQ |
| 1788 | * for the multi-IRQ ports, which is where we are primarily |
| 1789 | * concerned with the shutdown path synchronization. |
| 1790 | * |
| 1791 | * For the muxed case there's nothing more to do. |
| 1792 | */ |
Magnus Damm | 54aa89e | 2011-04-21 13:08:46 +0000 | [diff] [blame^] | 1793 | port->irq = p->irqs[SCIx_RXI_IRQ]; |
Guennadi Liakhovetski | 73a19e4 | 2010-03-02 11:39:15 +0900 | [diff] [blame] | 1794 | |
Paul Mundt | ce6738b | 2011-01-19 15:24:40 +0900 | [diff] [blame] | 1795 | if (p->dma_dev) |
| 1796 | dev_dbg(port->dev, "DMA device %p, tx %d, rx %d\n", |
| 1797 | p->dma_dev, p->dma_slave_tx, p->dma_slave_rx); |
Magnus Damm | 7ed7e07 | 2009-01-21 15:14:14 +0000 | [diff] [blame] | 1798 | |
Paul Mundt | c7ed1ab | 2010-03-10 18:35:14 +0900 | [diff] [blame] | 1799 | return 0; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1800 | } |
| 1801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE |
Magnus Damm | dc8e6f5 | 2009-01-21 15:14:06 +0000 | [diff] [blame] | 1803 | static void serial_console_putchar(struct uart_port *port, int ch) |
| 1804 | { |
| 1805 | sci_poll_put_char(port, ch); |
| 1806 | } |
| 1807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | /* |
| 1809 | * Print a string to the serial port trying not to disturb |
| 1810 | * any possible real use of the port... |
| 1811 | */ |
| 1812 | static void serial_console_write(struct console *co, const char *s, |
| 1813 | unsigned count) |
| 1814 | { |
Paul Mundt | 906b17d | 2011-01-21 16:19:53 +0900 | [diff] [blame] | 1815 | struct sci_port *sci_port = &sci_ports[co->index]; |
| 1816 | struct uart_port *port = &sci_port->port; |
Magnus Damm | 973e5d5 | 2009-02-24 15:57:12 +0900 | [diff] [blame] | 1817 | unsigned short bits; |
Paul Mundt | 07d2a1a | 2008-12-11 19:06:43 +0900 | [diff] [blame] | 1818 | |
Magnus Damm | 501b825 | 2009-01-21 15:14:30 +0000 | [diff] [blame] | 1819 | if (sci_port->enable) |
| 1820 | sci_port->enable(port); |
| 1821 | |
| 1822 | uart_console_write(port, s, count, serial_console_putchar); |
Magnus Damm | 973e5d5 | 2009-02-24 15:57:12 +0900 | [diff] [blame] | 1823 | |
| 1824 | /* wait until fifo is empty and last bit has been transmitted */ |
| 1825 | bits = SCxSR_TDxE(port) | SCxSR_TEND(port); |
| 1826 | while ((sci_in(port, SCxSR) & bits) != bits) |
| 1827 | cpu_relax(); |
Magnus Damm | 501b825 | 2009-01-21 15:14:30 +0000 | [diff] [blame] | 1828 | |
Magnus Damm | 345e5a7 | 2009-11-05 14:34:57 +0000 | [diff] [blame] | 1829 | if (sci_port->disable) |
Magnus Damm | 501b825 | 2009-01-21 15:14:30 +0000 | [diff] [blame] | 1830 | sci_port->disable(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
Magnus Damm | 7b6fd3b | 2009-12-14 10:24:42 +0000 | [diff] [blame] | 1833 | static int __devinit serial_console_setup(struct console *co, char *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | { |
Magnus Damm | dc8e6f5 | 2009-01-21 15:14:06 +0000 | [diff] [blame] | 1835 | struct sci_port *sci_port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | struct uart_port *port; |
| 1837 | int baud = 115200; |
| 1838 | int bits = 8; |
| 1839 | int parity = 'n'; |
| 1840 | int flow = 'n'; |
| 1841 | int ret; |
| 1842 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1843 | /* |
Paul Mundt | 906b17d | 2011-01-21 16:19:53 +0900 | [diff] [blame] | 1844 | * Refuse to handle any bogus ports. |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1845 | */ |
Paul Mundt | 906b17d | 2011-01-21 16:19:53 +0900 | [diff] [blame] | 1846 | if (co->index < 0 || co->index >= SCI_NPORTS) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1847 | return -ENODEV; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1848 | |
Paul Mundt | 906b17d | 2011-01-21 16:19:53 +0900 | [diff] [blame] | 1849 | sci_port = &sci_ports[co->index]; |
| 1850 | port = &sci_port->port; |
| 1851 | |
Alexandre Courbot | b2267a6 | 2011-02-09 03:18:46 +0000 | [diff] [blame] | 1852 | /* |
| 1853 | * Refuse to handle uninitialized ports. |
| 1854 | */ |
| 1855 | if (!port->ops) |
| 1856 | return -ENODEV; |
| 1857 | |
Paul Mundt | f6e9495 | 2011-01-21 15:25:36 +0900 | [diff] [blame] | 1858 | ret = sci_remap_port(port); |
| 1859 | if (unlikely(ret != 0)) |
| 1860 | return ret; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1861 | |
Magnus Damm | dc8e6f5 | 2009-01-21 15:14:06 +0000 | [diff] [blame] | 1862 | if (sci_port->enable) |
| 1863 | sci_port->enable(port); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | if (options) |
| 1866 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 1867 | |
| 1868 | ret = uart_set_options(port, co, baud, parity, bits, flow); |
| 1869 | #if defined(__H8300H__) || defined(__H8300S__) |
| 1870 | /* disable rx interrupt */ |
| 1871 | if (ret == 0) |
| 1872 | sci_stop_rx(port); |
| 1873 | #endif |
Magnus Damm | 501b825 | 2009-01-21 15:14:30 +0000 | [diff] [blame] | 1874 | /* TODO: disable clock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | return ret; |
| 1876 | } |
| 1877 | |
| 1878 | static struct console serial_console = { |
| 1879 | .name = "ttySC", |
Paul Mundt | 906b17d | 2011-01-21 16:19:53 +0900 | [diff] [blame] | 1880 | .device = uart_console_device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | .write = serial_console_write, |
| 1882 | .setup = serial_console_setup, |
Paul Mundt | fa5da2f | 2007-03-08 17:27:37 +0900 | [diff] [blame] | 1883 | .flags = CON_PRINTBUFFER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | .index = -1, |
Paul Mundt | 906b17d | 2011-01-21 16:19:53 +0900 | [diff] [blame] | 1885 | .data = &sci_uart_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | }; |
| 1887 | |
Magnus Damm | 7b6fd3b | 2009-12-14 10:24:42 +0000 | [diff] [blame] | 1888 | static struct console early_serial_console = { |
| 1889 | .name = "early_ttySC", |
| 1890 | .write = serial_console_write, |
| 1891 | .flags = CON_PRINTBUFFER, |
Paul Mundt | 906b17d | 2011-01-21 16:19:53 +0900 | [diff] [blame] | 1892 | .index = -1, |
Magnus Damm | 7b6fd3b | 2009-12-14 10:24:42 +0000 | [diff] [blame] | 1893 | }; |
Paul Mundt | ecdf8a4 | 2011-01-21 00:05:48 +0900 | [diff] [blame] | 1894 | |
Magnus Damm | 7b6fd3b | 2009-12-14 10:24:42 +0000 | [diff] [blame] | 1895 | static char early_serial_buf[32]; |
| 1896 | |
Paul Mundt | ecdf8a4 | 2011-01-21 00:05:48 +0900 | [diff] [blame] | 1897 | static int __devinit sci_probe_earlyprintk(struct platform_device *pdev) |
| 1898 | { |
| 1899 | struct plat_sci_port *cfg = pdev->dev.platform_data; |
| 1900 | |
| 1901 | if (early_serial_console.data) |
| 1902 | return -EEXIST; |
| 1903 | |
| 1904 | early_serial_console.index = pdev->id; |
Paul Mundt | ecdf8a4 | 2011-01-21 00:05:48 +0900 | [diff] [blame] | 1905 | |
Paul Mundt | 906b17d | 2011-01-21 16:19:53 +0900 | [diff] [blame] | 1906 | sci_init_single(NULL, &sci_ports[pdev->id], pdev->id, cfg); |
Paul Mundt | ecdf8a4 | 2011-01-21 00:05:48 +0900 | [diff] [blame] | 1907 | |
| 1908 | serial_console_setup(&early_serial_console, early_serial_buf); |
| 1909 | |
| 1910 | if (!strstr(early_serial_buf, "keep")) |
| 1911 | early_serial_console.flags |= CON_BOOT; |
| 1912 | |
| 1913 | register_console(&early_serial_console); |
| 1914 | return 0; |
| 1915 | } |
Nobuhiro Iwamatsu | 6a8c979 | 2011-03-24 02:20:56 +0000 | [diff] [blame] | 1916 | |
| 1917 | #define SCI_CONSOLE (&serial_console) |
| 1918 | |
Paul Mundt | ecdf8a4 | 2011-01-21 00:05:48 +0900 | [diff] [blame] | 1919 | #else |
| 1920 | static inline int __devinit sci_probe_earlyprintk(struct platform_device *pdev) |
| 1921 | { |
| 1922 | return -EINVAL; |
| 1923 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | |
Nobuhiro Iwamatsu | 6a8c979 | 2011-03-24 02:20:56 +0000 | [diff] [blame] | 1925 | #define SCI_CONSOLE NULL |
| 1926 | |
| 1927 | #endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | |
| 1929 | static char banner[] __initdata = |
| 1930 | KERN_INFO "SuperH SCI(F) driver initialized\n"; |
| 1931 | |
| 1932 | static struct uart_driver sci_uart_driver = { |
| 1933 | .owner = THIS_MODULE, |
| 1934 | .driver_name = "sci", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | .dev_name = "ttySC", |
| 1936 | .major = SCI_MAJOR, |
| 1937 | .minor = SCI_MINOR_START, |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1938 | .nr = SCI_NPORTS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | .cons = SCI_CONSOLE, |
| 1940 | }; |
| 1941 | |
Paul Mundt | 54507f6 | 2009-05-08 23:48:33 +0900 | [diff] [blame] | 1942 | static int sci_remove(struct platform_device *dev) |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 1943 | { |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 1944 | struct sci_port *port = platform_get_drvdata(dev); |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 1945 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 1946 | cpufreq_unregister_notifier(&port->freq_transition, |
| 1947 | CPUFREQ_TRANSITION_NOTIFIER); |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 1948 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 1949 | uart_remove_one_port(&sci_uart_driver, &port->port); |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 1950 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 1951 | clk_put(port->iclk); |
| 1952 | clk_put(port->fclk); |
| 1953 | |
Magnus Damm | 5e50d2d | 2011-04-19 10:38:25 +0000 | [diff] [blame] | 1954 | pm_runtime_disable(&dev->dev); |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 1955 | return 0; |
| 1956 | } |
| 1957 | |
Magnus Damm | 0ee7071 | 2009-01-21 15:13:50 +0000 | [diff] [blame] | 1958 | static int __devinit sci_probe_single(struct platform_device *dev, |
| 1959 | unsigned int index, |
| 1960 | struct plat_sci_port *p, |
| 1961 | struct sci_port *sciport) |
| 1962 | { |
Magnus Damm | 0ee7071 | 2009-01-21 15:13:50 +0000 | [diff] [blame] | 1963 | int ret; |
| 1964 | |
| 1965 | /* Sanity check */ |
| 1966 | if (unlikely(index >= SCI_NPORTS)) { |
| 1967 | dev_notice(&dev->dev, "Attempting to register port " |
| 1968 | "%d when only %d are available.\n", |
| 1969 | index+1, SCI_NPORTS); |
| 1970 | dev_notice(&dev->dev, "Consider bumping " |
| 1971 | "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n"); |
| 1972 | return 0; |
| 1973 | } |
| 1974 | |
Paul Mundt | c7ed1ab | 2010-03-10 18:35:14 +0900 | [diff] [blame] | 1975 | ret = sci_init_single(dev, sciport, index, p); |
| 1976 | if (ret) |
| 1977 | return ret; |
Magnus Damm | 0ee7071 | 2009-01-21 15:13:50 +0000 | [diff] [blame] | 1978 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 1979 | return uart_add_one_port(&sci_uart_driver, &sciport->port); |
Magnus Damm | 0ee7071 | 2009-01-21 15:13:50 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1982 | static int __devinit sci_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | { |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 1984 | struct plat_sci_port *p = dev->dev.platform_data; |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 1985 | struct sci_port *sp = &sci_ports[dev->id]; |
Paul Mundt | ecdf8a4 | 2011-01-21 00:05:48 +0900 | [diff] [blame] | 1986 | int ret; |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 1987 | |
Paul Mundt | ecdf8a4 | 2011-01-21 00:05:48 +0900 | [diff] [blame] | 1988 | /* |
| 1989 | * If we've come here via earlyprintk initialization, head off to |
| 1990 | * the special early probe. We don't have sufficient device state |
| 1991 | * to make it beyond this yet. |
| 1992 | */ |
| 1993 | if (is_early_platform_device(dev)) |
| 1994 | return sci_probe_earlyprintk(dev); |
Magnus Damm | 7b6fd3b | 2009-12-14 10:24:42 +0000 | [diff] [blame] | 1995 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 1996 | platform_set_drvdata(dev, sp); |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 1997 | |
Paul Mundt | 906b17d | 2011-01-21 16:19:53 +0900 | [diff] [blame] | 1998 | ret = sci_probe_single(dev, dev->id, p, sp); |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 1999 | if (ret) |
| 2000 | goto err_unreg; |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 2001 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 2002 | sp->freq_transition.notifier_call = sci_notifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 2004 | ret = cpufreq_register_notifier(&sp->freq_transition, |
| 2005 | CPUFREQ_TRANSITION_NOTIFIER); |
| 2006 | if (unlikely(ret < 0)) |
| 2007 | goto err_unreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | |
| 2009 | #ifdef CONFIG_SH_STANDARD_BIOS |
| 2010 | sh_bios_gdb_detach(); |
| 2011 | #endif |
| 2012 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2013 | return 0; |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 2014 | |
| 2015 | err_unreg: |
Magnus Damm | e552de2 | 2009-01-21 15:13:42 +0000 | [diff] [blame] | 2016 | sci_remove(dev); |
Paul Mundt | 7ff731a | 2008-10-01 15:46:58 +0900 | [diff] [blame] | 2017 | return ret; |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2018 | } |
| 2019 | |
Paul Mundt | 6daa79b | 2009-06-15 07:07:38 +0900 | [diff] [blame] | 2020 | static int sci_suspend(struct device *dev) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2021 | { |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 2022 | struct sci_port *sport = dev_get_drvdata(dev); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2023 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 2024 | if (sport) |
| 2025 | uart_suspend_port(&sci_uart_driver, &sport->port); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2026 | |
| 2027 | return 0; |
| 2028 | } |
| 2029 | |
Paul Mundt | 6daa79b | 2009-06-15 07:07:38 +0900 | [diff] [blame] | 2030 | static int sci_resume(struct device *dev) |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2031 | { |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 2032 | struct sci_port *sport = dev_get_drvdata(dev); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2033 | |
Paul Mundt | d535a23 | 2011-01-19 17:19:35 +0900 | [diff] [blame] | 2034 | if (sport) |
| 2035 | uart_resume_port(&sci_uart_driver, &sport->port); |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2036 | |
| 2037 | return 0; |
| 2038 | } |
| 2039 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 2040 | static const struct dev_pm_ops sci_dev_pm_ops = { |
Paul Mundt | 6daa79b | 2009-06-15 07:07:38 +0900 | [diff] [blame] | 2041 | .suspend = sci_suspend, |
| 2042 | .resume = sci_resume, |
| 2043 | }; |
| 2044 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2045 | static struct platform_driver sci_driver = { |
| 2046 | .probe = sci_probe, |
Uwe Kleine-König | b9e39c8 | 2009-11-24 22:07:32 +0100 | [diff] [blame] | 2047 | .remove = sci_remove, |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2048 | .driver = { |
| 2049 | .name = "sh-sci", |
| 2050 | .owner = THIS_MODULE, |
Paul Mundt | 6daa79b | 2009-06-15 07:07:38 +0900 | [diff] [blame] | 2051 | .pm = &sci_dev_pm_ops, |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2052 | }, |
| 2053 | }; |
| 2054 | |
| 2055 | static int __init sci_init(void) |
| 2056 | { |
| 2057 | int ret; |
| 2058 | |
| 2059 | printk(banner); |
| 2060 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2061 | ret = uart_register_driver(&sci_uart_driver); |
| 2062 | if (likely(ret == 0)) { |
| 2063 | ret = platform_driver_register(&sci_driver); |
| 2064 | if (unlikely(ret)) |
| 2065 | uart_unregister_driver(&sci_uart_driver); |
| 2066 | } |
| 2067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | return ret; |
| 2069 | } |
| 2070 | |
| 2071 | static void __exit sci_exit(void) |
| 2072 | { |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2073 | platform_driver_unregister(&sci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | uart_unregister_driver(&sci_uart_driver); |
| 2075 | } |
| 2076 | |
Magnus Damm | 7b6fd3b | 2009-12-14 10:24:42 +0000 | [diff] [blame] | 2077 | #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE |
| 2078 | early_platform_init_buffer("earlyprintk", &sci_driver, |
| 2079 | early_serial_buf, ARRAY_SIZE(early_serial_buf)); |
| 2080 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | module_init(sci_init); |
| 2082 | module_exit(sci_exit); |
| 2083 | |
Paul Mundt | e108b2c | 2006-09-27 16:32:13 +0900 | [diff] [blame] | 2084 | MODULE_LICENSE("GPL"); |
Kay Sievers | e169c13 | 2008-04-15 14:34:35 -0700 | [diff] [blame] | 2085 | MODULE_ALIAS("platform:sh-sci"); |