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