aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/tty/serial/nxp-lpc32xx-hsuart.txt14
-rw-r--r--Documentation/devicetree/bindings/tty/serial/of-serial.txt1
-rw-r--r--arch/um/drivers/chan_kern.c4
-rw-r--r--arch/um/drivers/line.c32
-rw-r--r--arch/um/drivers/line.h3
-rw-r--r--drivers/tty/amiserial.c14
-rw-r--r--drivers/tty/cyclades.c65
-rw-r--r--drivers/tty/n_r3964.c10
-rw-r--r--drivers/tty/n_tty.c6
-rw-r--r--drivers/tty/pty.c164
-rw-r--r--drivers/tty/serial/8250/8250.c88
-rw-r--r--drivers/tty/serial/8250/8250.h1
-rw-r--r--drivers/tty/serial/8250/8250_acorn.c22
-rw-r--r--drivers/tty/serial/8250/8250_dw.c38
-rw-r--r--drivers/tty/serial/8250/8250_gsc.c26
-rw-r--r--drivers/tty/serial/8250/8250_hp300.c26
-rw-r--r--drivers/tty/serial/8250/8250_pci.c126
-rw-r--r--drivers/tty/serial/8250/8250_pnp.c28
-rw-r--r--drivers/tty/serial/8250/serial_cs.c30
-rw-r--r--drivers/tty/serial/Kconfig19
-rw-r--r--drivers/tty/serial/Makefile1
-rw-r--r--drivers/tty/serial/amba-pl011.c34
-rw-r--r--drivers/tty/serial/crisv10.c8
-rw-r--r--drivers/tty/serial/imx.c2
-rw-r--r--drivers/tty/serial/lpc32xx_hs.c823
-rw-r--r--drivers/tty/serial/of_serial.c1
-rw-r--r--drivers/tty/serial/pch_uart.c38
-rw-r--r--drivers/tty/serial/pxa.c14
-rw-r--r--drivers/tty/serial/samsung.c28
-rw-r--r--drivers/tty/serial/serial_core.c6
-rw-r--r--drivers/tty/synclink.c4
-rw-r--r--drivers/tty/synclink_gt.c4
-rw-r--r--drivers/tty/synclinkmp.c4
-rw-r--r--drivers/tty/tty_io.c101
-rw-r--r--drivers/tty/tty_ldisc.c69
-rw-r--r--drivers/tty/tty_mutex.c71
-rw-r--r--drivers/tty/tty_port.c23
-rw-r--r--drivers/tty/vt/keyboard.c9
-rw-r--r--drivers/tty/vt/vt.c62
-rw-r--r--drivers/tty/vt/vt_ioctl.c47
-rw-r--r--drivers/usb/serial/metro-usb.c8
-rw-r--r--drivers/usb/serial/usb-serial.c2
-rw-r--r--include/linux/Kbuild3
-rw-r--r--include/linux/cd1400.h292
-rw-r--r--include/linux/cdk.h486
-rw-r--r--include/linux/comstats.h119
-rw-r--r--include/linux/generic_serial.h35
-rw-r--r--include/linux/istallion.h123
-rw-r--r--include/linux/kbd_kern.h12
-rw-r--r--include/linux/sc26198.h533
-rw-r--r--include/linux/serial167.h157
-rw-r--r--include/linux/serial_8250.h1
-rw-r--r--include/linux/serial_core.h3
-rw-r--r--include/linux/stallion.h147
-rw-r--r--include/linux/tty.h28
-rw-r--r--include/linux/tty_driver.h1
-rw-r--r--include/net/irda/ircomm_tty.h17
-rw-r--r--net/bluetooth/rfcomm/tty.c4
-rw-r--r--net/irda/ircomm/ircomm_param.c5
-rw-r--r--net/irda/ircomm/ircomm_tty.c271
-rw-r--r--net/irda/ircomm/ircomm_tty_attach.c40
-rw-r--r--net/irda/ircomm/ircomm_tty_ioctl.c25
62 files changed, 1742 insertions, 2636 deletions
diff --git a/Documentation/devicetree/bindings/tty/serial/nxp-lpc32xx-hsuart.txt b/Documentation/devicetree/bindings/tty/serial/nxp-lpc32xx-hsuart.txt
new file mode 100644
index 000000000000..0d439dfc1aa5
--- /dev/null
+++ b/Documentation/devicetree/bindings/tty/serial/nxp-lpc32xx-hsuart.txt
@@ -0,0 +1,14 @@
1* NXP LPC32xx SoC High Speed UART
2
3Required properties:
4- compatible: Should be "nxp,lpc3220-hsuart"
5- reg: Should contain registers location and length
6- interrupts: Should contain interrupt
7
8Example:
9
10 uart1: serial@40014000 {
11 compatible = "nxp,lpc3220-hsuart";
12 reg = <0x40014000 0x1000>;
13 interrupts = <26 0>;
14 };
diff --git a/Documentation/devicetree/bindings/tty/serial/of-serial.txt b/Documentation/devicetree/bindings/tty/serial/of-serial.txt
index b8b27b0aca10..0847fdeee11a 100644
--- a/Documentation/devicetree/bindings/tty/serial/of-serial.txt
+++ b/Documentation/devicetree/bindings/tty/serial/of-serial.txt
@@ -9,6 +9,7 @@ Required properties:
9 - "ns16750" 9 - "ns16750"
10 - "ns16850" 10 - "ns16850"
11 - "nvidia,tegra20-uart" 11 - "nvidia,tegra20-uart"
12 - "nxp,lpc3220-uart"
12 - "ibm,qpace-nwp-serial" 13 - "ibm,qpace-nwp-serial"
13 - "serial" if the port type is unknown. 14 - "serial" if the port type is unknown.
14- reg : offset and length of the register set for the device. 15- reg : offset and length of the register set for the device.
diff --git a/arch/um/drivers/chan_kern.c b/arch/um/drivers/chan_kern.c
index 45e248c2f43c..87eebfe03c61 100644
--- a/arch/um/drivers/chan_kern.c
+++ b/arch/um/drivers/chan_kern.c
@@ -150,9 +150,11 @@ void chan_enable_winch(struct chan *chan, struct tty_struct *tty)
150static void line_timer_cb(struct work_struct *work) 150static void line_timer_cb(struct work_struct *work)
151{ 151{
152 struct line *line = container_of(work, struct line, task.work); 152 struct line *line = container_of(work, struct line, task.work);
153 struct tty_struct *tty = tty_port_tty_get(&line->port);
153 154
154 if (!line->throttled) 155 if (!line->throttled)
155 chan_interrupt(line, line->tty, line->driver->read_irq); 156 chan_interrupt(line, tty, line->driver->read_irq);
157 tty_kref_put(tty);
156} 158}
157 159
158int enable_chan(struct line *line) 160int enable_chan(struct line *line)
diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index acfd0e0fd0c9..fb6e4ea09921 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -19,9 +19,11 @@ static irqreturn_t line_interrupt(int irq, void *data)
19{ 19{
20 struct chan *chan = data; 20 struct chan *chan = data;
21 struct line *line = chan->line; 21 struct line *line = chan->line;
22 struct tty_struct *tty = tty_port_tty_get(&line->port);
22 23
23 if (line) 24 if (line)
24 chan_interrupt(line, line->tty, irq); 25 chan_interrupt(line, tty, irq);
26 tty_kref_put(tty);
25 return IRQ_HANDLED; 27 return IRQ_HANDLED;
26} 28}
27 29
@@ -333,7 +335,7 @@ static irqreturn_t line_write_interrupt(int irq, void *data)
333{ 335{
334 struct chan *chan = data; 336 struct chan *chan = data;
335 struct line *line = chan->line; 337 struct line *line = chan->line;
336 struct tty_struct *tty = line->tty; 338 struct tty_struct *tty;
337 int err; 339 int err;
338 340
339 /* 341 /*
@@ -352,10 +354,13 @@ static irqreturn_t line_write_interrupt(int irq, void *data)
352 } 354 }
353 spin_unlock(&line->lock); 355 spin_unlock(&line->lock);
354 356
357 tty = tty_port_tty_get(&line->port);
355 if (tty == NULL) 358 if (tty == NULL)
356 return IRQ_NONE; 359 return IRQ_NONE;
357 360
358 tty_wakeup(tty); 361 tty_wakeup(tty);
362 tty_kref_put(tty);
363
359 return IRQ_HANDLED; 364 return IRQ_HANDLED;
360} 365}
361 366
@@ -404,12 +409,12 @@ int line_open(struct line *lines, struct tty_struct *tty)
404 goto out_unlock; 409 goto out_unlock;
405 410
406 err = 0; 411 err = 0;
407 if (line->count++) 412 if (line->port.count++)
408 goto out_unlock; 413 goto out_unlock;
409 414
410 BUG_ON(tty->driver_data); 415 BUG_ON(tty->driver_data);
411 tty->driver_data = line; 416 tty->driver_data = line;
412 line->tty = tty; 417 tty_port_tty_set(&line->port, tty);
413 418
414 err = enable_chan(line); 419 err = enable_chan(line);
415 if (err) /* line_close() will be called by our caller */ 420 if (err) /* line_close() will be called by our caller */
@@ -446,10 +451,10 @@ void line_close(struct tty_struct *tty, struct file * filp)
446 mutex_lock(&line->count_lock); 451 mutex_lock(&line->count_lock);
447 BUG_ON(!line->valid); 452 BUG_ON(!line->valid);
448 453
449 if (--line->count) 454 if (--line->port.count)
450 goto out_unlock; 455 goto out_unlock;
451 456
452 line->tty = NULL; 457 tty_port_tty_set(&line->port, NULL);
453 tty->driver_data = NULL; 458 tty->driver_data = NULL;
454 459
455 if (line->sigio) { 460 if (line->sigio) {
@@ -478,7 +483,7 @@ int setup_one_line(struct line *lines, int n, char *init,
478 483
479 mutex_lock(&line->count_lock); 484 mutex_lock(&line->count_lock);
480 485
481 if (line->count) { 486 if (line->port.count) {
482 *error_out = "Device is already open"; 487 *error_out = "Device is already open";
483 goto out; 488 goto out;
484 } 489 }
@@ -610,9 +615,15 @@ int line_get_config(char *name, struct line *lines, unsigned int num, char *str,
610 mutex_lock(&line->count_lock); 615 mutex_lock(&line->count_lock);
611 if (!line->valid) 616 if (!line->valid)
612 CONFIG_CHUNK(str, size, n, "none", 1); 617 CONFIG_CHUNK(str, size, n, "none", 1);
613 else if (line->tty == NULL) 618 else {
614 CONFIG_CHUNK(str, size, n, line->init_str, 1); 619 struct tty_struct *tty = tty_port_tty_get(&line->port);
615 else n = chan_config_string(line, str, size, error_out); 620 if (tty == NULL) {
621 CONFIG_CHUNK(str, size, n, line->init_str, 1);
622 } else {
623 n = chan_config_string(line, str, size, error_out);
624 tty_kref_put(tty);
625 }
626 }
616 mutex_unlock(&line->count_lock); 627 mutex_unlock(&line->count_lock);
617 628
618 return n; 629 return n;
@@ -663,6 +674,7 @@ int register_lines(struct line_driver *line_driver,
663 driver->init_termios = tty_std_termios; 674 driver->init_termios = tty_std_termios;
664 675
665 for (i = 0; i < nlines; i++) { 676 for (i = 0; i < nlines; i++) {
677 tty_port_init(&lines[i].port);
666 spin_lock_init(&lines[i].lock); 678 spin_lock_init(&lines[i].lock);
667 mutex_init(&lines[i].count_lock); 679 mutex_init(&lines[i].count_lock);
668 lines[i].driver = line_driver; 680 lines[i].driver = line_driver;
diff --git a/arch/um/drivers/line.h b/arch/um/drivers/line.h
index 0a1834719dba..5b3d4fbdec18 100644
--- a/arch/um/drivers/line.h
+++ b/arch/um/drivers/line.h
@@ -32,9 +32,8 @@ struct line_driver {
32}; 32};
33 33
34struct line { 34struct line {
35 struct tty_struct *tty; 35 struct tty_port port;
36 struct mutex count_lock; 36 struct mutex count_lock;
37 unsigned long count;
38 int valid; 37 int valid;
39 38
40 char *init_str; 39 char *init_str;
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 6cc4358f68c1..35819e312624 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -1033,7 +1033,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_state *state,
1033 if (!retinfo) 1033 if (!retinfo)
1034 return -EFAULT; 1034 return -EFAULT;
1035 memset(&tmp, 0, sizeof(tmp)); 1035 memset(&tmp, 0, sizeof(tmp));
1036 tty_lock(); 1036 tty_lock(tty);
1037 tmp.line = tty->index; 1037 tmp.line = tty->index;
1038 tmp.port = state->port; 1038 tmp.port = state->port;
1039 tmp.flags = state->tport.flags; 1039 tmp.flags = state->tport.flags;
@@ -1042,7 +1042,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_state *state,
1042 tmp.close_delay = state->tport.close_delay; 1042 tmp.close_delay = state->tport.close_delay;
1043 tmp.closing_wait = state->tport.closing_wait; 1043 tmp.closing_wait = state->tport.closing_wait;
1044 tmp.custom_divisor = state->custom_divisor; 1044 tmp.custom_divisor = state->custom_divisor;
1045 tty_unlock(); 1045 tty_unlock(tty);
1046 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) 1046 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
1047 return -EFAULT; 1047 return -EFAULT;
1048 return 0; 1048 return 0;
@@ -1059,12 +1059,12 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
1059 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 1059 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1060 return -EFAULT; 1060 return -EFAULT;
1061 1061
1062 tty_lock(); 1062 tty_lock(tty);
1063 change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) || 1063 change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) ||
1064 new_serial.custom_divisor != state->custom_divisor; 1064 new_serial.custom_divisor != state->custom_divisor;
1065 if (new_serial.irq || new_serial.port != state->port || 1065 if (new_serial.irq || new_serial.port != state->port ||
1066 new_serial.xmit_fifo_size != state->xmit_fifo_size) { 1066 new_serial.xmit_fifo_size != state->xmit_fifo_size) {
1067 tty_unlock(); 1067 tty_unlock(tty);
1068 return -EINVAL; 1068 return -EINVAL;
1069 } 1069 }
1070 1070
@@ -1074,7 +1074,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
1074 (new_serial.xmit_fifo_size != state->xmit_fifo_size) || 1074 (new_serial.xmit_fifo_size != state->xmit_fifo_size) ||
1075 ((new_serial.flags & ~ASYNC_USR_MASK) != 1075 ((new_serial.flags & ~ASYNC_USR_MASK) !=
1076 (port->flags & ~ASYNC_USR_MASK))) { 1076 (port->flags & ~ASYNC_USR_MASK))) {
1077 tty_unlock(); 1077 tty_unlock(tty);
1078 return -EPERM; 1078 return -EPERM;
1079 } 1079 }
1080 port->flags = ((port->flags & ~ASYNC_USR_MASK) | 1080 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
@@ -1084,7 +1084,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
1084 } 1084 }
1085 1085
1086 if (new_serial.baud_base < 9600) { 1086 if (new_serial.baud_base < 9600) {
1087 tty_unlock(); 1087 tty_unlock(tty);
1088 return -EINVAL; 1088 return -EINVAL;
1089 } 1089 }
1090 1090
@@ -1116,7 +1116,7 @@ check_and_exit:
1116 } 1116 }
1117 } else 1117 } else
1118 retval = startup(tty, state); 1118 retval = startup(tty, state);
1119 tty_unlock(); 1119 tty_unlock(tty);
1120 return retval; 1120 return retval;
1121} 1121}
1122 1122
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
index e61cabdd69df..69e9ca2dd4b3 100644
--- a/drivers/tty/cyclades.c
+++ b/drivers/tty/cyclades.c
@@ -1599,7 +1599,7 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
1599 * If the port is the middle of closing, bail out now 1599 * If the port is the middle of closing, bail out now
1600 */ 1600 */
1601 if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) { 1601 if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) {
1602 wait_event_interruptible_tty(info->port.close_wait, 1602 wait_event_interruptible_tty(tty, info->port.close_wait,
1603 !(info->port.flags & ASYNC_CLOSING)); 1603 !(info->port.flags & ASYNC_CLOSING));
1604 return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS; 1604 return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
1605 } 1605 }
@@ -3289,6 +3289,7 @@ static unsigned short __devinit cyy_init_card(void __iomem *true_base_addr,
3289static int __init cy_detect_isa(void) 3289static int __init cy_detect_isa(void)
3290{ 3290{
3291#ifdef CONFIG_ISA 3291#ifdef CONFIG_ISA
3292 struct cyclades_card *card;
3292 unsigned short cy_isa_irq, nboard; 3293 unsigned short cy_isa_irq, nboard;
3293 void __iomem *cy_isa_address; 3294 void __iomem *cy_isa_address;
3294 unsigned short i, j, cy_isa_nchan; 3295 unsigned short i, j, cy_isa_nchan;
@@ -3349,7 +3350,8 @@ static int __init cy_detect_isa(void)
3349 } 3350 }
3350 /* fill the next cy_card structure available */ 3351 /* fill the next cy_card structure available */
3351 for (j = 0; j < NR_CARDS; j++) { 3352 for (j = 0; j < NR_CARDS; j++) {
3352 if (cy_card[j].base_addr == NULL) 3353 card = &cy_card[j];
3354 if (card->base_addr == NULL)
3353 break; 3355 break;
3354 } 3356 }
3355 if (j == NR_CARDS) { /* no more cy_cards available */ 3357 if (j == NR_CARDS) { /* no more cy_cards available */
@@ -3363,7 +3365,7 @@ static int __init cy_detect_isa(void)
3363 3365
3364 /* allocate IRQ */ 3366 /* allocate IRQ */
3365 if (request_irq(cy_isa_irq, cyy_interrupt, 3367 if (request_irq(cy_isa_irq, cyy_interrupt,
3366 0, "Cyclom-Y", &cy_card[j])) { 3368 0, "Cyclom-Y", card)) {
3367 printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but " 3369 printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but "
3368 "could not allocate IRQ#%d.\n", 3370 "could not allocate IRQ#%d.\n",
3369 (unsigned long)cy_isa_address, cy_isa_irq); 3371 (unsigned long)cy_isa_address, cy_isa_irq);
@@ -3372,16 +3374,16 @@ static int __init cy_detect_isa(void)
3372 } 3374 }
3373 3375
3374 /* set cy_card */ 3376 /* set cy_card */
3375 cy_card[j].base_addr = cy_isa_address; 3377 card->base_addr = cy_isa_address;
3376 cy_card[j].ctl_addr.p9050 = NULL; 3378 card->ctl_addr.p9050 = NULL;
3377 cy_card[j].irq = (int)cy_isa_irq; 3379 card->irq = (int)cy_isa_irq;
3378 cy_card[j].bus_index = 0; 3380 card->bus_index = 0;
3379 cy_card[j].first_line = cy_next_channel; 3381 card->first_line = cy_next_channel;
3380 cy_card[j].num_chips = cy_isa_nchan / CyPORTS_PER_CHIP; 3382 card->num_chips = cy_isa_nchan / CyPORTS_PER_CHIP;
3381 cy_card[j].nports = cy_isa_nchan; 3383 card->nports = cy_isa_nchan;
3382 if (cy_init_card(&cy_card[j])) { 3384 if (cy_init_card(card)) {
3383 cy_card[j].base_addr = NULL; 3385 card->base_addr = NULL;
3384 free_irq(cy_isa_irq, &cy_card[j]); 3386 free_irq(cy_isa_irq, card);
3385 iounmap(cy_isa_address); 3387 iounmap(cy_isa_address);
3386 continue; 3388 continue;
3387 } 3389 }
@@ -3695,6 +3697,7 @@ err:
3695static int __devinit cy_pci_probe(struct pci_dev *pdev, 3697static int __devinit cy_pci_probe(struct pci_dev *pdev,
3696 const struct pci_device_id *ent) 3698 const struct pci_device_id *ent)
3697{ 3699{
3700 struct cyclades_card *card;
3698 void __iomem *addr0 = NULL, *addr2 = NULL; 3701 void __iomem *addr0 = NULL, *addr2 = NULL;
3699 char *card_name = NULL; 3702 char *card_name = NULL;
3700 u32 uninitialized_var(mailbox); 3703 u32 uninitialized_var(mailbox);
@@ -3829,7 +3832,8 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
3829 } 3832 }
3830 /* fill the next cy_card structure available */ 3833 /* fill the next cy_card structure available */
3831 for (card_no = 0; card_no < NR_CARDS; card_no++) { 3834 for (card_no = 0; card_no < NR_CARDS; card_no++) {
3832 if (cy_card[card_no].base_addr == NULL) 3835 card = &cy_card[card_no];
3836 if (card->base_addr == NULL)
3833 break; 3837 break;
3834 } 3838 }
3835 if (card_no == NR_CARDS) { /* no more cy_cards available */ 3839 if (card_no == NR_CARDS) { /* no more cy_cards available */
@@ -3843,27 +3847,26 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
3843 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) { 3847 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
3844 /* allocate IRQ */ 3848 /* allocate IRQ */
3845 retval = request_irq(irq, cyy_interrupt, 3849 retval = request_irq(irq, cyy_interrupt,
3846 IRQF_SHARED, "Cyclom-Y", &cy_card[card_no]); 3850 IRQF_SHARED, "Cyclom-Y", card);
3847 if (retval) { 3851 if (retval) {
3848 dev_err(&pdev->dev, "could not allocate IRQ\n"); 3852 dev_err(&pdev->dev, "could not allocate IRQ\n");
3849 goto err_unmap; 3853 goto err_unmap;
3850 } 3854 }
3851 cy_card[card_no].num_chips = nchan / CyPORTS_PER_CHIP; 3855 card->num_chips = nchan / CyPORTS_PER_CHIP;
3852 } else { 3856 } else {
3853 struct FIRM_ID __iomem *firm_id = addr2 + ID_ADDRESS; 3857 struct FIRM_ID __iomem *firm_id = addr2 + ID_ADDRESS;
3854 struct ZFW_CTRL __iomem *zfw_ctrl; 3858 struct ZFW_CTRL __iomem *zfw_ctrl;
3855 3859
3856 zfw_ctrl = addr2 + (readl(&firm_id->zfwctrl_addr) & 0xfffff); 3860 zfw_ctrl = addr2 + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3857 3861
3858 cy_card[card_no].hw_ver = mailbox; 3862 card->hw_ver = mailbox;
3859 cy_card[card_no].num_chips = (unsigned int)-1; 3863 card->num_chips = (unsigned int)-1;
3860 cy_card[card_no].board_ctrl = &zfw_ctrl->board_ctrl; 3864 card->board_ctrl = &zfw_ctrl->board_ctrl;
3861#ifdef CONFIG_CYZ_INTR 3865#ifdef CONFIG_CYZ_INTR
3862 /* allocate IRQ only if board has an IRQ */ 3866 /* allocate IRQ only if board has an IRQ */
3863 if (irq != 0 && irq != 255) { 3867 if (irq != 0 && irq != 255) {
3864 retval = request_irq(irq, cyz_interrupt, 3868 retval = request_irq(irq, cyz_interrupt,
3865 IRQF_SHARED, "Cyclades-Z", 3869 IRQF_SHARED, "Cyclades-Z", card);
3866 &cy_card[card_no]);
3867 if (retval) { 3870 if (retval) {
3868 dev_err(&pdev->dev, "could not allocate IRQ\n"); 3871 dev_err(&pdev->dev, "could not allocate IRQ\n");
3869 goto err_unmap; 3872 goto err_unmap;
@@ -3873,17 +3876,17 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
3873 } 3876 }
3874 3877
3875 /* set cy_card */ 3878 /* set cy_card */
3876 cy_card[card_no].base_addr = addr2; 3879 card->base_addr = addr2;
3877 cy_card[card_no].ctl_addr.p9050 = addr0; 3880 card->ctl_addr.p9050 = addr0;
3878 cy_card[card_no].irq = irq; 3881 card->irq = irq;
3879 cy_card[card_no].bus_index = 1; 3882 card->bus_index = 1;
3880 cy_card[card_no].first_line = cy_next_channel; 3883 card->first_line = cy_next_channel;
3881 cy_card[card_no].nports = nchan; 3884 card->nports = nchan;
3882 retval = cy_init_card(&cy_card[card_no]); 3885 retval = cy_init_card(card);
3883 if (retval) 3886 if (retval)
3884 goto err_null; 3887 goto err_null;
3885 3888
3886 pci_set_drvdata(pdev, &cy_card[card_no]); 3889 pci_set_drvdata(pdev, card);
3887 3890
3888 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo || 3891 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
3889 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) { 3892 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
@@ -3915,8 +3918,8 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
3915 3918
3916 return 0; 3919 return 0;
3917err_null: 3920err_null:
3918 cy_card[card_no].base_addr = NULL; 3921 card->base_addr = NULL;
3919 free_irq(irq, &cy_card[card_no]); 3922 free_irq(irq, card);
3920err_unmap: 3923err_unmap:
3921 iounmap(addr0); 3924 iounmap(addr0);
3922 if (addr2) 3925 if (addr2)
diff --git a/drivers/tty/n_r3964.c b/drivers/tty/n_r3964.c
index 5c6c31459a2f..1e6405070ce6 100644
--- a/drivers/tty/n_r3964.c
+++ b/drivers/tty/n_r3964.c
@@ -1065,7 +1065,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1065 1065
1066 TRACE_L("read()"); 1066 TRACE_L("read()");
1067 1067
1068 tty_lock(); 1068 tty_lock(tty);
1069 1069
1070 pClient = findClient(pInfo, task_pid(current)); 1070 pClient = findClient(pInfo, task_pid(current));
1071 if (pClient) { 1071 if (pClient) {
@@ -1077,7 +1077,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1077 goto unlock; 1077 goto unlock;
1078 } 1078 }
1079 /* block until there is a message: */ 1079 /* block until there is a message: */
1080 wait_event_interruptible_tty(pInfo->read_wait, 1080 wait_event_interruptible_tty(tty, pInfo->read_wait,
1081 (pMsg = remove_msg(pInfo, pClient))); 1081 (pMsg = remove_msg(pInfo, pClient)));
1082 } 1082 }
1083 1083
@@ -1107,7 +1107,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1107 } 1107 }
1108 ret = -EPERM; 1108 ret = -EPERM;
1109unlock: 1109unlock:
1110 tty_unlock(); 1110 tty_unlock(tty);
1111 return ret; 1111 return ret;
1112} 1112}
1113 1113
@@ -1156,7 +1156,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1156 pHeader->locks = 0; 1156 pHeader->locks = 0;
1157 pHeader->owner = NULL; 1157 pHeader->owner = NULL;
1158 1158
1159 tty_lock(); 1159 tty_lock(tty);
1160 1160
1161 pClient = findClient(pInfo, task_pid(current)); 1161 pClient = findClient(pInfo, task_pid(current));
1162 if (pClient) { 1162 if (pClient) {
@@ -1175,7 +1175,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1175 add_tx_queue(pInfo, pHeader); 1175 add_tx_queue(pInfo, pHeader);
1176 trigger_transmit(pInfo); 1176 trigger_transmit(pInfo);
1177 1177
1178 tty_unlock(); 1178 tty_unlock(tty);
1179 1179
1180 return 0; 1180 return 0;
1181} 1181}
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index ee1c268f5f9d..4f34491b65c6 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1432,6 +1432,12 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
1432 */ 1432 */
1433 if (tty->receive_room < TTY_THRESHOLD_THROTTLE) 1433 if (tty->receive_room < TTY_THRESHOLD_THROTTLE)
1434 tty_throttle(tty); 1434 tty_throttle(tty);
1435
1436 /* FIXME: there is a tiny race here if the receive room check runs
1437 before the other work executes and empties the buffer (upping
1438 the receiving room and unthrottling. We then throttle and get
1439 stuck. This has been observed and traced down by Vincent Pillet/
1440 We need to address this when we sort out out the rx path locking */
1435} 1441}
1436 1442
1437int is_ignored(int sig) 1443int is_ignored(int sig)
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 5505ffc91da4..a0ca0830cbcf 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -47,6 +47,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
47 wake_up_interruptible(&tty->read_wait); 47 wake_up_interruptible(&tty->read_wait);
48 wake_up_interruptible(&tty->write_wait); 48 wake_up_interruptible(&tty->write_wait);
49 tty->packet = 0; 49 tty->packet = 0;
50 /* Review - krefs on tty_link ?? */
50 if (!tty->link) 51 if (!tty->link)
51 return; 52 return;
52 tty->link->packet = 0; 53 tty->link->packet = 0;
@@ -62,9 +63,9 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
62 mutex_unlock(&devpts_mutex); 63 mutex_unlock(&devpts_mutex);
63 } 64 }
64#endif 65#endif
65 tty_unlock(); 66 tty_unlock(tty);
66 tty_vhangup(tty->link); 67 tty_vhangup(tty->link);
67 tty_lock(); 68 tty_lock(tty);
68 } 69 }
69} 70}
70 71
@@ -282,60 +283,98 @@ done:
282 return 0; 283 return 0;
283} 284}
284 285
285/* Traditional BSD devices */ 286static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
286#ifdef CONFIG_LEGACY_PTYS 287 bool legacy)
287
288static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
289{ 288{
290 struct tty_struct *o_tty; 289 struct tty_struct *o_tty;
290 struct tty_port *ports[2];
291 int idx = tty->index; 291 int idx = tty->index;
292 int retval; 292 int retval = -ENOMEM;
293 293
294 o_tty = alloc_tty_struct(); 294 o_tty = alloc_tty_struct();
295 if (!o_tty) 295 ports[0] = kmalloc(sizeof **ports, GFP_KERNEL);
296 return -ENOMEM; 296 ports[1] = kmalloc(sizeof **ports, GFP_KERNEL);
297 if (!o_tty || !ports[0] || !ports[1])
298 goto err_free_tty;
297 if (!try_module_get(driver->other->owner)) { 299 if (!try_module_get(driver->other->owner)) {
298 /* This cannot in fact currently happen */ 300 /* This cannot in fact currently happen */
299 retval = -ENOMEM;
300 goto err_free_tty; 301 goto err_free_tty;
301 } 302 }
302 initialize_tty_struct(o_tty, driver->other, idx); 303 initialize_tty_struct(o_tty, driver->other, idx);
303 304
304 /* We always use new tty termios data so we can do this 305 if (legacy) {
305 the easy way .. */ 306 /* We always use new tty termios data so we can do this
306 retval = tty_init_termios(tty); 307 the easy way .. */
307 if (retval) 308 retval = tty_init_termios(tty);
308 goto err_deinit_tty; 309 if (retval)
309 310 goto err_deinit_tty;
310 retval = tty_init_termios(o_tty); 311
311 if (retval) 312 retval = tty_init_termios(o_tty);
312 goto err_free_termios; 313 if (retval)
314 goto err_free_termios;
315
316 driver->other->ttys[idx] = o_tty;
317 driver->ttys[idx] = tty;
318 } else {
319 tty->termios = kzalloc(sizeof(struct ktermios[2]), GFP_KERNEL);
320 if (tty->termios == NULL)
321 goto err_deinit_tty;
322 *tty->termios = driver->init_termios;
323 tty->termios_locked = tty->termios + 1;
324
325 o_tty->termios = kzalloc(sizeof(struct ktermios[2]),
326 GFP_KERNEL);
327 if (o_tty->termios == NULL)
328 goto err_free_termios;
329 *o_tty->termios = driver->other->init_termios;
330 o_tty->termios_locked = o_tty->termios + 1;
331 }
313 332
314 /* 333 /*
315 * Everything allocated ... set up the o_tty structure. 334 * Everything allocated ... set up the o_tty structure.
316 */ 335 */
317 driver->other->ttys[idx] = o_tty;
318 tty_driver_kref_get(driver->other); 336 tty_driver_kref_get(driver->other);
319 if (driver->subtype == PTY_TYPE_MASTER) 337 if (driver->subtype == PTY_TYPE_MASTER)
320 o_tty->count++; 338 o_tty->count++;
321 /* Establish the links in both directions */ 339 /* Establish the links in both directions */
322 tty->link = o_tty; 340 tty->link = o_tty;
323 o_tty->link = tty; 341 o_tty->link = tty;
342 tty_port_init(ports[0]);
343 tty_port_init(ports[1]);
344 o_tty->port = ports[0];
345 tty->port = ports[1];
324 346
325 tty_driver_kref_get(driver); 347 tty_driver_kref_get(driver);
326 tty->count++; 348 tty->count++;
327 driver->ttys[idx] = tty;
328 return 0; 349 return 0;
329err_free_termios: 350err_free_termios:
330 tty_free_termios(tty); 351 if (legacy)
352 tty_free_termios(tty);
353 else
354 kfree(tty->termios);
331err_deinit_tty: 355err_deinit_tty:
332 deinitialize_tty_struct(o_tty); 356 deinitialize_tty_struct(o_tty);
333 module_put(o_tty->driver->owner); 357 module_put(o_tty->driver->owner);
334err_free_tty: 358err_free_tty:
359 kfree(ports[0]);
360 kfree(ports[1]);
335 free_tty_struct(o_tty); 361 free_tty_struct(o_tty);
336 return retval; 362 return retval;
337} 363}
338 364
365static void pty_cleanup(struct tty_struct *tty)
366{
367 kfree(tty->port);
368}
369
370/* Traditional BSD devices */
371#ifdef CONFIG_LEGACY_PTYS
372
373static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
374{
375 return pty_common_install(driver, tty, true);
376}
377
339static int pty_bsd_ioctl(struct tty_struct *tty, 378static int pty_bsd_ioctl(struct tty_struct *tty,
340 unsigned int cmd, unsigned long arg) 379 unsigned int cmd, unsigned long arg)
341{ 380{
@@ -366,6 +405,7 @@ static const struct tty_operations master_pty_ops_bsd = {
366 .unthrottle = pty_unthrottle, 405 .unthrottle = pty_unthrottle,
367 .set_termios = pty_set_termios, 406 .set_termios = pty_set_termios,
368 .ioctl = pty_bsd_ioctl, 407 .ioctl = pty_bsd_ioctl,
408 .cleanup = pty_cleanup,
369 .resize = pty_resize 409 .resize = pty_resize
370}; 410};
371 411
@@ -379,6 +419,7 @@ static const struct tty_operations slave_pty_ops_bsd = {
379 .chars_in_buffer = pty_chars_in_buffer, 419 .chars_in_buffer = pty_chars_in_buffer,
380 .unthrottle = pty_unthrottle, 420 .unthrottle = pty_unthrottle,
381 .set_termios = pty_set_termios, 421 .set_termios = pty_set_termios,
422 .cleanup = pty_cleanup,
382 .resize = pty_resize 423 .resize = pty_resize
383}; 424};
384 425
@@ -509,66 +550,17 @@ static void pty_unix98_shutdown(struct tty_struct *tty)
509 550
510static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty) 551static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty)
511{ 552{
512 struct tty_struct *o_tty; 553 return pty_common_install(driver, tty, false);
513 int idx = tty->index;
514
515 o_tty = alloc_tty_struct();
516 if (!o_tty)
517 return -ENOMEM;
518 if (!try_module_get(driver->other->owner)) {
519 /* This cannot in fact currently happen */
520 goto err_free_tty;
521 }
522 initialize_tty_struct(o_tty, driver->other, idx);
523
524 tty->termios = kzalloc(sizeof(struct ktermios[2]), GFP_KERNEL);
525 if (tty->termios == NULL)
526 goto err_free_mem;
527 *tty->termios = driver->init_termios;
528 tty->termios_locked = tty->termios + 1;
529
530 o_tty->termios = kzalloc(sizeof(struct ktermios[2]), GFP_KERNEL);
531 if (o_tty->termios == NULL)
532 goto err_free_mem;
533 *o_tty->termios = driver->other->init_termios;
534 o_tty->termios_locked = o_tty->termios + 1;
535
536 tty_driver_kref_get(driver->other);
537 if (driver->subtype == PTY_TYPE_MASTER)
538 o_tty->count++;
539 /* Establish the links in both directions */
540 tty->link = o_tty;
541 o_tty->link = tty;
542 /*
543 * All structures have been allocated, so now we install them.
544 * Failures after this point use release_tty to clean up, so
545 * there's no need to null out the local pointers.
546 */
547 tty_driver_kref_get(driver);
548 tty->count++;
549 return 0;
550err_free_mem:
551 deinitialize_tty_struct(o_tty);
552 kfree(o_tty->termios);
553 kfree(tty->termios);
554 module_put(o_tty->driver->owner);
555err_free_tty:
556 free_tty_struct(o_tty);
557 return -ENOMEM;
558}
559
560static void ptm_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
561{
562} 554}
563 555
564static void pts_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) 556static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
565{ 557{
566} 558}
567 559
568static const struct tty_operations ptm_unix98_ops = { 560static const struct tty_operations ptm_unix98_ops = {
569 .lookup = ptm_unix98_lookup, 561 .lookup = ptm_unix98_lookup,
570 .install = pty_unix98_install, 562 .install = pty_unix98_install,
571 .remove = ptm_unix98_remove, 563 .remove = pty_unix98_remove,
572 .open = pty_open, 564 .open = pty_open,
573 .close = pty_close, 565 .close = pty_close,
574 .write = pty_write, 566 .write = pty_write,
@@ -579,13 +571,14 @@ static const struct tty_operations ptm_unix98_ops = {
579 .set_termios = pty_set_termios, 571 .set_termios = pty_set_termios,
580 .ioctl = pty_unix98_ioctl, 572 .ioctl = pty_unix98_ioctl,
581 .shutdown = pty_unix98_shutdown, 573 .shutdown = pty_unix98_shutdown,
574 .cleanup = pty_cleanup,
582 .resize = pty_resize 575 .resize = pty_resize
583}; 576};
584 577
585static const struct tty_operations pty_unix98_ops = { 578static const struct tty_operations pty_unix98_ops = {
586 .lookup = pts_unix98_lookup, 579 .lookup = pts_unix98_lookup,
587 .install = pty_unix98_install, 580 .install = pty_unix98_install,
588 .remove = pts_unix98_remove, 581 .remove = pty_unix98_remove,
589 .open = pty_open, 582 .open = pty_open,
590 .close = pty_close, 583 .close = pty_close,
591 .write = pty_write, 584 .write = pty_write,
@@ -594,7 +587,8 @@ static const struct tty_operations pty_unix98_ops = {
594 .chars_in_buffer = pty_chars_in_buffer, 587 .chars_in_buffer = pty_chars_in_buffer,
595 .unthrottle = pty_unthrottle, 588 .unthrottle = pty_unthrottle,
596 .set_termios = pty_set_termios, 589 .set_termios = pty_set_termios,
597 .shutdown = pty_unix98_shutdown 590 .shutdown = pty_unix98_shutdown,
591 .cleanup = pty_cleanup,
598}; 592};
599 593
600/** 594/**
@@ -622,26 +616,26 @@ static int ptmx_open(struct inode *inode, struct file *filp)
622 return retval; 616 return retval;
623 617
624 /* find a device that is not in use. */ 618 /* find a device that is not in use. */
625 tty_lock(); 619 mutex_lock(&devpts_mutex);
626 index = devpts_new_index(inode); 620 index = devpts_new_index(inode);
627 tty_unlock(); 621 mutex_unlock(&devpts_mutex);
628 if (index < 0) { 622 if (index < 0) {
629 retval = index; 623 retval = index;
630 goto err_file; 624 goto err_file;
631 } 625 }
632 626
633 mutex_lock(&tty_mutex); 627 mutex_lock(&tty_mutex);
634 mutex_lock(&devpts_mutex);
635 tty = tty_init_dev(ptm_driver, index); 628 tty = tty_init_dev(ptm_driver, index);
636 mutex_unlock(&devpts_mutex);
637 tty_lock();
638 mutex_unlock(&tty_mutex);
639 629
640 if (IS_ERR(tty)) { 630 if (IS_ERR(tty)) {
641 retval = PTR_ERR(tty); 631 retval = PTR_ERR(tty);
642 goto out; 632 goto out;
643 } 633 }
644 634
635 /* The tty returned here is locked so we can safely
636 drop the mutex */
637 mutex_unlock(&tty_mutex);
638
645 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ 639 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
646 640
647 tty_add_file(tty, filp); 641 tty_add_file(tty, filp);
@@ -654,15 +648,15 @@ static int ptmx_open(struct inode *inode, struct file *filp)
654 if (retval) 648 if (retval)
655 goto err_release; 649 goto err_release;
656 650
657 tty_unlock(); 651 tty_unlock(tty);
658 return 0; 652 return 0;
659err_release: 653err_release:
660 tty_unlock(); 654 tty_unlock(tty);
661 tty_release(inode, filp); 655 tty_release(inode, filp);
662 return retval; 656 return retval;
663out: 657out:
658 mutex_unlock(&tty_mutex);
664 devpts_kill_index(inode, index); 659 devpts_kill_index(inode, index);
665 tty_unlock();
666err_file: 660err_file:
667 tty_free_file(filp); 661 tty_free_file(filp);
668 return retval; 662 return retval;
diff --git a/drivers/tty/serial/8250/8250.c b/drivers/tty/serial/8250/8250.c
index 6e1958a325bd..44f52c6f15b9 100644
--- a/drivers/tty/serial/8250/8250.c
+++ b/drivers/tty/serial/8250/8250.c
@@ -282,6 +282,14 @@ static const struct serial8250_config uart_config[] = {
282 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 282 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
283 .flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR, 283 .flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR,
284 }, 284 },
285 [PORT_LPC3220] = {
286 .name = "LPC3220",
287 .fifo_size = 64,
288 .tx_loadsz = 32,
289 .fcr = UART_FCR_DMA_SELECT | UART_FCR_ENABLE_FIFO |
290 UART_FCR_R_TRIG_00 | UART_FCR_T_TRIG_00,
291 .flags = UART_CAP_FIFO,
292 },
285}; 293};
286 294
287/* Uart divisor latch read */ 295/* Uart divisor latch read */
@@ -2194,6 +2202,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
2194 unsigned char cval, fcr = 0; 2202 unsigned char cval, fcr = 0;
2195 unsigned long flags; 2203 unsigned long flags;
2196 unsigned int baud, quot; 2204 unsigned int baud, quot;
2205 int fifo_bug = 0;
2197 2206
2198 switch (termios->c_cflag & CSIZE) { 2207 switch (termios->c_cflag & CSIZE) {
2199 case CS5: 2208 case CS5:
@@ -2213,8 +2222,11 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
2213 2222
2214 if (termios->c_cflag & CSTOPB) 2223 if (termios->c_cflag & CSTOPB)
2215 cval |= UART_LCR_STOP; 2224 cval |= UART_LCR_STOP;
2216 if (termios->c_cflag & PARENB) 2225 if (termios->c_cflag & PARENB) {
2217 cval |= UART_LCR_PARITY; 2226 cval |= UART_LCR_PARITY;
2227 if (up->bugs & UART_BUG_PARITY)
2228 fifo_bug = 1;
2229 }
2218 if (!(termios->c_cflag & PARODD)) 2230 if (!(termios->c_cflag & PARODD))
2219 cval |= UART_LCR_EPAR; 2231 cval |= UART_LCR_EPAR;
2220#ifdef CMSPAR 2232#ifdef CMSPAR
@@ -2238,7 +2250,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
2238 2250
2239 if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) { 2251 if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) {
2240 fcr = uart_config[port->type].fcr; 2252 fcr = uart_config[port->type].fcr;
2241 if (baud < 2400) { 2253 if (baud < 2400 || fifo_bug) {
2242 fcr &= ~UART_FCR_TRIGGER_MASK; 2254 fcr &= ~UART_FCR_TRIGGER_MASK;
2243 fcr |= UART_FCR_TRIGGER_1; 2255 fcr |= UART_FCR_TRIGGER_1;
2244 } 2256 }
@@ -2971,36 +2983,36 @@ void serial8250_resume_port(int line)
2971static int __devinit serial8250_probe(struct platform_device *dev) 2983static int __devinit serial8250_probe(struct platform_device *dev)
2972{ 2984{
2973 struct plat_serial8250_port *p = dev->dev.platform_data; 2985 struct plat_serial8250_port *p = dev->dev.platform_data;
2974 struct uart_port port; 2986 struct uart_8250_port uart;
2975 int ret, i, irqflag = 0; 2987 int ret, i, irqflag = 0;
2976 2988
2977 memset(&port, 0, sizeof(struct uart_port)); 2989 memset(&uart, 0, sizeof(uart));
2978 2990
2979 if (share_irqs) 2991 if (share_irqs)
2980 irqflag = IRQF_SHARED; 2992 irqflag = IRQF_SHARED;
2981 2993
2982 for (i = 0; p && p->flags != 0; p++, i++) { 2994 for (i = 0; p && p->flags != 0; p++, i++) {
2983 port.iobase = p->iobase; 2995 uart.port.iobase = p->iobase;
2984 port.membase = p->membase; 2996 uart.port.membase = p->membase;
2985 port.irq = p->irq; 2997 uart.port.irq = p->irq;
2986 port.irqflags = p->irqflags; 2998 uart.port.irqflags = p->irqflags;
2987 port.uartclk = p->uartclk; 2999 uart.port.uartclk = p->uartclk;
2988 port.regshift = p->regshift; 3000 uart.port.regshift = p->regshift;
2989 port.iotype = p->iotype; 3001 uart.port.iotype = p->iotype;
2990 port.flags = p->flags; 3002 uart.port.flags = p->flags;
2991 port.mapbase = p->mapbase; 3003 uart.port.mapbase = p->mapbase;
2992 port.hub6 = p->hub6; 3004 uart.port.hub6 = p->hub6;
2993 port.private_data = p->private_data; 3005 uart.port.private_data = p->private_data;
2994 port.type = p->type; 3006 uart.port.type = p->type;
2995 port.serial_in = p->serial_in; 3007 uart.port.serial_in = p->serial_in;
2996 port.serial_out = p->serial_out; 3008 uart.port.serial_out = p->serial_out;
2997 port.handle_irq = p->handle_irq; 3009 uart.port.handle_irq = p->handle_irq;
2998 port.handle_break = p->handle_break; 3010 uart.port.handle_break = p->handle_break;
2999 port.set_termios = p->set_termios; 3011 uart.port.set_termios = p->set_termios;
3000 port.pm = p->pm; 3012 uart.port.pm = p->pm;
3001 port.dev = &dev->dev; 3013 uart.port.dev = &dev->dev;
3002 port.irqflags |= irqflag; 3014 uart.port.irqflags |= irqflag;
3003 ret = serial8250_register_port(&port); 3015 ret = serial8250_register_8250_port(&uart);
3004 if (ret < 0) { 3016 if (ret < 0) {
3005 dev_err(&dev->dev, "unable to register port at index %d " 3017 dev_err(&dev->dev, "unable to register port at index %d "
3006 "(IO%lx MEM%llx IRQ%d): %d\n", i, 3018 "(IO%lx MEM%llx IRQ%d): %d\n", i,
@@ -3073,7 +3085,7 @@ static struct platform_driver serial8250_isa_driver = {
3073static struct platform_device *serial8250_isa_devs; 3085static struct platform_device *serial8250_isa_devs;
3074 3086
3075/* 3087/*
3076 * serial8250_register_port and serial8250_unregister_port allows for 3088 * serial8250_register_8250_port and serial8250_unregister_port allows for
3077 * 16x50 serial ports to be configured at run-time, to support PCMCIA 3089 * 16x50 serial ports to be configured at run-time, to support PCMCIA
3078 * modems and PCI multiport cards. 3090 * modems and PCI multiport cards.
3079 */ 3091 */
@@ -3147,6 +3159,7 @@ int serial8250_register_8250_port(struct uart_8250_port *up)
3147 uart->port.regshift = up->port.regshift; 3159 uart->port.regshift = up->port.regshift;
3148 uart->port.iotype = up->port.iotype; 3160 uart->port.iotype = up->port.iotype;
3149 uart->port.flags = up->port.flags | UPF_BOOT_AUTOCONF; 3161 uart->port.flags = up->port.flags | UPF_BOOT_AUTOCONF;
3162 uart->bugs = up->bugs;
3150 uart->port.mapbase = up->port.mapbase; 3163 uart->port.mapbase = up->port.mapbase;
3151 uart->port.private_data = up->port.private_data; 3164 uart->port.private_data = up->port.private_data;
3152 if (up->port.dev) 3165 if (up->port.dev)
@@ -3190,29 +3203,6 @@ int serial8250_register_8250_port(struct uart_8250_port *up)
3190EXPORT_SYMBOL(serial8250_register_8250_port); 3203EXPORT_SYMBOL(serial8250_register_8250_port);
3191 3204
3192/** 3205/**
3193 * serial8250_register_port - register a serial port
3194 * @port: serial port template
3195 *
3196 * Configure the serial port specified by the request. If the
3197 * port exists and is in use, it is hung up and unregistered
3198 * first.
3199 *
3200 * The port is then probed and if necessary the IRQ is autodetected
3201 * If this fails an error is returned.
3202 *
3203 * On success the port is ready to use and the line number is returned.
3204 */
3205int serial8250_register_port(struct uart_port *port)
3206{
3207 struct uart_8250_port up;
3208
3209 memset(&up, 0, sizeof(up));
3210 memcpy(&up.port, port, sizeof(*port));
3211 return serial8250_register_8250_port(&up);
3212}
3213EXPORT_SYMBOL(serial8250_register_port);
3214
3215/**
3216 * serial8250_unregister_port - remove a 16x50 serial port at runtime 3206 * serial8250_unregister_port - remove a 16x50 serial port at runtime
3217 * @line: serial line number 3207 * @line: serial line number
3218 * 3208 *
diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
index f9719d167c8d..c335b2b23a5f 100644
--- a/drivers/tty/serial/8250/8250.h
+++ b/drivers/tty/serial/8250/8250.h
@@ -78,6 +78,7 @@ struct serial8250_config {
78#define UART_BUG_TXEN (1 << 1) /* UART has buggy TX IIR status */ 78#define UART_BUG_TXEN (1 << 1) /* UART has buggy TX IIR status */
79#define UART_BUG_NOMSR (1 << 2) /* UART has buggy MSR status bits (Au1x00) */ 79#define UART_BUG_NOMSR (1 << 2) /* UART has buggy MSR status bits (Au1x00) */
80#define UART_BUG_THRE (1 << 3) /* UART has buggy THRE reassertion */ 80#define UART_BUG_THRE (1 << 3) /* UART has buggy THRE reassertion */
81#define UART_BUG_PARITY (1 << 4) /* UART mishandles parity if FIFO enabled */
81 82
82#define PROBE_RSA (1 << 0) 83#define PROBE_RSA (1 << 0)
83#define PROBE_ANY (~0) 84#define PROBE_ANY (~0)
diff --git a/drivers/tty/serial/8250/8250_acorn.c b/drivers/tty/serial/8250/8250_acorn.c
index b0ce8c56f1a4..857498312a9a 100644
--- a/drivers/tty/serial/8250/8250_acorn.c
+++ b/drivers/tty/serial/8250/8250_acorn.c
@@ -43,7 +43,7 @@ serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
43{ 43{
44 struct serial_card_info *info; 44 struct serial_card_info *info;
45 struct serial_card_type *type = id->data; 45 struct serial_card_type *type = id->data;
46 struct uart_port port; 46 struct uart_8250_port uart;
47 unsigned long bus_addr; 47 unsigned long bus_addr;
48 unsigned int i; 48 unsigned int i;
49 49
@@ -62,19 +62,19 @@ serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
62 62
63 ecard_set_drvdata(ec, info); 63 ecard_set_drvdata(ec, info);
64 64
65 memset(&port, 0, sizeof(struct uart_port)); 65 memset(&uart, 0, sizeof(struct uart_8250_port));
66 port.irq = ec->irq; 66 uart.port.irq = ec->irq;
67 port.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ; 67 uart.port.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
68 port.uartclk = type->uartclk; 68 uart.port.uartclk = type->uartclk;
69 port.iotype = UPIO_MEM; 69 uart.port.iotype = UPIO_MEM;
70 port.regshift = 2; 70 uart.port.regshift = 2;
71 port.dev = &ec->dev; 71 uart.port.dev = &ec->dev;
72 72
73 for (i = 0; i < info->num_ports; i ++) { 73 for (i = 0; i < info->num_ports; i ++) {
74 port.membase = info->vaddr + type->offset[i]; 74 uart.port.membase = info->vaddr + type->offset[i];
75 port.mapbase = bus_addr + type->offset[i]; 75 uart.port.mapbase = bus_addr + type->offset[i];
76 76
77 info->ports[i] = serial8250_register_port(&port); 77 info->ports[i] = serial8250_register_8250_port(&uart);
78 } 78 }
79 79
80 return 0; 80 return 0;
diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index f574eef3075f..afb955fdef03 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -89,7 +89,7 @@ static int dw8250_handle_irq(struct uart_port *p)
89 89
90static int __devinit dw8250_probe(struct platform_device *pdev) 90static int __devinit dw8250_probe(struct platform_device *pdev)
91{ 91{
92 struct uart_port port = {}; 92 struct uart_8250_port uart = {};
93 struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 93 struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
94 struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 94 struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
95 struct device_node *np = pdev->dev.of_node; 95 struct device_node *np = pdev->dev.of_node;
@@ -104,28 +104,28 @@ static int __devinit dw8250_probe(struct platform_device *pdev)
104 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 104 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
105 if (!data) 105 if (!data)
106 return -ENOMEM; 106 return -ENOMEM;
107 port.private_data = data; 107 uart.port.private_data = data;
108 108
109 spin_lock_init(&port.lock); 109 spin_lock_init(&uart.port.lock);
110 port.mapbase = regs->start; 110 uart.port.mapbase = regs->start;
111 port.irq = irq->start; 111 uart.port.irq = irq->start;
112 port.handle_irq = dw8250_handle_irq; 112 uart.port.handle_irq = dw8250_handle_irq;
113 port.type = PORT_8250; 113 uart.port.type = PORT_8250;
114 port.flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP | 114 uart.port.flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP |
115 UPF_FIXED_PORT | UPF_FIXED_TYPE; 115 UPF_FIXED_PORT | UPF_FIXED_TYPE;
116 port.dev = &pdev->dev; 116 uart.port.dev = &pdev->dev;
117 117
118 port.iotype = UPIO_MEM; 118 uart.port.iotype = UPIO_MEM;
119 port.serial_in = dw8250_serial_in; 119 uart.port.serial_in = dw8250_serial_in;
120 port.serial_out = dw8250_serial_out; 120 uart.port.serial_out = dw8250_serial_out;
121 if (!of_property_read_u32(np, "reg-io-width", &val)) { 121 if (!of_property_read_u32(np, "reg-io-width", &val)) {
122 switch (val) { 122 switch (val) {
123 case 1: 123 case 1:
124 break; 124 break;
125 case 4: 125 case 4:
126 port.iotype = UPIO_MEM32; 126 uart.port.iotype = UPIO_MEM32;
127 port.serial_in = dw8250_serial_in32; 127 uart.port.serial_in = dw8250_serial_in32;
128 port.serial_out = dw8250_serial_out32; 128 uart.port.serial_out = dw8250_serial_out32;
129 break; 129 break;
130 default: 130 default:
131 dev_err(&pdev->dev, "unsupported reg-io-width (%u)\n", 131 dev_err(&pdev->dev, "unsupported reg-io-width (%u)\n",
@@ -135,15 +135,15 @@ static int __devinit dw8250_probe(struct platform_device *pdev)
135 } 135 }
136 136
137 if (!of_property_read_u32(np, "reg-shift", &val)) 137 if (!of_property_read_u32(np, "reg-shift", &val))
138 port.regshift = val; 138 uart.port.regshift = val;
139 139
140 if (of_property_read_u32(np, "clock-frequency", &val)) { 140 if (of_property_read_u32(np, "clock-frequency", &val)) {
141 dev_err(&pdev->dev, "no clock-frequency property set\n"); 141 dev_err(&pdev->dev, "no clock-frequency property set\n");
142 return -EINVAL; 142 return -EINVAL;
143 } 143 }
144 port.uartclk = val; 144 uart.uart.port.uartclk = val;
145 145
146 data->line = serial8250_register_port(&port); 146 data->line = serial8250_register_8250_port(&uart);
147 if (data->line < 0) 147 if (data->line < 0)
148 return data->line; 148 return data->line;
149 149
diff --git a/drivers/tty/serial/8250/8250_gsc.c b/drivers/tty/serial/8250/8250_gsc.c
index d8c0ffbfa6e3..097dff9c08ad 100644
--- a/drivers/tty/serial/8250/8250_gsc.c
+++ b/drivers/tty/serial/8250/8250_gsc.c
@@ -26,7 +26,7 @@
26 26
27static int __init serial_init_chip(struct parisc_device *dev) 27static int __init serial_init_chip(struct parisc_device *dev)
28{ 28{
29 struct uart_port port; 29 struct uart_8250_port uart;
30 unsigned long address; 30 unsigned long address;
31 int err; 31 int err;
32 32
@@ -48,21 +48,21 @@ static int __init serial_init_chip(struct parisc_device *dev)
48 if (dev->id.sversion != 0x8d) 48 if (dev->id.sversion != 0x8d)
49 address += 0x800; 49 address += 0x800;
50 50
51 memset(&port, 0, sizeof(port)); 51 memset(&uart, 0, sizeof(uart));
52 port.iotype = UPIO_MEM; 52 uart.port.iotype = UPIO_MEM;
53 /* 7.272727MHz on Lasi. Assumed the same for Dino, Wax and Timi. */ 53 /* 7.272727MHz on Lasi. Assumed the same for Dino, Wax and Timi. */
54 port.uartclk = 7272727; 54 uart.port.uartclk = 7272727;
55 port.mapbase = address; 55 uart.port.mapbase = address;
56 port.membase = ioremap_nocache(address, 16); 56 uart.port.membase = ioremap_nocache(address, 16);
57 port.irq = dev->irq; 57 uart.port.irq = dev->irq;
58 port.flags = UPF_BOOT_AUTOCONF; 58 uart.port.flags = UPF_BOOT_AUTOCONF;
59 port.dev = &dev->dev; 59 uart.port.dev = &dev->dev;
60 60
61 err = serial8250_register_port(&port); 61 err = serial8250_register_8250_port(&uart);
62 if (err < 0) { 62 if (err < 0) {
63 printk(KERN_WARNING 63 printk(KERN_WARNING
64 "serial8250_register_port returned error %d\n", err); 64 "serial8250_register_8250_port returned error %d\n", err);
65 iounmap(port.membase); 65 iounmap(uart.port.membase);
66 return err; 66 return err;
67 } 67 }
68 68
diff --git a/drivers/tty/serial/8250/8250_hp300.c b/drivers/tty/serial/8250/8250_hp300.c
index c13438c93012..8f1dd2cc00a8 100644
--- a/drivers/tty/serial/8250/8250_hp300.c
+++ b/drivers/tty/serial/8250/8250_hp300.c
@@ -171,7 +171,7 @@ static int __devinit hpdca_init_one(struct dio_dev *d,
171 return 0; 171 return 0;
172 } 172 }
173#endif 173#endif
174 memset(&port, 0, sizeof(struct uart_port)); 174 memset(&uart, 0, sizeof(uart));
175 175
176 /* Memory mapped I/O */ 176 /* Memory mapped I/O */
177 port.iotype = UPIO_MEM; 177 port.iotype = UPIO_MEM;
@@ -182,7 +182,7 @@ static int __devinit hpdca_init_one(struct dio_dev *d,
182 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE); 182 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
183 port.regshift = 1; 183 port.regshift = 1;
184 port.dev = &d->dev; 184 port.dev = &d->dev;
185 line = serial8250_register_port(&port); 185 line = serial8250_register_8250_port(&uart);
186 186
187 if (line < 0) { 187 if (line < 0) {
188 printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d" 188 printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d"
@@ -210,7 +210,7 @@ static int __init hp300_8250_init(void)
210#ifdef CONFIG_HPAPCI 210#ifdef CONFIG_HPAPCI
211 int line; 211 int line;
212 unsigned long base; 212 unsigned long base;
213 struct uart_port uport; 213 struct uart_8250_port uart;
214 struct hp300_port *port; 214 struct hp300_port *port;
215 int i; 215 int i;
216#endif 216#endif
@@ -248,26 +248,26 @@ static int __init hp300_8250_init(void)
248 if (!port) 248 if (!port)
249 return -ENOMEM; 249 return -ENOMEM;
250 250
251 memset(&uport, 0, sizeof(struct uart_port)); 251 memset(&uart, 0, sizeof(uart));
252 252
253 base = (FRODO_BASE + FRODO_APCI_OFFSET(i)); 253 base = (FRODO_BASE + FRODO_APCI_OFFSET(i));
254 254
255 /* Memory mapped I/O */ 255 /* Memory mapped I/O */
256 uport.iotype = UPIO_MEM; 256 uart.port.iotype = UPIO_MEM;
257 uport.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ \ 257 uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ \
258 | UPF_BOOT_AUTOCONF; 258 | UPF_BOOT_AUTOCONF;
259 /* XXX - no interrupt support yet */ 259 /* XXX - no interrupt support yet */
260 uport.irq = 0; 260 uart.port.irq = 0;
261 uport.uartclk = HPAPCI_BAUD_BASE * 16; 261 uart.port.uartclk = HPAPCI_BAUD_BASE * 16;
262 uport.mapbase = base; 262 uart.port.mapbase = base;
263 uport.membase = (char *)(base + DIO_VIRADDRBASE); 263 uart.port.membase = (char *)(base + DIO_VIRADDRBASE);
264 uport.regshift = 2; 264 uart.port.regshift = 2;
265 265
266 line = serial8250_register_port(&uport); 266 line = serial8250_register_8250_port(&uart);
267 267
268 if (line < 0) { 268 if (line < 0) {
269 printk(KERN_NOTICE "8250_hp300: register_serial() APCI" 269 printk(KERN_NOTICE "8250_hp300: register_serial() APCI"
270 " %d irq %d failed\n", i, uport.irq); 270 " %d irq %d failed\n", i, uart.port.irq);
271 kfree(port); 271 kfree(port);
272 continue; 272 continue;
273 } 273 }
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 28e7c7cce893..62e10fe747a8 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -44,7 +44,7 @@ struct pci_serial_quirk {
44 int (*init)(struct pci_dev *dev); 44 int (*init)(struct pci_dev *dev);
45 int (*setup)(struct serial_private *, 45 int (*setup)(struct serial_private *,
46 const struct pciserial_board *, 46 const struct pciserial_board *,
47 struct uart_port *, int); 47 struct uart_8250_port *, int);
48 void (*exit)(struct pci_dev *dev); 48 void (*exit)(struct pci_dev *dev);
49}; 49};
50 50
@@ -59,7 +59,7 @@ struct serial_private {
59}; 59};
60 60
61static int pci_default_setup(struct serial_private*, 61static int pci_default_setup(struct serial_private*,
62 const struct pciserial_board*, struct uart_port*, int); 62 const struct pciserial_board*, struct uart_8250_port *, int);
63 63
64static void moan_device(const char *str, struct pci_dev *dev) 64static void moan_device(const char *str, struct pci_dev *dev)
65{ 65{
@@ -74,7 +74,7 @@ static void moan_device(const char *str, struct pci_dev *dev)
74} 74}
75 75
76static int 76static int
77setup_port(struct serial_private *priv, struct uart_port *port, 77setup_port(struct serial_private *priv, struct uart_8250_port *port,
78 int bar, int offset, int regshift) 78 int bar, int offset, int regshift)
79{ 79{
80 struct pci_dev *dev = priv->dev; 80 struct pci_dev *dev = priv->dev;
@@ -93,17 +93,17 @@ setup_port(struct serial_private *priv, struct uart_port *port,
93 if (!priv->remapped_bar[bar]) 93 if (!priv->remapped_bar[bar])
94 return -ENOMEM; 94 return -ENOMEM;
95 95
96 port->iotype = UPIO_MEM; 96 port->port.iotype = UPIO_MEM;
97 port->iobase = 0; 97 port->port.iobase = 0;
98 port->mapbase = base + offset; 98 port->port.mapbase = base + offset;
99 port->membase = priv->remapped_bar[bar] + offset; 99 port->port.membase = priv->remapped_bar[bar] + offset;
100 port->regshift = regshift; 100 port->port.regshift = regshift;
101 } else { 101 } else {
102 port->iotype = UPIO_PORT; 102 port->port.iotype = UPIO_PORT;
103 port->iobase = base + offset; 103 port->port.iobase = base + offset;
104 port->mapbase = 0; 104 port->port.mapbase = 0;
105 port->membase = NULL; 105 port->port.membase = NULL;
106 port->regshift = 0; 106 port->port.regshift = 0;
107 } 107 }
108 return 0; 108 return 0;
109} 109}
@@ -113,7 +113,7 @@ setup_port(struct serial_private *priv, struct uart_port *port,
113 */ 113 */
114static int addidata_apci7800_setup(struct serial_private *priv, 114static int addidata_apci7800_setup(struct serial_private *priv,
115 const struct pciserial_board *board, 115 const struct pciserial_board *board,
116 struct uart_port *port, int idx) 116 struct uart_8250_port *port, int idx)
117{ 117{
118 unsigned int bar = 0, offset = board->first_offset; 118 unsigned int bar = 0, offset = board->first_offset;
119 bar = FL_GET_BASE(board->flags); 119 bar = FL_GET_BASE(board->flags);
@@ -140,7 +140,7 @@ static int addidata_apci7800_setup(struct serial_private *priv,
140 */ 140 */
141static int 141static int
142afavlab_setup(struct serial_private *priv, const struct pciserial_board *board, 142afavlab_setup(struct serial_private *priv, const struct pciserial_board *board,
143 struct uart_port *port, int idx) 143 struct uart_8250_port *port, int idx)
144{ 144{
145 unsigned int bar, offset = board->first_offset; 145 unsigned int bar, offset = board->first_offset;
146 146
@@ -195,7 +195,7 @@ static int pci_hp_diva_init(struct pci_dev *dev)
195static int 195static int
196pci_hp_diva_setup(struct serial_private *priv, 196pci_hp_diva_setup(struct serial_private *priv,
197 const struct pciserial_board *board, 197 const struct pciserial_board *board,
198 struct uart_port *port, int idx) 198 struct uart_8250_port *port, int idx)
199{ 199{
200 unsigned int offset = board->first_offset; 200 unsigned int offset = board->first_offset;
201 unsigned int bar = FL_GET_BASE(board->flags); 201 unsigned int bar = FL_GET_BASE(board->flags);
@@ -370,7 +370,7 @@ static void __devexit pci_ni8430_exit(struct pci_dev *dev)
370/* SBS Technologies Inc. PMC-OCTPRO and P-OCTAL cards */ 370/* SBS Technologies Inc. PMC-OCTPRO and P-OCTAL cards */
371static int 371static int
372sbs_setup(struct serial_private *priv, const struct pciserial_board *board, 372sbs_setup(struct serial_private *priv, const struct pciserial_board *board,
373 struct uart_port *port, int idx) 373 struct uart_8250_port *port, int idx)
374{ 374{
375 unsigned int bar, offset = board->first_offset; 375 unsigned int bar, offset = board->first_offset;
376 376
@@ -525,7 +525,7 @@ static int pci_siig_init(struct pci_dev *dev)
525 525
526static int pci_siig_setup(struct serial_private *priv, 526static int pci_siig_setup(struct serial_private *priv,
527 const struct pciserial_board *board, 527 const struct pciserial_board *board,
528 struct uart_port *port, int idx) 528 struct uart_8250_port *port, int idx)
529{ 529{
530 unsigned int bar = FL_GET_BASE(board->flags) + idx, offset = 0; 530 unsigned int bar = FL_GET_BASE(board->flags) + idx, offset = 0;
531 531
@@ -619,7 +619,7 @@ static int pci_timedia_init(struct pci_dev *dev)
619static int 619static int
620pci_timedia_setup(struct serial_private *priv, 620pci_timedia_setup(struct serial_private *priv,
621 const struct pciserial_board *board, 621 const struct pciserial_board *board,
622 struct uart_port *port, int idx) 622 struct uart_8250_port *port, int idx)
623{ 623{
624 unsigned int bar = 0, offset = board->first_offset; 624 unsigned int bar = 0, offset = board->first_offset;
625 625
@@ -653,7 +653,7 @@ pci_timedia_setup(struct serial_private *priv,
653static int 653static int
654titan_400l_800l_setup(struct serial_private *priv, 654titan_400l_800l_setup(struct serial_private *priv,
655 const struct pciserial_board *board, 655 const struct pciserial_board *board,
656 struct uart_port *port, int idx) 656 struct uart_8250_port *port, int idx)
657{ 657{
658 unsigned int bar, offset = board->first_offset; 658 unsigned int bar, offset = board->first_offset;
659 659
@@ -754,7 +754,7 @@ static int pci_ni8430_init(struct pci_dev *dev)
754static int 754static int
755pci_ni8430_setup(struct serial_private *priv, 755pci_ni8430_setup(struct serial_private *priv,
756 const struct pciserial_board *board, 756 const struct pciserial_board *board,
757 struct uart_port *port, int idx) 757 struct uart_8250_port *port, int idx)
758{ 758{
759 void __iomem *p; 759 void __iomem *p;
760 unsigned long base, len; 760 unsigned long base, len;
@@ -781,7 +781,7 @@ pci_ni8430_setup(struct serial_private *priv,
781 781
782static int pci_netmos_9900_setup(struct serial_private *priv, 782static int pci_netmos_9900_setup(struct serial_private *priv,
783 const struct pciserial_board *board, 783 const struct pciserial_board *board,
784 struct uart_port *port, int idx) 784 struct uart_8250_port *port, int idx)
785{ 785{
786 unsigned int bar; 786 unsigned int bar;
787 787
@@ -1032,10 +1032,17 @@ static int pci_oxsemi_tornado_init(struct pci_dev *dev)
1032 return number_uarts; 1032 return number_uarts;
1033} 1033}
1034 1034
1035static int 1035static int pci_asix_setup(struct serial_private *priv,
1036pci_default_setup(struct serial_private *priv, 1036 const struct pciserial_board *board,
1037 struct uart_8250_port *port, int idx)
1038{
1039 port->bugs |= UART_BUG_PARITY;
1040 return pci_default_setup(priv, board, port, idx);
1041}
1042
1043static int pci_default_setup(struct serial_private *priv,
1037 const struct pciserial_board *board, 1044 const struct pciserial_board *board,
1038 struct uart_port *port, int idx) 1045 struct uart_8250_port *port, int idx)
1039{ 1046{
1040 unsigned int bar, offset = board->first_offset, maxnr; 1047 unsigned int bar, offset = board->first_offset, maxnr;
1041 1048
@@ -1057,15 +1064,15 @@ pci_default_setup(struct serial_private *priv,
1057static int 1064static int
1058ce4100_serial_setup(struct serial_private *priv, 1065ce4100_serial_setup(struct serial_private *priv,
1059 const struct pciserial_board *board, 1066 const struct pciserial_board *board,
1060 struct uart_port *port, int idx) 1067 struct uart_8250_port *port, int idx)
1061{ 1068{
1062 int ret; 1069 int ret;
1063 1070
1064 ret = setup_port(priv, port, 0, 0, board->reg_shift); 1071 ret = setup_port(priv, port, 0, 0, board->reg_shift);
1065 port->iotype = UPIO_MEM32; 1072 port->port.iotype = UPIO_MEM32;
1066 port->type = PORT_XSCALE; 1073 port->port.type = PORT_XSCALE;
1067 port->flags = (port->flags | UPF_FIXED_PORT | UPF_FIXED_TYPE); 1074 port->port.flags = (port->port.flags | UPF_FIXED_PORT | UPF_FIXED_TYPE);
1068 port->regshift = 2; 1075 port->port.regshift = 2;
1069 1076
1070 return ret; 1077 return ret;
1071} 1078}
@@ -1073,16 +1080,16 @@ ce4100_serial_setup(struct serial_private *priv,
1073static int 1080static int
1074pci_omegapci_setup(struct serial_private *priv, 1081pci_omegapci_setup(struct serial_private *priv,
1075 const struct pciserial_board *board, 1082 const struct pciserial_board *board,
1076 struct uart_port *port, int idx) 1083 struct uart_8250_port *port, int idx)
1077{ 1084{
1078 return setup_port(priv, port, 2, idx * 8, 0); 1085 return setup_port(priv, port, 2, idx * 8, 0);
1079} 1086}
1080 1087
1081static int skip_tx_en_setup(struct serial_private *priv, 1088static int skip_tx_en_setup(struct serial_private *priv,
1082 const struct pciserial_board *board, 1089 const struct pciserial_board *board,
1083 struct uart_port *port, int idx) 1090 struct uart_8250_port *port, int idx)
1084{ 1091{
1085 port->flags |= UPF_NO_TXEN_TEST; 1092 port->port.flags |= UPF_NO_TXEN_TEST;
1086 printk(KERN_DEBUG "serial8250: skipping TxEn test for device " 1093 printk(KERN_DEBUG "serial8250: skipping TxEn test for device "
1087 "[%04x:%04x] subsystem [%04x:%04x]\n", 1094 "[%04x:%04x] subsystem [%04x:%04x]\n",
1088 priv->dev->vendor, 1095 priv->dev->vendor,
@@ -1131,11 +1138,11 @@ static unsigned int kt_serial_in(struct uart_port *p, int offset)
1131 1138
1132static int kt_serial_setup(struct serial_private *priv, 1139static int kt_serial_setup(struct serial_private *priv,
1133 const struct pciserial_board *board, 1140 const struct pciserial_board *board,
1134 struct uart_port *port, int idx) 1141 struct uart_8250_port *port, int idx)
1135{ 1142{
1136 port->flags |= UPF_BUG_THRE; 1143 port->port.flags |= UPF_BUG_THRE;
1137 port->serial_in = kt_serial_in; 1144 port->port.serial_in = kt_serial_in;
1138 port->handle_break = kt_handle_break; 1145 port->port.handle_break = kt_handle_break;
1139 return skip_tx_en_setup(priv, board, port, idx); 1146 return skip_tx_en_setup(priv, board, port, idx);
1140} 1147}
1141 1148
@@ -1151,9 +1158,9 @@ static int pci_eg20t_init(struct pci_dev *dev)
1151static int 1158static int
1152pci_xr17c154_setup(struct serial_private *priv, 1159pci_xr17c154_setup(struct serial_private *priv,
1153 const struct pciserial_board *board, 1160 const struct pciserial_board *board,
1154 struct uart_port *port, int idx) 1161 struct uart_8250_port *port, int idx)
1155{ 1162{
1156 port->flags |= UPF_EXAR_EFR; 1163 port->port.flags |= UPF_EXAR_EFR;
1157 return pci_default_setup(priv, board, port, idx); 1164 return pci_default_setup(priv, board, port, idx);
1158} 1165}
1159 1166
@@ -1187,6 +1194,7 @@ pci_xr17c154_setup(struct serial_private *priv,
1187#define PCIE_DEVICE_ID_NEO_2_OX_IBM 0x00F6 1194#define PCIE_DEVICE_ID_NEO_2_OX_IBM 0x00F6
1188#define PCI_DEVICE_ID_PLX_CRONYX_OMEGA 0xc001 1195#define PCI_DEVICE_ID_PLX_CRONYX_OMEGA 0xc001
1189#define PCI_DEVICE_ID_INTEL_PATSBURG_KT 0x1d3d 1196#define PCI_DEVICE_ID_INTEL_PATSBURG_KT 0x1d3d
1197#define PCI_VENDOR_ID_ASIX 0x9710
1190 1198
1191/* Unknown vendors/cards - this should not be in linux/pci_ids.h */ 1199/* Unknown vendors/cards - this should not be in linux/pci_ids.h */
1192#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584 1200#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584
@@ -1726,7 +1734,17 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
1726 .subvendor = PCI_ANY_ID, 1734 .subvendor = PCI_ANY_ID,
1727 .subdevice = PCI_ANY_ID, 1735 .subdevice = PCI_ANY_ID,
1728 .setup = pci_omegapci_setup, 1736 .setup = pci_omegapci_setup,
1729 }, 1737 },
1738 /*
1739 * ASIX devices with FIFO bug
1740 */
1741 {
1742 .vendor = PCI_VENDOR_ID_ASIX,
1743 .device = PCI_ANY_ID,
1744 .subvendor = PCI_ANY_ID,
1745 .subdevice = PCI_ANY_ID,
1746 .setup = pci_asix_setup,
1747 },
1730 /* 1748 /*
1731 * Default "match everything" terminator entry 1749 * Default "match everything" terminator entry
1732 */ 1750 */
@@ -1887,7 +1905,6 @@ enum pci_board_num_t {
1887 pbn_panacom, 1905 pbn_panacom,
1888 pbn_panacom2, 1906 pbn_panacom2,
1889 pbn_panacom4, 1907 pbn_panacom4,
1890 pbn_exsys_4055,
1891 pbn_plx_romulus, 1908 pbn_plx_romulus,
1892 pbn_oxsemi, 1909 pbn_oxsemi,
1893 pbn_oxsemi_1_4000000, 1910 pbn_oxsemi_1_4000000,
@@ -2393,13 +2410,6 @@ static struct pciserial_board pci_boards[] __devinitdata = {
2393 .reg_shift = 7, 2410 .reg_shift = 7,
2394 }, 2411 },
2395 2412
2396 [pbn_exsys_4055] = {
2397 .flags = FL_BASE2,
2398 .num_ports = 4,
2399 .base_baud = 115200,
2400 .uart_offset = 8,
2401 },
2402
2403 /* I think this entry is broken - the first_offset looks wrong --rmk */ 2413 /* I think this entry is broken - the first_offset looks wrong --rmk */
2404 [pbn_plx_romulus] = { 2414 [pbn_plx_romulus] = {
2405 .flags = FL_BASE2, 2415 .flags = FL_BASE2,
@@ -2728,7 +2738,7 @@ serial_pci_matches(const struct pciserial_board *board,
2728struct serial_private * 2738struct serial_private *
2729pciserial_init_ports(struct pci_dev *dev, const struct pciserial_board *board) 2739pciserial_init_ports(struct pci_dev *dev, const struct pciserial_board *board)
2730{ 2740{
2731 struct uart_port serial_port; 2741 struct uart_8250_port uart;
2732 struct serial_private *priv; 2742 struct serial_private *priv;
2733 struct pci_serial_quirk *quirk; 2743 struct pci_serial_quirk *quirk;
2734 int rc, nr_ports, i; 2744 int rc, nr_ports, i;
@@ -2768,22 +2778,22 @@ pciserial_init_ports(struct pci_dev *dev, const struct pciserial_board *board)
2768 priv->dev = dev; 2778 priv->dev = dev;
2769 priv->quirk = quirk; 2779 priv->quirk = quirk;
2770 2780
2771 memset(&serial_port, 0, sizeof(struct uart_port)); 2781 memset(&uart, 0, sizeof(uart));
2772 serial_port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ; 2782 uart.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
2773 serial_port.uartclk = board->base_baud * 16; 2783 uart.port.uartclk = board->base_baud * 16;
2774 serial_port.irq = get_pci_irq(dev, board); 2784 uart.port.irq = get_pci_irq(dev, board);
2775 serial_port.dev = &dev->dev; 2785 uart.port.dev = &dev->dev;
2776 2786
2777 for (i = 0; i < nr_ports; i++) { 2787 for (i = 0; i < nr_ports; i++) {
2778 if (quirk->setup(priv, board, &serial_port, i)) 2788 if (quirk->setup(priv, board, &uart, i))
2779 break; 2789 break;
2780 2790
2781#ifdef SERIAL_DEBUG_PCI 2791#ifdef SERIAL_DEBUG_PCI
2782 printk(KERN_DEBUG "Setup PCI port: port %lx, irq %d, type %d\n", 2792 printk(KERN_DEBUG "Setup PCI port: port %lx, irq %d, type %d\n",
2783 serial_port.iobase, serial_port.irq, serial_port.iotype); 2793 uart.port.iobase, uart.port.irq, uart.port.iotype);
2784#endif 2794#endif
2785 2795
2786 priv->line[i] = serial8250_register_port(&serial_port); 2796 priv->line[i] = serial8250_register_8250_port(&uart);
2787 if (priv->line[i] < 0) { 2797 if (priv->line[i] < 0) {
2788 printk(KERN_WARNING "Couldn't register serial port %s: %d\n", pci_name(dev), priv->line[i]); 2798 printk(KERN_WARNING "Couldn't register serial port %s: %d\n", pci_name(dev), priv->line[i]);
2789 break; 2799 break;
@@ -3193,7 +3203,7 @@ static struct pci_device_id serial_pci_tbl[] = {
3193 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, 3203 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
3194 PCI_SUBVENDOR_ID_EXSYS, 3204 PCI_SUBVENDOR_ID_EXSYS,
3195 PCI_SUBDEVICE_ID_EXSYS_4055, 0, 0, 3205 PCI_SUBDEVICE_ID_EXSYS_4055, 0, 0,
3196 pbn_exsys_4055 }, 3206 pbn_b2_4_115200 },
3197 /* 3207 /*
3198 * Megawolf Romulus PCI Serial Card, from Mike Hudson 3208 * Megawolf Romulus PCI Serial Card, from Mike Hudson
3199 * (Exoray@isys.ca) 3209 * (Exoray@isys.ca)
diff --git a/drivers/tty/serial/8250/8250_pnp.c b/drivers/tty/serial/8250/8250_pnp.c
index a2f236510ff1..fde5aa60d51e 100644
--- a/drivers/tty/serial/8250/8250_pnp.c
+++ b/drivers/tty/serial/8250/8250_pnp.c
@@ -424,7 +424,7 @@ static int __devinit serial_pnp_guess_board(struct pnp_dev *dev, int *flags)
424static int __devinit 424static int __devinit
425serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) 425serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
426{ 426{
427 struct uart_port port; 427 struct uart_8250_port uart;
428 int ret, line, flags = dev_id->driver_data; 428 int ret, line, flags = dev_id->driver_data;
429 429
430 if (flags & UNKNOWN_DEV) { 430 if (flags & UNKNOWN_DEV) {
@@ -433,32 +433,32 @@ serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
433 return ret; 433 return ret;
434 } 434 }
435 435
436 memset(&port, 0, sizeof(struct uart_port)); 436 memset(&uart, 0, sizeof(uart));
437 if (pnp_irq_valid(dev, 0)) 437 if (pnp_irq_valid(dev, 0))
438 port.irq = pnp_irq(dev, 0); 438 uart.port.irq = pnp_irq(dev, 0);
439 if (pnp_port_valid(dev, 0)) { 439 if (pnp_port_valid(dev, 0)) {
440 port.iobase = pnp_port_start(dev, 0); 440 uart.port.iobase = pnp_port_start(dev, 0);
441 port.iotype = UPIO_PORT; 441 uart.port.iotype = UPIO_PORT;
442 } else if (pnp_mem_valid(dev, 0)) { 442 } else if (pnp_mem_valid(dev, 0)) {
443 port.mapbase = pnp_mem_start(dev, 0); 443 uart.port.mapbase = pnp_mem_start(dev, 0);
444 port.iotype = UPIO_MEM; 444 uart.port.iotype = UPIO_MEM;
445 port.flags = UPF_IOREMAP; 445 uart.port.flags = UPF_IOREMAP;
446 } else 446 } else
447 return -ENODEV; 447 return -ENODEV;
448 448
449#ifdef SERIAL_DEBUG_PNP 449#ifdef SERIAL_DEBUG_PNP
450 printk(KERN_DEBUG 450 printk(KERN_DEBUG
451 "Setup PNP port: port %x, mem 0x%lx, irq %d, type %d\n", 451 "Setup PNP port: port %x, mem 0x%lx, irq %d, type %d\n",
452 port.iobase, port.mapbase, port.irq, port.iotype); 452 uart.port.iobase, uart.port.mapbase, uart.port.irq, uart.port.iotype);
453#endif 453#endif
454 454
455 port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; 455 uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
456 if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE) 456 if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE)
457 port.flags |= UPF_SHARE_IRQ; 457 uart.port.flags |= UPF_SHARE_IRQ;
458 port.uartclk = 1843200; 458 uart.port.uartclk = 1843200;
459 port.dev = &dev->dev; 459 uart.port.dev = &dev->dev;
460 460
461 line = serial8250_register_port(&port); 461 line = serial8250_register_8250_port(&uart);
462 if (line < 0) 462 if (line < 0)
463 return -ENODEV; 463 return -ENODEV;
464 464
diff --git a/drivers/tty/serial/8250/serial_cs.c b/drivers/tty/serial/8250/serial_cs.c
index 29b695d041ec..b7d48b346393 100644
--- a/drivers/tty/serial/8250/serial_cs.c
+++ b/drivers/tty/serial/8250/serial_cs.c
@@ -73,7 +73,7 @@ struct serial_quirk {
73 unsigned int prodid; 73 unsigned int prodid;
74 int multi; /* 1 = multifunction, > 1 = # ports */ 74 int multi; /* 1 = multifunction, > 1 = # ports */
75 void (*config)(struct pcmcia_device *); 75 void (*config)(struct pcmcia_device *);
76 void (*setup)(struct pcmcia_device *, struct uart_port *); 76 void (*setup)(struct pcmcia_device *, struct uart_8250_port *);
77 void (*wakeup)(struct pcmcia_device *); 77 void (*wakeup)(struct pcmcia_device *);
78 int (*post)(struct pcmcia_device *); 78 int (*post)(struct pcmcia_device *);
79}; 79};
@@ -105,9 +105,9 @@ struct serial_cfg_mem {
105 * Elan VPU16551 UART with 14.7456MHz oscillator 105 * Elan VPU16551 UART with 14.7456MHz oscillator
106 * manfid 0x015D, 0x4C45 106 * manfid 0x015D, 0x4C45
107 */ 107 */
108static void quirk_setup_brainboxes_0104(struct pcmcia_device *link, struct uart_port *port) 108static void quirk_setup_brainboxes_0104(struct pcmcia_device *link, struct uart_8250_port *uart)
109{ 109{
110 port->uartclk = 14745600; 110 uart->port.uartclk = 14745600;
111} 111}
112 112
113static int quirk_post_ibm(struct pcmcia_device *link) 113static int quirk_post_ibm(struct pcmcia_device *link)
@@ -343,25 +343,25 @@ static void serial_detach(struct pcmcia_device *link)
343static int setup_serial(struct pcmcia_device *handle, struct serial_info * info, 343static int setup_serial(struct pcmcia_device *handle, struct serial_info * info,
344 unsigned int iobase, int irq) 344 unsigned int iobase, int irq)
345{ 345{
346 struct uart_port port; 346 struct uart_8250_port uart;
347 int line; 347 int line;
348 348
349 memset(&port, 0, sizeof (struct uart_port)); 349 memset(&uart, 0, sizeof(uart));
350 port.iobase = iobase; 350 uart.port.iobase = iobase;
351 port.irq = irq; 351 uart.port.irq = irq;
352 port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_SHARE_IRQ; 352 uart.port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_SHARE_IRQ;
353 port.uartclk = 1843200; 353 uart.port.uartclk = 1843200;
354 port.dev = &handle->dev; 354 uart.port.dev = &handle->dev;
355 if (buggy_uart) 355 if (buggy_uart)
356 port.flags |= UPF_BUGGY_UART; 356 uart.port.flags |= UPF_BUGGY_UART;
357 357
358 if (info->quirk && info->quirk->setup) 358 if (info->quirk && info->quirk->setup)
359 info->quirk->setup(handle, &port); 359 info->quirk->setup(handle, &uart);
360 360
361 line = serial8250_register_port(&port); 361 line = serial8250_register_8250_port(&uart);
362 if (line < 0) { 362 if (line < 0) {
363 printk(KERN_NOTICE "serial_cs: serial8250_register_port() at " 363 pr_err("serial_cs: serial8250_register_8250_port() at 0x%04lx, irq %d failed\n",
364 "0x%04lx, irq %d failed\n", (u_long)iobase, irq); 364 (unsigned long)iobase, irq);
365 return -EINVAL; 365 return -EINVAL;
366 } 366 }
367 367
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 070b442c1f81..00207865ec55 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -704,6 +704,25 @@ config SERIAL_PNX8XXX_CONSOLE
704 If you have a MIPS-based Philips SoC such as PNX8550 or PNX8330 704 If you have a MIPS-based Philips SoC such as PNX8550 or PNX8330
705 and you want to use serial console, say Y. Otherwise, say N. 705 and you want to use serial console, say Y. Otherwise, say N.
706 706
707config SERIAL_HS_LPC32XX
708 tristate "LPC32XX high speed serial port support"
709 depends on ARCH_LPC32XX && OF
710 select SERIAL_CORE
711 help
712 Support for the LPC32XX high speed serial ports (up to 900kbps).
713 Those are UARTs completely different from the Standard UARTs on the
714 LPC32XX SoC.
715 Choose M or Y here to build this driver.
716
717config SERIAL_HS_LPC32XX_CONSOLE
718 bool "Enable LPC32XX high speed UART serial console"
719 depends on SERIAL_HS_LPC32XX
720 select SERIAL_CORE_CONSOLE
721 help
722 If you would like to be able to use one of the high speed serial
723 ports on the LPC32XX as the console, you can do so by answering
724 Y to this option.
725
707config SERIAL_CORE 726config SERIAL_CORE
708 tristate 727 tristate
709 728
diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
index 7257c5d898ae..8a5df3804e5f 100644
--- a/drivers/tty/serial/Makefile
+++ b/drivers/tty/serial/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_SERIAL_MUX) += mux.o
34obj-$(CONFIG_SERIAL_68328) += 68328serial.o 34obj-$(CONFIG_SERIAL_68328) += 68328serial.o
35obj-$(CONFIG_SERIAL_MCF) += mcf.o 35obj-$(CONFIG_SERIAL_MCF) += mcf.o
36obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o 36obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o
37obj-$(CONFIG_SERIAL_HS_LPC32XX) += lpc32xx_hs.o
37obj-$(CONFIG_SERIAL_DZ) += dz.o 38obj-$(CONFIG_SERIAL_DZ) += dz.o
38obj-$(CONFIG_SERIAL_ZS) += zs.o 39obj-$(CONFIG_SERIAL_ZS) += zs.o
39obj-$(CONFIG_SERIAL_SH_SCI) += sh-sci.o 40obj-$(CONFIG_SERIAL_SH_SCI) += sh-sci.o
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index c17923ec6e95..b81cc31f2657 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -1215,14 +1215,14 @@ static irqreturn_t pl011_int(int irq, void *dev_id)
1215 return IRQ_RETVAL(handled); 1215 return IRQ_RETVAL(handled);
1216} 1216}
1217 1217
1218static unsigned int pl01x_tx_empty(struct uart_port *port) 1218static unsigned int pl011_tx_empty(struct uart_port *port)
1219{ 1219{
1220 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1220 struct uart_amba_port *uap = (struct uart_amba_port *)port;
1221 unsigned int status = readw(uap->port.membase + UART01x_FR); 1221 unsigned int status = readw(uap->port.membase + UART01x_FR);
1222 return status & (UART01x_FR_BUSY|UART01x_FR_TXFF) ? 0 : TIOCSER_TEMT; 1222 return status & (UART01x_FR_BUSY|UART01x_FR_TXFF) ? 0 : TIOCSER_TEMT;
1223} 1223}
1224 1224
1225static unsigned int pl01x_get_mctrl(struct uart_port *port) 1225static unsigned int pl011_get_mctrl(struct uart_port *port)
1226{ 1226{
1227 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1227 struct uart_amba_port *uap = (struct uart_amba_port *)port;
1228 unsigned int result = 0; 1228 unsigned int result = 0;
@@ -1285,7 +1285,7 @@ static void pl011_break_ctl(struct uart_port *port, int break_state)
1285} 1285}
1286 1286
1287#ifdef CONFIG_CONSOLE_POLL 1287#ifdef CONFIG_CONSOLE_POLL
1288static int pl010_get_poll_char(struct uart_port *port) 1288static int pl011_get_poll_char(struct uart_port *port)
1289{ 1289{
1290 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1290 struct uart_amba_port *uap = (struct uart_amba_port *)port;
1291 unsigned int status; 1291 unsigned int status;
@@ -1297,7 +1297,7 @@ static int pl010_get_poll_char(struct uart_port *port)
1297 return readw(uap->port.membase + UART01x_DR); 1297 return readw(uap->port.membase + UART01x_DR);
1298} 1298}
1299 1299
1300static void pl010_put_poll_char(struct uart_port *port, 1300static void pl011_put_poll_char(struct uart_port *port,
1301 unsigned char ch) 1301 unsigned char ch)
1302{ 1302{
1303 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1303 struct uart_amba_port *uap = (struct uart_amba_port *)port;
@@ -1637,7 +1637,7 @@ static const char *pl011_type(struct uart_port *port)
1637/* 1637/*
1638 * Release the memory region(s) being used by 'port' 1638 * Release the memory region(s) being used by 'port'
1639 */ 1639 */
1640static void pl010_release_port(struct uart_port *port) 1640static void pl011_release_port(struct uart_port *port)
1641{ 1641{
1642 release_mem_region(port->mapbase, SZ_4K); 1642 release_mem_region(port->mapbase, SZ_4K);
1643} 1643}
@@ -1645,7 +1645,7 @@ static void pl010_release_port(struct uart_port *port)
1645/* 1645/*
1646 * Request the memory region(s) being used by 'port' 1646 * Request the memory region(s) being used by 'port'
1647 */ 1647 */
1648static int pl010_request_port(struct uart_port *port) 1648static int pl011_request_port(struct uart_port *port)
1649{ 1649{
1650 return request_mem_region(port->mapbase, SZ_4K, "uart-pl011") 1650 return request_mem_region(port->mapbase, SZ_4K, "uart-pl011")
1651 != NULL ? 0 : -EBUSY; 1651 != NULL ? 0 : -EBUSY;
@@ -1654,18 +1654,18 @@ static int pl010_request_port(struct uart_port *port)
1654/* 1654/*
1655 * Configure/autoconfigure the port. 1655 * Configure/autoconfigure the port.
1656 */ 1656 */
1657static void pl010_config_port(struct uart_port *port, int flags) 1657static void pl011_config_port(struct uart_port *port, int flags)
1658{ 1658{
1659 if (flags & UART_CONFIG_TYPE) { 1659 if (flags & UART_CONFIG_TYPE) {
1660 port->type = PORT_AMBA; 1660 port->type = PORT_AMBA;
1661 pl010_request_port(port); 1661 pl011_request_port(port);
1662 } 1662 }
1663} 1663}
1664 1664
1665/* 1665/*
1666 * verify the new serial_struct (for TIOCSSERIAL). 1666 * verify the new serial_struct (for TIOCSSERIAL).
1667 */ 1667 */
1668static int pl010_verify_port(struct uart_port *port, struct serial_struct *ser) 1668static int pl011_verify_port(struct uart_port *port, struct serial_struct *ser)
1669{ 1669{
1670 int ret = 0; 1670 int ret = 0;
1671 if (ser->type != PORT_UNKNOWN && ser->type != PORT_AMBA) 1671 if (ser->type != PORT_UNKNOWN && ser->type != PORT_AMBA)
@@ -1678,9 +1678,9 @@ static int pl010_verify_port(struct uart_port *port, struct serial_struct *ser)
1678} 1678}
1679 1679
1680static struct uart_ops amba_pl011_pops = { 1680static struct uart_ops amba_pl011_pops = {
1681 .tx_empty = pl01x_tx_empty, 1681 .tx_empty = pl011_tx_empty,
1682 .set_mctrl = pl011_set_mctrl, 1682 .set_mctrl = pl011_set_mctrl,
1683 .get_mctrl = pl01x_get_mctrl, 1683 .get_mctrl = pl011_get_mctrl,
1684 .stop_tx = pl011_stop_tx, 1684 .stop_tx = pl011_stop_tx,
1685 .start_tx = pl011_start_tx, 1685 .start_tx = pl011_start_tx,
1686 .stop_rx = pl011_stop_rx, 1686 .stop_rx = pl011_stop_rx,
@@ -1691,13 +1691,13 @@ static struct uart_ops amba_pl011_pops = {
1691 .flush_buffer = pl011_dma_flush_buffer, 1691 .flush_buffer = pl011_dma_flush_buffer,
1692 .set_termios = pl011_set_termios, 1692 .set_termios = pl011_set_termios,
1693 .type = pl011_type, 1693 .type = pl011_type,
1694 .release_port = pl010_release_port, 1694 .release_port = pl011_release_port,
1695 .request_port = pl010_request_port, 1695 .request_port = pl011_request_port,
1696 .config_port = pl010_config_port, 1696 .config_port = pl011_config_port,
1697 .verify_port = pl010_verify_port, 1697 .verify_port = pl011_verify_port,
1698#ifdef CONFIG_CONSOLE_POLL 1698#ifdef CONFIG_CONSOLE_POLL
1699 .poll_get_char = pl010_get_poll_char, 1699 .poll_get_char = pl011_get_poll_char,
1700 .poll_put_char = pl010_put_poll_char, 1700 .poll_put_char = pl011_put_poll_char,
1701#endif 1701#endif
1702}; 1702};
1703 1703
diff --git a/drivers/tty/serial/crisv10.c b/drivers/tty/serial/crisv10.c
index 80b6b1b1f725..7264d4d26717 100644
--- a/drivers/tty/serial/crisv10.c
+++ b/drivers/tty/serial/crisv10.c
@@ -3976,7 +3976,7 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
3976 */ 3976 */
3977 if (tty_hung_up_p(filp) || 3977 if (tty_hung_up_p(filp) ||
3978 (info->flags & ASYNC_CLOSING)) { 3978 (info->flags & ASYNC_CLOSING)) {
3979 wait_event_interruptible_tty(info->close_wait, 3979 wait_event_interruptible_tty(tty, info->close_wait,
3980 !(info->flags & ASYNC_CLOSING)); 3980 !(info->flags & ASYNC_CLOSING));
3981#ifdef SERIAL_DO_RESTART 3981#ifdef SERIAL_DO_RESTART
3982 if (info->flags & ASYNC_HUP_NOTIFY) 3982 if (info->flags & ASYNC_HUP_NOTIFY)
@@ -4052,9 +4052,9 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
4052 printk("block_til_ready blocking: ttyS%d, count = %d\n", 4052 printk("block_til_ready blocking: ttyS%d, count = %d\n",
4053 info->line, info->count); 4053 info->line, info->count);
4054#endif 4054#endif
4055 tty_unlock(); 4055 tty_unlock(tty);
4056 schedule(); 4056 schedule();
4057 tty_lock(); 4057 tty_lock(tty);
4058 } 4058 }
4059 set_current_state(TASK_RUNNING); 4059 set_current_state(TASK_RUNNING);
4060 remove_wait_queue(&info->open_wait, &wait); 4060 remove_wait_queue(&info->open_wait, &wait);
@@ -4115,7 +4115,7 @@ rs_open(struct tty_struct *tty, struct file * filp)
4115 */ 4115 */
4116 if (tty_hung_up_p(filp) || 4116 if (tty_hung_up_p(filp) ||
4117 (info->flags & ASYNC_CLOSING)) { 4117 (info->flags & ASYNC_CLOSING)) {
4118 wait_event_interruptible_tty(info->close_wait, 4118 wait_event_interruptible_tty(tty, info->close_wait,
4119 !(info->flags & ASYNC_CLOSING)); 4119 !(info->flags & ASYNC_CLOSING));
4120#ifdef SERIAL_DO_RESTART 4120#ifdef SERIAL_DO_RESTART
4121 return ((info->flags & ASYNC_HUP_NOTIFY) ? 4121 return ((info->flags & ASYNC_HUP_NOTIFY) ?
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 4ef747307ecb..0af4eec8c7b1 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -207,7 +207,7 @@ struct imx_port {
207 unsigned short trcv_delay; /* transceiver delay */ 207 unsigned short trcv_delay; /* transceiver delay */
208 struct clk *clk_ipg; 208 struct clk *clk_ipg;
209 struct clk *clk_per; 209 struct clk *clk_per;
210 struct imx_uart_data *devdata; 210 const struct imx_uart_data *devdata;
211}; 211};
212 212
213struct imx_port_ucrs { 213struct imx_port_ucrs {
diff --git a/drivers/tty/serial/lpc32xx_hs.c b/drivers/tty/serial/lpc32xx_hs.c
new file mode 100644
index 000000000000..ba3af3bf6d43
--- /dev/null
+++ b/drivers/tty/serial/lpc32xx_hs.c
@@ -0,0 +1,823 @@
1/*
2 * High Speed Serial Ports on NXP LPC32xx SoC
3 *
4 * Authors: Kevin Wells <kevin.wells@nxp.com>
5 * Roland Stigge <stigge@antcom.de>
6 *
7 * Copyright (C) 2010 NXP Semiconductors
8 * Copyright (C) 2012 Roland Stigge
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/module.h>
22#include <linux/ioport.h>
23#include <linux/init.h>
24#include <linux/console.h>
25#include <linux/sysrq.h>
26#include <linux/tty.h>
27#include <linux/tty_flip.h>
28#include <linux/serial_core.h>
29#include <linux/serial.h>
30#include <linux/platform_device.h>
31#include <linux/delay.h>
32#include <linux/nmi.h>
33#include <linux/io.h>
34#include <linux/irq.h>
35#include <linux/gpio.h>
36#include <linux/of.h>
37#include <mach/platform.h>
38#include <mach/hardware.h>
39
40/*
41 * High Speed UART register offsets
42 */
43#define LPC32XX_HSUART_FIFO(x) ((x) + 0x00)
44#define LPC32XX_HSUART_LEVEL(x) ((x) + 0x04)
45#define LPC32XX_HSUART_IIR(x) ((x) + 0x08)
46#define LPC32XX_HSUART_CTRL(x) ((x) + 0x0C)
47#define LPC32XX_HSUART_RATE(x) ((x) + 0x10)
48
49#define LPC32XX_HSU_BREAK_DATA (1 << 10)
50#define LPC32XX_HSU_ERROR_DATA (1 << 9)
51#define LPC32XX_HSU_RX_EMPTY (1 << 8)
52
53#define LPC32XX_HSU_TX_LEV(n) (((n) >> 8) & 0xFF)
54#define LPC32XX_HSU_RX_LEV(n) ((n) & 0xFF)
55
56#define LPC32XX_HSU_TX_INT_SET (1 << 6)
57#define LPC32XX_HSU_RX_OE_INT (1 << 5)
58#define LPC32XX_HSU_BRK_INT (1 << 4)
59#define LPC32XX_HSU_FE_INT (1 << 3)
60#define LPC32XX_HSU_RX_TIMEOUT_INT (1 << 2)
61#define LPC32XX_HSU_RX_TRIG_INT (1 << 1)
62#define LPC32XX_HSU_TX_INT (1 << 0)
63
64#define LPC32XX_HSU_HRTS_INV (1 << 21)
65#define LPC32XX_HSU_HRTS_TRIG_8B (0x0 << 19)
66#define LPC32XX_HSU_HRTS_TRIG_16B (0x1 << 19)
67#define LPC32XX_HSU_HRTS_TRIG_32B (0x2 << 19)
68#define LPC32XX_HSU_HRTS_TRIG_48B (0x3 << 19)
69#define LPC32XX_HSU_HRTS_EN (1 << 18)
70#define LPC32XX_HSU_TMO_DISABLED (0x0 << 16)
71#define LPC32XX_HSU_TMO_INACT_4B (0x1 << 16)
72#define LPC32XX_HSU_TMO_INACT_8B (0x2 << 16)
73#define LPC32XX_HSU_TMO_INACT_16B (0x3 << 16)
74#define LPC32XX_HSU_HCTS_INV (1 << 15)
75#define LPC32XX_HSU_HCTS_EN (1 << 14)
76#define LPC32XX_HSU_OFFSET(n) ((n) << 9)
77#define LPC32XX_HSU_BREAK (1 << 8)
78#define LPC32XX_HSU_ERR_INT_EN (1 << 7)
79#define LPC32XX_HSU_RX_INT_EN (1 << 6)
80#define LPC32XX_HSU_TX_INT_EN (1 << 5)
81#define LPC32XX_HSU_RX_TL1B (0x0 << 2)
82#define LPC32XX_HSU_RX_TL4B (0x1 << 2)
83#define LPC32XX_HSU_RX_TL8B (0x2 << 2)
84#define LPC32XX_HSU_RX_TL16B (0x3 << 2)
85#define LPC32XX_HSU_RX_TL32B (0x4 << 2)
86#define LPC32XX_HSU_RX_TL48B (0x5 << 2)
87#define LPC32XX_HSU_TX_TLEMPTY (0x0 << 0)
88#define LPC32XX_HSU_TX_TL0B (0x0 << 0)
89#define LPC32XX_HSU_TX_TL4B (0x1 << 0)
90#define LPC32XX_HSU_TX_TL8B (0x2 << 0)
91#define LPC32XX_HSU_TX_TL16B (0x3 << 0)
92
93#define MODNAME "lpc32xx_hsuart"
94
95struct lpc32xx_hsuart_port {
96 struct uart_port port;
97};
98
99#define FIFO_READ_LIMIT 128
100#define MAX_PORTS 3
101#define LPC32XX_TTY_NAME "ttyTX"
102static struct lpc32xx_hsuart_port lpc32xx_hs_ports[MAX_PORTS];
103
104#ifdef CONFIG_SERIAL_HS_LPC32XX_CONSOLE
105static void wait_for_xmit_empty(struct uart_port *port)
106{
107 unsigned int timeout = 10000;
108
109 do {
110 if (LPC32XX_HSU_TX_LEV(readl(LPC32XX_HSUART_LEVEL(
111 port->membase))) == 0)
112 break;
113 if (--timeout == 0)
114 break;
115 udelay(1);
116 } while (1);
117}
118
119static void wait_for_xmit_ready(struct uart_port *port)
120{
121 unsigned int timeout = 10000;
122
123 while (1) {
124 if (LPC32XX_HSU_TX_LEV(readl(LPC32XX_HSUART_LEVEL(
125 port->membase))) < 32)
126 break;
127 if (--timeout == 0)
128 break;
129 udelay(1);
130 }
131}
132
133static void lpc32xx_hsuart_console_putchar(struct uart_port *port, int ch)
134{
135 wait_for_xmit_ready(port);
136 writel((u32)ch, LPC32XX_HSUART_FIFO(port->membase));
137}
138
139static void lpc32xx_hsuart_console_write(struct console *co, const char *s,
140 unsigned int count)
141{
142 struct lpc32xx_hsuart_port *up = &lpc32xx_hs_ports[co->index];
143 unsigned long flags;
144 int locked = 1;
145
146 touch_nmi_watchdog();
147 local_irq_save(flags);
148 if (up->port.sysrq)
149 locked = 0;
150 else if (oops_in_progress)
151 locked = spin_trylock(&up->port.lock);
152 else
153 spin_lock(&up->port.lock);
154
155 uart_console_write(&up->port, s, count, lpc32xx_hsuart_console_putchar);
156 wait_for_xmit_empty(&up->port);
157
158 if (locked)
159 spin_unlock(&up->port.lock);
160 local_irq_restore(flags);
161}
162
163static int __init lpc32xx_hsuart_console_setup(struct console *co,
164 char *options)
165{
166 struct uart_port *port;
167 int baud = 115200;
168 int bits = 8;
169 int parity = 'n';
170 int flow = 'n';
171
172 if (co->index >= MAX_PORTS)
173 co->index = 0;
174
175 port = &lpc32xx_hs_ports[co->index].port;
176 if (!port->membase)
177 return -ENODEV;
178
179 if (options)
180 uart_parse_options(options, &baud, &parity, &bits, &flow);
181
182 return uart_set_options(port, co, baud, parity, bits, flow);
183}
184
185static struct uart_driver lpc32xx_hsuart_reg;
186static struct console lpc32xx_hsuart_console = {
187 .name = LPC32XX_TTY_NAME,
188 .write = lpc32xx_hsuart_console_write,
189 .device = uart_console_device,
190 .setup = lpc32xx_hsuart_console_setup,
191 .flags = CON_PRINTBUFFER,
192 .index = -1,
193 .data = &lpc32xx_hsuart_reg,
194};
195
196static int __init lpc32xx_hsuart_console_init(void)
197{
198 register_console(&lpc32xx_hsuart_console);
199 return 0;
200}
201console_initcall(lpc32xx_hsuart_console_init);
202
203#define LPC32XX_HSUART_CONSOLE (&lpc32xx_hsuart_console)
204#else
205#define LPC32XX_HSUART_CONSOLE NULL
206#endif
207
208static struct uart_driver lpc32xx_hs_reg = {
209 .owner = THIS_MODULE,
210 .driver_name = MODNAME,
211 .dev_name = LPC32XX_TTY_NAME,
212 .nr = MAX_PORTS,
213 .cons = LPC32XX_HSUART_CONSOLE,
214};
215static int uarts_registered;
216
217static unsigned int __serial_get_clock_div(unsigned long uartclk,
218 unsigned long rate)
219{
220 u32 div, goodrate, hsu_rate, l_hsu_rate, comprate;
221 u32 rate_diff;
222
223 /* Find the closest divider to get the desired clock rate */
224 div = uartclk / rate;
225 goodrate = hsu_rate = (div / 14) - 1;
226 if (hsu_rate != 0)
227 hsu_rate--;
228
229 /* Tweak divider */
230 l_hsu_rate = hsu_rate + 3;
231 rate_diff = 0xFFFFFFFF;
232
233 while (hsu_rate < l_hsu_rate) {
234 comprate = uartclk / ((hsu_rate + 1) * 14);
235 if (abs(comprate - rate) < rate_diff) {
236 goodrate = hsu_rate;
237 rate_diff = abs(comprate - rate);
238 }
239
240 hsu_rate++;
241 }
242 if (hsu_rate > 0xFF)
243 hsu_rate = 0xFF;
244
245 return goodrate;
246}
247
248static void __serial_uart_flush(struct uart_port *port)
249{
250 u32 tmp;
251 int cnt = 0;
252
253 while ((readl(LPC32XX_HSUART_LEVEL(port->membase)) > 0) &&
254 (cnt++ < FIFO_READ_LIMIT))
255 tmp = readl(LPC32XX_HSUART_FIFO(port->membase));
256}
257
258static void __serial_lpc32xx_rx(struct uart_port *port)
259{
260 unsigned int tmp, flag;
261 struct tty_struct *tty = tty_port_tty_get(&port->state->port);
262
263 if (!tty) {
264 /* Discard data: no tty available */
265 while (!(readl(LPC32XX_HSUART_FIFO(port->membase)) &
266 LPC32XX_HSU_RX_EMPTY))
267 ;
268
269 return;
270 }
271
272 /* Read data from FIFO and push into terminal */
273 tmp = readl(LPC32XX_HSUART_FIFO(port->membase));
274 while (!(tmp & LPC32XX_HSU_RX_EMPTY)) {
275 flag = TTY_NORMAL;
276 port->icount.rx++;
277
278 if (tmp & LPC32XX_HSU_ERROR_DATA) {
279 /* Framing error */
280 writel(LPC32XX_HSU_FE_INT,
281 LPC32XX_HSUART_IIR(port->membase));
282 port->icount.frame++;
283 flag = TTY_FRAME;
284 tty_insert_flip_char(tty, 0, TTY_FRAME);
285 }
286
287 tty_insert_flip_char(tty, (tmp & 0xFF), flag);
288
289 tmp = readl(LPC32XX_HSUART_FIFO(port->membase));
290 }
291 tty_flip_buffer_push(tty);
292 tty_kref_put(tty);
293}
294
295static void __serial_lpc32xx_tx(struct uart_port *port)
296{
297 struct circ_buf *xmit = &port->state->xmit;
298 unsigned int tmp;
299
300 if (port->x_char) {
301 writel((u32)port->x_char, LPC32XX_HSUART_FIFO(port->membase));
302 port->icount.tx++;
303 port->x_char = 0;
304 return;
305 }
306
307 if (uart_circ_empty(xmit) || uart_tx_stopped(port))
308 goto exit_tx;
309
310 /* Transfer data */
311 while (LPC32XX_HSU_TX_LEV(readl(
312 LPC32XX_HSUART_LEVEL(port->membase))) < 64) {
313 writel((u32) xmit->buf[xmit->tail],
314 LPC32XX_HSUART_FIFO(port->membase));
315 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
316 port->icount.tx++;
317 if (uart_circ_empty(xmit))
318 break;
319 }
320
321 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
322 uart_write_wakeup(port);
323
324exit_tx:
325 if (uart_circ_empty(xmit)) {
326 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
327 tmp &= ~LPC32XX_HSU_TX_INT_EN;
328 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
329 }
330}
331
332static irqreturn_t serial_lpc32xx_interrupt(int irq, void *dev_id)
333{
334 struct uart_port *port = dev_id;
335 struct tty_struct *tty = tty_port_tty_get(&port->state->port);
336 u32 status;
337
338 spin_lock(&port->lock);
339
340 /* Read UART status and clear latched interrupts */
341 status = readl(LPC32XX_HSUART_IIR(port->membase));
342
343 if (status & LPC32XX_HSU_BRK_INT) {
344 /* Break received */
345 writel(LPC32XX_HSU_BRK_INT, LPC32XX_HSUART_IIR(port->membase));
346 port->icount.brk++;
347 uart_handle_break(port);
348 }
349
350 /* Framing error */
351 if (status & LPC32XX_HSU_FE_INT)
352 writel(LPC32XX_HSU_FE_INT, LPC32XX_HSUART_IIR(port->membase));
353
354 if (status & LPC32XX_HSU_RX_OE_INT) {
355 /* Receive FIFO overrun */
356 writel(LPC32XX_HSU_RX_OE_INT,
357 LPC32XX_HSUART_IIR(port->membase));
358 port->icount.overrun++;
359 if (tty) {
360 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
361 tty_schedule_flip(tty);
362 }
363 }
364
365 /* Data received? */
366 if (status & (LPC32XX_HSU_RX_TIMEOUT_INT | LPC32XX_HSU_RX_TRIG_INT)) {
367 __serial_lpc32xx_rx(port);
368 if (tty)
369 tty_flip_buffer_push(tty);
370 }
371
372 /* Transmit data request? */
373 if ((status & LPC32XX_HSU_TX_INT) && (!uart_tx_stopped(port))) {
374 writel(LPC32XX_HSU_TX_INT, LPC32XX_HSUART_IIR(port->membase));
375 __serial_lpc32xx_tx(port);
376 }
377
378 spin_unlock(&port->lock);
379 tty_kref_put(tty);
380
381 return IRQ_HANDLED;
382}
383
384/* port->lock is not held. */
385static unsigned int serial_lpc32xx_tx_empty(struct uart_port *port)
386{
387 unsigned int ret = 0;
388
389 if (LPC32XX_HSU_TX_LEV(readl(LPC32XX_HSUART_LEVEL(port->membase))) == 0)
390 ret = TIOCSER_TEMT;
391
392 return ret;
393}
394
395/* port->lock held by caller. */
396static void serial_lpc32xx_set_mctrl(struct uart_port *port,
397 unsigned int mctrl)
398{
399 /* No signals are supported on HS UARTs */
400}
401
402/* port->lock is held by caller and interrupts are disabled. */
403static unsigned int serial_lpc32xx_get_mctrl(struct uart_port *port)
404{
405 /* No signals are supported on HS UARTs */
406 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
407}
408
409/* port->lock held by caller. */
410static void serial_lpc32xx_stop_tx(struct uart_port *port)
411{
412 u32 tmp;
413
414 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
415 tmp &= ~LPC32XX_HSU_TX_INT_EN;
416 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
417}
418
419/* port->lock held by caller. */
420static void serial_lpc32xx_start_tx(struct uart_port *port)
421{
422 u32 tmp;
423
424 __serial_lpc32xx_tx(port);
425 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
426 tmp |= LPC32XX_HSU_TX_INT_EN;
427 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
428}
429
430/* port->lock held by caller. */
431static void serial_lpc32xx_stop_rx(struct uart_port *port)
432{
433 u32 tmp;
434
435 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
436 tmp &= ~(LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN);
437 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
438
439 writel((LPC32XX_HSU_BRK_INT | LPC32XX_HSU_RX_OE_INT |
440 LPC32XX_HSU_FE_INT), LPC32XX_HSUART_IIR(port->membase));
441}
442
443/* port->lock held by caller. */
444static void serial_lpc32xx_enable_ms(struct uart_port *port)
445{
446 /* Modem status is not supported */
447}
448
449/* port->lock is not held. */
450static void serial_lpc32xx_break_ctl(struct uart_port *port,
451 int break_state)
452{
453 unsigned long flags;
454 u32 tmp;
455
456 spin_lock_irqsave(&port->lock, flags);
457 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
458 if (break_state != 0)
459 tmp |= LPC32XX_HSU_BREAK;
460 else
461 tmp &= ~LPC32XX_HSU_BREAK;
462 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
463 spin_unlock_irqrestore(&port->lock, flags);
464}
465
466/* LPC3250 Errata HSUART.1: Hang workaround via loopback mode on inactivity */
467static void lpc32xx_loopback_set(resource_size_t mapbase, int state)
468{
469 int bit;
470 u32 tmp;
471
472 switch (mapbase) {
473 case LPC32XX_HS_UART1_BASE:
474 bit = 0;
475 break;
476 case LPC32XX_HS_UART2_BASE:
477 bit = 1;
478 break;
479 case LPC32XX_HS_UART7_BASE:
480 bit = 6;
481 break;
482 default:
483 WARN(1, "lpc32xx_hs: Warning: Unknown port at %08x\n", mapbase);
484 return;
485 }
486
487 tmp = readl(LPC32XX_UARTCTL_CLOOP);
488 if (state)
489 tmp |= (1 << bit);
490 else
491 tmp &= ~(1 << bit);
492 writel(tmp, LPC32XX_UARTCTL_CLOOP);
493}
494
495/* port->lock is not held. */
496static int serial_lpc32xx_startup(struct uart_port *port)
497{
498 int retval;
499 unsigned long flags;
500 u32 tmp;
501
502 spin_lock_irqsave(&port->lock, flags);
503
504 __serial_uart_flush(port);
505
506 writel((LPC32XX_HSU_TX_INT | LPC32XX_HSU_FE_INT |
507 LPC32XX_HSU_BRK_INT | LPC32XX_HSU_RX_OE_INT),
508 LPC32XX_HSUART_IIR(port->membase));
509
510 writel(0xFF, LPC32XX_HSUART_RATE(port->membase));
511
512 /*
513 * Set receiver timeout, HSU offset of 20, no break, no interrupts,
514 * and default FIFO trigger levels
515 */
516 tmp = LPC32XX_HSU_TX_TL8B | LPC32XX_HSU_RX_TL32B |
517 LPC32XX_HSU_OFFSET(20) | LPC32XX_HSU_TMO_INACT_4B;
518 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
519
520 lpc32xx_loopback_set(port->mapbase, 0); /* get out of loopback mode */
521
522 spin_unlock_irqrestore(&port->lock, flags);
523
524 retval = request_irq(port->irq, serial_lpc32xx_interrupt,
525 0, MODNAME, port);
526 if (!retval)
527 writel((tmp | LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN),
528 LPC32XX_HSUART_CTRL(port->membase));
529
530 return retval;
531}
532
533/* port->lock is not held. */
534static void serial_lpc32xx_shutdown(struct uart_port *port)
535{
536 u32 tmp;
537 unsigned long flags;
538
539 spin_lock_irqsave(&port->lock, flags);
540
541 tmp = LPC32XX_HSU_TX_TL8B | LPC32XX_HSU_RX_TL32B |
542 LPC32XX_HSU_OFFSET(20) | LPC32XX_HSU_TMO_INACT_4B;
543 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
544
545 lpc32xx_loopback_set(port->mapbase, 1); /* go to loopback mode */
546
547 spin_unlock_irqrestore(&port->lock, flags);
548
549 free_irq(port->irq, port);
550}
551
552/* port->lock is not held. */
553static void serial_lpc32xx_set_termios(struct uart_port *port,
554 struct ktermios *termios,
555 struct ktermios *old)
556{
557 unsigned long flags;
558 unsigned int baud, quot;
559 u32 tmp;
560
561 /* Always 8-bit, no parity, 1 stop bit */
562 termios->c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD);
563 termios->c_cflag |= CS8;
564
565 termios->c_cflag &= ~(HUPCL | CMSPAR | CLOCAL | CRTSCTS);
566
567 baud = uart_get_baud_rate(port, termios, old, 0,
568 port->uartclk / 14);
569
570 quot = __serial_get_clock_div(port->uartclk, baud);
571
572 spin_lock_irqsave(&port->lock, flags);
573
574 /* Ignore characters? */
575 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
576 if ((termios->c_cflag & CREAD) == 0)
577 tmp &= ~(LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN);
578 else
579 tmp |= LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN;
580 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
581
582 writel(quot, LPC32XX_HSUART_RATE(port->membase));
583
584 uart_update_timeout(port, termios->c_cflag, baud);
585
586 spin_unlock_irqrestore(&port->lock, flags);
587
588 /* Don't rewrite B0 */
589 if (tty_termios_baud_rate(termios))
590 tty_termios_encode_baud_rate(termios, baud, baud);
591}
592
593static const char *serial_lpc32xx_type(struct uart_port *port)
594{
595 return MODNAME;
596}
597
598static void serial_lpc32xx_release_port(struct uart_port *port)
599{
600 if ((port->iotype == UPIO_MEM32) && (port->mapbase)) {
601 if (port->flags & UPF_IOREMAP) {
602 iounmap(port->membase);
603 port->membase = NULL;
604 }
605
606 release_mem_region(port->mapbase, SZ_4K);
607 }
608}
609
610static int serial_lpc32xx_request_port(struct uart_port *port)
611{
612 int ret = -ENODEV;
613
614 if ((port->iotype == UPIO_MEM32) && (port->mapbase)) {
615 ret = 0;
616
617 if (!request_mem_region(port->mapbase, SZ_4K, MODNAME))
618 ret = -EBUSY;
619 else if (port->flags & UPF_IOREMAP) {
620 port->membase = ioremap(port->mapbase, SZ_4K);
621 if (!port->membase) {
622 release_mem_region(port->mapbase, SZ_4K);
623 ret = -ENOMEM;
624 }
625 }
626 }
627
628 return ret;
629}
630
631static void serial_lpc32xx_config_port(struct uart_port *port, int uflags)
632{
633 int ret;
634
635 ret = serial_lpc32xx_request_port(port);
636 if (ret < 0)
637 return;
638 port->type = PORT_UART00;
639 port->fifosize = 64;
640
641 __serial_uart_flush(port);
642
643 writel((LPC32XX_HSU_TX_INT | LPC32XX_HSU_FE_INT |
644 LPC32XX_HSU_BRK_INT | LPC32XX_HSU_RX_OE_INT),
645 LPC32XX_HSUART_IIR(port->membase));
646
647 writel(0xFF, LPC32XX_HSUART_RATE(port->membase));
648
649 /* Set receiver timeout, HSU offset of 20, no break, no interrupts,
650 and default FIFO trigger levels */
651 writel(LPC32XX_HSU_TX_TL8B | LPC32XX_HSU_RX_TL32B |
652 LPC32XX_HSU_OFFSET(20) | LPC32XX_HSU_TMO_INACT_4B,
653 LPC32XX_HSUART_CTRL(port->membase));
654}
655
656static int serial_lpc32xx_verify_port(struct uart_port *port,
657 struct serial_struct *ser)
658{
659 int ret = 0;
660
661 if (ser->type != PORT_UART00)
662 ret = -EINVAL;
663
664 return ret;
665}
666
667static struct uart_ops serial_lpc32xx_pops = {
668 .tx_empty = serial_lpc32xx_tx_empty,
669 .set_mctrl = serial_lpc32xx_set_mctrl,
670 .get_mctrl = serial_lpc32xx_get_mctrl,
671 .stop_tx = serial_lpc32xx_stop_tx,
672 .start_tx = serial_lpc32xx_start_tx,
673 .stop_rx = serial_lpc32xx_stop_rx,
674 .enable_ms = serial_lpc32xx_enable_ms,
675 .break_ctl = serial_lpc32xx_break_ctl,
676 .startup = serial_lpc32xx_startup,
677 .shutdown = serial_lpc32xx_shutdown,
678 .set_termios = serial_lpc32xx_set_termios,
679 .type = serial_lpc32xx_type,
680 .release_port = serial_lpc32xx_release_port,
681 .request_port = serial_lpc32xx_request_port,
682 .config_port = serial_lpc32xx_config_port,
683 .verify_port = serial_lpc32xx_verify_port,
684};
685
686/*
687 * Register a set of serial devices attached to a platform device
688 */
689static int __devinit serial_hs_lpc32xx_probe(struct platform_device *pdev)
690{
691 struct lpc32xx_hsuart_port *p = &lpc32xx_hs_ports[uarts_registered];
692 int ret = 0;
693 struct resource *res;
694
695 if (uarts_registered >= MAX_PORTS) {
696 dev_err(&pdev->dev,
697 "Error: Number of possible ports exceeded (%d)!\n",
698 uarts_registered + 1);
699 return -ENXIO;
700 }
701
702 memset(p, 0, sizeof(*p));
703
704 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
705 if (!res) {
706 dev_err(&pdev->dev,
707 "Error getting mem resource for HS UART port %d\n",
708 uarts_registered);
709 return -ENXIO;
710 }
711 p->port.mapbase = res->start;
712 p->port.membase = NULL;
713
714 p->port.irq = platform_get_irq(pdev, 0);
715 if (p->port.irq < 0) {
716 dev_err(&pdev->dev, "Error getting irq for HS UART port %d\n",
717 uarts_registered);
718 return p->port.irq;
719 }
720
721 p->port.iotype = UPIO_MEM32;
722 p->port.uartclk = LPC32XX_MAIN_OSC_FREQ;
723 p->port.regshift = 2;
724 p->port.flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | UPF_IOREMAP;
725 p->port.dev = &pdev->dev;
726 p->port.ops = &serial_lpc32xx_pops;
727 p->port.line = uarts_registered++;
728 spin_lock_init(&p->port.lock);
729
730 /* send port to loopback mode by default */
731 lpc32xx_loopback_set(p->port.mapbase, 1);
732
733 ret = uart_add_one_port(&lpc32xx_hs_reg, &p->port);
734
735 platform_set_drvdata(pdev, p);
736
737 return ret;
738}
739
740/*
741 * Remove serial ports registered against a platform device.
742 */
743static int __devexit serial_hs_lpc32xx_remove(struct platform_device *pdev)
744{
745 struct lpc32xx_hsuart_port *p = platform_get_drvdata(pdev);
746
747 uart_remove_one_port(&lpc32xx_hs_reg, &p->port);
748
749 return 0;
750}
751
752
753#ifdef CONFIG_PM
754static int serial_hs_lpc32xx_suspend(struct platform_device *pdev,
755 pm_message_t state)
756{
757 struct lpc32xx_hsuart_port *p = platform_get_drvdata(pdev);
758
759 uart_suspend_port(&lpc32xx_hs_reg, &p->port);
760
761 return 0;
762}
763
764static int serial_hs_lpc32xx_resume(struct platform_device *pdev)
765{
766 struct lpc32xx_hsuart_port *p = platform_get_drvdata(pdev);
767
768 uart_resume_port(&lpc32xx_hs_reg, &p->port);
769
770 return 0;
771}
772#else
773#define serial_hs_lpc32xx_suspend NULL
774#define serial_hs_lpc32xx_resume NULL
775#endif
776
777static const struct of_device_id serial_hs_lpc32xx_dt_ids[] = {
778 { .compatible = "nxp,lpc3220-hsuart" },
779 { /* sentinel */ }
780};
781
782MODULE_DEVICE_TABLE(of, serial_hs_lpc32xx_dt_ids);
783
784static struct platform_driver serial_hs_lpc32xx_driver = {
785 .probe = serial_hs_lpc32xx_probe,
786 .remove = __devexit_p(serial_hs_lpc32xx_remove),
787 .suspend = serial_hs_lpc32xx_suspend,
788 .resume = serial_hs_lpc32xx_resume,
789 .driver = {
790 .name = MODNAME,
791 .owner = THIS_MODULE,
792 .of_match_table = serial_hs_lpc32xx_dt_ids,
793 },
794};
795
796static int __init lpc32xx_hsuart_init(void)
797{
798 int ret;
799
800 ret = uart_register_driver(&lpc32xx_hs_reg);
801 if (ret)
802 return ret;
803
804 ret = platform_driver_register(&serial_hs_lpc32xx_driver);
805 if (ret)
806 uart_unregister_driver(&lpc32xx_hs_reg);
807
808 return ret;
809}
810
811static void __exit lpc32xx_hsuart_exit(void)
812{
813 platform_driver_unregister(&serial_hs_lpc32xx_driver);
814 uart_unregister_driver(&lpc32xx_hs_reg);
815}
816
817module_init(lpc32xx_hsuart_init);
818module_exit(lpc32xx_hsuart_exit);
819
820MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com>");
821MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
822MODULE_DESCRIPTION("NXP LPC32XX High Speed UART driver");
823MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index 5410c0637266..34e71874a892 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -208,6 +208,7 @@ static struct of_device_id __devinitdata of_platform_serial_table[] = {
208 { .compatible = "ns16750", .data = (void *)PORT_16750, }, 208 { .compatible = "ns16750", .data = (void *)PORT_16750, },
209 { .compatible = "ns16850", .data = (void *)PORT_16850, }, 209 { .compatible = "ns16850", .data = (void *)PORT_16850, },
210 { .compatible = "nvidia,tegra20-uart", .data = (void *)PORT_TEGRA, }, 210 { .compatible = "nvidia,tegra20-uart", .data = (void *)PORT_TEGRA, },
211 { .compatible = "nxp,lpc3220-uart", .data = (void *)PORT_LPC3220, },
211#ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL 212#ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL
212 { .compatible = "ibm,qpace-nwp-serial", 213 { .compatible = "ibm,qpace-nwp-serial",
213 .data = (void *)PORT_NWPSERIAL, }, 214 .data = (void *)PORT_NWPSERIAL, },
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index 4fdec6a6b758..d291518a58a4 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -253,6 +253,9 @@ struct eg20t_port {
253 dma_addr_t rx_buf_dma; 253 dma_addr_t rx_buf_dma;
254 254
255 struct dentry *debugfs; 255 struct dentry *debugfs;
256
257 /* protect the eg20t_port private structure and io access to membase */
258 spinlock_t lock;
256}; 259};
257 260
258/** 261/**
@@ -1058,7 +1061,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1058 int next = 1; 1061 int next = 1;
1059 u8 msr; 1062 u8 msr;
1060 1063
1061 spin_lock_irqsave(&priv->port.lock, flags); 1064 spin_lock_irqsave(&priv->lock, flags);
1062 handled = 0; 1065 handled = 0;
1063 while (next) { 1066 while (next) {
1064 iid = pch_uart_hal_get_iid(priv); 1067 iid = pch_uart_hal_get_iid(priv);
@@ -1116,7 +1119,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1116 handled |= (unsigned int)ret; 1119 handled |= (unsigned int)ret;
1117 } 1120 }
1118 1121
1119 spin_unlock_irqrestore(&priv->port.lock, flags); 1122 spin_unlock_irqrestore(&priv->lock, flags);
1120 return IRQ_RETVAL(handled); 1123 return IRQ_RETVAL(handled);
1121} 1124}
1122 1125
@@ -1226,9 +1229,9 @@ static void pch_uart_break_ctl(struct uart_port *port, int ctl)
1226 unsigned long flags; 1229 unsigned long flags;
1227 1230
1228 priv = container_of(port, struct eg20t_port, port); 1231 priv = container_of(port, struct eg20t_port, port);
1229 spin_lock_irqsave(&port->lock, flags); 1232 spin_lock_irqsave(&priv->lock, flags);
1230 pch_uart_hal_set_break(priv, ctl); 1233 pch_uart_hal_set_break(priv, ctl);
1231 spin_unlock_irqrestore(&port->lock, flags); 1234 spin_unlock_irqrestore(&priv->lock, flags);
1232} 1235}
1233 1236
1234/* Grab any interrupt resources and initialise any low level driver state. */ 1237/* Grab any interrupt resources and initialise any low level driver state. */
@@ -1376,7 +1379,8 @@ static void pch_uart_set_termios(struct uart_port *port,
1376 1379
1377 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); 1380 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
1378 1381
1379 spin_lock_irqsave(&port->lock, flags); 1382 spin_lock_irqsave(&priv->lock, flags);
1383 spin_lock(&port->lock);
1380 1384
1381 uart_update_timeout(port, termios->c_cflag, baud); 1385 uart_update_timeout(port, termios->c_cflag, baud);
1382 rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb); 1386 rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb);
@@ -1389,7 +1393,8 @@ static void pch_uart_set_termios(struct uart_port *port,
1389 tty_termios_encode_baud_rate(termios, baud, baud); 1393 tty_termios_encode_baud_rate(termios, baud, baud);
1390 1394
1391out: 1395out:
1392 spin_unlock_irqrestore(&port->lock, flags); 1396 spin_unlock(&port->lock);
1397 spin_unlock_irqrestore(&priv->lock, flags);
1393} 1398}
1394 1399
1395static const char *pch_uart_type(struct uart_port *port) 1400static const char *pch_uart_type(struct uart_port *port)
@@ -1538,8 +1543,9 @@ pch_console_write(struct console *co, const char *s, unsigned int count)
1538{ 1543{
1539 struct eg20t_port *priv; 1544 struct eg20t_port *priv;
1540 unsigned long flags; 1545 unsigned long flags;
1546 int priv_locked = 1;
1547 int port_locked = 1;
1541 u8 ier; 1548 u8 ier;
1542 int locked = 1;
1543 1549
1544 priv = pch_uart_ports[co->index]; 1550 priv = pch_uart_ports[co->index];
1545 1551
@@ -1547,12 +1553,16 @@ pch_console_write(struct console *co, const char *s, unsigned int count)
1547 1553
1548 local_irq_save(flags); 1554 local_irq_save(flags);
1549 if (priv->port.sysrq) { 1555 if (priv->port.sysrq) {
1550 /* serial8250_handle_port() already took the lock */ 1556 spin_lock(&priv->lock);
1551 locked = 0; 1557 /* serial8250_handle_port() already took the port lock */
1558 port_locked = 0;
1552 } else if (oops_in_progress) { 1559 } else if (oops_in_progress) {
1553 locked = spin_trylock(&priv->port.lock); 1560 priv_locked = spin_trylock(&priv->lock);
1554 } else 1561 port_locked = spin_trylock(&priv->port.lock);
1562 } else {
1563 spin_lock(&priv->lock);
1555 spin_lock(&priv->port.lock); 1564 spin_lock(&priv->port.lock);
1565 }
1556 1566
1557 /* 1567 /*
1558 * First save the IER then disable the interrupts 1568 * First save the IER then disable the interrupts
@@ -1570,8 +1580,10 @@ pch_console_write(struct console *co, const char *s, unsigned int count)
1570 wait_for_xmitr(priv, BOTH_EMPTY); 1580 wait_for_xmitr(priv, BOTH_EMPTY);
1571 iowrite8(ier, priv->membase + UART_IER); 1581 iowrite8(ier, priv->membase + UART_IER);
1572 1582
1573 if (locked) 1583 if (port_locked)
1574 spin_unlock(&priv->port.lock); 1584 spin_unlock(&priv->port.lock);
1585 if (priv_locked)
1586 spin_unlock(&priv->lock);
1575 local_irq_restore(flags); 1587 local_irq_restore(flags);
1576} 1588}
1577 1589
@@ -1669,6 +1681,8 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
1669 pci_enable_msi(pdev); 1681 pci_enable_msi(pdev);
1670 pci_set_master(pdev); 1682 pci_set_master(pdev);
1671 1683
1684 spin_lock_init(&priv->lock);
1685
1672 iobase = pci_resource_start(pdev, 0); 1686 iobase = pci_resource_start(pdev, 0);
1673 mapbase = pci_resource_start(pdev, 1); 1687 mapbase = pci_resource_start(pdev, 1);
1674 priv->mapbase = mapbase; 1688 priv->mapbase = mapbase;
diff --git a/drivers/tty/serial/pxa.c b/drivers/tty/serial/pxa.c
index 5847a4b855f7..9033fc6e0e4e 100644
--- a/drivers/tty/serial/pxa.c
+++ b/drivers/tty/serial/pxa.c
@@ -670,9 +670,19 @@ serial_pxa_console_write(struct console *co, const char *s, unsigned int count)
670{ 670{
671 struct uart_pxa_port *up = serial_pxa_ports[co->index]; 671 struct uart_pxa_port *up = serial_pxa_ports[co->index];
672 unsigned int ier; 672 unsigned int ier;
673 unsigned long flags;
674 int locked = 1;
673 675
674 clk_prepare_enable(up->clk); 676 clk_prepare_enable(up->clk);
675 677
678 local_irq_save(flags);
679 if (up->port.sysrq)
680 locked = 0;
681 else if (oops_in_progress)
682 locked = spin_trylock(&up->port.lock);
683 else
684 spin_lock(&up->port.lock);
685
676 /* 686 /*
677 * First save the IER then disable the interrupts 687 * First save the IER then disable the interrupts
678 */ 688 */
@@ -688,6 +698,10 @@ serial_pxa_console_write(struct console *co, const char *s, unsigned int count)
688 wait_for_xmitr(up); 698 wait_for_xmitr(up);
689 serial_out(up, UART_IER, ier); 699 serial_out(up, UART_IER, ier);
690 700
701 if (locked)
702 spin_unlock(&up->port.lock);
703 local_irq_restore(flags);
704
691 clk_disable_unprepare(up->clk); 705 clk_disable_unprepare(up->clk);
692} 706}
693 707
diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
index d8b0aee35632..d57f165d6be8 100644
--- a/drivers/tty/serial/samsung.c
+++ b/drivers/tty/serial/samsung.c
@@ -529,7 +529,7 @@ static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
529 529
530 switch (level) { 530 switch (level) {
531 case 3: 531 case 3:
532 if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL) 532 if (!IS_ERR(ourport->baudclk))
533 clk_disable(ourport->baudclk); 533 clk_disable(ourport->baudclk);
534 534
535 clk_disable(ourport->clk); 535 clk_disable(ourport->clk);
@@ -538,7 +538,7 @@ static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
538 case 0: 538 case 0:
539 clk_enable(ourport->clk); 539 clk_enable(ourport->clk);
540 540
541 if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL) 541 if (!IS_ERR(ourport->baudclk))
542 clk_enable(ourport->baudclk); 542 clk_enable(ourport->baudclk);
543 543
544 break; 544 break;
@@ -604,7 +604,6 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
604 char clkname[MAX_CLK_NAME_LENGTH]; 604 char clkname[MAX_CLK_NAME_LENGTH];
605 int calc_deviation, deviation = (1 << 30) - 1; 605 int calc_deviation, deviation = (1 << 30) - 1;
606 606
607 *best_clk = NULL;
608 clk_sel = (ourport->cfg->clk_sel) ? ourport->cfg->clk_sel : 607 clk_sel = (ourport->cfg->clk_sel) ? ourport->cfg->clk_sel :
609 ourport->info->def_clk_sel; 608 ourport->info->def_clk_sel;
610 for (cnt = 0; cnt < info->num_clks; cnt++) { 609 for (cnt = 0; cnt < info->num_clks; cnt++) {
@@ -613,7 +612,7 @@ static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
613 612
614 sprintf(clkname, "clk_uart_baud%d", cnt); 613 sprintf(clkname, "clk_uart_baud%d", cnt);
615 clk = clk_get(ourport->port.dev, clkname); 614 clk = clk_get(ourport->port.dev, clkname);
616 if (IS_ERR_OR_NULL(clk)) 615 if (IS_ERR(clk))
617 continue; 616 continue;
618 617
619 rate = clk_get_rate(clk); 618 rate = clk_get_rate(clk);
@@ -684,7 +683,7 @@ static void s3c24xx_serial_set_termios(struct uart_port *port,
684{ 683{
685 struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port); 684 struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
686 struct s3c24xx_uart_port *ourport = to_ourport(port); 685 struct s3c24xx_uart_port *ourport = to_ourport(port);
687 struct clk *clk = NULL; 686 struct clk *clk = ERR_PTR(-EINVAL);
688 unsigned long flags; 687 unsigned long flags;
689 unsigned int baud, quot, clk_sel = 0; 688 unsigned int baud, quot, clk_sel = 0;
690 unsigned int ulcon; 689 unsigned int ulcon;
@@ -705,7 +704,7 @@ static void s3c24xx_serial_set_termios(struct uart_port *port,
705 quot = s3c24xx_serial_getclk(ourport, baud, &clk, &clk_sel); 704 quot = s3c24xx_serial_getclk(ourport, baud, &clk, &clk_sel);
706 if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) 705 if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
707 quot = port->custom_divisor; 706 quot = port->custom_divisor;
708 if (!clk) 707 if (IS_ERR(clk))
709 return; 708 return;
710 709
711 /* check to see if we need to change clock source */ 710 /* check to see if we need to change clock source */
@@ -713,9 +712,9 @@ static void s3c24xx_serial_set_termios(struct uart_port *port,
713 if (ourport->baudclk != clk) { 712 if (ourport->baudclk != clk) {
714 s3c24xx_serial_setsource(port, clk_sel); 713 s3c24xx_serial_setsource(port, clk_sel);
715 714
716 if (ourport->baudclk != NULL && !IS_ERR(ourport->baudclk)) { 715 if (!IS_ERR(ourport->baudclk)) {
717 clk_disable(ourport->baudclk); 716 clk_disable(ourport->baudclk);
718 ourport->baudclk = NULL; 717 ourport->baudclk = ERR_PTR(-EINVAL);
719 } 718 }
720 719
721 clk_enable(clk); 720 clk_enable(clk);
@@ -1014,10 +1013,10 @@ static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb,
1014 * a disturbance in the clock-rate over the change. 1013 * a disturbance in the clock-rate over the change.
1015 */ 1014 */
1016 1015
1017 if (IS_ERR(port->clk)) 1016 if (IS_ERR(port->baudclk))
1018 goto exit; 1017 goto exit;
1019 1018
1020 if (port->baudclk_rate == clk_get_rate(port->clk)) 1019 if (port->baudclk_rate == clk_get_rate(port->baudclk))
1021 goto exit; 1020 goto exit;
1022 1021
1023 if (val == CPUFREQ_PRECHANGE) { 1022 if (val == CPUFREQ_PRECHANGE) {
@@ -1160,7 +1159,11 @@ static ssize_t s3c24xx_serial_show_clksrc(struct device *dev,
1160 struct uart_port *port = s3c24xx_dev_to_port(dev); 1159 struct uart_port *port = s3c24xx_dev_to_port(dev);
1161 struct s3c24xx_uart_port *ourport = to_ourport(port); 1160 struct s3c24xx_uart_port *ourport = to_ourport(port);
1162 1161
1163 return snprintf(buf, PAGE_SIZE, "* %s\n", ourport->baudclk->name); 1162 if (IS_ERR(ourport->baudclk))
1163 return -EINVAL;
1164
1165 return snprintf(buf, PAGE_SIZE, "* %s\n",
1166 ourport->baudclk->name ?: "(null)");
1164} 1167}
1165 1168
1166static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL); 1169static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL);
@@ -1200,6 +1203,7 @@ static int s3c24xx_serial_probe(struct platform_device *pdev)
1200 return -ENODEV; 1203 return -ENODEV;
1201 } 1204 }
1202 1205
1206 ourport->baudclk = ERR_PTR(-EINVAL);
1203 ourport->info = ourport->drv_data->info; 1207 ourport->info = ourport->drv_data->info;
1204 ourport->cfg = (pdev->dev.platform_data) ? 1208 ourport->cfg = (pdev->dev.platform_data) ?
1205 (struct s3c2410_uartcfg *)pdev->dev.platform_data : 1209 (struct s3c2410_uartcfg *)pdev->dev.platform_data :
@@ -1387,7 +1391,7 @@ s3c24xx_serial_get_options(struct uart_port *port, int *baud,
1387 sprintf(clk_name, "clk_uart_baud%d", clk_sel); 1391 sprintf(clk_name, "clk_uart_baud%d", clk_sel);
1388 1392
1389 clk = clk_get(port->dev, clk_name); 1393 clk = clk_get(port->dev, clk_name);
1390 if (!IS_ERR(clk) && clk != NULL) 1394 if (!IS_ERR(clk))
1391 rate = clk_get_rate(clk); 1395 rate = clk_get_rate(clk);
1392 else 1396 else
1393 rate = 1; 1397 rate = 1;
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 246b823c1b27..a21dc8e3b7c0 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2527,14 +2527,16 @@ void uart_insert_char(struct uart_port *port, unsigned int status,
2527 struct tty_struct *tty = port->state->port.tty; 2527 struct tty_struct *tty = port->state->port.tty;
2528 2528
2529 if ((status & port->ignore_status_mask & ~overrun) == 0) 2529 if ((status & port->ignore_status_mask & ~overrun) == 0)
2530 tty_insert_flip_char(tty, ch, flag); 2530 if (tty_insert_flip_char(tty, ch, flag) == 0)
2531 ++port->icount.buf_overrun;
2531 2532
2532 /* 2533 /*
2533 * Overrun is special. Since it's reported immediately, 2534 * Overrun is special. Since it's reported immediately,
2534 * it doesn't affect the current character. 2535 * it doesn't affect the current character.
2535 */ 2536 */
2536 if (status & ~port->ignore_status_mask & overrun) 2537 if (status & ~port->ignore_status_mask & overrun)
2537 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 2538 if (tty_insert_flip_char(tty, 0, TTY_OVERRUN) == 0)
2539 ++port->icount.buf_overrun;
2538} 2540}
2539EXPORT_SYMBOL_GPL(uart_insert_char); 2541EXPORT_SYMBOL_GPL(uart_insert_char);
2540 2542
diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
index 593d40ad0a6b..5ed0daae6564 100644
--- a/drivers/tty/synclink.c
+++ b/drivers/tty/synclink.c
@@ -3338,9 +3338,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3338 printk("%s(%d):block_til_ready blocking on %s count=%d\n", 3338 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
3339 __FILE__,__LINE__, tty->driver->name, port->count ); 3339 __FILE__,__LINE__, tty->driver->name, port->count );
3340 3340
3341 tty_unlock(); 3341 tty_unlock(tty);
3342 schedule(); 3342 schedule();
3343 tty_lock(); 3343 tty_lock(tty);
3344 } 3344 }
3345 3345
3346 set_current_state(TASK_RUNNING); 3346 set_current_state(TASK_RUNNING);
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index aa1debf97cc7..45b43f11ca39 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -3336,9 +3336,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3336 } 3336 }
3337 3337
3338 DBGINFO(("%s block_til_ready wait\n", tty->driver->name)); 3338 DBGINFO(("%s block_til_ready wait\n", tty->driver->name));
3339 tty_unlock(); 3339 tty_unlock(tty);
3340 schedule(); 3340 schedule();
3341 tty_lock(); 3341 tty_lock(tty);
3342 } 3342 }
3343 3343
3344 set_current_state(TASK_RUNNING); 3344 set_current_state(TASK_RUNNING);
diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
index a3dddc12d2fe..4a1e4f07765b 100644
--- a/drivers/tty/synclinkmp.c
+++ b/drivers/tty/synclinkmp.c
@@ -3357,9 +3357,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3357 printk("%s(%d):%s block_til_ready() count=%d\n", 3357 printk("%s(%d):%s block_til_ready() count=%d\n",
3358 __FILE__,__LINE__, tty->driver->name, port->count ); 3358 __FILE__,__LINE__, tty->driver->name, port->count );
3359 3359
3360 tty_unlock(); 3360 tty_unlock(tty);
3361 schedule(); 3361 schedule();
3362 tty_lock(); 3362 tty_lock(tty);
3363 } 3363 }
3364 3364
3365 set_current_state(TASK_RUNNING); 3365 set_current_state(TASK_RUNNING);
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index b425c79675ad..ca7c25d9f6d5 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -185,6 +185,7 @@ void free_tty_struct(struct tty_struct *tty)
185 put_device(tty->dev); 185 put_device(tty->dev);
186 kfree(tty->write_buf); 186 kfree(tty->write_buf);
187 tty_buffer_free_all(tty); 187 tty_buffer_free_all(tty);
188 tty->magic = 0xDEADDEAD;
188 kfree(tty); 189 kfree(tty);
189} 190}
190 191
@@ -573,7 +574,7 @@ void __tty_hangup(struct tty_struct *tty)
573 } 574 }
574 spin_unlock(&redirect_lock); 575 spin_unlock(&redirect_lock);
575 576
576 tty_lock(); 577 tty_lock(tty);
577 578
578 /* some functions below drop BTM, so we need this bit */ 579 /* some functions below drop BTM, so we need this bit */
579 set_bit(TTY_HUPPING, &tty->flags); 580 set_bit(TTY_HUPPING, &tty->flags);
@@ -666,7 +667,7 @@ void __tty_hangup(struct tty_struct *tty)
666 clear_bit(TTY_HUPPING, &tty->flags); 667 clear_bit(TTY_HUPPING, &tty->flags);
667 tty_ldisc_enable(tty); 668 tty_ldisc_enable(tty);
668 669
669 tty_unlock(); 670 tty_unlock(tty);
670 671
671 if (f) 672 if (f)
672 fput(f); 673 fput(f);
@@ -1103,12 +1104,12 @@ void tty_write_message(struct tty_struct *tty, char *msg)
1103{ 1104{
1104 if (tty) { 1105 if (tty) {
1105 mutex_lock(&tty->atomic_write_lock); 1106 mutex_lock(&tty->atomic_write_lock);
1106 tty_lock(); 1107 tty_lock(tty);
1107 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { 1108 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) {
1108 tty_unlock(); 1109 tty_unlock(tty);
1109 tty->ops->write(tty, msg, strlen(msg)); 1110 tty->ops->write(tty, msg, strlen(msg));
1110 } else 1111 } else
1111 tty_unlock(); 1112 tty_unlock(tty);
1112 tty_write_unlock(tty); 1113 tty_write_unlock(tty);
1113 } 1114 }
1114 return; 1115 return;
@@ -1403,10 +1404,14 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
1403 } 1404 }
1404 initialize_tty_struct(tty, driver, idx); 1405 initialize_tty_struct(tty, driver, idx);
1405 1406
1407 tty_lock(tty);
1406 retval = tty_driver_install_tty(driver, tty); 1408 retval = tty_driver_install_tty(driver, tty);
1407 if (retval < 0) 1409 if (retval < 0)
1408 goto err_deinit_tty; 1410 goto err_deinit_tty;
1409 1411
1412 if (!tty->port)
1413 tty->port = driver->ports[idx];
1414
1410 /* 1415 /*
1411 * Structures all installed ... call the ldisc open routines. 1416 * Structures all installed ... call the ldisc open routines.
1412 * If we fail here just call release_tty to clean up. No need 1417 * If we fail here just call release_tty to clean up. No need
@@ -1415,9 +1420,11 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
1415 retval = tty_ldisc_setup(tty, tty->link); 1420 retval = tty_ldisc_setup(tty, tty->link);
1416 if (retval) 1421 if (retval)
1417 goto err_release_tty; 1422 goto err_release_tty;
1423 /* Return the tty locked so that it cannot vanish under the caller */
1418 return tty; 1424 return tty;
1419 1425
1420err_deinit_tty: 1426err_deinit_tty:
1427 tty_unlock(tty);
1421 deinitialize_tty_struct(tty); 1428 deinitialize_tty_struct(tty);
1422 free_tty_struct(tty); 1429 free_tty_struct(tty);
1423err_module_put: 1430err_module_put:
@@ -1426,6 +1433,7 @@ err_module_put:
1426 1433
1427 /* call the tty release_tty routine to clean out this slot */ 1434 /* call the tty release_tty routine to clean out this slot */
1428err_release_tty: 1435err_release_tty:
1436 tty_unlock(tty);
1429 printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, " 1437 printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, "
1430 "clearing slot %d\n", idx); 1438 "clearing slot %d\n", idx);
1431 release_tty(tty, idx); 1439 release_tty(tty, idx);
@@ -1628,7 +1636,7 @@ int tty_release(struct inode *inode, struct file *filp)
1628 if (tty_paranoia_check(tty, inode, __func__)) 1636 if (tty_paranoia_check(tty, inode, __func__))
1629 return 0; 1637 return 0;
1630 1638
1631 tty_lock(); 1639 tty_lock(tty);
1632 check_tty_count(tty, __func__); 1640 check_tty_count(tty, __func__);
1633 1641
1634 __tty_fasync(-1, filp, 0); 1642 __tty_fasync(-1, filp, 0);
@@ -1637,10 +1645,11 @@ int tty_release(struct inode *inode, struct file *filp)
1637 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1645 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1638 tty->driver->subtype == PTY_TYPE_MASTER); 1646 tty->driver->subtype == PTY_TYPE_MASTER);
1639 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0; 1647 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0;
1648 /* Review: parallel close */
1640 o_tty = tty->link; 1649 o_tty = tty->link;
1641 1650
1642 if (tty_release_checks(tty, o_tty, idx)) { 1651 if (tty_release_checks(tty, o_tty, idx)) {
1643 tty_unlock(); 1652 tty_unlock(tty);
1644 return 0; 1653 return 0;
1645 } 1654 }
1646 1655
@@ -1652,7 +1661,7 @@ int tty_release(struct inode *inode, struct file *filp)
1652 if (tty->ops->close) 1661 if (tty->ops->close)
1653 tty->ops->close(tty, filp); 1662 tty->ops->close(tty, filp);
1654 1663
1655 tty_unlock(); 1664 tty_unlock(tty);
1656 /* 1665 /*
1657 * Sanity check: if tty->count is going to zero, there shouldn't be 1666 * Sanity check: if tty->count is going to zero, there shouldn't be
1658 * any waiters on tty->read_wait or tty->write_wait. We test the 1667 * any waiters on tty->read_wait or tty->write_wait. We test the
@@ -1675,7 +1684,7 @@ int tty_release(struct inode *inode, struct file *filp)
1675 opens on /dev/tty */ 1684 opens on /dev/tty */
1676 1685
1677 mutex_lock(&tty_mutex); 1686 mutex_lock(&tty_mutex);
1678 tty_lock(); 1687 tty_lock_pair(tty, o_tty);
1679 tty_closing = tty->count <= 1; 1688 tty_closing = tty->count <= 1;
1680 o_tty_closing = o_tty && 1689 o_tty_closing = o_tty &&
1681 (o_tty->count <= (pty_master ? 1 : 0)); 1690 (o_tty->count <= (pty_master ? 1 : 0));
@@ -1706,7 +1715,7 @@ int tty_release(struct inode *inode, struct file *filp)
1706 1715
1707 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n", 1716 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n",
1708 __func__, tty_name(tty, buf)); 1717 __func__, tty_name(tty, buf));
1709 tty_unlock(); 1718 tty_unlock_pair(tty, o_tty);
1710 mutex_unlock(&tty_mutex); 1719 mutex_unlock(&tty_mutex);
1711 schedule(); 1720 schedule();
1712 } 1721 }
@@ -1769,7 +1778,7 @@ int tty_release(struct inode *inode, struct file *filp)
1769 1778
1770 /* check whether both sides are closing ... */ 1779 /* check whether both sides are closing ... */
1771 if (!tty_closing || (o_tty && !o_tty_closing)) { 1780 if (!tty_closing || (o_tty && !o_tty_closing)) {
1772 tty_unlock(); 1781 tty_unlock_pair(tty, o_tty);
1773 return 0; 1782 return 0;
1774 } 1783 }
1775 1784
@@ -1782,14 +1791,16 @@ int tty_release(struct inode *inode, struct file *filp)
1782 tty_ldisc_release(tty, o_tty); 1791 tty_ldisc_release(tty, o_tty);
1783 /* 1792 /*
1784 * The release_tty function takes care of the details of clearing 1793 * The release_tty function takes care of the details of clearing
1785 * the slots and preserving the termios structure. 1794 * the slots and preserving the termios structure. The tty_unlock_pair
1795 * should be safe as we keep a kref while the tty is locked (so the
1796 * unlock never unlocks a freed tty).
1786 */ 1797 */
1787 release_tty(tty, idx); 1798 release_tty(tty, idx);
1799 tty_unlock_pair(tty, o_tty);
1788 1800
1789 /* Make this pty number available for reallocation */ 1801 /* Make this pty number available for reallocation */
1790 if (devpts) 1802 if (devpts)
1791 devpts_kill_index(inode, idx); 1803 devpts_kill_index(inode, idx);
1792 tty_unlock();
1793 return 0; 1804 return 0;
1794} 1805}
1795 1806
@@ -1893,6 +1904,9 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
1893 * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev. 1904 * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev.
1894 * tty->count should protect the rest. 1905 * tty->count should protect the rest.
1895 * ->siglock protects ->signal/->sighand 1906 * ->siglock protects ->signal/->sighand
1907 *
1908 * Note: the tty_unlock/lock cases without a ref are only safe due to
1909 * tty_mutex
1896 */ 1910 */
1897 1911
1898static int tty_open(struct inode *inode, struct file *filp) 1912static int tty_open(struct inode *inode, struct file *filp)
@@ -1916,8 +1930,7 @@ retry_open:
1916 retval = 0; 1930 retval = 0;
1917 1931
1918 mutex_lock(&tty_mutex); 1932 mutex_lock(&tty_mutex);
1919 tty_lock(); 1933 /* This is protected by the tty_mutex */
1920
1921 tty = tty_open_current_tty(device, filp); 1934 tty = tty_open_current_tty(device, filp);
1922 if (IS_ERR(tty)) { 1935 if (IS_ERR(tty)) {
1923 retval = PTR_ERR(tty); 1936 retval = PTR_ERR(tty);
@@ -1938,17 +1951,19 @@ retry_open:
1938 } 1951 }
1939 1952
1940 if (tty) { 1953 if (tty) {
1954 tty_lock(tty);
1941 retval = tty_reopen(tty); 1955 retval = tty_reopen(tty);
1942 if (retval) 1956 if (retval < 0) {
1957 tty_unlock(tty);
1943 tty = ERR_PTR(retval); 1958 tty = ERR_PTR(retval);
1944 } else 1959 }
1960 } else /* Returns with the tty_lock held for now */
1945 tty = tty_init_dev(driver, index); 1961 tty = tty_init_dev(driver, index);
1946 1962
1947 mutex_unlock(&tty_mutex); 1963 mutex_unlock(&tty_mutex);
1948 if (driver) 1964 if (driver)
1949 tty_driver_kref_put(driver); 1965 tty_driver_kref_put(driver);
1950 if (IS_ERR(tty)) { 1966 if (IS_ERR(tty)) {
1951 tty_unlock();
1952 retval = PTR_ERR(tty); 1967 retval = PTR_ERR(tty);
1953 goto err_file; 1968 goto err_file;
1954 } 1969 }
@@ -1977,7 +1992,7 @@ retry_open:
1977 printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__, 1992 printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__,
1978 retval, tty->name); 1993 retval, tty->name);
1979#endif 1994#endif
1980 tty_unlock(); /* need to call tty_release without BTM */ 1995 tty_unlock(tty); /* need to call tty_release without BTM */
1981 tty_release(inode, filp); 1996 tty_release(inode, filp);
1982 if (retval != -ERESTARTSYS) 1997 if (retval != -ERESTARTSYS)
1983 return retval; 1998 return retval;
@@ -1989,17 +2004,15 @@ retry_open:
1989 /* 2004 /*
1990 * Need to reset f_op in case a hangup happened. 2005 * Need to reset f_op in case a hangup happened.
1991 */ 2006 */
1992 tty_lock();
1993 if (filp->f_op == &hung_up_tty_fops) 2007 if (filp->f_op == &hung_up_tty_fops)
1994 filp->f_op = &tty_fops; 2008 filp->f_op = &tty_fops;
1995 tty_unlock();
1996 goto retry_open; 2009 goto retry_open;
1997 } 2010 }
1998 tty_unlock(); 2011 tty_unlock(tty);
1999 2012
2000 2013
2001 mutex_lock(&tty_mutex); 2014 mutex_lock(&tty_mutex);
2002 tty_lock(); 2015 tty_lock(tty);
2003 spin_lock_irq(&current->sighand->siglock); 2016 spin_lock_irq(&current->sighand->siglock);
2004 if (!noctty && 2017 if (!noctty &&
2005 current->signal->leader && 2018 current->signal->leader &&
@@ -2007,11 +2020,10 @@ retry_open:
2007 tty->session == NULL) 2020 tty->session == NULL)
2008 __proc_set_tty(current, tty); 2021 __proc_set_tty(current, tty);
2009 spin_unlock_irq(&current->sighand->siglock); 2022 spin_unlock_irq(&current->sighand->siglock);
2010 tty_unlock(); 2023 tty_unlock(tty);
2011 mutex_unlock(&tty_mutex); 2024 mutex_unlock(&tty_mutex);
2012 return 0; 2025 return 0;
2013err_unlock: 2026err_unlock:
2014 tty_unlock();
2015 mutex_unlock(&tty_mutex); 2027 mutex_unlock(&tty_mutex);
2016 /* after locks to avoid deadlock */ 2028 /* after locks to avoid deadlock */
2017 if (!IS_ERR_OR_NULL(driver)) 2029 if (!IS_ERR_OR_NULL(driver))
@@ -2094,10 +2106,13 @@ out:
2094 2106
2095static int tty_fasync(int fd, struct file *filp, int on) 2107static int tty_fasync(int fd, struct file *filp, int on)
2096{ 2108{
2109 struct tty_struct *tty = file_tty(filp);
2097 int retval; 2110 int retval;
2098 tty_lock(); 2111
2112 tty_lock(tty);
2099 retval = __tty_fasync(fd, filp, on); 2113 retval = __tty_fasync(fd, filp, on);
2100 tty_unlock(); 2114 tty_unlock(tty);
2115
2101 return retval; 2116 return retval;
2102} 2117}
2103 2118
@@ -2934,6 +2949,7 @@ void initialize_tty_struct(struct tty_struct *tty,
2934 tty->pgrp = NULL; 2949 tty->pgrp = NULL;
2935 tty->overrun_time = jiffies; 2950 tty->overrun_time = jiffies;
2936 tty_buffer_init(tty); 2951 tty_buffer_init(tty);
2952 mutex_init(&tty->legacy_mutex);
2937 mutex_init(&tty->termios_mutex); 2953 mutex_init(&tty->termios_mutex);
2938 mutex_init(&tty->ldisc_mutex); 2954 mutex_init(&tty->ldisc_mutex);
2939 init_waitqueue_head(&tty->write_wait); 2955 init_waitqueue_head(&tty->write_wait);
@@ -3094,6 +3110,7 @@ static void destruct_tty_driver(struct kref *kref)
3094 kfree(p); 3110 kfree(p);
3095 cdev_del(&driver->cdev); 3111 cdev_del(&driver->cdev);
3096 } 3112 }
3113 kfree(driver->ports);
3097 kfree(driver); 3114 kfree(driver);
3098} 3115}
3099 3116
@@ -3132,6 +3149,18 @@ int tty_register_driver(struct tty_driver *driver)
3132 if (!p) 3149 if (!p)
3133 return -ENOMEM; 3150 return -ENOMEM;
3134 } 3151 }
3152 /*
3153 * There is too many lines in PTY and we won't need the array there
3154 * since it has an ->install hook where it assigns ports properly.
3155 */
3156 if (driver->type != TTY_DRIVER_TYPE_PTY) {
3157 driver->ports = kcalloc(driver->num, sizeof(struct tty_port *),
3158 GFP_KERNEL);
3159 if (!driver->ports) {
3160 error = -ENOMEM;
3161 goto err_free_p;
3162 }
3163 }
3135 3164
3136 if (!driver->major) { 3165 if (!driver->major) {
3137 error = alloc_chrdev_region(&dev, driver->minor_start, 3166 error = alloc_chrdev_region(&dev, driver->minor_start,
@@ -3144,10 +3173,8 @@ int tty_register_driver(struct tty_driver *driver)
3144 dev = MKDEV(driver->major, driver->minor_start); 3173 dev = MKDEV(driver->major, driver->minor_start);
3145 error = register_chrdev_region(dev, driver->num, driver->name); 3174 error = register_chrdev_region(dev, driver->num, driver->name);
3146 } 3175 }
3147 if (error < 0) { 3176 if (error < 0)
3148 kfree(p); 3177 goto err_free_p;
3149 return error;
3150 }
3151 3178
3152 if (p) { 3179 if (p) {
3153 driver->ttys = (struct tty_struct **)p; 3180 driver->ttys = (struct tty_struct **)p;
@@ -3160,13 +3187,8 @@ int tty_register_driver(struct tty_driver *driver)
3160 cdev_init(&driver->cdev, &tty_fops); 3187 cdev_init(&driver->cdev, &tty_fops);
3161 driver->cdev.owner = driver->owner; 3188 driver->cdev.owner = driver->owner;
3162 error = cdev_add(&driver->cdev, dev, driver->num); 3189 error = cdev_add(&driver->cdev, dev, driver->num);
3163 if (error) { 3190 if (error)
3164 unregister_chrdev_region(dev, driver->num); 3191 goto err_unreg_char;
3165 driver->ttys = NULL;
3166 driver->termios = NULL;
3167 kfree(p);
3168 return error;
3169 }
3170 3192
3171 mutex_lock(&tty_mutex); 3193 mutex_lock(&tty_mutex);
3172 list_add(&driver->tty_drivers, &tty_drivers); 3194 list_add(&driver->tty_drivers, &tty_drivers);
@@ -3193,13 +3215,14 @@ err:
3193 list_del(&driver->tty_drivers); 3215 list_del(&driver->tty_drivers);
3194 mutex_unlock(&tty_mutex); 3216 mutex_unlock(&tty_mutex);
3195 3217
3218err_unreg_char:
3196 unregister_chrdev_region(dev, driver->num); 3219 unregister_chrdev_region(dev, driver->num);
3197 driver->ttys = NULL; 3220 driver->ttys = NULL;
3198 driver->termios = NULL; 3221 driver->termios = NULL;
3222err_free_p: /* destruct_tty_driver will free driver->ports */
3199 kfree(p); 3223 kfree(p);
3200 return error; 3224 return error;
3201} 3225}
3202
3203EXPORT_SYMBOL(tty_register_driver); 3226EXPORT_SYMBOL(tty_register_driver);
3204 3227
3205/* 3228/*
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 9911eb6b34cd..847f7ed7a3ed 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -568,7 +568,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
568 if (IS_ERR(new_ldisc)) 568 if (IS_ERR(new_ldisc))
569 return PTR_ERR(new_ldisc); 569 return PTR_ERR(new_ldisc);
570 570
571 tty_lock(); 571 tty_lock(tty);
572 /* 572 /*
573 * We need to look at the tty locking here for pty/tty pairs 573 * We need to look at the tty locking here for pty/tty pairs
574 * when both sides try to change in parallel. 574 * when both sides try to change in parallel.
@@ -582,12 +582,12 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
582 */ 582 */
583 583
584 if (tty->ldisc->ops->num == ldisc) { 584 if (tty->ldisc->ops->num == ldisc) {
585 tty_unlock(); 585 tty_unlock(tty);
586 tty_ldisc_put(new_ldisc); 586 tty_ldisc_put(new_ldisc);
587 return 0; 587 return 0;
588 } 588 }
589 589
590 tty_unlock(); 590 tty_unlock(tty);
591 /* 591 /*
592 * Problem: What do we do if this blocks ? 592 * Problem: What do we do if this blocks ?
593 * We could deadlock here 593 * We could deadlock here
@@ -595,7 +595,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
595 595
596 tty_wait_until_sent(tty, 0); 596 tty_wait_until_sent(tty, 0);
597 597
598 tty_lock(); 598 tty_lock(tty);
599 mutex_lock(&tty->ldisc_mutex); 599 mutex_lock(&tty->ldisc_mutex);
600 600
601 /* 601 /*
@@ -605,10 +605,10 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
605 605
606 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { 606 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) {
607 mutex_unlock(&tty->ldisc_mutex); 607 mutex_unlock(&tty->ldisc_mutex);
608 tty_unlock(); 608 tty_unlock(tty);
609 wait_event(tty_ldisc_wait, 609 wait_event(tty_ldisc_wait,
610 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); 610 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0);
611 tty_lock(); 611 tty_lock(tty);
612 mutex_lock(&tty->ldisc_mutex); 612 mutex_lock(&tty->ldisc_mutex);
613 } 613 }
614 614
@@ -623,7 +623,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
623 623
624 o_ldisc = tty->ldisc; 624 o_ldisc = tty->ldisc;
625 625
626 tty_unlock(); 626 tty_unlock(tty);
627 /* 627 /*
628 * Make sure we don't change while someone holds a 628 * Make sure we don't change while someone holds a
629 * reference to the line discipline. The TTY_LDISC bit 629 * reference to the line discipline. The TTY_LDISC bit
@@ -650,7 +650,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
650 650
651 retval = tty_ldisc_wait_idle(tty, 5 * HZ); 651 retval = tty_ldisc_wait_idle(tty, 5 * HZ);
652 652
653 tty_lock(); 653 tty_lock(tty);
654 mutex_lock(&tty->ldisc_mutex); 654 mutex_lock(&tty->ldisc_mutex);
655 655
656 /* handle wait idle failure locked */ 656 /* handle wait idle failure locked */
@@ -659,13 +659,13 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
659 goto enable; 659 goto enable;
660 } 660 }
661 661
662 if (test_bit(TTY_HUPPED, &tty->flags)) { 662 if (test_bit(TTY_HUPPING, &tty->flags)) {
663 /* We were raced by the hangup method. It will have stomped 663 /* We were raced by the hangup method. It will have stomped
664 the ldisc data and closed the ldisc down */ 664 the ldisc data and closed the ldisc down */
665 clear_bit(TTY_LDISC_CHANGING, &tty->flags); 665 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
666 mutex_unlock(&tty->ldisc_mutex); 666 mutex_unlock(&tty->ldisc_mutex);
667 tty_ldisc_put(new_ldisc); 667 tty_ldisc_put(new_ldisc);
668 tty_unlock(); 668 tty_unlock(tty);
669 return -EIO; 669 return -EIO;
670 } 670 }
671 671
@@ -708,7 +708,7 @@ enable:
708 if (o_work) 708 if (o_work)
709 schedule_work(&o_tty->buf.work); 709 schedule_work(&o_tty->buf.work);
710 mutex_unlock(&tty->ldisc_mutex); 710 mutex_unlock(&tty->ldisc_mutex);
711 tty_unlock(); 711 tty_unlock(tty);
712 return retval; 712 return retval;
713} 713}
714 714
@@ -816,11 +816,11 @@ void tty_ldisc_hangup(struct tty_struct *tty)
816 * need to wait for another function taking the BTM 816 * need to wait for another function taking the BTM
817 */ 817 */
818 clear_bit(TTY_LDISC, &tty->flags); 818 clear_bit(TTY_LDISC, &tty->flags);
819 tty_unlock(); 819 tty_unlock(tty);
820 cancel_work_sync(&tty->buf.work); 820 cancel_work_sync(&tty->buf.work);
821 mutex_unlock(&tty->ldisc_mutex); 821 mutex_unlock(&tty->ldisc_mutex);
822retry: 822retry:
823 tty_lock(); 823 tty_lock(tty);
824 mutex_lock(&tty->ldisc_mutex); 824 mutex_lock(&tty->ldisc_mutex);
825 825
826 /* At this point we have a closed ldisc and we want to 826 /* At this point we have a closed ldisc and we want to
@@ -831,7 +831,7 @@ retry:
831 if (atomic_read(&tty->ldisc->users) != 1) { 831 if (atomic_read(&tty->ldisc->users) != 1) {
832 char cur_n[TASK_COMM_LEN], tty_n[64]; 832 char cur_n[TASK_COMM_LEN], tty_n[64];
833 long timeout = 3 * HZ; 833 long timeout = 3 * HZ;
834 tty_unlock(); 834 tty_unlock(tty);
835 835
836 while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) { 836 while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) {
837 timeout = MAX_SCHEDULE_TIMEOUT; 837 timeout = MAX_SCHEDULE_TIMEOUT;
@@ -894,6 +894,23 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
894 tty_ldisc_enable(tty); 894 tty_ldisc_enable(tty);
895 return 0; 895 return 0;
896} 896}
897
898static void tty_ldisc_kill(struct tty_struct *tty)
899{
900 mutex_lock(&tty->ldisc_mutex);
901 /*
902 * Now kill off the ldisc
903 */
904 tty_ldisc_close(tty, tty->ldisc);
905 tty_ldisc_put(tty->ldisc);
906 /* Force an oops if we mess this up */
907 tty->ldisc = NULL;
908
909 /* Ensure the next open requests the N_TTY ldisc */
910 tty_set_termios_ldisc(tty, N_TTY);
911 mutex_unlock(&tty->ldisc_mutex);
912}
913
897/** 914/**
898 * tty_ldisc_release - release line discipline 915 * tty_ldisc_release - release line discipline
899 * @tty: tty being shut down 916 * @tty: tty being shut down
@@ -912,27 +929,19 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
912 * race with the set_ldisc code path. 929 * race with the set_ldisc code path.
913 */ 930 */
914 931
915 tty_unlock(); 932 tty_unlock_pair(tty, o_tty);
916 tty_ldisc_halt(tty); 933 tty_ldisc_halt(tty);
917 tty_ldisc_flush_works(tty); 934 tty_ldisc_flush_works(tty);
918 tty_lock(); 935 if (o_tty) {
919 936 tty_ldisc_halt(o_tty);
920 mutex_lock(&tty->ldisc_mutex); 937 tty_ldisc_flush_works(o_tty);
921 /* 938 }
922 * Now kill off the ldisc 939 tty_lock_pair(tty, o_tty);
923 */
924 tty_ldisc_close(tty, tty->ldisc);
925 tty_ldisc_put(tty->ldisc);
926 /* Force an oops if we mess this up */
927 tty->ldisc = NULL;
928 940
929 /* Ensure the next open requests the N_TTY ldisc */
930 tty_set_termios_ldisc(tty, N_TTY);
931 mutex_unlock(&tty->ldisc_mutex);
932 941
933 /* This will need doing differently if we need to lock */ 942 tty_ldisc_kill(tty);
934 if (o_tty) 943 if (o_tty)
935 tty_ldisc_release(o_tty, NULL); 944 tty_ldisc_kill(o_tty);
936 945
937 /* And the memory resources remaining (buffers, termios) will be 946 /* And the memory resources remaining (buffers, termios) will be
938 disposed of when the kref hits zero */ 947 disposed of when the kref hits zero */
diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c
index 9ff986c32a21..67feac9e6ebb 100644
--- a/drivers/tty/tty_mutex.c
+++ b/drivers/tty/tty_mutex.c
@@ -4,29 +4,70 @@
4#include <linux/semaphore.h> 4#include <linux/semaphore.h>
5#include <linux/sched.h> 5#include <linux/sched.h>
6 6
7/* 7/* Legacy tty mutex glue */
8 * The 'big tty mutex' 8
9 * 9enum {
10 * This mutex is taken and released by tty_lock() and tty_unlock(), 10 TTY_MUTEX_NORMAL,
11 * replacing the older big kernel lock. 11 TTY_MUTEX_NESTED,
12 * It can no longer be taken recursively, and does not get 12};
13 * released implicitly while sleeping.
14 *
15 * Don't use in new code.
16 */
17static DEFINE_MUTEX(big_tty_mutex);
18 13
19/* 14/*
20 * Getting the big tty mutex. 15 * Getting the big tty mutex.
21 */ 16 */
22void __lockfunc tty_lock(void) 17
18static void __lockfunc tty_lock_nested(struct tty_struct *tty,
19 unsigned int subclass)
23{ 20{
24 mutex_lock(&big_tty_mutex); 21 if (tty->magic != TTY_MAGIC) {
22 printk(KERN_ERR "L Bad %p\n", tty);
23 WARN_ON(1);
24 return;
25 }
26 tty_kref_get(tty);
27 mutex_lock_nested(&tty->legacy_mutex, subclass);
28}
29
30void __lockfunc tty_lock(struct tty_struct *tty)
31{
32 return tty_lock_nested(tty, TTY_MUTEX_NORMAL);
25} 33}
26EXPORT_SYMBOL(tty_lock); 34EXPORT_SYMBOL(tty_lock);
27 35
28void __lockfunc tty_unlock(void) 36void __lockfunc tty_unlock(struct tty_struct *tty)
29{ 37{
30 mutex_unlock(&big_tty_mutex); 38 if (tty->magic != TTY_MAGIC) {
39 printk(KERN_ERR "U Bad %p\n", tty);
40 WARN_ON(1);
41 return;
42 }
43 mutex_unlock(&tty->legacy_mutex);
44 tty_kref_put(tty);
31} 45}
32EXPORT_SYMBOL(tty_unlock); 46EXPORT_SYMBOL(tty_unlock);
47
48/*
49 * Getting the big tty mutex for a pair of ttys with lock ordering
50 * On a non pty/tty pair tty2 can be NULL which is just fine.
51 */
52void __lockfunc tty_lock_pair(struct tty_struct *tty,
53 struct tty_struct *tty2)
54{
55 if (tty < tty2) {
56 tty_lock(tty);
57 tty_lock_nested(tty2, TTY_MUTEX_NESTED);
58 } else {
59 if (tty2 && tty2 != tty)
60 tty_lock(tty2);
61 tty_lock_nested(tty, TTY_MUTEX_NESTED);
62 }
63}
64EXPORT_SYMBOL(tty_lock_pair);
65
66void __lockfunc tty_unlock_pair(struct tty_struct *tty,
67 struct tty_struct *tty2)
68{
69 tty_unlock(tty);
70 if (tty2 && tty2 != tty)
71 tty_unlock(tty2);
72}
73EXPORT_SYMBOL(tty_unlock_pair);
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index bf6e238146ae..a3ba776c574c 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -33,6 +33,15 @@ void tty_port_init(struct tty_port *port)
33} 33}
34EXPORT_SYMBOL(tty_port_init); 34EXPORT_SYMBOL(tty_port_init);
35 35
36struct device *tty_port_register_device(struct tty_port *port,
37 struct tty_driver *driver, unsigned index,
38 struct device *device)
39{
40 driver->ports[index] = port;
41 return tty_register_device(driver, index, device);
42}
43EXPORT_SYMBOL_GPL(tty_port_register_device);
44
36int tty_port_alloc_xmit_buf(struct tty_port *port) 45int tty_port_alloc_xmit_buf(struct tty_port *port)
37{ 46{
38 /* We may sleep in get_zeroed_page() */ 47 /* We may sleep in get_zeroed_page() */
@@ -230,7 +239,7 @@ int tty_port_block_til_ready(struct tty_port *port,
230 239
231 /* block if port is in the process of being closed */ 240 /* block if port is in the process of being closed */
232 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { 241 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
233 wait_event_interruptible_tty(port->close_wait, 242 wait_event_interruptible_tty(tty, port->close_wait,
234 !(port->flags & ASYNC_CLOSING)); 243 !(port->flags & ASYNC_CLOSING));
235 if (port->flags & ASYNC_HUP_NOTIFY) 244 if (port->flags & ASYNC_HUP_NOTIFY)
236 return -EAGAIN; 245 return -EAGAIN;
@@ -296,9 +305,9 @@ int tty_port_block_til_ready(struct tty_port *port,
296 retval = -ERESTARTSYS; 305 retval = -ERESTARTSYS;
297 break; 306 break;
298 } 307 }
299 tty_unlock(); 308 tty_unlock(tty);
300 schedule(); 309 schedule();
301 tty_lock(); 310 tty_lock(tty);
302 } 311 }
303 finish_wait(&port->open_wait, &wait); 312 finish_wait(&port->open_wait, &wait);
304 313
@@ -413,6 +422,14 @@ void tty_port_close(struct tty_port *port, struct tty_struct *tty,
413} 422}
414EXPORT_SYMBOL(tty_port_close); 423EXPORT_SYMBOL(tty_port_close);
415 424
425int tty_port_install(struct tty_port *port, struct tty_driver *driver,
426 struct tty_struct *tty)
427{
428 tty->port = port;
429 return tty_standard_install(driver, tty);
430}
431EXPORT_SYMBOL_GPL(tty_port_install);
432
416int tty_port_open(struct tty_port *port, struct tty_struct *tty, 433int tty_port_open(struct tty_port *port, struct tty_struct *tty,
417 struct file *filp) 434 struct file *filp)
418{ 435{
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 48cc6f25cfd3..9b4f60a6ab0e 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -310,7 +310,7 @@ static void put_queue(struct vc_data *vc, int ch)
310 310
311 if (tty) { 311 if (tty) {
312 tty_insert_flip_char(tty, ch, 0); 312 tty_insert_flip_char(tty, ch, 0);
313 con_schedule_flip(tty); 313 tty_schedule_flip(tty);
314 } 314 }
315} 315}
316 316
@@ -325,7 +325,7 @@ static void puts_queue(struct vc_data *vc, char *cp)
325 tty_insert_flip_char(tty, *cp, 0); 325 tty_insert_flip_char(tty, *cp, 0);
326 cp++; 326 cp++;
327 } 327 }
328 con_schedule_flip(tty); 328 tty_schedule_flip(tty);
329} 329}
330 330
331static void applkey(struct vc_data *vc, int key, char mode) 331static void applkey(struct vc_data *vc, int key, char mode)
@@ -586,7 +586,7 @@ static void fn_send_intr(struct vc_data *vc)
586 if (!tty) 586 if (!tty)
587 return; 587 return;
588 tty_insert_flip_char(tty, 0, TTY_BREAK); 588 tty_insert_flip_char(tty, 0, TTY_BREAK);
589 con_schedule_flip(tty); 589 tty_schedule_flip(tty);
590} 590}
591 591
592static void fn_scroll_forw(struct vc_data *vc) 592static void fn_scroll_forw(struct vc_data *vc)
@@ -1049,13 +1049,10 @@ static int kbd_update_leds_helper(struct input_handle *handle, void *data)
1049 */ 1049 */
1050int vt_get_leds(int console, int flag) 1050int vt_get_leds(int console, int flag)
1051{ 1051{
1052 unsigned long flags;
1053 struct kbd_struct * kbd = kbd_table + console; 1052 struct kbd_struct * kbd = kbd_table + console;
1054 int ret; 1053 int ret;
1055 1054
1056 spin_lock_irqsave(&kbd_event_lock, flags);
1057 ret = vc_kbd_led(kbd, flag); 1055 ret = vc_kbd_led(kbd, flag);
1058 spin_unlock_irqrestore(&kbd_event_lock, flags);
1059 1056
1060 return ret; 1057 return ret;
1061} 1058}
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 84cbf298c094..7cb53c236339 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -1380,7 +1380,7 @@ static void respond_string(const char *p, struct tty_struct *tty)
1380 tty_insert_flip_char(tty, *p, 0); 1380 tty_insert_flip_char(tty, *p, 0);
1381 p++; 1381 p++;
1382 } 1382 }
1383 con_schedule_flip(tty); 1383 tty_schedule_flip(tty);
1384} 1384}
1385 1385
1386static void cursor_report(struct vc_data *vc, struct tty_struct *tty) 1386static void cursor_report(struct vc_data *vc, struct tty_struct *tty)
@@ -2792,41 +2792,52 @@ static void con_flush_chars(struct tty_struct *tty)
2792/* 2792/*
2793 * Allocate the console screen memory. 2793 * Allocate the console screen memory.
2794 */ 2794 */
2795static int con_open(struct tty_struct *tty, struct file *filp) 2795static int con_install(struct tty_driver *driver, struct tty_struct *tty)
2796{ 2796{
2797 unsigned int currcons = tty->index; 2797 unsigned int currcons = tty->index;
2798 int ret = 0; 2798 struct vc_data *vc;
2799 int ret;
2799 2800
2800 console_lock(); 2801 console_lock();
2801 if (tty->driver_data == NULL) { 2802 ret = vc_allocate(currcons);
2802 ret = vc_allocate(currcons); 2803 if (ret)
2803 if (ret == 0) { 2804 goto unlock;
2804 struct vc_data *vc = vc_cons[currcons].d;
2805 2805
2806 /* Still being freed */ 2806 vc = vc_cons[currcons].d;
2807 if (vc->port.tty) {
2808 console_unlock();
2809 return -ERESTARTSYS;
2810 }
2811 tty->driver_data = vc;
2812 vc->port.tty = tty;
2813 2807
2814 if (!tty->winsize.ws_row && !tty->winsize.ws_col) { 2808 /* Still being freed */
2815 tty->winsize.ws_row = vc_cons[currcons].d->vc_rows; 2809 if (vc->port.tty) {
2816 tty->winsize.ws_col = vc_cons[currcons].d->vc_cols; 2810 ret = -ERESTARTSYS;
2817 } 2811 goto unlock;
2818 if (vc->vc_utf)
2819 tty->termios->c_iflag |= IUTF8;
2820 else
2821 tty->termios->c_iflag &= ~IUTF8;
2822 console_unlock();
2823 return ret;
2824 }
2825 } 2812 }
2813
2814 ret = tty_port_install(&vc->port, driver, tty);
2815 if (ret)
2816 goto unlock;
2817
2818 tty->driver_data = vc;
2819 vc->port.tty = tty;
2820
2821 if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
2822 tty->winsize.ws_row = vc_cons[currcons].d->vc_rows;
2823 tty->winsize.ws_col = vc_cons[currcons].d->vc_cols;
2824 }
2825 if (vc->vc_utf)
2826 tty->termios->c_iflag |= IUTF8;
2827 else
2828 tty->termios->c_iflag &= ~IUTF8;
2829unlock:
2826 console_unlock(); 2830 console_unlock();
2827 return ret; 2831 return ret;
2828} 2832}
2829 2833
2834static int con_open(struct tty_struct *tty, struct file *filp)
2835{
2836 /* everything done in install */
2837 return 0;
2838}
2839
2840
2830static void con_close(struct tty_struct *tty, struct file *filp) 2841static void con_close(struct tty_struct *tty, struct file *filp)
2831{ 2842{
2832 /* Nothing to do - we defer to shutdown */ 2843 /* Nothing to do - we defer to shutdown */
@@ -2947,6 +2958,7 @@ static int __init con_init(void)
2947console_initcall(con_init); 2958console_initcall(con_init);
2948 2959
2949static const struct tty_operations con_ops = { 2960static const struct tty_operations con_ops = {
2961 .install = con_install,
2950 .open = con_open, 2962 .open = con_open,
2951 .close = con_close, 2963 .close = con_close,
2952 .write = con_write, 2964 .write = con_write,
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 64618547be11..b841f56d2e66 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -110,16 +110,7 @@ void vt_event_post(unsigned int event, unsigned int old, unsigned int new)
110 wake_up_interruptible(&vt_event_waitqueue); 110 wake_up_interruptible(&vt_event_waitqueue);
111} 111}
112 112
113/** 113static void __vt_event_queue(struct vt_event_wait *vw)
114 * vt_event_wait - wait for an event
115 * @vw: our event
116 *
117 * Waits for an event to occur which completes our vt_event_wait
118 * structure. On return the structure has wv->done set to 1 for success
119 * or 0 if some event such as a signal ended the wait.
120 */
121
122static void vt_event_wait(struct vt_event_wait *vw)
123{ 114{
124 unsigned long flags; 115 unsigned long flags;
125 /* Prepare the event */ 116 /* Prepare the event */
@@ -129,8 +120,18 @@ static void vt_event_wait(struct vt_event_wait *vw)
129 spin_lock_irqsave(&vt_event_lock, flags); 120 spin_lock_irqsave(&vt_event_lock, flags);
130 list_add(&vw->list, &vt_events); 121 list_add(&vw->list, &vt_events);
131 spin_unlock_irqrestore(&vt_event_lock, flags); 122 spin_unlock_irqrestore(&vt_event_lock, flags);
123}
124
125static void __vt_event_wait(struct vt_event_wait *vw)
126{
132 /* Wait for it to pass */ 127 /* Wait for it to pass */
133 wait_event_interruptible(vt_event_waitqueue, vw->done); 128 wait_event_interruptible(vt_event_waitqueue, vw->done);
129}
130
131static void __vt_event_dequeue(struct vt_event_wait *vw)
132{
133 unsigned long flags;
134
134 /* Dequeue it */ 135 /* Dequeue it */
135 spin_lock_irqsave(&vt_event_lock, flags); 136 spin_lock_irqsave(&vt_event_lock, flags);
136 list_del(&vw->list); 137 list_del(&vw->list);
@@ -138,6 +139,22 @@ static void vt_event_wait(struct vt_event_wait *vw)
138} 139}
139 140
140/** 141/**
142 * vt_event_wait - wait for an event
143 * @vw: our event
144 *
145 * Waits for an event to occur which completes our vt_event_wait
146 * structure. On return the structure has wv->done set to 1 for success
147 * or 0 if some event such as a signal ended the wait.
148 */
149
150static void vt_event_wait(struct vt_event_wait *vw)
151{
152 __vt_event_queue(vw);
153 __vt_event_wait(vw);
154 __vt_event_dequeue(vw);
155}
156
157/**
141 * vt_event_wait_ioctl - event ioctl handler 158 * vt_event_wait_ioctl - event ioctl handler
142 * @arg: argument to ioctl 159 * @arg: argument to ioctl
143 * 160 *
@@ -177,10 +194,14 @@ int vt_waitactive(int n)
177{ 194{
178 struct vt_event_wait vw; 195 struct vt_event_wait vw;
179 do { 196 do {
180 if (n == fg_console + 1)
181 break;
182 vw.event.event = VT_EVENT_SWITCH; 197 vw.event.event = VT_EVENT_SWITCH;
183 vt_event_wait(&vw); 198 __vt_event_queue(&vw);
199 if (n == fg_console + 1) {
200 __vt_event_dequeue(&vw);
201 break;
202 }
203 __vt_event_wait(&vw);
204 __vt_event_dequeue(&vw);
184 if (vw.done == 0) 205 if (vw.done == 0)
185 return -EINTR; 206 return -EINTR;
186 } while (vw.event.newev != n); 207 } while (vw.event.newev != n);
diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c
index d47eb06fe463..7ae9af6b2a54 100644
--- a/drivers/usb/serial/metro-usb.c
+++ b/drivers/usb/serial/metro-usb.c
@@ -130,20 +130,14 @@ static void metrousb_read_int_callback(struct urb *urb)
130 130
131 /* Set the data read from the usb port into the serial port buffer. */ 131 /* Set the data read from the usb port into the serial port buffer. */
132 tty = tty_port_tty_get(&port->port); 132 tty = tty_port_tty_get(&port->port);
133 if (!tty) {
134 dev_err(&port->dev, "%s - bad tty pointer - exiting\n",
135 __func__);
136 return;
137 }
138
139 if (tty && urb->actual_length) { 133 if (tty && urb->actual_length) {
140 /* Loop through the data copying each byte to the tty layer. */ 134 /* Loop through the data copying each byte to the tty layer. */
141 tty_insert_flip_string(tty, data, urb->actual_length); 135 tty_insert_flip_string(tty, data, urb->actual_length);
142 136
143 /* Force the data to the tty layer. */ 137 /* Force the data to the tty layer. */
144 tty_flip_buffer_push(tty); 138 tty_flip_buffer_push(tty);
139 tty_kref_put(tty);
145 } 140 }
146 tty_kref_put(tty);
147 141
148 /* Set any port variables. */ 142 /* Set any port variables. */
149 spin_lock_irqsave(&metro_priv->lock, flags); 143 spin_lock_irqsave(&metro_priv->lock, flags);
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 27483f91a4a3..da67abb1945e 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -207,7 +207,7 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
207 if (retval) 207 if (retval)
208 goto error_get_interface; 208 goto error_get_interface;
209 209
210 retval = tty_standard_install(driver, tty); 210 retval = tty_port_install(&port->port, driver, tty);
211 if (retval) 211 if (retval)
212 goto error_init_termios; 212 goto error_init_termios;
213 213
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index 8760be30b375..cf41085e3331 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -84,7 +84,6 @@ header-y += capability.h
84header-y += capi.h 84header-y += capi.h
85header-y += cciss_defs.h 85header-y += cciss_defs.h
86header-y += cciss_ioctl.h 86header-y += cciss_ioctl.h
87header-y += cdk.h
88header-y += cdrom.h 87header-y += cdrom.h
89header-y += cgroupstats.h 88header-y += cgroupstats.h
90header-y += chio.h 89header-y += chio.h
@@ -93,7 +92,6 @@ header-y += cn_proc.h
93header-y += coda.h 92header-y += coda.h
94header-y += coda_psdev.h 93header-y += coda_psdev.h
95header-y += coff.h 94header-y += coff.h
96header-y += comstats.h
97header-y += connector.h 95header-y += connector.h
98header-y += const.h 96header-y += const.h
99header-y += cramfs_fs.h 97header-y += cramfs_fs.h
@@ -140,7 +138,6 @@ header-y += fuse.h
140header-y += futex.h 138header-y += futex.h
141header-y += gameport.h 139header-y += gameport.h
142header-y += gen_stats.h 140header-y += gen_stats.h
143header-y += generic_serial.h
144header-y += genetlink.h 141header-y += genetlink.h
145header-y += gfs2_ondisk.h 142header-y += gfs2_ondisk.h
146header-y += gigaset_dev.h 143header-y += gigaset_dev.h
diff --git a/include/linux/cd1400.h b/include/linux/cd1400.h
deleted file mode 100644
index 1dc3ab0523fd..000000000000
--- a/include/linux/cd1400.h
+++ /dev/null
@@ -1,292 +0,0 @@
1/*****************************************************************************/
2
3/*
4 * cd1400.h -- cd1400 UART hardware info.
5 *
6 * Copyright (C) 1996-1998 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24/*****************************************************************************/
25#ifndef _CD1400_H
26#define _CD1400_H
27/*****************************************************************************/
28
29/*
30 * Define the number of async ports per cd1400 uart chip.
31 */
32#define CD1400_PORTS 4
33
34/*
35 * Define the cd1400 uarts internal FIFO sizes.
36 */
37#define CD1400_TXFIFOSIZE 12
38#define CD1400_RXFIFOSIZE 12
39
40/*
41 * Local RX FIFO thresh hold level. Also define the RTS thresh hold
42 * based on the RX thresh hold.
43 */
44#define FIFO_RXTHRESHOLD 6
45#define FIFO_RTSTHRESHOLD 7
46
47/*****************************************************************************/
48
49/*
50 * Define the cd1400 register addresses. These are all the valid
51 * registers with the cd1400. Some are global, some virtual, some
52 * per port.
53 */
54#define GFRCR 0x40
55#define CAR 0x68
56#define GCR 0x4b
57#define SVRR 0x67
58#define RICR 0x44
59#define TICR 0x45
60#define MICR 0x46
61#define RIR 0x6b
62#define TIR 0x6a
63#define MIR 0x69
64#define PPR 0x7e
65
66#define RIVR 0x43
67#define TIVR 0x42
68#define MIVR 0x41
69#define TDR 0x63
70#define RDSR 0x62
71#define MISR 0x4c
72#define EOSRR 0x60
73
74#define LIVR 0x18
75#define CCR 0x05
76#define SRER 0x06
77#define COR1 0x08
78#define COR2 0x09
79#define COR3 0x0a
80#define COR4 0x1e
81#define COR5 0x1f
82#define CCSR 0x0b
83#define RDCR 0x0e
84#define SCHR1 0x1a
85#define SCHR2 0x1b
86#define SCHR3 0x1c
87#define SCHR4 0x1d
88#define SCRL 0x22
89#define SCRH 0x23
90#define LNC 0x24
91#define MCOR1 0x15
92#define MCOR2 0x16
93#define RTPR 0x21
94#define MSVR1 0x6c
95#define MSVR2 0x6d
96#define PSVR 0x6f
97#define RBPR 0x78
98#define RCOR 0x7c
99#define TBPR 0x72
100#define TCOR 0x76
101
102/*****************************************************************************/
103
104/*
105 * Define the set of baud rate clock divisors.
106 */
107#define CD1400_CLK0 8
108#define CD1400_CLK1 32
109#define CD1400_CLK2 128
110#define CD1400_CLK3 512
111#define CD1400_CLK4 2048
112
113#define CD1400_NUMCLKS 5
114
115/*****************************************************************************/
116
117/*
118 * Define the clock pre-scalar value to be a 5 ms clock. This should be
119 * OK for now. It would probably be better to make it 10 ms, but we
120 * can't fit that divisor into 8 bits!
121 */
122#define PPR_SCALAR 244
123
124/*****************************************************************************/
125
126/*
127 * Define values used to set character size options.
128 */
129#define COR1_CHL5 0x00
130#define COR1_CHL6 0x01
131#define COR1_CHL7 0x02
132#define COR1_CHL8 0x03
133
134/*
135 * Define values used to set the number of stop bits.
136 */
137#define COR1_STOP1 0x00
138#define COR1_STOP15 0x04
139#define COR1_STOP2 0x08
140
141/*
142 * Define values used to set the parity scheme in use.
143 */
144#define COR1_PARNONE 0x00
145#define COR1_PARFORCE 0x20
146#define COR1_PARENB 0x40
147#define COR1_PARIGNORE 0x10
148
149#define COR1_PARODD 0x80
150#define COR1_PAREVEN 0x00
151
152#define COR2_IXM 0x80
153#define COR2_TXIBE 0x40
154#define COR2_ETC 0x20
155#define COR2_LLM 0x10
156#define COR2_RLM 0x08
157#define COR2_RTSAO 0x04
158#define COR2_CTSAE 0x02
159
160#define COR3_SCDRNG 0x80
161#define COR3_SCD34 0x40
162#define COR3_FCT 0x20
163#define COR3_SCD12 0x10
164
165/*
166 * Define values used by COR4.
167 */
168#define COR4_BRKINT 0x08
169#define COR4_IGNBRK 0x18
170
171/*****************************************************************************/
172
173/*
174 * Define the modem control register values.
175 * Note that the actual hardware is a little different to the conventional
176 * pin names on the cd1400.
177 */
178#define MSVR1_DTR 0x01
179#define MSVR1_DSR 0x10
180#define MSVR1_RI 0x20
181#define MSVR1_CTS 0x40
182#define MSVR1_DCD 0x80
183
184#define MSVR2_RTS 0x02
185#define MSVR2_DSR 0x10
186#define MSVR2_RI 0x20
187#define MSVR2_CTS 0x40
188#define MSVR2_DCD 0x80
189
190#define MCOR1_DCD 0x80
191#define MCOR1_CTS 0x40
192#define MCOR1_RI 0x20
193#define MCOR1_DSR 0x10
194
195#define MCOR2_DCD 0x80
196#define MCOR2_CTS 0x40
197#define MCOR2_RI 0x20
198#define MCOR2_DSR 0x10
199
200/*****************************************************************************/
201
202/*
203 * Define the bits used with the service (interrupt) enable register.
204 */
205#define SRER_NNDT 0x01
206#define SRER_TXEMPTY 0x02
207#define SRER_TXDATA 0x04
208#define SRER_RXDATA 0x10
209#define SRER_MODEM 0x80
210
211/*****************************************************************************/
212
213/*
214 * Define operational commands for the command register.
215 */
216#define CCR_RESET 0x80
217#define CCR_CORCHANGE 0x4e
218#define CCR_SENDCH 0x20
219#define CCR_CHANCTRL 0x10
220
221#define CCR_TXENABLE (CCR_CHANCTRL | 0x08)
222#define CCR_TXDISABLE (CCR_CHANCTRL | 0x04)
223#define CCR_RXENABLE (CCR_CHANCTRL | 0x02)
224#define CCR_RXDISABLE (CCR_CHANCTRL | 0x01)
225
226#define CCR_SENDSCHR1 (CCR_SENDCH | 0x01)
227#define CCR_SENDSCHR2 (CCR_SENDCH | 0x02)
228#define CCR_SENDSCHR3 (CCR_SENDCH | 0x03)
229#define CCR_SENDSCHR4 (CCR_SENDCH | 0x04)
230
231#define CCR_RESETCHAN (CCR_RESET | 0x00)
232#define CCR_RESETFULL (CCR_RESET | 0x01)
233#define CCR_TXFLUSHFIFO (CCR_RESET | 0x02)
234
235#define CCR_MAXWAIT 10000
236
237/*****************************************************************************/
238
239/*
240 * Define the valid acknowledgement types (for hw ack cycle).
241 */
242#define ACK_TYPMASK 0x07
243#define ACK_TYPTX 0x02
244#define ACK_TYPMDM 0x01
245#define ACK_TYPRXGOOD 0x03
246#define ACK_TYPRXBAD 0x07
247
248#define SVRR_RX 0x01
249#define SVRR_TX 0x02
250#define SVRR_MDM 0x04
251
252#define ST_OVERRUN 0x01
253#define ST_FRAMING 0x02
254#define ST_PARITY 0x04
255#define ST_BREAK 0x08
256#define ST_SCHAR1 0x10
257#define ST_SCHAR2 0x20
258#define ST_SCHAR3 0x30
259#define ST_SCHAR4 0x40
260#define ST_RANGE 0x70
261#define ST_SCHARMASK 0x70
262#define ST_TIMEOUT 0x80
263
264#define MISR_DCD 0x80
265#define MISR_CTS 0x40
266#define MISR_RI 0x20
267#define MISR_DSR 0x10
268
269/*****************************************************************************/
270
271/*
272 * Defines for the CCSR status register.
273 */
274#define CCSR_RXENABLED 0x80
275#define CCSR_RXFLOWON 0x40
276#define CCSR_RXFLOWOFF 0x20
277#define CCSR_TXENABLED 0x08
278#define CCSR_TXFLOWON 0x04
279#define CCSR_TXFLOWOFF 0x02
280
281/*****************************************************************************/
282
283/*
284 * Define the embedded commands.
285 */
286#define ETC_CMD 0x00
287#define ETC_STARTBREAK 0x81
288#define ETC_DELAY 0x82
289#define ETC_STOPBREAK 0x83
290
291/*****************************************************************************/
292#endif
diff --git a/include/linux/cdk.h b/include/linux/cdk.h
deleted file mode 100644
index 80093a8d4f64..000000000000
--- a/include/linux/cdk.h
+++ /dev/null
@@ -1,486 +0,0 @@
1/*****************************************************************************/
2
3/*
4 * cdk.h -- CDK interface definitions.
5 *
6 * Copyright (C) 1996-1998 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24/*****************************************************************************/
25#ifndef _CDK_H
26#define _CDK_H
27/*****************************************************************************/
28
29#pragma pack(2)
30
31/*
32 * The following set of definitions is used to communicate with the
33 * shared memory interface of the Stallion intelligent multiport serial
34 * boards. The definitions in this file are taken directly from the
35 * document titled "Generic Stackable Interface, Downloader and
36 * Communications Development Kit".
37 */
38
39/*
40 * Define the set of important shared memory addresses. These are
41 * required to initialize the board and get things started. All of these
42 * addresses are relative to the start of the shared memory.
43 */
44#define CDK_SIGADDR 0x200
45#define CDK_FEATADDR 0x280
46#define CDK_CDKADDR 0x300
47#define CDK_RDYADDR 0x262
48
49#define CDK_ALIVEMARKER 13
50
51/*
52 * On hardware power up the ROMs located on the EasyConnection 8/64 will
53 * fill out the following signature information into shared memory. This
54 * way the host system can quickly determine that the board is present
55 * and is operational.
56 */
57typedef struct cdkecpsig {
58 unsigned long magic;
59 unsigned short romver;
60 unsigned short cputype;
61 unsigned char panelid[8];
62} cdkecpsig_t;
63
64#define ECP_MAGIC 0x21504345
65
66/*
67 * On hardware power up the ROMs located on the ONboard, Stallion and
68 * Brumbys will fill out the following signature information into shared
69 * memory. This way the host system can quickly determine that the board
70 * is present and is operational.
71 */
72typedef struct cdkonbsig {
73 unsigned short magic0;
74 unsigned short magic1;
75 unsigned short magic2;
76 unsigned short magic3;
77 unsigned short romver;
78 unsigned short memoff;
79 unsigned short memseg;
80 unsigned short amask0;
81 unsigned short pic;
82 unsigned short status;
83 unsigned short btype;
84 unsigned short clkticks;
85 unsigned short clkspeed;
86 unsigned short amask1;
87 unsigned short amask2;
88} cdkonbsig_t;
89
90#define ONB_MAGIC0 0xf2a7
91#define ONB_MAGIC1 0xa149
92#define ONB_MAGIC2 0x6352
93#define ONB_MAGIC3 0xf121
94
95/*
96 * Define the feature area structure. The feature area is the set of
97 * startup parameters used by the slave image when it starts executing.
98 * They allow for the specification of buffer sizes, debug trace, etc.
99 */
100typedef struct cdkfeature {
101 unsigned long debug;
102 unsigned long banner;
103 unsigned long etype;
104 unsigned long nrdevs;
105 unsigned long brdspec;
106 unsigned long txrqsize;
107 unsigned long rxrqsize;
108 unsigned long flags;
109} cdkfeature_t;
110
111#define ETYP_DDK 0
112#define ETYP_CDK 1
113
114/*
115 * Define the CDK header structure. This is the info that the slave
116 * environment sets up after it has been downloaded and started. It
117 * essentially provides a memory map for the shared memory interface.
118 */
119typedef struct cdkhdr {
120 unsigned short command;
121 unsigned short status;
122 unsigned short port;
123 unsigned short mode;
124 unsigned long cmd_buf[14];
125 unsigned short alive_cnt;
126 unsigned short intrpt_mode;
127 unsigned char intrpt_id[8];
128 unsigned char ver_release;
129 unsigned char ver_modification;
130 unsigned char ver_fix;
131 unsigned char deadman_restart;
132 unsigned short deadman;
133 unsigned short nrdevs;
134 unsigned long memp;
135 unsigned long hostp;
136 unsigned long slavep;
137 unsigned char hostreq;
138 unsigned char slavereq;
139 unsigned char cmd_reserved[30];
140} cdkhdr_t;
141
142#define MODE_DDK 0
143#define MODE_CDK 1
144
145#define IMD_INTR 0x0
146#define IMD_PPINTR 0x1
147#define IMD_POLL 0xff
148
149/*
150 * Define the memory mapping structure. This structure is pointed to by
151 * the memp field in the stlcdkhdr struct. As many as these structures
152 * as required are laid out in shared memory to define how the rest of
153 * shared memory is divided up. There will be one for each port.
154 */
155typedef struct cdkmem {
156 unsigned short dtype;
157 unsigned long offset;
158} cdkmem_t;
159
160#define TYP_UNDEFINED 0x0
161#define TYP_ASYNCTRL 0x1
162#define TYP_ASYNC 0x20
163#define TYP_PARALLEL 0x40
164#define TYP_SYNCX21 0x60
165
166/*****************************************************************************/
167
168/*
169 * Following is a set of defines and structures used to actually deal
170 * with the serial ports on the board. Firstly is the set of commands
171 * that can be applied to ports.
172 */
173#define ASYCMD (((unsigned long) 'a') << 8)
174
175#define A_NULL (ASYCMD | 0)
176#define A_FLUSH (ASYCMD | 1)
177#define A_BREAK (ASYCMD | 2)
178#define A_GETPORT (ASYCMD | 3)
179#define A_SETPORT (ASYCMD | 4)
180#define A_SETPORTF (ASYCMD | 5)
181#define A_SETPORTFTX (ASYCMD | 6)
182#define A_SETPORTFRX (ASYCMD | 7)
183#define A_GETSIGNALS (ASYCMD | 8)
184#define A_SETSIGNALS (ASYCMD | 9)
185#define A_SETSIGNALSF (ASYCMD | 10)
186#define A_SETSIGNALSFTX (ASYCMD | 11)
187#define A_SETSIGNALSFRX (ASYCMD | 12)
188#define A_GETNOTIFY (ASYCMD | 13)
189#define A_SETNOTIFY (ASYCMD | 14)
190#define A_NOTIFY (ASYCMD | 15)
191#define A_PORTCTRL (ASYCMD | 16)
192#define A_GETSTATS (ASYCMD | 17)
193#define A_RQSTATE (ASYCMD | 18)
194#define A_FLOWSTATE (ASYCMD | 19)
195#define A_CLEARSTATS (ASYCMD | 20)
196
197/*
198 * Define those arguments used for simple commands.
199 */
200#define FLUSHRX 0x1
201#define FLUSHTX 0x2
202
203#define BREAKON -1
204#define BREAKOFF -2
205
206/*
207 * Define the port setting structure, and all those defines that go along
208 * with it. Basically this structure defines the characteristics of this
209 * port: baud rate, chars, parity, input/output char cooking etc.
210 */
211typedef struct asyport {
212 unsigned long baudout;
213 unsigned long baudin;
214 unsigned long iflag;
215 unsigned long oflag;
216 unsigned long lflag;
217 unsigned long pflag;
218 unsigned long flow;
219 unsigned long spare1;
220 unsigned short vtime;
221 unsigned short vmin;
222 unsigned short txlo;
223 unsigned short txhi;
224 unsigned short rxlo;
225 unsigned short rxhi;
226 unsigned short rxhog;
227 unsigned short spare2;
228 unsigned char csize;
229 unsigned char stopbs;
230 unsigned char parity;
231 unsigned char stopin;
232 unsigned char startin;
233 unsigned char stopout;
234 unsigned char startout;
235 unsigned char parmark;
236 unsigned char brkmark;
237 unsigned char cc[11];
238} asyport_t;
239
240#define PT_STOP1 0x0
241#define PT_STOP15 0x1
242#define PT_STOP2 0x2
243
244#define PT_NOPARITY 0x0
245#define PT_ODDPARITY 0x1
246#define PT_EVENPARITY 0x2
247#define PT_MARKPARITY 0x3
248#define PT_SPACEPARITY 0x4
249
250#define F_NONE 0x0
251#define F_IXON 0x1
252#define F_IXOFF 0x2
253#define F_IXANY 0x4
254#define F_IOXANY 0x8
255#define F_RTSFLOW 0x10
256#define F_CTSFLOW 0x20
257#define F_DTRFLOW 0x40
258#define F_DCDFLOW 0x80
259#define F_DSROFLOW 0x100
260#define F_DSRIFLOW 0x200
261
262#define FI_NORX 0x1
263#define FI_RAW 0x2
264#define FI_ISTRIP 0x4
265#define FI_UCLC 0x8
266#define FI_INLCR 0x10
267#define FI_ICRNL 0x20
268#define FI_IGNCR 0x40
269#define FI_IGNBREAK 0x80
270#define FI_DSCRDBREAK 0x100
271#define FI_1MARKBREAK 0x200
272#define FI_2MARKBREAK 0x400
273#define FI_XCHNGBREAK 0x800
274#define FI_IGNRXERRS 0x1000
275#define FI_DSCDRXERRS 0x2000
276#define FI_1MARKRXERRS 0x4000
277#define FI_2MARKRXERRS 0x8000
278#define FI_XCHNGRXERRS 0x10000
279#define FI_DSCRDNULL 0x20000
280
281#define FO_OLCUC 0x1
282#define FO_ONLCR 0x2
283#define FO_OOCRNL 0x4
284#define FO_ONOCR 0x8
285#define FO_ONLRET 0x10
286#define FO_ONL 0x20
287#define FO_OBS 0x40
288#define FO_OVT 0x80
289#define FO_OFF 0x100
290#define FO_OTAB1 0x200
291#define FO_OTAB2 0x400
292#define FO_OTAB3 0x800
293#define FO_OCR1 0x1000
294#define FO_OCR2 0x2000
295#define FO_OCR3 0x4000
296#define FO_OFILL 0x8000
297#define FO_ODELL 0x10000
298
299#define P_RTSLOCK 0x1
300#define P_CTSLOCK 0x2
301#define P_MAPRTS 0x4
302#define P_MAPCTS 0x8
303#define P_LOOPBACK 0x10
304#define P_DTRFOLLOW 0x20
305#define P_FAKEDCD 0x40
306
307#define P_RXIMIN 0x10000
308#define P_RXITIME 0x20000
309#define P_RXTHOLD 0x40000
310
311/*
312 * Define a structure to communicate serial port signal and data state
313 * information.
314 */
315typedef struct asysigs {
316 unsigned long data;
317 unsigned long signal;
318 unsigned long sigvalue;
319} asysigs_t;
320
321#define DT_TXBUSY 0x1
322#define DT_TXEMPTY 0x2
323#define DT_TXLOW 0x4
324#define DT_TXHIGH 0x8
325#define DT_TXFULL 0x10
326#define DT_TXHOG 0x20
327#define DT_TXFLOWED 0x40
328#define DT_TXBREAK 0x80
329
330#define DT_RXBUSY 0x100
331#define DT_RXEMPTY 0x200
332#define DT_RXLOW 0x400
333#define DT_RXHIGH 0x800
334#define DT_RXFULL 0x1000
335#define DT_RXHOG 0x2000
336#define DT_RXFLOWED 0x4000
337#define DT_RXBREAK 0x8000
338
339#define SG_DTR 0x1
340#define SG_DCD 0x2
341#define SG_RTS 0x4
342#define SG_CTS 0x8
343#define SG_DSR 0x10
344#define SG_RI 0x20
345
346/*
347 * Define the notification setting structure. This is used to tell the
348 * port what events we want to be informed about. Fields here use the
349 * same defines as for the asysigs structure above.
350 */
351typedef struct asynotify {
352 unsigned long ctrl;
353 unsigned long data;
354 unsigned long signal;
355 unsigned long sigvalue;
356} asynotify_t;
357
358/*
359 * Define the port control structure. It is used to do fine grain
360 * control operations on the port.
361 */
362typedef struct {
363 unsigned long rxctrl;
364 unsigned long txctrl;
365 char rximdch;
366 char tximdch;
367 char spare1;
368 char spare2;
369} asyctrl_t;
370
371#define CT_ENABLE 0x1
372#define CT_DISABLE 0x2
373#define CT_STOP 0x4
374#define CT_START 0x8
375#define CT_STARTFLOW 0x10
376#define CT_STOPFLOW 0x20
377#define CT_SENDCHR 0x40
378
379/*
380 * Define the stats structure kept for each port. This is a useful set
381 * of data collected for each port on the slave. The A_GETSTATS command
382 * is used to retrieve this data from the slave.
383 */
384typedef struct asystats {
385 unsigned long opens;
386 unsigned long txchars;
387 unsigned long rxchars;
388 unsigned long txringq;
389 unsigned long rxringq;
390 unsigned long txmsgs;
391 unsigned long rxmsgs;
392 unsigned long txflushes;
393 unsigned long rxflushes;
394 unsigned long overruns;
395 unsigned long framing;
396 unsigned long parity;
397 unsigned long ringover;
398 unsigned long lost;
399 unsigned long rxstart;
400 unsigned long rxstop;
401 unsigned long txstart;
402 unsigned long txstop;
403 unsigned long dcdcnt;
404 unsigned long dtrcnt;
405 unsigned long ctscnt;
406 unsigned long rtscnt;
407 unsigned long dsrcnt;
408 unsigned long ricnt;
409 unsigned long txbreaks;
410 unsigned long rxbreaks;
411 unsigned long signals;
412 unsigned long state;
413 unsigned long hwid;
414} asystats_t;
415
416/*****************************************************************************/
417
418/*
419 * All command and control communication with a device on the slave is
420 * via a control block in shared memory. Each device has its own control
421 * block, defined by the following structure. The control block allows
422 * the host to open, close and control the device on the slave.
423 */
424typedef struct cdkctrl {
425 unsigned char open;
426 unsigned char close;
427 unsigned long openarg;
428 unsigned long closearg;
429 unsigned long cmd;
430 unsigned long status;
431 unsigned long args[32];
432} cdkctrl_t;
433
434/*
435 * Each device on the slave passes data to and from the host via a ring
436 * queue in shared memory. Define a ring queue structure to hold the
437 * vital information about each ring queue. Two ring queues will be
438 * allocated for each port, one for receive data and one for transmit
439 * data.
440 */
441typedef struct cdkasyrq {
442 unsigned long offset;
443 unsigned short size;
444 unsigned short head;
445 unsigned short tail;
446} cdkasyrq_t;
447
448/*
449 * Each asynchronous port is defined in shared memory by the following
450 * structure. It contains a control block to command a device, and also
451 * the necessary data channel information as well.
452 */
453typedef struct cdkasy {
454 cdkctrl_t ctrl;
455 unsigned short notify;
456 asynotify_t changed;
457 unsigned short receive;
458 cdkasyrq_t rxq;
459 unsigned short transmit;
460 cdkasyrq_t txq;
461} cdkasy_t;
462
463#pragma pack()
464
465/*****************************************************************************/
466
467/*
468 * Define the set of ioctls used by the driver to do special things
469 * to the board. These include interrupting it, and initializing
470 * the driver after board startup and shutdown.
471 */
472#include <linux/ioctl.h>
473
474#define STL_BINTR _IO('s',20)
475#define STL_BSTART _IO('s',21)
476#define STL_BSTOP _IO('s',22)
477#define STL_BRESET _IO('s',23)
478
479/*
480 * Define a set of ioctl extensions, used to get at special stuff.
481 */
482#define STL_GETPFLAG _IO('s',80)
483#define STL_SETPFLAG _IO('s',81)
484
485/*****************************************************************************/
486#endif
diff --git a/include/linux/comstats.h b/include/linux/comstats.h
deleted file mode 100644
index 3f5ea8e8026d..000000000000
--- a/include/linux/comstats.h
+++ /dev/null
@@ -1,119 +0,0 @@
1/*****************************************************************************/
2
3/*
4 * comstats.h -- Serial Port Stats.
5 *
6 * Copyright (C) 1996-1998 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24/*****************************************************************************/
25#ifndef _COMSTATS_H
26#define _COMSTATS_H
27/*****************************************************************************/
28
29/*
30 * Serial port stats structure. The structure itself is UART
31 * independent, but some fields may be UART/driver specific (for
32 * example state).
33 */
34
35typedef struct {
36 unsigned long brd;
37 unsigned long panel;
38 unsigned long port;
39 unsigned long hwid;
40 unsigned long type;
41 unsigned long txtotal;
42 unsigned long rxtotal;
43 unsigned long txbuffered;
44 unsigned long rxbuffered;
45 unsigned long rxoverrun;
46 unsigned long rxparity;
47 unsigned long rxframing;
48 unsigned long rxlost;
49 unsigned long txbreaks;
50 unsigned long rxbreaks;
51 unsigned long txxon;
52 unsigned long txxoff;
53 unsigned long rxxon;
54 unsigned long rxxoff;
55 unsigned long txctson;
56 unsigned long txctsoff;
57 unsigned long rxrtson;
58 unsigned long rxrtsoff;
59 unsigned long modem;
60 unsigned long state;
61 unsigned long flags;
62 unsigned long ttystate;
63 unsigned long cflags;
64 unsigned long iflags;
65 unsigned long oflags;
66 unsigned long lflags;
67 unsigned long signals;
68} comstats_t;
69
70
71/*
72 * Board stats structure. Returns useful info about the board.
73 */
74
75#define COM_MAXPANELS 8
76
77typedef struct {
78 unsigned long panel;
79 unsigned long type;
80 unsigned long hwid;
81 unsigned long nrports;
82} companel_t;
83
84typedef struct {
85 unsigned long brd;
86 unsigned long type;
87 unsigned long hwid;
88 unsigned long state;
89 unsigned long ioaddr;
90 unsigned long ioaddr2;
91 unsigned long memaddr;
92 unsigned long irq;
93 unsigned long nrpanels;
94 unsigned long nrports;
95 companel_t panels[COM_MAXPANELS];
96} combrd_t;
97
98
99/*
100 * Define the ioctl operations for stats stuff.
101 */
102#include <linux/ioctl.h>
103
104#define COM_GETPORTSTATS _IO('c',30)
105#define COM_CLRPORTSTATS _IO('c',31)
106#define COM_GETBRDSTATS _IO('c',32)
107
108
109/*
110 * Define the set of ioctls that give user level access to the
111 * private port, panel and board structures. The argument required
112 * will be driver dependent!
113 */
114#define COM_READPORT _IO('c',40)
115#define COM_READBOARD _IO('c',41)
116#define COM_READPANEL _IO('c',42)
117
118/*****************************************************************************/
119#endif
diff --git a/include/linux/generic_serial.h b/include/linux/generic_serial.h
deleted file mode 100644
index 79b3eb37243a..000000000000
--- a/include/linux/generic_serial.h
+++ /dev/null
@@ -1,35 +0,0 @@
1/*
2 * generic_serial.h
3 *
4 * Copyright (C) 1998 R.E.Wolff@BitWizard.nl
5 *
6 * written for the SX serial driver.
7 *
8 * Version 0.1 -- December, 1998.
9 */
10
11#ifndef GENERIC_SERIAL_H
12#define GENERIC_SERIAL_H
13
14#warning Use of this header is deprecated.
15#warning Since nobody sets the constants defined here for you, you should not, in any case, use them. Including the header is thus pointless.
16
17/* Flags */
18/* Warning: serial.h defines some ASYNC_ flags, they say they are "only"
19 used in serial.c, but they are also used in all other serial drivers.
20 Make sure they don't clash with these here... */
21#define GS_TX_INTEN 0x00800000
22#define GS_RX_INTEN 0x00400000
23#define GS_ACTIVE 0x00200000
24
25#define GS_TYPE_NORMAL 1
26
27#define GS_DEBUG_FLUSH 0x00000001
28#define GS_DEBUG_BTR 0x00000002
29#define GS_DEBUG_TERMIOS 0x00000004
30#define GS_DEBUG_STUFF 0x00000008
31#define GS_DEBUG_CLOSE 0x00000010
32#define GS_DEBUG_FLOW 0x00000020
33#define GS_DEBUG_WRITE 0x00000040
34
35#endif
diff --git a/include/linux/istallion.h b/include/linux/istallion.h
deleted file mode 100644
index ad700a60c158..000000000000
--- a/include/linux/istallion.h
+++ /dev/null
@@ -1,123 +0,0 @@
1/*****************************************************************************/
2
3/*
4 * istallion.h -- stallion intelligent multiport serial driver.
5 *
6 * Copyright (C) 1996-1998 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24/*****************************************************************************/
25#ifndef _ISTALLION_H
26#define _ISTALLION_H
27/*****************************************************************************/
28
29/*
30 * Define important driver constants here.
31 */
32#define STL_MAXBRDS 4
33#define STL_MAXPANELS 4
34#define STL_MAXPORTS 64
35#define STL_MAXCHANS (STL_MAXPORTS + 1)
36#define STL_MAXDEVS (STL_MAXBRDS * STL_MAXPORTS)
37
38
39/*
40 * Define a set of structures to hold all the board/panel/port info
41 * for our ports. These will be dynamically allocated as required at
42 * driver initialization time.
43 */
44
45/*
46 * Port and board structures to hold status info about each object.
47 * The board structure contains pointers to structures for each port
48 * connected to it. Panels are not distinguished here, since
49 * communication with the slave board will always be on a per port
50 * basis.
51 */
52struct stliport {
53 unsigned long magic;
54 struct tty_port port;
55 unsigned int portnr;
56 unsigned int panelnr;
57 unsigned int brdnr;
58 unsigned long state;
59 unsigned int devnr;
60 int baud_base;
61 int custom_divisor;
62 int closing_wait;
63 int rc;
64 int argsize;
65 void *argp;
66 unsigned int rxmarkmsk;
67 wait_queue_head_t raw_wait;
68 struct asysigs asig;
69 unsigned long addr;
70 unsigned long rxoffset;
71 unsigned long txoffset;
72 unsigned long sigs;
73 unsigned long pflag;
74 unsigned int rxsize;
75 unsigned int txsize;
76 unsigned char reqbit;
77 unsigned char portidx;
78 unsigned char portbit;
79};
80
81/*
82 * Use a structure of function pointers to do board level operations.
83 * These include, enable/disable, paging shared memory, interrupting, etc.
84 */
85struct stlibrd {
86 unsigned long magic;
87 unsigned int brdnr;
88 unsigned int brdtype;
89 unsigned long state;
90 unsigned int nrpanels;
91 unsigned int nrports;
92 unsigned int nrdevs;
93 unsigned int iobase;
94 int iosize;
95 unsigned long memaddr;
96 void __iomem *membase;
97 unsigned long memsize;
98 int pagesize;
99 int hostoffset;
100 int slaveoffset;
101 int bitsize;
102 int enabval;
103 unsigned int panels[STL_MAXPANELS];
104 int panelids[STL_MAXPANELS];
105 void (*init)(struct stlibrd *brdp);
106 void (*enable)(struct stlibrd *brdp);
107 void (*reenable)(struct stlibrd *brdp);
108 void (*disable)(struct stlibrd *brdp);
109 void __iomem *(*getmemptr)(struct stlibrd *brdp, unsigned long offset, int line);
110 void (*intr)(struct stlibrd *brdp);
111 void (*reset)(struct stlibrd *brdp);
112 struct stliport *ports[STL_MAXPORTS];
113};
114
115
116/*
117 * Define MAGIC numbers used for above structures.
118 */
119#define STLI_PORTMAGIC 0xe671c7a1
120#define STLI_BOARDMAGIC 0x4bc6c825
121
122/*****************************************************************************/
123#endif
diff --git a/include/linux/kbd_kern.h b/include/linux/kbd_kern.h
index daf4a3a40ee0..af9137db3035 100644
--- a/include/linux/kbd_kern.h
+++ b/include/linux/kbd_kern.h
@@ -145,16 +145,4 @@ void compute_shiftstate(void);
145 145
146extern unsigned int keymap_count; 146extern unsigned int keymap_count;
147 147
148/* console.c */
149
150static inline void con_schedule_flip(struct tty_struct *t)
151{
152 unsigned long flags;
153 spin_lock_irqsave(&t->buf.lock, flags);
154 if (t->buf.tail != NULL)
155 t->buf.tail->commit = t->buf.tail->used;
156 spin_unlock_irqrestore(&t->buf.lock, flags);
157 schedule_work(&t->buf.work);
158}
159
160#endif 148#endif
diff --git a/include/linux/sc26198.h b/include/linux/sc26198.h
deleted file mode 100644
index 7ca35abad387..000000000000
--- a/include/linux/sc26198.h
+++ /dev/null
@@ -1,533 +0,0 @@
1/*****************************************************************************/
2
3/*
4 * sc26198.h -- SC26198 UART hardware info.
5 *
6 * Copyright (C) 1995-1998 Stallion Technologies
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23/*****************************************************************************/
24#ifndef _SC26198_H
25#define _SC26198_H
26/*****************************************************************************/
27
28/*
29 * Define the number of async ports per sc26198 uart device.
30 */
31#define SC26198_PORTS 8
32
33/*
34 * Baud rate timing clocks. All derived from a master 14.7456 MHz clock.
35 */
36#define SC26198_MASTERCLOCK 14745600L
37#define SC26198_DCLK (SC26198_MASTERCLOCK)
38#define SC26198_CCLK (SC26198_MASTERCLOCK / 2)
39#define SC26198_BCLK (SC26198_MASTERCLOCK / 4)
40
41/*
42 * Define internal FIFO sizes for the 26198 ports.
43 */
44#define SC26198_TXFIFOSIZE 16
45#define SC26198_RXFIFOSIZE 16
46
47/*****************************************************************************/
48
49/*
50 * Global register definitions. These registers are global to each 26198
51 * device, not specific ports on it.
52 */
53#define TSTR 0x0d
54#define GCCR 0x0f
55#define ICR 0x1b
56#define WDTRCR 0x1d
57#define IVR 0x1f
58#define BRGTRUA 0x84
59#define GPOSR 0x87
60#define GPOC 0x8b
61#define UCIR 0x8c
62#define CIR 0x8c
63#define BRGTRUB 0x8d
64#define GRXFIFO 0x8e
65#define GTXFIFO 0x8e
66#define GCCR2 0x8f
67#define BRGTRLA 0x94
68#define GPOR 0x97
69#define GPOD 0x9b
70#define BRGTCR 0x9c
71#define GICR 0x9c
72#define BRGTRLB 0x9d
73#define GIBCR 0x9d
74#define GITR 0x9f
75
76/*
77 * Per port channel registers. These are the register offsets within
78 * the port address space, so need to have the port address (0 to 7)
79 * inserted in bit positions 4:6.
80 */
81#define MR0 0x00
82#define MR1 0x01
83#define IOPCR 0x02
84#define BCRBRK 0x03
85#define BCRCOS 0x04
86#define BCRX 0x06
87#define BCRA 0x07
88#define XONCR 0x08
89#define XOFFCR 0x09
90#define ARCR 0x0a
91#define RXCSR 0x0c
92#define TXCSR 0x0e
93#define MR2 0x80
94#define SR 0x81
95#define SCCR 0x81
96#define ISR 0x82
97#define IMR 0x82
98#define TXFIFO 0x83
99#define RXFIFO 0x83
100#define IPR 0x84
101#define IOPIOR 0x85
102#define XISR 0x86
103
104/*
105 * For any given port calculate the address to use to access a specified
106 * register. This is only used for unusual access, mostly this is done
107 * through the assembler access routines.
108 */
109#define SC26198_PORTREG(port,reg) ((((port) & 0x07) << 4) | (reg))
110
111/*****************************************************************************/
112
113/*
114 * Global configuration control register bit definitions.
115 */
116#define GCCR_NOACK 0x00
117#define GCCR_IVRACK 0x02
118#define GCCR_IVRCHANACK 0x04
119#define GCCR_IVRTYPCHANACK 0x06
120#define GCCR_ASYNCCYCLE 0x00
121#define GCCR_SYNCCYCLE 0x40
122
123/*****************************************************************************/
124
125/*
126 * Mode register 0 bit definitions.
127 */
128#define MR0_ADDRNONE 0x00
129#define MR0_AUTOWAKE 0x01
130#define MR0_AUTODOZE 0x02
131#define MR0_AUTOWAKEDOZE 0x03
132#define MR0_SWFNONE 0x00
133#define MR0_SWFTX 0x04
134#define MR0_SWFRX 0x08
135#define MR0_SWFRXTX 0x0c
136#define MR0_TXMASK 0x30
137#define MR0_TXEMPTY 0x00
138#define MR0_TXHIGH 0x10
139#define MR0_TXHALF 0x20
140#define MR0_TXRDY 0x00
141#define MR0_ADDRNT 0x00
142#define MR0_ADDRT 0x40
143#define MR0_SWFNT 0x00
144#define MR0_SWFT 0x80
145
146/*
147 * Mode register 1 bit definitions.
148 */
149#define MR1_CS5 0x00
150#define MR1_CS6 0x01
151#define MR1_CS7 0x02
152#define MR1_CS8 0x03
153#define MR1_PAREVEN 0x00
154#define MR1_PARODD 0x04
155#define MR1_PARENB 0x00
156#define MR1_PARFORCE 0x08
157#define MR1_PARNONE 0x10
158#define MR1_PARSPECIAL 0x18
159#define MR1_ERRCHAR 0x00
160#define MR1_ERRBLOCK 0x20
161#define MR1_ISRUNMASKED 0x00
162#define MR1_ISRMASKED 0x40
163#define MR1_AUTORTS 0x80
164
165/*
166 * Mode register 2 bit definitions.
167 */
168#define MR2_STOP1 0x00
169#define MR2_STOP15 0x01
170#define MR2_STOP2 0x02
171#define MR2_STOP916 0x03
172#define MR2_RXFIFORDY 0x00
173#define MR2_RXFIFOHALF 0x04
174#define MR2_RXFIFOHIGH 0x08
175#define MR2_RXFIFOFULL 0x0c
176#define MR2_AUTOCTS 0x10
177#define MR2_TXRTS 0x20
178#define MR2_MODENORM 0x00
179#define MR2_MODEAUTOECHO 0x40
180#define MR2_MODELOOP 0x80
181#define MR2_MODEREMECHO 0xc0
182
183/*****************************************************************************/
184
185/*
186 * Baud Rate Generator (BRG) selector values.
187 */
188#define BRG_50 0x00
189#define BRG_75 0x01
190#define BRG_150 0x02
191#define BRG_200 0x03
192#define BRG_300 0x04
193#define BRG_450 0x05
194#define BRG_600 0x06
195#define BRG_900 0x07
196#define BRG_1200 0x08
197#define BRG_1800 0x09
198#define BRG_2400 0x0a
199#define BRG_3600 0x0b
200#define BRG_4800 0x0c
201#define BRG_7200 0x0d
202#define BRG_9600 0x0e
203#define BRG_14400 0x0f
204#define BRG_19200 0x10
205#define BRG_28200 0x11
206#define BRG_38400 0x12
207#define BRG_57600 0x13
208#define BRG_115200 0x14
209#define BRG_230400 0x15
210#define BRG_GIN0 0x16
211#define BRG_GIN1 0x17
212#define BRG_CT0 0x18
213#define BRG_CT1 0x19
214#define BRG_RX2TX316 0x1b
215#define BRG_RX2TX31 0x1c
216
217#define SC26198_MAXBAUD 921600
218
219/*****************************************************************************/
220
221/*
222 * Command register command definitions.
223 */
224#define CR_NULL 0x04
225#define CR_ADDRNORMAL 0x0c
226#define CR_RXRESET 0x14
227#define CR_TXRESET 0x1c
228#define CR_CLEARRXERR 0x24
229#define CR_BREAKRESET 0x2c
230#define CR_TXSTARTBREAK 0x34
231#define CR_TXSTOPBREAK 0x3c
232#define CR_RTSON 0x44
233#define CR_RTSOFF 0x4c
234#define CR_ADDRINIT 0x5c
235#define CR_RXERRBLOCK 0x6c
236#define CR_TXSENDXON 0x84
237#define CR_TXSENDXOFF 0x8c
238#define CR_GANGXONSET 0x94
239#define CR_GANGXOFFSET 0x9c
240#define CR_GANGXONINIT 0xa4
241#define CR_GANGXOFFINIT 0xac
242#define CR_HOSTXON 0xb4
243#define CR_HOSTXOFF 0xbc
244#define CR_CANCELXOFF 0xc4
245#define CR_ADDRRESET 0xdc
246#define CR_RESETALLPORTS 0xf4
247#define CR_RESETALL 0xfc
248
249#define CR_RXENABLE 0x01
250#define CR_TXENABLE 0x02
251
252/*****************************************************************************/
253
254/*
255 * Channel status register.
256 */
257#define SR_RXRDY 0x01
258#define SR_RXFULL 0x02
259#define SR_TXRDY 0x04
260#define SR_TXEMPTY 0x08
261#define SR_RXOVERRUN 0x10
262#define SR_RXPARITY 0x20
263#define SR_RXFRAMING 0x40
264#define SR_RXBREAK 0x80
265
266#define SR_RXERRS (SR_RXPARITY | SR_RXFRAMING | SR_RXOVERRUN)
267
268/*****************************************************************************/
269
270/*
271 * Interrupt status register and interrupt mask register bit definitions.
272 */
273#define IR_TXRDY 0x01
274#define IR_RXRDY 0x02
275#define IR_RXBREAK 0x04
276#define IR_XONXOFF 0x10
277#define IR_ADDRRECOG 0x20
278#define IR_RXWATCHDOG 0x40
279#define IR_IOPORT 0x80
280
281/*****************************************************************************/
282
283/*
284 * Interrupt vector register field definitions.
285 */
286#define IVR_CHANMASK 0x07
287#define IVR_TYPEMASK 0x18
288#define IVR_CONSTMASK 0xc0
289
290#define IVR_RXDATA 0x10
291#define IVR_RXBADDATA 0x18
292#define IVR_TXDATA 0x08
293#define IVR_OTHER 0x00
294
295/*****************************************************************************/
296
297/*
298 * BRG timer control register bit definitions.
299 */
300#define BRGCTCR_DISABCLK0 0x00
301#define BRGCTCR_ENABCLK0 0x08
302#define BRGCTCR_DISABCLK1 0x00
303#define BRGCTCR_ENABCLK1 0x80
304
305#define BRGCTCR_0SCLK16 0x00
306#define BRGCTCR_0SCLK32 0x01
307#define BRGCTCR_0SCLK64 0x02
308#define BRGCTCR_0SCLK128 0x03
309#define BRGCTCR_0X1 0x04
310#define BRGCTCR_0X12 0x05
311#define BRGCTCR_0IO1A 0x06
312#define BRGCTCR_0GIN0 0x07
313
314#define BRGCTCR_1SCLK16 0x00
315#define BRGCTCR_1SCLK32 0x10
316#define BRGCTCR_1SCLK64 0x20
317#define BRGCTCR_1SCLK128 0x30
318#define BRGCTCR_1X1 0x40
319#define BRGCTCR_1X12 0x50
320#define BRGCTCR_1IO1B 0x60
321#define BRGCTCR_1GIN1 0x70
322
323/*****************************************************************************/
324
325/*
326 * Watch dog timer enable register.
327 */
328#define WDTRCR_ENABALL 0xff
329
330/*****************************************************************************/
331
332/*
333 * XON/XOFF interrupt status register.
334 */
335#define XISR_TXCHARMASK 0x03
336#define XISR_TXCHARNORMAL 0x00
337#define XISR_TXWAIT 0x01
338#define XISR_TXXOFFPEND 0x02
339#define XISR_TXXONPEND 0x03
340
341#define XISR_TXFLOWMASK 0x0c
342#define XISR_TXNORMAL 0x00
343#define XISR_TXSTOPPEND 0x04
344#define XISR_TXSTARTED 0x08
345#define XISR_TXSTOPPED 0x0c
346
347#define XISR_RXFLOWMASK 0x30
348#define XISR_RXFLOWNONE 0x00
349#define XISR_RXXONSENT 0x10
350#define XISR_RXXOFFSENT 0x20
351
352#define XISR_RXXONGOT 0x40
353#define XISR_RXXOFFGOT 0x80
354
355/*****************************************************************************/
356
357/*
358 * Current interrupt register.
359 */
360#define CIR_TYPEMASK 0xc0
361#define CIR_TYPEOTHER 0x00
362#define CIR_TYPETX 0x40
363#define CIR_TYPERXGOOD 0x80
364#define CIR_TYPERXBAD 0xc0
365
366#define CIR_RXDATA 0x80
367#define CIR_RXBADDATA 0x40
368#define CIR_TXDATA 0x40
369
370#define CIR_CHANMASK 0x07
371#define CIR_CNTMASK 0x38
372
373#define CIR_SUBTYPEMASK 0x38
374#define CIR_SUBNONE 0x00
375#define CIR_SUBCOS 0x08
376#define CIR_SUBADDR 0x10
377#define CIR_SUBXONXOFF 0x18
378#define CIR_SUBBREAK 0x28
379
380/*****************************************************************************/
381
382/*
383 * Global interrupting channel register.
384 */
385#define GICR_CHANMASK 0x07
386
387/*****************************************************************************/
388
389/*
390 * Global interrupting byte count register.
391 */
392#define GICR_COUNTMASK 0x0f
393
394/*****************************************************************************/
395
396/*
397 * Global interrupting type register.
398 */
399#define GITR_RXMASK 0xc0
400#define GITR_RXNONE 0x00
401#define GITR_RXBADDATA 0x80
402#define GITR_RXGOODDATA 0xc0
403#define GITR_TXDATA 0x20
404
405#define GITR_SUBTYPEMASK 0x07
406#define GITR_SUBNONE 0x00
407#define GITR_SUBCOS 0x01
408#define GITR_SUBADDR 0x02
409#define GITR_SUBXONXOFF 0x03
410#define GITR_SUBBREAK 0x05
411
412/*****************************************************************************/
413
414/*
415 * Input port change register.
416 */
417#define IPR_CTS 0x01
418#define IPR_DTR 0x02
419#define IPR_RTS 0x04
420#define IPR_DCD 0x08
421#define IPR_CTSCHANGE 0x10
422#define IPR_DTRCHANGE 0x20
423#define IPR_RTSCHANGE 0x40
424#define IPR_DCDCHANGE 0x80
425
426#define IPR_CHANGEMASK 0xf0
427
428/*****************************************************************************/
429
430/*
431 * IO port interrupt and output register.
432 */
433#define IOPR_CTS 0x01
434#define IOPR_DTR 0x02
435#define IOPR_RTS 0x04
436#define IOPR_DCD 0x08
437#define IOPR_CTSCOS 0x10
438#define IOPR_DTRCOS 0x20
439#define IOPR_RTSCOS 0x40
440#define IOPR_DCDCOS 0x80
441
442/*****************************************************************************/
443
444/*
445 * IO port configuration register.
446 */
447#define IOPCR_SETCTS 0x00
448#define IOPCR_SETDTR 0x04
449#define IOPCR_SETRTS 0x10
450#define IOPCR_SETDCD 0x00
451
452#define IOPCR_SETSIGS (IOPCR_SETRTS | IOPCR_SETRTS | IOPCR_SETDTR | IOPCR_SETDCD)
453
454/*****************************************************************************/
455
456/*
457 * General purpose output select register.
458 */
459#define GPORS_TXC1XA 0x08
460#define GPORS_TXC16XA 0x09
461#define GPORS_RXC16XA 0x0a
462#define GPORS_TXC16XB 0x0b
463#define GPORS_GPOR3 0x0c
464#define GPORS_GPOR2 0x0d
465#define GPORS_GPOR1 0x0e
466#define GPORS_GPOR0 0x0f
467
468/*****************************************************************************/
469
470/*
471 * General purpose output register.
472 */
473#define GPOR_0 0x01
474#define GPOR_1 0x02
475#define GPOR_2 0x04
476#define GPOR_3 0x08
477
478/*****************************************************************************/
479
480/*
481 * General purpose output clock register.
482 */
483#define GPORC_0NONE 0x00
484#define GPORC_0GIN0 0x01
485#define GPORC_0GIN1 0x02
486#define GPORC_0IO3A 0x02
487
488#define GPORC_1NONE 0x00
489#define GPORC_1GIN0 0x04
490#define GPORC_1GIN1 0x08
491#define GPORC_1IO3C 0x0c
492
493#define GPORC_2NONE 0x00
494#define GPORC_2GIN0 0x10
495#define GPORC_2GIN1 0x20
496#define GPORC_2IO3E 0x20
497
498#define GPORC_3NONE 0x00
499#define GPORC_3GIN0 0x40
500#define GPORC_3GIN1 0x80
501#define GPORC_3IO3G 0xc0
502
503/*****************************************************************************/
504
505/*
506 * General purpose output data register.
507 */
508#define GPOD_0MASK 0x03
509#define GPOD_0SET1 0x00
510#define GPOD_0SET0 0x01
511#define GPOD_0SETR0 0x02
512#define GPOD_0SETIO3B 0x03
513
514#define GPOD_1MASK 0x0c
515#define GPOD_1SET1 0x00
516#define GPOD_1SET0 0x04
517#define GPOD_1SETR0 0x08
518#define GPOD_1SETIO3D 0x0c
519
520#define GPOD_2MASK 0x30
521#define GPOD_2SET1 0x00
522#define GPOD_2SET0 0x10
523#define GPOD_2SETR0 0x20
524#define GPOD_2SETIO3F 0x30
525
526#define GPOD_3MASK 0xc0
527#define GPOD_3SET1 0x00
528#define GPOD_3SET0 0x40
529#define GPOD_3SETR0 0x80
530#define GPOD_3SETIO3H 0xc0
531
532/*****************************************************************************/
533#endif
diff --git a/include/linux/serial167.h b/include/linux/serial167.h
deleted file mode 100644
index 59c81b708562..000000000000
--- a/include/linux/serial167.h
+++ /dev/null
@@ -1,157 +0,0 @@
1/*
2 * serial167.h
3 *
4 * Richard Hirst [richard@sleepie.demon.co.uk]
5 *
6 * Based on cyclades.h
7 */
8
9struct cyclades_monitor {
10 unsigned long int_count;
11 unsigned long char_count;
12 unsigned long char_max;
13 unsigned long char_last;
14};
15
16/*
17 * This is our internal structure for each serial port's state.
18 *
19 * Many fields are paralleled by the structure used by the serial_struct
20 * structure.
21 *
22 * For definitions of the flags field, see tty.h
23 */
24
25struct cyclades_port {
26 int magic;
27 int type;
28 int card;
29 int line;
30 int flags; /* defined in tty.h */
31 struct tty_struct *tty;
32 int read_status_mask;
33 int timeout;
34 int xmit_fifo_size;
35 int cor1,cor2,cor3,cor4,cor5,cor6,cor7;
36 int tbpr,tco,rbpr,rco;
37 int ignore_status_mask;
38 int close_delay;
39 int IER; /* Interrupt Enable Register */
40 unsigned long last_active;
41 int count; /* # of fd on device */
42 int x_char; /* to be pushed out ASAP */
43 int x_break;
44 int blocked_open; /* # of blocked opens */
45 unsigned char *xmit_buf;
46 int xmit_head;
47 int xmit_tail;
48 int xmit_cnt;
49 int default_threshold;
50 int default_timeout;
51 wait_queue_head_t open_wait;
52 wait_queue_head_t close_wait;
53 struct cyclades_monitor mon;
54};
55
56#define CYCLADES_MAGIC 0x4359
57
58#define CYGETMON 0x435901
59#define CYGETTHRESH 0x435902
60#define CYSETTHRESH 0x435903
61#define CYGETDEFTHRESH 0x435904
62#define CYSETDEFTHRESH 0x435905
63#define CYGETTIMEOUT 0x435906
64#define CYSETTIMEOUT 0x435907
65#define CYGETDEFTIMEOUT 0x435908
66#define CYSETDEFTIMEOUT 0x435909
67
68#define CyMaxChipsPerCard 1
69
70/**** cd2401 registers ****/
71
72#define CyGFRCR (0x81)
73#define CyCCR (0x13)
74#define CyCLR_CHAN (0x40)
75#define CyINIT_CHAN (0x20)
76#define CyCHIP_RESET (0x10)
77#define CyENB_XMTR (0x08)
78#define CyDIS_XMTR (0x04)
79#define CyENB_RCVR (0x02)
80#define CyDIS_RCVR (0x01)
81#define CyCAR (0xee)
82#define CyIER (0x11)
83#define CyMdmCh (0x80)
84#define CyRxExc (0x20)
85#define CyRxData (0x08)
86#define CyTxMpty (0x02)
87#define CyTxRdy (0x01)
88#define CyLICR (0x26)
89#define CyRISR (0x89)
90#define CyTIMEOUT (0x80)
91#define CySPECHAR (0x70)
92#define CyOVERRUN (0x08)
93#define CyPARITY (0x04)
94#define CyFRAME (0x02)
95#define CyBREAK (0x01)
96#define CyREOIR (0x84)
97#define CyTEOIR (0x85)
98#define CyMEOIR (0x86)
99#define CyNOTRANS (0x08)
100#define CyRFOC (0x30)
101#define CyRDR (0xf8)
102#define CyTDR (0xf8)
103#define CyMISR (0x8b)
104#define CyRISR (0x89)
105#define CyTISR (0x8a)
106#define CyMSVR1 (0xde)
107#define CyMSVR2 (0xdf)
108#define CyDSR (0x80)
109#define CyDCD (0x40)
110#define CyCTS (0x20)
111#define CyDTR (0x02)
112#define CyRTS (0x01)
113#define CyRTPRL (0x25)
114#define CyRTPRH (0x24)
115#define CyCOR1 (0x10)
116#define CyPARITY_NONE (0x00)
117#define CyPARITY_E (0x40)
118#define CyPARITY_O (0xC0)
119#define Cy_5_BITS (0x04)
120#define Cy_6_BITS (0x05)
121#define Cy_7_BITS (0x06)
122#define Cy_8_BITS (0x07)
123#define CyCOR2 (0x17)
124#define CyETC (0x20)
125#define CyCtsAE (0x02)
126#define CyCOR3 (0x16)
127#define Cy_1_STOP (0x02)
128#define Cy_2_STOP (0x04)
129#define CyCOR4 (0x15)
130#define CyREC_FIFO (0x0F) /* Receive FIFO threshold */
131#define CyCOR5 (0x14)
132#define CyCOR6 (0x18)
133#define CyCOR7 (0x07)
134#define CyRBPR (0xcb)
135#define CyRCOR (0xc8)
136#define CyTBPR (0xc3)
137#define CyTCOR (0xc0)
138#define CySCHR1 (0x1f)
139#define CySCHR2 (0x1e)
140#define CyTPR (0xda)
141#define CyPILR1 (0xe3)
142#define CyPILR2 (0xe0)
143#define CyPILR3 (0xe1)
144#define CyCMR (0x1b)
145#define CyASYNC (0x02)
146#define CyLICR (0x26)
147#define CyLIVR (0x09)
148#define CySCRL (0x23)
149#define CySCRH (0x22)
150#define CyTFTC (0x80)
151
152
153/* max number of chars in the FIFO */
154
155#define CyMAX_CHAR_FIFO 12
156
157/***************************************************************************/
diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h
index a416e92012ef..f41dcc949218 100644
--- a/include/linux/serial_8250.h
+++ b/include/linux/serial_8250.h
@@ -69,7 +69,6 @@ struct uart_port;
69struct uart_8250_port; 69struct uart_8250_port;
70 70
71int serial8250_register_8250_port(struct uart_8250_port *); 71int serial8250_register_8250_port(struct uart_8250_port *);
72int serial8250_register_port(struct uart_port *);
73void serial8250_unregister_port(int line); 72void serial8250_unregister_port(int line);
74void serial8250_suspend_port(int line); 73void serial8250_suspend_port(int line);
75void serial8250_resume_port(int line); 74void serial8250_resume_port(int line);
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 65db9928e15f..0253c2022e53 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -47,7 +47,8 @@
47#define PORT_U6_16550A 19 /* ST-Ericsson U6xxx internal UART */ 47#define PORT_U6_16550A 19 /* ST-Ericsson U6xxx internal UART */
48#define PORT_TEGRA 20 /* NVIDIA Tegra internal UART */ 48#define PORT_TEGRA 20 /* NVIDIA Tegra internal UART */
49#define PORT_XR17D15X 21 /* Exar XR17D15x UART */ 49#define PORT_XR17D15X 21 /* Exar XR17D15x UART */
50#define PORT_MAX_8250 21 /* max port ID */ 50#define PORT_LPC3220 22 /* NXP LPC32xx SoC "Standard" UART */
51#define PORT_MAX_8250 22 /* max port ID */
51 52
52/* 53/*
53 * ARM specific type numbers. These are not currently guaranteed 54 * ARM specific type numbers. These are not currently guaranteed
diff --git a/include/linux/stallion.h b/include/linux/stallion.h
deleted file mode 100644
index 336af33c6ea4..000000000000
--- a/include/linux/stallion.h
+++ /dev/null
@@ -1,147 +0,0 @@
1/*****************************************************************************/
2
3/*
4 * stallion.h -- stallion multiport serial driver.
5 *
6 * Copyright (C) 1996-1998 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24/*****************************************************************************/
25#ifndef _STALLION_H
26#define _STALLION_H
27/*****************************************************************************/
28
29/*
30 * Define important driver constants here.
31 */
32#define STL_MAXBRDS 4
33#define STL_MAXPANELS 4
34#define STL_MAXBANKS 8
35#define STL_PORTSPERPANEL 16
36#define STL_MAXPORTS 64
37#define STL_MAXDEVS (STL_MAXBRDS * STL_MAXPORTS)
38
39
40/*
41 * Define a set of structures to hold all the board/panel/port info
42 * for our ports. These will be dynamically allocated as required.
43 */
44
45/*
46 * Define a ring queue structure for each port. This will hold the
47 * TX data waiting to be output. Characters are fed into this buffer
48 * from the line discipline (or even direct from user space!) and
49 * then fed into the UARTs during interrupts. Will use a classic ring
50 * queue here for this. The good thing about this type of ring queue
51 * is that the head and tail pointers can be updated without interrupt
52 * protection - since "write" code only needs to change the head, and
53 * interrupt code only needs to change the tail.
54 */
55struct stlrq {
56 char *buf;
57 char *head;
58 char *tail;
59};
60
61/*
62 * Port, panel and board structures to hold status info about each.
63 * The board structure contains pointers to structures for each panel
64 * connected to it, and in turn each panel structure contains pointers
65 * for each port structure for each port on that panel. Note that
66 * the port structure also contains the board and panel number that it
67 * is associated with, this makes it (fairly) easy to get back to the
68 * board/panel info for a port.
69 */
70struct stlport {
71 unsigned long magic;
72 struct tty_port port;
73 unsigned int portnr;
74 unsigned int panelnr;
75 unsigned int brdnr;
76 int ioaddr;
77 int uartaddr;
78 unsigned int pagenr;
79 unsigned long istate;
80 int baud_base;
81 int custom_divisor;
82 int close_delay;
83 int closing_wait;
84 int openwaitcnt;
85 int brklen;
86 unsigned int sigs;
87 unsigned int rxignoremsk;
88 unsigned int rxmarkmsk;
89 unsigned int imr;
90 unsigned int crenable;
91 unsigned long clk;
92 unsigned long hwid;
93 void *uartp;
94 comstats_t stats;
95 struct stlrq tx;
96};
97
98struct stlpanel {
99 unsigned long magic;
100 unsigned int panelnr;
101 unsigned int brdnr;
102 unsigned int pagenr;
103 unsigned int nrports;
104 int iobase;
105 void *uartp;
106 void (*isr)(struct stlpanel *panelp, unsigned int iobase);
107 unsigned int hwid;
108 unsigned int ackmask;
109 struct stlport *ports[STL_PORTSPERPANEL];
110};
111
112struct stlbrd {
113 unsigned long magic;
114 unsigned int brdnr;
115 unsigned int brdtype;
116 unsigned int state;
117 unsigned int nrpanels;
118 unsigned int nrports;
119 unsigned int nrbnks;
120 int irq;
121 int irqtype;
122 int (*isr)(struct stlbrd *brdp);
123 unsigned int ioaddr1;
124 unsigned int ioaddr2;
125 unsigned int iosize1;
126 unsigned int iosize2;
127 unsigned int iostatus;
128 unsigned int ioctrl;
129 unsigned int ioctrlval;
130 unsigned int hwid;
131 unsigned long clk;
132 unsigned int bnkpageaddr[STL_MAXBANKS];
133 unsigned int bnkstataddr[STL_MAXBANKS];
134 struct stlpanel *bnk2panel[STL_MAXBANKS];
135 struct stlpanel *panels[STL_MAXPANELS];
136};
137
138
139/*
140 * Define MAGIC numbers used for above structures.
141 */
142#define STL_PORTMAGIC 0x5a7182c9
143#define STL_PANELMAGIC 0x7ef621a1
144#define STL_BOARDMAGIC 0xa2267f52
145
146/*****************************************************************************/
147#endif
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 9f47ab540f65..7f9d7df9b131 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -268,6 +268,7 @@ struct tty_struct {
268 struct mutex ldisc_mutex; 268 struct mutex ldisc_mutex;
269 struct tty_ldisc *ldisc; 269 struct tty_ldisc *ldisc;
270 270
271 struct mutex legacy_mutex;
271 struct mutex termios_mutex; 272 struct mutex termios_mutex;
272 spinlock_t ctrl_lock; 273 spinlock_t ctrl_lock;
273 /* Termios values are protected by the termios mutex */ 274 /* Termios values are protected by the termios mutex */
@@ -497,6 +498,9 @@ extern int tty_write_lock(struct tty_struct *tty, int ndelay);
497#define tty_is_writelocked(tty) (mutex_is_locked(&tty->atomic_write_lock)) 498#define tty_is_writelocked(tty) (mutex_is_locked(&tty->atomic_write_lock))
498 499
499extern void tty_port_init(struct tty_port *port); 500extern void tty_port_init(struct tty_port *port);
501extern struct device *tty_port_register_device(struct tty_port *port,
502 struct tty_driver *driver, unsigned index,
503 struct device *device);
500extern int tty_port_alloc_xmit_buf(struct tty_port *port); 504extern int tty_port_alloc_xmit_buf(struct tty_port *port);
501extern void tty_port_free_xmit_buf(struct tty_port *port); 505extern void tty_port_free_xmit_buf(struct tty_port *port);
502extern void tty_port_put(struct tty_port *port); 506extern void tty_port_put(struct tty_port *port);
@@ -521,6 +525,8 @@ extern int tty_port_close_start(struct tty_port *port,
521extern void tty_port_close_end(struct tty_port *port, struct tty_struct *tty); 525extern void tty_port_close_end(struct tty_port *port, struct tty_struct *tty);
522extern void tty_port_close(struct tty_port *port, 526extern void tty_port_close(struct tty_port *port,
523 struct tty_struct *tty, struct file *filp); 527 struct tty_struct *tty, struct file *filp);
528extern int tty_port_install(struct tty_port *port, struct tty_driver *driver,
529 struct tty_struct *tty);
524extern int tty_port_open(struct tty_port *port, 530extern int tty_port_open(struct tty_port *port,
525 struct tty_struct *tty, struct file *filp); 531 struct tty_struct *tty, struct file *filp);
526static inline int tty_port_users(struct tty_port *port) 532static inline int tty_port_users(struct tty_port *port)
@@ -605,8 +611,12 @@ extern long vt_compat_ioctl(struct tty_struct *tty,
605 611
606/* tty_mutex.c */ 612/* tty_mutex.c */
607/* functions for preparation of BKL removal */ 613/* functions for preparation of BKL removal */
608extern void __lockfunc tty_lock(void) __acquires(tty_lock); 614extern void __lockfunc tty_lock(struct tty_struct *tty);
609extern void __lockfunc tty_unlock(void) __releases(tty_lock); 615extern void __lockfunc tty_unlock(struct tty_struct *tty);
616extern void __lockfunc tty_lock_pair(struct tty_struct *tty,
617 struct tty_struct *tty2);
618extern void __lockfunc tty_unlock_pair(struct tty_struct *tty,
619 struct tty_struct *tty2);
610 620
611/* 621/*
612 * this shall be called only from where BTM is held (like close) 622 * this shall be called only from where BTM is held (like close)
@@ -621,9 +631,9 @@ extern void __lockfunc tty_unlock(void) __releases(tty_lock);
621static inline void tty_wait_until_sent_from_close(struct tty_struct *tty, 631static inline void tty_wait_until_sent_from_close(struct tty_struct *tty,
622 long timeout) 632 long timeout)
623{ 633{
624 tty_unlock(); /* tty->ops->close holds the BTM, drop it while waiting */ 634 tty_unlock(tty); /* tty->ops->close holds the BTM, drop it while waiting */
625 tty_wait_until_sent(tty, timeout); 635 tty_wait_until_sent(tty, timeout);
626 tty_lock(); 636 tty_lock(tty);
627} 637}
628 638
629/* 639/*
@@ -638,16 +648,16 @@ static inline void tty_wait_until_sent_from_close(struct tty_struct *tty,
638 * 648 *
639 * Do not use in new code. 649 * Do not use in new code.
640 */ 650 */
641#define wait_event_interruptible_tty(wq, condition) \ 651#define wait_event_interruptible_tty(tty, wq, condition) \
642({ \ 652({ \
643 int __ret = 0; \ 653 int __ret = 0; \
644 if (!(condition)) { \ 654 if (!(condition)) { \
645 __wait_event_interruptible_tty(wq, condition, __ret); \ 655 __wait_event_interruptible_tty(tty, wq, condition, __ret); \
646 } \ 656 } \
647 __ret; \ 657 __ret; \
648}) 658})
649 659
650#define __wait_event_interruptible_tty(wq, condition, ret) \ 660#define __wait_event_interruptible_tty(tty, wq, condition, ret) \
651do { \ 661do { \
652 DEFINE_WAIT(__wait); \ 662 DEFINE_WAIT(__wait); \
653 \ 663 \
@@ -656,9 +666,9 @@ do { \
656 if (condition) \ 666 if (condition) \
657 break; \ 667 break; \
658 if (!signal_pending(current)) { \ 668 if (!signal_pending(current)) { \
659 tty_unlock(); \ 669 tty_unlock(tty); \
660 schedule(); \ 670 schedule(); \
661 tty_lock(); \ 671 tty_lock(tty); \
662 continue; \ 672 continue; \
663 } \ 673 } \
664 ret = -ERESTARTSYS; \ 674 ret = -ERESTARTSYS; \
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index 6e6dbb7447b6..04419c141b00 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -313,6 +313,7 @@ struct tty_driver {
313 * Pointer to the tty data structures 313 * Pointer to the tty data structures
314 */ 314 */
315 struct tty_struct **ttys; 315 struct tty_struct **ttys;
316 struct tty_port **ports;
316 struct ktermios **termios; 317 struct ktermios **termios;
317 void *driver_state; 318 void *driver_state;
318 319
diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
index 59ba38bc400f..80ffde3bb164 100644
--- a/include/net/irda/ircomm_tty.h
+++ b/include/net/irda/ircomm_tty.h
@@ -52,21 +52,16 @@
52/* Same for payload size. See qos.c for the smallest max data size */ 52/* Same for payload size. See qos.c for the smallest max data size */
53#define IRCOMM_TTY_DATA_UNINITIALISED (64 - IRCOMM_TTY_HDR_UNINITIALISED) 53#define IRCOMM_TTY_DATA_UNINITIALISED (64 - IRCOMM_TTY_HDR_UNINITIALISED)
54 54
55/* Those are really defined in include/linux/serial.h - Jean II */
56#define ASYNC_B_INITIALIZED 31 /* Serial port was initialized */
57#define ASYNC_B_NORMAL_ACTIVE 29 /* Normal device is active */
58#define ASYNC_B_CLOSING 27 /* Serial port is closing */
59
60/* 55/*
61 * IrCOMM TTY driver state 56 * IrCOMM TTY driver state
62 */ 57 */
63struct ircomm_tty_cb { 58struct ircomm_tty_cb {
64 irda_queue_t queue; /* Must be first */ 59 irda_queue_t queue; /* Must be first */
60 struct tty_port port;
65 magic_t magic; 61 magic_t magic;
66 62
67 int state; /* Connect state */ 63 int state; /* Connect state */
68 64
69 struct tty_struct *tty;
70 struct ircomm_cb *ircomm; /* IrCOMM layer instance */ 65 struct ircomm_cb *ircomm; /* IrCOMM layer instance */
71 66
72 struct sk_buff *tx_skb; /* Transmit buffer */ 67 struct sk_buff *tx_skb; /* Transmit buffer */
@@ -80,7 +75,6 @@ struct ircomm_tty_cb {
80 LOCAL_FLOW flow; /* IrTTP flow status */ 75 LOCAL_FLOW flow; /* IrTTP flow status */
81 76
82 int line; 77 int line;
83 unsigned long flags;
84 78
85 __u8 dlsap_sel; 79 __u8 dlsap_sel;
86 __u8 slsap_sel; 80 __u8 slsap_sel;
@@ -97,19 +91,10 @@ struct ircomm_tty_cb {
97 void *skey; 91 void *skey;
98 void *ckey; 92 void *ckey;
99 93
100 wait_queue_head_t open_wait;
101 wait_queue_head_t close_wait;
102 struct timer_list watchdog_timer; 94 struct timer_list watchdog_timer;
103 struct work_struct tqueue; 95 struct work_struct tqueue;
104 96
105 unsigned short close_delay;
106 unsigned short closing_wait; /* time to wait before closing */
107
108 int open_count;
109 int blocked_open; /* # of blocked opens */
110
111 /* Protect concurent access to : 97 /* Protect concurent access to :
112 * o self->open_count
113 * o self->ctrl_skb 98 * o self->ctrl_skb
114 * o self->tx_skb 99 * o self->tx_skb
115 * Maybe other things may gain to be protected as well... 100 * Maybe other things may gain to be protected as well...
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index d1820ff14aee..aa5d73b786ac 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -710,9 +710,9 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
710 break; 710 break;
711 } 711 }
712 712
713 tty_unlock(); 713 tty_unlock(tty);
714 schedule(); 714 schedule();
715 tty_lock(); 715 tty_lock(tty);
716 } 716 }
717 set_current_state(TASK_RUNNING); 717 set_current_state(TASK_RUNNING);
718 remove_wait_queue(&dev->wait, &wait); 718 remove_wait_queue(&dev->wait, &wait);
diff --git a/net/irda/ircomm/ircomm_param.c b/net/irda/ircomm/ircomm_param.c
index 8b915f3ac3b9..308939128359 100644
--- a/net/irda/ircomm/ircomm_param.c
+++ b/net/irda/ircomm/ircomm_param.c
@@ -99,7 +99,6 @@ pi_param_info_t ircomm_param_info = { pi_major_call_table, 3, 0x0f, 4 };
99 */ 99 */
100int ircomm_param_request(struct ircomm_tty_cb *self, __u8 pi, int flush) 100int ircomm_param_request(struct ircomm_tty_cb *self, __u8 pi, int flush)
101{ 101{
102 struct tty_struct *tty;
103 unsigned long flags; 102 unsigned long flags;
104 struct sk_buff *skb; 103 struct sk_buff *skb;
105 int count; 104 int count;
@@ -109,10 +108,6 @@ int ircomm_param_request(struct ircomm_tty_cb *self, __u8 pi, int flush)
109 IRDA_ASSERT(self != NULL, return -1;); 108 IRDA_ASSERT(self != NULL, return -1;);
110 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); 109 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
111 110
112 tty = self->tty;
113 if (!tty)
114 return 0;
115
116 /* Make sure we don't send parameters for raw mode */ 111 /* Make sure we don't send parameters for raw mode */
117 if (self->service_type == IRCOMM_3_WIRE_RAW) 112 if (self->service_type == IRCOMM_3_WIRE_RAW)
118 return 0; 113 return 0;
diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
index 6b9d5a0e42f9..4e35b45c1c73 100644
--- a/net/irda/ircomm/ircomm_tty.c
+++ b/net/irda/ircomm/ircomm_tty.c
@@ -104,6 +104,35 @@ static const struct tty_operations ops = {
104#endif /* CONFIG_PROC_FS */ 104#endif /* CONFIG_PROC_FS */
105}; 105};
106 106
107static void ircomm_port_raise_dtr_rts(struct tty_port *port, int raise)
108{
109 struct ircomm_tty_cb *self = container_of(port, struct ircomm_tty_cb,
110 port);
111 /*
112 * Here, we use to lock those two guys, but as ircomm_param_request()
113 * does it itself, I don't see the point (and I see the deadlock).
114 * Jean II
115 */
116 if (raise)
117 self->settings.dte |= IRCOMM_RTS | IRCOMM_DTR;
118 else
119 self->settings.dte &= ~(IRCOMM_RTS | IRCOMM_DTR);
120
121 ircomm_param_request(self, IRCOMM_DTE, TRUE);
122}
123
124static int ircomm_port_carrier_raised(struct tty_port *port)
125{
126 struct ircomm_tty_cb *self = container_of(port, struct ircomm_tty_cb,
127 port);
128 return self->settings.dce & IRCOMM_CD;
129}
130
131static const struct tty_port_operations ircomm_port_ops = {
132 .dtr_rts = ircomm_port_raise_dtr_rts,
133 .carrier_raised = ircomm_port_carrier_raised,
134};
135
107/* 136/*
108 * Function ircomm_tty_init() 137 * Function ircomm_tty_init()
109 * 138 *
@@ -194,7 +223,7 @@ static int ircomm_tty_startup(struct ircomm_tty_cb *self)
194 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); 223 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
195 224
196 /* Check if already open */ 225 /* Check if already open */
197 if (test_and_set_bit(ASYNC_B_INITIALIZED, &self->flags)) { 226 if (test_and_set_bit(ASYNCB_INITIALIZED, &self->port.flags)) {
198 IRDA_DEBUG(2, "%s(), already open so break out!\n", __func__ ); 227 IRDA_DEBUG(2, "%s(), already open so break out!\n", __func__ );
199 return 0; 228 return 0;
200 } 229 }
@@ -231,7 +260,7 @@ static int ircomm_tty_startup(struct ircomm_tty_cb *self)
231 260
232 return 0; 261 return 0;
233err: 262err:
234 clear_bit(ASYNC_B_INITIALIZED, &self->flags); 263 clear_bit(ASYNCB_INITIALIZED, &self->port.flags);
235 return ret; 264 return ret;
236} 265}
237 266
@@ -242,25 +271,23 @@ err:
242 * 271 *
243 */ 272 */
244static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self, 273static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
245 struct file *filp) 274 struct tty_struct *tty, struct file *filp)
246{ 275{
276 struct tty_port *port = &self->port;
247 DECLARE_WAITQUEUE(wait, current); 277 DECLARE_WAITQUEUE(wait, current);
248 int retval; 278 int retval;
249 int do_clocal = 0, extra_count = 0; 279 int do_clocal = 0, extra_count = 0;
250 unsigned long flags; 280 unsigned long flags;
251 struct tty_struct *tty;
252 281
253 IRDA_DEBUG(2, "%s()\n", __func__ ); 282 IRDA_DEBUG(2, "%s()\n", __func__ );
254 283
255 tty = self->tty;
256
257 /* 284 /*
258 * If non-blocking mode is set, or the port is not enabled, 285 * If non-blocking mode is set, or the port is not enabled,
259 * then make the check up front and then exit. 286 * then make the check up front and then exit.
260 */ 287 */
261 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){ 288 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
262 /* nonblock mode is set or port is not enabled */ 289 /* nonblock mode is set or port is not enabled */
263 self->flags |= ASYNC_NORMAL_ACTIVE; 290 port->flags |= ASYNC_NORMAL_ACTIVE;
264 IRDA_DEBUG(1, "%s(), O_NONBLOCK requested!\n", __func__ ); 291 IRDA_DEBUG(1, "%s(), O_NONBLOCK requested!\n", __func__ );
265 return 0; 292 return 0;
266 } 293 }
@@ -272,42 +299,34 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
272 299
273 /* Wait for carrier detect and the line to become 300 /* Wait for carrier detect and the line to become
274 * free (i.e., not in use by the callout). While we are in 301 * free (i.e., not in use by the callout). While we are in
275 * this loop, self->open_count is dropped by one, so that 302 * this loop, port->count is dropped by one, so that
276 * mgsl_close() knows when to free things. We restore it upon 303 * mgsl_close() knows when to free things. We restore it upon
277 * exit, either normal or abnormal. 304 * exit, either normal or abnormal.
278 */ 305 */
279 306
280 retval = 0; 307 retval = 0;
281 add_wait_queue(&self->open_wait, &wait); 308 add_wait_queue(&port->open_wait, &wait);
282 309
283 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n", 310 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
284 __FILE__,__LINE__, tty->driver->name, self->open_count ); 311 __FILE__, __LINE__, tty->driver->name, port->count);
285 312
286 /* As far as I can see, we protect open_count - Jean II */ 313 spin_lock_irqsave(&port->lock, flags);
287 spin_lock_irqsave(&self->spinlock, flags);
288 if (!tty_hung_up_p(filp)) { 314 if (!tty_hung_up_p(filp)) {
289 extra_count = 1; 315 extra_count = 1;
290 self->open_count--; 316 port->count--;
291 } 317 }
292 spin_unlock_irqrestore(&self->spinlock, flags); 318 spin_unlock_irqrestore(&port->lock, flags);
293 self->blocked_open++; 319 port->blocked_open++;
294 320
295 while (1) { 321 while (1) {
296 if (tty->termios->c_cflag & CBAUD) { 322 if (tty->termios->c_cflag & CBAUD)
297 /* Here, we use to lock those two guys, but 323 tty_port_raise_dtr_rts(port);
298 * as ircomm_param_request() does it itself,
299 * I don't see the point (and I see the deadlock).
300 * Jean II */
301 self->settings.dte |= IRCOMM_RTS + IRCOMM_DTR;
302
303 ircomm_param_request(self, IRCOMM_DTE, TRUE);
304 }
305 324
306 current->state = TASK_INTERRUPTIBLE; 325 current->state = TASK_INTERRUPTIBLE;
307 326
308 if (tty_hung_up_p(filp) || 327 if (tty_hung_up_p(filp) ||
309 !test_bit(ASYNC_B_INITIALIZED, &self->flags)) { 328 !test_bit(ASYNCB_INITIALIZED, &port->flags)) {
310 retval = (self->flags & ASYNC_HUP_NOTIFY) ? 329 retval = (port->flags & ASYNC_HUP_NOTIFY) ?
311 -EAGAIN : -ERESTARTSYS; 330 -EAGAIN : -ERESTARTSYS;
312 break; 331 break;
313 } 332 }
@@ -317,8 +336,8 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
317 * specified, we cannot return before the IrCOMM link is 336 * specified, we cannot return before the IrCOMM link is
318 * ready 337 * ready
319 */ 338 */
320 if (!test_bit(ASYNC_B_CLOSING, &self->flags) && 339 if (!test_bit(ASYNCB_CLOSING, &port->flags) &&
321 (do_clocal || (self->settings.dce & IRCOMM_CD)) && 340 (do_clocal || tty_port_carrier_raised(port)) &&
322 self->state == IRCOMM_TTY_READY) 341 self->state == IRCOMM_TTY_READY)
323 { 342 {
324 break; 343 break;
@@ -330,27 +349,27 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
330 } 349 }
331 350
332 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n", 351 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
333 __FILE__,__LINE__, tty->driver->name, self->open_count ); 352 __FILE__, __LINE__, tty->driver->name, port->count);
334 353
335 schedule(); 354 schedule();
336 } 355 }
337 356
338 __set_current_state(TASK_RUNNING); 357 __set_current_state(TASK_RUNNING);
339 remove_wait_queue(&self->open_wait, &wait); 358 remove_wait_queue(&port->open_wait, &wait);
340 359
341 if (extra_count) { 360 if (extra_count) {
342 /* ++ is not atomic, so this should be protected - Jean II */ 361 /* ++ is not atomic, so this should be protected - Jean II */
343 spin_lock_irqsave(&self->spinlock, flags); 362 spin_lock_irqsave(&port->lock, flags);
344 self->open_count++; 363 port->count++;
345 spin_unlock_irqrestore(&self->spinlock, flags); 364 spin_unlock_irqrestore(&port->lock, flags);
346 } 365 }
347 self->blocked_open--; 366 port->blocked_open--;
348 367
349 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n", 368 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
350 __FILE__,__LINE__, tty->driver->name, self->open_count); 369 __FILE__, __LINE__, tty->driver->name, port->count);
351 370
352 if (!retval) 371 if (!retval)
353 self->flags |= ASYNC_NORMAL_ACTIVE; 372 port->flags |= ASYNC_NORMAL_ACTIVE;
354 373
355 return retval; 374 return retval;
356} 375}
@@ -381,6 +400,8 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
381 return -ENOMEM; 400 return -ENOMEM;
382 } 401 }
383 402
403 tty_port_init(&self->port);
404 self->port.ops = &ircomm_port_ops;
384 self->magic = IRCOMM_TTY_MAGIC; 405 self->magic = IRCOMM_TTY_MAGIC;
385 self->flow = FLOW_STOP; 406 self->flow = FLOW_STOP;
386 407
@@ -388,13 +409,9 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
388 INIT_WORK(&self->tqueue, ircomm_tty_do_softint); 409 INIT_WORK(&self->tqueue, ircomm_tty_do_softint);
389 self->max_header_size = IRCOMM_TTY_HDR_UNINITIALISED; 410 self->max_header_size = IRCOMM_TTY_HDR_UNINITIALISED;
390 self->max_data_size = IRCOMM_TTY_DATA_UNINITIALISED; 411 self->max_data_size = IRCOMM_TTY_DATA_UNINITIALISED;
391 self->close_delay = 5*HZ/10;
392 self->closing_wait = 30*HZ;
393 412
394 /* Init some important stuff */ 413 /* Init some important stuff */
395 init_timer(&self->watchdog_timer); 414 init_timer(&self->watchdog_timer);
396 init_waitqueue_head(&self->open_wait);
397 init_waitqueue_head(&self->close_wait);
398 spin_lock_init(&self->spinlock); 415 spin_lock_init(&self->spinlock);
399 416
400 /* 417 /*
@@ -408,27 +425,28 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
408 tty->termios->c_oflag = 0; 425 tty->termios->c_oflag = 0;
409 426
410 /* Insert into hash */ 427 /* Insert into hash */
428 /* FIXME there is a window from find to here */
411 hashbin_insert(ircomm_tty, (irda_queue_t *) self, line, NULL); 429 hashbin_insert(ircomm_tty, (irda_queue_t *) self, line, NULL);
412 } 430 }
413 /* ++ is not atomic, so this should be protected - Jean II */ 431 /* ++ is not atomic, so this should be protected - Jean II */
414 spin_lock_irqsave(&self->spinlock, flags); 432 spin_lock_irqsave(&self->port.lock, flags);
415 self->open_count++; 433 self->port.count++;
416 434
417 tty->driver_data = self; 435 tty->driver_data = self;
418 self->tty = tty; 436 spin_unlock_irqrestore(&self->port.lock, flags);
419 spin_unlock_irqrestore(&self->spinlock, flags); 437 tty_port_tty_set(&self->port, tty);
420 438
421 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name, 439 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
422 self->line, self->open_count); 440 self->line, self->port.count);
423 441
424 /* Not really used by us, but lets do it anyway */ 442 /* Not really used by us, but lets do it anyway */
425 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 443 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
426 444
427 /* 445 /*
428 * If the port is the middle of closing, bail out now 446 * If the port is the middle of closing, bail out now
429 */ 447 */
430 if (tty_hung_up_p(filp) || 448 if (tty_hung_up_p(filp) ||
431 test_bit(ASYNC_B_CLOSING, &self->flags)) { 449 test_bit(ASYNCB_CLOSING, &self->port.flags)) {
432 450
433 /* Hm, why are we blocking on ASYNC_CLOSING if we 451 /* Hm, why are we blocking on ASYNC_CLOSING if we
434 * do return -EAGAIN/-ERESTARTSYS below anyway? 452 * do return -EAGAIN/-ERESTARTSYS below anyway?
@@ -438,14 +456,15 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
438 * probably better sleep uninterruptible? 456 * probably better sleep uninterruptible?
439 */ 457 */
440 458
441 if (wait_event_interruptible(self->close_wait, !test_bit(ASYNC_B_CLOSING, &self->flags))) { 459 if (wait_event_interruptible(self->port.close_wait,
460 !test_bit(ASYNCB_CLOSING, &self->port.flags))) {
442 IRDA_WARNING("%s - got signal while blocking on ASYNC_CLOSING!\n", 461 IRDA_WARNING("%s - got signal while blocking on ASYNC_CLOSING!\n",
443 __func__); 462 __func__);
444 return -ERESTARTSYS; 463 return -ERESTARTSYS;
445 } 464 }
446 465
447#ifdef SERIAL_DO_RESTART 466#ifdef SERIAL_DO_RESTART
448 return (self->flags & ASYNC_HUP_NOTIFY) ? 467 return (self->port.flags & ASYNC_HUP_NOTIFY) ?
449 -EAGAIN : -ERESTARTSYS; 468 -EAGAIN : -ERESTARTSYS;
450#else 469#else
451 return -EAGAIN; 470 return -EAGAIN;
@@ -469,7 +488,7 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
469 if (ret) 488 if (ret)
470 return ret; 489 return ret;
471 490
472 ret = ircomm_tty_block_til_ready(self, filp); 491 ret = ircomm_tty_block_til_ready(self, tty, filp);
473 if (ret) { 492 if (ret) {
474 IRDA_DEBUG(2, 493 IRDA_DEBUG(2,
475 "%s(), returning after block_til_ready with %d\n", __func__ , 494 "%s(), returning after block_til_ready with %d\n", __func__ ,
@@ -489,81 +508,22 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
489static void ircomm_tty_close(struct tty_struct *tty, struct file *filp) 508static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
490{ 509{
491 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data; 510 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
492 unsigned long flags; 511 struct tty_port *port = &self->port;
493 512
494 IRDA_DEBUG(0, "%s()\n", __func__ ); 513 IRDA_DEBUG(0, "%s()\n", __func__ );
495 514
496 IRDA_ASSERT(self != NULL, return;); 515 IRDA_ASSERT(self != NULL, return;);
497 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); 516 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
498 517
499 spin_lock_irqsave(&self->spinlock, flags); 518 if (tty_port_close_start(port, tty, filp) == 0)
500
501 if (tty_hung_up_p(filp)) {
502 spin_unlock_irqrestore(&self->spinlock, flags);
503
504 IRDA_DEBUG(0, "%s(), returning 1\n", __func__ );
505 return;
506 }
507
508 if ((tty->count == 1) && (self->open_count != 1)) {
509 /*
510 * Uh, oh. tty->count is 1, which means that the tty
511 * structure will be freed. state->count should always
512 * be one in these conditions. If it's greater than
513 * one, we've got real problems, since it means the
514 * serial port won't be shutdown.
515 */
516 IRDA_DEBUG(0, "%s(), bad serial port count; "
517 "tty->count is 1, state->count is %d\n", __func__ ,
518 self->open_count);
519 self->open_count = 1;
520 }
521
522 if (--self->open_count < 0) {
523 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
524 __func__, self->line, self->open_count);
525 self->open_count = 0;
526 }
527 if (self->open_count) {
528 spin_unlock_irqrestore(&self->spinlock, flags);
529
530 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
531 return; 519 return;
532 }
533
534 /* Hum... Should be test_and_set_bit ??? - Jean II */
535 set_bit(ASYNC_B_CLOSING, &self->flags);
536
537 /* We need to unlock here (we were unlocking at the end of this
538 * function), because tty_wait_until_sent() may schedule.
539 * I don't know if the rest should be protected somehow,
540 * so someone should check. - Jean II */
541 spin_unlock_irqrestore(&self->spinlock, flags);
542
543 /*
544 * Now we wait for the transmit buffer to clear; and we notify
545 * the line discipline to only process XON/XOFF characters.
546 */
547 tty->closing = 1;
548 if (self->closing_wait != ASYNC_CLOSING_WAIT_NONE)
549 tty_wait_until_sent_from_close(tty, self->closing_wait);
550 520
551 ircomm_tty_shutdown(self); 521 ircomm_tty_shutdown(self);
552 522
553 tty_driver_flush_buffer(tty); 523 tty_driver_flush_buffer(tty);
554 tty_ldisc_flush(tty);
555 524
556 tty->closing = 0; 525 tty_port_close_end(port, tty);
557 self->tty = NULL; 526 tty_port_tty_set(port, NULL);
558
559 if (self->blocked_open) {
560 if (self->close_delay)
561 schedule_timeout_interruptible(self->close_delay);
562 wake_up_interruptible(&self->open_wait);
563 }
564
565 self->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
566 wake_up_interruptible(&self->close_wait);
567} 527}
568 528
569/* 529/*
@@ -606,7 +566,7 @@ static void ircomm_tty_do_softint(struct work_struct *work)
606 if (!self || self->magic != IRCOMM_TTY_MAGIC) 566 if (!self || self->magic != IRCOMM_TTY_MAGIC)
607 return; 567 return;
608 568
609 tty = self->tty; 569 tty = tty_port_tty_get(&self->port);
610 if (!tty) 570 if (!tty)
611 return; 571 return;
612 572
@@ -627,7 +587,7 @@ static void ircomm_tty_do_softint(struct work_struct *work)
627 } 587 }
628 588
629 if (tty->hw_stopped) 589 if (tty->hw_stopped)
630 return; 590 goto put;
631 591
632 /* Unlink transmit buffer */ 592 /* Unlink transmit buffer */
633 spin_lock_irqsave(&self->spinlock, flags); 593 spin_lock_irqsave(&self->spinlock, flags);
@@ -646,6 +606,8 @@ static void ircomm_tty_do_softint(struct work_struct *work)
646 606
647 /* Check if user (still) wants to be waken up */ 607 /* Check if user (still) wants to be waken up */
648 tty_wakeup(tty); 608 tty_wakeup(tty);
609put:
610 tty_kref_put(tty);
649} 611}
650 612
651/* 613/*
@@ -955,7 +917,7 @@ static void ircomm_tty_shutdown(struct ircomm_tty_cb *self)
955 917
956 IRDA_DEBUG(0, "%s()\n", __func__ ); 918 IRDA_DEBUG(0, "%s()\n", __func__ );
957 919
958 if (!test_and_clear_bit(ASYNC_B_INITIALIZED, &self->flags)) 920 if (!test_and_clear_bit(ASYNCB_INITIALIZED, &self->port.flags))
959 return; 921 return;
960 922
961 ircomm_tty_detach_cable(self); 923 ircomm_tty_detach_cable(self);
@@ -994,6 +956,7 @@ static void ircomm_tty_shutdown(struct ircomm_tty_cb *self)
994static void ircomm_tty_hangup(struct tty_struct *tty) 956static void ircomm_tty_hangup(struct tty_struct *tty)
995{ 957{
996 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data; 958 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
959 struct tty_port *port = &self->port;
997 unsigned long flags; 960 unsigned long flags;
998 961
999 IRDA_DEBUG(0, "%s()\n", __func__ ); 962 IRDA_DEBUG(0, "%s()\n", __func__ );
@@ -1004,14 +967,17 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
1004 /* ircomm_tty_flush_buffer(tty); */ 967 /* ircomm_tty_flush_buffer(tty); */
1005 ircomm_tty_shutdown(self); 968 ircomm_tty_shutdown(self);
1006 969
1007 /* I guess we need to lock here - Jean II */ 970 spin_lock_irqsave(&port->lock, flags);
1008 spin_lock_irqsave(&self->spinlock, flags); 971 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1009 self->flags &= ~ASYNC_NORMAL_ACTIVE; 972 if (port->tty) {
1010 self->tty = NULL; 973 set_bit(TTY_IO_ERROR, &port->tty->flags);
1011 self->open_count = 0; 974 tty_kref_put(port->tty);
1012 spin_unlock_irqrestore(&self->spinlock, flags); 975 }
976 port->tty = NULL;
977 port->count = 0;
978 spin_unlock_irqrestore(&port->lock, flags);
1013 979
1014 wake_up_interruptible(&self->open_wait); 980 wake_up_interruptible(&port->open_wait);
1015} 981}
1016 982
1017/* 983/*
@@ -1071,20 +1037,20 @@ void ircomm_tty_check_modem_status(struct ircomm_tty_cb *self)
1071 IRDA_ASSERT(self != NULL, return;); 1037 IRDA_ASSERT(self != NULL, return;);
1072 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); 1038 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
1073 1039
1074 tty = self->tty; 1040 tty = tty_port_tty_get(&self->port);
1075 1041
1076 status = self->settings.dce; 1042 status = self->settings.dce;
1077 1043
1078 if (status & IRCOMM_DCE_DELTA_ANY) { 1044 if (status & IRCOMM_DCE_DELTA_ANY) {
1079 /*wake_up_interruptible(&self->delta_msr_wait);*/ 1045 /*wake_up_interruptible(&self->delta_msr_wait);*/
1080 } 1046 }
1081 if ((self->flags & ASYNC_CHECK_CD) && (status & IRCOMM_DELTA_CD)) { 1047 if ((self->port.flags & ASYNC_CHECK_CD) && (status & IRCOMM_DELTA_CD)) {
1082 IRDA_DEBUG(2, 1048 IRDA_DEBUG(2,
1083 "%s(), ircomm%d CD now %s...\n", __func__ , self->line, 1049 "%s(), ircomm%d CD now %s...\n", __func__ , self->line,
1084 (status & IRCOMM_CD) ? "on" : "off"); 1050 (status & IRCOMM_CD) ? "on" : "off");
1085 1051
1086 if (status & IRCOMM_CD) { 1052 if (status & IRCOMM_CD) {
1087 wake_up_interruptible(&self->open_wait); 1053 wake_up_interruptible(&self->port.open_wait);
1088 } else { 1054 } else {
1089 IRDA_DEBUG(2, 1055 IRDA_DEBUG(2,
1090 "%s(), Doing serial hangup..\n", __func__ ); 1056 "%s(), Doing serial hangup..\n", __func__ );
@@ -1092,10 +1058,10 @@ void ircomm_tty_check_modem_status(struct ircomm_tty_cb *self)
1092 tty_hangup(tty); 1058 tty_hangup(tty);
1093 1059
1094 /* Hangup will remote the tty, so better break out */ 1060 /* Hangup will remote the tty, so better break out */
1095 return; 1061 goto put;
1096 } 1062 }
1097 } 1063 }
1098 if (self->flags & ASYNC_CTS_FLOW) { 1064 if (tty && self->port.flags & ASYNC_CTS_FLOW) {
1099 if (tty->hw_stopped) { 1065 if (tty->hw_stopped) {
1100 if (status & IRCOMM_CTS) { 1066 if (status & IRCOMM_CTS) {
1101 IRDA_DEBUG(2, 1067 IRDA_DEBUG(2,
@@ -1103,10 +1069,10 @@ void ircomm_tty_check_modem_status(struct ircomm_tty_cb *self)
1103 tty->hw_stopped = 0; 1069 tty->hw_stopped = 0;
1104 1070
1105 /* Wake up processes blocked on open */ 1071 /* Wake up processes blocked on open */
1106 wake_up_interruptible(&self->open_wait); 1072 wake_up_interruptible(&self->port.open_wait);
1107 1073
1108 schedule_work(&self->tqueue); 1074 schedule_work(&self->tqueue);
1109 return; 1075 goto put;
1110 } 1076 }
1111 } else { 1077 } else {
1112 if (!(status & IRCOMM_CTS)) { 1078 if (!(status & IRCOMM_CTS)) {
@@ -1116,6 +1082,8 @@ void ircomm_tty_check_modem_status(struct ircomm_tty_cb *self)
1116 } 1082 }
1117 } 1083 }
1118 } 1084 }
1085put:
1086 tty_kref_put(tty);
1119} 1087}
1120 1088
1121/* 1089/*
@@ -1128,6 +1096,7 @@ static int ircomm_tty_data_indication(void *instance, void *sap,
1128 struct sk_buff *skb) 1096 struct sk_buff *skb)
1129{ 1097{
1130 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; 1098 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
1099 struct tty_struct *tty;
1131 1100
1132 IRDA_DEBUG(2, "%s()\n", __func__ ); 1101 IRDA_DEBUG(2, "%s()\n", __func__ );
1133 1102
@@ -1135,7 +1104,8 @@ static int ircomm_tty_data_indication(void *instance, void *sap,
1135 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); 1104 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
1136 IRDA_ASSERT(skb != NULL, return -1;); 1105 IRDA_ASSERT(skb != NULL, return -1;);
1137 1106
1138 if (!self->tty) { 1107 tty = tty_port_tty_get(&self->port);
1108 if (!tty) {
1139 IRDA_DEBUG(0, "%s(), no tty!\n", __func__ ); 1109 IRDA_DEBUG(0, "%s(), no tty!\n", __func__ );
1140 return 0; 1110 return 0;
1141 } 1111 }
@@ -1146,7 +1116,7 @@ static int ircomm_tty_data_indication(void *instance, void *sap,
1146 * Devices like WinCE can do this, and since they don't send any 1116 * Devices like WinCE can do this, and since they don't send any
1147 * params, we can just as well declare the hardware for running. 1117 * params, we can just as well declare the hardware for running.
1148 */ 1118 */
1149 if (self->tty->hw_stopped && (self->flow == FLOW_START)) { 1119 if (tty->hw_stopped && (self->flow == FLOW_START)) {
1150 IRDA_DEBUG(0, "%s(), polling for line settings!\n", __func__ ); 1120 IRDA_DEBUG(0, "%s(), polling for line settings!\n", __func__ );
1151 ircomm_param_request(self, IRCOMM_POLL, TRUE); 1121 ircomm_param_request(self, IRCOMM_POLL, TRUE);
1152 1122
@@ -1159,8 +1129,9 @@ static int ircomm_tty_data_indication(void *instance, void *sap,
1159 * Use flip buffer functions since the code may be called from interrupt 1129 * Use flip buffer functions since the code may be called from interrupt
1160 * context 1130 * context
1161 */ 1131 */
1162 tty_insert_flip_string(self->tty, skb->data, skb->len); 1132 tty_insert_flip_string(tty, skb->data, skb->len);
1163 tty_flip_buffer_push(self->tty); 1133 tty_flip_buffer_push(tty);
1134 tty_kref_put(tty);
1164 1135
1165 /* No need to kfree_skb - see ircomm_ttp_data_indication() */ 1136 /* No need to kfree_skb - see ircomm_ttp_data_indication() */
1166 1137
@@ -1211,12 +1182,13 @@ static void ircomm_tty_flow_indication(void *instance, void *sap,
1211 IRDA_ASSERT(self != NULL, return;); 1182 IRDA_ASSERT(self != NULL, return;);
1212 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); 1183 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
1213 1184
1214 tty = self->tty; 1185 tty = tty_port_tty_get(&self->port);
1215 1186
1216 switch (cmd) { 1187 switch (cmd) {
1217 case FLOW_START: 1188 case FLOW_START:
1218 IRDA_DEBUG(2, "%s(), hw start!\n", __func__ ); 1189 IRDA_DEBUG(2, "%s(), hw start!\n", __func__ );
1219 tty->hw_stopped = 0; 1190 if (tty)
1191 tty->hw_stopped = 0;
1220 1192
1221 /* ircomm_tty_do_softint will take care of the rest */ 1193 /* ircomm_tty_do_softint will take care of the rest */
1222 schedule_work(&self->tqueue); 1194 schedule_work(&self->tqueue);
@@ -1224,15 +1196,19 @@ static void ircomm_tty_flow_indication(void *instance, void *sap,
1224 default: /* If we get here, something is very wrong, better stop */ 1196 default: /* If we get here, something is very wrong, better stop */
1225 case FLOW_STOP: 1197 case FLOW_STOP:
1226 IRDA_DEBUG(2, "%s(), hw stopped!\n", __func__ ); 1198 IRDA_DEBUG(2, "%s(), hw stopped!\n", __func__ );
1227 tty->hw_stopped = 1; 1199 if (tty)
1200 tty->hw_stopped = 1;
1228 break; 1201 break;
1229 } 1202 }
1203
1204 tty_kref_put(tty);
1230 self->flow = cmd; 1205 self->flow = cmd;
1231} 1206}
1232 1207
1233#ifdef CONFIG_PROC_FS 1208#ifdef CONFIG_PROC_FS
1234static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m) 1209static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
1235{ 1210{
1211 struct tty_struct *tty;
1236 char sep; 1212 char sep;
1237 1213
1238 seq_printf(m, "State: %s\n", ircomm_tty_state[self->state]); 1214 seq_printf(m, "State: %s\n", ircomm_tty_state[self->state]);
@@ -1328,40 +1304,43 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
1328 1304
1329 seq_puts(m, "Flags:"); 1305 seq_puts(m, "Flags:");
1330 sep = ' '; 1306 sep = ' ';
1331 if (self->flags & ASYNC_CTS_FLOW) { 1307 if (self->port.flags & ASYNC_CTS_FLOW) {
1332 seq_printf(m, "%cASYNC_CTS_FLOW", sep); 1308 seq_printf(m, "%cASYNC_CTS_FLOW", sep);
1333 sep = '|'; 1309 sep = '|';
1334 } 1310 }
1335 if (self->flags & ASYNC_CHECK_CD) { 1311 if (self->port.flags & ASYNC_CHECK_CD) {
1336 seq_printf(m, "%cASYNC_CHECK_CD", sep); 1312 seq_printf(m, "%cASYNC_CHECK_CD", sep);
1337 sep = '|'; 1313 sep = '|';
1338 } 1314 }
1339 if (self->flags & ASYNC_INITIALIZED) { 1315 if (self->port.flags & ASYNC_INITIALIZED) {
1340 seq_printf(m, "%cASYNC_INITIALIZED", sep); 1316 seq_printf(m, "%cASYNC_INITIALIZED", sep);
1341 sep = '|'; 1317 sep = '|';
1342 } 1318 }
1343 if (self->flags & ASYNC_LOW_LATENCY) { 1319 if (self->port.flags & ASYNC_LOW_LATENCY) {
1344 seq_printf(m, "%cASYNC_LOW_LATENCY", sep); 1320 seq_printf(m, "%cASYNC_LOW_LATENCY", sep);
1345 sep = '|'; 1321 sep = '|';
1346 } 1322 }
1347 if (self->flags & ASYNC_CLOSING) { 1323 if (self->port.flags & ASYNC_CLOSING) {
1348 seq_printf(m, "%cASYNC_CLOSING", sep); 1324 seq_printf(m, "%cASYNC_CLOSING", sep);
1349 sep = '|'; 1325 sep = '|';
1350 } 1326 }
1351 if (self->flags & ASYNC_NORMAL_ACTIVE) { 1327 if (self->port.flags & ASYNC_NORMAL_ACTIVE) {
1352 seq_printf(m, "%cASYNC_NORMAL_ACTIVE", sep); 1328 seq_printf(m, "%cASYNC_NORMAL_ACTIVE", sep);
1353 sep = '|'; 1329 sep = '|';
1354 } 1330 }
1355 seq_putc(m, '\n'); 1331 seq_putc(m, '\n');
1356 1332
1357 seq_printf(m, "Role: %s\n", self->client ? "client" : "server"); 1333 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
1358 seq_printf(m, "Open count: %d\n", self->open_count); 1334 seq_printf(m, "Open count: %d\n", self->port.count);
1359 seq_printf(m, "Max data size: %d\n", self->max_data_size); 1335 seq_printf(m, "Max data size: %d\n", self->max_data_size);
1360 seq_printf(m, "Max header size: %d\n", self->max_header_size); 1336 seq_printf(m, "Max header size: %d\n", self->max_header_size);
1361 1337
1362 if (self->tty) 1338 tty = tty_port_tty_get(&self->port);
1339 if (tty) {
1363 seq_printf(m, "Hardware: %s\n", 1340 seq_printf(m, "Hardware: %s\n",
1364 self->tty->hw_stopped ? "Stopped" : "Running"); 1341 tty->hw_stopped ? "Stopped" : "Running");
1342 tty_kref_put(tty);
1343 }
1365} 1344}
1366 1345
1367static int ircomm_tty_proc_show(struct seq_file *m, void *v) 1346static int ircomm_tty_proc_show(struct seq_file *m, void *v)
diff --git a/net/irda/ircomm/ircomm_tty_attach.c b/net/irda/ircomm/ircomm_tty_attach.c
index b65d66e0d817..3ab70e7a0715 100644
--- a/net/irda/ircomm/ircomm_tty_attach.c
+++ b/net/irda/ircomm/ircomm_tty_attach.c
@@ -130,6 +130,8 @@ static int (*state[])(struct ircomm_tty_cb *self, IRCOMM_TTY_EVENT event,
130 */ 130 */
131int ircomm_tty_attach_cable(struct ircomm_tty_cb *self) 131int ircomm_tty_attach_cable(struct ircomm_tty_cb *self)
132{ 132{
133 struct tty_struct *tty;
134
133 IRDA_DEBUG(0, "%s()\n", __func__ ); 135 IRDA_DEBUG(0, "%s()\n", __func__ );
134 136
135 IRDA_ASSERT(self != NULL, return -1;); 137 IRDA_ASSERT(self != NULL, return -1;);
@@ -142,7 +144,11 @@ int ircomm_tty_attach_cable(struct ircomm_tty_cb *self)
142 } 144 }
143 145
144 /* Make sure nobody tries to write before the link is up */ 146 /* Make sure nobody tries to write before the link is up */
145 self->tty->hw_stopped = 1; 147 tty = tty_port_tty_get(&self->port);
148 if (tty) {
149 tty->hw_stopped = 1;
150 tty_kref_put(tty);
151 }
146 152
147 ircomm_tty_ias_register(self); 153 ircomm_tty_ias_register(self);
148 154
@@ -398,23 +404,26 @@ void ircomm_tty_disconnect_indication(void *instance, void *sap,
398 struct sk_buff *skb) 404 struct sk_buff *skb)
399{ 405{
400 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; 406 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
407 struct tty_struct *tty;
401 408
402 IRDA_DEBUG(2, "%s()\n", __func__ ); 409 IRDA_DEBUG(2, "%s()\n", __func__ );
403 410
404 IRDA_ASSERT(self != NULL, return;); 411 IRDA_ASSERT(self != NULL, return;);
405 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); 412 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
406 413
407 if (!self->tty) 414 tty = tty_port_tty_get(&self->port);
415 if (!tty)
408 return; 416 return;
409 417
410 /* This will stop control data transfers */ 418 /* This will stop control data transfers */
411 self->flow = FLOW_STOP; 419 self->flow = FLOW_STOP;
412 420
413 /* Stop data transfers */ 421 /* Stop data transfers */
414 self->tty->hw_stopped = 1; 422 tty->hw_stopped = 1;
415 423
416 ircomm_tty_do_event(self, IRCOMM_TTY_DISCONNECT_INDICATION, NULL, 424 ircomm_tty_do_event(self, IRCOMM_TTY_DISCONNECT_INDICATION, NULL,
417 NULL); 425 NULL);
426 tty_kref_put(tty);
418} 427}
419 428
420/* 429/*
@@ -550,12 +559,15 @@ void ircomm_tty_connect_indication(void *instance, void *sap,
550 */ 559 */
551void ircomm_tty_link_established(struct ircomm_tty_cb *self) 560void ircomm_tty_link_established(struct ircomm_tty_cb *self)
552{ 561{
562 struct tty_struct *tty;
563
553 IRDA_DEBUG(2, "%s()\n", __func__ ); 564 IRDA_DEBUG(2, "%s()\n", __func__ );
554 565
555 IRDA_ASSERT(self != NULL, return;); 566 IRDA_ASSERT(self != NULL, return;);
556 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); 567 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
557 568
558 if (!self->tty) 569 tty = tty_port_tty_get(&self->port);
570 if (!tty)
559 return; 571 return;
560 572
561 del_timer(&self->watchdog_timer); 573 del_timer(&self->watchdog_timer);
@@ -566,19 +578,22 @@ void ircomm_tty_link_established(struct ircomm_tty_cb *self)
566 * will have to wait for the peer device (DCE) to raise the CTS 578 * will have to wait for the peer device (DCE) to raise the CTS
567 * line. 579 * line.
568 */ 580 */
569 if ((self->flags & ASYNC_CTS_FLOW) && ((self->settings.dce & IRCOMM_CTS) == 0)) { 581 if ((self->port.flags & ASYNC_CTS_FLOW) &&
582 ((self->settings.dce & IRCOMM_CTS) == 0)) {
570 IRDA_DEBUG(0, "%s(), waiting for CTS ...\n", __func__ ); 583 IRDA_DEBUG(0, "%s(), waiting for CTS ...\n", __func__ );
571 return; 584 goto put;
572 } else { 585 } else {
573 IRDA_DEBUG(1, "%s(), starting hardware!\n", __func__ ); 586 IRDA_DEBUG(1, "%s(), starting hardware!\n", __func__ );
574 587
575 self->tty->hw_stopped = 0; 588 tty->hw_stopped = 0;
576 589
577 /* Wake up processes blocked on open */ 590 /* Wake up processes blocked on open */
578 wake_up_interruptible(&self->open_wait); 591 wake_up_interruptible(&self->port.open_wait);
579 } 592 }
580 593
581 schedule_work(&self->tqueue); 594 schedule_work(&self->tqueue);
595put:
596 tty_kref_put(tty);
582} 597}
583 598
584/* 599/*
@@ -977,14 +992,17 @@ static int ircomm_tty_state_ready(struct ircomm_tty_cb *self,
977 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH); 992 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH);
978 ircomm_tty_start_watchdog_timer(self, 3*HZ); 993 ircomm_tty_start_watchdog_timer(self, 3*HZ);
979 994
980 if (self->flags & ASYNC_CHECK_CD) { 995 if (self->port.flags & ASYNC_CHECK_CD) {
981 /* Drop carrier */ 996 /* Drop carrier */
982 self->settings.dce = IRCOMM_DELTA_CD; 997 self->settings.dce = IRCOMM_DELTA_CD;
983 ircomm_tty_check_modem_status(self); 998 ircomm_tty_check_modem_status(self);
984 } else { 999 } else {
1000 struct tty_struct *tty = tty_port_tty_get(&self->port);
985 IRDA_DEBUG(0, "%s(), hanging up!\n", __func__ ); 1001 IRDA_DEBUG(0, "%s(), hanging up!\n", __func__ );
986 if (self->tty) 1002 if (tty) {
987 tty_hangup(self->tty); 1003 tty_hangup(tty);
1004 tty_kref_put(tty);
1005 }
988 } 1006 }
989 break; 1007 break;
990 default: 1008 default:
diff --git a/net/irda/ircomm/ircomm_tty_ioctl.c b/net/irda/ircomm/ircomm_tty_ioctl.c
index d0667d68351d..0eab6500e99f 100644
--- a/net/irda/ircomm/ircomm_tty_ioctl.c
+++ b/net/irda/ircomm/ircomm_tty_ioctl.c
@@ -52,17 +52,18 @@
52 * Change speed of the driver. If the remote device is a DCE, then this 52 * Change speed of the driver. If the remote device is a DCE, then this
53 * should make it change the speed of its serial port 53 * should make it change the speed of its serial port
54 */ 54 */
55static void ircomm_tty_change_speed(struct ircomm_tty_cb *self) 55static void ircomm_tty_change_speed(struct ircomm_tty_cb *self,
56 struct tty_struct *tty)
56{ 57{
57 unsigned int cflag, cval; 58 unsigned int cflag, cval;
58 int baud; 59 int baud;
59 60
60 IRDA_DEBUG(2, "%s()\n", __func__ ); 61 IRDA_DEBUG(2, "%s()\n", __func__ );
61 62
62 if (!self->tty || !self->tty->termios || !self->ircomm) 63 if (!self->ircomm)
63 return; 64 return;
64 65
65 cflag = self->tty->termios->c_cflag; 66 cflag = tty->termios->c_cflag;
66 67
67 /* byte size and parity */ 68 /* byte size and parity */
68 switch (cflag & CSIZE) { 69 switch (cflag & CSIZE) {
@@ -81,7 +82,7 @@ static void ircomm_tty_change_speed(struct ircomm_tty_cb *self)
81 cval |= IRCOMM_PARITY_EVEN; 82 cval |= IRCOMM_PARITY_EVEN;
82 83
83 /* Determine divisor based on baud rate */ 84 /* Determine divisor based on baud rate */
84 baud = tty_get_baud_rate(self->tty); 85 baud = tty_get_baud_rate(tty);
85 if (!baud) 86 if (!baud)
86 baud = 9600; /* B0 transition handled in rs_set_termios */ 87 baud = 9600; /* B0 transition handled in rs_set_termios */
87 88
@@ -90,19 +91,19 @@ static void ircomm_tty_change_speed(struct ircomm_tty_cb *self)
90 91
91 /* CTS flow control flag and modem status interrupts */ 92 /* CTS flow control flag and modem status interrupts */
92 if (cflag & CRTSCTS) { 93 if (cflag & CRTSCTS) {
93 self->flags |= ASYNC_CTS_FLOW; 94 self->port.flags |= ASYNC_CTS_FLOW;
94 self->settings.flow_control |= IRCOMM_RTS_CTS_IN; 95 self->settings.flow_control |= IRCOMM_RTS_CTS_IN;
95 /* This got me. Bummer. Jean II */ 96 /* This got me. Bummer. Jean II */
96 if (self->service_type == IRCOMM_3_WIRE_RAW) 97 if (self->service_type == IRCOMM_3_WIRE_RAW)
97 IRDA_WARNING("%s(), enabling RTS/CTS on link that doesn't support it (3-wire-raw)\n", __func__); 98 IRDA_WARNING("%s(), enabling RTS/CTS on link that doesn't support it (3-wire-raw)\n", __func__);
98 } else { 99 } else {
99 self->flags &= ~ASYNC_CTS_FLOW; 100 self->port.flags &= ~ASYNC_CTS_FLOW;
100 self->settings.flow_control &= ~IRCOMM_RTS_CTS_IN; 101 self->settings.flow_control &= ~IRCOMM_RTS_CTS_IN;
101 } 102 }
102 if (cflag & CLOCAL) 103 if (cflag & CLOCAL)
103 self->flags &= ~ASYNC_CHECK_CD; 104 self->port.flags &= ~ASYNC_CHECK_CD;
104 else 105 else
105 self->flags |= ASYNC_CHECK_CD; 106 self->port.flags |= ASYNC_CHECK_CD;
106#if 0 107#if 0
107 /* 108 /*
108 * Set up parity check flag 109 * Set up parity check flag
@@ -159,7 +160,7 @@ void ircomm_tty_set_termios(struct tty_struct *tty,
159 return; 160 return;
160 } 161 }
161 162
162 ircomm_tty_change_speed(self); 163 ircomm_tty_change_speed(self, tty);
163 164
164 /* Handle transition to B0 status */ 165 /* Handle transition to B0 status */
165 if ((old_termios->c_cflag & CBAUD) && 166 if ((old_termios->c_cflag & CBAUD) &&
@@ -270,10 +271,10 @@ static int ircomm_tty_get_serial_info(struct ircomm_tty_cb *self,
270 271
271 memset(&info, 0, sizeof(info)); 272 memset(&info, 0, sizeof(info));
272 info.line = self->line; 273 info.line = self->line;
273 info.flags = self->flags; 274 info.flags = self->port.flags;
274 info.baud_base = self->settings.data_rate; 275 info.baud_base = self->settings.data_rate;
275 info.close_delay = self->close_delay; 276 info.close_delay = self->port.close_delay;
276 info.closing_wait = self->closing_wait; 277 info.closing_wait = self->port.closing_wait;
277 278
278 /* For compatibility */ 279 /* For compatibility */
279 info.type = PORT_16550A; 280 info.type = PORT_16550A;