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