2 * Blackfin On-Chip Serial Driver
4 * Copyright 2006-2010 Analog Devices Inc.
6 * Enter bugs at http://blackfin.uclinux.org/
8 * Licensed under the GPL-2 or later.
11 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
15 #define DRIVER_NAME "bfin-uart"
16 #define pr_fmt(fmt) DRIVER_NAME ": " fmt
18 #include <linux/module.h>
19 #include <linux/ioport.h>
20 #include <linux/gfp.h>
22 #include <linux/init.h>
23 #include <linux/console.h>
24 #include <linux/sysrq.h>
25 #include <linux/platform_device.h>
26 #include <linux/tty.h>
27 #include <linux/tty_flip.h>
28 #include <linux/serial_core.h>
29 #include <linux/gpio.h>
30 #include <linux/irq.h>
31 #include <linux/kgdb.h>
32 #include <linux/slab.h>
33 #include <linux/dma-mapping.h>
35 #include <asm/portmux.h>
36 #include <asm/cacheflush.h>
39 #define port_membase(uart) (((struct bfin_serial_port *)(uart))->port.membase)
40 #define get_lsr_cache(uart) (((struct bfin_serial_port *)(uart))->lsr)
41 #define put_lsr_cache(uart, v) (((struct bfin_serial_port *)(uart))->lsr = (v))
42 #include <asm/bfin_serial.h>
44 #ifdef CONFIG_SERIAL_BFIN_MODULE
45 # undef CONFIG_EARLY_PRINTK
48 #ifdef CONFIG_SERIAL_BFIN_MODULE
49 # undef CONFIG_EARLY_PRINTK
52 /* UART name and device definitions */
53 #define BFIN_SERIAL_DEV_NAME "ttyBF"
54 #define BFIN_SERIAL_MAJOR 204
55 #define BFIN_SERIAL_MINOR 64
57 static struct bfin_serial_port
*bfin_serial_ports
[BFIN_UART_NR_PORTS
];
59 #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
60 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
62 # ifndef CONFIG_SERIAL_BFIN_PIO
63 # error KGDB only support UART in PIO mode.
66 static int kgdboc_port_line
;
67 static int kgdboc_break_enabled
;
70 * Setup for console. Argument comes from the menuconfig
72 #define DMA_RX_XCOUNT 512
73 #define DMA_RX_YCOUNT (PAGE_SIZE / DMA_RX_XCOUNT)
75 #define DMA_RX_FLUSH_JIFFIES (HZ / 50)
77 #ifdef CONFIG_SERIAL_BFIN_DMA
78 static void bfin_serial_dma_tx_chars(struct bfin_serial_port
*uart
);
80 static void bfin_serial_tx_chars(struct bfin_serial_port
*uart
);
83 static void bfin_serial_reset_irda(struct uart_port
*port
);
85 #if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
86 defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
87 static unsigned int bfin_serial_get_mctrl(struct uart_port
*port
)
89 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
90 if (uart
->cts_pin
< 0)
91 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
93 /* CTS PIN is negative assertive. */
94 if (UART_GET_CTS(uart
))
95 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
97 return TIOCM_DSR
| TIOCM_CAR
;
100 static void bfin_serial_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
102 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
103 if (uart
->rts_pin
< 0)
106 /* RTS PIN is negative assertive. */
107 if (mctrl
& TIOCM_RTS
)
108 UART_ENABLE_RTS(uart
);
110 UART_DISABLE_RTS(uart
);
114 * Handle any change of modem status signal.
116 static irqreturn_t
bfin_serial_mctrl_cts_int(int irq
, void *dev_id
)
118 struct bfin_serial_port
*uart
= dev_id
;
119 unsigned int status
= bfin_serial_get_mctrl(&uart
->port
);
120 #ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
121 struct tty_struct
*tty
= uart
->port
.state
->port
.tty
;
123 UART_CLEAR_SCTS(uart
);
124 if (tty
->hw_stopped
) {
127 uart_write_wakeup(&uart
->port
);
134 uart_handle_cts_change(&uart
->port
, status
& TIOCM_CTS
);
139 static unsigned int bfin_serial_get_mctrl(struct uart_port
*port
)
141 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
144 static void bfin_serial_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
150 * interrupts are disabled on entry
152 static void bfin_serial_stop_tx(struct uart_port
*port
)
154 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
155 #ifdef CONFIG_SERIAL_BFIN_DMA
156 struct circ_buf
*xmit
= &uart
->port
.state
->xmit
;
159 while (!(UART_GET_LSR(uart
) & TEMT
))
162 #ifdef CONFIG_SERIAL_BFIN_DMA
163 disable_dma(uart
->tx_dma_channel
);
164 xmit
->tail
= (xmit
->tail
+ uart
->tx_count
) & (UART_XMIT_SIZE
- 1);
165 uart
->port
.icount
.tx
+= uart
->tx_count
;
171 UART_PUT_LSR(uart
, TFI
);
173 UART_CLEAR_IER(uart
, ETBEI
);
178 * port is locked and interrupts are disabled
180 static void bfin_serial_start_tx(struct uart_port
*port
)
182 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
183 struct tty_struct
*tty
= uart
->port
.state
->port
.tty
;
186 * To avoid losting RX interrupt, we reset IR function
187 * before sending data.
189 if (tty
->termios
->c_line
== N_IRDA
)
190 bfin_serial_reset_irda(port
);
192 #ifdef CONFIG_SERIAL_BFIN_DMA
194 bfin_serial_dma_tx_chars(uart
);
196 UART_SET_IER(uart
, ETBEI
);
197 bfin_serial_tx_chars(uart
);
202 * Interrupts are enabled
204 static void bfin_serial_stop_rx(struct uart_port
*port
)
206 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
208 UART_CLEAR_IER(uart
, ERBFI
);
212 * Set the modem control timer to fire immediately.
214 static void bfin_serial_enable_ms(struct uart_port
*port
)
219 #if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO)
220 # define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold)
221 # define UART_SET_ANOMALY_THRESHOLD(uart, v) ((uart)->anomaly_threshold = (v))
223 # define UART_GET_ANOMALY_THRESHOLD(uart) 0
224 # define UART_SET_ANOMALY_THRESHOLD(uart, v)
227 #ifdef CONFIG_SERIAL_BFIN_PIO
228 static void bfin_serial_rx_chars(struct bfin_serial_port
*uart
)
230 struct tty_struct
*tty
= NULL
;
231 unsigned int status
, ch
, flg
;
232 static struct timeval anomaly_start
= { .tv_sec
= 0 };
234 status
= UART_GET_LSR(uart
);
235 UART_CLEAR_LSR(uart
);
237 ch
= UART_GET_CHAR(uart
);
238 uart
->port
.icount
.rx
++;
240 #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
241 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
242 if (kgdb_connected
&& kgdboc_port_line
== uart
->port
.line
243 && kgdboc_break_enabled
)
244 if (ch
== 0x3) {/* Ctrl + C */
249 if (!uart
->port
.state
|| !uart
->port
.state
->port
.tty
)
252 tty
= uart
->port
.state
->port
.tty
;
254 if (ANOMALY_05000363
) {
255 /* The BF533 (and BF561) family of processors have a nice anomaly
256 * where they continuously generate characters for a "single" break.
257 * We have to basically ignore this flood until the "next" valid
258 * character comes across. Due to the nature of the flood, it is
259 * not possible to reliably catch bytes that are sent too quickly
260 * after this break. So application code talking to the Blackfin
261 * which sends a break signal must allow at least 1.5 character
262 * times after the end of the break for things to stabilize. This
263 * timeout was picked as it must absolutely be larger than 1
264 * character time +/- some percent. So 1.5 sounds good. All other
265 * Blackfin families operate properly. Woo.
267 if (anomaly_start
.tv_sec
) {
271 if ((~ch
& (~ch
+ 1)) & 0xff)
272 goto known_good_char
;
274 do_gettimeofday(&curr
);
275 if (curr
.tv_sec
- anomaly_start
.tv_sec
> 1)
276 goto known_good_char
;
279 if (curr
.tv_sec
!= anomaly_start
.tv_sec
)
280 usecs
+= USEC_PER_SEC
;
281 usecs
+= curr
.tv_usec
- anomaly_start
.tv_usec
;
283 if (usecs
> UART_GET_ANOMALY_THRESHOLD(uart
))
284 goto known_good_char
;
287 anomaly_start
.tv_sec
= 0;
289 anomaly_start
= curr
;
295 anomaly_start
.tv_sec
= 0;
300 if (ANOMALY_05000363
)
301 if (bfin_revid() < 5)
302 do_gettimeofday(&anomaly_start
);
303 uart
->port
.icount
.brk
++;
304 if (uart_handle_break(&uart
->port
))
306 status
&= ~(PE
| FE
);
309 uart
->port
.icount
.parity
++;
311 uart
->port
.icount
.overrun
++;
313 uart
->port
.icount
.frame
++;
315 status
&= uart
->port
.read_status_mask
;
319 else if (status
& PE
)
321 else if (status
& FE
)
326 if (uart_handle_sysrq_char(&uart
->port
, ch
))
329 uart_insert_char(&uart
->port
, status
, OE
, ch
, flg
);
332 tty_flip_buffer_push(tty
);
335 static void bfin_serial_tx_chars(struct bfin_serial_port
*uart
)
337 struct circ_buf
*xmit
= &uart
->port
.state
->xmit
;
339 if (uart_circ_empty(xmit
) || uart_tx_stopped(&uart
->port
)) {
342 UART_PUT_LSR(uart
, TFI
);
345 * 05000215 - we always clear ETBEI within last UART TX
346 * interrupt to end a string. It is always set
347 * when start a new tx.
349 UART_CLEAR_IER(uart
, ETBEI
);
353 if (uart
->port
.x_char
) {
354 UART_PUT_CHAR(uart
, uart
->port
.x_char
);
355 uart
->port
.icount
.tx
++;
356 uart
->port
.x_char
= 0;
359 while ((UART_GET_LSR(uart
) & THRE
) && xmit
->tail
!= xmit
->head
) {
360 UART_PUT_CHAR(uart
, xmit
->buf
[xmit
->tail
]);
361 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
362 uart
->port
.icount
.tx
++;
365 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
366 uart_write_wakeup(&uart
->port
);
369 static irqreturn_t
bfin_serial_rx_int(int irq
, void *dev_id
)
371 struct bfin_serial_port
*uart
= dev_id
;
373 while (UART_GET_LSR(uart
) & DR
)
374 bfin_serial_rx_chars(uart
);
379 static irqreturn_t
bfin_serial_tx_int(int irq
, void *dev_id
)
381 struct bfin_serial_port
*uart
= dev_id
;
383 spin_lock(&uart
->port
.lock
);
384 if (UART_GET_LSR(uart
) & THRE
)
385 bfin_serial_tx_chars(uart
);
386 spin_unlock(&uart
->port
.lock
);
392 #ifdef CONFIG_SERIAL_BFIN_DMA
393 static void bfin_serial_dma_tx_chars(struct bfin_serial_port
*uart
)
395 struct circ_buf
*xmit
= &uart
->port
.state
->xmit
;
399 if (uart_circ_empty(xmit
) || uart_tx_stopped(&uart
->port
)) {
405 if (uart
->port
.x_char
) {
406 UART_PUT_CHAR(uart
, uart
->port
.x_char
);
407 uart
->port
.icount
.tx
++;
408 uart
->port
.x_char
= 0;
411 uart
->tx_count
= CIRC_CNT(xmit
->head
, xmit
->tail
, UART_XMIT_SIZE
);
412 if (uart
->tx_count
> (UART_XMIT_SIZE
- xmit
->tail
))
413 uart
->tx_count
= UART_XMIT_SIZE
- xmit
->tail
;
414 blackfin_dcache_flush_range((unsigned long)(xmit
->buf
+xmit
->tail
),
415 (unsigned long)(xmit
->buf
+xmit
->tail
+uart
->tx_count
));
416 set_dma_config(uart
->tx_dma_channel
,
417 set_bfin_dma_config(DIR_READ
, DMA_FLOW_STOP
,
422 set_dma_start_addr(uart
->tx_dma_channel
, (unsigned long)(xmit
->buf
+xmit
->tail
));
423 set_dma_x_count(uart
->tx_dma_channel
, uart
->tx_count
);
424 set_dma_x_modify(uart
->tx_dma_channel
, 1);
426 enable_dma(uart
->tx_dma_channel
);
428 UART_SET_IER(uart
, ETBEI
);
431 static void bfin_serial_dma_rx_chars(struct bfin_serial_port
*uart
)
433 struct tty_struct
*tty
= uart
->port
.state
->port
.tty
;
436 status
= UART_GET_LSR(uart
);
437 UART_CLEAR_LSR(uart
);
439 uart
->port
.icount
.rx
+=
440 CIRC_CNT(uart
->rx_dma_buf
.head
, uart
->rx_dma_buf
.tail
,
444 uart
->port
.icount
.brk
++;
445 if (uart_handle_break(&uart
->port
))
446 goto dma_ignore_char
;
447 status
&= ~(PE
| FE
);
450 uart
->port
.icount
.parity
++;
452 uart
->port
.icount
.overrun
++;
454 uart
->port
.icount
.frame
++;
456 status
&= uart
->port
.read_status_mask
;
460 else if (status
& PE
)
462 else if (status
& FE
)
467 for (i
= uart
->rx_dma_buf
.tail
; ; i
++) {
468 if (i
>= UART_XMIT_SIZE
)
470 if (i
== uart
->rx_dma_buf
.head
)
472 if (!uart_handle_sysrq_char(&uart
->port
, uart
->rx_dma_buf
.buf
[i
]))
473 uart_insert_char(&uart
->port
, status
, OE
,
474 uart
->rx_dma_buf
.buf
[i
], flg
);
478 tty_flip_buffer_push(tty
);
481 void bfin_serial_rx_dma_timeout(struct bfin_serial_port
*uart
)
485 dma_disable_irq_nosync(uart
->rx_dma_channel
);
486 spin_lock_bh(&uart
->rx_lock
);
488 /* 2D DMA RX buffer ring is used. Because curr_y_count and
489 * curr_x_count can't be read as an atomic operation,
490 * curr_y_count should be read before curr_x_count. When
491 * curr_x_count is read, curr_y_count may already indicate
492 * next buffer line. But, the position calculated here is
493 * still indicate the old line. The wrong position data may
494 * be smaller than current buffer tail, which cause garbages
495 * are received if it is not prohibit.
497 uart
->rx_dma_nrows
= get_dma_curr_ycount(uart
->rx_dma_channel
);
498 x_pos
= get_dma_curr_xcount(uart
->rx_dma_channel
);
499 uart
->rx_dma_nrows
= DMA_RX_YCOUNT
- uart
->rx_dma_nrows
;
500 if (uart
->rx_dma_nrows
== DMA_RX_YCOUNT
|| x_pos
== 0)
501 uart
->rx_dma_nrows
= 0;
502 x_pos
= DMA_RX_XCOUNT
- x_pos
;
503 if (x_pos
== DMA_RX_XCOUNT
)
506 pos
= uart
->rx_dma_nrows
* DMA_RX_XCOUNT
+ x_pos
;
507 /* Ignore receiving data if new position is in the same line of
508 * current buffer tail and small.
510 if (pos
> uart
->rx_dma_buf
.tail
||
511 uart
->rx_dma_nrows
< (uart
->rx_dma_buf
.tail
/DMA_RX_XCOUNT
)) {
512 uart
->rx_dma_buf
.head
= pos
;
513 bfin_serial_dma_rx_chars(uart
);
514 uart
->rx_dma_buf
.tail
= uart
->rx_dma_buf
.head
;
517 spin_unlock_bh(&uart
->rx_lock
);
518 dma_enable_irq(uart
->rx_dma_channel
);
520 mod_timer(&(uart
->rx_dma_timer
), jiffies
+ DMA_RX_FLUSH_JIFFIES
);
523 static irqreturn_t
bfin_serial_dma_tx_int(int irq
, void *dev_id
)
525 struct bfin_serial_port
*uart
= dev_id
;
526 struct circ_buf
*xmit
= &uart
->port
.state
->xmit
;
528 spin_lock(&uart
->port
.lock
);
529 if (!(get_dma_curr_irqstat(uart
->tx_dma_channel
)&DMA_RUN
)) {
530 disable_dma(uart
->tx_dma_channel
);
531 clear_dma_irqstat(uart
->tx_dma_channel
);
533 * 05000215 - we always clear ETBEI within last UART TX
534 * interrupt to end a string. It is always set
535 * when start a new tx.
537 UART_CLEAR_IER(uart
, ETBEI
);
538 xmit
->tail
= (xmit
->tail
+ uart
->tx_count
) & (UART_XMIT_SIZE
- 1);
539 uart
->port
.icount
.tx
+= uart
->tx_count
;
541 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
542 uart_write_wakeup(&uart
->port
);
544 bfin_serial_dma_tx_chars(uart
);
547 spin_unlock(&uart
->port
.lock
);
551 static irqreturn_t
bfin_serial_dma_rx_int(int irq
, void *dev_id
)
553 struct bfin_serial_port
*uart
= dev_id
;
554 unsigned short irqstat
;
557 spin_lock(&uart
->rx_lock
);
558 irqstat
= get_dma_curr_irqstat(uart
->rx_dma_channel
);
559 clear_dma_irqstat(uart
->rx_dma_channel
);
561 uart
->rx_dma_nrows
= get_dma_curr_ycount(uart
->rx_dma_channel
);
562 x_pos
= get_dma_curr_xcount(uart
->rx_dma_channel
);
563 uart
->rx_dma_nrows
= DMA_RX_YCOUNT
- uart
->rx_dma_nrows
;
564 if (uart
->rx_dma_nrows
== DMA_RX_YCOUNT
|| x_pos
== 0)
565 uart
->rx_dma_nrows
= 0;
567 pos
= uart
->rx_dma_nrows
* DMA_RX_XCOUNT
;
568 if (pos
> uart
->rx_dma_buf
.tail
||
569 uart
->rx_dma_nrows
< (uart
->rx_dma_buf
.tail
/DMA_RX_XCOUNT
)) {
570 uart
->rx_dma_buf
.head
= pos
;
571 bfin_serial_dma_rx_chars(uart
);
572 uart
->rx_dma_buf
.tail
= uart
->rx_dma_buf
.head
;
575 spin_unlock(&uart
->rx_lock
);
582 * Return TIOCSER_TEMT when transmitter is not busy.
584 static unsigned int bfin_serial_tx_empty(struct uart_port
*port
)
586 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
589 lsr
= UART_GET_LSR(uart
);
596 static void bfin_serial_break_ctl(struct uart_port
*port
, int break_state
)
598 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
599 u16 lcr
= UART_GET_LCR(uart
);
604 UART_PUT_LCR(uart
, lcr
);
608 static int bfin_serial_startup(struct uart_port
*port
)
610 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
612 #ifdef CONFIG_SERIAL_BFIN_DMA
613 dma_addr_t dma_handle
;
615 if (request_dma(uart
->rx_dma_channel
, "BFIN_UART_RX") < 0) {
616 printk(KERN_NOTICE
"Unable to attach Blackfin UART RX DMA channel\n");
620 if (request_dma(uart
->tx_dma_channel
, "BFIN_UART_TX") < 0) {
621 printk(KERN_NOTICE
"Unable to attach Blackfin UART TX DMA channel\n");
622 free_dma(uart
->rx_dma_channel
);
626 set_dma_callback(uart
->rx_dma_channel
, bfin_serial_dma_rx_int
, uart
);
627 set_dma_callback(uart
->tx_dma_channel
, bfin_serial_dma_tx_int
, uart
);
629 uart
->rx_dma_buf
.buf
= (unsigned char *)dma_alloc_coherent(NULL
, PAGE_SIZE
, &dma_handle
, GFP_DMA
);
630 uart
->rx_dma_buf
.head
= 0;
631 uart
->rx_dma_buf
.tail
= 0;
632 uart
->rx_dma_nrows
= 0;
634 set_dma_config(uart
->rx_dma_channel
,
635 set_bfin_dma_config(DIR_WRITE
, DMA_FLOW_AUTO
,
636 INTR_ON_ROW
, DIMENSION_2D
,
639 set_dma_x_count(uart
->rx_dma_channel
, DMA_RX_XCOUNT
);
640 set_dma_x_modify(uart
->rx_dma_channel
, 1);
641 set_dma_y_count(uart
->rx_dma_channel
, DMA_RX_YCOUNT
);
642 set_dma_y_modify(uart
->rx_dma_channel
, 1);
643 set_dma_start_addr(uart
->rx_dma_channel
, (unsigned long)uart
->rx_dma_buf
.buf
);
644 enable_dma(uart
->rx_dma_channel
);
646 uart
->rx_dma_timer
.data
= (unsigned long)(uart
);
647 uart
->rx_dma_timer
.function
= (void *)bfin_serial_rx_dma_timeout
;
648 uart
->rx_dma_timer
.expires
= jiffies
+ DMA_RX_FLUSH_JIFFIES
;
649 add_timer(&(uart
->rx_dma_timer
));
651 # if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
652 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
653 if (kgdboc_port_line
== uart
->port
.line
&& kgdboc_break_enabled
)
654 kgdboc_break_enabled
= 0;
657 if (request_irq(uart
->rx_irq
, bfin_serial_rx_int
, 0,
658 "BFIN_UART_RX", uart
)) {
659 printk(KERN_NOTICE
"Unable to attach BlackFin UART RX interrupt\n");
664 (uart
->tx_irq
, bfin_serial_tx_int
, 0,
665 "BFIN_UART_TX", uart
)) {
666 printk(KERN_NOTICE
"Unable to attach BlackFin UART TX interrupt\n");
667 free_irq(uart
->rx_irq
, uart
);
674 * UART2 and UART3 on BF548 share interrupt PINs and DMA
675 * controllers with SPORT2 and SPORT3. UART rx and tx
676 * interrupts are generated in PIO mode only when configure
677 * their peripheral mapping registers properly, which means
678 * request corresponding DMA channels in PIO mode as well.
680 unsigned uart_dma_ch_rx
, uart_dma_ch_tx
;
682 switch (uart
->rx_irq
) {
684 uart_dma_ch_rx
= CH_UART3_RX
;
685 uart_dma_ch_tx
= CH_UART3_TX
;
688 uart_dma_ch_rx
= CH_UART2_RX
;
689 uart_dma_ch_tx
= CH_UART2_TX
;
692 uart_dma_ch_rx
= uart_dma_ch_tx
= 0;
696 if (uart_dma_ch_rx
&&
697 request_dma(uart_dma_ch_rx
, "BFIN_UART_RX") < 0) {
698 printk(KERN_NOTICE
"Fail to attach UART interrupt\n");
699 free_irq(uart
->rx_irq
, uart
);
700 free_irq(uart
->tx_irq
, uart
);
703 if (uart_dma_ch_tx
&&
704 request_dma(uart_dma_ch_tx
, "BFIN_UART_TX") < 0) {
705 printk(KERN_NOTICE
"Fail to attach UART interrupt\n");
706 free_dma(uart_dma_ch_rx
);
707 free_irq(uart
->rx_irq
, uart
);
708 free_irq(uart
->tx_irq
, uart
);
713 # if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
714 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
719 #ifdef CONFIG_SERIAL_BFIN_CTSRTS
720 if (uart
->cts_pin
>= 0) {
721 if (request_irq(gpio_to_irq(uart
->cts_pin
),
722 bfin_serial_mctrl_cts_int
,
723 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
|
724 0, "BFIN_UART_CTS", uart
)) {
726 pr_info("Unable to attach BlackFin UART CTS interrupt. So, disable it.\n");
729 if (uart
->rts_pin
>= 0) {
730 if (gpio_request(uart
->rts_pin
, DRIVER_NAME
)) {
731 pr_info("fail to request RTS PIN at GPIO_%d\n", uart
->rts_pin
);
734 gpio_direction_output(uart
->rts_pin
, 0);
737 #ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
738 if (uart
->cts_pin
>= 0) {
739 if (request_irq(uart
->status_irq
, bfin_serial_mctrl_cts_int
,
740 IRQF_DISABLED
, "BFIN_UART_MODEM_STATUS", uart
)) {
742 dev_info(port
->dev
, "Unable to attach BlackFin UART Modem Status interrupt.\n");
745 /* CTS RTS PINs are negative assertive. */
746 UART_PUT_MCR(uart
, ACTS
);
747 UART_SET_IER(uart
, EDSSI
);
751 UART_SET_IER(uart
, ERBFI
);
755 static void bfin_serial_shutdown(struct uart_port
*port
)
757 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
759 #ifdef CONFIG_SERIAL_BFIN_DMA
760 disable_dma(uart
->tx_dma_channel
);
761 free_dma(uart
->tx_dma_channel
);
762 disable_dma(uart
->rx_dma_channel
);
763 free_dma(uart
->rx_dma_channel
);
764 del_timer(&(uart
->rx_dma_timer
));
765 dma_free_coherent(NULL
, PAGE_SIZE
, uart
->rx_dma_buf
.buf
, 0);
768 switch (uart
->port
.irq
) {
770 free_dma(CH_UART3_RX
);
771 free_dma(CH_UART3_TX
);
774 free_dma(CH_UART2_RX
);
775 free_dma(CH_UART2_TX
);
781 free_irq(uart
->rx_irq
, uart
);
782 free_irq(uart
->tx_irq
, uart
);
785 #ifdef CONFIG_SERIAL_BFIN_CTSRTS
786 if (uart
->cts_pin
>= 0)
787 free_irq(gpio_to_irq(uart
->cts_pin
), uart
);
788 if (uart
->rts_pin
>= 0)
789 gpio_free(uart
->rts_pin
);
791 #ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
792 if (uart
->cts_pin
>= 0)
793 free_irq(uart
->status_irq
, uart
);
798 bfin_serial_set_termios(struct uart_port
*port
, struct ktermios
*termios
,
799 struct ktermios
*old
)
801 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
803 unsigned int baud
, quot
;
804 unsigned short val
, ier
, lcr
= 0;
806 switch (termios
->c_cflag
& CSIZE
) {
820 printk(KERN_ERR
"%s: word lengh not supported\n",
825 * 05000231 - STOP bit is always set to 1 whatever the user is set.
827 if (termios
->c_cflag
& CSTOPB
) {
828 if (ANOMALY_05000231
)
829 printk(KERN_WARNING
"STOP bits other than 1 is not "
830 "supported in case of anomaly 05000231.\n");
834 if (termios
->c_cflag
& PARENB
)
836 if (!(termios
->c_cflag
& PARODD
))
838 if (termios
->c_cflag
& CMSPAR
)
841 spin_lock_irqsave(&uart
->port
.lock
, flags
);
843 port
->read_status_mask
= OE
;
844 if (termios
->c_iflag
& INPCK
)
845 port
->read_status_mask
|= (FE
| PE
);
846 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
847 port
->read_status_mask
|= BI
;
850 * Characters to ignore
852 port
->ignore_status_mask
= 0;
853 if (termios
->c_iflag
& IGNPAR
)
854 port
->ignore_status_mask
|= FE
| PE
;
855 if (termios
->c_iflag
& IGNBRK
) {
856 port
->ignore_status_mask
|= BI
;
858 * If we're ignoring parity and break indicators,
859 * ignore overruns too (for real raw support).
861 if (termios
->c_iflag
& IGNPAR
)
862 port
->ignore_status_mask
|= OE
;
865 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
866 quot
= uart_get_divisor(port
, baud
);
868 /* If discipline is not IRDA, apply ANOMALY_05000230 */
869 if (termios
->c_line
!= N_IRDA
)
870 quot
-= ANOMALY_05000230
;
872 UART_SET_ANOMALY_THRESHOLD(uart
, USEC_PER_SEC
/ baud
* 15);
875 ier
= UART_GET_IER(uart
);
876 UART_DISABLE_INTS(uart
);
878 /* Set DLAB in LCR to Access DLL and DLH */
881 UART_PUT_DLL(uart
, quot
& 0xFF);
882 UART_PUT_DLH(uart
, (quot
>> 8) & 0xFF);
885 /* Clear DLAB in LCR to Access THR RBR IER */
886 UART_CLEAR_DLAB(uart
);
888 UART_PUT_LCR(uart
, lcr
);
891 UART_ENABLE_INTS(uart
, ier
);
893 val
= UART_GET_GCTL(uart
);
895 UART_PUT_GCTL(uart
, val
);
897 /* Port speed changed, update the per-port timeout. */
898 uart_update_timeout(port
, termios
->c_cflag
, baud
);
900 spin_unlock_irqrestore(&uart
->port
.lock
, flags
);
903 static const char *bfin_serial_type(struct uart_port
*port
)
905 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
907 return uart
->port
.type
== PORT_BFIN
? "BFIN-UART" : NULL
;
911 * Release the memory region(s) being used by 'port'.
913 static void bfin_serial_release_port(struct uart_port
*port
)
918 * Request the memory region(s) being used by 'port'.
920 static int bfin_serial_request_port(struct uart_port
*port
)
926 * Configure/autoconfigure the port.
928 static void bfin_serial_config_port(struct uart_port
*port
, int flags
)
930 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
932 if (flags
& UART_CONFIG_TYPE
&&
933 bfin_serial_request_port(&uart
->port
) == 0)
934 uart
->port
.type
= PORT_BFIN
;
938 * Verify the new serial_struct (for TIOCSSERIAL).
939 * The only change we allow are to the flags and type, and
940 * even then only between PORT_BFIN and PORT_UNKNOWN
943 bfin_serial_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
949 * Enable the IrDA function if tty->ldisc.num is N_IRDA.
950 * In other cases, disable IrDA function.
952 static void bfin_serial_set_ldisc(struct uart_port
*port
, int ld
)
954 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
959 val
= UART_GET_GCTL(uart
);
960 val
|= (IREN
| RPOLC
);
961 UART_PUT_GCTL(uart
, val
);
964 val
= UART_GET_GCTL(uart
);
965 val
&= ~(IREN
| RPOLC
);
966 UART_PUT_GCTL(uart
, val
);
970 static void bfin_serial_reset_irda(struct uart_port
*port
)
972 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
975 val
= UART_GET_GCTL(uart
);
976 val
&= ~(IREN
| RPOLC
);
977 UART_PUT_GCTL(uart
, val
);
979 val
|= (IREN
| RPOLC
);
980 UART_PUT_GCTL(uart
, val
);
984 #ifdef CONFIG_CONSOLE_POLL
986 * 05000099 - Because we only use THRE in poll_put and DR in poll_get,
987 * losing other bits of UART_LSR is not a problem here.
989 static void bfin_serial_poll_put_char(struct uart_port
*port
, unsigned char chr
)
991 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
993 while (!(UART_GET_LSR(uart
) & THRE
))
996 UART_CLEAR_DLAB(uart
);
997 UART_PUT_CHAR(uart
, (unsigned char)chr
);
1000 static int bfin_serial_poll_get_char(struct uart_port
*port
)
1002 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
1005 while (!(UART_GET_LSR(uart
) & DR
))
1008 UART_CLEAR_DLAB(uart
);
1009 chr
= UART_GET_CHAR(uart
);
1015 #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
1016 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
1017 static void bfin_kgdboc_port_shutdown(struct uart_port
*port
)
1019 if (kgdboc_break_enabled
) {
1020 kgdboc_break_enabled
= 0;
1021 bfin_serial_shutdown(port
);
1025 static int bfin_kgdboc_port_startup(struct uart_port
*port
)
1027 kgdboc_port_line
= port
->line
;
1028 kgdboc_break_enabled
= !bfin_serial_startup(port
);
1033 static struct uart_ops bfin_serial_pops
= {
1034 .tx_empty
= bfin_serial_tx_empty
,
1035 .set_mctrl
= bfin_serial_set_mctrl
,
1036 .get_mctrl
= bfin_serial_get_mctrl
,
1037 .stop_tx
= bfin_serial_stop_tx
,
1038 .start_tx
= bfin_serial_start_tx
,
1039 .stop_rx
= bfin_serial_stop_rx
,
1040 .enable_ms
= bfin_serial_enable_ms
,
1041 .break_ctl
= bfin_serial_break_ctl
,
1042 .startup
= bfin_serial_startup
,
1043 .shutdown
= bfin_serial_shutdown
,
1044 .set_termios
= bfin_serial_set_termios
,
1045 .set_ldisc
= bfin_serial_set_ldisc
,
1046 .type
= bfin_serial_type
,
1047 .release_port
= bfin_serial_release_port
,
1048 .request_port
= bfin_serial_request_port
,
1049 .config_port
= bfin_serial_config_port
,
1050 .verify_port
= bfin_serial_verify_port
,
1051 #if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
1052 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
1053 .kgdboc_port_startup
= bfin_kgdboc_port_startup
,
1054 .kgdboc_port_shutdown
= bfin_kgdboc_port_shutdown
,
1056 #ifdef CONFIG_CONSOLE_POLL
1057 .poll_put_char
= bfin_serial_poll_put_char
,
1058 .poll_get_char
= bfin_serial_poll_get_char
,
1062 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
1064 * If the port was already initialised (eg, by a boot loader),
1065 * try to determine the current setup.
1068 bfin_serial_console_get_options(struct bfin_serial_port
*uart
, int *baud
,
1069 int *parity
, int *bits
)
1071 unsigned short status
;
1073 status
= UART_GET_IER(uart
) & (ERBFI
| ETBEI
);
1074 if (status
== (ERBFI
| ETBEI
)) {
1075 /* ok, the port was enabled */
1078 lcr
= UART_GET_LCR(uart
);
1087 switch (lcr
& 0x03) {
1101 /* Set DLAB in LCR to Access DLL and DLH */
1102 UART_SET_DLAB(uart
);
1104 dll
= UART_GET_DLL(uart
);
1105 dlh
= UART_GET_DLH(uart
);
1107 /* Clear DLAB in LCR to Access THR RBR IER */
1108 UART_CLEAR_DLAB(uart
);
1110 *baud
= get_sclk() / (16*(dll
| dlh
<< 8));
1112 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__
, *baud
, *parity
, *bits
);
1115 static struct uart_driver bfin_serial_reg
;
1117 static void bfin_serial_console_putchar(struct uart_port
*port
, int ch
)
1119 struct bfin_serial_port
*uart
= (struct bfin_serial_port
*)port
;
1120 while (!(UART_GET_LSR(uart
) & THRE
))
1122 UART_PUT_CHAR(uart
, ch
);
1125 #endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) ||
1126 defined (CONFIG_EARLY_PRINTK) */
1128 #ifdef CONFIG_SERIAL_BFIN_CONSOLE
1129 #define CLASS_BFIN_CONSOLE "bfin-console"
1131 * Interrupts are disabled on entering
1134 bfin_serial_console_write(struct console
*co
, const char *s
, unsigned int count
)
1136 struct bfin_serial_port
*uart
= bfin_serial_ports
[co
->index
];
1137 unsigned long flags
;
1139 spin_lock_irqsave(&uart
->port
.lock
, flags
);
1140 uart_console_write(&uart
->port
, s
, count
, bfin_serial_console_putchar
);
1141 spin_unlock_irqrestore(&uart
->port
.lock
, flags
);
1146 bfin_serial_console_setup(struct console
*co
, char *options
)
1148 struct bfin_serial_port
*uart
;
1152 # if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
1153 defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
1160 * Check whether an invalid uart number has been specified, and
1161 * if so, search for the first available port that does have
1164 if (co
->index
< 0 || co
->index
>= BFIN_UART_NR_PORTS
)
1167 uart
= bfin_serial_ports
[co
->index
];
1172 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1174 bfin_serial_console_get_options(uart
, &baud
, &parity
, &bits
);
1176 return uart_set_options(&uart
->port
, co
, baud
, parity
, bits
, flow
);
1179 static struct console bfin_serial_console
= {
1180 .name
= BFIN_SERIAL_DEV_NAME
,
1181 .write
= bfin_serial_console_write
,
1182 .device
= uart_console_device
,
1183 .setup
= bfin_serial_console_setup
,
1184 .flags
= CON_PRINTBUFFER
,
1186 .data
= &bfin_serial_reg
,
1188 #define BFIN_SERIAL_CONSOLE (&bfin_serial_console)
1190 #define BFIN_SERIAL_CONSOLE NULL
1191 #endif /* CONFIG_SERIAL_BFIN_CONSOLE */
1193 #ifdef CONFIG_EARLY_PRINTK
1194 static struct bfin_serial_port bfin_earlyprintk_port
;
1195 #define CLASS_BFIN_EARLYPRINTK "bfin-earlyprintk"
1198 * Interrupts are disabled on entering
1201 bfin_earlyprintk_console_write(struct console
*co
, const char *s
, unsigned int count
)
1203 unsigned long flags
;
1205 if (bfin_earlyprintk_port
.port
.line
!= co
->index
)
1208 spin_lock_irqsave(&bfin_earlyprintk_port
.port
.lock
, flags
);
1209 uart_console_write(&bfin_earlyprintk_port
.port
, s
, count
,
1210 bfin_serial_console_putchar
);
1211 spin_unlock_irqrestore(&bfin_earlyprintk_port
.port
.lock
, flags
);
1215 * This should have a .setup or .early_setup in it, but then things get called
1216 * without the command line options, and the baud rate gets messed up - so
1217 * don't let the common infrastructure play with things. (see calls to setup
1218 * & earlysetup in ./kernel/printk.c:register_console()
1220 static struct __initdata console bfin_early_serial_console
= {
1221 .name
= "early_BFuart",
1222 .write
= bfin_earlyprintk_console_write
,
1223 .device
= uart_console_device
,
1224 .flags
= CON_PRINTBUFFER
,
1226 .data
= &bfin_serial_reg
,
1230 static struct uart_driver bfin_serial_reg
= {
1231 .owner
= THIS_MODULE
,
1232 .driver_name
= DRIVER_NAME
,
1233 .dev_name
= BFIN_SERIAL_DEV_NAME
,
1234 .major
= BFIN_SERIAL_MAJOR
,
1235 .minor
= BFIN_SERIAL_MINOR
,
1236 .nr
= BFIN_UART_NR_PORTS
,
1237 .cons
= BFIN_SERIAL_CONSOLE
,
1240 static int bfin_serial_suspend(struct platform_device
*pdev
, pm_message_t state
)
1242 struct bfin_serial_port
*uart
= platform_get_drvdata(pdev
);
1244 return uart_suspend_port(&bfin_serial_reg
, &uart
->port
);
1247 static int bfin_serial_resume(struct platform_device
*pdev
)
1249 struct bfin_serial_port
*uart
= platform_get_drvdata(pdev
);
1251 return uart_resume_port(&bfin_serial_reg
, &uart
->port
);
1254 static int bfin_serial_probe(struct platform_device
*pdev
)
1256 struct resource
*res
;
1257 struct bfin_serial_port
*uart
= NULL
;
1260 if (pdev
->id
< 0 || pdev
->id
>= BFIN_UART_NR_PORTS
) {
1261 dev_err(&pdev
->dev
, "Wrong bfin uart platform device id.\n");
1265 if (bfin_serial_ports
[pdev
->id
] == NULL
) {
1267 uart
= kzalloc(sizeof(*uart
), GFP_KERNEL
);
1270 "fail to malloc bfin_serial_port\n");
1273 bfin_serial_ports
[pdev
->id
] = uart
;
1275 #ifdef CONFIG_EARLY_PRINTK
1276 if (!(bfin_earlyprintk_port
.port
.membase
1277 && bfin_earlyprintk_port
.port
.line
== pdev
->id
)) {
1279 * If the peripheral PINs of current port is allocated
1280 * in earlyprintk probe stage, don't do it again.
1283 ret
= peripheral_request_list(
1284 (unsigned short *)pdev
->dev
.platform_data
, DRIVER_NAME
);
1287 "fail to request bfin serial peripherals\n");
1288 goto out_error_free_mem
;
1290 #ifdef CONFIG_EARLY_PRINTK
1294 spin_lock_init(&uart
->port
.lock
);
1295 uart
->port
.uartclk
= get_sclk();
1296 uart
->port
.fifosize
= BFIN_UART_TX_FIFO_SIZE
;
1297 uart
->port
.ops
= &bfin_serial_pops
;
1298 uart
->port
.line
= pdev
->id
;
1299 uart
->port
.iotype
= UPIO_MEM
;
1300 uart
->port
.flags
= UPF_BOOT_AUTOCONF
;
1302 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1304 dev_err(&pdev
->dev
, "Cannot get IORESOURCE_MEM\n");
1306 goto out_error_free_peripherals
;
1309 uart
->port
.membase
= ioremap(res
->start
, resource_size(res
));
1310 if (!uart
->port
.membase
) {
1311 dev_err(&pdev
->dev
, "Cannot map uart IO\n");
1313 goto out_error_free_peripherals
;
1315 uart
->port
.mapbase
= res
->start
;
1317 uart
->tx_irq
= platform_get_irq(pdev
, 0);
1318 if (uart
->tx_irq
< 0) {
1319 dev_err(&pdev
->dev
, "No uart TX IRQ specified\n");
1321 goto out_error_unmap
;
1324 uart
->rx_irq
= platform_get_irq(pdev
, 1);
1325 if (uart
->rx_irq
< 0) {
1326 dev_err(&pdev
->dev
, "No uart RX IRQ specified\n");
1328 goto out_error_unmap
;
1330 uart
->port
.irq
= uart
->rx_irq
;
1332 uart
->status_irq
= platform_get_irq(pdev
, 2);
1333 if (uart
->status_irq
< 0) {
1334 dev_err(&pdev
->dev
, "No uart status IRQ specified\n");
1336 goto out_error_unmap
;
1339 #ifdef CONFIG_SERIAL_BFIN_DMA
1340 spin_lock_init(&uart
->rx_lock
);
1344 res
= platform_get_resource(pdev
, IORESOURCE_DMA
, 0);
1346 dev_err(&pdev
->dev
, "No uart TX DMA channel specified\n");
1348 goto out_error_unmap
;
1350 uart
->tx_dma_channel
= res
->start
;
1352 res
= platform_get_resource(pdev
, IORESOURCE_DMA
, 1);
1354 dev_err(&pdev
->dev
, "No uart RX DMA channel specified\n");
1356 goto out_error_unmap
;
1358 uart
->rx_dma_channel
= res
->start
;
1360 init_timer(&(uart
->rx_dma_timer
));
1363 #if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
1364 defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
1365 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
1369 uart
->cts_pin
= res
->start
;
1370 #ifdef CONFIG_SERIAL_BFIN_CTSRTS
1371 uart
->port
.flags
|= ASYNC_CTS_FLOW
;
1375 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 1);
1379 uart
->rts_pin
= res
->start
;
1383 #ifdef CONFIG_SERIAL_BFIN_CONSOLE
1384 if (!is_early_platform_device(pdev
)) {
1386 uart
= bfin_serial_ports
[pdev
->id
];
1387 uart
->port
.dev
= &pdev
->dev
;
1388 dev_set_drvdata(&pdev
->dev
, uart
);
1389 ret
= uart_add_one_port(&bfin_serial_reg
, &uart
->port
);
1390 #ifdef CONFIG_SERIAL_BFIN_CONSOLE
1399 iounmap(uart
->port
.membase
);
1400 out_error_free_peripherals
:
1401 peripheral_free_list(
1402 (unsigned short *)pdev
->dev
.platform_data
);
1405 bfin_serial_ports
[pdev
->id
] = NULL
;
1411 static int __devexit
bfin_serial_remove(struct platform_device
*pdev
)
1413 struct bfin_serial_port
*uart
= platform_get_drvdata(pdev
);
1415 dev_set_drvdata(&pdev
->dev
, NULL
);
1418 uart_remove_one_port(&bfin_serial_reg
, &uart
->port
);
1419 iounmap(uart
->port
.membase
);
1420 peripheral_free_list(
1421 (unsigned short *)pdev
->dev
.platform_data
);
1423 bfin_serial_ports
[pdev
->id
] = NULL
;
1429 static struct platform_driver bfin_serial_driver
= {
1430 .probe
= bfin_serial_probe
,
1431 .remove
= __devexit_p(bfin_serial_remove
),
1432 .suspend
= bfin_serial_suspend
,
1433 .resume
= bfin_serial_resume
,
1435 .name
= DRIVER_NAME
,
1436 .owner
= THIS_MODULE
,
1440 #if defined(CONFIG_SERIAL_BFIN_CONSOLE)
1441 static __initdata
struct early_platform_driver early_bfin_serial_driver
= {
1442 .class_str
= CLASS_BFIN_CONSOLE
,
1443 .pdrv
= &bfin_serial_driver
,
1444 .requested_id
= EARLY_PLATFORM_ID_UNSET
,
1447 static int __init
bfin_serial_rs_console_init(void)
1449 early_platform_driver_register(&early_bfin_serial_driver
, DRIVER_NAME
);
1451 early_platform_driver_probe(CLASS_BFIN_CONSOLE
, BFIN_UART_NR_PORTS
, 0);
1453 register_console(&bfin_serial_console
);
1457 console_initcall(bfin_serial_rs_console_init
);
1460 #ifdef CONFIG_EARLY_PRINTK
1462 * Memory can't be allocated dynamically during earlyprink init stage.
1463 * So, do individual probe for earlyprink with a static uart port variable.
1465 static int bfin_earlyprintk_probe(struct platform_device
*pdev
)
1467 struct resource
*res
;
1470 if (pdev
->id
< 0 || pdev
->id
>= BFIN_UART_NR_PORTS
) {
1471 dev_err(&pdev
->dev
, "Wrong earlyprintk platform device id.\n");
1475 ret
= peripheral_request_list(
1476 (unsigned short *)pdev
->dev
.platform_data
, DRIVER_NAME
);
1479 "fail to request bfin serial peripherals\n");
1483 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1485 dev_err(&pdev
->dev
, "Cannot get IORESOURCE_MEM\n");
1487 goto out_error_free_peripherals
;
1490 bfin_earlyprintk_port
.port
.membase
= ioremap(res
->start
,
1491 resource_size(res
));
1492 if (!bfin_earlyprintk_port
.port
.membase
) {
1493 dev_err(&pdev
->dev
, "Cannot map uart IO\n");
1495 goto out_error_free_peripherals
;
1497 bfin_earlyprintk_port
.port
.mapbase
= res
->start
;
1498 bfin_earlyprintk_port
.port
.line
= pdev
->id
;
1499 bfin_earlyprintk_port
.port
.uartclk
= get_sclk();
1500 bfin_earlyprintk_port
.port
.fifosize
= BFIN_UART_TX_FIFO_SIZE
;
1501 spin_lock_init(&bfin_earlyprintk_port
.port
.lock
);
1505 out_error_free_peripherals
:
1506 peripheral_free_list(
1507 (unsigned short *)pdev
->dev
.platform_data
);
1512 static struct platform_driver bfin_earlyprintk_driver
= {
1513 .probe
= bfin_earlyprintk_probe
,
1515 .name
= DRIVER_NAME
,
1516 .owner
= THIS_MODULE
,
1520 static __initdata
struct early_platform_driver early_bfin_earlyprintk_driver
= {
1521 .class_str
= CLASS_BFIN_EARLYPRINTK
,
1522 .pdrv
= &bfin_earlyprintk_driver
,
1523 .requested_id
= EARLY_PLATFORM_ID_UNSET
,
1526 struct console __init
*bfin_earlyserial_init(unsigned int port
,
1532 if (port
< 0 || port
>= BFIN_UART_NR_PORTS
)
1536 * Only probe resource of the given port in earlyprintk boot arg.
1537 * The expected port id should be indicated in port name string.
1539 snprintf(port_name
, 20, DRIVER_NAME
".%d", port
);
1540 early_platform_driver_register(&early_bfin_earlyprintk_driver
,
1542 early_platform_driver_probe(CLASS_BFIN_EARLYPRINTK
, 1, 0);
1544 if (!bfin_earlyprintk_port
.port
.membase
)
1547 #ifdef CONFIG_SERIAL_BFIN_CONSOLE
1549 * If we are using early serial, don't let the normal console rewind
1550 * log buffer, since that causes things to be printed multiple times
1552 bfin_serial_console
.flags
&= ~CON_PRINTBUFFER
;
1555 bfin_early_serial_console
.index
= port
;
1561 bfin_serial_set_termios(&bfin_earlyprintk_port
.port
, &t
, &t
);
1563 return &bfin_early_serial_console
;
1565 #endif /* CONFIG_EARLY_PRINTK */
1567 static int __init
bfin_serial_init(void)
1571 pr_info("Blackfin serial driver\n");
1573 ret
= uart_register_driver(&bfin_serial_reg
);
1575 pr_err("failed to register %s:%d\n",
1576 bfin_serial_reg
.driver_name
, ret
);
1579 ret
= platform_driver_register(&bfin_serial_driver
);
1581 pr_err("fail to register bfin uart\n");
1582 uart_unregister_driver(&bfin_serial_reg
);
1588 static void __exit
bfin_serial_exit(void)
1590 platform_driver_unregister(&bfin_serial_driver
);
1591 uart_unregister_driver(&bfin_serial_reg
);
1595 module_init(bfin_serial_init
);
1596 module_exit(bfin_serial_exit
);
1598 MODULE_AUTHOR("Sonic Zhang, Aubrey Li");
1599 MODULE_DESCRIPTION("Blackfin generic serial port driver");
1600 MODULE_LICENSE("GPL");
1601 MODULE_ALIAS_CHARDEV_MAJOR(BFIN_SERIAL_MAJOR
);
1602 MODULE_ALIAS("platform:bfin-uart");