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.c239
1 files changed, 126 insertions, 113 deletions
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 569f0e2476c6..318d69dce8e1 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -22,7 +22,8 @@
22#include <linux/tty_flip.h> 22#include <linux/tty_flip.h>
23#include <linux/serial_core.h> 23#include <linux/serial_core.h>
24 24
25#ifdef CONFIG_KGDB_UART 25#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
26 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
26#include <linux/kgdb.h> 27#include <linux/kgdb.h>
27#include <asm/irq_regs.h> 28#include <asm/irq_regs.h>
28#endif 29#endif
@@ -45,6 +46,16 @@
45static struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS]; 46static struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS];
46static int nr_active_ports = ARRAY_SIZE(bfin_serial_resource); 47static int nr_active_ports = ARRAY_SIZE(bfin_serial_resource);
47 48
49#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
50 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
51
52# ifndef CONFIG_SERIAL_BFIN_PIO
53# error KGDB only support UART in PIO mode.
54# endif
55
56static int kgdboc_port_line;
57static int kgdboc_break_enabled;
58#endif
48/* 59/*
49 * Setup for console. Argument comes from the menuconfig 60 * Setup for console. Argument comes from the menuconfig
50 */ 61 */
@@ -62,13 +73,17 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart);
62 73
63static void bfin_serial_mctrl_check(struct bfin_serial_port *uart); 74static void bfin_serial_mctrl_check(struct bfin_serial_port *uart);
64 75
76static void bfin_serial_reset_irda(struct uart_port *port);
77
65/* 78/*
66 * interrupts are disabled on entry 79 * interrupts are disabled on entry
67 */ 80 */
68static void bfin_serial_stop_tx(struct uart_port *port) 81static void bfin_serial_stop_tx(struct uart_port *port)
69{ 82{
70 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 83 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
84#ifdef CONFIG_SERIAL_BFIN_DMA
71 struct circ_buf *xmit = &uart->port.info->xmit; 85 struct circ_buf *xmit = &uart->port.info->xmit;
86#endif
72 87
73 while (!(UART_GET_LSR(uart) & TEMT)) 88 while (!(UART_GET_LSR(uart) & TEMT))
74 cpu_relax(); 89 cpu_relax();
@@ -94,6 +109,14 @@ static void bfin_serial_stop_tx(struct uart_port *port)
94static void bfin_serial_start_tx(struct uart_port *port) 109static void bfin_serial_start_tx(struct uart_port *port)
95{ 110{
96 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 111 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
112 struct tty_struct *tty = uart->port.info->port.tty;
113
114 /*
115 * To avoid losting RX interrupt, we reset IR function
116 * before sending data.
117 */
118 if (tty->termios->c_line == N_IRDA)
119 bfin_serial_reset_irda(port);
97 120
98#ifdef CONFIG_SERIAL_BFIN_DMA 121#ifdef CONFIG_SERIAL_BFIN_DMA
99 if (uart->tx_done) 122 if (uart->tx_done)
@@ -110,9 +133,7 @@ static void bfin_serial_start_tx(struct uart_port *port)
110static void bfin_serial_stop_rx(struct uart_port *port) 133static void bfin_serial_stop_rx(struct uart_port *port)
111{ 134{
112 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 135 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
113#ifdef CONFIG_KGDB_UART 136
114 if (uart->port.line != CONFIG_KGDB_UART_PORT)
115#endif
116 UART_CLEAR_IER(uart, ERBFI); 137 UART_CLEAR_IER(uart, ERBFI);
117} 138}
118 139
@@ -123,49 +144,6 @@ static void bfin_serial_enable_ms(struct uart_port *port)
123{ 144{
124} 145}
125 146
126#ifdef CONFIG_KGDB_UART
127static int kgdb_entry_state;
128
129void kgdb_put_debug_char(int chr)
130{
131 struct bfin_serial_port *uart;
132
133 if (CONFIG_KGDB_UART_PORT < 0
134 || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
135 uart = &bfin_serial_ports[0];
136 else
137 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
138
139 while (!(UART_GET_LSR(uart) & THRE)) {
140 SSYNC();
141 }
142
143 UART_CLEAR_DLAB(uart);
144 UART_PUT_CHAR(uart, (unsigned char)chr);
145 SSYNC();
146}
147
148int kgdb_get_debug_char(void)
149{
150 struct bfin_serial_port *uart;
151 unsigned char chr;
152
153 if (CONFIG_KGDB_UART_PORT < 0
154 || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
155 uart = &bfin_serial_ports[0];
156 else
157 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
158
159 while(!(UART_GET_LSR(uart) & DR)) {
160 SSYNC();
161 }
162 UART_CLEAR_DLAB(uart);
163 chr = UART_GET_CHAR(uart);
164 SSYNC();
165
166 return chr;
167}
168#endif
169 147
170#if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO) 148#if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO)
171# define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold) 149# define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold)
@@ -178,7 +156,7 @@ int kgdb_get_debug_char(void)
178#ifdef CONFIG_SERIAL_BFIN_PIO 156#ifdef CONFIG_SERIAL_BFIN_PIO
179static void bfin_serial_rx_chars(struct bfin_serial_port *uart) 157static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
180{ 158{
181 struct tty_struct *tty = uart->port.info->port.tty; 159 struct tty_struct *tty = NULL;
182 unsigned int status, ch, flg; 160 unsigned int status, ch, flg;
183 static struct timeval anomaly_start = { .tv_sec = 0 }; 161 static struct timeval anomaly_start = { .tv_sec = 0 };
184 162
@@ -188,27 +166,18 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
188 ch = UART_GET_CHAR(uart); 166 ch = UART_GET_CHAR(uart);
189 uart->port.icount.rx++; 167 uart->port.icount.rx++;
190 168
191#ifdef CONFIG_KGDB_UART 169#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
192 if (uart->port.line == CONFIG_KGDB_UART_PORT) { 170 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
193 struct pt_regs *regs = get_irq_regs(); 171 if (kgdb_connected && kgdboc_port_line == uart->port.line)
194 if (uart->port.cons->index == CONFIG_KGDB_UART_PORT && ch == 0x1) { /* Ctrl + A */ 172 if (ch == 0x3) {/* Ctrl + C */
195 kgdb_breakkey_pressed(regs); 173 kgdb_breakpoint();
196 return;
197 } else if (kgdb_entry_state == 0 && ch == '$') {/* connection from KGDB */
198 kgdb_entry_state = 1;
199 } else if (kgdb_entry_state == 1 && ch == 'q') {
200 kgdb_entry_state = 0;
201 kgdb_breakkey_pressed(regs);
202 return;
203 } else if (ch == 0x3) {/* Ctrl + C */
204 kgdb_entry_state = 0;
205 kgdb_breakkey_pressed(regs);
206 return; 174 return;
207 } else {
208 kgdb_entry_state = 0;
209 } 175 }
210 } 176
177 if (!uart->port.info || !uart->port.info->tty)
178 return;
211#endif 179#endif
180 tty = uart->port.info->tty;
212 181
213 if (ANOMALY_05000363) { 182 if (ANOMALY_05000363) {
214 /* The BF533 (and BF561) family of processors have a nice anomaly 183 /* The BF533 (and BF561) family of processors have a nice anomaly
@@ -250,6 +219,7 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
250 return; 219 return;
251 220
252 known_good_char: 221 known_good_char:
222 status &= ~BI;
253 anomaly_start.tv_sec = 0; 223 anomaly_start.tv_sec = 0;
254 } 224 }
255 } 225 }
@@ -445,7 +415,9 @@ static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart)
445 415
446void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart) 416void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart)
447{ 417{
448 int x_pos, pos; 418 int x_pos, pos, flags;
419
420 spin_lock_irqsave(&uart->port.lock, flags);
449 421
450 uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel); 422 uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel);
451 x_pos = get_dma_curr_xcount(uart->rx_dma_channel); 423 x_pos = get_dma_curr_xcount(uart->rx_dma_channel);
@@ -463,6 +435,8 @@ void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart)
463 uart->rx_dma_buf.tail = uart->rx_dma_buf.head; 435 uart->rx_dma_buf.tail = uart->rx_dma_buf.head;
464 } 436 }
465 437
438 spin_unlock_irqrestore(&uart->port.lock, flags);
439
466 mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES); 440 mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES);
467} 441}
468 442
@@ -497,10 +471,9 @@ static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id)
497 spin_lock(&uart->port.lock); 471 spin_lock(&uart->port.lock);
498 irqstat = get_dma_curr_irqstat(uart->rx_dma_channel); 472 irqstat = get_dma_curr_irqstat(uart->rx_dma_channel);
499 clear_dma_irqstat(uart->rx_dma_channel); 473 clear_dma_irqstat(uart->rx_dma_channel);
474 bfin_serial_dma_rx_chars(uart);
500 spin_unlock(&uart->port.lock); 475 spin_unlock(&uart->port.lock);
501 476
502 mod_timer(&(uart->rx_dma_timer), jiffies);
503
504 return IRQ_HANDLED; 477 return IRQ_HANDLED;
505} 478}
506#endif 479#endif
@@ -630,16 +603,16 @@ static int bfin_serial_startup(struct uart_port *port)
630 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES; 603 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES;
631 add_timer(&(uart->rx_dma_timer)); 604 add_timer(&(uart->rx_dma_timer));
632#else 605#else
606#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
607 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
608 if (kgdboc_port_line == uart->port.line && kgdboc_break_enabled)
609 kgdboc_break_enabled = 0;
610 else {
611# endif
633 if (request_irq(uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED, 612 if (request_irq(uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED,
634 "BFIN_UART_RX", uart)) { 613 "BFIN_UART_RX", uart)) {
635# ifdef CONFIG_KGDB_UART
636 if (uart->port.line != CONFIG_KGDB_UART_PORT) {
637# endif
638 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n"); 614 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n");
639 return -EBUSY; 615 return -EBUSY;
640# ifdef CONFIG_KGDB_UART
641 }
642# endif
643 } 616 }
644 617
645 if (request_irq 618 if (request_irq
@@ -685,6 +658,10 @@ static int bfin_serial_startup(struct uart_port *port)
685 } 658 }
686 } 659 }
687# endif 660# endif
661#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
662 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
663 }
664# endif
688#endif 665#endif
689 UART_SET_IER(uart, ERBFI); 666 UART_SET_IER(uart, ERBFI);
690 return 0; 667 return 0;
@@ -716,9 +693,6 @@ static void bfin_serial_shutdown(struct uart_port *port)
716 break; 693 break;
717 }; 694 };
718#endif 695#endif
719#ifdef CONFIG_KGDB_UART
720 if (uart->port.line != CONFIG_KGDB_UART_PORT)
721#endif
722 free_irq(uart->port.irq, uart); 696 free_irq(uart->port.irq, uart);
723 free_irq(uart->port.irq+1, uart); 697 free_irq(uart->port.irq+1, uart);
724#endif 698#endif
@@ -887,6 +861,65 @@ static void bfin_serial_set_ldisc(struct uart_port *port)
887 } 861 }
888} 862}
889 863
864#ifdef CONFIG_CONSOLE_POLL
865static void bfin_serial_poll_put_char(struct uart_port *port, unsigned char chr)
866{
867 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
868
869 while (!(UART_GET_LSR(uart) & THRE))
870 cpu_relax();
871
872 UART_CLEAR_DLAB(uart);
873 UART_PUT_CHAR(uart, (unsigned char)chr);
874}
875
876static int bfin_serial_poll_get_char(struct uart_port *port)
877{
878 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
879 unsigned char chr;
880
881 while (!(UART_GET_LSR(uart) & DR))
882 cpu_relax();
883
884 UART_CLEAR_DLAB(uart);
885 chr = UART_GET_CHAR(uart);
886
887 return chr;
888}
889#endif
890
891#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
892 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
893static void bfin_kgdboc_port_shutdown(struct uart_port *port)
894{
895 if (kgdboc_break_enabled) {
896 kgdboc_break_enabled = 0;
897 bfin_serial_shutdown(port);
898 }
899}
900
901static int bfin_kgdboc_port_startup(struct uart_port *port)
902{
903 kgdboc_port_line = port->line;
904 kgdboc_break_enabled = !bfin_serial_startup(port);
905 return 0;
906}
907#endif
908
909static void bfin_serial_reset_irda(struct uart_port *port)
910{
911 int line = port->line;
912 unsigned short val;
913
914 val = UART_GET_GCTL(&bfin_serial_ports[line]);
915 val &= ~(IREN | RPOLC);
916 UART_PUT_GCTL(&bfin_serial_ports[line], val);
917 SSYNC();
918 val |= (IREN | RPOLC);
919 UART_PUT_GCTL(&bfin_serial_ports[line], val);
920 SSYNC();
921}
922
890static struct uart_ops bfin_serial_pops = { 923static struct uart_ops bfin_serial_pops = {
891 .tx_empty = bfin_serial_tx_empty, 924 .tx_empty = bfin_serial_tx_empty,
892 .set_mctrl = bfin_serial_set_mctrl, 925 .set_mctrl = bfin_serial_set_mctrl,
@@ -905,6 +938,15 @@ static struct uart_ops bfin_serial_pops = {
905 .request_port = bfin_serial_request_port, 938 .request_port = bfin_serial_request_port,
906 .config_port = bfin_serial_config_port, 939 .config_port = bfin_serial_config_port,
907 .verify_port = bfin_serial_verify_port, 940 .verify_port = bfin_serial_verify_port,
941#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
942 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
943 .kgdboc_port_startup = bfin_kgdboc_port_startup,
944 .kgdboc_port_shutdown = bfin_kgdboc_port_shutdown,
945#endif
946#ifdef CONFIG_CONSOLE_POLL
947 .poll_put_char = bfin_serial_poll_put_char,
948 .poll_get_char = bfin_serial_poll_get_char,
949#endif
908}; 950};
909 951
910static void __init bfin_serial_init_ports(void) 952static void __init bfin_serial_init_ports(void)
@@ -950,7 +992,7 @@ static void __init bfin_serial_init_ports(void)
950 992
951} 993}
952 994
953#ifdef CONFIG_SERIAL_BFIN_CONSOLE 995#if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
954/* 996/*
955 * If the port was already initialised (eg, by a boot loader), 997 * If the port was already initialised (eg, by a boot loader),
956 * try to determine the current setup. 998 * try to determine the current setup.
@@ -994,24 +1036,20 @@ bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud,
994 } 1036 }
995 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__, *baud, *parity, *bits); 1037 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__, *baud, *parity, *bits);
996} 1038}
997#endif
998 1039
999#if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
1000static struct uart_driver bfin_serial_reg; 1040static struct uart_driver bfin_serial_reg;
1001 1041
1002static int __init 1042static int __init
1003bfin_serial_console_setup(struct console *co, char *options) 1043bfin_serial_console_setup(struct console *co, char *options)
1004{ 1044{
1005 struct bfin_serial_port *uart; 1045 struct bfin_serial_port *uart;
1006# ifdef CONFIG_SERIAL_BFIN_CONSOLE
1007 int baud = 57600; 1046 int baud = 57600;
1008 int bits = 8; 1047 int bits = 8;
1009 int parity = 'n'; 1048 int parity = 'n';
1010# ifdef CONFIG_SERIAL_BFIN_CTSRTS 1049# ifdef CONFIG_SERIAL_BFIN_CTSRTS
1011 int flow = 'r'; 1050 int flow = 'r';
1012# else 1051# else
1013 int flow = 'n'; 1052 int flow = 'n';
1014# endif
1015# endif 1053# endif
1016 1054
1017 /* 1055 /*
@@ -1023,16 +1061,12 @@ bfin_serial_console_setup(struct console *co, char *options)
1023 co->index = 0; 1061 co->index = 0;
1024 uart = &bfin_serial_ports[co->index]; 1062 uart = &bfin_serial_ports[co->index];
1025 1063
1026# ifdef CONFIG_SERIAL_BFIN_CONSOLE
1027 if (options) 1064 if (options)
1028 uart_parse_options(options, &baud, &parity, &bits, &flow); 1065 uart_parse_options(options, &baud, &parity, &bits, &flow);
1029 else 1066 else
1030 bfin_serial_console_get_options(uart, &baud, &parity, &bits); 1067 bfin_serial_console_get_options(uart, &baud, &parity, &bits);
1031 1068
1032 return uart_set_options(&uart->port, co, baud, parity, bits, flow); 1069 return uart_set_options(&uart->port, co, baud, parity, bits, flow);
1033# else
1034 return 0;
1035# endif
1036} 1070}
1037#endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) || 1071#endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) ||
1038 defined (CONFIG_EARLY_PRINTK) */ 1072 defined (CONFIG_EARLY_PRINTK) */
@@ -1076,10 +1110,7 @@ static int __init bfin_serial_rs_console_init(void)
1076{ 1110{
1077 bfin_serial_init_ports(); 1111 bfin_serial_init_ports();
1078 register_console(&bfin_serial_console); 1112 register_console(&bfin_serial_console);
1079#ifdef CONFIG_KGDB_UART 1113
1080 kgdb_entry_state = 0;
1081 init_kgdb_uart();
1082#endif
1083 return 0; 1114 return 0;
1084} 1115}
1085console_initcall(bfin_serial_rs_console_init); 1116console_initcall(bfin_serial_rs_console_init);
@@ -1144,7 +1175,7 @@ struct console __init *bfin_earlyserial_init(unsigned int port,
1144 return &bfin_early_serial_console; 1175 return &bfin_early_serial_console;
1145} 1176}
1146 1177
1147#endif /* CONFIG_SERIAL_BFIN_CONSOLE */ 1178#endif /* CONFIG_EARLY_PRINTK */
1148 1179
1149static struct uart_driver bfin_serial_reg = { 1180static struct uart_driver bfin_serial_reg = {
1150 .owner = THIS_MODULE, 1181 .owner = THIS_MODULE,
@@ -1235,10 +1266,6 @@ static struct platform_driver bfin_serial_driver = {
1235static int __init bfin_serial_init(void) 1266static int __init bfin_serial_init(void)
1236{ 1267{
1237 int ret; 1268 int ret;
1238#ifdef CONFIG_KGDB_UART
1239 struct bfin_serial_port *uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
1240 struct ktermios t;
1241#endif
1242 1269
1243 pr_info("Serial: Blackfin serial driver\n"); 1270 pr_info("Serial: Blackfin serial driver\n");
1244 1271
@@ -1252,21 +1279,6 @@ static int __init bfin_serial_init(void)
1252 uart_unregister_driver(&bfin_serial_reg); 1279 uart_unregister_driver(&bfin_serial_reg);
1253 } 1280 }
1254 } 1281 }
1255#ifdef CONFIG_KGDB_UART
1256 if (uart->port.cons->index != CONFIG_KGDB_UART_PORT) {
1257 request_irq(uart->port.irq, bfin_serial_rx_int,
1258 IRQF_DISABLED, "BFIN_UART_RX", uart);
1259 pr_info("Request irq for kgdb uart port\n");
1260 UART_SET_IER(uart, ERBFI);
1261 SSYNC();
1262 t.c_cflag = CS8|B57600;
1263 t.c_iflag = 0;
1264 t.c_oflag = 0;
1265 t.c_lflag = ICANON;
1266 t.c_line = CONFIG_KGDB_UART_PORT;
1267 bfin_serial_set_termios(&uart->port, &t, &t);
1268 }
1269#endif
1270 return ret; 1282 return ret;
1271} 1283}
1272 1284
@@ -1276,6 +1288,7 @@ static void __exit bfin_serial_exit(void)
1276 uart_unregister_driver(&bfin_serial_reg); 1288 uart_unregister_driver(&bfin_serial_reg);
1277} 1289}
1278 1290
1291
1279module_init(bfin_serial_init); 1292module_init(bfin_serial_init);
1280module_exit(bfin_serial_exit); 1293module_exit(bfin_serial_exit);
1281 1294