diff options
Diffstat (limited to 'drivers/tty/serial/vt8500_serial.c')
-rw-r--r-- | drivers/tty/serial/vt8500_serial.c | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c index d5ed9f613005..a3f9dd5c9dff 100644 --- a/drivers/tty/serial/vt8500_serial.c +++ b/drivers/tty/serial/vt8500_serial.c | |||
@@ -136,22 +136,14 @@ static void vt8500_enable_ms(struct uart_port *port) | |||
136 | 136 | ||
137 | static void handle_rx(struct uart_port *port) | 137 | static void handle_rx(struct uart_port *port) |
138 | { | 138 | { |
139 | struct tty_struct *tty = tty_port_tty_get(&port->state->port); | 139 | struct tty_port *tport = &port->state->port; |
140 | if (!tty) { | ||
141 | /* Discard data: no tty available */ | ||
142 | int count = (vt8500_read(port, VT8500_URFIDX) & 0x1f00) >> 8; | ||
143 | u16 ch; | ||
144 | while (count--) | ||
145 | ch = readw(port->membase + VT8500_RXFIFO); | ||
146 | return; | ||
147 | } | ||
148 | 140 | ||
149 | /* | 141 | /* |
150 | * Handle overrun | 142 | * Handle overrun |
151 | */ | 143 | */ |
152 | if ((vt8500_read(port, VT8500_URISR) & RXOVER)) { | 144 | if ((vt8500_read(port, VT8500_URISR) & RXOVER)) { |
153 | port->icount.overrun++; | 145 | port->icount.overrun++; |
154 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); | 146 | tty_insert_flip_char(tport, 0, TTY_OVERRUN); |
155 | } | 147 | } |
156 | 148 | ||
157 | /* and now the main RX loop */ | 149 | /* and now the main RX loop */ |
@@ -174,11 +166,10 @@ static void handle_rx(struct uart_port *port) | |||
174 | port->icount.rx++; | 166 | port->icount.rx++; |
175 | 167 | ||
176 | if (!uart_handle_sysrq_char(port, c)) | 168 | if (!uart_handle_sysrq_char(port, c)) |
177 | tty_insert_flip_char(tty, c, flag); | 169 | tty_insert_flip_char(tport, c, flag); |
178 | } | 170 | } |
179 | 171 | ||
180 | tty_flip_buffer_push(tty); | 172 | tty_flip_buffer_push(tport); |
181 | tty_kref_put(tty); | ||
182 | } | 173 | } |
183 | 174 | ||
184 | static void handle_tx(struct uart_port *port) | 175 | static void handle_tx(struct uart_port *port) |
@@ -569,7 +560,7 @@ static int vt8500_serial_probe(struct platform_device *pdev) | |||
569 | 560 | ||
570 | if (np) | 561 | if (np) |
571 | port = of_alias_get_id(np, "serial"); | 562 | port = of_alias_get_id(np, "serial"); |
572 | if (port > VT8500_MAX_PORTS) | 563 | if (port >= VT8500_MAX_PORTS) |
573 | port = -1; | 564 | port = -1; |
574 | else | 565 | else |
575 | port = -1; | 566 | port = -1; |
@@ -580,7 +571,7 @@ static int vt8500_serial_probe(struct platform_device *pdev) | |||
580 | sizeof(vt8500_ports_in_use)); | 571 | sizeof(vt8500_ports_in_use)); |
581 | } | 572 | } |
582 | 573 | ||
583 | if (port > VT8500_MAX_PORTS) | 574 | if (port >= VT8500_MAX_PORTS) |
584 | return -ENODEV; | 575 | return -ENODEV; |
585 | 576 | ||
586 | /* reserve the port id */ | 577 | /* reserve the port id */ |
@@ -589,10 +580,27 @@ static int vt8500_serial_probe(struct platform_device *pdev) | |||
589 | return -EBUSY; | 580 | return -EBUSY; |
590 | } | 581 | } |
591 | 582 | ||
592 | vt8500_port = kzalloc(sizeof(struct vt8500_port), GFP_KERNEL); | 583 | vt8500_port = devm_kzalloc(&pdev->dev, sizeof(struct vt8500_port), |
584 | GFP_KERNEL); | ||
593 | if (!vt8500_port) | 585 | if (!vt8500_port) |
594 | return -ENOMEM; | 586 | return -ENOMEM; |
595 | 587 | ||
588 | vt8500_port->uart.membase = devm_request_and_ioremap(&pdev->dev, mmres); | ||
589 | if (!vt8500_port->uart.membase) | ||
590 | return -EADDRNOTAVAIL; | ||
591 | |||
592 | vt8500_port->clk = of_clk_get(pdev->dev.of_node, 0); | ||
593 | if (IS_ERR(vt8500_port->clk)) { | ||
594 | dev_err(&pdev->dev, "failed to get clock\n"); | ||
595 | return -EINVAL; | ||
596 | } | ||
597 | |||
598 | ret = clk_prepare_enable(vt8500_port->clk); | ||
599 | if (ret) { | ||
600 | dev_err(&pdev->dev, "failed to enable clock\n"); | ||
601 | return ret; | ||
602 | } | ||
603 | |||
596 | vt8500_port->uart.type = PORT_VT8500; | 604 | vt8500_port->uart.type = PORT_VT8500; |
597 | vt8500_port->uart.iotype = UPIO_MEM; | 605 | vt8500_port->uart.iotype = UPIO_MEM; |
598 | vt8500_port->uart.mapbase = mmres->start; | 606 | vt8500_port->uart.mapbase = mmres->start; |
@@ -615,12 +623,6 @@ static int vt8500_serial_probe(struct platform_device *pdev) | |||
615 | snprintf(vt8500_port->name, sizeof(vt8500_port->name), | 623 | snprintf(vt8500_port->name, sizeof(vt8500_port->name), |
616 | "VT8500 UART%d", pdev->id); | 624 | "VT8500 UART%d", pdev->id); |
617 | 625 | ||
618 | vt8500_port->uart.membase = ioremap(mmres->start, resource_size(mmres)); | ||
619 | if (!vt8500_port->uart.membase) { | ||
620 | ret = -ENOMEM; | ||
621 | goto err; | ||
622 | } | ||
623 | |||
624 | vt8500_uart_ports[port] = vt8500_port; | 626 | vt8500_uart_ports[port] = vt8500_port; |
625 | 627 | ||
626 | uart_add_one_port(&vt8500_uart_driver, &vt8500_port->uart); | 628 | uart_add_one_port(&vt8500_uart_driver, &vt8500_port->uart); |
@@ -628,10 +630,6 @@ static int vt8500_serial_probe(struct platform_device *pdev) | |||
628 | platform_set_drvdata(pdev, vt8500_port); | 630 | platform_set_drvdata(pdev, vt8500_port); |
629 | 631 | ||
630 | return 0; | 632 | return 0; |
631 | |||
632 | err: | ||
633 | kfree(vt8500_port); | ||
634 | return ret; | ||
635 | } | 633 | } |
636 | 634 | ||
637 | static int vt8500_serial_remove(struct platform_device *pdev) | 635 | static int vt8500_serial_remove(struct platform_device *pdev) |
@@ -639,8 +637,8 @@ static int vt8500_serial_remove(struct platform_device *pdev) | |||
639 | struct vt8500_port *vt8500_port = platform_get_drvdata(pdev); | 637 | struct vt8500_port *vt8500_port = platform_get_drvdata(pdev); |
640 | 638 | ||
641 | platform_set_drvdata(pdev, NULL); | 639 | platform_set_drvdata(pdev, NULL); |
640 | clk_disable_unprepare(vt8500_port->clk); | ||
642 | uart_remove_one_port(&vt8500_uart_driver, &vt8500_port->uart); | 641 | uart_remove_one_port(&vt8500_uart_driver, &vt8500_port->uart); |
643 | kfree(vt8500_port); | ||
644 | 642 | ||
645 | return 0; | 643 | return 0; |
646 | } | 644 | } |