aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/serial/serial_core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/tty/serial/serial_core.c')
-rw-r--r--drivers/tty/serial/serial_core.c257
1 files changed, 228 insertions, 29 deletions
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 0fcfd98a9566..2c7230aaefd4 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -610,34 +610,57 @@ static void uart_send_xchar(struct tty_struct *tty, char ch)
610static void uart_throttle(struct tty_struct *tty) 610static void uart_throttle(struct tty_struct *tty)
611{ 611{
612 struct uart_state *state = tty->driver_data; 612 struct uart_state *state = tty->driver_data;
613 struct uart_port *port = state->uart_port;
614 uint32_t mask = 0;
613 615
614 if (I_IXOFF(tty)) 616 if (I_IXOFF(tty))
617 mask |= UPF_SOFT_FLOW;
618 if (tty->termios.c_cflag & CRTSCTS)
619 mask |= UPF_HARD_FLOW;
620
621 if (port->flags & mask) {
622 port->ops->throttle(port);
623 mask &= ~port->flags;
624 }
625
626 if (mask & UPF_SOFT_FLOW)
615 uart_send_xchar(tty, STOP_CHAR(tty)); 627 uart_send_xchar(tty, STOP_CHAR(tty));
616 628
617 if (tty->termios.c_cflag & CRTSCTS) 629 if (mask & UPF_HARD_FLOW)
618 uart_clear_mctrl(state->uart_port, TIOCM_RTS); 630 uart_clear_mctrl(port, TIOCM_RTS);
619} 631}
620 632
621static void uart_unthrottle(struct tty_struct *tty) 633static void uart_unthrottle(struct tty_struct *tty)
622{ 634{
623 struct uart_state *state = tty->driver_data; 635 struct uart_state *state = tty->driver_data;
624 struct uart_port *port = state->uart_port; 636 struct uart_port *port = state->uart_port;
637 uint32_t mask = 0;
638
639 if (I_IXOFF(tty))
640 mask |= UPF_SOFT_FLOW;
641 if (tty->termios.c_cflag & CRTSCTS)
642 mask |= UPF_HARD_FLOW;
625 643
626 if (I_IXOFF(tty)) { 644 if (port->flags & mask) {
645 port->ops->unthrottle(port);
646 mask &= ~port->flags;
647 }
648
649 if (mask & UPF_SOFT_FLOW) {
627 if (port->x_char) 650 if (port->x_char)
628 port->x_char = 0; 651 port->x_char = 0;
629 else 652 else
630 uart_send_xchar(tty, START_CHAR(tty)); 653 uart_send_xchar(tty, START_CHAR(tty));
631 } 654 }
632 655
633 if (tty->termios.c_cflag & CRTSCTS) 656 if (mask & UPF_HARD_FLOW)
634 uart_set_mctrl(port, TIOCM_RTS); 657 uart_set_mctrl(port, TIOCM_RTS);
635} 658}
636 659
637static void uart_get_info(struct tty_port *port, 660static void do_uart_get_info(struct tty_port *port,
638 struct uart_state *state,
639 struct serial_struct *retinfo) 661 struct serial_struct *retinfo)
640{ 662{
663 struct uart_state *state = container_of(port, struct uart_state, port);
641 struct uart_port *uport = state->uart_port; 664 struct uart_port *uport = state->uart_port;
642 665
643 memset(retinfo, 0, sizeof(*retinfo)); 666 memset(retinfo, 0, sizeof(*retinfo));
@@ -662,17 +685,21 @@ static void uart_get_info(struct tty_port *port,
662 retinfo->iomem_base = (void *)(unsigned long)uport->mapbase; 685 retinfo->iomem_base = (void *)(unsigned long)uport->mapbase;
663} 686}
664 687
665static int uart_get_info_user(struct uart_state *state, 688static void uart_get_info(struct tty_port *port,
666 struct serial_struct __user *retinfo) 689 struct serial_struct *retinfo)
667{ 690{
668 struct tty_port *port = &state->port;
669 struct serial_struct tmp;
670
671 /* Ensure the state we copy is consistent and no hardware changes 691 /* Ensure the state we copy is consistent and no hardware changes
672 occur as we go */ 692 occur as we go */
673 mutex_lock(&port->mutex); 693 mutex_lock(&port->mutex);
674 uart_get_info(port, state, &tmp); 694 do_uart_get_info(port, retinfo);
675 mutex_unlock(&port->mutex); 695 mutex_unlock(&port->mutex);
696}
697
698static int uart_get_info_user(struct tty_port *port,
699 struct serial_struct __user *retinfo)
700{
701 struct serial_struct tmp;
702 uart_get_info(port, &tmp);
676 703
677 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 704 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
678 return -EFAULT; 705 return -EFAULT;
@@ -1131,7 +1158,7 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd,
1131 */ 1158 */
1132 switch (cmd) { 1159 switch (cmd) {
1133 case TIOCGSERIAL: 1160 case TIOCGSERIAL:
1134 ret = uart_get_info_user(state, uarg); 1161 ret = uart_get_info_user(port, uarg);
1135 break; 1162 break;
1136 1163
1137 case TIOCSSERIAL: 1164 case TIOCSSERIAL:
@@ -1210,9 +1237,22 @@ static void uart_set_termios(struct tty_struct *tty,
1210 struct ktermios *old_termios) 1237 struct ktermios *old_termios)
1211{ 1238{
1212 struct uart_state *state = tty->driver_data; 1239 struct uart_state *state = tty->driver_data;
1240 struct uart_port *uport = state->uart_port;
1213 unsigned long flags; 1241 unsigned long flags;
1214 unsigned int cflag = tty->termios.c_cflag; 1242 unsigned int cflag = tty->termios.c_cflag;
1243 unsigned int iflag_mask = IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK;
1244 bool sw_changed = false;
1215 1245
1246 /*
1247 * Drivers doing software flow control also need to know
1248 * about changes to these input settings.
1249 */
1250 if (uport->flags & UPF_SOFT_FLOW) {
1251 iflag_mask |= IXANY|IXON|IXOFF;
1252 sw_changed =
1253 tty->termios.c_cc[VSTART] != old_termios->c_cc[VSTART] ||
1254 tty->termios.c_cc[VSTOP] != old_termios->c_cc[VSTOP];
1255 }
1216 1256
1217 /* 1257 /*
1218 * These are the bits that are used to setup various 1258 * These are the bits that are used to setup various
@@ -1220,11 +1260,11 @@ static void uart_set_termios(struct tty_struct *tty,
1220 * bits in c_cflag; c_[io]speed will always be set 1260 * bits in c_cflag; c_[io]speed will always be set
1221 * appropriately by set_termios() in tty_ioctl.c 1261 * appropriately by set_termios() in tty_ioctl.c
1222 */ 1262 */
1223#define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1224 if ((cflag ^ old_termios->c_cflag) == 0 && 1263 if ((cflag ^ old_termios->c_cflag) == 0 &&
1225 tty->termios.c_ospeed == old_termios->c_ospeed && 1264 tty->termios.c_ospeed == old_termios->c_ospeed &&
1226 tty->termios.c_ispeed == old_termios->c_ispeed && 1265 tty->termios.c_ispeed == old_termios->c_ispeed &&
1227 RELEVANT_IFLAG(tty->termios.c_iflag ^ old_termios->c_iflag) == 0) { 1266 ((tty->termios.c_iflag ^ old_termios->c_iflag) & iflag_mask) == 0 &&
1267 !sw_changed) {
1228 return; 1268 return;
1229 } 1269 }
1230 1270
@@ -1232,31 +1272,38 @@ static void uart_set_termios(struct tty_struct *tty,
1232 1272
1233 /* Handle transition to B0 status */ 1273 /* Handle transition to B0 status */
1234 if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD)) 1274 if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD))
1235 uart_clear_mctrl(state->uart_port, TIOCM_RTS | TIOCM_DTR); 1275 uart_clear_mctrl(uport, TIOCM_RTS | TIOCM_DTR);
1236 /* Handle transition away from B0 status */ 1276 /* Handle transition away from B0 status */
1237 else if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) { 1277 else if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
1238 unsigned int mask = TIOCM_DTR; 1278 unsigned int mask = TIOCM_DTR;
1239 if (!(cflag & CRTSCTS) || 1279 if (!(cflag & CRTSCTS) ||
1240 !test_bit(TTY_THROTTLED, &tty->flags)) 1280 !test_bit(TTY_THROTTLED, &tty->flags))
1241 mask |= TIOCM_RTS; 1281 mask |= TIOCM_RTS;
1242 uart_set_mctrl(state->uart_port, mask); 1282 uart_set_mctrl(uport, mask);
1243 } 1283 }
1244 1284
1285 /*
1286 * If the port is doing h/w assisted flow control, do nothing.
1287 * We assume that tty->hw_stopped has never been set.
1288 */
1289 if (uport->flags & UPF_HARD_FLOW)
1290 return;
1291
1245 /* Handle turning off CRTSCTS */ 1292 /* Handle turning off CRTSCTS */
1246 if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) { 1293 if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) {
1247 spin_lock_irqsave(&state->uart_port->lock, flags); 1294 spin_lock_irqsave(&uport->lock, flags);
1248 tty->hw_stopped = 0; 1295 tty->hw_stopped = 0;
1249 __uart_start(tty); 1296 __uart_start(tty);
1250 spin_unlock_irqrestore(&state->uart_port->lock, flags); 1297 spin_unlock_irqrestore(&uport->lock, flags);
1251 } 1298 }
1252 /* Handle turning on CRTSCTS */ 1299 /* Handle turning on CRTSCTS */
1253 else if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) { 1300 else if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) {
1254 spin_lock_irqsave(&state->uart_port->lock, flags); 1301 spin_lock_irqsave(&uport->lock, flags);
1255 if (!(state->uart_port->ops->get_mctrl(state->uart_port) & TIOCM_CTS)) { 1302 if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS)) {
1256 tty->hw_stopped = 1; 1303 tty->hw_stopped = 1;
1257 state->uart_port->ops->stop_tx(state->uart_port); 1304 uport->ops->stop_tx(uport);
1258 } 1305 }
1259 spin_unlock_irqrestore(&state->uart_port->lock, flags); 1306 spin_unlock_irqrestore(&uport->lock, flags);
1260 } 1307 }
1261} 1308}
1262 1309
@@ -2293,6 +2340,8 @@ int uart_register_driver(struct uart_driver *drv)
2293 if (retval >= 0) 2340 if (retval >= 0)
2294 return retval; 2341 return retval;
2295 2342
2343 for (i = 0; i < drv->nr; i++)
2344 tty_port_destroy(&drv->state[i].port);
2296 put_tty_driver(normal); 2345 put_tty_driver(normal);
2297out_kfree: 2346out_kfree:
2298 kfree(drv->state); 2347 kfree(drv->state);
@@ -2312,8 +2361,12 @@ out:
2312void uart_unregister_driver(struct uart_driver *drv) 2361void uart_unregister_driver(struct uart_driver *drv)
2313{ 2362{
2314 struct tty_driver *p = drv->tty_driver; 2363 struct tty_driver *p = drv->tty_driver;
2364 unsigned int i;
2365
2315 tty_unregister_driver(p); 2366 tty_unregister_driver(p);
2316 put_tty_driver(p); 2367 put_tty_driver(p);
2368 for (i = 0; i < drv->nr; i++)
2369 tty_port_destroy(&drv->state[i].port);
2317 kfree(drv->state); 2370 kfree(drv->state);
2318 drv->state = NULL; 2371 drv->state = NULL;
2319 drv->tty_driver = NULL; 2372 drv->tty_driver = NULL;
@@ -2329,21 +2382,166 @@ struct tty_driver *uart_console_device(struct console *co, int *index)
2329static ssize_t uart_get_attr_uartclk(struct device *dev, 2382static ssize_t uart_get_attr_uartclk(struct device *dev,
2330 struct device_attribute *attr, char *buf) 2383 struct device_attribute *attr, char *buf)
2331{ 2384{
2332 int ret; 2385 struct serial_struct tmp;
2333 struct tty_port *port = dev_get_drvdata(dev); 2386 struct tty_port *port = dev_get_drvdata(dev);
2334 struct uart_state *state = container_of(port, struct uart_state, port);
2335 2387
2336 mutex_lock(&state->port.mutex); 2388 uart_get_info(port, &tmp);
2337 ret = snprintf(buf, PAGE_SIZE, "%d\n", state->uart_port->uartclk); 2389 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.baud_base * 16);
2338 mutex_unlock(&state->port.mutex); 2390}
2339 2391
2340 return ret; 2392static ssize_t uart_get_attr_type(struct device *dev,
2393 struct device_attribute *attr, char *buf)
2394{
2395 struct serial_struct tmp;
2396 struct tty_port *port = dev_get_drvdata(dev);
2397
2398 uart_get_info(port, &tmp);
2399 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.type);
2400}
2401static ssize_t uart_get_attr_line(struct device *dev,
2402 struct device_attribute *attr, char *buf)
2403{
2404 struct serial_struct tmp;
2405 struct tty_port *port = dev_get_drvdata(dev);
2406
2407 uart_get_info(port, &tmp);
2408 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.line);
2409}
2410
2411static ssize_t uart_get_attr_port(struct device *dev,
2412 struct device_attribute *attr, char *buf)
2413{
2414 struct serial_struct tmp;
2415 struct tty_port *port = dev_get_drvdata(dev);
2416 unsigned long ioaddr;
2417
2418 uart_get_info(port, &tmp);
2419 ioaddr = tmp.port;
2420 if (HIGH_BITS_OFFSET)
2421 ioaddr |= (unsigned long)tmp.port_high << HIGH_BITS_OFFSET;
2422 return snprintf(buf, PAGE_SIZE, "0x%lX\n", ioaddr);
2341} 2423}
2342 2424
2425static ssize_t uart_get_attr_irq(struct device *dev,
2426 struct device_attribute *attr, char *buf)
2427{
2428 struct serial_struct tmp;
2429 struct tty_port *port = dev_get_drvdata(dev);
2430
2431 uart_get_info(port, &tmp);
2432 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.irq);
2433}
2434
2435static ssize_t uart_get_attr_flags(struct device *dev,
2436 struct device_attribute *attr, char *buf)
2437{
2438 struct serial_struct tmp;
2439 struct tty_port *port = dev_get_drvdata(dev);
2440
2441 uart_get_info(port, &tmp);
2442 return snprintf(buf, PAGE_SIZE, "0x%X\n", tmp.flags);
2443}
2444
2445static ssize_t uart_get_attr_xmit_fifo_size(struct device *dev,
2446 struct device_attribute *attr, char *buf)
2447{
2448 struct serial_struct tmp;
2449 struct tty_port *port = dev_get_drvdata(dev);
2450
2451 uart_get_info(port, &tmp);
2452 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.xmit_fifo_size);
2453}
2454
2455
2456static ssize_t uart_get_attr_close_delay(struct device *dev,
2457 struct device_attribute *attr, char *buf)
2458{
2459 struct serial_struct tmp;
2460 struct tty_port *port = dev_get_drvdata(dev);
2461
2462 uart_get_info(port, &tmp);
2463 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.close_delay);
2464}
2465
2466
2467static ssize_t uart_get_attr_closing_wait(struct device *dev,
2468 struct device_attribute *attr, char *buf)
2469{
2470 struct serial_struct tmp;
2471 struct tty_port *port = dev_get_drvdata(dev);
2472
2473 uart_get_info(port, &tmp);
2474 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.closing_wait);
2475}
2476
2477static ssize_t uart_get_attr_custom_divisor(struct device *dev,
2478 struct device_attribute *attr, char *buf)
2479{
2480 struct serial_struct tmp;
2481 struct tty_port *port = dev_get_drvdata(dev);
2482
2483 uart_get_info(port, &tmp);
2484 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.custom_divisor);
2485}
2486
2487static ssize_t uart_get_attr_io_type(struct device *dev,
2488 struct device_attribute *attr, char *buf)
2489{
2490 struct serial_struct tmp;
2491 struct tty_port *port = dev_get_drvdata(dev);
2492
2493 uart_get_info(port, &tmp);
2494 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.io_type);
2495}
2496
2497static ssize_t uart_get_attr_iomem_base(struct device *dev,
2498 struct device_attribute *attr, char *buf)
2499{
2500 struct serial_struct tmp;
2501 struct tty_port *port = dev_get_drvdata(dev);
2502
2503 uart_get_info(port, &tmp);
2504 return snprintf(buf, PAGE_SIZE, "0x%lX\n", (unsigned long)tmp.iomem_base);
2505}
2506
2507static ssize_t uart_get_attr_iomem_reg_shift(struct device *dev,
2508 struct device_attribute *attr, char *buf)
2509{
2510 struct serial_struct tmp;
2511 struct tty_port *port = dev_get_drvdata(dev);
2512
2513 uart_get_info(port, &tmp);
2514 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.iomem_reg_shift);
2515}
2516
2517static DEVICE_ATTR(type, S_IRUSR | S_IRGRP, uart_get_attr_type, NULL);
2518static DEVICE_ATTR(line, S_IRUSR | S_IRGRP, uart_get_attr_line, NULL);
2519static DEVICE_ATTR(port, S_IRUSR | S_IRGRP, uart_get_attr_port, NULL);
2520static DEVICE_ATTR(irq, S_IRUSR | S_IRGRP, uart_get_attr_irq, NULL);
2521static DEVICE_ATTR(flags, S_IRUSR | S_IRGRP, uart_get_attr_flags, NULL);
2522static DEVICE_ATTR(xmit_fifo_size, S_IRUSR | S_IRGRP, uart_get_attr_xmit_fifo_size, NULL);
2343static DEVICE_ATTR(uartclk, S_IRUSR | S_IRGRP, uart_get_attr_uartclk, NULL); 2523static DEVICE_ATTR(uartclk, S_IRUSR | S_IRGRP, uart_get_attr_uartclk, NULL);
2524static DEVICE_ATTR(close_delay, S_IRUSR | S_IRGRP, uart_get_attr_close_delay, NULL);
2525static DEVICE_ATTR(closing_wait, S_IRUSR | S_IRGRP, uart_get_attr_closing_wait, NULL);
2526static DEVICE_ATTR(custom_divisor, S_IRUSR | S_IRGRP, uart_get_attr_custom_divisor, NULL);
2527static DEVICE_ATTR(io_type, S_IRUSR | S_IRGRP, uart_get_attr_io_type, NULL);
2528static DEVICE_ATTR(iomem_base, S_IRUSR | S_IRGRP, uart_get_attr_iomem_base, NULL);
2529static DEVICE_ATTR(iomem_reg_shift, S_IRUSR | S_IRGRP, uart_get_attr_iomem_reg_shift, NULL);
2344 2530
2345static struct attribute *tty_dev_attrs[] = { 2531static struct attribute *tty_dev_attrs[] = {
2532 &dev_attr_type.attr,
2533 &dev_attr_line.attr,
2534 &dev_attr_port.attr,
2535 &dev_attr_irq.attr,
2536 &dev_attr_flags.attr,
2537 &dev_attr_xmit_fifo_size.attr,
2346 &dev_attr_uartclk.attr, 2538 &dev_attr_uartclk.attr,
2539 &dev_attr_close_delay.attr,
2540 &dev_attr_closing_wait.attr,
2541 &dev_attr_custom_divisor.attr,
2542 &dev_attr_io_type.attr,
2543 &dev_attr_iomem_base.attr,
2544 &dev_attr_iomem_reg_shift.attr,
2347 NULL, 2545 NULL,
2348 }; 2546 };
2349 2547
@@ -2356,6 +2554,7 @@ static const struct attribute_group *tty_dev_attr_groups[] = {
2356 NULL 2554 NULL
2357 }; 2555 };
2358 2556
2557
2359/** 2558/**
2360 * uart_add_one_port - attach a driver-defined port structure 2559 * uart_add_one_port - attach a driver-defined port structure
2361 * @drv: pointer to the uart low level driver structure for this port 2560 * @drv: pointer to the uart low level driver structure for this port