aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial/bfin_5xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/serial/bfin_5xx.c')
-rw-r--r--drivers/serial/bfin_5xx.c123
1 files changed, 93 insertions, 30 deletions
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 4a0d30bed9f1..569f0e2476c6 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Blackfin On-Chip Serial Driver 2 * Blackfin On-Chip Serial Driver
3 * 3 *
4 * Copyright 2006-2007 Analog Devices Inc. 4 * Copyright 2006-2008 Analog Devices Inc.
5 * 5 *
6 * Enter bugs at http://blackfin.uclinux.org/ 6 * Enter bugs at http://blackfin.uclinux.org/
7 * 7 *
@@ -42,6 +42,9 @@
42#define BFIN_SERIAL_MAJOR 204 42#define BFIN_SERIAL_MAJOR 204
43#define BFIN_SERIAL_MINOR 64 43#define BFIN_SERIAL_MINOR 64
44 44
45static struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS];
46static int nr_active_ports = ARRAY_SIZE(bfin_serial_resource);
47
45/* 48/*
46 * Setup for console. Argument comes from the menuconfig 49 * Setup for console. Argument comes from the menuconfig
47 */ 50 */
@@ -126,13 +129,13 @@ static int kgdb_entry_state;
126void kgdb_put_debug_char(int chr) 129void kgdb_put_debug_char(int chr)
127{ 130{
128 struct bfin_serial_port *uart; 131 struct bfin_serial_port *uart;
129 132
130 if (CONFIG_KGDB_UART_PORT < 0 133 if (CONFIG_KGDB_UART_PORT < 0
131 || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS) 134 || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
132 uart = &bfin_serial_ports[0]; 135 uart = &bfin_serial_ports[0];
133 else 136 else
134 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT]; 137 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
135 138
136 while (!(UART_GET_LSR(uart) & THRE)) { 139 while (!(UART_GET_LSR(uart) & THRE)) {
137 SSYNC(); 140 SSYNC();
138 } 141 }
@@ -152,7 +155,7 @@ int kgdb_get_debug_char(void)
152 uart = &bfin_serial_ports[0]; 155 uart = &bfin_serial_ports[0];
153 else 156 else
154 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT]; 157 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
155 158
156 while(!(UART_GET_LSR(uart) & DR)) { 159 while(!(UART_GET_LSR(uart) & DR)) {
157 SSYNC(); 160 SSYNC();
158 } 161 }
@@ -298,7 +301,11 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart)
298 bfin_serial_mctrl_check(uart); 301 bfin_serial_mctrl_check(uart);
299 302
300 if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) { 303 if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) {
301 bfin_serial_stop_tx(&uart->port); 304#ifdef CONFIG_BF54x
305 /* Clear TFI bit */
306 UART_PUT_LSR(uart, TFI);
307#endif
308 UART_CLEAR_IER(uart, ETBEI);
302 return; 309 return;
303 } 310 }
304 311
@@ -317,9 +324,6 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart)
317 324
318 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 325 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
319 uart_write_wakeup(&uart->port); 326 uart_write_wakeup(&uart->port);
320
321 if (uart_circ_empty(xmit))
322 bfin_serial_stop_tx(&uart->port);
323} 327}
324 328
325static irqreturn_t bfin_serial_rx_int(int irq, void *dev_id) 329static irqreturn_t bfin_serial_rx_int(int irq, void *dev_id)
@@ -645,6 +649,42 @@ static int bfin_serial_startup(struct uart_port *port)
645 free_irq(uart->port.irq, uart); 649 free_irq(uart->port.irq, uart);
646 return -EBUSY; 650 return -EBUSY;
647 } 651 }
652
653# ifdef CONFIG_BF54x
654 {
655 unsigned uart_dma_ch_rx, uart_dma_ch_tx;
656
657 switch (uart->port.irq) {
658 case IRQ_UART3_RX:
659 uart_dma_ch_rx = CH_UART3_RX;
660 uart_dma_ch_tx = CH_UART3_TX;
661 break;
662 case IRQ_UART2_RX:
663 uart_dma_ch_rx = CH_UART2_RX;
664 uart_dma_ch_tx = CH_UART2_TX;
665 break;
666 default:
667 uart_dma_ch_rx = uart_dma_ch_tx = 0;
668 break;
669 };
670
671 if (uart_dma_ch_rx &&
672 request_dma(uart_dma_ch_rx, "BFIN_UART_RX") < 0) {
673 printk(KERN_NOTICE"Fail to attach UART interrupt\n");
674 free_irq(uart->port.irq, uart);
675 free_irq(uart->port.irq + 1, uart);
676 return -EBUSY;
677 }
678 if (uart_dma_ch_tx &&
679 request_dma(uart_dma_ch_tx, "BFIN_UART_TX") < 0) {
680 printk(KERN_NOTICE "Fail to attach UART interrupt\n");
681 free_dma(uart_dma_ch_rx);
682 free_irq(uart->port.irq, uart);
683 free_irq(uart->port.irq + 1, uart);
684 return -EBUSY;
685 }
686 }
687# endif
648#endif 688#endif
649 UART_SET_IER(uart, ERBFI); 689 UART_SET_IER(uart, ERBFI);
650 return 0; 690 return 0;
@@ -662,6 +702,20 @@ static void bfin_serial_shutdown(struct uart_port *port)
662 del_timer(&(uart->rx_dma_timer)); 702 del_timer(&(uart->rx_dma_timer));
663 dma_free_coherent(NULL, PAGE_SIZE, uart->rx_dma_buf.buf, 0); 703 dma_free_coherent(NULL, PAGE_SIZE, uart->rx_dma_buf.buf, 0);
664#else 704#else
705#ifdef CONFIG_BF54x
706 switch (uart->port.irq) {
707 case IRQ_UART3_RX:
708 free_dma(CH_UART3_RX);
709 free_dma(CH_UART3_TX);
710 break;
711 case IRQ_UART2_RX:
712 free_dma(CH_UART2_RX);
713 free_dma(CH_UART2_TX);
714 break;
715 default:
716 break;
717 };
718#endif
665#ifdef CONFIG_KGDB_UART 719#ifdef CONFIG_KGDB_UART
666 if (uart->port.line != CONFIG_KGDB_UART_PORT) 720 if (uart->port.line != CONFIG_KGDB_UART_PORT)
667#endif 721#endif
@@ -757,6 +811,9 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
757 val |= UCEN; 811 val |= UCEN;
758 UART_PUT_GCTL(uart, val); 812 UART_PUT_GCTL(uart, val);
759 813
814 /* Port speed changed, update the per-port timeout. */
815 uart_update_timeout(port, termios->c_cflag, baud);
816
760 spin_unlock_irqrestore(&uart->port.lock, flags); 817 spin_unlock_irqrestore(&uart->port.lock, flags);
761} 818}
762 819
@@ -859,8 +916,9 @@ static void __init bfin_serial_init_ports(void)
859 return; 916 return;
860 first = 0; 917 first = 0;
861 918
862 for (i = 0; i < nr_ports; i++) { 919 for (i = 0; i < nr_active_ports; i++) {
863 bfin_serial_ports[i].port.uartclk = get_sclk(); 920 bfin_serial_ports[i].port.uartclk = get_sclk();
921 bfin_serial_ports[i].port.fifosize = BFIN_UART_TX_FIFO_SIZE;
864 bfin_serial_ports[i].port.ops = &bfin_serial_pops; 922 bfin_serial_ports[i].port.ops = &bfin_serial_pops;
865 bfin_serial_ports[i].port.line = i; 923 bfin_serial_ports[i].port.line = i;
866 bfin_serial_ports[i].port.iotype = UPIO_MEM; 924 bfin_serial_ports[i].port.iotype = UPIO_MEM;
@@ -961,7 +1019,7 @@ bfin_serial_console_setup(struct console *co, char *options)
961 * if so, search for the first available port that does have 1019 * if so, search for the first available port that does have
962 * console support. 1020 * console support.
963 */ 1021 */
964 if (co->index == -1 || co->index >= nr_ports) 1022 if (co->index == -1 || co->index >= nr_active_ports)
965 co->index = 0; 1023 co->index = 0;
966 uart = &bfin_serial_ports[co->index]; 1024 uart = &bfin_serial_ports[co->index];
967 1025
@@ -1056,7 +1114,7 @@ static __init void early_serial_write(struct console *con, const char *s,
1056 } 1114 }
1057} 1115}
1058 1116
1059static struct __init console bfin_early_serial_console = { 1117static struct __initdata console bfin_early_serial_console = {
1060 .name = "early_BFuart", 1118 .name = "early_BFuart",
1061 .write = early_serial_write, 1119 .write = early_serial_write,
1062 .device = uart_console_device, 1120 .device = uart_console_device,
@@ -1072,7 +1130,7 @@ struct console __init *bfin_earlyserial_init(unsigned int port,
1072 struct bfin_serial_port *uart; 1130 struct bfin_serial_port *uart;
1073 struct ktermios t; 1131 struct ktermios t;
1074 1132
1075 if (port == -1 || port >= nr_ports) 1133 if (port == -1 || port >= nr_active_ports)
1076 port = 0; 1134 port = 0;
1077 bfin_serial_init_ports(); 1135 bfin_serial_init_ports();
1078 bfin_early_serial_console.index = port; 1136 bfin_early_serial_console.index = port;
@@ -1100,20 +1158,26 @@ static struct uart_driver bfin_serial_reg = {
1100 1158
1101static int bfin_serial_suspend(struct platform_device *dev, pm_message_t state) 1159static int bfin_serial_suspend(struct platform_device *dev, pm_message_t state)
1102{ 1160{
1103 struct bfin_serial_port *uart = platform_get_drvdata(dev); 1161 int i;
1104 1162
1105 if (uart) 1163 for (i = 0; i < nr_active_ports; i++) {
1106 uart_suspend_port(&bfin_serial_reg, &uart->port); 1164 if (bfin_serial_ports[i].port.dev != &dev->dev)
1165 continue;
1166 uart_suspend_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
1167 }
1107 1168
1108 return 0; 1169 return 0;
1109} 1170}
1110 1171
1111static int bfin_serial_resume(struct platform_device *dev) 1172static int bfin_serial_resume(struct platform_device *dev)
1112{ 1173{
1113 struct bfin_serial_port *uart = platform_get_drvdata(dev); 1174 int i;
1114 1175
1115 if (uart) 1176 for (i = 0; i < nr_active_ports; i++) {
1116 uart_resume_port(&bfin_serial_reg, &uart->port); 1177 if (bfin_serial_ports[i].port.dev != &dev->dev)
1178 continue;
1179 uart_resume_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
1180 }
1117 1181
1118 return 0; 1182 return 0;
1119} 1183}
@@ -1128,32 +1192,31 @@ static int bfin_serial_probe(struct platform_device *dev)
1128 break; 1192 break;
1129 1193
1130 if (i < dev->num_resources) { 1194 if (i < dev->num_resources) {
1131 for (i = 0; i < nr_ports; i++, res++) { 1195 for (i = 0; i < nr_active_ports; i++, res++) {
1132 if (bfin_serial_ports[i].port.mapbase != res->start) 1196 if (bfin_serial_ports[i].port.mapbase != res->start)
1133 continue; 1197 continue;
1134 bfin_serial_ports[i].port.dev = &dev->dev; 1198 bfin_serial_ports[i].port.dev = &dev->dev;
1135 uart_add_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port); 1199 uart_add_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
1136 platform_set_drvdata(dev, &bfin_serial_ports[i]);
1137 } 1200 }
1138 } 1201 }
1139 1202
1140 return 0; 1203 return 0;
1141} 1204}
1142 1205
1143static int bfin_serial_remove(struct platform_device *pdev) 1206static int bfin_serial_remove(struct platform_device *dev)
1144{ 1207{
1145 struct bfin_serial_port *uart = platform_get_drvdata(pdev); 1208 int i;
1146
1147 1209
1210 for (i = 0; i < nr_active_ports; i++) {
1211 if (bfin_serial_ports[i].port.dev != &dev->dev)
1212 continue;
1213 uart_remove_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
1214 bfin_serial_ports[i].port.dev = NULL;
1148#ifdef CONFIG_SERIAL_BFIN_CTSRTS 1215#ifdef CONFIG_SERIAL_BFIN_CTSRTS
1149 gpio_free(uart->cts_pin); 1216 gpio_free(bfin_serial_ports[i].cts_pin);
1150 gpio_free(uart->rts_pin); 1217 gpio_free(bfin_serial_ports[i].rts_pin);
1151#endif 1218#endif
1152 1219 }
1153 platform_set_drvdata(pdev, NULL);
1154
1155 if (uart)
1156 uart_remove_one_port(&bfin_serial_reg, &uart->port);
1157 1220
1158 return 0; 1221 return 0;
1159} 1222}