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