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