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