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.c182
1 files changed, 179 insertions, 3 deletions
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 22569bd5d821..66c92bc36f3d 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -41,6 +41,11 @@
41#include <linux/tty_flip.h> 41#include <linux/tty_flip.h>
42#include <linux/serial_core.h> 42#include <linux/serial_core.h>
43 43
44#ifdef CONFIG_KGDB_UART
45#include <linux/kgdb.h>
46#include <asm/irq_regs.h>
47#endif
48
44#include <asm/gpio.h> 49#include <asm/gpio.h>
45#include <asm/mach/bfin_serial_5xx.h> 50#include <asm/mach/bfin_serial_5xx.h>
46 51
@@ -81,15 +86,29 @@ static void bfin_serial_stop_tx(struct uart_port *port)
81{ 86{
82 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 87 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
83 88
89#ifdef CONFIG_BF54x
90 while (!(UART_GET_LSR(uart) & TEMT))
91 continue;
92#endif
93
84#ifdef CONFIG_SERIAL_BFIN_DMA 94#ifdef CONFIG_SERIAL_BFIN_DMA
85 disable_dma(uart->tx_dma_channel); 95 disable_dma(uart->tx_dma_channel);
86#else 96#else
97#ifdef CONFIG_BF54x
98 /* Waiting for Transmission Finished */
99 while (!(UART_GET_LSR(uart) & TFI))
100 continue;
101 /* Clear TFI bit */
102 UART_PUT_LSR(uart, TFI);
103 UART_CLEAR_IER(uart, ETBEI);
104#else
87 unsigned short ier; 105 unsigned short ier;
88 106
89 ier = UART_GET_IER(uart); 107 ier = UART_GET_IER(uart);
90 ier &= ~ETBEI; 108 ier &= ~ETBEI;
91 UART_PUT_IER(uart, ier); 109 UART_PUT_IER(uart, ier);
92#endif 110#endif
111#endif
93} 112}
94 113
95/* 114/*
@@ -102,12 +121,16 @@ static void bfin_serial_start_tx(struct uart_port *port)
102#ifdef CONFIG_SERIAL_BFIN_DMA 121#ifdef CONFIG_SERIAL_BFIN_DMA
103 bfin_serial_dma_tx_chars(uart); 122 bfin_serial_dma_tx_chars(uart);
104#else 123#else
124#ifdef CONFIG_BF54x
125 UART_SET_IER(uart, ETBEI);
126#else
105 unsigned short ier; 127 unsigned short ier;
106 ier = UART_GET_IER(uart); 128 ier = UART_GET_IER(uart);
107 ier |= ETBEI; 129 ier |= ETBEI;
108 UART_PUT_IER(uart, ier); 130 UART_PUT_IER(uart, ier);
109 bfin_serial_tx_chars(uart); 131 bfin_serial_tx_chars(uart);
110#endif 132#endif
133#endif
111} 134}
112 135
113/* 136/*
@@ -116,11 +139,18 @@ static void bfin_serial_start_tx(struct uart_port *port)
116static void bfin_serial_stop_rx(struct uart_port *port) 139static void bfin_serial_stop_rx(struct uart_port *port)
117{ 140{
118 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 141 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
142#ifdef CONFIG_BF54x
143 UART_CLEAR_IER(uart, ERBFI);
144#else
119 unsigned short ier; 145 unsigned short ier;
120 146
121 ier = UART_GET_IER(uart); 147 ier = UART_GET_IER(uart);
148#ifdef CONFIG_KGDB_UART
149 if (uart->port.line != CONFIG_KGDB_UART_PORT)
150#endif
122 ier &= ~ERBFI; 151 ier &= ~ERBFI;
123 UART_PUT_IER(uart, ier); 152 UART_PUT_IER(uart, ier);
153#endif
124} 154}
125 155
126/* 156/*
@@ -130,6 +160,49 @@ static void bfin_serial_enable_ms(struct uart_port *port)
130{ 160{
131} 161}
132 162
163#ifdef CONFIG_KGDB_UART
164static int kgdb_entry_state;
165
166void kgdb_put_debug_char(int chr)
167{
168 struct bfin_serial_port *uart;
169
170 if (CONFIG_KGDB_UART_PORT<0 || CONFIG_KGDB_UART_PORT>=NR_PORTS)
171 uart = &bfin_serial_ports[0];
172 else
173 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
174
175 while (!(UART_GET_LSR(uart) & THRE)) {
176 __builtin_bfin_ssync();
177 }
178 UART_PUT_LCR(uart, UART_GET_LCR(uart)&(~DLAB));
179 __builtin_bfin_ssync();
180 UART_PUT_CHAR(uart, (unsigned char)chr);
181 __builtin_bfin_ssync();
182}
183
184int kgdb_get_debug_char(void)
185{
186 struct bfin_serial_port *uart;
187 unsigned char chr;
188
189 if (CONFIG_KGDB_UART_PORT<0 || CONFIG_KGDB_UART_PORT>=NR_PORTS)
190 uart = &bfin_serial_ports[0];
191 else
192 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
193
194 while(!(UART_GET_LSR(uart) & DR)) {
195 __builtin_bfin_ssync();
196 }
197 UART_PUT_LCR(uart, UART_GET_LCR(uart)&(~DLAB));
198 __builtin_bfin_ssync();
199 chr = UART_GET_CHAR(uart);
200 __builtin_bfin_ssync();
201
202 return chr;
203}
204#endif
205
133#ifdef CONFIG_SERIAL_BFIN_PIO 206#ifdef CONFIG_SERIAL_BFIN_PIO
134static void local_put_char(struct bfin_serial_port *uart, char ch) 207static void local_put_char(struct bfin_serial_port *uart, char ch)
135{ 208{
@@ -152,6 +225,9 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
152{ 225{
153 struct tty_struct *tty = uart->port.info->tty; 226 struct tty_struct *tty = uart->port.info->tty;
154 unsigned int status, ch, flg; 227 unsigned int status, ch, flg;
228#ifdef CONFIG_KGDB_UART
229 struct pt_regs *regs = get_irq_regs();
230#endif
155#ifdef BF533_FAMILY 231#ifdef BF533_FAMILY
156 static int in_break = 0; 232 static int in_break = 0;
157#endif 233#endif
@@ -160,6 +236,27 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
160 ch = UART_GET_CHAR(uart); 236 ch = UART_GET_CHAR(uart);
161 uart->port.icount.rx++; 237 uart->port.icount.rx++;
162 238
239#ifdef CONFIG_KGDB_UART
240 if (uart->port.line == CONFIG_KGDB_UART_PORT) {
241 if (uart->port.cons->index == CONFIG_KGDB_UART_PORT && ch == 0x1) { /* Ctrl + A */
242 kgdb_breakkey_pressed(regs);
243 return;
244 } else if (kgdb_entry_state == 0 && ch == '$') {/* connection from KGDB */
245 kgdb_entry_state = 1;
246 } else if (kgdb_entry_state == 1 && ch == 'q') {
247 kgdb_entry_state = 0;
248 kgdb_breakkey_pressed(regs);
249 return;
250 } else if (ch == 0x3) {/* Ctrl + C */
251 kgdb_entry_state = 0;
252 kgdb_breakkey_pressed(regs);
253 return;
254 } else {
255 kgdb_entry_state = 0;
256 }
257 }
258#endif
259
163#ifdef BF533_FAMILY 260#ifdef BF533_FAMILY
164 /* The BF533 family of processors have a nice misbehavior where 261 /* The BF533 family of processors have a nice misbehavior where
165 * they continuously generate characters for a "single" break. 262 * they continuously generate characters for a "single" break.
@@ -250,10 +347,21 @@ static irqreturn_t bfin_serial_rx_int(int irq, void *dev_id)
250{ 347{
251 struct bfin_serial_port *uart = dev_id; 348 struct bfin_serial_port *uart = dev_id;
252 349
350#ifdef CONFIG_BF54x
351 unsigned short status;
352 spin_lock(&uart->port.lock);
353 status = UART_GET_LSR(uart);
354 while ((UART_GET_IER(uart) & ERBFI) && (status & DR)) {
355 bfin_serial_rx_chars(uart);
356 status = UART_GET_LSR(uart);
357 }
358 spin_unlock(&uart->port.lock);
359#else
253 spin_lock(&uart->port.lock); 360 spin_lock(&uart->port.lock);
254 while ((UART_GET_IIR(uart) & IIR_STATUS) == IIR_RX_READY) 361 while ((UART_GET_IIR(uart) & IIR_STATUS) == IIR_RX_READY)
255 bfin_serial_rx_chars(uart); 362 bfin_serial_rx_chars(uart);
256 spin_unlock(&uart->port.lock); 363 spin_unlock(&uart->port.lock);
364#endif
257 return IRQ_HANDLED; 365 return IRQ_HANDLED;
258} 366}
259 367
@@ -261,10 +369,21 @@ static irqreturn_t bfin_serial_tx_int(int irq, void *dev_id)
261{ 369{
262 struct bfin_serial_port *uart = dev_id; 370 struct bfin_serial_port *uart = dev_id;
263 371
372#ifdef CONFIG_BF54x
373 unsigned short status;
374 spin_lock(&uart->port.lock);
375 status = UART_GET_LSR(uart);
376 while ((UART_GET_IER(uart) & ETBEI) && (status & THRE)) {
377 bfin_serial_tx_chars(uart);
378 status = UART_GET_LSR(uart);
379 }
380 spin_unlock(&uart->port.lock);
381#else
264 spin_lock(&uart->port.lock); 382 spin_lock(&uart->port.lock);
265 while ((UART_GET_IIR(uart) & IIR_STATUS) == IIR_TX_READY) 383 while ((UART_GET_IIR(uart) & IIR_STATUS) == IIR_TX_READY)
266 bfin_serial_tx_chars(uart); 384 bfin_serial_tx_chars(uart);
267 spin_unlock(&uart->port.lock); 385 spin_unlock(&uart->port.lock);
386#endif
268 return IRQ_HANDLED; 387 return IRQ_HANDLED;
269} 388}
270 389
@@ -275,7 +394,6 @@ static void bfin_serial_do_work(struct work_struct *work)
275 394
276 bfin_serial_mctrl_check(uart); 395 bfin_serial_mctrl_check(uart);
277} 396}
278
279#endif 397#endif
280 398
281#ifdef CONFIG_SERIAL_BFIN_DMA 399#ifdef CONFIG_SERIAL_BFIN_DMA
@@ -324,9 +442,13 @@ static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart)
324 set_dma_x_count(uart->tx_dma_channel, uart->tx_count); 442 set_dma_x_count(uart->tx_dma_channel, uart->tx_count);
325 set_dma_x_modify(uart->tx_dma_channel, 1); 443 set_dma_x_modify(uart->tx_dma_channel, 1);
326 enable_dma(uart->tx_dma_channel); 444 enable_dma(uart->tx_dma_channel);
445#ifdef CONFIG_BF54x
446 UART_SET_IER(uart, ETBEI);
447#else
327 ier = UART_GET_IER(uart); 448 ier = UART_GET_IER(uart);
328 ier |= ETBEI; 449 ier |= ETBEI;
329 UART_PUT_IER(uart, ier); 450 UART_PUT_IER(uart, ier);
451#endif
330 spin_unlock_irqrestore(&uart->port.lock, flags); 452 spin_unlock_irqrestore(&uart->port.lock, flags);
331} 453}
332 454
@@ -406,9 +528,13 @@ static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id)
406 if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) { 528 if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) {
407 clear_dma_irqstat(uart->tx_dma_channel); 529 clear_dma_irqstat(uart->tx_dma_channel);
408 disable_dma(uart->tx_dma_channel); 530 disable_dma(uart->tx_dma_channel);
531#ifdef CONFIG_BF54x
532 UART_CLEAR_IER(uart, ETBEI);
533#else
409 ier = UART_GET_IER(uart); 534 ier = UART_GET_IER(uart);
410 ier &= ~ETBEI; 535 ier &= ~ETBEI;
411 UART_PUT_IER(uart, ier); 536 UART_PUT_IER(uart, ier);
537#endif
412 xmit->tail = (xmit->tail+uart->tx_count) &(UART_XMIT_SIZE -1); 538 xmit->tail = (xmit->tail+uart->tx_count) &(UART_XMIT_SIZE -1);
413 uart->port.icount.tx+=uart->tx_count; 539 uart->port.icount.tx+=uart->tx_count;
414 540
@@ -571,7 +697,11 @@ static int bfin_serial_startup(struct uart_port *port)
571 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES; 697 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES;
572 add_timer(&(uart->rx_dma_timer)); 698 add_timer(&(uart->rx_dma_timer));
573#else 699#else
700# ifdef CONFIG_KGDB_UART
701 if (uart->port.line != CONFIG_KGDB_UART_PORT && request_irq
702# else
574 if (request_irq 703 if (request_irq
704# endif
575 (uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED, 705 (uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED,
576 "BFIN_UART_RX", uart)) { 706 "BFIN_UART_RX", uart)) {
577 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n"); 707 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n");
@@ -586,7 +716,11 @@ static int bfin_serial_startup(struct uart_port *port)
586 return -EBUSY; 716 return -EBUSY;
587 } 717 }
588#endif 718#endif
719#ifdef CONFIG_BF54x
720 UART_SET_IER(uart, ERBFI);
721#else
589 UART_PUT_IER(uart, UART_GET_IER(uart) | ERBFI); 722 UART_PUT_IER(uart, UART_GET_IER(uart) | ERBFI);
723#endif
590 return 0; 724 return 0;
591} 725}
592 726
@@ -601,6 +735,9 @@ static void bfin_serial_shutdown(struct uart_port *port)
601 free_dma(uart->rx_dma_channel); 735 free_dma(uart->rx_dma_channel);
602 del_timer(&(uart->rx_dma_timer)); 736 del_timer(&(uart->rx_dma_timer));
603#else 737#else
738#ifdef CONFIG_KGDB_UART
739 if (uart->port.line != CONFIG_KGDB_UART_PORT)
740#endif
604 free_irq(uart->port.irq, uart); 741 free_irq(uart->port.irq, uart);
605 free_irq(uart->port.irq+1, uart); 742 free_irq(uart->port.irq+1, uart);
606#endif 743#endif
@@ -674,29 +811,41 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
674 811
675 /* Disable UART */ 812 /* Disable UART */
676 ier = UART_GET_IER(uart); 813 ier = UART_GET_IER(uart);
814#ifdef CONFIG_BF54x
815 UART_CLEAR_IER(uart, 0xF);
816#else
677 UART_PUT_IER(uart, 0); 817 UART_PUT_IER(uart, 0);
818#endif
678 819
820#ifndef CONFIG_BF54x
679 /* Set DLAB in LCR to Access DLL and DLH */ 821 /* Set DLAB in LCR to Access DLL and DLH */
680 val = UART_GET_LCR(uart); 822 val = UART_GET_LCR(uart);
681 val |= DLAB; 823 val |= DLAB;
682 UART_PUT_LCR(uart, val); 824 UART_PUT_LCR(uart, val);
683 SSYNC(); 825 SSYNC();
826#endif
684 827
685 UART_PUT_DLL(uart, quot & 0xFF); 828 UART_PUT_DLL(uart, quot & 0xFF);
686 SSYNC(); 829 SSYNC();
687 UART_PUT_DLH(uart, (quot >> 8) & 0xFF); 830 UART_PUT_DLH(uart, (quot >> 8) & 0xFF);
688 SSYNC(); 831 SSYNC();
689 832
833#ifndef CONFIG_BF54x
690 /* Clear DLAB in LCR to Access THR RBR IER */ 834 /* Clear DLAB in LCR to Access THR RBR IER */
691 val = UART_GET_LCR(uart); 835 val = UART_GET_LCR(uart);
692 val &= ~DLAB; 836 val &= ~DLAB;
693 UART_PUT_LCR(uart, val); 837 UART_PUT_LCR(uart, val);
694 SSYNC(); 838 SSYNC();
839#endif
695 840
696 UART_PUT_LCR(uart, lcr); 841 UART_PUT_LCR(uart, lcr);
697 842
698 /* Enable UART */ 843 /* Enable UART */
844#ifdef CONFIG_BF54x
845 UART_SET_IER(uart, ier);
846#else
699 UART_PUT_IER(uart, ier); 847 UART_PUT_IER(uart, ier);
848#endif
700 849
701 val = UART_GET_GCTL(uart); 850 val = UART_GET_GCTL(uart);
702 val |= UCEN; 851 val |= UCEN;
@@ -808,15 +957,15 @@ static void __init bfin_serial_init_ports(void)
808 bfin_serial_resource[i].uart_rts_pin; 957 bfin_serial_resource[i].uart_rts_pin;
809#endif 958#endif
810 bfin_serial_hw_init(&bfin_serial_ports[i]); 959 bfin_serial_hw_init(&bfin_serial_ports[i]);
811
812 } 960 }
961
813} 962}
814 963
815#ifdef CONFIG_SERIAL_BFIN_CONSOLE 964#ifdef CONFIG_SERIAL_BFIN_CONSOLE
816static void bfin_serial_console_putchar(struct uart_port *port, int ch) 965static void bfin_serial_console_putchar(struct uart_port *port, int ch)
817{ 966{
818 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 967 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
819 while (!(UART_GET_LSR(uart))) 968 while (!(UART_GET_LSR(uart) & THRE))
820 barrier(); 969 barrier();
821 UART_PUT_CHAR(uart, ch); 970 UART_PUT_CHAR(uart, ch);
822 SSYNC(); 971 SSYNC();
@@ -868,18 +1017,22 @@ bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud,
868 case 2: *bits = 7; break; 1017 case 2: *bits = 7; break;
869 case 3: *bits = 8; break; 1018 case 3: *bits = 8; break;
870 } 1019 }
1020#ifndef CONFIG_BF54x
871 /* Set DLAB in LCR to Access DLL and DLH */ 1021 /* Set DLAB in LCR to Access DLL and DLH */
872 val = UART_GET_LCR(uart); 1022 val = UART_GET_LCR(uart);
873 val |= DLAB; 1023 val |= DLAB;
874 UART_PUT_LCR(uart, val); 1024 UART_PUT_LCR(uart, val);
1025#endif
875 1026
876 dll = UART_GET_DLL(uart); 1027 dll = UART_GET_DLL(uart);
877 dlh = UART_GET_DLH(uart); 1028 dlh = UART_GET_DLH(uart);
878 1029
1030#ifndef CONFIG_BF54x
879 /* Clear DLAB in LCR to Access THR RBR IER */ 1031 /* Clear DLAB in LCR to Access THR RBR IER */
880 val = UART_GET_LCR(uart); 1032 val = UART_GET_LCR(uart);
881 val &= ~DLAB; 1033 val &= ~DLAB;
882 UART_PUT_LCR(uart, val); 1034 UART_PUT_LCR(uart, val);
1035#endif
883 1036
884 *baud = get_sclk() / (16*(dll | dlh << 8)); 1037 *baud = get_sclk() / (16*(dll | dlh << 8));
885 } 1038 }
@@ -931,6 +1084,10 @@ static int __init bfin_serial_rs_console_init(void)
931{ 1084{
932 bfin_serial_init_ports(); 1085 bfin_serial_init_ports();
933 register_console(&bfin_serial_console); 1086 register_console(&bfin_serial_console);
1087#ifdef CONFIG_KGDB_UART
1088 kgdb_entry_state = 0;
1089 init_kgdb_uart();
1090#endif
934 return 0; 1091 return 0;
935} 1092}
936console_initcall(bfin_serial_rs_console_init); 1093console_initcall(bfin_serial_rs_console_init);
@@ -1023,6 +1180,10 @@ static struct platform_driver bfin_serial_driver = {
1023static int __init bfin_serial_init(void) 1180static int __init bfin_serial_init(void)
1024{ 1181{
1025 int ret; 1182 int ret;
1183#ifdef CONFIG_KGDB_UART
1184 struct bfin_serial_port *uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
1185 struct termios t;
1186#endif
1026 1187
1027 pr_info("Serial: Blackfin serial driver\n"); 1188 pr_info("Serial: Blackfin serial driver\n");
1028 1189
@@ -1036,6 +1197,21 @@ static int __init bfin_serial_init(void)
1036 uart_unregister_driver(&bfin_serial_reg); 1197 uart_unregister_driver(&bfin_serial_reg);
1037 } 1198 }
1038 } 1199 }
1200#ifdef CONFIG_KGDB_UART
1201 if (uart->port.cons->index != CONFIG_KGDB_UART_PORT) {
1202 request_irq(uart->port.irq, bfin_serial_int,
1203 IRQF_DISABLED, "BFIN_UART_RX", uart);
1204 pr_info("Request irq for kgdb uart port\n");
1205 UART_PUT_IER(uart, UART_GET_IER(uart) | ERBFI);
1206 __builtin_bfin_ssync();
1207 t.c_cflag = CS8|B57600;
1208 t.c_iflag = 0;
1209 t.c_oflag = 0;
1210 t.c_lflag = ICANON;
1211 t.c_line = CONFIG_KGDB_UART_PORT;
1212 bfin_serial_set_termios(&uart->port, &t, &t);
1213 }
1214#endif
1039 return ret; 1215 return ret;
1040} 1216}
1041 1217