aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial/imx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/serial/imx.c')
-rw-r--r--drivers/serial/imx.c294
1 files changed, 229 insertions, 65 deletions
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c
index 738c8a5f64f2..285b414f3054 100644
--- a/drivers/serial/imx.c
+++ b/drivers/serial/imx.c
@@ -8,6 +8,9 @@
8 * Author: Sascha Hauer <sascha@saschahauer.de> 8 * Author: Sascha Hauer <sascha@saschahauer.de>
9 * Copyright (C) 2004 Pengutronix 9 * Copyright (C) 2004 Pengutronix
10 * 10 *
11 * Copyright (C) 2009 emlix GmbH
12 * Author: Fabian Godehardt (added IrDA support for iMX)
13 *
11 * This program is free software; you can redistribute it and/or modify 14 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 15 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 16 * the Free Software Foundation; either version 2 of the License, or
@@ -41,6 +44,8 @@
41#include <linux/serial_core.h> 44#include <linux/serial_core.h>
42#include <linux/serial.h> 45#include <linux/serial.h>
43#include <linux/clk.h> 46#include <linux/clk.h>
47#include <linux/delay.h>
48#include <linux/rational.h>
44 49
45#include <asm/io.h> 50#include <asm/io.h>
46#include <asm/irq.h> 51#include <asm/irq.h>
@@ -148,6 +153,7 @@
148#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */ 153#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */
149#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */ 154#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */
150#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */ 155#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */
156#define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7)
151#define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */ 157#define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */
152#define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */ 158#define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */
153#define USR1_RTSS (1<<14) /* RTS pin status */ 159#define USR1_RTSS (1<<14) /* RTS pin status */
@@ -204,10 +210,20 @@ struct imx_port {
204 struct timer_list timer; 210 struct timer_list timer;
205 unsigned int old_status; 211 unsigned int old_status;
206 int txirq,rxirq,rtsirq; 212 int txirq,rxirq,rtsirq;
207 int have_rtscts:1; 213 unsigned int have_rtscts:1;
214 unsigned int use_irda:1;
215 unsigned int irda_inv_rx:1;
216 unsigned int irda_inv_tx:1;
217 unsigned short trcv_delay; /* transceiver delay */
208 struct clk *clk; 218 struct clk *clk;
209}; 219};
210 220
221#ifdef CONFIG_IRDA
222#define USE_IRDA(sport) ((sport)->use_irda)
223#else
224#define USE_IRDA(sport) (0)
225#endif
226
211/* 227/*
212 * Handle any change of modem status signal since we were last called. 228 * Handle any change of modem status signal since we were last called.
213 */ 229 */
@@ -261,6 +277,48 @@ static void imx_stop_tx(struct uart_port *port)
261 struct imx_port *sport = (struct imx_port *)port; 277 struct imx_port *sport = (struct imx_port *)port;
262 unsigned long temp; 278 unsigned long temp;
263 279
280 if (USE_IRDA(sport)) {
281 /* half duplex - wait for end of transmission */
282 int n = 256;
283 while ((--n > 0) &&
284 !(readl(sport->port.membase + USR2) & USR2_TXDC)) {
285 udelay(5);
286 barrier();
287 }
288 /*
289 * irda transceiver - wait a bit more to avoid
290 * cutoff, hardware dependent
291 */
292 udelay(sport->trcv_delay);
293
294 /*
295 * half duplex - reactivate receive mode,
296 * flush receive pipe echo crap
297 */
298 if (readl(sport->port.membase + USR2) & USR2_TXDC) {
299 temp = readl(sport->port.membase + UCR1);
300 temp &= ~(UCR1_TXMPTYEN | UCR1_TRDYEN);
301 writel(temp, sport->port.membase + UCR1);
302
303 temp = readl(sport->port.membase + UCR4);
304 temp &= ~(UCR4_TCEN);
305 writel(temp, sport->port.membase + UCR4);
306
307 while (readl(sport->port.membase + URXD0) &
308 URXD_CHARRDY)
309 barrier();
310
311 temp = readl(sport->port.membase + UCR1);
312 temp |= UCR1_RRDYEN;
313 writel(temp, sport->port.membase + UCR1);
314
315 temp = readl(sport->port.membase + UCR4);
316 temp |= UCR4_DREN;
317 writel(temp, sport->port.membase + UCR4);
318 }
319 return;
320 }
321
264 temp = readl(sport->port.membase + UCR1); 322 temp = readl(sport->port.membase + UCR1);
265 writel(temp & ~UCR1_TXMPTYEN, sport->port.membase + UCR1); 323 writel(temp & ~UCR1_TXMPTYEN, sport->port.membase + UCR1);
266} 324}
@@ -295,13 +353,15 @@ static inline void imx_transmit_buffer(struct imx_port *sport)
295 /* send xmit->buf[xmit->tail] 353 /* send xmit->buf[xmit->tail]
296 * out the port here */ 354 * out the port here */
297 writel(xmit->buf[xmit->tail], sport->port.membase + URTX0); 355 writel(xmit->buf[xmit->tail], sport->port.membase + URTX0);
298 xmit->tail = (xmit->tail + 1) & 356 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
299 (UART_XMIT_SIZE - 1);
300 sport->port.icount.tx++; 357 sport->port.icount.tx++;
301 if (uart_circ_empty(xmit)) 358 if (uart_circ_empty(xmit))
302 break; 359 break;
303 } 360 }
304 361
362 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
363 uart_write_wakeup(&sport->port);
364
305 if (uart_circ_empty(xmit)) 365 if (uart_circ_empty(xmit))
306 imx_stop_tx(&sport->port); 366 imx_stop_tx(&sport->port);
307} 367}
@@ -314,9 +374,30 @@ static void imx_start_tx(struct uart_port *port)
314 struct imx_port *sport = (struct imx_port *)port; 374 struct imx_port *sport = (struct imx_port *)port;
315 unsigned long temp; 375 unsigned long temp;
316 376
377 if (USE_IRDA(sport)) {
378 /* half duplex in IrDA mode; have to disable receive mode */
379 temp = readl(sport->port.membase + UCR4);
380 temp &= ~(UCR4_DREN);
381 writel(temp, sport->port.membase + UCR4);
382
383 temp = readl(sport->port.membase + UCR1);
384 temp &= ~(UCR1_RRDYEN);
385 writel(temp, sport->port.membase + UCR1);
386 }
387
317 temp = readl(sport->port.membase + UCR1); 388 temp = readl(sport->port.membase + UCR1);
318 writel(temp | UCR1_TXMPTYEN, sport->port.membase + UCR1); 389 writel(temp | UCR1_TXMPTYEN, sport->port.membase + UCR1);
319 390
391 if (USE_IRDA(sport)) {
392 temp = readl(sport->port.membase + UCR1);
393 temp |= UCR1_TRDYEN;
394 writel(temp, sport->port.membase + UCR1);
395
396 temp = readl(sport->port.membase + UCR4);
397 temp |= UCR4_TCEN;
398 writel(temp, sport->port.membase + UCR4);
399 }
400
320 if (readl(sport->port.membase + UTS) & UTS_TXEMPTY) 401 if (readl(sport->port.membase + UTS) & UTS_TXEMPTY)
321 imx_transmit_buffer(sport); 402 imx_transmit_buffer(sport);
322} 403}
@@ -388,8 +469,7 @@ static irqreturn_t imx_rxint(int irq, void *dev_id)
388 continue; 469 continue;
389 } 470 }
390 471
391 if (uart_handle_sysrq_char 472 if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx))
392 (&sport->port, (unsigned char)rx))
393 continue; 473 continue;
394 474
395 if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) { 475 if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) {
@@ -464,26 +544,26 @@ static unsigned int imx_tx_empty(struct uart_port *port)
464 */ 544 */
465static unsigned int imx_get_mctrl(struct uart_port *port) 545static unsigned int imx_get_mctrl(struct uart_port *port)
466{ 546{
467 struct imx_port *sport = (struct imx_port *)port; 547 struct imx_port *sport = (struct imx_port *)port;
468 unsigned int tmp = TIOCM_DSR | TIOCM_CAR; 548 unsigned int tmp = TIOCM_DSR | TIOCM_CAR;
469 549
470 if (readl(sport->port.membase + USR1) & USR1_RTSS) 550 if (readl(sport->port.membase + USR1) & USR1_RTSS)
471 tmp |= TIOCM_CTS; 551 tmp |= TIOCM_CTS;
472 552
473 if (readl(sport->port.membase + UCR2) & UCR2_CTS) 553 if (readl(sport->port.membase + UCR2) & UCR2_CTS)
474 tmp |= TIOCM_RTS; 554 tmp |= TIOCM_RTS;
475 555
476 return tmp; 556 return tmp;
477} 557}
478 558
479static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl) 559static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl)
480{ 560{
481 struct imx_port *sport = (struct imx_port *)port; 561 struct imx_port *sport = (struct imx_port *)port;
482 unsigned long temp; 562 unsigned long temp;
483 563
484 temp = readl(sport->port.membase + UCR2) & ~UCR2_CTS; 564 temp = readl(sport->port.membase + UCR2) & ~UCR2_CTS;
485 565
486 if (mctrl & TIOCM_RTS) 566 if (mctrl & TIOCM_RTS)
487 temp |= UCR2_CTS; 567 temp |= UCR2_CTS;
488 568
489 writel(temp, sport->port.membase + UCR2); 569 writel(temp, sport->port.membase + UCR2);
@@ -527,12 +607,7 @@ static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode)
527 if(!ufcr_rfdiv) 607 if(!ufcr_rfdiv)
528 ufcr_rfdiv = 1; 608 ufcr_rfdiv = 1;
529 609
530 if(ufcr_rfdiv >= 7) 610 val |= UFCR_RFDIV_REG(ufcr_rfdiv);
531 ufcr_rfdiv = 6;
532 else
533 ufcr_rfdiv = 6 - ufcr_rfdiv;
534
535 val |= UFCR_RFDIV & (ufcr_rfdiv << 7);
536 611
537 writel(val, sport->port.membase + UFCR); 612 writel(val, sport->port.membase + UFCR);
538 613
@@ -551,8 +626,24 @@ static int imx_startup(struct uart_port *port)
551 * requesting IRQs 626 * requesting IRQs
552 */ 627 */
553 temp = readl(sport->port.membase + UCR4); 628 temp = readl(sport->port.membase + UCR4);
629
630 if (USE_IRDA(sport))
631 temp |= UCR4_IRSC;
632
554 writel(temp & ~UCR4_DREN, sport->port.membase + UCR4); 633 writel(temp & ~UCR4_DREN, sport->port.membase + UCR4);
555 634
635 if (USE_IRDA(sport)) {
636 /* reset fifo's and state machines */
637 int i = 100;
638 temp = readl(sport->port.membase + UCR2);
639 temp &= ~UCR2_SRST;
640 writel(temp, sport->port.membase + UCR2);
641 while (!(readl(sport->port.membase + UCR2) & UCR2_SRST) &&
642 (--i > 0)) {
643 udelay(1);
644 }
645 }
646
556 /* 647 /*
557 * Allocate the IRQ(s) i.MX1 has three interrupts whereas later 648 * Allocate the IRQ(s) i.MX1 has three interrupts whereas later
558 * chips only have one interrupt. 649 * chips only have one interrupt.
@@ -568,12 +659,16 @@ static int imx_startup(struct uart_port *port)
568 if (retval) 659 if (retval)
569 goto error_out2; 660 goto error_out2;
570 661
571 retval = request_irq(sport->rtsirq, imx_rtsint, 662 /* do not use RTS IRQ on IrDA */
572 (sport->rtsirq < MAX_INTERNAL_IRQ) ? 0 : 663 if (!USE_IRDA(sport)) {
573 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 664 retval = request_irq(sport->rtsirq, imx_rtsint,
574 DRIVER_NAME, sport); 665 (sport->rtsirq < MAX_INTERNAL_IRQ) ? 0 :
575 if (retval) 666 IRQF_TRIGGER_FALLING |
576 goto error_out3; 667 IRQF_TRIGGER_RISING,
668 DRIVER_NAME, sport);
669 if (retval)
670 goto error_out3;
671 }
577 } else { 672 } else {
578 retval = request_irq(sport->port.irq, imx_int, 0, 673 retval = request_irq(sport->port.irq, imx_int, 0,
579 DRIVER_NAME, sport); 674 DRIVER_NAME, sport);
@@ -590,18 +685,49 @@ static int imx_startup(struct uart_port *port)
590 685
591 temp = readl(sport->port.membase + UCR1); 686 temp = readl(sport->port.membase + UCR1);
592 temp |= UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN; 687 temp |= UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN;
688
689 if (USE_IRDA(sport)) {
690 temp |= UCR1_IREN;
691 temp &= ~(UCR1_RTSDEN);
692 }
693
593 writel(temp, sport->port.membase + UCR1); 694 writel(temp, sport->port.membase + UCR1);
594 695
595 temp = readl(sport->port.membase + UCR2); 696 temp = readl(sport->port.membase + UCR2);
596 temp |= (UCR2_RXEN | UCR2_TXEN); 697 temp |= (UCR2_RXEN | UCR2_TXEN);
597 writel(temp, sport->port.membase + UCR2); 698 writel(temp, sport->port.membase + UCR2);
598 699
700 if (USE_IRDA(sport)) {
701 /* clear RX-FIFO */
702 int i = 64;
703 while ((--i > 0) &&
704 (readl(sport->port.membase + URXD0) & URXD_CHARRDY)) {
705 barrier();
706 }
707 }
708
599#if defined CONFIG_ARCH_MX2 || defined CONFIG_ARCH_MX3 709#if defined CONFIG_ARCH_MX2 || defined CONFIG_ARCH_MX3
600 temp = readl(sport->port.membase + UCR3); 710 temp = readl(sport->port.membase + UCR3);
601 temp |= UCR3_RXDMUXSEL; 711 temp |= UCR3_RXDMUXSEL;
602 writel(temp, sport->port.membase + UCR3); 712 writel(temp, sport->port.membase + UCR3);
603#endif 713#endif
604 714
715 if (USE_IRDA(sport)) {
716 temp = readl(sport->port.membase + UCR4);
717 if (sport->irda_inv_rx)
718 temp |= UCR4_INVR;
719 else
720 temp &= ~(UCR4_INVR);
721 writel(temp | UCR4_DREN, sport->port.membase + UCR4);
722
723 temp = readl(sport->port.membase + UCR3);
724 if (sport->irda_inv_tx)
725 temp |= UCR3_INVT;
726 else
727 temp &= ~(UCR3_INVT);
728 writel(temp, sport->port.membase + UCR3);
729 }
730
605 /* 731 /*
606 * Enable modem status interrupts 732 * Enable modem status interrupts
607 */ 733 */
@@ -609,6 +735,16 @@ static int imx_startup(struct uart_port *port)
609 imx_enable_ms(&sport->port); 735 imx_enable_ms(&sport->port);
610 spin_unlock_irqrestore(&sport->port.lock,flags); 736 spin_unlock_irqrestore(&sport->port.lock,flags);
611 737
738 if (USE_IRDA(sport)) {
739 struct imxuart_platform_data *pdata;
740 pdata = sport->port.dev->platform_data;
741 sport->irda_inv_rx = pdata->irda_inv_rx;
742 sport->irda_inv_tx = pdata->irda_inv_tx;
743 sport->trcv_delay = pdata->transceiver_delay;
744 if (pdata->irda_enable)
745 pdata->irda_enable(1);
746 }
747
612 return 0; 748 return 0;
613 749
614error_out3: 750error_out3:
@@ -626,6 +762,17 @@ static void imx_shutdown(struct uart_port *port)
626 struct imx_port *sport = (struct imx_port *)port; 762 struct imx_port *sport = (struct imx_port *)port;
627 unsigned long temp; 763 unsigned long temp;
628 764
765 temp = readl(sport->port.membase + UCR2);
766 temp &= ~(UCR2_TXEN);
767 writel(temp, sport->port.membase + UCR2);
768
769 if (USE_IRDA(sport)) {
770 struct imxuart_platform_data *pdata;
771 pdata = sport->port.dev->platform_data;
772 if (pdata->irda_enable)
773 pdata->irda_enable(0);
774 }
775
629 /* 776 /*
630 * Stop our timer. 777 * Stop our timer.
631 */ 778 */
@@ -635,7 +782,8 @@ static void imx_shutdown(struct uart_port *port)
635 * Free the interrupts 782 * Free the interrupts
636 */ 783 */
637 if (sport->txirq > 0) { 784 if (sport->txirq > 0) {
638 free_irq(sport->rtsirq, sport); 785 if (!USE_IRDA(sport))
786 free_irq(sport->rtsirq, sport);
639 free_irq(sport->txirq, sport); 787 free_irq(sport->txirq, sport);
640 free_irq(sport->rxirq, sport); 788 free_irq(sport->rxirq, sport);
641 } else 789 } else
@@ -647,6 +795,9 @@ static void imx_shutdown(struct uart_port *port)
647 795
648 temp = readl(sport->port.membase + UCR1); 796 temp = readl(sport->port.membase + UCR1);
649 temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); 797 temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN);
798 if (USE_IRDA(sport))
799 temp &= ~(UCR1_IREN);
800
650 writel(temp, sport->port.membase + UCR1); 801 writel(temp, sport->port.membase + UCR1);
651} 802}
652 803
@@ -658,7 +809,9 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
658 unsigned long flags; 809 unsigned long flags;
659 unsigned int ucr2, old_ucr1, old_txrxen, baud, quot; 810 unsigned int ucr2, old_ucr1, old_txrxen, baud, quot;
660 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; 811 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
661 unsigned int div, num, denom, ufcr; 812 unsigned int div, ufcr;
813 unsigned long num, denom;
814 uint64_t tdiv64;
662 815
663 /* 816 /*
664 * If we don't support modem control lines, don't allow 817 * If we don't support modem control lines, don't allow
@@ -754,38 +907,39 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
754 sport->port.membase + UCR2); 907 sport->port.membase + UCR2);
755 old_txrxen &= (UCR2_TXEN | UCR2_RXEN); 908 old_txrxen &= (UCR2_TXEN | UCR2_RXEN);
756 909
757 div = sport->port.uartclk / (baud * 16); 910 if (USE_IRDA(sport)) {
758 if (div > 7) 911 /*
759 div = 7; 912 * use maximum available submodule frequency to
760 if (!div) 913 * avoid missing short pulses due to low sampling rate
914 */
761 div = 1; 915 div = 1;
762 916 } else {
763 num = baud; 917 div = sport->port.uartclk / (baud * 16);
764 denom = port->uartclk / div / 16; 918 if (div > 7)
765 919 div = 7;
766 /* shift num and denom right until they fit into 16 bits */ 920 if (!div)
767 while (num > 0x10000 || denom > 0x10000) { 921 div = 1;
768 num >>= 1;
769 denom >>= 1;
770 } 922 }
771 if (num > 0)
772 num -= 1;
773 if (denom > 0)
774 denom -= 1;
775 923
776 writel(num, sport->port.membase + UBIR); 924 rational_best_approximation(16 * div * baud, sport->port.uartclk,
777 writel(denom, sport->port.membase + UBMR); 925 1 << 16, 1 << 16, &num, &denom);
778 926
779 if (div == 7) 927 tdiv64 = sport->port.uartclk;
780 div = 6; /* 6 in RFDIV means divide by 7 */ 928 tdiv64 *= num;
781 else 929 do_div(tdiv64, denom * 16 * div);
782 div = 6 - div; 930 tty_encode_baud_rate(sport->port.info->port.tty,
931 (speed_t)tdiv64, (speed_t)tdiv64);
932
933 num -= 1;
934 denom -= 1;
783 935
784 ufcr = readl(sport->port.membase + UFCR); 936 ufcr = readl(sport->port.membase + UFCR);
785 ufcr = (ufcr & (~UFCR_RFDIV)) | 937 ufcr = (ufcr & (~UFCR_RFDIV)) | UFCR_RFDIV_REG(div);
786 (div << 7);
787 writel(ufcr, sport->port.membase + UFCR); 938 writel(ufcr, sport->port.membase + UFCR);
788 939
940 writel(num, sport->port.membase + UBIR);
941 writel(denom, sport->port.membase + UBMR);
942
789#ifdef ONEMS 943#ifdef ONEMS
790 writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS); 944 writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS);
791#endif 945#endif
@@ -1065,22 +1219,22 @@ static struct uart_driver imx_reg = {
1065 1219
1066static int serial_imx_suspend(struct platform_device *dev, pm_message_t state) 1220static int serial_imx_suspend(struct platform_device *dev, pm_message_t state)
1067{ 1221{
1068 struct imx_port *sport = platform_get_drvdata(dev); 1222 struct imx_port *sport = platform_get_drvdata(dev);
1069 1223
1070 if (sport) 1224 if (sport)
1071 uart_suspend_port(&imx_reg, &sport->port); 1225 uart_suspend_port(&imx_reg, &sport->port);
1072 1226
1073 return 0; 1227 return 0;
1074} 1228}
1075 1229
1076static int serial_imx_resume(struct platform_device *dev) 1230static int serial_imx_resume(struct platform_device *dev)
1077{ 1231{
1078 struct imx_port *sport = platform_get_drvdata(dev); 1232 struct imx_port *sport = platform_get_drvdata(dev);
1079 1233
1080 if (sport) 1234 if (sport)
1081 uart_resume_port(&imx_reg, &sport->port); 1235 uart_resume_port(&imx_reg, &sport->port);
1082 1236
1083 return 0; 1237 return 0;
1084} 1238}
1085 1239
1086static int serial_imx_probe(struct platform_device *pdev) 1240static int serial_imx_probe(struct platform_device *pdev)
@@ -1136,19 +1290,29 @@ static int serial_imx_probe(struct platform_device *pdev)
1136 imx_ports[pdev->id] = sport; 1290 imx_ports[pdev->id] = sport;
1137 1291
1138 pdata = pdev->dev.platform_data; 1292 pdata = pdev->dev.platform_data;
1139 if(pdata && (pdata->flags & IMXUART_HAVE_RTSCTS)) 1293 if (pdata && (pdata->flags & IMXUART_HAVE_RTSCTS))
1140 sport->have_rtscts = 1; 1294 sport->have_rtscts = 1;
1141 1295
1296#ifdef CONFIG_IRDA
1297 if (pdata && (pdata->flags & IMXUART_IRDA))
1298 sport->use_irda = 1;
1299#endif
1300
1142 if (pdata->init) { 1301 if (pdata->init) {
1143 ret = pdata->init(pdev); 1302 ret = pdata->init(pdev);
1144 if (ret) 1303 if (ret)
1145 goto clkput; 1304 goto clkput;
1146 } 1305 }
1147 1306
1148 uart_add_one_port(&imx_reg, &sport->port); 1307 ret = uart_add_one_port(&imx_reg, &sport->port);
1308 if (ret)
1309 goto deinit;
1149 platform_set_drvdata(pdev, &sport->port); 1310 platform_set_drvdata(pdev, &sport->port);
1150 1311
1151 return 0; 1312 return 0;
1313deinit:
1314 if (pdata->exit)
1315 pdata->exit(pdev);
1152clkput: 1316clkput:
1153 clk_put(sport->clk); 1317 clk_put(sport->clk);
1154 clk_disable(sport->clk); 1318 clk_disable(sport->clk);
@@ -1186,13 +1350,13 @@ static int serial_imx_remove(struct platform_device *pdev)
1186} 1350}
1187 1351
1188static struct platform_driver serial_imx_driver = { 1352static struct platform_driver serial_imx_driver = {
1189 .probe = serial_imx_probe, 1353 .probe = serial_imx_probe,
1190 .remove = serial_imx_remove, 1354 .remove = serial_imx_remove,
1191 1355
1192 .suspend = serial_imx_suspend, 1356 .suspend = serial_imx_suspend,
1193 .resume = serial_imx_resume, 1357 .resume = serial_imx_resume,
1194 .driver = { 1358 .driver = {
1195 .name = "imx-uart", 1359 .name = "imx-uart",
1196 .owner = THIS_MODULE, 1360 .owner = THIS_MODULE,
1197 }, 1361 },
1198}; 1362};