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