1 // SPDX-License-Identifier: GPL-2.0+
3 * Blackfin On-Chip Serial Driver
5 * Copyright 2006-2011 Analog Devices Inc.
7 * Enter bugs at http://blackfin.uclinux.org/
10 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
14 #define DRIVER_NAME "bfin-uart"
15 #define pr_fmt(fmt) DRIVER_NAME ": " fmt
17 #include <linux/module.h>
18 #include <linux/ioport.h>
19 #include <linux/gfp.h>
21 #include <linux/init.h>
22 #include <linux/console.h>
23 #include <linux/sysrq.h>
24 #include <linux/platform_device.h>
25 #include <linux/tty.h>
26 #include <linux/tty_flip.h>
27 #include <linux/serial_core.h>
28 #include <linux/gpio.h>
29 #include <linux/irq.h>
30 #include <linux/kgdb.h>
31 #include <linux/slab.h>
32 #include <linux/dma-mapping.h>
34 #include <asm/portmux.h>
35 #include <asm/cacheflush.h>
37 #include <asm/bfin_serial.h>
39 #ifdef CONFIG_SERIAL_BFIN_MODULE
40 # undef CONFIG_EARLY_PRINTK
43 /* UART name and device definitions */
44 #define BFIN_SERIAL_DEV_NAME "ttyBF"
45 #define BFIN_SERIAL_MAJOR 204
46 #define BFIN_SERIAL_MINOR 64
48 static struct bfin_serial_port
*bfin_serial_ports
[BFIN_UART_NR_PORTS
];
50 #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
51 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
53 # ifndef CONFIG_SERIAL_BFIN_PIO
54 # error KGDB only support UART in PIO mode.
57 static int kgdboc_port_line
;
58 static int kgdboc_break_enabled
;
61 * Setup for console. Argument comes from the menuconfig
63 #define DMA_RX_XCOUNT 512
64 #define DMA_RX_YCOUNT (PAGE_SIZE / DMA_RX_XCOUNT)
66 #define DMA_RX_FLUSH_JIFFIES (HZ / 50)
68 #ifdef CONFIG_SERIAL_BFIN_DMA
69 static void bfin_serial_dma_tx_chars(struct bfin_serial_port
*uart
);
71 static void bfin_serial_tx_chars(struct bfin_serial_port
*uart
);
74 static void bfin_serial_reset_irda(struct uart_port
*port
);
76 #if defined(SERIAL_BFIN_CTSRTS) || \
77 defined(SERIAL_BFIN_HARD_CTSRTS)
78 static unsigned int bfin_serial_get_mctrl(struct uart_port
*port
)
80 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
81 if (uart
->cts_pin
< 0)
82 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
84 /* CTS PIN is negative assertive. */
85 if (UART_GET_CTS(uart
))
86 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
88 return TIOCM_DSR
| TIOCM_CAR
;
91 static void bfin_serial_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
93 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
94 if (uart
->rts_pin
< 0)
97 /* RTS PIN is negative assertive. */
98 if (mctrl
& TIOCM_RTS
)
99 UART_ENABLE_RTS(uart
);
101 UART_DISABLE_RTS(uart
);
105 * Handle any change of modem status signal.
107 static irqreturn_t
bfin_serial_mctrl_cts_int(int irq
, void *dev_id
)
109 struct bfin_serial_port
*uart
= dev_id
;
110 struct uart_port
*uport
= &uart
->port
;
111 unsigned int status
= bfin_serial_get_mctrl(uport
);
112 #ifdef SERIAL_BFIN_HARD_CTSRTS
114 UART_CLEAR_SCTS(uart
);
115 if (uport
->hw_stopped
) {
117 uport
->hw_stopped
= 0;
118 uart_write_wakeup(uport
);
122 uport
->hw_stopped
= 1;
125 uart_handle_cts_change(uport
, status
& TIOCM_CTS
);
131 static unsigned int bfin_serial_get_mctrl(struct uart_port
*port
)
133 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
136 static void bfin_serial_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
142 * interrupts are disabled on entry
144 static void bfin_serial_stop_tx(struct uart_port
*port
)
146 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
147 #ifdef CONFIG_SERIAL_BFIN_DMA
148 struct circ_buf
*xmit
= &uart
->port
.state
->xmit
;
151 while (!(UART_GET_LSR(uart
) & TEMT
))
154 #ifdef CONFIG_SERIAL_BFIN_DMA
155 disable_dma(uart
->tx_dma_channel
);
156 xmit
->tail
= (xmit
->tail
+ uart
->tx_count
) & (UART_XMIT_SIZE
- 1);
157 uart
->port
.icount
.tx
+= uart
->tx_count
;
161 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
163 UART_PUT_LSR(uart
, TFI
);
165 UART_CLEAR_IER(uart
, ETBEI
);
170 * port is locked and interrupts are disabled
172 static void bfin_serial_start_tx(struct uart_port
*port
)
174 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
175 struct tty_struct
*tty
= uart
->port
.state
->port
.tty
;
178 * To avoid losting RX interrupt, we reset IR function
179 * before sending data.
181 if (tty
->termios
.c_line
== N_IRDA
)
182 bfin_serial_reset_irda(port
);
184 #ifdef CONFIG_SERIAL_BFIN_DMA
186 bfin_serial_dma_tx_chars(uart
);
188 UART_SET_IER(uart
, ETBEI
);
189 bfin_serial_tx_chars(uart
);
194 * Interrupts are enabled
196 static void bfin_serial_stop_rx(struct uart_port
*port
)
198 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
200 UART_CLEAR_IER(uart
, ERBFI
);
203 #if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO)
204 # define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold)
205 # define UART_SET_ANOMALY_THRESHOLD(uart, v) ((uart)->anomaly_threshold = (v))
207 # define UART_GET_ANOMALY_THRESHOLD(uart) 0
208 # define UART_SET_ANOMALY_THRESHOLD(uart, v)
211 #ifdef CONFIG_SERIAL_BFIN_PIO
212 static void bfin_serial_rx_chars(struct bfin_serial_port
*uart
)
214 unsigned int status
, ch
, flg
;
215 static u64 anomaly_start
;
217 status
= UART_GET_LSR(uart
);
218 UART_CLEAR_LSR(uart
);
220 ch
= UART_GET_CHAR(uart
);
221 uart
->port
.icount
.rx
++;
223 #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
224 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
225 if (kgdb_connected
&& kgdboc_port_line
== uart
->port
.line
226 && kgdboc_break_enabled
)
227 if (ch
== 0x3) {/* Ctrl + C */
232 if (!uart
->port
.state
)
235 if (ANOMALY_05000363
) {
236 /* The BF533 (and BF561) family of processors have a nice anomaly
237 * where they continuously generate characters for a "single" break.
238 * We have to basically ignore this flood until the "next" valid
239 * character comes across. Due to the nature of the flood, it is
240 * not possible to reliably catch bytes that are sent too quickly
241 * after this break. So application code talking to the Blackfin
242 * which sends a break signal must allow at least 1.5 character
243 * times after the end of the break for things to stabilize. This
244 * timeout was picked as it must absolutely be larger than 1
245 * character time +/- some percent. So 1.5 sounds good. All other
246 * Blackfin families operate properly. Woo.
248 if (anomaly_start
> 0) {
249 u64 curr
, nsecs
, threshold_ns
;
251 if ((~ch
& (~ch
+ 1)) & 0xff)
252 goto known_good_char
;
254 curr
= ktime_get_ns();
255 nsecs
= curr
- anomaly_start
;
257 goto known_good_char
;
259 threshold_ns
= UART_GET_ANOMALY_THRESHOLD(uart
)
261 if (nsecs
> threshold_ns
)
262 goto known_good_char
;
267 anomaly_start
= curr
;
278 if (ANOMALY_05000363
)
279 if (bfin_revid() < 5)
280 anomaly_start
= ktime_get_ns();
281 uart
->port
.icount
.brk
++;
282 if (uart_handle_break(&uart
->port
))
284 status
&= ~(PE
| FE
);
287 uart
->port
.icount
.parity
++;
289 uart
->port
.icount
.overrun
++;
291 uart
->port
.icount
.frame
++;
293 status
&= uart
->port
.read_status_mask
;
297 else if (status
& PE
)
299 else if (status
& FE
)
304 if (uart_handle_sysrq_char(&uart
->port
, ch
))
307 uart_insert_char(&uart
->port
, status
, OE
, ch
, flg
);
310 tty_flip_buffer_push(&uart
->port
.state
->port
);
313 static void bfin_serial_tx_chars(struct bfin_serial_port
*uart
)
315 struct circ_buf
*xmit
= &uart
->port
.state
->xmit
;
317 if (uart_circ_empty(xmit
) || uart_tx_stopped(&uart
->port
)) {
318 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
320 UART_PUT_LSR(uart
, TFI
);
323 * 05000215 - we always clear ETBEI within last UART TX
324 * interrupt to end a string. It is always set
325 * when start a new tx.
327 UART_CLEAR_IER(uart
, ETBEI
);
331 if (uart
->port
.x_char
) {
332 UART_PUT_CHAR(uart
, uart
->port
.x_char
);
333 uart
->port
.icount
.tx
++;
334 uart
->port
.x_char
= 0;
337 while ((UART_GET_LSR(uart
) & THRE
) && xmit
->tail
!= xmit
->head
) {
338 UART_PUT_CHAR(uart
, xmit
->buf
[xmit
->tail
]);
339 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
340 uart
->port
.icount
.tx
++;
343 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
344 uart_write_wakeup(&uart
->port
);
347 static irqreturn_t
bfin_serial_rx_int(int irq
, void *dev_id
)
349 struct bfin_serial_port
*uart
= dev_id
;
351 while (UART_GET_LSR(uart
) & DR
)
352 bfin_serial_rx_chars(uart
);
357 static irqreturn_t
bfin_serial_tx_int(int irq
, void *dev_id
)
359 struct bfin_serial_port
*uart
= dev_id
;
361 spin_lock(&uart
->port
.lock
);
362 if (UART_GET_LSR(uart
) & THRE
)
363 bfin_serial_tx_chars(uart
);
364 spin_unlock(&uart
->port
.lock
);
370 #ifdef CONFIG_SERIAL_BFIN_DMA
371 static void bfin_serial_dma_tx_chars(struct bfin_serial_port
*uart
)
373 struct circ_buf
*xmit
= &uart
->port
.state
->xmit
;
377 if (uart_circ_empty(xmit
) || uart_tx_stopped(&uart
->port
)) {
383 if (uart
->port
.x_char
) {
384 UART_PUT_CHAR(uart
, uart
->port
.x_char
);
385 uart
->port
.icount
.tx
++;
386 uart
->port
.x_char
= 0;
389 uart
->tx_count
= CIRC_CNT(xmit
->head
, xmit
->tail
, UART_XMIT_SIZE
);
390 if (uart
->tx_count
> (UART_XMIT_SIZE
- xmit
->tail
))
391 uart
->tx_count
= UART_XMIT_SIZE
- xmit
->tail
;
392 blackfin_dcache_flush_range((unsigned long)(xmit
->buf
+xmit
->tail
),
393 (unsigned long)(xmit
->buf
+xmit
->tail
+uart
->tx_count
));
394 set_dma_config(uart
->tx_dma_channel
,
395 set_bfin_dma_config(DIR_READ
, DMA_FLOW_STOP
,
400 set_dma_start_addr(uart
->tx_dma_channel
, (unsigned long)(xmit
->buf
+xmit
->tail
));
401 set_dma_x_count(uart
->tx_dma_channel
, uart
->tx_count
);
402 set_dma_x_modify(uart
->tx_dma_channel
, 1);
404 enable_dma(uart
->tx_dma_channel
);
406 UART_SET_IER(uart
, ETBEI
);
409 static void bfin_serial_dma_rx_chars(struct bfin_serial_port
*uart
)
413 status
= UART_GET_LSR(uart
);
414 UART_CLEAR_LSR(uart
);
416 uart
->port
.icount
.rx
+=
417 CIRC_CNT(uart
->rx_dma_buf
.head
, uart
->rx_dma_buf
.tail
,
421 uart
->port
.icount
.brk
++;
422 if (uart_handle_break(&uart
->port
))
423 goto dma_ignore_char
;
424 status
&= ~(PE
| FE
);
427 uart
->port
.icount
.parity
++;
429 uart
->port
.icount
.overrun
++;
431 uart
->port
.icount
.frame
++;
433 status
&= uart
->port
.read_status_mask
;
437 else if (status
& PE
)
439 else if (status
& FE
)
444 for (i
= uart
->rx_dma_buf
.tail
; ; i
++) {
445 if (i
>= UART_XMIT_SIZE
)
447 if (i
== uart
->rx_dma_buf
.head
)
449 if (!uart_handle_sysrq_char(&uart
->port
, uart
->rx_dma_buf
.buf
[i
]))
450 uart_insert_char(&uart
->port
, status
, OE
,
451 uart
->rx_dma_buf
.buf
[i
], flg
);
455 tty_flip_buffer_push(&uart
->port
.state
->port
);
458 void bfin_serial_rx_dma_timeout(struct timer_list
*t
)
460 struct bfin_serial_port
*uart
= from_timer(uart
, t
, rx_dma_timer
);
464 dma_disable_irq_nosync(uart
->rx_dma_channel
);
465 spin_lock_irqsave(&uart
->rx_lock
, flags
);
467 /* 2D DMA RX buffer ring is used. Because curr_y_count and
468 * curr_x_count can't be read as an atomic operation,
469 * curr_y_count should be read before curr_x_count. When
470 * curr_x_count is read, curr_y_count may already indicate
471 * next buffer line. But, the position calculated here is
472 * still indicate the old line. The wrong position data may
473 * be smaller than current buffer tail, which cause garbages
474 * are received if it is not prohibit.
476 uart
->rx_dma_nrows
= get_dma_curr_ycount(uart
->rx_dma_channel
);
477 x_pos
= get_dma_curr_xcount(uart
->rx_dma_channel
);
478 uart
->rx_dma_nrows
= DMA_RX_YCOUNT
- uart
->rx_dma_nrows
;
479 if (uart
->rx_dma_nrows
== DMA_RX_YCOUNT
|| x_pos
== 0)
480 uart
->rx_dma_nrows
= 0;
481 x_pos
= DMA_RX_XCOUNT
- x_pos
;
482 if (x_pos
== DMA_RX_XCOUNT
)
485 pos
= uart
->rx_dma_nrows
* DMA_RX_XCOUNT
+ x_pos
;
486 /* Ignore receiving data if new position is in the same line of
487 * current buffer tail and small.
489 if (pos
> uart
->rx_dma_buf
.tail
||
490 uart
->rx_dma_nrows
< (uart
->rx_dma_buf
.tail
/DMA_RX_XCOUNT
)) {
491 uart
->rx_dma_buf
.head
= pos
;
492 bfin_serial_dma_rx_chars(uart
);
493 uart
->rx_dma_buf
.tail
= uart
->rx_dma_buf
.head
;
496 spin_unlock_irqrestore(&uart
->rx_lock
, flags
);
497 dma_enable_irq(uart
->rx_dma_channel
);
499 mod_timer(&(uart
->rx_dma_timer
), jiffies
+ DMA_RX_FLUSH_JIFFIES
);
502 static irqreturn_t
bfin_serial_dma_tx_int(int irq
, void *dev_id
)
504 struct bfin_serial_port
*uart
= dev_id
;
505 struct circ_buf
*xmit
= &uart
->port
.state
->xmit
;
507 spin_lock(&uart
->port
.lock
);
508 if (!(get_dma_curr_irqstat(uart
->tx_dma_channel
)&DMA_RUN
)) {
509 disable_dma(uart
->tx_dma_channel
);
510 clear_dma_irqstat(uart
->tx_dma_channel
);
512 * 05000215 - we always clear ETBEI within last UART TX
513 * interrupt to end a string. It is always set
514 * when start a new tx.
516 UART_CLEAR_IER(uart
, ETBEI
);
517 uart
->port
.icount
.tx
+= uart
->tx_count
;
518 if (!(xmit
->tail
== 0 && xmit
->head
== 0)) {
519 xmit
->tail
= (xmit
->tail
+ uart
->tx_count
) & (UART_XMIT_SIZE
- 1);
521 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
522 uart_write_wakeup(&uart
->port
);
525 bfin_serial_dma_tx_chars(uart
);
528 spin_unlock(&uart
->port
.lock
);
532 static irqreturn_t
bfin_serial_dma_rx_int(int irq
, void *dev_id
)
534 struct bfin_serial_port
*uart
= dev_id
;
535 unsigned int irqstat
;
538 spin_lock(&uart
->rx_lock
);
539 irqstat
= get_dma_curr_irqstat(uart
->rx_dma_channel
);
540 clear_dma_irqstat(uart
->rx_dma_channel
);
542 uart
->rx_dma_nrows
= get_dma_curr_ycount(uart
->rx_dma_channel
);
543 x_pos
= get_dma_curr_xcount(uart
->rx_dma_channel
);
544 uart
->rx_dma_nrows
= DMA_RX_YCOUNT
- uart
->rx_dma_nrows
;
545 if (uart
->rx_dma_nrows
== DMA_RX_YCOUNT
|| x_pos
== 0)
546 uart
->rx_dma_nrows
= 0;
548 pos
= uart
->rx_dma_nrows
* DMA_RX_XCOUNT
;
549 if (pos
> uart
->rx_dma_buf
.tail
||
550 uart
->rx_dma_nrows
< (uart
->rx_dma_buf
.tail
/DMA_RX_XCOUNT
)) {
551 uart
->rx_dma_buf
.head
= pos
;
552 bfin_serial_dma_rx_chars(uart
);
553 uart
->rx_dma_buf
.tail
= uart
->rx_dma_buf
.head
;
556 spin_unlock(&uart
->rx_lock
);
563 * Return TIOCSER_TEMT when transmitter is not busy.
565 static unsigned int bfin_serial_tx_empty(struct uart_port
*port
)
567 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
570 lsr
= UART_GET_LSR(uart
);
577 static void bfin_serial_break_ctl(struct uart_port
*port
, int break_state
)
579 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
580 u32 lcr
= UART_GET_LCR(uart
);
585 UART_PUT_LCR(uart
, lcr
);
589 static int bfin_serial_startup(struct uart_port
*port
)
591 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
593 #ifdef CONFIG_SERIAL_BFIN_DMA
594 dma_addr_t dma_handle
;
596 if (request_dma(uart
->rx_dma_channel
, "BFIN_UART_RX") < 0) {
597 printk(KERN_NOTICE
"Unable to attach Blackfin UART RX DMA channel\n");
601 if (request_dma(uart
->tx_dma_channel
, "BFIN_UART_TX") < 0) {
602 printk(KERN_NOTICE
"Unable to attach Blackfin UART TX DMA channel\n");
603 free_dma(uart
->rx_dma_channel
);
607 set_dma_callback(uart
->rx_dma_channel
, bfin_serial_dma_rx_int
, uart
);
608 set_dma_callback(uart
->tx_dma_channel
, bfin_serial_dma_tx_int
, uart
);
610 uart
->rx_dma_buf
.buf
= (unsigned char *)dma_alloc_coherent(NULL
, PAGE_SIZE
, &dma_handle
, GFP_DMA
);
611 uart
->rx_dma_buf
.head
= 0;
612 uart
->rx_dma_buf
.tail
= 0;
613 uart
->rx_dma_nrows
= 0;
615 set_dma_config(uart
->rx_dma_channel
,
616 set_bfin_dma_config(DIR_WRITE
, DMA_FLOW_AUTO
,
617 INTR_ON_ROW
, DIMENSION_2D
,
620 set_dma_x_count(uart
->rx_dma_channel
, DMA_RX_XCOUNT
);
621 set_dma_x_modify(uart
->rx_dma_channel
, 1);
622 set_dma_y_count(uart
->rx_dma_channel
, DMA_RX_YCOUNT
);
623 set_dma_y_modify(uart
->rx_dma_channel
, 1);
624 set_dma_start_addr(uart
->rx_dma_channel
, (unsigned long)uart
->rx_dma_buf
.buf
);
625 enable_dma(uart
->rx_dma_channel
);
627 uart
->rx_dma_timer
.expires
= jiffies
+ DMA_RX_FLUSH_JIFFIES
;
628 add_timer(&(uart
->rx_dma_timer
));
630 # if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
631 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
632 if (kgdboc_port_line
== uart
->port
.line
&& kgdboc_break_enabled
)
633 kgdboc_break_enabled
= 0;
636 if (request_irq(uart
->rx_irq
, bfin_serial_rx_int
, 0,
637 "BFIN_UART_RX", uart
)) {
638 printk(KERN_NOTICE
"Unable to attach BlackFin UART RX interrupt\n");
643 (uart
->tx_irq
, bfin_serial_tx_int
, 0,
644 "BFIN_UART_TX", uart
)) {
645 printk(KERN_NOTICE
"Unable to attach BlackFin UART TX interrupt\n");
646 free_irq(uart
->rx_irq
, uart
);
653 * UART2 and UART3 on BF548 share interrupt PINs and DMA
654 * controllers with SPORT2 and SPORT3. UART rx and tx
655 * interrupts are generated in PIO mode only when configure
656 * their peripheral mapping registers properly, which means
657 * request corresponding DMA channels in PIO mode as well.
659 unsigned uart_dma_ch_rx
, uart_dma_ch_tx
;
661 switch (uart
->rx_irq
) {
663 uart_dma_ch_rx
= CH_UART3_RX
;
664 uart_dma_ch_tx
= CH_UART3_TX
;
667 uart_dma_ch_rx
= CH_UART2_RX
;
668 uart_dma_ch_tx
= CH_UART2_TX
;
671 uart_dma_ch_rx
= uart_dma_ch_tx
= 0;
675 if (uart_dma_ch_rx
&&
676 request_dma(uart_dma_ch_rx
, "BFIN_UART_RX") < 0) {
677 printk(KERN_NOTICE
"Fail to attach UART interrupt\n");
678 free_irq(uart
->rx_irq
, uart
);
679 free_irq(uart
->tx_irq
, uart
);
682 if (uart_dma_ch_tx
&&
683 request_dma(uart_dma_ch_tx
, "BFIN_UART_TX") < 0) {
684 printk(KERN_NOTICE
"Fail to attach UART interrupt\n");
685 free_dma(uart_dma_ch_rx
);
686 free_irq(uart
->rx_irq
, uart
);
687 free_irq(uart
->tx_irq
, uart
);
692 # if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
693 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
698 #ifdef SERIAL_BFIN_CTSRTS
699 if (uart
->cts_pin
>= 0) {
700 if (request_irq(gpio_to_irq(uart
->cts_pin
),
701 bfin_serial_mctrl_cts_int
,
702 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
|
703 0, "BFIN_UART_CTS", uart
)) {
705 pr_info("Unable to attach BlackFin UART CTS interrupt. So, disable it.\n");
708 if (uart
->rts_pin
>= 0) {
709 if (gpio_request(uart
->rts_pin
, DRIVER_NAME
)) {
710 pr_info("fail to request RTS PIN at GPIO_%d\n", uart
->rts_pin
);
713 gpio_direction_output(uart
->rts_pin
, 0);
716 #ifdef SERIAL_BFIN_HARD_CTSRTS
717 if (uart
->cts_pin
>= 0) {
718 if (request_irq(uart
->status_irq
, bfin_serial_mctrl_cts_int
,
719 0, "BFIN_UART_MODEM_STATUS", uart
)) {
721 dev_info(port
->dev
, "Unable to attach BlackFin UART Modem Status interrupt.\n");
724 /* CTS RTS PINs are negative assertive. */
725 UART_PUT_MCR(uart
, UART_GET_MCR(uart
) | ACTS
);
726 UART_SET_IER(uart
, EDSSI
);
730 UART_SET_IER(uart
, ERBFI
);
734 static void bfin_serial_shutdown(struct uart_port
*port
)
736 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
738 #ifdef CONFIG_SERIAL_BFIN_DMA
739 disable_dma(uart
->tx_dma_channel
);
740 free_dma(uart
->tx_dma_channel
);
741 disable_dma(uart
->rx_dma_channel
);
742 free_dma(uart
->rx_dma_channel
);
743 del_timer(&(uart
->rx_dma_timer
));
744 dma_free_coherent(NULL
, PAGE_SIZE
, uart
->rx_dma_buf
.buf
, 0);
747 switch (uart
->port
.irq
) {
749 free_dma(CH_UART3_RX
);
750 free_dma(CH_UART3_TX
);
753 free_dma(CH_UART2_RX
);
754 free_dma(CH_UART2_TX
);
760 free_irq(uart
->rx_irq
, uart
);
761 free_irq(uart
->tx_irq
, uart
);
764 #ifdef SERIAL_BFIN_CTSRTS
765 if (uart
->cts_pin
>= 0)
766 free_irq(gpio_to_irq(uart
->cts_pin
), uart
);
767 if (uart
->rts_pin
>= 0)
768 gpio_free(uart
->rts_pin
);
770 #ifdef SERIAL_BFIN_HARD_CTSRTS
771 if (uart
->cts_pin
>= 0)
772 free_irq(uart
->status_irq
, uart
);
777 bfin_serial_set_termios(struct uart_port
*port
, struct ktermios
*termios
,
778 struct ktermios
*old
)
780 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
782 unsigned int baud
, quot
;
783 unsigned int ier
, lcr
= 0;
784 unsigned long timeout
;
786 #ifdef SERIAL_BFIN_CTSRTS
787 if (old
== NULL
&& uart
->cts_pin
!= -1)
788 termios
->c_cflag
|= CRTSCTS
;
789 else if (uart
->cts_pin
== -1)
790 termios
->c_cflag
&= ~CRTSCTS
;
793 switch (termios
->c_cflag
& CSIZE
) {
807 printk(KERN_ERR
"%s: word length not supported\n",
812 * 05000231 - STOP bit is always set to 1 whatever the user is set.
814 if (termios
->c_cflag
& CSTOPB
) {
815 if (ANOMALY_05000231
)
816 printk(KERN_WARNING
"STOP bits other than 1 is not "
817 "supported in case of anomaly 05000231.\n");
821 if (termios
->c_cflag
& PARENB
)
823 if (!(termios
->c_cflag
& PARODD
))
825 if (termios
->c_cflag
& CMSPAR
)
828 spin_lock_irqsave(&uart
->port
.lock
, flags
);
830 port
->read_status_mask
= OE
;
831 if (termios
->c_iflag
& INPCK
)
832 port
->read_status_mask
|= (FE
| PE
);
833 if (termios
->c_iflag
& (IGNBRK
| BRKINT
| PARMRK
))
834 port
->read_status_mask
|= BI
;
837 * Characters to ignore
839 port
->ignore_status_mask
= 0;
840 if (termios
->c_iflag
& IGNPAR
)
841 port
->ignore_status_mask
|= FE
| PE
;
842 if (termios
->c_iflag
& IGNBRK
) {
843 port
->ignore_status_mask
|= BI
;
845 * If we're ignoring parity and break indicators,
846 * ignore overruns too (for real raw support).
848 if (termios
->c_iflag
& IGNPAR
)
849 port
->ignore_status_mask
|= OE
;
852 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
853 quot
= uart_get_divisor(port
, baud
);
855 /* If discipline is not IRDA, apply ANOMALY_05000230 */
856 if (termios
->c_line
!= N_IRDA
)
857 quot
-= ANOMALY_05000230
;
859 UART_SET_ANOMALY_THRESHOLD(uart
, USEC_PER_SEC
/ baud
* 15);
861 /* Wait till the transfer buffer is empty */
862 timeout
= jiffies
+ msecs_to_jiffies(10);
863 while (UART_GET_GCTL(uart
) & UCEN
&& !(UART_GET_LSR(uart
) & TEMT
))
864 if (time_after(jiffies
, timeout
)) {
865 dev_warn(port
->dev
, "timeout waiting for TX buffer empty\n");
870 ier
= UART_GET_IER(uart
);
871 UART_PUT_GCTL(uart
, UART_GET_GCTL(uart
) & ~UCEN
);
872 UART_DISABLE_INTS(uart
);
874 /* Set DLAB in LCR to Access CLK */
877 UART_PUT_CLK(uart
, quot
);
880 /* Clear DLAB in LCR to Access THR RBR IER */
881 UART_CLEAR_DLAB(uart
);
883 UART_PUT_LCR(uart
, (UART_GET_LCR(uart
) & ~LCR_MASK
) | lcr
);
886 UART_ENABLE_INTS(uart
, ier
);
887 UART_PUT_GCTL(uart
, UART_GET_GCTL(uart
) | UCEN
);
889 /* Port speed changed, update the per-port timeout. */
890 uart_update_timeout(port
, termios
->c_cflag
, baud
);
892 spin_unlock_irqrestore(&uart
->port
.lock
, flags
);
895 static const char *bfin_serial_type(struct uart_port
*port
)
897 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
899 return uart
->port
.type
== PORT_BFIN
? "BFIN-UART" : NULL
;
903 * Release the memory region(s) being used by 'port'.
905 static void bfin_serial_release_port(struct uart_port
*port
)
910 * Request the memory region(s) being used by 'port'.
912 static int bfin_serial_request_port(struct uart_port
*port
)
918 * Configure/autoconfigure the port.
920 static void bfin_serial_config_port(struct uart_port
*port
, int flags
)
922 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
924 if (flags
& UART_CONFIG_TYPE
&&
925 bfin_serial_request_port(&uart
->port
) == 0)
926 uart
->port
.type
= PORT_BFIN
;
930 * Verify the new serial_struct (for TIOCSSERIAL).
931 * The only change we allow are to the flags and type, and
932 * even then only between PORT_BFIN and PORT_UNKNOWN
935 bfin_serial_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
941 * Enable the IrDA function if tty->ldisc.num is N_IRDA.
942 * In other cases, disable IrDA function.
944 static void bfin_serial_set_ldisc(struct uart_port
*port
,
945 struct ktermios
*termios
)
947 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
950 switch (termios
->c_line
) {
952 val
= UART_GET_GCTL(uart
);
953 val
|= (UMOD_IRDA
| RPOLC
);
954 UART_PUT_GCTL(uart
, val
);
957 val
= UART_GET_GCTL(uart
);
958 val
&= ~(UMOD_MASK
| RPOLC
);
959 UART_PUT_GCTL(uart
, val
);
963 static void bfin_serial_reset_irda(struct uart_port
*port
)
965 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
968 val
= UART_GET_GCTL(uart
);
969 val
&= ~(UMOD_MASK
| RPOLC
);
970 UART_PUT_GCTL(uart
, val
);
972 val
|= (UMOD_IRDA
| RPOLC
);
973 UART_PUT_GCTL(uart
, val
);
977 #ifdef CONFIG_CONSOLE_POLL
979 * 05000099 - Because we only use THRE in poll_put and DR in poll_get,
980 * losing other bits of UART_LSR is not a problem here.
982 static void bfin_serial_poll_put_char(struct uart_port
*port
, unsigned char chr
)
984 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
986 while (!(UART_GET_LSR(uart
) & THRE
))
989 UART_CLEAR_DLAB(uart
);
990 UART_PUT_CHAR(uart
, (unsigned char)chr
);
993 static int bfin_serial_poll_get_char(struct uart_port
*port
)
995 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
998 while (!(UART_GET_LSR(uart
) & DR
))
1001 UART_CLEAR_DLAB(uart
);
1002 chr
= UART_GET_CHAR(uart
);
1008 static struct uart_ops bfin_serial_pops
= {
1009 .tx_empty
= bfin_serial_tx_empty
,
1010 .set_mctrl
= bfin_serial_set_mctrl
,
1011 .get_mctrl
= bfin_serial_get_mctrl
,
1012 .stop_tx
= bfin_serial_stop_tx
,
1013 .start_tx
= bfin_serial_start_tx
,
1014 .stop_rx
= bfin_serial_stop_rx
,
1015 .break_ctl
= bfin_serial_break_ctl
,
1016 .startup
= bfin_serial_startup
,
1017 .shutdown
= bfin_serial_shutdown
,
1018 .set_termios
= bfin_serial_set_termios
,
1019 .set_ldisc
= bfin_serial_set_ldisc
,
1020 .type
= bfin_serial_type
,
1021 .release_port
= bfin_serial_release_port
,
1022 .request_port
= bfin_serial_request_port
,
1023 .config_port
= bfin_serial_config_port
,
1024 .verify_port
= bfin_serial_verify_port
,
1025 #ifdef CONFIG_CONSOLE_POLL
1026 .poll_put_char
= bfin_serial_poll_put_char
,
1027 .poll_get_char
= bfin_serial_poll_get_char
,
1031 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
1033 * If the port was already initialised (eg, by a boot loader),
1034 * try to determine the current setup.
1037 bfin_serial_console_get_options(struct bfin_serial_port
*uart
, int *baud
,
1038 int *parity
, int *bits
)
1040 unsigned int status
;
1042 status
= UART_GET_IER(uart
) & (ERBFI
| ETBEI
);
1043 if (status
== (ERBFI
| ETBEI
)) {
1044 /* ok, the port was enabled */
1047 lcr
= UART_GET_LCR(uart
);
1056 *bits
= ((lcr
& WLS_MASK
) >> WLS_OFFSET
) + 5;
1058 /* Set DLAB in LCR to Access CLK */
1059 UART_SET_DLAB(uart
);
1061 clk
= UART_GET_CLK(uart
);
1063 /* Clear DLAB in LCR to Access THR RBR IER */
1064 UART_CLEAR_DLAB(uart
);
1066 *baud
= get_sclk() / (16*clk
);
1068 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__
, *baud
, *parity
, *bits
);
1071 static struct uart_driver bfin_serial_reg
;
1073 static void bfin_serial_console_putchar(struct uart_port
*port
, int ch
)
1075 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
1076 while (!(UART_GET_LSR(uart
) & THRE
))
1078 UART_PUT_CHAR(uart
, ch
);
1081 #endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) ||
1082 defined (CONFIG_EARLY_PRINTK) */
1084 #ifdef CONFIG_SERIAL_BFIN_CONSOLE
1085 #define CLASS_BFIN_CONSOLE "bfin-console"
1087 * Interrupts are disabled on entering
1090 bfin_serial_console_write(struct console
*co
, const char *s
, unsigned int count
)
1092 struct bfin_serial_port
*uart
= bfin_serial_ports
[co
->index
];
1093 unsigned long flags
;
1095 spin_lock_irqsave(&uart
->port
.lock
, flags
);
1096 uart_console_write(&uart
->port
, s
, count
, bfin_serial_console_putchar
);
1097 spin_unlock_irqrestore(&uart
->port
.lock
, flags
);
1102 bfin_serial_console_setup(struct console
*co
, char *options
)
1104 struct bfin_serial_port
*uart
;
1108 # if defined(SERIAL_BFIN_CTSRTS) || \
1109 defined(SERIAL_BFIN_HARD_CTSRTS)
1116 * Check whether an invalid uart number has been specified, and
1117 * if so, search for the first available port that does have
1120 if (co
->index
< 0 || co
->index
>= BFIN_UART_NR_PORTS
)
1123 uart
= bfin_serial_ports
[co
->index
];
1128 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1130 bfin_serial_console_get_options(uart
, &baud
, &parity
, &bits
);
1132 return uart_set_options(&uart
->port
, co
, baud
, parity
, bits
, flow
);
1135 static struct console bfin_serial_console
= {
1136 .name
= BFIN_SERIAL_DEV_NAME
,
1137 .write
= bfin_serial_console_write
,
1138 .device
= uart_console_device
,
1139 .setup
= bfin_serial_console_setup
,
1140 .flags
= CON_PRINTBUFFER
,
1142 .data
= &bfin_serial_reg
,
1144 #define BFIN_SERIAL_CONSOLE (&bfin_serial_console)
1146 #define BFIN_SERIAL_CONSOLE NULL
1147 #endif /* CONFIG_SERIAL_BFIN_CONSOLE */
1149 #ifdef CONFIG_EARLY_PRINTK
1150 static struct bfin_serial_port bfin_earlyprintk_port
;
1151 #define CLASS_BFIN_EARLYPRINTK "bfin-earlyprintk"
1154 * Interrupts are disabled on entering
1157 bfin_earlyprintk_console_write(struct console
*co
, const char *s
, unsigned int count
)
1159 unsigned long flags
;
1161 if (bfin_earlyprintk_port
.port
.line
!= co
->index
)
1164 spin_lock_irqsave(&bfin_earlyprintk_port
.port
.lock
, flags
);
1165 uart_console_write(&bfin_earlyprintk_port
.port
, s
, count
,
1166 bfin_serial_console_putchar
);
1167 spin_unlock_irqrestore(&bfin_earlyprintk_port
.port
.lock
, flags
);
1171 * This should have a .setup or .early_setup in it, but then things get called
1172 * without the command line options, and the baud rate gets messed up - so
1173 * don't let the common infrastructure play with things. (see calls to setup
1174 * & earlysetup in ./kernel/printk.c:register_console()
1176 static struct console bfin_early_serial_console __initdata
= {
1177 .name
= "early_BFuart",
1178 .write
= bfin_earlyprintk_console_write
,
1179 .device
= uart_console_device
,
1180 .flags
= CON_PRINTBUFFER
,
1182 .data
= &bfin_serial_reg
,
1186 static struct uart_driver bfin_serial_reg
= {
1187 .owner
= THIS_MODULE
,
1188 .driver_name
= DRIVER_NAME
,
1189 .dev_name
= BFIN_SERIAL_DEV_NAME
,
1190 .major
= BFIN_SERIAL_MAJOR
,
1191 .minor
= BFIN_SERIAL_MINOR
,
1192 .nr
= BFIN_UART_NR_PORTS
,
1193 .cons
= BFIN_SERIAL_CONSOLE
,
1196 static int bfin_serial_suspend(struct platform_device
*pdev
, pm_message_t state
)
1198 struct bfin_serial_port
*uart
= platform_get_drvdata(pdev
);
1200 return uart_suspend_port(&bfin_serial_reg
, &uart
->port
);
1203 static int bfin_serial_resume(struct platform_device
*pdev
)
1205 struct bfin_serial_port
*uart
= platform_get_drvdata(pdev
);
1207 return uart_resume_port(&bfin_serial_reg
, &uart
->port
);
1210 static int bfin_serial_probe(struct platform_device
*pdev
)
1212 struct resource
*res
;
1213 struct bfin_serial_port
*uart
= NULL
;
1216 if (pdev
->id
< 0 || pdev
->id
>= BFIN_UART_NR_PORTS
) {
1217 dev_err(&pdev
->dev
, "Wrong bfin uart platform device id.\n");
1221 if (bfin_serial_ports
[pdev
->id
] == NULL
) {
1223 uart
= kzalloc(sizeof(*uart
), GFP_KERNEL
);
1226 "fail to malloc bfin_serial_port\n");
1229 bfin_serial_ports
[pdev
->id
] = uart
;
1231 #ifdef CONFIG_EARLY_PRINTK
1232 if (!(bfin_earlyprintk_port
.port
.membase
1233 && bfin_earlyprintk_port
.port
.line
== pdev
->id
)) {
1235 * If the peripheral PINs of current port is allocated
1236 * in earlyprintk probe stage, don't do it again.
1239 ret
= peripheral_request_list(
1240 dev_get_platdata(&pdev
->dev
),
1244 "fail to request bfin serial peripherals\n");
1245 goto out_error_free_mem
;
1247 #ifdef CONFIG_EARLY_PRINTK
1251 spin_lock_init(&uart
->port
.lock
);
1252 uart
->port
.uartclk
= get_sclk();
1253 uart
->port
.fifosize
= BFIN_UART_TX_FIFO_SIZE
;
1254 uart
->port
.ops
= &bfin_serial_pops
;
1255 uart
->port
.line
= pdev
->id
;
1256 uart
->port
.iotype
= UPIO_MEM
;
1257 uart
->port
.flags
= UPF_BOOT_AUTOCONF
;
1259 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1261 dev_err(&pdev
->dev
, "Cannot get IORESOURCE_MEM\n");
1263 goto out_error_free_peripherals
;
1266 uart
->port
.membase
= ioremap(res
->start
, resource_size(res
));
1267 if (!uart
->port
.membase
) {
1268 dev_err(&pdev
->dev
, "Cannot map uart IO\n");
1270 goto out_error_free_peripherals
;
1272 uart
->port
.mapbase
= res
->start
;
1274 uart
->tx_irq
= platform_get_irq(pdev
, 0);
1275 if (uart
->tx_irq
< 0) {
1276 dev_err(&pdev
->dev
, "No uart TX IRQ specified\n");
1278 goto out_error_unmap
;
1281 uart
->rx_irq
= platform_get_irq(pdev
, 1);
1282 if (uart
->rx_irq
< 0) {
1283 dev_err(&pdev
->dev
, "No uart RX IRQ specified\n");
1285 goto out_error_unmap
;
1287 uart
->port
.irq
= uart
->rx_irq
;
1289 uart
->status_irq
= platform_get_irq(pdev
, 2);
1290 if (uart
->status_irq
< 0) {
1291 dev_err(&pdev
->dev
, "No uart status IRQ specified\n");
1293 goto out_error_unmap
;
1296 #ifdef CONFIG_SERIAL_BFIN_DMA
1297 spin_lock_init(&uart
->rx_lock
);
1301 res
= platform_get_resource(pdev
, IORESOURCE_DMA
, 0);
1303 dev_err(&pdev
->dev
, "No uart TX DMA channel specified\n");
1305 goto out_error_unmap
;
1307 uart
->tx_dma_channel
= res
->start
;
1309 res
= platform_get_resource(pdev
, IORESOURCE_DMA
, 1);
1311 dev_err(&pdev
->dev
, "No uart RX DMA channel specified\n");
1313 goto out_error_unmap
;
1315 uart
->rx_dma_channel
= res
->start
;
1317 timer_setup(&uart
->rx_dma_timer
, bfin_serial_rx_dma_timeout
, 0);
1320 #if defined(SERIAL_BFIN_CTSRTS) || \
1321 defined(SERIAL_BFIN_HARD_CTSRTS)
1322 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
1326 uart
->cts_pin
= res
->start
;
1328 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 1);
1332 uart
->rts_pin
= res
->start
;
1336 #ifdef CONFIG_SERIAL_BFIN_CONSOLE
1337 if (!is_early_platform_device(pdev
)) {
1339 uart
= bfin_serial_ports
[pdev
->id
];
1340 uart
->port
.dev
= &pdev
->dev
;
1341 dev_set_drvdata(&pdev
->dev
, uart
);
1342 ret
= uart_add_one_port(&bfin_serial_reg
, &uart
->port
);
1343 #ifdef CONFIG_SERIAL_BFIN_CONSOLE
1352 iounmap(uart
->port
.membase
);
1353 out_error_free_peripherals
:
1354 peripheral_free_list(dev_get_platdata(&pdev
->dev
));
1357 bfin_serial_ports
[pdev
->id
] = NULL
;
1363 static int bfin_serial_remove(struct platform_device
*pdev
)
1365 struct bfin_serial_port
*uart
= platform_get_drvdata(pdev
);
1367 dev_set_drvdata(&pdev
->dev
, NULL
);
1370 uart_remove_one_port(&bfin_serial_reg
, &uart
->port
);
1371 iounmap(uart
->port
.membase
);
1372 peripheral_free_list(dev_get_platdata(&pdev
->dev
));
1374 bfin_serial_ports
[pdev
->id
] = NULL
;
1380 static struct platform_driver bfin_serial_driver
= {
1381 .probe
= bfin_serial_probe
,
1382 .remove
= bfin_serial_remove
,
1383 .suspend
= bfin_serial_suspend
,
1384 .resume
= bfin_serial_resume
,
1386 .name
= DRIVER_NAME
,
1390 #if defined(CONFIG_SERIAL_BFIN_CONSOLE)
1391 static struct early_platform_driver early_bfin_serial_driver __initdata
= {
1392 .class_str
= CLASS_BFIN_CONSOLE
,
1393 .pdrv
= &bfin_serial_driver
,
1394 .requested_id
= EARLY_PLATFORM_ID_UNSET
,
1397 static int __init
bfin_serial_rs_console_init(void)
1399 early_platform_driver_register(&early_bfin_serial_driver
, DRIVER_NAME
);
1401 early_platform_driver_probe(CLASS_BFIN_CONSOLE
, BFIN_UART_NR_PORTS
, 0);
1403 register_console(&bfin_serial_console
);
1407 console_initcall(bfin_serial_rs_console_init
);
1410 #ifdef CONFIG_EARLY_PRINTK
1412 * Memory can't be allocated dynamically during earlyprink init stage.
1413 * So, do individual probe for earlyprink with a static uart port variable.
1415 static int bfin_earlyprintk_probe(struct platform_device
*pdev
)
1417 struct resource
*res
;
1420 if (pdev
->id
< 0 || pdev
->id
>= BFIN_UART_NR_PORTS
) {
1421 dev_err(&pdev
->dev
, "Wrong earlyprintk platform device id.\n");
1425 ret
= peripheral_request_list(dev_get_platdata(&pdev
->dev
),
1429 "fail to request bfin serial peripherals\n");
1433 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1435 dev_err(&pdev
->dev
, "Cannot get IORESOURCE_MEM\n");
1437 goto out_error_free_peripherals
;
1440 bfin_earlyprintk_port
.port
.membase
= ioremap(res
->start
,
1441 resource_size(res
));
1442 if (!bfin_earlyprintk_port
.port
.membase
) {
1443 dev_err(&pdev
->dev
, "Cannot map uart IO\n");
1445 goto out_error_free_peripherals
;
1447 bfin_earlyprintk_port
.port
.mapbase
= res
->start
;
1448 bfin_earlyprintk_port
.port
.line
= pdev
->id
;
1449 bfin_earlyprintk_port
.port
.uartclk
= get_sclk();
1450 bfin_earlyprintk_port
.port
.fifosize
= BFIN_UART_TX_FIFO_SIZE
;
1451 spin_lock_init(&bfin_earlyprintk_port
.port
.lock
);
1455 out_error_free_peripherals
:
1456 peripheral_free_list(dev_get_platdata(&pdev
->dev
));
1461 static struct platform_driver bfin_earlyprintk_driver
= {
1462 .probe
= bfin_earlyprintk_probe
,
1464 .name
= DRIVER_NAME
,
1465 .owner
= THIS_MODULE
,
1469 static struct early_platform_driver early_bfin_earlyprintk_driver __initdata
= {
1470 .class_str
= CLASS_BFIN_EARLYPRINTK
,
1471 .pdrv
= &bfin_earlyprintk_driver
,
1472 .requested_id
= EARLY_PLATFORM_ID_UNSET
,
1475 struct console __init
*bfin_earlyserial_init(unsigned int port
,
1481 if (port
< 0 || port
>= BFIN_UART_NR_PORTS
)
1485 * Only probe resource of the given port in earlyprintk boot arg.
1486 * The expected port id should be indicated in port name string.
1488 snprintf(port_name
, 20, DRIVER_NAME
".%d", port
);
1489 early_platform_driver_register(&early_bfin_earlyprintk_driver
,
1491 early_platform_driver_probe(CLASS_BFIN_EARLYPRINTK
, 1, 0);
1493 if (!bfin_earlyprintk_port
.port
.membase
)
1496 #ifdef CONFIG_SERIAL_BFIN_CONSOLE
1498 * If we are using early serial, don't let the normal console rewind
1499 * log buffer, since that causes things to be printed multiple times
1501 bfin_serial_console
.flags
&= ~CON_PRINTBUFFER
;
1504 bfin_early_serial_console
.index
= port
;
1510 bfin_serial_set_termios(&bfin_earlyprintk_port
.port
, &t
, &t
);
1512 return &bfin_early_serial_console
;
1514 #endif /* CONFIG_EARLY_PRINTK */
1516 static int __init
bfin_serial_init(void)
1520 pr_info("Blackfin serial driver\n");
1522 ret
= uart_register_driver(&bfin_serial_reg
);
1524 pr_err("failed to register %s:%d\n",
1525 bfin_serial_reg
.driver_name
, ret
);
1528 ret
= platform_driver_register(&bfin_serial_driver
);
1530 pr_err("fail to register bfin uart\n");
1531 uart_unregister_driver(&bfin_serial_reg
);
1537 static void __exit
bfin_serial_exit(void)
1539 platform_driver_unregister(&bfin_serial_driver
);
1540 uart_unregister_driver(&bfin_serial_reg
);
1544 module_init(bfin_serial_init
);
1545 module_exit(bfin_serial_exit
);
1547 MODULE_AUTHOR("Sonic Zhang, Aubrey Li");
1548 MODULE_DESCRIPTION("Blackfin generic serial port driver");
1549 MODULE_LICENSE("GPL");
1550 MODULE_ALIAS_CHARDEV_MAJOR(BFIN_SERIAL_MAJOR
);
1551 MODULE_ALIAS("platform:bfin-uart");