aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/serial/sh-sci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/tty/serial/sh-sci.c')
-rw-r--r--drivers/tty/serial/sh-sci.c103
1 files changed, 68 insertions, 35 deletions
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 784dd42002ea..31fcc7072a90 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * SuperH on-chip serial module support. (SCI with no FIFO / with FIFO) 3 * SuperH on-chip serial module support. (SCI with no FIFO / with FIFO)
3 * 4 *
@@ -13,10 +14,6 @@
13 * Modified to support SecureEdge. David McCullough (2002) 14 * Modified to support SecureEdge. David McCullough (2002)
14 * Modified to support SH7300 SCIF. Takashi Kusuda (Jun 2003). 15 * Modified to support SH7300 SCIF. Takashi Kusuda (Jun 2003).
15 * Removed SH7300 support (Jul 2007). 16 * Removed SH7300 support (Jul 2007).
16 *
17 * This file is subject to the terms and conditions of the GNU General Public
18 * License. See the file "COPYING" in the main directory of this archive
19 * for more details.
20 */ 17 */
21#if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 18#if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
22#define SUPPORT_SYSRQ 19#define SUPPORT_SYSRQ
@@ -40,6 +37,7 @@
40#include <linux/module.h> 37#include <linux/module.h>
41#include <linux/mm.h> 38#include <linux/mm.h>
42#include <linux/of.h> 39#include <linux/of.h>
40#include <linux/of_device.h>
43#include <linux/platform_device.h> 41#include <linux/platform_device.h>
44#include <linux/pm_runtime.h> 42#include <linux/pm_runtime.h>
45#include <linux/scatterlist.h> 43#include <linux/scatterlist.h>
@@ -152,6 +150,7 @@ struct sci_port {
152 int rx_trigger; 150 int rx_trigger;
153 struct timer_list rx_fifo_timer; 151 struct timer_list rx_fifo_timer;
154 int rx_fifo_timeout; 152 int rx_fifo_timeout;
153 u16 hscif_tot;
155 154
156 bool has_rtscts; 155 bool has_rtscts;
157 bool autorts; 156 bool autorts;
@@ -1107,8 +1106,14 @@ static ssize_t rx_fifo_timeout_show(struct device *dev,
1107{ 1106{
1108 struct uart_port *port = dev_get_drvdata(dev); 1107 struct uart_port *port = dev_get_drvdata(dev);
1109 struct sci_port *sci = to_sci_port(port); 1108 struct sci_port *sci = to_sci_port(port);
1109 int v;
1110
1111 if (port->type == PORT_HSCIF)
1112 v = sci->hscif_tot >> HSSCR_TOT_SHIFT;
1113 else
1114 v = sci->rx_fifo_timeout;
1110 1115
1111 return sprintf(buf, "%d\n", sci->rx_fifo_timeout); 1116 return sprintf(buf, "%d\n", v);
1112} 1117}
1113 1118
1114static ssize_t rx_fifo_timeout_store(struct device *dev, 1119static ssize_t rx_fifo_timeout_store(struct device *dev,
@@ -1124,11 +1129,19 @@ static ssize_t rx_fifo_timeout_store(struct device *dev,
1124 ret = kstrtol(buf, 0, &r); 1129 ret = kstrtol(buf, 0, &r);
1125 if (ret) 1130 if (ret)
1126 return ret; 1131 return ret;
1127 sci->rx_fifo_timeout = r; 1132
1128 scif_set_rtrg(port, 1); 1133 if (port->type == PORT_HSCIF) {
1129 if (r > 0) 1134 if (r < 0 || r > 3)
1130 setup_timer(&sci->rx_fifo_timer, rx_fifo_timer_fn, 1135 return -EINVAL;
1131 (unsigned long)sci); 1136 sci->hscif_tot = r << HSSCR_TOT_SHIFT;
1137 } else {
1138 sci->rx_fifo_timeout = r;
1139 scif_set_rtrg(port, 1);
1140 if (r > 0)
1141 setup_timer(&sci->rx_fifo_timer, rx_fifo_timer_fn,
1142 (unsigned long)sci);
1143 }
1144
1132 return count; 1145 return count;
1133} 1146}
1134 1147
@@ -1210,8 +1223,11 @@ static void sci_rx_dma_release(struct sci_port *s, bool enable_pio)
1210 dma_free_coherent(chan->device->dev, s->buf_len_rx * 2, s->rx_buf[0], 1223 dma_free_coherent(chan->device->dev, s->buf_len_rx * 2, s->rx_buf[0],
1211 sg_dma_address(&s->sg_rx[0])); 1224 sg_dma_address(&s->sg_rx[0]));
1212 dma_release_channel(chan); 1225 dma_release_channel(chan);
1213 if (enable_pio) 1226 if (enable_pio) {
1227 spin_lock_irqsave(&port->lock, flags);
1214 sci_start_rx(port); 1228 sci_start_rx(port);
1229 spin_unlock_irqrestore(&port->lock, flags);
1230 }
1215} 1231}
1216 1232
1217static void sci_dma_rx_complete(void *arg) 1233static void sci_dma_rx_complete(void *arg)
@@ -1278,8 +1294,11 @@ static void sci_tx_dma_release(struct sci_port *s, bool enable_pio)
1278 dma_unmap_single(chan->device->dev, s->tx_dma_addr, UART_XMIT_SIZE, 1294 dma_unmap_single(chan->device->dev, s->tx_dma_addr, UART_XMIT_SIZE,
1279 DMA_TO_DEVICE); 1295 DMA_TO_DEVICE);
1280 dma_release_channel(chan); 1296 dma_release_channel(chan);
1281 if (enable_pio) 1297 if (enable_pio) {
1298 spin_lock_irqsave(&port->lock, flags);
1282 sci_start_tx(port); 1299 sci_start_tx(port);
1300 spin_unlock_irqrestore(&port->lock, flags);
1301 }
1283} 1302}
1284 1303
1285static void sci_submit_rx(struct sci_port *s) 1304static void sci_submit_rx(struct sci_port *s)
@@ -1491,6 +1510,14 @@ static void sci_request_dma(struct uart_port *port)
1491 return; 1510 return;
1492 1511
1493 s->cookie_tx = -EINVAL; 1512 s->cookie_tx = -EINVAL;
1513
1514 /*
1515 * Don't request a dma channel if no channel was specified
1516 * in the device tree.
1517 */
1518 if (!of_find_property(port->dev->of_node, "dmas", NULL))
1519 return;
1520
1494 chan = sci_request_dma_chan(port, DMA_MEM_TO_DEV); 1521 chan = sci_request_dma_chan(port, DMA_MEM_TO_DEV);
1495 dev_dbg(port->dev, "%s: TX: got channel %p\n", __func__, chan); 1522 dev_dbg(port->dev, "%s: TX: got channel %p\n", __func__, chan);
1496 if (chan) { 1523 if (chan) {
@@ -1980,6 +2007,7 @@ static void sci_enable_ms(struct uart_port *port)
1980static void sci_break_ctl(struct uart_port *port, int break_state) 2007static void sci_break_ctl(struct uart_port *port, int break_state)
1981{ 2008{
1982 unsigned short scscr, scsptr; 2009 unsigned short scscr, scsptr;
2010 unsigned long flags;
1983 2011
1984 /* check wheter the port has SCSPTR */ 2012 /* check wheter the port has SCSPTR */
1985 if (!sci_getreg(port, SCSPTR)->size) { 2013 if (!sci_getreg(port, SCSPTR)->size) {
@@ -1990,6 +2018,7 @@ static void sci_break_ctl(struct uart_port *port, int break_state)
1990 return; 2018 return;
1991 } 2019 }
1992 2020
2021 spin_lock_irqsave(&port->lock, flags);
1993 scsptr = serial_port_in(port, SCSPTR); 2022 scsptr = serial_port_in(port, SCSPTR);
1994 scscr = serial_port_in(port, SCSCR); 2023 scscr = serial_port_in(port, SCSCR);
1995 2024
@@ -2003,6 +2032,7 @@ static void sci_break_ctl(struct uart_port *port, int break_state)
2003 2032
2004 serial_port_out(port, SCSPTR, scsptr); 2033 serial_port_out(port, SCSPTR, scsptr);
2005 serial_port_out(port, SCSCR, scscr); 2034 serial_port_out(port, SCSCR, scscr);
2035 spin_unlock_irqrestore(&port->lock, flags);
2006} 2036}
2007 2037
2008static int sci_startup(struct uart_port *port) 2038static int sci_startup(struct uart_port *port)
@@ -2037,9 +2067,13 @@ static void sci_shutdown(struct uart_port *port)
2037 spin_lock_irqsave(&port->lock, flags); 2067 spin_lock_irqsave(&port->lock, flags);
2038 sci_stop_rx(port); 2068 sci_stop_rx(port);
2039 sci_stop_tx(port); 2069 sci_stop_tx(port);
2040 /* Stop RX and TX, disable related interrupts, keep clock source */ 2070 /*
2071 * Stop RX and TX, disable related interrupts, keep clock source
2072 * and HSCIF TOT bits
2073 */
2041 scr = serial_port_in(port, SCSCR); 2074 scr = serial_port_in(port, SCSCR);
2042 serial_port_out(port, SCSCR, scr & (SCSCR_CKE1 | SCSCR_CKE0)); 2075 serial_port_out(port, SCSCR, scr &
2076 (SCSCR_CKE1 | SCSCR_CKE0 | s->hscif_tot));
2043 spin_unlock_irqrestore(&port->lock, flags); 2077 spin_unlock_irqrestore(&port->lock, flags);
2044 2078
2045#ifdef CONFIG_SERIAL_SH_SCI_DMA 2079#ifdef CONFIG_SERIAL_SH_SCI_DMA
@@ -2186,7 +2220,7 @@ static void sci_reset(struct uart_port *port)
2186 unsigned int status; 2220 unsigned int status;
2187 struct sci_port *s = to_sci_port(port); 2221 struct sci_port *s = to_sci_port(port);
2188 2222
2189 serial_port_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */ 2223 serial_port_out(port, SCSCR, s->hscif_tot); /* TE=0, RE=0, CKE1=0 */
2190 2224
2191 reg = sci_getreg(port, SCFCR); 2225 reg = sci_getreg(port, SCFCR);
2192 if (reg->size) 2226 if (reg->size)
@@ -2227,6 +2261,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
2227 int min_err = INT_MAX, err; 2261 int min_err = INT_MAX, err;
2228 unsigned long max_freq = 0; 2262 unsigned long max_freq = 0;
2229 int best_clk = -1; 2263 int best_clk = -1;
2264 unsigned long flags;
2230 2265
2231 if ((termios->c_cflag & CSIZE) == CS7) 2266 if ((termios->c_cflag & CSIZE) == CS7)
2232 smr_val |= SCSMR_CHR; 2267 smr_val |= SCSMR_CHR;
@@ -2336,6 +2371,8 @@ done:
2336 serial_port_out(port, SCCKS, sccks); 2371 serial_port_out(port, SCCKS, sccks);
2337 } 2372 }
2338 2373
2374 spin_lock_irqsave(&port->lock, flags);
2375
2339 sci_reset(port); 2376 sci_reset(port);
2340 2377
2341 uart_update_timeout(port, termios->c_cflag, baud); 2378 uart_update_timeout(port, termios->c_cflag, baud);
@@ -2353,10 +2390,7 @@ done:
2353 case 27: smr_val |= SCSMR_SRC_27; break; 2390 case 27: smr_val |= SCSMR_SRC_27; break;
2354 } 2391 }
2355 smr_val |= cks; 2392 smr_val |= cks;
2356 dev_dbg(port->dev, 2393 serial_port_out(port, SCSCR, scr_val | s->hscif_tot);
2357 "SCR 0x%x SMR 0x%x BRR %u CKS 0x%x DL %u SRR %u\n",
2358 scr_val, smr_val, brr, sccks, dl, srr);
2359 serial_port_out(port, SCSCR, scr_val);
2360 serial_port_out(port, SCSMR, smr_val); 2394 serial_port_out(port, SCSMR, smr_val);
2361 serial_port_out(port, SCBRR, brr); 2395 serial_port_out(port, SCBRR, brr);
2362 if (sci_getreg(port, HSSRR)->size) 2396 if (sci_getreg(port, HSSRR)->size)
@@ -2369,8 +2403,7 @@ done:
2369 scr_val = s->cfg->scscr & (SCSCR_CKE1 | SCSCR_CKE0); 2403 scr_val = s->cfg->scscr & (SCSCR_CKE1 | SCSCR_CKE0);
2370 smr_val |= serial_port_in(port, SCSMR) & 2404 smr_val |= serial_port_in(port, SCSMR) &
2371 (SCSMR_CKEDG | SCSMR_SRC_MASK | SCSMR_CKS); 2405 (SCSMR_CKEDG | SCSMR_SRC_MASK | SCSMR_CKS);
2372 dev_dbg(port->dev, "SCR 0x%x SMR 0x%x\n", scr_val, smr_val); 2406 serial_port_out(port, SCSCR, scr_val | s->hscif_tot);
2373 serial_port_out(port, SCSCR, scr_val);
2374 serial_port_out(port, SCSMR, smr_val); 2407 serial_port_out(port, SCSMR, smr_val);
2375 } 2408 }
2376 2409
@@ -2406,8 +2439,7 @@ done:
2406 2439
2407 scr_val |= SCSCR_RE | SCSCR_TE | 2440 scr_val |= SCSCR_RE | SCSCR_TE |
2408 (s->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)); 2441 (s->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0));
2409 dev_dbg(port->dev, "SCSCR 0x%x\n", scr_val); 2442 serial_port_out(port, SCSCR, scr_val | s->hscif_tot);
2410 serial_port_out(port, SCSCR, scr_val);
2411 if ((srr + 1 == 5) && 2443 if ((srr + 1 == 5) &&
2412 (port->type == PORT_SCIFA || port->type == PORT_SCIFB)) { 2444 (port->type == PORT_SCIFA || port->type == PORT_SCIFB)) {
2413 /* 2445 /*
@@ -2453,8 +2485,6 @@ done:
2453 s->rx_frame = (100 * bits * HZ) / (baud / 10); 2485 s->rx_frame = (100 * bits * HZ) / (baud / 10);
2454#ifdef CONFIG_SERIAL_SH_SCI_DMA 2486#ifdef CONFIG_SERIAL_SH_SCI_DMA
2455 s->rx_timeout = DIV_ROUND_UP(s->buf_len_rx * 2 * s->rx_frame, 1000); 2487 s->rx_timeout = DIV_ROUND_UP(s->buf_len_rx * 2 * s->rx_frame, 1000);
2456 dev_dbg(port->dev, "DMA Rx t-out %ums, tty t-out %u jiffies\n",
2457 s->rx_timeout * 1000 / HZ, port->timeout);
2458 if (s->rx_timeout < msecs_to_jiffies(20)) 2488 if (s->rx_timeout < msecs_to_jiffies(20))
2459 s->rx_timeout = msecs_to_jiffies(20); 2489 s->rx_timeout = msecs_to_jiffies(20);
2460#endif 2490#endif
@@ -2462,6 +2492,8 @@ done:
2462 if ((termios->c_cflag & CREAD) != 0) 2492 if ((termios->c_cflag & CREAD) != 0)
2463 sci_start_rx(port); 2493 sci_start_rx(port);
2464 2494
2495 spin_unlock_irqrestore(&port->lock, flags);
2496
2465 sci_port_disable(s); 2497 sci_port_disable(s);
2466 2498
2467 if (UART_ENABLE_MS(port, termios->c_cflag)) 2499 if (UART_ENABLE_MS(port, termios->c_cflag))
@@ -2773,6 +2805,7 @@ static int sci_init_single(struct platform_device *dev,
2773 } 2805 }
2774 2806
2775 sci_port->rx_fifo_timeout = 0; 2807 sci_port->rx_fifo_timeout = 0;
2808 sci_port->hscif_tot = 0;
2776 2809
2777 /* SCIFA on sh7723 and sh7724 need a custom sampling rate that doesn't 2810 /* SCIFA on sh7723 and sh7724 need a custom sampling rate that doesn't
2778 * match the SoC datasheet, this should be investigated. Let platform 2811 * match the SoC datasheet, this should be investigated. Let platform
@@ -2860,7 +2893,7 @@ static void serial_console_write(struct console *co, const char *s,
2860 ctrl_temp = SCSCR_RE | SCSCR_TE | 2893 ctrl_temp = SCSCR_RE | SCSCR_TE |
2861 (sci_port->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)) | 2894 (sci_port->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)) |
2862 (ctrl & (SCSCR_CKE1 | SCSCR_CKE0)); 2895 (ctrl & (SCSCR_CKE1 | SCSCR_CKE0));
2863 serial_port_out(port, SCSCR, ctrl_temp); 2896 serial_port_out(port, SCSCR, ctrl_temp | sci_port->hscif_tot);
2864 2897
2865 uart_console_write(port, s, count, serial_console_putchar); 2898 uart_console_write(port, s, count, serial_console_putchar);
2866 2899
@@ -2988,7 +3021,8 @@ static int sci_remove(struct platform_device *dev)
2988 sysfs_remove_file(&dev->dev.kobj, 3021 sysfs_remove_file(&dev->dev.kobj,
2989 &dev_attr_rx_fifo_trigger.attr); 3022 &dev_attr_rx_fifo_trigger.attr);
2990 } 3023 }
2991 if (port->port.type == PORT_SCIFA || port->port.type == PORT_SCIFB) { 3024 if (port->port.type == PORT_SCIFA || port->port.type == PORT_SCIFB ||
3025 port->port.type == PORT_HSCIF) {
2992 sysfs_remove_file(&dev->dev.kobj, 3026 sysfs_remove_file(&dev->dev.kobj,
2993 &dev_attr_rx_fifo_timeout.attr); 3027 &dev_attr_rx_fifo_timeout.attr);
2994 } 3028 }
@@ -3044,17 +3078,15 @@ static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
3044 unsigned int *dev_id) 3078 unsigned int *dev_id)
3045{ 3079{
3046 struct device_node *np = pdev->dev.of_node; 3080 struct device_node *np = pdev->dev.of_node;
3047 const struct of_device_id *match;
3048 struct plat_sci_port *p; 3081 struct plat_sci_port *p;
3049 struct sci_port *sp; 3082 struct sci_port *sp;
3083 const void *data;
3050 int id; 3084 int id;
3051 3085
3052 if (!IS_ENABLED(CONFIG_OF) || !np) 3086 if (!IS_ENABLED(CONFIG_OF) || !np)
3053 return NULL; 3087 return NULL;
3054 3088
3055 match = of_match_node(of_sci_match, np); 3089 data = of_device_get_match_data(&pdev->dev);
3056 if (!match)
3057 return NULL;
3058 3090
3059 p = devm_kzalloc(&pdev->dev, sizeof(struct plat_sci_port), GFP_KERNEL); 3091 p = devm_kzalloc(&pdev->dev, sizeof(struct plat_sci_port), GFP_KERNEL);
3060 if (!p) 3092 if (!p)
@@ -3070,8 +3102,8 @@ static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
3070 sp = &sci_ports[id]; 3102 sp = &sci_ports[id];
3071 *dev_id = id; 3103 *dev_id = id;
3072 3104
3073 p->type = SCI_OF_TYPE(match->data); 3105 p->type = SCI_OF_TYPE(data);
3074 p->regtype = SCI_OF_REGTYPE(match->data); 3106 p->regtype = SCI_OF_REGTYPE(data);
3075 3107
3076 sp->has_rtscts = of_property_read_bool(np, "uart-has-rtscts"); 3108 sp->has_rtscts = of_property_read_bool(np, "uart-has-rtscts");
3077 3109
@@ -3173,7 +3205,8 @@ static int sci_probe(struct platform_device *dev)
3173 if (ret) 3205 if (ret)
3174 return ret; 3206 return ret;
3175 } 3207 }
3176 if (sp->port.type == PORT_SCIFA || sp->port.type == PORT_SCIFB) { 3208 if (sp->port.type == PORT_SCIFA || sp->port.type == PORT_SCIFB ||
3209 sp->port.type == PORT_HSCIF) {
3177 ret = sysfs_create_file(&dev->dev.kobj, 3210 ret = sysfs_create_file(&dev->dev.kobj,
3178 &dev_attr_rx_fifo_timeout.attr); 3211 &dev_attr_rx_fifo_timeout.attr);
3179 if (ret) { 3212 if (ret) {
@@ -3244,7 +3277,7 @@ early_platform_init_buffer("earlyprintk", &sci_driver,
3244 early_serial_buf, ARRAY_SIZE(early_serial_buf)); 3277 early_serial_buf, ARRAY_SIZE(early_serial_buf));
3245#endif 3278#endif
3246#ifdef CONFIG_SERIAL_SH_SCI_EARLYCON 3279#ifdef CONFIG_SERIAL_SH_SCI_EARLYCON
3247static struct __init plat_sci_port port_cfg; 3280static struct plat_sci_port port_cfg __initdata;
3248 3281
3249static int __init early_console_setup(struct earlycon_device *device, 3282static int __init early_console_setup(struct earlycon_device *device,
3250 int type) 3283 int type)