Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge 3.4-rc4 into tty-next

This resolves the merge problem with:
drivers/tty/serial/pch_uart.c

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+1191 -1605
-8
arch/arm/mach-omap2/serial.c
··· 245 245 omap_up.dma_rx_poll_rate = info->dma_rx_poll_rate; 246 246 omap_up.autosuspend_timeout = info->autosuspend_timeout; 247 247 248 - /* Enable the MDR1 Errata i202 for OMAP2430/3xxx/44xx */ 249 - if (!cpu_is_omap2420() && !cpu_is_ti816x()) 250 - omap_up.errata |= UART_ERRATA_i202_MDR1_ACCESS; 251 - 252 - /* Enable DMA Mode Force Idle Errata i291 for omap34xx/3630 */ 253 - if (cpu_is_omap34xx() || cpu_is_omap3630()) 254 - omap_up.errata |= UART_ERRATA_i291_DMA_FORCEIDLE; 255 - 256 248 pdata = &omap_up; 257 249 pdata_size = sizeof(struct omap_uart_port_info); 258 250
+2
arch/arm/mach-tegra/board-harmony.c
··· 19 19 #include <linux/init.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/serial_8250.h> 22 + #include <linux/of_serial.h> 22 23 #include <linux/clk.h> 23 24 #include <linux/dma-mapping.h> 24 25 #include <linux/pda_power.h> ··· 53 52 .irq = INT_UARTD, 54 53 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE, 55 54 .type = PORT_TEGRA, 55 + .handle_break = tegra_serial_handle_break, 56 56 .iotype = UPIO_MEM, 57 57 .regshift = 2, 58 58 .uartclk = 216000000,
+3
arch/arm/mach-tegra/board-paz00.c
··· 21 21 #include <linux/init.h> 22 22 #include <linux/platform_device.h> 23 23 #include <linux/serial_8250.h> 24 + #include <linux/of_serial.h> 24 25 #include <linux/clk.h> 25 26 #include <linux/dma-mapping.h> 26 27 #include <linux/gpio_keys.h> ··· 56 55 .irq = INT_UARTA, 57 56 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE, 58 57 .type = PORT_TEGRA, 58 + .handle_break = tegra_serial_handle_break, 59 59 .iotype = UPIO_MEM, 60 60 .regshift = 2, 61 61 .uartclk = 216000000, ··· 67 65 .irq = INT_UARTC, 68 66 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE, 69 67 .type = PORT_TEGRA, 68 + .handle_break = tegra_serial_handle_break, 70 69 .iotype = UPIO_MEM, 71 70 .regshift = 2, 72 71 .uartclk = 216000000,
+2
arch/arm/mach-tegra/board-seaboard.c
··· 18 18 #include <linux/init.h> 19 19 #include <linux/platform_device.h> 20 20 #include <linux/serial_8250.h> 21 + #include <linux/of_serial.h> 21 22 #include <linux/i2c.h> 22 23 #include <linux/delay.h> 23 24 #include <linux/input.h> ··· 48 47 /* Memory and IRQ filled in before registration */ 49 48 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE, 50 49 .type = PORT_TEGRA, 50 + .handle_break = tegra_serial_handle_break, 51 51 .iotype = UPIO_MEM, 52 52 .regshift = 2, 53 53 .uartclk = 216000000,
+2
arch/arm/mach-tegra/board-trimslice.c
··· 22 22 #include <linux/init.h> 23 23 #include <linux/platform_device.h> 24 24 #include <linux/serial_8250.h> 25 + #include <linux/of_serial.h> 25 26 #include <linux/io.h> 26 27 #include <linux/i2c.h> 27 28 #include <linux/gpio.h> ··· 49 48 .irq = INT_UARTA, 50 49 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE, 51 50 .type = PORT_TEGRA, 51 + .handle_break = tegra_serial_handle_break, 52 52 .iotype = UPIO_MEM, 53 53 .regshift = 2, 54 54 .uartclk = 216000000,
-1
arch/arm/plat-omap/include/plat/omap-serial.h
··· 65 65 bool dma_enabled; /* To specify DMA Mode */ 66 66 unsigned int uartclk; /* UART clock rate */ 67 67 upf_t flags; /* UPF_* flags */ 68 - u32 errata; 69 68 unsigned int dma_rx_buf_size; 70 69 unsigned int dma_rx_timeout; 71 70 unsigned int autosuspend_timeout;
-5
drivers/isdn/i4l/isdn_common.c
··· 46 46 static char *isdn_revision = "$Revision: 1.1.2.3 $"; 47 47 48 48 extern char *isdn_net_revision; 49 - extern char *isdn_tty_revision; 50 49 #ifdef CONFIG_ISDN_PPP 51 50 extern char *isdn_ppp_revision; 52 51 #else ··· 2326 2327 dev->chanmap[i] = -1; 2327 2328 dev->m_idx[i] = -1; 2328 2329 strcpy(dev->num[i], "???"); 2329 - init_waitqueue_head(&dev->mdm.info[i].open_wait); 2330 - init_waitqueue_head(&dev->mdm.info[i].close_wait); 2331 2330 } 2332 2331 if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) { 2333 2332 printk(KERN_WARNING "isdn: Could not register control devices\n"); ··· 2350 2353 2351 2354 strcpy(tmprev, isdn_revision); 2352 2355 printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev)); 2353 - strcpy(tmprev, isdn_tty_revision); 2354 - printk("%s/", isdn_getrev(tmprev)); 2355 2356 strcpy(tmprev, isdn_net_revision); 2356 2357 printk("%s/", isdn_getrev(tmprev)); 2357 2358 strcpy(tmprev, isdn_ppp_revision);
+178 -286
drivers/isdn/i4l/isdn_tty.c
··· 1 - /* $Id: isdn_tty.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $ 2 - * 1 + /* 3 2 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel). 4 3 * 5 4 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de) ··· 11 12 #undef ISDN_TTY_STAT_DEBUG 12 13 13 14 #include <linux/isdn.h> 15 + #include <linux/serial.h> /* ASYNC_* flags */ 14 16 #include <linux/slab.h> 15 17 #include <linux/delay.h> 16 18 #include <linux/mutex.h> ··· 48 48 static int si2bit[8] = 49 49 {4, 1, 4, 4, 4, 4, 4, 4}; 50 50 51 - char *isdn_tty_revision = "$Revision: 1.1.2.3 $"; 52 - 53 - 54 51 /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb() 55 52 * to stuff incoming data directly into a tty's flip-buffer. This 56 53 * is done to speed up tty-receiving if the receive-queue is empty. ··· 65 68 struct tty_struct *tty; 66 69 char last; 67 70 68 - if (info->online) { 69 - if ((tty = info->tty)) { 70 - if (info->mcr & UART_MCR_RTS) { 71 - len = skb->len 72 - #ifdef CONFIG_ISDN_AUDIO 73 - + ISDN_AUDIO_SKB_DLECOUNT(skb) 74 - #endif 75 - ; 71 + if (!info->online) 72 + return 0; 76 73 77 - c = tty_buffer_request_room(tty, len); 78 - if (c >= len) { 74 + tty = info->port.tty; 75 + if (!tty) 76 + return 0; 77 + 78 + if (!(info->mcr & UART_MCR_RTS)) 79 + return 0; 80 + 81 + len = skb->len 79 82 #ifdef CONFIG_ISDN_AUDIO 80 - if (ISDN_AUDIO_SKB_DLECOUNT(skb)) { 81 - int l = skb->len; 82 - unsigned char *dp = skb->data; 83 - while (--l) { 84 - if (*dp == DLE) 85 - tty_insert_flip_char(tty, DLE, 0); 86 - tty_insert_flip_char(tty, *dp++, 0); 87 - } 88 - if (*dp == DLE) 89 - tty_insert_flip_char(tty, DLE, 0); 90 - last = *dp; 91 - } else { 83 + + ISDN_AUDIO_SKB_DLECOUNT(skb) 92 84 #endif 93 - if (len > 1) 94 - tty_insert_flip_string(tty, skb->data, len - 1); 95 - last = skb->data[len - 1]; 85 + ; 86 + 87 + c = tty_buffer_request_room(tty, len); 88 + if (c < len) 89 + return 0; 90 + 96 91 #ifdef CONFIG_ISDN_AUDIO 97 - } 98 - #endif 99 - if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP) 100 - tty_insert_flip_char(tty, last, 0xFF); 101 - else 102 - tty_insert_flip_char(tty, last, TTY_NORMAL); 103 - tty_flip_buffer_push(tty); 104 - kfree_skb(skb); 105 - return 1; 106 - } 107 - } 92 + if (ISDN_AUDIO_SKB_DLECOUNT(skb)) { 93 + int l = skb->len; 94 + unsigned char *dp = skb->data; 95 + while (--l) { 96 + if (*dp == DLE) 97 + tty_insert_flip_char(tty, DLE, 0); 98 + tty_insert_flip_char(tty, *dp++, 0); 108 99 } 100 + if (*dp == DLE) 101 + tty_insert_flip_char(tty, DLE, 0); 102 + last = *dp; 103 + } else { 104 + #endif 105 + if (len > 1) 106 + tty_insert_flip_string(tty, skb->data, len - 1); 107 + last = skb->data[len - 1]; 108 + #ifdef CONFIG_ISDN_AUDIO 109 109 } 110 - return 0; 110 + #endif 111 + if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP) 112 + tty_insert_flip_char(tty, last, 0xFF); 113 + else 114 + tty_insert_flip_char(tty, last, TTY_NORMAL); 115 + tty_flip_buffer_push(tty); 116 + kfree_skb(skb); 117 + 118 + return 1; 111 119 } 112 120 113 121 /* isdn_tty_readmodem() is called periodically from within timer-interrupt. ··· 130 128 modem_info *info; 131 129 132 130 for (i = 0; i < ISDN_MAX_CHANNELS; i++) { 133 - if ((midx = dev->m_idx[i]) >= 0) { 134 - info = &dev->mdm.info[midx]; 135 - if (info->online) { 136 - r = 0; 131 + midx = dev->m_idx[i]; 132 + if (midx < 0) 133 + continue; 134 + 135 + info = &dev->mdm.info[midx]; 136 + if (!info->online) 137 + continue; 138 + 139 + r = 0; 137 140 #ifdef CONFIG_ISDN_AUDIO 138 - isdn_audio_eval_dtmf(info); 139 - if ((info->vonline & 1) && (info->emu.vpar[1])) 140 - isdn_audio_eval_silence(info); 141 + isdn_audio_eval_dtmf(info); 142 + if ((info->vonline & 1) && (info->emu.vpar[1])) 143 + isdn_audio_eval_silence(info); 141 144 #endif 142 - if ((tty = info->tty)) { 143 - if (info->mcr & UART_MCR_RTS) { 144 - /* CISCO AsyncPPP Hack */ 145 - if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP)) 146 - r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0); 147 - else 148 - r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1); 149 - if (r) 150 - tty_flip_buffer_push(tty); 151 - } else 152 - r = 1; 153 - } else 154 - r = 1; 155 - if (r) { 156 - info->rcvsched = 0; 157 - resched = 1; 158 - } else 159 - info->rcvsched = 1; 160 - } 161 - } 145 + tty = info->port.tty; 146 + if (tty) { 147 + if (info->mcr & UART_MCR_RTS) { 148 + /* CISCO AsyncPPP Hack */ 149 + if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP)) 150 + r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0); 151 + else 152 + r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1); 153 + if (r) 154 + tty_flip_buffer_push(tty); 155 + } else 156 + r = 1; 157 + } else 158 + r = 1; 159 + if (r) { 160 + info->rcvsched = 0; 161 + resched = 1; 162 + } else 163 + info->rcvsched = 1; 162 164 } 163 165 if (!resched) 164 166 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0); ··· 300 294 len = skb->len; 301 295 if ((slen = isdn_writebuf_skb_stub(info->isdn_driver, 302 296 info->isdn_channel, 1, skb)) == len) { 303 - struct tty_struct *tty = info->tty; 297 + struct tty_struct *tty = info->port.tty; 304 298 info->send_outstanding++; 305 299 info->msr &= ~UART_MSR_CTS; 306 300 info->lsr &= ~UART_LSR_TEMT; ··· 333 327 static int 334 328 isdn_tty_handleDLEdown(modem_info *info, atemu *m, int len) 335 329 { 336 - unsigned char *p = &info->xmit_buf[info->xmit_count]; 330 + unsigned char *p = &info->port.xmit_buf[info->xmit_count]; 337 331 int count = 0; 338 332 339 333 while (len > 0) { ··· 477 471 return; 478 472 } 479 473 skb_reserve(skb, skb_res); 480 - memcpy(skb_put(skb, buflen), info->xmit_buf, buflen); 474 + memcpy(skb_put(skb, buflen), info->port.xmit_buf, buflen); 481 475 info->xmit_count = 0; 482 476 #ifdef CONFIG_ISDN_AUDIO 483 477 if (info->vonline & 2) { ··· 705 699 printk(KERN_DEBUG "Mhup ttyI%d\n", info->line); 706 700 #endif 707 701 info->rcvsched = 0; 708 - isdn_tty_flush_buffer(info->tty); 702 + isdn_tty_flush_buffer(info->port.tty); 709 703 if (info->online) { 710 704 info->last_lhup = local; 711 705 info->online = 0; ··· 1003 997 static void 1004 998 isdn_tty_change_speed(modem_info *info) 1005 999 { 1000 + struct tty_port *port = &info->port; 1006 1001 uint cflag, 1007 1002 cval, 1008 1003 quot; 1009 1004 int i; 1010 1005 1011 - if (!info->tty || !info->tty->termios) 1006 + if (!port->tty || !port->tty->termios) 1012 1007 return; 1013 - cflag = info->tty->termios->c_cflag; 1008 + cflag = port->tty->termios->c_cflag; 1014 1009 1015 1010 quot = i = cflag & CBAUD; 1016 1011 if (i & CBAUDEX) { 1017 1012 i &= ~CBAUDEX; 1018 1013 if (i < 1 || i > 2) 1019 - info->tty->termios->c_cflag &= ~CBAUDEX; 1014 + port->tty->termios->c_cflag &= ~CBAUDEX; 1020 1015 else 1021 1016 i += 15; 1022 1017 } ··· 1047 1040 1048 1041 /* CTS flow control flag and modem status interrupts */ 1049 1042 if (cflag & CRTSCTS) { 1050 - info->flags |= ISDN_ASYNC_CTS_FLOW; 1043 + port->flags |= ASYNC_CTS_FLOW; 1051 1044 } else 1052 - info->flags &= ~ISDN_ASYNC_CTS_FLOW; 1045 + port->flags &= ~ASYNC_CTS_FLOW; 1053 1046 if (cflag & CLOCAL) 1054 - info->flags &= ~ISDN_ASYNC_CHECK_CD; 1047 + port->flags &= ~ASYNC_CHECK_CD; 1055 1048 else { 1056 - info->flags |= ISDN_ASYNC_CHECK_CD; 1049 + port->flags |= ASYNC_CHECK_CD; 1057 1050 } 1058 1051 } 1059 1052 1060 1053 static int 1061 1054 isdn_tty_startup(modem_info *info) 1062 1055 { 1063 - if (info->flags & ISDN_ASYNC_INITIALIZED) 1056 + if (info->port.flags & ASYNC_INITIALIZED) 1064 1057 return 0; 1065 1058 isdn_lock_drivers(); 1066 1059 #ifdef ISDN_DEBUG_MODEM_OPEN ··· 1070 1063 * Now, initialize the UART 1071 1064 */ 1072 1065 info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2; 1073 - if (info->tty) 1074 - clear_bit(TTY_IO_ERROR, &info->tty->flags); 1066 + if (info->port.tty) 1067 + clear_bit(TTY_IO_ERROR, &info->port.tty->flags); 1075 1068 /* 1076 1069 * and set the speed of the serial port 1077 1070 */ 1078 1071 isdn_tty_change_speed(info); 1079 1072 1080 - info->flags |= ISDN_ASYNC_INITIALIZED; 1073 + info->port.flags |= ASYNC_INITIALIZED; 1081 1074 info->msr |= (UART_MSR_DSR | UART_MSR_CTS); 1082 1075 info->send_outstanding = 0; 1083 1076 return 0; ··· 1090 1083 static void 1091 1084 isdn_tty_shutdown(modem_info *info) 1092 1085 { 1093 - if (!(info->flags & ISDN_ASYNC_INITIALIZED)) 1086 + if (!(info->port.flags & ASYNC_INITIALIZED)) 1094 1087 return; 1095 1088 #ifdef ISDN_DEBUG_MODEM_OPEN 1096 1089 printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line); 1097 1090 #endif 1098 1091 isdn_unlock_drivers(); 1099 1092 info->msr &= ~UART_MSR_RI; 1100 - if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) { 1093 + if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL)) { 1101 1094 info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS); 1102 1095 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { 1103 1096 isdn_tty_modem_reset_regs(info, 0); ··· 1107 1100 isdn_tty_modem_hup(info, 1); 1108 1101 } 1109 1102 } 1110 - if (info->tty) 1111 - set_bit(TTY_IO_ERROR, &info->tty->flags); 1103 + if (info->port.tty) 1104 + set_bit(TTY_IO_ERROR, &info->port.tty->flags); 1112 1105 1113 - info->flags &= ~ISDN_ASYNC_INITIALIZED; 1106 + info->port.flags &= ~ASYNC_INITIALIZED; 1114 1107 } 1115 1108 1116 1109 /* isdn_tty_write() is the main send-routine. It is called from the upper ··· 1153 1146 isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c, 1154 1147 &(m->pluscount), 1155 1148 &(m->lastplus)); 1156 - memcpy(&(info->xmit_buf[info->xmit_count]), buf, c); 1149 + memcpy(&info->port.xmit_buf[info->xmit_count], buf, c); 1157 1150 #ifdef CONFIG_ISDN_AUDIO 1158 1151 if (info->vonline) { 1159 1152 int cc = isdn_tty_handleDLEdown(info, m, c); ··· 1485 1478 * isdn_tty_open() and friends 1486 1479 * ------------------------------------------------------------ 1487 1480 */ 1488 - static int 1489 - isdn_tty_block_til_ready(struct tty_struct *tty, struct file *filp, modem_info *info) 1490 - { 1491 - DECLARE_WAITQUEUE(wait, NULL); 1492 - int do_clocal = 0; 1493 - int retval; 1494 - 1495 - /* 1496 - * If the device is in the middle of being closed, then block 1497 - * until it's done, and then try again. 1498 - */ 1499 - if (tty_hung_up_p(filp) || 1500 - (info->flags & ISDN_ASYNC_CLOSING)) { 1501 - if (info->flags & ISDN_ASYNC_CLOSING) 1502 - interruptible_sleep_on(&info->close_wait); 1503 - #ifdef MODEM_DO_RESTART 1504 - if (info->flags & ISDN_ASYNC_HUP_NOTIFY) 1505 - return -EAGAIN; 1506 - else 1507 - return -ERESTARTSYS; 1508 - #else 1509 - return -EAGAIN; 1510 - #endif 1511 - } 1512 - /* 1513 - * If non-blocking mode is set, then make the check up front 1514 - * and then exit. 1515 - */ 1516 - if ((filp->f_flags & O_NONBLOCK) || 1517 - (tty->flags & (1 << TTY_IO_ERROR))) { 1518 - if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) 1519 - return -EBUSY; 1520 - info->flags |= ISDN_ASYNC_NORMAL_ACTIVE; 1521 - return 0; 1522 - } 1523 - if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) { 1524 - if (info->normal_termios.c_cflag & CLOCAL) 1525 - do_clocal = 1; 1526 - } else { 1527 - if (tty->termios->c_cflag & CLOCAL) 1528 - do_clocal = 1; 1529 - } 1530 - /* 1531 - * Block waiting for the carrier detect and the line to become 1532 - * free (i.e., not in use by the callout). While we are in 1533 - * this loop, info->count is dropped by one, so that 1534 - * isdn_tty_close() knows when to free things. We restore it upon 1535 - * exit, either normal or abnormal. 1536 - */ 1537 - retval = 0; 1538 - add_wait_queue(&info->open_wait, &wait); 1539 - #ifdef ISDN_DEBUG_MODEM_OPEN 1540 - printk(KERN_DEBUG "isdn_tty_block_til_ready before block: ttyi%d, count = %d\n", 1541 - info->line, info->count); 1542 - #endif 1543 - if (!(tty_hung_up_p(filp))) 1544 - info->count--; 1545 - info->blocked_open++; 1546 - while (1) { 1547 - set_current_state(TASK_INTERRUPTIBLE); 1548 - if (tty_hung_up_p(filp) || 1549 - !(info->flags & ISDN_ASYNC_INITIALIZED)) { 1550 - #ifdef MODEM_DO_RESTART 1551 - if (info->flags & ISDN_ASYNC_HUP_NOTIFY) 1552 - retval = -EAGAIN; 1553 - else 1554 - retval = -ERESTARTSYS; 1555 - #else 1556 - retval = -EAGAIN; 1557 - #endif 1558 - break; 1559 - } 1560 - if (!(info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) && 1561 - !(info->flags & ISDN_ASYNC_CLOSING) && 1562 - (do_clocal || (info->msr & UART_MSR_DCD))) { 1563 - break; 1564 - } 1565 - if (signal_pending(current)) { 1566 - retval = -ERESTARTSYS; 1567 - break; 1568 - } 1569 - #ifdef ISDN_DEBUG_MODEM_OPEN 1570 - printk(KERN_DEBUG "isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n", 1571 - info->line, info->count); 1572 - #endif 1573 - schedule(); 1574 - } 1575 - current->state = TASK_RUNNING; 1576 - remove_wait_queue(&info->open_wait, &wait); 1577 - if (!tty_hung_up_p(filp)) 1578 - info->count++; 1579 - info->blocked_open--; 1580 - #ifdef ISDN_DEBUG_MODEM_OPEN 1581 - printk(KERN_DEBUG "isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n", 1582 - info->line, info->count); 1583 - #endif 1584 - if (retval) 1585 - return retval; 1586 - info->flags |= ISDN_ASYNC_NORMAL_ACTIVE; 1587 - return 0; 1588 - } 1589 1481 1590 1482 /* 1591 1483 * This routine is called whenever a serial port is opened. It ··· 1495 1589 static int 1496 1590 isdn_tty_open(struct tty_struct *tty, struct file *filp) 1497 1591 { 1592 + struct tty_port *port; 1498 1593 modem_info *info; 1499 1594 int retval; 1500 1595 1501 1596 info = &dev->mdm.info[tty->index]; 1502 1597 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open")) 1503 1598 return -ENODEV; 1504 - if (!try_module_get(info->owner)) { 1505 - printk(KERN_WARNING "%s: cannot reserve module\n", __func__); 1506 - return -ENODEV; 1507 - } 1599 + port = &info->port; 1508 1600 #ifdef ISDN_DEBUG_MODEM_OPEN 1509 1601 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name, 1510 - info->count); 1602 + port->count); 1511 1603 #endif 1512 - info->count++; 1604 + port->count++; 1513 1605 tty->driver_data = info; 1514 - info->tty = tty; 1606 + port->tty = tty; 1607 + tty->port = port; 1515 1608 /* 1516 1609 * Start up serial port 1517 1610 */ ··· 1519 1614 #ifdef ISDN_DEBUG_MODEM_OPEN 1520 1615 printk(KERN_DEBUG "isdn_tty_open return after startup\n"); 1521 1616 #endif 1522 - module_put(info->owner); 1523 1617 return retval; 1524 1618 } 1525 - retval = isdn_tty_block_til_ready(tty, filp, info); 1619 + retval = tty_port_block_til_ready(port, tty, filp); 1526 1620 if (retval) { 1527 1621 #ifdef ISDN_DEBUG_MODEM_OPEN 1528 1622 printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n"); 1529 1623 #endif 1530 - module_put(info->owner); 1531 1624 return retval; 1532 1625 } 1533 1626 #ifdef ISDN_DEBUG_MODEM_OPEN ··· 1542 1639 isdn_tty_close(struct tty_struct *tty, struct file *filp) 1543 1640 { 1544 1641 modem_info *info = (modem_info *) tty->driver_data; 1642 + struct tty_port *port = &info->port; 1545 1643 ulong timeout; 1546 1644 1547 1645 if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close")) ··· 1553 1649 #endif 1554 1650 return; 1555 1651 } 1556 - if ((tty->count == 1) && (info->count != 1)) { 1652 + if ((tty->count == 1) && (port->count != 1)) { 1557 1653 /* 1558 1654 * Uh, oh. tty->count is 1, which means that the tty 1559 1655 * structure will be freed. Info->count should always ··· 1562 1658 * serial port won't be shutdown. 1563 1659 */ 1564 1660 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, " 1565 - "info->count is %d\n", info->count); 1566 - info->count = 1; 1661 + "info->count is %d\n", port->count); 1662 + port->count = 1; 1567 1663 } 1568 - if (--info->count < 0) { 1664 + if (--port->count < 0) { 1569 1665 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n", 1570 - info->line, info->count); 1571 - info->count = 0; 1666 + info->line, port->count); 1667 + port->count = 0; 1572 1668 } 1573 - if (info->count) { 1669 + if (port->count) { 1574 1670 #ifdef ISDN_DEBUG_MODEM_OPEN 1575 1671 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n"); 1576 1672 #endif 1577 - module_put(info->owner); 1578 1673 return; 1579 1674 } 1580 - info->flags |= ISDN_ASYNC_CLOSING; 1581 - /* 1582 - * Save the termios structure, since this port may have 1583 - * separate termios for callout and dialin. 1584 - */ 1585 - if (info->flags & ISDN_ASYNC_NORMAL_ACTIVE) 1586 - info->normal_termios = *tty->termios; 1587 - if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) 1588 - info->callout_termios = *tty->termios; 1675 + port->flags |= ASYNC_CLOSING; 1589 1676 1590 1677 tty->closing = 1; 1591 1678 /* ··· 1585 1690 * interrupt driver to stop checking the data ready bit in the 1586 1691 * line status register. 1587 1692 */ 1588 - if (info->flags & ISDN_ASYNC_INITIALIZED) { 1693 + if (port->flags & ASYNC_INITIALIZED) { 1589 1694 tty_wait_until_sent_from_close(tty, 3000); /* 30 seconds timeout */ 1590 1695 /* 1591 1696 * Before we drop DTR, make sure the UART transmitter ··· 1603 1708 isdn_tty_shutdown(info); 1604 1709 isdn_tty_flush_buffer(tty); 1605 1710 tty_ldisc_flush(tty); 1606 - info->tty = NULL; 1711 + port->tty = NULL; 1607 1712 info->ncarrier = 0; 1608 - tty->closing = 0; 1609 - module_put(info->owner); 1610 - if (info->blocked_open) { 1611 - msleep_interruptible(500); 1612 - wake_up_interruptible(&info->open_wait); 1613 - } 1614 - info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CLOSING); 1615 - wake_up_interruptible(&info->close_wait); 1713 + 1714 + tty_port_close_end(port, tty); 1616 1715 #ifdef ISDN_DEBUG_MODEM_OPEN 1617 1716 printk(KERN_DEBUG "isdn_tty_close normal exit\n"); 1618 1717 #endif ··· 1619 1730 isdn_tty_hangup(struct tty_struct *tty) 1620 1731 { 1621 1732 modem_info *info = (modem_info *) tty->driver_data; 1733 + struct tty_port *port = &info->port; 1622 1734 1623 1735 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup")) 1624 1736 return; 1625 1737 isdn_tty_shutdown(info); 1626 - info->count = 0; 1627 - info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE); 1628 - info->tty = NULL; 1629 - wake_up_interruptible(&info->open_wait); 1738 + port->count = 0; 1739 + port->flags &= ~ASYNC_NORMAL_ACTIVE; 1740 + port->tty = NULL; 1741 + wake_up_interruptible(&port->open_wait); 1630 1742 } 1631 1743 1632 1744 /* This routine initializes all emulator-data. ··· 1754 1864 .tiocmset = isdn_tty_tiocmset, 1755 1865 }; 1756 1866 1867 + static int isdn_tty_carrier_raised(struct tty_port *port) 1868 + { 1869 + modem_info *info = container_of(port, modem_info, port); 1870 + return info->msr & UART_MSR_DCD; 1871 + } 1872 + 1873 + static const struct tty_port_operations isdn_tty_port_ops = { 1874 + .carrier_raised = isdn_tty_carrier_raised, 1875 + }; 1876 + 1757 1877 int 1758 1878 isdn_tty_modem_init(void) 1759 1879 { ··· 1799 1899 goto err_unregister; 1800 1900 } 1801 1901 #endif 1802 - #ifdef MODULE 1803 - info->owner = THIS_MODULE; 1804 - #endif 1902 + tty_port_init(&info->port); 1903 + info->port.ops = &isdn_tty_port_ops; 1805 1904 spin_lock_init(&info->readlock); 1806 1905 sprintf(info->last_cause, "0000"); 1807 1906 sprintf(info->last_num, "none"); ··· 1812 1913 isdn_tty_modem_reset_regs(info, 1); 1813 1914 info->magic = ISDN_ASYNC_MAGIC; 1814 1915 info->line = i; 1815 - info->tty = NULL; 1816 1916 info->x_char = 0; 1817 - info->count = 0; 1818 - info->blocked_open = 0; 1819 - init_waitqueue_head(&info->open_wait); 1820 - init_waitqueue_head(&info->close_wait); 1821 1917 info->isdn_driver = -1; 1822 1918 info->isdn_channel = -1; 1823 1919 info->drv_index = -1; ··· 1824 1930 #ifdef CONFIG_ISDN_AUDIO 1825 1931 skb_queue_head_init(&info->dtmf_queue); 1826 1932 #endif 1827 - if (!(info->xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, GFP_KERNEL))) { 1933 + info->port.xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, 1934 + GFP_KERNEL); 1935 + if (!info->port.xmit_buf) { 1828 1936 printk(KERN_ERR "Could not allocate modem xmit-buffer\n"); 1829 1937 retval = -ENOMEM; 1830 1938 goto err_unregister; 1831 1939 } 1832 1940 /* Make room for T.70 header */ 1833 - info->xmit_buf += 4; 1941 + info->port.xmit_buf += 4; 1834 1942 } 1835 1943 return 0; 1836 1944 err_unregister: ··· 1841 1945 #ifdef CONFIG_ISDN_TTY_FAX 1842 1946 kfree(info->fax); 1843 1947 #endif 1844 - kfree(info->xmit_buf - 4); 1948 + kfree(info->port.xmit_buf - 4); 1845 1949 } 1846 1950 tty_unregister_driver(m->tty_modem); 1847 1951 err: ··· 1862 1966 #ifdef CONFIG_ISDN_TTY_FAX 1863 1967 kfree(info->fax); 1864 1968 #endif 1865 - kfree(info->xmit_buf - 4); 1969 + kfree(info->port.xmit_buf - 4); 1866 1970 } 1867 1971 tty_unregister_driver(dev->mdm.tty_modem); 1868 1972 put_tty_driver(dev->mdm.tty_modem); ··· 1964 2068 for (i = 0; i < ISDN_MAX_CHANNELS; i++) { 1965 2069 modem_info *info = &dev->mdm.info[i]; 1966 2070 1967 - if (info->count == 0) 2071 + if (info->port.count == 0) 1968 2072 continue; 1969 2073 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */ 1970 2074 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */ ··· 1972 2076 #ifdef ISDN_DEBUG_MODEM_ICALL 1973 2077 printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret); 1974 2078 printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx, 1975 - info->flags, info->isdn_driver, info->isdn_channel, 1976 - dev->usage[idx]); 2079 + info->port.flags, info->isdn_driver, 2080 + info->isdn_channel, dev->usage[idx]); 1977 2081 #endif 1978 2082 if ( 1979 2083 #ifndef FIX_FILE_TRANSFER 1980 - (info->flags & ISDN_ASYNC_NORMAL_ACTIVE) && 2084 + (info->port.flags & ASYNC_NORMAL_ACTIVE) && 1981 2085 #endif 1982 2086 (info->isdn_driver == -1) && 1983 2087 (info->isdn_channel == -1) && ··· 2016 2120 return (wret == 2) ? 3 : 0; 2017 2121 } 2018 2122 2019 - #define TTY_IS_ACTIVE(info) \ 2020 - (info->flags & (ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE)) 2123 + #define TTY_IS_ACTIVE(info) (info->port.flags & ASYNC_NORMAL_ACTIVE) 2021 2124 2022 2125 int 2023 2126 isdn_tty_stat_callback(int i, isdn_ctrl *c) ··· 2107 2212 * for incoming call of this device when 2108 2213 * DCD follow the state of incoming carrier 2109 2214 */ 2110 - if (info->blocked_open && 2215 + if (info->port.blocked_open && 2111 2216 (info->emu.mdmreg[REG_DCD] & BIT_DCD)) { 2112 - wake_up_interruptible(&info->open_wait); 2217 + wake_up_interruptible(&info->port.open_wait); 2113 2218 } 2114 2219 2115 2220 /* Schedule CONNECT-Message to any tty ··· 2117 2222 * set DCD-bit of its modem-status. 2118 2223 */ 2119 2224 if (TTY_IS_ACTIVE(info) || 2120 - (info->blocked_open && (info->emu.mdmreg[REG_DCD] & BIT_DCD))) { 2225 + (info->port.blocked_open && 2226 + (info->emu.mdmreg[REG_DCD] & BIT_DCD))) { 2121 2227 info->msr |= UART_MSR_DCD; 2122 2228 info->emu.charge = 0; 2123 2229 if (info->dialing & 0xf) ··· 2235 2339 l = strlen(msg); 2236 2340 2237 2341 spin_lock_irqsave(&info->readlock, flags); 2238 - tty = info->tty; 2239 - if ((info->flags & ISDN_ASYNC_CLOSING) || (!tty)) { 2342 + tty = info->port.tty; 2343 + if ((info->port.flags & ASYNC_CLOSING) || (!tty)) { 2240 2344 spin_unlock_irqrestore(&info->readlock, flags); 2241 2345 return; 2242 2346 } ··· 2386 2490 case RESULT_NO_CARRIER: 2387 2491 #ifdef ISDN_DEBUG_MODEM_HUP 2388 2492 printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n", 2389 - (info->flags & ISDN_ASYNC_CLOSING), 2390 - (!info->tty)); 2493 + (info->port.flags & ASYNC_CLOSING), 2494 + (!info->port.tty)); 2391 2495 #endif 2392 2496 m->mdmreg[REG_RINGCNT] = 0; 2393 2497 del_timer(&info->nc_timer); 2394 2498 info->ncarrier = 0; 2395 - if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) { 2499 + if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty)) 2396 2500 return; 2397 - } 2501 + 2398 2502 #ifdef CONFIG_ISDN_AUDIO 2399 2503 if (info->vonline & 1) { 2400 2504 #ifdef ISDN_DEBUG_MODEM_VOICE ··· 2525 2629 } 2526 2630 } 2527 2631 if (code == RESULT_NO_CARRIER) { 2528 - if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) { 2632 + if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty)) 2529 2633 return; 2530 - } 2531 - if ((info->flags & ISDN_ASYNC_CHECK_CD) && 2532 - (!((info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) && 2533 - (info->flags & ISDN_ASYNC_CALLOUT_NOHUP)))) { 2534 - tty_hangup(info->tty); 2535 - } 2634 + 2635 + if (info->port.flags & ASYNC_CHECK_CD) 2636 + tty_hangup(info->port.tty); 2536 2637 } 2537 2638 } 2538 2639 ··· 3696 3803 int midx; 3697 3804 3698 3805 for (i = 0; i < ISDN_MAX_CHANNELS; i++) 3699 - if (USG_MODEM(dev->usage[i])) 3700 - if ((midx = dev->m_idx[i]) >= 0) { 3701 - modem_info *info = &dev->mdm.info[midx]; 3702 - if (info->online) { 3703 - ton = 1; 3704 - if ((info->emu.pluscount == 3) && 3705 - time_after(jiffies , info->emu.lastplus + PLUSWAIT2)) { 3706 - info->emu.pluscount = 0; 3707 - info->online = 0; 3708 - isdn_tty_modem_result(RESULT_OK, info); 3709 - } 3806 + if (USG_MODEM(dev->usage[i]) && (midx = dev->m_idx[i]) >= 0) { 3807 + modem_info *info = &dev->mdm.info[midx]; 3808 + if (info->online) { 3809 + ton = 1; 3810 + if ((info->emu.pluscount == 3) && 3811 + time_after(jiffies, 3812 + info->emu.lastplus + PLUSWAIT2)) { 3813 + info->emu.pluscount = 0; 3814 + info->online = 0; 3815 + isdn_tty_modem_result(RESULT_OK, info); 3710 3816 } 3711 3817 } 3818 + } 3712 3819 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton); 3713 3820 } 3714 3821 ··· 3766 3873 3767 3874 for (i = 0; i < ISDN_MAX_CHANNELS; i++) { 3768 3875 modem_info *info = &dev->mdm.info[i]; 3769 - if (info->dialing) { 3770 - if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) { 3771 - info->dialing = 0; 3772 - isdn_tty_modem_result(RESULT_NO_CARRIER, info); 3773 - isdn_tty_modem_hup(info, 1); 3774 - } 3775 - else 3776 - ton = 1; 3777 - } 3876 + if (!info->dialing) 3877 + continue; 3878 + if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) { 3879 + info->dialing = 0; 3880 + isdn_tty_modem_result(RESULT_NO_CARRIER, info); 3881 + isdn_tty_modem_hup(info, 1); 3882 + } else 3883 + ton = 1; 3778 3884 } 3779 3885 isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton); 3780 3886 }
+44 -61
drivers/net/usb/hso.c
··· 106 106 107 107 #define MAX_RX_URBS 2 108 108 109 - static inline struct hso_serial *get_serial_by_tty(struct tty_struct *tty) 110 - { 111 - if (tty) 112 - return tty->driver_data; 113 - return NULL; 114 - } 115 - 116 109 /*****************************************************************************/ 117 110 /* Debugging functions */ 118 111 /*****************************************************************************/ ··· 248 255 u8 dtr_state; 249 256 unsigned tx_urb_used:1; 250 257 258 + struct tty_port port; 251 259 /* from usb_serial_port */ 252 - struct tty_struct *tty; 253 - int open_count; 254 260 spinlock_t serial_lock; 255 261 256 262 int (*write_data) (struct hso_serial *serial); ··· 1106 1114 static void _hso_serial_set_termios(struct tty_struct *tty, 1107 1115 struct ktermios *old) 1108 1116 { 1109 - struct hso_serial *serial = get_serial_by_tty(tty); 1117 + struct hso_serial *serial = tty->driver_data; 1110 1118 struct ktermios *termios; 1111 1119 1112 1120 if (!serial) { ··· 1182 1190 struct urb *urb; 1183 1191 1184 1192 urb = serial->rx_urb[0]; 1185 - if (serial->open_count > 0) { 1193 + if (serial->port.count > 0) { 1186 1194 count = put_rxbuf_data(urb, serial); 1187 1195 if (count == -1) 1188 1196 return; ··· 1218 1226 DUMP1(urb->transfer_buffer, urb->actual_length); 1219 1227 1220 1228 /* Anyone listening? */ 1221 - if (serial->open_count == 0) 1229 + if (serial->port.count == 0) 1222 1230 return; 1223 1231 1224 1232 if (status == 0) { ··· 1260 1268 1261 1269 static void hso_unthrottle(struct tty_struct *tty) 1262 1270 { 1263 - struct hso_serial *serial = get_serial_by_tty(tty); 1271 + struct hso_serial *serial = tty->driver_data; 1264 1272 1265 1273 tasklet_hi_schedule(&serial->unthrottle_tasklet); 1266 1274 } ··· 1296 1304 kref_get(&serial->parent->ref); 1297 1305 1298 1306 /* setup */ 1299 - spin_lock_irq(&serial->serial_lock); 1300 1307 tty->driver_data = serial; 1301 - tty_kref_put(serial->tty); 1302 - serial->tty = tty_kref_get(tty); 1303 - spin_unlock_irq(&serial->serial_lock); 1308 + tty_port_tty_set(&serial->port, tty); 1304 1309 1305 1310 /* check for port already opened, if not set the termios */ 1306 - serial->open_count++; 1307 - if (serial->open_count == 1) { 1311 + serial->port.count++; 1312 + if (serial->port.count == 1) { 1308 1313 serial->rx_state = RX_IDLE; 1309 1314 /* Force default termio settings */ 1310 1315 _hso_serial_set_termios(tty, NULL); ··· 1313 1324 result = hso_start_serial_device(serial->parent, GFP_KERNEL); 1314 1325 if (result) { 1315 1326 hso_stop_serial_device(serial->parent); 1316 - serial->open_count--; 1327 + serial->port.count--; 1317 1328 kref_put(&serial->parent->ref, hso_serial_ref_free); 1318 1329 } 1319 1330 } else { ··· 1350 1361 1351 1362 /* reset the rts and dtr */ 1352 1363 /* do the actual close */ 1353 - serial->open_count--; 1364 + serial->port.count--; 1354 1365 1355 - if (serial->open_count <= 0) { 1356 - serial->open_count = 0; 1357 - spin_lock_irq(&serial->serial_lock); 1358 - if (serial->tty == tty) { 1359 - serial->tty->driver_data = NULL; 1360 - serial->tty = NULL; 1361 - tty_kref_put(tty); 1362 - } 1363 - spin_unlock_irq(&serial->serial_lock); 1366 + if (serial->port.count <= 0) { 1367 + serial->port.count = 0; 1368 + tty_port_tty_set(&serial->port, NULL); 1364 1369 if (!usb_gone) 1365 1370 hso_stop_serial_device(serial->parent); 1366 1371 tasklet_kill(&serial->unthrottle_tasklet); ··· 1373 1390 static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf, 1374 1391 int count) 1375 1392 { 1376 - struct hso_serial *serial = get_serial_by_tty(tty); 1393 + struct hso_serial *serial = tty->driver_data; 1377 1394 int space, tx_bytes; 1378 1395 unsigned long flags; 1379 1396 ··· 1405 1422 /* how much room is there for writing */ 1406 1423 static int hso_serial_write_room(struct tty_struct *tty) 1407 1424 { 1408 - struct hso_serial *serial = get_serial_by_tty(tty); 1425 + struct hso_serial *serial = tty->driver_data; 1409 1426 int room; 1410 1427 unsigned long flags; 1411 1428 ··· 1420 1437 /* setup the term */ 1421 1438 static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old) 1422 1439 { 1423 - struct hso_serial *serial = get_serial_by_tty(tty); 1440 + struct hso_serial *serial = tty->driver_data; 1424 1441 unsigned long flags; 1425 1442 1426 1443 if (old) ··· 1429 1446 1430 1447 /* the actual setup */ 1431 1448 spin_lock_irqsave(&serial->serial_lock, flags); 1432 - if (serial->open_count) 1449 + if (serial->port.count) 1433 1450 _hso_serial_set_termios(tty, old); 1434 1451 else 1435 1452 tty->termios = old; ··· 1441 1458 /* how many characters in the buffer */ 1442 1459 static int hso_serial_chars_in_buffer(struct tty_struct *tty) 1443 1460 { 1444 - struct hso_serial *serial = get_serial_by_tty(tty); 1461 + struct hso_serial *serial = tty->driver_data; 1445 1462 int chars; 1446 1463 unsigned long flags; 1447 1464 ··· 1612 1629 struct serial_icounter_struct *icount) 1613 1630 { 1614 1631 struct uart_icount cnow; 1615 - struct hso_serial *serial = get_serial_by_tty(tty); 1632 + struct hso_serial *serial = tty->driver_data; 1616 1633 struct hso_tiocmget *tiocmget = serial->tiocmget; 1617 1634 1618 1635 memset(icount, 0, sizeof(struct serial_icounter_struct)); ··· 1642 1659 static int hso_serial_tiocmget(struct tty_struct *tty) 1643 1660 { 1644 1661 int retval; 1645 - struct hso_serial *serial = get_serial_by_tty(tty); 1662 + struct hso_serial *serial = tty->driver_data; 1646 1663 struct hso_tiocmget *tiocmget; 1647 1664 u16 UART_state_bitmap; 1648 1665 ··· 1676 1693 int val = 0; 1677 1694 unsigned long flags; 1678 1695 int if_num; 1679 - struct hso_serial *serial = get_serial_by_tty(tty); 1696 + struct hso_serial *serial = tty->driver_data; 1680 1697 1681 1698 /* sanity check */ 1682 1699 if (!serial) { ··· 1716 1733 static int hso_serial_ioctl(struct tty_struct *tty, 1717 1734 unsigned int cmd, unsigned long arg) 1718 1735 { 1719 - struct hso_serial *serial = get_serial_by_tty(tty); 1736 + struct hso_serial *serial = tty->driver_data; 1720 1737 int ret = 0; 1721 1738 D4("IOCTL cmd: %d, arg: %ld", cmd, arg); 1722 1739 ··· 1888 1905 D1("Pending read interrupt on port %d\n", i); 1889 1906 spin_lock(&serial->serial_lock); 1890 1907 if (serial->rx_state == RX_IDLE && 1891 - serial->open_count > 0) { 1908 + serial->port.count > 0) { 1892 1909 /* Setup and send a ctrl req read on 1893 1910 * port i */ 1894 1911 if (!serial->rx_urb_filled[0]) { ··· 1937 1954 1938 1955 spin_lock(&serial->serial_lock); 1939 1956 serial->tx_urb_used = 0; 1940 - tty = tty_kref_get(serial->tty); 1941 1957 spin_unlock(&serial->serial_lock); 1942 1958 if (status) { 1943 1959 handle_usb_error(status, __func__, serial->parent); 1944 - tty_kref_put(tty); 1945 1960 return; 1946 1961 } 1947 1962 hso_put_activity(serial->parent); 1963 + tty = tty_port_tty_get(&serial->port); 1948 1964 if (tty) { 1949 1965 tty_wakeup(tty); 1950 1966 tty_kref_put(tty); ··· 1983 2001 struct hso_serial *serial = urb->context; 1984 2002 struct usb_ctrlrequest *req; 1985 2003 int status = urb->status; 1986 - struct tty_struct *tty; 1987 2004 1988 2005 /* sanity check */ 1989 2006 if (!serial) ··· 1990 2009 1991 2010 spin_lock(&serial->serial_lock); 1992 2011 serial->tx_urb_used = 0; 1993 - tty = tty_kref_get(serial->tty); 1994 2012 spin_unlock(&serial->serial_lock); 1995 2013 if (status) { 1996 2014 handle_usb_error(status, __func__, serial->parent); 1997 - tty_kref_put(tty); 1998 2015 return; 1999 2016 } 2000 2017 ··· 2010 2031 put_rxbuf_data_and_resubmit_ctrl_urb(serial); 2011 2032 spin_unlock(&serial->serial_lock); 2012 2033 } else { 2034 + struct tty_struct *tty = tty_port_tty_get(&serial->port); 2013 2035 hso_put_activity(serial->parent); 2014 - if (tty) 2036 + if (tty) { 2015 2037 tty_wakeup(tty); 2038 + tty_kref_put(tty); 2039 + } 2016 2040 /* response to a write command */ 2017 2041 hso_kick_transmit(serial); 2018 2042 } 2019 - tty_kref_put(tty); 2020 2043 } 2021 2044 2022 2045 /* handle RX data for serial port */ ··· 2034 2053 return -2; 2035 2054 } 2036 2055 2037 - /* All callers to put_rxbuf_data hold serial_lock */ 2038 - tty = tty_kref_get(serial->tty); 2056 + tty = tty_port_tty_get(&serial->port); 2039 2057 2040 2058 /* Push data to tty */ 2041 2059 if (tty) { ··· 2054 2074 write_length_remaining -= curr_write_len; 2055 2075 tty_flip_buffer_push(tty); 2056 2076 } 2077 + tty_kref_put(tty); 2057 2078 } 2058 2079 if (write_length_remaining == 0) { 2059 2080 serial->curr_rx_urb_offset = 0; 2060 2081 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; 2061 2082 } 2062 - tty_kref_put(tty); 2063 2083 return write_length_remaining; 2064 2084 } 2065 2085 ··· 2300 2320 serial->minor = minor; 2301 2321 serial->magic = HSO_SERIAL_MAGIC; 2302 2322 spin_lock_init(&serial->serial_lock); 2323 + tty_port_init(&serial->port); 2303 2324 serial->num_rx_urbs = num_urbs; 2304 2325 2305 2326 /* RX, allocate urb and initialize */ ··· 3079 3098 /* Start all serial ports */ 3080 3099 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { 3081 3100 if (serial_table[i] && (serial_table[i]->interface == iface)) { 3082 - if (dev2ser(serial_table[i])->open_count) { 3101 + if (dev2ser(serial_table[i])->port.count) { 3083 3102 result = 3084 3103 hso_start_serial_device(serial_table[i], GFP_NOIO); 3085 3104 hso_kick_transmit(dev2ser(serial_table[i])); ··· 3153 3172 if (serial_table[i] && 3154 3173 (serial_table[i]->interface == interface)) { 3155 3174 hso_dev = dev2ser(serial_table[i]); 3156 - spin_lock_irq(&hso_dev->serial_lock); 3157 - tty = tty_kref_get(hso_dev->tty); 3158 - spin_unlock_irq(&hso_dev->serial_lock); 3159 - if (tty) 3175 + tty = tty_port_tty_get(&hso_dev->port); 3176 + if (tty) { 3160 3177 tty_hangup(tty); 3178 + tty_kref_put(tty); 3179 + } 3161 3180 mutex_lock(&hso_dev->parent->mutex); 3162 - tty_kref_put(tty); 3163 3181 hso_dev->parent->usb_gone = 1; 3164 3182 mutex_unlock(&hso_dev->parent->mutex); 3165 3183 kref_put(&serial_table[i]->ref, hso_serial_ref_free); ··· 3292 3312 return -ENOMEM; 3293 3313 3294 3314 /* fill in all needed values */ 3295 - tty_drv->magic = TTY_DRIVER_MAGIC; 3296 3315 tty_drv->driver_name = driver_name; 3297 3316 tty_drv->name = tty_filename; 3298 3317 ··· 3312 3333 if (result) { 3313 3334 printk(KERN_ERR "%s - tty_register_driver failed(%d)\n", 3314 3335 __func__, result); 3315 - return result; 3336 + goto err_free_tty; 3316 3337 } 3317 3338 3318 3339 /* register this module as an usb driver */ ··· 3320 3341 if (result) { 3321 3342 printk(KERN_ERR "Could not register hso driver? error: %d\n", 3322 3343 result); 3323 - /* cleanup serial interface */ 3324 - tty_unregister_driver(tty_drv); 3325 - return result; 3344 + goto err_unreg_tty; 3326 3345 } 3327 3346 3328 3347 /* done */ 3329 3348 return 0; 3349 + err_unreg_tty: 3350 + tty_unregister_driver(tty_drv); 3351 + err_free_tty: 3352 + put_tty_driver(tty_drv); 3353 + return result; 3330 3354 } 3331 3355 3332 3356 static void __exit hso_exit(void) ··· 3337 3355 printk(KERN_INFO "hso: unloaded\n"); 3338 3356 3339 3357 tty_unregister_driver(tty_drv); 3358 + put_tty_driver(tty_drv); 3340 3359 /* deregister the usb driver */ 3341 3360 usb_deregister(&hso_driver); 3342 3361 }
+76 -66
drivers/s390/char/con3215.c
··· 20 20 #include <linux/interrupt.h> 21 21 #include <linux/err.h> 22 22 #include <linux/reboot.h> 23 + #include <linux/serial.h> /* ASYNC_* flags */ 23 24 #include <linux/slab.h> 24 25 #include <asm/ccwdev.h> 25 26 #include <asm/cio.h> ··· 45 44 #define RAW3215_TIMEOUT HZ/10 /* time for delayed output */ 46 45 47 46 #define RAW3215_FIXED 1 /* 3215 console device is not be freed */ 48 - #define RAW3215_ACTIVE 2 /* set if the device is in use */ 49 47 #define RAW3215_WORKING 4 /* set if a request is being worked on */ 50 48 #define RAW3215_THROTTLED 8 /* set if reading is disabled */ 51 49 #define RAW3215_STOPPED 16 /* set if writing is disabled */ 52 - #define RAW3215_CLOSING 32 /* set while in close process */ 53 50 #define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */ 54 51 #define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */ 55 - #define RAW3215_FROZEN 256 /* set if 3215 is frozen for suspend */ 56 52 57 53 #define TAB_STOP_SIZE 8 /* tab stop size */ 58 54 ··· 74 76 } __attribute__ ((aligned(8))); 75 77 76 78 struct raw3215_info { 79 + struct tty_port port; 77 80 struct ccw_device *cdev; /* device for tty driver */ 78 81 spinlock_t *lock; /* pointer to irq lock */ 79 82 int flags; /* state flags */ ··· 83 84 int head; /* first free byte in output buffer */ 84 85 int count; /* number of bytes in output buffer */ 85 86 int written; /* number of bytes in write requests */ 86 - struct tty_struct *tty; /* pointer to tty structure if present */ 87 87 struct raw3215_req *queued_read; /* pointer to queued read requests */ 88 88 struct raw3215_req *queued_write;/* pointer to queued write requests */ 89 89 struct tasklet_struct tlet; /* tasklet to invoke tty_wakeup */ ··· 291 293 if (raw->flags & RAW3215_TIMER_RUNS) { 292 294 del_timer(&raw->timer); 293 295 raw->flags &= ~RAW3215_TIMER_RUNS; 294 - if (!(raw->flags & RAW3215_FROZEN)) { 296 + if (!(raw->port.flags & ASYNC_SUSPENDED)) { 295 297 raw3215_mk_write_req(raw); 296 298 raw3215_start_io(raw); 297 299 } ··· 307 309 */ 308 310 static inline void raw3215_try_io(struct raw3215_info *raw) 309 311 { 310 - if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FROZEN)) 312 + if (!(raw->port.flags & ASYNC_INITIALIZED) || 313 + (raw->port.flags & ASYNC_SUSPENDED)) 311 314 return; 312 315 if (raw->queued_read != NULL) 313 316 raw3215_start_io(raw); ··· 323 324 } 324 325 } else if (!(raw->flags & RAW3215_TIMER_RUNS)) { 325 326 /* delay small writes */ 326 - init_timer(&raw->timer); 327 327 raw->timer.expires = RAW3215_TIMEOUT + jiffies; 328 - raw->timer.data = (unsigned long) raw; 329 - raw->timer.function = raw3215_timeout; 330 328 add_timer(&raw->timer); 331 329 raw->flags |= RAW3215_TIMER_RUNS; 332 330 } ··· 336 340 static void raw3215_wakeup(unsigned long data) 337 341 { 338 342 struct raw3215_info *raw = (struct raw3215_info *) data; 339 - tty_wakeup(raw->tty); 343 + struct tty_struct *tty; 344 + 345 + tty = tty_port_tty_get(&raw->port); 346 + tty_wakeup(tty); 347 + tty_kref_put(tty); 340 348 } 341 349 342 350 /* 343 351 * Try to start the next IO and wake up processes waiting on the tty. 344 352 */ 345 - static void raw3215_next_io(struct raw3215_info *raw) 353 + static void raw3215_next_io(struct raw3215_info *raw, struct tty_struct *tty) 346 354 { 347 355 raw3215_mk_write_req(raw); 348 356 raw3215_try_io(raw); 349 - if (raw->tty && RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) 357 + if (tty && RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) 350 358 tasklet_schedule(&raw->tlet); 351 359 } 352 360 ··· 368 368 369 369 raw = dev_get_drvdata(&cdev->dev); 370 370 req = (struct raw3215_req *) intparm; 371 + tty = tty_port_tty_get(&raw->port); 371 372 cstat = irb->scsw.cmd.cstat; 372 373 dstat = irb->scsw.cmd.dstat; 373 374 if (cstat != 0) 374 - raw3215_next_io(raw); 375 + raw3215_next_io(raw, tty); 375 376 if (dstat & 0x01) { /* we got a unit exception */ 376 377 dstat &= ~0x01; /* we can ignore it */ 377 378 } ··· 382 381 break; 383 382 /* Attention interrupt, someone hit the enter key */ 384 383 raw3215_mk_read_req(raw); 385 - raw3215_next_io(raw); 384 + raw3215_next_io(raw, tty); 386 385 break; 387 386 case 0x08: 388 387 case 0x0C: 389 388 /* Channel end interrupt. */ 390 389 if ((raw = req->info) == NULL) 391 - return; /* That shouldn't happen ... */ 390 + goto put_tty; /* That shouldn't happen ... */ 392 391 if (req->type == RAW3215_READ) { 393 392 /* store residual count, then wait for device end */ 394 393 req->residual = irb->scsw.cmd.count; ··· 398 397 case 0x04: 399 398 /* Device end interrupt. */ 400 399 if ((raw = req->info) == NULL) 401 - return; /* That shouldn't happen ... */ 402 - if (req->type == RAW3215_READ && raw->tty != NULL) { 400 + goto put_tty; /* That shouldn't happen ... */ 401 + if (req->type == RAW3215_READ && tty != NULL) { 403 402 unsigned int cchar; 404 403 405 - tty = raw->tty; 406 404 count = 160 - req->residual; 407 405 EBCASC(raw->inbuf, count); 408 406 cchar = ctrlchar_handle(raw->inbuf, count, tty); ··· 411 411 412 412 case CTRLCHAR_CTRL: 413 413 tty_insert_flip_char(tty, cchar, TTY_NORMAL); 414 - tty_flip_buffer_push(raw->tty); 414 + tty_flip_buffer_push(tty); 415 415 break; 416 416 417 417 case CTRLCHAR_NONE: ··· 424 424 } else 425 425 count -= 2; 426 426 tty_insert_flip_string(tty, raw->inbuf, count); 427 - tty_flip_buffer_push(raw->tty); 427 + tty_flip_buffer_push(tty); 428 428 break; 429 429 } 430 430 } else if (req->type == RAW3215_WRITE) { ··· 439 439 raw->queued_read == NULL) { 440 440 wake_up_interruptible(&raw->empty_wait); 441 441 } 442 - raw3215_next_io(raw); 442 + raw3215_next_io(raw, tty); 443 443 break; 444 444 default: 445 445 /* Strange interrupt, I'll do my best to clean up */ ··· 451 451 raw->flags &= ~RAW3215_WORKING; 452 452 raw3215_free_req(req); 453 453 } 454 - raw3215_next_io(raw); 454 + raw3215_next_io(raw, tty); 455 455 } 456 - return; 456 + put_tty: 457 + tty_kref_put(tty); 457 458 } 458 459 459 460 /* ··· 488 487 /* While console is frozen for suspend we have no other 489 488 * choice but to drop message from the buffer to make 490 489 * room for even more messages. */ 491 - if (raw->flags & RAW3215_FROZEN) { 490 + if (raw->port.flags & ASYNC_SUSPENDED) { 492 491 raw3215_drop_line(raw); 493 492 continue; 494 493 } ··· 610 609 { 611 610 unsigned long flags; 612 611 613 - if (raw->flags & RAW3215_ACTIVE) 612 + if (raw->port.flags & ASYNC_INITIALIZED) 614 613 return 0; 615 614 raw->line_pos = 0; 616 - raw->flags |= RAW3215_ACTIVE; 615 + raw->port.flags |= ASYNC_INITIALIZED; 617 616 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 618 617 raw3215_try_io(raw); 619 618 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); ··· 629 628 DECLARE_WAITQUEUE(wait, current); 630 629 unsigned long flags; 631 630 632 - if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED)) 631 + if (!(raw->port.flags & ASYNC_INITIALIZED) || 632 + (raw->flags & RAW3215_FIXED)) 633 633 return; 634 634 /* Wait for outstanding requests, then free irq */ 635 635 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 636 636 if ((raw->flags & RAW3215_WORKING) || 637 637 raw->queued_write != NULL || 638 638 raw->queued_read != NULL) { 639 - raw->flags |= RAW3215_CLOSING; 639 + raw->port.flags |= ASYNC_CLOSING; 640 640 add_wait_queue(&raw->empty_wait, &wait); 641 641 set_current_state(TASK_INTERRUPTIBLE); 642 642 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); ··· 645 643 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 646 644 remove_wait_queue(&raw->empty_wait, &wait); 647 645 set_current_state(TASK_RUNNING); 648 - raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING); 646 + raw->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING); 649 647 } 650 648 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); 649 + } 650 + 651 + static struct raw3215_info *raw3215_alloc_info(void) 652 + { 653 + struct raw3215_info *info; 654 + 655 + info = kzalloc(sizeof(struct raw3215_info), GFP_KERNEL | GFP_DMA); 656 + if (!info) 657 + return NULL; 658 + 659 + info->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA); 660 + info->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA); 661 + if (!info->buffer || !info->inbuf) { 662 + kfree(info); 663 + return NULL; 664 + } 665 + 666 + setup_timer(&info->timer, raw3215_timeout, (unsigned long)info); 667 + init_waitqueue_head(&info->empty_wait); 668 + tasklet_init(&info->tlet, raw3215_wakeup, (unsigned long)info); 669 + tty_port_init(&info->port); 670 + 671 + return info; 672 + } 673 + 674 + static void raw3215_free_info(struct raw3215_info *raw) 675 + { 676 + kfree(raw->inbuf); 677 + kfree(raw->buffer); 678 + kfree(raw); 651 679 } 652 680 653 681 static int raw3215_probe (struct ccw_device *cdev) ··· 688 656 /* Console is special. */ 689 657 if (raw3215[0] && (raw3215[0] == dev_get_drvdata(&cdev->dev))) 690 658 return 0; 691 - raw = kmalloc(sizeof(struct raw3215_info) + 692 - RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA); 659 + 660 + raw = raw3215_alloc_info(); 693 661 if (raw == NULL) 694 662 return -ENOMEM; 663 + 664 + raw->cdev = cdev; 665 + dev_set_drvdata(&cdev->dev, raw); 666 + cdev->handler = raw3215_irq; 695 667 696 668 spin_lock(&raw3215_device_lock); 697 669 for (line = 0; line < NR_3215; line++) { ··· 706 670 } 707 671 spin_unlock(&raw3215_device_lock); 708 672 if (line == NR_3215) { 709 - kfree(raw); 673 + raw3215_free_info(raw); 710 674 return -ENODEV; 711 675 } 712 - 713 - raw->cdev = cdev; 714 - raw->inbuf = (char *) raw + sizeof(struct raw3215_info); 715 - memset(raw, 0, sizeof(struct raw3215_info)); 716 - raw->buffer = kmalloc(RAW3215_BUFFER_SIZE, 717 - GFP_KERNEL|GFP_DMA); 718 - if (raw->buffer == NULL) { 719 - spin_lock(&raw3215_device_lock); 720 - raw3215[line] = NULL; 721 - spin_unlock(&raw3215_device_lock); 722 - kfree(raw); 723 - return -ENOMEM; 724 - } 725 - init_waitqueue_head(&raw->empty_wait); 726 - tasklet_init(&raw->tlet, raw3215_wakeup, (unsigned long) raw); 727 - 728 - dev_set_drvdata(&cdev->dev, raw); 729 - cdev->handler = raw3215_irq; 730 676 731 677 return 0; 732 678 } ··· 721 703 raw = dev_get_drvdata(&cdev->dev); 722 704 if (raw) { 723 705 dev_set_drvdata(&cdev->dev, NULL); 724 - kfree(raw->buffer); 725 - kfree(raw); 706 + raw3215_free_info(raw); 726 707 } 727 708 } 728 709 ··· 758 741 raw = dev_get_drvdata(&cdev->dev); 759 742 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 760 743 raw3215_make_room(raw, RAW3215_BUFFER_SIZE); 761 - raw->flags |= RAW3215_FROZEN; 744 + raw->port.flags |= ASYNC_SUSPENDED; 762 745 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); 763 746 return 0; 764 747 } ··· 771 754 /* Allow I/O again and flush output buffer. */ 772 755 raw = dev_get_drvdata(&cdev->dev); 773 756 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 774 - raw->flags &= ~RAW3215_FROZEN; 757 + raw->port.flags &= ~ASYNC_SUSPENDED; 775 758 raw->flags |= RAW3215_FLUSHING; 776 759 raw3215_try_io(raw); 777 760 raw->flags &= ~RAW3215_FLUSHING; ··· 844 827 unsigned long flags; 845 828 846 829 raw = raw3215[0]; /* console 3215 is the first one */ 847 - if (raw->flags & RAW3215_FROZEN) 830 + if (raw->port.flags & ASYNC_SUSPENDED) 848 831 /* The console is still frozen for suspend. */ 849 832 if (ccw_device_force_console()) 850 833 /* Forcing didn't work, no panic message .. */ ··· 914 897 if (IS_ERR(cdev)) 915 898 return -ENODEV; 916 899 917 - raw3215[0] = raw = (struct raw3215_info *) 918 - kzalloc(sizeof(struct raw3215_info), GFP_KERNEL | GFP_DMA); 919 - raw->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA); 920 - raw->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA); 900 + raw3215[0] = raw = raw3215_alloc_info(); 921 901 raw->cdev = cdev; 922 902 dev_set_drvdata(&cdev->dev, raw); 923 903 cdev->handler = raw3215_irq; 924 904 925 905 raw->flags |= RAW3215_FIXED; 926 - init_waitqueue_head(&raw->empty_wait); 927 - tasklet_init(&raw->tlet, raw3215_wakeup, (unsigned long) raw); 928 906 929 907 /* Request the console irq */ 930 908 if (raw3215_startup(raw) != 0) { 931 - kfree(raw->inbuf); 932 - kfree(raw->buffer); 933 - kfree(raw); 909 + raw3215_free_info(raw); 934 910 raw3215[0] = NULL; 935 911 return -ENODEV; 936 912 } ··· 950 940 return -ENODEV; 951 941 952 942 tty->driver_data = raw; 953 - raw->tty = tty; 943 + tty_port_tty_set(&raw->port, tty); 954 944 955 945 tty->low_latency = 0; /* don't use bottom half for pushing chars */ 956 946 /* ··· 981 971 raw3215_shutdown(raw); 982 972 tasklet_kill(&raw->tlet); 983 973 tty->closing = 0; 984 - raw->tty = NULL; 974 + tty_port_tty_set(&raw->port, NULL); 985 975 } 986 976 987 977 /*
+17 -13
drivers/s390/char/keyboard.c
··· 199 199 if (ch == ' ' || ch == d) 200 200 return d; 201 201 202 - kbd_put_queue(kbd->tty, d); 202 + kbd_put_queue(kbd->port, d); 203 203 return ch; 204 204 } 205 205 ··· 221 221 { 222 222 if (kbd->diacr) 223 223 value = handle_diacr(kbd, value); 224 - kbd_put_queue(kbd->tty, value); 224 + kbd_put_queue(kbd->port, value); 225 225 } 226 226 227 227 /* ··· 239 239 k_fn(struct kbd_data *kbd, unsigned char value) 240 240 { 241 241 if (kbd->func_table[value]) 242 - kbd_puts_queue(kbd->tty, kbd->func_table[value]); 242 + kbd_puts_queue(kbd->port, kbd->func_table[value]); 243 243 } 244 244 245 245 static void ··· 257 257 * but we need only 16 bits here 258 258 */ 259 259 static void 260 - to_utf8(struct tty_struct *tty, ushort c) 260 + to_utf8(struct tty_port *port, ushort c) 261 261 { 262 262 if (c < 0x80) 263 263 /* 0******* */ 264 - kbd_put_queue(tty, c); 264 + kbd_put_queue(port, c); 265 265 else if (c < 0x800) { 266 266 /* 110***** 10****** */ 267 - kbd_put_queue(tty, 0xc0 | (c >> 6)); 268 - kbd_put_queue(tty, 0x80 | (c & 0x3f)); 267 + kbd_put_queue(port, 0xc0 | (c >> 6)); 268 + kbd_put_queue(port, 0x80 | (c & 0x3f)); 269 269 } else { 270 270 /* 1110**** 10****** 10****** */ 271 - kbd_put_queue(tty, 0xe0 | (c >> 12)); 272 - kbd_put_queue(tty, 0x80 | ((c >> 6) & 0x3f)); 273 - kbd_put_queue(tty, 0x80 | (c & 0x3f)); 271 + kbd_put_queue(port, 0xe0 | (c >> 12)); 272 + kbd_put_queue(port, 0x80 | ((c >> 6) & 0x3f)); 273 + kbd_put_queue(port, 0x80 | (c & 0x3f)); 274 274 } 275 275 } 276 276 ··· 283 283 unsigned short keysym; 284 284 unsigned char type, value; 285 285 286 - if (!kbd || !kbd->tty) 286 + if (!kbd) 287 287 return; 288 288 289 289 if (keycode >= 384) ··· 323 323 #endif 324 324 (*k_handler[type])(kbd, value); 325 325 } else 326 - to_utf8(kbd->tty, keysym); 326 + to_utf8(kbd->port, keysym); 327 327 } 328 328 329 329 /* ··· 457 457 458 458 int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg) 459 459 { 460 + struct tty_struct *tty; 460 461 void __user *argp; 461 462 unsigned int ct; 462 463 int perm; ··· 468 467 * To have permissions to do most of the vt ioctls, we either have 469 468 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG. 470 469 */ 471 - perm = current->signal->tty == kbd->tty || capable(CAP_SYS_TTY_CONFIG); 470 + tty = tty_port_tty_get(kbd->port); 471 + /* FIXME this test is pretty racy */ 472 + perm = current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG); 473 + tty_kref_put(tty); 472 474 switch (cmd) { 473 475 case KDGKBTYPE: 474 476 return put_user(KB_101, (char __user *)argp);
+11 -3
drivers/s390/char/keyboard.h
··· 21 21 */ 22 22 23 23 struct kbd_data { 24 - struct tty_struct *tty; 24 + struct tty_port *port; 25 25 unsigned short **key_maps; 26 26 char **func_table; 27 27 fn_handler_fn **fn_handler; ··· 42 42 * Helper Functions. 43 43 */ 44 44 static inline void 45 - kbd_put_queue(struct tty_struct *tty, int ch) 45 + kbd_put_queue(struct tty_port *port, int ch) 46 46 { 47 + struct tty_struct *tty = tty_port_tty_get(port); 48 + if (!tty) 49 + return; 47 50 tty_insert_flip_char(tty, ch, 0); 48 51 tty_schedule_flip(tty); 52 + tty_kref_put(tty); 49 53 } 50 54 51 55 static inline void 52 - kbd_puts_queue(struct tty_struct *tty, char *cp) 56 + kbd_puts_queue(struct tty_port *port, char *cp) 53 57 { 58 + struct tty_struct *tty = tty_port_tty_get(port); 59 + if (!tty) 60 + return; 54 61 while (*cp) 55 62 tty_insert_flip_char(tty, *cp++, 0); 56 63 tty_schedule_flip(tty); 64 + tty_kref_put(tty); 57 65 }
+19 -14
drivers/s390/char/sclp_tty.c
··· 48 48 /* Timer for delayed output of console messages. */ 49 49 static struct timer_list sclp_tty_timer; 50 50 51 - static struct tty_struct *sclp_tty; 51 + static struct tty_port sclp_port; 52 52 static unsigned char sclp_tty_chars[SCLP_TTY_BUF_SIZE]; 53 53 static unsigned short int sclp_tty_chars_count; 54 54 ··· 64 64 static int 65 65 sclp_tty_open(struct tty_struct *tty, struct file *filp) 66 66 { 67 - sclp_tty = tty; 67 + tty_port_tty_set(&sclp_port, tty); 68 68 tty->driver_data = NULL; 69 69 tty->low_latency = 0; 70 70 return 0; ··· 76 76 { 77 77 if (tty->count > 1) 78 78 return; 79 - sclp_tty = NULL; 79 + tty_port_tty_set(&sclp_port, NULL); 80 80 } 81 81 82 82 /* ··· 108 108 static void 109 109 sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc) 110 110 { 111 + struct tty_struct *tty; 111 112 unsigned long flags; 112 113 void *page; 113 114 ··· 127 126 spin_unlock_irqrestore(&sclp_tty_lock, flags); 128 127 } while (buffer && sclp_emit_buffer(buffer, sclp_ttybuf_callback)); 129 128 /* check if the tty needs a wake up call */ 130 - if (sclp_tty != NULL) { 131 - tty_wakeup(sclp_tty); 129 + tty = tty_port_tty_get(&sclp_port); 130 + if (tty != NULL) { 131 + tty_wakeup(tty); 132 + tty_kref_put(tty); 132 133 } 133 134 } 134 135 ··· 329 326 static void 330 327 sclp_tty_input(unsigned char* buf, unsigned int count) 331 328 { 329 + struct tty_struct *tty = tty_port_tty_get(&sclp_port); 332 330 unsigned int cchar; 333 331 334 332 /* 335 333 * If this tty driver is currently closed 336 334 * then throw the received input away. 337 335 */ 338 - if (sclp_tty == NULL) 336 + if (tty == NULL) 339 337 return; 340 - cchar = ctrlchar_handle(buf, count, sclp_tty); 338 + cchar = ctrlchar_handle(buf, count, tty); 341 339 switch (cchar & CTRLCHAR_MASK) { 342 340 case CTRLCHAR_SYSRQ: 343 341 break; 344 342 case CTRLCHAR_CTRL: 345 - tty_insert_flip_char(sclp_tty, cchar, TTY_NORMAL); 346 - tty_flip_buffer_push(sclp_tty); 343 + tty_insert_flip_char(tty, cchar, TTY_NORMAL); 344 + tty_flip_buffer_push(tty); 347 345 break; 348 346 case CTRLCHAR_NONE: 349 347 /* send (normal) input to line discipline */ ··· 352 348 (strncmp((const char *) buf + count - 2, "^n", 2) && 353 349 strncmp((const char *) buf + count - 2, "\252n", 2))) { 354 350 /* add the auto \n */ 355 - tty_insert_flip_string(sclp_tty, buf, count); 356 - tty_insert_flip_char(sclp_tty, '\n', TTY_NORMAL); 351 + tty_insert_flip_string(tty, buf, count); 352 + tty_insert_flip_char(tty, '\n', TTY_NORMAL); 357 353 } else 358 - tty_insert_flip_string(sclp_tty, buf, count - 2); 359 - tty_flip_buffer_push(sclp_tty); 354 + tty_insert_flip_string(tty, buf, count - 2); 355 + tty_flip_buffer_push(tty); 360 356 break; 361 357 } 358 + tty_kref_put(tty); 362 359 } 363 360 364 361 /* ··· 548 543 sclp_tty_tolower = 1; 549 544 } 550 545 sclp_tty_chars_count = 0; 551 - sclp_tty = NULL; 546 + tty_port_init(&sclp_port); 552 547 553 548 rc = sclp_register(&sclp_input_event); 554 549 if (rc) {
+15 -18
drivers/s390/char/sclp_vt220.c
··· 34 34 #define SCLP_VT220_DEVICE_NAME "ttysclp" 35 35 #define SCLP_VT220_CONSOLE_NAME "ttyS" 36 36 #define SCLP_VT220_CONSOLE_INDEX 1 /* console=ttyS1 */ 37 - #define SCLP_VT220_BUF_SIZE 80 38 37 39 38 /* Representation of a single write request */ 40 39 struct sclp_vt220_request { ··· 55 56 /* Structures and data needed to register tty driver */ 56 57 static struct tty_driver *sclp_vt220_driver; 57 58 58 - /* The tty_struct that the kernel associated with us */ 59 - static struct tty_struct *sclp_vt220_tty; 59 + static struct tty_port sclp_vt220_port; 60 60 61 61 /* Lock to protect internal data from concurrent access */ 62 62 static spinlock_t sclp_vt220_lock; ··· 114 116 static void 115 117 sclp_vt220_process_queue(struct sclp_vt220_request *request) 116 118 { 119 + struct tty_struct *tty; 117 120 unsigned long flags; 118 121 void *page; 119 122 ··· 140 141 if (request == NULL && sclp_vt220_flush_later) 141 142 sclp_vt220_emit_current(); 142 143 /* Check if the tty needs a wake up call */ 143 - if (sclp_vt220_tty != NULL) { 144 - tty_wakeup(sclp_vt220_tty); 144 + tty = tty_port_tty_get(&sclp_vt220_port); 145 + if (tty) { 146 + tty_wakeup(tty); 147 + tty_kref_put(tty); 145 148 } 146 149 } 147 150 ··· 461 460 static void 462 461 sclp_vt220_receiver_fn(struct evbuf_header *evbuf) 463 462 { 463 + struct tty_struct *tty = tty_port_tty_get(&sclp_vt220_port); 464 464 char *buffer; 465 465 unsigned int count; 466 466 467 467 /* Ignore input if device is not open */ 468 - if (sclp_vt220_tty == NULL) 468 + if (tty == NULL) 469 469 return; 470 470 471 471 buffer = (char *) ((addr_t) evbuf + sizeof(struct evbuf_header)); ··· 480 478 /* Send input to line discipline */ 481 479 buffer++; 482 480 count--; 483 - tty_insert_flip_string(sclp_vt220_tty, buffer, count); 484 - tty_flip_buffer_push(sclp_vt220_tty); 481 + tty_insert_flip_string(tty, buffer, count); 482 + tty_flip_buffer_push(tty); 485 483 break; 486 484 } 485 + tty_kref_put(tty); 487 486 } 488 487 489 488 /* ··· 494 491 sclp_vt220_open(struct tty_struct *tty, struct file *filp) 495 492 { 496 493 if (tty->count == 1) { 497 - sclp_vt220_tty = tty; 498 - tty->driver_data = kmalloc(SCLP_VT220_BUF_SIZE, GFP_KERNEL); 499 - if (tty->driver_data == NULL) 500 - return -ENOMEM; 494 + tty_port_tty_set(&sclp_vt220_port, tty); 501 495 tty->low_latency = 0; 502 496 if (!tty->winsize.ws_row && !tty->winsize.ws_col) { 503 497 tty->winsize.ws_row = 24; ··· 510 510 static void 511 511 sclp_vt220_close(struct tty_struct *tty, struct file *filp) 512 512 { 513 - if (tty->count == 1) { 514 - sclp_vt220_tty = NULL; 515 - kfree(tty->driver_data); 516 - tty->driver_data = NULL; 517 - } 513 + if (tty->count == 1) 514 + tty_port_tty_set(&sclp_vt220_port, NULL); 518 515 } 519 516 520 517 /* ··· 632 635 INIT_LIST_HEAD(&sclp_vt220_empty); 633 636 INIT_LIST_HEAD(&sclp_vt220_outqueue); 634 637 init_timer(&sclp_vt220_timer); 638 + tty_port_init(&sclp_vt220_port); 635 639 sclp_vt220_current_request = NULL; 636 640 sclp_vt220_buffered_chars = 0; 637 - sclp_vt220_tty = NULL; 638 641 sclp_vt220_flush_later = 0; 639 642 640 643 /* Allocate pages for output buffering */
+56 -65
drivers/s390/char/tty3270.c
··· 61 61 */ 62 62 struct tty3270 { 63 63 struct raw3270_view view; 64 - struct tty_struct *tty; /* Pointer to tty structure */ 64 + struct tty_port port; 65 65 void **freemem_pages; /* Array of pages used for freemem. */ 66 66 struct list_head freemem; /* List of free memory for strings. */ 67 67 ··· 324 324 static void 325 325 tty3270_write_callback(struct raw3270_request *rq, void *data) 326 326 { 327 - struct tty3270 *tp; 327 + struct tty3270 *tp = container_of(rq->view, struct tty3270, view); 328 328 329 - tp = (struct tty3270 *) rq->view; 330 329 if (rq->rc != 0) { 331 330 /* Write wasn't successful. Refresh all. */ 332 331 tp->update_flags = TTY_UPDATE_ALL; ··· 449 450 static void 450 451 tty3270_rcl_backward(struct kbd_data *kbd) 451 452 { 452 - struct tty3270 *tp; 453 + struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); 453 454 struct string *s; 454 455 455 - tp = kbd->tty->driver_data; 456 456 spin_lock_bh(&tp->view.lock); 457 457 if (tp->inattr == TF_INPUT) { 458 458 if (tp->rcl_walk && tp->rcl_walk->prev != &tp->rcl_lines) ··· 476 478 static void 477 479 tty3270_exit_tty(struct kbd_data *kbd) 478 480 { 479 - struct tty3270 *tp; 481 + struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); 480 482 481 - tp = kbd->tty->driver_data; 482 483 raw3270_deactivate_view(&tp->view); 483 484 } 484 485 ··· 487 490 static void 488 491 tty3270_scroll_forward(struct kbd_data *kbd) 489 492 { 490 - struct tty3270 *tp; 493 + struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); 491 494 int nr_up; 492 495 493 - tp = kbd->tty->driver_data; 494 496 spin_lock_bh(&tp->view.lock); 495 497 nr_up = tp->nr_up - tp->view.rows + 2; 496 498 if (nr_up < 0) ··· 509 513 static void 510 514 tty3270_scroll_backward(struct kbd_data *kbd) 511 515 { 512 - struct tty3270 *tp; 516 + struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); 513 517 int nr_up; 514 518 515 - tp = kbd->tty->driver_data; 516 519 spin_lock_bh(&tp->view.lock); 517 520 nr_up = tp->nr_up + tp->view.rows - 2; 518 521 if (nr_up + tp->view.rows - 2 > tp->nr_lines) ··· 532 537 tty3270_read_tasklet(struct raw3270_request *rrq) 533 538 { 534 539 static char kreset_data = TW_KR; 535 - struct tty3270 *tp; 540 + struct tty3270 *tp = container_of(rrq->view, struct tty3270, view); 536 541 char *input; 537 542 int len; 538 543 539 - tp = (struct tty3270 *) rrq->view; 540 544 spin_lock_bh(&tp->view.lock); 541 545 /* 542 546 * Two AID keys are special: For 0x7d (enter) the input line ··· 571 577 raw3270_request_add_data(tp->kreset, &kreset_data, 1); 572 578 raw3270_start(&tp->view, tp->kreset); 573 579 574 - /* Emit input string. */ 575 - if (tp->tty) { 576 - while (len-- > 0) 577 - kbd_keycode(tp->kbd, *input++); 578 - /* Emit keycode for AID byte. */ 579 - kbd_keycode(tp->kbd, 256 + tp->input->string[0]); 580 - } 580 + while (len-- > 0) 581 + kbd_keycode(tp->kbd, *input++); 582 + /* Emit keycode for AID byte. */ 583 + kbd_keycode(tp->kbd, 256 + tp->input->string[0]); 581 584 582 585 raw3270_request_reset(rrq); 583 586 xchg(&tp->read, rrq); ··· 587 596 static void 588 597 tty3270_read_callback(struct raw3270_request *rq, void *data) 589 598 { 599 + struct tty3270 *tp = container_of(rq->view, struct tty3270, view); 590 600 raw3270_get_view(rq->view); 591 601 /* Schedule tasklet to pass input to tty. */ 592 - tasklet_schedule(&((struct tty3270 *) rq->view)->readlet); 602 + tasklet_schedule(&tp->readlet); 593 603 } 594 604 595 605 /* ··· 627 635 static int 628 636 tty3270_activate(struct raw3270_view *view) 629 637 { 630 - struct tty3270 *tp; 638 + struct tty3270 *tp = container_of(view, struct tty3270, view); 631 639 632 - tp = (struct tty3270 *) view; 633 640 tp->update_flags = TTY_UPDATE_ALL; 634 641 tty3270_set_timer(tp, 1); 635 642 return 0; ··· 637 646 static void 638 647 tty3270_deactivate(struct raw3270_view *view) 639 648 { 640 - struct tty3270 *tp; 649 + struct tty3270 *tp = container_of(view, struct tty3270, view); 641 650 642 - tp = (struct tty3270 *) view; 643 651 del_timer(&tp->timer); 644 652 } 645 653 ··· 680 690 if (!tp->freemem_pages) 681 691 goto out_tp; 682 692 INIT_LIST_HEAD(&tp->freemem); 693 + INIT_LIST_HEAD(&tp->lines); 694 + INIT_LIST_HEAD(&tp->update); 695 + INIT_LIST_HEAD(&tp->rcl_lines); 696 + tp->rcl_max = 20; 697 + tty_port_init(&tp->port); 698 + setup_timer(&tp->timer, (void (*)(unsigned long)) tty3270_update, 699 + (unsigned long) tp); 700 + tasklet_init(&tp->readlet, 701 + (void (*)(unsigned long)) tty3270_read_tasklet, 702 + (unsigned long) tp->read); 703 + 683 704 for (pages = 0; pages < TTY3270_STRING_PAGES; pages++) { 684 705 tp->freemem_pages[pages] = (void *) 685 706 __get_free_pages(GFP_KERNEL|GFP_DMA, 0); ··· 795 794 static void 796 795 tty3270_release(struct raw3270_view *view) 797 796 { 798 - struct tty3270 *tp; 799 - struct tty_struct *tty; 797 + struct tty3270 *tp = container_of(view, struct tty3270, view); 798 + struct tty_struct *tty = tty_port_tty_get(&tp->port); 800 799 801 - tp = (struct tty3270 *) view; 802 - tty = tp->tty; 803 800 if (tty) { 804 801 tty->driver_data = NULL; 805 - tp->tty = tp->kbd->tty = NULL; 802 + tty_port_tty_set(&tp->port, NULL); 806 803 tty_hangup(tty); 807 804 raw3270_put_view(&tp->view); 805 + tty_kref_put(tty); 808 806 } 809 807 } 810 808 ··· 813 813 static void 814 814 tty3270_free(struct raw3270_view *view) 815 815 { 816 - tty3270_free_screen((struct tty3270 *) view); 817 - tty3270_free_view((struct tty3270 *) view); 816 + struct tty3270 *tp = container_of(view, struct tty3270, view); 817 + tty3270_free_screen(tp); 818 + tty3270_free_view(tp); 818 819 } 819 820 820 821 /* ··· 824 823 static void 825 824 tty3270_del_views(void) 826 825 { 827 - struct tty3270 *tp; 828 826 int i; 829 827 830 828 for (i = 0; i < tty3270_max_index; i++) { 831 - tp = (struct tty3270 *) 829 + struct raw3270_view *view = 832 830 raw3270_find_view(&tty3270_fn, i + RAW3270_FIRSTMINOR); 833 - if (!IS_ERR(tp)) 834 - raw3270_del_view(&tp->view); 831 + if (!IS_ERR(view)) 832 + raw3270_del_view(view); 835 833 } 836 834 } 837 835 ··· 848 848 static int 849 849 tty3270_open(struct tty_struct *tty, struct file * filp) 850 850 { 851 + struct raw3270_view *view; 851 852 struct tty3270 *tp; 852 853 int i, rc; 853 854 854 855 if (tty->count > 1) 855 856 return 0; 856 857 /* Check if the tty3270 is already there. */ 857 - tp = (struct tty3270 *) 858 - raw3270_find_view(&tty3270_fn, 858 + view = raw3270_find_view(&tty3270_fn, 859 859 tty->index + RAW3270_FIRSTMINOR); 860 - if (!IS_ERR(tp)) { 860 + if (!IS_ERR(view)) { 861 + tp = container_of(view, struct tty3270, view); 861 862 tty->driver_data = tp; 862 863 tty->winsize.ws_row = tp->view.rows - 2; 863 864 tty->winsize.ws_col = tp->view.cols; 864 865 tty->low_latency = 0; 865 - tp->tty = tty; 866 - tp->kbd->tty = tty; 866 + /* why to reassign? */ 867 + tty_port_tty_set(&tp->port, tty); 867 868 tp->inattr = TF_INPUT; 868 869 return 0; 869 870 } ··· 872 871 tty3270_max_index = tty->index + 1; 873 872 874 873 /* Quick exit if there is no device for tty->index. */ 875 - if (PTR_ERR(tp) == -ENODEV) 874 + if (PTR_ERR(view) == -ENODEV) 876 875 return -ENODEV; 877 876 878 877 /* Allocate tty3270 structure on first open. */ 879 878 tp = tty3270_alloc_view(); 880 879 if (IS_ERR(tp)) 881 880 return PTR_ERR(tp); 882 - 883 - INIT_LIST_HEAD(&tp->lines); 884 - INIT_LIST_HEAD(&tp->update); 885 - INIT_LIST_HEAD(&tp->rcl_lines); 886 - tp->rcl_max = 20; 887 - setup_timer(&tp->timer, (void (*)(unsigned long)) tty3270_update, 888 - (unsigned long) tp); 889 - tasklet_init(&tp->readlet, 890 - (void (*)(unsigned long)) tty3270_read_tasklet, 891 - (unsigned long) tp->read); 892 881 893 882 rc = raw3270_add_view(&tp->view, &tty3270_fn, 894 883 tty->index + RAW3270_FIRSTMINOR); ··· 894 903 return rc; 895 904 } 896 905 897 - tp->tty = tty; 906 + tty_port_tty_set(&tp->port, tty); 898 907 tty->low_latency = 0; 899 908 tty->driver_data = tp; 900 909 tty->winsize.ws_row = tp->view.rows - 2; ··· 908 917 for (i = 0; i < tp->view.rows - 2; i++) 909 918 tty3270_blank_line(tp); 910 919 911 - tp->kbd->tty = tty; 920 + tp->kbd->port = &tp->port; 912 921 tp->kbd->fn_handler[KVAL(K_INCRCONSOLE)] = tty3270_exit_tty; 913 922 tp->kbd->fn_handler[KVAL(K_SCROLLBACK)] = tty3270_scroll_backward; 914 923 tp->kbd->fn_handler[KVAL(K_SCROLLFORW)] = tty3270_scroll_forward; ··· 926 935 static void 927 936 tty3270_close(struct tty_struct *tty, struct file * filp) 928 937 { 929 - struct tty3270 *tp; 938 + struct tty3270 *tp = tty->driver_data; 930 939 931 940 if (tty->count > 1) 932 941 return; 933 - tp = (struct tty3270 *) tty->driver_data; 934 942 if (tp) { 935 943 tty->driver_data = NULL; 936 - tp->tty = tp->kbd->tty = NULL; 944 + tty_port_tty_set(&tp->port, NULL); 937 945 raw3270_put_view(&tp->view); 938 946 } 939 947 } ··· 1381 1391 tty3270_lf(tp); 1382 1392 break; 1383 1393 case 'Z': /* Respond ID. */ 1384 - kbd_puts_queue(tp->tty, "\033[?6c"); 1394 + kbd_puts_queue(&tp->port, "\033[?6c"); 1385 1395 break; 1386 1396 case '7': /* Save cursor position. */ 1387 1397 tp->saved_cx = tp->cx; ··· 1427 1437 tp->esc_state = ESnormal; 1428 1438 if (ch == 'n' && !tp->esc_ques) { 1429 1439 if (tp->esc_par[0] == 5) /* Status report. */ 1430 - kbd_puts_queue(tp->tty, "\033[0n"); 1440 + kbd_puts_queue(&tp->port, "\033[0n"); 1431 1441 else if (tp->esc_par[0] == 6) { /* Cursor report. */ 1432 1442 char buf[40]; 1433 1443 sprintf(buf, "\033[%d;%dR", tp->cy + 1, tp->cx + 1); 1434 - kbd_puts_queue(tp->tty, buf); 1444 + kbd_puts_queue(&tp->port, buf); 1435 1445 } 1436 1446 return; 1437 1447 } ··· 1503 1513 * String write routine for 3270 ttys 1504 1514 */ 1505 1515 static void 1506 - tty3270_do_write(struct tty3270 *tp, const unsigned char *buf, int count) 1516 + tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty, 1517 + const unsigned char *buf, int count) 1507 1518 { 1508 1519 int i_msg, i; 1509 1520 1510 1521 spin_lock_bh(&tp->view.lock); 1511 - for (i_msg = 0; !tp->tty->stopped && i_msg < count; i_msg++) { 1522 + for (i_msg = 0; !tty->stopped && i_msg < count; i_msg++) { 1512 1523 if (tp->esc_state != 0) { 1513 1524 /* Continue escape sequence. */ 1514 1525 tty3270_escape_sequence(tp, buf[i_msg]); ··· 1586 1595 if (!tp) 1587 1596 return 0; 1588 1597 if (tp->char_count > 0) { 1589 - tty3270_do_write(tp, tp->char_buf, tp->char_count); 1598 + tty3270_do_write(tp, tty, tp->char_buf, tp->char_count); 1590 1599 tp->char_count = 0; 1591 1600 } 1592 - tty3270_do_write(tp, buf, count); 1601 + tty3270_do_write(tp, tty, buf, count); 1593 1602 return count; 1594 1603 } 1595 1604 ··· 1620 1629 if (!tp) 1621 1630 return; 1622 1631 if (tp->char_count > 0) { 1623 - tty3270_do_write(tp, tp->char_buf, tp->char_count); 1632 + tty3270_do_write(tp, tty, tp->char_buf, tp->char_count); 1624 1633 tp->char_count = 0; 1625 1634 } 1626 1635 }
+22 -22
drivers/tty/bfin_jtag_comm.c
··· 62 62 63 63 static struct tty_driver *bfin_jc_driver; 64 64 static struct task_struct *bfin_jc_kthread; 65 - static struct tty_struct * volatile bfin_jc_tty; 66 - static unsigned long bfin_jc_count; 67 - static DEFINE_MUTEX(bfin_jc_tty_mutex); 65 + static struct tty_port port; 68 66 static volatile struct circ_buf bfin_jc_write_buf; 69 67 70 68 static int ··· 71 73 uint32_t inbound_len = 0, outbound_len = 0; 72 74 73 75 while (!kthread_should_stop()) { 76 + struct tty_struct *tty = tty_port_tty_get(&port); 74 77 /* no one left to give data to, so sleep */ 75 - if (bfin_jc_tty == NULL && circ_empty(&bfin_jc_write_buf)) { 78 + if (tty == NULL && circ_empty(&bfin_jc_write_buf)) { 76 79 pr_debug("waiting for readers\n"); 77 80 __set_current_state(TASK_UNINTERRUPTIBLE); 78 81 schedule(); 79 82 __set_current_state(TASK_RUNNING); 83 + continue; 80 84 } 81 85 82 86 /* no data available, so just chill */ 83 87 if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) { 84 88 pr_debug("waiting for data (in_len = %i) (circ: %i %i)\n", 85 89 inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head); 90 + tty_kref_put(tty); 86 91 if (inbound_len) 87 92 schedule(); 88 93 else ··· 95 94 96 95 /* if incoming data is ready, eat it */ 97 96 if (bfin_read_DBGSTAT() & EMUDIF) { 98 - struct tty_struct *tty; 99 - mutex_lock(&bfin_jc_tty_mutex); 100 - tty = (struct tty_struct *)bfin_jc_tty; 101 97 if (tty != NULL) { 102 98 uint32_t emudat = bfin_read_emudat(); 103 99 if (inbound_len == 0) { ··· 108 110 tty_flip_buffer_push(tty); 109 111 } 110 112 } 111 - mutex_unlock(&bfin_jc_tty_mutex); 112 113 } 113 114 114 115 /* if outgoing data is ready, post it */ ··· 117 120 bfin_write_emudat(outbound_len); 118 121 pr_debug("outgoing length: 0x%08x\n", outbound_len); 119 122 } else { 120 - struct tty_struct *tty; 121 123 int tail = bfin_jc_write_buf.tail; 122 124 size_t ate = (4 <= outbound_len ? 4 : outbound_len); 123 125 uint32_t emudat = ··· 128 132 ); 129 133 bfin_jc_write_buf.tail += ate; 130 134 outbound_len -= ate; 131 - mutex_lock(&bfin_jc_tty_mutex); 132 - tty = (struct tty_struct *)bfin_jc_tty; 133 135 if (tty) 134 136 tty_wakeup(tty); 135 - mutex_unlock(&bfin_jc_tty_mutex); 136 137 pr_debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate); 137 138 } 138 139 } 140 + tty_kref_put(tty); 139 141 } 140 142 141 143 __set_current_state(TASK_RUNNING); ··· 143 149 static int 144 150 bfin_jc_open(struct tty_struct *tty, struct file *filp) 145 151 { 146 - mutex_lock(&bfin_jc_tty_mutex); 147 - pr_debug("open %lu\n", bfin_jc_count); 148 - ++bfin_jc_count; 149 - bfin_jc_tty = tty; 152 + unsigned long flags; 153 + 154 + spin_lock_irqsave(&port.lock, flags); 155 + port.count++; 156 + spin_unlock_irqrestore(&port.lock, flags); 157 + tty_port_tty_set(&port, tty); 150 158 wake_up_process(bfin_jc_kthread); 151 - mutex_unlock(&bfin_jc_tty_mutex); 152 159 return 0; 153 160 } 154 161 155 162 static void 156 163 bfin_jc_close(struct tty_struct *tty, struct file *filp) 157 164 { 158 - mutex_lock(&bfin_jc_tty_mutex); 159 - pr_debug("close %lu\n", bfin_jc_count); 160 - if (--bfin_jc_count == 0) 161 - bfin_jc_tty = NULL; 165 + unsigned long flags; 166 + bool last; 167 + 168 + spin_lock_irqsave(&port.lock, flags); 169 + last = --port.count == 0; 170 + spin_unlock_irqrestore(&port.lock, flags); 171 + if (last) 172 + tty_port_tty_set(&port, NULL); 162 173 wake_up_process(bfin_jc_kthread); 163 - mutex_unlock(&bfin_jc_tty_mutex); 164 174 } 165 175 166 176 /* XXX: we dont handle the put_char() case where we must handle count = 1 */ ··· 239 241 static int __init bfin_jc_init(void) 240 242 { 241 243 int ret; 244 + 245 + tty_port_init(&port); 242 246 243 247 bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME); 244 248 if (IS_ERR(bfin_jc_kthread))
+46 -50
drivers/tty/hvc/hvc_console.c
··· 107 107 list_for_each_entry(hp, &hvc_structs, next) { 108 108 spin_lock_irqsave(&hp->lock, flags); 109 109 if (hp->index == index) { 110 - kref_get(&hp->kref); 110 + tty_port_get(&hp->port); 111 111 spin_unlock_irqrestore(&hp->lock, flags); 112 112 spin_unlock(&hvc_structs_lock); 113 113 return hp; ··· 229 229 console_initcall(hvc_console_init); 230 230 231 231 /* callback when the kboject ref count reaches zero. */ 232 - static void destroy_hvc_struct(struct kref *kref) 232 + static void hvc_port_destruct(struct tty_port *port) 233 233 { 234 - struct hvc_struct *hp = container_of(kref, struct hvc_struct, kref); 234 + struct hvc_struct *hp = container_of(port, struct hvc_struct, port); 235 235 unsigned long flags; 236 236 237 237 spin_lock(&hvc_structs_lock); ··· 264 264 /* make sure no no tty has been registered in this index */ 265 265 hp = hvc_get_by_index(index); 266 266 if (hp) { 267 - kref_put(&hp->kref, destroy_hvc_struct); 267 + tty_port_put(&hp->port); 268 268 return -1; 269 269 } 270 270 ··· 313 313 if (!(hp = hvc_get_by_index(tty->index))) 314 314 return -ENODEV; 315 315 316 - spin_lock_irqsave(&hp->lock, flags); 316 + spin_lock_irqsave(&hp->port.lock, flags); 317 317 /* Check and then increment for fast path open. */ 318 - if (hp->count++ > 0) { 319 - tty_kref_get(tty); 320 - spin_unlock_irqrestore(&hp->lock, flags); 318 + if (hp->port.count++ > 0) { 319 + spin_unlock_irqrestore(&hp->port.lock, flags); 321 320 hvc_kick(); 322 321 return 0; 323 322 } /* else count == 0 */ 323 + spin_unlock_irqrestore(&hp->port.lock, flags); 324 324 325 325 tty->driver_data = hp; 326 - 327 - hp->tty = tty_kref_get(tty); 328 - 329 - spin_unlock_irqrestore(&hp->lock, flags); 326 + tty_port_tty_set(&hp->port, tty); 330 327 331 328 if (hp->ops->notifier_add) 332 329 rc = hp->ops->notifier_add(hp, hp->data); ··· 335 338 * tty fields and return the kref reference. 336 339 */ 337 340 if (rc) { 338 - spin_lock_irqsave(&hp->lock, flags); 339 - hp->tty = NULL; 340 - spin_unlock_irqrestore(&hp->lock, flags); 341 - tty_kref_put(tty); 341 + tty_port_tty_set(&hp->port, NULL); 342 342 tty->driver_data = NULL; 343 - kref_put(&hp->kref, destroy_hvc_struct); 343 + tty_port_put(&hp->port); 344 344 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc); 345 345 } 346 346 /* Force wakeup of the polling thread */ ··· 364 370 365 371 hp = tty->driver_data; 366 372 367 - spin_lock_irqsave(&hp->lock, flags); 373 + spin_lock_irqsave(&hp->port.lock, flags); 368 374 369 - if (--hp->count == 0) { 375 + if (--hp->port.count == 0) { 376 + spin_unlock_irqrestore(&hp->port.lock, flags); 370 377 /* We are done with the tty pointer now. */ 371 - hp->tty = NULL; 372 - spin_unlock_irqrestore(&hp->lock, flags); 378 + tty_port_tty_set(&hp->port, NULL); 373 379 374 380 if (hp->ops->notifier_del) 375 381 hp->ops->notifier_del(hp, hp->data); ··· 384 390 */ 385 391 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT); 386 392 } else { 387 - if (hp->count < 0) 393 + if (hp->port.count < 0) 388 394 printk(KERN_ERR "hvc_close %X: oops, count is %d\n", 389 - hp->vtermno, hp->count); 390 - spin_unlock_irqrestore(&hp->lock, flags); 395 + hp->vtermno, hp->port.count); 396 + spin_unlock_irqrestore(&hp->port.lock, flags); 391 397 } 392 398 393 - tty_kref_put(tty); 394 - kref_put(&hp->kref, destroy_hvc_struct); 399 + tty_port_put(&hp->port); 395 400 } 396 401 397 402 static void hvc_hangup(struct tty_struct *tty) ··· 405 412 /* cancel pending tty resize work */ 406 413 cancel_work_sync(&hp->tty_resize); 407 414 408 - spin_lock_irqsave(&hp->lock, flags); 415 + spin_lock_irqsave(&hp->port.lock, flags); 409 416 410 417 /* 411 418 * The N_TTY line discipline has problems such that in a close vs 412 419 * open->hangup case this can be called after the final close so prevent 413 420 * that from happening for now. 414 421 */ 415 - if (hp->count <= 0) { 416 - spin_unlock_irqrestore(&hp->lock, flags); 422 + if (hp->port.count <= 0) { 423 + spin_unlock_irqrestore(&hp->port.lock, flags); 417 424 return; 418 425 } 419 426 420 - temp_open_count = hp->count; 421 - hp->count = 0; 422 - hp->n_outbuf = 0; 423 - hp->tty = NULL; 427 + temp_open_count = hp->port.count; 428 + hp->port.count = 0; 429 + spin_unlock_irqrestore(&hp->port.lock, flags); 430 + tty_port_tty_set(&hp->port, NULL); 424 431 425 - spin_unlock_irqrestore(&hp->lock, flags); 432 + hp->n_outbuf = 0; 426 433 427 434 if (hp->ops->notifier_hangup) 428 435 hp->ops->notifier_hangup(hp, hp->data); 429 436 430 437 while(temp_open_count) { 431 438 --temp_open_count; 432 - tty_kref_put(tty); 433 - kref_put(&hp->kref, destroy_hvc_struct); 439 + tty_port_put(&hp->port); 434 440 } 435 441 } 436 442 ··· 470 478 if (!hp) 471 479 return -EPIPE; 472 480 473 - if (hp->count <= 0) 481 + /* FIXME what's this (unprotected) check for? */ 482 + if (hp->port.count <= 0) 474 483 return -EIO; 475 484 476 485 spin_lock_irqsave(&hp->lock, flags); ··· 519 526 520 527 hp = container_of(work, struct hvc_struct, tty_resize); 521 528 522 - spin_lock_irqsave(&hp->lock, hvc_flags); 523 - if (!hp->tty) { 524 - spin_unlock_irqrestore(&hp->lock, hvc_flags); 529 + tty = tty_port_tty_get(&hp->port); 530 + if (!tty) 525 531 return; 526 - } 527 - ws = hp->ws; 528 - tty = tty_kref_get(hp->tty); 532 + 533 + spin_lock_irqsave(&hp->lock, hvc_flags); 534 + ws = hp->ws; 529 535 spin_unlock_irqrestore(&hp->lock, hvc_flags); 530 536 531 537 tty_do_resize(tty, &ws); ··· 593 601 } 594 602 595 603 /* No tty attached, just skip */ 596 - tty = tty_kref_get(hp->tty); 604 + tty = tty_port_tty_get(&hp->port); 597 605 if (tty == NULL) 598 606 goto bail; 599 607 ··· 673 681 674 682 tty_flip_buffer_push(tty); 675 683 } 676 - if (tty) 677 - tty_kref_put(tty); 684 + tty_kref_put(tty); 678 685 679 686 return poll_mask; 680 687 } ··· 808 817 #endif 809 818 }; 810 819 820 + static const struct tty_port_operations hvc_port_ops = { 821 + .destruct = hvc_port_destruct, 822 + }; 823 + 811 824 struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, 812 825 const struct hv_ops *ops, 813 826 int outbuf_size) ··· 837 842 hp->outbuf_size = outbuf_size; 838 843 hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))]; 839 844 840 - kref_init(&hp->kref); 845 + tty_port_init(&hp->port); 846 + hp->port.ops = &hvc_port_ops; 841 847 842 848 INIT_WORK(&hp->tty_resize, hvc_set_winsz); 843 849 spin_lock_init(&hp->lock); ··· 871 875 unsigned long flags; 872 876 struct tty_struct *tty; 873 877 874 - spin_lock_irqsave(&hp->lock, flags); 875 - tty = tty_kref_get(hp->tty); 878 + tty = tty_port_tty_get(&hp->port); 876 879 880 + spin_lock_irqsave(&hp->lock, flags); 877 881 if (hp->index < MAX_NR_HVC_CONSOLES) 878 882 vtermnos[hp->index] = -1; 879 883 ··· 887 891 * kref cause it to be removed, which will probably be the tty_vhangup 888 892 * below. 889 893 */ 890 - kref_put(&hp->kref, destroy_hvc_struct); 894 + tty_port_put(&hp->port); 891 895 892 896 /* 893 897 * This function call will auto chain call hvc_hangup.
+1 -3
drivers/tty/hvc/hvc_console.h
··· 46 46 #define HVC_ALLOC_TTY_ADAPTERS 8 47 47 48 48 struct hvc_struct { 49 + struct tty_port port; 49 50 spinlock_t lock; 50 51 int index; 51 - struct tty_struct *tty; 52 - int count; 53 52 int do_wakeup; 54 53 char *outbuf; 55 54 int outbuf_size; ··· 60 61 struct winsize ws; 61 62 struct work_struct tty_resize; 62 63 struct list_head next; 63 - struct kref kref; /* ref count & hvc_struct lifetime */ 64 64 }; 65 65 66 66 /* implemented by a low level driver */
+35 -39
drivers/tty/hvc/hvcs.c
··· 261 261 262 262 /* One vty-server per hvcs_struct */ 263 263 struct hvcs_struct { 264 + struct tty_port port; 264 265 spinlock_t lock; 265 266 266 267 /* ··· 269 268 * specific tty index. 270 269 */ 271 270 unsigned int index; 272 - 273 - struct tty_struct *tty; 274 - int open_count; 275 271 276 272 /* 277 273 * Used to tell the driver kernel_thread what operations need to take ··· 288 290 int chars_in_buffer; 289 291 290 292 /* 291 - * Any variable below the kref is valid before a tty is connected and 293 + * Any variable below is valid before a tty is connected and 292 294 * stays valid after the tty is disconnected. These shouldn't be 293 295 * whacked until the kobject refcount reaches zero though some entries 294 296 * may be changed via sysfs initiatives. 295 297 */ 296 - struct kref kref; /* ref count & hvcs_struct lifetime */ 297 298 int connected; /* is the vty-server currently connected to a vty? */ 298 299 uint32_t p_unit_address; /* partner unit address */ 299 300 uint32_t p_partition_ID; /* partner partition ID */ ··· 300 303 struct list_head next; /* list management */ 301 304 struct vio_dev *vdev; 302 305 }; 303 - 304 - /* Required to back map a kref to its containing object */ 305 - #define from_kref(k) container_of(k, struct hvcs_struct, kref) 306 306 307 307 static LIST_HEAD(hvcs_structs); 308 308 static DEFINE_SPINLOCK(hvcs_structs_lock); ··· 416 422 417 423 spin_lock_irqsave(&hvcsd->lock, flags); 418 424 419 - if (hvcsd->open_count > 0) { 425 + if (hvcsd->port.count > 0) { 420 426 spin_unlock_irqrestore(&hvcsd->lock, flags); 421 427 printk(KERN_INFO "HVCS: vterm state unchanged. " 422 428 "The hvcs device node is still in use.\n"); ··· 558 564 static void hvcs_try_write(struct hvcs_struct *hvcsd) 559 565 { 560 566 uint32_t unit_address = hvcsd->vdev->unit_address; 561 - struct tty_struct *tty = hvcsd->tty; 567 + struct tty_struct *tty = hvcsd->port.tty; 562 568 int sent; 563 569 564 570 if (hvcsd->todo_mask & HVCS_TRY_WRITE) { ··· 596 602 spin_lock_irqsave(&hvcsd->lock, flags); 597 603 598 604 unit_address = hvcsd->vdev->unit_address; 599 - tty = hvcsd->tty; 605 + tty = hvcsd->port.tty; 600 606 601 607 hvcs_try_write(hvcsd); 602 608 ··· 695 701 hvcs_index_list[index] = -1; 696 702 } 697 703 698 - /* callback when the kref ref count reaches zero */ 699 - static void destroy_hvcs_struct(struct kref *kref) 704 + static void hvcs_destruct_port(struct tty_port *p) 700 705 { 701 - struct hvcs_struct *hvcsd = from_kref(kref); 706 + struct hvcs_struct *hvcsd = container_of(p, struct hvcs_struct, port); 702 707 struct vio_dev *vdev; 703 708 unsigned long flags; 704 709 ··· 733 740 734 741 kfree(hvcsd); 735 742 } 743 + 744 + static const struct tty_port_operations hvcs_port_ops = { 745 + .destruct = hvcs_destruct_port, 746 + }; 736 747 737 748 static int hvcs_get_index(void) 738 749 { ··· 786 789 if (!hvcsd) 787 790 return -ENODEV; 788 791 789 - 792 + tty_port_init(&hvcsd->port); 793 + hvcsd->port.ops = &hvcs_port_ops; 790 794 spin_lock_init(&hvcsd->lock); 791 - /* Automatically incs the refcount the first time */ 792 - kref_init(&hvcsd->kref); 793 795 794 796 hvcsd->vdev = dev; 795 797 dev_set_drvdata(&dev->dev, hvcsd); ··· 848 852 849 853 spin_lock_irqsave(&hvcsd->lock, flags); 850 854 851 - tty = hvcsd->tty; 855 + tty = hvcsd->port.tty; 852 856 853 857 spin_unlock_irqrestore(&hvcsd->lock, flags); 854 858 ··· 856 860 * Let the last holder of this object cause it to be removed, which 857 861 * would probably be tty_hangup below. 858 862 */ 859 - kref_put(&hvcsd->kref, destroy_hvcs_struct); 863 + tty_port_put(&hvcsd->port); 860 864 861 865 /* 862 866 * The hangup is a scheduled function which will auto chain call ··· 1090 1094 list_for_each_entry(hvcsd, &hvcs_structs, next) { 1091 1095 spin_lock_irqsave(&hvcsd->lock, flags); 1092 1096 if (hvcsd->index == index) { 1093 - kref_get(&hvcsd->kref); 1097 + tty_port_get(&hvcsd->port); 1094 1098 spin_unlock_irqrestore(&hvcsd->lock, flags); 1095 1099 spin_unlock(&hvcs_structs_lock); 1096 1100 return hvcsd; ··· 1134 1138 if ((retval = hvcs_partner_connect(hvcsd))) 1135 1139 goto error_release; 1136 1140 1137 - hvcsd->open_count = 1; 1138 - hvcsd->tty = tty; 1141 + hvcsd->port.count = 1; 1142 + hvcsd->port.tty = tty; 1139 1143 tty->driver_data = hvcsd; 1140 1144 1141 1145 memset(&hvcsd->buffer[0], 0x00, HVCS_BUFF_LEN); ··· 1156 1160 * and will grab the spinlock and free the connection if it fails. 1157 1161 */ 1158 1162 if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) { 1159 - kref_put(&hvcsd->kref, destroy_hvcs_struct); 1163 + tty_port_put(&hvcsd->port); 1160 1164 printk(KERN_WARNING "HVCS: enable device failed.\n"); 1161 1165 return rc; 1162 1166 } ··· 1167 1171 hvcsd = tty->driver_data; 1168 1172 1169 1173 spin_lock_irqsave(&hvcsd->lock, flags); 1170 - kref_get(&hvcsd->kref); 1171 - hvcsd->open_count++; 1174 + tty_port_get(&hvcsd->port); 1175 + hvcsd->port.count++; 1172 1176 hvcsd->todo_mask |= HVCS_SCHED_READ; 1173 1177 spin_unlock_irqrestore(&hvcsd->lock, flags); 1174 1178 ··· 1182 1186 1183 1187 error_release: 1184 1188 spin_unlock_irqrestore(&hvcsd->lock, flags); 1185 - kref_put(&hvcsd->kref, destroy_hvcs_struct); 1189 + tty_port_put(&hvcsd->port); 1186 1190 1187 1191 printk(KERN_WARNING "HVCS: partner connect failed.\n"); 1188 1192 return retval; ··· 1212 1216 hvcsd = tty->driver_data; 1213 1217 1214 1218 spin_lock_irqsave(&hvcsd->lock, flags); 1215 - if (--hvcsd->open_count == 0) { 1219 + if (--hvcsd->port.count == 0) { 1216 1220 1217 1221 vio_disable_interrupts(hvcsd->vdev); 1218 1222 ··· 1221 1225 * execute any operations on the TTY even though it is obligated 1222 1226 * to deliver any pending I/O to the hypervisor. 1223 1227 */ 1224 - hvcsd->tty = NULL; 1228 + hvcsd->port.tty = NULL; 1225 1229 1226 1230 irq = hvcsd->vdev->irq; 1227 1231 spin_unlock_irqrestore(&hvcsd->lock, flags); ··· 1236 1240 tty->driver_data = NULL; 1237 1241 1238 1242 free_irq(irq, hvcsd); 1239 - kref_put(&hvcsd->kref, destroy_hvcs_struct); 1243 + tty_port_put(&hvcsd->port); 1240 1244 return; 1241 - } else if (hvcsd->open_count < 0) { 1245 + } else if (hvcsd->port.count < 0) { 1242 1246 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d" 1243 1247 " is missmanaged.\n", 1244 - hvcsd->vdev->unit_address, hvcsd->open_count); 1248 + hvcsd->vdev->unit_address, hvcsd->port.count); 1245 1249 } 1246 1250 1247 1251 spin_unlock_irqrestore(&hvcsd->lock, flags); 1248 - kref_put(&hvcsd->kref, destroy_hvcs_struct); 1252 + tty_port_put(&hvcsd->port); 1249 1253 } 1250 1254 1251 1255 static void hvcs_hangup(struct tty_struct * tty) ··· 1257 1261 1258 1262 spin_lock_irqsave(&hvcsd->lock, flags); 1259 1263 /* Preserve this so that we know how many kref refs to put */ 1260 - temp_open_count = hvcsd->open_count; 1264 + temp_open_count = hvcsd->port.count; 1261 1265 1262 1266 /* 1263 1267 * Don't kref put inside the spinlock because the destruction ··· 1269 1273 hvcsd->todo_mask = 0; 1270 1274 1271 1275 /* I don't think the tty needs the hvcs_struct pointer after a hangup */ 1272 - hvcsd->tty->driver_data = NULL; 1273 - hvcsd->tty = NULL; 1276 + tty->driver_data = NULL; 1277 + hvcsd->port.tty = NULL; 1274 1278 1275 - hvcsd->open_count = 0; 1279 + hvcsd->port.count = 0; 1276 1280 1277 1281 /* This will drop any buffered data on the floor which is OK in a hangup 1278 1282 * scenario. */ ··· 1297 1301 * NOTE: If this hangup was signaled from user space then the 1298 1302 * final put will never happen. 1299 1303 */ 1300 - kref_put(&hvcsd->kref, destroy_hvcs_struct); 1304 + tty_port_put(&hvcsd->port); 1301 1305 } 1302 1306 } 1303 1307 ··· 1343 1347 * the middle of a write operation? This is a crummy place to do this 1344 1348 * but we want to keep it all in the spinlock. 1345 1349 */ 1346 - if (hvcsd->open_count <= 0) { 1350 + if (hvcsd->port.count <= 0) { 1347 1351 spin_unlock_irqrestore(&hvcsd->lock, flags); 1348 1352 return -ENODEV; 1349 1353 } ··· 1417 1421 { 1418 1422 struct hvcs_struct *hvcsd = tty->driver_data; 1419 1423 1420 - if (!hvcsd || hvcsd->open_count <= 0) 1424 + if (!hvcsd || hvcsd->port.count <= 0) 1421 1425 return 0; 1422 1426 1423 1427 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
+54 -74
drivers/tty/hvc/hvsi.c
··· 69 69 #define __ALIGNED__ __attribute__((__aligned__(sizeof(long)))) 70 70 71 71 struct hvsi_struct { 72 + struct tty_port port; 72 73 struct delayed_work writer; 73 74 struct work_struct handshaker; 74 75 wait_queue_head_t emptyq; /* woken when outbuf is emptied */ 75 76 wait_queue_head_t stateq; /* woken when HVSI state changes */ 76 77 spinlock_t lock; 77 78 int index; 78 - struct tty_struct *tty; 79 - int count; 80 79 uint8_t throttle_buf[128]; 81 80 uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */ 82 81 /* inbuf is for packet reassembly. leave a little room for leftovers. */ ··· 236 237 } 237 238 238 239 static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet, 239 - struct tty_struct **to_hangup, struct hvsi_struct **to_handshake) 240 + struct tty_struct *tty, struct hvsi_struct **to_handshake) 240 241 { 241 242 struct hvsi_control *header = (struct hvsi_control *)packet; 242 243 ··· 246 247 /* CD went away; no more connection */ 247 248 pr_debug("hvsi%i: CD dropped\n", hp->index); 248 249 hp->mctrl &= TIOCM_CD; 249 - /* If userland hasn't done an open(2) yet, hp->tty is NULL. */ 250 - if (hp->tty && !(hp->tty->flags & CLOCAL)) 251 - *to_hangup = hp->tty; 250 + if (tty && !C_CLOCAL(tty)) 251 + tty_hangup(tty); 252 252 } 253 253 break; 254 254 case VSV_CLOSE_PROTOCOL: ··· 329 331 } 330 332 } 331 333 332 - static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len) 334 + static void hvsi_insert_chars(struct hvsi_struct *hp, struct tty_struct *tty, 335 + const char *buf, int len) 333 336 { 334 337 int i; 335 338 ··· 346 347 continue; 347 348 } 348 349 #endif /* CONFIG_MAGIC_SYSRQ */ 349 - tty_insert_flip_char(hp->tty, c, 0); 350 + tty_insert_flip_char(tty, c, 0); 350 351 } 351 352 } 352 353 ··· 359 360 * revisited. 360 361 */ 361 362 #define TTY_THRESHOLD_THROTTLE 128 362 - static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp, 363 + static bool hvsi_recv_data(struct hvsi_struct *hp, struct tty_struct *tty, 363 364 const uint8_t *packet) 364 365 { 365 366 const struct hvsi_header *header = (const struct hvsi_header *)packet; ··· 370 371 pr_debug("queueing %i chars '%.*s'\n", datalen, datalen, data); 371 372 372 373 if (datalen == 0) 373 - return NULL; 374 + return false; 374 375 375 376 if (overflow > 0) { 376 377 pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __func__); 377 378 datalen = TTY_THRESHOLD_THROTTLE; 378 379 } 379 380 380 - hvsi_insert_chars(hp, data, datalen); 381 + hvsi_insert_chars(hp, tty, data, datalen); 381 382 382 383 if (overflow > 0) { 383 384 /* ··· 389 390 hp->n_throttle = overflow; 390 391 } 391 392 392 - return hp->tty; 393 + return true; 393 394 } 394 395 395 396 /* ··· 398 399 * machine during console handshaking (in which case tty = NULL and we ignore 399 400 * incoming data). 400 401 */ 401 - static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip, 402 - struct tty_struct **hangup, struct hvsi_struct **handshake) 402 + static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct *tty, 403 + struct hvsi_struct **handshake) 403 404 { 404 405 uint8_t *packet = hp->inbuf; 405 406 int chunklen; 407 + bool flip = false; 406 408 407 - *flip = NULL; 408 - *hangup = NULL; 409 409 *handshake = NULL; 410 410 411 411 chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ); ··· 438 440 case VS_DATA_PACKET_HEADER: 439 441 if (!is_open(hp)) 440 442 break; 441 - if (hp->tty == NULL) 443 + if (tty == NULL) 442 444 break; /* no tty buffer to put data in */ 443 - *flip = hvsi_recv_data(hp, packet); 445 + flip = hvsi_recv_data(hp, tty, packet); 444 446 break; 445 447 case VS_CONTROL_PACKET_HEADER: 446 - hvsi_recv_control(hp, packet, hangup, handshake); 448 + hvsi_recv_control(hp, packet, tty, handshake); 447 449 break; 448 450 case VS_QUERY_RESPONSE_PACKET_HEADER: 449 451 hvsi_recv_response(hp, packet); ··· 460 462 461 463 packet += len_packet(packet); 462 464 463 - if (*hangup || *handshake) { 464 - pr_debug("%s: hangup or handshake\n", __func__); 465 - /* 466 - * we need to send the hangup now before receiving any more data. 467 - * If we get "data, hangup, data", we can't deliver the second 468 - * data before the hangup. 469 - */ 465 + if (*handshake) { 466 + pr_debug("%s: handshake\n", __func__); 470 467 break; 471 468 } 472 469 } 473 470 474 471 compact_inbuf(hp, packet); 475 472 473 + if (flip) 474 + tty_flip_buffer_push(tty); 475 + 476 476 return 1; 477 477 } 478 478 479 - static void hvsi_send_overflow(struct hvsi_struct *hp) 479 + static void hvsi_send_overflow(struct hvsi_struct *hp, struct tty_struct *tty) 480 480 { 481 481 pr_debug("%s: delivering %i bytes overflow\n", __func__, 482 482 hp->n_throttle); 483 483 484 - hvsi_insert_chars(hp, hp->throttle_buf, hp->n_throttle); 484 + hvsi_insert_chars(hp, tty, hp->throttle_buf, hp->n_throttle); 485 485 hp->n_throttle = 0; 486 486 } 487 487 ··· 490 494 static irqreturn_t hvsi_interrupt(int irq, void *arg) 491 495 { 492 496 struct hvsi_struct *hp = (struct hvsi_struct *)arg; 493 - struct tty_struct *flip; 494 - struct tty_struct *hangup; 495 497 struct hvsi_struct *handshake; 498 + struct tty_struct *tty; 496 499 unsigned long flags; 497 500 int again = 1; 498 501 499 502 pr_debug("%s\n", __func__); 500 503 504 + tty = tty_port_tty_get(&hp->port); 505 + 501 506 while (again) { 502 507 spin_lock_irqsave(&hp->lock, flags); 503 - again = hvsi_load_chunk(hp, &flip, &hangup, &handshake); 508 + again = hvsi_load_chunk(hp, tty, &handshake); 504 509 spin_unlock_irqrestore(&hp->lock, flags); 505 - 506 - /* 507 - * we have to call tty_flip_buffer_push() and tty_hangup() outside our 508 - * spinlock. But we also have to keep going until we've read all the 509 - * available data. 510 - */ 511 - 512 - if (flip) { 513 - /* there was data put in the tty flip buffer */ 514 - tty_flip_buffer_push(flip); 515 - flip = NULL; 516 - } 517 - 518 - if (hangup) { 519 - tty_hangup(hangup); 520 - } 521 510 522 511 if (handshake) { 523 512 pr_debug("hvsi%i: attempting re-handshake\n", handshake->index); ··· 511 530 } 512 531 513 532 spin_lock_irqsave(&hp->lock, flags); 514 - if (hp->tty && hp->n_throttle 515 - && (!test_bit(TTY_THROTTLED, &hp->tty->flags))) { 516 - /* we weren't hung up and we weren't throttled, so we can deliver the 517 - * rest now */ 518 - flip = hp->tty; 519 - hvsi_send_overflow(hp); 533 + if (tty && hp->n_throttle && !test_bit(TTY_THROTTLED, &tty->flags)) { 534 + /* we weren't hung up and we weren't throttled, so we can 535 + * deliver the rest now */ 536 + hvsi_send_overflow(hp, tty); 537 + tty_flip_buffer_push(tty); 520 538 } 521 539 spin_unlock_irqrestore(&hp->lock, flags); 522 540 523 - if (flip) { 524 - tty_flip_buffer_push(flip); 525 - } 541 + tty_kref_put(tty); 526 542 527 543 return IRQ_HANDLED; 528 544 } ··· 727 749 if (hp->state == HVSI_FSP_DIED) 728 750 return -EIO; 729 751 752 + tty_port_tty_set(&hp->port, tty); 730 753 spin_lock_irqsave(&hp->lock, flags); 731 - hp->tty = tty; 732 - hp->count++; 754 + hp->port.count++; 733 755 atomic_set(&hp->seqno, 0); 734 756 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE); 735 757 spin_unlock_irqrestore(&hp->lock, flags); ··· 786 808 787 809 spin_lock_irqsave(&hp->lock, flags); 788 810 789 - if (--hp->count == 0) { 790 - hp->tty = NULL; 811 + if (--hp->port.count == 0) { 812 + tty_port_tty_set(&hp->port, NULL); 791 813 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */ 792 814 793 815 /* only close down connection if it is not the console */ ··· 819 841 820 842 spin_lock_irqsave(&hp->lock, flags); 821 843 } 822 - } else if (hp->count < 0) 844 + } else if (hp->port.count < 0) 823 845 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n", 824 - hp - hvsi_ports, hp->count); 846 + hp - hvsi_ports, hp->port.count); 825 847 826 848 spin_unlock_irqrestore(&hp->lock, flags); 827 849 } ··· 833 855 834 856 pr_debug("%s\n", __func__); 835 857 858 + tty_port_tty_set(&hp->port, NULL); 859 + 836 860 spin_lock_irqsave(&hp->lock, flags); 837 - 838 - hp->count = 0; 861 + hp->port.count = 0; 839 862 hp->n_outbuf = 0; 840 - hp->tty = NULL; 841 - 842 863 spin_unlock_irqrestore(&hp->lock, flags); 843 864 } 844 865 ··· 865 888 { 866 889 struct hvsi_struct *hp = 867 890 container_of(work, struct hvsi_struct, writer.work); 891 + struct tty_struct *tty; 868 892 unsigned long flags; 869 893 #ifdef DEBUG 870 894 static long start_j = 0; ··· 899 921 start_j = 0; 900 922 #endif /* DEBUG */ 901 923 wake_up_all(&hp->emptyq); 902 - tty_wakeup(hp->tty); 924 + tty = tty_port_tty_get(&hp->port); 925 + if (tty) { 926 + tty_wakeup(tty); 927 + tty_kref_put(tty); 928 + } 903 929 } 904 930 905 931 out: ··· 948 966 * and hvsi_write_worker will be scheduled. subsequent hvsi_write() calls 949 967 * will see there is no room in outbuf and return. 950 968 */ 951 - while ((count > 0) && (hvsi_write_room(hp->tty) > 0)) { 952 - int chunksize = min(count, hvsi_write_room(hp->tty)); 969 + while ((count > 0) && (hvsi_write_room(tty) > 0)) { 970 + int chunksize = min(count, hvsi_write_room(tty)); 953 971 954 972 BUG_ON(hp->n_outbuf < 0); 955 973 memcpy(hp->outbuf + hp->n_outbuf, source, chunksize); ··· 996 1014 { 997 1015 struct hvsi_struct *hp = tty->driver_data; 998 1016 unsigned long flags; 999 - int shouldflip = 0; 1000 1017 1001 1018 pr_debug("%s\n", __func__); 1002 1019 1003 1020 spin_lock_irqsave(&hp->lock, flags); 1004 1021 if (hp->n_throttle) { 1005 - hvsi_send_overflow(hp); 1006 - shouldflip = 1; 1022 + hvsi_send_overflow(hp, tty); 1023 + tty_flip_buffer_push(tty); 1007 1024 } 1008 1025 spin_unlock_irqrestore(&hp->lock, flags); 1009 1026 1010 - if (shouldflip) 1011 - tty_flip_buffer_push(hp->tty); 1012 1027 1013 1028 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE); 1014 1029 } ··· 1207 1228 init_waitqueue_head(&hp->emptyq); 1208 1229 init_waitqueue_head(&hp->stateq); 1209 1230 spin_lock_init(&hp->lock); 1231 + tty_port_init(&hp->port); 1210 1232 hp->index = hvsi_count; 1211 1233 hp->inbuf_end = hp->inbuf; 1212 1234 hp->state = HVSI_CLOSED;
+1 -1
drivers/tty/hvc/hvsi_lib.c
··· 377 377 pr_devel("HVSI@%x: open !\n", pv->termno); 378 378 379 379 /* Keep track of the tty data structure */ 380 - pv->tty = tty_kref_get(hp->tty); 380 + pv->tty = tty_port_tty_get(&hp->port); 381 381 382 382 hvsilib_establish(pv); 383 383
+35 -46
drivers/tty/ipwireless/tty.c
··· 44 44 #define TTYTYPE_RAS_RAW (2) 45 45 46 46 struct ipw_tty { 47 + struct tty_port port; 47 48 int index; 48 49 struct ipw_hardware *hardware; 49 50 unsigned int channel_idx; 50 51 unsigned int secondary_channel_idx; 51 52 int tty_type; 52 53 struct ipw_network *network; 53 - struct tty_struct *linux_tty; 54 - int open_count; 55 54 unsigned int control_lines; 56 55 struct mutex ipw_tty_mutex; 57 56 int tx_bytes_queued; ··· 70 71 }; 71 72 72 73 return channel_names[tty_type]; 73 - } 74 - 75 - static void report_registering(struct ipw_tty *tty) 76 - { 77 - char *iftype = tty_type_name(tty->tty_type); 78 - 79 - printk(KERN_INFO IPWIRELESS_PCCARD_NAME 80 - ": registering %s device ttyIPWp%d\n", iftype, tty->index); 81 - } 82 - 83 - static void report_deregistering(struct ipw_tty *tty) 84 - { 85 - char *iftype = tty_type_name(tty->tty_type); 86 - 87 - printk(KERN_INFO IPWIRELESS_PCCARD_NAME 88 - ": deregistering %s device ttyIPWp%d\n", iftype, 89 - tty->index); 90 74 } 91 75 92 76 static struct ipw_tty *get_tty(int index) ··· 99 117 mutex_unlock(&tty->ipw_tty_mutex); 100 118 return -ENODEV; 101 119 } 102 - if (tty->open_count == 0) 120 + if (tty->port.count == 0) 103 121 tty->tx_bytes_queued = 0; 104 122 105 - tty->open_count++; 123 + tty->port.count++; 106 124 107 - tty->linux_tty = linux_tty; 125 + tty->port.tty = linux_tty; 108 126 linux_tty->driver_data = tty; 109 127 linux_tty->low_latency = 1; 110 128 ··· 118 136 119 137 static void do_ipw_close(struct ipw_tty *tty) 120 138 { 121 - tty->open_count--; 139 + tty->port.count--; 122 140 123 - if (tty->open_count == 0) { 124 - struct tty_struct *linux_tty = tty->linux_tty; 141 + if (tty->port.count == 0) { 142 + struct tty_struct *linux_tty = tty->port.tty; 125 143 126 144 if (linux_tty != NULL) { 127 - tty->linux_tty = NULL; 145 + tty->port.tty = NULL; 128 146 linux_tty->driver_data = NULL; 129 147 130 148 if (tty->tty_type == TTYTYPE_MODEM) ··· 141 159 return; 142 160 143 161 mutex_lock(&tty->ipw_tty_mutex); 144 - if (tty->open_count == 0) { 162 + if (tty->port.count == 0) { 145 163 mutex_unlock(&tty->ipw_tty_mutex); 146 164 return; 147 165 } ··· 164 182 int work = 0; 165 183 166 184 mutex_lock(&tty->ipw_tty_mutex); 167 - linux_tty = tty->linux_tty; 185 + linux_tty = tty->port.tty; 168 186 if (linux_tty == NULL) { 169 187 mutex_unlock(&tty->ipw_tty_mutex); 170 188 return; 171 189 } 172 190 173 - if (!tty->open_count) { 191 + if (!tty->port.count) { 174 192 mutex_unlock(&tty->ipw_tty_mutex); 175 193 return; 176 194 } ··· 212 230 return -ENODEV; 213 231 214 232 mutex_lock(&tty->ipw_tty_mutex); 215 - if (!tty->open_count) { 233 + if (!tty->port.count) { 216 234 mutex_unlock(&tty->ipw_tty_mutex); 217 235 return -EINVAL; 218 236 } ··· 252 270 if (!tty) 253 271 return -ENODEV; 254 272 255 - if (!tty->open_count) 273 + if (!tty->port.count) 256 274 return -EINVAL; 257 275 258 276 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued; ··· 294 312 if (!tty) 295 313 return 0; 296 314 297 - if (!tty->open_count) 315 + if (!tty->port.count) 298 316 return 0; 299 317 300 318 return tty->tx_bytes_queued; ··· 375 393 if (!tty) 376 394 return -ENODEV; 377 395 378 - if (!tty->open_count) 396 + if (!tty->port.count) 379 397 return -EINVAL; 380 398 381 399 return get_control_lines(tty); ··· 391 409 if (!tty) 392 410 return -ENODEV; 393 411 394 - if (!tty->open_count) 412 + if (!tty->port.count) 395 413 return -EINVAL; 396 414 397 415 return set_control_lines(tty, set, clear); ··· 405 423 if (!tty) 406 424 return -ENODEV; 407 425 408 - if (!tty->open_count) 426 + if (!tty->port.count) 409 427 return -EINVAL; 410 428 411 429 /* FIXME: Exactly how is the tty object locked here .. */ ··· 474 492 ttys[j]->network = network; 475 493 ttys[j]->tty_type = tty_type; 476 494 mutex_init(&ttys[j]->ipw_tty_mutex); 495 + tty_port_init(&ttys[j]->port); 477 496 478 497 tty_register_device(ipw_tty_driver, j, NULL); 479 498 ipwireless_associate_network_tty(network, channel_idx, ttys[j]); ··· 483 500 ipwireless_associate_network_tty(network, 484 501 secondary_channel_idx, 485 502 ttys[j]); 486 - if (get_tty(j) == ttys[j]) 487 - report_registering(ttys[j]); 503 + /* check if we provide raw device (if loopback is enabled) */ 504 + if (get_tty(j)) 505 + printk(KERN_INFO IPWIRELESS_PCCARD_NAME 506 + ": registering %s device ttyIPWp%d\n", 507 + tty_type_name(tty_type), j); 508 + 488 509 return 0; 489 510 } 490 511 ··· 547 560 548 561 if (ttyj) { 549 562 mutex_lock(&ttyj->ipw_tty_mutex); 550 - if (get_tty(j) == ttyj) 551 - report_deregistering(ttyj); 563 + if (get_tty(j)) 564 + printk(KERN_INFO IPWIRELESS_PCCARD_NAME 565 + ": deregistering %s device ttyIPWp%d\n", 566 + tty_type_name(ttyj->tty_type), j); 552 567 ttyj->closing = 1; 553 - if (ttyj->linux_tty != NULL) { 568 + if (ttyj->port.tty != NULL) { 554 569 mutex_unlock(&ttyj->ipw_tty_mutex); 555 - tty_hangup(ttyj->linux_tty); 556 - /* Wait till the tty_hangup has completed */ 557 - flush_work_sync(&ttyj->linux_tty->hangup_work); 570 + tty_vhangup(ttyj->port.tty); 558 571 /* FIXME: Exactly how is the tty object locked here 559 572 against a parallel ioctl etc */ 573 + /* FIXME2: hangup does not mean all processes 574 + * are gone */ 560 575 mutex_lock(&ttyj->ipw_tty_mutex); 561 576 } 562 - while (ttyj->open_count) 577 + while (ttyj->port.count) 563 578 do_ipw_close(ttyj); 564 579 ipwireless_disassociate_network_ttys(network, 565 580 ttyj->channel_idx); ··· 650 661 */ 651 662 if ((old_control_lines & IPW_CONTROL_LINE_DCD) 652 663 && !(tty->control_lines & IPW_CONTROL_LINE_DCD) 653 - && tty->linux_tty) { 654 - tty_hangup(tty->linux_tty); 664 + && tty->port.tty) { 665 + tty_hangup(tty->port.tty); 655 666 } 656 667 } 657 668
+153 -232
drivers/tty/serial/68328serial.c
··· 17 17 #include <asm/dbg.h> 18 18 #include <linux/module.h> 19 19 #include <linux/errno.h> 20 + #include <linux/serial.h> 20 21 #include <linux/signal.h> 21 22 #include <linux/sched.h> 22 23 #include <linux/timer.h> ··· 57 56 #endif /* CONFIG_M68VZ328 */ 58 57 #endif /* CONFIG_M68EZ328 */ 59 58 60 - #include "68328serial.h" 61 - 62 59 /* Turn off usage of real serial interrupt code, to "support" Copilot */ 63 60 #ifdef CONFIG_XCOPILOT_BUGS 64 61 #undef USE_INTS ··· 64 65 #define USE_INTS 65 66 #endif 66 67 68 + /* 69 + * I believe this is the optimal setting that reduces the number of interrupts. 70 + * At high speeds the output might become a little "bursted" (use USTCNT_TXHE 71 + * if that bothers you), but in most cases it will not, since we try to 72 + * transmit characters every time rs_interrupt is called. Thus, quite often 73 + * you'll see that a receive interrupt occures before the transmit one. 74 + * -- Vladimir Gurevich 75 + */ 76 + #define USTCNT_TX_INTR_MASK (USTCNT_TXEE) 77 + 78 + /* 79 + * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special 80 + * "Old data interrupt" which occures whenever the data stay in the FIFO 81 + * longer than 30 bits time. This allows us to use FIFO without compromising 82 + * latency. '328 does not have this feature and without the real 328-based 83 + * board I would assume that RXRE is the safest setting. 84 + * 85 + * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of 86 + * interrupts. RXFE (receive queue full) causes the system to lose data 87 + * at least at 115200 baud 88 + * 89 + * If your board is busy doing other stuff, you might consider to use 90 + * RXRE (data ready intrrupt) instead. 91 + * 92 + * The other option is to make these INTR masks run-time configurable, so 93 + * that people can dynamically adapt them according to the current usage. 94 + * -- Vladimir Gurevich 95 + */ 96 + 97 + /* (es) */ 98 + #if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328) 99 + #define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN) 100 + #elif defined(CONFIG_M68328) 101 + #define USTCNT_RX_INTR_MASK (USTCNT_RXRE) 102 + #else 103 + #error Please, define the Rx interrupt events for your CPU 104 + #endif 105 + /* (/es) */ 106 + 107 + /* 108 + * This is our internal structure for each serial port's state. 109 + */ 110 + struct m68k_serial { 111 + struct tty_port tport; 112 + char is_cons; /* Is this our console. */ 113 + int magic; 114 + int baud_base; 115 + int port; 116 + int irq; 117 + int type; /* UART type */ 118 + int custom_divisor; 119 + int x_char; /* xon/xoff character */ 120 + int line; 121 + unsigned char *xmit_buf; 122 + int xmit_head; 123 + int xmit_tail; 124 + int xmit_cnt; 125 + }; 126 + 127 + #define SERIAL_MAGIC 0x5301 128 + 129 + /* 130 + * Define the number of ports supported and their irqs. 131 + */ 132 + #define NR_PORTS 1 133 + 67 134 static struct m68k_serial m68k_soft[NR_PORTS]; 68 135 69 - static unsigned int uart_irqs[NR_PORTS] = UART_IRQ_DEFNS; 136 + static unsigned int uart_irqs[NR_PORTS] = { UART_IRQ_NUM }; 70 137 71 138 /* multiple ports are contiguous in memory */ 72 139 m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR; 73 140 74 - struct tty_struct m68k_ttys; 75 - struct m68k_serial *m68k_consinfo = 0; 76 - 77 - #define M68K_CLOCK (16667000) /* FIXME: 16MHz is likely wrong */ 78 - 79 141 struct tty_driver *serial_driver; 80 142 81 - /* number of characters left in xmit buffer before we ask for more */ 82 - #define WAKEUP_CHARS 256 83 - 84 - /* Debugging... DEBUG_INTR is bad to use when one of the zs 85 - * lines is your console ;( 86 - */ 87 - #undef SERIAL_DEBUG_INTR 88 - #undef SERIAL_DEBUG_OPEN 89 - #undef SERIAL_DEBUG_FLOW 90 - 91 - #define RS_ISR_PASS_LIMIT 256 92 - 93 - static void change_speed(struct m68k_serial *info); 143 + static void change_speed(struct m68k_serial *info, struct tty_struct *tty); 94 144 95 145 /* 96 146 * Setup for console. Argument comes from the boot command line. ··· 191 143 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 192 144 9600, 19200, 38400, 57600, 115200, 0 }; 193 145 194 - /* Sets or clears DTR/RTS on the requested line */ 195 - static inline void m68k_rtsdtr(struct m68k_serial *ss, int set) 196 - { 197 - if (set) { 198 - /* set the RTS/CTS line */ 199 - } else { 200 - /* clear it */ 201 - } 202 - return; 203 - } 204 - 205 146 /* Utility routines */ 206 147 static inline int get_baud(struct m68k_serial *ss) 207 148 { ··· 226 189 227 190 static int rs_put_char(char ch) 228 191 { 229 - int flags, loops = 0; 192 + unsigned long flags; 193 + int loops = 0; 230 194 231 195 local_irq_save(flags); 232 196 ··· 262 224 local_irq_restore(flags); 263 225 } 264 226 265 - /* Drop into either the boot monitor or kadb upon receiving a break 266 - * from keyboard/console input. 267 - */ 268 - static void batten_down_hatches(void) 227 + static void receive_chars(struct m68k_serial *info, struct tty_struct *tty, 228 + unsigned short rx) 269 229 { 270 - /* Drop into the debugger */ 271 - } 272 - 273 - static void status_handle(struct m68k_serial *info, unsigned short status) 274 - { 275 - /* If this is console input and this is a 276 - * 'break asserted' status change interrupt 277 - * see if we can drop into the debugger 278 - */ 279 - if((status & URX_BREAK) && info->break_abort) 280 - batten_down_hatches(); 281 - return; 282 - } 283 - 284 - static void receive_chars(struct m68k_serial *info, unsigned short rx) 285 - { 286 - struct tty_struct *tty = info->tty; 287 230 m68328_uart *uart = &uart_addr[info->line]; 288 231 unsigned char ch, flag; 289 232 ··· 278 259 279 260 if(info->is_cons) { 280 261 if(URX_BREAK & rx) { /* whee, break received */ 281 - status_handle(info, rx); 282 262 return; 283 263 #ifdef CONFIG_MAGIC_SYSRQ 284 264 } else if (ch == 0x10) { /* ^P */ ··· 298 280 299 281 flag = TTY_NORMAL; 300 282 301 - if(rx & URX_PARITY_ERROR) { 283 + if (rx & URX_PARITY_ERROR) 302 284 flag = TTY_PARITY; 303 - status_handle(info, rx); 304 - } else if(rx & URX_OVRUN) { 285 + else if (rx & URX_OVRUN) 305 286 flag = TTY_OVERRUN; 306 - status_handle(info, rx); 307 - } else if(rx & URX_FRAME_ERROR) { 287 + else if (rx & URX_FRAME_ERROR) 308 288 flag = TTY_FRAME; 309 - status_handle(info, rx); 310 - } 289 + 311 290 tty_insert_flip_char(tty, ch, flag); 312 291 #ifndef CONFIG_XCOPILOT_BUGS 313 292 } while((rx = uart->urx.w) & URX_DATA_READY); ··· 316 301 return; 317 302 } 318 303 319 - static void transmit_chars(struct m68k_serial *info) 304 + static void transmit_chars(struct m68k_serial *info, struct tty_struct *tty) 320 305 { 321 306 m68328_uart *uart = &uart_addr[info->line]; 322 307 ··· 327 312 goto clear_and_return; 328 313 } 329 314 330 - if((info->xmit_cnt <= 0) || info->tty->stopped) { 315 + if ((info->xmit_cnt <= 0) || !tty || tty->stopped) { 331 316 /* That's peculiar... TX ints off */ 332 317 uart->ustcnt &= ~USTCNT_TX_INTR_MASK; 333 318 goto clear_and_return; ··· 355 340 irqreturn_t rs_interrupt(int irq, void *dev_id) 356 341 { 357 342 struct m68k_serial *info = dev_id; 343 + struct tty_struct *tty = tty_port_tty_get(&info->tport); 358 344 m68328_uart *uart; 359 345 unsigned short rx; 360 346 unsigned short tx; ··· 366 350 #ifdef USE_INTS 367 351 tx = uart->utx.w; 368 352 369 - if (rx & URX_DATA_READY) receive_chars(info, rx); 370 - if (tx & UTX_TX_AVAIL) transmit_chars(info); 353 + if (rx & URX_DATA_READY) 354 + receive_chars(info, tty, rx); 355 + if (tx & UTX_TX_AVAIL) 356 + transmit_chars(info, tty); 371 357 #else 372 - receive_chars(info, rx); 358 + receive_chars(info, tty, rx); 373 359 #endif 360 + tty_kref_put(tty); 361 + 374 362 return IRQ_HANDLED; 375 363 } 376 364 377 - static int startup(struct m68k_serial * info) 365 + static int startup(struct m68k_serial *info, struct tty_struct *tty) 378 366 { 379 367 m68328_uart *uart = &uart_addr[info->line]; 380 368 unsigned long flags; 381 369 382 - if (info->flags & S_INITIALIZED) 370 + if (info->tport.flags & ASYNC_INITIALIZED) 383 371 return 0; 384 372 385 373 if (!info->xmit_buf) { ··· 400 380 */ 401 381 402 382 uart->ustcnt = USTCNT_UEN; 403 - info->xmit_fifo_size = 1; 404 383 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN; 405 384 (void)uart->urx.w; 406 385 ··· 413 394 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK; 414 395 #endif 415 396 416 - if (info->tty) 417 - clear_bit(TTY_IO_ERROR, &info->tty->flags); 397 + if (tty) 398 + clear_bit(TTY_IO_ERROR, &tty->flags); 418 399 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 419 400 420 401 /* 421 402 * and set the speed of the serial port 422 403 */ 423 404 424 - change_speed(info); 405 + change_speed(info, tty); 425 406 426 - info->flags |= S_INITIALIZED; 407 + info->tport.flags |= ASYNC_INITIALIZED; 427 408 local_irq_restore(flags); 428 409 return 0; 429 410 } ··· 432 413 * This routine will shutdown a serial port; interrupts are disabled, and 433 414 * DTR is dropped if the hangup on close termio flag is on. 434 415 */ 435 - static void shutdown(struct m68k_serial * info) 416 + static void shutdown(struct m68k_serial *info, struct tty_struct *tty) 436 417 { 437 418 m68328_uart *uart = &uart_addr[info->line]; 438 419 unsigned long flags; 439 420 440 421 uart->ustcnt = 0; /* All off! */ 441 - if (!(info->flags & S_INITIALIZED)) 422 + if (!(info->tport.flags & ASYNC_INITIALIZED)) 442 423 return; 443 424 444 425 local_irq_save(flags); ··· 448 429 info->xmit_buf = 0; 449 430 } 450 431 451 - if (info->tty) 452 - set_bit(TTY_IO_ERROR, &info->tty->flags); 432 + if (tty) 433 + set_bit(TTY_IO_ERROR, &tty->flags); 453 434 454 - info->flags &= ~S_INITIALIZED; 435 + info->tport.flags &= ~ASYNC_INITIALIZED; 455 436 local_irq_restore(flags); 456 437 } 457 438 ··· 507 488 * This routine is called to set the UART divisor registers to match 508 489 * the specified baud rate for a serial port. 509 490 */ 510 - static void change_speed(struct m68k_serial *info) 491 + static void change_speed(struct m68k_serial *info, struct tty_struct *tty) 511 492 { 512 493 m68328_uart *uart = &uart_addr[info->line]; 513 494 unsigned short port; ··· 515 496 unsigned cflag; 516 497 int i; 517 498 518 - if (!info->tty || !info->tty->termios) 519 - return; 520 - cflag = info->tty->termios->c_cflag; 499 + cflag = tty->termios->c_cflag; 521 500 if (!(port = info->port)) 522 501 return; 523 502 ··· 527 510 i = (i & ~CBAUDEX) + B38400; 528 511 } 529 512 530 - info->baud = baud_table[i]; 531 513 uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) | 532 514 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale); 533 515 ··· 823 807 tmp.line = info->line; 824 808 tmp.port = info->port; 825 809 tmp.irq = info->irq; 826 - tmp.flags = info->flags; 810 + tmp.flags = info->tport.flags; 827 811 tmp.baud_base = info->baud_base; 828 - tmp.close_delay = info->close_delay; 829 - tmp.closing_wait = info->closing_wait; 812 + tmp.close_delay = info->tport.close_delay; 813 + tmp.closing_wait = info->tport.closing_wait; 830 814 tmp.custom_divisor = info->custom_divisor; 831 815 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 832 816 return -EFAULT; ··· 834 818 return 0; 835 819 } 836 820 837 - static int set_serial_info(struct m68k_serial * info, 821 + static int set_serial_info(struct m68k_serial *info, struct tty_struct *tty, 838 822 struct serial_struct * new_info) 839 823 { 824 + struct tty_port *port = &info->tport; 840 825 struct serial_struct new_serial; 841 826 struct m68k_serial old_info; 842 827 int retval = 0; ··· 851 834 if (!capable(CAP_SYS_ADMIN)) { 852 835 if ((new_serial.baud_base != info->baud_base) || 853 836 (new_serial.type != info->type) || 854 - (new_serial.close_delay != info->close_delay) || 855 - ((new_serial.flags & ~S_USR_MASK) != 856 - (info->flags & ~S_USR_MASK))) 837 + (new_serial.close_delay != port->close_delay) || 838 + ((new_serial.flags & ~ASYNC_USR_MASK) != 839 + (port->flags & ~ASYNC_USR_MASK))) 857 840 return -EPERM; 858 - info->flags = ((info->flags & ~S_USR_MASK) | 859 - (new_serial.flags & S_USR_MASK)); 841 + port->flags = ((port->flags & ~ASYNC_USR_MASK) | 842 + (new_serial.flags & ASYNC_USR_MASK)); 860 843 info->custom_divisor = new_serial.custom_divisor; 861 844 goto check_and_exit; 862 845 } 863 846 864 - if (info->count > 1) 847 + if (port->count > 1) 865 848 return -EBUSY; 866 849 867 850 /* ··· 870 853 */ 871 854 872 855 info->baud_base = new_serial.baud_base; 873 - info->flags = ((info->flags & ~S_FLAGS) | 874 - (new_serial.flags & S_FLAGS)); 856 + port->flags = ((port->flags & ~ASYNC_FLAGS) | 857 + (new_serial.flags & ASYNC_FLAGS)); 875 858 info->type = new_serial.type; 876 - info->close_delay = new_serial.close_delay; 877 - info->closing_wait = new_serial.closing_wait; 859 + port->close_delay = new_serial.close_delay; 860 + port->closing_wait = new_serial.closing_wait; 878 861 879 862 check_and_exit: 880 - retval = startup(info); 863 + retval = startup(info, tty); 881 864 return retval; 882 865 } 883 866 ··· 963 946 return get_serial_info(info, 964 947 (struct serial_struct *) arg); 965 948 case TIOCSSERIAL: 966 - return set_serial_info(info, 949 + return set_serial_info(info, tty, 967 950 (struct serial_struct *) arg); 968 951 case TIOCSERGETLSR: /* Get line status register */ 969 952 return get_lsr_info(info, (unsigned int *) arg); ··· 982 965 { 983 966 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 984 967 985 - change_speed(info); 968 + change_speed(info, tty); 986 969 987 970 if ((old_termios->c_cflag & CRTSCTS) && 988 971 !(tty->termios->c_cflag & CRTSCTS)) { ··· 1005 988 static void rs_close(struct tty_struct *tty, struct file * filp) 1006 989 { 1007 990 struct m68k_serial * info = (struct m68k_serial *)tty->driver_data; 991 + struct tty_port *port = &info->tport; 1008 992 m68328_uart *uart = &uart_addr[info->line]; 1009 993 unsigned long flags; 1010 994 ··· 1019 1001 return; 1020 1002 } 1021 1003 1022 - if ((tty->count == 1) && (info->count != 1)) { 1004 + if ((tty->count == 1) && (port->count != 1)) { 1023 1005 /* 1024 1006 * Uh, oh. tty->count is 1, which means that the tty 1025 1007 * structure will be freed. Info->count should always ··· 1028 1010 * serial port won't be shutdown. 1029 1011 */ 1030 1012 printk("rs_close: bad serial port count; tty->count is 1, " 1031 - "info->count is %d\n", info->count); 1032 - info->count = 1; 1013 + "port->count is %d\n", port->count); 1014 + port->count = 1; 1033 1015 } 1034 - if (--info->count < 0) { 1016 + if (--port->count < 0) { 1035 1017 printk("rs_close: bad serial port count for ttyS%d: %d\n", 1036 - info->line, info->count); 1037 - info->count = 0; 1018 + info->line, port->count); 1019 + port->count = 0; 1038 1020 } 1039 - if (info->count) { 1021 + if (port->count) { 1040 1022 local_irq_restore(flags); 1041 1023 return; 1042 1024 } 1043 - info->flags |= S_CLOSING; 1025 + port->flags |= ASYNC_CLOSING; 1044 1026 /* 1045 1027 * Now we wait for the transmit buffer to clear; and we notify 1046 1028 * the line discipline to only process XON/XOFF characters. 1047 1029 */ 1048 1030 tty->closing = 1; 1049 - if (info->closing_wait != S_CLOSING_WAIT_NONE) 1050 - tty_wait_until_sent(tty, info->closing_wait); 1031 + if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) 1032 + tty_wait_until_sent(tty, port->closing_wait); 1051 1033 /* 1052 1034 * At this point we stop accepting input. To do this, we 1053 1035 * disable the receive line status interrupts, and tell the ··· 1058 1040 uart->ustcnt &= ~USTCNT_RXEN; 1059 1041 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK); 1060 1042 1061 - shutdown(info); 1043 + shutdown(info, tty); 1062 1044 rs_flush_buffer(tty); 1063 1045 1064 1046 tty_ldisc_flush(tty); 1065 1047 tty->closing = 0; 1066 - info->event = 0; 1067 - info->tty = NULL; 1048 + tty_port_tty_set(&info->tport, NULL); 1068 1049 #warning "This is not and has never been valid so fix it" 1069 1050 #if 0 1070 1051 if (tty->ldisc.num != ldiscs[N_TTY].num) { ··· 1075 1058 (tty->ldisc.open)(tty); 1076 1059 } 1077 1060 #endif 1078 - if (info->blocked_open) { 1079 - if (info->close_delay) { 1080 - msleep_interruptible(jiffies_to_msecs(info->close_delay)); 1081 - } 1082 - wake_up_interruptible(&info->open_wait); 1061 + if (port->blocked_open) { 1062 + if (port->close_delay) 1063 + msleep_interruptible(jiffies_to_msecs(port->close_delay)); 1064 + wake_up_interruptible(&port->open_wait); 1083 1065 } 1084 - info->flags &= ~(S_NORMAL_ACTIVE|S_CLOSING); 1085 - wake_up_interruptible(&info->close_wait); 1066 + port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1067 + wake_up_interruptible(&port->close_wait); 1086 1068 local_irq_restore(flags); 1087 1069 } 1088 1070 ··· 1096 1080 return; 1097 1081 1098 1082 rs_flush_buffer(tty); 1099 - shutdown(info); 1100 - info->event = 0; 1101 - info->count = 0; 1102 - info->flags &= ~S_NORMAL_ACTIVE; 1103 - info->tty = NULL; 1104 - wake_up_interruptible(&info->open_wait); 1083 + shutdown(info, tty); 1084 + info->tport.count = 0; 1085 + info->tport.flags &= ~ASYNC_NORMAL_ACTIVE; 1086 + tty_port_tty_set(&info->tport, NULL); 1087 + wake_up_interruptible(&info->tport.open_wait); 1105 1088 } 1106 - 1107 - /* 1108 - * ------------------------------------------------------------ 1109 - * rs_open() and friends 1110 - * ------------------------------------------------------------ 1111 - */ 1112 - static int block_til_ready(struct tty_struct *tty, struct file * filp, 1113 - struct m68k_serial *info) 1114 - { 1115 - DECLARE_WAITQUEUE(wait, current); 1116 - int retval; 1117 - int do_clocal = 0; 1118 - 1119 - /* 1120 - * If the device is in the middle of being closed, then block 1121 - * until it's done, and then try again. 1122 - */ 1123 - if (info->flags & S_CLOSING) { 1124 - interruptible_sleep_on(&info->close_wait); 1125 - #ifdef SERIAL_DO_RESTART 1126 - if (info->flags & S_HUP_NOTIFY) 1127 - return -EAGAIN; 1128 - else 1129 - return -ERESTARTSYS; 1130 - #else 1131 - return -EAGAIN; 1132 - #endif 1133 - } 1134 - 1135 - /* 1136 - * If non-blocking mode is set, or the port is not enabled, 1137 - * then make the check up front and then exit. 1138 - */ 1139 - if ((filp->f_flags & O_NONBLOCK) || 1140 - (tty->flags & (1 << TTY_IO_ERROR))) { 1141 - info->flags |= S_NORMAL_ACTIVE; 1142 - return 0; 1143 - } 1144 - 1145 - if (tty->termios->c_cflag & CLOCAL) 1146 - do_clocal = 1; 1147 - 1148 - /* 1149 - * Block waiting for the carrier detect and the line to become 1150 - * free (i.e., not in use by the callout). While we are in 1151 - * this loop, info->count is dropped by one, so that 1152 - * rs_close() knows when to free things. We restore it upon 1153 - * exit, either normal or abnormal. 1154 - */ 1155 - retval = 0; 1156 - add_wait_queue(&info->open_wait, &wait); 1157 - 1158 - info->count--; 1159 - info->blocked_open++; 1160 - while (1) { 1161 - local_irq_disable(); 1162 - m68k_rtsdtr(info, 1); 1163 - local_irq_enable(); 1164 - current->state = TASK_INTERRUPTIBLE; 1165 - if (tty_hung_up_p(filp) || 1166 - !(info->flags & S_INITIALIZED)) { 1167 - #ifdef SERIAL_DO_RESTART 1168 - if (info->flags & S_HUP_NOTIFY) 1169 - retval = -EAGAIN; 1170 - else 1171 - retval = -ERESTARTSYS; 1172 - #else 1173 - retval = -EAGAIN; 1174 - #endif 1175 - break; 1176 - } 1177 - if (!(info->flags & S_CLOSING) && do_clocal) 1178 - break; 1179 - if (signal_pending(current)) { 1180 - retval = -ERESTARTSYS; 1181 - break; 1182 - } 1183 - tty_unlock(); 1184 - schedule(); 1185 - tty_lock(); 1186 - } 1187 - current->state = TASK_RUNNING; 1188 - remove_wait_queue(&info->open_wait, &wait); 1189 - if (!tty_hung_up_p(filp)) 1190 - info->count++; 1191 - info->blocked_open--; 1192 - 1193 - if (retval) 1194 - return retval; 1195 - info->flags |= S_NORMAL_ACTIVE; 1196 - return 0; 1197 - } 1198 1089 1199 1090 /* 1200 1091 * This routine is called whenever a serial port is opened. It ··· 1119 1196 if (serial_paranoia_check(info, tty->name, "rs_open")) 1120 1197 return -ENODEV; 1121 1198 1122 - info->count++; 1199 + info->tport.count++; 1123 1200 tty->driver_data = info; 1124 - info->tty = tty; 1201 + tty_port_tty_set(&info->tport, tty); 1125 1202 1126 1203 /* 1127 1204 * Start up serial port 1128 1205 */ 1129 - retval = startup(info); 1206 + retval = startup(info, tty); 1130 1207 if (retval) 1131 1208 return retval; 1132 1209 1133 - return block_til_ready(tty, filp, info); 1210 + return tty_port_block_til_ready(&info->tport, tty, filp); 1134 1211 } 1135 1212 1136 1213 /* Finally, routines used to initialize the serial driver. */ ··· 1158 1235 .set_ldisc = rs_set_ldisc, 1159 1236 }; 1160 1237 1238 + static const struct tty_port_operations rs_port_ops = { 1239 + }; 1240 + 1161 1241 /* rs_init inits the driver */ 1162 1242 static int __init 1163 1243 rs68328_init(void) 1164 1244 { 1165 - int flags, i; 1245 + unsigned long flags; 1246 + int i; 1166 1247 struct m68k_serial *info; 1167 1248 1168 1249 serial_driver = alloc_tty_driver(NR_PORTS); ··· 1200 1273 for(i=0;i<NR_PORTS;i++) { 1201 1274 1202 1275 info = &m68k_soft[i]; 1276 + tty_port_init(&info->tport); 1277 + info->tport.ops = &rs_port_ops; 1203 1278 info->magic = SERIAL_MAGIC; 1204 1279 info->port = (int) &uart_addr[i]; 1205 - info->tty = NULL; 1206 1280 info->irq = uart_irqs[i]; 1207 1281 info->custom_divisor = 16; 1208 - info->close_delay = 50; 1209 - info->closing_wait = 3000; 1210 1282 info->x_char = 0; 1211 - info->event = 0; 1212 - info->count = 0; 1213 - info->blocked_open = 0; 1214 - init_waitqueue_head(&info->open_wait); 1215 - init_waitqueue_head(&info->close_wait); 1216 1283 info->line = i; 1217 1284 info->is_cons = 1; /* Means shortcuts work */ 1218 1285
-186
drivers/tty/serial/68328serial.h
··· 1 - /* 68328serial.h: Definitions for the mc68328 serial driver. 2 - * 3 - * Copyright (C) 1995 David S. Miller <davem@caip.rutgers.edu> 4 - * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com> 5 - * Copyright (C) 1998, 1999 D. Jeff Dionne <jeff@uclinux.org> 6 - * Copyright (C) 1999 Vladimir Gurevich <vgurevic@cisco.com> 7 - * 8 - * VZ Support/Fixes Evan Stawnyczy <e@lineo.ca> 9 - */ 10 - 11 - #ifndef _MC683XX_SERIAL_H 12 - #define _MC683XX_SERIAL_H 13 - 14 - 15 - struct serial_struct { 16 - int type; 17 - int line; 18 - int port; 19 - int irq; 20 - int flags; 21 - int xmit_fifo_size; 22 - int custom_divisor; 23 - int baud_base; 24 - unsigned short close_delay; 25 - char reserved_char[2]; 26 - int hub6; /* FIXME: We don't have AT&T Hub6 boards! */ 27 - unsigned short closing_wait; /* time to wait before closing */ 28 - unsigned short closing_wait2; /* no longer used... */ 29 - int reserved[4]; 30 - }; 31 - 32 - /* 33 - * For the close wait times, 0 means wait forever for serial port to 34 - * flush its output. 65535 means don't wait at all. 35 - */ 36 - #define S_CLOSING_WAIT_INF 0 37 - #define S_CLOSING_WAIT_NONE 65535 38 - 39 - /* 40 - * Definitions for S_struct (and serial_struct) flags field 41 - */ 42 - #define S_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes 43 - on the callout port */ 44 - #define S_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */ 45 - #define S_SAK 0x0004 /* Secure Attention Key (Orange book) */ 46 - #define S_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */ 47 - 48 - #define S_SPD_MASK 0x0030 49 - #define S_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */ 50 - 51 - #define S_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */ 52 - #define S_SPD_CUST 0x0030 /* Use user-specified divisor */ 53 - 54 - #define S_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */ 55 - #define S_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */ 56 - #define S_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */ 57 - #define S_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */ 58 - #define S_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */ 59 - 60 - #define S_FLAGS 0x0FFF /* Possible legal S flags */ 61 - #define S_USR_MASK 0x0430 /* Legal flags that non-privileged 62 - * users can set or reset */ 63 - 64 - /* Internal flags used only by kernel/chr_drv/serial.c */ 65 - #define S_INITIALIZED 0x80000000 /* Serial port was initialized */ 66 - #define S_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */ 67 - #define S_NORMAL_ACTIVE 0x20000000 /* Normal device is active */ 68 - #define S_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */ 69 - #define S_CLOSING 0x08000000 /* Serial port is closing */ 70 - #define S_CTS_FLOW 0x04000000 /* Do CTS flow control */ 71 - #define S_CHECK_CD 0x02000000 /* i.e., CLOCAL */ 72 - 73 - /* Software state per channel */ 74 - 75 - #ifdef __KERNEL__ 76 - 77 - /* 78 - * I believe this is the optimal setting that reduces the number of interrupts. 79 - * At high speeds the output might become a little "bursted" (use USTCNT_TXHE 80 - * if that bothers you), but in most cases it will not, since we try to 81 - * transmit characters every time rs_interrupt is called. Thus, quite often 82 - * you'll see that a receive interrupt occures before the transmit one. 83 - * -- Vladimir Gurevich 84 - */ 85 - #define USTCNT_TX_INTR_MASK (USTCNT_TXEE) 86 - 87 - /* 88 - * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special 89 - * "Old data interrupt" which occures whenever the data stay in the FIFO 90 - * longer than 30 bits time. This allows us to use FIFO without compromising 91 - * latency. '328 does not have this feature and without the real 328-based 92 - * board I would assume that RXRE is the safest setting. 93 - * 94 - * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of 95 - * interrupts. RXFE (receive queue full) causes the system to lose data 96 - * at least at 115200 baud 97 - * 98 - * If your board is busy doing other stuff, you might consider to use 99 - * RXRE (data ready intrrupt) instead. 100 - * 101 - * The other option is to make these INTR masks run-time configurable, so 102 - * that people can dynamically adapt them according to the current usage. 103 - * -- Vladimir Gurevich 104 - */ 105 - 106 - /* (es) */ 107 - #if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328) 108 - #define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN) 109 - #elif defined(CONFIG_M68328) 110 - #define USTCNT_RX_INTR_MASK (USTCNT_RXRE) 111 - #else 112 - #error Please, define the Rx interrupt events for your CPU 113 - #endif 114 - /* (/es) */ 115 - 116 - /* 117 - * This is our internal structure for each serial port's state. 118 - * 119 - * Many fields are paralleled by the structure used by the serial_struct 120 - * structure. 121 - * 122 - * For definitions of the flags field, see tty.h 123 - */ 124 - 125 - struct m68k_serial { 126 - char soft_carrier; /* Use soft carrier on this channel */ 127 - char break_abort; /* Is serial console in, so process brk/abrt */ 128 - char is_cons; /* Is this our console. */ 129 - 130 - /* We need to know the current clock divisor 131 - * to read the bps rate the chip has currently 132 - * loaded. 133 - */ 134 - unsigned char clk_divisor; /* May be 1, 16, 32, or 64 */ 135 - int baud; 136 - int magic; 137 - int baud_base; 138 - int port; 139 - int irq; 140 - int flags; /* defined in tty.h */ 141 - int type; /* UART type */ 142 - struct tty_struct *tty; 143 - int read_status_mask; 144 - int ignore_status_mask; 145 - int timeout; 146 - int xmit_fifo_size; 147 - int custom_divisor; 148 - int x_char; /* xon/xoff character */ 149 - int close_delay; 150 - unsigned short closing_wait; 151 - unsigned short closing_wait2; 152 - unsigned long event; 153 - unsigned long last_active; 154 - int line; 155 - int count; /* # of fd on device */ 156 - int blocked_open; /* # of blocked opens */ 157 - unsigned char *xmit_buf; 158 - int xmit_head; 159 - int xmit_tail; 160 - int xmit_cnt; 161 - wait_queue_head_t open_wait; 162 - wait_queue_head_t close_wait; 163 - }; 164 - 165 - 166 - #define SERIAL_MAGIC 0x5301 167 - 168 - /* 169 - * The size of the serial xmit buffer is 1 page, or 4096 bytes 170 - */ 171 - #define SERIAL_XMIT_SIZE 4096 172 - 173 - /* 174 - * Events are used to schedule things to happen at timer-interrupt 175 - * time, instead of at rs interrupt time. 176 - */ 177 - #define RS_EVENT_WRITE_WAKEUP 0 178 - 179 - /* 180 - * Define the number of ports supported and their irqs. 181 - */ 182 - #define NR_PORTS 1 183 - #define UART_IRQ_DEFNS {UART_IRQ_NUM} 184 - 185 - #endif /* __KERNEL__ */ 186 - #endif /* !(_MC683XX_SERIAL_H) */
+13 -31
drivers/tty/serial/8250/8250.c
··· 568 568 } 569 569 } 570 570 571 + void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p) 572 + { 573 + unsigned char fcr; 574 + 575 + serial8250_clear_fifos(p); 576 + fcr = uart_config[p->port.type].fcr; 577 + serial_out(p, UART_FCR, fcr); 578 + } 579 + EXPORT_SYMBOL_GPL(serial8250_clear_and_reinit_fifos); 580 + 571 581 /* 572 582 * IER sleep support. UARTs which have EFRs need the "extended 573 583 * capability" bit enabled. Note that on XR16C850s, we need to ··· 1342 1332 } 1343 1333 1344 1334 /* 1345 - * Clear the Tegra rx fifo after a break 1346 - * 1347 - * FIXME: This needs to become a port specific callback once we have a 1348 - * framework for this 1349 - */ 1350 - static void clear_rx_fifo(struct uart_8250_port *up) 1351 - { 1352 - unsigned int status, tmout = 10000; 1353 - do { 1354 - status = serial_in(up, UART_LSR); 1355 - if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS)) 1356 - status = serial_in(up, UART_RX); 1357 - else 1358 - break; 1359 - if (--tmout == 0) 1360 - break; 1361 - udelay(1); 1362 - } while (1); 1363 - } 1364 - 1365 - /* 1366 1335 * serial8250_rx_chars: processes according to the passed in LSR 1367 1336 * value, and returns the remaining LSR bits not handled 1368 1337 * by this Rx routine. ··· 1375 1386 up->lsr_saved_flags = 0; 1376 1387 1377 1388 if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) { 1378 - /* 1379 - * For statistics only 1380 - */ 1381 1389 if (lsr & UART_LSR_BI) { 1382 1390 lsr &= ~(UART_LSR_FE | UART_LSR_PE); 1383 1391 port->icount.brk++; 1384 - /* 1385 - * If tegra port then clear the rx fifo to 1386 - * accept another break/character. 1387 - */ 1388 - if (port->type == PORT_TEGRA) 1389 - clear_rx_fifo(up); 1390 - 1391 1392 /* 1392 1393 * We do the SysRQ and SAK checking 1393 1394 * here because otherwise the break ··· 3016 3037 port.serial_in = p->serial_in; 3017 3038 port.serial_out = p->serial_out; 3018 3039 port.handle_irq = p->handle_irq; 3040 + port.handle_break = p->handle_break; 3019 3041 port.set_termios = p->set_termios; 3020 3042 port.pm = p->pm; 3021 3043 port.dev = &dev->dev; ··· 3189 3209 uart->port.set_termios = port->set_termios; 3190 3210 if (port->pm) 3191 3211 uart->port.pm = port->pm; 3212 + if (port->handle_break) 3213 + uart->port.handle_break = port->handle_break; 3192 3214 3193 3215 if (serial8250_isa_config != NULL) 3194 3216 serial8250_isa_config(0, &uart->port,
+2
drivers/tty/serial/8250/8250.h
··· 96 96 up->port.serial_out(&up->port, offset, value); 97 97 } 98 98 99 + void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p); 100 + 99 101 #if defined(__alpha__) && !defined(CONFIG_PCI) 100 102 /* 101 103 * Digital did something really horribly wrong with the OUT1 and OUT2
+45
drivers/tty/serial/8250/8250_pci.c
··· 17 17 #include <linux/slab.h> 18 18 #include <linux/delay.h> 19 19 #include <linux/tty.h> 20 + #include <linux/serial_reg.h> 20 21 #include <linux/serial_core.h> 21 22 #include <linux/8250_pci.h> 22 23 #include <linux/bitops.h> ··· 1093 1092 return pci_default_setup(priv, board, port, idx); 1094 1093 } 1095 1094 1095 + static void kt_handle_break(struct uart_port *p) 1096 + { 1097 + struct uart_8250_port *up = 1098 + container_of(p, struct uart_8250_port, port); 1099 + /* 1100 + * On receipt of a BI, serial device in Intel ME (Intel 1101 + * management engine) needs to have its fifos cleared for sane 1102 + * SOL (Serial Over Lan) output. 1103 + */ 1104 + serial8250_clear_and_reinit_fifos(up); 1105 + } 1106 + 1107 + static unsigned int kt_serial_in(struct uart_port *p, int offset) 1108 + { 1109 + struct uart_8250_port *up = 1110 + container_of(p, struct uart_8250_port, port); 1111 + unsigned int val; 1112 + 1113 + /* 1114 + * When the Intel ME (management engine) gets reset its serial 1115 + * port registers could return 0 momentarily. Functions like 1116 + * serial8250_console_write, read and save the IER, perform 1117 + * some operation and then restore it. In order to avoid 1118 + * setting IER register inadvertently to 0, if the value read 1119 + * is 0, double check with ier value in uart_8250_port and use 1120 + * that instead. up->ier should be the same value as what is 1121 + * currently configured. 1122 + */ 1123 + val = inb(p->iobase + offset); 1124 + if (offset == UART_IER) { 1125 + if (val == 0) 1126 + val = up->ier; 1127 + } 1128 + return val; 1129 + } 1130 + 1096 1131 static int kt_serial_setup(struct serial_private *priv, 1097 1132 const struct pciserial_board *board, 1098 1133 struct uart_port *port, int idx) 1099 1134 { 1100 1135 port->flags |= UPF_BUG_THRE; 1136 + port->serial_in = kt_serial_in; 1137 + port->handle_break = kt_handle_break; 1101 1138 return skip_tx_en_setup(priv, board, port, idx); 1102 1139 } 1103 1140 ··· 2814 2775 for (i = 0; i < priv->nr; i++) 2815 2776 if (priv->line[i] >= 0) 2816 2777 serial8250_suspend_port(priv->line[i]); 2778 + 2779 + /* 2780 + * Ensure that every init quirk is properly torn down 2781 + */ 2782 + if (priv->quirk->exit) 2783 + priv->quirk->exit(priv->dev); 2817 2784 } 2818 2785 EXPORT_SYMBOL_GPL(pciserial_suspend_ports); 2819 2786
+18 -91
drivers/tty/serial/amba-pl011.c
··· 67 67 #define UART_DR_ERROR (UART011_DR_OE|UART011_DR_BE|UART011_DR_PE|UART011_DR_FE) 68 68 #define UART_DUMMY_DR_RX (1 << 16) 69 69 70 - 71 - #define UART_WA_SAVE_NR 14 72 - 73 - static void pl011_lockup_wa(unsigned long data); 74 - static const u32 uart_wa_reg[UART_WA_SAVE_NR] = { 75 - ST_UART011_DMAWM, 76 - ST_UART011_TIMEOUT, 77 - ST_UART011_LCRH_RX, 78 - UART011_IBRD, 79 - UART011_FBRD, 80 - ST_UART011_LCRH_TX, 81 - UART011_IFLS, 82 - ST_UART011_XFCR, 83 - ST_UART011_XON1, 84 - ST_UART011_XON2, 85 - ST_UART011_XOFF1, 86 - ST_UART011_XOFF2, 87 - UART011_CR, 88 - UART011_IMSC 89 - }; 90 - 91 - static u32 uart_wa_regdata[UART_WA_SAVE_NR]; 92 - static DECLARE_TASKLET(pl011_lockup_tlet, pl011_lockup_wa, 0); 93 - 94 70 /* There is by now at least one vendor with differing details, so handle it */ 95 71 struct vendor_data { 96 72 unsigned int ifls; ··· 76 100 bool oversampling; 77 101 bool interrupt_may_hang; /* vendor-specific */ 78 102 bool dma_threshold; 103 + bool cts_event_workaround; 79 104 }; 80 105 81 106 static struct vendor_data vendor_arm = { ··· 86 109 .lcrh_rx = UART011_LCRH, 87 110 .oversampling = false, 88 111 .dma_threshold = false, 112 + .cts_event_workaround = false, 89 113 }; 90 114 91 115 static struct vendor_data vendor_st = { ··· 97 119 .oversampling = true, 98 120 .interrupt_may_hang = true, 99 121 .dma_threshold = true, 122 + .cts_event_workaround = true, 100 123 }; 101 124 102 125 static struct uart_amba_port *amba_ports[UART_NR]; ··· 1033 1054 #define pl011_dma_flush_buffer NULL 1034 1055 #endif 1035 1056 1036 - 1037 - /* 1038 - * pl011_lockup_wa 1039 - * This workaround aims to break the deadlock situation 1040 - * when after long transfer over uart in hardware flow 1041 - * control, uart interrupt registers cannot be cleared. 1042 - * Hence uart transfer gets blocked. 1043 - * 1044 - * It is seen that during such deadlock condition ICR 1045 - * don't get cleared even on multiple write. This leads 1046 - * pass_counter to decrease and finally reach zero. This 1047 - * can be taken as trigger point to run this UART_BT_WA. 1048 - * 1049 - */ 1050 - static void pl011_lockup_wa(unsigned long data) 1051 - { 1052 - struct uart_amba_port *uap = amba_ports[0]; 1053 - void __iomem *base = uap->port.membase; 1054 - struct circ_buf *xmit = &uap->port.state->xmit; 1055 - struct tty_struct *tty = uap->port.state->port.tty; 1056 - int buf_empty_retries = 200; 1057 - int loop; 1058 - 1059 - /* Stop HCI layer from submitting data for tx */ 1060 - tty->hw_stopped = 1; 1061 - while (!uart_circ_empty(xmit)) { 1062 - if (buf_empty_retries-- == 0) 1063 - break; 1064 - udelay(100); 1065 - } 1066 - 1067 - /* Backup registers */ 1068 - for (loop = 0; loop < UART_WA_SAVE_NR; loop++) 1069 - uart_wa_regdata[loop] = readl(base + uart_wa_reg[loop]); 1070 - 1071 - /* Disable UART so that FIFO data is flushed out */ 1072 - writew(0x00, uap->port.membase + UART011_CR); 1073 - 1074 - /* Soft reset UART module */ 1075 - if (uap->port.dev->platform_data) { 1076 - struct amba_pl011_data *plat; 1077 - 1078 - plat = uap->port.dev->platform_data; 1079 - if (plat->reset) 1080 - plat->reset(); 1081 - } 1082 - 1083 - /* Restore registers */ 1084 - for (loop = 0; loop < UART_WA_SAVE_NR; loop++) 1085 - writew(uart_wa_regdata[loop] , 1086 - uap->port.membase + uart_wa_reg[loop]); 1087 - 1088 - /* Initialise the old status of the modem signals */ 1089 - uap->old_status = readw(uap->port.membase + UART01x_FR) & 1090 - UART01x_FR_MODEM_ANY; 1091 - 1092 - if (readl(base + UART011_MIS) & 0x2) 1093 - printk(KERN_EMERG "UART_BT_WA: ***FAILED***\n"); 1094 - 1095 - /* Start Tx/Rx */ 1096 - tty->hw_stopped = 0; 1097 - } 1098 - 1099 1057 static void pl011_stop_tx(struct uart_port *port) 1100 1058 { 1101 1059 struct uart_amba_port *uap = (struct uart_amba_port *)port; ··· 1161 1245 unsigned long flags; 1162 1246 unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT; 1163 1247 int handled = 0; 1248 + unsigned int dummy_read; 1164 1249 1165 1250 spin_lock_irqsave(&uap->port.lock, flags); 1166 1251 1167 1252 status = readw(uap->port.membase + UART011_MIS); 1168 1253 if (status) { 1169 1254 do { 1255 + if (uap->vendor->cts_event_workaround) { 1256 + /* workaround to make sure that all bits are unlocked.. */ 1257 + writew(0x00, uap->port.membase + UART011_ICR); 1258 + 1259 + /* 1260 + * WA: introduce 26ns(1 uart clk) delay before W1C; 1261 + * single apb access will incur 2 pclk(133.12Mhz) delay, 1262 + * so add 2 dummy reads 1263 + */ 1264 + dummy_read = readw(uap->port.membase + UART011_ICR); 1265 + dummy_read = readw(uap->port.membase + UART011_ICR); 1266 + } 1267 + 1170 1268 writew(status & ~(UART011_TXIS|UART011_RTIS| 1171 1269 UART011_RXIS), 1172 1270 uap->port.membase + UART011_ICR); ··· 1197 1267 if (status & UART011_TXIS) 1198 1268 pl011_tx_chars(uap); 1199 1269 1200 - if (pass_counter-- == 0) { 1201 - if (uap->interrupt_may_hang) 1202 - tasklet_schedule(&pl011_lockup_tlet); 1270 + if (pass_counter-- == 0) 1203 1271 break; 1204 - } 1205 1272 1206 1273 status = readw(uap->port.membase + UART011_MIS); 1207 1274 } while (status != 0);
+2 -26
drivers/tty/serial/crisv10.c
··· 952 952 /* Input */ 953 953 #define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask) 954 954 955 - 956 - /* 957 - * tmp_buf is used as a temporary buffer by serial_write. We need to 958 - * lock it in case the memcpy_fromfs blocks while swapping in a page, 959 - * and some other program tries to do a serial write at the same time. 960 - * Since the lock will only come under contention when the system is 961 - * swapping and available memory is low, it makes sense to share one 962 - * buffer across all the serial ports, since it significantly saves 963 - * memory if large numbers of serial ports are open. 964 - */ 965 - static unsigned char *tmp_buf; 966 - static DEFINE_MUTEX(tmp_buf_mutex); 967 - 968 955 /* Calculate the chartime depending on baudrate, numbor of bits etc. */ 969 956 static void update_char_time(struct e100_serial * info) 970 957 { ··· 3137 3150 3138 3151 /* first some sanity checks */ 3139 3152 3140 - if (!tty || !info->xmit.buf || !tmp_buf) 3153 + if (!tty || !info->xmit.buf) 3141 3154 return 0; 3142 3155 3143 3156 #ifdef SERIAL_DEBUG_DATA ··· 4093 4106 { 4094 4107 struct e100_serial *info; 4095 4108 int retval; 4096 - unsigned long page; 4097 4109 int allocated_resources = 0; 4098 4110 4099 4111 info = rs_table + tty->index; ··· 4109 4123 info->port.tty = tty; 4110 4124 4111 4125 tty->low_latency = !!(info->flags & ASYNC_LOW_LATENCY); 4112 - 4113 - if (!tmp_buf) { 4114 - page = get_zeroed_page(GFP_KERNEL); 4115 - if (!page) { 4116 - return -ENOMEM; 4117 - } 4118 - if (tmp_buf) 4119 - free_page(page); 4120 - else 4121 - tmp_buf = (unsigned char *) page; 4122 - } 4123 4126 4124 4127 /* 4125 4128 * If the port is in the middle of closing, bail out now ··· 4462 4487 info->enabled = 0; 4463 4488 } 4464 4489 } 4490 + tty_port_init(&info->port); 4465 4491 info->uses_dma_in = 0; 4466 4492 info->uses_dma_out = 0; 4467 4493 info->line = i;
+26
drivers/tty/serial/of_serial.c
··· 12 12 #include <linux/init.h> 13 13 #include <linux/module.h> 14 14 #include <linux/slab.h> 15 + #include <linux/delay.h> 15 16 #include <linux/serial_core.h> 16 17 #include <linux/serial_8250.h> 18 + #include <linux/serial_reg.h> 17 19 #include <linux/of_address.h> 18 20 #include <linux/of_irq.h> 21 + #include <linux/of_serial.h> 19 22 #include <linux/of_platform.h> 20 23 #include <linux/nwpserial.h> 21 24 ··· 26 23 int type; 27 24 int line; 28 25 }; 26 + 27 + #ifdef CONFIG_ARCH_TEGRA 28 + void tegra_serial_handle_break(struct uart_port *p) 29 + { 30 + unsigned int status, tmout = 10000; 31 + 32 + do { 33 + status = p->serial_in(p, UART_LSR); 34 + if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS)) 35 + status = p->serial_in(p, UART_RX); 36 + else 37 + break; 38 + if (--tmout == 0) 39 + break; 40 + udelay(1); 41 + } while (1); 42 + } 43 + /* FIXME remove this export when tegra finishes conversion to open firmware */ 44 + EXPORT_SYMBOL_GPL(tegra_serial_handle_break); 45 + #endif 29 46 30 47 /* 31 48 * Fill a struct uart_port for a given device node ··· 106 83 port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP 107 84 | UPF_FIXED_PORT | UPF_FIXED_TYPE; 108 85 port->dev = &ofdev->dev; 86 + 87 + if (type == PORT_TEGRA) 88 + port->handle_break = tegra_serial_handle_break; 109 89 110 90 return 0; 111 91 }
+73 -1
drivers/tty/serial/omap-serial.c
··· 44 44 #include <plat/dmtimer.h> 45 45 #include <plat/omap-serial.h> 46 46 47 + #define UART_BUILD_REVISION(x, y) (((x) << 8) | (y)) 48 + 49 + #define OMAP_UART_REV_42 0x0402 50 + #define OMAP_UART_REV_46 0x0406 51 + #define OMAP_UART_REV_52 0x0502 52 + #define OMAP_UART_REV_63 0x0603 53 + 47 54 #define DEFAULT_CLK_SPEED 48000000 /* 48Mhz*/ 48 55 49 56 /* SCR register bitmasks */ ··· 59 52 /* FCR register bitmasks */ 60 53 #define OMAP_UART_FCR_RX_FIFO_TRIG_SHIFT 6 61 54 #define OMAP_UART_FCR_RX_FIFO_TRIG_MASK (0x3 << 6) 55 + 56 + /* MVR register bitmasks */ 57 + #define OMAP_UART_MVR_SCHEME_SHIFT 30 58 + 59 + #define OMAP_UART_LEGACY_MVR_MAJ_MASK 0xf0 60 + #define OMAP_UART_LEGACY_MVR_MAJ_SHIFT 4 61 + #define OMAP_UART_LEGACY_MVR_MIN_MASK 0x0f 62 + 63 + #define OMAP_UART_MVR_MAJ_MASK 0x700 64 + #define OMAP_UART_MVR_MAJ_SHIFT 8 65 + #define OMAP_UART_MVR_MIN_MASK 0x3f 62 66 63 67 static struct uart_omap_port *ui[OMAP_MAX_HSUART_PORTS]; 64 68 ··· 1364 1346 return; 1365 1347 } 1366 1348 1349 + static void omap_serial_fill_features_erratas(struct uart_omap_port *up) 1350 + { 1351 + u32 mvr, scheme; 1352 + u16 revision, major, minor; 1353 + 1354 + mvr = serial_in(up, UART_OMAP_MVER); 1355 + 1356 + /* Check revision register scheme */ 1357 + scheme = mvr >> OMAP_UART_MVR_SCHEME_SHIFT; 1358 + 1359 + switch (scheme) { 1360 + case 0: /* Legacy Scheme: OMAP2/3 */ 1361 + /* MINOR_REV[0:4], MAJOR_REV[4:7] */ 1362 + major = (mvr & OMAP_UART_LEGACY_MVR_MAJ_MASK) >> 1363 + OMAP_UART_LEGACY_MVR_MAJ_SHIFT; 1364 + minor = (mvr & OMAP_UART_LEGACY_MVR_MIN_MASK); 1365 + break; 1366 + case 1: 1367 + /* New Scheme: OMAP4+ */ 1368 + /* MINOR_REV[0:5], MAJOR_REV[8:10] */ 1369 + major = (mvr & OMAP_UART_MVR_MAJ_MASK) >> 1370 + OMAP_UART_MVR_MAJ_SHIFT; 1371 + minor = (mvr & OMAP_UART_MVR_MIN_MASK); 1372 + break; 1373 + default: 1374 + dev_warn(&up->pdev->dev, 1375 + "Unknown %s revision, defaulting to highest\n", 1376 + up->name); 1377 + /* highest possible revision */ 1378 + major = 0xff; 1379 + minor = 0xff; 1380 + } 1381 + 1382 + /* normalize revision for the driver */ 1383 + revision = UART_BUILD_REVISION(major, minor); 1384 + 1385 + switch (revision) { 1386 + case OMAP_UART_REV_46: 1387 + up->errata |= (UART_ERRATA_i202_MDR1_ACCESS | 1388 + UART_ERRATA_i291_DMA_FORCEIDLE); 1389 + break; 1390 + case OMAP_UART_REV_52: 1391 + up->errata |= (UART_ERRATA_i202_MDR1_ACCESS | 1392 + UART_ERRATA_i291_DMA_FORCEIDLE); 1393 + break; 1394 + case OMAP_UART_REV_63: 1395 + up->errata |= UART_ERRATA_i202_MDR1_ACCESS; 1396 + break; 1397 + default: 1398 + break; 1399 + } 1400 + } 1401 + 1367 1402 static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev) 1368 1403 { 1369 1404 struct omap_uart_port_info *omap_up_info; ··· 1510 1439 "%d\n", DEFAULT_CLK_SPEED); 1511 1440 } 1512 1441 up->uart_dma.uart_base = mem->start; 1513 - up->errata = omap_up_info->errata; 1514 1442 1515 1443 if (omap_up_info->dma_enabled) { 1516 1444 up->uart_dma.uart_dma_tx = dma_tx->start; ··· 1538 1468 pm_runtime_irq_safe(&pdev->dev); 1539 1469 pm_runtime_enable(&pdev->dev); 1540 1470 pm_runtime_get_sync(&pdev->dev); 1471 + 1472 + omap_serial_fill_features_erratas(up); 1541 1473 1542 1474 ui[up->port.line] = up; 1543 1475 serial_omap_add_console_port(up);
+30 -23
drivers/tty/serial/pch_uart.c
··· 39 39 PCH_UART_HANDLED_RX_ERR_INT_SHIFT, 40 40 PCH_UART_HANDLED_RX_TRG_INT_SHIFT, 41 41 PCH_UART_HANDLED_MS_INT_SHIFT, 42 + PCH_UART_HANDLED_LS_INT_SHIFT, 42 43 }; 43 44 44 45 enum { ··· 63 62 #define PCH_UART_HANDLED_RX_TRG_INT (1<<((\ 64 63 PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1)) 65 64 #define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1)) 65 + 66 + #define PCH_UART_HANDLED_LS_INT (1<<((PCH_UART_HANDLED_LS_INT_SHIFT)<<1)) 66 67 67 68 #define PCH_UART_RBR 0x00 68 69 #define PCH_UART_THR 0x00 ··· 232 229 int start_tx; 233 230 int start_rx; 234 231 int tx_empty; 235 - int int_dis_flag; 236 232 int trigger; 237 233 int trigger_level; 238 234 struct pch_uart_buffer rxbuf; ··· 239 237 unsigned int fcr; 240 238 unsigned int mcr; 241 239 unsigned int use_dma; 242 - unsigned int use_dma_flag; 243 240 struct dma_async_tx_descriptor *desc_tx; 244 241 struct dma_async_tx_descriptor *desc_rx; 245 242 struct pch_dma_slave param_tx; ··· 561 560 return i; 562 561 } 563 562 564 - static unsigned int pch_uart_hal_get_iid(struct eg20t_port *priv) 563 + static unsigned char pch_uart_hal_get_iid(struct eg20t_port *priv) 565 564 { 566 - unsigned int iir; 567 - int ret; 568 - 569 - iir = ioread8(priv->membase + UART_IIR); 570 - ret = (iir & (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP)); 571 - return ret; 565 + return ioread8(priv->membase + UART_IIR) &\ 566 + (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP); 572 567 } 573 568 574 569 static u8 pch_uart_hal_get_line_status(struct eg20t_port *priv) ··· 663 666 dma_release_channel(priv->chan_rx); 664 667 priv->chan_rx = NULL; 665 668 } 666 - if (sg_dma_address(&priv->sg_rx)) 667 - dma_free_coherent(port->dev, port->fifosize, 668 - sg_virt(&priv->sg_rx), 669 - sg_dma_address(&priv->sg_rx)); 669 + 670 + if (priv->rx_buf_dma) { 671 + dma_free_coherent(port->dev, port->fifosize, priv->rx_buf_virt, 672 + priv->rx_buf_dma); 673 + priv->rx_buf_virt = NULL; 674 + priv->rx_buf_dma = 0; 675 + } 670 676 671 677 return; 672 678 } ··· 1053 1053 unsigned int handled; 1054 1054 u8 lsr; 1055 1055 int ret = 0; 1056 - unsigned int iid; 1056 + unsigned char iid; 1057 1057 unsigned long flags; 1058 + int next = 1; 1059 + u8 msr; 1058 1060 1059 1061 spin_lock_irqsave(&priv->port.lock, flags); 1060 1062 handled = 0; 1061 - while ((iid = pch_uart_hal_get_iid(priv)) > 1) { 1063 + while (next) { 1064 + iid = pch_uart_hal_get_iid(priv); 1065 + if (iid & PCH_UART_IIR_IP) /* No Interrupt */ 1066 + break; 1062 1067 switch (iid) { 1063 1068 case PCH_UART_IID_RLS: /* Receiver Line Status */ 1064 1069 lsr = pch_uart_hal_get_line_status(priv); ··· 1071 1066 UART_LSR_PE | UART_LSR_OE)) { 1072 1067 pch_uart_err_ir(priv, lsr); 1073 1068 ret = PCH_UART_HANDLED_RX_ERR_INT; 1069 + } else { 1070 + ret = PCH_UART_HANDLED_LS_INT; 1074 1071 } 1075 1072 break; 1076 1073 case PCH_UART_IID_RDR: /* Received Data Ready */ ··· 1099 1092 ret = handle_tx(priv); 1100 1093 break; 1101 1094 case PCH_UART_IID_MS: /* Modem Status */ 1102 - ret = PCH_UART_HANDLED_MS_INT; 1095 + msr = pch_uart_hal_get_modem(priv); 1096 + next = 0; /* MS ir prioirty is the lowest. So, MS ir 1097 + means final interrupt */ 1098 + if ((msr & UART_MSR_ANY_DELTA) == 0) 1099 + break; 1100 + ret |= PCH_UART_HANDLED_MS_INT; 1103 1101 break; 1104 1102 default: /* Never junp to this label */ 1105 - dev_err(priv->port.dev, "%s:iid=%d (%lu)\n", __func__, 1103 + dev_err(priv->port.dev, "%s:iid=%02x (%lu)\n", __func__, 1106 1104 iid, jiffies); 1107 1105 ret = -1; 1106 + next = 0; 1108 1107 break; 1109 1108 } 1110 1109 handled |= (unsigned int)ret; 1111 - } 1112 - if (handled == 0 && iid <= 1) { 1113 - if (priv->int_dis_flag) 1114 - priv->int_dis_flag = 0; 1115 1110 } 1116 1111 1117 1112 spin_unlock_irqrestore(&priv->port.lock, flags); ··· 1209 1200 priv = container_of(port, struct eg20t_port, port); 1210 1201 priv->start_rx = 0; 1211 1202 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT); 1212 - priv->int_dis_flag = 1; 1213 1203 } 1214 1204 1215 1205 /* Enable the modem status interrupts. */ ··· 1455 1447 __func__); 1456 1448 return -EOPNOTSUPP; 1457 1449 #endif 1458 - priv->use_dma_flag = 1; 1459 1450 dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n"); 1460 1451 if (!priv->use_dma) 1461 1452 pch_request_dma(port);
+65 -20
drivers/tty/tty_buffer.c
··· 185 185 /* Should possibly check if this fails for the largest buffer we 186 186 have queued and recycle that ? */ 187 187 } 188 - 189 188 /** 190 - * tty_buffer_request_room - grow tty buffer if needed 189 + * __tty_buffer_request_room - grow tty buffer if needed 191 190 * @tty: tty structure 192 191 * @size: size desired 193 192 * 194 193 * Make at least size bytes of linear space available for the tty 195 194 * buffer. If we fail return the size we managed to find. 196 - * 197 - * Locking: Takes tty->buf.lock 195 + * Locking: Caller must hold tty->buf.lock 198 196 */ 199 - int tty_buffer_request_room(struct tty_struct *tty, size_t size) 197 + static int __tty_buffer_request_room(struct tty_struct *tty, size_t size) 200 198 { 201 199 struct tty_buffer *b, *n; 202 200 int left; 203 - unsigned long flags; 204 - 205 - spin_lock_irqsave(&tty->buf.lock, flags); 206 - 207 201 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to 208 202 remove this conditional if its worth it. This would be invisible 209 203 to the callers */ ··· 219 225 size = left; 220 226 } 221 227 222 - spin_unlock_irqrestore(&tty->buf.lock, flags); 223 228 return size; 229 + } 230 + 231 + 232 + /** 233 + * tty_buffer_request_room - grow tty buffer if needed 234 + * @tty: tty structure 235 + * @size: size desired 236 + * 237 + * Make at least size bytes of linear space available for the tty 238 + * buffer. If we fail return the size we managed to find. 239 + * 240 + * Locking: Takes tty->buf.lock 241 + */ 242 + int tty_buffer_request_room(struct tty_struct *tty, size_t size) 243 + { 244 + unsigned long flags; 245 + int length; 246 + 247 + spin_lock_irqsave(&tty->buf.lock, flags); 248 + length = __tty_buffer_request_room(tty, size); 249 + spin_unlock_irqrestore(&tty->buf.lock, flags); 250 + return length; 224 251 } 225 252 EXPORT_SYMBOL_GPL(tty_buffer_request_room); 226 253 ··· 264 249 int copied = 0; 265 250 do { 266 251 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); 267 - int space = tty_buffer_request_room(tty, goal); 268 - struct tty_buffer *tb = tty->buf.tail; 252 + int space; 253 + unsigned long flags; 254 + struct tty_buffer *tb; 255 + 256 + spin_lock_irqsave(&tty->buf.lock, flags); 257 + space = __tty_buffer_request_room(tty, goal); 258 + tb = tty->buf.tail; 269 259 /* If there is no space then tb may be NULL */ 270 - if (unlikely(space == 0)) 260 + if (unlikely(space == 0)) { 261 + spin_unlock_irqrestore(&tty->buf.lock, flags); 271 262 break; 263 + } 272 264 memcpy(tb->char_buf_ptr + tb->used, chars, space); 273 265 memset(tb->flag_buf_ptr + tb->used, flag, space); 274 266 tb->used += space; 267 + spin_unlock_irqrestore(&tty->buf.lock, flags); 275 268 copied += space; 276 269 chars += space; 277 270 /* There is a small chance that we need to split the data over ··· 309 286 int copied = 0; 310 287 do { 311 288 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); 312 - int space = tty_buffer_request_room(tty, goal); 313 - struct tty_buffer *tb = tty->buf.tail; 289 + int space; 290 + unsigned long __flags; 291 + struct tty_buffer *tb; 292 + 293 + spin_lock_irqsave(&tty->buf.lock, __flags); 294 + space = __tty_buffer_request_room(tty, goal); 295 + tb = tty->buf.tail; 314 296 /* If there is no space then tb may be NULL */ 315 - if (unlikely(space == 0)) 297 + if (unlikely(space == 0)) { 298 + spin_unlock_irqrestore(&tty->buf.lock, __flags); 316 299 break; 300 + } 317 301 memcpy(tb->char_buf_ptr + tb->used, chars, space); 318 302 memcpy(tb->flag_buf_ptr + tb->used, flags, space); 319 303 tb->used += space; 304 + spin_unlock_irqrestore(&tty->buf.lock, __flags); 320 305 copied += space; 321 306 chars += space; 322 307 flags += space; ··· 375 344 int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, 376 345 size_t size) 377 346 { 378 - int space = tty_buffer_request_room(tty, size); 347 + int space; 348 + unsigned long flags; 349 + struct tty_buffer *tb; 350 + 351 + spin_lock_irqsave(&tty->buf.lock, flags); 352 + space = __tty_buffer_request_room(tty, size); 353 + 354 + tb = tty->buf.tail; 379 355 if (likely(space)) { 380 - struct tty_buffer *tb = tty->buf.tail; 381 356 *chars = tb->char_buf_ptr + tb->used; 382 357 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); 383 358 tb->used += space; 384 359 } 360 + spin_unlock_irqrestore(&tty->buf.lock, flags); 385 361 return space; 386 362 } 387 363 EXPORT_SYMBOL_GPL(tty_prepare_flip_string); ··· 412 374 int tty_prepare_flip_string_flags(struct tty_struct *tty, 413 375 unsigned char **chars, char **flags, size_t size) 414 376 { 415 - int space = tty_buffer_request_room(tty, size); 377 + int space; 378 + unsigned long __flags; 379 + struct tty_buffer *tb; 380 + 381 + spin_lock_irqsave(&tty->buf.lock, __flags); 382 + space = __tty_buffer_request_room(tty, size); 383 + 384 + tb = tty->buf.tail; 416 385 if (likely(space)) { 417 - struct tty_buffer *tb = tty->buf.tail; 418 386 *chars = tb->char_buf_ptr + tb->used; 419 387 *flags = tb->flag_buf_ptr + tb->used; 420 388 tb->used += space; 421 389 } 390 + spin_unlock_irqrestore(&tty->buf.lock, __flags); 422 391 return space; 423 392 } 424 393 EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
+32 -36
drivers/tty/vt/vt.c
··· 3892 3892 vc->vc_sw->con_set_palette(vc, color_table); 3893 3893 } 3894 3894 3895 - static int set_get_cmap(unsigned char __user *arg, int set) 3896 - { 3897 - int i, j, k; 3898 - 3899 - WARN_CONSOLE_UNLOCKED(); 3900 - 3901 - for (i = 0; i < 16; i++) 3902 - if (set) { 3903 - get_user(default_red[i], arg++); 3904 - get_user(default_grn[i], arg++); 3905 - get_user(default_blu[i], arg++); 3906 - } else { 3907 - put_user(default_red[i], arg++); 3908 - put_user(default_grn[i], arg++); 3909 - put_user(default_blu[i], arg++); 3910 - } 3911 - if (set) { 3912 - for (i = 0; i < MAX_NR_CONSOLES; i++) 3913 - if (vc_cons_allocated(i)) { 3914 - for (j = k = 0; j < 16; j++) { 3915 - vc_cons[i].d->vc_palette[k++] = default_red[j]; 3916 - vc_cons[i].d->vc_palette[k++] = default_grn[j]; 3917 - vc_cons[i].d->vc_palette[k++] = default_blu[j]; 3918 - } 3919 - set_palette(vc_cons[i].d); 3920 - } 3921 - } 3922 - return 0; 3923 - } 3924 - 3925 3895 /* 3926 3896 * Load palette into the DAC registers. arg points to a colour 3927 3897 * map, 3 bytes per colour, 16 colours, range from 0 to 255. ··· 3899 3929 3900 3930 int con_set_cmap(unsigned char __user *arg) 3901 3931 { 3902 - int rc; 3932 + int i, j, k; 3933 + unsigned char colormap[3*16]; 3934 + 3935 + if (copy_from_user(colormap, arg, sizeof(colormap))) 3936 + return -EFAULT; 3903 3937 3904 3938 console_lock(); 3905 - rc = set_get_cmap (arg,1); 3939 + for (i = k = 0; i < 16; i++) { 3940 + default_red[i] = colormap[k++]; 3941 + default_grn[i] = colormap[k++]; 3942 + default_blu[i] = colormap[k++]; 3943 + } 3944 + for (i = 0; i < MAX_NR_CONSOLES; i++) { 3945 + if (!vc_cons_allocated(i)) 3946 + continue; 3947 + for (j = k = 0; j < 16; j++) { 3948 + vc_cons[i].d->vc_palette[k++] = default_red[j]; 3949 + vc_cons[i].d->vc_palette[k++] = default_grn[j]; 3950 + vc_cons[i].d->vc_palette[k++] = default_blu[j]; 3951 + } 3952 + set_palette(vc_cons[i].d); 3953 + } 3906 3954 console_unlock(); 3907 3955 3908 - return rc; 3956 + return 0; 3909 3957 } 3910 3958 3911 3959 int con_get_cmap(unsigned char __user *arg) 3912 3960 { 3913 - int rc; 3961 + int i, k; 3962 + unsigned char colormap[3*16]; 3914 3963 3915 3964 console_lock(); 3916 - rc = set_get_cmap (arg,0); 3965 + for (i = k = 0; i < 16; i++) { 3966 + colormap[k++] = default_red[i]; 3967 + colormap[k++] = default_grn[i]; 3968 + colormap[k++] = default_blu[i]; 3969 + } 3917 3970 console_unlock(); 3918 3971 3919 - return rc; 3972 + if (copy_to_user(arg, colormap, sizeof(colormap))) 3973 + return -EFAULT; 3974 + 3975 + return 0; 3920 3976 } 3921 3977 3922 3978 void reset_palette(struct vc_data *vc)
+24 -27
drivers/usb/gadget/u_serial.c
··· 94 94 * (and thus for each /dev/ node). 95 95 */ 96 96 struct gs_port { 97 + struct tty_port port; 97 98 spinlock_t port_lock; /* guard port_* access */ 98 99 99 100 struct gserial *port_usb; 100 - struct tty_struct *port_tty; 101 101 102 - unsigned open_count; 103 102 bool openclose; /* open/close in progress */ 104 103 u8 port_num; 105 - 106 - wait_queue_head_t close_wait; /* wait for last close */ 107 104 108 105 struct list_head read_pool; 109 106 int read_started; ··· 409 412 break; 410 413 } 411 414 412 - if (do_tty_wake && port->port_tty) 413 - tty_wakeup(port->port_tty); 415 + if (do_tty_wake && port->port.tty) 416 + tty_wakeup(port->port.tty); 414 417 return status; 415 418 } 416 419 ··· 432 435 struct tty_struct *tty; 433 436 434 437 /* no more rx if closed */ 435 - tty = port->port_tty; 438 + tty = port->port.tty; 436 439 if (!tty) 437 440 break; 438 441 ··· 485 488 486 489 /* hand any queued data to the tty */ 487 490 spin_lock_irq(&port->port_lock); 488 - tty = port->port_tty; 491 + tty = port->port.tty; 489 492 while (!list_empty(queue)) { 490 493 struct usb_request *req; 491 494 ··· 696 699 697 700 /* unblock any pending writes into our circular buffer */ 698 701 if (started) { 699 - tty_wakeup(port->port_tty); 702 + tty_wakeup(port->port.tty); 700 703 } else { 701 704 gs_free_requests(ep, head, &port->read_allocated); 702 705 gs_free_requests(port->port_usb->in, &port->write_pool, ··· 731 734 spin_lock_irq(&port->port_lock); 732 735 733 736 /* already open? Great. */ 734 - if (port->open_count) { 737 + if (port->port.count) { 735 738 status = 0; 736 - port->open_count++; 739 + port->port.count++; 737 740 738 741 /* currently opening/closing? wait ... */ 739 742 } else if (port->openclose) { ··· 790 793 /* REVISIT maybe wait for "carrier detect" */ 791 794 792 795 tty->driver_data = port; 793 - port->port_tty = tty; 796 + port->port.tty = tty; 794 797 795 - port->open_count = 1; 798 + port->port.count = 1; 796 799 port->openclose = false; 797 800 798 801 /* if connected, start the I/O stream */ ··· 834 837 835 838 spin_lock_irq(&port->port_lock); 836 839 837 - if (port->open_count != 1) { 838 - if (port->open_count == 0) 840 + if (port->port.count != 1) { 841 + if (port->port.count == 0) 839 842 WARN_ON(1); 840 843 else 841 - --port->open_count; 844 + --port->port.count; 842 845 goto exit; 843 846 } 844 847 ··· 848 851 * and sleep if necessary 849 852 */ 850 853 port->openclose = true; 851 - port->open_count = 0; 854 + port->port.count = 0; 852 855 853 856 gser = port->port_usb; 854 857 if (gser && gser->disconnect) ··· 876 879 gs_buf_clear(&port->port_write_buf); 877 880 878 881 tty->driver_data = NULL; 879 - port->port_tty = NULL; 882 + port->port.tty = NULL; 880 883 881 884 port->openclose = false; 882 885 883 886 pr_debug("gs_close: ttyGS%d (%p,%p) done!\n", 884 887 port->port_num, tty, file); 885 888 886 - wake_up_interruptible(&port->close_wait); 889 + wake_up_interruptible(&port->port.close_wait); 887 890 exit: 888 891 spin_unlock_irq(&port->port_lock); 889 892 } ··· 1031 1034 if (port == NULL) 1032 1035 return -ENOMEM; 1033 1036 1037 + tty_port_init(&port->port); 1034 1038 spin_lock_init(&port->port_lock); 1035 - init_waitqueue_head(&port->close_wait); 1036 1039 init_waitqueue_head(&port->drain_wait); 1037 1040 1038 1041 tasklet_init(&port->push, gs_rx_push, (unsigned long) port); ··· 1152 1155 int cond; 1153 1156 1154 1157 spin_lock_irq(&port->port_lock); 1155 - cond = (port->open_count == 0) && !port->openclose; 1158 + cond = (port->port.count == 0) && !port->openclose; 1156 1159 spin_unlock_irq(&port->port_lock); 1157 1160 return cond; 1158 1161 } ··· 1191 1194 tasklet_kill(&port->push); 1192 1195 1193 1196 /* wait for old opens to finish */ 1194 - wait_event(port->close_wait, gs_closed(port)); 1197 + wait_event(port->port.close_wait, gs_closed(port)); 1195 1198 1196 1199 WARN_ON(port->port_usb != NULL); 1197 1200 ··· 1265 1268 /* if it's already open, start I/O ... and notify the serial 1266 1269 * protocol about open/close status (connect/disconnect). 1267 1270 */ 1268 - if (port->open_count) { 1271 + if (port->port.count) { 1269 1272 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num); 1270 1273 gs_start_io(port); 1271 1274 if (gser->connect) ··· 1312 1315 1313 1316 port->port_usb = NULL; 1314 1317 gser->ioport = NULL; 1315 - if (port->open_count > 0 || port->openclose) { 1318 + if (port->port.count > 0 || port->openclose) { 1316 1319 wake_up_interruptible(&port->drain_wait); 1317 - if (port->port_tty) 1318 - tty_hangup(port->port_tty); 1320 + if (port->port.tty) 1321 + tty_hangup(port->port.tty); 1319 1322 } 1320 1323 spin_unlock_irqrestore(&port->port_lock, flags); 1321 1324 ··· 1328 1331 1329 1332 /* finally, free any unused/unusable I/O buffers */ 1330 1333 spin_lock_irqsave(&port->port_lock, flags); 1331 - if (port->open_count == 0 && !port->openclose) 1334 + if (port->port.count == 0 && !port->openclose) 1332 1335 gs_buf_free(&port->port_write_buf); 1333 1336 gs_free_requests(gser->out, &port->read_pool, NULL); 1334 1337 gs_free_requests(gser->out, &port->read_queue, NULL);
+2 -62
include/linux/generic_serial.h
··· 4 4 * Copyright (C) 1998 R.E.Wolff@BitWizard.nl 5 5 * 6 6 * written for the SX serial driver. 7 - * Contains the code that should be shared over all the serial drivers. 8 7 * 9 8 * Version 0.1 -- December, 1998. 10 9 */ ··· 11 12 #ifndef GENERIC_SERIAL_H 12 13 #define GENERIC_SERIAL_H 13 14 14 - #ifdef __KERNEL__ 15 - #include <linux/mutex.h> 16 - #include <linux/tty.h> 17 - 18 - struct real_driver { 19 - void (*disable_tx_interrupts) (void *); 20 - void (*enable_tx_interrupts) (void *); 21 - void (*disable_rx_interrupts) (void *); 22 - void (*enable_rx_interrupts) (void *); 23 - void (*shutdown_port) (void*); 24 - int (*set_real_termios) (void*); 25 - int (*chars_in_buffer) (void*); 26 - void (*close) (void*); 27 - void (*hungup) (void*); 28 - void (*getserial) (void*, struct serial_struct *sp); 29 - }; 30 - 31 - 32 - 33 - struct gs_port { 34 - int magic; 35 - struct tty_port port; 36 - unsigned char *xmit_buf; 37 - int xmit_head; 38 - int xmit_tail; 39 - int xmit_cnt; 40 - struct mutex port_write_mutex; 41 - unsigned long event; 42 - unsigned short closing_wait; 43 - int close_delay; 44 - struct real_driver *rd; 45 - int wakeup_chars; 46 - int baud_base; 47 - int baud; 48 - int custom_divisor; 49 - spinlock_t driver_lock; 50 - }; 51 - 52 - #endif /* __KERNEL__ */ 15 + #warning Use of this header is deprecated. 16 + #warning Since nobody sets the constants defined here for you, you should not, in any case, use them. Including the header is thus pointless. 53 17 54 18 /* Flags */ 55 19 /* Warning: serial.h defines some ASYNC_ flags, they say they are "only" ··· 21 59 #define GS_TX_INTEN 0x00800000 22 60 #define GS_RX_INTEN 0x00400000 23 61 #define GS_ACTIVE 0x00200000 24 - 25 - 26 62 27 63 #define GS_TYPE_NORMAL 1 28 64 ··· 32 72 #define GS_DEBUG_FLOW 0x00000020 33 73 #define GS_DEBUG_WRITE 0x00000040 34 74 35 - #ifdef __KERNEL__ 36 - int gs_put_char(struct tty_struct *tty, unsigned char ch); 37 - int gs_write(struct tty_struct *tty, 38 - const unsigned char *buf, int count); 39 - int gs_write_room(struct tty_struct *tty); 40 - int gs_chars_in_buffer(struct tty_struct *tty); 41 - void gs_flush_buffer(struct tty_struct *tty); 42 - void gs_flush_chars(struct tty_struct *tty); 43 - void gs_stop(struct tty_struct *tty); 44 - void gs_start(struct tty_struct *tty); 45 - void gs_hangup(struct tty_struct *tty); 46 - int gs_block_til_ready(void *port, struct file *filp); 47 - void gs_close(struct tty_struct *tty, struct file *filp); 48 - void gs_set_termios (struct tty_struct * tty, 49 - struct ktermios * old_termios); 50 - int gs_init_port(struct gs_port *port); 51 - int gs_setserial(struct gs_port *port, struct serial_struct __user *sp); 52 - int gs_getserial(struct gs_port *port, struct serial_struct __user *sp); 53 - void gs_got_break(struct gs_port *port); 54 - #endif /* __KERNEL__ */ 55 75 #endif
+2 -24
include/linux/isdn.h
··· 15 15 #define __ISDN_H__ 16 16 17 17 #include <linux/ioctl.h> 18 + #include <linux/tty.h> 18 19 19 20 #define ISDN_MAX_DRIVERS 32 20 21 #define ISDN_MAX_CHANNELS 64 ··· 393 392 /*======================= Start of ISDN-tty stuff ===========================*/ 394 393 395 394 #define ISDN_ASYNC_MAGIC 0x49344C01 /* for paranoia-checking */ 396 - #define ISDN_ASYNC_INITIALIZED 0x80000000 /* port was initialized */ 397 - #define ISDN_ASYNC_CALLOUT_ACTIVE 0x40000000 /* Call out device active */ 398 - #define ISDN_ASYNC_NORMAL_ACTIVE 0x20000000 /* Normal device active */ 399 - #define ISDN_ASYNC_CLOSING 0x08000000 /* Serial port is closing */ 400 - #define ISDN_ASYNC_CTS_FLOW 0x04000000 /* Do CTS flow control */ 401 - #define ISDN_ASYNC_CHECK_CD 0x02000000 /* i.e., CLOCAL */ 402 - #define ISDN_ASYNC_HUP_NOTIFY 0x0001 /* Notify tty on hangups/closes */ 403 - #define ISDN_ASYNC_SESSION_LOCKOUT 0x0100 /* Lock cua opens on session */ 404 - #define ISDN_ASYNC_PGRP_LOCKOUT 0x0200 /* Lock cua opens on pgrp */ 405 - #define ISDN_ASYNC_CALLOUT_NOHUP 0x0400 /* No hangup for cui */ 406 - #define ISDN_ASYNC_SPLIT_TERMIOS 0x0008 /* Sep. termios for dialin/out */ 407 395 #define ISDN_SERIAL_XMIT_SIZE 1024 /* Default bufsize for write */ 408 396 #define ISDN_SERIAL_XMIT_MAX 4000 /* Maximum bufsize for write */ 409 - #define ISDN_SERIAL_TYPE_NORMAL 1 410 - #define ISDN_SERIAL_TYPE_CALLOUT 2 411 397 412 398 #ifdef CONFIG_ISDN_AUDIO 413 399 /* For using sk_buffs with audio we need some private variables ··· 436 448 /* Private data (similar to async_struct in <linux/serial.h>) */ 437 449 typedef struct modem_info { 438 450 int magic; 439 - struct module *owner; 440 - int flags; /* defined in tty.h */ 451 + struct tty_port port; 441 452 int x_char; /* xon/xoff character */ 442 453 int mcr; /* Modem control register */ 443 454 int msr; /* Modem status register */ 444 455 int lsr; /* Line status register */ 445 456 int line; 446 - int count; /* # of fd on device */ 447 - int blocked_open; /* # of blocked opens */ 448 - long session; /* Session of opening process */ 449 - long pgrp; /* pgrp of opening process */ 450 457 int online; /* 1 = B-Channel is up, drop data */ 451 458 /* 2 = B-Channel is up, deliver d.*/ 452 459 int dialing; /* Dial in progress or ATA */ ··· 461 478 int send_outstanding;/* # of outstanding send-requests */ 462 479 int xmit_size; /* max. # of chars in xmit_buf */ 463 480 int xmit_count; /* # of chars in xmit_buf */ 464 - unsigned char *xmit_buf; /* transmit buffer */ 465 481 struct sk_buff_head xmit_queue; /* transmit queue */ 466 482 atomic_t xmit_lock; /* Semaphore for isdn_tty_write */ 467 483 #ifdef CONFIG_ISDN_AUDIO ··· 478 496 struct T30_s *fax; /* T30 Fax Group 3 data/interface */ 479 497 int faxonline; /* Fax-channel status */ 480 498 #endif 481 - struct tty_struct *tty; /* Pointer to corresponding tty */ 482 499 atemu emu; /* AT-emulator data */ 483 - struct ktermios normal_termios; /* For saving termios structs */ 484 - struct ktermios callout_termios; 485 - wait_queue_head_t open_wait, close_wait; 486 500 spinlock_t readlock; 487 501 } modem_info; 488 502
+17
include/linux/of_serial.h
··· 1 + #ifndef __LINUX_OF_SERIAL_H 2 + #define __LINUX_OF_SERIAL_H 3 + 4 + /* 5 + * FIXME remove this file when tegra finishes conversion to open firmware, 6 + * expectation is that all quirks will then be self-contained in 7 + * drivers/tty/serial/of_serial.c. 8 + */ 9 + #ifdef CONFIG_ARCH_TEGRA 10 + extern void tegra_serial_handle_break(struct uart_port *port); 11 + #else 12 + static inline void tegra_serial_handle_break(struct uart_port *port) 13 + { 14 + } 15 + #endif 16 + 17 + #endif /* __LINUX_OF_SERIAL */
+1
include/linux/serial_8250.h
··· 38 38 int (*handle_irq)(struct uart_port *); 39 39 void (*pm)(struct uart_port *, unsigned int state, 40 40 unsigned old); 41 + void (*handle_break)(struct uart_port *); 41 42 }; 42 43 43 44 /*
+5
include/linux/serial_core.h
··· 310 310 int (*handle_irq)(struct uart_port *); 311 311 void (*pm)(struct uart_port *, unsigned int state, 312 312 unsigned int old); 313 + void (*handle_break)(struct uart_port *); 313 314 unsigned int irq; /* irq number */ 314 315 unsigned long irqflags; /* irq flags */ 315 316 unsigned int uartclk; /* base uart clock */ ··· 534 533 static inline int uart_handle_break(struct uart_port *port) 535 534 { 536 535 struct uart_state *state = port->state; 536 + 537 + if (port->handle_break) 538 + port->handle_break(port); 539 + 537 540 #ifdef SUPPORT_SYSRQ 538 541 if (port->cons && port->cons->index == port->line) { 539 542 if (!port->sysrq) {
+62 -71
net/bluetooth/rfcomm/tty.c
··· 48 48 static struct tty_driver *rfcomm_tty_driver; 49 49 50 50 struct rfcomm_dev { 51 + struct tty_port port; 51 52 struct list_head list; 52 - atomic_t refcnt; 53 53 54 54 char name[12]; 55 55 int id; 56 56 unsigned long flags; 57 - atomic_t opened; 58 57 int err; 59 58 60 59 bdaddr_t src; ··· 63 64 uint modem_status; 64 65 65 66 struct rfcomm_dlc *dlc; 66 - struct tty_struct *tty; 67 67 wait_queue_head_t wait; 68 - struct work_struct wakeup_task; 69 68 70 69 struct device *tty_dev; 71 70 ··· 79 82 static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err); 80 83 static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig); 81 84 82 - static void rfcomm_tty_wakeup(struct work_struct *work); 83 - 84 85 /* ---- Device functions ---- */ 85 - static void rfcomm_dev_destruct(struct rfcomm_dev *dev) 86 + 87 + /* 88 + * The reason this isn't actually a race, as you no doubt have a little voice 89 + * screaming at you in your head, is that the refcount should never actually 90 + * reach zero unless the device has already been taken off the list, in 91 + * rfcomm_dev_del(). And if that's not true, we'll hit the BUG() in 92 + * rfcomm_dev_destruct() anyway. 93 + */ 94 + static void rfcomm_dev_destruct(struct tty_port *port) 86 95 { 96 + struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port); 87 97 struct rfcomm_dlc *dlc = dev->dlc; 88 98 89 99 BT_DBG("dev %p dlc %p", dev, dlc); ··· 117 113 module_put(THIS_MODULE); 118 114 } 119 115 120 - static inline void rfcomm_dev_hold(struct rfcomm_dev *dev) 121 - { 122 - atomic_inc(&dev->refcnt); 123 - } 124 - 125 - static inline void rfcomm_dev_put(struct rfcomm_dev *dev) 126 - { 127 - /* The reason this isn't actually a race, as you no 128 - doubt have a little voice screaming at you in your 129 - head, is that the refcount should never actually 130 - reach zero unless the device has already been taken 131 - off the list, in rfcomm_dev_del(). And if that's not 132 - true, we'll hit the BUG() in rfcomm_dev_destruct() 133 - anyway. */ 134 - if (atomic_dec_and_test(&dev->refcnt)) 135 - rfcomm_dev_destruct(dev); 136 - } 116 + static const struct tty_port_operations rfcomm_port_ops = { 117 + .destruct = rfcomm_dev_destruct, 118 + }; 137 119 138 120 static struct rfcomm_dev *__rfcomm_dev_get(int id) 139 121 { ··· 144 154 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) 145 155 dev = NULL; 146 156 else 147 - rfcomm_dev_hold(dev); 157 + tty_port_get(&dev->port); 148 158 } 149 159 150 160 spin_unlock(&rfcomm_dev_lock); ··· 231 241 sprintf(dev->name, "rfcomm%d", dev->id); 232 242 233 243 list_add(&dev->list, head); 234 - atomic_set(&dev->refcnt, 1); 235 244 236 245 bacpy(&dev->src, &req->src); 237 246 bacpy(&dev->dst, &req->dst); ··· 239 250 dev->flags = req->flags & 240 251 ((1 << RFCOMM_RELEASE_ONHUP) | (1 << RFCOMM_REUSE_DLC)); 241 252 242 - atomic_set(&dev->opened, 0); 243 - 253 + tty_port_init(&dev->port); 254 + dev->port.ops = &rfcomm_port_ops; 244 255 init_waitqueue_head(&dev->wait); 245 - INIT_WORK(&dev->wakeup_task, rfcomm_tty_wakeup); 246 256 247 257 skb_queue_head_init(&dev->pending); 248 258 ··· 308 320 309 321 static void rfcomm_dev_del(struct rfcomm_dev *dev) 310 322 { 323 + unsigned long flags; 311 324 BT_DBG("dev %p", dev); 312 325 313 326 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags)); 314 327 315 - if (atomic_read(&dev->opened) > 0) 328 + spin_lock_irqsave(&dev->port.lock, flags); 329 + if (dev->port.count > 0) { 330 + spin_unlock_irqrestore(&dev->port.lock, flags); 316 331 return; 332 + } 333 + spin_unlock_irqrestore(&dev->port.lock, flags); 317 334 318 335 spin_lock(&rfcomm_dev_lock); 319 336 list_del_init(&dev->list); 320 337 spin_unlock(&rfcomm_dev_lock); 321 338 322 - rfcomm_dev_put(dev); 339 + tty_port_put(&dev->port); 323 340 } 324 341 325 342 /* ---- Send buffer ---- */ ··· 338 345 static void rfcomm_wfree(struct sk_buff *skb) 339 346 { 340 347 struct rfcomm_dev *dev = (void *) skb->sk; 348 + struct tty_struct *tty = dev->port.tty; 341 349 atomic_sub(skb->truesize, &dev->wmem_alloc); 342 - if (test_bit(RFCOMM_TTY_ATTACHED, &dev->flags)) 343 - queue_work(system_nrt_wq, &dev->wakeup_task); 344 - rfcomm_dev_put(dev); 350 + if (test_bit(RFCOMM_TTY_ATTACHED, &dev->flags) && tty) 351 + tty_wakeup(tty); 352 + tty_port_put(&dev->port); 345 353 } 346 354 347 355 static inline void rfcomm_set_owner_w(struct sk_buff *skb, struct rfcomm_dev *dev) 348 356 { 349 - rfcomm_dev_hold(dev); 357 + tty_port_get(&dev->port); 350 358 atomic_add(skb->truesize, &dev->wmem_alloc); 351 359 skb->sk = (void *) dev; 352 360 skb->destructor = rfcomm_wfree; ··· 426 432 return -ENODEV; 427 433 428 434 if (dev->flags != NOCAP_FLAGS && !capable(CAP_NET_ADMIN)) { 429 - rfcomm_dev_put(dev); 435 + tty_port_put(&dev->port); 430 436 return -EPERM; 431 437 } 432 438 ··· 434 440 rfcomm_dlc_close(dev->dlc, 0); 435 441 436 442 /* Shut down TTY synchronously before freeing rfcomm_dev */ 437 - if (dev->tty) 438 - tty_vhangup(dev->tty); 443 + if (dev->port.tty) 444 + tty_vhangup(dev->port.tty); 439 445 440 446 if (!test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) 441 447 rfcomm_dev_del(dev); 442 - rfcomm_dev_put(dev); 448 + tty_port_put(&dev->port); 443 449 return 0; 444 450 } 445 451 ··· 517 523 if (copy_to_user(arg, &di, sizeof(di))) 518 524 err = -EFAULT; 519 525 520 - rfcomm_dev_put(dev); 526 + tty_port_put(&dev->port); 521 527 return err; 522 528 } 523 529 ··· 553 559 return; 554 560 } 555 561 556 - tty = dev->tty; 562 + tty = dev->port.tty; 557 563 if (!tty || !skb_queue_empty(&dev->pending)) { 558 564 skb_queue_tail(&dev->pending, skb); 559 565 return; ··· 579 585 wake_up_interruptible(&dev->wait); 580 586 581 587 if (dlc->state == BT_CLOSED) { 582 - if (!dev->tty) { 588 + if (!dev->port.tty) { 583 589 if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) { 584 590 /* Drop DLC lock here to avoid deadlock 585 591 * 1. rfcomm_dev_get will take rfcomm_dev_lock 586 592 * but in rfcomm_dev_add there's lock order: 587 593 * rfcomm_dev_lock -> dlc lock 588 - * 2. rfcomm_dev_put will deadlock if it's 594 + * 2. tty_port_put will deadlock if it's 589 595 * the last reference 590 596 */ 591 597 rfcomm_dlc_unlock(dlc); ··· 595 601 } 596 602 597 603 rfcomm_dev_del(dev); 598 - rfcomm_dev_put(dev); 604 + tty_port_put(&dev->port); 599 605 rfcomm_dlc_lock(dlc); 600 606 } 601 607 } else 602 - tty_hangup(dev->tty); 608 + tty_hangup(dev->port.tty); 603 609 } 604 610 } 605 611 ··· 612 618 BT_DBG("dlc %p dev %p v24_sig 0x%02x", dlc, dev, v24_sig); 613 619 614 620 if ((dev->modem_status & TIOCM_CD) && !(v24_sig & RFCOMM_V24_DV)) { 615 - if (dev->tty && !C_CLOCAL(dev->tty)) 616 - tty_hangup(dev->tty); 621 + if (dev->port.tty && !C_CLOCAL(dev->port.tty)) 622 + tty_hangup(dev->port.tty); 617 623 } 618 624 619 625 dev->modem_status = ··· 624 630 } 625 631 626 632 /* ---- TTY functions ---- */ 627 - static void rfcomm_tty_wakeup(struct work_struct *work) 628 - { 629 - struct rfcomm_dev *dev = container_of(work, struct rfcomm_dev, 630 - wakeup_task); 631 - struct tty_struct *tty = dev->tty; 632 - if (!tty) 633 - return; 634 - 635 - BT_DBG("dev %p tty %p", dev, tty); 636 - tty_wakeup(tty); 637 - } 638 - 639 633 static void rfcomm_tty_copy_pending(struct rfcomm_dev *dev) 640 634 { 641 - struct tty_struct *tty = dev->tty; 635 + struct tty_struct *tty = dev->port.tty; 642 636 struct sk_buff *skb; 643 637 int inserted = 0; 644 638 ··· 653 671 DECLARE_WAITQUEUE(wait, current); 654 672 struct rfcomm_dev *dev; 655 673 struct rfcomm_dlc *dlc; 674 + unsigned long flags; 656 675 int err, id; 657 676 658 677 id = tty->index; ··· 669 686 return -ENODEV; 670 687 671 688 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst), 672 - dev->channel, atomic_read(&dev->opened)); 689 + dev->channel, dev->port.count); 673 690 674 - if (atomic_inc_return(&dev->opened) > 1) 691 + spin_lock_irqsave(&dev->port.lock, flags); 692 + if (++dev->port.count > 1) { 693 + spin_unlock_irqrestore(&dev->port.lock, flags); 675 694 return 0; 695 + } 696 + spin_unlock_irqrestore(&dev->port.lock, flags); 676 697 677 698 dlc = dev->dlc; 678 699 ··· 684 697 685 698 rfcomm_dlc_lock(dlc); 686 699 tty->driver_data = dev; 687 - dev->tty = tty; 700 + dev->port.tty = tty; 688 701 rfcomm_dlc_unlock(dlc); 689 702 set_bit(RFCOMM_TTY_ATTACHED, &dev->flags); 690 703 ··· 731 744 static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp) 732 745 { 733 746 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data; 747 + unsigned long flags; 748 + 734 749 if (!dev) 735 750 return; 736 751 737 752 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc, 738 - atomic_read(&dev->opened)); 753 + dev->port.count); 739 754 740 - if (atomic_dec_and_test(&dev->opened)) { 755 + spin_lock_irqsave(&dev->port.lock, flags); 756 + if (!--dev->port.count) { 757 + spin_unlock_irqrestore(&dev->port.lock, flags); 741 758 if (dev->tty_dev->parent) 742 759 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST); 743 760 ··· 749 758 rfcomm_dlc_close(dev->dlc, 0); 750 759 751 760 clear_bit(RFCOMM_TTY_ATTACHED, &dev->flags); 752 - cancel_work_sync(&dev->wakeup_task); 753 761 754 762 rfcomm_dlc_lock(dev->dlc); 755 763 tty->driver_data = NULL; 756 - dev->tty = NULL; 764 + dev->port.tty = NULL; 757 765 rfcomm_dlc_unlock(dev->dlc); 758 766 759 767 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) { ··· 760 770 list_del_init(&dev->list); 761 771 spin_unlock(&rfcomm_dev_lock); 762 772 763 - rfcomm_dev_put(dev); 773 + tty_port_put(&dev->port); 764 774 } 765 - } 775 + } else 776 + spin_unlock_irqrestore(&dev->port.lock, flags); 766 777 767 - rfcomm_dev_put(dev); 778 + tty_port_put(&dev->port); 768 779 } 769 780 770 781 static int rfcomm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) ··· 1074 1083 if (rfcomm_dev_get(dev->id) == NULL) 1075 1084 return; 1076 1085 rfcomm_dev_del(dev); 1077 - rfcomm_dev_put(dev); 1086 + tty_port_put(&dev->port); 1078 1087 } 1079 1088 } 1080 1089